lokdocview: move keyboard handling to LOKDocView_Impl
Change-Id: I1117ec42bdf0f2cb19f77723b87597d301d20ddb
This commit is contained in:
@@ -68,6 +68,9 @@ gboolean lok_docview_get_edit (LOKDocView* pDocView);
|
||||
|
||||
/// Posts the .uno: command to the LibreOfficeKit.
|
||||
void lok_docview_post_command (LOKDocView* pDocView, const char* pCommand);
|
||||
|
||||
/// Posts a keyboard event to LibreOfficeKit.
|
||||
void lok_docview_post_key (GtkWidget* pWidget, GdkEventKey* pEvent, gpointer pData);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -14,8 +14,6 @@ $(eval $(call gb_Executable_set_include,gtktiledviewer,\
|
||||
-I$(SRCDIR)/desktop/inc \
|
||||
))
|
||||
|
||||
$(eval $(call gb_Executable_use_sdk_api,gtktiledviewer))
|
||||
|
||||
$(eval $(call gb_Executable_use_externals,gtktiledviewer,\
|
||||
gtk \
|
||||
))
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
$(eval $(call gb_Library_Library,libreofficekitgtk))
|
||||
|
||||
$(eval $(call gb_Library_use_sdk_api,libreofficekitgtk))
|
||||
|
||||
$(eval $(call gb_Library_use_externals,libreofficekitgtk,\
|
||||
gtk \
|
||||
|
@@ -12,16 +12,12 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <LibreOfficeKit/LibreOfficeKitGtk.h>
|
||||
#include <LibreOfficeKit/LibreOfficeKitInit.h>
|
||||
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
||||
|
||||
#include <com/sun/star/awt/Key.hpp>
|
||||
#include <rsc/rsc-vcl-shared-types.hxx>
|
||||
|
||||
#ifndef g_info
|
||||
#define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
|
||||
#endif
|
||||
@@ -119,65 +115,6 @@ void toggleBold(GtkWidget* /*pButton*/, gpointer /*pItem*/)
|
||||
lok_docview_post_command(pLOKDocView, ".uno:Bold");
|
||||
}
|
||||
|
||||
/// Receives a key press or release event.
|
||||
static void signalKey(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pData*/)
|
||||
{
|
||||
LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
|
||||
int nCharCode = 0;
|
||||
int nKeyCode = 0;
|
||||
|
||||
if (!lok_docview_get_edit(pLOKDocView))
|
||||
{
|
||||
g_info("signalKey: not in edit mode, ignore");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pEvent->keyval)
|
||||
{
|
||||
case GDK_BackSpace:
|
||||
nKeyCode = com::sun::star::awt::Key::BACKSPACE;
|
||||
break;
|
||||
case GDK_Return:
|
||||
nKeyCode = com::sun::star::awt::Key::RETURN;
|
||||
break;
|
||||
case GDK_Escape:
|
||||
nKeyCode = com::sun::star::awt::Key::ESCAPE;
|
||||
break;
|
||||
case GDK_Tab:
|
||||
nKeyCode = com::sun::star::awt::Key::TAB;
|
||||
break;
|
||||
case GDK_Down:
|
||||
nKeyCode = com::sun::star::awt::Key::DOWN;
|
||||
break;
|
||||
case GDK_Up:
|
||||
nKeyCode = com::sun::star::awt::Key::UP;
|
||||
break;
|
||||
case GDK_Left:
|
||||
nKeyCode = com::sun::star::awt::Key::LEFT;
|
||||
break;
|
||||
case GDK_Right:
|
||||
nKeyCode = com::sun::star::awt::Key::RIGHT;
|
||||
break;
|
||||
default:
|
||||
if (pEvent->keyval >= GDK_F1 && pEvent->keyval <= GDK_F26)
|
||||
nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_F1);
|
||||
else
|
||||
nCharCode = gdk_keyval_to_unicode(pEvent->keyval);
|
||||
}
|
||||
|
||||
// rsc is not public API, but should be good enough for debugging purposes.
|
||||
// If this is needed for real, then probably a new param of type
|
||||
// css::awt::KeyModifier is needed in postKeyEvent().
|
||||
if (pEvent->state & GDK_SHIFT_MASK)
|
||||
nKeyCode |= KEY_SHIFT;
|
||||
|
||||
LibreOfficeKitDocument* pDocument = lok_docview_get_document(pLOKDocView);
|
||||
if (pEvent->type == GDK_KEY_RELEASE)
|
||||
pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
|
||||
else
|
||||
pDocument->pClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
|
||||
}
|
||||
|
||||
// GtkComboBox requires gtk 2.24 or later
|
||||
#if ( GTK_MAJOR_VERSION == 2 && GTK_MINOR_VERSION >= 24 ) || GTK_MAJOR_VERSION > 2
|
||||
void populatePartSelector()
|
||||
@@ -330,8 +267,8 @@ int main( int argc, char* argv[] )
|
||||
g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
|
||||
|
||||
// Input handling.
|
||||
g_signal_connect(pWindow, "key-press-event", G_CALLBACK(signalKey), NULL);
|
||||
g_signal_connect(pWindow, "key-release-event", G_CALLBACK(signalKey), NULL);
|
||||
g_signal_connect(pWindow, "key-press-event", G_CALLBACK(lok_docview_post_key), pDocView);
|
||||
g_signal_connect(pWindow, "key-release-event", G_CALLBACK(lok_docview_post_key), pDocView);
|
||||
|
||||
gtk_container_add( GTK_CONTAINER(pVBox), pDocView );
|
||||
|
||||
|
@@ -11,10 +11,14 @@
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gdk/gdkkeysyms.h>
|
||||
|
||||
#include <com/sun/star/awt/Key.hpp>
|
||||
#define LOK_USE_UNSTABLE_API
|
||||
#include <LibreOfficeKit/LibreOfficeKit.h>
|
||||
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
|
||||
#include <LibreOfficeKit/LibreOfficeKitGtk.h>
|
||||
#include <rsc/rsc-vcl-shared-types.hxx>
|
||||
|
||||
#if !GLIB_CHECK_VERSION(2,32,0)
|
||||
#define G_SOURCE_REMOVE FALSE
|
||||
@@ -104,6 +108,8 @@ struct LOKDocView_Impl
|
||||
float pixelToTwip(float fInput);
|
||||
/// Converts from document coordinates to screen pixels.
|
||||
float twipToPixel(float fInput);
|
||||
/// Receives a key press or release event.
|
||||
void signalKey(GdkEventKey* pEvent);
|
||||
};
|
||||
|
||||
LOKDocView_Impl::LOKDocView_Impl()
|
||||
@@ -166,6 +172,63 @@ float LOKDocView_Impl::twipToPixel(float fInput)
|
||||
return fInput / 1440.0f * DPI * m_fZoom;
|
||||
}
|
||||
|
||||
void LOKDocView_Impl::signalKey(GdkEventKey* pEvent)
|
||||
{
|
||||
int nCharCode = 0;
|
||||
int nKeyCode = 0;
|
||||
|
||||
if (!m_bEdit)
|
||||
{
|
||||
g_info("signalKey: not in edit mode, ignore");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pEvent->keyval)
|
||||
{
|
||||
case GDK_BackSpace:
|
||||
nKeyCode = com::sun::star::awt::Key::BACKSPACE;
|
||||
break;
|
||||
case GDK_Return:
|
||||
nKeyCode = com::sun::star::awt::Key::RETURN;
|
||||
break;
|
||||
case GDK_Escape:
|
||||
nKeyCode = com::sun::star::awt::Key::ESCAPE;
|
||||
break;
|
||||
case GDK_Tab:
|
||||
nKeyCode = com::sun::star::awt::Key::TAB;
|
||||
break;
|
||||
case GDK_Down:
|
||||
nKeyCode = com::sun::star::awt::Key::DOWN;
|
||||
break;
|
||||
case GDK_Up:
|
||||
nKeyCode = com::sun::star::awt::Key::UP;
|
||||
break;
|
||||
case GDK_Left:
|
||||
nKeyCode = com::sun::star::awt::Key::LEFT;
|
||||
break;
|
||||
case GDK_Right:
|
||||
nKeyCode = com::sun::star::awt::Key::RIGHT;
|
||||
break;
|
||||
default:
|
||||
if (pEvent->keyval >= GDK_F1 && pEvent->keyval <= GDK_F26)
|
||||
nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_F1);
|
||||
else
|
||||
nCharCode = gdk_keyval_to_unicode(pEvent->keyval);
|
||||
}
|
||||
|
||||
// rsc is not public API, but should be good enough for debugging purposes.
|
||||
// If this is needed for real, then probably a new param of type
|
||||
// css::awt::KeyModifier is needed in postKeyEvent().
|
||||
if (pEvent->state & GDK_SHIFT_MASK)
|
||||
nKeyCode |= KEY_SHIFT;
|
||||
|
||||
if (pEvent->type == GDK_KEY_RELEASE)
|
||||
m_pDocument->pClass->postKeyEvent(m_pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
|
||||
else
|
||||
m_pDocument->pClass->postKeyEvent(m_pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
|
||||
}
|
||||
|
||||
|
||||
static void lok_docview_class_init( gpointer );
|
||||
static void lok_docview_init( GTypeInstance *, gpointer );
|
||||
static gboolean renderOverlay(GtkWidget* pWidget, GdkEventExpose* pEvent, gpointer pData);
|
||||
@@ -1051,4 +1114,10 @@ SAL_DLLPUBLIC_EXPORT void lok_docview_post_command(LOKDocView* pDocView, const c
|
||||
pDocView->m_pImpl->m_pDocument->pClass->postUnoCommand(pDocView->m_pImpl->m_pDocument, pCommand);
|
||||
}
|
||||
|
||||
SAL_DLLPUBLIC_EXPORT void lok_docview_post_key(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer pData)
|
||||
{
|
||||
LOKDocView* pDocView = static_cast<LOKDocView *>(pData);
|
||||
pDocView->m_pImpl->signalKey(pEvent);
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
Reference in New Issue
Block a user