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/.
10 #include "calcoptionsdlg.hxx"
11 #include "calcoptionsdlg.hrc"
12 #include "scresid.hxx"
14 #include "svtools/svlbitm.hxx"
15 #include "svtools/treelistentry.hxx"
19 class OptionString
: public SvLBoxString
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*/)
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
);
42 rDev
.DrawText(aPos
, maValue
);
44 rDev
.SetFont(aOldFont
);
47 formula::FormulaGrammar::AddressConvention
toAddressConvention(sal_uInt16 nPos
)
52 return formula::FormulaGrammar::CONV_OOO
;
54 return formula::FormulaGrammar::CONV_XL_A1
;
56 return formula::FormulaGrammar::CONV_XL_R1C1
;
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()),
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
);
108 ScCalcOptionsDialog::~ScCalcOptionsDialog() {}
110 const ScCalcConfig
& ScCalcOptionsDialog::GetConfig() const
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
)
154 // Formula syntax for INDIRECT function.
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);
169 case formula::FormulaGrammar::CONV_XL_A1
:
170 maLbOptionEdit
.SelectEntryPos(2);
172 case formula::FormulaGrammar::CONV_XL_R1C1
:
173 maLbOptionEdit
.SelectEntryPos(3);
175 case formula::FormulaGrammar::CONV_UNSPECIFIED
:
177 maLbOptionEdit
.SelectEntryPos(0);
179 maFtAnnotation
.SetText(maDescStringRefSyntax
);
184 // Treat empty string as zero.
185 maLbOptionEdit
.Hide();
189 if (maConfig
.mbEmptyStringAsZero
)
191 maBtnTrue
.Check(true);
192 maBtnFalse
.Check(false);
196 maBtnTrue
.Check(false);
197 maBtnFalse
.Check(true);
199 maFtAnnotation
.SetText(maDescEmptyStringAsZero
);
207 void ScCalcOptionsDialog::ListOptionValueChanged()
209 sal_uInt16 nSelected
= maLbSettings
.GetSelectEntryPos();
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);
225 OptionString
* pItem
= new OptionString(
226 maCaptionStringRefSyntax
, toString(maConfig
.meStringRefAddressSyntax
));
227 pEntry
->ReplaceItem(pItem
, 2);
229 maLbSettings
.SetUpdateMode(true);
237 void ScCalcOptionsDialog::RadioValueChanged()
239 sal_uInt16 nSelected
= maLbSettings
.GetSelectEntryPos();
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);
253 OptionString
* pItem
= new OptionString(
254 maCaptionEmptyStringAsZero
, toString(maConfig
.mbEmptyStringAsZero
));
255 pEntry
->ReplaceItem(pItem
, 2);
257 maLbSettings
.SetUpdateMode(true);
265 OUString
ScCalcOptionsDialog::toString(formula::FormulaGrammar::AddressConvention eConv
) const
269 case formula::FormulaGrammar::CONV_OOO
:
271 case formula::FormulaGrammar::CONV_XL_A1
:
273 case formula::FormulaGrammar::CONV_XL_R1C1
:
275 case formula::FormulaGrammar::CONV_UNSPECIFIED
:
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
)
291 else if (pCtrl
== &maLbOptionEdit
)
292 ListOptionValueChanged();
297 IMPL_LINK_NOARG(ScCalcOptionsDialog
, BtnToggleHdl
)
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */