LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/inc/model - SlideSorterModel.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 3 4 75.0 %
Date: 2015-06-13 12:38:46 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_MODEL_SLIDESORTERMODEL_HXX
      21             : #define INCLUDED_SD_SOURCE_UI_SLIDESORTER_INC_MODEL_SLIDESORTERMODEL_HXX
      22             : 
      23             : class SdDrawDocument;
      24             : 
      25             : #include "model/SlsPageEnumeration.hxx"
      26             : #include "model/SlsSharedPageDescriptor.hxx"
      27             : 
      28             : #include "pres.hxx"
      29             : #include <com/sun/star/drawing/XDrawPage.hpp>
      30             : #include <osl/mutex.hxx>
      31             : #include <vcl/region.hxx>
      32             : 
      33             : #include <vector>
      34             : #include <functional>
      35             : 
      36             : class SdrPage;
      37             : class SdPage;
      38             : 
      39             : namespace sd { namespace slidesorter {
      40             : class SlideSorter;
      41             : } }
      42             : 
      43             : namespace sd { namespace slidesorter { namespace model {
      44             : 
      45          10 : inline sal_Int32 FromCoreIndex (const sal_uInt16 nCoreIndex) { return (nCoreIndex-1)/2; }
      46             : inline sal_uInt16 ToCoreIndex (const sal_Int32 nIndex) { return static_cast<sal_uInt16>(nIndex*2+1); }
      47             : 
      48             : /** The model of the slide sorter gives access to the slides that are to be
      49             :     displayed in the slide sorter view.  Via the SetDocumentSlides() method
      50             :     this set of slides can be modified (but do not call it directly, use
      51             :     SlideSorterController::SetDocumentSlides() instead.)
      52             : */
      53             : class SlideSorterModel
      54             : {
      55             : public:
      56             :     SlideSorterModel (SlideSorter& rSlideSorter);
      57             : 
      58             :     virtual ~SlideSorterModel();
      59             :     void Dispose();
      60             : 
      61             :     /** This method is present to let the view create a ShowView for
      62             :         displaying slides.
      63             :     */
      64             :     SdDrawDocument* GetDocument();
      65             : 
      66             :     /** Set a new edit mode and return whether the edit mode really
      67             :         has been changed.  When the edit mode is changed then the
      68             :         previous page descriptor list is replaced by a new one which
      69             :         has to be repainted.
      70             :         @return
      71             :             A return value of <TRUE/> indicates that the edit mode has
      72             :             changed and thus the page descriptor list has been set up
      73             :             to reflect that change.  A repaint is necessary.
      74             :     */
      75             :     bool SetEditMode (EditMode eEditMode);
      76             : 
      77             :     /** Set the edit mode to that currently used by the controller.
      78             :     */
      79             :     bool SetEditModeFromController();
      80           8 :     EditMode GetEditMode() const { return meEditMode;}
      81           0 :     PageKind GetPageType() const { return mePageKind;}
      82             : 
      83             :     /** Return the number of slides in the document regardless of whether
      84             :         they are visible or not or whether they are hidden or not.
      85             :         The number of slides depends on the set of slides available through
      86             :         the XIndexAccess given to SetDocumentSlides().
      87             :     */
      88             :     sal_Int32 GetPageCount() const;
      89             : 
      90             :     /** Return a page descriptor for the page with the specified index.
      91             :         Page descriptors are created on demand.  The page descriptor is
      92             :         found (or not found) in constant time.
      93             :         @param nPageIndex
      94             :             The index of the requested slide.  The valid values
      95             :             are 0 to GetPageCount()-1.
      96             :         @param bCreate
      97             :             When <TRUE/> and the requested page descriptor is missing then
      98             :             it is created.  When <FALSE/> then an empty reference is
      99             :             returned for missing descriptors.
     100             :         @return
     101             :             When the given index is not valid, i.e. lower then zero or
     102             :             larger than or equal to the number of pages then an empty
     103             :             reference is returned. Note that the page count may change
     104             :             between calls to GetPageCount() and GetPageDescriptor().
     105             :     */
     106             :     SharedPageDescriptor GetPageDescriptor (
     107             :         const sal_Int32 nPageIndex,
     108             :         const bool bCreate = true) const;
     109             : 
     110             :     /** Return a page descriptor for the given XDrawPage.  Page descriptors
     111             :         are created on demand.  The page descriptor is found (or not found)
     112             :         in (at most) linear time.  Note that all page descriptors in front of
     113             :         the one associated with the given XDrawPage are created when not yet
     114             :         present. When the XDrawPage is not found then all descriptors are
     115             :         created.
     116             :         @return
     117             :             Returns the index to the requested page descriptor or -1 when
     118             :             there is no such page descriptor.
     119             :     */
     120             :     sal_Int32 GetIndex (
     121             :         const ::com::sun::star::uno::Reference<com::sun::star::drawing::XDrawPage>& rxSlide) const;
     122             : 
     123             :     /** Return a page descriptor for the given SdrPage.  Page descriptors
     124             :         are created on demand.  The page descriptor is found (or not found)
     125             :         in (at most) linear time.  Note that all page descriptors in front of
     126             :         the one associated with the given XDrawPage are created when not yet
     127             :         present. When the SdrPage is not found then all descriptors are
     128             :         created.
     129             :         @return
     130             :             Returns the index to the requested page descriptor or -1 when
     131             :             there is no such page descriptor.
     132             :     */
     133             :     sal_Int32 GetIndex (const SdrPage* pPage) const;
     134             : 
     135             :     /** Return an index for accessing an SdrModel that corresponds to the
     136             :         given SlideSorterModel index.  In many cases we just have to apply
     137             :         the n*2+1 magic.  Only when a special model is set, like a custom
     138             :         slide show, then the returned value is different.
     139             :     */
     140             :     sal_uInt16 GetCoreIndex (const sal_Int32 nIndex) const;
     141             : 
     142             :     /** Call this method after the document has changed its structure.  This
     143             :         will get the model in sync with the SdDrawDocument.  This method
     144             :         tries not to throw away to much information already gathered.  This
     145             :         is especially important for previews of complex pages that take some
     146             :         time to create.
     147             :     */
     148             :     void Resync();
     149             : 
     150             :     /** Delete all descriptors that currently are in the container.  The size
     151             :         of the container, however, is not altered.  Use the AdaptSize
     152             :         method for that.
     153             :     */
     154             :     void ClearDescriptorList();
     155             : 
     156             :     /** Set the selection of the document to exactly that of the called model.
     157             :     */
     158             :     void SynchronizeDocumentSelection();
     159             : 
     160             :     /** Set the selection of the called model to exactly that of the document.
     161             :     */
     162             :     void SynchronizeModelSelection();
     163             : 
     164             :     /** Return the mutex so that the caller can lock it and then safely
     165             :         access the model.
     166             :     */
     167         152 :     ::osl::Mutex& GetMutex() { return maMutex;}
     168             : 
     169             :     /** Set the XIndexAccess from which the called SlideSorterModel takes
     170             :         its pages.
     171             :         @param rxSlides
     172             :             The set of slides accessible through this XIndexAccess are not
     173             :             necessarily the same as the ones of the XModel of the
     174             :             XController (although it typically is a subset).
     175             :     */
     176             :     void SetDocumentSlides (const css::uno::Reference<css::container::XIndexAccess>& rxSlides);
     177             : 
     178             :     /** Return the set of pages that is currently displayed by the slide sorter.
     179             :     */
     180             :     css::uno::Reference<css::container::XIndexAccess> GetDocumentSlides() const;
     181             : 
     182             :     /** This method is called when the edit mode has changed.  It calls
     183             :         SetDocumentSlides() with the set of slides or master pages obtained
     184             :         from the model of the XController.
     185             :     */
     186             :     void UpdatePageList();
     187             : 
     188             :     bool IsReadOnly() const;
     189             : 
     190             :     /** The current selection is saved by copying the ST_Selected state into
     191             :         ST_WasSelected for slides.
     192             :     */
     193             :     void SaveCurrentSelection();
     194             : 
     195             :     /** The current selection is restored from the ST_WasSelected state from
     196             :         the slides.
     197             :         @returns
     198             :             The returned region has to be repainted to reflect the updated
     199             :             selection states.
     200             :     */
     201             :     vcl::Region RestoreSelection();
     202             : 
     203             :     /** Typically called from controller::Listener this method handles the
     204             :         insertion and deletion of single pages.
     205             :         @return
     206             :             Returns <TRUE/> when the given page is relevant for the current
     207             :             page kind and edit mode.
     208             :     */
     209             :     bool NotifyPageEvent (const SdrPage* pPage);
     210             : 
     211             : private:
     212             :     mutable ::osl::Mutex maMutex;
     213             :     SlideSorter& mrSlideSorter;
     214             :     ::com::sun::star::uno::Reference<com::sun::star::container::XIndexAccess> mxSlides;
     215             :     PageKind mePageKind;
     216             :     EditMode meEditMode;
     217             :     typedef ::std::vector<SharedPageDescriptor> DescriptorContainer;
     218             :     mutable DescriptorContainer maPageDescriptors;
     219             : 
     220             :     /** Resize the descriptor container according to current values of
     221             :         page kind and edit mode.
     222             :     */
     223             :     void AdaptSize();
     224             : 
     225             :     SdPage* GetPage (const sal_Int32 nCoreIndex) const;
     226             :     void InsertSlide (SdPage* pPage);
     227             :     void DeleteSlide (const SdPage* pPage);
     228             :     void UpdateIndices (const sal_Int32 nFirstIndex);
     229             : };
     230             : 
     231             : } } } // end of namespace ::sd::slidesorter::model
     232             : 
     233             : #endif
     234             : 
     235             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11