예제 #1
0
 public Monitor(UIElement element)
 {
     this.Element                = element;
     this.HwndSource             = ScreenLocation.FindTopLevelHwndSource(element);
     this.Element.LayoutUpdated += new EventHandler(this.OnLayoutUpdated);
     PresentationSource.AddSourceChangedHandler((IInputElement)element, new SourceChangedEventHandler(this.OnPresentationSourceChanged));
 }
 public OldSchoolMdiWindow()
 {
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         PresentationSource.AddSourceChangedHandler(this, OnPresentationSourceChanged);
     }
 }
        /// <summary>
        ///   Enable Horizontal Wheel support for all that control and all controls hosted by the same window/popup/context menu.
        ///   This method does not need to be called if AutoEnableMouseHorizontalWheelSupport is true.
        ///   If it was already enabled it will do nothing.
        /// </summary>
        /// <param name="uiElement">UI Element to enable support for.</param>
        public static void EnableMouseHorizontalWheelSupportForParentOf(UIElement uiElement)
        {
            // try to add it right now
            if (uiElement is Window)
            {
                EnableMouseHorizontalWheelSupport((Window)uiElement);
            }
            else if (uiElement is Popup)
            {
                EnableMouseHorizontalWheelSupport((System.Windows.Controls.Primitives.Popup)uiElement);
            }
            else if (uiElement is ContextMenu)
            {
                EnableMouseHorizontalWheelSupport((ContextMenu)uiElement);
            }
            else
            {
                IntPtr?parentHandle = GetObjectParentHandle(uiElement);
                if (parentHandle != null)
                {
                    EnableMouseHorizontalWheelSupport(parentHandle.Value);
                }

                // and in the rare case the parent window ever changes...
                PresentationSource.AddSourceChangedHandler(uiElement, PresenationSourceChangedHandler);
            }
        }
예제 #4
0
        public MainWindow()
        {
            InitializeComponent();

            //for (int i = 0; i < 10000; i++)
            //{
            //    StackPanel.Children.Add(new TextBlock()
            //    {
            //        Text = i.ToString()
            //    });
            //}

            var transform = new ScaleTransform(1, 1);

            MainGrid.RenderTransform = transform;
            _transform = transform;

            DataContext = this;

            PresentationSource.AddSourceChangedHandler(this, OnSourceChanged);

            _manipulationHandler.ScaleUpdated += ManipulationHandler_ScaleUpdated;

            SizeChanged += MainWindow_SizeChanged;
        }
예제 #5
0
        public Dashboard(
            DashboardViewModel model,
            IWpfTextView textView)
        {
            _model = model;
            InitializeComponent();

            _tabNavigableChildren = new UIElement[] { this.OverloadsCheckbox, this.CommentsCheckbox, this.StringsCheckbox, this.PreviewChangesCheckbox, this.ApplyButton, this.CloseButton }.ToList();

            _textView        = textView;
            this.DataContext = model;

            this.Visibility = textView.HasAggregateFocus ? Visibility.Visible : Visibility.Collapsed;

            _textView.GotAggregateFocus         += OnTextViewGotAggregateFocus;
            _textView.LostAggregateFocus        += OnTextViewLostAggregateFocus;
            _textView.VisualElement.SizeChanged += OnElementSizeChanged;
            this.SizeChanged += OnElementSizeChanged;

            PresentationSource.AddSourceChangedHandler(this, OnPresentationSourceChanged);

            try
            {
                _findAdornmentLayer = textView.GetAdornmentLayer("FindUIAdornmentLayer");
                ((UIElement)_findAdornmentLayer).LayoutUpdated += FindAdornmentCanvas_LayoutUpdated;
            }
            catch (ArgumentOutOfRangeException)
            {
                // Find UI doesn't exist in ETA.
            }

            this.Focus();
            textView.Caret.IsHidden         = false;
            ShouldReceiveKeyboardNavigation = true;
        }
예제 #6
0
 public ClassicMdiChild()
 {
     if (!DesignerProperties.GetIsInDesignMode(this))
     {
         PresentationSource.AddSourceChangedHandler(this, OnPresentationSourceChanged);
     }
 }
 /// <summary>
 /// Observes for HwndSource changes on the given UIElement,
 /// and adds and removes an HwndSource hook when the HwndSource
 /// changes.
 /// </summary>
 /// <param name="child">The UIElement to observe.</param>
 static void HookChildHwndSource(UIElement child)
 {
     // The delegate reference is stored on the UIElement, and the lifetime
     // of the child is equal to the lifetime of this UIElementDialogPage,
     // so we are not leaking memory by not calling RemoveSourceChangedHandler.
     PresentationSource.AddSourceChangedHandler(child, OnSourceChanged);
 }
        public ClassicMdiFrame()
        {
            _hook = new HwndSourceHook(OnMessage);

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                PresentationSource.AddSourceChangedHandler(this, OnPresentationSourceChanged);
            }
        }
예제 #9
0
 public WpfAvaloniaHost()
 {
     _sync = SynchronizationContext.Current;
     _impl = new WpfTopLevelImpl();
     _impl.ControlRoot.Prepare();
     _impl.Visibility    = Visibility.Visible;
     SnapsToDevicePixels = true;
     UseLayoutRounding   = true;
     PresentationSource.AddSourceChangedHandler(this, OnSourceChanged);
 }
예제 #10
0
 private void Initialize(bool fTrusted)
 {
     this._fTrusted              = new SecurityCriticalDataForSet <bool>(fTrusted);
     this._hwndSubclassHook      = new HwndWrapperHook(this.SubclassWndProc);
     this._handlerLayoutUpdated  = new EventHandler(this.OnLayoutUpdated);
     this._handlerEnabledChanged = new DependencyPropertyChangedEventHandler(this.OnEnabledChanged);
     this._handlerVisibleChanged = new DependencyPropertyChangedEventHandler(this.OnVisibleChanged);
     PresentationSource.AddSourceChangedHandler(this, new SourceChangedEventHandler(this.OnSourceChanged));
     this._weakEventDispatcherShutdown = new HwndHost.WeakEventDispatcherShutdown(this, base.Dispatcher);
 }
예제 #11
0
        public ChromiumWebBrowser()
        {
            if (!Cef.IsInitialized && !Cef.Initialize())
            {
                throw new InvalidOperationException("Cef::Initialize() failed");
            }

            Cef.AddDisposable(this);
            Focusable        = true;
            FocusVisualStyle = null;
            IsTabStop        = true;

            Dispatcher.BeginInvoke((Action)(() => WebBrowser = this));

            Loaded += OnLoaded;

            GotKeyboardFocus  += OnGotKeyboardFocus;
            LostKeyboardFocus += OnLostKeyboardFocus;

            IsVisibleChanged += OnIsVisibleChanged;

            ToolTip            = toolTip = new ToolTip();
            toolTip.StaysOpen  = true;
            toolTip.Visibility = Visibility.Collapsed;
            toolTip.Closed    += OnTooltipClosed;


            BackCommand       = new DelegateCommand(Back, () => CanGoBack);
            ForwardCommand    = new DelegateCommand(Forward, () => CanGoForward);
            ReloadCommand     = new DelegateCommand(Reload, () => CanReload);
            PrintCommand      = new DelegateCommand(Print);
            ZoomInCommand     = new DelegateCommand(ZoomIn);
            ZoomOutCommand    = new DelegateCommand(ZoomOut);
            ZoomResetCommand  = new DelegateCommand(ZoomReset);
            ViewSourceCommand = new DelegateCommand(ViewSource);
            CleanupCommand    = new DelegateCommand(Dispose);
            StopCommand       = new DelegateCommand(Stop);
            CutCommand        = new DelegateCommand(Cut);
            CopyCommand       = new DelegateCommand(Copy);
            PasteCommand      = new DelegateCommand(Paste);
            SelectAllCommand  = new DelegateCommand(SelectAll);
            UndoCommand       = new DelegateCommand(Undo);
            RedoCommand       = new DelegateCommand(Redo);

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);

            disposables.Add(managedCefBrowserAdapter);
            disposables.Add(new DisposableEventWrapper(this, ActualHeightProperty, OnActualSizeChanged));
            disposables.Add(new DisposableEventWrapper(this, ActualWidthProperty, OnActualSizeChanged));

            ResourceHandler = new DefaultResourceHandler();
            BrowserSettings = new BrowserSettings();

            PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler);
        }
예제 #12
0
        public Dashboard(
            DashboardViewModel model,
            IEditorFormatMapService editorFormatMapService,
            IWpfTextView textView)
        {
            _model = model;
            InitializeComponent();

            _tabNavigableChildren = new UIElement[] { this.OverloadsCheckbox, this.CommentsCheckbox, this.StringsCheckbox, this.FileRenameCheckbox, this.PreviewChangesCheckbox, this.ApplyButton, this.CloseButton }.ToList();

            _textView        = textView;
            this.DataContext = model;

            this.Visibility = textView.HasAggregateFocus ? Visibility.Visible : Visibility.Collapsed;

            _textView.GotAggregateFocus         += OnTextViewGotAggregateFocus;
            _textView.LostAggregateFocus        += OnTextViewLostAggregateFocus;
            _textView.VisualElement.SizeChanged += OnElementSizeChanged;
            this.SizeChanged += OnElementSizeChanged;

            PresentationSource.AddSourceChangedHandler(this, OnPresentationSourceChanged);

            try
            {
                _findAdornmentLayer = textView.GetAdornmentLayer("FindUIAdornmentLayer");
                ((UIElement)_findAdornmentLayer).LayoutUpdated += FindAdornmentCanvas_LayoutUpdated;
            }
            catch (ArgumentOutOfRangeException)
            {
                // Find UI doesn't exist in ETA.
            }

            // Once the Dashboard is loaded, the visual tree is completely created and the
            // UIAutomation system has discovered and connected the AutomationPeer to the tree,
            // allowing us to raise the AutomationFocusChanged event and have it process correctly.
            // for us to set up the AutomationPeer
            this.Loaded += Dashboard_Loaded;

            if (editorFormatMapService != null)
            {
                _textFormattingMap = editorFormatMapService.GetEditorFormatMap("text");
                _textFormattingMap.FormatMappingChanged += UpdateBorderColors;
                UpdateBorderColors(this, eventArgs: null);
            }

            ResolvableConflictBorder.StrokeThickness = RenameFixupTagDefinition.StrokeThickness;
            ResolvableConflictBorder.StrokeDashArray = new DoubleCollection(RenameFixupTagDefinition.StrokeDashArray);

            UnresolvableConflictBorder.StrokeThickness = RenameConflictTagDefinition.StrokeThickness;
            UnresolvableConflictBorder.StrokeDashArray = new DoubleCollection(RenameConflictTagDefinition.StrokeDashArray);

            this.Focus();
            textView.Caret.IsHidden         = false;
            ShouldReceiveKeyboardNavigation = false;
        }
예제 #13
0
 private static void OnPopupAnimationChanged(
     DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is ContextMenu menu)
     {
         if (!SourceChangedHandlers.TryGetValue(menu, out var _))
         {
             PresentationSource.AddSourceChangedHandler(menu, OnSourceChanged);
             SourceChangedHandlers.Add(menu, null);
         }
     }
 }
예제 #14
0
        public NativeHandleHostAdapter(INativeHandleContract nativeHandleContract, ObserverHostAdapter adapter)
        {
            Debug.Assert(null != nativeHandleContract);
            contract = new ContractHandle(nativeHandleContract);
            observer = adapter;

            PresentationSource.AddSourceChangedHandler(this, OnSourceChanged);
            Dispatcher.ShutdownFinished += OnDispatcherShutdown;

            //if (null == observer) return;
            //observer.Execute += ExecutedRoutedCommandHandler;
            //observer.CanExecute += CanExecuteRoutedCommandHandler;
        }
예제 #15
0
        /// <summary>
        /// Observes for HwndSource changes on the given UIElement, and adds and removes an HwndSource hook when the HwndSource changes.</summary>
        private void HookChildHwndSource(UIElement child)
        {
            // The delegate reference is stored on the UIElement, and the lifetime
            // of the child is equal to the lifetime of this UIElementDialogPage,
            // so we are not leaking memory by not calling RemoveSourceChangedHandler.
            PresentationSource.AddSourceChangedHandler(child, OnSourceChanged);
            void OnSourceChanged(object sender, SourceChangedEventArgs e)
            {
                if (e.OldSource is HwndSource old_source)
                {
                    old_source.RemoveHook(SourceHook);
                }
                if (e.NewSource is HwndSource new_source)
                {
                    new_source.AddHook(SourceHook);
                }
            }

            IntPtr SourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
            {
                // Handle WM_GETDLGCODE in order to allow for arrow and tab navigation inside the dialog page.
                // By returning this code, Windows will pass arrow and tab keys to our HWND instead of handling
                // them for its own default tab and directional navigation.
                switch (msg)
                {
                case Win32.WM_GETDLGCODE:
                {
                    int dlg_code = Win32.DLGC_WANTARROWS | Win32.DLGC_WANTTAB | Win32.DLGC_WANTCHARS;

                    // Ask the currently-focused element if it wants to handle all keys or not.  The DialogKeyPendingEvent
                    // is a routed event starting with the focused control.  If any control in the route handles
                    // this message, then we'll add DLGC_WANTALLKEYS to request that this pending message
                    // be delivered to our content instead of the default dialog procedure.
                    if (Keyboard.FocusedElement is IInputElement current_element)
                    {
                        var args = new DialogKeyEventArgs(DialogKeyPendingEvent, KeyInterop.KeyFromVirtualKey(wParam.ToInt32()));
                        current_element.RaiseEvent(args);
                        if (args.Handled)
                        {
                            dlg_code |= Win32.DLGC_WANTALLKEYS;
                        }
                    }

                    handled = true;
                    return(new IntPtr(dlg_code));
                }
                }

                return(IntPtr.Zero);
            }
        }
예제 #16
0
            public ToolsOptionsPageWin32Window(IEditableObject model, UserControl view, IMessageBoxService messageBox)
            {
                this.model      = model;
                this.view       = view;
                this.messageBox = messageBox;

                this.elementHost      = new DialogPageElementHost();
                this.elementHost.Dock = System.Windows.Forms.DockStyle.Fill;

                // Hooks the child hwnd source.
                PresentationSource.AddSourceChangedHandler(this.view, this.OnSourceChanged);

                this.elementHost.Child = this.view;
            }
 private static void OnThemeScrollBarsChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
 {
     if (!(sender is FrameworkElement element))
     {
         return;
     }
     if (PresentationSource.FromDependencyObject(element) != null)
     {
         UpdateScrollBarStyles(element);
     }
     else
     {
         PresentationSource.AddSourceChangedHandler(element, OnPresentationSourceChanged);
     }
 }
예제 #18
0
        public RedirectedHwndHost()
        {
            PresentationSource.AddSourceChangedHandler(this, (s, e) => CurrentHwndSource = (HwndSource)e.NewSource);
            Loaded += new RoutedEventHandler(OnLoaded);

            _inputRedirectionTimer           = new DispatcherTimer(DispatcherPriority.Input);
            _inputRedirectionTimer.Tick     += (e, a) => UpdateInputRedirection();
            _inputRedirectionTimer.Interval  = InputRedirectionPeriod;
            _inputRedirectionTimer.IsEnabled = IsInputRedirectionEnabled;

            _outputRedirectionTimer           = new DispatcherTimer(DispatcherPriority.Render);
            _outputRedirectionTimer.Tick     += (e, a) => UpdateOutputRedirection();
            _outputRedirectionTimer.Interval  = OutputRedirectionPeriod;
            _outputRedirectionTimer.IsEnabled = IsOutputRedirectionEnabled;
        }
        public MainWindow()
        {
            InitializeComponent();

            transform = new ScaleTransform(1, 1);
            mainGrid.RenderTransform = transform;

            /*mainGrid.IsManipulationEnabled = true;
             * mainGrid.ManipulationStarting += MainGrid_ManipulationStarting;
             * mainGrid.ManipulationStarted += MainGrid_ManipulationStarted;
             * mainGrid.ManipulationDelta += MainGrid_ManipulationDelta;*/
            PresentationSource.AddSourceChangedHandler(this, OnSourceChanged);
            manipulationHandler.ScaleUpdated += (newScale) => transform.ScaleX = transform.ScaleY = newScale;
            this.SizeChanged           += MainWindow_SizeChanged;
            mainGrid.MouseLeftButtonUp += MainGrid_MouseLeftButtonUp;
        }
예제 #20
0
        protected void Activate()
        {
            if (m_activated)
            {
                return;
            }

            var hwndSource = PresentationSource.FromVisual(m_connector) as HwndSource;

            if (hwndSource != null)
            {
                OnSourceConnected(hwndSource);
            }

            PresentationSource.AddSourceChangedHandler(m_connector, OnSourceChanged);
            m_activated = true;
        }
예제 #21
0
        public WpfTopLevelImpl()
        {
            PresentationSource.AddSourceChangedHandler(this, OnSourceChanged);
            _hook     = WndProc;
            _ttl      = this;
            _surfaces = new object[] { new WritableBitmapSurface(this), new Direct2DImageSurface(this) };
            _mouse    = new WpfMouseDevice(this);
            _keyboard = AvaloniaLocator.Current.GetService <IKeyboardDevice>();

            ControlRoot         = new CustomControlRoot(this);
            SnapsToDevicePixels = true;
            Focusable           = true;
            DataContextChanged += delegate
            {
                ControlRoot.DataContext = DataContext;
            };
        }
예제 #22
0
        internal static void AddPresentationSourceCleanupAction(UIElement element, Action handler)
        {
            SourceChangedEventHandler relayHandler = (SourceChangedEventHandler)null;

            relayHandler = (SourceChangedEventHandler)((sender, args) =>
            {
                if (args.NewSource != null)
                {
                    return;
                }
                if (!element.Dispatcher.HasShutdownStarted)
                {
                    handler();
                }
                PresentationSource.RemoveSourceChangedHandler((IInputElement)element, relayHandler);
            });
            PresentationSource.AddSourceChangedHandler((IInputElement)element, relayHandler);
        }
예제 #23
0
        public Dashboard(
            DashboardViewModel model,
            IWpfTextView textView)
        {
            _model = model;
            InitializeComponent();

            _tabNavigableChildren = new UIElement[] { this.OverloadsCheckbox, this.CommentsCheckbox, this.StringsCheckbox, this.PreviewChangesCheckbox, this.ApplyButton, this.CloseButton }.ToList();

            _textView        = textView;
            this.DataContext = model;

            this.Visibility = textView.HasAggregateFocus ? Visibility.Visible : Visibility.Collapsed;

            _textView.GotAggregateFocus         += OnTextViewGotAggregateFocus;
            _textView.LostAggregateFocus        += OnTextViewLostAggregateFocus;
            _textView.VisualElement.SizeChanged += OnElementSizeChanged;
            this.SizeChanged += OnElementSizeChanged;

            PresentationSource.AddSourceChangedHandler(this, OnPresentationSourceChanged);

            try
            {
                _findAdornmentLayer = textView.GetAdornmentLayer("FindUIAdornmentLayer");
                ((UIElement)_findAdornmentLayer).LayoutUpdated += FindAdornmentCanvas_LayoutUpdated;
            }
            catch (ArgumentOutOfRangeException)
            {
                // Find UI doesn't exist in ETA.
            }

            // Once the Dashboard is loaded, the visual tree is completely created and the
            // UIAutomation system has discovered and connected the AutomationPeer to the tree,
            // allowing us to raise the AutomationFocusChanged event and have it process correctly.
            // for us to set up the AutomationPeer
            this.Loaded += Dashboard_Loaded;

            this.Focus();
            textView.Caret.IsHidden         = false;
            ShouldReceiveKeyboardNavigation = false;
        }
예제 #24
0
        /// <summary>
        /// Add this StylusPlugInCollection to the StylusPlugInCollectionList when it the first
        /// element is added.
        /// </summary>
        private void EnsureEventsHooked()
        {
            if (this.Count == 0)
            {
                // Grab current element info
                UpdateRect();
                // Now hook up events to track on this element.
                _element.IsEnabledChanged        += _isEnabledChangedEventHandler;
                _element.IsVisibleChanged        += _isVisibleChangedEventHandler;
                _element.IsHitTestVisibleChanged += _isHitTestVisibleChangedEventHandler;
                PresentationSource.AddSourceChangedHandler(_element, _sourceChangedEventHandler);  // has a security linkdemand
                _element.LayoutUpdated += _layoutChangedEventHandler;

                if (_element.RenderTransform != null &&
                    !_element.RenderTransform.IsFrozen)
                {
                    if (_renderTransformChangedEventHandler == null)
                    {
                        _renderTransformChangedEventHandler = new EventHandler(OnRenderTransformChanged);
                        _element.RenderTransform.Changed   += _renderTransformChangedEventHandler;
                    }
                }
            }
        }
 public ScrollViewerWindowsFormsHost()
 {
     PresentationSource.AddSourceChangedHandler(this, SourceChangedEventHandler);
 }
예제 #26
0
 public WindowsFormsHostEx()
 {
     PresentationSource.AddSourceChangedHandler(this, SourceChangedEventHandler);
 }
예제 #27
0
        public ChromiumWebBrowser()
        {
            if (!Cef.IsInitialized && !Cef.Initialize())
            {
                throw new InvalidOperationException("Cef::Initialize() failed");
            }

            BitmapFactory = new BitmapFactory();

            Cef.AddDisposable(this);
            Focusable        = true;
            FocusVisualStyle = null;
            IsTabStop        = true;

            Dispatcher.BeginInvoke((Action)(() => WebBrowser = this));

            Loaded      += OnLoaded;
            SizeChanged += OnActualSizeChanged;

            GotKeyboardFocus  += OnGotKeyboardFocus;
            LostKeyboardFocus += OnLostKeyboardFocus;

            // Drag Drop events
            DragEnter += OnDragEnter;
            DragOver  += OnDragOver;
            DragLeave += OnDragLeave;
            Drop      += OnDrop;

            IsVisibleChanged += OnIsVisibleChanged;

            ToolTip            = toolTip = new ToolTip();
            toolTip.StaysOpen  = true;
            toolTip.Visibility = Visibility.Collapsed;
            toolTip.Closed    += OnTooltipClosed;

            BackCommand       = new DelegateCommand(this.Back, () => CanGoBack);
            ForwardCommand    = new DelegateCommand(this.Forward, () => CanGoForward);
            ReloadCommand     = new DelegateCommand(this.Reload, () => !IsLoading);
            PrintCommand      = new DelegateCommand(this.Print);
            ZoomInCommand     = new DelegateCommand(ZoomIn);
            ZoomOutCommand    = new DelegateCommand(ZoomOut);
            ZoomResetCommand  = new DelegateCommand(ZoomReset);
            ViewSourceCommand = new DelegateCommand(this.ViewSource);
            CleanupCommand    = new DelegateCommand(Dispose);
            StopCommand       = new DelegateCommand(this.Stop);
            CutCommand        = new DelegateCommand(this.Cut);
            CopyCommand       = new DelegateCommand(this.Copy);
            PasteCommand      = new DelegateCommand(this.Paste);
            SelectAllCommand  = new DelegateCommand(this.SelectAll);
            UndoCommand       = new DelegateCommand(this.Undo);
            RedoCommand       = new DelegateCommand(this.Redo);

            managedCefBrowserAdapter = new ManagedCefBrowserAdapter(this, true);

            ResourceHandlerFactory = new DefaultResourceHandlerFactory();
            BrowserSettings        = new BrowserSettings();

            PresentationSource.AddSourceChangedHandler(this, PresentationSourceChangedHandler);

            RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.NearestNeighbor);
        }
예제 #28
0
 protected FocusableHwndHost()
 {
     FocusTracker.Instance.TrackFocus += new EventHandler <TrackFocusEventArgs>(this.OnTrackFocus);
     PresentationSource.AddSourceChangedHandler(this, new SourceChangedEventHandler(this.OnSourceChanged));
 }
예제 #29
0
 public RoutedCommandButton()
 {
     PresentationSource.AddSourceChangedHandler(this, OnSourceChanged);
 }
예제 #30
0
 protected ElementContainer()
 {
     Child = new HostVisual();
     PresentationSource.AddSourceChangedHandler(this, OnPresentationSourceChanged);
 }