sdext: adapt xpdfwrapper to poppler 24.12
[LibreOffice.git] / vcl / source / control / roadmap.cxx
blob9216fb29a230c5117c2bfbc3acfd1f383db3c359
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 <o3tl/safeint.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/toolkit/roadmap.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/vclevent.hxx>
27 #include <hyperlabel.hxx>
28 #include <tools/color.hxx>
29 #include <rtl/ustring.hxx>
31 constexpr tools::Long LABELBASEMAPHEIGHT = 8;
32 constexpr tools::Long ROADMAP_INDENT_X = 4;
33 constexpr tools::Long ROADMAP_INDENT_Y = 27;
34 constexpr tools::Long ROADMAP_ITEM_DISTANCE_Y = 6;
36 namespace vcl
39 typedef std::vector< RoadmapItem* > HL_Vector;
41 //= ColorChanger
43 namespace {
45 class IDLabel : public FixedText
47 public:
48 IDLabel( vcl::Window* _pParent, WinBits _nWinStyle );
49 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
50 virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
55 class RoadmapItem : public RoadmapTypes
57 private:
58 VclPtr<IDLabel> mpID;
59 VclPtr<HyperLabel> mpDescription;
60 const Size m_aItemPlayground;
62 public:
63 RoadmapItem( ORoadmap& _rParent, const Size& _rItemPlayground );
64 ~RoadmapItem();
66 void SetID( sal_Int16 ID );
67 sal_Int16 GetID() const;
69 void SetIndex( ItemIndex Index );
70 ItemIndex GetIndex() const;
72 void Update( ItemIndex RMIndex, const OUString& _rText );
74 void SetPosition( RoadmapItem const * OldHyperLabel );
76 void ToggleBackgroundColor( const Color& _rGBColor );
77 void SetInteractive( bool _bInteractive );
79 void SetClickHdl( const Link<HyperLabel*,void>& rLink );
80 void Enable( bool bEnable );
81 bool IsEnabled() const;
82 void GrabFocus();
84 bool Contains( const vcl::Window* _pWindow ) const;
86 private:
87 void ImplUpdateIndex( const ItemIndex _nIndex );
88 void ImplUpdatePosSize();
91 //= RoadmapImpl
93 class RoadmapImpl : public RoadmapTypes
95 protected:
96 const ORoadmap& m_rAntiImpl;
97 Link<LinkParamNone*,void> m_aSelectHdl;
98 BitmapEx m_aPicture;
99 HL_Vector m_aRoadmapSteps;
100 ItemId m_iCurItemID;
101 bool m_bInteractive : 1;
102 bool m_bComplete : 1;
103 Size m_aItemSizePixel;
104 public:
105 bool m_bPaintInitialized : 1;
107 public:
108 explicit RoadmapImpl(const ORoadmap& rAntiImpl)
109 : m_rAntiImpl(rAntiImpl)
110 , m_iCurItemID(-1)
111 , m_bInteractive(true)
112 , m_bComplete(true)
113 , m_bPaintInitialized(false)
114 , InCompleteHyperLabel(nullptr)
117 RoadmapItem* InCompleteHyperLabel;
119 HL_Vector& getHyperLabels()
121 return m_aRoadmapSteps;
124 void insertHyperLabel(ItemIndex Index, RoadmapItem* _rRoadmapStep)
126 m_aRoadmapSteps.insert(m_aRoadmapSteps.begin() + Index, _rRoadmapStep);
129 ItemIndex getItemCount() const
131 return m_aRoadmapSteps.size();
134 void setCurItemID(ItemId i)
136 m_iCurItemID = i;
138 ItemId getCurItemID() const
140 return m_iCurItemID;
143 void setInteractive(const bool _bInteractive)
145 m_bInteractive = _bInteractive;
147 bool isInteractive() const
149 return m_bInteractive;
152 void setComplete(const bool _bComplete)
154 m_bComplete = _bComplete;
156 bool isComplete() const
158 return m_bComplete;
161 void setPicture(const BitmapEx& _rPic)
163 m_aPicture = _rPic;
165 const BitmapEx& getPicture() const
167 return m_aPicture;
170 void setSelectHdl(const Link<LinkParamNone*,void>& _rHdl)
172 m_aSelectHdl = _rHdl;
174 const Link<LinkParamNone*,void>& getSelectHdl() const
176 return m_aSelectHdl;
179 void initItemSize();
180 const Size& getItemSize() const
182 return m_aItemSizePixel;
185 void removeHyperLabel(ItemIndex Index)
187 if ((Index > -1) && (Index < getItemCount()))
189 delete m_aRoadmapSteps[Index];
190 m_aRoadmapSteps.erase(m_aRoadmapSteps.begin() + Index);
195 void RoadmapImpl::initItemSize()
197 Size aLabelSize( m_rAntiImpl.GetOutputSizePixel() );
198 aLabelSize.setHeight( m_rAntiImpl.LogicToPixel(Size(0, LABELBASEMAPHEIGHT), MapMode(MapUnit::MapAppFont)).Height() );
199 aLabelSize.AdjustWidth( -(m_rAntiImpl.LogicToPixel(Size(2 * ROADMAP_INDENT_X, 0), MapMode(MapUnit::MapAppFont)).Width()) );
200 m_aItemSizePixel = aLabelSize;
203 //= Roadmap
205 ORoadmap::ORoadmap(vcl::Window* _pParent, WinBits _nWinStyle)
206 : Control(_pParent, _nWinStyle)
207 , m_pImpl(new RoadmapImpl(*this))
211 void ORoadmap::implInit(vcl::RenderContext& rRenderContext)
213 delete m_pImpl->InCompleteHyperLabel;
214 m_pImpl->InCompleteHyperLabel = nullptr;
215 m_pImpl->setCurItemID(-1);
216 m_pImpl->setComplete(true);
217 m_pImpl->m_bPaintInitialized = true;
219 // Roadmap control should be reachable as one unit with a Tab key
220 // the next Tab key should spring out of the control.
221 // To reach it the control itself should get focus and set it
222 // on entries. The entries themself should not be reachable with
223 // the Tab key directly. So each entry should have WB_NOTABSTOP.
225 // In other words the creator should create the control with the following
226 // flags:
227 // SetStyle( ( GetStyle() | WB_TABSTOP ) & ~WB_DIALOGCONTROL );
229 // TODO: if somebody sets a new font from outside (OutputDevice::SetFont), we would have to react
230 // on this with calculating a new bold font.
231 // Unfortunately, the OutputDevice does not offer a notify mechanism for a changed font.
232 // So settings the font from outside is simply a forbidden scenario at the moment
233 rRenderContext.EnableMapMode(false);
236 ORoadmap::~ORoadmap()
238 disposeOnce();
241 void ORoadmap::dispose()
243 HL_Vector aItemsCopy = m_pImpl->getHyperLabels();
244 m_pImpl->getHyperLabels().clear();
245 for (auto const& itemCopy : aItemsCopy)
247 delete itemCopy;
249 if ( ! m_pImpl->isComplete() )
250 delete m_pImpl->InCompleteHyperLabel;
251 m_pImpl.reset();
252 Control::dispose();
255 RoadmapTypes::ItemId ORoadmap::GetCurrentRoadmapItemID() const
257 return m_pImpl->getCurItemID();
260 RoadmapItem* ORoadmap::GetPreviousHyperLabel(ItemIndex Index)
262 RoadmapItem* pOldItem = nullptr;
263 if ( Index > 0 )
264 pOldItem = m_pImpl->getHyperLabels().at( Index - 1 );
265 return pOldItem;
268 RoadmapItem* ORoadmap::InsertHyperLabel(ItemIndex Index, const OUString& _sLabel, ItemId RMID, bool _bEnabled, bool _bIncomplete)
270 if (m_pImpl->getItemCount() == 0)
271 m_pImpl->initItemSize();
273 RoadmapItem* pItem = nullptr;
274 RoadmapItem* pOldItem = GetPreviousHyperLabel( Index );
276 pItem = new RoadmapItem( *this, m_pImpl->getItemSize() );
277 if ( _bIncomplete )
279 pItem->SetInteractive( false );
281 else
283 pItem->SetInteractive( m_pImpl->isInteractive() );
284 m_pImpl->insertHyperLabel( Index, pItem );
286 pItem->SetPosition( pOldItem );
287 pItem->Update( Index, _sLabel );
288 pItem->SetClickHdl(LINK( this, ORoadmap, ImplClickHdl ) );
289 pItem->SetID( RMID );
290 pItem->SetIndex( Index );
291 if (!_bEnabled)
292 pItem->Enable( _bEnabled );
293 return pItem;
296 void ORoadmap::SetRoadmapBitmap(const BitmapEx& _rBmp)
298 m_pImpl->setPicture( _rBmp );
299 Invalidate( );
302 void ORoadmap::SetRoadmapInteractive(bool _bInteractive)
304 m_pImpl->setInteractive( _bInteractive );
306 const HL_Vector& rItems = m_pImpl->getHyperLabels();
307 for (auto const& item : rItems)
309 item->SetInteractive( _bInteractive );
313 bool ORoadmap::IsRoadmapInteractive() const
315 return m_pImpl->isInteractive();
318 void ORoadmap::SetRoadmapComplete(bool _bComplete)
320 bool bWasComplete = m_pImpl->isComplete();
321 m_pImpl->setComplete( _bComplete );
322 if (_bComplete)
324 if (m_pImpl->InCompleteHyperLabel != nullptr)
326 delete m_pImpl->InCompleteHyperLabel;
327 m_pImpl->InCompleteHyperLabel = nullptr;
330 else if (bWasComplete)
331 m_pImpl->InCompleteHyperLabel = InsertHyperLabel(m_pImpl->getItemCount(), u"..."_ustr, -1, true/*bEnabled*/, true/*bIncomplete*/ );
334 void ORoadmap::UpdatefollowingHyperLabels(ItemIndex _nIndex)
336 const HL_Vector& rItems = m_pImpl->getHyperLabels();
337 if ( _nIndex < static_cast<ItemIndex>(rItems.size()) )
339 for ( HL_Vector::const_iterator i = rItems.begin() + _nIndex;
340 i != rItems.end();
341 ++i, ++_nIndex
344 RoadmapItem* pItem = *i;
346 pItem->SetIndex( _nIndex );
347 pItem->SetPosition( GetPreviousHyperLabel( _nIndex ) );
351 if ( ! m_pImpl->isComplete() )
353 RoadmapItem* pOldItem = GetPreviousHyperLabel( m_pImpl->getItemCount() );
354 m_pImpl->InCompleteHyperLabel->SetPosition( pOldItem );
355 m_pImpl->InCompleteHyperLabel->Update( m_pImpl->getItemCount(), u"..."_ustr );
359 void ORoadmap::ReplaceRoadmapItem(ItemIndex Index, const OUString& roadmapItem, ItemId RMID, bool _bEnabled)
361 RoadmapItem* pItem = GetByIndex( Index);
362 if ( pItem != nullptr )
364 pItem->Update( Index, roadmapItem );
365 pItem->SetID( RMID );
366 pItem->Enable( _bEnabled );
370 RoadmapTypes::ItemIndex ORoadmap::GetItemCount() const
372 return m_pImpl->getItemCount();
375 RoadmapTypes::ItemId ORoadmap::GetItemID(ItemIndex _nIndex) const
377 const RoadmapItem* pHyperLabel = GetByIndex( _nIndex );
378 if ( pHyperLabel )
379 return pHyperLabel->GetID();
380 return -1;
383 void ORoadmap::InsertRoadmapItem(ItemIndex Index, const OUString& RoadmapItem, ItemId _nUniqueId, bool _bEnabled)
385 InsertHyperLabel( Index, RoadmapItem, _nUniqueId, _bEnabled, false/*bIncomplete*/ );
386 // TODO YPos is superfluous, if items are always appended
387 UpdatefollowingHyperLabels( Index + 1 );
390 void ORoadmap::DeleteRoadmapItem(ItemIndex Index)
392 if ( m_pImpl->getItemCount() > 0 && ( Index > -1) && ( Index < m_pImpl->getItemCount() ) )
394 m_pImpl->removeHyperLabel( Index );
395 UpdatefollowingHyperLabels( Index );
399 bool ORoadmap::IsRoadmapComplete() const
401 return m_pImpl->isComplete();
404 void ORoadmap::EnableRoadmapItem( ItemId _nItemId, bool _bEnable )
406 RoadmapItem* pItem = GetByID( _nItemId );
407 if ( pItem != nullptr )
408 pItem->Enable( _bEnable );
411 void ORoadmap::ChangeRoadmapItemLabel( ItemId _nID, const OUString& _sLabel )
413 RoadmapItem* pItem = GetByID( _nID );
414 if ( pItem == nullptr )
415 return;
417 pItem->Update( pItem->GetIndex(), _sLabel );
419 const HL_Vector& rItems = m_pImpl->getHyperLabels();
420 size_t nPos = 0;
421 for (auto const& item : rItems)
423 item->SetPosition( GetPreviousHyperLabel(nPos) );
424 ++nPos;
428 void ORoadmap::ChangeRoadmapItemID(ItemId _nID, ItemId NewID)
430 RoadmapItem* pItem = GetByID( _nID );
431 if ( pItem != nullptr )
432 pItem->SetID( NewID );
435 RoadmapItem* ORoadmap::GetByID(ItemId _nID)
437 ItemId nLocID = 0;
438 const HL_Vector& rItems = m_pImpl->getHyperLabels();
439 for (auto const& item : rItems)
441 nLocID = item->GetID();
442 if ( nLocID == _nID )
443 return item;
445 return nullptr;
448 const RoadmapItem* ORoadmap::GetByID(ItemId _nID) const
450 return const_cast< ORoadmap* >( this )->GetByID( _nID );
453 RoadmapItem* ORoadmap::GetByIndex(ItemIndex _nItemIndex)
455 const HL_Vector& rItems = m_pImpl->getHyperLabels();
456 if ( ( _nItemIndex > -1 ) && ( o3tl::make_unsigned(_nItemIndex) < rItems.size() ) )
458 return rItems.at( _nItemIndex );
460 return nullptr;
463 const RoadmapItem* ORoadmap::GetByIndex(ItemIndex _nItemIndex) const
465 return const_cast< ORoadmap* >( this )->GetByIndex( _nItemIndex );
468 RoadmapTypes::ItemId ORoadmap::GetNextAvailableItemId(ItemIndex _nNewIndex)
470 ItemIndex searchIndex = ++_nNewIndex;
471 while ( searchIndex < m_pImpl->getItemCount() )
473 RoadmapItem* pItem = GetByIndex( searchIndex );
474 if ( pItem->IsEnabled() )
475 return pItem->GetID( );
477 ++searchIndex;
479 return -1;
482 RoadmapTypes::ItemId ORoadmap::GetPreviousAvailableItemId(ItemIndex _nNewIndex)
484 ItemIndex searchIndex = --_nNewIndex;
485 while ( searchIndex > -1 )
487 RoadmapItem* pItem = GetByIndex( searchIndex );
488 if ( pItem->IsEnabled() )
489 return pItem->GetID( );
491 searchIndex--;
493 return -1;
496 void ORoadmap::DeselectOldRoadmapItems()
498 const HL_Vector& rItems = m_pImpl->getHyperLabels();
499 for (auto const& item : rItems)
501 item->ToggleBackgroundColor( COL_TRANSPARENT );
505 void ORoadmap::SetItemSelectHdl(const Link<LinkParamNone*,void>& _rHdl)
507 m_pImpl->setSelectHdl(_rHdl);
510 Link<LinkParamNone*,void> const & ORoadmap::GetItemSelectHdl() const
512 return m_pImpl->getSelectHdl();
515 void ORoadmap::Select()
517 GetItemSelectHdl().Call( nullptr );
518 CallEventListeners( VclEventId::RoadmapItemSelected );
521 void ORoadmap::GetFocus()
523 RoadmapItem* pCurHyperLabel = GetByID( GetCurrentRoadmapItemID() );
524 if ( pCurHyperLabel != nullptr )
525 pCurHyperLabel->GrabFocus();
528 bool ORoadmap::SelectRoadmapItemByID(ItemId _nNewID, bool bGrabFocus)
530 DeselectOldRoadmapItems();
531 RoadmapItem* pItem = GetByID( _nNewID );
532 if ( pItem != nullptr )
534 if ( pItem->IsEnabled() )
536 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
537 pItem->ToggleBackgroundColor( rStyleSettings.GetHighlightColor() ); //HighlightColor
539 if (bGrabFocus)
540 pItem->GrabFocus();
541 m_pImpl->setCurItemID(_nNewID);
543 Select();
544 return true;
547 return false;
550 void ORoadmap::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect)
552 if (!m_pImpl->m_bPaintInitialized)
553 implInit(rRenderContext);
554 Control::Paint(rRenderContext, _rRect);
556 // draw the bitmap
557 if (!m_pImpl->getPicture().IsEmpty())
559 Size aBitmapSize = m_pImpl->getPicture().GetSizePixel();
560 Size aMySize(GetOutputSizePixel());
562 Point aBitmapPos(aMySize.Width() - aBitmapSize.Width(), aMySize.Height() - aBitmapSize.Height());
564 // draw it
565 rRenderContext.DrawBitmapEx( aBitmapPos, m_pImpl->getPicture() );
568 // draw the headline
569 DrawHeadline(rRenderContext);
572 void ORoadmap::DrawHeadline(vcl::RenderContext& rRenderContext)
574 Point aTextPos = OutputDevice::LogicToLogic(Point(ROADMAP_INDENT_X, 8), GetMapMode(), MapMode(MapUnit::MapAppFont));
576 Size aOutputSize(rRenderContext.GetOutputSize());
578 // draw it
579 rRenderContext.DrawText(tools::Rectangle(aTextPos, aOutputSize), GetText(),
580 DrawTextFlags::Left | DrawTextFlags::Top | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak);
581 rRenderContext.DrawTextLine(aTextPos, aOutputSize.Width(), STRIKEOUT_NONE, LINESTYLE_SINGLE, LINESTYLE_NONE);
582 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
583 rRenderContext.SetLineColor(rStyleSettings.GetFieldTextColor());
584 rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
587 RoadmapItem* ORoadmap::GetByPointer(vcl::Window const * pWindow)
589 const HL_Vector& rItems = m_pImpl->getHyperLabels();
590 for (auto const& item : rItems)
592 if ( item->Contains( pWindow ) )
593 return item;
595 return nullptr;
598 bool ORoadmap::PreNotify(NotifyEvent& _rNEvt)
600 // capture KeyEvents for taskpane cycling
601 if ( _rNEvt.GetType() == NotifyEventType::KEYINPUT )
603 vcl::Window* pWindow = _rNEvt.GetWindow();
604 RoadmapItem* pItem = GetByPointer( pWindow );
605 if ( pItem != nullptr )
607 sal_Int16 nKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
608 switch( nKeyCode )
610 case KEY_UP:
611 { // Note: Performance wise this is not optimal, because we search for an ID in the labels
612 // and afterwards we search again for a label with the appropriate ID ->
613 // unnecessarily we search twice!!!
614 ItemId nPrevItemID = GetPreviousAvailableItemId( pItem->GetIndex() );
615 if ( nPrevItemID != -1 )
616 return SelectRoadmapItemByID( nPrevItemID );
618 break;
619 case KEY_DOWN:
621 ItemId nNextItemID = GetNextAvailableItemId( pItem->GetIndex() );
622 if ( nNextItemID != -1 )
623 return SelectRoadmapItemByID( nNextItemID );
625 break;
626 case KEY_SPACE:
627 return SelectRoadmapItemByID( pItem->GetID() );
631 return Window::PreNotify( _rNEvt );
634 IMPL_LINK(ORoadmap, ImplClickHdl, HyperLabel*, CurHyperLabel, void)
636 SelectRoadmapItemByID( CurHyperLabel->GetID() );
639 void ORoadmap::DataChanged(const DataChangedEvent& rDCEvt)
641 if (!((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
642 ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
643 ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE )))
644 return;
646 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
647 SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) );
648 Color aTextColor = rStyleSettings.GetFieldTextColor();
649 vcl::Font aFont = GetFont();
650 aFont.SetColor( aTextColor );
651 SetFont( aFont );
652 RoadmapTypes::ItemId curItemID = GetCurrentRoadmapItemID();
653 RoadmapItem* pLabelItem = GetByID( curItemID );
654 if (pLabelItem != nullptr)
656 pLabelItem->ToggleBackgroundColor(rStyleSettings.GetHighlightColor());
658 Invalidate();
661 void ORoadmap::ApplySettings(vcl::RenderContext& rRenderContext)
663 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
664 Color aTextColor = rStyleSettings.GetFieldTextColor();
665 vcl::Font aFont = rRenderContext.GetFont();
666 aFont.SetColor(aTextColor);
667 aFont.SetWeight(WEIGHT_BOLD);
668 aFont.SetUnderline(LINESTYLE_SINGLE);
669 rRenderContext.SetFont(aFont);
670 rRenderContext.SetBackground(rStyleSettings.GetFieldColor());
673 RoadmapItem::RoadmapItem(ORoadmap& _rParent, const Size& _rItemPlayground)
674 : m_aItemPlayground(_rItemPlayground)
676 mpID = VclPtr<IDLabel>::Create( &_rParent, WB_WORDBREAK );
677 mpID->Show();
678 mpDescription = VclPtr<HyperLabel>::Create( &_rParent, WB_NOTABSTOP | WB_WORDBREAK );
679 mpDescription->Show();
682 RoadmapItem::~RoadmapItem()
684 mpID.disposeAndClear();
685 mpDescription.disposeAndClear();
688 bool RoadmapItem::Contains(const vcl::Window* _pWindow) const
690 return ( mpID == _pWindow ) || ( mpDescription == _pWindow );
693 void RoadmapItem::GrabFocus()
695 if ( mpDescription )
696 mpDescription->GrabFocus();
699 void RoadmapItem::SetInteractive(bool _bInteractive)
701 if ( mpDescription )
702 mpDescription->SetInteractive(_bInteractive);
705 void RoadmapItem::SetID(sal_Int16 ID)
707 if ( mpDescription )
708 mpDescription->SetID(ID);
711 sal_Int16 RoadmapItem::GetID() const
713 return mpDescription ? mpDescription->GetID() : sal_Int16(-1);
716 void RoadmapItem::ImplUpdateIndex(const ItemIndex _nIndex)
718 mpDescription->SetIndex( _nIndex );
720 OUString aIDText = OUString::number( _nIndex + 1 ) + ".";
721 mpID->SetText( aIDText );
723 // update the geometry of both controls
724 ImplUpdatePosSize();
727 void RoadmapItem::SetIndex(ItemIndex Index)
729 ImplUpdateIndex(Index);
732 RoadmapTypes::ItemIndex RoadmapItem::GetIndex() const
734 return mpDescription ? mpDescription->GetIndex() : ItemIndex(-1);
737 void RoadmapItem::SetPosition(RoadmapItem const * _pOldItem)
739 Point aIDPos;
740 if ( _pOldItem == nullptr )
742 aIDPos = mpID->LogicToPixel(Point(ROADMAP_INDENT_X, ROADMAP_INDENT_Y), MapMode(MapUnit::MapAppFont));
744 else
746 Size aOldSize = _pOldItem->mpDescription->GetSizePixel();
748 aIDPos = _pOldItem->mpID->GetPosPixel();
749 aIDPos.AdjustY(aOldSize.Height() );
750 aIDPos.AdjustY(mpID->GetParent()->LogicToPixel( Size( 0, ROADMAP_ITEM_DISTANCE_Y ) ).Height() );
752 mpID->SetPosPixel( aIDPos );
754 sal_Int32 nDescPos = aIDPos.X() + mpID->GetSizePixel().Width();
755 mpDescription->SetPosPixel( Point( nDescPos, aIDPos.Y() ) );
758 void RoadmapItem::Enable(bool _bEnable)
760 mpID->Enable(_bEnable);
761 mpDescription->Enable(_bEnable);
764 bool RoadmapItem::IsEnabled() const
766 return mpID->IsEnabled();
769 void RoadmapItem::ToggleBackgroundColor(const Color& _rGBColor)
771 if (_rGBColor == COL_TRANSPARENT)
772 mpID->SetControlBackground();
773 else
774 mpID->SetControlBackground( mpID->GetSettings().GetStyleSettings().GetHighlightColor() );
775 mpDescription->ToggleBackgroundColor(_rGBColor);
778 void RoadmapItem::ImplUpdatePosSize()
780 // calculate widths
781 tools::Long nIDWidth = mpID->GetTextWidth( mpID->GetText() );
782 tools::Long nMaxIDWidth = mpID->GetTextWidth( u"100."_ustr );
783 nIDWidth = ::std::min( nIDWidth, nMaxIDWidth );
785 // check how many space the description would need
786 Size aDescriptionSize = mpDescription->CalcMinimumSize( m_aItemPlayground.Width() - nIDWidth );
788 // position and size both controls
789 Size aIDSize( nIDWidth, aDescriptionSize.Height() );
790 mpID->SetSizePixel( aIDSize );
792 Point aIDPos = mpID->GetPosPixel();
793 mpDescription->SetPosPixel( Point( aIDPos.X() + nIDWidth, aIDPos.Y() ) );
794 mpDescription->SetSizePixel( aDescriptionSize );
797 void RoadmapItem::Update(ItemIndex RMIndex, const OUString& _rText)
799 // update description label
800 mpDescription->SetLabel( _rText );
802 // update the index in both controls, which triggers updating the geometry of both
803 ImplUpdateIndex( RMIndex );
806 void RoadmapItem::SetClickHdl(const Link<HyperLabel*,void>& rLink)
808 if ( mpDescription )
809 mpDescription->SetClickHdl( rLink);
812 IDLabel::IDLabel(vcl::Window* _pParent, WinBits _nWinStyle)
813 : FixedText(_pParent, _nWinStyle)
817 void IDLabel::ApplySettings(vcl::RenderContext& rRenderContext)
819 FixedText::ApplySettings(rRenderContext);
821 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
822 if (GetControlBackground() == COL_TRANSPARENT)
823 rRenderContext.SetTextColor(rStyleSettings.GetFieldTextColor());
824 else
825 rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
828 void IDLabel::DataChanged(const DataChangedEvent& rDCEvt)
830 FixedText::DataChanged( rDCEvt );
832 if ((( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
833 ( rDCEvt.GetType() == DataChangedEventType::DISPLAY )) &&
834 ( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ))
836 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
837 if (GetControlBackground() != COL_TRANSPARENT)
838 SetControlBackground(rStyleSettings.GetHighlightColor());
839 Invalidate();
843 } // namespace vcl
845 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */