[Libreoffice-commits] .: basctl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Sep 7 02:14:33 PDT 2012


 basctl/source/basicide/baside3.cxx |   83 +++++++++++++++++++++++++++++++------
 basctl/source/basicide/layout.cxx  |   43 ++++++++++++++++++-
 basctl/source/basicide/layout.hxx  |    3 +
 basctl/source/dlged/dlged.cxx      |   10 ++--
 basctl/source/dlged/propbrw.cxx    |    7 ++-
 basctl/source/inc/baside3.hxx      |   14 ++++--
 basctl/source/inc/dlged.hxx        |    6 +-
 basctl/source/inc/propbrw.hxx      |    6 +-
 8 files changed, 144 insertions(+), 28 deletions(-)

New commits:
commit 5764c51f2c9870c91727464c0d889d3554a5663e
Author: Uray M. János <uray.janos at gmail.com>
Date:   Wed Sep 5 19:41:42 2012 +0200

    Fix for docking property browser
    
    This fixes the crash of 'Basic IDE: Docking property browser under
    object catalog' commit. The aPropertyBrowser data member was replaced by
    a new-allocated pointer. We need this because toolkit releases it by
    delete.
    When the property browser is closed in the floating state, it tells
    DialogWindowLayout to null the pointer. If the user clicks the 'property
    browser' button on the toolbar, it is created again.
    
    Change-Id: Ie842a72fe37dfdd2ed5921ffa2f1f41d3f2c51c6
    Reviewed-on: https://gerrit.libreoffice.org/568
    Tested-by: Noel Power <noel.power at suse.com>
    Reviewed-by: Noel Power <noel.power at suse.com>

diff --git a/basctl/source/basicide/baside3.cxx b/basctl/source/basicide/baside3.cxx
index 3f87967..ef03686 100644
--- a/basctl/source/basicide/baside3.cxx
+++ b/basctl/source/basicide/baside3.cxx
@@ -86,7 +86,7 @@ DialogWindow::DialogWindow (
 {
     InitSettings( true, true, true );
 
-    pEditor = new DlgEditor(rDocument.isDocument() ? rDocument.getDocument() : Reference<frame::XModel>(), rLayout.aPropertyBrowser);
+    pEditor = new DlgEditor(rDocument.isDocument() ? rDocument.getDocument() : Reference<frame::XModel>(), rLayout);
     pEditor->SetWindow( this );
     pEditor->SetDialog( xDialogModel );
 
@@ -683,12 +683,12 @@ bool DialogWindow::RenameDialog( const ::rtl::OUString& rNewName )
 
 void DialogWindow::DisableBrowser()
 {
-    rLayout.aPropertyBrowser.Update(0);
+    rLayout.DisablePropertyBrowser();
 }
 
 void DialogWindow::UpdateBrowser()
 {
-    rLayout.aPropertyBrowser.Update(GetShell());
+    rLayout.UpdatePropertyBrowser();
 }
 
 static ::rtl::OUString aResourceResolverPropName( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" ));
@@ -1433,8 +1433,56 @@ DialogWindowLayout::DialogWindowLayout (Window* pParent, ObjectCatalog& rObjectC
     Layout(pParent),
     pChild(0),
     rObjectCatalog(rObjectCatalog_),
-    aPropertyBrowser(*this)
-{ }
+    pPropertyBrowser(0)
+{
+    ShowPropertyBrowser();
+}
+
+// shows the property browser (and creates if neccessary)
+void DialogWindowLayout::ShowPropertyBrowser ()
+{
+    // not exists?
+    if (!pPropertyBrowser)
+    {
+        // creating
+        pPropertyBrowser = new PropBrw(*this);
+        // after OnFirstSize():
+        if (HasSize())
+            AddPropertyBrowser();
+        // updating if neccessary
+        UpdatePropertyBrowser();
+    }
+    pPropertyBrowser->Show();
+    // refreshing the button state
+    if (SfxBindings* pBindings = GetBindingsPtr())
+        pBindings->Invalidate(SID_SHOW_PROPERTYBROWSER);
+}
+
+// disables the property browser
+void DialogWindowLayout::DisablePropertyBrowser ()
+{
+    if (pPropertyBrowser)
+        pPropertyBrowser->Update(0);
+}
+
+// updates the property browser
+void DialogWindowLayout::UpdatePropertyBrowser ()
+{
+    if (pPropertyBrowser)
+        pPropertyBrowser->Update(GetShell());
+}
+
+// Removes the property browser from the layout.
+// Called by PropBrw when closed. It'll destroy itself.
+void DialogWindowLayout::RemovePropertyBrowser ()
+{
+    if (pPropertyBrowser)
+        Remove(pPropertyBrowser);
+    pPropertyBrowser = 0;
+    // refreshing the button state
+    if (SfxBindings* pBindings = GetBindingsPtr())
+        pBindings->Invalidate(SID_SHOW_PROPERTYBROWSER);
+}
 
 void DialogWindowLayout::Activating (BaseWindow& rChild)
 {
@@ -1443,7 +1491,8 @@ void DialogWindowLayout::Activating (BaseWindow& rChild)
     rObjectCatalog.SetLayoutWindow(this);
     rObjectCatalog.UpdateEntries();
     rObjectCatalog.Show();
-    aPropertyBrowser.Show();
+    if (pPropertyBrowser)
+        pPropertyBrowser->Show();
     Layout::Activating(rChild);
 }
 
@@ -1451,7 +1500,8 @@ void DialogWindowLayout::Deactivating ()
 {
     Layout::Deactivating();
     rObjectCatalog.Hide();
-    aPropertyBrowser.Hide();
+    if (pPropertyBrowser)
+        pPropertyBrowser->Hide();
     pChild = 0;
 }
 
@@ -1461,9 +1511,12 @@ void DialogWindowLayout::ExecuteGlobal (SfxRequest& rReq)
     {
         case SID_SHOW_PROPERTYBROWSER:
             // toggling property browser
-            aPropertyBrowser.Show(!aPropertyBrowser.IsVisible());
+            if (pPropertyBrowser && pPropertyBrowser->IsVisible())
+                pPropertyBrowser->Hide();
+            else
+                ShowPropertyBrowser();
             ArrangeWindows();
-            // refresh the button state
+            // refreshing the button state
             if (SfxBindings* pBindings = GetBindingsPtr())
                 pBindings->Invalidate(SID_SHOW_PROPERTYBROWSER);
             break;
@@ -1475,7 +1528,7 @@ void DialogWindowLayout::GetState (SfxItemSet& rSet, unsigned nWhich)
     switch (nWhich)
     {
         case SID_SHOW_PROPERTYBROWSER:
-            rSet.Put(SfxBoolItem(nWhich, aPropertyBrowser.IsVisible()));
+            rSet.Put(SfxBoolItem(nWhich, pPropertyBrowser && pPropertyBrowser->IsVisible()));
             break;
 
         case SID_BASICIDE_CHOOSEMACRO:
@@ -1486,8 +1539,14 @@ void DialogWindowLayout::GetState (SfxItemSet& rSet, unsigned nWhich)
 
 void DialogWindowLayout::OnFirstSize (int const nWidth, int const nHeight)
 {
-    AddToLeft(&rObjectCatalog,   Size(nWidth * 0.25, nHeight * 0.35));
-    AddToLeft(&aPropertyBrowser, Size(nWidth * 0.25, nHeight * 0.65));
+    AddToLeft(&rObjectCatalog, Size(nWidth * 0.25, nHeight * 0.35));
+    if (pPropertyBrowser)
+        AddPropertyBrowser();
+}
+
+void DialogWindowLayout::AddPropertyBrowser () {
+    Size const aSize = GetOutputSizePixel();
+    AddToLeft(pPropertyBrowser, Size(aSize.Width() * 0.25, aSize.Height() * 0.65));
 }
 
 
diff --git a/basctl/source/basicide/layout.cxx b/basctl/source/basicide/layout.cxx
index 5d1be2e..32edb58 100644
--- a/basctl/source/basicide/layout.cxx
+++ b/basctl/source/basicide/layout.cxx
@@ -56,6 +56,13 @@ Layout::Layout (Window* pParent) :
 Layout::~Layout()
 { }
 
+// removes a docking window
+void Layout::Remove (DockingWindow* pWin)
+{
+    aLeftSide.Remove(pWin);
+    aBottomSide.Remove(pWin);
+}
+
 // called by Window when resized
 void Layout::Resize()
 {
@@ -70,10 +77,18 @@ void Layout::ArrangeWindows ()
     int const nWidth = aSize.Width(), nHeight = aSize.Height();
     if (!nWidth || !nHeight) // empty size
         return;
+
+    // prevent recursion via OnFirstSize() -> Add() -> ArrangeWindows()
+    static bool bRecursion = false;
+    if (bRecursion)
+        return;
+    bRecursion = true;
+
+    // on first call
     if (bFirstSize)
     {
-        this->OnFirstSize(nWidth, nHeight); // virtual
         bFirstSize = false;
+        this->OnFirstSize(nWidth, nHeight); // virtual
     }
 
     // sides
@@ -84,6 +99,8 @@ void Layout::ArrangeWindows ()
         Point(aLeftSide.GetSize(), 0),
         Size(nWidth - aLeftSide.GetSize(), nHeight - aBottomSide.GetSize())
     );
+
+    bRecursion = false;
 }
 
 void Layout::DockaWindow (DockingWindow*)
@@ -175,6 +192,30 @@ void Layout::SplittedSide::Add (DockingWindow* pWin, Size const& rSize)
     }
     // nLastPos
     nLastPos += nSize2 + nSplitThickness;
+    // refresh
+    rLayout.ArrangeWindows();
+}
+
+// Remove() -- removes a window from the side (if contains)
+void Layout::SplittedSide::Remove (DockingWindow* pWin)
+{
+    // contains?
+    std::vector<DockingWindow*>::iterator const itWin =
+        std::find(vWindows.begin(), vWindows.end(), pWin);
+    if (itWin == vWindows.end())
+        return;
+    // index
+    unsigned const iWin = itWin - vWindows.begin();
+    // nLastPos
+    if (iWin == vWindows.size() - 1) // that is the last one
+        nLastPos = vSplitters.back()->GetSplitPosPixel() + nSplitThickness;
+    // remove
+    vWindows.erase(itWin);
+    // remove a splitter line
+    if (!vSplitters.empty())
+        vSplitters.pop_back();
+    // refresh
+    rLayout.ArrangeWindows();
 }
 
 // creating a Point or a Size object
diff --git a/basctl/source/basicide/layout.hxx b/basctl/source/basicide/layout.hxx
index 9f56321..6a63547 100644
--- a/basctl/source/basicide/layout.hxx
+++ b/basctl/source/basicide/layout.hxx
@@ -59,6 +59,8 @@ protected:
 
     void AddToLeft   (DockingWindow* pWin, Size const& rSize) { aLeftSide.Add(pWin, rSize); }
     void AddToBottom (DockingWindow* pWin, Size const& rSize) { aBottomSide.Add(pWin, rSize); }
+    void Remove (DockingWindow*);
+    bool HasSize () const { return !bFirstSize; }
 
 protected:
     // Window:
@@ -81,6 +83,7 @@ private:
         enum Side {Right, Top, Left, Bottom};
         SplittedSide (Layout*, Side);
         void Add (DockingWindow*, Size const&);
+        void Remove (DockingWindow*);
         bool IsEmpty () const;
         int  GetSize () const;
         void ArrangeIn (Rectangle const&);
diff --git a/basctl/source/dlged/dlged.cxx b/basctl/source/dlged/dlged.cxx
index 67e6d65..c087e67 100644
--- a/basctl/source/dlged/dlged.cxx
+++ b/basctl/source/dlged/dlged.cxx
@@ -30,7 +30,7 @@
 #include "dlgedview.hxx"
 #include "iderdll.hxx"
 #include "localizationmgr.hxx"
-#include "propbrw.hxx"
+#include "baside3.hxx"
 
 #include <com/sun/star/awt/XDialog.hpp>
 #include <com/sun/star/resource/XStringResourcePersistence.hpp>
@@ -176,7 +176,7 @@ bool DlgEditor::RemarkDialog()
 
 DlgEditor::DlgEditor (
     com::sun::star::uno::Reference<com::sun::star::frame::XModel> const& xModel,
-    PropBrw& rPropertyBrowser_
+    DialogWindowLayout& rLayout_
 )
     :pHScroll(NULL)
     ,pVScroll(NULL)
@@ -190,7 +190,7 @@ DlgEditor::DlgEditor (
     ,pObjFac(NULL)
     ,pWindow(NULL)
     ,pFunc(NULL)
-    ,rPropertyBrowser(rPropertyBrowser_)
+    ,rLayout(rLayout_)
     ,eMode( DlgEditor::SELECT )
     ,eActObj( OBJ_DLG_PUSHBUTTON )
     ,bFirstDraw(false)
@@ -612,7 +612,7 @@ IMPL_LINK_NOARG(DlgEditor, PaintTimeout)
 
 IMPL_LINK_NOARG(DlgEditor, MarkTimeout)
 {
-    rPropertyBrowser.Update(GetShell());
+    rLayout.UpdatePropertyBrowser();
     return 1;
 }
 
@@ -1125,7 +1125,7 @@ bool DlgEditor::IsPasteAllowed()
 
 void DlgEditor::ShowProperties()
 {
-    rPropertyBrowser.Show(!rPropertyBrowser.IsVisible());
+    rLayout.ShowPropertyBrowser();
 }
 
 
diff --git a/basctl/source/dlged/propbrw.cxx b/basctl/source/dlged/propbrw.cxx
index c3bd5d2..04a0a79 100644
--- a/basctl/source/dlged/propbrw.cxx
+++ b/basctl/source/dlged/propbrw.cxx
@@ -22,6 +22,7 @@
 #include "basidesh.hxx"
 #include "dlgedobj.hxx"
 #include "iderid.hxx"
+#include "baside3.hxx"
 
 #include "dlgresid.hrc"
 #include <svx/svxids.hrc>
@@ -79,11 +80,12 @@ const long WIN_BORDER = 2;
 DBG_NAME(PropBrw)
 
 
-PropBrw::PropBrw (Layout& rLayout):
-    DockingWindow(&rLayout),
+PropBrw::PropBrw (DialogWindowLayout& rLayout_):
+    DockingWindow(&rLayout_),
     m_bInitialStateChange(true),
     m_xORB(comphelper::getProcessServiceFactory()),
     m_xContextDocument(SfxViewShell::Current() ? SfxViewShell::Current()->GetCurrentDocument() : Reference<XModel>()),
+    rLayout(rLayout_),
     pView(0)
 {
     DBG_CTOR(PropBrw,NULL);
@@ -201,6 +203,7 @@ PropBrw::~PropBrw()
 {
     if ( m_xBrowserController.is() )
         ImplDestroyController();
+    rLayout.RemovePropertyBrowser();
 
     DBG_DTOR(PropBrw,NULL);
 }
diff --git a/basctl/source/inc/baside3.hxx b/basctl/source/inc/baside3.hxx
index 6f4d86e..6e32162 100644
--- a/basctl/source/inc/baside3.hxx
+++ b/basctl/source/inc/baside3.hxx
@@ -125,6 +125,11 @@ class DialogWindowLayout : public Layout
 public:
     DialogWindowLayout (Window* pParent, ObjectCatalog&);
 public:
+    void ShowPropertyBrowser ();
+    void UpdatePropertyBrowser ();
+    void DisablePropertyBrowser ();
+    void RemovePropertyBrowser ();
+public:
     // Layout:
     virtual void Activating (BaseWindow&);
     virtual void Deactivating ();
@@ -138,12 +143,15 @@ protected:
 private:
     // child window
     DialogWindow* pChild;
-    // dockable windows
+    // dockable windows:
+    // object catalog (owned by Shell)
     ObjectCatalog& rObjectCatalog;
-    // property browser
-    PropBrw aPropertyBrowser;
+    // property browser (created by this, deleted by toolkit)
+    PropBrw* pPropertyBrowser;
 
 private:
+    void AddPropertyBrowser ();
+private:
     friend class DialogWindow;
 };
 
diff --git a/basctl/source/inc/dlged.hxx b/basctl/source/inc/dlged.hxx
index 9f52cd4..a564f97 100644
--- a/basctl/source/inc/dlged.hxx
+++ b/basctl/source/inc/dlged.hxx
@@ -40,7 +40,7 @@ class Window;
 namespace basctl
 {
 
-class PropBrw;
+class DialogWindowLayout;
 
 #define DLGED_PAGE_WIDTH_MIN    1280
 #define DLGED_PAGE_HEIGHT_MIN   1024
@@ -119,7 +119,7 @@ private:
     DlgEdFactory*       pObjFac;
     Window*             pWindow;
     DlgEdFunc*          pFunc;
-    PropBrw&            rPropertyBrowser;
+    DialogWindowLayout& rLayout;
     Mode                eMode;
     sal_uInt16          eActObj;
     bool                bFirstDraw;
@@ -136,7 +136,7 @@ private:
 
     DlgEditor(); // not implemented
 public:
-    DlgEditor (com::sun::star::uno::Reference<com::sun::star::frame::XModel> const& xModel, PropBrw&);
+    DlgEditor (com::sun::star::uno::Reference<com::sun::star::frame::XModel> const& xModel, DialogWindowLayout&);
     ~DlgEditor();
 
     void            SetWindow( Window* pWindow );
diff --git a/basctl/source/inc/propbrw.hxx b/basctl/source/inc/propbrw.hxx
index a3bbad9..e8011ef 100644
--- a/basctl/source/inc/propbrw.hxx
+++ b/basctl/source/inc/propbrw.hxx
@@ -34,7 +34,7 @@ class SfxViewShell;
 namespace basctl
 {
 
-class Layout;
+class DialogWindowLayout;
 
 class PropBrw : public DockingWindow, public SfxListener, public SfxBroadcaster
 {
@@ -52,6 +52,8 @@ private:
     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >
                     m_xContextDocument;
 
+    DialogWindowLayout& rLayout;
+
 protected:
     SdrView*        pView;
     virtual void Resize();
@@ -71,7 +73,7 @@ protected:
         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxObject);
 
 public:
-    explicit PropBrw (Layout&);
+    explicit PropBrw (DialogWindowLayout&);
     virtual ~PropBrw();
     using Window::Update;
     // note: changing the Context document to an instance other than the one given in the ctor is not supported


More information about the Libreoffice-commits mailing list