xref: /AOO41X/main/sw/source/ui/fldui/inpdlg.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #ifdef SW_DLLIMPLEMENTATION
32 #undef SW_DLLIMPLEMENTATION
33 #endif
34 
35 #include <vcl/msgbox.hxx>
36 #include <unotools/charclass.hxx>
37 #include <editeng/unolingu.hxx>
38 #include <wrtsh.hxx>
39 #include <fldbas.hxx>
40 #include <expfld.hxx>
41 #include <usrfld.hxx>
42 #include <inpdlg.hxx>
43 #include <fldmgr.hxx>
44 
45 #include <fldui.hrc>
46 #include <inpdlg.hrc>
47 
48 
49 /*--------------------------------------------------------------------
50 	Beschreibung: Feldeinfuegen bearbeiten
51  --------------------------------------------------------------------*/
52 
53 SwFldInputDlg::SwFldInputDlg( Window *pParent, SwWrtShell &rS,
54 							  SwField* pField, sal_Bool bNextButton ) :
55 
56 	SvxStandardDialog(pParent,	SW_RES(DLG_FLD_INPUT)),
57 
58 	rSh( rS ),
59     pInpFld(0),
60     pSetFld(0),
61     pUsrType(0),
62 
63     aLabelED    (this, SW_RES(ED_LABEL  )),
64 	aEditED		(this, SW_RES(ED_EDIT	)),
65     aEditFL     (this, SW_RES(FL_EDIT       )),
66 
67     aOKBT       (this, SW_RES(BT_OK     )),
68 	aCancelBT	(this, SW_RES(BT_CANCEL	)),
69 	aNextBT		(this, SW_RES(PB_NEXT	)),
70     aHelpBT     (this, SW_RES(PB_HELP    ))
71 {
72 	// Font fuers Edit umschalten
73 	Font aFont(aEditED.GetFont());
74 	aFont.SetWeight(WEIGHT_LIGHT);
75 	aEditED.SetFont(aFont);
76 
77 	if( bNextButton )
78 	{
79 		aNextBT.Show();
80 		aNextBT.SetClickHdl(LINK(this, SwFldInputDlg, NextHdl));
81 	}
82 	else
83 	{
84 		long nDiff = aCancelBT.GetPosPixel().Y() - aOKBT.GetPosPixel().Y();
85 		Point aPos = aHelpBT.GetPosPixel();
86 		aPos.Y() -= nDiff;
87 		aHelpBT.SetPosPixel(aPos);
88 	}
89 
90 	// Auswertung hier
91 	String aStr;
92 	if( RES_INPUTFLD == pField->GetTyp()->Which() )
93 	{	// Es ist eine Eingabefeld
94 		//
95 		pInpFld = (SwInputField*)pField;
96 		aLabelED.SetText( pInpFld->GetPar2() );
97 		sal_uInt16 nSubType = pInpFld->GetSubType();
98 
99 		switch(nSubType & 0xff)
100 		{
101 			case INP_TXT:
102 				aStr = pInpFld->GetPar1();
103 				break;
104 
105 			case INP_USR:
106 				// Benutzerfeld
107 				if( 0 != ( pUsrType = (SwUserFieldType*)rSh.GetFldType(
108 							RES_USERFLD, pInpFld->GetPar1() ) ) )
109 					aStr = pUsrType->GetContent();
110 				break;
111 		}
112 	}
113 	else
114 	{
115 		// es ist eine SetExpression
116 		pSetFld = (SwSetExpField*)pField;
117 		String sFormula(pSetFld->GetFormula());
118 		//values are formatted - formulas are not
119 		CharClass aCC( SvxCreateLocale( pSetFld->GetLanguage() ));
120 		if( aCC.isNumeric( sFormula ))
121         {
122             aStr = pSetFld->ExpandField(true);
123         }
124 		else
125 			aStr = sFormula;
126 		aLabelED.SetText( pSetFld->GetPromptText() );
127 	}
128 
129 	// JP 31.3.00: Inputfields in readonly regions must be allowed to
130 	//				input any content. - 74639
131 	sal_Bool bEnable = !rSh.IsCrsrReadonly();
132 					/*!rSh.IsReadOnlyAvailable() || !rSh.HasReadonlySel()*/;
133 	aOKBT.Enable( bEnable );
134 	aEditED.SetReadOnly( !bEnable );
135 
136 	if( aStr.Len() )
137 		aEditED.SetText( aStr.ConvertLineEnd() );
138 	FreeResource();
139 }
140 
141 SwFldInputDlg::~SwFldInputDlg()
142 {
143 }
144 
145 void SwFldInputDlg::StateChanged( StateChangedType nType )
146 {
147     if ( nType == STATE_CHANGE_INITSHOW )
148         aEditED.GrabFocus();
149     SvxStandardDialog::StateChanged( nType );
150 }
151 
152 /*--------------------------------------------------------------------
153 	 Beschreibung:	Schliessen
154  --------------------------------------------------------------------*/
155 
156 void SwFldInputDlg::Apply()
157 {
158 	String aTmp( aEditED.GetText() );
159 	aTmp.EraseAllChars( '\r' );
160 
161 	rSh.StartAllAction();
162 	sal_Bool bModified = sal_False;
163 	if(pInpFld)
164 	{
165 		if(pUsrType)
166 		{
167 			if( aTmp != pUsrType->GetContent() )
168 			{
169 				pUsrType->SetContent(aTmp);
170 				pUsrType->UpdateFlds();
171 				bModified = sal_True;
172 			}
173 		}
174 		else if( aTmp != pInpFld->GetPar1() )
175 		{
176 			pInpFld->SetPar1(aTmp);
177 			rSh.SwEditShell::UpdateFlds(*pInpFld);
178 			bModified = sal_True;
179 		}
180 	}
181 	else if( aTmp != pSetFld->GetPar2() )
182 	{
183 		pSetFld->SetPar2(aTmp);
184 		rSh.SwEditShell::UpdateFlds(*pSetFld);
185 		bModified = sal_True;
186 	}
187 
188 	if( bModified )
189 		rSh.SetUndoNoResetModified();
190 
191 	rSh.EndAllAction();
192 }
193 
194 
195 IMPL_LINK(SwFldInputDlg, NextHdl, PushButton*, EMPTYARG)
196 {
197 	EndDialog(RET_OK);
198 	return 0;
199 }
200 
201 
202