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