Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svtools/generictoolboxcontroller.hxx>
30 : :
31 : : #include <com/sun/star/util/URLTransformer.hpp>
32 : : #include <com/sun/star/util/XURLTransformer.hpp>
33 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
34 : : #include <com/sun/star/beans/PropertyValue.hpp>
35 : : #include <com/sun/star/lang/DisposedException.hpp>
36 : : #include <com/sun/star/frame/status/ItemStatus.hpp>
37 : : #include <com/sun/star/frame/status/ItemState.hpp>
38 : :
39 : : #include <comphelper/componentcontext.hxx>
40 : : #include <osl/mutex.hxx>
41 : : #include <vcl/svapp.hxx>
42 : :
43 : : using namespace ::com::sun::star::awt;
44 : : using namespace ::com::sun::star::uno;
45 : : using namespace ::com::sun::star::beans;
46 : : using namespace ::com::sun::star::lang;
47 : : using namespace ::com::sun::star::frame;
48 : : using namespace ::com::sun::star::frame::status;
49 : : using namespace ::com::sun::star::util;
50 : :
51 : : namespace svt
52 : : {
53 : :
54 [ # # ][ # # ]: 0 : struct ExecuteInfo
55 : : {
56 : : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
57 : : ::com::sun::star::util::URL aTargetURL;
58 : : ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
59 : : };
60 : :
61 : 0 : GenericToolboxController::GenericToolboxController( const Reference< XMultiServiceFactory >& rServiceManager,
62 : : const Reference< XFrame >& rFrame,
63 : : ToolBox* pToolbox,
64 : : sal_uInt16 nID,
65 : : const ::rtl::OUString& aCommand ) :
66 : : svt::ToolboxController( rServiceManager, rFrame, aCommand )
67 : : , m_pToolbox( pToolbox )
68 : 0 : , m_nID( nID )
69 : : {
70 : : // Initialization is done through ctor
71 : 0 : m_bInitialized = sal_True;
72 : :
73 : : // insert main command to our listener map
74 [ # # ]: 0 : if ( !m_aCommandURL.isEmpty() )
75 [ # # ][ # # ]: 0 : m_aListenerMap.insert( URLToDispatchMap::value_type( aCommand, Reference< XDispatch >() ));
[ # # ]
76 : 0 : }
77 : :
78 : 0 : GenericToolboxController::~GenericToolboxController()
79 : : {
80 [ # # ]: 0 : }
81 : :
82 : 0 : void SAL_CALL GenericToolboxController::dispose()
83 : : throw ( RuntimeException )
84 : : {
85 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
86 : :
87 [ # # ]: 0 : svt::ToolboxController::dispose();
88 : :
89 : 0 : m_pToolbox = 0;
90 [ # # ]: 0 : m_nID = 0;
91 : 0 : }
92 : :
93 : 0 : void SAL_CALL GenericToolboxController::execute( sal_Int16 /*KeyModifier*/ )
94 : : throw ( RuntimeException )
95 : : {
96 : 0 : Reference< XDispatch > xDispatch;
97 : 0 : Reference< XURLTransformer > xURLTransformer;
98 : 0 : ::rtl::OUString aCommandURL;
99 : :
100 : : {
101 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
102 : :
103 [ # # ]: 0 : if ( m_bDisposed )
104 [ # # ]: 0 : throw DisposedException();
105 : :
106 [ # # # # : 0 : if ( m_bInitialized &&
# # # # ]
[ # # ]
107 : 0 : m_xFrame.is() &&
108 : 0 : m_xServiceManager.is() &&
109 : 0 : !m_aCommandURL.isEmpty() )
110 : : {
111 [ # # ][ # # ]: 0 : xURLTransformer = com::sun::star::util::URLTransformer::create( ::comphelper::ComponentContext(m_xServiceManager).getUNOContext() );
[ # # ][ # # ]
[ # # ]
112 : :
113 : 0 : aCommandURL = m_aCommandURL;
114 [ # # ]: 0 : URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
115 [ # # ][ # # ]: 0 : if ( pIter != m_aListenerMap.end() )
116 [ # # ][ # # ]: 0 : xDispatch = pIter->second;
117 [ # # ]: 0 : }
118 : : }
119 : :
120 [ # # ][ # # ]: 0 : if ( xDispatch.is() && xURLTransformer.is() )
[ # # ]
121 : : {
122 : 0 : com::sun::star::util::URL aTargetURL;
123 [ # # ]: 0 : Sequence<PropertyValue> aArgs;
124 : :
125 : 0 : aTargetURL.Complete = aCommandURL;
126 [ # # ][ # # ]: 0 : xURLTransformer->parseStrict( aTargetURL );
127 : :
128 : : // Execute dispatch asynchronously
129 [ # # ][ # # ]: 0 : ExecuteInfo* pExecuteInfo = new ExecuteInfo;
130 [ # # ]: 0 : pExecuteInfo->xDispatch = xDispatch;
131 : 0 : pExecuteInfo->aTargetURL = aTargetURL;
132 [ # # ]: 0 : pExecuteInfo->aArgs = aArgs;
133 [ # # ][ # # ]: 0 : Application::PostUserEvent( STATIC_LINK(0, GenericToolboxController , ExecuteHdl_Impl), pExecuteInfo );
[ # # ]
134 : 0 : }
135 : 0 : }
136 : :
137 : 0 : void GenericToolboxController::statusChanged( const FeatureStateEvent& Event )
138 : : throw ( RuntimeException )
139 : : {
140 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
141 : :
142 [ # # ]: 0 : if ( m_bDisposed )
143 : 0 : return;
144 : :
145 [ # # ]: 0 : if ( m_pToolbox )
146 : : {
147 [ # # ]: 0 : m_pToolbox->EnableItem( m_nID, Event.IsEnabled );
148 : :
149 [ # # ]: 0 : sal_uInt16 nItemBits = m_pToolbox->GetItemBits( m_nID );
150 : 0 : nItemBits &= ~TIB_CHECKABLE;
151 : 0 : TriState eTri = STATE_NOCHECK;
152 : :
153 : 0 : sal_Bool bValue = sal_Bool();
154 : 0 : rtl::OUString aStrValue;
155 : 0 : ItemStatus aItemState;
156 : :
157 [ # # ]: 0 : if ( Event.State >>= bValue )
158 : : {
159 : : // Boolean, treat it as checked/unchecked
160 [ # # ]: 0 : m_pToolbox->SetItemBits( m_nID, nItemBits );
161 [ # # ]: 0 : m_pToolbox->CheckItem( m_nID, bValue );
162 [ # # ]: 0 : if ( bValue )
163 : 0 : eTri = STATE_CHECK;
164 : 0 : nItemBits |= TIB_CHECKABLE;
165 : : }
166 [ # # ]: 0 : else if ( Event.State >>= aStrValue )
167 : : {
168 [ # # ][ # # ]: 0 : m_pToolbox->SetItemText( m_nID, aStrValue );
[ # # ]
169 : : }
170 [ # # ][ # # ]: 0 : else if ( Event.State >>= aItemState )
171 : : {
172 : 0 : eTri = STATE_DONTKNOW;
173 : 0 : nItemBits |= TIB_CHECKABLE;
174 : : }
175 : :
176 [ # # ]: 0 : m_pToolbox->SetItemState( m_nID, eTri );
177 [ # # ]: 0 : m_pToolbox->SetItemBits( m_nID, nItemBits );
178 [ # # ][ # # ]: 0 : }
179 : : }
180 : :
181 : 0 : IMPL_STATIC_LINK_NOINSTANCE( GenericToolboxController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
182 : : {
183 : : try
184 : : {
185 : : // Asynchronous execution as this can lead to our own destruction!
186 : : // Framework can recycle our current frame and the layout manager disposes all user interface
187 : : // elements if a component gets detached from its frame!
188 [ # # ][ # # ]: 0 : pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
189 : : }
190 : 0 : catch ( Exception& )
191 : : {
192 : : }
193 [ # # ]: 0 : delete pExecuteInfo;
194 [ # # ]: 0 : return 0;
195 : : }
196 : :
197 : : } // namespace
198 : :
199 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|