[Libreoffice-commits] .: Branch 'feature/cmclayout' - sfx2/inc sfx2/source tools/inc tools/source vcl/inc vcl/source

Caolán McNamara caolan at kemper.freedesktop.org
Tue May 22 04:49:53 PDT 2012


 sfx2/inc/sfx2/basedlgs.hxx      |    2 
 sfx2/source/dialog/basedlgs.cxx |   71 +++++++++++++---------
 tools/inc/tools/resmgr.hxx      |    3 
 tools/source/rc/resmgr.cxx      |    5 +
 vcl/inc/vcl/builder.hxx         |   11 +++
 vcl/inc/vcl/button.hxx          |    4 +
 vcl/inc/vcl/dialog.hxx          |    5 +
 vcl/inc/vcl/window.hxx          |    7 ++
 vcl/source/control/button.cxx   |   18 +++++
 vcl/source/control/edit.cxx     |    3 
 vcl/source/control/field.cxx    |    7 ++
 vcl/source/control/fixed.cxx    |    7 ++
 vcl/source/control/lstbox.cxx   |    4 +
 vcl/source/window/builder.cxx   |   98 ++++++++++++++++++++++++++++++-
 vcl/source/window/dialog.cxx    |   35 ++++++++++-
 vcl/source/window/window.cxx    |  124 ++++++++++++++++++++++++++++++++++++++++
 16 files changed, 370 insertions(+), 34 deletions(-)

New commits:
commit 6423055e0762a102ad82978989e378c03d553e51
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue May 22 12:33:28 2012 +0100

    Implement conversion scheme for dialogs without changing their code
    
    This supports a scheme where we can change over a dialog to GtkBuilder xml
    without touching its code by the presence of a .ui file in the right place e.g.
    share/config/soffice.cfg/cui/10000.ui for the zoom dialog

diff --git a/sfx2/inc/sfx2/basedlgs.hxx b/sfx2/inc/sfx2/basedlgs.hxx
index d1dc5b7..cfd1288 100644
--- a/sfx2/inc/sfx2/basedlgs.hxx
+++ b/sfx2/inc/sfx2/basedlgs.hxx
@@ -79,8 +79,6 @@ private:
     SAL_DLLPRIVATE void init();
 
 protected:
-    VclBuilder              *m_pUIBuilder;
-
     SfxModalDialog(Window *pParent, const ResId& );
     SfxModalDialog(Window *pParent, const rtl::OString& rID, const rtl::OUString& rUIXMLDescription );
     SfxModalDialog(Window* pParent, sal_uInt32 nUniqueId, WinBits nWinStyle = WB_STDMODAL );
diff --git a/sfx2/source/dialog/basedlgs.cxx b/sfx2/source/dialog/basedlgs.cxx
index 9b9d510..5a7529a 100644
--- a/sfx2/source/dialog/basedlgs.cxx
+++ b/sfx2/source/dialog/basedlgs.cxx
@@ -31,6 +31,7 @@
 
 #include <stdlib.h>
 #include <comphelper/processfactory.hxx>
+#include <osl/file.hxx>
 #include <vcl/fixed.hxx>
 #include <vcl/help.hxx>
 #include <vcl/msgbox.hxx>
@@ -162,34 +163,11 @@ void SfxModalDialog::init()
     GetDialogData_Impl();
 }
 
-// -----------------------------------------------------------------------
-
-SfxModalDialog::SfxModalDialog(Window* pParent, const ResId &rResId )
-
-/*  [Description]
-
-    Constructor of the general base class for modal Dialoge;
-    ResId is used as ID in ini-file. The saved position from there is set.
-*/
-
-:   ModalDialog(pParent, rResId),
-    nUniqId(rResId.GetId()),
-    pInputSet(0),
-    pOutputSet(0),
-    m_pUIBuilder(0)
-{
-    init();
-}
-
 #define BASEPATH_SHARE_LAYER rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UIConfig"))
 #define RELPATH_SHARE_LAYER rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("soffice.cfg"))
 #define SERVICENAME_PATHSETTINGS rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.PathSettings"))
 
-SfxModalDialog::SfxModalDialog(Window *pParent, const rtl::OString& rID, const rtl::OUString& rUIXMLDescription )
-:   ModalDialog(pParent, 0), //todo
-    nUniqId(0), //todo
-    pInputSet(0),
-    pOutputSet(0)
+rtl::OUString getUIRootDir()
 {
     namespace css = ::com::sun::star;
 
@@ -214,8 +192,47 @@ SfxModalDialog::SfxModalDialog(Window *pParent, const rtl::OString& rID, const r
     sShareLayer += RELPATH_SHARE_LAYER; // folder
     sShareLayer += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
     /*to-do, can we merge all this foo with existing soffice.cfg finding code, etc*/
+    return sShareLayer;
+}
+
+// -----------------------------------------------------------------------
+
+SfxModalDialog::SfxModalDialog(Window* pParent, const ResId &rResId )
+
+/*  [Description]
+
+    Constructor of the general base class for modal Dialoge;
+    ResId is used as ID in ini-file. The saved position from there is set.
+*/
+
+:   ModalDialog(pParent, rResId),
+    nUniqId(rResId.GetId()),
+    pInputSet(0),
+    pOutputSet(0)
+{
+    sal_Int32 nUIid = static_cast<sal_Int32>(nUniqId);
+    rtl::OUString sPath = rtl::OUStringBuffer(getUIRootDir()).
+        append(rResId.GetResMgr()->getPrefixName()).
+        append('/').
+        append(nUIid).
+        appendAscii(".ui").
+        makeStringAndClear();
+    fprintf(stderr, "path %s id %d\n", rtl::OUStringToOString(sPath, RTL_TEXTENCODING_UTF8).getStr(), nUniqId);
+
+    osl::File aUIFile(sPath);
+    osl::File::RC error = aUIFile.open(osl_File_OpenFlag_Read);
+    if (error == osl::File::E_None)
+        m_pUIBuilder = new VclBuilder(this, sPath, rtl::OString::valueOf(nUIid));
+    init();
+}
 
-    m_pUIBuilder = new VclBuilder(this, sShareLayer + rUIXMLDescription, rID);
+SfxModalDialog::SfxModalDialog(Window *pParent, const rtl::OString& rID, const rtl::OUString& rUIXMLDescription )
+:   ModalDialog(pParent, 0), //todo
+    nUniqId(0), //todo
+    pInputSet(0),
+    pOutputSet(0)
+{
+    m_pUIBuilder = new VclBuilder(this, getUIRootDir() + rUIXMLDescription, rID);
     init();
 }
 
@@ -234,8 +251,7 @@ SfxModalDialog::SfxModalDialog(Window* pParent,
     ModalDialog(pParent, nWinStyle),
     nUniqId(nUniqueId),
     pInputSet(0),
-    pOutputSet(0),
-    m_pUIBuilder(0)
+    pOutputSet(0)
 {
     init();
 }
@@ -252,7 +268,6 @@ SfxModalDialog::~SfxModalDialog()
 {
     SetDialogData_Impl();
     delete pOutputSet;
-    delete m_pUIBuilder;
 }
 
 void SfxModalDialog::CreateOutputItemSet( SfxItemPool& rPool )
diff --git a/tools/inc/tools/resmgr.hxx b/tools/inc/tools/resmgr.hxx
index bb81d0d..d9b92f8 100644
--- a/tools/inc/tools/resmgr.hxx
+++ b/tools/inc/tools/resmgr.hxx
@@ -201,7 +201,8 @@ public:
     // Gibt die verbleibende Groesse zurueck
     sal_uInt32          GetRemainSize();
 
-    const rtl::OUString&GetFileName() const;
+    const rtl::OUString& GetFileName() const;
+    rtl::OUString       getPrefixName() const;
 
     sal_Int16               ReadShort();
     sal_Int32               ReadLong();
diff --git a/tools/source/rc/resmgr.cxx b/tools/source/rc/resmgr.cxx
index bc4e4ad..f55c242 100644
--- a/tools/source/rc/resmgr.cxx
+++ b/tools/source/rc/resmgr.cxx
@@ -1681,6 +1681,11 @@ ResMgr* ResMgr::CreateResMgr( const sal_Char* pPrefixName,
     return pImp ? new ResMgr( pImp ) : NULL;
 }
 
+rtl::OUString ResMgr::getPrefixName() const
+{
+    return pImpRes->aPrefix;
+}
+
 // -----------------------------------------------------------------------
 
 ResMgr* ResMgr::SearchCreateResMgr(
diff --git a/vcl/inc/vcl/builder.hxx b/vcl/inc/vcl/builder.hxx
index 730fd34..6839a79 100644
--- a/vcl/inc/vcl/builder.hxx
+++ b/vcl/inc/vcl/builder.hxx
@@ -42,9 +42,11 @@ private:
     {
         rtl::OString m_sID;
         Window *m_pWindow;
+        bool m_bOwned;
         WinAndId(const rtl::OString &rId, Window *pWindow)
             : m_sID(rId)
             , m_pWindow(pWindow)
+            , m_bOwned(true)
         {
         }
     };
@@ -69,6 +71,11 @@ public:
     ~VclBuilder();
     Window *get_widget_root();
     Window *get_by_name(rtl::OString sID);
+    //for the purposes of retrofitting this to the existing code
+    //look up sID, clone its properties into replacement and
+    //splice replacement into the tree instead of it, without
+    //taking ownership of it
+    bool replace(rtl::OString sID, Window &rReplacement);
 
     typedef std::map<rtl::OString, rtl::OString> stringmap;
 private:
@@ -81,6 +88,10 @@ private:
     void handlePacking(Window *pCurrent, xmlreader::XmlReader &reader);
     void applyPackingProperty(Window *pCurrent, xmlreader::XmlReader &reader);
     void collectProperty(xmlreader::XmlReader &reader, stringmap &rVec);
+
+    //Helpers to retrofit all the existing code the the builder
+    static void swapGuts(Window &rOrig, Window &rReplacement);
+    static sal_uInt16 getPositionWithinParent(Window &rWindow);
 };
 
 #endif
diff --git a/vcl/inc/vcl/button.hxx b/vcl/inc/vcl/button.hxx
index 3fc5dc7..c775240 100644
--- a/vcl/inc/vcl/button.hxx
+++ b/vcl/inc/vcl/button.hxx
@@ -398,6 +398,10 @@ public:
     std::vector<RadioButton*> GetRadioButtonGroup(bool bIncludeThis = true) const;
 
     virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue);
+
+    /*
+     * Group this RadioButton with another
+     */
     void group(RadioButton &rOther);
 };
 
diff --git a/vcl/inc/vcl/dialog.hxx b/vcl/inc/vcl/dialog.hxx
index 39e50e5..7f2670a 100644
--- a/vcl/inc/vcl/dialog.hxx
+++ b/vcl/inc/vcl/dialog.hxx
@@ -42,6 +42,7 @@
 // - Dialog -
 // ----------
 struct DialogImpl;
+class VclBuilder;
 
 class VCL_DLLPUBLIC Dialog : public SystemWindow
 {
@@ -72,6 +73,8 @@ protected:
     SAL_DLLPRIVATE void    ImplInit( Window* pParent, WinBits nStyle );
     SAL_DLLPRIVATE void    ImplDialogRes( const ResId& rResId );
 
+    VclBuilder              *m_pUIBuilder;
+
 public:
     SAL_DLLPRIVATE sal_Bool    IsInClose() const { return mbInClose; }
     SAL_DLLPRIVATE bool hasPendingLayout() const { return maLayoutTimer.IsActive(); }
@@ -137,6 +140,8 @@ public:
     sal_Bool            IsModalInputMode() const { return mbModalMode; }
 
     void            GrabFocusToFirstControl();
+
+    static bool     replace_buildable(Window *pParent, sal_Int32 nID, Window &rReplacement);
 };
 
 // ------------------
diff --git a/vcl/inc/vcl/window.hxx b/vcl/inc/vcl/window.hxx
index ccd4fd2..3bd7816 100644
--- a/vcl/inc/vcl/window.hxx
+++ b/vcl/inc/vcl/window.hxx
@@ -345,6 +345,7 @@ const char* ImplDbgCheckWindow( const void* pObj );
 
 class Dialog;
 class WindowImpl;
+class VclBuilder;
 
 class VCL_DLLPUBLIC Window : public OutputDevice
 {
@@ -362,6 +363,7 @@ class VCL_DLLPUBLIC Window : public OutputDevice
     friend class RadioButton;
     friend class SystemChildWindow;
     friend class ImplBorderWindow;
+    friend class VclBuilder;
 
     // TODO: improve missing functionality
     // only required because of SetFloatingMode()
@@ -1100,6 +1102,11 @@ public:
      */
     virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue);
 
+    /*
+     * Takes ownership of the rOther properties
+     */
+    void take_properties(Window &rOther);
+
     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/control/button.cxx b/vcl/source/control/button.cxx
index b070115..d76f09b 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -1207,6 +1207,9 @@ PushButton::PushButton( Window* pParent, WinBits nStyle ) :
 PushButton::PushButton( Window* pParent, const ResId& rResId ) :
     Button( WINDOW_PUSHBUTTON )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     ImplInitPushButtonData();
     rResId.SetRT( RSC_PUSHBUTTON );
     WinBits nStyle = ImplInitRes( rResId );
@@ -1748,6 +1751,9 @@ OKButton::OKButton( Window* pParent, WinBits nStyle ) :
 OKButton::OKButton( Window* pParent, const ResId& rResId ) :
     PushButton( WINDOW_OKBUTTON )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     rResId.SetRT( RSC_OKBUTTON );
     WinBits nStyle = ImplInitRes( rResId );
     ImplInit( pParent, nStyle );
@@ -1815,6 +1821,9 @@ CancelButton::CancelButton( Window* pParent, WinBits nStyle ) :
 CancelButton::CancelButton( Window* pParent, const ResId& rResId ) :
     PushButton( WINDOW_CANCELBUTTON )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     rResId.SetRT( RSC_CANCELBUTTON );
     WinBits nStyle = ImplInitRes( rResId );
     ImplInit( pParent, nStyle );
@@ -1882,6 +1891,9 @@ HelpButton::HelpButton( Window* pParent, WinBits nStyle ) :
 HelpButton::HelpButton( Window* pParent, const ResId& rResId ) :
     PushButton( WINDOW_HELPBUTTON )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     rResId.SetRT( RSC_HELPBUTTON );
     WinBits nStyle = ImplInitRes( rResId );
     ImplInit( pParent, nStyle );
@@ -2428,6 +2440,9 @@ RadioButton::RadioButton( Window* pParent, WinBits nStyle ) :
 RadioButton::RadioButton( Window* pParent, const ResId& rResId ) :
     Button( WINDOW_RADIOBUTTON )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     ImplInitRadioButtonData();
     rResId.SetRT( RSC_RADIOBUTTON );
     WinBits nStyle = ImplInitRes( rResId );
@@ -3372,6 +3387,9 @@ CheckBox::CheckBox( Window* pParent, WinBits nStyle ) :
 CheckBox::CheckBox( Window* pParent, const ResId& rResId ) :
     Button( WINDOW_CHECKBOX )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     ImplInitCheckBoxData();
     rResId.SetRT( RSC_CHECKBOX );
     WinBits nStyle = ImplInitRes( rResId );
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index 7d03316..2bb7ae2 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -207,6 +207,9 @@ Edit::Edit( Window* pParent, WinBits nStyle ) :
 Edit::Edit( Window* pParent, const ResId& rResId ) :
     Control( WINDOW_EDIT )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     ImplInitEditData();
     rResId.SetRT( RSC_EDIT );
     WinBits nStyle = ImplInitRes( rResId );
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index 1a880eb..2f8bcd6 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -33,6 +33,7 @@
 
 #include "tools/rc.h"
 
+#include "vcl/dialog.hxx"
 #include "vcl/field.hxx"
 #include "vcl/event.hxx"
 #include "vcl/svapp.hxx"
@@ -788,6 +789,9 @@ NumericField::NumericField( Window* pParent, WinBits nWinStyle ) :
 NumericField::NumericField( Window* pParent, const ResId& rResId ) :
     SpinField( WINDOW_NUMERICFIELD )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     rResId.SetRT( RSC_NUMERICFIELD );
     WinBits nStyle = ImplInitRes( rResId ) ;
     SpinField::ImplInit( pParent, nStyle );
@@ -1657,6 +1661,9 @@ MetricField::MetricField( Window* pParent, WinBits nWinStyle ) :
 MetricField::MetricField( Window* pParent, const ResId& rResId ) :
     SpinField( WINDOW_METRICFIELD )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     rResId.SetRT( RSC_METRICFIELD );
     WinBits nStyle = ImplInitRes( rResId ) ;
     SpinField::ImplInit( pParent, nStyle );
diff --git a/vcl/source/control/fixed.cxx b/vcl/source/control/fixed.cxx
index 0606073..03ee12e 100644
--- a/vcl/source/control/fixed.cxx
+++ b/vcl/source/control/fixed.cxx
@@ -30,6 +30,7 @@
 #include "tools/rc.h"
 
 #include "vcl/decoview.hxx"
+#include "vcl/dialog.hxx"
 #include "vcl/event.hxx"
 #include "vcl/fixed.hxx"
 
@@ -164,6 +165,9 @@ FixedText::FixedText( Window* pParent, WinBits nStyle ) :
 FixedText::FixedText( Window* pParent, const ResId& rResId ) :
     Control( WINDOW_FIXEDTEXT )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     rResId.SetRT( RSC_TEXT );
     WinBits nStyle = ImplInitRes( rResId );
     ImplInit( pParent, nStyle );
@@ -580,6 +584,9 @@ FixedLine::FixedLine( Window* pParent, WinBits nStyle ) :
 FixedLine::FixedLine( Window* pParent, const ResId& rResId ) :
     Control( WINDOW_FIXEDLINE )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     rResId.SetRT( RSC_FIXEDLINE );
     WinBits nStyle = ImplInitRes( rResId );
     ImplInit( pParent, nStyle );
diff --git a/vcl/source/control/lstbox.cxx b/vcl/source/control/lstbox.cxx
index 951c3e9..2adf61c 100644
--- a/vcl/source/control/lstbox.cxx
+++ b/vcl/source/control/lstbox.cxx
@@ -32,6 +32,7 @@
 
 
 #include "vcl/decoview.hxx"
+#include "vcl/dialog.hxx"
 #include "vcl/event.hxx"
 #include "vcl/scrbar.hxx"
 #include "vcl/button.hxx"
@@ -67,6 +68,9 @@ ListBox::ListBox( Window* pParent, WinBits nStyle ) : Control( WINDOW_LISTBOX )
 ListBox::ListBox( Window* pParent, const ResId& rResId ) :
     Control( WINDOW_LISTBOX )
 {
+    if (Dialog::replace_buildable(pParent, rResId.GetId(), *this))
+        return;
+
     ImplInitListBoxData();
     rResId.SetRT( RSC_LISTBOX );
     WinBits nStyle = ImplInitRes( rResId );
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 32829ee..e978d7d 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -34,6 +34,7 @@
 #include <vcl/fixed.hxx>
 #include <vcl/layout.hxx>
 #include <vcl/lstbox.hxx>
+#include <window.h>
 
 VclBuilder::VclBuilder(Window *pParent, rtl::OUString sUri, rtl::OString sID)
     : m_sID(sID)
@@ -73,8 +74,8 @@ VclBuilder::~VclBuilder()
     for (std::vector<WinAndId>::reverse_iterator aI = m_aChildren.rbegin(),
          aEnd = m_aChildren.rend(); aI != aEnd; ++aI)
     {
-        Window *pWindow = aI->m_pWindow;
-        delete pWindow;
+        if (aI->m_bOwned)
+            delete aI->m_pWindow;
     }
 }
 
@@ -268,6 +269,20 @@ void VclBuilder::handleChild(Window *pParent, xmlreader::XmlReader &reader)
                             continue;
                         aChilds[i]->reorderWithinParent(nPosition);
                     }
+
+#if TODO
+//sort by ltr ttb
+                    rtl::OString sLeftAttach(RTL_CONSTASCII_STRINGPARAM("left-attach"));
+                    rtl::OString sTopAttach(RTL_CONSTASCII_STRINGPARAM("top-attach"));
+                    for (size_t i = 0; i < aChilds.size(); ++i)
+                    {
+                        sal_uInt16 nPosition = aChilds[i]->getWidgetProperty<sal_uInt16>(sPosition, 0xFFFF);
+                        if (nPosition == 0xFFFF)
+                            continue;
+                        aChilds[i]->reorderWithinParent(nPosition);
+                    }
+#endif
+
                 }
             }
             else if (name.equals(RTL_CONSTASCII_STRINGPARAM("packing")))
@@ -483,4 +498,83 @@ Window *VclBuilder::get_by_name(rtl::OString sID)
     return NULL;
 }
 
+sal_uInt16 VclBuilder::getPositionWithinParent(Window &rWindow)
+{
+    sal_uInt16 nPosition = 0;
+    Window* pChild = rWindow.GetParent()->mpWindowImpl->mpFirstChild;
+    while (pChild)
+    {
+        if (pChild == &rWindow)
+            break;
+        pChild = pChild->mpWindowImpl->mpNext;
+        ++nPosition;
+    }
+    return nPosition;
+}
+
+void VclBuilder::swapGuts(Window &rOrig, Window &rReplacement)
+{
+#if 1
+    sal_uInt16 nPosition = getPositionWithinParent(rOrig);
+
+    rReplacement.ImplInit(rOrig.GetParent(), rOrig.GetStyle(), NULL);
+
+    rReplacement.take_properties(rOrig);
+
+    rReplacement.reorderWithinParent(nPosition);
+
+    assert(nPosition == getPositionWithinParent(rReplacement));
+#else
+    //rReplacement is intended to be not inserted into
+    //anything yet
+    assert(!rReplacement.mpWindowImpl->mpParent);
+
+    rReplacement.ImplInit(rOrig.GetParent(), rOrig.GetStyle(), NULL);
+    assert(rReplacement.GetParent() == rOrig.GetParent());
+
+    rReplacement.ImplRemoveWindow(false);
+
+    Window *pParent = rOrig.mpWindowImpl->mpParent;
+    Window *pOrigsNext = rOrig.mpWindowImpl->mpNext;
+    Window *pOrigsPrev = rOrig.mpWindowImpl->mpPrev;
+    std::swap(rOrig.mpWindowImpl, rReplacement.mpWindowImpl);
+    std::swap(rOrig.m_aWidgetProperties, rReplacement.m_aWidgetProperties);
+    assert(rReplacement.mpWindowImpl->mpPrev == pOrigsPrev);
+    assert(rReplacement.mpWindowImpl->mpNext == pOrigsNext);
+    if (pOrigsNext)
+        pOrigsNext->mpWindowImpl->mpPrev = &rReplacement;
+    else
+        pParent->mpWindowImpl->mpLastChild = &rReplacement;
+    if (pOrigsPrev)
+        pOrigsPrev->mpWindowImpl->mpNext = &rReplacement;
+    else
+        pParent->mpWindowImpl->mpFirstChild = &rReplacement;
+    assert(!rOrig.mpWindowImpl->mpNext && !rOrig.mpWindowImpl->mpPrev);
+
+    //now put this at the end of the window list
+    rOrig.ImplInsertWindow(pParent);
+#endif
+    fprintf(stderr, "swapped %p for %p (%d)\n", &rReplacement, &rOrig);
+}
+
+bool VclBuilder::replace(rtl::OString sID, Window &rReplacement)
+{
+    for (std::vector<WinAndId>::iterator aI = m_aChildren.begin(),
+         aEnd = m_aChildren.end(); aI != aEnd; ++aI)
+    {
+        if (aI->m_sID.equals(sID))
+        {
+            Window *pOrig = aI->m_pWindow;
+            swapGuts(*pOrig, rReplacement);
+            delete pOrig;
+
+            aI->m_pWindow = &rReplacement;
+            aI->m_bOwned = false;
+            return true;
+        }
+    }
+    fprintf(stderr, "no sign of %s\n", sID.getStr());
+    return false;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 4ffa8ba..79cb5df 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -36,6 +36,7 @@
 #include <rtl/strbuf.hxx>
 #include <sal/log.hxx>
 
+#include <vcl/builder.hxx>
 #include <vcl/layout.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/event.hxx>
@@ -349,6 +350,7 @@ void Dialog::ImplInitDialogData()
     mnMousePositioned       = 0;
     m_nBorderWidth          = 0;
     mpDialogImpl            = new DialogImpl;
+    m_pUIBuilder            = NULL;
 
     //To-Do, reuse maResizeTimer
     maLayoutTimer.SetTimeout(50);
@@ -1081,7 +1083,9 @@ void Dialog::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal
 bool Dialog::isLayoutEnabled() const
 {
     //Child is a container => we're layout enabled
-    return dynamic_cast<const VclContainer*>(GetWindow(WINDOW_FIRSTCHILD));
+    bool bRet = dynamic_cast<const VclContainer*>(GetWindow(WINDOW_FIRSTCHILD));
+    fprintf(stderr, "isLayoutEnabled is %d\n", bRet);
+    return bRet;
 }
 
 Size Dialog::GetOptimalSize(WindowSizeType eType) const
@@ -1098,6 +1102,11 @@ Size Dialog::GetOptimalSize(WindowSizeType eType) const
 IMPL_LINK( Dialog, ImplHandleLayoutTimerHdl, void*, EMPTYARG )
 {
     VclBox *pBox = dynamic_cast<VclBox*>(GetWindow(WINDOW_FIRSTCHILD));
+    if (!pBox)
+    {
+        fprintf(stderr, "WTF!\n");
+        return 0;
+    }
     Size aSize = GetSizePixel();
     aSize.Width() -= mpWindowImpl->mnLeftBorder + mpWindowImpl->mnRightBorder
         + 2 * m_nBorderWidth;
@@ -1142,6 +1151,30 @@ bool Dialog::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
     return true;
 }
 
+bool Dialog::replace_buildable(Window *pParent, sal_Int32 nID, Window &rReplacement)
+{
+    if (!pParent)
+        return false;
+    if (!pParent->IsDialog())
+        return false;
+    Dialog *pDialog = static_cast<Dialog*>(pParent);
+    VclBuilder *pUIBuilder = pDialog->m_pUIBuilder;
+    if (!pUIBuilder)
+        return false;
+    bool bFound = pUIBuilder->replace(rtl::OString::valueOf(nID), rReplacement);
+    if (!bFound)
+    {
+        fprintf(stderr, "%d %p not found, hiding\n", nID, &rReplacement);
+        //move "missing" elements into the action area (just to have
+        //a known container as an owner) and hide it
+        VclButtonBox* pActionArea = getActionArea(pDialog);
+        rReplacement.ImplInit(pActionArea, 0, NULL);
+        rReplacement.Hide();
+    }
+    assert(rReplacement.mpWindowImpl);
+    return true;
+}
+
 // -----------------------------------------------------------------------
 
 ModelessDialog::ModelessDialog( Window* pParent, const ResId& rResId ) :
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 9c0b8c9..c1e8b87 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -6469,6 +6469,12 @@ void Window::Show( sal_Bool bVisible, sal_uInt16 nFlags )
 
 Size Window::GetSizePixel() const
 {
+    if (!mpWindowImpl)
+    {
+        fprintf(stderr, "WTF\n");
+        return Size(0,0);
+    }
+
     // #i43257# trigger pending resize handler to assure correct window sizes
     if( mpWindowImpl->mpFrameData->maResizeTimer.IsActive() )
     {
@@ -9672,6 +9678,124 @@ Size Window::get_preferred_size() const
     return aRet;
 }
 
+void Window::take_properties(Window &rOther)
+{
+    WindowImpl *pWindowImpl = rOther.mpWindowImpl;
+    std::swap(mpWindowImpl->mpUserData, pWindowImpl->mpUserData);
+    std::swap(mpWindowImpl->mpExtImpl, pWindowImpl->mpExtImpl);
+    std::swap(mpWindowImpl->mpCursor, pWindowImpl->mpCursor);
+    std::swap(mpWindowImpl->maPointer, pWindowImpl->maPointer);
+    mpWindowImpl->maZoom = pWindowImpl->maZoom;
+    mpWindowImpl->maText = pWindowImpl->maText;
+    std::swap(mpWindowImpl->mpControlFont, pWindowImpl->mpControlFont);
+    mpWindowImpl->maControlForeground = pWindowImpl->maControlForeground;
+    mpWindowImpl->maControlBackground = pWindowImpl->maControlBackground;
+    mpWindowImpl->mnLeftBorder = pWindowImpl->mnLeftBorder;
+    mpWindowImpl->mnTopBorder = pWindowImpl->mnTopBorder;
+    mpWindowImpl->mnRightBorder = pWindowImpl->mnRightBorder;
+    mpWindowImpl->mnBottomBorder = pWindowImpl->mnBottomBorder;
+    mpWindowImpl->mnX = pWindowImpl->mnX;
+    mpWindowImpl->mnY = pWindowImpl->mnY;
+    mpWindowImpl->mnAbsScreenX = pWindowImpl->mnAbsScreenX;
+    mpWindowImpl->maPos = pWindowImpl->maPos;
+    mpWindowImpl->maHelpId = pWindowImpl->maHelpId;
+    mpWindowImpl->maUniqId = pWindowImpl->maUniqId;
+    mpWindowImpl->maHelpText = pWindowImpl->maHelpText;
+    mpWindowImpl->maQuickHelpText = pWindowImpl->maQuickHelpText;
+    std::swap(mpWindowImpl->maInputContext, pWindowImpl->maInputContext);
+    mpWindowImpl->mnStyle = pWindowImpl->mnStyle;
+    mpWindowImpl->mnPrevStyle = pWindowImpl->mnPrevStyle;
+    mpWindowImpl->mnExtendedStyle = pWindowImpl->mnExtendedStyle;
+    mpWindowImpl->mnPrevExtendedStyle = pWindowImpl->mnPrevExtendedStyle;
+    mpWindowImpl->mnType = pWindowImpl->mnType;
+    mpWindowImpl->mnNativeBackground = pWindowImpl->mnNativeBackground;
+    mpWindowImpl->mnWaitCount = pWindowImpl->mnWaitCount;
+    mpWindowImpl->mnPaintFlags = pWindowImpl->mnPaintFlags;
+    mpWindowImpl->mnGetFocusFlags = pWindowImpl->mnGetFocusFlags;
+    mpWindowImpl->mnParentClipMode = pWindowImpl->mnParentClipMode;
+    mpWindowImpl->mnActivateMode = pWindowImpl->mnActivateMode;
+    mpWindowImpl->mnDlgCtrlFlags = pWindowImpl->mnDlgCtrlFlags;
+    mpWindowImpl->mnLockCount = pWindowImpl->mnLockCount;
+    mpWindowImpl->meAlwaysInputMode = pWindowImpl->meAlwaysInputMode;
+    mpWindowImpl->mbFrame = pWindowImpl->mbFrame;
+    mpWindowImpl->mbBorderWin = pWindowImpl->mbBorderWin;
+    mpWindowImpl->mbOverlapWin = pWindowImpl->mbOverlapWin;
+    mpWindowImpl->mbSysWin = pWindowImpl->mbSysWin;
+    mpWindowImpl->mbDialog = pWindowImpl->mbDialog;
+    mpWindowImpl->mbDockWin = pWindowImpl->mbDockWin;
+    mpWindowImpl->mbFloatWin = pWindowImpl->mbFloatWin;
+    mpWindowImpl->mbPushButton = pWindowImpl->mbPushButton;
+    mpWindowImpl->mbVisible = pWindowImpl->mbVisible;
+    mpWindowImpl->mbDisabled = pWindowImpl->mbDisabled;
+    mpWindowImpl->mbInputDisabled = pWindowImpl->mbInputDisabled;
+    mpWindowImpl->mbDropDisabled = pWindowImpl->mbDropDisabled;
+    mpWindowImpl->mbNoUpdate = pWindowImpl->mbNoUpdate;
+    mpWindowImpl->mbNoParentUpdate = pWindowImpl->mbNoParentUpdate;
+    mpWindowImpl->mbActive = pWindowImpl->mbActive;
+    mpWindowImpl->mbParentActive = pWindowImpl->mbParentActive;
+    mpWindowImpl->mbReallyVisible = pWindowImpl->mbReallyVisible;
+    mpWindowImpl->mbReallyShown = pWindowImpl->mbReallyShown;
+    mpWindowImpl->mbInInitShow = pWindowImpl->mbInInitShow;
+    mpWindowImpl->mbChildNotify = pWindowImpl->mbChildNotify;
+    mpWindowImpl->mbChildPtrOverwrite = pWindowImpl->mbChildPtrOverwrite;
+    mpWindowImpl->mbNoPtrVisible = pWindowImpl->mbNoPtrVisible;
+    mpWindowImpl->mbPaintFrame = pWindowImpl->mbPaintFrame;
+    mpWindowImpl->mbInPaint = pWindowImpl->mbInPaint;
+    mpWindowImpl->mbMouseMove = pWindowImpl->mbMouseMove;
+    mpWindowImpl->mbMouseButtonDown = pWindowImpl->mbMouseButtonDown;
+    mpWindowImpl->mbMouseButtonUp = pWindowImpl->mbMouseButtonUp;
+    mpWindowImpl->mbKeyInput = pWindowImpl->mbKeyInput;
+    mpWindowImpl->mbKeyUp = pWindowImpl->mbKeyUp;
+    mpWindowImpl->mbCommand = pWindowImpl->mbCommand;
+    mpWindowImpl->mbDefPos = pWindowImpl->mbDefPos;
+    mpWindowImpl->mbDefSize = pWindowImpl->mbDefSize;
+    mpWindowImpl->mbCallMove = pWindowImpl->mbCallMove;
+    mpWindowImpl->mbCallResize = pWindowImpl->mbCallResize;
+    mpWindowImpl->mbWaitSystemResize = pWindowImpl->mbWaitSystemResize;
+    mpWindowImpl->mbInitWinClipRegion = pWindowImpl->mbInitWinClipRegion;
+    mpWindowImpl->mbInitChildRegion = pWindowImpl->mbInitChildRegion;
+    mpWindowImpl->mbWinRegion = pWindowImpl->mbWinRegion;
+    mpWindowImpl->mbClipChildren = pWindowImpl->mbClipChildren;
+    mpWindowImpl->mbClipSiblings = pWindowImpl->mbClipSiblings;
+    mpWindowImpl->mbChildTransparent = pWindowImpl->mbChildTransparent;
+    mpWindowImpl->mbPaintTransparent = pWindowImpl->mbPaintTransparent;
+    mpWindowImpl->mbMouseTransparent = pWindowImpl->mbMouseTransparent;
+    mpWindowImpl->mbDlgCtrlStart = pWindowImpl->mbDlgCtrlStart;
+    mpWindowImpl->mbFocusVisible = pWindowImpl->mbFocusVisible;
+    mpWindowImpl->mbTrackVisible = pWindowImpl->mbTrackVisible;
+    mpWindowImpl->mbUseNativeFocus = pWindowImpl->mbUseNativeFocus;
+    mpWindowImpl->mbNativeFocusVisible = pWindowImpl->mbNativeFocusVisible;
+    mpWindowImpl->mbInShowFocus = pWindowImpl->mbInShowFocus;
+    mpWindowImpl->mbInHideFocus = pWindowImpl->mbInHideFocus;
+    mpWindowImpl->mbControlForeground = pWindowImpl->mbControlForeground;
+    mpWindowImpl->mbControlBackground = pWindowImpl->mbControlBackground;
+    mpWindowImpl->mbAlwaysOnTop = pWindowImpl->mbAlwaysOnTop;
+    mpWindowImpl->mbCompoundControl = pWindowImpl->mbCompoundControl;
+    mpWindowImpl->mbCompoundControlHasFocus = pWindowImpl->mbCompoundControlHasFocus;
+    mpWindowImpl->mbPaintDisabled = pWindowImpl->mbPaintDisabled;
+    mpWindowImpl->mbAllResize = pWindowImpl->mbAllResize;
+    mpWindowImpl->mbInDtor = pWindowImpl->mbInDtor;
+    mpWindowImpl->mbExtTextInput = pWindowImpl->mbExtTextInput;
+    mpWindowImpl->mbInFocusHdl = pWindowImpl->mbInFocusHdl;
+    mpWindowImpl->mbOverlapVisible = pWindowImpl->mbOverlapVisible;
+    mpWindowImpl->mbCreatedWithToolkit = pWindowImpl->mbCreatedWithToolkit;
+    mpWindowImpl->mbToolBox = pWindowImpl->mbToolBox;
+    mpWindowImpl->mbSplitter = pWindowImpl->mbSplitter;
+    mpWindowImpl->mbSuppressAccessibilityEvents = pWindowImpl->mbSuppressAccessibilityEvents;
+    mpWindowImpl->mbMenuFloatingWindow = pWindowImpl->mbMenuFloatingWindow;
+    mpWindowImpl->mbDrawSelectionBackground = pWindowImpl->mbDrawSelectionBackground;
+    mpWindowImpl->mbIsInTaskPaneList = pWindowImpl->mbIsInTaskPaneList;
+    mpWindowImpl->mbToolbarFloatingWindow = pWindowImpl->mbToolbarFloatingWindow;
+    mpWindowImpl->mbCallHandlersDuringInputDisabled = pWindowImpl->mbCallHandlersDuringInputDisabled;
+    mpWindowImpl->mbDisableAccessibleLabelForRelation = pWindowImpl->mbDisableAccessibleLabelForRelation;
+    mpWindowImpl->mbDisableAccessibleLabeledByRelation = pWindowImpl->mbDisableAccessibleLabeledByRelation;
+    mpWindowImpl->mbHelpTextDynamic = pWindowImpl->mbHelpTextDynamic;
+    mpWindowImpl->mbFakeFocusSet = pWindowImpl->mbFakeFocusSet;
+    mpWindowImpl->mbInterceptChildWindowKeyDown = pWindowImpl->mbInterceptChildWindowKeyDown;
+
+    std::swap(m_aWidgetProperties, rOther.m_aWidgetProperties);
+}
+
 bool Window::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
 {
     if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("label")))


More information about the Libreoffice-commits mailing list