summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranav Kant <pranavk@collabora.co.uk>2017-11-29 17:47:10 +0530
committerJan Holesovsky <kendy@collabora.com>2017-12-04 13:03:05 +0100
commit0002dfb6d723dfc7c29b5344240de4a525fa49a2 (patch)
treee8c1fb4323900558445ffe15a9b8c1cc0f16ae5f
parent3d5b550bd68a88f85f793aa2194932a61ecd8983 (diff)
lokdialog: Allow closing a dialog from LOK client
... and rename paintDialog -> paintWindow before it's too late. We not only render dialogs now but also popups. Change-Id: I6b1253c4d9be0c79199b683df4413658a461f850
-rw-r--r--desktop/source/lib/init.cxx27
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h7
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx20
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitEnums.h6
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx6
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx2
6 files changed, 56 insertions, 12 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index f0c970905a39..1ca906185de4 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -633,12 +633,14 @@ static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis,
int* pFontHeight);
static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart);
-static void doc_paintDialog(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer,
+static void doc_paintWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer,
const int nX, const int nY,
const int nWidth, const int nHeight);
static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, unsigned char* pBuffer, int* nWidth, int* nHeight);
+static void doc_postWindow(LibreOfficeKitDocument* pThis, unsigned nLOKWindowId, int nAction);
+
LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent)
: mxComponent(xComponent)
{
@@ -689,8 +691,9 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->renderFont = doc_renderFont;
m_pDocumentClass->getPartHash = doc_getPartHash;
- m_pDocumentClass->paintDialog = doc_paintDialog;
+ m_pDocumentClass->paintWindow = doc_paintWindow;
m_pDocumentClass->paintActiveFloatingWindow = doc_paintActiveFloatingWindow;
+ m_pDocumentClass->postWindow = doc_postWindow;
gDocumentClass = m_pDocumentClass;
}
@@ -3310,7 +3313,7 @@ unsigned char* doc_renderFont(LibreOfficeKitDocument* /*pThis*/,
return nullptr;
}
-static void doc_paintDialog(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId,
+static void doc_paintWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId,
unsigned char* pBuffer,
const int nX, const int nY,
const int nWidth, const int nHeight)
@@ -3361,6 +3364,24 @@ static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* /*pThis*/, uns
comphelper::LibreOfficeKit::setDialogPainting(false);
}
+static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindowId, int nAction)
+{
+ SolarMutexGuard aGuard;
+
+ VclPtr<Window> pWindow = vcl::Window::FindLOKWindow(nLOKWindowId);
+ if (!pWindow)
+ {
+ gImpl->maLastExceptionMsg = "Document doesn't support dialog rendering, or window not found.";
+ return;
+ }
+
+ if (Dialog* pDialog = dynamic_cast<Dialog*>(pWindow.get()))
+ {
+ if (nAction == LOK_WINDOW_CLOSE)
+ pDialog->EndDialog( RET_CANCEL );
+ }
+}
+
static char* lo_getError (LibreOfficeKit *pThis)
{
SolarMutexGuard aGuard;
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 40f74f4f8f1a..2a5f2cd43e49 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -260,8 +260,8 @@ struct _LibreOfficeKitDocumentClass
size_t nSize);
/// Paints dialog with given dialog id to the buffer
- /// @see lok::Document::paintDialog().
- void (*paintDialog) (LibreOfficeKitDocument* pThis, unsigned nDialogId,
+ /// @see lok::Document::paintWindow().
+ void (*paintWindow) (LibreOfficeKitDocument* pThis, unsigned nWindowId,
unsigned char* pBuffer,
const int x, const int y,
const int width, const int height);
@@ -269,6 +269,9 @@ struct _LibreOfficeKitDocumentClass
/// @see lok::Document::paintActiveFloatingWindow().
void (*paintActiveFloatingWindow) (LibreOfficeKitDocument* pThis, unsigned nDialogId, unsigned char* pBuffer, int* nWidth, int* nHeight);
+ /// @see lok::Document::postWindow().
+ void (*postWindow) (LibreOfficeKitDocument* pThis, unsigned nWindowId, int nAction);
+
/// @see lok::Document::postDialogKeyEvent().
void (*postDialogKeyEvent) (LibreOfficeKitDocument* pThis,
unsigned nDialogId,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 8c83a4bde0ed..ae48b6ac5242 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -155,25 +155,23 @@ public:
}
/**
- * Renders a dialog with give dialog id and writes the width and height of the rendered dialog
+ * Renders a window (dialog, popup, etc.) with give id
*
- * Client must truncate pBuffer according to the nWidth and nHeight returned after the call.
- *
- * @param nDialogId Unique dialog id to be painted
+ * @param nWindowId
* @param pBuffer Buffer with enough memory allocated to render any dialog
* @param x x-coordinate from where the dialog should start painting
* @param y y-coordinate from where the dialog should start painting
* @param width The width of the dialog image to be painted
* @param height The height of the dialog image to be painted
*/
- void paintDialog(unsigned nDialogId,
+ void paintWindow(unsigned nWindowId,
unsigned char* pBuffer,
const int x,
const int y,
const int width,
const int height)
{
- return mpDoc->pClass->paintDialog(mpDoc, nDialogId, pBuffer,
+ return mpDoc->pClass->paintWindow(mpDoc, nWindowId, pBuffer,
x, y, width, height);
}
@@ -197,6 +195,16 @@ public:
}
/**
+ * Posts a command to the window (dialog, popup, etc.) with given id
+ *
+ * @param nWindowid
+ */
+ void postWindow(unsigned nWindowId, int nAction)
+ {
+ return mpDoc->pClass->postWindow(mpDoc, nWindowId, nAction);
+ }
+
+ /**
* Gets the tile mode: the pixel format used for the pBuffer of paintTile().
*
* @return an element of the LibreOfficeKitTileMode enum.
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 62b9faf7ecb4..facbd351633d 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -40,6 +40,12 @@ typedef enum
}
LibreOfficeKitTileMode;
+typedef enum
+{
+ LOK_WINDOW_CLOSE
+}
+LibreOfficeKitWindowAction;
+
/** Optional features of LibreOfficeKit, in particular callbacks that block
* LibreOfficeKit until the corresponding reply is received, which would
* deadlock if the client does not support the feature.
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx
index dcebbe59418b..64d79e4c3d9c 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-application-window.cxx
@@ -412,7 +412,13 @@ gtv_application_window_unregister_child_window(GtvApplicationWindow* window, Gtk
{
GtvApplicationWindowPrivate* priv = getPrivate(window);
if (pChildWin)
+ {
priv->m_pChildWindows = g_list_remove(priv->m_pChildWindows, pChildWin);
+ LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview));
+ guint dialogId = 0;
+ g_object_get(G_OBJECT(pChildWin), "dialogid", &dialogId, nullptr);
+ pDocument->pClass->postWindow(pDocument, dialogId, LOK_WINDOW_CLOSE);
+ }
}
GtkWindow*
diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx
index 7249a1928a38..b2deb0666b56 100644
--- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx
@@ -106,7 +106,7 @@ gtv_lok_dialog_draw(GtkWidget* pDialogDrawingArea, cairo_t* pCairo, gpointer)
cairo_surface_t* pSurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, nWidth, nHeight);
unsigned char* pBuffer = cairo_image_surface_get_data(pSurface);
LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(priv->lokdocview));
- pDocument->pClass->paintDialog(pDocument, priv->dialogid, pBuffer, aRect.x, aRect.y, nWidth, nHeight);
+ pDocument->pClass->paintWindow(pDocument, priv->dialogid, pBuffer, aRect.x, aRect.y, nWidth, nHeight);
gtk_widget_set_size_request(GTK_WIDGET(pDialogDrawingArea), priv->m_nWidth, priv->m_nHeight);