LibreOffice Module sw (master)  1
inpdlg.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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>
27 
28 // edit field-insert
30  SwField* pField, bool bPrevButton, bool bNextButton)
31  : GenericDialogController(pParent, "modules/swriter/ui/inputfielddialog.ui", "InputFieldDialog")
32  , rSh( rS )
33  , pInpField(nullptr)
34  , pSetField(nullptr)
35  , pUsrType(nullptr)
36  , m_pPressedButton(nullptr)
37  , m_xLabelED(m_xBuilder->weld_entry("name"))
38  , m_xEditED(m_xBuilder->weld_text_view("text"))
39  , m_xPrevBT(m_xBuilder->weld_button("prev"))
40  , m_xNextBT(m_xBuilder->weld_button("next"))
41  , m_xOKBT(m_xBuilder->weld_button("ok"))
42 {
43  m_xEditED->set_size_request(-1, m_xEditED->get_height_rows(8));
44 
45  if( bPrevButton || bNextButton )
46  {
47  m_xPrevBT->show();
48  m_xPrevBT->connect_clicked(LINK(this, SwFieldInputDlg, PrevHdl));
49  m_xPrevBT->set_sensitive(bPrevButton);
50 
51  m_xNextBT->show();
52  m_xNextBT->connect_clicked(LINK(this, SwFieldInputDlg, NextHdl));
53  m_xNextBT->set_sensitive(bNextButton);
54  }
55 
56  // evaluation here
57  OUString aStr;
58  if( SwFieldIds::Input == pField->GetTyp()->Which() )
59  { // it is an input field
60 
61  pInpField = static_cast<SwInputField*>(pField);
62  m_xLabelED->set_text(pInpField->GetPar2());
63  sal_uInt16 nSubType = pInpField->GetSubType();
64 
65  switch(nSubType & 0xff)
66  {
67  case INP_TXT:
68  aStr = pInpField->GetPar1();
69  break;
70 
71  case INP_USR:
72  // user field
73  pUsrType = static_cast<SwUserFieldType*>(rSh.GetFieldType(
75  if( nullptr != pUsrType )
76  aStr = pUsrType->GetContent();
77  break;
78  }
79  }
80  else
81  {
82  // it is a SetExpression
83  pSetField = static_cast<SwSetExpField*>(pField);
84  OUString sFormula(pSetField->GetFormula());
85  //values are formatted - formulas are not
87  if( aCC.isNumeric( sFormula ))
88  {
89  aStr = pSetField->ExpandField(true, rS.GetLayout());
90  }
91  else
92  aStr = sFormula;
93  m_xLabelED->set_text(pSetField->GetPromptText());
94  }
95 
96  // JP 31.3.00: Inputfields in readonly regions must be allowed to
97  // input any content. - 74639
98  bool bEnable = !rSh.IsCursorReadonly();
99 
100  m_xOKBT->set_sensitive( bEnable );
101  m_xEditED->set_editable( bEnable );
102 
103  if( !aStr.isEmpty() )
104  m_xEditED->set_text(convertLineEnd(aStr, GetSystemLineEnd()));
105  m_xEditED->grab_focus();
106 
107  // preselect all text to allow quickly changing the content
108  if (bEnable)
109  m_xEditED->select_region(0, -1);
110 }
111 
113 {
114 }
115 
116 // Close
118 {
119  OUString aTmp = m_xEditED->get_text().replaceAll("\r", "");
121  bool bModified = false;
122  if(pInpField)
123  {
124  if(pUsrType)
125  {
126  if( aTmp != pUsrType->GetContent() )
127  {
128  pUsrType->SetContent(aTmp);
130  bModified = true;
131  }
132  }
133  else if( aTmp != pInpField->GetPar1() )
134  {
135  pInpField->SetPar1(aTmp);
136  rSh.SwEditShell::UpdateOneField(*pInpField);
137  bModified = true;
138  }
139  }
140  else if( aTmp != pSetField->GetPar2())
141  {
142  pSetField->SetPar2(aTmp);
143  rSh.SwEditShell::UpdateOneField(*pSetField);
144  bModified = true;
145  }
146 
147  if( bModified )
149 
150  rSh.EndAllAction();
151 }
152 
154 {
155  return m_pPressedButton == m_xPrevBT.get();
156 }
157 
159 {
160  return m_pPressedButton == m_xNextBT.get();
161 }
162 
164 {
165  m_pPressedButton = m_xPrevBT.get();
166  m_xDialog->response(RET_OK);
167 }
168 
170 {
171  m_pPressedButton = m_xNextBT.get();
172  m_xDialog->response(RET_OK);
173 }
174 
175 
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwFieldType * GetFieldType(size_t nField, SwFieldIds nResId=SwFieldIds::Unknown) const
get field types with a ResId, if 0 get all
Definition: edfld.cxx:64
void Apply()
Definition: inpdlg.cxx:117
IMPL_LINK_NOARG(SwFieldInputDlg, PrevHdl, weld::Button &, void)
Definition: inpdlg.cxx:163
The shared part of a user field.
Definition: usrfld.hxx:35
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:406
void SetUndoNoResetModified()
Definition: edws.cxx:80
std::unique_ptr< weld::Button > m_xPrevBT
Definition: inpdlg.hxx:44
Base class of all fields.
Definition: fldbas.hxx:293
const OUString & GetPromptText() const
Definition: expfld.hxx:259
std::unique_ptr< weld::Button > m_xOKBT
Definition: inpdlg.hxx:46
void EndAllAction()
Definition: edws.cxx:97
virtual OUString GetPar1() const override
Content.
Definition: expfld.cxx:1387
virtual void SetPar2(const OUString &rStr) override
Definition: expfld.cxx:1037
void UpdateFields() const
Definition: fldbas.hxx:285
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
weld::Button * m_pPressedButton
Definition: inpdlg.hxx:41
LineEnd GetSystemLineEnd()
SwWrtShell & rSh
Definition: inpdlg.hxx:36
bool NextButtonPressed() const
Definition: inpdlg.cxx:158
bool IsCursorReadonly() const
Definition: crsrsh.cxx:3280
virtual void SetPar1(const OUString &rStr) override
set condition
Definition: expfld.cxx:1382
bool PrevButtonPressed() const
Definition: inpdlg.cxx:153
virtual OUString GetFormula() const override
Definition: fldbas.cxx:727
std::unique_ptr< weld::Entry > m_xLabelED
Definition: inpdlg.hxx:42
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
SwInputField * pInpField
Definition: inpdlg.hxx:37
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:443
RET_OK
Reference< XExecutableDialog > m_xDialog
std::unique_ptr< weld::TextView > m_xEditED
Definition: inpdlg.hxx:43
OUString GetContent(sal_uInt32 nFormat=0)
Definition: usrfld.cxx:266
SwFieldInputDlg(weld::Widget *pParent, SwWrtShell &rSh, SwField *pField, bool bPrevButton, bool bNextButton)
Definition: inpdlg.cxx:29
virtual OUString GetPar2() const override
Query formula.
Definition: expfld.cxx:1028
SwUserFieldType * pUsrType
Definition: inpdlg.hxx:39
SwSetExpField * pSetField
Definition: inpdlg.hxx:38
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2069
std::unique_ptr< weld::Button > m_xNextBT
Definition: inpdlg.hxx:45
SwFieldIds Which() const
Definition: fldbas.hxx:272
aStr
virtual OUString GetPar2() const override
aPromptText
Definition: expfld.cxx:1397
virtual ~SwFieldInputDlg() override
Definition: inpdlg.cxx:112
virtual sal_uInt16 GetSubType() const override
Definition: expfld.cxx:1422
void SetContent(const OUString &rStr, sal_uInt32 nFormat=0)
Definition: usrfld.cxx:282