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