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 INCLUDED_FRAMEWORK_INC_HELPER_PERSISTENTWINDOWSTATE_HXX
21 #define INCLUDED_FRAMEWORK_INC_HELPER_PERSISTENTWINDOWSTATE_HXX
23 #include <macros/xinterface.hxx>
24 #include <macros/xtypeprovider.hxx>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/lang/XInitialization.hpp>
29 #include <com/sun/star/frame/XFrame.hpp>
30 #include <com/sun/star/frame/XFrameActionListener.hpp>
31 #include <com/sun/star/lang/XEventListener.hpp>
32 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <unotools/moduleoptions.hxx>
35 #include <cppuhelper/implbase2.hxx>
39 /*-************************************************************************************************************
40 @short listener for closing document frames to make her window state persistent
41 @descr It's a feature of our office. If a document window was created by ourself (and not from
42 any external process e.g. the office bean) we save and restore the window state of it
43 corresponding to the document service factory. That means: one instance of this class will be
44 a listener on one frame which container window was created by ourself.
45 We listen for frame action events and every time a component will deattached from a frame
46 we store its current position and size to the configuration. Every time a new component is
47 attached to a frame first time(!) we restore this information again.
50 implements ref counting for this class.
54 *//*-*************************************************************************************************************/
55 class PersistentWindowState
: public ::cppu::WeakImplHelper2
<
56 css::lang::XInitialization
,
57 css::frame::XFrameActionListener
> // => XEventListener
64 /// may we need an uno service manager to create own services
65 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
67 /// reference to the frame which was created by the office himself
68 css::uno::WeakReference
< css::frame::XFrame
> m_xFrame
;
70 /// we call SetWindowState one times only for the same frame!
71 bool m_bWindowStateAlreadySet
;
78 PersistentWindowState(const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
79 virtual ~PersistentWindowState( );
82 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
>& lArguments
)
83 throw(css::uno::Exception
,
84 css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
86 // XFrameActionListener
87 virtual void SAL_CALL
frameAction(const css::frame::FrameActionEvent
& aEvent
)
88 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
91 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
)
92 throw(css::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
98 /** @short identify the application module, which is used behind the component
102 needed to create needed uno resources.
105 contains the component, which must be identified.
108 a module identifier for the current frame component.
110 static OUString
implst_identifyModule(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
111 const css::uno::Reference
< css::frame::XFrame
>& xFrame
);
113 /** @short retrieve the window state from the configuration.
116 needed to create the configuration access.
119 identifies the application module, where the
120 information should be getted for.
123 contains the information about position and size.
125 static OUString
implst_getWindowStateFromConfig(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
126 const OUString
& sModuleName
);
128 /** @short retrieve the window state from the container window.
131 must point to the container window of the frame.
132 We use it VCL part here - because the toolkit doesn't
133 provide the right functionality!
136 contains the information about position and size.
138 static OUString
implst_getWindowStateFromWindow(const css::uno::Reference
< css::awt::XWindow
>& xWindow
);
140 /** @short restore the position and size on the container window.
143 needed to create the configuration access.
146 identifies the application module, where the
147 information should be setted on.
150 contains the information about position and size.
152 static void implst_setWindowStateOnConfig(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
153 const OUString
& sModuleName
,
154 const OUString
& sWindowState
);
156 /** @short restore the position and size on the container window.
159 must point to the container window of the frame.
160 We use it VCL part here - because the toolkit doesn't
161 provide the right functionality!
164 contains the information about position and size.
166 static void implst_setWindowStateOnWindow(const css::uno::Reference
< css::awt::XWindow
>& xWindow
,
167 const OUString
& sWindowState
);
169 }; // class PersistentWindowState
171 } // namespace framework
173 #endif // INCLUDED_FRAMEWORK_INC_HELPER_PERSISTENTWINDOWSTATE_HXX
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */