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 <editeng/unolingu.hxx>
23 #include <wrtsh.hxx>
24 #include <fldbas.hxx>
25 #include <expfld.hxx>
26 #include <usrfld.hxx>
27 #include <inpdlg.hxx>
28 #include <fldmgr.hxx>
29 
30 // edit field-insert
32  SwField* pField, bool bPrevButton, bool bNextButton)
33  : GenericDialogController(pParent, "modules/swriter/ui/inputfielddialog.ui", "InputFieldDialog")
34  , rSh( rS )
35  , pInpField(nullptr)
36  , pSetField(nullptr)
37  , pUsrType(nullptr)
38  , m_pPressedButton(nullptr)
39  , m_xLabelED(m_xBuilder->weld_entry("name"))
40  , m_xEditED(m_xBuilder->weld_text_view("text"))
41  , m_xPrevBT(m_xBuilder->weld_button("prev"))
42  , m_xNextBT(m_xBuilder->weld_button("next"))
43  , m_xOKBT(m_xBuilder->weld_button("ok"))
44 {
45  m_xEditED->set_size_request(-1, m_xEditED->get_height_rows(8));
46 
47  if( bPrevButton || bNextButton )
48  {
49  m_xPrevBT->show();
50  m_xPrevBT->connect_clicked(LINK(this, SwFieldInputDlg, PrevHdl));
51  m_xPrevBT->set_sensitive(bPrevButton);
52 
53  m_xNextBT->show();
54  m_xNextBT->connect_clicked(LINK(this, SwFieldInputDlg, NextHdl));
55  m_xNextBT->set_sensitive(bNextButton);
56  }
57 
58  // evaluation here
59  OUString aStr;
60  if( SwFieldIds::Input == pField->GetTyp()->Which() )
61  { // it is an input field
62 
63  pInpField = static_cast<SwInputField*>(pField);
64  m_xLabelED->set_text(pInpField->GetPar2());
65  sal_uInt16 nSubType = pInpField->GetSubType();
66 
67  switch(nSubType & 0xff)
68  {
69  case INP_TXT:
70  aStr = pInpField->GetPar1();
71  break;
72 
73  case INP_USR:
74  // user field
75  if( nullptr != ( pUsrType = static_cast<SwUserFieldType*>(rSh.GetFieldType(
77  aStr = pUsrType->GetContent();
78  break;
79  }
80  }
81  else
82  {
83  // it is a SetExpression
84  pSetField = static_cast<SwSetExpField*>(pField);
85  OUString sFormula(pSetField->GetFormula());
86  //values are formatted - formulas are not
88  if( aCC.isNumeric( sFormula ))
89  {
90  aStr = pSetField->ExpandField(true, rS.GetLayout());
91  }
92  else
93  aStr = sFormula;
94  m_xLabelED->set_text(pSetField->GetPromptText());
95  }
96 
97  // JP 31.3.00: Inputfields in readonly regions must be allowed to
98  // input any content. - 74639
99  bool bEnable = !rSh.IsCursorReadonly();
100 
101  m_xOKBT->set_sensitive( bEnable );
102  m_xEditED->set_editable( bEnable );
103 
104  if( !aStr.isEmpty() )
105  m_xEditED->set_text(convertLineEnd(aStr, GetSystemLineEnd()));
106  m_xEditED->grab_focus();
107 
108  // preselect all text to allow quickly changing the content
109  if (bEnable)
110  m_xEditED->select_region(0, -1);
111 }
112 
114 {
115 }
116 
117 // Close
119 {
120  OUString aTmp = m_xEditED->get_text().replaceAll("\r", "");
122  bool bModified = false;
123  if(pInpField)
124  {
125  if(pUsrType)
126  {
127  if( aTmp != pUsrType->GetContent() )
128  {
129  pUsrType->SetContent(aTmp);
131  bModified = true;
132  }
133  }
134  else if( aTmp != pInpField->GetPar1() )
135  {
136  pInpField->SetPar1(aTmp);
137  rSh.SwEditShell::UpdateOneField(*pInpField);
138  bModified = true;
139  }
140  }
141  else if( aTmp != pSetField->GetPar2())
142  {
143  pSetField->SetPar2(aTmp);
144  rSh.SwEditShell::UpdateOneField(*pSetField);
145  bModified = true;
146  }
147 
148  if( bModified )
150 
151  rSh.EndAllAction();
152 }
153 
155 {
156  return m_pPressedButton == m_xPrevBT.get();
157 }
158 
160 {
161  return m_pPressedButton == m_xNextBT.get();
162 }
163 
165 {
166  m_pPressedButton = m_xPrevBT.get();
167  m_xDialog->response(RET_OK);
168 }
169 
171 {
172  m_pPressedButton = m_xNextBT.get();
173  m_xDialog->response(RET_OK);
174 }
175 
176 
177 /* 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:118
IMPL_LINK_NOARG(SwFieldInputDlg, PrevHdl, weld::Button &, void)
Definition: inpdlg.cxx:164
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:393
void SetUndoNoResetModified()
Definition: edws.cxx:79
std::unique_ptr< weld::Button > m_xPrevBT
Definition: inpdlg.hxx:44
Base class of all fields.
Definition: fldbas.hxx:280
const OUString & GetPromptText() const
Definition: expfld.hxx:258
std::unique_ptr< weld::Button > m_xOKBT
Definition: inpdlg.hxx:46
void EndAllAction()
Definition: edws.cxx:96
virtual OUString GetPar1() const override
Content.
Definition: expfld.cxx:1393
virtual void SetPar2(const OUString &rStr) override
Definition: expfld.cxx:1043
void UpdateFields() const
Definition: fldbas.hxx:272
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:159
bool IsCursorReadonly() const
Definition: crsrsh.cxx:3259
virtual void SetPar1(const OUString &rStr) override
set condition
Definition: expfld.cxx:1388
bool PrevButtonPressed() const
Definition: inpdlg.cxx:154
virtual OUString GetFormula() const override
Definition: fldbas.cxx:688
std::unique_ptr< weld::Entry > m_xLabelED
Definition: inpdlg.hxx:42
SwFieldType * GetTyp() const
Definition: fldbas.hxx:383
SwInputField * pInpField
Definition: inpdlg.hxx:37
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:404
RET_OK
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:31
virtual OUString GetPar2() const override
Query formula.
Definition: expfld.cxx:1034
SwUserFieldType * pUsrType
Definition: inpdlg.hxx:39
SwSetExpField * pSetField
Definition: inpdlg.hxx:38
void StartAllAction()
For all views of this document.
Definition: edws.cxx:85
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
std::unique_ptr< weld::Button > m_xNextBT
Definition: inpdlg.hxx:45
SwFieldIds Which() const
Definition: fldbas.hxx:266
aStr
virtual OUString GetPar2() const override
aPromptText
Definition: expfld.cxx:1403
virtual ~SwFieldInputDlg() override
Definition: inpdlg.cxx:113
virtual sal_uInt16 GetSubType() const override
Definition: expfld.cxx:1428
void SetContent(const OUString &rStr, sal_uInt32 nFormat=0)
Definition: usrfld.cxx:282