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_formula.hxx" 26 27 //---------------------------------------------------------------------------- 28 #include <vcl/sound.hxx> 29 #include <vcl/svapp.hxx> 30 #include <vcl/scrbar.hxx> 31 32 #include "formula/funcutl.hxx" 33 #include "formula/IControlReferenceHandler.hxx" 34 #include "ControlHelper.hxx" 35 #include "ModuleHelper.hxx" 36 #include "ForResId.hrc" 37 #include "com/sun/star/accessibility/AccessibleRole.hpp" 38 39 40 namespace formula 41 { 42 //============================================================================ 43 // class ValWnd 44 //---------------------------------------------------------------------------- 45 46 ValWnd::ValWnd( Window* pParent, const ResId& rId ) : Window( pParent, rId ) 47 { 48 Font aFnt( GetFont() ); 49 aFnt.SetTransparent( sal_True ); 50 aFnt.SetWeight( WEIGHT_LIGHT ); 51 if ( pParent->IsBackground() ) 52 { 53 Wallpaper aBack = pParent->GetBackground(); 54 SetFillColor( aBack.GetColor() ); 55 SetBackground( aBack ); 56 aFnt.SetFillColor( aBack.GetColor() ); 57 } 58 else 59 { 60 SetFillColor(); 61 SetBackground(); 62 } 63 SetFont( aFnt ); 64 SetLineColor(); 65 66 Size aSzWnd = GetOutputSizePixel(); 67 long nHeight = GetTextHeight(); 68 long nDiff = aSzWnd.Height()-nHeight; 69 70 aRectOut = Rectangle( Point( 1, ( nDiff<2 ) ? 1 : nDiff/2), 71 Size ( aSzWnd.Width()-2, nHeight ) ); 72 SetClipRegion( Region( aRectOut ) ); 73 SetAccessibleRole( ::com::sun::star::accessibility::AccessibleRole::LABEL ); 74 } 75 76 //---------------------------------------------------------------------------- 77 78 void __EXPORT ValWnd::Paint( const Rectangle& ) 79 { 80 DrawText( aRectOut.TopLeft(), aStrValue ); 81 } 82 83 //---------------------------------------------------------------------------- 84 85 void ValWnd::SetValue( const String& rStrVal ) 86 { 87 if ( aStrValue != rStrVal ) 88 { 89 aStrValue = rStrVal; 90 DrawRect( aRectOut ); // alten Text loeschen 91 Paint( aRectOut ); // und neu malen 92 } 93 } 94 95 //============================================================================ 96 // class ArgEdit 97 //---------------------------------------------------------------------------- 98 99 ArgEdit::ArgEdit( Window* pParent, const ResId& rResId ) 100 : RefEdit( pParent, rResId ), 101 pEdPrev ( NULL ), 102 pEdNext ( NULL ), 103 pSlider ( NULL ), 104 nArgs ( 0 ) 105 { 106 } 107 108 //---------------------------------------------------------------------------- 109 110 void ArgEdit::Init( ArgEdit* pPrevEdit, ArgEdit* pNextEdit, 111 ScrollBar& rArgSlider, sal_uInt16 nArgCount ) 112 { 113 pEdPrev = pPrevEdit; 114 pEdNext = pNextEdit; 115 pSlider = &rArgSlider; 116 nArgs = nArgCount; 117 } 118 119 //---------------------------------------------------------------------------- 120 121 // Cursorsteuerung fuer EditFelder im Argument-Dialog 122 123 void __EXPORT ArgEdit::KeyInput( const KeyEvent& rKEvt ) 124 { 125 KeyCode aCode = rKEvt.GetKeyCode(); 126 sal_Bool bUp = (aCode.GetCode() == KEY_UP); 127 sal_Bool bDown = (aCode.GetCode() == KEY_DOWN); 128 ArgEdit* pEd = NULL; 129 130 if ( pSlider 131 && ( !aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() ) 132 && ( bUp || bDown ) ) 133 { 134 if ( nArgs > 1 ) 135 { 136 long nThumb = pSlider->GetThumbPos(); 137 sal_Bool bDoScroll = sal_False; 138 sal_Bool bChangeFocus = sal_False; 139 140 if ( bDown ) 141 { 142 if ( nArgs > 4 ) 143 { 144 if ( !pEdNext ) 145 { 146 nThumb++; 147 bDoScroll = ( nThumb+3 < (long)nArgs ); 148 } 149 else 150 { 151 pEd = pEdNext; 152 bChangeFocus = sal_True; 153 } 154 } 155 else if ( pEdNext ) 156 { 157 pEd = pEdNext; 158 bChangeFocus = sal_True; 159 } 160 } 161 else // if ( bUp ) 162 { 163 if ( nArgs > 4 ) 164 { 165 if ( !pEdPrev ) 166 { 167 nThumb--; 168 bDoScroll = ( nThumb >= 0 ); 169 } 170 else 171 { 172 pEd = pEdPrev; 173 bChangeFocus = sal_True; 174 } 175 } 176 else if ( pEdPrev ) 177 { 178 pEd = pEdPrev; 179 bChangeFocus = sal_True; 180 } 181 } 182 183 if ( bDoScroll ) 184 { 185 pSlider->SetThumbPos( nThumb ); 186 ((Link&)pSlider->GetEndScrollHdl()).Call( pSlider ); 187 } 188 else if ( bChangeFocus ) 189 { 190 pEd->GrabFocus(); 191 } 192 else 193 Sound::Beep(); 194 } 195 else 196 Sound::Beep(); 197 } 198 else 199 RefEdit::KeyInput( rKEvt ); 200 } 201 202 203 204 205 /************************************************************************* 206 #* Member: ArgInput Datum:13.01.97 207 #*------------------------------------------------------------------------ 208 #* 209 #* Klasse: ArgInput 210 #* 211 #* Funktion: Konstruktor der Klasse ArgInput 212 #* 213 #* Input: --- 214 #* 215 #* Output: --- 216 #* 217 #************************************************************************/ 218 219 ArgInput::ArgInput() 220 { 221 pFtArg=NULL; 222 pBtnFx=NULL; 223 pEdArg=NULL; 224 pRefBtn=NULL; 225 } 226 227 /************************************************************************* 228 #* Member: InitArgInput Datum:13.01.97 229 #*------------------------------------------------------------------------ 230 #* 231 #* Klasse: ArgInput 232 #* 233 #* Funktion: Initialisiert die Pointer der Klasse 234 #* 235 #* Input: --- 236 #* 237 #* Output: --- 238 #* 239 #************************************************************************/ 240 241 void ArgInput::InitArgInput(FixedText* pftArg, 242 ImageButton* pbtnFx, 243 ArgEdit* pedArg, 244 RefButton* prefBtn) 245 { 246 pFtArg =pftArg; 247 pBtnFx =pbtnFx; 248 pEdArg =pedArg; 249 pRefBtn=prefBtn; 250 251 if(pBtnFx!=NULL) 252 { 253 pBtnFx->SetClickHdl ( LINK( this, ArgInput, FxBtnClickHdl ) ); 254 pBtnFx->SetGetFocusHdl( LINK( this, ArgInput, FxBtnFocusHdl ) ); 255 } 256 if(pRefBtn!=NULL) 257 { 258 pRefBtn->SetClickHdl ( LINK( this, ArgInput, RefBtnClickHdl ) ); 259 pRefBtn->SetGetFocusHdl( LINK( this, ArgInput, RefBtnFocusHdl ) ); 260 } 261 if(pEdArg!=NULL) 262 { 263 pEdArg->SetGetFocusHdl ( LINK( this, ArgInput, EdFocusHdl ) ); 264 pEdArg->SetModifyHdl ( LINK( this, ArgInput, EdModifyHdl ) ); 265 } 266 267 } 268 269 /************************************************************************* 270 #* Member: SetArgName Datum:13.01.97 271 #*------------------------------------------------------------------------ 272 #* 273 #* Klasse: ArgInput 274 #* 275 #* Funktion: Setzt den Namen fuer das Argument 276 #* 277 #* Input: String 278 #* 279 #* Output: --- 280 #* 281 #************************************************************************/ 282 void ArgInput::SetArgName(const String &aArg) 283 { 284 if(pFtArg !=NULL) pFtArg->SetText(aArg ); 285 } 286 287 /************************************************************************* 288 #* Member: GetArgName Datum:06.02.97 289 #*------------------------------------------------------------------------ 290 #* 291 #* Klasse: ArgInput 292 #* 293 #* Funktion: Liefert den Namen fuer das Argument zurueck 294 #* 295 #* Input: String 296 #* 297 #* Output: --- 298 #* 299 #************************************************************************/ 300 String ArgInput::GetArgName() 301 { 302 String aPrivArgName; 303 if(pFtArg !=NULL) 304 aPrivArgName=pFtArg->GetText(); 305 306 return aPrivArgName; 307 } 308 309 310 /************************************************************************* 311 #* Member: SetArgName Datum:13.01.97 312 #*------------------------------------------------------------------------ 313 #* 314 #* Klasse: ArgInput 315 #* 316 #* Funktion: Setzt den Namen fuer das Argument 317 #* 318 #* Input: String 319 #* 320 #* Output: --- 321 #* 322 #************************************************************************/ 323 void ArgInput::SetArgNameFont (const Font &aFont) 324 { 325 if(pFtArg !=NULL) pFtArg->SetFont(aFont); 326 } 327 328 /************************************************************************* 329 #* Member: SetArgSelection Datum:13.01.97 330 #*------------------------------------------------------------------------ 331 #* 332 #* Klasse: ArgInput 333 #* 334 #* Funktion: Stellt die Selection fuer die EditBox ein. 335 #* 336 #* Input: String 337 #* 338 #* Output: --- 339 #* 340 #************************************************************************/ 341 void ArgInput::SetArgSelection (const Selection& rSel ) 342 { 343 if(pEdArg !=NULL) pEdArg ->SetSelection(rSel ); 344 } 345 346 /************************************************************************* 347 #* Member: SetArgSelection Datum:13.01.97 348 #*------------------------------------------------------------------------ 349 #* 350 #* Klasse: ArgInput 351 #* 352 #* Funktion: Liefert die Selection fuer die EditBox zurueck. 353 #* 354 #* Input: String 355 #* 356 #* Output: --- 357 #* 358 #************************************************************************/ 359 Selection ArgInput::GetArgSelection () 360 { 361 Selection aSel; 362 if(pEdArg !=NULL) aSel=pEdArg ->GetSelection(); 363 return aSel; 364 } 365 366 /************************************************************************* 367 #* Member: SetArgSelection Datum:13.01.97 368 #*------------------------------------------------------------------------ 369 #* 370 #* Klasse: ArgInput 371 #* 372 #* Funktion: Ersetzt die Selection in der EditBox. 373 #* 374 #* Input: String 375 #* 376 #* Output: --- 377 #* 378 #************************************************************************/ 379 void ArgInput::ReplaceSelOfArg(const String& rStr ) 380 { 381 if(pEdArg !=NULL) pEdArg ->ReplaceSelected(rStr ); 382 } 383 384 385 386 /************************************************************************* 387 #* Member: SetArgVal Datum:13.01.97 388 #*------------------------------------------------------------------------ 389 #* 390 #* Klasse: ArgInput 391 #* 392 #* Funktion: Setzt den Wert fuer das Argument 393 #* 394 #* Input: String 395 #* 396 #* Output: --- 397 #* 398 #************************************************************************/ 399 void ArgInput::SetArgVal(const String &aVal) 400 { 401 if(pEdArg !=NULL) 402 { 403 pEdArg ->SetRefString(aVal ); 404 } 405 } 406 407 /************************************************************************* 408 #* Member: SetArgName Datum:13.01.97 409 #*------------------------------------------------------------------------ 410 #* 411 #* Klasse: ArgInput 412 #* 413 #* Funktion: Liefert den Wert fuer das Argument 414 #* 415 #* Input: --- 416 #* 417 #* Output: String 418 #* 419 #************************************************************************/ 420 String ArgInput::GetArgVal() 421 { 422 String aResult; 423 if(pEdArg!=NULL) 424 { 425 aResult=pEdArg->GetText(); 426 } 427 return aResult; 428 } 429 430 /************************************************************************* 431 #* Member: SetArgName Datum:13.01.97 432 #*------------------------------------------------------------------------ 433 #* 434 #* Klasse: ArgInput 435 #* 436 #* Funktion: Versteckt die Controls 437 #* 438 #* Input: --- 439 #* 440 #* Output: --- 441 #* 442 #************************************************************************/ 443 void ArgInput::Hide() 444 { 445 if ( pFtArg && pBtnFx && pEdArg && pRefBtn) 446 { 447 pFtArg->Hide(); 448 pBtnFx->Hide(); 449 pEdArg->Hide(); 450 pRefBtn->Hide(); 451 } 452 } 453 454 /************************************************************************* 455 #* Member: SetArgName Datum:13.01.97 456 #*------------------------------------------------------------------------ 457 #* 458 #* Klasse: ArgInput 459 #* 460 #* Funktion: Zaubert die Controls wieder hervor. 461 #* 462 #* Input: --- 463 #* 464 #* Output: --- 465 #* 466 #************************************************************************/ 467 void ArgInput::Show() 468 { 469 if ( pFtArg && pBtnFx && pEdArg && pRefBtn) 470 { 471 pFtArg->Show(); 472 pBtnFx->Show(); 473 pEdArg->Show(); 474 pRefBtn->Show(); 475 } 476 } 477 void ArgInput::UpdateAccessibleNames() 478 { 479 String aArgName = String::CreateFromAscii(":"); 480 aArgName += pFtArg->GetText(); 481 482 String aName = pBtnFx->GetQuickHelpText(); 483 aName += aArgName; 484 pBtnFx->SetAccessibleName(aName); 485 486 aName = pRefBtn->GetQuickHelpText(); 487 aName += aArgName; 488 pRefBtn->SetAccessibleName(aName); 489 } 490 491 /************************************************************************* 492 #* Member: FxClick Datum:13.01.97 493 #*------------------------------------------------------------------------ 494 #* 495 #* Klasse: ArgInput 496 #* 497 #* Funktion: Gibt den Event weiter. 498 #* 499 #* Input: --- 500 #* 501 #* Output: --- 502 #* 503 #************************************************************************/ 504 void ArgInput::FxClick() 505 { 506 aFxClickLink.Call(this); 507 } 508 509 /************************************************************************* 510 #* Member: RefClick Datum:13.01.97 511 #*------------------------------------------------------------------------ 512 #* 513 #* Klasse: ArgInput 514 #* 515 #* Funktion: Gibt den Event weiter. 516 #* 517 #* Input: --- 518 #* 519 #* Output: --- 520 #* 521 #************************************************************************/ 522 void ArgInput::RefClick() 523 { 524 aRefClickLink.Call(this); 525 } 526 527 /************************************************************************* 528 #* Member: FxFocus Datum:13.01.97 529 #*------------------------------------------------------------------------ 530 #* 531 #* Klasse: ArgInput 532 #* 533 #* Funktion: Gibt den Event weiter. 534 #* 535 #* Input: --- 536 #* 537 #* Output: --- 538 #* 539 #************************************************************************/ 540 void ArgInput::FxFocus() 541 { 542 aFxFocusLink.Call(this); 543 } 544 545 /************************************************************************* 546 #* Member: RefFocus Datum:13.01.97 547 #*------------------------------------------------------------------------ 548 #* 549 #* Klasse: ArgInput 550 #* 551 #* Funktion: Gibt den Event weiter. 552 #* 553 #* Input: --- 554 #* 555 #* Output: --- 556 #* 557 #************************************************************************/ 558 void ArgInput::RefFocus() 559 { 560 aRefFocusLink.Call(this); 561 } 562 563 /************************************************************************* 564 #* Member: EdFocus Datum:13.01.97 565 #*------------------------------------------------------------------------ 566 #* 567 #* Klasse: ArgInput 568 #* 569 #* Funktion: Gibt den Event weiter. 570 #* 571 #* Input: --- 572 #* 573 #* Output: --- 574 #* 575 #************************************************************************/ 576 void ArgInput::EdFocus() 577 { 578 aEdFocusLink.Call(this); 579 } 580 581 /************************************************************************* 582 #* Member: EdModify Datum:13.01.97 583 #*------------------------------------------------------------------------ 584 #* 585 #* Klasse: ArgInput 586 #* 587 #* Funktion: Gibt den Event weiter. 588 #* 589 #* Input: --- 590 #* 591 #* Output: --- 592 #* 593 #************************************************************************/ 594 void ArgInput::EdModify() 595 { 596 aEdModifyLink.Call(this); 597 } 598 599 /************************************************************************* 600 #* Handle: FxBtnHdl Datum:13.01.97 601 #*------------------------------------------------------------------------ 602 #* 603 #* Klasse: ArgInput 604 #* 605 #* Funktion: Handle fuer Fx-Button Click-Event. 606 #* 607 #* Input: --- 608 #* 609 #* Output: --- 610 #* 611 #************************************************************************/ 612 IMPL_LINK( ArgInput, FxBtnClickHdl, ImageButton*, pBtn ) 613 { 614 if(pBtn==pBtnFx) FxClick(); 615 616 return 0; 617 } 618 619 /************************************************************************* 620 #* Handle: RefBtnClickHdl Datum:13.01.97 621 #*------------------------------------------------------------------------ 622 #* 623 #* Klasse: ArgInput 624 #* 625 #* Funktion: Handle fuer Fx-Button Click-Event. 626 #* 627 #* Input: --- 628 #* 629 #* Output: --- 630 #* 631 #************************************************************************/ 632 IMPL_LINK( ArgInput, RefBtnClickHdl,RefButton*, pBtn ) 633 { 634 if(pRefBtn==pBtn) RefClick(); 635 636 return 0; 637 } 638 639 /************************************************************************* 640 #* Handle: FxBtnFocusHdl Datum:13.01.97 641 #*------------------------------------------------------------------------ 642 #* 643 #* Klasse: ArgInput 644 #* 645 #* Funktion: Handle fuer Fx-Button Focus-Event. 646 #* 647 #* Input: --- 648 #* 649 #* Output: --- 650 #* 651 #************************************************************************/ 652 IMPL_LINK( ArgInput, FxBtnFocusHdl, ImageButton*, pBtn ) 653 { 654 if(pBtn==pBtnFx) FxFocus(); 655 656 return 0; 657 } 658 659 /************************************************************************* 660 #* Handle: RefBtnFocusHdl Datum:13.01.97 661 #*------------------------------------------------------------------------ 662 #* 663 #* Klasse: ArgInput 664 #* 665 #* Funktion: Handle fuer Fx-Button Focus-Event. 666 #* 667 #* Input: --- 668 #* 669 #* Output: --- 670 #* 671 #************************************************************************/ 672 IMPL_LINK( ArgInput, RefBtnFocusHdl,RefButton*, pBtn ) 673 { 674 if(pRefBtn==pBtn) RefFocus(); 675 676 return 0; 677 } 678 679 /************************************************************************* 680 #* Handle: EdFocusHdl Datum:13.01.97 681 #*------------------------------------------------------------------------ 682 #* 683 #* Klasse: ArgInput 684 #* 685 #* Funktion: Handle fuer Fx-Button Focus-Event. 686 #* 687 #* Input: --- 688 #* 689 #* Output: --- 690 #* 691 #************************************************************************/ 692 IMPL_LINK( ArgInput, EdFocusHdl, ArgEdit*, pEd ) 693 { 694 if(pEd==pEdArg) EdFocus(); 695 696 return 0; 697 } 698 699 /************************************************************************* 700 #* Handle: RefBtnClickHdl Datum:13.01.97 701 #*------------------------------------------------------------------------ 702 #* 703 #* Klasse: ArgInput 704 #* 705 #* Funktion: Handle fuer Fx-Button Focus-Event. 706 #* 707 #* Input: --- 708 #* 709 #* Output: --- 710 #* 711 #************************************************************************/ 712 IMPL_LINK( ArgInput, EdModifyHdl,ArgEdit*, pEd ) 713 { 714 if(pEd==pEdArg) EdModify(); 715 716 return 0; 717 } 718 719 /************************************************************************* 720 #* Member: EditBox Datum:20.01.97 721 #*------------------------------------------------------------------------ 722 #* 723 #* Klasse: EditBox 724 #* 725 #* Funktion: Konstruktor der Klasse ArgInput 726 #* 727 #* Input: Parent, Window-Style 728 #* 729 #* Output: --- 730 #* 731 #************************************************************************/ 732 EditBox::EditBox( Window* pParent,WinBits nWinStyle) 733 :Control(pParent,nWinStyle|WB_DIALOGCONTROL) 734 { 735 pMEdit=new MultiLineEdit(this,WB_LEFT | WB_VSCROLL | (nWinStyle & WB_TABSTOP) | 736 WB_NOBORDER | WB_NOHIDESELECTION | WB_IGNORETAB); 737 738 pMEdit->Show(); 739 aOldSel=pMEdit->GetSelection(); 740 } 741 742 /************************************************************************* 743 #* Member: EditBox Datum:20.01.97 744 #*------------------------------------------------------------------------ 745 #* 746 #* Klasse: EditBox 747 #* 748 #* Funktion: Konstruktor der Klasse ArgInput 749 #* 750 #* Input: Parent, Resource 751 #* 752 #* Output: --- 753 #* 754 #************************************************************************/ 755 EditBox::EditBox( Window* pParent, const ResId& rResId ) 756 :Control(pParent,rResId), 757 bMouseFlag(sal_False) 758 { 759 WinBits nStyle=GetStyle(); 760 SetStyle( nStyle| WB_DIALOGCONTROL); 761 762 pMEdit=new MultiLineEdit(this,WB_LEFT | WB_VSCROLL | (nStyle & WB_TABSTOP) | 763 WB_NOBORDER | WB_NOHIDESELECTION | WB_IGNORETAB); 764 pMEdit->Show(); 765 aOldSel=pMEdit->GetSelection(); 766 Resize(); 767 WinBits nWinStyle=GetStyle() | WB_DIALOGCONTROL; 768 SetStyle(nWinStyle); 769 770 // #105582# the HelpId from the resource must be set for the MultiLineEdit, 771 // not for the control that contains it. 772 pMEdit->SetHelpId( GetHelpId() ); 773 SetHelpId( "" ); 774 } 775 776 EditBox::~EditBox() 777 { 778 MultiLineEdit* pTheEdit=pMEdit; 779 pMEdit->Disable(); 780 pMEdit=NULL; 781 delete pTheEdit; 782 } 783 /************************************************************************* 784 #* Member: EditBox Datum:20.01.97 785 #*------------------------------------------------------------------------ 786 #* 787 #* Klasse: EditBox 788 #* 789 #* Funktion: Wenn sich die Selektion geaendert hat, so wird 790 #* diese Funktion aufgerufen. 791 #* 792 #* Input: --- 793 #* 794 #* Output: --- 795 #* 796 #************************************************************************/ 797 void EditBox::SelectionChanged() 798 { 799 aSelChangedLink.Call(this); 800 } 801 802 /************************************************************************* 803 #* Member: EditBox Datum:20.05.98 804 #*------------------------------------------------------------------------ 805 #* 806 #* Klasse: EditBox 807 #* 808 #* Funktion: Wenn sich die Groesse geaendert hat, so muss 809 #* auch der MultiLineEdit angepasst werden.. 810 #* 811 #* Input: --- 812 #* 813 #* Output: --- 814 #* 815 #************************************************************************/ 816 void EditBox::Resize() 817 { 818 Size aSize=GetOutputSizePixel(); 819 if(pMEdit!=NULL) pMEdit->SetOutputSizePixel(aSize); 820 } 821 822 /************************************************************************* 823 #* Member: GetFocus Datum:26.05.98 824 #*------------------------------------------------------------------------ 825 #* 826 #* Klasse: EditBox 827 #* 828 #* Funktion: Wenn der Control aktiviert wird, so wird 829 #* die Selection aufgehoben und der Cursor ans 830 #* Ende gesetzt. 831 #* 832 #* Input: --- 833 #* 834 #* Output: --- 835 #* 836 #************************************************************************/ 837 void EditBox::GetFocus() 838 { 839 if(pMEdit!=NULL) 840 { 841 pMEdit->GrabFocus(); 842 } 843 } 844 845 846 847 /************************************************************************* 848 #* Member: EditBox Datum:20.01.97 849 #*------------------------------------------------------------------------ 850 #* 851 #* Klasse: EditBox 852 #* 853 #* Funktion: Wenn ein Event ausgeloest wird, so wird diese Routine 854 #* zuerst aufgerufen und ein PostUserEvent verschickt. 855 #* 856 #* Input: Notify-Event 857 #* 858 #* Output: --- 859 #* 860 #************************************************************************/ 861 long EditBox::PreNotify( NotifyEvent& rNEvt ) 862 { 863 long nResult=sal_True; 864 865 if(pMEdit==NULL) return nResult; 866 867 sal_uInt16 nSwitch=rNEvt.GetType(); 868 if(nSwitch==EVENT_KEYINPUT)// || nSwitch==EVENT_KEYUP) 869 { 870 const KeyCode& aKeyCode=rNEvt.GetKeyEvent()->GetKeyCode(); 871 sal_uInt16 nKey=aKeyCode.GetCode(); 872 if( (nKey==KEY_RETURN && !aKeyCode.IsShift()) || nKey==KEY_TAB ) 873 { 874 nResult=GetParent()->Notify(rNEvt); 875 } 876 else 877 { 878 nResult=Control::PreNotify(rNEvt); 879 Application::PostUserEvent( LINK( this, EditBox, ChangedHdl ) ); 880 } 881 882 } 883 else 884 { 885 nResult=Control::PreNotify(rNEvt); 886 887 if(nSwitch==EVENT_MOUSEBUTTONDOWN || nSwitch==EVENT_MOUSEBUTTONUP) 888 { 889 bMouseFlag=sal_True; 890 Application::PostUserEvent( LINK( this, EditBox, ChangedHdl ) ); 891 } 892 } 893 return nResult; 894 } 895 896 /************************************************************************* 897 #* Member: EditBox Datum:21.01.97 898 #*------------------------------------------------------------------------ 899 #* 900 #* Klasse: EditBox 901 #* 902 #* Funktion: Wenn ein Event ausgeloest wurde, so wird diese Routine 903 #* zuerst aufgerufen. 904 #* 905 #* Input: Key-Event 906 #* 907 #* Output: --- 908 #* 909 #************************************************************************/ 910 IMPL_LINK( EditBox, ChangedHdl, EditBox*, EMPTYARG ) 911 { 912 if(pMEdit!=NULL) 913 { 914 Selection aNewSel=pMEdit->GetSelection(); 915 916 if(aNewSel.Min()!=aOldSel.Min() || aNewSel.Max()!=aOldSel.Max()) 917 { 918 SelectionChanged(); 919 aOldSel=aNewSel; 920 } 921 } 922 return 0; 923 } 924 925 void EditBox::UpdateOldSel() 926 { 927 // if selection is set for editing a function, store it as aOldSel, 928 // so SelectionChanged isn't called in the next ChangedHdl call 929 930 if (pMEdit) 931 aOldSel = pMEdit->GetSelection(); 932 } 933 //---------------------------------------------------------------------------- 934 935 //============================================================================ 936 // class RefEdit 937 //---------------------------------------------------------------------------- 938 939 #define SC_ENABLE_TIME 100 940 941 RefEdit::RefEdit( Window* _pParent,IControlReferenceHandler* pParent, const ResId& rResId ) : 942 Edit( _pParent, rResId ), 943 pAnyRefDlg( pParent ), 944 bSilentFocus( sal_False ) 945 { 946 aTimer.SetTimeoutHdl( LINK( this, RefEdit, UpdateHdl ) ); 947 aTimer.SetTimeout( SC_ENABLE_TIME ); 948 } 949 950 RefEdit::RefEdit( Window* pParent, const ResId& rResId ) : 951 Edit( pParent, rResId ), 952 pAnyRefDlg( NULL ), 953 bSilentFocus( sal_False ) 954 { 955 } 956 957 RefEdit::~RefEdit() 958 { 959 aTimer.SetTimeoutHdl( Link() ); 960 aTimer.Stop(); 961 } 962 963 void RefEdit::SetRefString( const XubString& rStr ) 964 { 965 Edit::SetText( rStr ); 966 } 967 968 void RefEdit::SetText( const XubString& rStr ) 969 { 970 Edit::SetText( rStr ); 971 UpdateHdl( &aTimer ); 972 } 973 974 void RefEdit::StartUpdateData() 975 { 976 aTimer.Start(); 977 } 978 979 void RefEdit::SilentGrabFocus() 980 { 981 bSilentFocus = sal_True; 982 GrabFocus(); 983 bSilentFocus = sal_False; 984 } 985 986 void RefEdit::SetRefDialog( IControlReferenceHandler* pDlg ) 987 { 988 pAnyRefDlg = pDlg; 989 990 if( pDlg ) 991 { 992 aTimer.SetTimeoutHdl( LINK( this, RefEdit, UpdateHdl ) ); 993 aTimer.SetTimeout( SC_ENABLE_TIME ); 994 } 995 else 996 { 997 aTimer.SetTimeoutHdl( Link() ); 998 aTimer.Stop(); 999 } 1000 } 1001 1002 void RefEdit::Modify() 1003 { 1004 Edit::Modify(); 1005 if( pAnyRefDlg ) 1006 pAnyRefDlg->HideReference(); 1007 } 1008 1009 void RefEdit::KeyInput( const KeyEvent& rKEvt ) 1010 { 1011 const KeyCode& rKeyCode = rKEvt.GetKeyCode(); 1012 if( pAnyRefDlg && !rKeyCode.GetModifier() && (rKeyCode.GetCode() == KEY_F2) ) 1013 pAnyRefDlg->ReleaseFocus( this ); 1014 else 1015 Edit::KeyInput( rKEvt ); 1016 } 1017 1018 void RefEdit::GetFocus() 1019 { 1020 Edit::GetFocus(); 1021 if( !bSilentFocus ) 1022 StartUpdateData(); 1023 } 1024 1025 void RefEdit::LoseFocus() 1026 { 1027 Edit::LoseFocus(); 1028 if( pAnyRefDlg ) 1029 pAnyRefDlg->HideReference(); 1030 } 1031 1032 IMPL_LINK( RefEdit, UpdateHdl, Timer*, EMPTYARG ) 1033 { 1034 if( pAnyRefDlg ) 1035 pAnyRefDlg->ShowReference( GetText() ); 1036 return 0; 1037 } 1038 1039 1040 //============================================================================ 1041 // class RefButton 1042 //---------------------------------------------------------------------------- 1043 RefButton::RefButton( Window* _pParent, const ResId& rResId) : 1044 ImageButton( _pParent, rResId ), 1045 aImgRefStart( ModuleRes( RID_BMP_REFBTN1 ) ), 1046 aImgRefStartHC( ModuleRes( RID_BMP_REFBTN1_H ) ), 1047 aImgRefDone( ModuleRes( RID_BMP_REFBTN2 ) ), 1048 aImgRefDoneHC( ModuleRes( RID_BMP_REFBTN2_H ) ), 1049 pAnyRefDlg( NULL ), 1050 pRefEdit( NULL ) 1051 { 1052 SetStartImage(); 1053 } 1054 1055 RefButton::RefButton( Window* _pParent, const ResId& rResId, RefEdit* pEdit, IControlReferenceHandler* _pDlg ) : 1056 ImageButton( _pParent, rResId ), 1057 aImgRefStart( ModuleRes( RID_BMP_REFBTN1 ) ), 1058 aImgRefStartHC( ModuleRes( RID_BMP_REFBTN1_H ) ), 1059 aImgRefDone( ModuleRes( RID_BMP_REFBTN2 ) ), 1060 aImgRefDoneHC( ModuleRes( RID_BMP_REFBTN2_H ) ), 1061 pAnyRefDlg( _pDlg ), 1062 pRefEdit( pEdit ) 1063 { 1064 SetStartImage(); 1065 } 1066 1067 void RefButton::SetStartImage() 1068 { 1069 SetModeImage( aImgRefStart ); 1070 SetModeImage( aImgRefStartHC, BMP_COLOR_HIGHCONTRAST ); 1071 } 1072 1073 void RefButton::SetEndImage() 1074 { 1075 SetModeImage( aImgRefDone ); 1076 SetModeImage( aImgRefDoneHC, BMP_COLOR_HIGHCONTRAST ); 1077 } 1078 1079 void RefButton::SetReferences( IControlReferenceHandler* pDlg, RefEdit* pEdit ) 1080 { 1081 pAnyRefDlg = pDlg; 1082 pRefEdit = pEdit; 1083 } 1084 1085 //---------------------------------------------------------------------------- 1086 1087 void RefButton::Click() 1088 { 1089 if( pAnyRefDlg ) 1090 pAnyRefDlg->ToggleCollapsed( pRefEdit, this ); 1091 } 1092 1093 void RefButton::KeyInput( const KeyEvent& rKEvt ) 1094 { 1095 const KeyCode& rKeyCode = rKEvt.GetKeyCode(); 1096 if( pAnyRefDlg && !rKeyCode.GetModifier() && (rKeyCode.GetCode() == KEY_F2) ) 1097 pAnyRefDlg->ReleaseFocus( pRefEdit ); 1098 else 1099 ImageButton::KeyInput( rKEvt ); 1100 } 1101 1102 void RefButton::GetFocus() 1103 { 1104 ImageButton::GetFocus(); 1105 if( pRefEdit ) 1106 pRefEdit->StartUpdateData(); 1107 } 1108 1109 void RefButton::LoseFocus() 1110 { 1111 ImageButton::LoseFocus(); 1112 if( pRefEdit ) 1113 pRefEdit->Modify(); 1114 } 1115 1116 1117 } // formula 1118