diff options
author | Pranav Kant <pranavk@collabora.co.uk> | 2017-11-05 18:40:52 +0530 |
---|---|---|
committer | pranavk <pranavk@collabora.co.uk> | 2017-11-09 04:14:38 +0100 |
commit | 25822ff930edd13442442a47714755a99fbb9992 (patch) | |
tree | 8aaef28ba7aca657bf2e681dcf15c312617ed179 | |
parent | 446a37ece35dbe4c442f0679dd1cb4df79ed87a7 (diff) |
lokdialog: Move getting dialog information in separate LOK call
Using outparameters to get the dialog information with the paintDialog
call was quite confusing.
Change-Id: Ief331b251dc66e66084b827ce5b025ba6c9ce7d2
Reviewed-on: https://gerrit.libreoffice.org/44473
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: pranavk <pranavk@collabora.co.uk>
-rw-r--r-- | desktop/source/lib/init.cxx | 46 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 10 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 40 | ||||
-rw-r--r-- | include/vcl/IDialogRenderable.hxx | 5 | ||||
-rw-r--r-- | libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx | 6 | ||||
-rw-r--r-- | sw/inc/unotxdoc.hxx | 3 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 24 |
7 files changed, 91 insertions, 43 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index d126da925b2b..a5df72c72ac9 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -610,7 +610,12 @@ static unsigned char* doc_renderFont(LibreOfficeKitDocument* pThis, int* pFontHeight); static char* doc_getPartHash(LibreOfficeKitDocument* pThis, int nPart); -static void doc_paintDialog(LibreOfficeKitDocument* pThis, const char* pDialogId, const int x, const int y, unsigned char* pBuffer, char** pDialogTitle, int* nWidth, int* nHeight); +static void doc_paintDialog(LibreOfficeKitDocument* pThis, const char* pDialogId, unsigned char* pBuffer, + const int nX, const int nY, + const int nWidth, const int nHeight); + +static void doc_getDialogInfo(LibreOfficeKitDocument* pThis, const char* pDialogId, + char** pDialogTitle, int* nWidth, int* nHeight); static void doc_paintActiveFloatingWindow(LibreOfficeKitDocument* pThis, const char* pDialogId, unsigned char* pBuffer, int* nWidth, int* nHeight); @@ -664,6 +669,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->getPartHash = doc_getPartHash; m_pDocumentClass->paintDialog = doc_paintDialog; + m_pDocumentClass->getDialogInfo = doc_getDialogInfo; m_pDocumentClass->paintActiveFloatingWindow = doc_paintActiveFloatingWindow; gDocumentClass = m_pDocumentClass; @@ -3091,11 +3097,29 @@ unsigned char* doc_renderFont(SAL_UNUSED_PARAMETER LibreOfficeKitDocument* /*pTh return nullptr; } +static void doc_getDialogInfo(LibreOfficeKitDocument* pThis, const char* pDialogId, + char** pDialogTitle, int* nWidth, int* nHeight) +{ + SolarMutexGuard aGuard; + + IDialogRenderable* pDialogRenderable = getDialogRenderable(pThis); + vcl::DialogID aDialogID = OUString::createFromAscii(pDialogId); + OUString aDialogTitle; + pDialogRenderable->getDialogInfo(aDialogID, aDialogTitle, *nWidth, *nHeight); + + // copy dialog title + if (!aDialogTitle.isEmpty()) + { + OString aTitleString = OUStringToOString(aDialogTitle, RTL_TEXTENCODING_UTF8); + *pDialogTitle = static_cast<char*>(malloc(aTitleString.getLength() + 1)); + strcpy(*pDialogTitle, aTitleString.getStr()); + } +} + static void doc_paintDialog(LibreOfficeKitDocument* pThis, const char* pDialogId, - const int x, const int y, unsigned char* pBuffer, - char** pDialogTitle, - int* nWidth, int* nHeight) + const int nX, const int nY, + const int nWidth, const int nHeight) { SolarMutexGuard aGuard; @@ -3104,24 +3128,16 @@ static void doc_paintDialog(LibreOfficeKitDocument* pThis, const char* pDialogId ScopedVclPtrInstance<VirtualDevice> pDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT); pDevice->SetBackground(Wallpaper(Color(COL_TRANSPARENT))); - pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(*nWidth, *nHeight), Fraction(1.0), Point(), pBuffer); + pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nWidth, nHeight), Fraction(1.0), Point(), pBuffer); vcl::DialogID aDialogID = OUString::createFromAscii(pDialogId); MapMode aMapMode(pDevice->GetMapMode()); - aMapMode.SetOrigin(Point(-x, -y)); + aMapMode.SetOrigin(Point(-nX, -nY)); pDevice->SetMapMode(aMapMode); comphelper::LibreOfficeKit::setDialogPainting(true); - // copy the title of the dialog to outparam - OUString aDialogTitle; - pDialogRenderable->paintDialog(aDialogID, *pDevice.get(), aDialogTitle, *nWidth, *nHeight); - if (!aDialogTitle.isEmpty()) - { - OString aTitleString = OUStringToOString(aDialogTitle, RTL_TEXTENCODING_UTF8); - *pDialogTitle = static_cast<char*>(malloc(aTitleString.getLength() + 1)); - strcpy(*pDialogTitle, aTitleString.getStr()); - } + pDialogRenderable->paintDialog(aDialogID, *pDevice.get()); comphelper::LibreOfficeKit::setDialogPainting(false); } diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h index cb0f17a41655..14824821cfd7 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -269,10 +269,14 @@ struct _LibreOfficeKitDocumentClass /// Paints dialog with given dialog id to the buffer /// @see lok::Document::paintDialog(). void (*paintDialog) (LibreOfficeKitDocument* pThis, const char* pDialogId, - const int x, const int y, unsigned char* pBuffer, - char** pDialogTitle, - int* nWidth, int* nHeight); + const int x, const int y, + const int width, const int height); + + /// Get info about dialog with given dialog id + /// @see lok::Document::getDialogInfo(). + void (*getDialogInfo) (LibreOfficeKitDocument* pThis, const char* pDialogId, + char** pDialogTitle, int* pWidth, int* pHeight); /// @see lok::Document::paintActiveFloatingWindow(). void (*paintActiveFloatingWindow) (LibreOfficeKitDocument* pThis, const char* pDialogId, unsigned char* pBuffer, int* nWidth, int* nHeight); diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 586637f6606e..19e121fe6573 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -161,28 +161,38 @@ public: * Client must truncate pBuffer according to the nWidth and nHeight returned after the call. * * @param pDialogId Unique dialog id to be painted + * @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 pBuffer Buffer with enough memory allocated to render any dialog - * @param pDialogTitle output parameter pointing to a dialog title - * string. Should be freed by the caller. - * @param nWidth in/out parameter returning the width of the rendered - * dialog. The input width value is used to determined the size of the - * image to be painted. - * @param nHeight in/out parameter returning the height of the rendered - * dialog. The input height value is used to determine the size of the - * image to be painted. + * @param width The width of the dialog image to be painted + * @param height The height of the dialog image to be painted */ void paintDialog(const char* pDialogId, + unsigned char* pBuffer, const int x, const int y, - unsigned char* pBuffer, - char** pDialogTitle, - int& nWidth, - int& nHeight) + const int width, + const int height) + { + return mpDoc->pClass->paintDialog(mpDoc, pDialogId, pBuffer, + x, y, width, height); + } + + /* Get info about dialog with given dialog id + * + * @param pDialogId Unique dialog id for which to get info about + * @param pDialogTitle Pointer to pointer pointing to string containing the + * dialog title. Caller should the pointer to allocated string themselves. + * @param pWidth The width of the dialog + * @param pHeight The height of the dialog + */ + void getDialogInfo(const char* pDialogId, + char** pDialogTitle, + int& pWidth, + int& pHeight) { - return mpDoc->pClass->paintDialog(mpDoc, pDialogId, x, y, pBuffer, - pDialogTitle, &nWidth, &nHeight); + return mpDoc->pClass->getDialogInfo(mpDoc, pDialogId, pDialogTitle, &pWidth, &pHeight); + } /** diff --git a/include/vcl/IDialogRenderable.hxx b/include/vcl/IDialogRenderable.hxx index 2574cf5430db..87630d5c2f1d 100644 --- a/include/vcl/IDialogRenderable.hxx +++ b/include/vcl/IDialogRenderable.hxx @@ -28,8 +28,9 @@ class VCL_DLLPUBLIC IDialogRenderable public: virtual ~IDialogRenderable(); - virtual void paintDialog(const DialogID& rDialogID, VirtualDevice &rDevice, - OUString& rDialogTitle, int& nOutputWidth, int& nOutputHeight) = 0; + virtual void paintDialog(const DialogID& rDialogID, VirtualDevice &rDevice) = 0; + + virtual void getDialogInfo(const DialogID& rDialogID, OUString& rDialogTitle, int& rWidth, int& rHeight) = 0; virtual void paintActiveFloatingWindow(const DialogID& rDialogID, VirtualDevice &rDevice, int& nOutputWidth, int& nOutputHeight) = 0; diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx index 1614c157ae7c..001242ec6f52 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx @@ -102,14 +102,16 @@ gtv_lok_dialog_draw(GtkWidget* pDialogDrawingArea, cairo_t* pCairo, gpointer) unsigned char* pBuffer = cairo_image_surface_get_data(pSurface); LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(priv->lokdocview)); char* pDialogTitle = nullptr; - pDocument->pClass->paintDialog(pDocument, priv->dialogid, aRect.x, aRect.y, pBuffer, &pDialogTitle, &nWidth, &nHeight); + pDocument->pClass->paintDialog(pDocument, priv->dialogid, pBuffer, aRect.x, aRect.y, nWidth, nHeight); + int outWidth = 0, outHeight = 0; + pDocument->pClass->getDialogInfo(pDocument, priv->dialogid, &pDialogTitle, &outWidth, &outHeight); if (pDialogTitle) { gtk_window_set_title(GTK_WINDOW(pDialog), pDialogTitle); free(pDialogTitle); } - gtk_widget_set_size_request(GTK_WIDGET(pDialogDrawingArea), nWidth, nHeight); + gtk_widget_set_size_request(GTK_WIDGET(pDialogDrawingArea), outWidth, outHeight); cairo_surface_flush(pSurface); cairo_surface_mark_dirty(pSurface); diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index 3d886beda8e3..b9fb29d3aa16 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -431,7 +431,8 @@ public: /// @see vcl::ITiledRenderable::getPostIts(). OUString getPostIts() override; - void paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& rDevice, OUString& rDialogTitle, int& nWidth, int& nHeight) override; + void paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& rDevice) override; + void getDialogInfo(const vcl::DialogID& rDialogID, OUString& rDialogTitle, int& rWidth, int& rHeight) override; void paintActiveFloatingWindow(const vcl::DialogID& rDialogID, VirtualDevice& rDevice, int& nWidth, int& nHeight) override; void postDialogKeyEvent(const vcl::DialogID& rDialogID, int nType, int nCharCode, int nKeyCode) override; diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 63a7e609766f..2ede2e2b69eb 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3639,7 +3639,7 @@ void SAL_CALL SwXTextDocument::paintTile( const ::css::uno::Any& Parent, ::sal_I #endif } -void SwXTextDocument::paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& rDevice, OUString& rDialogTitle, int& nWidth, int& nHeight) +void SwXTextDocument::paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& rDevice) { SfxViewFrame* pViewFrame = pDocShell->GetView()->GetViewFrame(); SfxSlotPool* pSlotPool = SW_MOD()->GetSlotPool(); @@ -3665,12 +3665,27 @@ void SwXTextDocument::paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& // register the instance so that vcl::Dialog can emit LOK callbacks pDlg->registerDialogRenderable(this, rDialogID); pDlg->paintDialog(rDevice); +} + +void SwXTextDocument::getDialogInfo(const vcl::DialogID& rDialogID, OUString& rDialogTitle, int& rWidth, int& rHeight) +{ + SfxViewFrame* pViewFrame = pDocShell->GetView()->GetViewFrame(); + SfxSlotPool* pSlotPool = SW_MOD()->GetSlotPool(); + const SfxSlot* pSlot = pSlotPool->GetUnoSlot(rDialogID); + if (!pSlot) + { + SAL_WARN("lok.dialog", "No slot found for " << rDialogID); + return; + } + SfxChildWindow* pChild = pViewFrame->GetChildWindow(pSlot->GetSlotId()); + if (!pChild) + return; - // set outparams + Dialog* pDlg = static_cast<Dialog*>(pChild->GetWindow()); rDialogTitle = pDlg->GetText(); const Size aSize = pDlg->GetOptimalSize(); - nWidth = aSize.getWidth(); - nHeight = aSize.getHeight(); + rWidth = aSize.getWidth(); + rHeight = aSize.getHeight(); } void SwXTextDocument::postDialogKeyEvent(const vcl::DialogID& rDialogID, int nType, int nCharCode, int nKeyCode) @@ -3811,7 +3826,6 @@ void SwXTextDocument::paintActiveFloatingWindow(const vcl::DialogID& rDialogID, return; Dialog* pDlg = static_cast<Dialog*>(pChild->GetWindow()); - // register the instance so that vcl::Dialog can emit LOK callbacks const Size aSize = pDlg->PaintActiveFloatingWindow(rDevice); nWidth = aSize.getWidth(); nHeight = aSize.getHeight(); |