1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "tp_Scale.hxx"
#include "ResId.hxx"
#include "Strings.hrc"
#include "chartview/ChartSfxItemIds.hxx"
#include "AxisHelper.hxx"
#include <svx/svxids.hrc>
#include <rtl/math.hxx>
// header for class SvxDoubleItem
#include <svx/chrtitem.hxx>
// header for class SfxBoolItem
#include <svl/eitem.hxx>
// header for SfxInt32Item
#include <svl/intitem.hxx>
// header for class WarningBox
#include <vcl/msgbox.hxx>
// header for class SvNumberformat
#include <svl/zformat.hxx>
#include <svtools/controldims.hrc>
#include <com/sun/star/chart2/AxisType.hpp>
using namespace ::com::sun::star;
namespace chart
{
namespace
{
void lcl_setValue( FormattedField& rFmtField, double fValue )
{
rFmtField.SetValue( fValue );
rFmtField.SetDefaultValue( fValue );
}
}
ScaleTabPage::ScaleTabPage(Window* pWindow,const SfxItemSet& rInAttrs) :
SfxTabPage(pWindow
, "tp_Scale"
, "modules/schart/ui/tp_Scale.ui"
, rInAttrs),
fMin(0.0),
fMax(0.0),
fStepMain(0.0),
nStepHelp(0),
fOrigin(0.0),
m_nTimeResolution(1),
m_nMainTimeUnit(1),
m_nHelpTimeUnit(1),
m_nAxisType(chart2::AxisType::REALNUMBER),
m_bAllowDateAxis(false),
pNumFormatter(NULL),
m_bShowAxisOrigin(false)
{
get(m_pCbxReverse, "CBX_REVERSE");
get(m_pCbxLogarithm, "CBX_LOGARITHM");
get(m_pLB_AxisType, "LB_AXIS_TYPE");
get(m_pBxType,"boxTYPE");
get(m_pBxMinMax, "gridMINMAX");
get(m_pFmtFldMin, "EDT_MIN");
get(m_pCbxAutoMin, "CBX_AUTO_MIN");
get(m_pFmtFldMax, "EDT_MAX");
get(m_pCbxAutoMax, "CBX_AUTO_MAX");
get(m_pBxResolution, "boxRESOLUTION");
get(m_pLB_TimeResolution, "LB_TIME_RESOLUTION");
get(m_pCbx_AutoTimeResolution, "CBX_AUTO_TIME_RESOLUTION");
get(m_pBxMain, "boxMAIN");
get(m_pFmtFldStepMain, "EDT_STEP_MAIN");
get(m_pMt_MainDateStep, "MT_MAIN_DATE_STEP");
get(m_pLB_MainTimeUnit, "LB_MAIN_TIME_UNIT");
get(m_pCbxAutoStepMain, "CBX_AUTO_STEP_MAIN");
get(m_pBxMinor, "boxMINOR");
get(m_pMtStepHelp, "MT_STEPHELP");
get(m_pLB_HelpTimeUnit, "LB_HELP_TIME_UNIT");
get(m_pCbxAutoStepHelp, "CBX_AUTO_STEP_HELP");
get(m_pTxtHelpCount,"TXT_STEP_HELP_COUNT");
get(m_pTxtHelp,"TXT_STEP_HELP");
get(m_pBxOrigin,"boxORIGIN");
get(m_pFmtFldOrigin, "EDT_ORIGIN");
get(m_pCbxAutoOrigin, "CBX_AUTO_ORIGIN");
m_pCbxAutoMin->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
m_pCbxAutoMax->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
m_pCbxAutoStepMain->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
m_pCbxAutoStepHelp->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
m_pCbxAutoOrigin->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
m_pCbx_AutoTimeResolution->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
m_pLB_AxisType->SetDropDownLineCount(3);
m_pLB_AxisType->SetSelectHdl(LINK(this, ScaleTabPage, SelectAxisTypeHdl));
m_pLB_TimeResolution->SetDropDownLineCount(3);
m_pLB_MainTimeUnit->SetDropDownLineCount(3);
m_pLB_HelpTimeUnit->SetDropDownLineCount(3);
m_pFmtFldMin->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
m_pFmtFldMax->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
m_pFmtFldStepMain->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
m_pFmtFldOrigin->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
HideAllControls();
}
IMPL_LINK( ScaleTabPage, FmtFieldModifiedHdl, FormattedField*, pFmtFied )
{
if( pFmtFied )
pFmtFied->SetDefaultValue( pFmtFied->GetValue() );
return 0;
}
void ScaleTabPage::StateChanged( StateChangedType nType )
{
TabPage::StateChanged( nType );
}
void ScaleTabPage::EnableControls()
{
bool bValueAxis = chart2::AxisType::REALNUMBER == m_nAxisType
|| chart2::AxisType::PERCENT == m_nAxisType
|| chart2::AxisType::DATE == m_nAxisType;
bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
m_pBxType->Show(m_bAllowDateAxis);
m_pCbxLogarithm->Show( bValueAxis && !bDateAxis );
m_pBxMinMax->Show(bValueAxis);
m_pBxMain->Show( bValueAxis );
m_pBxMinor->Show( bValueAxis );
m_pBxOrigin->Show( m_bShowAxisOrigin && bValueAxis );
m_pTxtHelpCount->Show( bValueAxis && !bDateAxis );
m_pTxtHelp->Show( bDateAxis );
m_pBxResolution->Show( bDateAxis );
bool bWasDateAxis = m_pMt_MainDateStep->IsVisible();
if( bWasDateAxis != bDateAxis )
{
//transport value from one to other control
if( bWasDateAxis )
lcl_setValue( *m_pFmtFldStepMain, m_pMt_MainDateStep->GetValue() );
else
m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(m_pFmtFldStepMain->GetValue()) );
}
m_pFmtFldStepMain->Show( bValueAxis && !bDateAxis );
m_pMt_MainDateStep->Show( bDateAxis );
m_pLB_MainTimeUnit->Show( bDateAxis );
m_pLB_HelpTimeUnit->Show( bDateAxis );
EnableValueHdl(m_pCbxAutoMin);
EnableValueHdl(m_pCbxAutoMax);
EnableValueHdl(m_pCbxAutoStepMain);
EnableValueHdl(m_pCbxAutoStepHelp);
EnableValueHdl(m_pCbxAutoOrigin);
EnableValueHdl(m_pCbx_AutoTimeResolution);
}
IMPL_LINK( ScaleTabPage, EnableValueHdl, CheckBox *, pCbx )
{
bool bEnable = pCbx && !pCbx->IsChecked() && pCbx->IsEnabled();
if (pCbx == m_pCbxAutoMin)
{
m_pFmtFldMin->Enable( bEnable );
}
else if (pCbx == m_pCbxAutoMax)
{
m_pFmtFldMax->Enable( bEnable );
}
else if (pCbx == m_pCbxAutoStepMain)
{
m_pFmtFldStepMain->Enable( bEnable );
m_pMt_MainDateStep->Enable( bEnable );
m_pLB_MainTimeUnit->Enable( bEnable );
}
else if (pCbx == m_pCbxAutoStepHelp)
{
m_pMtStepHelp->Enable( bEnable );
m_pLB_HelpTimeUnit->Enable( bEnable );
}
else if (pCbx == m_pCbx_AutoTimeResolution)
{
m_pLB_TimeResolution->Enable( bEnable );
}
else if (pCbx == m_pCbxAutoOrigin)
{
m_pFmtFldOrigin->Enable( bEnable );
}
return 0;
}
enum AxisTypeListBoxEntry
{
TYPE_AUTO=0,
TYPE_TEXT=1,
TYPE_DATE=2
};
IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl)
{
sal_uInt16 nPos = m_pLB_AxisType->GetSelectEntryPos();
if( nPos==TYPE_DATE )
m_nAxisType = chart2::AxisType::DATE;
else
m_nAxisType = chart2::AxisType::CATEGORY;
if( chart2::AxisType::DATE == m_nAxisType )
m_pCbxLogarithm->Check(false);
EnableControls();
SetNumFormat();
return 0;
}
SfxTabPage* ScaleTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
{
return new ScaleTabPage(pWindow, rOutAttrs);
}
sal_Bool ScaleTabPage::FillItemSet(SfxItemSet& rOutAttrs)
{
OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType));
if(m_bAllowDateAxis)
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, TYPE_AUTO==m_pLB_AxisType->GetSelectEntryPos()));
bool bAutoScale = false;
if( m_nAxisType==chart2::AxisType::CATEGORY )
bAutoScale = true;//reset scaling for category charts
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN ,bAutoScale || m_pCbxAutoMin->IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX ,bAutoScale || m_pCbxAutoMax->IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || m_pCbxAutoStepHelp->IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN ,bAutoScale || m_pCbxAutoOrigin->IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM ,m_pCbxLogarithm->IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_REVERSE ,m_pCbxReverse->IsChecked()));
rOutAttrs.Put(SvxDoubleItem(fMax , SCHATTR_AXIS_MAX));
rOutAttrs.Put(SvxDoubleItem(fMin , SCHATTR_AXIS_MIN));
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp));
rOutAttrs.Put(SvxDoubleItem(fOrigin , SCHATTR_AXIS_ORIGIN));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_pCbxAutoStepMain->IsChecked()));
rOutAttrs.Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_pCbx_AutoTimeResolution->IsChecked()));
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,m_nTimeResolution));
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit));
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit));
return sal_True;
}
void ScaleTabPage::Reset(const SfxItemSet& rInAttrs)
{
OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
if(!pNumFormatter)
return;
const SfxPoolItem *pPoolItem = NULL;
if (rInAttrs.GetItemState(SCHATTR_AXIS_ALLOW_DATEAXIS, sal_True, &pPoolItem) == SFX_ITEM_SET)
m_bAllowDateAxis = (bool) ((const SfxBoolItem*)pPoolItem)->GetValue();
m_nAxisType=chart2::AxisType::REALNUMBER;
if (rInAttrs.GetItemState(SCHATTR_AXISTYPE, sal_True, &pPoolItem) == SFX_ITEM_SET)
m_nAxisType = (int) ((const SfxInt32Item*)pPoolItem)->GetValue();
if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis )
m_nAxisType=chart2::AxisType::CATEGORY;
if( m_bAllowDateAxis )
{
bool bAutoDateAxis = false;
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_DATEAXIS, sal_True, &pPoolItem) == SFX_ITEM_SET)
bAutoDateAxis = (bool) ((const SfxBoolItem*)pPoolItem)->GetValue();
sal_uInt16 nPos = 0;
if( m_nAxisType==chart2::AxisType::DATE )
nPos=TYPE_DATE;
else if( bAutoDateAxis )
nPos=TYPE_AUTO;
else
nPos=TYPE_TEXT;
m_pLB_AxisType->SelectEntryPos( nPos );
}
if( m_bAllowDateAxis )
m_pCbxReverse->SetHelpId("chart2:CheckBox:TP_SCALE:CBX_REVERSE:MayBeDateAxis");
else if( m_nAxisType==chart2::AxisType::CATEGORY || m_nAxisType==chart2::AxisType::SERIES )
m_pCbxReverse->SetHelpId("chart2:CheckBox:TP_SCALE:CBX_REVERSE:Category");
m_pCbxAutoMin->Check( true );
m_pCbxAutoMax->Check( true );
m_pCbxAutoStepMain->Check( true );
m_pCbxAutoStepHelp->Check( true );
m_pCbxAutoOrigin->Check( true );
m_pCbx_AutoTimeResolution->Check( true );
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MIN,sal_True,&pPoolItem) == SFX_ITEM_SET)
m_pCbxAutoMin->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_MIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
fMin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
lcl_setValue( *m_pFmtFldMin, fMin );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MAX,sal_True, &pPoolItem) == SFX_ITEM_SET)
m_pCbxAutoMax->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_MAX,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
fMax = ((const SvxDoubleItem*)pPoolItem)->GetValue();
lcl_setValue( *m_pFmtFldMax, fMax );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
m_pCbxAutoStepMain->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_MAIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
fStepMain = ((const SvxDoubleItem*)pPoolItem)->GetValue();
lcl_setValue( *m_pFmtFldStepMain, fStepMain );
m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(fStepMain) );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP,sal_True, &pPoolItem) == SFX_ITEM_SET)
m_pCbxAutoStepHelp->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_LOGARITHM,sal_True, &pPoolItem) == SFX_ITEM_SET)
m_pCbxLogarithm->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_REVERSE,sal_True, &pPoolItem) == SFX_ITEM_SET)
m_pCbxReverse->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_HELP,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
nStepHelp = ((const SfxInt32Item*)pPoolItem)->GetValue();
m_pMtStepHelp->SetValue( nStepHelp );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_ORIGIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
m_pCbxAutoOrigin->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_ORIGIN,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
fOrigin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
lcl_setValue( *m_pFmtFldOrigin, fOrigin );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,sal_True, &pPoolItem) == SFX_ITEM_SET)
m_pCbx_AutoTimeResolution->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_TIME_RESOLUTION,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
m_nTimeResolution = ((const SfxInt32Item*)pPoolItem)->GetValue();
m_pLB_TimeResolution->SelectEntryPos( m_nTimeResolution );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_MAIN_TIME_UNIT,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
m_nMainTimeUnit = ((const SfxInt32Item*)pPoolItem)->GetValue();
m_pLB_MainTimeUnit->SelectEntryPos( m_nMainTimeUnit );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_HELP_TIME_UNIT,sal_True, &pPoolItem) == SFX_ITEM_SET)
{
m_nHelpTimeUnit = ((const SfxInt32Item*)pPoolItem)->GetValue();
m_pLB_HelpTimeUnit->SelectEntryPos( m_nHelpTimeUnit );
}
EnableControls();
SetNumFormat();
}
int ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet)
{
if( !pNumFormatter )
{
OSL_FAIL( "No NumberFormatter available" );
return LEAVE_PAGE;
}
bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
sal_uInt32 nMinMaxOriginFmt = m_pFmtFldMax->GetFormatKey();
if ((pNumFormatter->GetType(nMinMaxOriginFmt) &~ NUMBERFORMAT_DEFINED) == NUMBERFORMAT_TEXT)
nMinMaxOriginFmt = 0;
// numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can.
sal_uInt32 nStepFmt = m_pFmtFldStepMain->GetFormatKey();
if ((pNumFormatter->GetType(nStepFmt) &~NUMBERFORMAT_DEFINED) == NUMBERFORMAT_TEXT)
nStepFmt = 0;
Control* pControl = NULL;
sal_uInt16 nErrStrId = 0;
double fDummy;
fMax = m_pFmtFldMax->GetValue();
fMin = m_pFmtFldMin->GetValue();
fOrigin = m_pFmtFldOrigin->GetValue();
fStepMain = bDateAxis ? m_pMt_MainDateStep->GetValue() : m_pFmtFldStepMain->GetValue();
nStepHelp = static_cast< sal_Int32 >( m_pMtStepHelp->GetValue());
m_nTimeResolution = m_pLB_TimeResolution->GetSelectEntryPos();
m_nMainTimeUnit = m_pLB_MainTimeUnit->GetSelectEntryPos();
m_nHelpTimeUnit = m_pLB_HelpTimeUnit->GetSelectEntryPos();
if( chart2::AxisType::REALNUMBER != m_nAxisType )
m_pCbxLogarithm->Show( false );
//check which entries need user action
if ( m_pCbxLogarithm->IsChecked() &&
( ( !m_pCbxAutoMin->IsChecked() && fMin <= 0.0 )
|| ( !m_pCbxAutoMax->IsChecked() && fMax <= 0.0 ) ) )
{
pControl = m_pFmtFldMin;
nErrStrId = STR_BAD_LOGARITHM;
}
// check for entries that cannot be parsed for the current number format
else if ( m_pFmtFldMin->IsModified()
&& !m_pCbxAutoMin->IsChecked()
&& !pNumFormatter->IsNumberFormat( m_pFmtFldMin->GetText(), nMinMaxOriginFmt, fDummy))
{
pControl = m_pFmtFldMin;
nErrStrId = STR_INVALID_NUMBER;
}
else if ( m_pFmtFldMax->IsModified()
&& !m_pCbxAutoMax->IsChecked()
&& !pNumFormatter->IsNumberFormat( m_pFmtFldMax->GetText(), nMinMaxOriginFmt, fDummy))
{
pControl = m_pFmtFldMax;
nErrStrId = STR_INVALID_NUMBER;
}
else if ( !bDateAxis && m_pFmtFldStepMain->IsModified()
&& !m_pCbxAutoStepMain->IsChecked()
&& !pNumFormatter->IsNumberFormat( m_pFmtFldStepMain->GetText(), nStepFmt, fDummy))
{
pControl = m_pFmtFldStepMain;
nErrStrId = STR_INVALID_NUMBER;
}
else if (m_pFmtFldOrigin->IsModified() && !m_pCbxAutoOrigin->IsChecked() &&
!pNumFormatter->IsNumberFormat( m_pFmtFldOrigin->GetText(), nMinMaxOriginFmt, fDummy))
{
pControl = m_pFmtFldOrigin;
nErrStrId = STR_INVALID_NUMBER;
}
else if (!m_pCbxAutoStepMain->IsChecked() && fStepMain <= 0.0)
{
pControl = m_pFmtFldStepMain;
nErrStrId = STR_STEP_GT_ZERO;
}
else if (!m_pCbxAutoMax->IsChecked() && !m_pCbxAutoMin->IsChecked() &&
fMin >= fMax)
{
pControl = m_pFmtFldMin;
nErrStrId = STR_MIN_GREATER_MAX;
}
else if( bDateAxis )
{
if( !m_pCbxAutoStepMain->IsChecked() && !m_pCbxAutoStepHelp->IsChecked() )
{
if( m_nHelpTimeUnit > m_nMainTimeUnit )
{
pControl = m_pLB_MainTimeUnit;
nErrStrId = STR_INVALID_INTERVALS;
}
else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain )
{
pControl = m_pLB_MainTimeUnit;
nErrStrId = STR_INVALID_INTERVALS;
}
}
if( !nErrStrId && !m_pCbx_AutoTimeResolution->IsChecked() )
{
if( (!m_pCbxAutoStepMain->IsChecked() && m_nTimeResolution > m_nMainTimeUnit )
||
(!m_pCbxAutoStepHelp->IsChecked() && m_nTimeResolution > m_nHelpTimeUnit )
)
{
pControl = m_pLB_TimeResolution;
nErrStrId = STR_INVALID_TIME_UNIT;
}
}
}
if( ShowWarning( nErrStrId, pControl ) )
return KEEP_PAGE;
if( pItemSet )
FillItemSet( *pItemSet );
return LEAVE_PAGE;
}
void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
{
pNumFormatter = pFormatter;
m_pFmtFldMax->SetFormatter( pNumFormatter );
m_pFmtFldMin->SetFormatter( pNumFormatter );
m_pFmtFldStepMain->SetFormatter( pNumFormatter );
m_pFmtFldOrigin->SetFormatter( pNumFormatter );
// #i6278# allow more decimal places than the output format. As
// the numbers shown in the edit fields are used for input, it makes more
// sense to display the values in the input format rather than the output
// format.
m_pFmtFldMax->UseInputStringForFormatting();
m_pFmtFldMin->UseInputStringForFormatting();
m_pFmtFldStepMain->UseInputStringForFormatting();
m_pFmtFldOrigin->UseInputStringForFormatting();
SetNumFormat();
}
void ScaleTabPage::SetNumFormat()
{
const SfxPoolItem *pPoolItem = NULL;
if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, sal_True, &pPoolItem ) == SFX_ITEM_SET )
{
sal_uLong nFmt = (sal_uLong)((const SfxInt32Item*)pPoolItem)->GetValue();
m_pFmtFldMax->SetFormatKey( nFmt );
m_pFmtFldMin->SetFormatKey( nFmt );
m_pFmtFldOrigin->SetFormatKey( nFmt );
if( pNumFormatter )
{
short eType = pNumFormatter->GetType( nFmt );
if( eType == NUMBERFORMAT_DATE )
{
// for intervals use standard format for dates (so you can enter a number of days)
const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
if( pFormat )
nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
else
nFmt = pNumFormatter->GetStandardIndex();
}
else if( eType == NUMBERFORMAT_DATETIME )
{
// for intervals use time format for date times
const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
if( pFormat )
nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_TIME, pFormat->GetLanguage() );
else
nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_TIME );
}
if( chart2::AxisType::DATE == m_nAxisType && ( eType != NUMBERFORMAT_DATE && eType != NUMBERFORMAT_DATETIME) )
{
const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
if( pFormat )
nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_DATE, pFormat->GetLanguage() );
else
nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_DATE );
m_pFmtFldMax->SetFormatKey( nFmt );
m_pFmtFldMin->SetFormatKey( nFmt );
m_pFmtFldOrigin->SetFormatKey( nFmt );
}
}
m_pFmtFldStepMain->SetFormatKey( nFmt );
}
}
void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
{
m_bShowAxisOrigin = bShowOrigin;
if( !AxisHelper::isAxisPositioningEnabled() )
m_bShowAxisOrigin = true;
}
bool ScaleTabPage::ShowWarning( sal_uInt16 nResIdMessage, Control* pControl /* = NULL */ )
{
if( nResIdMessage == 0 )
return false;
WarningBox( this, WinBits( WB_OK ), SCH_RESSTR( nResIdMessage ) ).Execute();
if( pControl )
{
pControl->GrabFocus();
Edit* pEdit = dynamic_cast<Edit*>(pControl);
if(pEdit)
pEdit->SetSelection( Selection( 0, SELECTION_MAX ));
}
return true;
}
void ScaleTabPage::HideAllControls()
{
// We need to set these controls invisible when the class is instantiated
// since some code in EnableControls() depends on that logic. The real
// visibility of these controls depend on axis data type, and are
// set in EnableControls().
m_pBxType->Hide();
m_pCbxLogarithm->Hide();
m_pBxMinMax->Hide();
m_pBxMain->Hide();
m_pBxMinor->Hide();
m_pBxOrigin->Hide();
m_pBxResolution->Hide();
}
} //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|