~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Components.Docking/DockGroup.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
using System.Xml;
33
33
using System.Collections.Generic;
34
34
using Gtk;
 
35
using MonoDevelop.Ide.Gui;
35
36
 
36
37
namespace MonoDevelop.Components.Docking
37
38
{
301
302
                {
302
303
                        visibleObjects = null;
303
304
                        bool visChanged;
304
 
                        CalcNewSizes ();
305
305
                        MarkForRelayout ();
306
306
                        
307
307
                        visChanged = child.Visible ? VisibleObjects.Count == 1 : VisibleObjects.Count == 0;
348
348
                        if (type == DockGroupType.Tabbed) {
349
349
                                if (boundTabStrip != null) {
350
350
                                        int tabsHeight = boundTabStrip.SizeRequest ().Height;
351
 
                                        boundTabStrip.SizeAllocate (new Gdk.Rectangle (newAlloc.X, newAlloc.Bottom - tabsHeight, newAlloc.Width, tabsHeight));
 
351
                                        boundTabStrip.SizeAllocate (new Gdk.Rectangle (newAlloc.X, newAlloc.Y, newAlloc.Width, tabsHeight));
352
352
                                }
353
353
                                if (allocStatus == AllocStatus.Valid && newAlloc == oldAlloc) {
354
354
                                        // Even if allocation has not changed, SizeAllocation has to be called on all items to avoid redrawing issues.
359
359
                                if (VisibleObjects.Count > 1 && boundTabStrip != null) {
360
360
                                        int tabsHeight = boundTabStrip.SizeRequest ().Height;
361
361
                                        newAlloc.Height -= tabsHeight;
 
362
                                        newAlloc.Y += tabsHeight;
362
363
                                        boundTabStrip.QueueDraw ();
363
364
                                } else if (VisibleObjects.Count != 0) {
364
365
                                        ((DockGroupItem)VisibleObjects [0]).Item.Widget.Show ();
404
405
                                CalcNewSizes ();
405
406
                        }
406
407
                        else if (allocStatus != AllocStatus.NewSizeRequest) {
407
 
                                // Available space has changed, so the size of the items must be changed.
 
408
 
 
409
                                // Don't proportionally resize the pads. Instead, resize only those pads with the Expand flag.
 
410
                                // This logic is implemented in CalcNewSizes, so no need to reimplement it
 
411
                                CalcNewSizes ();
 
412
 
 
413
                                // Disabled the proportional resize of pads for the above reason
 
414
 
 
415
/*                              // Available space has changed, so the size of the items must be changed.
408
416
                                // First of all, get the change fraction
409
417
                                double change;
410
418
                                if (horiz)
433
441
                                        }
434
442
                                        ob.DefaultSize = ob.DefaultSize * change;
435
443
                                }
436
 
                                CheckMinSizes ();
 
444
                                CheckMinSizes ();*/
437
445
                        }
438
446
 
439
447
                        allocStatus = AllocStatus.Valid;
619
627
                        // Add missing pages
620
628
                        foreach (DockObject ob in VisibleObjects) {
621
629
                                DockGroupItem it = ob as DockGroupItem;
622
 
                                ts.AddTab (it.Item.Widget, it.Item.Icon, it.Item.Label);
 
630
                                ts.AddTab (it.Item.TitleTab);
623
631
                        }
624
632
 
625
633
                        boundTabStrip = ts;
626
634
                        
627
 
                        if (currentTabPage != -1 && currentTabPage < boundTabStrip.TabCount) {
 
635
                        if (oldpage != null) {
 
636
                                boundTabStrip.CurrentPage = oldpage;
 
637
                        }
 
638
                        else if (currentTabPage != -1 && currentTabPage < boundTabStrip.TabCount) {
628
639
                                boundTabStrip.CurrentTab = currentTabPage;
629
 
                                // Discard the currentTabPage value. Current page is now tracked by the tab strip
630
 
                                currentTabPage = -1;
631
640
                        }
632
 
                        else if (oldpage != null)
633
 
                                boundTabStrip.CurrentPage = oldpage;
634
 
                        
 
641
 
 
642
                        // Discard the currentTabPage value. Current page is now tracked by the tab strip
 
643
                        currentTabPage = -1;
 
644
 
635
645
                        if (boundTabStrip.CurrentTab == -1) {
636
646
                                if (oldtab != -1) {
637
647
                                        if (oldtab < boundTabStrip.TabCount)
678
688
                                boundTabStrip.SetTabLabel (it.Widget, it.Icon, it.Label);
679
689
                }
680
690
                                
 
691
                internal void UpdateStyle (DockItem it)
 
692
                {
 
693
                        if (it.Visible && type == DockGroupType.Tabbed && boundTabStrip != null)
 
694
                                boundTabStrip.UpdateStyle (it);
 
695
                }
 
696
                
681
697
                internal void FocusItem (DockGroupItem it)
682
698
                {
683
699
                        tabFocus = it;
690
706
                
691
707
                public void LayoutWidgets ()
692
708
                {
 
709
                        Frame.UpdateRegionStyle (this);
 
710
 
693
711
                        foreach (DockObject ob in VisibleObjects) {
694
712
                                DockGroupItem it = ob as DockGroupItem;
695
713
                                if (it != null) {
696
 
                                        if (it.Item.Widget.Parent != Frame.Container) {
697
 
                                                if (it.Item.Widget.Parent != null) {
698
 
                                                        ((Gtk.Container)it.Item.Widget.Parent).Remove (it.Item.Widget);
699
 
                                                }
700
 
                                                Frame.Container.Add (it.Item.Widget);
 
714
                                        if (it.Visible) {
 
715
                                                Frame.UpdateRegionStyle (it);
 
716
                                                it.Item.SetRegionStyle (it.VisualStyle);
701
717
                                        }
702
 
                                        if (!it.Item.Widget.Visible && type != DockGroupType.Tabbed)
703
 
                                                it.Item.Widget.Show ();
704
718
                                }
705
719
                                else
706
720
                                        ((DockGroup)ob).LayoutWidgets ();
707
721
                        }
708
722
                }
709
723
        
 
724
                public void AddRemoveWidgets ()
 
725
                {
 
726
                        foreach (DockObject ob in Objects) {
 
727
                                DockGroupItem it = ob as DockGroupItem;
 
728
                                if (it != null) {
 
729
                                        if (it.Visible) {
 
730
                                                // Add the dock item to the container and show it if visible
 
731
                                                if (it.Item.Widget.Parent != Frame.Container) {
 
732
                                                        if (it.Item.Widget.Parent != null) {
 
733
                                                                ((Gtk.Container)it.Item.Widget.Parent).Remove (it.Item.Widget);
 
734
                                                        }
 
735
                                                        Frame.Container.Add (it.Item.Widget);
 
736
                                                }
 
737
                                                if (!it.Item.Widget.Visible && type != DockGroupType.Tabbed)
 
738
                                                        it.Item.Widget.Show ();
 
739
 
 
740
                                                // Do the same for the title tab
 
741
                                                if ((type != DockGroupType.Tabbed || VisibleObjects.Count == 1) && (it.Item.Behavior & DockItemBehavior.NoGrip) == 0) {
 
742
                                                        var tab = it.Item.TitleTab;
 
743
                                                        if (tab.Parent != Frame.Container) {
 
744
                                                                if (tab.Parent != null) {
 
745
                                                                        ((Gtk.Container)tab.Parent).Remove (tab);
 
746
                                                                }
 
747
                                                                Frame.Container.Add (tab);
 
748
                                                                tab.Active = true;
 
749
                                                        }
 
750
                                                        tab.ShowAll ();
 
751
                                                }
 
752
                                        } else {
 
753
                                                if (it.Item.Widget.Parent == Frame.Container)
 
754
                                                        Frame.Container.Remove (it.Item.Widget);
 
755
                                                var tab = it.Item.TitleTab;
 
756
                                                if (tab.Parent == Frame.Container)
 
757
                                                        Frame.Container.Remove (tab);
 
758
                                        }
 
759
                                }
 
760
                                else
 
761
                                        ((DockGroup)ob).AddRemoveWidgets ();
 
762
                        }
 
763
                }
 
764
 
710
765
                internal override void GetDefaultSize (out int width, out int height)
711
766
                {
712
767
                        if (type == DockGroupType.Tabbed) {
786
841
                public void Draw (Gdk.Rectangle exposedArea, DockGroup currentHandleGrp, int currentHandleIndex)
787
842
                {
788
843
                        if (type != DockGroupType.Tabbed) {
789
 
                                DrawSeparators (exposedArea, currentHandleGrp, currentHandleIndex, false, false, null);
 
844
                                DrawSeparators (exposedArea, currentHandleGrp, currentHandleIndex, DrawSeparatorOperation.Draw, false, null);
790
845
                                foreach (DockObject it in VisibleObjects) {
791
846
                                        DockGroup grp = it as DockGroup;
792
847
                                        if (grp != null)
795
850
                        }
796
851
                }
797
852
                
798
 
                public void DrawSeparators (Gdk.Rectangle exposedArea, DockGroup currentHandleGrp, int currentHandleIndex, bool invalidateOnly, List<Gdk.Rectangle> areasList)
 
853
                public void DrawSeparators (Gdk.Rectangle exposedArea, DockGroup currentHandleGrp, int currentHandleIndex, DrawSeparatorOperation oper, List<Gdk.Rectangle> areasList)
799
854
                {
800
 
                        DrawSeparators (exposedArea, currentHandleGrp, currentHandleIndex, invalidateOnly, true, areasList);
 
855
                        DrawSeparators (exposedArea, currentHandleGrp, currentHandleIndex, oper, true, areasList);
801
856
                }
802
857
                
803
 
                void DrawSeparators (Gdk.Rectangle exposedArea, DockGroup currentHandleGrp, int currentHandleIndex, bool invalidateOnly, bool drawChildrenSep, List<Gdk.Rectangle> areasList)
 
858
                void DrawSeparators (Gdk.Rectangle exposedArea, DockGroup currentHandleGrp, int currentHandleIndex, DrawSeparatorOperation oper, bool drawChildrenSep, List<Gdk.Rectangle> areasList)
804
859
                {
805
860
                        if (type == DockGroupType.Tabbed || VisibleObjects.Count == 0)
806
861
                                return;
812
867
                        int y = Allocation.Y;
813
868
                        int hw = horiz ? Frame.HandleSize : Allocation.Width;
814
869
                        int hh = horiz ? Allocation.Height : Frame.HandleSize;
815
 
                        Gtk.Orientation or = horiz ? Gtk.Orientation.Vertical : Gtk.Orientation.Horizontal;
 
870
 
 
871
                        Gdk.GC hgc = null;
 
872
 
 
873
                        if (areasList == null && oper == DrawSeparatorOperation.Draw) {
 
874
                                hgc = new Gdk.GC (Frame.Container.GdkWindow);
 
875
                                hgc.RgbFgColor = Styles.DockFrameBackground;
 
876
                        }
816
877
 
817
878
                        for (int n=0; n<VisibleObjects.Count; n++) {
818
879
                                DockObject ob = VisibleObjects [n];
819
880
                                DockGroup grp = ob as DockGroup;
820
881
                                if (grp != null && drawChildrenSep)
821
 
                                        grp.DrawSeparators (exposedArea, currentHandleGrp, currentHandleIndex, invalidateOnly, areasList);
 
882
                                        grp.DrawSeparators (exposedArea, currentHandleGrp, currentHandleIndex, oper, areasList);
822
883
                                if (ob != last) {
823
884
                                        if (horiz)
824
885
                                                x += ob.Allocation.Width + Frame.HandlePadding;
825
886
                                        else
826
887
                                                y += ob.Allocation.Height + Frame.HandlePadding;
827
 
                                        
828
 
                                        if (areasList != null) {
 
888
 
 
889
                                        switch (oper) {
 
890
                                        case DrawSeparatorOperation.CollectAreas:
829
891
                                                if (Frame.ShadedSeparators)
830
892
                                                        areasList.Add (new Gdk.Rectangle (x, y, hw, hh));
831
 
                                        } else if (invalidateOnly) {
 
893
                                                break;
 
894
                                        case DrawSeparatorOperation.Invalidate:
832
895
                                                Frame.Container.QueueDrawArea (x, y, hw, hh);
833
 
                                        }
834
 
                                        else {
835
 
                                                if (Frame.ShadedSeparators) {
836
 
                                                        Frame.ShadedContainer.DrawBackground (Frame.Container, new Gdk.Rectangle (x, y, hw, hh));
837
 
                                                } else {
838
 
                                                        StateType state = (currentHandleGrp == this && currentHandleIndex == n) ? StateType.Prelight : StateType.Normal;
839
 
                                                        if (!DockFrame.IsWindows)
840
 
                                                                Gtk.Style.PaintHandle (Frame.Style, Frame.Container.GdkWindow, state, ShadowType.None, exposedArea, Frame, "paned", x, y, hw, hh, or);
841
 
                                                }
 
896
                                                break;
 
897
                                        case DrawSeparatorOperation.Draw:
 
898
                                                Frame.Container.GdkWindow.DrawRectangle (hgc, true, x, y, hw, hh);
 
899
                                                break;
 
900
                                        case DrawSeparatorOperation.Allocate:
 
901
                                                Frame.Container.AllocateSplitter (this, n, new Gdk.Rectangle (x, y, hw, hh));
 
902
                                                break;
842
903
                                        }
843
904
                                        
844
905
                                        if (horiz)
847
908
                                                y += Frame.HandleSize + Frame.HandlePadding;
848
909
                                }
849
910
                        }
 
911
                        if (hgc != null)
 
912
                                hgc.Dispose ();
850
913
                }
851
914
                
852
915
                public void ResizeItem (int index, int newSize)
906
969
                
907
970
                internal override bool GetDockTarget (DockItem item, int px, int py, out DockDelegate dockDelegate, out Gdk.Rectangle rect)
908
971
                {
909
 
                        if (!Allocation.Contains (px, py) || VisibleObjects.Count == 0) {
910
 
                                dockDelegate = null;
911
 
                                rect = Gdk.Rectangle.Zero;
 
972
                        dockDelegate = null;
 
973
                        rect = Gdk.Rectangle.Zero;
 
974
 
 
975
                        if (!Allocation.Contains (px, py) || VisibleObjects.Count == 0)
912
976
                                return false;
913
 
                        }
914
 
                        
 
977
 
915
978
                        if (type == DockGroupType.Tabbed) {
916
979
                                // Tabs can only contain DockGroupItems
917
 
                                return ((DockGroupItem)VisibleObjects[0]).GetDockTarget (item, px, py, Allocation, out dockDelegate, out rect);
 
980
                                var sel = boundTabStrip != null ? VisibleObjects[boundTabStrip.CurrentTab] : VisibleObjects[VisibleObjects.Count - 1];
 
981
                                return ((DockGroupItem)sel).GetDockTarget (item, px, py, Allocation, out dockDelegate, out rect);
918
982
                        }
919
983
                        else if (type == DockGroupType.Horizontal) {
920
984
                                if (px >= Allocation.Right - DockFrame.GroupDockSeparatorSize) {
 
985
                                        // Check if the item is allowed to be docked here
 
986
                                        var s = Frame.GetRegionStyleForObject (VisibleObjects[VisibleObjects.Count - 1]);
 
987
                                        if (s.SingleColumnMode.Value)
 
988
                                                return false;
921
989
                                        // Dock to the right of the group
922
990
                                        dockDelegate = delegate (DockItem it) {
923
991
                                                DockTarget (it, dockObjects.Count);
926
994
                                        return true;
927
995
                                }
928
996
                                else if (px <= Allocation.Left + DockFrame.GroupDockSeparatorSize) {
 
997
                                        // Check if the item is allowed to be docked here
 
998
                                        var s = Frame.GetRegionStyleForObject (VisibleObjects[0]);
 
999
                                        if (s.SingleColumnMode.Value)
 
1000
                                                return false;
929
1001
                                        // Dock to the left of the group
930
1002
                                        dockDelegate = delegate (DockItem it) {
931
1003
                                                DockTarget (it, 0);
940
1012
                                            px >= ob.Allocation.Right - DockFrame.GroupDockSeparatorSize/2 &&
941
1013
                                            px <= ob.Allocation.Right + DockFrame.GroupDockSeparatorSize/2)
942
1014
                                        {
943
 
                                                int dn = dockObjects.IndexOf (ob);
 
1015
                                                // Check if the item is allowed to be docked here
 
1016
                                                int dn = dockObjects.IndexOf (ob) + 1;
 
1017
                                                var s = Frame.GetRegionStyleForPosition (this, dn, true);
 
1018
                                                if (s.SingleColumnMode.Value)
 
1019
                                                        return false;
944
1020
                                                dockDelegate = delegate (DockItem it) {
945
 
                                                        DockTarget (it, dn+1);
 
1021
                                                        DockTarget (it, dn);
946
1022
                                                };
947
1023
                                                rect = new Gdk.Rectangle (ob.Allocation.Right - DockFrame.GroupDockSeparatorSize/2, Allocation.Y, DockFrame.GroupDockSeparatorSize, Allocation.Height);
948
1024
                                                return true;
953
1029
                        }
954
1030
                        else if (type == DockGroupType.Vertical) {
955
1031
                                if (py >= Allocation.Bottom - DockFrame.GroupDockSeparatorSize) {
 
1032
                                        // Check if the item is allowed to be docked here
 
1033
                                        var s = Frame.GetRegionStyleForObject (VisibleObjects[VisibleObjects.Count - 1]);
 
1034
                                        if (s.SingleRowMode.Value)
 
1035
                                                return false;
956
1036
                                        // Dock to the bottom of the group
957
1037
                                        dockDelegate = delegate (DockItem it) {
958
1038
                                                DockTarget (it, dockObjects.Count);
961
1041
                                        return true;
962
1042
                                }
963
1043
                                else if (py <= Allocation.Top + DockFrame.GroupDockSeparatorSize) {
 
1044
                                        // Check if the item is allowed to be docked here
 
1045
                                        var s = Frame.GetRegionStyleForObject (VisibleObjects[0]);
 
1046
                                        if (s.SingleRowMode.Value)
 
1047
                                                return false;
964
1048
                                        // Dock to the top of the group
965
1049
                                        dockDelegate = delegate (DockItem it) {
966
1050
                                                DockTarget (it, 0);
975
1059
                                            py >= ob.Allocation.Bottom - DockFrame.GroupDockSeparatorSize/2 &&
976
1060
                                            py <= ob.Allocation.Bottom + DockFrame.GroupDockSeparatorSize/2)
977
1061
                                        {
978
 
                                                int dn = dockObjects.IndexOf (ob);
 
1062
                                                // Check if the item is allowed to be docked here
 
1063
                                                int dn = dockObjects.IndexOf (ob) + 1;
 
1064
                                                var s = Frame.GetRegionStyleForPosition (this, dn, true);
 
1065
                                                if (s.SingleRowMode.Value)
 
1066
                                                        return false;
979
1067
                                                dockDelegate = delegate (DockItem it) {
980
 
                                                        DockTarget (it, dn+1);
 
1068
                                                        DockTarget (it, dn);
981
1069
                                                };
982
1070
                                                rect = new Gdk.Rectangle (Allocation.X, ob.Allocation.Bottom - DockFrame.GroupDockSeparatorSize/2, Allocation.Width, DockFrame.GroupDockSeparatorSize);
983
1071
                                                return true;