LCOV - code coverage report
Current view: top level - forms/source/solar/control - navtoolbar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 235 300 78.3 %
Date: 2014-04-11 Functions: 32 43 74.4 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10