diff --git a/sources/appl/Buffer/Buffer.cpp b/sources/appl/Buffer/Buffer.cpp index 34eb95c..9490735 100644 --- a/sources/appl/Buffer/Buffer.cpp +++ b/sources/appl/Buffer/Buffer.cpp @@ -10,6 +10,11 @@ #include #include +appl::Buffer::Buffer(void) : + m_cursorPos(3) +{ + +} bool appl::Buffer::LoadFile(const etk::UString& _name) { @@ -31,3 +36,39 @@ void appl::Buffer::SetFileName(const etk::UString& _name) // TODO : ... } +bool appl::Buffer::OnEventEntry(const ewol::EventEntry& _event) +{ + APPL_DEBUG(" event : " << _event); + if (_event.GetType() == ewol::keyEvent::keyboardChar) { + //APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent); + if (_event.GetStatus() != ewol::keyEvent::statusDown) { + return false; + } + if (_event.GetChar() == etk::UniChar::Tabulation) { + m_data.Insert(m_cursorPos, '\t'); + } else if (_event.GetChar() == etk::UniChar::Return) { + m_data.Insert(m_cursorPos, '\n'); + } else if (_event.GetChar() == etk::UniChar::Backspace ) { + APPL_INFO("keyEvent : pos=" << m_cursorPos); + } else if (_event.GetChar() == etk::UniChar::Delete) { + APPL_INFO("keyEvent : pos=" << m_cursorPos); + } else { + // normal adding char ... + char output[5]; + int32_t nbElement = _event.GetChar().GetUtf8(output); + etk::Vector values; + for (int32_t iii=0; iiiCursorMove(_event.GetType()); + + return true; + } + return false; +} diff --git a/sources/appl/Buffer/Buffer.h b/sources/appl/Buffer/Buffer.h index c15bae7..c41b759 100644 --- a/sources/appl/Buffer/Buffer.h +++ b/sources/appl/Buffer/Buffer.h @@ -15,13 +15,14 @@ #include #include #include +#include namespace appl { class Buffer : public ewol::EObject { public: - Buffer(void) { }; + Buffer(void); ~Buffer(void) { }; private: etk::UString m_fileName; //!< name of the file (with his path) @@ -42,6 +43,9 @@ namespace appl ejson::Value* m_property; appl::Selection m_selection; */ + public: + esize_t m_cursorPos; //!< cursor position. + bool OnEventEntry(const ewol::EventEntry& _event); }; }; diff --git a/sources/appl/Gui/TextViewer.cpp b/sources/appl/Gui/TextViewer.cpp index dcf236b..1f84c3b 100644 --- a/sources/appl/Gui/TextViewer.cpp +++ b/sources/appl/Gui/TextViewer.cpp @@ -24,7 +24,8 @@ appl::TextViewer::TextViewer(const etk::UString& _fontName, int32_t _fontSize) : m_buffer(NULL), - m_displayText(_fontName, _fontSize) + m_displayText(_fontName, _fontSize), + m_insertMode(false) { SetCanHaveFocus(true); RegisterMultiCast(ednMsgBufferId); @@ -87,109 +88,193 @@ void appl::TextViewer::OnDraw(void) } -esize_t appl::TextViewer::Get(esize_t _pos, UniChar& _value, charset_te _charset) const +esize_t appl::TextViewer::Get(esize_t _pos, etk::UniChar& _value, unicode::charset_te _charset) const { _value = '\0'; if (_charset == unicode::EDN_CHARSET_UTF8) { - char tmpVal[8]; - tmpVal[0] = m_buffer[_pos]; - tmpVal[1] = m_buffer[_pos+1]; - tmpVal[2] = m_buffer[_pos+2]; - tmpVal[3] = m_buffer[_pos+3]; - tmpVal[4] = m_buffer[_pos+4]; - tmpVal[5] = m_buffer[_pos+5]; - tmpVal[6] = m_buffer[_pos+6]; - tmpVal[7] = '\0'; + char tmpVal[5]; + tmpVal[0] = m_buffer->GetData()[_pos]; + tmpVal[1] = m_buffer->GetData()[_pos+1]; + tmpVal[2] = m_buffer->GetData()[_pos+2]; + tmpVal[3] = m_buffer->GetData()[_pos+3]; + tmpVal[4] = '\0'; // transform ... - + int32_t nbElement = _value.SetUtf8(tmpVal); + return nbElement; } // TODO :: need to trancode iso ==> UNICODE ... - _value = m_buffer[_pos]; - return _pos+1; + _value.Set(m_buffer->GetData()[_pos]); + return 1; } +static const char *ControlCodeTable[32] = { + "NUL", "soh", "stx", "etx", "eot", "enq", "ack", "bel", "bs", "ht", "nl", "vt", "np", "cr", "so", "si", + "dle", "dc1", "dc2", "dc3", "dc4", "nak", "syn", "etb", "can", "em", "sub", "esc", "fs", "gs", "rs", "us"}; + +void appl::TextViewer::Expand(esize_t& _indent, const etk::UniChar& _value, etk::UString& _out) const +{ + _out.Clear(); + int32_t tabDist = 4; + if (_value == etk::UniChar::Tabulation) { + int32_t nSpaces = tabDist - (_indent % tabDist); + for (int32_t iii=0; iii')); + return; + } + if (_value == etk::UniChar::Return) { + // nothing to display... + return; + } + if (_value.Get() <= 31) { + _out.Append(etk::UniChar('<')); + const char * tmp = ControlCodeTable[_value.Get()]; + while (*tmp!='\0') { + _out.Append(etk::UniChar(*tmp)); + tmp++; + } + _out.Append(etk::UniChar('>')); + return; + } + if (_value == etk::UniChar::Delete) { + _out.Append(etk::UniChar('<')); + _out.Append(etk::UniChar('d')); + _out.Append(etk::UniChar('e')); + _out.Append(etk::UniChar('l')); + _out.Append(etk::UniChar('>')); + return; + } + // nothing to do ... + _out.Append(_value); + //APPL_DEBUG("plop : " << _out); +} + + void appl::TextViewer::OnRegenerateDisplay(void) { - if (true == NeedRedraw()) { - // For the scrooling windows - CalculateMaxSize(); - m_displayDrawing.Clear(); - m_displayText.Clear(); - - // Reset the background : - m_displayDrawing.SetPos(vec3(0, 0, 0)); - m_displayDrawing.SetColor(etk::Color<>(220, 220, 220, 256)); - m_displayDrawing.RectangleWidth(m_size); - - if (m_buffer == NULL) { - m_displayText.SetTextAlignement(10, m_size.x()-20, ewol::Text::alignLeft); - m_displayText.SetRelPos(vec3(10, 0, 0)); - etk::UString tmpString("
\n" - "\n" - " \n" - " edn - Editeur De N'ours\n" - " \n" - "\n" - "
\n" - "
\n" - "\n" - " \n" - " No Buffer Availlable to display\n" - " \n" - "\n"); - m_displayText.SetPos(vec3(0.0f, m_size.y(), 0.0f) ); - m_displayText.ForceLineReturn(); - m_displayText.PrintDecorated(tmpString); - } else { - // real display ... - etk::Buffer& buf = m_buffer->GetData(); - m_displayText.SetColor(etk::Color<>(0, 0, 0, 256)); - float countNbLine = 1; - float countColomn = 0; - vec3 tmpLetterSize = m_displayText.CalculateSize((uniChar_t)'A'); - - for (int32_t iii=0; iii(220, 220, 220, 256)); + m_displayDrawing.RectangleWidth(m_size); + + if (m_buffer == NULL) { + m_displayText.SetTextAlignement(10, m_size.x()-20, ewol::Text::alignLeft); + m_displayText.SetRelPos(vec3(10, 0, 0)); + etk::UString tmpString("
\n" + "\n" + " \n" + " edn - Editeur De N'ours\n" + " \n" + "\n" + "
\n" + "
\n" + "\n" + " \n" + " No Buffer Availlable to display\n" + " \n" + "\n"); + m_displayText.SetPos(vec3(0.0f, m_size.y(), 0.0f) ); + m_displayText.ForceLineReturn(); + m_displayText.PrintDecorated(tmpString); // call the herited class... WidgetScrooled::OnRegenerateDisplay(); + return; } + // normal displa of the buffer : + vec3 tmpCursorPosition(0, 0, -1); + // real display ... + etk::Buffer& buf = m_buffer->GetData(); + m_displayText.SetColor(etk::Color<>(0, 0, 0, 256)); + float countNbLine = 1; + esize_t countColomn = 0; + vec3 tmpLetterSize = m_displayText.CalculateSize((uniChar_t)'A'); + vec3 positionCurentDisplay(0.0f, m_size.y()-tmpLetterSize.y(), 0.0f); + m_displayText.SetPos(positionCurentDisplay); + // the siplay string : + etk::UString stringToDisplay; + esize_t bufferElementSize = 0; + etk::UniChar currentValue; + for (int32_t iii=0; iiim_cursorPos) { + // need to display the cursor : + tmpCursorPosition = positionCurentDisplay; + } + bufferElementSize = Get(iii, currentValue, unicode::EDN_CHARSET_UTF8); + //APPL_DEBUG(" element size : " << iii << " : " << bufferElementSize); + if (currentValue == etk::UniChar::Return) { + countNbLine += 1; + countColomn = 0; + if (bufferElementSize ==0) { + bufferElementSize = 1; + } + positionCurentDisplay.setX(0); + positionCurentDisplay.setY(positionCurentDisplay.y()-tmpLetterSize.y()); + m_displayText.SetPos(positionCurentDisplay); + continue; + } + appl::TextViewer::Expand(countColomn, currentValue, stringToDisplay); + //m_displayText.SetPos(positionCurentDisplay); + for (esize_t kkk=0; kkk(0xFF0000FF)); + m_displayText.SetColorBg(etk::Color<>(0xFF0000FF)); + m_displayText.PrintCursor(m_insertMode); + } + // call the herited class... + WidgetScrooled::OnRegenerateDisplay(); } bool appl::TextViewer::OnEventEntry(const ewol::EventEntry& _event) { - if (_event.GetType() == ewol::keyEvent::keyboardChar) { - //APPL_DEBUG("KB EVENT : \"" << UTF8_data << "\" size=" << strlen(UTF8_data) << "type=" << (int32_t)typeEvent); - if (_event.GetStatus() == ewol::keyEvent::statusDown) { - if (m_buffer != NULL) { - //tmpBuffer->AddChar(_event.GetChar()); - } - MarkToRedraw(); - } + if (m_buffer == NULL) { + return false; + } + if (m_buffer->OnEventEntry(_event) == true) { + MarkToRedraw(); return true; } - // move events ... - if (_event.GetStatus() == ewol::keyEvent::statusDown) { - if (m_buffer != NULL) { - //tmpBuffer->cursorMove(_event.GetType()); - } - MarkToRedraw(); + return false; +} + + +bool appl::TextViewer::OnEventInput(const ewol::EventInput& _event) +{ + vec2 relativePos = RelativePosition(_event.GetPos()); + if (m_buffer != NULL) { + } + GetFocus(); return true; } @@ -201,15 +286,6 @@ void appl::TextViewer::OnEventClipboard(ewol::clipBoard::clipboardListe_te _clip MarkToRedraw(); } -bool appl::TextViewer::OnEventInput(const ewol::EventInput& _event) -{ - vec2 relativePos = RelativePosition(_event.GetPos()); - if (m_buffer != NULL) { - - } - return true; -} - void appl::TextViewer::OnReceiveMessage(const ewol::EMessage& _msg) { // Force redraw of the widget diff --git a/sources/appl/Gui/TextViewer.h b/sources/appl/Gui/TextViewer.h index 9e5739d..e362032 100644 --- a/sources/appl/Gui/TextViewer.h +++ b/sources/appl/Gui/TextViewer.h @@ -26,10 +26,9 @@ namespace appl TextViewer(const etk::UString& _fontName="", int32_t _fontSize=-1); virtual ~TextViewer(void); private: - appl::Buffer* m_buffer; - // drawing elements : - ewol::Text m_displayText; - ewol::Drawing m_displayDrawing; + appl::Buffer* m_buffer; //!< pointer on the current buffer to display (can be null if the buffer is remover or in state of changing buffer) + ewol::Text m_displayText; //!< Text display properties. + ewol::Drawing m_displayDrawing; //!< Other diaplay requested. public: void SetFontSize(int32_t _size); void SetFontName(const etk::UString& _fontName); @@ -47,6 +46,24 @@ namespace appl virtual void OnEventClipboard(ewol::clipBoard::clipboardListe_te clipboardID); virtual void OnGetFocus(void); virtual void OnLostFocus(void); + private: + /** + * @brief Get the next element in the buffer. + * @param[in] _pos Position in the buffer + * @param[out] _value Unicode value read in the buffer + * @param[in] _charset Charset used to parse the current buffer + * @return number ofelement read in the buffer (to increment the position) + */ + esize_t Get(esize_t _pos, etk::UniChar& _value, unicode::charset_te _charset) const; + /** + * @brief Expand the specify char to have a user frendly display for special char and tabs + * @param[in] _indent Curent indentation in the line + * @param[in] _value Current value to transform + * @param[out] _out String that represent the curent value to display + */ + void Expand(esize_t& _indent, const etk::UniChar& _value, etk::UString& _out) const; + private: + bool m_insertMode; //!< the insert mode is enable }; };