1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: taskstat.cxx,v $
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"
36 #ifndef _TOOLS_LIST_HXX
37 #include <tools/list.hxx>
39 #include <tools/debug.hxx>
40 #include <tools/date.hxx>
41 #include <vcl/image.hxx>
42 #include <vcl/help.hxx>
43 #include <vcl/svapp.hxx>
44 #include <unotools/calendarwrapper.hxx>
46 #include <svtools/syslocale.hxx>
47 #include <taskbar.hxx>
49 // =======================================================================
51 #define TASKSTATUSBAR_CLOCXOFFX 3
52 #define TASKSTATUSBAR_IMAGEOFFX 1
54 // =======================================================================
56 struct ImplTaskSBFldItem
58 TaskStatusFieldItem maItem
;
63 DECLARE_LIST( ImplTaskSBItemList
, ImplTaskSBFldItem
* )
65 // =======================================================================
67 BOOL
ITaskStatusNotify::MouseButtonDown( USHORT
, const MouseEvent
& )
72 // -----------------------------------------------------------------------
74 BOOL
ITaskStatusNotify::MouseButtonUp( USHORT
, const MouseEvent
& )
79 // -----------------------------------------------------------------------
81 BOOL
ITaskStatusNotify::MouseMove( USHORT
, const MouseEvent
& )
86 // -----------------------------------------------------------------------
88 BOOL
ITaskStatusNotify::Command( USHORT
, const CommandEvent
& )
93 // -----------------------------------------------------------------------
95 BOOL
ITaskStatusNotify::UpdateHelp( USHORT
)
100 // =======================================================================
102 TaskStatusFieldItem::TaskStatusFieldItem()
108 // -----------------------------------------------------------------------
110 TaskStatusFieldItem::TaskStatusFieldItem( const TaskStatusFieldItem
& rItem
) :
111 mpNotify( rItem
.mpNotify
),
112 maImage( rItem
.maImage
),
113 maQuickHelpText( rItem
.maQuickHelpText
),
114 maHelpText( rItem
.maHelpText
),
115 mnFlags( rItem
.mnFlags
)
119 // -----------------------------------------------------------------------
121 TaskStatusFieldItem::TaskStatusFieldItem( ITaskStatusNotify
* pNotify
,
123 const XubString
& rQuickHelpText
,
124 const XubString
& rHelpText
,
128 maQuickHelpText( rQuickHelpText
),
129 maHelpText( rHelpText
),
134 // -----------------------------------------------------------------------
136 TaskStatusFieldItem::~TaskStatusFieldItem()
140 // -----------------------------------------------------------------------
142 const TaskStatusFieldItem
& TaskStatusFieldItem::operator=( const TaskStatusFieldItem
& rItem
)
144 mpNotify
= rItem
.mpNotify
;
145 maImage
= rItem
.maImage
;
146 maQuickHelpText
= rItem
.maQuickHelpText
;
147 maHelpText
= rItem
.maHelpText
;
148 mnFlags
= rItem
.mnFlags
;
152 // =======================================================================
154 TaskStatusBar::TaskStatusBar( Window
* pParent
, WinBits nWinStyle
) :
155 StatusBar( pParent
, nWinStyle
| WB_3DLOOK
),
158 mpFieldItemList
= NULL
;
159 mpNotifyTaskBar
= NULL
;
165 mbFlashItems
= FALSE
;
166 mbOutInterval
= FALSE
;
168 maTimer
.SetTimeoutHdl( LINK( this, TaskStatusBar
, ImplTimerHdl
) );
171 // -----------------------------------------------------------------------
173 TaskStatusBar::~TaskStatusBar()
175 if ( mpFieldItemList
)
177 ImplTaskSBFldItem
* pItem
= mpFieldItemList
->First();
181 pItem
= mpFieldItemList
->Next();
184 delete mpFieldItemList
;
188 // -----------------------------------------------------------------------
190 IMPL_LINK( TaskStatusBar
, ImplTimerHdl
, Timer
*, EMPTYARG
)
192 BOOL bUpdate
= ImplUpdateClock();
193 if ( ImplUpdateFlashItems() )
196 SetItemData( TASKSTATUSBAR_STATUSFIELDID
, NULL
);
201 // -----------------------------------------------------------------------
203 ImplTaskSBFldItem
* TaskStatusBar::ImplGetFieldItem( USHORT nItemId
) const
205 if ( !mpFieldItemList
)
208 ImplTaskSBFldItem
* pItem
= mpFieldItemList
->First();
211 if ( pItem
->mnId
== nItemId
)
214 pItem
= mpFieldItemList
->Next();
220 // -----------------------------------------------------------------------
222 ImplTaskSBFldItem
* TaskStatusBar::ImplGetFieldItem( const Point
& rPos
, BOOL
& rFieldRect
) const
224 if ( GetItemId( rPos
) == TASKSTATUSBAR_STATUSFIELDID
)
228 if ( mpFieldItemList
)
230 long nX
= rPos
.X()-GetItemRect( TASKSTATUSBAR_STATUSFIELDID
).Left();
231 ImplTaskSBFldItem
* pItem
= mpFieldItemList
->First();
234 if ( nX
< pItem
->mnOffX
+pItem
->maItem
.GetImage().GetSizePixel().Width() )
237 pItem
= mpFieldItemList
->Next();
247 // -----------------------------------------------------------------------
249 BOOL
TaskStatusBar::ImplUpdateClock()
251 if ( mnFieldFlags
& TASKSTATUSFIELD_CLOCK
)
254 maTimer
.SetTimeout( ((long)60000)-((aTime
.GetSec()*1000)+(aTime
.Get100Sec()*10)) );
255 if ( (aTime
.GetMin() != maTime
.GetMin()) ||
256 (aTime
.GetHour() != maTime
.GetHour()) )
259 maTimeText
= SvtSysLocale().GetLocaleData().getTime( aTime
, FALSE
, FALSE
);
267 // -----------------------------------------------------------------------
269 BOOL
TaskStatusBar::ImplUpdateFlashItems()
275 maTimer
.SetTimeout( 900 );
276 mbOutInterval
= FALSE
;
280 maTimer
.SetTimeout( 700 );
281 mbOutInterval
= TRUE
;
290 // -----------------------------------------------------------------------
292 void TaskStatusBar::ImplUpdateField( BOOL bItems
)
298 ImplTaskSBFldItem
* pItem
= mpFieldItemList
->First();
300 mbFlashItems
= FALSE
;
301 mbOutInterval
= FALSE
;
304 mnItemWidth
+= TASKSTATUSBAR_IMAGEOFFX
;
305 pItem
->mnOffX
= mnItemWidth
;
306 mnItemWidth
+= pItem
->maItem
.GetImage().GetSizePixel().Width();
307 if ( pItem
->maItem
.GetFlags() & TASKSTATUSFIELDITEM_FLASH
)
310 pItem
= mpFieldItemList
->Next();
315 if ( mnFieldFlags
& TASKSTATUSFIELD_CLOCK
)
317 XubString aStr
= SvtSysLocale().GetLocaleData().getTime( Time( 23, 59, 59 ), FALSE
, FALSE
);
318 mnClockWidth
= GetTextWidth( aStr
)+(TASKSTATUSBAR_CLOCXOFFX
*2);
324 long nNewWidth
= mnItemWidth
+mnClockWidth
;
325 if ( mnItemWidth
&& !mnClockWidth
)
326 nNewWidth
+= TASKSTATUSBAR_IMAGEOFFX
;
327 if ( nNewWidth
!= mnFieldWidth
)
329 RemoveItem( TASKSTATUSBAR_STATUSFIELDID
);
331 if ( mnItemWidth
|| mnClockWidth
)
333 mnFieldWidth
= nNewWidth
;
334 long nOffset
= GetItemOffset( TASKSTATUSBAR_STATUSFIELDID
);
335 USHORT nItemPos
= GetItemPos( TASKSTATUSBAR_STATUSFIELDID
);
336 InsertItem( TASKSTATUSBAR_STATUSFIELDID
, nNewWidth
, SIB_RIGHT
| SIB_IN
| SIB_USERDRAW
, nOffset
, nItemPos
);
341 if ( mpNotifyTaskBar
)
342 mpNotifyTaskBar
->Resize();
345 SetItemData( TASKSTATUSBAR_STATUSFIELDID
, NULL
);
347 if ( mbFlashItems
|| (mnFieldFlags
& TASKSTATUSFIELD_CLOCK
) )
350 mbOutInterval
= TRUE
;
351 ImplUpdateFlashItems();
356 // -----------------------------------------------------------------------
358 void TaskStatusBar::MouseButtonDown( const MouseEvent
& rMEvt
)
361 BOOL bBaseClass
= FALSE
;
362 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( rMEvt
.GetPosPixel(), bFieldRect
);
364 ITaskStatusNotify
* pNotify
= mpNotify
;
368 nItemId
= TASKSTATUSBAR_CLOCKID
;
372 pNotify
= pItem
->maItem
.GetNotifyObject();
373 nItemId
= pItem
->mnId
;
377 bBaseClass
= pNotify
->MouseButtonDown( nItemId
, rMEvt
);
380 StatusBar::MouseButtonDown( rMEvt
);
383 // -----------------------------------------------------------------------
385 void TaskStatusBar::MouseButtonUp( const MouseEvent
& rMEvt
)
388 BOOL bBaseClass
= FALSE
;
389 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( rMEvt
.GetPosPixel(), bFieldRect
);
391 ITaskStatusNotify
* pNotify
= mpNotify
;
395 nItemId
= TASKSTATUSBAR_CLOCKID
;
399 pNotify
= pItem
->maItem
.GetNotifyObject();
400 nItemId
= pItem
->mnId
;
404 bBaseClass
= pNotify
->MouseButtonUp( nItemId
, rMEvt
);
407 StatusBar::MouseButtonUp( rMEvt
);
410 // -----------------------------------------------------------------------
412 void TaskStatusBar::MouseMove( const MouseEvent
& rMEvt
)
415 BOOL bBaseClass
= FALSE
;
416 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( rMEvt
.GetPosPixel(), bFieldRect
);
418 ITaskStatusNotify
* pNotify
= mpNotify
;
422 nItemId
= TASKSTATUSBAR_CLOCKID
;
426 pNotify
= pItem
->maItem
.GetNotifyObject();
427 nItemId
= pItem
->mnId
;
431 bBaseClass
= pNotify
->MouseMove( nItemId
, rMEvt
);
434 StatusBar::MouseMove( rMEvt
);
437 // -----------------------------------------------------------------------
439 void TaskStatusBar::Command( const CommandEvent
& rCEvt
)
442 BOOL bBaseClass
= FALSE
;
443 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( rCEvt
.GetMousePosPixel(), bFieldRect
);
445 ITaskStatusNotify
* pNotify
= mpNotify
;
449 nItemId
= TASKSTATUSBAR_CLOCKID
;
453 pNotify
= pItem
->maItem
.GetNotifyObject();
454 nItemId
= pItem
->mnId
;
458 bBaseClass
= pNotify
->Command( nItemId
, rCEvt
);
461 StatusBar::Command( rCEvt
);
464 // -----------------------------------------------------------------------
466 void TaskStatusBar::RequestHelp( const HelpEvent
& rHEvt
)
469 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ), bFieldRect
);
472 ITaskStatusNotify
* pNotify
= mpNotify
;
477 pNotify
= pItem
->maItem
.GetNotifyObject();
478 nItemId
= pItem
->mnId
;
482 pNotify
->UpdateHelp( nItemId
);
484 if ( rHEvt
.GetMode() & (HELPMODE_BALLOON
| HELPMODE_QUICK
) )
486 Rectangle aItemRect
= GetItemRect( TASKSTATUSBAR_STATUSFIELDID
);
487 Point aPt
= OutputToScreenPixel( aItemRect
.TopLeft() );
488 aItemRect
.Left() = aPt
.X();
489 aItemRect
.Top() = aPt
.Y();
490 aPt
= OutputToScreenPixel( aItemRect
.BottomRight() );
491 aItemRect
.Right() = aPt
.X();
492 aItemRect
.Bottom() = aPt
.Y();
495 if ( rHEvt
.GetMode() & HELPMODE_BALLOON
)
497 XubString aStr
= pItem
->maItem
.GetHelpText();
499 aStr
= pItem
->maItem
.GetQuickHelpText();
500 Help::ShowBalloon( this, aItemRect
.Center(), aItemRect
, aStr
);
503 Help::ShowQuickHelp( this, aItemRect
, pItem
->maItem
.GetQuickHelpText() );
508 const LocaleDataWrapper
& rLDW
= aSL
.GetLocaleData();
509 CalendarWrapper
aCal( rLDW
.getServiceFactory());
510 aCal
.loadDefaultCalendar( rLDW
.getLoadedLocale());
511 XubString aStr
= rLDW
.getLongDate( Date(), aCal
);
512 if ( rHEvt
.GetMode() & HELPMODE_BALLOON
)
513 Help::ShowBalloon( this, aItemRect
.Center(), aItemRect
, aStr
);
515 Help::ShowQuickHelp( this, aItemRect
, aStr
);
519 else if ( rHEvt
.GetMode() & HELPMODE_EXTENDED
)
523 ULONG nHelpId
= pItem
->maItem
.GetHelpId();
526 // Wenn eine Hilfe existiert, dann ausloesen
527 Help
* pHelp
= Application::GetHelp();
529 pHelp
->Start( nHelpId
, this );
536 StatusBar::RequestHelp( rHEvt
);
539 // -----------------------------------------------------------------------
541 void TaskStatusBar::UserDraw( const UserDrawEvent
& rUDEvt
)
543 if ( rUDEvt
.GetItemId() == TASKSTATUSBAR_STATUSFIELDID
)
545 OutputDevice
* pDev
= rUDEvt
.GetDevice();
546 Rectangle aRect
= rUDEvt
.GetRect();
548 if ( mpFieldItemList
)
550 ImplTaskSBFldItem
* pItem
= mpFieldItemList
->First();
553 if ( !mbOutInterval
|| !(pItem
->maItem
.GetFlags() & TASKSTATUSFIELDITEM_FLASH
) )
555 const Image
& rImage
= pItem
->maItem
.GetImage();
556 Size aImgSize
= rImage
.GetSizePixel();
557 pDev
->DrawImage( Point( aRect
.Left()+pItem
->mnOffX
,
558 aRect
.Top()+((aRect
.GetHeight()-aImgSize
.Width())/2) ),
562 pItem
= mpFieldItemList
->Next();
566 if ( mnFieldFlags
& TASKSTATUSFIELD_CLOCK
)
568 long nX
= mnItemWidth
+TASKSTATUSBAR_CLOCXOFFX
;
569 Point aPos
= GetItemTextPos( TASKSTATUSBAR_STATUSFIELDID
);
570 aPos
.X() = aRect
.Left()+nX
;
571 pDev
->DrawText( aPos
, maTimeText
);
575 StatusBar::UserDraw( rUDEvt
);
578 // -----------------------------------------------------------------------
580 void TaskStatusBar::InsertStatusField( long, USHORT
,
583 mnFieldFlags
= nFlags
;
584 ImplUpdateField( FALSE
);
587 // -----------------------------------------------------------------------
589 void TaskStatusBar::SetFieldFlags( USHORT nFlags
)
591 if ( mnFieldFlags
!= nFlags
)
593 mnFieldFlags
= nFlags
;
594 ImplUpdateField( FALSE
);
598 // -----------------------------------------------------------------------
600 void TaskStatusBar::AddStatusFieldItem( USHORT nItemId
, const TaskStatusFieldItem
& rItem
,
603 DBG_ASSERT( nItemId
, "TaskStatusBar::AddStatusFieldItem() - Item is 0" );
604 DBG_ASSERT( !ImplGetFieldItem( nItemId
), "TaskStatusBar::AddStatusFieldItem() - Item-Id already exist" );
606 if ( !mpFieldItemList
)
607 mpFieldItemList
= new ImplTaskSBItemList
;
609 ImplTaskSBFldItem
* pItem
= new ImplTaskSBFldItem
;
610 pItem
->maItem
= rItem
;
611 pItem
->mnId
= nItemId
;
613 mpFieldItemList
->Insert( pItem
, (ULONG
)nPos
);
615 ImplUpdateField( TRUE
);
618 // -----------------------------------------------------------------------
620 void TaskStatusBar::ModifyStatusFieldItem( USHORT nItemId
, const TaskStatusFieldItem
& rItem
)
622 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( nItemId
);
625 BOOL bUpdate
= (pItem
->maItem
.GetImage() != rItem
.GetImage()) ||
626 (pItem
->maItem
.GetFlags() != rItem
.GetFlags());
627 pItem
->maItem
= rItem
;
629 ImplUpdateField( TRUE
);
633 // -----------------------------------------------------------------------
635 void TaskStatusBar::RemoveStatusFieldItem( USHORT nItemId
)
637 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( nItemId
);
640 mpFieldItemList
->Remove( pItem
);
642 ImplUpdateField( TRUE
);
646 // -----------------------------------------------------------------------
648 BOOL
TaskStatusBar::GetStatusFieldItem( USHORT nItemId
, TaskStatusFieldItem
& rItem
) const
650 ImplTaskSBFldItem
* pItem
= ImplGetFieldItem( nItemId
);
653 rItem
= pItem
->maItem
;