Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / framework / inc / helper / persistentwindowstate.hxx
blob8d062488fe83bb6f7a598951430c9afe3272d694
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <sal/config.h>
24 #include <string_view>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/frame/XFrame.hpp>
28 #include <com/sun/star/frame/XFrameActionListener.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/weakref.hxx>
34 namespace framework{
36 /*-************************************************************************************************************
37 @short listener for closing document frames to make her window state persistent
38 @descr It's a feature of our office. If a document window was created by ourself (and not from
39 any external process e.g. the office bean) we save and restore the window state of it
40 corresponding to the document service factory. That means: one instance of this class will be
41 a listener on one frame which container window was created by ourself.
42 We listen for frame action events and every time a component will detached from a frame
43 we store its current position and size to the configuration. Every time a new component is
44 attached to a frame first time(!) we restore this information again.
46 @base OWeakObject
47 implements ref counting for this class.
49 @devstatus ready
50 @threadsafe yes
51 *//*-*************************************************************************************************************/
52 class PersistentWindowState final : public ::cppu::WeakImplHelper<
53 css::lang::XInitialization,
54 css::frame::XFrameActionListener > // => XEventListener
57 // member
59 private:
61 /// may we need a uno service manager to create own services
62 css::uno::Reference< css::uno::XComponentContext > m_xContext;
64 /// reference to the frame which was created by the office himself
65 css::uno::WeakReference< css::frame::XFrame > m_xFrame;
67 /// we call SetWindowState one times only for the same frame!
68 bool m_bWindowStateAlreadySet;
70 // interface
72 public:
74 // ctor/dtor
75 PersistentWindowState(css::uno::Reference< css::uno::XComponentContext > xContext);
76 virtual ~PersistentWindowState( ) override;
78 // XInitialization
79 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) override;
81 // XFrameActionListener
82 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) override;
84 // XEventListener
85 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
87 // helper
89 private:
91 /** @short identify the application module, which is used behind the component
92 of our frame.
94 @param rxContext
95 needed to create needed uno resources.
97 @param xFrame
98 contains the component, which must be identified.
100 @return [string]
101 a module identifier for the current frame component.
103 static OUString implst_identifyModule(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
104 const css::uno::Reference< css::frame::XFrame >& xFrame);
106 /** @short retrieve the window state from the configuration.
108 @param rxContext
109 needed to create the configuration access.
111 @param sModuleName
112 identifies the application module, where the
113 information should be obtained for.
115 @return [string]
116 contains the information about position and size.
118 static OUString implst_getWindowStateFromConfig(const css::uno::Reference< css::uno::XComponentContext >& rxContext ,
119 std::u16string_view sModuleName);
121 /** @short retrieve the window state from the container window.
123 @param xWindow
124 must point to the container window of the frame.
125 We use it VCL part here - because the toolkit doesn't
126 provide the right functionality!
128 @return [string]
129 contains the information about position and size.
131 static OUString implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow >& xWindow);
133 /** @short restore the position and size on the container window.
135 @param rxContext
136 needed to create the configuration access.
138 @param sModuleName
139 identifies the application module, where the
140 information should be set on.
142 @param sWindowState
143 contains the information about position and size.
145 static void implst_setWindowStateOnConfig(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
146 std::u16string_view sModuleName ,
147 const OUString& sWindowState );
149 /** @short restore the position and size on the container window.
151 @param xWindow
152 must point to the container window of the frame.
153 We use it VCL part here - because the toolkit doesn't
154 provide the right functionality!
156 @param sWindowState
157 contains the information about position and size.
159 static void implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow >& xWindow ,
160 std::u16string_view sWindowState);
162 }; // class PersistentWindowState
164 } // namespace framework
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */