2013-11-25 22:18:06 +01:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
*
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* @license GPL v3 (see license file)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __APPL_TEXT_PLUGIN_DATA_H__
|
|
|
|
#define __APPL_TEXT_PLUGIN_DATA_H__
|
|
|
|
|
|
|
|
#include <etk/types.h>
|
2013-12-13 21:50:40 +01:00
|
|
|
#include <ewol/object/Object.h>
|
2013-11-25 22:18:06 +01:00
|
|
|
#include <appl/Gui/TextViewer.h>
|
|
|
|
#include <ewol/compositing/Text.h>
|
|
|
|
#include <appl/TextPlugin.h>
|
|
|
|
|
|
|
|
namespace appl {
|
|
|
|
template <typename TYPE> class TextViewerPluginData : public appl::TextViewerPlugin {
|
2014-08-07 23:41:48 +02:00
|
|
|
protected:
|
2014-05-15 21:37:39 +02:00
|
|
|
TextViewerPluginData() {
|
2013-11-25 22:18:06 +01:00
|
|
|
// nothing to do ...
|
2014-05-26 21:42:51 +02:00
|
|
|
addObjectType("appl::TextViewerPluginData");
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
2014-08-07 23:41:48 +02:00
|
|
|
void init() {
|
|
|
|
appl::TextViewerPlugin::init();
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
DECLARE_FACTORY(TextViewerPluginData);
|
2014-05-15 21:37:39 +02:00
|
|
|
virtual ~TextViewerPluginData() {
|
2013-11-25 22:18:06 +01:00
|
|
|
for (size_t iii = 0; iii < m_specificData.size() ; ++iii) {
|
2014-06-05 22:01:24 +02:00
|
|
|
if (m_specificData[iii].second != nullptr) {
|
2013-11-25 22:18:06 +01:00
|
|
|
remove(*m_specificData[iii].second);
|
|
|
|
delete(m_specificData[iii].second);
|
2014-06-05 22:01:24 +02:00
|
|
|
m_specificData[iii].second = nullptr;
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_specificData.clear();
|
|
|
|
}
|
|
|
|
private:
|
2014-08-07 23:41:48 +02:00
|
|
|
std::vector<std::pair<std::shared_ptr<appl::Buffer> ,TYPE* >> m_specificData;
|
2013-11-25 22:18:06 +01:00
|
|
|
protected:
|
|
|
|
TYPE* getDataRef(appl::TextViewer& _textDrawer) {
|
|
|
|
for (size_t iii = 0; iii < m_specificData.size() ; ++iii) {
|
2013-11-26 21:06:01 +01:00
|
|
|
if (m_specificData[iii].first == _textDrawer.internalGetBuffer()) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return m_specificData[iii].second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TYPE* data = new TYPE();
|
2014-06-05 22:01:24 +02:00
|
|
|
if (data == nullptr) {
|
|
|
|
return nullptr;
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
2013-11-26 21:06:01 +01:00
|
|
|
m_specificData.push_back(std::make_pair(_textDrawer.internalGetBuffer(), data));
|
2013-11-25 22:18:06 +01:00
|
|
|
// create a new one ...
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
protected: // Wrap all element with their internal data: (do not use theses function)
|
2014-08-27 22:58:21 +02:00
|
|
|
bool onReceiveShortCut(appl::TextViewer& _textDrawer,
|
|
|
|
const std::string& _shortCutName) {
|
2013-11-25 22:18:06 +01:00
|
|
|
TYPE* data = getDataRef(_textDrawer);
|
2014-06-05 22:01:24 +02:00
|
|
|
if (data == nullptr) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-27 22:58:21 +02:00
|
|
|
return onDataReceiveShortCut(_textDrawer, _shortCutName, *data);
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
|
|
|
bool onWrite(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
|
|
|
const std::string& _data) {
|
|
|
|
TYPE* data = getDataRef(_textDrawer);
|
2014-06-05 22:01:24 +02:00
|
|
|
if (data == nullptr) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 21:00:13 +02:00
|
|
|
return onDataWrite(_textDrawer, _pos, _data, *data);
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
|
|
|
bool onReplace(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
|
|
|
const std::string& _data,
|
|
|
|
const appl::Buffer::Iterator& _posEnd) {
|
|
|
|
TYPE* data = getDataRef(_textDrawer);
|
2014-06-05 22:01:24 +02:00
|
|
|
if (data == nullptr) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 21:00:13 +02:00
|
|
|
return onDataReplace(_textDrawer, _pos, _data, _posEnd, *data);
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
|
|
|
bool onRemove(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
|
|
|
const appl::Buffer::Iterator& _posEnd) {
|
|
|
|
TYPE* data = getDataRef(_textDrawer);
|
2014-06-05 22:01:24 +02:00
|
|
|
if (data == nullptr) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 21:00:13 +02:00
|
|
|
return onDataRemove(_textDrawer, _pos, _posEnd, *data);
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2014-08-27 22:58:21 +02:00
|
|
|
virtual bool onDataReceiveShortCut(appl::TextViewer& _textDrawer,
|
|
|
|
const std::string& _shortCutName,
|
|
|
|
TYPE& _data) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 21:00:13 +02:00
|
|
|
virtual bool onDataWrite(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
|
|
|
const std::string& _strData,
|
|
|
|
TYPE& _data) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 21:00:13 +02:00
|
|
|
virtual bool onDataReplace(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
|
|
|
const std::string& _strData,
|
|
|
|
const appl::Buffer::Iterator& _posEnd,
|
|
|
|
TYPE& _data) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-08-21 21:00:13 +02:00
|
|
|
virtual bool onDataRemove(appl::TextViewer& _textDrawer,
|
|
|
|
const appl::Buffer::Iterator& _pos,
|
|
|
|
const appl::Buffer::Iterator& _posEnd,
|
|
|
|
TYPE& _data) {
|
2013-11-25 22:18:06 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void remove(TYPE& _data) {
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|