bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / fldui / inpdlg.cxx
blobc6e63403f704b9684669d8dbfc996ce4fb86effa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/string.hxx>
21 #include <vcl/msgbox.hxx>
22 #include <unotools/charclass.hxx>
23 #include <editeng/unolingu.hxx>
24 #include <wrtsh.hxx>
25 #include <fldbas.hxx>
26 #include <expfld.hxx>
27 #include <usrfld.hxx>
28 #include <inpdlg.hxx>
29 #include <fldmgr.hxx>
31 #include <fldui.hrc>
33 /*--------------------------------------------------------------------
34 Description: edit field-insert
35 --------------------------------------------------------------------*/
37 SwFldInputDlg::SwFldInputDlg( Window *pParent, SwWrtShell &rS,
38 SwField* pField, sal_Bool bNextButton )
39 : SvxStandardDialog( pParent, "InputFieldDialog",
40 "modules/swriter/ui/inputfielddialog.ui")
41 , rSh( rS )
42 , pInpFld(0)
43 , pSetFld(0)
44 , pUsrType(0)
46 get(m_pLabelED, "name");
47 get(m_pEditED, "text");
48 m_pEditED->set_height_request(m_pEditED->GetTextHeight() * 9);
49 get(m_pNextBT, "next");
50 get(m_pOKBT, "ok");
51 // switch font for Edit
52 Font aFont(m_pEditED->GetFont());
53 aFont.SetWeight(WEIGHT_LIGHT);
54 m_pEditED->SetFont(aFont);
56 if( bNextButton )
58 m_pNextBT->Show();
59 m_pNextBT->SetClickHdl(LINK(this, SwFldInputDlg, NextHdl));
62 // evaluation here
63 String aStr;
64 if( RES_INPUTFLD == pField->GetTyp()->Which() )
65 { // it is an input field
67 pInpFld = (SwInputField*)pField;
68 m_pLabelED->SetText( pInpFld->GetPar2() );
69 sal_uInt16 nSubType = pInpFld->GetSubType();
71 switch(nSubType & 0xff)
73 case INP_TXT:
74 aStr = pInpFld->GetPar1();
75 break;
77 case INP_USR:
78 // user field
79 if( 0 != ( pUsrType = (SwUserFieldType*)rSh.GetFldType(
80 RES_USERFLD, pInpFld->GetPar1() ) ) )
81 aStr = pUsrType->GetContent();
82 break;
85 else
87 // it is a SetExpression
88 pSetFld = (SwSetExpField*)pField;
89 String sFormula(pSetFld->GetFormula());
90 //values are formatted - formulas are not
91 CharClass aCC( LanguageTag( pSetFld->GetLanguage() ));
92 if( aCC.isNumeric( sFormula ))
94 aStr = pSetFld->ExpandField(true);
96 else
97 aStr = sFormula;
98 m_pLabelED->SetText( pSetFld->GetPromptText() );
101 // JP 31.3.00: Inputfields in readonly regions must be allowed to
102 // input any content. - 74639
103 sal_Bool bEnable = !rSh.IsCrsrReadonly();
105 m_pOKBT->Enable( bEnable );
106 m_pEditED->SetReadOnly( !bEnable );
108 if( aStr.Len() )
109 m_pEditED->SetText(convertLineEnd(aStr, GetSystemLineEnd()));
112 void SwFldInputDlg::StateChanged( StateChangedType nType )
114 if ( nType == STATE_CHANGE_INITSHOW )
115 m_pEditED->GrabFocus();
116 SvxStandardDialog::StateChanged( nType );
119 /*--------------------------------------------------------------------
120 Description: Close
121 --------------------------------------------------------------------*/
123 void SwFldInputDlg::Apply()
125 OUString aTmp(comphelper::string::remove(m_pEditED->GetText(), '\r'));
127 rSh.StartAllAction();
128 bool bModified = false;
129 if(pInpFld)
131 if(pUsrType)
133 if( !aTmp.equals(pUsrType->GetContent()) )
135 pUsrType->SetContent(aTmp);
136 pUsrType->UpdateFlds();
137 bModified = true;
140 else if( !aTmp.equals(pInpFld->GetPar1()) )
142 pInpFld->SetPar1(aTmp);
143 rSh.SwEditShell::UpdateFlds(*pInpFld);
144 bModified = true;
147 else if( !aTmp.equals(pSetFld->GetPar2()) )
149 pSetFld->SetPar2(aTmp);
150 rSh.SwEditShell::UpdateFlds(*pSetFld);
151 bModified = true;
154 if( bModified )
155 rSh.SetUndoNoResetModified();
157 rSh.EndAllAction();
161 IMPL_LINK_NOARG(SwFldInputDlg, NextHdl)
163 EndDialog(RET_OK);
164 return 0;
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */