include/vcl/dialog.hxx | 3 libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx | 126 +++++++++++++++++++- libreofficekit/source/gtk/lokdocview.cxx | 41 +----- sw/source/uibase/uno/unotxdoc.cxx | 31 ++++ vcl/source/window/dialog.cxx | 16 ++ 5 files changed, 182 insertions(+), 35 deletions(-)
New commits: commit 1fdc2503344a7aeea7f351e7899b5155ffc4e101 Author: Pranav Kant <pran...@collabora.co.uk> Date: Sun Jul 30 06:06:56 2017 +0530 lokdialog: Handle key events in core Change-Id: If84aaac87beebf69d92db5446fc713d8cc20421e diff --git a/include/vcl/dialog.hxx b/include/vcl/dialog.hxx index fb0e0751ddc8..f0425a961cf3 100644 --- a/include/vcl/dialog.hxx +++ b/include/vcl/dialog.hxx @@ -74,6 +74,9 @@ public: void LogicMouseButtonUp(const MouseEvent& rMouseEvent); void LogicMouseMove(const MouseEvent& rMouseEvent); + void KeyInput(const KeyEvent& rKeyEvent); + void KeyUp(const KeyEvent& rKeyEvent); + protected: explicit Dialog( WindowType nType ); explicit Dialog( vcl::Window* pParent, const OUString& rID, const OUString& rUIXMLDescription, WindowType nType, InitFlag eFlag = InitFlag::Default ); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 095ba9fee5f6..3be26d0f28b6 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -3581,9 +3581,38 @@ void SwXTextDocument::paintDialog(const vcl::DialogID& rDialogID, VirtualDevice& nHeight = aSize.getHeight(); } -void SwXTextDocument::postDialogKeyEvent(const vcl::DialogID& /*rDialogID*/, int /*nType*/, int /*nCharCode*/, int /*nKeyCode*/) +void SwXTextDocument::postDialogKeyEvent(const vcl::DialogID& rDialogID, int nType, int nCharCode, int nKeyCode) { + SolarMutexGuard aGuard; + + // check if dialog is already open + SfxViewFrame* pViewFrame = pDocShell->GetView()->GetViewFrame(); + SfxSlotPool* pSlotPool = SW_MOD()->GetSlotPool(); + const SfxSlot* pSlot = pSlotPool->GetUnoSlot(rDialogID); + if (!pSlot) + { + SAL_WARN("lok.dialog", "No slot found for " << rDialogID); + return; + } + SfxChildWindow* pChild = pViewFrame->GetChildWindow(pSlot->GetSlotId()); + if (pChild) + { + Dialog* pDialog = static_cast<Dialog*>(pChild->GetWindow()); + KeyEvent aEvent(nCharCode, nKeyCode, 0); + switch (nType) + { + case LOK_KEYEVENT_KEYINPUT: + pDialog->KeyInput(aEvent); + break; + case LOK_KEYEVENT_KEYUP: + pDialog->KeyUp(aEvent); + break; + default: + assert(false); + break; + } + } } void SwXTextDocument::postDialogMouseEvent(const vcl::DialogID& rDialogID, int nType, int nX, int nY, diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx index ee606eae351e..897bc8f74543 100644 --- a/vcl/source/window/dialog.cxx +++ b/vcl/source/window/dialog.cxx @@ -888,6 +888,22 @@ void Dialog::LogicMouseMove(const MouseEvent& rMouseEvent) ImplWindowFrameProc(this, SalEvent::ExternalMouseMove, &rMouseEvent); } +void Dialog::KeyInput(const KeyEvent& rKeyEvent) +{ + // as of now only lok uses it + assert(comphelper::LibreOfficeKit::isActive()); + + ImplWindowFrameProc(this, SalEvent::ExternalKeyInput, &rKeyEvent); +} + +void Dialog::KeyUp(const KeyEvent& rKeyEvent) +{ + // as of now only lok uses it + assert(comphelper::LibreOfficeKit::isActive()); + + ImplWindowFrameProc(this, SalEvent::ExternalKeyUp, &rKeyEvent); +} + void Dialog::ensureRepaint() { // ensure repaint commit bee77206ff3ff7138b957a411d8f35ad5ffbdf8d Author: Pranav Kant <pran...@collabora.co.uk> Date: Sun Jul 30 05:18:33 2017 +0530 lokdialog: gtv: Forward key events on dialog to core Change-Id: Icfc210b08c7f1d8ebaf9c731ed64bb128cfc4356 diff --git a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx index 7a9fa7712900..bb8800e3d734 100644 --- a/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx +++ b/libreofficekit/qa/gtktiledviewer/gtv-lok-dialog.cxx @@ -8,9 +8,11 @@ */ #include <gtk/gtk.h> +#include <gdk/gdkkeysyms.h> #include <cmath> #include <iostream> +#include <sstream> #include <LibreOfficeKit/LibreOfficeKitGtk.h> #include <LibreOfficeKit/LibreOfficeKitEnums.h> @@ -136,7 +138,7 @@ gtv_lok_dialog_signal_button(GtkWidget* pDialogDrawingArea, GdkEventButton* pEve (pEvent->y), nCount, nEventButton, - 0/* Modifier */); + priv->m_nKeyModifier); break; } @@ -167,7 +169,7 @@ gtv_lok_dialog_signal_button(GtkWidget* pDialogDrawingArea, GdkEventButton* pEve (pEvent->y), nCount, nEventButton, - 0/* Modifier */); + priv->m_nKeyModifier); break; } default: @@ -198,7 +200,119 @@ gtv_lok_dialog_signal_motion(GtkWidget* pDialogDrawingArea, GdkEventButton* pEve (pEvent->y), 1, priv->m_nLastButtonPressed, - 0/* Modifier */); + priv->m_nKeyModifier); + + return FALSE; +} + +static gboolean +gtv_lok_dialog_signal_key(GtkWidget* pDialogDrawingArea, GdkEventKey* pEvent) +{ + GtvLokDialog* pDialog = GTV_LOK_DIALOG(gtk_widget_get_toplevel(pDialogDrawingArea)); + GtvLokDialogPrivate* priv = getPrivate(pDialog); + GtvApplicationWindow* window = GTV_APPLICATION_WINDOW(gtk_window_get_transient_for(GTK_WINDOW(pDialog))); + LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(window->lokdocview)); + + int nCharCode = 0; + int nKeyCode = 0; + priv->m_nKeyModifier &= KEY_MOD2; + switch (pEvent->keyval) + { + case GDK_KEY_BackSpace: + nKeyCode = com::sun::star::awt::Key::BACKSPACE; + break; + case GDK_KEY_Delete: + nKeyCode = com::sun::star::awt::Key::DELETE; + break; + case GDK_KEY_Return: + case GDK_KEY_KP_Enter: + nKeyCode = com::sun::star::awt::Key::RETURN; + break; + case GDK_KEY_Escape: + nKeyCode = com::sun::star::awt::Key::ESCAPE; + break; + case GDK_KEY_Tab: + nKeyCode = com::sun::star::awt::Key::TAB; + break; + case GDK_KEY_Down: + nKeyCode = com::sun::star::awt::Key::DOWN; + break; + case GDK_KEY_Up: + nKeyCode = com::sun::star::awt::Key::UP; + break; + case GDK_KEY_Left: + nKeyCode = com::sun::star::awt::Key::LEFT; + break; + case GDK_KEY_Right: + nKeyCode = com::sun::star::awt::Key::RIGHT; + break; + case GDK_KEY_Page_Down: + nKeyCode = com::sun::star::awt::Key::PAGEDOWN; + break; + case GDK_KEY_Page_Up: + nKeyCode = com::sun::star::awt::Key::PAGEUP; + break; + case GDK_KEY_Insert: + nKeyCode = com::sun::star::awt::Key::INSERT; + break; + case GDK_KEY_Shift_L: + case GDK_KEY_Shift_R: + if (pEvent->type == GDK_KEY_PRESS) + priv->m_nKeyModifier |= KEY_SHIFT; + break; + case GDK_KEY_Control_L: + case GDK_KEY_Control_R: + if (pEvent->type == GDK_KEY_PRESS) + priv->m_nKeyModifier |= KEY_MOD1; + break; + case GDK_KEY_Alt_L: + case GDK_KEY_Alt_R: + if (pEvent->type == GDK_KEY_PRESS) + priv->m_nKeyModifier |= KEY_MOD2; + else + priv->m_nKeyModifier &= ~KEY_MOD2; + break; + default: + if (pEvent->keyval >= GDK_KEY_F1 && pEvent->keyval <= GDK_KEY_F26) + nKeyCode = com::sun::star::awt::Key::F1 + (pEvent->keyval - GDK_KEY_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->state & GDK_CONTROL_MASK) + nKeyCode |= KEY_MOD1; + + if (priv->m_nKeyModifier & KEY_MOD2) + nKeyCode |= KEY_MOD2; + + if (nKeyCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)) { + if (pEvent->keyval >= GDK_KEY_a && pEvent->keyval <= GDK_KEY_z) + { + nKeyCode |= 512 + (pEvent->keyval - GDK_KEY_a); + } + else if (pEvent->keyval >= GDK_KEY_A && pEvent->keyval <= GDK_KEY_Z) { + nKeyCode |= 512 + (pEvent->keyval - GDK_KEY_A); + } + else if (pEvent->keyval >= GDK_KEY_0 && pEvent->keyval <= GDK_KEY_9) { + nKeyCode |= 256 + (pEvent->keyval - GDK_KEY_0); + } + } + + std::stringstream ss; + ss << "gtv_lok_dialog::postKey(" << pEvent->type << ", " << nCharCode << ", " << nKeyCode << ")"; + g_info("%s", ss.str().c_str()); + + pDocument->pClass->postDialogKeyEvent(pDocument, + priv->dialogid, + pEvent->type == GDK_KEY_RELEASE ? LOK_KEYEVENT_KEYUP : LOK_KEYEVENT_KEYINPUT, + nCharCode, + nKeyCode); return FALSE; } @@ -219,12 +333,16 @@ gtv_lok_dialog_init(GtvLokDialog* dialog) gtk_widget_add_events(GTK_WIDGET(priv->pDialogDrawingArea), GDK_BUTTON_PRESS_MASK |GDK_BUTTON_RELEASE_MASK - |GDK_BUTTON_MOTION_MASK); + |GDK_BUTTON_MOTION_MASK + |GDK_KEY_PRESS_MASK + |GDK_KEY_RELEASE_MASK); g_signal_connect(G_OBJECT(priv->pDialogDrawingArea), "draw", G_CALLBACK(gtv_lok_dialog_draw), nullptr); g_signal_connect(G_OBJECT(priv->pDialogDrawingArea), "button-press-event", G_CALLBACK(gtv_lok_dialog_signal_button), nullptr); g_signal_connect(G_OBJECT(priv->pDialogDrawingArea), "button-release-event", G_CALLBACK(gtv_lok_dialog_signal_button), nullptr); g_signal_connect(G_OBJECT(priv->pDialogDrawingArea), "motion-notify-event", G_CALLBACK(gtv_lok_dialog_signal_motion), nullptr); + g_signal_connect(G_OBJECT(priv->pDialogDrawingArea), "key-press-event", G_CALLBACK(gtv_lok_dialog_signal_key), nullptr); + g_signal_connect(G_OBJECT(priv->pDialogDrawingArea), "key-release-event", G_CALLBACK(gtv_lok_dialog_signal_key), nullptr); gtk_container_add(GTK_CONTAINER(pContentArea), priv->pDialogDrawingArea); } commit eca1cb8bbd243edede4a9ed284a79212b0d585b2 Author: Pranav Kant <pran...@collabora.co.uk> Date: Sun Jul 30 05:16:39 2017 +0530 lokdocview: Remove unnecessary code Change-Id: I1d744c91f01eb098e9273d2459b63a5444558f39 diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 3ee8641c6472..d3bd91eced2a 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -812,38 +812,19 @@ signalKey (GtkWidget* pWidget, GdkEventKey* pEvent) } } - if (pEvent->type == GDK_KEY_RELEASE) - { - GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr); - LOEvent* pLOEvent = new LOEvent(LOK_POST_KEY); - pLOEvent->m_nKeyEvent = LOK_KEYEVENT_KEYUP; - pLOEvent->m_nCharCode = nCharCode; - pLOEvent->m_nKeyCode = nKeyCode; - g_task_set_task_data(task, pLOEvent, LOEvent::destroy); - g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), &error); - if (error != nullptr) - { - g_warning("Unable to call LOK_POST_KEY: %s", error->message); - g_clear_error(&error); - } - g_object_unref(task); - } - else + GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr); + LOEvent* pLOEvent = new LOEvent(LOK_POST_KEY); + pLOEvent->m_nKeyEvent = pEvent->type == GDK_KEY_RELEASE ? LOK_KEYEVENT_KEYUP : LOK_KEYEVENT_KEYINPUT; + pLOEvent->m_nCharCode = nCharCode; + pLOEvent->m_nKeyCode = nKeyCode; + g_task_set_task_data(task, pLOEvent, LOEvent::destroy); + g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), &error); + if (error != nullptr) { - GTask* task = g_task_new(pDocView, nullptr, nullptr, nullptr); - LOEvent* pLOEvent = new LOEvent(LOK_POST_KEY); - pLOEvent->m_nKeyEvent = LOK_KEYEVENT_KEYINPUT; - pLOEvent->m_nCharCode = nCharCode; - pLOEvent->m_nKeyCode = nKeyCode; - g_task_set_task_data(task, pLOEvent, LOEvent::destroy); - g_thread_pool_push(priv->lokThreadPool, g_object_ref(task), &error); - if (error != nullptr) - { - g_warning("Unable to call LOK_POST_KEY: %s", error->message); - g_clear_error(&error); - } - g_object_unref(task); + g_warning("Unable to call LOK_POST_KEY: %s", error->message); + g_clear_error(&error); } + g_object_unref(task); return FALSE; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits