2013-09-19 22:23:31 +02:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
*
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* @license GPL v3 (see license file)
|
|
|
|
*/
|
|
|
|
|
2013-10-25 20:49:26 +02:00
|
|
|
#include <appl/debug.h>
|
2013-09-19 22:23:31 +02:00
|
|
|
#include <appl/global.h>
|
2013-11-23 18:30:52 +01:00
|
|
|
#include <appl/Gui/TextViewer.h>
|
|
|
|
#include <appl/BufferManager.h>
|
2013-12-13 21:50:40 +01:00
|
|
|
#include <ewol/context/clipBoard.h>
|
2013-09-19 22:23:31 +02:00
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
#include <ewol/widget/Manager.h>
|
2013-11-23 18:30:52 +01:00
|
|
|
#include <appl/Gui/ViewerManager.h>
|
2013-12-13 21:50:40 +01:00
|
|
|
#include <ewol/object/Object.h>
|
2013-10-28 21:47:51 +01:00
|
|
|
#include <appl/TextPluginManager.h>
|
2013-09-19 22:23:31 +02:00
|
|
|
|
|
|
|
#undef __class__
|
2013-10-09 22:00:24 +02:00
|
|
|
#define __class__ "TextViewer"
|
2013-09-19 22:23:31 +02:00
|
|
|
|
2013-11-20 21:57:00 +01:00
|
|
|
#define tic() \
|
|
|
|
int64_t startTime = ewol::getTime();
|
|
|
|
|
|
|
|
#define toc(comment) \
|
|
|
|
int64_t endTime = ewol::getTime(); \
|
|
|
|
int64_t processTimeLocal = (endTime - startTime); \
|
|
|
|
APPL_DEBUG(comment << (float)((float)processTimeLocal / 1000.0) << "ms");
|
|
|
|
|
2013-11-14 21:57:10 +01:00
|
|
|
appl::TextViewer::TextViewer(const std::string& _fontName, int32_t _fontSize) :
|
2013-10-09 22:00:24 +02:00
|
|
|
m_buffer(NULL),
|
|
|
|
m_displayText(_fontName, _fontSize),
|
|
|
|
m_insertMode(false) {
|
2013-11-20 21:57:00 +01:00
|
|
|
addObjectType("appl::TextViewer");
|
2013-10-07 22:04:21 +02:00
|
|
|
setCanHaveFocus(true);
|
2013-10-09 22:00:24 +02:00
|
|
|
registerMultiCast(ednMsgBufferId);
|
|
|
|
registerMultiCast(ednMsgGuiFind);
|
|
|
|
registerMultiCast(ednMsgGuiReplace);
|
2013-11-26 21:22:06 +01:00
|
|
|
registerMultiCast(appl::MsgSelectGotoLine);
|
2013-10-29 21:13:45 +01:00
|
|
|
registerMultiCast(appl::MsgSelectNewFile);
|
2013-11-26 21:22:06 +01:00
|
|
|
registerMultiCast(appl::MsgSelectGotoLineSelect);
|
2013-10-07 22:04:21 +02:00
|
|
|
setLimitScrolling(0.2);
|
2013-09-19 22:23:31 +02:00
|
|
|
|
2013-10-29 21:13:45 +01:00
|
|
|
// load buffer manager:
|
|
|
|
m_bufferManager = appl::BufferManager::keep();
|
2013-11-23 18:30:52 +01:00
|
|
|
m_viewerManager = appl::ViewerManager::keep();
|
2013-10-29 21:13:45 +01:00
|
|
|
|
2013-10-27 20:36:54 +01:00
|
|
|
// load color properties
|
|
|
|
m_paintingProperties = appl::GlyphPainting::keep("THEME:COLOR:textViewer.json");
|
|
|
|
// get all id properties ...
|
|
|
|
m_colorBackground = m_paintingProperties->request("CODE_basicBackgroung");
|
|
|
|
m_colorSpace = m_paintingProperties->request("CODE_space");
|
|
|
|
m_colorTabulation = m_paintingProperties->request("CODE_tabulation");
|
|
|
|
m_colorCursor = m_paintingProperties->request("CODE_cursor");
|
|
|
|
m_colorLineNumber = m_paintingProperties->request("CODE_lineNumber");
|
|
|
|
m_colorSelection = m_paintingProperties->request("SelectedText");
|
|
|
|
m_colorNormal = m_paintingProperties->request("normal");
|
|
|
|
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::textPluginManager::connect(*this);
|
2013-11-07 21:08:57 +01:00
|
|
|
// last created has focus ...
|
|
|
|
setCurrentSelect();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
appl::TextViewer::~TextViewer(void) {
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::textPluginManager::disconnect(*this);
|
2013-11-23 18:30:52 +01:00
|
|
|
appl::GlyphPainting::release(m_paintingProperties);
|
|
|
|
appl::BufferManager::release(m_bufferManager);
|
|
|
|
appl::ViewerManager::release(m_viewerManager);
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
bool appl::TextViewer::calculateMinSize(void) {
|
2013-09-19 22:23:31 +02:00
|
|
|
m_minSize.setValue(50,50);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
void appl::TextViewer::onDraw(void) {
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayDrawing.draw();
|
|
|
|
m_displayText.draw();
|
|
|
|
WidgetScrooled::onDraw();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
void appl::TextViewer::onRegenerateDisplay(void) {
|
2013-10-07 22:04:21 +02:00
|
|
|
if (false == needRedraw()) {
|
2013-09-26 22:15:39 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-11-20 21:57:00 +01:00
|
|
|
//tic();
|
2013-09-26 22:15:39 +02:00
|
|
|
// For the scrooling windows
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayDrawing.clear();
|
|
|
|
m_displayText.clear();
|
2013-09-26 22:15:39 +02:00
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
// reset the background :
|
|
|
|
m_displayDrawing.setPos(vec3(0, 0, 0));
|
2013-10-27 20:36:54 +01:00
|
|
|
m_displayDrawing.setColor((*m_paintingProperties)[m_colorBackground].getForeground());
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayDrawing.rectangleWidth(m_size);
|
2013-09-26 22:15:39 +02:00
|
|
|
|
|
|
|
if (m_buffer == NULL) {
|
2013-10-21 21:47:28 +02:00
|
|
|
m_maxSize.setX(256);
|
|
|
|
m_maxSize.setY(256);
|
2013-12-13 21:50:40 +01:00
|
|
|
m_displayText.setTextAlignement(10, m_size.x()-20, ewol::compositing::Text::alignLeft);
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setRelPos(vec3(10, 0, 0));
|
2013-11-14 21:57:10 +01:00
|
|
|
std::string tmpString("<br/>\n"
|
2013-09-26 22:15:39 +02:00
|
|
|
"<font color=\"red\">\n"
|
|
|
|
" <b>\n"
|
|
|
|
" edn - Editeur De N'ours\n"
|
|
|
|
" </b>\n"
|
|
|
|
"</font>\n"
|
|
|
|
"<br/>\n"
|
|
|
|
"<br/>\n"
|
|
|
|
"<font color=\"indigo\">\n"
|
|
|
|
" <i>\n"
|
|
|
|
" No Buffer Availlable to display\n"
|
|
|
|
" </i>\n"
|
|
|
|
"</font>\n");
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setPos(vec3(0.0f, m_size.y(), 0.0f) );
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
m_displayText.printDecorated(tmpString);
|
2013-09-26 22:15:39 +02:00
|
|
|
// call the herited class...
|
2013-10-07 22:04:21 +02:00
|
|
|
WidgetScrooled::onRegenerateDisplay();
|
2013-09-26 22:15:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// normal displa of the buffer :
|
|
|
|
vec3 tmpCursorPosition(0, 0, -1);
|
2013-11-27 21:33:42 +01:00
|
|
|
float tmpCursorLenght = -1.0;
|
2013-09-26 22:15:39 +02:00
|
|
|
// real display ...
|
2013-10-07 22:04:21 +02:00
|
|
|
etk::Buffer& buf = m_buffer->getData();
|
|
|
|
m_displayText.setColor(etk::Color<>(0, 0, 0, 256));
|
2013-09-26 22:15:39 +02:00
|
|
|
float countNbLine = 1;
|
2013-11-22 21:48:05 +01:00
|
|
|
int32_t countColomn = 0;
|
2013-09-26 22:15:39 +02:00
|
|
|
// the siplay string :
|
2013-11-14 21:57:10 +01:00
|
|
|
std::u32string stringToDisplay;
|
2013-11-22 21:48:05 +01:00
|
|
|
int64_t bufferElementSize = 0;
|
2013-10-17 21:57:31 +02:00
|
|
|
bool isSelect = false;
|
2013-10-21 21:47:28 +02:00
|
|
|
appl::Buffer::Iterator selectPosStart = m_buffer->begin();
|
|
|
|
appl::Buffer::Iterator selectPosStop = m_buffer->begin();
|
|
|
|
if (m_buffer->hasTextSelected() == true) {
|
|
|
|
selectPosStart = m_buffer->selectStart();
|
|
|
|
selectPosStop = m_buffer->selectStop();
|
2013-10-17 21:57:31 +02:00
|
|
|
}
|
2013-10-21 21:47:28 +02:00
|
|
|
m_displayText.setPos(vec3(-m_originScrooled.x(), m_size.y()+m_originScrooled.y(), 0));
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
appl::Buffer::Iterator startingIt = m_buffer->begin();
|
2013-11-22 21:48:05 +01:00
|
|
|
int64_t startLineId = 0;
|
2013-10-21 21:47:28 +02:00
|
|
|
if (m_size.y() < m_displayText.getPos().y()) {
|
|
|
|
for (startingIt = m_buffer->begin();
|
2013-10-26 13:16:30 +02:00
|
|
|
(bool)startingIt == true;
|
2013-10-21 21:47:28 +02:00
|
|
|
++startingIt) {
|
|
|
|
if (*startingIt == etk::UChar::Return) {
|
|
|
|
++startLineId;
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
if (m_size.y() >= m_displayText.getPos().y()) {
|
|
|
|
++startingIt;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Display line number :
|
|
|
|
m_lastOffsetDisplay = 0;
|
2013-11-14 21:57:10 +01:00
|
|
|
vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A');
|
2013-10-21 21:47:28 +02:00
|
|
|
{
|
2013-11-22 21:48:05 +01:00
|
|
|
int32_t nbLine = m_buffer->getNumberOfLines();
|
2013-10-21 21:47:28 +02:00
|
|
|
float nbLineCalc = nbLine;
|
|
|
|
int32_t nbChar = 0;
|
|
|
|
while (nbLineCalc >= 1.0f) {
|
|
|
|
++nbChar;
|
|
|
|
nbLineCalc /= 10.0f;
|
|
|
|
}
|
|
|
|
m_lastOffsetDisplay = tmpLetterSize.x() * (float)nbChar + 1.0f;
|
2013-10-27 20:36:54 +01:00
|
|
|
m_displayText.setFontItalic((*m_paintingProperties)[m_colorLineNumber].getItalic());
|
|
|
|
m_displayText.setFontBold((*m_paintingProperties)[m_colorLineNumber].getBold());
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorLineNumber].getBackground());
|
|
|
|
m_displayText.setColor((*m_paintingProperties)[m_colorLineNumber].getForeground());
|
2013-10-21 21:47:28 +02:00
|
|
|
m_displayText.setClippingMode(false);
|
|
|
|
|
|
|
|
vec3 startWriteRealPosition = m_displayText.getPos();
|
|
|
|
m_displayText.setPos(vec3(0.0f, startWriteRealPosition.y(), 0.0f));
|
|
|
|
for (int32_t iii=startLineId;
|
|
|
|
iii<nbLine;
|
|
|
|
++iii) {
|
|
|
|
char tmpLineNumber[50];
|
2013-11-20 21:57:00 +01:00
|
|
|
sprintf(tmpLineNumber, "%*d", nbChar, iii+1);
|
2013-10-21 21:47:28 +02:00
|
|
|
m_displayText.print(tmpLineNumber);
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
if (m_displayText.getPos().y() < -20.0f ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_displayText.setPos(vec3(-m_originScrooled.x()+m_lastOffsetDisplay, startWriteRealPosition.y(), 0.0f));
|
|
|
|
m_displayText.setClipping(vec2(m_lastOffsetDisplay, 0), m_size);
|
|
|
|
}
|
2013-10-27 20:36:54 +01:00
|
|
|
appl::DisplayHLData displayLocalSyntax;
|
2013-12-05 22:16:04 +01:00
|
|
|
m_buffer->hightlightGenerateLines(displayLocalSyntax, startingIt, (m_size.y()/tmpLetterSize.y()) + 5);
|
2013-10-21 21:47:28 +02:00
|
|
|
float maxSizeX = 0;
|
2013-10-27 20:36:54 +01:00
|
|
|
appl::HighlightInfo * HLColor = NULL;
|
2013-11-23 18:30:52 +01:00
|
|
|
bool DisplayCursorAndSelection = isSelectedLast();
|
2013-11-23 12:25:42 +01:00
|
|
|
appl::Buffer::Iterator it;
|
|
|
|
for (it = startingIt;
|
2013-10-26 13:16:30 +02:00
|
|
|
(bool)it == true;
|
2013-10-18 22:23:52 +02:00
|
|
|
++it) {
|
2013-10-21 21:47:28 +02:00
|
|
|
if (it == m_buffer->cursor()) {
|
2013-09-26 22:15:39 +02:00
|
|
|
// need to display the cursor :
|
2013-10-18 22:23:52 +02:00
|
|
|
tmpCursorPosition = m_displayText.getPos();
|
2013-11-27 21:33:42 +01:00
|
|
|
tmpCursorLenght = 0.0f;
|
2013-09-26 22:15:39 +02:00
|
|
|
}
|
2013-10-18 22:23:52 +02:00
|
|
|
//APPL_DEBUG("display element '" << currentValue << "'at pos : " << m_displayText.getPos() );
|
2013-09-26 22:15:39 +02:00
|
|
|
//APPL_DEBUG(" element size : " << iii << " : " << bufferElementSize);
|
2013-10-27 20:36:54 +01:00
|
|
|
if (*it == etk::UChar::Return) {
|
2013-09-26 22:15:39 +02:00
|
|
|
countNbLine += 1;
|
|
|
|
countColomn = 0;
|
2013-10-21 21:47:28 +02:00
|
|
|
maxSizeX = etk_max(m_displayText.getPos().x(), maxSizeX);
|
2013-10-30 21:16:38 +01:00
|
|
|
// Display the end line position only if we have the focus ...
|
2013-11-23 18:30:52 +01:00
|
|
|
if (DisplayCursorAndSelection == true) {
|
2013-10-30 21:16:38 +01:00
|
|
|
if (it >= selectPosStart && it < selectPosStop) {
|
2013-12-13 21:50:40 +01:00
|
|
|
ewol::compositing::Drawing& draw = m_displayText.getDrawing();
|
2013-10-30 21:16:38 +01:00
|
|
|
draw.setColor(etk::Color<>(0xFF0000FF));
|
|
|
|
draw.setPos(m_displayText.getPos() + tmpLetterSize/4.0f);
|
|
|
|
draw.rectangle(m_displayText.getPos() + tmpLetterSize*3.0f/4.0f);
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
}
|
2013-11-27 21:33:42 +01:00
|
|
|
if (tmpCursorLenght == 0.0f) {
|
|
|
|
tmpCursorLenght = tmpLetterSize.x();
|
|
|
|
}
|
2013-10-18 22:23:52 +02:00
|
|
|
m_displayText.forceLineReturn();
|
2013-10-21 21:47:28 +02:00
|
|
|
m_displayText.setPos(vec3(-m_originScrooled.x()+m_lastOffsetDisplay, m_displayText.getPos().y(), 0.0f));
|
|
|
|
if (m_displayText.getPos().y() < -20.0f ) {
|
|
|
|
break;
|
|
|
|
}
|
2013-09-26 22:15:39 +02:00
|
|
|
continue;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
2013-11-22 21:48:05 +01:00
|
|
|
HLColor = m_buffer->getElementColorAtPosition(displayLocalSyntax, (int64_t)it);
|
2013-10-27 20:36:54 +01:00
|
|
|
bool haveBackground = false;
|
|
|
|
if ( HLColor != NULL
|
|
|
|
&& HLColor->patern != NULL) {
|
|
|
|
m_displayText.setColor(HLColor->patern->getColorGlyph().getForeground());
|
|
|
|
m_displayText.setColorBg(HLColor->patern->getColorGlyph().getBackground());
|
|
|
|
haveBackground = HLColor->patern->getColorGlyph().haveBackground();
|
|
|
|
m_displayText.setFontItalic(HLColor->patern->getColorGlyph().getItalic());
|
|
|
|
m_displayText.setFontBold(HLColor->patern->getColorGlyph().getBold());
|
|
|
|
} else {
|
|
|
|
m_displayText.setFontItalic((*m_paintingProperties)[m_colorNormal].getItalic());
|
|
|
|
m_displayText.setFontBold((*m_paintingProperties)[m_colorNormal].getBold());
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorNormal].getBackground());
|
|
|
|
m_displayText.setColor((*m_paintingProperties)[m_colorNormal].getForeground());
|
|
|
|
}
|
|
|
|
if (haveBackground == false) {
|
|
|
|
if (*it == etk::UChar::Space) {
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorSpace].getForeground());
|
|
|
|
} else if (*it == etk::UChar::Tabulation) {
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorTabulation].getForeground());
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
}
|
2013-10-27 20:36:54 +01:00
|
|
|
m_buffer->expand(countColomn, *it, stringToDisplay);
|
2013-10-30 21:16:38 +01:00
|
|
|
// Display selection only if we have the focus ...
|
2013-11-23 18:30:52 +01:00
|
|
|
if (DisplayCursorAndSelection == true) {
|
2013-10-30 21:16:38 +01:00
|
|
|
if (it >= selectPosStart && it < selectPosStop) {
|
|
|
|
m_displayText.setColor((*m_paintingProperties)[m_colorSelection].getForeground());
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorSelection].getBackground());
|
|
|
|
}
|
2013-10-17 21:57:31 +02:00
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
//APPL_DEBUG("display : '" << currentValue << "' == > '" << stringToDisplay << "'");
|
2013-10-17 21:57:31 +02:00
|
|
|
m_displayText.print(stringToDisplay);
|
2013-11-27 21:33:42 +01:00
|
|
|
if (tmpCursorLenght == 0.0f) {
|
|
|
|
tmpCursorLenght = m_displayText.getPos().x()-tmpCursorPosition.x();
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
countColomn += stringToDisplay.size();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
2013-11-23 12:25:42 +01:00
|
|
|
if (it == m_buffer->cursor()) {
|
|
|
|
tmpCursorPosition = m_displayText.getPos();
|
2013-11-27 21:33:42 +01:00
|
|
|
tmpCursorLenght = 5;
|
2013-11-23 12:25:42 +01:00
|
|
|
}
|
2013-10-21 21:47:28 +02:00
|
|
|
maxSizeX = etk_max(m_displayText.getPos().x(), maxSizeX);
|
2013-10-30 21:16:38 +01:00
|
|
|
// Display cursor only if we have the focus ...
|
|
|
|
if ( tmpCursorPosition.z() != -1
|
|
|
|
&& getFocus() == true) {
|
2013-09-26 22:15:39 +02:00
|
|
|
// display the cursor:
|
2013-09-30 00:08:52 +02:00
|
|
|
//APPL_DEBUG("display cursor at position : " << tmpCursorPosition);
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setPos(tmpCursorPosition);
|
2013-11-27 21:33:42 +01:00
|
|
|
if (m_buffer->hasTextSelected() == true) {
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorCursor].getForeground());
|
|
|
|
m_displayText.printCursor(false);
|
|
|
|
} else {
|
|
|
|
if (m_insertMode == true) {
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorSelection].getBackground());
|
|
|
|
} else {
|
|
|
|
m_displayText.setColorBg((*m_paintingProperties)[m_colorCursor].getForeground());
|
|
|
|
}
|
|
|
|
m_displayText.printCursor(m_insertMode, tmpCursorLenght);
|
|
|
|
}
|
2013-09-26 22:15:39 +02:00
|
|
|
}
|
2013-10-21 21:47:28 +02:00
|
|
|
// set maximum size (X&Y) :
|
|
|
|
{
|
2013-11-14 21:57:10 +01:00
|
|
|
vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A');
|
2013-11-22 21:48:05 +01:00
|
|
|
int64_t nbLines = m_buffer->getNumberOfLines();
|
2013-10-21 21:47:28 +02:00
|
|
|
m_maxSize.setX(maxSizeX+m_originScrooled.x());
|
|
|
|
m_maxSize.setY((float)nbLines*tmpLetterSize.y());
|
|
|
|
}
|
2013-11-20 21:57:00 +01:00
|
|
|
//toc("Display time : ");
|
2013-09-26 22:15:39 +02:00
|
|
|
// call the herited class...
|
2013-10-07 22:04:21 +02:00
|
|
|
WidgetScrooled::onRegenerateDisplay();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
bool appl::TextViewer::onEventEntry(const ewol::event::Entry& _event) {
|
2013-09-26 22:15:39 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
// First call plugin
|
|
|
|
if (appl::textPluginManager::onEventEntry(*this, _event) == true) {
|
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
// just forward event == > manage directly in the buffer
|
2013-12-13 21:50:40 +01:00
|
|
|
if (_event.getType() == ewol::key::keyboardChar) {
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
|
2013-12-13 21:50:40 +01:00
|
|
|
if (_event.getStatus() != ewol::key::statusDown) {
|
2013-10-20 18:14:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-11-14 21:57:10 +01:00
|
|
|
char32_t localValue = _event.getChar();
|
2013-10-20 18:14:22 +02:00
|
|
|
if (localValue == etk::UChar::Return) {
|
2013-12-13 21:50:40 +01:00
|
|
|
if (true == _event.getSpecialKey().getShift()) {
|
2013-10-20 18:14:22 +02:00
|
|
|
localValue = etk::UChar::CarrierReturn;
|
|
|
|
}
|
|
|
|
} else if (localValue == etk::UChar::Suppress ) {
|
|
|
|
//APPL_INFO("keyEvent : <suppr> pos=" << m_cursorPos);
|
|
|
|
if (m_buffer->hasTextSelected()) {
|
2013-10-22 21:34:13 +02:00
|
|
|
remove();
|
2013-10-20 18:14:22 +02:00
|
|
|
} else {
|
|
|
|
appl::Buffer::Iterator pos = m_buffer->cursor();
|
|
|
|
appl::Buffer::Iterator posEnd = pos;
|
|
|
|
++posEnd;
|
|
|
|
replace("", pos, posEnd);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else if (localValue == etk::UChar::Delete) {
|
|
|
|
//APPL_INFO("keyEvent : <del> pos=" << m_cursorPos);
|
|
|
|
if (m_buffer->hasTextSelected()) {
|
2013-10-22 21:34:13 +02:00
|
|
|
remove();
|
2013-10-20 18:14:22 +02:00
|
|
|
} else {
|
|
|
|
appl::Buffer::Iterator pos = m_buffer->cursor();
|
|
|
|
appl::Buffer::Iterator posEnd = pos;
|
|
|
|
--pos;
|
|
|
|
replace("", pos, posEnd);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
m_buffer->setSelectMode(false);
|
|
|
|
// normal adding char ...
|
|
|
|
char output[5];
|
2013-11-14 21:57:10 +01:00
|
|
|
int32_t nbElement = etk::getUtf8(localValue, output);
|
2013-10-20 18:14:22 +02:00
|
|
|
if ( m_buffer->hasTextSelected() == false
|
2013-12-13 21:50:40 +01:00
|
|
|
&& _event.getSpecialKey().getInsert() == true) {
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator pos = m_buffer->cursor();
|
|
|
|
appl::Buffer::Iterator posEnd = pos;
|
|
|
|
++posEnd;
|
2013-11-14 21:57:10 +01:00
|
|
|
replace(output, pos, posEnd);
|
|
|
|
//TODO : choisce UTF ... replace(localValue, pos, posEnd);
|
2013-10-20 18:14:22 +02:00
|
|
|
} else {
|
2013-11-14 21:57:10 +01:00
|
|
|
std::string myString = output;
|
2013-10-20 18:14:22 +02:00
|
|
|
write(myString);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// move events ...
|
2013-12-13 21:50:40 +01:00
|
|
|
if (_event.getStatus() == ewol::key::statusDown) {
|
2013-10-20 18:14:22 +02:00
|
|
|
bool needUpdatePosition = true;
|
2013-11-20 21:57:00 +01:00
|
|
|
// selection when shift is set:
|
2013-12-13 21:50:40 +01:00
|
|
|
m_buffer->setSelectMode(_event.getSpecialKey().getShift());
|
2013-10-20 18:14:22 +02:00
|
|
|
// check selection event ...
|
|
|
|
switch(_event.getType()) {
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardInsert:
|
2013-11-27 21:33:42 +01:00
|
|
|
m_insertMode = m_insertMode==true?false:true;
|
|
|
|
markToRedraw();
|
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardLeft:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <LEFT>");
|
|
|
|
moveCursorLeft();
|
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardRight:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <RIGHT>");
|
|
|
|
moveCursorRight();
|
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardUp:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <UP>");
|
|
|
|
moveCursorUp(1);
|
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardDown:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <DOWN>");
|
|
|
|
moveCursorDown(1);
|
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardPageUp:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <PAGE-UP>");
|
2013-11-20 21:57:00 +01:00
|
|
|
moveCursorUp(15); // TODO : Set the real number of line ...
|
2013-10-20 18:14:22 +02:00
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardPageDown:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <PAGE-DOWN>");
|
2013-11-20 21:57:00 +01:00
|
|
|
moveCursorDown(15); // TODO : Set the real number of line ...
|
2013-10-20 18:14:22 +02:00
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardStart:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <Start of line>");
|
|
|
|
moveCursorLeft(moveEnd);
|
|
|
|
break;
|
2013-12-13 21:50:40 +01:00
|
|
|
case ewol::key::keyboardEnd:
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("keyEvent : <End of line>");
|
|
|
|
moveCursorRight(moveEnd);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2013-09-26 22:15:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
bool appl::TextViewer::onEventInput(const ewol::event::Input& _event) {
|
2013-11-07 21:08:57 +01:00
|
|
|
if (_event.getId() != 0) {
|
|
|
|
keepFocus();
|
|
|
|
}
|
2013-11-20 21:57:00 +01:00
|
|
|
//tic();
|
2013-10-16 21:55:45 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
2013-10-21 21:47:28 +02:00
|
|
|
// First call the scrolling widget :
|
|
|
|
if (WidgetScrooled::onEventInput(_event) == true) {
|
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Second call plugin
|
2013-10-20 18:14:22 +02:00
|
|
|
if (appl::textPluginManager::onEventInput(*this, _event) == true) {
|
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-16 21:55:45 +02:00
|
|
|
vec2 relativePos = relativePosition(_event.getPos());
|
2013-10-21 21:47:28 +02:00
|
|
|
// offset for the lineNumber:
|
|
|
|
relativePos -= vec2(m_lastOffsetDisplay, 0);
|
|
|
|
// offset for the scrolling:
|
|
|
|
relativePos += vec2(m_originScrooled.x(), -m_originScrooled.y());
|
2013-10-16 21:55:45 +02:00
|
|
|
// invert for the buffer event ...
|
|
|
|
relativePos.setY(m_size.y()-relativePos.y());
|
2013-10-20 18:14:22 +02:00
|
|
|
if (relativePos.x()<0) {
|
|
|
|
relativePos.setX(0);
|
|
|
|
}
|
2013-11-19 21:43:43 +01:00
|
|
|
if ( _event.getId() == 12
|
2013-12-13 21:50:40 +01:00
|
|
|
&& _event.getStatus() == ewol::key::statusSingle) {
|
2013-11-19 21:43:43 +01:00
|
|
|
APPL_DEBUG("kjhkjhkjh");
|
|
|
|
// Rat5 save event
|
|
|
|
sendMultiCast(ednMsgGuiSave, "current");
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-16 21:55:45 +02:00
|
|
|
// just forward event == > manage directly in the buffer
|
2013-10-20 18:14:22 +02:00
|
|
|
if (_event.getId() == 1) {
|
|
|
|
// mouse selection :
|
2013-12-13 21:50:40 +01:00
|
|
|
if (_event.getType() == ewol::key::typeMouse) {
|
|
|
|
if (_event.getStatus() == ewol::key::statusDown) {
|
2013-11-20 21:57:00 +01:00
|
|
|
//if (_event.getSpecialKey().isSetShift() == false) {
|
|
|
|
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
|
|
|
|
moveCursor(newPos);
|
|
|
|
m_buffer->setSelectMode(true);
|
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
//}
|
2013-12-13 21:50:40 +01:00
|
|
|
} else if (_event.getStatus() == ewol::key::statusUp) {
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
|
|
|
|
moveCursor(newPos);
|
|
|
|
m_buffer->setSelectMode(false);
|
2013-11-20 21:57:00 +01:00
|
|
|
// Copy selection :
|
|
|
|
std::string value;
|
|
|
|
m_buffer->copy(value);
|
|
|
|
if (value.size() != 0) {
|
2013-12-13 21:50:40 +01:00
|
|
|
ewol::context::clipBoard::set(ewol::context::clipBoard::clipboardSelection, value);
|
2013-11-20 21:57:00 +01:00
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-12-13 21:50:40 +01:00
|
|
|
if (_event.getStatus() == ewol::key::statusSingle) {
|
2013-12-20 00:43:31 +01:00
|
|
|
if ( _event.getType() == ewol::key::typeMouse
|
|
|
|
|| _event.getType() == ewol::key::typeFinger) {
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
|
|
|
|
moveCursor(newPos);
|
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-13 21:50:40 +01:00
|
|
|
} else if (_event.getStatus() == ewol::key::statusDouble) {
|
2013-10-20 18:14:22 +02:00
|
|
|
mouseEventDouble();
|
2013-11-21 21:18:30 +01:00
|
|
|
// Copy selection :
|
|
|
|
std::string value;
|
|
|
|
m_buffer->copy(value);
|
|
|
|
if (value.size() != 0) {
|
2013-12-13 21:50:40 +01:00
|
|
|
ewol::context::clipBoard::set(ewol::context::clipBoard::clipboardSelection, value);
|
2013-11-21 21:18:30 +01:00
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
markToRedraw();
|
|
|
|
return true;
|
2013-12-13 21:50:40 +01:00
|
|
|
} else if (_event.getStatus() == ewol::key::statusTriple) {
|
2013-10-20 18:14:22 +02:00
|
|
|
mouseEventTriple();
|
2013-11-21 21:18:30 +01:00
|
|
|
// Copy selection :
|
|
|
|
std::string value;
|
|
|
|
m_buffer->copy(value);
|
|
|
|
if (value.size() != 0) {
|
2013-12-13 21:50:40 +01:00
|
|
|
ewol::context::clipBoard::set(ewol::context::clipBoard::clipboardSelection, value);
|
2013-11-21 21:18:30 +01:00
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
markToRedraw();
|
|
|
|
return true;
|
2013-12-13 21:50:40 +01:00
|
|
|
} else if (_event.getStatus() == ewol::key::statusMove) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (m_buffer->getSelectMode() == true) {
|
2013-12-05 22:16:04 +01:00
|
|
|
//int64_t timeStart = ewol::getTime();
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
|
2013-12-05 22:16:04 +01:00
|
|
|
//int64_t timeMedium1 = ewol::getTime();
|
2013-10-20 18:14:22 +02:00
|
|
|
moveCursor(newPos);
|
2013-12-05 22:16:04 +01:00
|
|
|
//int64_t timeMedium2 = ewol::getTime();
|
2013-10-20 18:14:22 +02:00
|
|
|
markToRedraw();
|
2013-12-05 22:16:04 +01:00
|
|
|
/*
|
|
|
|
int64_t timeStop = ewol::getTime();
|
|
|
|
APPL_DEBUG("Display selection=" << (timeStop-timeStart)/1000.0f << " ms");
|
|
|
|
APPL_DEBUG(" 1=" << (timeMedium1-timeStart)/1000.0f << " ms");
|
|
|
|
APPL_DEBUG(" 2=" << (timeMedium2-timeMedium1)/1000.0f << " ms");
|
|
|
|
*/
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (2 == _event.getId()) {
|
2013-12-13 21:50:40 +01:00
|
|
|
if (ewol::key::statusSingle == _event.getStatus()) {
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator newPos = getMousePosition(relativePos);
|
|
|
|
moveCursor(newPos);
|
2013-12-13 21:50:40 +01:00
|
|
|
ewol::context::clipBoard::request(ewol::context::clipBoard::clipboardSelection);
|
2013-10-20 18:14:22 +02:00
|
|
|
markToRedraw();
|
|
|
|
return true;
|
|
|
|
}
|
2013-10-16 21:55:45 +02:00
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void appl::TextViewer::mouseEventDouble(void) {
|
|
|
|
//m_selectMode = false;
|
|
|
|
appl::Buffer::Iterator beginPos, endPos;
|
|
|
|
if (true == m_buffer->getPosAround(m_buffer->cursor(), beginPos, endPos)) {
|
|
|
|
moveCursor(endPos);
|
|
|
|
m_buffer->setSelectionPos(beginPos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void appl::TextViewer::mouseEventTriple(void) {
|
|
|
|
//m_selectMode = false;
|
|
|
|
moveCursor(m_buffer->getEndLine(m_buffer->cursor()));
|
|
|
|
m_buffer->setSelectionPos(m_buffer->getStartLine(m_buffer->cursor()));
|
|
|
|
}
|
|
|
|
|
2013-12-05 22:16:04 +01:00
|
|
|
// TODO : optimise this with retaine the display position buffer and his position in the real view ...
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator appl::TextViewer::getMousePosition(const vec2& _relativePos) {
|
2013-11-14 21:57:10 +01:00
|
|
|
char32_t currentValue;
|
2013-10-20 18:14:22 +02:00
|
|
|
vec3 positionCurentDisplay(0,0,0);
|
2013-11-14 21:57:10 +01:00
|
|
|
vec3 tmpLetterSize = m_displayText.calculateSize((char32_t)'A');
|
2013-11-22 21:48:05 +01:00
|
|
|
int32_t countColomn = 0;
|
2013-11-14 21:57:10 +01:00
|
|
|
std::u32string stringToDisplay;
|
2013-10-20 18:14:22 +02:00
|
|
|
m_displayText.clear();
|
|
|
|
m_displayText.forceLineReturn();
|
2013-11-26 21:33:45 +01:00
|
|
|
positionCurentDisplay = m_displayText.getPos();
|
2013-10-20 18:14:22 +02:00
|
|
|
for (appl::Buffer::Iterator it = m_buffer->begin();
|
2013-10-26 13:16:30 +02:00
|
|
|
(bool)it == true;
|
2013-10-20 18:14:22 +02:00
|
|
|
++it) {
|
|
|
|
currentValue = *it;
|
2013-12-05 22:16:04 +01:00
|
|
|
if (currentValue == etk::UChar::Return) {
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
countColomn = 0;
|
|
|
|
} else {
|
|
|
|
if (-_relativePos.y() >= positionCurentDisplay.y()) {
|
|
|
|
m_buffer->expand(countColomn, currentValue, stringToDisplay);
|
|
|
|
for (size_t kkk=0; kkk<stringToDisplay.size(); ++kkk) {
|
|
|
|
if (stringToDisplay[kkk] == etk::UChar::Return) {
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
countColomn = 0;
|
|
|
|
} else {
|
|
|
|
//note : Without this condithion the time od selection change to 0.6 ms to 8ms ...
|
|
|
|
//APPL_DEBUG("check : " << -_relativePos.y() << ">=" << positionCurentDisplay.y());
|
|
|
|
m_displayText.print(stringToDisplay[kkk]);
|
|
|
|
++countColomn;
|
|
|
|
}
|
2013-11-20 21:57:00 +01:00
|
|
|
}
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (-_relativePos.y() >= positionCurentDisplay.y()) {
|
|
|
|
if (-_relativePos.y() < positionCurentDisplay.y()+tmpLetterSize.y()) {
|
2013-11-24 15:26:47 +01:00
|
|
|
APPL_VERBOSE("line position : '" << (char)(*it) << "' = '" << stringToDisplay << "' n=" << countColomn << " " <<positionCurentDisplay.x() << " < " << _relativePos.x() << " < " << m_displayText.getPos().x() );
|
2013-10-20 18:14:22 +02:00
|
|
|
if ( _relativePos.x() >= positionCurentDisplay.x()
|
|
|
|
&& _relativePos.x() < m_displayText.getPos().x() ) {
|
2013-11-24 15:26:47 +01:00
|
|
|
APPL_VERBOSE("find ...");
|
2013-10-20 18:14:22 +02:00
|
|
|
return it;
|
|
|
|
}
|
|
|
|
} else {
|
2013-11-24 15:26:47 +01:00
|
|
|
// previous line ...
|
2013-10-20 18:14:22 +02:00
|
|
|
return --it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
positionCurentDisplay = m_displayText.getPos();
|
|
|
|
}
|
|
|
|
return m_buffer->end();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
void appl::TextViewer::onEventClipboard(enum ewol::context::clipBoard::clipboardListe _clipboardID) {
|
2013-09-26 22:15:39 +02:00
|
|
|
if (m_buffer != NULL) {
|
2013-12-13 21:50:40 +01:00
|
|
|
std::string data = ewol::context::clipBoard::get(_clipboardID);
|
2013-10-20 18:14:22 +02:00
|
|
|
write(data);
|
2013-09-26 22:15:39 +02:00
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
markToRedraw();
|
2013-09-26 22:15:39 +02:00
|
|
|
}
|
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
void appl::TextViewer::onReceiveMessage(const ewol::object::Message& _msg) {
|
|
|
|
ewol::widget::WidgetScrooled::onReceiveMessage(_msg);
|
2013-11-20 21:57:00 +01:00
|
|
|
APPL_VERBOSE("receive msg: " << _msg);
|
2013-10-30 21:16:38 +01:00
|
|
|
// First call plugin
|
2013-10-20 18:14:22 +02:00
|
|
|
if (appl::textPluginManager::onReceiveMessage(*this, _msg) == true) {
|
|
|
|
markToRedraw();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-07 21:08:57 +01:00
|
|
|
// event needed even if selection of buffer is not done ...
|
|
|
|
if (_msg.getMessage() == appl::Buffer::eventIsModify) {
|
|
|
|
markToRedraw();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_msg.getMessage() == appl::Buffer::eventSelectChange) {
|
|
|
|
markToRedraw();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If not the last buffer selected, then no event parsing ...
|
|
|
|
if (isSelectedLast() == false) {
|
|
|
|
return;
|
|
|
|
}
|
2013-11-26 21:22:06 +01:00
|
|
|
if (_msg.getMessage() == appl::MsgSelectGotoLineSelect) {
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
appl::Buffer::Iterator it = m_buffer->countForwardNLines(m_buffer->begin(), std::stoi(_msg.getData()));
|
|
|
|
select(it, m_buffer->getEndLine(it));
|
|
|
|
markToRedraw();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_msg.getMessage() == appl::MsgSelectGotoLine) {
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
appl::Buffer::Iterator it = m_buffer->countForwardNLines(m_buffer->begin(), std::stoi(_msg.getData()));
|
|
|
|
moveCursor(it);
|
|
|
|
markToRedraw();
|
|
|
|
return;
|
|
|
|
}
|
2013-10-29 21:13:45 +01:00
|
|
|
if (_msg.getMessage() == appl::MsgSelectNewFile) {
|
2013-11-21 21:18:30 +01:00
|
|
|
// reset scroll:
|
2013-10-30 21:16:38 +01:00
|
|
|
if (m_buffer != NULL) {
|
|
|
|
m_buffer->unRegisterOnEvent(this);
|
2013-11-21 21:18:30 +01:00
|
|
|
bool needAdd = true;
|
|
|
|
for (size_t iii=0; iii<m_drawingRemenber.size(); ++iii) {
|
|
|
|
if (m_drawingRemenber[iii].first == m_buffer) {
|
|
|
|
m_drawingRemenber[iii].second = m_originScrooled;
|
|
|
|
APPL_VERBOSE("store origin : " << m_originScrooled);
|
|
|
|
needAdd = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (needAdd == true) {
|
|
|
|
m_drawingRemenber.push_back(std::make_pair(m_buffer, m_originScrooled));
|
|
|
|
APPL_VERBOSE("Push origin : " << m_originScrooled);
|
|
|
|
}
|
2013-10-30 21:16:38 +01:00
|
|
|
}
|
2013-11-21 21:18:30 +01:00
|
|
|
m_originScrooled = vec2(0,0);
|
2013-11-07 21:08:57 +01:00
|
|
|
if (m_bufferManager != NULL) {
|
2013-11-21 21:18:30 +01:00
|
|
|
m_buffer = m_bufferManager->get(_msg.getData());
|
2013-11-07 21:08:57 +01:00
|
|
|
m_bufferManager->setBufferSelected(m_buffer);
|
2013-11-21 21:18:30 +01:00
|
|
|
if (m_buffer != NULL) {
|
|
|
|
m_buffer->registerOnEvent(this, appl::Buffer::eventIsModify);
|
|
|
|
m_buffer->registerOnEvent(this, appl::Buffer::eventSelectChange);
|
|
|
|
for (auto element : m_drawingRemenber) {
|
|
|
|
if (element.first == m_buffer) {
|
|
|
|
m_originScrooled = element.second;
|
|
|
|
APPL_VERBOSE("retrive origin : " << m_originScrooled);
|
|
|
|
// TODO : Check if this element is not out of the display text ...
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-11-07 21:08:57 +01:00
|
|
|
}
|
2013-10-30 21:16:38 +01:00
|
|
|
markToRedraw();
|
|
|
|
return;
|
2013-10-29 21:13:45 +01:00
|
|
|
}
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-12-13 21:50:40 +01:00
|
|
|
void appl::TextViewer::onObjectRemove(ewol::Object* _removeObject) {
|
|
|
|
ewol::widget::WidgetScrooled::onObjectRemove(_removeObject);
|
2013-10-29 21:13:45 +01:00
|
|
|
if (m_buffer == _removeObject) {
|
|
|
|
m_buffer = NULL;
|
|
|
|
markToRedraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
void appl::TextViewer::onGetFocus(void) {
|
|
|
|
showKeyboard();
|
2013-09-19 22:23:31 +02:00
|
|
|
APPL_INFO("Focus - In");
|
2013-11-07 21:08:57 +01:00
|
|
|
setCurrentSelect();
|
|
|
|
markToRedraw();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
void appl::TextViewer::onLostFocus(void) {
|
|
|
|
hideKeyboard();
|
2013-09-19 22:23:31 +02:00
|
|
|
APPL_INFO("Focus - out");
|
2013-11-07 21:08:57 +01:00
|
|
|
markToRedraw();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
void appl::TextViewer::setFontSize(int32_t _size) {
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setFontSize(_size);
|
|
|
|
setScrollingSize(_size*3.0*1.46); // 1.46 is a magic number ...
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-11-14 21:57:10 +01:00
|
|
|
void appl::TextViewer::setFontName(const std::string& _fontName) {
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setFontName(_fontName);
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-12-05 22:16:04 +01:00
|
|
|
// TODO : Update process time ==> a little expensive (2->4ms) in end of file
|
2013-11-20 21:57:00 +01:00
|
|
|
void appl::TextViewer::updateScrolling(void) {
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
vec2 realCursorPosition(0,0);
|
|
|
|
uint32_t lineId = m_buffer->getCursorLinesId();
|
|
|
|
m_displayText.clear();
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
float lineSize = -m_displayText.getPos().y();
|
|
|
|
for (size_t iii=0; iii<lineId; ++iii) {
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
}
|
|
|
|
realCursorPosition.setY(-m_displayText.getPos().y());
|
2013-11-23 18:30:52 +01:00
|
|
|
realCursorPosition.setX(getScreenSize(m_buffer->getStartLine(m_buffer->cursor()), m_buffer->cursor()));
|
2013-11-20 21:57:00 +01:00
|
|
|
APPL_VERBOSE("position=" << realCursorPosition << " scrool=" << m_originScrooled << " size" << m_size);
|
2013-11-23 18:30:52 +01:00
|
|
|
if (realCursorPosition.x() < m_originScrooled.x()+lineSize*2.0f) {
|
2013-11-20 21:57:00 +01:00
|
|
|
m_originScrooled.setX(realCursorPosition.x()-lineSize*2.0f);
|
2013-11-23 18:30:52 +01:00
|
|
|
} else if (realCursorPosition.x() > m_originScrooled.x()+(m_size.x()-m_lastOffsetDisplay)-lineSize*2.0f-10) {
|
|
|
|
m_originScrooled.setX(realCursorPosition.x()-(m_size.x()-m_lastOffsetDisplay)+lineSize*2.0f+10);
|
2013-11-20 21:57:00 +01:00
|
|
|
}
|
|
|
|
if (realCursorPosition.y() < m_originScrooled.y()+lineSize*2.0f) {
|
|
|
|
m_originScrooled.setY(realCursorPosition.y()-lineSize*2.0f);
|
|
|
|
} else if (realCursorPosition.y() > m_originScrooled.y()+m_size.y()-lineSize*2.0f) {
|
|
|
|
m_originScrooled.setY(realCursorPosition.y()-m_size.y()+lineSize*2.0f);
|
|
|
|
}
|
2013-11-21 21:22:38 +01:00
|
|
|
m_originScrooled.setMax(vec2(0,0));
|
2013-11-21 21:56:22 +01:00
|
|
|
// TODO : Limit min position too ...
|
2013-11-20 21:57:00 +01:00
|
|
|
}
|
|
|
|
|
2013-10-20 18:14:22 +02:00
|
|
|
bool appl::TextViewer::moveCursor(const appl::Buffer::Iterator& _pos) {
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
2013-10-20 18:14:22 +02:00
|
|
|
if (appl::textPluginManager::onCursorMove(*this, _pos) == true) {
|
2013-11-20 21:57:00 +01:00
|
|
|
updateScrolling();
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-11-22 21:48:05 +01:00
|
|
|
m_buffer->moveCursor((int64_t)_pos);
|
2013-11-20 21:57:00 +01:00
|
|
|
updateScrolling();
|
2013-10-20 18:14:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-14 21:57:10 +01:00
|
|
|
bool appl::TextViewer::write(const std::string& _data) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_buffer->hasTextSelected() == true) {
|
|
|
|
return replace(_data);
|
|
|
|
}
|
|
|
|
return write(_data, m_buffer->cursor());
|
|
|
|
}
|
|
|
|
|
2013-11-14 21:57:10 +01:00
|
|
|
bool appl::TextViewer::write(const std::string& _data, const appl::Buffer::Iterator& _pos) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
2013-10-20 18:14:22 +02:00
|
|
|
if (appl::textPluginManager::onWrite(*this, _pos, _data) == true) {
|
2013-10-22 21:34:13 +02:00
|
|
|
// no call of the move cursor, because pluging might call theses function to copy and cut data...
|
2013-11-27 21:45:56 +01:00
|
|
|
updateScrolling();
|
2013-10-22 21:34:13 +02:00
|
|
|
return true;
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
bool ret = m_buffer->write(_data, _pos);
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor());
|
2013-11-27 21:45:56 +01:00
|
|
|
updateScrolling();
|
2013-10-20 18:14:22 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-14 21:57:10 +01:00
|
|
|
bool appl::TextViewer::replace(const std::string& _data, const appl::Buffer::Iterator& _pos, const appl::Buffer::Iterator& _posEnd) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
2013-10-20 18:14:22 +02:00
|
|
|
if (appl::textPluginManager::onReplace(*this, _pos, _data, _posEnd) == true) {
|
2013-10-22 21:34:13 +02:00
|
|
|
// no call of the move cursor, because pluging might call theses function to copy and cut data...
|
2013-11-27 21:45:56 +01:00
|
|
|
updateScrolling();
|
2013-10-22 21:34:13 +02:00
|
|
|
return true;
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
bool ret = m_buffer->replace(_data, _pos, _posEnd);
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor());
|
2013-11-27 21:45:56 +01:00
|
|
|
updateScrolling();
|
2013-10-20 18:14:22 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-14 21:57:10 +01:00
|
|
|
bool appl::TextViewer::replace(const std::string& _data) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_buffer->hasTextSelected() == false) {
|
|
|
|
return write(_data);
|
|
|
|
}
|
|
|
|
return replace(_data, m_buffer->selectStart(), m_buffer->selectStop());
|
|
|
|
}
|
|
|
|
|
|
|
|
void appl::TextViewer::remove(void) {
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_buffer->hasTextSelected() == false) {
|
|
|
|
// nothing to do ...
|
|
|
|
return;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
|
|
|
if (appl::textPluginManager::onRemove(*this, m_buffer->selectStart(), m_buffer->selectStop()) == true) {
|
|
|
|
return;
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
m_buffer->removeSelection();
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::textPluginManager::onCursorMove(*this, m_buffer->cursor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void appl::TextViewer::moveCursorRight(appl::TextViewer::moveMode _mode) {
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator it;
|
|
|
|
switch (_mode) {
|
|
|
|
default:
|
|
|
|
case moveLetter:
|
|
|
|
it = m_buffer->cursor();
|
2013-11-23 12:25:42 +01:00
|
|
|
++it;
|
2013-10-20 18:14:22 +02:00
|
|
|
moveCursor(it);
|
|
|
|
break;
|
|
|
|
case moveWord:
|
|
|
|
// TODO : ...
|
|
|
|
break;
|
|
|
|
case moveEnd:
|
|
|
|
it = m_buffer->getEndLine(m_buffer->cursor());
|
|
|
|
moveCursor(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void appl::TextViewer::moveCursorLeft(appl::TextViewer::moveMode _mode) {
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
2013-10-20 18:14:22 +02:00
|
|
|
appl::Buffer::Iterator it;
|
|
|
|
switch (_mode) {
|
|
|
|
default:
|
|
|
|
case moveLetter:
|
2013-11-23 12:25:42 +01:00
|
|
|
it = m_buffer->cursor();
|
2013-10-20 18:14:22 +02:00
|
|
|
--it;
|
|
|
|
moveCursor(it);
|
|
|
|
break;
|
|
|
|
case moveWord:
|
|
|
|
// TODO : ...
|
|
|
|
break;
|
|
|
|
case moveEnd:
|
|
|
|
it = m_buffer->getStartLine(m_buffer->cursor());
|
2013-11-21 21:56:22 +01:00
|
|
|
moveCursor(it);
|
2013-10-20 18:14:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 21:48:05 +01:00
|
|
|
void appl::TextViewer::moveCursorUp(uint32_t _nbLine) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
2013-10-20 18:14:22 +02:00
|
|
|
// find the position of the start of the line.
|
|
|
|
appl::Buffer::Iterator lineStartPos = m_buffer->getStartLine(m_buffer->cursor());
|
|
|
|
// check if we can go up ...
|
|
|
|
if (lineStartPos == m_buffer->begin()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Decide what column to move to, if there's a preferred column use that
|
|
|
|
if (m_buffer->getFavoriteUpDownPos() < 0) {
|
2013-11-21 21:56:22 +01:00
|
|
|
m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos, m_buffer->cursor()));
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
// get the previous line
|
2013-11-21 21:56:22 +01:00
|
|
|
appl::Buffer::Iterator prevLineStartPos = m_buffer->countBackwardNLines(lineStartPos-1, _nbLine);
|
2013-10-20 18:14:22 +02:00
|
|
|
//APPL_INFO("Move line UP result : prevLineStartPos=" << prevLineStartPos);
|
|
|
|
// get the display char position
|
|
|
|
appl::Buffer::Iterator newPos = getPosSize(prevLineStartPos, m_buffer->getFavoriteUpDownPos());
|
|
|
|
//APPL_INFO("Move to colomn : column=" << column << " newPos=" << newPos);
|
|
|
|
float posStore = m_buffer->getFavoriteUpDownPos();
|
|
|
|
moveCursor(newPos);
|
|
|
|
m_buffer->setFavoriteUpDownPos(posStore);
|
|
|
|
}
|
|
|
|
|
2013-11-22 21:48:05 +01:00
|
|
|
void appl::TextViewer::moveCursorDown(uint32_t _nbLine) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-22 21:34:13 +02:00
|
|
|
markToRedraw();
|
2013-10-20 18:14:22 +02:00
|
|
|
// check if we are not at the end of Buffer
|
|
|
|
if (m_buffer->cursor() == m_buffer->end() ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// find the position of the start of the line.
|
|
|
|
appl::Buffer::Iterator lineStartPos = m_buffer->getStartLine(m_buffer->cursor());
|
|
|
|
|
|
|
|
if (m_buffer->getFavoriteUpDownPos() < 0) {
|
2013-11-21 21:56:22 +01:00
|
|
|
m_buffer->setFavoriteUpDownPos(getScreenSize(lineStartPos, m_buffer->cursor()));
|
2013-10-20 18:14:22 +02:00
|
|
|
}
|
|
|
|
// get the next line :
|
|
|
|
appl::Buffer::Iterator nextLineStartPos = m_buffer->countForwardNLines(lineStartPos, _nbLine);
|
|
|
|
//APPL_INFO("Move line DOWN result : nextLineStartPos=" << nextLineStartPos);
|
|
|
|
// get the display char position
|
|
|
|
appl::Buffer::Iterator newPos = getPosSize(nextLineStartPos, m_buffer->getFavoriteUpDownPos());
|
|
|
|
//APPL_INFO("Move to colomn : column=" << column << " newPos=" << newPos);
|
|
|
|
float posStore = m_buffer->getFavoriteUpDownPos();
|
|
|
|
moveCursor(newPos);
|
|
|
|
m_buffer->setFavoriteUpDownPos(posStore);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO : Rename ...
|
|
|
|
appl::Buffer::Iterator appl::TextViewer::getPosSize(const appl::Buffer::Iterator& _startLinePos, float _distance) {
|
2013-11-14 21:57:10 +01:00
|
|
|
char32_t currentValue;
|
2013-11-22 21:48:05 +01:00
|
|
|
int32_t countColomn = 0;
|
2013-11-14 21:57:10 +01:00
|
|
|
std::u32string stringToDisplay;
|
2013-10-20 18:14:22 +02:00
|
|
|
m_displayText.clear();
|
|
|
|
m_displayText.forceLineReturn();
|
|
|
|
for (appl::Buffer::Iterator it = _startLinePos;
|
2013-10-26 13:16:30 +02:00
|
|
|
(bool)it == true;
|
2013-10-20 18:14:22 +02:00
|
|
|
++it) {
|
|
|
|
currentValue = *it;
|
|
|
|
m_buffer->expand(countColomn, currentValue, stringToDisplay);
|
2013-11-22 21:48:05 +01:00
|
|
|
for (size_t kkk=0; kkk<stringToDisplay.size(); ++kkk) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (stringToDisplay[kkk] == etk::UChar::Return) {
|
|
|
|
return it;
|
|
|
|
} else {
|
|
|
|
m_displayText.print(stringToDisplay[kkk]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_displayText.getPos().x() >= _distance) {
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
countColomn += stringToDisplay.size();
|
|
|
|
}
|
|
|
|
return m_buffer->end();
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO : Rename ...
|
|
|
|
float appl::TextViewer::getScreenSize(const appl::Buffer::Iterator& _startLinePos, const appl::Buffer::Iterator& _stopPos) {
|
|
|
|
float ret = 0;
|
2013-11-14 21:57:10 +01:00
|
|
|
char32_t currentValue;
|
2013-11-22 21:48:05 +01:00
|
|
|
int32_t countColomn = 0;
|
2013-11-14 21:57:10 +01:00
|
|
|
std::u32string stringToDisplay;
|
2013-10-20 18:14:22 +02:00
|
|
|
m_displayText.clear();
|
|
|
|
|
|
|
|
for (appl::Buffer::Iterator it = _startLinePos;
|
2013-10-26 13:16:30 +02:00
|
|
|
(bool)it == true && it <= _stopPos;
|
2013-10-20 18:14:22 +02:00
|
|
|
++it) {
|
|
|
|
currentValue = *it;
|
|
|
|
//APPL_DEBUG("parse : " << currentValue);
|
|
|
|
m_buffer->expand(countColomn, currentValue, stringToDisplay);
|
2013-11-22 21:48:05 +01:00
|
|
|
for (size_t kkk=0; kkk<stringToDisplay.size(); ++kkk) {
|
2013-10-20 18:14:22 +02:00
|
|
|
if (stringToDisplay[kkk] == etk::UChar::Return) {
|
|
|
|
return m_displayText.getPos().x() + 2; // TODO : Add the +2 for the end of line ...
|
|
|
|
} else {
|
|
|
|
m_displayText.print(stringToDisplay[kkk]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret = m_displayText.getPos().x();
|
|
|
|
countColomn += stringToDisplay.size();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2013-11-07 21:08:57 +01:00
|
|
|
|
|
|
|
void appl::TextViewer::setCurrentSelect(void) {
|
2013-11-23 18:30:52 +01:00
|
|
|
if (m_viewerManager != NULL) {
|
|
|
|
m_viewerManager->setViewerSelected(this, m_buffer);
|
2013-11-07 21:08:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appl::TextViewer::isSelectedLast(void) {
|
2013-11-23 18:30:52 +01:00
|
|
|
if (m_viewerManager != NULL) {
|
|
|
|
return m_viewerManager->isLastSelected(this);
|
2013-11-07 21:08:57 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|