1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
29 #define __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 //_________________________________________________________________________________________________________________
34 
35 #include <threadhelp/threadhelpbase.hxx>
36 #include <macros/debug.hxx>
37 #include <macros/xinterface.hxx>
38 #include <macros/xtypeprovider.hxx>
39 #include <general.h>
40 
41 //_________________________________________________________________________________________________________________
42 //	interface includes
43 //_________________________________________________________________________________________________________________
44 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 #include <com/sun/star/lang/XInitialization.hpp>
46 #include <com/sun/star/frame/XFrame.hpp>
47 #include <com/sun/star/frame/XFrameActionListener.hpp>
48 #include <com/sun/star/lang/XEventListener.hpp>
49 
50 //_________________________________________________________________________________________________________________
51 //	other includes
52 //_________________________________________________________________________________________________________________
53 #include <unotools/moduleoptions.hxx>
54 #include <cppuhelper/weak.hxx>
55 
56 //_________________________________________________________________________________________________________________
57 //	const
58 //_________________________________________________________________________________________________________________
59 
60 //_________________________________________________________________________________________________________________
61 //	namespace
62 //_________________________________________________________________________________________________________________
63 
64 namespace framework{
65 
66 //_________________________________________________________________________________________________________________
67 //	declarations
68 //_________________________________________________________________________________________________________________
69 
70 /*-************************************************************************************************************//**
71     @short          listener for closing document frames to make her window state persistent
72     @descr          It's a feature of our office. If a document window was created by ourself (and not from
73                     any external process e.g. the office bean) we save and restore the window state of it
74                     corresponding to the document service factory. That means: one instance of this class will be
75                     a listener on one frame which container window was created by ourself.
76                     We listen for frame action events and everytimes a component will deattached from a frame
77                     we store its current position and size to the configuration. Everytimes a new component is
78                     attached to a frame first time(!) we restore this informations again.
79 
80     @base           ThreadHelpBase
81                         guarantee right initialized lock member during startup of instances of this class.
82 
83     @base           OWeakObject
84                         implements ref counting for this class.
85 
86     @devstatus      ready
87     @threadsafe     yes
88     @modified       06.08.2004 08:41, as96863
89 *//*-*************************************************************************************************************/
90 class PersistentWindowState :   // interfaces
91                                 public css::lang::XTypeProvider,
92                                 public css::lang::XInitialization,
93                                 public css::frame::XFrameActionListener, // => XEventListener
94                                 // baseclasses (order neccessary for right initialization!)
95                                 private ThreadHelpBase,
96                                 public  ::cppu::OWeakObject
97 {
98     //________________________________
99     // member
100 
101 	private:
102 
103         /// may we need an uno service manager to create own services
104         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
105 
106         /// reference to the frame which was created by the office himself
107         css::uno::WeakReference< css::frame::XFrame > m_xFrame;
108 
109         /// we call SetWindowState one times only for the same frame!
110         sal_Bool m_bWindowStateAlreadySet;
111 
112     //________________________________
113     // interface
114 
115 	public:
116 
117         //____________________________
118         // ctor/dtor
119                  PersistentWindowState(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
120         virtual ~PersistentWindowState(                                                                   );
121 
122         //____________________________
123         // XInterface, XTypeProvider
124         FWK_DECLARE_XINTERFACE
125         FWK_DECLARE_XTYPEPROVIDER
126 
127         //____________________________
128         // XInitialization
129         virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments)
130             throw(css::uno::Exception       ,
131                   css::uno::RuntimeException);
132 
133         //____________________________
134         // XFrameActionListener
135         virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent)
136             throw(css::uno::RuntimeException);
137 
138         //____________________________
139         // XEventListener
140         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
141             throw(css::uno::RuntimeException);
142 
143     //________________________________
144     // helper
145 
146     private:
147         //____________________________
148         /** @short  identify the application module, which  is used behind the component
149                     of our frame.
150 
151             @param  xSMGR
152                     needed to create needed uno resources.
153 
154             @param  xFrame
155                     contains the component, wich must be identified.
156 
157             @return [string]
158                     a module identifier for the current frame component.
159          */
160         static ::rtl::OUString implst_identifyModule(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
161                                                      const css::uno::Reference< css::frame::XFrame >&              xFrame);
162 
163         //____________________________
164         /** @short  retrieve the window state from the configuration.
165 
166             @param  xSMGR
167                     needed to create the configuration access.
168 
169             @param  sModuleName
170                     identifies the application module, where the
171                     information should be getted for.
172 
173             @return [string]
174                     contains the information about position and size.
175          */
176         static ::rtl::OUString implst_getWindowStateFromConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR      ,
177                                                                const ::rtl::OUString&                                        sModuleName);
178 
179         //____________________________
180         /** @short  retrieve the window state from the container window.
181 
182             @param  xWindow
183                     must point to the container window of the frame.
184                     We use it VCL part here - because the toolkit doesnt
185                     provide the right functionality!
186 
187             @return [string]
188                     contains the information about position and size.
189          */
190         static ::rtl::OUString implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow >& xWindow);
191 
192         //____________________________
193         /** @short  restore the position and size on the container window.
194 
195             @param  xSMGR
196                     needed to create the configuration access.
197 
198             @param  sModuleName
199                     identifies the application module, where the
200                     information should be setted on.
201 
202             @param  sWindowState
203                     contains the information about position and size.
204          */
205         static void implst_setWindowStateOnConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR         ,
206                                                   const ::rtl::OUString&                                        sModuleName   ,
207                                                   const ::rtl::OUString&                                        sWindowState  );
208 
209         //____________________________
210         /** @short  restore the position and size on the container window.
211 
212             @param  xWindow
213                     must point to the container window of the frame.
214                     We use it VCL part here - because the toolkit doesnt
215                     provide the right functionality!
216 
217             @param  sWindowState
218                     contains the information about position and size.
219          */
220         static void implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow >& xWindow     ,
221                                                   const ::rtl::OUString&                          sWindowState);
222 
223 }; // class PersistentWindowState
224 
225 } // namespace framework
226 
227 #endif // #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
228