You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by af...@apache.org on 2013/02/19 10:09:05 UTC

svn commit: r1447641 [6/9] - in /openoffice/branches/sidebar/main: default_images/sfx2/res/symphony/ framework/inc/services/ framework/source/services/ offapi/com/sun/star/ui/ officecfg/registry/data/org/openoffice/Office/ officecfg/registry/data/org/o...

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.cxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.cxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.cxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,416 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#include "precompiled_sd.hxx"
+
+#include "MasterPageDescriptor.hxx"
+
+#include "DocumentHelper.hxx"
+#include "sdpage.hxx"
+#include <tools/urlobj.hxx>
+
+namespace sd { namespace sidebar {
+
+
+//===== MasterPageDescriptor ==================================================
+
+MasterPageDescriptor::MasterPageDescriptor (
+    MasterPageContainer::Origin eOrigin,
+    const sal_Int32 nTemplateIndex,
+    const String& rsURL,
+    const String& rsPageName,
+    const String& rsStyleName,
+    const bool bIsPrecious,
+    const ::boost::shared_ptr<PageObjectProvider>& rpPageObjectProvider,
+    const ::boost::shared_ptr<PreviewProvider>& rpPreviewProvider)
+    : maToken(MasterPageContainer::NIL_TOKEN),
+      meOrigin(eOrigin),
+      msURL(INetURLObject(rsURL).GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS)),
+      msPageName(rsPageName),
+      msStyleName(rsStyleName),
+      mbIsPrecious(bIsPrecious),
+      mpMasterPage(NULL),
+      mpSlide(NULL),
+      maSmallPreview(),
+      maLargePreview(),
+      mpPreviewProvider(rpPreviewProvider),
+      mpPageObjectProvider(rpPageObjectProvider),
+      mnTemplateIndex(nTemplateIndex),
+      meURLClassification(URLCLASS_UNDETERMINED),
+      mnUseCount(0)
+{
+}
+   
+
+
+
+MasterPageDescriptor::MasterPageDescriptor (const MasterPageDescriptor& rDescriptor)
+    : maToken(rDescriptor.maToken),
+      meOrigin(rDescriptor.meOrigin),
+      msURL(rDescriptor.msURL),
+      msPageName(rDescriptor.msPageName),
+      msStyleName(rDescriptor.msStyleName),
+      mbIsPrecious(rDescriptor.mbIsPrecious),
+      mpMasterPage(rDescriptor.mpMasterPage),
+      mpSlide(rDescriptor.mpSlide),
+      maSmallPreview(rDescriptor.maSmallPreview),
+      maLargePreview(rDescriptor.maLargePreview),
+      mpPreviewProvider(rDescriptor.mpPreviewProvider),
+      mpPageObjectProvider(rDescriptor.mpPageObjectProvider),
+      mnTemplateIndex(rDescriptor.mnTemplateIndex),
+      meURLClassification(rDescriptor.meURLClassification),
+      mnUseCount(rDescriptor.mnUseCount)
+{
+}
+
+
+
+
+MasterPageDescriptor::~MasterPageDescriptor (void)
+{
+}
+
+
+
+
+void MasterPageDescriptor::SetToken (MasterPageContainer::Token aToken)
+{
+    maToken = aToken;
+}
+
+
+
+
+Image MasterPageDescriptor::GetPreview (MasterPageContainer::PreviewSize eSize)
+{
+    if (eSize == MasterPageContainer::SMALL)
+        return maSmallPreview;
+    else
+        return maLargePreview;
+}
+
+
+
+
+::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> >
+    MasterPageDescriptor::Update (
+        const MasterPageDescriptor& rDescriptor)
+{
+    bool bDataChanged (false);
+    bool bIndexChanged (false);
+    bool bPreviewChanged (false);
+
+    if (meOrigin==MasterPageContainer::UNKNOWN
+        && rDescriptor.meOrigin!=MasterPageContainer::UNKNOWN)
+    {
+        meOrigin = rDescriptor.meOrigin;
+        bIndexChanged = true;
+    }
+    
+    if (msURL.getLength()==0 && rDescriptor.msURL.getLength()!=0)
+    {
+        msURL = rDescriptor.msURL;
+        bDataChanged = true;
+    }
+    
+    if (msPageName.getLength()==0 && rDescriptor.msPageName.getLength()!=0)
+    {
+        msPageName = rDescriptor.msPageName;
+        bDataChanged = true;
+    }
+    
+    if (msStyleName.getLength()==0 && rDescriptor.msStyleName.getLength()!=0)
+    {
+        msStyleName = rDescriptor.msStyleName;
+        bDataChanged = true;
+    }
+    
+    if (mpPageObjectProvider.get()==NULL && rDescriptor.mpPageObjectProvider.get()!=NULL)
+    {
+        mpPageObjectProvider = rDescriptor.mpPageObjectProvider;
+        bDataChanged = true;
+    }
+    
+     if (mpPreviewProvider.get()==NULL && rDescriptor.mpPreviewProvider.get()!=NULL)
+     {
+         mpPreviewProvider = rDescriptor.mpPreviewProvider;
+         bPreviewChanged = true;
+     }
+
+     if (mnTemplateIndex<0 && rDescriptor.mnTemplateIndex>=0)
+     {
+         mnTemplateIndex = rDescriptor.mnTemplateIndex;
+         bIndexChanged = true;
+     }
+
+     // Prepare the list of event types that will be returned.
+     ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > pResult;
+     if (bDataChanged || bIndexChanged || bPreviewChanged)
+     {
+         pResult.reset(new std::vector<MasterPageContainerChangeEvent::EventType>());
+         if (bDataChanged)
+             pResult->push_back(MasterPageContainerChangeEvent::DATA_CHANGED);
+         if (bIndexChanged)
+             pResult->push_back(MasterPageContainerChangeEvent::INDEX_CHANGED);
+         if (bPreviewChanged)
+             pResult->push_back(MasterPageContainerChangeEvent::PREVIEW_CHANGED);
+     }
+     
+     return pResult;
+}
+
+
+
+
+bool MasterPageDescriptor::UpdatePageObject (
+    sal_Int32 nCostThreshold,
+    SdDrawDocument* pDocument)
+{
+    bool bModified (false);
+    
+    // Update the page object when that is not yet known.
+    if (mpMasterPage == NULL
+        && mpPageObjectProvider.get()!=NULL
+        && (nCostThreshold<0 || mpPageObjectProvider->GetCostIndex()<=nCostThreshold))
+    {
+        // Note that pDocument may be NULL.
+            
+        SdPage* pPage = (*mpPageObjectProvider)(pDocument);
+        if (meOrigin == MasterPageContainer::MASTERPAGE)
+        {
+            mpMasterPage = pPage;
+            if (mpMasterPage != NULL)
+                mpMasterPage->SetPrecious(mbIsPrecious);
+        }
+        else
+        {
+            // Master pages from templates are copied into the local document.
+            if (pDocument != NULL)
+                mpMasterPage = DocumentHelper::CopyMasterPageToLocalDocument(*pDocument,pPage);
+            mpSlide = DocumentHelper::GetSlideForMasterPage(mpMasterPage);
+        }
+
+        if (mpMasterPage != NULL)
+        {
+            // Update page name and style name.
+            if (msPageName.getLength() == 0)
+                msPageName = mpMasterPage->GetName();
+            msStyleName = mpMasterPage->GetName();
+
+            // Delete an existing substitution. The next request for a preview
+            // will create the real one.
+            maSmallPreview = Image();
+            maLargePreview = Image();
+            mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider());
+        }
+        else
+        {
+            DBG_ASSERT(false, "UpdatePageObject: master page is NULL");
+        }
+
+        bModified = true;
+    }
+
+    return bModified;
+}
+
+
+
+
+bool MasterPageDescriptor::UpdatePreview (
+    sal_Int32 nCostThreshold,
+    const Size& rSmallSize,
+    const Size& rLargeSize,
+    ::sd::PreviewRenderer& rRenderer)
+{
+    bool bModified (false);
+    
+    // Update the preview when that is not yet known.
+    if (maLargePreview.GetSizePixel().Width()==0
+        && mpPreviewProvider.get()!=NULL
+        && (nCostThreshold<0 || mpPreviewProvider->GetCostIndex()<=nCostThreshold))
+    {
+        SdPage* pPage = mpSlide;
+        if (pPage == NULL)
+        {
+            pPage = mpMasterPage;
+        }
+        maLargePreview = (*mpPreviewProvider)(
+            rLargeSize.Width(),
+            pPage,
+            rRenderer);
+        if (maLargePreview.GetSizePixel().Width() > 0)
+        {
+            // Create the small preview by scaling the large one down.
+            maSmallPreview = rRenderer.ScaleBitmap(
+                maLargePreview.GetBitmapEx(),
+                rSmallSize.Width());
+            // The large preview may not have the desired width.  Scale it
+            // accrodingly.
+            if (maLargePreview.GetSizePixel().Width() != rLargeSize.Width())
+                maLargePreview = rRenderer.ScaleBitmap(
+                    maLargePreview.GetBitmapEx(),
+                    rLargeSize.Width());
+            bModified = true;
+        }
+    }
+
+    return bModified;
+}
+
+
+
+
+MasterPageDescriptor::URLClassification MasterPageDescriptor::GetURLClassification (void)
+{
+    if (meURLClassification == URLCLASS_UNDETERMINED)
+    {
+        if (msURL.getLength() == 0)
+            meURLClassification = URLCLASS_UNKNOWN;
+        else if (msURL.indexOf(::rtl::OUString::createFromAscii("presnt"))>=0)
+        {
+            meURLClassification = URLCLASS_PRESENTATION;
+        }
+        else if (msURL.indexOf(::rtl::OUString::createFromAscii("layout"))>=0)
+        {
+            meURLClassification = URLCLASS_LAYOUT;
+        }
+        else if (msURL.indexOf(::rtl::OUString::createFromAscii("educate"))>=0)
+        {
+            meURLClassification = URLCLASS_OTHER;
+        }
+        else
+        {
+            meURLClassification = URLCLASS_USER;
+        }
+    }
+    
+    return meURLClassification;
+}
+
+
+
+//===== URLComparator =========================================================
+
+MasterPageDescriptor::URLComparator::URLComparator (const ::rtl::OUString& sURL)
+    : msURL(sURL)
+{
+}
+
+
+
+
+bool MasterPageDescriptor::URLComparator::operator() (
+    const SharedMasterPageDescriptor& rDescriptor)
+{
+    if (rDescriptor.get() == NULL)
+        return false;
+    else
+        return rDescriptor->msURL.equals(msURL);
+}
+
+
+
+
+// ===== StyleNameComparator ==================================================
+
+MasterPageDescriptor::StyleNameComparator::StyleNameComparator (const ::rtl::OUString& sStyleName)
+    : msStyleName(sStyleName)
+{
+}
+
+
+
+
+bool MasterPageDescriptor::StyleNameComparator::operator() (
+    const SharedMasterPageDescriptor& rDescriptor)
+{
+    if (rDescriptor.get() == NULL)
+        return false;
+    else
+        return rDescriptor->msStyleName.equals(msStyleName);
+}
+
+
+
+
+//===== PageObjectComparator ==================================================
+
+MasterPageDescriptor::PageObjectComparator::PageObjectComparator (const SdPage* pPageObject) 
+    : mpMasterPage(pPageObject)
+{
+}
+
+
+
+
+bool MasterPageDescriptor::PageObjectComparator::operator() (
+    const SharedMasterPageDescriptor& rDescriptor)
+{
+    if (rDescriptor.get() == NULL)
+        return false;
+    else
+        return rDescriptor->mpMasterPage==mpMasterPage;
+}
+
+
+
+
+//===== AllComparator =========================================================
+
+MasterPageDescriptor::AllComparator::AllComparator(const SharedMasterPageDescriptor& rDescriptor)
+    : mpDescriptor(rDescriptor)
+{
+}
+
+
+
+
+bool MasterPageDescriptor::AllComparator::operator() (const SharedMasterPageDescriptor&rDescriptor)
+{
+    if (rDescriptor.get() == NULL)
+        return false;
+    else
+    {
+        // Take URL, page name, style name, and page object into account
+        // when comparing two descriptors.  When two descriptors are
+        // identical in any of these values then their are thought of as
+        // equivalent.  Only the Origin has to be the same in both
+        // descriptors.
+        return
+            mpDescriptor->meOrigin == rDescriptor->meOrigin
+            && (
+                (mpDescriptor->msURL.getLength()>0
+                    && mpDescriptor->msURL.equals(rDescriptor->msURL))
+                || (mpDescriptor->msPageName.getLength()>0
+                    && mpDescriptor->msPageName.equals(rDescriptor->msPageName))
+                || (mpDescriptor->msStyleName.getLength()>0
+                    && mpDescriptor->msStyleName.equals(rDescriptor->msStyleName))
+                || (mpDescriptor->mpMasterPage!=NULL
+                    && mpDescriptor->mpMasterPage==rDescriptor->mpMasterPage)
+                || (mpDescriptor->mpPageObjectProvider.get()!=NULL
+                    && rDescriptor->mpPageObjectProvider.get()!=NULL
+                    && mpDescriptor->mpPageObjectProvider==rDescriptor->mpPageObjectProvider));
+    }
+}
+
+
+} } // end of namespace sd::sidebar

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.hxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.hxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageDescriptor.hxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,234 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_DESCRIPTOR_HXX
+#define SD_SIDEBAR_PANELS_MASTER_PAGE_DESCRIPTOR_HXX
+
+#include "MasterPageContainer.hxx"
+#include <boost/shared_ptr.hpp>
+
+namespace sd { namespace sidebar {
+
+class PageObjectProvider;
+class PreviewProvider;
+
+class MasterPageDescriptor;
+typedef ::boost::shared_ptr<MasterPageDescriptor> SharedMasterPageDescriptor;
+
+/** A collection of data that is stored for every master page in the
+    MasterpageContainer.
+*/
+class MasterPageDescriptor
+{
+public:
+    MasterPageDescriptor (
+        MasterPageContainer::Origin eOrigin,
+        const sal_Int32 nTemplateIndex,
+        const String& rURL,
+        const String& rPageName,
+        const String& rStyleName,
+        const bool bIsPrecious,
+        const ::boost::shared_ptr<PageObjectProvider>& rpPageObjectProvider,
+        const ::boost::shared_ptr<PreviewProvider>& rpPreviewProvider);
+    MasterPageDescriptor (const MasterPageDescriptor& rDescriptor);
+    ~MasterPageDescriptor (void);
+
+    void SetToken (MasterPageContainer::Token aToken);
+
+    /** Update the called MasterPageDescriptor object with values from the
+        given one.  Only those values are updated that have default values
+        in the called object and that have non-default values in the given
+        one.
+        @return
+            Returns a list of event types for which event notifications have
+            to be sent to listeners.  The list may be empty or NULL.
+    */
+    ::std::auto_ptr<std::vector<MasterPageContainerChangeEvent::EventType> >
+        Update (
+            const MasterPageDescriptor& rDescriptor);
+    
+    /** This convenience method returns either a small or a large preview,
+        depending on the given size specifier.
+        Note that the previews are not created when they are not present.
+        @return
+            The returned preview may be empty.
+    */
+    Image GetPreview (MasterPageContainer::PreviewSize ePreviewSize);
+
+    /** Use the PreviewProvider to get access to a preview of the master
+        page.
+        
+        Note that this is only done, when either bForce is <TRUE/> or
+        the PreviewProvider::GetCostIndex() returns 0.
+        
+        The small preview is created by scaling the large one, not by
+        calling PreviewProvider::operator() a second time.
+        
+        It is the responsibility of the caller to call UpdatePageObject()
+        before calling this method  when the PreviewProvider can only work
+        when the master page object is present, i.e. its NeedsPageObject()
+        method returns <TRUE/>.
+        
+        @param nCostThreshold
+            When this is zero or positive then the preview is created only
+            when the preview provider has a cost equal to or smaller than
+            this threshold.  A negative value forces the preview to be
+            created, regardless of the cost.
+        @param rSmallSize
+            Size of the small preview.
+        @param rLargeSize
+            Size of the large preview.
+        @param rRenderer
+            A PreviewRenderer object that may be used to create a preview.
+        @return
+            When the previews are successfully provided then <TRUE/> is
+            returned.
+    */
+    bool UpdatePreview (
+        sal_Int32 nCostThreshold,
+        const Size& rSmallSize,
+        const Size& rLargeSize,
+        ::sd::PreviewRenderer& rRenderer);
+
+    /** Use the PageObjectProvider to get access to the master page object.
+        
+        Note that this is only done, when either bForce is <TRUE/> or the
+        PreviewProvider::GetCostIndex() returns 0.
+
+        @param nCostThreshold
+            When this is zero or positive then the page object is created
+            only when the page object provider has a cost equal to or
+            smaller than this threshold.  A negative value forces the
+            page object be created, regardless of the cost.
+        @param pDocument
+            This document of the MasterPageContainer may be used to create
+            a page object with or store one in.
+        @return
+            When the master page object is successfully provided then
+            <TRUE/> is returned.
+    */
+    bool UpdatePageObject (
+        sal_Int32 nCostThreshold,
+        SdDrawDocument* pDocument);
+
+    enum URLClassification {
+        URLCLASS_USER,
+        URLCLASS_LAYOUT,
+        URLCLASS_PRESENTATION,
+        URLCLASS_OTHER,
+        URLCLASS_UNKNOWN,
+        URLCLASS_UNDETERMINED
+    };
+
+    URLClassification GetURLClassification (void);
+    
+    /** The Token under which the MasterPageContainer gives access to the
+        object.
+    */
+    MasterPageContainer::Token maToken;
+
+    /** A rough specification of the origin of the master page.
+    */
+    MasterPageContainer::Origin meOrigin;
+    
+    /** The URL is not empty for master pages loaded from a template
+        document.
+    */
+    ::rtl::OUString msURL;
+    
+    /** Taken from the title of the template file.
+    */
+    ::rtl::OUString msPageName;
+    
+    /** Taken from the master page object.
+    */
+    ::rtl::OUString msStyleName;
+
+    const bool mbIsPrecious;
+
+    /** The actual master page.
+    */
+    SdPage* mpMasterPage;
+    
+    /** A slide that uses the master page.
+    */
+    SdPage* mpSlide;
+    
+    /** A small (the default size) preview of the master page.  May be
+        empty.  When this smaller preview is not empty then the larger one
+        is not empty, too.
+    */
+    Image maSmallPreview;
+    
+    /** A large preview of the master page.  May be empty.  When this larger
+        preview is not empty then the smaller one is not empty, too.
+    */
+    Image maLargePreview;
+
+    /** The prewview provider. May be empty.  May be replaced during the
+        lifetime of a MasterPageDescriptor object.
+    */
+    ::boost::shared_ptr<PreviewProvider> mpPreviewProvider;
+
+    /** The master page provider.  May be empty.  May be replaced during
+        the lifetime of a MasterPageDescriptor object.
+    */
+    ::boost::shared_ptr<PageObjectProvider> mpPageObjectProvider;
+    
+    /** This index represents the order in which templates are provided via
+        the TemplateScanner.  It defines the order in which the entries in
+        the AllMasterPagesSelector are displayed.  The default value is -1.
+    */
+    sal_Int32 mnTemplateIndex;
+
+    URLClassification meURLClassification;
+
+    sal_Int32 mnUseCount;
+
+    class URLComparator { public:
+        ::rtl::OUString msURL;
+        URLComparator (const ::rtl::OUString& sURL);
+        bool operator() (const SharedMasterPageDescriptor& rDescriptor);
+    };
+    class StyleNameComparator { public:
+        ::rtl::OUString msStyleName;
+        StyleNameComparator (const ::rtl::OUString& sStyleName);
+        bool operator() (const SharedMasterPageDescriptor& rDescriptor);
+    };
+    class PageObjectComparator { public:
+        const SdPage* mpMasterPage;
+        PageObjectComparator (const SdPage* pPageObject);
+        bool operator() (const SharedMasterPageDescriptor& rDescriptor);
+    };
+    class AllComparator { public:
+        AllComparator(const SharedMasterPageDescriptor& rDescriptor);
+        bool operator() (const SharedMasterPageDescriptor& rDescriptor);
+    private:
+        SharedMasterPageDescriptor mpDescriptor;
+    };
+
+
+};
+
+
+} } // end of namespace sd::sidebar
+
+#endif

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageObserver.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageObserver.cxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageObserver.cxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPageObserver.cxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,419 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#include "precompiled_sd.hxx"
+
+#include "MasterPageObserver.hxx"
+
+#include <algorithm>
+#include "drawdoc.hxx"
+#include "sdpage.hxx"
+#include <hash_map>
+#include <set>
+#include <vector>
+#include <svl/lstner.hxx>
+#include <osl/doublecheckedlocking.h>
+#include <osl/getglobalmutex.hxx>
+
+
+namespace sd {
+
+class MasterPageObserver::Implementation
+    : public SfxListener
+{
+public:
+    /** The single instance of this class.  It is created on demand when
+        Instance() is called for the first time.
+    */
+    static MasterPageObserver* mpInstance;
+
+    /** The master page observer will listen to events of this document and
+        detect changes of the use of master pages.
+    */
+    void RegisterDocument (SdDrawDocument& rDocument);
+
+    /** The master page observer will stop to listen to events of this
+        document.
+    */
+    void UnregisterDocument (SdDrawDocument& rDocument);
+    
+    /** Add a listener that is informed of master pages that are newly
+        assigned to slides or become unassigned.
+        @param rEventListener
+            The event listener to call for future events.  Call
+            RemoveEventListener() before the listener is destroyed.
+    */
+    void AddEventListener (const Link& rEventListener);
+
+    /** Remove the given listener from the list of listeners.
+        @param rEventListener
+            After this method returns the given listener is not called back
+            from this object.  Passing a listener that has not
+            been registered before is safe and is silently ignored.
+    */
+    void RemoveEventListener (const Link& rEventListener);
+
+    /** Return a set of the names of master pages for the given document.
+        This convenience method exists because this set is part of the
+        internal data structure and thus takes no time to create.
+    */
+    inline MasterPageObserver::MasterPageNameSet GetMasterPageNames (
+        SdDrawDocument& rDocument);
+
+private:
+    ::std::vector<Link> maListeners;
+
+    struct DrawDocHash {
+        size_t operator()(SdDrawDocument* argument) const 
+        { return reinterpret_cast<unsigned long>(argument); }
+    };
+    typedef ::std::hash_map<SdDrawDocument*,
+                            MasterPageObserver::MasterPageNameSet,
+                            DrawDocHash>
+        MasterPageContainer;
+    MasterPageContainer maUsedMasterPages;
+
+    virtual void Notify(
+        SfxBroadcaster& rBroadcaster,
+        const SfxHint& rHint);
+
+    void AnalyzeUsedMasterPages (SdDrawDocument& rDocument);
+
+    void SendEvent (MasterPageObserverEvent& rEvent);
+};
+
+MasterPageObserver* MasterPageObserver::Implementation::mpInstance = NULL;
+
+
+
+//===== MasterPageObserver ====================================================
+
+MasterPageObserver&  MasterPageObserver::Instance (void)
+{
+    if (Implementation::mpInstance == NULL)
+    {
+        ::osl::GetGlobalMutex aMutexFunctor;
+        ::osl::MutexGuard aGuard (aMutexFunctor());
+        if (Implementation::mpInstance == NULL)
+        {
+            MasterPageObserver* pInstance = new MasterPageObserver ();
+            SdGlobalResourceContainer::Instance().AddResource (
+                ::std::auto_ptr<SdGlobalResource>(pInstance));
+            OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
+            Implementation::mpInstance = pInstance;
+        }
+    }
+    else
+    {
+        OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER();
+    }
+    
+    DBG_ASSERT(Implementation::mpInstance!=NULL,
+        "MasterPageObserver::Instance(): instance is NULL");
+    return *Implementation::mpInstance;
+}
+
+
+
+
+void MasterPageObserver::RegisterDocument (SdDrawDocument& rDocument)
+{
+    mpImpl->RegisterDocument (rDocument);
+}
+
+
+
+
+void MasterPageObserver::UnregisterDocument (SdDrawDocument& rDocument)
+{
+    mpImpl->UnregisterDocument (rDocument);
+}
+
+
+
+    
+void MasterPageObserver::AddEventListener (const Link& rEventListener)
+{
+
+    mpImpl->AddEventListener (rEventListener);
+}
+
+
+
+
+void MasterPageObserver::RemoveEventListener (const Link& rEventListener)
+{
+    mpImpl->RemoveEventListener (rEventListener);
+}
+
+
+
+
+MasterPageObserver::MasterPageObserver (void)
+    : mpImpl (new Implementation())
+{}
+
+
+
+
+MasterPageObserver::~MasterPageObserver (void)
+{}
+
+
+
+
+//===== MasterPageObserver::Implementation ====================================
+
+void MasterPageObserver::Implementation::RegisterDocument (
+    SdDrawDocument& rDocument)
+{
+    // Gather the names of all the master pages in the given document.
+    MasterPageContainer::data_type aMasterPageSet;
+    sal_uInt16 nMasterPageCount = rDocument.GetMasterSdPageCount(PK_STANDARD);
+    for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++)
+    {
+        SdPage* pMasterPage = rDocument.GetMasterSdPage (nIndex, PK_STANDARD);
+        if (pMasterPage != NULL)
+            aMasterPageSet.insert (pMasterPage->GetName());
+    }
+
+    maUsedMasterPages[&rDocument] = aMasterPageSet;
+
+    StartListening (rDocument);
+}
+
+
+
+
+void MasterPageObserver::Implementation::UnregisterDocument (
+    SdDrawDocument& rDocument)
+{
+    EndListening (rDocument);
+
+	MasterPageContainer::iterator aMasterPageDescriptor(maUsedMasterPages.find(&rDocument));
+	if(aMasterPageDescriptor != maUsedMasterPages.end())
+		maUsedMasterPages.erase(aMasterPageDescriptor);
+}
+
+
+
+    
+void MasterPageObserver::Implementation::AddEventListener (
+    const Link& rEventListener)
+{
+    if (::std::find (
+        maListeners.begin(),
+        maListeners.end(),
+        rEventListener) == maListeners.end())
+    {
+        maListeners.push_back (rEventListener);
+        
+        // Tell the new listener about all the master pages that are
+        // currently in use.
+        typedef ::std::vector<String> StringList;
+        StringList aNewMasterPages;
+        StringList aRemovedMasterPages;
+        MasterPageContainer::iterator aDocumentIterator;
+        for (aDocumentIterator=maUsedMasterPages.begin();
+             aDocumentIterator!=maUsedMasterPages.end();
+             ++aDocumentIterator)
+        {
+            ::std::set<String>::reverse_iterator aNameIterator;
+            for (aNameIterator=aDocumentIterator->second.rbegin();
+                 aNameIterator!=aDocumentIterator->second.rend();
+                 ++aNameIterator)
+            {
+			  MasterPageObserverEvent aEvent (
+				  MasterPageObserverEvent::ET_MASTER_PAGE_EXISTS,
+				  *aDocumentIterator->first,
+				  *aNameIterator);
+			  SendEvent (aEvent);
+            }
+        }
+    }
+}
+
+
+
+
+void MasterPageObserver::Implementation::RemoveEventListener (
+    const Link& rEventListener)
+{
+    maListeners.erase (
+        ::std::find (
+            maListeners.begin(),
+            maListeners.end(),
+            rEventListener));
+}
+
+
+
+
+MasterPageObserver::MasterPageNameSet 
+    MasterPageObserver::Implementation::GetMasterPageNames (
+        SdDrawDocument& rDocument)
+{
+    MasterPageContainer::iterator aMasterPageDescriptor (
+        maUsedMasterPages.find(&rDocument));
+    if (aMasterPageDescriptor != maUsedMasterPages.end())
+        return aMasterPageDescriptor->second;
+    else
+        // Not found so return an empty set.
+        return MasterPageObserver::MasterPageNameSet();
+}
+
+
+
+
+void MasterPageObserver::Implementation::Notify(
+    SfxBroadcaster& rBroadcaster,
+    const SfxHint& rHint)
+{
+    if (rHint.ISA(SdrHint))
+    {
+        SdrHint& rSdrHint (*PTR_CAST(SdrHint,&rHint));
+        switch (rSdrHint.GetKind())
+        {
+            case HINT_PAGEORDERCHG:
+                // Process the modified set of pages only when the number of
+                // standard and notes master pages are equal.  This test
+                // filters out events that are sent in between the insertion
+                // of a new standard master page and a new notes master
+                // page.
+                if (rBroadcaster.ISA(SdDrawDocument))
+                {
+                    SdDrawDocument& rDocument (
+                        static_cast<SdDrawDocument&>(rBroadcaster));
+                    if (rDocument.GetMasterSdPageCount(PK_STANDARD)
+                        == rDocument.GetMasterSdPageCount(PK_NOTES))
+                    {
+                        AnalyzeUsedMasterPages (rDocument);
+                    }
+                }
+                break;
+
+			default:
+				break;
+        }
+    }
+}
+
+
+
+
+void MasterPageObserver::Implementation::AnalyzeUsedMasterPages (
+    SdDrawDocument& rDocument)
+{
+    // Create a set of names of the master pages used by the given document.
+    sal_uInt16 nMasterPageCount = rDocument.GetMasterSdPageCount(PK_STANDARD);
+    ::std::set<String> aCurrentMasterPages;
+    for (sal_uInt16 nIndex=0; nIndex<nMasterPageCount; nIndex++)
+    {
+        SdPage* pMasterPage = rDocument.GetMasterSdPage (nIndex, PK_STANDARD);
+        if (pMasterPage != NULL)
+            aCurrentMasterPages.insert (pMasterPage->GetName());
+        OSL_TRACE("currently used master page %d is %s",
+            nIndex,
+            ::rtl::OUStringToOString(pMasterPage->GetName(),
+                RTL_TEXTENCODING_UTF8).getStr());
+    }
+
+    typedef ::std::vector<String> StringList;
+    StringList aNewMasterPages;
+    StringList aRemovedMasterPages;
+    MasterPageContainer::iterator aOldMasterPagesDescriptor (
+        maUsedMasterPages.find(&rDocument));
+    if (aOldMasterPagesDescriptor != maUsedMasterPages.end())
+    {
+        StringList::iterator I;
+
+        ::std::set<String>::iterator J;
+        int i=0;
+        for (J=aOldMasterPagesDescriptor->second.begin(); 
+             J!=aOldMasterPagesDescriptor->second.end(); 
+             ++J)
+            OSL_TRACE("old used master page %d is %s",
+            i++,
+            ::rtl::OUStringToOString(*J,
+                RTL_TEXTENCODING_UTF8).getStr());
+
+        // Send events about the newly used master pages.
+        ::std::set_difference (
+            aCurrentMasterPages.begin(),
+            aCurrentMasterPages.end(),
+            aOldMasterPagesDescriptor->second.begin(),
+            aOldMasterPagesDescriptor->second.end(),
+            ::std::back_insert_iterator<StringList>(aNewMasterPages));
+        for (I=aNewMasterPages.begin(); I!=aNewMasterPages.end(); ++I)
+        {
+            OSL_TRACE("    added master page %s",
+                ::rtl::OUStringToOString(*I,
+                    RTL_TEXTENCODING_UTF8).getStr());
+
+			MasterPageObserverEvent aEvent (
+				MasterPageObserverEvent::ET_MASTER_PAGE_ADDED, 
+				rDocument, 
+				*I);
+            SendEvent (aEvent);
+        }
+
+        // Send events about master pages that are not used any longer.
+        ::std::set_difference (
+            aOldMasterPagesDescriptor->second.begin(),
+            aOldMasterPagesDescriptor->second.end(),
+            aCurrentMasterPages.begin(),
+            aCurrentMasterPages.end(),
+            ::std::back_insert_iterator<StringList>(aRemovedMasterPages));
+        for (I=aRemovedMasterPages.begin(); I!=aRemovedMasterPages.end(); ++I)
+        {
+            OSL_TRACE("    removed master page %s",
+                ::rtl::OUStringToOString(*I,
+                    RTL_TEXTENCODING_UTF8).getStr());
+
+			MasterPageObserverEvent aEvent (
+				MasterPageObserverEvent::ET_MASTER_PAGE_REMOVED,
+				rDocument, 
+				*I);
+			SendEvent (aEvent);
+        }
+
+        // Store the new list of master pages.
+        aOldMasterPagesDescriptor->second = aCurrentMasterPages;
+    }
+}
+
+
+
+
+void MasterPageObserver::Implementation::SendEvent (
+    MasterPageObserverEvent& rEvent)
+{
+    ::std::vector<Link>::iterator aLink (maListeners.begin());
+    ::std::vector<Link>::iterator aEnd (maListeners.end());
+    while (aLink!=aEnd)
+    {
+        aLink->Call (&rEvent);
+        ++aLink;
+    }
+}
+
+
+} // end of namespace sd

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.cxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.cxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.cxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,870 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sd.hxx"
+
+#include "MasterPagesSelector.hxx"
+
+#include "MasterPageContainer.hxx"
+#include "DocumentHelper.hxx"
+#include "../SidebarShellManager.hxx"
+#include "pres.hxx"
+#include "drawdoc.hxx"
+#include "DrawDocShell.hxx"
+#include "sdpage.hxx"
+#include "glob.hxx"
+#include "glob.hrc"
+#include "app.hrc"
+#include "res_bmp.hrc"
+#include "strings.hrc"
+#include "DrawViewShell.hxx"
+#include "DrawController.hxx"
+#include "SlideSorterViewShell.hxx"
+#include "PreviewValueSet.hxx"
+#include "ViewShellBase.hxx"
+#include "controller/SlideSorterController.hxx"
+#include "controller/SlsPageSelector.hxx"
+#include <sfx2/objface.hxx>
+#include "sdresid.hxx"
+#include "TemplateScanner.hxx"
+#include "drawview.hxx"
+#include <vcl/image.hxx>
+#include <svl/languageoptions.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/dispatch.hxx>
+#include <sfx2/mnumgr.hxx>
+#include <svl/itemset.hxx>
+#include <svl/eitem.hxx>
+#include <svx/dlgutil.hxx>
+#include <svx/svdpagv.hxx>
+#include <svx/svxids.hrc>
+#include "FrameView.hxx"
+#include "sdpage.hxx"
+#include "stlpool.hxx"
+#include "unmovss.hxx"
+#include <sfx2/request.hxx>
+#include <svl/itempool.hxx>
+
+using namespace ::sd::sidebar;
+#define MasterPagesSelector
+#include "sdslots.hxx"
+
+using namespace ::com::sun::star::text;
+
+
+
+namespace sd { namespace sidebar {
+
+
+SFX_IMPL_INTERFACE(MasterPagesSelector, SfxShell, 
+    SdResId(STR_MASTERPAGESSELECTOR))
+{
+	SFX_POPUPMENU_REGISTRATION( SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP) );
+}
+
+TYPEINIT1(MasterPagesSelector, SfxShell);
+
+
+
+MasterPagesSelector::MasterPagesSelector (
+    ::Window* pParent,
+    SdDrawDocument& rDocument,
+    ViewShellBase& rBase,
+    SidebarShellManager& rShellManager,
+    const ::boost::shared_ptr<MasterPageContainer>& rpContainer)
+    : SfxShell(),
+      PreviewValueSet(pParent),
+      maMutex(),
+      mpContainer(rpContainer),
+      mrDocument(rDocument),
+      mrBase(rBase),
+      mnDefaultClickAction(SID_TP_APPLY_TO_ALL_SLIDES),
+      maPreviewUpdateQueue(),
+      maCurrentItemList(),
+      maTokenToValueSetIndex(),
+      maLockedMasterPages(),
+      mrShellManager(rShellManager),
+      mxSidebar()
+{
+	SetPool (&rDocument.GetPool());
+
+    PreviewValueSet::SetSelectHdl (
+        LINK(this, MasterPagesSelector, ClickHandler));
+	PreviewValueSet::SetRightMouseClickHandler (
+        LINK(this, MasterPagesSelector, RightClickHandler));
+	PreviewValueSet::SetContextMenuCallback (
+        LINK(this, MasterPagesSelector, ContextMenuCallback));
+    PreviewValueSet::SetStyle(PreviewValueSet::GetStyle() | WB_NO_DIRECTSELECT);
+    PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
+    PreviewValueSet::Show();
+
+    Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
+    mpContainer->AddChangeListener(aChangeListener);
+}
+
+
+
+
+MasterPagesSelector::~MasterPagesSelector (void)
+{
+    Clear();
+    UpdateLocks(ItemList());
+
+    if (GetShellManager() != NULL)
+        GetShellManager()->RemoveSubShell(this);
+
+    Link aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
+    mpContainer->RemoveChangeListener(aChangeListener);
+}
+
+
+
+
+void MasterPagesSelector::LateInit (void)
+{
+}
+
+
+
+
+sal_Int32 MasterPagesSelector::GetPreferredWidth (sal_Int32 nHeight)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    return PreviewValueSet::GetPreferredWidth (nHeight);
+}
+
+
+
+
+sal_Int32 MasterPagesSelector::GetPreferredHeight (sal_Int32 nWidth)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    return PreviewValueSet::GetPreferredHeight (nWidth);
+}
+
+
+
+
+Size MasterPagesSelector::GetPreferredSize (void)
+{
+    int nPreferredWidth = GetPreferredWidth(
+        PreviewValueSet::GetOutputSizePixel().Height());
+    int nPreferredHeight = GetPreferredHeight(nPreferredWidth);
+    return Size (nPreferredWidth, nPreferredHeight);
+
+}
+
+
+
+
+void MasterPagesSelector::UpdateLocks (const ItemList& rItemList)
+{
+    ItemList aNewLockList;
+    
+    // In here we first lock the master pages in the given list and then
+    // release the locks acquired in a previous call to this method.  When
+    // this were done the other way round the lock count of some master
+    // pages might drop temporarily to 0 and would lead to unnecessary
+    // deletion and re-creation of MasterPageDescriptor objects.
+
+    // Lock the master pages in the given list.
+    ItemList::const_iterator iItem;
+    for (iItem=rItemList.begin(); iItem!=rItemList.end(); ++iItem)
+    {
+        mpContainer->AcquireToken(*iItem);
+        aNewLockList.push_back(*iItem);
+    }
+
+    // Release the previously locked master pages.
+    ItemList::const_iterator iPage;
+    ItemList::const_iterator iEnd (maLockedMasterPages.end());
+    for (iPage=maLockedMasterPages.begin(); iPage!=iEnd; ++iPage)
+        mpContainer->ReleaseToken(*iPage);
+
+    maLockedMasterPages.swap(aNewLockList);
+}
+
+
+
+
+void MasterPagesSelector::Fill (void)
+{
+    ::std::auto_ptr<ItemList> pItemList (new ItemList());
+    
+    Fill(*pItemList);
+
+    UpdateLocks(*pItemList);
+    UpdateItemList(pItemList);
+}
+
+
+
+
+ResId MasterPagesSelector::GetContextMenuResId (void) const
+{
+    return SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP);
+}
+
+
+
+
+IMPL_LINK(MasterPagesSelector, ClickHandler, PreviewValueSet*, EMPTYARG)
+{
+    // We use the framework to assign the clicked-on master page because we
+    // so use the same mechanism as the context menu does (where we do not
+    // have the option to call the assignment method directly.)
+    if (GetShellManager() != NULL)
+        GetShellManager()->MoveToTop (this);
+
+    SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
+    if (pViewFrame != NULL)
+    {
+        SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
+        if (pDispatcher != NULL)
+            pDispatcher->Execute(mnDefaultClickAction);
+    }
+
+    return 0;
+}
+
+
+
+
+IMPL_LINK(MasterPagesSelector, RightClickHandler, MouseEvent*, pEvent)
+{
+    // Here we only prepare the display of the context menu: the item under
+    // the mouse is selected.  The actual display of the context menu is
+    // done in ContextMenuCallback which is called indirectly through
+    // PreviewValueSet::Command().
+    PreviewValueSet::GrabFocus ();
+    PreviewValueSet::ReleaseMouse();
+    if (GetDispatcher() != NULL &&  pEvent != NULL)
+    {
+        sal_uInt16 nIndex = PreviewValueSet::GetItemId (pEvent->GetPosPixel());
+        if (nIndex > 0)
+            PreviewValueSet::SelectItem (nIndex);
+    }
+    return 0;
+}
+
+
+
+
+IMPL_LINK(MasterPagesSelector, ContextMenuCallback, CommandEvent*, pEvent)
+{
+    // Use the currently selected item and show the popup menu in its
+    // center.
+    if (GetShellManager() != NULL)
+        GetShellManager()->MoveToTop (this);
+    const sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
+    if (nIndex > 0 && pEvent!=NULL)
+    {
+        // The position of the upper left corner of the context menu is
+        // taken either from the mouse position (when the command was sent
+        // as reaction to a right click) or in the center of the selected
+        // item (when the command was sent as reaction to Shift+F10.)
+        Point aPosition (pEvent->GetMousePosPixel());
+        if ( ! pEvent->IsMouseEvent())
+        {
+            Rectangle aBBox (PreviewValueSet::GetItemRect(nIndex));
+            aPosition = aBBox.Center();
+        }
+
+        const ResId aPopupResId (GetContextMenuResId());
+        mrBase.GetViewFrame()->GetDispatcher()->ExecutePopup(
+            aPopupResId,
+            this,
+            &aPosition);
+    }
+    
+    return 0;
+}
+
+
+
+
+IMPL_LINK(MasterPagesSelector, ContainerChangeListener, MasterPageContainerChangeEvent*, pEvent)
+{
+    if (pEvent)
+        NotifyContainerChangeEvent(*pEvent);
+    return 0;
+}
+
+
+
+
+SdPage* MasterPagesSelector::GetSelectedMasterPage (void)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    SdPage* pMasterPage = NULL;
+    sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
+    UserData* pData = GetUserData(nIndex);
+    if (pData != NULL)
+    {
+        pMasterPage = mpContainer->GetPageObjectForToken(pData->second);
+    }
+    return pMasterPage;
+}
+
+
+
+
+/** Assemble a list of all slides of the document and pass it to
+    AssignMasterPageToPageList().
+*/
+void MasterPagesSelector::AssignMasterPageToAllSlides (SdPage* pMasterPage)
+{
+    do
+    {
+        if (pMasterPage == NULL)
+            break;
+
+        sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
+        if (nPageCount == 0)
+            break;
+
+        // Get a list of all pages.  As a little optimization we only
+        // include pages that do not already have the given master page
+        // assigned.
+        String sFullLayoutName (pMasterPage->GetLayoutName());
+        ::sd::slidesorter::SharedPageSelection pPageList (
+            new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
+        for (sal_uInt16 nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
+        {
+            SdPage* pPage = mrDocument.GetSdPage (nPageIndex, PK_STANDARD);
+            if (pPage != NULL
+                && pPage->GetLayoutName().CompareTo(sFullLayoutName)!=0)
+            {
+                pPageList->push_back (pPage);
+            }
+        }
+
+        AssignMasterPageToPageList(pMasterPage, pPageList);
+    }
+    while (false);
+}
+
+
+
+
+/** Assemble a list of the currently selected slides (selected in a visible
+    slide sorter) and pass it to AssignMasterPageToPageList().
+*/
+void MasterPagesSelector::AssignMasterPageToSelectedSlides (
+    SdPage* pMasterPage)
+{
+    do
+    {
+        using namespace ::std;
+        using namespace ::sd::slidesorter;
+        using namespace ::sd::slidesorter::controller;
+
+        if (pMasterPage == NULL)
+            break;
+
+        // Find a visible slide sorter.
+        SlideSorterViewShell* pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
+        if (pSlideSorter == NULL)
+            break;
+
+        // Get a list of selected pages.
+        ::sd::slidesorter::SharedPageSelection pPageSelection = pSlideSorter->GetPageSelection();
+        if (pPageSelection->empty())
+            break;
+
+        AssignMasterPageToPageList(pMasterPage, pPageSelection);
+
+        // Restore the previous selection.
+        pSlideSorter->SetPageSelection(pPageSelection);
+    }
+    while (false);
+}
+
+
+
+
+void MasterPagesSelector::AssignMasterPageToPageList (
+    SdPage* pMasterPage,
+    const ::sd::slidesorter::SharedPageSelection& rPageList)
+{
+    DocumentHelper::AssignMasterPageToPageList(mrDocument, pMasterPage, rPageList);
+}
+
+
+
+
+void MasterPagesSelector::NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    switch (rEvent.meEventType)
+    {
+        case MasterPageContainerChangeEvent::SIZE_CHANGED:
+            PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
+            UpdateAllPreviews();
+            break;
+
+        case MasterPageContainerChangeEvent::PREVIEW_CHANGED:
+        {
+            int nIndex (GetIndexForToken(rEvent.maChildToken));
+            if (nIndex >= 0)
+            {
+                PreviewValueSet::SetItemImage (
+                    (sal_uInt16)nIndex,
+                    mpContainer->GetPreviewForToken(rEvent.maChildToken));
+                PreviewValueSet::Invalidate(PreviewValueSet::GetItemRect((sal_uInt16)nIndex));
+            }
+        }
+        break;
+
+        case MasterPageContainerChangeEvent::DATA_CHANGED:
+        {
+            InvalidateItem(rEvent.maChildToken);
+            Fill();
+        }
+        break;
+
+		default:
+			break;
+   }
+}
+
+
+
+
+MasterPagesSelector::UserData* MasterPagesSelector::CreateUserData (
+    int nIndex,
+    MasterPageContainer::Token aToken) const
+{
+    return new UserData(nIndex,aToken);
+}
+
+
+
+
+MasterPagesSelector::UserData* MasterPagesSelector::GetUserData (int nIndex) const
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    if (nIndex>0 && nIndex<=PreviewValueSet::GetItemCount())
+        return reinterpret_cast<UserData*>(PreviewValueSet::GetItemData((sal_uInt16)nIndex));
+    else
+        return NULL;
+}
+
+
+
+
+void MasterPagesSelector::SetUserData (int nIndex, UserData* pData)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    if (nIndex>0 && nIndex<=PreviewValueSet::GetItemCount())
+    {
+        UserData* pOldData = GetUserData(nIndex);
+        if (pOldData!=NULL && pOldData!=pData)
+            delete pOldData;
+        PreviewValueSet::SetItemData((sal_uInt16)nIndex, pData);
+    }
+}
+
+
+
+
+bool MasterPagesSelector::IsResizable (void)
+{
+    return false;
+}
+
+
+
+
+::Window* MasterPagesSelector::GetWindow (void)
+{
+    return this;
+}
+
+
+
+
+sal_Int32 MasterPagesSelector::GetMinimumWidth (void)
+{
+    return mpContainer->GetPreviewSizePixel().Width() + 2*3;
+}
+
+
+
+
+void MasterPagesSelector::UpdateSelection (void)
+{
+}
+
+
+
+
+void MasterPagesSelector::Execute (SfxRequest& rRequest)
+{
+	switch (rRequest.GetSlot())
+    {
+        case SID_TP_APPLY_TO_ALL_SLIDES:
+            mrBase.SetBusyState (true);
+            AssignMasterPageToAllSlides (GetSelectedMasterPage());
+            mrBase.SetBusyState (false);
+            break;
+
+        case SID_TP_APPLY_TO_SELECTED_SLIDES:
+            mrBase.SetBusyState (true);
+            AssignMasterPageToSelectedSlides (GetSelectedMasterPage());
+            mrBase.SetBusyState (false);
+            break;
+
+        case SID_TP_USE_FOR_NEW_PRESENTATIONS:
+            DBG_ASSERT (false, 
+                "Using slides as default for new presentations"
+                " is not yet implemented");
+            break;
+
+        case SID_TP_SHOW_SMALL_PREVIEW:
+        case SID_TP_SHOW_LARGE_PREVIEW:
+        {
+            mrBase.SetBusyState (true);
+            mpContainer->SetPreviewSize(
+                rRequest.GetSlot()==SID_TP_SHOW_SMALL_PREVIEW
+                ? MasterPageContainer::SMALL
+                : MasterPageContainer::LARGE);
+            mrBase.SetBusyState (false);
+            break;
+        }
+
+        case SID_TP_EDIT_MASTER:
+        {
+            using namespace ::com::sun::star;
+            uno::Reference<drawing::XDrawPage> xSelectedMaster (
+                GetSelectedMasterPage()->getUnoPage(), uno::UNO_QUERY);
+            SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
+            if (pViewFrame != NULL && xSelectedMaster.is())
+            {
+                SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
+                if (pDispatcher != NULL)
+                {
+                    sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
+                    pDispatcher->Execute(SID_MASTERPAGE, SFX_CALLMODE_SYNCHRON);
+                    PreviewValueSet::SelectItem (nIndex);
+                    mrBase.GetDrawController().setCurrentPage(xSelectedMaster);
+                }
+            }
+            break;
+        }
+
+        case SID_CUT:
+        case SID_COPY:
+        case SID_PASTE:
+            // Cut, copy, and paste are not supported and thus are ignored.
+            break;
+    }
+}
+
+
+
+
+void MasterPagesSelector::GetState (SfxItemSet& rItemSet)
+{
+    if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL)
+        rItemSet.DisableItem (SID_TP_SHOW_SMALL_PREVIEW);
+    else
+        rItemSet.DisableItem (SID_TP_SHOW_LARGE_PREVIEW);
+
+    // Cut and paste is not supported so do not show the menu entries.
+    rItemSet.DisableItem (SID_CUT);
+    rItemSet.DisableItem (SID_COPY);
+    rItemSet.DisableItem (SID_PASTE);
+}
+
+
+
+
+void MasterPagesSelector::SetItem (
+    sal_uInt16 nIndex,
+    MasterPageContainer::Token aToken)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    RemoveTokenToIndexEntry(nIndex,aToken);
+
+    if (nIndex > 0)
+    {
+        if (aToken != MasterPageContainer::NIL_TOKEN)
+        {
+            Image aPreview (mpContainer->GetPreviewForToken(aToken));
+            MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
+
+            if (aPreview.GetSizePixel().Width()>0)
+            {
+                if (PreviewValueSet::GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
+                {
+                    PreviewValueSet::SetItemImage(nIndex,aPreview);
+                    PreviewValueSet::SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
+                }
+                else
+                {
+                    PreviewValueSet::InsertItem (
+                        nIndex,
+                        aPreview,
+                        mpContainer->GetPageNameForToken(aToken),
+                        nIndex);
+                }
+                SetUserData(nIndex, CreateUserData(nIndex,aToken));
+
+                AddTokenToIndexEntry(nIndex,aToken);
+            }
+
+            if (eState == MasterPageContainer::PS_CREATABLE)
+                mpContainer->RequestPreview(aToken);
+        }
+        else
+        {
+            PreviewValueSet::RemoveItem(nIndex);
+        }
+    }
+  
+}
+
+
+
+
+void MasterPagesSelector::AddTokenToIndexEntry (
+    sal_uInt16 nIndex,
+    MasterPageContainer::Token aToken)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    maTokenToValueSetIndex[aToken] = nIndex;
+}
+
+
+
+
+void MasterPagesSelector::RemoveTokenToIndexEntry (
+    sal_uInt16 nIndex,
+    MasterPageContainer::Token aNewToken)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    UserData* pData = GetUserData(nIndex);
+    if (pData != NULL)
+    {
+        // Get the token that the index pointed to previously.
+        MasterPageContainer::Token aOldToken (pData->second);
+
+        if (aNewToken != aOldToken
+            && nIndex == GetIndexForToken(aOldToken))
+        {
+            maTokenToValueSetIndex[aOldToken] = 0;
+        }
+    }
+}
+
+
+
+
+void MasterPagesSelector::InvalidatePreview (const SdPage* pPage)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
+    {
+        UserData* pData = GetUserData(nIndex);
+        if (pData != NULL)
+        {
+            MasterPageContainer::Token aToken (pData->second);
+            if (pPage == mpContainer->GetPageObjectForToken(aToken,false))
+            {
+                mpContainer->InvalidatePreview(aToken);
+                mpContainer->RequestPreview(aToken);
+                break;
+            }
+        }
+    }
+}
+
+void MasterPagesSelector::UpdateAllPreviews (void)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+    
+    for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
+    {
+        UserData* pData = GetUserData(nIndex);
+        if (pData != NULL)
+        {
+            MasterPageContainer::Token aToken (pData->second);
+            PreviewValueSet::SetItemImage(
+                nIndex,
+                mpContainer->GetPreviewForToken(aToken));
+            if (mpContainer->GetPreviewState(aToken) == MasterPageContainer::PS_CREATABLE)
+                mpContainer->RequestPreview(aToken);
+        }
+    }
+    PreviewValueSet::Rearrange(true);
+}
+
+
+
+
+void MasterPagesSelector::ClearPageSet (void)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    for (sal_uInt16 nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
+    {
+        UserData* pData = GetUserData(nIndex);
+        if (pData != NULL)
+            delete pData;
+    }
+    PreviewValueSet::Clear();
+}
+
+
+
+
+void MasterPagesSelector::SetHelpId( const rtl::OString& aId )
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+	PreviewValueSet::SetHelpId( aId );
+}
+
+
+
+
+sal_Int32 MasterPagesSelector::GetIndexForToken (MasterPageContainer::Token aToken) const
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    TokenToValueSetIndex::const_iterator iIndex (maTokenToValueSetIndex.find(aToken));
+    if (iIndex != maTokenToValueSetIndex.end())
+        return iIndex->second;
+    else
+        return -1;
+}
+
+
+
+
+void MasterPagesSelector::Clear (void)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    ClearPageSet();
+}
+
+
+
+
+void MasterPagesSelector::InvalidateItem (MasterPageContainer::Token aToken)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    ItemList::iterator iItem;
+    for (iItem=maCurrentItemList.begin(); iItem!=maCurrentItemList.end(); ++iItem)
+    {
+        if (*iItem == aToken)
+        {
+            *iItem = MasterPageContainer::NIL_TOKEN;
+            break;
+        }
+    }
+}
+
+
+
+
+void MasterPagesSelector::UpdateItemList (::std::auto_ptr<ItemList> pNewItemList)
+{
+    const ::osl::MutexGuard aGuard (maMutex);
+
+    ItemList::const_iterator iNewItem (pNewItemList->begin());
+    ItemList::const_iterator iCurrentItem (maCurrentItemList.begin());
+    ItemList::const_iterator iNewEnd (pNewItemList->end());
+    ItemList::const_iterator iCurrentEnd (maCurrentItemList.end());
+    sal_uInt16 nIndex (1);
+
+    // Update existing items.
+    for ( ; iNewItem!=iNewEnd && iCurrentItem!=iCurrentEnd; ++iNewItem, ++iCurrentItem,++nIndex)
+    {
+        if (*iNewItem != *iCurrentItem)
+        {
+            SetItem(nIndex,*iNewItem);
+        }
+    }
+    
+    // Append new items.
+    for ( ; iNewItem!=iNewEnd; ++iNewItem,++nIndex)
+    {
+        SetItem(nIndex,*iNewItem);
+    }
+    
+    // Remove trailing items.
+    for ( ; iCurrentItem!=iCurrentEnd; ++iCurrentItem,++nIndex)
+    {
+        SetItem(nIndex,MasterPageContainer::NIL_TOKEN);
+    }
+
+    maCurrentItemList.swap(*pNewItemList);
+    
+    PreviewValueSet::Rearrange();
+    if (mxSidebar.is())
+        mxSidebar->requestLayout();
+}
+
+
+
+
+SidebarShellManager* MasterPagesSelector::GetShellManager (void)
+{
+    return &mrShellManager;
+}
+
+
+
+
+void MasterPagesSelector::SetSidebar (const cssu::Reference<css::ui::XSidebar>& rxSidebar)
+{
+    mxSidebar = rxSidebar;
+    if (mxSidebar.is())
+        mxSidebar->requestLayout();
+}
+
+
+
+
+css::ui::LayoutSize MasterPagesSelector::GetHeightForWidth (const sal_Int32 nWidth)
+{
+    const sal_Int32 nHeight (GetPreferredHeight(nWidth));
+    return css::ui::LayoutSize(nHeight,nHeight,nHeight);
+}
+
+} } // end of namespace sd::sidebar

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.hxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.hxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/MasterPagesSelector.hxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,251 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX
+#define SD_SIDEBAR_PANELS_MASTER_PAGES_SELECTOR_HXX
+
+#include "MasterPageContainer.hxx"
+#include "SlideSorterViewShell.hxx"
+#include "PreviewValueSet.hxx"
+#include "../ISidebarReceiver.hxx"
+#include "../ILayoutableWindow.hxx"
+
+#include "pres.hxx"
+#include <sfx2/shell.hxx>
+#include <vcl/image.hxx>
+#include "glob.hxx"
+#include <osl/mutex.hxx>
+#include <com/sun/star/ui/XSidebar.hpp>
+
+#include <queue>
+
+namespace css = ::com::sun::star;
+namespace cssu = ::com::sun::star::uno;
+
+class MouseEvent;
+class SdDrawDocument;
+class SdPage;
+class SfxModule;
+
+namespace sd { 
+class DrawViewShell;
+class TemplateEntry;
+class TemplateDir;
+class ViewShellBase;
+}
+
+namespace sd { namespace sidebar {
+
+class PreviewValueSet;
+class SidebarShellManager;
+
+
+/** Base class of a menu that lets the user select from a list of
+    templates or designs that are loaded from files.
+*/
+class MasterPagesSelector
+    : public SfxShell,
+      public PreviewValueSet,
+      public ISidebarReceiver,
+      public ILayoutableWindow
+{
+public:
+    TYPEINFO();
+    SFX_DECL_INTERFACE(SD_IF_SDMASTERPAGESSELECTOR)
+
+    MasterPagesSelector (
+        ::Window* pParent,
+        SdDrawDocument& rDocument,
+        ViewShellBase& rBase,
+        SidebarShellManager& rShellManager,
+        const ::boost::shared_ptr<MasterPageContainer>& rpContainer);
+    virtual ~MasterPagesSelector (void);
+
+    virtual void LateInit (void);
+
+    /** Return the height that this control needs to show all of its lines.
+    */
+    long GetRequiredHeight (int nWidth) const;
+
+    /** The given master page, either the master page of a slide or a notes
+        page, is cloned and inserted into mrDocument.  The necessary styles
+        are copied as well.
+    */
+    static SdPage* AddMasterPage (
+        SdDrawDocument* pTargetDocument,
+        SdPage* pMasterPage,
+        sal_uInt16 nInsertionIndex);
+
+    virtual Size GetPreferredSize (void);
+    virtual sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
+    virtual sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
+    virtual bool IsResizable (void);
+    virtual ::Window* GetWindow (void);
+    virtual sal_Int32 GetMinimumWidth (void);
+
+    virtual void Execute (SfxRequest& rRequest);
+    virtual void GetState (SfxItemSet& rItemSet);
+
+    /** Update the selection of previews according to whatever
+        influences them appart from mouse and keyboard.  If, for
+        example, the current page of the main pane changes, then call
+        this method at the CurrentMasterPagesSelector to select the
+        previews of the master pages that are assigned to the new
+        current page.
+
+        The default implementation of this method ignores the call. This is
+        used by e.g. the RecentMasterPagesSelector because it does not show
+        the currently used master pages by default and thus is not
+        influenced by its changes.
+    */
+    virtual void UpdateSelection (void);
+
+    void FillPageSet (void);
+
+    /** Make the selector empty.  This method clear the value set from any
+        entries. Overload this method to add functionality, especially to
+        destroy objects set as data items at the value set.
+    */
+    void ClearPageSet (void);
+
+    using SfxShell::SetHelpId;
+	void SetHelpId( const rtl::OString& aId );
+
+    /** Mark the preview that belongs to the given index as not up-to-date
+        anymore with respect to page content or preview size.
+        The implementation of this method will either sunchronously or
+        asynchronously call UpdatePreview().
+        @param nIndex
+            Index into the value set control that is used for displaying the
+            previews.
+    */
+    void InvalidatePreview (const SdPage* pPage);
+
+    void UpdateAllPreviews (void);
+
+    // ISidebarReceiver
+    virtual void SetSidebar (const cssu::Reference<css::ui::XSidebar>& rxSidebar);
+
+    // ILayoutableWindow
+    virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth);
+
+protected:
+    mutable ::osl::Mutex maMutex;
+    ::boost::shared_ptr<MasterPageContainer> mpContainer;
+
+    SdDrawDocument& mrDocument;
+    bool mbSmallPreviewSize;
+    ViewShellBase& mrBase;
+    /** Slot that is executed as default action when the left mouse button is
+        clicked over a master page.
+    */
+	sal_uInt16 mnDefaultClickAction;
+    /** Pages with pointers in this queue have their previews updated
+        eventually.  Filled by InvalidatePreview() and operated upon by
+        UpdatePreviews(). 
+    */
+    ::std::queue<sal_uInt16> maPreviewUpdateQueue;
+
+    virtual SdPage* GetSelectedMasterPage (void);
+
+    /** Assign the given master page to all slides of the document.
+        @param pMasterPage
+            The master page to assign to all slides.
+    */
+    void AssignMasterPageToAllSlides (SdPage* pMasterPage);
+
+    /** Assign the given master page to all slides that are selected in a
+        slide sorter that is displayed in the lef or center pane.  When both
+        panes display a slide sorter then the one in the center pane is
+        used.
+    */
+    void AssignMasterPageToSelectedSlides (SdPage* pMasterPage);
+
+    virtual void AssignMasterPageToPageList (
+        SdPage* pMasterPage,
+        const ::sd::slidesorter::SharedPageSelection& rPageList);
+
+    virtual void NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent);
+
+    typedef ::std::pair<int, MasterPageContainer::Token> UserData;
+    UserData* CreateUserData (int nIndex, MasterPageContainer::Token aToken) const;
+    UserData* GetUserData (int nIndex) const;
+    void SetUserData (int nIndex, UserData* pData);
+
+    virtual sal_Int32 GetIndexForToken (MasterPageContainer::Token aToken) const;
+    typedef ::std::vector<MasterPageContainer::Token> ItemList;
+    void UpdateItemList (::std::auto_ptr<ItemList> pList);
+    void Clear (void);
+    /** Invalidate the specified item so that on the next Fill() this item
+        is updated.
+    */
+    void InvalidateItem (MasterPageContainer::Token aToken);
+
+    // For every item in the ValueSet we store its associated token.  This
+    // allows a faster access and easier change tracking.
+    ItemList maCurrentItemList;
+    typedef ::std::map<MasterPageContainer::Token,sal_Int32> TokenToValueSetIndex;
+    TokenToValueSetIndex maTokenToValueSetIndex;
+
+    ItemList maLockedMasterPages;
+    /** Lock master pages in the given list and release locks that where
+        previously aquired.
+    */
+    void UpdateLocks (const ItemList& rItemList);
+
+    void Fill (void);
+    virtual void Fill (ItemList& rItemList) = 0;
+
+    /** Give derived classes the oportunity to provide their own context
+        menu.  If they do then they probably have to provide their own
+        Execute() and GetState() methods as well.
+    */
+    virtual ResId GetContextMenuResId (void) const;
+
+    SidebarShellManager* GetShellManager (void);
+
+private:
+    SidebarShellManager& mrShellManager;
+    cssu::Reference<css::ui::XSidebar> mxSidebar;
+
+    /** The offset between ValueSet index and MasterPageContainer::Token
+        last seen.  This value is used heuristically to speed up the lookup
+        of an index for a token.
+    */
+    DECL_LINK(ClickHandler, PreviewValueSet*);
+    DECL_LINK(RightClickHandler, MouseEvent*);
+    DECL_LINK(ContextMenuCallback, CommandEvent*);
+    DECL_LINK(ContainerChangeListener, MasterPageContainerChangeEvent*);
+    
+    void SetItem (
+        sal_uInt16 nIndex,
+        MasterPageContainer::Token aToken);
+    void AddTokenToIndexEntry (
+        sal_uInt16 nIndex,
+        MasterPageContainer::Token aToken);
+    void RemoveTokenToIndexEntry (
+        sal_uInt16 nIndex,
+        MasterPageContainer::Token aToken);
+};
+
+} } // end of namespace sd::sidebar
+
+#endif

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.cxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.cxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.cxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,130 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#include "precompiled_sd.hxx"
+
+#include "TableDesignPanel.hxx"
+
+
+
+namespace sd { namespace sidebar {
+
+
+PanelBase::PanelBase (
+    ::Window* pParentWindow,
+    ViewShellBase& rViewShellBase)
+    : Control(pParentWindow),
+      mpWrappedControl(NULL),
+      mxSidebar(),
+      mrViewShellBase(rViewShellBase)
+{
+    OSL_TRACE("created PanelBase at %x for parent %x", this, pParentWindow);
+
+#ifdef DEBUG
+    SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sd:PanelBase")));
+#endif
+}
+
+
+
+
+PanelBase::~PanelBase (void)
+{
+    OSL_TRACE("deleting wrapped control at %x", mpWrappedControl.get());
+    mpWrappedControl.reset();
+    OSL_TRACE("deleting PanelBase at %x from parent %x", this, GetParent());
+}
+
+
+
+
+
+void PanelBase::Dispose (void)
+{
+    OSL_TRACE("PanelBase::DisposeL: deleting wrapped control at %x", mpWrappedControl.get());
+    mpWrappedControl.reset();
+}
+
+
+
+
+css::ui::LayoutSize PanelBase::GetHeightForWidth (const sal_Int32 nWidth)
+{
+    sal_Int32 nHeight (0);
+    if (ProvideWrappedControl())
+        nHeight = mpWrappedControl->GetSizePixel().Height();
+    return css::ui::LayoutSize(nHeight,nHeight,nHeight);
+}
+
+
+
+
+void PanelBase::Resize (void)
+{
+    if (ProvideWrappedControl())
+    {
+        Size aNewSize (GetSizePixel());
+        mpWrappedControl->SetOutputSizePixel(aNewSize);
+    }
+}
+
+
+
+
+::com::sun::star::uno::Reference<
+    ::com::sun::star::accessibility::XAccessible> PanelBase::CreateAccessibleObject (
+        const ::com::sun::star::uno::Reference<
+        ::com::sun::star::accessibility::XAccessible>& )
+{
+    if (ProvideWrappedControl())
+        return mpWrappedControl->GetAccessible();
+    else
+        return NULL;
+}
+
+
+
+
+void PanelBase::SetSidebar (const cssu::Reference<css::ui::XSidebar>& rxSidebar)
+{
+    mxSidebar = rxSidebar;
+    if (mxSidebar.is() && mpWrappedControl!=NULL)
+        mxSidebar->requestLayout();
+}
+
+
+
+
+bool PanelBase::ProvideWrappedControl (void)
+{
+    if ( ! mpWrappedControl)
+    {
+        mpWrappedControl.reset(CreateWrappedControl(this, mrViewShellBase));
+        OSL_TRACE("created wrapped control at %x for parent PanelBase at %x", mpWrappedControl.get(), this);
+        if (mpWrappedControl)
+            mpWrappedControl->Show();
+        if (mxSidebar.is())
+            mxSidebar->requestLayout();
+    }
+    return mpWrappedControl.get() != NULL;
+}
+
+} } // end of namespace sd::sidebar

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.hxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.hxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PanelBase.hxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,90 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef SD_SIDEBAR_PANELS_PANEL_BASE_HXX
+#define SD_SIDEBAR_PANELS_PANEL_BASE_HXX
+
+#include "../IDisposable.hxx"
+#include "../ILayoutableWindow.hxx"
+#include "../ISidebarReceiver.hxx"
+
+#include <vcl/ctrl.hxx>
+
+#include <boost/scoped_ptr.hpp>
+
+
+namespace css = ::com::sun::star;
+namespace cssu = ::com::sun::star::uno;
+
+namespace sd {
+    class ViewShellBase;
+}
+
+
+
+
+namespace sd { namespace sidebar {
+
+
+class PanelBase
+    : public Control,
+      public ILayoutableWindow,
+      public IDisposable,
+      public ISidebarReceiver
+{
+public:
+    PanelBase (
+        ::Window* pParentWindow,
+        ViewShellBase& rViewShellBase);
+    virtual ~PanelBase (void);
+
+    virtual void Resize (void);
+
+    // IDisposable
+    virtual void Dispose (void);
+    
+    // ILayoutableWindow
+    virtual css::ui::LayoutSize GetHeightForWidth (const sal_Int32 nWidth);
+
+    // ISidebarReceiver
+    virtual void SetSidebar (const cssu::Reference<css::ui::XSidebar>& rxSidebar);
+
+    virtual ::com::sun::star::uno::Reference<
+        ::com::sun::star::accessibility::XAccessible > CreateAccessibleObject (
+            const ::com::sun::star::uno::Reference<
+            ::com::sun::star::accessibility::XAccessible>& rxParent);
+
+protected:
+    ::boost::scoped_ptr< ::Window> mpWrappedControl;
+    virtual ::Window* CreateWrappedControl (
+        ::Window* pParentWindow,
+        ViewShellBase& rViewShellBase) = 0;
+
+private:
+    cssu::Reference<css::ui::XSidebar> mxSidebar;
+    ViewShellBase& mrViewShellBase;
+
+    bool ProvideWrappedControl (void);
+};
+
+} } // end of namespace sd::sidebar
+
+#endif

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.cxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.cxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.cxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.cxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,233 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#include "precompiled_sd.hxx"
+
+#include "PreviewValueSet.hxx"
+#include <vcl/image.hxx>
+
+namespace sd { namespace sidebar {
+
+
+PreviewValueSet::PreviewValueSet (::Window* pParent)
+    : ValueSet (pParent, WB_TABSTOP),
+      maPreviewSize(10,10),
+      mnBorderWidth(3),
+      mnBorderHeight(3),
+      mnMaxColumnCount(-1)
+{
+	SetStyle (
+        GetStyle() 
+        & ~(WB_ITEMBORDER)// | WB_MENUSTYLEVALUESET)
+        //        | WB_FLATVALUESET);
+        );
+
+	SetColCount(2);
+    //	SetLineCount(1);
+	SetExtraSpacing (2);
+}
+
+
+
+
+PreviewValueSet::~PreviewValueSet (void)
+{
+}
+
+
+
+
+void PreviewValueSet::SetPreviewSize (const Size& rSize)
+{
+    maPreviewSize = rSize;
+}
+
+
+
+
+void PreviewValueSet::SetRightMouseClickHandler (const Link& rLink)
+{
+    maRightMouseClickHandler = rLink;
+}
+
+
+
+
+void PreviewValueSet::MouseButtonDown (const MouseEvent& rEvent)
+{
+    if (rEvent.IsRight())
+        maRightMouseClickHandler.Call(reinterpret_cast<void*>(
+            &const_cast<MouseEvent&>(rEvent)));
+    else
+        ValueSet::MouseButtonDown (rEvent);
+
+}
+
+
+
+
+void PreviewValueSet::Paint (const Rectangle& rRect)
+{
+    SetBackground (GetSettings().GetStyleSettings().GetWindowColor());
+
+    ValueSet::Paint (rRect);
+
+    SetBackground (Wallpaper());
+}
+
+
+
+
+void PreviewValueSet::Resize (void)
+{
+    ValueSet::Resize ();
+
+    Size aWindowSize (GetOutputSizePixel());
+    if (aWindowSize.Width()>0 && aWindowSize.Height()>0)
+    {
+        Rearrange();
+    }
+}
+
+
+
+
+void PreviewValueSet::Command (const CommandEvent& rEvent)
+{
+    switch (rEvent.GetCommand())
+    {
+        case COMMAND_CONTEXTMENU:
+        {
+            CommandEvent aNonConstEventCopy (rEvent);
+            maContextMenuCallback.Call(&aNonConstEventCopy);
+        }
+        break;
+            
+        default:
+            ValueSet::Command(rEvent);
+            break;
+    }
+}
+
+
+
+
+void PreviewValueSet::Rearrange (bool bForceRequestResize)
+{
+    sal_uInt16 nOldColumnCount (GetColCount());
+    sal_uInt16 nOldRowCount (GetLineCount());
+
+    sal_uInt16 nNewColumnCount (CalculateColumnCount (
+        GetOutputSizePixel().Width()));
+    sal_uInt16 nNewRowCount (CalculateRowCount (nNewColumnCount));
+
+    SetColCount(nNewColumnCount);
+    SetLineCount(nNewRowCount);
+
+    if (bForceRequestResize
+        || nOldColumnCount != nNewColumnCount
+        || nOldRowCount != nNewRowCount)
+    {
+        //SIDEBAR:TODO:   mpParent->RequestResize();
+    }
+}
+
+
+
+
+void PreviewValueSet::SetContextMenuCallback (const Link& rLink)
+{
+    maContextMenuCallback = rLink;
+}
+
+
+
+
+sal_uInt16 PreviewValueSet::CalculateColumnCount (int nWidth) const
+{
+    int nColumnCount = 0;
+    if (nWidth > 0)
+    {
+        nColumnCount = nWidth / (maPreviewSize.Width() + 2*mnBorderWidth);
+        if (nColumnCount < 1)
+            nColumnCount = 1;
+        else if (mnMaxColumnCount>0 && nColumnCount>mnMaxColumnCount)
+            nColumnCount = mnMaxColumnCount;
+    }
+    return (sal_uInt16)nColumnCount;
+}
+
+
+
+
+sal_uInt16 PreviewValueSet::CalculateRowCount (sal_uInt16 nColumnCount) const
+{
+    int nRowCount = 0;
+    int nItemCount = GetItemCount();
+    if (nColumnCount > 0)
+    {
+        nRowCount = (nItemCount+nColumnCount-1) / nColumnCount;
+        if (nRowCount < 1)
+            nRowCount = 1;
+    }
+
+    return (sal_uInt16)nRowCount;
+}
+
+
+
+
+sal_Int32 PreviewValueSet::GetPreferredWidth (sal_Int32 nHeight)
+{
+    int nPreferredWidth (maPreviewSize.Width() + 2*mnBorderWidth);
+
+    // Get height of each row.
+    int nItemHeight (maPreviewSize.Height() + 2*mnBorderHeight);
+
+    // Calculate the row- and column count and from the later the preferred
+    // width.
+    int nRowCount = nHeight / nItemHeight;
+    if (nRowCount > 0)
+    {
+        int nColumnCount = (GetItemCount()+nRowCount-1) / nRowCount;
+        if (nColumnCount > 0)
+            nPreferredWidth = (maPreviewSize.Width() + 2*mnBorderWidth) 
+                * nColumnCount;
+    }
+
+    return nPreferredWidth;
+}
+
+
+
+
+sal_Int32 PreviewValueSet::GetPreferredHeight (sal_Int32 nWidth)
+{
+    int nRowCount (CalculateRowCount(CalculateColumnCount(nWidth)));
+    int nItemHeight (maPreviewSize.Height());
+    
+    return nRowCount * (nItemHeight + 2*mnBorderHeight);
+}
+
+
+
+
+} } // end of namespace sd::sidebar

Added: openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.hxx
URL: http://svn.apache.org/viewvc/openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.hxx?rev=1447641&view=auto
==============================================================================
--- openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.hxx (added)
+++ openoffice/branches/sidebar/main/sd/source/ui/sidebar/panels/PreviewValueSet.hxx Tue Feb 19 09:09:02 2013
@@ -0,0 +1,85 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+#ifndef SD_SIDEBAR_PANELS_PREVIEW_VALUE_SET_HXX
+#define SD_SIDEBAR_PANELS_PREVIEW_VALUE_SET_HXX
+
+#include <svtools/valueset.hxx>
+
+
+namespace sd { namespace sidebar {
+
+
+/** Adapt the svtools valueset to the needs of the master page controlls.
+*/
+class PreviewValueSet
+    : public ValueSet
+{
+public:
+    PreviewValueSet (::Window* pParent);
+    ~PreviewValueSet (void);
+
+	void SetRightMouseClickHandler (const Link& rLink);
+	virtual void Paint (const Rectangle& rRect);
+    virtual void Resize (void);
+    
+    /** When a request for the display of a context menu is made to this
+        method then that request is forwarded via the ContextMenuCallback.
+        This way the owning class can handle the context menu without having
+        to be derived from this class.
+        Use SetContextMenuCallback to set or rest the handler.
+    */
+	virtual void Command (const CommandEvent& rEvent);
+
+    void SetPreviewSize (const Size& rSize);
+
+    sal_Int32 GetPreferredWidth (sal_Int32 nHeight);
+    sal_Int32 GetPreferredHeight (sal_Int32 nWidth);
+
+    /** Set the number of rows and columns according to the current number
+        of items.  Call this method when new items have been inserted.
+    */
+    void Rearrange (bool bForceRequestResize = false);
+
+    /** Set the callback function to which requests for context menus are
+        forewarded.  Call with an empty Link to reset the callback
+        function.
+    */
+    void SetContextMenuCallback (const Link& rLink);
+
+protected:
+    virtual void MouseButtonDown (const MouseEvent& rEvent);
+
+private:
+    Link maRightMouseClickHandler;
+    Link maContextMenuCallback;
+    Size maPreviewSize;
+    const int mnBorderWidth;
+    const int mnBorderHeight;
+    const int mnMaxColumnCount;
+    
+    sal_uInt16 CalculateColumnCount (int nWidth) const;
+    sal_uInt16 CalculateRowCount (sal_uInt16 nColumnCount) const;
+};
+
+} } // end of namespace sd::sidebar
+
+#endif