[DEV] some rework on ewol...

This commit is contained in:
Edouard DUPIN 2014-08-25 21:08:13 +02:00
parent 367831116f
commit 6e39002da5
7 changed files with 87 additions and 94 deletions

View File

@ -18,6 +18,8 @@
namespace ewol {
namespace object {
#undef __class__
#define __class__ "object::Signal<T>"
template<typename T> class Signal : public SignalBase {
private:
std::vector<std::pair<std::weak_ptr<ewol::Object>,
@ -46,7 +48,7 @@ namespace ewol {
* @brief Bind a callback function to the current signal (generic methis (simplest))
* @param[in] _obj Shared pointer on the caller object
* @param[in] _func Link on the fuction that might be called (inside a class)
* @example signalXXXX.connect(shared_from_this(), &ClassName::onCallbackXXX);
* @example signalXXXX.bind(shared_from_this(), &ClassName::onCallbackXXX);
*/
template<class TYPE> void bind(std::shared_ptr<ewol::Object> _obj, void (TYPE::*_func)(const T&)) {
std::shared_ptr<TYPE> obj2 = std::dynamic_pointer_cast<TYPE>(_obj);
@ -89,11 +91,13 @@ namespace ewol {
EWOL_VERBOSE(" nullptr dest");
continue;
}
EWOL_DEBUG("emit signal : '" << m_name << "' to [" << destObject->getId() << "] data='" << etk::to_string(_data) << "'");
it.second(_data);
}
}
};
#undef __class__
#define __class__ "object::Signal<void>"
template<> class Signal<void> : public SignalBase {
private:
std::vector<std::pair<std::weak_ptr<ewol::Object>, std::function<void()>>> m_callerList;
@ -161,11 +165,13 @@ namespace ewol {
EWOL_VERBOSE(" nullptr dest");
continue;
}
EWOL_DEBUG("emit signal : '" << m_name << "' to [" << destObject->getId() << "] BANG!!!");
it.second();
}
}
};
#undef __class__
#define __class__ nullptr
};
};
#endif

View File

@ -44,22 +44,23 @@ ewol::widget::Entry::Entry() :
m_displayCursorPosSelection(0),
m_textWhenNothing(*this, "emptytext", "", "Text that is displayed when the Entry is empty (decorated text)") {
addObjectType("ewol::widget::Entry");
setCanHaveFocus(true);
shortCutAdd("ctrl+w", ewolEventEntryClean);
shortCutAdd("ctrl+x", ewolEventEntryCut);
shortCutAdd("ctrl+c", ewolEventEntryCopy);
shortCutAdd("ctrl+v", ewolEventEntryPaste);
shortCutAdd("ctrl+a", ewolEventEntrySelect, "ALL");
shortCutAdd("ctrl+shift+a", ewolEventEntrySelect, "NONE");
m_regExp.setString(".*");
markToRedraw();
}
void ewol::widget::Entry::init(const std::string& _newData) {
ewol::Widget::init();
m_data.set(_newData);
m_shaper.setString("THEME:GUI:Entry.json");
setCanHaveFocus(true);
m_regExp.setString(".*");
markToRedraw();
shortCutAdd("ctrl+w", "clean");
shortCutAdd("ctrl+x", "cut");
shortCutAdd("ctrl+c", "copy");
shortCutAdd("ctrl+v", "paste");
shortCutAdd("ctrl+a", "select:all");
shortCutAdd("ctrl+shift+a", "select:none");
signalShortcut.bind(shared_from_this(), &ewol::widget::Entry::onCallbackShortCut);
}
@ -67,6 +68,10 @@ ewol::widget::Entry::~Entry() {
}
void ewol::widget::Entry::onCallbackShortCut(const std::string& _value) {
EWOL_WARNING("Event from ShortCut : " << _value);
}
void ewol::widget::Entry::calculateMinMaxSize() {
// call main class
ewol::Widget::calculateMinMaxSize();

View File

@ -176,6 +176,8 @@ namespace ewol {
virtual void changeStatusIn(int32_t _newStatusId);
virtual void periodicCall(const ewol::event::Time& _event);
virtual void onParameterChangeValue(const ewol::object::ParameterRef& _paramPointer);
private: // callback functions
void onCallbackShortCut(const std::string& _value);
};
};
};

View File

@ -18,7 +18,8 @@
#undef __class__
#define __class__ "Menu"
ewol::widget::Menu::Menu() {
ewol::widget::Menu::Menu() :
signalSelect(*this, "select") {
addObjectType("ewol::widget::Menu");
m_staticId = 0;
}
@ -55,9 +56,8 @@ void ewol::widget::Menu::clear() {
int32_t ewol::widget::Menu::addTitle(std::string _label,
std::string _image,
const char * _generateEvent,
const std::string _message) {
return add(-1, _label, _image, _generateEvent, _message);
return add(-1, _label, _image, _message);
}
static const char* eventButtonPressed = "menu-local-pressed";
@ -65,14 +65,12 @@ static const char* eventButtonPressed = "menu-local-pressed";
int32_t ewol::widget::Menu::add(int32_t _parent,
std::string _label,
std::string _image,
const char *_generateEvent,
const std::string _message) {
ewol::widget::MenuElement tmpObject;
tmpObject.m_localId = m_staticId++;
tmpObject.m_parentId = _parent;
tmpObject.m_label = std::string("<left>") + _label + "</left>";
tmpObject.m_image = _image;
tmpObject.m_generateEvent = _generateEvent;
tmpObject.m_message = _message;
if (-1 == tmpObject.m_parentId) {
std::shared_ptr<ewol::widget::Button> myButton = ewol::widget::Button::create();
@ -116,10 +114,10 @@ void ewol::widget::Menu::onButtonPressed(std::weak_ptr<ewol::widget::Button> _bu
for (auto &it : m_listElement) {
if (caller == it.m_widgetPointer.lock()) {
// 2 posible case (have a message or have a child ...
if (it.m_generateEvent != nullptr) {
if (it.m_message.size() > 0) {
EWOL_DEBUG("Menu == > generate Event");
// Send a multicast event ...
sendMultiCast(it.m_generateEvent, it.m_message);
signalSelect.emit(it.m_message);
std::shared_ptr<ewol::widget::ContextMenu> tmpContext = m_widgetContextMenu.lock();
if (tmpContext != nullptr) {
EWOL_DEBUG("Mark the menu to remove ...");

View File

@ -27,13 +27,14 @@ namespace ewol {
std::weak_ptr<ewol::Widget> m_widgetPointer;
std::string m_label;
std::string m_image;
const char* m_generateEvent;
std::string m_message;
};
/**
* @ingroup ewolWidgetGroup
*/
class Menu :public ewol::widget::Sizer {
public:
ewol::object::Signal<std::string> signalSelect; // event on a menu button or ...
protected:
Menu();
void init();
@ -51,8 +52,8 @@ namespace ewol {
std::weak_ptr<ewol::widget::ContextMenu> m_widgetContextMenu;
public:
void clear();
int32_t addTitle(std::string _label, std::string _image="", const char * _generateEvent = nullptr, const std::string _message = "");
int32_t add(int32_t _parent, std::string _label, std::string _image="", const char * _generateEvent = nullptr, const std::string _message = "");
int32_t addTitle(std::string _label, std::string _image="", const std::string _message = "");
int32_t add(int32_t _parent, std::string _label, std::string _image="", const std::string _message = "");
void addSpacer();
// Derived function
virtual void onReceiveMessage(const ewol::object::Message& _msg);

View File

@ -105,6 +105,7 @@ ewol::Widget::Widget() :
m_allowRepeateKeyboardEvent(true),
m_periodicCallDeltaTime(-1),
m_periodicCallTime(0),
signalShortcut(*this, "shortcut"),
m_needRegenerateDisplay(true),
m_grabCursor(false),
m_cursorDisplay(ewol::context::cursorArrow),
@ -425,12 +426,8 @@ const bvec2& ewol::Widget::canFill() {
// -- Shortcut : management of the shortcut
// ----------------------------------------------------------------------------------------------------------------
void ewol::Widget::shortCutAdd(const char * _descriptiveString,
const char * _generateEventId,
std::string _data,
bool _broadcast) {
if ( _descriptiveString == nullptr
|| strlen(_descriptiveString) == 0) {
void ewol::Widget::shortCutAdd(const std::string& _descriptiveString, const std::string& _message) {
if (_descriptiveString.size() == 0) {
EWOL_ERROR("try to add shortcut with no descriptive string ...");
return;
}
@ -439,83 +436,81 @@ void ewol::Widget::shortCutAdd(const char * _descriptiveString,
EWOL_ERROR("allocation error ... Memory error ...");
return;
}
tmpElement->broadcastEvent = _broadcast;
tmpElement->generateEventId = _generateEventId;
tmpElement->eventData = _data;
if (_message.size() == 0) {
tmpElement->message = _descriptiveString;
} else {
tmpElement->message = _message;
}
// parsing of the string :
//"ctrl+shift+alt+meta+s"
const char * tmp = strstr(_descriptiveString, "ctrl");
if(nullptr != tmp) {
if(_descriptiveString.find("ctrl") != std::string::npos) {
tmpElement->specialKey.setCtrl(true);
}
tmp = strstr(_descriptiveString, "shift");
if(nullptr != tmp) {
if(_descriptiveString.find("shift") != std::string::npos) {
tmpElement->specialKey.setShift(true);
}
tmp = strstr(_descriptiveString, "alt");
if(nullptr != tmp) {
if(_descriptiveString.find("alt") != std::string::npos) {
tmpElement->specialKey.setAlt(true);
}
tmp = strstr(_descriptiveString, "meta");
if(nullptr != tmp) {
if(_descriptiveString.find("meta") != std::string::npos) {
tmpElement->specialKey.setMeta(true);
}
if(nullptr != strstr(_descriptiveString, "F12") ) {
if(_descriptiveString.find("F12") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF12;
} else if(nullptr != strstr(_descriptiveString, "F11") ) {
} else if(_descriptiveString.find("F11") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF11;
} else if(nullptr != strstr(_descriptiveString, "F10") ) {
} else if(_descriptiveString.find("F10") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF10;
} else if(nullptr != strstr(_descriptiveString, "F9") ) {
} else if(_descriptiveString.find("F9") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF9;
} else if(nullptr != strstr(_descriptiveString, "F8") ) {
} else if(_descriptiveString.find("F8") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF8;
} else if(nullptr != strstr(_descriptiveString, "F7") ) {
} else if(_descriptiveString.find("F7") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF7;
} else if(nullptr != strstr(_descriptiveString, "F6") ) {
} else if(_descriptiveString.find("F6") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF6;
} else if(nullptr != strstr(_descriptiveString, "F5") ) {
} else if(_descriptiveString.find("F5") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF5;
} else if(nullptr != strstr(_descriptiveString, "F4") ) {
} else if(_descriptiveString.find("F4") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF4;
} else if(nullptr != strstr(_descriptiveString, "F3") ) {
} else if(_descriptiveString.find("F3") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF3;
} else if(nullptr != strstr(_descriptiveString, "F2") ) {
} else if(_descriptiveString.find("F2") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF2;
} else if(nullptr != strstr(_descriptiveString, "F1") ) {
} else if(_descriptiveString.find("F1") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardF1;
} else if(nullptr != strstr(_descriptiveString, "LEFT") ) {
} else if(_descriptiveString.find("LEFT") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardLeft;
} else if(nullptr != strstr(_descriptiveString, "RIGHT") ) {
} else if(_descriptiveString.find("RIGHT") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardRight;
} else if(nullptr != strstr(_descriptiveString, "UP") ) {
} else if(_descriptiveString.find("UP") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardUp;
} else if(nullptr != strstr(_descriptiveString, "DOWN") ) {
} else if(_descriptiveString.find("DOWN") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardDown;
} else if(nullptr != strstr(_descriptiveString, "PAGE_UP") ) {
} else if(_descriptiveString.find("PAGE_UP") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardPageUp;
} else if(nullptr != strstr(_descriptiveString, "PAGE_DOWN") ) {
} else if(_descriptiveString.find("PAGE_DOWN") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardPageDown;
} else if(nullptr != strstr(_descriptiveString, "START") ) {
} else if(_descriptiveString.find("START") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardStart;
} else if(nullptr != strstr(_descriptiveString, "END") ) {
} else if(_descriptiveString.find("END") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardEnd;
} else if(nullptr != strstr(_descriptiveString, "PRINT") ) {
} else if(_descriptiveString.find("PRINT") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardPrint;
} else if(nullptr != strstr(_descriptiveString, "ARRET_DEFIL") ) {
} else if(_descriptiveString.find("ARRET_DEFIL") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardStopDefil;
} else if(nullptr != strstr(_descriptiveString, "WAIT") ) {
} else if(_descriptiveString.find("WAIT") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardWait;
} else if(nullptr != strstr(_descriptiveString, "INSERT") ) {
} else if(_descriptiveString.find("INSERT") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardInsert;
} else if(nullptr != strstr(_descriptiveString, "CAPLOCK") ) {
} else if(_descriptiveString.find("CAPLOCK") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardCapLock;
} else if(nullptr != strstr(_descriptiveString, "CONTEXT_MENU") ) {
} else if(_descriptiveString.find("CONTEXT_MENU") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardContextMenu;
} else if(nullptr != strstr(_descriptiveString, "NUM_LOCK") ) {
} else if(_descriptiveString.find("NUM_LOCK") != std::string::npos) {
tmpElement->keyboardMoveValue = ewol::key::keyboardNumLock;
} else {
tmpElement->unicodeValue = _descriptiveString[strlen(_descriptiveString) -1];
tmpElement->unicodeValue = _descriptiveString[_descriptiveString.size() -1];
}
// add it on the List ...
m_localShortcut.push_back(tmpElement);
@ -523,11 +518,9 @@ void ewol::Widget::shortCutAdd(const char * _descriptiveString,
void ewol::Widget::shortCutClean() {
for (size_t iii=0; iii<m_localShortcut.size(); iii++) {
if (nullptr != m_localShortcut[iii]) {
delete(m_localShortcut[iii]);
m_localShortcut[iii]=nullptr;
}
}
m_localShortcut.clear();
}
@ -551,14 +544,8 @@ bool ewol::Widget::onEventShortCut(ewol::key::Special& _special,
&& m_localShortcut[iii]->unicodeValue == 0)
) ) {
if (_isDown) {
if (true == m_localShortcut[iii]->broadcastEvent) {
// send message at all the widget (exepted this one)
sendMultiCast(m_localShortcut[iii]->generateEventId, m_localShortcut[iii]->eventData);
signalShortcut.emit(m_localShortcut[iii]->message);
}
// send message direct to the current widget (in every case, really useful for some generic windows shortcut)
ewol::object::Message tmpMsg(m_localShortcut[iii]->generateEventId, m_localShortcut[iii]->eventData);
onReceiveMessage(tmpMsg);
} // no else
return true;
}
}
@ -596,8 +583,7 @@ enum ewol::context::cursorDisplay ewol::Widget::getCursor() {
}
bool ewol::Widget::loadXML(exml::Element* _node) {
// Call EObject basic parser
ewol::Object::loadXML(_node); // note : load standard parameters (attribute in XML)
ewol::Object::loadXML(_node);
markToRedraw();
return true;
}

View File

@ -100,16 +100,12 @@ namespace ewol {
*/
class EventShortCut {
public:
bool broadcastEvent; //!< if it is true, then the message is sent to all the system
const char* generateEventId; //!< Local generated event
std::string eventData; //!< data link with the event
std::string message; //!< data link with the event
ewol::key::Special specialKey; //!< special board key
char32_t unicodeValue; //!< 0 if not used
enum ewol::key::keyboard keyboardMoveValue; //!< ewol::EVENT_KB_MOVE_TYPE_NONE if not used
EventShortCut() {
broadcastEvent = false;
generateEventId = nullptr;
eventData = "";
message = "";
unicodeValue = 0;
keyboardMoveValue = ewol::key::keyboardUnknow;
};
@ -585,19 +581,18 @@ namespace ewol {
// ----------------------------------------------------------------------------------------------------------------
// -- Shortcut : management of the shortcut
// ----------------------------------------------------------------------------------------------------------------
public:
ewol::object::Signal<std::string> signalShortcut; //!< signal handle of the message
private:
std::vector<EventShortCut*> m_localShortcut; //!< list of all shortcut in the widget
protected:
/**
* @brief add a specific shortcut with his description
* @param[in] _descriptiveString Description string of the shortcut
* @param[in] _generateEventId Event generic of the element
* @param[in] _data Associate data wit the event
* @param[in] _message massage to generate (or shortcut name)
*/
virtual void shortCutAdd(const char * _descriptiveString,
const char * _generateEventId,
std::string _data="",
bool _broadcast=false);
virtual void shortCutAdd(const std::string& _descriptiveString,
const std::string& _message="");
/**
* @brief remove all curent shortCut
*/