Example #1
0
        public static void AddFault(Stetic.Wrapper.Widget owner, object faultId,
                                    Gtk.SideType side, Gtk.Widget widget)
        {
            Gdk.Rectangle   fault;
            Gtk.Orientation orientation;

            if (widget == null)
            {
                fault = owner.Wrapped.Allocation;
                int border = (int)((Gtk.Container)owner.Wrapped).BorderWidth;
                fault.Inflate(-border, -border);
            }
            else
            {
                fault = widget.Allocation;
            }

            switch (side)
            {
            case Gtk.SideType.Top:
                fault.Y     -= FaultOverlap;
                fault.Height = 2 * FaultOverlap;
                orientation  = Gtk.Orientation.Horizontal;
                break;

            case Gtk.SideType.Bottom:
                fault.Y     += fault.Height - FaultOverlap;
                fault.Height = 2 * FaultOverlap;
                orientation  = Gtk.Orientation.Horizontal;
                break;

            case Gtk.SideType.Left:
                fault.X    -= FaultOverlap;
                fault.Width = 2 * FaultOverlap;
                orientation = Gtk.Orientation.Vertical;
                break;

            case Gtk.SideType.Right:
                fault.X    += fault.Width - FaultOverlap;
                fault.Width = 2 * FaultOverlap;
                orientation = Gtk.Orientation.Vertical;
                break;

            default:
                throw new Exception("not reached");
            }

            AddFault(owner, faultId, orientation, fault);
        }
Example #2
0
/*
 *              FIXME: why was this needed?
 *              protected override bool AllowPlaceholders {
 *                      get {
 *                              return InternalChildProperty != null;
 *                      }
 *              }
 */
        // DoSync() does two things: first, it makes sure that all of the
        // PackStart widgets have Position numbers less than all of the
        // PackEnd widgets. Second, it creates faults anywhere two widgets
        // could be split apart. The fault IDs correspond to the Position
        // a widget would have to be assigned to end up in that slot
        // (negated for PackEnd slots).
        //
        // Position/PackType:   0S 1S 2S     4E  3E
        //                    +----------------------+
        //                    | AA BB CC     DD  EE  |
        //                    +----------------------+
        // Fault Id:           0  1  2  3  -5  -4  -3

        protected override void DoSync()
        {
            if (!box.IsRealized)
            {
                return;
            }

            DND.ClearFaults(this);

            Gtk.Widget[] children = box.Children;
            if (children.Length == 0)
            {
                return;
            }

            Gtk.Widget[] sorted     = new Gtk.Widget[children.Length];
            int          last_start = -1;
            bool         hbox       = ContainerOrientation == Gtk.Orientation.Horizontal;

            foreach (Gtk.Widget child in children)
            {
                Gtk.Box.BoxChild bc = box[child] as Gtk.Box.BoxChild;
                if (AutoSize[child])
                {
                    bool exp = hbox ? ChildHExpandable(child) : ChildVExpandable(child);
                    if (bc.Expand != exp)
                    {
                        bc.Expand = exp;
                    }
                    if (bc.Fill != exp)
                    {
                        bc.Fill = exp;
                    }
                }

                // Make sure all of the PackStart widgets are before
                // any PackEnd widgets in the list.
                if (bc.PackType == Gtk.PackType.Start)
                {
                    if (bc.Position != ++last_start)
                    {
                        Array.Copy(sorted, last_start, sorted, last_start + 1, bc.Position - last_start);
                        box.ReorderChild(child, last_start);
                    }
                }

                if (!(child is Placeholder))
                {
                    sorted[bc.Position] = child;
                }
            }

            // The orientation of the faults is the opposite of the
            // orientation of the box
            Gtk.Orientation orientation = hbox ? Gtk.Orientation.Vertical : Gtk.Orientation.Horizontal;
            Gtk.SideType    before      = hbox ? Gtk.SideType.Left : Gtk.SideType.Top;
            Gtk.SideType    after       = hbox ? Gtk.SideType.Right : Gtk.SideType.Bottom;

            if (!Unselectable)
            {
                // If there are no PackStart widgets, we need a fault at the leading
                // edge. Otherwise if there's a widget at the leading edge, we need a
                // fault before it.
                if (last_start == -1)
                {
                    DND.AddFault(this, 0, before, null);
                }
                else if (sorted[0] != null)
                {
                    DND.AddFault(this, 0, before, sorted[0]);
                }

                // Add a fault between each pair of (non-placeholder) start widgets
                for (int i = 1; i <= last_start; i++)
                {
                    if (sorted[i - 1] != null && sorted[i] != null)
                    {
                        DND.AddFault(this, i, orientation, sorted[i - 1], sorted[i]);
                    }
                }

                // If there's a non-placeholder at the end of the PackStart
                // range, add a fault after it
                if (last_start > -1 && sorted[last_start] != null)
                {
                    DND.AddFault(this, last_start + 1, after, sorted[last_start]);
                }

                // Now the PackEnd widgets
                if (last_start == sorted.Length - 1)
                {
                    DND.AddFault(this, -(last_start + 1), after, null);
                }
                else if (sorted[last_start + 1] != null)
                {
                    DND.AddFault(this, -(last_start + 1), after, sorted[last_start + 1]);
                }

                for (int i = last_start + 2; i < sorted.Length; i++)
                {
                    if (sorted[i - 1] != null && sorted[i] != null)
                    {
                        DND.AddFault(this, -i, orientation, sorted[i - 1], sorted[i]);
                    }
                }

                if (sorted.Length > last_start + 1 && sorted[sorted.Length - 1] != null)
                {
                    DND.AddFault(this, -sorted.Length, before, sorted[sorted.Length - 1]);
                }
            }
        }