1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
31 #include "scresid.hxx"
32 #include "document.hxx"
33 #include "globstr.hrc"
34 #include "miscdlgs.hrc"
37 #include "filldlg.hxx"
42 //============================================================================
43 // class ScFillSeriesDlg
45 //----------------------------------------------------------------------------
47 ScFillSeriesDlg::ScFillSeriesDlg( Window
* pParent
,
48 ScDocument
& rDocument
,
51 FillDateCmd eFillDateCmd
,
52 const OUString
& aStartStr
,
56 : ModalDialog(pParent
, "FillSeriesDialog", "modules/scalc/ui/filldlg.ui"),
57 aStartStrVal ( aStartStr
),
58 aErrMsgInvalidVal( SC_RESSTR(SCSTR_VALERR
) ),
60 theFillDir ( eFillDir
),
61 theFillCmd ( eFillCmd
),
62 theFillDateCmd ( eFillDateCmd
),
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");
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");
91 //----------------------------------------------------------------------------
93 ScFillSeriesDlg::~ScFillSeriesDlg()
97 //----------------------------------------------------------------------------
99 void ScFillSeriesDlg::SetEdStartValEnabled(bool bFlag
)
104 m_pFtStartVal
->Enable();
105 m_pEdStartVal
->Enable();
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();
132 if( nPossDir
== FDS_OPT_HORZ
)
134 m_pBtnDown
->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;
154 switch ( theFillCmd
)
157 m_pBtnArithmetic
->Check();
158 DisableHdl( m_pBtnArithmetic
);
161 m_pBtnGeometric
->Check();
162 DisableHdl( m_pBtnGeometric
);
166 DisableHdl( m_pBtnDate
);
169 m_pBtnAutoFill
->Check();
170 DisableHdl( m_pBtnAutoFill
);
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;
186 fStartVal
= MAXDOUBLE
;
188 m_pEdStartVal
->SetText( aStartStrVal
);
191 rDoc
.GetFormatTable()->GetInputLineString( fIncrement
, 0, aIncrTxt
);
192 m_pEdIncrement
->SetText( aIncrTxt
);
195 if ( fEndVal
!= MAXDOUBLE
)
196 rDoc
.GetFormatTable()->GetInputLineString( fEndVal
, 0, aEndTxt
);
197 m_pEdEndVal
->SetText( aEndTxt
);
199 bStartValFlag
= false;
203 //----------------------------------------------------------------------------
205 bool ScFillSeriesDlg::CheckStartVal()
208 OUString aStr
= m_pEdStartVal
->GetText();
210 if ( aStr
.isEmpty() || m_pBtnAutoFill
->IsChecked())
212 fStartVal
= MAXDOUBLE
;
218 bValOk
= rDoc
.GetFormatTable()->IsNumberFormat( aStr
, nKey
, fStartVal
);
224 //----------------------------------------------------------------------------
226 bool ScFillSeriesDlg::CheckIncrementVal()
229 OUString aStr
= m_pEdIncrement
->GetText();
231 return rDoc
.GetFormatTable()->IsNumberFormat( aStr
, nKey
, fIncrement
);
235 //----------------------------------------------------------------------------
237 bool ScFillSeriesDlg::CheckEndVal()
240 OUString aStr
= m_pEdEndVal
->GetText();
244 fEndVal
= (fIncrement
< 0) ? -MAXDOUBLE
: MAXDOUBLE
;
250 bValOk
= rDoc
.GetFormatTable()->IsNumberFormat( aStr
, nKey
, fEndVal
);
256 //----------------------------------------------------------------------------
258 //----------------------------------------------------------------------------
260 IMPL_LINK( ScFillSeriesDlg
, DisableHdl
, Button
*, pBtn
)
262 if ( pBtn
== m_pBtnDate
)
265 m_pBtnDayOfWeek
->Enable();
266 m_pBtnMonth
->Enable();
267 m_pBtnYear
->Enable();
268 m_pFtTimeUnit
->Enable();
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();
288 m_pFtIncrement
->Disable();
289 m_pEdIncrement
->Disable();
290 m_pFtEndVal
->Disable();
291 m_pEdEndVal
->Disable();
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() )
321 pEdWrong
= m_pEdStartVal
;
323 else if ( !CheckIncrementVal() )
326 pEdWrong
= m_pEdIncrement
;
328 else if ( !CheckEndVal() )
331 pEdWrong
= m_pEdEndVal
;
338 WinBits( WB_OK
| WB_DEF_OK
),
341 pEdWrong
->GrabFocus();
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */