diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-10-25 14:46:59 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-10-25 15:32:09 +0100 |
commit | d3fb6d227c77198aa0b70d6f5260ff239f5d692c (patch) | |
tree | 160da1f4aa2bf1f0034969469b68b01b29b7f3d7 /vcl | |
parent | remove all traces of saxon (diff) | |
download | core-d3fb6d227c77198aa0b70d6f5260ff239f5d692c.tar.gz core-d3fb6d227c77198aa0b70d6f5260ff239f5d692c.zip |
remove .ui mark-up in favor of font attributes
so we can keep translations markup free, and it matches
better our existing font use in controls
Change-Id: Ib762030f8bf831f2b0afabdd643508e660ad9266
See: https://live.gnome.org/GnomeGoals/RemoveMarkupInMessages
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/builder.hxx | 5 | ||||
-rw-r--r-- | vcl/inc/vcl/window.hxx | 7 | ||||
-rw-r--r-- | vcl/qa/cppunit/builder/demo.ui | 11 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 119 | ||||
-rw-r--r-- | vcl/source/window/window2.cxx | 47 | ||||
-rw-r--r-- | vcl/uiconfig/ui/printdialog.ui | 42 |
6 files changed, 134 insertions, 97 deletions
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx index 8ef33278acc2..de8da5154e84 100644 --- a/vcl/inc/vcl/builder.hxx +++ b/vcl/inc/vcl/builder.hxx @@ -165,7 +165,9 @@ public: //taking ownership of it bool replace(OString sID, Window &rReplacement); private: - Window *insertObject(Window *pParent, const OString &rClass, const OString &rID, stringmap &rVec); + Window *insertObject(Window *pParent, const OString &rClass, const OString &rID, + stringmap &rProps, stringmap &rPangoAttributes); + Window *makeObject(Window *pParent, const OString &rClass, const OString &rID, stringmap &rVec); bool extractGroup(const OString &id, stringmap &rVec); bool extractModel(const OString &id, stringmap &rVec); @@ -181,6 +183,7 @@ private: void handlePacking(Window *pCurrent, xmlreader::XmlReader &reader); void applyPackingProperty(Window *pCurrent, xmlreader::XmlReader &reader); void collectProperty(xmlreader::XmlReader &reader, const OString &rID, stringmap &rVec); + void collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap); void handleListStore(xmlreader::XmlReader &reader, const OString &rID); void handleRow(xmlreader::XmlReader &reader, const OString &rID, sal_Int32 nRowIndex); diff --git a/vcl/inc/vcl/window.hxx b/vcl/inc/vcl/window.hxx index 54a9ba9bf394..90543e4207ee 100644 --- a/vcl/inc/vcl/window.hxx +++ b/vcl/inc/vcl/window.hxx @@ -1222,6 +1222,13 @@ public: virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue); /* + * Sets a font attribute + * + * @return false if attribute is unknown + */ + bool set_font_attribute(const rtl::OString &rKey, const rtl::OString &rValue); + + /* * Move this widget to be the nNewPosition'd child of its parent */ void reorderWithinParent(sal_uInt16 nNewPosition); diff --git a/vcl/qa/cppunit/builder/demo.ui b/vcl/qa/cppunit/builder/demo.ui index b83fd65d5622..1b31adcb4511 100644 --- a/vcl/qa/cppunit/builder/demo.ui +++ b/vcl/qa/cppunit/builder/demo.ui @@ -348,7 +348,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Frame Label</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -557,7 +556,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Make Title Pages</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -703,7 +701,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Page Numbering</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -763,7 +760,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Edit Page Properties</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -937,7 +933,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Type</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -1100,7 +1095,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Zoom factor</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -1237,7 +1231,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">View layout</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -1299,7 +1292,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Level</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -1589,7 +1581,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Numbering</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -1651,7 +1642,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Level</property> - <property name="use_markup">True</property> </object> </child> </object> @@ -1854,7 +1844,6 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Position and spacing</property> - <property name="use_markup">True</property> </object> </child> </object> diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 8c330d083a08..34238e26e5aa 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -328,18 +328,6 @@ namespace return bVertical; } - bool extractMarkup(VclBuilder::stringmap &rMap) - { - bool bUseMarkup = false; - VclBuilder::stringmap::iterator aFind = rMap.find(OString("use-markup")); - if (aFind != rMap.end()) - { - bUseMarkup = toBool(aFind->second); - rMap.erase(aFind); - } - return bUseMarkup; - } - bool extractInconsistent(VclBuilder::stringmap &rMap) { bool bInconsistent = false; @@ -837,50 +825,10 @@ namespace { return pWindow->GetType() == WINDOW_TABPAGE; } - - //super cheesy markup, just globally set bold and/or - //italic if any tag exists and return detagged string - OString handleMarkup(Window &rWindow, const OString &rLabel) - { - OStringBuffer aBuf; - - xmlreader::XmlReader reader(rLabel.getStr(), rLabel.getLength()); - xmlreader::Span name; - int nsId; - - while(1) - { - xmlreader::XmlReader::Result res = reader.nextItem( - xmlreader::XmlReader::TEXT_RAW, &name, &nsId); - - if (res == xmlreader::XmlReader::RESULT_BEGIN) - { - if (name.equals(RTL_CONSTASCII_STRINGPARAM("b"))) - { - Font aFont(rWindow.GetControlFont()); - aFont.SetWeight(WEIGHT_BOLD); - rWindow.SetControlFont(aFont); - } - else if (name.equals(RTL_CONSTASCII_STRINGPARAM("i"))) - { - Font aFont(rWindow.GetControlFont()); - aFont.SetItalic(ITALIC_NORMAL); - rWindow.SetControlFont(aFont); - } - } - - if (res == xmlreader::XmlReader::RESULT_TEXT) - aBuf.append(name.begin, name.length); - - if (res == xmlreader::XmlReader::RESULT_DONE) - break; - } - - return aBuf.makeStringAndClear(); - } } -Window *VclBuilder::insertObject(Window *pParent, const OString &rClass, const OString &rID, stringmap &rMap) +Window *VclBuilder::insertObject(Window *pParent, const OString &rClass, + const OString &rID, stringmap &rProps, stringmap &rPango) { Window *pCurrentChild = NULL; @@ -891,7 +839,7 @@ Window *VclBuilder::insertObject(Window *pParent, const OString &rClass, const O if (pCurrentChild->IsDialog()) { Dialog *pDialog = (Dialog*)pCurrentChild; - pDialog->doDeferredInit(extractResizable(rMap)); + pDialog->doDeferredInit(extractResizable(rProps)); m_bToplevelHasDeferredInit = false; } if (pCurrentChild->GetHelpId().isEmpty()) @@ -909,32 +857,28 @@ Window *VclBuilder::insertObject(Window *pParent, const OString &rClass, const O //been seen yet, then make unattached widgets parent-less toplevels if (pParent == m_pParent && m_bToplevelHasDeferredInit) pParent = NULL; - pCurrentChild = makeObject(pParent, rClass, rID, rMap); + pCurrentChild = makeObject(pParent, rClass, rID, rProps); } if (pCurrentChild) { - //Support super-basic bold/italic hints - if (extractMarkup(rMap)) + for (stringmap::iterator aI = rProps.begin(), aEnd = rProps.end(); aI != aEnd; ++aI) { - VclBuilder::stringmap::iterator aFind = rMap.find(OString("label")); - if (aFind != rMap.end()) - { - OString &rLabel = aFind->second; - if (rLabel.indexOf('<') != -1) - rLabel = handleMarkup(*pCurrentChild, aFind->second); - } + const OString &rKey = aI->first; + const OString &rValue = aI->second; + pCurrentChild->set_property(rKey, rValue); } - for (stringmap::iterator aI = rMap.begin(), aEnd = rMap.end(); aI != aEnd; ++aI) + for (stringmap::iterator aI = rPango.begin(), aEnd = rPango.end(); aI != aEnd; ++aI) { const OString &rKey = aI->first; const OString &rValue = aI->second; - pCurrentChild->set_property(rKey, rValue); + pCurrentChild->set_font_attribute(rKey, rValue); } } - rMap.clear(); + rProps.clear(); + rPango.clear(); if (!pCurrentChild) pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back().m_pWindow; @@ -1186,6 +1130,32 @@ void VclBuilder::handleChild(Window *pParent, xmlreader::XmlReader &reader) } } +void VclBuilder::collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap) +{ + xmlreader::Span span; + int nsId; + + OString sProperty; + OString sValue; + + while (reader.nextAttribute(&nsId, &span)) + { + if (span.equals(RTL_CONSTASCII_STRINGPARAM("name"))) + { + span = reader.getAttributeValue(false); + sProperty = OString(span.begin, span.length); + } + else if (span.equals(RTL_CONSTASCII_STRINGPARAM("value"))) + { + span = reader.getAttributeValue(false); + sValue = OString(span.begin, span.length); + } + } + + if (!sProperty.isEmpty()) + rMap[sProperty] = sValue; +} + void VclBuilder::handleAdjustment(const OString &rID, stringmap &rProperties) { m_pParserState->m_aAdjustments.push_back(AdjustmentAndId(rID, rProperties)); @@ -1329,7 +1299,7 @@ Window* VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) int nLevel = 1; - stringmap aProperties; + stringmap aProperties, aPangoAttributes; if (!sPattern.isEmpty()) aProperties[OString("pattern")] = sPattern; @@ -1348,7 +1318,10 @@ Window* VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) if (name.equals(RTL_CONSTASCII_STRINGPARAM("child"))) { if (!pCurrentChild) - pCurrentChild = insertObject(pParent, sClass, sID, aProperties); + { + pCurrentChild = insertObject(pParent, sClass, sID, + aProperties, aPangoAttributes); + } handleChild(pCurrentChild, reader); } else @@ -1356,6 +1329,8 @@ Window* VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) ++nLevel; if (name.equals(RTL_CONSTASCII_STRINGPARAM("property"))) collectProperty(reader, sID, aProperties); + else if (name.equals(RTL_CONSTASCII_STRINGPARAM("attribute"))) + collectPangoAttribute(reader, aPangoAttributes); } } @@ -1375,7 +1350,7 @@ Window* VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) } if (!pCurrentChild) - pCurrentChild = insertObject(pParent, sClass, sID, aProperties); + pCurrentChild = insertObject(pParent, sClass, sID, aProperties, aPangoAttributes); return pCurrentChild; } @@ -1528,6 +1503,8 @@ void VclBuilder::collectProperty(xmlreader::XmlReader &reader, const OString &rI if (!sProperty.isEmpty()) { sProperty = sProperty.replace('_', '-'); + //https://live.gnome.org/GnomeGoals/RemoveMarkupInMessages + SAL_WARN_IF(sProperty == "use-markup", "vcl.layout", "Use pango attributes instead of mark-up"); rMap[sProperty] = sValue; } } diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx index 69d580bd5966..0006d0febe53 100644 --- a/vcl/source/window/window2.cxx +++ b/vcl/source/window/window2.cxx @@ -1974,6 +1974,53 @@ namespace } } +bool Window::set_font_attribute(const OString &rKey, const OString &rValue) +{ + if (rKey == "weight") + { + Font aFont(GetControlFont()); + if (rValue == "thin") + aFont.SetWeight(WEIGHT_THIN); + else if (rValue == "ultralight") + aFont.SetWeight(WEIGHT_ULTRALIGHT); + else if (rValue == "light") + aFont.SetWeight(WEIGHT_LIGHT); + else if (rValue == "book") + aFont.SetWeight(WEIGHT_SEMILIGHT); + else if (rValue == "normal") + aFont.SetWeight(WEIGHT_NORMAL); + else if (rValue == "medium") + aFont.SetWeight(WEIGHT_MEDIUM); + else if (rValue == "semibold") + aFont.SetWeight(WEIGHT_SEMIBOLD); + else if (rValue == "bold") + aFont.SetWeight(WEIGHT_BOLD); + else if (rValue == "ultrabold") + aFont.SetWeight(WEIGHT_ULTRABOLD); + else + aFont.SetWeight(WEIGHT_BLACK); + SetControlFont(aFont); + } + else if (rKey == "style") + { + Font aFont(GetControlFont()); + if (rValue == "normal") + aFont.SetItalic(ITALIC_NONE); + else if (rValue == "oblique") + aFont.SetItalic(ITALIC_OBLIQUE); + else if (rValue == "italic") + aFont.SetItalic(ITALIC_NORMAL); + SetControlFont(aFont); + } + else + { + SAL_INFO("vcl.layout", "unhandled font attribute: " << rKey.getStr()); + return false; + } + return true; +} + + bool Window::set_property(const OString &rKey, const OString &rValue) { if ( diff --git a/vcl/uiconfig/ui/printdialog.ui b/vcl/uiconfig/ui/printdialog.ui index 507742ec4db2..b806228adf09 100644 --- a/vcl/uiconfig/ui/printdialog.ui +++ b/vcl/uiconfig/ui/printdialog.ui @@ -372,8 +372,10 @@ <object class="GtkLabel" id="label5"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Printer</b></property> - <property name="use_markup">True</property> + <property name="label" translatable="yes">Printer</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> </child> </object> @@ -712,8 +714,10 @@ <object class="GtkLabel" id="label13"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Range and copies</b></property> - <property name="use_markup">True</property> + <property name="label" translatable="yes">Range and copies</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> </child> </object> @@ -769,8 +773,10 @@ <object class="GtkLabel" id="label15"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Print</b></property> - <property name="use_markup">True</property> + <property name="label" translatable="yes">Print</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> </child> </object> @@ -897,8 +903,10 @@ <object class="GtkLabel" id="label11"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Print</b></property> - <property name="use_markup">True</property> + <property name="label" translatable="yes">Print</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> </child> </object> @@ -1292,8 +1300,10 @@ <object class="GtkLabel" id="label18"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Layout</b></property> - <property name="use_markup">True</property> + <property name="label" translatable="yes">Layout</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> </child> </object> @@ -1350,8 +1360,10 @@ <object class="GtkLabel" id="label3"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Page sides</b></property> - <property name="use_markup">True</property> + <property name="label" translatable="yes">Page sides</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> </child> </object> @@ -1453,8 +1465,10 @@ <object class="GtkLabel" id="label21"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes"><b>Options</b></property> - <property name="use_markup">True</property> + <property name="label" translatable="yes">Options</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> </child> </object> |