예제 #1
0
                public _Floating(_Node node, bool onDrag)
                {
                    _node      = node;
                    _owner     = _node._pm._ContainerWindow;
                    _isToolbar = _node._IsToolbarsNode;

                    //workaround for: if a HwndHost-ed native control in this panel is focused, WPF will activate the floating panel and disable next mouse click
                    if (Keyboard.FocusedElement == null)
                    {
                        var wFocus = Api.GetFocus();
                        if (!wFocus.Is0 && wFocus.IsChildOf(_owner.Hwnd()))
                        {
                            if (null != _node.Elem.FindVisualDescendant(o => o is HwndHost h && h.Handle == wFocus.Handle))
                            {
                                _owner.Focus();
                            }
                        }
                    }

                    var style = WS.THICKFRAME | WS.POPUP | WS.CLIPCHILDREN; if (node._IsStack)
                    {
                        style |= WS.CAPTION;
                    }
                    var estyle = WSE.TOOLWINDOW | WSE.WINDOWEDGE; if (_isToolbar)
                    {
                        estyle |= WSE.NOACTIVATE;
                    }
                    RECT rect        = default;
                    bool defaultRect = onDrag | (_node._floatSavedRect == null);

                    if (defaultRect)
                    {
                        var c2 = _node._ParentIsTab ? _node.Parent._elem : _node._elem;
                        if (c2.IsVisible)
                        {
                            rect = c2.RectInScreen();
                            Dpi.AdjustWindowRectEx(c2, ref rect, style, estyle);
                        }
                        else
                        {
                            var p = mouse.xy;
                            rect = (p.x - 10, p.y - 10, 200, 200);
                        }
                    }

                    base.SourceInitialized += (_, _) => {
                        var w = this.Hwnd();
                        w.SetStyle(style);
                        if (_isToolbar)
                        {
                            w.SetExStyle(estyle);
                        }
                    };

                    base.Title = script.name + " - " + _node.ToString();
                    base.Owner = _owner;
                    base.WindowStartupLocation = WindowStartupLocation.Manual;
                    base.WindowStyle           = WindowStyle.ToolWindow;
                    base.ShowInTaskbar         = false;             //never mind: if false, WPF creates a "Hidden Window", probably as owner, even if owner specified
                    base.ShowActivated         = false;

                    if (defaultRect)
                    {
                        this.SetRect(rect);
                    }
                    else
                    {
                        WndSavedRect.Restore(this, _node._floatSavedRect);
                    }

                    _owner.Closing          += _Owner_Closing;
                    _owner.IsVisibleChanged += _Owner_IsVisibleChanged;
                }