1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tpcalc.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #include "tpformula.hxx"
42 #include "scresid.hxx"
43 #include "formula/grammar.hxx"
44 #include "docoptio.hxx"
47 #include <unotools/localedatawrapper.hxx>
49 #include <com/sun/star/lang/Locale.hpp>
50 #include <com/sun/star/i18n/LocaleDataItem.hpp>
52 using ::rtl::OUString
;
53 using ::com::sun::star::lang::Locale
;
54 using ::com::sun::star::i18n::LocaleDataItem
;
56 ScTpFormulaOptions::ScTpFormulaOptions(Window
* pParent
, const SfxItemSet
& rCoreAttrs
) :
57 SfxTabPage(pParent
, ScResId(RID_SCPAGE_FORMULA
), rCoreAttrs
),
59 maFlFormulaOpt(this, ScResId(FL_FORMULA_OPTIONS
)),
60 maFtFormulaSyntax(this, ScResId(FT_FORMULA_SYNTAX
)),
61 maLbFormulaSyntax(this, ScResId(LB_FORMULA_SYNTAX
)),
62 maFlFormulaSeps(this, ScResId(FL_FORMULA_SEPS
)),
63 maFtSepFuncArg(this, ScResId(FT_FORMULA_SEP_ARG
)),
64 maEdSepFuncArg(this, ScResId(ED_FORMULA_SEP_ARG
)),
65 maFtSepArrayCol(this, ScResId(FT_FORMULA_SEP_ARRAY_C
)),
66 maEdSepArrayCol(this, ScResId(ED_FORMULA_SEP_ARRAY_C
)),
67 maFtSepArrayRow(this, ScResId(FT_FORMULA_SEP_ARRAY_R
)),
68 maEdSepArrayRow(this, ScResId(ED_FORMULA_SEP_ARRAY_R
)),
69 maBtnSepReset(this, ScResId(BTN_FORMULA_SEP_RESET
)),
77 const ScTpCalcItem
& rItem
= static_cast<const ScTpCalcItem
&>(
78 rCoreAttrs
.Get(GetWhich(SID_SCDOCOPTIONS
)));
79 mpOldOptions
.reset(new ScDocOptions(rItem
.GetDocOptions()));
80 mpNewOptions
.reset(new ScDocOptions(rItem
.GetDocOptions()));
85 ScTpFormulaOptions::~ScTpFormulaOptions()
89 void ScTpFormulaOptions::Init()
91 Link aLink
= LINK( this, ScTpFormulaOptions
, ButtonHdl
);
92 maBtnSepReset
.SetClickHdl(aLink
);
94 aLink
= LINK( this, ScTpFormulaOptions
, SepModifyHdl
);
95 maEdSepFuncArg
.SetModifyHdl(aLink
);
96 maEdSepArrayCol
.SetModifyHdl(aLink
);
97 maEdSepArrayRow
.SetModifyHdl(aLink
);
99 aLink
= LINK( this, ScTpFormulaOptions
, SepEditOnFocusHdl
);
100 maEdSepFuncArg
.SetGetFocusHdl(aLink
);
101 maEdSepArrayCol
.SetGetFocusHdl(aLink
);
102 maEdSepArrayRow
.SetGetFocusHdl(aLink
);
104 // Get the decimal separator for current locale.
105 String aSep
= mpOldOptions
->GetLocaleDataWrapper().getNumDecimalSep();
106 mnDecSep
= aSep
.Len() ? aSep
.GetChar(0) : sal_Unicode('.');
109 void ScTpFormulaOptions::ResetSeparators()
112 maEdSepFuncArg
.SetText(aOpt
.GetFormulaSepArg());
113 maEdSepArrayCol
.SetText(aOpt
.GetFormulaSepArrayCol());
114 maEdSepArrayRow
.SetText(aOpt
.GetFormulaSepArrayRow());
117 void ScTpFormulaOptions::OnFocusSeparatorInput(Edit
* pEdit
)
122 // Make sure the entire text is selected.
123 xub_StrLen nLen
= pEdit
->GetText().Len();
124 Selection
aSel(0, nLen
);
125 pEdit
->SetSelection(aSel
);
126 maOldSepValue
= pEdit
->GetText();
129 bool ScTpFormulaOptions::IsValidSeparator(const OUString
& rSep
) const
131 if (rSep
.getLength() != 1)
132 // Must be one-character long.
135 if (rSep
.compareToAscii("a") >= 0 && rSep
.compareToAscii("z") <= 0)
138 if (rSep
.compareToAscii("A") >= 0 && rSep
.compareToAscii("Z") <= 0)
141 sal_Unicode c
= rSep
.getStr()[0];
156 // Disallowed characters. Anything else we want to disallow ?
161 // decimal separator is not allowed.
167 bool ScTpFormulaOptions::IsValidSeparatorSet() const
169 // Make sure the column and row separators are different.
170 String aColStr
= maEdSepArrayCol
.GetText();
171 String aRowStr
= maEdSepArrayRow
.GetText();
172 if (aColStr
== aRowStr
)
178 IMPL_LINK( ScTpFormulaOptions
, ButtonHdl
, PushButton
*, pBtn
)
180 if (pBtn
== &maBtnSepReset
)
186 IMPL_LINK( ScTpFormulaOptions
, SepModifyHdl
, Edit
*, pEdit
)
191 String aStr
= pEdit
->GetText();
194 // In case the string is more than one character long, only grab the
196 aStr
= aStr
.Copy(0, 1);
197 pEdit
->SetText(aStr
);
200 if ((!IsValidSeparator(aStr
) || !IsValidSeparatorSet()) && maOldSepValue
.getLength())
201 // Invalid separator. Restore the old value.
202 pEdit
->SetText(maOldSepValue
);
204 OnFocusSeparatorInput(pEdit
);
208 IMPL_LINK( ScTpFormulaOptions
, SepEditOnFocusHdl
, Edit
*, pEdit
)
210 OnFocusSeparatorInput(pEdit
);
215 SfxTabPage
* ScTpFormulaOptions::Create(Window
* pParent
, const SfxItemSet
& rCoreSet
)
217 return new ScTpFormulaOptions(pParent
, rCoreSet
);
220 BOOL
ScTpFormulaOptions::FillItemSet(SfxItemSet
& rCoreSet
)
222 ::formula::FormulaGrammar::Grammar eGram
= ::formula::FormulaGrammar::GRAM_DEFAULT
;
223 switch (maLbFormulaSyntax
.GetSelectEntryPos())
226 eGram
= ::formula::FormulaGrammar::GRAM_NATIVE
;
229 eGram
= ::formula::FormulaGrammar::GRAM_NATIVE_XL_A1
;
232 eGram
= ::formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1
;
236 mpNewOptions
->SetFormulaSyntax(eGram
);
238 mpNewOptions
->SetFormulaSepArg(maEdSepFuncArg
.GetText());
239 mpNewOptions
->SetFormulaSepArrayCol(maEdSepArrayCol
.GetText());
240 mpNewOptions
->SetFormulaSepArrayRow(maEdSepArrayRow
.GetText());
242 if (*mpNewOptions
!= *mpOldOptions
)
244 rCoreSet
.Put(ScTpCalcItem(GetWhich(SID_SCDOCOPTIONS
), *mpNewOptions
));
251 void ScTpFormulaOptions::Reset(const SfxItemSet
& /*rCoreSet*/)
253 ::formula::FormulaGrammar::Grammar eGram
= mpNewOptions
->GetFormulaSyntax();
256 case ::formula::FormulaGrammar::GRAM_NATIVE
:
257 maLbFormulaSyntax
.SelectEntryPos(0);
259 case ::formula::FormulaGrammar::GRAM_NATIVE_XL_A1
:
260 maLbFormulaSyntax
.SelectEntryPos(1);
262 case ::formula::FormulaGrammar::GRAM_NATIVE_XL_R1C1
:
263 maLbFormulaSyntax
.SelectEntryPos(2);
266 maLbFormulaSyntax
.SelectEntryPos(0);
269 OUString aSep
= mpNewOptions
->GetFormulaSepArg();
270 OUString aSepArrayRow
= mpNewOptions
->GetFormulaSepArrayRow();
271 OUString aSepArrayCol
= mpNewOptions
->GetFormulaSepArrayCol();
273 if (aSep
.getLength() == 1 && aSepArrayRow
.getLength() == 1 && aSepArrayCol
.getLength() == 1)
275 // Each separator must be one character long.
276 maEdSepFuncArg
.SetText(aSep
);
277 maEdSepArrayCol
.SetText(aSepArrayCol
);
278 maEdSepArrayRow
.SetText(aSepArrayRow
);
284 int ScTpFormulaOptions::DeactivatePage(SfxItemSet
* /*pSet*/)
286 // What's this method for ?