/// <summary>
        /// first run new settings
        /// </summary>
        internal static void InitializeDefaultSettings()
        {
            var panel = AddDesktopPanel(null, DockName.None);

            panel.ViewModel.Title = "dock 1";

            var widget1 = new WidgetControl();

            widget1.ViewModel.Title = "widget 1";
            widget1.AutoSizableElementViewModel.WidthSizeMode  = SizeMode.MaximizedResizable;
            widget1.AutoSizableElementViewModel.HeightSizeMode = SizeMode.Auto;
            panel.ViewModel.AddWidget(widget1);

            var widget2 = new WidgetControl();

            widget2.ViewModel.Title       = "widget 2";
            widget2.ViewModel.HasSettings = false;
            widget2.AutoSizableElementViewModel.WidthSizeMode  = SizeMode.Auto;
            widget2.AutoSizableElementViewModel.HeightSizeMode = SizeMode.AutoResizable;
            panel.ViewModel.AddWidget(widget2);

            var widget3 = new WidgetControl();

            widget3.ViewModel.Title = "widget 3";
            widget3.AutoSizableElementViewModel.WidthSizeMode  = SizeMode.MaximizedResizable;
            widget3.AutoSizableElementViewModel.HeightSizeMode = SizeMode.MaximizedResizable;
            panel.ViewModel.AddWidget(widget3);

            var scr = DisplayDevices.GetCurrentScreenInfo();
            var x   = (scr.WorkArea.Width - panel.Width) / 2d;
            var y   = (scr.WorkArea.Height - panel.Height) / 2d;

            panel.Left = x;
            panel.Top  = y;
        }
Beispiel #2
0
        public void PlaceWidget(WidgetControl widget)
        {
            var     colSpan = Grid.GetColumnSpan(widget);
            AppCell cell    = App.WindowManager.Matrix.GetFreeCell(colSpan);

            Grid.SetColumn(widget, (int)cell.Column);
            Grid.SetRow(widget, (int)cell.Row);
            widget.HorizontalAlignment = HorizontalAlignment.Right;
            App.WindowManager.Matrix.ReserveSpace(cell.Column, cell.Row, colSpan);
            widget.Width  = colSpan * Envi.MinTileWidth - Envi.TileSpacing * 2;
            widget.Height = Envi.MinTileHeight - Envi.TileSpacing * 2;
        }
Beispiel #3
0
        void WidgetManagerWidgetLoaded(WidgetProxy widget)
        {
            var control = new WidgetControl(widget)
            {
                Order = WidgetHost.Children.Count
            };

            control.Load();
            PlaceWidget(control);
            //WidgetHost.HorizontalAlignment = HorizontalAlignment.Right;
            WidgetHost.Children.Add(control);
        }
        public void CloseWidget(WidgetControl widget)
        {
            if (WidgetsViewModels.Remove(widget.ViewModel))
            {
                /*var index = View.WidgetsPanel.Children.IndexOf(widget);
                 * var dropholder = View.WidgetsPanel.Children[index - 1];
                 * View.WidgetsPanel.Children.Remove(widget);
                 * View.WidgetsPanel.Children.Remove(dropholder);*/
                var index = View.WidgetsPanel.IndexOf(widget);
                View.WidgetsPanel.RemoveElement(widget);
#if alldbg || dbg
                DumpWidgetsPanelChildren();
#endif
            }
        }
 public void AddWidget(WidgetControl widget, int targetIndex = -1)
 {
     WidgetsViewModels.Add(widget.ViewModel);
     widget.ViewModel.PanelViewModel = this;
     if (targetIndex == -1)
     {
         /*View.WidgetsPanel.Children.Add(GetNewWidgetStackPanelDropPlaceHolder());
          * View.WidgetsPanel.Children.Add(widget);*/
         View.WidgetsPanel.AddElement(widget);
     }
     else
     {
         /*View.WidgetsPanel.Children.Insert(targetIndex, widget);
          * View.WidgetsPanel.Children.Insert(targetIndex, GetNewWidgetStackPanelDropPlaceHolder());*/
     }
 }
        internal static void DropWidget(WidgetControl widget, FrameworkElement target, DragEventArgs e)
        {
            var targetPanel = WPFHelper.FindLogicalParent <DesktopPanelBase>(target);
            var sourcePanel = WPFHelper.FindLogicalParent <DesktopPanelBase>(widget);
            var targetStack = WPFHelper.FindLogicalParent <StackPanel>(target);
            var sourceStack = WPFHelper.FindLogicalParent <StackPanel>(widget);

            if (targetPanel != null && sourcePanel != null && targetStack != null && sourceStack != null)
            {
                var dropAreaTarget        = WPFHelper.FindLogicalParent <WidgetStackPanelDropPlaceHolder>(target);
                var idxSourceStack        = sourceStack.Children.IndexOf(widget);
                var idxTargetStack        = targetStack.Children.IndexOf(dropAreaTarget);
                var targetIsLargeDropArea = dropAreaTarget.Name == "PermanentWidgetDropPlaceHolder";
#if alldbg || dbg
                DesktopPanelTool.Lib.Debug.WriteLine($"--------------- drop: {widget.ViewModel.Title} ------------ before:");
                DesktopPanelTool.Lib.Debug.WriteLine($"idxTargetStack={idxTargetStack} idxSourceStack={idxSourceStack}");
                DesktopPanelTool.Lib.Debug.WriteLine($"sourcePanel==targetPanel:{sourcePanel==targetPanel} targetIsLargeDropArea={targetIsLargeDropArea} idxSourceStack==sourceStack.Children.Count-1:{idxSourceStack == sourceStack.Children.Count - 1}");
#endif
                if (!((!targetIsLargeDropArea && sourcePanel == targetPanel && Math.Abs(idxTargetStack - idxSourceStack) == 1) ||
                      (targetIsLargeDropArea && sourcePanel == targetPanel && idxSourceStack == sourceStack.Children.Count - 1)
                      ))
                {
                    widget.ViewModel.PanelViewModel.CloseWidget(widget);
                    if (targetIsLargeDropArea)
                    {
                        targetPanel.ViewModel.AddWidget(widget);
                    }
                    else
                    {
                        if (idxTargetStack > idxSourceStack)
                        {
                            idxTargetStack -= 2;
                        }
                        targetPanel.ViewModel.AddWidget(widget, idxTargetStack);
                    }
                    widget.UpdateWidgetViewBindings(sourcePanel, targetPanel);
                }

#if false && dbg
                DesktopPanelTool.Lib.Debug.WriteLine($"--------------- after:");
                widget.ViewModel.PanelViewModel.DumpWidgetsPanelChildren();
#endif
            }
        }
        internal static void DropWidgetOnDesktop(WidgetControl widget, FrameworkElement target, DragEventArgs e)
        {
            var oldpanel = WPFHelper.FindLogicalParent <DesktopPanelBase>(widget);

            widget.ViewModel.PanelViewModel.CloseWidget(widget);
            var panel = AddDesktopPanel();

            panel.ViewModel.Title = GetNewPanelDefaultTitle();
            var p = new POINT();

            GetCursorPos(ref p);
            var gap  = (Thickness)widget.FindResource("WindowShadowAreaSize");
            var mind = (double)widget.FindResource("DropWidgetOnDesktopPanelMouseRelativeMinPosition");
            var maxd = (double)widget.FindResource("DropWidgetOnDesktopPanelMouseRelativeMaxPosition");

            panel.Left = p.X - gap.Left - maxd - widget.WidthBackup / 2d;
            panel.Top  = p.Y - gap.Top - mind - widget.HeightBackup / 2d;
            panel.ViewModel.AddWidget(widget);
            widget.UpdateWidgetViewBindings(oldpanel, panel);
            panel.Show();
        }
 public WidgetBaseViewModel(WidgetControl widget)
 {
     AutoSizableElementViewModel = new AutoSizableElementViewModel();
     View = widget;
     Initialize();
 }
 public WidgetBaseViewModel(SerializationInfo info, StreamingContext context)
 {
     info.GetValues(this, _members);
     View = new WidgetControl(this, AutoSizableElementViewModel);
     Initialize();
 }