/// <summary>
        /// Show the popup using the provided rectangle as the screen rect.
        /// </summary>
        /// <param name="screenRect">Screen rectangle for showing the popup.</param>
        public virtual void Show(Rectangle screenRect)
        {
            // Offset by the width/height of the shadow
            screenRect.X += SHADOW_SIZE;
            screenRect.Y += SHADOW_SIZE;

            // Update the screen position
            Location   = screenRect.Location;
            ClientSize = screenRect.Size;

            // Show the window without activating it (i.e. do not take focus)
            PI.ShowWindow(this.Handle, (short)PI.SW_SHOWNOACTIVATE);
            PI.SetWindowPos(this.Handle, (IntPtr)(-2), screenRect.X, screenRect.Y, screenRect.Width, screenRect.Height, 0x0010);
            PI.SetWindowPos(this.Handle, (IntPtr)(-1), screenRect.X, screenRect.Y, screenRect.Width, screenRect.Height, 0x0010);
            //  this.Visible = true;
            //  PI.SetWindowPos(this.Handle, (IntPtr)(-2), screenRect.X, screenRect.Y, screenRect.Width, screenRect.Height, 0x0010);
            //this.TopMost = true;
            //this.TopMost = false;
        }
Exemple #2
0
        /// <summary>
        /// Process Windows-based messages.
        /// </summary>
        /// <param name="m">A Windows-based message.</param>
        protected override void WndProc(ref Message m)
        {
            // We need to snoop the need to show a context menu
            if (m.Msg == PI.WM_CONTEXTMENU)
            {
                // Only interested in overriding the behavior when we have a krypton context menu...
                if (KryptonContextMenu != null)
                {
                    // Extract the screen mouse position (if might not actually be provided)
                    Point mousePt = new Point(PI.LOWORD(m.LParam), PI.HIWORD(m.LParam));

                    // If keyboard activated, the menu position is centered
                    if (((int)((long)m.LParam)) == -1)
                    {
                        mousePt = new Point(Width / 2, Height / 2);
                    }
                    else
                    {
                        mousePt = PointToClient(mousePt);

                        // Mouse point up and left 1 pixel so that the mouse overlaps the top left corner
                        // of the showing context menu just like it happens for a ContextMenuStrip.
                        mousePt.X -= 1;
                        mousePt.Y -= 1;
                    }

                    // If the mouse posiiton is within our client area
                    if (ClientRectangle.Contains(mousePt))
                    {
                        // Show the context menu
                        KryptonContextMenu.Show(this, PointToScreen(mousePt));

                        // We eat the message!
                        return;
                    }
                }
            }

            base.WndProc(ref m);
        }
        private bool ProcessMouseMoveWithCMS(ref Message m)
        {
            if (_current == null)
            {
                return(false);
            }

            // Convert the client position to screen point
            Point screenPt = CommonHelper.ClientMouseMessageToScreenPt(m);

            // Convert from a class to a structure
            PI.POINT screenPIPt = new PI.POINT();
            screenPIPt.x = screenPt.X;
            screenPIPt.y = screenPt.Y;

            // Get the window handle of the window under this screen point
            IntPtr hWnd = PI.WindowFromPoint(screenPIPt);

            // Is the window handle that of the currently tracking popup
            if (_current.Handle == hWnd)
            {
                return(true);
            }

            // Search all the stacked popups for any that match the window handle
            VisualPopup[] popups = _stack.ToArray();
            for (int i = 0; i < popups.Length; i++)
            {
                if (!popups[i].IsDisposed)
                {
                    if (popups[i].Handle == hWnd)
                    {
                        return(true);
                    }
                }
            }

            // Mouse move is not over a popup, so allow it
            return(false);
        }
Exemple #4
0
        private static string InternalShow(IWin32Window owner,
                                           string prompt,
                                           string caption,
                                           string defaultResponse)
        {
            IWin32Window showOwner = null;

            // If do not have an owner passed in then get the active window and use that instead
            if (owner == null)
            {
                showOwner = Control.FromHandle(PI.GetActiveWindow());
            }
            else
            {
                showOwner = owner;
            }

            // Show input box window as a modal dialog and then dispose of it afterwards
            using (KryptonInputBox ib = new KryptonInputBox(prompt, caption, defaultResponse))
            {
                if (showOwner == null)
                {
                    ib.StartPosition = FormStartPosition.CenterScreen;
                }
                else
                {
                    ib.StartPosition = FormStartPosition.CenterParent;
                }

                if (ib.ShowDialog(showOwner) == DialogResult.OK)
                {
                    return(ib.InputResponse);
                }
                else
                {
                    return(string.Empty);
                }
            }
        }
        private bool ProcessNonClientMouseDown(ref Message m)
        {
            // Extract the x and y mouse position from message
            Point screenPt = new Point(PI.LOWORD((int)m.LParam), PI.HIWORD((int)m.LParam));

            // Ask the popup if this message causes the entire stack to be killed
            if (_current.DoesCurrentMouseDownEndAllTracking(m, ScreenPtToClientPt(screenPt)))
            {
                EndAllTracking();
            }

            // Do any of the current popups want the mouse down to be eaten?
            bool processed = false;

            if (_current != null)
            {
                processed = _current.DoesMouseDownGetEaten(m, screenPt);
                if (!processed)
                {
                    // Search from end towards the front, the last entry is the most recent 'Push'
                    VisualPopup[] popups = _stack.ToArray();
                    for (int i = 0; i < popups.Length; i++)
                    {
                        // Ignore disposed popups
                        VisualPopup popup = popups[i];
                        if (!popup.IsDisposed)
                        {
                            processed = popup.DoesMouseDownGetEaten(m, screenPt);
                            if (processed)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(processed);
        }
        /// <summary>
        /// Perform a paint of the view.
        /// </summary>
        /// <param name="context">Renderer context.</param>
        public virtual void Paint(RenderContext context)
        {
            Debug.Assert(context != null);
            Debug.Assert(Root != null);

            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // Do nothing if the control is disposed or inside a layout call
            if (!_control.IsDisposed)
            {
                if (_outputDebug)
                {
                    PI.QueryPerformanceCounter(ref _outputStart);
                }

                // Ask the view to paint itself
                Root.Render(context);

                if (_outputDebug)
                {
                    long outputEnd = 0;
                    PI.QueryPerformanceCounter(ref outputEnd);
                    long outputDiff = outputEnd - _outputStart;

                    Console.WriteLine("Id:{0} Paint Type:{1} Elapsed: {2}",
                                      Id,
                                      _control.GetType().ToString(),
                                      outputDiff.ToString());
                }
            }

            // Maintain internal counters for measuring perf
            _paintCounter++;
        }
        /// <summary>
        /// Show the popup using the provided rectangle as the screen rect.
        /// </summary>
        /// <param name="screenRect">Screen rectangle for showing the popup.</param>
        public virtual void Show(Rectangle screenRect)
        {
            // Update the screen position
            SetBounds(screenRect.X, screenRect.Y,
                      screenRect.Width, screenRect.Height);

            // If we have a shadow then update it now
            if (_shadow != null)
            {
                _shadow.Show(screenRect);
            }

            // Show the window without activating it (i.e. do not take focus)
            PI.ShowWindow(this.Handle, (short)PI.SW_SHOWNOACTIVATE);
            PI.SetWindowPos(this.Handle, (IntPtr)(-1), screenRect.X, screenRect.Y, screenRect.Width, screenRect.Height, 0x0010);
            this.Visible = true;
            // PI.SetWindowPos(this.Handle, (IntPtr)(-2), screenRect.X, screenRect.Y, screenRect.Width, screenRect.Height, 0x0010);
            //this.BringToFront();
            //this.SetTopLevel(true);

            // Use manager to track mouse/keyboard input and to dismiss the window
            VisualPopupManager.Singleton.StartTracking(this);
        }
        /// <summary>
        /// Draw text with a glowing background, for use on a composition element.
        /// </summary>
        /// <param name="g">Graphics reference.</param>
        /// <param name="text">Text to be drawn.</param>
        /// <param name="font">Font to use for text.</param>
        /// <param name="bounds">Bounding area for the text.</param>
        /// <param name="state">State of the source element.</param>
        /// <param name="color">Color of the text.</param>
        /// <param name="copyBackground">Should existing background be copied into the bitmap.</param>
        public static void DrawCompositionGlowingText(Graphics g,
                                                      string text,
                                                      Font font,
                                                      Rectangle bounds,
                                                      PaletteState state,
                                                      Color color,
                                                      bool copyBackground)
        {
            try
            {
                // Get the hDC for the graphics instance and create a memory DC
                IntPtr gDC = g.GetHdc();
                IntPtr mDC = PI.CreateCompatibleDC(gDC);

                PI.BITMAPINFO bmi = new PI.BITMAPINFO();
                bmi.biSize        = Marshal.SizeOf(bmi);
                bmi.biWidth       = bounds.Width;
                bmi.biHeight      = -(bounds.Height + GLOW_EXTRA_HEIGHT * 2);
                bmi.biCompression = 0;
                bmi.biBitCount    = 32;
                bmi.biPlanes      = 1;

                // Create a device independant bitmp and select into the memory DC
                IntPtr hDIB = PI.CreateDIBSection(gDC, bmi, 0, 0, IntPtr.Zero, 0);
                PI.SelectObject(mDC, hDIB);

                if (copyBackground)
                {
                    // Copy existing background into the bitmap
                    PI.BitBlt(mDC, 0, 0, bounds.Width, bounds.Height + GLOW_EXTRA_HEIGHT * 2,
                              gDC, bounds.X, bounds.Y - GLOW_EXTRA_HEIGHT, 0x00CC0020);
                }

                // Select the font for use when drawing
                IntPtr hFont = font.ToHfont();
                PI.SelectObject(mDC, hFont);

                // Get renderer for the correct state
                VisualStyleRenderer renderer = new VisualStyleRenderer(state == PaletteState.Normal ? VisualStyleElement.Window.Caption.Active :
                                                                       VisualStyleElement.Window.Caption.Inactive);

                // Create structures needed for theme drawing call
                PI.RECT textBounds = new PI.RECT();
                textBounds.left   = 0;
                textBounds.top    = 0;
                textBounds.right  = (bounds.Right - bounds.Left);
                textBounds.bottom = (bounds.Bottom - bounds.Top) + (GLOW_EXTRA_HEIGHT * 2);
                PI.DTTOPTS dttOpts = new PI.DTTOPTS();
                dttOpts.dwSize    = Marshal.SizeOf(typeof(PI.DTTOPTS));
                dttOpts.dwFlags   = PI.DTT_COMPOSITED | PI.DTT_GLOWSIZE | PI.DTT_TEXTCOLOR;
                dttOpts.crText    = ColorTranslator.ToWin32(color);
                dttOpts.iGlowSize = 11;

                // Always draw text centered
                TextFormatFlags textFormat = TextFormatFlags.SingleLine |
                                             TextFormatFlags.HorizontalCenter |
                                             TextFormatFlags.VerticalCenter |
                                             TextFormatFlags.EndEllipsis;

                // Perform actual drawing
                PI.DrawThemeTextEx(renderer.Handle,
                                   mDC, 0, 0,
                                   text, -1, (int)textFormat,
                                   ref textBounds, ref dttOpts);

                // Copy to foreground
                PI.BitBlt(gDC,
                          bounds.Left, bounds.Top - GLOW_EXTRA_HEIGHT,
                          bounds.Width, bounds.Height + (GLOW_EXTRA_HEIGHT * 2),
                          mDC, 0, 0, 0x00CC0020);

                // Dispose of allocated objects
                PI.DeleteObject(hFont);
                PI.DeleteObject(hDIB);
                PI.DeleteDC(mDC);

                // Must remember to release the hDC
                g.ReleaseHdc(gDC);
            }
            catch
            {
            }
        }
 /// <summary>
 /// Shows the task dialog as a modal dialog box with the currently active window set as its owner.
 /// </summary>
 /// <returns>One of the DialogResult values.</returns>
 public DialogResult ShowDialog()
 {
     return(ShowDialog(Control.FromHandle(PI.GetActiveWindow())));
 }
        public bool PreFilterMessage(ref Message m)
        {
            // If we have suspended operation....
            if (_suspended > 0)
            {
                // Intercept the non-client mouse move to prevent the custom
                // chrome of the form from providing hot tracking feedback
                if (m.Msg == PI.WM_NCMOUSEMOVE)
                {
                    return(true);
                }

                // A mouse move can occur because a context menu is showing with a popup also
                // already showing. We suppress the mouse move to prevent tracking of the popup
                if (m.Msg == PI.WM_MOUSEMOVE)
                {
                    return(ProcessMouseMoveWithCMS(ref m));
                }

                return(false);
            }

            if (_current != null)
            {
                // If the popup has been become disposed
                if (_current.IsDisposed)
                {
                    EndCurrentTracking();
                    return(false);
                }
                else
                {
                    // Get the active window
                    IntPtr activeWindow = PI.GetActiveWindow();

                    // Is there a change in active window?
                    if (activeWindow != _activeWindow)
                    {
                        // If the current window has become active, ask popup if that is allowed
                        if ((activeWindow == _current.Handle) && _current.AllowBecomeActiveWhenCurrent)
                        {
                            _activeWindow = _current.Handle;
                        }
                        else
                        {
                            bool focus = _current.ContainsFocus;

                            if (!focus)
                            {
                                VisualPopup[] popups = _stack.ToArray();

                                // For from last to first for any popup that has the focus
                                for (int i = popups.Length - 1; i >= 0; i--)
                                {
                                    if (!popups[i].IsDisposed)
                                    {
                                        if (popups[i].ContainsFocus)
                                        {
                                            focus = true;
                                            break;
                                        }
                                    }
                                }
                            }

                            // If the change in active window (focus) is not to the current
                            // or a stacked popup then we need to pull down the entire stack
                            // as focus has been shifted away from the use of any popup.
                            if (!focus)
                            {
                                EndAllTracking();
                                return(false);
                            }
                        }
                    }
                }

                // We only intercept and handle keyboard and mouse messages
                if (!IsKeyOrMouseMessage(ref m))
                {
                    return(false);
                }

                switch (m.Msg)
                {
                case PI.WM_KEYDOWN:
                case PI.WM_SYSKEYDOWN:
                    // If the popup is telling us to redirect keyboard to itself
                    if (!_current.KeyboardInert)
                    {
                        // If the focus is not inside the actual current tracking popup
                        // then we need to manually translate the message to ensure that
                        // KeyPress events occur for the current popup.
                        if (!_current.ContainsFocus)
                        {
                            PI.MSG msg = new PI.MSG();
                            msg.hwnd    = m.HWnd;
                            msg.message = m.Msg;
                            msg.lParam  = m.LParam;
                            msg.wParam  = m.WParam;
                            PI.TranslateMessage(ref msg);
                        }
                        return(ProcessKeyboard(ref m));
                    }
                    break;

                case PI.WM_CHAR:
                case PI.WM_KEYUP:
                case PI.WM_DEADCHAR:
                case PI.WM_SYSCHAR:
                case PI.WM_SYSKEYUP:
                case PI.WM_SYSDEADCHAR:
                    // If the popup is telling us to redirect keyboard to itself
                    if (!_current.KeyboardInert)
                    {
                        return(ProcessKeyboard(ref m));
                    }
                    break;

                case PI.WM_MOUSEMOVE:
                case PI.WM_NCMOUSEMOVE:
                    return(ProcessMouseMove(ref m));

                case PI.WM_LBUTTONDOWN:
                case PI.WM_RBUTTONDOWN:
                case PI.WM_MBUTTONDOWN:
                    return(ProcessClientMouseDown(ref m));

                case PI.WM_NCLBUTTONDOWN:
                case PI.WM_NCRBUTTONDOWN:
                case PI.WM_NCMBUTTONDOWN:
                    return(ProcessNonClientMouseDown(ref m));
                }
            }

            return(false);
        }