From 6e92491a9f2cffbae8d6bc1d767f2057dba5eafe Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Tue, 22 Nov 2011 17:56:04 +0100 Subject: [PATCH] First step to generate the keyboard event directly on the correct widget --- Sources/base/guiX11.cpp | 19 ++++++++++++++----- Sources/ewolOObject2DColored.cpp | 5 ++++- Sources/widget/ewolButton.cpp | 18 +++++++++++++++++- Sources/widget/ewolButton.h | 1 + Sources/widget/ewolCheckBox.cpp | 20 +++++++++++++++++++- Sources/widget/ewolCheckBox.h | 1 + 6 files changed, 56 insertions(+), 8 deletions(-) diff --git a/Sources/base/guiX11.cpp b/Sources/base/guiX11.cpp index fe2b86c6..9c2c90ad 100644 --- a/Sources/base/guiX11.cpp +++ b/Sources/base/guiX11.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -642,17 +643,25 @@ namespace guiAbstraction { break; case KeyPress: case KeyRelease: - EWOL_DEBUG("X11 event : " << event.type << " = \"KeyPress/KeyRelease\" "); + //EWOL_DEBUG("X11 event : " << event.type << " = \"KeyPress/KeyRelease\" "); { char buf[11]; KeySym keysym; XComposeStatus status; int count = XLookupString(&event.xkey, buf, 10, &keysym, &status); buf[count] = '\0'; - if(event.type == KeyPress) { - // TODO : set the char here... - } else { - // TODO : set the char here... + // Get the current Focused Widget : + ewol::Widget * tmpWidget = ewol::widgetManager::FocusGet(); + if (NULL != tmpWidget) { + if(event.type == KeyPress) { + // TODO : set the char here... + EWOL_DEBUG("X11 PRESSED : \"" << buf << "\" size=" << count); + tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_DOWN, buf); + } else { + // TODO : set the char here... + EWOL_DEBUG("X11 Release : \"" << buf << "\" size=" << count); + tmpWidget->OnEventKb(ewol::EVENT_KB_TYPE_UP, buf); + } } break; } diff --git a/Sources/ewolOObject2DColored.cpp b/Sources/ewolOObject2DColored.cpp index 6567021e..f6ec8937 100644 --- a/Sources/ewolOObject2DColored.cpp +++ b/Sources/ewolOObject2DColored.cpp @@ -84,6 +84,7 @@ void generatePolyGone(etk::VectorType & input, etk::VectorType #include - +#include const char * const ewolEventButtonPressed = "ewol Button Pressed"; @@ -49,6 +49,7 @@ void ewol::Button::Init(void) m_textColorBg.green = 0.0; m_textColorBg.blue = 0.0; m_textColorBg.alpha = 0.25; + SetCanHaveFocus(true); } ewol::Button::Button(void) @@ -172,8 +173,23 @@ bool ewol::Button::OnEventArea(const char * generateEventId, etkFloat_t x, etkFl if(ewolEventButtonPressed == generateEventId) { EWOL_INFO("BT pressed ... " << m_label); eventIsOK = true; + ewol::widgetManager::FocusKeep(this); } else if(ewolEventButtonEnter == generateEventId) { OnRegenerateDisplay(); } return eventIsOK; } + + +bool ewol::Button::OnEventKb(eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE]) +{ + //EWOL_DEBUG("BT PRESSED : \"" << UTF8_data << "\" size=" << strlen(UTF8_data)); + if( UTF8_data != NULL + && typeEvent == ewol::EVENT_KB_TYPE_DOWN + && UTF8_data[0] == '\r') { + return OnEventArea(ewolEventButtonPressed, -1, -1); + } + return false; +} + + diff --git a/Sources/widget/ewolButton.h b/Sources/widget/ewolButton.h index 19df1b42..b1802b56 100644 --- a/Sources/widget/ewolButton.h +++ b/Sources/widget/ewolButton.h @@ -54,6 +54,7 @@ namespace ewol { public: //virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, etkFloat_t x, etkFloat_t y); virtual bool OnEventArea(const char * generateEventId, etkFloat_t x, etkFloat_t y); + virtual bool OnEventKb(eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE]); }; }; diff --git a/Sources/widget/ewolCheckBox.cpp b/Sources/widget/ewolCheckBox.cpp index a06ee03c..8703727a 100644 --- a/Sources/widget/ewolCheckBox.cpp +++ b/Sources/widget/ewolCheckBox.cpp @@ -26,6 +26,8 @@ #include #include +#include + const char * ewolEventCheckBoxClicked = "ewol CheckBox Clicked"; @@ -45,6 +47,7 @@ void ewol::CheckBox::Init(void) m_textColorBg.blue = 1.0; m_textColorBg.alpha = 1.0; m_value = false; + SetCanHaveFocus(true); } ewol::CheckBox::CheckBox(void) @@ -109,7 +112,7 @@ void ewol::CheckBox::OnRegenerateDisplay(void) int32_t fontHeight = ewol::GetHeight(fontId); int32_t fontWidth = ewol::GetWidth(fontId, m_label.c_str()); int32_t posy = (m_size.y - fontHeight - 6)/2 + 3; - int32_t posx = (m_size.x - fontWidth - 6)/2 + 25; + //int32_t posx = (m_size.x - fontWidth - 6)/2 + 25; tmpText->Text(25, posy+3, m_label.c_str()); @@ -151,6 +154,7 @@ bool ewol::CheckBox::OnEventArea(const char * generateEventId, etkFloat_t x, etk bool eventIsOK = false; //EWOL_DEBUG("Receive event : \"" << generateEventId << "\""); if(ewolEventCheckBoxClicked == generateEventId) { + ewol::widgetManager::FocusKeep(this); EWOL_INFO("CB pressed ... " << m_label); if(true == m_value) { m_value = false; @@ -162,3 +166,17 @@ bool ewol::CheckBox::OnEventArea(const char * generateEventId, etkFloat_t x, etk } return eventIsOK; } + +bool ewol::CheckBox::OnEventKb(eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE]) +{ + //EWOL_DEBUG("BT PRESSED : \"" << UTF8_data << "\" size=" << strlen(UTF8_data)); + if( UTF8_data != NULL + && typeEvent == ewol::EVENT_KB_TYPE_DOWN + && ( UTF8_data[0] == '\r' + || UTF8_data[0] == ' ') + ) { + return OnEventArea(ewolEventCheckBoxClicked, -1, -1); + } + return false; +} + diff --git a/Sources/widget/ewolCheckBox.h b/Sources/widget/ewolCheckBox.h index ac6ba9e9..8b20399a 100644 --- a/Sources/widget/ewolCheckBox.h +++ b/Sources/widget/ewolCheckBox.h @@ -55,6 +55,7 @@ namespace ewol { public: //virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, etkFloat_t x, etkFloat_t y); virtual bool OnEventArea(const char * generateEventId, etkFloat_t x, etkFloat_t y); + virtual bool OnEventKb(eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE]); }; };