2013-09-19 22:23:31 +02:00
|
|
|
/**
|
|
|
|
* @author Edouard DUPIN
|
|
|
|
*
|
|
|
|
* @copyright 2010, Edouard DUPIN, all right reserved
|
|
|
|
*
|
|
|
|
* @license GPL v3 (see license file)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <CodeView.h>
|
|
|
|
|
|
|
|
#include <appl/Debug.h>
|
|
|
|
#include <appl/global.h>
|
|
|
|
#include <TextViewer.h>
|
|
|
|
#include <BufferManager.h>
|
|
|
|
#include <ColorizeManager.h>
|
|
|
|
#include <ewol/clipBoard.h>
|
|
|
|
#include <SearchData.h>
|
|
|
|
|
|
|
|
#include <ewol/widget/WidgetManager.h>
|
|
|
|
#include <ewol/renderer/EObject.h>
|
|
|
|
|
|
|
|
#undef __class__
|
|
|
|
#define __class__ "TextViewer"
|
|
|
|
|
|
|
|
appl::TextViewer::TextViewer(const etk::UString& _fontName, int32_t _fontSize) :
|
|
|
|
m_buffer(NULL),
|
2013-09-26 22:15:39 +02:00
|
|
|
m_displayText(_fontName, _fontSize),
|
|
|
|
m_insertMode(false)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
2013-10-07 22:04:21 +02:00
|
|
|
setCanHaveFocus(true);
|
2013-09-19 22:23:31 +02:00
|
|
|
RegisterMultiCast(ednMsgBufferId);
|
|
|
|
RegisterMultiCast(ednMsgGuiCopy);
|
|
|
|
RegisterMultiCast(ednMsgGuiPaste);
|
|
|
|
RegisterMultiCast(ednMsgGuiCut);
|
|
|
|
RegisterMultiCast(ednMsgGuiRedo);
|
|
|
|
RegisterMultiCast(ednMsgGuiUndo);
|
|
|
|
RegisterMultiCast(ednMsgGuiRm);
|
|
|
|
RegisterMultiCast(ednMsgGuiSelect);
|
|
|
|
RegisterMultiCast(ednMsgGuiChangeCharset);
|
|
|
|
RegisterMultiCast(ednMsgGuiFind);
|
|
|
|
RegisterMultiCast(ednMsgGuiReplace);
|
|
|
|
RegisterMultiCast(ednMsgGuiGotoLine);
|
2013-10-07 22:04:21 +02:00
|
|
|
setLimitScrolling(0.2);
|
2013-09-19 22:23:31 +02:00
|
|
|
|
|
|
|
ShortCutAdd("ctrl+w", ednMsgGuiRm, "Line");
|
|
|
|
ShortCutAdd("ctrl+shift+w", ednMsgGuiRm, "Paragraph");
|
|
|
|
ShortCutAdd("ctrl+x", ednMsgGuiCut, "STD");
|
|
|
|
ShortCutAdd("ctrl+c", ednMsgGuiCopy, "STD");
|
|
|
|
ShortCutAdd("ctrl+v", ednMsgGuiPaste, "STD");
|
|
|
|
ShortCutAdd("ctrl+a", ednMsgGuiSelect, "ALL");
|
|
|
|
ShortCutAdd("ctrl+shift+a", ednMsgGuiSelect, "NONE");
|
|
|
|
|
|
|
|
// by default we load an example object:
|
|
|
|
|
|
|
|
m_buffer = new appl::Buffer();
|
|
|
|
if (m_buffer == NULL) {
|
|
|
|
APPL_ERROR("can not create buffer ... ");
|
|
|
|
return;
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
m_buffer->loadFile("./example.txt");
|
2013-09-19 22:23:31 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
appl::TextViewer::~TextViewer(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
bool appl::TextViewer::calculateMinSize(void)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
|
|
|
m_minSize.setValue(50,50);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::calculateMaxSize(void)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
|
|
|
m_maxSize.setX(256);
|
|
|
|
m_maxSize.setY(256);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::onDraw(void)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
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-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::onRegenerateDisplay(void)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
2013-10-07 22:04:21 +02:00
|
|
|
if (false == needRedraw()) {
|
2013-09-26 22:15:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// For the scrooling windows
|
2013-10-07 22:04:21 +02:00
|
|
|
calculateMaxSize();
|
|
|
|
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));
|
|
|
|
m_displayDrawing.setColor(etk::Color<>(220, 220, 220, 256));
|
|
|
|
m_displayDrawing.rectangleWidth(m_size);
|
2013-09-26 22:15:39 +02:00
|
|
|
|
|
|
|
if (m_buffer == NULL) {
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setTextAlignement(10, m_size.x()-20, ewol::Text::alignLeft);
|
|
|
|
m_displayText.setRelPos(vec3(10, 0, 0));
|
2013-09-26 22:15:39 +02:00
|
|
|
etk::UString tmpString("<br/>\n"
|
|
|
|
"<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);
|
|
|
|
// 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;
|
|
|
|
esize_t countColomn = 0;
|
2013-10-07 22:04:21 +02:00
|
|
|
vec3 tmpLetterSize = m_displayText.calculateSize((uniChar_t)'A');
|
2013-09-26 22:15:39 +02:00
|
|
|
vec3 positionCurentDisplay(0.0f, m_size.y()-tmpLetterSize.y(), 0.0f);
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setPos(positionCurentDisplay);
|
2013-09-26 22:15:39 +02:00
|
|
|
// the siplay string :
|
|
|
|
etk::UString stringToDisplay;
|
|
|
|
esize_t bufferElementSize = 0;
|
|
|
|
etk::UniChar currentValue;
|
2013-10-07 22:04:21 +02:00
|
|
|
for (int32_t iii=0; iii<buf.size(); iii+=bufferElementSize) {
|
|
|
|
if (iii == m_buffer->m_cursorPos) {
|
2013-09-26 22:15:39 +02:00
|
|
|
// need to display the cursor :
|
|
|
|
tmpCursorPosition = positionCurentDisplay;
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
bufferElementSize = m_buffer->get(iii, currentValue);
|
2013-09-26 22:15:39 +02:00
|
|
|
//APPL_DEBUG(" element size : " << iii << " : " << bufferElementSize);
|
|
|
|
if (currentValue == etk::UniChar::Return) {
|
|
|
|
countNbLine += 1;
|
|
|
|
countColomn = 0;
|
2013-10-07 22:04:21 +02:00
|
|
|
if (bufferElementSize == 0) {
|
2013-09-26 22:15:39 +02:00
|
|
|
bufferElementSize = 1;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
2013-09-26 22:15:39 +02:00
|
|
|
positionCurentDisplay.setX(0);
|
|
|
|
positionCurentDisplay.setY(positionCurentDisplay.y()-tmpLetterSize.y());
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setPos(positionCurentDisplay);
|
2013-09-26 22:15:39 +02:00
|
|
|
continue;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
2013-09-30 00:08:52 +02:00
|
|
|
m_buffer->Expand(countColomn, currentValue, stringToDisplay);
|
2013-10-07 22:04:21 +02:00
|
|
|
//APPL_DEBUG("display : '" << currentValue << "' == > '" << stringToDisplay << "'");
|
|
|
|
//m_displayText.setPos(positionCurentDisplay);
|
|
|
|
for (esize_t kkk=0; kkk<stringToDisplay.size(); ++kkk) {
|
|
|
|
m_displayText.print(stringToDisplay[kkk]);
|
2013-09-26 22:15:39 +02:00
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
positionCurentDisplay = m_displayText.getPos();
|
|
|
|
countColomn += stringToDisplay.size();
|
2013-09-26 22:15:39 +02:00
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
if (bufferElementSize == 0) {
|
2013-09-26 22:15:39 +02:00
|
|
|
bufferElementSize = 1;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
2013-09-26 22:15:39 +02:00
|
|
|
if (tmpCursorPosition.z()!=-1) {
|
|
|
|
// 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);
|
|
|
|
m_displayText.setColor(etk::Color<>(0xFF0000FF));
|
|
|
|
m_displayText.setColorBg(etk::Color<>(0xFF0000FF));
|
|
|
|
m_displayText.printCursor(m_insertMode);
|
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-09-26 22:15:39 +02:00
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
bool appl::TextViewer::onEventEntry(const ewol::EventEntry& _event)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
2013-09-26 22:15:39 +02:00
|
|
|
if (m_buffer == NULL) {
|
|
|
|
return false;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
// just forward event == > manage directly in the buffer
|
|
|
|
if (m_buffer->onEventEntry(_event) == true) {
|
|
|
|
markToRedraw();
|
2013-09-26 22:15:39 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
2013-09-26 22:15:39 +02:00
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
bool appl::TextViewer::onEventInput(const ewol::EventInput& _event)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
2013-10-07 22:04:21 +02:00
|
|
|
vec2 relativePos = relativePosition(_event.getPos());
|
2013-09-19 22:23:31 +02:00
|
|
|
if (m_buffer != NULL) {
|
|
|
|
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
keepFocus();
|
2013-09-19 22:23:31 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::onEventClipboard(ewol::clipBoard::clipboardListe_te _clipboardID)
|
2013-09-26 22:15:39 +02:00
|
|
|
{
|
|
|
|
if (m_buffer != NULL) {
|
|
|
|
//tmpBuffer->Paste(_clipboardID);
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
markToRedraw();
|
2013-09-26 22:15:39 +02:00
|
|
|
}
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::onReceiveMessage(const ewol::EMessage& _msg)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
2013-10-07 22:04:21 +02:00
|
|
|
// force redraw of the widget
|
|
|
|
markToRedraw();
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::onGetFocus(void)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
|
|
|
ShowKeyboard();
|
|
|
|
APPL_INFO("Focus - In");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::onLostFocus(void)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
|
|
|
HideKeyboard();
|
|
|
|
APPL_INFO("Focus - out");
|
|
|
|
}
|
|
|
|
|
2013-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::setFontSize(int32_t _size)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
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-10-07 22:04:21 +02:00
|
|
|
void appl::TextViewer::setFontName(const etk::UString& _fontName)
|
2013-09-19 22:23:31 +02:00
|
|
|
{
|
2013-10-07 22:04:21 +02:00
|
|
|
m_displayText.setFontName(_fontName);
|
2013-09-19 22:23:31 +02:00
|
|
|
}
|
|
|
|
|