Example #1
0
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            var clicked = Clicked;

            if (clicked != null)
            {
                clicked(this, e);
            }
            else
            {
                IMXView view;
                var     parent = Parent as IGridBase;
                if (parent is IMXView)
                {
                    view = parent as IMXView;
                }
                else
                {
                    var control = CompactFactory.GetNativeObject <GridCell>(parent, "Parent");
                    view = control.Parent as IMXView ?? control.Parent.Parent as IMXView;
                }
                CompactFactory.Navigate(NavigationLink, view);
            }
        }
Example #2
0
        public IMXView[] PopToRoot()
        {
            if (Context.ActivePane == Pane.Popover)
            {
                var views = Views.ToArray();
                foreach (var view in views)
                {
                    _views.Remove(view);
                    var d = view is IListView?CompactFactory.GetNativeObject <SmoothListbox>(view, "view") : null;

                    if (d != null)
                    {
                        d.Parent = null;
                        d.animationTimer.Enabled = false;
                        d.Dispose();
                    }
                }
                if (views.Any())
                {
                    var master = (HistoryStack)PaneManager.Instance.FromNavContext(Pane.Master, PaneManager.Instance.CurrentTab);
                    master.Align(NavigationType.Back);
                }
                return(views);
            }

            var root = Views.FirstOrDefault();

            return(PopToView(root));
        }
Example #3
0
        public void Layout()
        {
            Columns.Clear();

            var childControls = Children.ToList();

            foreach (var childControl in childControls)
            {
                RemoveChild(childControl);
            }

            if (PrimaryItems != null)
            {
                foreach (var toolbarItem in PrimaryItems)
                {
                    IElement item = toolbarItem is IToolbarButton || toolbarItem.Pair is IToolbarButton
                        ? CompactFactory.GetNativeObject <ToolbarButton>(toolbarItem, "toolbarItem")
                        : null;

                    //toolbarItem is IToolbarSeparator || toolbarItem.Pair is IToolbarSeparator ? CompactFactory.GetNativeObject<ToolbarSeparator>(toolbarItem, "toolbarItem") : null;
                    if (item != null)
                    {
                        Columns.Add(Column.AutoSized);
                        AddChild(item);
                    }
                }
            }

            if (SecondaryItems != null)
            {
                foreach (var toolbarItem in SecondaryItems)
                {
                    IElement item = toolbarItem is IToolbarButton || toolbarItem.Pair is IToolbarButton
                        ? CompactFactory.GetNativeObject <ToolbarButton>(toolbarItem, "toolbarItem")
                        : null;

                    //toolbarItem is IToolbarSeparator || toolbarItem.Pair is IToolbarSeparator ? CompactFactory.GetNativeObject<ToolbarSeparator>(toolbarItem, "toolbarItem") : null;
                    if (item != null)
                    {
                        Columns.Add(Column.AutoSized);
                        AddChild(item);
                    }
                }
            }

            var minSize = new Size(MinWidth, MinHeight);
            var maxSize = new Size(MaxWidth, MaxHeight);
            var newSize = this.PerformLayout(minSize, maxSize);

            if ((int)newSize.Height == 0)
            {
                return;
            }
            Size   = newSize.ToSize();
            _width = Width;
        }
Example #4
0
 private void Draw(Graphics grp)
 {
     foreach (var paint in Children
              .Select(element => element is IPaintable ||
                      element.Pair is IPaintable ? CompactFactory.GetNativeObject <IPaintable>(element, "element") : null)
              .Where(paint => paint != null))
     {
         paint.Paint(grp);
     }
 }
Example #5
0
        public void Render()
        {
            lock (SyncRoot) if (_instance == null)
                {
                    _instance = this;
                }

            Rendering.Raise(this, EventArgs.Empty);
            if (!TabItems.Any())
            {
                return;
            }
            if (string.IsNullOrEmpty(Text))
            {
                Text = "Go to...";
            }

            PaneManager.Instance.Clear();
            var tabs = TabItems.Select(item => CompactFactory.GetNativeObject <TabItem>(item, item.Title)).ToList();

            for (int i = 0; i < tabs.Count; i++)
            {
                var tab = tabs[i];
                if (tab == null)
                {
                    continue;
                }
                tab.View  = this;
                tab.Index = i;
                MenuItems.Add(tab);
                var context = new iApp.AppNavigationContext {
                    ActivePane = Pane.Master, ActiveTab = i
                };
                PaneManager.Instance.AddStack(new HistoryStack {
                    Context = context
                }, context);
            }

            var cxt = new iApp.AppNavigationContext {
                ActivePane = Pane.Popover,
            };

            PaneManager.Instance.AddStack(new HistoryStack {
                Context = cxt
            }, cxt);
            if (PaneManager.Instance.CurrentTab > TabItems.Count() || PaneManager.Instance.CurrentTab < 0)
            {
                PaneManager.Instance.CurrentTab = 0;
            }
            CompactFactory.Navigate(TabItems.ElementAt(PaneManager.Instance.CurrentTab).NavigationLink, this);
        }
Example #6
0
        public void RemoveChild(IElement element)
        {
            _children.Remove(element);

            if (element is Control || element.Pair is Control)
            {
                var control = CompactFactory.GetNativeObject <Control>(element, "element");
                if (control != null)
                {
                    control.Parent = null;
                }
            }

            _forceLayout = true;
        }
Example #7
0
        public IMXView[] PopToView(IMXView view)
        {
            if (view == null)
            {
                return(null);
            }
            if (!Views.Contains(view))
            {
                throw new ArgumentException();
            }

            var removed = new List <IMXView>();
            var layer   = CurrentLayer;

            // Perform pop on Views collection
            IMXView current;

            while (!Equals(current = _views.LastOrDefault(), view))
            {
                _views.Remove(current);
                var d = current is IListView?CompactFactory.GetNativeObject <SmoothListbox>(current, "view") : null;

                if (d != null)
                {
                    d.Parent = null;
                    d.animationTimer.Enabled = false;
                    d.Dispose();
                }
                removed.Add(current);
            }

            if (removed.Count <= 0)
            {
                return(removed.ToArray());
            }

            Align(NavigationType.Back);
            if (layer != null)
            {
                layer.Unload();
            }
            var iview = removed.First() as IView;

            iview.RaiseEvent("Deactivated", EventArgs.Empty);
            return(removed.ToArray());
        }
Example #8
0
        public void AddChild(IElement element)
        {
            _children.Add(element);

            if (element is Control || element.Pair is Control)
            {
                var control = CompactFactory.GetNativeObject <Control>(element, "element");
                if (control != null)
                {
                    control.Parent = this;
                }
            }
            else if (element is IPaintable || element.Pair is IPaintable)
            {
                var paint = CompactFactory.GetNativeObject <IPaintable>(element, "element");
                if (paint != null)
                {
                    paint.SetParent(this);
                }
            }
            _forceLayout = true;
        }
Example #9
0
        /// <summary>
        /// Syncronize the rendered stack with the <see cref="Views"/> collection
        /// </summary>
        public void Align(NavigationType navType)
        {
            var view = _views.LastOrDefault();

            if (view == null)
            {
                return;
            }
            var monoView = view as IView;

            if (monoView != null && monoView.Pair is Control)
            {
                view = CompactFactory.GetNativeObject <Control>(monoView, "view") as IMXView;
            }

            if (!(view is Control))
            {
                _views.Remove(view);
                return;
            }

            ((RootForm)CompactFactory.Instance.RootForm).Attach(view, this);
        }
Example #10
0
        public void Add(IMenuButton menuButton)
        {
            var button = CompactFactory.GetNativeObject <MenuButton>(menuButton, "menuButton");

            _buttons.Add(button);
        }
Example #11
0
        internal void Attach(IMXView view, HistoryStack stack)
        {
            if (GridControl.Bitmaps.Any())
            {
                var bitmaps = new Dictionary <GridControl, System.Drawing.Bitmap>(GridControl.Bitmaps);
                GridControl.Bitmaps.Clear();
                GridControl.mem = 0;
                foreach (var bit in bitmaps)
                {
                    bit.Value.Dispose();
                }
            }

            Device.Thread.ExecuteOnMainThread(() =>
            {
                if (view == null)
                {
                    return;
                }
                iApp.CurrentNavContext.ActivePane = stack.Context.ActivePane;
                var t            = CompactFactory.MetricStopwatch.ElapsedTicks;
                var absView      = view as IView;
                var list         = view as IListView;
                var grid         = view as IGridView;
                var browser      = view as IBrowserView;
                var history      = view as IHistoryEntry;
                var concreteView = view as System.Windows.Forms.Control ?? (view is IPairable ? ((IPairable)view).Pair as System.Windows.Forms.Control : null);

                if (absView != null)
                {
                    Text = absView.Title;
                }
                var listbox = ActiveView as SmoothListbox;
                if (listbox != null)
                {
                    listbox.animationTimer.Enabled = false;
                }
                Controls.Clear();
                int top = CompactFactory.TopPadding;
                if (list != null && list.SearchBox != null)
                {
                    var box    = CompactFactory.GetNativeObject <System.Windows.Forms.Control>(list.SearchBox, "SearchBox");
                    box.Parent = this;
                    var min    = new Size(Width, 0);
                    var max    = new Size(Width, 50 * CompactFactory.Instance.DpiScale);
                    box.Size   = ((IGridBase)box).PerformLayout(min, max).ToSize();
                    box.Top    = top;
                    top        = box.Bottom;
                }

                if (concreteView != null)
                {
                    var h                 = Screen.PrimaryScreen.WorkingArea.Height - SystemInformation.MenuHeight;
                    concreteView.Size     = new System.Drawing.Size(Width, h);
                    concreteView.Parent   = this;
                    concreteView.Location = new Point(0, top);
                }

                Menu.MenuItems.Clear();

                var back       = history == null ? null : history.BackLink;
                var backButton = new MenuItem {
                    Text = iApp.Factory.GetResourceString("Back")
                };
                backButton.Click += (sender, args) => stack.HandleBackLink(back, stack.Context.ActivePane);
                Menu.MenuItems.Add(backButton);
                var layer          = view.GetModel() as iLayer;
                backButton.Enabled = stack.DisplayBackButton(back) || stack.Context.ActivePane == Pane.Popover && !(layer is LoginLayer) && stack.Views.Count() < 2;
                if (MenuTabView.Instance != null && !(layer is LoginLayer) && (layer == null || stack.Context.ActivePane != Pane.Popover))
                {
                    Menu.MenuItems.Add(MenuTabView.Instance);
                }

                var menu = (list != null ? list.Menu : grid != null ? grid.Menu : browser != null ? browser.Menu : null);
                if (menu != null)
                {
                    MenuItem menuButton;
                    if (menu.ButtonCount == 1)
                    {
                        menuButton = CompactFactory.GetNativeObject <MenuItem>(menu.GetButton(0), "menu[0]");
                    }
                    else
                    {
                        menuButton = new MenuItem {
                            Text = iApp.Factory.GetResourceString("Menu")
                        };
                        for (int i = 0; i < menu.ButtonCount; i++)
                        {
                            menuButton.MenuItems.Add(CompactFactory.GetNativeObject <MenuItem>(menu.GetButton(i), "menu[" + i + "]"));
                        }
                    }
                    Menu.MenuItems.Add(menuButton);
                }

                MinimizeBox = layer == null || layer.ActionButtons.All(b => b.Action != Button.ActionType.Submit);

                listbox = ActiveView as SmoothListbox;
                if (listbox != null)
                {
                    listbox.animationTimer.Enabled = true;
                }

                CompactFactory.NavigatedAddresses.Clear();

                Debug.WriteLineIf(CompactFactory.MetricStopwatch.IsRunning, string.Format("[{1}] Attach IMXView took {0}ms", new TimeSpan(CompactFactory.MetricStopwatch.ElapsedTicks - t).TotalMilliseconds, CompactFactory.MetricStopwatch.ElapsedMilliseconds));
                Debug.WriteLineIf(CompactFactory.MetricStopwatch.IsRunning, string.Format("Total elapsed layer load time: {0}ms", CompactFactory.MetricStopwatch.ElapsedMilliseconds));

                CompactFactory.MetricStopwatch.Stop();
            });
        }