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