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/dropdownboxtoolbarcontroller.hxx"
31 : :
32 : : #include "uielement/toolbar.hxx"
33 : :
34 : : #include <com/sun/star/util/XURLTransformer.hpp>
35 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
36 : : #include <com/sun/star/beans/PropertyValue.hpp>
37 : : #include <com/sun/star/frame/status/ItemStatus.hpp>
38 : : #include <com/sun/star/frame/status/ItemState.hpp>
39 : : #include <com/sun/star/frame/status/Visibility.hpp>
40 : : #include <com/sun/star/frame/XControlNotificationListener.hpp>
41 : :
42 : : #include <svtools/toolboxcontroller.hxx>
43 : : #include <osl/mutex.hxx>
44 : : #include <vcl/svapp.hxx>
45 : : #include <vcl/mnemonic.hxx>
46 : :
47 : : using namespace ::com::sun::star;
48 : : using namespace ::com::sun::star::awt;
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::frame::status;
54 : : using namespace ::com::sun::star::util;
55 : :
56 : : namespace framework
57 : : {
58 : :
59 : : // ------------------------------------------------------------------
60 : :
61 : : // Wrapper class to notify controller about events from ListBox.
62 : : // Unfortunaltly the events are notifed through virtual methods instead
63 : : // of Listeners.
64 : :
65 : : class ListBoxControl : public ListBox
66 : : {
67 : : public:
68 : : ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener );
69 : : virtual ~ListBoxControl();
70 : :
71 : : virtual void Select();
72 : : virtual void DoubleClick();
73 : : virtual void GetFocus();
74 : : virtual void LoseFocus();
75 : : virtual long PreNotify( NotifyEvent& rNEvt );
76 : :
77 : : private:
78 : : IListBoxListener* m_pListBoxListener;
79 : : };
80 : :
81 : 0 : ListBoxControl::ListBoxControl( Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener ) :
82 : : ListBox( pParent, nStyle )
83 : 0 : , m_pListBoxListener( pListBoxListener )
84 : : {
85 : 0 : }
86 : :
87 : 0 : ListBoxControl::~ListBoxControl()
88 : : {
89 : 0 : m_pListBoxListener = 0;
90 [ # # ]: 0 : }
91 : :
92 : 0 : void ListBoxControl::Select()
93 : : {
94 : 0 : ListBox::Select();
95 [ # # ]: 0 : if ( m_pListBoxListener )
96 : 0 : m_pListBoxListener->Select();
97 : 0 : }
98 : :
99 : 0 : void ListBoxControl::DoubleClick()
100 : : {
101 : 0 : ListBox::DoubleClick();
102 [ # # ]: 0 : if ( m_pListBoxListener )
103 : 0 : m_pListBoxListener->DoubleClick();
104 : 0 : }
105 : :
106 : 0 : void ListBoxControl::GetFocus()
107 : : {
108 : 0 : ListBox::GetFocus();
109 [ # # ]: 0 : if ( m_pListBoxListener )
110 : 0 : m_pListBoxListener->GetFocus();
111 : 0 : }
112 : :
113 : 0 : void ListBoxControl::LoseFocus()
114 : : {
115 : 0 : ListBox::LoseFocus();
116 [ # # ]: 0 : if ( m_pListBoxListener )
117 : 0 : m_pListBoxListener->LoseFocus();
118 : 0 : }
119 : :
120 : 0 : long ListBoxControl::PreNotify( NotifyEvent& rNEvt )
121 : : {
122 : 0 : long nRet( 0 );
123 [ # # ]: 0 : if ( m_pListBoxListener )
124 : 0 : nRet = m_pListBoxListener->PreNotify( rNEvt );
125 [ # # ]: 0 : if ( nRet == 0 )
126 : 0 : nRet = ListBox::PreNotify( rNEvt );
127 : :
128 : 0 : return nRet;
129 : : }
130 : :
131 : : // ------------------------------------------------------------------
132 : :
133 : 0 : DropdownToolbarController::DropdownToolbarController(
134 : : const Reference< XMultiServiceFactory >& rServiceManager,
135 : : const Reference< XFrame >& rFrame,
136 : : ToolBox* pToolbar,
137 : : sal_uInt16 nID,
138 : : sal_Int32 nWidth,
139 : : const ::rtl::OUString& aCommand ) :
140 : : ComplexToolbarController( rServiceManager, rFrame, pToolbar, nID, aCommand )
141 [ # # ]: 0 : , m_pListBoxControl( 0 )
142 : : {
143 [ # # ][ # # ]: 0 : m_pListBoxControl = new ListBoxControl( m_pToolbar, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER, this );
144 [ # # ]: 0 : if ( nWidth == 0 )
145 : 0 : nWidth = 100;
146 : :
147 : : // default dropdown size
148 : 0 : ::Size aLogicalSize( 0, 160 );
149 [ # # ][ # # ]: 0 : ::Size aPixelSize = m_pListBoxControl->LogicToPixel( aLogicalSize, MAP_APPFONT );
[ # # ]
150 : :
151 [ # # ]: 0 : m_pListBoxControl->SetSizePixel( ::Size( nWidth, aPixelSize.Height() ));
152 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, m_pListBoxControl );
153 [ # # ]: 0 : m_pListBoxControl->SetDropDownLineCount( 5 );
154 : 0 : }
155 : :
156 : : // ------------------------------------------------------------------
157 : :
158 [ # # ]: 0 : DropdownToolbarController::~DropdownToolbarController()
159 : : {
160 [ # # ]: 0 : }
161 : :
162 : : // ------------------------------------------------------------------
163 : :
164 : 0 : void SAL_CALL DropdownToolbarController::dispose()
165 : : throw ( RuntimeException )
166 : : {
167 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
168 : :
169 [ # # ]: 0 : m_pToolbar->SetItemWindow( m_nID, 0 );
170 [ # # ][ # # ]: 0 : delete m_pListBoxControl;
171 : :
172 [ # # ]: 0 : ComplexToolbarController::dispose();
173 : :
174 [ # # ]: 0 : m_pListBoxControl = 0;
175 : 0 : }
176 : :
177 : : // ------------------------------------------------------------------
178 : 0 : Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
179 : : {
180 [ # # ]: 0 : Sequence<PropertyValue> aArgs( 2 );
181 [ # # ][ # # ]: 0 : ::rtl::OUString aSelectedText = m_pListBoxControl->GetSelectEntry();
[ # # ]
182 : :
183 : : // Add key modifier to argument list
184 [ # # ][ # # ]: 0 : aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
185 [ # # ][ # # ]: 0 : aArgs[0].Value <<= KeyModifier;
186 [ # # ][ # # ]: 0 : aArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ));
187 [ # # ][ # # ]: 0 : aArgs[1].Value <<= aSelectedText;
188 : 0 : return aArgs;
189 : : }
190 : :
191 : : // ------------------------------------------------------------------
192 : :
193 : 0 : void DropdownToolbarController::Select()
194 : : {
195 [ # # ]: 0 : if ( m_pListBoxControl->GetEntryCount() > 0 )
196 : : {
197 [ # # ]: 0 : Window::PointerState aState = m_pListBoxControl->GetPointerState();
198 : :
199 : 0 : sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODTYPE );
200 [ # # ]: 0 : execute( nKeyModifier );
201 : : }
202 : 0 : }
203 : :
204 : 0 : void DropdownToolbarController::DoubleClick()
205 : : {
206 : 0 : }
207 : :
208 : 0 : void DropdownToolbarController::GetFocus()
209 : : {
210 : 0 : notifyFocusGet();
211 : 0 : }
212 : :
213 : 0 : void DropdownToolbarController::LoseFocus()
214 : : {
215 : 0 : notifyFocusLost();
216 : 0 : }
217 : :
218 : 0 : long DropdownToolbarController::PreNotify( NotifyEvent& /*rNEvt*/ )
219 : : {
220 : 0 : return 0;
221 : : }
222 : :
223 : : // --------------------------------------------------------
224 : :
225 : 0 : void DropdownToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
226 : : {
227 [ # # ]: 0 : if ( rControlCommand.Command.equalsAsciiL( "SetList", 7 ))
228 : : {
229 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
230 : : {
231 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "List", 4 ))
232 : : {
233 [ # # ]: 0 : Sequence< ::rtl::OUString > aList;
234 [ # # ]: 0 : m_pListBoxControl->Clear();
235 : :
236 [ # # ]: 0 : rControlCommand.Arguments[i].Value >>= aList;
237 [ # # ]: 0 : for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
238 [ # # ][ # # ]: 0 : m_pListBoxControl->InsertEntry( aList[j] );
[ # # ][ # # ]
239 : :
240 [ # # ]: 0 : m_pListBoxControl->SelectEntryPos( 0 );
241 : :
242 : : // send notification
243 [ # # ]: 0 : uno::Sequence< beans::NamedValue > aInfo( 1 );
244 [ # # ][ # # ]: 0 : aInfo[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "List" ));
245 [ # # ][ # # ]: 0 : aInfo[0].Value <<= aList;
246 : : addNotifyInfo( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ListChanged" )),
247 : : getDispatchFromCommand( m_aCommandURL ),
248 [ # # ][ # # ]: 0 : aInfo );
[ # # ]
249 : :
250 [ # # ][ # # ]: 0 : break;
251 : : }
252 : : }
253 : : }
254 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "AddEntry", 8 ))
255 : : {
256 : 0 : sal_uInt16 nPos( LISTBOX_APPEND );
257 : 0 : rtl::OUString aText;
258 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
259 : : {
260 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
261 : : {
262 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aText )
263 [ # # ][ # # ]: 0 : m_pListBoxControl->InsertEntry( aText, nPos );
[ # # ]
264 : 0 : break;
265 : : }
266 : 0 : }
267 : : }
268 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "InsertEntry", 11 ))
269 : : {
270 : 0 : sal_uInt16 nPos( LISTBOX_APPEND );
271 : 0 : rtl::OUString aText;
272 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
273 : : {
274 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
275 : : {
276 : 0 : sal_Int32 nTmpPos = 0;
277 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
278 : : {
279 [ # # ][ # # ]: 0 : if (( nTmpPos >= 0 ) &&
[ # # ]
280 [ # # ]: 0 : ( nTmpPos < sal_Int32( m_pListBoxControl->GetEntryCount() )))
281 : 0 : nPos = sal_uInt16( nTmpPos );
282 : : }
283 : : }
284 [ # # ]: 0 : else if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
285 : 0 : rControlCommand.Arguments[i].Value >>= aText;
286 : : }
287 : :
288 [ # # ][ # # ]: 0 : m_pListBoxControl->InsertEntry( aText, nPos );
[ # # ]
289 : : }
290 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryPos", 14 ))
291 : : {
292 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
293 : : {
294 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Pos", 3 ))
295 : : {
296 : 0 : sal_Int32 nPos( -1 );
297 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= nPos )
298 : : {
299 [ # # ][ # # ]: 0 : if ( nPos < sal_Int32( m_pListBoxControl->GetEntryCount() ))
300 [ # # ]: 0 : m_pListBoxControl->RemoveEntry( sal_uInt16( nPos ));
301 : : }
302 : : break;
303 : : }
304 : : }
305 : : }
306 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "RemoveEntryText", 15 ))
307 : : {
308 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
309 : : {
310 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Text", 4 ))
311 : : {
312 : 0 : rtl::OUString aText;
313 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Value >>= aText )
314 [ # # ][ # # ]: 0 : m_pListBoxControl->RemoveEntry( aText );
[ # # ]
315 : 0 : break;
316 : : }
317 : : }
318 : : }
319 [ # # ]: 0 : else if ( rControlCommand.Command.equalsAsciiL( "SetDropDownLines", 16 ))
320 : : {
321 [ # # ]: 0 : for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
322 : : {
323 [ # # ]: 0 : if ( rControlCommand.Arguments[i].Name.equalsAsciiL( "Lines", 5 ))
324 : : {
325 : 0 : sal_Int32 nValue( 5 );
326 : 0 : rControlCommand.Arguments[i].Value >>= nValue;
327 [ # # ]: 0 : m_pListBoxControl->SetDropDownLineCount( sal_uInt16( nValue ));
328 : : break;
329 : : }
330 : : }
331 : : }
332 : 0 : }
333 : :
334 : : } // namespace
335 : :
336 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|