1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
21 #define __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
23 #include <threadhelp/threadhelpbase.hxx>
24 #include <macros/debug.hxx>
25 #include <macros/xinterface.hxx>
26 #include <macros/xtypeprovider.hxx>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <com/sun/star/lang/XInitialization.hpp>
31 #include <com/sun/star/frame/XFrame.hpp>
32 #include <com/sun/star/frame/XFrameActionListener.hpp>
33 #include <com/sun/star/lang/XEventListener.hpp>
35 #include <unotools/moduleoptions.hxx>
36 #include <cppuhelper/weak.hxx>
40 /*-************************************************************************************************************//**
41 @short listener for closing document frames to make her window state persistent
42 @descr It's a feature of our office. If a document window was created by ourself (and not from
43 any external process e.g. the office bean) we save and restore the window state of it
44 corresponding to the document service factory. That means: one instance of this class will be
45 a listener on one frame which container window was created by ourself.
46 We listen for frame action events and everytimes a component will deattached from a frame
47 we store its current position and size to the configuration. Everytimes a new component is
48 attached to a frame first time(!) we restore this information again.
51 guarantee right initialized lock member during startup of instances of this class.
54 implements ref counting for this class.
58 *//*-*************************************************************************************************************/
59 class PersistentWindowState
: // interfaces
60 public css::lang::XTypeProvider
,
61 public css::lang::XInitialization
,
62 public css::frame::XFrameActionListener
, // => XEventListener
63 // baseclasses (order necessary for right initialization!)
64 private ThreadHelpBase
,
65 public ::cppu::OWeakObject
67 //________________________________
72 /// may we need an uno service manager to create own services
73 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
75 /// reference to the frame which was created by the office himself
76 css::uno::WeakReference
< css::frame::XFrame
> m_xFrame
;
78 /// we call SetWindowState one times only for the same frame!
79 sal_Bool m_bWindowStateAlreadySet
;
81 //________________________________
86 //____________________________
88 PersistentWindowState(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
);
89 virtual ~PersistentWindowState( );
91 //____________________________
92 // XInterface, XTypeProvider
93 FWK_DECLARE_XINTERFACE
94 FWK_DECLARE_XTYPEPROVIDER
96 //____________________________
98 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
>& lArguments
)
99 throw(css::uno::Exception
,
100 css::uno::RuntimeException
);
102 //____________________________
103 // XFrameActionListener
104 virtual void SAL_CALL
frameAction(const css::frame::FrameActionEvent
& aEvent
)
105 throw(css::uno::RuntimeException
);
107 //____________________________
109 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
)
110 throw(css::uno::RuntimeException
);
112 //________________________________
116 //____________________________
117 /** @short identify the application module, which is used behind the component
121 needed to create needed uno resources.
124 contains the component, which must be identified.
127 a module identifier for the current frame component.
129 static OUString
implst_identifyModule(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
130 const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
132 //____________________________
133 /** @short retrieve the window state from the configuration.
136 needed to create the configuration access.
139 identifies the application module, where the
140 information should be getted for.
143 contains the information about position and size.
145 static OUString
implst_getWindowStateFromConfig(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
146 const OUString
& sModuleName
);
148 //____________________________
149 /** @short retrieve the window state from the container window.
152 must point to the container window of the frame.
153 We use it VCL part here - because the toolkit doesnt
154 provide the right functionality!
157 contains the information about position and size.
159 static OUString
implst_getWindowStateFromWindow(const css::uno::Reference
< css::awt::XWindow
>& xWindow
);
161 //____________________________
162 /** @short restore the position and size on the container window.
165 needed to create the configuration access.
168 identifies the application module, where the
169 information should be setted on.
172 contains the information about position and size.
174 static void implst_setWindowStateOnConfig(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
175 const OUString
& sModuleName
,
176 const OUString
& sWindowState
);
178 //____________________________
179 /** @short restore the position and size on the container window.
182 must point to the container window of the frame.
183 We use it VCL part here - because the toolkit doesnt
184 provide the right functionality!
187 contains the information about position and size.
189 static void implst_setWindowStateOnWindow(const css::uno::Reference
< css::awt::XWindow
>& xWindow
,
190 const OUString
& sWindowState
);
192 }; // class PersistentWindowState
194 } // namespace framework
196 #endif // #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */