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