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
|
/* -*- 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 "navbarcontrol.hxx"
#include <frm_strings.hxx>
#include <componenttools.hxx>
#include <navtoolbar.hxx>
#include <commandimageprovider.hxx>
#include <com/sun/star/awt/XView.hpp>
#include <com/sun/star/awt/PosSize.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/form/runtime/FormFeature.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/frame/ModuleManager.hpp>
#include <tools/debug.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
namespace frm
{
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::graphic;
namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
ONavigationBarControl::ONavigationBarControl( const Reference< XComponentContext >& _rxORB)
: m_xContext(_rxORB)
{
}
ONavigationBarControl::~ONavigationBarControl()
{
}
IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarControl, UnoControl, ONavigationBarControl_Base )
Any SAL_CALL ONavigationBarControl::queryAggregation( const Type& _rType )
{
Any aReturn = UnoControl::queryAggregation( _rType );
if ( !aReturn.hasValue() )
aReturn = ONavigationBarControl_Base::queryInterface( _rType );
return aReturn;
}
namespace
{
WinBits lcl_getWinBits_nothrow( const Reference< XControlModel >& _rxModel )
{
WinBits nBits = 0;
try
{
Reference< XPropertySet > xProps( _rxModel, UNO_QUERY );
if ( xProps.is() )
{
sal_Int16 nBorder = 0;
xProps->getPropertyValue( PROPERTY_BORDER ) >>= nBorder;
if ( nBorder )
nBits |= WB_BORDER;
bool bTabStop = false;
if ( xProps->getPropertyValue( PROPERTY_TABSTOP ) >>= bTabStop )
nBits |= ( bTabStop ? WB_TABSTOP : WB_NOTABSTOP );
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("forms.component");
}
return nBits;
}
}
void SAL_CALL ONavigationBarControl::createPeer( const Reference< XToolkit >& /*_rToolkit*/, const Reference< XWindowPeer >& _rParentPeer )
{
SolarMutexGuard aGuard;
if (getPeer().is())
return;
mbCreatingPeer = true;
// determine the VCL window for the parent
vcl::Window* pParentWin = nullptr;
if ( _rParentPeer.is() )
{
VCLXWindow* pParentXWin = dynamic_cast<VCLXWindow*>( _rParentPeer.get() );
if ( pParentXWin )
pParentWin = pParentXWin->GetWindow();
DBG_ASSERT( pParentWin, "ONavigationBarControl::createPeer: could not obtain the VCL-level parent window!" );
}
// create the peer
rtl::Reference<ONavigationBarPeer> pPeer = ONavigationBarPeer::Create( m_xContext, pParentWin, getModel() );
assert(pPeer && "ONavigationBarControl::createPeer: invalid peer returned!");
// announce the peer to the base class
setPeer( pPeer );
// initialize ourself (and thus the peer) with the model properties
updateFromModel();
Reference< XView > xPeerView( getPeer(), UNO_QUERY );
if ( xPeerView.is() )
{
xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY );
xPeerView->setGraphics( mxGraphics );
}
// a lot of initial settings from our component infos
setPosSize( maComponentInfos.nX, maComponentInfos.nY, maComponentInfos.nWidth, maComponentInfos.nHeight, PosSize::POSSIZE );
pPeer->setVisible ( maComponentInfos.bVisible && !mbDesignMode );
pPeer->setEnable ( maComponentInfos.bEnable );
pPeer->setDesignMode( mbDesignMode );
peerCreated();
mbCreatingPeer = false;
}
OUString SAL_CALL ONavigationBarControl::getImplementationName()
{
return "com.sun.star.comp.form.ONavigationBarControl";
}
Sequence< OUString > SAL_CALL ONavigationBarControl::getSupportedServiceNames()
{
return { "com.sun.star.awt.UnoControl",
"com.sun.star.form.control.NavigationToolBar" };
}
void SAL_CALL ONavigationBarControl::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
{
Reference< XDispatchProviderInterception > xTypedPeer(getPeer(), UNO_QUERY);
if (xTypedPeer.is())
{
xTypedPeer->registerDispatchProviderInterceptor(_rxInterceptor);
}
}
void SAL_CALL ONavigationBarControl::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
{
Reference< XDispatchProviderInterception > xTypedPeer(getPeer(), UNO_QUERY);
if (xTypedPeer.is())
{
xTypedPeer->releaseDispatchProviderInterceptor(_rxInterceptor);
}
}
void SAL_CALL ONavigationBarControl::setDesignMode( sal_Bool _bOn )
{
UnoControl::setDesignMode( _bOn );
Reference< XVclWindowPeer > xTypedPeer(getPeer(), UNO_QUERY);
if (xTypedPeer.is())
{
xTypedPeer->setDesignMode(_bOn);
}
}
// ONavigationBarPeer
rtl::Reference<ONavigationBarPeer> ONavigationBarPeer::Create( const Reference< XComponentContext >& _rxORB,
vcl::Window* _pParentWindow, const Reference< XControlModel >& _rxModel )
{
DBG_TESTSOLARMUTEX();
// the peer itself
rtl::Reference<ONavigationBarPeer> pPeer(new ONavigationBarPeer( _rxORB ));
// the VCL control for the peer
Reference< XModel > xContextDocument( getXModel( _rxModel ) );
Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rxORB) );
OUString sModuleID = xModuleManager->identify( xContextDocument );
VclPtrInstance<NavigationToolBar> pNavBar(
_pParentWindow,
lcl_getWinBits_nothrow( _rxModel ),
std::make_shared<DocumentCommandImageProvider>( _rxORB, xContextDocument ),
sModuleID
);
// some knittings
pNavBar->setDispatcher( pPeer.get() );
pNavBar->SetComponentInterface( pPeer );
// we want a faster repeating rate for the slots in this
// toolbox
AllSettings aSettings = pNavBar->GetSettings();
MouseSettings aMouseSettings = aSettings.GetMouseSettings();
aMouseSettings.SetButtonRepeat( 10 );
aSettings.SetMouseSettings( aMouseSettings );
pNavBar->SetSettings( aSettings, true );
// outta here
return pPeer;
}
ONavigationBarPeer::ONavigationBarPeer( const Reference< XComponentContext >& _rxORB )
:OFormNavigationHelper( _rxORB )
{
}
ONavigationBarPeer::~ONavigationBarPeer()
{
}
IMPLEMENT_FORWARD_XINTERFACE2( ONavigationBarPeer, VCLXWindow, OFormNavigationHelper )
IMPLEMENT_FORWARD_XTYPEPROVIDER2( ONavigationBarPeer, VCLXWindow, OFormNavigationHelper )
void SAL_CALL ONavigationBarPeer::dispose( )
{
VCLXWindow::dispose();
OFormNavigationHelper::dispose();
}
void SAL_CALL ONavigationBarPeer::setProperty( const OUString& _rPropertyName, const Any& _rValue )
{
SolarMutexGuard aGuard;
VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
if ( !pNavBar )
{
VCLXWindow::setProperty( _rPropertyName, _rValue );
return;
}
bool bVoid = !_rValue.hasValue();
bool bBoolValue = false;
Color nColor = COL_TRANSPARENT;
// TODO: more generic mechanisms for this (the grid control implementation,
// when used herein, will do the same stuff for lot of these)
if ( _rPropertyName == PROPERTY_BACKGROUNDCOLOR )
{
if ( bVoid )
{
pNavBar->SetBackground( pNavBar->GetSettings().GetStyleSettings().GetFaceColor() );
pNavBar->SetControlBackground();
}
else
{
OSL_VERIFY( _rValue >>= nColor );
Color aColor( nColor );
pNavBar->SetBackground( aColor );
pNavBar->SetControlBackground( aColor );
}
}
else if ( _rPropertyName == PROPERTY_TEXTLINECOLOR )
{
if ( bVoid )
{
pNavBar->SetTextLineColor();
}
else
{
OSL_VERIFY( _rValue >>= nColor );
pNavBar->SetTextLineColor( nColor );
}
}
else if ( _rPropertyName == PROPERTY_ICONSIZE )
{
sal_Int16 nInt16Value = 0;
OSL_VERIFY( _rValue >>= nInt16Value );
pNavBar->SetImageSize( nInt16Value ? NavigationToolBar::eLarge : NavigationToolBar::eSmall );
}
else if ( _rPropertyName == PROPERTY_SHOW_POSITION )
{
OSL_VERIFY( _rValue >>= bBoolValue );
pNavBar->ShowFunctionGroup( NavigationToolBar::ePosition, bBoolValue );
}
else if ( _rPropertyName == PROPERTY_SHOW_NAVIGATION )
{
OSL_VERIFY( _rValue >>= bBoolValue );
pNavBar->ShowFunctionGroup( NavigationToolBar::eNavigation, bBoolValue );
}
else if ( _rPropertyName == PROPERTY_SHOW_RECORDACTIONS )
{
OSL_VERIFY( _rValue >>= bBoolValue );
pNavBar->ShowFunctionGroup( NavigationToolBar::eRecordActions, bBoolValue );
}
else if ( _rPropertyName == PROPERTY_SHOW_FILTERSORT )
{
OSL_VERIFY( _rValue >>= bBoolValue );
pNavBar->ShowFunctionGroup( NavigationToolBar::eFilterSort, bBoolValue );
}
else
{
VCLXWindow::setProperty( _rPropertyName, _rValue );
}
}
Any SAL_CALL ONavigationBarPeer::getProperty( const OUString& _rPropertyName )
{
SolarMutexGuard aGuard;
Any aReturn;
VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
if ( _rPropertyName == PROPERTY_BACKGROUNDCOLOR )
{
aReturn <<= pNavBar->GetControlBackground();
}
else if ( _rPropertyName == PROPERTY_TEXTLINECOLOR )
{
aReturn <<= pNavBar->GetTextLineColor();
}
else if ( _rPropertyName == PROPERTY_ICONSIZE )
{
sal_Int16 nIconType = ( NavigationToolBar::eLarge == pNavBar->GetImageSize() )
? 1 : 0;
aReturn <<= nIconType;
}
else if ( _rPropertyName == PROPERTY_SHOW_POSITION )
{
aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::ePosition );
}
else if ( _rPropertyName == PROPERTY_SHOW_NAVIGATION )
{
aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::eNavigation );
}
else if ( _rPropertyName == PROPERTY_SHOW_RECORDACTIONS )
{
aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::eRecordActions );
}
else if ( _rPropertyName == PROPERTY_SHOW_FILTERSORT )
{
aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::eFilterSort );
}
else
aReturn = VCLXWindow::getProperty( _rPropertyName );
return aReturn;
}
void ONavigationBarPeer::interceptorsChanged( )
{
if ( isDesignMode() )
// not interested in if we're in design mode
return;
OFormNavigationHelper::interceptorsChanged();
}
void ONavigationBarPeer::featureStateChanged( sal_Int16 _nFeatureId, bool _bEnabled )
{
// enable this button on the toolbox
VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
if ( pNavBar )
{
pNavBar->enableFeature( _nFeatureId, _bEnabled );
// is it a feature with additional state information?
if ( _nFeatureId == FormFeature::ToggleApplyFilter )
{ // additional boolean state
pNavBar->checkFeature( _nFeatureId, getBooleanState( _nFeatureId ) );
}
else if ( _nFeatureId == FormFeature::TotalRecords )
{
pNavBar->setFeatureText( _nFeatureId, getStringState( _nFeatureId ) );
}
else if ( _nFeatureId == FormFeature::MoveAbsolute )
{
pNavBar->setFeatureText( _nFeatureId, OUString::number(getIntegerState(_nFeatureId)) );
}
}
// base class
OFormNavigationHelper::featureStateChanged( _nFeatureId, _bEnabled );
}
void ONavigationBarPeer::allFeatureStatesChanged( )
{
{
// force the control to update it's states
SolarMutexGuard g;
VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
if ( pNavBar )
pNavBar->setDispatcher( this );
}
// base class
OFormNavigationHelper::allFeatureStatesChanged( );
}
bool ONavigationBarPeer::isEnabled( sal_Int16 _nFeatureId ) const
{
if ( const_cast< ONavigationBarPeer* >( this )->isDesignMode() )
return false;
return OFormNavigationHelper::isEnabled( _nFeatureId );
}
void SAL_CALL ONavigationBarPeer::setDesignMode( sal_Bool _bOn )
{
VCLXWindow::setDesignMode( _bOn );
if ( _bOn )
disconnectDispatchers();
else
connectDispatchers();
// this will connect if not already connected and just update else
}
void SAL_CALL ONavigationBarPeer::disposing( const EventObject& _rSource )
{
VCLXWindow::disposing( _rSource );
OFormNavigationHelper::disposing( _rSource );
}
void ONavigationBarPeer::getSupportedFeatures( ::std::vector< sal_Int16 >& _rFeatureIds )
{
_rFeatureIds.push_back( FormFeature::MoveAbsolute );
_rFeatureIds.push_back( FormFeature::TotalRecords );
_rFeatureIds.push_back( FormFeature::MoveToFirst );
_rFeatureIds.push_back( FormFeature::MoveToPrevious );
_rFeatureIds.push_back( FormFeature::MoveToNext );
_rFeatureIds.push_back( FormFeature::MoveToLast );
_rFeatureIds.push_back( FormFeature::SaveRecordChanges );
_rFeatureIds.push_back( FormFeature::UndoRecordChanges );
_rFeatureIds.push_back( FormFeature::MoveToInsertRow );
_rFeatureIds.push_back( FormFeature::DeleteRecord );
_rFeatureIds.push_back( FormFeature::ReloadForm );
_rFeatureIds.push_back( FormFeature::RefreshCurrentControl );
_rFeatureIds.push_back( FormFeature::SortAscending );
_rFeatureIds.push_back( FormFeature::SortDescending );
_rFeatureIds.push_back( FormFeature::InteractiveSort );
_rFeatureIds.push_back( FormFeature::AutoFilter );
_rFeatureIds.push_back( FormFeature::InteractiveFilter );
_rFeatureIds.push_back( FormFeature::ToggleApplyFilter );
_rFeatureIds.push_back( FormFeature::RemoveFilterAndSort );
}
} // namespace frm
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
com_sun_star_comp_form_ONavigationBarControl_get_implementation (css::uno::XComponentContext* context,
css::uno::Sequence<css::uno::Any> const &)
{
return cppu::acquire(new frm::ONavigationBarControl(context));
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|