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