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