1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: edit.cxx,v $
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_starmath.hxx"
35 #include <com/sun/star/accessibility/XAccessible.hpp>
36 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
37 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
38 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
39 #include <toolkit/helper/vclunohelper.hxx>
42 #include "starmath.hrc"
44 #define ITEMID_FONTHEIGHT 2
45 #define ITEMID_LRSPACE 3
46 #define ITEMID_WEIGHT 4
49 #include <vcl/menu.hxx>
50 #include <svx/editview.hxx>
51 #include <svx/editeng.hxx>
52 #include <svx/editstat.hxx>
53 #include <svx/eeitem.hxx>
54 #include <sfx2/dispatch.hxx>
55 #include <svtools/intitem.hxx>
56 #include <svtools/itempool.hxx>
57 #include <svtools/stritem.hxx>
58 #include <svx/fhgtitem.hxx>
59 #include <svx/wghtitem.hxx>
60 #include <svx/lrspitem.hxx>
61 #include <svtools/itemset.hxx>
62 #include <svx/fontitem.hxx>
63 #include <sfx2/viewfrm.hxx>
67 #include "document.hxx"
70 #define SCROLL_LINE 24
75 #define SPLITTERWIDTH 2
78 using namespace com::sun::star::accessibility
;
79 using namespace com::sun::star
;
80 using namespace com::sun::star::uno
;
82 ////////////////////////////////////////
85 void SmGetLeftSelectionPart(const ESelection aSel
,
86 USHORT
&nPara
, USHORT
&nPos
)
87 // returns paragraph number and position of the selections left part
89 // compare start and end of selection and use the one that comes first
90 if ( aSel
.nStartPara
< aSel
.nEndPara
91 || (aSel
.nStartPara
== aSel
.nEndPara
&& aSel
.nStartPos
< aSel
.nEndPos
) )
92 { nPara
= aSel
.nStartPara
;
93 nPos
= aSel
.nStartPos
;
96 { nPara
= aSel
.nEndPara
;
101 ////////////////////////////////////////
103 SmEditWindow::SmEditWindow( SmCmdBoxWindow
&rMyCmdBoxWin
) :
104 Window (&rMyCmdBoxWin
),
105 DropTargetHelper ( this ),
107 rCmdBox (rMyCmdBoxWin
),
113 SetHelpId(HID_SMA_COMMAND_WIN_EDIT
);
114 SetMapMode(MAP_PIXEL
);
116 // Even RTL languages don't use RTL for math
117 rCmdBox
.GetEditWindow()->EnableRTL( FALSE
);
119 ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
121 // compare DataChanged
122 SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
124 aModifyTimer
.SetTimeoutHdl(LINK(this, SmEditWindow
, ModifyTimerHdl
));
125 aModifyTimer
.SetTimeout(2000);
126 aModifyTimer
.Start();
128 aCursorMoveTimer
.SetTimeoutHdl(LINK(this, SmEditWindow
, CursorMoveTimerHdl
));
129 aCursorMoveTimer
.SetTimeout(500);
131 // if not called explicitly the this edit window within the
132 // command window will just show an empty gray panel.
137 SmEditWindow::~SmEditWindow()
139 aCursorMoveTimer
.Stop();
143 // #112565# clean up of classes used for accessibility
144 // must be done before EditView (and thus EditEngine) is no longer
145 // available for those classes.
147 pAccessible
->ClearWin(); // make Accessible defunctional
148 // Note: memory for pAccessible will be freed when the reference
149 // xAccessible is released.
153 EditEngine
*pEditEngine
= pEditView
->GetEditEngine();
156 pEditEngine
->SetStatusEventHdl( Link() );
157 pEditEngine
->RemoveView( pEditView
);
166 void SmEditWindow::InvalidateSlots()
168 SfxBindings
& rBind
= GetView()->GetViewFrame()->GetBindings();
169 rBind
.Invalidate(SID_COPY
);
170 rBind
.Invalidate(SID_CUT
);
171 rBind
.Invalidate(SID_DELETE
);
174 SmViewShell
* SmEditWindow::GetView()
176 return rCmdBox
.GetView();
180 SmDocShell
* SmEditWindow::GetDoc()
182 SmViewShell
*pView
= rCmdBox
.GetView();
183 return pView
? pView
->GetDoc() : 0;
187 EditEngine
* SmEditWindow::GetEditEngine()
189 EditEngine
*pEditEng
= 0;
191 pEditEng
= pEditView
->GetEditEngine();
194 SmDocShell
*pDoc
= GetDoc();
196 pEditEng
= &pDoc
->GetEditEngine();
202 SfxItemPool
* SmEditWindow::GetEditEngineItemPool()
204 SmDocShell
*pDoc
= GetDoc();
205 return pDoc
? &pDoc
->GetEditEngineItemPool() : 0;
208 void SmEditWindow::ApplyColorConfigValues( const svtools::ColorConfig
&rColorCfg
)
210 // Note: SetBackground still done in SmEditWindow::DataChanged
211 #if OSL_DEBUG_LEVEL > 1
212 // ColorData nVal = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
214 SetTextColor( rColorCfg
.GetColorValue(svtools::FONTCOLOR
).nColor
);
218 void SmEditWindow::DataChanged( const DataChangedEvent
& )
220 const StyleSettings
aSettings( GetSettings().GetStyleSettings() );
222 ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
223 SetBackground( aSettings
.GetWindowColor() );
225 // edit fields in other Applications use this font instead of
226 // the application font thus we use this one too
227 SetPointFont( aSettings
.GetFieldFont() /*aSettings.GetAppFont()*/ );
229 EditEngine
*pEditEngine
= GetEditEngine();
230 SfxItemPool
*pEditEngineItemPool
= GetEditEngineItemPool();
232 if (pEditEngine
&& pEditEngineItemPool
)
235 //! see also SmDocShell::GetEditEngine() !
238 pEditEngine
->SetDefTab( USHORT( GetTextWidth( C2S("XXXX") ) ) );
240 SetEditEngineDefaultFonts( *pEditEngine
, *pEditEngineItemPool
);
242 // forces new settings to be used
243 // unfortunately this resets the whole edit engine
244 // thus we need to save at least the text
245 String
aTxt( pEditEngine
->GetText( LINEEND_LF
) );
246 pEditEngine
->Clear(); //#77957 incorrect font size
247 pEditEngine
->SetText( aTxt
);
254 IMPL_LINK( SmEditWindow
, ModifyTimerHdl
, Timer
*, EMPTYARG
/*pTimer*/ )
256 SmModule
*pp
= SM_MOD1();
257 if (pp
->GetConfig()->IsAutoRedraw())
259 aModifyTimer
.Start();
264 IMPL_LINK(SmEditWindow
, CursorMoveTimerHdl
, Timer
*, EMPTYARG
/*pTimer*/)
265 // every once in a while check cursor position (selection) of edit
266 // window and if it has changed (try to) set the formula-cursor
267 // according to that.
269 ESelection
aNewSelection (GetSelection());
271 if (!aNewSelection
.IsEqual(aOldSelection
))
272 { SmViewShell
*pView
= rCmdBox
.GetView();
276 // get row and column to look for
278 SmGetLeftSelectionPart(aNewSelection
, nRow
, nCol
);
282 pView
->GetGraphicWindow().SetCursorPos(nRow
, nCol
);
284 aOldSelection
= aNewSelection
;
292 void SmEditWindow::Resize()
299 pEditView
->SetOutputArea(AdjustScrollBars());
300 pEditView
->ShowCursor();
302 DBG_ASSERT( pEditView
->GetEditEngine(), "EditEngine missing" );
303 const long nMaxVisAreaStart
= pEditView
->GetEditEngine()->GetTextHeight() -
304 pEditView
->GetOutputArea().GetHeight();
305 if (pEditView
->GetVisArea().Top() > nMaxVisAreaStart
)
307 Rectangle
aVisArea(pEditView
->GetVisArea() );
308 aVisArea
.Top() = (nMaxVisAreaStart
> 0 ) ? nMaxVisAreaStart
: 0;
309 aVisArea
.SetSize(pEditView
->GetOutputArea().GetSize());
310 pEditView
->SetVisArea(aVisArea
);
311 pEditView
->ShowCursor();
318 void SmEditWindow::MouseButtonUp(const MouseEvent
&rEvt
)
321 pEditView
->MouseButtonUp(rEvt
);
323 Window::MouseButtonUp (rEvt
);
325 // ggf FormulaCursor neu positionieren
326 CursorMoveTimerHdl(&aCursorMoveTimer
);
330 void SmEditWindow::MouseButtonDown(const MouseEvent
&rEvt
)
333 pEditView
->MouseButtonDown(rEvt
);
335 Window::MouseButtonDown (rEvt
);
340 void SmEditWindow::Command(const CommandEvent
& rCEvt
)
342 BOOL bForwardEvt
= TRUE
;
343 if (rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
)
345 GetParent()->ToTop();
347 Point aPoint
= rCEvt
.GetMousePosPixel();
348 PopupMenu
* pPopupMenu
= new PopupMenu(SmResId(RID_COMMANDMENU
));
350 // added for replaceability of context menus #96085, #93782
352 ::com::sun::star::ui::ContextMenuExecuteEvent aEvent
;
353 aEvent
.SourceWindow
= VCLUnoHelper::GetInterface( this );
354 aEvent
.ExecutePosition
.X
= aPoint
.X();
355 aEvent
.ExecutePosition
.Y
= aPoint
.Y();
356 ::rtl::OUString sDummy
;
357 if ( GetView()->TryContextMenuInterception( *pPopupMenu
, sDummy
, pMenu
, aEvent
) )
362 pPopupMenu
= (PopupMenu
*) pMenu
;
366 pPopupMenu
->SetSelectHdl(LINK(this, SmEditWindow
, MenuSelectHdl
));
368 pPopupMenu
->Execute( this, aPoint
);
372 else if (rCEvt
.GetCommand() == COMMAND_WHEEL
)
373 bForwardEvt
= !HandleWheelCommands( rCEvt
);
378 pEditView
->Command( rCEvt
);
380 Window::Command (rCEvt
);
385 BOOL
SmEditWindow::HandleWheelCommands( const CommandEvent
&rCEvt
)
387 BOOL bCommandHandled
= FALSE
; // true if the CommandEvent needs not
388 // to be passed on (because it has fully
389 // been taken care of).
391 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
394 if (COMMAND_WHEEL_ZOOM
== pWData
->GetMode())
395 bCommandHandled
= TRUE
; // no zooming in Command window
397 bCommandHandled
= HandleScrollCommand( rCEvt
, pHScrollBar
, pVScrollBar
);
400 return bCommandHandled
;
404 IMPL_LINK_INLINE_START( SmEditWindow
, MenuSelectHdl
, Menu
*, pMenu
)
406 SmViewShell
*pViewSh
= rCmdBox
.GetView();
408 pViewSh
->GetViewFrame()->GetDispatcher()->Execute(
409 SID_INSERTCOMMAND
, SFX_CALLMODE_STANDARD
,
410 new SfxInt16Item(SID_INSERTCOMMAND
, pMenu
->GetCurItemId()), 0L);
413 IMPL_LINK_INLINE_END( SmEditWindow
, MenuSelectHdl
, Menu
*, pMenu
)
415 void SmEditWindow::KeyInput(const KeyEvent
& rKEvt
)
417 if (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
419 BOOL bCallBase
= TRUE
;
420 SfxViewShell
* pViewShell
= GetView();
421 if ( pViewShell
&& pViewShell
->ISA(SmViewShell
) )
423 // Terminate possible InPlace mode
424 bCallBase
= !pViewShell
->Escape();
427 Window::KeyInput( rKEvt
);
431 // Timer neu starten, um den Handler (auch bei laengeren Eingaben)
432 // moeglichst nur einmal am Ende aufzurufen.
433 aCursorMoveTimer
.Start();
435 DBG_ASSERT( pEditView
, "EditView missing (NULL pointer)" );
438 if ( !pEditView
->PostKeyEvent(rKEvt
) )
440 SmViewShell
*pView
= GetView();
441 if ( pView
&& !pView
->KeyInput(rKEvt
) )
443 /* fuert bei F1 (Hilfe) zum Zerstoeren von this! */
445 if ( aModifyTimer
.IsActive() )
447 Window::KeyInput(rKEvt
);
451 //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack
452 //im SFX) den Focus auf die View gesetzt
453 SfxViewShell
* pVShell
= GetView();
454 if ( pVShell
&& pVShell
->ISA(SmViewShell
) &&
455 ((SmViewShell
*)pVShell
)->GetGraphicWindow().HasFocus() )
463 // have doc-shell modified only for formula input/change and not
464 // cursor travelling and such things...
465 SmDocShell
*pDocShell
= GetDoc();
467 pDocShell
->SetModified( GetEditEngine()->IsModified() );
469 aModifyTimer
.Start();
476 void SmEditWindow::Paint(const Rectangle
& rRect
)
480 pEditView
->Paint(rRect
);
483 void SmEditWindow::CreateEditView()
485 EditEngine
*pEditEngine
= GetEditEngine();
487 //! pEditEngine and pEditView may be 0.
488 //! For example when the program is used by the document-converter
489 if (!pEditView
&& pEditEngine
)
491 pEditView
= new EditView( pEditEngine
, this );
492 pEditEngine
->InsertView( pEditView
);
495 pVScrollBar
= new ScrollBar(this, WinBits(WB_VSCROLL
));
497 pHScrollBar
= new ScrollBar(this, WinBits(WB_HSCROLL
));
499 pScrollBox
= new ScrollBarBox(this);
500 pVScrollBar
->SetScrollHdl(LINK(this, SmEditWindow
, ScrollHdl
));
501 pHScrollBar
->SetScrollHdl(LINK(this, SmEditWindow
, ScrollHdl
));
502 pVScrollBar
->EnableDrag( TRUE
);
503 pHScrollBar
->EnableDrag( TRUE
);
505 pEditView
->SetOutputArea(AdjustScrollBars());
507 ESelection eSelection
;
509 pEditView
->SetSelection(eSelection
);
511 pEditView
->ShowCursor(TRUE
, TRUE
);
513 pEditEngine
->SetStatusEventHdl( LINK(this, SmEditWindow
, EditStatusHdl
) );
514 SetPointer(pEditView
->GetPointer());
516 SetScrollBarRanges();
521 IMPL_LINK( SmEditWindow
, EditStatusHdl
, EditStatus
*, EMPTYARG
/*pStat*/ )
532 IMPL_LINK_INLINE_START( SmEditWindow
, ScrollHdl
, ScrollBar
*, EMPTYARG
/*pScrollBar*/ )
534 DBG_ASSERT(pEditView
, "EditView missing");
537 pEditView
->SetVisArea(Rectangle(Point(pHScrollBar
->GetThumbPos(),
538 pVScrollBar
->GetThumbPos()),
539 pEditView
->GetVisArea().GetSize()));
540 pEditView
->Invalidate();
544 IMPL_LINK_INLINE_END( SmEditWindow
, ScrollHdl
, ScrollBar
*, pScrollBar
)
546 Rectangle
SmEditWindow::AdjustScrollBars()
548 const Size
aOut( GetOutputSizePixel() );
550 Rectangle
aRect( aPoint
, aOut
);
552 if (pVScrollBar
&& pHScrollBar
&& pScrollBox
)
554 const long nTmp
= GetSettings().GetStyleSettings().GetScrollBarSize();
555 Point
aPt( aRect
.TopRight() ); aPt
.X() -= nTmp
-1L;
556 pVScrollBar
->SetPosSizePixel( aPt
, Size(nTmp
, aOut
.Height() - nTmp
));
558 aPt
= aRect
.BottomLeft(); aPt
.Y() -= nTmp
- 1L;
559 pHScrollBar
->SetPosSizePixel( aPt
, Size(aOut
.Width() - nTmp
, nTmp
));
561 aPt
.X() = pHScrollBar
->GetSizePixel().Width();
562 aPt
.Y() = pVScrollBar
->GetSizePixel().Height();
563 pScrollBox
->SetPosSizePixel(aPt
, Size(nTmp
, nTmp
));
565 aRect
.Right() = aPt
.X() - 2;
566 aRect
.Bottom() = aPt
.Y() - 2;
571 void SmEditWindow::SetScrollBarRanges()
573 // Extra-Methode, nicht InitScrollBars, da auch fuer EditEngine-Events.
574 EditEngine
*pEditEngine
= GetEditEngine();
575 if (pVScrollBar
&& pHScrollBar
&& pEditEngine
&& pEditView
)
577 long nTmp
= pEditEngine
->GetTextHeight();
578 pVScrollBar
->SetRange(Range(0, nTmp
));
579 pVScrollBar
->SetThumbPos(pEditView
->GetVisArea().Top());
581 nTmp
= pEditEngine
->GetPaperSize().Width();
582 pHScrollBar
->SetRange(Range(0,nTmp
));
583 pHScrollBar
->SetThumbPos(pEditView
->GetVisArea().Left());
587 void SmEditWindow::InitScrollBars()
589 if (pVScrollBar
&& pHScrollBar
&& pScrollBox
&& pEditView
)
591 const Size
aOut( pEditView
->GetOutputArea().GetSize() );
592 pVScrollBar
->SetVisibleSize(aOut
.Height());
593 pVScrollBar
->SetPageSize(aOut
.Height() * 8 / 10);
594 pVScrollBar
->SetLineSize(aOut
.Height() * 2 / 10);
596 pHScrollBar
->SetVisibleSize(aOut
.Width());
597 pHScrollBar
->SetPageSize(aOut
.Width() * 8 / 10);
598 pHScrollBar
->SetLineSize(SCROLL_LINE
);
600 SetScrollBarRanges();
609 String
SmEditWindow::GetText() const
612 EditEngine
*pEditEngine
= const_cast< SmEditWindow
* >(this)->GetEditEngine();
613 DBG_ASSERT( pEditEngine
, "EditEngine missing" );
615 aText
= pEditEngine
->GetText( LINEEND_LF
);
620 void SmEditWindow::SetText(const XubString
& rText
)
622 EditEngine
*pEditEngine
= GetEditEngine();
623 DBG_ASSERT( pEditEngine
, "EditEngine missing" );
624 if (pEditEngine
&& !pEditEngine
->IsModified())
629 ESelection eSelection
= pEditView
->GetSelection();
631 pEditEngine
->SetText(rText
);
632 pEditEngine
->ClearModifyFlag();
634 //! Hier die Timer neu zu starten verhindert, dass die Handler fuer andere
635 //! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden.
636 aModifyTimer
.Start();
637 aCursorMoveTimer
.Start();
639 pEditView
->SetSelection(eSelection
);
644 void SmEditWindow::GetFocus()
648 if (xAccessible
.is())
650 // Note: will implicitly send the AccessibleStateType::FOCUSED event
651 ::accessibility::AccessibleTextHelper
*pHelper
= pAccessible
->GetTextHelper();
653 pHelper
->SetFocus( sal_True
);
658 EditEngine
*pEditEngine
= GetEditEngine();
660 pEditEngine
->SetStatusEventHdl( LINK(this, SmEditWindow
, EditStatusHdl
) );
664 void SmEditWindow::LoseFocus()
666 EditEngine
*pEditEngine
= GetEditEngine();
668 pEditEngine
->SetStatusEventHdl( Link() );
672 if (xAccessible
.is())
674 // Note: will implicitly send the AccessibleStateType::FOCUSED event
675 ::accessibility::AccessibleTextHelper
*pHelper
= pAccessible
->GetTextHelper();
677 pHelper
->SetFocus( sal_False
);
682 BOOL
SmEditWindow::IsAllSelected() const
685 EditEngine
*pEditEngine
= ((SmEditWindow
*) this)->GetEditEngine();
686 DBG_ASSERT( pEditView
, "NULL pointer" );
687 DBG_ASSERT( pEditEngine
, "NULL pointer" );
688 if (pEditEngine
&& pEditView
)
690 ESelection
eSelection( pEditView
->GetSelection() );
691 INT32 nParaCnt
= pEditEngine
->GetParagraphCount();
694 String
Text( pEditEngine
->GetText( LINEEND_LF
) );
695 bRes
= !eSelection
.nStartPos
&& (eSelection
.nEndPos
== Text
.Len () - 1);
699 bRes
= !eSelection
.nStartPara
&& (eSelection
.nEndPara
== nParaCnt
- 1);
705 void SmEditWindow::SelectAll()
707 DBG_ASSERT( pEditView
, "NULL pointer" );
710 // 0xFFFF as last two parameters refers to the end of the text
711 pEditView
->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
715 void SmEditWindow::InsertCommand(USHORT nCommand
)
717 DBG_ASSERT( pEditView
, "EditView missing" );
720 //Anfang der Selektion merken und hinterher den Cursor daraufsetzen. Nur so
721 //macht das SelNextMark() Sinn.
722 ESelection aSelection
= pEditView
->GetSelection();
723 aSelection
.nEndPos
= aSelection
.nStartPos
;
724 aSelection
.nEndPara
= aSelection
.nStartPara
;
726 DBG_ASSERT( pEditView
, "NULL pointer" );
727 String aText
= String(SmResId(nCommand
));
728 pEditView
->InsertText(aText
);
731 { // set selection to next mark
732 pEditView
->SetSelection(aSelection
);
736 { // set selection after inserted text
737 aSelection
.nEndPos
= aSelection
.nEndPos
+ sal::static_int_cast
< xub_StrLen
>(aText
.Len());
738 aSelection
.nStartPos
= aSelection
.nEndPos
;
739 pEditView
->SetSelection(aSelection
);
746 void SmEditWindow::MarkError(const Point
&rPos
)
748 DBG_ASSERT( pEditView
, "EditView missing" );
751 const xub_StrLen nCol
= sal::static_int_cast
< xub_StrLen
>(rPos
.X());
752 const USHORT nRow
= sal::static_int_cast
< USHORT
>(rPos
.Y() - 1);
754 pEditView
->SetSelection(ESelection(nRow
, nCol
- 1, nRow
, nCol
));
759 void SmEditWindow::SelNextMark()
761 EditEngine
*pEditEngine
= GetEditEngine();
762 DBG_ASSERT( pEditView
, "NULL pointer" );
763 DBG_ASSERT( pEditEngine
, "NULL pointer" );
764 if (pEditEngine
&& pEditView
)
766 ESelection eSelection
= pEditView
->GetSelection();
767 USHORT Pos
= eSelection
.nEndPos
;
768 String
aMark (C2S("<?>"));
770 USHORT nCounts
= pEditEngine
->GetParagraphCount();
772 while (eSelection
.nEndPara
< nCounts
)
774 aText
= pEditEngine
->GetText( eSelection
.nEndPara
);
775 Pos
= aText
.Search(aMark
, Pos
);
777 if (Pos
!= STRING_NOTFOUND
)
779 pEditView
->SetSelection(ESelection (eSelection
.nEndPara
, Pos
, eSelection
.nEndPara
, Pos
+ 3));
784 eSelection
.nEndPara
++;
789 void SmEditWindow::SelPrevMark()
791 EditEngine
*pEditEngine
= GetEditEngine();
792 DBG_ASSERT( pEditEngine
, "NULL pointer" );
793 DBG_ASSERT( pEditView
, "NULL pointer" );
794 if (pEditEngine
&& pEditView
)
796 ESelection eSelection
= pEditView
->GetSelection();
797 USHORT Pos
= STRING_NOTFOUND
;
798 xub_StrLen Max
= eSelection
.nStartPos
;
799 String
Text( pEditEngine
->GetText( eSelection
.nStartPara
) );
800 String
aMark (C2S("<?>"));
801 USHORT nCounts
= pEditEngine
->GetParagraphCount();
805 USHORT Fnd
= Text
.Search(aMark
, 0);
807 while ((Fnd
< Max
) && (Fnd
!= STRING_NOTFOUND
))
810 Fnd
= Text
.Search(aMark
, Fnd
+ 1);
813 if (Pos
== STRING_NOTFOUND
)
815 eSelection
.nStartPara
--;
816 Text
= pEditEngine
->GetText( eSelection
.nStartPara
);
820 while ((eSelection
.nStartPara
< nCounts
) &&
821 (Pos
== STRING_NOTFOUND
));
823 if (Pos
!= STRING_NOTFOUND
)
825 pEditView
->SetSelection(ESelection (eSelection
.nStartPara
, Pos
, eSelection
.nStartPara
, Pos
+ 3));
830 BOOL
SmEditWindow::HasMark(const String
& rText
) const
831 // returns true iff 'rText' contains a mark
833 return rText
.SearchAscii("<?>", 0) != STRING_NOTFOUND
;
836 void SmEditWindow::MouseMove(const MouseEvent
&rEvt
)
839 pEditView
->MouseMove(rEvt
);
842 sal_Int8
SmEditWindow::AcceptDrop( const AcceptDropEvent
& /*rEvt*/ )
844 return pEditView
? /*pEditView->QueryDrop( rEvt )*/DND_ACTION_NONE
: DND_ACTION_NONE
;
847 sal_Int8
SmEditWindow::ExecuteDrop( const ExecuteDropEvent
& /*rEvt*/ )
849 return pEditView
? /*pEditView->Drop( rEvt )*/DND_ACTION_NONE
: DND_ACTION_NONE
;
852 ESelection
SmEditWindow::GetSelection() const
854 // pointer may be 0 when reloading a document and the old view
855 // was already destroyed
856 //(DBG_ASSERT( pEditView, "NULL pointer" );
859 eSel
= pEditView
->GetSelection();
863 void SmEditWindow::SetSelection(const ESelection
&rSel
)
865 DBG_ASSERT( pEditView
, "NULL pointer" );
867 pEditView
->SetSelection(rSel
);
871 BOOL
SmEditWindow::IsEmpty() const
873 EditEngine
*pEditEngine
= ((SmEditWindow
*) this)->GetEditEngine();
874 BOOL bEmpty
= sal::static_int_cast
< BOOL
>(
875 pEditEngine
? pEditEngine
->GetTextLen() == 0 : FALSE
);
879 BOOL
SmEditWindow::IsSelected() const
881 return pEditView
? pEditView
->HasSelection() : FALSE
;
884 void SmEditWindow::Cut()
886 DBG_ASSERT( pEditView
, "EditView missing" );
891 void SmEditWindow::Copy()
893 DBG_ASSERT( pEditView
, "EditView missing" );
898 void SmEditWindow::Paste()
900 DBG_ASSERT( pEditView
, "EditView missing" );
905 void SmEditWindow::Delete()
907 DBG_ASSERT( pEditView
, "EditView missing" );
909 pEditView
->DeleteSelected();
912 void SmEditWindow::InsertText(const String
& Text
)
914 DBG_ASSERT( pEditView
, "EditView missing" );
916 pEditView
->InsertText(Text
);
919 void SmEditWindow::Flush()
921 EditEngine
*pEditEngine
= GetEditEngine();
922 if (pEditEngine
&& pEditEngine
->IsModified())
924 pEditEngine
->ClearModifyFlag();
925 SmViewShell
*pViewSh
= rCmdBox
.GetView();
927 pViewSh
->GetViewFrame()->GetDispatcher()->Execute(
928 SID_TEXT
, SFX_CALLMODE_STANDARD
,
929 new SfxStringItem(SID_TEXT
, GetText()), 0L);
932 if (aCursorMoveTimer
.IsActive())
934 aCursorMoveTimer
.Stop();
935 // ggf noch die (neue) FormulaCursor Position setzen
936 CursorMoveTimerHdl(&aCursorMoveTimer
);
941 void SmEditWindow::DeleteEditView( SmViewShell
& /*rView*/ )
945 EditEngine
*pEditEngine
= pEditView
->GetEditEngine();
948 pEditEngine
->SetStatusEventHdl( Link() );
949 pEditEngine
->RemoveView( pEditView
);
957 uno::Reference
< XAccessible
> SmEditWindow::CreateAccessible()
961 pAccessible
= new SmEditAccessible( this );
962 xAccessible
= pAccessible
;