Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "toolboxcontroller.hxx"
21 : : #include <com/sun/star/ui/ImageType.hpp>
22 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
23 : : #include <toolkit/helper/vclunohelper.hxx>
24 : : #include <vcl/menu.hxx>
25 : : #include <com/sun/star/ui/XUIConfigurationManager.hpp>
26 : : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
27 : : #include <com/sun/star/ui/XImageManager.hpp>
28 : : #include <com/sun/star/graphic/XGraphic.hpp>
29 : : #include <vcl/svapp.hxx>
30 : : #include <vcl/toolbox.hxx>
31 : : #include "dbu_resource.hrc"
32 : : #include <svtools/miscopt.hxx>
33 : : #include <unotools/moduleoptions.hxx>
34 : : #include <tools/diagnose_ex.h>
35 : : #include <svtools/menuoptions.hxx>
36 : : #include <osl/mutex.hxx>
37 : : #include "dbu_reghelper.hxx"
38 : : #include "UITools.hxx"
39 : :
40 : :
41 : 8 : extern "C" void SAL_CALL createRegistryInfo_OToolboxController()
42 : : {
43 [ + - ][ + - ]: 8 : static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::OToolboxController> aAutoRegistration;
[ + - ][ # # ]
44 : 8 : }
45 : : namespace dbaui
46 : : {
47 : : using namespace svt;
48 : : using namespace ::com::sun::star::graphic;
49 : : using namespace com::sun::star::uno;
50 : : using namespace com::sun::star::beans;
51 : : using namespace com::sun::star::lang;
52 : : using namespace ::com::sun::star::frame;
53 : : using namespace ::com::sun::star::util;
54 : : using namespace ::com::sun::star::ui;
55 : :
56 : : namespace
57 : : {
58 : 0 : void lcl_copy(Menu* _pMenu,sal_uInt16 _nMenuId,sal_uInt16 _nMenuPos,ToolBox* _pToolBox,sal_uInt16 _nToolId,const ::rtl::OUString& _sCommand)
59 : : {
60 [ # # ]: 0 : if ( _pMenu->GetItemType(_nMenuPos) != MENUITEM_STRING )
61 [ # # ]: 0 : _pToolBox->SetItemImage(_nToolId, _pMenu->GetItemImage(_nMenuId));
62 [ # # ]: 0 : _pToolBox->SetItemCommand( _nToolId, _sCommand);
63 [ # # ]: 0 : _pToolBox->SetHelpId(_nToolId, _pMenu->GetHelpId(_nMenuId));
64 : 0 : _pToolBox->SetHelpText(_nToolId, _pMenu->GetHelpText(_nMenuId));
65 : 0 : _pToolBox->SetQuickHelpText(_nToolId, _pMenu->GetTipHelpText(_nMenuId));
66 [ # # ]: 0 : _pToolBox->SetItemText(_nToolId, _pMenu->GetItemText(_nMenuId));
67 : 0 : }
68 : : }
69 : :
70 : 0 : OToolboxController::OToolboxController(const Reference< XMultiServiceFactory >& _rxORB)
71 [ # # ][ # # ]: 0 : : m_nToolBoxId(1)
72 : : {
73 [ # # ]: 0 : osl_incrementInterlockedCount(&m_refCount);
74 [ # # ]: 0 : m_xServiceManager = _rxORB;
75 [ # # ]: 0 : osl_decrementInterlockedCount(&m_refCount);
76 : :
77 : 0 : }
78 : : // -----------------------------------------------------------------------------
79 [ # # ][ # # ]: 24 : IMPLEMENT_SERVICE_INFO1_STATIC(OToolboxController,"com.sun.star.sdb.ApplicationToolboxController","com.sun.star.frame.ToolboxController")
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ]
80 : : // -----------------------------------------------------------------------------
81 : : // XInterface
82 : 0 : Any SAL_CALL OToolboxController::queryInterface( const Type& _rType ) throw (RuntimeException)
83 : : {
84 : 0 : Any aReturn = ToolboxController::queryInterface(_rType);
85 [ # # ]: 0 : if (!aReturn.hasValue())
86 [ # # ]: 0 : aReturn = TToolboxController_BASE::queryInterface(_rType);
87 : 0 : return aReturn;
88 : : }
89 : : // -----------------------------------------------------------------------------
90 : 0 : void SAL_CALL OToolboxController::acquire() throw ()
91 : : {
92 : 0 : ToolboxController::acquire();
93 : 0 : }
94 : : // -----------------------------------------------------------------------------
95 : 0 : void SAL_CALL OToolboxController::release() throw ()
96 : : {
97 : 0 : ToolboxController::release();
98 : 0 : }
99 : : // -----------------------------------------------------------------------------
100 : 0 : void SAL_CALL OToolboxController::initialize( const Sequence< Any >& _rArguments ) throw (Exception, RuntimeException)
101 : : {
102 [ # # ]: 0 : ToolboxController::initialize(_rArguments);
103 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
104 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
105 : :
106 [ # # ]: 0 : if ( m_aCommandURL == ".uno:DBNewForm" )
107 : : {
108 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewForm")) ,sal_True));
109 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewView")) ,sal_True));
110 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewViewSQL")) ,sal_True));
111 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewQuery")) ,sal_True));
112 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewQuerySql")) ,sal_True));
113 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewReport")) ,sal_True));
114 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewReportAutoPilot")),sal_True));
115 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewTable")) ,sal_True));
116 : : }
117 : : else
118 : : {
119 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Refresh")) ,sal_True));
120 [ # # ][ # # ]: 0 : m_aStates.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBRebuildData")) ,sal_True));
121 : : }
122 : :
123 : 0 : TCommandState::iterator aIter = m_aStates.begin();
124 : 0 : TCommandState::iterator aEnd = m_aStates.end();
125 [ # # ]: 0 : for (; aIter != aEnd; ++aIter)
126 [ # # ]: 0 : addStatusListener(aIter->first);
127 : :
128 [ # # ][ # # ]: 0 : ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
129 [ # # ]: 0 : if ( pToolBox )
130 : : {
131 [ # # ]: 0 : sal_uInt16 nCount = pToolBox->GetItemCount();
132 [ # # ]: 0 : for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
133 : : {
134 [ # # ]: 0 : sal_uInt16 nItemId = pToolBox->GetItemId(nPos);
135 [ # # ][ # # ]: 0 : if ( pToolBox->GetItemCommand(nItemId) == String(m_aCommandURL) )
[ # # ][ # # ]
[ # # ]
136 : : {
137 : 0 : m_nToolBoxId = nItemId;
138 : 0 : break;
139 : : }
140 : : }
141 : :
142 : : // check if paste special is allowed, when not don't add DROPDOWN
143 [ # # ][ # # ]: 0 : pToolBox->SetItemBits(m_nToolBoxId,pToolBox->GetItemBits(m_nToolBoxId) | TIB_DROPDOWN);
144 [ # # ][ # # ]: 0 : }
145 : 0 : }
146 : : // -----------------------------------------------------------------------------
147 : 0 : void SAL_CALL OToolboxController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException )
148 : : {
149 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
150 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
151 [ # # ]: 0 : TCommandState::iterator aFind = m_aStates.find( Event.FeatureURL.Complete );
152 [ # # ]: 0 : if ( aFind != m_aStates.end() )
153 : : {
154 : 0 : aFind->second = Event.IsEnabled;
155 [ # # ][ # # ]: 0 : if ( m_aCommandURL == aFind->first && !Event.IsEnabled )
[ # # ]
156 : : {
157 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
158 [ # # ][ # # ]: 0 : ::std::auto_ptr<PopupMenu> pMenu = getMenu();
159 : : SAL_WNODEPRECATED_DECLARATIONS_POP
160 [ # # ]: 0 : sal_uInt16 nCount = pMenu->GetItemCount();
161 [ # # ]: 0 : for (sal_uInt16 i = 0; i < nCount; ++i)
162 : : {
163 [ # # ]: 0 : sal_uInt16 nItemId = pMenu->GetItemId(i);
164 [ # # ][ # # ]: 0 : aFind = m_aStates.find(pMenu->GetItemCommand(nItemId));
[ # # ]
165 [ # # ][ # # ]: 0 : if ( aFind != m_aStates.end() && aFind->second )
[ # # ][ # # ]
166 : : {
167 : 0 : m_aCommandURL = aFind->first;
168 : :
169 [ # # ][ # # ]: 0 : ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
170 [ # # ]: 0 : lcl_copy(pMenu.get(),nItemId,i,pToolBox,m_nToolBoxId, m_aCommandURL);
171 : 0 : break;
172 : : }
173 [ # # ]: 0 : }
174 : : }
175 [ # # ][ # # ]: 0 : }
176 : 0 : }
177 : : // -----------------------------------------------------------------------------
178 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
179 : 0 : ::std::auto_ptr<PopupMenu> OToolboxController::getMenu()
180 : : {
181 : 0 : ::std::auto_ptr<PopupMenu> pMenu;
182 [ # # ]: 0 : if ( m_aStates.size() > 2 )
183 : : {
184 [ # # ][ # # ]: 0 : pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_APP_NEW ) ) );
[ # # ]
185 : :
186 : : try
187 : : {
188 [ # # ][ # # ]: 0 : Reference<XModuleUIConfigurationManagerSupplier> xModuleCfgMgrSupplier(getServiceManager()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.ModuleUIConfigurationManagerSupplier"))),UNO_QUERY);
[ # # ][ # # ]
[ # # ]
189 [ # # ][ # # ]: 0 : Reference<XUIConfigurationManager> xUIConfigMgr = xModuleCfgMgrSupplier->getUIConfigurationManager(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument")));
[ # # ]
190 [ # # ][ # # ]: 0 : Reference<XImageManager> xImageMgr(xUIConfigMgr->getImageManager(),UNO_QUERY);
[ # # ]
191 : :
192 : :
193 [ # # ][ # # ]: 0 : short nImageType = hasBigImages() ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT;
194 : :
195 [ # # ]: 0 : Sequence< ::rtl::OUString> aSeq(1);
196 [ # # ]: 0 : sal_uInt16 nCount = pMenu->GetItemCount();
197 [ # # ]: 0 : for (sal_uInt16 nPos = 0; nPos < nCount; ++nPos)
198 : : {
199 [ # # ][ # # ]: 0 : if ( pMenu->GetItemType( nPos ) == MENUITEM_SEPARATOR )
200 : 0 : continue;
201 : :
202 [ # # ]: 0 : sal_uInt16 nItemId = pMenu->GetItemId(nPos);
203 [ # # ][ # # ]: 0 : aSeq[0] = pMenu->GetItemCommand(nItemId);
[ # # ]
204 [ # # ][ # # ]: 0 : Sequence< Reference<XGraphic> > aImages = xImageMgr->getImages(nImageType,aSeq);
205 : :
206 [ # # ][ # # ]: 0 : Image aImage(aImages[0]);
207 [ # # ]: 0 : pMenu->SetItemImage(nItemId,aImage);
208 [ # # ][ # # ]: 0 : TCommandState::iterator aFind = m_aStates.find( aSeq[0] );
209 [ # # ]: 0 : if ( aFind != m_aStates.end() )
210 : : {
211 [ # # ]: 0 : pMenu->EnableItem(nItemId,aFind->second);
212 : : }
213 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
214 : : }
215 [ # # ]: 0 : catch(const Exception&)
216 : : {
217 : : DBG_UNHANDLED_EXCEPTION();
218 : : }
219 : : }
220 : : else
221 : : {
222 [ # # ][ # # ]: 0 : pMenu.reset( new PopupMenu( ModuleRes( RID_MENU_REFRESH_DATA ) ) );
[ # # ]
223 : : }
224 : 0 : return pMenu;
225 : : }
226 : : SAL_WNODEPRECATED_DECLARATIONS_POP
227 : : // -----------------------------------------------------------------------------
228 : 0 : Reference< ::com::sun::star::awt::XWindow > SAL_CALL OToolboxController::createPopupWindow() throw (RuntimeException)
229 : : {
230 : : // execute the menu
231 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
232 [ # # ]: 0 : ::osl::MutexGuard aGuard(m_aMutex);
233 : :
234 [ # # ][ # # ]: 0 : ToolBox* pToolBox = static_cast<ToolBox*>(VCLUnoHelper::GetWindow(getParent()));
235 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
236 [ # # ][ # # ]: 0 : ::std::auto_ptr<PopupMenu> pMenu = getMenu();
237 : : SAL_WNODEPRECATED_DECLARATIONS_POP
238 : :
239 [ # # ][ # # ]: 0 : sal_uInt16 nSelected = pMenu->Execute(pToolBox, pToolBox->GetItemRect( m_nToolBoxId ),POPUPMENU_EXECUTE_DOWN);
240 : : // "cleanup" the toolbox state
241 [ # # ]: 0 : Point aPoint = pToolBox->GetItemRect( m_nToolBoxId ).TopLeft();
242 [ # # ]: 0 : MouseEvent aLeave( aPoint, 0, MOUSE_LEAVEWINDOW | MOUSE_SYNTHETIC );
243 [ # # ]: 0 : pToolBox->MouseMove( aLeave );
244 [ # # ]: 0 : pToolBox->SetItemDown( m_nToolBoxId, sal_False);
245 : :
246 [ # # ]: 0 : if ( nSelected )
247 : : {
248 [ # # ][ # # ]: 0 : m_aCommandURL = pMenu->GetItemCommand(nSelected);
249 [ # # ][ # # ]: 0 : lcl_copy(pMenu.get(),nSelected,pMenu->GetItemPos(nSelected),pToolBox,m_nToolBoxId, m_aCommandURL);
250 : :
251 [ # # ][ # # ]: 0 : Reference<XDispatch> xDispatch = m_aListenerMap.find(m_aCommandURL)->second;
252 [ # # ]: 0 : if ( xDispatch.is() )
253 : : {
254 : 0 : URL aUrl;
255 [ # # ]: 0 : Sequence < PropertyValue > aArgs;
256 : 0 : aUrl.Complete = m_aCommandURL;
257 : : OSL_ENSURE(!aUrl.Complete.isEmpty(),"Command is empty!");
258 [ # # ][ # # ]: 0 : if ( getURLTransformer().is() )
259 [ # # ][ # # ]: 0 : getURLTransformer()->parseStrict(aUrl);
[ # # ]
260 [ # # ][ # # ]: 0 : xDispatch->dispatch(aUrl,aArgs);
[ # # ]
261 : :
262 : 0 : }
263 : : }
264 [ # # ][ # # ]: 0 : return Reference< ::com::sun::star::awt::XWindow >();
[ # # ]
265 : : }
266 : : // -----------------------------------------------------------------------------
267 : : // -----------------------------------------------------------------------------
268 : : //..........................................................................
269 : : } // dbaui
270 : : //..........................................................................
271 : :
272 : :
273 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|