diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-08-30 12:41:18 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-09-28 08:48:43 +0100 |
commit | 19863833be0cfc8b72cee5bbc7ebf32f0c423468 (patch) | |
tree | 54095c1015911eb7c85017bbb78535c27da687c2 /vcl | |
parent | b9fbb89eab7ea1f7b5e7b65c95d39f6d67fb269a (diff) |
autoconnect multi-column list stores to dropdowns
Default to importing the first column into the list and the second column as
the additional data and only considering the first column for translation
Change-Id: Ic74a4550167455c83634c4112ab2b698c1d25ea1
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/builder.hxx | 4 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 77 |
2 files changed, 69 insertions, 12 deletions
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx index 0f6f2282c2c5..ae0bc7fb7e51 100644 --- a/vcl/inc/vcl/builder.hxx +++ b/vcl/inc/vcl/builder.hxx @@ -62,7 +62,8 @@ private: struct ListStore { - std::vector<rtl::OString> m_aEntries; + typedef std::vector<rtl::OString> row; + std::vector<row> m_aEntries; }; struct ModelAndId @@ -189,6 +190,7 @@ private: void collectProperty(xmlreader::XmlReader &reader, const rtl::OString &rID, stringmap &rVec); void handleListStore(xmlreader::XmlReader &reader, const rtl::OString &rID); + void handleRow(xmlreader::XmlReader &reader, const rtl::OString &rID, sal_Int32 nRowIndex); void handleAdjustment(const rtl::OString &rID, stringmap &rProperties); void handleTabChild(Window *pParent, xmlreader::XmlReader &reader); diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 49373ee4f39f..50e6b94eb62b 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -536,7 +536,10 @@ Window *VclBuilder::insertObject(Window *pParent, const rtl::OString &rClass, co if (pCurrentChild->IsDialog()) pCurrentChild->SetStyle(pCurrentChild->GetStyle() | WB_SIZEMOVE | WB_3DLOOK); if (pCurrentChild->GetHelpId().isEmpty()) + { pCurrentChild->SetHelpId(m_sHelpRoot + m_sID); + fprintf(stderr, "for toplevel dialog %p %s, set helpid %s\n", this, rID.getStr(), pCurrentChild->GetHelpId().getStr()); + } } else { @@ -782,12 +785,13 @@ void VclBuilder::handleAdjustment(const rtl::OString &rID, stringmap &rPropertie m_pParserState->m_aAdjustments.push_back(AdjustmentAndId(rID, rProperties)); } -void VclBuilder::handleListStore(xmlreader::XmlReader &reader, const rtl::OString &rID) +void VclBuilder::handleRow(xmlreader::XmlReader &reader, const rtl::OString &rID, sal_Int32 nRowIndex) { - m_pParserState->m_aModels.push_back(ModelAndId(rID, new ListStore)); - int nLevel = 1; - sal_Int32 nIndex = 0; + + fprintf(stderr, "handleRow for %s\n", rID.getStr()); + + ListStore::row aRow; while(1) { @@ -807,12 +811,18 @@ void VclBuilder::handleListStore(xmlreader::XmlReader &reader, const rtl::OStrin { bool bTranslated = false; rtl::OString sProperty, sValue; + sal_uInt32 nId = 0; while (reader.nextAttribute(&nsId, &name)) { - if (name.equals(RTL_CONSTASCII_STRINGPARAM("translatable")) && reader.getAttributeValue(false).equals(RTL_CONSTASCII_STRINGPARAM("yes"))) + if (name.equals(RTL_CONSTASCII_STRINGPARAM("id"))) + { + name = reader.getAttributeValue(false); + nId = rtl::OString(name.begin, name.length).toInt32(); + } + else if (nId == 0 && name.equals(RTL_CONSTASCII_STRINGPARAM("translatable")) && reader.getAttributeValue(false).equals(RTL_CONSTASCII_STRINGPARAM("yes"))) { - sValue = getTranslation(rID, rtl::OString::valueOf(nIndex)); + sValue = getTranslation(rID, rtl::OString::valueOf(nRowIndex)); bTranslated = !sValue.isEmpty(); } } @@ -823,9 +833,9 @@ void VclBuilder::handleListStore(xmlreader::XmlReader &reader, const rtl::OStrin if (!bTranslated) sValue = rtl::OString(name.begin, name.length); - m_pParserState->m_aModels.back().m_pModel->m_aEntries.push_back(sValue); - - ++nIndex; + if (aRow.size() < nId+1) + aRow.resize(nId+1); + aRow[nId] = sValue; } } @@ -837,6 +847,45 @@ void VclBuilder::handleListStore(xmlreader::XmlReader &reader, const rtl::OStrin if (!nLevel) break; } + + if (!aRow.empty()) + m_pParserState->m_aModels.back().m_pModel->m_aEntries.push_back(aRow); +} + +void VclBuilder::handleListStore(xmlreader::XmlReader &reader, const rtl::OString &rID) +{ + m_pParserState->m_aModels.push_back(ModelAndId(rID, new ListStore)); + + int nLevel = 1; + sal_Int32 nRowIndex = 0; + + while(1) + { + xmlreader::Span name; + int nsId; + + xmlreader::XmlReader::Result res = reader.nextItem( + xmlreader::XmlReader::TEXT_NONE, &name, &nsId); + + if (res == xmlreader::XmlReader::RESULT_DONE) + break; + + if (res == xmlreader::XmlReader::RESULT_BEGIN) + { + if (name.equals(RTL_CONSTASCII_STRINGPARAM("row"))) + handleRow(reader, rID, nRowIndex++); + else + ++nLevel; + } + + if (res == xmlreader::XmlReader::RESULT_END) + { + --nLevel; + } + + if (!nLevel) + break; + } } Window* VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) @@ -1188,10 +1237,16 @@ bool VclBuilder::replace(rtl::OString sID, Window &rReplacement) void VclBuilder::mungemodel(ListBox &rTarget, ListStore &rStore) { - for (std::vector<rtl::OString>::iterator aI = rStore.m_aEntries.begin(), aEnd = rStore.m_aEntries.end(); + for (std::vector<ListStore::row>::iterator aI = rStore.m_aEntries.begin(), aEnd = rStore.m_aEntries.end(); aI != aEnd; ++aI) { - rTarget.InsertEntry(rtl::OStringToOUString(*aI, RTL_TEXTENCODING_UTF8)); + const ListStore::row &rRow = *aI; + sal_uInt16 nEntry = rTarget.InsertEntry(rtl::OStringToOUString(rRow[0], RTL_TEXTENCODING_UTF8)); + if (rRow.size() > 1) + { + sal_IntPtr nValue = rRow[1].toInt32(); + rTarget.SetEntryData(nEntry, (void*)nValue); + } } if (!rStore.m_aEntries.empty()) rTarget.SelectEntryPos(0); |