fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / togglebuttontoolbarcontroller.cxx
blob3ee98ab91f247a2c6b92bdc91bb3de9e1f6e292c
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/togglebuttontoolbarcontroller.hxx"
22 #include <framework/addonsoptions.hxx>
24 #include <com/sun/star/util/XURLTransformer.hpp>
25 #include <com/sun/star/frame/XDispatchProvider.hpp>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/frame/XControlNotificationListener.hpp>
28 #include <com/sun/star/util/XMacroExpander.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <rtl/uri.hxx>
33 #include <osl/mutex.hxx>
34 #include <comphelper/processfactory.hxx>
35 #include <unotools/ucbstreamhelper.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vcl/mnemonic.hxx>
38 #include <vcl/window.hxx>
39 #include <vcl/graph.hxx>
40 #include <vcl/bitmap.hxx>
41 #include <vcl/graphicfilter.hxx>
42 #include <vcl/toolbox.hxx>
43 #include <svtools/miscopt.hxx>
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::awt;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::beans;
49 using namespace ::com::sun::star::lang;
50 using namespace ::com::sun::star::frame;
51 using namespace ::com::sun::star::util;
53 namespace framework
56 ToggleButtonToolbarController::ToggleButtonToolbarController(
57 const Reference< XComponentContext >& rxContext,
58 const Reference< XFrame >& rFrame,
59 ToolBox* pToolbar,
60 sal_uInt16 nID,
61 Style eStyle,
62 const OUString& aCommand ) :
63 ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand ),
64 m_eStyle( eStyle )
66 if ( eStyle == STYLE_DROPDOWNBUTTON )
67 m_pToolbar->SetItemBits( m_nID, ToolBoxItemBits::DROPDOWNONLY | m_pToolbar->GetItemBits( m_nID ) );
68 else if ( eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )
69 m_pToolbar->SetItemBits( m_nID, ToolBoxItemBits::DROPDOWN | m_pToolbar->GetItemBits( m_nID ) );
72 ToggleButtonToolbarController::~ToggleButtonToolbarController()
76 void SAL_CALL ToggleButtonToolbarController::dispose()
77 throw ( RuntimeException, std::exception )
79 SolarMutexGuard aSolarMutexGuard;
80 ComplexToolbarController::dispose();
83 Sequence<PropertyValue> ToggleButtonToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
85 Sequence<PropertyValue> aArgs( 2 );
87 // Add key modifier to argument list
88 aArgs[0].Name = "KeyModifier";
89 aArgs[0].Value <<= KeyModifier;
90 aArgs[1].Name = "Text";
91 aArgs[1].Value <<= m_aCurrentSelection;
92 return aArgs;
95 uno::Reference< awt::XWindow > SAL_CALL ToggleButtonToolbarController::createPopupWindow()
96 throw (::com::sun::star::uno::RuntimeException, std::exception)
98 uno::Reference< awt::XWindow > xWindow;
100 SolarMutexGuard aSolarMutexGuard;
101 if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
102 ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
104 // create popup menu
105 ::PopupMenu aPopup;
106 const sal_uInt32 nCount = m_aDropdownMenuList.size();
107 for ( sal_uInt32 i = 0; i < nCount; i++ )
109 OUString aLabel( m_aDropdownMenuList[i] );
110 aPopup.InsertItem( sal_uInt16( i+1 ), aLabel );
111 if ( aLabel == m_aCurrentSelection )
112 aPopup.CheckItem( sal_uInt16( i+1 ), true );
113 else
114 aPopup.CheckItem( sal_uInt16( i+1 ), false );
117 m_pToolbar->SetItemDown( m_nID, true );
118 aPopup.SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl ));
119 aPopup.Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID ));
120 m_pToolbar->SetItemDown( m_nID, false );
123 return xWindow;
126 void ToggleButtonToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
128 SolarMutexGuard aSolarMutexGuard;
130 if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
131 ( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
133 if ( rControlCommand.Command == "SetList" )
135 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
137 if ( rControlCommand.Arguments[i].Name == "List" )
139 Sequence< OUString > aList;
140 m_aDropdownMenuList.clear();
142 rControlCommand.Arguments[i].Value >>= aList;
143 for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
144 m_aDropdownMenuList.push_back( aList[j] );
146 // send notification
147 uno::Sequence< beans::NamedValue > aInfo( 1 );
148 aInfo[0].Name = "List";
149 aInfo[0].Value <<= aList;
150 addNotifyInfo( OUString( "ListChanged" ),
151 getDispatchFromCommand( m_aCommandURL ),
152 aInfo );
154 break;
158 else if ( rControlCommand.Command == "CheckItemPos" )
160 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
162 if ( rControlCommand.Arguments[i].Name == "Pos" )
164 sal_Int32 nPos( -1 );
166 rControlCommand.Arguments[i].Value >>= nPos;
167 if ( nPos >= 0 &&
168 ( sal::static_int_cast< sal_uInt32 >(nPos)
169 < m_aDropdownMenuList.size() ) )
171 m_aCurrentSelection = m_aDropdownMenuList[nPos];
173 // send notification
174 uno::Sequence< beans::NamedValue > aInfo( 1 );
175 aInfo[0].Name = "ItemChecked";
176 aInfo[0].Value <<= nPos;
177 addNotifyInfo( OUString( "Pos" ),
178 getDispatchFromCommand( m_aCommandURL ),
179 aInfo );
181 break;
185 else if ( rControlCommand.Command == "AddEntry" )
187 OUString aText;
188 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
190 if ( rControlCommand.Arguments[i].Name == "Text" )
192 if ( rControlCommand.Arguments[i].Value >>= aText )
193 m_aDropdownMenuList.push_back( aText );
194 break;
198 else if ( rControlCommand.Command == "InsertEntry" )
200 sal_Int32 nPos( COMBOBOX_APPEND );
201 sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
202 OUString aText;
203 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
205 if ( rControlCommand.Arguments[i].Name == "Pos" )
207 sal_Int32 nTmpPos = 0;
208 if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
210 if (( nTmpPos >= 0 ) && ( nTmpPos < sal_Int32( nSize )))
211 nPos = nTmpPos;
214 else if ( rControlCommand.Arguments[i].Name == "Text" )
215 rControlCommand.Arguments[i].Value >>= aText;
218 std::vector< OUString >::iterator aIter = m_aDropdownMenuList.begin();
219 aIter += nPos;
220 m_aDropdownMenuList.insert( aIter, aText );
222 else if ( rControlCommand.Command == "RemoveEntryPos" )
224 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
226 if ( rControlCommand.Arguments[i].Name == "Pos" )
228 sal_Int32 nPos( -1 );
229 if ( rControlCommand.Arguments[i].Value >>= nPos )
231 if ( nPos < sal_Int32( m_aDropdownMenuList.size() ))
233 m_aDropdownMenuList.erase(m_aDropdownMenuList.begin() + nPos);
236 break;
240 else if ( rControlCommand.Command == "RemoveEntryText" )
242 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
244 if ( rControlCommand.Arguments[i].Name == "Text" )
246 OUString aText;
247 if ( rControlCommand.Arguments[i].Value >>= aText )
249 sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
250 for ( sal_Int32 j = 0; j < nSize; j++ )
252 if ( m_aDropdownMenuList[j] == aText )
254 m_aDropdownMenuList.erase(m_aDropdownMenuList.begin() + j);
255 break;
259 break;
266 IMPL_LINK( ToggleButtonToolbarController, MenuSelectHdl, Menu *, pMenu )
268 SolarMutexGuard aGuard;
270 sal_uInt16 nItemId = pMenu->GetCurItemId();
271 if ( nItemId > 0 && nItemId <= m_aDropdownMenuList.size() )
273 m_aCurrentSelection = m_aDropdownMenuList[nItemId-1];
275 execute( 0 );
277 return 0;
280 } // namespace
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */