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