diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-03-19 10:28:04 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2010-03-19 10:28:04 +0100 |
commit | 75716ac51b8555e77382a1c20a307477f0b43058 (patch) | |
tree | e043b2e13cc26a2bc76d017f165092234cdb2c30 | |
parent | cd95230c2f9a46805d494981152d91df8481424a (diff) |
slidecopy: reworked the ToolPanelDeck to have a dedicated anchor window for the panel's windows. This will ease some later changes
-rw-r--r-- | svtools/inc/svtools/toolpanel/toolpanel.hxx | 39 | ||||
-rw-r--r-- | svtools/inc/svtools/toolpanel/toolpaneldeck.hxx | 7 | ||||
-rw-r--r-- | svtools/source/toolpanel/dummypanel.cxx | 12 | ||||
-rw-r--r-- | svtools/source/toolpanel/dummypanel.hxx | 7 | ||||
-rw-r--r-- | svtools/source/toolpanel/toolpaneldeck.cxx | 31 | ||||
-rw-r--r-- | svtools/workben/toolpanel/toolpaneltest.cxx | 36 |
6 files changed, 75 insertions, 57 deletions
diff --git a/svtools/inc/svtools/toolpanel/toolpanel.hxx b/svtools/inc/svtools/toolpanel/toolpanel.hxx index eae9c504a270..dd91713b3725 100644 --- a/svtools/inc/svtools/toolpanel/toolpanel.hxx +++ b/svtools/inc/svtools/toolpanel/toolpanel.hxx @@ -56,28 +56,41 @@ namespace svt /// retrieves the image associated with the panel, if any virtual Image GetImage() const = 0; - /// shows the panel window - virtual void Show() = 0; + /** activates the panel - /// hides the panel window - virtual void Hide() = 0; + Usually, this means the panel's Window is created (if not previosly done so) and shown. - /// sets the position of the panel window - virtual void SetPosSizePixel( const Rectangle& i_rPanelPlayground ) = 0; + @param i_rParentWindow + the parent window to anchor the panel window at. Subsequent calls to the Activate + method will always get the same parent window. The complete area of this window is + available, and should be used, for the panel window. + */ + virtual void Activate( Window& i_rParentWindow ) = 0; - /// sets the focus to the panel window - virtual void GrabFocus() = 0; + /** deactivates the panel + + There are different ways how an implementation could deactivate a panel. The easiest way + would be to simply hide the associated Window. Alternatively, you could completely destroy it, + or decide to cache it by re-parenting it to another (temporary, invisible) window. + */ + virtual void Deactivate() = 0; - /** determines whether the panel window, or any of its children, currently has the focus + /** sets a new size for the panel's Window - Effectively, an implementation simply needs to redelegate this to its panel window's HasChildPathFocus - method. + The panel window is always expected to be positioned at (0,0), relative to the parent window + which was passed to the Activate member. Resizing the panel window is necessary when the size of + this parent window changes. Effectively, this method is a means of convenience, to relief panel + implementations from reacting on size changes of their parent window themselves. */ - virtual bool HasFocus() const = 0; + virtual void SetSizePixel( const Size& i_rPanelWindowSize ) = 0; + + /// sets the focus to the panel window + virtual void GrabFocus() = 0; /** release any resources associated with the panel. - In particular, implementations should destroy the VCL window which implements the panel window. + In particular, implementations should ultimately destroy the VCL window which implements the panel + window. No subsequent calls to any other method will happen after Destroy has been called. */ virtual void Dispose() = 0; diff --git a/svtools/inc/svtools/toolpanel/toolpaneldeck.hxx b/svtools/inc/svtools/toolpanel/toolpaneldeck.hxx index 7e0827dbc44a..97653eea0eb0 100644 --- a/svtools/inc/svtools/toolpanel/toolpaneldeck.hxx +++ b/svtools/inc/svtools/toolpanel/toolpaneldeck.hxx @@ -137,6 +137,13 @@ namespace svt PDeckLayouter GetLayouter() const; void SetLayouter( const PDeckLayouter& i_pNewLayouter ); + /** returns the window which acts as anchor for the panel windows. + + This is a single dedicated window, which is passed to the IToolPanel::ActivatePanel method + whenever a panel is activated, to act as parent window for the panel's VCL-Window. + */ + Window& GetPanelWindowAnchor(); + // IToolPanelDeck virtual size_t GetPanelCount() const; virtual PToolPanel GetPanel( const size_t i_nPos ) const; diff --git a/svtools/source/toolpanel/dummypanel.cxx b/svtools/source/toolpanel/dummypanel.cxx index d199628b004e..d92444369c04 100644 --- a/svtools/source/toolpanel/dummypanel.cxx +++ b/svtools/source/toolpanel/dummypanel.cxx @@ -50,17 +50,17 @@ namespace svt IMPLEMENT_IREFERENCE( DummyPanel ) //-------------------------------------------------------------------- - void DummyPanel::Show() + void DummyPanel::Activate( Window& ) { } //-------------------------------------------------------------------- - void DummyPanel::Hide() + void DummyPanel::Deactivate() { } //-------------------------------------------------------------------- - void DummyPanel::SetPosSizePixel( const Rectangle& /*i_rPanelPlayground*/ ) + void DummyPanel::SetSizePixel( const Size& ) { } @@ -82,12 +82,6 @@ namespace svt } //-------------------------------------------------------------------- - bool DummyPanel::HasFocus() const - { - return false; - } - - //-------------------------------------------------------------------- void DummyPanel::Dispose() { } diff --git a/svtools/source/toolpanel/dummypanel.hxx b/svtools/source/toolpanel/dummypanel.hxx index a5af4844e420..bcaf564cb021 100644 --- a/svtools/source/toolpanel/dummypanel.hxx +++ b/svtools/source/toolpanel/dummypanel.hxx @@ -49,11 +49,10 @@ namespace svt // IToolPanel virtual ::rtl::OUString GetDisplayName() const; virtual Image GetImage() const; - virtual void Show(); - virtual void Hide(); - virtual void SetPosSizePixel( const Rectangle& i_rPanelPlayground ); + virtual void Activate( Window& i_rParentWindow ); + virtual void Deactivate(); + virtual void SetSizePixel( const Size& i_rPanelWindowSize ); virtual void GrabFocus(); - virtual bool HasFocus() const; virtual void Dispose(); DECLARE_IREFERENCE() diff --git a/svtools/source/toolpanel/toolpaneldeck.cxx b/svtools/source/toolpanel/toolpaneldeck.cxx index 6f5a8ad6fa19..3b54a112c0da 100644 --- a/svtools/source/toolpanel/toolpaneldeck.cxx +++ b/svtools/source/toolpanel/toolpaneldeck.cxx @@ -65,12 +65,13 @@ namespace svt public: ToolPanelDeck_Impl( ToolPanelDeck& i_rDeck ) :m_rDeck( i_rDeck ) + ,m_aPanelAnchor( &i_rDeck ) ,m_aPanels() ,m_pDummyPanel( new DummyPanel ) ,m_pLayouter() - ,m_aPanelPlayground() { m_aPanels.AddListener( *this ); + m_aPanelAnchor.Show(); } ~ToolPanelDeck_Impl() @@ -82,6 +83,8 @@ namespace svt PDeckLayouter GetLayouter() const { return m_pLayouter; } void SetLayouter( const PDeckLayouter& i_pNewLayouter ); + Window& GetPanelWindowAnchor() { return m_aPanelAnchor; } + // IToolPanelDeck equivalents size_t GetPanelCount() const; PToolPanel GetPanel( const size_t i_nPos ) const; @@ -113,12 +116,12 @@ namespace svt private: ToolPanelDeck& m_rDeck; + Window m_aPanelAnchor; ToolPanelCollection m_aPanels; PToolPanel m_pDummyPanel; PanelDeckListeners m_aListeners; PDeckLayouter m_pLayouter; - Rectangle m_aPanelPlayground; }; //-------------------------------------------------------------------- @@ -184,17 +187,18 @@ namespace svt { const Rectangle aDeckPlayground( Point(), m_rDeck.GetOutputSizePixel() ); - // let the layouter do the main work - m_aPanelPlayground = aDeckPlayground; + // ask the layouter what is left for our panel, and position the panel container window appropriately + Rectangle aPlaygroundArea( aDeckPlayground ); OSL_ENSURE( m_pLayouter.get(), "ToolPanelDeck_Impl::ImplDoLayout: no layouter!" ); if ( m_pLayouter.get() ) { - m_aPanelPlayground = m_pLayouter->Layout( aDeckPlayground ); + aPlaygroundArea = m_pLayouter->Layout( aDeckPlayground ); } + m_aPanelAnchor.SetPosSizePixel( aPlaygroundArea.TopLeft(), aPlaygroundArea.GetSize() ); - // and position the active panel + // position the active panel const PToolPanel pActive( GetActiveOrDummyPanel_Impl() ); - pActive->SetPosSizePixel( m_aPanelPlayground ); + pActive->SetSizePixel( m_aPanelAnchor.GetSizePixel() ); } //-------------------------------------------------------------------- @@ -243,7 +247,7 @@ namespace svt case ACTION_TOGGLE_FOCUS: { PToolPanel pActivePanel( GetActiveOrDummyPanel_Impl() ); - if ( !pActivePanel->HasFocus() ) + if ( !m_aPanelAnchor.HasChildPathFocus() ) pActivePanel->GrabFocus(); else GetLayouter()->SetFocusToPanelSelector(); @@ -285,13 +289,12 @@ namespace svt if ( !!i_rOldActive ) { const PToolPanel pOldActive( m_aPanels.GetPanel( *i_rOldActive ) ); - pOldActive->Hide(); + pOldActive->Deactivate(); } // position and show the new panel const PToolPanel pNewActive( !i_rNewActive ? m_pDummyPanel : m_aPanels.GetPanel( *i_rNewActive ) ); - pNewActive->SetPosSizePixel( m_aPanelPlayground ); - pNewActive->Show(); + pNewActive->Activate( m_aPanelAnchor ); pNewActive->GrabFocus(); // multiplex to our own listeners @@ -391,6 +394,12 @@ namespace svt } //-------------------------------------------------------------------- + Window& ToolPanelDeck::GetPanelWindowAnchor() + { + return m_pImpl->GetPanelWindowAnchor(); + } + + //-------------------------------------------------------------------- void ToolPanelDeck::Resize() { Control::Resize(); diff --git a/svtools/workben/toolpanel/toolpaneltest.cxx b/svtools/workben/toolpanel/toolpaneltest.cxx index f6b642f905e6..8291d60a3b7b 100644 --- a/svtools/workben/toolpanel/toolpaneltest.cxx +++ b/svtools/workben/toolpanel/toolpaneltest.cxx @@ -144,11 +144,10 @@ public: // IToolPanel virtual ::rtl::OUString GetDisplayName() const; virtual Image GetImage() const; - virtual void Show(); - virtual void Hide(); - virtual void SetPosSizePixel( const Rectangle& i_rPanelPlayground ); + virtual void Activate( Window& i_rParentWindow ); + virtual void Deactivate(); + virtual void SetSizePixel( const Size& i_rPanelWindowSize ); virtual void GrabFocus(); - virtual bool HasFocus() const; virtual void Dispose(); // IReference @@ -211,24 +210,28 @@ oslInterlockedCount SAL_CALL ColoredPanel::release() } //----------------------------------------------------------------------------- -void ColoredPanel::Show() +void ColoredPanel::Activate( Window& i_rParentWindow ) { ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" ); + OSL_ENSURE( &i_rParentWindow == m_pWindow->GetParent(), "ColoredPanel::Activate: unexpected new parent window!" ); + // the documentation of IToolPanel::Activate says it is guaranteed that the parent window is + // always the same ... + m_pWindow->SetPosSizePixel( Point(), i_rParentWindow.GetSizePixel() ); m_pWindow->Show(); } //----------------------------------------------------------------------------- -void ColoredPanel::Hide() +void ColoredPanel::Deactivate() { ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" ); m_pWindow->Hide(); } //----------------------------------------------------------------------------- -void ColoredPanel::SetPosSizePixel( const Rectangle& i_rPanelPlayground ) +void ColoredPanel::SetSizePixel( const Size& i_rPanelWindowSize ) { ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" ); - m_pWindow->SetPosSizePixel( i_rPanelPlayground.TopLeft(), i_rPanelPlayground.GetSize() ); + m_pWindow->SetSizePixel( i_rPanelWindowSize ); } //----------------------------------------------------------------------------- @@ -239,13 +242,6 @@ void ColoredPanel::GrabFocus() } //----------------------------------------------------------------------------- -bool ColoredPanel::HasFocus() const -{ - ENSURE_OR_RETURN_FALSE( m_pWindow.get(), "disposed!" ); - return m_pWindow->HasChildPathFocus(); -} - -//----------------------------------------------------------------------------- void ColoredPanel::Dispose() { ENSURE_OR_RETURN_VOID( m_pWindow.get(), "disposed!" ); @@ -733,10 +729,10 @@ PanelDemoMainWindow::PanelDemoMainWindow() m_aToolPanelDeck.SetPosSizePixel( Point( 20, 20 ), Size( 500, 300 ) ); m_aToolPanelDeck.SetBorderStyle( WINDOW_BORDER_MONO ); - m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck, Color( COL_RED ), "Red" ) ), m_aToolPanelDeck.GetPanelCount() ); - m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck, Color( COL_GREEN ), "Some flavor of Green" ) ), m_aToolPanelDeck.GetPanelCount() ); - m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck, RGB_COLORDATA( 255, 255, 0 ), "Yellow is ugly" ) ), m_aToolPanelDeck.GetPanelCount() ); - m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck, RGB_COLORDATA( 0, 0, 128 ), "Blue is the Color" ) ), m_aToolPanelDeck.GetPanelCount() ); + m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), Color( COL_RED ), "Red" ) ), m_aToolPanelDeck.GetPanelCount() ); + m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), Color( COL_GREEN ), "Some flavor of Green" ) ), m_aToolPanelDeck.GetPanelCount() ); + m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), RGB_COLORDATA( 255, 255, 0 ), "Yellow is ugly" ) ), m_aToolPanelDeck.GetPanelCount() ); + m_aToolPanelDeck.InsertPanel( PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), RGB_COLORDATA( 0, 0, 128 ), "Blue is the Color" ) ), m_aToolPanelDeck.GetPanelCount() ); m_aToolPanelDeck.ActivatePanel( size_t( 0 ) ); m_aToolPanelDeck.Show(); @@ -812,7 +808,7 @@ IToolPanelDeck& PanelDemoMainWindow::GetToolPanelDeck() //----------------------------------------------------------------------------- PToolPanel PanelDemoMainWindow::CreateToolPanel( const Color& i_rColor, const String& i_rPanelName ) { - return PToolPanel( new ColoredPanel( m_aToolPanelDeck, i_rColor, i_rPanelName ) ); + return PToolPanel( new ColoredPanel( m_aToolPanelDeck.GetPanelWindowAnchor(), i_rColor, i_rPanelName ) ); } //============================================================================= |