Exemplo n.º 1
0
        private void Child_TopChanged(object sender, EventArgs e)
        {
            WindowControl windowControl = ( WindowControl )sender;

            if (windowControl != null)
            {
                windowControl.Top = this.GetRestrictedTop(windowControl);
            }

            Canvas.SetTop(windowControl, windowControl.Top);
        }
Exemplo n.º 2
0
        private void Child_LeftChanged(object sender, EventArgs e)
        {
            WindowControl windowControl = (WindowControl)sender;

            if (windowControl != null)
            {
                windowControl.Left = this.GetRestrictedLeft(windowControl);
            }

            Canvas.SetLeft(windowControl, windowControl.Left);
        }
Exemplo n.º 3
0
        private static object OnCoerceIsActive(DependencyObject d, object basevalue)
        {
            WindowControl w = d as WindowControl;

            if (w != null && !w._setIsActiveInternal && !w.AllowPublicIsActiveChange)
            {
                throw new InvalidOperationException("Cannot set IsActive directly. This is handled by the underlying system");
            }

            return(basevalue);
        }
Exemplo n.º 4
0
        private void Child_PreviewMouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            WindowControl windowControl = ( WindowControl )sender;

            WindowControl modalWindow = this.GetModalWindow();

            if (modalWindow == null)
            {
                this.SetNextActiveWindow(windowControl);
            }
        }
Exemplo n.º 5
0
        private void CenterChild(WindowControl windowControl)
        {
            windowControl.UpdateLayout();

            if ((windowControl.ActualWidth != 0) && (windowControl.ActualHeight != 0))
            {
                windowControl.Left  = (this.ActualWidth - windowControl.ActualWidth) / 2.0;
                windowControl.Left += (windowControl.Margin.Left - windowControl.Margin.Right);
                windowControl.Top   = (this.ActualHeight - windowControl.ActualHeight) / 2.0;
                windowControl.Top  += (windowControl.Margin.Top - windowControl.Margin.Bottom);
            }
        }
Exemplo n.º 6
0
        private void BringToFront(WindowControl windowControl)
        {
            if (windowControl != null)
            {
                int maxZIndez = this.Children.OfType <WindowControl>().Max((x) => Canvas.GetZIndex(x));
                Canvas.SetZIndex(windowControl, maxZIndez + 1);

                windowControl.Focus();

                this.SetActiveWindow(windowControl);
            }
        }
Exemplo n.º 7
0
        private void SetActiveWindow(WindowControl windowControl)
        {
            if (windowControl.IsActive)
            {
                return;
            }

            foreach (WindowControl window in this.Children)
            {
                window.SetIsActiveInternal(false);
            }
            windowControl.SetIsActiveInternal(true);
        }
Exemplo n.º 8
0
        private static object OnCoerceWindowStyle(DependencyObject d, object basevalue)
        {
            if (basevalue == DependencyProperty.UnsetValue)
            {
                return(basevalue);
            }

            WindowControl windowControl = d as WindowControl;

            if (windowControl == null)
            {
                return(basevalue);
            }
            return(windowControl.OnCoerceWindowStyle((WindowStyle)basevalue));
        }
Exemplo n.º 9
0
 private void SetChildPos(WindowControl windowControl)
 {
     // A MessageBox with no X and Y will be centered.
     // A ChildWindow with WindowStartupLocation == Center will be centered.
     if (((windowControl is MessageBox) && (windowControl.Left == 0) && (windowControl.Top == 0)) ||
         ((windowControl is ChildWindow) && ((( ChildWindow )windowControl).WindowStartupLocation == WindowStartupLocation.Center)))
     {
         this.CenterChild(windowControl);
     }
     else
     {
         Canvas.SetLeft(windowControl, windowControl.Left);
         Canvas.SetTop(windowControl, windowControl.Top);
     }
 }
Exemplo n.º 10
0
        private double GetRestrictedLeft(WindowControl windowControl)
        {
            if (windowControl.Left < 0)
            {
                return(0);
            }

            if (((windowControl.Left + windowControl.ActualWidth) > this.ActualWidth) && (this.ActualWidth != 0))
            {
                double x = this.ActualWidth - windowControl.ActualWidth;
                return(x < 0 ? 0 : x);
            }

            return(windowControl.Left);
        }
Exemplo n.º 11
0
        private static object OnCoerceCloseButtonVisibility(DependencyObject d, object basevalue)
        {
            if (basevalue == DependencyProperty.UnsetValue)
            {
                return(basevalue);
            }

            WindowControl windowControl = d as WindowControl;

            if (windowControl == null)
            {
                return(basevalue);
            }
            return(windowControl.OnCoerceCloseButtonVisibility((Visibility)basevalue));
        }
Exemplo n.º 12
0
        private double GetRestrictedTop(WindowControl windowControl)
        {
            if (windowControl.Top < 0)
            {
                return(0);
            }

            if (((windowControl.Top + windowControl.ActualHeight) > this.ActualHeight) && (this.ActualHeight != 0))
            {
                double y = this.ActualHeight - windowControl.ActualHeight;
                return(y < 0 ? 0 : y);
            }

            return(windowControl.Top);
        }
Exemplo n.º 13
0
        private void SetNextActiveWindow(WindowControl windowControl)
        {
            if (!this.IsLoaded)
            {
                return;
            }

            WindowControl modalWindow = this.GetModalWindow();

            // Modal window is always in front
            if (modalWindow != null)
            {
                this.BringToFront(modalWindow);
            }
            else if (windowControl != null)
            {
                this.BringToFront(windowControl);
            }
            else
            {
                this.BringToFront(this.Children.OfType <WindowControl>().FirstOrDefault((x) => x.Visibility == Visibility.Visible));
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Register and unregister to children events.
        /// </summary>
        protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
        {
            base.OnVisualChildrenChanged(visualAdded, visualRemoved);

            if (visualAdded != null && !(visualAdded is WindowControl))
            {
                throw new InvalidOperationException("WindowContainer can only contain WindowControl types.");
            }

            if (visualRemoved != null)
            {
                WindowControl removedChild = ( WindowControl )visualRemoved;
                removedChild.LeftChanged -= new EventHandler <EventArgs>(this.Child_LeftChanged);
                removedChild.TopChanged  -= new EventHandler <EventArgs>(this.Child_TopChanged);
                removedChild.PreviewMouseLeftButtonDown   -= new MouseButtonEventHandler(this.Child_PreviewMouseLeftButtonDown);
                removedChild.IsVisibleChanged             -= new DependencyPropertyChangedEventHandler(this.Child_IsVisibleChanged);
                removedChild.IsKeyboardFocusWithinChanged -= new DependencyPropertyChangedEventHandler(this.Child_IsKeyboardFocusWithinChanged);
                if (removedChild is ChildWindow)
                {
                    (( ChildWindow )removedChild).IsModalChanged -= new EventHandler <EventArgs>(this.Child_IsModalChanged);
                }
            }

            if (visualAdded != null)
            {
                WindowControl addedChild = ( WindowControl )visualAdded;
                addedChild.LeftChanged += new EventHandler <EventArgs>(this.Child_LeftChanged);
                addedChild.TopChanged  += new EventHandler <EventArgs>(this.Child_TopChanged);
                addedChild.PreviewMouseLeftButtonDown   += new MouseButtonEventHandler(this.Child_PreviewMouseLeftButtonDown);
                addedChild.IsVisibleChanged             += new DependencyPropertyChangedEventHandler(this.Child_IsVisibleChanged);
                addedChild.IsKeyboardFocusWithinChanged += new DependencyPropertyChangedEventHandler(this.Child_IsKeyboardFocusWithinChanged);
                if (addedChild is ChildWindow)
                {
                    (( ChildWindow )addedChild).IsModalChanged += new EventHandler <EventArgs>(this.Child_IsModalChanged);
                }
            }
        }
Exemplo n.º 15
0
    public override void OnApplyTemplate()
    {
      base.OnApplyTemplate();

      if( _windowControl != null )
      {
        _windowControl.HeaderDragDelta -= ( o, e ) => this.OnHeaderDragDelta( e );
        _windowControl.HeaderIconDoubleClicked -= ( o, e ) => this.OnHeaderIconDoubleClick( e );
        _windowControl.CloseButtonClicked -= ( o, e ) => this.OnCloseButtonClicked( e );
      }
      _windowControl = this.GetTemplateChild( PART_WindowControl ) as WindowControl;
      if( _windowControl != null )
      {
        _windowControl.HeaderDragDelta += ( o, e ) => this.OnHeaderDragDelta( e );
        _windowControl.HeaderIconDoubleClicked += ( o, e ) => this.OnHeaderIconDoubleClick( e );
        _windowControl.CloseButtonClicked += ( o, e ) => this.OnCloseButtonClicked( e );
      }

      this.UpdateBlockMouseInputsPanel();

      _windowRoot = this.GetTemplateChild( PART_WindowRoot ) as Grid;
      if( _windowRoot != null )
      {
        _windowRoot.RenderTransform = _moveTransform;
      }
      _hasWindowContainer = ( VisualTreeHelper.GetParent( this ) as WindowContainer ) != null;

      if( !_hasWindowContainer )
      {
        _parentContainer = VisualTreeHelper.GetParent( this ) as FrameworkElement;
        if( _parentContainer != null )
        {
          _parentContainer.LayoutUpdated += ParentContainer_LayoutUpdated;
          _parentContainer.SizeChanged += ParentContainer_SizeChanged;

          //this is for XBAP applications only. When inside an XBAP the parent container has no height or width until it has loaded. Therefore
          //we need to handle the loaded event and reposition the window.
          if( System.Windows.Interop.BrowserInteropHelper.IsBrowserHosted )
          {
            _parentContainer.Loaded += ( o, e ) =>
            {
              ExecuteOpen();
            };
          }
        }

        this.Unloaded += new RoutedEventHandler( ChildWindow_Unloaded );

        //initialize our modal background width/height
        _modalLayer.Height = _parentContainer.ActualHeight;
        _modalLayer.Width = _parentContainer.ActualWidth;

        _root = this.GetTemplateChild( PART_Root ) as Grid;

#if VS2008
      FocusVisualStyle = null;
#else
        Style focusStyle = ( _root != null ) ? _root.Resources[ "FocusVisualStyle" ] as Style : null;
        if( focusStyle != null )
        {
          Setter focusStyleDataContext = new Setter( Control.DataContextProperty, this );
          focusStyle.Setters.Add( focusStyleDataContext );
          FocusVisualStyle = focusStyle;
        }
#endif
        if( _root != null )
        {
          _root.Children.Add( _modalLayerPanel );
        }
      }
    }
    /// <summary>
    /// Overrides the OnApplyTemplate method.
    /// </summary>
    public override void OnApplyTemplate()
    {
      base.OnApplyTemplate();

      if( _windowControl != null )
      {
        _windowControl.HeaderDragDelta -= ( o, e ) => this.OnHeaderDragDelta( e );
        _windowControl.HeaderIconDoubleClicked -= ( o, e ) => this.OnHeaderIconDoubleClicked( e );
        _windowControl.CloseButtonClicked -= ( o, e ) => this.OnCloseButtonClicked( e );
      }
      _windowControl = this.GetTemplateChild( PART_WindowControl ) as WindowControl;
      if( _windowControl != null )
      {
        _windowControl.HeaderDragDelta += ( o, e ) => this.OnHeaderDragDelta( e );
        _windowControl.HeaderIconDoubleClicked += ( o, e ) => this.OnHeaderIconDoubleClicked( e );
        _windowControl.CloseButtonClicked += ( o, e ) => this.OnCloseButtonClicked( e );
      }
      this.UpdateBlockMouseInputsPanel();

      ChangeVisualState( _button.ToString(), true );

      Button closeButton = GetMessageBoxButton( PART_CloseButton );
      if( closeButton != null )
        closeButton.IsEnabled = !object.Equals( _button, MessageBoxButton.YesNo );

      Button okButton = GetMessageBoxButton( PART_OkButton );
      if( okButton != null )
        okButton.IsCancel = object.Equals( _button, MessageBoxButton.OK );

      SetDefaultResult();
    }
Exemplo n.º 17
0
    private double GetRestrictedTop( WindowControl windowControl )
    {
      if( windowControl.Top < 0 )
        return 0;

      if( ( ( windowControl.Top + windowControl.ActualHeight ) > this.ActualHeight ) && ( this.ActualHeight != 0 ) )
      {
        double y = this.ActualHeight - windowControl.ActualHeight;
        return y < 0 ? 0 : y;
      }

      return windowControl.Top;
    }
Exemplo n.º 18
0
    private double GetRestrictedLeft( WindowControl windowControl )
    {
      if( windowControl.Left < 0 )
        return 0;

      if( ( ( windowControl.Left + windowControl.ActualWidth ) > this.ActualWidth ) && ( this.ActualWidth != 0 ) )
      {
        double x = this.ActualWidth - windowControl.ActualWidth;
        return x < 0 ? 0 : x;
      }

      return windowControl.Left;
    }
Exemplo n.º 19
0
 private bool IsModalWindow( WindowControl windowControl )
 {
   return ( ( windowControl is MessageBox )
          || ( ( windowControl is ChildWindow ) && ( ( ChildWindow )windowControl ).IsModal ) );
 }
Exemplo n.º 20
0
 private void SetActiveWindow( WindowControl windowControl )
 {
   foreach( WindowControl window in this.Children )
   {
     window.SetIsActiveInternal( false );
   }
   windowControl.SetIsActiveInternal( true );
 }
Exemplo n.º 21
0
 private void ExpandWindowControl( WindowControl windowControl )
 {
   if( windowControl != null )
   {
     windowControl.Left = 0;
     windowControl.Top = 0;
     windowControl.Width = Math.Min( this.ActualWidth, windowControl.MaxWidth );
     windowControl.Height = Math.Min( this.ActualHeight, windowControl.MaxHeight );
   }
 }
Exemplo n.º 22
0
    private void SetNextActiveWindow( WindowControl windowControl )
    {
      if( !this.IsLoaded )
        return;

      WindowControl modalWindow = this.GetModalWindow();
      // Modal window is always in front
      if( modalWindow != null )
      {
        this.BringToFront( modalWindow );
      }
      else if( windowControl != null )
      {
        this.BringToFront( windowControl );
      }
      else
      {
        this.BringToFront( this.Children.OfType<WindowControl>().FirstOrDefault( (x) => x.Visibility == Visibility.Visible ) );
      }
    }
Exemplo n.º 23
0
        private void Child_PreviewMouseLeftButtonDown(object sender, RoutedEventArgs e)
        {
            WindowControl windowControl = ( WindowControl )sender;

            this.SetNextActiveWindow(windowControl);
        }
Exemplo n.º 24
0
 private bool IsModalWindow(WindowControl windowControl)
 {
     return((windowControl is MessageBox) ||
            ((windowControl is ChildWindow) && (( ChildWindow )windowControl).IsModal));
 }
Exemplo n.º 25
0
    private void BringToFront( WindowControl windowControl )
    {
      if( windowControl != null )
      {
        int maxZIndez = this.Children.OfType<WindowControl>().Max( ( x ) => Canvas.GetZIndex( x ) );
        Canvas.SetZIndex( windowControl, maxZIndez + 1 );

        windowControl.Focus();

        this.SetActiveWindow( windowControl );
      }
    }
Exemplo n.º 26
0
 private bool IsModalWindow( WindowControl windowControl )
 {
   return ( ( ( windowControl is MessageBox ) && (windowControl.Visibility == Visibility.Visible) )
          || ( ( windowControl is ChildWindow ) && ( ( ChildWindow )windowControl ).IsModal && ( ( ChildWindow )windowControl).WindowState == WindowState.Open ) );
 }
Exemplo n.º 27
0
 private bool IsModalWindow(WindowControl windowControl)
 {
     return(((windowControl is MessageBox) && (windowControl.Visibility == Visibility.Visible)) ||
            ((windowControl is ChildWindow) && (( ChildWindow )windowControl).IsModal && (( ChildWindow )windowControl).WindowState == WindowState.Open));
 }
Exemplo n.º 28
0
 private void SetChildPos( WindowControl windowControl )
 {
   // A MessageBox with no X and Y will be centered.
   // A ChildWindow with WindowStartupLocation == Center will be centered.
   if( ( ( windowControl is MessageBox ) && ( windowControl.Left == 0 ) && ( windowControl.Top == 0 ) )
     || ( ( windowControl is ChildWindow ) && ( ( ( ChildWindow )windowControl ).WindowStartupLocation == WindowStartupLocation.Center ) ) )
   {
     this.CenterChild( windowControl );
   }
   else
   {
     Canvas.SetLeft( windowControl, windowControl.Left );
     Canvas.SetTop( windowControl, windowControl.Top );
   }
 }
Exemplo n.º 29
0
 private void CenterChild( WindowControl windowControl )
 {
   if( ( windowControl.ActualWidth != 0 ) && ( windowControl.ActualHeight != 0 ) )
   {
     windowControl.Left = ( this.ActualWidth - windowControl.ActualWidth ) / 2.0;
     windowControl.Top = ( this.ActualHeight - windowControl.ActualHeight ) / 2.0;
   }
 }
Exemplo n.º 30
0
 private void CenterChild( WindowControl windowControl )
 {
   if( ( windowControl.ActualWidth != 0 ) && ( windowControl.ActualHeight != 0 ) )
   {
     windowControl.Left = ( this.ActualWidth - windowControl.ActualWidth ) / 2.0;
     windowControl.Left += (windowControl.Margin.Left - windowControl.Margin.Right);
     windowControl.Top = ( this.ActualHeight - windowControl.ActualHeight ) / 2.0;
     windowControl.Top += ( windowControl.Margin.Top - windowControl.Margin.Bottom );
   }
 }