1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_ 29*cdf0e10cSrcweir #define __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_ 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx> 36*cdf0e10cSrcweir #include <macros/debug.hxx> 37*cdf0e10cSrcweir #include <macros/xinterface.hxx> 38*cdf0e10cSrcweir #include <macros/xtypeprovider.hxx> 39*cdf0e10cSrcweir #include <general.h> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42*cdf0e10cSrcweir // interface includes 43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/frame/XFrameActionListener.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51*cdf0e10cSrcweir // other includes 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 54*cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 57*cdf0e10cSrcweir // const 58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61*cdf0e10cSrcweir // namespace 62*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir namespace framework{ 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67*cdf0e10cSrcweir // declarations 68*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir /*-************************************************************************************************************//** 71*cdf0e10cSrcweir @short listener for closing document frames to make her window state persistent 72*cdf0e10cSrcweir @descr It's a feature of our office. If a document window was created by ourself (and not from 73*cdf0e10cSrcweir any external process e.g. the office bean) we save and restore the window state of it 74*cdf0e10cSrcweir corresponding to the document service factory. That means: one instance of this class will be 75*cdf0e10cSrcweir a listener on one frame which container window was created by ourself. 76*cdf0e10cSrcweir We listen for frame action events and everytimes a component will deattached from a frame 77*cdf0e10cSrcweir we store its current position and size to the configuration. Everytimes a new component is 78*cdf0e10cSrcweir attached to a frame first time(!) we restore this informations again. 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir @base ThreadHelpBase 81*cdf0e10cSrcweir guarantee right initialized lock member during startup of instances of this class. 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir @base OWeakObject 84*cdf0e10cSrcweir implements ref counting for this class. 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir @devstatus ready 87*cdf0e10cSrcweir @threadsafe yes 88*cdf0e10cSrcweir @modified 06.08.2004 08:41, as96863 89*cdf0e10cSrcweir *//*-*************************************************************************************************************/ 90*cdf0e10cSrcweir class PersistentWindowState : // interfaces 91*cdf0e10cSrcweir public css::lang::XTypeProvider, 92*cdf0e10cSrcweir public css::lang::XInitialization, 93*cdf0e10cSrcweir public css::frame::XFrameActionListener, // => XEventListener 94*cdf0e10cSrcweir // baseclasses (order neccessary for right initialization!) 95*cdf0e10cSrcweir private ThreadHelpBase, 96*cdf0e10cSrcweir public ::cppu::OWeakObject 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir //________________________________ 99*cdf0e10cSrcweir // member 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir private: 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir /// may we need an uno service manager to create own services 104*cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir /// reference to the frame which was created by the office himself 107*cdf0e10cSrcweir css::uno::WeakReference< css::frame::XFrame > m_xFrame; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /// we call SetWindowState one times only for the same frame! 110*cdf0e10cSrcweir sal_Bool m_bWindowStateAlreadySet; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir //________________________________ 113*cdf0e10cSrcweir // interface 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir public: 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir //____________________________ 118*cdf0e10cSrcweir // ctor/dtor 119*cdf0e10cSrcweir PersistentWindowState(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); 120*cdf0e10cSrcweir virtual ~PersistentWindowState( ); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir //____________________________ 123*cdf0e10cSrcweir // XInterface, XTypeProvider 124*cdf0e10cSrcweir FWK_DECLARE_XINTERFACE 125*cdf0e10cSrcweir FWK_DECLARE_XTYPEPROVIDER 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir //____________________________ 128*cdf0e10cSrcweir // XInitialization 129*cdf0e10cSrcweir virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) 130*cdf0e10cSrcweir throw(css::uno::Exception , 131*cdf0e10cSrcweir css::uno::RuntimeException); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir //____________________________ 134*cdf0e10cSrcweir // XFrameActionListener 135*cdf0e10cSrcweir virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) 136*cdf0e10cSrcweir throw(css::uno::RuntimeException); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir //____________________________ 139*cdf0e10cSrcweir // XEventListener 140*cdf0e10cSrcweir virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) 141*cdf0e10cSrcweir throw(css::uno::RuntimeException); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir //________________________________ 144*cdf0e10cSrcweir // helper 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir private: 147*cdf0e10cSrcweir //____________________________ 148*cdf0e10cSrcweir /** @short identify the application module, which is used behind the component 149*cdf0e10cSrcweir of our frame. 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir @param xSMGR 152*cdf0e10cSrcweir needed to create needed uno resources. 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir @param xFrame 155*cdf0e10cSrcweir contains the component, wich must be identified. 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir @return [string] 158*cdf0e10cSrcweir a module identifier for the current frame component. 159*cdf0e10cSrcweir */ 160*cdf0e10cSrcweir static ::rtl::OUString implst_identifyModule(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 161*cdf0e10cSrcweir const css::uno::Reference< css::frame::XFrame >& xFrame); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir //____________________________ 164*cdf0e10cSrcweir /** @short retrieve the window state from the configuration. 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir @param xSMGR 167*cdf0e10cSrcweir needed to create the configuration access. 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir @param sModuleName 170*cdf0e10cSrcweir identifies the application module, where the 171*cdf0e10cSrcweir information should be getted for. 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir @return [string] 174*cdf0e10cSrcweir contains the information about position and size. 175*cdf0e10cSrcweir */ 176*cdf0e10cSrcweir static ::rtl::OUString implst_getWindowStateFromConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 177*cdf0e10cSrcweir const ::rtl::OUString& sModuleName); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir //____________________________ 180*cdf0e10cSrcweir /** @short retrieve the window state from the container window. 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir @param xWindow 183*cdf0e10cSrcweir must point to the container window of the frame. 184*cdf0e10cSrcweir We use it VCL part here - because the toolkit doesnt 185*cdf0e10cSrcweir provide the right functionality! 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir @return [string] 188*cdf0e10cSrcweir contains the information about position and size. 189*cdf0e10cSrcweir */ 190*cdf0e10cSrcweir static ::rtl::OUString implst_getWindowStateFromWindow(const css::uno::Reference< css::awt::XWindow >& xWindow); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir //____________________________ 193*cdf0e10cSrcweir /** @short restore the position and size on the container window. 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir @param xSMGR 196*cdf0e10cSrcweir needed to create the configuration access. 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir @param sModuleName 199*cdf0e10cSrcweir identifies the application module, where the 200*cdf0e10cSrcweir information should be setted on. 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir @param sWindowState 203*cdf0e10cSrcweir contains the information about position and size. 204*cdf0e10cSrcweir */ 205*cdf0e10cSrcweir static void implst_setWindowStateOnConfig(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR , 206*cdf0e10cSrcweir const ::rtl::OUString& sModuleName , 207*cdf0e10cSrcweir const ::rtl::OUString& sWindowState ); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir //____________________________ 210*cdf0e10cSrcweir /** @short restore the position and size on the container window. 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir @param xWindow 213*cdf0e10cSrcweir must point to the container window of the frame. 214*cdf0e10cSrcweir We use it VCL part here - because the toolkit doesnt 215*cdf0e10cSrcweir provide the right functionality! 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir @param sWindowState 218*cdf0e10cSrcweir contains the information about position and size. 219*cdf0e10cSrcweir */ 220*cdf0e10cSrcweir static void implst_setWindowStateOnWindow(const css::uno::Reference< css::awt::XWindow >& xWindow , 221*cdf0e10cSrcweir const ::rtl::OUString& sWindowState); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir }; // class PersistentWindowState 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir } // namespace framework 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_HELPER_PERSISTENTWINDOWSTATE_HXX_ 228