示例#1
0
        /// <summary>
        /// Extracts a PDF page as a Bitmap for a given pdf source and a page number.
        /// </summary>
        /// <param name="source">The PDF source</param>
        /// <param name="pageNumber">Page number, starting at 0</param>
        /// <param name="zoomFactor">Used to get a smaller or bigger Bitmap, depending on the specified value</param>
        /// <param name="password">The password for the pdf file (if required)</param>
        public static BitmapSource ExtractPageAtScale(IPdfSource source, int pageNumber, float zoomFactor = 1.0f, string password = null)
        {
            if (pageNumber < 0 || pageNumber >= CountPages(source))
            {
                throw new ArgumentOutOfRangeException("pageNumber", "The page \"" + pageNumber + "\" does not exist !");
            }

            using (var stream = new PdfFileStream(source))
            {
                ValidatePassword(stream.Document, password);

                IntPtr p          = NativeMethods.LoadPage(stream.Document, pageNumber); // loads the page
                var    currentDpi = DpiHelper.GetCurrentDpi();
                var    bmp        = RenderPageAtScale(stream.Context, stream.Document, p, zoomFactor, currentDpi.HorizontalDpi, currentDpi.VerticalDpi);
                NativeMethods.FreePage(stream.Document, p); // releases the resources consumed by the page

                return(bmp.ToBitmapSource());
            }
        }
示例#2
0
        protected override void OnHandleCreated(EventArgs e)
        {
            try
            {
                UxTheme.SetWindowTheme(Handle, string.Empty, string.Empty);
                User32.DisableProcessWindowsGhosting();

                ScaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(Handle);
            }
            catch { }

            base.OnHandleCreated(e);



            CheckResetDPIAutoScale(true);

            ResumeLayout();
        }
示例#3
0
        /// <summary>
        /// Handles the OnPait event of the <see cref="DialogForm"/> dialog.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            int buttonHeight = mShowFooterArea ? DpiHelper.RescaleByDpiY(BUTTON_AREA_HEIGHT) : 0;

            using (Brush contentBrush = new SolidBrush(ContentColor))
            {
                e.Graphics.FillRectangle(
                    contentBrush
                    , new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height - buttonHeight));
            }

            // Set the TextRenderingHint to clear type.
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;

            // Draw the dialog as a default dialog.
            DrawDialogBackground(e.Graphics);
        }
        private IntPtr _HandleNCHITTEST(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            // We always want to handle hit-testing
            handled = true;

            var dpi = this.AssociatedObject.GetDpi();

            // Let the system know if we consider the mouse to be in our effective non-client area.
            var mousePosScreen = Utility.GetPoint(lParam); //new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam));
            var windowPosition = this._GetWindowRect();

            var mousePosWindow = mousePosScreen;

            mousePosWindow.Offset(-windowPosition.X, -windowPosition.Y);
            mousePosWindow = DpiHelper.DevicePixelsToLogical(mousePosWindow, dpi.DpiScaleX, dpi.DpiScaleY);

            var ht = this._HitTestNca(DpiHelper.DeviceRectToLogical(windowPosition, dpi.DpiScaleX, dpi.DpiScaleY),
                                      DpiHelper.DevicePixelsToLogical(mousePosScreen, dpi.DpiScaleX, dpi.DpiScaleY));

            if (ht != HT.CLIENT ||
                this.AssociatedObject.ResizeMode == ResizeMode.CanResizeWithGrip)
            {
                // If the app is asking for content to be treated as client then that takes precedence over _everything_, even DWM caption buttons.
                // This allows apps to set the glass frame to be non-empty, still cover it with WPF content to hide all the glass,
                // yet still get DWM to draw a drop shadow.
                var inputElement = this.AssociatedObject.InputHitTest(mousePosWindow);
                if (inputElement is not null)
                {
                    if (WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                    {
                        return(new IntPtr((int)HT.CLIENT));
                    }

                    var direction = WindowChrome.GetResizeGripDirection(inputElement);
                    if (direction != ResizeGripDirection.None)
                    {
                        return(new IntPtr((int)this._GetHTFromResizeGripDirection(direction)));
                    }
                }
            }

            return(new IntPtr((int)ht));
        }
        public BorderlessWindow()
        {
            this.WindowState   = FormWindowState.Maximized;
            base.AutoScaleMode = AutoScaleMode.None;

            base.BackColor = Color.White;

            DpiHelper.InitializeDpiHelper();

            InitializeReflectedFields();

            _deviceDpi = DpiHelper.DeviceDpi;



            _shadowDecorator = new ShadowDecorator(this, false);

            SuspendLayout();
        }
示例#6
0
        private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            var mousePosScreen = new Point(Utility.GET_X_LPARAM(lParam), Utility.GET_Y_LPARAM(lParam));
            var windowPosition = _GetWindowRect();
            var mousePosWindow = mousePosScreen;

            mousePosWindow.Offset(-windowPosition.X, -windowPosition.Y);
            mousePosWindow = DpiHelper.DevicePixelsToLogical(mousePosWindow);

            var inputElement = _window.InputHitTest(mousePosWindow);

            if (inputElement != null)
            {
                if (WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                {
                    handled = true;
                    return(new IntPtr((int)HT.CLIENT));
                }
                var direction = WindowChrome.GetResizeGripDirection(inputElement);
                if (direction != ResizeGripDirection.None)
                {
                    handled = true;
                    return(new IntPtr((int)_GetHTFromResizeGripDirection(direction)));
                }
            }

            if (_chromeInfo.UseAeroCaptionButtons)
            {
                if (Utility.IsOSVistaOrNewer && _chromeInfo.GlassFrameThickness != default(Thickness) && _isGlassEnabled)
                {
                    IntPtr lRet;
                    handled = NativeMethods.DwmDefWindowProc(_hwnd, uMsg, wParam, lParam, out lRet);
                    if (IntPtr.Zero != lRet)
                    {
                        return(lRet);
                    }
                }
            }
            var ht = _HitTestNca(DpiHelper.DeviceRectToLogical(windowPosition), DpiHelper.DevicePixelsToLogical(mousePosScreen));

            handled = true;
            return(new IntPtr((int)ht));
        }
示例#7
0
        public void StartDrawing(List <Point> startPoints)
        {
            if (_settingsChanged)
            {
                _settingsChanged = false;
                InitializeForm();
            }

            if (_penWidth <= 0)
            {
                return;
            }

            ClearSurfaces();

            //follow dynamic system color
            _drawingPen.Color = AppConfig.VisualFeedbackColor;
            _drawingPen.Width = _penWidth * DpiHelper.GetScreenDpi(startPoints.FirstOrDefault()) / 96f;
        }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebViewHost"/> class.
        /// </summary>
        protected WebViewHost()
        {
            DpiHelper.SetPerMonitorDpiAwareness();
            DpiScale = VisualTreeHelper.GetDpi(this);

            DpiChanged  += OnDpiChanged;
            SizeChanged += OnSizeChanged;

#if DEBUG_FOCUS
            GotFocus          += (o, e) => { Debug.WriteLine($"GotFocus"); };
            GotKeyboardFocus  += (o, e) => { Debug.WriteLine("GotKeyboardFocus"); };
            LostFocus         += (o, e) => { Debug.WriteLine($"LostFocus"); };
            LostKeyboardFocus += (o, e) => { Debug.WriteLine("LostKeyboardFocus"); };
            KeyUp             += (o, e) =>
            {
                Debug.WriteLine($"KeyUp: Key: {e.Key}, SystemKey: {e.SystemKey}");
            };
#endif
        }
        public void EnsureFloatingSiteInVisibleBounds(FloatSite site)
        {
            Rect        logicalRect = new Rect(site.FloatingLeft, site.FloatingTop, site.FloatingWidth, site.FloatingHeight);
            RECT        lprc        = new RECT(DpiHelper.LogicalToDeviceUnits(logicalRect));
            IntPtr      hMonitor    = Microsoft.VisualStudio.PlatformUI.NativeMethods.MonitorFromRect(ref lprc, 1U);
            MONITORINFO monitorInfo = new MONITORINFO();

            monitorInfo.cbSize = (uint)Marshal.SizeOf((object)monitorInfo);
            if (!Microsoft.VisualStudio.PlatformUI.NativeMethods.GetMonitorInfo(hMonitor, ref monitorInfo))
            {
                return;
            }
            Rect rect  = DpiHelper.DeviceToLogicalUnits(monitorInfo.rcWork.WPFRectValue);
            bool flag1 = logicalRect.Right < rect.Left + (double)this.MonitorPadding;
            bool flag2 = logicalRect.Left > rect.Right - (double)this.MonitorPadding;
            bool flag3 = logicalRect.Top < rect.Top + (double)this.MonitorPadding;
            bool flag4 = logicalRect.Top > rect.Bottom - (double)this.MonitorPadding;

            if (!flag1 && !flag2 && (!flag3 && !flag4))
            {
                return;
            }
            if (flag1)
            {
                site.FloatingLeft = rect.Left;
            }
            else if (flag2)
            {
                site.FloatingLeft = rect.Right - site.FloatingWidth;
            }
            if (flag3)
            {
                site.FloatingTop = rect.Top;
            }
            else
            {
                if (!flag4)
                {
                    return;
                }
                site.FloatingTop = rect.Bottom - site.FloatingHeight;
            }
        }
示例#10
0
        protected override void GetViewRect(CefBrowser browser, out CefRectangle rect)
        {
            var handle = _owner.HostWindowHandle;

            var scaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(handle);

            var clientRect = new RECT();

            rect = new CefRectangle();


            User32.GetClientRect(handle, ref clientRect);

            rect.X = rect.Y = 0;


            if (User32.IsIconic(handle) || clientRect.Width == 0 || clientRect.Height == 0)
            {
                var placement = new WINDOWPLACEMENT();

                User32.GetWindowPlacement(_owner.HostWindowHandle, ref placement);

                clientRect = placement.rcNormalPosition;

                rect.Width = (int)(clientRect.Width / scaleFactor);

                rect.Height = (int)(clientRect.Height / scaleFactor);
            }
            else
            {
                rect.Width  = (int)(clientRect.Width / scaleFactor);
                rect.Height = (int)(clientRect.Height / scaleFactor);
            }


            if (clientRect.Width != _view_width || clientRect.Height != _view_height)
            {
                _view_width  = clientRect.Width;
                _view_height = clientRect.Height;

                _renderTarget?.Resize(new Vortice.Mathematics.Size(_view_width, _view_height));
            }
        }
 private void _FixupRestoreBounds(object sender, EventArgs e)
 {
     if ((_window.WindowState == WindowState.Maximized || _window.WindowState == WindowState.Minimized) &&
         _hasUserMovedWindow)
     {
         _hasUserMovedWindow = false;
         var windowPlacement = NativeMethods.GetWindowPlacement(_hwnd);
         var rcWindow        = new RECT
         {
             Bottom = 100,
             Right  = 100
         };
         var rect  = _GetAdjustedWindowRect(rcWindow);
         var point = DpiHelper.DevicePixelsToLogical(new Point(windowPlacement.rcNormalPosition.Left - rect.Left,
                                                               windowPlacement.rcNormalPosition.Top - rect.Top));
         _window.Top  = point.Y;
         _window.Left = point.X;
     }
 }
        /// <summary>
        /// <see cref="FrameworkElement.Loaded"/> event handler.
        /// </summary>
        /// <param name="sender">event sender.</param>
        /// <param name="args">event arguments.</param>
        protected virtual void OnLoaded(object sender, RoutedEventArgs args)
        {
            // WPF has already scaled window size, graphics and text based on system DPI. In order to scale the window based on monitor DPI, update the
            // window size, graphics and text based on monitor DPI. For example consider an application with size 600 x 400 in device independent pixels
            //		- Size in device independent pixels = 600 x 400
            //		- Size calculated by WPF based on system/WPF DPI = 192 (scale factor = 2)
            //		- Expected size based on monitor DPI = 144 (scale factor = 1.5)

            // Similarly the graphics and text are updated updated by applying appropriate scale transform to the top level node of the WPF application

            // Important Note: This method overwrites the size of the window and the scale transform of the root node of the WPF Window. Hence,
            // this sample may not work "as is" if
            //	- The size of the window impacts other portions of the application like this WPF  Window being hosted inside another application.
            //  - The WPF application that is extending this class is setting some other transform on the root visual; the sample may
            //     overwrite some other transform that is being applied by the WPF application itself.

            SystemDpi = DpiHelper.GetSystemDpi();
            var source = (HwndSource)PresentationSource.FromVisual(this);

            source?.AddHook(WindowProcedureHook);

            // Calculate the DPI used by WPF.
            var transform = source?.CompositionTarget?.TransformToDevice;

            WpfDpi = new DPI(96 * (transform?.M11 ?? 1), 96 * (transform?.M22 ?? 1));

            if (IsPerMonitorEnabled && (source != null))
            {
                // Get the Current DPI of the monitor of the window.
                CurrentDpi = DpiHelper.GetDpiForHwnd(source.Handle);

                // Calculate the scale factor used to modify window size, graphics and text.
                ScaleFactor = new DPI(CurrentDpi.X / WpfDpi.X, CurrentDpi.Y / WpfDpi.Y);
            }

            UpdateWindowSize();
            UpdateLocation();

            // Update graphics and text based on the current DPI of the monitor.
            UpdateLayoutTransform(ScaleFactor);
            OnDpiChanged();
        }
示例#13
0
        // Helper to generate the image - I grabbed this off Google
        // somewhere. -- Chris Bordeman [email protected]
        private static BitmapSource CaptureScreen(Visual target, FlowDirection flowDirection)
        {
            if (target == null)
            {
                return(null);
            }

            var dpiX = DpiHelper.DpiX;
            var dpiY = DpiHelper.DpiY;

            var bounds    = VisualTreeHelper.GetDescendantBounds(target);
            var dpiBounds = DpiHelper.LogicalRectToDevice(bounds);

            var pixelWidth  = (int)Math.Ceiling(dpiBounds.Width);
            var pixelHeight = (int)Math.Ceiling(dpiBounds.Height);

            if (pixelWidth < 0 || pixelHeight < 0)
            {
                return(null);
            }

            var rtb = new RenderTargetBitmap(pixelWidth, pixelHeight, dpiX, dpiY, PixelFormats.Pbgra32);

            var dv = new DrawingVisual();

            using (var ctx = dv.RenderOpen())
            {
                var vb = new VisualBrush(target);
                if (flowDirection == FlowDirection.RightToLeft)
                {
                    var transformGroup = new TransformGroup();
                    transformGroup.Children.Add(new ScaleTransform(-1, 1));
                    transformGroup.Children.Add(new TranslateTransform(bounds.Size.Width - 1, 0));
                    ctx.PushTransform(transformGroup);
                }
                ctx.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
            }

            rtb.Render(dv);

            return(rtb);
        }
示例#14
0
        public ImagePanel()
        {
            InitializeComponent();

            var scale = DpiHelper.GetCurrentScaleFactor();

            backgroundBrush.Viewport = new Rect(new Size(
                                                    backgroundBrush.ImageSource.Width / scale.Horizontal,
                                                    backgroundBrush.ImageSource.Height / scale.Vertical));

            SizeChanged += ImagePanel_SizeChanged;

            viewPanel.PreviewMouseWheel   += ViewPanel_PreviewMouseWheel;
            viewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown;
            viewPanel.MouseMove           += ViewPanel_MouseMove;

            viewPanel.ManipulationInertiaStarting += ViewPanel_ManipulationInertiaStarting;
            viewPanel.ManipulationStarting        += ViewPanel_ManipulationStarting;
            viewPanel.ManipulationDelta           += ViewPanel_ManipulationDelta;
        }
示例#15
0
        public GifProvider(string path, MetaProvider meta) : base(path, meta)
        {
            if (!ImageAnimator.CanAnimate(Image.FromFile(path)))
            {
                _nativeProvider = new NativeProvider(path, meta);
                return;
            }

            _fileHandle = (Bitmap)Image.FromFile(path);

            _fileHandle.SetResolution(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
                                      DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

            Animator = new Int32AnimationUsingKeyFrames {
                RepeatBehavior = RepeatBehavior.Forever
            };
            Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(10))));
            Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(2, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(20))));
        }
示例#16
0
        public static ImageList GetThemedImageList(Bitmap bitmap, ThemeResourceKey backgroundColorKey)
        {
            Debug.Assert(bitmap != null, "bitmap != null");
            bitmap.MakeTransparent(TransparentColor);
            var themedBitmap = ThemeBitmap(bitmap, VSColorTheme.GetThemedColor(backgroundColorKey));
            var imageList    = new ImageList
            {
                ColorDepth = ColorDepth.Depth32Bit,
                ImageSize  = new Size(16, 16)
            };

            imageList.Images.AddStrip(themedBitmap);

#pragma warning disable 0618 // DpiHelper is obsolete, need to move to DpiAwareness (and ImageManifest)
            // scales images as appropriate for screen resolution
            DpiHelper.LogicalToDeviceUnits(ref imageList);
#pragma warning restore 0618

            return(imageList);
        }
示例#17
0
 private void _FixupRestoreBounds(object sender, EventArgs e)
 {
     Assert.IsTrue(_IsPresentationFrameworkVersionLessThan4);
     if (_window.WindowState == WindowState.Maximized || _window.WindowState == WindowState.Minimized)
     {
         if (_hasUserMovedWindow)
         {
             _hasUserMovedWindow = false;
             var wp = NativeMethods.GetWindowPlacement(_hwnd);
             var adjustedDeviceRc = _GetAdjustedWindowRect(new RECT {
                 Bottom = 100, Right = 100
             });
             var adjustedTopLeft =
                 DpiHelper.DevicePixelsToLogical(new Point(wp.rcNormalPosition.Left - adjustedDeviceRc.Left,
                                                           wp.rcNormalPosition.Top - adjustedDeviceRc.Top));
             _window.Top  = adjustedTopLeft.Y;
             _window.Left = adjustedTopLeft.X;
         }
     }
 }
示例#18
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (BackgroundImage != null && Height > 0 && Width > 0)
            {
                Rectangle imageDimensions = new Rectangle(
                    0
                    , 0
                    , BackgroundImage.Width
                    , BackgroundImage.Height);

                e.Graphics.DrawImage(BackgroundImage, new Rectangle(
                                         0
                                         , 0
                                         , DpiHelper.RescaleByDpiX(imageDimensions.Width)
                                         , DpiHelper.RescaleByDpiY(imageDimensions.Height))
                                     , imageDimensions
                                     , GraphicsUnit.Pixel);
            }
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (provider is null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc is null)
            {
                throw new InvalidOperationException("Service provider couldn't fetch " + nameof(edSvc));
            }

            IUIService uiService = (IUIService)provider.GetService(typeof(IUIService));
            IComponent comp      = context.Instance as IComponent;

            using (DpiHelper.EnterDpiAwarenessScope(User32.DPI_AWARENESS_CONTEXT.SYSTEM_AWARE))
            {
                _builderDialog ??= new DataGridViewCellStyleBuilder(provider, comp);
                if (uiService != null)
                {
                    _builderDialog.Font = (Font)uiService.Styles["DialogFont"];
                }

                if (value is DataGridViewCellStyle dgvcs)
                {
                    _builderDialog.CellStyle = dgvcs;
                }

                _builderDialog.Context = context;
                if (_builderDialog.ShowDialog() == DialogResult.OK)
                {
                    value = _builderDialog.CellStyle;
                }
            }

            return(value);
        }
示例#20
0
        protected override void OnCreateControl()
        {
            base.OnCreateControl();
            Scale(new SizeF(ScaleFactor, ScaleFactor));

            if (!DesignMode)
            {
                //


                var currentScreenScaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(Handle);

                var primaryScreenScaleFactor = DpiHelper.GetScreenDpi(Screen.PrimaryScreen) / 96f;

                if (primaryScreenScaleFactor != 1.0f)
                {
                    Font = new Font(Font.FontFamily, (float)Math.Round(Font.Size / primaryScreenScaleFactor), Font.Style);
                }

                Font = new Font(Font.FontFamily, (float)Math.Round(Font.Size * currentScreenScaleFactor), Font.Style);
            }
        }
        public override Task <BitmapSource> GetRenderedFrame(int index)
        {
            var fullSize = Meta.GetSize();

            return(new Task <BitmapSource>(() =>
            {
                try
                {
                    using (var mi = new MagickImage(Path))
                    {
                        var profile = mi.GetColorProfile();
                        if (profile?.Description != null && !profile.Description.Contains("sRGB"))
                        {
                            mi.SetProfile(ColorProfile.SRGB);
                        }

                        mi.AutoOrient();

                        if (mi.Width != (int)fullSize.Width || mi.Height != (int)fullSize.Height)
                        {
                            mi.Resize((int)fullSize.Width, (int)fullSize.Height);
                        }

                        mi.Density = new Density(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
                                                 DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

                        var img = mi.ToBitmapSource(BitmapDensity.Use);

                        img.Freeze();
                        return img;
                    }
                }
                catch (Exception e)
                {
                    ProcessHelper.WriteLog(e.ToString());
                    return null;
                }
            }));
        }
示例#22
0
        protected override void OnDraggableRegionsChanged(CefBrowser browser, CefFrame frame, CefDraggableRegion[] regions)
        {
            if (_owner.WebView.DraggableRegion != null)
            {
                _owner.WebView.DraggableRegion.Dispose();
                _owner.WebView.DraggableRegion = null;
            }

            if (regions.Length > 0)
            {
                var scaleFactor = DpiHelper.GetScaleFactorForCurrentWindow(_owner.WebView.BrowserHost.GetWindowHandle());
                //DpiHelper.GetScaleFactorForCurrentWindow(_owner.WebView.BrowserHost.GetWindowHandle());


                //var targetRegion = _core.DraggableRegion = new Region();


                foreach (var region in regions)
                {
                    var rect = new Rectangle((int)(region.Bounds.X * scaleFactor), (int)(region.Bounds.Y * scaleFactor), (int)(region.Bounds.Width * scaleFactor), (int)(region.Bounds.Height * scaleFactor));

                    if (_owner.WebView.DraggableRegion == null)
                    {
                        _owner.WebView.DraggableRegion = new Region(rect);
                    }
                    else
                    {
                        if (region.Draggable)
                        {
                            _owner.WebView.DraggableRegion.Union(rect);
                        }
                        else
                        {
                            _owner.WebView.DraggableRegion.Exclude(rect);
                        }
                    }
                }
            }
        }
 private void _FixupFrameworkIssues()
 {
     if (Utility.IsPresentationFrameworkVersionLessThan4 && _window.Template != null)
     {
         if (VisualTreeHelper.GetChildrenCount(_window) == 0)
         {
             _window.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new _Action(_FixupFrameworkIssues));
         }
         else
         {
             var child      = (FrameworkElement)VisualTreeHelper.GetChild(_window, 0);
             var windowRect = NativeMethods.GetWindowRect(_hwnd);
             var rect2      = _GetAdjustedWindowRect(windowRect);
             var rect3      = DpiHelper.DeviceRectToLogical(new Rect(windowRect.Left, windowRect.Top,
                                                                     windowRect.Width, windowRect.Height));
             var rect4 = DpiHelper.DeviceRectToLogical(
                 new Rect(rect2.Left, rect2.Top, rect2.Width, rect2.Height));
             var thickness = new Thickness(rect3.Left - rect4.Left, rect3.Top - rect4.Top,
                                           rect4.Right - rect3.Right, rect4.Bottom - rect3.Bottom);
             child.Margin = new Thickness(0.0, 0.0, -(thickness.Left + thickness.Right),
                                          -(thickness.Top + thickness.Bottom));
             if (_window.FlowDirection == FlowDirection.RightToLeft)
             {
                 child.RenderTransform =
                     new MatrixTransform(1.0, 0.0, 0.0, 1.0, -(thickness.Left + thickness.Right), 0.0);
             }
             else
             {
                 child.RenderTransform = null;
             }
             if (!_isFixedUp)
             {
                 _hasUserMovedWindow   = false;
                 _window.StateChanged += _FixupRestoreBounds;
                 _isFixedUp            = true;
             }
         }
     }
 }
        private IntPtr _HandleNCHitTest(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
        {
            DpiScale dpi             = this._window.GetDpi();
            Point    point           = new Point((double)Utility.GET_X_LPARAM(lParam), (double)Utility.GET_Y_LPARAM(lParam));
            Rect     deviceRectangle = this._GetWindowRect();
            Point    point2          = point;

            point2.Offset(-deviceRectangle.X, -deviceRectangle.Y);
            point2 = DpiHelper.DevicePixelsToLogical(point2, dpi.DpiScaleX, dpi.DpiScaleY);
            IInputElement inputElement = this._window.InputHitTest(point2);

            if (inputElement != null)
            {
                if (WindowChrome.GetIsHitTestVisibleInChrome(inputElement))
                {
                    handled = true;
                    return(new IntPtr(1));
                }
                ResizeGripDirection resizeGripDirection = WindowChrome.GetResizeGripDirection(inputElement);
                if (resizeGripDirection != ResizeGripDirection.None)
                {
                    handled = true;
                    return(new IntPtr((int)this._GetHTFromResizeGripDirection(resizeGripDirection)));
                }
            }
            if (this._chromeInfo.UseAeroCaptionButtons && Utility.IsOSVistaOrNewer && this._chromeInfo.GlassFrameThickness != default(Thickness) && this._isGlassEnabled)
            {
                IntPtr intPtr;
                handled = NativeMethods.DwmDefWindowProc(this._hwnd, uMsg, wParam, lParam, out intPtr);
                if (IntPtr.Zero != intPtr)
                {
                    return(intPtr);
                }
            }
            HT value = this._HitTestNca(DpiHelper.DeviceRectToLogical(deviceRectangle, dpi.DpiScaleX, dpi.DpiScaleY), DpiHelper.DevicePixelsToLogical(point, dpi.DpiScaleX, dpi.DpiScaleY));

            handled = true;
            return(new IntPtr((int)value));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="WebViewHost"/> class.
        /// </summary>
        protected WebViewHost()
        {
            DpiHelper.Initialize();
            DpiHelper.SetPerMonitorDpiAwareness();

            // Get system DPI
            DeviceDpi = DpiHelper.DeviceDpi;

            DpiChanged  += OnDpiChanged;
            SizeChanged += OnSizeChanged;

#if DEBUG_FOCUS
            GotFocus          += (o, e) => { Debug.WriteLine($"GotFocus"); };
            GotKeyboardFocus  += (o, e) => { Debug.WriteLine("GotKeyboardFocus"); };
            LostFocus         += (o, e) => { Debug.WriteLine($"LostFocus"); };
            LostKeyboardFocus += (o, e) => { Debug.WriteLine("LostKeyboardFocus"); };
            KeyUp             += (o, e) =>
            {
                Debug.WriteLine($"KeyUp: Key: {e.Key}, SystemKey: {e.SystemKey}");
            };
#endif
        }
示例#26
0
        private HRESULT _UpdateThumbnailClipping(bool attached)
        {
            RefRECT prcClip = null;

            if (attached && this.ThumbnailClipMargin != TaskbarItemInfo._EmptyThickness)
            {
                Thickness thumbnailClipMargin = this.ThumbnailClipMargin;
                RECT      clientRect          = NativeMethods.GetClientRect(this._hwndSource.Handle);
                Rect      rect = DpiHelper.DeviceRectToLogical(new Rect((double)clientRect.Left, (double)clientRect.Top, (double)clientRect.Width, (double)clientRect.Height));
                if (thumbnailClipMargin.Left + thumbnailClipMargin.Right >= rect.Width || thumbnailClipMargin.Top + thumbnailClipMargin.Bottom >= rect.Height)
                {
                    prcClip = new RefRECT(0, 0, 0, 0);
                }
                else
                {
                    Rect logicalRectangle = new Rect(thumbnailClipMargin.Left, thumbnailClipMargin.Top, rect.Width - thumbnailClipMargin.Left - thumbnailClipMargin.Right, rect.Height - thumbnailClipMargin.Top - thumbnailClipMargin.Bottom);
                    Rect rect2            = DpiHelper.LogicalRectToDevice(logicalRectangle);
                    prcClip = new RefRECT((int)rect2.Left, (int)rect2.Top, (int)rect2.Right, (int)rect2.Bottom);
                }
            }
            return(this._taskbarList.SetThumbnailClip(this._hwndSource.Handle, prcClip));
        }
示例#27
0
        public DatabaseObjectTreeView()
        {
            InitializeComponent();

            components = new Container();

            // Load new ImageList with glyphs from resources
            var imageList = new ImageList(components)
            {
                ColorDepth       = ColorDepth.Depth32Bit,
                ImageSize        = new Size(16, 16),
                TransparentColor = Color.Magenta
            };

            imageList.Images.Add("DbTables.bmp", Resources.DbTables);
            imageList.Images.Add("Table.bmp", Resources.Table);
            imageList.Images.Add("DbViews.bmp", Resources.DbViews);
            imageList.Images.Add("View.bmp", Resources.View);
            imageList.Images.Add("DBStoredProcs.bmp", Resources.DBStoredProcs);
            imageList.Images.Add("StoredProc.bmp", Resources.StoredProc);
            imageList.Images.Add("DbDeletedItems.bmp", Resources.DbDeletedItems);
            imageList.Images.Add("DeletedItem.bmp", Resources.DeletedItem);
            imageList.Images.Add("DbAddedItems.bmp", Resources.DbAddedItems);
            imageList.Images.Add("DbUpdatedItems.bmp", Resources.DbUpdatedItems);
            imageList.Images.Add("database_schema.bmp", Resources.database_schema);

#pragma warning disable 0618 // DpiHelper is obsolete, need to move to DpiAwareness (and ImageManifest)
            // scale images as appropriate for screen resolution
            DpiHelper.LogicalToDeviceUnits(ref imageList);
#pragma warning restore 0618

            treeView.ImageList = imageList;

            VsShellUtilities.ApplyTreeViewThemeStyles(treeView);
            treeView.DrawMode    = TreeViewDrawMode.OwnerDrawText;
            treeView.DrawNode   += TreeViewControl_DrawNode;
            treeView.AfterCheck += TreeViewControl_AfterCheck;
        }
示例#28
0
        public override Boolean OnTouchDown(Int32 touchId, Point point)
        {
            this.TouchId = touchId;

            if (!startPoint.HasValue)
            {
                this.drawingCanvas.AddWorkingDrawTool(this);

                this.pen = this.drawingCanvas.Pen;

                this.fontSize = this.drawingCanvas.FontSize;
                this.typeface = new Typeface(new FontFamily("Microsoft YaHei UI,Tahoma"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);

                this.dpi = DpiHelper.GetDpiFromVisual(this.drawingCanvas);

                startPoint = point;

                geometry = new PathGeometry();

                var figure = new PathFigure();
                pathGeometry.Figures.Add(figure);

                this.CanTouchMove = true;

                if (this.TouchId != 0 || !this.drawingCanvas.CaptureMouse())
                {
                    this.CanTouchLeave = true;
                }

                this.drawingCanvas.AddVisual(this);

                return(true);
            }
            else
            {
                return(OnTouchLeave(point));
            }
        }
        public override void PaintLabel(System.Drawing.Graphics g, Rectangle rect, Rectangle clipRect, bool selected, bool paintFullLabel)
        {
            base.PaintLabel(g, rect, clipRect, selected, paintFullLabel);

            IPropertyValueUIService propValSvc = this.PropertyValueUIService;

            if (propValSvc == null)
            {
                return;
            }

            pvUIItems = propValSvc.GetPropertyUIValueItems(this, propertyInfo);

            if (pvUIItems != null)
            {
                if (uiItemRects == null || uiItemRects.Length != pvUIItems.Length)
                {
                    uiItemRects = new Rectangle[pvUIItems.Length];
                }

                if (!isScalingInitialized)
                {
                    if (DpiHelper.IsScalingRequired)
                    {
                        scaledImageSizeX = DpiHelper.LogicalToDeviceUnitsX(IMAGE_SIZE);
                        scaledImageSizeY = DpiHelper.LogicalToDeviceUnitsY(IMAGE_SIZE);
                    }
                    isScalingInitialized = true;
                }

                for (int i = 0; i < pvUIItems.Length; i++)
                {
                    uiItemRects[i] = new Rectangle(rect.Right - ((scaledImageSizeX + 1) * (i + 1)), (rect.Height - scaledImageSizeY) / 2, scaledImageSizeX, scaledImageSizeY);
                    g.DrawImage(pvUIItems[i].Image, uiItemRects[i]);
                }
                GridEntryHost.LabelPaintMargin = (scaledImageSizeX + 1) * pvUIItems.Length;
            }
        }
示例#30
0
    private void _FixupFrameworkIssues()
    {
        if (!Utility.IsPresentationFrameworkVersionLessThan4)
        {
            return;
        }
        if (this._window.Template == null)
        {
            return;
        }
        if (VisualTreeHelper.GetChildrenCount(this._window) == 0)
        {
            this._window.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new WindowChromeWorker._Action(this._FixupFrameworkIssues));
            return;
        }
        FrameworkElement frameworkElement = (FrameworkElement)VisualTreeHelper.GetChild(this._window, 0);
        RECT             windowRect       = NativeMethods.GetWindowRect(this._hwnd);
        RECT             rect             = this._GetAdjustedWindowRect(windowRect);
        Rect             rect2            = DpiHelper.DeviceRectToLogical(new Rect((double)windowRect.Left, (double)windowRect.Top, (double)windowRect.Width, (double)windowRect.Height));
        Rect             rect3            = DpiHelper.DeviceRectToLogical(new Rect((double)rect.Left, (double)rect.Top, (double)rect.Width, (double)rect.Height));
        Thickness        thickness        = new Thickness(rect2.Left - rect3.Left, rect2.Top - rect3.Top, rect3.Right - rect2.Right, rect3.Bottom - rect2.Bottom);

        frameworkElement.Margin = new Thickness(0.0, 0.0, -(thickness.Left + thickness.Right), -(thickness.Top + thickness.Bottom));
        if (this._window.FlowDirection == FlowDirection.RightToLeft)
        {
            frameworkElement.RenderTransform = new MatrixTransform(1.0, 0.0, 0.0, 1.0, -(thickness.Left + thickness.Right), 0.0);
        }
        else
        {
            frameworkElement.RenderTransform = null;
        }
        if (!this._isFixedUp)
        {
            this._hasUserMovedWindow   = false;
            this._window.StateChanged += this._FixupRestoreBounds;
            this._isFixedUp            = true;
        }
    }