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 __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
25 #define __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <threadhelp/threadhelpbase.hxx>
32 #include <macros/debug.hxx>
33 #include <macros/xinterface.hxx>
34 #include <macros/xtypeprovider.hxx>
35 #include <general.h>
36 
37 //_________________________________________________________________________________________________________________
38 //	interface includes
39 //_________________________________________________________________________________________________________________
40 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <com/sun/star/lang/XInitialization.hpp>
42 #include <com/sun/star/frame/XFrame.hpp>
43 #include <com/sun/star/frame/XFrameActionListener.hpp>
44 #include <com/sun/star/lang/XEventListener.hpp>
45 
46 //_________________________________________________________________________________________________________________
47 //	other includes
48 //_________________________________________________________________________________________________________________
49 #include <unotools/moduleoptions.hxx>
50 #include <cppuhelper/weak.hxx>
51 
52 //_________________________________________________________________________________________________________________
53 //	const
54 //_________________________________________________________________________________________________________________
55 
56 //_________________________________________________________________________________________________________________
57 //	namespace
58 //_________________________________________________________________________________________________________________
59 
60 namespace framework{
61 
62 //_________________________________________________________________________________________________________________
63 //	declarations
64 //_________________________________________________________________________________________________________________
65 
66 /*-************************************************************************************************************//**
67     @short          listener for closing document frames to make her window state persistent
68     @descr          It's a feature of our office. If a document window was created by ourself (and not from
69                     any external process e.g. the office bean) we save and restore the window state of it
70                     corresponding to the document service factory. That means: one instance of this class will be
71                     a listener on one frame which container window was created by ourself.
72                     We listen for frame action events and everytimes a component will deattached from a frame
73                     we store its current position and size to the configuration. Everytimes a new component is
74                     attached to a frame first time(!) we restore this informations again.
75 
76     @base           ThreadHelpBase
77                         guarantee right initialized lock member during startup of instances of this class.
78 
79     @base           OWeakObject
80                         implements ref counting for this class.
81 
82     @devstatus      ready
83     @threadsafe     yes
84     @modified       06.08.2004 08:41, as96863
85 *//*-*************************************************************************************************************/
86 class PersistentWindowState :   // interfaces
87                                 public css::lang::XTypeProvider,
88                                 public css::lang::XInitialization,
89                                 public css::frame::XFrameActionListener, // => XEventListener
90                                 // baseclasses (order necessary for right initialization!)
91                                 private ThreadHelpBase,
92                                 public  ::cppu::OWeakObject
93 {
94     //________________________________
95     // member
96 
97 	private:
98 
99         /// may we need an uno service manager to create own services
100         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
101 
102         /// reference to the frame which was created by the office himself
103         css::uno::WeakReference< css::frame::XFrame > m_xFrame;
104 
105         /// we call SetWindowState one times only for the same frame!
106         sal_Bool m_bWindowStateAlreadySet;
107 
108     //________________________________
109     // interface
110 
111 	public:
112 
113         //____________________________
114         // ctor/dtor
115                  PersistentWindowState(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
116         virtual ~PersistentWindowState(                                                                   );
117 
118         //____________________________
119         // XInterface, XTypeProvider
120         FWK_DECLARE_XINTERFACE
121         FWK_DECLARE_XTYPEPROVIDER
122 
123         //____________________________
124         // XInitialization
125         virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
126             throw(css::uno::Exception       ,
127                   css::uno::RuntimeException);
128 
129         //____________________________
130         // XFrameActionListener
131         virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent)
132             throw(css::uno::RuntimeException);
133 
134         //____________________________
135         // XEventListener
136         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
137             throw(css::uno::RuntimeException);
138 
139     //________________________________
140     // helper
141 
142     private:
143         //____________________________
144         /** @short  identify the application module, which  is used behind the component
145                     of our frame.
146 
147             @param  xSMGR
148                     needed to create needed uno resources.
149 
150             @param  xFrame
151                     contains the component, which must be identified.
152 
153             @return [string]
154                     a module identifier for the current frame component.
155          */
156         static ::rtl::OUString implst_identifyModule(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
157                                                      const css::uno::Reference< css::frame::XFrame >&              xFrame);
158 
159         //____________________________
160         /** @short  retrieve the window state from the configuration.
161 
162             @param  xSMGR
163                     needed to create the configuration access.
164 
165             @param  sModuleName
166                     identifies the application module, where the
167                     information should be getted for.
168 
169             @return [string]
170                     contains the information about position and size.
171          */
172         static ::rtl::OUString implst_getWindowStateFromConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR      ,
173                                                                const ::rtl::OUString&                                        sModuleName);
174 
175         //____________________________
176         /** @short  retrieve the window state from the container window.
177 
178             @param  xWindow
179                     must point to the container window of the frame.
180                     We use it VCL part here - because the toolkit doesn't
181                     provide the right functionality!
182 
183             @return [string]
184                     contains the information about position and size.
185          */
186         static ::rtl::OUString implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow >& xWindow);
187 
188         //____________________________
189         /** @short  restore the position and size on the container window.
190 
191             @param  xSMGR
192                     needed to create the configuration access.
193 
194             @param  sModuleName
195                     identifies the application module, where the
196                     information should be set on.
197 
198             @param  sWindowState
199                     contains the information about position and size.
200          */
201         static void implst_setWindowStateOnConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR         ,
202                                                   const ::rtl::OUString&                                        sModuleName   ,
203                                                   const ::rtl::OUString&                                        sWindowState  );
204 
205         //____________________________
206         /** @short  restore the position and size on the container window.
207 
208             @param  xWindow
209                     must point to the container window of the frame.
210                     We use it VCL part here - because the toolkit doesn't
211                     provide the right functionality!
212 
213             @param  sWindowState
214                     contains the information about position and size.
215          */
216         static void implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow >& xWindow     ,
217                                                   const ::rtl::OUString&                          sWindowState);
218 
219 }; // class PersistentWindowState
220 
221 } // namespace framework
222 
223 #endif // #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
224