xref: /trunk/main/framework/inc/helper/persistentwindowstate.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
127         //____________________________
128         // XFrameActionListener
129         virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent);
130 
131         //____________________________
132         // XEventListener
133         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent);
134 
135     //________________________________
136     // helper
137 
138     private:
139         //____________________________
140         /** @short  identify the application module, which  is used behind the component
141                     of our frame.
142 
143             @param  xSMGR
144                     needed to create needed uno resources.
145 
146             @param  xFrame
147                     contains the component, which must be identified.
148 
149             @return [string]
150                     a module identifier for the current frame component.
151          */
152         static ::rtl::OUString implst_identifyModule(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
153                                                      const css::uno::Reference< css::frame::XFrame >&              xFrame);
154 
155         //____________________________
156         /** @short  retrieve the window state from the configuration.
157 
158             @param  xSMGR
159                     needed to create the configuration access.
160 
161             @param  sModuleName
162                     identifies the application module, where the
163                     information should be getted for.
164 
165             @return [string]
166                     contains the information about position and size.
167          */
168         static ::rtl::OUString implst_getWindowStateFromConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR      ,
169                                                                const ::rtl::OUString&                                        sModuleName);
170 
171         //____________________________
172         /** @short  retrieve the window state from the container window.
173 
174             @param  xWindow
175                     must point to the container window of the frame.
176                     We use it VCL part here - because the toolkit doesn't
177                     provide the right functionality!
178 
179             @return [string]
180                     contains the information about position and size.
181          */
182         static ::rtl::OUString implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow >& xWindow);
183 
184         //____________________________
185         /** @short  restore the position and size on the container window.
186 
187             @param  xSMGR
188                     needed to create the configuration access.
189 
190             @param  sModuleName
191                     identifies the application module, where the
192                     information should be set on.
193 
194             @param  sWindowState
195                     contains the information about position and size.
196          */
197         static void implst_setWindowStateOnConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR         ,
198                                                   const ::rtl::OUString&                                        sModuleName   ,
199                                                   const ::rtl::OUString&                                        sWindowState  );
200 
201         //____________________________
202         /** @short  restore the position and size on the container window.
203 
204             @param  xWindow
205                     must point to the container window of the frame.
206                     We use it VCL part here - because the toolkit doesn't
207                     provide the right functionality!
208 
209             @param  sWindowState
210                     contains the information about position and size.
211          */
212         static void implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow >& xWindow     ,
213                                                   const ::rtl::OUString&                          sWindowState);
214 
215 }; // class PersistentWindowState
216 
217 } // namespace framework
218 
219 #endif // #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
220