1*5900e8ecSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5900e8ecSAndrew Rist * distributed with this work for additional information 6*5900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5900e8ecSAndrew Rist * "License"); you may not use this file except in compliance 9*5900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5900e8ecSAndrew Rist * software distributed under the License is distributed on an 15*5900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5900e8ecSAndrew Rist * KIND, either express or implied. See the License for the 17*5900e8ecSAndrew Rist * specific language governing permissions and limitations 18*5900e8ecSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5900e8ecSAndrew Rist *************************************************************/ 21*5900e8ecSAndrew Rist 22*5900e8ecSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svtools.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #define _TASKBAR_CXX 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <tools/list.hxx> 30cdf0e10cSrcweir #include <tools/debug.hxx> 31cdf0e10cSrcweir #include <vcl/image.hxx> 32cdf0e10cSrcweir #include <vcl/help.hxx> 33cdf0e10cSrcweir #include <svtools/taskbar.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir // ======================================================================= 36cdf0e10cSrcweir 37cdf0e10cSrcweir #define TASKBOX_TASKOFF 3 38cdf0e10cSrcweir 39cdf0e10cSrcweir // ======================================================================= 40cdf0e10cSrcweir 41cdf0e10cSrcweir struct ImplTaskItem 42cdf0e10cSrcweir { 43cdf0e10cSrcweir Image maImage; 44cdf0e10cSrcweir XubString maText; 45cdf0e10cSrcweir }; 46cdf0e10cSrcweir 47cdf0e10cSrcweir DECLARE_LIST( ImplTaskItemList, ImplTaskItem* ) 48cdf0e10cSrcweir 49cdf0e10cSrcweir // ======================================================================= 50cdf0e10cSrcweir 51cdf0e10cSrcweir TaskToolBox::TaskToolBox( Window* pParent, WinBits nWinStyle ) : 52cdf0e10cSrcweir ToolBox( pParent, nWinStyle | WB_SCROLL | WB_3DLOOK ) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir mpItemList = new ImplTaskItemList; 55cdf0e10cSrcweir mnMaxTextWidth = 0; 56cdf0e10cSrcweir mnActiveItemId = 0; 57cdf0e10cSrcweir mnTaskItem = 0; 58cdf0e10cSrcweir mnSmallItem = TOOLBOX_ITEM_NOTFOUND; 59cdf0e10cSrcweir mbMinActivate = sal_False; 60cdf0e10cSrcweir 61cdf0e10cSrcweir SetAlign( WINDOWALIGN_BOTTOM ); 62cdf0e10cSrcweir SetButtonType( BUTTON_SYMBOLTEXT ); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir // ----------------------------------------------------------------------- 66cdf0e10cSrcweir 67cdf0e10cSrcweir TaskToolBox::~TaskToolBox() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir ImplTaskItem* pItem = mpItemList->First(); 70cdf0e10cSrcweir while ( pItem ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir delete pItem; 73cdf0e10cSrcweir pItem = mpItemList->Next(); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir 76cdf0e10cSrcweir delete mpItemList; 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir // ----------------------------------------------------------------------- 80cdf0e10cSrcweir 81cdf0e10cSrcweir void TaskToolBox::ActivateTaskItem( sal_uInt16 nItemId, sal_Bool bMinActivate ) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir if ( nItemId ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir if ( nItemId != mnActiveItemId ) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir if ( mnActiveItemId ) 88cdf0e10cSrcweir CheckItem( mnActiveItemId, sal_False ); 89cdf0e10cSrcweir CheckItem( nItemId ); 90cdf0e10cSrcweir mnActiveItemId = nItemId; 91cdf0e10cSrcweir } 92cdf0e10cSrcweir else 93cdf0e10cSrcweir { 94cdf0e10cSrcweir if ( !bMinActivate ) 95cdf0e10cSrcweir return; 96cdf0e10cSrcweir 97cdf0e10cSrcweir mbMinActivate = sal_True; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir mnTaskItem = nItemId-1; 101cdf0e10cSrcweir ActivateTask(); 102cdf0e10cSrcweir mnTaskItem = 0; 103cdf0e10cSrcweir mbMinActivate = sal_False; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir // ----------------------------------------------------------------------- 108cdf0e10cSrcweir 109cdf0e10cSrcweir void TaskToolBox::ActivateTask() 110cdf0e10cSrcweir { 111cdf0e10cSrcweir maActivateTaskHdl.Call( this ); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ----------------------------------------------------------------------- 115cdf0e10cSrcweir 116cdf0e10cSrcweir void TaskToolBox::ContextMenu() 117cdf0e10cSrcweir { 118cdf0e10cSrcweir maContextMenuHdl.Call( this ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir // ----------------------------------------------------------------------- 122cdf0e10cSrcweir 123cdf0e10cSrcweir void TaskToolBox::MouseButtonDown( const MouseEvent& rMEvt ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if ( !rMEvt.IsRight() ) 126cdf0e10cSrcweir ToolBox::MouseButtonDown( rMEvt ); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir // ----------------------------------------------------------------------- 130cdf0e10cSrcweir 131cdf0e10cSrcweir void TaskToolBox::Resize() 132cdf0e10cSrcweir { 133cdf0e10cSrcweir mnOldItemCount = mpItemList->Count(); 134cdf0e10cSrcweir mnUpdatePos = (sal_uInt16)mnOldItemCount; 135cdf0e10cSrcweir mnUpdateNewPos = TOOLBOX_ITEM_NOTFOUND; 136cdf0e10cSrcweir ImplFormatTaskToolBox(); 137cdf0e10cSrcweir ToolBox::Resize(); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir // ----------------------------------------------------------------------- 141cdf0e10cSrcweir 142cdf0e10cSrcweir void TaskToolBox::Command( const CommandEvent& rCEvt ) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir sal_uInt16 nItemId = GetItemId( rCEvt.GetMousePosPixel() ); 147cdf0e10cSrcweir // Dies machen wir nicht mehr, da es von zu vielen als stoerend empfunden wurde 148cdf0e10cSrcweir // ActivateTaskItem( nItemId ); 149cdf0e10cSrcweir mnTaskItem = nItemId-1; 150cdf0e10cSrcweir 151cdf0e10cSrcweir maContextMenuPos = rCEvt.GetMousePosPixel(); 152cdf0e10cSrcweir ContextMenu(); 153cdf0e10cSrcweir maContextMenuPos = Point(); 154cdf0e10cSrcweir mnTaskItem = 0; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir else 157cdf0e10cSrcweir ToolBox::Command( rCEvt ); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir // ----------------------------------------------------------------------- 161cdf0e10cSrcweir 162cdf0e10cSrcweir void TaskToolBox::RequestHelp( const HelpEvent& rHEvt ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir if ( rHEvt.GetMode() & (HELPMODE_BALLOON | HELPMODE_QUICK) ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir sal_uInt16 nItemId = GetItemId( ScreenToOutputPixel( rHEvt.GetMousePosPixel() ) ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir if ( nItemId ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir ImplTaskItem* pItem = mpItemList->GetObject( nItemId-1 ); 171cdf0e10cSrcweir if ( pItem ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir if ( pItem->maText != GetItemText( nItemId ) ) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir Rectangle aItemRect = GetItemRect( nItemId ); 176cdf0e10cSrcweir if ( rHEvt.GetMode() & HELPMODE_QUICK ) 177cdf0e10cSrcweir Help::ShowQuickHelp( this, aItemRect, pItem->maText ); 178cdf0e10cSrcweir else 179cdf0e10cSrcweir Help::ShowBalloon( this, aItemRect.Center(), aItemRect, pItem->maText ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir else 182cdf0e10cSrcweir Help::ShowQuickHelp( this, Rectangle(), String() ); 183cdf0e10cSrcweir return; 184cdf0e10cSrcweir } 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir ToolBox::RequestHelp( rHEvt ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir // ----------------------------------------------------------------------- 192cdf0e10cSrcweir 193cdf0e10cSrcweir void TaskToolBox::Select() 194cdf0e10cSrcweir { 195cdf0e10cSrcweir sal_uInt16 nItemId = GetCurItemId(); 196cdf0e10cSrcweir ActivateTaskItem( nItemId, sal_True ); 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir // ----------------------------------------------------------------------- 200cdf0e10cSrcweir 201cdf0e10cSrcweir void TaskToolBox::ImplFormatTaskToolBox() 202cdf0e10cSrcweir { 203cdf0e10cSrcweir if ( mnUpdateNewPos == TOOLBOX_ITEM_NOTFOUND ) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir // Eintraege aus der Liste entfernen 206cdf0e10cSrcweir while ( mpItemList->Count() > mnUpdatePos ) 207cdf0e10cSrcweir delete mpItemList->Remove( (sal_uLong)mnUpdatePos ); 208cdf0e10cSrcweir mnUpdateNewPos = mnUpdatePos; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir // Maximale Itemgroesse berechnen 212cdf0e10cSrcweir long nOldMaxTextWidth = mnMaxTextWidth; 213cdf0e10cSrcweir mnMaxTextWidth = 70; 214cdf0e10cSrcweir if ( mpItemList->Count() ) 215cdf0e10cSrcweir { 216cdf0e10cSrcweir long nWinSize = GetOutputSizePixel().Width()-8; 217cdf0e10cSrcweir long nItemSize = mpItemList->GetObject(0)->maImage.GetSizePixel().Width()+7+TASKBOX_TASKOFF+2; 218cdf0e10cSrcweir nWinSize -= mpItemList->Count()*nItemSize; 219cdf0e10cSrcweir if ( nWinSize > 0 ) 220cdf0e10cSrcweir nWinSize /= mpItemList->Count(); 221cdf0e10cSrcweir else 222cdf0e10cSrcweir nWinSize = 0; 223cdf0e10cSrcweir if ( nWinSize < mnMaxTextWidth ) 224cdf0e10cSrcweir mnMaxTextWidth = nWinSize; 225cdf0e10cSrcweir if ( (mnMaxTextWidth < nOldMaxTextWidth) || 226cdf0e10cSrcweir ((mnMaxTextWidth-nOldMaxTextWidth > 3) && 227cdf0e10cSrcweir (mnSmallItem != TOOLBOX_ITEM_NOTFOUND)) ) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir mnSmallItem = TOOLBOX_ITEM_NOTFOUND; 230cdf0e10cSrcweir mnUpdateNewPos = 0; 231cdf0e10cSrcweir } 232cdf0e10cSrcweir } 233cdf0e10cSrcweir 234cdf0e10cSrcweir // Eintraege aus der ToolBox entfernen, die ersetzt werden 235cdf0e10cSrcweir sal_uInt16 nBtnPos = (mnUpdateNewPos*2); 236cdf0e10cSrcweir while ( nBtnPos < GetItemCount() ) 237cdf0e10cSrcweir RemoveItem( nBtnPos ); 238cdf0e10cSrcweir if ( mnUpdateNewPos <= (mnActiveItemId-1) ) 239cdf0e10cSrcweir mnActiveItemId = 0; 240cdf0e10cSrcweir 241cdf0e10cSrcweir // Neue Eintrage einfuegen 242cdf0e10cSrcweir sal_uInt16 i = mnUpdateNewPos; 243cdf0e10cSrcweir while ( i < mpItemList->Count() ) 244cdf0e10cSrcweir { 245cdf0e10cSrcweir ImplTaskItem* pItem = mpItemList->GetObject( i ); 246cdf0e10cSrcweir 247cdf0e10cSrcweir // Textlaenge berechnen 248cdf0e10cSrcweir XubString aText = pItem->maText; 249cdf0e10cSrcweir if ( !aText.Len() ) 250cdf0e10cSrcweir aText = ' '; 251cdf0e10cSrcweir long nTxtWidth = GetTextWidth( aText ); 252cdf0e10cSrcweir if ( nTxtWidth > mnMaxTextWidth ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir if ( mnSmallItem == TOOLBOX_ITEM_NOTFOUND ) 255cdf0e10cSrcweir mnSmallItem = i; 256cdf0e10cSrcweir // 3 == Len of "..." 257cdf0e10cSrcweir aText.AppendAscii( "..." ); 258cdf0e10cSrcweir do 259cdf0e10cSrcweir { 260cdf0e10cSrcweir aText.Erase( aText.Len()-3-1, 1 ); 261cdf0e10cSrcweir nTxtWidth = GetTextWidth( aText ); 262cdf0e10cSrcweir } 263cdf0e10cSrcweir while ( (nTxtWidth > mnMaxTextWidth) && (aText.Len() > 3) ); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir sal_uInt16 nItemId = i+1; 267cdf0e10cSrcweir if ( aText.EqualsAscii( "..." ) ) 268cdf0e10cSrcweir InsertItem( nItemId, pItem->maImage, TIB_LEFT ); 269cdf0e10cSrcweir else 270cdf0e10cSrcweir InsertItem( nItemId, pItem->maImage, aText, TIB_LEFT ); 271cdf0e10cSrcweir InsertSeparator( TOOLBOX_APPEND, TASKBOX_TASKOFF ); 272cdf0e10cSrcweir i++; 273cdf0e10cSrcweir } 274cdf0e10cSrcweir 275cdf0e10cSrcweir if ( mnUpdateNewPos != 0 ) 276cdf0e10cSrcweir mnMaxTextWidth = nOldMaxTextWidth; 277cdf0e10cSrcweir 278cdf0e10cSrcweir if ( mnNewActivePos+1 != mnActiveItemId ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir if ( mnActiveItemId ) 281cdf0e10cSrcweir CheckItem( mnActiveItemId, sal_False ); 282cdf0e10cSrcweir mnActiveItemId = mnNewActivePos+1; 283cdf0e10cSrcweir CheckItem( mnActiveItemId ); 284cdf0e10cSrcweir } 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir // ----------------------------------------------------------------------- 288cdf0e10cSrcweir 289cdf0e10cSrcweir void TaskToolBox::StartUpdateTask() 290cdf0e10cSrcweir { 291cdf0e10cSrcweir mnOldItemCount = mpItemList->Count(); 292cdf0e10cSrcweir mnUpdatePos = 0; 293cdf0e10cSrcweir mnUpdateNewPos = TOOLBOX_ITEM_NOTFOUND; 294cdf0e10cSrcweir mnNewActivePos = 0xFFFE; 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir // ----------------------------------------------------------------------- 298cdf0e10cSrcweir 299cdf0e10cSrcweir void TaskToolBox::UpdateTask( const Image& rImage, const String& rText, 300cdf0e10cSrcweir sal_Bool bActive ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir ImplTaskItem* pItem = mpItemList->GetObject( mnUpdatePos ); 303cdf0e10cSrcweir if ( pItem ) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir if ( (pItem->maText != rText) || (pItem->maImage != rImage) ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir // Eintraege aus der Liste entfernen 308cdf0e10cSrcweir while ( mpItemList->Count() > mnUpdatePos ) 309cdf0e10cSrcweir delete mpItemList->Remove( (sal_uLong)mnUpdatePos ); 310cdf0e10cSrcweir pItem = NULL; 311cdf0e10cSrcweir } 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir if ( !pItem ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir if ( mnUpdatePos < mnUpdateNewPos ) 317cdf0e10cSrcweir mnUpdateNewPos = mnUpdatePos; 318cdf0e10cSrcweir 319cdf0e10cSrcweir pItem = new ImplTaskItem; 320cdf0e10cSrcweir pItem->maImage = rImage; 321cdf0e10cSrcweir pItem->maText = rText; 322cdf0e10cSrcweir mpItemList->Insert( pItem, LIST_APPEND ); 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir if ( bActive ) 326cdf0e10cSrcweir mnNewActivePos = mnUpdatePos; 327cdf0e10cSrcweir 328cdf0e10cSrcweir mnUpdatePos++; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir // ----------------------------------------------------------------------- 332cdf0e10cSrcweir 333cdf0e10cSrcweir void TaskToolBox::EndUpdateTask() 334cdf0e10cSrcweir { 335cdf0e10cSrcweir if ( mnUpdateNewPos == TOOLBOX_ITEM_NOTFOUND ) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir // Eintraege aus der Liste entfernen 338cdf0e10cSrcweir while ( mpItemList->Count() > mnUpdatePos ) 339cdf0e10cSrcweir delete mpItemList->Remove( (sal_uLong)mnUpdatePos ); 340cdf0e10cSrcweir mnUpdateNewPos = mnUpdatePos; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir ImplFormatTaskToolBox(); 344cdf0e10cSrcweir } 345cdf0e10cSrcweir 346