LibreOffice Module framework (master) 1
persistentwindowstate.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23
24#include <string_view>
25
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>
30
33
34namespace framework{
35
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.
45
46 @base OWeakObject
47 implements ref counting for this class.
48
49 @devstatus ready
50 @threadsafe yes
51*//*-*************************************************************************************************************/
52class PersistentWindowState final : public ::cppu::WeakImplHelper<
53 css::lang::XInitialization,
54 css::frame::XFrameActionListener > // => XEventListener
55{
56
57 // member
58
59 private:
60
62 css::uno::Reference< css::uno::XComponentContext > m_xContext;
63
65 css::uno::WeakReference< css::frame::XFrame > m_xFrame;
66
69
70 // interface
71
72 public:
73
74 // ctor/dtor
75 PersistentWindowState(css::uno::Reference< css::uno::XComponentContext > xContext);
76 virtual ~PersistentWindowState( ) override;
77
78 // XInitialization
79 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) override;
80
81 // XFrameActionListener
82 virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) override;
83
84 // XEventListener
85 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
86
87 // helper
88
89 private:
90
103 static OUString implst_identifyModule(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
104 const css::uno::Reference< css::frame::XFrame >& xFrame);
105
118 static OUString implst_getWindowStateFromConfig(const css::uno::Reference< css::uno::XComponentContext >& rxContext ,
119 std::u16string_view sModuleName);
120
131 static OUString implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow >& xWindow);
132
145 static void implst_setWindowStateOnConfig(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
146 std::u16string_view sModuleName ,
147 const OUString& sWindowState );
148
159 static void implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow >& xWindow ,
160 std::u16string_view sWindowState);
161
162}; // class PersistentWindowState
163
164} // namespace framework
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
PersistentWindowState(css::uno::Reference< css::uno::XComponentContext > xContext)
css::uno::Reference< css::uno::XComponentContext > m_xContext
may we need a uno service manager to create own services
static OUString implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow > &xWindow)
retrieve the window state from the container window.
static OUString implst_getWindowStateFromConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, std::u16string_view sModuleName)
retrieve the window state from the configuration.
bool m_bWindowStateAlreadySet
we call SetWindowState one times only for the same frame!
css::uno::WeakReference< css::frame::XFrame > m_xFrame
reference to the frame which was created by the office himself
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &lArguments) override
static OUString implst_identifyModule(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &xFrame)
identify the application module, which is used behind the component of our frame.
static void implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow > &xWindow, std::u16string_view sWindowState)
restore the position and size on the container window.
virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent &aEvent) override
static void implst_setWindowStateOnConfig(const css::uno::Reference< css::uno::XComponentContext > &rxContext, std::u16string_view sModuleName, const OUString &sWindowState)
restore the position and size on the container window.