diff options
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitGtk.h | 1 | ||||
-rw-r--r-- | libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 14 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 21 |
3 files changed, 34 insertions, 2 deletions
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h index cce580f36353..320121e0b819 100644 --- a/include/LibreOfficeKit/LibreOfficeKitGtk.h +++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h @@ -40,6 +40,7 @@ struct _LOKDocViewClass void (* edit_changed) (LOKDocView* pView, gboolean was_edit); void (* command_changed) (LOKDocView* pView, char* new_state); void (* search_not_found) (LOKDocView* pView, char* new_state); + void (* part_changed) (LOKDocView* pView, int new_part); }; guint lok_docview_get_type (void); diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index edd5006ccd48..ed2471f6c401 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -45,6 +45,8 @@ static GtkWidget* pVBox; // GtkComboBox requires gtk 2.24 or later #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2 static GtkComboBoxText* pPartSelector; +/// Should the part selector avoid calling lok::Document::setPart()? +static bool g_bPartSelectorBroadcast = true; #endif GtkWidget* pFindbar; GtkWidget* pFindbarEntry; @@ -238,6 +240,15 @@ static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpoint gtk_label_set_text(GTK_LABEL(pFindbarLabel), "Search key not found"); } +static void signalPart(LOKDocView* /*pLOKDocView*/, int nPart, gpointer /*pData*/) +{ +#if GTK_CHECK_VERSION(2,24,0) + g_bPartSelectorBroadcast = false; + gtk_combo_box_set_active(GTK_COMBO_BOX(pPartSelector), nPart); + g_bPartSelectorBroadcast = true; +#endif +} + /// User clicked on a cmmand button -> inform LOKDocView. static void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/) { @@ -285,7 +296,7 @@ static void changePart( GtkWidget* pSelector, gpointer /* pItem */ ) { int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) ); - if ( pDocView ) + if (g_bPartSelectorBroadcast && pDocView) { lok_docview_set_part( LOK_DOCVIEW(pDocView), nPart ); } @@ -443,6 +454,7 @@ int main( int argc, char* argv[] ) g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL); g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL); g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL); + g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL); // Input handling. g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), pDocView); diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 874f96a1f6ba..73dd15e172fb 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -194,6 +194,8 @@ struct LOKDocView_Impl void commandChanged(const std::string& rPayload); /// Search did not find any matches. void searchNotFound(const std::string& rPayload); + /// LOK decided to change parts, need to update UI. + void setPart(const std::string& rPayload); }; namespace { @@ -1019,7 +1021,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback) break; case LOK_CALLBACK_SET_PART: { - renderDocument(0); + setPart(pCallback->m_aPayload); } break; default: @@ -1066,6 +1068,7 @@ enum EDIT_CHANGED, COMMAND_CHANGED, SEARCH_NOT_FOUND, + PART_CHANGED, LAST_SIGNAL }; @@ -1081,6 +1084,12 @@ void LOKDocView_Impl::searchNotFound(const std::string& rString) g_signal_emit(m_pDocView, docview_signals[SEARCH_NOT_FOUND], 0, rString.c_str()); } +void LOKDocView_Impl::setPart(const std::string& rString) +{ + g_signal_emit(m_pDocView, docview_signals[PART_CHANGED], 0, std::stoi(rString)); + renderDocument(0); +} + static void lok_docview_class_init( gpointer ptr ) { LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr); @@ -1115,6 +1124,16 @@ static void lok_docview_class_init( gpointer ptr ) g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); + pClass->part_changed = 0; + docview_signals[PART_CHANGED] = + g_signal_new("part-changed", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET(LOKDocViewClass, part_changed), + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, + G_TYPE_INT); } static void lok_docview_init( GTypeInstance* pInstance, gpointer ) |