bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / optdlg / calcoptionsdlg.cxx
blob427e6af9c82420de35a72bd09dd1a5d9b304866c
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/.
8 */
10 #include "calcoptionsdlg.hxx"
11 #include "calcoptionsdlg.hrc"
12 #include "scresid.hxx"
14 #include "svtools/svlbitm.hxx"
15 #include "svtools/treelistentry.hxx"
17 namespace {
19 class OptionString : public SvLBoxString
21 OUString maDesc;
22 OUString maValue;
23 public:
24 OptionString(const OUString& rDesc, const OUString& rValue) :
25 maDesc(rDesc), maValue(rValue) {}
27 virtual void Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry);
30 void OptionString::Paint(const Point& rPos, SvTreeListBox& rDev, const SvViewDataEntry* /*pView*/, const SvTreeListEntry* /*pEntry*/)
32 Point aPos = rPos;
33 OUString aDesc = maDesc + OUString(": ");
34 rDev.DrawText(aPos, aDesc);
36 aPos.X() += rDev.GetTextWidth(aDesc);
37 Font aOldFont = rDev.GetFont();
38 Font aFont = aOldFont;
39 aFont.SetWeight(WEIGHT_BOLD);
41 rDev.SetFont(aFont);
42 rDev.DrawText(aPos, maValue);
44 rDev.SetFont(aOldFont);
47 formula::FormulaGrammar::AddressConvention toAddressConvention(sal_uInt16 nPos)
49 switch (nPos)
51 case 1:
52 return formula::FormulaGrammar::CONV_OOO;
53 case 2:
54 return formula::FormulaGrammar::CONV_XL_A1;
55 case 3:
56 return formula::FormulaGrammar::CONV_XL_R1C1;
57 case 0:
58 default:
62 return formula::FormulaGrammar::CONV_UNSPECIFIED;
67 ScCalcOptionsDialog::ScCalcOptionsDialog(Window* pParent, const ScCalcConfig& rConfig) :
68 ModalDialog(pParent, ScResId(RID_SCDLG_FORMULA_CALCOPTIONS)),
69 maLbSettings(this, ScResId(LB_SETTINGS)),
70 maFtOptionEditCaption(this, ScResId(FT_OPTION_EDIT_CAPTION)),
71 maLbOptionEdit(this, ScResId(LB_OPTION_EDIT)),
72 maBtnTrue(this, ScResId(BTN_OPTION_TRUE)),
73 maBtnFalse(this, ScResId(BTN_OPTION_FALSE)),
74 maFlAnnotation(this, ScResId(FL_ANNOTATION)),
75 maFtAnnotation(this, ScResId(FT_ANNOTATION)),
76 maBtnOK(this, ScResId(BTN_OK)),
77 maBtnCancel(this, ScResId(BTN_CANCEL)),
78 maTrue(ScResId(STR_TRUE).toString()),
79 maFalse(ScResId(STR_FALSE).toString()),
80 maCalcA1(ScResId(SCSTR_FORMULA_SYNTAX_CALC_A1).toString()),
81 maExcelA1(ScResId(SCSTR_FORMULA_SYNTAX_XL_A1).toString()),
82 maExcelR1C1(ScResId(SCSTR_FORMULA_SYNTAX_XL_R1C1).toString()),
83 maCaptionStringRefSyntax(ScResId(STR_STRING_REF_SYNTAX_CAPTION).toString()),
84 maDescStringRefSyntax(ScResId(STR_STRING_REF_SYNTAX_DESC).toString()),
85 maUseFormulaSyntax(ScResId(STR_USE_FORMULA_SYNTAX).toString()),
86 maCaptionEmptyStringAsZero(ScResId(STR_EMPTY_STRING_AS_ZERO_CAPTION).toString()),
87 maDescEmptyStringAsZero(ScResId(STR_EMPTY_STRING_AS_ZERO_DESC).toString()),
88 maConfig(rConfig)
90 maLbSettings.SetStyle(maLbSettings.GetStyle() | WB_CLIPCHILDREN | WB_FORCE_MAKEVISIBLE);
91 maLbSettings.SetHighlightRange();
93 Link aLink = LINK(this, ScCalcOptionsDialog, SettingsSelHdl);
94 maLbSettings.SetSelectHdl(aLink);
95 maLbOptionEdit.SetSelectHdl(aLink);
97 aLink = LINK(this, ScCalcOptionsDialog, BtnToggleHdl);
98 maBtnTrue.SetToggleHdl(aLink); // Set handler only to the 'True' button.
100 maBtnTrue.SetText(maTrue);
101 maBtnFalse.SetText(maFalse);
103 FillOptionsList();
104 FreeResource();
105 SelectionChanged();
108 ScCalcOptionsDialog::~ScCalcOptionsDialog() {}
110 const ScCalcConfig& ScCalcOptionsDialog::GetConfig() const
112 return maConfig;
115 void ScCalcOptionsDialog::FillOptionsList()
117 maLbSettings.SetUpdateMode(false);
118 maLbSettings.Clear();
120 SvTreeList* pModel = maLbSettings.GetModel();
123 // Syntax for INDIRECT function.
124 SvTreeListEntry* pEntry = new SvTreeListEntry;
125 pEntry->AddItem(new SvLBoxString(pEntry, 0, OUString()));
126 pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
127 OptionString* pItem = new OptionString(
128 maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
129 pEntry->AddItem(pItem);
130 pModel->Insert(pEntry);
134 // Treat empty string as zero.
135 SvTreeListEntry* pEntry = new SvTreeListEntry;
136 pEntry->AddItem(new SvLBoxString(pEntry, 0, OUString()));
137 pEntry->AddItem(new SvLBoxContextBmp(pEntry, 0, Image(), Image(), 0));
138 OptionString* pItem = new OptionString(
139 maCaptionEmptyStringAsZero, toString(maConfig.mbEmptyStringAsZero));
140 pEntry->AddItem(pItem);
141 pModel->Insert(pEntry);
144 maLbSettings.SetUpdateMode(true);
147 void ScCalcOptionsDialog::SelectionChanged()
149 sal_uInt16 nSelectedPos = maLbSettings.GetSelectEntryPos();
150 switch (nSelectedPos)
152 case 0:
154 // Formula syntax for INDIRECT function.
155 maBtnTrue.Hide();
156 maBtnFalse.Hide();
157 maLbOptionEdit.Show();
159 maLbOptionEdit.Clear();
160 maLbOptionEdit.InsertEntry(maUseFormulaSyntax);
161 maLbOptionEdit.InsertEntry(maCalcA1);
162 maLbOptionEdit.InsertEntry(maExcelA1);
163 maLbOptionEdit.InsertEntry(maExcelR1C1);
164 switch (maConfig.meStringRefAddressSyntax)
166 case formula::FormulaGrammar::CONV_OOO:
167 maLbOptionEdit.SelectEntryPos(1);
168 break;
169 case formula::FormulaGrammar::CONV_XL_A1:
170 maLbOptionEdit.SelectEntryPos(2);
171 break;
172 case formula::FormulaGrammar::CONV_XL_R1C1:
173 maLbOptionEdit.SelectEntryPos(3);
174 break;
175 case formula::FormulaGrammar::CONV_UNSPECIFIED:
176 default:
177 maLbOptionEdit.SelectEntryPos(0);
179 maFtAnnotation.SetText(maDescStringRefSyntax);
181 break;
182 case 1:
184 // Treat empty string as zero.
185 maLbOptionEdit.Hide();
186 maBtnTrue.Show();
187 maBtnFalse.Show();
189 if (maConfig.mbEmptyStringAsZero)
191 maBtnTrue.Check(true);
192 maBtnFalse.Check(false);
194 else
196 maBtnTrue.Check(false);
197 maBtnFalse.Check(true);
199 maFtAnnotation.SetText(maDescEmptyStringAsZero);
201 break;
202 default:
207 void ScCalcOptionsDialog::ListOptionValueChanged()
209 sal_uInt16 nSelected = maLbSettings.GetSelectEntryPos();
210 switch (nSelected)
212 case 0:
214 // Formula syntax for INDIRECT function.
215 sal_uInt16 nPos = maLbOptionEdit.GetSelectEntryPos();
216 maConfig.meStringRefAddressSyntax = toAddressConvention(nPos);
218 maLbSettings.SetUpdateMode(false);
220 SvTreeList* pModel = maLbSettings.GetModel();
221 SvTreeListEntry* pEntry = pModel->GetEntry(NULL, 0);
222 if (!pEntry)
223 return;
225 OptionString* pItem = new OptionString(
226 maCaptionStringRefSyntax, toString(maConfig.meStringRefAddressSyntax));
227 pEntry->ReplaceItem(pItem, 2);
229 maLbSettings.SetUpdateMode(true);
231 break;
232 default:
237 void ScCalcOptionsDialog::RadioValueChanged()
239 sal_uInt16 nSelected = maLbSettings.GetSelectEntryPos();
240 switch (nSelected)
242 case 1:
244 // Treat empty string as zero.
245 maConfig.mbEmptyStringAsZero = maBtnTrue.IsChecked();
246 maLbSettings.SetUpdateMode(false);
248 SvTreeList* pModel = maLbSettings.GetModel();
249 SvTreeListEntry* pEntry = pModel->GetEntry(NULL, 1);
250 if (!pEntry)
251 return;
253 OptionString* pItem = new OptionString(
254 maCaptionEmptyStringAsZero, toString(maConfig.mbEmptyStringAsZero));
255 pEntry->ReplaceItem(pItem, 2);
257 maLbSettings.SetUpdateMode(true);
259 break;
260 default:
265 OUString ScCalcOptionsDialog::toString(formula::FormulaGrammar::AddressConvention eConv) const
267 switch (eConv)
269 case formula::FormulaGrammar::CONV_OOO:
270 return maCalcA1;
271 case formula::FormulaGrammar::CONV_XL_A1:
272 return maExcelA1;
273 case formula::FormulaGrammar::CONV_XL_R1C1:
274 return maExcelR1C1;
275 case formula::FormulaGrammar::CONV_UNSPECIFIED:
276 default:
279 return maUseFormulaSyntax;
282 OUString ScCalcOptionsDialog::toString(bool bVal) const
284 return bVal ? maTrue : maFalse;
287 IMPL_LINK(ScCalcOptionsDialog, SettingsSelHdl, Control*, pCtrl)
289 if (pCtrl == &maLbSettings)
290 SelectionChanged();
291 else if (pCtrl == &maLbOptionEdit)
292 ListOptionValueChanged();
294 return 0;
297 IMPL_LINK_NOARG(ScCalcOptionsDialog, BtnToggleHdl)
299 RadioValueChanged();
300 return 0;
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */