/// <summary>
        /// Invokes the type editor for editing this item.
        /// </summary>
        internal override void EditPropertyValue(PropertyGridView iva)
        {
            base.EditPropertyValue(iva);

            if (!IsValueEditable)
            {
                RefreshPropertiesAttribute refreshAttr = (RefreshPropertiesAttribute)propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)];
                if ((refreshAttr != null && !refreshAttr.RefreshProperties.Equals(RefreshProperties.None)))
                {
                    GridEntryHost.Refresh(refreshAttr != null && refreshAttr.Equals(RefreshPropertiesAttribute.All));
                }
            }
        }
 public override bool OnMouseClick(int x, int y, int count, MouseButtons button)
 {
     if (pvUIItems != null && count == 2 && ((button & MouseButtons.Left) == MouseButtons.Left))
     {
         for (int i = 0; i < pvUIItems.Length; i++)
         {
             if (uiItemRects[i].Contains(x, GridEntryHost.GetGridEntryHeight() / 2))
             {
                 pvUIItems[i].InvokeHandler(this, propertyInfo, pvUIItems[i]);
                 return(true);
             }
         }
     }
     return(base.OnMouseClick(x, y, count, button));
 }
 internal override Point GetLabelToolTipLocation(int mouseX, int mouseY)
 {
     if (pvUIItems != null)
     {
         for (int i = 0; i < pvUIItems.Length; i++)
         {
             if (uiItemRects[i].Contains(mouseX, GridEntryHost.GetGridEntryHeight() / 2))
             {
                 this.toolTipText = pvUIItems[i].ToolTip;
                 return(new Point(mouseX, mouseY));
             }
         }
     }
     this.toolTipText = null;
     return(base.GetLabelToolTipLocation(mouseX, mouseY));
 }
Exemplo n.º 4
0
 protected override Brush GetBackgroundBrush(Graphics g)
 {
     return(GridEntryHost.GetLineBrush(g));
 }
Exemplo n.º 5
0
 protected override Color GetBackgroundColor() => GridEntryHost.GetLineColor();
        private object SetPropertyValue(object obj, object objVal, bool reset, string undoText)
        {
            DesignerTransaction trans = null;

            try
            {
                object oldValue = GetPropertyValueCore(obj);

                if (objVal != null && objVal.Equals(oldValue))
                {
                    return(objVal);
                }

                ClearCachedValues();

                IDesignerHost host = DesignerHost;


                if (host != null)
                {
                    string text = (undoText ?? string.Format(SR.PropertyGridSetValue, propertyInfo.Name));
                    trans = host.CreateTransaction(text);
                }

                // Usually IComponent things are sited and this notification will be
                // fired automatically by the PropertyDescriptor.  However, for non-IComponent sub objects
                // or sub objects that are non-sited sub components, we need to manuall fire
                // the notification.
                //
                bool needChangeNotify = !(obj is IComponent) || ((IComponent)obj).Site == null;

                if (needChangeNotify)
                {
                    try
                    {
                        if (ComponentChangeService != null)
                        {
                            ComponentChangeService.OnComponentChanging(obj, propertyInfo);
                        }
                    }
                    catch (CheckoutException coEx)
                    {
                        if (coEx == CheckoutException.Canceled)
                        {
                            return(oldValue);
                        }
                        throw coEx;
                    }
                }


                bool wasExpanded = InternalExpanded;
                int  childCount  = -1;
                if (wasExpanded)
                {
                    childCount = ChildCount;
                }

                RefreshPropertiesAttribute refreshAttr = (RefreshPropertiesAttribute)propertyInfo.Attributes[typeof(RefreshPropertiesAttribute)];
                bool needsRefresh = wasExpanded || (refreshAttr != null && !refreshAttr.RefreshProperties.Equals(RefreshProperties.None));

                if (needsRefresh)
                {
                    DisposeChildren();
                }

                // Determine if this is an event being created, and if so, navigate to the event code
                //

                EventDescriptor eventDesc = null;

                // This is possibly an event.  Check it out.
                //
                if (obj != null && objVal is string)
                {
                    if (eventBindings == null)
                    {
                        eventBindings = (IEventBindingService)GetService(typeof(IEventBindingService));
                    }
                    if (eventBindings != null)
                    {
                        eventDesc = eventBindings.GetEvent(propertyInfo);
                    }

                    // For a merged set of propertius, the event binding service won't
                    // find an event.  So, we ask type descriptor directly.
                    //
                    if (eventDesc == null)
                    {
                        // If we have a merged property descriptor, pull out one of
                        // the elements.
                        //
                        object eventObj = obj;

                        if (propertyInfo is MergePropertyDescriptor && obj is Array)
                        {
                            Array objArray = obj as Array;
                            if (objArray.Length > 0)
                            {
                                eventObj = objArray.GetValue(0);
                            }
                        }
                        eventDesc = TypeDescriptor.GetEvents(eventObj)[propertyInfo.Name];
                    }
                }

                bool setSuccessful = false;
                try
                {
                    if (reset)
                    {
                        propertyInfo.ResetValue(obj);
                    }
                    else if (eventDesc != null)
                    {
                        ViewEvent(obj, (string)objVal, eventDesc, false);
                    }
                    else
                    { // Not an event
                        SetPropertyValueCore(obj, objVal, true);
                    }

                    setSuccessful = true;

                    // Now notify the change service that the change was successful.
                    //
                    if (needChangeNotify && ComponentChangeService != null)
                    {
                        ComponentChangeService.OnComponentChanged(obj, propertyInfo, null, objVal);
                    }

                    NotifyParentChange(this);
                }
                finally
                {
                    // see if we need to refresh the property browser
                    // 1) if this property has the refreshpropertiesattribute, or
                    // 2) it's got expanded sub properties
                    //
                    if (needsRefresh && GridEntryHost != null)
                    {
                        RecreateChildren(childCount);
                        if (setSuccessful)
                        {
                            GridEntryHost.Refresh(refreshAttr != null && refreshAttr.Equals(RefreshPropertiesAttribute.All));
                        }
                    }
                }
            }
            catch (CheckoutException checkoutEx)
            {
                if (trans != null)
                {
                    trans.Cancel();
                    trans = null;
                }

                if (checkoutEx == CheckoutException.Canceled)
                {
                    return(null);
                }
                throw;
            }
            catch
            {
                if (trans != null)
                {
                    trans.Cancel();
                    trans = null;
                }

                throw;
            }
            finally
            {
                if (trans != null)
                {
                    trans.Commit();
                }
            }
            return(obj);
        }
Exemplo n.º 7
0
        public override void PaintOutline(System.Drawing.Graphics g, Rectangle r)
        {
            // draw outline pointer triangle.
            if (Expandable)
            {
                bool      fExpanded = Expanded;
                Rectangle outline   = OutlineRect;

                // make sure we're in our bounds
                outline = Rectangle.Intersect(r, outline);

                if (outline.IsEmpty)
                {
                    return;
                }

#if PAINT_CATEGORY_TRIANGLE
                // bump it over a pixel
                //outline.Offset(1, 0);
                //outline.Inflate(-1,-1);

                // build the triangle, an equalaterial centered around the midpoint of the rect.

                Point[] points      = new Point[3];
                int     borderWidth = 2;

                // width is always the length of the sides of the triangle.
                // Height = (width /2 * (Cos60)) ; Cos60 ~ .86
                int triWidth, triHeight;
                int xOffset, yOffset;

                if (!fExpanded)
                {
                    // draw arrow pointing right, remember height is pointing right
                    //      0
                    //      |\
                    //      | \2
                    //      | /
                    //      |/
                    //      1

                    triWidth = (int)((outline.Height * TRI_WIDTH_RATIO) - (2 * borderWidth));
                    // make sure it's an odd width so our lines will match up
                    if (!(triWidth % 2 == 0))
                    {
                        triWidth++;
                    }

                    triHeight = (int)Math.Ceil((triWidth / 2) * TRI_HEIGHT_RATIO);

                    yOffset = outline.Y + (outline.Height - triWidth) / 2;
                    xOffset = outline.X + (outline.Width - triHeight) / 2;

                    points[0] = new Point(xOffset, yOffset);
                    points[1] = new Point(xOffset, yOffset + triWidth);
                    points[2] = new Point(xOffset + triHeight, yOffset + (triWidth / 2));
                }
                else
                {
                    // draw arrow pointing down

                    //  0 -------- 1
                    //    \      /
                    //     \    /
                    //      \  /
                    //       \/
                    //       2

                    triWidth = (int)((outline.Width * TRI_WIDTH_RATIO) - (2 * borderWidth));
                    // make sure it's an odd width so our lines will match up
                    if (!(triWidth % 2 == 0))
                    {
                        triWidth++;
                    }

                    triHeight = (int)Math.Ceil((triWidth / 2) * TRI_HEIGHT_RATIO);

                    xOffset = outline.X + (outline.Width - triWidth) / 2;
                    yOffset = outline.Y + (outline.Height - triHeight) / 2;

                    points[0] = new Point(xOffset, yOffset);
                    points[1] = new Point(xOffset + triWidth, yOffset);
                    points[2] = new Point(xOffset + (triWidth / 2), yOffset + triHeight);
                }

                g.FillPolygon(SystemPens.WindowText, points);
#else
                // draw border area box
                Brush b;
                Pen   p;
                bool  disposeBrush = false;
                bool  disposePen   = false;

                Color color = GridEntryHost.GetLineColor();
                b            = new SolidBrush(g.GetNearestColor(color));
                disposeBrush = true;

                color = GridEntryHost.GetTextColor();

                p          = new Pen(g.GetNearestColor(color));
                disposePen = true;

                g.FillRectangle(b, outline);
                g.DrawRectangle(p, outline.X, outline.Y, outline.Width - 1, outline.Height - 1);

                // draw horizontal line for +/-
                int indent = 2;
                g.DrawLine(SystemPens.WindowText, outline.X + indent, outline.Y + outline.Height / 2,
                           outline.X + outline.Width - indent - 1, outline.Y + outline.Height / 2);

                // draw vertical line to make a +
                if (!fExpanded)
                {
                    g.DrawLine(SystemPens.WindowText, outline.X + outline.Width / 2, outline.Y + indent,
                               outline.X + outline.Width / 2, outline.Y + outline.Height - indent - 1);
                }

                if (disposePen)
                {
                    p.Dispose();
                }
                if (disposeBrush)
                {
                    b.Dispose();
                }
#endif
            }
        }