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 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 // include --------------------------------------------------------------- 28 29 #include <string> // HACK: prevent conflict between STLPORT and Workshop headers 30 #include <vcl/toolbox.hxx> 31 #ifndef _SV_BUTTON_HXX //autogen 32 #include <vcl/button.hxx> 33 #endif 34 #include <svl/intitem.hxx> 35 #include <sfx2/dispatch.hxx> 36 #include <sfx2/app.hxx> 37 38 #include <svx/dialogs.hrc> 39 #include "svx/layctrl.hxx" 40 #include <svx/dialmgr.hxx> 41 #include <comphelper/processfactory.hxx> 42 #include <svtools/colorcfg.hxx> 43 44 // namespaces 45 using namespace ::com::sun::star::uno; 46 using namespace ::com::sun::star::beans; 47 using namespace ::com::sun::star::util; 48 using namespace ::com::sun::star::frame; 49 50 SFX_IMPL_TOOLBOX_CONTROL(SvxTableToolBoxControl,SfxUInt16Item); 51 SFX_IMPL_TOOLBOX_CONTROL(SvxColumnsToolBoxControl,SfxUInt16Item); 52 53 // class TableWindow ----------------------------------------------------- 54 55 class TableWindow : public SfxPopupWindow 56 { 57 private: 58 ::Color aLineColor; 59 ::Color aHighlightLineColor; 60 ::Color aFillColor; 61 ::Color aHighlightFillColor; 62 long nCol; 63 long nLine; 64 long nWidth; 65 long nHeight; 66 long nMX; 67 long nMY; 68 long nTextHeight; 69 sal_Bool bInitialKeyInput; 70 sal_Bool m_bMod1; 71 ToolBox& rTbx; 72 Reference< XFrame > mxFrame; 73 rtl::OUString maCommand; 74 75 void UpdateSize_Impl( long nNewCol, long nNewLine); 76 77 public: 78 TableWindow( sal_uInt16 nSlotId, 79 const rtl::OUString& rCmd, 80 ToolBox& rParentTbx, 81 const Reference< XFrame >& rFrame ); 82 ~TableWindow(); 83 84 void KeyInput( const KeyEvent& rKEvt ); 85 virtual void MouseMove( const MouseEvent& rMEvt ); 86 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 87 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 88 virtual void Paint( const Rectangle& ); 89 virtual void PopupModeEnd(); 90 virtual SfxPopupWindow* Clone() const; 91 92 sal_uInt16 GetColCount() const { return (sal_uInt16)nCol; } 93 sal_uInt16 GetLineCount() const { return (sal_uInt16)nLine; } 94 }; 95 96 // ----------------------------------------------------------------------- 97 98 TableWindow::TableWindow( sal_uInt16 nSlotId, const rtl::OUString& rCmd, ToolBox& rParentTbx, const Reference< XFrame >& rFrame ) : 99 SfxPopupWindow( nSlotId, rFrame, WB_SYSTEMWINDOW ), 100 bInitialKeyInput(sal_True), 101 m_bMod1(sal_False), 102 rTbx(rParentTbx), 103 mxFrame( rFrame ), 104 maCommand( rCmd ) 105 { 106 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings(); 107 svtools::ColorConfig aColorConfig; 108 aLineColor = ::Color( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor ); 109 aHighlightLineColor = rStyles.GetHighlightTextColor(); 110 aFillColor = rStyles.GetWindowColor(); 111 aHighlightFillColor = rStyles.GetHighlightColor(); 112 113 nTextHeight = GetTextHeight()+1; 114 SetBackground(); 115 Font aFont = GetFont(); 116 aFont.SetColor( aLineColor ); 117 aFont.SetFillColor( aFillColor ); 118 aFont.SetTransparent( sal_False ); 119 SetFont( aFont ); 120 121 nCol = 0; 122 nLine = 0; 123 nWidth = 5; 124 nHeight = 5; 125 126 Size aLogicSize = LogicToPixel( Size( 55, 35 ), MapMode( MAP_10TH_MM ) ); 127 nMX = aLogicSize.Width(); 128 nMY = aLogicSize.Height(); 129 SetOutputSizePixel( Size( nMX*nWidth-1, nMY*nHeight-1+nTextHeight ) ); 130 } 131 // ----------------------------------------------------------------------- 132 TableWindow::~TableWindow() 133 { 134 } 135 // ----------------------------------------------------------------------- 136 137 SfxPopupWindow* TableWindow::Clone() const 138 { 139 return new TableWindow( GetId(), maCommand, rTbx, mxFrame ); 140 } 141 142 // ----------------------------------------------------------------------- 143 144 void TableWindow::MouseMove( const MouseEvent& rMEvt ) 145 { 146 SfxPopupWindow::MouseMove( rMEvt ); 147 Point aPos = rMEvt.GetPosPixel(); 148 Point aMousePos( aPos ); 149 150 if ( rMEvt.IsEnterWindow() ) 151 CaptureMouse(); 152 else if ( aMousePos.X() < 0 || aMousePos.Y() < 0 ) 153 { 154 nCol = 0; 155 nLine = 0; 156 ReleaseMouse(); 157 Invalidate(); 158 return; 159 } 160 161 long nNewCol = 0; 162 long nNewLine = 0; 163 164 if ( aPos.X() > 0 ) 165 nNewCol = aPos.X() / nMX + 1; 166 if ( aPos.Y() > 0 ) 167 nNewLine = aPos.Y() / nMY + 1; 168 169 if ( nNewCol > 500 ) 170 nNewCol = 500; 171 if ( nNewLine > 1000 ) 172 nNewLine = 1000; 173 174 UpdateSize_Impl( nNewCol, nNewLine); 175 176 } 177 /* -----------------------------15.05.2002 17:14------------------------------ 178 179 ---------------------------------------------------------------------------*/ 180 void TableWindow::UpdateSize_Impl( long nNewCol, long nNewLine) 181 { 182 Size aWinSize = GetOutputSizePixel(); 183 Point aWinPos = GetPosPixel(); 184 Point aMaxPos = OutputToScreenPixel( GetDesktopRectPixel().BottomRight() ); 185 if ( (nWidth <= nNewCol) || (nHeight < nNewLine) ) 186 { 187 long nOff = 0; 188 189 if ( nWidth <= nNewCol ) 190 { 191 nWidth = nNewCol; 192 nWidth++; 193 } 194 if ( nHeight <= nNewLine ) 195 { 196 nHeight = nNewLine; 197 nOff = 1; 198 } 199 while ( nWidth > 0 && 200 (short)(aWinPos.X()+(nMX*nWidth-1)) >= aMaxPos.X()-3 ) 201 nWidth--; 202 203 while ( nHeight > 0 && 204 (short)(aWinPos.Y()+(nMY*nHeight-1+nTextHeight)) >= 205 aMaxPos.Y()-3 ) 206 nHeight--; 207 208 if ( nNewCol > nWidth ) 209 nNewCol = nWidth; 210 211 if ( nNewLine > nHeight ) 212 nNewLine = nHeight; 213 214 Size _aWinSize = GetOutputSizePixel(); 215 Invalidate( Rectangle( 0, _aWinSize.Height()-nTextHeight+2-nOff, 216 _aWinSize.Width(), _aWinSize.Height() ) ); 217 SetOutputSizePixel( Size( nMX*nWidth-1, nMY*nHeight-1+nTextHeight ) ); 218 } 219 long nMinCol = 0; 220 long nMaxCol = 0; 221 long nMinLine = 0; 222 long nMaxLine = 0; 223 if ( nNewCol < nCol ) 224 { 225 nMinCol = nNewCol; 226 nMaxCol = nCol; 227 } 228 else 229 { 230 nMinCol = nCol; 231 nMaxCol = nNewCol; 232 } 233 if ( nNewLine < nLine ) 234 { 235 nMinLine = nNewLine; 236 nMaxLine = nLine; 237 } 238 else 239 { 240 nMinLine = nLine; 241 nMaxLine = nNewLine; 242 } 243 244 if ( (nNewCol != nCol) || (nNewLine != nLine) ) 245 { 246 Invalidate( Rectangle( 0, aWinSize.Height()-nTextHeight+2, 247 aWinSize.Width(), aWinSize.Height() ) ); 248 249 if ( nNewCol != nCol ) 250 { 251 Invalidate( Rectangle( nMinCol*nMX-1, 0, nMaxCol*nMX+1, nMaxLine*nMY ) ); 252 nCol = nNewCol; 253 } 254 if ( nNewLine != nLine ) 255 { 256 Invalidate( Rectangle( 0, nMinLine*nMY-2, nMaxCol*nMX, nMaxLine*nMY+1 ) ); 257 nLine = nNewLine; 258 } 259 } 260 Update(); 261 } 262 /* -----------------------------15.05.2002 14:22------------------------------ 263 264 ---------------------------------------------------------------------------*/ 265 void TableWindow::KeyInput( const KeyEvent& rKEvt ) 266 { 267 sal_Bool bHandled = sal_False; 268 sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier(); 269 sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode(); 270 if(!nModifier) 271 { 272 if( KEY_UP == nKey || KEY_DOWN == nKey || 273 KEY_LEFT == nKey || KEY_RIGHT == nKey || 274 KEY_ESCAPE == nKey ||KEY_RETURN == nKey ) 275 { 276 bHandled = sal_True; 277 long nNewCol = nCol; 278 long nNewLine = nLine; 279 switch(nKey) 280 { 281 case KEY_UP : 282 if(nNewLine > 1) 283 { 284 nNewLine--; 285 break; 286 } 287 //no break; 288 case KEY_ESCAPE: 289 EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL); 290 break; 291 case KEY_DOWN : 292 nNewLine++; 293 break; 294 case KEY_LEFT : 295 296 if(nNewCol) 297 nNewCol--; 298 break; 299 case KEY_RIGHT : 300 nNewCol++; 301 break; 302 case KEY_RETURN : 303 if(IsMouseCaptured()) 304 ReleaseMouse(); 305 EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL ); 306 break; 307 } 308 //make sure that a table can initially be created 309 if(bInitialKeyInput) 310 { 311 bInitialKeyInput = sal_False; 312 if(!nNewLine) 313 nNewLine = 1; 314 if(!nNewCol) 315 nNewCol = 1; 316 } 317 UpdateSize_Impl( nNewCol, nNewLine); 318 } 319 } 320 else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey) 321 { 322 m_bMod1 = sal_True; 323 if(IsMouseCaptured()) 324 ReleaseMouse(); 325 EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL ); 326 } 327 328 if(!bHandled) 329 SfxPopupWindow::KeyInput(rKEvt); 330 331 } 332 // ----------------------------------------------------------------------- 333 334 void TableWindow::MouseButtonDown( const MouseEvent& rMEvt ) 335 { 336 SfxPopupWindow::MouseButtonDown( rMEvt ); 337 CaptureMouse(); 338 } 339 340 // ----------------------------------------------------------------------- 341 342 void TableWindow::MouseButtonUp( const MouseEvent& rMEvt ) 343 { 344 SfxPopupWindow::MouseButtonUp( rMEvt ); 345 ReleaseMouse(); 346 347 if ( IsInPopupMode() ) 348 EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL ); 349 } 350 351 // ----------------------------------------------------------------------- 352 353 void TableWindow::Paint( const Rectangle& ) 354 { 355 long i; 356 long nStart; 357 Size aSize = GetOutputSizePixel(); 358 359 SetLineColor(); 360 SetFillColor( aHighlightFillColor ); 361 DrawRect( Rectangle( 0, 0, nCol*nMX-1, nLine*nMY-1 ) ); 362 SetFillColor( aFillColor ); 363 DrawRect( Rectangle( nCol*nMX-1, 0, 364 aSize.Width(), aSize.Height()-nTextHeight+1 ) ); 365 DrawRect( Rectangle( 0, nLine*nMY-1, 366 aSize.Width(), aSize.Height()-nTextHeight+1 ) ); 367 368 SetLineColor( aHighlightLineColor ); 369 for ( i = 1; i < nCol; i++ ) 370 DrawLine( Point( i*nMX-1, 0 ), Point( i*nMX-1, nLine*nMY-1 ) ); 371 for ( i = 1; i < nLine; i++ ) 372 DrawLine( Point( 0, i*nMY-1 ), Point( nCol*nMX-1, i*nMY-1 ) ); 373 SetLineColor( aLineColor ); 374 for ( i = 1; i <= nWidth; i++ ) 375 { 376 if ( i < nCol ) 377 nStart = nLine*nMY-1; 378 else 379 nStart = 0; 380 DrawLine( Point( i*nMX-1, nStart ), Point( i*nMX-1, nHeight*nMY-1 ) ); 381 } 382 for ( i = 1; i <= nHeight; i++ ) 383 { 384 if ( i < nLine ) 385 nStart = nCol*nMX-1; 386 else 387 nStart = 0; 388 DrawLine( Point( nStart, i*nMY-1 ), Point( nWidth*nMX-1, i*nMY-1 ) ); 389 } 390 391 SetLineColor(); 392 String aText; 393 if ( nCol && nLine ) 394 { 395 aText += String::CreateFromInt32( nCol ); 396 aText.AppendAscii( " x " ); 397 aText += String::CreateFromInt32( nLine ); 398 if(GetId() == FN_SHOW_MULTIPLE_PAGES) 399 { 400 aText += ' '; 401 aText += String(SVX_RESSTR(RID_SVXSTR_PAGES)); 402 } 403 404 } 405 else 406 aText = Button::GetStandardText( BUTTON_CANCEL ); 407 Size aTextSize( GetTextWidth( aText ), GetTextHeight() ); 408 409 Rectangle aClearRect( 0, aSize.Height()-nTextHeight+2, (aSize.Width()), aSize.Height() ); 410 DrawRect( aClearRect ); 411 412 // #i95350# force RTL output 413 if( IsRTLEnabled() && nCol && nLine ) 414 aText.Insert(0x202D, 0); 415 DrawText( Point( (aSize.Width() - aTextSize.Width()) / 2, aSize.Height() - nTextHeight + 2 ), aText ); 416 417 SetLineColor( aLineColor ); 418 SetFillColor(); 419 DrawRect( Rectangle( Point(0,0), aSize ) ); 420 } 421 422 // ----------------------------------------------------------------------- 423 424 void TableWindow::PopupModeEnd() 425 { 426 if ( !IsPopupModeCanceled() && nCol && nLine ) 427 { 428 Window* pParent = rTbx.GetParent(); 429 sal_uInt16 nId = GetId(); 430 pParent->UserEvent(SVX_EVENT_COLUM_WINDOW_EXECUTE, reinterpret_cast<void*>(nId)); 431 432 Reference< XDispatchProvider > xDispatchProvider( mxFrame, UNO_QUERY ); 433 if ( xDispatchProvider.is() ) 434 { 435 com::sun::star::util::URL aTargetURL; 436 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( 437 rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), 438 UNO_QUERY ); 439 aTargetURL.Complete = maCommand; 440 xTrans->parseStrict( aTargetURL ); 441 Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, rtl::OUString(), 0 ); 442 if ( xDispatch.is() ) 443 { 444 Sequence< PropertyValue > aArgs( 2 ); 445 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Columns" )); 446 aArgs[0].Value = makeAny( sal_Int16( nCol )); 447 aArgs[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Rows" )); 448 aArgs[1].Value = makeAny( sal_Int16( nLine )); 449 450 xDispatch->dispatch( aTargetURL, aArgs ); 451 } 452 } 453 } 454 else if ( IsPopupModeCanceled() ) 455 ReleaseMouse(); 456 SfxPopupWindow::PopupModeEnd(); 457 } 458 459 // class ColumnsWindow --------------------------------------------------- 460 461 class ColumnsWindow : public SfxPopupWindow 462 { 463 private: 464 ::Color aLineColor; 465 ::Color aHighlightLineColor; 466 ::Color aFillColor; 467 ::Color aHighlightFillColor; 468 long nCol; 469 long nWidth; 470 long nMX; 471 long nTextHeight; 472 sal_Bool bInitialKeyInput; 473 sal_Bool m_bMod1; 474 ToolBox& rTbx; 475 Reference< XFrame > mxFrame; 476 ::rtl::OUString maCommand; 477 478 void UpdateSize_Impl( long nNewCol ); 479 public: 480 ColumnsWindow( sal_uInt16 nId, const ::rtl::OUString& rCmd, ToolBox& rParentTbx, const Reference< XFrame >& rFrame ); 481 482 void KeyInput( const KeyEvent& rKEvt ); 483 virtual void MouseMove( const MouseEvent& rMEvt ); 484 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 485 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 486 virtual void Paint( const Rectangle& ); 487 virtual void PopupModeEnd(); 488 virtual SfxPopupWindow* Clone() const; 489 490 sal_uInt16 GetColCount() const { return (sal_uInt16)nCol; } 491 }; 492 493 // ----------------------------------------------------------------------- 494 495 ColumnsWindow::ColumnsWindow( sal_uInt16 nId, const ::rtl::OUString& rCmd, ToolBox& rParentTbx, const Reference< XFrame >& rFrame ) : 496 SfxPopupWindow( nId, rFrame, WB_SYSTEMWINDOW ), 497 bInitialKeyInput(sal_True), 498 m_bMod1(sal_False), 499 rTbx(rParentTbx), 500 mxFrame(rFrame), 501 maCommand( rCmd ) 502 { 503 const StyleSettings& rStyles = Application::GetSettings().GetStyleSettings(); 504 svtools::ColorConfig aColorConfig; 505 aLineColor = ::Color( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor ); 506 aHighlightLineColor = rStyles.GetHighlightTextColor(); 507 aFillColor = rStyles.GetWindowColor(); 508 aHighlightFillColor = rStyles.GetHighlightColor(); 509 510 nTextHeight = GetTextHeight()+1; 511 SetBackground(); 512 Font aFont( GetFont() ); 513 aFont.SetColor( aLineColor ); 514 aFont.SetFillColor( aFillColor ); 515 aFont.SetTransparent( sal_False ); 516 SetFont( aFont ); 517 518 nCol = 0; 519 nWidth = 4; 520 521 Size aLogicSize = LogicToPixel( Size( 95, 155 ), MapMode( MAP_10TH_MM ) ); 522 nMX = aLogicSize.Width(); 523 SetOutputSizePixel( Size( nMX*nWidth-1, aLogicSize.Height()+nTextHeight ) ); 524 StartCascading(); 525 } 526 527 // ----------------------------------------------------------------------- 528 529 SfxPopupWindow* ColumnsWindow::Clone() const 530 { 531 return new ColumnsWindow( GetId(), maCommand, rTbx, mxFrame ); 532 } 533 534 // ----------------------------------------------------------------------- 535 536 void ColumnsWindow::MouseMove( const MouseEvent& rMEvt ) 537 { 538 SfxPopupWindow::MouseMove( rMEvt ); 539 Point aPos = rMEvt.GetPosPixel(); 540 Point aMousePos = aPos; 541 Point aWinPos = GetPosPixel(); 542 543 if ( rMEvt.IsEnterWindow() ) 544 CaptureMouse(); 545 else if ( aMousePos.X() < 0 || aMousePos.Y() < 0 ) 546 { 547 nCol = 0; 548 ReleaseMouse(); 549 Invalidate(); 550 return; 551 } 552 553 long nNewCol = 0; 554 if ( aPos.X() > 0 ) 555 nNewCol = aPos.X() / nMX + 1; 556 if ( aPos.Y() < 0 ) 557 nNewCol = 0; 558 if ( nNewCol > 20 ) 559 nNewCol = 20; 560 UpdateSize_Impl( nNewCol ); 561 } 562 /* -----------------------------21.05.2002 16:16------------------------------ 563 564 ---------------------------------------------------------------------------*/ 565 void ColumnsWindow::UpdateSize_Impl( long nNewCol ) 566 { 567 Size aWinSize = GetOutputSizePixel(); 568 long nMinCol = 0; 569 long nMaxCol = 0; 570 Point aWinPos;// = GetPosPixel(); 571 572 if ( nWidth <= nNewCol ) 573 { 574 Point aMaxPos = OutputToScreenPixel( GetDesktopRectPixel().BottomRight() ); 575 576 if ( nWidth <= nNewCol ) 577 { 578 nWidth = nNewCol; 579 nWidth++; 580 } 581 582 while ( nWidth > 0 && 583 (short)(aWinPos.X()+(nMX*nWidth-1)) >= aMaxPos.X()-3 ) 584 nWidth--; 585 586 if ( nNewCol > nWidth ) 587 nNewCol = nWidth; 588 589 Invalidate( Rectangle( 0, aWinSize.Height()-nTextHeight+2, 590 aWinSize.Width(), aWinSize.Height() ) ); 591 SetOutputSizePixel( Size( nMX*nWidth-1, aWinSize.Height() ) ); 592 } 593 594 595 if ( nNewCol != nCol ) 596 { 597 Invalidate( Rectangle( 0, aWinSize.Height()-nTextHeight+2, 598 aWinSize.Width(), aWinSize.Height() ) ); 599 600 if ( nNewCol < nCol ) 601 { 602 nMinCol = nNewCol; 603 nMaxCol = nCol; 604 } 605 else 606 { 607 nMinCol = nCol; 608 nMaxCol = nNewCol; 609 } 610 611 Invalidate( Rectangle( nMinCol*nMX-1, 0, 612 nMaxCol*nMX+1, aWinSize.Height()-nTextHeight+2 ) ); 613 nCol = nNewCol; 614 } 615 Update(); 616 } 617 // ----------------------------------------------------------------------- 618 619 void ColumnsWindow::MouseButtonDown( const MouseEvent& rMEvt ) 620 { 621 SfxPopupWindow::MouseButtonDown( rMEvt ); 622 CaptureMouse(); 623 } 624 /* -----------------------------21.05.2002 16:11------------------------------ 625 626 ---------------------------------------------------------------------------*/ 627 void ColumnsWindow::KeyInput( const KeyEvent& rKEvt ) 628 { 629 sal_Bool bHandled = sal_False; 630 sal_uInt16 nModifier = rKEvt.GetKeyCode().GetModifier(); 631 sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode(); 632 if(!nModifier) 633 { 634 if( KEY_LEFT == nKey || KEY_RIGHT == nKey || 635 KEY_RETURN == nKey ||KEY_ESCAPE == nKey || 636 KEY_UP == nKey) 637 { 638 bHandled = sal_True; 639 long nNewCol = nCol; 640 switch(nKey) 641 { 642 case KEY_LEFT : 643 if(nNewCol) 644 nNewCol--; 645 break; 646 case KEY_RIGHT : 647 nNewCol++; 648 break; 649 case KEY_RETURN : 650 if(IsMouseCaptured()) 651 ReleaseMouse(); 652 EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL ); 653 break; 654 case KEY_ESCAPE : 655 case KEY_UP : 656 EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL); 657 break; 658 } 659 //make sure that a table can initially be created 660 if(bInitialKeyInput) 661 { 662 bInitialKeyInput = sal_False; 663 if(!nNewCol) 664 nNewCol = 1; 665 } 666 UpdateSize_Impl( nNewCol ); 667 } 668 } 669 else if(KEY_MOD1 == nModifier && KEY_RETURN == nKey) 670 { 671 m_bMod1 = sal_True; 672 if(IsMouseCaptured()) 673 ReleaseMouse(); 674 EndPopupMode(FLOATWIN_POPUPMODEEND_CLOSEALL ); 675 } 676 if(!bHandled) 677 SfxPopupWindow::KeyInput(rKEvt); 678 } 679 680 // ----------------------------------------------------------------------- 681 682 void ColumnsWindow::MouseButtonUp( const MouseEvent& rMEvt ) 683 { 684 SfxPopupWindow::MouseButtonUp( rMEvt ); 685 ReleaseMouse(); 686 687 if ( IsInPopupMode() ) 688 EndPopupMode( FLOATWIN_POPUPMODEEND_CLOSEALL ); 689 } 690 691 // ----------------------------------------------------------------------- 692 693 void ColumnsWindow::Paint( const Rectangle& ) 694 { 695 long i; 696 long j; 697 long nLineWidth; 698 Size aSize = GetOutputSizePixel(); 699 700 for ( i = 0; i < nWidth; i++ ) 701 { 702 if ( i < nCol ) 703 { 704 SetLineColor( aHighlightLineColor ); 705 SetFillColor( aHighlightFillColor ); 706 } 707 else 708 { 709 SetLineColor( aLineColor ); 710 SetFillColor( aFillColor ); 711 } 712 713 DrawRect( Rectangle( i*nMX-1, -1, 714 i*nMX+nMX, aSize.Height()-nTextHeight+1 ) ); 715 716 j = 4; 717 while ( j < aSize.Height()-nTextHeight-4 ) 718 { 719 if ( !(j % 16) ) 720 nLineWidth = 10; 721 else 722 nLineWidth = 4; 723 DrawLine( Point( i*nMX+4, j ), Point( i*nMX+nMX-nLineWidth-4, j ) ); 724 j += 4; 725 } 726 } 727 728 SetLineColor(); 729 SetFillColor( aFillColor ); 730 String aText; 731 if ( nCol ) 732 aText = String( String::CreateFromInt32(nCol) ); 733 else 734 aText = Button::GetStandardText( BUTTON_CANCEL ); 735 Size aTextSize(GetTextWidth( aText ), GetTextHeight()); 736 DrawText( Point( ( aSize.Width() - aTextSize.Width() ) / 2, aSize.Height() - nTextHeight + 2 ), aText ); 737 738 DrawRect( Rectangle( 0, aSize.Height()-nTextHeight+2, (aSize.Width()-aTextSize.Width())/2-1, aSize.Height() ) ); 739 DrawRect( Rectangle( (aSize.Width()-aTextSize.Width())/2+aTextSize.Width(), aSize.Height()-nTextHeight+2, aSize.Width(), aSize.Height() ) ); 740 741 SetLineColor( aLineColor ); 742 SetFillColor(); 743 DrawRect( Rectangle( Point(0,0), aSize ) ); 744 } 745 746 // ----------------------------------------------------------------------- 747 748 void ColumnsWindow::PopupModeEnd() 749 { 750 if ( !IsPopupModeCanceled() && nCol ) 751 { 752 sal_uInt16 nId = GetId(); 753 Window* pParent = rTbx.GetParent(); 754 pParent->UserEvent(SVX_EVENT_COLUM_WINDOW_EXECUTE, reinterpret_cast<void*>(nId)); 755 756 Sequence< PropertyValue > aArgs( 2 ); 757 aArgs[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Columns" )); 758 aArgs[0].Value = makeAny( sal_Int16( nCol )); 759 aArgs[1].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Modifier" )); 760 aArgs[1].Value = makeAny( sal_Int16( m_bMod1 ? KEY_MOD1 : 0 )); 761 762 SfxToolBoxControl::Dispatch( Reference< XDispatchProvider >( mxFrame->getController(), UNO_QUERY ), 763 maCommand, 764 aArgs ); 765 } 766 else if ( IsPopupModeCanceled() ) 767 ReleaseMouse(); 768 SfxPopupWindow::PopupModeEnd(); 769 } 770 771 // class SvxTableToolBoxControl ------------------------------------------ 772 773 SvxTableToolBoxControl::SvxTableToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 774 SfxToolBoxControl( nSlotId, nId, rTbx ), 775 bEnabled( sal_True ) 776 { 777 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 778 rTbx.Invalidate(); 779 } 780 781 // ----------------------------------------------------------------------- 782 783 SvxTableToolBoxControl::~SvxTableToolBoxControl() 784 { 785 } 786 787 // ----------------------------------------------------------------------- 788 789 SfxPopupWindowType SvxTableToolBoxControl::GetPopupWindowType() const 790 { 791 return SFX_POPUPWINDOW_ONTIMEOUTANDMOVE; 792 } 793 794 // ----------------------------------------------------------------------- 795 796 SfxPopupWindow* SvxTableToolBoxControl::CreatePopupWindow() 797 { 798 if ( bEnabled ) 799 { 800 ToolBox& rTbx = GetToolBox(); 801 TableWindow* pWin = new TableWindow( GetSlotId(), m_aCommandURL, rTbx, m_xFrame ); 802 pWin->StartPopupMode( &rTbx, FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_NOKEYCLOSE ); 803 SetPopupWindow( pWin ); 804 return pWin; 805 } 806 return 0; 807 } 808 809 // ----------------------------------------------------------------------- 810 811 SfxPopupWindow* SvxTableToolBoxControl::CreatePopupWindowCascading() 812 { 813 if ( bEnabled ) 814 return new TableWindow( GetSlotId(), m_aCommandURL, GetToolBox(), m_xFrame ); 815 return 0; 816 } 817 818 // ----------------------------------------------------------------------- 819 820 void SvxTableToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState ) 821 { 822 if ( pState && pState->ISA(SfxUInt16Item) ) 823 { 824 sal_Int16 nValue = static_cast< const SfxUInt16Item* >( pState )->GetValue(); 825 bEnabled = ( nValue != 0 ); 826 } 827 else 828 bEnabled = SFX_ITEM_DISABLED != eState; 829 830 sal_uInt16 nId = GetId(); 831 ToolBox& rTbx = GetToolBox(); 832 833 rTbx.EnableItem( nId, SFX_ITEM_DISABLED != eState ); 834 rTbx.SetItemState( nId, 835 ( SFX_ITEM_DONTCARE == eState ) ? STATE_DONTKNOW : STATE_NOCHECK ); 836 } 837 838 // class SvxColumnsToolBoxControl ------------------------------------------ 839 840 SvxColumnsToolBoxControl::SvxColumnsToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) : 841 SfxToolBoxControl( nSlotId, nId, rTbx ) 842 { 843 rTbx.SetItemBits( nId, TIB_DROPDOWN | rTbx.GetItemBits( nId ) ); 844 rTbx.Invalidate(); 845 } 846 847 // ----------------------------------------------------------------------- 848 849 SvxColumnsToolBoxControl::~SvxColumnsToolBoxControl() 850 { 851 } 852 853 // ----------------------------------------------------------------------- 854 855 SfxPopupWindowType SvxColumnsToolBoxControl::GetPopupWindowType() const 856 { 857 return SFX_POPUPWINDOW_ONTIMEOUTANDMOVE; 858 } 859 860 // ----------------------------------------------------------------------- 861 862 SfxPopupWindow* SvxColumnsToolBoxControl::CreatePopupWindow() 863 { 864 ColumnsWindow* pWin = 0; 865 if(bEnabled) 866 { 867 pWin = new ColumnsWindow( GetSlotId(), m_aCommandURL, GetToolBox(), m_xFrame ); 868 pWin->StartPopupMode( &GetToolBox(), 869 FLOATWIN_POPUPMODE_GRABFOCUS|FLOATWIN_POPUPMODE_NOKEYCLOSE ); 870 SetPopupWindow( pWin ); 871 } 872 return pWin; 873 } 874 875 // ----------------------------------------------------------------------- 876 877 SfxPopupWindow* SvxColumnsToolBoxControl::CreatePopupWindowCascading() 878 { 879 ColumnsWindow* pWin = 0; 880 if(bEnabled) 881 { 882 pWin = new ColumnsWindow( GetSlotId(), m_aCommandURL, GetToolBox(), m_xFrame ); 883 } 884 return pWin; 885 } 886 /* -----------------18.11.99 16:38------------------- 887 888 --------------------------------------------------*/ 889 void SvxColumnsToolBoxControl::StateChanged( sal_uInt16 nSID, 890 SfxItemState eState, 891 const SfxPoolItem* pState ) 892 { 893 bEnabled = SFX_ITEM_DISABLED != eState; 894 SfxToolBoxControl::StateChanged(nSID, eState, pState ); 895 } 896