update dev300-m58
[ooovba.git] / sd / source / ui / notes / EditWindow.cxx
blob917bc80012ea2254d81c96b044e0d2d1856c78f6
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: EditWindow.cxx,v $
10 * $Revision: 1.7.138.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "EditWindow.hxx"
36 #include "sdmod.hxx"
37 #include <svx/editeng.hxx>
38 #include <svx/editview.hxx>
39 #include <vcl/scrbar.hxx>
40 #include <svx/eeitem.hxx>
41 #include "sdresid.hxx"
42 #include <svtools/itempool.hxx>
43 #include <svx/fhgtitem.hxx>
44 #include <vos/mutex.hxx>
45 #include <vcl/svapp.hxx>
46 #include <svtools/linguprops.hxx>
47 #include <svtools/lingucfg.hxx>
48 #include <svx/fontitem.hxx>
49 #include <svx/editstat.hxx>
51 #define SCROLL_LINE 24
53 using namespace com::sun::star::accessibility;
54 using namespace com::sun::star;
55 using namespace com::sun::star::uno;
57 namespace sd { namespace notes {
59 EditWindow::EditWindow (Window* pParentWindow, SfxItemPool* pItemPool)
60 : Window (pParentWindow, WinBits()),
61 DropTargetHelper(this),
62 mpEditView(NULL),
63 mpEditEngine(NULL),
64 mpHorizontalScrollBar(NULL),
65 mpVerticalScrollBar(NULL),
66 mpScrollBox(NULL)
68 SetMapMode(MAP_PIXEL);
70 // compare DataChanged
71 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
73 maModifyTimer.SetTimeout(2000);
74 maModifyTimer.Start();
76 maCursorMoveTimer.SetTimeout(500);
78 CreateEditView();
80 SvxFontHeightItem aItem (GetFont().GetSize().Height(), 100,
81 EE_CHAR_FONTHEIGHT);
82 pItemPool->SetPoolDefaultItem (aItem);
83 aItem.SetWhich(EE_CHAR_FONTHEIGHT_CJK);
84 pItemPool->SetPoolDefaultItem (aItem);
85 aItem.SetWhich(EE_CHAR_FONTHEIGHT_CTL);
86 pItemPool->SetPoolDefaultItem (aItem);
88 InsertText (UniString::CreateFromAscii("EditWindow created and ready.\n"));
92 EditWindow::~EditWindow (void)
94 maCursorMoveTimer.Stop();
95 maModifyTimer.Stop();
97 if (mpEditView != NULL)
99 EditEngine *pEditEngine = mpEditView->GetEditEngine();
100 if (pEditEngine)
102 pEditEngine->SetStatusEventHdl(Link());
103 pEditEngine->RemoveView (mpEditView);
106 delete mpEditView;
107 delete mpHorizontalScrollBar;
108 delete mpVerticalScrollBar;
109 delete mpScrollBox;
113 ////////////////////////////////////////
116 void SmGetLeftSelectionPart(const ESelection aSel,
117 USHORT &nPara, USHORT &nPos)
118 // returns paragraph number and position of the selections left part
120 // compare start and end of selection and use the one that comes first
121 if (
122 (aSel.nStartPara < aSel.nEndPara) ||
123 (aSel.nStartPara == aSel.nEndPara && aSel.nStartPos < aSel.nEndPos)
125 { nPara = aSel.nStartPara;
126 nPos = aSel.nStartPos;
128 else
129 { nPara = aSel.nEndPara;
130 nPos = aSel.nEndPos;
137 EditEngine * EditWindow::GetEditEngine (void)
139 if (mpEditEngine == NULL)
140 mpEditEngine = CreateEditEngine ();
141 return mpEditEngine;
147 EditEngine* EditWindow::CreateEditEngine (void)
149 EditEngine* pEditEngine = mpEditEngine;
150 if (pEditEngine == NULL)
152 mpEditEngineItemPool = EditEngine::CreatePool();
155 // set fonts to be used
157 SvtLinguOptions aOpt;
158 SvtLinguConfig().GetOptions( aOpt );
160 struct FontDta {
161 INT16 nFallbackLang;
162 INT16 nLang;
163 USHORT nFontType;
164 USHORT nFontInfoId;
165 } aTable[3] =
167 // info to get western font to be used
168 { LANGUAGE_ENGLISH_US, LANGUAGE_NONE,
169 DEFAULTFONT_SERIF, EE_CHAR_FONTINFO },
170 // info to get CJK font to be used
171 { LANGUAGE_JAPANESE, LANGUAGE_NONE,
172 DEFAULTFONT_CJK_TEXT, EE_CHAR_FONTINFO_CJK },
173 // info to get CTL font to be used
174 { LANGUAGE_ARABIC_SAUDI_ARABIA, LANGUAGE_NONE,
175 DEFAULTFONT_CTL_TEXT, EE_CHAR_FONTINFO_CTL }
177 aTable[0].nLang = aOpt.nDefaultLanguage;
178 aTable[1].nLang = aOpt.nDefaultLanguage_CJK;
179 aTable[2].nLang = aOpt.nDefaultLanguage_CTL;
181 for (int i = 0; i < 3; ++i)
183 const FontDta &rFntDta = aTable[i];
184 LanguageType nLang = (LANGUAGE_NONE == rFntDta.nLang) ?
185 rFntDta.nFallbackLang : rFntDta.nLang;
186 Font aFont = Application::GetDefaultDevice()->GetDefaultFont(
187 rFntDta.nFontType, nLang, DEFAULTFONT_FLAGS_ONLYONE);
188 mpEditEngineItemPool->SetPoolDefaultItem(
189 SvxFontItem(
190 aFont.GetFamily(),
191 aFont.GetName(),
192 aFont.GetStyleName(),
193 aFont.GetPitch(),
194 aFont.GetCharSet(),
195 rFntDta.nFontInfoId));
198 // set font heights
199 SvxFontHeightItem aFontHeigt(
200 Application::GetDefaultDevice()->LogicToPixel(
201 Size (0, 10), MapMode (MAP_POINT)).Height(), 100,
202 EE_CHAR_FONTHEIGHT );
203 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt);
204 aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CJK);
205 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt);
206 aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CTL);
207 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt);
209 pEditEngine = new EditEngine (mpEditEngineItemPool);
211 pEditEngine->EnableUndo (TRUE);
212 pEditEngine->SetDefTab (USHORT(
213 Application::GetDefaultDevice()->GetTextWidth(
214 UniString::CreateFromAscii("XXXX"))));
216 pEditEngine->SetControlWord(
217 (pEditEngine->GetControlWord()
218 | EE_CNTRL_AUTOINDENTING) &
219 (~EE_CNTRL_UNDOATTRIBS) &
220 (~EE_CNTRL_PASTESPECIAL));
222 pEditEngine->SetWordDelimiters (
223 UniString::CreateFromAscii(" .=+-*/(){}[];\""));
224 pEditEngine->SetRefMapMode (MAP_PIXEL);
225 pEditEngine->SetPaperSize (Size(800, 0));
226 pEditEngine->EraseVirtualDevice();
227 pEditEngine->ClearModifyFlag();
230 return pEditEngine;
236 void EditWindow::DataChanged (const DataChangedEvent&)
238 const StyleSettings aSettings (GetSettings().GetStyleSettings());
240 SetBackground( aSettings.GetWindowColor() );
242 // edit fields in other Applications use this font instead of
243 // the application font thus we use this one too
244 SetPointFont( aSettings.GetFieldFont() );
245 EditEngine* pEditEngine = GetEditEngine();
247 if (pEditEngine!=NULL && mpEditEngineItemPool!=NULL)
250 //! see also SmDocShell::GetEditEngine() !
253 // pEditEngine->SetDefTab( USHORT( GetTextWidth( C2S("XXXX") ) ) );
255 USHORT aFntInfoId[3] = {
256 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL };
257 for (int i = 0; i < 3; ++i)
259 const SfxPoolItem *pItem = mpEditEngineItemPool->GetPoolDefaultItem( aFntInfoId[i] );
260 if( pItem )
262 const SvxFontItem *pFntItem = ((const SvxFontItem *) pItem);
263 const Font &rFnt = aSettings.GetFieldFont();
264 SvxFontItem aFntItem( rFnt.GetFamily(), rFnt.GetName(),
265 rFnt.GetStyleName(), rFnt.GetPitch(),
266 pFntItem->GetCharSet(),
267 aFntInfoId[i] );
268 mpEditEngineItemPool->SetPoolDefaultItem( aFntItem );
272 SvxFontHeightItem aItem( GetFont().GetSize().Height(), 100,
273 EE_CHAR_FONTHEIGHT );
274 mpEditEngineItemPool->SetPoolDefaultItem( aItem );
275 aItem.SetWhich( EE_CHAR_FONTHEIGHT_CJK );
276 mpEditEngineItemPool->SetPoolDefaultItem( aItem );
277 aItem.SetWhich( EE_CHAR_FONTHEIGHT_CTL );
278 mpEditEngineItemPool->SetPoolDefaultItem( aItem );
280 // forces new settings to be used
281 // unfortunately this resets the whole edit engine
282 // thus we need to save at least the text
283 String aTxt( pEditEngine->GetText( LINEEND_LF ) );
284 pEditEngine->Clear(); //#77957 incorrect font size
285 pEditEngine->SetText( aTxt );
288 String aText (mpEditEngine->GetText (LINEEND_LF));
289 mpEditEngine->Clear();
290 mpEditEngine->SetText (aText);
292 AdjustScrollBars();
293 Resize();
299 void EditWindow::Resize (void)
301 if (!mpEditView)
302 CreateEditView();
304 if (mpEditView != NULL)
306 mpEditView->SetOutputArea(AdjustScrollBars());
307 mpEditView->ShowCursor();
309 DBG_ASSERT( mpEditView->GetEditEngine(), "EditEngine missing" );
310 const long nMaxVisAreaStart = mpEditView->GetEditEngine()->GetTextHeight() -
311 mpEditView->GetOutputArea().GetHeight();
312 if (mpEditView->GetVisArea().Top() > nMaxVisAreaStart)
314 Rectangle aVisArea(mpEditView->GetVisArea() );
315 aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0;
316 aVisArea.SetSize(mpEditView->GetOutputArea().GetSize());
317 mpEditView->SetVisArea(aVisArea);
318 mpEditView->ShowCursor();
320 InitScrollBars();
322 Invalidate();
328 void EditWindow::MouseButtonUp(const MouseEvent &rEvt)
330 if (mpEditView != NULL)
331 mpEditView->MouseButtonUp(rEvt);
332 else
333 Window::MouseButtonUp (rEvt);
335 // ggf FormulaCursor neu positionieren
336 // CursorMoveTimerHdl(&aCursorMoveTimer);
342 void EditWindow::MouseButtonDown(const MouseEvent &rEvt)
344 if (mpEditView != NULL)
345 mpEditView->MouseButtonDown(rEvt);
346 else
347 Window::MouseButtonDown (rEvt);
349 GrabFocus();
355 void EditWindow::Command(const CommandEvent& rCEvt)
357 /* if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU)
359 GetParent()->ToTop();
361 Point aPoint = rCEvt.GetMousePosPixel();
362 PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU));
364 // added for replaceability of context menus #96085, #93782
365 Menu* pMenu = NULL;
366 ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
367 aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
368 aEvent.ExecutePosition.X = aPoint.X();
369 aEvent.ExecutePosition.Y = aPoint.Y();
370 if ( GetView()->TryContextMenuInterception( *pPopupMenu, pMenu, aEvent ) )
372 if ( pMenu )
374 delete pPopupMenu;
375 pPopupMenu = (PopupMenu*) pMenu;
379 pPopupMenu->SetSelectHdl(LINK(this, EditWindow, MenuSelectHdl));
381 pPopupMenu->Execute( this, aPoint );
382 delete pPopupMenu;
384 else*/ if (mpEditView)
385 mpEditView->Command( rCEvt );
386 else
387 Window::Command (rCEvt);
390 IMPL_LINK_INLINE_START( EditWindow, MenuSelectHdl, Menu *, EMPTYARG )
392 /* SmViewShell *pViewSh = rCmdBox.GetView();
393 if (pViewSh)
394 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
395 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
396 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
398 return 0;
400 IMPL_LINK_INLINE_END( EditWindow, MenuSelectHdl, Menu *, EMPTYARG )
402 void EditWindow::KeyInput(const KeyEvent& )
404 /* if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
406 BOOL bCallBase = TRUE;
407 SfxViewShell* pViewShell = SfxViewShell::Current();
408 if ( pViewShell && pViewShell->ISA(SmViewShell) )
410 SmDocShell* pDocSh = (SmDocShell*) pViewShell->GetViewFrame()->GetObjectShell();
411 if (pDocSh)
413 // fuert zum (sofortigen) Zerstoeren von this!
414 pDocSh->DoInPlaceActivate( FALSE );
415 bCallBase = FALSE;
418 if ( bCallBase )
419 Window::KeyInput( rKEvt );
421 else
423 // Timer neu starten, um den Handler (auch bei längeren Eingaben)
424 // möglichst nur einmal am Ende aufzurufen.
425 aCursorMoveTimer.Start();
427 DBG_ASSERT( mpEditView, "EditView missing (NULL pointer)" );
428 if (!mpEditView)
429 CreateEditView();
430 if ( !mpEditView->PostKeyEvent(rKEvt) )
432 if ( !SfxViewShell::Current()->KeyInput(rKEvt) )
434 // fuert bei F1 (Hilfe) zum Zerstoeren von this!
435 Flush();
436 if ( aModifyTimer.IsActive() )
437 aModifyTimer.Stop();
438 Window::KeyInput(rKEvt);
440 else
442 //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack
443 //im SFX) den Focus auf die View gesetzt
444 SfxViewShell* pVShell = SfxViewShell::Current();
445 if ( pVShell && pVShell->ISA(SmViewShell) &&
446 ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() )
448 GrabFocus();
452 else
454 // have doc-shell modified only for formula input/change and not
455 // cursor travelling and such things...
456 SmDocShell *pDocShell = GetDoc();
457 if (pDocShell)
458 pDocShell->SetModified( GetEditEngine()->IsModified() );
460 aModifyTimer.Start();
469 void EditWindow::Paint(const Rectangle& rRect)
471 if (!mpEditView)
472 CreateEditView();
473 mpEditView->Paint(rRect);
479 void EditWindow::CreateEditView (void)
481 EditEngine* pEditEngine = GetEditEngine();
483 //! pEditEngine and mpEditView may be 0.
484 //! For example when the program is used by the document-converter
485 if (mpEditView==NULL && pEditEngine!=NULL)
487 mpEditView = new EditView (pEditEngine, this);
488 pEditEngine->InsertView (mpEditView);
490 if (mpVerticalScrollBar == NULL)
491 mpVerticalScrollBar = new ScrollBar (
492 this, WinBits(WB_VSCROLL | WB_DRAG));
493 if (mpHorizontalScrollBar == NULL)
494 mpHorizontalScrollBar = new ScrollBar (
495 this, WinBits(WB_HSCROLL | WB_DRAG));
496 if (mpScrollBox == NULL)
497 mpScrollBox = new ScrollBarBox (this);
498 mpVerticalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl));
499 mpHorizontalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl));
501 mpEditView->SetOutputArea(AdjustScrollBars());
503 ESelection eSelection;
505 mpEditView->SetSelection(eSelection);
506 Update();
507 mpEditView->ShowCursor(TRUE, TRUE);
509 pEditEngine->SetStatusEventHdl(
510 LINK(this, EditWindow, EditStatusHdl));
511 SetPointer(mpEditView->GetPointer());
513 SetScrollBarRanges();
520 IMPL_LINK( EditWindow, EditStatusHdl, EditStatus *, EMPTYARG )
522 if (!mpEditView)
523 return 1;
524 else
526 SetScrollBarRanges();
527 return 0;
531 IMPL_LINK_INLINE_START( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG )
533 DBG_ASSERT(mpEditView, "EditView missing");
534 if (mpEditView)
536 mpEditView->SetVisArea(Rectangle(Point(mpHorizontalScrollBar->GetThumbPos(),
537 mpVerticalScrollBar->GetThumbPos()),
538 mpEditView->GetVisArea().GetSize()));
539 mpEditView->Invalidate();
541 return 0;
543 IMPL_LINK_INLINE_END( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG )
545 Rectangle EditWindow::AdjustScrollBars()
547 const Size aOut( GetOutputSizePixel() );
548 Point aPoint;
549 Rectangle aRect( aPoint, aOut );
551 if (mpVerticalScrollBar && mpHorizontalScrollBar && mpScrollBox)
553 const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
554 Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L;
555 mpVerticalScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp));
557 aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L;
558 mpHorizontalScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp));
560 aPt.X() = mpHorizontalScrollBar->GetSizePixel().Width();
561 aPt.Y() = mpVerticalScrollBar->GetSizePixel().Height();
562 mpScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp ));
564 aRect.Right() = aPt.X() - 2;
565 aRect.Bottom() = aPt.Y() - 2;
567 return aRect;
570 void EditWindow::SetScrollBarRanges()
572 EditEngine* pEditEngine = GetEditEngine();
573 if (mpEditView != NULL && pEditEngine != NULL)
575 if (mpVerticalScrollBar != NULL)
577 long nTmp = pEditEngine->GetTextHeight();
578 mpVerticalScrollBar->SetRange(Range(0, nTmp));
579 mpVerticalScrollBar->SetThumbPos(mpEditView->GetVisArea().Top());
581 if (mpHorizontalScrollBar != NULL)
583 long nTmp = pEditEngine->GetPaperSize().Width();
584 mpHorizontalScrollBar->SetRange(Range(0,nTmp));
585 mpHorizontalScrollBar->SetThumbPos(mpEditView->GetVisArea().Left());
590 void EditWindow::InitScrollBars()
592 if (mpEditView != NULL)
594 const Size aOut( mpEditView->GetOutputArea().GetSize() );
595 if (mpVerticalScrollBar != NULL)
597 mpVerticalScrollBar->SetVisibleSize(aOut.Height());
598 mpVerticalScrollBar->SetPageSize(aOut.Height() * 8 / 10);
599 mpVerticalScrollBar->SetLineSize(aOut.Height() * 2 / 10);
602 if (mpHorizontalScrollBar != NULL)
604 mpHorizontalScrollBar->SetVisibleSize(aOut.Width());
605 mpHorizontalScrollBar->SetPageSize(aOut.Width() * 8 / 10);
606 mpHorizontalScrollBar->SetLineSize(SCROLL_LINE );
609 SetScrollBarRanges();
611 if (mpVerticalScrollBar != NULL)
612 mpVerticalScrollBar->Show();
613 if (mpHorizontalScrollBar != NULL)
614 mpHorizontalScrollBar->Show();
615 if (mpScrollBox != NULL)
616 mpScrollBox->Show();
621 XubString EditWindow::GetText()
623 String aText;
624 EditEngine *pEditEngine = GetEditEngine();
625 DBG_ASSERT( pEditEngine, "EditEngine missing" );
626 if (pEditEngine)
627 aText = pEditEngine->GetText( LINEEND_LF );
628 return aText;
632 void EditWindow::SetText(const XubString& rText)
634 EditEngine *pEditEngine = GetEditEngine();
635 DBG_ASSERT( pEditEngine, "EditEngine missing" );
636 if (pEditEngine && !pEditEngine->IsModified())
638 if (!mpEditView)
639 CreateEditView();
641 ESelection eSelection = mpEditView->GetSelection();
643 pEditEngine->SetText(rText);
644 pEditEngine->ClearModifyFlag();
646 //! Hier die Timer neu zu starten verhindert, dass die Handler für andere
647 //! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden.
648 maModifyTimer.Start();
649 maCursorMoveTimer.Start();
651 mpEditView->SetSelection(eSelection);
656 void EditWindow::GetFocus()
658 Window::GetFocus();
660 if (!mpEditView)
661 CreateEditView();
662 if (mpEditEngine != NULL)
663 mpEditEngine->SetStatusEventHdl(
664 LINK(this, EditWindow, EditStatusHdl));
668 void EditWindow::LoseFocus()
670 if (mpEditEngine != NULL)
671 mpEditEngine->SetStatusEventHdl (Link());
673 Window::LoseFocus();
677 BOOL EditWindow::IsAllSelected() const
679 BOOL bRes = FALSE;
680 EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine();
681 DBG_ASSERT( mpEditView, "NULL pointer" );
682 DBG_ASSERT( pEditEngine, "NULL pointer" );
683 if (pEditEngine && mpEditView)
685 ESelection eSelection( mpEditView->GetSelection() );
686 INT32 nParaCnt = pEditEngine->GetParagraphCount();
687 if (!(nParaCnt - 1))
689 String Text( pEditEngine->GetText( LINEEND_LF ) );
690 bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1);
692 else
694 bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
697 return bRes;
700 void EditWindow::SelectAll()
702 DBG_ASSERT( mpEditView, "NULL pointer" );
703 if (mpEditView)
705 // 0xFFFF as last two parameters refers to the end of the text
706 mpEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
711 void EditWindow::MarkError(const Point &rPos)
713 DBG_ASSERT( mpEditView, "EditView missing" );
714 if (mpEditView)
716 const int Col = rPos.X();
717 const int Row = rPos.Y() - 1;
719 mpEditView->SetSelection(ESelection ( (USHORT)Row, (USHORT)(Col - 1), (USHORT)Row, (USHORT)Col));
720 GrabFocus();
724 void EditWindow::SelNextMark()
726 EditEngine *pEditEngine = GetEditEngine();
727 DBG_ASSERT( mpEditView, "NULL pointer" );
728 DBG_ASSERT( pEditEngine, "NULL pointer" );
729 if (pEditEngine && mpEditView)
731 ESelection eSelection = mpEditView->GetSelection();
732 USHORT Pos = eSelection.nEndPos;
733 String aMark (UniString::CreateFromAscii("<?>"));
734 String aText;
735 USHORT nCounts = pEditEngine->GetParagraphCount();
737 while (eSelection.nEndPara < nCounts)
739 aText = pEditEngine->GetText( eSelection.nEndPara );
740 Pos = aText.Search(aMark, Pos);
742 if (Pos != STRING_NOTFOUND)
744 mpEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3));
745 break;
748 Pos = 0;
749 eSelection.nEndPara++;
754 void EditWindow::SelPrevMark()
756 EditEngine *pEditEngine = GetEditEngine();
757 DBG_ASSERT( pEditEngine, "NULL pointer" );
758 DBG_ASSERT( mpEditView, "NULL pointer" );
759 if (pEditEngine && mpEditView)
761 ESelection eSelection = mpEditView->GetSelection();
762 USHORT Pos = STRING_NOTFOUND;
763 xub_StrLen Max = eSelection.nStartPos;
764 String Text( pEditEngine->GetText( eSelection.nStartPara ) );
765 String aMark (UniString::CreateFromAscii("<?>"));
766 USHORT nCounts = pEditEngine->GetParagraphCount();
770 USHORT Fnd = Text.Search(aMark, 0);
772 while ((Fnd < Max) && (Fnd != STRING_NOTFOUND))
774 Pos = Fnd;
775 Fnd = Text.Search(aMark, Fnd + 1);
778 if (Pos == STRING_NOTFOUND)
780 eSelection.nStartPara--;
781 Text = pEditEngine->GetText( eSelection.nStartPara );
782 Max = Text.Len();
785 while ((eSelection.nStartPara < nCounts) &&
786 (Pos == STRING_NOTFOUND));
788 if (Pos != STRING_NOTFOUND)
790 mpEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3));
795 BOOL EditWindow::HasMark(const String& rText) const
796 // returns true iff 'rText' contains a mark
798 return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND;
801 void EditWindow::MouseMove(const MouseEvent &rEvt)
803 if (mpEditView)
804 mpEditView->MouseMove(rEvt);
807 sal_Int8 EditWindow::AcceptDrop( const AcceptDropEvent& )
809 return mpEditView ? /*mpEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE;
812 sal_Int8 EditWindow::ExecuteDrop( const ExecuteDropEvent& )
814 return mpEditView ? /*mpEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE;
817 ESelection EditWindow::GetSelection() const
819 // pointer may be 0 when reloading a document and the old view
820 // was already destroyed
821 //(DBG_ASSERT( mpEditView, "NULL pointer" );
822 ESelection eSel;
823 if (mpEditView)
824 eSel = mpEditView->GetSelection();
825 return eSel;
828 void EditWindow::SetSelection(const ESelection &rSel)
830 DBG_ASSERT( mpEditView, "NULL pointer" );
831 if (mpEditView)
832 mpEditView->SetSelection(rSel);
835 BOOL EditWindow::IsEmpty() const
837 EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine();
838 return (pEditEngine && (pEditEngine->GetTextLen() == 0)) ? TRUE : FALSE;
841 BOOL EditWindow::IsSelected() const
843 return mpEditView ? mpEditView->HasSelection() : FALSE;
846 void EditWindow::Cut()
848 DBG_ASSERT( mpEditView, "EditView missing" );
849 if (mpEditView)
850 mpEditView->Cut();
853 void EditWindow::Copy()
855 DBG_ASSERT( mpEditView, "EditView missing" );
856 if (mpEditView)
857 mpEditView->Copy();
860 void EditWindow::Paste()
862 DBG_ASSERT( mpEditView, "EditView missing" );
863 if (mpEditView)
864 mpEditView->Paste();
867 void EditWindow::Delete()
869 DBG_ASSERT( mpEditView, "EditView missing" );
870 if (mpEditView)
871 mpEditView->DeleteSelected();
874 void EditWindow::InsertText(const String& Text)
876 DBG_ASSERT( mpEditView, "EditView missing" );
877 ::vos::OGuard aGuard (::Application::GetSolarMutex());
878 if (mpEditView)
879 mpEditView->InsertText(Text);
884 } } // end of namespace ::sd::notes