1*f8e07b45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f8e07b45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f8e07b45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f8e07b45SAndrew Rist * distributed with this work for additional information 6*f8e07b45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f8e07b45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f8e07b45SAndrew Rist * "License"); you may not use this file except in compliance 9*f8e07b45SAndrew Rist * with the License. You may obtain a copy of the License at 10*f8e07b45SAndrew Rist * 11*f8e07b45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f8e07b45SAndrew Rist * 13*f8e07b45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f8e07b45SAndrew Rist * software distributed under the License is distributed on an 15*f8e07b45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f8e07b45SAndrew Rist * KIND, either express or implied. See the License for the 17*f8e07b45SAndrew Rist * specific language governing permissions and limitations 18*f8e07b45SAndrew Rist * under the License. 19*f8e07b45SAndrew Rist * 20*f8e07b45SAndrew Rist *************************************************************/ 21*f8e07b45SAndrew Rist 22*f8e07b45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_ 25cdf0e10cSrcweir #define __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir // Attention: stl headers must(!) be included at first. Otherwhise it can make trouble 28cdf0e10cSrcweir // with solaris headers ... 29cdf0e10cSrcweir #include <vector> 30cdf0e10cSrcweir 31cdf0e10cSrcweir //_______________________________________________ 32cdf0e10cSrcweir // include files of own module 33cdf0e10cSrcweir #include <helper/wakeupthread.hxx> 34cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx> 35cdf0e10cSrcweir #include <macros/xinterface.hxx> 36cdf0e10cSrcweir #include <macros/xtypeprovider.hxx> 37cdf0e10cSrcweir #include <macros/xserviceinfo.hxx> 38cdf0e10cSrcweir #include <macros/debug.hxx> 39cdf0e10cSrcweir #include <macros/generic.hxx> 40cdf0e10cSrcweir #include <general.h> 41cdf0e10cSrcweir 42cdf0e10cSrcweir //_______________________________________________ 43cdf0e10cSrcweir // include uno interfaces 44cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp> 45cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 46cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 47cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 48cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicatorFactory.hpp> 49cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp> 50cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 51cdf0e10cSrcweir #include <com/sun/star/awt/XWindowListener.hpp> 52cdf0e10cSrcweir #include <com/sun/star/lang/EventObject.hpp> 53cdf0e10cSrcweir #include <com/sun/star/awt/WindowEvent.hpp> 54cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 55cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 56cdf0e10cSrcweir 57cdf0e10cSrcweir #ifndef _COM_SUN_STAR_URTIL_XUPDATABLE_HPP_ 58cdf0e10cSrcweir #include <com/sun/star/util/XUpdatable.hpp> 59cdf0e10cSrcweir #endif 60cdf0e10cSrcweir 61cdf0e10cSrcweir //_______________________________________________ 62cdf0e10cSrcweir // include others 63cdf0e10cSrcweir #include <vcl/status.hxx> 64cdf0e10cSrcweir #include <cppuhelper/weak.hxx> 65cdf0e10cSrcweir #include <osl/thread.hxx> 66cdf0e10cSrcweir 67cdf0e10cSrcweir //_______________________________________________ 68cdf0e10cSrcweir // namespace 69cdf0e10cSrcweir 70cdf0e10cSrcweir namespace framework{ 71cdf0e10cSrcweir 72cdf0e10cSrcweir //_______________________________________________ 73cdf0e10cSrcweir // definitions 74cdf0e10cSrcweir 75cdf0e10cSrcweir //=============================================== 76cdf0e10cSrcweir /** 77cdf0e10cSrcweir @descr This struct hold some informations about all currently running progress proccesses. 78cdf0e10cSrcweir Because the can be used on a stack, we must cache her states but must paint only 79cdf0e10cSrcweir the top most one. 80cdf0e10cSrcweir */ 81cdf0e10cSrcweir struct IndicatorInfo 82cdf0e10cSrcweir { 83cdf0e10cSrcweir //------------------------------------------- 84cdf0e10cSrcweir // member 85cdf0e10cSrcweir public: 86cdf0e10cSrcweir 87cdf0e10cSrcweir /** @short points to the indicator child, where we hold its states 88cdf0e10cSrcweir alive here. */ 89cdf0e10cSrcweir css::uno::Reference< css::task::XStatusIndicator > m_xIndicator; 90cdf0e10cSrcweir 91cdf0e10cSrcweir /** @short the last set text for this indicator */ 92cdf0e10cSrcweir ::rtl::OUString m_sText; 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** @short the max range for this indicator. */ 95cdf0e10cSrcweir sal_Int32 m_nRange; 96cdf0e10cSrcweir 97cdf0e10cSrcweir /** @short the last set value for this indicator */ 98cdf0e10cSrcweir sal_Int32 m_nValue; 99cdf0e10cSrcweir 100cdf0e10cSrcweir //------------------------------------------- 101cdf0e10cSrcweir // interface 102cdf0e10cSrcweir public: 103cdf0e10cSrcweir 104cdf0e10cSrcweir //--------------------------------------- 105cdf0e10cSrcweir /** @short initialize new instance of this class 106cdf0e10cSrcweir 107cdf0e10cSrcweir @param xIndicator 108cdf0e10cSrcweir the new child indiactor of our factory. 109cdf0e10cSrcweir 110cdf0e10cSrcweir @param sText 111cdf0e10cSrcweir its initial text. 112cdf0e10cSrcweir 113cdf0e10cSrcweir @param nRange 114cdf0e10cSrcweir the max range for this indicator. 115cdf0e10cSrcweir */ 116cdf0e10cSrcweir IndicatorInfo(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator, 117cdf0e10cSrcweir const ::rtl::OUString& sText , 118cdf0e10cSrcweir sal_Int32 nRange ) 119cdf0e10cSrcweir { 120cdf0e10cSrcweir m_xIndicator = xIndicator; 121cdf0e10cSrcweir m_sText = sText ; 122cdf0e10cSrcweir m_nRange = nRange ; 123cdf0e10cSrcweir m_nValue = 0 ; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir //--------------------------------------- 127cdf0e10cSrcweir /** @short Don't forget to free used references! 128cdf0e10cSrcweir */ 129cdf0e10cSrcweir ~IndicatorInfo() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir m_xIndicator.clear(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 135cdf0e10cSrcweir /** @short Used to locate an info struct inside a stl structure ... 136cdf0e10cSrcweir 137cdf0e10cSrcweir @descr The indicator object itself is used as key. Its values 138cdf0e10cSrcweir are not interesting then. Because mor then one child 139cdf0e10cSrcweir indicator can use the same values ... 140cdf0e10cSrcweir */ 141cdf0e10cSrcweir sal_Bool operator==(const css::uno::Reference< css::task::XStatusIndicator >& xIndicator) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir return (m_xIndicator == xIndicator); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir }; 146cdf0e10cSrcweir /* 147cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------------- 148cdf0e10cSrcweir // norm nValue to fit range of 0..100% 149cdf0e10cSrcweir sal_Int32 calcPercentage() 150cdf0e10cSrcweir { 151cdf0e10cSrcweir return ::std::min( (( m_nValue * 100 )/ ::std::max( m_nRange, (sal_Int32)1 ) ), (sal_Int32)100 ); 152cdf0e10cSrcweir } 153cdf0e10cSrcweir */ 154cdf0e10cSrcweir 155cdf0e10cSrcweir //=============================================== 156cdf0e10cSrcweir /** @descr Define a lits of child indicator objects and her data. */ 157cdf0e10cSrcweir typedef ::std::vector< IndicatorInfo > IndicatorStack; 158cdf0e10cSrcweir 159cdf0e10cSrcweir //=============================================== 160cdf0e10cSrcweir /** @short implement a factory service to create new status indicator objects 161cdf0e10cSrcweir 162cdf0e10cSrcweir @descr Internaly it uses: 163cdf0e10cSrcweir - a vcl based 164cdf0e10cSrcweir - or an uno based and by the frame layouted 165cdf0e10cSrcweir progress implementation. 166cdf0e10cSrcweir 167cdf0e10cSrcweir This factory create different indicators and control his access 168cdf0e10cSrcweir to a shared output device! Only the last activated component 169cdf0e10cSrcweir can write his state to this device. All other requests will be 170cdf0e10cSrcweir cached only. 171cdf0e10cSrcweir 172cdf0e10cSrcweir @devstatus ready to use 173cdf0e10cSrcweir @threadsafe yes 174cdf0e10cSrcweir */ 175cdf0e10cSrcweir class StatusIndicatorFactory : public css::lang::XTypeProvider 176cdf0e10cSrcweir , public css::lang::XServiceInfo 177cdf0e10cSrcweir , public css::lang::XInitialization 178cdf0e10cSrcweir , public css::task::XStatusIndicatorFactory 179cdf0e10cSrcweir , public css::util::XUpdatable 180cdf0e10cSrcweir , private ThreadHelpBase 181cdf0e10cSrcweir , public ::cppu::OWeakObject // => XInterface 182cdf0e10cSrcweir { 183cdf0e10cSrcweir //------------------------------------------- 184cdf0e10cSrcweir // member 185cdf0e10cSrcweir private: 186cdf0e10cSrcweir 187cdf0e10cSrcweir /** stack with all current indicator childs. */ 188cdf0e10cSrcweir IndicatorStack m_aStack; 189cdf0e10cSrcweir 190cdf0e10cSrcweir /** uno service manager to create own needed uno resources. */ 191cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; 192cdf0e10cSrcweir 193cdf0e10cSrcweir /** most active indicator child, which could work with our shared indicator window only. */ 194cdf0e10cSrcweir css::uno::Reference< css::task::XStatusIndicator > m_xActiveChild; 195cdf0e10cSrcweir 196cdf0e10cSrcweir /** used to show the progress on the frame (layouted!) or 197cdf0e10cSrcweir as a plugged vcl window. */ 198cdf0e10cSrcweir css::uno::Reference< css::task::XStatusIndicator > m_xProgress; 199cdf0e10cSrcweir 200cdf0e10cSrcweir /** points to the frame, where we show the progress (in case 201cdf0e10cSrcweir m_xProgress points to a frame progress. */ 202cdf0e10cSrcweir css::uno::WeakReference< css::frame::XFrame > m_xFrame; 203cdf0e10cSrcweir 204cdf0e10cSrcweir /** points to an outside window, where we show the progress (in case 205cdf0e10cSrcweir we are plugged into such window). */ 206cdf0e10cSrcweir css::uno::WeakReference< css::awt::XWindow > m_xPluggWindow; 207cdf0e10cSrcweir 208cdf0e10cSrcweir /** Notify us if a fix time is over. We use it to implement an 209cdf0e10cSrcweir intelligent "Reschedule" ... */ 210cdf0e10cSrcweir WakeUpThread* m_pWakeUp; 211cdf0e10cSrcweir 212cdf0e10cSrcweir /** Our WakeUpThread calls us in our interface method "XUpdatable::update(). 213cdf0e10cSrcweir There we set this member m_bAllowReschedule to sal_True. Next time if our impl_reschedule() 214cdf0e10cSrcweir method is called, we know, that an Application::Reschedule() should be made. 215cdf0e10cSrcweir Because the last made Reschedule can be was taken long time ago ... may be.*/ 216cdf0e10cSrcweir sal_Bool m_bAllowReschedule; 217cdf0e10cSrcweir 218cdf0e10cSrcweir /** enable/disable automatic showing of our parent window. */ 219cdf0e10cSrcweir sal_Bool m_bAllowParentShow; 220cdf0e10cSrcweir 221cdf0e10cSrcweir /** enable/disable rescheduling. Default=enabled*/ 222cdf0e10cSrcweir sal_Bool m_bDisableReschedule; 223cdf0e10cSrcweir 224cdf0e10cSrcweir /** prevent recursive calling of Application::Reschedule(). */ 225cdf0e10cSrcweir static sal_Int32 m_nInReschedule; 226cdf0e10cSrcweir 227cdf0e10cSrcweir /** time where there last start call was made. */ 228cdf0e10cSrcweir sal_Int32 m_nStartTime; 229cdf0e10cSrcweir 230cdf0e10cSrcweir //------------------------------------------- 231cdf0e10cSrcweir // interface 232cdf0e10cSrcweir 233cdf0e10cSrcweir public: 234cdf0e10cSrcweir 235cdf0e10cSrcweir //--------------------------------------- 236cdf0e10cSrcweir // ctor 237cdf0e10cSrcweir StatusIndicatorFactory(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); 238cdf0e10cSrcweir 239cdf0e10cSrcweir //--------------------------------------- 240cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo 241cdf0e10cSrcweir FWK_DECLARE_XINTERFACE 242cdf0e10cSrcweir FWK_DECLARE_XTYPEPROVIDER 243cdf0e10cSrcweir DECLARE_XSERVICEINFO 244cdf0e10cSrcweir 245cdf0e10cSrcweir //--------------------------------------- 246cdf0e10cSrcweir // XInitialization 247cdf0e10cSrcweir virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any >& lArguments) 248cdf0e10cSrcweir throw(css::uno::Exception , 249cdf0e10cSrcweir css::uno::RuntimeException); 250cdf0e10cSrcweir 251cdf0e10cSrcweir //--------------------------------------- 252cdf0e10cSrcweir // XStatusIndicatorFactory 253cdf0e10cSrcweir virtual css::uno::Reference< css::task::XStatusIndicator > SAL_CALL createStatusIndicator() 254cdf0e10cSrcweir throw(css::uno::RuntimeException); 255cdf0e10cSrcweir 256cdf0e10cSrcweir //--------------------------------------- 257cdf0e10cSrcweir // XUpdatable 258cdf0e10cSrcweir virtual void SAL_CALL update() 259cdf0e10cSrcweir throw(css::uno::RuntimeException); 260cdf0e10cSrcweir 261cdf0e10cSrcweir //--------------------------------------- 262cdf0e10cSrcweir // similar (XStatusIndicator) 263cdf0e10cSrcweir virtual void start(const css::uno::Reference< css::task::XStatusIndicator >& xChild, 264cdf0e10cSrcweir const ::rtl::OUString& sText , 265cdf0e10cSrcweir sal_Int32 nRange); 266cdf0e10cSrcweir 267cdf0e10cSrcweir virtual void SAL_CALL reset(const css::uno::Reference< css::task::XStatusIndicator >& xChild); 268cdf0e10cSrcweir 269cdf0e10cSrcweir virtual void SAL_CALL end(const css::uno::Reference< css::task::XStatusIndicator >& xChild); 270cdf0e10cSrcweir 271cdf0e10cSrcweir virtual void SAL_CALL setText(const css::uno::Reference< css::task::XStatusIndicator >& xChild, 272cdf0e10cSrcweir const ::rtl::OUString& sText ); 273cdf0e10cSrcweir 274cdf0e10cSrcweir virtual void SAL_CALL setValue(const css::uno::Reference< css::task::XStatusIndicator >& xChild, 275cdf0e10cSrcweir sal_Int32 nValue); 276cdf0e10cSrcweir 277cdf0e10cSrcweir //------------------------------------------- 278cdf0e10cSrcweir // specials 279cdf0e10cSrcweir 280cdf0e10cSrcweir protected: 281cdf0e10cSrcweir 282cdf0e10cSrcweir virtual ~StatusIndicatorFactory(); 283cdf0e10cSrcweir 284cdf0e10cSrcweir //------------------------------------------- 285cdf0e10cSrcweir // helper 286cdf0e10cSrcweir private: 287cdf0e10cSrcweir 288cdf0e10cSrcweir /** @short show the parent window of this progress ... 289cdf0e10cSrcweir if it's allowed to do so. 290cdf0e10cSrcweir 291cdf0e10cSrcweir 292cdf0e10cSrcweir @descr By default we show the parent window automaticly 293cdf0e10cSrcweir if this progress is used. 294cdf0e10cSrcweir If that isn't a valid operation, the user of this 295cdf0e10cSrcweir progress can suppress this feature by initializaing 296cdf0e10cSrcweir us with a special parameter. 297cdf0e10cSrcweir 298cdf0e10cSrcweir @seealso initialize() 299cdf0e10cSrcweir */ 300cdf0e10cSrcweir void implts_makeParentVisibleIfAllowed(); 301cdf0e10cSrcweir 302cdf0e10cSrcweir /** @short creates a new internal used progress. 303cdf0e10cSrcweir @descr This factory does not paint the progress itself. 304cdf0e10cSrcweir It uses helper for that. They can be vcl based or 305cdf0e10cSrcweir layouted by the frame and provided as an uno interface. 306cdf0e10cSrcweir */ 307cdf0e10cSrcweir void impl_createProgress(); 308cdf0e10cSrcweir 309cdf0e10cSrcweir /** @short shows the internal used progress. 310cdf0e10cSrcweir @descr This factory does not paint the progress itself. 311cdf0e10cSrcweir It uses helper for that. They can be vcl based or 312cdf0e10cSrcweir layouted by the frame and provided as an uno interface. 313cdf0e10cSrcweir */ 314cdf0e10cSrcweir void impl_showProgress(); 315cdf0e10cSrcweir 316cdf0e10cSrcweir /** @short hides the internal used progress. 317cdf0e10cSrcweir @descr This factory does not paint the progress itself. 318cdf0e10cSrcweir It uses helper for that. They can be vcl based or 319cdf0e10cSrcweir layouted by the frame and provided as an uno interface. 320cdf0e10cSrcweir */ 321cdf0e10cSrcweir void impl_hideProgress(); 322cdf0e10cSrcweir 323cdf0e10cSrcweir /** @short try to "share the current thread in an intelligent manner" :-) 324cdf0e10cSrcweir 325cdf0e10cSrcweir @param Overwrites our algorithm for Reschedule and force it to be shure 326cdf0e10cSrcweir that our progress was painted right. 327cdf0e10cSrcweir */ 328cdf0e10cSrcweir void impl_reschedule(sal_Bool bForceUpdate); 329cdf0e10cSrcweir 330cdf0e10cSrcweir void impl_startWakeUpThread(); 331cdf0e10cSrcweir void impl_stopWakeUpThread(); 332cdf0e10cSrcweir 333cdf0e10cSrcweir }; // class StatusIndicatorFactory 334cdf0e10cSrcweir 335cdf0e10cSrcweir } // namespace framework 336cdf0e10cSrcweir 337cdf0e10cSrcweir #endif // #ifndef __FRAMEWORK_HELPER_STATUSINDICATORFACTORY_HXX_ 338