Kaydet (Commit) 6650fe94 authored tarafından Miklos Vajna's avatar Miklos Vajna

LOK: move Office::postKeyEvent to Document

The implementation still sends them to the currently active VCL frame,
not to the given document, though.

Change-Id: I6fa2decdea3f949c55287e802cb3373c85664207
üst 645bebd9
......@@ -106,6 +106,14 @@ public class Document {
public native void initializeForRendering();
/**
* Post a key event to LibreOffice.
* @param type - type of key event
* @param charCode - the Unicode character generated by this event or 0.
* @param keyCode - the integer code representing the key of the event (non-zero for control keys).
*/
public native void postKeyEvent(int type, int charCode, int keyCode);
/**
* Post a mouse event to LOK
* @param type - mouse event type
......
......@@ -34,14 +34,6 @@ public class Office {
return document;
}
/**
* Post a key event to LibreOffice.
* @param type - type of key event
* @param charCode - the Unicode character generated by this event or 0.
* @param keyCode - the integer code representing the key of the event (non-zero for control keys).
*/
public native void postKeyEvent(int type, int charCode, int keyCode);
public native void destroy();
public native void destroyAndExit();
}
......@@ -313,12 +313,12 @@ public class LOKitTileProvider implements TileProvider, Document.MessageCallback
String keyString = keyEvent.getCharacters();
for (int i = 0; i < keyString.length(); i++) {
int codePoint = keyString.codePointAt(i);
mOffice.postKeyEvent(Office.KEY_PRESS, codePoint, getKeyCode(keyEvent));
mDocument.postKeyEvent(Office.KEY_PRESS, codePoint, getKeyCode(keyEvent));
}
} else if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
mOffice.postKeyEvent(Office.KEY_PRESS, getCharCode(keyEvent), getKeyCode(keyEvent));
mDocument.postKeyEvent(Office.KEY_PRESS, getCharCode(keyEvent), getKeyCode(keyEvent));
} else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
mOffice.postKeyEvent(Office.KEY_RELEASE, getCharCode(keyEvent), getKeyCode(keyEvent));
mDocument.postKeyEvent(Office.KEY_RELEASE, getCharCode(keyEvent), getKeyCode(keyEvent));
}
}
......
......@@ -203,6 +203,10 @@ static void doc_initializeForRendering(LibreOfficeKitDocument* pThis);
static void doc_registerCallback(LibreOfficeKitDocument* pThis,
LibreOfficeKitCallback pCallback,
void* pData);
static void doc_postKeyEvent(LibreOfficeKitDocument* pThis,
int nType,
int nCharCode,
int nKeyCode);
static void doc_postMouseEvent (LibreOfficeKitDocument* pThis,
int nType,
int nX,
......@@ -239,6 +243,7 @@ struct LibLODocument_Impl : public _LibreOfficeKitDocument
m_pDocumentClass->getDocumentSize = doc_getDocumentSize;
m_pDocumentClass->initializeForRendering = doc_initializeForRendering;
m_pDocumentClass->registerCallback = doc_registerCallback;
m_pDocumentClass->postKeyEvent = doc_postKeyEvent;
m_pDocumentClass->postMouseEvent = doc_postMouseEvent;
m_pDocumentClass->setTextSelection = doc_setTextSelection;
......@@ -266,7 +271,6 @@ 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 nCharCode, int nKeyCode);
struct LibLibreOffice_Impl : public _LibreOfficeKit
......@@ -286,7 +290,6 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit
m_pOfficeClass->documentLoad = lo_documentLoad;
m_pOfficeClass->getError = lo_getError;
m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
m_pOfficeClass->postKeyEvent = lo_postKeyEvent;
gOfficeClass = m_pOfficeClass;
}
......@@ -693,6 +696,25 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis,
pDoc->registerCallback(pCallback, pData);
}
static void doc_postKeyEvent(LibreOfficeKitDocument* /*pThis*/, int nType, int nCharCode, int nKeyCode)
{
#if defined(UNX) && !defined(MACOSX) && !defined(ENABLE_HEADLESS)
if (SalFrame *pFocus = SvpSalFrame::GetFocusFrame())
{
KeyEvent aEvent(nCharCode, nKeyCode, 0);
switch (nType)
{
case LOK_KEYEVENT_KEYINPUT:
Application::PostKeyEvent(VCLEVENT_WINDOW_KEYINPUT, pFocus->GetWindow(), &aEvent);
break;
case LOK_KEYEVENT_KEYUP:
Application::PostKeyEvent(VCLEVENT_WINDOW_KEYUP, pFocus->GetWindow(), &aEvent);
break;
}
}
#endif
}
static void doc_postMouseEvent(LibreOfficeKitDocument* pThis, int nType, int nX, int nY, int nCount)
{
ITiledRenderable* pDoc = getTiledRenderable(pThis);
......@@ -726,25 +748,6 @@ static char* lo_getError (LibreOfficeKit *pThis)
return pMemory;
}
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(nCharCode, nKeyCode, 0);
switch (nType)
{
case LOK_KEYEVENT_KEYINPUT:
Application::PostKeyEvent(VCLEVENT_WINDOW_KEYINPUT, pFocus->GetWindow(), &aEvent);
break;
case LOK_KEYEVENT_KEYUP:
Application::PostKeyEvent(VCLEVENT_WINDOW_KEYUP, pFocus->GetWindow(), &aEvent);
break;
}
}
#endif
}
static void force_c_locale(void)
{
// force locale (and resource files loaded) to en-US
......
......@@ -75,13 +75,6 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_destroyAn
_exit(0);
}
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Office_postKeyEvent
(JNIEnv* pEnv, jobject aObject, jint nType, jint nCharCode, jint nKeyCode)
{
LibreOfficeKit* pLibreOfficeKit = getHandle<LibreOfficeKit>(pEnv, aObject);
pLibreOfficeKit->pClass->postKeyEvent(pLibreOfficeKit, nType, nCharCode, nKeyCode);
}
namespace
{
......@@ -277,6 +270,13 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs
return result;
}
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postKeyEvent
(JNIEnv* pEnv, jobject aObject, jint nType, jint nCharCode, jint nKeyCode)
{
LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject);
pDocument->pClass->postKeyEvent(pDocument, nType, nCharCode, nKeyCode);
}
extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_postMouseEvent
(JNIEnv* pEnv, jobject aObject, jint type, jint x, jint y, jint count)
{
......
......@@ -49,9 +49,6 @@ struct _LibreOfficeKitClass
LibreOfficeKitDocument* (*documentLoadWithOptions) (LibreOfficeKit* pThis,
const char* pURL,
const char* pOptions);
#ifdef LOK_USE_UNSTABLE_API
void (*postKeyEvent) (LibreOfficeKit* pThis, int nType, int nCharCode, int nKeyCode);
#endif // LOK_USE_UNSTABLE_API
};
#define LIBREOFFICEKIT_DOCUMENT_HAS(pDoc,member) LIBREOFFICEKIT_HAS_MEMBER(LibreOfficeKitDocumentClass,member,(pDoc)->pClass->nSize)
......@@ -125,6 +122,11 @@ struct _LibreOfficeKitDocumentClass
LibreOfficeKitCallback pCallback,
void* pData);
/// @see lok::Document::postKeyEvent
void (*postKeyEvent)(LibreOfficeKitDocument* pThis,
int nType,
int nCharCode,
int nKeyCode);
/// @see lok::Document::postMouseEvent
void (*postMouseEvent)(LibreOfficeKitDocument* pThis,
int nType,
......
......@@ -105,6 +105,18 @@ public:
mpDoc->pClass->registerCallback(mpDoc, pCallback, pData);
}
/**
* Posts a keyboard event to the focused frame.
*
* @param nType Event type, like press or release.
* @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 nCharCode, int nKeyCode)
{
mpDoc->pClass->postKeyEvent(mpDoc, nType, nCharCode, nKeyCode);
}
/**
* Posts a mouse event to the document.
*
......@@ -167,20 +179,6 @@ public:
{
return mpThis->pClass->getError(mpThis);
}
#ifdef LOK_USE_UNSTABLE_API
/**
* Posts a keyboard event to the focused frame.
*
* @param nType Event type, like press or release.
* @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 nCharCode, int nKeyCode)
{
mpThis->pClass->postKeyEvent(mpThis, nType, nCharCode, nKeyCode);
}
#endif // LOK_USE_UNSTABLE_API
};
inline Office* lok_cpp_init(const char* pInstallPath)
......
......@@ -186,9 +186,9 @@ static void signalKey(GtkWidget* /*pWidget*/, GdkEventKey* pEvent, gpointer /*pD
nKeyCode |= KEY_SHIFT;
if (pEvent->type == GDK_KEY_RELEASE)
pLOKDocView->pOffice->pClass->postKeyEvent(pLOKDocView->pOffice, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
pLOKDocView->pDocument->pClass->postKeyEvent(pLOKDocView->pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
else
pLOKDocView->pOffice->pClass->postKeyEvent(pLOKDocView->pOffice, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
pLOKDocView->pDocument->pClass->postKeyEvent(pLOKDocView->pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
}
// GtkComboBox requires gtk 2.24 or later
......
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