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: taskbox.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 <vcl/image.hxx>
41 #include <vcl/help.hxx>
43 #include <taskbar.hxx>
45 // =======================================================================
47 #define TASKBOX_TASKOFF 3
49 // =======================================================================
57 DECLARE_LIST( ImplTaskItemList
, ImplTaskItem
* )
59 // =======================================================================
61 TaskToolBox::TaskToolBox( Window
* pParent
, WinBits nWinStyle
) :
62 ToolBox( pParent
, nWinStyle
| WB_SCROLL
| WB_3DLOOK
)
64 mpItemList
= new ImplTaskItemList
;
68 mnSmallItem
= TOOLBOX_ITEM_NOTFOUND
;
69 mbMinActivate
= FALSE
;
71 SetAlign( WINDOWALIGN_BOTTOM
);
72 SetButtonType( BUTTON_SYMBOLTEXT
);
75 // -----------------------------------------------------------------------
77 TaskToolBox::~TaskToolBox()
79 ImplTaskItem
* pItem
= mpItemList
->First();
83 pItem
= mpItemList
->Next();
89 // -----------------------------------------------------------------------
91 void TaskToolBox::ActivateTaskItem( USHORT nItemId
, BOOL bMinActivate
)
95 if ( nItemId
!= mnActiveItemId
)
98 CheckItem( mnActiveItemId
, FALSE
);
100 mnActiveItemId
= nItemId
;
107 mbMinActivate
= TRUE
;
110 mnTaskItem
= nItemId
-1;
113 mbMinActivate
= FALSE
;
117 // -----------------------------------------------------------------------
119 void TaskToolBox::ActivateTask()
121 maActivateTaskHdl
.Call( this );
124 // -----------------------------------------------------------------------
126 void TaskToolBox::ContextMenu()
128 maContextMenuHdl
.Call( this );
131 // -----------------------------------------------------------------------
133 void TaskToolBox::MouseButtonDown( const MouseEvent
& rMEvt
)
135 if ( !rMEvt
.IsRight() )
136 ToolBox::MouseButtonDown( rMEvt
);
139 // -----------------------------------------------------------------------
141 void TaskToolBox::Resize()
143 mnOldItemCount
= mpItemList
->Count();
144 mnUpdatePos
= (USHORT
)mnOldItemCount
;
145 mnUpdateNewPos
= TOOLBOX_ITEM_NOTFOUND
;
146 ImplFormatTaskToolBox();
150 // -----------------------------------------------------------------------
152 void TaskToolBox::Command( const CommandEvent
& rCEvt
)
154 if ( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
)
156 USHORT nItemId
= GetItemId( rCEvt
.GetMousePosPixel() );
157 // Dies machen wir nicht mehr, da es von zu vielen als stoerend empfunden wurde
158 // ActivateTaskItem( nItemId );
159 mnTaskItem
= nItemId
-1;
161 maContextMenuPos
= rCEvt
.GetMousePosPixel();
163 maContextMenuPos
= Point();
167 ToolBox::Command( rCEvt
);
170 // -----------------------------------------------------------------------
172 void TaskToolBox::RequestHelp( const HelpEvent
& rHEvt
)
174 if ( rHEvt
.GetMode() & (HELPMODE_BALLOON
| HELPMODE_QUICK
) )
176 USHORT nItemId
= GetItemId( ScreenToOutputPixel( rHEvt
.GetMousePosPixel() ) );
180 ImplTaskItem
* pItem
= mpItemList
->GetObject( nItemId
-1 );
183 if ( pItem
->maText
!= GetItemText( nItemId
) )
185 Rectangle aItemRect
= GetItemRect( nItemId
);
186 if ( rHEvt
.GetMode() & HELPMODE_QUICK
)
187 Help::ShowQuickHelp( this, aItemRect
, pItem
->maText
);
189 Help::ShowBalloon( this, aItemRect
.Center(), aItemRect
, pItem
->maText
);
192 Help::ShowQuickHelp( this, Rectangle(), String() );
198 ToolBox::RequestHelp( rHEvt
);
201 // -----------------------------------------------------------------------
203 void TaskToolBox::Select()
205 USHORT nItemId
= GetCurItemId();
206 ActivateTaskItem( nItemId
, TRUE
);
209 // -----------------------------------------------------------------------
211 void TaskToolBox::ImplFormatTaskToolBox()
213 if ( mnUpdateNewPos
== TOOLBOX_ITEM_NOTFOUND
)
215 // Eintraege aus der Liste entfernen
216 while ( mpItemList
->Count() > mnUpdatePos
)
217 delete mpItemList
->Remove( (ULONG
)mnUpdatePos
);
218 mnUpdateNewPos
= mnUpdatePos
;
221 // Maximale Itemgroesse berechnen
222 long nOldMaxTextWidth
= mnMaxTextWidth
;
224 if ( mpItemList
->Count() )
226 long nWinSize
= GetOutputSizePixel().Width()-8;
227 long nItemSize
= mpItemList
->GetObject(0)->maImage
.GetSizePixel().Width()+7+TASKBOX_TASKOFF
+2;
228 nWinSize
-= mpItemList
->Count()*nItemSize
;
230 nWinSize
/= mpItemList
->Count();
233 if ( nWinSize
< mnMaxTextWidth
)
234 mnMaxTextWidth
= nWinSize
;
235 if ( (mnMaxTextWidth
< nOldMaxTextWidth
) ||
236 ((mnMaxTextWidth
-nOldMaxTextWidth
> 3) &&
237 (mnSmallItem
!= TOOLBOX_ITEM_NOTFOUND
)) )
239 mnSmallItem
= TOOLBOX_ITEM_NOTFOUND
;
244 // Eintraege aus der ToolBox entfernen, die ersetzt werden
245 USHORT nBtnPos
= (mnUpdateNewPos
*2);
246 while ( nBtnPos
< GetItemCount() )
247 RemoveItem( nBtnPos
);
248 if ( mnUpdateNewPos
<= (mnActiveItemId
-1) )
251 // Neue Eintrage einfuegen
252 USHORT i
= mnUpdateNewPos
;
253 while ( i
< mpItemList
->Count() )
255 ImplTaskItem
* pItem
= mpItemList
->GetObject( i
);
257 // Textlaenge berechnen
258 XubString aText
= pItem
->maText
;
261 long nTxtWidth
= GetTextWidth( aText
);
262 if ( nTxtWidth
> mnMaxTextWidth
)
264 if ( mnSmallItem
== TOOLBOX_ITEM_NOTFOUND
)
267 aText
.AppendAscii( "..." );
270 aText
.Erase( aText
.Len()-3-1, 1 );
271 nTxtWidth
= GetTextWidth( aText
);
273 while ( (nTxtWidth
> mnMaxTextWidth
) && (aText
.Len() > 3) );
276 USHORT nItemId
= i
+1;
277 if ( aText
.EqualsAscii( "..." ) )
278 InsertItem( nItemId
, pItem
->maImage
, TIB_LEFT
);
280 InsertItem( nItemId
, pItem
->maImage
, aText
, TIB_LEFT
);
281 InsertSeparator( TOOLBOX_APPEND
, TASKBOX_TASKOFF
);
285 if ( mnUpdateNewPos
!= 0 )
286 mnMaxTextWidth
= nOldMaxTextWidth
;
288 if ( mnNewActivePos
+1 != mnActiveItemId
)
290 if ( mnActiveItemId
)
291 CheckItem( mnActiveItemId
, FALSE
);
292 mnActiveItemId
= mnNewActivePos
+1;
293 CheckItem( mnActiveItemId
);
297 // -----------------------------------------------------------------------
299 void TaskToolBox::StartUpdateTask()
301 mnOldItemCount
= mpItemList
->Count();
303 mnUpdateNewPos
= TOOLBOX_ITEM_NOTFOUND
;
304 mnNewActivePos
= 0xFFFE;
307 // -----------------------------------------------------------------------
309 void TaskToolBox::UpdateTask( const Image
& rImage
, const String
& rText
,
312 ImplTaskItem
* pItem
= mpItemList
->GetObject( mnUpdatePos
);
315 if ( (pItem
->maText
!= rText
) || (pItem
->maImage
!= rImage
) )
317 // Eintraege aus der Liste entfernen
318 while ( mpItemList
->Count() > mnUpdatePos
)
319 delete mpItemList
->Remove( (ULONG
)mnUpdatePos
);
326 if ( mnUpdatePos
< mnUpdateNewPos
)
327 mnUpdateNewPos
= mnUpdatePos
;
329 pItem
= new ImplTaskItem
;
330 pItem
->maImage
= rImage
;
331 pItem
->maText
= rText
;
332 mpItemList
->Insert( pItem
, LIST_APPEND
);
336 mnNewActivePos
= mnUpdatePos
;
341 // -----------------------------------------------------------------------
343 void TaskToolBox::EndUpdateTask()
345 if ( mnUpdateNewPos
== TOOLBOX_ITEM_NOTFOUND
)
347 // Eintraege aus der Liste entfernen
348 while ( mpItemList
->Count() > mnUpdatePos
)
349 delete mpItemList
->Remove( (ULONG
)mnUpdatePos
);
350 mnUpdateNewPos
= mnUpdatePos
;
353 ImplFormatTaskToolBox();