[Libreoffice-commits] .: Branch 'feature/layout' - vcl/inc vcl/source
Ricardo Cruz
rpmcruz at kemper.freedesktop.org
Sun Dec 19 19:01:49 PST 2010
vcl/inc/vcl/box.hxx | 3 +
vcl/inc/vcl/layout.hxx | 3 +
vcl/source/layout/box.cxx | 124 +++++++++++++------------------------------
vcl/source/layout/layout.cxx | 38 +++++++++++++
4 files changed, 84 insertions(+), 84 deletions(-)
New commits:
commit 508f7504439d9c83287bf6974f9ac8f8da61ee4f
Author: Ricardo Cruz <rpmcruz at alunos.dcc.fc.up.pt>
Date: Mon Dec 20 03:01:23 2010 +0000
Box: cut code | layout.hxx: added GetProperty() method
diff --git a/vcl/inc/vcl/box.hxx b/vcl/inc/vcl/box.hxx
index c58c936..1c82fd9 100644
--- a/vcl/inc/vcl/box.hxx
+++ b/vcl/inc/vcl/box.hxx
@@ -76,6 +76,9 @@ protected:
Size m_requisition; /* cached */
Rectangle m_allocation;
Widget m_parent;
+ // to help cut on code: these variables are 0 or 1 if x
+ // or y respectively represents the primary axis in this Box
+ int prim : 2, secu : 2;
};
struct VCL_DLLPUBLIC HBox : public Box {
diff --git a/vcl/inc/vcl/layout.hxx b/vcl/inc/vcl/layout.hxx
index 3fe1c90..5f6d791 100644
--- a/vcl/inc/vcl/layout.hxx
+++ b/vcl/inc/vcl/layout.hxx
@@ -66,6 +66,9 @@ public:
bool operator == (const Widget &other) const;
bool operator != (const Widget &other) const;
+ bool GetPropertyBool (const char *property);
+ int GetPropertyInt (const char *property);
+
static Widget NIL;
private:
diff --git a/vcl/source/layout/box.cxx b/vcl/source/layout/box.cxx
index 70be531..bce94b7 100644
--- a/vcl/source/layout/box.cxx
+++ b/vcl/source/layout/box.cxx
@@ -37,7 +37,10 @@ Box::ChildData::ChildData (Widget &w, bool e, bool f)
Box::Box (Orientation orientation, bool homogeneous, int spacing)
: m_orientation (orientation), m_homogeneous (homogeneous), m_spacing (spacing), m_borderWidth (0), m_allocation (Rectangle(0,0,0,0)), m_parent (Widget::NIL)
-{}
+{
+ prim = (orientation == HORIZONTAL) ? 0 : 1;
+ secu = !prim;
+}
void Box::Pack (Widget &child, bool expand, bool fill)
{
@@ -82,79 +85,35 @@ void Box::SetBorderWidth (int borderWidth)
QueueResize (this);
}
-// GPoint uses primary/secundary axis, rather than X/Y
-struct GVector {
- GVector (const Box *box)
- : m_orientation (box->GetOrientation()), prim (0), secun (0) {}
-
- GVector (const Box *box, long x, long y)
- : m_orientation (box->GetOrientation())
- { Set (x, y); }
-
- GVector (const Box *box, const Size &size)
- : m_orientation (box->GetOrientation())
- { Set (size.getWidth(), size.getHeight()); }
-
- GVector (const GVector &other)
- : m_orientation (other.m_orientation), prim (other.prim), secun (other.secun) {}
-
- GVector & operator = (const GVector &other) {
- m_orientation = other.m_orientation;
- prim = other.prim;
- secun = other.secun;
- return *this;
- }
-
- long GetX() const
- { return m_orientation == Box::HORIZONTAL ? prim : secun; }
- long GetY() const
- { return m_orientation == Box::HORIZONTAL ? secun : prim; }
-
- Size GetSize() const
- { return Size (GetX(), GetY()); }
-
- void Set (long x, long y) {
- prim = m_orientation == Box::HORIZONTAL ? x : y;
- secun = m_orientation == Box::HORIZONTAL ? y : x;
- }
-
- Box::Orientation m_orientation;
- long prim, secun;
-};
-
-
Size Box::SizeRequest()
{
if (m_requisition.Width() != 0 && m_requisition.Height() != 0)
return m_requisition;
-
- GVector reqSize (this);
- int visibleChildren = 0;
-
+ long reqSize[2] = { 0 };
+ int n_visible = 0;
for (std::list <ChildData>::iterator it = m_children.begin();
it != m_children.end(); it++) {
ChildData &child = *it;
if (child.widget.IsVisible()) {
child.requisition = child.widget.SizeRequest();
- GVector reqChildSize (this, child.requisition);
-
+ long childReqSize[2] = { child.requisition.Width(), child.requisition.Height() };
if (m_homogeneous)
- reqSize.prim = SAL_MAX (reqSize.prim, reqChildSize.prim);
+ reqSize[prim] = SAL_MAX (reqSize[prim], childReqSize[prim]);
else
- reqSize.prim += reqChildSize.prim;
- reqSize.secun = SAL_MAX (reqSize.secun, reqChildSize.secun);
- visibleChildren++;
+ reqSize[prim] += childReqSize[prim];
+ reqSize[secu] = SAL_MAX (reqSize[secu], childReqSize[secu]);
+ n_visible++;
}
}
if (m_homogeneous)
- reqSize.prim *= visibleChildren;
- if (visibleChildren > 1)
- reqSize.prim += m_spacing * (visibleChildren-1);
- reqSize.prim += m_borderWidth * 2;
- reqSize.secun += m_borderWidth * 2;
+ reqSize[prim] *= n_visible;
+ if (n_visible > 1)
+ reqSize[prim] += m_spacing * (n_visible-1);
+ reqSize[prim] += m_borderWidth * 2;
+ reqSize[secu] += m_borderWidth * 2;
- return (m_requisition = reqSize.GetSize());
+ return (m_requisition = Size (reqSize[0], reqSize[1]));
}
void Box::SizeAllocate (long x, long y, long width, long height)
@@ -164,7 +123,7 @@ void Box::SizeAllocate (long x, long y, long width, long height)
width -= m_borderWidth * 2; height -= m_borderWidth * 2;
SizeRequest(); // ensure was called beforehand
- int visibleChildren = 0, expandChildren = 0;
+ int n_visible = 0, n_expand = 0;
long sameChildSize = 0;
for (std::list <ChildData>::iterator it = m_children.begin();
@@ -172,50 +131,47 @@ void Box::SizeAllocate (long x, long y, long width, long height)
ChildData &child = *it;
if (child.widget.IsVisible()) {
if (child.expand)
- expandChildren++;
+ n_expand++;
if (m_homogeneous) {
- GVector childReqSize (this, child.requisition);
- sameChildSize = SAL_MAX (sameChildSize, childReqSize.prim);
+ long childReqSize[2] = { child.requisition.Width(), child.requisition.Height() };
+ sameChildSize = SAL_MAX (sameChildSize, childReqSize[prim]);
}
- visibleChildren++;
+ n_visible++;
}
}
- if (!visibleChildren) return;
+ if (!n_visible) return;
long extraSpace = 0;
- GVector allocSize (this, width, height);
- if (expandChildren) {
- GVector reqSize = GVector (this, m_requisition);
- extraSpace = SAL_MAX (0, (allocSize.prim - reqSize.prim) / expandChildren);
+ long allocSize[2] = { width, height };
+ if (n_expand > 0) {
+ long reqSize[2] = { m_requisition.Width(), m_requisition.Height() };
+ extraSpace = SAL_MAX (0, (allocSize[prim] - reqSize[prim]) / n_expand);
}
- GVector childPoint (this, x, y);
- GVector childSize (this);
- childSize.secun = SAL_MAX (1, allocSize.secun);
+ long childPoint[2] = { x, y }, childSize[2] = { 0 };
+ childSize[secu] = allocSize[secu];
for (std::list <ChildData>::iterator it = m_children.begin();
it != m_children.end(); it++) {
ChildData &child = *it;
- GVector childReqSize (this, child.requisition);
- childSize.prim = childReqSize.prim;
+ long childReqSize[2] = { child.requisition.Width(), child.requisition.Height() };
+ childSize[prim] = childReqSize[prim];
if (m_homogeneous)
- childSize.prim = sameChildSize;
+ childSize[prim] = sameChildSize;
if (child.expand)
- childSize.prim += extraSpace;
+ childSize[prim] += extraSpace;
- GVector innerChildPoint (childPoint);
- GVector innerChildSize (childSize);
+ long _childPoint[2] = { childPoint[0], childPoint[1] };
+ long _childSize[2] = { childSize[0], childSize[1] };
if (!child.fill) {
- innerChildSize = childReqSize;
- innerChildPoint.prim += (childSize.prim - innerChildSize.prim) / 2;
- innerChildPoint.secun += (childSize.secun - innerChildSize.secun) / 2;
+ _childSize[0] = childReqSize[0]; _childSize[1] = childReqSize[1];
+ _childPoint[prim] += (childSize[prim] - _childSize[prim]) / 2;
+ _childPoint[secu] += (childSize[secu] - _childSize[secu]) / 2;
}
- child.widget.SizeAllocate (
- innerChildPoint.GetX(), innerChildPoint.GetY(),
- innerChildSize.GetX(), innerChildSize.GetY());
- childPoint.prim += childSize.prim + m_spacing;
+ child.widget.SizeAllocate (_childPoint[0], _childPoint[1], _childSize[0], _childSize[1]);
+ childPoint[prim] += childSize[prim] + m_spacing;
}
}
diff --git a/vcl/source/layout/layout.cxx b/vcl/source/layout/layout.cxx
index 91a3c5e..ef0f0ec 100644
--- a/vcl/source/layout/layout.cxx
+++ b/vcl/source/layout/layout.cxx
@@ -347,6 +347,44 @@ const char *Widget::DebugName() const
return "(NIL)";
}
+#include <com/sun/star/awt/XTopWindow.hpp>
+#include <com/sun/star/beans/XPropertySetInfo.hpp>
+#include <com/sun/star/beans/XFastPropertySet.hpp>
+
+static com::sun::star::uno::Any GetProperty (Window *window, const char *property)
+{
+ com::sun::star::uno::Reference< com::sun::star::awt::XWindowPeer > xPeer
+ = window->GetComponentInterface();
+ com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xPropertySet
+ ( xPeer, com::sun::star::uno::UNO_QUERY );
+ com::sun::star::beans::Property prop
+ = xPropertySet->getPropertyByName (String::CreateFromAscii (property));
+ long handle = prop.Handle;
+ com::sun::star::uno::Any value;
+ if (handle >= 0) {
+ com::sun::star::uno::Reference< com::sun::star::beans::XFastPropertySet > xFastPropertySet
+ ( xPeer, com::sun::star::uno::UNO_QUERY );
+ xFastPropertySet->setFastPropertyValue (handle, value);
+ }
+ else
+ fprintf (stderr, "GetProperty (%s): no such property\n", property);
+ return value;
+}
+
+bool Widget::GetPropertyBool (const char *property)
+{
+ if (m_window)
+ return GetProperty (m_window, property).get <bool>();
+ return 0;
+}
+
+int Widget::GetPropertyInt (const char *property)
+{
+ if (m_window)
+ return GetProperty (m_window, property).get <sal_uInt32>();
+ return 0;
+}
+
bool Widget::operator == (const Widget &other) const
{ return this->m_window == other.m_window && this->m_layout == other.m_layout; }
More information about the Libreoffice-commits
mailing list