Uniformisation of the UNICODE in the soft

This commit is contained in:
Edouard Dupin 2012-02-13 18:03:09 +01:00
parent 71fa38d61e
commit cd84475aea
6 changed files with 83 additions and 90 deletions

View File

@ -270,7 +270,7 @@ void Buffer::cursorMove(ewol::eventKbMoveType_te moveTypeEvent)
* @return ---
*
*/
void Buffer::AddChar(char * UTF8data)
void Buffer::AddChar(uniChar_t unicodeData)
{
// nothing to do
}

View File

@ -88,7 +88,7 @@ class Buffer {
ewol::OObject2DTextColored* OOTextBoldItalic,
ewol::OObject2DColored* OOColored, int32_t offsetX, int32_t offsetY, int32_t sizeX, int32_t sizeY);
virtual void ForceReDraw(bool allElement);
virtual void AddChar(char * UTF8data);
virtual void AddChar(uniChar_t unicodeData);
virtual void cursorMove(ewol::eventKbMoveType_te moveTypeEvent);
virtual void MouseSelectFromCursorTo(int32_t width, int32_t height);
virtual void MouseEvent(int32_t width, int32_t height);

View File

@ -29,6 +29,7 @@
#include <BufferText.h>
#include <toolsMemory.h>
#include <etk/RegExp.h>
#include <etk/unicode.h>
#include <ewol/ewol.h>
#include <ewol/OObject.h>
@ -1035,102 +1036,94 @@ void BufferText::UpdateWindowsPosition(bool centerPage)
* @return ---
*
*/
void BufferText::AddChar(char * UTF8data)
void BufferText::AddChar(uniChar_t unicodeData)
{
int32_t SelectionStart, SelectionEnd, SelectionRectStart, SelectionRectEnd;
bool SelectionIsRect;
bool haveSelectionActive = m_EdnBuf.GetSelectionPos(SELECTION_PRIMARY, SelectionStart, SelectionEnd, SelectionIsRect, SelectionRectStart, SelectionRectEnd);
int32_t size=strlen(UTF8data);
bool actionDone = false;
if (1==size) {
if (UTF8data[0] == 0x09) {
if (false == haveSelectionActive) {
if (unicodeData == 0x09) {
if (false == haveSelectionActive) {
etk::VectorType<int8_t> tmpVect;
tmpVect.PushBack(0x09);
m_EdnBuf.Insert(m_cursorPos, tmpVect);
SetInsertPosition(m_cursorPos+1, true);
} else {
// Indent depend of the multiline in the selection ...
// count the number of line :
int32_t nbSelectedLines = m_EdnBuf.CountLines(SelectionStart, SelectionEnd);
if (0 == nbSelectedLines) {
etk::VectorType<int8_t> tmpVect;
tmpVect.PushBack(0x09);
m_EdnBuf.Insert(m_cursorPos, tmpVect);
SetInsertPosition(m_cursorPos+1, true);
} else {
// Indent depend of the multiline in the selection ...
// count the number of line :
int32_t nbSelectedLines = m_EdnBuf.CountLines(SelectionStart, SelectionEnd);
if (0 == nbSelectedLines) {
etk::VectorType<int8_t> tmpVect;
tmpVect.PushBack(0x09);
m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, tmpVect);
SetInsertPosition(SelectionStart+tmpVect.Size(), true);
} else {
if (true == ewol::IsSetShift() ) {
m_cursorPos = m_EdnBuf.UnIndent(SELECTION_PRIMARY);
} else {
m_cursorPos = m_EdnBuf.Indent(SELECTION_PRIMARY);
}
}
}
actionDone = true;
} else if (UTF8data[0] == '\n') {
etk::VectorType<int8_t> tmpVect;
if (true == ewol::IsSetShift()) {
tmpVect.PushBack('\r');
} else {
tmpVect.PushBack('\n');
// if Auto indent Enable ==> we get the start of the previous line and add it to tne new one
if (true == globals::IsSetAutoIndent() ) {
int32_t l_lineStart;
// Get the begin of the line or the begin of the line befor selection
if (false == haveSelectionActive) {
l_lineStart = m_EdnBuf.StartOfLine(m_cursorPos);
} else {
l_lineStart = m_EdnBuf.StartOfLine(SelectionStart);
}
// add same characters in the temporar buffer
for (int32_t kk=l_lineStart; kk<m_cursorPos; kk++) {
if (' ' == m_EdnBuf[kk]) {
tmpVect.PushBack(' ');
} else if('\t' == m_EdnBuf[kk]) {
tmpVect.PushBack('\t');
} else {
break;
}
}
}
}
// Set temporary buffer in the real buffer
if (false == haveSelectionActive) {
m_EdnBuf.Insert(m_cursorPos, tmpVect);
SetInsertPosition(m_cursorPos+tmpVect.Size(), true);
} else {
m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, tmpVect);
SetInsertPosition(SelectionStart+tmpVect.Size(), true);
}
actionDone = true;
} else if (UTF8data[0] == 0x7F ) {
//EDN_INFO("keyEvent : <Suppr> pos=" << m_cursorPos);
if (false == haveSelectionActive) {
m_EdnBuf.Remove(m_cursorPos, m_cursorPos+1);
} else {
m_EdnBuf.RemoveSelected(SELECTION_PRIMARY);
SetInsertPosition(SelectionStart, true);
if (true == ewol::IsSetShift() ) {
m_cursorPos = m_EdnBuf.UnIndent(SELECTION_PRIMARY);
} else {
m_cursorPos = m_EdnBuf.Indent(SELECTION_PRIMARY);
}
}
actionDone = true;
} else if (UTF8data[0] == 0x08) {
//EDN_INFO("keyEvent : <Del> pos=" << m_cursorPos);
if (false == haveSelectionActive) {
m_EdnBuf.Remove(m_cursorPos-1, m_cursorPos);
SetInsertPosition(m_cursorPos-1, true);
} else {
m_EdnBuf.RemoveSelected(SELECTION_PRIMARY);
SetInsertPosition(SelectionStart, true);
}
actionDone = true;
}
}
if (false == actionDone) {
} else if (unicodeData == '\n') {
etk::VectorType<int8_t> tmpVect;
if (true == ewol::IsSetShift()) {
tmpVect.PushBack('\r');
} else {
tmpVect.PushBack('\n');
// if Auto indent Enable ==> we get the start of the previous line and add it to tne new one
if (true == globals::IsSetAutoIndent() ) {
int32_t l_lineStart;
// Get the begin of the line or the begin of the line befor selection
if (false == haveSelectionActive) {
l_lineStart = m_EdnBuf.StartOfLine(m_cursorPos);
} else {
l_lineStart = m_EdnBuf.StartOfLine(SelectionStart);
}
// add same characters in the temporar buffer
for (int32_t kk=l_lineStart; kk<m_cursorPos; kk++) {
if (' ' == m_EdnBuf[kk]) {
tmpVect.PushBack(' ');
} else if('\t' == m_EdnBuf[kk]) {
tmpVect.PushBack('\t');
} else {
break;
}
}
}
}
// Set temporary buffer in the real buffer
if (false == haveSelectionActive) {
m_EdnBuf.Insert(m_cursorPos, tmpVect);
SetInsertPosition(m_cursorPos+tmpVect.Size(), true);
} else {
m_EdnBuf.ReplaceSelected(SELECTION_PRIMARY, tmpVect);
SetInsertPosition(SelectionStart+tmpVect.Size(), true);
}
} else if (unicodeData == 0x7F ) {
//EDN_INFO("keyEvent : <Suppr> pos=" << m_cursorPos);
if (false == haveSelectionActive) {
m_EdnBuf.Remove(m_cursorPos, m_cursorPos+1);
} else {
m_EdnBuf.RemoveSelected(SELECTION_PRIMARY);
SetInsertPosition(SelectionStart, true);
}
} else if (unicodeData == 0x08) {
//EDN_INFO("keyEvent : <Del> pos=" << m_cursorPos);
if (false == haveSelectionActive) {
m_EdnBuf.Remove(m_cursorPos-1, m_cursorPos);
SetInsertPosition(m_cursorPos-1, true);
} else {
m_EdnBuf.RemoveSelected(SELECTION_PRIMARY);
SetInsertPosition(SelectionStart, true);
}
} else {
// normal adding char ...
if (true == m_EdnBuf.GetUTF8Mode()) {
char tmpUTF8[16];
unicode::convertUnicodeToUtf8(unicodeData, tmpUTF8);
etk::VectorType<int8_t> tmpVect;
int32_t localOfset = strlen(UTF8data);
tmpVect.PushBack((int8_t*)UTF8data, localOfset);
int32_t localOfset = strlen(tmpUTF8);
tmpVect.PushBack((int8_t*)tmpUTF8, localOfset);
if (false == haveSelectionActive) {
m_EdnBuf.Insert(m_cursorPos, tmpVect);
SetInsertPosition(m_cursorPos+localOfset, true);
@ -1141,7 +1134,7 @@ void BufferText::AddChar(char * UTF8data)
} else {
// convert in the Good ISO format :
char output_ISO;
convertUtf8ToIso(m_EdnBuf.GetCharsetType(), UTF8data, output_ISO);
unicode::convertUnicodeToIso(m_EdnBuf.GetCharsetType(), unicodeData, output_ISO);
//printf(" insert : \"%s\"==> 0x%08x=%d ", UTF8data, (unsigned int)output_ISO, (int)output_ISO);
etk::VectorType<int8_t> tmpVect;
tmpVect.PushBack(output_ISO);

View File

@ -54,7 +54,7 @@ class BufferText : public Buffer {
int32_t offsetX, int32_t offsetY,
int32_t sizeX, int32_t sizeY);
void ForceReDraw(bool allElement);
void AddChar(char * UTF8data);
void AddChar(uniChar_t unicodeData);
void cursorMove(ewol::eventKbMoveType_te moveTypeEvent);
void MouseSelectFromCursorTo(int32_t width, int32_t height);
void MouseEvent(int32_t width, int32_t height);

View File

@ -126,11 +126,11 @@ void CodeView::OnRegenerateDisplay(void)
}
bool CodeView::OnEventKb(ewol::eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE])
bool CodeView::OnEventKb(ewol::eventKbType_te typeEvent, uniChar_t unicodeData)
{
//EDN_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent);
if (typeEvent == ewol::EVENT_KB_TYPE_DOWN) {
m_bufferManager->Get(m_bufferID)->AddChar(UTF8_data);
m_bufferManager->Get(m_bufferID)->AddChar(unicodeData);
MarkToReedraw();
}
return true;

View File

@ -54,7 +54,7 @@ class CodeView :public ewol::WidgetScrooled
bool OnEventAreaExternal(int32_t widgetID, const char * generateEventId, const char * eventExternId, etkFloat_t x, etkFloat_t y);
public:
virtual bool OnEventInput(int32_t IdInput, ewol::eventInputType_te typeEvent, etkFloat_t x, etkFloat_t y);
virtual bool OnEventKb(ewol::eventKbType_te typeEvent, char UTF8_data[UTF8_MAX_SIZE]);
virtual bool OnEventKb(ewol::eventKbType_te typeEvent, uniChar_t unicodeData);
virtual bool OnEventKbMove(ewol::eventKbType_te typeEvent, ewol::eventKbMoveType_te moveTypeEvent);
virtual void OnGetFocus(void);
virtual void OnLostFocus(void);