1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SVT_TOOLPANELDECK_HXX
25 #define SVT_TOOLPANELDECK_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include "svtools/toolpanel/toolpanel.hxx"
29 #include "svtools/toolpanel/decklayouter.hxx"
30 
31 #include <vcl/ctrl.hxx>
32 
33 #include <boost/optional.hpp>
34 #include <memory>
35 
36 //........................................................................
37 namespace svt
38 {
39 //........................................................................
40 
41     class ToolPanelCollection;
42     class ToolPanelDeck_Impl;
43 
44 	//====================================================================
45 	//= IToolPanelDeckListener
46 	//====================================================================
47     class SAL_NO_VTABLE IToolPanelDeckListener
48     {
49     public:
50         /** called when a panel has been inserted into the deck
51         */
52         virtual void PanelInserted( const PToolPanel& i_pPanel, const size_t i_nPosition ) = 0;
53 
54         /** called when a panel has been removed from the deck
55         */
56         virtual void PanelRemoved( const size_t i_nPosition ) = 0;
57 
58         /** called when the active panel of the deck changed
59         */
60         virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive ) = 0;
61 
62         /** called when a new layouter has been set at a tool panel deck.
63 
64             The method is called after the old layouter has been disposed (i.e. its Destroy method has been
65             invoked), and after the complete deck has been re-layouter.
66         */
67         virtual void LayouterChanged( const PDeckLayouter& i_rNewLayouter ) = 0;
68 
69         /** called when the tool panel deck which the listener registered at is dying. The listener is required to
70             release all references to the deck then.
71         */
72         virtual void Dying() = 0;
73     };
74 
75 	//====================================================================
76 	//= IToolPanelDeck
77 	//====================================================================
78     class SVT_DLLPUBLIC IToolPanelDeck
79     {
80     public:
81         /** returns the number of panels in the container
82         */
83         virtual size_t      GetPanelCount() const = 0;
84 
85         /** retrieves the panel with the given index. Invalid indexes will be reported via an assertion in the
86             non-product version, and silently ignored in the product version, with a NULL panel being returned.
87         */
88         virtual PToolPanel  GetPanel( const size_t i_nPos ) const = 0;
89 
90         /** returns the number of the currently active panel.
91         */
92         virtual ::boost::optional< size_t >
93                             GetActivePanel() const = 0;
94 
95         /** activates the panel with the given number. If the given number is larger or equal to the number of panels
96             in the deck, this will be reported via an assertion in non-product builds, and otherwise ignored.
97             @param i_rPanel
98                 the number of the panel to activate. If this is not set, the currently active panel is de-activated,
99                 and no new panel is activated at all. Whether or not this makes sense for your application is at
100                 your own discretion.
101         */
102         virtual void        ActivatePanel( const ::boost::optional< size_t >& i_rPanel ) = 0;
103 
104         /** inserts a new panel into the container. NULL panels are not allowed, as are positions greater than the
105             current panel count. Violations of this will be reported via an assertion in the non-product version, and
106             silently ignored in the product version.
107         */
108         virtual size_t      InsertPanel( const PToolPanel& i_pPanel, const size_t i_nPosition ) = 0;
109 
110         /** removes a panel specified by its position.
111 
112             Note: It is the responsibility of the caller to ensure that the panel is destroyed appropriately. That is,
113             the tool panel deck will <em>not</em> invoke <member>IToolPanel::Dispose</member> on the removed panel.
114             The advantage is that the panel might be re-used later, with the disadvantage that the owner of the panel
115             deck must know whether Dispose must be invoked after removal, or whether the panel will properly
116             dispose itself when its ref count drops to 0.
117         */
118         virtual PToolPanel  RemovePanel( const size_t i_nPosition ) = 0;
119 
120         /** adds a new listener to be notified when the container content changes. The caller is responsible
121             for life time control, i.e. removing the listener before it actually dies.
122         */
123         virtual void        AddListener( IToolPanelDeckListener& i_rListener ) = 0;
124 
125         /** removes a container listener previously added via addListener.
126         */
127         virtual void        RemoveListener( IToolPanelDeckListener& i_rListener ) = 0;
128     };
129 
130 	//====================================================================
131 	//= ToolPanelDeck
132 	//====================================================================
133     class SVT_DLLPUBLIC ToolPanelDeck   :public Control
134                                         ,public IToolPanelDeck
135 	{
136     public:
137         ToolPanelDeck( Window& i_rParent, const WinBits i_nStyle = WB_DIALOGCONTROL );
138         ~ToolPanelDeck();
139 
140         // attributes
141         PDeckLayouter       GetLayouter() const;
142         void                SetLayouter( const PDeckLayouter& i_pNewLayouter );
143 
144         /** returns the window which acts as anchor for the panel windows.
145 
146             This is a single dedicated window, which is passed to the IToolPanel::ActivatePanel method
147             whenever a panel is activated, to act as parent window for the panel's VCL-Window.
148         */
149         ::Window&           GetPanelWindowAnchor();
150         const ::Window&     GetPanelWindowAnchor() const;
151 
152         /** sets the window which should act as parent in the A11Y object hierarchy.
153 
154             Calling this method has no effect if CreateAccessible had always been called.
155         */
156         void                SetAccessibleParentWindow( ::Window* i_pAccessibleParent );
157         ::Window*           GetAccessibleParentWindow() const;
158 
159         // IToolPanelDeck
160         virtual size_t      GetPanelCount() const;
161         virtual PToolPanel  GetPanel( const size_t i_nPos ) const;
162         virtual ::boost::optional< size_t >
163                             GetActivePanel() const;
164         virtual void        ActivatePanel( const ::boost::optional< size_t >& i_rPanel );
165         virtual size_t      InsertPanel( const PToolPanel& i_pPanel, const size_t i_nPosition );
166         virtual PToolPanel  RemovePanel( const size_t i_nPosition );
167         virtual void        AddListener( IToolPanelDeckListener& i_rListener );
168         virtual void        RemoveListener( IToolPanelDeckListener& i_rListener );
169 
170     protected:
171         // Window overridables
172         virtual void Resize();
173         virtual long Notify( NotifyEvent& i_rNotifyEvent );
174         virtual void GetFocus();
175 
176         virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
177                      GetComponentInterface( sal_Bool i_bCreate );
178 
179     private:
180         ::std::auto_ptr< ToolPanelDeck_Impl >   m_pImpl;
181 
182     private:
183         using Window::GetAccessibleParentWindow;
184 	};
185 
186 //........................................................................
187 } // namespace svt
188 //........................................................................
189 
190 #endif // SVT_TOOLPANELDECK_HXX
191