update dev300-m58
[ooovba.git] / svtools / source / control / taskbar.cxx
blob6c1729ffad3c4ca0d7235c6f5e97ddea4885fea7
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: taskbar.cxx,v $
10 * $Revision: 1.7 $
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>
41 #ifndef _VCL_FLOATWIN_HXX
42 #include <vcl/floatwin.hxx>
43 #endif
45 #include <taskbar.hxx>
47 // =======================================================================
49 class ImplTaskBarFloat : public FloatingWindow
51 public:
52 TaskBar* mpTaskBar;
54 public:
55 ImplTaskBarFloat( TaskBar* pTaskBar );
58 // -----------------------------------------------------------------------
60 ImplTaskBarFloat::ImplTaskBarFloat( TaskBar* pTaskBar ) :
61 FloatingWindow( pTaskBar, 0 )
63 mpTaskBar = pTaskBar;
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 )
80 mpButtonBar = NULL;
81 mpTaskToolBox = NULL;
82 mpStatusBar = NULL;
83 mnStatusWidth = 0;
84 mnOldStatusWidth = 0;
85 mnLines = 1;
86 mnWinBits = nWinStyle;
87 mbStatusText = FALSE;
88 mbShowItems = FALSE;
89 mbAutoHide = FALSE;
91 ImplInitSettings();
94 // -----------------------------------------------------------------------
96 TaskBar::~TaskBar()
98 if ( mpButtonBar )
99 delete mpButtonBar;
100 if ( mpTaskToolBox )
101 delete mpTaskToolBox;
102 if ( mpStatusBar )
103 delete mpStatusBar;
106 // -----------------------------------------------------------------------
108 void TaskBar::ImplInitSettings()
110 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
112 Color aColor;
113 if ( IsControlBackground() )
114 aColor = GetControlBackground();
115 else if ( Window::GetStyle() & WB_3DLOOK )
116 aColor = rStyleSettings.GetFaceColor();
117 else
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 );
132 TaskResize();
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;
180 else
181 ePtrStyle = POINTER_ARROW;
182 Pointer aPtr( ePtrStyle );
183 SetPointer( aPtr );
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 )
205 if ( mnStatusWidth )
207 mnStatusWidth = 0;
208 Resize();
211 else
213 StartTracking();
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;
231 Resize();
232 Update();
235 else
237 Size aSize = GetOutputSizePixel();
239 long nMouseX = rTEvt.GetMouseEvent().GetPosPixel().X()-mnMouseOff;
240 if ( nMouseX < 0 )
241 nMouseX = 0;
242 long nMaxX = aSize.Width()-TASKBAR_OFFX-TASKBAR_OFFSIZE-1;
243 if ( nMouseX > nMaxX )
244 nMouseX = nMaxX;
245 mnStatusWidth = aSize.Width()-nMouseX-TASKBAR_OFFX-TASKBAR_OFFSIZE;
246 Resize();
247 Update();
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();
259 long nY = 0;
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 ) );
267 nY += 2;
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;
279 if ( nStatusX > 0 )
281 SetLineColor( rStyleSettings.GetShadowColor() );
282 DrawLine( Point( nStatusX, nY ), Point( nStatusX, aSize.Height()-1 ) );
283 nStatusX++;
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() )
299 return;
301 TaskButtonBar* pTempButtonBar = GetButtonBar();
302 TaskToolBox* pTempTaskToolBox = GetTaskToolBox();
303 TaskStatusBar* pTempStatusBar = GetStatusBar();
304 Point aToolPos( TASKBAR_OFFX, 0 );
305 Size aSize = GetOutputSizePixel();
306 Size aStatusSize;
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 )
320 USHORT i = 0;
321 BOOL bVisibleItems = FALSE;
322 while ( i < pTempButtonBar->GetItemCount() )
324 if ( pTempButtonBar->IsItemVisible( pTempButtonBar->GetItemId( i ) ) )
326 bVisibleItems = TRUE;
327 break;
329 i++;
331 if ( mbStatusText || !bVisibleItems )
332 pTempButtonBar->Hide();
333 else
335 Size aButtonBarSize = pTempButtonBar->CalcWindowSizePixel();
336 if ( pTempButtonBar->GetItemCount() )
337 nTaskHeight = aButtonBarSize.Height();
338 else
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();
351 if ( mnStatusWidth )
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;
370 if ( aPos.X() < 0 )
372 aStatusSize.Width() = aSize.Width();
373 aPos.X() = 0;
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();
397 else
399 aToolSize.Height() = pTempTaskToolBox->CalcWindowSizePixel().Height();
400 if ( pTempTaskToolBox->GetItemCount() )
401 nTaskHeight = aToolSize.Height();
402 else
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 );
415 Invalidate( aRect );
417 if ( nNewStatusX > 0 )
419 Rectangle aRect( nNewStatusX, 0, nNewStatusX+2, aSize.Height()-1 );
420 Invalidate( aRect );
425 // -----------------------------------------------------------------------
427 void TaskBar::StateChanged( StateChangedType nType )
429 Window::StateChanged( nType );
431 if ( nType == STATE_CHANGE_INITSHOW )
432 Format();
433 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
435 ImplInitSettings();
436 Invalidate();
438 else if ( nType == STATE_CHANGE_FORMAT )
440 ImplInitSettings();
441 ImplNewHeight( CalcWindowSizePixel().Height() );
442 Format();
443 Invalidate();
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
460 // orientieren kann
461 PostStateChanged( STATE_CHANGE_FORMAT );
465 // -----------------------------------------------------------------------
467 void TaskBar::Format()
469 ImplNewHeight( CalcWindowSizePixel().Height() );
470 Resize();
473 // -----------------------------------------------------------------------
475 void TaskBar::SetLines( USHORT nLines )
477 mnLines = nLines;
480 // -----------------------------------------------------------------------
482 void TaskBar::EnableAutoHide( BOOL bAutoHide )
484 mbAutoHide = bAutoHide;
486 if ( mbAutoHide )
488 ImplNewHeight( TASKBAR_AUTOHIDE_HEIGHT );
490 else
492 ImplNewHeight( CalcWindowSizePixel().Height() );
496 // -----------------------------------------------------------------------
498 void TaskBar::ShowStatusText( const String& rText )
500 if ( mpStatusBar )
502 if ( !mbStatusText )
504 mbStatusText = TRUE;
505 if ( mpStatusBar->AreItemsVisible() )
507 mbShowItems = TRUE;
508 mpStatusBar->HideItems();
510 else
511 mbShowItems = TRUE;
512 maOldText = mpStatusBar->GetText();
513 Resize();
514 mpStatusBar->SetText( rText );
515 Update();
516 mpStatusBar->Update();
518 else
519 mpStatusBar->SetText( rText );
523 // -----------------------------------------------------------------------
525 void TaskBar::HideStatusText()
527 if ( mbStatusText && mpStatusBar )
529 mbStatusText = FALSE;
530 mpStatusBar->SetText( maOldText );
531 Resize();
532 if ( mbShowItems )
533 mpStatusBar->ShowItems();
537 // -----------------------------------------------------------------------
539 Size TaskBar::CalcWindowSizePixel() const
541 TaskButtonBar* pTempButtonBar = GetButtonBar();
542 TaskToolBox* pTempTaskToolBox = GetTaskToolBox();
543 TaskStatusBar* pTempStatusBar = GetStatusBar();
544 Size aSize;
545 long nTempHeight;
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;
565 return aSize;
568 // -----------------------------------------------------------------------
570 TaskButtonBar* TaskBar::GetButtonBar() const
572 if ( !mpButtonBar )
573 ((TaskBar*)this)->mpButtonBar = ((TaskBar*)this)->CreateButtonBar();
574 return mpButtonBar;
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
590 if ( !mpStatusBar )
592 ((TaskBar*)this)->mpStatusBar = ((TaskBar*)this)->CreateTaskStatusBar();
593 if ( mpStatusBar )
594 mpStatusBar->mpNotifyTaskBar = (TaskBar*)this;
596 return mpStatusBar;