fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / starmath / source / edit.cxx
blobfc88ba7cca3d911ae5476497be3f281aed6f27c8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/accessibility/XAccessible.hpp>
21 #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
24 #include <toolkit/helper/vclunohelper.hxx>
27 #include "starmath.hrc"
29 #include <vcl/menu.hxx>
30 #include <editeng/editview.hxx>
31 #include <editeng/editeng.hxx>
32 #include <editeng/editstat.hxx>
33 #include <editeng/eeitem.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <svl/intitem.hxx>
36 #include <svl/itempool.hxx>
37 #include <svl/stritem.hxx>
38 #include <editeng/fhgtitem.hxx>
39 #include <editeng/wghtitem.hxx>
40 #include <editeng/lrspitem.hxx>
41 #include <svl/itemset.hxx>
42 #include <editeng/fontitem.hxx>
43 #include <sfx2/viewfrm.hxx>
45 #include "edit.hxx"
46 #include "view.hxx"
47 #include "document.hxx"
48 #include "config.hxx"
49 #include "accessibility.hxx"
51 #define SCROLL_LINE 24
54 using namespace com::sun::star::accessibility;
55 using namespace com::sun::star;
56 using namespace com::sun::star::uno;
58 ////////////////////////////////////////
61 void SmGetLeftSelectionPart(const ESelection &rSel,
62 sal_Int32 &nPara, sal_uInt16 &nPos)
63 // returns paragraph number and position of the selections left part
65 // compare start and end of selection and use the one that comes first
66 if ( rSel.nStartPara < rSel.nEndPara
67 || (rSel.nStartPara == rSel.nEndPara && rSel.nStartPos < rSel.nEndPos) )
68 { nPara = rSel.nStartPara;
69 nPos = rSel.nStartPos;
71 else
72 { nPara = rSel.nEndPara;
73 nPos = rSel.nEndPos;
77 bool SmEditWindow::IsInlineEditEnabled()
79 SmViewShell *pView = GetView();
80 return pView ? pView->IsInlineEditEnabled() : false;
83 ////////////////////////////////////////
85 SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
86 Window (&rMyCmdBoxWin),
87 DropTargetHelper ( this ),
88 pAccessible (0),
89 rCmdBox (rMyCmdBoxWin),
90 pEditView (0),
91 pHScrollBar (0),
92 pVScrollBar (0),
93 pScrollBox (0)
95 SetHelpId(HID_SMA_COMMAND_WIN_EDIT);
96 SetMapMode(MAP_PIXEL);
98 // Even RTL languages don't use RTL for math
99 rCmdBox.GetEditWindow()->EnableRTL( false );
101 ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
103 // compare DataChanged
104 SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
106 aModifyTimer.SetTimeoutHdl(LINK(this, SmEditWindow, ModifyTimerHdl));
107 aModifyTimer.SetTimeout(500);
109 if (!IsInlineEditEnabled())
111 aCursorMoveTimer.SetTimeoutHdl(LINK(this, SmEditWindow, CursorMoveTimerHdl));
112 aCursorMoveTimer.SetTimeout(500);
115 // if not called explicitly the this edit window within the
116 // command window will just show an empty gray panel.
117 Show();
121 SmEditWindow::~SmEditWindow()
123 aModifyTimer.Stop();
125 StartCursorMove();
127 // clean up of classes used for accessibility
128 // must be done before EditView (and thus EditEngine) is no longer
129 // available for those classes.
130 if (pAccessible)
131 pAccessible->ClearWin(); // make Accessible defunctional
132 // Note: memory for pAccessible will be freed when the reference
133 // xAccessible is released.
135 if (pEditView)
137 EditEngine *pEditEngine = pEditView->GetEditEngine();
138 if (pEditEngine)
140 pEditEngine->SetStatusEventHdl( Link() );
141 pEditEngine->RemoveView( pEditView );
144 delete pEditView;
145 delete pHScrollBar;
146 delete pVScrollBar;
147 delete pScrollBox;
150 void SmEditWindow::StartCursorMove()
152 if (!IsInlineEditEnabled())
153 aCursorMoveTimer.Stop();
156 void SmEditWindow::InvalidateSlots()
158 SfxBindings& rBind = GetView()->GetViewFrame()->GetBindings();
159 rBind.Invalidate(SID_COPY);
160 rBind.Invalidate(SID_CUT);
161 rBind.Invalidate(SID_DELETE);
164 SmViewShell * SmEditWindow::GetView()
166 return rCmdBox.GetView();
170 SmDocShell * SmEditWindow::GetDoc()
172 SmViewShell *pView = rCmdBox.GetView();
173 return pView ? pView->GetDoc() : 0;
177 EditEngine * SmEditWindow::GetEditEngine()
179 EditEngine *pEditEng = 0;
180 if (pEditView)
181 pEditEng = pEditView->GetEditEngine();
182 else
184 SmDocShell *pDoc = GetDoc();
185 if (pDoc)
186 pEditEng = &pDoc->GetEditEngine();
188 return pEditEng;
192 SfxItemPool * SmEditWindow::GetEditEngineItemPool()
194 SmDocShell *pDoc = GetDoc();
195 return pDoc ? &pDoc->GetEditEngineItemPool() : 0;
198 void SmEditWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
200 // Note: SetBackground still done in SmEditWindow::DataChanged
201 #if OSL_DEBUG_LEVEL > 1
202 // ColorData nVal = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
203 #endif
204 SetTextColor( rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor );
205 Invalidate();
208 void SmEditWindow::DataChanged( const DataChangedEvent& )
210 const StyleSettings aSettings( GetSettings().GetStyleSettings() );
212 ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
213 SetBackground( aSettings.GetWindowColor() );
215 // edit fields in other Applications use this font instead of
216 // the application font thus we use this one too
217 SetPointFont( aSettings.GetFieldFont() /*aSettings.GetAppFont()*/ );
219 EditEngine *pEditEngine = GetEditEngine();
220 SfxItemPool *pEditEngineItemPool = GetEditEngineItemPool();
222 if (pEditEngine && pEditEngineItemPool)
225 //! see also SmDocShell::GetEditEngine() !
228 pEditEngine->SetDefTab(sal_uInt16(GetTextWidth(OUString("XXXX"))));
230 SetEditEngineDefaultFonts(*pEditEngineItemPool);
232 // forces new settings to be used
233 // unfortunately this resets the whole edit engine
234 // thus we need to save at least the text
235 OUString aTxt( pEditEngine->GetText( LINEEND_LF ) );
236 pEditEngine->Clear(); //incorrect font size
237 pEditEngine->SetText( aTxt );
240 AdjustScrollBars();
241 Resize();
244 IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
246 UpdateStatus();
247 aModifyTimer.Stop();
248 return 0;
251 IMPL_LINK(SmEditWindow, CursorMoveTimerHdl, Timer *, EMPTYARG /*pTimer*/)
252 // every once in a while check cursor position (selection) of edit
253 // window and if it has changed (try to) set the formula-cursor
254 // according to that.
256 if (IsInlineEditEnabled())
257 return 0;
259 ESelection aNewSelection(GetSelection());
261 if (!aNewSelection.IsEqual(aOldSelection))
263 SmViewShell *pView = rCmdBox.GetView();
264 if (pView)
266 // get row and column to look for
267 sal_Int32 nRow;
268 sal_uInt16 nCol;
269 SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
270 nRow++;
271 nCol++;
272 pView->GetGraphicWindow().SetCursorPos(static_cast<sal_uInt16>(nRow), nCol);
273 aOldSelection = aNewSelection;
276 aCursorMoveTimer.Stop();
278 return 0;
281 void SmEditWindow::Resize()
283 if (!pEditView)
284 CreateEditView();
286 if (pEditView)
288 pEditView->SetOutputArea(AdjustScrollBars());
289 pEditView->ShowCursor();
291 OSL_ENSURE( pEditView->GetEditEngine(), "EditEngine missing" );
292 const long nMaxVisAreaStart = pEditView->GetEditEngine()->GetTextHeight() -
293 pEditView->GetOutputArea().GetHeight();
294 if (pEditView->GetVisArea().Top() > nMaxVisAreaStart)
296 Rectangle aVisArea(pEditView->GetVisArea() );
297 aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0;
298 aVisArea.SetSize(pEditView->GetOutputArea().GetSize());
299 pEditView->SetVisArea(aVisArea);
300 pEditView->ShowCursor();
302 InitScrollBars();
304 Invalidate();
307 void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
309 if (pEditView)
310 pEditView->MouseButtonUp(rEvt);
311 else
312 Window::MouseButtonUp (rEvt);
314 if (!IsInlineEditEnabled())
315 CursorMoveTimerHdl(&aCursorMoveTimer);
316 InvalidateSlots();
319 void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)
321 if (pEditView)
322 pEditView->MouseButtonDown(rEvt);
323 else
324 Window::MouseButtonDown (rEvt);
326 GrabFocus();
329 void SmEditWindow::Command(const CommandEvent& rCEvt)
331 bool bForwardEvt = true;
332 if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU)
334 GetParent()->ToTop();
336 Point aPoint = rCEvt.GetMousePosPixel();
337 PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU));
339 // added for replaceability of context menus
340 Menu* pMenu = NULL;
341 ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
342 aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
343 aEvent.ExecutePosition.X = aPoint.X();
344 aEvent.ExecutePosition.Y = aPoint.Y();
345 OUString sDummy;
346 if ( GetView()->TryContextMenuInterception( *pPopupMenu, sDummy, pMenu, aEvent ) )
348 if ( pMenu )
350 delete pPopupMenu;
351 pPopupMenu = (PopupMenu*) pMenu;
355 pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl));
357 pPopupMenu->Execute( this, aPoint );
358 delete pPopupMenu;
359 bForwardEvt = false;
361 else if (rCEvt.GetCommand() == COMMAND_WHEEL)
362 bForwardEvt = !HandleWheelCommands( rCEvt );
364 if (bForwardEvt)
366 if (pEditView)
367 pEditView->Command( rCEvt );
368 else
369 Window::Command (rCEvt);
374 bool SmEditWindow::HandleWheelCommands( const CommandEvent &rCEvt )
376 bool bCommandHandled = false; // true if the CommandEvent needs not
377 // to be passed on (because it has fully
378 // been taken care of).
380 const CommandWheelData* pWData = rCEvt.GetWheelData();
381 if (pWData)
383 if (COMMAND_WHEEL_ZOOM == pWData->GetMode())
384 bCommandHandled = true; // no zooming in Command window
385 else
386 bCommandHandled = HandleScrollCommand( rCEvt, pHScrollBar, pVScrollBar);
389 return bCommandHandled;
393 IMPL_LINK_INLINE_START( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
395 SmViewShell *pViewSh = rCmdBox.GetView();
396 if (pViewSh)
397 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
398 SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
399 new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
400 return 0;
402 IMPL_LINK_INLINE_END( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
404 void SmEditWindow::KeyInput(const KeyEvent& rKEvt)
406 if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
408 bool bCallBase = true;
409 SfxViewShell* pViewShell = GetView();
410 if ( pViewShell && pViewShell->ISA(SmViewShell) )
412 // Terminate possible InPlace mode
413 bCallBase = !pViewShell->Escape();
415 if ( bCallBase )
416 Window::KeyInput( rKEvt );
418 else
420 StartCursorMove();
422 if (!pEditView)
423 CreateEditView();
424 if ( !pEditView->PostKeyEvent(rKEvt) )
426 SmViewShell *pView = GetView();
427 if ( pView && !pView->KeyInput(rKEvt) )
429 // F1 (help) leads to the destruction of this
430 Flush();
431 if ( aModifyTimer.IsActive() )
432 aModifyTimer.Stop();
433 Window::KeyInput(rKEvt);
435 else
437 // SFX has maybe called a slot of the view and thus (because of a hack in SFX)
438 // set the focus to the view
439 SfxViewShell* pVShell = GetView();
440 if ( pVShell && pVShell->ISA(SmViewShell) &&
441 ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() )
443 GrabFocus();
447 else
449 // have doc-shell modified only for formula input/change and not
450 // cursor travelling and such things...
451 SmDocShell *pDocShell = GetDoc();
452 if (pDocShell)
453 pDocShell->SetModified( GetEditEngine()->IsModified() );
455 aModifyTimer.Start();
458 InvalidateSlots();
462 void SmEditWindow::Paint(const Rectangle& rRect)
464 if (!pEditView)
465 CreateEditView();
466 pEditView->Paint(rRect);
469 void SmEditWindow::CreateEditView()
471 EditEngine *pEditEngine = GetEditEngine();
473 //! pEditEngine and pEditView may be 0.
474 //! For example when the program is used by the document-converter
475 if (!pEditView && pEditEngine)
477 pEditView = new EditView( pEditEngine, this );
478 pEditEngine->InsertView( pEditView );
480 if (!pVScrollBar)
481 pVScrollBar = new ScrollBar(this, WinBits(WB_VSCROLL));
482 if (!pHScrollBar)
483 pHScrollBar = new ScrollBar(this, WinBits(WB_HSCROLL));
484 if (!pScrollBox)
485 pScrollBox = new ScrollBarBox(this);
486 pVScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
487 pHScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
488 pVScrollBar->EnableDrag( true );
489 pHScrollBar->EnableDrag( true );
491 pEditView->SetOutputArea(AdjustScrollBars());
493 ESelection eSelection;
495 pEditView->SetSelection(eSelection);
496 Update();
497 pEditView->ShowCursor(true, true);
499 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
500 SetPointer(pEditView->GetPointer());
502 SetScrollBarRanges();
507 IMPL_LINK( SmEditWindow, EditStatusHdl, EditStatus *, EMPTYARG /*pStat*/ )
509 if (!pEditView)
510 return 1;
511 else
513 Resize();
514 return 0;
518 IMPL_LINK_INLINE_START( SmEditWindow, ScrollHdl, ScrollBar *, EMPTYARG /*pScrollBar*/ )
520 OSL_ENSURE(pEditView, "EditView missing");
521 if (pEditView)
523 pEditView->SetVisArea(Rectangle(Point(pHScrollBar->GetThumbPos(),
524 pVScrollBar->GetThumbPos()),
525 pEditView->GetVisArea().GetSize()));
526 pEditView->Invalidate();
528 return 0;
530 IMPL_LINK_INLINE_END( SmEditWindow, ScrollHdl, ScrollBar *, pScrollBar )
532 Rectangle SmEditWindow::AdjustScrollBars()
534 const Size aOut( GetOutputSizePixel() );
535 Point aPoint;
536 Rectangle aRect( aPoint, aOut );
538 if (pVScrollBar && pHScrollBar && pScrollBox)
540 const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
541 Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L;
542 pVScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp));
544 aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L;
545 pHScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp));
547 aPt.X() = pHScrollBar->GetSizePixel().Width();
548 aPt.Y() = pVScrollBar->GetSizePixel().Height();
549 pScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp ));
551 aRect.Right() = aPt.X() - 2;
552 aRect.Bottom() = aPt.Y() - 2;
554 return aRect;
557 void SmEditWindow::SetScrollBarRanges()
559 // Extra method, not InitScrollBars, since it's also being used for EditEngine events
560 EditEngine *pEditEngine = GetEditEngine();
561 if (pVScrollBar && pHScrollBar && pEditEngine && pEditView)
563 long nTmp = pEditEngine->GetTextHeight();
564 pVScrollBar->SetRange(Range(0, nTmp));
565 pVScrollBar->SetThumbPos(pEditView->GetVisArea().Top());
567 nTmp = pEditEngine->GetPaperSize().Width();
568 pHScrollBar->SetRange(Range(0,nTmp));
569 pHScrollBar->SetThumbPos(pEditView->GetVisArea().Left());
573 void SmEditWindow::InitScrollBars()
575 if (pVScrollBar && pHScrollBar && pScrollBox && pEditView)
577 const Size aOut( pEditView->GetOutputArea().GetSize() );
578 pVScrollBar->SetVisibleSize(aOut.Height());
579 pVScrollBar->SetPageSize(aOut.Height() * 8 / 10);
580 pVScrollBar->SetLineSize(aOut.Height() * 2 / 10);
582 pHScrollBar->SetVisibleSize(aOut.Width());
583 pHScrollBar->SetPageSize(aOut.Width() * 8 / 10);
584 pHScrollBar->SetLineSize(SCROLL_LINE );
586 SetScrollBarRanges();
588 pVScrollBar->Show();
589 pHScrollBar->Show();
590 pScrollBox->Show();
595 OUString SmEditWindow::GetText() const
597 String aText;
598 EditEngine *pEditEngine = const_cast< SmEditWindow* >(this)->GetEditEngine();
599 OSL_ENSURE( pEditEngine, "EditEngine missing" );
600 if (pEditEngine)
601 aText = pEditEngine->GetText( LINEEND_LF );
602 return aText;
606 void SmEditWindow::SetText(const OUString& rText)
608 EditEngine *pEditEngine = GetEditEngine();
609 OSL_ENSURE( pEditEngine, "EditEngine missing" );
610 if (pEditEngine && !pEditEngine->IsModified())
612 if (!pEditView)
613 CreateEditView();
615 ESelection eSelection = pEditView->GetSelection();
617 pEditEngine->SetText(rText);
618 pEditEngine->ClearModifyFlag();
620 // Restarting the timer here, prevents calling the handlers for other (currently inactive)
621 // math tasks
622 aModifyTimer.Start();
624 pEditView->SetSelection(eSelection);
629 void SmEditWindow::GetFocus()
631 Window::GetFocus();
633 if (xAccessible.is())
635 // Note: will implicitly send the AccessibleStateType::FOCUSED event
636 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
637 if (pHelper)
638 pHelper->SetFocus(true);
641 if (!pEditView)
642 CreateEditView();
643 EditEngine *pEditEngine = GetEditEngine();
644 if (pEditEngine)
645 pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
647 //Let SmViewShell know we got focus
648 if(GetView() && IsInlineEditEnabled())
649 GetView()->SetInsertIntoEditWindow(true);
653 void SmEditWindow::LoseFocus()
655 EditEngine *pEditEngine = GetEditEngine();
656 if (pEditEngine)
657 pEditEngine->SetStatusEventHdl( Link() );
659 Window::LoseFocus();
661 if (xAccessible.is())
663 // Note: will implicitly send the AccessibleStateType::FOCUSED event
664 ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
665 if (pHelper)
666 pHelper->SetFocus(false);
671 bool SmEditWindow::IsAllSelected() const
673 bool bRes = false;
674 EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
675 OSL_ENSURE( pEditView, "NULL pointer" );
676 OSL_ENSURE( pEditEngine, "NULL pointer" );
677 if (pEditEngine && pEditView)
679 ESelection eSelection( pEditView->GetSelection() );
680 sal_Int32 nParaCnt = pEditEngine->GetParagraphCount();
681 if (!(nParaCnt - 1))
683 sal_Int32 nTextLen = pEditEngine->GetText( LINEEND_LF ).getLength();
684 bRes = !eSelection.nStartPos && (eSelection.nEndPos == nTextLen - 1);
686 else
688 bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
691 return bRes;
694 void SmEditWindow::SelectAll()
696 OSL_ENSURE( pEditView, "NULL pointer" );
697 if (pEditView)
699 // ALL as last two parameters refers to the end of the text
700 pEditView->SetSelection( ESelection( 0, 0, EE_PARA_ALL, EE_TEXTPOS_ALL ) );
704 void SmEditWindow::InsertCommand(sal_uInt16 nCommand)
706 OSL_ENSURE( pEditView, "EditView missing" );
707 if (pEditView)
709 // Remember start of the selection and move the cursor there afterwards.
710 // Only this way the SelNextMark() makes sense...
711 ESelection aSelection = pEditView->GetSelection();
712 aSelection.nEndPos = aSelection.nStartPos;
713 aSelection.nEndPara = aSelection.nStartPara;
715 OSL_ENSURE( pEditView, "NULL pointer" );
716 OUString aText = SM_RESSTR(nCommand);
717 pEditView->InsertText(aText);
719 if (HasMark(aText))
720 { // set selection to next mark
721 pEditView->SetSelection(aSelection);
722 SelNextMark();
724 else
725 { // set selection after inserted text
726 aSelection.nEndPos += aText.getLength();
727 aSelection.nStartPos = aSelection.nEndPos;
728 pEditView->SetSelection(aSelection);
731 aModifyTimer.Start();
732 StartCursorMove();
733 GrabFocus();
737 void SmEditWindow::MarkError(const Point &rPos)
739 OSL_ENSURE( pEditView, "EditView missing" );
740 if (pEditView)
742 const xub_StrLen nCol = sal::static_int_cast< xub_StrLen >(rPos.X());
743 const sal_uInt16 nRow = sal::static_int_cast< sal_uInt16 >(rPos.Y() - 1);
745 pEditView->SetSelection(ESelection(nRow, nCol - 1, nRow, nCol));
746 GrabFocus();
750 void SmEditWindow::SelNextMark()
752 EditEngine *pEditEngine = GetEditEngine();
753 OSL_ENSURE( pEditView, "NULL pointer" );
754 OSL_ENSURE( pEditEngine, "NULL pointer" );
755 if (pEditEngine && pEditView)
757 ESelection eSelection = pEditView->GetSelection();
758 sal_Int32 nPos = eSelection.nEndPos;
759 sal_Int32 nCounts = pEditEngine->GetParagraphCount();
761 while (eSelection.nEndPara < nCounts)
763 OUString aText = pEditEngine->GetText(eSelection.nEndPara);
764 nPos = aText.indexOf("<?>", nPos);
765 if (nPos != -1)
767 pEditView->SetSelection(ESelection(
768 eSelection.nEndPara, nPos, eSelection.nEndPara, nPos + 3));
769 break;
772 nPos = 0;
773 eSelection.nEndPara++;
778 void SmEditWindow::SelPrevMark()
780 EditEngine *pEditEngine = GetEditEngine();
781 OSL_ENSURE( pEditEngine, "NULL pointer" );
782 OSL_ENSURE( pEditView, "NULL pointer" );
783 if (pEditEngine && pEditView)
785 ESelection eSelection = pEditView->GetSelection();
786 sal_Int32 nPos = -1;
787 sal_Int32 nMax = eSelection.nStartPos;
788 OUString aText(pEditEngine->GetText(eSelection.nStartPara));
789 OUString aMark("<?>");
790 sal_Int32 nCounts = pEditEngine->GetParagraphCount();
794 sal_Int32 nMarkIndex = aText.indexOf(aMark);
795 while ((nMarkIndex < nMax) && (nMarkIndex != -1))
797 nPos = nMarkIndex;
798 nMarkIndex = aText.indexOf(aMark, nMarkIndex + 1);
801 if (nPos == -1)
803 eSelection.nStartPara--;
804 aText = pEditEngine->GetText(eSelection.nStartPara);
805 nMax = aText.getLength();
808 while ((eSelection.nStartPara < nCounts) &&
809 (nPos == -1));
811 if (nPos != -1)
813 pEditView->SetSelection(ESelection(
814 eSelection.nStartPara, nPos, eSelection.nStartPara, nPos + 3));
819 bool SmEditWindow::HasMark(const OUString& rText) const
820 // returns true iff 'rText' contains a mark
822 return rText.indexOf("<?>") != -1;
825 void SmEditWindow::MouseMove(const MouseEvent &rEvt)
827 if (pEditView)
828 pEditView->MouseMove(rEvt);
831 sal_Int8 SmEditWindow::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
833 return pEditView ? /*pEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE;
836 sal_Int8 SmEditWindow::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
838 return pEditView ? /*pEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE;
841 ESelection SmEditWindow::GetSelection() const
843 // pointer may be 0 when reloading a document and the old view
844 // was already destroyed
845 //(OSL_ENSURE( pEditView, "NULL pointer" );
846 ESelection eSel;
847 if (pEditView)
848 eSel = pEditView->GetSelection();
849 return eSel;
852 void SmEditWindow::SetSelection(const ESelection &rSel)
854 OSL_ENSURE( pEditView, "NULL pointer" );
855 if (pEditView)
856 pEditView->SetSelection(rSel);
857 InvalidateSlots();
860 bool SmEditWindow::IsEmpty() const
862 EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
863 bool bEmpty = ( pEditEngine ? pEditEngine->GetTextLen() == 0 : false);
864 return bEmpty;
867 bool SmEditWindow::IsSelected() const
869 return pEditView ? pEditView->HasSelection() : false;
873 void SmEditWindow::UpdateStatus( bool bSetDocModified )
875 SmModule *pMod = SM_MOD();
876 if (pMod && pMod->GetConfig()->IsAutoRedraw())
877 Flush();
878 if ( bSetDocModified )
879 GetDoc()->SetModified(true);
882 void SmEditWindow::Cut()
884 OSL_ENSURE( pEditView, "EditView missing" );
885 if (pEditView)
887 pEditView->Cut();
888 UpdateStatus(true);
892 void SmEditWindow::Copy()
894 OSL_ENSURE( pEditView, "EditView missing" );
895 if (pEditView)
896 pEditView->Copy();
899 void SmEditWindow::Paste()
901 OSL_ENSURE( pEditView, "EditView missing" );
902 if (pEditView)
904 pEditView->Paste();
905 UpdateStatus(true);
909 void SmEditWindow::Delete()
911 OSL_ENSURE( pEditView, "EditView missing" );
912 if (pEditView)
914 pEditView->DeleteSelected();
915 UpdateStatus(true);
919 void SmEditWindow::InsertText(const OUString& rText)
921 OSL_ENSURE( pEditView, "EditView missing" );
922 if (pEditView)
924 pEditView->InsertText(rText);
925 aModifyTimer.Start();
926 StartCursorMove();
930 void SmEditWindow::Flush()
932 EditEngine *pEditEngine = GetEditEngine();
933 if (pEditEngine && pEditEngine->IsModified())
935 pEditEngine->ClearModifyFlag();
936 SmViewShell *pViewSh = rCmdBox.GetView();
937 if (pViewSh)
939 pViewSh->GetViewFrame()->GetDispatcher()->Execute(
940 SID_TEXT, SFX_CALLMODE_STANDARD,
941 new SfxStringItem(SID_TEXT, GetText()), 0L);
944 if (aCursorMoveTimer.IsActive())
946 aCursorMoveTimer.Stop();
947 CursorMoveTimerHdl(&aCursorMoveTimer);
952 void SmEditWindow::DeleteEditView( SmViewShell & /*rView*/ )
954 if (pEditView)
956 EditEngine *pEditEngine = pEditView->GetEditEngine();
957 if (pEditEngine)
959 pEditEngine->SetStatusEventHdl( Link() );
960 pEditEngine->RemoveView( pEditView );
962 delete pEditView;
963 pEditView = 0;
968 uno::Reference< XAccessible > SmEditWindow::CreateAccessible()
970 if (!pAccessible)
972 pAccessible = new SmEditAccessible( this );
973 xAccessible = pAccessible;
974 pAccessible->Init();
976 return xAccessible;
979 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */