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: taskbar.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>
41 #ifndef _VCL_FLOATWIN_HXX
42 #include <vcl/floatwin.hxx>
45 #include <taskbar.hxx>
47 // =======================================================================
49 class ImplTaskBarFloat
: public FloatingWindow
55 ImplTaskBarFloat( TaskBar
* pTaskBar
);
58 // -----------------------------------------------------------------------
60 ImplTaskBarFloat::ImplTaskBarFloat( TaskBar
* pTaskBar
) :
61 FloatingWindow( pTaskBar
, 0 )
66 // =======================================================================
68 #define TASKBAR_BORDER 2
69 #define TASKBAR_OFFSIZE 3
70 #define TASKBAR_OFFX 2
71 #define TASKBAR_OFFY 1
72 #define TASKBAR_BUTTONOFF 5
73 #define TASKBAR_AUTOHIDE_HEIGHT 2
75 // =======================================================================
77 TaskBar::TaskBar( Window
* pParent
, WinBits nWinStyle
) :
78 Window( pParent
, WB_3DLOOK
)
86 mnWinBits
= nWinStyle
;
94 // -----------------------------------------------------------------------
101 delete mpTaskToolBox
;
106 // -----------------------------------------------------------------------
108 void TaskBar::ImplInitSettings()
110 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
113 if ( IsControlBackground() )
114 aColor
= GetControlBackground();
115 else if ( Window::GetStyle() & WB_3DLOOK
)
116 aColor
= rStyleSettings
.GetFaceColor();
118 aColor
= rStyleSettings
.GetWindowColor();
119 SetBackground( aColor
);
122 // -----------------------------------------------------------------------
124 void TaskBar::ImplNewHeight( long nNewHeight
)
126 long nOldHeight
= GetSizePixel().Height();
127 if ( nNewHeight
!= nOldHeight
)
129 long nY
= GetPosPixel().Y()-(nNewHeight
-nOldHeight
);
130 SetPosSizePixel( 0, nY
, 0, nNewHeight
,
131 WINDOW_POSSIZE_Y
| WINDOW_POSSIZE_HEIGHT
);
136 // -----------------------------------------------------------------------
138 void TaskBar::TaskResize()
140 maTaskResizeHdl
.Call( this );
143 // -----------------------------------------------------------------------
145 TaskButtonBar
* TaskBar::CreateButtonBar()
147 return new TaskButtonBar( this );
150 // -----------------------------------------------------------------------
152 TaskToolBox
* TaskBar::CreateTaskToolBox()
154 return new TaskToolBox( this );
157 // -----------------------------------------------------------------------
159 TaskStatusBar
* TaskBar::CreateTaskStatusBar()
161 return new TaskStatusBar( this );
164 // -----------------------------------------------------------------------
166 void TaskBar::MouseMove( const MouseEvent
& rMEvt
)
168 if ( mnWinBits
& WB_SIZEABLE
)
170 TaskToolBox
* pTempTaskToolBox
= GetTaskToolBox();
171 TaskStatusBar
* pTempStatusBar
= GetStatusBar();
173 if ( pTempTaskToolBox
&& pTempStatusBar
)
175 long nStatusX
= pTempStatusBar
->GetPosPixel().X()-TASKBAR_OFFSIZE
-2;
176 long nMouseX
= rMEvt
.GetPosPixel().X();
177 PointerStyle ePtrStyle
;
178 if ( (nMouseX
>= nStatusX
-1) && (nMouseX
<= nStatusX
+3) )
179 ePtrStyle
= POINTER_HSIZEBAR
;
181 ePtrStyle
= POINTER_ARROW
;
182 Pointer
aPtr( ePtrStyle
);
188 // -----------------------------------------------------------------------
190 void TaskBar::MouseButtonDown( const MouseEvent
& rMEvt
)
192 if ( rMEvt
.IsLeft() && (mnWinBits
& WB_SIZEABLE
) )
194 TaskToolBox
* pTempTaskToolBox
= GetTaskToolBox();
195 TaskStatusBar
* pTempStatusBar
= GetStatusBar();
197 if ( pTempTaskToolBox
&& pTempStatusBar
)
199 long nStatusX
= pTempStatusBar
->GetPosPixel().X()-TASKBAR_OFFSIZE
-2;
200 long nMouseX
= rMEvt
.GetPosPixel().X();
201 if ( (nMouseX
>= nStatusX
-1) && (nMouseX
<= nStatusX
+3) )
203 if ( rMEvt
.GetClicks() == 2 )
214 mnOldStatusWidth
= mnStatusWidth
;
215 mnMouseOff
= nMouseX
-nStatusX
;
222 // -----------------------------------------------------------------------
224 void TaskBar::Tracking( const TrackingEvent
& rTEvt
)
226 if ( rTEvt
.IsTrackingEnded() )
228 if ( rTEvt
.IsTrackingCanceled() )
230 mnStatusWidth
= mnOldStatusWidth
;
237 Size aSize
= GetOutputSizePixel();
239 long nMouseX
= rTEvt
.GetMouseEvent().GetPosPixel().X()-mnMouseOff
;
242 long nMaxX
= aSize
.Width()-TASKBAR_OFFX
-TASKBAR_OFFSIZE
-1;
243 if ( nMouseX
> nMaxX
)
245 mnStatusWidth
= aSize
.Width()-nMouseX
-TASKBAR_OFFX
-TASKBAR_OFFSIZE
;
251 // -----------------------------------------------------------------------
253 void TaskBar::Paint( const Rectangle
& rRect
)
255 if ( mnWinBits
& (WB_BORDER
| WB_SIZEABLE
) )
257 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
258 Size aSize
= GetOutputSizePixel();
261 if ( mnWinBits
& WB_BORDER
)
263 SetLineColor( rStyleSettings
.GetShadowColor() );
264 DrawLine( Point( 0, 0 ), Point( aSize
.Width()-1, 0 ) );
265 SetLineColor( rStyleSettings
.GetLightColor() );
266 DrawLine( Point( 0, 1 ), Point( aSize
.Width()-1, 1 ) );
270 if ( (mnWinBits
& WB_SIZEABLE
) )
272 //TaskButtonBar* pTempButtonBar = GetButtonBar();
273 TaskToolBox
* pTempTaskToolBox
= GetTaskToolBox();
274 TaskStatusBar
* pTempStatusBar
= GetStatusBar();
276 if ( pTempTaskToolBox
&& pTempStatusBar
)
278 long nStatusX
= pTempStatusBar
->GetPosPixel().X()-TASKBAR_OFFSIZE
-2;
281 SetLineColor( rStyleSettings
.GetShadowColor() );
282 DrawLine( Point( nStatusX
, nY
), Point( nStatusX
, aSize
.Height()-1 ) );
284 SetLineColor( rStyleSettings
.GetLightColor() );
285 DrawLine( Point( nStatusX
, nY
), Point( nStatusX
, aSize
.Height()-1 ) );
291 Window::Paint( rRect
);
294 // -----------------------------------------------------------------------
296 void TaskBar::Resize()
298 if ( !IsReallyShown() )
301 TaskButtonBar
* pTempButtonBar
= GetButtonBar();
302 TaskToolBox
* pTempTaskToolBox
= GetTaskToolBox();
303 TaskStatusBar
* pTempStatusBar
= GetStatusBar();
304 Point
aToolPos( TASKBAR_OFFX
, 0 );
305 Size aSize
= GetOutputSizePixel();
307 Size
aToolSize( aSize
.Width()-(TASKBAR_OFFX
*2), 0 );
308 long nOldStatusX
= -1;
309 long nNewStatusX
= -1;
310 long nTaskHeight
= aSize
.Height() - (TASKBAR_OFFY
*2);
312 if ( mnWinBits
& WB_BORDER
)
314 nTaskHeight
-= TASKBAR_BORDER
;
315 aToolPos
.Y() += TASKBAR_BORDER
;
318 if ( pTempButtonBar
)
321 BOOL bVisibleItems
= FALSE
;
322 while ( i
< pTempButtonBar
->GetItemCount() )
324 if ( pTempButtonBar
->IsItemVisible( pTempButtonBar
->GetItemId( i
) ) )
326 bVisibleItems
= TRUE
;
331 if ( mbStatusText
|| !bVisibleItems
)
332 pTempButtonBar
->Hide();
335 Size aButtonBarSize
= pTempButtonBar
->CalcWindowSizePixel();
336 if ( pTempButtonBar
->GetItemCount() )
337 nTaskHeight
= aButtonBarSize
.Height();
339 aButtonBarSize
.Height() = nTaskHeight
;
340 Point aTempPos
= aToolPos
;
341 aTempPos
.Y() += (aSize
.Height()-aButtonBarSize
.Height()-aTempPos
.Y())/2;
342 pTempButtonBar
->SetPosSizePixel( aTempPos
, aButtonBarSize
);
343 pTempButtonBar
->Show();
344 aToolPos
.X() += aButtonBarSize
.Width()+TASKBAR_BUTTONOFF
;
348 if ( pTempStatusBar
)
350 aStatusSize
= pTempStatusBar
->CalcWindowSizePixel();
352 aStatusSize
.Width() = mnStatusWidth
;
353 if ( !pTempTaskToolBox
|| mbStatusText
)
354 aStatusSize
.Width() = aSize
.Width();
355 long nMaxHeight
= aSize
.Height()-(TASKBAR_OFFY
*2);
356 if ( mnWinBits
& WB_BORDER
)
357 nMaxHeight
-= TASKBAR_BORDER
;
358 if ( nMaxHeight
+2 > aStatusSize
.Height() )
359 aStatusSize
.Height() = nMaxHeight
;
360 Point
aPos( aSize
.Width()-aStatusSize
.Width(), 0 );
361 if ( pTempTaskToolBox
&& (mnWinBits
& WB_SIZEABLE
) && !mbStatusText
)
363 long nMinToolWidth
= aToolPos
.X()+50;
364 if ( aPos
.X() < nMinToolWidth
)
366 aStatusSize
.Width() -= nMinToolWidth
-aPos
.X();
367 aPos
.X() = nMinToolWidth
;
372 aStatusSize
.Width() = aSize
.Width();
375 if ( mnWinBits
& WB_BORDER
)
376 aPos
.Y() += TASKBAR_BORDER
;
377 aPos
.Y() += (aSize
.Height()-aStatusSize
.Height()-aPos
.Y())/2;
378 if ( mnWinBits
& WB_SIZEABLE
)
380 if ( pTempTaskToolBox
)
382 nOldStatusX
= pTempStatusBar
->GetPosPixel().X()-TASKBAR_OFFSIZE
-2;
383 nNewStatusX
= aPos
.X()-TASKBAR_OFFSIZE
-2;
386 pTempStatusBar
->SetPosSizePixel( aPos
, aStatusSize
);
387 pTempStatusBar
->Show();
388 aToolSize
.Width() = aPos
.X()-aToolPos
.X()-TASKBAR_OFFX
;
389 if ( mnWinBits
& WB_SIZEABLE
)
390 aToolSize
.Width() -= (TASKBAR_OFFSIZE
*2)-2;
393 if ( pTempTaskToolBox
)
395 if ( aToolSize
.Width() <= 24 )
396 pTempTaskToolBox
->Hide();
399 aToolSize
.Height() = pTempTaskToolBox
->CalcWindowSizePixel().Height();
400 if ( pTempTaskToolBox
->GetItemCount() )
401 nTaskHeight
= aToolSize
.Height();
403 aToolSize
.Height() = nTaskHeight
;
404 aToolPos
.Y() += (aSize
.Height()-aToolSize
.Height()-aToolPos
.Y())/2;
405 pTempTaskToolBox
->SetPosSizePixel( aToolPos
, aToolSize
);
406 pTempTaskToolBox
->Show();
410 if ( nOldStatusX
!= nNewStatusX
)
412 if ( nOldStatusX
> 0 )
414 Rectangle
aRect( nOldStatusX
, 0, nOldStatusX
+2, aSize
.Height()-1 );
417 if ( nNewStatusX
> 0 )
419 Rectangle
aRect( nNewStatusX
, 0, nNewStatusX
+2, aSize
.Height()-1 );
425 // -----------------------------------------------------------------------
427 void TaskBar::StateChanged( StateChangedType nType
)
429 Window::StateChanged( nType
);
431 if ( nType
== STATE_CHANGE_INITSHOW
)
433 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
438 else if ( nType
== STATE_CHANGE_FORMAT
)
441 ImplNewHeight( CalcWindowSizePixel().Height() );
447 // -----------------------------------------------------------------------
449 void TaskBar::DataChanged( const DataChangedEvent
& rDCEvt
)
451 Window::DataChanged( rDCEvt
);
453 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
454 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
455 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
456 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
458 // Asyncronen StateChanged ausloesen, damit sich die
459 // TaskBar an die neuen Groessen der Child-Fenster
461 PostStateChanged( STATE_CHANGE_FORMAT
);
465 // -----------------------------------------------------------------------
467 void TaskBar::Format()
469 ImplNewHeight( CalcWindowSizePixel().Height() );
473 // -----------------------------------------------------------------------
475 void TaskBar::SetLines( USHORT nLines
)
480 // -----------------------------------------------------------------------
482 void TaskBar::EnableAutoHide( BOOL bAutoHide
)
484 mbAutoHide
= bAutoHide
;
488 ImplNewHeight( TASKBAR_AUTOHIDE_HEIGHT
);
492 ImplNewHeight( CalcWindowSizePixel().Height() );
496 // -----------------------------------------------------------------------
498 void TaskBar::ShowStatusText( const String
& rText
)
505 if ( mpStatusBar
->AreItemsVisible() )
508 mpStatusBar
->HideItems();
512 maOldText
= mpStatusBar
->GetText();
514 mpStatusBar
->SetText( rText
);
516 mpStatusBar
->Update();
519 mpStatusBar
->SetText( rText
);
523 // -----------------------------------------------------------------------
525 void TaskBar::HideStatusText()
527 if ( mbStatusText
&& mpStatusBar
)
529 mbStatusText
= FALSE
;
530 mpStatusBar
->SetText( maOldText
);
533 mpStatusBar
->ShowItems();
537 // -----------------------------------------------------------------------
539 Size
TaskBar::CalcWindowSizePixel() const
541 TaskButtonBar
* pTempButtonBar
= GetButtonBar();
542 TaskToolBox
* pTempTaskToolBox
= GetTaskToolBox();
543 TaskStatusBar
* pTempStatusBar
= GetStatusBar();
547 if ( pTempButtonBar
&& pTempButtonBar
->GetItemCount() )
548 aSize
.Height() = pTempButtonBar
->CalcWindowSizePixel().Height()+(TASKBAR_OFFY
*2);
549 if ( pTempTaskToolBox
&& pTempTaskToolBox
->GetItemCount() )
551 nTempHeight
= pTempTaskToolBox
->CalcWindowSizePixel().Height()+(TASKBAR_OFFY
*2);
552 if ( nTempHeight
> aSize
.Height() )
553 aSize
.Height() = nTempHeight
;
555 if ( pTempStatusBar
)
557 nTempHeight
= pTempStatusBar
->GetSizePixel().Height();
558 if ( nTempHeight
> aSize
.Height() )
559 aSize
.Height() = nTempHeight
;
562 if ( mnWinBits
& WB_BORDER
)
563 aSize
.Height() += TASKBAR_BORDER
;
568 // -----------------------------------------------------------------------
570 TaskButtonBar
* TaskBar::GetButtonBar() const
573 ((TaskBar
*)this)->mpButtonBar
= ((TaskBar
*)this)->CreateButtonBar();
577 // -----------------------------------------------------------------------
579 TaskToolBox
* TaskBar::GetTaskToolBox() const
581 if ( !mpTaskToolBox
)
582 ((TaskBar
*)this)->mpTaskToolBox
= ((TaskBar
*)this)->CreateTaskToolBox();
583 return mpTaskToolBox
;
586 // -----------------------------------------------------------------------
588 TaskStatusBar
* TaskBar::GetStatusBar() const
592 ((TaskBar
*)this)->mpStatusBar
= ((TaskBar
*)this)->CreateTaskStatusBar();
594 mpStatusBar
->mpNotifyTaskBar
= (TaskBar
*)this;