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
|
/* -*- 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 "calcoptionsdlg.hxx"
#include "sc.hrc"
#include "scresid.hxx"
#include "svtools/svlbitm.hxx"
#include "svtools/treelistentry.hxx"
#if HAVE_FEATURE_OPENCL
#include "formulagroup.hxx"
#include "globalnames.hxx"
#endif
namespace {
typedef enum {
CALC_OPTION_REF_SYNTAX = 0,
CALC_OPTION_EMPTY_AS_ZERO = 1,
CALC_OPTION_ENABLE_OPENCL = 2
} CalcOptionOrder;
class OptionString : public SvLBoxString
{
OUString maDesc;
OUString maValue;
public:
OptionString(const OUString& rDesc, const OUString& rValue) :
maDesc(rDesc), maValue(rValue) {}
void SetValue(const OUString &rValue) { maValue = rValue; }
virtual void Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
virtual void InitViewData(SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData);
};
void OptionString::InitViewData(
SvTreeListBox* pView, SvTreeListEntry* pEntry, SvViewDataItem* pViewData)
{
if( !pViewData )
pViewData = pView->GetViewDataItem( pEntry, this );
OUString aDesc = maDesc + ": ";
Size aDescSize(pView->GetTextWidth(aDesc), pView->GetTextHeight());
Font aOldFont = pView->GetFont();
Font aFont = aOldFont;
aFont.SetWeight(WEIGHT_BOLD);
//To not make the SvTreeListBox try and recalculate all rows, call the
//underlying SetFont, we just want to know what size this text will be
//and are going to reset the font to the original again afterwards
pView->Control::SetFont(aFont);
Size aValueSize(pView->GetTextWidth(maValue), pView->GetTextHeight());
pView->Control::SetFont(aOldFont);
pViewData->maSize = Size(aDescSize.Width() + aValueSize.Width(), std::max(aDescSize.Height(), aValueSize.Height()));
}
void OptionString::Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* /*pEntry*/)
{
Point aPos = rPos;
OUString aDesc = maDesc + ": ";
rDev.DrawText(aPos, aDesc);
aPos.X() += rDev.GetTextWidth(aDesc);
Font aOldFont = rDev.GetFont();
Font aFont = aOldFont;
aFont.SetWeight(WEIGHT_BOLD);
//To not make the SvTreeListBox try and recalculate all rows, call the
//underlying SetFont, we are going to draw this string and then going to
//reset the font to the original again afterwards
rDev.Control::SetFont(aFont);
rDev.DrawText(aPos, maValue);
rDev.Control::SetFont(aOldFont);
}
formula::FormulaGrammar::AddressConvention toAddressConvention(sal_Int32 nPos)
{
switch (nPos)
{
case 1:
return formula::FormulaGrammar::CONV_OOO;
case 2:
return formula::FormulaGrammar::CONV_XL_A1;
case 3:
return formula::FormulaGrammar::CONV_XL_R1C1;
case 0:
default:
;
}
return formula::FormulaGrammar::CONV_UNSPECIFIED;
}
}
ScCalcOptionsDialog::ScCalcOptionsDialog(Window* pParent, const ScCalcConfig& rConfig)
: ModalDialog(pParent, "FormulaCalculationOptions",
"modules/scalc/ui/formulacalculationoptions.ui")
, maCalcA1(ScResId(SCSTR_FORMULA_SYNTAX_CALC_A1).toString())
, maExcelA1(ScResId(SCSTR_FORMULA_SYNTAX_XL_A1).toString())
, maExcelR1C1(ScResId(SCSTR_FORMULA_SYNTAX_XL_R1C1).toString())
, maConfig(rConfig)
{
get(mpLbSettings, "settings");
get(mpLbOptionEdit, "edit");
get(mpFtAnnotation, "annotation");
get(mpBtnTrue, "true");
get(mpBtnFalse, "false");
get(mpOpenclInfoList, "opencl_list");
get(mpBtnAutomaticSelectionTrue, "automatic_select_true");
get(mpBtnAutomaticSelectionFalse, "automatic_select_false");
get(mpFtFrequency, "frequency");
get(mpFtComputeUnits, "compute_units");
get(mpFtMemory, "memory");
mpOpenclInfoList->set_height_request(4* mpOpenclInfoList->GetTextHeight());
mpOpenclInfoList->SetStyle(mpOpenclInfoList->GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE);
mpOpenclInfoList->SetHighlightRange();
mpOpenclInfoList->GetParent()->Hide();
mpOpenclInfoList->SetSelectHdl(LINK(this, ScCalcOptionsDialog, DeviceSelHdl));
mpBtnAutomaticSelectionTrue->SetToggleHdl(LINK(this, ScCalcOptionsDialog, BtnAutomaticSelectHdl));
maCaptionStringRefSyntax = get<Window>("ref_syntax_caption")->GetText();
maDescStringRefSyntax = get<Window>("ref_syntax_desc")->GetText();
maUseFormulaSyntax = get<Window>("use_formula_syntax")->GetText();
maCaptionEmptyStringAsZero = get<Window>("empty_str_as_zero_caption")->GetText();
maDescEmptyStringAsZero = get<Window>("empty_str_as_zero_desc")->GetText();
maCaptionOpenCLEnabled = get<Window>("opencl_enabled")->GetText();
maDescOpenCLEnabled = get<Window>("opencl_enabled_desc")->GetText();
maSoftware = get<Window>("software")->GetText();
mpLbSettings->set_height_request(8 * mpLbSettings->GetTextHeight());
mpLbSettings->SetStyle(mpLbSettings->GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE);
mpLbSettings->SetHighlightRange();
Link aLink = LINK(this, ScCalcOptionsDialog, SettingsSelHdl);
mpLbSettings->SetSelectHdl(aLink);
mpLbOptionEdit->SetSelectHdl(aLink);
aLink = LINK(this, ScCalcOptionsDialog, BtnToggleHdl);
mpBtnTrue->SetToggleHdl(aLink); // Set handler only to the 'True' button.
maTrue = mpBtnTrue->GetText();
maFalse = mpBtnFalse->GetText();
FillOptionsList();
SelectionChanged();
}
ScCalcOptionsDialog::~ScCalcOptionsDialog() {}
const ScCalcConfig& ScCalcOptionsDialog::GetConfig() const
{
return maConfig;
}
SvTreeListEntry *ScCalcOptionsDialog::createBoolItem(const OUString &rCaption, bool bValue) const
{
SvTreeListEntry* pEntry = new SvTreeListEntry;
pEntry->AddItem(new SvLBoxString(pEntry, 0, OUString()));
pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), false));
OptionString* pItem = new OptionString(rCaption, toString(bValue));
pEntry->AddItem(pItem);
return pEntry;
}
void ScCalcOptionsDialog::setValueAt(size_t nPos, const OUString &rValue)
{
SvTreeList *pModel = mpLbSettings->GetModel();
SvTreeListEntry* pEntry = pModel->GetEntry(NULL, nPos);
if (!pEntry)
{
SAL_WARN("sc", "missing entry at " << nPos << " in value view");
return;
}
OptionString* pOpt = dynamic_cast<OptionString *>(pEntry->GetItem(2));
if (!pOpt)
{
SAL_WARN("sc", "missing option string item so can't set " << rValue);
return;
}
pOpt->SetValue(rValue);
pModel->InvalidateEntry(pEntry);
}
#if HAVE_FEATURE_OPENCL
void ScCalcOptionsDialog::fillOpenclList()
{
mpOpenclInfoList->SetUpdateMode(false);
mpOpenclInfoList->Clear();
SvTreeListEntry* pSoftwareEntry = mpOpenclInfoList->InsertEntry(maSoftware);
OUString aStoredDevice = maConfig.maOpenCLDevice;
SvTreeListEntry* pSelectedEntry = NULL;
sc::FormulaGroupInterpreter::fillOpenCLInfo(maPlatformInfo);
for(std::vector<sc::OpenclPlatformInfo>::iterator it = maPlatformInfo.begin(),
itEnd = maPlatformInfo.end(); it != itEnd; ++it)
{
for(std::vector<sc::OpenclDeviceInfo>::iterator
itr = it->maDevices.begin(), itrEnd = it->maDevices.end(); itr != itrEnd; ++itr)
{
OUString aDeviceId = it->maVendor + " " + itr->maName;
SvTreeListEntry* pEntry = mpOpenclInfoList->InsertEntry(aDeviceId);
if(aDeviceId == aStoredDevice)
{
pSelectedEntry = pEntry;
}
pEntry->SetUserData(&(*itr));
}
}
mpOpenclInfoList->SetUpdateMode(true);
mpOpenclInfoList->GetModel()->GetView(0)->SelectAll(false, false);
if (pSelectedEntry)
mpOpenclInfoList->Select(pSelectedEntry);
else if (aStoredDevice == OPENCL_SOFTWARE_DEVICE_CONFIG_NAME)
mpOpenclInfoList->Select(pSoftwareEntry);
SelectedDeviceChanged();
}
#endif
void ScCalcOptionsDialog::FillOptionsList()
{
mpLbSettings->SetUpdateMode(false);
mpLbSettings->Clear();
SvTreeList* pModel = mpLbSettings->GetModel();
{
// Syntax for INDIRECT function.
SvTreeListEntry* pEntry = new SvTreeListEntry;
pEntry->AddItem(new SvLBoxString(pEntry, 0, OUString()));
pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), false));
OptionString* pItem = new OptionString(
maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
pEntry->AddItem(pItem);
pModel->Insert(pEntry);
}
pModel->Insert(createBoolItem(maCaptionEmptyStringAsZero,maConfig.mbEmptyStringAsZero));
#if HAVE_FEATURE_OPENCL
pModel->Insert(createBoolItem(maCaptionOpenCLEnabled,maConfig.mbOpenCLEnabled));
fillOpenclList();
mpBtnAutomaticSelectionFalse->Check(!maConfig.mbOpenCLAutoSelect);
mpBtnAutomaticSelectionTrue->Check(maConfig.mbOpenCLAutoSelect);
#endif
mpLbSettings->SetUpdateMode(true);
}
void ScCalcOptionsDialog::SelectionChanged()
{
sal_uLong nSelectedPos = mpLbSettings->GetSelectEntryPos();
switch ((CalcOptionOrder)nSelectedPos)
{
case CALC_OPTION_REF_SYNTAX:
{
// Formula syntax for INDIRECT function.
mpBtnTrue->Hide();
mpBtnFalse->Hide();
mpLbOptionEdit->Show();
mpOpenclInfoList->GetParent()->Hide();
mpLbOptionEdit->Clear();
mpLbOptionEdit->InsertEntry(maUseFormulaSyntax);
mpLbOptionEdit->InsertEntry(maCalcA1);
mpLbOptionEdit->InsertEntry(maExcelA1);
mpLbOptionEdit->InsertEntry(maExcelR1C1);
switch (maConfig.meStringRefAddressSyntax)
{
case formula::FormulaGrammar::CONV_OOO:
mpLbOptionEdit->SelectEntryPos(1);
break;
case formula::FormulaGrammar::CONV_XL_A1:
mpLbOptionEdit->SelectEntryPos(2);
break;
case formula::FormulaGrammar::CONV_XL_R1C1:
mpLbOptionEdit->SelectEntryPos(3);
break;
case formula::FormulaGrammar::CONV_UNSPECIFIED:
default:
mpLbOptionEdit->SelectEntryPos(0);
}
mpFtAnnotation->SetText(maDescStringRefSyntax);
}
break;
// booleans
case CALC_OPTION_EMPTY_AS_ZERO:
case CALC_OPTION_ENABLE_OPENCL:
{
// Treat empty string as zero.
mpLbOptionEdit->Hide();
mpBtnTrue->Show();
mpBtnFalse->Show();
bool bValue = false;
if ( nSelectedPos == CALC_OPTION_EMPTY_AS_ZERO )
{
bValue = maConfig.mbEmptyStringAsZero;
mpFtAnnotation->SetText(maDescEmptyStringAsZero);
mpOpenclInfoList->GetParent()->Hide();
}
else
{
bValue = maConfig.mbOpenCLEnabled;
mpFtAnnotation->SetText(maDescOpenCLEnabled);
mpOpenclInfoList->GetParent()->Show();
setOptimalLayoutSize();
if(bValue)
mpOpenclInfoList->GetParent()->Enable();
else
mpOpenclInfoList->GetParent()->Disable();
OpenclAutomaticSelectionChanged();
}
if ( bValue )
{
mpBtnTrue->Check(true);
mpBtnFalse->Check(false);
}
else
{
mpBtnTrue->Check(false);
mpBtnFalse->Check(true);
}
}
break;
default:
;
}
}
void ScCalcOptionsDialog::ListOptionValueChanged()
{
sal_uLong nSelected = mpLbSettings->GetSelectEntryPos();
switch ((CalcOptionOrder) nSelected)
{
case CALC_OPTION_REF_SYNTAX:
{
// Formula syntax for INDIRECT function.
sal_Int32 nPos = mpLbOptionEdit->GetSelectEntryPos();
maConfig.meStringRefAddressSyntax = toAddressConvention(nPos);
setValueAt(nSelected, toString(maConfig.meStringRefAddressSyntax));
}
break;
case CALC_OPTION_EMPTY_AS_ZERO:
case CALC_OPTION_ENABLE_OPENCL:
break;
}
}
void ScCalcOptionsDialog::OpenclAutomaticSelectionChanged()
{
bool bValue = mpBtnAutomaticSelectionTrue->IsChecked();
if(bValue)
mpOpenclInfoList->Disable();
else
mpOpenclInfoList->Enable();
maConfig.mbOpenCLAutoSelect = bValue;
}
void ScCalcOptionsDialog::SelectedDeviceChanged()
{
#if HAVE_FEATURE_OPENCL
SvTreeListEntry* pEntry = mpOpenclInfoList->GetModel()->GetView(0)->FirstSelected();
if(!pEntry)
return;
sc::OpenclDeviceInfo* pInfo = reinterpret_cast<sc::OpenclDeviceInfo*>(pEntry->GetUserData());
if(pInfo)
{
mpFtFrequency->SetText(OUString::number(pInfo->mnFrequency));
mpFtComputeUnits->SetText(OUString::number(pInfo->mnComputeUnits));
mpFtMemory->SetText(OUString::number(pInfo->mnMemory/1024/1024));
}
else
{
mpFtFrequency->SetText(OUString());
mpFtComputeUnits->SetText(OUString());
mpFtMemory->SetText(OUString());
}
SvLBoxString* pBoxEntry = dynamic_cast<SvLBoxString*>(pEntry->GetItem(1));
if (!pBoxEntry)
return;
OUString aDevice = pBoxEntry->GetText();
// use english string for configuration
if(aDevice == maSoftware)
aDevice = OPENCL_SOFTWARE_DEVICE_CONFIG_NAME;
maConfig.maOpenCLDevice = aDevice;
#endif
}
void ScCalcOptionsDialog::RadioValueChanged()
{
sal_uLong nSelected = mpLbSettings->GetSelectEntryPos();
bool bValue = mpBtnTrue->IsChecked();
switch (nSelected)
{
case CALC_OPTION_REF_SYNTAX:
return;
case CALC_OPTION_EMPTY_AS_ZERO:
maConfig.mbEmptyStringAsZero = bValue;
break;
case CALC_OPTION_ENABLE_OPENCL:
maConfig.mbOpenCLEnabled = bValue;
if(bValue)
mpOpenclInfoList->GetParent()->Enable();
else
mpOpenclInfoList->GetParent()->Disable();
OpenclAutomaticSelectionChanged();
break;
}
setValueAt(nSelected, toString(bValue));
}
OUString ScCalcOptionsDialog::toString(formula::FormulaGrammar::AddressConvention eConv) const
{
switch (eConv)
{
case formula::FormulaGrammar::CONV_OOO:
return maCalcA1;
case formula::FormulaGrammar::CONV_XL_A1:
return maExcelA1;
case formula::FormulaGrammar::CONV_XL_R1C1:
return maExcelR1C1;
case formula::FormulaGrammar::CONV_UNSPECIFIED:
default:
;
}
return maUseFormulaSyntax;
}
OUString ScCalcOptionsDialog::toString(bool bVal) const
{
return bVal ? maTrue : maFalse;
}
IMPL_LINK(ScCalcOptionsDialog, SettingsSelHdl, Control*, pCtrl)
{
if (pCtrl == mpLbSettings)
SelectionChanged();
else if (pCtrl == mpLbOptionEdit)
ListOptionValueChanged();
return 0;
}
IMPL_LINK_NOARG(ScCalcOptionsDialog, BtnToggleHdl)
{
RadioValueChanged();
return 0;
}
IMPL_LINK_NOARG(ScCalcOptionsDialog, BtnAutomaticSelectHdl)
{
OpenclAutomaticSelectionChanged();
return 0;
}
IMPL_LINK_NOARG(ScCalcOptionsDialog, DeviceSelHdl)
{
SelectedDeviceChanged();
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|