summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2015-02-17 10:33:47 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2015-02-23 10:10:22 +0100
commitbfe3a47e1e5bb51b7f9440b6155d002eedcea22b (patch)
tree4abe069df6959ac50b108063d56173482c1f878d
parent0622d2658a8ccadadfb5eb2180a252833c3a9c22 (diff)
lok::Office::postKeyEvent: allow different char and key code
editeng is not happy with non-zero char code for css::awt::Key::ESCAPE. Change-Id: If26923df7defb8a47766e9109835a8569067e578
-rw-r--r--android/Bootstrap/src/org/libreoffice/kit/Office.java2
-rw-r--r--android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java25
-rw-r--r--desktop/source/lib/init.cxx6
-rw-r--r--desktop/source/lib/lokandroid.cxx4
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h2
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx7
-rw-r--r--libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx17
7 files changed, 40 insertions, 23 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/Office.java b/android/Bootstrap/src/org/libreoffice/kit/Office.java
index 25861c92abfc..f344e21e109e 100644
--- a/android/Bootstrap/src/org/libreoffice/kit/Office.java
+++ b/android/Bootstrap/src/org/libreoffice/kit/Office.java
@@ -39,7 +39,7 @@ public class Office {
* @param type - type of key event
* @param code - key event code
*/
- public native void postKeyEvent(int type, int code);
+ public native void postKeyEvent(int type, int charCode, int keyCode);
public native void destroy();
public native void destroyAndExit();
diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
index 71dd17c442fb..8e7c4f6b9ce1 100644
--- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java
@@ -287,6 +287,23 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
this.tileInvalidationCallback = tileInvalidationCallback;
}
+ /**
+ * Returns the Unicode character generated by this event or 0.
+ */
+ private int getCharCode(KeyEvent keyEvent) {
+ switch (keyEvent.getKeyCode())
+ {
+ case KeyEvent.KEYCODE_DEL:
+ case KeyEvent.KEYCODE_ENTER:
+ return 0;
+ }
+ return keyEvent.getUnicodeChar();
+ }
+
+ /**
+ * Returns the integer code representing the key of the event (non-zero for
+ * control keys).
+ */
private int getKeyCode(KeyEvent keyEvent) {
switch (keyEvent.getKeyCode())
{
@@ -295,19 +312,17 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
case KeyEvent.KEYCODE_ENTER:
return com.sun.star.awt.Key.RETURN;
}
- return keyEvent.getUnicodeChar();
+ return 0;
}
@Override
public void keyPress(KeyEvent keyEvent) {
- int code = getKeyCode(keyEvent);
- mOffice.postKeyEvent(Office.KEY_PRESS, code);
+ mOffice.postKeyEvent(Office.KEY_PRESS, getCharCode(keyEvent), getKeyCode(keyEvent));
}
@Override
public void keyRelease(KeyEvent keyEvent) {
- int code = getKeyCode(keyEvent);
- mOffice.postKeyEvent(Office.KEY_RELEASE, code);
+ mOffice.postKeyEvent(Office.KEY_RELEASE, getCharCode(keyEvent), getKeyCode(keyEvent));
}
private void mouseButton(int type, PointF inDocument) {
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 3be8a2002eaa..a144b51969bf 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -265,7 +265,7 @@ static char * lo_getError (LibreOfficeKit* pThis);
static LibreOfficeKitDocument* lo_documentLoadWithOptions (LibreOfficeKit* pThis,
const char* pURL,
const char* pOptions);
-static void lo_postKeyEvent (LibreOfficeKit* pThis, int nType, int nCode);
+static void lo_postKeyEvent (LibreOfficeKit* pThis, int nType, int nCharCode, int nKeyCode);
struct LibLibreOffice_Impl : public _LibreOfficeKit
@@ -712,12 +712,12 @@ static char* lo_getError (LibreOfficeKit *pThis)
return pMemory;
}
-static void lo_postKeyEvent(LibreOfficeKit* /*pThis*/, int nType, int nCode)
+static void lo_postKeyEvent(LibreOfficeKit* /*pThis*/, int nType, int nCharCode, int nKeyCode)
{
#if defined(UNX) && !defined(MACOSX) && !defined(ENABLE_HEADLESS)
if (SalFrame *pFocus = SvpSalFrame::GetFocusFrame())
{
- KeyEvent aEvent(nCode, nCode, 0);
+ KeyEvent aEvent(nCharCode, nKeyCode, 0);
switch (nType)
{
case LOK_KEYEVENT_KEYINPUT:
diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx
index 5403ea0544ad..9ea1842975a3 100644
--- a/desktop/source/lib/lokandroid.cxx
+++ b/desktop/source/lib/lokandroid.cxx
@@ -76,10 +76,10 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroyAn
}
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_postKeyEvent
- (JNIEnv* pEnv, jobject aObject, jint nType, jint nCode)
+ (JNIEnv* pEnv, jobject aObject, jint nType, jint nCharCode, jint nKeyCode)
{
LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
- pLibreOfficeKit->pClass->postKeyEvent(pLibreOfficeKit, nType, nCode);
+ pLibreOfficeKit->pClass->postKeyEvent(pLibreOfficeKit, nType, nCharCode, nKeyCode);
}
namespace
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index ce1e63698686..c7dac9aed627 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -147,7 +147,7 @@ struct _LibreOfficeKitClass
const char* pURL,
const char* pOptions);
#ifdef LOK_USE_UNSTABLE_API
- void (*postKeyEvent) (LibreOfficeKit* pThis, int nType, int nCode);
+ void (*postKeyEvent) (LibreOfficeKit* pThis, int nType, int nCharCode, int nKeyCode);
#endif // LOK_USE_UNSTABLE_API
};
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 74c8533d980d..8f1958266c01 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -173,11 +173,12 @@ public:
* Posts a keyboard event to the focused frame.
*
* @param nType Event type, like press or release.
- * @param nCode Code of the key.
+ * @param nCharCode contains the Unicode character generated by this event or 0
+ * @param nKeyCode contains the integer code representing the key of the event (non-zero for control keys)
*/
- inline void postKeyEvent(int nType, int nCode)
+ inline void postKeyEvent(int nType, int nCharCode, int nKeyCode)
{
- mpThis->pClass->postKeyEvent(mpThis, nType, nCode);
+ mpThis->pClass->postKeyEvent(mpThis, nType, nCharCode, nKeyCode);
}
#endif // LOK_USE_UNSTABLE_API
};
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index c2fc02bb21ab..fbaa97fa224d 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -135,7 +135,8 @@ void changeQuadView( GtkWidget* /*pButton*/, gpointer /* pItem */ )
static void signalKey(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pData*/)
{
LOKDocView* pLOKDocView = LOK_DOCVIEW(pDocView);
- int nCode = 0;
+ int nCharCode = 0;
+ int nKeyCode = 0;
if (!pLOKDocView->m_bEdit)
{
@@ -146,25 +147,25 @@ static void signalKey(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pD
switch (pEvent->keyval)
{
case GDK_BackSpace:
- nCode = com::sun::star::awt::Key::BACKSPACE;
+ nKeyCode = com::sun::star::awt::Key::BACKSPACE;
break;
case GDK_Return:
- nCode = com::sun::star::awt::Key::RETURN;
+ nKeyCode = com::sun::star::awt::Key::RETURN;
break;
case GDK_Escape:
- nCode = com::sun::star::awt::Key::ESCAPE;
+ nKeyCode = com::sun::star::awt::Key::ESCAPE;
break;
default:
if (pEvent->keyval >= GDK_F1 && pEvent->keyval <= GDK_F26)
- nCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_F1);
+ nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_F1);
else
- nCode = gdk_keyval_to_unicode(pEvent->keyval);
+ nCharCode = gdk_keyval_to_unicode(pEvent->keyval);
}
if (pEvent->type == GDK_KEY_RELEASE)
- pLOKDocView->pOffice->pClass->postKeyEvent(pLOKDocView->pOffice, LOK_KEYEVENT_KEYUP, nCode);
+ pLOKDocView->pOffice->pClass->postKeyEvent(pLOKDocView->pOffice, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
else
- pLOKDocView->pOffice->pClass->postKeyEvent(pLOKDocView->pOffice, LOK_KEYEVENT_KEYINPUT, nCode);
+ pLOKDocView->pOffice->pClass->postKeyEvent(pLOKDocView->pOffice, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
}
// GtkComboBox requires gtk 2.24 or later