include/LibreOfficeKit/LibreOfficeKitGtk.h | 3 libreofficekit/Executable_gtktiledviewer.mk | 2 libreofficekit/Library_libreofficekitgtk.mk | 1 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 67 --- libreofficekit/source/gtk/lokdocview.cxx | 353 +++++++++++--------- 5 files changed, 217 insertions(+), 209 deletions(-)
New commits: commit 31f4e1c075d5fb0dc1f7c75ed8c552ed5d641b8b Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Mar 25 18:19:11 2015 +0100 lokdocview: move button handling to LOKDocView_Impl Change-Id: Iac5d9e97f04af92ff6f6945d691abe94a3d785b0 diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 86a7e18..5793d7a 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -39,6 +39,7 @@ static const int DPI = 96; /// Holds data used by LOKDocView only. struct LOKDocView_Impl { + LOKDocView* m_pDocView; GtkWidget* m_pEventBox; GtkWidget* m_pTable; GtkWidget** m_pCanvas; @@ -100,7 +101,7 @@ struct LOKDocView_Impl bool m_bInDragGraphicHandles[8]; ///@} - LOKDocView_Impl(); + LOKDocView_Impl(LOKDocView* pDocView); ~LOKDocView_Impl(); /// Connected to the destroy signal of LOKDocView, deletes its LOKDocView_Impl. static void destroy(LOKDocView* pDocView, gpointer pData); @@ -110,10 +111,24 @@ struct LOKDocView_Impl float twipToPixel(float fInput); /// Receives a key press or release event. void signalKey(GdkEventKey* pEvent); + /** + * The user drags the handle, which is below the cursor, but wants to move the + * cursor accordingly. + * + * @param pHandle the rectangle of the handle + * @param pEvent the motion event + * @param pPoint the computed point (output parameter) + */ + static void getDragPoint(GdkRectangle* pHandle, GdkEventButton* pEvent, GdkPoint* pPoint); + /// Receives a button press event. + static gboolean signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView); + /// Implementation of button press event handler, invoked by signalButton(). + gboolean signalButtonImpl(GdkEventButton* pEvent); }; -LOKDocView_Impl::LOKDocView_Impl() - : m_pEventBox(gtk_event_box_new()), +LOKDocView_Impl::LOKDocView_Impl(LOKDocView* pDocView) + : m_pDocView(pDocView), + m_pEventBox(gtk_event_box_new()), m_pTable(0), m_pCanvas(0), m_fZoom(1), @@ -228,150 +243,58 @@ void LOKDocView_Impl::signalKey(GdkEventKey* pEvent) m_pDocument->pClass->postKeyEvent(m_pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode); } - -static void lok_docview_class_init( gpointer ); -static void lok_docview_init( GTypeInstance *, gpointer ); -static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData); - -/** - * The user drags the handle, which is below the cursor, but wants to move the - * cursor accordingly. - * - * @param pHandle the rectangle of the handle - * @param pEvent the motion event - * @param pPoint the computed point (output parameter) - */ -void lcl_getDragPoint(GdkRectangle* pHandle, GdkEventButton* pEvent, GdkPoint* pPoint) +gboolean LOKDocView_Impl::signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView) { - GdkPoint aCursor, aHandle; - - // Center of the cursor rectangle: we know that it's above the handle. - aCursor.x = pHandle->x + pHandle->width / 2; - aCursor.y = pHandle->y - pHandle->height / 2; - // Center of the handle rectangle. - aHandle.x = pHandle->x + pHandle->width / 2; - aHandle.y = pHandle->y + pHandle->height / 2; - // Our target is the original cursor position + the dragged offset. - pPoint->x = aCursor.x + (pEvent->x - aHandle.x); - pPoint->y = aCursor.y + (pEvent->y - aHandle.y); -} - -gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView) -{ - GdkPoint aPoint; - - if (pDocView->m_pImpl->m_bInDragMiddleHandle) - { - g_info("lcl_signalMotion: dragging the middle handle"); - lcl_getDragPoint(&pDocView->m_pImpl->m_aHandleMiddleRect, pEvent, &aPoint); - pDocView->m_pImpl->m_pDocument->pClass->setTextSelection( - pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_RESET, - pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y)); - return FALSE; - } - if (pDocView->m_pImpl->m_bInDragStartHandle) - { - g_info("lcl_signalMotion: dragging the start handle"); - lcl_getDragPoint(&pDocView->m_pImpl->m_aHandleStartRect, pEvent, &aPoint); - pDocView->m_pImpl->m_pDocument->pClass->setTextSelection( - pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_START, - pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y)); - return FALSE; - } - if (pDocView->m_pImpl->m_bInDragEndHandle) - { - g_info("lcl_signalMotion: dragging the end handle"); - lcl_getDragPoint(&pDocView->m_pImpl->m_aHandleEndRect, pEvent, &aPoint); - pDocView->m_pImpl->m_pDocument->pClass->setTextSelection( - pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_END, - pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y)); - return FALSE; - } - for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i) - { - if (pDocView->m_pImpl->m_bInDragGraphicHandles[i]) - { - g_info("lcl_signalMotion: dragging the graphic handle #%d", i); - return FALSE; - } - } - if (pDocView->m_pImpl->m_bInDragGraphicSelection) - { - g_info("lcl_signalMotion: dragging the graphic selection"); - return FALSE; - } - - GdkRectangle aMotionInTwipsInTwips; - aMotionInTwipsInTwips.x = pDocView->m_pImpl->pixelToTwip(pEvent->x); - aMotionInTwipsInTwips.y = pDocView->m_pImpl->pixelToTwip(pEvent->y); - aMotionInTwipsInTwips.width = 1; - aMotionInTwipsInTwips.height = 1; - if (gdk_rectangle_intersect(&aMotionInTwipsInTwips, &pDocView->m_pImpl->m_aGraphicSelection, 0)) - { - g_info("lcl_signalMotion: start of drag graphic selection"); - pDocView->m_pImpl->m_bInDragGraphicSelection = true; - pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection( - pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_START, - pDocView->m_pImpl->pixelToTwip(pEvent->x), - pDocView->m_pImpl->pixelToTwip(pEvent->y)); - return FALSE; - } - - return FALSE; + return pDocView->m_pImpl->signalButtonImpl(pEvent); } /// Receives a button press event. -gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView) +gboolean LOKDocView_Impl::signalButtonImpl(GdkEventButton* pEvent) { - g_info("lcl_signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pDocView->m_pImpl->pixelToTwip(pEvent->x), (int)pDocView->m_pImpl->pixelToTwip(pEvent->y)); + g_info("LOKDocView_Impl::ssignalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pixelToTwip(pEvent->x), (int)pixelToTwip(pEvent->y)); if (pEvent->type == GDK_BUTTON_RELEASE) { - if (pDocView->m_pImpl->m_bInDragStartHandle) + if (m_bInDragStartHandle) { - g_info("lcl_signalButton: end of drag start handle"); - pDocView->m_pImpl->m_bInDragStartHandle = false; + g_info("LOKDocView_Impl::signalButton: end of drag start handle"); + m_bInDragStartHandle = false; return FALSE; } - else if (pDocView->m_pImpl->m_bInDragMiddleHandle) + else if (m_bInDragMiddleHandle) { - g_info("lcl_signalButton: end of drag middle handle"); - pDocView->m_pImpl->m_bInDragMiddleHandle = false; + g_info("LOKDocView_Impl::signalButton: end of drag middle handle"); + m_bInDragMiddleHandle = false; return FALSE; } - else if (pDocView->m_pImpl->m_bInDragEndHandle) + else if (m_bInDragEndHandle) { - g_info("lcl_signalButton: end of drag end handle"); - pDocView->m_pImpl->m_bInDragEndHandle = false; + g_info("LOKDocView_Impl::signalButton: end of drag end handle"); + m_bInDragEndHandle = false; return FALSE; } for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i) { - if (pDocView->m_pImpl->m_bInDragGraphicHandles[i]) + if (m_bInDragGraphicHandles[i]) { - g_info("lcl_signalButton: end of drag graphic handle #%d", i); - pDocView->m_pImpl->m_bInDragGraphicHandles[i] = false; - pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection( - pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_END, - pDocView->m_pImpl->pixelToTwip(pEvent->x), pDocView->m_pImpl->pixelToTwip(pEvent->y)); + g_info("LOKDocView_Impl::signalButton: end of drag graphic handle #%d", i); + m_bInDragGraphicHandles[i] = false; + m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y)); return FALSE; } } - if (pDocView->m_pImpl->m_bInDragGraphicSelection) + if (m_bInDragGraphicSelection) { - g_info("lcl_signalButton: end of drag graphic selection"); - pDocView->m_pImpl->m_bInDragGraphicSelection = false; - pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection( - pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_END, - pDocView->m_pImpl->pixelToTwip(pEvent->x), - pDocView->m_pImpl->pixelToTwip(pEvent->y)); + g_info("LOKDocView_Impl::signalButton: end of drag graphic selection"); + m_bInDragGraphicSelection = false; + m_pDocument->pClass->setGraphicSelection(m_pDocument, LOK_SETGRAPHICSELECTION_END, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y)); return FALSE; } } - if (pDocView->m_pImpl->m_bEdit) + if (m_bEdit) { GdkRectangle aClick; aClick.x = pEvent->x; @@ -380,68 +303,62 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD aClick.height = 1; if (pEvent->type == GDK_BUTTON_PRESS) { - if (gdk_rectangle_intersect(&aClick, &pDocView->m_pImpl->m_aHandleStartRect, NULL)) + if (gdk_rectangle_intersect(&aClick, &m_aHandleStartRect, NULL)) { - g_info("lcl_signalButton: start of drag start handle"); - pDocView->m_pImpl->m_bInDragStartHandle = true; + g_info("LOKDocView_Impl::signalButton: start of drag start handle"); + m_bInDragStartHandle = true; return FALSE; } - else if (gdk_rectangle_intersect(&aClick, &pDocView->m_pImpl->m_aHandleMiddleRect, NULL)) + else if (gdk_rectangle_intersect(&aClick, &m_aHandleMiddleRect, NULL)) { - g_info("lcl_signalButton: start of drag middle handle"); - pDocView->m_pImpl->m_bInDragMiddleHandle = true; + g_info("LOKDocView_Impl::signalButton: start of drag middle handle"); + m_bInDragMiddleHandle = true; return FALSE; } - else if (gdk_rectangle_intersect(&aClick, &pDocView->m_pImpl->m_aHandleEndRect, NULL)) + else if (gdk_rectangle_intersect(&aClick, &m_aHandleEndRect, NULL)) { - g_info("lcl_signalButton: start of drag end handle"); - pDocView->m_pImpl->m_bInDragEndHandle = true; + g_info("LOKDocView_Impl::signalButton: start of drag end handle"); + m_bInDragEndHandle = true; return FALSE; } for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i) { - if (gdk_rectangle_intersect(&aClick, &pDocView->m_pImpl->m_aGraphicHandleRects[i], NULL)) + if (gdk_rectangle_intersect(&aClick, &m_aGraphicHandleRects[i], NULL)) { - g_info("lcl_signalButton: start of drag graphic handle #%d", i); - pDocView->m_pImpl->m_bInDragGraphicHandles[i] = true; - pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection( - pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_START, - pDocView->m_pImpl->pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[i].x + pDocView->m_pImpl->m_aGraphicHandleRects[i].width / 2), - pDocView->m_pImpl->pixelToTwip(pDocView->m_pImpl->m_aGraphicHandleRects[i].y + pDocView->m_pImpl->m_aGraphicHandleRects[i].height / 2)); + g_info("LOKDocView_Impl::signalButton: start of drag graphic handle #%d", i); + m_bInDragGraphicHandles[i] = true; + m_pDocument->pClass->setGraphicSelection(m_pDocument, + LOK_SETGRAPHICSELECTION_START, + pixelToTwip(m_aGraphicHandleRects[i].x + m_aGraphicHandleRects[i].width / 2), + pixelToTwip(m_aGraphicHandleRects[i].y + m_aGraphicHandleRects[i].height / 2)); return FALSE; } } } } - if (!pDocView->m_pImpl->m_bEdit) - lok_docview_set_edit(pDocView, TRUE); + if (!m_bEdit) + lok_docview_set_edit(m_pDocView, TRUE); switch (pEvent->type) { case GDK_BUTTON_PRESS: { int nCount = 1; - if ((pEvent->time - pDocView->m_pImpl->m_nLastButtonPressTime) < 250) + if ((pEvent->time - m_nLastButtonPressTime) < 250) nCount++; - pDocView->m_pImpl->m_nLastButtonPressTime = pEvent->time; - pDocView->m_pImpl->m_pDocument->pClass->postMouseEvent( - pDocView->m_pImpl->m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, - pDocView->m_pImpl->pixelToTwip(pEvent->x), - pDocView->m_pImpl->pixelToTwip(pEvent->y), nCount); + m_nLastButtonPressTime = pEvent->time; + m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount); break; } case GDK_BUTTON_RELEASE: { int nCount = 1; - if ((pEvent->time - pDocView->m_pImpl->m_nLastButtonReleaseTime) < 250) + if ((pEvent->time - m_nLastButtonReleaseTime) < 250) nCount++; - pDocView->m_pImpl->m_nLastButtonReleaseTime = pEvent->time; - pDocView->m_pImpl->m_pDocument->pClass->postMouseEvent( - pDocView->m_pImpl->m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, - pDocView->m_pImpl->pixelToTwip(pEvent->x), - pDocView->m_pImpl->pixelToTwip(pEvent->y), nCount); + m_nLastButtonReleaseTime = pEvent->time; + m_pDocument->pClass->postMouseEvent(m_pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP, pixelToTwip(pEvent->x), pixelToTwip(pEvent->y), nCount); break; } default: @@ -450,6 +367,89 @@ gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKD return FALSE; } +void LOKDocView_Impl::getDragPoint(GdkRectangle* pHandle, GdkEventButton* pEvent, GdkPoint* pPoint) +{ + GdkPoint aCursor, aHandle; + + // Center of the cursor rectangle: we know that it's above the handle. + aCursor.x = pHandle->x + pHandle->width / 2; + aCursor.y = pHandle->y - pHandle->height / 2; + // Center of the handle rectangle. + aHandle.x = pHandle->x + pHandle->width / 2; + aHandle.y = pHandle->y + pHandle->height / 2; + // Our target is the original cursor position + the dragged offset. + pPoint->x = aCursor.x + (pEvent->x - aHandle.x); + pPoint->y = aCursor.y + (pEvent->y - aHandle.y); +} + +static void lok_docview_class_init( gpointer ); +static void lok_docview_init( GTypeInstance *, gpointer ); +static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData); + +gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView) +{ + GdkPoint aPoint; + + if (pDocView->m_pImpl->m_bInDragMiddleHandle) + { + g_info("lcl_signalMotion: dragging the middle handle"); + LOKDocView_Impl::getDragPoint(&pDocView->m_pImpl->m_aHandleMiddleRect, pEvent, &aPoint); + pDocView->m_pImpl->m_pDocument->pClass->setTextSelection( + pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_RESET, + pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y)); + return FALSE; + } + if (pDocView->m_pImpl->m_bInDragStartHandle) + { + g_info("lcl_signalMotion: dragging the start handle"); + LOKDocView_Impl::getDragPoint(&pDocView->m_pImpl->m_aHandleStartRect, pEvent, &aPoint); + pDocView->m_pImpl->m_pDocument->pClass->setTextSelection( + pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_START, + pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y)); + return FALSE; + } + if (pDocView->m_pImpl->m_bInDragEndHandle) + { + g_info("lcl_signalMotion: dragging the end handle"); + LOKDocView_Impl::getDragPoint(&pDocView->m_pImpl->m_aHandleEndRect, pEvent, &aPoint); + pDocView->m_pImpl->m_pDocument->pClass->setTextSelection( + pDocView->m_pImpl->m_pDocument, LOK_SETTEXTSELECTION_END, + pDocView->m_pImpl->pixelToTwip(aPoint.x), pDocView->m_pImpl->pixelToTwip(aPoint.y)); + return FALSE; + } + for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i) + { + if (pDocView->m_pImpl->m_bInDragGraphicHandles[i]) + { + g_info("lcl_signalMotion: dragging the graphic handle #%d", i); + return FALSE; + } + } + if (pDocView->m_pImpl->m_bInDragGraphicSelection) + { + g_info("lcl_signalMotion: dragging the graphic selection"); + return FALSE; + } + + GdkRectangle aMotionInTwipsInTwips; + aMotionInTwipsInTwips.x = pDocView->m_pImpl->pixelToTwip(pEvent->x); + aMotionInTwipsInTwips.y = pDocView->m_pImpl->pixelToTwip(pEvent->y); + aMotionInTwipsInTwips.width = 1; + aMotionInTwipsInTwips.height = 1; + if (gdk_rectangle_intersect(&aMotionInTwipsInTwips, &pDocView->m_pImpl->m_aGraphicSelection, 0)) + { + g_info("lcl_signalMotion: start of drag graphic selection"); + pDocView->m_pImpl->m_bInDragGraphicSelection = true; + pDocView->m_pImpl->m_pDocument->pClass->setGraphicSelection( + pDocView->m_pImpl->m_pDocument, LOK_SETGRAPHICSELECTION_START, + pDocView->m_pImpl->pixelToTwip(pEvent->x), + pDocView->m_pImpl->pixelToTwip(pEvent->y)); + return FALSE; + } + + return FALSE; +} + SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type() { static guint lok_docview_type = 0; @@ -507,13 +507,13 @@ static void lok_docview_init( GTypeInstance* pInstance, gpointer ) gtk_scrolled_window_set_hadjustment( GTK_SCROLLED_WINDOW( pDocView ), NULL ); gtk_scrolled_window_set_vadjustment( GTK_SCROLLED_WINDOW( pDocView ), NULL ); - pDocView->m_pImpl = new LOKDocView_Impl(); + pDocView->m_pImpl = new LOKDocView_Impl(pDocView); gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView), pDocView->m_pImpl->m_pEventBox ); gtk_widget_set_events(pDocView->m_pImpl->m_pEventBox, GDK_BUTTON_PRESS_MASK); // So that drag doesn't try to move the whole window. - gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "button-press-event", GTK_SIGNAL_FUNC(lcl_signalButton), pDocView); - gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "button-release-event", GTK_SIGNAL_FUNC(lcl_signalButton), pDocView); + gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "button-press-event", GTK_SIGNAL_FUNC(LOKDocView_Impl::signalButton), pDocView); + gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "button-release-event", GTK_SIGNAL_FUNC(LOKDocView_Impl::signalButton), pDocView); gtk_signal_connect(GTK_OBJECT(pDocView->m_pImpl->m_pEventBox), "motion-notify-event", GTK_SIGNAL_FUNC(lcl_signalMotion), pDocView); gtk_widget_show( pDocView->m_pImpl->m_pEventBox ); commit d80aa56cb63532b2d4ad341a78e28806c7e292b3 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Wed Mar 25 17:54:11 2015 +0100 lokdocview: move keyboard handling to LOKDocView_Impl Change-Id: I1117ec42bdf0f2cb19f77723b87597d301d20ddb diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h index 1a5b932..bb8ae78 100644 --- a/include/LibreOfficeKit/LibreOfficeKitGtk.h +++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h @@ -68,6 +68,9 @@ gboolean lok_docview_get_edit (LOKDocView* pDocView); /// Posts the .uno: command to the LibreOfficeKit. void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand); + +/// Posts a keyboard event to LibreOfficeKit. +void lok_docview_post_key (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData); #ifdef __cplusplus } #endif diff --git a/libreofficekit/Executable_gtktiledviewer.mk b/libreofficekit/Executable_gtktiledviewer.mk index d57500c..47c6f96 100644 --- a/libreofficekit/Executable_gtktiledviewer.mk +++ b/libreofficekit/Executable_gtktiledviewer.mk @@ -14,8 +14,6 @@ $(eval $(call gb_Executable_set_include,gtktiledviewer,\ -I$(SRCDIR)/desktop/inc \ )) -$(eval $(call gb_Executable_use_sdk_api,gtktiledviewer)) - $(eval $(call gb_Executable_use_externals,gtktiledviewer,\ gtk \ )) diff --git a/libreofficekit/Library_libreofficekitgtk.mk b/libreofficekit/Library_libreofficekitgtk.mk index 01db40f..ff800d0 100644 --- a/libreofficekit/Library_libreofficekitgtk.mk +++ b/libreofficekit/Library_libreofficekitgtk.mk @@ -9,6 +9,7 @@ $(eval $(call gb_Library_Library,libreofficekitgtk)) +$(eval $(call gb_Library_use_sdk_api,libreofficekitgtk)) $(eval $(call gb_Library_use_externals,libreofficekitgtk,\ gtk \ diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx index 194ee41..9c1c7ed 100644 --- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx @@ -12,16 +12,12 @@ #include <string.h> #include <gdk/gdk.h> -#include <gdk/gdkkeysyms.h> #include <gtk/gtk.h> #include <LibreOfficeKit/LibreOfficeKitGtk.h> #include <LibreOfficeKit/LibreOfficeKitInit.h> #include <LibreOfficeKit/LibreOfficeKitEnums.h> -#include <com/sun/star/awt/Key.hpp> -#include <rsc/rsc-vcl-shared-types.hxx> - #ifndef g_info #define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__) #endif @@ -119,65 +115,6 @@ void toggleBold(GtkWidget* /*pButton*/, gpointer /*pItem*/) lok_docview_post_command(pLOKDocView, ".uno:Bold"); } -/// Receives a key press or release event. -static void signalKey(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pData*/) -{ - LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView); - int nCharCode = 0; - int nKeyCode = 0; - - if (!lok_docview_get_edit(pLOKDocView)) - { - g_info("signalKey: not in edit mode, ignore"); - return; - } - - switch (pEvent->keyval) - { - case GDK_BackSpace: - nKeyCode = com::sun::star::awt::Key::BACKSPACE; - break; - case GDK_Return: - nKeyCode = com::sun::star::awt::Key::RETURN; - break; - case GDK_Escape: - nKeyCode = com::sun::star::awt::Key::ESCAPE; - break; - case GDK_Tab: - nKeyCode = com::sun::star::awt::Key::TAB; - break; - case GDK_Down: - nKeyCode = com::sun::star::awt::Key::DOWN; - break; - case GDK_Up: - nKeyCode = com::sun::star::awt::Key::UP; - break; - case GDK_Left: - nKeyCode = com::sun::star::awt::Key::LEFT; - break; - case GDK_Right: - nKeyCode = com::sun::star::awt::Key::RIGHT; - break; - default: - if (pEvent->keyval >= GDK_F1 && pEvent->keyval <= GDK_F26) - nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_F1); - else - nCharCode = gdk_keyval_to_unicode(pEvent->keyval); - } - - // rsc is not public API, but should be good enough for debugging purposes. - // If this is needed for real, then probably a new param of type - // css::awt::KeyModifier is needed in postKeyEvent(). - if (pEvent->state & GDK_SHIFT_MASK) - nKeyCode |= KEY_SHIFT; - - LibreOfficeKitDocument* pDocument = lok_docview_get_document(pLOKDocView); - if (pEvent->type == GDK_KEY_RELEASE) - pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode); - else - pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode); -} - // GtkComboBox requires gtk 2.24 or later #if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2 void populatePartSelector() @@ -330,8 +267,8 @@ int main( int argc, char* argv[] ) g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL); // Input handling. - g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), NULL); - g_signal_connect(pWindow, "key-release-event", G_CALLBACK(signalKey), NULL); + g_signal_connect(pWindow, "key-press-event", G_CALLBACK(lok_docview_post_key), pDocView); + g_signal_connect(pWindow, "key-release-event", G_CALLBACK(lok_docview_post_key), pDocView); gtk_container_add( GTK_CONTAINER(pVBox), pDocView ); diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index fa44b1d..86a7e18 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -11,10 +11,14 @@ #include <math.h> #include <string.h> +#include <gdk/gdkkeysyms.h> + +#include <com/sun/star/awt/Key.hpp> #define LOK_USE_UNSTABLE_API #include <LibreOfficeKit/LibreOfficeKit.h> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <LibreOfficeKit/LibreOfficeKitGtk.h> +#include <rsc/rsc-vcl-shared-types.hxx> #if !GLIB_CHECK_VERSION(2,32,0) #define G_SOURCE_REMOVE FALSE @@ -104,6 +108,8 @@ struct LOKDocView_Impl float pixelToTwip(float fInput); /// Converts from document coordinates to screen pixels. float twipToPixel(float fInput); + /// Receives a key press or release event. + void signalKey(GdkEventKey* pEvent); }; LOKDocView_Impl::LOKDocView_Impl() @@ -166,6 +172,63 @@ float LOKDocView_Impl::twipToPixel(float fInput) return fInput / 1440.0f * DPI * m_fZoom; } +void LOKDocView_Impl::signalKey(GdkEventKey* pEvent) +{ + int nCharCode = 0; + int nKeyCode = 0; + + if (!m_bEdit) + { + g_info("signalKey: not in edit mode, ignore"); + return; + } + + switch (pEvent->keyval) + { + case GDK_BackSpace: + nKeyCode = com::sun::star::awt::Key::BACKSPACE; + break; + case GDK_Return: + nKeyCode = com::sun::star::awt::Key::RETURN; + break; + case GDK_Escape: + nKeyCode = com::sun::star::awt::Key::ESCAPE; + break; + case GDK_Tab: + nKeyCode = com::sun::star::awt::Key::TAB; + break; + case GDK_Down: + nKeyCode = com::sun::star::awt::Key::DOWN; + break; + case GDK_Up: + nKeyCode = com::sun::star::awt::Key::UP; + break; + case GDK_Left: + nKeyCode = com::sun::star::awt::Key::LEFT; + break; + case GDK_Right: + nKeyCode = com::sun::star::awt::Key::RIGHT; + break; + default: + if (pEvent->keyval >= GDK_F1 && pEvent->keyval <= GDK_F26) + nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_F1); + else + nCharCode = gdk_keyval_to_unicode(pEvent->keyval); + } + + // rsc is not public API, but should be good enough for debugging purposes. + // If this is needed for real, then probably a new param of type + // css::awt::KeyModifier is needed in postKeyEvent(). + if (pEvent->state & GDK_SHIFT_MASK) + nKeyCode |= KEY_SHIFT; + + if (pEvent->type == GDK_KEY_RELEASE) + m_pDocument->pClass->postKeyEvent(m_pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode); + else + m_pDocument->pClass->postKeyEvent(m_pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode); +} + + static void lok_docview_class_init( gpointer ); static void lok_docview_init( GTypeInstance *, gpointer ); static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData); @@ -1051,4 +1114,10 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const c pDocView->m_pImpl->m_pDocument->pClass->postUnoCommand(pDocView->m_pImpl->m_pDocument, pCommand); } +SAL_DLLPUBLIC_EXPORT void lok_docview_post_key(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer pData) +{ + LOKDocView* pDocView = static_cast<LOKDocView *>(pData); + pDocView->m_pImpl->signalKey(pEvent); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits