Update ooo320-m1
[ooovba.git] / sd / source / ui / notes / EditWindow.cxx
blob90e3f3a3c80a23280b3fc8e3b96dbe838c980017
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 <i18npool/mslangid.hxx>
38 #include <com/sun/star/i18n/ScriptType.hpp>
39 #include <svx/editeng.hxx>
40 #include <svx/editview.hxx>
41 #include <vcl/scrbar.hxx>
42 #include <svx/eeitem.hxx>
43 #include "sdresid.hxx"
44 #include <svtools/itempool.hxx>
45 #include <svx/fhgtitem.hxx>
46 #include <vos/mutex.hxx>
47 #include <vcl/svapp.hxx>
48 #include <svtools/linguprops.hxx>
49 #include <svtools/lingucfg.hxx>
50 #include <svx/fontitem.hxx>
51 #include <svx/editstat.hxx>
53 #define SCROLL_LINE 24
55 using namespace com::sun::star::accessibility;
56 using namespace com::sun::star;
57 using namespace com::sun::star::uno;
59 namespace sd { namespace notes {
61 EditWindow::EditWindow (Window* pParentWindow, SfxItemPool* pItemPool)
62 : Window (pParentWindow, WinBits()),
63 DropTargetHelper(this),
64 mpEditView(NULL),
65 mpEditEngine(NULL),
66 mpHorizontalScrollBar(NULL),
67 mpVerticalScrollBar(NULL),
68 mpScrollBox(NULL)
70 SetMapMode(MAP_PIXEL);
72 // compare DataChanged
73 SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
75 maModifyTimer.SetTimeout(2000);
76 maModifyTimer.Start();
78 maCursorMoveTimer.SetTimeout(500);
80 CreateEditView();
82 SvxFontHeightItem aItem (GetFont().GetSize().Height(), 100,
83 EE_CHAR_FONTHEIGHT);
84 pItemPool->SetPoolDefaultItem (aItem);
85 aItem.SetWhich(EE_CHAR_FONTHEIGHT_CJK);
86 pItemPool->SetPoolDefaultItem (aItem);
87 aItem.SetWhich(EE_CHAR_FONTHEIGHT_CTL);
88 pItemPool->SetPoolDefaultItem (aItem);
90 InsertText (UniString::CreateFromAscii("EditWindow created and ready.\n"));
94 EditWindow::~EditWindow (void)
96 maCursorMoveTimer.Stop();
97 maModifyTimer.Stop();
99 if (mpEditView != NULL)
101 EditEngine *pEditEngine = mpEditView->GetEditEngine();
102 if (pEditEngine)
104 pEditEngine->SetStatusEventHdl(Link());
105 pEditEngine->RemoveView (mpEditView);
108 delete mpEditView;
109 delete mpHorizontalScrollBar;
110 delete mpVerticalScrollBar;
111 delete mpScrollBox;
115 ////////////////////////////////////////
118 void SmGetLeftSelectionPart(const ESelection aSel,
119 USHORT &nPara, USHORT &nPos)
120 // returns paragraph number and position of the selections left part
122 // compare start and end of selection and use the one that comes first
123 if (
124 (aSel.nStartPara < aSel.nEndPara) ||
125 (aSel.nStartPara == aSel.nEndPara && aSel.nStartPos < aSel.nEndPos)
127 { nPara = aSel.nStartPara;
128 nPos = aSel.nStartPos;
130 else
131 { nPara = aSel.nEndPara;
132 nPos = aSel.nEndPos;
139 EditEngine * EditWindow::GetEditEngine (void)
141 if (mpEditEngine == NULL)
142 mpEditEngine = CreateEditEngine ();
143 return mpEditEngine;
149 EditEngine* EditWindow::CreateEditEngine (void)
151 EditEngine* pEditEngine = mpEditEngine;
152 if (pEditEngine == NULL)
154 mpEditEngineItemPool = EditEngine::CreatePool();
157 // set fonts to be used
159 SvtLinguOptions aOpt;
160 SvtLinguConfig().GetOptions( aOpt );
162 struct FontDta {
163 INT16 nFallbackLang;
164 INT16 nLang;
165 USHORT nFontType;
166 USHORT nFontInfoId;
167 } aTable[3] =
169 // info to get western font to be used
170 { LANGUAGE_ENGLISH_US, LANGUAGE_NONE,
171 DEFAULTFONT_SERIF, EE_CHAR_FONTINFO },
172 // info to get CJK font to be used
173 { LANGUAGE_JAPANESE, LANGUAGE_NONE,
174 DEFAULTFONT_CJK_TEXT, EE_CHAR_FONTINFO_CJK },
175 // info to get CTL font to be used
176 { LANGUAGE_ARABIC_SAUDI_ARABIA, LANGUAGE_NONE,
177 DEFAULTFONT_CTL_TEXT, EE_CHAR_FONTINFO_CTL }
179 aTable[0].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN);
180 aTable[1].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CJK, ::com::sun::star::i18n::ScriptType::ASIAN);
181 aTable[2].nLang = MsLangId::resolveSystemLanguageByScriptType(aOpt.nDefaultLanguage_CTL, ::com::sun::star::i18n::ScriptType::COMPLEX);
183 for (int i = 0; i < 3; ++i)
185 const FontDta &rFntDta = aTable[i];
186 LanguageType nLang = (LANGUAGE_NONE == rFntDta.nLang) ?
187 rFntDta.nFallbackLang : rFntDta.nLang;
188 Font aFont = Application::GetDefaultDevice()->GetDefaultFont(
189 rFntDta.nFontType, nLang, DEFAULTFONT_FLAGS_ONLYONE);
190 mpEditEngineItemPool->SetPoolDefaultItem(
191 SvxFontItem(
192 aFont.GetFamily(),
193 aFont.GetName(),
194 aFont.GetStyleName(),
195 aFont.GetPitch(),
196 aFont.GetCharSet(),
197 rFntDta.nFontInfoId));
200 // set font heights
201 SvxFontHeightItem aFontHeigt(
202 Application::GetDefaultDevice()->LogicToPixel(
203 Size (0, 10), MapMode (MAP_POINT)).Height(), 100,
204 EE_CHAR_FONTHEIGHT );
205 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt);
206 aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CJK);
207 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt);
208 aFontHeigt.SetWhich (EE_CHAR_FONTHEIGHT_CTL);
209 mpEditEngineItemPool->SetPoolDefaultItem( aFontHeigt);
211 pEditEngine = new EditEngine (mpEditEngineItemPool);
213 pEditEngine->EnableUndo (TRUE);
214 pEditEngine->SetDefTab (USHORT(
215 Application::GetDefaultDevice()->GetTextWidth(
216 UniString::CreateFromAscii("XXXX"))));
218 pEditEngine->SetControlWord(
219 (pEditEngine->GetControlWord()
220 | EE_CNTRL_AUTOINDENTING) &
221 (~EE_CNTRL_UNDOATTRIBS) &
222 (~EE_CNTRL_PASTESPECIAL));
224 pEditEngine->SetWordDelimiters (
225 UniString::CreateFromAscii(" .=+-*/(){}[];\""));
226 pEditEngine->SetRefMapMode (MAP_PIXEL);
227 pEditEngine->SetPaperSize (Size(800, 0));
228 pEditEngine->EraseVirtualDevice();
229 pEditEngine->ClearModifyFlag();
232 return pEditEngine;
238 void EditWindow::DataChanged (const DataChangedEvent&)
240 const StyleSettings aSettings (GetSettings().GetStyleSettings());
242 SetBackground( aSettings.GetWindowColor() );
244 // edit fields in other Applications use this font instead of
245 // the application font thus we use this one too
246 SetPointFont( aSettings.GetFieldFont() );
247 EditEngine* pEditEngine = GetEditEngine();
249 if (pEditEngine!=NULL && mpEditEngineItemPool!=NULL)
252 //! see also SmDocShell::GetEditEngine() !
255 // pEditEngine->SetDefTab( USHORT( GetTextWidth( C2S("XXXX") ) ) );
257 USHORT aFntInfoId[3] = {
258 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL };
259 for (int i = 0; i < 3; ++i)
261 const SfxPoolItem *pItem = mpEditEngineItemPool->GetPoolDefaultItem( aFntInfoId[i] );
262 if( pItem )
264 const SvxFontItem *pFntItem = ((const SvxFontItem *) pItem);
265 const Font &rFnt = aSettings.GetFieldFont();
266 SvxFontItem aFntItem( rFnt.GetFamily(), rFnt.GetName(),
267 rFnt.GetStyleName(), rFnt.GetPitch(),
268 pFntItem->GetCharSet(),
269 aFntInfoId[i] );
270 mpEditEngineItemPool->SetPoolDefaultItem( aFntItem );
274 SvxFontHeightItem aItem( GetFont().GetSize().Height(), 100,
275 EE_CHAR_FONTHEIGHT );
276 mpEditEngineItemPool->SetPoolDefaultItem( aItem );
277 aItem.SetWhich( EE_CHAR_FONTHEIGHT_CJK );
278 mpEditEngineItemPool->SetPoolDefaultItem( aItem );
279 aItem.SetWhich( EE_CHAR_FONTHEIGHT_CTL );
280 mpEditEngineItemPool->SetPoolDefaultItem( aItem );
282 // forces new settings to be used
283 // unfortunately this resets the whole edit engine
284 // thus we need to save at least the text
285 String aTxt( pEditEngine->GetText( LINEEND_LF ) );
286 pEditEngine->Clear(); //#77957 incorrect font size
287 pEditEngine->SetText( aTxt );
290 String aText (mpEditEngine->GetText (LINEEND_LF));
291 mpEditEngine->Clear();
292 mpEditEngine->SetText (aText);
294 AdjustScrollBars();
295 Resize();
301 void EditWindow::Resize (void)
303 if (!mpEditView)
304 CreateEditView();
306 if (mpEditView != NULL)
308 mpEditView->SetOutputArea(AdjustScrollBars());
309 mpEditView->ShowCursor();
311 DBG_ASSERT( mpEditView->GetEditEngine(), "EditEngine missing" );
312 const long nMaxVisAreaStart = mpEditView->GetEditEngine()->GetTextHeight() -
313 mpEditView->GetOutputArea().GetHeight();
314 if (mpEditView->GetVisArea().Top() > nMaxVisAreaStart)
316 Rectangle aVisArea(mpEditView->GetVisArea() );
317 aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0;
318 aVisArea.SetSize(mpEditView->GetOutputArea().GetSize());
319 mpEditView->SetVisArea(aVisArea);
320 mpEditView->ShowCursor();
322 InitScrollBars();
324 Invalidate();
330 void EditWindow::MouseButtonUp(const MouseEvent &rEvt)
332 if (mpEditView != NULL)
333 mpEditView->MouseButtonUp(rEvt);
334 else
335 Window::MouseButtonUp (rEvt);
337 // ggf FormulaCursor neu positionieren
338 // CursorMoveTimerHdl(&aCursorMoveTimer);
344 void EditWindow::MouseButtonDown(const MouseEvent &rEvt)
346 if (mpEditView != NULL)
347 mpEditView->MouseButtonDown(rEvt);
348 else
349 Window::MouseButtonDown (rEvt);
351 GrabFocus();
357 void EditWindow::Command(const CommandEvent& rCEvt)
359 /* if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU)
361 GetParent()->ToTop();
363 Point aPoint = rCEvt.GetMousePosPixel();
364 PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU));
366 // added for replaceability of context menus #96085, #93782
367 Menu* pMenu = NULL;
368 ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
369 aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
370 aEvent.ExecutePosition.X = aPoint.X();
371 aEvent.ExecutePosition.Y = aPoint.Y();
372 if ( GetView()->TryContextMenuInterception( *pPopupMenu, pMenu, aEvent ) )
374 if ( pMenu )
376 delete pPopupMenu;
377 pPopupMenu = (PopupMenu*) pMenu;
381 pPopupMenu->SetSelectHdl(LINK(this, EditWindow, MenuSelectHdl));
383 pPopupMenu->Execute( this, aPoint );
384 delete pPopupMenu;
386 else*/ if (mpEditView)
387 mpEditView->Command( rCEvt );
388 else
389 Window::Command (rCEvt);
392 IMPL_LINK_INLINE_START( EditWindow, MenuSelectHdl, Menu *, EMPTYARG )
394 /* SmViewShell *pViewSh = rCmdBox.GetView();
395 if (pViewSh)
396 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
397 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
398 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
400 return 0;
402 IMPL_LINK_INLINE_END( EditWindow, MenuSelectHdl, Menu *, EMPTYARG )
404 void EditWindow::KeyInput(const KeyEvent& )
406 /* if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
408 BOOL bCallBase = TRUE;
409 SfxViewShell* pViewShell = SfxViewShell::Current();
410 if ( pViewShell && pViewShell->ISA(SmViewShell) )
412 SmDocShell* pDocSh = (SmDocShell*) pViewShell->GetViewFrame()->GetObjectShell();
413 if (pDocSh)
415 // fuert zum (sofortigen) Zerstoeren von this!
416 pDocSh->DoInPlaceActivate( FALSE );
417 bCallBase = FALSE;
420 if ( bCallBase )
421 Window::KeyInput( rKEvt );
423 else
425 // Timer neu starten, um den Handler (auch bei längeren Eingaben)
426 // möglichst nur einmal am Ende aufzurufen.
427 aCursorMoveTimer.Start();
429 DBG_ASSERT( mpEditView, "EditView missing (NULL pointer)" );
430 if (!mpEditView)
431 CreateEditView();
432 if ( !mpEditView->PostKeyEvent(rKEvt) )
434 if ( !SfxViewShell::Current()->KeyInput(rKEvt) )
436 // fuert bei F1 (Hilfe) zum Zerstoeren von this!
437 Flush();
438 if ( aModifyTimer.IsActive() )
439 aModifyTimer.Stop();
440 Window::KeyInput(rKEvt);
442 else
444 //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack
445 //im SFX) den Focus auf die View gesetzt
446 SfxViewShell* pVShell = SfxViewShell::Current();
447 if ( pVShell && pVShell->ISA(SmViewShell) &&
448 ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() )
450 GrabFocus();
454 else
456 // have doc-shell modified only for formula input/change and not
457 // cursor travelling and such things...
458 SmDocShell *pDocShell = GetDoc();
459 if (pDocShell)
460 pDocShell->SetModified( GetEditEngine()->IsModified() );
462 aModifyTimer.Start();
471 void EditWindow::Paint(const Rectangle& rRect)
473 if (!mpEditView)
474 CreateEditView();
475 mpEditView->Paint(rRect);
481 void EditWindow::CreateEditView (void)
483 EditEngine* pEditEngine = GetEditEngine();
485 //! pEditEngine and mpEditView may be 0.
486 //! For example when the program is used by the document-converter
487 if (mpEditView==NULL && pEditEngine!=NULL)
489 mpEditView = new EditView (pEditEngine, this);
490 pEditEngine->InsertView (mpEditView);
492 if (mpVerticalScrollBar == NULL)
493 mpVerticalScrollBar = new ScrollBar (
494 this, WinBits(WB_VSCROLL | WB_DRAG));
495 if (mpHorizontalScrollBar == NULL)
496 mpHorizontalScrollBar = new ScrollBar (
497 this, WinBits(WB_HSCROLL | WB_DRAG));
498 if (mpScrollBox == NULL)
499 mpScrollBox = new ScrollBarBox (this);
500 mpVerticalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl));
501 mpHorizontalScrollBar->SetScrollHdl(LINK(this, EditWindow, ScrollHdl));
503 mpEditView->SetOutputArea(AdjustScrollBars());
505 ESelection eSelection;
507 mpEditView->SetSelection(eSelection);
508 Update();
509 mpEditView->ShowCursor(TRUE, TRUE);
511 pEditEngine->SetStatusEventHdl(
512 LINK(this, EditWindow, EditStatusHdl));
513 SetPointer(mpEditView->GetPointer());
515 SetScrollBarRanges();
522 IMPL_LINK( EditWindow, EditStatusHdl, EditStatus *, EMPTYARG )
524 if (!mpEditView)
525 return 1;
526 else
528 SetScrollBarRanges();
529 return 0;
533 IMPL_LINK_INLINE_START( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG )
535 DBG_ASSERT(mpEditView, "EditView missing");
536 if (mpEditView)
538 mpEditView->SetVisArea(Rectangle(Point(mpHorizontalScrollBar->GetThumbPos(),
539 mpVerticalScrollBar->GetThumbPos()),
540 mpEditView->GetVisArea().GetSize()));
541 mpEditView->Invalidate();
543 return 0;
545 IMPL_LINK_INLINE_END( EditWindow, ScrollHdl, ScrollBar *, EMPTYARG )
547 Rectangle EditWindow::AdjustScrollBars()
549 const Size aOut( GetOutputSizePixel() );
550 Point aPoint;
551 Rectangle aRect( aPoint, aOut );
553 if (mpVerticalScrollBar && mpHorizontalScrollBar && mpScrollBox)
555 const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
556 Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L;
557 mpVerticalScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp));
559 aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L;
560 mpHorizontalScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp));
562 aPt.X() = mpHorizontalScrollBar->GetSizePixel().Width();
563 aPt.Y() = mpVerticalScrollBar->GetSizePixel().Height();
564 mpScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp ));
566 aRect.Right() = aPt.X() - 2;
567 aRect.Bottom() = aPt.Y() - 2;
569 return aRect;
572 void EditWindow::SetScrollBarRanges()
574 EditEngine* pEditEngine = GetEditEngine();
575 if (mpEditView != NULL && pEditEngine != NULL)
577 if (mpVerticalScrollBar != NULL)
579 long nTmp = pEditEngine->GetTextHeight();
580 mpVerticalScrollBar->SetRange(Range(0, nTmp));
581 mpVerticalScrollBar->SetThumbPos(mpEditView->GetVisArea().Top());
583 if (mpHorizontalScrollBar != NULL)
585 long nTmp = pEditEngine->GetPaperSize().Width();
586 mpHorizontalScrollBar->SetRange(Range(0,nTmp));
587 mpHorizontalScrollBar->SetThumbPos(mpEditView->GetVisArea().Left());
592 void EditWindow::InitScrollBars()
594 if (mpEditView != NULL)
596 const Size aOut( mpEditView->GetOutputArea().GetSize() );
597 if (mpVerticalScrollBar != NULL)
599 mpVerticalScrollBar->SetVisibleSize(aOut.Height());
600 mpVerticalScrollBar->SetPageSize(aOut.Height() * 8 / 10);
601 mpVerticalScrollBar->SetLineSize(aOut.Height() * 2 / 10);
604 if (mpHorizontalScrollBar != NULL)
606 mpHorizontalScrollBar->SetVisibleSize(aOut.Width());
607 mpHorizontalScrollBar->SetPageSize(aOut.Width() * 8 / 10);
608 mpHorizontalScrollBar->SetLineSize(SCROLL_LINE );
611 SetScrollBarRanges();
613 if (mpVerticalScrollBar != NULL)
614 mpVerticalScrollBar->Show();
615 if (mpHorizontalScrollBar != NULL)
616 mpHorizontalScrollBar->Show();
617 if (mpScrollBox != NULL)
618 mpScrollBox->Show();
623 XubString EditWindow::GetText()
625 String aText;
626 EditEngine *pEditEngine = GetEditEngine();
627 DBG_ASSERT( pEditEngine, "EditEngine missing" );
628 if (pEditEngine)
629 aText = pEditEngine->GetText( LINEEND_LF );
630 return aText;
634 void EditWindow::SetText(const XubString& rText)
636 EditEngine *pEditEngine = GetEditEngine();
637 DBG_ASSERT( pEditEngine, "EditEngine missing" );
638 if (pEditEngine && !pEditEngine->IsModified())
640 if (!mpEditView)
641 CreateEditView();
643 ESelection eSelection = mpEditView->GetSelection();
645 pEditEngine->SetText(rText);
646 pEditEngine->ClearModifyFlag();
648 //! Hier die Timer neu zu starten verhindert, dass die Handler für andere
649 //! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden.
650 maModifyTimer.Start();
651 maCursorMoveTimer.Start();
653 mpEditView->SetSelection(eSelection);
658 void EditWindow::GetFocus()
660 Window::GetFocus();
662 if (!mpEditView)
663 CreateEditView();
664 if (mpEditEngine != NULL)
665 mpEditEngine->SetStatusEventHdl(
666 LINK(this, EditWindow, EditStatusHdl));
670 void EditWindow::LoseFocus()
672 if (mpEditEngine != NULL)
673 mpEditEngine->SetStatusEventHdl (Link());
675 Window::LoseFocus();
679 BOOL EditWindow::IsAllSelected() const
681 BOOL bRes = FALSE;
682 EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine();
683 DBG_ASSERT( mpEditView, "NULL pointer" );
684 DBG_ASSERT( pEditEngine, "NULL pointer" );
685 if (pEditEngine && mpEditView)
687 ESelection eSelection( mpEditView->GetSelection() );
688 INT32 nParaCnt = pEditEngine->GetParagraphCount();
689 if (!(nParaCnt - 1))
691 String Text( pEditEngine->GetText( LINEEND_LF ) );
692 bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1);
694 else
696 bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
699 return bRes;
702 void EditWindow::SelectAll()
704 DBG_ASSERT( mpEditView, "NULL pointer" );
705 if (mpEditView)
707 // 0xFFFF as last two parameters refers to the end of the text
708 mpEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
713 void EditWindow::MarkError(const Point &rPos)
715 DBG_ASSERT( mpEditView, "EditView missing" );
716 if (mpEditView)
718 const int Col = rPos.X();
719 const int Row = rPos.Y() - 1;
721 mpEditView->SetSelection(ESelection ( (USHORT)Row, (USHORT)(Col - 1), (USHORT)Row, (USHORT)Col));
722 GrabFocus();
726 void EditWindow::SelNextMark()
728 EditEngine *pEditEngine = GetEditEngine();
729 DBG_ASSERT( mpEditView, "NULL pointer" );
730 DBG_ASSERT( pEditEngine, "NULL pointer" );
731 if (pEditEngine && mpEditView)
733 ESelection eSelection = mpEditView->GetSelection();
734 USHORT Pos = eSelection.nEndPos;
735 String aMark (UniString::CreateFromAscii("<?>"));
736 String aText;
737 USHORT nCounts = pEditEngine->GetParagraphCount();
739 while (eSelection.nEndPara < nCounts)
741 aText = pEditEngine->GetText( eSelection.nEndPara );
742 Pos = aText.Search(aMark, Pos);
744 if (Pos != STRING_NOTFOUND)
746 mpEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3));
747 break;
750 Pos = 0;
751 eSelection.nEndPara++;
756 void EditWindow::SelPrevMark()
758 EditEngine *pEditEngine = GetEditEngine();
759 DBG_ASSERT( pEditEngine, "NULL pointer" );
760 DBG_ASSERT( mpEditView, "NULL pointer" );
761 if (pEditEngine && mpEditView)
763 ESelection eSelection = mpEditView->GetSelection();
764 USHORT Pos = STRING_NOTFOUND;
765 xub_StrLen Max = eSelection.nStartPos;
766 String Text( pEditEngine->GetText( eSelection.nStartPara ) );
767 String aMark (UniString::CreateFromAscii("<?>"));
768 USHORT nCounts = pEditEngine->GetParagraphCount();
772 USHORT Fnd = Text.Search(aMark, 0);
774 while ((Fnd < Max) && (Fnd != STRING_NOTFOUND))
776 Pos = Fnd;
777 Fnd = Text.Search(aMark, Fnd + 1);
780 if (Pos == STRING_NOTFOUND)
782 eSelection.nStartPara--;
783 Text = pEditEngine->GetText( eSelection.nStartPara );
784 Max = Text.Len();
787 while ((eSelection.nStartPara < nCounts) &&
788 (Pos == STRING_NOTFOUND));
790 if (Pos != STRING_NOTFOUND)
792 mpEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3));
797 BOOL EditWindow::HasMark(const String& rText) const
798 // returns true iff 'rText' contains a mark
800 return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND;
803 void EditWindow::MouseMove(const MouseEvent &rEvt)
805 if (mpEditView)
806 mpEditView->MouseMove(rEvt);
809 sal_Int8 EditWindow::AcceptDrop( const AcceptDropEvent& )
811 return mpEditView ? /*mpEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE;
814 sal_Int8 EditWindow::ExecuteDrop( const ExecuteDropEvent& )
816 return mpEditView ? /*mpEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE;
819 ESelection EditWindow::GetSelection() const
821 // pointer may be 0 when reloading a document and the old view
822 // was already destroyed
823 //(DBG_ASSERT( mpEditView, "NULL pointer" );
824 ESelection eSel;
825 if (mpEditView)
826 eSel = mpEditView->GetSelection();
827 return eSel;
830 void EditWindow::SetSelection(const ESelection &rSel)
832 DBG_ASSERT( mpEditView, "NULL pointer" );
833 if (mpEditView)
834 mpEditView->SetSelection(rSel);
837 BOOL EditWindow::IsEmpty() const
839 EditEngine *pEditEngine = ((EditWindow *) this)->GetEditEngine();
840 return (pEditEngine && (pEditEngine->GetTextLen() == 0)) ? TRUE : FALSE;
843 BOOL EditWindow::IsSelected() const
845 return mpEditView ? mpEditView->HasSelection() : FALSE;
848 void EditWindow::Cut()
850 DBG_ASSERT( mpEditView, "EditView missing" );
851 if (mpEditView)
852 mpEditView->Cut();
855 void EditWindow::Copy()
857 DBG_ASSERT( mpEditView, "EditView missing" );
858 if (mpEditView)
859 mpEditView->Copy();
862 void EditWindow::Paste()
864 DBG_ASSERT( mpEditView, "EditView missing" );
865 if (mpEditView)
866 mpEditView->Paste();
869 void EditWindow::Delete()
871 DBG_ASSERT( mpEditView, "EditView missing" );
872 if (mpEditView)
873 mpEditView->DeleteSelected();
876 void EditWindow::InsertText(const String& Text)
878 DBG_ASSERT( mpEditView, "EditView missing" );
879 ::vos::OGuard aGuard (::Application::GetSolarMutex());
880 if (mpEditView)
881 mpEditView->InsertText(Text);
886 } } // end of namespace ::sd::notes