diff options
author | Caolán McNamara <caolanm@redhat.com> | 2012-03-27 14:20:17 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2012-09-28 08:48:11 +0100 |
commit | 70a9db6698eacd45c817159d524876f34156b45c (patch) | |
tree | d7a7a3bd76d995e3c4aed389243a3b43efb58d4b | |
parent | d0570bbebefe33ebccc5c82283cf4a28fbb6eaeb (diff) |
labels, radio buttons, vbox, hbox, button-boxes, text alignment
-rw-r--r-- | vcl/inc/vcl/builder.hxx | 8 | ||||
-rw-r--r-- | vcl/qa/cppunit/builder/demo.ui | 84 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 232 |
3 files changed, 253 insertions, 71 deletions
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx index 4c2ce32d4158..9e7197a07074 100644 --- a/vcl/inc/vcl/builder.hxx +++ b/vcl/inc/vcl/builder.hxx @@ -31,21 +31,25 @@ #include <vcl/dllapi.h> #include <vcl/window.hxx> #include <xmlreader/xmlreader.hxx> +#include <map> #include <vector> class VCL_DLLPUBLIC VclBuilder { private: std::vector<Window*> m_aChildren; + typedef std::map<rtl::OString, rtl::OString> stringmap; public: VclBuilder(Window *pParent, rtl::OUString sUIFile); ~VclBuilder(); Window *get_widget_root(); private: - Window *makeObject(Window *pParent, xmlreader::Span &name); + Window *insertObject(Window *pParent, const rtl::OString &rClass, stringmap &rVec); + Window *makeObject(Window *pParent, const rtl::OString &rClass, bool bVertical=false); + void handleChild(Window *pParent, xmlreader::XmlReader &reader); void handleObject(Window *pParent, xmlreader::XmlReader &reader); - void handleProperty(Window *pWindow, xmlreader::XmlReader &reader); + void collectProperty(xmlreader::XmlReader &reader, stringmap &rVec); }; #endif diff --git a/vcl/qa/cppunit/builder/demo.ui b/vcl/qa/cppunit/builder/demo.ui index d6bd41b8eac0..92904e7417df 100644 --- a/vcl/qa/cppunit/builder/demo.ui +++ b/vcl/qa/cppunit/builder/demo.ui @@ -10,6 +10,48 @@ <property name="can_focus">False</property> <property name="orientation">vertical</property> <property name="spacing">2</property> + <child> + <object class="GtkBox" id="box2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkButton" id="button3"> + <property name="label" translatable="yes">button</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="use_action_appearance">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkRadioButton" id="radiobutton1"> + <property name="label" translatable="yes">radiobutton</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="use_action_appearance">False</property> + <property name="xalign">0</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> <child internal-child="action_area"> <object class="GtkButtonBox" id="dialog-action_area1"> <property name="can_focus">False</property> @@ -51,10 +93,48 @@ </packing> </child> <child> - <object class="GtkLabel" id="label1"> + <object class="GtkBox" id="box1"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">Hello World</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">left</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="xalign">1</property> + <property name="label" translatable="yes">right</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">center</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 0378ea9ba9b0..5bb7b284374a 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -14,7 +14,7 @@ * * The Initial Developer of the Original Code is * Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.) - * Portions created by the Initial Developer are Copyright (C) 2011 the + * Portions created by the Initial Developer are Copyright (C) 2012 the * Initial Developer. All Rights Reserved. * * Contributor(s): Caolán McNamara <caolanm@redhat.com> @@ -36,24 +36,7 @@ VclBuilder::VclBuilder(Window *pParent, rtl::OUString sUri) { xmlreader::XmlReader reader(sUri); - while(1) - { - xmlreader::Span name; - int nsId; - xmlreader::XmlReader::Result res = reader.nextItem( - xmlreader::XmlReader::TEXT_NONE, &name, &nsId); - - if (res == xmlreader::XmlReader::RESULT_BEGIN && - name.equals(RTL_CONSTASCII_STRINGPARAM("object"))) - { - handleObject(pParent, reader); - } - - rtl::OString sFoo(name.begin, name.length); - fprintf(stderr, "interface level is %s\n", sFoo.getStr()); - if (res == xmlreader::XmlReader::RESULT_DONE) - break; - } + handleChild(pParent, reader); for (std::vector<Window*>::iterator aI = m_aChildren.begin(), aEnd = m_aChildren.end(); aI != aEnd; ++aI) @@ -76,56 +59,111 @@ VclBuilder::~VclBuilder() } } -Window *VclBuilder::makeObject(Window *pParent, xmlreader::Span &name) +Window *VclBuilder::makeObject(Window *pParent, const rtl::OString &name, bool bVertical) { Window *pWindow = NULL; - if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkDialog"))) + if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkDialog"))) { pWindow = new Dialog(pParent, WB_SIZEMOVE); } - else if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkBox"))) + else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkBox"))) + { + if (bVertical) + pWindow = new VclVBox(pParent); + else + pWindow = new VclHBox(pParent); + } + else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkButtonBox"))) + { + if (bVertical) + pWindow = new VclVButtonBox(pParent); + else + pWindow = new VclHButtonBox(pParent); + } + else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkButton"))) { - pWindow = new VclHBox(pParent); + pWindow = new PushButton(pParent, WB_CENTER|WB_VCENTER); } - else if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkButton"))) + else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkRadioButton"))) { - pWindow = new PushButton(pParent); + pWindow = new RadioButton(pParent, WB_CENTER|WB_VCENTER); } - else if (name.equals(RTL_CONSTASCII_STRINGPARAM("GtkLabel"))) + else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkLabel"))) { - pWindow = new FixedText(pParent); + pWindow = new FixedText(pParent, WB_CENTER|WB_VCENTER); } else { - fprintf(stderr, "TO-DO, implement %s\n", - rtl::OString(name.begin, name.length).getStr()); + fprintf(stderr, "TO-DO, implement %s\n", name.getStr()); } - fprintf(stderr, "created %p child of %p\n", pWindow, pParent); + fprintf(stderr, "for %s, created %p child of %p\n", name.getStr(), pWindow, pParent); return pWindow; } -void VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) +Window *VclBuilder::insertObject(Window *pParent, const rtl::OString &rClass, stringmap &rMap) { - Window *pCurrentChild = NULL; + bool bVertical = false; + stringmap::iterator aFind = rMap.find(rtl::OString(RTL_CONSTASCII_STRINGPARAM("orientation"))); + if (aFind != rMap.end()) + bVertical = aFind->second.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("vertical")); - xmlreader::Span name; - int nsId; + Window *pCurrentChild = makeObject(pParent, rClass, bVertical); + if (!pCurrentChild) + { + fprintf(stderr, "missing object!\n"); + } - while (reader.nextAttribute(&nsId, &name)) { - rtl::OString sFoo(name.begin, name.length); - fprintf(stderr, "objectlevel attribute: is %s\n", sFoo.getStr()); + if (pCurrentChild) + { + m_aChildren.push_back(pCurrentChild); - if (name.equals(RTL_CONSTASCII_STRINGPARAM("class"))) + for (stringmap::iterator aI = rMap.begin(), aEnd = rMap.end(); aI != aEnd; ++aI) { - name = reader.getAttributeValue(false); - pCurrentChild = makeObject(pParent, name); - if (!pCurrentChild) + const rtl::OString &rKey = aI->first; + const rtl::OString &rValue = aI->second; + if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("label"))) + pCurrentChild->SetText(rtl::OStringToOUString(rValue, RTL_TEXTENCODING_UTF8)); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("xalign"))) { - fprintf(stderr, "missing object!\n"); + WinBits nBits = pCurrentChild->GetStyle(); + nBits &= ~(WB_LEFT | WB_CENTER | WB_RIGHT); + + float f = rValue.toFloat(); + if (f == 0.0) + nBits |= WB_LEFT; + else if (f == 1.0) + nBits |= WB_RIGHT; + else if (f == 0.5) + nBits |= WB_CENTER; + + pCurrentChild->SetStyle(nBits); } + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("yalign"))) + { + WinBits nBits = pCurrentChild->GetStyle(); + nBits &= ~(WB_TOP | WB_VCENTER | WB_BOTTOM); - if (pCurrentChild) - m_aChildren.push_back(pCurrentChild); + float f = rValue.toFloat(); + if (f == 0.0) + nBits |= WB_TOP; + else if (f == 1.0) + nBits |= WB_BOTTOM; + else if (f == 0.5) + nBits |= WB_CENTER; + + pCurrentChild->SetStyle(nBits); + } + else if + ( + rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("expand")) || + rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("fill")) + ) + { + bool bTrue = (rValue[0] == 't' || rValue[0] == 'T' || rValue[0] == '1'); + pCurrentChild->setChildProperty(rKey, bTrue); + } + else + fprintf(stderr, "unhandled property %s\n", rKey.getStr()); } } @@ -134,34 +172,93 @@ void VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) fprintf(stderr, "missing object!\n"); pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back(); } + rMap.clear(); + return pCurrentChild; +} +void VclBuilder::handleChild(Window *pParent, xmlreader::XmlReader &reader) +{ int nLevel = 1; while(1) { + xmlreader::Span name; + int nsId; xmlreader::XmlReader::Result res = reader.nextItem( xmlreader::XmlReader::TEXT_NONE, &name, &nsId); + if (res == xmlreader::XmlReader::RESULT_BEGIN) + { + if (name.equals(RTL_CONSTASCII_STRINGPARAM("object"))) + { + handleObject(pParent, reader); + } + else + ++nLevel; + } + + if (res == xmlreader::XmlReader::RESULT_END) + { + --nLevel; + } + + if (!nLevel) + break; + if (res == xmlreader::XmlReader::RESULT_DONE) break; + } +} - rtl::OString sFoo(name.begin, name.length); - fprintf(stderr, "objectlevel: is %s %d\n", sFoo.getStr(), - res); +void VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) +{ + rtl::OString sClass; - if (res == xmlreader::XmlReader::RESULT_BEGIN) - ++nLevel; + xmlreader::Span name; + int nsId; + + while (reader.nextAttribute(&nsId, &name)) + { + rtl::OString sFoo(name.begin, name.length); - if (res == xmlreader::XmlReader::RESULT_BEGIN && - name.equals(RTL_CONSTASCII_STRINGPARAM("object"))) + if (name.equals(RTL_CONSTASCII_STRINGPARAM("class"))) { - handleObject(pCurrentChild, reader); + name = reader.getAttributeValue(false); + sClass = rtl::OString(name.begin, name.length); } + } + + int nLevel = 1; + + stringmap aProperties; - if (res == xmlreader::XmlReader::RESULT_BEGIN && - name.equals(RTL_CONSTASCII_STRINGPARAM("property"))) + Window *pCurrentChild = NULL; + while(1) + { + xmlreader::XmlReader::Result res = reader.nextItem( + xmlreader::XmlReader::TEXT_NONE, &name, &nsId); + + if (res == xmlreader::XmlReader::RESULT_DONE) + break; + + rtl::OString sFoo(name.begin, name.length); + + fprintf(stderr, "level tag %d %s\n", nLevel, sFoo.getStr()); + + if (res == xmlreader::XmlReader::RESULT_BEGIN) { - handleProperty(pCurrentChild, reader); + if (name.equals(RTL_CONSTASCII_STRINGPARAM("child"))) + { + if (!pCurrentChild) + pCurrentChild = insertObject(pParent, sClass, aProperties); + handleChild(pCurrentChild, reader); + } + else + { + ++nLevel; + if (name.equals(RTL_CONSTASCII_STRINGPARAM("property"))) + collectProperty(reader, aProperties); + } } if (res == xmlreader::XmlReader::RESULT_END) @@ -172,29 +269,30 @@ void VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) if (!nLevel) break; } + + if (!pCurrentChild) + insertObject(pParent, sClass, aProperties); + + fprintf(stderr, "finished %s\n", sClass.getStr()); } -void VclBuilder::handleProperty(Window *pWindow, xmlreader::XmlReader &reader) +void VclBuilder::collectProperty(xmlreader::XmlReader &reader, stringmap &rMap) { - if (!pWindow) - return; - xmlreader::Span name; int nsId; - while (reader.nextAttribute(&nsId, &name)) { + while (reader.nextAttribute(&nsId, &name)) + { rtl::OString sFoo(name.begin, name.length); - fprintf(stderr, "property attribute: is %s\n", sFoo.getStr()); if (name.equals(RTL_CONSTASCII_STRINGPARAM("name"))) { name = reader.getAttributeValue(false); - if (name.equals(RTL_CONSTASCII_STRINGPARAM("label"))) - { - reader.nextItem( - xmlreader::XmlReader::TEXT_NORMALIZED, &name, &nsId); - pWindow->SetText(rtl::OUString(name.begin, name.length, RTL_TEXTENCODING_UTF8)); - } + rtl::OString sProperty(name.begin, name.length); + reader.nextItem( + xmlreader::XmlReader::TEXT_NORMALIZED, &name, &nsId); + rtl::OString sValue(name.begin, name.length); + rMap[sProperty] = sValue; } } } |