fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / dropdownboxtoolbarcontroller.cxx
blob7d00fbcd70d97cd371400ddc8001cfe1092c90ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "uielement/dropdownboxtoolbarcontroller.hxx"
22 #include <com/sun/star/util/XURLTransformer.hpp>
23 #include <com/sun/star/frame/XDispatchProvider.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/frame/status/ItemStatus.hpp>
26 #include <com/sun/star/frame/status/ItemState.hpp>
27 #include <com/sun/star/frame/status/Visibility.hpp>
28 #include <com/sun/star/frame/XControlNotificationListener.hpp>
30 #include <svtools/toolboxcontroller.hxx>
31 #include <osl/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include <vcl/mnemonic.hxx>
34 #include <vcl/toolbox.hxx>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::awt;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::frame;
42 using namespace ::com::sun::star::frame::status;
43 using namespace ::com::sun::star::util;
45 namespace framework
48 // Wrapper class to notify controller about events from ListBox.
49 // Unfortunaltly the events are notifed through virtual methods instead
50 // of Listeners.
52 class ListBoxControl : public ListBox
54 public:
55 ListBoxControl( vcl::Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener );
56 virtual ~ListBoxControl();
57 virtual void dispose() SAL_OVERRIDE;
59 virtual void Select() SAL_OVERRIDE;
60 virtual void DoubleClick() SAL_OVERRIDE;
61 virtual void GetFocus() SAL_OVERRIDE;
62 virtual void LoseFocus() SAL_OVERRIDE;
63 virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
65 private:
66 IListBoxListener* m_pListBoxListener;
69 ListBoxControl::ListBoxControl( vcl::Window* pParent, WinBits nStyle, IListBoxListener* pListBoxListener ) :
70 ListBox( pParent, nStyle )
71 , m_pListBoxListener( pListBoxListener )
75 ListBoxControl::~ListBoxControl()
77 disposeOnce();
80 void ListBoxControl::dispose()
82 m_pListBoxListener = 0;
83 ListBox::dispose();
86 void ListBoxControl::Select()
88 ListBox::Select();
89 if ( m_pListBoxListener )
90 m_pListBoxListener->Select();
93 void ListBoxControl::DoubleClick()
95 ListBox::DoubleClick();
96 if ( m_pListBoxListener )
97 m_pListBoxListener->DoubleClick();
100 void ListBoxControl::GetFocus()
102 ListBox::GetFocus();
103 if ( m_pListBoxListener )
104 m_pListBoxListener->GetFocus();
107 void ListBoxControl::LoseFocus()
109 ListBox::LoseFocus();
110 if ( m_pListBoxListener )
111 m_pListBoxListener->LoseFocus();
114 bool ListBoxControl::PreNotify( NotifyEvent& rNEvt )
116 bool nRet = false;
117 if ( m_pListBoxListener )
118 nRet = m_pListBoxListener->PreNotify( rNEvt );
119 if ( !nRet )
120 nRet = ListBox::PreNotify( rNEvt );
122 return nRet;
125 DropdownToolbarController::DropdownToolbarController(
126 const Reference< XComponentContext >& rxContext,
127 const Reference< XFrame >& rFrame,
128 ToolBox* pToolbar,
129 sal_uInt16 nID,
130 sal_Int32 nWidth,
131 const OUString& aCommand ) :
132 ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
133 , m_pListBoxControl( 0 )
135 m_pListBoxControl = VclPtr<ListBoxControl>::Create( m_pToolbar, WB_DROPDOWN|WB_AUTOHSCROLL|WB_BORDER, this );
136 if ( nWidth == 0 )
137 nWidth = 100;
139 // default dropdown size
140 ::Size aLogicalSize( 0, 160 );
141 ::Size aPixelSize = m_pListBoxControl->LogicToPixel( aLogicalSize, MAP_APPFONT );
143 m_pListBoxControl->SetSizePixel( ::Size( nWidth, aPixelSize.Height() ));
144 m_pToolbar->SetItemWindow( m_nID, m_pListBoxControl );
145 m_pListBoxControl->SetDropDownLineCount( 5 );
148 DropdownToolbarController::~DropdownToolbarController()
152 void SAL_CALL DropdownToolbarController::dispose()
153 throw ( RuntimeException, std::exception )
155 SolarMutexGuard aSolarMutexGuard;
157 m_pToolbar->SetItemWindow( m_nID, 0 );
158 m_pListBoxControl.disposeAndClear();
160 ComplexToolbarController::dispose();
163 Sequence<PropertyValue> DropdownToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
165 Sequence<PropertyValue> aArgs( 2 );
166 OUString aSelectedText = m_pListBoxControl->GetSelectEntry();
168 // Add key modifier to argument list
169 aArgs[0].Name = "KeyModifier";
170 aArgs[0].Value <<= KeyModifier;
171 aArgs[1].Name = "Text";
172 aArgs[1].Value <<= aSelectedText;
173 return aArgs;
176 void DropdownToolbarController::Select()
178 if ( m_pListBoxControl->GetEntryCount() > 0 )
180 vcl::Window::PointerState aState = m_pListBoxControl->GetPointerState();
182 sal_uInt16 nKeyModifier = sal_uInt16( aState.mnState & KEY_MODIFIERS_MASK );
183 execute( nKeyModifier );
187 void DropdownToolbarController::DoubleClick()
191 void DropdownToolbarController::GetFocus()
193 notifyFocusGet();
196 void DropdownToolbarController::LoseFocus()
198 notifyFocusLost();
201 bool DropdownToolbarController::PreNotify( NotifyEvent& /*rNEvt*/ )
203 return false;
206 void DropdownToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
208 if ( rControlCommand.Command == "SetList" )
210 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
212 if ( rControlCommand.Arguments[i].Name == "List" )
214 Sequence< OUString > aList;
215 m_pListBoxControl->Clear();
217 rControlCommand.Arguments[i].Value >>= aList;
218 for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
219 m_pListBoxControl->InsertEntry( aList[j] );
221 m_pListBoxControl->SelectEntryPos( 0 );
223 // send notification
224 uno::Sequence< beans::NamedValue > aInfo( 1 );
225 aInfo[0].Name = "List";
226 aInfo[0].Value <<= aList;
227 addNotifyInfo( OUString( "ListChanged" ),
228 getDispatchFromCommand( m_aCommandURL ),
229 aInfo );
231 break;
235 else if ( rControlCommand.Command == "AddEntry" )
237 sal_Int32 nPos( LISTBOX_APPEND );
238 OUString aText;
239 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
241 if ( rControlCommand.Arguments[i].Name == "Text" )
243 if ( rControlCommand.Arguments[i].Value >>= aText )
244 m_pListBoxControl->InsertEntry( aText, nPos );
245 break;
249 else if ( rControlCommand.Command == "InsertEntry" )
251 sal_Int32 nPos( LISTBOX_APPEND );
252 OUString aText;
253 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
255 if ( rControlCommand.Arguments[i].Name == "Pos" )
257 sal_Int32 nTmpPos = 0;
258 if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
260 if (( nTmpPos >= 0 ) &&
261 ( nTmpPos < sal_Int32( m_pListBoxControl->GetEntryCount() )))
262 nPos = nTmpPos;
265 else if ( rControlCommand.Arguments[i].Name == "Text" )
266 rControlCommand.Arguments[i].Value >>= aText;
269 m_pListBoxControl->InsertEntry( aText, nPos );
271 else if ( rControlCommand.Command == "RemoveEntryPos" )
273 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
275 if ( rControlCommand.Arguments[i].Name == "Pos" )
277 sal_Int32 nPos( -1 );
278 if ( rControlCommand.Arguments[i].Value >>= nPos )
280 if ( 0 <= nPos && nPos < sal_Int32( m_pListBoxControl->GetEntryCount() ))
281 m_pListBoxControl->RemoveEntry( nPos );
283 break;
287 else if ( rControlCommand.Command == "RemoveEntryText" )
289 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
291 if ( rControlCommand.Arguments[i].Name == "Text" )
293 OUString aText;
294 if ( rControlCommand.Arguments[i].Value >>= aText )
295 m_pListBoxControl->RemoveEntry( aText );
296 break;
300 else if ( rControlCommand.Command == "SetDropDownLines" )
302 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
304 if ( rControlCommand.Arguments[i].Name == "Lines" )
306 sal_Int32 nValue( 5 );
307 rControlCommand.Arguments[i].Value >>= nValue;
308 m_pListBoxControl->SetDropDownLineCount( sal_uInt16( nValue ));
309 break;
315 } // namespace
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */