1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: persistentwindowstate.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
32 #define __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
38 #include <threadhelp/threadhelpbase.hxx>
39 #include <macros/debug.hxx>
40 #include <macros/xinterface.hxx>
41 #include <macros/xtypeprovider.hxx>
44 //_________________________________________________________________________________________________________________
46 //_________________________________________________________________________________________________________________
47 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #include <com/sun/star/lang/XInitialization.hpp>
49 #include <com/sun/star/frame/XFrame.hpp>
50 #include <com/sun/star/frame/XFrameActionListener.hpp>
51 #include <com/sun/star/lang/XEventListener.hpp>
53 //_________________________________________________________________________________________________________________
55 //_________________________________________________________________________________________________________________
56 #include <svtools/moduleoptions.hxx>
57 #include <cppuhelper/weak.hxx>
59 //_________________________________________________________________________________________________________________
61 //_________________________________________________________________________________________________________________
63 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
69 //_________________________________________________________________________________________________________________
71 //_________________________________________________________________________________________________________________
73 /*-************************************************************************************************************//**
74 @short listener for closing document frames to make her window state persistent
75 @descr It's a feature of our office. If a document window was created by ourself (and not from
76 any external process e.g. the office bean) we save and restore the window state of it
77 corresponding to the document service factory. That means: one instance of this class will be
78 a listener on one frame which container window was created by ourself.
79 We listen for frame action events and everytimes a component will deattached from a frame
80 we store its current position and size to the configuration. Everytimes a new component is
81 attached to a frame first time(!) we restore this informations again.
84 guarantee right initialized lock member during startup of instances of this class.
87 implements ref counting for this class.
91 @modified 06.08.2004 08:41, as96863
92 *//*-*************************************************************************************************************/
93 class PersistentWindowState
: // interfaces
94 public css::lang::XTypeProvider
,
95 public css::lang::XInitialization
,
96 public css::frame::XFrameActionListener
, // => XEventListener
97 // baseclasses (order neccessary for right initialization!)
98 private ThreadHelpBase
,
99 public ::cppu::OWeakObject
101 //________________________________
106 /// may we need an uno service manager to create own services
107 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
109 /// reference to the frame which was created by the office himself
110 css::uno::WeakReference
< css::frame::XFrame
> m_xFrame
;
112 /// we call SetWindowState one times only for the same frame!
113 sal_Bool m_bWindowStateAlreadySet
;
115 //________________________________
120 //____________________________
122 PersistentWindowState(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
);
123 virtual ~PersistentWindowState( );
125 //____________________________
126 // XInterface, XTypeProvider
127 FWK_DECLARE_XINTERFACE
128 FWK_DECLARE_XTYPEPROVIDER
130 //____________________________
132 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
>& lArguments
)
133 throw(css::uno::Exception
,
134 css::uno::RuntimeException
);
136 //____________________________
137 // XFrameActionListener
138 virtual void SAL_CALL
frameAction(const css::frame::FrameActionEvent
& aEvent
)
139 throw(css::uno::RuntimeException
);
141 //____________________________
143 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
)
144 throw(css::uno::RuntimeException
);
146 //________________________________
150 //____________________________
151 /** @short identify the application module, which is used behind the component
155 needed to create needed uno resources.
158 contains the component, wich must be identified.
161 a module identifier for the current frame component.
163 static ::rtl::OUString
implst_identifyModule(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
164 const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
166 //____________________________
167 /** @short retrieve the window state from the configuration.
170 needed to create the configuration access.
173 identifies the application module, where the
174 information should be getted for.
177 contains the information about position and size.
179 static ::rtl::OUString
implst_getWindowStateFromConfig(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
180 const ::rtl::OUString
& sModuleName
);
182 //____________________________
183 /** @short retrieve the window state from the container window.
186 must point to the container window of the frame.
187 We use it VCL part here - because the toolkit doesnt
188 provide the right functionality!
191 contains the information about position and size.
193 static ::rtl::OUString
implst_getWindowStateFromWindow(const css::uno::Reference
< css::awt::XWindow
>& xWindow
);
195 //____________________________
196 /** @short restore the position and size on the container window.
199 needed to create the configuration access.
202 identifies the application module, where the
203 information should be setted on.
206 contains the information about position and size.
208 static void implst_setWindowStateOnConfig(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
,
209 const ::rtl::OUString
& sModuleName
,
210 const ::rtl::OUString
& sWindowState
);
212 //____________________________
213 /** @short restore the position and size on the container window.
216 must point to the container window of the frame.
217 We use it VCL part here - because the toolkit doesnt
218 provide the right functionality!
221 contains the information about position and size.
223 static void implst_setWindowStateOnWindow(const css::uno::Reference
< css::awt::XWindow
>& xWindow
,
224 const ::rtl::OUString
& sWindowState
);
226 }; // class PersistentWindowState
228 } // namespace framework
230 #endif // #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_