CWS-TOOLING: integrate CWS tl88
[LibreOffice.git] / starmath / source / edit.cxx
blob020376c05dfbefd238f83e073ccdd12dd38e2ef7
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"
40 #define ITEMID_FONT 1
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>
62 #include "edit.hxx"
63 #include "view.hxx"
64 #include "document.hxx"
65 #include "config.hxx"
67 #define SCROLL_LINE 24
69 #define MINWIDTH 200
70 #define MINHEIGHT 200
71 #define MINSPLIT 40
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;
92 else
93 { nPara = aSel.nEndPara;
94 nPos = aSel.nEndPos;
98 ////////////////////////////////////////
100 SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
101 Window (&rMyCmdBoxWin),
102 DropTargetHelper ( this ),
103 pAccessible (0),
104 rCmdBox (rMyCmdBoxWin),
105 pEditView (0),
106 pHScrollBar (0),
107 pVScrollBar (0),
108 pScrollBox (0)
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.
129 Show();
133 SmEditWindow::~SmEditWindow()
135 aCursorMoveTimer.Stop();
136 aModifyTimer.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.
142 if (pAccessible)
143 pAccessible->ClearWin(); // make Accessible defunctional
144 // Note: memory for pAccessible will be freed when the reference
145 // xAccessible is released.
147 if (pEditView)
149 EditEngine *pEditEngine = pEditView->GetEditEngine();
150 if (pEditEngine)
152 pEditEngine->SetStatusEventHdl( Link() );
153 pEditEngine->RemoveView( pEditView );
156 delete pEditView;
157 delete pHScrollBar;
158 delete pVScrollBar;
159 delete pScrollBox;
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;
186 if (pEditView)
187 pEditEng = pEditView->GetEditEngine();
188 else
190 SmDocShell *pDoc = GetDoc();
191 if (pDoc)
192 pEditEng = &pDoc->GetEditEngine();
194 return pEditEng;
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;
209 #endif
210 SetTextColor( rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor );
211 Invalidate();
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 );
246 AdjustScrollBars();
247 Resize();
250 IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
252 SmModule *pp = SM_MOD();
253 if (pp->GetConfig()->IsAutoRedraw())
254 Flush();
255 aModifyTimer.Stop();
256 return 0;
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();
270 if (pView)
272 // get row and column to look for
273 USHORT nRow, nCol;
274 SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
275 nRow++;
276 nCol++;
278 pView->GetGraphicWindow().SetCursorPos(nRow, nCol);
280 aOldSelection = aNewSelection;
283 aCursorMoveTimer.Stop();
285 return 0;
289 void SmEditWindow::Resize()
291 if (!pEditView)
292 CreateEditView();
294 if (pEditView)
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();
310 InitScrollBars();
312 Invalidate();
315 void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
317 if (pEditView)
318 pEditView->MouseButtonUp(rEvt);
319 else
320 Window::MouseButtonUp (rEvt);
322 // ggf FormulaCursor neu positionieren
323 CursorMoveTimerHdl(&aCursorMoveTimer);
324 InvalidateSlots();
327 void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)
329 if (pEditView)
330 pEditView->MouseButtonDown(rEvt);
331 else
332 Window::MouseButtonDown (rEvt);
334 GrabFocus();
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
348 Menu* pMenu = NULL;
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 ) )
356 if ( pMenu )
358 delete pPopupMenu;
359 pPopupMenu = (PopupMenu*) pMenu;
363 pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl));
365 pPopupMenu->Execute( this, aPoint );
366 delete pPopupMenu;
367 bForwardEvt = FALSE;
369 else if (rCEvt.GetCommand() == COMMAND_WHEEL)
370 bForwardEvt = !HandleWheelCommands( rCEvt );
372 if (bForwardEvt)
374 if (pEditView)
375 pEditView->Command( rCEvt );
376 else
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();
389 if (pWData)
391 if (COMMAND_WHEEL_ZOOM == pWData->GetMode())
392 bCommandHandled = TRUE; // no zooming in Command window
393 else
394 bCommandHandled = HandleScrollCommand( rCEvt, pHScrollBar, pVScrollBar);
397 return bCommandHandled;
401 IMPL_LINK_INLINE_START( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
403 SmViewShell *pViewSh = rCmdBox.GetView();
404 if (pViewSh)
405 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
406 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
407 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
408 return 0;
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();
423 if ( bCallBase )
424 Window::KeyInput( rKEvt );
426 else
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)" );
433 if (!pEditView)
434 CreateEditView();
435 if ( !pEditView->PostKeyEvent(rKEvt) )
437 SmViewShell *pView = GetView();
438 if ( pView && !pView->KeyInput(rKEvt) )
440 /* fuert bei F1 (Hilfe) zum Zerstoeren von this! */
441 Flush();
442 if ( aModifyTimer.IsActive() )
443 aModifyTimer.Stop();
444 Window::KeyInput(rKEvt);
446 else
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() )
454 GrabFocus();
458 else
460 // have doc-shell modified only for formula input/change and not
461 // cursor travelling and such things...
462 SmDocShell *pDocShell = GetDoc();
463 if (pDocShell)
464 pDocShell->SetModified( GetEditEngine()->IsModified() );
466 aModifyTimer.Start();
469 InvalidateSlots();
473 void SmEditWindow::Paint(const Rectangle& rRect)
475 if (!pEditView)
476 CreateEditView();
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 );
491 if (!pVScrollBar)
492 pVScrollBar = new ScrollBar(this, WinBits(WB_VSCROLL));
493 if (!pHScrollBar)
494 pHScrollBar = new ScrollBar(this, WinBits(WB_HSCROLL));
495 if (!pScrollBox)
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);
507 Update();
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*/ )
520 if (!pEditView)
521 return 1;
522 else
524 Resize();
525 return 0;
529 IMPL_LINK_INLINE_START( SmEditWindow, ScrollHdl, ScrollBar *, EMPTYARG /*pScrollBar*/ )
531 DBG_ASSERT(pEditView, "EditView missing");
532 if (pEditView)
534 pEditView->SetVisArea(Rectangle(Point(pHScrollBar->GetThumbPos(),
535 pVScrollBar->GetThumbPos()),
536 pEditView->GetVisArea().GetSize()));
537 pEditView->Invalidate();
539 return 0;
541 IMPL_LINK_INLINE_END( SmEditWindow, ScrollHdl, ScrollBar *, pScrollBar )
543 Rectangle SmEditWindow::AdjustScrollBars()
545 const Size aOut( GetOutputSizePixel() );
546 Point aPoint;
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;
565 return aRect;
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();
599 pVScrollBar->Show();
600 pHScrollBar->Show();
601 pScrollBox->Show();
606 String SmEditWindow::GetText() const
608 String aText;
609 EditEngine *pEditEngine = const_cast< SmEditWindow* >(this)->GetEditEngine();
610 DBG_ASSERT( pEditEngine, "EditEngine missing" );
611 if (pEditEngine)
612 aText = pEditEngine->GetText( LINEEND_LF );
613 return aText;
617 void SmEditWindow::SetText(const XubString& rText)
619 EditEngine *pEditEngine = GetEditEngine();
620 DBG_ASSERT( pEditEngine, "EditEngine missing" );
621 if (pEditEngine && !pEditEngine->IsModified())
623 if (!pEditView)
624 CreateEditView();
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()
643 Window::GetFocus();
645 if (xAccessible.is())
647 // Note: will implicitly send the AccessibleStateType::FOCUSED event
648 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
649 if (pHelper)
650 pHelper->SetFocus( sal_True );
653 if (!pEditView)
654 CreateEditView();
655 EditEngine *pEditEngine = GetEditEngine();
656 if (pEditEngine)
657 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
661 void SmEditWindow::LoseFocus()
663 EditEngine *pEditEngine = GetEditEngine();
664 if (pEditEngine)
665 pEditEngine->SetStatusEventHdl( Link() );
667 Window::LoseFocus();
669 if (xAccessible.is())
671 // Note: will implicitly send the AccessibleStateType::FOCUSED event
672 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
673 if (pHelper)
674 pHelper->SetFocus( sal_False );
679 BOOL SmEditWindow::IsAllSelected() const
681 BOOL bRes = FALSE;
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();
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 SmEditWindow::SelectAll()
704 DBG_ASSERT( pEditView, "NULL pointer" );
705 if (pEditView)
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" );
715 if (pEditView)
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);
727 if (HasMark(aText))
728 { // set selection to next mark
729 pEditView->SetSelection(aSelection);
730 SelNextMark();
732 else
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();
742 GrabFocus();
746 void SmEditWindow::MarkError(const Point &rPos)
748 DBG_ASSERT( pEditView, "EditView missing" );
749 if (pEditView)
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));
755 GrabFocus();
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("<?>"));
769 String aText;
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));
780 break;
783 Pos = 0;
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))
809 Pos = Fnd;
810 Fnd = Text.Search(aMark, Fnd + 1);
813 if (Pos == STRING_NOTFOUND)
815 eSelection.nStartPara--;
816 Text = pEditEngine->GetText( eSelection.nStartPara );
817 Max = Text.Len();
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)
838 if (pEditView)
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" );
857 ESelection eSel;
858 if (pEditView)
859 eSel = pEditView->GetSelection();
860 return eSel;
863 void SmEditWindow::SetSelection(const ESelection &rSel)
865 DBG_ASSERT( pEditView, "NULL pointer" );
866 if (pEditView)
867 pEditView->SetSelection(rSel);
868 InvalidateSlots();
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);
876 return bEmpty;
879 BOOL SmEditWindow::IsSelected() const
881 return pEditView ? pEditView->HasSelection() : FALSE;
884 void SmEditWindow::Cut()
886 DBG_ASSERT( pEditView, "EditView missing" );
887 if (pEditView)
889 pEditView->Cut();
890 GetDoc()->SetModified( TRUE );
894 void SmEditWindow::Copy()
896 DBG_ASSERT( pEditView, "EditView missing" );
897 if (pEditView)
898 pEditView->Copy();
901 void SmEditWindow::Paste()
903 DBG_ASSERT( pEditView, "EditView missing" );
904 if (pEditView)
906 pEditView->Paste();
907 GetDoc()->SetModified( TRUE );
911 void SmEditWindow::Delete()
913 DBG_ASSERT( pEditView, "EditView missing" );
914 if (pEditView)
916 pEditView->DeleteSelected();
917 GetDoc()->SetModified( TRUE );
921 void SmEditWindow::InsertText(const String& Text)
923 DBG_ASSERT( pEditView, "EditView missing" );
924 if (pEditView)
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();
939 if (pViewSh)
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*/ )
958 if (pEditView)
960 EditEngine *pEditEngine = pEditView->GetEditEngine();
961 if (pEditEngine)
963 pEditEngine->SetStatusEventHdl( Link() );
964 pEditEngine->RemoveView( pEditView );
966 delete pEditView;
967 pEditView = 0;
972 uno::Reference< XAccessible > SmEditWindow::CreateAccessible()
974 if (!pAccessible)
976 pAccessible = new SmEditAccessible( this );
977 xAccessible = pAccessible;
978 pAccessible->Init();
980 return xAccessible;