fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / control / roadmap.cxx
bloba934bd29af63b60b309511c7274dc4b2f9e6c05b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <roadmap.hxx>
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>
30 #define ROADMAP_INDENT_X 4
31 #define ROADMAP_INDENT_Y 27
32 #define ROADMAP_ITEM_DISTANCE_Y 6
34 namespace svt
37 typedef std::vector< RoadmapItem* > HL_Vector;
39 //= ColorChanger
41 class IDLabel : public FixedText
43 public:
44 IDLabel( vcl::Window* _pParent, WinBits _nWinStyle = 0 );
45 virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
48 class RoadmapItem : public RoadmapTypes
50 private:
51 VclPtr<IDLabel> mpID;
52 VclPtr<HyperLabel> mpDescription;
53 const Size m_aItemPlayground;
55 public:
56 RoadmapItem( ORoadmap& _rParent, const Size& _rItemPlayground );
57 ~RoadmapItem();
59 void SetID( sal_Int16 _ID );
60 sal_Int16 GetID() const;
62 void SetIndex( ItemIndex _Index );
63 ItemIndex GetIndex() const;
65 void Update( ItemIndex _RMIndex, const OUString& _rText );
67 void SetPosition( RoadmapItem* OldHyperLabel );
69 void ToggleBackgroundColor( const Color& _rGBColor );
70 void SetInteractive( bool _bInteractive );
72 void SetClickHdl( const Link<>& rLink );
73 void Enable( bool bEnable = true);
74 bool IsEnabled() const;
75 void GrabFocus();
77 bool Contains( const vcl::Window* _pWindow ) const;
79 HyperLabel* GetDescriptionHyperLabel() const { return mpDescription; }
81 private:
82 void ImplUpdateIndex( const ItemIndex _nIndex );
83 void ImplUpdatePosSize();
86 //= RoadmapImpl
88 class RoadmapImpl : public RoadmapTypes
90 protected:
91 const ORoadmap& m_rAntiImpl;
92 Link<> m_aSelectHdl;
93 BitmapEx m_aPicture;
94 HL_Vector m_aRoadmapSteps;
95 ItemId m_iCurItemID;
96 bool m_bInteractive : 1;
97 bool m_bComplete : 1;
98 Size m_aItemSizePixel;
99 public:
100 bool m_bPaintInitialized : 1;
102 public:
103 RoadmapImpl(const ORoadmap& rAntiImpl)
104 : m_rAntiImpl(rAntiImpl)
105 , m_iCurItemID(-1)
106 , m_bInteractive(true)
107 , m_bComplete(true)
108 , m_bPaintInitialized(false)
109 , InCompleteHyperLabel(NULL)
112 RoadmapItem* InCompleteHyperLabel;
114 HL_Vector& getHyperLabels()
116 return m_aRoadmapSteps;
119 void insertHyperLabel(ItemIndex _Index, RoadmapItem* _rRoadmapStep)
121 m_aRoadmapSteps.insert(m_aRoadmapSteps.begin() + _Index, _rRoadmapStep);
124 ItemIndex getItemCount() const
126 return m_aRoadmapSteps.size();
129 void setCurItemID(ItemId i)
131 m_iCurItemID = i;
133 ItemId getCurItemID() const
135 return m_iCurItemID;
138 void setInteractive(const bool _bInteractive)
140 m_bInteractive = _bInteractive;
142 bool isInteractive() const
144 return m_bInteractive;
147 void setComplete(const bool _bComplete)
149 m_bComplete = _bComplete;
151 bool isComplete() const
153 return m_bComplete;
156 void setPicture(const BitmapEx& _rPic)
158 m_aPicture = _rPic;
160 const BitmapEx& getPicture() const
162 return m_aPicture;
165 void setSelectHdl(const Link<>& _rHdl)
167 m_aSelectHdl = _rHdl;
169 const Link<>& getSelectHdl() const
171 return m_aSelectHdl;
174 void initItemSize();
175 const Size& getItemSize() const
177 return m_aItemSizePixel;
180 void removeHyperLabel(ItemIndex _Index)
182 if ((_Index > -1) && (_Index < getItemCount()))
184 delete m_aRoadmapSteps[_Index];
185 m_aRoadmapSteps.erase(m_aRoadmapSteps.begin() + _Index);
190 void RoadmapImpl::initItemSize()
192 Size aLabelSize( m_rAntiImpl.GetOutputSizePixel() );
193 aLabelSize.Height() = m_rAntiImpl.LogicToPixel( Size( 0, LABELBASEMAPHEIGHT ), MAP_APPFONT ).Height();
194 aLabelSize.Width() -= m_rAntiImpl.LogicToPixel( Size( 2 * ROADMAP_INDENT_X, 0 ), MAP_APPFONT ).Width();
195 m_aItemSizePixel = aLabelSize;
198 //= Roadmap
200 ORoadmap::ORoadmap(vcl::Window* _pParent, WinBits _nWinStyle)
201 : Control(_pParent, _nWinStyle)
202 , m_pImpl(new RoadmapImpl(*this))
206 void ORoadmap::implInit(vcl::RenderContext& rRenderContext)
208 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
209 Color aTextColor = rStyleSettings.GetFieldTextColor();
210 vcl::Font aFont = rRenderContext.GetFont();
211 aFont.SetColor(aTextColor);
212 aFont.SetWeight(WEIGHT_BOLD);
213 aFont.SetUnderline(UNDERLINE_SINGLE);
214 rRenderContext.SetFont(aFont);
215 rRenderContext.SetBackground(Wallpaper(rStyleSettings.GetFieldColor()));
216 m_pImpl->InCompleteHyperLabel = NULL;
217 m_pImpl->setCurItemID(-1);
218 m_pImpl->setComplete(true);
219 m_pImpl->m_bPaintInitialized = true;
221 // Roadmap control should be reachable as one unit with a Tab key
222 // the next Tab key should spring out of the control.
223 // To reach it the control itself should get focus and set it
224 // on entries. The entries themself should not be reachable with
225 // the Tab key directly. So each entry should have WB_NOTABSTOP.
227 // In other words the creator should create the control with the following
228 // flags:
229 // SetStyle( ( GetStyle() | WB_TABSTOP ) & ~WB_DIALOGCONTROL );
231 // TODO: if somebody sets a new font from outside (OutputDevice::SetFont), we would have to react
232 // on this with calculating a new bold font.
233 // Unfortunately, the OutputDevice does not offer a notify mechanism for a changed font.
234 // So settings the font from outside is simply a forbidded scenario at the moment
235 rRenderContext.EnableMapMode(false);
238 ORoadmap::~ORoadmap()
240 disposeOnce();
243 void ORoadmap::dispose()
245 HL_Vector aItemsCopy = m_pImpl->getHyperLabels();
246 m_pImpl->getHyperLabels().clear();
247 for ( HL_Vector::iterator i = aItemsCopy.begin(); i != aItemsCopy.end(); ++i )
249 delete *i;
251 if ( ! m_pImpl->isComplete() )
252 delete m_pImpl->InCompleteHyperLabel;
253 delete m_pImpl;
254 m_pImpl = NULL;
255 Control::dispose();
258 RoadmapTypes::ItemId ORoadmap::GetCurrentRoadmapItemID() const
260 return m_pImpl->getCurItemID();
263 RoadmapItem* ORoadmap::GetPreviousHyperLabel(ItemIndex _Index)
265 RoadmapItem* pOldItem = NULL;
266 if ( _Index > 0 )
267 pOldItem = m_pImpl->getHyperLabels().at( _Index - 1 );
268 return pOldItem;
271 RoadmapItem* ORoadmap::InsertHyperLabel(ItemIndex _Index, const OUString& _sLabel, ItemId _RMID, bool _bEnabled, bool _bIncomplete)
273 if (m_pImpl->getItemCount() == 0)
274 m_pImpl->initItemSize();
276 RoadmapItem* pItem = NULL;
277 RoadmapItem* pOldItem = GetPreviousHyperLabel( _Index );
279 pItem = new RoadmapItem( *this, m_pImpl->getItemSize() );
280 if ( _bIncomplete )
282 pItem->SetInteractive( false );
284 else
286 pItem->SetInteractive( m_pImpl->isInteractive() );
287 m_pImpl->insertHyperLabel( _Index, pItem );
289 pItem->SetPosition( pOldItem );
290 pItem->Update( _Index, _sLabel );
291 pItem->SetClickHdl(LINK( this, ORoadmap, ImplClickHdl ) );
292 pItem->SetID( _RMID );
293 pItem->SetIndex( _Index );
294 if (!_bEnabled)
295 pItem->Enable( _bEnabled );
296 return pItem;
299 void ORoadmap::SetRoadmapBitmap(const BitmapEx& _rBmp, bool _bInvalidate)
301 m_pImpl->setPicture( _rBmp );
302 if ( _bInvalidate )
303 Invalidate( );
306 void ORoadmap::SetRoadmapInteractive(bool _bInteractive)
308 m_pImpl->setInteractive( _bInteractive );
310 const HL_Vector& rItems = m_pImpl->getHyperLabels();
311 for ( HL_Vector::const_iterator i = rItems.begin();
312 i != rItems.end();
316 (*i)->SetInteractive( _bInteractive );
320 bool ORoadmap::IsRoadmapInteractive()
322 return m_pImpl->isInteractive();
325 void ORoadmap::SetRoadmapComplete(bool _bComplete)
327 bool bWasComplete = m_pImpl->isComplete();
328 m_pImpl->setComplete( _bComplete );
329 if (_bComplete)
331 if (m_pImpl->InCompleteHyperLabel != NULL)
333 delete m_pImpl->InCompleteHyperLabel;
334 m_pImpl->InCompleteHyperLabel = NULL;
337 else if (bWasComplete)
338 m_pImpl->InCompleteHyperLabel = InsertHyperLabel(m_pImpl->getItemCount(), OUString("..."), -1, true/*bEnabled*/, true/*bIncomplete*/ );
341 void ORoadmap::UpdatefollowingHyperLabels(ItemIndex _nIndex)
343 const HL_Vector& rItems = m_pImpl->getHyperLabels();
344 if ( _nIndex < (ItemIndex)rItems.size() )
346 for ( HL_Vector::const_iterator i = rItems.begin() + _nIndex;
347 i != rItems.end();
348 ++i, ++_nIndex
351 RoadmapItem* pItem = *i;
353 pItem->SetIndex( _nIndex );
354 pItem->SetPosition( GetPreviousHyperLabel( _nIndex ) );
357 if ( ! m_pImpl->isComplete() )
359 RoadmapItem* pOldItem = GetPreviousHyperLabel( m_pImpl->getItemCount() );
360 m_pImpl->InCompleteHyperLabel->SetPosition( pOldItem );
361 m_pImpl->InCompleteHyperLabel->Update( m_pImpl->getItemCount(), OUString("...") );
365 void ORoadmap::ReplaceRoadmapItem(ItemIndex _Index, const OUString& _RoadmapItem, ItemId _RMID, bool _bEnabled)
367 RoadmapItem* pItem = GetByIndex( _Index);
368 if ( pItem != NULL )
370 pItem->Update( _Index, _RoadmapItem );
371 pItem->SetID( _RMID );
372 pItem->Enable( _bEnabled );
376 RoadmapTypes::ItemIndex ORoadmap::GetItemCount() const
378 return m_pImpl->getItemCount();
381 RoadmapTypes::ItemId ORoadmap::GetItemID(ItemIndex _nIndex) const
383 const RoadmapItem* pHyperLabel = GetByIndex( _nIndex );
384 if ( pHyperLabel )
385 return pHyperLabel->GetID();
386 return -1;
389 void ORoadmap::InsertRoadmapItem(ItemIndex _Index, const OUString& _RoadmapItem, ItemId _nUniqueId, bool _bEnabled)
391 InsertHyperLabel( _Index, _RoadmapItem, _nUniqueId, _bEnabled, false/*bIncomplete*/ );
392 // TODO YPos is superfluous, if items are always appended
393 UpdatefollowingHyperLabels( _Index + 1 );
396 void ORoadmap::DeleteRoadmapItem(ItemIndex _Index)
398 if ( m_pImpl->getItemCount() > 0 && ( _Index > -1) && ( _Index < m_pImpl->getItemCount() ) )
400 m_pImpl->removeHyperLabel( _Index );
401 UpdatefollowingHyperLabels( _Index );
405 bool ORoadmap::IsRoadmapComplete() const
407 return m_pImpl->isComplete();
410 void ORoadmap::EnableRoadmapItem( ItemId _nItemId, bool _bEnable, ItemIndex _nStartIndex )
412 RoadmapItem* pItem = GetByID( _nItemId, _nStartIndex );
413 if ( pItem != NULL )
414 pItem->Enable( _bEnable );
417 void ORoadmap::ChangeRoadmapItemLabel( ItemId _nID, const OUString& _sLabel, ItemIndex _nStartIndex )
419 RoadmapItem* pItem = GetByID( _nID, _nStartIndex );
420 if ( pItem != NULL )
422 pItem->Update( pItem->GetIndex(), _sLabel );
424 const HL_Vector& rItems = m_pImpl->getHyperLabels();
425 for ( HL_Vector::const_iterator i = rItems.begin() + _nStartIndex;
426 i != rItems.end();
430 (*i)->SetPosition( GetPreviousHyperLabel( i - rItems.begin() ) );
435 void ORoadmap::ChangeRoadmapItemID(ItemId _nID, ItemId _NewID, ItemIndex _nStartIndex)
437 RoadmapItem* pItem = GetByID( _nID, _nStartIndex );
438 if ( pItem != NULL )
439 pItem->SetID( _NewID );
442 RoadmapItem* ORoadmap::GetByID(ItemId _nID, ItemIndex _nStartIndex)
444 ItemId nLocID = 0;
445 const HL_Vector& rItems = m_pImpl->getHyperLabels();
446 for ( HL_Vector::const_iterator i = rItems.begin() + _nStartIndex;
447 i != rItems.end();
451 nLocID = (*i)->GetID();
452 if ( nLocID == _nID )
453 return *i;
455 return NULL;
458 const RoadmapItem* ORoadmap::GetByID(ItemId _nID, ItemIndex _nStartIndex) const
460 return const_cast< ORoadmap* >( this )->GetByID( _nID, _nStartIndex );
463 RoadmapItem* ORoadmap::GetByIndex(ItemIndex _nItemIndex)
465 const HL_Vector& rItems = m_pImpl->getHyperLabels();
466 if ( ( _nItemIndex > -1 ) && ( _nItemIndex < (ItemIndex)rItems.size() ) )
468 return rItems.at( _nItemIndex );
470 return NULL;
473 const RoadmapItem* ORoadmap::GetByIndex(ItemIndex _nItemIndex) const
475 return const_cast< ORoadmap* >( this )->GetByIndex( _nItemIndex );
478 RoadmapTypes::ItemId ORoadmap::GetNextAvailableItemId(ItemIndex _nNewIndex)
480 ItemIndex searchIndex = ++_nNewIndex;
481 while ( searchIndex < m_pImpl->getItemCount() )
483 RoadmapItem* pItem = GetByIndex( searchIndex );
484 if ( pItem->IsEnabled() )
485 return pItem->GetID( );
487 ++searchIndex;
489 return -1;
492 RoadmapTypes::ItemId ORoadmap::GetPreviousAvailableItemId(ItemIndex _nNewIndex)
494 ItemIndex searchIndex = --_nNewIndex;
495 while ( searchIndex > -1 )
497 RoadmapItem* pItem = GetByIndex( searchIndex );
498 if ( pItem->IsEnabled() )
499 return pItem->GetID( );
501 searchIndex--;
503 return -1;
506 void ORoadmap::DeselectOldRoadmapItems()
508 const HL_Vector& rItems = m_pImpl->getHyperLabels();
509 for ( HL_Vector::const_iterator i = rItems.begin();
510 i != rItems.end();
514 (*i)->ToggleBackgroundColor( COL_TRANSPARENT );
518 void ORoadmap::SetItemSelectHdl(const Link<>& _rHdl)
520 m_pImpl->setSelectHdl(_rHdl);
523 Link<> ORoadmap::GetItemSelectHdl() const
525 return m_pImpl->getSelectHdl();
528 void ORoadmap::Select()
530 GetItemSelectHdl().Call( this );
531 CallEventListeners( VCLEVENT_ROADMAP_ITEMSELECTED );
534 void ORoadmap::GetFocus()
536 RoadmapItem* pCurHyperLabel = GetByID( GetCurrentRoadmapItemID() );
537 if ( pCurHyperLabel != NULL )
538 pCurHyperLabel->GrabFocus();
541 bool ORoadmap::SelectRoadmapItemByID( ItemId _nNewID )
543 DeselectOldRoadmapItems();
544 RoadmapItem* pItem = GetByID( _nNewID );
545 if ( pItem != NULL )
547 if ( pItem->IsEnabled() )
549 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
550 pItem->ToggleBackgroundColor( rStyleSettings.GetHighlightColor() ); //HighlightColor
552 pItem->GrabFocus();
553 m_pImpl->setCurItemID(_nNewID);
555 Select();
556 return true;
559 return false;
562 void ORoadmap::Paint(vcl::RenderContext& rRenderContext, const Rectangle& _rRect)
564 if (!m_pImpl->m_bPaintInitialized)
565 implInit(rRenderContext);
566 Control::Paint(rRenderContext, _rRect);
568 // draw the bitmap
569 if (!!m_pImpl->getPicture())
571 Size aBitmapSize = m_pImpl->getPicture().GetSizePixel();
572 Size aMySize(GetOutputSizePixel());
574 Point aBitmapPos(aMySize.Width() - aBitmapSize.Width(), aMySize.Height() - aBitmapSize.Height());
576 // draw it
577 rRenderContext.DrawBitmapEx( aBitmapPos, m_pImpl->getPicture() );
580 // draw the headline
581 DrawHeadline(rRenderContext);
584 void ORoadmap::DrawHeadline(vcl::RenderContext& rRenderContext)
586 Point aTextPos = LogicToPixel(Point(ROADMAP_INDENT_X, 8), MAP_APPFONT);
588 Size aOutputSize(GetOutputSizePixel());
590 // draw it
591 rRenderContext.DrawText(Rectangle(aTextPos, aOutputSize), GetText(),
592 DrawTextFlags::Left | DrawTextFlags::Top | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak);
593 rRenderContext.DrawTextLine(aTextPos, aOutputSize.Width(), STRIKEOUT_NONE, UNDERLINE_SINGLE, UNDERLINE_NONE, false);
594 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
595 rRenderContext.SetLineColor(rStyleSettings.GetFieldTextColor());
596 rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
599 RoadmapItem* ORoadmap::GetByPointer(vcl::Window* pWindow)
601 const HL_Vector& rItems = m_pImpl->getHyperLabels();
602 for ( HL_Vector::const_iterator i = rItems.begin();
603 i != rItems.end();
607 if ( (*i)->Contains( pWindow ) )
608 return *i;
610 return NULL;
613 bool ORoadmap::PreNotify(NotifyEvent& _rNEvt)
615 // capture KeyEvents for taskpane cycling
616 if ( _rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
618 vcl::Window* pWindow = _rNEvt.GetWindow();
619 RoadmapItem* pItem = GetByPointer( pWindow );
620 if ( pItem != NULL )
622 sal_Int16 nKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
623 switch( nKeyCode )
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 ItemId nPrevItemID = GetPreviousAvailableItemId( pItem->GetIndex() );
630 if ( nPrevItemID != -1 )
631 return SelectRoadmapItemByID( nPrevItemID );
633 break;
634 case KEY_DOWN:
636 ItemId nNextItemID = GetNextAvailableItemId( pItem->GetIndex() );
637 if ( nNextItemID != -1 )
638 return SelectRoadmapItemByID( nNextItemID );
640 break;
641 case KEY_SPACE:
642 return SelectRoadmapItemByID( pItem->GetID() );
646 return Window::PreNotify( _rNEvt );
649 IMPL_LINK(ORoadmap, ImplClickHdl, HyperLabel*, _CurHyperLabel)
651 return SelectRoadmapItemByID( _CurHyperLabel->GetID() ) ? 1 : 0;
654 void ORoadmap::DataChanged(const DataChangedEvent& rDCEvt)
656 if ((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
657 ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
658 ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ))
660 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
661 SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) );
662 Color aTextColor = rStyleSettings.GetFieldTextColor();
663 vcl::Font aFont = GetFont();
664 aFont.SetColor( aTextColor );
665 SetFont( aFont );
666 RoadmapTypes::ItemId curItemID = GetCurrentRoadmapItemID();
667 RoadmapItem* pLabelItem = GetByID( curItemID );
668 if (pLabelItem != NULL)
670 pLabelItem->ToggleBackgroundColor(rStyleSettings.GetHighlightColor());
672 Invalidate();
676 RoadmapItem::RoadmapItem(ORoadmap& _rParent, const Size& _rItemPlayground)
677 : m_aItemPlayground(_rItemPlayground)
679 mpID = VclPtr<IDLabel>::Create( &_rParent, WB_WORDBREAK );
680 mpID->SetTextColor( mpID->GetSettings().GetStyleSettings().GetFieldTextColor( ) );
681 mpID->Show();
682 mpDescription = VclPtr<HyperLabel>::Create( &_rParent, WB_NOTABSTOP | WB_WORDBREAK );
683 mpDescription->Show();
686 RoadmapItem::~RoadmapItem()
688 mpID.disposeAndClear();
689 mpDescription.disposeAndClear();
692 bool RoadmapItem::Contains(const vcl::Window* _pWindow) const
694 return ( mpID == _pWindow ) || ( mpDescription == _pWindow );
697 void RoadmapItem::GrabFocus()
699 if ( mpDescription )
700 mpDescription->GrabFocus();
703 void RoadmapItem::SetInteractive(bool _bInteractive)
705 if ( mpDescription )
706 mpDescription->SetInteractive(_bInteractive);
709 void RoadmapItem::SetID(sal_Int16 _ID)
711 if ( mpDescription )
712 mpDescription->SetID(_ID);
715 sal_Int16 RoadmapItem::GetID() const
717 return mpDescription ? mpDescription->GetID() : sal_Int16(-1);
720 void RoadmapItem::ImplUpdateIndex(const ItemIndex _nIndex)
722 mpDescription->SetIndex( _nIndex );
724 OUString aIDText = OUString::number( _nIndex + 1 ) + ".";
725 mpID->SetText( aIDText );
727 // update the geometry of both controls
728 ImplUpdatePosSize();
731 void RoadmapItem::SetIndex(ItemIndex _Index)
733 ImplUpdateIndex(_Index);
736 RoadmapTypes::ItemIndex RoadmapItem::GetIndex() const
738 return mpDescription ? mpDescription->GetIndex() : ItemIndex(-1);
741 void RoadmapItem::SetPosition(RoadmapItem* _pOldItem)
743 Point aIDPos;
744 if ( _pOldItem == NULL )
746 aIDPos = mpID->LogicToPixel( Point( ROADMAP_INDENT_X, ROADMAP_INDENT_Y ), MAP_APPFONT );
748 else
750 Size aOldSize = _pOldItem->GetDescriptionHyperLabel()->GetSizePixel();
752 aIDPos = _pOldItem->mpID->GetPosPixel();
753 aIDPos.Y() += aOldSize.Height();
754 aIDPos.Y() += mpID->GetParent()->LogicToPixel( Size( 0, ROADMAP_ITEM_DISTANCE_Y ) ).Height();
756 mpID->SetPosPixel( aIDPos );
758 sal_Int32 nDescPos = aIDPos.X() + mpID->GetSizePixel().Width();
759 mpDescription->SetPosPixel( Point( nDescPos, aIDPos.Y() ) );
762 void RoadmapItem::Enable(bool _bEnable)
764 mpID->Enable(_bEnable);
765 mpDescription->Enable(_bEnable);
768 bool RoadmapItem::IsEnabled() const
770 return mpID->IsEnabled();
773 void RoadmapItem::ToggleBackgroundColor(const Color& _rGBColor)
775 if (_rGBColor == COL_TRANSPARENT)
777 mpID->SetTextColor( mpID->GetSettings().GetStyleSettings().GetFieldTextColor( ) );
778 mpID->SetControlBackground( COL_TRANSPARENT );
780 else
782 mpID->SetControlBackground( mpID->GetSettings().GetStyleSettings().GetHighlightColor() );
783 mpID->SetTextColor( mpID->GetSettings().GetStyleSettings().GetHighlightTextColor( ) );
785 mpDescription->ToggleBackgroundColor(_rGBColor);
788 void RoadmapItem::ImplUpdatePosSize()
790 // calculate widths
791 long nIDWidth = mpID->GetTextWidth( mpID->GetText() );
792 long nMaxIDWidth = mpID->GetTextWidth( OUString( "100." ) );
793 nIDWidth = ::std::min( nIDWidth, nMaxIDWidth );
795 // check how many space the description would need
796 Size aDescriptionSize = mpDescription->CalcMinimumSize( m_aItemPlayground.Width() - nIDWidth );
798 // position and size both controls
799 Size aIDSize( nIDWidth, aDescriptionSize.Height() );
800 mpID->SetSizePixel( aIDSize );
802 Point aIDPos = mpID->GetPosPixel();
803 mpDescription->SetPosPixel( Point( aIDPos.X() + nIDWidth, aIDPos.Y() ) );
804 mpDescription->SetSizePixel( aDescriptionSize );
807 void RoadmapItem::Update(ItemIndex _RMIndex, const OUString& _rText)
809 // update description label
810 mpDescription->SetLabel( _rText );
812 // update the index in both controls, which triggers updating the geometry of both
813 ImplUpdateIndex( _RMIndex );
816 void RoadmapItem::SetClickHdl(const Link<>& rLink)
818 if ( mpDescription )
819 mpDescription->SetClickHdl( rLink);
822 IDLabel::IDLabel(vcl::Window* _pParent, WinBits _nWinStyle)
823 : FixedText(_pParent, _nWinStyle)
827 void IDLabel::DataChanged(const DataChangedEvent& rDCEvt)
829 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
830 FixedText::DataChanged( rDCEvt );
831 if ((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
832 ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
833 ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ))
835 const Color& rGBColor = GetControlBackground();
836 if (rGBColor == COL_TRANSPARENT)
837 SetTextColor( rStyleSettings.GetFieldTextColor( ) );
838 else
840 SetControlBackground(rStyleSettings.GetHighlightColor());
841 SetTextColor( rStyleSettings.GetHighlightTextColor( ) );
843 Invalidate();
847 } // namespace svt
849 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */