Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopLevel"/> class.
        /// </summary>
        /// <param name="impl">The platform-specific window implementation.</param>
        /// <param name="dependencyResolver">
        /// The dependency resolver to use. If null the default dependency resolver will be used.
        /// </param>
        public TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver dependencyResolver)
        {
            if (impl == null)
            {
                throw new InvalidOperationException(
                          "Could not create window implementation: maybe no windowing subsystem was initialized?");
            }

            PlatformImpl = impl;

            dependencyResolver = dependencyResolver ?? AvaloniaLocator.Current;
            var styler = TryGetService <IStyler>(dependencyResolver);

            _accessKeyHandler          = TryGetService <IAccessKeyHandler>(dependencyResolver);
            _inputManager              = TryGetService <IInputManager>(dependencyResolver);
            _keyboardNavigationHandler = TryGetService <IKeyboardNavigationHandler>(dependencyResolver);
            _renderInterface           = TryGetService <IPlatformRenderInterface>(dependencyResolver);
            _globalStyles              = TryGetService <IGlobalStyles>(dependencyResolver);

            Renderer = impl.CreateRenderer(this);

            if (Renderer != null)
            {
                Renderer.SceneInvalidated += SceneInvalidated;
            }

            impl.SetInputRoot(this);

            impl.Closed         = HandleClosed;
            impl.Input          = HandleInput;
            impl.Paint          = HandlePaint;
            impl.Resized        = HandleResized;
            impl.ScalingChanged = HandleScalingChanged;

            _keyboardNavigationHandler?.SetOwner(this);
            _accessKeyHandler?.SetOwner(this);

            if (_globalStyles is object)
            {
                _globalStyles.GlobalStylesAdded   += ((IStyleHost)this).StylesAdded;
                _globalStyles.GlobalStylesRemoved += ((IStyleHost)this).StylesRemoved;
            }

            styler?.ApplyStyles(this);

            ClientSize = impl.ClientSize;

            this.GetObservable(PointerOverElementProperty)
            .Select(
                x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty <Cursor>())
            .Switch().Subscribe(cursor => PlatformImpl?.SetCursor(cursor?.PlatformCursor));

            if (((IStyleHost)this).StylingParent is IResourceProvider applicationResources)
            {
                WeakSubscriptionManager.Subscribe(
                    applicationResources,
                    nameof(IResourceProvider.ResourcesChanged),
                    this);
            }
        }
Example #2
0
 public RenderTargetDecorator(IRenderTarget target, ITopLevelImpl window)
 {
     _target = target;
     var dec = window as WindowDecorator;
     if (dec != null)
         window = dec.TopLevel;
     _window = window;
 }
 public WindowDecorator(ITopLevelImpl tl)
 {
     _tl         = tl;
     _window     = tl as IWindowImpl;
     _popup      = tl as IPopupImpl;
     _tl.Input   = OnInput;
     _tl.Paint   = OnPaint;
     _tl.Resized = OnResized;
 }
Example #4
0
 public WindowDecorator(ITopLevelImpl tl)
 {
     _tl = tl;
     _window = tl as IWindowImpl;
     _popup = tl as IPopupImpl;
     _tl.Input = OnInput;
     _tl.Paint = OnPaint;
     _tl.Resized = OnResized;
 }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopLevel"/> class.
        /// </summary>
        /// <param name="impl">The platform-specific window implementation.</param>
        /// <param name="dependencyResolver">
        /// The dependency resolver to use. If null the default dependency resolver will be used.
        /// </param>
        public TopLevel(ITopLevelImpl impl, IPerspexDependencyResolver dependencyResolver)
        {
            if (impl == null)
            {
                throw new InvalidOperationException(
                          "Could not create window implementation: maybe no windowing subsystem was initialized?");
            }

            PlatformImpl = impl;

            dependencyResolver = dependencyResolver ?? PerspexLocator.Current;
            var renderInterface = TryGetService <IPlatformRenderInterface>(dependencyResolver);
            var styler          = TryGetService <IStyler>(dependencyResolver);

            _accessKeyHandler          = TryGetService <IAccessKeyHandler>(dependencyResolver);
            _inputManager              = TryGetService <IInputManager>(dependencyResolver);
            _keyboardNavigationHandler = TryGetService <IKeyboardNavigationHandler>(dependencyResolver);
            LayoutManager              = TryGetService <ILayoutManager>(dependencyResolver);
            _renderQueueManager        = TryGetService <IRenderQueueManager>(dependencyResolver);
            (TryGetService <ITopLevelRenderer>(dependencyResolver) ?? new DefaultTopLevelRenderer()).Attach(this);

            PlatformImpl.SetInputRoot(this);
            PlatformImpl.Activated   = HandleActivated;
            PlatformImpl.Deactivated = HandleDeactivated;
            PlatformImpl.Closed      = HandleClosed;
            PlatformImpl.Input       = HandleInput;
            PlatformImpl.Resized     = HandleResized;

            Size clientSize = ClientSize = PlatformImpl.ClientSize;

            if (LayoutManager != null)
            {
                LayoutManager.Root = this;
                LayoutManager.LayoutNeeded.Subscribe(_ => HandleLayoutNeeded());
                LayoutManager.LayoutCompleted.Subscribe(_ => HandleLayoutCompleted());
            }

            if (_keyboardNavigationHandler != null)
            {
                _keyboardNavigationHandler.SetOwner(this);
            }

            if (_accessKeyHandler != null)
            {
                _accessKeyHandler.SetOwner(this);
            }

            styler?.ApplyStyles(this);

            GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl.ClientSize = x);
            GetObservable(PointerOverElementProperty)
            .Select(
                x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty <Cursor>())
            .Switch().Subscribe(cursor => PlatformImpl.SetCursor(cursor?.PlatformCursor));
        }
            public RenderTargetDecorator(IRenderTarget target, ITopLevelImpl window)
            {
                _target = target;
                var dec = window as WindowDecorator;

                if (dec != null)
                {
                    window = dec.TopLevel;
                }
                _window = window;
            }
Example #7
0
    public static ITopLevelImpl Wrap(ITopLevelImpl impl)
    {
#if DEBUG
        if (impl is ValidatingToplevelImpl)
        {
            return(impl);
        }
        return(new ValidatingToplevelImpl(impl));
#else
        return(impl);
#endif
    }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopLevel"/> class.
        /// </summary>
        /// <param name="impl">The platform-specific window implementation.</param>
        /// <param name="dependencyResolver">
        /// The dependency resolver to use. If null the default dependency resolver will be used.
        /// </param>
        public TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver dependencyResolver)
        {
            if (impl == null)
            {
                throw new InvalidOperationException(
                          "Could not create window implementation: maybe no windowing subsystem was initialized?");
            }

            PlatformImpl       = impl;
            dependencyResolver = dependencyResolver ?? AvaloniaLocator.Current;
            var styler = TryGetService <IStyler>(dependencyResolver);

            _accessKeyHandler          = TryGetService <IAccessKeyHandler>(dependencyResolver);
            _inputManager              = TryGetService <IInputManager>(dependencyResolver);
            _keyboardNavigationHandler = TryGetService <IKeyboardNavigationHandler>(dependencyResolver);
            _applicationLifecycle      = TryGetService <IApplicationLifecycle>(dependencyResolver);
            _renderInterface           = TryGetService <IPlatformRenderInterface>(dependencyResolver);

            var renderLoop      = TryGetService <IRenderLoop>(dependencyResolver);
            var rendererFactory = TryGetService <IRendererFactory>(dependencyResolver);

            Renderer = rendererFactory?.CreateRenderer(this, renderLoop);

            PlatformImpl.SetInputRoot(this);
            PlatformImpl.Activated       = HandleActivated;
            PlatformImpl.Deactivated     = HandleDeactivated;
            PlatformImpl.Closed          = HandleClosed;
            PlatformImpl.Input           = HandleInput;
            PlatformImpl.Paint           = Renderer != null ? (Action <Rect>)Renderer.Render : null;
            PlatformImpl.Resized         = HandleResized;
            PlatformImpl.ScalingChanged  = HandleScalingChanged;
            PlatformImpl.PositionChanged = HandlePositionChanged;

            _keyboardNavigationHandler?.SetOwner(this);
            _accessKeyHandler?.SetOwner(this);
            styler?.ApplyStyles(this);

            ClientSize = PlatformImpl.ClientSize;
            this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => PlatformImpl.ClientSize = x);
            this.GetObservable(PointerOverElementProperty)
            .Select(
                x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty <Cursor>())
            .Switch().Subscribe(cursor => PlatformImpl.SetCursor(cursor?.PlatformCursor));

            if (_applicationLifecycle != null)
            {
                _applicationLifecycle.OnExit += OnApplicationExiting;
            }
        }
Example #9
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;
            };
        }
Example #10
0
 public OleDropTarget(ITopLevelImpl tl, IInputElement target)
 {
     _dragDevice = AvaloniaLocator.Current.GetService <IDragDropDevice>();
     _tl         = tl;
     _target     = target;
 }
Example #11
0
 public TouchHandler(AvaloniaView view, ITopLevelImpl tl)
 {
     _view = view;
     _tl   = tl;
 }
Example #12
0
 public static IRenderTarget CreateRenderTarget(ITopLevelImpl window)
 {
     return
         new RenderTargetDecorator(
             PerspexLocator.Current.GetService<IPlatformRenderInterface>().CreateRenderer(window.Handle), window);
 }
Example #13
0
 public static IRenderTarget CreateRenderTarget(ITopLevelImpl window)
 {
     return AvaloniaLocator.Current
         .GetService<IPlatformRenderInterface>()
         .CreateRenderer(window.Handle);
 }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TopLevel"/> class.
 /// </summary>
 /// <param name="impl">The platform-specific window implementation.</param>
 public TopLevel(ITopLevelImpl impl)
     : this(impl, PerspexLocator.Current)
 {
 }
Example #15
0
 public TestTopLevel(ITopLevelImpl impl, ILayoutManager layoutManager = null)
     : base(impl)
 {
     _layoutManager = layoutManager ?? new LayoutManager();
 }
Example #16
0
 public TestTopLevel(ITopLevelImpl impl)
     : base(impl)
 {
 }
Example #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopLevel"/> class.
        /// </summary>
        /// <param name="impl">The platform-specific window implementation.</param>
        /// <param name="dependencyResolver">
        /// The dependency resolver to use. If null the default dependency resolver will be used.
        /// </param>
        public TopLevel(ITopLevelImpl impl, IAvaloniaDependencyResolver?dependencyResolver)
        {
            if (impl == null)
            {
                throw new InvalidOperationException(
                          "Could not create window implementation: maybe no windowing subsystem was initialized?");
            }

            PlatformImpl = impl;

            _actualTransparencyLevel = PlatformImpl.TransparencyLevel;

            dependencyResolver = dependencyResolver ?? AvaloniaLocator.Current;
            var styler = TryGetService <IStyler>(dependencyResolver);

            _accessKeyHandler          = TryGetService <IAccessKeyHandler>(dependencyResolver);
            _inputManager              = TryGetService <IInputManager>(dependencyResolver);
            _keyboardNavigationHandler = TryGetService <IKeyboardNavigationHandler>(dependencyResolver);
            _renderInterface           = TryGetService <IPlatformRenderInterface>(dependencyResolver);
            _globalStyles              = TryGetService <IGlobalStyles>(dependencyResolver);

            Renderer = impl.CreateRenderer(this);

            if (Renderer != null)
            {
                Renderer.SceneInvalidated += SceneInvalidated;
            }
            else
            {
                // Prevent nullable error.
                Renderer = null !;
            }

            impl.SetInputRoot(this);

            impl.Closed                   = HandleClosed;
            impl.Input                    = HandleInput;
            impl.Paint                    = HandlePaint;
            impl.Resized                  = HandleResized;
            impl.ScalingChanged           = HandleScalingChanged;
            impl.TransparencyLevelChanged = HandleTransparencyLevelChanged;

            _keyboardNavigationHandler?.SetOwner(this);
            _accessKeyHandler?.SetOwner(this);

            if (_globalStyles is object)
            {
                _globalStyles.GlobalStylesAdded   += ((IStyleHost)this).StylesAdded;
                _globalStyles.GlobalStylesRemoved += ((IStyleHost)this).StylesRemoved;
            }

            styler?.ApplyStyles(this);

            ClientSize = impl.ClientSize;
            FrameSize  = impl.FrameSize;

            this.GetObservable(PointerOverElementProperty)
            .Select(
                x => (x as InputElement)?.GetObservable(CursorProperty) ?? Observable.Empty <Cursor>())
            .Switch().Subscribe(cursor => PlatformImpl?.SetCursor(cursor?.PlatformImpl));

            if (((IStyleHost)this).StylingParent is IResourceHost applicationResources)
            {
                _resourcesChangesSubscriber = new TargetWeakEventSubscriber <TopLevel, ResourcesChangedEventArgs>(
                    this, static (target, _, _, e) =>
                {
                    ((ILogical)target).NotifyResourcesChanged(e);
                });

                ResourcesChangedWeakEvent.Subscribe(applicationResources, _resourcesChangesSubscriber);
            }

            impl.LostFocus += PlatformImpl_LostFocus;

            _pointerOverPreProcessor             = new PointerOverPreProcessor(this);
            _pointerOverPreProcessorSubscription = _inputManager?.PreProcess.Subscribe(_pointerOverPreProcessor);
        }
Example #18
0
 public ValidatingToplevelImpl(ITopLevelImpl impl)
 {
     _impl = impl ?? throw new InvalidOperationException(
                       "Could not create TopLevel implementation: maybe no windowing subsystem was initialized?");
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TopLevel"/> class.
 /// </summary>
 /// <param name="impl">The platform-specific window implementation.</param>
 public TopLevel(ITopLevelImpl impl)
     : this(impl, AvaloniaLocator.Current)
 {
 }
Example #20
0
 public EmbeddableControlRoot(ITopLevelImpl impl) : base(impl)
 {
 }
Example #21
0
 public static IRenderTarget CreateRenderTarget(ITopLevelImpl window)
 {
     return
         (new RenderTargetDecorator(
              PerspexLocator.Current.GetService <IPlatformRenderInterface>().CreateRenderer(window.Handle), window));
 }
Example #22
0
 public TestTopLevel(ITopLevelImpl impl)
     : base(impl)
 {
 }
Example #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TopLevel"/> class.
        /// </summary>
        /// <param name="impl">The platform-specific window implementation.</param>
        /// <param name="dependencyResolver">
        /// The dependency resolver to use. If null the default dependency resolver will be used.
        /// </param>
        public TopLevel(ITopLevelImpl impl, IDependencyResolver dependencyResolver)
        {
            dependencyResolver = dependencyResolver ?? Locator.Current;

            IPlatformRenderInterface renderInterface = dependencyResolver.GetService<IPlatformRenderInterface>();

            this.PlatformImpl = impl;
            this.accessKeyHandler = dependencyResolver.GetService<IAccessKeyHandler>();
            this.inputManager = dependencyResolver.GetService<IInputManager>();
            this.keyboardNavigationHandler = dependencyResolver.GetService<IKeyboardNavigationHandler>();
            this.LayoutManager = dependencyResolver.GetService<ILayoutManager>();
            this.renderManager = dependencyResolver.GetService<IRenderManager>();

            if (renderInterface == null)
            {
                throw new InvalidOperationException(
                    "Could not create an interface to the rendering subsystem: maybe no rendering subsystem was initialized?");
            }

            if (this.PlatformImpl == null)
            {
                throw new InvalidOperationException(
                    "Could not create window implementation: maybe no windowing subsystem was initialized?");
            }

            if (this.inputManager == null)
            {
                throw new InvalidOperationException(
                    "Could not create input manager: maybe Application.RegisterServices() wasn't called?");
            }

            if (this.LayoutManager == null)
            {
                throw new InvalidOperationException(
                    "Could not create layout manager: maybe Application.RegisterServices() wasn't called?");
            }

            if (this.renderManager == null)
            {
                throw new InvalidOperationException(
                    "Could not create render manager: maybe Application.RegisterServices() wasn't called?");
            }

            if (this.accessKeyHandler != null)
            {
                this.accessKeyHandler.SetOwner(this);
            }

            if (this.keyboardNavigationHandler != null)
            {
                this.keyboardNavigationHandler.SetOwner(this);
            }

            this.PlatformImpl.SetOwner(this);
            this.PlatformImpl.Activated = this.HandleActivated;
            this.PlatformImpl.Deactivated = this.HandleDeactivated;
            this.PlatformImpl.Closed = this.HandleClosed;
            this.PlatformImpl.Input = this.HandleInput;
            this.PlatformImpl.Paint = this.HandlePaint;
            this.PlatformImpl.Resized = this.HandleResized;

            Size clientSize = this.ClientSize = this.PlatformImpl.ClientSize;

            this.dispatcher = Dispatcher.UIThread;
            this.renderer = renderInterface.CreateRenderer(this.PlatformImpl.Handle, clientSize.Width, clientSize.Height);

            this.LayoutManager.Root = this;
            this.LayoutManager.LayoutNeeded.Subscribe(_ => this.HandleLayoutNeeded());
            this.LayoutManager.LayoutCompleted.Subscribe(_ => this.HandleLayoutCompleted());
            this.renderManager.RenderNeeded.Subscribe(_ => this.HandleRenderNeeded());

            IStyler styler = dependencyResolver.GetService<IStyler>();
            styler.ApplyStyles(this);

            this.GetObservable(ClientSizeProperty).Skip(1).Subscribe(x => this.PlatformImpl.ClientSize = x);
        }
Example #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TopLevel"/> class.
 /// </summary>
 /// <param name="impl">The platform-specific window implementation.</param>
 public TopLevel(ITopLevelImpl impl)
     : this(impl, Locator.Current)
 {
 }
Example #25
0
 public static IRenderTarget CreateRenderTarget(ITopLevelImpl window)
 {
     return(AvaloniaLocator.Current
            .GetService <IPlatformRenderInterface>()
            .CreateRenderer(window.Handle));
 }