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