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>
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 , 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("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 m_pInpField = static_cast<SwInputField*>(pField);
62 m_xLabelED->set_text(m_pInpField->GetPar2());
63 sal_uInt16 nSubType = m_pInpField->GetSubType();
64
65 switch(nSubType & 0xff)
66 {
67 case INP_TXT:
69 break;
70
71 case INP_USR:
72 // user field
75 if( nullptr != m_pUsrType )
77 break;
78 }
79 }
80 else
81 {
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
87 if( aCC.isNumeric( sFormula ))
88 {
90 }
91 else
92 aStr = sFormula;
94 }
95
96 // JP 31.3.00: Inputfields in readonly regions must be allowed to
97 // input any content. - 74639
98 bool bEnable = !m_rSh.IsCursorReadonly();
99
100 m_xOKBT->set_sensitive( bEnable );
101 m_xEditED->set_editable( bEnable );
102
103 if( !aStr.isEmpty() )
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(m_pInpField)
123 {
124 if(m_pUsrType)
125 {
126 if( aTmp != m_pUsrType->GetContent() )
127 {
128 m_pUsrType->SetContent(aTmp);
130 bModified = true;
131 }
132 }
133 else if( aTmp != m_pInpField->GetPar1() )
134 {
135 m_pInpField->SetPar1(aTmp);
136 m_rSh.SwEditShell::UpdateOneField(*m_pInpField);
137 bModified = true;
138 }
139 }
140 else if( aTmp != m_pSetField->GetPar2())
141 {
142 m_pSetField->SetPar2(aTmp);
143 m_rSh.SwEditShell::UpdateOneField(*m_pSetField);
144 bModified = true;
145 }
146
147 if( bModified )
149
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: */
Reference< XExecutableDialog > m_xDialog
bool isNumeric(const OUString &rStr) const
bool IsCursorReadonly() const
Definition: crsrsh.cxx:3609
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void SetUndoNoResetModified()
Definition: edws.cxx:80
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 EndAllAction()
Definition: edws.cxx:97
std::unique_ptr< weld::Button > m_xNextBT
Definition: inpdlg.hxx:45
std::unique_ptr< weld::Button > m_xOKBT
Definition: inpdlg.hxx:46
std::unique_ptr< weld::Entry > m_xLabelED
Definition: inpdlg.hxx:42
virtual ~SwFieldInputDlg() override
Definition: inpdlg.cxx:112
std::unique_ptr< weld::TextView > m_xEditED
Definition: inpdlg.hxx:43
std::unique_ptr< weld::Button > m_xPrevBT
Definition: inpdlg.hxx:44
SwSetExpField * m_pSetField
Definition: inpdlg.hxx:38
void Apply()
Definition: inpdlg.cxx:117
weld::Button * m_pPressedButton
Definition: inpdlg.hxx:41
bool PrevButtonPressed() const
Definition: inpdlg.cxx:153
bool NextButtonPressed() const
Definition: inpdlg.cxx:158
SwInputField * m_pInpField
Definition: inpdlg.hxx:37
SwFieldInputDlg(weld::Widget *pParent, SwWrtShell &rSh, SwField *pField, bool bPrevButton, bool bNextButton)
Definition: inpdlg.cxx:29
SwUserFieldType * m_pUsrType
Definition: inpdlg.hxx:39
SwWrtShell & m_rSh
Definition: inpdlg.hxx:36
virtual void UpdateFields()
Definition: fldbas.cxx:219
SwFieldIds Which() const
Definition: fldbas.hxx:276
Base class of all fields.
Definition: fldbas.hxx:296
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:491
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:412
virtual OUString GetFormula() const override
Definition: fldbas.cxx:820
virtual void SetPar1(const OUString &rStr) override
set condition
Definition: expfld.cxx:1387
virtual OUString GetPar2() const override
aPromptText
Definition: expfld.cxx:1402
virtual sal_uInt16 GetSubType() const override
Definition: expfld.cxx:1427
virtual OUString GetPar1() const override
Content.
Definition: expfld.cxx:1392
const OUString & GetPromptText() const
Definition: expfld.hxx:263
virtual OUString GetPar2() const override
Query formula.
Definition: expfld.cxx:1022
virtual void SetPar2(const OUString &rStr) override
Definition: expfld.cxx:1031
The shared part of a user field.
Definition: usrfld.hxx:35
OUString GetContent(sal_uInt32 nFormat=0) const
Definition: usrfld.cxx:283
void SetContent(const OUString &rStr, sal_uInt32 nFormat=0)
Definition: usrfld.cxx:299
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
OString sFormula
@ INP_USR
Definition: fldbas.hxx:223
@ INP_TXT
Definition: fldbas.hxx:222
IMPL_LINK_NOARG(SwFieldInputDlg, PrevHdl, weld::Button &, void)
Definition: inpdlg.cxx:163
LineEnd GetSystemLineEnd()
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
aStr
RET_OK