1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_starmath.hxx"
32 #include <com/sun/star/accessibility/XAccessible.hpp>
33 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
34 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
35 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
36 #include <toolkit/helper/vclunohelper.hxx>
39 #include "starmath.hrc"
41 #define ITEMID_FONTHEIGHT 2
42 #define ITEMID_LRSPACE 3
43 #define ITEMID_WEIGHT 4
46 #include <vcl/menu.hxx>
47 #include <editeng/editview.hxx>
48 #include <editeng/editeng.hxx>
49 #include <editeng/editstat.hxx>
50 #include <editeng/eeitem.hxx>
51 #include <sfx2/dispatch.hxx>
52 #include <svl/intitem.hxx>
53 #include <svl/itempool.hxx>
54 #include <svl/stritem.hxx>
55 #include <editeng/fhgtitem.hxx>
56 #include <editeng/wghtitem.hxx>
57 #include <editeng/lrspitem.hxx>
58 #include <svl/itemset.hxx>
59 #include <editeng/fontitem.hxx>
60 #include <sfx2/viewfrm.hxx>
64 #include "document.hxx"
67 #define SCROLL_LINE 24
72 #define SPLITTERWIDTH 2
75 using namespace com::sun::star::accessibility
;
76 using namespace com::sun::star
;
77 using namespace com::sun::star::uno
;
79 ////////////////////////////////////////
82 void SmGetLeftSelectionPart(const ESelection aSel
,
83 USHORT
&nPara
, USHORT
&nPos
)
84 // returns paragraph number and position of the selections left part
86 // compare start and end of selection and use the one that comes first
87 if ( aSel
.nStartPara
< aSel
.nEndPara
88 || (aSel
.nStartPara
== aSel
.nEndPara
&& aSel
.nStartPos
< aSel
.nEndPos
) )
89 { nPara
= aSel
.nStartPara
;
90 nPos
= aSel
.nStartPos
;
93 { nPara
= aSel
.nEndPara
;
98 ////////////////////////////////////////
100 SmEditWindow::SmEditWindow( SmCmdBoxWindow
&rMyCmdBoxWin
) :
101 Window (&rMyCmdBoxWin
),
102 DropTargetHelper ( this ),
104 rCmdBox (rMyCmdBoxWin
),
110 SetHelpId(HID_SMA_COMMAND_WIN_EDIT
);
111 SetMapMode(MAP_PIXEL
);
113 // Even RTL languages don't use RTL for math
114 rCmdBox
.GetEditWindow()->EnableRTL( FALSE
);
116 ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
118 // compare DataChanged
119 SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
121 aModifyTimer
.SetTimeoutHdl(LINK(this, SmEditWindow
, ModifyTimerHdl
));
122 aModifyTimer
.SetTimeout(500);
124 aCursorMoveTimer
.SetTimeoutHdl(LINK(this, SmEditWindow
, CursorMoveTimerHdl
));
125 aCursorMoveTimer
.SetTimeout(500);
127 // if not called explicitly the this edit window within the
128 // command window will just show an empty gray panel.
133 SmEditWindow::~SmEditWindow()
135 aCursorMoveTimer
.Stop();
139 // #112565# clean up of classes used for accessibility
140 // must be done before EditView (and thus EditEngine) is no longer
141 // available for those classes.
143 pAccessible
->ClearWin(); // make Accessible defunctional
144 // Note: memory for pAccessible will be freed when the reference
145 // xAccessible is released.
149 EditEngine
*pEditEngine
= pEditView
->GetEditEngine();
152 pEditEngine
->SetStatusEventHdl( Link() );
153 pEditEngine
->RemoveView( pEditView
);
162 void SmEditWindow::InvalidateSlots()
164 SfxBindings
& rBind
= GetView()->GetViewFrame()->GetBindings();
165 rBind
.Invalidate(SID_COPY
);
166 rBind
.Invalidate(SID_CUT
);
167 rBind
.Invalidate(SID_DELETE
);
170 SmViewShell
* SmEditWindow::GetView()
172 return rCmdBox
.GetView();
176 SmDocShell
* SmEditWindow::GetDoc()
178 SmViewShell
*pView
= rCmdBox
.GetView();
179 return pView
? pView
->GetDoc() : 0;
183 EditEngine
* SmEditWindow::GetEditEngine()
185 EditEngine
*pEditEng
= 0;
187 pEditEng
= pEditView
->GetEditEngine();
190 SmDocShell
*pDoc
= GetDoc();
192 pEditEng
= &pDoc
->GetEditEngine();
198 SfxItemPool
* SmEditWindow::GetEditEngineItemPool()
200 SmDocShell
*pDoc
= GetDoc();
201 return pDoc
? &pDoc
->GetEditEngineItemPool() : 0;
204 void SmEditWindow::ApplyColorConfigValues( const svtools::ColorConfig
&rColorCfg
)
206 // Note: SetBackground still done in SmEditWindow::DataChanged
207 #if OSL_DEBUG_LEVEL > 1
208 // ColorData nVal = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
210 SetTextColor( rColorCfg
.GetColorValue(svtools::FONTCOLOR
).nColor
);
214 void SmEditWindow::DataChanged( const DataChangedEvent
& )
216 const StyleSettings
aSettings( GetSettings().GetStyleSettings() );
218 ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
219 SetBackground( aSettings
.GetWindowColor() );
221 // edit fields in other Applications use this font instead of
222 // the application font thus we use this one too
223 SetPointFont( aSettings
.GetFieldFont() /*aSettings.GetAppFont()*/ );
225 EditEngine
*pEditEngine
= GetEditEngine();
226 SfxItemPool
*pEditEngineItemPool
= GetEditEngineItemPool();
228 if (pEditEngine
&& pEditEngineItemPool
)
231 //! see also SmDocShell::GetEditEngine() !
234 pEditEngine
->SetDefTab( USHORT( GetTextWidth( C2S("XXXX") ) ) );
236 SetEditEngineDefaultFonts( *pEditEngine
, *pEditEngineItemPool
);
238 // forces new settings to be used
239 // unfortunately this resets the whole edit engine
240 // thus we need to save at least the text
241 String
aTxt( pEditEngine
->GetText( LINEEND_LF
) );
242 pEditEngine
->Clear(); //#77957 incorrect font size
243 pEditEngine
->SetText( aTxt
);
250 IMPL_LINK( SmEditWindow
, ModifyTimerHdl
, Timer
*, EMPTYARG
/*pTimer*/ )
252 SmModule
*pp
= SM_MOD();
253 if (pp
->GetConfig()->IsAutoRedraw())
260 IMPL_LINK(SmEditWindow
, CursorMoveTimerHdl
, Timer
*, EMPTYARG
/*pTimer*/)
261 // every once in a while check cursor position (selection) of edit
262 // window and if it has changed (try to) set the formula-cursor
263 // according to that.
265 ESelection
aNewSelection (GetSelection());
267 if (!aNewSelection
.IsEqual(aOldSelection
))
268 { SmViewShell
*pView
= rCmdBox
.GetView();
272 // get row and column to look for
274 SmGetLeftSelectionPart(aNewSelection
, nRow
, nCol
);
278 pView
->GetGraphicWindow().SetCursorPos(nRow
, nCol
);
280 aOldSelection
= aNewSelection
;
283 aCursorMoveTimer
.Stop();
289 void SmEditWindow::Resize()
296 pEditView
->SetOutputArea(AdjustScrollBars());
297 pEditView
->ShowCursor();
299 DBG_ASSERT( pEditView
->GetEditEngine(), "EditEngine missing" );
300 const long nMaxVisAreaStart
= pEditView
->GetEditEngine()->GetTextHeight() -
301 pEditView
->GetOutputArea().GetHeight();
302 if (pEditView
->GetVisArea().Top() > nMaxVisAreaStart
)
304 Rectangle
aVisArea(pEditView
->GetVisArea() );
305 aVisArea
.Top() = (nMaxVisAreaStart
> 0 ) ? nMaxVisAreaStart
: 0;
306 aVisArea
.SetSize(pEditView
->GetOutputArea().GetSize());
307 pEditView
->SetVisArea(aVisArea
);
308 pEditView
->ShowCursor();
315 void SmEditWindow::MouseButtonUp(const MouseEvent
&rEvt
)
318 pEditView
->MouseButtonUp(rEvt
);
320 Window::MouseButtonUp (rEvt
);
322 // ggf FormulaCursor neu positionieren
323 CursorMoveTimerHdl(&aCursorMoveTimer
);
327 void SmEditWindow::MouseButtonDown(const MouseEvent
&rEvt
)
330 pEditView
->MouseButtonDown(rEvt
);
332 Window::MouseButtonDown (rEvt
);
337 void SmEditWindow::Command(const CommandEvent
& rCEvt
)
339 BOOL bForwardEvt
= TRUE
;
340 if (rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
)
342 GetParent()->ToTop();
344 Point aPoint
= rCEvt
.GetMousePosPixel();
345 PopupMenu
* pPopupMenu
= new PopupMenu(SmResId(RID_COMMANDMENU
));
347 // added for replaceability of context menus #96085, #93782
349 ::com::sun::star::ui::ContextMenuExecuteEvent aEvent
;
350 aEvent
.SourceWindow
= VCLUnoHelper::GetInterface( this );
351 aEvent
.ExecutePosition
.X
= aPoint
.X();
352 aEvent
.ExecutePosition
.Y
= aPoint
.Y();
353 ::rtl::OUString sDummy
;
354 if ( GetView()->TryContextMenuInterception( *pPopupMenu
, sDummy
, pMenu
, aEvent
) )
359 pPopupMenu
= (PopupMenu
*) pMenu
;
363 pPopupMenu
->SetSelectHdl(LINK(this, SmEditWindow
, MenuSelectHdl
));
365 pPopupMenu
->Execute( this, aPoint
);
369 else if (rCEvt
.GetCommand() == COMMAND_WHEEL
)
370 bForwardEvt
= !HandleWheelCommands( rCEvt
);
375 pEditView
->Command( rCEvt
);
377 Window::Command (rCEvt
);
382 BOOL
SmEditWindow::HandleWheelCommands( const CommandEvent
&rCEvt
)
384 BOOL bCommandHandled
= FALSE
; // true if the CommandEvent needs not
385 // to be passed on (because it has fully
386 // been taken care of).
388 const CommandWheelData
* pWData
= rCEvt
.GetWheelData();
391 if (COMMAND_WHEEL_ZOOM
== pWData
->GetMode())
392 bCommandHandled
= TRUE
; // no zooming in Command window
394 bCommandHandled
= HandleScrollCommand( rCEvt
, pHScrollBar
, pVScrollBar
);
397 return bCommandHandled
;
401 IMPL_LINK_INLINE_START( SmEditWindow
, MenuSelectHdl
, Menu
*, pMenu
)
403 SmViewShell
*pViewSh
= rCmdBox
.GetView();
405 pViewSh
->GetViewFrame()->GetDispatcher()->Execute(
406 SID_INSERTCOMMAND
, SFX_CALLMODE_STANDARD
,
407 new SfxInt16Item(SID_INSERTCOMMAND
, pMenu
->GetCurItemId()), 0L);
410 IMPL_LINK_INLINE_END( SmEditWindow
, MenuSelectHdl
, Menu
*, pMenu
)
412 void SmEditWindow::KeyInput(const KeyEvent
& rKEvt
)
414 if (rKEvt
.GetKeyCode().GetCode() == KEY_ESCAPE
)
416 BOOL bCallBase
= TRUE
;
417 SfxViewShell
* pViewShell
= GetView();
418 if ( pViewShell
&& pViewShell
->ISA(SmViewShell
) )
420 // Terminate possible InPlace mode
421 bCallBase
= !pViewShell
->Escape();
424 Window::KeyInput( rKEvt
);
428 // Timer neu starten, um den Handler (auch bei laengeren Eingaben)
429 // moeglichst nur einmal am Ende aufzurufen.
430 aCursorMoveTimer
.Start();
432 DBG_ASSERT( pEditView
, "EditView missing (NULL pointer)" );
435 if ( !pEditView
->PostKeyEvent(rKEvt
) )
437 SmViewShell
*pView
= GetView();
438 if ( pView
&& !pView
->KeyInput(rKEvt
) )
440 /* fuert bei F1 (Hilfe) zum Zerstoeren von this! */
442 if ( aModifyTimer
.IsActive() )
444 Window::KeyInput(rKEvt
);
448 //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack
449 //im SFX) den Focus auf die View gesetzt
450 SfxViewShell
* pVShell
= GetView();
451 if ( pVShell
&& pVShell
->ISA(SmViewShell
) &&
452 ((SmViewShell
*)pVShell
)->GetGraphicWindow().HasFocus() )
460 // have doc-shell modified only for formula input/change and not
461 // cursor travelling and such things...
462 SmDocShell
*pDocShell
= GetDoc();
464 pDocShell
->SetModified( GetEditEngine()->IsModified() );
466 aModifyTimer
.Start();
473 void SmEditWindow::Paint(const Rectangle
& rRect
)
477 pEditView
->Paint(rRect
);
480 void SmEditWindow::CreateEditView()
482 EditEngine
*pEditEngine
= GetEditEngine();
484 //! pEditEngine and pEditView may be 0.
485 //! For example when the program is used by the document-converter
486 if (!pEditView
&& pEditEngine
)
488 pEditView
= new EditView( pEditEngine
, this );
489 pEditEngine
->InsertView( pEditView
);
492 pVScrollBar
= new ScrollBar(this, WinBits(WB_VSCROLL
));
494 pHScrollBar
= new ScrollBar(this, WinBits(WB_HSCROLL
));
496 pScrollBox
= new ScrollBarBox(this);
497 pVScrollBar
->SetScrollHdl(LINK(this, SmEditWindow
, ScrollHdl
));
498 pHScrollBar
->SetScrollHdl(LINK(this, SmEditWindow
, ScrollHdl
));
499 pVScrollBar
->EnableDrag( TRUE
);
500 pHScrollBar
->EnableDrag( TRUE
);
502 pEditView
->SetOutputArea(AdjustScrollBars());
504 ESelection eSelection
;
506 pEditView
->SetSelection(eSelection
);
508 pEditView
->ShowCursor(TRUE
, TRUE
);
510 pEditEngine
->SetStatusEventHdl( LINK(this, SmEditWindow
, EditStatusHdl
) );
511 SetPointer(pEditView
->GetPointer());
513 SetScrollBarRanges();
518 IMPL_LINK( SmEditWindow
, EditStatusHdl
, EditStatus
*, EMPTYARG
/*pStat*/ )
529 IMPL_LINK_INLINE_START( SmEditWindow
, ScrollHdl
, ScrollBar
*, EMPTYARG
/*pScrollBar*/ )
531 DBG_ASSERT(pEditView
, "EditView missing");
534 pEditView
->SetVisArea(Rectangle(Point(pHScrollBar
->GetThumbPos(),
535 pVScrollBar
->GetThumbPos()),
536 pEditView
->GetVisArea().GetSize()));
537 pEditView
->Invalidate();
541 IMPL_LINK_INLINE_END( SmEditWindow
, ScrollHdl
, ScrollBar
*, pScrollBar
)
543 Rectangle
SmEditWindow::AdjustScrollBars()
545 const Size
aOut( GetOutputSizePixel() );
547 Rectangle
aRect( aPoint
, aOut
);
549 if (pVScrollBar
&& pHScrollBar
&& pScrollBox
)
551 const long nTmp
= GetSettings().GetStyleSettings().GetScrollBarSize();
552 Point
aPt( aRect
.TopRight() ); aPt
.X() -= nTmp
-1L;
553 pVScrollBar
->SetPosSizePixel( aPt
, Size(nTmp
, aOut
.Height() - nTmp
));
555 aPt
= aRect
.BottomLeft(); aPt
.Y() -= nTmp
- 1L;
556 pHScrollBar
->SetPosSizePixel( aPt
, Size(aOut
.Width() - nTmp
, nTmp
));
558 aPt
.X() = pHScrollBar
->GetSizePixel().Width();
559 aPt
.Y() = pVScrollBar
->GetSizePixel().Height();
560 pScrollBox
->SetPosSizePixel(aPt
, Size(nTmp
, nTmp
));
562 aRect
.Right() = aPt
.X() - 2;
563 aRect
.Bottom() = aPt
.Y() - 2;
568 void SmEditWindow::SetScrollBarRanges()
570 // Extra-Methode, nicht InitScrollBars, da auch fuer EditEngine-Events.
571 EditEngine
*pEditEngine
= GetEditEngine();
572 if (pVScrollBar
&& pHScrollBar
&& pEditEngine
&& pEditView
)
574 long nTmp
= pEditEngine
->GetTextHeight();
575 pVScrollBar
->SetRange(Range(0, nTmp
));
576 pVScrollBar
->SetThumbPos(pEditView
->GetVisArea().Top());
578 nTmp
= pEditEngine
->GetPaperSize().Width();
579 pHScrollBar
->SetRange(Range(0,nTmp
));
580 pHScrollBar
->SetThumbPos(pEditView
->GetVisArea().Left());
584 void SmEditWindow::InitScrollBars()
586 if (pVScrollBar
&& pHScrollBar
&& pScrollBox
&& pEditView
)
588 const Size
aOut( pEditView
->GetOutputArea().GetSize() );
589 pVScrollBar
->SetVisibleSize(aOut
.Height());
590 pVScrollBar
->SetPageSize(aOut
.Height() * 8 / 10);
591 pVScrollBar
->SetLineSize(aOut
.Height() * 2 / 10);
593 pHScrollBar
->SetVisibleSize(aOut
.Width());
594 pHScrollBar
->SetPageSize(aOut
.Width() * 8 / 10);
595 pHScrollBar
->SetLineSize(SCROLL_LINE
);
597 SetScrollBarRanges();
606 String
SmEditWindow::GetText() const
609 EditEngine
*pEditEngine
= const_cast< SmEditWindow
* >(this)->GetEditEngine();
610 DBG_ASSERT( pEditEngine
, "EditEngine missing" );
612 aText
= pEditEngine
->GetText( LINEEND_LF
);
617 void SmEditWindow::SetText(const XubString
& rText
)
619 EditEngine
*pEditEngine
= GetEditEngine();
620 DBG_ASSERT( pEditEngine
, "EditEngine missing" );
621 if (pEditEngine
&& !pEditEngine
->IsModified())
626 ESelection eSelection
= pEditView
->GetSelection();
628 pEditEngine
->SetText(rText
);
629 pEditEngine
->ClearModifyFlag();
631 //! Hier die Timer neu zu starten verhindert, dass die Handler fuer andere
632 //! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden.
633 aModifyTimer
.Start();
634 aCursorMoveTimer
.Start();
636 pEditView
->SetSelection(eSelection
);
641 void SmEditWindow::GetFocus()
645 if (xAccessible
.is())
647 // Note: will implicitly send the AccessibleStateType::FOCUSED event
648 ::accessibility::AccessibleTextHelper
*pHelper
= pAccessible
->GetTextHelper();
650 pHelper
->SetFocus( sal_True
);
655 EditEngine
*pEditEngine
= GetEditEngine();
657 pEditEngine
->SetStatusEventHdl( LINK(this, SmEditWindow
, EditStatusHdl
) );
661 void SmEditWindow::LoseFocus()
663 EditEngine
*pEditEngine
= GetEditEngine();
665 pEditEngine
->SetStatusEventHdl( Link() );
669 if (xAccessible
.is())
671 // Note: will implicitly send the AccessibleStateType::FOCUSED event
672 ::accessibility::AccessibleTextHelper
*pHelper
= pAccessible
->GetTextHelper();
674 pHelper
->SetFocus( sal_False
);
679 BOOL
SmEditWindow::IsAllSelected() const
682 EditEngine
*pEditEngine
= ((SmEditWindow
*) this)->GetEditEngine();
683 DBG_ASSERT( pEditView
, "NULL pointer" );
684 DBG_ASSERT( pEditEngine
, "NULL pointer" );
685 if (pEditEngine
&& pEditView
)
687 ESelection
eSelection( pEditView
->GetSelection() );
688 INT32 nParaCnt
= pEditEngine
->GetParagraphCount();
691 String
Text( pEditEngine
->GetText( LINEEND_LF
) );
692 bRes
= !eSelection
.nStartPos
&& (eSelection
.nEndPos
== Text
.Len () - 1);
696 bRes
= !eSelection
.nStartPara
&& (eSelection
.nEndPara
== nParaCnt
- 1);
702 void SmEditWindow::SelectAll()
704 DBG_ASSERT( pEditView
, "NULL pointer" );
707 // 0xFFFF as last two parameters refers to the end of the text
708 pEditView
->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
712 void SmEditWindow::InsertCommand(USHORT nCommand
)
714 DBG_ASSERT( pEditView
, "EditView missing" );
717 //Anfang der Selektion merken und hinterher den Cursor daraufsetzen. Nur so
718 //macht das SelNextMark() Sinn.
719 ESelection aSelection
= pEditView
->GetSelection();
720 aSelection
.nEndPos
= aSelection
.nStartPos
;
721 aSelection
.nEndPara
= aSelection
.nStartPara
;
723 DBG_ASSERT( pEditView
, "NULL pointer" );
724 String aText
= String(SmResId(nCommand
));
725 pEditView
->InsertText(aText
);
728 { // set selection to next mark
729 pEditView
->SetSelection(aSelection
);
733 { // set selection after inserted text
734 aSelection
.nEndPos
= aSelection
.nEndPos
+ sal::static_int_cast
< xub_StrLen
>(aText
.Len());
735 aSelection
.nStartPos
= aSelection
.nEndPos
;
736 pEditView
->SetSelection(aSelection
);
739 aModifyTimer
.Start();
740 aCursorMoveTimer
.Start();
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" );
890 GetDoc()->SetModified( TRUE
);
894 void SmEditWindow::Copy()
896 DBG_ASSERT( pEditView
, "EditView missing" );
901 void SmEditWindow::Paste()
903 DBG_ASSERT( pEditView
, "EditView missing" );
907 GetDoc()->SetModified( TRUE
);
911 void SmEditWindow::Delete()
913 DBG_ASSERT( pEditView
, "EditView missing" );
916 pEditView
->DeleteSelected();
917 GetDoc()->SetModified( TRUE
);
921 void SmEditWindow::InsertText(const String
& Text
)
923 DBG_ASSERT( pEditView
, "EditView missing" );
926 pEditView
->InsertText(Text
);
927 aModifyTimer
.Start();
928 aCursorMoveTimer
.Start();
932 void SmEditWindow::Flush()
934 EditEngine
*pEditEngine
= GetEditEngine();
935 if (pEditEngine
&& pEditEngine
->IsModified())
937 pEditEngine
->ClearModifyFlag();
938 SmViewShell
*pViewSh
= rCmdBox
.GetView();
941 pViewSh
->GetViewFrame()->GetDispatcher()->Execute(
942 SID_TEXT
, SFX_CALLMODE_STANDARD
,
943 new SfxStringItem(SID_TEXT
, GetText()), 0L);
947 if (aCursorMoveTimer
.IsActive())
949 aCursorMoveTimer
.Stop();
950 // ggf noch die (neue) FormulaCursor Position setzen
951 CursorMoveTimerHdl(&aCursorMoveTimer
);
956 void SmEditWindow::DeleteEditView( SmViewShell
& /*rView*/ )
960 EditEngine
*pEditEngine
= pEditView
->GetEditEngine();
963 pEditEngine
->SetStatusEventHdl( Link() );
964 pEditEngine
->RemoveView( pEditView
);
972 uno::Reference
< XAccessible
> SmEditWindow::CreateAccessible()
976 pAccessible
= new SmEditAccessible( this );
977 xAccessible
= pAccessible
;