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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_framework.hxx"
#include <uielement/addonstoolbarmanager.hxx>
#include <uielement/toolbarmerger.hxx>
//_________________________________________________________________________________________________________________
// my own includes
//_________________________________________________________________________________________________________________
#include <uielement/toolbar.hxx>
#include <uielement/generictoolbarcontroller.hxx>
#include <threadhelp/resetableguard.hxx>
#include "services.h"
#include <helper/imageproducer.hxx>
#include <classes/sfxhelperfunctions.hxx>
#include <classes/fwkresid.hxx>
#include <classes/resource.hrc>
#include <classes/addonsoptions.hxx>
#include <uielement/comboboxtoolbarcontroller.hxx>
#include <uielement/imagebuttontoolbarcontroller.hxx>
#include <uielement/togglebuttontoolbarcontroller.hxx>
#include <uielement/buttontoolbarcontroller.hxx>
#include <uielement/spinfieldtoolbarcontroller.hxx>
#include <uielement/edittoolbarcontroller.hxx>
#include <uielement/dropdownboxtoolbarcontroller.hxx>
#include <uielement/toolbarmerger.hxx>
//_________________________________________________________________________________________________________________
// interface includes
//_________________________________________________________________________________________________________________
#include <com/sun/star/ui/ItemType.hpp>
#include <com/sun/star/frame/XToolbarController.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/frame/XLayoutManager.hpp>
#include <com/sun/star/ui/DockingArea.hpp>
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
//_________________________________________________________________________________________________________________
// other includes
//_________________________________________________________________________________________________________________
#include <svtools/imgdef.hxx>
#include <svtools/toolboxcontroller.hxx>
#include <toolkit/unohlp.hxx>
#include <svtools/miscopt.hxx>
#include <vcl/svapp.hxx>
#include <vcl/menu.hxx>
#include <vcl/syswin.hxx>
#include <vcl/taskpanelist.hxx>
//_________________________________________________________________________________________________________________
// namespaces
//_________________________________________________________________________________________________________________
using namespace ::com::sun::star;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::ui;
namespace framework
{
static const char TOOLBOXITEM_SEPARATOR_STR[] = "private:separator";
static const USHORT TOOLBOXITEM_SEPARATOR_STR_LEN = sizeof( TOOLBOXITEM_SEPARATOR_STR )-1;
AddonsToolBarManager::AddonsToolBarManager( const Reference< XMultiServiceFactory >& rServiceManager,
const Reference< XFrame >& rFrame,
const rtl::OUString& rResourceName,
ToolBar* pToolBar ) :
ToolBarManager( rServiceManager, rFrame, rResourceName, pToolBar )
{
// Configuration data is retrieved from non-writable configuration layer. Therefor we
// must disable some menu entries.
m_bCanBeCustomized = sal_False;
m_pToolBar->SetMenuType( TOOLBOX_MENUTYPE_CLIPPEDITEMS );
m_pToolBar->SetSelectHdl( LINK( this, AddonsToolBarManager, Select) );
m_pToolBar->SetActivateHdl( LINK( this, AddonsToolBarManager, Activate) );
m_pToolBar->SetDeactivateHdl( LINK( this, AddonsToolBarManager, Deactivate) );
m_pToolBar->SetClickHdl( LINK( this, AddonsToolBarManager, Click ) );
m_pToolBar->SetDoubleClickHdl( LINK( this, AddonsToolBarManager, DoubleClick ) );
m_pToolBar->SetCommandHdl( LINK( this, AddonsToolBarManager, Command ) );
m_pToolBar->SetStateChangedHdl( LINK( this, AddonsToolBarManager, StateChanged ) );
m_pToolBar->SetDataChangedHdl( LINK( this, AddonsToolBarManager, DataChanged ) );
}
AddonsToolBarManager::~AddonsToolBarManager()
{
}
static sal_Bool IsCorrectContext( const ::rtl::OUString& rModuleIdentifier, const ::rtl::OUString& aContextList )
{
if ( aContextList.getLength() == 0 )
return sal_True;
if ( rModuleIdentifier.getLength() > 0 )
{
sal_Int32 nIndex = aContextList.indexOf( rModuleIdentifier );
return ( nIndex >= 0 );
}
return sal_False;
}
static Image RetrieveImage( Reference< com::sun::star::frame::XFrame >& rFrame,
const rtl::OUString& aImageId,
const rtl::OUString& aURL,
BOOL bBigImage )
{
Image aImage;
if ( aImageId.getLength() > 0 )
{
aImage = framework::AddonsOptions().GetImageFromURL( aImageId, bBigImage );
if ( !!aImage )
return aImage;
else
aImage = GetImageFromURL( rFrame, aImageId, bBigImage );
if ( !!aImage )
return aImage;
}
aImage = framework::AddonsOptions().GetImageFromURL( aURL, bBigImage );
if ( !aImage )
aImage = GetImageFromURL( rFrame, aImageId, bBigImage );
return aImage;
}
// XComponent
void SAL_CALL AddonsToolBarManager::dispose() throw( RuntimeException )
{
Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
{
// Remove addon specific data from toolbar items.
ResetableGuard aGuard( m_aLock );
for ( sal_uInt16 n = 0; n < m_pToolBar->GetItemCount(); n++ )
{
USHORT nId( m_pToolBar->GetItemId( n ) );
if ( nId > 0 )
{
AddonsParams* pRuntimeItemData = (AddonsParams*)m_pToolBar->GetItemData( nId );
if ( pRuntimeItemData )
delete pRuntimeItemData;
m_pToolBar->SetItemData( nId, NULL );
}
}
}
// Base class will destroy our m_pToolBar member
ToolBarManager::dispose();
}
bool AddonsToolBarManager::MenuItemAllowed( sal_uInt16 nId ) const
{
if (( nId == MENUITEM_TOOLBAR_VISIBLEBUTTON ) ||
( nId == MENUITEM_TOOLBAR_CUSTOMIZETOOLBAR ))
return false;
else
return true;
}
void AddonsToolBarManager::RefreshImages()
{
sal_Bool bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
for ( USHORT nPos = 0; nPos < m_pToolBar->GetItemCount(); nPos++ )
{
USHORT nId( m_pToolBar->GetItemId( nPos ) );
if ( nId > 0 )
{
::rtl::OUString aCommandURL = m_pToolBar->GetItemCommand( nId );
::rtl::OUString aImageId;
AddonsParams* pRuntimeItemData = (AddonsParams*)m_pToolBar->GetItemData( nId );
if ( pRuntimeItemData )
aImageId = pRuntimeItemData->aImageId;
m_pToolBar->SetItemImage( nId, RetrieveImage( m_xFrame,
aImageId,
aCommandURL,
bBigImages ));
}
}
}
void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue > >& rAddonToolbar )
{
ResetableGuard aGuard( m_aLock );
if ( m_bDisposed )
return;
USHORT nId( 1 );
RemoveControllers();
m_pToolBar->Clear();
m_aControllerMap.clear();
::rtl::OUString aModuleIdentifier;
try
{
Reference< XModuleManager > xModuleManager(
m_xServiceManager->createInstance( SERVICENAME_MODULEMANAGER ), UNO_QUERY_THROW );
aModuleIdentifier = xModuleManager->identify( m_xFrame );
}
catch ( Exception& )
{
}
Reference< XMultiComponentFactory > xToolbarControllerFactory( m_xToolbarControllerRegistration, UNO_QUERY );
Reference< XComponentContext > xComponentContext;
Reference< XPropertySet > xProps( m_xServiceManager, UNO_QUERY );
if ( xProps.is() )
xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xComponentContext;
sal_uInt32 nElements( 0 );
sal_Bool bAppendSeparator( sal_False );
Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
for ( sal_uInt32 n = 0; n < (sal_uInt32)rAddonToolbar.getLength(); n++ )
{
rtl::OUString aValueName;
rtl::OUString aURL;
rtl::OUString aTitle;
rtl::OUString aImageId;
rtl::OUString aContext;
rtl::OUString aTarget;
rtl::OUString aControlType;
sal_uInt16 nWidth( 0 );
const Sequence< PropertyValue >& rSeq = rAddonToolbar[n];
ToolBarMerger::ConvertSequenceToValues( rSeq, aURL, aTitle, aImageId, aTarget, aContext, aControlType, nWidth );
if ( IsCorrectContext( aModuleIdentifier, aContext ))
{
if ( aURL.equalsAsciiL( TOOLBOXITEM_SEPARATOR_STR, TOOLBOXITEM_SEPARATOR_STR_LEN ))
{
USHORT nCount = m_pToolBar->GetItemCount();
if ( nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != TOOLBOXITEM_SEPARATOR ) && nElements > 0 )
{
nElements = 0;
m_pToolBar->InsertSeparator();
}
}
else
{
USHORT nCount = m_pToolBar->GetItemCount();
if ( bAppendSeparator && nCount > 0 && ( m_pToolBar->GetItemType( nCount-1 ) != TOOLBOXITEM_SEPARATOR ))
{
// We have to append a separator first if the last item is not a separator
m_pToolBar->InsertSeparator();
}
bAppendSeparator = FALSE;
m_pToolBar->InsertItem( nId, aTitle );
Image aImage = RetrieveImage( m_xFrame, aImageId, aURL, !m_bSmallSymbols );
if ( !!aImage )
m_pToolBar->SetItemImage( nId, aImage );
// Create TbRuntimeItemData to hold additional information we will need in the future
AddonsParams* pRuntimeItemData = new AddonsParams;
pRuntimeItemData->aImageId = aImageId;
pRuntimeItemData->aTarget = aTarget;
m_pToolBar->SetItemData( nId, pRuntimeItemData );
m_pToolBar->SetItemCommand( nId, aURL );
Reference< XStatusListener > xController;
sal_Bool bMustBeInit( sal_True );
// Support external toolbar controller for add-ons!
if ( m_xToolbarControllerRegistration.is() &&
m_xToolbarControllerRegistration->hasController( aURL, m_aModuleIdentifier ))
{
if ( xToolbarControllerFactory.is() )
{
Sequence< Any > aArgs(5);
PropertyValue aPropValue;
aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleName" ));
aPropValue.Value <<= m_aModuleIdentifier;
aArgs[0] <<= aPropValue;
aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
aPropValue.Value <<= m_xFrame;
aArgs[1] <<= aPropValue;
aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
aPropValue.Value <<= m_xServiceManager;
aArgs[2] <<= aPropValue;
aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ));
aPropValue.Value <<= xToolbarWindow;
aArgs[3] <<= aPropValue;
aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ItemId" ));
aPropValue.Value = makeAny( sal_Int32( nId ));
aArgs[4] <<= aPropValue;
try
{
xController = Reference< XStatusListener >( xToolbarControllerFactory->createInstanceWithArgumentsAndContext(
aURL, aArgs, xComponentContext ),
UNO_QUERY );
}
catch ( uno::Exception& )
{
}
bMustBeInit = sal_False; // factory called init already!
}
}
else
{
::cppu::OWeakObject* pController = 0;
pController = ToolBarMerger::CreateController( m_xServiceManager, m_xFrame, m_pToolBar, aURL, nId, nWidth, aControlType );
xController = Reference< XStatusListener >( pController, UNO_QUERY );
}
// insert controller to the map
m_aControllerMap[nId] = xController;
Reference< XInitialization > xInit( xController, UNO_QUERY );
if ( xInit.is() && bMustBeInit )
{
PropertyValue aPropValue;
Sequence< Any > aArgs( 3 );
aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
aPropValue.Value <<= m_xFrame;
aArgs[0] <<= aPropValue;
aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" ));
aPropValue.Value <<= aURL;
aArgs[1] <<= aPropValue;
aPropValue.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ServiceManager" ));
aPropValue.Value <<= m_xServiceManager;
aArgs[2] <<= aPropValue;
try
{
xInit->initialize( aArgs );
}
catch ( uno::Exception& )
{
}
}
// Request a item window from the toolbar controller and set it at the VCL toolbar
Reference< XToolbarController > xTbxController( xController, UNO_QUERY );
if ( xTbxController.is() && xToolbarWindow.is() )
{
Reference< XWindow > xWindow = xTbxController->createItemWindow( xToolbarWindow );
if ( xWindow.is() )
{
Window* pItemWin = VCLUnoHelper::GetWindow( xWindow );
if ( pItemWin )
{
WindowType nType = pItemWin->GetType();
if ( nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX )
pItemWin->SetAccessibleName( m_pToolBar->GetItemText( nId ) );
m_pToolBar->SetItemWindow( nId, pItemWin );
}
}
}
// Notify controller implementation to its listeners. Controller is now useable from outside.
Reference< XUpdatable > xUpdatable( xController, UNO_QUERY );
if ( xUpdatable.is() )
{
try
{
xUpdatable->update();
}
catch ( uno::Exception& )
{
}
}
++nId;
++nElements;
}
}
}
AddFrameActionListener();
}
IMPL_LINK( AddonsToolBarManager, Click, ToolBox*, EMPTYARG )
{
if ( m_bDisposed )
return 1;
USHORT nId( m_pToolBar->GetCurItemId() );
ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
if ( pIter != m_aControllerMap.end() )
{
Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
if ( xController.is() )
xController->click();
}
return 1;
}
IMPL_LINK( AddonsToolBarManager, DoubleClick, ToolBox*, EMPTYARG )
{
if ( m_bDisposed )
return 1;
USHORT nId( m_pToolBar->GetCurItemId() );
ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
if ( pIter != m_aControllerMap.end() )
{
Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
if ( xController.is() )
xController->doubleClick();
}
return 1;
}
IMPL_LINK( AddonsToolBarManager, Command, CommandEvent*, EMPTYARG )
{
ResetableGuard aGuard( m_aLock );
if ( m_bDisposed )
return 1;
return 0;
}
IMPL_LINK( AddonsToolBarManager, Select, ToolBox*, EMPTYARG )
{
if ( m_bDisposed )
return 1;
sal_Int16 nKeyModifier( (sal_Int16)m_pToolBar->GetModifier() );
USHORT nId( m_pToolBar->GetCurItemId() );
ToolBarControllerMap::const_iterator pIter = m_aControllerMap.find( nId );
if ( pIter != m_aControllerMap.end() )
{
Reference< XToolbarController > xController( pIter->second, UNO_QUERY );
if ( xController.is() )
xController->execute( nKeyModifier );
}
return 1;
}
IMPL_LINK( AddonsToolBarManager, Highlight, ToolBox*, EMPTYARG )
{
return 1;
}
IMPL_LINK( AddonsToolBarManager, Activate, ToolBox*, EMPTYARG )
{
return 1;
}
IMPL_LINK( AddonsToolBarManager, Deactivate, ToolBox*, EMPTYARG )
{
return 1;
}
IMPL_LINK( AddonsToolBarManager, StateChanged, StateChangedType*, pStateChangedType )
{
if ( *pStateChangedType == STATE_CHANGE_CONTROLBACKGROUND )
{
// Check if we need to get new images for normal/high contrast mode
CheckAndUpdateImages();
}
return 1;
}
IMPL_LINK( AddonsToolBarManager, DataChanged, DataChangedEvent*, pDataChangedEvent )
{
if ((( pDataChangedEvent->GetType() == DATACHANGED_SETTINGS ) ||
( pDataChangedEvent->GetType() == DATACHANGED_DISPLAY )) &&
( pDataChangedEvent->GetFlags() & SETTINGS_STYLE ))
{
// Check if we need to get new images for normal/high contrast mode
CheckAndUpdateImages();
}
for ( USHORT nPos = 0; nPos < m_pToolBar->GetItemCount(); ++nPos )
{
const USHORT nId = m_pToolBar->GetItemId(nPos);
Window* pWindow = m_pToolBar->GetItemWindow( nId );
if ( pWindow )
{
const DataChangedEvent& rDCEvt( *pDataChangedEvent );
pWindow->DataChanged( rDCEvt );
}
}
return 1;
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|