1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #define private public 24 25 #include <tools/ref.hxx> 26 #include <vcl/msgbox.hxx> 27 #include <soldep/soldep.hxx> 28 #include <soldep/tbox.hxx> 29 #include <soldep/soldlg.hrc> 30 31 32 33 SoldepToolBox::SoldepToolBox( Window* pParent, const ResId& aId, sal_Bool bDAble ) : 34 ToolBox( pParent, aId ), 35 bDockable( bDAble ), 36 bCloseMode( sal_False ), 37 bBoxIsVisible( sal_True ), 38 bPinable( sal_True ), 39 aPinedBitmap( DtSodResId( TID_SMALL_PIN_PINED )), // BMP_SMALL_PIN_PINED 40 aUnpinedBitmap( DtSodResId( TID_SMALL_PIN_UNPINED )) // BMP_SMALL_PIN_UNPINED 41 { 42 bPinable = sal_True; 43 44 SetAlign( WINDOWALIGN_TOP ); 45 HideItem(TID_SOLDEP_BACK); //Inital hide this item, activated in project view. 46 HideItem(TID_SOLDEP_SAVE); // Hide this item now, not used yet 47 HideItem(TID_SOLDEP_OPEN); // Hide this item now, not used yet 48 49 //SetMouseDownHdl(LINK(this,SoldepToolBox,MouseDownHdl)); 50 //SetFloatingLines( nFloatingLines ); 51 //SetFloatingMode( bFloatingMode ); 52 sal_Bool bFloatingMode = sal_False; 53 if ( bFloatingMode ) 54 { 55 //Point aPos( sToolBoxInfo.GetToken( 4, ',' ).ToInt64(), sToolBoxInfo.GetToken( 5, ',' ).ToInt64()); 56 //SetPosPixel( aPos ); 57 } 58 59 if ( bDockable ) InsertSeparator( 0 ); // Freiraum f�r Abrei�d�del schaffen 60 // (ein Separator an 1er Pos wird 61 // nicht gezeichnet, 62 // schafft aber Platz.) 63 bBoxIsVisible = sal_False; 64 // if ( sToolBoxInfo.GetToken( 3, ',' ) == "Visible" ) { 65 for ( sal_uInt16 i = 0; i < GetItemCount() && !bBoxIsVisible; i++ ) 66 { 67 // sal_uInt16 nItemId = GetItemId( i ); 68 69 switch ( GetItemType( i )) 70 { 71 case TOOLBOXITEM_SPACE: 72 break; 73 case TOOLBOXITEM_SEPARATOR : 74 break; 75 default: 76 bBoxIsVisible = sal_True; 77 break; 78 } 79 } 80 // } 81 82 if ( bBoxIsVisible ) { 83 if (!bDockable) 84 Show(); 85 else 86 Hide(); 87 } 88 else 89 Hide(); 90 91 bOldFloatMode = IsFloatingMode(); 92 } 93 94 /************************************************************************* 95 |* SoldepToolBox::~SoldepToolBox() 96 |************************************************************************/ 97 98 SoldepToolBox::~SoldepToolBox() 99 { 100 } 101 102 /************************************************************************* 103 |* SoldepToolBox::Paint() 104 |************************************************************************/ 105 106 void SoldepToolBox::Paint( const Rectangle& rRect ) 107 { 108 SetOutStyle( TOOLBOX_STYLE_FLAT ); 109 110 // Wenn wir eine Dockable ToolBox haben, ... 111 112 if ( bDockable ) 113 { 114 sal_uInt16 nItemId = GetItemId( 0 ); 115 116 // ... zeichnen wir den wunderbaren Abrei�d�del �ber das erste Item (Seperator) 117 118 if ( !IsFloatingMode() && ( mnCurLine == 1 )) { 119 sal_Bool bIsCloseable = (( mnWinStyle & WB_CLOSEABLE ) != 0 ); 120 121 ShowItem( nItemId ); 122 Rectangle aRect = GetItemRect( nItemId ); 123 124 ToolBox::Paint( rRect ); 125 126 if ( bIsCloseable ) 127 { 128 // Paint small cross button left/top of toolbar 129 SetLineColor( Color( COL_WHITE )); 130 131 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left()+6, aRect.Top())); 132 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Top()+6)); 133 134 SetLineColor( Color( COL_GRAY )); 135 136 DrawLine( Point( aRect.Left(), aRect.Top()+6), Point( aRect.Left()+6, aRect.Top()+6)); 137 DrawLine( Point( aRect.Left()+6, aRect.Top()), Point( aRect.Left()+6, aRect.Top()+6)); 138 139 SetLineColor( Color( COL_BLACK )); 140 141 DrawLine( Point( aRect.Left()+2, aRect.Top()+2), Point( aRect.Left()+4, aRect.Top()+4)); 142 DrawLine( Point( aRect.Left()+2, aRect.Top()+4), Point( aRect.Left()+4, aRect.Top()+2)); 143 } 144 else if ( bPinable ) 145 { 146 if ( GetPin()) 147 DrawBitmap( Point( aRect.Left(), aRect.Top()), aPinedBitmap ); 148 else 149 DrawBitmap( Point( aRect.Left(), aRect.Top()), aUnpinedBitmap ); 150 } 151 152 SetLineColor( Color( COL_WHITE )); 153 154 if ( IsHorizontal()) 155 { 156 if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left(), aRect.Top()+8), Point( aRect.Right(), aRect.Bottom())); 157 158 DrawLine( Point(aRect.Left(), aRect.Top()), Point(aRect.Left(), aRect.Bottom())); 159 DrawLine( Point(aRect.Left(), aRect.Top()), Point(aRect.Left()+2, aRect.Top())); 160 161 SetLineColor( Color( COL_WHITE )); 162 163 DrawLine( Point(aRect.Left()+4, aRect.Top()), Point(aRect.Left()+4, aRect.Bottom())); 164 DrawLine( Point(aRect.Left()+4, aRect.Top()), Point(aRect.Left()+6, aRect.Top())); 165 166 SetLineColor( Color( COL_GRAY ));//GRAY 167 168 DrawLine( Point(aRect.Left()+2, aRect.Top()), Point(aRect.Left()+2, aRect.Bottom())); 169 DrawLine( Point(aRect.Left(), aRect.Bottom()), Point(aRect.Left()+2, aRect.Bottom())); 170 171 SetLineColor( Color( COL_BLACK )); 172 173 DrawLine( Point(aRect.Left()+6, aRect.Top()), Point(aRect.Left()+6, aRect.Bottom())); 174 DrawLine( Point(aRect.Left()+4, aRect.Bottom()), Point(aRect.Left()+6, aRect.Bottom())); 175 176 } 177 else 178 { 179 if ( bIsCloseable || bPinable ) aRect = Rectangle( Point( aRect.Left()+8, aRect.Top()), Point( aRect.Right(), aRect.Bottom())); 180 181 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Top()+2)); 182 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top())); 183 184 DrawLine( Point( aRect.Left(), aRect.Top()+4), Point( aRect.Left(), aRect.Top()+6)); 185 DrawLine( Point( aRect.Left(), aRect.Top()+4), Point( aRect.Right(), aRect.Top()+4)); 186 187 SetLineColor( Color( COL_GRAY )); 188 189 DrawLine( Point( aRect.Left(), aRect.Top()+2), Point( aRect.Right(),aRect.Top()+2)); 190 DrawLine( Point( aRect.Right(), aRect.Top()), Point( aRect.Right(), aRect.Top()+2)); 191 192 DrawLine( Point( aRect.Left(), aRect.Top()+6), Point( aRect.Right(),aRect.Top()+6)); 193 DrawLine( Point( aRect.Right(), aRect.Top()+4), Point( aRect.Right(), aRect.Top()+6)); 194 195 } 196 } 197 else 198 { 199 // Sind wir im FloatingMode, dann wollen wir keinen Abrei�d�del haben 200 // und hiden somit das erste Item. 201 202 //Hiden l�scht leider das erste Object der n�chsten Zeile, daher nicht 203 //l�schen 204 HideItem( nItemId ); 205 ToolBox::Paint( rRect ); 206 } 207 } 208 else 209 { 210 ToolBox::Paint( rRect ); 211 } 212 } 213 214 /************************************************************************* 215 |* SoldepToolBox::MouseButtonDown() 216 |************************************************************************/ 217 218 void SoldepToolBox::MouseButtonDown(const MouseEvent& rEvent) 219 { 220 // Sind wir im DockingMode, ... 221 222 if ( !IsFloatingMode() && ((( mnWinStyle & WB_CLOSEABLE ) != 0 ) || bPinable )) 223 { 224 // ... dann testen wir, ob am Abrei�d�del der Close-Button gedr�ckt wurde ... 225 226 Rectangle aRect = GetItemRect( GetItemId( 0 )); 227 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 )); 228 if ( rEvent.IsLeft() && aRect.IsInside( rEvent.GetPosPixel())) 229 { 230 if ( bPinable ) { 231 TogglePin(); 232 Invalidate(); 233 } 234 else { 235 bCloseMode = sal_True; 236 237 // ... und zeichnen ggf. den Button gedr�ckt. 238 239 SetLineColor( Color( COL_WHITE )); 240 241 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom())); 242 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top())); 243 244 SetLineColor( Color( COL_GRAY )); 245 246 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top())); 247 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom())); 248 } 249 } 250 else 251 { 252 ToolBox::MouseButtonDown( rEvent ); 253 } 254 } 255 else 256 { 257 ToolBox::MouseButtonDown( rEvent ); 258 } 259 260 aMouseDownHdl.Call(this); 261 } 262 263 /************************************************************************* 264 |* SoldepToolBox::MouseButtonUp() 265 |************************************************************************/ 266 267 void SoldepToolBox::MouseButtonUp(const MouseEvent& rEvent) 268 { 269 // Wenn der Close-Button am Abrei�d�del zuvor gedr�ckt wurde, ... 270 271 if ( bCloseMode ) 272 { 273 bCloseMode = sal_False; 274 275 // ... so zeichen wir diesen wieder normal ... 276 277 Rectangle aRect = GetItemRect( GetItemId( 0 )); 278 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 )); 279 280 SetLineColor( Color( COL_WHITE )); 281 282 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top())); 283 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom())); 284 285 SetLineColor( Color( COL_GRAY )); 286 287 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom())); 288 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top())); 289 290 if ( rEvent.IsLeft() && aRect.IsInside( rEvent.GetPosPixel())) 291 { 292 // ... und schlie�en die Box durch Aufruf der virtuellen Methode 293 // CloseDockingMode(). 294 295 CloseDockingMode(); 296 } 297 else 298 { 299 ToolBox::MouseButtonUp( rEvent ); 300 } 301 } 302 else 303 { 304 ToolBox::MouseButtonUp( rEvent ); 305 } 306 } 307 308 /************************************************************************* 309 |* SoldepToolBox::MouseMove() 310 |************************************************************************/ 311 312 void SoldepToolBox::MouseMove(const MouseEvent& rEvent) 313 { 314 // Wenn der Close-Button am Abrei�d�del zuvor gedr�ckt wurde, ... 315 316 if ( bCloseMode ) 317 { 318 Rectangle aRect = GetItemRect( GetItemId( 0 )); 319 aRect = Rectangle( aRect.TopLeft(), Point( aRect.Left()+6, aRect.Top()+6 )); 320 321 // ... der Mouse-Zeiger jedoch den Close-Button verl��t, ... 322 323 if ( !aRect.IsInside( rEvent.GetPosPixel())) 324 { 325 SetLineColor( Color( COL_WHITE )); 326 327 // ... zeichnen wir diesen halt wieder normal. 328 329 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Right(), aRect.Top())); 330 DrawLine( Point( aRect.Left(), aRect.Top()), Point( aRect.Left(), aRect.Bottom())); 331 332 SetLineColor( Color( COL_GRAY )); 333 334 DrawLine( Point( aRect.Left(), aRect.Bottom()), Point( aRect.Right(), aRect.Bottom())); 335 DrawLine( Point( aRect.Right(), aRect.Bottom()), Point( aRect.Right(), aRect.Top())); 336 337 bCloseMode = sal_False; 338 } 339 else 340 { 341 ToolBox::MouseMove( rEvent ); 342 } 343 } 344 else 345 { 346 ToolBox::MouseMove( rEvent ); 347 } 348 } 349 350 /*****************************************************************************/ 351 void SoldepToolBox::ToggleFloatingMode() 352 /*****************************************************************************/ 353 { 354 ToolBox::ToggleFloatingMode(); 355 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this); 356 } 357 358 /*****************************************************************************/ 359 void SoldepToolBox::EndDocking( const Rectangle& rRect, sal_Bool bFloatMode ) 360 /*****************************************************************************/ 361 { 362 ToolBox::EndDocking( rRect, bFloatMode ); 363 if ( aResizeHdl.IsSet()) 364 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this); 365 else 366 { 367 GetParent()->Resize(); 368 } 369 }; 370 371 /*****************************************************************************/ 372 sal_Bool SoldepToolBox::Close() 373 /*****************************************************************************/ 374 { 375 if (!ToolBox::Close()) return sal_False; 376 377 return sal_True; 378 } 379 380 /*****************************************************************************/ 381 void SoldepToolBox::Move() 382 /*****************************************************************************/ 383 { 384 } 385 386 /************************************************************************* 387 |* SoldepToolBox::CloseDockingMode() 388 |* 389 |* virtuelle Methode zur Reaktion auf den Close-Button im DockinMode 390 |************************************************************************/ 391 392 void SoldepToolBox::CloseDockingMode() 393 { 394 Hide(); 395 bBoxIsVisible = sal_False; 396 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this); 397 } 398 399 /************************************************************************* 400 |* SoldepToolBox::Command() 401 |************************************************************************/ 402 403 void SoldepToolBox::Command( const CommandEvent& rCEvt) 404 { 405 if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) 406 { 407 if( !IsFloatingMode() && bDockable 408 && ( GetItemRect(GetItemId( 0 )).IsInside(rCEvt.GetMousePosPixel()))) 409 { 410 // Hier das Context-Menue fuer Abrei�d�del dynamisch erzeugen... 411 412 PopupMenu aPopupMenu; 413 414 String sText( String::CreateFromAscii( "Floating mode" )); 415 aPopupMenu.InsertItem( 5, sText ); 416 aPopupMenu.InsertSeparator(); 417 418 sText = String::CreateFromAscii( "Top" ); 419 aPopupMenu.InsertItem( 1, sText ); 420 sText = String::CreateFromAscii( "Bottom" ); 421 aPopupMenu.InsertItem( 2, sText ); 422 sText = String::CreateFromAscii( "Left" ); 423 aPopupMenu.InsertItem( 3, sText ); 424 sText = String::CreateFromAscii( "Right" ); 425 aPopupMenu.InsertItem( 4, sText ); 426 427 switch( GetAlign()) 428 { 429 case WINDOWALIGN_TOP : aPopupMenu.EnableItem( 1, sal_False ); break; 430 case WINDOWALIGN_BOTTOM : aPopupMenu.EnableItem( 2, sal_False ); break; 431 case WINDOWALIGN_LEFT : aPopupMenu.EnableItem( 3, sal_False ); break; 432 case WINDOWALIGN_RIGHT : aPopupMenu.EnableItem( 4, sal_False ); break; 433 } 434 435 if (( mnWinStyle & WB_CLOSEABLE ) != 0 ) 436 { 437 aPopupMenu.InsertSeparator(); 438 sText = String::CreateFromAscii( "Hide" ); 439 aPopupMenu.InsertItem( 6, sText ); 440 } 441 else if ( bPinable ) { 442 aPopupMenu.InsertSeparator(); 443 sText = String::CreateFromAscii( "Pin" ); 444 aPopupMenu.InsertItem( 6, sText ); 445 aPopupMenu.CheckItem( 6, GetPin()); 446 } 447 448 // ... und rufen. 449 450 aPopupMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl )); 451 aPopupMenu.Execute( this, rCEvt.GetMousePosPixel()); 452 } 453 else if ( !GetItemId(rCEvt.GetMousePosPixel())) 454 { 455 CallContextMenu( this, rCEvt.GetMousePosPixel()); 456 } 457 } 458 else ToolBox::Command( rCEvt ); 459 } 460 461 /************************************************************************* 462 |* SoldepToolBox::GetContextMenu() 463 |************************************************************************/ 464 465 PopupMenu *SoldepToolBox::GetContextMenu() 466 { 467 InitContextMenu(); 468 return &aMenu; 469 } 470 471 /************************************************************************* 472 |* SoldepToolBox::InitContextMenu() 473 |************************************************************************/ 474 475 void SoldepToolBox::InitContextMenu() 476 { 477 sal_uInt16 nStart = 0; 478 if ( bDockable ) 479 nStart = 1; 480 481 aMenu.Clear(); 482 483 for ( sal_uInt16 i = nStart; i < GetItemCount(); i++ ) 484 { 485 sal_uInt16 nItemId = GetItemId( i ); 486 487 switch ( GetItemType( i )) 488 { 489 case TOOLBOXITEM_SPACE: 490 break; 491 case TOOLBOXITEM_SEPARATOR : 492 if (!(( i < GetItemCount() - 1 ) && ( GetItemType( i + 1 ) == TOOLBOXITEM_DONTKNOW ))) 493 aMenu.InsertSeparator(); 494 break; 495 default: 496 aMenu.InsertItem( nItemId, GetItemText( nItemId ), GetItemImage( nItemId )); 497 if (IsItemChecked( nItemId )) aMenu.CheckItem( nItemId, sal_True ); 498 if (!IsItemEnabled( nItemId )) aMenu.EnableItem( nItemId, sal_False ); 499 if (!IsItemVisible( nItemId )) aMenu.HideItem(nItemId); 500 break; 501 } 502 } 503 } 504 505 /************************************************************************* 506 |* SoldepToolBox::CallContextMenu() 507 |************************************************************************/ 508 509 void SoldepToolBox::CallContextMenu( Window *pWin, Point aPos ) 510 { 511 if ( aMenu.IsInExecute()) 512 return; 513 514 InitContextMenu(); 515 516 // ... und rufen. 517 518 aMenu.SetSelectHdl ( LINK ( this, SoldepToolBox, MenuSelectHdl )); 519 aMenu.Execute( pWin, aPos ); 520 } 521 522 void SoldepToolBox::SetPosSizePixel( const Point& rNewPos, 523 const Size& rNewSize ) 524 { 525 // if(rNewPos != GetPosPixel() || rNewSize != GetSizePixel()) 526 // { 527 ToolBox::SetPosSizePixel(rNewPos,rNewSize); 528 // Resize(); 529 // } 530 } 531 532 void SoldepToolBox::SetDockingRects( const Rectangle& rOutRect, 533 const Rectangle& rInRect ) 534 { 535 if(rOutRect != aOutRect || rInRect != aInRect) 536 { 537 ToolBox::SetDockingRects(rOutRect,rInRect); 538 Invalidate(); 539 540 aOutRect = rOutRect; 541 aInRect = rInRect; 542 } 543 } 544 545 /*****************************************************************************/ 546 void SoldepToolBox::StartDocking() 547 /*****************************************************************************/ 548 { 549 ToolBox::StartDocking(); 550 CallEventListeners( VCLEVENT_USER_TBOX_RESIZE_APP, this); 551 }; 552 553 sal_Bool SoldepToolBox::GetPin() 554 555 { 556 return bPin; 557 } 558 559 void SoldepToolBox::TogglePin() 560 { 561 bPin = !bPin; 562 } 563 564 void SoldepToolBox::SetPin( sal_Bool bP ) 565 { 566 bPin = bP; 567 } 568 569 /************************************************************************* 570 |* SoldepToolBox::MenuSelectHdl() 571 |* 572 |* Handler, der beim Execute der Context-Men�s gerufen wird 573 |************************************************************************/ 574 575 IMPL_LINK ( SoldepToolBox, MenuSelectHdl, Menu*, pMenu ) 576 { 577 // Wenn die CurItemId <= 6 ist, dann wurde das Abrei�d�del-Context-Men� ausgef�hrt ... 578 sal_uIntPtr itemid; 579 itemid = pMenu->GetCurItemId(); 580 581 if ( pMenu == &aMenu ) 582 { 583 // ... Andernfalls wurde das Default-Context-Men� ausgef�hrt ... 584 sal_uInt16 nTmpId = mnCurItemId; 585 mnCurItemId = pMenu->GetCurItemId(); 586 587 // ... und der gesetzte Handler (in soldep.cxx) wird gerufen. 588 maSelectHdl.Call( this ); 589 mnCurItemId = nTmpId; 590 } 591 return 0; 592 } 593