2014-06-12 17:38:10 +01:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sal/types.h>
|
2015-01-14 17:57:47 +01:00
|
|
|
#include <math.h>
|
2015-01-16 15:47:51 +01:00
|
|
|
#include <string.h>
|
2014-06-12 17:38:10 +01:00
|
|
|
|
|
|
|
#define LOK_USE_UNSTABLE_API
|
|
|
|
#include <LibreOfficeKit/LibreOfficeKit.h>
|
2015-02-20 16:21:06 +01:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
2014-06-12 17:38:10 +01:00
|
|
|
#include <LibreOfficeKit/LibreOfficeKitGtk.h>
|
|
|
|
|
2015-01-27 14:36:12 +01:00
|
|
|
#if !GLIB_CHECK_VERSION(2,32,0)
|
2015-01-12 11:58:18 +00:00
|
|
|
#define G_SOURCE_REMOVE FALSE
|
2015-01-27 14:36:12 +01:00
|
|
|
#define G_SOURCE_CONTINUE TRUE
|
2015-01-12 11:58:18 +00:00
|
|
|
#endif
|
2015-01-26 10:57:10 +01:00
|
|
|
#ifndef g_info
|
|
|
|
#define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
|
|
|
|
#endif
|
2015-01-12 11:58:18 +00:00
|
|
|
|
2015-02-09 14:22:01 +01:00
|
|
|
// Cursor bitmaps from the Android app.
|
|
|
|
#define CURSOR_HANDLE_DIR "android/experimental/LOAndroid3/res/drawable/"
|
2015-03-10 10:12:02 +01:00
|
|
|
// Number of handles around a graphic selection.
|
|
|
|
#define GRAPHIC_HANDLE_COUNT 8
|
2015-02-09 14:22:01 +01:00
|
|
|
|
2014-06-12 17:38:10 +01:00
|
|
|
static void lok_docview_class_init( LOKDocViewClass* pClass );
|
|
|
|
static void lok_docview_init( LOKDocView* pDocView );
|
2015-01-20 17:50:46 +01:00
|
|
|
static float pixelToTwip(float nInput);
|
2015-01-27 09:34:04 +01:00
|
|
|
static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData);
|
2014-06-12 17:38:10 +01:00
|
|
|
|
2014-06-24 21:13:42 +01:00
|
|
|
// We specifically need to destroy the document when closing in order to ensure
|
|
|
|
// that lock files etc. are cleaned up.
|
|
|
|
void lcl_onDestroy( LOKDocView* pDocView, gpointer pData )
|
|
|
|
{
|
|
|
|
(void) pData;
|
2014-06-26 11:14:50 +01:00
|
|
|
if ( pDocView->pDocument )
|
|
|
|
pDocView->pDocument->pClass->destroy( pDocView->pDocument );
|
|
|
|
pDocView->pDocument = NULL;
|
2014-06-24 21:13:42 +01:00
|
|
|
}
|
|
|
|
|
2015-02-10 18:19:32 +01:00
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-03-11 09:21:13 +01:00
|
|
|
gboolean lcl_signalMotion(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView)
|
2015-02-10 14:15:42 +01:00
|
|
|
{
|
2015-02-10 18:35:00 +01:00
|
|
|
GdkPoint aPoint;
|
|
|
|
|
2015-02-10 14:15:42 +01:00
|
|
|
if (pDocView->m_bInDragMiddleHandle)
|
|
|
|
{
|
|
|
|
g_info("lcl_signalMotion: dragging the middle handle");
|
2015-02-10 18:19:32 +01:00
|
|
|
lcl_getDragPoint(&pDocView->m_aHandleMiddleRect, pEvent, &aPoint);
|
2015-02-23 10:04:38 +00:00
|
|
|
pDocView->pDocument->pClass->setTextSelection(
|
|
|
|
pDocView->pDocument, LOK_SETTEXTSELECTION_RESET,
|
|
|
|
pixelToTwip(aPoint.x) / pDocView->fZoom, pixelToTwip(aPoint.y) / pDocView->fZoom);
|
2015-03-10 10:55:26 +01:00
|
|
|
return FALSE;
|
2015-02-10 14:15:42 +01:00
|
|
|
}
|
2015-03-10 10:55:26 +01:00
|
|
|
if (pDocView->m_bInDragStartHandle)
|
2015-02-10 18:35:00 +01:00
|
|
|
{
|
|
|
|
g_info("lcl_signalMotion: dragging the start handle");
|
|
|
|
lcl_getDragPoint(&pDocView->m_aHandleStartRect, pEvent, &aPoint);
|
2015-02-23 10:04:38 +00:00
|
|
|
pDocView->pDocument->pClass->setTextSelection(
|
|
|
|
pDocView->pDocument, LOK_SETTEXTSELECTION_START,
|
|
|
|
pixelToTwip(aPoint.x) / pDocView->fZoom, pixelToTwip(aPoint.y) / pDocView->fZoom);
|
2015-03-10 10:55:26 +01:00
|
|
|
return FALSE;
|
2015-02-10 18:35:00 +01:00
|
|
|
}
|
2015-03-10 10:55:26 +01:00
|
|
|
if (pDocView->m_bInDragEndHandle)
|
2015-02-10 18:19:32 +01:00
|
|
|
{
|
|
|
|
g_info("lcl_signalMotion: dragging the end handle");
|
|
|
|
lcl_getDragPoint(&pDocView->m_aHandleEndRect, pEvent, &aPoint);
|
2015-02-23 10:04:38 +00:00
|
|
|
pDocView->pDocument->pClass->setTextSelection(
|
|
|
|
pDocView->pDocument, LOK_SETTEXTSELECTION_END,
|
|
|
|
pixelToTwip(aPoint.x) / pDocView->fZoom, pixelToTwip(aPoint.y) / pDocView->fZoom);
|
2015-03-10 10:55:26 +01:00
|
|
|
return FALSE;
|
2015-02-10 18:19:32 +01:00
|
|
|
}
|
2015-03-11 09:21:13 +01:00
|
|
|
for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
|
2015-03-10 10:12:02 +01:00
|
|
|
{
|
2015-03-10 10:55:26 +01:00
|
|
|
if (pDocView->m_bInDragGraphicHandles[i])
|
2015-03-10 10:12:02 +01:00
|
|
|
{
|
2015-03-10 10:58:41 +01:00
|
|
|
g_info("lcl_signalMotion: dragging the graphic handle #%d", i);
|
2015-03-10 10:55:26 +01:00
|
|
|
return FALSE;
|
2015-03-10 10:12:02 +01:00
|
|
|
}
|
|
|
|
}
|
2015-03-10 10:58:41 +01:00
|
|
|
if (pDocView->m_bInDragGraphicSelection)
|
|
|
|
{
|
|
|
|
g_info("lcl_signalMotion: dragging the graphic selection");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-10 14:15:42 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-20 10:20:24 +01:00
|
|
|
/// Receives a button press event.
|
2015-03-11 09:21:13 +01:00
|
|
|
gboolean lcl_signalButton(GtkWidget* /*pEventBox*/, GdkEventButton* pEvent, LOKDocView* pDocView)
|
2015-01-20 10:20:24 +01:00
|
|
|
{
|
2015-01-20 17:50:46 +01:00
|
|
|
g_info("lcl_signalButton: %d, %d (in twips: %d, %d)", (int)pEvent->x, (int)pEvent->y, (int)pixelToTwip(pEvent->x), (int)pixelToTwip(pEvent->y));
|
2015-01-20 10:20:24 +01:00
|
|
|
|
2015-02-10 18:35:00 +01:00
|
|
|
if (pEvent->type == GDK_BUTTON_RELEASE)
|
2015-02-10 18:19:32 +01:00
|
|
|
{
|
2015-02-10 18:35:00 +01:00
|
|
|
if (pDocView->m_bInDragStartHandle)
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: end of drag start handle");
|
|
|
|
pDocView->m_bInDragStartHandle = FALSE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (pDocView->m_bInDragMiddleHandle)
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: end of drag middle handle");
|
|
|
|
pDocView->m_bInDragMiddleHandle = FALSE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (pDocView->m_bInDragEndHandle)
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: end of drag end handle");
|
|
|
|
pDocView->m_bInDragEndHandle = FALSE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-03-10 10:12:02 +01:00
|
|
|
|
2015-03-11 09:21:13 +01:00
|
|
|
for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
|
2015-03-10 10:12:02 +01:00
|
|
|
{
|
|
|
|
if (pDocView->m_bInDragGraphicHandles[i])
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: end of drag graphic handle #%d", i);
|
|
|
|
pDocView->m_bInDragGraphicHandles[i] = FALSE;
|
|
|
|
pDocView->pDocument->pClass->setGraphicSelection(
|
|
|
|
pDocView->pDocument, LOK_SETGRAPHICSELECTION_END,
|
|
|
|
pixelToTwip(pEvent->x) / pDocView->fZoom, pixelToTwip(pEvent->y) / pDocView->fZoom);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2015-03-10 10:53:28 +01:00
|
|
|
|
|
|
|
if (pDocView->m_bInDragGraphicSelection)
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: end of drag graphic selection");
|
|
|
|
pDocView->m_bInDragGraphicSelection = FALSE;
|
|
|
|
pDocView->pDocument->pClass->setGraphicSelection(
|
|
|
|
pDocView->pDocument, LOK_SETGRAPHICSELECTION_END,
|
|
|
|
pixelToTwip(pEvent->x) / pDocView->fZoom,
|
|
|
|
pixelToTwip(pEvent->y) / pDocView->fZoom);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-10 18:19:32 +01:00
|
|
|
}
|
2015-02-10 14:15:42 +01:00
|
|
|
|
|
|
|
if (pDocView->m_bEdit)
|
|
|
|
{
|
|
|
|
GdkRectangle aClick;
|
|
|
|
aClick.x = pEvent->x;
|
|
|
|
aClick.y = pEvent->y;
|
|
|
|
aClick.width = 1;
|
|
|
|
aClick.height = 1;
|
2015-02-10 18:35:00 +01:00
|
|
|
if (pEvent->type == GDK_BUTTON_PRESS)
|
2015-02-10 14:15:42 +01:00
|
|
|
{
|
2015-03-10 10:53:28 +01:00
|
|
|
GdkRectangle aClickInTwips;
|
2015-03-10 10:12:02 +01:00
|
|
|
|
2015-02-10 18:35:00 +01:00
|
|
|
if (gdk_rectangle_intersect(&aClick, &pDocView->m_aHandleStartRect, NULL))
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: start of drag start handle");
|
|
|
|
pDocView->m_bInDragStartHandle = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (gdk_rectangle_intersect(&aClick, &pDocView->m_aHandleMiddleRect, NULL))
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: start of drag middle handle");
|
|
|
|
pDocView->m_bInDragMiddleHandle = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else if (gdk_rectangle_intersect(&aClick, &pDocView->m_aHandleEndRect, NULL))
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: start of drag end handle");
|
|
|
|
pDocView->m_bInDragEndHandle = TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-03-10 10:12:02 +01:00
|
|
|
|
2015-03-11 09:21:13 +01:00
|
|
|
for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
|
2015-03-10 10:12:02 +01:00
|
|
|
{
|
|
|
|
if (gdk_rectangle_intersect(&aClick, &pDocView->m_aGraphicHandleRects[i], NULL))
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: start of drag graphic handle #%d", i);
|
|
|
|
pDocView->m_bInDragGraphicHandles[i] = TRUE;
|
|
|
|
pDocView->pDocument->pClass->setGraphicSelection(
|
|
|
|
pDocView->pDocument, LOK_SETGRAPHICSELECTION_START,
|
|
|
|
pixelToTwip(pDocView->m_aGraphicHandleRects[i].x + pDocView->m_aGraphicHandleRects[i].width / 2) / pDocView->fZoom,
|
|
|
|
pixelToTwip(pDocView->m_aGraphicHandleRects[i].y + pDocView->m_aGraphicHandleRects[i].height / 2) / pDocView->fZoom);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2015-03-10 10:53:28 +01:00
|
|
|
|
|
|
|
aClickInTwips.x = pixelToTwip(pEvent->x) / pDocView->fZoom;
|
|
|
|
aClickInTwips.y = pixelToTwip(pEvent->y) / pDocView->fZoom;
|
|
|
|
aClickInTwips.width = 1;
|
|
|
|
aClickInTwips.height = 1;
|
|
|
|
if (gdk_rectangle_intersect(&aClickInTwips, &pDocView->m_aGraphicSelection, NULL))
|
|
|
|
{
|
|
|
|
g_info("lcl_signalButton: start of drag graphic selection");
|
|
|
|
pDocView->m_bInDragGraphicSelection = TRUE;
|
|
|
|
pDocView->pDocument->pClass->setGraphicSelection(
|
|
|
|
pDocView->pDocument, LOK_SETGRAPHICSELECTION_START,
|
|
|
|
pixelToTwip(pEvent->x) / pDocView->fZoom,
|
|
|
|
pixelToTwip(pEvent->y) / pDocView->fZoom);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-02-10 18:19:32 +01:00
|
|
|
}
|
2015-02-10 14:15:42 +01:00
|
|
|
}
|
|
|
|
|
2015-03-10 12:50:59 +01:00
|
|
|
if (!pDocView->m_bEdit)
|
|
|
|
lok_docview_set_edit(pDocView, TRUE);
|
2015-01-20 10:20:24 +01:00
|
|
|
|
|
|
|
switch (pEvent->type)
|
|
|
|
{
|
|
|
|
case GDK_BUTTON_PRESS:
|
2015-02-05 14:19:35 +01:00
|
|
|
{
|
|
|
|
int nCount = 1;
|
|
|
|
if ((pEvent->time - pDocView->m_nLastButtonPressTime) < 250)
|
|
|
|
nCount++;
|
|
|
|
pDocView->m_nLastButtonPressTime = pEvent->time;
|
2015-02-23 10:04:38 +00:00
|
|
|
pDocView->pDocument->pClass->postMouseEvent(
|
|
|
|
pDocView->pDocument, LOK_MOUSEEVENT_MOUSEBUTTONDOWN,
|
|
|
|
pixelToTwip(pEvent->x) / pDocView->fZoom,
|
|
|
|
pixelToTwip(pEvent->y) / pDocView->fZoom, nCount);
|
2015-01-20 10:20:24 +01:00
|
|
|
break;
|
2015-02-05 14:19:35 +01:00
|
|
|
}
|
2015-01-20 10:20:24 +01:00
|
|
|
case GDK_BUTTON_RELEASE:
|
2015-02-05 14:19:35 +01:00
|
|
|
{
|
|
|
|
int nCount = 1;
|
|
|
|
if ((pEvent->time - pDocView->m_nLastButtonReleaseTime) < 250)
|
|
|
|
nCount++;
|
|
|
|
pDocView->m_nLastButtonReleaseTime = pEvent->time;
|
2015-02-23 10:04:38 +00:00
|
|
|
pDocView->pDocument->pClass->postMouseEvent(
|
|
|
|
pDocView->pDocument, LOK_MOUSEEVENT_MOUSEBUTTONUP,
|
|
|
|
pixelToTwip(pEvent->x) / pDocView->fZoom,
|
|
|
|
pixelToTwip(pEvent->y) / pDocView->fZoom, nCount);
|
2015-01-20 10:20:24 +01:00
|
|
|
break;
|
2015-02-05 14:19:35 +01:00
|
|
|
}
|
2015-01-20 10:20:24 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-02-10 14:15:42 +01:00
|
|
|
return FALSE;
|
2015-01-20 10:20:24 +01:00
|
|
|
}
|
|
|
|
|
2014-06-12 17:38:10 +01:00
|
|
|
SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
|
|
|
|
{
|
|
|
|
static guint lok_docview_type = 0;
|
|
|
|
|
|
|
|
if (!lok_docview_type)
|
|
|
|
{
|
2015-03-10 16:42:10 +01:00
|
|
|
char pName[] = "LokDocView";
|
2014-06-12 17:38:10 +01:00
|
|
|
GtkTypeInfo lok_docview_info =
|
|
|
|
{
|
2015-03-10 16:42:10 +01:00
|
|
|
pName,
|
2014-06-12 17:38:10 +01:00
|
|
|
sizeof( LOKDocView ),
|
|
|
|
sizeof( LOKDocViewClass ),
|
|
|
|
(GtkClassInitFunc) lok_docview_class_init,
|
|
|
|
(GtkObjectInitFunc) lok_docview_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
(GtkClassInitFunc) NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
lok_docview_type = gtk_type_unique( gtk_scrolled_window_get_type(), &lok_docview_info );
|
|
|
|
}
|
|
|
|
return lok_docview_type;
|
|
|
|
}
|
|
|
|
|
2015-03-10 12:50:59 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
EDIT_CHANGED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint docview_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2014-06-12 17:38:10 +01:00
|
|
|
static void lok_docview_class_init( LOKDocViewClass* pClass )
|
|
|
|
{
|
2015-03-10 12:50:59 +01:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS(pClass);
|
|
|
|
pClass->edit_changed = NULL;
|
|
|
|
docview_signals[EDIT_CHANGED] =
|
|
|
|
g_signal_new("edit-changed",
|
|
|
|
G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (LOKDocViewClass, edit_changed),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__BOOLEAN,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
G_TYPE_BOOLEAN);
|
2014-06-12 17:38:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void lok_docview_init( LOKDocView* pDocView )
|
|
|
|
{
|
2014-06-13 11:21:38 +01:00
|
|
|
// Gtk ScrolledWindow is apparently not fully initialised yet, we specifically
|
|
|
|
// have to set the [hv]adjustment to prevent GTK assertions from firing, see
|
|
|
|
// https://bugzilla.gnome.org/show_bug.cgi?id=438114 for more info.
|
|
|
|
gtk_scrolled_window_set_hadjustment( GTK_SCROLLED_WINDOW( pDocView ), NULL );
|
|
|
|
gtk_scrolled_window_set_vadjustment( GTK_SCROLLED_WINDOW( pDocView ), NULL );
|
|
|
|
|
2014-06-12 17:38:10 +01:00
|
|
|
pDocView->pEventBox = gtk_event_box_new();
|
|
|
|
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(pDocView),
|
|
|
|
pDocView->pEventBox );
|
|
|
|
|
2015-02-10 14:15:42 +01:00
|
|
|
gtk_widget_set_events(pDocView->pEventBox, GDK_BUTTON_PRESS_MASK); // So that drag doesn't try to move the whole window.
|
2015-01-20 10:20:24 +01:00
|
|
|
gtk_signal_connect(GTK_OBJECT(pDocView->pEventBox), "button-press-event", GTK_SIGNAL_FUNC(lcl_signalButton), pDocView);
|
|
|
|
gtk_signal_connect(GTK_OBJECT(pDocView->pEventBox), "button-release-event", GTK_SIGNAL_FUNC(lcl_signalButton), pDocView);
|
2015-02-10 14:15:42 +01:00
|
|
|
gtk_signal_connect(GTK_OBJECT(pDocView->pEventBox), "motion-notify-event", GTK_SIGNAL_FUNC(lcl_signalMotion), pDocView);
|
2015-01-13 16:47:23 +01:00
|
|
|
|
2014-06-12 17:38:10 +01:00
|
|
|
gtk_widget_show( pDocView->pEventBox );
|
|
|
|
|
2015-01-14 17:57:47 +01:00
|
|
|
pDocView->pTable = 0;
|
|
|
|
pDocView->pCanvas = 0;
|
2014-06-12 17:38:10 +01:00
|
|
|
|
|
|
|
// TODO: figure out a clever view of getting paths set up.
|
|
|
|
pDocView->pOffice = 0;
|
|
|
|
pDocView->pDocument = 0;
|
2014-06-23 15:13:25 +01:00
|
|
|
|
|
|
|
pDocView->fZoom = 1;
|
2015-01-13 16:47:23 +01:00
|
|
|
pDocView->m_bEdit = FALSE;
|
2015-01-27 09:34:04 +01:00
|
|
|
memset(&pDocView->m_aVisibleCursor, 0, sizeof(pDocView->m_aVisibleCursor));
|
2015-03-04 10:03:49 +01:00
|
|
|
pDocView->m_bCursorOverlayVisible = FALSE;
|
2015-03-06 11:02:40 +01:00
|
|
|
pDocView->m_bCursorVisible = TRUE;
|
2015-02-05 14:19:35 +01:00
|
|
|
pDocView->m_nLastButtonPressTime = 0;
|
|
|
|
pDocView->m_nLastButtonReleaseTime = 0;
|
2015-02-06 12:12:44 +01:00
|
|
|
pDocView->m_pTextSelectionRectangles = NULL;
|
2015-02-10 11:10:50 +01:00
|
|
|
memset(&pDocView->m_aTextSelectionStart, 0, sizeof(pDocView->m_aTextSelectionStart));
|
|
|
|
memset(&pDocView->m_aTextSelectionEnd, 0, sizeof(pDocView->m_aTextSelectionEnd));
|
2015-03-05 11:57:25 +01:00
|
|
|
memset(&pDocView->m_aGraphicSelection, 0, sizeof(pDocView->m_aGraphicSelection));
|
2015-03-10 10:53:28 +01:00
|
|
|
pDocView->m_bInDragGraphicSelection = FALSE;
|
2015-02-10 18:35:00 +01:00
|
|
|
|
|
|
|
// Start/middle/end handle.
|
2015-02-10 11:41:59 +01:00
|
|
|
pDocView->m_pHandleStart = NULL;
|
2015-02-10 18:35:00 +01:00
|
|
|
memset(&pDocView->m_aHandleStartRect, 0, sizeof(pDocView->m_aHandleStartRect));
|
|
|
|
pDocView->m_bInDragStartHandle = FALSE;
|
2015-02-10 11:41:59 +01:00
|
|
|
pDocView->m_pHandleMiddle = NULL;
|
2015-02-10 14:15:42 +01:00
|
|
|
memset(&pDocView->m_aHandleMiddleRect, 0, sizeof(pDocView->m_aHandleMiddleRect));
|
|
|
|
pDocView->m_bInDragMiddleHandle = FALSE;
|
2015-02-10 18:35:00 +01:00
|
|
|
pDocView->m_pHandleEnd = NULL;
|
2015-02-10 18:19:32 +01:00
|
|
|
memset(&pDocView->m_aHandleEndRect, 0, sizeof(pDocView->m_aHandleEndRect));
|
|
|
|
pDocView->m_bInDragEndHandle = FALSE;
|
2014-06-24 21:13:42 +01:00
|
|
|
|
2015-03-05 14:15:54 +01:00
|
|
|
pDocView->m_pGraphicHandle = NULL;
|
2015-03-10 10:12:02 +01:00
|
|
|
memset(&pDocView->m_aGraphicHandleRects, 0, sizeof(pDocView->m_aGraphicHandleRects));
|
|
|
|
memset(&pDocView->m_bInDragGraphicHandles, 0, sizeof(pDocView->m_bInDragGraphicHandles));
|
2015-03-05 14:15:54 +01:00
|
|
|
|
2014-06-24 21:13:42 +01:00
|
|
|
gtk_signal_connect( GTK_OBJECT(pDocView), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC(lcl_onDestroy), NULL );
|
2015-01-27 09:34:04 +01:00
|
|
|
g_signal_connect_after(pDocView->pEventBox, "expose-event",
|
|
|
|
G_CALLBACK(renderOverlay), pDocView);
|
2014-06-12 17:38:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SAL_DLLPUBLIC_EXPORT GtkWidget* lok_docview_new( LibreOfficeKit* pOffice )
|
|
|
|
{
|
2015-03-10 16:42:10 +01:00
|
|
|
LOKDocView* pDocView = LOK_DOCVIEW(gtk_type_new(lok_docview_get_type()));
|
2014-06-12 17:38:10 +01:00
|
|
|
pDocView->pOffice = pOffice;
|
|
|
|
return GTK_WIDGET( pDocView );
|
|
|
|
}
|
|
|
|
|
2015-03-08 11:23:03 +01:00
|
|
|
// We know that VirtualDevices use a DPI of 96.
|
2015-01-14 14:37:20 +01:00
|
|
|
static const int g_nDPI = 96;
|
|
|
|
|
|
|
|
/// Converts from document coordinates to screen pixels.
|
|
|
|
static float twipToPixel(float nInput)
|
|
|
|
{
|
|
|
|
return nInput / 1440.0f * g_nDPI;
|
|
|
|
}
|
|
|
|
|
2015-01-14 17:57:47 +01:00
|
|
|
/// Converts from screen pixels to document coordinates
|
|
|
|
static float pixelToTwip(float nInput)
|
2014-06-12 17:38:10 +01:00
|
|
|
{
|
2015-01-14 17:57:47 +01:00
|
|
|
return (nInput / g_nDPI) * 1440.0f;
|
|
|
|
}
|
2014-06-25 14:46:57 +01:00
|
|
|
|
2015-01-27 09:34:04 +01:00
|
|
|
static gboolean lcl_isEmptyRectangle(GdkRectangle* pRectangle)
|
|
|
|
{
|
|
|
|
return pRectangle->x == 0 && pRectangle->y == 0 && pRectangle->width == 0 && pRectangle->height == 0;
|
|
|
|
}
|
|
|
|
|
2015-01-27 14:36:12 +01:00
|
|
|
/// Takes care of the blinking cursor.
|
|
|
|
static gboolean lcl_handleTimeout(gpointer pData)
|
|
|
|
{
|
2015-03-10 16:42:10 +01:00
|
|
|
LOKDocView* pDocView = LOK_DOCVIEW(pData);
|
2015-01-27 14:36:12 +01:00
|
|
|
|
|
|
|
if (pDocView->m_bEdit)
|
|
|
|
{
|
2015-03-04 10:03:49 +01:00
|
|
|
if (pDocView->m_bCursorOverlayVisible)
|
|
|
|
pDocView->m_bCursorOverlayVisible = FALSE;
|
2015-01-27 14:36:12 +01:00
|
|
|
else
|
2015-03-04 10:03:49 +01:00
|
|
|
pDocView->m_bCursorOverlayVisible = TRUE;
|
2015-01-27 14:36:12 +01:00
|
|
|
gtk_widget_queue_draw(GTK_WIDGET(pDocView->pEventBox));
|
|
|
|
}
|
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
}
|
|
|
|
|
2015-02-10 11:10:50 +01:00
|
|
|
/// Renders pHandle below a pCursor rectangle on pCairo.
|
2015-02-23 10:04:38 +00:00
|
|
|
static void lcl_renderHandle(cairo_t* pCairo, GdkRectangle* pCursor, cairo_surface_t* pHandle,
|
|
|
|
GdkRectangle* pRectangle, float fZoom)
|
2015-02-10 11:10:50 +01:00
|
|
|
{
|
|
|
|
GdkPoint aCursorBottom;
|
|
|
|
int nHandleWidth, nHandleHeight;
|
|
|
|
double fHandleScale;
|
|
|
|
|
|
|
|
nHandleWidth = cairo_image_surface_get_width(pHandle);
|
|
|
|
nHandleHeight = cairo_image_surface_get_height(pHandle);
|
|
|
|
// We want to scale down the handle, so that its height is the same as the cursor caret.
|
2015-02-23 10:04:38 +00:00
|
|
|
fHandleScale = twipToPixel(pCursor->height) * fZoom / nHandleHeight;
|
2015-02-10 11:10:50 +01:00
|
|
|
// We want the top center of the handle bitmap to be at the bottom center of the cursor rectangle.
|
2015-02-23 10:04:38 +00:00
|
|
|
aCursorBottom.x = twipToPixel(pCursor->x) * fZoom + twipToPixel(pCursor->width) * fZoom / 2 - (nHandleWidth * fHandleScale) / 2;
|
|
|
|
aCursorBottom.y = twipToPixel(pCursor->y) * fZoom + twipToPixel(pCursor->height) * fZoom;
|
2015-02-10 11:10:50 +01:00
|
|
|
cairo_save(pCairo);
|
|
|
|
cairo_translate(pCairo, aCursorBottom.x, aCursorBottom.y);
|
|
|
|
cairo_scale(pCairo, fHandleScale, fHandleScale);
|
|
|
|
cairo_set_source_surface(pCairo, pHandle, 0, 0);
|
|
|
|
cairo_paint(pCairo);
|
|
|
|
cairo_restore(pCairo);
|
2015-02-10 14:15:42 +01:00
|
|
|
|
|
|
|
if (pRectangle)
|
|
|
|
{
|
|
|
|
// Return the rectangle that contains the rendered handle.
|
|
|
|
pRectangle->x = aCursorBottom.x;
|
|
|
|
pRectangle->y = aCursorBottom.y;
|
|
|
|
pRectangle->width = nHandleWidth * fHandleScale;
|
|
|
|
pRectangle->height = nHandleHeight * fHandleScale;
|
|
|
|
}
|
2015-02-10 11:10:50 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 14:15:54 +01:00
|
|
|
/// Renders pHandle around a pSelection rectangle on pCairo.
|
2015-03-10 10:12:02 +01:00
|
|
|
static void lcl_renderGraphicHandle(cairo_t* pCairo, GdkRectangle* pSelection, cairo_surface_t* pHandle, GdkRectangle* pGraphicHandleRects, float fZoom)
|
2015-03-05 14:15:54 +01:00
|
|
|
{
|
|
|
|
int nHandleWidth, nHandleHeight;
|
|
|
|
GdkRectangle aSelection;
|
|
|
|
|
|
|
|
nHandleWidth = cairo_image_surface_get_width(pHandle);
|
|
|
|
nHandleHeight = cairo_image_surface_get_height(pHandle);
|
|
|
|
|
|
|
|
aSelection.x = twipToPixel(pSelection->x) * fZoom;
|
|
|
|
aSelection.y = twipToPixel(pSelection->y) * fZoom;
|
|
|
|
aSelection.width = twipToPixel(pSelection->width) * fZoom;
|
|
|
|
aSelection.height = twipToPixel(pSelection->height) * fZoom;
|
|
|
|
|
2015-03-11 09:21:13 +01:00
|
|
|
for (int i = 0; i < GRAPHIC_HANDLE_COUNT; ++i)
|
2015-03-05 14:15:54 +01:00
|
|
|
{
|
|
|
|
int x = aSelection.x, y = aSelection.y;
|
|
|
|
cairo_save(pCairo);
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0: // top-left
|
|
|
|
break;
|
|
|
|
case 1: // top-middle
|
|
|
|
x += aSelection.width / 2;
|
|
|
|
break;
|
|
|
|
case 2: // top-right
|
|
|
|
x += aSelection.width;
|
|
|
|
break;
|
|
|
|
case 3: // middle-left
|
|
|
|
y += aSelection.height / 2;
|
|
|
|
break;
|
|
|
|
case 4: // middle-right
|
|
|
|
x += aSelection.width;
|
|
|
|
y += aSelection.height / 2;
|
|
|
|
break;
|
|
|
|
case 5: // bottom-left
|
|
|
|
y += aSelection.height;
|
|
|
|
break;
|
|
|
|
case 6: // bottom-middle
|
|
|
|
x += aSelection.width / 2;
|
|
|
|
y += aSelection.height;
|
|
|
|
break;
|
|
|
|
case 7: // bottom-right
|
|
|
|
x += aSelection.width;
|
|
|
|
y += aSelection.height;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Center the handle.
|
|
|
|
x -= nHandleWidth / 2;
|
|
|
|
y -= nHandleHeight / 2;
|
|
|
|
|
2015-03-10 10:12:02 +01:00
|
|
|
pGraphicHandleRects[i].x = x;
|
|
|
|
pGraphicHandleRects[i].y = y;
|
|
|
|
pGraphicHandleRects[i].width = nHandleWidth;
|
|
|
|
pGraphicHandleRects[i].height = nHandleHeight;
|
|
|
|
|
2015-03-05 14:15:54 +01:00
|
|
|
cairo_translate(pCairo, x, y);
|
|
|
|
cairo_set_source_surface(pCairo, pHandle, 0, 0);
|
|
|
|
cairo_paint(pCairo);
|
|
|
|
cairo_restore(pCairo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-11 09:21:13 +01:00
|
|
|
static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* /*pEvent*/, gpointer pData)
|
2015-01-27 09:34:04 +01:00
|
|
|
{
|
2015-02-09 08:02:46 +01:00
|
|
|
#if GTK_CHECK_VERSION(2,14,0) // we need gtk_widget_get_window()
|
2015-03-10 16:42:10 +01:00
|
|
|
LOKDocView* pDocView = LOK_DOCVIEW(pData);
|
2015-01-27 09:34:04 +01:00
|
|
|
cairo_t* pCairo;
|
|
|
|
|
|
|
|
pCairo = gdk_cairo_create(gtk_widget_get_window(pWidget));
|
|
|
|
|
2015-03-10 11:24:11 +01:00
|
|
|
if (pDocView->m_bEdit && pDocView->m_bCursorVisible && pDocView->m_bCursorOverlayVisible && !lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor))
|
2015-01-27 09:34:04 +01:00
|
|
|
{
|
2015-03-12 15:18:00 +01:00
|
|
|
if (pDocView->m_aVisibleCursor.width < 30)
|
2015-01-27 09:34:04 +01:00
|
|
|
// Set a minimal width if it would be 0.
|
|
|
|
pDocView->m_aVisibleCursor.width = 30;
|
|
|
|
|
|
|
|
cairo_set_source_rgb(pCairo, 0, 0, 0);
|
|
|
|
cairo_rectangle(pCairo,
|
2015-02-23 10:04:38 +00:00
|
|
|
twipToPixel(pDocView->m_aVisibleCursor.x) * pDocView->fZoom,
|
|
|
|
twipToPixel(pDocView->m_aVisibleCursor.y) * pDocView->fZoom,
|
|
|
|
twipToPixel(pDocView->m_aVisibleCursor.width) * pDocView->fZoom,
|
|
|
|
twipToPixel(pDocView->m_aVisibleCursor.height) * pDocView->fZoom);
|
2015-01-27 09:34:04 +01:00
|
|
|
cairo_fill(pCairo);
|
2015-02-09 14:22:01 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-10 11:24:11 +01:00
|
|
|
if (pDocView->m_bEdit && pDocView->m_bCursorVisible && !lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor) && !pDocView->m_pTextSelectionRectangles)
|
2015-02-09 14:22:01 +01:00
|
|
|
{
|
|
|
|
// Have a cursor, but no selection: we need the middle handle.
|
2015-02-10 11:41:59 +01:00
|
|
|
if (!pDocView->m_pHandleMiddle)
|
|
|
|
pDocView->m_pHandleMiddle = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_middle.png");
|
2015-02-23 10:04:38 +00:00
|
|
|
lcl_renderHandle(pCairo, &pDocView->m_aVisibleCursor,
|
|
|
|
pDocView->m_pHandleMiddle, &pDocView->m_aHandleMiddleRect,
|
|
|
|
pDocView->fZoom);
|
2015-01-27 09:34:04 +01:00
|
|
|
}
|
|
|
|
|
2015-02-06 12:12:44 +01:00
|
|
|
if (pDocView->m_pTextSelectionRectangles)
|
|
|
|
{
|
2015-03-11 09:21:13 +01:00
|
|
|
for (GList* i = pDocView->m_pTextSelectionRectangles; i != NULL; i = i->next)
|
2015-02-06 12:12:44 +01:00
|
|
|
{
|
2015-03-10 16:42:10 +01:00
|
|
|
GdkRectangle* pRectangle = static_cast<GdkRectangle*>(i->data);
|
2015-02-06 12:12:44 +01:00
|
|
|
// Blue with 75% transparency.
|
|
|
|
cairo_set_source_rgba(pCairo, ((double)0x43)/255, ((double)0xac)/255, ((double)0xe8)/255, 0.25);
|
2015-02-23 10:04:38 +00:00
|
|
|
cairo_rectangle(pCairo,
|
|
|
|
twipToPixel(pRectangle->x) * pDocView->fZoom,
|
|
|
|
twipToPixel(pRectangle->y) * pDocView->fZoom,
|
|
|
|
twipToPixel(pRectangle->width) * pDocView->fZoom,
|
|
|
|
twipToPixel(pRectangle->height) * pDocView->fZoom);
|
2015-02-06 12:12:44 +01:00
|
|
|
cairo_fill(pCairo);
|
|
|
|
}
|
2015-02-10 11:10:50 +01:00
|
|
|
|
|
|
|
// Handles
|
|
|
|
if (!lcl_isEmptyRectangle(&pDocView->m_aTextSelectionStart))
|
|
|
|
{
|
|
|
|
// Have a start position: we need a start handle.
|
2015-02-10 11:41:59 +01:00
|
|
|
if (!pDocView->m_pHandleStart)
|
|
|
|
pDocView->m_pHandleStart = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_start.png");
|
2015-02-23 10:04:38 +00:00
|
|
|
lcl_renderHandle(pCairo, &pDocView->m_aTextSelectionStart,
|
|
|
|
pDocView->m_pHandleStart, &pDocView->m_aHandleStartRect,
|
|
|
|
pDocView->fZoom);
|
2015-02-10 11:10:50 +01:00
|
|
|
}
|
|
|
|
if (!lcl_isEmptyRectangle(&pDocView->m_aTextSelectionEnd))
|
|
|
|
{
|
|
|
|
// Have a start position: we need an end handle.
|
2015-02-10 11:41:59 +01:00
|
|
|
if (!pDocView->m_pHandleEnd)
|
|
|
|
pDocView->m_pHandleEnd = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_end.png");
|
2015-02-23 10:04:38 +00:00
|
|
|
lcl_renderHandle(pCairo, &pDocView->m_aTextSelectionEnd,
|
|
|
|
pDocView->m_pHandleEnd, &pDocView->m_aHandleEndRect,
|
|
|
|
pDocView->fZoom);
|
2015-02-10 11:10:50 +01:00
|
|
|
}
|
2015-02-06 12:12:44 +01:00
|
|
|
}
|
|
|
|
|
2015-03-05 11:57:25 +01:00
|
|
|
if (!lcl_isEmptyRectangle(&pDocView->m_aGraphicSelection))
|
|
|
|
{
|
2015-03-05 14:15:54 +01:00
|
|
|
if (!pDocView->m_pGraphicHandle)
|
|
|
|
pDocView->m_pGraphicHandle = cairo_image_surface_create_from_png(CURSOR_HANDLE_DIR "handle_graphic.png");
|
2015-03-10 10:12:02 +01:00
|
|
|
lcl_renderGraphicHandle(pCairo, &pDocView->m_aGraphicSelection, pDocView->m_pGraphicHandle, pDocView->m_aGraphicHandleRects, pDocView->fZoom);
|
2015-03-05 11:57:25 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 09:34:04 +01:00
|
|
|
cairo_destroy(pCairo);
|
2015-02-09 08:02:46 +01:00
|
|
|
#endif
|
2015-01-27 09:34:04 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-01-16 15:47:51 +01:00
|
|
|
void renderDocument(LOKDocView* pDocView, GdkRectangle* pPartial)
|
2015-01-14 17:57:47 +01:00
|
|
|
{
|
|
|
|
const int nTileSizePixels = 256;
|
2014-06-12 17:38:10 +01:00
|
|
|
|
2015-01-14 17:57:47 +01:00
|
|
|
// Get document size and find out how many rows / columns we need.
|
2015-03-11 09:21:13 +01:00
|
|
|
long nDocumentWidthTwips, nDocumentHeightTwips;
|
2015-01-14 17:57:47 +01:00
|
|
|
pDocView->pDocument->pClass->getDocumentSize(pDocView->pDocument, &nDocumentWidthTwips, &nDocumentHeightTwips);
|
2015-03-11 09:21:13 +01:00
|
|
|
long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips) * pDocView->fZoom;
|
|
|
|
long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips) * pDocView->fZoom;
|
|
|
|
// Total number of rows / columns in this document.
|
|
|
|
guint nRows = ceil((double)nDocumentHeightPixels / nTileSizePixels);
|
|
|
|
guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
|
2015-01-14 17:57:47 +01:00
|
|
|
|
|
|
|
// Set up our table and the tile pointers.
|
2015-01-16 15:47:51 +01:00
|
|
|
if (!pDocView->pTable)
|
|
|
|
pPartial = NULL;
|
|
|
|
if (pPartial)
|
|
|
|
{
|
|
|
|
// Same as nRows / nColumns, but from the previous renderDocument() call.
|
|
|
|
guint nOldRows, nOldColumns;
|
|
|
|
|
2015-01-26 14:08:45 +01:00
|
|
|
#if GTK_CHECK_VERSION(2,22,0)
|
2015-01-16 15:47:51 +01:00
|
|
|
gtk_table_get_size(GTK_TABLE(pDocView->pTable), &nOldRows, &nOldColumns);
|
|
|
|
if (nOldRows != nRows || nOldColumns != nColumns)
|
|
|
|
// Can't do partial rendering, document size changed.
|
|
|
|
pPartial = NULL;
|
2015-01-26 14:08:45 +01:00
|
|
|
#else
|
|
|
|
pPartial = NULL;
|
|
|
|
#endif
|
2015-01-16 15:47:51 +01:00
|
|
|
}
|
|
|
|
if (!pPartial)
|
|
|
|
{
|
|
|
|
if (pDocView->pTable)
|
|
|
|
gtk_container_remove(GTK_CONTAINER(pDocView->pEventBox), pDocView->pTable);
|
|
|
|
pDocView->pTable = gtk_table_new(nRows, nColumns, FALSE);
|
|
|
|
gtk_container_add(GTK_CONTAINER(pDocView->pEventBox), pDocView->pTable);
|
|
|
|
gtk_widget_show(pDocView->pTable);
|
|
|
|
if (pDocView->pCanvas)
|
|
|
|
g_free(pDocView->pCanvas);
|
2015-03-10 16:42:10 +01:00
|
|
|
pDocView->pCanvas = static_cast<GtkWidget**>(g_malloc0(sizeof(GtkWidget*) * nRows * nColumns));
|
2015-01-16 15:47:51 +01:00
|
|
|
}
|
2015-01-14 17:57:47 +01:00
|
|
|
|
|
|
|
// Render the tiles.
|
2015-03-11 09:21:13 +01:00
|
|
|
for (guint nRow = 0; nRow < nRows; ++nRow)
|
2014-06-12 17:38:10 +01:00
|
|
|
{
|
2015-03-11 09:21:13 +01:00
|
|
|
for (guint nColumn = 0; nColumn < nColumns; ++nColumn)
|
2015-01-14 17:57:47 +01:00
|
|
|
{
|
2015-01-16 18:42:31 +01:00
|
|
|
GdkRectangle aTileRectangleTwips, aTileRectanglePixels;
|
2015-01-16 15:47:51 +01:00
|
|
|
gboolean bPaint = TRUE;
|
2015-01-14 17:57:47 +01:00
|
|
|
|
2015-01-16 15:47:51 +01:00
|
|
|
// Determine size of the tile: the rightmost/bottommost tiles may be smaller and we need the size to decide if we need to repaint.
|
2015-01-14 17:57:47 +01:00
|
|
|
if (nColumn == nColumns - 1)
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectanglePixels.width = nDocumentWidthPixels - nColumn * nTileSizePixels;
|
2015-01-14 17:57:47 +01:00
|
|
|
else
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectanglePixels.width = nTileSizePixels;
|
2015-01-14 17:57:47 +01:00
|
|
|
if (nRow == nRows - 1)
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectanglePixels.height = nDocumentHeightPixels - nRow * nTileSizePixels;
|
2015-01-14 17:57:47 +01:00
|
|
|
else
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectanglePixels.height = nTileSizePixels;
|
2015-01-14 17:57:47 +01:00
|
|
|
|
2015-01-16 15:47:51 +01:00
|
|
|
// Determine size and position of the tile in document coordinates, so we can decide if we can skip painting for partial rendering.
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectangleTwips.x = pixelToTwip(nTileSizePixels) / pDocView->fZoom * nColumn;
|
|
|
|
aTileRectangleTwips.y = pixelToTwip(nTileSizePixels) / pDocView->fZoom * nRow;
|
|
|
|
aTileRectangleTwips.width = pixelToTwip(aTileRectanglePixels.width) / pDocView->fZoom;
|
|
|
|
aTileRectangleTwips.height = pixelToTwip(aTileRectanglePixels.height) / pDocView->fZoom;
|
|
|
|
if (pPartial && !gdk_rectangle_intersect(pPartial, &aTileRectangleTwips, NULL))
|
2015-01-16 15:47:51 +01:00
|
|
|
bPaint = FALSE;
|
|
|
|
|
|
|
|
if (bPaint)
|
|
|
|
{
|
2015-01-16 18:42:31 +01:00
|
|
|
// Index of the current tile.
|
|
|
|
guint nTile = nRow * nColumns + nColumn;
|
|
|
|
|
2015-03-11 09:21:13 +01:00
|
|
|
GdkPixbuf* pPixBuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, aTileRectanglePixels.width, aTileRectanglePixels.height);
|
|
|
|
unsigned char* pBuffer = gdk_pixbuf_get_pixels(pPixBuf);
|
2015-01-16 18:53:45 +01:00
|
|
|
g_info("renderDocument: paintTile(%d, %d)", nRow, nColumn);
|
2015-03-11 09:21:13 +01:00
|
|
|
int nRowStride;
|
2015-01-16 15:47:51 +01:00
|
|
|
pDocView->pDocument->pClass->paintTile(pDocView->pDocument,
|
|
|
|
// Buffer and its size, depends on the position only.
|
|
|
|
pBuffer,
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectanglePixels.width, aTileRectanglePixels.height,
|
2015-01-16 15:47:51 +01:00
|
|
|
&nRowStride,
|
|
|
|
// Position of the tile.
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectangleTwips.x, aTileRectangleTwips.y,
|
2015-01-16 15:47:51 +01:00
|
|
|
// Size of the tile, depends on the zoom factor and the tile position only.
|
2015-01-16 18:42:31 +01:00
|
|
|
aTileRectangleTwips.width, aTileRectangleTwips.height);
|
2015-01-16 15:47:51 +01:00
|
|
|
(void) nRowStride;
|
|
|
|
|
2015-01-16 18:42:31 +01:00
|
|
|
if (pDocView->pCanvas[nTile])
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(pDocView->pCanvas[nTile]));
|
|
|
|
pDocView->pCanvas[nTile] = gtk_image_new();
|
|
|
|
gtk_image_set_from_pixbuf(GTK_IMAGE(pDocView->pCanvas[nTile]), pPixBuf);
|
2015-01-16 15:47:51 +01:00
|
|
|
g_object_unref(G_OBJECT(pPixBuf));
|
2015-01-16 18:42:31 +01:00
|
|
|
gtk_widget_show(pDocView->pCanvas[nTile]);
|
2015-01-16 15:47:51 +01:00
|
|
|
gtk_table_attach(GTK_TABLE(pDocView->pTable),
|
2015-01-16 18:42:31 +01:00
|
|
|
pDocView->pCanvas[nTile],
|
2015-01-16 15:47:51 +01:00
|
|
|
nColumn, nColumn + 1, nRow, nRow + 1,
|
|
|
|
GTK_SHRINK, GTK_SHRINK, 0, 0);
|
|
|
|
}
|
2015-01-14 17:57:47 +01:00
|
|
|
}
|
2014-06-12 17:38:10 +01:00
|
|
|
}
|
2014-06-23 15:13:25 +01:00
|
|
|
}
|
|
|
|
|
2015-01-15 15:16:48 +01:00
|
|
|
/// Callback data, allocated in lok_docview_callback_worker(), released in lok_docview_callback().
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int m_nType;
|
2015-01-16 15:47:51 +01:00
|
|
|
char* m_pPayload;
|
2015-01-15 15:16:48 +01:00
|
|
|
LOKDocView* m_pDocView;
|
|
|
|
}
|
|
|
|
LOKDocViewCallbackData;
|
|
|
|
|
2015-01-16 15:47:51 +01:00
|
|
|
/// Returns the GdkRectangle of a width,height,x,y string.
|
|
|
|
static GdkRectangle lcl_payloadToRectangle(const char* pPayload)
|
|
|
|
{
|
|
|
|
GdkRectangle aRet;
|
|
|
|
|
2015-01-30 20:56:07 +00:00
|
|
|
aRet.width = aRet.height = aRet.x = aRet.y = 0;
|
2015-03-11 09:21:13 +01:00
|
|
|
gchar** ppCoordinates = g_strsplit(pPayload, ", ", 4);
|
|
|
|
gchar** ppCoordinate = ppCoordinates;
|
2015-02-05 18:09:30 +01:00
|
|
|
if (!*ppCoordinate)
|
2015-01-16 15:47:51 +01:00
|
|
|
return aRet;
|
2015-02-05 18:09:30 +01:00
|
|
|
aRet.width = atoi(*ppCoordinate);
|
|
|
|
++ppCoordinate;
|
|
|
|
if (!*ppCoordinate)
|
2015-01-16 15:47:51 +01:00
|
|
|
return aRet;
|
2015-02-05 18:09:30 +01:00
|
|
|
aRet.height = atoi(*ppCoordinate);
|
|
|
|
++ppCoordinate;
|
|
|
|
if (!*ppCoordinate)
|
2015-01-16 15:47:51 +01:00
|
|
|
return aRet;
|
2015-02-05 18:09:30 +01:00
|
|
|
aRet.x = atoi(*ppCoordinate);
|
|
|
|
++ppCoordinate;
|
|
|
|
if (!*ppCoordinate)
|
2015-01-16 15:47:51 +01:00
|
|
|
return aRet;
|
2015-02-05 18:09:30 +01:00
|
|
|
aRet.y = atoi(*ppCoordinate);
|
|
|
|
g_strfreev(ppCoordinates);
|
2015-01-16 15:47:51 +01:00
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
2015-02-06 12:12:44 +01:00
|
|
|
/// Returns the GdkRectangle list of a w,h,x,y;w2,h2,x2,y2;... string.
|
|
|
|
static GList* lcl_payloadToRectangles(const char* pPayload)
|
|
|
|
{
|
|
|
|
GList* pRet = NULL;
|
|
|
|
|
2015-03-11 09:21:13 +01:00
|
|
|
gchar** ppRectangles = g_strsplit(pPayload, "; ", 0);
|
|
|
|
for (gchar** ppRectangle = ppRectangles; *ppRectangle; ++ppRectangle)
|
2015-02-06 12:12:44 +01:00
|
|
|
{
|
|
|
|
GdkRectangle aRect = lcl_payloadToRectangle(*ppRectangle);
|
|
|
|
GdkRectangle* pRect = g_new0(GdkRectangle, 1);
|
|
|
|
*pRect = aRect;
|
|
|
|
pRet = g_list_prepend(pRet, pRect);
|
|
|
|
}
|
|
|
|
g_strfreev(ppRectangles);
|
2015-03-11 09:21:13 +01:00
|
|
|
|
2015-02-06 12:12:44 +01:00
|
|
|
return pRet;
|
|
|
|
}
|
2015-02-23 10:04:38 +00:00
|
|
|
|
2015-02-26 14:29:32 +01:00
|
|
|
static const gchar* lcl_LibreOfficeKitCallbackTypeToString(int nType)
|
|
|
|
{
|
|
|
|
switch (nType)
|
|
|
|
{
|
|
|
|
case LOK_CALLBACK_INVALIDATE_TILES:
|
|
|
|
return "LOK_CALLBACK_INVALIDATE_TILES";
|
|
|
|
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
|
|
|
|
return "LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR";
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION:
|
|
|
|
return "LOK_CALLBACK_TEXT_SELECTION";
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_START:
|
|
|
|
return "LOK_CALLBACK_TEXT_SELECTION_START";
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_END:
|
|
|
|
return "LOK_CALLBACK_TEXT_SELECTION_END";
|
2015-03-04 10:09:53 +01:00
|
|
|
case LOK_CALLBACK_CURSOR_VISIBLE:
|
|
|
|
return "LOK_CALLBACK_CURSOR_VISIBLE";
|
2015-03-05 11:57:25 +01:00
|
|
|
case LOK_CALLBACK_GRAPHIC_SELECTION:
|
|
|
|
return "LOK_CALLBACK_GRAPHIC_SELECTION";
|
2015-03-09 12:40:23 +01:00
|
|
|
case LOK_CALLBACK_HYPERLINK_CLICKED:
|
|
|
|
return "LOK_CALLBACK_HYPERLINK_CLICKED";
|
2015-02-26 14:29:32 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:12:52 +01:00
|
|
|
/// Invoked on the main thread if lok_docview_callback_worker() requests so.
|
|
|
|
static gboolean lok_docview_callback(gpointer pData)
|
|
|
|
{
|
2015-02-09 08:02:46 +01:00
|
|
|
#if GLIB_CHECK_VERSION(2,28,0) // we need g_list_free_full()
|
2015-03-10 16:42:10 +01:00
|
|
|
LOKDocViewCallbackData* pCallback = static_cast<LOKDocViewCallbackData*>(pData);
|
2015-01-12 14:57:05 +01:00
|
|
|
|
2015-01-15 15:16:48 +01:00
|
|
|
switch (pCallback->m_nType)
|
|
|
|
{
|
|
|
|
case LOK_CALLBACK_INVALIDATE_TILES:
|
2015-01-16 15:47:51 +01:00
|
|
|
{
|
|
|
|
if (strcmp(pCallback->m_pPayload, "EMPTY") != 0)
|
|
|
|
{
|
|
|
|
GdkRectangle aRectangle = lcl_payloadToRectangle(pCallback->m_pPayload);
|
|
|
|
renderDocument(pCallback->m_pDocView, &aRectangle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
renderDocument(pCallback->m_pDocView, NULL);
|
|
|
|
}
|
|
|
|
break;
|
2015-01-27 09:34:04 +01:00
|
|
|
case LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR:
|
|
|
|
{
|
|
|
|
pCallback->m_pDocView->m_aVisibleCursor = lcl_payloadToRectangle(pCallback->m_pPayload);
|
2015-03-04 10:03:49 +01:00
|
|
|
pCallback->m_pDocView->m_bCursorOverlayVisible = TRUE;
|
2015-01-27 09:34:04 +01:00
|
|
|
gtk_widget_queue_draw(GTK_WIDGET(pCallback->m_pDocView->pEventBox));
|
|
|
|
}
|
|
|
|
break;
|
2015-02-06 12:12:44 +01:00
|
|
|
case LOK_CALLBACK_TEXT_SELECTION:
|
|
|
|
{
|
2015-02-10 11:10:50 +01:00
|
|
|
LOKDocView* pDocView = pCallback->m_pDocView;
|
2015-02-06 12:12:44 +01:00
|
|
|
GList* pRectangles = lcl_payloadToRectangles(pCallback->m_pPayload);
|
2015-02-10 11:10:50 +01:00
|
|
|
if (pDocView->m_pTextSelectionRectangles)
|
|
|
|
g_list_free_full(pDocView->m_pTextSelectionRectangles, g_free);
|
|
|
|
pDocView->m_pTextSelectionRectangles = pRectangles;
|
|
|
|
|
|
|
|
// In case the selection is empty, then we get no LOK_CALLBACK_TEXT_SELECTION_START/END events.
|
|
|
|
if (pRectangles == NULL)
|
|
|
|
{
|
|
|
|
memset(&pDocView->m_aTextSelectionStart, 0, sizeof(pDocView->m_aTextSelectionStart));
|
2015-02-10 18:40:02 +01:00
|
|
|
memset(&pDocView->m_aHandleStartRect, 0, sizeof(pDocView->m_aHandleStartRect));
|
2015-02-10 11:10:50 +01:00
|
|
|
memset(&pDocView->m_aTextSelectionEnd, 0, sizeof(pDocView->m_aTextSelectionEnd));
|
2015-02-10 18:40:02 +01:00
|
|
|
memset(&pDocView->m_aHandleEndRect, 0, sizeof(pDocView->m_aHandleEndRect));
|
2015-02-10 11:10:50 +01:00
|
|
|
}
|
2015-02-10 18:40:02 +01:00
|
|
|
else
|
|
|
|
memset(&pDocView->m_aHandleMiddleRect, 0, sizeof(pDocView->m_aHandleMiddleRect));
|
2015-02-10 11:10:50 +01:00
|
|
|
gtk_widget_queue_draw(GTK_WIDGET(pDocView->pEventBox));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_START:
|
|
|
|
{
|
|
|
|
pCallback->m_pDocView->m_aTextSelectionStart = lcl_payloadToRectangle(pCallback->m_pPayload);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOK_CALLBACK_TEXT_SELECTION_END:
|
|
|
|
{
|
|
|
|
pCallback->m_pDocView->m_aTextSelectionEnd = lcl_payloadToRectangle(pCallback->m_pPayload);
|
2015-02-06 12:12:44 +01:00
|
|
|
}
|
|
|
|
break;
|
2015-03-04 10:09:53 +01:00
|
|
|
case LOK_CALLBACK_CURSOR_VISIBLE:
|
|
|
|
{
|
|
|
|
pCallback->m_pDocView->m_bCursorVisible = strcmp(pCallback->m_pPayload, "true") == 0;
|
|
|
|
}
|
|
|
|
break;
|
2015-03-05 11:57:25 +01:00
|
|
|
case LOK_CALLBACK_GRAPHIC_SELECTION:
|
|
|
|
{
|
|
|
|
if (strcmp(pCallback->m_pPayload, "EMPTY") != 0)
|
|
|
|
pCallback->m_pDocView->m_aGraphicSelection = lcl_payloadToRectangle(pCallback->m_pPayload);
|
|
|
|
else
|
|
|
|
memset(&pCallback->m_pDocView->m_aGraphicSelection, 0, sizeof(pCallback->m_pDocView->m_aGraphicSelection));
|
|
|
|
gtk_widget_queue_draw(GTK_WIDGET(pCallback->m_pDocView->pEventBox));
|
|
|
|
}
|
|
|
|
break;
|
2015-03-09 12:40:23 +01:00
|
|
|
case LOK_CALLBACK_HYPERLINK_CLICKED:
|
|
|
|
{
|
|
|
|
GError* pError = NULL;
|
|
|
|
gtk_show_uri(NULL, pCallback->m_pPayload, GDK_CURRENT_TIME, &pError);
|
|
|
|
}
|
|
|
|
break;
|
2015-01-15 15:16:48 +01:00
|
|
|
default:
|
2015-03-09 12:40:23 +01:00
|
|
|
g_assert(0);
|
2015-01-15 15:16:48 +01:00
|
|
|
break;
|
|
|
|
}
|
2015-01-12 14:57:05 +01:00
|
|
|
|
2015-01-16 15:47:51 +01:00
|
|
|
g_free(pCallback->m_pPayload);
|
2015-01-15 15:16:48 +01:00
|
|
|
g_free(pCallback);
|
2015-02-09 08:02:46 +01:00
|
|
|
#endif
|
2015-01-09 18:12:52 +01:00
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Our LOK callback, runs on the LO thread.
|
|
|
|
static void lok_docview_callback_worker(int nType, const char* pPayload, void* pData)
|
2015-01-06 15:56:23 +01:00
|
|
|
{
|
2015-03-10 16:42:10 +01:00
|
|
|
LOKDocView* pDocView = static_cast<LOKDocView*>(pData);
|
2015-01-06 15:56:23 +01:00
|
|
|
|
2015-01-15 15:16:48 +01:00
|
|
|
LOKDocViewCallbackData* pCallback = g_new0(LOKDocViewCallbackData, 1);
|
|
|
|
pCallback->m_nType = nType;
|
2015-01-16 15:47:51 +01:00
|
|
|
pCallback->m_pPayload = g_strdup(pPayload);
|
2015-01-15 15:16:48 +01:00
|
|
|
pCallback->m_pDocView = pDocView;
|
2015-02-26 14:29:32 +01:00
|
|
|
g_info("lok_docview_callback_worker: %s, '%s'", lcl_LibreOfficeKitCallbackTypeToString(nType), pPayload);
|
2015-01-12 14:57:05 +01:00
|
|
|
#if GTK_CHECK_VERSION(2,12,0)
|
2015-01-15 15:16:48 +01:00
|
|
|
gdk_threads_add_idle(lok_docview_callback, pCallback);
|
2015-01-12 14:57:05 +01:00
|
|
|
#else
|
2015-01-15 15:16:48 +01:00
|
|
|
g_idle_add(lok_docview_callback, pDocView);
|
2015-01-12 14:57:05 +01:00
|
|
|
#endif
|
2015-01-06 15:56:23 +01:00
|
|
|
}
|
|
|
|
|
2014-06-23 15:13:25 +01:00
|
|
|
SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, char* pPath )
|
|
|
|
{
|
|
|
|
if ( pDocView->pDocument )
|
|
|
|
{
|
|
|
|
pDocView->pDocument->pClass->destroy( pDocView->pDocument );
|
2014-06-26 11:14:50 +01:00
|
|
|
pDocView->pDocument = NULL;
|
2014-06-23 15:13:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pDocView->pDocument = pDocView->pOffice->pClass->documentLoad( pDocView->pOffice,
|
2014-06-26 11:14:50 +01:00
|
|
|
pPath );
|
|
|
|
if ( !pDocView->pDocument )
|
|
|
|
{
|
|
|
|
// FIXME: should have a GError parameter and populate it.
|
|
|
|
char *pError = pDocView->pOffice->pClass->getError( pDocView->pOffice );
|
|
|
|
fprintf( stderr, "Error opening document '%s'\n", pError );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
2015-01-06 15:56:23 +01:00
|
|
|
{
|
2015-01-13 12:02:00 +01:00
|
|
|
pDocView->pDocument->pClass->initializeForRendering(pDocView->pDocument);
|
2015-03-10 11:24:11 +01:00
|
|
|
pDocView->pDocument->pClass->registerCallback(pDocView->pDocument, &lok_docview_callback_worker, pDocView);
|
|
|
|
g_timeout_add(600, &lcl_handleTimeout, pDocView);
|
2015-01-16 15:47:51 +01:00
|
|
|
renderDocument(pDocView, NULL);
|
2015-01-06 15:56:23 +01:00
|
|
|
}
|
2014-06-12 17:38:10 +01:00
|
|
|
|
2014-06-26 11:14:50 +01:00
|
|
|
return TRUE;
|
2014-06-12 17:38:10 +01:00
|
|
|
}
|
|
|
|
|
2014-06-23 15:13:25 +01:00
|
|
|
SAL_DLLPUBLIC_EXPORT void lok_docview_set_zoom ( LOKDocView* pDocView, float fZoom )
|
|
|
|
{
|
|
|
|
pDocView->fZoom = fZoom;
|
2014-07-08 09:43:09 +02:00
|
|
|
|
|
|
|
if ( pDocView->pDocument )
|
|
|
|
{
|
2015-01-16 15:47:51 +01:00
|
|
|
renderDocument(pDocView, NULL);
|
2014-07-08 09:43:09 +02:00
|
|
|
}
|
2014-06-23 15:13:25 +01:00
|
|
|
// TODO: maybe remember and reset positiong?
|
|
|
|
}
|
|
|
|
|
|
|
|
SAL_DLLPUBLIC_EXPORT float lok_docview_get_zoom ( LOKDocView* pDocView )
|
|
|
|
{
|
|
|
|
return pDocView->fZoom;
|
|
|
|
}
|
|
|
|
|
2014-07-08 15:32:20 +02:00
|
|
|
SAL_DLLPUBLIC_EXPORT int lok_docview_get_parts( LOKDocView* pDocView )
|
|
|
|
{
|
|
|
|
return pDocView->pDocument->pClass->getParts( pDocView->pDocument );
|
|
|
|
}
|
|
|
|
|
|
|
|
SAL_DLLPUBLIC_EXPORT int lok_docview_get_part( LOKDocView* pDocView )
|
|
|
|
{
|
|
|
|
return pDocView->pDocument->pClass->getPart( pDocView->pDocument );
|
|
|
|
}
|
|
|
|
|
|
|
|
SAL_DLLPUBLIC_EXPORT void lok_docview_set_part( LOKDocView* pDocView, int nPart)
|
|
|
|
{
|
|
|
|
pDocView->pDocument->pClass->setPart( pDocView->pDocument, nPart );
|
2015-01-16 15:47:51 +01:00
|
|
|
renderDocument(pDocView, NULL);
|
2014-07-08 15:32:20 +02:00
|
|
|
}
|
|
|
|
|
2014-07-29 13:17:30 +02:00
|
|
|
SAL_DLLPUBLIC_EXPORT char* lok_docview_get_part_name( LOKDocView* pDocView, int nPart )
|
|
|
|
{
|
|
|
|
return pDocView->pDocument->pClass->getPartName( pDocView->pDocument, nPart );
|
|
|
|
}
|
2014-07-29 17:00:33 +02:00
|
|
|
|
|
|
|
SAL_DLLPUBLIC_EXPORT void lok_docview_set_partmode( LOKDocView* pDocView,
|
2015-02-20 16:21:06 +01:00
|
|
|
int nPartMode )
|
2014-07-29 17:00:33 +02:00
|
|
|
{
|
2015-02-20 16:21:06 +01:00
|
|
|
pDocView->pDocument->pClass->setPartMode( pDocView->pDocument, nPartMode );
|
2015-01-16 15:47:51 +01:00
|
|
|
renderDocument(pDocView, NULL);
|
2014-07-29 17:00:33 +02:00
|
|
|
}
|
2015-01-13 16:47:23 +01:00
|
|
|
|
|
|
|
SAL_DLLPUBLIC_EXPORT void lok_docview_set_edit( LOKDocView* pDocView,
|
|
|
|
gboolean bEdit )
|
|
|
|
{
|
2015-03-10 12:50:59 +01:00
|
|
|
gboolean bWasEdit = pDocView->m_bEdit;
|
|
|
|
|
2015-01-13 16:47:23 +01:00
|
|
|
if (!pDocView->m_bEdit && bEdit)
|
2015-03-10 11:24:11 +01:00
|
|
|
g_info("lok_docview_set_edit: entering edit mode");
|
2015-03-10 16:13:53 +01:00
|
|
|
else if (pDocView->m_bEdit && !bEdit)
|
|
|
|
{
|
|
|
|
g_info("lok_docview_set_edit: leaving edit mode");
|
|
|
|
pDocView->pDocument->pClass->resetSelection(pDocView->pDocument);
|
|
|
|
}
|
2015-01-13 16:47:23 +01:00
|
|
|
pDocView->m_bEdit = bEdit;
|
2015-03-10 12:50:59 +01:00
|
|
|
g_signal_emit(pDocView, docview_signals[EDIT_CHANGED], 0, bWasEdit);
|
2015-03-10 11:24:11 +01:00
|
|
|
gtk_widget_queue_draw(GTK_WIDGET(pDocView->pEventBox));
|
2015-01-13 16:47:23 +01:00
|
|
|
}
|
|
|
|
|
2015-03-10 11:18:25 +01:00
|
|
|
SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView)
|
|
|
|
{
|
|
|
|
return pDocView->m_bEdit;
|
|
|
|
}
|
|
|
|
|
2015-03-12 14:59:59 +01:00
|
|
|
SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand)
|
|
|
|
{
|
|
|
|
pDocView->pDocument->pClass->postUnoCommand(pDocView->pDocument, pCommand);
|
|
|
|
}
|
|
|
|
|
2014-06-12 17:38:10 +01:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|