[Libreoffice-commits] .: Branch 'feature/layout' - sw/source vcl/inc vcl/source
Ricardo Cruz
rpmcruz at kemper.freedesktop.org
Thu Aug 25 02:16:21 PDT 2011
sw/source/ui/dialog/wordcountdialog.cxx | 4
sw/source/ui/dialog/wordcountdialog.ui | 8 +
vcl/inc/vcl/arrange.hxx | 53 ++++++-
vcl/source/layout/xmlparser.cxx | 223 +++++++++++++++++++++++---------
4 files changed, 222 insertions(+), 66 deletions(-)
New commits:
commit 41bedd31d12d4f77dfa9347848e40ba243771dba
Author: Ricardo Cruz <rpmcruz at alunos.dcc.fc.up.pt>
Date: Thu Aug 25 10:15:48 2011 +0100
Use WindowArranger for the layout
diff --git a/sw/source/ui/dialog/wordcountdialog.cxx b/sw/source/ui/dialog/wordcountdialog.cxx
index 4a98a4e..ce09b3d 100644
--- a/sw/source/ui/dialog/wordcountdialog.cxx
+++ b/sw/source/ui/dialog/wordcountdialog.cxx
@@ -48,6 +48,8 @@
#include <helpid.h>
#endif /* ENABLE_LAYOUT */
+#include <vcl/xmlparser.hxx>
+
SwWordCountDialog::SwWordCountDialog(Window* pParent) :
SfxModalDialog(pParent, SW_RES(DLG_WORDCOUNT)),
#if defined _MSC_VER
@@ -79,6 +81,8 @@ SwWordCountDialog::SwWordCountDialog(Window* pParent) :
SetHelpId (HID_DLG_WORDCOUNT);
#endif /* ENABLE_LAYOUT */
FreeResource();
+
+ LayoutParser parser (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "wordcountdialog.ui" ) ));
}
SwWordCountDialog::~SwWordCountDialog()
diff --git a/sw/source/ui/dialog/wordcountdialog.ui b/sw/source/ui/dialog/wordcountdialog.ui
new file mode 100644
index 0000000..dbdcc89
--- /dev/null
+++ b/sw/source/ui/dialog/wordcountdialog.ui
@@ -0,0 +1,8 @@
+<modal-dialog>
+ <column>
+ <push-button />
+ <push-button />
+ <push-button />
+ </column>
+</modal-dialog>
+
diff --git a/vcl/inc/vcl/arrange.hxx b/vcl/inc/vcl/arrange.hxx
index 5568cc3..383ffbb 100644
--- a/vcl/inc/vcl/arrange.hxx
+++ b/vcl/inc/vcl/arrange.hxx
@@ -154,6 +154,12 @@ namespace vcl
virtual com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > getProperties() const;
virtual void setProperties( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& );
+ // generic means to manage the children of the arranger
+ virtual size_t addWindow( Window* ) = 0;
+ virtual size_t addChild( boost::shared_ptr<WindowArranger> const & ) = 0;
+ virtual void remove( Window* ) = 0;
+ virtual void remove( boost::shared_ptr<WindowArranger> const & ) = 0;
+
sal_Int32 getExpandPriority( size_t i_nIndex ) const
{
const Element* pEle = getConstElement( i_nIndex );
@@ -219,6 +225,10 @@ namespace vcl
void setIdentifier( const rtl::OUString& i_rId )
{ m_aIdentifier = i_rId; }
+
+ // window may be shared by the parent arranger
+ Window *getParentWindow() { return m_pParentWindow; }
+ WindowArranger *getParentArranger() { return m_pParentArranger; }
};
class VCL_DLLPUBLIC RowOrColumn : public WindowArranger
@@ -250,14 +260,19 @@ namespace vcl
// add a managed window at the given index
// an index smaller than zero means add the window at the end
- size_t addWindow( Window*, sal_Int32 i_nExpandPrio = 0, const Size& i_rMinSize = Size(), size_t i_nIndex = ~0 );
- void remove( Window* );
+ size_t addWindow( Window*, sal_Int32 i_nExpandPrio, const Size& i_rMinSize = Size(), size_t i_nIndex = ~0 );
+ virtual void remove( Window* );
- size_t addChild( boost::shared_ptr<WindowArranger> const &, sal_Int32 i_nExpandPrio = 0, size_t i_nIndex = ~0 );
+ size_t addChild( boost::shared_ptr<WindowArranger> const &, sal_Int32 i_nExpandPrio, size_t i_nIndex = ~0 );
// convenience: use for addChild( new WindowArranger( ... ) ) constructs
size_t addChild( WindowArranger* i_pNewChild, sal_Int32 i_nExpandPrio = 0, size_t i_nIndex = ~0 )
{ return addChild( boost::shared_ptr<WindowArranger>( i_pNewChild ), i_nExpandPrio, i_nIndex ); }
- void remove( boost::shared_ptr<WindowArranger> const & );
+ virtual void remove( boost::shared_ptr<WindowArranger> const & );
+
+ virtual size_t addWindow( Window* c )
+ { return addWindow( c, 0 ); }
+ virtual size_t addChild( boost::shared_ptr<WindowArranger> const &c )
+ { return addChild( c, 0 ); }
long getBorderWidth() const { return m_nBorderWidth; }
};
@@ -304,6 +319,12 @@ namespace vcl
{ return m_aLabel.getOptimalSize( i_eType ); }
Size getElementSize( WindowSizeType i_eType ) const
{ return m_aElement.getOptimalSize( i_eType ); }
+
+ // TODO
+ virtual size_t addWindow( Window* ) { return 0; }
+ virtual size_t addChild( boost::shared_ptr<WindowArranger> const & ) { return 0; }
+ virtual void remove( Window* ) {}
+ virtual void remove( boost::shared_ptr<WindowArranger> const & ) {}
};
class VCL_DLLPUBLIC LabelColumn : public RowOrColumn
@@ -355,6 +376,15 @@ namespace vcl
// convenience: use for setChild( new WindowArranger( ... ) ) constructs
void setChild( WindowArranger* i_pChild, sal_Int32 i_nExpandPrio = 0 )
{ setChild( boost::shared_ptr<WindowArranger>( i_pChild ), i_nExpandPrio ); }
+
+ virtual size_t addWindow( Window *c )
+ { if( !countElements() ) setWindow( c ); return 0; }
+ virtual size_t addChild( boost::shared_ptr<WindowArranger> const &c )
+ { if( !countElements() ) setChild( c ); return 0; }
+ virtual void remove( Window *c )
+ { if( m_aElement.m_pElement == c ) m_aElement.m_pElement = 0; }
+ virtual void remove( boost::shared_ptr<WindowArranger> const &c )
+ { if( m_aElement.m_pChild == c ) m_aElement.m_pChild.reset(); }
};
class VCL_DLLPUBLIC Spacer : public WindowArranger
@@ -381,6 +411,11 @@ namespace vcl
virtual void setParentWindow( Window* ) {}
virtual size_t countElements() const { return 1; }
virtual bool isVisible() const { return true; }
+
+ virtual size_t addWindow( Window* ) { return 0; }
+ virtual size_t addChild( boost::shared_ptr<WindowArranger> const & ) { return 0; }
+ virtual void remove( Window* ) {}
+ virtual void remove( boost::shared_ptr<WindowArranger> const & ) {}
};
class VCL_DLLPUBLIC MatrixArranger : public WindowArranger
@@ -445,15 +480,19 @@ namespace vcl
// add a managed window at the given matrix position
size_t addWindow( Window*, sal_uInt32 i_nX, sal_uInt32 i_nY, sal_Int32 i_nExpandPrio = 0, const Size& i_rMinSize = Size() );
- void remove( Window* );
+ virtual void remove( Window* );
size_t addChild( boost::shared_ptr<WindowArranger> const &, sal_uInt32 i_nX, sal_uInt32 i_nY, sal_Int32 i_nExpandPrio = 0 );
// convenience: use for addChild( new WindowArranger( ... ) ) constructs
size_t addChild( WindowArranger* i_pNewChild, sal_uInt32 i_nX, sal_uInt32 i_nY, sal_Int32 i_nExpandPrio = 0 )
{ return addChild( boost::shared_ptr<WindowArranger>( i_pNewChild ), i_nX, i_nY, i_nExpandPrio ); }
- void remove( boost::shared_ptr<WindowArranger> const & );
- };
+ virtual void remove( boost::shared_ptr<WindowArranger> const & );
+ virtual size_t addWindow( Window *c )
+ { return addWindow( c, countElements(), 0 ); }
+ virtual size_t addChild( boost::shared_ptr<WindowArranger> const &c )
+ { return addChild( c, countElements(), 0 ); }
+ };
}
#endif
diff --git a/vcl/source/layout/xmlparser.cxx b/vcl/source/layout/xmlparser.cxx
index 7240d9a..f190c8e 100644
--- a/vcl/source/layout/xmlparser.cxx
+++ b/vcl/source/layout/xmlparser.cxx
@@ -33,31 +33,36 @@
//** Factory
#include <vcl/button.hxx>
-#include <vcl/grid.hxx>
-#include <vcl/ldialog.hxx>
+#include <vcl/dialog.hxx>
+#include <vcl/arrange.hxx>
+#include <com/sun/star/uno/Sequence.h>
+#include <com/sun/star/beans/PropertyValue.hpp>
+#include <xmlreader/xmlreader.hxx>
-static Window *CreateWindow (Window *parent, const std::string &name)
-{
- if(name == "pushbutton") return new PushButton(parent);
- if(name == "grid") return new Grid(parent);
- if(name == "ldialog") return new LDialog();
- return NULL;
-}
-
-//** LayoutParser::Impl
-
-#include "xmlreader/xmlreader.hxx"
-#include <map>
-#include "com/sun/star/beans/PropertyValue.hpp"
+using namespace vcl;
using namespace com::sun::star;
-typedef std::map <std::string, Window *> WidgetMap;
+static boost::shared_ptr< WindowArranger > CreateArranger( boost::shared_ptr< WindowArranger > pParent, const char *sName )
+{
+ WindowArranger *p = pParent.get();
+ WindowArranger *w = 0;
+ if( !strcmp( "row", sName ) ) w = new RowOrColumn( p, false );
+ else if( !strcmp( "column", sName ) ) w = new RowOrColumn( p, true );
+ else if( !strcmp( "labeled-element", sName ) ) w = new LabeledElement( p );
+ else if( !strcmp( "label-column", sName ) ) w = new LabelColumn( p );
+ else if( !strcmp( "indenter", sName ) ) w = new Indenter( p );
+ else if( !strcmp( "spacer", sName ) ) w = new Spacer( p );
+ else if( !strcmp( "matrix", sName ) ) w = new MatrixArranger( p );
+ else if( !strcmp( "label-column", sName ) ) w = new LabelColumn( p );
+ return boost::shared_ptr< WindowArranger >( w );
+}
-struct LayoutParser::Impl
+static Window *CreateWindow( Window *pParent, const char *sName )
{
- Impl( const rtl::OUString &filename );
- WidgetMap widgets;
-};
+ if( !strcmp( "push-button", sName )) return new PushButton( pParent );
+ if( !strcmp( "modal-dialog", sName )) return new ModalDialog( NULL );
+ return NULL;
+}
static uno::Any getPropertyValue(const char *value) {
// HACK
@@ -72,7 +77,7 @@ static uno::Any getPropertyValue(const char *value) {
rtl::OUString str( value, strlen( value ), RTL_TEXTENCODING_ASCII_US );
return uno::makeAny( str );
}
-
+/*
static void SetWidgetProperty( Window *pWidget, const char *pProp, const uno::Any &rValue ) {
uno::Sequence< beans::PropertyValue > aProps( 1 );
aProps[0].Name = rtl::OUString( pProp, strlen( pProp ), RTL_TEXTENCODING_ASCII_US );
@@ -85,42 +90,113 @@ static void SetChildProperty( Window *pParent, Window *pChild, const char *pProp
aProps[0].Name = rtl::OUString( pProp, strlen( pProp ), RTL_TEXTENCODING_ASCII_US );
aProps[0].Value = rValue;
pParent->setChildProperties( pChild, aProps );
-}
+}*/
+
+
+
+
+struct WindowWrapper
+{
+ WindowWrapper( Window *pWindow )
+ : mpWindow( pWindow ), type( WINDOW_TYPE ) {}
+
+ WindowWrapper( boost::shared_ptr< vcl::WindowArranger > xArranger )
+ : mpWindow( NULL ), mxArranger( xArranger ), type( ARRANGER_TYPE ) {}
+
+ void setProperties( uno::Sequence< beans::PropertyValue > &props )
+ {
+ switch( type ) {
+ case WINDOW_TYPE:
+ mpWindow->setProperties( props );
+ break;
+ case ARRANGER_TYPE:
+ mxArranger->setProperties( props );
+ break;
+ }
+ }
+
+ void setChildProperties( uno::Sequence< beans::PropertyValue > & )
+ {
+// TODO: parent->setChildProperties( widget, props );
+ switch( type ) {
+ case WINDOW_TYPE:
+// mpWindow->setProperties( props );
+ break;
+ case ARRANGER_TYPE:
+// mxArranger->setProperties( props );
+ break;
+ }
+ }
+
+ bool isArranger() const { return type == ARRANGER_TYPE; }
+
+ boost::shared_ptr< WindowArranger > getArranger() const { return mxArranger; }
+ Window *getWindow() const { return mpWindow; }
+
+ Window *getAncestorWindow() const
+ {
+ switch( type ) {
+ case ARRANGER_TYPE:
+ return mxArranger->getParentWindow();
+ case WINDOW_TYPE: break;
+ }
+ return mpWindow;
+ }
+
+// union {
+ Window *mpWindow;
+ boost::shared_ptr< WindowArranger > mxArranger;
+// };
+
+ enum Type {
+ WINDOW_TYPE, ARRANGER_TYPE
+ } type;
+};
+
+typedef std::map <std::string, Window *> WidgetMap;
+
+struct LayoutParser::Impl
+{
+ Impl( const rtl::OUString &sFilename );
+ WidgetMap widgets;
+};
struct LayoutAux
{
+ std::list< WindowWrapper > widgets;
+ LayoutParser::Impl *impl;
+ int child_ns;
+
+
/* Spontaneous class that does the parsing. */
- LayoutAux(LayoutParser::Impl *_impl, const rtl::OUString &filename)
- : impl(_impl), reader(filename), parent(NULL)
+ LayoutAux(LayoutParser::Impl *pimpl, const rtl::OUString &filename)
+ : impl(pimpl)
{
+ xmlreader::XmlReader reader( filename );
child_ns = reader.registerNamespaceIri( xmlreader::Span("child", 5) );
bool done = false;
while(!done) {
- // FIXME: not sure the diff between TEXT_RAW and TEXT_NORMALIZED
+ // FIXME: what's the deal on TEXT_RAW and TEXT_NORMALIZED
int ns;
xmlreader::Span data;
- xmlreader::XmlReader::Result res = reader.nextItem( xmlreader::XmlReader::TEXT_RAW, &data, &ns );
+ xmlreader::XmlReader::Result res = reader.nextItem(
+ xmlreader::XmlReader::TEXT_NORMALIZED, &data, &ns );
+
switch(res) {
case xmlreader::XmlReader::RESULT_BEGIN: {
- Window *w = createWidget(data.begin);
- // FIXME: element->AddChild(w) ?
- if(parent)
- parent->addWindow(w);
-
- int _ns;
- xmlreader::Span attrb, value;
- while( reader.nextAttribute( &_ns, &attrb) ) {
- value = reader.getAttributeValue( false ); // FIXME: fullyNormalized ?!
- parseWidgetProperty( w, _ns, attrb.begin, value.begin );
- }
-
- parent = w; // assign after processing
+ WindowWrapper ¤t = widgets.front();
+
+ const char *name = data.begin;
+ WindowWrapper widget = createElement( name, current );
+ widgets.push_front( widget );
+
+ parseWidgetProperties( reader, widget );
break;
}
case xmlreader::XmlReader::RESULT_END:
- parent = parent->GetParent();
+ widgets.pop_front();
break;
case xmlreader::XmlReader::RESULT_TEXT:
break;
@@ -131,38 +207,67 @@ struct LayoutAux
}
}
- Window *createWidget( const char *name ) {
- return CreateWindow(parent, name);
+ WindowWrapper createElement( const char *name, WindowWrapper &parent )
+ {
+ boost::shared_ptr< WindowArranger > arranger = CreateArranger( parent.getArranger(), name );
+ if( arranger ) {
+ parent.getArranger()->addChild( arranger );
+ return WindowWrapper( arranger );
+ }
+
+ Window *window = CreateWindow( parent.getAncestorWindow(), name );
+ if( window ) {
+ parent.getArranger()->addWindow( window );
+ return WindowWrapper( window );
+ }
+
+ return NULL;
}
- void parseWidgetProperty( Window *w, int ns, const char *prop, const char *value ) {
- if(!strcmp("id", prop)) {
+ void parseWidgetProperties( xmlreader::XmlReader &reader, WindowWrapper &widget )
+ {
+ uno::Sequence< beans::PropertyValue > props, childProps;
+
+ int ns;
+ xmlreader::Span attrb_span, value_span;
+ while( reader.nextAttribute( &ns, &attrb_span) ) {
+ value_span = reader.getAttributeValue( false ); // FIXME: fullyNormalized ?!
+
+ const char *prop = attrb_span.begin;
+ const char *value = value_span.begin;
+ if(!strcmp("id", prop)) {
// w->setIdentifier(value);
- impl->widgets.insert(std::pair <std::string, Window *> ( value, w ));
- }
- else if(ns == child_ns) {
+ // TODO: assig ids to layout stuff
+ impl->widgets.insert(std::pair <std::string, Window *> ( value, widget.getWindow() ));
+ }
+ else {
// Type type = parent->GetPropertyType(attrb.begin);
- uno::Any v = getPropertyValue(value);
- SetChildProperty( parent, w, prop, v );
- }
- else {
-// Type type = w->GetPropertyType(attrb.begin);
- uno::Any v = getPropertyValue(value);
- SetWidgetProperty( w, prop, v );
+ uno::Any v = getPropertyValue(value);
+ uno::Sequence< beans::PropertyValue > &p
+ = (child_ns == ns) ? childProps : props;
+
+ int i = p.getLength();
+ p.realloc( i+1 );
+ p[ i ].Name = rtl::OUString( prop, strlen( prop ), RTL_TEXTENCODING_ASCII_US );
+ p[ i ].Value = v;
+ }
}
- }
- LayoutParser::Impl *impl;
- xmlreader::XmlReader reader;
- Window *parent;
- int child_ns;
+ if( props.getLength() > 0 )
+ widget.setProperties( props );
+ if( childProps.getLength() > 0 )
+ widget.setChildProperties( childProps );
+ }
};
+
LayoutParser::Impl::Impl(const rtl::OUString &filename)
{
LayoutAux reader(this, filename);
}
+
+
//** LayoutParser
LayoutParser::LayoutParser( const rtl::OUString &filename )
More information about the Libreoffice-commits
mailing list