Kaydet (Commit) 2f2679a5 authored tarafından Pranav Kant's avatar Pranav Kant

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
üst cc05f8d9
......@@ -613,12 +613,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)
{
......@@ -669,8 +671,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;
}
......@@ -3283,7 +3286,7 @@ unsigned char* doc_renderFont(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pTh
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)
......@@ -3334,6 +3337,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;
......
......@@ -271,8 +271,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);
......@@ -280,6 +280,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,
......
......@@ -156,25 +156,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:
&nWidth, &nHeight);
}
/**
* 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().
*
......
......@@ -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.
......
......@@ -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*
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment