xref: /AOO41X/main/framework/source/uielement/togglebuttontoolbarcontroller.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_TOGGLEBUTTONTOOLBARCONTROLLER_HXX
32*cdf0e10cSrcweir #include "uielement/togglebuttontoolbarcontroller.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36*cdf0e10cSrcweir //	my own includes
37*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38*cdf0e10cSrcweir #include <framework/addonsoptions.hxx>
39*cdf0e10cSrcweir #ifndef __FRAMEWORK_TOOLBAR_HXX_
40*cdf0e10cSrcweir #include "uielement/toolbar.hxx"
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44*cdf0e10cSrcweir //	interface includes
45*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/frame/XControlNotificationListener.hpp>
50*cdf0e10cSrcweir #include "com/sun/star/util/XMacroExpander.hpp"
51*cdf0e10cSrcweir #include "com/sun/star/uno/XComponentContext.hpp"
52*cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55*cdf0e10cSrcweir //	other includes
56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #include <rtl/uri.hxx>
59*cdf0e10cSrcweir #include <vos/mutex.hxx>
60*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
61*cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
62*cdf0e10cSrcweir #include <tools/urlobj.hxx>
63*cdf0e10cSrcweir #include <vcl/svapp.hxx>
64*cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
65*cdf0e10cSrcweir #include <vcl/window.hxx>
66*cdf0e10cSrcweir #include <vcl/graph.hxx>
67*cdf0e10cSrcweir #include <vcl/bitmap.hxx>
68*cdf0e10cSrcweir #include <svtools/filter.hxx>
69*cdf0e10cSrcweir #include <svtools/miscopt.hxx>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir using namespace ::com::sun::star;
72*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
73*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
74*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
75*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
76*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
77*cdf0e10cSrcweir using namespace ::com::sun::star::util;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir namespace framework
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir // ------------------------------------------------------------------
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir ToggleButtonToolbarController::ToggleButtonToolbarController(
85*cdf0e10cSrcweir     const Reference< XMultiServiceFactory >& rServiceManager,
86*cdf0e10cSrcweir     const Reference< XFrame >&               rFrame,
87*cdf0e10cSrcweir     ToolBox*                                 pToolbar,
88*cdf0e10cSrcweir     sal_uInt16                                   nID,
89*cdf0e10cSrcweir     Style                                    eStyle,
90*cdf0e10cSrcweir     const ::rtl::OUString&                          aCommand ) :
91*cdf0e10cSrcweir     ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand ),
92*cdf0e10cSrcweir     m_eStyle( eStyle )
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     if ( eStyle == STYLE_DROPDOWNBUTTON )
95*cdf0e10cSrcweir         m_pToolbar->SetItemBits( m_nID, TIB_DROPDOWNONLY | m_pToolbar->GetItemBits( m_nID ) );
96*cdf0e10cSrcweir     else if ( eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )
97*cdf0e10cSrcweir 	    m_pToolbar->SetItemBits( m_nID, TIB_DROPDOWN | m_pToolbar->GetItemBits( m_nID ) );
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir // ------------------------------------------------------------------
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir ToggleButtonToolbarController::~ToggleButtonToolbarController()
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir }
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir // ------------------------------------------------------------------
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir void SAL_CALL ToggleButtonToolbarController::dispose()
109*cdf0e10cSrcweir throw ( RuntimeException )
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
112*cdf0e10cSrcweir     ComplexToolbarController::dispose();
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir // ------------------------------------------------------------------
116*cdf0e10cSrcweir Sequence<PropertyValue> ToggleButtonToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
117*cdf0e10cSrcweir {
118*cdf0e10cSrcweir     Sequence<PropertyValue> aArgs( 2 );
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     // Add key modifier to argument list
121*cdf0e10cSrcweir     aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
122*cdf0e10cSrcweir     aArgs[0].Value <<= KeyModifier;
123*cdf0e10cSrcweir     aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
124*cdf0e10cSrcweir     aArgs[1].Value <<= m_aCurrentSelection;
125*cdf0e10cSrcweir     return aArgs;
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir // ------------------------------------------------------------------
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir uno::Reference< awt::XWindow > SAL_CALL ToggleButtonToolbarController::createPopupWindow()
131*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException)
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir     uno::Reference< awt::XWindow > xWindow;
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
136*cdf0e10cSrcweir     if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
137*cdf0e10cSrcweir         ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
138*cdf0e10cSrcweir     {
139*cdf0e10cSrcweir         // create popup menu
140*cdf0e10cSrcweir         PopupMenu aPopup;
141*cdf0e10cSrcweir         const sal_uInt32 nCount = m_aDropdownMenuList.size();
142*cdf0e10cSrcweir         for ( sal_uInt32 i = 0; i < nCount; i++ )
143*cdf0e10cSrcweir         {
144*cdf0e10cSrcweir             rtl::OUString aLabel( m_aDropdownMenuList[i] );
145*cdf0e10cSrcweir             aPopup.InsertItem( sal_uInt16( i+1 ), aLabel );
146*cdf0e10cSrcweir             if ( aLabel == m_aCurrentSelection )
147*cdf0e10cSrcweir                 aPopup.CheckItem( sal_uInt16( i+1 ), sal_True );
148*cdf0e10cSrcweir             else
149*cdf0e10cSrcweir                 aPopup.CheckItem( sal_uInt16( i+1 ), sal_False );
150*cdf0e10cSrcweir         }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir         m_pToolbar->SetItemDown( m_nID, sal_True );
153*cdf0e10cSrcweir         aPopup.SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl ));
154*cdf0e10cSrcweir         aPopup.Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID ));
155*cdf0e10cSrcweir         m_pToolbar->SetItemDown( m_nID, sal_False );
156*cdf0e10cSrcweir     }
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     return xWindow;
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir // ------------------------------------------------------------------
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir void ToggleButtonToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
168*cdf0e10cSrcweir         ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
169*cdf0e10cSrcweir     {
170*cdf0e10cSrcweir         if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 ))
171*cdf0e10cSrcweir         {
172*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
173*cdf0e10cSrcweir             {
174*cdf0e10cSrcweir                 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 ))
175*cdf0e10cSrcweir                 {
176*cdf0e10cSrcweir                     Sequence< ::rtl::OUString > aList;
177*cdf0e10cSrcweir                     m_aDropdownMenuList.clear();
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir                     rControlCommand.Arguments[i].Value >>= aList;
180*cdf0e10cSrcweir                     for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
181*cdf0e10cSrcweir                         m_aDropdownMenuList.push_back( aList[j] );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir                     // send notification
184*cdf0e10cSrcweir                     uno::Sequence< beans::NamedValue > aInfo( 1 );
185*cdf0e10cSrcweir                     aInfo[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ));
186*cdf0e10cSrcweir                     aInfo[0].Value <<= aList;
187*cdf0e10cSrcweir                     addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )),
188*cdf0e10cSrcweir                                 getDispatchFromCommand( m_aCommandURL ),
189*cdf0e10cSrcweir                                 aInfo );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir                     break;
192*cdf0e10cSrcweir                 }
193*cdf0e10cSrcweir             }
194*cdf0e10cSrcweir         }
195*cdf0e10cSrcweir         else if ( rControlCommand.Command.equalsAsciiL( "CheckItemPos", 12 ))
196*cdf0e10cSrcweir         {
197*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
198*cdf0e10cSrcweir             {
199*cdf0e10cSrcweir                 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
200*cdf0e10cSrcweir                 {
201*cdf0e10cSrcweir                     sal_Int32 nPos( -1 );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir                     rControlCommand.Arguments[i].Value >>= nPos;
204*cdf0e10cSrcweir                     if ( nPos >= 0 &&
205*cdf0e10cSrcweir                          ( sal::static_int_cast< sal_uInt32 >(nPos)
206*cdf0e10cSrcweir                            < m_aDropdownMenuList.size() ) )
207*cdf0e10cSrcweir                     {
208*cdf0e10cSrcweir                         m_aCurrentSelection = m_aDropdownMenuList[nPos];
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir                         // send notification
211*cdf0e10cSrcweir                         uno::Sequence< beans::NamedValue > aInfo( 1 );
212*cdf0e10cSrcweir                         aInfo[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ItemChecked" ));
213*cdf0e10cSrcweir                         aInfo[0].Value <<= nPos;
214*cdf0e10cSrcweir                         addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" )),
215*cdf0e10cSrcweir                                     getDispatchFromCommand( m_aCommandURL ),
216*cdf0e10cSrcweir                                     aInfo );
217*cdf0e10cSrcweir                     }
218*cdf0e10cSrcweir                     break;
219*cdf0e10cSrcweir                 }
220*cdf0e10cSrcweir             }
221*cdf0e10cSrcweir         }
222*cdf0e10cSrcweir         else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 ))
223*cdf0e10cSrcweir         {
224*cdf0e10cSrcweir             rtl::OUString   aText;
225*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
226*cdf0e10cSrcweir             {
227*cdf0e10cSrcweir                 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
228*cdf0e10cSrcweir                 {
229*cdf0e10cSrcweir                     if ( rControlCommand.Arguments[i].Value >>= aText )
230*cdf0e10cSrcweir                         m_aDropdownMenuList.push_back( aText );
231*cdf0e10cSrcweir                     break;
232*cdf0e10cSrcweir                 }
233*cdf0e10cSrcweir             }
234*cdf0e10cSrcweir         }
235*cdf0e10cSrcweir         else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 ))
236*cdf0e10cSrcweir         {
237*cdf0e10cSrcweir             sal_Int32      nPos( COMBOBOX_APPEND );
238*cdf0e10cSrcweir             sal_Int32      nSize = sal_Int32( m_aDropdownMenuList.size() );
239*cdf0e10cSrcweir             rtl::OUString  aText;
240*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
241*cdf0e10cSrcweir             {
242*cdf0e10cSrcweir                 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
243*cdf0e10cSrcweir                 {
244*cdf0e10cSrcweir                     sal_Int32 nTmpPos = 0;
245*cdf0e10cSrcweir                     if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
246*cdf0e10cSrcweir                     {
247*cdf0e10cSrcweir                         if (( nTmpPos >= 0 ) && ( nTmpPos < sal_Int32( nSize )))
248*cdf0e10cSrcweir                             nPos = nTmpPos;
249*cdf0e10cSrcweir                     }
250*cdf0e10cSrcweir                 }
251*cdf0e10cSrcweir                 else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
252*cdf0e10cSrcweir                     rControlCommand.Arguments[i].Value >>= aText;
253*cdf0e10cSrcweir             }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir             std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin();
256*cdf0e10cSrcweir             aIter += nPos;
257*cdf0e10cSrcweir 		    m_aDropdownMenuList.insert( aIter, aText );
258*cdf0e10cSrcweir         }
259*cdf0e10cSrcweir         else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 ))
260*cdf0e10cSrcweir         {
261*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
262*cdf0e10cSrcweir             {
263*cdf0e10cSrcweir                 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
264*cdf0e10cSrcweir                 {
265*cdf0e10cSrcweir                     sal_Int32 nPos( -1 );
266*cdf0e10cSrcweir                     if ( rControlCommand.Arguments[i].Value >>= nPos )
267*cdf0e10cSrcweir                     {
268*cdf0e10cSrcweir                         if ( nPos < sal_Int32( m_aDropdownMenuList.size() ))
269*cdf0e10cSrcweir                         {
270*cdf0e10cSrcweir                             std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin();
271*cdf0e10cSrcweir                             aIter += nPos;
272*cdf0e10cSrcweir 		                    m_aDropdownMenuList.erase( aIter );
273*cdf0e10cSrcweir                         }
274*cdf0e10cSrcweir                     }
275*cdf0e10cSrcweir                     break;
276*cdf0e10cSrcweir                 }
277*cdf0e10cSrcweir             }
278*cdf0e10cSrcweir         }
279*cdf0e10cSrcweir         else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 ))
280*cdf0e10cSrcweir         {
281*cdf0e10cSrcweir             for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
282*cdf0e10cSrcweir             {
283*cdf0e10cSrcweir                 if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
284*cdf0e10cSrcweir                 {
285*cdf0e10cSrcweir                     rtl::OUString aText;
286*cdf0e10cSrcweir                     if ( rControlCommand.Arguments[i].Value >>= aText )
287*cdf0e10cSrcweir                     {
288*cdf0e10cSrcweir                         sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
289*cdf0e10cSrcweir                         for ( sal_Int32 j = 0; j < nSize; j++ )
290*cdf0e10cSrcweir                         {
291*cdf0e10cSrcweir                             if ( m_aDropdownMenuList[j] == aText )
292*cdf0e10cSrcweir                             {
293*cdf0e10cSrcweir                                 std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin();
294*cdf0e10cSrcweir                                 aIter += j;
295*cdf0e10cSrcweir 		                        m_aDropdownMenuList.erase( aIter );
296*cdf0e10cSrcweir                                 break;
297*cdf0e10cSrcweir                             }
298*cdf0e10cSrcweir                         }
299*cdf0e10cSrcweir                     }
300*cdf0e10cSrcweir                     break;
301*cdf0e10cSrcweir                 }
302*cdf0e10cSrcweir             }
303*cdf0e10cSrcweir         }
304*cdf0e10cSrcweir     }
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir IMPL_LINK( ToggleButtonToolbarController, MenuSelectHdl, Menu *, pMenu )
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir     vos::OGuard aGuard( Application::GetSolarMutex() );
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir     sal_uInt16 nItemId = pMenu->GetCurItemId();
312*cdf0e10cSrcweir     if ( nItemId > 0 && nItemId <= m_aDropdownMenuList.size() )
313*cdf0e10cSrcweir     {
314*cdf0e10cSrcweir         m_aCurrentSelection = m_aDropdownMenuList[nItemId-1];
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir         execute( 0 );
317*cdf0e10cSrcweir     }
318*cdf0e10cSrcweir     return 0;
319*cdf0e10cSrcweir }
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir } // namespace
322*cdf0e10cSrcweir 
323