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 : :
30 : : #include "uielement/togglebuttontoolbarcontroller.hxx"
31 : :
32 : : #include <framework/addonsoptions.hxx>
33 : : #include "uielement/toolbar.hxx"
34 : :
35 : : #include <com/sun/star/util/XURLTransformer.hpp>
36 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
37 : : #include <com/sun/star/beans/PropertyValue.hpp>
38 : : #include <com/sun/star/frame/XControlNotificationListener.hpp>
39 : : #include "com/sun/star/util/XMacroExpander.hpp"
40 : : #include "com/sun/star/uno/XComponentContext.hpp"
41 : : #include "com/sun/star/beans/XPropertySet.hpp"
42 : :
43 : : #include <rtl/uri.hxx>
44 : : #include <osl/mutex.hxx>
45 : : #include <comphelper/processfactory.hxx>
46 : : #include <unotools/ucbstreamhelper.hxx>
47 : : #include <vcl/svapp.hxx>
48 : : #include <vcl/mnemonic.hxx>
49 : : #include <vcl/window.hxx>
50 : : #include <vcl/graph.hxx>
51 : : #include <vcl/bitmap.hxx>
52 : : #include <svtools/filter.hxx>
53 : : #include <svtools/miscopt.hxx>
54 : :
55 : : using namespace ::com::sun::star;
56 : : using namespace ::com::sun::star::awt;
57 : : using namespace ::com::sun::star::uno;
58 : : using namespace ::com::sun::star::beans;
59 : : using namespace ::com::sun::star::lang;
60 : : using namespace ::com::sun::star::frame;
61 : : using namespace ::com::sun::star::util;
62 : :
63 : : namespace framework
64 : : {
65 : :
66 : : // ------------------------------------------------------------------
67 : :
68 : 0 : ToggleButtonToolbarController::ToggleButtonToolbarController(
69 : : const Reference< XMultiServiceFactory >& rServiceManager,
70 : : const Reference< XFrame >& rFrame,
71 : : ToolBox* pToolbar,
72 : : sal_uInt16 nID,
73 : : Style eStyle,
74 : : const ::rtl::OUString& aCommand ) :
75 : : ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand ),
76 [ # # ]: 0 : m_eStyle( eStyle )
77 : : {
78 [ # # ]: 0 : if ( eStyle == STYLE_DROPDOWNBUTTON )
79 [ # # ][ # # ]: 0 : m_pToolbar->SetItemBits( m_nID, TIB_DROPDOWNONLY | m_pToolbar->GetItemBits( m_nID ) );
80 [ # # ]: 0 : else if ( eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )
81 [ # # ][ # # ]: 0 : m_pToolbar->SetItemBits( m_nID, TIB_DROPDOWN | m_pToolbar->GetItemBits( m_nID ) );
82 : 0 : }
83 : :
84 : : // ------------------------------------------------------------------
85 : :
86 : 0 : ToggleButtonToolbarController::~ToggleButtonToolbarController()
87 : : {
88 [ # # ]: 0 : }
89 : :
90 : : // ------------------------------------------------------------------
91 : :
92 : 0 : void SAL_CALL ToggleButtonToolbarController::dispose()
93 : : throw ( RuntimeException )
94 : : {
95 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
96 [ # # ][ # # ]: 0 : ComplexToolbarController::dispose();
97 : 0 : }
98 : :
99 : : // ------------------------------------------------------------------
100 : 0 : Sequence<PropertyValue> ToggleButtonToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
101 : : {
102 : 0 : Sequence<PropertyValue> aArgs( 2 );
103 : :
104 : : // Add key modifier to argument list
105 [ # # ][ # # ]: 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
106 [ # # ][ # # ]: 0 : aArgs[0].Value <<= KeyModifier;
107 [ # # ][ # # ]: 0 : aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
108 [ # # ][ # # ]: 0 : aArgs[1].Value <<= m_aCurrentSelection;
109 : 0 : return aArgs;
110 : : }
111 : :
112 : : // ------------------------------------------------------------------
113 : :
114 : 0 : uno::Reference< awt::XWindow > SAL_CALL ToggleButtonToolbarController::createPopupWindow()
115 : : throw (::com::sun::star::uno::RuntimeException)
116 : : {
117 : 0 : uno::Reference< awt::XWindow > xWindow;
118 : :
119 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
120 [ # # ][ # # ]: 0 : if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
121 : : ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
122 : : {
123 : : // create popup menu
124 [ # # ]: 0 : PopupMenu aPopup;
125 : 0 : const sal_uInt32 nCount = m_aDropdownMenuList.size();
126 [ # # ]: 0 : for ( sal_uInt32 i = 0; i < nCount; i++ )
127 : : {
128 : 0 : rtl::OUString aLabel( m_aDropdownMenuList[i] );
129 [ # # ][ # # ]: 0 : aPopup.InsertItem( sal_uInt16( i+1 ), aLabel );
[ # # ]
130 [ # # ]: 0 : if ( aLabel == m_aCurrentSelection )
131 [ # # ]: 0 : aPopup.CheckItem( sal_uInt16( i+1 ), sal_True );
132 : : else
133 [ # # ]: 0 : aPopup.CheckItem( sal_uInt16( i+1 ), sal_False );
134 : 0 : }
135 : :
136 [ # # ]: 0 : m_pToolbar->SetItemDown( m_nID, sal_True );
137 [ # # ]: 0 : aPopup.SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl ));
138 [ # # ][ # # ]: 0 : aPopup.Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID ));
139 [ # # ][ # # ]: 0 : m_pToolbar->SetItemDown( m_nID, sal_False );
140 : : }
141 : :
142 [ # # ]: 0 : return xWindow;
143 : : }
144 : :
145 : : // ------------------------------------------------------------------
146 : :
147 : 0 : void ToggleButtonToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
148 : : {
149 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
150 : :
151 [ # # ][ # # ]: 0 : if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
152 : : ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
153 : : {
154 [ # # ]: 0 : if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 ))
155 : : {
156 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
157 : : {
158 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 ))
159 : : {
160 [ # # ]: 0 : Sequence< ::rtl::OUString > aList;
161 : 0 : m_aDropdownMenuList.clear();
162 : :
163 [ # # ]: 0 : rControlCommand.Arguments[i].Value >>= aList;
164 [ # # ]: 0 : for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
165 [ # # ][ # # ]: 0 : m_aDropdownMenuList.push_back( aList[j] );
166 : :
167 : : // send notification
168 [ # # ]: 0 : uno::Sequence< beans::NamedValue > aInfo( 1 );
169 [ # # ][ # # ]: 0 : aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ));
170 [ # # ][ # # ]: 0 : aInfo[0].Value <<= aList;
171 : : addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )),
172 : : getDispatchFromCommand( m_aCommandURL ),
173 [ # # ][ # # ]: 0 : aInfo );
[ # # ]
174 : :
175 [ # # ][ # # ]: 0 : break;
176 : : }
177 : : }
178 : : }
179 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "CheckItemPos", 12 ))
180 : : {
181 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
182 : : {
183 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
184 : : {
185 : 0 : sal_Int32 nPos( -1 );
186 : :
187 : 0 : rControlCommand.Arguments[i].Value >>= nPos;
188 [ # # ]: 0 : if ( nPos >= 0 &&
[ # # # # ]
189 : 0 : ( sal::static_int_cast< sal_uInt32 >(nPos)
190 : 0 : < m_aDropdownMenuList.size() ) )
191 : : {
192 : 0 : m_aCurrentSelection = m_aDropdownMenuList[nPos];
193 : :
194 : : // send notification
195 [ # # ]: 0 : uno::Sequence< beans::NamedValue > aInfo( 1 );
196 [ # # ][ # # ]: 0 : aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ItemChecked" ));
197 [ # # ][ # # ]: 0 : aInfo[0].Value <<= nPos;
198 : : addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" )),
199 : : getDispatchFromCommand( m_aCommandURL ),
200 [ # # ][ # # ]: 0 : aInfo );
[ # # ][ # # ]
201 : : }
202 : : break;
203 : : }
204 : : }
205 : : }
206 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 ))
207 : : {
208 : 0 : rtl::OUString aText;
209 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
210 : : {
211 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
212 : : {
213 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aText )
214 [ # # ]: 0 : m_aDropdownMenuList.push_back( aText );
215 : 0 : break;
216 : : }
217 : 0 : }
218 : : }
219 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 ))
220 : : {
221 : 0 : sal_Int32 nPos( COMBOBOX_APPEND );
222 : 0 : sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
223 : 0 : rtl::OUString aText;
224 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
225 : : {
226 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
227 : : {
228 : 0 : sal_Int32 nTmpPos = 0;
229 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
230 : : {
231 [ # # ][ # # ]: 0 : if (( nTmpPos >= 0 ) && ( nTmpPos < sal_Int32( nSize )))
232 : 0 : nPos = nTmpPos;
233 : : }
234 : : }
235 [ # # ]: 0 : else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
236 : 0 : rControlCommand.Arguments[i].Value >>= aText;
237 : : }
238 : :
239 : 0 : std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin();
240 : 0 : aIter += nPos;
241 [ # # ]: 0 : m_aDropdownMenuList.insert( aIter, aText );
242 : : }
243 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 ))
244 : : {
245 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
246 : : {
247 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
248 : : {
249 : 0 : sal_Int32 nPos( -1 );
250 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= nPos )
251 : : {
252 [ # # ]: 0 : if ( nPos < sal_Int32( m_aDropdownMenuList.size() ))
253 : : {
254 : 0 : std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin();
255 : 0 : aIter += nPos;
256 [ # # ]: 0 : m_aDropdownMenuList.erase( aIter );
257 : : }
258 : : }
259 : : break;
260 : : }
261 : : }
262 : : }
263 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 ))
264 : : {
265 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
266 : : {
267 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
268 : : {
269 : 0 : rtl::OUString aText;
270 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aText )
271 : : {
272 : 0 : sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
273 [ # # ]: 0 : for ( sal_Int32 j = 0; j < nSize; j++ )
274 : : {
275 [ # # ]: 0 : if ( m_aDropdownMenuList[j] == aText )
276 : : {
277 : 0 : std::vector< ::rtl::OUString >::iterator aIter = m_aDropdownMenuList.begin();
278 : 0 : aIter += j;
279 [ # # ]: 0 : m_aDropdownMenuList.erase( aIter );
280 : : break;
281 : : }
282 : : }
283 : : }
284 : 0 : break;
285 : : }
286 : : }
287 : : }
288 [ # # ]: 0 : }
289 : 0 : }
290 : :
291 : 0 : IMPL_LINK( ToggleButtonToolbarController, MenuSelectHdl, Menu *, pMenu )
292 : : {
293 [ # # ]: 0 : SolarMutexGuard aGuard;
294 : :
295 [ # # ]: 0 : sal_uInt16 nItemId = pMenu->GetCurItemId();
296 [ # # ][ # # ]: 0 : if ( nItemId > 0 && nItemId <= m_aDropdownMenuList.size() )
[ # # ]
297 : : {
298 : 0 : m_aCurrentSelection = m_aDropdownMenuList[nItemId-1];
299 : :
300 [ # # ]: 0 : execute( 0 );
301 : : }
302 [ # # ]: 0 : return 0;
303 : : }
304 : :
305 : : } // namespace
306 : :
307 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|