Exemplo n.º 1
0
        protected override void DoSync()
        {
            DND.ClearFaults(this);
            Gtk.Orientation faultOrientation =
                Orientation == Gtk.Orientation.Horizontal ? Gtk.Orientation.Vertical : Gtk.Orientation.Horizontal;
            Gdk.Rectangle tbAlloc = toolbar.Allocation;

            Gtk.Widget[] children = toolbar.Children;
            if (children.Length == 0)
            {
                DND.AddFault(this, 0, faultOrientation, tbAlloc);
                return;
            }

            if (faultOrientation == Gtk.Orientation.Horizontal)
            {
                DND.AddHFault(this, 0, null, children[0]);
                DND.AddHFault(this, children.Length, children[children.Length - 1], null);
            }
            else
            {
                DND.AddVFault(this, 0, null, children[0]);
                DND.AddVFault(this, children.Length, children[children.Length - 1], null);
            }

            for (int i = 1; i < children.Length; i++)
            {
                if (faultOrientation == Gtk.Orientation.Horizontal)
                {
                    DND.AddHFault(this, i, children[i - 1], children[i]);
                }
                else
                {
                    DND.AddVFault(this, i, children[i - 1], children[i]);
                }
            }
        }
Exemplo n.º 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]);
                }
            }
        }