LibreOffice Module forms (master) 1
navbarcontrol.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "navbarcontrol.hxx"
22#include <frm_strings.hxx>
23#include <componenttools.hxx>
24#include <navtoolbar.hxx>
26
27#include <com/sun/star/awt/XView.hpp>
28#include <com/sun/star/awt/PosSize.hpp>
29#include <com/sun/star/beans/XPropertySet.hpp>
30#include <com/sun/star/form/runtime/FormFeature.hpp>
31#include <com/sun/star/awt/XControlModel.hpp>
32#include <com/sun/star/frame/ModuleManager.hpp>
33
34#include <tools/debug.hxx>
36#include <vcl/svapp.hxx>
37#include <vcl/settings.hxx>
38
39
40namespace frm
41{
42
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::beans;
45 using namespace ::com::sun::star::awt;
46 using namespace ::com::sun::star::lang;
47 using namespace ::com::sun::star::frame;
48 using namespace ::com::sun::star::graphic;
49 namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
50
51 ONavigationBarControl::ONavigationBarControl( const Reference< XComponentContext >& _rxORB)
52 : m_xContext(_rxORB)
53 {
54 }
55
56
58 {
59 }
60
61
63
64
65 Any SAL_CALL ONavigationBarControl::queryAggregation( const Type& _rType )
66 {
67 Any aReturn = UnoControl::queryAggregation( _rType );
68
69 if ( !aReturn.hasValue() )
71
72 return aReturn;
73 }
74
75
76 namespace
77 {
78
79 WinBits lcl_getWinBits_nothrow( const Reference< XControlModel >& _rxModel )
80 {
81 WinBits nBits = 0;
82 try
83 {
84 Reference< XPropertySet > xProps( _rxModel, UNO_QUERY );
85 if ( xProps.is() )
86 {
87 sal_Int16 nBorder = 0;
88 xProps->getPropertyValue( PROPERTY_BORDER ) >>= nBorder;
89 if ( nBorder )
90 nBits |= WB_BORDER;
91
92 bool bTabStop = false;
93 if ( xProps->getPropertyValue( PROPERTY_TABSTOP ) >>= bTabStop )
94 nBits |= ( bTabStop ? WB_TABSTOP : WB_NOTABSTOP );
95 }
96 }
97 catch( const Exception& )
98 {
99 DBG_UNHANDLED_EXCEPTION("forms.component");
100 }
101 return nBits;
102 }
103 }
104
105
106 void SAL_CALL ONavigationBarControl::createPeer( const Reference< XToolkit >& /*_rToolkit*/, const Reference< XWindowPeer >& _rParentPeer )
107 {
108 SolarMutexGuard aGuard;
109
110 if (getPeer().is())
111 return;
112
113 mbCreatingPeer = true;
114
115 // determine the VCL window for the parent
116 vcl::Window* pParentWin = nullptr;
117 if ( _rParentPeer.is() )
118 {
119 VCLXWindow* pParentXWin = dynamic_cast<VCLXWindow*>( _rParentPeer.get() );
120 if ( pParentXWin )
121 pParentWin = pParentXWin->GetWindow();
122 DBG_ASSERT( pParentWin, "ONavigationBarControl::createPeer: could not obtain the VCL-level parent window!" );
123 }
124
125 // create the peer
127 assert(pPeer && "ONavigationBarControl::createPeer: invalid peer returned!");
128
129 // announce the peer to the base class
130 setPeer( pPeer );
131
132 // initialize ourself (and thus the peer) with the model properties
134
135 Reference< XView > xPeerView( getPeer(), UNO_QUERY );
136 if ( xPeerView.is() )
137 {
138 xPeerView->setZoom( maComponentInfos.nZoomX, maComponentInfos.nZoomY );
139 xPeerView->setGraphics( mxGraphics );
140 }
141
142 // a lot of initial settings from our component infos
144
145 pPeer->setVisible ( maComponentInfos.bVisible && !mbDesignMode );
146 pPeer->setEnable ( maComponentInfos.bEnable );
147 pPeer->setDesignMode( mbDesignMode );
148
149 peerCreated();
150
151 mbCreatingPeer = false;
152 }
153
154
156 {
157 return "com.sun.star.comp.form.ONavigationBarControl";
158 }
159
160
162 {
163 return { "com.sun.star.awt.UnoControl",
164 "com.sun.star.form.control.NavigationToolBar" };
165 }
166
167
168 void SAL_CALL ONavigationBarControl::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
169 {
170 Reference< XDispatchProviderInterception > xTypedPeer(getPeer(), UNO_QUERY);
171 if (xTypedPeer.is())
172 {
173 xTypedPeer->registerDispatchProviderInterceptor(_rxInterceptor);
174 }
175 }
176
177
178 void SAL_CALL ONavigationBarControl::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor )
179 {
180 Reference< XDispatchProviderInterception > xTypedPeer(getPeer(), UNO_QUERY);
181 if (xTypedPeer.is())
182 {
183 xTypedPeer->releaseDispatchProviderInterceptor(_rxInterceptor);
184 }
185 }
186
187
189 {
191 Reference< XVclWindowPeer > xTypedPeer(getPeer(), UNO_QUERY);
192 if (xTypedPeer.is())
193 {
194 xTypedPeer->setDesignMode(_bOn);
195 }
196 }
197
198
199 // ONavigationBarPeer
200
201
202 rtl::Reference<ONavigationBarPeer> ONavigationBarPeer::Create( const Reference< XComponentContext >& _rxORB,
203 vcl::Window* _pParentWindow, const Reference< XControlModel >& _rxModel )
204 {
206
207 // the peer itself
209
210 // the VCL control for the peer
211 Reference< XModel > xContextDocument( getXModel( _rxModel ) );
212 Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rxORB) );
213 OUString sModuleID = xModuleManager->identify( xContextDocument );
214
216 _pParentWindow,
217 lcl_getWinBits_nothrow( _rxModel ),
218 std::make_shared<DocumentCommandImageProvider>( _rxORB, xContextDocument ),
219 sModuleID
220 );
221
222 // some knittings
223 pNavBar->setDispatcher( pPeer.get() );
224 pNavBar->SetComponentInterface( pPeer );
225
226 // we want a faster repeating rate for the slots in this
227 // toolbox
228 AllSettings aSettings = pNavBar->GetSettings();
229 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
230 aMouseSettings.SetButtonRepeat( 10 );
231 aSettings.SetMouseSettings( aMouseSettings );
232 pNavBar->SetSettings( aSettings, true );
233
234 // outta here
235 return pPeer;
236 }
237
238
239 ONavigationBarPeer::ONavigationBarPeer( const Reference< XComponentContext >& _rxORB )
240 :OFormNavigationHelper( _rxORB )
241 {
242 }
243
244
246 {
247 }
248
249
251
252
254
255
256 void SAL_CALL ONavigationBarPeer::dispose( )
257 {
260 }
261
262
263 void SAL_CALL ONavigationBarPeer::setProperty( const OUString& _rPropertyName, const Any& _rValue )
264 {
265 SolarMutexGuard aGuard;
266
267 VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
268 if ( !pNavBar )
269 {
270 VCLXWindow::setProperty( _rPropertyName, _rValue );
271 return;
272 }
273
274 bool bVoid = !_rValue.hasValue();
275
276 bool bBoolValue = false;
277 Color nColor = COL_TRANSPARENT;
278
279 // TODO: more generic mechanisms for this (the grid control implementation,
280 // when used herein, will do the same stuff for lot of these)
281
282 if ( _rPropertyName == PROPERTY_BACKGROUNDCOLOR )
283 {
284 if ( bVoid )
285 {
286 pNavBar->SetBackground( pNavBar->GetSettings().GetStyleSettings().GetFaceColor() );
287 pNavBar->SetControlBackground();
288 }
289 else
290 {
291 OSL_VERIFY( _rValue >>= nColor );
292 Color aColor( nColor );
293 pNavBar->SetBackground( aColor );
294 pNavBar->SetControlBackground( aColor );
295 }
296 }
297 else if ( _rPropertyName == PROPERTY_TEXTLINECOLOR )
298 {
299 if ( bVoid )
300 {
301 pNavBar->SetTextLineColor();
302 }
303 else
304 {
305 OSL_VERIFY( _rValue >>= nColor );
306 pNavBar->SetTextLineColor( nColor );
307 }
308 }
309 else if ( _rPropertyName == PROPERTY_ICONSIZE )
310 {
311 sal_Int16 nInt16Value = 0;
312 OSL_VERIFY( _rValue >>= nInt16Value );
313 pNavBar->SetImageSize( nInt16Value ? NavigationToolBar::eLarge : NavigationToolBar::eSmall );
314 }
315 else if ( _rPropertyName == PROPERTY_SHOW_POSITION )
316 {
317 OSL_VERIFY( _rValue >>= bBoolValue );
318 pNavBar->ShowFunctionGroup( NavigationToolBar::ePosition, bBoolValue );
319 }
320 else if ( _rPropertyName == PROPERTY_SHOW_NAVIGATION )
321 {
322 OSL_VERIFY( _rValue >>= bBoolValue );
323 pNavBar->ShowFunctionGroup( NavigationToolBar::eNavigation, bBoolValue );
324 }
325 else if ( _rPropertyName == PROPERTY_SHOW_RECORDACTIONS )
326 {
327 OSL_VERIFY( _rValue >>= bBoolValue );
328 pNavBar->ShowFunctionGroup( NavigationToolBar::eRecordActions, bBoolValue );
329 }
330 else if ( _rPropertyName == PROPERTY_SHOW_FILTERSORT )
331 {
332 OSL_VERIFY( _rValue >>= bBoolValue );
333 pNavBar->ShowFunctionGroup( NavigationToolBar::eFilterSort, bBoolValue );
334 }
335 else
336 {
337 VCLXWindow::setProperty( _rPropertyName, _rValue );
338 }
339 }
340
341
342 Any SAL_CALL ONavigationBarPeer::getProperty( const OUString& _rPropertyName )
343 {
344 SolarMutexGuard aGuard;
345
346 Any aReturn;
347 VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
348
349 if ( _rPropertyName == PROPERTY_BACKGROUNDCOLOR )
350 {
351 aReturn <<= pNavBar->GetControlBackground();
352 }
353 else if ( _rPropertyName == PROPERTY_TEXTLINECOLOR )
354 {
355 aReturn <<= pNavBar->GetTextLineColor();
356 }
357 else if ( _rPropertyName == PROPERTY_ICONSIZE )
358 {
359 sal_Int16 nIconType = ( NavigationToolBar::eLarge == pNavBar->GetImageSize() )
360 ? 1 : 0;
361 aReturn <<= nIconType;
362 }
363 else if ( _rPropertyName == PROPERTY_SHOW_POSITION )
364 {
365 aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::ePosition );
366 }
367 else if ( _rPropertyName == PROPERTY_SHOW_NAVIGATION )
368 {
369 aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::eNavigation );
370 }
371 else if ( _rPropertyName == PROPERTY_SHOW_RECORDACTIONS )
372 {
373 aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::eRecordActions );
374 }
375 else if ( _rPropertyName == PROPERTY_SHOW_FILTERSORT )
376 {
377 aReturn <<= pNavBar->IsFunctionGroupVisible( NavigationToolBar::eFilterSort );
378 }
379 else
380 aReturn = VCLXWindow::getProperty( _rPropertyName );
381
382 return aReturn;
383 }
384
385
387 {
388 if ( isDesignMode() )
389 // not interested in if we're in design mode
390 return;
391
393 }
394
395
396 void ONavigationBarPeer::featureStateChanged( sal_Int16 _nFeatureId, bool _bEnabled )
397 {
398 // enable this button on the toolbox
399 VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
400 if ( pNavBar )
401 {
402 pNavBar->enableFeature( _nFeatureId, _bEnabled );
403
404 // is it a feature with additional state information?
405 if ( _nFeatureId == FormFeature::ToggleApplyFilter )
406 { // additional boolean state
407 pNavBar->checkFeature( _nFeatureId, getBooleanState( _nFeatureId ) );
408 }
409 else if ( _nFeatureId == FormFeature::TotalRecords )
410 {
411 pNavBar->setFeatureText( _nFeatureId, getStringState( _nFeatureId ) );
412 }
413 else if ( _nFeatureId == FormFeature::MoveAbsolute )
414 {
415 pNavBar->setFeatureText( _nFeatureId, OUString::number(getIntegerState(_nFeatureId)) );
416 }
417 }
418
419 // base class
420 OFormNavigationHelper::featureStateChanged( _nFeatureId, _bEnabled );
421 }
422
423
425 {
426 {
427 // force the control to update it's states
429 VclPtr< NavigationToolBar > pNavBar = GetAs< NavigationToolBar >();
430 if ( pNavBar )
431 pNavBar->setDispatcher( this );
432 }
433
434 // base class
436 }
437
438
439 bool ONavigationBarPeer::isEnabled( sal_Int16 _nFeatureId ) const
440 {
441 if ( const_cast< ONavigationBarPeer* >( this )->isDesignMode() )
442 return false;
443
444 return OFormNavigationHelper::isEnabled( _nFeatureId );
445 }
446
447
449 {
451
452 if ( _bOn )
454 else
456 // this will connect if not already connected and just update else
457 }
458
459
460 void SAL_CALL ONavigationBarPeer::disposing( const EventObject& _rSource )
461 {
462 VCLXWindow::disposing( _rSource );
464 }
465
466
467 void ONavigationBarPeer::getSupportedFeatures( ::std::vector< sal_Int16 >& _rFeatureIds )
468 {
469 _rFeatureIds.push_back( FormFeature::MoveAbsolute );
470 _rFeatureIds.push_back( FormFeature::TotalRecords );
471 _rFeatureIds.push_back( FormFeature::MoveToFirst );
472 _rFeatureIds.push_back( FormFeature::MoveToPrevious );
473 _rFeatureIds.push_back( FormFeature::MoveToNext );
474 _rFeatureIds.push_back( FormFeature::MoveToLast );
475 _rFeatureIds.push_back( FormFeature::SaveRecordChanges );
476 _rFeatureIds.push_back( FormFeature::UndoRecordChanges );
477 _rFeatureIds.push_back( FormFeature::MoveToInsertRow );
478 _rFeatureIds.push_back( FormFeature::DeleteRecord );
479 _rFeatureIds.push_back( FormFeature::ReloadForm );
480 _rFeatureIds.push_back( FormFeature::RefreshCurrentControl );
481 _rFeatureIds.push_back( FormFeature::SortAscending );
482 _rFeatureIds.push_back( FormFeature::SortDescending );
483 _rFeatureIds.push_back( FormFeature::InteractiveSort );
484 _rFeatureIds.push_back( FormFeature::AutoFilter );
485 _rFeatureIds.push_back( FormFeature::InteractiveFilter );
486 _rFeatureIds.push_back( FormFeature::ToggleApplyFilter );
487 _rFeatureIds.push_back( FormFeature::RemoveFilterAndSort );
488 }
489
490} // namespace frm
491
492
493extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
495 css::uno::Sequence<css::uno::Any> const &)
496{
497 return cppu::acquire(new frm::ONavigationBarControl(context));
498}
499
500/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xContext
const MouseSettings & GetMouseSettings() const
void SetMouseSettings(const MouseSettings &rSet)
void SetButtonRepeat(sal_Int32 nRepeat)
css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override
bool mbDesignMode
virtual void updateFromModel()
UnoControlComponentInfos maComponentInfos
void SAL_CALL setPosSize(sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height, sal_Int16 Flags) override
css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override
void SAL_CALL setDesignMode(sal_Bool bOn) override
void setPeer(const css::uno::Reference< css::awt::XVclWindowPeer > &_xPeer)
void peerCreated()
css::uno::Reference< css::awt::XGraphics > mxGraphics
bool mbCreatingPeer
vcl::Window * GetWindow() const
void SAL_CALL setDesignMode(sal_Bool bOn) override
css::uno::Any SAL_CALL getProperty(const OUString &PropertyName) override
void SAL_CALL setProperty(const OUString &PropertyName, const css::uno::Any &Value) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
sal_Bool SAL_CALL isDesignMode() override
void SAL_CALL dispose() override
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual void interceptorsChanged()
is called when the interceptors have.
void disconnectDispatchers()
disconnect from the dispatch interceptors
virtual OUString getStringState(sal_Int16 _nFeatureId) const override
returns the string state of a feature
virtual bool getBooleanState(sal_Int16 _nFeatureId) const override
returns the boolean state of a feature
virtual void allFeatureStatesChanged()
notification for (potential) changes in the state of all features
virtual sal_Int32 getIntegerState(sal_Int16 _nFeatureId) const override
returns the integer state of a feature
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
virtual bool isEnabled(sal_Int16 _nFeatureId) const override
checks whether a given feature is enabled
void connectDispatchers()
connect to the dispatch interceptors
virtual void featureStateChanged(sal_Int16 _nFeatureId, bool _bEnabled)
called when the status of a feature changed
virtual void SAL_CALL registerDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor > &Interceptor) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual void SAL_CALL createPeer(const css::uno::Reference< css::awt::XToolkit > &_rToolkit, const css::uno::Reference< css::awt::XWindowPeer > &_rParent) override
virtual void SAL_CALL releaseDispatchProviderInterceptor(const css::uno::Reference< css::frame::XDispatchProviderInterceptor > &Interceptor) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
ONavigationBarControl(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
virtual void SAL_CALL setDesignMode(sal_Bool _bOn) override
virtual OUString SAL_CALL getImplementationName() override
virtual ~ONavigationBarControl() override
css::uno::Any SAL_CALL getProperty(const OUString &_rPropertyName) override
virtual void featureStateChanged(sal_Int16 _nFeatureId, bool _bEnabled) override
called when the status of a feature changed
virtual void getSupportedFeatures(::std::vector< sal_Int16 > &_rFeatureIds) override
retrieves the list of supported features
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
ONavigationBarPeer(const css::uno::Reference< css::uno::XComponentContext > &_rxORB)
static rtl::Reference< ONavigationBarPeer > Create(const css::uno::Reference< css::uno::XComponentContext > &_rxORB, vcl::Window *_pParentWindow, const css::uno::Reference< css::awt::XControlModel > &_rxModel)
factory method
void SAL_CALL setProperty(const OUString &_rPropertyName, const css::uno::Any &_rValue) override
virtual ~ONavigationBarPeer() override
virtual void interceptorsChanged() override
is called when the interceptors have.
sal_Bool SAL_CALL isEnabled() override
virtual void allFeatureStatesChanged() override
notification for (potential) changes in the state of all features
virtual void SAL_CALL setDesignMode(sal_Bool _bOn) override
constexpr ::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define DBG_ASSERT(sCon, aError)
#define DBG_TESTSOLARMUTEX()
#define DBG_UNHANDLED_EXCEPTION(...)
constexpr OUStringLiteral PROPERTY_BACKGROUNDCOLOR
constexpr OUStringLiteral PROPERTY_ICONSIZE
constexpr OUStringLiteral PROPERTY_SHOW_RECORDACTIONS
constexpr OUStringLiteral PROPERTY_SHOW_FILTERSORT
constexpr OUStringLiteral PROPERTY_SHOW_POSITION
constexpr OUStringLiteral PROPERTY_TEXTLINECOLOR
constexpr OUStringLiteral PROPERTY_SHOW_NAVIGATION
constexpr OUStringLiteral PROPERTY_TABSTOP
constexpr OUStringLiteral PROPERTY_BORDER
tools::Long const nBorder
Type
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
css::uno::Reference< css::frame::XModel > getXModel(const css::uno::Reference< css::uno::XInterface > &_rxComponent)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
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 &)
unsigned char sal_Bool
sal_Int64 WinBits
WinBits const WB_NOTABSTOP
WinBits const WB_BORDER
WinBits const WB_TABSTOP