1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26 
27 #include "navtoolbar.hxx"
28 #include "frm_resource.hxx"
29 #include "featuredispatcher.hxx"
30 #include "frm_resource.hrc"
31 #include "commandimageprovider.hxx"
32 #include "commanddescriptionprovider.hxx"
33 
34 #include <com/sun/star/uno/Any.hxx>
35 #include <com/sun/star/form/runtime/FormFeature.hpp>
36 
37 #include <sfx2/imgmgr.hxx>
38 #include <vcl/fixed.hxx>
39 
40 #include <memory>
41 
42 #define LID_RECORD_LABEL    1000
43 #define LID_RECORD_FILLER   1001
44 
45 //.........................................................................
46 namespace frm
47 {
48 //.........................................................................
49 
50     using ::com::sun::star::uno::makeAny;
51     namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
52 
53     //=====================================================================
54     //.....................................................................
55     namespace
56     {
isArtificialItem(sal_Int16 _nFeatureId)57         static bool isArtificialItem( sal_Int16 _nFeatureId )
58         {
59             return ( _nFeatureId == LID_RECORD_LABEL )
60                 || ( _nFeatureId == LID_RECORD_FILLER );
61         }
62 
getLabelString(sal_uInt16 _nResId)63         static String getLabelString( sal_uInt16 _nResId )
64         {
65             String sLabel = String::CreateFromAscii( " " );
66             sLabel += String( FRM_RES_STRING( _nResId ) );
67             sLabel += String::CreateFromAscii( " " );
68             return sLabel;
69         }
70 
lcl_getCommandURL(const sal_Int16 _nFormFeature)71         ::rtl::OUString lcl_getCommandURL( const sal_Int16 _nFormFeature )
72         {
73             const sal_Char* pAsciiCommandName = NULL;
74             switch ( _nFormFeature )
75             {
76                 case FormFeature::MoveAbsolute          : pAsciiCommandName = "AbsoluteRecord";     break;
77                 case FormFeature::TotalRecords          : pAsciiCommandName = "RecTotal";           break;
78                 case FormFeature::MoveToFirst           : pAsciiCommandName = "FirstRecord";        break;
79                 case FormFeature::MoveToPrevious        : pAsciiCommandName = "PrevRecord";         break;
80                 case FormFeature::MoveToNext            : pAsciiCommandName = "NextRecord";         break;
81                 case FormFeature::MoveToLast            : pAsciiCommandName = "LastRecord";         break;
82                 case FormFeature::SaveRecordChanges     : pAsciiCommandName = "RecSave";            break;
83                 case FormFeature::UndoRecordChanges     : pAsciiCommandName = "RecUndo";            break;
84                 case FormFeature::MoveToInsertRow       : pAsciiCommandName = "NewRecord";          break;
85                 case FormFeature::DeleteRecord          : pAsciiCommandName = "DeleteRecord";       break;
86                 case FormFeature::ReloadForm            : pAsciiCommandName = "Refresh";            break;
87                 case FormFeature::RefreshCurrentControl : pAsciiCommandName = "RefreshFormControl"; break;
88                 case FormFeature::SortAscending         : pAsciiCommandName = "Sortup";             break;
89                 case FormFeature::SortDescending        : pAsciiCommandName = "SortDown";           break;
90                 case FormFeature::InteractiveSort       : pAsciiCommandName = "OrderCrit";          break;
91                 case FormFeature::AutoFilter            : pAsciiCommandName = "AutoFilter";         break;
92                 case FormFeature::InteractiveFilter     : pAsciiCommandName = "FilterCrit";         break;
93                 case FormFeature::ToggleApplyFilter     : pAsciiCommandName = "FormFiltered";       break;
94                 case FormFeature::RemoveFilterAndSort   : pAsciiCommandName = "RemoveFilterSort";   break;
95             }
96             if ( pAsciiCommandName != NULL )
97                 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:" ) ) + ::rtl::OUString::createFromAscii( pAsciiCommandName );
98 
99             OSL_ENSURE( false, "lcl_getCommandURL: unknown FormFeature!" );
100             return ::rtl::OUString();
101         }
102     }
103 
104     //=====================================================================
105     //= ImplNavToolBar
106     //=====================================================================
107     class ImplNavToolBar : public ToolBox
108     {
109     protected:
110         const IFeatureDispatcher*   m_pDispatcher;
111 
112     public:
ImplNavToolBar(Window * _pParent)113         ImplNavToolBar( Window* _pParent )
114             :ToolBox( _pParent, WB_3DLOOK )
115             ,m_pDispatcher( NULL )
116         {
117         }
118 
setDispatcher(const IFeatureDispatcher * _pDispatcher)119         void setDispatcher( const IFeatureDispatcher* _pDispatcher )
120         {
121             m_pDispatcher = _pDispatcher;
122         }
123 
124     protected:
125         // ToolBox overridables
126         virtual void        Select();
127 
128     };
129 
130     //---------------------------------------------------------------------
Select()131     void ImplNavToolBar::Select()
132     {
133         if ( m_pDispatcher )
134         {
135             if ( !m_pDispatcher->isEnabled( GetCurItemId() ) )
136                 // the toolbox is a little bit buggy: With TIB_REPEAT, it sometimes
137                 // happens that a select is reported, even though the respective
138                 // item has just been disabled.
139                 return;
140             m_pDispatcher->dispatch( GetCurItemId() );
141         }
142     }
143 
144     //=====================================================================
145     //= NavigationToolBar
146     //=====================================================================
DBG_NAME(NavigationToolBar)147     DBG_NAME( NavigationToolBar )
148     //---------------------------------------------------------------------
149     NavigationToolBar::NavigationToolBar( Window* _pParent, WinBits _nStyle, const PCommandImageProvider& _pImageProvider,
150             const PCommandDescriptionProvider& _pDescriptionProvider )
151         :Window( _pParent, _nStyle )
152         ,m_pDispatcher( NULL )
153         ,m_pImageProvider( _pImageProvider )
154         ,m_pDescriptionProvider( _pDescriptionProvider )
155         ,m_eImageSize( eSmall )
156         ,m_pToolbar( NULL )
157     {
158         DBG_CTOR( NavigationToolBar, NULL );
159         implInit( );
160     }
161 
162     //---------------------------------------------------------------------
~NavigationToolBar()163     NavigationToolBar::~NavigationToolBar( )
164     {
165         for (   ::std::vector< Window* >::iterator loopChildWins = m_aChildWins.begin();
166                 loopChildWins != m_aChildWins.end();
167                 ++loopChildWins
168             )
169         {
170             delete *loopChildWins;
171         }
172         delete m_pToolbar;
173         DBG_DTOR( NavigationToolBar, NULL );
174     }
175 
176     //---------------------------------------------------------------------
setDispatcher(const IFeatureDispatcher * _pDispatcher)177     void NavigationToolBar::setDispatcher( const IFeatureDispatcher* _pDispatcher )
178     {
179         m_pDispatcher = _pDispatcher;
180 
181         m_pToolbar->setDispatcher( _pDispatcher );
182 
183         RecordPositionInput* pPositionWindow = static_cast< RecordPositionInput* >( m_pToolbar->GetItemWindow( FormFeature::MoveAbsolute ) );
184         OSL_ENSURE( pPositionWindow, "NavigationToolBar::setDispatcher: can't forward the dispatcher to the position window!" );
185         if ( pPositionWindow )
186             pPositionWindow->setDispatcher( _pDispatcher );
187 
188         updateFeatureStates( );
189     }
190 
191     //---------------------------------------------------------------------
updateFeatureStates()192     void NavigationToolBar::updateFeatureStates( )
193     {
194         for ( sal_uInt16 nPos = 0; nPos < m_pToolbar->GetItemCount(); ++nPos )
195         {
196             sal_uInt16 nItemId = m_pToolbar->GetItemId( nPos );
197 
198             if ( ( nItemId == LID_RECORD_LABEL ) || ( nItemId == LID_RECORD_FILLER ) )
199                 continue;
200 
201             // is this item enabled?
202             bool bEnabled = m_pDispatcher ? m_pDispatcher->isEnabled( nItemId ) : false;
203             implEnableItem( nItemId, bEnabled );
204         }
205     }
206 
207     //---------------------------------------------------------------------
implEnableItem(sal_uInt16 _nItemId,bool _bEnabled)208     void NavigationToolBar::implEnableItem( sal_uInt16 _nItemId, bool _bEnabled )
209     {
210         m_pToolbar->EnableItem( _nItemId, _bEnabled );
211 
212         if ( _nItemId == FormFeature::MoveAbsolute )
213             m_pToolbar->EnableItem( LID_RECORD_LABEL, _bEnabled );
214 
215         if ( _nItemId == FormFeature::TotalRecords )
216             m_pToolbar->EnableItem( LID_RECORD_FILLER, _bEnabled );
217     }
218 
219     //---------------------------------------------------------------------
enableFeature(sal_Int16 _nFeatureId,bool _bEnabled)220     void NavigationToolBar::enableFeature( sal_Int16 _nFeatureId, bool _bEnabled )
221     {
222         DBG_ASSERT( m_pToolbar->GetItemPos( (sal_uInt16)_nFeatureId ) != TOOLBOX_ITEM_NOTFOUND,
223             "NavigationToolBar::enableFeature: invalid id!" );
224 
225         implEnableItem( (sal_uInt16)_nFeatureId, _bEnabled );
226     }
227 
228     //---------------------------------------------------------------------
checkFeature(sal_Int16 _nFeatureId,bool _bEnabled)229     void NavigationToolBar::checkFeature( sal_Int16 _nFeatureId, bool _bEnabled )
230     {
231         DBG_ASSERT( m_pToolbar->GetItemPos( (sal_uInt16)_nFeatureId ) != TOOLBOX_ITEM_NOTFOUND,
232             "NavigationToolBar::checkFeature: invalid id!" );
233 
234         m_pToolbar->CheckItem( (sal_uInt16)_nFeatureId, _bEnabled );
235     }
236 
237     //---------------------------------------------------------------------
setFeatureText(sal_Int16 _nFeatureId,const::rtl::OUString & _rText)238     void NavigationToolBar::setFeatureText( sal_Int16 _nFeatureId, const ::rtl::OUString& _rText )
239     {
240         DBG_ASSERT( m_pToolbar->GetItemPos( (sal_uInt16)_nFeatureId ) != TOOLBOX_ITEM_NOTFOUND,
241             "NavigationToolBar::checkFeature: invalid id!" );
242 
243         Window* pItemWindow = m_pToolbar->GetItemWindow( (sal_uInt16)_nFeatureId );
244         if ( pItemWindow )
245             pItemWindow->SetText( _rText );
246         else
247             m_pToolbar->SetItemText( (sal_uInt16)_nFeatureId, _rText );
248     }
249 
250     //---------------------------------------------------------------------
implInit()251     void NavigationToolBar::implInit( )
252     {
253         m_pToolbar = new ImplNavToolBar( this );
254         m_pToolbar->SetOutStyle( TOOLBOX_STYLE_FLAT );
255         m_pToolbar->Show();
256 
257         // need the SfxApplication for retrieving informations about our
258         // items. We could duplicate all the information here in our lib
259         // (such as the item text and the image), but why should we?
260 
261         struct FeatureDescription
262         {
263             sal_uInt16      nId;
264             bool        bRepeat;
265             bool        bItemWindow;
266         } aSupportedFeatures[] =
267         {
268             { LID_RECORD_LABEL,                     false, true },
269             { FormFeature::MoveAbsolute,            false, true },
270             { LID_RECORD_FILLER,                    false, true },
271             { FormFeature::TotalRecords,            false, true },
272             { FormFeature::MoveToFirst,             true,  false },
273             { FormFeature::MoveToPrevious,          true,  false },
274             { FormFeature::MoveToNext,              true,  false },
275             { FormFeature::MoveToLast,              true,  false },
276             { FormFeature::MoveToInsertRow,         false, false },
277             { 0, false, false },
278             { FormFeature::SaveRecordChanges,       false, false },
279             { FormFeature::UndoRecordChanges,       false, false },
280             { FormFeature::DeleteRecord,            false, false },
281             { FormFeature::ReloadForm,              false, false },
282             { FormFeature::RefreshCurrentControl,   false, false },
283             { 0, false, false },
284             { FormFeature::SortAscending,           false, false },
285             { FormFeature::SortDescending,          false, false },
286             { FormFeature::InteractiveSort,         false, false },
287             { FormFeature::AutoFilter,              false, false },
288             { FormFeature::InteractiveFilter,       false, false },
289             { FormFeature::ToggleApplyFilter,       false, false },
290             { FormFeature::RemoveFilterAndSort,     false, false },
291         };
292 
293         size_t nSupportedFeatures = sizeof( aSupportedFeatures ) / sizeof( aSupportedFeatures[0] );
294         FeatureDescription* pSupportedFeatures = aSupportedFeatures;
295         FeatureDescription* pSupportedFeaturesEnd = aSupportedFeatures + nSupportedFeatures;
296         for ( ; pSupportedFeatures < pSupportedFeaturesEnd; ++pSupportedFeatures )
297         {
298             if ( pSupportedFeatures->nId )
299             {   // it's _not_ a separator
300 
301                 // insert the entry
302                 m_pToolbar->InsertItem( pSupportedFeatures->nId, String(), pSupportedFeatures->bRepeat ? TIB_REPEAT : 0 );
303                 m_pToolbar->SetQuickHelpText( pSupportedFeatures->nId, String() );  // TODO
304 
305                 if ( !isArtificialItem( pSupportedFeatures->nId ) )
306                 {
307                     ::rtl::OUString sCommandURL( lcl_getCommandURL( pSupportedFeatures->nId ) );
308                     m_pToolbar->SetItemCommand( pSupportedFeatures->nId, sCommandURL );
309                     if ( m_pDescriptionProvider )
310                         m_pToolbar->SetQuickHelpText( pSupportedFeatures->nId, m_pDescriptionProvider->getCommandDescription( sCommandURL ) );
311                 }
312 
313                 if ( pSupportedFeatures->bItemWindow )
314                 {
315                     Window* pItemWindow = NULL;
316                     if ( FormFeature::MoveAbsolute == pSupportedFeatures->nId )
317                     {
318                         pItemWindow = new RecordPositionInput( m_pToolbar );
319                         static_cast< RecordPositionInput* >( pItemWindow )->setDispatcher( m_pDispatcher );
320                     }
321                     else if ( LID_RECORD_FILLER == pSupportedFeatures->nId )
322                     {
323                         pItemWindow = new FixedText( m_pToolbar, WB_CENTER | WB_VCENTER );
324 						pItemWindow->SetBackground(Wallpaper(Color(COL_TRANSPARENT)));
325                     }
326                     else
327                     {
328                         pItemWindow = new FixedText( m_pToolbar, WB_VCENTER );
329 						pItemWindow->SetBackground();
330                         pItemWindow->SetPaintTransparent(sal_True);
331                     }
332                     m_aChildWins.push_back( pItemWindow );
333 
334                     switch ( pSupportedFeatures->nId )
335                     {
336                     case LID_RECORD_LABEL:
337                         pItemWindow->SetText( getLabelString( RID_STR_LABEL_RECORD ) );
338                         break;
339 
340                     case LID_RECORD_FILLER:
341                         pItemWindow->SetText( getLabelString( RID_STR_LABEL_OF ) );
342                         break;
343                     }
344 
345                     m_pToolbar->SetItemWindow( pSupportedFeatures->nId, pItemWindow );
346                 }
347             }
348             else
349             {   // a separator
350                 m_pToolbar->InsertSeparator( );
351             }
352         }
353 
354         forEachItemWindow( &NavigationToolBar::adjustItemWindowWidth, NULL );
355 
356         implUpdateImages();
357     }
358 
359     //---------------------------------------------------------------------
implUpdateImages()360     void NavigationToolBar::implUpdateImages()
361     {
362         OSL_ENSURE( m_pImageProvider, "NavigationToolBar::implUpdateImages: no image provider => no images!" );
363         if ( !m_pImageProvider )
364             return;
365 
366         const bool bIsHighContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
367 
368         const sal_uInt16 nItemCount = m_pToolbar->GetItemCount();
369 
370         // collect the FormFeatures in the toolbar
371         typedef ::std::vector< sal_Int16 >  FormFeatures;
372         FormFeatures aFormFeatures;
373         aFormFeatures.reserve( nItemCount );
374 
375         for ( sal_uInt16 i=0; i<nItemCount; ++i )
376         {
377             sal_uInt16 nId = m_pToolbar->GetItemId( i );
378             if ( ( TOOLBOXITEM_BUTTON == m_pToolbar->GetItemType( i ) ) && !isArtificialItem( nId ) )
379                 aFormFeatures.push_back( nId );
380         }
381 
382         // translate them into command URLs
383         CommandURLs aCommandURLs( aFormFeatures.size() );
384         for (   FormFeatures::const_iterator formFeature = aFormFeatures.begin();
385                 formFeature != aFormFeatures.end();
386                 ++formFeature
387             )
388         {
389             aCommandURLs[ formFeature - aFormFeatures.begin() ] = lcl_getCommandURL( *formFeature );
390         }
391 
392         // retrieve the images for the command URLs
393         CommandImages aCommandImages = m_pImageProvider->getCommandImages( aCommandURLs, m_eImageSize == eLarge, bIsHighContrast );
394 
395         // and set them at the toolbar
396         CommandImages::const_iterator commandImage = aCommandImages.begin();
397         for (   FormFeatures::const_iterator formFeature = aFormFeatures.begin();
398                 formFeature != aFormFeatures.end();
399                 ++formFeature, ++commandImage
400             )
401         {
402             m_pToolbar->SetItemImage( *formFeature, *commandImage );
403         }
404 
405         // parts of our layout is dependent on the size of our icons
406         Resize();
407     }
408 
409     //---------------------------------------------------------------------
implSetImageSize(ImageSize _eSize)410     void NavigationToolBar::implSetImageSize( ImageSize _eSize )
411     {
412         if ( _eSize != m_eImageSize )
413         {
414             m_eImageSize = _eSize;
415             implUpdateImages();
416         }
417     }
418 
419     //---------------------------------------------------------------------
SetImageSize(ImageSize _eSize)420     void NavigationToolBar::SetImageSize( ImageSize _eSize )
421     {
422         implSetImageSize( _eSize );
423     }
424 
425     //---------------------------------------------------------------------
ShowFunctionGroup(FunctionGroup _eGroup,bool _bShow)426     void NavigationToolBar::ShowFunctionGroup( FunctionGroup _eGroup, bool _bShow )
427     {
428         const sal_uInt16* pGroupIds = NULL;
429 
430         switch ( _eGroup )
431         {
432         case ePosition:
433         {
434             static const sal_uInt16 aPositionIds[] = {
435                 LID_RECORD_LABEL, FormFeature::MoveAbsolute, LID_RECORD_FILLER, FormFeature::TotalRecords, 0
436             };
437             pGroupIds = aPositionIds;
438         }
439         break;
440         case eNavigation:
441         {
442             static const sal_uInt16 aNavigationIds[] = {
443                 FormFeature::MoveToFirst, FormFeature::MoveToPrevious, FormFeature::MoveToNext, FormFeature::MoveToLast, FormFeature::MoveToInsertRow, 0
444             };
445             pGroupIds = aNavigationIds;
446         }
447         break;
448         case eRecordActions:
449         {
450             static const sal_uInt16 aActionIds[] = {
451                 FormFeature::SaveRecordChanges, FormFeature::UndoRecordChanges, FormFeature::DeleteRecord, FormFeature::ReloadForm, FormFeature::RefreshCurrentControl, 0
452             };
453             pGroupIds = aActionIds;
454         }
455         break;
456         case eFilterSort:
457         {
458             static const sal_uInt16 aFilterSortIds[] = {
459                 FormFeature::SortAscending, FormFeature::SortDescending, FormFeature::InteractiveSort, FormFeature::AutoFilter, FormFeature::InteractiveFilter, FormFeature::ToggleApplyFilter, FormFeature::RemoveFilterAndSort, 0
460             };
461             pGroupIds = aFilterSortIds;
462         }
463         break;
464         default:
465             OSL_ENSURE( sal_False, "NavigationToolBar::ShowFunctionGroup: invalid group id!" );
466         }
467 
468         if ( pGroupIds )
469             while ( *pGroupIds )
470                 m_pToolbar->ShowItem( *pGroupIds++, _bShow );
471     }
472 
473     //---------------------------------------------------------------------
IsFunctionGroupVisible(FunctionGroup _eGroup)474     bool NavigationToolBar::IsFunctionGroupVisible( FunctionGroup _eGroup )
475     {
476         sal_uInt16 nIndicatorItem = 0;
477         switch ( _eGroup )
478         {
479         case ePosition      : nIndicatorItem = LID_RECORD_LABEL;    break;
480         case eNavigation    : nIndicatorItem = FormFeature::MoveToFirst; break;
481         case eRecordActions : nIndicatorItem = FormFeature::SaveRecordChanges;  break;
482         case eFilterSort    : nIndicatorItem = FormFeature::SortAscending;       break;
483         default:
484             OSL_ENSURE( sal_False, "NavigationToolBar::IsFunctionGroupVisible: invalid group id!" );
485         }
486 
487         return m_pToolbar->IsItemVisible( nIndicatorItem );
488     }
489 
490     //------------------------------------------------------------------------------
StateChanged(StateChangedType nType)491     void NavigationToolBar::StateChanged( StateChangedType nType )
492     {
493 	    Window::StateChanged( nType );
494 
495         switch ( nType )
496 	    {
497 		    case STATE_CHANGE_ZOOM:
498 //                m_pToolbar->SetZoom( GetZoom() );
499 //                forEachItemWindow( setItemWindowZoom, NULL );
500                 // the ToolBox class is not zoomable at the moment, so
501                 // we better have no zoom at all instead of only half a zoom ...
502                 break;
503 
504             case STATE_CHANGE_CONTROLFONT:
505                 forEachItemWindow( &NavigationToolBar::setItemControlFont, NULL );
506                 forEachItemWindow( &NavigationToolBar::adjustItemWindowWidth, NULL );
507                 break;
508 
509             case STATE_CHANGE_CONTROLFOREGROUND:
510                 forEachItemWindow( &NavigationToolBar::setItemControlForeground, NULL );
511                 break;
512 
513             case STATE_CHANGE_MIRRORING:
514             {
515                 sal_Bool bIsRTLEnabled( IsRTLEnabled() );
516                 m_pToolbar->EnableRTL( bIsRTLEnabled );
517                 forEachItemWindow( &NavigationToolBar::enableItemRTL, &bIsRTLEnabled );
518                 Resize();
519             }
520             break;
521         }
522     }
523 
524     //---------------------------------------------------------------------
Resize()525     void NavigationToolBar::Resize()
526     {
527         // resize/position the toolbox as a whole
528         sal_Int32 nToolbarHeight = m_pToolbar->CalcWindowSizePixel().Height();
529 
530         sal_Int32 nMyHeight = GetOutputSizePixel().Height();
531         m_pToolbar->SetPosSizePixel( Point( 0, ( nMyHeight - nToolbarHeight ) / 2 ),
532                                      Size( GetSizePixel().Width(), nToolbarHeight ) );
533 
534         Window::Resize();
535     }
536 
537     //---------------------------------------------------------------------
SetControlBackground()538     void NavigationToolBar::SetControlBackground()
539     {
540         Window::SetControlBackground();
541         m_pToolbar->SetControlBackground();
542         forEachItemWindow( &NavigationToolBar::setItemBackground, NULL );
543 
544         // the contrast of the background color may have changed, so force
545         // the images to be rebuild (high contrast requires a possibly different
546         // image set)
547         implUpdateImages();
548     }
549 
550     //---------------------------------------------------------------------
SetControlBackground(const Color & _rColor)551     void NavigationToolBar::SetControlBackground( const Color& _rColor )
552     {
553         Window::SetControlBackground( _rColor );
554         m_pToolbar->SetControlBackground( _rColor );
555         forEachItemWindow( &NavigationToolBar::setItemBackground, &_rColor );
556 
557         // the contrast of the background color may have changed, so force
558         // the images to be rebuild (high contrast requires a possibly different
559         // image set)
560         implUpdateImages();
561     }
562 
563     //---------------------------------------------------------------------
SetTextLineColor()564     void NavigationToolBar::SetTextLineColor( )
565     {
566         Window::SetTextLineColor( );
567         m_pToolbar->SetTextLineColor( );
568         forEachItemWindow( &NavigationToolBar::setTextLineColor, NULL );
569     }
570 
571     //---------------------------------------------------------------------
SetTextLineColor(const Color & _rColor)572     void NavigationToolBar::SetTextLineColor( const Color& _rColor )
573     {
574         Window::SetTextLineColor( _rColor );
575         m_pToolbar->SetTextLineColor( _rColor );
576         forEachItemWindow( &NavigationToolBar::setTextLineColor, &_rColor );
577     }
578 
579     //---------------------------------------------------------------------
forEachItemWindow(ItemWindowHandler _handler,const void * _pParam)580     void NavigationToolBar::forEachItemWindow( ItemWindowHandler _handler, const void* _pParam )
581     {
582         for ( sal_uInt16 item = 0; item < m_pToolbar->GetItemCount(); ++item )
583         {
584             sal_uInt16 nItemId = m_pToolbar->GetItemId( item );
585             Window* pItemWindow = m_pToolbar->GetItemWindow( nItemId );
586             if ( pItemWindow )
587                 (this->*_handler)( nItemId, pItemWindow, _pParam );
588         }
589     }
590 
591     //---------------------------------------------------------------------
setItemBackground(sal_uInt16,Window * _pItemWindow,const void * _pColor) const592     void NavigationToolBar::setItemBackground( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* _pColor ) const
593     {
594         if ( _pColor )
595             _pItemWindow->SetControlBackground( *static_cast< const Color* >( _pColor ) );
596         else
597             _pItemWindow->SetControlBackground();
598     }
599 
600     //---------------------------------------------------------------------
setTextLineColor(sal_uInt16,Window * _pItemWindow,const void * _pColor) const601     void NavigationToolBar::setTextLineColor( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* _pColor ) const
602     {
603         if ( _pColor )
604             _pItemWindow->SetTextLineColor( *static_cast< const Color* >( _pColor ) );
605         else
606             _pItemWindow->SetTextLineColor();
607     }
608 #if 0
609     //---------------------------------------------------------------------
610     void NavigationToolBar::setItemWindowZoom( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const
611     {
612         _pItemWindow->SetZoom( GetZoom() );
613         _pItemWindow->SetZoomedPointFont( IsControlFont() ? GetControlFont() : GetPointFont() );
614     }
615 #endif
616     //---------------------------------------------------------------------
setItemControlFont(sal_uInt16,Window * _pItemWindow,const void *) const617     void NavigationToolBar::setItemControlFont( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const
618     {
619         if ( IsControlFont() )
620             _pItemWindow->SetControlFont( GetControlFont() );
621         else
622             _pItemWindow->SetControlFont( );
623     }
624 
625     //---------------------------------------------------------------------
setItemControlForeground(sal_uInt16,Window * _pItemWindow,const void *) const626     void NavigationToolBar::setItemControlForeground( sal_uInt16 /* _nItemId */, Window* _pItemWindow, const void* /* _pParam */ ) const
627     {
628         if ( IsControlForeground() )
629             _pItemWindow->SetControlForeground( GetControlForeground() );
630         else
631             _pItemWindow->SetControlForeground( );
632         _pItemWindow->SetTextColor( GetTextColor() );
633     }
634 
635     //---------------------------------------------------------------------
adjustItemWindowWidth(sal_uInt16 _nItemId,Window * _pItemWindow,const void *) const636     void NavigationToolBar::adjustItemWindowWidth( sal_uInt16 _nItemId, Window* _pItemWindow, const void* /* _pParam */ ) const
637     {
638         String sItemText;
639         switch ( _nItemId )
640         {
641         case LID_RECORD_LABEL:
642             sItemText = getLabelString( RID_STR_LABEL_RECORD );
643             break;
644 
645         case LID_RECORD_FILLER:
646             sItemText = getLabelString( RID_STR_LABEL_OF );
647             break;
648 
649         case FormFeature::MoveAbsolute:
650             sItemText = String::CreateFromAscii( "12345678" );
651             break;
652 
653         case FormFeature::TotalRecords:
654             sItemText = String::CreateFromAscii( "123456" );
655             break;
656         }
657 
658         Size aSize( _pItemWindow->GetTextWidth( sItemText ), /* _pItemWindow->GetSizePixel( ).Height() */ _pItemWindow->GetTextHeight() + 4 );
659         aSize.Width() += 6;
660         _pItemWindow->SetSizePixel( aSize );
661 
662         m_pToolbar->SetItemWindow( _nItemId, _pItemWindow );
663     }
664 
665     //---------------------------------------------------------------------
enableItemRTL(sal_uInt16,Window * _pItemWindow,const void * _pIsRTLEnabled) const666     void NavigationToolBar::enableItemRTL( sal_uInt16 /*_nItemId*/, Window* _pItemWindow, const void* _pIsRTLEnabled ) const
667     {
668         _pItemWindow->EnableRTL( *static_cast< const sal_Bool* >( _pIsRTLEnabled ) );
669     }
670 
671     //=====================================================================
672     //= RecordPositionInput
673     //=====================================================================
674     //---------------------------------------------------------------------
RecordPositionInput(Window * _pParent)675     RecordPositionInput::RecordPositionInput( Window* _pParent )
676 	    :NumericField( _pParent, WB_BORDER | WB_VCENTER )
677         ,m_pDispatcher( NULL )
678     {
679 	    SetMin( 1 );
680 	    SetFirst( 1 );
681 	    SetSpinSize( 1 );
682 	    SetDecimalDigits( 0 );
683 	    SetStrictFormat( sal_True );
684         SetBorderStyle( WINDOW_BORDER_MONO );
685     }
686 
687     //---------------------------------------------------------------------
~RecordPositionInput()688     RecordPositionInput::~RecordPositionInput()
689     {
690     }
691 
692     //---------------------------------------------------------------------
setDispatcher(const IFeatureDispatcher * _pDispatcher)693     void RecordPositionInput::setDispatcher( const IFeatureDispatcher* _pDispatcher )
694     {
695         m_pDispatcher = _pDispatcher;
696     }
697 
698     //---------------------------------------------------------------------
FirePosition(sal_Bool _bForce)699     void RecordPositionInput::FirePosition( sal_Bool _bForce )
700     {
701 	    if ( _bForce || ( GetText() != GetSavedValue() ) )
702 	    {
703 		    sal_Int64 nRecord = GetValue();
704 		    if ( nRecord < GetMin() || nRecord > GetMax() )
705 			    return;
706 
707             if ( m_pDispatcher )
708                 m_pDispatcher->dispatchWithArgument( FormFeature::MoveAbsolute, "Position", makeAny( (sal_Int32)nRecord ) );
709 
710             SaveValue();
711 	    }
712     }
713 
714     //---------------------------------------------------------------------
LoseFocus()715     void RecordPositionInput::LoseFocus()
716     {
717 	    FirePosition( sal_False );
718     }
719 
720     //---------------------------------------------------------------------
KeyInput(const KeyEvent & rKeyEvent)721     void RecordPositionInput::KeyInput( const KeyEvent& rKeyEvent )
722     {
723 	    if( rKeyEvent.GetKeyCode() == KEY_RETURN && GetText().Len() )
724 		    FirePosition( sal_True );
725 	    else
726 		    NumericField::KeyInput( rKeyEvent );
727     }
728 
729 
730 //.........................................................................
731 }   // namespace frm
732 //.........................................................................
733