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