merge the formfield patch from ooo-build
[ooovba.git] / starmath / source / edit.cxx
blob0e4542b96ed473d540ea8f4c76d6df9f7af5f9db
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: edit.cxx,v $
10 * $Revision: 1.40 $
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"
43 #define ITEMID_FONT 1
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>
65 #include "edit.hxx"
66 #include "view.hxx"
67 #include "document.hxx"
68 #include "config.hxx"
70 #define SCROLL_LINE 24
72 #define MINWIDTH 200
73 #define MINHEIGHT 200
74 #define MINSPLIT 40
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;
95 else
96 { nPara = aSel.nEndPara;
97 nPos = aSel.nEndPos;
101 ////////////////////////////////////////
103 SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
104 Window (&rMyCmdBoxWin),
105 DropTargetHelper ( this ),
106 pAccessible (0),
107 rCmdBox (rMyCmdBoxWin),
108 pEditView (0),
109 pHScrollBar (0),
110 pVScrollBar (0),
111 pScrollBox (0)
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.
133 Show();
137 SmEditWindow::~SmEditWindow()
139 aCursorMoveTimer.Stop();
140 aModifyTimer.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.
146 if (pAccessible)
147 pAccessible->ClearWin(); // make Accessible defunctional
148 // Note: memory for pAccessible will be freed when the reference
149 // xAccessible is released.
151 if (pEditView)
153 EditEngine *pEditEngine = pEditView->GetEditEngine();
154 if (pEditEngine)
156 pEditEngine->SetStatusEventHdl( Link() );
157 pEditEngine->RemoveView( pEditView );
160 delete pEditView;
161 delete pHScrollBar;
162 delete pVScrollBar;
163 delete pScrollBox;
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;
190 if (pEditView)
191 pEditEng = pEditView->GetEditEngine();
192 else
194 SmDocShell *pDoc = GetDoc();
195 if (pDoc)
196 pEditEng = &pDoc->GetEditEngine();
198 return pEditEng;
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;
213 #endif
214 SetTextColor( rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor );
215 Invalidate();
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 );
250 AdjustScrollBars();
251 Resize();
254 IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
256 SmModule *pp = SM_MOD1();
257 if (pp->GetConfig()->IsAutoRedraw())
258 Flush();
259 aModifyTimer.Start();
260 return 0;
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();
274 if (pView)
276 // get row and column to look for
277 USHORT nRow, nCol;
278 SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
279 nRow++;
280 nCol++;
282 pView->GetGraphicWindow().SetCursorPos(nRow, nCol);
284 aOldSelection = aNewSelection;
288 return 0;
292 void SmEditWindow::Resize()
294 if (!pEditView)
295 CreateEditView();
297 if (pEditView)
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();
313 InitScrollBars();
315 Invalidate();
318 void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
320 if (pEditView)
321 pEditView->MouseButtonUp(rEvt);
322 else
323 Window::MouseButtonUp (rEvt);
325 // ggf FormulaCursor neu positionieren
326 CursorMoveTimerHdl(&aCursorMoveTimer);
327 InvalidateSlots();
330 void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)
332 if (pEditView)
333 pEditView->MouseButtonDown(rEvt);
334 else
335 Window::MouseButtonDown (rEvt);
337 GrabFocus();
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
351 Menu* pMenu = NULL;
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 ) )
359 if ( pMenu )
361 delete pPopupMenu;
362 pPopupMenu = (PopupMenu*) pMenu;
366 pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl));
368 pPopupMenu->Execute( this, aPoint );
369 delete pPopupMenu;
370 bForwardEvt = FALSE;
372 else if (rCEvt.GetCommand() == COMMAND_WHEEL)
373 bForwardEvt = !HandleWheelCommands( rCEvt );
375 if (bForwardEvt)
377 if (pEditView)
378 pEditView->Command( rCEvt );
379 else
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();
392 if (pWData)
394 if (COMMAND_WHEEL_ZOOM == pWData->GetMode())
395 bCommandHandled = TRUE; // no zooming in Command window
396 else
397 bCommandHandled = HandleScrollCommand( rCEvt, pHScrollBar, pVScrollBar);
400 return bCommandHandled;
404 IMPL_LINK_INLINE_START( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
406 SmViewShell *pViewSh = rCmdBox.GetView();
407 if (pViewSh)
408 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
409 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
410 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
411 return 0;
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();
426 if ( bCallBase )
427 Window::KeyInput( rKEvt );
429 else
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)" );
436 if (!pEditView)
437 CreateEditView();
438 if ( !pEditView->PostKeyEvent(rKEvt) )
440 SmViewShell *pView = GetView();
441 if ( pView && !pView->KeyInput(rKEvt) )
443 /* fuert bei F1 (Hilfe) zum Zerstoeren von this! */
444 Flush();
445 if ( aModifyTimer.IsActive() )
446 aModifyTimer.Stop();
447 Window::KeyInput(rKEvt);
449 else
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() )
457 GrabFocus();
461 else
463 // have doc-shell modified only for formula input/change and not
464 // cursor travelling and such things...
465 SmDocShell *pDocShell = GetDoc();
466 if (pDocShell)
467 pDocShell->SetModified( GetEditEngine()->IsModified() );
469 aModifyTimer.Start();
472 InvalidateSlots();
476 void SmEditWindow::Paint(const Rectangle& rRect)
478 if (!pEditView)
479 CreateEditView();
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 );
494 if (!pVScrollBar)
495 pVScrollBar = new ScrollBar(this, WinBits(WB_VSCROLL));
496 if (!pHScrollBar)
497 pHScrollBar = new ScrollBar(this, WinBits(WB_HSCROLL));
498 if (!pScrollBox)
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);
510 Update();
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*/ )
523 if (!pEditView)
524 return 1;
525 else
527 Resize();
528 return 0;
532 IMPL_LINK_INLINE_START( SmEditWindow, ScrollHdl, ScrollBar *, EMPTYARG /*pScrollBar*/ )
534 DBG_ASSERT(pEditView, "EditView missing");
535 if (pEditView)
537 pEditView->SetVisArea(Rectangle(Point(pHScrollBar->GetThumbPos(),
538 pVScrollBar->GetThumbPos()),
539 pEditView->GetVisArea().GetSize()));
540 pEditView->Invalidate();
542 return 0;
544 IMPL_LINK_INLINE_END( SmEditWindow, ScrollHdl, ScrollBar *, pScrollBar )
546 Rectangle SmEditWindow::AdjustScrollBars()
548 const Size aOut( GetOutputSizePixel() );
549 Point aPoint;
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;
568 return aRect;
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();
602 pVScrollBar->Show();
603 pHScrollBar->Show();
604 pScrollBox->Show();
609 String SmEditWindow::GetText() const
611 String aText;
612 EditEngine *pEditEngine = const_cast< SmEditWindow* >(this)->GetEditEngine();
613 DBG_ASSERT( pEditEngine, "EditEngine missing" );
614 if (pEditEngine)
615 aText = pEditEngine->GetText( LINEEND_LF );
616 return aText;
620 void SmEditWindow::SetText(const XubString& rText)
622 EditEngine *pEditEngine = GetEditEngine();
623 DBG_ASSERT( pEditEngine, "EditEngine missing" );
624 if (pEditEngine && !pEditEngine->IsModified())
626 if (!pEditView)
627 CreateEditView();
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()
646 Window::GetFocus();
648 if (xAccessible.is())
650 // Note: will implicitly send the AccessibleStateType::FOCUSED event
651 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
652 if (pHelper)
653 pHelper->SetFocus( sal_True );
656 if (!pEditView)
657 CreateEditView();
658 EditEngine *pEditEngine = GetEditEngine();
659 if (pEditEngine)
660 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
664 void SmEditWindow::LoseFocus()
666 EditEngine *pEditEngine = GetEditEngine();
667 if (pEditEngine)
668 pEditEngine->SetStatusEventHdl( Link() );
670 Window::LoseFocus();
672 if (xAccessible.is())
674 // Note: will implicitly send the AccessibleStateType::FOCUSED event
675 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
676 if (pHelper)
677 pHelper->SetFocus( sal_False );
682 BOOL SmEditWindow::IsAllSelected() const
684 BOOL bRes = FALSE;
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();
692 if (!(nParaCnt - 1))
694 String Text( pEditEngine->GetText( LINEEND_LF ) );
695 bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1);
697 else
699 bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
702 return bRes;
705 void SmEditWindow::SelectAll()
707 DBG_ASSERT( pEditView, "NULL pointer" );
708 if (pEditView)
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" );
718 if (pEditView)
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);
730 if (HasMark(aText))
731 { // set selection to next mark
732 pEditView->SetSelection(aSelection);
733 SelNextMark();
735 else
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);
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)
888 pEditView->Cut();
891 void SmEditWindow::Copy()
893 DBG_ASSERT( pEditView, "EditView missing" );
894 if (pEditView)
895 pEditView->Copy();
898 void SmEditWindow::Paste()
900 DBG_ASSERT( pEditView, "EditView missing" );
901 if (pEditView)
902 pEditView->Paste();
905 void SmEditWindow::Delete()
907 DBG_ASSERT( pEditView, "EditView missing" );
908 if (pEditView)
909 pEditView->DeleteSelected();
912 void SmEditWindow::InsertText(const String& Text)
914 DBG_ASSERT( pEditView, "EditView missing" );
915 if (pEditView)
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();
926 if (pViewSh)
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*/ )
943 if (pEditView)
945 EditEngine *pEditEngine = pEditView->GetEditEngine();
946 if (pEditEngine)
948 pEditEngine->SetStatusEventHdl( Link() );
949 pEditEngine->RemoveView( pEditView );
951 delete pEditView;
952 pEditView = 0;
957 uno::Reference< XAccessible > SmEditWindow::CreateAccessible()
959 if (!pAccessible)
961 pAccessible = new SmEditAccessible( this );
962 xAccessible = pAccessible;
963 pAccessible->Init();
965 return xAccessible;