update dev300-m58
[ooovba.git] / svtools / source / control / roadmap.cxx
blobc68ad3ca1e62f10efdd8ca085c856d6a873cc98e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: roadmap.cxx,v $
10 * $Revision: 1.16.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <roadmap.hxx>
35 #ifndef _STRING_HXX
36 #define _STRING_HXX
37 #endif
39 #ifndef __SGI_STL_VECTOR
40 #include <vector>
41 #endif
43 #include <algorithm>
44 #include <vcl/bitmap.hxx>
45 #include <tools/color.hxx>
47 #ifndef _RTL_USTRING_HXX_
48 #include <rtl/OUString.hxx>
49 #endif
50 #include <memory>
52 #define RMENTRYPOINT_X 4
53 #define RMENTRYPOINT_Y 27
54 #define RMITEMDISTANCE_Y 6
55 #define RMINCOMPLETE -1
56 #define NREMOVERMITEM -1
57 #define NADDITEM 1
58 #define INCOMPLETELABEL ::String::CreateFromAscii("...") // TODO: Cast to String
60 //.........................................................................
61 namespace svt
63 //.........................................................................
65 typedef std::vector< ::rtl::OUString > S_Vector;
66 typedef std::vector< ORoadmapHyperLabel* > HL_Vector;
68 //=====================================================================
69 //= FontChanger
70 //=====================================================================
71 // class FontChanger
72 // {
73 // protected:
74 // OutputDevice* m_pDev;
76 // public:
77 // FontChanger( OutputDevice* _pDev, const Font& _rNewFont )
78 // :m_pDev( _pDev )
79 // {
80 // m_pDev->Push( PUSH_FONT );
81 // m_pDev->SetFont( _rNewFont );
82 // }
84 // ~FontChanger()
85 // {
86 // m_pDev->Pop( );
87 // }
88 // };
91 //=====================================================================
92 //= ColorChanger
93 //=====================================================================
94 class ColorChanger
96 protected:
97 OutputDevice* m_pDev;
99 public:
100 ColorChanger( OutputDevice* _pDev, const Color& _rNewLineColor, const Color& _rNewFillColor )
101 :m_pDev( _pDev )
103 m_pDev->Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
104 m_pDev->SetLineColor( _rNewLineColor );
105 m_pDev->SetFillColor( _rNewFillColor );
108 ~ColorChanger()
110 m_pDev->Pop();
115 //=====================================================================
116 //= RoadmapImpl
117 //=====================================================================
118 class RoadmapImpl : public RoadmapTypes
120 protected:
121 Link m_aSelectHdl;
122 BitmapEx m_aPicture;
123 HL_Vector m_aRoadmapSteps;
124 ItemId m_iCurItemID;
125 sal_Bool m_bInteractive;
126 sal_Bool m_bComplete;
128 public:
129 RoadmapImpl() :
130 m_bInteractive( sal_True ),
131 m_bComplete( sal_True ) {}
133 Size aHyperLabelPixelSize;
134 ORoadmapHyperLabel* InCompleteHyperLabel;
136 void addHyperLabel( ORoadmapHyperLabel* _rRoadmapStep ) { m_aRoadmapSteps.push_back(_rRoadmapStep); }
138 HL_Vector& getHyperLabels() { return m_aRoadmapSteps; }
139 const HL_Vector& getHyperLabels() const { return m_aRoadmapSteps; }
141 void insertHyperLabel( ItemIndex _Index, ORoadmapHyperLabel* _rRoadmapStep ) { m_aRoadmapSteps.insert( m_aRoadmapSteps.begin() + _Index, _rRoadmapStep ); }
143 ItemIndex getItemCount() const { return m_aRoadmapSteps.size();}
145 void setCurItemID( ItemId i ) {m_iCurItemID = i; }
146 ItemId getCurItemID() const { return m_iCurItemID; }
148 void setInteractive(const sal_Bool _bInteractive) {m_bInteractive = _bInteractive; }
149 sal_Bool isInteractive() const { return m_bInteractive; };
151 void setComplete(const sal_Bool _bComplete) {m_bComplete = _bComplete; }
152 sal_Bool isComplete() const { return m_bComplete; };
154 void setPicture( const BitmapEx& _rPic ) { m_aPicture = _rPic; }
155 const BitmapEx& getPicture( ) const { return m_aPicture; }
157 void setSelectHdl( const Link& _rHdl ) { m_aSelectHdl = _rHdl; }
158 const Link& getSelectHdl( ) const { return m_aSelectHdl; }
160 void removeHyperLabel( ItemIndex _Index )
162 if ( ( _Index > -1 ) && ( _Index < getItemCount() ) )
164 delete m_aRoadmapSteps[_Index];
165 m_aRoadmapSteps.erase( m_aRoadmapSteps.begin() + _Index);
171 //=====================================================================
172 //= Roadmap
173 //=====================================================================
174 //---------------------------------------------------------------------
175 ORoadmap::ORoadmap( Window* _pParent, const ResId& _rId ):Control( _pParent, _rId )
176 ,m_pImpl( new RoadmapImpl() )
178 implInit();
181 //---------------------------------------------------------------------
182 ORoadmap::ORoadmap( Window* _pParent, WinBits _nWinStyle )
183 :Control( _pParent, _nWinStyle )
184 , m_pImpl( new RoadmapImpl() )
187 implInit();
190 //---------------------------------------------------------------------
191 void ORoadmap::implInit()
193 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
194 Color aTextColor = rStyleSettings.GetFieldTextColor();
195 Font aFont = GetFont( );
196 aFont.SetColor( aTextColor );
197 aFont.SetWeight( WEIGHT_BOLD );
198 aFont.SetUnderline( UNDERLINE_SINGLE );
199 SetFont( aFont );
200 SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) );
201 m_pImpl->InCompleteHyperLabel = NULL;
202 m_pImpl->setCurItemID(-1 );
203 m_pImpl->setComplete( sal_True );
204 // TODO: if somebody sets a new font from outside (OutputDevice::SetFont), we would have to react
205 // on this with calculating a new bold font.
206 // Unfortunately, the OutputDevice does not offer a notify mechanism for a changed font.
207 // So settings the font from outside is simply a forbidded scenario at the moment
210 //---------------------------------------------------------------------
211 ORoadmap::~ORoadmap( )
213 HL_Vector pLocRoadmapItems = m_pImpl->getHyperLabels();
214 m_pImpl->getHyperLabels().clear();
215 for ( HL_Vector::iterator i = pLocRoadmapItems.begin(); i< pLocRoadmapItems.end(); i++)
217 delete *i;
219 if ( ! m_pImpl->isComplete() )
220 delete m_pImpl->InCompleteHyperLabel;
221 delete m_pImpl;
222 m_pImpl = NULL;
226 RoadmapTypes::ItemId ORoadmap::GetCurrentRoadmapItemID() const
228 return m_pImpl->getCurItemID();
232 void ORoadmap::InitializeHyperLabelSize()
234 Size aSize = GetSizePixel();
235 Size aLogicSize = PixelToLogic( aSize, MAP_APPFONT );
236 aLogicSize.Height() = LABELBASEMAPHEIGHT;
237 aLogicSize.Width() -= (2*RMENTRYPOINT_X);
238 m_pImpl->aHyperLabelPixelSize = LogicToPixel( aLogicSize, MAP_APPFONT );
239 EnableMapMode( sal_False );
243 ORoadmapHyperLabel* ORoadmap::GetPreviousHyperLabel( ItemIndex _Index)
245 ORoadmapHyperLabel* OldHyperLabel = NULL;
246 if (_Index > 0)
247 OldHyperLabel = m_pImpl->getHyperLabels().at( _Index - 1 );
248 return OldHyperLabel;
252 //---------------------------------------------------------------------
254 ORoadmapHyperLabel* ORoadmap::InsertHyperLabel( ItemIndex _Index, ::rtl::OUString _sLabel, ItemId _RMID, sal_Bool _bEnabled)
256 if (m_pImpl->getItemCount() == 0 )
257 InitializeHyperLabelSize();
258 ORoadmapHyperLabel* CurHyperLabel;
259 ORoadmapHyperLabel* OldHyperLabel = GetPreviousHyperLabel( _Index);
261 if (_RMID != RMINCOMPLETE )
263 CurHyperLabel = new ORoadmapHyperLabel(this, WB_WORDBREAK);
264 CurHyperLabel->SetInteractive( m_pImpl->isInteractive() );
265 m_pImpl->insertHyperLabel(_Index, CurHyperLabel );
267 else
269 CurHyperLabel = new ORoadmapHyperLabel(this);
270 CurHyperLabel->SetInteractive( sal_False );
272 CurHyperLabel->SetPosition( OldHyperLabel );
273 CurHyperLabel->SetLabelAndSize( _Index, _sLabel, m_pImpl->aHyperLabelPixelSize );
274 CurHyperLabel->SetClickHdl(LINK( this, ORoadmap, ImplClickHdl ) );
275 CurHyperLabel->SetID( _RMID );
276 CurHyperLabel->SetIndex( _Index );
277 if (!_bEnabled)
278 CurHyperLabel->Enable( _bEnabled );
279 return CurHyperLabel;
282 //---------------------------------------------------------------------
283 void ORoadmap::SetRoadmapBitmap( const BitmapEx& _rBmp, sal_Bool _bInvalidate )
285 m_pImpl->setPicture( _rBmp );
286 if ( _bInvalidate )
287 Invalidate( );
290 //---------------------------------------------------------------------
291 const BitmapEx& ORoadmap::GetRoadmapBitmap( ) const
293 return m_pImpl->getPicture( );
296 //---------------------------------------------------------------------
297 void ORoadmap::SetRoadmapInteractive( sal_Bool _bInteractive )
299 m_pImpl->setInteractive( _bInteractive );
300 ORoadmapHyperLabel* CurHyperLabel;
301 HL_Vector pLocRoadmapItems = m_pImpl->getHyperLabels();
302 for ( HL_Vector::iterator i = pLocRoadmapItems.begin(); i< pLocRoadmapItems.end(); i++)
304 CurHyperLabel = *i;
305 CurHyperLabel->SetInteractive( _bInteractive );
309 //---------------------------------------------------------------------
310 sal_Bool ORoadmap::IsRoadmapInteractive()
312 return m_pImpl->isInteractive();
315 //---------------------------------------------------------------------
316 void ORoadmap::SetRoadmapComplete( sal_Bool _bComplete )
318 sal_Bool OldbComplete = m_pImpl->isComplete();
319 m_pImpl->setComplete( _bComplete);
320 if (_bComplete)
322 if ( m_pImpl->InCompleteHyperLabel != NULL)
324 if (m_pImpl->getItemCount() > 0)
326 HL_Vector pLocRoadmapItems = m_pImpl->getHyperLabels();
327 pLocRoadmapItems.pop_back();
328 delete m_pImpl->InCompleteHyperLabel;
330 m_pImpl->InCompleteHyperLabel = NULL;
333 else if (OldbComplete)
334 m_pImpl->InCompleteHyperLabel = InsertHyperLabel( m_pImpl->getItemCount(), ::String::CreateFromAscii("..."), RMINCOMPLETE );
337 //---------------------------------------------------------------------
338 void ORoadmap::SetRoadmapLabel(ORoadmapHyperLabel* CurHyperLabel, sal_Int32 _nPrefix, String _sDescription)
340 const xub_StrLen n_Pos = _sDescription.Search( String::CreateFromAscii(".") );
341 if ( n_Pos != STRING_NOTFOUND )
343 const String sID = ::String::CreateFromInt32( _nPrefix );
344 _sDescription.Replace(0 , n_Pos, sID );
346 CurHyperLabel->SetLabelAndSize( _nPrefix, _sDescription, m_pImpl->aHyperLabelPixelSize );
349 //---------------------------------------------------------------------
350 void ORoadmap::UpdatefollowingHyperLabels( ItemIndex _Index, sal_Int16 )
352 if ( _Index < ( m_pImpl->getItemCount() ) )
354 Point aPos;
355 String sLabel;
356 HL_Vector pLocRoadmapItems = m_pImpl->getHyperLabels();
357 ORoadmapHyperLabel* CurHyperLabel = NULL;
358 ItemIndex n_CurPrefix = _Index + 1 ;
359 for ( HL_Vector::iterator i = pLocRoadmapItems.begin()+ _Index; i< pLocRoadmapItems.end(); i++)
361 CurHyperLabel = *i;
362 aPos = CurHyperLabel->GetLogicalPosition();
363 CurHyperLabel->SetIndex( n_CurPrefix - 1);
364 sLabel = CurHyperLabel->GetLabel();
365 SetRoadmapLabel(CurHyperLabel, n_CurPrefix, sLabel);
366 ORoadmapHyperLabel* OldHyperLabel = GetPreviousHyperLabel( n_CurPrefix-1);
367 CurHyperLabel->SetPosition( OldHyperLabel);
368 n_CurPrefix++;
371 if ( ! m_pImpl->isComplete() )
373 ORoadmapHyperLabel* OldHyperLabel = GetPreviousHyperLabel( m_pImpl->getItemCount());
374 m_pImpl->InCompleteHyperLabel->SetPosition( OldHyperLabel );
375 m_pImpl->InCompleteHyperLabel->SetLabelAndSize( m_pImpl->getItemCount(), ::String::CreateFromAscii("..."), m_pImpl->aHyperLabelPixelSize );
379 //---------------------------------------------------------------------
380 void ORoadmap::ReplaceRoadmapItem( ItemIndex _Index, ::rtl::OUString _RoadmapItem, ItemId _RMID, sal_Bool _bEnabled )
382 ORoadmapHyperLabel* CurHyperLabel = GetByIndex( _Index);
383 if ( CurHyperLabel != NULL )
385 CurHyperLabel->SetLabelAndSize( _Index, _RoadmapItem, m_pImpl->aHyperLabelPixelSize );
386 CurHyperLabel->SetID( _RMID );
387 CurHyperLabel->Enable( _bEnabled );
391 //---------------------------------------------------------------------
392 RoadmapTypes::ItemIndex ORoadmap::GetItemCount() const
394 return m_pImpl->getItemCount();
397 //---------------------------------------------------------------------
398 RoadmapTypes::ItemId ORoadmap::GetItemID( ItemIndex _nIndex ) const
400 const ORoadmapHyperLabel* pHyperLabel = GetByIndex( _nIndex );
401 if ( pHyperLabel )
402 return pHyperLabel->GetID();
403 return -1;
406 //---------------------------------------------------------------------
407 RoadmapTypes::ItemIndex ORoadmap::GetItemIndex( ItemId _nID ) const
409 ORoadmapHyperLabel* CurHyperLabel;
410 ItemId nLocID = 0;
411 HL_Vector &LocHyperLabels = m_pImpl->getHyperLabels();
412 ItemIndex nResult = 0;
413 for ( HL_Vector::iterator i = LocHyperLabels.begin(); i< LocHyperLabels.end(); i++)
415 CurHyperLabel = *i;
416 nLocID = CurHyperLabel->GetID();
417 if ( nLocID == _nID )
418 return nResult;
419 nResult++;
421 return -1;
424 //---------------------------------------------------------------------
425 void ORoadmap::InsertRoadmapItem( ItemIndex _Index, ::rtl::OUString _RoadmapItem, ItemId _nUniqueId, sal_Bool _bEnabled )
427 ORoadmapHyperLabel* CurHyperLabel;
428 CurHyperLabel = InsertHyperLabel(_Index, _RoadmapItem, _nUniqueId, _bEnabled);
429 // Todo: YPos is superfluous, if items are always appended
430 UpdatefollowingHyperLabels( _Index + 1);
433 //---------------------------------------------------------------------
434 void ORoadmap::DeleteRoadmapItem( ItemIndex _Index )
436 if ( m_pImpl->getItemCount() > 0 && ( _Index > -1) && ( _Index < m_pImpl->getItemCount() ) )
438 m_pImpl->removeHyperLabel( _Index );
439 UpdatefollowingHyperLabels( _Index, NREMOVERMITEM);
443 //---------------------------------------------------------------------
444 sal_Bool ORoadmap::IsRoadmapComplete( ) const
446 return m_pImpl->isComplete();
449 //---------------------------------------------------------------------
450 sal_Bool ORoadmap::IsRoadmapItemEnabled( ItemId _nItemId, ItemIndex _nStartIndex ) const
452 const ORoadmapHyperLabel* _pLabelItem = GetByID( _nItemId, _nStartIndex );
453 return _pLabelItem ? _pLabelItem->IsEnabled() : sal_False;
456 //---------------------------------------------------------------------
457 void ORoadmap::EnableRoadmapItem( ItemId _nItemId, sal_Bool _bEnable, ItemIndex _nStartIndex )
459 ORoadmapHyperLabel* CurHyperLabel = GetByID( _nItemId, _nStartIndex );
460 if ( CurHyperLabel != NULL )
461 CurHyperLabel->Enable( _bEnable );
464 //---------------------------------------------------------------------
465 void ORoadmap::ChangeRoadmapItemLabel( ItemId _nID, ::rtl::OUString _sLabel, ItemIndex _nStartIndex )
467 ORoadmapHyperLabel* CurHyperLabel = GetByID( _nID, _nStartIndex );
468 if ( CurHyperLabel != NULL )
470 CurHyperLabel->SetLabelAndSize( CurHyperLabel->GetIndex(), _sLabel, m_pImpl->aHyperLabelPixelSize );
471 HL_Vector pLocRoadmapItems = m_pImpl->getHyperLabels();
472 ItemIndex Index = _nStartIndex;
473 for ( HL_Vector::iterator i = pLocRoadmapItems.begin()+ Index; i< pLocRoadmapItems.end(); i++)
475 CurHyperLabel = *i;
476 ORoadmapHyperLabel* OldHyperLabel = GetPreviousHyperLabel( Index );
477 CurHyperLabel->SetPosition( OldHyperLabel);
478 Index++;
483 //---------------------------------------------------------------------
485 ::rtl::OUString ORoadmap::GetRoadmapItemLabel( ItemId _nID, ItemIndex _nStartIndex )
487 ORoadmapHyperLabel* CurHyperLabel = GetByID( _nID, _nStartIndex );
488 if ( CurHyperLabel != NULL )
489 return CurHyperLabel->GetLabel();
490 else
491 return ::rtl::OUString();
494 //---------------------------------------------------------------------
495 void ORoadmap::ChangeRoadmapItemID( ItemId _nID, ItemId _NewID, ItemIndex _nStartIndex )
497 ORoadmapHyperLabel* CurHyperLabel = GetByID( _nID, _nStartIndex );
498 if ( CurHyperLabel != NULL )
499 CurHyperLabel->SetID( _NewID );
502 //---------------------------------------------------------------------
503 ORoadmapHyperLabel* ORoadmap::GetByID( ItemId _nID, ItemIndex _nStartIndex)
505 ORoadmapHyperLabel* CurHyperLabel;
506 ItemId nLocID = 0;
507 HL_Vector &LocHyperLabels = m_pImpl->getHyperLabels();
508 for ( HL_Vector::iterator i = LocHyperLabels.begin()+ _nStartIndex; i< LocHyperLabels.end(); i++)
510 CurHyperLabel = *i;
511 nLocID = CurHyperLabel->GetID();
512 if ( nLocID == _nID )
513 return CurHyperLabel;
515 return NULL;
518 //---------------------------------------------------------------------
519 const ORoadmapHyperLabel* ORoadmap::GetByID( ItemId _nID, ItemIndex _nStartIndex ) const
521 return const_cast< ORoadmap* >( this )->GetByID( _nID, _nStartIndex );
524 //---------------------------------------------------------------------
525 ORoadmapHyperLabel* ORoadmap::GetByIndex( ItemIndex _nItemIndex)
527 HL_Vector &LocHyperLabels = m_pImpl->getHyperLabels();
528 if ((_nItemIndex > -1) && (_nItemIndex < m_pImpl->getItemCount( ) ) )
530 ORoadmapHyperLabel* CurHyperLabel = LocHyperLabels.at(_nItemIndex); // Vectors are one-based
531 return CurHyperLabel;
533 return NULL;
536 //---------------------------------------------------------------------
537 const ORoadmapHyperLabel* ORoadmap::GetByIndex( ItemIndex _nItemIndex ) const
539 return const_cast< ORoadmap* >( this )->GetByIndex( _nItemIndex );
542 //---------------------------------------------------------------------
543 RoadmapTypes::ItemId ORoadmap::GetNextAvailableItemId( ItemIndex _nNewIndex )
545 ORoadmapHyperLabel* CurHyperLabel;
547 ItemIndex searchIndex = ++_nNewIndex;
548 while ( searchIndex < m_pImpl->getItemCount() )
550 CurHyperLabel = GetByIndex( searchIndex );
551 if ( CurHyperLabel->IsEnabled() )
552 return CurHyperLabel->GetID( );
554 ++searchIndex;
556 return -1;
559 //---------------------------------------------------------------------
560 RoadmapTypes::ItemId ORoadmap::GetPreviousAvailableItemId( ItemIndex _nNewIndex )
562 ORoadmapHyperLabel* CurHyperLabel;
563 ItemIndex searchIndex = --_nNewIndex;
564 while ( searchIndex > -1 )
566 CurHyperLabel = GetByIndex( searchIndex );
567 if ( CurHyperLabel->IsEnabled() )
568 return CurHyperLabel->GetID( );
570 searchIndex--;
572 return -1;
575 //---------------------------------------------------------------------
576 void ORoadmap::DeselectOldRoadmapItems()
578 HL_Vector pLocRoadmapItems = m_pImpl->getHyperLabels();
579 ORoadmapHyperLabel* CurHyperLabel = NULL;
580 for ( HL_Vector::iterator i = pLocRoadmapItems.begin(); i< pLocRoadmapItems.end(); i++)
582 CurHyperLabel = *i;
583 CurHyperLabel->ToggleBackgroundColor( COL_TRANSPARENT );
587 //---------------------------------------------------------------------
588 void ORoadmap::SetItemSelectHdl( const Link& _rHdl )
590 m_pImpl->setSelectHdl( _rHdl );
593 //---------------------------------------------------------------------
594 Link ORoadmap::GetItemSelectHdl( ) const
596 return m_pImpl->getSelectHdl();
599 //---------------------------------------------------------------------
600 void ORoadmap::Select()
602 GetItemSelectHdl().Call( this );
603 CallEventListeners( VCLEVENT_ROADMAP_ITEMSELECTED );
606 //---------------------------------------------------------------------
607 void ORoadmap::GetFocus()
609 ORoadmapHyperLabel* pCurHyperLabel = GetByID( GetCurrentRoadmapItemID() );
610 if ( pCurHyperLabel != NULL )
611 pCurHyperLabel->GrabFocus();
614 //---------------------------------------------------------------------
615 sal_Bool ORoadmap::SelectRoadmapItemByID( ItemId _nNewID )
617 DeselectOldRoadmapItems();
618 ORoadmapHyperLabel* CurHyperLabel = GetByID( _nNewID );
619 if (CurHyperLabel != NULL)
621 if (CurHyperLabel->IsEnabled())
623 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
624 CurHyperLabel->ToggleBackgroundColor( rStyleSettings.GetHighlightColor() ); //HighlightColor
626 CurHyperLabel->GrabFocus();
627 m_pImpl->setCurItemID(_nNewID);
629 Select();
630 return sal_True;
633 return sal_False;
636 //---------------------------------------------------------------------
637 void ORoadmap::Paint( const Rectangle& _rRect )
639 Control::Paint( _rRect );
642 // draw the bitmap
643 if ( !!m_pImpl->getPicture() )
645 Size aBitmapSize = m_pImpl->getPicture().GetSizePixel();
646 Size aMySize = GetOutputSizePixel();
648 Point aBitmapPos( aMySize.Width() - aBitmapSize.Width(), aMySize.Height() - aBitmapSize.Height() );
650 // draw it
651 DrawBitmapEx( aBitmapPos, m_pImpl->getPicture() );
654 //.................................................................
655 // draw the headline
656 DrawHeadline();
659 //---------------------------------------------------------------------
660 void ORoadmap::DrawHeadline()
662 Point aTextPos = LogicToPixel( Point( RMENTRYPOINT_X, 8 ), MAP_APPFONT );
664 Size aOutputSize( GetOutputSizePixel() );
666 // draw it
667 DrawText( Rectangle( aTextPos, aOutputSize ), GetText(), TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
668 DrawTextLine( aTextPos, aOutputSize.Width(), STRIKEOUT_NONE, UNDERLINE_SINGLE, UNDERLINE_NONE, sal_False );
669 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
670 SetLineColor( rStyleSettings.GetFieldTextColor());
671 SetTextColor(rStyleSettings.GetFieldTextColor());
674 //---------------------------------------------------------------------
675 ORoadmapHyperLabel* ORoadmap::GetByPointer(Window* pWindow)
677 ORoadmapHyperLabel* CurHyperLabel;
678 HL_Vector &LocHyperLabels = m_pImpl->getHyperLabels();
679 for ( HL_Vector::iterator i = LocHyperLabels.begin(); i< LocHyperLabels.end(); i++)
681 CurHyperLabel = *i;
682 if ( (CurHyperLabel->GetIDLabel() == pWindow) || (CurHyperLabel->GetDescriptionHyperLabel() == pWindow) )
683 return CurHyperLabel;
685 return NULL;
688 //---------------------------------------------------------------------
689 long ORoadmap::PreNotify( NotifyEvent& _rNEvt )
691 // capture KeyEvents for taskpane cycling
692 if ( _rNEvt.GetType() == EVENT_KEYINPUT )
694 Window* pWindow = _rNEvt.GetWindow();
695 ORoadmapHyperLabel* CurHyperLabel = GetByPointer( pWindow );
696 if ( CurHyperLabel != NULL )
698 sal_Int16 nKeyCode = _rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
699 switch( nKeyCode )
701 case KEY_UP:
702 { // Note: Performancewhise this is not optimal, because we search for an ID in the labels
703 // and afterwards we search again for a label with the appropriate ID ->
704 // unnecessarily we search twice!!!
705 ItemId nPrevItemID = GetPreviousAvailableItemId( CurHyperLabel->GetIndex() );
706 if ( nPrevItemID != -1 )
707 return SelectRoadmapItemByID( nPrevItemID );
709 break;
710 case KEY_DOWN:
712 ItemId nNextItemID = GetNextAvailableItemId( CurHyperLabel->GetIndex() );
713 if ( nNextItemID != -1 )
714 return SelectRoadmapItemByID( nNextItemID );
716 break;
717 case KEY_SPACE:
718 return SelectRoadmapItemByID( CurHyperLabel->GetID() );
722 return Window::PreNotify( _rNEvt );
725 //---------------------------------------------------------------------
726 IMPL_LINK(ORoadmap, ImplClickHdl, HyperLabel*, _CurHyperLabel)
728 return SelectRoadmapItemByID( _CurHyperLabel->GetID() );
733 void ORoadmap::DataChanged( const DataChangedEvent& rDCEvt )
735 if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
736 ( rDCEvt.GetType() == DATACHANGED_DISPLAY )) &&
737 ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
739 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
740 SetBackground( Wallpaper( rStyleSettings.GetFieldColor() ) );
741 Color aTextColor = rStyleSettings.GetFieldTextColor();
742 Font aFont = GetFont();
743 aFont.SetColor( aTextColor );
744 SetFont( aFont );
745 RoadmapTypes::ItemId curItemID = GetCurrentRoadmapItemID();
746 ORoadmapHyperLabel* pLabelItem = GetByID( curItemID );
747 pLabelItem->ToggleBackgroundColor(rStyleSettings.GetHighlightColor());
748 Invalidate();
753 ORoadmapHyperLabel::ORoadmapHyperLabel( Window* _pParent, const ResId& )
755 mpIDLabel = new ORoadmapIDHyperLabel(_pParent, WB_WORDBREAK);
756 mpDescHyperLabel = new HyperLabel(_pParent, WB_TABSTOP | WB_WORDBREAK);
760 ORoadmapHyperLabel::ORoadmapHyperLabel( Window* _pParent, WinBits )
762 mpIDLabel = new ORoadmapIDHyperLabel(_pParent, WB_WORDBREAK);
763 mpIDLabel->SetTextColor( mpIDLabel->GetSettings().GetStyleSettings().GetFieldTextColor( ) );
764 mpDescHyperLabel = new HyperLabel(_pParent, WB_TABSTOP | WB_WORDBREAK);
767 //---------------------------------------------------------------------
768 void ORoadmapHyperLabel::GrabFocus()
770 if ( mpDescHyperLabel )
771 mpDescHyperLabel->GrabFocus();
775 void ORoadmapHyperLabel::SetInteractive( sal_Bool _bInteractive )
777 if ( mpDescHyperLabel )
778 mpDescHyperLabel->SetInteractive(_bInteractive);
781 void ORoadmapHyperLabel::SetID( sal_Int16 _ID )
783 if ( mpDescHyperLabel )
784 mpDescHyperLabel->SetID(_ID);
787 sal_Int16 ORoadmapHyperLabel::GetID() const
789 return mpDescHyperLabel ? mpDescHyperLabel->GetID() : sal_Int16(-1);
792 void ORoadmapHyperLabel::SetIndex( sal_Int32 _Index )
794 if ( mpDescHyperLabel )
795 mpDescHyperLabel->SetIndex(_Index);
799 sal_Int32 ORoadmapHyperLabel::GetIndex() const
801 return mpDescHyperLabel ? mpDescHyperLabel->GetIndex() : sal_Int32(-1);
805 void ORoadmapHyperLabel::SetLabel( ::rtl::OUString _rText )
807 if ( mpDescHyperLabel )
808 mpDescHyperLabel->SetText(_rText);
812 ::rtl::OUString ORoadmapHyperLabel::GetLabel( )
814 return mpDescHyperLabel ? mpDescHyperLabel->GetText() : String();
818 void ORoadmapHyperLabel::SetPosition(ORoadmapHyperLabel* OldHyperLabel)
820 Point aNewLogicalPoint;
821 Point aNewPoint;
822 if (OldHyperLabel == NULL)
824 aNewLogicalPoint = Point( RMENTRYPOINT_X, RMENTRYPOINT_Y);
825 aNewPoint = mpIDLabel->LogicToPixel(aNewLogicalPoint, MAP_APPFONT );
827 else
829 Size aOldSize = OldHyperLabel->GetDescriptionHyperLabel()->GetSizePixel();
830 Point aOldLogicalPoint = OldHyperLabel->GetLogicalPosition();
831 aNewLogicalPoint = Point(aOldLogicalPoint.X(), (aOldLogicalPoint.Y() + RMITEMDISTANCE_Y));
832 aNewPoint = mpIDLabel->LogicToPixel(aNewLogicalPoint, MAP_APPFONT );
833 aNewPoint = Point(aNewPoint.X(),aNewPoint.Y() + aOldSize.Height());
835 mpIDLabel->SetPosPixel( aNewPoint );
836 sal_Int32 xDescPos = aNewPoint.X() + mpIDLabel->GetSizePixel().Width();
837 mpDescHyperLabel->SetPosPixel( Point(xDescPos, aNewPoint.Y()) );
841 void ORoadmapHyperLabel::SetZOrder( ORoadmapHyperLabel* pRefRoadmapHyperLabel, USHORT nFlags )
843 if (pRefRoadmapHyperLabel == NULL)
844 mpDescHyperLabel->SetZOrder( NULL, nFlags); //WINDOW_ZORDER_FIRST );
845 else
846 mpDescHyperLabel->SetZOrder( pRefRoadmapHyperLabel->mpDescHyperLabel, nFlags); //, WINDOW_ZORDER_BEHIND );
850 void ORoadmapHyperLabel::Enable( BOOL _bEnable)
852 mpIDLabel->Enable(_bEnable);
853 mpDescHyperLabel->Enable(_bEnable);
856 BOOL ORoadmapHyperLabel::IsEnabled() const
858 return mpIDLabel->IsEnabled();
861 // void ORoadmapHyperLabel::GrabFocus()
862 // {
863 // mpDescHyperLabel->GrabFocus();
865 // }
867 void ORoadmapHyperLabel::ToggleBackgroundColor( const Color& _rGBColor )
869 if (_rGBColor == COL_TRANSPARENT)
871 mpIDLabel->SetTextColor( mpIDLabel->GetSettings().GetStyleSettings().GetFieldTextColor( ) );
872 mpIDLabel->SetControlBackground( COL_TRANSPARENT );
874 else
876 mpIDLabel->SetControlBackground( mpIDLabel->GetSettings().GetStyleSettings().GetHighlightColor() );
877 mpIDLabel->SetTextColor( mpIDLabel->GetSettings().GetStyleSettings().GetHighlightTextColor( ) );
879 mpDescHyperLabel->ToggleBackgroundColor(_rGBColor);
883 Point ORoadmapHyperLabel::GetLogicalPosition()
885 Point aPoint = mpIDLabel->GetPosPixel( );
886 Size aSize = Size(aPoint.X(), aPoint.Y());
887 aSize = mpIDLabel->PixelToLogic( aSize, MAP_APPFONT );
888 aPoint = Point(aSize.Width(), aSize.Height());
889 return aPoint;
893 void ORoadmapHyperLabel::SetLabelAndSize( ItemIndex _RMIndex, ::rtl::OUString _rText, const Size& _rNewSize)
895 Size rIDSize = _rNewSize;
896 ::rtl::OUString aStr = ::rtl::OUString::valueOf( (sal_Int32)( _RMIndex + 1 ) ) + ::rtl::OUString::createFromAscii( "." );
897 rIDSize.Width() = (sal_Int32) mpIDLabel->GetTextWidth( aStr );
898 long nMaxWidth = mpIDLabel->GetTextWidth( ::rtl::OUString::createFromAscii("100.") );
899 rIDSize.Width() = ::std::min( rIDSize.getWidth(),nMaxWidth );
900 mpIDLabel->SetSizePixel(mpIDLabel->LogicToPixel( rIDSize));
901 mpIDLabel->SetText( aStr);
902 mpIDLabel->Show();
903 Size rDescSize = _rNewSize;
904 rDescSize.Width() -= rIDSize.Width();
905 sal_Int32 xDescPos = mpIDLabel->GetPosPixel().X() + mpIDLabel->GetSizePixel().Width();
906 sal_Int32 yDescPos = mpIDLabel->GetPosPixel().Y();
907 Point aPoint = Point(xDescPos, yDescPos);
908 mpDescHyperLabel->SetPosPixel( aPoint );
909 mpDescHyperLabel->SetLabelAndSize(_rText, rDescSize);
910 mpIDLabel->SetSizePixel( Size( mpIDLabel->GetSizePixel().Width(), mpDescHyperLabel->GetSizePixel().Height() ) );
913 ORoadmapHyperLabel::~ORoadmapHyperLabel( )
916 ::std::auto_ptr<Control> aTemp(mpIDLabel);
917 mpIDLabel = NULL;
920 ::std::auto_ptr<Control> aTemp(mpDescHyperLabel);
921 mpDescHyperLabel = NULL;
926 void ORoadmapHyperLabel::SetClickHdl( const Link& rLink )
928 if ( mpDescHyperLabel )
929 mpDescHyperLabel->SetClickHdl( rLink);
932 const Link& ORoadmapHyperLabel::GetClickHdl( ) const
934 return mpDescHyperLabel->GetClickHdl();
938 ORoadmapIDHyperLabel::ORoadmapIDHyperLabel( Window* _pParent, const ResId& _rId )
939 :FixedText( _pParent, _rId )
943 ORoadmapIDHyperLabel::ORoadmapIDHyperLabel( Window* _pParent, WinBits _nWinStyle )
944 :FixedText( _pParent, _nWinStyle )
950 ORoadmapIDHyperLabel::~ORoadmapIDHyperLabel( )
955 void ORoadmapIDHyperLabel::DataChanged( const DataChangedEvent& rDCEvt )
957 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
958 FixedText::DataChanged( rDCEvt );
959 if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
960 ( rDCEvt.GetType() == DATACHANGED_DISPLAY )) &&
961 ( rDCEvt.GetFlags() & SETTINGS_STYLE ))
963 const Color& rGBColor = GetControlBackground();
964 if (rGBColor == COL_TRANSPARENT)
965 SetTextColor( rStyleSettings.GetFieldTextColor( ) );
966 else
968 SetControlBackground(rStyleSettings.GetHighlightColor());
969 SetTextColor( rStyleSettings.GetHighlightTextColor( ) );
971 Invalidate();
978 //.........................................................................
979 } // namespace svt
980 //.........................................................................