vcl/inc/vcl/builder.hxx | 4 - vcl/inc/vcl/layout.hxx | 65 ++++++++++++++++ vcl/inc/vcl/tabpage.hxx | 4 - vcl/inc/vcl/window.hxx | 7 + vcl/source/control/combobox.cxx | 7 + vcl/source/control/lstbox.cxx | 4 - vcl/source/window/builder.cxx | 154 +++++++++++++++++----------------------- vcl/source/window/dialog.cxx | 30 ++++++- vcl/source/window/layout.cxx | 133 +++++++++++++++++++++++++++------- vcl/source/window/tabpage.cxx | 11 +- vcl/source/window/window.cxx | 65 +++++++++++----- vcl/unx/gtk/a11y/atkwindow.cxx | 2 12 files changed, 334 insertions(+), 152 deletions(-)
New commits: commit e1b187d929ed7491e4bad1c0424d031c64d922cb Author: Caolán McNamara <caol...@redhat.com> Date: Mon Apr 16 15:14:42 2012 +0100 basic optimization pass diff --git a/vcl/inc/vcl/tabpage.hxx b/vcl/inc/vcl/tabpage.hxx index 5ff66ce..5edf199 100644 --- a/vcl/inc/vcl/tabpage.hxx +++ b/vcl/inc/vcl/tabpage.hxx @@ -59,8 +59,10 @@ public: virtual void ActivatePage(); virtual void DeactivatePage(); + //To-Do, inherit from VclContainer + using Window::SetPosSizePixel; + virtual void SetPosSizePixel(const Point& rNewPos, const Size& rNewSize); virtual Size GetOptimalSize(WindowSizeType eType) const; - virtual void Resize(); }; #endif // _SV_TABPAGE_HXX diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx index db3bfb2..6756e32 100644 --- a/vcl/source/control/combobox.cxx +++ b/vcl/source/control/combobox.cxx @@ -95,8 +95,9 @@ ComboBox::~ComboBox() SetSubEdit( NULL ); delete mpSubEdit; - delete mpImplLB; + ImplListBox *pImplLB = mpImplLB; mpImplLB = NULL; + delete pImplLB; delete mpFloatWin; delete mpBtn; diff --git a/vcl/source/control/lstbox.cxx b/vcl/source/control/lstbox.cxx index 0f82e65..951c3e9 100644 --- a/vcl/source/control/lstbox.cxx +++ b/vcl/source/control/lstbox.cxx @@ -84,11 +84,11 @@ ListBox::~ListBox() //#109201# ImplCallEventListeners( VCLEVENT_OBJECT_DYING ); - delete mpImplLB; - // Beim zerstoeren des FloatWins macht TH ein GrabFocus auf den Parent, // also diese ListBox => PreNotify()... + ImplListBox *pImplLB = mpImplLB; mpImplLB = NULL; + delete pImplLB; delete mpFloatWin; delete mpImplWin; diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index e810189..fd189ed 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -537,6 +537,22 @@ void Dialog::StateChanged( StateChangedType nType ) if ( nType == STATE_CHANGE_INITSHOW ) { + if (isLayoutEnabled()) + { + maLayoutTimer.Stop(); + + //resize dialog to fit requisition on initial show + const Window *pContainer = GetWindow(WINDOW_FIRSTCHILD); + Size aSize = pContainer->get_preferred_size(); + + Size aMax = GetOptimalSize(WINDOWSIZE_MAXIMUM); + aSize.Width() = std::min(aMax.Width(), aSize.Width()); + aSize.Height() = std::min(aMax.Height(), aSize.Height()); + + SetMinOutputSizePixel(aSize); + SetSizePixel(aSize); + } + if ( GetSettings().GetStyleSettings().GetAutoMnemonic() ) ImplWindowAutoMnemonic( this ); @@ -1022,8 +1038,8 @@ void Dialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal bool Dialog::isLayoutEnabled() const { - //Has one child, and that child is a container => we're layout enabled - return (GetChildCount() == 1 && dynamic_cast<const VclContainer*>(GetChild(0))); + //Child is a container => we're layout enabled + return dynamic_cast<const VclContainer*>(GetWindow(WINDOW_FIRSTCHILD)); } Size Dialog::GetOptimalSize(WindowSizeType eType) const @@ -1031,7 +1047,7 @@ Size Dialog::GetOptimalSize(WindowSizeType eType) const if (eType == WINDOWSIZE_MAXIMUM || !isLayoutEnabled()) return SystemWindow::GetOptimalSize(eType); - Size aSize = GetChild(0)->GetOptimalSize(eType); + Size aSize = GetWindow(WINDOW_FIRSTCHILD)->GetOptimalSize(eType); return Window::CalcWindowSize(aSize); } @@ -1042,13 +1058,17 @@ IMPL_LINK( Dialog, ImplHandleLayoutTimerHdl, void*, EMPTYARG ) aSize.Width() -= mpWindowImpl->mnLeftBorder + mpWindowImpl->mnRightBorder; aSize.Height() -= mpWindowImpl->mnTopBorder + mpWindowImpl->mnBottomBorder; Point aPos(mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder); - GetChild(0)->SetPosSizePixel(aPos, aSize); + GetWindow(WINDOW_FIRSTCHILD)->SetPosSizePixel(aPos, aSize); return 0; } void Dialog::Resize() { - if (hasPendingLayout() || !isLayoutEnabled()) + if (hasPendingLayout()) + return; + if (IsInClose()) + return; + if (!isLayoutEnabled()) return; maLayoutTimer.Start(); } diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index af3763b..5d6b587 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -49,10 +49,8 @@ Size VclBox::calculateRequisition() const sal_uInt16 nVisibleChildren = 0; Size aSize; - sal_uInt16 nChildren = GetChildCount(); - for (sal_uInt16 i = 0; i < nChildren; ++i) + for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT)) { - Window *pChild = GetChild(i); if (!pChild->IsVisible()) continue; ++nVisibleChildren; @@ -92,16 +90,11 @@ Size VclBox::calculateRequisition() const void VclBox::setAllocation(const Size &rAllocation) { - sal_uInt16 nChildren = GetChildCount(); - if (!nChildren) - return; - rtl::OString sExpand(RTL_CONSTASCII_STRINGPARAM("expand")); sal_uInt16 nVisibleChildren = 0, nExpandChildren = 0; - for (sal_uInt16 i = 0; i < nChildren; ++i) + for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT)) { - Window *pChild = GetChild(i); if (!pChild->IsVisible()) continue; ++nVisibleChildren; @@ -149,9 +142,8 @@ void VclBox::setAllocation(const Size &rAllocation) setPrimaryCoordinate(aPos, nPrimaryCoordinate + nAllocPrimaryDimension); } - for (sal_uInt16 i = 0; i < nChildren; ++i) + for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT)) { - Window *pChild = GetChild(i); if (!pChild->IsVisible()) continue; @@ -238,10 +230,8 @@ Size VclButtonBox::calculateRequisition() const sal_Int32 nChildMinHeight = getWidgetStyleProperty<sal_Int32>(sChildMinHeight, DEFAULT_CHILD_MIN_HEIGHT); Size aSize(nChildMinWidth, nChildMinHeight); - sal_uInt16 nChildren = GetChildCount(); - for (sal_uInt16 i = 0; i < nChildren; ++i) + for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT)) { - Window *pChild = GetChild(i); if (!pChild->IsVisible()) continue; ++nVisibleChildren; @@ -276,14 +266,9 @@ Size VclButtonBox::calculateRequisition() const void VclButtonBox::setAllocation(const Size &rAllocation) { - sal_uInt16 nChildren = GetChildCount(); - if (!nChildren) - return; - sal_uInt16 nVisibleChildren = 0; - for (sal_uInt16 i = 0; i < nChildren; ++i) + for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT)) { - Window *pChild = GetChild(i); if (!pChild->IsVisible()) continue; ++nVisibleChildren; @@ -312,9 +297,8 @@ void VclButtonBox::setAllocation(const Size &rAllocation) setPrimaryCoordinate(aPos, nPrimaryCoordinate + nAllocPrimaryDimension - getPrimaryDimension(aRequisition)); - for (sal_uInt16 i = 0; i < nChildren; ++i) + for (Window *pChild = GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT)) { - Window *pChild = GetChild(i); if (!pChild->IsVisible()) continue; diff --git a/vcl/source/window/tabpage.cxx b/vcl/source/window/tabpage.cxx index 0fabc34..cdeb565 100644 --- a/vcl/source/window/tabpage.cxx +++ b/vcl/source/window/tabpage.cxx @@ -205,8 +205,8 @@ void TabPage::DeactivatePage() bool TabPage::isLayoutEnabled() const { - //Has one child, and that child is a container => we're layout enabled - return (GetChildCount() == 1 && dynamic_cast<const VclContainer*>(GetChild(0))); + //Child is a container => we're layout enabled + return dynamic_cast<const VclContainer*>(GetWindow(WINDOW_FIRSTCHILD)); } Size TabPage::GetOptimalSize(WindowSizeType eType) const @@ -215,16 +215,17 @@ Size TabPage::GetOptimalSize(WindowSizeType eType) const return Window::GetOptimalSize(eType); Size aSize; if (isLayoutEnabled()) - aSize = GetChild(0)->GetOptimalSize(eType); + aSize = GetWindow(WINDOW_FIRSTCHILD)->GetOptimalSize(eType); else aSize = getLegacyBestSizeForChildren(*this); return Window::CalcWindowSize(aSize); } -void TabPage::Resize() +void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation) { + Window::SetPosSizePixel(rAllocPos, rAllocation); if (isLayoutEnabled()) - GetChild(0)->SetPosSizePixel(Point(0,0), GetSizePixel()); + GetWindow(WINDOW_FIRSTCHILD)->SetPosSizePixel(Point(0, 0), rAllocation); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 7e27e50..d4e4e5d 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -9637,25 +9637,6 @@ void Window::queue_resize() Dialog *pParent = GetParentDialog(); if (!pParent) return; - if (pParent->IsInClose()) - return; - if (!pParent->isLayoutEnabled()) - return; - if (!pParent->IsReallyShown()) - { - //resize dialog to fit requisition - const Window *pContainer = pParent->GetChild(0); - Size aSize = pContainer->get_preferred_size(); - - Size aMax = pParent->GetOptimalSize(WINDOWSIZE_MAXIMUM); - aSize.Width() = std::min(aMax.Width(), aSize.Width()); - aSize.Height() = std::min(aMax.Height(), aSize.Height()); - - pParent->SetMinOutputSizePixel(aSize); - pParent->SetSizePixel(aSize); - } - if (pParent->hasPendingLayout()) - return; pParent->Resize(); } diff --git a/vcl/unx/gtk/a11y/atkwindow.cxx b/vcl/unx/gtk/a11y/atkwindow.cxx index 9c252c7..4579048 100644 --- a/vcl/unx/gtk/a11y/atkwindow.cxx +++ b/vcl/unx/gtk/a11y/atkwindow.cxx @@ -97,7 +97,7 @@ init_from_window( AtkObject *accessible, Window *pWindow ) default: { - Window *pChild = pWindow->GetChild( 0 ); + Window *pChild = pWindow->GetWindow(WINDOW_FIRSTCHILD); if( pChild ) { if( WINDOW_HELPTEXTWINDOW == pChild->GetType() ) commit 75e9401f49d35572a0ad974f67e4ae50085c85cf Author: Caolán McNamara <caol...@redhat.com> Date: Mon Apr 16 12:15:13 2012 +0100 mpImplLB of ComboBox is NULLed during destruction diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx index 27a008e..db3bfb2 100644 --- a/vcl/source/control/combobox.cxx +++ b/vcl/source/control/combobox.cxx @@ -1103,6 +1103,10 @@ long ComboBox::getMaxWidthScrollBarAndDownButton() const Size ComboBox::CalcMinimumSize() const { Size aSz; + + if (!mpImplLB) + return aSz; + if ( !IsDropDownBox() ) { aSz = mpImplLB->CalcSize( mpImplLB->GetEntryList()->GetEntryCount() ); commit 5efe5acc2cd9173c84111c69b40b4f6047981a77 Author: Caolán McNamara <caol...@redhat.com> Date: Mon Apr 16 11:33:57 2012 +0100 handle some stock buttons diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx index 588505a..d96bafa 100644 --- a/vcl/inc/vcl/builder.hxx +++ b/vcl/inc/vcl/builder.hxx @@ -38,14 +38,14 @@ 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(); + typedef std::map<rtl::OString, rtl::OString> stringmap; private: Window *insertObject(Window *pParent, const rtl::OString &rClass, stringmap &rVec); - Window *makeObject(Window *pParent, const rtl::OString &rClass, bool bVertical=false); + Window *makeObject(Window *pParent, const rtl::OString &rClass, stringmap &rVec); void handleChild(Window *pParent, xmlreader::XmlReader &reader); Window* handleObject(Window *pParent, xmlreader::XmlReader &reader); diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index de6669a..5434d96 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -62,99 +62,108 @@ VclBuilder::~VclBuilder() } } -Window *VclBuilder::makeObject(Window *pParent, const rtl::OString &name, bool bVertical) +namespace +{ + bool extractOrientation(VclBuilder::stringmap &rMap) + { + bool bVertical = false; + VclBuilder::stringmap::iterator aFind = rMap.find(rtl::OString(RTL_CONSTASCII_STRINGPARAM("orientation"))); + if (aFind != rMap.end()) + { + bVertical = aFind->second.equalsIgnoreAsciiCaseL(RTL_CONSTASCII_STRINGPARAM("vertical")); + rMap.erase(aFind); + } + return bVertical; + } + + Window * extractStockAndBuildButton(Window *pParent, VclBuilder::stringmap &rMap) + { + WinBits nBits = WB_CENTER|WB_VCENTER|WB_3DLOOK; + + bool bIsStock = false; + VclBuilder::stringmap::iterator aFind = rMap.find(rtl::OString(RTL_CONSTASCII_STRINGPARAM("use-stock"))); + if (aFind != rMap.end()) + { + bIsStock = toBool(aFind->second); + rMap.erase(aFind); + } + + Window *pWindow = NULL; + + if (bIsStock) + { + rtl::OString sType; + aFind = rMap.find(rtl::OString(RTL_CONSTASCII_STRINGPARAM("label"))); + if (aFind != rMap.end()) + { + sType = aFind->second; + rMap.erase(aFind); + } + + if (sType.equalsL(RTL_CONSTASCII_STRINGPARAM("gtk-ok"))) + pWindow = new OKButton(pParent, nBits); + else if (sType.equalsL(RTL_CONSTASCII_STRINGPARAM("gtk-cancel"))) + pWindow = new CancelButton(pParent, nBits); + else if (sType.equalsL(RTL_CONSTASCII_STRINGPARAM("gtk-help"))) + pWindow = new HelpButton(pParent, nBits); + else + fprintf(stderr, "unknown stock type %s\n", sType.getStr()); + } + + if (!pWindow) + pWindow = new PushButton(pParent, nBits); + return pWindow; + } +} + +Window *VclBuilder::makeObject(Window *pParent, const rtl::OString &name, stringmap &rMap) { Window *pWindow = NULL; if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkDialog"))) - { pWindow = new Dialog(pParent, WB_SIZEMOVE|WB_3DLOOK|WB_CLOSEABLE); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkBox"))) { - // <property name="visible">True</property> - // <property name="can_focus">False</property> - // <property name="orientation">vertical</property> - // <property name="spacing">6</property> - // <property name="homogeneous">True</property> - if (bVertical) + if (extractOrientation(rMap)) pWindow = new VclVBox(pParent); else pWindow = new VclHBox(pParent); } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkButtonBox"))) { - if (bVertical) + if (extractOrientation(rMap)) pWindow = new VclVButtonBox(pParent); else pWindow = new VclHButtonBox(pParent); } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkGrid"))) - { - // <property name="row_spacing">4</property> - // <property name="column_spacing">2</property> - // <property name="row_homogeneous">True</property> - // <property name="column_homogeneous">True</property> pWindow = new VclGrid(pParent); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkFrame"))) - { - // <property name="label_xalign">0</property> - // <property name="shadow_type">none</property> pWindow = new VclFrame(pParent); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkAlignment"))) - { - // <property name="label_xalign">0</property> - // <property name="shadow_type">none</property> pWindow = new VclAlignment(pParent); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkButton"))) - { - pWindow = new PushButton(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK); - } + pWindow = extractStockAndBuildButton(pParent, rMap); else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkRadioButton"))) - { pWindow = new RadioButton(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkCheckButton"))) - { pWindow = new CheckBox(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkSpinButton"))) - { pWindow = new NumericField(pParent, WB_RIGHT|WB_SPIN|WB_BORDER|WB_3DLOOK); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkComboBox"))) - { pWindow = new ListBox(pParent, WB_DROPDOWN|WB_CENTER|WB_VCENTER|WB_3DLOOK); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkLabel"))) - { pWindow = new FixedText(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK); - } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkEntry"))) - { pWindow = new Edit(pParent, WB_LEFT|WB_VCENTER|WB_BORDER|WB_3DLOOK ); - } else - { fprintf(stderr, "TO-DO, implement %s\n", name.getStr()); - } fprintf(stderr, "for %s, created %p child of %p\n", name.getStr(), pWindow, pParent); return pWindow; } Window *VclBuilder::insertObject(Window *pParent, const rtl::OString &rClass, stringmap &rMap) { - 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")); - rMap.erase(aFind); - } - - Window *pCurrentChild = makeObject(pParent, rClass, bVertical); + Window *pCurrentChild = makeObject(pParent, rClass, rMap); if (!pCurrentChild) fprintf(stderr, "missing object!\n"); commit 743aec8579e27d6077f9686837434caa1fa11b2b Author: Caolán McNamara <caol...@redhat.com> Date: Mon Apr 16 11:05:57 2012 +0100 implement Grid and Box properties diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx index 45855ec..1840fb4 100644 --- a/vcl/inc/vcl/layout.hxx +++ b/vcl/inc/vcl/layout.hxx @@ -63,6 +63,23 @@ public: { Show(); } + void set_spacing(int nSpacing) + { + m_nSpacing = nSpacing; + } + int get_spacing() const + { + return m_nSpacing; + } + void set_homogeneous(bool bHomogeneous) + { + m_bHomogeneous = bHomogeneous; + } + bool get_homogeneous() const + { + return m_bHomogeneous; + } + virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue); protected: virtual Size calculateRequisition() const; virtual void setAllocation(const Size &rAllocation); @@ -312,6 +329,7 @@ public: { return m_nColumnSpacing; } + virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue); }; VCL_DLLPUBLIC void setGridAttach(Window &rWidget, sal_Int32 nLeft, sal_Int32 nTop, @@ -325,7 +343,6 @@ public: const Window *get_child() const; }; - class VCL_DLLPUBLIC VclFrame : public VclBin { public: @@ -365,6 +382,11 @@ private: float m_fYScale; }; +/* + * @return true if rValue is "True", "true", "1", etc. + */ +bool toBool(const rtl::OString &rValue); + // retro-fitting utilities // //Get a Size which is large enough to contain all children with diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index 8cd7624..af3763b 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -212,6 +212,17 @@ void VclBox::setAllocation(const Size &rAllocation) } } +bool VclBox::set_property(const rtl::OString &rKey, const rtl::OString &rValue) +{ + if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("spacing"))) + set_spacing(rValue.toInt32()); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("homogeneous"))) + set_homogeneous(toBool(rValue)); + else + return Window::set_property(rKey, rValue); + return true; +} + #define DEFAULT_CHILD_INTERNAL_PAD_X 4 #define DEFAULT_CHILD_INTERNAL_PAD_Y 0 #define DEFAULT_CHILD_MIN_WIDTH 85 @@ -499,6 +510,26 @@ void VclGrid::setAllocation(const Size& rAllocation) } } +bool toBool(const rtl::OString &rValue) +{ + return (rValue[0] == 't' || rValue[0] == 'T' || rValue[0] == '1'); +} + +bool VclGrid::set_property(const rtl::OString &rKey, const rtl::OString &rValue) +{ + if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("row-spacing"))) + set_row_spacing(rValue.toInt32()); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("column-spacing"))) + set_row_spacing(rValue.toInt32()); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("row-homogeneous"))) + set_row_homogeneous(toBool(rValue)); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("column-homogeneous"))) + set_column_homogeneous(toBool(rValue)); + else + return Window::set_property(rKey, rValue); + return true; +} + void setGridAttach(Window &rWidget, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nWidth, sal_Int32 nHeight) { rtl::OString sLeftAttach(RTL_CONSTASCII_STRINGPARAM("left-attach")); @@ -607,7 +638,6 @@ void VclAlignment::setAllocation(const Size &rAllocation) bool VclAlignment::set_property(const rtl::OString &rKey, const rtl::OString &rValue) { - fprintf(stderr, "VclAlignment::set_property %s %s\n", rKey.getStr(), rValue.getStr()); if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("bottom-padding"))) m_nBottomPadding = rValue.toInt32(); else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("left-padding"))) diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index 77404a8..7e27e50 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -9696,10 +9696,7 @@ bool Window::set_property(const rtl::OString &rKey, const rtl::OString &rValue) if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("label"))) SetText(rtl::OStringToOUString(rValue, RTL_TEXTENCODING_UTF8)); else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("visible"))) - { - bool bIsVisible = (rValue[0] == 't' || rValue[0] == 'T' || rValue[0] == '1'); - Show(bIsVisible); - } + Show(toBool(rValue)); else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("xalign"))) { WinBits nBits = GetStyle(); commit 3c4fa3b59808894ed3e66233fb247d3ece58d48c Author: Caolán McNamara <caol...@redhat.com> Date: Mon Apr 16 10:50:23 2012 +0100 move property setting into widgets diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx index 64c43da..45855ec 100644 --- a/vcl/inc/vcl/layout.hxx +++ b/vcl/inc/vcl/layout.hxx @@ -350,6 +350,7 @@ public: , m_fYScale(1.0) { } + virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue); protected: virtual Size calculateRequisition() const; virtual void setAllocation(const Size &rAllocation); diff --git a/vcl/inc/vcl/window.hxx b/vcl/inc/vcl/window.hxx index 01e37ee..ccd4fd2 100644 --- a/vcl/inc/vcl/window.hxx +++ b/vcl/inc/vcl/window.hxx @@ -1093,6 +1093,13 @@ public: */ Size get_preferred_size() const; + /* + * Sets a widget property + * + * @return false if property is unknown + */ + virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue); + virtual void setChildAnyProperty(const rtl::OString &rString, const ::com::sun::star::uno::Any &rValue); virtual ::com::sun::star::uno::Any getWidgetAnyProperty(const rtl::OString &rString) const; diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index a7e98cd..de6669a 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -149,13 +149,14 @@ Window *VclBuilder::insertObject(Window *pParent, const rtl::OString &rClass, st 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")); + rMap.erase(aFind); + } Window *pCurrentChild = makeObject(pParent, rClass, bVertical); if (!pCurrentChild) - { fprintf(stderr, "missing object!\n"); - } if (pCurrentChild) { @@ -165,56 +166,17 @@ Window *VclBuilder::insertObject(Window *pParent, const rtl::OString &rClass, st { 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("visible"))) - { - bool bIsVisible = (rValue[0] == 't' || rValue[0] == 'T' || rValue[0] == '1'); - pCurrentChild->Show(bIsVisible); - } - else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("xalign"))) - { - 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); - - 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("text"))) - pCurrentChild->SetText(rtl::OStringToOUString(rValue, RTL_TEXTENCODING_UTF8)); - else - fprintf(stderr, "unhandled property %s\n", rKey.getStr()); + pCurrentChild->set_property(rKey, rValue); } } + rMap.clear(); + if (!pCurrentChild) { fprintf(stderr, "missing object!\n"); pCurrentChild = m_aChildren.empty() ? pParent : m_aChildren.back(); } - rMap.clear(); return pCurrentChild; } @@ -428,10 +390,11 @@ void VclBuilder::collectProperty(xmlreader::XmlReader &reader, stringmap &rMap) { name = reader.getAttributeValue(false); rtl::OString sProperty(name.begin, name.length); + sProperty = sProperty.replace('_', '-'); reader.nextItem( xmlreader::XmlReader::TEXT_NORMALIZED, &name, &nsId); rtl::OString sValue(name.begin, name.length); - rMap[sProperty] = sValue.replace('_', '-');; + rMap[sProperty] = sValue.replace('_', '-'); } } } diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index af195ac..8cd7624 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -605,6 +605,30 @@ void VclAlignment::setAllocation(const Size &rAllocation) pChild->SetPosSizePixel(aChildPos, aAllocation); } +bool VclAlignment::set_property(const rtl::OString &rKey, const rtl::OString &rValue) +{ + fprintf(stderr, "VclAlignment::set_property %s %s\n", rKey.getStr(), rValue.getStr()); + if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("bottom-padding"))) + m_nBottomPadding = rValue.toInt32(); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("left-padding"))) + m_nLeftPadding = rValue.toInt32(); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("right-padding"))) + m_nRightPadding = rValue.toInt32(); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("top-padding"))) + m_nTopPadding = rValue.toInt32(); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("xalign"))) + m_fXAlign = rValue.toFloat(); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("xscale"))) + m_fXScale = rValue.toFloat(); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("yalign"))) + m_fYAlign = rValue.toFloat(); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("yscale"))) + m_fYScale = rValue.toFloat(); + else + return Window::set_property(rKey, rValue); + return true; +} + Size getLegacyBestSizeForChildren(const Window &rWindow) { Rectangle aBounds; diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx index d16b831..77404a8 100644 --- a/vcl/source/window/window.cxx +++ b/vcl/source/window/window.cxx @@ -9691,4 +9691,53 @@ Size Window::get_preferred_size() const return aRet; } +bool Window::set_property(const rtl::OString &rKey, const rtl::OString &rValue) +{ + if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("label"))) + SetText(rtl::OStringToOUString(rValue, RTL_TEXTENCODING_UTF8)); + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("visible"))) + { + bool bIsVisible = (rValue[0] == 't' || rValue[0] == 'T' || rValue[0] == '1'); + Show(bIsVisible); + } + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("xalign"))) + { + WinBits nBits = 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; + + SetStyle(nBits); + } + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("yalign"))) + { + WinBits nBits = GetStyle(); + nBits &= ~(WB_TOP | WB_VCENTER | WB_BOTTOM); + + 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; + + SetStyle(nBits); + } + else if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("text"))) + SetText(rtl::OStringToOUString(rValue, RTL_TEXTENCODING_UTF8)); + else + { + fprintf(stderr, "unhandled property %s\n", rKey.getStr()); + return false; + } + return true; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ commit 0c2fdf91727070e7f210fcb22b2135369c04d501 Author: Caolán McNamara <caol...@redhat.com> Date: Mon Apr 16 10:12:57 2012 +0100 implement basic VclAlignment diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx index cff021f..64c43da 100644 --- a/vcl/inc/vcl/layout.hxx +++ b/vcl/inc/vcl/layout.hxx @@ -317,15 +317,53 @@ public: VCL_DLLPUBLIC void setGridAttach(Window &rWidget, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nWidth = 1, sal_Int32 nHeight = 1); -class VCL_DLLPUBLIC VclFrame : public VclContainer +class VCL_DLLPUBLIC VclBin : public VclContainer { public: - VclFrame(Window *pParent) : VclContainer(pParent) {} + VclBin(Window *pParent) : VclContainer(pParent) {} + Window *get_child(); + const Window *get_child() const; +}; + + +class VCL_DLLPUBLIC VclFrame : public VclBin +{ +public: + VclFrame(Window *pParent) : VclBin(pParent) {} protected: virtual Size calculateRequisition() const; virtual void setAllocation(const Size &rAllocation); }; +class VCL_DLLPUBLIC VclAlignment : public VclBin +{ +public: + VclAlignment(Window *pParent) + : VclBin(pParent) + , m_nBottomPadding(0) + , m_nLeftPadding(0) + , m_nRightPadding(0) + , m_nTopPadding(0) + , m_fXAlign(0.0) + , m_fXScale(1.0) + , m_fYAlign(0.0) + , m_fYScale(1.0) + { + } +protected: + virtual Size calculateRequisition() const; + virtual void setAllocation(const Size &rAllocation); +private: + sal_Int32 m_nBottomPadding; + sal_Int32 m_nLeftPadding; + sal_Int32 m_nRightPadding; + sal_Int32 m_nTopPadding; + float m_fXAlign; + float m_fXScale; + float m_fYAlign; + float m_fYScale; +}; + // retro-fitting utilities // //Get a Size which is large enough to contain all children with diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 40ba994..a7e98cd 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -102,6 +102,12 @@ Window *VclBuilder::makeObject(Window *pParent, const rtl::OString &name, bool b // <property name="shadow_type">none</property> pWindow = new VclFrame(pParent); } + else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkAlignment"))) + { + // <property name="label_xalign">0</property> + // <property name="shadow_type">none</property> + pWindow = new VclAlignment(pParent); + } else if (name.equalsL(RTL_CONSTASCII_STRINGPARAM("GtkButton"))) { pWindow = new PushButton(pParent, WB_CENTER|WB_VCENTER|WB_3DLOOK); diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx index 0764a8c..af195ac 100644 --- a/vcl/source/window/layout.cxx +++ b/vcl/source/window/layout.cxx @@ -511,6 +511,18 @@ void setGridAttach(Window &rWidget, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 n rWidget.setChildProperty<sal_Int32>(sHeight, nHeight); } +const Window *VclBin::get_child() const +{ + const WindowImpl* pWindowImpl = ImplGetWindowImpl(); + + return pWindowImpl->mpLastChild; +} + +Window *VclBin::get_child() +{ + return const_cast<Window*>(const_cast<const VclBin*>(this)->get_child()); +} + //To-Do, hook a DecorationView into VclFrame ? Size VclFrame::calculateRequisition() const @@ -519,8 +531,8 @@ Size VclFrame::calculateRequisition() const WindowImpl* pWindowImpl = ImplGetWindowImpl(); - Window *pChild = pWindowImpl->mpLastChild; - Window *pLabel = pChild != pWindowImpl->mpFirstChild ? pWindowImpl->mpFirstChild : NULL; + const Window *pChild = get_child(); + const Window *pLabel = pChild != pWindowImpl->mpFirstChild ? pWindowImpl->mpFirstChild : NULL; if (pChild && pChild->IsVisible()) aRet = pChild->GetOptimalSize(WINDOWSIZE_PREFERRED); @@ -544,7 +556,7 @@ void VclFrame::setAllocation(const Size &rAllocation) WindowImpl* pWindowImpl = ImplGetWindowImpl(); //The label widget is the last (of two) children - Window *pChild = pWindowImpl->mpLastChild; + Window *pChild = get_child(); Window *pLabel = pChild != pWindowImpl->mpFirstChild ? pWindowImpl->mpFirstChild : NULL; if (pLabel && pLabel->IsVisible()) @@ -562,11 +574,42 @@ void VclFrame::setAllocation(const Size &rAllocation) pChild->SetPosSizePixel(aChildPos, aAllocation); } +Size VclAlignment::calculateRequisition() const +{ + Size aRet(m_nLeftPadding + m_nRightPadding, + m_nTopPadding + m_nBottomPadding); + + const Window *pChild = get_child(); + if (pChild && pChild->IsVisible()) + { + Size aChildSize = pChild->GetOptimalSize(WINDOWSIZE_PREFERRED); + aRet.Width() += aChildSize.Width(); + aRet.Height() += aChildSize.Height(); + } + + return aRet; +} + +void VclAlignment::setAllocation(const Size &rAllocation) +{ + Window *pChild = get_child(); + if (!pChild || !pChild->IsVisible()) + return; + + Point aChildPos(m_nLeftPadding, m_nTopPadding); + + Size aAllocation; + aAllocation.Width() = rAllocation.Width() - (m_nLeftPadding + m_nRightPadding); + aAllocation.Height() = rAllocation.Height() - (m_nTopPadding + m_nBottomPadding); + + pChild->SetPosSizePixel(aChildPos, aAllocation); +} + Size getLegacyBestSizeForChildren(const Window &rWindow) { Rectangle aBounds; - for (Window* pChild = rWindow.GetWindow(WINDOW_FIRSTCHILD); pChild; + for (const Window* pChild = rWindow.GetWindow(WINDOW_FIRSTCHILD); pChild; pChild = pChild->GetWindow(WINDOW_NEXT)) { if (!pChild->IsVisible())
_______________________________________________ Libreoffice-commits mailing list Libreoffice-commits@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits