bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / control / roadmap.cxx
blob8d228e629c4bcefce6e7c4bd66f8645fa07e72ac
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 <vector>
21 #include <algorithm>
22 #include <vcl/event.hxx>
23 #include <vcl/toolkit/roadmap.hxx>
24 #include <vcl/settings.hxx>
25 #include <hyperlabel.hxx>
26 #include <tools/color.hxx>
27 #include <rtl/ustring.hxx>
29 constexpr long LABELBASEMAPHEIGHT = 8;
30 constexpr long ROADMAP_INDENT_X = 4;
31 constexpr long ROADMAP_INDENT_Y = 27;
32 constexpr long ROADMAP_ITEM_DISTANCE_Y = 6;
34 namespace vcl
37 typedef std::vector< RoadmapItem* > HL_Vector;
39 //= ColorChanger
41 class IDLabel : public FixedText
43 public:
44 IDLabel( vcl::Window* _pParent, WinBits _nWinStyle );
45 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
46 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
49 class RoadmapItem : public RoadmapTypes
51 private:
52 VclPtr<IDLabel> mpID;
53 VclPtr<HyperLabel> mpDescription;
54 const Size m_aItemPlayground;
56 public:
57 RoadmapItem( ORoadmap& _rParent, const Size& _rItemPlayground );
58 ~RoadmapItem();
60 void SetID( sal_Int16 ID );
61 sal_Int16 GetID() const;
63 void SetIndex( ItemIndex Index );
64 ItemIndex GetIndex() const;
66 void Update( ItemIndex RMIndex, const OUString& _rText );
68 void SetPosition( RoadmapItem const * OldHyperLabel );
70 void ToggleBackgroundColor( const Color& _rGBColor );
71 void SetInteractive( bool _bInteractive );
73 void SetClickHdl( const Link<HyperLabel*,void>& rLink );
74 void Enable( bool bEnable );
75 bool IsEnabled() const;
76 void GrabFocus();
78 bool Contains( const vcl::Window* _pWindow ) const;
80 private:
81 void ImplUpdateIndex( const ItemIndex _nIndex );
82 void ImplUpdatePosSize();
85 //= RoadmapImpl
87 class RoadmapImpl : public RoadmapTypes
89 protected:
90 const ORoadmap& m_rAntiImpl;
91 Link<LinkParamNone*,void> m_aSelectHdl;
92 BitmapEx m_aPicture;
93 HL_Vector m_aRoadmapSteps;
94 ItemId m_iCurItemID;
95 bool m_bInteractive : 1;
96 bool m_bComplete : 1;
97 Size m_aItemSizePixel;
98 public:
99 bool m_bPaintInitialized : 1;
101 public:
102 explicit RoadmapImpl(const ORoadmap& rAntiImpl)
103 : m_rAntiImpl(rAntiImpl)
104 , m_iCurItemID(-1)
105 , m_bInteractive(true)
106 , m_bComplete(true)
107 , m_bPaintInitialized(false)
108 , InCompleteHyperLabel(nullptr)
111 RoadmapItem* InCompleteHyperLabel;
113 HL_Vector& getHyperLabels()
115 return m_aRoadmapSteps;
118 void insertHyperLabel(ItemIndex Index, RoadmapItem* _rRoadmapStep)
120 m_aRoadmapSteps.insert(m_aRoadmapSteps.begin() + Index, _rRoadmapStep);
123 ItemIndex getItemCount() const
125 return m_aRoadmapSteps.size();
128 void setCurItemID(ItemId i)
130 m_iCurItemID = i;
132 ItemId getCurItemID() const
134 return m_iCurItemID;
137 void setInteractive(const bool _bInteractive)
139 m_bInteractive = _bInteractive;
141 bool isInteractive() const
143 return m_bInteractive;
146 void setComplete(const bool _bComplete)
148 m_bComplete = _bComplete;
150 bool isComplete() const
152 return m_bComplete;
155 void setPicture(const BitmapEx& _rPic)
157 m_aPicture = _rPic;
159 const BitmapEx& getPicture() const
161 return m_aPicture;
164 void setSelectHdl(const Link<LinkParamNone*,void>& _rHdl)
166 m_aSelectHdl = _rHdl;
168 const Link<LinkParamNone*,void>& getSelectHdl() const
170 return m_aSelectHdl;
173 void initItemSize();
174 const Size& getItemSize() const
176 return m_aItemSizePixel;
179 void removeHyperLabel(ItemIndex Index)
181 if ((Index > -1) && (Index < getItemCount()))
183 delete m_aRoadmapSteps[Index];
184 m_aRoadmapSteps.erase(m_aRoadmapSteps.begin() + Index);
189 void RoadmapImpl::initItemSize()
191 Size aLabelSize( m_rAntiImpl.GetOutputSizePixel() );
192 aLabelSize.setHeight( m_rAntiImpl.LogicToPixel(Size(0, LABELBASEMAPHEIGHT), MapMode(MapUnit::MapAppFont)).Height() );
193 aLabelSize.AdjustWidth( -(m_rAntiImpl.LogicToPixel(Size(2 * ROADMAP_INDENT_X, 0), MapMode(MapUnit::MapAppFont)).Width()) );
194 m_aItemSizePixel = aLabelSize;
197 //= Roadmap
199 ORoadmap::ORoadmap(vcl::Window* _pParent, WinBits _nWinStyle)
200 : Control(_pParent, _nWinStyle)
201 , m_pImpl(new RoadmapImpl(*this))
205 void ORoadmap::implInit(vcl::RenderContext& rRenderContext)
207 m_pImpl->InCompleteHyperLabel = nullptr;
208 m_pImpl->setCurItemID(-1);
209 m_pImpl->setComplete(true);
210 m_pImpl->m_bPaintInitialized = true;
212 // Roadmap control should be reachable as one unit with a Tab key
213 // the next Tab key should spring out of the control.
214 // To reach it the control itself should get focus and set it
215 // on entries. The entries themself should not be reachable with
216 // the Tab key directly. So each entry should have WB_NOTABSTOP.
218 // In other words the creator should create the control with the following
219 // flags:
220 // SetStyle( ( GetStyle() | WB_TABSTOP ) & ~WB_DIALOGCONTROL );
222 // TODO: if somebody sets a new font from outside (OutputDevice::SetFont), we would have to react
223 // on this with calculating a new bold font.
224 // Unfortunately, the OutputDevice does not offer a notify mechanism for a changed font.
225 // So settings the font from outside is simply a forbidden scenario at the moment
226 rRenderContext.EnableMapMode(false);
229 ORoadmap::~ORoadmap()
231 disposeOnce();
234 void ORoadmap::dispose()
236 HL_Vector aItemsCopy = m_pImpl->getHyperLabels();
237 m_pImpl->getHyperLabels().clear();
238 for (auto const& itemCopy : aItemsCopy)
240 delete itemCopy;
242 if ( ! m_pImpl->isComplete() )
243 delete m_pImpl->InCompleteHyperLabel;
244 m_pImpl.reset();
245 Control::dispose();
248 RoadmapTypes::ItemId ORoadmap::GetCurrentRoadmapItemID() const
250 return m_pImpl->getCurItemID();
253 RoadmapItem* ORoadmap::GetPreviousHyperLabel(ItemIndex Index)
255 RoadmapItem* pOldItem = nullptr;
256 if ( Index > 0 )
257 pOldItem = m_pImpl->getHyperLabels().at( Index - 1 );
258 return pOldItem;
261 RoadmapItem* ORoadmap::InsertHyperLabel(ItemIndex Index, const OUString& _sLabel, ItemId RMID, bool _bEnabled, bool _bIncomplete)
263 if (m_pImpl->getItemCount() == 0)
264 m_pImpl->initItemSize();
266 RoadmapItem* pItem = nullptr;
267 RoadmapItem* pOldItem = GetPreviousHyperLabel( Index );
269 pItem = new RoadmapItem( *this, m_pImpl->getItemSize() );
270 if ( _bIncomplete )
272 pItem->SetInteractive( false );
274 else
276 pItem->SetInteractive( m_pImpl->isInteractive() );
277 m_pImpl->insertHyperLabel( Index, pItem );
279 pItem->SetPosition( pOldItem );
280 pItem->Update( Index, _sLabel );
281 pItem->SetClickHdl(LINK( this, ORoadmap, ImplClickHdl ) );
282 pItem->SetID( RMID );
283 pItem->SetIndex( Index );
284 if (!_bEnabled)
285 pItem->Enable( _bEnabled );
286 return pItem;
289 void ORoadmap::SetRoadmapBitmap(const BitmapEx& _rBmp)
291 m_pImpl->setPicture( _rBmp );
292 Invalidate( );
295 void ORoadmap::SetRoadmapInteractive(bool _bInteractive)
297 m_pImpl->setInteractive( _bInteractive );
299 const HL_Vector& rItems = m_pImpl->getHyperLabels();
300 for (auto const& item : rItems)
302 item->SetInteractive( _bInteractive );
306 bool ORoadmap::IsRoadmapInteractive() const
308 return m_pImpl->isInteractive();
311 void ORoadmap::SetRoadmapComplete(bool _bComplete)
313 bool bWasComplete = m_pImpl->isComplete();
314 m_pImpl->setComplete( _bComplete );
315 if (_bComplete)
317 if (m_pImpl->InCompleteHyperLabel != nullptr)
319 delete m_pImpl->InCompleteHyperLabel;
320 m_pImpl->InCompleteHyperLabel = nullptr;
323 else if (bWasComplete)
324 m_pImpl->InCompleteHyperLabel = InsertHyperLabel(m_pImpl->getItemCount(), "...", -1, true/*bEnabled*/, true/*bIncomplete*/ );
327 void ORoadmap::UpdatefollowingHyperLabels(ItemIndex _nIndex)
329 const HL_Vector& rItems = m_pImpl->getHyperLabels();
330 if ( _nIndex < static_cast<ItemIndex>(rItems.size()) )
332 for ( HL_Vector::const_iterator i = rItems.begin() + _nIndex;
333 i != rItems.end();
334 ++i, ++_nIndex
337 RoadmapItem* pItem = *i;
339 pItem->SetIndex( _nIndex );
340 pItem->SetPosition( GetPreviousHyperLabel( _nIndex ) );
344 if ( ! m_pImpl->isComplete() )
346 RoadmapItem* pOldItem = GetPreviousHyperLabel( m_pImpl->getItemCount() );
347 m_pImpl->InCompleteHyperLabel->SetPosition( pOldItem );
348 m_pImpl->InCompleteHyperLabel->Update( m_pImpl->getItemCount(), "..." );
352 void ORoadmap::ReplaceRoadmapItem(ItemIndex Index, const OUString& roadmapItem, ItemId RMID, bool _bEnabled)
354 RoadmapItem* pItem = GetByIndex( Index);
355 if ( pItem != nullptr )
357 pItem->Update( Index, roadmapItem );
358 pItem->SetID( RMID );
359 pItem->Enable( _bEnabled );
363 RoadmapTypes::ItemIndex ORoadmap::GetItemCount() const
365 return m_pImpl->getItemCount();
368 RoadmapTypes::ItemId ORoadmap::GetItemID(ItemIndex _nIndex) const
370 const RoadmapItem* pHyperLabel = GetByIndex( _nIndex );
371 if ( pHyperLabel )
372 return pHyperLabel->GetID();
373 return -1;
376 void ORoadmap::InsertRoadmapItem(ItemIndex Index, const OUString& RoadmapItem, ItemId _nUniqueId, bool _bEnabled)
378 InsertHyperLabel( Index, RoadmapItem, _nUniqueId, _bEnabled, false/*bIncomplete*/ );
379 // TODO YPos is superfluous, if items are always appended
380 UpdatefollowingHyperLabels( Index + 1 );
383 void ORoadmap::DeleteRoadmapItem(ItemIndex Index)
385 if ( m_pImpl->getItemCount() > 0 && ( Index > -1) && ( Index < m_pImpl->getItemCount() ) )
387 m_pImpl->removeHyperLabel( Index );
388 UpdatefollowingHyperLabels( Index );
392 bool ORoadmap::IsRoadmapComplete() const
394 return m_pImpl->isComplete();
397 void ORoadmap::EnableRoadmapItem( ItemId _nItemId, bool _bEnable )
399 RoadmapItem* pItem = GetByID( _nItemId );
400 if ( pItem != nullptr )
401 pItem->Enable( _bEnable );
404 void ORoadmap::ChangeRoadmapItemLabel( ItemId _nID, const OUString& _sLabel )
406 RoadmapItem* pItem = GetByID( _nID );
407 if ( pItem == nullptr )
408 return;
410 pItem->Update( pItem->GetIndex(), _sLabel );
412 const HL_Vector& rItems = m_pImpl->getHyperLabels();
413 size_t nPos = 0;
414 for (auto const& item : rItems)
416 item->SetPosition( GetPreviousHyperLabel(nPos) );
417 ++nPos;
421 void ORoadmap::ChangeRoadmapItemID(ItemId _nID, ItemId NewID)
423 RoadmapItem* pItem = GetByID( _nID );
424 if ( pItem != nullptr )
425 pItem->SetID( NewID );
428 RoadmapItem* ORoadmap::GetByID(ItemId _nID)
430 ItemId nLocID = 0;
431 const HL_Vector& rItems = m_pImpl->getHyperLabels();
432 for (auto const& item : rItems)
434 nLocID = item->GetID();
435 if ( nLocID == _nID )
436 return item;
438 return nullptr;
441 const RoadmapItem* ORoadmap::GetByID(ItemId _nID) const
443 return const_cast< ORoadmap* >( this )->GetByID( _nID );
446 RoadmapItem* ORoadmap::GetByIndex(ItemIndex _nItemIndex)
448 const HL_Vector& rItems = m_pImpl->getHyperLabels();
449 if ( ( _nItemIndex > -1 ) && ( _nItemIndex < static_cast<ItemIndex>(rItems.size()) ) )
451 return rItems.at( _nItemIndex );
453 return nullptr;
456 const RoadmapItem* ORoadmap::GetByIndex(ItemIndex _nItemIndex) const
458 return const_cast< ORoadmap* >( this )->GetByIndex( _nItemIndex );
461 RoadmapTypes::ItemId ORoadmap::GetNextAvailableItemId(ItemIndex _nNewIndex)
463 ItemIndex searchIndex = ++_nNewIndex;
464 while ( searchIndex < m_pImpl->getItemCount() )
466 RoadmapItem* pItem = GetByIndex( searchIndex );
467 if ( pItem->IsEnabled() )
468 return pItem->GetID( );
470 ++searchIndex;
472 return -1;
475 RoadmapTypes::ItemId ORoadmap::GetPreviousAvailableItemId(ItemIndex _nNewIndex)
477 ItemIndex searchIndex = --_nNewIndex;
478 while ( searchIndex > -1 )
480 RoadmapItem* pItem = GetByIndex( searchIndex );
481 if ( pItem->IsEnabled() )
482 return pItem->GetID( );
484 searchIndex--;
486 return -1;
489 void ORoadmap::DeselectOldRoadmapItems()
491 const HL_Vector& rItems = m_pImpl->getHyperLabels();
492 for (auto const& item : rItems)
494 item->ToggleBackgroundColor( COL_TRANSPARENT );
498 void ORoadmap::SetItemSelectHdl(const Link<LinkParamNone*,void>& _rHdl)
500 m_pImpl->setSelectHdl(_rHdl);
503 Link<LinkParamNone*,void> const & ORoadmap::GetItemSelectHdl() const
505 return m_pImpl->getSelectHdl();
508 void ORoadmap::Select()
510 GetItemSelectHdl().Call( nullptr );
511 CallEventListeners( VclEventId::RoadmapItemSelected );
514 void ORoadmap::GetFocus()
516 RoadmapItem* pCurHyperLabel = GetByID( GetCurrentRoadmapItemID() );
517 if ( pCurHyperLabel != nullptr )
518 pCurHyperLabel->GrabFocus();
521 bool ORoadmap::SelectRoadmapItemByID( ItemId _nNewID )
523 DeselectOldRoadmapItems();
524 RoadmapItem* pItem = GetByID( _nNewID );
525 if ( pItem != nullptr )
527 if ( pItem->IsEnabled() )
529 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
530 pItem->ToggleBackgroundColor( rStyleSettings.GetHighlightColor() ); //HighlightColor
532 pItem->GrabFocus();
533 m_pImpl->setCurItemID(_nNewID);
535 Select();
536 return true;
539 return false;
542 void ORoadmap::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect)
544 if (!m_pImpl->m_bPaintInitialized)
545 implInit(rRenderContext);
546 Control::Paint(rRenderContext, _rRect);
548 // draw the bitmap
549 if (!!m_pImpl->getPicture())
551 Size aBitmapSize = m_pImpl->getPicture().GetSizePixel();
552 Size aMySize(GetOutputSizePixel());
554 Point aBitmapPos(aMySize.Width() - aBitmapSize.Width(), aMySize.Height() - aBitmapSize.Height());
556 // draw it
557 rRenderContext.DrawBitmapEx( aBitmapPos, m_pImpl->getPicture() );
560 // draw the headline
561 DrawHeadline(rRenderContext);
564 void ORoadmap::DrawHeadline(vcl::RenderContext& rRenderContext)
566 Point aTextPos = LogicToPixel(Point(ROADMAP_INDENT_X, 8), MapMode(MapUnit::MapAppFont));
568 Size aOutputSize(GetOutputSizePixel());
570 // draw it
571 rRenderContext.DrawText(tools::Rectangle(aTextPos, aOutputSize), GetText(),
572 DrawTextFlags::Left | DrawTextFlags::Top | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak);
573 rRenderContext.DrawTextLine(aTextPos, aOutputSize.Width(), STRIKEOUT_NONE, LINESTYLE_SINGLE, LINESTYLE_NONE);
574 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
575 rRenderContext.SetLineColor(rStyleSettings.GetFieldTextColor());
576 rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
579 RoadmapItem* ORoadmap::GetByPointer(vcl::Window const * pWindow)
581 const HL_Vector& rItems = m_pImpl->getHyperLabels();
582 for (auto const& item : rItems)
584 if ( item->Contains( pWindow ) )
585 return item;
587 return nullptr;
590 bool ORoadmap::PreNotify(NotifyEvent& _rNEvt)
592 // capture KeyEvents for taskpane cycling
593 if ( _rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
595 vcl::Window* pWindow = _rNEvt.GetWindow();
596 RoadmapItem* pItem = GetByPointer( pWindow );
597 if ( pItem != nullptr )
599 sal_Int16 nKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
600 switch( nKeyCode )
602 case KEY_UP:
603 { // Note: Performance wise this is not optimal, because we search for an ID in the labels
604 // and afterwards we search again for a label with the appropriate ID ->
605 // unnecessarily we search twice!!!
606 ItemId nPrevItemID = GetPreviousAvailableItemId( pItem->GetIndex() );
607 if ( nPrevItemID != -1 )
608 return SelectRoadmapItemByID( nPrevItemID );
610 break;
611 case KEY_DOWN:
613 ItemId nNextItemID = GetNextAvailableItemId( pItem->GetIndex() );
614 if ( nNextItemID != -1 )
615 return SelectRoadmapItemByID( nNextItemID );
617 break;
618 case KEY_SPACE:
619 return SelectRoadmapItemByID( pItem->GetID() );
623 return Window::PreNotify( _rNEvt );
626 IMPL_LINK(ORoadmap, ImplClickHdl, HyperLabel*, CurHyperLabel, void)
628 SelectRoadmapItemByID( CurHyperLabel->GetID() );
631 void ORoadmap::DataChanged(const DataChangedEvent& rDCEvt)
633 if (!((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
634 ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
635 ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE )))
636 return;
638 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
639 SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) );
640 Color aTextColor = rStyleSettings.GetFieldTextColor();
641 vcl::Font aFont = GetFont();
642 aFont.SetColor( aTextColor );
643 SetFont( aFont );
644 RoadmapTypes::ItemId curItemID = GetCurrentRoadmapItemID();
645 RoadmapItem* pLabelItem = GetByID( curItemID );
646 if (pLabelItem != nullptr)
648 pLabelItem->ToggleBackgroundColor(rStyleSettings.GetHighlightColor());
650 Invalidate();
653 void ORoadmap::ApplySettings(vcl::RenderContext& rRenderContext)
655 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
656 Color aTextColor = rStyleSettings.GetFieldTextColor();
657 vcl::Font aFont = rRenderContext.GetFont();
658 aFont.SetColor(aTextColor);
659 aFont.SetWeight(WEIGHT_BOLD);
660 aFont.SetUnderline(LINESTYLE_SINGLE);
661 rRenderContext.SetFont(aFont);
662 rRenderContext.SetBackground(rStyleSettings.GetFieldColor());
665 RoadmapItem::RoadmapItem(ORoadmap& _rParent, const Size& _rItemPlayground)
666 : m_aItemPlayground(_rItemPlayground)
668 mpID = VclPtr<IDLabel>::Create( &_rParent, WB_WORDBREAK );
669 mpID->Show();
670 mpDescription = VclPtr<HyperLabel>::Create( &_rParent, WB_NOTABSTOP | WB_WORDBREAK );
671 mpDescription->Show();
674 RoadmapItem::~RoadmapItem()
676 mpID.disposeAndClear();
677 mpDescription.disposeAndClear();
680 bool RoadmapItem::Contains(const vcl::Window* _pWindow) const
682 return ( mpID == _pWindow ) || ( mpDescription == _pWindow );
685 void RoadmapItem::GrabFocus()
687 if ( mpDescription )
688 mpDescription->GrabFocus();
691 void RoadmapItem::SetInteractive(bool _bInteractive)
693 if ( mpDescription )
694 mpDescription->SetInteractive(_bInteractive);
697 void RoadmapItem::SetID(sal_Int16 ID)
699 if ( mpDescription )
700 mpDescription->SetID(ID);
703 sal_Int16 RoadmapItem::GetID() const
705 return mpDescription ? mpDescription->GetID() : sal_Int16(-1);
708 void RoadmapItem::ImplUpdateIndex(const ItemIndex _nIndex)
710 mpDescription->SetIndex( _nIndex );
712 OUString aIDText = OUString::number( _nIndex + 1 ) + ".";
713 mpID->SetText( aIDText );
715 // update the geometry of both controls
716 ImplUpdatePosSize();
719 void RoadmapItem::SetIndex(ItemIndex Index)
721 ImplUpdateIndex(Index);
724 RoadmapTypes::ItemIndex RoadmapItem::GetIndex() const
726 return mpDescription ? mpDescription->GetIndex() : ItemIndex(-1);
729 void RoadmapItem::SetPosition(RoadmapItem const * _pOldItem)
731 Point aIDPos;
732 if ( _pOldItem == nullptr )
734 aIDPos = mpID->LogicToPixel(Point(ROADMAP_INDENT_X, ROADMAP_INDENT_Y), MapMode(MapUnit::MapAppFont));
736 else
738 Size aOldSize = _pOldItem->mpDescription->GetSizePixel();
740 aIDPos = _pOldItem->mpID->GetPosPixel();
741 aIDPos.AdjustY(aOldSize.Height() );
742 aIDPos.AdjustY(mpID->GetParent()->LogicToPixel( Size( 0, ROADMAP_ITEM_DISTANCE_Y ) ).Height() );
744 mpID->SetPosPixel( aIDPos );
746 sal_Int32 nDescPos = aIDPos.X() + mpID->GetSizePixel().Width();
747 mpDescription->SetPosPixel( Point( nDescPos, aIDPos.Y() ) );
750 void RoadmapItem::Enable(bool _bEnable)
752 mpID->Enable(_bEnable);
753 mpDescription->Enable(_bEnable);
756 bool RoadmapItem::IsEnabled() const
758 return mpID->IsEnabled();
761 void RoadmapItem::ToggleBackgroundColor(const Color& _rGBColor)
763 if (_rGBColor == COL_TRANSPARENT)
764 mpID->SetControlBackground();
765 else
766 mpID->SetControlBackground( mpID->GetSettings().GetStyleSettings().GetHighlightColor() );
767 mpDescription->ToggleBackgroundColor(_rGBColor);
770 void RoadmapItem::ImplUpdatePosSize()
772 // calculate widths
773 long nIDWidth = mpID->GetTextWidth( mpID->GetText() );
774 long nMaxIDWidth = mpID->GetTextWidth( "100." );
775 nIDWidth = ::std::min( nIDWidth, nMaxIDWidth );
777 // check how many space the description would need
778 Size aDescriptionSize = mpDescription->CalcMinimumSize( m_aItemPlayground.Width() - nIDWidth );
780 // position and size both controls
781 Size aIDSize( nIDWidth, aDescriptionSize.Height() );
782 mpID->SetSizePixel( aIDSize );
784 Point aIDPos = mpID->GetPosPixel();
785 mpDescription->SetPosPixel( Point( aIDPos.X() + nIDWidth, aIDPos.Y() ) );
786 mpDescription->SetSizePixel( aDescriptionSize );
789 void RoadmapItem::Update(ItemIndex RMIndex, const OUString& _rText)
791 // update description label
792 mpDescription->SetLabel( _rText );
794 // update the index in both controls, which triggers updating the geometry of both
795 ImplUpdateIndex( RMIndex );
798 void RoadmapItem::SetClickHdl(const Link<HyperLabel*,void>& rLink)
800 if ( mpDescription )
801 mpDescription->SetClickHdl( rLink);
804 IDLabel::IDLabel(vcl::Window* _pParent, WinBits _nWinStyle)
805 : FixedText(_pParent, _nWinStyle)
809 void IDLabel::ApplySettings(vcl::RenderContext& rRenderContext)
811 FixedText::ApplySettings(rRenderContext);
813 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
814 if (GetControlBackground() == COL_TRANSPARENT)
815 rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
816 else
817 rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
820 void IDLabel::DataChanged(const DataChangedEvent& rDCEvt)
822 FixedText::DataChanged( rDCEvt );
824 if ((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
825 ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
826 ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ))
828 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
829 if (GetControlBackground() != COL_TRANSPARENT)
830 SetControlBackground(rStyleSettings.GetHighlightColor());
831 Invalidate();
835 } // namespace vcl
837 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */