2016-05-02 22:01:55 +02:00
|
|
|
/** @file
|
2013-11-25 22:18:06 +01:00
|
|
|
* @author Edouard DUPIN
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
* @license GPL v3 (see license file)
|
|
|
|
*/
|
2016-05-02 22:01:55 +02:00
|
|
|
#pragma once
|
2016-10-03 22:01:55 +02:00
|
|
|
#include <etk/types.hpp>
|
|
|
|
#include <ewol/object/Object.hpp>
|
|
|
|
#include <appl/Gui/TextViewer.hpp>
|
|
|
|
#include <ewol/compositing/Text.hpp>
|
|
|
|
#include <appl/TextPlugin.hpp>
|
2013-11-25 22:18:06 +01:00
|
|
|
|
|
|
|
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
|
|
|
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) {
|
2018-06-19 22:31:29 +02:00
|
|
|
if (m_specificData[iii].second != null) {
|
2013-11-25 22:18:06 +01:00
|
|
|
remove(*m_specificData[iii].second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_specificData.clear();
|
|
|
|
}
|
|
|
|
private:
|
2017-10-09 10:25:41 +02:00
|
|
|
etk::Vector<etk::Pair<ememory::WeakPtr<appl::Buffer> ,ememory::UniquePtr<TYPE>>> m_specificData;
|
2013-11-25 22:18:06 +01:00
|
|
|
protected:
|
|
|
|
TYPE* getDataRef(appl::TextViewer& _textDrawer) {
|
2014-09-15 07:21:22 +02:00
|
|
|
auto it = m_specificData.begin();
|
|
|
|
while(it != m_specificData.end()) {
|
2016-07-19 22:03:39 +02:00
|
|
|
ememory::SharedPtr<appl::Buffer> buf = it->first.lock();
|
2018-06-19 22:31:29 +02:00
|
|
|
if (buf == null) {
|
2014-09-15 07:21:22 +02:00
|
|
|
it = m_specificData.erase(it);
|
2016-03-15 22:33:06 +01:00
|
|
|
continue;
|
2014-09-15 07:21:22 +02:00
|
|
|
}
|
|
|
|
if (buf == _textDrawer.internalGetBuffer()) {
|
2016-03-15 22:33:06 +01:00
|
|
|
return it->second.get();
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
2014-09-18 21:01:41 +02:00
|
|
|
++it;
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
2017-10-21 19:07:42 +02:00
|
|
|
ememory::UniquePtr<TYPE> data(ETK_NEW(TYPE));
|
2018-06-19 22:31:29 +02:00
|
|
|
if (data == null) {
|
2017-03-16 22:39:06 +01:00
|
|
|
APPL_ERROR("ALLOCATION plugin data error");
|
2018-06-19 22:31:29 +02:00
|
|
|
return null;
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
2017-03-16 22:39:06 +01:00
|
|
|
TYPE* copyPocalPointer = data.get();
|
2017-10-09 10:25:41 +02:00
|
|
|
ememory::WeakPtr<appl::Buffer> tmpBuffer = _textDrawer.internalGetBuffer();
|
|
|
|
m_specificData.pushBack(etk::makePair(tmpBuffer, etk::move(data)));
|
2013-11-25 22:18:06 +01:00
|
|
|
// create a new one ...
|
2017-03-16 22:39:06 +01:00
|
|
|
return copyPocalPointer;
|
2013-11-25 22:18:06 +01:00
|
|
|
}
|
|
|
|
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,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _shortCutName) {
|
2013-11-25 22:18:06 +01:00
|
|
|
TYPE* data = getDataRef(_textDrawer);
|
2018-06-19 22:31:29 +02:00
|
|
|
if (data == null) {
|
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,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _data) {
|
2013-11-25 22:18:06 +01:00
|
|
|
TYPE* data = getDataRef(_textDrawer);
|
2018-06-19 22:31:29 +02:00
|
|
|
if (data == null) {
|
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,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _data,
|
2013-11-25 22:18:06 +01:00
|
|
|
const appl::Buffer::Iterator& _posEnd) {
|
|
|
|
TYPE* data = getDataRef(_textDrawer);
|
2018-06-19 22:31:29 +02:00
|
|
|
if (data == null) {
|
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);
|
2018-06-19 22:31:29 +02:00
|
|
|
if (data == null) {
|
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,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _shortCutName,
|
2014-08-27 22:58:21 +02:00
|
|
|
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,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _strData,
|
2014-08-21 21:00:13 +02:00
|
|
|
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,
|
2017-08-28 00:09:10 +02:00
|
|
|
const etk::String& _strData,
|
2014-08-21 21:00:13 +02:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
};
|
2016-05-02 22:01:55 +02:00
|
|
|
}
|
2013-11-25 22:18:06 +01:00
|
|
|
|