LCOV - code coverage report
Current view: top level - svtools/source/control - roadmap.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 399 0.0 %
Date: 2014-04-14 Functions: 0 80 0.0 %
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             : #include <svtools/roadmap.hxx>
      21             : 
      22             : #include <vector>
      23             : #include <algorithm>
      24             : #include <vcl/bitmap.hxx>
      25             : #include <vcl/settings.hxx>
      26             : #include <tools/color.hxx>
      27             : #include <rtl/ustring.hxx>
      28             : #include <boost/scoped_ptr.hpp>
      29             : 
      30             : #define ROADMAP_INDENT_X        4
      31             : #define ROADMAP_INDENT_Y        27
      32             : #define ROADMAP_ITEM_DISTANCE_Y 6
      33             : #define RMINCOMPLETE        -1
      34             : 
      35             : 
      36             : namespace svt
      37             : {
      38             : 
      39             : 
      40             :     typedef std::vector< RoadmapItem* > HL_Vector;
      41             : 
      42             : 
      43             :     //= ColorChanger
      44             : 
      45             :     class IDLabel :  public FixedText
      46             :     {
      47             :     public:
      48             :         IDLabel( Window* _pParent, WinBits _nWinStyle = 0 );
      49             :         virtual ~IDLabel( );
      50             :         virtual void    DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
      51             :     };
      52             : 
      53             :     class RoadmapItem : public RoadmapTypes
      54             :     {
      55             :     private:
      56             :         IDLabel*                mpID;
      57             :         HyperLabel*             mpDescription;
      58             :         const Size              m_aItemPlayground;
      59             : 
      60             :     public:
      61             :         RoadmapItem( ORoadmap& _rParent, const Size& _rItemPlayground );
      62             :         ~RoadmapItem( );
      63             : 
      64             :         void                    SetID( sal_Int16 _ID );
      65             :         sal_Int16               GetID() const;
      66             : 
      67             :         void                    SetIndex( ItemIndex _Index );
      68             :         ItemIndex               GetIndex() const;
      69             : 
      70             :         void                    Update( ItemIndex _RMIndex, const OUString& _rText );
      71             : 
      72             :         void                    SetPosition( RoadmapItem* OldHyperLabel );
      73             : 
      74             :         void                    ToggleBackgroundColor( const Color& _rGBColor );
      75             :         void                    SetInteractive( bool _bInteractive );
      76             : 
      77             :         void                    SetClickHdl( const Link& rLink );
      78             :         void                    Enable( bool bEnable = true);
      79             :         bool                    IsEnabled() const;
      80             :         void                    GrabFocus();
      81             : 
      82             :         bool                    Contains( const Window* _pWindow ) const;
      83             : 
      84           0 :         HyperLabel*             GetDescriptionHyperLabel() const { return mpDescription; }
      85             : 
      86             :     private:
      87             :         void                    ImplUpdateIndex( const ItemIndex _nIndex );
      88             :         void                    ImplUpdatePosSize();
      89             :     };
      90             : 
      91             : 
      92             :     //= RoadmapImpl
      93             : 
      94           0 :     class RoadmapImpl : public RoadmapTypes
      95             :     {
      96             :     protected:
      97             :         const ORoadmap&     m_rAntiImpl;
      98             :         Link                m_aSelectHdl;
      99             :         BitmapEx            m_aPicture;
     100             :         HL_Vector           m_aRoadmapSteps;
     101             :         ItemId              m_iCurItemID;
     102             :         bool                m_bInteractive;
     103             :         bool                m_bComplete;
     104             :         Size                m_aItemSizePixel;
     105             : 
     106             :     public:
     107           0 :         RoadmapImpl( const ORoadmap& _rAntiImpl )
     108             :             :m_rAntiImpl( _rAntiImpl )
     109             :             ,m_iCurItemID( -1 )
     110             :             ,m_bInteractive( true )
     111             :             ,m_bComplete( true )
     112           0 :             ,InCompleteHyperLabel ( NULL )
     113             :         {
     114           0 :         }
     115             : 
     116             :         RoadmapItem* InCompleteHyperLabel;
     117             : 
     118           0 :         HL_Vector&          getHyperLabels() { return m_aRoadmapSteps; }
     119             : 
     120           0 :         void                insertHyperLabel( ItemIndex _Index, RoadmapItem* _rRoadmapStep ) { m_aRoadmapSteps.insert( m_aRoadmapSteps.begin() + _Index, _rRoadmapStep ); }
     121             : 
     122           0 :         ItemIndex           getItemCount() const { return m_aRoadmapSteps.size();}
     123             : 
     124           0 :         void                setCurItemID( ItemId i ) {m_iCurItemID = i; }
     125           0 :         ItemId              getCurItemID() const { return m_iCurItemID; }
     126             : 
     127           0 :         void                setInteractive(const bool _bInteractive) {m_bInteractive = _bInteractive; }
     128           0 :         bool                isInteractive() const { return m_bInteractive; };
     129             : 
     130           0 :         void                setComplete(const bool _bComplete) {m_bComplete = _bComplete; }
     131           0 :         bool                isComplete() const { return m_bComplete; };
     132             : 
     133           0 :         void                setPicture( const BitmapEx& _rPic ) { m_aPicture = _rPic; }
     134           0 :         const BitmapEx&     getPicture( ) const { return m_aPicture; }
     135             : 
     136           0 :         void                setSelectHdl( const Link& _rHdl ) { m_aSelectHdl = _rHdl; }
     137           0 :         const Link&         getSelectHdl( ) const { return m_aSelectHdl; }
     138             : 
     139             :         void                initItemSize();
     140           0 :         const Size&         getItemSize() const { return m_aItemSizePixel; }
     141             : 
     142           0 :         void removeHyperLabel( ItemIndex _Index )
     143             :         {
     144           0 :             if ( ( _Index > -1 ) && ( _Index < getItemCount() ) )
     145             :             {
     146           0 :                 delete m_aRoadmapSteps[_Index];
     147           0 :                 m_aRoadmapSteps.erase( m_aRoadmapSteps.begin() + _Index);
     148             :             }
     149           0 :         }
     150             :     };
     151             : 
     152             : 
     153           0 :     void RoadmapImpl::initItemSize()
     154             :     {
     155           0 :         Size aLabelSize( m_rAntiImpl.GetOutputSizePixel() );
     156           0 :         aLabelSize.Height() = m_rAntiImpl.LogicToPixel( Size( 0, LABELBASEMAPHEIGHT ), MAP_APPFONT ).Height();
     157           0 :         aLabelSize.Width() -= m_rAntiImpl.LogicToPixel( Size( 2 * ROADMAP_INDENT_X, 0 ), MAP_APPFONT ).Width();
     158           0 :         m_aItemSizePixel = aLabelSize;
     159           0 :     }
     160             : 
     161             : 
     162             :     //= Roadmap
     163             : 
     164             : 
     165           0 :     ORoadmap::ORoadmap( Window* _pParent, WinBits _nWinStyle )
     166             :         :Control( _pParent, _nWinStyle )
     167           0 :         ,m_pImpl( new RoadmapImpl( *this ) )
     168             : 
     169             :     {
     170           0 :         implInit();
     171           0 :     }
     172             : 
     173             : 
     174           0 :     void ORoadmap::implInit()
     175             :     {
     176           0 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     177           0 :         Color aTextColor = rStyleSettings.GetFieldTextColor();
     178           0 :         Font aFont = GetFont( );
     179           0 :         aFont.SetColor( aTextColor );
     180           0 :         aFont.SetWeight( WEIGHT_BOLD );
     181           0 :         aFont.SetUnderline( UNDERLINE_SINGLE );
     182           0 :         SetFont( aFont );
     183           0 :         SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) );
     184           0 :         m_pImpl->InCompleteHyperLabel = NULL;
     185           0 :         m_pImpl->setCurItemID(-1 );
     186           0 :         m_pImpl->setComplete( true );
     187             : 
     188             :         // Roadmap control should be reachable as one unit with a Tab key
     189             :         // the next Tab key should spring out of the control.
     190             :         // To reach it the control itself should get focus and set it
     191             :         // on entries. The entries themself should not be reachable with
     192             :         // the Tab key directly. So each entry should have WB_NOTABSTOP.
     193             : 
     194             :         // In other words the creator should create the control with the following
     195             :         // flags:
     196             :         // SetStyle( ( GetStyle() | WB_TABSTOP ) & ~WB_DIALOGCONTROL );
     197             : 
     198             : // TODO: if somebody sets a new font from outside (OutputDevice::SetFont), we would have to react
     199             : // on this with calculating a new bold font.
     200             : // Unfortunately, the OutputDevice does not offer a notify mechanism for a changed font.
     201             : // So settings the font from outside is simply a forbidded scenario at the moment
     202           0 :         EnableMapMode( false );
     203           0 :     }
     204             : 
     205             : 
     206           0 :     ORoadmap::~ORoadmap( )
     207             :     {
     208           0 :         HL_Vector aItemsCopy = m_pImpl->getHyperLabels();
     209           0 :         m_pImpl->getHyperLabels().clear();
     210           0 :         for ( HL_Vector::iterator i = aItemsCopy.begin(); i != aItemsCopy.end(); ++i )
     211             :         {
     212           0 :             delete *i;
     213             :         }
     214           0 :         if ( ! m_pImpl->isComplete() )
     215           0 :             delete m_pImpl->InCompleteHyperLabel;
     216           0 :         delete m_pImpl;
     217           0 :         m_pImpl = NULL;
     218           0 :     }
     219             : 
     220             : 
     221           0 :     RoadmapTypes::ItemId ORoadmap::GetCurrentRoadmapItemID() const
     222             :     {
     223           0 :         return m_pImpl->getCurItemID();
     224             :     }
     225             : 
     226             : 
     227           0 :     RoadmapItem* ORoadmap::GetPreviousHyperLabel( ItemIndex _Index)
     228             :     {
     229           0 :         RoadmapItem* pOldItem = NULL;
     230           0 :         if ( _Index > 0 )
     231           0 :             pOldItem = m_pImpl->getHyperLabels().at( _Index - 1 );
     232           0 :         return pOldItem;
     233             :     }
     234             : 
     235             : 
     236             : 
     237             : 
     238           0 :     RoadmapItem* ORoadmap::InsertHyperLabel( ItemIndex _Index, const OUString& _sLabel, ItemId _RMID, bool _bEnabled)
     239             :     {
     240           0 :         if ( m_pImpl->getItemCount() == 0 )
     241           0 :             m_pImpl->initItemSize();
     242             : 
     243           0 :         RoadmapItem* pItem = NULL;
     244           0 :         RoadmapItem* pOldItem = GetPreviousHyperLabel( _Index );
     245             : 
     246           0 :         pItem = new RoadmapItem( *this, m_pImpl->getItemSize() );
     247           0 :         if ( _RMID != RMINCOMPLETE )
     248             :         {
     249           0 :             pItem->SetInteractive( m_pImpl->isInteractive() );
     250           0 :             m_pImpl->insertHyperLabel( _Index, pItem );
     251             :         }
     252             :         else
     253             :         {
     254           0 :             pItem->SetInteractive( false );
     255             :         }
     256           0 :         pItem->SetPosition( pOldItem );
     257           0 :         pItem->Update( _Index, _sLabel );
     258           0 :         pItem->SetClickHdl(LINK( this, ORoadmap, ImplClickHdl ) );
     259           0 :         pItem->SetID( _RMID );
     260           0 :         pItem->SetIndex( _Index );
     261           0 :         if (!_bEnabled)
     262           0 :             pItem->Enable( _bEnabled );
     263           0 :         return pItem;
     264             :     }
     265             : 
     266             : 
     267           0 :     void ORoadmap::SetRoadmapBitmap( const BitmapEx& _rBmp, bool _bInvalidate )
     268             :     {
     269           0 :         m_pImpl->setPicture( _rBmp );
     270           0 :         if ( _bInvalidate )
     271           0 :             Invalidate( );
     272           0 :     }
     273             : 
     274             : 
     275           0 :     void ORoadmap::SetRoadmapInteractive( bool _bInteractive )
     276             :     {
     277           0 :         m_pImpl->setInteractive( _bInteractive );
     278             : 
     279           0 :         const HL_Vector& rItems = m_pImpl->getHyperLabels();
     280           0 :         for (   HL_Vector::const_iterator i = rItems.begin();
     281           0 :                 i != rItems.end();
     282             :                 ++i
     283             :             )
     284             :         {
     285           0 :             (*i)->SetInteractive( _bInteractive );
     286             :         }
     287           0 :     }
     288             : 
     289             : 
     290           0 :     bool ORoadmap::IsRoadmapInteractive()
     291             :     {
     292           0 :         return m_pImpl->isInteractive();
     293             :     }
     294             : 
     295             : 
     296           0 :     void ORoadmap::SetRoadmapComplete( bool _bComplete )
     297             :     {
     298           0 :         bool bWasComplete = m_pImpl->isComplete();
     299           0 :         m_pImpl->setComplete( _bComplete );
     300           0 :         if ( _bComplete )
     301             :         {
     302           0 :             if ( m_pImpl->InCompleteHyperLabel != NULL)
     303             :             {
     304           0 :                 delete m_pImpl->InCompleteHyperLabel;
     305           0 :                 m_pImpl->InCompleteHyperLabel = NULL;
     306             :             }
     307             :         }
     308           0 :         else if ( bWasComplete )
     309           0 :             m_pImpl->InCompleteHyperLabel = InsertHyperLabel( m_pImpl->getItemCount(), OUString("..."), RMINCOMPLETE );
     310           0 :     }
     311             : 
     312             : 
     313           0 :     void ORoadmap::UpdatefollowingHyperLabels( ItemIndex _nIndex )
     314             :     {
     315           0 :         const HL_Vector& rItems = m_pImpl->getHyperLabels();
     316           0 :         if ( _nIndex < (ItemIndex)rItems.size() )
     317             :         {
     318           0 :             RoadmapItem* pItem = NULL;
     319           0 :             for (   HL_Vector::const_iterator i = rItems.begin() + _nIndex;
     320           0 :                     i != rItems.end();
     321             :                     ++i, ++_nIndex
     322             :                 )
     323             :             {
     324           0 :                 pItem = *i;
     325             : 
     326           0 :                 pItem->SetIndex( _nIndex );
     327           0 :                 pItem->SetPosition( GetPreviousHyperLabel( _nIndex ) );
     328             :             }
     329             :         }
     330           0 :         if ( ! m_pImpl->isComplete() )
     331             :         {
     332           0 :             RoadmapItem* pOldItem = GetPreviousHyperLabel( m_pImpl->getItemCount() );
     333           0 :             m_pImpl->InCompleteHyperLabel->SetPosition( pOldItem );
     334           0 :             m_pImpl->InCompleteHyperLabel->Update( m_pImpl->getItemCount(), OUString("...") );
     335             :         }
     336           0 :     }
     337             : 
     338             : 
     339           0 :     void ORoadmap::ReplaceRoadmapItem( ItemIndex _Index, const OUString& _RoadmapItem, ItemId _RMID, bool _bEnabled )
     340             :     {
     341           0 :         RoadmapItem* pItem = GetByIndex( _Index);
     342           0 :         if ( pItem != NULL )
     343             :         {
     344           0 :             pItem->Update( _Index,  _RoadmapItem );
     345           0 :             pItem->SetID( _RMID );
     346           0 :             pItem->Enable( _bEnabled );
     347             :         }
     348           0 :     }
     349             : 
     350             : 
     351           0 :     RoadmapTypes::ItemIndex ORoadmap::GetItemCount() const
     352             :     {
     353           0 :         return m_pImpl->getItemCount();
     354             :     }
     355             : 
     356             : 
     357           0 :     RoadmapTypes::ItemId ORoadmap::GetItemID( ItemIndex _nIndex ) const
     358             :     {
     359           0 :         const RoadmapItem* pHyperLabel = GetByIndex( _nIndex );
     360           0 :         if ( pHyperLabel )
     361           0 :             return pHyperLabel->GetID();
     362           0 :         return -1;
     363             :     }
     364             : 
     365             : 
     366           0 :     void ORoadmap::InsertRoadmapItem( ItemIndex _Index, const OUString& _RoadmapItem, ItemId _nUniqueId, bool _bEnabled )
     367             :     {
     368           0 :         InsertHyperLabel( _Index, _RoadmapItem, _nUniqueId, _bEnabled );
     369             :             // Todo: YPos is superfluous, if items are always appended
     370           0 :         UpdatefollowingHyperLabels( _Index + 1 );
     371           0 :     }
     372             : 
     373             : 
     374           0 :     void ORoadmap::DeleteRoadmapItem( ItemIndex _Index )
     375             :     {
     376           0 :         if ( m_pImpl->getItemCount() > 0 && ( _Index > -1)  &&  ( _Index < m_pImpl->getItemCount() ) )
     377             :         {
     378           0 :             m_pImpl->removeHyperLabel( _Index );
     379           0 :             UpdatefollowingHyperLabels( _Index );
     380             :         }
     381           0 :     }
     382             : 
     383             : 
     384           0 :     bool ORoadmap::IsRoadmapComplete( ) const
     385             :     {
     386           0 :         return m_pImpl->isComplete();
     387             :     }
     388             : 
     389             : 
     390           0 :     void ORoadmap::EnableRoadmapItem( ItemId _nItemId, bool _bEnable, ItemIndex _nStartIndex )
     391             :     {
     392           0 :         RoadmapItem* pItem = GetByID( _nItemId, _nStartIndex );
     393           0 :         if ( pItem != NULL )
     394           0 :             pItem->Enable( _bEnable );
     395           0 :     }
     396             : 
     397             : 
     398           0 :     void ORoadmap::ChangeRoadmapItemLabel( ItemId _nID, const OUString& _sLabel, ItemIndex _nStartIndex )
     399             :     {
     400           0 :         RoadmapItem* pItem = GetByID( _nID, _nStartIndex );
     401           0 :         if ( pItem != NULL )
     402             :         {
     403           0 :             pItem->Update( pItem->GetIndex(), _sLabel );
     404             : 
     405           0 :             const HL_Vector& rItems = m_pImpl->getHyperLabels();
     406           0 :             for (   HL_Vector::const_iterator i = rItems.begin() + _nStartIndex;
     407           0 :                     i != rItems.end();
     408             :                     ++i
     409             :                 )
     410             :             {
     411           0 :                 (*i)->SetPosition( GetPreviousHyperLabel( i - rItems.begin() ) );
     412             :             }
     413             :         }
     414           0 :     }
     415             : 
     416             : 
     417           0 :     void ORoadmap::ChangeRoadmapItemID( ItemId _nID, ItemId _NewID, ItemIndex _nStartIndex )
     418             :     {
     419           0 :         RoadmapItem* pItem = GetByID( _nID, _nStartIndex );
     420           0 :         if ( pItem != NULL )
     421           0 :             pItem->SetID( _NewID );
     422           0 :     }
     423             : 
     424             : 
     425           0 :     RoadmapItem* ORoadmap::GetByID( ItemId _nID, ItemIndex _nStartIndex)
     426             :     {
     427           0 :         ItemId nLocID = 0;
     428           0 :         const HL_Vector& rItems = m_pImpl->getHyperLabels();
     429           0 :         for (   HL_Vector::const_iterator i = rItems.begin() + _nStartIndex;
     430           0 :                 i != rItems.end();
     431             :                 ++i
     432             :             )
     433             :         {
     434           0 :             nLocID = (*i)->GetID();
     435           0 :             if ( nLocID == _nID )
     436           0 :                 return *i;
     437             :         }
     438           0 :         return NULL;
     439             :     }
     440             : 
     441             : 
     442           0 :     const RoadmapItem* ORoadmap::GetByID( ItemId _nID, ItemIndex _nStartIndex  ) const
     443             :     {
     444           0 :         return const_cast< ORoadmap* >( this )->GetByID( _nID, _nStartIndex );
     445             :     }
     446             : 
     447             : 
     448           0 :     RoadmapItem* ORoadmap::GetByIndex( ItemIndex _nItemIndex)
     449             :     {
     450           0 :         const HL_Vector& rItems = m_pImpl->getHyperLabels();
     451           0 :         if ( ( _nItemIndex > -1 ) && ( _nItemIndex < (ItemIndex)rItems.size() ) )
     452             :         {
     453           0 :             return rItems.at( _nItemIndex );
     454             :         }
     455           0 :         return NULL;
     456             :     }
     457             : 
     458             : 
     459           0 :     const RoadmapItem* ORoadmap::GetByIndex( ItemIndex _nItemIndex ) const
     460             :     {
     461           0 :         return const_cast< ORoadmap* >( this )->GetByIndex( _nItemIndex );
     462             :     }
     463             : 
     464             : 
     465           0 :     RoadmapTypes::ItemId ORoadmap::GetNextAvailableItemId( ItemIndex _nNewIndex )
     466             :     {
     467           0 :         RoadmapItem* pItem = NULL;
     468             : 
     469           0 :         ItemIndex searchIndex = ++_nNewIndex;
     470           0 :         while ( searchIndex < m_pImpl->getItemCount() )
     471             :         {
     472           0 :             pItem = GetByIndex( searchIndex );
     473           0 :             if ( pItem->IsEnabled() )
     474           0 :                 return pItem->GetID( );
     475             : 
     476           0 :             ++searchIndex;
     477             :         }
     478           0 :         return -1;
     479             :     }
     480             : 
     481             : 
     482           0 :     RoadmapTypes::ItemId ORoadmap::GetPreviousAvailableItemId( ItemIndex _nNewIndex )
     483             :     {
     484           0 :         RoadmapItem* pItem = NULL;
     485           0 :         ItemIndex searchIndex = --_nNewIndex;
     486           0 :         while ( searchIndex > -1 )
     487             :         {
     488           0 :             pItem = GetByIndex( searchIndex );
     489           0 :             if ( pItem->IsEnabled() )
     490           0 :                 return pItem->GetID( );
     491             : 
     492           0 :             searchIndex--;
     493             :         }
     494           0 :         return -1;
     495             :     }
     496             : 
     497             : 
     498           0 :     void ORoadmap::DeselectOldRoadmapItems()
     499             :     {
     500           0 :         const HL_Vector& rItems = m_pImpl->getHyperLabels();
     501           0 :         for (   HL_Vector::const_iterator i = rItems.begin();
     502           0 :                 i != rItems.end();
     503             :                 ++i
     504             :             )
     505             :         {
     506           0 :             (*i)->ToggleBackgroundColor( COL_TRANSPARENT );
     507             :         }
     508           0 :     }
     509             : 
     510             : 
     511           0 :     void ORoadmap::SetItemSelectHdl( const Link& _rHdl )
     512             :     {
     513           0 :         m_pImpl->setSelectHdl( _rHdl );
     514           0 :     }
     515             : 
     516             : 
     517           0 :     Link ORoadmap::GetItemSelectHdl( ) const
     518             :     {
     519           0 :         return m_pImpl->getSelectHdl();
     520             :     }
     521             : 
     522             : 
     523           0 :     void ORoadmap::Select()
     524             :     {
     525           0 :         GetItemSelectHdl().Call( this );
     526           0 :         CallEventListeners( VCLEVENT_ROADMAP_ITEMSELECTED );
     527           0 :     }
     528             : 
     529             : 
     530           0 :     void ORoadmap::GetFocus()
     531             :     {
     532           0 :         RoadmapItem* pCurHyperLabel = GetByID( GetCurrentRoadmapItemID() );
     533           0 :         if ( pCurHyperLabel != NULL )
     534           0 :             pCurHyperLabel->GrabFocus();
     535           0 :     }
     536             : 
     537             : 
     538           0 :     bool ORoadmap::SelectRoadmapItemByID( ItemId _nNewID )
     539             :     {
     540           0 :         DeselectOldRoadmapItems();
     541           0 :         RoadmapItem* pItem = GetByID( _nNewID );
     542           0 :         if ( pItem != NULL )
     543             :         {
     544           0 :             if ( pItem->IsEnabled() )
     545             :             {
     546           0 :                 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     547           0 :                 pItem->ToggleBackgroundColor( rStyleSettings.GetHighlightColor() ); //HighlightColor
     548             : 
     549           0 :                 pItem->GrabFocus();
     550           0 :                 m_pImpl->setCurItemID(_nNewID);
     551             : 
     552           0 :                 Select();
     553           0 :                 return true;
     554             :             }
     555             :         }
     556           0 :         return false;
     557             :     }
     558             : 
     559             : 
     560           0 :     void ORoadmap::Paint( const Rectangle& _rRect )
     561             :     {
     562           0 :         Control::Paint( _rRect );
     563             : 
     564             : 
     565             :         // draw the bitmap
     566           0 :         if ( !!m_pImpl->getPicture() )
     567             :         {
     568           0 :             Size aBitmapSize = m_pImpl->getPicture().GetSizePixel();
     569           0 :             Size aMySize = GetOutputSizePixel();
     570             : 
     571           0 :             Point aBitmapPos( aMySize.Width() - aBitmapSize.Width(),  aMySize.Height() - aBitmapSize.Height() );
     572             : 
     573             :             // draw it
     574           0 :             DrawBitmapEx( aBitmapPos, m_pImpl->getPicture() );
     575             :         }
     576             : 
     577             : 
     578             :         // draw the headline
     579           0 :         DrawHeadline();
     580           0 :     }
     581             : 
     582             : 
     583           0 :     void ORoadmap::DrawHeadline()
     584             :     {
     585           0 :         Point aTextPos = LogicToPixel( Point( ROADMAP_INDENT_X, 8 ), MAP_APPFONT );
     586             : 
     587           0 :         Size aOutputSize( GetOutputSizePixel() );
     588             : 
     589             :         // draw it
     590           0 :         DrawText( Rectangle( aTextPos, aOutputSize ), GetText(), TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
     591           0 :         DrawTextLine( aTextPos, aOutputSize.Width(), STRIKEOUT_NONE, UNDERLINE_SINGLE, UNDERLINE_NONE, false );
     592           0 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     593           0 :         SetLineColor( rStyleSettings.GetFieldTextColor());
     594           0 :         SetTextColor(rStyleSettings.GetFieldTextColor());
     595           0 :     }
     596             : 
     597             : 
     598           0 :     RoadmapItem* ORoadmap::GetByPointer(Window* pWindow)
     599             :     {
     600           0 :         const HL_Vector& rItems = m_pImpl->getHyperLabels();
     601           0 :         for (   HL_Vector::const_iterator i = rItems.begin();
     602           0 :                 i != rItems.end();
     603             :                 ++i
     604             :             )
     605             :         {
     606           0 :             if ( (*i)->Contains( pWindow ) )
     607           0 :                 return *i;
     608             :         }
     609           0 :         return NULL;
     610             :     }
     611             : 
     612             : 
     613           0 :     bool ORoadmap::PreNotify( NotifyEvent& _rNEvt )
     614             :     {
     615             :         // capture KeyEvents for taskpane cycling
     616           0 :         if ( _rNEvt.GetType() == EVENT_KEYINPUT )
     617             :         {
     618           0 :             Window* pWindow = _rNEvt.GetWindow();
     619           0 :             RoadmapItem* pItem = GetByPointer( pWindow );
     620           0 :             if ( pItem != NULL )
     621             :             {
     622           0 :                 sal_Int16 nKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
     623           0 :                 switch( nKeyCode )
     624             :                 {
     625             :                     case KEY_UP:
     626             :                         {   // Note: Performancewise this is not optimal, because we search for an ID in the labels
     627             :                             //       and afterwards we search again for a label with the appropriate ID ->
     628             :                             //       unnecessarily we search twice!!!
     629           0 :                             ItemId nPrevItemID = GetPreviousAvailableItemId( pItem->GetIndex() );
     630           0 :                             if ( nPrevItemID != -1 )
     631           0 :                                 return SelectRoadmapItemByID( nPrevItemID );
     632             :                         }
     633           0 :                         break;
     634             :                     case KEY_DOWN:
     635             :                         {
     636           0 :                             ItemId nNextItemID = GetNextAvailableItemId( pItem->GetIndex() );
     637           0 :                             if ( nNextItemID != -1 )
     638           0 :                                 return SelectRoadmapItemByID( nNextItemID );
     639             :                         }
     640           0 :                         break;
     641             :                     case KEY_SPACE:
     642           0 :                         return SelectRoadmapItemByID( pItem->GetID() );
     643             :                 }
     644             :             }
     645             :         }
     646           0 :         return Window::PreNotify( _rNEvt );
     647             :     }
     648             : 
     649             : 
     650           0 :     IMPL_LINK(ORoadmap, ImplClickHdl, HyperLabel*, _CurHyperLabel)
     651             :     {
     652           0 :        return SelectRoadmapItemByID( _CurHyperLabel->GetID() ) ? 1 : 0;
     653             :     }
     654             : 
     655             : 
     656             : 
     657             : 
     658           0 :     void ORoadmap::DataChanged( const DataChangedEvent& rDCEvt )
     659             :     {
     660           0 :         if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS )   ||
     661           0 :             ( rDCEvt.GetType() == DATACHANGED_DISPLAY   ))  &&
     662           0 :             ( rDCEvt.GetFlags() & SETTINGS_STYLE        ))
     663             :         {
     664           0 :             const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     665           0 :             SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) );
     666           0 :             Color aTextColor = rStyleSettings.GetFieldTextColor();
     667           0 :             Font aFont = GetFont();
     668           0 :             aFont.SetColor( aTextColor );
     669           0 :             SetFont( aFont );
     670           0 :             RoadmapTypes::ItemId curItemID = GetCurrentRoadmapItemID();
     671           0 :             RoadmapItem* pLabelItem = GetByID( curItemID );
     672           0 :             if (pLabelItem != NULL)
     673             :             {
     674           0 :                 pLabelItem->ToggleBackgroundColor(rStyleSettings.GetHighlightColor());
     675             :             }
     676           0 :             Invalidate();
     677             :         }
     678           0 :     }
     679             : 
     680             : 
     681             : 
     682           0 :     RoadmapItem::RoadmapItem( ORoadmap& _rParent, const Size& _rItemPlayground )
     683           0 :         :m_aItemPlayground( _rItemPlayground )
     684             :     {
     685           0 :         mpID = new IDLabel( &_rParent, WB_WORDBREAK );
     686           0 :         mpID->SetTextColor( mpID->GetSettings().GetStyleSettings().GetFieldTextColor( ) );
     687           0 :         mpID->Show();
     688           0 :         mpDescription = new HyperLabel( &_rParent, WB_NOTABSTOP | WB_WORDBREAK );
     689           0 :         mpDescription->Show();
     690           0 :     }
     691             : 
     692             : 
     693           0 :     bool RoadmapItem::Contains( const Window* _pWindow ) const
     694             :     {
     695           0 :         return ( mpID == _pWindow ) || ( mpDescription == _pWindow );
     696             :     }
     697             : 
     698             : 
     699           0 :     void RoadmapItem::GrabFocus()
     700             :     {
     701           0 :         if ( mpDescription )
     702           0 :             mpDescription->GrabFocus();
     703           0 :     }
     704             : 
     705             : 
     706           0 :     void RoadmapItem::SetInteractive( bool _bInteractive )
     707             :     {
     708           0 :         if ( mpDescription )
     709           0 :         mpDescription->SetInteractive(_bInteractive);
     710           0 :     }
     711             : 
     712             : 
     713           0 :     void RoadmapItem::SetID( sal_Int16 _ID )
     714             :     {
     715           0 :         if ( mpDescription )
     716           0 :             mpDescription->SetID(_ID);
     717           0 :     }
     718             : 
     719             : 
     720           0 :     sal_Int16 RoadmapItem::GetID() const
     721             :     {
     722           0 :         return mpDescription ? mpDescription->GetID() : sal_Int16(-1);
     723             :     }
     724             : 
     725             : 
     726           0 :     void RoadmapItem::ImplUpdateIndex( const ItemIndex _nIndex )
     727             :     {
     728           0 :         if ( mpDescription )
     729           0 :             mpDescription->SetIndex( _nIndex );
     730             : 
     731           0 :         if ( mpID )
     732             :         {
     733           0 :             OUString aIDText = OUString::number( _nIndex + 1 ) + ".";
     734           0 :              mpID->SetText( aIDText );
     735             :         }
     736             : 
     737             :         // update the geometry of both controls
     738           0 :         ImplUpdatePosSize();
     739           0 :     }
     740             : 
     741             : 
     742           0 :     void RoadmapItem::SetIndex( ItemIndex _Index )
     743             :     {
     744           0 :         ImplUpdateIndex( _Index );
     745           0 :     }
     746             : 
     747             : 
     748           0 :     RoadmapTypes::ItemIndex RoadmapItem::GetIndex() const
     749             :     {
     750           0 :         return mpDescription ? mpDescription->GetIndex() : ItemIndex(-1);
     751             :     }
     752             : 
     753             : 
     754           0 :     void RoadmapItem::SetPosition( RoadmapItem* _pOldItem )
     755             :     {
     756           0 :         Point aIDPos;
     757           0 :         if ( _pOldItem == NULL )
     758             :         {
     759           0 :             aIDPos = mpID->LogicToPixel( Point( ROADMAP_INDENT_X, ROADMAP_INDENT_Y ), MAP_APPFONT );
     760             :         }
     761             :         else
     762             :         {
     763           0 :             Size aOldSize = _pOldItem->GetDescriptionHyperLabel()->GetSizePixel();
     764             : 
     765           0 :             aIDPos = _pOldItem->mpID->GetPosPixel();
     766           0 :             aIDPos.Y() += aOldSize.Height();
     767           0 :             aIDPos.Y() += mpID->GetParent()->LogicToPixel( Size( 0, ROADMAP_ITEM_DISTANCE_Y ) ).Height();
     768             :         }
     769           0 :         mpID->SetPosPixel( aIDPos );
     770             : 
     771           0 :         sal_Int32 nDescPos = aIDPos.X() + mpID->GetSizePixel().Width();
     772           0 :         mpDescription->SetPosPixel( Point( nDescPos, aIDPos.Y() ) );
     773           0 :     }
     774             : 
     775             : 
     776           0 :     void RoadmapItem::Enable( bool _bEnable)
     777             :     {
     778           0 :         mpID->Enable(_bEnable);
     779           0 :         mpDescription->Enable(_bEnable);
     780           0 :     }
     781             : 
     782             : 
     783           0 :     bool RoadmapItem::IsEnabled() const
     784             :     {
     785           0 :         return mpID->IsEnabled();
     786             :     }
     787             : 
     788             : 
     789           0 :     void RoadmapItem::ToggleBackgroundColor( const Color& _rGBColor )
     790             :     {
     791           0 :         if (_rGBColor == COL_TRANSPARENT)
     792             :         {
     793           0 :             mpID->SetTextColor( mpID->GetSettings().GetStyleSettings().GetFieldTextColor( ) );
     794           0 :             mpID->SetControlBackground( COL_TRANSPARENT );
     795             :         }
     796             :         else
     797             :         {
     798           0 :             mpID->SetControlBackground( mpID->GetSettings().GetStyleSettings().GetHighlightColor() );
     799           0 :             mpID->SetTextColor( mpID->GetSettings().GetStyleSettings().GetHighlightTextColor( ) );
     800             :         }
     801           0 :         mpDescription->ToggleBackgroundColor(_rGBColor);
     802           0 :     }
     803             : 
     804             : 
     805           0 :     void RoadmapItem::ImplUpdatePosSize()
     806             :     {
     807             :         // calculate widths
     808           0 :         long nIDWidth = mpID->GetTextWidth( mpID->GetText() );
     809           0 :         long nMaxIDWidth = mpID->GetTextWidth( OUString( "100." ) );
     810           0 :         nIDWidth = ::std::min( nIDWidth, nMaxIDWidth );
     811             : 
     812             :         // check how many space the description would need
     813           0 :         Size aDescriptionSize = mpDescription->CalcMinimumSize( m_aItemPlayground.Width() - nIDWidth );
     814             : 
     815             :         // position and size both controls
     816           0 :         Size aIDSize( nIDWidth, aDescriptionSize.Height() );
     817           0 :          mpID->SetSizePixel( aIDSize );
     818             : 
     819           0 :         Point aIDPos = mpID->GetPosPixel();
     820           0 :         mpDescription->SetPosPixel( Point( aIDPos.X() + nIDWidth, aIDPos.Y() ) );
     821           0 :         mpDescription->SetSizePixel( aDescriptionSize );
     822           0 :     }
     823             : 
     824             : 
     825           0 :     void RoadmapItem::Update( ItemIndex _RMIndex, const OUString& _rText )
     826             :     {
     827             :         // update description label
     828           0 :         mpDescription->SetLabel( _rText );
     829             : 
     830             :         // update the index in both controls, which triggers updating the geometry of both
     831           0 :         ImplUpdateIndex( _RMIndex );
     832           0 :     }
     833             : 
     834             : 
     835           0 :     RoadmapItem::~RoadmapItem( )
     836             :     {
     837             :         {
     838           0 :             boost::scoped_ptr<Control> xTakeOnership(mpID);
     839           0 :             mpID = NULL;
     840             :         }
     841             :         {
     842           0 :             boost::scoped_ptr<Control> xTakeOnership(mpDescription);
     843           0 :             mpDescription = NULL;
     844             :         }
     845           0 :     }
     846             : 
     847             : 
     848           0 :     void RoadmapItem::SetClickHdl( const Link& rLink )
     849             :     {
     850           0 :         if ( mpDescription )
     851           0 :             mpDescription->SetClickHdl( rLink);
     852           0 :     }
     853             : 
     854             : 
     855           0 :     IDLabel::IDLabel( Window* _pParent, WinBits _nWinStyle )
     856           0 :         :FixedText( _pParent, _nWinStyle )
     857             :     {
     858             : 
     859           0 :     }
     860             : 
     861             : 
     862           0 :     IDLabel::~IDLabel( )
     863             :     {
     864           0 :     }
     865             : 
     866             : 
     867           0 :     void IDLabel::DataChanged( const DataChangedEvent& rDCEvt )
     868             :     {
     869           0 :         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     870           0 :         FixedText::DataChanged( rDCEvt );
     871           0 :         if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS )   ||
     872           0 :             ( rDCEvt.GetType() == DATACHANGED_DISPLAY   ))  &&
     873           0 :             ( rDCEvt.GetFlags() & SETTINGS_STYLE        ))
     874             :         {
     875           0 :             const Color& rGBColor = GetControlBackground();
     876           0 :             if (rGBColor == COL_TRANSPARENT)
     877           0 :                 SetTextColor( rStyleSettings.GetFieldTextColor( ) );
     878             :             else
     879             :             {
     880           0 :                 SetControlBackground(rStyleSettings.GetHighlightColor());
     881           0 :                 SetTextColor( rStyleSettings.GetHighlightTextColor( ) );
     882             :             }
     883           0 :             Invalidate();
     884             :         }
     885           0 :     }
     886             : 
     887             : 
     888             : 
     889             : 
     890             : 
     891             : }   // namespace svt
     892             : 
     893             : 
     894             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10