1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "uielement/togglebuttontoolbarcontroller.hxx"
#include <framework/addonsoptions.hxx>
#include <com/sun/star/util/XURLTransformer.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/frame/XControlNotificationListener.hpp>
#include <com/sun/star/util/XMacroExpander.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <rtl/uri.hxx>
#include <osl/mutex.hxx>
#include <comphelper/processfactory.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <vcl/svapp.hxx>
#include <vcl/mnemonic.hxx>
#include <vcl/window.hxx>
#include <vcl/graph.hxx>
#include <vcl/bitmap.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/toolbox.hxx>
#include <svtools/miscopt.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::util;
namespace framework
{
ToggleButtonToolbarController::ToggleButtonToolbarController(
const Reference< XComponentContext >& rxContext,
const Reference< XFrame >& rFrame,
ToolBox* pToolbar,
sal_uInt16 nID,
Style eStyle,
const OUString& aCommand ) :
ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand ),
m_eStyle( eStyle )
{
if ( eStyle == STYLE_DROPDOWNBUTTON )
m_pToolbar->SetItemBits( m_nID, ToolBoxItemBits::DROPDOWNONLY | m_pToolbar->GetItemBits( m_nID ) );
else if ( eStyle == STYLE_TOGGLE_DROPDOWNBUTTON )
m_pToolbar->SetItemBits( m_nID, ToolBoxItemBits::DROPDOWN | m_pToolbar->GetItemBits( m_nID ) );
}
ToggleButtonToolbarController::~ToggleButtonToolbarController()
{
}
void SAL_CALL ToggleButtonToolbarController::dispose()
throw ( RuntimeException, std::exception )
{
SolarMutexGuard aSolarMutexGuard;
ComplexToolbarController::dispose();
}
Sequence<PropertyValue> ToggleButtonToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
{
Sequence<PropertyValue> aArgs( 2 );
// Add key modifier to argument list
aArgs[0].Name = "KeyModifier";
aArgs[0].Value <<= KeyModifier;
aArgs[1].Name = "Text";
aArgs[1].Value <<= m_aCurrentSelection;
return aArgs;
}
uno::Reference< awt::XWindow > SAL_CALL ToggleButtonToolbarController::createPopupWindow()
throw (css::uno::RuntimeException, std::exception)
{
uno::Reference< awt::XWindow > xWindow;
SolarMutexGuard aSolarMutexGuard;
if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
{
// create popup menu
ScopedVclPtrInstance<::PopupMenu> aPopup;
const sal_uInt32 nCount = m_aDropdownMenuList.size();
for ( sal_uInt32 i = 0; i < nCount; i++ )
{
OUString aLabel( m_aDropdownMenuList[i] );
aPopup->InsertItem( sal_uInt16( i+1 ), aLabel );
if ( aLabel == m_aCurrentSelection )
aPopup->CheckItem( sal_uInt16( i+1 ) );
else
aPopup->CheckItem( sal_uInt16( i+1 ), false );
}
m_pToolbar->SetItemDown( m_nID, true );
aPopup->SetSelectHdl( LINK( this, ToggleButtonToolbarController, MenuSelectHdl ));
aPopup->Execute( m_pToolbar, m_pToolbar->GetItemRect( m_nID ));
m_pToolbar->SetItemDown( m_nID, false );
}
return xWindow;
}
void ToggleButtonToolbarController::executeControlCommand( const css::frame::ControlCommand& rControlCommand )
{
SolarMutexGuard aSolarMutexGuard;
if (( m_eStyle == STYLE_DROPDOWNBUTTON ) ||
( m_eStyle == STYLE_TOGGLE_DROPDOWNBUTTON ))
{
if ( rControlCommand.Command == "SetList" )
{
for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
{
if ( rControlCommand.Arguments[i].Name == "List" )
{
Sequence< OUString > aList;
m_aDropdownMenuList.clear();
rControlCommand.Arguments[i].Value >>= aList;
for ( sal_Int32 j = 0; j < aList.getLength(); j++ )
m_aDropdownMenuList.push_back( aList[j] );
// send notification
uno::Sequence< beans::NamedValue > aInfo { { "List", css::uno::makeAny(aList) } };
addNotifyInfo( "ListChanged",
getDispatchFromCommand( m_aCommandURL ),
aInfo );
break;
}
}
}
else if ( rControlCommand.Command == "CheckItemPos" )
{
for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
{
if ( rControlCommand.Arguments[i].Name == "Pos" )
{
sal_Int32 nPos( -1 );
rControlCommand.Arguments[i].Value >>= nPos;
if ( nPos >= 0 &&
( sal::static_int_cast< sal_uInt32 >(nPos)
< m_aDropdownMenuList.size() ) )
{
m_aCurrentSelection = m_aDropdownMenuList[nPos];
// send notification
uno::Sequence< beans::NamedValue > aInfo { { "ItemChecked", css::uno::makeAny(nPos) } };
addNotifyInfo( "Pos",
getDispatchFromCommand( m_aCommandURL ),
aInfo );
}
break;
}
}
}
else if ( rControlCommand.Command == "AddEntry" )
{
OUString aText;
for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
{
if ( rControlCommand.Arguments[i].Name == "Text" )
{
if ( rControlCommand.Arguments[i].Value >>= aText )
m_aDropdownMenuList.push_back( aText );
break;
}
}
}
else if ( rControlCommand.Command == "InsertEntry" )
{
sal_Int32 nPos( COMBOBOX_APPEND );
sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
OUString aText;
for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
{
if ( rControlCommand.Arguments[i].Name == "Pos" )
{
sal_Int32 nTmpPos = 0;
if ( rControlCommand.Arguments[i].Value >>= nTmpPos )
{
if (( nTmpPos >= 0 ) && ( nTmpPos < sal_Int32( nSize )))
nPos = nTmpPos;
}
}
else if ( rControlCommand.Arguments[i].Name == "Text" )
rControlCommand.Arguments[i].Value >>= aText;
}
std::vector< OUString >::iterator aIter = m_aDropdownMenuList.begin();
aIter += nPos;
m_aDropdownMenuList.insert( aIter, aText );
}
else if ( rControlCommand.Command == "RemoveEntryPos" )
{
for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
{
if ( rControlCommand.Arguments[i].Name == "Pos" )
{
sal_Int32 nPos( -1 );
if ( rControlCommand.Arguments[i].Value >>= nPos )
{
if ( nPos < sal_Int32( m_aDropdownMenuList.size() ))
{
m_aDropdownMenuList.erase(m_aDropdownMenuList.begin() + nPos);
}
}
break;
}
}
}
else if ( rControlCommand.Command == "RemoveEntryText" )
{
for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
{
if ( rControlCommand.Arguments[i].Name == "Text" )
{
OUString aText;
if ( rControlCommand.Arguments[i].Value >>= aText )
{
sal_Int32 nSize = sal_Int32( m_aDropdownMenuList.size() );
for ( sal_Int32 j = 0; j < nSize; j++ )
{
if ( m_aDropdownMenuList[j] == aText )
{
m_aDropdownMenuList.erase(m_aDropdownMenuList.begin() + j);
break;
}
}
}
break;
}
}
}
}
}
IMPL_LINK( ToggleButtonToolbarController, MenuSelectHdl, Menu *, pMenu, bool )
{
SolarMutexGuard aGuard;
sal_uInt16 nItemId = pMenu->GetCurItemId();
if ( nItemId > 0 && nItemId <= m_aDropdownMenuList.size() )
{
m_aCurrentSelection = m_aDropdownMenuList[nItemId-1];
execute( 0 );
}
return false;
}
} // namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|