Esempio n. 1
0
        private T CreateContextMenu <T>(CompactButton target) where T : CompactContextMenu, new()
        {
            T contextMenu = new T();

            contextMenu.Window          = Window;
            contextMenu.PlacementTarget = target;
            contextMenu.Placement       = PlacementMode.Bottom;
            //contextMenu.Placement = PlacementMode.Relative;
            //contextMenu.PlacementRectangle = new Rect(iconButton.Width, iconButton.Height, 100, 100);
            contextMenu.Build();
            if (contextMenu.HasItems)
            {
                contextMenu.IsOpen = true;
            }
            return(contextMenu);
        }
Esempio n. 2
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            switch (msg)
            {
            case Native.WM_NCHITTEST:
                Point pos = new Point((lParam.ToInt32() & 0xFFFF), (lParam.ToInt32() >> 16));
                pos = PointFromScreen(pos);

                var           result           = VisualTreeHelper.HitTest(this, pos);
                CompactButton button           = result.VisualHit as CompactButton;
                bool          ignoreButton     = false;
                bool          ignoreButtonDrag = false;
                if (button != null)
                {
                    if (button.IsControlBoxFade || button.IsControlBoxOverlay)
                    {
                        ignoreButton     = true;
                        ignoreButtonDrag = true;
                    }
                    else if (button.IsIconButton && Header.AllowBorderResizeOnIcon)
                    {
                        ignoreButton = true;
                    }
                    else if (button.IsControlBoxButton && Header.AllowBorderResizeOnControlBoxButton)
                    {
                        ignoreButton = true;
                    }
                    else if (!button.IsControlBoxButton && !button.IsIconButton && Header.AllowBorderResizeOnButtons)
                    {
                        ignoreButton = true;
                    }
                    else
                    {
                        break;
                    }
                }

                Rect leftRect        = new Rect(0, 0, BorderSize, ActualHeight);
                Rect rightRect       = new Rect(ActualWidth - BorderSize, 0, BorderSize, ActualHeight);
                Rect topRect         = new Rect(0, 0, ActualWidth, BorderSize);
                Rect bottomRect      = new Rect(0, ActualHeight - BorderSize, ActualWidth, BorderSize);
                Rect topLeftRect     = new Rect(0, 0, CornerSize, CornerSize);
                Rect topRightRect    = new Rect(ActualWidth - CornerSize, 0, CornerSize, CornerSize);
                Rect bottomLeftRect  = new Rect(0, ActualHeight - CornerSize, CornerSize, CornerSize);
                Rect bottomRightRect = new Rect(ActualWidth - CornerSize, ActualHeight - CornerSize, CornerSize, CornerSize);
                Rect captionRect     = new Rect(0, 0, ActualWidth, Header.HeaderSize);
                if (bottomRightRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTBOTTOMRIGHT);
                }
                else if (bottomLeftRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTBOTTOMLEFT);
                }
                else if (topLeftRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTTOPLEFT);
                }
                else if (topRightRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTTOPRIGHT);
                }
                else if (leftRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTLEFT);
                }
                else if (rightRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTRIGHT);
                }
                else if (topRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTTOP);
                }
                else if (bottomRect.Contains(pos))
                {
                    handled = true;
                    return((IntPtr)HitTest.HTBOTTOM);
                }
                else if (captionRect.Contains(pos))
                {
                    if ((result.VisualHit as CompactHeader) == null && (!ignoreButton || !Header.AllowWindowDragOnButtons) && !ignoreButtonDrag)
                    {
                        break;
                    }
                    handled = true;
                    return((IntPtr)HitTest.HTCAPTION);
                }
                else
                {
                    Cursor = Cursors.Arrow;
                }
                // Consume all NCHITTEST so that resize grip doesn't take control
                //handled = true;
                break;

            case Native.WM_GETMINMAXINFO:
                WmGetMinMaxInfo(hwnd, lParam);
                handled = true;
                break;
            }

            return(IntPtr.Zero);
        }
Esempio n. 3
0
        public CompactHeader(WPFCompactForm window)
        {
            Window = window;

            HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            HeaderSize          = 31;
            DrawItemPadding     = true;
            ItemPadding         = 1;
            //ItemPaddingBrush = new SolidColorBrush(Color.FromArgb(100, 255, 255, 255));

            FontFamily               = "Arial";
            FontSize                 = 13;
            TextPadding              = 6;
            TextColor                = Colors.White;
            TextBackgroundColor      = Color.FromArgb(25, 255, 255, 255);
            TextColorDeactivatedDraw = Colors.LightGray;

            ControlBoxFontFamily = "Arial";//Estrangelo Edessa
            ControlBoxFontSize   = 15;
            //ControlBoxImageColorOffset = Colors.Tomato;

            ControlBoxPaddingTop    = 3;
            ControlBoxPaddingBottom = 3;
            ControlBoxPaddingLeft   = 3;
            ControlBoxPaddingRight  = Window.BorderSize;
            ControlBoxFadeSize      = 25;

            IconPaddingBorder      = false;
            IconPaddingHalfBorder  = false;
            IconPaddingHalf2Border = true;
            if (IconPaddingHalf2Border)
            {
                IconPadding = (int)(Window.BorderSize / 1.2f);
            }
            else if (IconPaddingHalfBorder)
            {
                IconPadding = Window.BorderSize / 2;
            }
            else if (IconPaddingBorder)
            {
                IconPadding = Window.BorderSize;
            }

            AllowBorderResizeOnButtons = true;
            AllowWindowDragOnButtons   = false;
            AdditionalWindowDrag       = true;

            //DrawDeactivated = true;

            Window.Activated   += Window_Activated;
            Window.Deactivated += Window_Deactivated;

            creatingLayout = true;

            ///////////////////////////////////////////////////
            // Left controls
            ///////////////////////////////////////////////////

            iconButton = new CompactButton(this);
            iconButton.IsIconButton = true;
            iconButton.Click       += iconButton_Click;
            leftButtons.Add(iconButton);
            Children.Add(iconButton);

            languageButton        = new CompactButton(this);
            languageButton.Click += languageButton_Click;
            leftButtons.Add(languageButton);
            Children.Add(languageButton);

            layoutButton        = new CompactButton(this);
            layoutButton.Click += layoutButton_Click;
            leftButtons.Add(layoutButton);
            Children.Add(layoutButton);

            ocrEngineButton        = new CompactButton(this);
            ocrEngineButton.Click += ocrEngineButton_Click;
            leftButtons.Add(ocrEngineButton);
            Children.Add(ocrEngineButton);

            ocrEngineProfileButton        = new CompactButton(this);
            ocrEngineProfileButton.Click += ocrEngineProfileButton_Click;
            leftButtons.Add(ocrEngineProfileButton);
            Children.Add(ocrEngineProfileButton);

            translateAPIButton        = new CompactButton(this);
            translateAPIButton.Click += translateAPIButton_Click;
            leftButtons.Add(translateAPIButton);
            Children.Add(translateAPIButton);

            captureButton        = new CompactButton(this);
            captureButton.Click += captureButton_Click;
            leftButtons.Add(captureButton);
            Children.Add(captureButton);

            captureAreaButton        = new CompactButton(this);
            captureAreaButton.Click += captureAreaButton_Click;
            leftButtons.Add(captureAreaButton);
            Children.Add(captureAreaButton);

            captureAreaFrozenButton        = new CompactButton(this);
            captureAreaFrozenButton.Click += captureAreaFrozenButton_Click;
            leftButtons.Add(captureAreaFrozenButton);
            Children.Add(captureAreaFrozenButton);

            captureAreaEditableButton        = new CompactButton(this);
            captureAreaEditableButton.Click += captureAreaEditableButton_Click;
            leftButtons.Add(captureAreaEditableButton);
            Children.Add(captureAreaEditableButton);

            //iconButton.IsEnabled = false;
            //languageButton.IsEnabled = false;
            //layoutButton.IsEnabled = false;
            //ocrEngineButton.IsEnabled = false;
            //ocrEngineProfileButton.IsEnabled = false;
            translateAPIButton.IsEnabled = false;

            captureButton.IsEnabled             = false;
            captureAreaButton.IsEnabled         = false;
            captureAreaFrozenButton.IsEnabled   = false;
            captureAreaEditableButton.IsEnabled = false;

            ///////////////////////////////////////////////////
            // Right controls
            ///////////////////////////////////////////////////

            sizeControlsOverlay = new CompactButton(this);
            sizeControlsOverlay.IsControlBoxOverlay = true;
            Children.Add(sizeControlsOverlay);
            Canvas.SetRight(sizeControlsOverlay, 0);

            sizeControlsFadeOverlay = new CompactButton(this);
            sizeControlsFadeOverlay.IsControlBoxFade = true;
            Children.Add(sizeControlsFadeOverlay);

            closeButton = new CompactButton(this);
            closeButton.IsControlBoxButton = true;
            closeButton.Click += closeButton_Click;
            rightButtons.Add(closeButton);
            Children.Add(closeButton);

            minimizeButton = new CompactButton(this);
            minimizeButton.IsControlBoxButton = true;
            minimizeButton.Click += minimizeButton_Click;
            rightButtons.Add(minimizeButton);
            Children.Add(minimizeButton);

            Canvas.SetZIndex(sizeControlsFadeOverlay, 999);
            Canvas.SetZIndex(sizeControlsOverlay, 1000);
            Canvas.SetZIndex(closeButton, 1001);
            Canvas.SetZIndex(minimizeButton, 1002);

            iconButton.Width           += IconPadding * 2;
            iconButton.Image            = Properties.Resources.Default27.ToBitmapImage();
            iconButton.DeactivatedImage = Properties.Resources.LostFocus27.ToBitmapImage();

            //minimizeButton.Text = "_";
            //minimizeButton.TextOffset = new Point(0, -2);
            //closeButton.Text = "X";
            //closeButton.TextOffset = new Point(0, 0);
            if (ControlBoxImageColorOffset != default(Color))
            {
                using (var closeImage = Properties.Resources.Close.ColorTint(ControlBoxImageColorOffset))
                {
                    closeButton.Image = closeImage.ToBitmapImage();
                }
                using (var minimizeImage = Properties.Resources.Minimize.ColorTint(ControlBoxImageColorOffset))
                {
                    minimizeButton.Image = minimizeImage.ToBitmapImage();
                }
            }
            else
            {
                closeButton.Image    = Properties.Resources.Close.ToBitmapImage();
                minimizeButton.Image = Properties.Resources.Minimize.ToBitmapImage();
            }
            closeButton.HoverBackColor    = Color.FromArgb(0xFF, 0xFC, 0x3A, 0x3A).DarkenBy(3);
            minimizeButton.HoverBackColor = Color.FromArgb(0xFF, 0x37, 0x9D, 0xE6);
            closeButton.PressBackColor    = closeButton.HoverBackColor.DarkenBy(12);
            minimizeButton.PressBackColor = minimizeButton.HoverBackColor.DarkenBy(12);

            languageButton.Text         = "Chinese (Traditional) - English";
            layoutButton.Text           = "Translated";
            ocrEngineButton.Text        = "Windows";
            ocrEngineProfileButton.Text = "1x Linear";

            creatingLayout = false;
            Layout();
        }