GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / uno / generictoolboxcontroller.cxx
blob1f43c1b918fb5d972db001c01ce558bcecc6984d
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 <svtools/generictoolboxcontroller.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>
30 #include <comphelper/processfactory.hxx>
31 #include <osl/mutex.hxx>
32 #include <vcl/svapp.hxx>
34 using namespace ::com::sun::star::awt;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::lang;
38 using namespace ::com::sun::star::frame;
39 using namespace ::com::sun::star::frame::status;
40 using namespace ::com::sun::star::util;
42 namespace svt
45 struct ExecuteInfo
47 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
48 ::com::sun::star::util::URL aTargetURL;
49 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
52 GenericToolboxController::GenericToolboxController( const Reference< XComponentContext >& rxContext,
53 const Reference< XFrame >& rFrame,
54 ToolBox* pToolbox,
55 sal_uInt16 nID,
56 const OUString& aCommand ) :
57 svt::ToolboxController( rxContext, rFrame, aCommand )
58 , m_pToolbox( pToolbox )
59 , m_nID( nID )
61 // Initialization is done through ctor
62 m_bInitialized = sal_True;
64 // insert main command to our listener map
65 if ( !m_aCommandURL.isEmpty() )
66 m_aListenerMap.insert( URLToDispatchMap::value_type( aCommand, Reference< XDispatch >() ));
69 GenericToolboxController::~GenericToolboxController()
73 void SAL_CALL GenericToolboxController::dispose()
74 throw ( RuntimeException )
76 SolarMutexGuard aSolarMutexGuard;
78 svt::ToolboxController::dispose();
80 m_pToolbox = 0;
81 m_nID = 0;
84 void SAL_CALL GenericToolboxController::execute( sal_Int16 /*KeyModifier*/ )
85 throw ( RuntimeException )
87 Reference< XDispatch > xDispatch;
88 Reference< XURLTransformer > xURLTransformer;
89 OUString aCommandURL;
92 SolarMutexGuard aSolarMutexGuard;
94 if ( m_bDisposed )
95 throw DisposedException();
97 if ( m_bInitialized &&
98 m_xFrame.is() &&
99 m_xContext.is() &&
100 !m_aCommandURL.isEmpty() )
102 xURLTransformer = URLTransformer::create( m_xContext );
104 aCommandURL = m_aCommandURL;
105 URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
106 if ( pIter != m_aListenerMap.end() )
107 xDispatch = pIter->second;
111 if ( xDispatch.is() && xURLTransformer.is() )
113 com::sun::star::util::URL aTargetURL;
114 Sequence<PropertyValue> aArgs;
116 aTargetURL.Complete = aCommandURL;
117 xURLTransformer->parseStrict( aTargetURL );
119 // Execute dispatch asynchronously
120 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
121 pExecuteInfo->xDispatch = xDispatch;
122 pExecuteInfo->aTargetURL = aTargetURL;
123 pExecuteInfo->aArgs = aArgs;
124 Application::PostUserEvent( STATIC_LINK(0, GenericToolboxController , ExecuteHdl_Impl), pExecuteInfo );
128 void GenericToolboxController::statusChanged( const FeatureStateEvent& Event )
129 throw ( RuntimeException )
131 SolarMutexGuard aSolarMutexGuard;
133 if ( m_bDisposed )
134 return;
136 if ( m_pToolbox )
138 m_pToolbox->EnableItem( m_nID, Event.IsEnabled );
140 sal_uInt16 nItemBits = m_pToolbox->GetItemBits( m_nID );
141 nItemBits &= ~TIB_CHECKABLE;
142 TriState eTri = STATE_NOCHECK;
144 sal_Bool bValue = sal_Bool();
145 OUString aStrValue;
146 ItemStatus aItemState;
148 if ( Event.State >>= bValue )
150 // Boolean, treat it as checked/unchecked
151 m_pToolbox->SetItemBits( m_nID, nItemBits );
152 m_pToolbox->CheckItem( m_nID, bValue );
153 if ( bValue )
154 eTri = STATE_CHECK;
155 nItemBits |= TIB_CHECKABLE;
157 else if ( Event.State >>= aStrValue )
159 m_pToolbox->SetItemText( m_nID, aStrValue );
161 else if ( Event.State >>= aItemState )
163 eTri = STATE_DONTKNOW;
164 nItemBits |= TIB_CHECKABLE;
167 m_pToolbox->SetItemState( m_nID, eTri );
168 m_pToolbox->SetItemBits( m_nID, nItemBits );
172 IMPL_STATIC_LINK_NOINSTANCE( GenericToolboxController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
176 // Asynchronous execution as this can lead to our own destruction!
177 // Framework can recycle our current frame and the layout manager disposes all user interface
178 // elements if a component gets detached from its frame!
179 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
181 catch ( Exception& )
184 delete pExecuteInfo;
185 return 0;
188 } // namespace
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */