diff options
author | Caolán McNamara <caolanm@redhat.com> | 2013-02-18 21:59:21 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-02-19 10:48:41 +0000 |
commit | 7cf8320c5db2355da1983ef8cd2fd6737338d33b (patch) | |
tree | b02c34f71e70133f8132fe3413af163ea001d876 /vcl | |
parent | 9a49ff646bdd27fb1355847828794b0a9df40e1d (diff) |
add a mechanism to load TimeFields from .ui files
Change-Id: I7704f46d262888639a17c5219e784559db91b847
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/builder.hxx | 13 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 114 |
2 files changed, 100 insertions, 27 deletions
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx index 220e5b194d05..41178ed207c6 100644 --- a/vcl/inc/vcl/builder.hxx +++ b/vcl/inc/vcl/builder.hxx @@ -23,6 +23,7 @@ class ListBox; class NumericFormatter; class PopupMenu; class ScrollBar; +class TimeField; class VclMultiLineEdit; class VCL_DLLPUBLIC VclBuilder @@ -127,8 +128,9 @@ private: typedef stringmap Adjustment; const Adjustment *get_adjustment_by_name(OString sID) const; - static void mungeSpinAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment); - static void mungeScrollAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment); + static void mungeAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment); + static void mungeAdjustment(TimeField &rTarget, const Adjustment &rAdjustment); + static void mungeAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment); typedef std::map<OString, OString> WidgetTranslations; typedef std::map<OString, WidgetTranslations> Translations; @@ -165,7 +167,8 @@ private: std::vector<TextBufferMap> m_aTextBufferMaps; std::map<OString, TextBuffer> m_aTextBuffers; - std::vector<WidgetAdjustmentMap> m_aSpinAdjustmentMaps; + std::vector<WidgetAdjustmentMap> m_aNumericFormatterAdjustmentMaps; + std::vector<WidgetAdjustmentMap> m_aTimeFormatterAdjustmentMaps; std::vector<WidgetAdjustmentMap> m_aScrollAdjustmentMaps; std::map<OString, Adjustment> m_aAdjustments; @@ -258,10 +261,12 @@ private: Window *makeObject(Window *pParent, const OString &rClass, const OString &rID, stringmap &rVec, const std::vector<OString> &rItems); + void connectNumericFormatterAdjustment(const OString &id, const OString &rAdjustment); + void connectTimeFormatterAdjustment(const OString &id, const OString &rAdjustment); + bool extractGroup(const OString &id, stringmap &rVec); bool extractModel(const OString &id, stringmap &rVec); bool extractBuffer(const OString &id, stringmap &rVec); - bool extractSpinAdjustment(const OString &id, stringmap &rVec); bool extractScrollAdjustment(const OString &id, stringmap &rVec); bool extractButtonImage(const OString &id, stringmap &rMap, bool bRadio); bool extractStock(const OString &id, stringmap &rMap); diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 13251a480263..9b3da1b432c3 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -236,14 +236,24 @@ VclBuilder::VclBuilder(Window *pParent, OUString sUIDir, OUString sUIFile, OStri } //Set SpinButton adjustments when everything has been imported - for (std::vector<WidgetAdjustmentMap>::iterator aI = m_pParserState->m_aSpinAdjustmentMaps.begin(), - aEnd = m_pParserState->m_aSpinAdjustmentMaps.end(); aI != aEnd; ++aI) + for (std::vector<WidgetAdjustmentMap>::iterator aI = m_pParserState->m_aNumericFormatterAdjustmentMaps.begin(), + aEnd = m_pParserState->m_aNumericFormatterAdjustmentMaps.end(); aI != aEnd; ++aI) { NumericFormatter *pTarget = dynamic_cast<NumericFormatter*>(get<Window>(aI->m_sID)); const Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue); SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment"); if (pTarget && pAdjustment) - mungeSpinAdjustment(*pTarget, *pAdjustment); + mungeAdjustment(*pTarget, *pAdjustment); + } + + for (std::vector<WidgetAdjustmentMap>::iterator aI = m_pParserState->m_aTimeFormatterAdjustmentMaps.begin(), + aEnd = m_pParserState->m_aTimeFormatterAdjustmentMaps.end(); aI != aEnd; ++aI) + { + TimeField *pTarget = dynamic_cast<TimeField*>(get<Window>(aI->m_sID)); + const Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue); + SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of spinbutton/adjustment"); + if (pTarget && pAdjustment) + mungeAdjustment(*pTarget, *pAdjustment); } //Set ScrollBar adjustments when everything has been imported @@ -254,7 +264,7 @@ VclBuilder::VclBuilder(Window *pParent, OUString sUIDir, OUString sUIFile, OStri const Adjustment *pAdjustment = get_adjustment_by_name(aI->m_sValue); SAL_WARN_IF(!pTarget || !pAdjustment, "vcl", "missing elements of scrollbar/adjustment"); if (pTarget && pAdjustment) - mungeScrollAdjustment(*pTarget, *pAdjustment); + mungeAdjustment(*pTarget, *pAdjustment); } //Set size-groups when all widgets have been imported @@ -663,6 +673,8 @@ namespace else if (sUnit == "%") eUnit = FUNIT_PERCENT; + assert(eUnit != FUNIT_NONE); //unknown unit + return eUnit; } @@ -691,19 +703,19 @@ bool VclBuilder::extractGroup(const OString &id, stringmap &rMap) return false; } -bool VclBuilder::extractSpinAdjustment(const OString &id, stringmap &rMap) +void VclBuilder::connectNumericFormatterAdjustment(const OString &id, const OString &rAdjustment) { - VclBuilder::stringmap::iterator aFind = rMap.find(OString("adjustment")); - if (aFind != rMap.end()) - { - m_pParserState->m_aSpinAdjustmentMaps.push_back(WidgetAdjustmentMap(id, aFind->second)); - rMap.erase(aFind); - return true; - } - return false; + if (!rAdjustment.isEmpty()) + m_pParserState->m_aNumericFormatterAdjustmentMaps.push_back(WidgetAdjustmentMap(id, rAdjustment)); +} + +void VclBuilder::connectTimeFormatterAdjustment(const OString &id, const OString &rAdjustment) +{ + if (!rAdjustment.isEmpty()) + m_pParserState->m_aTimeFormatterAdjustmentMaps.push_back(WidgetAdjustmentMap(id, rAdjustment)); } -bool VclBuilder::extractScrollAdjustment(const OString &id, stringmap &rMap) +bool VclBuilder::extractScrollAdjustment(const OString &id, VclBuilder::stringmap &rMap) { VclBuilder::stringmap::iterator aFind = rMap.find(OString("adjustment")); if (aFind != rMap.end()) @@ -741,6 +753,18 @@ namespace return bSelectable; } + OString extractAdjustment(VclBuilder::stringmap &rMap) + { + OString sAdjustment; + VclBuilder::stringmap::iterator aFind = rMap.find(OString("adjustment")); + if (aFind != rMap.end()) + { + sAdjustment= aFind->second; + rMap.erase(aFind); + return sAdjustment; + } + return sAdjustment; + } } bool VclBuilder::extractModel(const OString &id, stringmap &rMap) @@ -968,7 +992,7 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri } else if (name == "GtkSpinButton") { - extractSpinAdjustment(id, rMap); + OString sAdjustment = extractAdjustment(rMap); OString sPattern = extractCustomProperty(rMap); OString sUnit = sPattern; @@ -981,23 +1005,34 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri } } - FieldUnit eUnit = detectMetricUnit(sUnit); - WinBits nBits = WB_LEFT|WB_BORDER|WB_3DLOOK; if (!id.endsWith("-nospin")) nBits |= WB_SPIN; if (sPattern.isEmpty()) { + connectNumericFormatterAdjustment(id, sAdjustment); SAL_INFO("vcl.layout", "making numeric field for " << name.getStr() << " " << sUnit.getStr()); pWindow = new NumericField(pParent, nBits); } else { - SAL_INFO("vcl.layout", "making metric field for " << name.getStr() << " " << sUnit.getStr()); - MetricField *pField = new MetricField(pParent, nBits); - pField->SetUnit(eUnit); - pWindow = pField; + if (sPattern == "hh:mm") + { + connectTimeFormatterAdjustment(id, sAdjustment); + SAL_INFO("vcl.layout", "making time field for " << name.getStr() << " " << sUnit.getStr()); + TimeField *pField = new TimeField(pParent, nBits); + pWindow = pField; + } + else + { + connectNumericFormatterAdjustment(id, sAdjustment); + FieldUnit eUnit = detectMetricUnit(sUnit); + SAL_INFO("vcl.layout", "making metric field for " << name.getStr() << " " << sUnit.getStr()); + MetricField *pField = new MetricField(pParent, nBits); + pField->SetUnit(eUnit); + pWindow = pField; + } } } else if (name == "GtkLinkButton") @@ -2467,7 +2502,7 @@ void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt1 rTarget.SelectEntryPos(nActiveId); } -void VclBuilder::mungeSpinAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment) +void VclBuilder::mungeAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment) { int nMul = rtl_math_pow10Exp(1, rTarget.GetDecimalDigits()); @@ -2505,7 +2540,40 @@ void VclBuilder::mungeSpinAdjustment(NumericFormatter &rTarget, const Adjustment } } -void VclBuilder::mungeScrollAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment) +//assume all in minutes for the moment +void VclBuilder::mungeAdjustment(TimeField &rTarget, const Adjustment &rAdjustment) +{ + for (stringmap::const_iterator aI = rAdjustment.begin(), aEnd = rAdjustment.end(); aI != aEnd; ++aI) + { + const OString &rKey = aI->first; + const OString &rValue = aI->second; + + if (rKey == "upper") + { + Time aUpper(0, rValue.toInt32()); + rTarget.SetMax(aUpper); + rTarget.SetLast(aUpper); + } + else if (rKey == "lower") + { + Time aLower(0, rValue.toInt32()); + rTarget.SetMin(aLower); + rTarget.SetFirst(aLower); + } + else if (rKey == "value") + { + Time aValue(0, rValue.toInt32()); + rTarget.SetTime(aValue); + } + else + { + SAL_INFO("vcl.layout", "unhandled property :" << rKey.getStr()); + } + } +} + + +void VclBuilder::mungeAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment) { for (stringmap::const_iterator aI = rAdjustment.begin(), aEnd = rAdjustment.end(); aI != aEnd; ++aI) { |