Kaydet (Commit) 00b758b4 authored tarafından Jan Holesovsky's avatar Jan Holesovsky Kaydeden (comit) Miklos Vajna

LOK: Implement posting of .uno: commands.

Implements also Bold button as an example in the gtktiledviewer.

Change-Id: I3b07d51165f28534aadbb4673f964ec10d5fc6ef
üst a250e9d3
......@@ -27,6 +27,7 @@
#include <rtl/strbuf.hxx>
#include <rtl/bootstrap.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <comphelper/dispatchcommand.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
......@@ -213,6 +214,8 @@ static void doc_postMouseEvent (LibreOfficeKitDocument* pThis,
int nX,
int nY,
int nCount);
static void doc_postUnoCommand(LibreOfficeKitDocument* pThis,
const char* pCommand);
static void doc_setTextSelection (LibreOfficeKitDocument* pThis,
int nType,
int nX,
......@@ -251,6 +254,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->registerCallback = doc_registerCallback;
m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
m_pDocumentClass->postUnoCommand = doc_postUnoCommand;
m_pDocumentClass->setTextSelection = doc_setTextSelection;
m_pDocumentClass->setGraphicSelection = doc_setGraphicSelection;
m_pDocumentClass->resetSelection = doc_resetSelection;
......@@ -723,6 +727,16 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* /*pThis*/, int nType, int n
#endif
}
static void doc_postUnoCommand(LibreOfficeKitDocument* /*pThis*/, const char* pCommand)
{
OUString aCommand(pCommand, strlen(pCommand), RTL_TEXTENCODING_UTF8);
if (!comphelper::dispatchCommand(aCommand))
{
gImpl->maLastExceptionMsg = "Failed to dispatch the .uno: command";
}
}
static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, int nY, int nCount)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
......
......@@ -132,6 +132,10 @@ struct _LibreOfficeKitDocumentClass
int nX,
int nY,
int nCount);
/// @see lok::Document::postUnoCommand
void (*postUnoCommand)(LibreOfficeKitDocument* pThis,
const char* pCommand);
/// @see lok::Document::setTextSelection
void (*setTextSelection)(LibreOfficeKitDocument* pThis,
int nType,
......
......@@ -130,6 +130,16 @@ public:
mpDoc->pClass->postMouseEvent(mpDoc, nType, nX, nY, nCount);
}
/**
* Posts an UNO command to the document.
*
* @param pCommand uno command to be posted to the document, like ".uno:Bold"
*/
inline void postUnoCommand(const char* pCommand)
{
mpDoc->pClass->postUnoCommand(mpDoc, pCommand);
}
/**
* Sets the start or end of a text selection.
*
......
......@@ -121,6 +121,9 @@ void lok_docview_set_edit (LOKDocView* pDocView,
gboolean bEdit);
/// Gets if the viewer is actually an editor or not.
gboolean lok_docview_get_edit (LOKDocView* pDocView);
/// Posts the .uno: command to the LibreOfficeKit.
void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand);
#ifdef __cplusplus
}
#endif
......
......@@ -35,6 +35,7 @@ static int help()
static GtkWidget* pDocView;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
static GtkWidget* pDocViewQuad;
static GtkWidget* pVBox;
// GtkComboBox requires gtk 2.24 or later
......@@ -124,6 +125,14 @@ static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pD
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing), bEdit);
}
/// User clicked on the 'Bold' button -> inform LOKDocView.
void toggleBold(GtkWidget* /*pButton*/, gpointer /*pItem*/)
{
LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
lok_docview_post_command(pLOKDocView, ".uno:Bold");
}
void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
{
if ( pDocView )
......@@ -364,6 +373,12 @@ int main( int argc, char* argv[] )
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pEnableEditing, -1);
g_signal_connect(G_OBJECT(pEnableEditing), "toggled", G_CALLBACK(toggleEditing), NULL);
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
pBold = gtk_toggle_tool_button_new();
gtk_tool_button_set_label(GTK_TOOL_BUTTON(pBold), "Bold");
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pBold, -1);
g_signal_connect(G_OBJECT(pBold), "toggled", G_CALLBACK(toggleBold), NULL);
gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
// Docview
......
......@@ -971,4 +971,9 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView)
return pDocView->m_bEdit;
}
SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const char* pCommand)
{
pDocView->pDocument->pClass->postUnoCommand(pDocView->pDocument, pCommand);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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