1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sd.hxx" 30 31 #include "EditWindow.hxx" 32 33 #include "sdmod.hxx" 34 #include <i18npool/mslangid.hxx> 35 #include <com/sun/star/i18n/ScriptType.hpp> 36 #include <editeng/editeng.hxx> 37 #include <editeng/editview.hxx> 38 #include <vcl/scrbar.hxx> 39 #include <editeng/eeitem.hxx> 40 #include "sdresid.hxx" 41 #include <svl/itempool.hxx> 42 #include <editeng/fhgtitem.hxx> 43 #include <vos/mutex.hxx> 44 #include <vcl/svapp.hxx> 45 #include <unotools/linguprops.hxx> 46 #include <unotools/lingucfg.hxx> 47 #include <editeng/fontitem.hxx> 48 #include <editeng/editstat.hxx> 49 50 #define SCROLL_LINE 24 51 52 using namespace com::sun::star::accessibility; 53 using namespace com::sun::star; 54 using namespace com::sun::star::uno; 55 56 namespace sd { namespace notes { 57 58 EditWindow::EditWindow (Window* pParentWindow, SfxItemPool* pItemPool) 59 : Window (pParentWindow, WinBits()), 60 DropTargetHelper(this), 61 mpEditView(NULL), 62 mpEditEngine(NULL), 63 mpHorizontalScrollBar(NULL), 64 mpVerticalScrollBar(NULL), 65 mpScrollBox(NULL) 66 { 67 SetMapMode(MAP_PIXEL); 68 69 // compare DataChanged 70 SetBackground (GetSettings().GetStyleSettings().GetWindowColor()); 71 72 maModifyTimer.SetTimeout(2000); 73 maModifyTimer.Start(); 74 75 maCursorMoveTimer.SetTimeout(500); 76 77 CreateEditView(); 78 79 SvxFontHeightItem aItem (GetFont().GetSize().Height(), 100, 80 EE_CHAR_FONTHEIGHT); 81 pItemPool->SetPoolDefaultItem (aItem); 82 aItem.SetWhich(EE_CHAR_FONTHEIGHT_CJK); 83 pItemPool->SetPoolDefaultItem (aItem); 84 aItem.SetWhich(EE_CHAR_FONTHEIGHT_CTL); 85 pItemPool->SetPoolDefaultItem (aItem); 86 87 InsertText (UniString::CreateFromAscii("EditWindow created and ready.\n")); 88 } 89 90 91 EditWindow::~EditWindow (void) 92 { 93 maCursorMoveTimer.Stop(); 94 maModifyTimer.Stop(); 95 96 if (mpEditView != NULL) 97 { 98 EditEngine *pEditEngine = mpEditView->GetEditEngine(); 99 if (pEditEngine) 100 { 101 pEditEngine->SetStatusEventHdl(Link()); 102 pEditEngine->RemoveView (mpEditView); 103 } 104 } 105 delete mpEditView; 106 delete mpHorizontalScrollBar; 107 delete mpVerticalScrollBar; 108 delete mpScrollBox; 109 110 } 111 112 //////////////////////////////////////// 113 114 115 void SmGetLeftSelectionPart(const ESelection aSel, 116 sal_uInt16 &nPara, sal_uInt16 &nPos) 117 // returns paragraph number and position of the selections left part 118 { 119 // compare start and end of selection and use the one that comes first 120 if ( 121 (aSel.nStartPara < aSel.nEndPara) || 122 (aSel.nStartPara == aSel.nEndPara && aSel.nStartPos < aSel.nEndPos) 123 ) 124 { nPara = aSel.nStartPara; 125 nPos = aSel.nStartPos; 126 } 127 else 128 { nPara = aSel.nEndPara; 129 nPos = aSel.nEndPos; 130 } 131 } 132 133 134 135 136 EditEngine * EditWindow::GetEditEngine (void) 137 { 138 if (mpEditEngine == NULL) 139 mpEditEngine = CreateEditEngine (); 140 return mpEditEngine; 141 } 142 143 144 145 146 EditEngine* EditWindow::CreateEditEngine (void) 147 { 148 EditEngine* pEditEngine = mpEditEngine; 149 if (pEditEngine == NULL) 150 { 151 mpEditEngineItemPool = EditEngine::CreatePool(); 152 153 // 154 // set fonts to be used 155 // 156 SvtLinguOptions aOpt; 157 SvtLinguConfig().GetOptions( aOpt ); 158 // 159 struct FontDta { 160 sal_Int16 nFallbackLang; 161 sal_Int16 nLang; 162 sal_uInt16 nFontType; 163 sal_uInt16 nFontInfoId; 164 } aTable[3] = 165 { 166 // info to get western font to be used 167 { LANGUAGE_ENGLISH_US, LANGUAGE_NONE, 168 DEFAULTFONT_SERIF, EE_CHAR_FONTINFO }, 169 // info to get CJK font to be used 170 { LANGUAGE_JAPANESE, LANGUAGE_NONE, 171 DEFAULTFONT_CJK_TEXT, EE_CHAR_FONTINFO_CJK }, 172 // info to get CTL font to be used 173 { LANGUAGE_ARABIC_SAUDI_ARABIA, LANGUAGE_NONE, 174 DEFAULTFONT_CTL_TEXT, EE_CHAR_FONTINFO_CTL } 175 }; 176 aTable[0].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN); 177 aTable[1].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN); 178 aTable[2].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX); 179 // 180 for (int i = 0; i < 3; ++i) 181 { 182 const FontDta &rFntDta = aTable[i]; 183 LanguageType nLang = (LANGUAGE_NONE == rFntDta.nLang) ? 184 rFntDta.nFallbackLang : rFntDta.nLang; 185 Font aFont = Application::GetDefaultDevice()->GetDefaultFont( 186 rFntDta.nFontType, nLang, DEFAULTFONT_FLAGS_ONLYONE); 187 mpEditEngineItemPool->SetPoolDefaultItem( 188 SvxFontItem( 189 aFont.GetFamily(), 190 aFont.GetName(), 191 aFont.GetStyleName(), 192 aFont.GetPitch(), 193 aFont.GetCharSet(), 194 rFntDta.nFontInfoId)); 195 } 196 197 // set font heights 198 SvxFontHeightItem aFontHeigt( 199 Application::GetDefaultDevice()->LogicToPixel( 200 Size (0, 10), MapMode (MAP_POINT)).Height(), 100, 201 EE_CHAR_FONTHEIGHT ); 202 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt); 203 aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CJK); 204 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt); 205 aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CTL); 206 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt); 207 208 pEditEngine = new EditEngine (mpEditEngineItemPool); 209 210 pEditEngine->EnableUndo (sal_True); 211 pEditEngine->SetDefTab (sal_uInt16( 212 Application::GetDefaultDevice()->GetTextWidth( 213 UniString::CreateFromAscii("XXXX")))); 214 215 pEditEngine->SetControlWord( 216 (pEditEngine->GetControlWord() 217 | EE_CNTRL_AUTOINDENTING) & 218 (~EE_CNTRL_UNDOATTRIBS) & 219 (~EE_CNTRL_PASTESPECIAL)); 220 221 pEditEngine->SetWordDelimiters ( 222 UniString::CreateFromAscii(" .=+-*/(){}[];\"")); 223 pEditEngine->SetRefMapMode (MAP_PIXEL); 224 pEditEngine->SetPaperSize (Size(800, 0)); 225 pEditEngine->EraseVirtualDevice(); 226 pEditEngine->ClearModifyFlag(); 227 } 228 229 return pEditEngine; 230 } 231 232 233 234 235 void EditWindow::DataChanged (const DataChangedEvent&) 236 { 237 const StyleSettings aSettings (GetSettings().GetStyleSettings()); 238 239 SetBackground( aSettings.GetWindowColor() ); 240 241 // edit fields in other Applications use this font instead of 242 // the application font thus we use this one too 243 SetPointFont( aSettings.GetFieldFont() ); 244 EditEngine* pEditEngine = GetEditEngine(); 245 246 if (pEditEngine!=NULL && mpEditEngineItemPool!=NULL) 247 { 248 //! 249 //! see also SmDocShell::GetEditEngine() ! 250 //! 251 252 // pEditEngine->SetDefTab( sal_uInt16( GetTextWidth( C2S("XXXX") ) ) ); 253 254 sal_uInt16 aFntInfoId[3] = { 255 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL }; 256 for (int i = 0; i < 3; ++i) 257 { 258 const SfxPoolItem *pItem = mpEditEngineItemPool->GetPoolDefaultItem( aFntInfoId[i] ); 259 if( pItem ) 260 { 261 const SvxFontItem *pFntItem = ((const SvxFontItem *) pItem); 262 const Font &rFnt = aSettings.GetFieldFont(); 263 SvxFontItem aFntItem( rFnt.GetFamily(), rFnt.GetName(), 264 rFnt.GetStyleName(), rFnt.GetPitch(), 265 pFntItem->GetCharSet(), 266 aFntInfoId[i] ); 267 mpEditEngineItemPool->SetPoolDefaultItem( aFntItem ); 268 } 269 } 270 271 SvxFontHeightItem aItem( GetFont().GetSize().Height(), 100, 272 EE_CHAR_FONTHEIGHT ); 273 mpEditEngineItemPool->SetPoolDefaultItem( aItem ); 274 aItem.SetWhich( EE_CHAR_FONTHEIGHT_CJK ); 275 mpEditEngineItemPool->SetPoolDefaultItem( aItem ); 276 aItem.SetWhich( EE_CHAR_FONTHEIGHT_CTL ); 277 mpEditEngineItemPool->SetPoolDefaultItem( aItem ); 278 279 // forces new settings to be used 280 // unfortunately this resets the whole edit engine 281 // thus we need to save at least the text 282 String aTxt( pEditEngine->GetText( LINEEND_LF ) ); 283 pEditEngine->Clear(); //#77957 incorrect font size 284 pEditEngine->SetText( aTxt ); 285 } 286 287 String aText (mpEditEngine->GetText (LINEEND_LF)); 288 mpEditEngine->Clear(); 289 mpEditEngine->SetText (aText); 290 291 AdjustScrollBars(); 292 Resize(); 293 } 294 295 296 297 298 void EditWindow::Resize (void) 299 { 300 if (!mpEditView) 301 CreateEditView(); 302 303 if (mpEditView != NULL) 304 { 305 mpEditView->SetOutputArea(AdjustScrollBars()); 306 mpEditView->ShowCursor(); 307 308 DBG_ASSERT( mpEditView->GetEditEngine(), "EditEngine missing" ); 309 const long nMaxVisAreaStart = mpEditView->GetEditEngine()->GetTextHeight() - 310 mpEditView->GetOutputArea().GetHeight(); 311 if (mpEditView->GetVisArea().Top() > nMaxVisAreaStart) 312 { 313 Rectangle aVisArea(mpEditView->GetVisArea() ); 314 aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0; 315 aVisArea.SetSize(mpEditView->GetOutputArea().GetSize()); 316 mpEditView->SetVisArea(aVisArea); 317 mpEditView->ShowCursor(); 318 } 319 InitScrollBars(); 320 } 321 Invalidate(); 322 } 323 324 325 326 327 void EditWindow::MouseButtonUp(const MouseEvent &rEvt) 328 { 329 if (mpEditView != NULL) 330 mpEditView->MouseButtonUp(rEvt); 331 else 332 Window::MouseButtonUp (rEvt); 333 334 // ggf FormulaCursor neu positionieren 335 // CursorMoveTimerHdl(&aCursorMoveTimer); 336 } 337 338 339 340 341 void EditWindow::MouseButtonDown(const MouseEvent &rEvt) 342 { 343 if (mpEditView != NULL) 344 mpEditView->MouseButtonDown(rEvt); 345 else 346 Window::MouseButtonDown (rEvt); 347 348 GrabFocus(); 349 } 350 351 352 353 354 void EditWindow::Command(const CommandEvent& rCEvt) 355 { 356 /* if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU) 357 { 358 GetParent()->ToTop(); 359 360 Point aPoint = rCEvt.GetMousePosPixel(); 361 PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU)); 362 363 // added for replaceability of context menus #96085, #93782 364 Menu* pMenu = NULL; 365 ::com::sun::star::ui::ContextMenuExecuteEvent aEvent; 366 aEvent.SourceWindow = VCLUnoHelper::GetInterface( this ); 367 aEvent.ExecutePosition.X = aPoint.X(); 368 aEvent.ExecutePosition.Y = aPoint.Y(); 369 if ( GetView()->TryContextMenuInterception( *pPopupMenu, pMenu, aEvent ) ) 370 { 371 if ( pMenu ) 372 { 373 delete pPopupMenu; 374 pPopupMenu = (PopupMenu*) pMenu; 375 } 376 } 377 378 pPopupMenu->SetSelectHdl(LINK(this, EditWindow, MenuSelectHdl)); 379 380 pPopupMenu->Execute( this, aPoint ); 381 delete pPopupMenu; 382 } 383 else*/ if (mpEditView) 384 mpEditView->Command( rCEvt ); 385 else 386 Window::Command (rCEvt); 387 388 } 389 IMPL_LINK_INLINE_START( EditWindow, MenuSelectHdl, Menu *, EMPTYARG ) 390 { 391 /* SmViewShell *pViewSh = rCmdBox.GetView(); 392 if (pViewSh) 393 pViewSh->GetViewFrame()->GetDispatcher()->Execute( 394 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD, 395 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L); 396 */ 397 return 0; 398 } 399 IMPL_LINK_INLINE_END( EditWindow, MenuSelectHdl, Menu *, EMPTYARG ) 400 401 void EditWindow::KeyInput(const KeyEvent& ) 402 { 403 /* if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE) 404 { 405 sal_Bool bCallBase = sal_True; 406 SfxViewShell* pViewShell = SfxViewShell::Current(); 407 if ( pViewShell && pViewShell->ISA(SmViewShell) ) 408 { 409 SmDocShell* pDocSh = (SmDocShell*) pViewShell->GetViewFrame()->GetObjectShell(); 410 if (pDocSh) 411 { 412 // fuert zum (sofortigen) Zerstoeren von this! 413 pDocSh->DoInPlaceActivate( sal_False ); 414 bCallBase = sal_False; 415 } 416 } 417 if ( bCallBase ) 418 Window::KeyInput( rKEvt ); 419 } 420 else 421 { 422 // Timer neu starten, um den Handler (auch bei l�ngeren Eingaben) 423 // m�glichst nur einmal am Ende aufzurufen. 424 aCursorMoveTimer.Start(); 425 426 DBG_ASSERT( mpEditView, "EditView missing (NULL pointer)" ); 427 if (!mpEditView) 428 CreateEditView(); 429 if ( !mpEditView->PostKeyEvent(rKEvt) ) 430 { 431 if ( !SfxViewShell::Current()->KeyInput(rKEvt) ) 432 { 433 // fuert bei F1 (Hilfe) zum Zerstoeren von this! 434 Flush(); 435 if ( aModifyTimer.IsActive() ) 436 aModifyTimer.Stop(); 437 Window::KeyInput(rKEvt); 438 } 439 else 440 { 441 //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack 442 //im SFX) den Focus auf die View gesetzt 443 SfxViewShell* pVShell = SfxViewShell::Current(); 444 if ( pVShell && pVShell->ISA(SmViewShell) && 445 ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() ) 446 { 447 GrabFocus(); 448 } 449 } 450 } 451 else 452 { 453 // have doc-shell modified only for formula input/change and not 454 // cursor travelling and such things... 455 SmDocShell *pDocShell = GetDoc(); 456 if (pDocShell) 457 pDocShell->SetModified( GetEditEngine()->IsModified() ); 458 459 aModifyTimer.Start(); 460 } 461 } 462 */ 463 } 464 465 466 467 468 void EditWindow::Paint(const Rectangle& rRect) 469 { 470 if (!mpEditView) 471 CreateEditView(); 472 mpEditView->Paint(rRect); 473 } 474 475 476 477 478 void EditWindow::CreateEditView (void) 479 { 480 EditEngine* pEditEngine = GetEditEngine(); 481 482 //! pEditEngine and mpEditView may be 0. 483 //! For example when the program is used by the document-converter 484 if (mpEditView==NULL && pEditEngine!=NULL) 485 { 486 mpEditView = new EditView (pEditEngine, this); 487 pEditEngine->InsertView (mpEditView); 488 489 if (mpVerticalScrollBar == NULL) 490 mpVerticalScrollBar = new ScrollBar ( 491 this, WinBits(WB_VSCROLL | WB_DRAG)); 492 if (mpHorizontalScrollBar == NULL) 493 mpHorizontalScrollBar = new ScrollBar ( 494 this, WinBits(WB_HSCROLL | WB_DRAG)); 495 if (mpScrollBox == NULL) 496 mpScrollBox = new ScrollBarBox (this); 497 mpVerticalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl)); 498 mpHorizontalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl)); 499 500 mpEditView->SetOutputArea(AdjustScrollBars()); 501 502 ESelection eSelection; 503 504 mpEditView->SetSelection(eSelection); 505 Update(); 506 mpEditView->ShowCursor(sal_True, sal_True); 507 508 pEditEngine->SetStatusEventHdl( 509 LINK(this, EditWindow, EditStatusHdl)); 510 SetPointer(mpEditView->GetPointer()); 511 512 SetScrollBarRanges(); 513 } 514 } 515 516 517 518 519 IMPL_LINK( EditWindow, EditStatusHdl, EditStatus *, EMPTYARG ) 520 { 521 if (!mpEditView) 522 return 1; 523 else 524 { 525 SetScrollBarRanges(); 526 return 0; 527 } 528 } 529 530 IMPL_LINK_INLINE_START( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG ) 531 { 532 DBG_ASSERT(mpEditView, "EditView missing"); 533 if (mpEditView) 534 { 535 mpEditView->SetVisArea(Rectangle(Point(mpHorizontalScrollBar->GetThumbPos(), 536 mpVerticalScrollBar->GetThumbPos()), 537 mpEditView->GetVisArea().GetSize())); 538 mpEditView->Invalidate(); 539 } 540 return 0; 541 } 542 IMPL_LINK_INLINE_END( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG ) 543 544 Rectangle EditWindow::AdjustScrollBars() 545 { 546 const Size aOut( GetOutputSizePixel() ); 547 Point aPoint; 548 Rectangle aRect( aPoint, aOut ); 549 550 if (mpVerticalScrollBar && mpHorizontalScrollBar && mpScrollBox) 551 { 552 const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize(); 553 Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L; 554 mpVerticalScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp)); 555 556 aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L; 557 mpHorizontalScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp)); 558 559 aPt.X() = mpHorizontalScrollBar->GetSizePixel().Width(); 560 aPt.Y() = mpVerticalScrollBar->GetSizePixel().Height(); 561 mpScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp )); 562 563 aRect.Right() = aPt.X() - 2; 564 aRect.Bottom() = aPt.Y() - 2; 565 } 566 return aRect; 567 } 568 569 void EditWindow::SetScrollBarRanges() 570 { 571 EditEngine* pEditEngine = GetEditEngine(); 572 if (mpEditView != NULL && pEditEngine != NULL) 573 { 574 if (mpVerticalScrollBar != NULL) 575 { 576 long nTmp = pEditEngine->GetTextHeight(); 577 mpVerticalScrollBar->SetRange(Range(0, nTmp)); 578 mpVerticalScrollBar->SetThumbPos(mpEditView->GetVisArea().Top()); 579 } 580 if (mpHorizontalScrollBar != NULL) 581 { 582 long nTmp = pEditEngine->GetPaperSize().Width(); 583 mpHorizontalScrollBar->SetRange(Range(0,nTmp)); 584 mpHorizontalScrollBar->SetThumbPos(mpEditView->GetVisArea().Left()); 585 } 586 } 587 } 588 589 void EditWindow::InitScrollBars() 590 { 591 if (mpEditView != NULL) 592 { 593 const Size aOut( mpEditView->GetOutputArea().GetSize() ); 594 if (mpVerticalScrollBar != NULL) 595 { 596 mpVerticalScrollBar->SetVisibleSize(aOut.Height()); 597 mpVerticalScrollBar->SetPageSize(aOut.Height() * 8 / 10); 598 mpVerticalScrollBar->SetLineSize(aOut.Height() * 2 / 10); 599 } 600 601 if (mpHorizontalScrollBar != NULL) 602 { 603 mpHorizontalScrollBar->SetVisibleSize(aOut.Width()); 604 mpHorizontalScrollBar->SetPageSize(aOut.Width() * 8 / 10); 605 mpHorizontalScrollBar->SetLineSize(SCROLL_LINE ); 606 } 607 608 SetScrollBarRanges(); 609 610 if (mpVerticalScrollBar != NULL) 611 mpVerticalScrollBar->Show(); 612 if (mpHorizontalScrollBar != NULL) 613 mpHorizontalScrollBar->Show(); 614 if (mpScrollBox != NULL) 615 mpScrollBox->Show(); 616 } 617 } 618 619 620 XubString EditWindow::GetText() 621 { 622 String aText; 623 EditEngine *pEditEngine = GetEditEngine(); 624 DBG_ASSERT( pEditEngine, "EditEngine missing" ); 625 if (pEditEngine) 626 aText = pEditEngine->GetText( LINEEND_LF ); 627 return aText; 628 } 629 630 631 void EditWindow::SetText(const XubString& rText) 632 { 633 EditEngine *pEditEngine = GetEditEngine(); 634 DBG_ASSERT( pEditEngine, "EditEngine missing" ); 635 if (pEditEngine && !pEditEngine->IsModified()) 636 { 637 if (!mpEditView) 638 CreateEditView(); 639 640 ESelection eSelection = mpEditView->GetSelection(); 641 642 pEditEngine->SetText(rText); 643 pEditEngine->ClearModifyFlag(); 644 645 //! Hier die Timer neu zu starten verhindert, dass die Handler f�r andere 646 //! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden. 647 maModifyTimer.Start(); 648 maCursorMoveTimer.Start(); 649 650 mpEditView->SetSelection(eSelection); 651 } 652 } 653 654 655 void EditWindow::GetFocus() 656 { 657 Window::GetFocus(); 658 659 if (!mpEditView) 660 CreateEditView(); 661 if (mpEditEngine != NULL) 662 mpEditEngine->SetStatusEventHdl( 663 LINK(this, EditWindow, EditStatusHdl)); 664 } 665 666 667 void EditWindow::LoseFocus() 668 { 669 if (mpEditEngine != NULL) 670 mpEditEngine->SetStatusEventHdl (Link()); 671 672 Window::LoseFocus(); 673 } 674 675 676 sal_Bool EditWindow::IsAllSelected() const 677 { 678 sal_Bool bRes = sal_False; 679 EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine(); 680 DBG_ASSERT( mpEditView, "NULL pointer" ); 681 DBG_ASSERT( pEditEngine, "NULL pointer" ); 682 if (pEditEngine && mpEditView) 683 { 684 ESelection eSelection( mpEditView->GetSelection() ); 685 sal_Int32 nParaCnt = pEditEngine->GetParagraphCount(); 686 if (!(nParaCnt - 1)) 687 { 688 String Text( pEditEngine->GetText( LINEEND_LF ) ); 689 bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1); 690 } 691 else 692 { 693 bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1); 694 } 695 } 696 return bRes; 697 } 698 699 void EditWindow::SelectAll() 700 { 701 DBG_ASSERT( mpEditView, "NULL pointer" ); 702 if (mpEditView) 703 { 704 // 0xFFFF as last two parameters refers to the end of the text 705 mpEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) ); 706 } 707 } 708 709 710 void EditWindow::MarkError(const Point &rPos) 711 { 712 DBG_ASSERT( mpEditView, "EditView missing" ); 713 if (mpEditView) 714 { 715 const int Col = rPos.X(); 716 const int Row = rPos.Y() - 1; 717 718 mpEditView->SetSelection(ESelection ( (sal_uInt16)Row, (sal_uInt16)(Col - 1), (sal_uInt16)Row, (sal_uInt16)Col)); 719 GrabFocus(); 720 } 721 } 722 723 void EditWindow::SelNextMark() 724 { 725 EditEngine *pEditEngine = GetEditEngine(); 726 DBG_ASSERT( mpEditView, "NULL pointer" ); 727 DBG_ASSERT( pEditEngine, "NULL pointer" ); 728 if (pEditEngine && mpEditView) 729 { 730 ESelection eSelection = mpEditView->GetSelection(); 731 sal_uInt16 Pos = eSelection.nEndPos; 732 String aMark (UniString::CreateFromAscii("<?>")); 733 String aText; 734 sal_uInt16 nCounts = pEditEngine->GetParagraphCount(); 735 736 while (eSelection.nEndPara < nCounts) 737 { 738 aText = pEditEngine->GetText( eSelection.nEndPara ); 739 Pos = aText.Search(aMark, Pos); 740 741 if (Pos != STRING_NOTFOUND) 742 { 743 mpEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3)); 744 break; 745 } 746 747 Pos = 0; 748 eSelection.nEndPara++; 749 } 750 } 751 } 752 753 void EditWindow::SelPrevMark() 754 { 755 EditEngine *pEditEngine = GetEditEngine(); 756 DBG_ASSERT( pEditEngine, "NULL pointer" ); 757 DBG_ASSERT( mpEditView, "NULL pointer" ); 758 if (pEditEngine && mpEditView) 759 { 760 ESelection eSelection = mpEditView->GetSelection(); 761 sal_uInt16 Pos = STRING_NOTFOUND; 762 xub_StrLen Max = eSelection.nStartPos; 763 String Text( pEditEngine->GetText( eSelection.nStartPara ) ); 764 String aMark (UniString::CreateFromAscii("<?>")); 765 sal_uInt16 nCounts = pEditEngine->GetParagraphCount(); 766 767 do 768 { 769 sal_uInt16 Fnd = Text.Search(aMark, 0); 770 771 while ((Fnd < Max) && (Fnd != STRING_NOTFOUND)) 772 { 773 Pos = Fnd; 774 Fnd = Text.Search(aMark, Fnd + 1); 775 } 776 777 if (Pos == STRING_NOTFOUND) 778 { 779 eSelection.nStartPara--; 780 Text = pEditEngine->GetText( eSelection.nStartPara ); 781 Max = Text.Len(); 782 } 783 } 784 while ((eSelection.nStartPara < nCounts) && 785 (Pos == STRING_NOTFOUND)); 786 787 if (Pos != STRING_NOTFOUND) 788 { 789 mpEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3)); 790 } 791 } 792 } 793 794 sal_Bool EditWindow::HasMark(const String& rText) const 795 // returns true iff 'rText' contains a mark 796 { 797 return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND; 798 } 799 800 void EditWindow::MouseMove(const MouseEvent &rEvt) 801 { 802 if (mpEditView) 803 mpEditView->MouseMove(rEvt); 804 } 805 806 sal_Int8 EditWindow::AcceptDrop( const AcceptDropEvent& ) 807 { 808 return mpEditView ? /*mpEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE; 809 } 810 811 sal_Int8 EditWindow::ExecuteDrop( const ExecuteDropEvent& ) 812 { 813 return mpEditView ? /*mpEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE; 814 } 815 816 ESelection EditWindow::GetSelection() const 817 { 818 // pointer may be 0 when reloading a document and the old view 819 // was already destroyed 820 //(DBG_ASSERT( mpEditView, "NULL pointer" ); 821 ESelection eSel; 822 if (mpEditView) 823 eSel = mpEditView->GetSelection(); 824 return eSel; 825 } 826 827 void EditWindow::SetSelection(const ESelection &rSel) 828 { 829 DBG_ASSERT( mpEditView, "NULL pointer" ); 830 if (mpEditView) 831 mpEditView->SetSelection(rSel); 832 } 833 834 sal_Bool EditWindow::IsEmpty() const 835 { 836 EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine(); 837 return (pEditEngine && (pEditEngine->GetTextLen() == 0)) ? sal_True : sal_False; 838 } 839 840 sal_Bool EditWindow::IsSelected() const 841 { 842 return mpEditView ? mpEditView->HasSelection() : sal_False; 843 } 844 845 void EditWindow::Cut() 846 { 847 DBG_ASSERT( mpEditView, "EditView missing" ); 848 if (mpEditView) 849 mpEditView->Cut(); 850 } 851 852 void EditWindow::Copy() 853 { 854 DBG_ASSERT( mpEditView, "EditView missing" ); 855 if (mpEditView) 856 mpEditView->Copy(); 857 } 858 859 void EditWindow::Paste() 860 { 861 DBG_ASSERT( mpEditView, "EditView missing" ); 862 if (mpEditView) 863 mpEditView->Paste(); 864 } 865 866 void EditWindow::Delete() 867 { 868 DBG_ASSERT( mpEditView, "EditView missing" ); 869 if (mpEditView) 870 mpEditView->DeleteSelected(); 871 } 872 873 void EditWindow::InsertText(const String& Text) 874 { 875 DBG_ASSERT( mpEditView, "EditView missing" ); 876 ::vos::OGuard aGuard (::Application::GetSolarMutex()); 877 if (mpEditView) 878 mpEditView->InsertText(Text); 879 } 880 881 882 883 } } // end of namespace ::sd::notes 884