fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / complextoolbarcontroller.cxx
blob9d013f4021a7cf8ead3e1463943388fa904c6506
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 #include "uielement/complextoolbarcontroller.hxx"
22 #include <com/sun/star/util/URLTransformer.hpp>
23 #include <com/sun/star/util/XURLTransformer.hpp>
24 #include <com/sun/star/frame/XDispatchProvider.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
27 #include <com/sun/star/frame/status/ItemStatus.hpp>
28 #include <com/sun/star/frame/status/ItemState.hpp>
29 #include <com/sun/star/frame/status/Visibility.hpp>
30 #include <com/sun/star/frame/XControlNotificationListener.hpp>
32 #include <comphelper/processfactory.hxx>
33 #include <svtools/toolboxcontroller.hxx>
34 #include <osl/mutex.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/mnemonic.hxx>
37 #include <vcl/toolbox.hxx>
38 #include <vcl/settings.hxx>
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::awt;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::frame;
46 using namespace ::com::sun::star::frame::status;
47 using namespace ::com::sun::star::util;
49 namespace framework
52 ComplexToolbarController::ComplexToolbarController(
53 const Reference< XComponentContext >& rxContext,
54 const Reference< XFrame >& rFrame,
55 ToolBox* pToolbar,
56 sal_uInt16 nID,
57 const OUString& aCommand ) :
58 svt::ToolboxController( rxContext, rFrame, aCommand )
59 , m_pToolbar( pToolbar )
60 , m_nID( nID )
61 , m_bMadeInvisible( false )
63 m_xURLTransformer.set( URLTransformer::create(m_xContext) );
66 ComplexToolbarController::~ComplexToolbarController()
70 void SAL_CALL ComplexToolbarController::dispose()
71 throw ( RuntimeException, std::exception )
73 SolarMutexGuard aSolarMutexGuard;
75 m_pToolbar->SetItemWindow( m_nID, 0 );
76 svt::ToolboxController::dispose();
78 m_xURLTransformer.clear();
79 m_pToolbar.clear();
80 m_nID = 0;
83 Sequence<PropertyValue> ComplexToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
85 Sequence<PropertyValue> aArgs( 1 );
87 // Add key modifier to argument list
88 aArgs[0].Name = "KeyModifier";
89 aArgs[0].Value <<= KeyModifier;
90 return aArgs;
93 void SAL_CALL ComplexToolbarController::execute( sal_Int16 KeyModifier )
94 throw ( RuntimeException, std::exception )
96 Reference< XDispatch > xDispatch;
97 Reference< XURLTransformer > xURLTransformer;
98 OUString aCommandURL;
99 ::com::sun::star::util::URL aTargetURL;
100 Sequence<PropertyValue> aArgs;
103 SolarMutexGuard aSolarMutexGuard;
105 if ( m_bDisposed )
106 throw DisposedException();
108 if ( m_bInitialized &&
109 m_xFrame.is() &&
110 !m_aCommandURL.isEmpty() )
112 xURLTransformer = m_xURLTransformer;
113 xDispatch = getDispatchFromCommand( m_aCommandURL );
114 aCommandURL = m_aCommandURL;
115 aTargetURL = getInitializedURL();
116 aArgs = getExecuteArgs(KeyModifier);
120 if ( xDispatch.is() && !aTargetURL.Complete.isEmpty() )
122 // Execute dispatch asynchronously
123 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
124 pExecuteInfo->xDispatch = xDispatch;
125 pExecuteInfo->aTargetURL = aTargetURL;
126 pExecuteInfo->aArgs = aArgs;
127 Application::PostUserEvent( LINK(0, ComplexToolbarController , ExecuteHdl_Impl), pExecuteInfo );
131 void ComplexToolbarController::statusChanged( const FeatureStateEvent& Event )
132 throw ( RuntimeException, std::exception )
134 SolarMutexGuard aSolarMutexGuard;
136 if ( m_bDisposed )
137 return;
139 if ( m_pToolbar )
141 m_pToolbar->EnableItem( m_nID, Event.IsEnabled );
143 ToolBoxItemBits nItemBits = m_pToolbar->GetItemBits( m_nID );
144 nItemBits &= ~ToolBoxItemBits::CHECKABLE;
145 TriState eTri = TRISTATE_FALSE;
147 bool bValue;
148 OUString aStrValue;
149 ItemStatus aItemState;
150 Visibility aItemVisibility;
151 ControlCommand aControlCommand;
153 if ( Event.State >>= bValue )
155 // Boolean, treat it as checked/unchecked
156 if ( m_bMadeInvisible )
157 m_pToolbar->ShowItem( m_nID, true );
158 m_pToolbar->CheckItem( m_nID, bValue );
159 if ( bValue )
160 eTri = TRISTATE_TRUE;
161 nItemBits |= ToolBoxItemBits::CHECKABLE;
163 else if ( Event.State >>= aStrValue )
165 OUString aText( MnemonicGenerator::EraseAllMnemonicChars( aStrValue ) );
166 m_pToolbar->SetItemText( m_nID, aText );
167 m_pToolbar->SetQuickHelpText( m_nID, aText );
169 if ( m_bMadeInvisible )
170 m_pToolbar->ShowItem( m_nID, true );
172 else if ( Event.State >>= aItemState )
174 eTri = TRISTATE_INDET;
175 nItemBits |= ToolBoxItemBits::CHECKABLE;
176 if ( m_bMadeInvisible )
177 m_pToolbar->ShowItem( m_nID, true );
179 else if ( Event.State >>= aItemVisibility )
181 m_pToolbar->ShowItem( m_nID, aItemVisibility.bVisible );
182 m_bMadeInvisible = !aItemVisibility.bVisible;
184 else if ( Event.State >>= aControlCommand )
186 executeControlCommand( aControlCommand );
187 if ( m_bMadeInvisible )
188 m_pToolbar->ShowItem( m_nID, true );
191 else if ( m_bMadeInvisible )
192 m_pToolbar->ShowItem( m_nID, true );
194 m_pToolbar->SetItemState( m_nID, eTri );
195 m_pToolbar->SetItemBits( m_nID, nItemBits );
199 IMPL_STATIC_LINK( ComplexToolbarController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
201 SolarMutexReleaser aReleaser;
204 // Asynchronous execution as this can lead to our own destruction!
205 // Framework can recycle our current frame and the layout manager disposes all user interface
206 // elements if a component gets detached from its frame!
207 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
209 catch ( const Exception& )
213 delete pExecuteInfo;
214 return 0;
217 IMPL_STATIC_LINK( ComplexToolbarController, Notify_Impl, NotifyInfo*, pNotifyInfo )
219 SolarMutexReleaser aReleaser;
222 // Asynchronous execution: As this can lead to our own destruction!
223 // Framework can recycle our current frame and the layout manager disposes all user interface
224 // elements if a component gets detached from its frame!
225 frame::ControlEvent aEvent;
226 aEvent.aURL = pNotifyInfo->aSourceURL;
227 aEvent.Event = pNotifyInfo->aEventName;
228 aEvent.aInformation = pNotifyInfo->aInfoSeq;
229 pNotifyInfo->xNotifyListener->controlEvent( aEvent );
231 catch ( const Exception& )
235 delete pNotifyInfo;
236 return 0;
239 void ComplexToolbarController::addNotifyInfo(
240 const OUString& aEventName,
241 const uno::Reference< frame::XDispatch >& xDispatch,
242 const uno::Sequence< beans::NamedValue >& rInfo )
244 uno::Reference< frame::XControlNotificationListener > xControlNotify( xDispatch, uno::UNO_QUERY );
246 if ( xControlNotify.is() )
248 // Execute notification asynchronously
249 NotifyInfo* pNotifyInfo = new NotifyInfo;
251 pNotifyInfo->aEventName = aEventName;
252 pNotifyInfo->xNotifyListener = xControlNotify;
253 pNotifyInfo->aSourceURL = getInitializedURL();
255 // Add frame as source to the information sequence
256 sal_Int32 nCount = rInfo.getLength();
257 uno::Sequence< beans::NamedValue > aInfoSeq( rInfo );
258 aInfoSeq.realloc( nCount+1 );
259 aInfoSeq[nCount].Name = "Source";
260 aInfoSeq[nCount].Value = uno::makeAny( getFrameInterface() );
261 pNotifyInfo->aInfoSeq = aInfoSeq;
263 Application::PostUserEvent( LINK(0, ComplexToolbarController, Notify_Impl), pNotifyInfo );
267 sal_Int32 ComplexToolbarController::getFontSizePixel( const vcl::Window* pWindow )
269 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
270 const vcl::Font& rFont = rSettings.GetAppFont();
272 // Calculate height of the application font used by window
273 sal_Int32 nHeight = sal_Int32( rFont.GetHeight() );
274 ::Size aPixelSize = pWindow->LogicToPixel( ::Size( 0, nHeight ), MAP_APPFONT );
275 return aPixelSize.Height();
278 uno::Reference< frame::XDispatch > ComplexToolbarController::getDispatchFromCommand( const OUString& aCommand ) const
280 uno::Reference< frame::XDispatch > xDispatch;
282 if ( m_bInitialized && m_xFrame.is() && !aCommand.isEmpty() )
284 URLToDispatchMap::const_iterator pIter = m_aListenerMap.find( aCommand );
285 if ( pIter != m_aListenerMap.end() )
286 xDispatch = pIter->second;
289 return xDispatch;
292 const ::com::sun::star::util::URL& ComplexToolbarController::getInitializedURL()
294 if ( m_aURL.Complete.isEmpty() )
296 m_aURL.Complete = m_aCommandURL;
297 m_xURLTransformer->parseStrict( m_aURL );
299 return m_aURL;
302 void ComplexToolbarController::notifyFocusGet()
304 // send focus get notification
305 uno::Sequence< beans::NamedValue > aInfo;
306 addNotifyInfo( OUString( "FocusSet" ),
307 getDispatchFromCommand( m_aCommandURL ),
308 aInfo );
311 void ComplexToolbarController::notifyFocusLost()
313 // send focus lost notification
314 uno::Sequence< beans::NamedValue > aInfo;
315 addNotifyInfo( OUString( "FocusLost" ),
316 getDispatchFromCommand( m_aCommandURL ),
317 aInfo );
320 void ComplexToolbarController::notifyTextChanged( const OUString& aText )
322 // send text changed notification
323 uno::Sequence< beans::NamedValue > aInfo( 1 );
324 aInfo[0].Name = "Text";
325 aInfo[0].Value <<= aText;
326 addNotifyInfo( OUString( "TextChanged" ),
327 getDispatchFromCommand( m_aCommandURL ),
328 aInfo );
331 } // namespace
333 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */