[Libreoffice-commits] core.git: 4 commits - android/experimental desktop/source sd/source

Tomaž Vajngerl tomaz.vajngerl at collabora.com
Wed Aug 13 00:29:19 PDT 2014


 android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java        |   10 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java                 |   25 ++-
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java             |   10 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java       |   38 ++--
 android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java |   12 +
 android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java        |    7 
 android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java            |    2 
 desktop/source/lib/init.cxx                                                           |   39 ++---
 sd/source/ui/inc/unomodel.hxx                                                         |    4 
 sd/source/ui/unoidl/unomodel.cxx                                                      |   78 ++++++----
 sd/source/ui/view/drviewsa.cxx                                                        |   17 +-
 11 files changed, 159 insertions(+), 83 deletions(-)

New commits:
commit c5581d19c6c5d857c4117e72cb022dcfc9561409
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Wed Aug 13 09:21:21 2014 +0200

    android: Add logic to change document parts from sidebar
    
    Add click listener for list elements (parts) in "drawer layout"
    side bar, add new LOEvent - change parts, propagate the change event
    up to TileProvider, call setPart on LOK facade, clean all tiles and
    redraw.
    
    Change-Id: I711e0fb5e7e867cef87f97b96f1292d7c6801083

diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java
index 436e37e..e014e13 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java
@@ -2,13 +2,19 @@ package org.libreoffice;
 
 
 public class DocumentPartView {
-    private String partName;
+    private final int partIndex;
+    private final String partName;
 
-    public DocumentPartView(String partName) {
+    public DocumentPartView(int partIndex, String partName) {
+        this.partIndex = partIndex;
         this.partName = partName;
     }
 
     public String getPartName() {
         return partName;
     }
+
+    public int getPartIndex() {
+        return partIndex;
+    }
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
index 2814730..746ceb5 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOEvent.java
@@ -11,17 +11,16 @@ public class LOEvent {
     public static final int TILE_SIZE = 2;
     public static final int VIEWPORT = 3;
     public static final int DRAW = 4;
-
-    private ViewportMetrics mViewportMetrics;
-
+    public static final int CHANGE_PART = 5;
     public int mType;
-    private String mTypeString;
-
     ViewportMetrics viewportMetrics;
+    private ViewportMetrics mViewportMetrics;
+    private String mTypeString;
+    private int mPartIndex;
 
     public LOEvent(int type, int widthPixels, int heightPixels, int tileWidth, int tileHeight) {
         mType = type;
-        mTypeString = "Size Changed: " + widthPixels + " "+ heightPixels;
+        mTypeString = "Size Changed: " + widthPixels + " " + heightPixels;
     }
 
     public LOEvent(int type, IntSize tileSize) {
@@ -40,6 +39,12 @@ public class LOEvent {
         mTypeString = "Draw";
     }
 
+    public LOEvent(int type, int partIndex) {
+        mType = type;
+        mPartIndex = partIndex;
+        mTypeString = "Change part";
+    }
+
     public static LOEvent draw(Rect rect) {
         return new LOEvent(DRAW, rect);
     }
@@ -56,6 +61,10 @@ public class LOEvent {
         return new LOEvent(VIEWPORT, viewportMetrics);
     }
 
+    public static LOEvent changePart(int part) {
+        return new LOEvent(CHANGE_PART, part);
+    }
+
     public String getTypeString() {
         return mTypeString;
     }
@@ -63,4 +72,8 @@ public class LOEvent {
     public ViewportMetrics getViewport() {
         return mViewportMetrics;
     }
+
+    public int getPartIndex() {
+        return mPartIndex;
+    }
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
index d56f451..a831a55 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitThread.java
@@ -115,6 +115,13 @@ public class LOKitThread extends Thread {
         return true;
     }
 
+    private void changePart(int partIndex) throws InterruptedException {
+        mTileProvider.changePart(partIndex);
+        GeckoLayerClient layerClient = mApplication.getLayerClient();
+        layerClient.getTiles().clear();
+        LOKitShell.sendEvent(LOEvent.draw(new Rect()));
+    }
+
     private boolean initialize() {
         mApplication = LibreOfficeMainActivity.mAppContext;
         mTileProvider = new LOKitTileProvider(mApplication.getLayerController(), mInputFile);
@@ -144,6 +151,9 @@ public class LOKitThread extends Thread {
                 break;
             case LOEvent.SIZE_CHANGED:
                 break;
+            case LOEvent.CHANGE_PART:
+                changePart(event.getPartIndex());
+                break;
         }
     }
 
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 4758b70..8085d02 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -15,27 +15,14 @@ import java.nio.ByteBuffer;
 
 public class LOKitTileProvider implements TileProvider {
     private static final String LOGTAG = LOKitTileProvider.class.getSimpleName();
-
-    private final LayerController mLayerController;
-
     public static int TILE_SIZE = 256;
-    private final double mTileWidth;
-    private final double mTileHeight;
-
-
     public final Office mOffice;
     public final Document mDocument;
-
+    private final LayerController mLayerController;
+    private final double mTileWidth;
+    private final double mTileHeight;
     private double mDPI;
 
-    private double twipToPixel(double input, double dpi) {
-        return input / 1440.0 * dpi;
-    }
-
-    private double pixelToTwip(double input, double dpi) {
-        return (input / dpi) * 1440.0;
-    }
-
     public LOKitTileProvider(LayerController layerController, String input) {
         mLayerController = layerController;
         mDPI = (double) LOKitShell.getDpi();
@@ -61,7 +48,7 @@ public class LOKitTileProvider implements TileProvider {
                     partName = "Part " + (i + 1);
                 }
                 Log.i(LOGTAG, "Document part " + i + " name:'" + partName + "'");
-                final DocumentPartView partView = new DocumentPartView(partName);
+                final DocumentPartView partView = new DocumentPartView(i, partName);
                 LibreOfficeMainActivity.mAppContext.getDocumentPartView().add(partView);
             }
 
@@ -74,8 +61,16 @@ public class LOKitTileProvider implements TileProvider {
         }
     }
 
+    private double twipToPixel(double input, double dpi) {
+        return input / 1440.0 * dpi;
+    }
+
+    private double pixelToTwip(double input, double dpi) {
+        return (input / dpi) * 1440.0;
+    }
+
     private boolean checkDocument() {
-        if(mDocument == null || !mOffice.getError().isEmpty()) {
+        if (mDocument == null || !mOffice.getError().isEmpty()) {
             Log.e(LOGTAG, "Error at loading: " + mOffice.getError());
             return false;
         }
@@ -108,7 +103,7 @@ public class LOKitTileProvider implements TileProvider {
         ByteBuffer buffer = ByteBuffer.allocateDirect(TILE_SIZE * TILE_SIZE * 4);
         Bitmap bitmap = Bitmap.createBitmap(TILE_SIZE, TILE_SIZE, Bitmap.Config.ARGB_8888);
 
-        mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE, (int) pixelToTwip(x, mDPI), (int) pixelToTwip(y, mDPI), (int)mTileWidth, (int)mTileHeight);
+        mDocument.paintTile(buffer, TILE_SIZE, TILE_SIZE, (int) pixelToTwip(x, mDPI), (int) pixelToTwip(y, mDPI), (int) mTileWidth, (int) mTileHeight);
 
         bitmap.copyPixelsFromBuffer(buffer);
 
@@ -117,4 +112,9 @@ public class LOKitTileProvider implements TileProvider {
         tile.beginTransaction();
         return tile;
     }
+
+    @Override
+    public void changePart(int partIndex) {
+        mDocument.setPart(partIndex);
+    }
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
index c50fba4..20c2cf3 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -8,6 +8,8 @@ import android.util.DisplayMetrics;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuItem;
+import android.view.View;
+import android.widget.AdapterView;
 import android.widget.ListView;
 import android.widget.RelativeLayout;
 
@@ -104,6 +106,7 @@ public class LibreOfficeMainActivity extends Activity {
 
         mDocumentPartViewListAdpater = new DocumentPartViewListAdpater(this, R.layout.document_part_list_layout, mDocumentPartView);
         mDrawerList.setAdapter(mDocumentPartViewListAdpater);
+        mDrawerList.setOnItemClickListener(new DocumentPartClickListener());
 
         if (mLayerController == null) {
             mLayerController = new LayerController(this);
@@ -122,6 +125,15 @@ public class LibreOfficeMainActivity extends Activity {
         Log.w(LOGTAG, "UI almost up");
     }
 
+    private class DocumentPartClickListener implements android.widget.AdapterView.OnItemClickListener {
+        @Override
+        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+            DocumentPartView partView = mDocumentPartViewListAdpater.getItem(position);
+            LOKitShell.sendEvent(LOEvent.changePart(partView.getPartIndex()));
+            mDrawerLayout.closeDrawer(mDrawerList);
+        }
+    }
+
     @Override
     protected void onResume() {
         super.onResume();
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
index e7ced82..8de60d6 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java
@@ -18,7 +18,7 @@ public class MockTileProvider implements TileProvider {
 
         for (int i = 0; i < 5; i++) {
             String partName = "Part " + i;
-            DocumentPartView partView = new DocumentPartView(partName);
+            DocumentPartView partView = new DocumentPartView(i, partName);
             LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().add(partView);
         }
         LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() {
@@ -60,4 +60,9 @@ public class MockTileProvider implements TileProvider {
 
         return tile;
     }
+
+    @Override
+    public void changePart(int partIndex) {
+
+    }
 }
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
index 6743e0c..63e358d 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/TileProvider.java
@@ -10,4 +10,6 @@ public interface TileProvider {
     boolean isReady();
 
     SubTile createTile(int x, int y);
+
+    void changePart(int partIndex);
 }
commit 3b9e7f49efc84d474151f6818a77de635efd3a47
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Wed Aug 13 09:13:09 2014 +0200

    Ignore exception when service ScannerManager is unavailable
    
    Exception from an unavailable service ScannerManager propagated to
    the top. This caused that presentations in android crashed
    (DrawViewShell wasn't initialized).
    
    Change-Id: I485d0cdad05e4d2d6096042e5762c0350a8339a9

diff --git a/sd/source/ui/view/drviewsa.cxx b/sd/source/ui/view/drviewsa.cxx
index 627dfda..9779ed2 100644
--- a/sd/source/ui/view/drviewsa.cxx
+++ b/sd/source/ui/view/drviewsa.cxx
@@ -362,11 +362,20 @@ void DrawViewShell::Construct(DrawDocShell* pDocSh, PageKind eInitialPageKind)
 
     uno::Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
 
-    mxScannerManager = scanner::ScannerManager::create( xContext );
+    try
+    {
+        mxScannerManager = scanner::ScannerManager::create( xContext );
 
-    mxScannerListener = uno::Reference< lang::XEventListener >(
-                        static_cast< ::cppu::OWeakObject* >( new ScannerEventListener( this ) ),
-                        uno::UNO_QUERY );
+        mxScannerListener = uno::Reference< lang::XEventListener >(
+                            static_cast< ::cppu::OWeakObject* >( new ScannerEventListener( this ) ),
+                            uno::UNO_QUERY );
+    }
+    catch (Exception& exception)
+    {
+        // Eat the exception and log it
+        // We can still continue if scanner manager is not available.
+        SAL_WARN("sd", "Scanner manager exception: " << exception.Message);
+    }
 
     mpAnnotationManager.reset( new AnnotationManager( GetViewShellBase() ) );
     mpViewOverlayManager.reset( new ViewOverlayManager( GetViewShellBase() ) );
commit 8da923dfa6663197aab6f53ac03b97a3ab8fab40
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Wed Aug 13 09:10:08 2014 +0200

    reduce code duplication in LOK init.cxx
    
    Change-Id: I65335a2d0fb6e1ff46e3302463fbcf396fbea215

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 53e49e3..60c53fb 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -59,6 +59,7 @@
 #endif
 
 using namespace css;
+using namespace vcl;
 using namespace utl;
 
 using namespace boost;
@@ -265,6 +266,17 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit
     }
 };
 
+namespace
+{
+
+ITiledRenderable* getTiledRenderable(LibreOfficeKitDocument* pThis)
+{
+    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
+    return dynamic_cast<ITiledRenderable*>(pDocument->mxComponent.get());
+}
+
+} // anonymous namespace
+
 // Wonder global state ...
 static uno::Reference<css::uno::XComponentContext> xContext;
 static uno::Reference<css::lang::XMultiServiceFactory> xSFactory;
@@ -431,9 +443,7 @@ static LibreOfficeKitDocumentType doc_getDocumentType (LibreOfficeKitDocument* p
 
 static int doc_getParts (LibreOfficeKitDocument* pThis)
 {
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
-    ::vcl::ITiledRenderable* pDoc = dynamic_cast< ::vcl::ITiledRenderable* >( pDocument->mxComponent.get() );
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
     {
         gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
@@ -445,9 +455,7 @@ static int doc_getParts (LibreOfficeKitDocument* pThis)
 
 static int doc_getPart (LibreOfficeKitDocument* pThis)
 {
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
-    ::vcl::ITiledRenderable* pDoc = dynamic_cast< ::vcl::ITiledRenderable* >( pDocument->mxComponent.get() );
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
     {
         gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
@@ -459,9 +467,7 @@ static int doc_getPart (LibreOfficeKitDocument* pThis)
 
 static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
 {
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
-    ::vcl::ITiledRenderable* pDoc = dynamic_cast< ::vcl::ITiledRenderable* >( pDocument->mxComponent.get() );
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
     {
         gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
@@ -474,9 +480,7 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
 
 static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
 {
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
-    ::vcl::ITiledRenderable* pDoc = dynamic_cast< ::vcl::ITiledRenderable* >( pDocument->mxComponent.get() );
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
     {
         gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
@@ -494,9 +498,7 @@ static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart)
 static void doc_setPartMode(LibreOfficeKitDocument* pThis,
                             LibreOfficeKitPartMode ePartMode)
 {
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
-    ::vcl::ITiledRenderable* pDoc = dynamic_cast< ::vcl::ITiledRenderable* >( pDocument->mxComponent.get() );
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
     {
         gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
@@ -538,9 +540,8 @@ void doc_paintTile (LibreOfficeKitDocument* pThis,
     SAL_INFO( "lok.tiledrendering", "paintTile: painting [" << nTileWidth << "x" << nTileHeight <<
               "]@(" << nTilePosX << ", " << nTilePosY << ") to [" <<
               nCanvasWidth << "x" << nCanvasHeight << "]px" );
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
 
-    ::vcl::ITiledRenderable* pDoc = dynamic_cast< ::vcl::ITiledRenderable* >( pDocument->mxComponent.get() );
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (!pDoc)
     {
         gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
@@ -583,9 +584,7 @@ static void doc_getDocumentSize(LibreOfficeKitDocument* pThis,
                                 long* pWidth,
                                 long* pHeight)
 {
-    LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
-
-    ::vcl::ITiledRenderable* pDoc = dynamic_cast< ::vcl::ITiledRenderable* >( pDocument->mxComponent.get() );
+    ITiledRenderable* pDoc = getTiledRenderable(pThis);
     if (pDoc)
     {
         Size aDocumentSize = pDoc->getDocumentSize();
commit 8a1ad93aa41e1749eb6f1eedf1f25015d15f41e7
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.com>
Date:   Wed Aug 13 09:08:59 2014 +0200

    reduce code duplication
    
    Change-Id: Ie5910239d7a54a29262e556af779bda9fa2dddca

diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index e620ca5..c7bf63b 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -56,6 +56,7 @@ class SdPage;
 
 namespace sd {
 class DrawDocShell;
+class DrawViewShell;
 }
 
 extern OUString getPageApiName( SdPage* pPage );
@@ -123,6 +124,9 @@ private:
     OUString   maBuildId;
 
     void initializeDocument();
+
+    sd::DrawViewShell* GetViewShell();
+
 public:
     SdXImpressDocument( ::sd::DrawDocShell* pShell, bool bClipBoard = false ) throw();
     SdXImpressDocument( SdDrawDocument* pDoc, bool bClipBoard = false ) throw();
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 79146e9..83da209 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2188,11 +2188,26 @@ void SAL_CALL SdXImpressDocument::render( sal_Int32 nRenderer, const uno::Any& r
     }
 }
 
+DrawViewShell* SdXImpressDocument::GetViewShell()
+{
+    DrawViewShell* pViewSh = dynamic_cast<DrawViewShell*>(mpDocShell->GetViewShell());
+    if (!pViewSh)
+    {
+        SAL_WARN("sd", "DrawViewShell not available!");
+        return NULL;
+    }
+    return pViewSh;
+}
+
 void SdXImpressDocument::paintTile( VirtualDevice& rDevice,
                             int nOutputWidth, int nOutputHeight,
                             int nTilePosX, int nTilePosY,
                             long nTileWidth, long nTileHeight )
 {
+    DrawViewShell* pViewSh = GetViewShell();
+    if (!pViewSh)
+        return;
+
     // Scaling. Must convert from pixels to twips. We know
     // that VirtualDevices use a DPI of 96.
     // We specifically calculate these scales first as we're still
@@ -2221,26 +2236,27 @@ void SdXImpressDocument::paintTile( VirtualDevice& rDevice,
     rDevice.SetMapMode( aMapMode );
 
     rDevice.SetOutputSizePixel( Size(nOutputWidth, nOutputHeight) );
-    mpDoc->GetDocSh()->GetViewShell()->GetView()->CompleteRedraw(
-        &rDevice,
-        Region(
-            Rectangle( Point( nTilePosX, nTilePosY ),
-                       Size( nTileWidth, nTileHeight ) ) ) );
+
+    Point aPoint(nTilePosX, nTilePosY);
+    Size aSize(nTileWidth, nTileHeight);
+    Rectangle aRect(aPoint, aSize);
+
+    pViewSh->GetView()->CompleteRedraw(&rDevice, Region(aRect));
 }
 
 void SdXImpressDocument::setPart( int nPart )
 {
-    DrawViewShell* pViewSh = dynamic_cast< DrawViewShell* >( mpDoc->GetDocSh()->GetViewShell() );
-    if (pViewSh)
-    {
-        // TODO: have an API to allow selecting between PK_STANDARD (just slide)
-        // and PK_NOTES (which shows the combined slide above notes). There is alo
-        // a PK_HANDOUT -- that however just shows multiple empty pages (it's also
-        // only possible to select page 0 in this mode, I have no idea how you
-        // then actually select what is on the handout page, which defaults to
-        // a 4x4 grid of empty pages).
-        pViewSh->SwitchPage( nPart );
-    }
+    DrawViewShell* pViewSh = GetViewShell();
+    if (!pViewSh)
+        return;
+
+    // TODO: have an API to allow selecting between PK_STANDARD (just slide)
+    // and PK_NOTES (which shows the combined slide above notes). There is alo
+    // a PK_HANDOUT -- that however just shows multiple empty pages (it's also
+    // only possible to select page 0 in this mode, I have no idea how you
+    // then actually select what is on the handout page, which defaults to
+    // a 4x4 grid of empty pages).
+    pViewSh->SwitchPage( nPart );
 }
 
 int SdXImpressDocument::getParts()
@@ -2252,29 +2268,31 @@ int SdXImpressDocument::getParts()
 
 int SdXImpressDocument::getPart()
 {
-    DrawViewShell* pViewSh = dynamic_cast< DrawViewShell* >( mpDoc->GetDocSh()->GetViewShell() );
-    if (pViewSh)
-    {
-        // curPageId seems to start at 1
-        return pViewSh->GetCurPageId() - 1;
-    }
-    return 0;
+    DrawViewShell* pViewSh = GetViewShell();
+    if (!pViewSh)
+        return 0;
+
+    // curPageId seems to start at 1
+    return pViewSh->GetCurPageId() - 1;
 }
 
 OUString SdXImpressDocument::getPartName( int nPart )
 {
     SdPage* pPage = mpDoc->GetSdPage( nPart, PK_STANDARD );
-    assert( pPage );
+    if (!pPage)
+    {
+        SAL_WARN("sd", "DrawViewShell not available!");
+        return OUString();
+    }
+
     return pPage->GetName();
 }
 
 void SdXImpressDocument::setPartMode( LibreOfficeKitPartMode ePartMode )
 {
-    DrawViewShell* pViewSh = dynamic_cast< DrawViewShell* >( mpDoc->GetDocSh()->GetViewShell() );
+    DrawViewShell* pViewSh = GetViewShell();
     if (!pViewSh)
-    {
         return;
-    }
 
     PageKind aPageKind( PK_STANDARD );
     switch ( ePartMode )
@@ -2303,14 +2321,12 @@ void SdXImpressDocument::setPartMode( LibreOfficeKitPartMode ePartMode )
 
 Size SdXImpressDocument::getDocumentSize()
 {
-    DrawViewShell* pViewSh = dynamic_cast<DrawViewShell*>(mpDoc->GetDocSh()->GetViewShell());
+    DrawViewShell* pViewSh = GetViewShell();
     if (!pViewSh)
-    {
-        SAL_WARN("sd", "DrawViewShell not available!");
         return Size();
-    }
 
     SdrPageView* pCurPageView = pViewSh->GetView()->GetSdrPageView();
+
     Size aSize = pCurPageView->GetPageRect().GetSize();
     // Convert the size in 100th mm to TWIP
     // See paintTile above for further info.


More information about the Libreoffice-commits mailing list