[Libreoffice-commits] core.git: Branch 'feature/tiled-editing' - 3 commits - include/LibreOfficeKit libreofficekit/qa libreofficekit/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Mar 10 04:56:39 PDT 2015
include/LibreOfficeKit/LibreOfficeKitGtk.h | 3 +
libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx | 26 +++++++++++
libreofficekit/source/gtk/lokdocview.c | 44 +++++++++++++++-----
3 files changed, 64 insertions(+), 9 deletions(-)
New commits:
commit 4f239cc722f72d7be91bca4276d873d2282b2e6c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Mar 10 12:50:59 2015 +0100
lokdocview: add edit-changed signal, so toolbar toggle button is in sync
Editing can start by clicking into the widget or by pressing the toggle
button on the toolbar. In the first case the widget should emit a signal,
so the the toggle button's state can be up to date.
In both toggle button <-> LOK widget direction only update the state if
it's not yet up to date to avoid infinite loops.
Change-Id: I84c9e7757cd7cde42a95f67f0cb28f9ad6984e7a
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index d6f6c3d..77e9118 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -97,6 +97,7 @@ struct _LOKDocView
struct _LOKDocViewClass
{
GtkScrolledWindowClass parent_class;
+ void (* edit_changed) (LOKDocView* pView, gboolean was_edit);
};
guint lok_docview_get_type (void);
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 360d9f4..32a107e 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -34,6 +34,7 @@ static int help()
}
static GtkWidget* pDocView;
+static GtkToolItem* pEnableEditing;
static GtkWidget* pDocViewQuad;
static GtkWidget* pVBox;
// GtkComboBox requires gtk 2.24 or later
@@ -105,11 +106,22 @@ void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
}
}
+/// User clicked on the button -> inform LOKDocView.
void toggleEditing(GtkWidget* /*pButton*/, gpointer /*pItem*/)
{
LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
- bool bEdit = lok_docview_get_edit(pLOKDocView);
- lok_docview_set_edit(pLOKDocView, !bEdit);
+ bool bActive = gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing));
+ if (lok_docview_get_edit(pLOKDocView) != bActive)
+ lok_docview_set_edit(pLOKDocView, bActive);
+}
+
+/// LOKDocView changed edit state -> inform the tool button.
+static void signalEdit(LOKDocView* pLOKDocView, gboolean bWasEdit, gpointer /*pData*/)
+{
+ gboolean bEdit = lok_docview_get_edit(pLOKDocView);
+ g_info("signalEdit: %d -> %d", bWasEdit, lok_docview_get_edit(pLOKDocView));
+ if (gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing)) != bEdit)
+ gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(pEnableEditing), bEdit);
}
void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
@@ -347,7 +359,7 @@ int main( int argc, char* argv[] )
g_signal_connect( G_OBJECT(pEnableQuadView), "toggled", G_CALLBACK(changeQuadView), NULL );
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
- GtkToolItem* pEnableEditing = gtk_toggle_tool_button_new();
+ pEnableEditing = gtk_toggle_tool_button_new();
gtk_tool_button_set_label(GTK_TOOL_BUTTON(pEnableEditing), "Editing");
gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pEnableEditing, -1);
g_signal_connect(G_OBJECT(pEnableEditing), "toggled", G_CALLBACK(toggleEditing), NULL);
@@ -357,6 +369,7 @@ int main( int argc, char* argv[] )
// Docview
pDocView = lok_docview_new( pOffice );
pDocViewQuad = 0;
+ g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
// Input handling.
g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), NULL);
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index e12266b..3980a50 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -232,7 +232,8 @@ gboolean lcl_signalButton(GtkWidget* pEventBox, GdkEventButton* pEvent, LOKDocVi
}
}
- lok_docview_set_edit(pDocView, TRUE);
+ if (!pDocView->m_bEdit)
+ lok_docview_set_edit(pDocView, TRUE);
switch (pEvent->type)
{
@@ -289,9 +290,27 @@ SAL_DLLPUBLIC_EXPORT guint lok_docview_get_type()
return lok_docview_type;
}
+enum
+{
+ EDIT_CHANGED,
+ LAST_SIGNAL
+};
+
+static guint docview_signals[LAST_SIGNAL] = { 0 };
+
static void lok_docview_class_init( LOKDocViewClass* pClass )
{
- (void)pClass;
+ GObjectClass *gobject_class = G_OBJECT_CLASS(pClass);
+ pClass->edit_changed = NULL;
+ docview_signals[EDIT_CHANGED] =
+ g_signal_new("edit-changed",
+ G_TYPE_FROM_CLASS (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (LOKDocViewClass, edit_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1,
+ G_TYPE_BOOLEAN);
}
static void lok_docview_init( LOKDocView* pDocView )
@@ -950,9 +969,12 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_set_partmode( LOKDocView* pDocView,
SAL_DLLPUBLIC_EXPORT void lok_docview_set_edit( LOKDocView* pDocView,
gboolean bEdit )
{
+ gboolean bWasEdit = pDocView->m_bEdit;
+
if (!pDocView->m_bEdit && bEdit)
g_info("lok_docview_set_edit: entering edit mode");
pDocView->m_bEdit = bEdit;
+ g_signal_emit(pDocView, docview_signals[EDIT_CHANGED], 0, bWasEdit);
gtk_widget_queue_draw(GTK_WIDGET(pDocView->pEventBox));
}
commit 33ad46087c19534fca8e6c0833148300ef942c91
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Mar 10 11:24:11 2015 +0100
lokdocview: register callback early
This is mainly to be in sync with Android, but this also makes blinking
text work in viewer mode.
Change-Id: Ie307cab722bae5030ca9bdfb442555a728aa33cc
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index 61ab957..e12266b 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -505,7 +505,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpoint
(void)pEvent;
pCairo = gdk_cairo_create(gtk_widget_get_window(pWidget));
- if (pDocView->m_bCursorVisible && pDocView->m_bCursorOverlayVisible && !lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor))
+ if (pDocView->m_bEdit && pDocView->m_bCursorVisible && pDocView->m_bCursorOverlayVisible && !lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor))
{
if (pDocView->m_aVisibleCursor.width == 0)
// Set a minimal width if it would be 0.
@@ -521,7 +521,7 @@ static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpoint
}
- if (pDocView->m_bCursorVisible && !lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor) && !pDocView->m_pTextSelectionRectangles)
+ if (pDocView->m_bEdit && pDocView->m_bCursorVisible && !lcl_isEmptyRectangle(&pDocView->m_aVisibleCursor) && !pDocView->m_pTextSelectionRectangles)
{
// Have a cursor, but no selection: we need the middle handle.
if (!pDocView->m_pHandleMiddle)
@@ -895,6 +895,8 @@ SAL_DLLPUBLIC_EXPORT gboolean lok_docview_open_document( LOKDocView* pDocView, c
else
{
pDocView->pDocument->pClass->initializeForRendering(pDocView->pDocument);
+ pDocView->pDocument->pClass->registerCallback(pDocView->pDocument, &lok_docview_callback_worker, pDocView);
+ g_timeout_add(600, &lcl_handleTimeout, pDocView);
renderDocument(pDocView, NULL);
}
@@ -949,12 +951,9 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_set_edit( LOKDocView* pDocView,
gboolean bEdit )
{
if (!pDocView->m_bEdit && bEdit)
- {
- g_info("lok_docview_set_edit: entering edit mode, registering callback");
- pDocView->pDocument->pClass->registerCallback(pDocView->pDocument, &lok_docview_callback_worker, pDocView);
- g_timeout_add(600, &lcl_handleTimeout, pDocView);
- }
+ g_info("lok_docview_set_edit: entering edit mode");
pDocView->m_bEdit = bEdit;
+ gtk_widget_queue_draw(GTK_WIDGET(pDocView->pEventBox));
}
SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView)
commit 720c60d0593a2cbf3f8b1b14b5861eecdef5e948
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Mar 10 11:18:25 2015 +0100
lokdocview: add lok_docview_get_edit()
Change-Id: I57a9c94ed0fb67befd226afe78a90bee9a7fb358
diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index a67c841..d6f6c3d 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -118,6 +118,8 @@ void lok_docview_set_partmode (LOKDocView* pDocView,
/// Sets if the viewer is actually an editor or not.
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);
#ifdef __cplusplus
}
#endif
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index cfa108e..360d9f4 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -105,6 +105,13 @@ void changeZoom( GtkWidget* pButton, gpointer /* pItem */ )
}
}
+void toggleEditing(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+{
+ LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
+ bool bEdit = lok_docview_get_edit(pLOKDocView);
+ lok_docview_set_edit(pLOKDocView, !bEdit);
+}
+
void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
{
if ( pDocView )
@@ -339,6 +346,12 @@ int main( int argc, char* argv[] )
gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pEnableQuadView, -1 );
g_signal_connect( G_OBJECT(pEnableQuadView), "toggled", G_CALLBACK(changeQuadView), NULL );
+ gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
+ GtkToolItem* pEnableEditing = gtk_toggle_tool_button_new();
+ gtk_tool_button_set_label(GTK_TOOL_BUTTON(pEnableEditing), "Editing");
+ gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pEnableEditing, -1);
+ g_signal_connect(G_OBJECT(pEnableEditing), "toggled", G_CALLBACK(toggleEditing), NULL);
+
gtk_box_pack_start( GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
// Docview
diff --git a/libreofficekit/source/gtk/lokdocview.c b/libreofficekit/source/gtk/lokdocview.c
index ebebbbf..61ab957 100644
--- a/libreofficekit/source/gtk/lokdocview.c
+++ b/libreofficekit/source/gtk/lokdocview.c
@@ -957,4 +957,9 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_set_edit( LOKDocView* pDocView,
pDocView->m_bEdit = bEdit;
}
+SAL_DLLPUBLIC_EXPORT gboolean lok_docview_get_edit(LOKDocView* pDocView)
+{
+ return pDocView->m_bEdit;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list