diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-03-25 18:19:11 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2015-03-30 09:23:49 +0200 |
commit | 9d76382efb4e89d2c9bcf43922e1a2527811a51a (patch) | |
tree | 946f2c4bc300f438a8b1173ba7e303c9e1fe4cdc /libreofficekit | |
parent | ffd4b87966a69ede188a5e15151c95f199558f27 (diff) |
lokdocview: move button handling to LOKDocView_Impl
Change-Id: Iac5d9e97f04af92ff6f6945d691abe94a3d785b0
Diffstat (limited to 'libreofficekit')
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 300 |
1 files changed, 150 insertions, 150 deletions
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 86a7e18d75b7..5793d7a6d88f 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 ); |