Ejemplo n.º 1
0
 void ActivateLayoutWithSuspend(XmlUiLayout x0, XmlUiLayout x1, Control c, List <Control> suspended)
 {
     if (!NodeEquals(x0, x1))
     {
         ActivateLayoutWithSuspend(x1, c, suspended);
     }
 }
Ejemplo n.º 2
0
 void ChangeLayout(XmlUiLayout x0, XmlUiLayout x1, Control c)
 {
     if (!NodeEquals(x0, x1))
     {
         CreateLayout(x1, c, null);
     }
 }
Ejemplo n.º 3
0
        bool NodeEquals(XmlUiLayout x0, XmlUiLayout x1)
        {
            var e = x0.HideMvcButton == x1.HideMvcButton &&
                    x0.HideTabs == x1.HideTabs &&
                    x0.IsCollapsed == x1.IsCollapsed &&
                    x0.SelectedIndex == x1.SelectedIndex &&
                    (x0.Split != null) == (x1.Split != null) &&
                    (x0.Tabs != null) == (x1.Tabs != null);

            if (e && x0.Tabs != null)
            {
                if (x0.Tabs.Count != x1.Tabs.Count)
                {
                    e = false;
                }
                else
                {
                    foreach (var t in x0.Tabs.Zip(x1.Tabs, (a, b) => new { a = a, b = b }))
                    {
                        var aIsTp = t.a.StartsWith(_LayoutTabPageTypeName);
                        var bIsTp = t.b.StartsWith(_LayoutTabPageTypeName);
                        if (aIsTp != bIsTp)
                        {
                            e = false;
                            break;
                        }
                        if (aIsTp)
                        {
                            var atpl = x0.LayoutTabs.SingleOrDefault(lq => lq.TabName == t.a.Substring(_LayoutTabPageTypeName.Length));
                            var btpl = x1.LayoutTabs.SingleOrDefault(lq => lq.TabName == t.b.Substring(_LayoutTabPageTypeName.Length));
                            if (!NodeEquals(atpl, btpl))
                            {
                                e = false;
                                break;
                            }
                        }
                        else
                        {
                            if (t.a != t.b)
                            {
                                e = false;
                                break;
                            }
                        }
                    }
                }
            }
            if (e && x0.Split != null)
            {
                e = x0.Split.FixedPanel == x1.Split.FixedPanel &&
                    x0.Split.IsSplitterFixed == x1.Split.IsSplitterFixed &&
                    x0.Split.Orientation == x1.Split.Orientation &&
                    x0.Split.SplitterDistance == x1.Split.SplitterDistance &&
                    NodeEquals(x0.Split.Panel1, x1.Split.Panel1) &&
                    NodeEquals(x0.Split.Panel2, x1.Split.Panel2);
            }
            return(e);
        }
Ejemplo n.º 4
0
        XmlUiLayout ExtractLayout(Control c)
        {
            var x = new XmlUiLayout();

            var tabs     = c.Controls.AsEnumerable().SingleOrDefault(sod => sod is TabControl) as TabControl;
            var button   = c.Controls.AsEnumerable().SingleOrDefault(sod => sod is Button) as Button;
            var splitter = c.Controls.AsEnumerable().SingleOrDefault(sod => sod is SplitContainer) as SplitContainer;

            if (tabs == null && splitter == null || tabs != null && splitter != null)
            {
                throw new InvalidOperationException("UI layout levels must be either a TabControl or a SplitContainer");
            }

            if (tabs != null)
            {
                x.SelectedIndex = tabs.SelectedIndex;
                x.Size          = tabs.Size;
                x.HideMvcButton =
                    button != null &&
                    button.BackgroundImage == ButtonTemplate.BackgroundImage &&
                    !button.Visible;
                x.HideTabs    = (tabs is UiLayoutTabControl) && !(tabs as UiLayoutTabControl).TabsVisible;
                x.IsCollapsed = (tabs is UiLayoutTabControl) && !(tabs as UiLayoutTabControl).Visible;
                x.Tabs        = tabs.TabPages.AsEnumerable().Select(tp => tp.Name).ToList();
                x.Sizes       = tabs.TabPages.AsEnumerable().Select(tp => tp.Size).ToList();
                foreach (var lt in tabs.TabPages.AsEnumerable().Where(lq => lq is LayoutTabPage))
                {
                    var i = x.Tabs.Findi(lq => lq == lt.Name);
                    if (i >= 0)
                    {
                        var name = x.Tabs[i];
                        x.Tabs[i] = _LayoutTabPageTypeName + x.Tabs[i];
                        var tpl = ExtractLayout(lt.Controls[0]);
                        tpl.TabName = name;
                        x.LayoutTabs.Add(tpl);
                    }
                }
            }

            if (splitter != null)
            {
                x.Size  = splitter.Size;
                x.Sizes = new[] { splitter.Panel1.ClientSize, splitter.Panel2.ClientSize }.ToList();
                x.Split = new XmlUiSplitter {
                    Orientation      = splitter.Orientation,
                    SplitterDistance = splitter.SplitterDistance,
                    IsSplitterFixed  = splitter.IsSplitterFixed,
                    FixedPanel       = splitter.FixedPanel,
                    Panel1           = ExtractLayout(splitter.Panel1),
                    Panel2           = ExtractLayout(splitter.Panel2)
                };
            }
            return(x);
        }
Ejemplo n.º 5
0
 void CreateLayout(XmlUiLayout x, Control c, List <Action> finishLayout)
 {
     if (_Debug)
     {
         _DebugLevel += "  ";
     }
     try {
         c.Controls.Clear();
         if (x.Split == null)
         {
             var tabControl    = _TabsTemplate;
             var newTabControl = CreateNewTabControl(tabControl);
             newTabControl.TabsVisible = !x.HideTabs;
             c.AllowDrop  = true;
             c.DragDrop  += splitterPanel_DragDrop;
             c.DragEnter += splitterPanel_DragEnter;
             var button    = _ButtonTemplate;
             var newButton = CreateNewButton(button, c);
             newButton.Visible = !x.HideMvcButton;
             c.Controls.Add(newButton);
             c.Controls.Add(newTabControl);
             var a = c.Controls.GetChildIndex(newButton);
             var b = c.Controls.GetChildIndex(newTabControl);
             var i = -1;
             foreach (var tabName in x.Tabs)
             {
                 var tp = (TabPage)null;
                 i++;
                 if (tabName.StartsWith(_LayoutTabPageTypeName))
                 {
                     var tn = tabName.Substring(_LayoutTabPageTypeName.Length);
                     var tl = x.LayoutTabs.FirstOrDefault(lq => lq.TabName == tn);
                     if (tl != null)
                     {
                         tp = CreateNewLayoutTabPage(tn);
                         if (tp != null)
                         {
                             newTabControl.TabPages.Add(tp);
                             if (_Debug)
                             {
                                 Console.WriteLine("UIM {1}LayoutTabPage {0}", tn, _DebugLevel);
                             }
                             CreateLayout(tl, tp.Controls[0], finishLayout);
                         }
                         else
                         {
                             if (_Debug)
                             {
                                 Console.WriteLine("UIM {0}LayoutTabPage ERROR tp == null", _DebugLevel);
                             }
                         }
                     }
                     else
                     {
                         if (_Debug)
                         {
                             Console.WriteLine("UIM {0}LayoutTabPage ERROR tl == null", _DebugLevel);
                         }
                     }
                 }
                 else
                 {
                     tp = _AllTabs.SingleOrDefault(sod => sod.Name == tabName);
                     if (tp != null)
                     {
                         if (_Debug)
                         {
                             Console.WriteLine("UIM {1}TabPage tabName={0}", tabName, _DebugLevel);
                         }
                         newTabControl.TabPages.Add(tp);
                     }
                     else
                     {
                         if (_Debug)
                         {
                             Console.WriteLine("UIM {1}TabPage ERROR tabName={0} not found.", tabName, _DebugLevel);
                         }
                     }
                 }
             }
             newTabControl.SelectedIndex = x.SelectedIndex;
         }
         if (x.Split != null)
         {
             var splitter = new SplitContainer();
             splitter.Orientation = x.Split.Orientation;
             c.Controls.Add(splitter);
             if (splitter.SplitterDistance < splitter.Panel1MinSize || splitter.SplitterDistance > splitter.Width - splitter.Panel2MinSize)
             {
                 var w = splitter.Width;
             }
             try {
                 splitter.Dock = DockStyle.Fill;
             } catch (Exception ex) {
                 if (_Debug)
                 {
                     Console.WriteLine("UIM {2}{0}Splitter Dock EXCEPTION={1}", (x.Split.Orientation == Orientation.Horizontal ? "H" : "V"), ex.LastInnerMessage(), _DebugLevel);
                 }
                 splitter.Dock = DockStyle.None;
             }
             splitter.IsSplitterFixed = x.Split.IsSplitterFixed;
             splitter.FixedPanel      = x.Split.FixedPanel;
             splitter.Paint          += SplitterPaint;
             if (_Debug)
             {
                 Console.WriteLine("UIM {2}{0}Splitter Distance={1}", (x.Split.Orientation == Orientation.Horizontal ? "H" : "V"), x.Split.SplitterDistance, _DebugLevel);
             }
             finishLayout?.Add(() => { splitter.SplitterDistance = x.Split.SplitterDistance; });
             if (_Debug)
             {
                 Console.WriteLine("UIM {0}  Panel1", _DebugLevel);
             }
             CreateLayout(x.Split.Panel1, splitter.Panel1, finishLayout);
             if (_Debug)
             {
                 Console.WriteLine("UIM {0}  Panel2", _DebugLevel);
             }
             CreateLayout(x.Split.Panel2, splitter.Panel2, finishLayout);
         }
     } finally {
         if (_Debug)
         {
             _DebugLevel = _DebugLevel.Substring(2);
         }
     }
 }