xref: /aoo41x/main/sw/source/ui/ribbar/inputwin.cxx (revision 4d7c9de0)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <tools/gen.hxx>
29cdf0e10cSrcweir #include <sfx2/imgmgr.hxx>
30cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
31cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
32cdf0e10cSrcweir #include <svx/ruler.hxx>
33cdf0e10cSrcweir #include <svl/zforlist.hxx>
34cdf0e10cSrcweir #include <svl/stritem.hxx>
35cdf0e10cSrcweir #include <unotools/undoopt.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "swtypes.hxx"
38cdf0e10cSrcweir #include "cmdid.h"
39cdf0e10cSrcweir #include "swmodule.hxx"
40cdf0e10cSrcweir #include "wrtsh.hxx"
41cdf0e10cSrcweir #include "view.hxx"
42cdf0e10cSrcweir #include "calc.hxx"
43cdf0e10cSrcweir #include "inputwin.hxx"
44cdf0e10cSrcweir #include "fldbas.hxx"
45cdf0e10cSrcweir #include "fldmgr.hxx"
46cdf0e10cSrcweir #include "frmfmt.hxx"
47cdf0e10cSrcweir #include "cellatr.hxx"
48cdf0e10cSrcweir #include "edtwin.hxx"
49cdf0e10cSrcweir #include "helpid.h"
50*ca62e2c2SSteve Yin #include "access.hrc"
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // nur fuers UpdateRange - Box in dem der gestackte Cursor sthet loeschen
53cdf0e10cSrcweir #include "pam.hxx"
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #include "swundo.hxx"
56cdf0e10cSrcweir #include "ribbar.hrc"
57cdf0e10cSrcweir #include "inputwin.hrc"
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include <IDocumentContentOperations.hxx>
60cdf0e10cSrcweir 
SFX_IMPL_POS_CHILDWINDOW(SwInputChild,FN_EDIT_FORMULA,SFX_OBJECTBAR_OBJECT)61cdf0e10cSrcweir SFX_IMPL_POS_CHILDWINDOW( SwInputChild, FN_EDIT_FORMULA, SFX_OBJECTBAR_OBJECT )
62cdf0e10cSrcweir 
63cdf0e10cSrcweir //==================================================================
64cdf0e10cSrcweir 
65cdf0e10cSrcweir SwInputWindow::SwInputWindow( Window* pParent, SfxBindings* pBind )
66cdf0e10cSrcweir 	: ToolBox( 	pParent ,	SW_RES( RID_TBX_FORMULA )),
67cdf0e10cSrcweir     aPos(       this,       SW_RES(ED_POS)),
68cdf0e10cSrcweir 	aEdit(      this, WB_3DLOOK|WB_TABSTOP|WB_BORDER|WB_NOHIDESELECTION),
69cdf0e10cSrcweir 	aPopMenu(	SW_RES(MN_CALC_POPUP)),
70cdf0e10cSrcweir 	pMgr(0),
71cdf0e10cSrcweir     pWrtShell(0),
72cdf0e10cSrcweir 	pView(0),
73cdf0e10cSrcweir     pBindings(pBind),
74cdf0e10cSrcweir 	aAktTableName(aEmptyStr)
75cdf0e10cSrcweir     , m_nActionCount(0)
76cdf0e10cSrcweir     , m_bDoesUndo(true)
77cdf0e10cSrcweir     , m_bResetUndo(false)
78cdf0e10cSrcweir     , m_bCallUndo(false)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir     bFirst = sal_True;
81cdf0e10cSrcweir     bActive = bIsTable = bDelSel = sal_False;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	FreeResource();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 	aEdit.SetSizePixel( aEdit.CalcMinimumSize() );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     SfxImageManager* pManager = SfxImageManager::GetImageManager( SW_MOD() );
88cdf0e10cSrcweir     pManager->RegisterToolBox(this);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	pView = ::GetActiveView();
91cdf0e10cSrcweir 	pWrtShell = pView ? pView->GetWrtShellPtr() : 0;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	InsertWindow( ED_POS, &aPos, 0, 0);
94*ca62e2c2SSteve Yin 	SetItemText(ED_POS, String(SW_RES(STR_ACCESS_FORMULA_TYPE)));
95*ca62e2c2SSteve Yin 	aPos.SetAccessibleName(String(SW_RES(STR_ACCESS_FORMULA_TYPE)));
96*ca62e2c2SSteve Yin 	SetAccessibleName(String(SW_RES(STR_ACCESS_FORMULA_TOOLBAR)));
97cdf0e10cSrcweir 	InsertSeparator ( 1 );
98cdf0e10cSrcweir 	InsertSeparator ();
99cdf0e10cSrcweir 	InsertWindow( ED_FORMULA, &aEdit);
100*ca62e2c2SSteve Yin 	SetItemText(ED_FORMULA, String(SW_RES(STR_ACCESS_FORMULA_TEXT)));
101*ca62e2c2SSteve Yin 	aEdit.SetAccessibleName(String(SW_RES(STR_ACCESS_FORMULA_TEXT)));
102cdf0e10cSrcweir 	SetHelpId(ED_FORMULA, HID_EDIT_FORMULA);
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
105cdf0e10cSrcweir     SetItemImage( FN_FORMULA_CALC, pManager->GetImage(FN_FORMULA_CALC, bHC ));
106cdf0e10cSrcweir 	SetItemImage( FN_FORMULA_CANCEL, pManager->GetImage(FN_FORMULA_CANCEL, bHC  ));
107cdf0e10cSrcweir 	SetItemImage( FN_FORMULA_APPLY, pManager->GetImage(FN_FORMULA_APPLY, bHC  ));
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     SetItemBits( FN_FORMULA_CALC, GetItemBits( FN_FORMULA_CALC ) | TIB_DROPDOWNONLY );
110cdf0e10cSrcweir     SetDropdownClickHdl( LINK( this, SwInputWindow, DropdownClickHdl ));
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	Size	aSizeTbx = CalcWindowSizePixel();
113cdf0e10cSrcweir 	Size 	aEditSize = aEdit.GetSizePixel();
114cdf0e10cSrcweir 	Rectangle aItemRect( GetItemRect(FN_FORMULA_CALC) );
115cdf0e10cSrcweir 	long nMaxHeight = (aEditSize.Height() > aItemRect.GetHeight()) ? aEditSize.Height() : aItemRect.GetHeight();
116cdf0e10cSrcweir 	if( nMaxHeight+2 > aSizeTbx.Height() )
117cdf0e10cSrcweir 	    aSizeTbx.Height() = nMaxHeight+2;
118cdf0e10cSrcweir 	Size aSize = GetSizePixel();
119cdf0e10cSrcweir 	aSize.Height() = aSizeTbx.Height();
120cdf0e10cSrcweir 	SetSizePixel( aSize );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	// align edit and item vcentered
123cdf0e10cSrcweir 	Size 	aPosSize = aPos.GetSizePixel();
124cdf0e10cSrcweir 	aPosSize.Height()  = nMaxHeight;
125cdf0e10cSrcweir 	aEditSize.Height() = nMaxHeight;
126cdf0e10cSrcweir 	Point aPosPos  = aPos.GetPosPixel();
127cdf0e10cSrcweir 	Point aEditPos = aEdit.GetPosPixel();
128cdf0e10cSrcweir 	aPosPos.Y()    = (aSize.Height() - nMaxHeight)/2 + 1;
129cdf0e10cSrcweir 	aEditPos.Y()   = (aSize.Height() - nMaxHeight)/2 + 1;
130cdf0e10cSrcweir 	aPos.SetPosSizePixel( aPosPos, aPosSize );
131cdf0e10cSrcweir 	aEdit.SetPosSizePixel( aEditPos, aEditSize );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	aPopMenu.SetSelectHdl(LINK( this, SwInputWindow, MenuHdl ));
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //==================================================================
137cdf0e10cSrcweir 
~SwInputWindow()138cdf0e10cSrcweir __EXPORT SwInputWindow::~SwInputWindow()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     SfxImageManager::GetImageManager( SW_MOD() )->ReleaseToolBox(this);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 	//Lineale aufwecken
143cdf0e10cSrcweir 	if(pView)
144cdf0e10cSrcweir 	{
145cdf0e10cSrcweir         pView->GetHLineal().SetActive( sal_True );
146cdf0e10cSrcweir         pView->GetVLineal().SetActive( sal_True );
147cdf0e10cSrcweir 	}
148cdf0e10cSrcweir 	if ( pMgr )
149cdf0e10cSrcweir 		delete pMgr;
150cdf0e10cSrcweir 	if(pWrtShell)
151cdf0e10cSrcweir 		pWrtShell->EndSelTblCells();
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     CleanupUglyHackWithUndo();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir 
CleanupUglyHackWithUndo()156cdf0e10cSrcweir void SwInputWindow::CleanupUglyHackWithUndo()
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     if (m_bResetUndo)
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir         DelBoxCntnt();
161cdf0e10cSrcweir         pWrtShell->DoUndo(m_bDoesUndo);
162cdf0e10cSrcweir         if (m_bCallUndo)
163cdf0e10cSrcweir         {
164cdf0e10cSrcweir             pWrtShell->Undo();
165cdf0e10cSrcweir         }
166cdf0e10cSrcweir         if (0 == m_nActionCount)
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             SW_MOD()->GetUndoOptions().SetUndoCount(0);
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir         m_bResetUndo = false; // #i117122# once is enough :)
171cdf0e10cSrcweir     }
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 
175cdf0e10cSrcweir //==================================================================
176cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)177cdf0e10cSrcweir void SwInputWindow::DataChanged( const DataChangedEvent& rDCEvt )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir     if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         //      update item images
182cdf0e10cSrcweir         SwModule *pMod  = SW_MOD();
183cdf0e10cSrcweir         SfxImageManager *pImgMgr = SfxImageManager::GetImageManager( pMod );
184cdf0e10cSrcweir         sal_Bool bHC = GetSettings().GetStyleSettings().GetHighContrastMode();
185cdf0e10cSrcweir         //
186cdf0e10cSrcweir         SetItemImage( FN_FORMULA_CALC,   pImgMgr->GetImage(FN_FORMULA_CALC,   bHC ));
187cdf0e10cSrcweir         SetItemImage( FN_FORMULA_CANCEL, pImgMgr->GetImage(FN_FORMULA_CANCEL, bHC ));
188cdf0e10cSrcweir         SetItemImage( FN_FORMULA_APPLY,  pImgMgr->GetImage(FN_FORMULA_APPLY,  bHC ));
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     ToolBox::DataChanged( rDCEvt );
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir //==================================================================
195cdf0e10cSrcweir 
Resize()196cdf0e10cSrcweir void __EXPORT SwInputWindow::Resize()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	ToolBox::Resize();
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 	long	nWidth		= GetSizePixel().Width();
201cdf0e10cSrcweir 	long	nLeft		= aEdit.GetPosPixel().X();
202cdf0e10cSrcweir 	Size	aEditSize	= aEdit.GetSizePixel();
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	aEditSize.Width() = Max( ((long)(nWidth - nLeft - 5)), (long)0 );
205cdf0e10cSrcweir 	aEdit.SetSizePixel( aEditSize );
206cdf0e10cSrcweir 	aEdit.Invalidate();
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //==================================================================
210cdf0e10cSrcweir 
ShowWin()211cdf0e10cSrcweir void SwInputWindow::ShowWin()
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	bIsTable = sal_False;
214cdf0e10cSrcweir 	//Lineale anhalten
215cdf0e10cSrcweir 	if(pView)
216cdf0e10cSrcweir 	{
217cdf0e10cSrcweir         pView->GetHLineal().SetActive( sal_False );
218cdf0e10cSrcweir         pView->GetVLineal().SetActive( sal_False );
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 		DBG_ASSERT(pWrtShell, "Keine WrtShell!");
221cdf0e10cSrcweir 		// Cursor in Tabelle
222cdf0e10cSrcweir 		bIsTable = pWrtShell->IsCrsrInTbl() ? sal_True : sal_False;
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 		if( bFirst )
225cdf0e10cSrcweir 			pWrtShell->SelTblCells( LINK( this, SwInputWindow,
226cdf0e10cSrcweir 												SelTblCellsNotify) );
227cdf0e10cSrcweir 		if( bIsTable )
228cdf0e10cSrcweir 		{
229cdf0e10cSrcweir 			const String& rPos = pWrtShell->GetBoxNms();
230cdf0e10cSrcweir 			sal_uInt16 nPos = 0;
231cdf0e10cSrcweir 			short nSrch = -1;
232cdf0e10cSrcweir 			while( (nPos = rPos.Search( ':',nPos + 1 ) ) != STRING_NOTFOUND )
233cdf0e10cSrcweir 				nSrch = (short) nPos;
234cdf0e10cSrcweir 			aPos.SetText( rPos.Copy( ++nSrch ) );
235cdf0e10cSrcweir 			aAktTableName = pWrtShell->GetTableFmt()->GetName();
236cdf0e10cSrcweir 		}
237cdf0e10cSrcweir 		else
238cdf0e10cSrcweir             aPos.SetText(SW_RESSTR(STR_TBL_FORMULA));
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 		// Aktuelles Feld bearbeiten
241cdf0e10cSrcweir 		ASSERT(pMgr == 0, FieldManager nicht geloescht.);
242cdf0e10cSrcweir 		pMgr = new SwFldMgr;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 		// JP 13.01.97: Formel soll immer mit einem "=" beginnen, hier
245cdf0e10cSrcweir 		//				also setzen
246cdf0e10cSrcweir 		String sEdit( '=' );
247cdf0e10cSrcweir 		if( pMgr->GetCurFld() && TYP_FORMELFLD == pMgr->GetCurTypeId() )
248cdf0e10cSrcweir 		{
249cdf0e10cSrcweir 			sEdit += pMgr->GetCurFldPar2();
250cdf0e10cSrcweir 		}
251cdf0e10cSrcweir 		else if( bFirst )
252cdf0e10cSrcweir 		{
253cdf0e10cSrcweir 			if( bIsTable )
254cdf0e10cSrcweir             {
255cdf0e10cSrcweir                 m_bResetUndo = true;
256cdf0e10cSrcweir                 m_nActionCount = SW_MOD()->GetUndoOptions().GetUndoCount();
257cdf0e10cSrcweir                 if (0 == m_nActionCount) { // deactivated? turn it on...
258cdf0e10cSrcweir                     SW_MOD()->GetUndoOptions().SetUndoCount(1);
259cdf0e10cSrcweir                 }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir                 m_bDoesUndo = pWrtShell->DoesUndo();
262cdf0e10cSrcweir                 if( !m_bDoesUndo )
263cdf0e10cSrcweir                 {
264cdf0e10cSrcweir                     pWrtShell->DoUndo( sal_True );
265cdf0e10cSrcweir                 }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 				if( !pWrtShell->SwCrsrShell::HasSelection() )
268cdf0e10cSrcweir 				{
269cdf0e10cSrcweir 					pWrtShell->MoveSection( fnSectionCurr, fnSectionStart );
270cdf0e10cSrcweir 					pWrtShell->SetMark();
271cdf0e10cSrcweir 					pWrtShell->MoveSection( fnSectionCurr, fnSectionEnd );
272cdf0e10cSrcweir 				}
273cdf0e10cSrcweir 				if( pWrtShell->SwCrsrShell::HasSelection() )
274cdf0e10cSrcweir 				{
275cdf0e10cSrcweir 					pWrtShell->StartUndo( UNDO_DELETE );
276cdf0e10cSrcweir 					pWrtShell->Delete();
277cdf0e10cSrcweir 					if( 0 != pWrtShell->EndUndo( UNDO_DELETE ))
278cdf0e10cSrcweir                     {
279cdf0e10cSrcweir                         m_bCallUndo = true;
280cdf0e10cSrcweir                     }
281cdf0e10cSrcweir                 }
282cdf0e10cSrcweir                 pWrtShell->DoUndo(false);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 				SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_BOXATR_FORMULA, RES_BOXATR_FORMULA );
285cdf0e10cSrcweir 				if( pWrtShell->GetTblBoxFormulaAttrs( aSet ))
286cdf0e10cSrcweir 					sEdit += ((SwTblBoxFormula&)aSet.Get( RES_BOXATR_FORMULA )).GetFormula();
287cdf0e10cSrcweir 			}
288cdf0e10cSrcweir 		}
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 		if( bFirst )
291cdf0e10cSrcweir 		{
292cdf0e10cSrcweir 			// WrtShell Flags richtig setzen
293cdf0e10cSrcweir 			pWrtShell->SttSelect();
294cdf0e10cSrcweir 			pWrtShell->EndSelect();
295cdf0e10cSrcweir 		}
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 		bFirst = sal_False;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 		aEdit.SetModifyHdl( LINK( this, SwInputWindow, ModifyHdl ));
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 		aEdit.SetText( sEdit );
302cdf0e10cSrcweir 		aEdit.SetSelection( Selection( sEdit.Len(), sEdit.Len() ) );
303cdf0e10cSrcweir 		sOldFml = sEdit;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 		aEdit.Invalidate();
306cdf0e10cSrcweir 		aEdit.Update();
307cdf0e10cSrcweir 		aEdit.GrabFocus();
308cdf0e10cSrcweir 		// UserInterface fuer die Eingabe abklemmen
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 		pView->GetEditWin().LockKeyInput(sal_True);
311cdf0e10cSrcweir 		pView->GetViewFrame()->GetDispatcher()->Lock(sal_True);
312cdf0e10cSrcweir 		pWrtShell->Push();
313cdf0e10cSrcweir 	}
314cdf0e10cSrcweir 	ToolBox::Show();
315cdf0e10cSrcweir }
316cdf0e10cSrcweir //==================================================================
317cdf0e10cSrcweir 
IMPL_LINK(SwInputWindow,MenuHdl,Menu *,pMenu)318cdf0e10cSrcweir IMPL_LINK( SwInputWindow, MenuHdl, Menu *, pMenu )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir static const char * __READONLY_DATA aStrArr[] = {
321cdf0e10cSrcweir 	sCalc_Phd,
322cdf0e10cSrcweir 	sCalc_Sqrt,
323cdf0e10cSrcweir 	sCalc_Or,
324cdf0e10cSrcweir 	sCalc_Xor,
325cdf0e10cSrcweir 	sCalc_And,
326cdf0e10cSrcweir 	sCalc_Not,
327cdf0e10cSrcweir 	sCalc_Eq,
328cdf0e10cSrcweir 	sCalc_Neq,
329cdf0e10cSrcweir 	sCalc_Leq,
330cdf0e10cSrcweir 	sCalc_Geq,
331cdf0e10cSrcweir 	sCalc_L,
332cdf0e10cSrcweir 	sCalc_G,
333cdf0e10cSrcweir 	sCalc_Sum,
334cdf0e10cSrcweir 	sCalc_Mean,
335cdf0e10cSrcweir 	sCalc_Min,
336cdf0e10cSrcweir 	sCalc_Max,
337cdf0e10cSrcweir 	sCalc_Sin,
338cdf0e10cSrcweir 	sCalc_Cos,
339cdf0e10cSrcweir 	sCalc_Tan,
340cdf0e10cSrcweir 	sCalc_Asin,
341cdf0e10cSrcweir 	sCalc_Acos,
342cdf0e10cSrcweir 	sCalc_Atan,
343cdf0e10cSrcweir 	sCalc_Pow,
344cdf0e10cSrcweir 	"|",
345cdf0e10cSrcweir 	sCalc_Round
346cdf0e10cSrcweir };
347cdf0e10cSrcweir 
348cdf0e10cSrcweir 	sal_uInt16 nId = pMenu->GetCurItemId();
349cdf0e10cSrcweir 	if ( nId <= MN_CALC_ROUND )
350cdf0e10cSrcweir 	{
351cdf0e10cSrcweir 		String aTmp( String::CreateFromAscii(aStrArr[nId - 1]) );
352cdf0e10cSrcweir 		aTmp += ' ';
353cdf0e10cSrcweir 		aEdit.ReplaceSelected( aTmp );
354cdf0e10cSrcweir 	}
355cdf0e10cSrcweir 	return 0;
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
IMPL_LINK(SwInputWindow,DropdownClickHdl,ToolBox *,EMPTYARG)358cdf0e10cSrcweir IMPL_LINK( SwInputWindow, DropdownClickHdl, ToolBox*, EMPTYARG )
359cdf0e10cSrcweir {
360cdf0e10cSrcweir 	sal_uInt16 nCurID = GetCurItemId();
361cdf0e10cSrcweir 	EndSelection();	// setzt CurItemId zurueck !
362cdf0e10cSrcweir 	switch ( nCurID )
363cdf0e10cSrcweir 	{
364cdf0e10cSrcweir 		case FN_FORMULA_CALC :
365cdf0e10cSrcweir 		{
366cdf0e10cSrcweir             aPopMenu.Execute( this, GetItemRect( FN_FORMULA_CALC ), POPUPMENU_NOMOUSEUPCLOSE );
367cdf0e10cSrcweir             break;
368cdf0e10cSrcweir         default:
369cdf0e10cSrcweir             break;
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir     }
372cdf0e10cSrcweir 
373cdf0e10cSrcweir     return sal_True;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir //==================================================================
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 
Click()379cdf0e10cSrcweir void __EXPORT SwInputWindow::Click( )
380cdf0e10cSrcweir {
381cdf0e10cSrcweir 	sal_uInt16 nCurID = GetCurItemId();
382cdf0e10cSrcweir 	EndSelection();	// setzt CurItemId zurueck !
383cdf0e10cSrcweir 	switch ( nCurID )
384cdf0e10cSrcweir 	{
385cdf0e10cSrcweir 		case FN_FORMULA_CANCEL:
386cdf0e10cSrcweir 		{
387cdf0e10cSrcweir 			CancelFormula();
388cdf0e10cSrcweir 		}
389cdf0e10cSrcweir 		break;
390cdf0e10cSrcweir 		case FN_FORMULA_APPLY:
391cdf0e10cSrcweir 		{
392cdf0e10cSrcweir 			ApplyFormula();
393cdf0e10cSrcweir 		}
394cdf0e10cSrcweir 		break;
395cdf0e10cSrcweir    }
396cdf0e10cSrcweir }
397cdf0e10cSrcweir 
398cdf0e10cSrcweir //==================================================================
399cdf0e10cSrcweir 
ApplyFormula()400cdf0e10cSrcweir void  SwInputWindow::ApplyFormula()
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 	pView->GetViewFrame()->GetDispatcher()->Lock(sal_False);
403cdf0e10cSrcweir 	pView->GetEditWin().LockKeyInput(sal_False);
404cdf0e10cSrcweir     CleanupUglyHackWithUndo();
405cdf0e10cSrcweir 	pWrtShell->Pop( sal_False );
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 	// JP 13.01.97: Formel soll immer mit einem "=" beginnen, hier
408cdf0e10cSrcweir 	//				also wieder entfernen
409cdf0e10cSrcweir 	String sEdit( aEdit.GetText() );
410cdf0e10cSrcweir 	sEdit.EraseLeadingChars().EraseTrailingChars();
411cdf0e10cSrcweir 	if( sEdit.Len() && '=' == sEdit.GetChar( 0 ) )
412cdf0e10cSrcweir 		sEdit.Erase( 0, 1 );
413cdf0e10cSrcweir     SfxStringItem aParam(FN_EDIT_FORMULA, sEdit);
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 	pWrtShell->EndSelTblCells();
416cdf0e10cSrcweir 	pView->GetEditWin().GrabFocus();
417cdf0e10cSrcweir     const SfxPoolItem* aArgs[2];
418cdf0e10cSrcweir     aArgs[0] = &aParam;
419cdf0e10cSrcweir     aArgs[1] = 0;
420cdf0e10cSrcweir     pView->GetViewFrame()->GetBindings().Execute( FN_EDIT_FORMULA, aArgs, 0, SFX_CALLMODE_ASYNCHRON );
421cdf0e10cSrcweir }
422cdf0e10cSrcweir 
423cdf0e10cSrcweir //==================================================================
424cdf0e10cSrcweir 
CancelFormula()425cdf0e10cSrcweir void  SwInputWindow::CancelFormula()
426cdf0e10cSrcweir {
427cdf0e10cSrcweir 	if(pView)
428cdf0e10cSrcweir 	{
429cdf0e10cSrcweir 		pView->GetViewFrame()->GetDispatcher()->Lock( sal_False );
430cdf0e10cSrcweir 		pView->GetEditWin().LockKeyInput(sal_False);
431cdf0e10cSrcweir         CleanupUglyHackWithUndo();
432cdf0e10cSrcweir 		pWrtShell->Pop( sal_False );
433cdf0e10cSrcweir 
434cdf0e10cSrcweir 		if( bDelSel )
435cdf0e10cSrcweir 			pWrtShell->EnterStdMode();
436cdf0e10cSrcweir 
437cdf0e10cSrcweir 		pWrtShell->EndSelTblCells();
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 		pView->GetEditWin().GrabFocus();
440cdf0e10cSrcweir 	}
441cdf0e10cSrcweir 	pView->GetViewFrame()->GetDispatcher()->Execute( FN_EDIT_FORMULA, SFX_CALLMODE_ASYNCHRON);
442cdf0e10cSrcweir }
443cdf0e10cSrcweir //==================================================================
444cdf0e10cSrcweir 
445cdf0e10cSrcweir const xub_Unicode CH_LRE = 0x202a;
446cdf0e10cSrcweir const xub_Unicode CH_PDF = 0x202c;
447cdf0e10cSrcweir 
IMPL_LINK(SwInputWindow,SelTblCellsNotify,SwWrtShell *,pCaller)448cdf0e10cSrcweir IMPL_LINK( SwInputWindow, SelTblCellsNotify, SwWrtShell *, pCaller )
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	if(bIsTable)
451cdf0e10cSrcweir 	{
452cdf0e10cSrcweir 		SwFrmFmt* pTblFmt = pCaller->GetTableFmt();
453cdf0e10cSrcweir 		String sBoxNms( pCaller->GetBoxNms() );
454cdf0e10cSrcweir 		String sTblNm;
455cdf0e10cSrcweir 		if( pTblFmt && aAktTableName != pTblFmt->GetName() )
456cdf0e10cSrcweir 			sTblNm = pTblFmt->GetName();
457cdf0e10cSrcweir 
458cdf0e10cSrcweir 		aEdit.UpdateRange( sBoxNms, sTblNm );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 		String sNew;
461cdf0e10cSrcweir         sNew += CH_LRE;
462cdf0e10cSrcweir         sNew += aEdit.GetText();
463cdf0e10cSrcweir         sNew += CH_PDF;
464cdf0e10cSrcweir 
465cdf0e10cSrcweir         if( sNew != sOldFml )
466cdf0e10cSrcweir 		{
467cdf0e10cSrcweir 			// Die WrtShell ist in der Tabellen Selektion
468cdf0e10cSrcweir 			// dann die Tabellen Selektion wieder aufheben, sonst steht der
469cdf0e10cSrcweir 			// Cursor "im Wald" und das LiveUpdate funktioniert nicht!
470cdf0e10cSrcweir 			pWrtShell->StartAllAction();
471cdf0e10cSrcweir 
472cdf0e10cSrcweir 			SwPaM aPam( *pWrtShell->GetStkCrsr()->GetPoint() );
473cdf0e10cSrcweir 			aPam.Move( fnMoveBackward, fnGoSection );
474cdf0e10cSrcweir 			aPam.SetMark();
475cdf0e10cSrcweir 			aPam.Move( fnMoveForward, fnGoSection );
476cdf0e10cSrcweir 
477cdf0e10cSrcweir             IDocumentContentOperations* pIDCO = pWrtShell->getIDocumentContentOperations();
478cdf0e10cSrcweir             pIDCO->DeleteRange( aPam );
479cdf0e10cSrcweir             pIDCO->InsertString( aPam, sNew );
480cdf0e10cSrcweir 			pWrtShell->EndAllAction();
481cdf0e10cSrcweir 			sOldFml = sNew;
482cdf0e10cSrcweir 		}
483cdf0e10cSrcweir 	}
484cdf0e10cSrcweir 	else
485cdf0e10cSrcweir 		aEdit.GrabFocus();
486cdf0e10cSrcweir 	return 0;
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 
SetFormula(const String & rFormula,sal_Bool bDelFlag)490cdf0e10cSrcweir void SwInputWindow::SetFormula( const String& rFormula, sal_Bool bDelFlag )
491cdf0e10cSrcweir {
492cdf0e10cSrcweir 	String sEdit( '=' );
493cdf0e10cSrcweir 	if( rFormula.Len() )
494cdf0e10cSrcweir 	{
495cdf0e10cSrcweir 		if( '=' == rFormula.GetChar( 0 ) )
496cdf0e10cSrcweir 			sEdit = rFormula;
497cdf0e10cSrcweir 		else
498cdf0e10cSrcweir 			sEdit += rFormula;
499cdf0e10cSrcweir 	}
500cdf0e10cSrcweir 	aEdit.SetText( sEdit );
501cdf0e10cSrcweir 	aEdit.SetSelection( Selection( sEdit.Len(), sEdit.Len() ) );
502cdf0e10cSrcweir 	aEdit.Invalidate();
503cdf0e10cSrcweir 	bDelSel = bDelFlag;
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
IMPL_LINK(SwInputWindow,ModifyHdl,InputEdit *,EMPTYARG)506cdf0e10cSrcweir IMPL_LINK( SwInputWindow, ModifyHdl, InputEdit*, EMPTYARG )
507cdf0e10cSrcweir {
508cdf0e10cSrcweir     if (bIsTable && m_bResetUndo)
509cdf0e10cSrcweir 	{
510cdf0e10cSrcweir 		pWrtShell->StartAllAction();
511cdf0e10cSrcweir 		DelBoxCntnt();
512cdf0e10cSrcweir 		String sNew;
513cdf0e10cSrcweir         sNew += CH_LRE;
514cdf0e10cSrcweir         sNew += aEdit.GetText();
515cdf0e10cSrcweir         sNew += CH_PDF;
516cdf0e10cSrcweir         pWrtShell->SwEditShell::Insert2( sNew );
517cdf0e10cSrcweir 		pWrtShell->EndAllAction();
518cdf0e10cSrcweir 		sOldFml = sNew;
519cdf0e10cSrcweir 	}
520cdf0e10cSrcweir 	return 0;
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir 
DelBoxCntnt()524cdf0e10cSrcweir void SwInputWindow::DelBoxCntnt()
525cdf0e10cSrcweir {
526cdf0e10cSrcweir 	if( bIsTable )
527cdf0e10cSrcweir 	{
528cdf0e10cSrcweir 		pWrtShell->StartAllAction();
529cdf0e10cSrcweir 		pWrtShell->ClearMark();
530cdf0e10cSrcweir 		pWrtShell->Pop( sal_False );
531cdf0e10cSrcweir 		pWrtShell->Push();
532cdf0e10cSrcweir 		pWrtShell->MoveSection( fnSectionCurr, fnSectionStart );
533cdf0e10cSrcweir 		pWrtShell->SetMark();
534cdf0e10cSrcweir 		pWrtShell->MoveSection( fnSectionCurr, fnSectionEnd );
535cdf0e10cSrcweir 		pWrtShell->SwEditShell::Delete();
536cdf0e10cSrcweir 		pWrtShell->EndAllAction();
537cdf0e10cSrcweir 	}
538cdf0e10cSrcweir }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir //==================================================================
541cdf0e10cSrcweir 
KeyInput(const KeyEvent & rEvent)542cdf0e10cSrcweir void __EXPORT InputEdit::KeyInput(const KeyEvent& rEvent)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir 	const KeyCode aCode = rEvent.GetKeyCode();
545cdf0e10cSrcweir 	if(aCode == KEY_RETURN || aCode == KEY_F2 )
546cdf0e10cSrcweir 		((SwInputWindow*)GetParent())->ApplyFormula();
547cdf0e10cSrcweir 	else if(aCode == KEY_ESCAPE )
548cdf0e10cSrcweir 		((SwInputWindow*)GetParent())->CancelFormula();
549cdf0e10cSrcweir 	else
550cdf0e10cSrcweir 		Edit::KeyInput(rEvent);
551cdf0e10cSrcweir }
552cdf0e10cSrcweir 
553cdf0e10cSrcweir //==================================================================
554cdf0e10cSrcweir 
UpdateRange(const String & rBoxes,const String & rName)555cdf0e10cSrcweir void __EXPORT InputEdit::UpdateRange(const String& rBoxes,
556cdf0e10cSrcweir 									const String& rName )
557cdf0e10cSrcweir {
558cdf0e10cSrcweir 	if( !rBoxes.Len() )
559cdf0e10cSrcweir 	{
560cdf0e10cSrcweir 		GrabFocus();
561cdf0e10cSrcweir 		return;
562cdf0e10cSrcweir 	}
563cdf0e10cSrcweir 	const sal_Unicode	cOpen = '<', cClose = '>',
564cdf0e10cSrcweir                 cOpenBracket = '(';
565cdf0e10cSrcweir 	String aPrefix = rName;
566cdf0e10cSrcweir 	if(rName.Len())
567cdf0e10cSrcweir 		aPrefix += '.';
568cdf0e10cSrcweir 	String aBoxes = aPrefix;
569cdf0e10cSrcweir 	aBoxes += rBoxes;
570cdf0e10cSrcweir 	Selection aSelection(GetSelection());
571cdf0e10cSrcweir 	sal_uInt16 nSel = (sal_uInt16) aSelection.Len();
572cdf0e10cSrcweir 	//OS: mit dem folgenden Ausdruck wird sichergestellt, dass im overwrite-Modus
573cdf0e10cSrcweir 	//die selektierte schliessende Klammer nicht geloescht wird
574cdf0e10cSrcweir 	if( nSel && ( nSel > 1 ||
575cdf0e10cSrcweir 		GetText().GetChar( (sal_uInt16)aSelection.Min() ) != cClose ) )
576cdf0e10cSrcweir 		Cut();
577cdf0e10cSrcweir 	else
578cdf0e10cSrcweir 		aSelection.Max() = aSelection.Min();
579cdf0e10cSrcweir 	String aActText(GetText());
580cdf0e10cSrcweir 	const sal_uInt16 nLen = aActText.Len();
581cdf0e10cSrcweir 	if( !nLen )
582cdf0e10cSrcweir 	{
583cdf0e10cSrcweir 		String aStr(cOpen);
584cdf0e10cSrcweir 		aStr += aBoxes;
585cdf0e10cSrcweir 		aStr += cClose;
586cdf0e10cSrcweir 		SetText(aStr);
587cdf0e10cSrcweir 		sal_uInt16 nPos = aStr.Search( cClose );
588cdf0e10cSrcweir 		ASSERT(nPos < aStr.Len(), Delimiter nicht gefunden.);
589cdf0e10cSrcweir 		++nPos;
590cdf0e10cSrcweir 		SetSelection( Selection( nPos, nPos ));
591cdf0e10cSrcweir 	}
592cdf0e10cSrcweir 	else
593cdf0e10cSrcweir 	{
594cdf0e10cSrcweir 		sal_Bool bFound = sal_False;
595cdf0e10cSrcweir 		sal_Unicode cCh;
596cdf0e10cSrcweir         sal_uInt16 nPos, nEndPos = 0, nStartPos = (sal_uInt16) aSelection.Min();
597cdf0e10cSrcweir 		if( nStartPos-- )
598cdf0e10cSrcweir 		{
599cdf0e10cSrcweir 			do {
600cdf0e10cSrcweir 				if( cOpen  == (cCh = aActText.GetChar( nStartPos ) ) ||
601cdf0e10cSrcweir 					cOpenBracket == cCh )
602cdf0e10cSrcweir 				{
603cdf0e10cSrcweir 					bFound = cCh == cOpen;
604cdf0e10cSrcweir 					break;
605cdf0e10cSrcweir 				}
606cdf0e10cSrcweir 			} while( nStartPos-- > 0 );
607cdf0e10cSrcweir 		}
608cdf0e10cSrcweir 		if( bFound )
609cdf0e10cSrcweir 		{
610cdf0e10cSrcweir 			bFound = sal_False;
611cdf0e10cSrcweir 			nEndPos = nStartPos;
612cdf0e10cSrcweir 			while( nEndPos < nLen )
613cdf0e10cSrcweir 			{
614cdf0e10cSrcweir 				if( cClose == (cCh = aActText.GetChar( nEndPos )) /*||
615cdf0e10cSrcweir 					cCh == cCloseBracket*/ )
616cdf0e10cSrcweir 				{
617cdf0e10cSrcweir 					bFound = sal_True;
618cdf0e10cSrcweir 					break;
619cdf0e10cSrcweir 				}
620cdf0e10cSrcweir 				++nEndPos;
621cdf0e10cSrcweir 			}
622cdf0e10cSrcweir 			// nur wenn akt. Pos im Breich oder direkt dahinter liegt
623cdf0e10cSrcweir 			if( bFound && !( nStartPos < (sal_uInt16)aSelection.Max() &&
624cdf0e10cSrcweir 							 (sal_uInt16)aSelection.Max() <= nEndPos + 1 ))
625cdf0e10cSrcweir 				bFound = sal_False;
626cdf0e10cSrcweir 		}
627cdf0e10cSrcweir 		if( bFound )
628cdf0e10cSrcweir 		{
629cdf0e10cSrcweir 			nPos = ++nStartPos + 1; // wir wollen dahinter
630cdf0e10cSrcweir 			aActText.Erase( nStartPos, nEndPos - nStartPos );
631cdf0e10cSrcweir 			aActText.Insert( aBoxes, nStartPos );
632cdf0e10cSrcweir             nPos = nPos + aBoxes.Len();
633cdf0e10cSrcweir 		}
634cdf0e10cSrcweir 		else
635cdf0e10cSrcweir 		{
636cdf0e10cSrcweir 			String aTmp( (char)cOpen );
637cdf0e10cSrcweir 			aTmp += aBoxes;
638cdf0e10cSrcweir 			aTmp += (char)cClose;
639cdf0e10cSrcweir 			nPos = (sal_uInt16)aSelection.Min();
640cdf0e10cSrcweir 			aActText.Insert( aTmp, nPos );
641cdf0e10cSrcweir             nPos = nPos + aTmp.Len();
642cdf0e10cSrcweir 		}
643cdf0e10cSrcweir 		if( GetText() != aActText )
644cdf0e10cSrcweir 		{
645cdf0e10cSrcweir 			SetText( aActText );
646cdf0e10cSrcweir 			SetSelection( Selection( nPos, nPos ) );
647cdf0e10cSrcweir //			GetModifyHdl().Call( this );
648cdf0e10cSrcweir 		}
649cdf0e10cSrcweir 	}
650cdf0e10cSrcweir 	GrabFocus();
651cdf0e10cSrcweir 
652cdf0e10cSrcweir }
653cdf0e10cSrcweir //==================================================================
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 
SwInputChild(Window * _pParent,sal_uInt16 nId,SfxBindings * pBindings,SfxChildWinInfo *)656cdf0e10cSrcweir SwInputChild::SwInputChild(Window* _pParent,
657cdf0e10cSrcweir 								sal_uInt16 nId,
658cdf0e10cSrcweir                                 SfxBindings* pBindings,
659cdf0e10cSrcweir 								SfxChildWinInfo* ) :
660cdf0e10cSrcweir                                 SfxChildWindow( _pParent, nId )
661cdf0e10cSrcweir {
662cdf0e10cSrcweir     pDispatch = pBindings->GetDispatcher();
663cdf0e10cSrcweir     pWindow = new SwInputWindow( _pParent, pBindings );
664cdf0e10cSrcweir 	((SwInputWindow*)pWindow)->ShowWin();
665cdf0e10cSrcweir 	eChildAlignment = SFX_ALIGN_LOWESTTOP;
666cdf0e10cSrcweir }
667cdf0e10cSrcweir 
668cdf0e10cSrcweir 
~SwInputChild()669cdf0e10cSrcweir __EXPORT SwInputChild::~SwInputChild()
670cdf0e10cSrcweir {
671cdf0e10cSrcweir 	if(pDispatch)
672cdf0e10cSrcweir 		pDispatch->Lock(sal_False);
673cdf0e10cSrcweir }
674cdf0e10cSrcweir 
675cdf0e10cSrcweir 
GetInfo() const676cdf0e10cSrcweir SfxChildWinInfo __EXPORT SwInputChild::GetInfo() const
677cdf0e10cSrcweir {
678cdf0e10cSrcweir 	SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();	   \
679cdf0e10cSrcweir 	return aInfo;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir 
682