[Libreoffice-commits] core.git: 5 commits - include/LibreOfficeKit libreofficekit/qa libreofficekit/source sfx2/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Apr 14 02:54:08 PDT 2015
include/LibreOfficeKit/LibreOfficeKitGtk.h | 1
libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 72 ++++++++++++++++++--
libreofficekit/source/gtk/lokdocview.cxx | 20 +++++
sfx2/source/control/unoctitm.cxx | 2
4 files changed, 88 insertions(+), 7 deletions(-)
New commits:
commit 4dbff9ece8599365d65feb98403266d23633cd79
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Apr 14 11:37:27 2015 +0200
SfxDispatchController_Impl::InterceptLOKStateChangeEvent: fix typo
Without this, the strikethrough event is not sent to LOK clients, i.e.
the strikethrough button in gtktiledviewer did not change to the toggled
state when the cursor entered an area marked as strikethrough.
Change-Id: I0b2d3acc50cdfff88675ceb14cf653b6622797e7
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index f8c8ed0..141fa1d 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1054,7 +1054,7 @@ void SfxDispatchController_Impl::InterceptLOKStateChangeEvent(const SfxObjectShe
if (aEvent.FeatureURL.Path == "Bold" ||
aEvent.FeatureURL.Path == "Italic" ||
aEvent.FeatureURL.Path == "Underline" ||
- aEvent.FeatureURL.Path == "StrikeOut")
+ aEvent.FeatureURL.Path == "Strikeout")
{
OUStringBuffer aBuffer;
commit d01e4adfec33464594680140ce38c757885de343
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Apr 14 11:33:12 2015 +0200
gtktiledviewer: add underline and strikethrough
Change-Id: I457deb8d544b97874701dec37d8baee237ce4ebb
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 5bf1bdb..0e8ad7e 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -34,6 +34,8 @@ static GtkWidget* pDocView;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
static GtkToolItem* pItalic;
+static GtkToolItem* pUnderline;
+static GtkToolItem* pStrikethrough;
std::map<GtkToolItem*, std::string> g_aToolItemCommandNames;
std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
bool g_bToolItemBroadcast = true;
@@ -153,6 +155,7 @@ void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
const std::string& rString = g_aToolItemCommandNames[pItem];
+ g_info("toggleToolItem: lok_docview_post_command('%s')", rString.c_str());
lok_docview_post_command(pLOKDocView, rString.c_str());
}
}
@@ -307,6 +310,16 @@ int main( int argc, char* argv[] )
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pItalic, -1);
g_signal_connect(G_OBJECT(pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
lcl_registerToolItem(pItalic, ".uno:Italic");
+ pUnderline = gtk_toggle_tool_button_new();
+ gtk_tool_button_set_label(GTK_TOOL_BUTTON(pUnderline), "Underline");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pUnderline, -1);
+ g_signal_connect(G_OBJECT(pUnderline), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(pUnderline, ".uno:Underline");
+ pStrikethrough = gtk_toggle_tool_button_new();
+ gtk_tool_button_set_label(GTK_TOOL_BUTTON(pStrikethrough), "Strikethrough");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pStrikethrough, -1);
+ g_signal_connect(G_OBJECT(pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(pStrikethrough, ".uno:Strikeout");
gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
commit 6a488e1fde2705e5e51129825ebfe654f6f673e1
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Apr 14 11:19:27 2015 +0200
gtktiledviewer: add toggleToolItem() to avoid copy&paste
Change-Id: If2553d96472e6ced9b2fad4c202d0793a1fce3bc
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 976e523..5bf1bdb 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -11,6 +11,7 @@
#include <stdio.h>
#include <string.h>
#include <string>
+#include <map>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
@@ -33,6 +34,8 @@ static GtkWidget* pDocView;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
static GtkToolItem* pItalic;
+std::map<GtkToolItem*, std::string> g_aToolItemCommandNames;
+std::map<std::string, GtkToolItem*> g_aCommandNameToolItems;
bool g_bToolItemBroadcast = true;
static GtkWidget* pVBox;
// GtkComboBox requires gtk 2.24 or later
@@ -43,6 +46,12 @@ static GtkComboBoxText* pPartSelector;
static LibreOfficeKit* pOffice;
static char* pFileName;
+static void lcl_registerToolItem(GtkToolItem* pItem, const std::string& rName)
+{
+ g_aToolItemCommandNames[pItem] = rName;
+ g_aCommandNameToolItems[rName] = pItem;
+}
+
const float fZooms[] = { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 3.0, 5.0 };
void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
@@ -121,14 +130,9 @@ static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer
std::string aValue = aPayload.substr(nPosition + 1);
g_info("signalCommand: '%s' is '%s'", aKey.c_str(), aValue.c_str());
- GtkToolItem* pItem = 0;
- if (aKey == ".uno:Bold")
- pItem = pBold;
- else if (aKey == ".uno:Italic")
- pItem = pItalic;
-
- if (pItem)
+ if (g_aCommandNameToolItems.find(aKey) != g_aCommandNameToolItems.end())
{
+ GtkToolItem* pItem = g_aCommandNameToolItems[aKey];
bool bEdit = aValue == "true";
if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit)
{
@@ -141,22 +145,16 @@ static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer
}
}
-/// User clicked on the 'Bold' button -> inform LOKDocView.
-void toggleBold(GtkWidget* /*pButton*/, gpointer /*pItem*/)
-{
- LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
-
- if (g_bToolItemBroadcast)
- lok_docview_post_command(pLOKDocView, ".uno:Bold");
-}
-
-/// User clicked on the 'Italic' button -> inform LOKDocView.
-void toggleItalic(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+/// User clicked on a cmmand button -> inform LOKDocView.
+void toggleToolItem(GtkWidget* pWidget, gpointer /*pData*/)
{
- LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
-
if (g_bToolItemBroadcast)
- lok_docview_post_command(pLOKDocView, ".uno:Italic");
+ {
+ LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+ GtkToolItem* pItem = GTK_TOOL_ITEM(pWidget);
+ const std::string& rString = g_aToolItemCommandNames[pItem];
+ lok_docview_post_command(pLOKDocView, rString.c_str());
+ }
}
// GtkComboBox requires gtk 2.24 or later
@@ -302,11 +300,13 @@ int main( int argc, char* argv[] )
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);
+ g_signal_connect(G_OBJECT(pBold), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(pBold, ".uno:Bold");
pItalic = gtk_toggle_tool_button_new();
gtk_tool_button_set_label(GTK_TOOL_BUTTON(pItalic), "Italic");
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pItalic, -1);
- g_signal_connect(G_OBJECT(pItalic), "toggled", G_CALLBACK(toggleItalic), NULL);
+ g_signal_connect(G_OBJECT(pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
+ lcl_registerToolItem(pItalic, ".uno:Italic");
gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
commit a16fd82cdb6c1d7ddbdc78f1075dafef9360adb7
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Apr 14 11:04:42 2015 +0200
lokdocview: add Italic button
Change-Id: If23cb2f799df99cab92c13e09628fc139cdedb00
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index b706b41..976e523 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -32,6 +32,7 @@ static int help()
static GtkWidget* pDocView;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
+static GtkToolItem* pItalic;
bool g_bToolItemBroadcast = true;
static GtkWidget* pVBox;
// GtkComboBox requires gtk 2.24 or later
@@ -123,6 +124,8 @@ static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer
GtkToolItem* pItem = 0;
if (aKey == ".uno:Bold")
pItem = pBold;
+ else if (aKey == ".uno:Italic")
+ pItem = pItalic;
if (pItem)
{
@@ -147,6 +150,15 @@ void toggleBold(GtkWidget* /*pButton*/, gpointer /*pItem*/)
lok_docview_post_command(pLOKDocView, ".uno:Bold");
}
+/// User clicked on the 'Italic' button -> inform LOKDocView.
+void toggleItalic(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+{
+ LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+
+ if (g_bToolItemBroadcast)
+ lok_docview_post_command(pLOKDocView, ".uno:Italic");
+}
+
// GtkComboBox requires gtk 2.24 or later
#if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
void populatePartSelector()
@@ -291,6 +303,10 @@ int main( int argc, char* argv[] )
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);
+ pItalic = gtk_toggle_tool_button_new();
+ gtk_tool_button_set_label(GTK_TOOL_BUTTON(pItalic), "Italic");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pItalic, -1);
+ g_signal_connect(G_OBJECT(pItalic), "toggled", G_CALLBACK(toggleItalic), NULL);
gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
commit f9339d1ba316b11d00c235e9538ef0afde514443
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Apr 14 11:00:11 2015 +0200
lokdocview: implement LOK_CALLBACK_STATE_CHANGED
Change-Id: I239849056dd88f785dce239c4d53d6c905177b64
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index bb8ae78..f76c1fb 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -38,6 +38,7 @@ struct _LOKDocViewClass
{
GtkScrolledWindowClass parent_class;
void (* edit_changed) (LOKDocView* pView, gboolean was_edit);
+ void (* command_changed) (LOKDocView* pView, char* new_state);
};
guint lok_docview_get_type (void);
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 9c1c7ed..b706b41 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -10,6 +10,7 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
+#include <string>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
@@ -31,6 +32,7 @@ static int help()
static GtkWidget* pDocView;
static GtkToolItem* pEnableEditing;
static GtkToolItem* pBold;
+bool g_bToolItemBroadcast = true;
static GtkWidget* pVBox;
// GtkComboBox requires gtk 2.24 or later
#if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
@@ -107,12 +109,42 @@ static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pD
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing), bEdit);
}
+/// LOKDocView changed command state -> inform the tool button.
+static void signalCommand(LOKDocView* /*pLOKDocView*/, char* pPayload, gpointer /*pData*/)
+{
+ std::string aPayload(pPayload);
+ size_t nPosition = aPayload.find("=");
+ if (nPosition != std::string::npos)
+ {
+ std::string aKey = aPayload.substr(0, nPosition);
+ std::string aValue = aPayload.substr(nPosition + 1);
+ g_info("signalCommand: '%s' is '%s'", aKey.c_str(), aValue.c_str());
+
+ GtkToolItem* pItem = 0;
+ if (aKey == ".uno:Bold")
+ pItem = pBold;
+
+ if (pItem)
+ {
+ bool bEdit = aValue == "true";
+ if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pItem)) != bEdit)
+ {
+ // Avoid invoking lok_docview_post_command().
+ g_bToolItemBroadcast = false;
+ gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pItem), bEdit);
+ g_bToolItemBroadcast = true;
+ }
+ }
+ }
+}
+
/// 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");
+ if (g_bToolItemBroadcast)
+ lok_docview_post_command(pLOKDocView, ".uno:Bold");
}
// GtkComboBox requires gtk 2.24 or later
@@ -265,6 +297,7 @@ int main( int argc, char* argv[] )
// Docview
pDocView = lok_docview_new( pOffice );
g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
+ g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
// Input handling.
g_signal_connect(pWindow, "key-press-event", G_CALLBACK(lok_docview_post_key), pDocView);
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 2e2313a..2e6858c 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -182,6 +182,8 @@ struct LOKDocView_Impl
static void callbackWorker(int nType, const char* pPayload, void* pData);
/// Implementation of the callback worder handler, invoked by callbackWorker().
void callbackWorkerImpl(int nType, const char* pPayload);
+ /// Command state (various buttons like bold are toggled or not) is changed.
+ void commandChanged(const std::string& rPayload);
};
LOKDocView_Impl::CallbackData::CallbackData(int nType, const std::string& rPayload, LOKDocView* pDocView)
@@ -941,7 +943,7 @@ gboolean LOKDocView_Impl::callbackImpl(CallbackData* pCallback)
}
case LOK_CALLBACK_STATE_CHANGED:
{
- g_info("%s", pCallback->m_aPayload.c_str());
+ commandChanged(pCallback->m_aPayload);
}
break;
default:
@@ -971,11 +973,17 @@ void LOKDocView_Impl::callbackWorkerImpl(int nType, const char* pPayload)
enum
{
EDIT_CHANGED,
+ COMMAND_CHANGED,
LAST_SIGNAL
};
static guint docview_signals[LAST_SIGNAL] = { 0 };
+void LOKDocView_Impl::commandChanged(const std::string& rString)
+{
+ g_signal_emit(m_pDocView, docview_signals[COMMAND_CHANGED], 0, rString.c_str());
+}
+
static void lok_docview_class_init( gpointer ptr )
{
LOKDocViewClass* pClass = static_cast<LOKDocViewClass *>(ptr);
@@ -990,6 +998,16 @@ static void lok_docview_class_init( gpointer ptr )
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
+ pClass->command_changed = NULL;
+ docview_signals[COMMAND_CHANGED] =
+ g_signal_new("command-changed",
+ G_TYPE_FROM_CLASS(gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET(LOKDocViewClass, command_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1,
+ G_TYPE_STRING);
}
static void lok_docview_init( GTypeInstance* pInstance, gpointer )
More information about the Libreoffice-commits
mailing list