First step for the EObject

This commit is contained in:
Edouard Dupin 2012-02-24 17:26:15 +01:00
parent 3bb73288c6
commit a35b65f4c1
5 changed files with 306 additions and 7 deletions

View File

@ -0,0 +1,169 @@
/**
*******************************************************************************
* @file ewol/EObject.cpp
* @brief basic ewol object (Sources)
* @author Edouard DUPIN
* @date 24/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/EObject.h>
#include <ewol/Debug.h>
/**
* @brief Constructor
*/
ewol::EObject::EObject(void)
{
static int32_t ss_globalUniqueId = 0;
// note this is nearly atomic ... (but it is enough)
m_uniqueId = ss_globalUniqueId++;
EWOL_DEBUG("new EObject : [" << m_uniqueId << "]");
}
/**
* @brief Destructor
*/
ewol::EObject::~EObject(void)
{
EWOL_DEBUG("delete EObject : [" << m_uniqueId << "]");
for (int32_t iii=0; iii<m_externEvent.Size(); iii++) {
if (NULL!=m_externEvent[iii]) {
delete(m_externEvent[iii]);
m_externEvent[iii] = NULL;
}
}
m_externEvent.Clear();
m_availlableEventId.Clear();
m_uniqueId = -1;
}
/**
* @brief Get the UniqueId of the EObject
* @param ---
* @return the requested ID
*/
int32_t ewol::EObject::GetId(void)
{
return m_uniqueId;
};
/**
* @brief Add a specific event Id in the list to prevent wrong link on a EObject
* @param[in] generateEventId event Id to add
* @return ---
*/
void ewol::EObject::AddEventId(const char * generateEventId)
{
if (NULL != generateEventId) {
m_availlableEventId.PushBack(generateEventId);
}
}
/**
* @brief Generate event on all registered EObject
* @param[in] generateEventId event Id that is curetly generated
* @return ---
*/
void ewol::EObject::GenerateEventId(const char * generateEventId)
{
// for every element registered ...
for (int32_t iii=0; iii<m_externEvent.Size(); iii++) {
if (NULL!=m_externEvent[iii]) {
// if we find the event ...
if (m_externEvent[iii]->localEventId == generateEventId) {
if (NULL != m_externEvent[iii]->destEObject) {
m_externEvent[iii]->destEObject->OnReceiveMessage(this, m_externEvent[iii]->destEventId, m_externEvent[iii]->destData);
}
}
}
}
}
/**
* @brief Register an EObject over an other to get event on the second...
* @param[in] destinationObject pointer on the object that might be call when an event is generated
* @param[in] eventId Event generate inside the object
* @param[in] eventIdgenerated event generated when call the distant EObject.OnReceiveMessage(...)
* @param[in] data data associated with the event
* @return true if register corectly done
*/
void ewol::EObject::RegisterOnEvent(ewol::EObject * destinationObject, const char * eventId, const char * eventIdgenerated, etk::UString data)
{
if (NULL == destinationObject) {
EWOL_ERROR("Input ERROR NULL pointer EObject ...");
return;
}
if (NULL == eventId) {
EWOL_ERROR("Input ERROR NULL pointer Event Id...");
return;
}
if (NULL == eventIdgenerated) {
EWOL_ERROR("Input ERROR NULL pointer destination Event Id...");
return;
}
ewol::EventExtGen * tmpEvent = new ewol::EventExtGen();
if (NULL == tmpEvent) {
EWOL_ERROR("Allocation error in Register Event...");
return;
}
tmpEvent->localEventId = eventId;
tmpEvent->destEObject = destinationObject;
tmpEvent->destEventId = eventIdgenerated;
tmpEvent->destData = data;
m_externEvent.PushBack(tmpEvent);
}
/**
* @brief Inform object that an other object is removed ...
* @param[in] removeObject Pointer on the EObject remeved ==> the user must remove all reference on this EObject
* @return ---
*/
void ewol::EObject::OnObjectRemove(ewol::EObject * removeObject)
{
int32_t iii = m_externEvent.Size()-1;
while(iii>=0) {
if (NULL==m_externEvent[iii]) {
m_externEvent.Erase(iii);
} else if (m_externEvent[iii]->destEObject == removeObject) {
m_externEvent.Erase(iii);
} else {
iii--;
}
}
}
/**
* @brief Receive a message from an other EObject with a specific eventId and data
* @param[in] CallerObject Pointer on the EObject that information came from
* @param[in] eventId Message registered by this class
* @param[in] data Data registered by this class
* @return ---
*/
void ewol::EObject::OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data)
{
// here nothing to do ...
}

View File

@ -0,0 +1,125 @@
/**
*******************************************************************************
* @file ewol/EObject.h
* @brief basic ewol object (header)
* @author Edouard DUPIN
* @date 24/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_E_OBJECT_H__
#define __EWOL_E_OBJECT_H__
#include <etk/Types.h>
#include <etk/UString.h>
#include <etk/VectorType.h>
namespace ewol {
class EObject;
/**
* local class for event generation
*/
class EventExtGen {
public:
const char* localEventId; //!< local event Id generation
ewol::EObject* destEObject; //!< destination widget that might be call
const char* destEventId; //!< Generated event ID on the distant widget
etk::UString destData; //!< destination data
};
/**
* @brief Basic message classes for ewol system
*
* this class mermit at every EObject to communicate between them.
*/
class EObject {
private:
int32_t m_uniqueId; //!< Object UniqueID ==> TODO : Check if it use is needed
etk::VectorType<EventExtGen*> m_externEvent; //!< Generic list of event generation for output link
etk::VectorType<const char*> m_availlableEventId; //!< List of all event availlable for this widget
public:
/**
* @brief Constructor
*/
EObject(void);
/**
* @brief Destructor
*/
~EObject(void);
protected:
/**
* @brief Get the UniqueId of the EObject
* @param ---
* @return the requested ID
*/
int32_t GetId(void);
/**
* @brief Add a specific event Id in the list to prevent wrong link on a EObject
* @param[in] generateEventId event Id to add
* @return ---
*/
void AddEventId(const char * generateEventId);
/**
* @brief Generate event on all registered EObject
* @param[in] generateEventId event Id that is curetly generated
* @return ---
*/
void GenerateEventId(const char * generateEventId);
public:
/**
* @brief Register an EObject over an other to get event on the second...
* @param[in] destinationObject pointer on the object that might be call when an event is generated
* @param[in] eventId Event generate inside the object
* @param[in] eventIdgenerated event generated when call the distant EObject.OnReceiveMessage(...)
* @param[in] data data associated with the event
* @return ---
*/
void RegisterOnEvent(ewol::EObject * destinationObject, const char * eventId, const char * eventIdgenerated = NULL, etk::UString data = "");
/**
* @brief Inform object that an other object is removed ...
* @param[in] removeObject Pointer on the EObject remeved ==> the user must remove all reference on this EObject
* @note : Sub classes must call this class
* @return ---
*/
virtual void OnObjectRemove(ewol::EObject * removeObject);
/**
* @brief Receive a message from an other EObject with a specific eventId and data
* @param[in] CallerObject Pointer on the EObject that information came from
* @param[in] eventId Message registered by this class
* @param[in] data Data registered by this class
* @return ---
*/
virtual void OnReceiveMessage(ewol::EObject * CallerObject, const char * eventId, etk::UString data);
};
};
#endif

View File

@ -107,6 +107,8 @@ namespace ewol {
class Widget {
public:
Widget(void);
@ -170,10 +172,6 @@ namespace ewol {
virtual void OnGetFocus(void) {};
virtual void OnLostFocus(void) {};
// ----------------------------------------------------------------------------------------------------------------
// -- Input Event on the widget : The input is the muse for a computer, or the finger for the tablettes
// -- Shortcut: (only for computer) ==> must be manage otherwise for tablette pc
// ----------------------------------------------------------------------------------------------------------------
private:
etk::VectorType<eventExtern_ts> m_externEvent; //!< Generic list of event generation for output link
etk::VectorType<const char*> m_ListEventAvaillable; //!< List of all event availlable for this widget

View File

@ -35,18 +35,23 @@
namespace ewol {
void Stop(void);
void DisplayWindows(ewol::Windows * windows);
// only on computer
void ChangeSize(int32_t w, int32_t h);
void ChangePos(int32_t x, int32_t y);
// TODO : Deprecated used FOR???
void GetAbsPos(int32_t & x, int32_t & y);
// TODO : Deprecated remove it ...
bool IsPressedInput(int32_t inputID);
void KeyboardShow(ewol::keyboardMode_te mode);
void KeyboardHide(void);
void ForceRedrawAll(void);
void PopUpWidgetPush(ewol::Widget * tmpWidget);
void RmPopUp(int32_t widgetID);
int32_t CmdLineNb(void);
etk::UString CmdLineGet(int32_t id);
// TODO : This might be deprecated ...
bool IsSetCapsLock(void);
bool IsSetShift(void);
bool IsSetCtrl(void);
@ -55,15 +60,16 @@ namespace ewol {
bool IsSetAltGr(void);
bool IsSetVerNum(void);
bool IsSetInsert(void);
// basic shortcut setting (set default value, the configutration file will overloaded it automaticly
namespace shortCut {
void Add(bool shift, bool control, bool alt, bool meta, uniChar_t unicodeValue, const char * generateEventId, etk::UString data);
void Add(const char * descriptiveString, const char * generateEventId, etk::UString data);
};
// TODO : This is dangerous and might be deprecated ... Soon
int32_t GetCurrentWidth(void);
int32_t GetCurrentHeight(void);
};
// get current time in ms...
int64_t GetCurrentTime(void);

View File

@ -5,6 +5,7 @@ FILE_LIST = ewol/ewol.cpp \
ewol/base/MainThread.cpp \
ewol/base/gui.cpp \
ewol/Debug.cpp \
ewol/EObject.cpp \
ewol/OObject.cpp \
ewol/OObject/2DText.cpp \
ewol/OObject/2DTextColored.cpp \