tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / miscdlgs / filldlg.cxx
blob38cfb3782b32a190ef6b433e10988413c6e59aa6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include <svl/numformat.hxx>
23 #include <utility>
24 #include <vcl/svapp.hxx>
25 #include <vcl/weld.hxx>
27 #include <scresid.hxx>
28 #include <document.hxx>
29 #include <strings.hrc>
30 #include <filldlg.hxx>
31 #include <scui_def.hxx>
34 ScFillSeriesDlg::ScFillSeriesDlg( weld::Window* pParent,
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, u"modules/scalc/ui/filldlg.ui"_ustr, u"FillSeriesDialog"_ustr)
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(u"startL"_ustr))
57 , m_xEdStartVal(m_xBuilder->weld_entry(u"startValue"_ustr))
58 , m_xFtEndVal(m_xBuilder->weld_label(u"endL"_ustr))
59 , m_xEdEndVal(m_xBuilder->weld_entry(u"endValue"_ustr))
60 , m_xFtIncrement(m_xBuilder->weld_label(u"incrementL"_ustr))
61 , m_xEdIncrement(m_xBuilder->weld_entry(u"increment"_ustr))
62 , m_xBtnDown(m_xBuilder->weld_radio_button(u"down"_ustr))
63 , m_xBtnRight(m_xBuilder->weld_radio_button(u"right"_ustr))
64 , m_xBtnUp(m_xBuilder->weld_radio_button(u"up"_ustr))
65 , m_xBtnLeft(m_xBuilder->weld_radio_button(u"left"_ustr))
66 , m_xBtnArithmetic(m_xBuilder->weld_radio_button(u"linear"_ustr))
67 , m_xBtnGeometric(m_xBuilder->weld_radio_button(u"growth"_ustr))
68 , m_xBtnDate(m_xBuilder->weld_radio_button(u"date"_ustr))
69 , m_xBtnAutoFill(m_xBuilder->weld_radio_button(u"autofill"_ustr))
70 , m_xFtTimeUnit(m_xBuilder->weld_label(u"tuL"_ustr))
71 , m_xBtnDay(m_xBuilder->weld_radio_button(u"day"_ustr))
72 , m_xBtnDayOfWeek(m_xBuilder->weld_radio_button(u"week"_ustr))
73 , m_xBtnMonth(m_xBuilder->weld_radio_button(u"month"_ustr))
74 , m_xBtnYear(m_xBuilder->weld_radio_button(u"year"_ustr))
75 , m_xBtnOk(m_xBuilder->weld_button(u"ok"_ustr))
77 Init(nPossDir);
80 ScFillSeriesDlg::~ScFillSeriesDlg()
84 void ScFillSeriesDlg::SetEdStartValEnabled(bool bFlag)
86 if(bFlag)
88 m_xFtStartVal->set_sensitive(true);
89 m_xEdStartVal->set_sensitive(true);
91 else
93 m_xFtStartVal->set_sensitive(false);
94 m_xEdStartVal->set_sensitive(false);
98 void ScFillSeriesDlg::Init( sal_uInt16 nPossDir )
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 ) );
106 if( nPossDir == FDS_OPT_NONE )
108 m_xBtnLeft->set_sensitive(false);
109 m_xBtnRight->set_sensitive(false);
110 m_xBtnDown->set_sensitive(false);
111 m_xBtnUp->set_sensitive(false);
114 if( nPossDir == FDS_OPT_HORZ )
116 m_xBtnDown->set_sensitive(false);
117 m_xBtnUp->set_sensitive(false);
120 if( nPossDir == FDS_OPT_VERT )
122 m_xBtnLeft->set_sensitive(false);
123 m_xBtnRight->set_sensitive(false);
126 switch ( theFillDir )
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;
136 switch ( theFillCmd )
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;
158 switch ( theFillDateCmd )
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;
168 fStartVal = MAXDOUBLE;
170 m_xEdStartVal->set_text( aStartStrVal);
172 OUString aIncrTxt = rDoc.GetFormatTable()->GetInputLineString( fIncrement, 0 );
173 m_xEdIncrement->set_text( aIncrTxt );
175 OUString aEndTxt;
176 if ( fEndVal != MAXDOUBLE )
177 aEndTxt = rDoc.GetFormatTable()->GetInputLineString( fEndVal, 0 );
178 m_xEdEndVal->set_text( aEndTxt );
181 weld::Entry* ScFillSeriesDlg::CheckValues()
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;
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();
200 if ( theFillCmd == FILL_LINEAR && !aEndStr.isEmpty()
201 && aStartStr.isEmpty() != aIncStr.isEmpty()
202 && ( ( m_nSelectHeight == 1 ) != ( m_nSelectWidth == 1 ) ) )
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;
211 else
213 if ( aStartStr.isEmpty() || m_xBtnAutoFill->get_active() )
214 fStartVal = MAXDOUBLE;
215 if ( aIncStr.isEmpty() )
216 return m_xEdIncrement.get();
217 if ( aEndStr.isEmpty() )
218 fEndVal = ( fIncrement < 0 ) ? -MAXDOUBLE : MAXDOUBLE;
220 return nullptr;
223 // Handler:
224 IMPL_LINK(ScFillSeriesDlg, DisableHdl, weld::Toggleable&, rBtn, void)
226 if (&rBtn == m_xBtnDate.get())
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);
234 else
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);
243 if (&rBtn != m_xBtnAutoFill.get())
245 m_xFtIncrement->set_sensitive(true);
246 m_xEdIncrement->set_sensitive(true);
247 m_xFtEndVal->set_sensitive(true);
248 m_xEdEndVal->set_sensitive(true);
250 else
252 m_xFtIncrement->set_sensitive(false);
253 m_xEdIncrement->set_sensitive(false);
254 m_xFtEndVal->set_sensitive(false);
255 m_xEdEndVal->set_sensitive(false);
259 IMPL_LINK_NOARG(ScFillSeriesDlg, OKHdl, weld::Button&, void)
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;
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;
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;
276 weld::Entry* pEdWrong = CheckValues();
277 if ( pEdWrong == nullptr )
279 m_xDialog->response(RET_OK);
281 else
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();
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */