diff --git a/Sources/libewol/ewol/ShortCutManager.cpp b/Sources/libewol/ewol/ShortCutManager.cpp new file mode 100644 index 00000000..4dc7f162 --- /dev/null +++ b/Sources/libewol/ewol/ShortCutManager.cpp @@ -0,0 +1,143 @@ +/** + ******************************************************************************* + * @file ewol/ShortCutManager.cpp + * @brief ewol shortCut manager (Sources) + * @author Edouard DUPIN + * @date 22/02/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + + +#include +#include +#include + + +class EventShortCut { + public: + const char * generateEventId; // event generate ID (to be unique it was pointer on the string name) + etk::UString eventData; + bool shift; + bool control; + bool alt; + bool meta; + uniChar_t UnicodeValue; +}; + +static etk::VectorType l_inputShortCutEvent; //!< generic short-cut event + + +void ewol::shortCut::Add(bool shift, bool control, bool alt, bool meta, uniChar_t unicodeValue, const char * generateEventId, etk::UString& data) +{ + EventShortCut * newEvent = new EventShortCut(); + if (NULL == newEvent) { + EWOL_ERROR("Allocation Error on the shortcut ..."); + return; + } + newEvent->generateEventId = generateEventId; + newEvent->shift = shift; + newEvent->control = control; + newEvent->alt = alt; + newEvent->meta = meta; + newEvent->UnicodeValue = unicodeValue; + newEvent->eventData = data; + l_inputShortCutEvent.PushBack(newEvent); + return; +} + + +void ewol::shortCut::Add(char * descriptiveString, const char * generateEventId, etk::UString& data) +{ + if( NULL==descriptiveString + || 0==strlen(descriptiveString)) + { + return; + } + bool shift = false; + bool control = false; + bool alt = false; + bool meta = false; + uint32_t UnicodeValue = 0; + + // parsing of the string : + //"ctrl+shift+alt+meta+s" + char * tmp = strstr(descriptiveString, "ctrl"); + if(NULL != tmp) { + control = true; + } + tmp = strstr(descriptiveString, "shift"); + if(NULL != tmp) { + shift = true; + } + tmp = strstr(descriptiveString, "alt"); + if(NULL != tmp) { + alt = true; + } + tmp = strstr(descriptiveString, "meta"); + if(NULL != tmp) { + meta = true; + } + UnicodeValue = descriptiveString[strlen(descriptiveString) -1]; + // add with generic Adding function ... + ewol::shortCut::Add(shift, control, alt, meta, UnicodeValue, generateEventId, data); +} + + +void ewol::shortCut::Init(void) +{ + if (l_inputShortCutEvent.Size()>0) { + EWOL_WARNING("Old element error in the shortCut system"); + for(int32_t iii=0; iii< l_inputShortCutEvent.Size(); iii++) { + delete(l_inputShortCutEvent[iii]); + l_inputShortCutEvent[iii] = NULL; + } + } + l_inputShortCutEvent.Clear(); +} + +void ewol::shortCut::UnInit(void) +{ + if (l_inputShortCutEvent.Size()>0) { + for(int32_t iii=0; iii< l_inputShortCutEvent.Size(); iii++) { + delete(l_inputShortCutEvent[iii]); + l_inputShortCutEvent[iii] = NULL; + } + } + l_inputShortCutEvent.Clear(); +} + + + +bool ewol::shortCut::Process(bool shift, bool control, bool alt, bool meta, uniChar_t unicodeValue) +{ + //EWOL_INFO("Try to find generic shortcut ..."); + for(int32_t iii=l_inputShortCutEvent.Size()-1; iii>=0; iii--) { + if( l_inputShortCutEvent[iii]->shift == shift + && l_inputShortCutEvent[iii]->control == control + && l_inputShortCutEvent[iii]->alt == alt + && l_inputShortCutEvent[iii]->meta == meta + && l_inputShortCutEvent[iii]->UnicodeValue == unicodeValue) + { + ewol::widgetMessageMultiCast::Send(-1, l_inputShortCutEvent[iii]->generateEventId, l_inputShortCutEvent[iii]->eventData); + return true; + } + } + return false; +} + + diff --git a/Sources/libewol/ewol/ShortCutManager.h b/Sources/libewol/ewol/ShortCutManager.h new file mode 100644 index 00000000..5e530fd5 --- /dev/null +++ b/Sources/libewol/ewol/ShortCutManager.h @@ -0,0 +1,42 @@ +/** + ******************************************************************************* + * @file ewol/ShortCutManager.h + * @brief ewol shortCut manager (Header) + * @author Edouard DUPIN + * @date 22/02/2012 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_SHORT_CUT_MANAGER_H__ +#define __EWOL_SHORT_CUT_MANAGER_H__ + +#include +#include + +namespace ewol { + namespace shortCut { + void Init(void); + void UnInit(void); + bool Process(bool shift, bool control, bool alt, bool meta, uniChar_t unicodeValue); + }; +}; + + + +#endif + diff --git a/Sources/libewol/ewol/base/MainThread.cpp b/Sources/libewol/ewol/base/MainThread.cpp index 551f03db..89d85347 100644 --- a/Sources/libewol/ewol/base/MainThread.cpp +++ b/Sources/libewol/ewol/base/MainThread.cpp @@ -31,6 +31,7 @@ #include #include #include +#include @@ -89,8 +90,6 @@ void EWOL_NativeEventInputState(int pointerID, bool isUp, float x, float y ); void EWOL_NativeResize(int w, int h ); void EWOL_NativeRegenerateDisplay(void); - - static void* BaseAppEntry(void* param) { bool requestEndProcessing = false; @@ -118,6 +117,7 @@ static void* BaseAppEntry(void* param) ewol::texture::Init(); ewol::theme::Init(); ewol::InitFont(); + ewol::shortCut::Init(); APP_Init(); int32_t countNbEvent = 0; EWOL_DEBUG("==> Init BThread (END)"); @@ -161,6 +161,7 @@ static void* BaseAppEntry(void* param) { eventKeyboardKey_ts * tmpData = (eventKeyboardKey_ts*)data.data; guiAbstraction::SendKeyboardEvent(tmpData->isDown, tmpData->myChar); + //if (false==ewol::shortCut::Process(bool shift, bool control, bool alt, bool meta, uniChar_t unicodeValue)) { ... } } break; case THREAD_KEYBORAD_MOVE: @@ -201,6 +202,7 @@ static void* BaseAppEntry(void* param) // call application to uninit APP_UnInit(); + ewol::shortCut::UnInit(); ewol::texture::UnInit(); ewol::UnInitFont(); ewol::widgetManager::UnInit(); diff --git a/Sources/libewol/ewol/ewol.h b/Sources/libewol/ewol/ewol.h index 64a19c1f..f20408e1 100644 --- a/Sources/libewol/ewol/ewol.h +++ b/Sources/libewol/ewol/ewol.h @@ -55,6 +55,10 @@ namespace ewol { bool IsSetAltGr(void); bool IsSetVerNum(void); bool IsSetInsert(void); + namespace shortCut { + void Add(bool shift, bool control, bool alt, bool meta, uniChar_t unicodeValue, const char * generateEventId, etk::UString& data); + void Add(char * descriptiveString, const char * generateEventId, etk::UString& data); + }; }; int64_t GetCurrentTime(void); diff --git a/Sources/libewol/ewol/widget/WidgetShortCut.cpp b/Sources/libewol/ewol/widget/WidgetShortCut.cpp deleted file mode 100644 index bb4b1c28..00000000 --- a/Sources/libewol/ewol/widget/WidgetShortCut.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/** - ******************************************************************************* - * @file ewol/widget/WidgetShortCut.cpp - * @brief basic ewol short Cut widget (Sources) - * @author Edouard DUPIN - * @date 19/02/2012 - * @par Project - * ewol - * - * @par Copyright - * Copyright 2011 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * - * Term of the licence in in the file licence.txt. - * - ******************************************************************************* - */ - -#include - - -ewol::WidgetShortCut::WidgetShortCut(void) -{ - // nothing to do ... -} - -ewol::WidgetShortCut::~WidgetShortCut(void) -{ - //clean all the object - m_inputShortCutEvent.Clear(); -} - - - - -bool ewol::WidgetShortCut::AddEventShortCut(bool shift, bool control, bool alt, bool meta, uint32_t unicodeValue, const char * generateEventId) -{ - eventShortCut_ts newEvent; - newEvent.generateEventId = generateEventId; - newEvent.shift = shift; - newEvent.control = control; - newEvent.alt = alt; - newEvent.meta = meta; - newEvent.UnicodeValue = unicodeValue; - m_inputShortCutEvent.PushBack(newEvent); - return true; -} - - -bool ewol::WidgetShortCut::AddEventShortCut(char * descriptiveString, const char * generateEventId) -{ - if( NULL==descriptiveString - || 0==strlen(descriptiveString)) - { - return false; - } - bool shift = false; - bool control = false; - bool alt = false; - bool meta = false; - uint32_t UnicodeValue = 0; - - // parsing of the string : - //"ctrl+shift+alt+meta+s" - char * tmp = strstr(descriptiveString, "ctrl"); - if(NULL != tmp) { - control = true; - } - tmp = strstr(descriptiveString, "shift"); - if(NULL != tmp) { - shift = true; - } - tmp = strstr(descriptiveString, "alt"); - if(NULL != tmp) { - alt = true; - } - tmp = strstr(descriptiveString, "meta"); - if(NULL != tmp) { - meta = true; - } - UnicodeValue = descriptiveString[strlen(descriptiveString) -1]; - // add with generic Adding function ... - return AddEventShortCut(shift, control, alt, meta, UnicodeValue, generateEventId); -} - - - -bool ewol::WidgetShortCut::GenEventShortCut(bool shift, bool control, bool alt, bool meta, uint32_t unicodeValue) -{ - bool ended = false; - //EWOL_WARNING("Input event : " << IdInput << " pos(" << x << "," << y << ")"); - for(int32_t iii=m_inputShortCutEvent.Size()-1; iii>=0; iii--) { - if( m_inputShortCutEvent[iii].shift == shift - && m_inputShortCutEvent[iii].control == control - && m_inputShortCutEvent[iii].alt == alt - && m_inputShortCutEvent[iii].meta == meta - && m_inputShortCutEvent[iii].UnicodeValue == unicodeValue) - { - if (true == GenEventInputExternal(m_inputShortCutEvent[iii].generateEventId, -1, -1)) { - ended = true; - break; - } - } - } - return ended; -} - diff --git a/Sources/libewol/ewol/widget/WidgetShortCut.h b/Sources/libewol/ewol/widget/WidgetShortCut.h deleted file mode 100644 index 1494aa7f..00000000 --- a/Sources/libewol/ewol/widget/WidgetShortCut.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - ******************************************************************************* - * @file ewol/widget/WidgetShortCut.h - * @brief basic ewol shortCut widget (header) - * @author Edouard DUPIN - * @date 19/02/2012 - * @par Project - * ewol - * - * @par Copyright - * Copyright 2011 Edouard DUPIN, all right reserved - * - * This software is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY. - * - * Licence summary : - * You can modify and redistribute the sources code and binaries. - * You can send me the bug-fix - * - * Term of the licence in in the file licence.txt. - * - ******************************************************************************* - */ - -#ifndef __EWOL_WIDGET_SHORT_CUT_H__ -#define __EWOL_WIDGET_SHORT_CUT_H__ - -#include - - -namespace ewol { - - typedef struct { - const char * generateEventId; // event generate ID (to be unique it was pointer on the string name) - bool shift; - bool control; - bool alt; - bool meta; - uint32_t UnicodeValue; - } eventShortCut_ts; - - class WidgetShortCut : virtual public ewol::Widget { - public: - WidgetShortCut(void); - virtual ~WidgetShortCut(void); - private: - etk::VectorType m_inputShortCutEvent; //!< generic short-cut event - protected: - bool AddEventShortCut(bool shift, bool control, bool alt, bool pomme, uint32_t unicodeValue, const char * generateEventId); - bool AddEventShortCut(char * descriptiveString, const char * generateEventId); - public: - virtual bool GenEventShortCut(bool shift, bool control, bool alt, bool meta, uint32_t unicodeValue); - }; -}; - - -#endif - diff --git a/Sources/libewol/file.mk b/Sources/libewol/file.mk index 9ab303cf..50358cc0 100644 --- a/Sources/libewol/file.mk +++ b/Sources/libewol/file.mk @@ -17,8 +17,8 @@ FILE_LIST = ewol/ewol.cpp \ ewol/WidgetManager.cpp \ ewol/WidgetMessageMultiCast.cpp \ ewol/Windows.cpp \ + ewol/ShortCutManager.cpp \ ewol/widget/WidgetScrolled.cpp \ - ewol/widget/WidgetShortCut.cpp \ ewol/widget/Drawable.cpp \ ewol/widget/Button.cpp \ ewol/widget/Label.cpp \