summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2012-10-25 14:46:59 +0100
committerCaolán McNamara <caolanm@redhat.com>2012-10-25 15:32:09 +0100
commitd3fb6d227c77198aa0b70d6f5260ff239f5d692c (patch)
tree160da1f4aa2bf1f0034969469b68b01b29b7f3d7 /vcl/source
parent725eba738eae4eee6cd9b833d375db5463833119 (diff)
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/source')
-rw-r--r--vcl/source/window/builder.cxx119
-rw-r--r--vcl/source/window/window2.cxx47
2 files changed, 95 insertions, 71 deletions
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 (