1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef __FRAMEWORK_DISPATCH_HELPAGENTDISPATCHER_HXX_ 29 #define __FRAMEWORK_DISPATCH_HELPAGENTDISPATCHER_HXX_ 30 31 #include <threadhelp/threadhelpbase.hxx> 32 #include <macros/xinterface.hxx> 33 #include <macros/xtypeprovider.hxx> 34 #include <com/sun/star/frame/XDispatch.hpp> 35 #include <com/sun/star/frame/XFrame.hpp> 36 #include <com/sun/star/awt/XWindowListener.hpp> 37 #include <com/sun/star/awt/XWindow.hpp> 38 #include <svtools/helpagentwindow.hxx> 39 #include <vcl/timer.hxx> 40 #include <vcl/evntpost.hxx> 41 #include <cppuhelper/weak.hxx> 42 43 //........................................................................ 44 namespace framework 45 { 46 47 // define css alias ... and undefine it at the end of this file !!! 48 #ifdef css 49 #error "I tried to use css as namespace define inside non exported header ... but it was already defined by somwhere else. .-)" 50 #else 51 #define css ::com::sun::star 52 #endif 53 54 //........................................................................ 55 56 class HelpAgentDispatcher : public css::lang::XTypeProvider 57 , public css::frame::XDispatch 58 , public css::awt::XWindowListener // => css::lang::XEventListener 59 , public ::svt::IHelpAgentCallback 60 , private ThreadHelpBase 61 , public ::cppu::OWeakObject 62 { 63 private: 64 65 //--------------------------------------- 66 /// @short represent the current active help URL, which must be used to show the right help page 67 ::rtl::OUString m_sCurrentURL; 68 69 //--------------------------------------- 70 /// @short parent of the agent window. 71 css::uno::Reference< css::awt::XWindow > m_xContainerWindow; 72 73 //--------------------------------------- 74 /// @short the agent window itself (implemented in svtools) 75 css::uno::Reference< css::awt::XWindow > m_xAgentWindow; 76 77 //--------------------------------------- 78 /// @short the timer for showing the agent window 79 Timer m_aTimer; 80 81 //--------------------------------------- 82 /** @short hold this dispatcher alive till the timer was killed or expired! 83 @descr Because the vcl timer knows us by using a pointer ... and our instance is used 84 ref counted normaly it can happen that our reference goes down to 0 ... and the timer 85 runs into some trouble. So we hold us self alive till the timer could be stopped or expired. 86 */ 87 css::uno::Reference< css::uno::XInterface > m_xSelfHold; 88 89 public: 90 91 HelpAgentDispatcher(const css::uno::Reference< css::frame::XFrame >& xParentFrame); 92 93 FWK_DECLARE_XINTERFACE 94 FWK_DECLARE_XTYPEPROVIDER 95 96 // css::frame::XDispatch 97 virtual void SAL_CALL dispatch(const css::util::URL& sURL , 98 const css::uno::Sequence< css::beans::PropertyValue >& lArgs) 99 throw(css::uno::RuntimeException); 100 virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& xListener, 101 const css::util::URL& aURL ) 102 throw(css::uno::RuntimeException); 103 virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& xListener, 104 const css::util::URL& aURL ) 105 throw(css::uno::RuntimeException); 106 107 // css::awt::XWindowListener 108 virtual void SAL_CALL windowResized(const css::awt::WindowEvent& aSource) 109 throw(css::uno::RuntimeException); 110 virtual void SAL_CALL windowMoved(const css::awt::WindowEvent& aSource) 111 throw(css::uno::RuntimeException); 112 virtual void SAL_CALL windowShown(const css::lang::EventObject& aSource) 113 throw(css::uno::RuntimeException); 114 virtual void SAL_CALL windowHidden(const css::lang::EventObject& aSource) 115 throw(css::uno::RuntimeException); 116 117 // css::lang::XEventListener 118 virtual void SAL_CALL disposing(const css::lang::EventObject& aSource) 119 throw(css::uno::RuntimeException); 120 121 protected: 122 123 ~HelpAgentDispatcher(); 124 125 protected: 126 127 /// IHelpAgentCallback overridables 128 virtual void helpRequested(); 129 virtual void closeAgent(); 130 131 private: 132 133 //--------------------------------------- 134 /** @short mark the current set URL as "accepted by user" and show the right help window 135 */ 136 void implts_acceptCurrentURL(); 137 138 //--------------------------------------- 139 /** @short mark the current set URL as "ignored by user" 140 */ 141 void implts_ignoreCurrentURL(); 142 143 //--------------------------------------- 144 /** @short ensures that the agent's window exists 145 @descr We create the agent window on demand. But afterwards we hold it alive till 146 this helpagent dispatcher dies. The agent window will be made visible/hidden 147 in case a new dispatch occures or in case the timer expired. 148 149 @return [sal_Bool] 150 sal_True in case the member m_xAgentWindow is a valid reference; 151 sal_False otherwise. 152 */ 153 css::uno::Reference< css::awt::XWindow > implts_ensureAgentWindow(); 154 155 //--------------------------------------- 156 /** @short show the agent window. 157 @descr If the agent window does not exists, it will be created on demand. 158 (see implts_ensureAgentWindow). Further it's checked if the parent container 159 window is currently visible or not. Only if its visible the agent window will 160 be shown too. 161 */ 162 void implts_showAgentWindow(); 163 164 //--------------------------------------- 165 /** @short hide the agent window. 166 */ 167 void implts_hideAgentWindow(); 168 169 //--------------------------------------- 170 /** @short set the new position and size of the agent window. 171 @descr If the agent window does not exists, it will be created on demand. 172 (see implts_ensureAgentWindow). 173 If the agent window exists, its position and size will be calculated 174 and set. 175 */ 176 void implts_positionAgentWindow(); 177 178 //--------------------------------------- 179 /** @short starts the timer for showing the agent window. 180 @descr The timer wont be started twice ... this method checks the current running state .-) 181 */ 182 void implts_startTimer(); 183 184 //--------------------------------------- 185 /** @short stop the timer. 186 @descr The timer wont be stopped twice ... this method checks the current running state .-) 187 Further this method marks the current help URL (m_xCurrentURL) as "ignorable". 188 Cause the user ignored it ! 189 */ 190 void implts_stopTimer(); 191 192 //--------------------------------------- 193 /** @short callback of our internal timer. 194 */ 195 DECL_LINK(implts_timerExpired, void*); 196 }; 197 198 #undef css 199 200 //........................................................................ 201 } // namespace framework 202 //........................................................................ 203 204 #endif // _FRAMEWORK_DISPATCH_HELPAGENTDISPATCHER_HXX_ 205 206