update dev300-m58
[ooovba.git] / sw / source / ui / fldui / inpdlg.cxx
blob949cb9c2075f7c6584b35e1b38bb47bdafd976a7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: inpdlg.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
40 #define _INPDLG_CXX
42 #ifndef _MSGBOX_HXX //autogen
43 #include <vcl/msgbox.hxx>
44 #endif
45 #include <unotools/charclass.hxx>
46 #include <svx/unolingu.hxx>
47 #include <wrtsh.hxx>
48 #include <fldbas.hxx>
49 #include <expfld.hxx>
50 #include <usrfld.hxx>
51 #include <inpdlg.hxx>
52 #include <fldmgr.hxx>
54 #ifndef _FLDUI_HRC
55 #include <fldui.hrc>
56 #endif
57 #ifndef _INPDLG_HRC
58 #include <inpdlg.hrc>
59 #endif
62 /*--------------------------------------------------------------------
63 Beschreibung: Feldeinfuegen bearbeiten
64 --------------------------------------------------------------------*/
66 SwFldInputDlg::SwFldInputDlg( Window *pParent, SwWrtShell &rS,
67 SwField* pField, BOOL bNextButton ) :
69 SvxStandardDialog(pParent, SW_RES(DLG_FLD_INPUT)),
71 rSh( rS ),
72 pInpFld(0),
73 pSetFld(0),
74 pUsrType(0),
76 aLabelED (this, SW_RES(ED_LABEL )),
77 aEditED (this, SW_RES(ED_EDIT )),
78 aEditFL (this, SW_RES(FL_EDIT )),
80 aOKBT (this, SW_RES(BT_OK )),
81 aCancelBT (this, SW_RES(BT_CANCEL )),
82 aNextBT (this, SW_RES(PB_NEXT )),
83 aHelpBT (this, SW_RES(PB_HELP ))
85 // Font fuers Edit umschalten
86 Font aFont(aEditED.GetFont());
87 aFont.SetWeight(WEIGHT_LIGHT);
88 aEditED.SetFont(aFont);
90 if( bNextButton )
92 aNextBT.Show();
93 aNextBT.SetClickHdl(LINK(this, SwFldInputDlg, NextHdl));
95 else
97 long nDiff = aCancelBT.GetPosPixel().Y() - aOKBT.GetPosPixel().Y();
98 Point aPos = aHelpBT.GetPosPixel();
99 aPos.Y() -= nDiff;
100 aHelpBT.SetPosPixel(aPos);
103 // Auswertung hier
104 String aStr;
105 if( RES_INPUTFLD == pField->GetTyp()->Which() )
106 { // Es ist eine Eingabefeld
108 pInpFld = (SwInputField*)pField;
109 aLabelED.SetText( pInpFld->GetPar2() );
110 USHORT nSubType = pInpFld->GetSubType();
112 switch(nSubType & 0xff)
114 case INP_TXT:
115 aStr = pInpFld->GetPar1();
116 break;
118 case INP_USR:
119 // Benutzerfeld
120 if( 0 != ( pUsrType = (SwUserFieldType*)rSh.GetFldType(
121 RES_USERFLD, pInpFld->GetPar1() ) ) )
122 aStr = pUsrType->GetContent();
123 break;
126 else
128 // es ist eine SetExpression
129 pSetFld = (SwSetExpField*)pField;
130 String sFormula(pSetFld->GetFormula());
131 //values are formatted - formulas are not
132 CharClass aCC( SvxCreateLocale( pSetFld->GetLanguage() ));
133 if( aCC.isNumeric( sFormula ))
134 aStr = pSetFld->Expand();
135 else
136 aStr = sFormula;
137 aLabelED.SetText( pSetFld->GetPromptText() );
140 // JP 31.3.00: Inputfields in readonly regions must be allowed to
141 // input any content. - 74639
142 BOOL bEnable = !rSh.IsCrsrReadonly();
143 /*!rSh.IsReadOnlyAvailable() || !rSh.HasReadonlySel()*/;
144 aOKBT.Enable( bEnable );
145 aEditED.SetReadOnly( !bEnable );
147 if( aStr.Len() )
148 aEditED.SetText( aStr.ConvertLineEnd() );
149 FreeResource();
152 SwFldInputDlg::~SwFldInputDlg()
156 void SwFldInputDlg::StateChanged( StateChangedType nType )
158 if ( nType == STATE_CHANGE_INITSHOW )
159 aEditED.GrabFocus();
160 SvxStandardDialog::StateChanged( nType );
163 /*--------------------------------------------------------------------
164 Beschreibung: Schliessen
165 --------------------------------------------------------------------*/
167 void SwFldInputDlg::Apply()
169 String aTmp( aEditED.GetText() );
170 aTmp.EraseAllChars( '\r' );
172 rSh.StartAllAction();
173 BOOL bModified = FALSE;
174 if(pInpFld)
176 if(pUsrType)
178 if( aTmp != pUsrType->GetContent() )
180 pUsrType->SetContent(aTmp);
181 pUsrType->UpdateFlds();
182 bModified = TRUE;
185 else if( aTmp != pInpFld->GetPar1() )
187 pInpFld->SetPar1(aTmp);
188 rSh.SwEditShell::UpdateFlds(*pInpFld);
189 bModified = TRUE;
192 else if( aTmp != pSetFld->GetPar2() )
194 pSetFld->SetPar2(aTmp);
195 rSh.SwEditShell::UpdateFlds(*pSetFld);
196 bModified = TRUE;
199 if( bModified )
200 rSh.SetUndoNoResetModified();
202 rSh.EndAllAction();
206 IMPL_LINK(SwFldInputDlg, NextHdl, PushButton*, EMPTYARG)
208 EndDialog(RET_OK);
209 return 0;