merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / control / taskstat.cxx
blobc916b42c808dbb303fd8fe44bc870bb361427ed8
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: taskstat.cxx,v $
10 * $Revision: 1.10 $
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"
34 #define _TASKBAR_CXX
36 #ifndef _TOOLS_LIST_HXX
37 #include <tools/list.hxx>
38 #endif
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;
59 USHORT mnId;
60 long mnOffX;
63 DECLARE_LIST( ImplTaskSBItemList, ImplTaskSBFldItem* )
65 // =======================================================================
67 BOOL ITaskStatusNotify::MouseButtonDown( USHORT, const MouseEvent& )
69 return FALSE;
72 // -----------------------------------------------------------------------
74 BOOL ITaskStatusNotify::MouseButtonUp( USHORT, const MouseEvent& )
76 return FALSE;
79 // -----------------------------------------------------------------------
81 BOOL ITaskStatusNotify::MouseMove( USHORT, const MouseEvent& )
83 return FALSE;
86 // -----------------------------------------------------------------------
88 BOOL ITaskStatusNotify::Command( USHORT, const CommandEvent& )
90 return FALSE;
93 // -----------------------------------------------------------------------
95 BOOL ITaskStatusNotify::UpdateHelp( USHORT )
97 return FALSE;
100 // =======================================================================
102 TaskStatusFieldItem::TaskStatusFieldItem()
104 mpNotify = NULL;
105 mnFlags = 0;
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,
122 const Image& rImage,
123 const XubString& rQuickHelpText,
124 const XubString& rHelpText,
125 USHORT nFlags ) :
126 mpNotify( pNotify ),
127 maImage( rImage ),
128 maQuickHelpText( rQuickHelpText ),
129 maHelpText( rHelpText ),
130 mnFlags( nFlags )
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;
149 return *this;
152 // =======================================================================
154 TaskStatusBar::TaskStatusBar( Window* pParent, WinBits nWinStyle ) :
155 StatusBar( pParent, nWinStyle | WB_3DLOOK ),
156 maTime( 0, 0, 0 )
158 mpFieldItemList = NULL;
159 mpNotifyTaskBar = NULL;
160 mpNotify = NULL;
161 mnClockWidth = 0;
162 mnItemWidth = 0;
163 mnFieldWidth = 0;
164 mnFieldFlags = 0;
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();
178 while ( pItem )
180 delete pItem;
181 pItem = mpFieldItemList->Next();
184 delete mpFieldItemList;
188 // -----------------------------------------------------------------------
190 IMPL_LINK( TaskStatusBar, ImplTimerHdl, Timer*, EMPTYARG )
192 BOOL bUpdate = ImplUpdateClock();
193 if ( ImplUpdateFlashItems() )
194 bUpdate = TRUE;
195 if ( bUpdate )
196 SetItemData( TASKSTATUSBAR_STATUSFIELDID, NULL );
198 return 0;
201 // -----------------------------------------------------------------------
203 ImplTaskSBFldItem* TaskStatusBar::ImplGetFieldItem( USHORT nItemId ) const
205 if ( !mpFieldItemList )
206 return NULL;
208 ImplTaskSBFldItem* pItem = mpFieldItemList->First();
209 while ( pItem )
211 if ( pItem->mnId == nItemId )
212 return pItem;
214 pItem = mpFieldItemList->Next();
217 return NULL;
220 // -----------------------------------------------------------------------
222 ImplTaskSBFldItem* TaskStatusBar::ImplGetFieldItem( const Point& rPos, BOOL& rFieldRect ) const
224 if ( GetItemId( rPos ) == TASKSTATUSBAR_STATUSFIELDID )
226 rFieldRect = TRUE;
228 if ( mpFieldItemList )
230 long nX = rPos.X()-GetItemRect( TASKSTATUSBAR_STATUSFIELDID ).Left();
231 ImplTaskSBFldItem* pItem = mpFieldItemList->First();
232 while ( pItem )
234 if ( nX < pItem->mnOffX+pItem->maItem.GetImage().GetSizePixel().Width() )
235 return pItem;
237 pItem = mpFieldItemList->Next();
241 else
242 rFieldRect = FALSE;
244 return NULL;
247 // -----------------------------------------------------------------------
249 BOOL TaskStatusBar::ImplUpdateClock()
251 if ( mnFieldFlags & TASKSTATUSFIELD_CLOCK )
253 Time aTime;
254 maTimer.SetTimeout( ((long)60000)-((aTime.GetSec()*1000)+(aTime.Get100Sec()*10)) );
255 if ( (aTime.GetMin() != maTime.GetMin()) ||
256 (aTime.GetHour() != maTime.GetHour()) )
258 maTime = aTime;
259 maTimeText = SvtSysLocale().GetLocaleData().getTime( aTime, FALSE, FALSE );
260 return TRUE;
264 return FALSE;
267 // -----------------------------------------------------------------------
269 BOOL TaskStatusBar::ImplUpdateFlashItems()
271 if ( mbFlashItems )
273 if ( mbOutInterval )
275 maTimer.SetTimeout( 900 );
276 mbOutInterval = FALSE;
278 else
280 maTimer.SetTimeout( 700 );
281 mbOutInterval = TRUE;
284 return TRUE;
287 return FALSE;
290 // -----------------------------------------------------------------------
292 void TaskStatusBar::ImplUpdateField( BOOL bItems )
294 maTimer.Stop();
296 if ( bItems )
298 ImplTaskSBFldItem* pItem = mpFieldItemList->First();
299 mnItemWidth = 0;
300 mbFlashItems = FALSE;
301 mbOutInterval = FALSE;
302 while ( pItem )
304 mnItemWidth += TASKSTATUSBAR_IMAGEOFFX;
305 pItem->mnOffX = mnItemWidth;
306 mnItemWidth += pItem->maItem.GetImage().GetSizePixel().Width();
307 if ( pItem->maItem.GetFlags() & TASKSTATUSFIELDITEM_FLASH )
308 mbFlashItems = TRUE;
310 pItem = mpFieldItemList->Next();
313 else
315 if ( mnFieldFlags & TASKSTATUSFIELD_CLOCK )
317 XubString aStr = SvtSysLocale().GetLocaleData().getTime( Time( 23, 59, 59 ), FALSE, FALSE );
318 mnClockWidth = GetTextWidth( aStr )+(TASKSTATUSBAR_CLOCXOFFX*2);
320 else
321 mnClockWidth = 0;
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 );
338 else
339 mnFieldWidth = 0;
341 if ( mpNotifyTaskBar )
342 mpNotifyTaskBar->Resize();
344 else
345 SetItemData( TASKSTATUSBAR_STATUSFIELDID, NULL );
347 if ( mbFlashItems || (mnFieldFlags & TASKSTATUSFIELD_CLOCK) )
349 ImplUpdateClock();
350 mbOutInterval = TRUE;
351 ImplUpdateFlashItems();
352 maTimer.Start();
356 // -----------------------------------------------------------------------
358 void TaskStatusBar::MouseButtonDown( const MouseEvent& rMEvt )
360 BOOL bFieldRect;
361 BOOL bBaseClass = FALSE;
362 ImplTaskSBFldItem* pItem = ImplGetFieldItem( rMEvt.GetPosPixel(), bFieldRect );
364 ITaskStatusNotify* pNotify = mpNotify;
365 USHORT nItemId = 0;
367 if ( bFieldRect )
368 nItemId = TASKSTATUSBAR_CLOCKID;
370 if ( pItem )
372 pNotify = pItem->maItem.GetNotifyObject();
373 nItemId = pItem->mnId;
376 if ( pNotify )
377 bBaseClass = pNotify->MouseButtonDown( nItemId, rMEvt );
379 if ( bBaseClass )
380 StatusBar::MouseButtonDown( rMEvt );
383 // -----------------------------------------------------------------------
385 void TaskStatusBar::MouseButtonUp( const MouseEvent& rMEvt )
387 BOOL bFieldRect;
388 BOOL bBaseClass = FALSE;
389 ImplTaskSBFldItem* pItem = ImplGetFieldItem( rMEvt.GetPosPixel(), bFieldRect );
391 ITaskStatusNotify* pNotify = mpNotify;
392 USHORT nItemId = 0;
394 if ( bFieldRect )
395 nItemId = TASKSTATUSBAR_CLOCKID;
397 if ( pItem )
399 pNotify = pItem->maItem.GetNotifyObject();
400 nItemId = pItem->mnId;
403 if ( pNotify )
404 bBaseClass = pNotify->MouseButtonUp( nItemId, rMEvt );
406 if ( bBaseClass )
407 StatusBar::MouseButtonUp( rMEvt );
410 // -----------------------------------------------------------------------
412 void TaskStatusBar::MouseMove( const MouseEvent& rMEvt )
414 BOOL bFieldRect;
415 BOOL bBaseClass = FALSE;
416 ImplTaskSBFldItem* pItem = ImplGetFieldItem( rMEvt.GetPosPixel(), bFieldRect );
418 ITaskStatusNotify* pNotify = mpNotify;
419 USHORT nItemId = 0;
421 if ( bFieldRect )
422 nItemId = TASKSTATUSBAR_CLOCKID;
424 if ( pItem )
426 pNotify = pItem->maItem.GetNotifyObject();
427 nItemId = pItem->mnId;
430 if ( pNotify )
431 bBaseClass = pNotify->MouseMove( nItemId, rMEvt );
433 if ( bBaseClass )
434 StatusBar::MouseMove( rMEvt );
437 // -----------------------------------------------------------------------
439 void TaskStatusBar::Command( const CommandEvent& rCEvt )
441 BOOL bFieldRect;
442 BOOL bBaseClass = FALSE;
443 ImplTaskSBFldItem* pItem = ImplGetFieldItem( rCEvt.GetMousePosPixel(), bFieldRect );
445 ITaskStatusNotify* pNotify = mpNotify;
446 USHORT nItemId = 0;
448 if ( bFieldRect )
449 nItemId = TASKSTATUSBAR_CLOCKID;
451 if ( pItem )
453 pNotify = pItem->maItem.GetNotifyObject();
454 nItemId = pItem->mnId;
457 if ( pNotify )
458 bBaseClass = pNotify->Command( nItemId, rCEvt );
460 if ( bBaseClass )
461 StatusBar::Command( rCEvt );
464 // -----------------------------------------------------------------------
466 void TaskStatusBar::RequestHelp( const HelpEvent& rHEvt )
468 BOOL bFieldRect;
469 ImplTaskSBFldItem* pItem = ImplGetFieldItem( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ), bFieldRect );
470 if ( bFieldRect )
472 ITaskStatusNotify* pNotify = mpNotify;
473 USHORT nItemId = 0;
475 if ( pItem )
477 pNotify = pItem->maItem.GetNotifyObject();
478 nItemId = pItem->mnId;
481 if ( pNotify )
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();
493 if ( pItem )
495 if ( rHEvt.GetMode() & HELPMODE_BALLOON )
497 XubString aStr = pItem->maItem.GetHelpText();
498 if ( !aStr.Len() )
499 aStr = pItem->maItem.GetQuickHelpText();
500 Help::ShowBalloon( this, aItemRect.Center(), aItemRect, aStr );
502 else
503 Help::ShowQuickHelp( this, aItemRect, pItem->maItem.GetQuickHelpText() );
505 else
507 SvtSysLocale aSL;
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 );
514 else
515 Help::ShowQuickHelp( this, aItemRect, aStr );
517 return;
519 else if ( rHEvt.GetMode() & HELPMODE_EXTENDED )
521 if ( pItem )
523 ULONG nHelpId = pItem->maItem.GetHelpId();
524 if ( nHelpId )
526 // Wenn eine Hilfe existiert, dann ausloesen
527 Help* pHelp = Application::GetHelp();
528 if ( pHelp )
529 pHelp->Start( nHelpId, this );
530 return;
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();
551 while ( pItem )
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) ),
559 rImage );
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 );
574 else
575 StatusBar::UserDraw( rUDEvt );
578 // -----------------------------------------------------------------------
580 void TaskStatusBar::InsertStatusField( long, USHORT,
581 USHORT nFlags )
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,
601 USHORT nPos )
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;
612 pItem->mnOffX = 0;
613 mpFieldItemList->Insert( pItem, (ULONG)nPos );
615 ImplUpdateField( TRUE );
618 // -----------------------------------------------------------------------
620 void TaskStatusBar::ModifyStatusFieldItem( USHORT nItemId, const TaskStatusFieldItem& rItem )
622 ImplTaskSBFldItem* pItem = ImplGetFieldItem( nItemId );
623 if ( pItem )
625 BOOL bUpdate = (pItem->maItem.GetImage() != rItem.GetImage()) ||
626 (pItem->maItem.GetFlags() != rItem.GetFlags());
627 pItem->maItem = rItem;
628 if ( bUpdate )
629 ImplUpdateField( TRUE );
633 // -----------------------------------------------------------------------
635 void TaskStatusBar::RemoveStatusFieldItem( USHORT nItemId )
637 ImplTaskSBFldItem* pItem = ImplGetFieldItem( nItemId );
638 if ( pItem )
640 mpFieldItemList->Remove( pItem );
641 delete pItem;
642 ImplUpdateField( TRUE );
646 // -----------------------------------------------------------------------
648 BOOL TaskStatusBar::GetStatusFieldItem( USHORT nItemId, TaskStatusFieldItem& rItem ) const
650 ImplTaskSBFldItem* pItem = ImplGetFieldItem( nItemId );
651 if ( pItem )
653 rItem = pItem->maItem;
654 return TRUE;
657 return FALSE;