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
|
/* -*- 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/.
*/
#include "colorformat.hxx"
#include "colorscale.hxx"
#include "document.hxx"
#include "sc.hrc"
#include <svx/xtable.hxx>
#include <svx/drawitem.hxx>
#include <vcl/msgbox.hxx>
namespace {
void SetType(const ScColorScaleEntry* pEntry, ListBox& rLstBox)
{
rLstBox.SelectEntryPos(pEntry->GetType());
}
void GetType(const ListBox& rLstBox, const Edit& rEd, ScColorScaleEntry* pEntry, SvNumberFormatter* pNumberFormatter,
ScDocument* pDoc, const ScAddress& rPos )
{
double nVal = 0;
sal_uInt32 nIndex = 0;
pEntry->SetType(static_cast<ScColorScaleEntryType>(rLstBox.GetSelectEntryPos()));
switch(rLstBox.GetSelectEntryPos())
{
case COLORSCALE_AUTO:
case COLORSCALE_MIN:
case COLORSCALE_MAX:
break;
case COLORSCALE_PERCENTILE:
case COLORSCALE_VALUE:
case COLORSCALE_PERCENT:
(void)pNumberFormatter->IsNumberFormat( rEd.GetText(), nIndex, nVal );
pEntry->SetValue(nVal);
break;
case COLORSCALE_FORMULA:
pEntry->SetFormula(rEd.GetText(), pDoc, rPos);
break;
}
}
OUString convertNumberToString(double nVal, ScDocument* pDoc)
{
SvNumberFormatter* pNumberFormatter = pDoc->GetFormatTable();
OUString aText;
pNumberFormatter->GetInputLineString(nVal, 0, aText);
return aText;
}
void SetValue( ScDocument* pDoc, ScColorScaleEntry* pEntry, Edit& aEdit)
{
if(pEntry->GetType() == COLORSCALE_FORMULA)
aEdit.SetText(pEntry->GetFormula(formula::FormulaGrammar::GRAM_DEFAULT));
else if(pEntry->GetType() != COLORSCALE_MIN && pEntry->GetType() != COLORSCALE_MAX)
aEdit.SetText(convertNumberToString(pEntry->GetValue(), pDoc));
else
aEdit.Disable();
}
}
ScDataBarSettingsDlg::ScDataBarSettingsDlg(vcl::Window* pWindow, const ScDataBarFormatData& rData, ScDocument* pDoc, const ScAddress& rPos):
ModalDialog( pWindow, "DataBarOptions", "modules/scalc/ui/databaroptions.ui" ),
mpNumberFormatter( pDoc->GetFormatTable() ),
mpDoc(pDoc),
maPos(rPos)
{
get( mpBtnOk, "ok");
get( mpBtnCancel, "cancel" );
get( mpLbPos, "positive_colour" );
get( mpLbNeg, "negative_colour" );
get( mpLbFillType, "fill_type" );
get( mpLbTypeMin, "min" );
get( mpLbTypeMax, "max" );
get( mpLbAxisPos, "axis_pos" );
get( mpLbAxisCol, "axis_colour" );
get( mpEdMin, "min_value" );
get( mpEdMax, "max_value" );
get( mpLenMin, "min_length" );
get( mpLenMax, "max_length" );
get( mpCbOnlyBar, "only_bar");
maStrWarnSameValue = get<FixedText>("str_same_value")->GetText();
Init();
mpLbPos->SelectEntry( rData.maPositiveColor );
mpLbFillType->SelectEntryPos( rData.mbGradient ? 1 : 0 );
if(rData.mpNegativeColor)
mpLbNeg->SelectEntry( *rData.mpNegativeColor );
switch (rData.meAxisPosition)
{
case databar::NONE:
mpLbAxisPos->SelectEntryPos(2);
break;
case databar::AUTOMATIC:
mpLbAxisPos->SelectEntryPos(0);
break;
case databar::MIDDLE:
mpLbAxisPos->SelectEntryPos(1);
break;
}
::SetType(rData.mpLowerLimit.get(), *mpLbTypeMin);
::SetType(rData.mpUpperLimit.get(), *mpLbTypeMax);
SetValue(mpDoc, rData.mpLowerLimit.get(), *mpEdMin);
SetValue(mpDoc, rData.mpUpperLimit.get(), *mpEdMax);
mpLenMin->SetText(convertNumberToString(rData.mnMinLength, mpDoc));
mpLenMax->SetText(convertNumberToString(rData.mnMaxLength, mpDoc));
mpLbAxisCol->SelectEntry(rData.maAxisColor);
mpCbOnlyBar->Check(rData.mbOnlyBar);
TypeSelectHdl(NULL);
PosSelectHdl(NULL);
}
ScDataBarSettingsDlg::~ScDataBarSettingsDlg()
{
disposeOnce();
}
void ScDataBarSettingsDlg::dispose()
{
mpBtnOk.clear();
mpBtnCancel.clear();
mpLbPos.clear();
mpLbNeg.clear();
mpLbAxisCol.clear();
mpLbTypeMin.clear();
mpLbTypeMax.clear();
mpLbFillType.clear();
mpLbAxisPos.clear();
mpEdMin.clear();
mpEdMax.clear();
mpLenMin.clear();
mpLenMax.clear();
mpCbOnlyBar.clear();
ModalDialog::dispose();
}
void ScDataBarSettingsDlg::Init()
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
XColorListRef pColorTable;
DBG_ASSERT( pDocSh, "DocShell not found!" );
if ( pDocSh )
{
const SfxPoolItem* pItem = pDocSh->GetItem( SID_COLOR_TABLE );
if ( pItem != NULL )
pColorTable = static_cast<const SvxColorListItem*>(pItem)->GetColorList();
}
if ( pColorTable.is() )
{
// filling the line color box
mpLbPos->SetUpdateMode( false );
mpLbNeg->SetUpdateMode( false );
mpLbAxisCol->SetUpdateMode( false );
for ( long i = 0; i < pColorTable->Count(); ++i )
{
XColorEntry* pEntry = pColorTable->GetColor(i);
mpLbPos->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
mpLbNeg->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
mpLbAxisCol->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
if(pEntry->GetColor() == Color(COL_LIGHTRED))
mpLbNeg->SelectEntryPos(i);
if(pEntry->GetColor() == Color(COL_BLACK))
mpLbAxisCol->SelectEntryPos(i);
if(pEntry->GetColor() == Color(COL_LIGHTBLUE))
mpLbPos->SelectEntryPos(i);
}
mpLbPos->SetUpdateMode( true );
mpLbNeg->SetUpdateMode( true );
mpLbAxisCol->SetUpdateMode( true );
}
mpBtnOk->SetClickHdl( LINK( this, ScDataBarSettingsDlg, OkBtnHdl ) );
mpLbTypeMin->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
mpLbTypeMax->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, TypeSelectHdl ) );
mpLbAxisPos->SetSelectHdl( LINK( this, ScDataBarSettingsDlg, PosSelectHdl ) );
}
namespace {
void GetAxesPosition(ScDataBarFormatData* pData, const ListBox* rLbox)
{
switch(rLbox->GetSelectEntryPos())
{
case 0:
pData->meAxisPosition = databar::AUTOMATIC;
break;
case 1:
pData->meAxisPosition = databar::MIDDLE;
break;
case 2:
pData->meAxisPosition = databar::NONE;
break;
}
}
void SetBarLength(ScDataBarFormatData* pData, const OUString& minStr, const OUString& maxStr, SvNumberFormatter* mpNumberFormatter)
{
double nMinValue = 0;
sal_uInt32 nIndex = 0;
(void)mpNumberFormatter->IsNumberFormat(minStr, nIndex, nMinValue);
nIndex = 0;
double nMaxValue = 0;
(void)mpNumberFormatter->IsNumberFormat(maxStr, nIndex, nMaxValue);
pData->mnMinLength = nMinValue;
pData->mnMaxLength = nMaxValue;
}
}
ScDataBarFormatData* ScDataBarSettingsDlg::GetData()
{
ScDataBarFormatData* pData = new ScDataBarFormatData();
pData->maPositiveColor = mpLbPos->GetSelectEntryColor();
pData->mpNegativeColor.reset(new Color(mpLbNeg->GetSelectEntryColor()));
pData->mbGradient = ( mpLbFillType->GetSelectEntryPos() == 1 );
pData->mpUpperLimit.reset(new ScColorScaleEntry());
pData->mpLowerLimit.reset(new ScColorScaleEntry());
pData->maAxisColor = mpLbAxisCol->GetSelectEntryColor();
pData->mbOnlyBar = mpCbOnlyBar->IsChecked();
::GetType(*mpLbTypeMin, *mpEdMin, pData->mpLowerLimit.get(), mpNumberFormatter, mpDoc, maPos);
::GetType(*mpLbTypeMax, *mpEdMax, pData->mpUpperLimit.get(), mpNumberFormatter, mpDoc, maPos);
GetAxesPosition(pData, mpLbAxisPos);
SetBarLength(pData, mpLenMin->GetText(), mpLenMax->GetText(), mpNumberFormatter);
return pData;
}
IMPL_LINK_NOARG_TYPED( ScDataBarSettingsDlg, OkBtnHdl, Button*, void )
{
//check that min < max
bool bWarn = false;
sal_Int32 nSelectMin = mpLbTypeMin->GetSelectEntryPos();
if( nSelectMin == COLORSCALE_MAX )
bWarn = true;
sal_Int32 nSelectMax = mpLbTypeMax->GetSelectEntryPos();
if( nSelectMax == COLORSCALE_MIN )
bWarn = true;
if(!bWarn) // databar length checks
{
OUString aMinString = mpLenMin->GetText();
OUString aMaxString = mpLenMax->GetText();
double nMinValue = 0;
sal_uInt32 nIndex = 0;
(void)mpNumberFormatter->IsNumberFormat(aMinString, nIndex, nMinValue);
nIndex = 0;
double nMaxValue = 0;
(void)mpNumberFormatter->IsNumberFormat(aMaxString, nIndex, nMaxValue);
if(rtl::math::approxEqual(nMinValue, nMaxValue) || nMinValue > nMaxValue || nMaxValue > 100 || nMinValue < 0)
bWarn = true;
}
if(!bWarn && mpLbTypeMin->GetSelectEntryPos() == mpLbTypeMax->GetSelectEntryPos())
{
if(nSelectMax != COLORSCALE_FORMULA && nSelectMax != COLORSCALE_AUTO)
{
OUString aMinString = mpEdMin->GetText();
OUString aMaxString = mpEdMax->GetText();
double nMinValue = 0;
sal_uInt32 nIndex = 0;
(void)mpNumberFormatter->IsNumberFormat(aMinString, nIndex, nMinValue);
nIndex = 0;
double nMaxValue = 0;
(void)mpNumberFormatter->IsNumberFormat(aMaxString, nIndex, nMaxValue);
if(rtl::math::approxEqual(nMinValue, nMaxValue) || nMinValue > nMaxValue)
bWarn = true;
}
}
if(bWarn)
{
//show warning message and don't close
ScopedVclPtrInstance< WarningBox > aWarn(this, WB_OK, maStrWarnSameValue );
aWarn->Execute();
}
else
{
EndDialog(RET_OK);
}
}
IMPL_LINK_NOARG( ScDataBarSettingsDlg, TypeSelectHdl )
{
sal_Int32 nSelectMin = mpLbTypeMin->GetSelectEntryPos();
if( nSelectMin <= COLORSCALE_MAX)
mpEdMin->Disable();
else
{
mpEdMin->Enable();
if(mpEdMin->GetText().isEmpty())
{
if(nSelectMin == COLORSCALE_PERCENTILE || nSelectMin == COLORSCALE_PERCENT)
mpEdMin->SetText(OUString::number(50));
else
mpEdMin->SetText(OUString::number(0));
}
}
sal_Int32 nSelectMax = mpLbTypeMax->GetSelectEntryPos();
if(nSelectMax <= COLORSCALE_MAX)
mpEdMax->Disable();
else
{
mpEdMax->Enable();
if(mpEdMax->GetText().isEmpty())
{
if(nSelectMax == COLORSCALE_PERCENTILE || nSelectMax == COLORSCALE_PERCENT)
mpEdMax->SetText(OUString::number(50));
else
mpEdMax->SetText(OUString::number(0));
}
}
return 0;
}
IMPL_LINK_NOARG( ScDataBarSettingsDlg, PosSelectHdl )
{
sal_Int32 axisPos = mpLbAxisPos->GetSelectEntryPos();
if(axisPos != 2 && axisPos != 1) // disable if axis vertical position is automatic
{
mpLenMin->Disable();
mpLenMax->Disable();
}
else
{
mpLenMin->Enable();
mpLenMax->Enable();
if(mpLenMin->GetText().isEmpty())
{
mpLenMin->SetText(OUString::number(0));
mpLenMax->SetText(OUString::number(100));
}
}
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|