include/LibreOfficeKit/LibreOfficeKitEnums.h | 32 +++++++ libreofficekit/source/gtk/lokdocview.cxx | 110 ++++++++++++++++++++------- 2 files changed, 114 insertions(+), 28 deletions(-)
New commits: commit 71cd37fad9792038279969c82e0cb209df06f024 Author: Pranav Kant <[email protected]> Date: Thu Dec 21 13:20:26 2017 +0530 lokdocview: Handle INVALIDATE_HEADER cb With this calc gtktiledviewer or any other lok client shouldn't crash anymore when a new view is opened. And while at it, update documentation of callbacks. Change-Id: I436c3b424dd4e2e6b8c312b0d3ba43d7006e944b diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 9cf635bb4c40..46be3f25fea8 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -514,11 +514,12 @@ typedef enum * The column/row header is no more valid because of a column/row insertion * or a similar event. Clients must query a new column/row header set. * - * The payload says if we are invalidating a row or column header. + * The payload says if we are invalidating a row or column header. So, + * payload values can be: "row", "column", "all". */ LOK_CALLBACK_INVALIDATE_HEADER = 33, /** - * The text content of the address field in Calc. + * The text content of the address field in Calc. Eg: "A7" */ LOK_CALLBACK_CELL_ADDRESS = 34, /** @@ -539,7 +540,32 @@ typedef enum */ LOK_CALLBACK_RULER_UPDATE = 35, /** - * Dialog invalidation + * Window related callbacks are emitted under this category. It includes + * external windows like dialogs, autopopups for now. + * + * The payload format is: + * + * { + * "id": "unique integer id of the dialog", + * "action": "<see below>", + * "type": "<see below>" + * "rectangle": "x, y, width, height" + * } + * + * "type" tells the type of the window the action is associated with + * - "dialog" - window is a dialog + * - "child" - window is a floating window (combo boxes, etc.) + * + * "action" can take following values: + * - "created" - window is created in the backend, client can render it now + * - "title_changed" - window's title is changed + * - "size_changed" - window's size is changed + * - "invalidate" - the area as described by "rectangle" is invalidated + * Clients must request the new area + * - "cursor_invalidate" - cursor is invalidated. New position is in "rectangle" + * - "cursor_visible" - cursor visible status is changed. Status is availabe + * in "visible" field + * - "close" - window is closed */ LOK_CALLBACK_WINDOW = 36, } diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 9070cb902236..f2609149de06 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -275,6 +275,7 @@ enum COMMENT, RULER, WINDOW, + INVALIDATE_HEADER, LAST_SIGNAL }; @@ -428,6 +429,8 @@ callbackTypeToString (int nType) return "LOK_CALLBACK_REDLINE_TABLE_SIZE_CHANGED"; case LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED: return "LOK_CALLBACK_REDLINE_TABLE_ENTRY_MODIFIED"; + case LOK_CALLBACK_INVALIDATE_HEADER: + return "LOK_CALLBACK_INVALIDATE_HEADER"; case LOK_CALLBACK_COMMENT: return "LOK_CALLBACK_COMMENT"; case LOK_CALLBACK_RULER_UPDATE: @@ -1410,6 +1413,9 @@ callback (gpointer pData) case LOK_CALLBACK_WINDOW: g_signal_emit(pCallback->m_pDocView, doc_view_signals[WINDOW], 0, pCallback->m_aPayload.c_str()); break; + case LOK_CALLBACK_INVALIDATE_HEADER: + g_signal_emit(pCallback->m_pDocView, doc_view_signals[INVALIDATE_HEADER], 0, pCallback->m_aPayload.c_str()); + break; default: g_assert(false); break; @@ -3198,6 +3204,22 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) G_TYPE_NONE, 1, G_TYPE_STRING); + /** + * The key ruler related properties on change are reported by this. + * + * The payload format is: + * + * { + * "margin1": "...", + * "margin2": "...", + * "leftOffset": "...", + * "pageOffset": "...", + * "pageWidth": "...", + * "unit": "..." + * } + * + * Here all aproperties are same as described in svxruler. + */ doc_view_signals[RULER] = g_signal_new("ruler", G_TYPE_FROM_CLASS(pGObjectClass), @@ -3209,9 +3231,32 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) G_TYPE_STRING); /** - * LOKDocView::window - * @pDocView: the #LOKDocView on which the signal is emitted - * @pPayload: JSON containing the information, including id, about the window + * Window related callbacks are emitted under this category. It includes + * external windows like dialogs, autopopups for now. + * + * The payload format is: + * + * { + * "id": "unique integer id of the dialog", + * "action": "<see below>", + * "type": "<see below>" + * "rectangle": "x, y, width, height" + * } + * + * "type" tells the type of the window the action is associated with + * - "dialog" - window is a dialog + * - "child" - window is a floating window (combo boxes, etc.) + * + * "action" can take following values: + * - "created" - window is created in the backend, client can render it now + * - "title_changed" - window's title is changed + * - "size_changed" - window's size is changed + * - "invalidate" - the area as described by "rectangle" is invalidated + * Clients must request the new area + * - "cursor_invalidate" - cursor is invalidated. New position is in "rectangle" + * - "cursor_visible" - cursor visible status is changed. Status is availabe + * in "visible" field + * - "close" - window is closed */ doc_view_signals[WINDOW] = g_signal_new("window", @@ -3222,6 +3267,23 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass) g_cclosure_marshal_generic, G_TYPE_NONE, 1, G_TYPE_STRING); + + /** + * The column/row header is no more valid because of a column/row insertion + * or a similar event. Clients must query a new column/row header set. + * + * The payload says if we are invalidating a row or column header. So, + * payload values can be: "row", "column", "all". + */ + doc_view_signals[INVALIDATE_HEADER] = + g_signal_new("invalidate-header", + G_TYPE_FROM_CLASS(pGObjectClass), + G_SIGNAL_RUN_FIRST, + 0, + nullptr, nullptr, + g_cclosure_marshal_generic, + G_TYPE_NONE, 1, + G_TYPE_STRING); } SAL_DLLPUBLIC_EXPORT GtkWidget* commit 9d2e0d60c0381a4bb23fada14c80e032b68bf2a8 Author: Pranav Kant <[email protected]> Date: Thu Dec 21 12:47:52 2017 +0530 lokdocview: use std::string where possible This also prevents an invalid memory access: we were storing the pointer to a temporary in the struct and then using it after temporary was gone. Change-Id: I2b6d9df16bc24b222095ccbf45c9f0bd9c86ed65 diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index eae5c6225cd9..9070cb902236 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -76,9 +76,9 @@ struct ViewRectangles /// Private struct used by this GObject type struct LOKDocViewPrivateImpl { - const gchar* m_aLOPath; - const gchar* m_pUserProfileURL; - const gchar* m_aDocPath; + std::string m_aLOPath; + std::string m_aUserProfileURL; + std::string m_aDocPath; std::string m_aRenderingArguments; gdouble m_nLoadProgress; gboolean m_bIsLoading; @@ -192,10 +192,7 @@ struct LOKDocViewPrivateImpl std::map<int, ViewRectangle> m_aViewLockRectangles; LOKDocViewPrivateImpl() - : m_aLOPath(nullptr), - m_pUserProfileURL(nullptr), - m_aDocPath(nullptr), - m_nLoadProgress(0), + : m_nLoadProgress(0), m_bIsLoading(false), m_bCanZoomIn(true), m_bCanZoomOut(true), @@ -1750,7 +1747,7 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) if (priv->m_bEdit && priv->m_bCursorVisible && !isEmptyRectangle(priv->m_aVisibleCursor) && priv->m_aTextSelectionRectangles.empty()) { // Have a cursor, but no selection: we need the middle handle. - gchar* handleMiddlePath = g_strconcat (priv->m_aLOPath, CURSOR_HANDLE_DIR, "handle_image_middle.png", nullptr); + gchar* handleMiddlePath = g_strconcat (priv->m_aLOPath.c_str(), CURSOR_HANDLE_DIR, "handle_image_middle.png", nullptr); if (!priv->m_pHandleMiddle) { priv->m_pHandleMiddle = cairo_image_surface_create_from_png(handleMiddlePath); @@ -1778,7 +1775,7 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) if (!isEmptyRectangle(priv->m_aTextSelectionStart)) { // Have a start position: we need a start handle. - gchar* handleStartPath = g_strconcat (priv->m_aLOPath, CURSOR_HANDLE_DIR, "handle_image_start.png", nullptr); + gchar* handleStartPath = g_strconcat (priv->m_aLOPath.c_str(), CURSOR_HANDLE_DIR, "handle_image_start.png", nullptr); if (!priv->m_pHandleStart) { priv->m_pHandleStart = cairo_image_surface_create_from_png(handleStartPath); @@ -1790,7 +1787,7 @@ renderOverlay(LOKDocView* pDocView, cairo_t* pCairo) if (!isEmptyRectangle(priv->m_aTextSelectionEnd)) { // Have a start position: we need an end handle. - gchar* handleEndPath = g_strconcat (priv->m_aLOPath, CURSOR_HANDLE_DIR, "handle_image_end.png", nullptr); + gchar* handleEndPath = g_strconcat (priv->m_aLOPath.c_str(), CURSOR_HANDLE_DIR, "handle_image_end.png", nullptr); if (!priv->m_pHandleEnd) { priv->m_pHandleEnd = cairo_image_surface_create_from_png(handleEndPath); @@ -2221,7 +2218,7 @@ openDocumentInThread (gpointer data) } priv->m_pOffice->pClass->registerCallback(priv->m_pOffice, globalCallbackWorker, pDocView); - priv->m_pDocument = priv->m_pOffice->pClass->documentLoad( priv->m_pOffice, priv->m_aDocPath ); + priv->m_pDocument = priv->m_pOffice->pClass->documentLoad( priv->m_pOffice, priv->m_aDocPath.c_str() ); priv->m_eDocumentType = static_cast<LibreOfficeKitDocumentType>(priv->m_pDocument->pClass->getDocumentType(priv->m_pDocument)); if ( !priv->m_pDocument ) { @@ -2484,16 +2481,17 @@ static void lok_doc_view_set_property (GObject* object, guint propId, const GVal switch (propId) { case PROP_LO_PATH: - priv->m_aLOPath = g_value_dup_string (value); + priv->m_aLOPath = g_value_get_string (value); break; case PROP_LO_POINTER: priv->m_pOffice = static_cast<LibreOfficeKit*>(g_value_get_pointer(value)); break; case PROP_USER_PROFILE_URL: - priv->m_pUserProfileURL = g_value_dup_string(value); + if (const gchar* pUserProfile = g_value_get_string(value)) + priv->m_aUserProfileURL = pUserProfile; break; case PROP_DOC_PATH: - priv->m_aDocPath = g_value_dup_string (value); + priv->m_aDocPath = g_value_get_string (value); break; case PROP_DOC_POINTER: priv->m_pDocument = static_cast<LibreOfficeKitDocument*>(g_value_get_pointer(value)); @@ -2545,16 +2543,16 @@ static void lok_doc_view_get_property (GObject* object, guint propId, GValue *va switch (propId) { case PROP_LO_PATH: - g_value_set_string (value, priv->m_aLOPath); + g_value_set_string (value, priv->m_aLOPath.c_str()); break; case PROP_LO_POINTER: g_value_set_pointer(value, priv->m_pOffice); break; case PROP_USER_PROFILE_URL: - g_value_set_string(value, priv->m_pUserProfileURL); + g_value_set_string(value, priv->m_aUserProfileURL.c_str()); break; case PROP_DOC_PATH: - g_value_set_string (value, priv->m_aDocPath); + g_value_set_string (value, priv->m_aDocPath.c_str()); break; case PROP_DOC_POINTER: g_value_set_pointer(value, priv->m_pDocument); @@ -2677,14 +2675,14 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* / if (priv->m_pOffice != nullptr) return TRUE; - priv->m_pOffice = lok_init_2(priv->m_aLOPath, priv->m_pUserProfileURL); + priv->m_pOffice = lok_init_2(priv->m_aLOPath.c_str(), priv->m_aUserProfileURL.empty() ? nullptr : priv->m_aUserProfileURL.c_str()); if (priv->m_pOffice == nullptr) { g_set_error (error, g_quark_from_static_string ("LOK initialization error"), 0, "Failed to get LibreOfficeKit context. Make sure path (%s) is correct", - priv->m_aLOPath); + priv->m_aLOPath.c_str()); return FALSE; } priv->m_nLOKFeatures |= LOK_FEATURE_PART_IN_INVALIDATION_CALLBACK; @@ -3252,8 +3250,8 @@ SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOK { LOKDocViewPrivate& pOldPriv = getPrivate(pOldLOKDocView); GtkWidget* pNewDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/nullptr, /*error=*/nullptr, - "lopath", pOldPriv->m_aLOPath, - "userprofileurl", pOldPriv->m_pUserProfileURL, + "lopath", pOldPriv->m_aLOPath.c_str(), + "userprofileurl", pOldPriv->m_aUserProfileURL.c_str(), "lopointer", pOldPriv->m_pOffice, "docpointer", pOldPriv->m_pDocument, "halign", GTK_ALIGN_CENTER, @@ -3298,7 +3296,7 @@ lok_doc_view_open_document (LOKDocView* pDocView, LOEvent* pLOEvent = new LOEvent(LOK_LOAD_DOC); - priv->m_aDocPath = pPath; + g_object_set(G_OBJECT(pDocView), "docpath", pPath, nullptr); if (pRenderingArguments) priv->m_aRenderingArguments = pRenderingArguments; g_task_set_task_data(task, pLOEvent, LOEvent::destroy); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
