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