1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: toolboxcontroller.cxx,v $
10 * $Revision: 1.13.98.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
33 #ifndef DBACCESS_TOOLBOXCONTROLLER_HXX
34 #include "toolboxcontroller.hxx"
36 #ifndef _COM_SUN_STAR_UI_IMAGETYPE_HPP_
37 #include <com/sun/star/ui/ImageType.hpp>
39 #ifndef _COM_SUN_STAR_FRAME_XDISPATCHPROVIDER_HPP_
40 #include <com/sun/star/frame/XDispatchProvider.hpp>
42 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
43 #include <toolkit/helper/vclunohelper.hxx>
46 #include <vcl/menu.hxx>
48 #ifndef _COM_SUN_STAR_UI_XUICONFIGURATIONMANAGER_HPP_
49 #include <com/sun/star/ui/XUIConfigurationManager.hpp>
51 #ifndef _COM_SUN_STAR_UI_XMODULEUICONFIGURATIONMANAGERSUPPLIER_HPP_
52 #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
54 #ifndef _COM_SUN_STAR_UI_XIMAGEMANAGER_HPP_
55 #include <com/sun/star/ui/XImageManager.hpp>
57 #ifndef _COM_SUN_STAR_UI_IMAGETYPE_HPP_
58 #include <com/sun/star/ui/ImageType.hpp>
60 #ifndef _COM_SUN_STAR_GRAPHIC_XGRAPHIC_HPP_
61 #include <com/sun/star/graphic/XGraphic.hpp>
63 #ifndef _SV_SVAPP_HXX //autogen
64 #include <vcl/svapp.hxx>
66 #ifndef _SV_TOOLBOX_HXX
67 #include <vcl/toolbox.hxx>
69 #ifndef _DBU_RESOURCE_HRC_
70 #include "dbu_resource.hrc"
72 #ifndef INCLUDED_SVTOOLS_MISCOPT_HXX
73 #include <svtools/miscopt.hxx>
75 #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
76 #include <svtools/moduleoptions.hxx>
78 #ifndef TOOLS_DIAGNOSE_EX_H
79 #include <tools/diagnose_ex.h>
81 #ifndef INCLUDED_SVTOOLS_MENUOPTIONS_HXX
82 #include <svtools/menuoptions.hxx>
84 #ifndef _VOS_MUTEX_HXX_
85 #include <vos/mutex.hxx>
87 #ifndef _DBU_REGHELPER_HXX_
88 #include "dbu_reghelper.hxx"
90 #ifndef DBAUI_TOOLS_HXX
91 #include "UITools.hxx"
95 extern "C" void SAL_CALL
createRegistryInfo_OToolboxController()
97 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::OToolboxController
> aAutoRegistration
;
102 using namespace ::com::sun::star::graphic
;
103 using namespace com::sun::star::uno
;
104 using namespace com::sun::star::beans
;
105 using namespace com::sun::star::lang
;
106 using namespace ::com::sun::star::frame
;
107 using namespace ::com::sun::star::util
;
108 using namespace ::com::sun::star::ui
;
112 void lcl_copy(Menu
* _pMenu
,USHORT _nMenuId
,USHORT _nMenuPos
,ToolBox
* _pToolBox
,USHORT _nToolId
,const ::rtl::OUString
& _sCommand
)
114 if ( _pMenu
->GetItemType(_nMenuPos
) != MENUITEM_STRING
)
115 _pToolBox
->SetItemImage(_nToolId
, _pMenu
->GetItemImage(_nMenuId
));
116 _pToolBox
->SetItemCommand( _nToolId
, _sCommand
);
117 _pToolBox
->SetHelpId(_nToolId
, _pMenu
->GetHelpId(_nMenuId
));
118 _pToolBox
->SetHelpText(_nToolId
, _pMenu
->GetHelpText(_nMenuId
));
119 _pToolBox
->SetQuickHelpText(_nToolId
, _pMenu
->GetTipHelpText(_nMenuId
));
120 _pToolBox
->SetItemText(_nToolId
, _pMenu
->GetItemText(_nMenuId
));
124 OToolboxController::OToolboxController(const Reference
< XMultiServiceFactory
>& _rxORB
)
127 osl_incrementInterlockedCount(&m_refCount
);
128 m_xServiceManager
= _rxORB
;
129 osl_decrementInterlockedCount(&m_refCount
);
132 // -----------------------------------------------------------------------------
133 IMPLEMENT_SERVICE_INFO1_STATIC(OToolboxController
,"com.sun.star.sdb.ApplicationToolboxController","com.sun.star.frame.ToolboxController")
134 // -----------------------------------------------------------------------------
136 Any SAL_CALL
OToolboxController::queryInterface( const Type
& _rType
) throw (RuntimeException
)
138 Any aReturn
= ToolboxController::queryInterface(_rType
);
139 if (!aReturn
.hasValue())
140 aReturn
= TToolboxController_BASE::queryInterface(_rType
);
143 // -----------------------------------------------------------------------------
144 void SAL_CALL
OToolboxController::acquire() throw ()
146 ToolboxController::acquire();
148 // -----------------------------------------------------------------------------
149 void SAL_CALL
OToolboxController::release() throw ()
151 ToolboxController::release();
153 // -----------------------------------------------------------------------------
154 void SAL_CALL
OToolboxController::initialize( const Sequence
< Any
>& _rArguments
) throw (Exception
, RuntimeException
)
156 ToolboxController::initialize(_rArguments
);
157 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
158 ::osl::MutexGuard
aGuard(m_aMutex
);
160 if ( m_aCommandURL
.equalsAscii(".uno:DBNewForm") )
162 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewForm")) ,sal_True
));
163 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewView")) ,sal_True
));
164 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewViewSQL")) ,sal_True
));
165 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewQuery")) ,sal_True
));
166 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewQuerySql")) ,sal_True
));
167 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewReport")) ,sal_True
));
168 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewReportAutoPilot")),sal_True
));
169 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBNewTable")) ,sal_True
));
173 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:Refresh")) ,sal_True
));
174 m_aStates
.insert(TCommandState::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".uno:DBRebuildData")) ,sal_True
));
177 TCommandState::iterator aIter
= m_aStates
.begin();
178 TCommandState::iterator aEnd
= m_aStates
.end();
179 for (; aIter
!= aEnd
; ++aIter
)
180 addStatusListener(aIter
->first
);
182 ToolBox
* pToolBox
= static_cast<ToolBox
*>(VCLUnoHelper::GetWindow(getParent()));
185 USHORT nCount
= pToolBox
->GetItemCount();
186 for (USHORT nPos
= 0; nPos
< nCount
; ++nPos
)
188 USHORT nItemId
= pToolBox
->GetItemId(nPos
);
189 if ( pToolBox
->GetItemCommand(nItemId
) == String(m_aCommandURL
) )
191 m_nToolBoxId
= nItemId
;
196 // check if paste special is allowed, when not don't add DROPDOWN
197 pToolBox
->SetItemBits(m_nToolBoxId
,pToolBox
->GetItemBits(m_nToolBoxId
) | TIB_DROPDOWN
);
200 // -----------------------------------------------------------------------------
201 void SAL_CALL
OToolboxController::statusChanged( const FeatureStateEvent
& Event
) throw ( RuntimeException
)
203 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
204 ::osl::MutexGuard
aGuard(m_aMutex
);
205 TCommandState::iterator aFind
= m_aStates
.find( Event
.FeatureURL
.Complete
);
206 if ( aFind
!= m_aStates
.end() )
208 aFind
->second
= Event
.IsEnabled
;
209 if ( m_aCommandURL
== aFind
->first
&& !Event
.IsEnabled
)
211 ::std::auto_ptr
<PopupMenu
> pMenu
= getMenu();
212 USHORT nCount
= pMenu
->GetItemCount();
213 for (USHORT i
= 0; i
< nCount
; ++i
)
215 USHORT nItemId
= pMenu
->GetItemId(i
);
216 aFind
= m_aStates
.find(pMenu
->GetItemCommand(nItemId
));
217 if ( aFind
!= m_aStates
.end() && aFind
->second
)
219 m_aCommandURL
= aFind
->first
;
221 ToolBox
* pToolBox
= static_cast<ToolBox
*>(VCLUnoHelper::GetWindow(getParent()));
222 lcl_copy(pMenu
.get(),nItemId
,i
,pToolBox
,m_nToolBoxId
, m_aCommandURL
);
229 // -----------------------------------------------------------------------------
230 ::std::auto_ptr
<PopupMenu
> OToolboxController::getMenu()
232 ::std::auto_ptr
<PopupMenu
> pMenu
;
233 if ( m_aStates
.size() > 2 )
235 pMenu
.reset( new PopupMenu( ModuleRes( RID_MENU_APP_NEW
) ) );
237 sal_Bool bHighContrast
= isHighContrast();
241 Reference
<XModuleUIConfigurationManagerSupplier
> xModuleCfgMgrSupplier(getServiceManager()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ui.ModuleUIConfigurationManagerSupplier"))),UNO_QUERY
);
242 Reference
<XUIConfigurationManager
> xUIConfigMgr
= xModuleCfgMgrSupplier
->getUIConfigurationManager(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument")));
243 Reference
<XImageManager
> xImageMgr(xUIConfigMgr
->getImageManager(),UNO_QUERY
);
246 short nImageType
= hasBigImages() ? ImageType::SIZE_LARGE
: ImageType::SIZE_DEFAULT
;
248 nImageType
|= ImageType::COLOR_HIGHCONTRAST
;
250 Sequence
< ::rtl::OUString
> aSeq(1);
251 USHORT nCount
= pMenu
->GetItemCount();
252 for (USHORT nPos
= 0; nPos
< nCount
; ++nPos
)
254 if ( pMenu
->GetItemType( nPos
) == MENUITEM_SEPARATOR
)
257 USHORT nItemId
= pMenu
->GetItemId(nPos
);
258 aSeq
[0] = pMenu
->GetItemCommand(nItemId
);
259 Sequence
< Reference
<XGraphic
> > aImages
= xImageMgr
->getImages(nImageType
,aSeq
);
261 Image
aImage(aImages
[0]);
262 pMenu
->SetItemImage(nItemId
,aImage
);
263 TCommandState::iterator aFind
= m_aStates
.find( aSeq
[0] );
264 if ( aFind
!= m_aStates
.end() )
266 pMenu
->EnableItem(nItemId
,aFind
->second
);
270 catch(const Exception
&)
272 DBG_UNHANDLED_EXCEPTION();
277 pMenu
.reset( new PopupMenu( ModuleRes( RID_MENU_REFRESH_DATA
) ) );
281 // -----------------------------------------------------------------------------
282 Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
OToolboxController::createPopupWindow() throw (RuntimeException
)
285 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
286 ::osl::MutexGuard
aGuard(m_aMutex
);
288 ToolBox
* pToolBox
= static_cast<ToolBox
*>(VCLUnoHelper::GetWindow(getParent()));
289 ::std::auto_ptr
<PopupMenu
> pMenu
= getMenu();
291 USHORT nSelected
= pMenu
->Execute(pToolBox
, pToolBox
->GetItemRect( m_nToolBoxId
),POPUPMENU_EXECUTE_DOWN
);
292 // "cleanup" the toolbox state
293 Point aPoint
= pToolBox
->GetItemRect( m_nToolBoxId
).TopLeft();
294 MouseEvent
aLeave( aPoint
, 0, MOUSE_LEAVEWINDOW
| MOUSE_SYNTHETIC
);
295 pToolBox
->MouseMove( aLeave
);
296 pToolBox
->SetItemDown( m_nToolBoxId
, sal_False
);
300 m_aCommandURL
= pMenu
->GetItemCommand(nSelected
);
301 lcl_copy(pMenu
.get(),nSelected
,pMenu
->GetItemPos(nSelected
),pToolBox
,m_nToolBoxId
, m_aCommandURL
);
303 Reference
<XDispatch
> xDispatch
= m_aListenerMap
.find(m_aCommandURL
)->second
;
304 if ( xDispatch
.is() )
307 Sequence
< PropertyValue
> aArgs
;
308 aUrl
.Complete
= m_aCommandURL
;
309 OSL_ENSURE(aUrl
.Complete
.getLength(),"Command is empty!");
310 if ( getURLTransformer().is() )
311 getURLTransformer()->parseStrict(aUrl
);
312 xDispatch
->dispatch(aUrl
,aArgs
);
316 return Reference
< ::com::sun::star::awt::XWindow
>();
318 // -----------------------------------------------------------------------------
319 // -----------------------------------------------------------------------------
320 //..........................................................................
322 //..........................................................................