xref: /aoo41x/main/sw/source/ui/fldui/inpdlg.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 #include <vcl/msgbox.hxx>
32 #include <unotools/charclass.hxx>
33 #include <editeng/unolingu.hxx>
34 #include <wrtsh.hxx>
35 #include <fldbas.hxx>
36 #include <expfld.hxx>
37 #include <usrfld.hxx>
38 #include <inpdlg.hxx>
39 #include <fldmgr.hxx>
40 
41 #include <fldui.hrc>
42 #include <inpdlg.hrc>
43 
44 
45 /*--------------------------------------------------------------------
46 	Beschreibung: Feldeinfuegen bearbeiten
47  --------------------------------------------------------------------*/
48 
SwFldInputDlg(Window * pParent,SwWrtShell & rS,SwField * pField,sal_Bool bNextButton)49 SwFldInputDlg::SwFldInputDlg( Window *pParent, SwWrtShell &rS,
50 							  SwField* pField, sal_Bool bNextButton ) :
51 
52 	SvxStandardDialog(pParent,	SW_RES(DLG_FLD_INPUT)),
53 
54 	rSh( rS ),
55     pInpFld(0),
56     pSetFld(0),
57     pUsrType(0),
58 
59     aLabelED    (this, SW_RES(ED_LABEL  )),
60 	aEditED		(this, SW_RES(ED_EDIT	)),
61     aEditFL     (this, SW_RES(FL_EDIT       )),
62 
63     aOKBT       (this, SW_RES(BT_OK     )),
64 	aCancelBT	(this, SW_RES(BT_CANCEL	)),
65 	aNextBT		(this, SW_RES(PB_NEXT	)),
66     aHelpBT     (this, SW_RES(PB_HELP    ))
67 {
68 	// Font fuers Edit umschalten
69 	Font aFont(aEditED.GetFont());
70 	aFont.SetWeight(WEIGHT_LIGHT);
71 	aEditED.SetFont(aFont);
72 
73 	if( bNextButton )
74 	{
75 		aNextBT.Show();
76 		aNextBT.SetClickHdl(LINK(this, SwFldInputDlg, NextHdl));
77 	}
78 	else
79 	{
80 		long nDiff = aCancelBT.GetPosPixel().Y() - aOKBT.GetPosPixel().Y();
81 		Point aPos = aHelpBT.GetPosPixel();
82 		aPos.Y() -= nDiff;
83 		aHelpBT.SetPosPixel(aPos);
84 	}
85 
86 	// Auswertung hier
87 	String aStr;
88 	if( RES_INPUTFLD == pField->GetTyp()->Which() )
89 	{	// Es ist eine Eingabefeld
90 		//
91 		pInpFld = (SwInputField*)pField;
92 		aLabelED.SetText( pInpFld->GetPar2() );
93 		sal_uInt16 nSubType = pInpFld->GetSubType();
94 
95 		switch(nSubType & 0xff)
96 		{
97 			case INP_TXT:
98 				aStr = pInpFld->GetPar1();
99 				break;
100 
101 			case INP_USR:
102 				// Benutzerfeld
103 				if( 0 != ( pUsrType = (SwUserFieldType*)rSh.GetFldType(
104 							RES_USERFLD, pInpFld->GetPar1() ) ) )
105 					aStr = pUsrType->GetContent();
106 				break;
107 		}
108 	}
109 	else
110 	{
111 		// es ist eine SetExpression
112 		pSetFld = (SwSetExpField*)pField;
113 		String sFormula(pSetFld->GetFormula());
114 		//values are formatted - formulas are not
115 		CharClass aCC( SvxCreateLocale( pSetFld->GetLanguage() ));
116 		if( aCC.isNumeric( sFormula ))
117         {
118             aStr = pSetFld->ExpandField(true);
119         }
120 		else
121 			aStr = sFormula;
122 		aLabelED.SetText( pSetFld->GetPromptText() );
123 	}
124 
125 	// JP 31.3.00: Inputfields in readonly regions must be allowed to
126 	//				input any content. - 74639
127 	sal_Bool bEnable = !rSh.IsCrsrReadonly();
128 					/*!rSh.IsReadOnlyAvailable() || !rSh.HasReadonlySel()*/;
129 	aOKBT.Enable( bEnable );
130 	aEditED.SetReadOnly( !bEnable );
131 
132 	if( aStr.Len() )
133 		aEditED.SetText( aStr.ConvertLineEnd() );
134 	FreeResource();
135 }
136 
~SwFldInputDlg()137 SwFldInputDlg::~SwFldInputDlg()
138 {
139 }
140 
StateChanged(StateChangedType nType)141 void SwFldInputDlg::StateChanged( StateChangedType nType )
142 {
143     if ( nType == STATE_CHANGE_INITSHOW )
144         aEditED.GrabFocus();
145     SvxStandardDialog::StateChanged( nType );
146 }
147 
148 /*--------------------------------------------------------------------
149 	 Beschreibung:	Schliessen
150  --------------------------------------------------------------------*/
151 
Apply()152 void SwFldInputDlg::Apply()
153 {
154 	String aTmp( aEditED.GetText() );
155 	aTmp.EraseAllChars( '\r' );
156 
157 	rSh.StartAllAction();
158 	sal_Bool bModified = sal_False;
159 	if(pInpFld)
160 	{
161 		if(pUsrType)
162 		{
163 			if( aTmp != pUsrType->GetContent() )
164 			{
165 				pUsrType->SetContent(aTmp);
166 				pUsrType->UpdateFlds();
167 				bModified = sal_True;
168 			}
169 		}
170 		else if( aTmp != pInpFld->GetPar1() )
171 		{
172 			pInpFld->SetPar1(aTmp);
173 			rSh.SwEditShell::UpdateFlds(*pInpFld);
174 			bModified = sal_True;
175 		}
176 	}
177 	else if( aTmp != pSetFld->GetPar2() )
178 	{
179 		pSetFld->SetPar2(aTmp);
180 		rSh.SwEditShell::UpdateFlds(*pSetFld);
181 		bModified = sal_True;
182 	}
183 
184 	if( bModified )
185 		rSh.SetUndoNoResetModified();
186 
187 	rSh.EndAllAction();
188 }
189 
190 
IMPL_LINK(SwFldInputDlg,NextHdl,PushButton *,EMPTYARG)191 IMPL_LINK(SwFldInputDlg, NextHdl, PushButton*, EMPTYARG)
192 {
193 	EndDialog(RET_OK);
194 	return 0;
195 }
196 
197 
198