sync master with lastest vba changes
[ooovba.git] / starmath / source / edit.cxx
blob270b5410785687de96f6a5833f4c90d82c8fb840
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>
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;
167 SmViewShell * SmEditWindow::GetView()
169 return rCmdBox.GetView();
173 SmDocShell * SmEditWindow::GetDoc()
175 SmViewShell *pView = rCmdBox.GetView();
176 return pView ? pView->GetDoc() : 0;
180 EditEngine * SmEditWindow::GetEditEngine()
182 EditEngine *pEditEng = 0;
183 if (pEditView)
184 pEditEng = pEditView->GetEditEngine();
185 else
187 SmDocShell *pDoc = GetDoc();
188 if (pDoc)
189 pEditEng = &pDoc->GetEditEngine();
191 return pEditEng;
195 SfxItemPool * SmEditWindow::GetEditEngineItemPool()
197 SmDocShell *pDoc = GetDoc();
198 return pDoc ? &pDoc->GetEditEngineItemPool() : 0;
201 void SmEditWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
203 // Note: SetBackground still done in SmEditWindow::DataChanged
204 #if OSL_DEBUG_LEVEL > 1
205 // ColorData nVal = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
206 #endif
207 SetTextColor( rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor );
208 Invalidate();
211 void SmEditWindow::DataChanged( const DataChangedEvent& )
213 const StyleSettings aSettings( GetSettings().GetStyleSettings() );
215 ApplyColorConfigValues( SM_MOD1()->GetColorConfig() );
216 SetBackground( aSettings.GetWindowColor() );
218 // edit fields in other Applications use this font instead of
219 // the application font thus we use this one too
220 SetPointFont( aSettings.GetFieldFont() /*aSettings.GetAppFont()*/ );
222 EditEngine *pEditEngine = GetEditEngine();
223 SfxItemPool *pEditEngineItemPool = GetEditEngineItemPool();
225 if (pEditEngine && pEditEngineItemPool)
228 //! see also SmDocShell::GetEditEngine() !
231 pEditEngine->SetDefTab( USHORT( GetTextWidth( C2S("XXXX") ) ) );
233 SetEditEngineDefaultFonts( *pEditEngine, *pEditEngineItemPool );
235 // forces new settings to be used
236 // unfortunately this resets the whole edit engine
237 // thus we need to save at least the text
238 String aTxt( pEditEngine->GetText( LINEEND_LF ) );
239 pEditEngine->Clear(); //#77957 incorrect font size
240 pEditEngine->SetText( aTxt );
243 AdjustScrollBars();
244 Resize();
247 IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
249 SmModule *pp = SM_MOD1();
250 if (pp->GetConfig()->IsAutoRedraw())
251 Flush();
252 aModifyTimer.Start();
253 return 0;
257 IMPL_LINK(SmEditWindow, CursorMoveTimerHdl, Timer *, EMPTYARG /*pTimer*/)
258 // every once in a while check cursor position (selection) of edit
259 // window and if it has changed (try to) set the formula-cursor
260 // according to that.
262 ESelection aNewSelection (GetSelection());
264 if (!aNewSelection.IsEqual(aOldSelection))
265 { SmViewShell *pView = rCmdBox.GetView();
267 if (pView)
269 // get row and column to look for
270 USHORT nRow, nCol;
271 SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
272 nRow++;
273 nCol++;
275 pView->GetGraphicWindow().SetCursorPos(nRow, nCol);
277 aOldSelection = aNewSelection;
281 return 0;
285 void SmEditWindow::Resize()
287 if (!pEditView)
288 CreateEditView();
290 if (pEditView)
292 pEditView->SetOutputArea(AdjustScrollBars());
293 pEditView->ShowCursor();
295 DBG_ASSERT( pEditView->GetEditEngine(), "EditEngine missing" );
296 const long nMaxVisAreaStart = pEditView->GetEditEngine()->GetTextHeight() -
297 pEditView->GetOutputArea().GetHeight();
298 if (pEditView->GetVisArea().Top() > nMaxVisAreaStart)
300 Rectangle aVisArea(pEditView->GetVisArea() );
301 aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0;
302 aVisArea.SetSize(pEditView->GetOutputArea().GetSize());
303 pEditView->SetVisArea(aVisArea);
304 pEditView->ShowCursor();
306 InitScrollBars();
308 Invalidate();
311 void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
313 if (pEditView)
314 pEditView->MouseButtonUp(rEvt);
315 else
316 Window::MouseButtonUp (rEvt);
318 // ggf FormulaCursor neu positionieren
319 CursorMoveTimerHdl(&aCursorMoveTimer);
322 void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)
324 if (pEditView)
325 pEditView->MouseButtonDown(rEvt);
326 else
327 Window::MouseButtonDown (rEvt);
329 GrabFocus();
332 void SmEditWindow::Command(const CommandEvent& rCEvt)
334 BOOL bForwardEvt = TRUE;
335 if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU)
337 GetParent()->ToTop();
339 Point aPoint = rCEvt.GetMousePosPixel();
340 PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU));
342 // added for replaceability of context menus #96085, #93782
343 Menu* pMenu = NULL;
344 ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
345 aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
346 aEvent.ExecutePosition.X = aPoint.X();
347 aEvent.ExecutePosition.Y = aPoint.Y();
348 ::rtl::OUString sDummy;
349 if ( GetView()->TryContextMenuInterception( *pPopupMenu, sDummy, pMenu, aEvent ) )
351 if ( pMenu )
353 delete pPopupMenu;
354 pPopupMenu = (PopupMenu*) pMenu;
358 pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl));
360 pPopupMenu->Execute( this, aPoint );
361 delete pPopupMenu;
362 bForwardEvt = FALSE;
364 else if (rCEvt.GetCommand() == COMMAND_WHEEL)
365 bForwardEvt = !HandleWheelCommands( rCEvt );
367 if (bForwardEvt)
369 if (pEditView)
370 pEditView->Command( rCEvt );
371 else
372 Window::Command (rCEvt);
377 BOOL SmEditWindow::HandleWheelCommands( const CommandEvent &rCEvt )
379 BOOL bCommandHandled = FALSE; // true if the CommandEvent needs not
380 // to be passed on (because it has fully
381 // been taken care of).
383 const CommandWheelData* pWData = rCEvt.GetWheelData();
384 if (pWData)
386 if (COMMAND_WHEEL_ZOOM == pWData->GetMode())
387 bCommandHandled = TRUE; // no zooming in Command window
388 else
389 bCommandHandled = HandleScrollCommand( rCEvt, pHScrollBar, pVScrollBar);
392 return bCommandHandled;
396 IMPL_LINK_INLINE_START( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
398 SmViewShell *pViewSh = rCmdBox.GetView();
399 if (pViewSh)
400 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
401 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
402 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
403 return 0;
405 IMPL_LINK_INLINE_END( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
407 void SmEditWindow::KeyInput(const KeyEvent& rKEvt)
409 if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
411 BOOL bCallBase = TRUE;
412 SfxViewShell* pViewShell = GetView();
413 if ( pViewShell && pViewShell->ISA(SmViewShell) )
415 // Terminate possible InPlace mode
416 bCallBase = !pViewShell->Escape();
418 if ( bCallBase )
419 Window::KeyInput( rKEvt );
421 else
423 // Timer neu starten, um den Handler (auch bei laengeren Eingaben)
424 // moeglichst nur einmal am Ende aufzurufen.
425 aCursorMoveTimer.Start();
427 DBG_ASSERT( pEditView, "EditView missing (NULL pointer)" );
428 if (!pEditView)
429 CreateEditView();
430 if ( !pEditView->PostKeyEvent(rKEvt) )
432 SmViewShell *pView = GetView();
433 if ( pView && !pView->KeyInput(rKEvt) )
435 /* fuert bei F1 (Hilfe) zum Zerstoeren von this! */
436 Flush();
437 if ( aModifyTimer.IsActive() )
438 aModifyTimer.Stop();
439 Window::KeyInput(rKEvt);
441 else
443 //SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack
444 //im SFX) den Focus auf die View gesetzt
445 SfxViewShell* pVShell = GetView();
446 if ( pVShell && pVShell->ISA(SmViewShell) &&
447 ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() )
449 GrabFocus();
453 else
455 // have doc-shell modified only for formula input/change and not
456 // cursor travelling and such things...
457 SmDocShell *pDocShell = GetDoc();
458 if (pDocShell)
459 pDocShell->SetModified( GetEditEngine()->IsModified() );
461 aModifyTimer.Start();
466 void SmEditWindow::Paint(const Rectangle& rRect)
468 if (!pEditView)
469 CreateEditView();
470 pEditView->Paint(rRect);
473 void SmEditWindow::CreateEditView()
475 EditEngine *pEditEngine = GetEditEngine();
477 //! pEditEngine and pEditView may be 0.
478 //! For example when the program is used by the document-converter
479 if (!pEditView && pEditEngine)
481 pEditView = new EditView( pEditEngine, this );
482 pEditEngine->InsertView( pEditView );
484 if (!pVScrollBar)
485 pVScrollBar = new ScrollBar(this, WinBits(WB_VSCROLL));
486 if (!pHScrollBar)
487 pHScrollBar = new ScrollBar(this, WinBits(WB_HSCROLL));
488 if (!pScrollBox)
489 pScrollBox = new ScrollBarBox(this);
490 pVScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
491 pHScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
492 pVScrollBar->EnableDrag( TRUE );
493 pHScrollBar->EnableDrag( TRUE );
495 pEditView->SetOutputArea(AdjustScrollBars());
497 ESelection eSelection;
499 pEditView->SetSelection(eSelection);
500 Update();
501 pEditView->ShowCursor(TRUE, TRUE);
503 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
504 SetPointer(pEditView->GetPointer());
506 SetScrollBarRanges();
511 IMPL_LINK( SmEditWindow, EditStatusHdl, EditStatus *, EMPTYARG /*pStat*/ )
513 if (!pEditView)
514 return 1;
515 else
517 Resize();
518 return 0;
522 IMPL_LINK_INLINE_START( SmEditWindow, ScrollHdl, ScrollBar *, EMPTYARG /*pScrollBar*/ )
524 DBG_ASSERT(pEditView, "EditView missing");
525 if (pEditView)
527 pEditView->SetVisArea(Rectangle(Point(pHScrollBar->GetThumbPos(),
528 pVScrollBar->GetThumbPos()),
529 pEditView->GetVisArea().GetSize()));
530 pEditView->Invalidate();
532 return 0;
534 IMPL_LINK_INLINE_END( SmEditWindow, ScrollHdl, ScrollBar *, pScrollBar )
536 Rectangle SmEditWindow::AdjustScrollBars()
538 const Size aOut( GetOutputSizePixel() );
539 Point aPoint;
540 Rectangle aRect( aPoint, aOut );
542 if (pVScrollBar && pHScrollBar && pScrollBox)
544 const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
545 Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L;
546 pVScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp));
548 aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L;
549 pHScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp));
551 aPt.X() = pHScrollBar->GetSizePixel().Width();
552 aPt.Y() = pVScrollBar->GetSizePixel().Height();
553 pScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp ));
555 aRect.Right() = aPt.X() - 2;
556 aRect.Bottom() = aPt.Y() - 2;
558 return aRect;
561 void SmEditWindow::SetScrollBarRanges()
563 // Extra-Methode, nicht InitScrollBars, da auch fuer EditEngine-Events.
564 EditEngine *pEditEngine = GetEditEngine();
565 if (pVScrollBar && pHScrollBar && pEditEngine && pEditView)
567 long nTmp = pEditEngine->GetTextHeight();
568 pVScrollBar->SetRange(Range(0, nTmp));
569 pVScrollBar->SetThumbPos(pEditView->GetVisArea().Top());
571 nTmp = pEditEngine->GetPaperSize().Width();
572 pHScrollBar->SetRange(Range(0,nTmp));
573 pHScrollBar->SetThumbPos(pEditView->GetVisArea().Left());
577 void SmEditWindow::InitScrollBars()
579 if (pVScrollBar && pHScrollBar && pScrollBox && pEditView)
581 const Size aOut( pEditView->GetOutputArea().GetSize() );
582 pVScrollBar->SetVisibleSize(aOut.Height());
583 pVScrollBar->SetPageSize(aOut.Height() * 8 / 10);
584 pVScrollBar->SetLineSize(aOut.Height() * 2 / 10);
586 pHScrollBar->SetVisibleSize(aOut.Width());
587 pHScrollBar->SetPageSize(aOut.Width() * 8 / 10);
588 pHScrollBar->SetLineSize(SCROLL_LINE );
590 SetScrollBarRanges();
592 pVScrollBar->Show();
593 pHScrollBar->Show();
594 pScrollBox->Show();
599 String SmEditWindow::GetText() const
601 String aText;
602 EditEngine *pEditEngine = const_cast< SmEditWindow* >(this)->GetEditEngine();
603 DBG_ASSERT( pEditEngine, "EditEngine missing" );
604 if (pEditEngine)
605 aText = pEditEngine->GetText( LINEEND_LF );
606 return aText;
610 void SmEditWindow::SetText(const XubString& rText)
612 EditEngine *pEditEngine = GetEditEngine();
613 DBG_ASSERT( pEditEngine, "EditEngine missing" );
614 if (pEditEngine && !pEditEngine->IsModified())
616 if (!pEditView)
617 CreateEditView();
619 ESelection eSelection = pEditView->GetSelection();
621 pEditEngine->SetText(rText);
622 pEditEngine->ClearModifyFlag();
624 //! Hier die Timer neu zu starten verhindert, dass die Handler fuer andere
625 //! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden.
626 aModifyTimer.Start();
627 aCursorMoveTimer.Start();
629 pEditView->SetSelection(eSelection);
634 void SmEditWindow::GetFocus()
636 Window::GetFocus();
638 if (xAccessible.is())
640 // Note: will implicitly send the AccessibleStateType::FOCUSED event
641 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
642 if (pHelper)
643 pHelper->SetFocus( sal_True );
646 if (!pEditView)
647 CreateEditView();
648 EditEngine *pEditEngine = GetEditEngine();
649 if (pEditEngine)
650 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
654 void SmEditWindow::LoseFocus()
656 EditEngine *pEditEngine = GetEditEngine();
657 if (pEditEngine)
658 pEditEngine->SetStatusEventHdl( Link() );
660 Window::LoseFocus();
662 if (xAccessible.is())
664 // Note: will implicitly send the AccessibleStateType::FOCUSED event
665 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
666 if (pHelper)
667 pHelper->SetFocus( sal_False );
672 BOOL SmEditWindow::IsAllSelected() const
674 BOOL bRes = FALSE;
675 EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
676 DBG_ASSERT( pEditView, "NULL pointer" );
677 DBG_ASSERT( pEditEngine, "NULL pointer" );
678 if (pEditEngine && pEditView)
680 ESelection eSelection( pEditView->GetSelection() );
681 INT32 nParaCnt = pEditEngine->GetParagraphCount();
682 if (!(nParaCnt - 1))
684 String Text( pEditEngine->GetText( LINEEND_LF ) );
685 bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1);
687 else
689 bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
692 return bRes;
695 void SmEditWindow::SelectAll()
697 DBG_ASSERT( pEditView, "NULL pointer" );
698 if (pEditView)
700 // 0xFFFF as last two parameters refers to the end of the text
701 pEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
705 void SmEditWindow::InsertCommand(USHORT nCommand)
707 DBG_ASSERT( pEditView, "EditView missing" );
708 if (pEditView)
710 //Anfang der Selektion merken und hinterher den Cursor daraufsetzen. Nur so
711 //macht das SelNextMark() Sinn.
712 ESelection aSelection = pEditView->GetSelection();
713 aSelection.nEndPos = aSelection.nStartPos;
714 aSelection.nEndPara = aSelection.nStartPara;
716 DBG_ASSERT( pEditView, "NULL pointer" );
717 String aText = String(SmResId(nCommand));
718 pEditView->InsertText(aText);
720 if (HasMark(aText))
721 { // set selection to next mark
722 pEditView->SetSelection(aSelection);
723 SelNextMark();
725 else
726 { // set selection after inserted text
727 aSelection.nEndPos = aSelection.nEndPos + sal::static_int_cast< xub_StrLen >(aText.Len());
728 aSelection.nStartPos = aSelection.nEndPos;
729 pEditView->SetSelection(aSelection);
732 GrabFocus();
736 void SmEditWindow::MarkError(const Point &rPos)
738 DBG_ASSERT( pEditView, "EditView missing" );
739 if (pEditView)
741 const xub_StrLen nCol = sal::static_int_cast< xub_StrLen >(rPos.X());
742 const USHORT nRow = sal::static_int_cast< USHORT >(rPos.Y() - 1);
744 pEditView->SetSelection(ESelection(nRow, nCol - 1, nRow, nCol));
745 GrabFocus();
749 void SmEditWindow::SelNextMark()
751 EditEngine *pEditEngine = GetEditEngine();
752 DBG_ASSERT( pEditView, "NULL pointer" );
753 DBG_ASSERT( pEditEngine, "NULL pointer" );
754 if (pEditEngine && pEditView)
756 ESelection eSelection = pEditView->GetSelection();
757 USHORT Pos = eSelection.nEndPos;
758 String aMark (C2S("<?>"));
759 String aText;
760 USHORT nCounts = pEditEngine->GetParagraphCount();
762 while (eSelection.nEndPara < nCounts)
764 aText = pEditEngine->GetText( eSelection.nEndPara );
765 Pos = aText.Search(aMark, Pos);
767 if (Pos != STRING_NOTFOUND)
769 pEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3));
770 break;
773 Pos = 0;
774 eSelection.nEndPara++;
779 void SmEditWindow::SelPrevMark()
781 EditEngine *pEditEngine = GetEditEngine();
782 DBG_ASSERT( pEditEngine, "NULL pointer" );
783 DBG_ASSERT( pEditView, "NULL pointer" );
784 if (pEditEngine && pEditView)
786 ESelection eSelection = pEditView->GetSelection();
787 USHORT Pos = STRING_NOTFOUND;
788 xub_StrLen Max = eSelection.nStartPos;
789 String Text( pEditEngine->GetText( eSelection.nStartPara ) );
790 String aMark (C2S("<?>"));
791 USHORT nCounts = pEditEngine->GetParagraphCount();
795 USHORT Fnd = Text.Search(aMark, 0);
797 while ((Fnd < Max) && (Fnd != STRING_NOTFOUND))
799 Pos = Fnd;
800 Fnd = Text.Search(aMark, Fnd + 1);
803 if (Pos == STRING_NOTFOUND)
805 eSelection.nStartPara--;
806 Text = pEditEngine->GetText( eSelection.nStartPara );
807 Max = Text.Len();
810 while ((eSelection.nStartPara < nCounts) &&
811 (Pos == STRING_NOTFOUND));
813 if (Pos != STRING_NOTFOUND)
815 pEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3));
820 BOOL SmEditWindow::HasMark(const String& rText) const
821 // returns true iff 'rText' contains a mark
823 return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND;
826 void SmEditWindow::MouseMove(const MouseEvent &rEvt)
828 if (pEditView)
829 pEditView->MouseMove(rEvt);
832 sal_Int8 SmEditWindow::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
834 return pEditView ? /*pEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE;
837 sal_Int8 SmEditWindow::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
839 return pEditView ? /*pEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE;
842 ESelection SmEditWindow::GetSelection() const
844 // pointer may be 0 when reloading a document and the old view
845 // was already destroyed
846 //(DBG_ASSERT( pEditView, "NULL pointer" );
847 ESelection eSel;
848 if (pEditView)
849 eSel = pEditView->GetSelection();
850 return eSel;
853 void SmEditWindow::SetSelection(const ESelection &rSel)
855 DBG_ASSERT( pEditView, "NULL pointer" );
856 if (pEditView)
857 pEditView->SetSelection(rSel);
860 BOOL SmEditWindow::IsEmpty() const
862 EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
863 BOOL bEmpty = sal::static_int_cast< BOOL >(
864 pEditEngine ? pEditEngine->GetTextLen() == 0 : FALSE);
865 return bEmpty;
868 BOOL SmEditWindow::IsSelected() const
870 return pEditView ? pEditView->HasSelection() : FALSE;
873 void SmEditWindow::Cut()
875 DBG_ASSERT( pEditView, "EditView missing" );
876 if (pEditView)
877 pEditView->Cut();
880 void SmEditWindow::Copy()
882 DBG_ASSERT( pEditView, "EditView missing" );
883 if (pEditView)
884 pEditView->Copy();
887 void SmEditWindow::Paste()
889 DBG_ASSERT( pEditView, "EditView missing" );
890 if (pEditView)
891 pEditView->Paste();
894 void SmEditWindow::Delete()
896 DBG_ASSERT( pEditView, "EditView missing" );
897 if (pEditView)
898 pEditView->DeleteSelected();
901 void SmEditWindow::InsertText(const String& Text)
903 DBG_ASSERT( pEditView, "EditView missing" );
904 if (pEditView)
905 pEditView->InsertText(Text);
908 void SmEditWindow::Flush()
910 EditEngine *pEditEngine = GetEditEngine();
911 if (pEditEngine && pEditEngine->IsModified())
913 pEditEngine->ClearModifyFlag();
914 SmViewShell *pViewSh = rCmdBox.GetView();
915 if (pViewSh)
916 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
917 SID_TEXT, SFX_CALLMODE_STANDARD,
918 new SfxStringItem(SID_TEXT, GetText()), 0L);
921 if (aCursorMoveTimer.IsActive())
923 aCursorMoveTimer.Stop();
924 // ggf noch die (neue) FormulaCursor Position setzen
925 CursorMoveTimerHdl(&aCursorMoveTimer);
930 void SmEditWindow::DeleteEditView( SmViewShell & /*rView*/ )
932 if (pEditView)
934 EditEngine *pEditEngine = pEditView->GetEditEngine();
935 if (pEditEngine)
937 pEditEngine->SetStatusEventHdl( Link() );
938 pEditEngine->RemoveView( pEditView );
940 delete pEditView;
941 pEditView = 0;
946 uno::Reference< XAccessible > SmEditWindow::CreateAccessible()
948 if (!pAccessible)
950 pAccessible = new SmEditAccessible( this );
951 xAccessible = pAccessible;
952 pAccessible->Init();
954 return xAccessible;