1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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")
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");
51 // switch font for Edit
52 Font
aFont(m_pEditED
->GetFont());
53 aFont
.SetWeight(WEIGHT_LIGHT
);
54 m_pEditED
->SetFont(aFont
);
59 m_pNextBT
->SetClickHdl(LINK(this, SwFldInputDlg
, NextHdl
));
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)
74 aStr
= pInpFld
->GetPar1();
79 if( 0 != ( pUsrType
= (SwUserFieldType
*)rSh
.GetFldType(
80 RES_USERFLD
, pInpFld
->GetPar1() ) ) )
81 aStr
= pUsrType
->GetContent();
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);
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
);
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 /*--------------------------------------------------------------------
121 --------------------------------------------------------------------*/
123 void SwFldInputDlg::Apply()
125 OUString
aTmp(comphelper::string::remove(m_pEditED
->GetText(), '\r'));
127 rSh
.StartAllAction();
128 bool bModified
= false;
133 if( !aTmp
.equals(pUsrType
->GetContent()) )
135 pUsrType
->SetContent(aTmp
);
136 pUsrType
->UpdateFlds();
140 else if( !aTmp
.equals(pInpFld
->GetPar1()) )
142 pInpFld
->SetPar1(aTmp
);
143 rSh
.SwEditShell::UpdateFlds(*pInpFld
);
147 else if( !aTmp
.equals(pSetFld
->GetPar2()) )
149 pSetFld
->SetPar2(aTmp
);
150 rSh
.SwEditShell::UpdateFlds(*pSetFld
);
155 rSh
.SetUndoNoResetModified();
161 IMPL_LINK_NOARG(SwFldInputDlg
, NextHdl
)
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */