xref: /aoo41x/main/starmath/source/edit.cxx (revision a050e4e7)
1d107581fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d107581fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d107581fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d107581fSAndrew Rist  * distributed with this work for additional information
6d107581fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d107581fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d107581fSAndrew Rist  * "License"); you may not use this file except in compliance
9d107581fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10d107581fSAndrew Rist  *
11d107581fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12d107581fSAndrew Rist  *
13d107581fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d107581fSAndrew Rist  * software distributed under the License is distributed on an
15d107581fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d107581fSAndrew Rist  * KIND, either express or implied.  See the License for the
17d107581fSAndrew Rist  * specific language governing permissions and limitations
18d107581fSAndrew Rist  * under the License.
19d107581fSAndrew Rist  *
20d107581fSAndrew Rist  *************************************************************/
21d107581fSAndrew Rist 
22d107581fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_starmath.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp>
29cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventObject.hpp>
30cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "starmath.hrc"
36cdf0e10cSrcweir #define ITEMID_FONT 		1
37cdf0e10cSrcweir #define ITEMID_FONTHEIGHT	2
38cdf0e10cSrcweir #define ITEMID_LRSPACE		3
39cdf0e10cSrcweir #define ITEMID_WEIGHT		4
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <vcl/menu.hxx>
43cdf0e10cSrcweir #include <editeng/editview.hxx>
44cdf0e10cSrcweir #include <editeng/editeng.hxx>
45cdf0e10cSrcweir #include <editeng/editstat.hxx>
46cdf0e10cSrcweir #include <editeng/eeitem.hxx>
47cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
48cdf0e10cSrcweir #include <svl/intitem.hxx>
49cdf0e10cSrcweir #include <svl/itempool.hxx>
50cdf0e10cSrcweir #include <svl/stritem.hxx>
51cdf0e10cSrcweir #include <editeng/fhgtitem.hxx>
52cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
53cdf0e10cSrcweir #include <editeng/lrspitem.hxx>
54cdf0e10cSrcweir #include <svl/itemset.hxx>
55cdf0e10cSrcweir #include <editeng/fontitem.hxx>
56cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include "edit.hxx"
59cdf0e10cSrcweir #include "view.hxx"
60cdf0e10cSrcweir #include "document.hxx"
61cdf0e10cSrcweir #include "config.hxx"
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #define SCROLL_LINE 		24
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #define MINWIDTH		200
66cdf0e10cSrcweir #define MINHEIGHT		200
67cdf0e10cSrcweir #define MINSPLIT		40
68cdf0e10cSrcweir #define SPLITTERWIDTH	2
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 
71cdf0e10cSrcweir using namespace com::sun::star::accessibility;
72cdf0e10cSrcweir using namespace com::sun::star;
73cdf0e10cSrcweir using namespace com::sun::star::uno;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir ////////////////////////////////////////
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
SmGetLeftSelectionPart(const ESelection aSel,sal_uInt16 & nPara,sal_uInt16 & nPos)78cdf0e10cSrcweir void SmGetLeftSelectionPart(const ESelection aSel,
79cdf0e10cSrcweir 							sal_uInt16 &nPara, sal_uInt16 &nPos)
80cdf0e10cSrcweir 	// returns paragraph number and position of the selections left part
81cdf0e10cSrcweir {
82cdf0e10cSrcweir 	// compare start and end of selection and use the one that comes first
83cdf0e10cSrcweir 	if (	aSel.nStartPara <  aSel.nEndPara
84cdf0e10cSrcweir 		||	(aSel.nStartPara == aSel.nEndPara  &&  aSel.nStartPos < aSel.nEndPos) )
85cdf0e10cSrcweir 	{	nPara = aSel.nStartPara;
86cdf0e10cSrcweir 		nPos  = aSel.nStartPos;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 	else
89cdf0e10cSrcweir 	{	nPara = aSel.nEndPara;
90cdf0e10cSrcweir 		nPos  = aSel.nEndPos;
91cdf0e10cSrcweir 	}
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir ////////////////////////////////////////
95cdf0e10cSrcweir 
SmEditWindow(SmCmdBoxWindow & rMyCmdBoxWin)96cdf0e10cSrcweir SmEditWindow::SmEditWindow( SmCmdBoxWindow &rMyCmdBoxWin ) :
97cdf0e10cSrcweir     Window              (&rMyCmdBoxWin),
98cdf0e10cSrcweir     DropTargetHelper    ( this ),
99cdf0e10cSrcweir     pAccessible         (0),
100cdf0e10cSrcweir     rCmdBox             (rMyCmdBoxWin),
101cdf0e10cSrcweir     pEditView           (0),
102cdf0e10cSrcweir     pHScrollBar         (0),
103cdf0e10cSrcweir     pVScrollBar         (0),
104cdf0e10cSrcweir     pScrollBox          (0)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	SetHelpId(HID_SMA_COMMAND_WIN_EDIT);
107cdf0e10cSrcweir 	SetMapMode(MAP_PIXEL);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     // Even RTL languages don't use RTL for math
110cdf0e10cSrcweir     rCmdBox.GetEditWindow()->EnableRTL( sal_False );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     // compare DataChanged
115cdf0e10cSrcweir 	SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	aModifyTimer.SetTimeoutHdl(LINK(this, SmEditWindow, ModifyTimerHdl));
118cdf0e10cSrcweir 	aModifyTimer.SetTimeout(500);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	aCursorMoveTimer.SetTimeoutHdl(LINK(this, SmEditWindow, CursorMoveTimerHdl));
121cdf0e10cSrcweir 	aCursorMoveTimer.SetTimeout(500);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	// if not called explicitly the this edit window within the
124cdf0e10cSrcweir 	// command window will just show an empty gray panel.
125cdf0e10cSrcweir     Show();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 
~SmEditWindow()129cdf0e10cSrcweir SmEditWindow::~SmEditWindow()
130cdf0e10cSrcweir {
131cdf0e10cSrcweir 	aCursorMoveTimer.Stop();
132cdf0e10cSrcweir 	aModifyTimer.Stop();
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     // #112565# clean up of classes used for accessibility
136cdf0e10cSrcweir     // must be done before EditView (and thus EditEngine) is no longer
137cdf0e10cSrcweir     // available for those classes.
138cdf0e10cSrcweir     if (pAccessible)
139cdf0e10cSrcweir         pAccessible->ClearWin();    // make Accessible defunctional
140cdf0e10cSrcweir     // Note: memory for pAccessible will be freed when the reference
141cdf0e10cSrcweir     // xAccessible is released.
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     if (pEditView)
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         EditEngine *pEditEngine = pEditView->GetEditEngine();
146cdf0e10cSrcweir         if (pEditEngine)
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             pEditEngine->SetStatusEventHdl( Link() );
149cdf0e10cSrcweir             pEditEngine->RemoveView( pEditView );
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir 	delete pEditView;
153cdf0e10cSrcweir 	delete pHScrollBar;
154cdf0e10cSrcweir 	delete pVScrollBar;
155cdf0e10cSrcweir 	delete pScrollBox;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
InvalidateSlots()158cdf0e10cSrcweir void SmEditWindow::InvalidateSlots()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	SfxBindings& rBind = GetView()->GetViewFrame()->GetBindings();
161cdf0e10cSrcweir 	rBind.Invalidate(SID_COPY);
162cdf0e10cSrcweir 	rBind.Invalidate(SID_CUT);
163cdf0e10cSrcweir 	rBind.Invalidate(SID_DELETE);
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
GetView()166cdf0e10cSrcweir SmViewShell * SmEditWindow::GetView()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir     return rCmdBox.GetView();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 
GetDoc()172cdf0e10cSrcweir SmDocShell * SmEditWindow::GetDoc()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir     SmViewShell *pView = rCmdBox.GetView();
175cdf0e10cSrcweir     return pView ? pView->GetDoc() : 0;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 
GetEditEngine()179cdf0e10cSrcweir EditEngine * SmEditWindow::GetEditEngine()
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     EditEngine *pEditEng = 0;
182cdf0e10cSrcweir     if (pEditView)
183cdf0e10cSrcweir         pEditEng = pEditView->GetEditEngine();
184cdf0e10cSrcweir     else
185cdf0e10cSrcweir     {
186cdf0e10cSrcweir         SmDocShell *pDoc = GetDoc();
187cdf0e10cSrcweir         if (pDoc)
188cdf0e10cSrcweir             pEditEng = &pDoc->GetEditEngine();
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir     return pEditEng;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 
GetEditEngineItemPool()194cdf0e10cSrcweir SfxItemPool * SmEditWindow::GetEditEngineItemPool()
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     SmDocShell *pDoc = GetDoc();
197cdf0e10cSrcweir     return pDoc ? &pDoc->GetEditEngineItemPool() : 0;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
ApplyColorConfigValues(const svtools::ColorConfig & rColorCfg)200cdf0e10cSrcweir void SmEditWindow::ApplyColorConfigValues( const svtools::ColorConfig &rColorCfg )
201cdf0e10cSrcweir {
202cdf0e10cSrcweir     // Note: SetBackground still done in SmEditWindow::DataChanged
203cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
204cdf0e10cSrcweir //   ColorData nVal = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
205cdf0e10cSrcweir #endif
206cdf0e10cSrcweir     SetTextColor( rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor );
207cdf0e10cSrcweir     Invalidate();
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
DataChanged(const DataChangedEvent &)210cdf0e10cSrcweir void SmEditWindow::DataChanged( const DataChangedEvent& )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     const StyleSettings aSettings( GetSettings().GetStyleSettings() );
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     ApplyColorConfigValues( SM_MOD()->GetColorConfig() );
215cdf0e10cSrcweir     SetBackground( aSettings.GetWindowColor() );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     // edit fields in other Applications use this font instead of
218cdf0e10cSrcweir     // the application font thus we use this one too
219cdf0e10cSrcweir     SetPointFont( aSettings.GetFieldFont() /*aSettings.GetAppFont()*/ );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     EditEngine  *pEditEngine = GetEditEngine();
222cdf0e10cSrcweir     SfxItemPool *pEditEngineItemPool = GetEditEngineItemPool();
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 	if (pEditEngine && pEditEngineItemPool)
225cdf0e10cSrcweir 	{
226cdf0e10cSrcweir         //!
227cdf0e10cSrcweir         //! see also SmDocShell::GetEditEngine() !
228cdf0e10cSrcweir         //!
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 		pEditEngine->SetDefTab( sal_uInt16( GetTextWidth( C2S("XXXX") ) ) );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir         SetEditEngineDefaultFonts( *pEditEngine, *pEditEngineItemPool );
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 		// forces new settings to be used
235cdf0e10cSrcweir         // unfortunately this resets the whole edit engine
236cdf0e10cSrcweir         // thus we need to save at least the text
237cdf0e10cSrcweir         String aTxt( pEditEngine->GetText( LINEEND_LF ) );
238cdf0e10cSrcweir 		pEditEngine->Clear();	//#77957 incorrect font size
239cdf0e10cSrcweir         pEditEngine->SetText( aTxt );
240cdf0e10cSrcweir 	}
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	AdjustScrollBars();
243cdf0e10cSrcweir 	Resize();
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
IMPL_LINK(SmEditWindow,ModifyTimerHdl,Timer *,EMPTYARG)246cdf0e10cSrcweir IMPL_LINK( SmEditWindow, ModifyTimerHdl, Timer *, EMPTYARG /*pTimer*/ )
247cdf0e10cSrcweir {
248*a050e4e7SAriel Constenla-Haile     UpdateStatus();
249cdf0e10cSrcweir     aModifyTimer.Stop();
250cdf0e10cSrcweir 	return 0;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 
IMPL_LINK(SmEditWindow,CursorMoveTimerHdl,Timer *,EMPTYARG)254cdf0e10cSrcweir IMPL_LINK(SmEditWindow, CursorMoveTimerHdl, Timer *, EMPTYARG /*pTimer*/)
255cdf0e10cSrcweir 	// every once in a while check cursor position (selection) of edit
256cdf0e10cSrcweir 	// window and if it has changed (try to) set the formula-cursor
257cdf0e10cSrcweir 	// according to that.
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	ESelection	aNewSelection   (GetSelection());
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	if (!aNewSelection.IsEqual(aOldSelection))
262cdf0e10cSrcweir     {   SmViewShell *pView = rCmdBox.GetView();
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 		if (pView)
265cdf0e10cSrcweir 		{
266cdf0e10cSrcweir 			// get row and column to look for
267cdf0e10cSrcweir 			sal_uInt16	nRow, nCol;
268cdf0e10cSrcweir 			SmGetLeftSelectionPart(aNewSelection, nRow, nCol);
269cdf0e10cSrcweir 			nRow++;
270cdf0e10cSrcweir 			nCol++;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 			pView->GetGraphicWindow().SetCursorPos(nRow, nCol);
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 			aOldSelection = aNewSelection;
275cdf0e10cSrcweir 		}
276cdf0e10cSrcweir 	}
277cdf0e10cSrcweir     aCursorMoveTimer.Stop();
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	return 0;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 
Resize()283cdf0e10cSrcweir void SmEditWindow::Resize()
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	if (!pEditView)
286cdf0e10cSrcweir 		CreateEditView();
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 	if (pEditView)
289cdf0e10cSrcweir 	{
290cdf0e10cSrcweir 		pEditView->SetOutputArea(AdjustScrollBars());
291cdf0e10cSrcweir 		pEditView->ShowCursor();
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         DBG_ASSERT( pEditView->GetEditEngine(), "EditEngine missing" );
294cdf0e10cSrcweir 		const long nMaxVisAreaStart = pEditView->GetEditEngine()->GetTextHeight() -
295cdf0e10cSrcweir 									  pEditView->GetOutputArea().GetHeight();
296cdf0e10cSrcweir 		if (pEditView->GetVisArea().Top() > nMaxVisAreaStart)
297cdf0e10cSrcweir 		{
298cdf0e10cSrcweir 			Rectangle aVisArea(pEditView->GetVisArea() );
299cdf0e10cSrcweir 			aVisArea.Top() = (nMaxVisAreaStart > 0 ) ? nMaxVisAreaStart : 0;
300cdf0e10cSrcweir 			aVisArea.SetSize(pEditView->GetOutputArea().GetSize());
301cdf0e10cSrcweir 			pEditView->SetVisArea(aVisArea);
302cdf0e10cSrcweir 			pEditView->ShowCursor();
303cdf0e10cSrcweir 		}
304cdf0e10cSrcweir 		InitScrollBars();
305cdf0e10cSrcweir 	}
306cdf0e10cSrcweir 	Invalidate();
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent & rEvt)309cdf0e10cSrcweir void SmEditWindow::MouseButtonUp(const MouseEvent &rEvt)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir 	if (pEditView)
312cdf0e10cSrcweir 		pEditView->MouseButtonUp(rEvt);
313cdf0e10cSrcweir 	else
314cdf0e10cSrcweir 		Window::MouseButtonUp (rEvt);
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 	// ggf FormulaCursor neu positionieren
317cdf0e10cSrcweir 	CursorMoveTimerHdl(&aCursorMoveTimer);
318cdf0e10cSrcweir 	InvalidateSlots();
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rEvt)321cdf0e10cSrcweir void SmEditWindow::MouseButtonDown(const MouseEvent &rEvt)
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	if (pEditView)
324cdf0e10cSrcweir 		pEditView->MouseButtonDown(rEvt);
325cdf0e10cSrcweir 	else
326cdf0e10cSrcweir 		Window::MouseButtonDown (rEvt);
327cdf0e10cSrcweir 
328cdf0e10cSrcweir 	GrabFocus();
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)331cdf0e10cSrcweir void SmEditWindow::Command(const CommandEvent& rCEvt)
332cdf0e10cSrcweir {
333cdf0e10cSrcweir     sal_Bool bForwardEvt = sal_True;
334cdf0e10cSrcweir 	if (rCEvt.GetCommand() == COMMAND_CONTEXTMENU)
335cdf0e10cSrcweir 	{
336cdf0e10cSrcweir 		GetParent()->ToTop();
337cdf0e10cSrcweir 
338cdf0e10cSrcweir         Point aPoint = rCEvt.GetMousePosPixel();
339cdf0e10cSrcweir 		PopupMenu* pPopupMenu = new PopupMenu(SmResId(RID_COMMANDMENU));
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         // added for replaceability of context menus #96085, #93782
342cdf0e10cSrcweir         Menu* pMenu = NULL;
343cdf0e10cSrcweir         ::com::sun::star::ui::ContextMenuExecuteEvent aEvent;
344cdf0e10cSrcweir         aEvent.SourceWindow = VCLUnoHelper::GetInterface( this );
345cdf0e10cSrcweir         aEvent.ExecutePosition.X = aPoint.X();
346cdf0e10cSrcweir         aEvent.ExecutePosition.Y = aPoint.Y();
347cdf0e10cSrcweir         ::rtl::OUString sDummy;
348cdf0e10cSrcweir         if ( GetView()->TryContextMenuInterception( *pPopupMenu, sDummy, pMenu, aEvent ) )
349cdf0e10cSrcweir         {
350cdf0e10cSrcweir             if ( pMenu )
351cdf0e10cSrcweir             {
352cdf0e10cSrcweir                 delete pPopupMenu;
353cdf0e10cSrcweir                 pPopupMenu = (PopupMenu*) pMenu;
354cdf0e10cSrcweir             }
355cdf0e10cSrcweir         }
356cdf0e10cSrcweir 
357cdf0e10cSrcweir         pPopupMenu->SetSelectHdl(LINK(this, SmEditWindow, MenuSelectHdl));
358cdf0e10cSrcweir 
359cdf0e10cSrcweir         pPopupMenu->Execute( this, aPoint );
360cdf0e10cSrcweir 		delete pPopupMenu;
361cdf0e10cSrcweir         bForwardEvt = sal_False;
362cdf0e10cSrcweir 	}
363cdf0e10cSrcweir     else if (rCEvt.GetCommand() == COMMAND_WHEEL)
364cdf0e10cSrcweir         bForwardEvt = !HandleWheelCommands( rCEvt );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     if (bForwardEvt)
367cdf0e10cSrcweir     {
368cdf0e10cSrcweir         if (pEditView)
369cdf0e10cSrcweir             pEditView->Command( rCEvt );
370cdf0e10cSrcweir         else
371cdf0e10cSrcweir             Window::Command (rCEvt);
372cdf0e10cSrcweir     }
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir 
HandleWheelCommands(const CommandEvent & rCEvt)376cdf0e10cSrcweir sal_Bool SmEditWindow::HandleWheelCommands( const CommandEvent &rCEvt )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     sal_Bool bCommandHandled = sal_False;    // true if the CommandEvent needs not
379cdf0e10cSrcweir                                     // to be passed on (because it has fully
380cdf0e10cSrcweir                                     // been taken care of).
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     const CommandWheelData* pWData = rCEvt.GetWheelData();
383cdf0e10cSrcweir     if (pWData)
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         if (COMMAND_WHEEL_ZOOM == pWData->GetMode())
386cdf0e10cSrcweir             bCommandHandled = sal_True;     // no zooming in Command window
387cdf0e10cSrcweir         else
388cdf0e10cSrcweir             bCommandHandled = HandleScrollCommand( rCEvt, pHScrollBar, pVScrollBar);
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     return bCommandHandled;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(SmEditWindow,MenuSelectHdl,Menu *,pMenu)395cdf0e10cSrcweir IMPL_LINK_INLINE_START( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
396cdf0e10cSrcweir {
397cdf0e10cSrcweir     SmViewShell *pViewSh = rCmdBox.GetView();
398cdf0e10cSrcweir 	if (pViewSh)
399cdf0e10cSrcweir 		pViewSh->GetViewFrame()->GetDispatcher()->Execute(
400cdf0e10cSrcweir 				SID_INSERTCOMMAND, SFX_CALLMODE_STANDARD,
401cdf0e10cSrcweir 				new SfxInt16Item(SID_INSERTCOMMAND, pMenu->GetCurItemId()), 0L);
402cdf0e10cSrcweir 	return 0;
403cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SmEditWindow,MenuSelectHdl,Menu *,pMenu)404cdf0e10cSrcweir IMPL_LINK_INLINE_END( SmEditWindow, MenuSelectHdl, Menu *, pMenu )
405cdf0e10cSrcweir 
406cdf0e10cSrcweir void SmEditWindow::KeyInput(const KeyEvent& rKEvt)
407cdf0e10cSrcweir {
408cdf0e10cSrcweir 	if (rKEvt.GetKeyCode().GetCode() == KEY_ESCAPE)
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 		sal_Bool bCallBase = sal_True;
411cdf0e10cSrcweir 		SfxViewShell* pViewShell = GetView();
412cdf0e10cSrcweir 		if ( pViewShell && pViewShell->ISA(SmViewShell) )
413cdf0e10cSrcweir 		{
414cdf0e10cSrcweir             // Terminate possible InPlace mode
415cdf0e10cSrcweir             bCallBase = !pViewShell->Escape();
416cdf0e10cSrcweir 		}
417cdf0e10cSrcweir 		if ( bCallBase )
418cdf0e10cSrcweir 			Window::KeyInput( rKEvt );
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir 	else
421cdf0e10cSrcweir 	{
422cdf0e10cSrcweir         // Timer neu starten, um den Handler (auch bei laengeren Eingaben)
423cdf0e10cSrcweir         // moeglichst nur einmal am Ende aufzurufen.
424cdf0e10cSrcweir 		aCursorMoveTimer.Start();
425cdf0e10cSrcweir 
426cdf0e10cSrcweir         DBG_ASSERT( pEditView, "EditView missing (NULL pointer)" );
427cdf0e10cSrcweir         if (!pEditView)
428cdf0e10cSrcweir             CreateEditView();
429cdf0e10cSrcweir 		if ( !pEditView->PostKeyEvent(rKEvt) )
430cdf0e10cSrcweir 		{
431cdf0e10cSrcweir             SmViewShell *pView = GetView();
432cdf0e10cSrcweir             if ( pView && !pView->KeyInput(rKEvt) )
433cdf0e10cSrcweir 			{
434cdf0e10cSrcweir 				/* fuert bei F1 (Hilfe) zum Zerstoeren von this! */
435cdf0e10cSrcweir 				Flush();
436cdf0e10cSrcweir 				if ( aModifyTimer.IsActive() )
437cdf0e10cSrcweir 					aModifyTimer.Stop();
438cdf0e10cSrcweir 				Window::KeyInput(rKEvt);
439cdf0e10cSrcweir 			}
440cdf0e10cSrcweir 			else
441cdf0e10cSrcweir 			{
442cdf0e10cSrcweir 				//SFX hat evtl. Slot an der View gecallt und dabei (wg. Hack
443cdf0e10cSrcweir 				//im SFX) den Focus auf die View gesetzt
444cdf0e10cSrcweir 				SfxViewShell* pVShell = GetView();
445cdf0e10cSrcweir 				if ( pVShell && pVShell->ISA(SmViewShell) &&
446cdf0e10cSrcweir 					 ((SmViewShell*)pVShell)->GetGraphicWindow().HasFocus() )
447cdf0e10cSrcweir 				{
448cdf0e10cSrcweir 					GrabFocus();
449cdf0e10cSrcweir 				}
450cdf0e10cSrcweir 			}
451cdf0e10cSrcweir 		}
452cdf0e10cSrcweir 		else
453cdf0e10cSrcweir         {
454cdf0e10cSrcweir             // have doc-shell modified only for formula input/change and not
455cdf0e10cSrcweir             // cursor travelling and such things...
456cdf0e10cSrcweir             SmDocShell *pDocShell = GetDoc();
457cdf0e10cSrcweir             if (pDocShell)
458cdf0e10cSrcweir                 pDocShell->SetModified( GetEditEngine()->IsModified() );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             aModifyTimer.Start();
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 		InvalidateSlots();
464cdf0e10cSrcweir 	}
465cdf0e10cSrcweir }
466cdf0e10cSrcweir 
Paint(const Rectangle & rRect)467cdf0e10cSrcweir void SmEditWindow::Paint(const Rectangle& rRect)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir 	if (!pEditView)
470cdf0e10cSrcweir 		CreateEditView();
471cdf0e10cSrcweir 	pEditView->Paint(rRect);
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
CreateEditView()474cdf0e10cSrcweir void SmEditWindow::CreateEditView()
475cdf0e10cSrcweir {
476cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
477cdf0e10cSrcweir 
478cdf0e10cSrcweir     //! pEditEngine and pEditView may be 0.
479cdf0e10cSrcweir     //! For example when the program is used by the document-converter
480cdf0e10cSrcweir 	if (!pEditView && pEditEngine)
481cdf0e10cSrcweir 	{
482cdf0e10cSrcweir 		pEditView = new EditView( pEditEngine, this );
483cdf0e10cSrcweir 		pEditEngine->InsertView( pEditView );
484cdf0e10cSrcweir 
485cdf0e10cSrcweir         if (!pVScrollBar)
486cdf0e10cSrcweir             pVScrollBar = new ScrollBar(this, WinBits(WB_VSCROLL));
487cdf0e10cSrcweir         if (!pHScrollBar)
488cdf0e10cSrcweir             pHScrollBar = new ScrollBar(this, WinBits(WB_HSCROLL));
489cdf0e10cSrcweir         if (!pScrollBox)
490cdf0e10cSrcweir             pScrollBox  = new ScrollBarBox(this);
491cdf0e10cSrcweir 		pVScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
492cdf0e10cSrcweir 		pHScrollBar->SetScrollHdl(LINK(this, SmEditWindow, ScrollHdl));
493cdf0e10cSrcweir         pVScrollBar->EnableDrag( sal_True );
494cdf0e10cSrcweir         pHScrollBar->EnableDrag( sal_True );
495cdf0e10cSrcweir 
496cdf0e10cSrcweir 		pEditView->SetOutputArea(AdjustScrollBars());
497cdf0e10cSrcweir 
498cdf0e10cSrcweir 		ESelection eSelection;
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 		pEditView->SetSelection(eSelection);
501cdf0e10cSrcweir 		Update();
502cdf0e10cSrcweir 		pEditView->ShowCursor(sal_True, sal_True);
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 		pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
505cdf0e10cSrcweir 		SetPointer(pEditView->GetPointer());
506cdf0e10cSrcweir 
507cdf0e10cSrcweir 		SetScrollBarRanges();
508cdf0e10cSrcweir 	}
509cdf0e10cSrcweir }
510cdf0e10cSrcweir 
511cdf0e10cSrcweir 
IMPL_LINK(SmEditWindow,EditStatusHdl,EditStatus *,EMPTYARG)512cdf0e10cSrcweir IMPL_LINK( SmEditWindow, EditStatusHdl, EditStatus *, EMPTYARG /*pStat*/ )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir     if (!pEditView)
515cdf0e10cSrcweir 		return 1;
516cdf0e10cSrcweir 	else
517cdf0e10cSrcweir 	{
518cdf0e10cSrcweir 		Resize();
519cdf0e10cSrcweir 		return 0;
520cdf0e10cSrcweir 	}
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(SmEditWindow,ScrollHdl,ScrollBar *,EMPTYARG)523cdf0e10cSrcweir IMPL_LINK_INLINE_START( SmEditWindow, ScrollHdl, ScrollBar *, EMPTYARG /*pScrollBar*/ )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir     DBG_ASSERT(pEditView, "EditView missing");
526cdf0e10cSrcweir     if (pEditView)
527cdf0e10cSrcweir     {
528cdf0e10cSrcweir         pEditView->SetVisArea(Rectangle(Point(pHScrollBar->GetThumbPos(),
529cdf0e10cSrcweir                                             pVScrollBar->GetThumbPos()),
530cdf0e10cSrcweir                                         pEditView->GetVisArea().GetSize()));
531cdf0e10cSrcweir         pEditView->Invalidate();
532cdf0e10cSrcweir     }
533cdf0e10cSrcweir 	return 0;
534cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SmEditWindow,ScrollHdl,ScrollBar *,pScrollBar)535cdf0e10cSrcweir IMPL_LINK_INLINE_END( SmEditWindow, ScrollHdl, ScrollBar *, pScrollBar )
536cdf0e10cSrcweir 
537cdf0e10cSrcweir Rectangle SmEditWindow::AdjustScrollBars()
538cdf0e10cSrcweir {
539cdf0e10cSrcweir 	const Size aOut( GetOutputSizePixel() );
540cdf0e10cSrcweir 	Point aPoint;
541cdf0e10cSrcweir 	Rectangle aRect( aPoint, aOut );
542cdf0e10cSrcweir 
543cdf0e10cSrcweir 	if (pVScrollBar && pHScrollBar && pScrollBox)
544cdf0e10cSrcweir 	{
545cdf0e10cSrcweir 		const long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
546cdf0e10cSrcweir 		Point aPt( aRect.TopRight() ); aPt.X() -= nTmp -1L;
547cdf0e10cSrcweir 		pVScrollBar->SetPosSizePixel( aPt, Size(nTmp, aOut.Height() - nTmp));
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 		aPt = aRect.BottomLeft(); aPt.Y() -= nTmp - 1L;
550cdf0e10cSrcweir 		pHScrollBar->SetPosSizePixel( aPt, Size(aOut.Width() - nTmp, nTmp));
551cdf0e10cSrcweir 
552cdf0e10cSrcweir 		aPt.X() = pHScrollBar->GetSizePixel().Width();
553cdf0e10cSrcweir 		aPt.Y() = pVScrollBar->GetSizePixel().Height();
554cdf0e10cSrcweir 		pScrollBox->SetPosSizePixel(aPt, Size(nTmp, nTmp ));
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 		aRect.Right()  = aPt.X() - 2;
557cdf0e10cSrcweir 		aRect.Bottom() = aPt.Y() - 2;
558cdf0e10cSrcweir 	}
559cdf0e10cSrcweir 	return aRect;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir 
SetScrollBarRanges()562cdf0e10cSrcweir void SmEditWindow::SetScrollBarRanges()
563cdf0e10cSrcweir {
564cdf0e10cSrcweir 	// Extra-Methode, nicht InitScrollBars, da auch fuer EditEngine-Events.
565cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
566cdf0e10cSrcweir 	if (pVScrollBar && pHScrollBar && pEditEngine && pEditView)
567cdf0e10cSrcweir 	{
568cdf0e10cSrcweir 		long nTmp = pEditEngine->GetTextHeight();
569cdf0e10cSrcweir 		pVScrollBar->SetRange(Range(0, nTmp));
570cdf0e10cSrcweir 		pVScrollBar->SetThumbPos(pEditView->GetVisArea().Top());
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 		nTmp = pEditEngine->GetPaperSize().Width();
573cdf0e10cSrcweir 		pHScrollBar->SetRange(Range(0,nTmp));
574cdf0e10cSrcweir 		pHScrollBar->SetThumbPos(pEditView->GetVisArea().Left());
575cdf0e10cSrcweir 	}
576cdf0e10cSrcweir }
577cdf0e10cSrcweir 
InitScrollBars()578cdf0e10cSrcweir void SmEditWindow::InitScrollBars()
579cdf0e10cSrcweir {
580cdf0e10cSrcweir     if (pVScrollBar && pHScrollBar && pScrollBox && pEditView)
581cdf0e10cSrcweir 	{
582cdf0e10cSrcweir 		const Size aOut( pEditView->GetOutputArea().GetSize() );
583cdf0e10cSrcweir 		pVScrollBar->SetVisibleSize(aOut.Height());
584cdf0e10cSrcweir 		pVScrollBar->SetPageSize(aOut.Height() * 8 / 10);
585cdf0e10cSrcweir 		pVScrollBar->SetLineSize(aOut.Height() * 2 / 10);
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 		pHScrollBar->SetVisibleSize(aOut.Width());
588cdf0e10cSrcweir 		pHScrollBar->SetPageSize(aOut.Width() * 8 / 10);
589cdf0e10cSrcweir 		pHScrollBar->SetLineSize(SCROLL_LINE );
590cdf0e10cSrcweir 
591cdf0e10cSrcweir 		SetScrollBarRanges();
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 		pVScrollBar->Show();
594cdf0e10cSrcweir 		pHScrollBar->Show();
595cdf0e10cSrcweir 		pScrollBox->Show();
596cdf0e10cSrcweir 	}
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 
GetText() const600cdf0e10cSrcweir String SmEditWindow::GetText() const
601cdf0e10cSrcweir {
602cdf0e10cSrcweir 	String aText;
603cdf0e10cSrcweir     EditEngine *pEditEngine = const_cast< SmEditWindow* >(this)->GetEditEngine();
604cdf0e10cSrcweir 	DBG_ASSERT( pEditEngine, "EditEngine missing" );
605cdf0e10cSrcweir 	if (pEditEngine)
606cdf0e10cSrcweir 		aText = pEditEngine->GetText( LINEEND_LF );
607cdf0e10cSrcweir 	return aText;
608cdf0e10cSrcweir }
609cdf0e10cSrcweir 
610cdf0e10cSrcweir 
SetText(const XubString & rText)611cdf0e10cSrcweir void SmEditWindow::SetText(const XubString& rText)
612cdf0e10cSrcweir {
613cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
614cdf0e10cSrcweir 	DBG_ASSERT( pEditEngine, "EditEngine missing" );
615cdf0e10cSrcweir 	if (pEditEngine  &&  !pEditEngine->IsModified())
616cdf0e10cSrcweir 	{
617cdf0e10cSrcweir 		if (!pEditView)
618cdf0e10cSrcweir 			CreateEditView();
619cdf0e10cSrcweir 
620cdf0e10cSrcweir 		ESelection eSelection = pEditView->GetSelection();
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 		pEditEngine->SetText(rText);
623cdf0e10cSrcweir 		pEditEngine->ClearModifyFlag();
624cdf0e10cSrcweir 
625cdf0e10cSrcweir         //! Hier die Timer neu zu starten verhindert, dass die Handler fuer andere
626cdf0e10cSrcweir 		//! (im Augenblick nicht mehr aktive) Math Tasks aufgerufen werden.
627cdf0e10cSrcweir 		aModifyTimer.Start();
628cdf0e10cSrcweir 		aCursorMoveTimer.Start();
629cdf0e10cSrcweir 
630cdf0e10cSrcweir 		pEditView->SetSelection(eSelection);
631cdf0e10cSrcweir 	}
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 
GetFocus()635cdf0e10cSrcweir void SmEditWindow::GetFocus()
636cdf0e10cSrcweir {
637cdf0e10cSrcweir 	Window::GetFocus();
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     if (xAccessible.is())
640cdf0e10cSrcweir     {
641cdf0e10cSrcweir         // Note: will implicitly send the AccessibleStateType::FOCUSED event
642cdf0e10cSrcweir         ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
643cdf0e10cSrcweir         if (pHelper)
644cdf0e10cSrcweir             pHelper->SetFocus( sal_True );
645cdf0e10cSrcweir     }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir     if (!pEditView)
648cdf0e10cSrcweir          CreateEditView();
649cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
650cdf0e10cSrcweir 	if (pEditEngine)
651cdf0e10cSrcweir 		pEditEngine->SetStatusEventHdl( LINK(this, SmEditWindow, EditStatusHdl) );
652cdf0e10cSrcweir }
653cdf0e10cSrcweir 
654cdf0e10cSrcweir 
LoseFocus()655cdf0e10cSrcweir void SmEditWindow::LoseFocus()
656cdf0e10cSrcweir {
657cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
658cdf0e10cSrcweir 	if (pEditEngine)
659cdf0e10cSrcweir 		pEditEngine->SetStatusEventHdl( Link() );
660cdf0e10cSrcweir 
661cdf0e10cSrcweir 	Window::LoseFocus();
662cdf0e10cSrcweir 
663cdf0e10cSrcweir     if (xAccessible.is())
664cdf0e10cSrcweir     {
665cdf0e10cSrcweir         // Note: will implicitly send the AccessibleStateType::FOCUSED event
666cdf0e10cSrcweir         ::accessibility::AccessibleTextHelper *pHelper = pAccessible->GetTextHelper();
667cdf0e10cSrcweir         if (pHelper)
668cdf0e10cSrcweir             pHelper->SetFocus( sal_False );
669cdf0e10cSrcweir     }
670cdf0e10cSrcweir }
671cdf0e10cSrcweir 
672cdf0e10cSrcweir 
IsAllSelected() const673cdf0e10cSrcweir sal_Bool SmEditWindow::IsAllSelected() const
674cdf0e10cSrcweir {
675cdf0e10cSrcweir     sal_Bool bRes = sal_False;
676cdf0e10cSrcweir     EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
677cdf0e10cSrcweir 	DBG_ASSERT( pEditView, "NULL pointer" );
678cdf0e10cSrcweir     DBG_ASSERT( pEditEngine, "NULL pointer" );
679cdf0e10cSrcweir     if (pEditEngine  &&  pEditView)
680cdf0e10cSrcweir     {
681cdf0e10cSrcweir         ESelection eSelection( pEditView->GetSelection() );
682cdf0e10cSrcweir         sal_Int32 nParaCnt = pEditEngine->GetParagraphCount();
683cdf0e10cSrcweir         if (!(nParaCnt - 1))
684cdf0e10cSrcweir         {
685cdf0e10cSrcweir             String Text( pEditEngine->GetText( LINEEND_LF ) );
686cdf0e10cSrcweir             bRes = !eSelection.nStartPos && (eSelection.nEndPos == Text.Len () - 1);
687cdf0e10cSrcweir         }
688cdf0e10cSrcweir         else
689cdf0e10cSrcweir         {
690cdf0e10cSrcweir             bRes = !eSelection.nStartPara && (eSelection.nEndPara == nParaCnt - 1);
691cdf0e10cSrcweir         }
692cdf0e10cSrcweir     }
693cdf0e10cSrcweir     return bRes;
694cdf0e10cSrcweir }
695cdf0e10cSrcweir 
SelectAll()696cdf0e10cSrcweir void SmEditWindow::SelectAll()
697cdf0e10cSrcweir {
698cdf0e10cSrcweir 	DBG_ASSERT( pEditView, "NULL pointer" );
699cdf0e10cSrcweir 	if (pEditView)
700cdf0e10cSrcweir 	{
701cdf0e10cSrcweir 		// 0xFFFF as last two parameters refers to the end of the text
702cdf0e10cSrcweir 		pEditView->SetSelection( ESelection( 0, 0, 0xFFFF, 0xFFFF ) );
703cdf0e10cSrcweir 	}
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
InsertCommand(sal_uInt16 nCommand)706cdf0e10cSrcweir void SmEditWindow::InsertCommand(sal_uInt16 nCommand)
707cdf0e10cSrcweir {
708cdf0e10cSrcweir     DBG_ASSERT( pEditView, "EditView missing" );
709cdf0e10cSrcweir     if (pEditView)
710cdf0e10cSrcweir     {
711cdf0e10cSrcweir         //Anfang der Selektion merken und hinterher den Cursor daraufsetzen. Nur so
712cdf0e10cSrcweir         //macht das SelNextMark() Sinn.
713cdf0e10cSrcweir         ESelection aSelection = pEditView->GetSelection();
714cdf0e10cSrcweir         aSelection.nEndPos  = aSelection.nStartPos;
715cdf0e10cSrcweir         aSelection.nEndPara = aSelection.nStartPara;
716cdf0e10cSrcweir 
717cdf0e10cSrcweir         DBG_ASSERT( pEditView, "NULL pointer" );
718cdf0e10cSrcweir         String  aText = String(SmResId(nCommand));
719cdf0e10cSrcweir         pEditView->InsertText(aText);
720cdf0e10cSrcweir 
721cdf0e10cSrcweir         if (HasMark(aText))
722cdf0e10cSrcweir         {   // set selection to next mark
723cdf0e10cSrcweir             pEditView->SetSelection(aSelection);
724cdf0e10cSrcweir             SelNextMark();
725cdf0e10cSrcweir         }
726cdf0e10cSrcweir         else
727cdf0e10cSrcweir         {   // set selection after inserted text
728cdf0e10cSrcweir             aSelection.nEndPos    = aSelection.nEndPos + sal::static_int_cast< xub_StrLen >(aText.Len());
729cdf0e10cSrcweir             aSelection.nStartPos  = aSelection.nEndPos;
730cdf0e10cSrcweir             pEditView->SetSelection(aSelection);
731cdf0e10cSrcweir         }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir         aModifyTimer.Start();
734cdf0e10cSrcweir 		aCursorMoveTimer.Start();
735cdf0e10cSrcweir 
736cdf0e10cSrcweir         GrabFocus();
737cdf0e10cSrcweir     }
738cdf0e10cSrcweir }
739cdf0e10cSrcweir 
MarkError(const Point & rPos)740cdf0e10cSrcweir void SmEditWindow::MarkError(const Point &rPos)
741cdf0e10cSrcweir {
742cdf0e10cSrcweir     DBG_ASSERT( pEditView, "EditView missing" );
743cdf0e10cSrcweir     if (pEditView)
744cdf0e10cSrcweir     {
745cdf0e10cSrcweir         const xub_StrLen    nCol = sal::static_int_cast< xub_StrLen >(rPos.X());
746cdf0e10cSrcweir         const sal_uInt16        nRow = sal::static_int_cast< sal_uInt16 >(rPos.Y() - 1);
747cdf0e10cSrcweir 
748cdf0e10cSrcweir         pEditView->SetSelection(ESelection(nRow, nCol - 1, nRow, nCol));
749cdf0e10cSrcweir         GrabFocus();
750cdf0e10cSrcweir     }
751cdf0e10cSrcweir }
752cdf0e10cSrcweir 
SelNextMark()753cdf0e10cSrcweir void SmEditWindow::SelNextMark()
754cdf0e10cSrcweir {
755cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
756cdf0e10cSrcweir 	DBG_ASSERT( pEditView, "NULL pointer" );
757cdf0e10cSrcweir 	DBG_ASSERT( pEditEngine, "NULL pointer" );
758cdf0e10cSrcweir     if (pEditEngine  &&  pEditView)
759cdf0e10cSrcweir     {
760cdf0e10cSrcweir         ESelection eSelection = pEditView->GetSelection();
761cdf0e10cSrcweir         sal_uInt16     Pos        = eSelection.nEndPos;
762cdf0e10cSrcweir         String     aMark (C2S("<?>"));
763cdf0e10cSrcweir         String     aText;
764cdf0e10cSrcweir         sal_uInt16     nCounts    = pEditEngine->GetParagraphCount();
765cdf0e10cSrcweir 
766cdf0e10cSrcweir         while (eSelection.nEndPara < nCounts)
767cdf0e10cSrcweir         {
768cdf0e10cSrcweir             aText = pEditEngine->GetText( eSelection.nEndPara );
769cdf0e10cSrcweir             Pos   = aText.Search(aMark, Pos);
770cdf0e10cSrcweir 
771cdf0e10cSrcweir             if (Pos != STRING_NOTFOUND)
772cdf0e10cSrcweir             {
773cdf0e10cSrcweir                 pEditView->SetSelection(ESelection (eSelection.nEndPara, Pos, eSelection.nEndPara, Pos + 3));
774cdf0e10cSrcweir                 break;
775cdf0e10cSrcweir             }
776cdf0e10cSrcweir 
777cdf0e10cSrcweir             Pos = 0;
778cdf0e10cSrcweir             eSelection.nEndPara++;
779cdf0e10cSrcweir         }
780cdf0e10cSrcweir     }
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
SelPrevMark()783cdf0e10cSrcweir void SmEditWindow::SelPrevMark()
784cdf0e10cSrcweir {
785cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
786cdf0e10cSrcweir 	DBG_ASSERT( pEditEngine, "NULL pointer" );
787cdf0e10cSrcweir 	DBG_ASSERT( pEditView, "NULL pointer" );
788cdf0e10cSrcweir     if (pEditEngine  &&  pEditView)
789cdf0e10cSrcweir     {
790cdf0e10cSrcweir         ESelection eSelection = pEditView->GetSelection();
791cdf0e10cSrcweir         sal_uInt16     Pos        = STRING_NOTFOUND;
792cdf0e10cSrcweir         xub_StrLen Max        = eSelection.nStartPos;
793cdf0e10cSrcweir         String     Text( pEditEngine->GetText( eSelection.nStartPara ) );
794cdf0e10cSrcweir         String     aMark (C2S("<?>"));
795cdf0e10cSrcweir         sal_uInt16     nCounts    = pEditEngine->GetParagraphCount();
796cdf0e10cSrcweir 
797cdf0e10cSrcweir         do
798cdf0e10cSrcweir         {
799cdf0e10cSrcweir             sal_uInt16 Fnd = Text.Search(aMark, 0);
800cdf0e10cSrcweir 
801cdf0e10cSrcweir             while ((Fnd < Max) && (Fnd != STRING_NOTFOUND))
802cdf0e10cSrcweir             {
803cdf0e10cSrcweir                 Pos = Fnd;
804cdf0e10cSrcweir                 Fnd = Text.Search(aMark, Fnd + 1);
805cdf0e10cSrcweir             }
806cdf0e10cSrcweir 
807cdf0e10cSrcweir             if (Pos == STRING_NOTFOUND)
808cdf0e10cSrcweir             {
809cdf0e10cSrcweir                 eSelection.nStartPara--;
810cdf0e10cSrcweir                 Text = pEditEngine->GetText( eSelection.nStartPara );
811cdf0e10cSrcweir                 Max = Text.Len();
812cdf0e10cSrcweir             }
813cdf0e10cSrcweir         }
814cdf0e10cSrcweir         while ((eSelection.nStartPara < nCounts) &&
815cdf0e10cSrcweir             (Pos == STRING_NOTFOUND));
816cdf0e10cSrcweir 
817cdf0e10cSrcweir         if (Pos != STRING_NOTFOUND)
818cdf0e10cSrcweir         {
819cdf0e10cSrcweir             pEditView->SetSelection(ESelection (eSelection.nStartPara, Pos, eSelection.nStartPara, Pos + 3));
820cdf0e10cSrcweir         }
821cdf0e10cSrcweir     }
822cdf0e10cSrcweir }
823cdf0e10cSrcweir 
HasMark(const String & rText) const824cdf0e10cSrcweir sal_Bool SmEditWindow::HasMark(const String& rText) const
825cdf0e10cSrcweir 	// returns true iff 'rText' contains a mark
826cdf0e10cSrcweir {
827cdf0e10cSrcweir 	return rText.SearchAscii("<?>", 0) != STRING_NOTFOUND;
828cdf0e10cSrcweir }
829cdf0e10cSrcweir 
MouseMove(const MouseEvent & rEvt)830cdf0e10cSrcweir void SmEditWindow::MouseMove(const MouseEvent &rEvt)
831cdf0e10cSrcweir {
832cdf0e10cSrcweir 	if (pEditView)
833cdf0e10cSrcweir 		pEditView->MouseMove(rEvt);
834cdf0e10cSrcweir }
835cdf0e10cSrcweir 
AcceptDrop(const AcceptDropEvent &)836cdf0e10cSrcweir sal_Int8 SmEditWindow::AcceptDrop( const AcceptDropEvent& /*rEvt*/ )
837cdf0e10cSrcweir {
838cdf0e10cSrcweir 	return pEditView ? /*pEditView->QueryDrop( rEvt )*/DND_ACTION_NONE: DND_ACTION_NONE;
839cdf0e10cSrcweir }
840cdf0e10cSrcweir 
ExecuteDrop(const ExecuteDropEvent &)841cdf0e10cSrcweir sal_Int8 SmEditWindow::ExecuteDrop( const ExecuteDropEvent& /*rEvt*/ )
842cdf0e10cSrcweir {
843cdf0e10cSrcweir 	return pEditView ? /*pEditView->Drop( rEvt )*/DND_ACTION_NONE : DND_ACTION_NONE;
844cdf0e10cSrcweir }
845cdf0e10cSrcweir 
GetSelection() const846cdf0e10cSrcweir ESelection SmEditWindow::GetSelection() const
847cdf0e10cSrcweir {
848cdf0e10cSrcweir     // pointer may be 0 when reloading a document and the old view
849cdf0e10cSrcweir     // was already destroyed
850cdf0e10cSrcweir     //(DBG_ASSERT( pEditView, "NULL pointer" );
851cdf0e10cSrcweir 	ESelection eSel;
852cdf0e10cSrcweir 	if (pEditView)
853cdf0e10cSrcweir 		eSel = pEditView->GetSelection();
854cdf0e10cSrcweir 	return eSel;
855cdf0e10cSrcweir }
856cdf0e10cSrcweir 
SetSelection(const ESelection & rSel)857cdf0e10cSrcweir void SmEditWindow::SetSelection(const ESelection &rSel)
858cdf0e10cSrcweir {
859cdf0e10cSrcweir 	DBG_ASSERT( pEditView, "NULL pointer" );
860cdf0e10cSrcweir     if (pEditView)
861cdf0e10cSrcweir         pEditView->SetSelection(rSel);
862cdf0e10cSrcweir 	InvalidateSlots();
863cdf0e10cSrcweir }
864cdf0e10cSrcweir 
IsEmpty() const865cdf0e10cSrcweir sal_Bool SmEditWindow::IsEmpty() const
866cdf0e10cSrcweir {
867cdf0e10cSrcweir     EditEngine *pEditEngine = ((SmEditWindow *) this)->GetEditEngine();
868cdf0e10cSrcweir     sal_Bool bEmpty = sal::static_int_cast< sal_Bool >(
869cdf0e10cSrcweir                     pEditEngine ? pEditEngine->GetTextLen() == 0 : sal_False);
870cdf0e10cSrcweir     return bEmpty;
871cdf0e10cSrcweir }
872cdf0e10cSrcweir 
IsSelected() const873cdf0e10cSrcweir sal_Bool SmEditWindow::IsSelected() const
874cdf0e10cSrcweir {
875cdf0e10cSrcweir     return pEditView ? pEditView->HasSelection() : sal_False;
876cdf0e10cSrcweir }
877cdf0e10cSrcweir 
878*a050e4e7SAriel Constenla-Haile 
UpdateStatus(bool bSetDocModified)879*a050e4e7SAriel Constenla-Haile void SmEditWindow::UpdateStatus( bool bSetDocModified )
880*a050e4e7SAriel Constenla-Haile {
881*a050e4e7SAriel Constenla-Haile     SmModule *pMod = SM_MOD();
882*a050e4e7SAriel Constenla-Haile     if (pMod && pMod->GetConfig()->IsAutoRedraw())
883*a050e4e7SAriel Constenla-Haile         Flush();
884*a050e4e7SAriel Constenla-Haile     if ( bSetDocModified )
885*a050e4e7SAriel Constenla-Haile         GetDoc()->SetModified( sal_True );
886*a050e4e7SAriel Constenla-Haile }
887*a050e4e7SAriel Constenla-Haile 
Cut()888cdf0e10cSrcweir void SmEditWindow::Cut()
889cdf0e10cSrcweir {
890cdf0e10cSrcweir     DBG_ASSERT( pEditView, "EditView missing" );
891cdf0e10cSrcweir     if (pEditView)
892cdf0e10cSrcweir     {
893cdf0e10cSrcweir         pEditView->Cut();
894*a050e4e7SAriel Constenla-Haile         UpdateStatus( sal_True );
895cdf0e10cSrcweir     }
896cdf0e10cSrcweir }
897cdf0e10cSrcweir 
Copy()898cdf0e10cSrcweir void SmEditWindow::Copy()
899cdf0e10cSrcweir {
900cdf0e10cSrcweir     DBG_ASSERT( pEditView, "EditView missing" );
901cdf0e10cSrcweir     if (pEditView)
902cdf0e10cSrcweir         pEditView->Copy();
903cdf0e10cSrcweir }
904cdf0e10cSrcweir 
Paste()905cdf0e10cSrcweir void SmEditWindow::Paste()
906cdf0e10cSrcweir {
907cdf0e10cSrcweir     DBG_ASSERT( pEditView, "EditView missing" );
908cdf0e10cSrcweir     if (pEditView)
909cdf0e10cSrcweir     {
910cdf0e10cSrcweir         pEditView->Paste();
911*a050e4e7SAriel Constenla-Haile         UpdateStatus( sal_True );
912cdf0e10cSrcweir     }
913cdf0e10cSrcweir }
914cdf0e10cSrcweir 
Delete()915cdf0e10cSrcweir void SmEditWindow::Delete()
916cdf0e10cSrcweir {
917cdf0e10cSrcweir     DBG_ASSERT( pEditView, "EditView missing" );
918cdf0e10cSrcweir     if (pEditView)
919cdf0e10cSrcweir     {
920cdf0e10cSrcweir         pEditView->DeleteSelected();
921*a050e4e7SAriel Constenla-Haile         UpdateStatus( sal_True );
922cdf0e10cSrcweir     }
923cdf0e10cSrcweir }
924cdf0e10cSrcweir 
InsertText(const String & Text)925cdf0e10cSrcweir void SmEditWindow::InsertText(const String& Text)
926cdf0e10cSrcweir {
927cdf0e10cSrcweir     DBG_ASSERT( pEditView, "EditView missing" );
928cdf0e10cSrcweir     if (pEditView)
929cdf0e10cSrcweir     {
930cdf0e10cSrcweir         pEditView->InsertText(Text);
931cdf0e10cSrcweir         aModifyTimer.Start();
932cdf0e10cSrcweir 		aCursorMoveTimer.Start();
933cdf0e10cSrcweir     }
934cdf0e10cSrcweir }
935cdf0e10cSrcweir 
Flush()936cdf0e10cSrcweir void SmEditWindow::Flush()
937cdf0e10cSrcweir {
938cdf0e10cSrcweir     EditEngine *pEditEngine = GetEditEngine();
939cdf0e10cSrcweir 	if (pEditEngine  &&  pEditEngine->IsModified())
940cdf0e10cSrcweir 	{
941cdf0e10cSrcweir 		pEditEngine->ClearModifyFlag();
942cdf0e10cSrcweir         SmViewShell *pViewSh = rCmdBox.GetView();
943cdf0e10cSrcweir 		if (pViewSh)
944cdf0e10cSrcweir         {
945cdf0e10cSrcweir 			pViewSh->GetViewFrame()->GetDispatcher()->Execute(
946cdf0e10cSrcweir 					SID_TEXT, SFX_CALLMODE_STANDARD,
947cdf0e10cSrcweir 					new SfxStringItem(SID_TEXT, GetText()), 0L);
948cdf0e10cSrcweir         }
949cdf0e10cSrcweir 	}
950cdf0e10cSrcweir 
951cdf0e10cSrcweir 	if (aCursorMoveTimer.IsActive())
952cdf0e10cSrcweir 	{
953cdf0e10cSrcweir 		aCursorMoveTimer.Stop();
954cdf0e10cSrcweir 		// ggf noch die (neue) FormulaCursor Position setzen
955cdf0e10cSrcweir 		CursorMoveTimerHdl(&aCursorMoveTimer);
956cdf0e10cSrcweir 	}
957cdf0e10cSrcweir }
958cdf0e10cSrcweir 
959cdf0e10cSrcweir 
DeleteEditView(SmViewShell &)960cdf0e10cSrcweir void SmEditWindow::DeleteEditView( SmViewShell & /*rView*/ )
961cdf0e10cSrcweir {
962cdf0e10cSrcweir     if (pEditView)
963cdf0e10cSrcweir     {
964cdf0e10cSrcweir         EditEngine *pEditEngine = pEditView->GetEditEngine();
965cdf0e10cSrcweir         if (pEditEngine)
966cdf0e10cSrcweir         {
967cdf0e10cSrcweir             pEditEngine->SetStatusEventHdl( Link() );
968cdf0e10cSrcweir             pEditEngine->RemoveView( pEditView );
969cdf0e10cSrcweir         }
970cdf0e10cSrcweir         delete pEditView;
971cdf0e10cSrcweir         pEditView = 0;
972cdf0e10cSrcweir     }
973cdf0e10cSrcweir }
974cdf0e10cSrcweir 
975cdf0e10cSrcweir 
CreateAccessible()976cdf0e10cSrcweir uno::Reference< XAccessible > SmEditWindow::CreateAccessible()
977cdf0e10cSrcweir {
978cdf0e10cSrcweir     if (!pAccessible)
979cdf0e10cSrcweir     {
980cdf0e10cSrcweir         pAccessible = new SmEditAccessible( this );
981cdf0e10cSrcweir         xAccessible = pAccessible;
982cdf0e10cSrcweir         pAccessible->Init();
983cdf0e10cSrcweir     }
984cdf0e10cSrcweir     return xAccessible;
985cdf0e10cSrcweir }
986cdf0e10cSrcweir 
987