[Libreoffice-commits] core.git: 15 commits - desktop/source include/LibreOfficeKit include/vcl libreofficekit/qa libreofficekit/source sd/source sw/inc sw/source

Andrzej Hunt andrzej.hunt at collabora.com
Wed Jul 30 03:44:55 PDT 2014


 desktop/source/lib/init.cxx                         |   62 +++++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.h             |   23 ++++-
 include/LibreOfficeKit/LibreOfficeKit.hxx           |    5 +
 include/LibreOfficeKit/LibreOfficeKitGtk.h          |    5 +
 include/vcl/ITiledRenderable.hxx                    |   32 +++++++-
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |   80 +++++++++++++++++---
 libreofficekit/source/gtk/lokdocview.c              |   10 ++
 sd/source/ui/inc/unomodel.hxx                       |    2 
 sd/source/ui/unoidl/unomodel.cxx                    |   45 ++++++++++-
 sw/inc/unotxdoc.hxx                                 |    3 
 sw/source/uibase/uno/unotxdoc.cxx                   |   15 ---
 11 files changed, 242 insertions(+), 40 deletions(-)

New commits:
commit 77d083130948fa35f9f404656b8c170060e78043
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Wed Jul 30 07:33:54 2014 +0200

    LokDocView: Update part selector when mode changes.
    
    Change-Id: Ice754a46d07ce2714257c30e1aef27193b614cd3

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index c588993..9a40325 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -27,6 +27,7 @@ static int help()
 static GtkWidget* pDocView;
 static GtkWidget* pDocViewQuad;
 static GtkWidget* pVBox;
+static GtkComboBoxText* pPartSelector;
 static LibreOfficeKit* pOffice;
 static char* pFileName;
 
@@ -121,20 +122,29 @@ void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
 
 // GtkComboBox requires gtk 2.24 or later
 #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
-void populatePartSelector( GtkComboBoxText* pSelector, LOKDocView* pView )
+void populatePartSelector()
 {
+    gtk_list_store_clear( GTK_LIST_STORE(
+                              gtk_combo_box_get_model(
+                                  GTK_COMBO_BOX(pPartSelector) )) );
+
+    if ( !pDocView )
+    {
+        return;
+    }
+
     const int nMaxLength = 50;
     char sText[nMaxLength];
 
-    int nParts = lok_docview_get_parts(pView);
+    int nParts = lok_docview_get_parts( LOK_DOCVIEW(pDocView) );
     for ( int i = 0; i < nParts; i++ )
     {
-        char* pName = lok_docview_get_part_name( pView, i );
+        char* pName = lok_docview_get_part_name( LOK_DOCVIEW(pDocView), i );
         assert( pName );
         snprintf( sText, nMaxLength, "%i (%s)", i+1, pName );
         free( pName );
 
-        gtk_combo_box_text_append_text( pSelector, sText );
+        gtk_combo_box_text_append_text( pPartSelector, sText );
     }
     gtk_combo_box_set_active( GTK_COMBO_BOX(pPartSelector),
                               lok_docview_get_part( LOK_DOCVIEW(pDocView) ) );
@@ -174,6 +184,10 @@ void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
     {
         lok_docview_set_partmode( LOK_DOCVIEW(pDocView), ePartMode );
     }
+
+    // The number of items could change e.g. if we change from slide
+    // to embeddede obj mode -- hence we should update the part list.
+    populatePartSelector();
 }
 #endif
 
@@ -232,6 +246,8 @@ int main( int argc, char* argv[] )
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartSelectorToolItem, -1 );
     g_signal_connect( G_OBJECT(pComboBox), "changed", G_CALLBACK(changePart), NULL );
 
+    pPartSelector = GTK_COMBO_BOX_TEXT(pComboBox);
+
     GtkToolItem* pSeparator2 = gtk_separator_tool_item_new();
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator2, -1);
 
@@ -265,7 +281,7 @@ int main( int argc, char* argv[] )
 
     // GtkComboBox requires gtk 2.24 or later
 #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
-    populatePartSelector( GTK_COMBO_BOX_TEXT(pComboBox), LOK_DOCVIEW(pDocView) );
+    populatePartSelector();
     populatePartModeSelector( GTK_COMBO_BOX_TEXT(pPartModeComboBox) );
 #endif
 
commit df438e6ea260c1367fac0c2f195f1aff6311709f
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Wed Jul 30 07:33:35 2014 +0200

    LokDocView: set current item for part selector.
    
    Change-Id: Idbb3d63803bd60a182a9b8e26620d11b2d643cb6

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index a96e1e3..c588993 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -136,7 +136,8 @@ void populatePartSelector( GtkComboBoxText* pSelector, LOKDocView* pView )
 
         gtk_combo_box_text_append_text( pSelector, sText );
     }
-    gtk_combo_box_set_active( GTK_COMBO_BOX(pSelector), 0 );
+    gtk_combo_box_set_active( GTK_COMBO_BOX(pPartSelector),
+                              lok_docview_get_part( LOK_DOCVIEW(pDocView) ) );
 }
 
 void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
commit ba520b9dbb911d32dd770f4548399b98dd80bd2c
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 17:01:48 2014 +0200

    gtktiledviewer: add part mode selector.
    
    Change-Id: Ia1e78df1d833f9b0fbda0b78136590c9c960fa27

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index d74eb96..a96e1e3 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -151,6 +151,29 @@ void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
         lok_docview_set_part( LOK_DOCVIEW(pDocView), nPart );
     }
 }
+
+void populatePartModeSelector( GtkComboBoxText* pSelector )
+{
+    gtk_combo_box_text_append_text( pSelector, "Default" );
+    gtk_combo_box_text_append_text( pSelector, "Slide" );
+    gtk_combo_box_text_append_text( pSelector, "Notes" );
+    gtk_combo_box_text_append_text( pSelector, "Combined (SlideNotes)" );
+    gtk_combo_box_text_append_text( pSelector, "Embedded Objects" );
+    gtk_combo_box_set_active( GTK_COMBO_BOX(pSelector), 0 );
+}
+
+void changePartMode( GtkWidget* pSelector, gpointer /* pItem */ )
+{
+    // Just convert directly back to the LibreOfficeKitPartMode enum.
+    // I.e. the ordering above should match the enum member ordering.
+    LibreOfficeKitPartMode ePartMode =
+        LibreOfficeKitPartMode( gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ) );
+
+    if ( pDocView )
+    {
+        lok_docview_set_partmode( LOK_DOCVIEW(pDocView), ePartMode );
+    }
+}
 #endif
 
 int main( int argc, char* argv[] )
@@ -207,11 +230,20 @@ int main( int argc, char* argv[] )
     gtk_container_add( GTK_CONTAINER(pPartSelectorToolItem), pComboBox );
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartSelectorToolItem, -1 );
     g_signal_connect( G_OBJECT(pComboBox), "changed", G_CALLBACK(changePart), NULL );
-#endif
 
     GtkToolItem* pSeparator2 = gtk_separator_tool_item_new();
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator2, -1);
 
+    GtkToolItem* pPartModeSelectorToolItem = gtk_tool_item_new();
+    GtkWidget* pPartModeComboBox = gtk_combo_box_text_new();
+    gtk_container_add( GTK_CONTAINER(pPartModeSelectorToolItem), pPartModeComboBox );
+    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartModeSelectorToolItem, -1 );
+    g_signal_connect( G_OBJECT(pPartModeComboBox), "changed", G_CALLBACK(changePartMode), NULL );
+#endif
+
+    GtkToolItem* pSeparator3 = gtk_separator_tool_item_new();
+    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator3, -1);
+
     GtkToolItem* pEnableQuadView = gtk_toggle_tool_button_new();
     gtk_tool_button_set_label( GTK_TOOL_BUTTON(pEnableQuadView), "Use Quad View" );
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pEnableQuadView, -1 );
@@ -233,6 +265,7 @@ int main( int argc, char* argv[] )
     // GtkComboBox requires gtk 2.24 or later
 #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
     populatePartSelector( GTK_COMBO_BOX_TEXT(pComboBox), LOK_DOCVIEW(pDocView) );
+    populatePartModeSelector( GTK_COMBO_BOX_TEXT(pPartModeComboBox) );
 #endif
 
     gtk_main();
commit af58bb8335416ac6416f7f4b6269337b2127ab08
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 17:01:20 2014 +0200

    Protect setPartMode and ensure we actually show the new mode.
    
    Change-Id: I3642702c5bf268f3c9ab04162166078052804270

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 4de42e3..138b8f5 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -504,7 +504,31 @@ static void doc_setPartMode(LibreOfficeKitDocument* pThis,
         return;
     }
 
-    pDoc->setPartMode(ePartMode);
+    Application::AcquireSolarMutex(1);
+    {
+        int nCurrentPart = pDoc->getPart();
+
+        pDoc->setPartMode(ePartMode);
+
+        // We need to make sure the internal state is updated, just changing the mode
+        // might not update the relevant shells (i.e. impress will keep rendering the
+        // previous mode unless we do this).
+        // TODO: we might want to do this within the relevant components rather than
+        // here, but that's also dependent on how we implement embedded object
+        // rendering I guess?
+        // TODO: we could be clever and e.g. set to 0 when we change to/from
+        // embedded object mode, and not when changing between slide/notes/combined
+        // modes?
+        if ( nCurrentPart < pDoc->getParts() )
+        {
+            pDoc->setPart( nCurrentPart );
+        }
+        else
+        {
+            pDoc->setPart( 0 );
+        }
+    }
+    Application::ReleaseSolarMutex();
 }
 
 void doc_paintTile (LibreOfficeKitDocument* pThis,
commit b3375a273e8030fd576e8094fe0890fab23362ea
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 17:00:56 2014 +0200

    Impress/Tiled Rendering: implement setPartMode.
    
    Change-Id: I831953ac3fa1d0a15b64aa008cc3bfb79e72575a

diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index 8fa1904..e620ca5 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -234,6 +234,7 @@ public:
     virtual int  getPart() SAL_OVERRIDE;
     virtual int  getParts() SAL_OVERRIDE;
     virtual OUString getPartName( int nPart ) SAL_OVERRIDE;
+    virtual void setPartMode( LibreOfficeKitPartMode ePartMode ) SAL_OVERRIDE;
 
     // XComponent
 
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 7726de4..6c1661b 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2239,7 +2239,6 @@ void SdXImpressDocument::setPart( int nPart )
         // 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->SetPageKind( PK_STANDARD );
         pViewSh->SwitchPage( nPart );
     }
 }
@@ -2269,6 +2268,40 @@ OUString SdXImpressDocument::getPartName( int nPart )
     return pPage->GetName();
 }
 
+void SdXImpressDocument::setPartMode( LibreOfficeKitPartMode ePartMode )
+{
+    DrawViewShell* pViewSh = dynamic_cast< DrawViewShell* >( mpDoc->GetDocSh()->GetViewShell() );
+    if (!pViewSh)
+    {
+        return;
+    }
+
+    PageKind aPageKind;
+    switch ( ePartMode )
+    {
+    case LOK_PARTMODE_EMBEDDEDOBJ:
+        // This will probably be handled higher up, i.e.
+        // we probably shouldn't be handling this here.
+        // (However we don't offer embedded object-only
+        //  rendering anywhere yet, so this may be a
+        //  completely incorrect comment.)
+        assert( false );
+        // And let's fall through in a normal build.
+    case LOK_PARTMODE_DEFAULT:
+    case LOK_PARTMODE_SLIDE:
+        aPageKind = PK_STANDARD;
+        break;
+    case LOK_PARTMODE_SLIDENOTES:
+        aPageKind = PK_NOTES;
+        break;
+    case LOK_PARTMODE_NOTES:
+        // TODO: this shows combined slides + notes
+        aPageKind = PK_NOTES;
+        break;
+    }
+    pViewSh->SetPageKind( aPageKind );
+}
+
 Size SdXImpressDocument::getDocumentSize()
 {
     SdrPageView* pCurPageView = mpDoc->GetDocSh()->GetViewShell()->GetView()->GetSdrPageView();
commit 7f8eb6d501f962d2bdac9a581389289f8054daec
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 17:00:33 2014 +0200

    LOKDocView: add set_part_mode.
    
    Change-Id: I0e14a535124e93979ef05431255911245a11aa29

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index a73f98d..522d74d 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -64,6 +64,8 @@ void            lok_docview_set_part        (LOKDocView* pDocView,
                                              int nPart);
 char*           lok_docview_get_part_name   (LOKDocView* pDocView,
                                              int nPart);
+void            lok_docview_set_partmode    (LOKDocView* pDocView,
+                                             LibreOfficeKitPartMode ePartMode);
 #ifdef __cplusplus
 }
 #endif
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index cb045ce..5884e66 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -208,4 +208,11 @@ SAL_DLLPUBLIC_EXPORT char* lok_docview_get_part_name( LOKDocView* pDocView, int
 {
     return pDocView->pDocument->pClass->getPartName( pDocView->pDocument, nPart );
 }
+
+SAL_DLLPUBLIC_EXPORT void lok_docview_set_partmode( LOKDocView* pDocView,
+                                                    LibreOfficeKitPartMode ePartMode )
+{
+    pDocView->pDocument->pClass->setPartMode( pDocView->pDocument, ePartMode );
+    renderDocument( pDocView );
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 0dc6db6fafd4a4fa9a5ad8d2d09c7ec8ae3ae04e
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 16:59:10 2014 +0200

    Impress/Tiled Rendering: return correct number for getPart.
    
    It looks like page ids begin with 1.
    
    Change-Id: I367285b8cfa1fcc9b8f22a9bb3c679d7e9579099

diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index b6754ec..7726de4 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2256,7 +2256,8 @@ int SdXImpressDocument::getPart()
     DrawViewShell* pViewSh = dynamic_cast< DrawViewShell* >( mpDoc->GetDocSh()->GetViewShell() );
     if (pViewSh)
     {
-        return pViewSh->GetCurPageId();
+        // curPageId seems to start at 1
+        return pViewSh->GetCurPageId() - 1;
     }
     return 0;
 }
commit dd032c3f3b6d6d3142b86860b02efd47c27504cc
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 13:28:49 2014 +0200

    ITiledRenderable: provide default implementations for some methods.
    
    Writer doesn't understand the concept of parts at the moment, it
    makes most sense to keep these dummy implementations central.
    
    Change-Id: Iafbd89864b753ba2bed28a05b0f59df85f364feb

diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index a872713..a57053e 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -47,18 +47,27 @@ public:
      * Set the document "part", i.e. slide for a slideshow, and
      * tab for a spreadsheet.
      */
-    virtual void setPart( int nPart ) = 0;
+    virtual void setPart( int nPart )
+    {
+        (void) nPart;
+    }
 
     /**
      * Get the number of parts -- see setPart for further details.
      */
-    virtual int getParts() = 0;
+    virtual int getParts()
+    {
+        return 1;
+    }
 
     /**
      * Get the currently displayed/selected part -- see setPart for further
      * details.
      */
-    virtual int getPart() = 0;
+    virtual int getPart()
+    {
+        return 0;
+    }
 
     /**
      * Get the name of the currently displayed part, i.e. sheet in a spreadsheet
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 1318071..a48a8f3 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -439,9 +439,6 @@ public:
                             long nTileWidth,
                             long nTileHeight ) SAL_OVERRIDE;
     virtual Size getDocumentSize() SAL_OVERRIDE;
-    virtual void setPart(   int nPart ) SAL_OVERRIDE;
-    virtual int  getPart() SAL_OVERRIDE;
-    virtual int  getParts() SAL_OVERRIDE;
 
     void                        Invalidate();
     void                        Reactivate(SwDocShell* pNewDocShell);
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 8208814..1dc5f54 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3139,21 +3139,6 @@ Size SwXTextDocument::getDocumentSize()
     return pViewShell->GetDocSize();
 }
 
-void SwXTextDocument::setPart( int /*nPart*/ )
-{
-}
-
-int SwXTextDocument::getPart()
-{
-    return 0;
-}
-
-int SwXTextDocument::getParts()
-{
-    // For now we treat the document as one large piece.
-    return 1;
-}
-
 void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
 {
     return SwXTextDocumentBaseClass::operator new(t);
commit a965dfd7ea87a5aba4e4aefa21049159e56579cf
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 13:19:44 2014 +0200

    Impress: Implement getPartName.
    
    Change-Id: I614838505fef901fc37e8d3906bb59c60b034453

diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index 6887663..8fa1904 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -233,6 +233,7 @@ public:
     virtual void setPart(   int nPart ) SAL_OVERRIDE;
     virtual int  getPart() SAL_OVERRIDE;
     virtual int  getParts() SAL_OVERRIDE;
+    virtual OUString getPartName( int nPart ) SAL_OVERRIDE;
 
     // XComponent
 
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index 5a162f2..b6754ec 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -2261,6 +2261,13 @@ int SdXImpressDocument::getPart()
     return 0;
 }
 
+OUString SdXImpressDocument::getPartName( int nPart )
+{
+    SdPage* pPage = mpDoc->GetSdPage( nPart, PK_STANDARD );
+    assert( pPage );
+    return pPage->GetName();
+}
+
 Size SdXImpressDocument::getDocumentSize()
 {
     SdrPageView* pCurPageView = mpDoc->GetDocSh()->GetViewShell()->GetView()->GetSdrPageView();
commit 36e5f73637194afdb9ff0e320f6086be35c94a61
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 13:17:45 2014 +0200

    gtktiledviewer: show part names in selector.
    
    Change-Id: I02ae5b729f96e36b3f226218b32495907cb63cf3

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 21cb179..d74eb96 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -7,6 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -122,10 +123,17 @@ void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
 #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
 void populatePartSelector( GtkComboBoxText* pSelector, LOKDocView* pView )
 {
-    char sText[10];
-    for ( int i = 0; i < lok_docview_get_parts(pView); i++ )
+    const int nMaxLength = 50;
+    char sText[nMaxLength];
+
+    int nParts = lok_docview_get_parts(pView);
+    for ( int i = 0; i < nParts; i++ )
     {
-        sprintf( sText, "%i", i+1 );
+        char* pName = lok_docview_get_part_name( pView, i );
+        assert( pName );
+        snprintf( sText, nMaxLength, "%i (%s)", i+1, pName );
+        free( pName );
+
         gtk_combo_box_text_append_text( pSelector, sText );
     }
     gtk_combo_box_set_active( GTK_COMBO_BOX(pSelector), 0 );
@@ -219,8 +227,10 @@ int main( int argc, char* argv[] )
     gtk_widget_show_all( pWindow );
 
     pFileName = argv[2];
-    lok_docview_open_document( LOK_DOCVIEW(pDocView), argv[2] );
-// GtkComboBox requires gtk 2.24 or later
+    assert( lok_docview_open_document( LOK_DOCVIEW(pDocView), argv[2] ) );
+    assert( LOK_DOCVIEW(pDocView)->pDocument );
+
+    // GtkComboBox requires gtk 2.24 or later
 #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
     populatePartSelector( GTK_COMBO_BOX_TEXT(pComboBox), LOK_DOCVIEW(pDocView) );
 #endif
commit 366d8fb4dbe829653a4996acc8e9bae512ed0155
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 13:17:30 2014 +0200

    LOKDocView: add part name retrieval.
    
    Change-Id: Iac31de0410d7f6187e5884152c329375047a23f4

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 37d21f0..a73f98d 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -62,7 +62,8 @@ int             lok_docview_get_parts       (LOKDocView* pDocView);
 int             lok_docview_get_part        (LOKDocView* pDocView);
 void            lok_docview_set_part        (LOKDocView* pDocView,
                                              int nPart);
-
+char*           lok_docview_get_part_name   (LOKDocView* pDocView,
+                                             int nPart);
 #ifdef __cplusplus
 }
 #endif
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index 07d07a1..cb045ce 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -204,5 +204,8 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_set_part( LOKDocView* pDocView, int nPart)
     renderDocument( pDocView );
 }
 
-
+SAL_DLLPUBLIC_EXPORT char* lok_docview_get_part_name( LOKDocView* pDocView, int nPart )
+{
+    return pDocView->pDocument->pClass->getPartName( pDocView->pDocument, nPart );
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 977ba354b2256da7c871179a75b72c4f568d5fcb
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 09:02:02 2014 +0200

    Remove horrifically outdated comment.
    
    Change-Id: I1362489c9aecf536b31bf6ab57ad8c149f37a876

diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index c935ebc..d7b8e41 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -99,11 +99,6 @@ struct _LibreOfficeKitDocumentClass
   void (*setPartMode)     (LibreOfficeKitDocument* pThis,
                            LibreOfficeKitPartMode eMode);
 
-  // Get a pointer to a raw array, of size 3*nCanvasWidth*nCanvasHeight
-  // Basebmp's bitmap device seems to round the width up if needed
-  // for its internal buffer, i.e. the rowstride for the buffer may be larger
-  // than the desired width, hence we need to be able to return the
-  // rowstride too.
   void (*paintTile)       (LibreOfficeKitDocument* pThis,
                            unsigned char* pBuffer,
                            const int nCanvasWidth,
commit 6872ecdbc70befc1f3e9215f5c1cf1530ff8dc40
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 08:59:13 2014 +0200

    LOK: add setPartMode.
    
    This API seems to be simplest in the long run where we'll want to be
    able to select between rendering slides/notes/both/embedded objects,
    and maybe even adding the option of switching between continuous
    and single page mode in writer (although I have no idea how hard
    getting a single page mode out of writer would be).
    
    Change-Id: I5bdfdb61854c37281c6992c8f3ed1c50c8aa0919

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 6772694..4de42e3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -185,6 +185,7 @@ static int doc_getParts(LibreOfficeKitDocument* pThis);
 static int doc_getPart(LibreOfficeKitDocument* pThis);
 static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart);
 static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
+static void doc_setPartMode(LibreOfficeKitDocument* pThis, LibreOfficeKitPartMode ePartMode);
 void        doc_paintTile(LibreOfficeKitDocument* pThis,
                           unsigned char* pBuffer,
                           const int nCanvasWidth, const int nCanvasHeight,
@@ -216,6 +217,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
             m_pDocumentClass->getPart = doc_getPart;
             m_pDocumentClass->setPart = doc_setPart;
             m_pDocumentClass->getPartName = doc_getPartName;
+            m_pDocumentClass->setPartMode = doc_setPartMode;
             m_pDocumentClass->paintTile = doc_paintTile;
             m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
 
@@ -490,6 +492,21 @@ 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() );
+    if (!pDoc)
+    {
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+        return;
+    }
+
+    pDoc->setPartMode(ePartMode);
+}
+
 void doc_paintTile (LibreOfficeKitDocument* pThis,
                     unsigned char* pBuffer,
                     const int nCanvasWidth, const int nCanvasHeight,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index c90a947..c935ebc 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -40,6 +40,16 @@ typedef enum
   LOK_DOCTYPE_OTHER
 }
 LibreOfficeKitDocumentType;
+
+typedef enum
+{
+    LOK_PARTMODE_DEFAULT,
+    LOK_PARTMODE_SLIDE,
+    LOK_PARTMODE_NOTES,
+    LOK_PARTMODE_SLIDENOTES,
+    LOK_PARTMODE_EMBEDDEDOBJ
+}
+LibreOfficeKitPartMode;
 #endif // LOK_USE_UNSTABLE_API
 
 struct _LibreOfficeKit
@@ -86,6 +96,9 @@ struct _LibreOfficeKitDocumentClass
   char* (*getPartName)    (LibreOfficeKitDocument* pThis,
                            int nPart);
 
+  void (*setPartMode)     (LibreOfficeKitDocument* pThis,
+                           LibreOfficeKitPartMode eMode);
+
   // Get a pointer to a raw array, of size 3*nCanvasWidth*nCanvasHeight
   // Basebmp's bitmap device seems to round the width up if needed
   // for its internal buffer, i.e. the rowstride for the buffer may be larger
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index ca6ee25..a872713 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -11,6 +11,8 @@
 #ifndef INCLUDED_VCL_ITILEDRENDERABLE_HXX
 #define INCLUDED_VCL_ITILEDRENDERABLE_HXX
 
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKit.h>
 #include <tools/gen.hxx>
 #include <vcl/virdev.hxx>
 
@@ -67,6 +69,11 @@ public:
         (void) nPart;
         return "";
     }
+
+    virtual void setPartMode(LibreOfficeKitPartMode ePartMode)
+    {
+        (void) ePartMode;
+    }
 };
 
 } // namespace vcl
commit 6548361109deeb3be2e2c65b27eca04e59fa1f6f
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 08:50:34 2014 +0200

    LOK: Add getPartName.
    
    By default (i.e. for writer) we can just return an empty string,
    and we only actually need to implement ITiledRenderable's
    getPartName for components that actually support it (i.e. calc/impress).
    
    Change-Id: I8b381e5d7a8000638b02f763b4bea8ef0226f8e0

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 6c4d5cc..6772694 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -184,6 +184,7 @@ static LibreOfficeKitDocumentType doc_getDocumentType(LibreOfficeKitDocument* pT
 static int doc_getParts(LibreOfficeKitDocument* pThis);
 static int doc_getPart(LibreOfficeKitDocument* pThis);
 static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart);
+static char* doc_getPartName(LibreOfficeKitDocument* pThis, int nPart);
 void        doc_paintTile(LibreOfficeKitDocument* pThis,
                           unsigned char* pBuffer,
                           const int nCanvasWidth, const int nCanvasHeight,
@@ -214,6 +215,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
             m_pDocumentClass->getParts = doc_getParts;
             m_pDocumentClass->getPart = doc_getPart;
             m_pDocumentClass->setPart = doc_setPart;
+            m_pDocumentClass->getPartName = doc_getPartName;
             m_pDocumentClass->paintTile = doc_paintTile;
             m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
 
@@ -469,6 +471,25 @@ static void doc_setPart(LibreOfficeKitDocument* pThis, int nPart)
     Application::ReleaseSolarMutex();
 }
 
+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() );
+    if (!pDoc)
+    {
+        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+        return 0;
+    }
+
+    OUString sName = pDoc->getPartName( nPart );
+    OString aString = OUStringToOString(sName, RTL_TEXTENCODING_UTF8);
+    char* pMemory = (char*) malloc(aString.getLength() + 1);
+    strcpy(pMemory, aString.getStr());
+    return pMemory;
+
+}
+
 void doc_paintTile (LibreOfficeKitDocument* pThis,
                     unsigned char* pBuffer,
                     const int nCanvasWidth, const int nCanvasHeight,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 9fb5ace..c90a947 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -83,6 +83,9 @@ struct _LibreOfficeKitDocumentClass
   void (*setPart)         (LibreOfficeKitDocument* pThis,
                            int nPart);
 
+  char* (*getPartName)    (LibreOfficeKitDocument* pThis,
+                           int nPart);
+
   // Get a pointer to a raw array, of size 3*nCanvasWidth*nCanvasHeight
   // Basebmp's bitmap device seems to round the width up if needed
   // for its internal buffer, i.e. the rowstride for the buffer may be larger
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 32faf26..f61a4b8 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -64,6 +64,11 @@ public:
         mpDoc->pClass->setPart(mpDoc, nPart);
     }
 
+    inline char* getPartName(int nPart)
+    {
+        return mpDoc->pClass->getPartName(mpDoc, nPart);
+    }
+
     inline void paintTile(
                           unsigned char* pBuffer,
                           const int nCanvasWidth,
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 55e1b39..ca6ee25 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -57,6 +57,16 @@ public:
      * details.
      */
     virtual int getPart() = 0;
+
+    /**
+     * Get the name of the currently displayed part, i.e. sheet in a spreadsheet
+     * or slide in a presentation.
+     */
+    virtual OUString getPartName(int nPart)
+    {
+        (void) nPart;
+        return "";
+    }
 };
 
 } // namespace vcl
commit 5fe0711dbe8568f6ec5fe7c2edeb122519ac68a7
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Tue Jul 29 08:32:07 2014 +0200

    Fix comment typo.
    
    Change-Id: I8ebe3ad2a6efcf1797a2dc941994c7fc1e36f4bf

diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 9c74634..9fb5ace 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -76,7 +76,7 @@ struct _LibreOfficeKitDocumentClass
   LibreOfficeKitDocumentType (*getDocumentType) (LibreOfficeKitDocument* pThis);
 
   // Part refers to either indivual sheets in a Spreadsheet, or slides
-  // in a Slideshow, and has no relevance for wrtier documents.
+  // in a Slideshow, and has no relevance for writer documents.
   int (*getParts) (LibreOfficeKitDocument* pThis);
 
   int (*getPart)          (LibreOfficeKitDocument* pThis);


More information about the Libreoffice-commits mailing list