LibreOffice Module sc (master) 1
filldlg.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#undef SC_DLLIMPLEMENTATION
21
22#include <svl/numformat.hxx>
23#include <utility>
24#include <vcl/svapp.hxx>
25#include <vcl/weld.hxx>
26
27#include <scresid.hxx>
28#include <document.hxx>
29#include <strings.hrc>
30#include <filldlg.hxx>
31#include <scui_def.hxx>
32
33
35 ScDocument& rDocument,
36 FillDir eFillDir,
37 FillCmd eFillCmd,
38 FillDateCmd eFillDateCmd,
39 OUString aStartStr,
40 double fStep,
41 double fMax,
42 const SCSIZE nSelectHeight,
43 const SCSIZE nSelectWidth,
44 sal_uInt16 nPossDir )
45 : GenericDialogController(pParent, "modules/scalc/ui/filldlg.ui", "FillSeriesDialog")
46 , aStartStrVal(std::move(aStartStr))
47 , aErrMsgInvalidVal(ScResId(SCSTR_VALERR))
48 , rDoc(rDocument)
49 , theFillDir(eFillDir)
50 , theFillCmd(eFillCmd)
51 , theFillDateCmd(eFillDateCmd)
52 , fIncrement(fStep)
53 , fEndVal(fMax)
54 , m_nSelectHeight(nSelectHeight)
55 , m_nSelectWidth(nSelectWidth)
56 , m_xFtStartVal(m_xBuilder->weld_label("startL"))
57 , m_xEdStartVal(m_xBuilder->weld_entry("startValue"))
58 , m_xFtEndVal(m_xBuilder->weld_label("endL"))
59 , m_xEdEndVal(m_xBuilder->weld_entry("endValue"))
60 , m_xFtIncrement(m_xBuilder->weld_label("incrementL"))
61 , m_xEdIncrement(m_xBuilder->weld_entry("increment"))
62 , m_xBtnDown(m_xBuilder->weld_radio_button("down"))
63 , m_xBtnRight(m_xBuilder->weld_radio_button("right"))
64 , m_xBtnUp(m_xBuilder->weld_radio_button("up"))
65 , m_xBtnLeft(m_xBuilder->weld_radio_button("left"))
66 , m_xBtnArithmetic(m_xBuilder->weld_radio_button("linear"))
67 , m_xBtnGeometric(m_xBuilder->weld_radio_button("growth"))
68 , m_xBtnDate(m_xBuilder->weld_radio_button("date"))
69 , m_xBtnAutoFill(m_xBuilder->weld_radio_button("autofill"))
70 , m_xFtTimeUnit(m_xBuilder->weld_label("tuL"))
71 , m_xBtnDay(m_xBuilder->weld_radio_button("day"))
72 , m_xBtnDayOfWeek(m_xBuilder->weld_radio_button("week"))
73 , m_xBtnMonth(m_xBuilder->weld_radio_button("month"))
74 , m_xBtnYear(m_xBuilder->weld_radio_button("year"))
75 , m_xBtnOk(m_xBuilder->weld_button("ok"))
76{
77 Init(nPossDir);
78}
79
81{
82}
83
85{
86 if(bFlag)
87 {
88 m_xFtStartVal->set_sensitive(true);
89 m_xEdStartVal->set_sensitive(true);
90 }
91 else
92 {
93 m_xFtStartVal->set_sensitive(false);
94 m_xEdStartVal->set_sensitive(false);
95 }
96}
97
98void ScFillSeriesDlg::Init( sal_uInt16 nPossDir )
99{
100 m_xBtnOk->connect_clicked ( LINK( this, ScFillSeriesDlg, OKHdl ) );
101 m_xBtnArithmetic->connect_toggled ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
102 m_xBtnGeometric->connect_toggled ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
103 m_xBtnDate->connect_toggled ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
104 m_xBtnAutoFill->connect_toggled ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
105
106 if( nPossDir == FDS_OPT_NONE )
107 {
108 m_xBtnLeft->set_sensitive(false);
109 m_xBtnRight->set_sensitive(false);
110 m_xBtnDown->set_sensitive(false);
111 m_xBtnUp->set_sensitive(false);
112 }
113
114 if( nPossDir == FDS_OPT_HORZ )
115 {
116 m_xBtnDown->set_sensitive(false);
117 m_xBtnUp->set_sensitive(false);
118 }
119
120 if( nPossDir == FDS_OPT_VERT )
121 {
122 m_xBtnLeft->set_sensitive(false);
123 m_xBtnRight->set_sensitive(false);
124 }
125
126 switch ( theFillDir )
127 {
128 case FILL_TO_LEFT: m_xBtnLeft->set_active(true); break;
129 case FILL_TO_RIGHT: m_xBtnRight->set_active(true); break;
130 case FILL_TO_BOTTOM: m_xBtnDown->set_active(true); break;
131 case FILL_TO_TOP: m_xBtnUp->set_active(true); break;
132 default:
133 break;
134 }
135
136 switch ( theFillCmd )
137 {
138 case FILL_LINEAR:
139 m_xBtnArithmetic->set_active(true);
140 DisableHdl(*m_xBtnArithmetic);
141 break;
142 case FILL_GROWTH:
143 m_xBtnGeometric->set_active(true);
144 DisableHdl(*m_xBtnGeometric );
145 break;
146 case FILL_DATE:
147 m_xBtnDate->set_active(true);
148 DisableHdl(*m_xBtnDate);
149 break;
150 case FILL_AUTO:
151 m_xBtnAutoFill->set_active(true);
152 DisableHdl(*m_xBtnAutoFill);
153 break;
154 default:
155 break;
156 }
157
158 switch ( theFillDateCmd )
159 {
160 case FILL_DAY: m_xBtnDay->set_active(true); break;
161 case FILL_WEEKDAY: m_xBtnDayOfWeek->set_active(true); break;
162 case FILL_MONTH: m_xBtnMonth->set_active(true); break;
163 case FILL_YEAR: m_xBtnYear->set_active(true); break;
164 default:
165 break;
166 }
167
169
170 m_xEdStartVal->set_text( aStartStrVal);
171
172 OUString aIncrTxt;
174 m_xEdIncrement->set_text( aIncrTxt );
175
176 OUString aEndTxt;
177 if ( fEndVal != MAXDOUBLE )
179 m_xEdEndVal->set_text( aEndTxt );
180}
181
183{
184 OUString aStartStr = m_xEdStartVal->get_text();
185 OUString aIncStr = m_xEdIncrement->get_text();
186 OUString aEndStr = m_xEdEndVal->get_text();
187 sal_uInt32 nKey = 0;
188
189 // If entry is filled, capture value before handling special cases.
190 if ( !aStartStr.isEmpty()
192 && !rDoc.GetFormatTable()->IsNumberFormat( aStartStr, nKey, fStartVal ) )
193 return m_xEdStartVal.get();
194 if ( !aIncStr.isEmpty()
195 && !rDoc.GetFormatTable()->IsNumberFormat( aIncStr, nKey, fIncrement ) )
196 return m_xEdIncrement.get();
197 if ( !aEndStr.isEmpty()
198 && !rDoc.GetFormatTable()->IsNumberFormat( aEndStr, nKey, fEndVal ) )
199 return m_xEdEndVal.get();
200
201 if ( theFillCmd == FILL_LINEAR && !aEndStr.isEmpty()
202 && aStartStr.isEmpty() != aIncStr.isEmpty()
203 && ( ( m_nSelectHeight == 1 ) != ( m_nSelectWidth == 1 ) ) )
204 {
205 SCSIZE nStepAmount = ( theFillDir == FILL_TO_BOTTOM || theFillDir == FILL_TO_TOP ) ?
207 if ( aStartStr.isEmpty() )
208 fStartVal = fEndVal - fIncrement * nStepAmount;
209 if ( aIncStr.isEmpty() && nStepAmount != 0 )
210 fIncrement = (fEndVal - fStartVal) / nStepAmount;
211 }
212 else
213 {
214 if ( aStartStr.isEmpty() || m_xBtnAutoFill->get_active() )
216 if ( aIncStr.isEmpty() )
217 return m_xEdIncrement.get();
218 if ( aEndStr.isEmpty() )
219 fEndVal = ( fIncrement < 0 ) ? -MAXDOUBLE : MAXDOUBLE;
220 }
221 return nullptr;
222}
223
224// Handler:
226{
227 if (&rBtn == m_xBtnDate.get())
228 {
229 m_xBtnDay->set_sensitive(true);
230 m_xBtnDayOfWeek->set_sensitive(true);
231 m_xBtnMonth->set_sensitive(true);
232 m_xBtnYear->set_sensitive(true);
233 m_xFtTimeUnit->set_sensitive(true);
234 }
235 else
236 {
237 m_xBtnDay->set_sensitive(false);
238 m_xBtnDayOfWeek->set_sensitive(false);
239 m_xBtnMonth->set_sensitive(false);
240 m_xBtnYear->set_sensitive(false);
241 m_xFtTimeUnit->set_sensitive(false);
242 }
243
244 if (&rBtn != m_xBtnAutoFill.get())
245 {
246 m_xFtIncrement->set_sensitive(true);
247 m_xEdIncrement->set_sensitive(true);
248 m_xFtEndVal->set_sensitive(true);
249 m_xEdEndVal->set_sensitive(true);
250 }
251 else
252 {
253 m_xFtIncrement->set_sensitive(false);
254 m_xEdIncrement->set_sensitive(false);
255 m_xFtEndVal->set_sensitive(false);
256 m_xEdEndVal->set_sensitive(false);
257 }
258}
259
261{
262 if ( m_xBtnLeft->get_active() ) theFillDir = FILL_TO_LEFT;
263 else if ( m_xBtnRight->get_active() ) theFillDir = FILL_TO_RIGHT;
264 else if ( m_xBtnDown->get_active() ) theFillDir = FILL_TO_BOTTOM;
265 else if ( m_xBtnUp->get_active() ) theFillDir = FILL_TO_TOP;
266
267 if ( m_xBtnArithmetic->get_active() ) theFillCmd = FILL_LINEAR;
268 else if ( m_xBtnGeometric->get_active() ) theFillCmd = FILL_GROWTH;
269 else if ( m_xBtnDate->get_active() ) theFillCmd = FILL_DATE;
270 else if ( m_xBtnAutoFill->get_active() ) theFillCmd = FILL_AUTO;
271
272 if ( m_xBtnDay->get_active() ) theFillDateCmd = FILL_DAY;
273 else if ( m_xBtnDayOfWeek->get_active() ) theFillDateCmd = FILL_WEEKDAY;
274 else if ( m_xBtnMonth->get_active() ) theFillDateCmd = FILL_MONTH;
275 else if ( m_xBtnYear->get_active() ) theFillDateCmd = FILL_YEAR;
276
277 weld::Entry* pEdWrong = CheckValues();
278 if ( pEdWrong == nullptr )
279 {
280 m_xDialog->response(RET_OK);
281 }
282 else
283 {
284 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning,
285 VclButtonsType::Ok, aErrMsgInvalidVal));
286 xBox->run();
287 pEdWrong->grab_focus();
288 }
289}
290
291/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:44
Reference< XExecutableDialog > m_xDialog
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:467
const SCSIZE m_nSelectHeight
Definition: filldlg.hxx:65
void SetEdStartValEnabled(bool bFlag)
Definition: filldlg.cxx:84
std::unique_ptr< weld::RadioButton > m_xBtnYear
Definition: filldlg.hxx:90
const OUString aStartStrVal
Definition: filldlg.hxx:55
double fIncrement
Definition: filldlg.hxx:63
std::unique_ptr< weld::RadioButton > m_xBtnAutoFill
Definition: filldlg.hxx:84
std::unique_ptr< weld::RadioButton > m_xBtnDay
Definition: filldlg.hxx:87
std::unique_ptr< weld::Entry > m_xEdIncrement
Definition: filldlg.hxx:75
std::unique_ptr< weld::RadioButton > m_xBtnArithmetic
Definition: filldlg.hxx:81
std::unique_ptr< weld::RadioButton > m_xBtnLeft
Definition: filldlg.hxx:79
std::unique_ptr< weld::RadioButton > m_xBtnUp
Definition: filldlg.hxx:78
void Init(sal_uInt16 nPossDir)
Definition: filldlg.cxx:98
FillDateCmd theFillDateCmd
Definition: filldlg.hxx:61
std::unique_ptr< weld::RadioButton > m_xBtnGeometric
Definition: filldlg.hxx:82
double fEndVal
Definition: filldlg.hxx:64
FillCmd theFillCmd
Definition: filldlg.hxx:60
double fStartVal
Definition: filldlg.hxx:62
const SCSIZE m_nSelectWidth
Definition: filldlg.hxx:66
std::unique_ptr< weld::RadioButton > m_xBtnDown
Definition: filldlg.hxx:76
std::unique_ptr< weld::RadioButton > m_xBtnMonth
Definition: filldlg.hxx:89
std::unique_ptr< weld::Entry > m_xEdEndVal
Definition: filldlg.hxx:72
std::unique_ptr< weld::RadioButton > m_xBtnRight
Definition: filldlg.hxx:77
FillDir theFillDir
Definition: filldlg.hxx:59
std::unique_ptr< weld::Label > m_xFtStartVal
Definition: filldlg.hxx:68
std::unique_ptr< weld::RadioButton > m_xBtnDate
Definition: filldlg.hxx:83
ScDocument & rDoc
Definition: filldlg.hxx:58
std::unique_ptr< weld::RadioButton > m_xBtnDayOfWeek
Definition: filldlg.hxx:88
std::unique_ptr< weld::Entry > m_xEdStartVal
Definition: filldlg.hxx:69
weld::Entry * CheckValues()
Definition: filldlg.cxx:182
std::unique_ptr< weld::Button > m_xBtnOk
Definition: filldlg.hxx:92
ScFillSeriesDlg(weld::Window *pParent, ScDocument &rDocument, FillDir eFillDir, FillCmd eFillCmd, FillDateCmd eFillDateCmd, OUString aStartStr, double fStep, double fMax, SCSIZE nSelectHeight, SCSIZE nSelectWidth, sal_uInt16 nPossDir)
Definition: filldlg.cxx:34
virtual ~ScFillSeriesDlg() override
Definition: filldlg.cxx:80
void GetInputLineString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &rOutString, bool bFiltering=false, bool bForceSystemLocale=false)
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
virtual void grab_focus()=0
IMPL_LINK(ScFillSeriesDlg, DisableHdl, weld::Toggleable &, rBtn, void)
Definition: filldlg.cxx:225
IMPL_LINK_NOARG(ScFillSeriesDlg, OKHdl, weld::Button &, void)
Definition: filldlg.cxx:260
FillDateCmd
Definition: global.hxx:334
@ FILL_MONTH
Definition: global.hxx:337
@ FILL_YEAR
Definition: global.hxx:339
@ FILL_WEEKDAY
Definition: global.hxx:336
@ FILL_DAY
Definition: global.hxx:335
#define MAXDOUBLE
Definition: global.hxx:77
FillCmd
Definition: global.hxx:317
@ FILL_GROWTH
Definition: global.hxx:320
@ FILL_LINEAR
Definition: global.hxx:319
@ FILL_AUTO
Definition: global.hxx:322
@ FILL_DATE
Definition: global.hxx:321
FillDir
Definition: global.hxx:309
@ FILL_TO_TOP
Definition: global.hxx:312
@ FILL_TO_RIGHT
Definition: global.hxx:311
@ FILL_TO_LEFT
Definition: global.hxx:313
@ FILL_TO_BOTTOM
Definition: global.hxx:310
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
#define FDS_OPT_VERT
Definition: scui_def.hxx:29
#define FDS_OPT_NONE
Definition: scui_def.hxx:27
#define FDS_OPT_HORZ
Definition: scui_def.hxx:28
RET_OK