Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / miscdlgs / filldlg.cxx
blob1e28222655f5cfa6229c4a45e96f5fc9e7151da0
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 .
21 #undef SC_DLLIMPLEMENTATION
25 //----------------------------------------------------------------------------
27 #include <svl/zforlist.hxx>
28 #include <vcl/msgbox.hxx>
29 #include <limits.h>
31 #include "scresid.hxx"
32 #include "document.hxx"
33 #include "globstr.hrc"
34 #include "miscdlgs.hrc"
36 #define _FILLDLG_CXX
37 #include "filldlg.hxx"
38 #undef _FILLDLG_CXX
42 //============================================================================
43 // class ScFillSeriesDlg
45 //----------------------------------------------------------------------------
47 ScFillSeriesDlg::ScFillSeriesDlg( Window* pParent,
48 ScDocument& rDocument,
49 FillDir eFillDir,
50 FillCmd eFillCmd,
51 FillDateCmd eFillDateCmd,
52 const OUString& aStartStr,
53 double fStep,
54 double fMax,
55 sal_uInt16 nPossDir )
56 : ModalDialog(pParent, "FillSeriesDialog", "modules/scalc/ui/filldlg.ui"),
57 aStartStrVal ( aStartStr),
58 aErrMsgInvalidVal( SC_RESSTR(SCSTR_VALERR) ),
59 rDoc ( rDocument ),
60 theFillDir ( eFillDir ),
61 theFillCmd ( eFillCmd ),
62 theFillDateCmd ( eFillDateCmd ),
63 fIncrement ( fStep ),
64 fEndVal ( fMax )
66 get(m_pFtStartVal, "startL");
67 get(m_pEdStartVal, "startValue");
68 get(m_pFtEndVal, "endL");
69 get(m_pEdEndVal, "endValue");
70 get(m_pFtIncrement, "incrementL");
71 get(m_pEdIncrement, "increment");
72 get(m_pBtnDown, "down");
73 get(m_pBtnRight, "right");
74 get(m_pBtnUp, "up");
75 get(m_pBtnLeft, "left");
76 get(m_pBtnArithmetic, "linear");
77 get(m_pBtnGeometric, "growth");
78 get(m_pBtnDate, "date");
79 get(m_pBtnAutoFill, "autofill");
80 get(m_pFtTimeUnit, "tuL");
81 get(m_pBtnDay, "day");
82 get(m_pBtnDayOfWeek, "week");
83 get(m_pBtnMonth, "month");
84 get(m_pBtnYear, "year");
85 get(m_pBtnOk, "ok");
87 Init( nPossDir );
91 //----------------------------------------------------------------------------
93 ScFillSeriesDlg::~ScFillSeriesDlg()
97 //----------------------------------------------------------------------------
99 void ScFillSeriesDlg::SetEdStartValEnabled(bool bFlag)
101 bStartValFlag=bFlag;
102 if(bFlag)
104 m_pFtStartVal->Enable();
105 m_pEdStartVal->Enable();
107 else
109 m_pFtStartVal->Disable();
110 m_pEdStartVal->Disable();
114 //----------------------------------------------------------------------------
116 void ScFillSeriesDlg::Init( sal_uInt16 nPossDir )
118 m_pBtnOk->SetClickHdl ( LINK( this, ScFillSeriesDlg, OKHdl ) );
119 m_pBtnArithmetic->SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
120 m_pBtnGeometric->SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
121 m_pBtnDate->SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
122 m_pBtnAutoFill->SetClickHdl ( LINK( this, ScFillSeriesDlg, DisableHdl ) );
124 if( nPossDir == FDS_OPT_NONE )
126 m_pBtnLeft->Disable();
127 m_pBtnRight->Disable();
128 m_pBtnDown->Disable();
129 m_pBtnUp->Disable();
132 if( nPossDir == FDS_OPT_HORZ )
134 m_pBtnDown->Disable();
135 m_pBtnUp->Disable();
138 if( nPossDir == FDS_OPT_VERT )
140 m_pBtnLeft->Disable();
141 m_pBtnRight->Disable();
144 switch ( theFillDir )
146 case FILL_TO_LEFT: m_pBtnLeft->Check(); break;
147 case FILL_TO_RIGHT: m_pBtnRight->Check(); break;
148 case FILL_TO_BOTTOM: m_pBtnDown->Check(); break;
149 case FILL_TO_TOP: m_pBtnUp->Check(); break;
150 default:
151 break;
154 switch ( theFillCmd )
156 case FILL_LINEAR:
157 m_pBtnArithmetic->Check();
158 DisableHdl( m_pBtnArithmetic );
159 break;
160 case FILL_GROWTH:
161 m_pBtnGeometric->Check();
162 DisableHdl( m_pBtnGeometric );
163 break;
164 case FILL_DATE:
165 m_pBtnDate->Check();
166 DisableHdl( m_pBtnDate );
167 break;
168 case FILL_AUTO:
169 m_pBtnAutoFill->Check();
170 DisableHdl( m_pBtnAutoFill );
171 break;
172 default:
173 break;
176 switch ( theFillDateCmd )
178 case FILL_DAY: m_pBtnDay->Check(); break;
179 case FILL_WEEKDAY: m_pBtnDayOfWeek->Check(); break;
180 case FILL_MONTH: m_pBtnMonth->Check(); break;
181 case FILL_YEAR: m_pBtnYear->Check(); break;
182 default:
183 break;
186 fStartVal = MAXDOUBLE;
188 m_pEdStartVal->SetText( aStartStrVal);
190 OUString aIncrTxt;
191 rDoc.GetFormatTable()->GetInputLineString( fIncrement, 0, aIncrTxt );
192 m_pEdIncrement->SetText( aIncrTxt );
194 OUString aEndTxt;
195 if ( fEndVal != MAXDOUBLE )
196 rDoc.GetFormatTable()->GetInputLineString( fEndVal, 0, aEndTxt );
197 m_pEdEndVal->SetText( aEndTxt );
199 bStartValFlag = false;
203 //----------------------------------------------------------------------------
205 bool ScFillSeriesDlg::CheckStartVal()
207 bool bValOk = false;
208 OUString aStr = m_pEdStartVal->GetText();
210 if ( aStr.isEmpty() || m_pBtnAutoFill->IsChecked())
212 fStartVal = MAXDOUBLE;
213 bValOk = true;
215 else
217 sal_uInt32 nKey = 0;
218 bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fStartVal );
220 return bValOk;
224 //----------------------------------------------------------------------------
226 bool ScFillSeriesDlg::CheckIncrementVal()
228 sal_uInt32 nKey = 0;
229 OUString aStr = m_pEdIncrement->GetText();
231 return rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fIncrement );
235 //----------------------------------------------------------------------------
237 bool ScFillSeriesDlg::CheckEndVal()
239 bool bValOk = false;
240 OUString aStr = m_pEdEndVal->GetText();
242 if (aStr.isEmpty())
244 fEndVal = (fIncrement < 0) ? -MAXDOUBLE : MAXDOUBLE;
245 bValOk = true;
247 else
249 sal_uInt32 nKey = 0;
250 bValOk = rDoc.GetFormatTable()->IsNumberFormat( aStr, nKey, fEndVal );
252 return bValOk;
256 //----------------------------------------------------------------------------
257 // Handler:
258 //----------------------------------------------------------------------------
260 IMPL_LINK( ScFillSeriesDlg, DisableHdl, Button *, pBtn )
262 if ( pBtn == m_pBtnDate )
264 m_pBtnDay->Enable();
265 m_pBtnDayOfWeek->Enable();
266 m_pBtnMonth->Enable();
267 m_pBtnYear->Enable();
268 m_pFtTimeUnit->Enable();
270 else
272 m_pBtnDay->Disable();
273 m_pBtnDayOfWeek->Disable();
274 m_pBtnMonth->Disable();
275 m_pBtnYear->Disable();
276 m_pFtTimeUnit->Disable();
279 if ( pBtn != m_pBtnAutoFill )
281 m_pFtIncrement->Enable();
282 m_pEdIncrement->Enable();
283 m_pFtEndVal->Enable();
284 m_pEdEndVal->Enable();
286 else
288 m_pFtIncrement->Disable();
289 m_pEdIncrement->Disable();
290 m_pFtEndVal->Disable();
291 m_pEdEndVal->Disable();
293 return 0;
297 //----------------------------------------------------------------------------
299 IMPL_LINK_NOARG(ScFillSeriesDlg, OKHdl)
301 if ( m_pBtnLeft->IsChecked() ) theFillDir = FILL_TO_LEFT;
302 else if ( m_pBtnRight->IsChecked() ) theFillDir = FILL_TO_RIGHT;
303 else if ( m_pBtnDown->IsChecked() ) theFillDir = FILL_TO_BOTTOM;
304 else if ( m_pBtnUp->IsChecked() ) theFillDir = FILL_TO_TOP;
306 if ( m_pBtnArithmetic->IsChecked() ) theFillCmd = FILL_LINEAR;
307 else if ( m_pBtnGeometric->IsChecked() ) theFillCmd = FILL_GROWTH;
308 else if ( m_pBtnDate->IsChecked() ) theFillCmd = FILL_DATE;
309 else if ( m_pBtnAutoFill->IsChecked() ) theFillCmd = FILL_AUTO;
311 if ( m_pBtnDay->IsChecked() ) theFillDateCmd = FILL_DAY;
312 else if ( m_pBtnDayOfWeek->IsChecked() ) theFillDateCmd = FILL_WEEKDAY;
313 else if ( m_pBtnMonth->IsChecked() ) theFillDateCmd = FILL_MONTH;
314 else if ( m_pBtnYear->IsChecked() ) theFillDateCmd = FILL_YEAR;
316 sal_Bool bAllOk = true;
317 Edit* pEdWrong = NULL;
318 if ( !CheckStartVal() )
320 bAllOk = false;
321 pEdWrong = m_pEdStartVal;
323 else if ( !CheckIncrementVal() )
325 bAllOk = false;
326 pEdWrong = m_pEdIncrement;
328 else if ( !CheckEndVal() )
330 bAllOk = false;
331 pEdWrong = m_pEdEndVal;
333 if ( bAllOk )
334 EndDialog( RET_OK );
335 else
337 ErrorBox( this,
338 WinBits( WB_OK | WB_DEF_OK ),
339 aErrMsgInvalidVal
340 ).Execute();
341 pEdWrong->GrabFocus();
344 return 0;
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */