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 <navtoolbar.hxx>
22 #include <frm_resource.hxx>
23 #include <featuredispatcher.hxx>
24 #include <strings.hrc>
25 #include <commandimageprovider.hxx>
26 
27 #include <com/sun/star/uno/Any.hxx>
28 #include <com/sun/star/form/runtime/FormFeature.hpp>
29 
30 #include <svx/labelitemwindow.hxx>
31 
32 #include <vcl/commandinfoprovider.hxx>
33 #include <vcl/toolbox.hxx>
34 
35 #include <sal/macros.h>
36 #include <osl/diagnose.h>
37 #include <tools/debug.hxx>
38 
39 #define LID_RECORD_LABEL    1000
40 #define LID_RECORD_FILLER   1001
41 
42 
43 namespace frm
44 {
45 
46 
47     using ::com::sun::star::uno::makeAny;
48     namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
49 
50 
51     namespace
52     {
isArtificialItem(sal_Int16 _nFeatureId)53         bool isArtificialItem( sal_Int16 _nFeatureId )
54         {
55             return ( _nFeatureId == LID_RECORD_LABEL )
56                 || ( _nFeatureId == LID_RECORD_FILLER );
57         }
58 
getLabelString(const char * pResId)59         OUString getLabelString(const char* pResId)
60         {
61             OUString sLabel( " " + FRM_RES_STRING(pResId) + " " );
62             return sLabel;
63         }
64 
lcl_getCommandURL(const sal_Int16 _nFormFeature)65         OUString lcl_getCommandURL( const sal_Int16 _nFormFeature )
66         {
67             const char* pAsciiCommandName = nullptr;
68             switch ( _nFormFeature )
69             {
70                 case FormFeature::MoveAbsolute          : pAsciiCommandName = "AbsoluteRecord";     break;
71                 case FormFeature::TotalRecords          : pAsciiCommandName = "RecTotal";           break;
72                 case FormFeature::MoveToFirst           : pAsciiCommandName = "FirstRecord";        break;
73                 case FormFeature::MoveToPrevious        : pAsciiCommandName = "PrevRecord";         break;
74                 case FormFeature::MoveToNext            : pAsciiCommandName = "NextRecord";         break;
75                 case FormFeature::MoveToLast            : pAsciiCommandName = "LastRecord";         break;
76                 case FormFeature::SaveRecordChanges     : pAsciiCommandName = "RecSave";            break;
77                 case FormFeature::UndoRecordChanges     : pAsciiCommandName = "RecUndo";            break;
78                 case FormFeature::MoveToInsertRow       : pAsciiCommandName = "NewRecord";          break;
79                 case FormFeature::DeleteRecord          : pAsciiCommandName = "DeleteRecord";       break;
80                 case FormFeature::ReloadForm            : pAsciiCommandName = "Refresh";            break;
81                 case FormFeature::RefreshCurrentControl : pAsciiCommandName = "RefreshFormControl"; break;
82                 case FormFeature::SortAscending         : pAsciiCommandName = "Sortup";             break;
83                 case FormFeature::SortDescending        : pAsciiCommandName = "SortDown";           break;
84                 case FormFeature::InteractiveSort       : pAsciiCommandName = "OrderCrit";          break;
85                 case FormFeature::AutoFilter            : pAsciiCommandName = "AutoFilter";         break;
86                 case FormFeature::InteractiveFilter     : pAsciiCommandName = "FilterCrit";         break;
87                 case FormFeature::ToggleApplyFilter     : pAsciiCommandName = "FormFiltered";       break;
88                 case FormFeature::RemoveFilterAndSort   : pAsciiCommandName = "RemoveFilterSort";   break;
89             }
90             if ( pAsciiCommandName != nullptr )
91                 return ".uno:" + OUString::createFromAscii( pAsciiCommandName );
92 
93             OSL_FAIL( "lcl_getCommandURL: unknown FormFeature!" );
94             return OUString();
95         }
96     }
97 
98     class ImplNavToolBar : public ToolBox
99     {
100     protected:
101         const IFeatureDispatcher*   m_pDispatcher;
102 
103     public:
ImplNavToolBar(vcl::Window * _pParent)104         explicit ImplNavToolBar( vcl::Window* _pParent )
105             :ToolBox( _pParent, WB_3DLOOK )
106             ,m_pDispatcher( nullptr )
107         {
108         }
109 
setDispatcher(const IFeatureDispatcher * _pDispatcher)110         void setDispatcher( const IFeatureDispatcher* _pDispatcher )
111         {
112             m_pDispatcher = _pDispatcher;
113         }
114 
115     protected:
116         // ToolBox overridables
117         virtual void        Select() override;
118 
119     };
120 
121 
Select()122     void ImplNavToolBar::Select()
123     {
124         if ( m_pDispatcher )
125         {
126             sal_Int16 nFeatureId = sal_uInt16(GetCurItemId());
127             if ( !m_pDispatcher->isEnabled( nFeatureId ) )
128                 // the toolbox is a little bit buggy: With ToolBoxItemBits::REPEAT, it sometimes
129                 // happens that a select is reported, even though the respective
130                 // item has just been disabled.
131                 return;
132             m_pDispatcher->dispatch( nFeatureId );
133         }
134     }
135 
NavigationToolBar(vcl::Window * _pParent,WinBits _nStyle,const PCommandImageProvider & _pImageProvider,const OUString & sModuleId)136     NavigationToolBar::NavigationToolBar( vcl::Window* _pParent, WinBits _nStyle,
137                                           const PCommandImageProvider& _pImageProvider,
138                                           const OUString & sModuleId )
139         :Window( _pParent, _nStyle )
140         ,m_pDispatcher( nullptr )
141         ,m_pImageProvider( _pImageProvider )
142         ,m_eImageSize( eSmall )
143         ,m_pToolbar( nullptr )
144         ,m_sModuleId( sModuleId )
145     {
146         implInit( );
147     }
148 
~NavigationToolBar()149     NavigationToolBar::~NavigationToolBar( )
150     {
151         disposeOnce();
152     }
153 
dispose()154     void NavigationToolBar::dispose()
155     {
156         for (auto & childWin : m_aChildWins)
157             childWin.disposeAndClear();
158         m_aChildWins.clear();
159         m_pToolbar.disposeAndClear();
160         vcl::Window::dispose();
161     }
162 
setDispatcher(const IFeatureDispatcher * _pDispatcher)163     void NavigationToolBar::setDispatcher( const IFeatureDispatcher* _pDispatcher )
164     {
165         m_pDispatcher = _pDispatcher;
166 
167         m_pToolbar->setDispatcher( _pDispatcher );
168 
169         RecordPositionInput* pPositionWindow = static_cast< RecordPositionInput* >( m_pToolbar->GetItemWindow( ToolBoxItemId(FormFeature::MoveAbsolute) ) );
170         OSL_ENSURE( pPositionWindow, "NavigationToolBar::setDispatcher: can't forward the dispatcher to the position window!" );
171         if ( pPositionWindow )
172             pPositionWindow->setDispatcher( _pDispatcher );
173 
174         // update feature states
175         for ( ToolBox::ImplToolItems::size_type nPos = 0; nPos < m_pToolbar->GetItemCount(); ++nPos )
176         {
177             sal_uInt16 nItemId = sal_uInt16(m_pToolbar->GetItemId( nPos ));
178 
179             if ( ( nItemId == LID_RECORD_LABEL ) || ( nItemId == LID_RECORD_FILLER ) )
180                 continue;
181 
182             // is this item enabled?
183             bool bEnabled = m_pDispatcher && m_pDispatcher->isEnabled( nItemId );
184             implEnableItem( nItemId, bEnabled );
185         }
186     }
187 
implEnableItem(sal_uInt16 _nItemId,bool _bEnabled)188     void NavigationToolBar::implEnableItem( sal_uInt16 _nItemId, bool _bEnabled )
189     {
190         m_pToolbar->EnableItem( ToolBoxItemId(_nItemId), _bEnabled );
191 
192         if ( _nItemId == FormFeature::MoveAbsolute )
193             m_pToolbar->EnableItem( ToolBoxItemId(LID_RECORD_LABEL), _bEnabled );
194 
195         if ( _nItemId == FormFeature::TotalRecords )
196             m_pToolbar->EnableItem( ToolBoxItemId(LID_RECORD_FILLER), _bEnabled );
197     }
198 
enableFeature(sal_Int16 _nFeatureId,bool _bEnabled)199     void NavigationToolBar::enableFeature( sal_Int16 _nFeatureId, bool _bEnabled )
200     {
201         DBG_ASSERT( m_pToolbar->GetItemPos( ToolBoxItemId(_nFeatureId) ) != ToolBox::ITEM_NOTFOUND,
202             "NavigationToolBar::enableFeature: invalid id!" );
203 
204         implEnableItem( static_cast<sal_uInt16>(_nFeatureId), _bEnabled );
205     }
206 
checkFeature(sal_Int16 _nFeatureId,bool _bEnabled)207     void NavigationToolBar::checkFeature( sal_Int16 _nFeatureId, bool _bEnabled )
208     {
209         DBG_ASSERT( m_pToolbar->GetItemPos( ToolBoxItemId(_nFeatureId) ) != ToolBox::ITEM_NOTFOUND,
210             "NavigationToolBar::checkFeature: invalid id!" );
211 
212         m_pToolbar->CheckItem( ToolBoxItemId(_nFeatureId), _bEnabled );
213     }
214 
setFeatureText(sal_Int16 _nFeatureId,const OUString & _rText)215     void NavigationToolBar::setFeatureText( sal_Int16 _nFeatureId, const OUString& _rText )
216     {
217         DBG_ASSERT( m_pToolbar->GetItemPos( ToolBoxItemId(_nFeatureId) ) != ToolBox::ITEM_NOTFOUND,
218             "NavigationToolBar::checkFeature: invalid id!" );
219 
220         vcl::Window* pItemWindow = m_pToolbar->GetItemWindow( ToolBoxItemId(_nFeatureId) );
221         if ( pItemWindow )
222         {
223             if (_nFeatureId == FormFeature::TotalRecords)
224                 static_cast<LabelItemWindow*>(pItemWindow)->set_label(_rText);
225             else if (_nFeatureId == FormFeature::MoveAbsolute)
226                 static_cast<RecordPositionInput*>(pItemWindow)->set_text(_rText);
227         }
228         else
229             m_pToolbar->SetItemText( ToolBoxItemId(_nFeatureId), _rText );
230     }
231 
implInit()232     void NavigationToolBar::implInit( )
233     {
234         m_pToolbar = VclPtr<ImplNavToolBar>::Create( this );
235         m_pToolbar->Show();
236 
237         // need the SfxApplication for retrieving information about our
238         // items. We could duplicate all the information here in our lib
239         // (such as the item text and the image), but why should we?
240 
241         static struct FeatureDescription
242         {
243             sal_uInt16      nId;
244             bool        bRepeat;
245             bool        bItemWindow;
246         } const aSupportedFeatures[] =
247         {
248             { LID_RECORD_LABEL,                     false, true },
249             { FormFeature::MoveAbsolute,            false, true },
250             { LID_RECORD_FILLER,                    false, true },
251             { FormFeature::TotalRecords,            false, true },
252             { FormFeature::MoveToFirst,             true,  false },
253             { FormFeature::MoveToPrevious,          true,  false },
254             { FormFeature::MoveToNext,              true,  false },
255             { FormFeature::MoveToLast,              true,  false },
256             { FormFeature::MoveToInsertRow,         false, false },
257             { 0, false, false },
258             { FormFeature::SaveRecordChanges,       false, false },
259             { FormFeature::UndoRecordChanges,       false, false },
260             { FormFeature::DeleteRecord,            false, false },
261             { FormFeature::ReloadForm,              false, false },
262             { FormFeature::RefreshCurrentControl,   false, false },
263             { 0, false, false },
264             { FormFeature::SortAscending,           false, false },
265             { FormFeature::SortDescending,          false, false },
266             { FormFeature::InteractiveSort,         false, false },
267             { FormFeature::AutoFilter,              false, false },
268             { FormFeature::InteractiveFilter,       false, false },
269             { FormFeature::ToggleApplyFilter,       false, false },
270             { FormFeature::RemoveFilterAndSort,     false, false },
271         };
272 
273         FeatureDescription const * pSupportedFeatures = aSupportedFeatures;
274         FeatureDescription const * pSupportedFeaturesEnd = aSupportedFeatures + SAL_N_ELEMENTS( aSupportedFeatures );
275         for ( ; pSupportedFeatures < pSupportedFeaturesEnd; ++pSupportedFeatures )
276         {
277             if ( pSupportedFeatures->nId )
278             {   // it's _not_ a separator
279 
280                 // insert the entry
281                 m_pToolbar->InsertItem( ToolBoxItemId(pSupportedFeatures->nId), OUString(), pSupportedFeatures->bRepeat ? ToolBoxItemBits::REPEAT : ToolBoxItemBits::NONE );
282                 m_pToolbar->SetQuickHelpText( ToolBoxItemId(pSupportedFeatures->nId), OUString() );  // TODO
283 
284                 if ( !isArtificialItem( pSupportedFeatures->nId ) )
285                 {
286                     OUString sCommandURL( lcl_getCommandURL( pSupportedFeatures->nId ) );
287                     m_pToolbar->SetItemCommand( ToolBoxItemId(pSupportedFeatures->nId), sCommandURL );
288                     auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(sCommandURL, m_sModuleId);
289                     m_pToolbar->SetQuickHelpText(ToolBoxItemId(pSupportedFeatures->nId),
290                             vcl::CommandInfoProvider::GetLabelForCommand(aProperties));
291                 }
292 
293                 if ( pSupportedFeatures->bItemWindow )
294                 {
295                     vcl::Window* pItemWindow = nullptr;
296                     if ( FormFeature::MoveAbsolute == pSupportedFeatures->nId )
297                     {
298                         pItemWindow = VclPtr<RecordPositionInput>::Create( m_pToolbar );
299                         static_cast< RecordPositionInput* >( pItemWindow )->setDispatcher( m_pDispatcher );
300                     }
301                     else if (pSupportedFeatures->nId == LID_RECORD_FILLER)
302                         pItemWindow = VclPtr<LabelItemWindow>::Create(m_pToolbar, getLabelString(RID_STR_LABEL_OF));
303                     else if (pSupportedFeatures->nId == LID_RECORD_LABEL)
304                         pItemWindow = VclPtr<LabelItemWindow>::Create(m_pToolbar, getLabelString(RID_STR_LABEL_RECORD));
305                     else if (pSupportedFeatures->nId == FormFeature::TotalRecords)
306                         pItemWindow = VclPtr<LabelItemWindow>::Create(m_pToolbar, "");
307 
308                     m_aChildWins.emplace_back(pItemWindow );
309                     m_pToolbar->SetItemWindow( ToolBoxItemId(pSupportedFeatures->nId), pItemWindow );
310                 }
311             }
312             else
313             {   // a separator
314                 m_pToolbar->InsertSeparator( );
315             }
316         }
317 
318         forEachItemWindow( &NavigationToolBar::adjustItemWindowWidth );
319 
320         implUpdateImages();
321     }
322 
323 
implUpdateImages()324     void NavigationToolBar::implUpdateImages()
325     {
326         OSL_ENSURE( m_pImageProvider, "NavigationToolBar::implUpdateImages: no image provider => no images!" );
327         if ( !m_pImageProvider )
328             return;
329 
330         const ToolBox::ImplToolItems::size_type nItemCount = m_pToolbar->GetItemCount();
331 
332         // collect the FormFeatures in the toolbar
333         std::vector<sal_Int16> aFormFeatures;
334         aFormFeatures.reserve( nItemCount );
335 
336         for ( ToolBox::ImplToolItems::size_type i=0; i<nItemCount; ++i )
337         {
338             ToolBoxItemId nId = m_pToolbar->GetItemId( i );
339             if ( ( ToolBoxItemType::BUTTON == m_pToolbar->GetItemType( i ) ) && !isArtificialItem( sal_uInt16(nId) ) )
340                 aFormFeatures.push_back( sal_uInt16(nId) );
341         }
342 
343         // translate them into command URLs
344         css::uno::Sequence< OUString > aCommandURLs( aFormFeatures.size() );
345         size_t i = 0;
346         for (auto const& formFeature : aFormFeatures)
347         {
348             aCommandURLs[i++] = lcl_getCommandURL(formFeature);
349         }
350 
351         // retrieve the images for the command URLs
352         std::vector<Image> aCommandImages = m_pImageProvider->getCommandImages( aCommandURLs, m_eImageSize == eLarge );
353 
354         // and set them at the toolbar
355         auto commandImage = aCommandImages.begin();
356         for (sal_Int16 formFeature : aFormFeatures)
357         {
358             m_pToolbar->SetItemImage( ToolBoxItemId(formFeature), *commandImage );
359             ++commandImage;
360         }
361 
362         // parts of our layout is dependent on the size of our icons
363         Resize();
364     }
365 
366 
implSetImageSize(ImageSize _eSize)367     void NavigationToolBar::implSetImageSize( ImageSize _eSize )
368     {
369         if ( _eSize != m_eImageSize )
370         {
371             m_eImageSize = _eSize;
372             implUpdateImages();
373         }
374     }
375 
376 
SetImageSize(ImageSize _eSize)377     void NavigationToolBar::SetImageSize( ImageSize _eSize )
378     {
379         implSetImageSize( _eSize );
380     }
381 
382 
ShowFunctionGroup(FunctionGroup _eGroup,bool _bShow)383     void NavigationToolBar::ShowFunctionGroup( FunctionGroup _eGroup, bool _bShow )
384     {
385         const sal_uInt16* pGroupIds = nullptr;
386 
387         switch ( _eGroup )
388         {
389         case ePosition:
390         {
391             static const sal_uInt16 aPositionIds[] = {
392                 LID_RECORD_LABEL, FormFeature::MoveAbsolute, LID_RECORD_FILLER, FormFeature::TotalRecords, 0
393             };
394             pGroupIds = aPositionIds;
395         }
396         break;
397         case eNavigation:
398         {
399             static const sal_uInt16 aNavigationIds[] = {
400                 FormFeature::MoveToFirst, FormFeature::MoveToPrevious, FormFeature::MoveToNext, FormFeature::MoveToLast, FormFeature::MoveToInsertRow, 0
401             };
402             pGroupIds = aNavigationIds;
403         }
404         break;
405         case eRecordActions:
406         {
407             static const sal_uInt16 aActionIds[] = {
408                 FormFeature::SaveRecordChanges, FormFeature::UndoRecordChanges, FormFeature::DeleteRecord, FormFeature::ReloadForm, FormFeature::RefreshCurrentControl, 0
409             };
410             pGroupIds = aActionIds;
411         }
412         break;
413         case eFilterSort:
414         {
415             static const sal_uInt16 aFilterSortIds[] = {
416                 FormFeature::SortAscending, FormFeature::SortDescending, FormFeature::InteractiveSort, FormFeature::AutoFilter, FormFeature::InteractiveFilter, FormFeature::ToggleApplyFilter, FormFeature::RemoveFilterAndSort, 0
417             };
418             pGroupIds = aFilterSortIds;
419         }
420         break;
421         default:
422             OSL_FAIL( "NavigationToolBar::ShowFunctionGroup: invalid group id!" );
423         }
424 
425         if ( pGroupIds )
426             while ( *pGroupIds )
427                 m_pToolbar->ShowItem( ToolBoxItemId(*pGroupIds++), _bShow );
428     }
429 
430 
IsFunctionGroupVisible(FunctionGroup _eGroup)431     bool NavigationToolBar::IsFunctionGroupVisible( FunctionGroup _eGroup )
432     {
433         sal_uInt16 nIndicatorItem = 0;
434         switch ( _eGroup )
435         {
436         case ePosition      : nIndicatorItem = LID_RECORD_LABEL;    break;
437         case eNavigation    : nIndicatorItem = FormFeature::MoveToFirst; break;
438         case eRecordActions : nIndicatorItem = FormFeature::SaveRecordChanges;  break;
439         case eFilterSort    : nIndicatorItem = FormFeature::SortAscending;       break;
440         default:
441             OSL_FAIL( "NavigationToolBar::IsFunctionGroupVisible: invalid group id!" );
442         }
443 
444         return m_pToolbar->IsItemVisible( ToolBoxItemId(nIndicatorItem) );
445     }
446 
447 
StateChanged(StateChangedType nType)448     void NavigationToolBar::StateChanged( StateChangedType nType )
449     {
450         Window::StateChanged( nType );
451 
452         switch ( nType )
453         {
454             case StateChangedType::Zoom:
455 //                m_pToolbar->SetZoom( GetZoom() );
456 //                forEachItemWindow( setItemWindowZoom, NULL );
457                 // the ToolBox class is not zoomable at the moment, so
458                 // we better have no zoom at all instead of only half a zoom ...
459                 break;
460 
461             case StateChangedType::ControlFont:
462                 forEachItemWindow( &NavigationToolBar::setItemControlFont );
463                 forEachItemWindow( &NavigationToolBar::adjustItemWindowWidth );
464                 break;
465 
466             case StateChangedType::ControlForeground:
467                 forEachItemWindow( &NavigationToolBar::setItemControlForeground );
468                 break;
469 
470             case StateChangedType::Mirroring:
471             {
472                 sal_Bool bIsRTLEnabled( IsRTLEnabled() );
473                 m_pToolbar->EnableRTL( bIsRTLEnabled );
474                 forEachItemWindow( &NavigationToolBar::enableItemRTL, &bIsRTLEnabled );
475                 Resize();
476             }
477             break;
478             default:;
479         }
480     }
481 
Resize()482     void NavigationToolBar::Resize()
483     {
484         // resize/position the toolbox as a whole
485         sal_Int32 nToolbarHeight = m_pToolbar->CalcWindowSizePixel().Height();
486 
487         sal_Int32 nMyHeight = GetOutputSizePixel().Height();
488         m_pToolbar->SetPosSizePixel( Point( 0, ( nMyHeight - nToolbarHeight ) / 2 ),
489                                      Size( GetSizePixel().Width(), nToolbarHeight ) );
490 
491         Window::Resize();
492     }
493 
SetControlBackground()494     void NavigationToolBar::SetControlBackground()
495     {
496         Window::SetControlBackground();
497         m_pToolbar->SetControlBackground();
498         forEachItemWindow( &NavigationToolBar::setItemBackground, nullptr );
499 
500         implUpdateImages();
501     }
502 
SetControlBackground(const Color & _rColor)503     void NavigationToolBar::SetControlBackground( const Color& _rColor )
504     {
505         Window::SetControlBackground( _rColor );
506         m_pToolbar->SetControlBackground( _rColor );
507         forEachItemWindow( &NavigationToolBar::setItemBackground, &_rColor );
508 
509         implUpdateImages();
510     }
511 
SetTextLineColor()512     void NavigationToolBar::SetTextLineColor( )
513     {
514         Window::SetTextLineColor( );
515         m_pToolbar->SetTextLineColor( );
516         forEachItemWindow( &NavigationToolBar::setTextLineColor, nullptr );
517     }
518 
SetTextLineColor(const Color & _rColor)519     void NavigationToolBar::SetTextLineColor( const Color& _rColor )
520     {
521         Window::SetTextLineColor( _rColor );
522         m_pToolbar->SetTextLineColor( _rColor );
523         forEachItemWindow( &NavigationToolBar::setTextLineColor, &_rColor );
524     }
525 
forEachItemWindow(ItemWindowHandler _handler)526     void NavigationToolBar::forEachItemWindow( ItemWindowHandler _handler )
527     {
528         for ( ToolBox::ImplToolItems::size_type item = 0; item < m_pToolbar->GetItemCount(); ++item )
529         {
530             ToolBoxItemId nItemId = m_pToolbar->GetItemId( item );
531             vcl::Window* pItemWindow = m_pToolbar->GetItemWindow( nItemId );
532             if ( pItemWindow )
533                 (this->*_handler)( sal_uInt16(nItemId), pItemWindow );
534         }
535     }
536 
forEachItemWindow(ItemWindowHandler2 _handler,const void * _pParam)537     void NavigationToolBar::forEachItemWindow( ItemWindowHandler2 _handler, const void* _pParam )
538     {
539         for ( ToolBox::ImplToolItems::size_type item = 0; item < m_pToolbar->GetItemCount(); ++item )
540         {
541             ToolBoxItemId nItemId = m_pToolbar->GetItemId( item );
542             vcl::Window* pItemWindow = m_pToolbar->GetItemWindow( nItemId );
543             if ( pItemWindow )
544                 (*_handler)( sal_uInt16(nItemId), pItemWindow, _pParam );
545         }
546     }
547 
setItemBackground(sal_uInt16,vcl::Window * _pItemWindow,const void * _pColor)548     void NavigationToolBar::setItemBackground( sal_uInt16 /* _nItemId */, vcl::Window* _pItemWindow, const void* _pColor )
549     {
550         if ( _pColor )
551             _pItemWindow->SetControlBackground( *static_cast< const Color* >( _pColor ) );
552         else
553             _pItemWindow->SetControlBackground();
554     }
555 
setTextLineColor(sal_uInt16,vcl::Window * _pItemWindow,const void * _pColor)556     void NavigationToolBar::setTextLineColor( sal_uInt16 /* _nItemId */, vcl::Window* _pItemWindow, const void* _pColor )
557     {
558         if ( _pColor )
559             _pItemWindow->SetTextLineColor( *static_cast< const Color* >( _pColor ) );
560         else
561             _pItemWindow->SetTextLineColor();
562     }
563 
setItemControlFont(sal_uInt16,vcl::Window * _pItemWindow) const564     void NavigationToolBar::setItemControlFont( sal_uInt16 /* _nItemId */, vcl::Window* _pItemWindow ) const
565     {
566         if ( IsControlFont() )
567             _pItemWindow->SetControlFont( GetControlFont() );
568         else
569             _pItemWindow->SetControlFont( );
570     }
571 
setItemControlForeground(sal_uInt16,vcl::Window * _pItemWindow) const572     void NavigationToolBar::setItemControlForeground( sal_uInt16 /* _nItemId */, vcl::Window* _pItemWindow ) const
573     {
574         if ( IsControlForeground() )
575             _pItemWindow->SetControlForeground( GetControlForeground() );
576         else
577             _pItemWindow->SetControlForeground( );
578         _pItemWindow->SetTextColor( GetTextColor() );
579     }
580 
adjustItemWindowWidth(sal_uInt16 _nItemId,vcl::Window * _pItemWindow) const581     void NavigationToolBar::adjustItemWindowWidth( sal_uInt16 _nItemId, vcl::Window* _pItemWindow ) const
582     {
583         int nHeight = 0;
584 
585         OUString sItemText;
586         switch ( _nItemId )
587         {
588         case LID_RECORD_LABEL:
589             sItemText = getLabelString( RID_STR_LABEL_RECORD );
590             break;
591 
592         case LID_RECORD_FILLER:
593             sItemText = getLabelString( RID_STR_LABEL_OF );
594             break;
595 
596         case FormFeature::MoveAbsolute:
597             sItemText = "12345678";
598             nHeight = _pItemWindow->get_preferred_size().Height();
599             break;
600 
601         case FormFeature::TotalRecords:
602             sItemText = "123456";
603             break;
604         }
605 
606         if (nHeight == 0)
607             nHeight = _pItemWindow->GetTextHeight() + 4;
608 
609         Size aSize(_pItemWindow->GetTextWidth(sItemText), nHeight);
610         aSize.AdjustWidth(6 );
611         _pItemWindow->SetSizePixel( aSize );
612 
613         m_pToolbar->SetItemWindow( ToolBoxItemId(_nItemId), _pItemWindow );
614     }
615 
enableItemRTL(sal_uInt16,vcl::Window * _pItemWindow,const void * _pIsRTLEnabled)616     void NavigationToolBar::enableItemRTL( sal_uInt16 /*_nItemId*/, vcl::Window* _pItemWindow, const void* _pIsRTLEnabled )
617     {
618         _pItemWindow->EnableRTL( *static_cast< const sal_Bool* >( _pIsRTLEnabled ) );
619     }
620 
RecordPositionInput(vcl::Window * pParent)621     RecordPositionInput::RecordPositionInput(vcl::Window* pParent)
622         : RecordItemWindow(pParent)
623         , m_pDispatcher( nullptr )
624     {
625     }
626 
setDispatcher(const IFeatureDispatcher * _pDispatcher)627     void RecordPositionInput::setDispatcher( const IFeatureDispatcher* _pDispatcher )
628     {
629         m_pDispatcher = _pDispatcher;
630     }
631 
PositionFired(sal_Int64 nRecord)632     void RecordPositionInput::PositionFired(sal_Int64 nRecord)
633     {
634         if (!m_pDispatcher)
635             return;
636         m_pDispatcher->dispatchWithArgument( FormFeature::MoveAbsolute, "Position", makeAny( static_cast<sal_Int32>(nRecord) ) );
637     }
638 
639 }   // namespace frm
640 
641 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
642