xref: /aoo41x/main/sc/source/ui/app/inputwin.cxx (revision 36eb089e)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <algorithm>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "scitems.hxx"
30cdf0e10cSrcweir #include <editeng/eeitem.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <sfx2/app.hxx>
33cdf0e10cSrcweir #include <editeng/adjitem.hxx>
34cdf0e10cSrcweir #include <editeng/editview.hxx>
35cdf0e10cSrcweir #include <editeng/editstat.hxx>
36cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
37cdf0e10cSrcweir #include <editeng/lspcitem.hxx>
38cdf0e10cSrcweir #include <sfx2/bindings.hxx>
39cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
40cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
41cdf0e10cSrcweir #include <sfx2/event.hxx>
42cdf0e10cSrcweir #include <sfx2/imgmgr.hxx>
43cdf0e10cSrcweir #include <stdlib.h>		// qsort
44cdf0e10cSrcweir #include <editeng/scriptspaceitem.hxx>
45cdf0e10cSrcweir #include <editeng/scripttypeitem.hxx>
46cdf0e10cSrcweir #include <vcl/cursor.hxx>
47cdf0e10cSrcweir #include <vcl/help.hxx>
48cdf0e10cSrcweir #include <svl/stritem.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include "inputwin.hxx"
51cdf0e10cSrcweir #include "scmod.hxx"
52cdf0e10cSrcweir #include "uiitems.hxx"
53cdf0e10cSrcweir #include "global.hxx"
54cdf0e10cSrcweir #include "scresid.hxx"
55cdf0e10cSrcweir #include "sc.hrc"
56cdf0e10cSrcweir #include "globstr.hrc"
57cdf0e10cSrcweir #include "editutil.hxx"
58cdf0e10cSrcweir #include "inputhdl.hxx"
59cdf0e10cSrcweir #include "tabvwsh.hxx"
60cdf0e10cSrcweir #include "document.hxx"
61cdf0e10cSrcweir #include "docsh.hxx"
62cdf0e10cSrcweir #include "appoptio.hxx"
63cdf0e10cSrcweir #include "rangenam.hxx"
64cdf0e10cSrcweir #include <formula/compiler.hrc>
65cdf0e10cSrcweir #include "dbcolect.hxx"
66cdf0e10cSrcweir #include "rangeutl.hxx"
67cdf0e10cSrcweir #include "docfunc.hxx"
68cdf0e10cSrcweir #include "funcdesc.hxx"
69cdf0e10cSrcweir #include <editeng/fontitem.hxx>
70cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessible.hpp>
71cdf0e10cSrcweir #include "AccessibleEditObject.hxx"
72cdf0e10cSrcweir #include "AccessibleText.hxx"
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #define TEXT_STARTPOS		3
75cdf0e10cSrcweir #define THESIZE				1000000	//!!! langt... :-)
76cdf0e10cSrcweir #define TBX_WINDOW_HEIGHT 	22 // in Pixeln - fuer alle Systeme gleich?
77cdf0e10cSrcweir 
78cdf0e10cSrcweir enum ScNameInputType
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     SC_NAME_INPUT_CELL,
81cdf0e10cSrcweir     SC_NAME_INPUT_RANGE,
82cdf0e10cSrcweir     SC_NAME_INPUT_NAMEDRANGE,
83cdf0e10cSrcweir     SC_NAME_INPUT_DATABASE,
84cdf0e10cSrcweir     SC_NAME_INPUT_ROW,
85cdf0e10cSrcweir     SC_NAME_INPUT_SHEET,
86cdf0e10cSrcweir     SC_NAME_INPUT_DEFINE,
87cdf0e10cSrcweir     SC_NAME_INPUT_BAD_NAME,
88cdf0e10cSrcweir     SC_NAME_INPUT_BAD_SELECTION
89cdf0e10cSrcweir };
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //==================================================================
93cdf0e10cSrcweir //	class ScInputWindowWrapper
94cdf0e10cSrcweir //==================================================================
95cdf0e10cSrcweir 
SFX_IMPL_CHILDWINDOW(ScInputWindowWrapper,FID_INPUTLINE_STATUS)96cdf0e10cSrcweir SFX_IMPL_CHILDWINDOW(ScInputWindowWrapper,FID_INPUTLINE_STATUS)
97cdf0e10cSrcweir 
98cdf0e10cSrcweir ScInputWindowWrapper::ScInputWindowWrapper( Window*          pParentP,
99cdf0e10cSrcweir 											sal_uInt16			 nId,
100cdf0e10cSrcweir 											SfxBindings*	 pBindings,
101cdf0e10cSrcweir                                             SfxChildWinInfo* /* pInfo */ )
102cdf0e10cSrcweir     :   SfxChildWindow( pParentP, nId )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     ScInputWindow* pWin=new ScInputWindow( pParentP, pBindings );
105cdf0e10cSrcweir 	pWindow = pWin;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	pWin->Show();
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	pWin->SetSizePixel( pWin->CalcWindowSizePixel() );
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	eChildAlignment = SFX_ALIGN_LOWESTTOP;
112cdf0e10cSrcweir 	pBindings->Invalidate( FID_TOGGLEINPUTLINE );
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir //	GetInfo fliegt wieder raus, wenn es ein SFX_IMPL_TOOLBOX gibt !!!!
116cdf0e10cSrcweir 
GetInfo() const117cdf0e10cSrcweir SfxChildWinInfo __EXPORT ScInputWindowWrapper::GetInfo() const
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();
120cdf0e10cSrcweir 	return aInfo;
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //==================================================================
124cdf0e10cSrcweir 
125cdf0e10cSrcweir #define IMAGE(id) pImgMgr->SeekImage(id, bHC)
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //==================================================================
128cdf0e10cSrcweir //	class ScInputWindow
129cdf0e10cSrcweir //==================================================================
130cdf0e10cSrcweir 
ScInputWindow(Window * pParent,SfxBindings * pBind)131cdf0e10cSrcweir ScInputWindow::ScInputWindow( Window* pParent, SfxBindings* pBind ) :
132cdf0e10cSrcweir #ifdef OS2
133cdf0e10cSrcweir // #37192# ohne WB_CLIPCHILDREN wg. os/2 Paintproblem
134cdf0e10cSrcweir 		ToolBox         ( pParent, WinBits(WB_BORDER|WB_3DLOOK) ),
135cdf0e10cSrcweir #else
136cdf0e10cSrcweir // mit WB_CLIPCHILDREN, sonst Flicker
137cdf0e10cSrcweir 		ToolBox         ( pParent, WinBits(WB_BORDER|WB_3DLOOK|WB_CLIPCHILDREN) ),
138cdf0e10cSrcweir #endif
139cdf0e10cSrcweir 		aWndPos         ( this ),
140cdf0e10cSrcweir 		aTextWindow     ( this ),
141cdf0e10cSrcweir 		pInputHdl		( NULL ),
142cdf0e10cSrcweir         pBindings       ( pBind ),
143cdf0e10cSrcweir 		aTextOk			( ScResId( SCSTR_QHELP_BTNOK ) ),		// nicht immer neu aus Resource
144cdf0e10cSrcweir 		aTextCancel		( ScResId( SCSTR_QHELP_BTNCANCEL ) ),
145cdf0e10cSrcweir 		aTextSum		( ScResId( SCSTR_QHELP_BTNSUM ) ),
146cdf0e10cSrcweir 		aTextEqual		( ScResId( SCSTR_QHELP_BTNEQUAL ) ),
147cdf0e10cSrcweir 		bIsOkCancelMode ( sal_False )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	ScModule*		 pScMod  = SC_MOD();
150cdf0e10cSrcweir     SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // #i73615# don't rely on SfxViewShell::Current while constructing the input line
153cdf0e10cSrcweir     // (also for GetInputHdl below)
154cdf0e10cSrcweir     ScTabViewShell* pViewSh = NULL;
155cdf0e10cSrcweir     SfxDispatcher* pDisp = pBind->GetDispatcher();
156cdf0e10cSrcweir     if ( pDisp )
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         SfxViewFrame* pViewFrm = pDisp->GetFrame();
159cdf0e10cSrcweir         if ( pViewFrm )
160cdf0e10cSrcweir             pViewSh = PTR_CAST( ScTabViewShell, pViewFrm->GetViewShell() );
161cdf0e10cSrcweir     }
162cdf0e10cSrcweir     DBG_ASSERT( pViewSh, "no view shell for input window" );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	// Positionsfenster, 3 Buttons, Eingabefenster
167cdf0e10cSrcweir 	InsertWindow    ( 1, &aWndPos, 0,								      0 );
168cdf0e10cSrcweir 	InsertSeparator ( 												   	  1 );
169cdf0e10cSrcweir 	InsertItem      ( SID_INPUT_FUNCTION, IMAGE( SID_INPUT_FUNCTION ), 0, 2 );
170cdf0e10cSrcweir 	InsertItem      ( SID_INPUT_SUM, 	  IMAGE( SID_INPUT_SUM ), 0,      3 );
171cdf0e10cSrcweir 	InsertItem      ( SID_INPUT_EQUAL,	  IMAGE( SID_INPUT_EQUAL ), 0,    4 );
172cdf0e10cSrcweir 	InsertSeparator ( 												      5 );
173cdf0e10cSrcweir 	InsertWindow    ( 7, &aTextWindow, 0,                                 6 );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	aWndPos	   .SetQuickHelpText( ScResId( SCSTR_QHELP_POSWND ) );
176cdf0e10cSrcweir 	aWndPos    .SetHelpId		( HID_INSWIN_POS );
177cdf0e10cSrcweir 	aTextWindow.SetQuickHelpText( ScResId( SCSTR_QHELP_INPUTWND ) );
178cdf0e10cSrcweir 	aTextWindow.SetHelpId		( HID_INSWIN_INPUT );
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	//	kein SetHelpText, die Hilfetexte kommen aus der Hilfe
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	SetItemText ( SID_INPUT_FUNCTION, ScResId( SCSTR_QHELP_BTNCALC ) );
183cdf0e10cSrcweir 	SetHelpId	( SID_INPUT_FUNCTION, HID_INSWIN_CALC );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	SetItemText ( SID_INPUT_SUM, aTextSum );
186cdf0e10cSrcweir 	SetHelpId	( SID_INPUT_SUM, HID_INSWIN_SUMME );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	SetItemText ( SID_INPUT_EQUAL, aTextEqual );
189cdf0e10cSrcweir 	SetHelpId	( SID_INPUT_EQUAL, HID_INSWIN_FUNC );
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	SetHelpId( HID_SC_INPUTWIN );	// fuer die ganze Eingabezeile
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	aWndPos		.Show();
194cdf0e10cSrcweir 	aTextWindow	.Show();
195cdf0e10cSrcweir 
196cdf0e10cSrcweir     pInputHdl = SC_MOD()->GetInputHdl( pViewSh, sal_False );    // use own handler even if ref-handler is set
197cdf0e10cSrcweir 	if (pInputHdl)
198cdf0e10cSrcweir 		pInputHdl->SetInputWindow( this );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 	if ( pInputHdl && pInputHdl->GetFormString().Len() )
201cdf0e10cSrcweir 	{
202cdf0e10cSrcweir 		//	Umschalten waehrend der Funktionsautopilot aktiv ist
203cdf0e10cSrcweir 		//	-> Inhalt des Funktionsautopiloten wieder anzeigen
204cdf0e10cSrcweir 		//!	auch Selektion (am InputHdl gemerkt) wieder anzeigen
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		aTextWindow.SetTextString( pInputHdl->GetFormString() );
207cdf0e10cSrcweir 	}
208cdf0e10cSrcweir 	else if ( pInputHdl && pInputHdl->IsInputMode() )
209cdf0e10cSrcweir 	{
210cdf0e10cSrcweir 		//	wenn waehrend des Editierens die Eingabezeile weg war
211cdf0e10cSrcweir 		//	(Editieren einer Formel, dann umschalten zu fremdem Dokument/Hilfe),
212cdf0e10cSrcweir 		//	wieder den gerade editierten Text aus dem InputHandler anzeigen
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 		aTextWindow.SetTextString( pInputHdl->GetEditString() );	// Text anzeigen
215cdf0e10cSrcweir 		if ( pInputHdl->IsTopMode() )
216cdf0e10cSrcweir 			pInputHdl->SetMode( SC_INPUT_TABLE );		// Focus kommt eh nach unten
217cdf0e10cSrcweir 	}
218cdf0e10cSrcweir 	else if ( pViewSh )
219cdf0e10cSrcweir 		pViewSh->UpdateInputHandler( sal_True ); // unbedingtes Update
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 	pImgMgr->RegisterToolBox( this );
222cdf0e10cSrcweir 	SetAccessibleName(ScResId(STR_ACC_TOOLBAR_FORMULA));
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
~ScInputWindow()225cdf0e10cSrcweir __EXPORT ScInputWindow::~ScInputWindow()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     sal_Bool bDown = ( ScGlobal::pSysLocale == NULL );    // after Clear?
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	//	if any view's input handler has a pointer to this input window, reset it
230cdf0e10cSrcweir 	//	(may be several ones, #74522#)
231cdf0e10cSrcweir 	//	member pInputHdl is not used here
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	if ( !bDown )
234cdf0e10cSrcweir 	{
235cdf0e10cSrcweir 		TypeId aScType = TYPE(ScTabViewShell);
236cdf0e10cSrcweir 		SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
237cdf0e10cSrcweir 		while ( pSh )
238cdf0e10cSrcweir 		{
239cdf0e10cSrcweir 			ScInputHandler* pHdl = ((ScTabViewShell*)pSh)->GetInputHandler();
240cdf0e10cSrcweir 			if ( pHdl && pHdl->GetInputWindow() == this )
241cdf0e10cSrcweir             {
242cdf0e10cSrcweir 				pHdl->SetInputWindow( NULL );
243cdf0e10cSrcweir                 pHdl->StopInputWinEngine( sal_False );  // #125841# reset pTopView pointer
244cdf0e10cSrcweir             }
245cdf0e10cSrcweir 			pSh = SfxViewShell::GetNext( *pSh, &aScType );
246cdf0e10cSrcweir 		}
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     SfxImageManager::GetImageManager( SC_MOD() )->ReleaseToolBox( this );
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
SetInputHandler(ScInputHandler * pNew)252cdf0e10cSrcweir void ScInputWindow::SetInputHandler( ScInputHandler* pNew )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	//	wird im Activate der View gerufen...
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     if ( pNew != pInputHdl )
257cdf0e10cSrcweir 	{
258cdf0e10cSrcweir 		//	Bei Reload (letzte Version) ist pInputHdl der Input-Handler der alten,
259cdf0e10cSrcweir 		//	geloeschten ViewShell, darum hier auf keinen Fall anfassen!
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 		pInputHdl = pNew;
262cdf0e10cSrcweir 		if (pInputHdl)
263cdf0e10cSrcweir 			pInputHdl->SetInputWindow( this );
264cdf0e10cSrcweir 	}
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
UseSubTotal(ScRangeList * pRangeList) const267cdf0e10cSrcweir sal_Bool ScInputWindow::UseSubTotal(ScRangeList* pRangeList) const
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     sal_Bool bSubTotal(sal_False);
270cdf0e10cSrcweir     ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
271cdf0e10cSrcweir     if ( pViewSh )
272cdf0e10cSrcweir     {
273cdf0e10cSrcweir         ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
274cdf0e10cSrcweir         sal_Int32 nRangeCount (pRangeList->Count());
275cdf0e10cSrcweir         sal_Int32 nRangeIndex (0);
276cdf0e10cSrcweir         while (!bSubTotal && nRangeIndex < nRangeCount)
277cdf0e10cSrcweir         {
278cdf0e10cSrcweir             const ScRange* pRange = pRangeList->GetObject( nRangeIndex );
279cdf0e10cSrcweir             if( pRange )
280cdf0e10cSrcweir             {
281cdf0e10cSrcweir                 SCTAB nTabEnd(pRange->aEnd.Tab());
282cdf0e10cSrcweir                 SCTAB nTab(pRange->aStart.Tab());
283cdf0e10cSrcweir                 while (!bSubTotal && nTab <= nTabEnd)
284cdf0e10cSrcweir                 {
285cdf0e10cSrcweir                     SCROW nRowEnd(pRange->aEnd.Row());
286cdf0e10cSrcweir                     SCROW nRow(pRange->aStart.Row());
287cdf0e10cSrcweir                     while (!bSubTotal && nRow <= nRowEnd)
288cdf0e10cSrcweir                     {
289cdf0e10cSrcweir                         if (pDoc->RowFiltered(nRow, nTab))
290cdf0e10cSrcweir                             bSubTotal = sal_True;
291cdf0e10cSrcweir                         else
292cdf0e10cSrcweir                             ++nRow;
293cdf0e10cSrcweir                     }
294cdf0e10cSrcweir                     ++nTab;
295cdf0e10cSrcweir                 }
296cdf0e10cSrcweir             }
297cdf0e10cSrcweir             ++nRangeIndex;
298cdf0e10cSrcweir         }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir         ScDBCollection* pDBCollection = pDoc->GetDBCollection();
301cdf0e10cSrcweir         sal_uInt16 nDBCount (pDBCollection->GetCount());
302cdf0e10cSrcweir         sal_uInt16 nDBIndex (0);
303cdf0e10cSrcweir         while (!bSubTotal && nDBIndex < nDBCount)
304cdf0e10cSrcweir         {
305cdf0e10cSrcweir             ScDBData* pDB = (*pDBCollection)[nDBIndex];
306cdf0e10cSrcweir             if (pDB && pDB->HasAutoFilter())
307cdf0e10cSrcweir             {
308cdf0e10cSrcweir                 nRangeIndex = 0;
309cdf0e10cSrcweir                 while (!bSubTotal && nRangeIndex < nRangeCount)
310cdf0e10cSrcweir                 {
311cdf0e10cSrcweir                     const ScRange* pRange = pRangeList->GetObject( nRangeIndex );
312cdf0e10cSrcweir                     if( pRange )
313cdf0e10cSrcweir                     {
314cdf0e10cSrcweir                         ScRange aDBArea;
315cdf0e10cSrcweir                         pDB->GetArea(aDBArea);
316cdf0e10cSrcweir                         if (aDBArea.Intersects(*pRange))
317cdf0e10cSrcweir                             bSubTotal = sal_True;
318cdf0e10cSrcweir                     }
319cdf0e10cSrcweir                     ++nRangeIndex;
320cdf0e10cSrcweir                 }
321cdf0e10cSrcweir             }
322cdf0e10cSrcweir             ++nDBIndex;
323cdf0e10cSrcweir         }
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir     return bSubTotal;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
Select()328cdf0e10cSrcweir void __EXPORT ScInputWindow::Select()
329cdf0e10cSrcweir {
330cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
331cdf0e10cSrcweir 	ToolBox::Select();
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	switch ( GetCurItemId() )
334cdf0e10cSrcweir 	{
335cdf0e10cSrcweir 		case SID_INPUT_FUNCTION:
336cdf0e10cSrcweir 			{
337cdf0e10cSrcweir 				//!	new method at ScModule to query if function autopilot is open
338cdf0e10cSrcweir 				SfxViewFrame* pViewFrm = SfxViewFrame::Current();
339cdf0e10cSrcweir 				if ( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) )
340cdf0e10cSrcweir 				{
341cdf0e10cSrcweir 					pViewFrm->GetDispatcher()->Execute( SID_OPENDLG_FUNCTION,
342cdf0e10cSrcweir 											  SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 					//	die Toolbox wird sowieso disabled, also braucht auch nicht umgeschaltet
345cdf0e10cSrcweir 					//	zu werden, egal ob's geklappt hat oder nicht
346cdf0e10cSrcweir //					SetOkCancelMode();
347cdf0e10cSrcweir 				}
348cdf0e10cSrcweir 			}
349cdf0e10cSrcweir 			break;
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 		case SID_INPUT_CANCEL:
352cdf0e10cSrcweir 			pScMod->InputCancelHandler();
353cdf0e10cSrcweir 			SetSumAssignMode();
354cdf0e10cSrcweir 			break;
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 		case SID_INPUT_OK:
357cdf0e10cSrcweir 			pScMod->InputEnterHandler();
358cdf0e10cSrcweir 			SetSumAssignMode();
359cdf0e10cSrcweir 			aTextWindow.Invalidate();		// sonst bleibt Selektion stehen
360cdf0e10cSrcweir 			break;
361cdf0e10cSrcweir 
362cdf0e10cSrcweir 		case SID_INPUT_SUM:
363cdf0e10cSrcweir 			{
364cdf0e10cSrcweir 				ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
365cdf0e10cSrcweir 				if ( pViewSh )
366cdf0e10cSrcweir 				{
367cdf0e10cSrcweir 					const ScMarkData& rMark = pViewSh->GetViewData()->GetMarkData();
368cdf0e10cSrcweir 					if ( rMark.IsMarked() || rMark.IsMultiMarked() )
369cdf0e10cSrcweir 					{
370cdf0e10cSrcweir                         ScRangeList aMarkRangeList;
371cdf0e10cSrcweir                         rMark.FillRangeListWithMarks( &aMarkRangeList, sal_False );
372cdf0e10cSrcweir                         ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
373cdf0e10cSrcweir 
374cdf0e10cSrcweir                         // check if one of the marked ranges is empty
375cdf0e10cSrcweir                         bool bEmpty = false;
376cdf0e10cSrcweir                         const sal_uLong nCount = aMarkRangeList.Count();
377cdf0e10cSrcweir                         for ( sal_uLong i = 0; i < nCount; ++i )
378cdf0e10cSrcweir                         {
379cdf0e10cSrcweir                             const ScRange aRange( *aMarkRangeList.GetObject( i ) );
380cdf0e10cSrcweir                             if ( pDoc->IsBlockEmpty( aRange.aStart.Tab(),
381cdf0e10cSrcweir                                     aRange.aStart.Col(), aRange.aStart.Row(),
382cdf0e10cSrcweir                                     aRange.aEnd.Col(), aRange.aEnd.Row() ) )
383cdf0e10cSrcweir                             {
384cdf0e10cSrcweir                                 bEmpty = true;
385cdf0e10cSrcweir                                 break;
386cdf0e10cSrcweir                             }
387cdf0e10cSrcweir                         }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir                         if ( bEmpty )
390cdf0e10cSrcweir                         {
391cdf0e10cSrcweir                             ScRangeList aRangeList;
392cdf0e10cSrcweir 					        const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList );
393cdf0e10cSrcweir                             if ( bDataFound )
394cdf0e10cSrcweir                             {
395cdf0e10cSrcweir                                 const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) );
396cdf0e10cSrcweir                                 pViewSh->EnterAutoSum( aRangeList, bSubTotal );	// Block mit Summen fuellen
397cdf0e10cSrcweir                             }
398cdf0e10cSrcweir                         }
399cdf0e10cSrcweir                         else
400cdf0e10cSrcweir                         {
401cdf0e10cSrcweir                             const sal_Bool bSubTotal( UseSubTotal( &aMarkRangeList ) );
402cdf0e10cSrcweir                             for ( sal_uLong i = 0; i < nCount; ++i )
403cdf0e10cSrcweir                             {
404cdf0e10cSrcweir                                 const ScRange aRange( *aMarkRangeList.GetObject( i ) );
405cdf0e10cSrcweir                                 const bool bSetCursor = ( i == nCount - 1 ? true : false );
406cdf0e10cSrcweir                                 const bool bContinue = ( i != 0  ? true : false );
407cdf0e10cSrcweir                                 if ( !pViewSh->AutoSum( aRange, bSubTotal, bSetCursor, bContinue ) )
408cdf0e10cSrcweir                                 {
409cdf0e10cSrcweir                                     pViewSh->MarkRange( aRange, sal_False, sal_False );
410cdf0e10cSrcweir                                     pViewSh->SetCursor( aRange.aEnd.Col(), aRange.aEnd.Row() );
411cdf0e10cSrcweir                                     const ScRangeList aRangeList;
412cdf0e10cSrcweir                                     const String aFormula = pViewSh->GetAutoSumFormula( aRangeList, bSubTotal );
413cdf0e10cSrcweir                                     SetFuncString( aFormula );
414cdf0e10cSrcweir                                     break;
415cdf0e10cSrcweir                                 }
416cdf0e10cSrcweir                             }
417cdf0e10cSrcweir                         }
418cdf0e10cSrcweir 					}
419cdf0e10cSrcweir 					else									// nur in Eingabezeile einfuegen
420cdf0e10cSrcweir 					{
421cdf0e10cSrcweir                         ScRangeList aRangeList;
422cdf0e10cSrcweir 					    const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList );
423cdf0e10cSrcweir                         const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) );
424cdf0e10cSrcweir                         const String aFormula = pViewSh->GetAutoSumFormula( aRangeList, bSubTotal );
425cdf0e10cSrcweir 						SetFuncString( aFormula );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir                         if ( bDataFound && pScMod->IsEditMode() )
428cdf0e10cSrcweir 						{
429cdf0e10cSrcweir 							ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
430cdf0e10cSrcweir 							if ( pHdl )
431cdf0e10cSrcweir 							{
432cdf0e10cSrcweir 								pHdl->InitRangeFinder( aFormula );
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 								//!	SetSelection am InputHandler ???
435cdf0e10cSrcweir 								//!	bSelIsRef setzen ???
436cdf0e10cSrcweir 								const xub_StrLen nOpen = aFormula.Search('(');
437cdf0e10cSrcweir 								const xub_StrLen nLen = aFormula.Len();
438cdf0e10cSrcweir 								if ( nOpen != STRING_NOTFOUND && nLen > nOpen )
439cdf0e10cSrcweir 								{
440cdf0e10cSrcweir                                     sal_uInt8 nAdd(1);
441cdf0e10cSrcweir                                     if (bSubTotal)
442cdf0e10cSrcweir                                         nAdd = 3;
443cdf0e10cSrcweir 									ESelection aSel(0,nOpen+nAdd,0,nLen-1);
444cdf0e10cSrcweir 									EditView* pTableView = pHdl->GetTableView();
445cdf0e10cSrcweir 									if (pTableView)
446cdf0e10cSrcweir 										pTableView->SetSelection(aSel);
447cdf0e10cSrcweir 									EditView* pTopView = pHdl->GetTopView();
448cdf0e10cSrcweir 									if (pTopView)
449cdf0e10cSrcweir 										pTopView->SetSelection(aSel);
450cdf0e10cSrcweir 								}
451cdf0e10cSrcweir 							}
452cdf0e10cSrcweir 						}
453cdf0e10cSrcweir 					}
454cdf0e10cSrcweir 				}
455cdf0e10cSrcweir 			}
456cdf0e10cSrcweir 			break;
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 		case SID_INPUT_EQUAL:
459cdf0e10cSrcweir 		{
460cdf0e10cSrcweir 			aTextWindow.StartEditEngine();
461cdf0e10cSrcweir 			if ( pScMod->IsEditMode() )			// nicht, wenn z.B. geschuetzt
462cdf0e10cSrcweir 			{
463cdf0e10cSrcweir 				aTextWindow.GrabFocus();
464*36eb089eSTsutomu Uchino 
465*36eb089eSTsutomu Uchino 				xub_StrLen nStartPos = 1;
466*36eb089eSTsutomu Uchino 				xub_StrLen nEndPos = 1;
467*36eb089eSTsutomu Uchino 
468*36eb089eSTsutomu Uchino 				ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
469*36eb089eSTsutomu Uchino 				if ( pViewSh )
470*36eb089eSTsutomu Uchino 				{
471*36eb089eSTsutomu Uchino 					const String& aString = aTextWindow.GetTextString();
472*36eb089eSTsutomu Uchino 					const xub_StrLen nLen = aString.Len();
473*36eb089eSTsutomu Uchino 
474*36eb089eSTsutomu Uchino 					ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
475*36eb089eSTsutomu Uchino 					CellType eCellType = pDoc->GetCellType( pViewSh->GetViewData()->GetCurPos() );
476*36eb089eSTsutomu Uchino 					switch ( eCellType )
477*36eb089eSTsutomu Uchino 					{
478*36eb089eSTsutomu Uchino 						case CELLTYPE_VALUE:
479*36eb089eSTsutomu Uchino 						{
480*36eb089eSTsutomu Uchino 							nEndPos = nLen +1;
481*36eb089eSTsutomu Uchino 							String aNewStr( '=' );
482*36eb089eSTsutomu Uchino 							aNewStr.Append( aString );
483*36eb089eSTsutomu Uchino 							aTextWindow.SetTextString( aNewStr );
484*36eb089eSTsutomu Uchino 							break;
485*36eb089eSTsutomu Uchino 						}
486*36eb089eSTsutomu Uchino 						case CELLTYPE_STRING:
487*36eb089eSTsutomu Uchino 						case CELLTYPE_EDIT:
488*36eb089eSTsutomu Uchino 							nStartPos = 0;
489*36eb089eSTsutomu Uchino 							nEndPos = nLen;
490*36eb089eSTsutomu Uchino 							break;
491*36eb089eSTsutomu Uchino 						case CELLTYPE_FORMULA:
492*36eb089eSTsutomu Uchino 							nEndPos = nLen;
493*36eb089eSTsutomu Uchino 							break;
494*36eb089eSTsutomu Uchino 						default:
495*36eb089eSTsutomu Uchino 							aTextWindow.SetTextString( '=' );
496*36eb089eSTsutomu Uchino 							break;
497*36eb089eSTsutomu Uchino 					}
498*36eb089eSTsutomu Uchino 				}
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 				EditView* pView = aTextWindow.GetEditView();
501cdf0e10cSrcweir 				if (pView)
502cdf0e10cSrcweir 				{
503*36eb089eSTsutomu Uchino 					pView->SetSelection( ESelection(0, nStartPos, 0, nEndPos) );
504cdf0e10cSrcweir 					pScMod->InputChanged(pView);
505cdf0e10cSrcweir 					SetOkCancelMode();
506cdf0e10cSrcweir 					pView->SetEditEngineUpdateMode(sal_True);
507cdf0e10cSrcweir 				}
508cdf0e10cSrcweir 			}
509cdf0e10cSrcweir 			break;
510cdf0e10cSrcweir 		}
511cdf0e10cSrcweir 	}
512cdf0e10cSrcweir }
513cdf0e10cSrcweir 
Resize()514cdf0e10cSrcweir void __EXPORT ScInputWindow::Resize()
515cdf0e10cSrcweir {
516cdf0e10cSrcweir 	ToolBox::Resize();
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 	long nWidth = GetSizePixel().Width();
519cdf0e10cSrcweir 	long nLeft  = aTextWindow.GetPosPixel().X();
520cdf0e10cSrcweir 	Size aSize  = aTextWindow.GetSizePixel();
521cdf0e10cSrcweir 
522cdf0e10cSrcweir 	aSize.Width() = Max( ((long)(nWidth - nLeft - 5)), (long)0 );
523cdf0e10cSrcweir 	aTextWindow.SetSizePixel( aSize );
524cdf0e10cSrcweir 	aTextWindow.Invalidate();
525cdf0e10cSrcweir }
526cdf0e10cSrcweir 
SetFuncString(const String & rString,sal_Bool bDoEdit)527cdf0e10cSrcweir void ScInputWindow::SetFuncString( const String& rString, sal_Bool bDoEdit )
528cdf0e10cSrcweir {
529cdf0e10cSrcweir 	//!	new method at ScModule to query if function autopilot is open
530cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
531cdf0e10cSrcweir 	EnableButtons( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) );
532cdf0e10cSrcweir 	aTextWindow.StartEditEngine();
533cdf0e10cSrcweir 
534cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
535cdf0e10cSrcweir 	if ( pScMod->IsEditMode() )
536cdf0e10cSrcweir 	{
537cdf0e10cSrcweir 		if ( bDoEdit )
538cdf0e10cSrcweir 			aTextWindow.GrabFocus();
539cdf0e10cSrcweir 		aTextWindow.SetTextString( rString );
540cdf0e10cSrcweir 		EditView* pView = aTextWindow.GetEditView();
541cdf0e10cSrcweir 		if (pView)
542cdf0e10cSrcweir 		{
543cdf0e10cSrcweir 			xub_StrLen nLen = rString.Len();
544cdf0e10cSrcweir 
545cdf0e10cSrcweir 			if ( nLen > 0 )
546cdf0e10cSrcweir 			{
547cdf0e10cSrcweir 				nLen--;
548cdf0e10cSrcweir 				pView->SetSelection( ESelection( 0, nLen, 0, nLen ) );
549cdf0e10cSrcweir 			}
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 			pScMod->InputChanged(pView);
552cdf0e10cSrcweir 			if ( bDoEdit )
553cdf0e10cSrcweir 				SetOkCancelMode();			// nicht, wenn gleich hinterher Enter/Cancel
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 			pView->SetEditEngineUpdateMode(sal_True);
556cdf0e10cSrcweir 		}
557cdf0e10cSrcweir 	}
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
SetPosString(const String & rStr)560cdf0e10cSrcweir void ScInputWindow::SetPosString( const String& rStr )
561cdf0e10cSrcweir {
562cdf0e10cSrcweir 	aWndPos.SetPos( rStr );
563cdf0e10cSrcweir }
564cdf0e10cSrcweir 
SetTextString(const String & rString)565cdf0e10cSrcweir void ScInputWindow::SetTextString( const String& rString )
566cdf0e10cSrcweir {
567cdf0e10cSrcweir 	if (rString.Len() <= 32767)
568cdf0e10cSrcweir 		aTextWindow.SetTextString(rString);
569cdf0e10cSrcweir 	else
570cdf0e10cSrcweir 	{
571cdf0e10cSrcweir 		String aNew = rString;
572cdf0e10cSrcweir 		aNew.Erase(32767);
573cdf0e10cSrcweir 		aTextWindow.SetTextString(aNew);
574cdf0e10cSrcweir 	}
575cdf0e10cSrcweir }
576cdf0e10cSrcweir 
SetOkCancelMode()577cdf0e10cSrcweir void ScInputWindow::SetOkCancelMode()
578cdf0e10cSrcweir {
579cdf0e10cSrcweir 	//!	new method at ScModule to query if function autopilot is open
580cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
581cdf0e10cSrcweir 	EnableButtons( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) );
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
584cdf0e10cSrcweir     SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
585cdf0e10cSrcweir 	if (!bIsOkCancelMode)
586cdf0e10cSrcweir 	{
587cdf0e10cSrcweir         sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 		RemoveItem( 3 ); // SID_INPUT_SUM und SID_INPUT_EQUAL entfernen
590cdf0e10cSrcweir 		RemoveItem( 3 );
591cdf0e10cSrcweir 		InsertItem( SID_INPUT_CANCEL, IMAGE( SID_INPUT_CANCEL ), 0, 3 );
592cdf0e10cSrcweir 		InsertItem( SID_INPUT_OK,	  IMAGE( SID_INPUT_OK ),	 0, 4 );
593cdf0e10cSrcweir 		SetItemText	( SID_INPUT_CANCEL, aTextCancel );
594cdf0e10cSrcweir 		SetHelpId	( SID_INPUT_CANCEL, HID_INSWIN_CANCEL );
595cdf0e10cSrcweir 		SetItemText	( SID_INPUT_OK,		aTextOk );
596cdf0e10cSrcweir 		SetHelpId	( SID_INPUT_OK,		HID_INSWIN_OK );
597cdf0e10cSrcweir 		bIsOkCancelMode = sal_True;
598cdf0e10cSrcweir 	}
599cdf0e10cSrcweir }
600cdf0e10cSrcweir 
SetSumAssignMode()601cdf0e10cSrcweir void ScInputWindow::SetSumAssignMode()
602cdf0e10cSrcweir {
603cdf0e10cSrcweir 	//!	new method at ScModule to query if function autopilot is open
604cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
605cdf0e10cSrcweir 	EnableButtons( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) );
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 	ScModule* pScMod = SC_MOD();
608cdf0e10cSrcweir     SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
609cdf0e10cSrcweir 	if (bIsOkCancelMode)
610cdf0e10cSrcweir 	{
611cdf0e10cSrcweir         sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 		// SID_INPUT_CANCEL, und SID_INPUT_OK entfernen
614cdf0e10cSrcweir 		RemoveItem( 3 );
615cdf0e10cSrcweir 		RemoveItem( 3 );
616cdf0e10cSrcweir 		InsertItem( SID_INPUT_SUM, 	 IMAGE( SID_INPUT_SUM ), 	 0, 3 );
617cdf0e10cSrcweir 		InsertItem( SID_INPUT_EQUAL, IMAGE( SID_INPUT_EQUAL ),	 0, 4 );
618cdf0e10cSrcweir 		SetItemText	( SID_INPUT_SUM,   aTextSum );
619cdf0e10cSrcweir 		SetHelpId	( SID_INPUT_SUM,   HID_INSWIN_SUMME );
620cdf0e10cSrcweir 		SetItemText	( SID_INPUT_EQUAL, aTextEqual );
621cdf0e10cSrcweir 		SetHelpId	( SID_INPUT_EQUAL, HID_INSWIN_FUNC );
622cdf0e10cSrcweir 		bIsOkCancelMode = sal_False;
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 		SetFormulaMode(sal_False);		// kein editieren -> keine Formel
625cdf0e10cSrcweir 	}
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
SetFormulaMode(sal_Bool bSet)628cdf0e10cSrcweir void ScInputWindow::SetFormulaMode( sal_Bool bSet )
629cdf0e10cSrcweir {
630cdf0e10cSrcweir 	aWndPos.SetFormulaMode(bSet);
631cdf0e10cSrcweir 	aTextWindow.SetFormulaMode(bSet);
632cdf0e10cSrcweir }
633cdf0e10cSrcweir 
SetText(const String & rString)634cdf0e10cSrcweir void __EXPORT ScInputWindow::SetText( const String& rString )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir 	ToolBox::SetText(rString);
637cdf0e10cSrcweir }
638cdf0e10cSrcweir 
GetText() const639cdf0e10cSrcweir String __EXPORT ScInputWindow::GetText() const
640cdf0e10cSrcweir {
641cdf0e10cSrcweir 	return ToolBox::GetText();
642cdf0e10cSrcweir }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 
645cdf0e10cSrcweir //UNUSED2008-05  EditView* ScInputWindow::ActivateEdit( const String&     rText,
646cdf0e10cSrcweir //UNUSED2008-05                                         const ESelection& rSel )
647cdf0e10cSrcweir //UNUSED2008-05  {
648cdf0e10cSrcweir //UNUSED2008-05      if ( !aTextWindow.IsInputActive() )
649cdf0e10cSrcweir //UNUSED2008-05      {
650cdf0e10cSrcweir //UNUSED2008-05          aTextWindow.StartEditEngine();
651cdf0e10cSrcweir //UNUSED2008-05          aTextWindow.GrabFocus();
652cdf0e10cSrcweir //UNUSED2008-05          aTextWindow.SetTextString( rText );
653cdf0e10cSrcweir //UNUSED2008-05          aTextWindow.GetEditView()->SetSelection( rSel );
654cdf0e10cSrcweir //UNUSED2008-05      }
655cdf0e10cSrcweir //UNUSED2008-05
656cdf0e10cSrcweir //UNUSED2008-05      return aTextWindow.GetEditView();
657cdf0e10cSrcweir //UNUSED2008-05  }
658cdf0e10cSrcweir 
IsInputActive()659cdf0e10cSrcweir sal_Bool ScInputWindow::IsInputActive()
660cdf0e10cSrcweir {
661cdf0e10cSrcweir 	return aTextWindow.IsInputActive();
662cdf0e10cSrcweir }
663cdf0e10cSrcweir 
GetEditView()664cdf0e10cSrcweir EditView* ScInputWindow::GetEditView()
665cdf0e10cSrcweir {
666cdf0e10cSrcweir 	return aTextWindow.GetEditView();
667cdf0e10cSrcweir }
668cdf0e10cSrcweir 
MakeDialogEditView()669cdf0e10cSrcweir void ScInputWindow::MakeDialogEditView()
670cdf0e10cSrcweir {
671cdf0e10cSrcweir 	aTextWindow.MakeDialogEditView();
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
StopEditEngine(sal_Bool bAll)674cdf0e10cSrcweir void ScInputWindow::StopEditEngine( sal_Bool bAll )
675cdf0e10cSrcweir {
676cdf0e10cSrcweir 	aTextWindow.StopEditEngine( bAll );
677cdf0e10cSrcweir }
678cdf0e10cSrcweir 
TextGrabFocus()679cdf0e10cSrcweir void ScInputWindow::TextGrabFocus()
680cdf0e10cSrcweir {
681cdf0e10cSrcweir 	aTextWindow.GrabFocus();
682cdf0e10cSrcweir }
683cdf0e10cSrcweir 
TextInvalidate()684cdf0e10cSrcweir void ScInputWindow::TextInvalidate()
685cdf0e10cSrcweir {
686cdf0e10cSrcweir 	aTextWindow.Invalidate();
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
SwitchToTextWin()689cdf0e10cSrcweir void ScInputWindow::SwitchToTextWin()
690cdf0e10cSrcweir {
691cdf0e10cSrcweir 	// used for shift-ctrl-F2
692cdf0e10cSrcweir 
693cdf0e10cSrcweir 	aTextWindow.StartEditEngine();
694cdf0e10cSrcweir 	if ( SC_MOD()->IsEditMode() )
695cdf0e10cSrcweir 	{
696cdf0e10cSrcweir 		aTextWindow.GrabFocus();
697cdf0e10cSrcweir 		EditView* pView = aTextWindow.GetEditView();
698cdf0e10cSrcweir 		if (pView)
699cdf0e10cSrcweir 		{
700cdf0e10cSrcweir 			xub_StrLen nLen = pView->GetEditEngine()->GetTextLen(0);
701cdf0e10cSrcweir 			ESelection aSel( 0, nLen, 0, nLen );
702cdf0e10cSrcweir 			pView->SetSelection( aSel );				// set cursor to end of text
703cdf0e10cSrcweir 		}
704cdf0e10cSrcweir 	}
705cdf0e10cSrcweir }
706cdf0e10cSrcweir 
PosGrabFocus()707cdf0e10cSrcweir void ScInputWindow::PosGrabFocus()
708cdf0e10cSrcweir {
709cdf0e10cSrcweir 	aWndPos.GrabFocus();
710cdf0e10cSrcweir }
711cdf0e10cSrcweir 
EnableButtons(sal_Bool bEnable)712cdf0e10cSrcweir void ScInputWindow::EnableButtons( sal_Bool bEnable )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir 	//	when enabling buttons, always also enable the input window itself
715cdf0e10cSrcweir 	if ( bEnable && !IsEnabled() )
716cdf0e10cSrcweir 		Enable();
717cdf0e10cSrcweir 
718cdf0e10cSrcweir 	EnableItem( SID_INPUT_FUNCTION,									  bEnable );
719cdf0e10cSrcweir 	EnableItem( bIsOkCancelMode ? SID_INPUT_CANCEL : SID_INPUT_SUM,   bEnable );
720cdf0e10cSrcweir 	EnableItem( bIsOkCancelMode ? SID_INPUT_OK     : SID_INPUT_EQUAL, bEnable );
721cdf0e10cSrcweir //	Invalidate();
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
StateChanged(StateChangedType nType)724cdf0e10cSrcweir void ScInputWindow::StateChanged( StateChangedType nType )
725cdf0e10cSrcweir {
726cdf0e10cSrcweir 	ToolBox::StateChanged( nType );
727cdf0e10cSrcweir 
728cdf0e10cSrcweir 	if ( nType == STATE_CHANGE_INITSHOW ) Resize();
729cdf0e10cSrcweir }
730cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)731cdf0e10cSrcweir void ScInputWindow::DataChanged( const DataChangedEvent& rDCEvt )
732cdf0e10cSrcweir {
733cdf0e10cSrcweir 	if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
734cdf0e10cSrcweir 	{
735cdf0e10cSrcweir 		//	update item images
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 		ScModule*		 pScMod  = SC_MOD();
738cdf0e10cSrcweir         SfxImageManager* pImgMgr = SfxImageManager::GetImageManager( pScMod );
739cdf0e10cSrcweir         sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
740cdf0e10cSrcweir 		// IMAGE macro uses pScMod, pImgMgr, bHC
741cdf0e10cSrcweir 
742cdf0e10cSrcweir 		SetItemImage( SID_INPUT_FUNCTION, IMAGE( SID_INPUT_FUNCTION ) );
743cdf0e10cSrcweir 		if ( bIsOkCancelMode )
744cdf0e10cSrcweir 		{
745cdf0e10cSrcweir 			SetItemImage( SID_INPUT_CANCEL, IMAGE( SID_INPUT_CANCEL ) );
746cdf0e10cSrcweir 			SetItemImage( SID_INPUT_OK,     IMAGE( SID_INPUT_OK ) );
747cdf0e10cSrcweir 		}
748cdf0e10cSrcweir 		else
749cdf0e10cSrcweir 		{
750cdf0e10cSrcweir 			SetItemImage( SID_INPUT_SUM,   IMAGE( SID_INPUT_SUM ) );
751cdf0e10cSrcweir 			SetItemImage( SID_INPUT_EQUAL, IMAGE( SID_INPUT_EQUAL ) );
752cdf0e10cSrcweir 		}
753cdf0e10cSrcweir 	}
754cdf0e10cSrcweir 
755cdf0e10cSrcweir     ToolBox::DataChanged( rDCEvt );
756cdf0e10cSrcweir }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir //========================================================================
759cdf0e10cSrcweir // 							Eingabefenster
760cdf0e10cSrcweir //========================================================================
761cdf0e10cSrcweir 
ScTextWnd(Window * pParent)762cdf0e10cSrcweir ScTextWnd::ScTextWnd( Window* pParent )
763cdf0e10cSrcweir 	:	Window		 ( pParent, WinBits(WB_HIDE | WB_BORDER) ),
764cdf0e10cSrcweir 		DragSourceHelper( this ),
765cdf0e10cSrcweir 		pEditEngine	 ( NULL ),
766cdf0e10cSrcweir 		pEditView	 ( NULL ),
767cdf0e10cSrcweir 		bIsInsertMode( sal_True ),
768cdf0e10cSrcweir 		bFormulaMode ( sal_False ),
769cdf0e10cSrcweir         bInputMode   ( sal_False )
770cdf0e10cSrcweir {
771cdf0e10cSrcweir 	EnableRTL( sal_False );		// #106269# EditEngine can't be used with VCL EnableRTL
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 	bIsRTL = GetSettings().GetLayoutRTL();
774cdf0e10cSrcweir 
775cdf0e10cSrcweir 	//	#79096# always use application font, so a font with cjk chars can be installed
776cdf0e10cSrcweir 	Font aAppFont = GetFont();
777cdf0e10cSrcweir 	aTextFont = aAppFont;
778cdf0e10cSrcweir 	aTextFont.SetSize( PixelToLogic( aAppFont.GetSize(), MAP_TWIP ) );	// AppFont ist in Pixeln
779cdf0e10cSrcweir 
780cdf0e10cSrcweir 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 	Color aBgColor= rStyleSettings.GetWindowColor();
783cdf0e10cSrcweir 	Color aTxtColor= rStyleSettings.GetWindowTextColor();
784cdf0e10cSrcweir 
785cdf0e10cSrcweir 	aTextFont.SetTransparent ( sal_True );
786cdf0e10cSrcweir 	aTextFont.SetFillColor   ( aBgColor );
787cdf0e10cSrcweir 	//aTextFont.SetColor		 ( COL_FIELDTEXT );
788cdf0e10cSrcweir 	aTextFont.SetColor		 (aTxtColor);
789cdf0e10cSrcweir 	aTextFont.SetWeight		 ( WEIGHT_NORMAL );
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 	Size aSize(1,TBX_WINDOW_HEIGHT);
792cdf0e10cSrcweir 	Size aMinEditSize( Edit::GetMinimumEditSize() );
793cdf0e10cSrcweir 	if( aMinEditSize.Height() > aSize.Height() )
794cdf0e10cSrcweir 	    aSize.Height() = aMinEditSize.Height();
795cdf0e10cSrcweir 	SetSizePixel		( aSize );
796cdf0e10cSrcweir 	SetBackground		( aBgColor );
797cdf0e10cSrcweir 	SetLineColor		( COL_BLACK );
798cdf0e10cSrcweir 	SetMapMode		    ( MAP_TWIP );
799cdf0e10cSrcweir 	SetPointer		    ( POINTER_TEXT );
800cdf0e10cSrcweir }
801cdf0e10cSrcweir 
~ScTextWnd()802cdf0e10cSrcweir __EXPORT ScTextWnd::~ScTextWnd()
803cdf0e10cSrcweir {
804cdf0e10cSrcweir     while (!maAccTextDatas.empty()) {
805cdf0e10cSrcweir         maAccTextDatas.back()->Dispose();
806cdf0e10cSrcweir     }
807cdf0e10cSrcweir     delete pEditView;
808cdf0e10cSrcweir     delete pEditEngine;
809cdf0e10cSrcweir }
810cdf0e10cSrcweir 
Paint(const Rectangle & rRec)811cdf0e10cSrcweir void __EXPORT ScTextWnd::Paint( const Rectangle& rRec )
812cdf0e10cSrcweir {
813cdf0e10cSrcweir 	if (pEditView)
814cdf0e10cSrcweir 		pEditView->Paint( rRec );
815cdf0e10cSrcweir 	else
816cdf0e10cSrcweir 	{
817cdf0e10cSrcweir 		SetFont( aTextFont );
818cdf0e10cSrcweir 
819cdf0e10cSrcweir 		long nDiff =  GetOutputSizePixel().Height()
820cdf0e10cSrcweir 					- LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
821cdf0e10cSrcweir //		if (nDiff<2) nDiff=2;		// mind. 1 Pixel
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 		long nStartPos = TEXT_STARTPOS;
824cdf0e10cSrcweir 		if ( bIsRTL )
825cdf0e10cSrcweir 		{
826cdf0e10cSrcweir 			//	right-align
827cdf0e10cSrcweir 			nStartPos += GetOutputSizePixel().Width() - 2*TEXT_STARTPOS -
828cdf0e10cSrcweir 						LogicToPixel( Size( GetTextWidth( aString ), 0 ) ).Width();
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 			//	LayoutMode isn't changed as long as ModifyRTLDefaults doesn't include SvxFrameDirectionItem
831cdf0e10cSrcweir 		}
832cdf0e10cSrcweir 
833cdf0e10cSrcweir 		DrawText( PixelToLogic( Point( nStartPos, nDiff/2 ) ), aString );
834cdf0e10cSrcweir 	}
835cdf0e10cSrcweir }
836cdf0e10cSrcweir 
Resize()837cdf0e10cSrcweir void __EXPORT ScTextWnd::Resize()
838cdf0e10cSrcweir {
839cdf0e10cSrcweir 	if (pEditView)
840cdf0e10cSrcweir 	{
841cdf0e10cSrcweir 		Size aSize = GetOutputSizePixel();
842cdf0e10cSrcweir 		long nDiff =  aSize.Height()
843cdf0e10cSrcweir 					- LogicToPixel( Size( 0, GetTextHeight() ) ).Height();
844cdf0e10cSrcweir 
845cdf0e10cSrcweir #ifdef OS2_DOCH_NICHT
846cdf0e10cSrcweir 		nDiff-=2;		// wird durch 2 geteilt
847cdf0e10cSrcweir 						// passt sonst nicht zur normalen Textausgabe
848cdf0e10cSrcweir #endif
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 		aSize.Width() -= 2 * TEXT_STARTPOS - 1;
851cdf0e10cSrcweir 
852cdf0e10cSrcweir 		pEditView->SetOutputArea(
853cdf0e10cSrcweir 			PixelToLogic( Rectangle( Point( TEXT_STARTPOS, (nDiff > 0) ? nDiff/2 : 1 ),
854cdf0e10cSrcweir 									 aSize ) ) );
855cdf0e10cSrcweir 	}
856cdf0e10cSrcweir }
857cdf0e10cSrcweir 
MouseMove(const MouseEvent & rMEvt)858cdf0e10cSrcweir void __EXPORT ScTextWnd::MouseMove( const MouseEvent& rMEvt )
859cdf0e10cSrcweir {
860cdf0e10cSrcweir 	if (pEditView)
861cdf0e10cSrcweir 		pEditView->MouseMove( rMEvt );
862cdf0e10cSrcweir }
863cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)864cdf0e10cSrcweir void __EXPORT ScTextWnd::MouseButtonDown( const MouseEvent& rMEvt )
865cdf0e10cSrcweir {
866cdf0e10cSrcweir 	if (!HasFocus())
867cdf0e10cSrcweir 	{
868cdf0e10cSrcweir 		StartEditEngine();
869cdf0e10cSrcweir 		if ( SC_MOD()->IsEditMode() )
870cdf0e10cSrcweir 			GrabFocus();
871cdf0e10cSrcweir 	}
872cdf0e10cSrcweir 
873cdf0e10cSrcweir 	if (pEditView)
874cdf0e10cSrcweir 	{
875cdf0e10cSrcweir 		pEditView->SetEditEngineUpdateMode( sal_True );
876cdf0e10cSrcweir 		pEditView->MouseButtonDown( rMEvt );
877cdf0e10cSrcweir 	}
878cdf0e10cSrcweir }
879cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent & rMEvt)880cdf0e10cSrcweir void __EXPORT ScTextWnd::MouseButtonUp( const MouseEvent& rMEvt )
881cdf0e10cSrcweir {
882cdf0e10cSrcweir 	if (pEditView)
883cdf0e10cSrcweir 		if (pEditView->MouseButtonUp( rMEvt ))
884cdf0e10cSrcweir 		{
885cdf0e10cSrcweir 			if ( rMEvt.IsMiddle() &&
886cdf0e10cSrcweir 		         	GetSettings().GetMouseSettings().GetMiddleButtonAction() == MOUSE_MIDDLE_PASTESELECTION )
887cdf0e10cSrcweir 		    {
888cdf0e10cSrcweir 		    	//	EditView may have pasted from selection
889cdf0e10cSrcweir 		    	SC_MOD()->InputChanged( pEditView );
890cdf0e10cSrcweir 		    }
891cdf0e10cSrcweir 			else
892cdf0e10cSrcweir 				SC_MOD()->InputSelection( pEditView );
893cdf0e10cSrcweir 		}
894cdf0e10cSrcweir }
895cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)896cdf0e10cSrcweir void __EXPORT ScTextWnd::Command( const CommandEvent& rCEvt )
897cdf0e10cSrcweir {
898cdf0e10cSrcweir     bInputMode = sal_True;
899cdf0e10cSrcweir 	sal_uInt16 nCommand = rCEvt.GetCommand();
900cdf0e10cSrcweir 	if ( pEditView /* && ( nCommand == COMMAND_STARTDRAG || nCommand == COMMAND_VOICE ) */ )
901cdf0e10cSrcweir 	{
902cdf0e10cSrcweir 		ScModule* pScMod = SC_MOD();
903cdf0e10cSrcweir 		ScTabViewShell* pStartViewSh = ScTabViewShell::GetActiveViewShell();
904cdf0e10cSrcweir 
905cdf0e10cSrcweir 		// #109441# don't modify the font defaults here - the right defaults are
906cdf0e10cSrcweir 		// already set in StartEditEngine when the EditEngine is created
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 		// #63263# verhindern, dass die EditView beim View-Umschalten wegkommt
909cdf0e10cSrcweir 		pScMod->SetInEditCommand( sal_True );
910cdf0e10cSrcweir 		pEditView->Command( rCEvt );
911cdf0e10cSrcweir 		pScMod->SetInEditCommand( sal_False );
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 		//	#48929# COMMAND_STARTDRAG heiss noch lange nicht, dass der Inhalt geaendert wurde
914cdf0e10cSrcweir 		//	darum in dem Fall kein InputChanged
915cdf0e10cSrcweir 		//!	erkennen, ob mit Move gedraggt wurde, oder Drag&Move irgendwie verbieten
916cdf0e10cSrcweir 
917cdf0e10cSrcweir 		if ( nCommand == COMMAND_STARTDRAG )
918cdf0e10cSrcweir 		{
919cdf0e10cSrcweir 			//	ist auf eine andere View gedraggt worden?
920cdf0e10cSrcweir 			ScTabViewShell* pEndViewSh = ScTabViewShell::GetActiveViewShell();
921cdf0e10cSrcweir 			if ( pEndViewSh != pStartViewSh && pStartViewSh != NULL )
922cdf0e10cSrcweir 			{
923cdf0e10cSrcweir 				ScViewData* pViewData = pStartViewSh->GetViewData();
924cdf0e10cSrcweir 				ScInputHandler* pHdl = pScMod->GetInputHdl( pStartViewSh );
925cdf0e10cSrcweir 				if ( pHdl && pViewData->HasEditView( pViewData->GetActivePart() ) )
926cdf0e10cSrcweir 				{
927cdf0e10cSrcweir 					pHdl->CancelHandler();
928cdf0e10cSrcweir 					pViewData->GetView()->ShowCursor();		// fehlt bei KillEditView, weil nicht aktiv
929cdf0e10cSrcweir 				}
930cdf0e10cSrcweir 			}
931cdf0e10cSrcweir 		}
932cdf0e10cSrcweir 		else if ( nCommand == COMMAND_CURSORPOS )
933cdf0e10cSrcweir 		{
934cdf0e10cSrcweir 			//	don't call InputChanged for COMMAND_CURSORPOS
935cdf0e10cSrcweir 		}
936cdf0e10cSrcweir         else if ( nCommand == COMMAND_INPUTLANGUAGECHANGE )
937cdf0e10cSrcweir         {
938cdf0e10cSrcweir             // #i55929# Font and font size state depends on input language if nothing is selected,
939cdf0e10cSrcweir             // so the slots have to be invalidated when the input language is changed.
940cdf0e10cSrcweir 
941cdf0e10cSrcweir             SfxViewFrame* pViewFrm = SfxViewFrame::Current();
942cdf0e10cSrcweir             if (pViewFrm)
943cdf0e10cSrcweir             {
944cdf0e10cSrcweir                 SfxBindings& rBindings = pViewFrm->GetBindings();
945cdf0e10cSrcweir                 rBindings.Invalidate( SID_ATTR_CHAR_FONT );
946cdf0e10cSrcweir                 rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
947cdf0e10cSrcweir             }
948cdf0e10cSrcweir         }
949cdf0e10cSrcweir 		else
950cdf0e10cSrcweir 			SC_MOD()->InputChanged( pEditView );
951cdf0e10cSrcweir 	}
952cdf0e10cSrcweir 	else
953cdf0e10cSrcweir 		Window::Command(rCEvt);		//	sonst soll sich die Basisklasse drum kuemmern...
954cdf0e10cSrcweir 
955cdf0e10cSrcweir     bInputMode = sal_False;
956cdf0e10cSrcweir }
957cdf0e10cSrcweir 
StartDrag(sal_Int8,const Point & rPosPixel)958cdf0e10cSrcweir void ScTextWnd::StartDrag( sal_Int8 /* nAction */, const Point& rPosPixel )
959cdf0e10cSrcweir {
960cdf0e10cSrcweir 	if ( pEditView )
961cdf0e10cSrcweir 	{
962cdf0e10cSrcweir 		CommandEvent aDragEvent( rPosPixel, COMMAND_STARTDRAG, sal_True );
963cdf0e10cSrcweir 		pEditView->Command( aDragEvent );
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 		//	handling of d&d to different view (CancelHandler) can't be done here,
966cdf0e10cSrcweir 		//	because the call returns before d&d is complete.
967cdf0e10cSrcweir 	}
968cdf0e10cSrcweir }
969cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)970cdf0e10cSrcweir void __EXPORT ScTextWnd::KeyInput(const KeyEvent& rKEvt)
971cdf0e10cSrcweir {
972cdf0e10cSrcweir     bInputMode = sal_True;
973cdf0e10cSrcweir 	if (!SC_MOD()->InputKeyEvent( rKEvt ))
974cdf0e10cSrcweir 	{
975cdf0e10cSrcweir 		sal_Bool bUsed = sal_False;
976cdf0e10cSrcweir 		ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
977cdf0e10cSrcweir 		if ( pViewSh )
978cdf0e10cSrcweir 			bUsed = pViewSh->SfxKeyInput(rKEvt);	// nur Acceleratoren, keine Eingabe
979cdf0e10cSrcweir 		if (!bUsed)
980cdf0e10cSrcweir 			Window::KeyInput( rKEvt );
981cdf0e10cSrcweir 	}
982cdf0e10cSrcweir     bInputMode = sal_False;
983cdf0e10cSrcweir }
984cdf0e10cSrcweir 
GetFocus()985cdf0e10cSrcweir void __EXPORT ScTextWnd::GetFocus()
986cdf0e10cSrcweir {
987cdf0e10cSrcweir     ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
988cdf0e10cSrcweir     if ( pViewSh )
989cdf0e10cSrcweir         pViewSh->SetFormShellAtTop( sal_False );     // focus in input line -> FormShell no longer on top
990cdf0e10cSrcweir }
991cdf0e10cSrcweir 
LoseFocus()992cdf0e10cSrcweir void __EXPORT ScTextWnd::LoseFocus()
993cdf0e10cSrcweir {
994cdf0e10cSrcweir }
995cdf0e10cSrcweir 
GetText() const996cdf0e10cSrcweir String __EXPORT ScTextWnd::GetText() const
997cdf0e10cSrcweir {
998cdf0e10cSrcweir 	//	ueberladen, um per Testtool an den Text heranzukommen
999cdf0e10cSrcweir 
1000cdf0e10cSrcweir 	if ( pEditEngine )
1001cdf0e10cSrcweir 		return pEditEngine->GetText();
1002cdf0e10cSrcweir 	else
1003cdf0e10cSrcweir 		return GetTextString();
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir 
SetFormulaMode(sal_Bool bSet)1006cdf0e10cSrcweir void ScTextWnd::SetFormulaMode( sal_Bool bSet )
1007cdf0e10cSrcweir {
1008cdf0e10cSrcweir 	if ( bSet != bFormulaMode )
1009cdf0e10cSrcweir 	{
1010cdf0e10cSrcweir 		bFormulaMode = bSet;
1011cdf0e10cSrcweir 		UpdateAutoCorrFlag();
1012cdf0e10cSrcweir 	}
1013cdf0e10cSrcweir }
1014cdf0e10cSrcweir 
UpdateAutoCorrFlag()1015cdf0e10cSrcweir void ScTextWnd::UpdateAutoCorrFlag()
1016cdf0e10cSrcweir {
1017cdf0e10cSrcweir 	if ( pEditEngine )
1018cdf0e10cSrcweir 	{
1019cdf0e10cSrcweir 		sal_uLong nControl = pEditEngine->GetControlWord();
1020cdf0e10cSrcweir 		sal_uLong nOld = nControl;
1021cdf0e10cSrcweir 		if ( bFormulaMode )
1022cdf0e10cSrcweir 			nControl &= ~EE_CNTRL_AUTOCORRECT;		// keine Autokorrektur in Formeln
1023cdf0e10cSrcweir 		else
1024cdf0e10cSrcweir 			nControl |= EE_CNTRL_AUTOCORRECT;		// sonst schon
1025cdf0e10cSrcweir 		if ( nControl != nOld )
1026cdf0e10cSrcweir 			pEditEngine->SetControlWord( nControl );
1027cdf0e10cSrcweir 	}
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir 
lcl_ExtendEditFontAttribs(SfxItemSet & rSet)1030cdf0e10cSrcweir void lcl_ExtendEditFontAttribs( SfxItemSet& rSet )
1031cdf0e10cSrcweir {
1032cdf0e10cSrcweir 	const SfxPoolItem& rFontItem = rSet.Get( EE_CHAR_FONTINFO );
1033cdf0e10cSrcweir 	rSet.Put( rFontItem, EE_CHAR_FONTINFO_CJK );
1034cdf0e10cSrcweir 	rSet.Put( rFontItem, EE_CHAR_FONTINFO_CTL );
1035cdf0e10cSrcweir 	const SfxPoolItem& rHeightItem = rSet.Get( EE_CHAR_FONTHEIGHT );
1036cdf0e10cSrcweir 	rSet.Put( rHeightItem, EE_CHAR_FONTHEIGHT_CJK );
1037cdf0e10cSrcweir 	rSet.Put( rHeightItem, EE_CHAR_FONTHEIGHT_CTL );
1038cdf0e10cSrcweir 	const SfxPoolItem& rWeightItem = rSet.Get( EE_CHAR_WEIGHT );
1039cdf0e10cSrcweir 	rSet.Put( rWeightItem, EE_CHAR_WEIGHT_CJK );
1040cdf0e10cSrcweir 	rSet.Put( rWeightItem, EE_CHAR_WEIGHT_CTL );
1041cdf0e10cSrcweir 	const SfxPoolItem& rItalicItem = rSet.Get( EE_CHAR_ITALIC );
1042cdf0e10cSrcweir 	rSet.Put( rItalicItem, EE_CHAR_ITALIC_CJK );
1043cdf0e10cSrcweir 	rSet.Put( rItalicItem, EE_CHAR_ITALIC_CTL );
1044cdf0e10cSrcweir 	const SfxPoolItem& rLangItem = rSet.Get( EE_CHAR_LANGUAGE );
1045cdf0e10cSrcweir 	rSet.Put( rLangItem, EE_CHAR_LANGUAGE_CJK );
1046cdf0e10cSrcweir 	rSet.Put( rLangItem, EE_CHAR_LANGUAGE_CTL );
1047cdf0e10cSrcweir }
1048cdf0e10cSrcweir 
lcl_ModifyRTLDefaults(SfxItemSet & rSet)1049cdf0e10cSrcweir void lcl_ModifyRTLDefaults( SfxItemSet& rSet )
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir 	rSet.Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir 	//	always using rtl writing direction would break formulas
1054cdf0e10cSrcweir 	//rSet.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir 	//	PaperSize width is limited to USHRT_MAX in RTL mode (because of EditEngine's
1057cdf0e10cSrcweir 	//	sal_uInt16 values in EditLine), so the text may be wrapped and line spacing must be
1058cdf0e10cSrcweir 	//	increased to not see the beginning of the next line.
1059cdf0e10cSrcweir 	SvxLineSpacingItem aItem( SVX_LINESPACE_TWO_LINES, EE_PARA_SBL );
1060cdf0e10cSrcweir 	aItem.SetPropLineSpace( 200 );
1061cdf0e10cSrcweir 	rSet.Put( aItem );
1062cdf0e10cSrcweir }
1063cdf0e10cSrcweir 
lcl_ModifyRTLVisArea(EditView * pEditView)1064cdf0e10cSrcweir void lcl_ModifyRTLVisArea( EditView* pEditView )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir 	Rectangle aVisArea = pEditView->GetVisArea();
1067cdf0e10cSrcweir 	Size aPaper = pEditView->GetEditEngine()->GetPaperSize();
1068cdf0e10cSrcweir 	long nDiff = aPaper.Width() - aVisArea.Right();
1069cdf0e10cSrcweir 	aVisArea.Left()  += nDiff;
1070cdf0e10cSrcweir 	aVisArea.Right() += nDiff;
1071cdf0e10cSrcweir 	pEditView->SetVisArea(aVisArea);
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir 
StartEditEngine()1074cdf0e10cSrcweir void ScTextWnd::StartEditEngine()
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir 	//	#31147# Bei "eigener Modalitaet" (Doc-modale Dialoge) nicht aktivieren
1077cdf0e10cSrcweir 	SfxObjectShell* pObjSh = SfxObjectShell::Current();
1078cdf0e10cSrcweir 	if ( pObjSh && pObjSh->IsInModalMode() )
1079cdf0e10cSrcweir 		return;
1080cdf0e10cSrcweir 
1081cdf0e10cSrcweir 	if ( !pEditView || !pEditEngine )
1082cdf0e10cSrcweir 	{
1083cdf0e10cSrcweir 		ScFieldEditEngine* pNew;
1084cdf0e10cSrcweir 		ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
1085cdf0e10cSrcweir 		if ( pViewSh )
1086cdf0e10cSrcweir 		{
1087cdf0e10cSrcweir 			const ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
1088cdf0e10cSrcweir 			pNew = new ScFieldEditEngine( pDoc->GetEnginePool(), pDoc->GetEditPool() );
1089cdf0e10cSrcweir 		}
1090cdf0e10cSrcweir 		else
1091cdf0e10cSrcweir 			pNew = new ScFieldEditEngine( EditEngine::CreatePool(),	NULL, sal_True );
1092cdf0e10cSrcweir 		pNew->SetExecuteURL( sal_False );
1093cdf0e10cSrcweir 		pEditEngine = pNew;
1094cdf0e10cSrcweir 
1095cdf0e10cSrcweir 		pEditEngine->SetUpdateMode( sal_False );
1096cdf0e10cSrcweir 		pEditEngine->SetPaperSize( Size( bIsRTL ? USHRT_MAX : THESIZE, 300 ) );
1097cdf0e10cSrcweir 		pEditEngine->SetWordDelimiters(
1098cdf0e10cSrcweir 						ScEditUtil::ModifyDelimiters( pEditEngine->GetWordDelimiters() ) );
1099cdf0e10cSrcweir 
1100cdf0e10cSrcweir 		UpdateAutoCorrFlag();
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir 		{
1103cdf0e10cSrcweir 			SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() );
1104cdf0e10cSrcweir 			pEditEngine->SetFontInfoInItemSet( *pSet, aTextFont );
1105cdf0e10cSrcweir 			lcl_ExtendEditFontAttribs( *pSet );
1106cdf0e10cSrcweir 			// turn off script spacing to match DrawText output
1107cdf0e10cSrcweir 			pSet->Put( SvxScriptSpaceItem( sal_False, EE_PARA_ASIANCJKSPACING ) );
1108cdf0e10cSrcweir 			if ( bIsRTL )
1109cdf0e10cSrcweir 				lcl_ModifyRTLDefaults( *pSet );
1110cdf0e10cSrcweir 			pEditEngine->SetDefaults( pSet );
1111cdf0e10cSrcweir 		}
1112cdf0e10cSrcweir 
1113cdf0e10cSrcweir 		//	#57254# Wenn in der Zelle URL-Felder enthalten sind, muessen die auch in
1114cdf0e10cSrcweir 		//	die Eingabezeile uebernommen werden, weil sonst die Positionen nicht stimmen.
1115cdf0e10cSrcweir 
1116cdf0e10cSrcweir 		sal_Bool bFilled = sal_False;
1117cdf0e10cSrcweir 		ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
1118cdf0e10cSrcweir 		if ( pHdl )			//!	Testen, ob's der richtige InputHdl ist?
1119cdf0e10cSrcweir 			bFilled = pHdl->GetTextAndFields( *pEditEngine );
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir 		pEditEngine->SetUpdateMode( sal_True );
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 		//	aString ist die Wahrheit...
1124cdf0e10cSrcweir 		if ( bFilled && pEditEngine->GetText() == aString )
1125cdf0e10cSrcweir 			Invalidate();						// Repaint fuer (hinterlegte) Felder
1126cdf0e10cSrcweir 		else
1127cdf0e10cSrcweir 			pEditEngine->SetText(aString);		// dann wenigstens den richtigen Text
1128cdf0e10cSrcweir 
1129cdf0e10cSrcweir 		pEditView = new EditView( pEditEngine, this );
1130cdf0e10cSrcweir 		pEditView->SetInsertMode(bIsInsertMode);
1131cdf0e10cSrcweir 
1132cdf0e10cSrcweir 		// Text aus Clipboard wird als ASCII einzeilig uebernommen
1133cdf0e10cSrcweir 		sal_uLong n = pEditView->GetControlWord();
1134cdf0e10cSrcweir 		pEditView->SetControlWord( n | EV_CNTRL_SINGLELINEPASTE	);
1135cdf0e10cSrcweir 
1136cdf0e10cSrcweir 		pEditEngine->InsertView( pEditView, EE_APPEND );
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir 		Resize();
1139cdf0e10cSrcweir 
1140cdf0e10cSrcweir 		if ( bIsRTL )
1141cdf0e10cSrcweir 			lcl_ModifyRTLVisArea( pEditView );
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir         pEditEngine->SetModifyHdl(LINK(this, ScTextWnd, NotifyHdl));
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir         if (!maAccTextDatas.empty())
1146cdf0e10cSrcweir             maAccTextDatas.back()->StartEdit();
1147cdf0e10cSrcweir 
1148cdf0e10cSrcweir 		//	as long as EditEngine and DrawText sometimes differ for CTL text,
1149cdf0e10cSrcweir 		//	repaint now to have the EditEngine's version visible
1150cdf0e10cSrcweir //        SfxObjectShell* pObjSh = SfxObjectShell::Current();
1151cdf0e10cSrcweir 		if ( pObjSh && pObjSh->ISA(ScDocShell) )
1152cdf0e10cSrcweir 		{
1153cdf0e10cSrcweir 			ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument();	// any document
1154cdf0e10cSrcweir 			sal_uInt8 nScript = pDoc->GetStringScriptType( aString );
1155cdf0e10cSrcweir 			if ( nScript & SCRIPTTYPE_COMPLEX )
1156cdf0e10cSrcweir 				Invalidate();
1157cdf0e10cSrcweir 		}
1158cdf0e10cSrcweir     }
1159cdf0e10cSrcweir 
1160cdf0e10cSrcweir 	SC_MOD()->SetInputMode( SC_INPUT_TOP );
1161cdf0e10cSrcweir 
1162cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1163cdf0e10cSrcweir 	if (pViewFrm)
1164cdf0e10cSrcweir 		pViewFrm->GetBindings().Invalidate( SID_ATTR_INSERT );
1165cdf0e10cSrcweir }
1166cdf0e10cSrcweir 
IMPL_LINK(ScTextWnd,NotifyHdl,EENotify *,EMPTYARG)1167cdf0e10cSrcweir IMPL_LINK(ScTextWnd, NotifyHdl, EENotify*, EMPTYARG)
1168cdf0e10cSrcweir {
1169cdf0e10cSrcweir     if (pEditView && !bInputMode)
1170cdf0e10cSrcweir 	{
1171cdf0e10cSrcweir 		ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir 		//	#105354# Use the InputHandler's InOwnChange flag to prevent calling InputChanged
1174cdf0e10cSrcweir 		//	while an InputHandler method is modifying the EditEngine content
1175cdf0e10cSrcweir 
1176cdf0e10cSrcweir 		if ( pHdl && !pHdl->IsInOwnChange() )
1177cdf0e10cSrcweir 			pHdl->InputChanged( pEditView, sal_True );	// #i20282# InputChanged must know if called from modify handler
1178cdf0e10cSrcweir 	}
1179cdf0e10cSrcweir 
1180cdf0e10cSrcweir     return 0;
1181cdf0e10cSrcweir }
1182cdf0e10cSrcweir 
StopEditEngine(sal_Bool bAll)1183cdf0e10cSrcweir void ScTextWnd::StopEditEngine( sal_Bool bAll )
1184cdf0e10cSrcweir {
1185cdf0e10cSrcweir 	if (pEditView)
1186cdf0e10cSrcweir 	{
1187cdf0e10cSrcweir         if (!maAccTextDatas.empty())
1188cdf0e10cSrcweir             maAccTextDatas.back()->EndEdit();
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir 		ScModule* pScMod = SC_MOD();
1191cdf0e10cSrcweir 
1192cdf0e10cSrcweir 		if (!bAll)
1193cdf0e10cSrcweir 			pScMod->InputSelection( pEditView );
1194cdf0e10cSrcweir 		aString = pEditEngine->GetText();
1195cdf0e10cSrcweir 		bIsInsertMode = pEditView->IsInsertMode();
1196cdf0e10cSrcweir 		sal_Bool bSelection = pEditView->HasSelection();
1197cdf0e10cSrcweir         pEditEngine->SetModifyHdl(Link());
1198cdf0e10cSrcweir 		DELETEZ(pEditView);
1199cdf0e10cSrcweir 		DELETEZ(pEditEngine);
1200cdf0e10cSrcweir 
1201cdf0e10cSrcweir 		if ( pScMod->IsEditMode() && !bAll )
1202cdf0e10cSrcweir 			pScMod->SetInputMode(SC_INPUT_TABLE);
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir 		SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1205cdf0e10cSrcweir 		if (pViewFrm)
1206cdf0e10cSrcweir 			pViewFrm->GetBindings().Invalidate( SID_ATTR_INSERT );
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir 		if (bSelection)
1209cdf0e10cSrcweir 			Invalidate();			// damit Selektion nicht stehenbleibt
1210cdf0e10cSrcweir 	}
1211cdf0e10cSrcweir }
1212cdf0e10cSrcweir 
SetTextString(const String & rNewString)1213cdf0e10cSrcweir void ScTextWnd::SetTextString( const String& rNewString )
1214cdf0e10cSrcweir {
1215cdf0e10cSrcweir 	if ( rNewString != aString )
1216cdf0e10cSrcweir 	{
1217cdf0e10cSrcweir         bInputMode = sal_True;
1218cdf0e10cSrcweir 
1219cdf0e10cSrcweir 		//	Position der Aenderung suchen, nur Rest painten
1220cdf0e10cSrcweir 
1221cdf0e10cSrcweir 		long nInvPos = 0;
1222cdf0e10cSrcweir 		long nStartPos = 0;
1223cdf0e10cSrcweir 		long nTextSize = 0;
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir 		if (!pEditEngine)
1226cdf0e10cSrcweir 		{
1227cdf0e10cSrcweir 			sal_Bool bPaintAll;
1228cdf0e10cSrcweir 			if ( bIsRTL )
1229cdf0e10cSrcweir 				bPaintAll = sal_True;
1230cdf0e10cSrcweir 			else
1231cdf0e10cSrcweir 			{
1232cdf0e10cSrcweir 				//	test if CTL script type is involved
1233cdf0e10cSrcweir 				sal_uInt8 nOldScript = 0;
1234cdf0e10cSrcweir 				sal_uInt8 nNewScript = 0;
1235cdf0e10cSrcweir 				SfxObjectShell* pObjSh = SfxObjectShell::Current();
1236cdf0e10cSrcweir 				if ( pObjSh && pObjSh->ISA(ScDocShell) )
1237cdf0e10cSrcweir 				{
1238cdf0e10cSrcweir 					//	any document can be used (used only for its break iterator)
1239cdf0e10cSrcweir 					ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument();
1240cdf0e10cSrcweir 					nOldScript = pDoc->GetStringScriptType( aString );
1241cdf0e10cSrcweir 					nNewScript = pDoc->GetStringScriptType( rNewString );
1242cdf0e10cSrcweir 				}
1243cdf0e10cSrcweir 				bPaintAll = ( nOldScript & SCRIPTTYPE_COMPLEX ) || ( nNewScript & SCRIPTTYPE_COMPLEX );
1244cdf0e10cSrcweir 			}
1245cdf0e10cSrcweir 
1246cdf0e10cSrcweir 			if ( bPaintAll )
1247cdf0e10cSrcweir 			{
1248cdf0e10cSrcweir 				// if CTL is involved, the whole text has to be redrawn
1249cdf0e10cSrcweir 				Invalidate();
1250cdf0e10cSrcweir 			}
1251cdf0e10cSrcweir 			else
1252cdf0e10cSrcweir 			{
1253cdf0e10cSrcweir 				xub_StrLen nDifPos;
1254cdf0e10cSrcweir 				if (rNewString.Len() > aString.Len())
1255cdf0e10cSrcweir 					nDifPos = rNewString.Match(aString);
1256cdf0e10cSrcweir 				else
1257cdf0e10cSrcweir 					nDifPos = aString.Match(rNewString);
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir 				long nSize1 = GetTextWidth(aString);
1260cdf0e10cSrcweir 				long nSize2 = GetTextWidth(rNewString);
1261cdf0e10cSrcweir 				if ( nSize1>0 && nSize2>0 )
1262cdf0e10cSrcweir 					nTextSize = Max( nSize1, nSize2 );
1263cdf0e10cSrcweir 				else
1264cdf0e10cSrcweir 					nTextSize = GetOutputSize().Width();		// Ueberlauf
1265cdf0e10cSrcweir 
1266cdf0e10cSrcweir 				if (nDifPos == STRING_MATCH)
1267cdf0e10cSrcweir 					nDifPos = 0;
1268cdf0e10cSrcweir 
1269cdf0e10cSrcweir 												// -1 wegen Rundung und "A"
1270cdf0e10cSrcweir 				Point aLogicStart = PixelToLogic(Point(TEXT_STARTPOS-1,0));
1271cdf0e10cSrcweir 				nStartPos = aLogicStart.X();
1272cdf0e10cSrcweir 				nInvPos = nStartPos;
1273cdf0e10cSrcweir 				if (nDifPos)
1274cdf0e10cSrcweir 					nInvPos += GetTextWidth(aString,0,nDifPos);
1275cdf0e10cSrcweir 
1276cdf0e10cSrcweir 				sal_uInt16 nFlags = 0;
1277cdf0e10cSrcweir 				if ( nDifPos == aString.Len() )			// only new characters appended
1278cdf0e10cSrcweir 					nFlags = INVALIDATE_NOERASE;		// then background is already clear
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir 				Invalidate( Rectangle( nInvPos, 0,
1281cdf0e10cSrcweir 										nStartPos+nTextSize, GetOutputSize().Height()-1 ),
1282cdf0e10cSrcweir 							nFlags );
1283cdf0e10cSrcweir 			}
1284cdf0e10cSrcweir 		}
1285cdf0e10cSrcweir 		else
1286cdf0e10cSrcweir 		{
1287cdf0e10cSrcweir 			pEditEngine->SetText(rNewString);
1288cdf0e10cSrcweir 		}
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir 		aString = rNewString;
1291cdf0e10cSrcweir 
1292cdf0e10cSrcweir         if (!maAccTextDatas.empty())
1293cdf0e10cSrcweir             maAccTextDatas.back()->TextChanged();
1294cdf0e10cSrcweir 
1295cdf0e10cSrcweir         bInputMode = sal_False;
1296cdf0e10cSrcweir     }
1297cdf0e10cSrcweir }
1298cdf0e10cSrcweir 
GetTextString() const1299cdf0e10cSrcweir const String& ScTextWnd::GetTextString() const
1300cdf0e10cSrcweir {
1301cdf0e10cSrcweir 	return aString;
1302cdf0e10cSrcweir }
1303cdf0e10cSrcweir 
IsInputActive()1304cdf0e10cSrcweir sal_Bool ScTextWnd::IsInputActive()
1305cdf0e10cSrcweir {
1306cdf0e10cSrcweir 	return HasFocus();
1307cdf0e10cSrcweir }
1308cdf0e10cSrcweir 
GetEditView()1309cdf0e10cSrcweir EditView* ScTextWnd::GetEditView()
1310cdf0e10cSrcweir {
1311cdf0e10cSrcweir 	return pEditView;
1312cdf0e10cSrcweir }
1313cdf0e10cSrcweir 
MakeDialogEditView()1314cdf0e10cSrcweir void ScTextWnd::MakeDialogEditView()
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir 	if ( pEditView ) return;
1317cdf0e10cSrcweir 
1318cdf0e10cSrcweir 	ScFieldEditEngine* pNew;
1319cdf0e10cSrcweir 	ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
1320cdf0e10cSrcweir 	if ( pViewSh )
1321cdf0e10cSrcweir 	{
1322cdf0e10cSrcweir 		const ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
1323cdf0e10cSrcweir 		pNew = new ScFieldEditEngine( pDoc->GetEnginePool(), pDoc->GetEditPool() );
1324cdf0e10cSrcweir 	}
1325cdf0e10cSrcweir 	else
1326cdf0e10cSrcweir 		pNew = new ScFieldEditEngine( EditEngine::CreatePool(),	NULL, sal_True );
1327cdf0e10cSrcweir 	pNew->SetExecuteURL( sal_False );
1328cdf0e10cSrcweir 	pEditEngine = pNew;
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir 	pEditEngine->SetUpdateMode( sal_False );
1331cdf0e10cSrcweir 	pEditEngine->SetWordDelimiters( pEditEngine->GetWordDelimiters() += '=' );
1332cdf0e10cSrcweir 	pEditEngine->SetPaperSize( Size( bIsRTL ? USHRT_MAX : THESIZE, 300 ) );
1333cdf0e10cSrcweir 
1334cdf0e10cSrcweir 	SfxItemSet* pSet = new SfxItemSet( pEditEngine->GetEmptyItemSet() );
1335cdf0e10cSrcweir 	pEditEngine->SetFontInfoInItemSet( *pSet, aTextFont );
1336cdf0e10cSrcweir 	lcl_ExtendEditFontAttribs( *pSet );
1337cdf0e10cSrcweir 	if ( bIsRTL )
1338cdf0e10cSrcweir 		lcl_ModifyRTLDefaults( *pSet );
1339cdf0e10cSrcweir 	pEditEngine->SetDefaults( pSet );
1340cdf0e10cSrcweir 	pEditEngine->SetUpdateMode( sal_True );
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir 	pEditView	= new EditView( pEditEngine, this );
1343cdf0e10cSrcweir 	pEditEngine->InsertView( pEditView, EE_APPEND );
1344cdf0e10cSrcweir 
1345cdf0e10cSrcweir 	Resize();
1346cdf0e10cSrcweir 
1347cdf0e10cSrcweir 	if ( bIsRTL )
1348cdf0e10cSrcweir 		lcl_ModifyRTLVisArea( pEditView );
1349cdf0e10cSrcweir 
1350cdf0e10cSrcweir     if (!maAccTextDatas.empty())
1351cdf0e10cSrcweir         maAccTextDatas.back()->StartEdit();
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir 
ImplInitSettings()1354cdf0e10cSrcweir void ScTextWnd::ImplInitSettings()
1355cdf0e10cSrcweir {
1356cdf0e10cSrcweir 	bIsRTL = GetSettings().GetLayoutRTL();
1357cdf0e10cSrcweir 
1358cdf0e10cSrcweir 	const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1359cdf0e10cSrcweir 
1360cdf0e10cSrcweir 	Color aBgColor= rStyleSettings.GetWindowColor();
1361cdf0e10cSrcweir 	Color aTxtColor= rStyleSettings.GetWindowTextColor();
1362cdf0e10cSrcweir 
1363cdf0e10cSrcweir 	aTextFont.SetFillColor   ( aBgColor );
1364cdf0e10cSrcweir 	aTextFont.SetColor		 (aTxtColor);
1365cdf0e10cSrcweir 	SetBackground			( aBgColor );
1366cdf0e10cSrcweir 	Invalidate();
1367cdf0e10cSrcweir }
1368cdf0e10cSrcweir 
CreateAccessible()1369cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScTextWnd::CreateAccessible()
1370cdf0e10cSrcweir {
1371cdf0e10cSrcweir     return new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), NULL, this,
1372cdf0e10cSrcweir         rtl::OUString(String(ScResId(STR_ACC_EDITLINE_NAME))),
1373cdf0e10cSrcweir         rtl::OUString(String(ScResId(STR_ACC_EDITLINE_DESCR))), EditLine);
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir 
InsertAccessibleTextData(ScAccessibleEditLineTextData & rTextData)1376cdf0e10cSrcweir void ScTextWnd::InsertAccessibleTextData( ScAccessibleEditLineTextData& rTextData )
1377cdf0e10cSrcweir {
1378cdf0e10cSrcweir     OSL_ENSURE( ::std::find( maAccTextDatas.begin(), maAccTextDatas.end(), &rTextData ) == maAccTextDatas.end(),
1379cdf0e10cSrcweir         "ScTextWnd::InsertAccessibleTextData - passed object already registered" );
1380cdf0e10cSrcweir     maAccTextDatas.push_back( &rTextData );
1381cdf0e10cSrcweir }
1382cdf0e10cSrcweir 
RemoveAccessibleTextData(ScAccessibleEditLineTextData & rTextData)1383cdf0e10cSrcweir void ScTextWnd::RemoveAccessibleTextData( ScAccessibleEditLineTextData& rTextData )
1384cdf0e10cSrcweir {
1385cdf0e10cSrcweir     AccTextDataVector::iterator aEnd = maAccTextDatas.end();
1386cdf0e10cSrcweir     AccTextDataVector::iterator aIt = ::std::find( maAccTextDatas.begin(), aEnd, &rTextData );
1387cdf0e10cSrcweir     OSL_ENSURE( aIt != aEnd, "ScTextWnd::RemoveAccessibleTextData - passed object not registered" );
1388cdf0e10cSrcweir     if( aIt != aEnd )
1389cdf0e10cSrcweir         maAccTextDatas.erase( aIt );
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir // -----------------------------------------------------------------------
1393cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)1394cdf0e10cSrcweir void ScTextWnd::DataChanged( const DataChangedEvent& rDCEvt )
1395cdf0e10cSrcweir {
1396cdf0e10cSrcweir 	if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
1397cdf0e10cSrcweir 		 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
1398cdf0e10cSrcweir 	{
1399cdf0e10cSrcweir 		ImplInitSettings();
1400cdf0e10cSrcweir 		Invalidate();
1401cdf0e10cSrcweir 	}
1402cdf0e10cSrcweir 	else
1403cdf0e10cSrcweir 		Window::DataChanged( rDCEvt );
1404cdf0e10cSrcweir }
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir 
1407cdf0e10cSrcweir //========================================================================
1408cdf0e10cSrcweir // 							Positionsfenster
1409cdf0e10cSrcweir //========================================================================
1410cdf0e10cSrcweir 
ScPosWnd(Window * pParent)1411cdf0e10cSrcweir ScPosWnd::ScPosWnd( Window* pParent ) :
1412cdf0e10cSrcweir 	ComboBox	( pParent, WinBits(WB_HIDE | WB_DROPDOWN) ),
1413cdf0e10cSrcweir 	pAccel		( NULL ),
1414cdf0e10cSrcweir     nTipVisible ( 0 ),
1415cdf0e10cSrcweir 	bFormulaMode( sal_False )
1416cdf0e10cSrcweir {
1417cdf0e10cSrcweir 	Size aSize( GetTextWidth( String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("GW99999:GW99999")) ),
1418cdf0e10cSrcweir 				GetTextHeight() );
1419cdf0e10cSrcweir 	aSize.Width() += 25;	// ??
1420cdf0e10cSrcweir 	aSize.Height() = CalcWindowSizePixel(11);		// Funktionen: 10 MRU + "andere..."
1421cdf0e10cSrcweir 	SetSizePixel( aSize );
1422cdf0e10cSrcweir 
1423cdf0e10cSrcweir 	FillRangeNames();
1424cdf0e10cSrcweir 
1425cdf0e10cSrcweir 	StartListening( *SFX_APP() );		// fuer Navigator-Bereichsnamen-Updates
1426cdf0e10cSrcweir }
1427cdf0e10cSrcweir 
~ScPosWnd()1428cdf0e10cSrcweir __EXPORT ScPosWnd::~ScPosWnd()
1429cdf0e10cSrcweir {
1430cdf0e10cSrcweir 	EndListening( *SFX_APP() );
1431cdf0e10cSrcweir 
1432cdf0e10cSrcweir     HideTip();
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 	delete pAccel;
1435cdf0e10cSrcweir }
1436cdf0e10cSrcweir 
SetFormulaMode(sal_Bool bSet)1437cdf0e10cSrcweir void ScPosWnd::SetFormulaMode( sal_Bool bSet )
1438cdf0e10cSrcweir {
1439cdf0e10cSrcweir 	if ( bSet != bFormulaMode )
1440cdf0e10cSrcweir 	{
1441cdf0e10cSrcweir 		bFormulaMode = bSet;
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir 		if ( bSet )
1444cdf0e10cSrcweir 			FillFunctions();
1445cdf0e10cSrcweir 		else
1446cdf0e10cSrcweir 			FillRangeNames();
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir         HideTip();
1449cdf0e10cSrcweir 	}
1450cdf0e10cSrcweir }
1451cdf0e10cSrcweir 
SetPos(const String & rPosStr)1452cdf0e10cSrcweir void ScPosWnd::SetPos( const String& rPosStr )
1453cdf0e10cSrcweir {
1454cdf0e10cSrcweir 	if ( aPosStr != rPosStr )
1455cdf0e10cSrcweir 	{
1456cdf0e10cSrcweir 		aPosStr = rPosStr;
1457cdf0e10cSrcweir 		SetText(aPosStr);
1458cdf0e10cSrcweir 	}
1459cdf0e10cSrcweir }
1460cdf0e10cSrcweir 
FillRangeNames()1461cdf0e10cSrcweir void ScPosWnd::FillRangeNames()
1462cdf0e10cSrcweir {
1463cdf0e10cSrcweir 	Clear();
1464cdf0e10cSrcweir 
1465cdf0e10cSrcweir 	SfxObjectShell* pObjSh = SfxObjectShell::Current();
1466cdf0e10cSrcweir 	if ( pObjSh && pObjSh->ISA(ScDocShell) )
1467cdf0e10cSrcweir 	{
1468cdf0e10cSrcweir 		ScDocument* pDoc = ((ScDocShell*)pObjSh)->GetDocument();
1469cdf0e10cSrcweir 
1470cdf0e10cSrcweir 		//	per Hand sortieren, weil Funktionen nicht sortiert werden:
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir 		ScRangeName* pRangeNames = pDoc->GetRangeName();
1473cdf0e10cSrcweir 		sal_uInt16 nCount = pRangeNames->GetCount();
1474cdf0e10cSrcweir 		if ( nCount > 0 )
1475cdf0e10cSrcweir 		{
1476cdf0e10cSrcweir 			sal_uInt16 nValidCount = 0;
1477cdf0e10cSrcweir 			ScRange aDummy;
1478cdf0e10cSrcweir 			sal_uInt16 i;
1479cdf0e10cSrcweir 			for ( i=0; i<nCount; i++ )
1480cdf0e10cSrcweir 			{
1481cdf0e10cSrcweir 				ScRangeData* pData = (*pRangeNames)[i];
1482cdf0e10cSrcweir 				if (pData->IsValidReference(aDummy))
1483cdf0e10cSrcweir 					nValidCount++;
1484cdf0e10cSrcweir 			}
1485cdf0e10cSrcweir 			if ( nValidCount )
1486cdf0e10cSrcweir 			{
1487cdf0e10cSrcweir 				ScRangeData** ppSortArray = new ScRangeData* [ nValidCount ];
1488cdf0e10cSrcweir 				sal_uInt16 j;
1489cdf0e10cSrcweir 				for ( i=0, j=0; i<nCount; i++ )
1490cdf0e10cSrcweir 				{
1491cdf0e10cSrcweir 					ScRangeData* pData = (*pRangeNames)[i];
1492cdf0e10cSrcweir 					if (pData->IsValidReference(aDummy))
1493cdf0e10cSrcweir 						ppSortArray[j++] = pData;
1494cdf0e10cSrcweir 				}
1495cdf0e10cSrcweir #ifndef ICC
1496cdf0e10cSrcweir 				qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*),
1497cdf0e10cSrcweir 					&ScRangeData_QsortNameCompare );
1498cdf0e10cSrcweir #else
1499cdf0e10cSrcweir 				qsort( (void*)ppSortArray, nValidCount, sizeof(ScRangeData*),
1500cdf0e10cSrcweir 					ICCQsortNameCompare );
1501cdf0e10cSrcweir #endif
1502cdf0e10cSrcweir 				for ( j=0; j<nValidCount; j++ )
1503cdf0e10cSrcweir 					InsertEntry( ppSortArray[j]->GetName() );
1504cdf0e10cSrcweir 				delete [] ppSortArray;
1505cdf0e10cSrcweir 			}
1506cdf0e10cSrcweir 		}
1507cdf0e10cSrcweir 	}
1508cdf0e10cSrcweir 	SetText(aPosStr);
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir 
FillFunctions()1511cdf0e10cSrcweir void ScPosWnd::FillFunctions()
1512cdf0e10cSrcweir {
1513cdf0e10cSrcweir 	Clear();
1514cdf0e10cSrcweir 
1515cdf0e10cSrcweir 	String aFirstName;
1516cdf0e10cSrcweir 	const ScAppOptions& rOpt = SC_MOD()->GetAppOptions();
1517cdf0e10cSrcweir 	sal_uInt16 nMRUCount = rOpt.GetLRUFuncListCount();
1518cdf0e10cSrcweir 	const sal_uInt16* pMRUList = rOpt.GetLRUFuncList();
1519cdf0e10cSrcweir 	if (pMRUList)
1520cdf0e10cSrcweir 	{
1521cdf0e10cSrcweir 		const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
1522cdf0e10cSrcweir 		sal_uLong nListCount = pFuncList->GetCount();
1523cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<nMRUCount; i++)
1524cdf0e10cSrcweir 		{
1525cdf0e10cSrcweir 			sal_uInt16 nId = pMRUList[i];
1526cdf0e10cSrcweir 			for (sal_uLong j=0; j<nListCount; j++)
1527cdf0e10cSrcweir 			{
1528cdf0e10cSrcweir 				const ScFuncDesc* pDesc = pFuncList->GetFunction( j );
1529cdf0e10cSrcweir 				if ( pDesc->nFIndex == nId && pDesc->pFuncName )
1530cdf0e10cSrcweir 				{
1531cdf0e10cSrcweir 					InsertEntry( *pDesc->pFuncName );
1532cdf0e10cSrcweir 					if (!aFirstName.Len())
1533cdf0e10cSrcweir 						aFirstName = *pDesc->pFuncName;
1534cdf0e10cSrcweir 					break;	// nicht weitersuchen
1535cdf0e10cSrcweir 				}
1536cdf0e10cSrcweir 			}
1537cdf0e10cSrcweir 		}
1538cdf0e10cSrcweir 	}
1539cdf0e10cSrcweir 
1540cdf0e10cSrcweir 	//!	Eintrag "Andere..." fuer Funktions-Autopilot wieder aufnehmen,
1541cdf0e10cSrcweir 	//!	wenn der Funktions-Autopilot mit dem bisher eingegebenen Text arbeiten kann!
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir //	InsertEntry( ScGlobal::GetRscString(STR_FUNCTIONLIST_MORE) );
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 	SetText(aFirstName);
1546cdf0e10cSrcweir }
1547cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)1548cdf0e10cSrcweir void __EXPORT ScPosWnd::Notify( SfxBroadcaster&, const SfxHint& rHint )
1549cdf0e10cSrcweir {
1550cdf0e10cSrcweir 	if ( !bFormulaMode )
1551cdf0e10cSrcweir 	{
1552cdf0e10cSrcweir 		//	muss die Liste der Bereichsnamen updgedated werden?
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir 		if ( rHint.ISA(SfxSimpleHint) )
1555cdf0e10cSrcweir 		{
1556cdf0e10cSrcweir 			sal_uLong nHintId = ((SfxSimpleHint&)rHint).GetId();
1557cdf0e10cSrcweir 			if ( nHintId == SC_HINT_AREAS_CHANGED || nHintId == SC_HINT_NAVIGATOR_UPDATEALL)
1558cdf0e10cSrcweir 				FillRangeNames();
1559cdf0e10cSrcweir 		}
1560cdf0e10cSrcweir 		else if ( rHint.ISA(SfxEventHint) )
1561cdf0e10cSrcweir 		{
1562cdf0e10cSrcweir 			sal_uLong nEventId = ((SfxEventHint&)rHint).GetEventId();
1563cdf0e10cSrcweir 			if ( nEventId == SFX_EVENT_ACTIVATEDOC )
1564cdf0e10cSrcweir 				FillRangeNames();
1565cdf0e10cSrcweir 		}
1566cdf0e10cSrcweir 	}
1567cdf0e10cSrcweir }
1568cdf0e10cSrcweir 
HideTip()1569cdf0e10cSrcweir void ScPosWnd::HideTip()
1570cdf0e10cSrcweir {
1571cdf0e10cSrcweir     if ( nTipVisible )
1572cdf0e10cSrcweir     {
1573cdf0e10cSrcweir         Help::HideTip( nTipVisible );
1574cdf0e10cSrcweir         nTipVisible = 0;
1575cdf0e10cSrcweir     }
1576cdf0e10cSrcweir }
1577cdf0e10cSrcweir 
lcl_GetInputType(const String & rText)1578cdf0e10cSrcweir ScNameInputType lcl_GetInputType( const String& rText )
1579cdf0e10cSrcweir {
1580cdf0e10cSrcweir     ScNameInputType eRet = SC_NAME_INPUT_BAD_NAME;      // the more general error
1581cdf0e10cSrcweir 
1582cdf0e10cSrcweir     ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
1583cdf0e10cSrcweir     if ( pViewSh )
1584cdf0e10cSrcweir     {
1585cdf0e10cSrcweir         ScViewData* pViewData = pViewSh->GetViewData();
1586cdf0e10cSrcweir         ScDocument* pDoc = pViewData->GetDocument();
1587cdf0e10cSrcweir         SCTAB nTab = pViewData->GetTabNo();
1588cdf0e10cSrcweir         formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir         // test in same order as in SID_CURRENTCELL execute
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir         ScRange aRange;
1593cdf0e10cSrcweir         ScAddress aAddress;
1594cdf0e10cSrcweir         ScRangeUtil aRangeUtil;
1595cdf0e10cSrcweir         SCTAB nNameTab;
1596cdf0e10cSrcweir         sal_Int32 nNumeric;
1597cdf0e10cSrcweir 
1598cdf0e10cSrcweir         if ( aRange.Parse( rText, pDoc, eConv ) & SCA_VALID )
1599cdf0e10cSrcweir             eRet = SC_NAME_INPUT_NAMEDRANGE;
1600cdf0e10cSrcweir         else if ( aAddress.Parse( rText, pDoc, eConv ) & SCA_VALID )
1601cdf0e10cSrcweir             eRet = SC_NAME_INPUT_CELL;
1602cdf0e10cSrcweir         else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_NAMES, eConv ) )
1603cdf0e10cSrcweir             eRet = SC_NAME_INPUT_NAMEDRANGE;
1604cdf0e10cSrcweir         else if ( aRangeUtil.MakeRangeFromName( rText, pDoc, nTab, aRange, RUTL_DBASE, eConv ) )
1605cdf0e10cSrcweir             eRet = SC_NAME_INPUT_DATABASE;
1606cdf0e10cSrcweir         else if ( ByteString( rText, RTL_TEXTENCODING_ASCII_US ).IsNumericAscii() &&
1607cdf0e10cSrcweir                   ( nNumeric = rText.ToInt32() ) > 0 && nNumeric <= MAXROW+1 )
1608cdf0e10cSrcweir             eRet = SC_NAME_INPUT_ROW;
1609cdf0e10cSrcweir         else if ( pDoc->GetTable( rText, nNameTab ) )
1610cdf0e10cSrcweir             eRet = SC_NAME_INPUT_SHEET;
1611cdf0e10cSrcweir         else if ( ScRangeData::IsNameValid( rText, pDoc ) )     // nothing found, create new range?
1612cdf0e10cSrcweir         {
1613cdf0e10cSrcweir             if ( pViewData->GetSimpleArea( aRange ) == SC_MARK_SIMPLE )
1614cdf0e10cSrcweir                 eRet = SC_NAME_INPUT_DEFINE;
1615cdf0e10cSrcweir             else
1616cdf0e10cSrcweir                 eRet = SC_NAME_INPUT_BAD_SELECTION;
1617cdf0e10cSrcweir         }
1618cdf0e10cSrcweir         else
1619cdf0e10cSrcweir             eRet = SC_NAME_INPUT_BAD_NAME;
1620cdf0e10cSrcweir     }
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir     return eRet;
1623cdf0e10cSrcweir }
1624cdf0e10cSrcweir 
Modify()1625cdf0e10cSrcweir void ScPosWnd::Modify()
1626cdf0e10cSrcweir {
1627cdf0e10cSrcweir     ComboBox::Modify();
1628cdf0e10cSrcweir 
1629cdf0e10cSrcweir     HideTip();
1630cdf0e10cSrcweir 
1631cdf0e10cSrcweir     if ( !IsTravelSelect() && !bFormulaMode )
1632cdf0e10cSrcweir     {
1633cdf0e10cSrcweir         // determine the action that would be taken for the current input
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir         ScNameInputType eType = lcl_GetInputType( GetText() );      // uses current view
1636cdf0e10cSrcweir         sal_uInt16 nStrId = 0;
1637cdf0e10cSrcweir         switch ( eType )
1638cdf0e10cSrcweir         {
1639cdf0e10cSrcweir             case SC_NAME_INPUT_CELL:
1640cdf0e10cSrcweir                 nStrId = STR_NAME_INPUT_CELL;
1641cdf0e10cSrcweir                 break;
1642cdf0e10cSrcweir             case SC_NAME_INPUT_RANGE:
1643cdf0e10cSrcweir             case SC_NAME_INPUT_NAMEDRANGE:
1644cdf0e10cSrcweir                 nStrId = STR_NAME_INPUT_RANGE;      // named range or range reference
1645cdf0e10cSrcweir                 break;
1646cdf0e10cSrcweir             case SC_NAME_INPUT_DATABASE:
1647cdf0e10cSrcweir                 nStrId = STR_NAME_INPUT_DBRANGE;
1648cdf0e10cSrcweir                 break;
1649cdf0e10cSrcweir             case SC_NAME_INPUT_ROW:
1650cdf0e10cSrcweir                 nStrId = STR_NAME_INPUT_ROW;
1651cdf0e10cSrcweir                 break;
1652cdf0e10cSrcweir             case SC_NAME_INPUT_SHEET:
1653cdf0e10cSrcweir                 nStrId = STR_NAME_INPUT_SHEET;
1654cdf0e10cSrcweir                 break;
1655cdf0e10cSrcweir             case SC_NAME_INPUT_DEFINE:
1656cdf0e10cSrcweir                 nStrId = STR_NAME_INPUT_DEFINE;
1657cdf0e10cSrcweir                 break;
1658cdf0e10cSrcweir             default:
1659cdf0e10cSrcweir                 // other cases (error): no tip help
1660cdf0e10cSrcweir                 break;
1661cdf0e10cSrcweir         }
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir         if ( nStrId )
1664cdf0e10cSrcweir         {
1665cdf0e10cSrcweir             // show the help tip at the text cursor position
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir             Window* pWin = GetSubEdit();
1668cdf0e10cSrcweir             if (!pWin)
1669cdf0e10cSrcweir                 pWin = this;
1670cdf0e10cSrcweir             Point aPos;
1671cdf0e10cSrcweir             Cursor* pCur = pWin->GetCursor();
1672cdf0e10cSrcweir             if (pCur)
1673cdf0e10cSrcweir                 aPos = pWin->LogicToPixel( pCur->GetPos() );
1674cdf0e10cSrcweir             aPos = pWin->OutputToScreenPixel( aPos );
1675cdf0e10cSrcweir             Rectangle aRect( aPos, aPos );
1676cdf0e10cSrcweir 
1677cdf0e10cSrcweir             String aText = ScGlobal::GetRscString( nStrId );
1678cdf0e10cSrcweir             sal_uInt16 nAlign = QUICKHELP_LEFT|QUICKHELP_BOTTOM;
1679cdf0e10cSrcweir             nTipVisible = Help::ShowTip(pWin, aRect, aText, nAlign);
1680cdf0e10cSrcweir         }
1681cdf0e10cSrcweir     }
1682cdf0e10cSrcweir }
1683cdf0e10cSrcweir 
Select()1684cdf0e10cSrcweir void __EXPORT ScPosWnd::Select()
1685cdf0e10cSrcweir {
1686cdf0e10cSrcweir 	ComboBox::Select();		//	in VCL gibt GetText() erst danach den ausgewaehlten Eintrag
1687cdf0e10cSrcweir 
1688cdf0e10cSrcweir     HideTip();
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir 	if (!IsTravelSelect())
1691cdf0e10cSrcweir 		DoEnter();
1692cdf0e10cSrcweir }
1693cdf0e10cSrcweir 
DoEnter()1694cdf0e10cSrcweir void ScPosWnd::DoEnter()
1695cdf0e10cSrcweir {
1696cdf0e10cSrcweir 	String aText = GetText();
1697cdf0e10cSrcweir 	if ( aText.Len() )
1698cdf0e10cSrcweir 	{
1699cdf0e10cSrcweir 		if ( bFormulaMode )
1700cdf0e10cSrcweir 		{
1701cdf0e10cSrcweir 			ScModule* pScMod = SC_MOD();
1702cdf0e10cSrcweir 			if ( aText == ScGlobal::GetRscString(STR_FUNCTIONLIST_MORE) )
1703cdf0e10cSrcweir 			{
1704cdf0e10cSrcweir 				//	Funktions-Autopilot
1705cdf0e10cSrcweir 				//!	mit dem bisher eingegebenen Text weiterarbeiten !!!
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir 				//!	new method at ScModule to query if function autopilot is open
1708cdf0e10cSrcweir 				SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1709cdf0e10cSrcweir 				if ( pViewFrm && !pViewFrm->GetChildWindow( SID_OPENDLG_FUNCTION ) )
1710cdf0e10cSrcweir 					pViewFrm->GetDispatcher()->Execute( SID_OPENDLG_FUNCTION,
1711cdf0e10cSrcweir 											  SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD );
1712cdf0e10cSrcweir 			}
1713cdf0e10cSrcweir 			else
1714cdf0e10cSrcweir 			{
1715cdf0e10cSrcweir 				ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
1716cdf0e10cSrcweir 				ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
1717cdf0e10cSrcweir 				if (pHdl)
1718cdf0e10cSrcweir 					pHdl->InsertFunction( aText );
1719cdf0e10cSrcweir 			}
1720cdf0e10cSrcweir 		}
1721cdf0e10cSrcweir 		else
1722cdf0e10cSrcweir 		{
1723cdf0e10cSrcweir             // depending on the input, select something or create a new named range
1724cdf0e10cSrcweir 
1725cdf0e10cSrcweir             ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
1726cdf0e10cSrcweir             if ( pViewSh )
1727cdf0e10cSrcweir             {
1728cdf0e10cSrcweir                 ScNameInputType eType = lcl_GetInputType( aText );
1729cdf0e10cSrcweir                 if ( eType == SC_NAME_INPUT_BAD_NAME || eType == SC_NAME_INPUT_BAD_SELECTION )
1730cdf0e10cSrcweir                 {
1731cdf0e10cSrcweir                     sal_uInt16 nId = ( eType == SC_NAME_INPUT_BAD_NAME ) ? STR_NAME_ERROR_NAME : STR_NAME_ERROR_SELECTION;
1732cdf0e10cSrcweir                     pViewSh->ErrorMessage( nId );
1733cdf0e10cSrcweir                 }
1734cdf0e10cSrcweir                 else if ( eType == SC_NAME_INPUT_DEFINE )
1735cdf0e10cSrcweir                 {
1736cdf0e10cSrcweir                     ScViewData* pViewData = pViewSh->GetViewData();
1737cdf0e10cSrcweir                     ScDocShell* pDocShell = pViewData->GetDocShell();
1738cdf0e10cSrcweir                     ScDocument* pDoc = pDocShell->GetDocument();
1739cdf0e10cSrcweir                     ScRangeName* pNames = pDoc->GetRangeName();
1740cdf0e10cSrcweir                     ScRange aSelection;
1741cdf0e10cSrcweir                     sal_uInt16 nIndex = 0;
1742cdf0e10cSrcweir                     if ( pNames && !pNames->SearchName( aText, nIndex ) &&
1743cdf0e10cSrcweir                             (pViewData->GetSimpleArea( aSelection ) == SC_MARK_SIMPLE) )
1744cdf0e10cSrcweir                     {
1745cdf0e10cSrcweir                         ScRangeName aNewRanges( *pNames );
1746cdf0e10cSrcweir                         ScAddress aCursor( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() );
1747cdf0e10cSrcweir                         String aContent;
1748cdf0e10cSrcweir                         aSelection.Format( aContent, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
1749cdf0e10cSrcweir                         ScRangeData* pNew = new ScRangeData( pDoc, aText, aContent, aCursor );
1750cdf0e10cSrcweir                         if ( aNewRanges.Insert(pNew) )
1751cdf0e10cSrcweir                         {
1752cdf0e10cSrcweir                             ScDocFunc aFunc(*pDocShell);
1753cdf0e10cSrcweir                             aFunc.ModifyRangeNames( aNewRanges, sal_False );
1754cdf0e10cSrcweir                             pViewSh->UpdateInputHandler(sal_True);
1755cdf0e10cSrcweir                         }
1756cdf0e10cSrcweir                         else
1757cdf0e10cSrcweir                             delete pNew;        // shouldn't happen
1758cdf0e10cSrcweir                     }
1759cdf0e10cSrcweir                 }
1760cdf0e10cSrcweir                 else
1761cdf0e10cSrcweir                 {
1762cdf0e10cSrcweir                     // for all selection types, excecute the SID_CURRENTCELL slot
1763cdf0e10cSrcweir 
1764cdf0e10cSrcweir                     SfxStringItem aPosItem( SID_CURRENTCELL, aText );
1765cdf0e10cSrcweir                     SfxBoolItem aUnmarkItem( FN_PARAM_1, sal_True );        // remove existing selection
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir                     pViewSh->GetViewData()->GetDispatcher().Execute( SID_CURRENTCELL,
1768cdf0e10cSrcweir                                         SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD,
1769cdf0e10cSrcweir                                         &aPosItem, &aUnmarkItem, 0L );
1770cdf0e10cSrcweir                 }
1771cdf0e10cSrcweir             }
1772cdf0e10cSrcweir 		}
1773cdf0e10cSrcweir 	}
1774cdf0e10cSrcweir 	else
1775cdf0e10cSrcweir 		SetText( aPosStr );
1776cdf0e10cSrcweir 
1777cdf0e10cSrcweir 	ReleaseFocus_Impl();
1778cdf0e10cSrcweir }
1779cdf0e10cSrcweir 
Notify(NotifyEvent & rNEvt)1780cdf0e10cSrcweir long __EXPORT ScPosWnd::Notify( NotifyEvent& rNEvt )
1781cdf0e10cSrcweir {
1782cdf0e10cSrcweir 	long nHandled = 0;
1783cdf0e10cSrcweir 
1784cdf0e10cSrcweir 	if ( rNEvt.GetType() == EVENT_KEYINPUT )
1785cdf0e10cSrcweir 	{
1786cdf0e10cSrcweir 		const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1787cdf0e10cSrcweir 
1788cdf0e10cSrcweir 		switch ( pKEvt->GetKeyCode().GetCode() )
1789cdf0e10cSrcweir 		{
1790cdf0e10cSrcweir 			case KEY_RETURN:
1791cdf0e10cSrcweir 				DoEnter();
1792cdf0e10cSrcweir 				nHandled = 1;
1793cdf0e10cSrcweir 				break;
1794cdf0e10cSrcweir 
1795cdf0e10cSrcweir 			case KEY_ESCAPE:
1796cdf0e10cSrcweir                 if (nTipVisible)
1797cdf0e10cSrcweir                 {
1798cdf0e10cSrcweir                     // escape when the tip help is shown: only hide the tip
1799cdf0e10cSrcweir                     HideTip();
1800cdf0e10cSrcweir                 }
1801cdf0e10cSrcweir                 else
1802cdf0e10cSrcweir                 {
1803cdf0e10cSrcweir                     if (!bFormulaMode)
1804cdf0e10cSrcweir                         SetText( aPosStr );
1805cdf0e10cSrcweir                     ReleaseFocus_Impl();
1806cdf0e10cSrcweir                 }
1807cdf0e10cSrcweir 				nHandled = 1;
1808cdf0e10cSrcweir 				break;
1809cdf0e10cSrcweir 		}
1810cdf0e10cSrcweir 	}
1811cdf0e10cSrcweir 
1812cdf0e10cSrcweir 	if ( !nHandled )
1813cdf0e10cSrcweir 		nHandled = ComboBox::Notify( rNEvt );
1814cdf0e10cSrcweir 
1815cdf0e10cSrcweir     if ( rNEvt.GetType() == EVENT_LOSEFOCUS )
1816cdf0e10cSrcweir         HideTip();
1817cdf0e10cSrcweir 
1818cdf0e10cSrcweir 	return nHandled;
1819cdf0e10cSrcweir }
1820cdf0e10cSrcweir 
ReleaseFocus_Impl()1821cdf0e10cSrcweir void ScPosWnd::ReleaseFocus_Impl()
1822cdf0e10cSrcweir {
1823cdf0e10cSrcweir     HideTip();
1824cdf0e10cSrcweir 
1825cdf0e10cSrcweir 	SfxViewShell* pCurSh = SfxViewShell::Current();
1826cdf0e10cSrcweir 	ScInputHandler* pHdl = SC_MOD()->GetInputHdl( PTR_CAST( ScTabViewShell, pCurSh ) );
1827cdf0e10cSrcweir 	if ( pHdl && pHdl->IsTopMode() )
1828cdf0e10cSrcweir 	{
1829cdf0e10cSrcweir 		//	Focus wieder in die Eingabezeile?
1830cdf0e10cSrcweir 
1831cdf0e10cSrcweir 		ScInputWindow* pInputWin = pHdl->GetInputWindow();
1832cdf0e10cSrcweir 		if (pInputWin)
1833cdf0e10cSrcweir 		{
1834cdf0e10cSrcweir 			pInputWin->TextGrabFocus();
1835cdf0e10cSrcweir 			return;
1836cdf0e10cSrcweir 		}
1837cdf0e10cSrcweir 	}
1838cdf0e10cSrcweir 
1839cdf0e10cSrcweir 	//	Focus auf die aktive View
1840cdf0e10cSrcweir 
1841cdf0e10cSrcweir 	if ( pCurSh )
1842cdf0e10cSrcweir 	{
1843cdf0e10cSrcweir 		Window* pShellWnd = pCurSh->GetWindow();
1844cdf0e10cSrcweir 
1845cdf0e10cSrcweir 		if ( pShellWnd )
1846cdf0e10cSrcweir 			pShellWnd->GrabFocus();
1847cdf0e10cSrcweir 	}
1848cdf0e10cSrcweir }
1849cdf0e10cSrcweir 
1850cdf0e10cSrcweir 
1851cdf0e10cSrcweir 
1852cdf0e10cSrcweir 
1853cdf0e10cSrcweir 
1854cdf0e10cSrcweir 
1855