Add Marathi autocorrect
[LibreOffice.git] / sw / source / ui / fldui / inpdlg.cxx
blob54c6b15ed84495a4041e01c2d829f51f40376d41
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 <tools/lineend.hxx>
21 #include <unotools/charclass.hxx>
22 #include <wrtsh.hxx>
23 #include <fldbas.hxx>
24 #include <expfld.hxx>
25 #include <usrfld.hxx>
26 #include <inpdlg.hxx>
28 // edit field-insert
29 SwFieldInputDlg::SwFieldInputDlg(weld::Widget *pParent, SwWrtShell &rS,
30 SwField* pField, bool bPrevButton, bool bNextButton)
31 : GenericDialogController(pParent, u"modules/swriter/ui/inputfielddialog.ui"_ustr, u"InputFieldDialog"_ustr)
32 , m_rSh( rS )
33 , m_pInpField(nullptr)
34 , m_pSetField(nullptr)
35 , m_pUsrType(nullptr)
36 , m_pPressedButton(nullptr)
37 , m_xLabelED(m_xBuilder->weld_entry(u"name"_ustr))
38 , m_xEditED(m_xBuilder->weld_text_view(u"text"_ustr))
39 , m_xPrevBT(m_xBuilder->weld_button(u"prev"_ustr))
40 , m_xNextBT(m_xBuilder->weld_button(u"next"_ustr))
41 , m_xOKBT(m_xBuilder->weld_button(u"ok"_ustr))
43 m_xEditED->set_size_request(-1, m_xEditED->get_height_rows(8));
45 if( bPrevButton || bNextButton )
47 m_xPrevBT->show();
48 m_xPrevBT->connect_clicked(LINK(this, SwFieldInputDlg, PrevHdl));
49 m_xPrevBT->set_sensitive(bPrevButton);
51 m_xNextBT->show();
52 m_xNextBT->connect_clicked(LINK(this, SwFieldInputDlg, NextHdl));
53 m_xNextBT->set_sensitive(bNextButton);
56 // evaluation here
57 OUString aStr;
58 if( SwFieldIds::Input == pField->GetTyp()->Which() )
59 { // it is an input field
61 m_pInpField = static_cast<SwInputField*>(pField);
62 m_xLabelED->set_text(m_pInpField->GetPar2());
63 sal_uInt16 nSubType = m_pInpField->GetSubType();
65 switch(nSubType & 0xff)
67 case INP_TXT:
68 aStr = m_pInpField->GetPar1();
69 break;
71 case INP_USR:
72 // user field
73 m_pUsrType = static_cast<SwUserFieldType*>(m_rSh.GetFieldType(
74 SwFieldIds::User, m_pInpField->GetPar1() ));
75 if( nullptr != m_pUsrType )
76 aStr = m_pUsrType->GetContent();
77 break;
80 else
82 // it is a SetExpression
83 m_pSetField = static_cast<SwSetExpField*>(pField);
84 OUString sFormula(m_pSetField->GetFormula());
85 //values are formatted - formulas are not
86 CharClass aCC( LanguageTag( m_pSetField->GetLanguage() ));
87 if( aCC.isNumeric( sFormula ))
89 aStr = m_pSetField->ExpandField(true, rS.GetLayout());
91 else
92 aStr = sFormula;
93 m_xLabelED->set_text(m_pSetField->GetPromptText());
96 // JP 31.3.00: Inputfields in readonly regions must be allowed to
97 // input any content. - 74639
98 bool bEnable = !m_rSh.IsCursorReadonly();
100 m_xOKBT->set_sensitive( bEnable );
101 m_xEditED->set_editable( bEnable );
103 if( !aStr.isEmpty() )
104 m_xEditED->set_text(convertLineEnd(aStr, GetSystemLineEnd()));
105 m_xEditED->grab_focus();
107 // preselect all text to allow quickly changing the content
108 if (bEnable)
109 m_xEditED->select_region(0, -1);
112 SwFieldInputDlg::~SwFieldInputDlg()
116 // Close
117 void SwFieldInputDlg::Apply()
119 OUString aTmp = m_xEditED->get_text().replaceAll("\r", "");
120 m_rSh.StartAllAction();
121 bool bModified = false;
122 if(m_pInpField)
124 if(m_pUsrType)
126 if( aTmp != m_pUsrType->GetContent() )
128 m_pUsrType->SetContent(aTmp);
129 m_pUsrType->UpdateFields();
130 bModified = true;
133 else if( aTmp != m_pInpField->GetPar1() )
135 m_pInpField->SetPar1(aTmp);
136 m_rSh.SwEditShell::UpdateOneField(*m_pInpField);
137 bModified = true;
140 else if( aTmp != m_pSetField->GetPar2())
142 m_pSetField->SetPar2(aTmp);
143 m_rSh.SwEditShell::UpdateOneField(*m_pSetField);
144 bModified = true;
147 if( bModified )
148 m_rSh.SetUndoNoResetModified();
150 m_rSh.EndAllAction();
153 bool SwFieldInputDlg::PrevButtonPressed() const
155 return m_pPressedButton == m_xPrevBT.get();
158 bool SwFieldInputDlg::NextButtonPressed() const
160 return m_pPressedButton == m_xNextBT.get();
163 IMPL_LINK_NOARG(SwFieldInputDlg, PrevHdl, weld::Button&, void)
165 m_pPressedButton = m_xPrevBT.get();
166 m_xDialog->response(RET_OK);
169 IMPL_LINK_NOARG(SwFieldInputDlg, NextHdl, weld::Button&, void)
171 m_pPressedButton = m_xNextBT.get();
172 m_xDialog->response(RET_OK);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */