[DEV] start rework buffer display

This commit is contained in:
Edouard DUPIN 2013-09-19 22:23:31 +02:00
parent b98ee05d2a
commit 40bf24a095
8 changed files with 489 additions and 110 deletions

View File

@ -0,0 +1,33 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#include <appl/Buffer/Buffer.h>
#include <appl/Debug.h>
bool appl::Buffer::LoadFile(const etk::UString& _name)
{
APPL_DEBUG("Load file : '" << _name << "'");
m_fileName = _name;
etk::FSNode file(m_fileName);
if (file.Exist() == false) {
return false;
}
if (true == m_data.DumpFrom(file) ) {
return true;
}
return false;
}
void appl::Buffer::SetFileName(const etk::UString& _name)
{
// TODO : ...
}

View File

@ -0,0 +1,49 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_BUFFER_H__
#define __APPL_BUFFER_H__
#include <etk/UString.h>
#include <etk/os/FSNode.h>
#include <etk/unicode.h>
#include <ewol/ewol.h>
#include <etk/Buffer.h>
#include <ewol/renderer/EObject.h>
namespace appl
{
class Buffer : public ewol::EObject
{
public:
Buffer(void) { };
~Buffer(void) { };
private:
etk::UString m_fileName; //!< name of the file (with his path)
public:
/**
* @brief Get the curent filename of the Buffer
*/
const etk::UString& GetFileName(void) { return m_fileName; }
bool LoadFile(const etk::UString& _name);
void SetFileName(const etk::UString& _name);
bool m_isModify; //!< true if the file is modify
etk::Buffer m_data; //!< copy of the file buffer
public:
etk::Buffer& GetData(void) { return m_data; };
/*
appl::History m_history;
Highlight m_highlight;
ejson::Value* m_property;
appl::Selection m_selection;
*/
};
};
#endif

View File

@ -49,12 +49,12 @@ typedef struct{
class BufferText class BufferText
{ {
private: private:
bool m_fileModify; //!< bool m_fileModify;
// naming // naming
etk::FSNode m_fileName; //!< filename of the curent buffer etk::FSNode m_fileName; //!< filename of the curent buffer
bool m_haveName; //!< to know if the file have a name or NOT bool m_haveName; //!< to know if the file have a name or NOT
bool m_updatePositionRequested; //!< if a position xhange in the windows ... bool m_updatePositionRequested; //!< if a position xhange in the windows ...
vec2 m_maximumSize; //!< current maxSize of the buffer vec2 m_maximumSize; //!< current maxSize of the buffer
public: public:
void SetModify(bool status); void SetModify(bool status);
virtual vec2 GetBorderSize(void); virtual vec2 GetBorderSize(void);
@ -64,10 +64,7 @@ class BufferText
vec2 GetMaxSize(void) { return m_maximumSize; }; vec2 GetMaxSize(void) { return m_maximumSize; };
bool IsModify(void); bool IsModify(void);
public: public:
etk::FSNode GetFileName(void) etk::FSNode GetFileName(void) { return m_fileName; };
{
return m_fileName;
};
void SetFileName(etk::FSNode &newName) void SetFileName(etk::FSNode &newName)
{ {

View File

@ -33,23 +33,21 @@ end *************** *************
*/ */
typedef struct { typedef struct {
bool selected; //!< True if the selection is active bool selected; //!< True if the selection is active
bool rectangular; //!< True if the selection is rectangular bool rectangular; //!< True if the selection is rectangular
bool zeroWidth; //!< Width 0 selections aren't "real" selections, but they can be useful when creating rectangular selections from the keyboard. bool zeroWidth; //!< Width 0 selections aren't "real" selections, but they can be useful when creating rectangular selections from the keyboard.
int32_t start; //!< Pos. of start of selection, or if rectangular start of line containing it. int32_t start; //!< Pos. of start of selection, or if rectangular start of line containing it.
int32_t end; //!< Pos. of end of selection, or if rectangular end of line containing it. int32_t end; //!< Pos. of end of selection, or if rectangular end of line containing it.
int32_t rectStart; //!< Indent of left edge of rect. selection int32_t rectStart; //!< Indent of left edge of rect. selection
int32_t rectEnd; //!< Indent of right edge of rect. selection int32_t rectEnd; //!< Indent of right edge of rect. selection
} selection; } selection;
typedef struct { typedef struct {
etk::Vector<colorInformation_ts> HLData; etk::Vector<colorInformation_ts> HLData;
int32_t posHLPass1; int32_t posHLPass1;
int32_t posHLPass2; int32_t posHLPass2;
}displayHLData_ts; }displayHLData_ts;
class EdnBuf { class EdnBuf {
// TODO : Set an iterator to acces at every data without knowin the system ... // TODO : Set an iterator to acces at every data without knowin the system ...
public: public:
@ -58,136 +56,132 @@ class EdnBuf {
// destructer // destructer
~EdnBuf(void); ~EdnBuf(void);
// public function : // public function :
void GetAll( etk::Vector<int8_t> &text); void GetAll(etk::Vector<int8_t>& _text);
void SetAll( etk::Vector<int8_t> &text); void SetAll(etk::Vector<int8_t>& _text);
void GetRange( int32_t start, int32_t end, etk::Vector<int8_t> &output); void GetRange(int32_t _start, int32_t _end, etk::Vector<int8_t>& _output);
void GetRange( int32_t start, int32_t end, etk::UString &output); void GetRange(int32_t _start, int32_t _end, etk::UString& _output);
bool DumpIn( etk::FSNode &file); bool DumpIn(etk::FSNode& _file);
bool DumpFrom( etk::FSNode &file); bool DumpFrom(etk::FSNode& _file);
// replace with operator [] ... // replace with operator [] ...
int8_t operator[] (int32_t) const; int8_t operator[] (int32_t) const;
int32_t Insert( int32_t pos, etk::Vector<int8_t> &insertText); int32_t Insert(int32_t _pos, etk::Vector<int8_t>& _insertText);
int32_t Insert( int32_t pos, etk::UString &insertText); int32_t Insert(int32_t _pos, etk::UString& _insertText);
int32_t Replace( int32_t start, int32_t end, etk::Vector<int8_t> &insertText); int32_t Replace(int32_t _start, int32_t _end, etk::Vector<int8_t>& _insertText);
int32_t Replace( int32_t start, int32_t end, etk::UString &insertText); int32_t Replace(int32_t _start, int32_t _end, etk::UString& _insertText);
void Remove( int32_t start, int32_t end); void Remove(int32_t _start, int32_t _end);
int32_t Indent( void); int32_t Indent(void);
int32_t UnIndent( void); int32_t UnIndent(void);
void GetLineText( int32_t pos, etk::Vector<int8_t> &text); void GetLineText(int32_t _pos, etk::Vector<int8_t>& _text);
int32_t StartOfLine( int32_t pos); int32_t StartOfLine(int32_t _pos);
int32_t EndOfLine( int32_t pos); int32_t EndOfLine(int32_t _pos);
int32_t GetExpandedChar( int32_t &pos, int32_t indent, uniChar_t outUnicode[MAX_EXP_CHAR_LEN], uint32_t &currentChar); int32_t GetExpandedChar(int32_t& _pos, int32_t _indent, uniChar_t _outUnicode[MAX_EXP_CHAR_LEN], uint32_t& _currentChar);
int32_t GetExpandedChar( int32_t &pos, int32_t indent, char outUTF8[MAX_EXP_CHAR_LEN], uint32_t &currentChar); int32_t GetExpandedChar(int32_t& _pos, int32_t _indent, char _outUTF8[MAX_EXP_CHAR_LEN], uint32_t& _currentChar);
int32_t ExpandCharacter( char c, int32_t indent, char outUTF8[MAX_EXP_CHAR_LEN]); // TODO : Remove int32_t ExpandCharacter(char _c, int32_t _indent, char _outUTF8[MAX_EXP_CHAR_LEN]); // TODO : Remove
int32_t CharWidth( char c, int32_t indent); // TODO : rework this int32_t CharWidth(char _c, int32_t _indent); // TODO : rework this
int32_t CountDispChars( int32_t lineStartPos, int32_t targetPos); int32_t CountDispChars(int32_t _lineStartPos, int32_t _targetPos);
int32_t CountForwardDispChars( int32_t lineStartPos, int32_t nChars); int32_t CountForwardDispChars(int32_t _lineStartPos, int32_t _nChars);
int32_t CountLines( int32_t startPos, int32_t endPos); int32_t CountLines(int32_t _startPos, int32_t _endPos);
int32_t CountLines( void); int32_t CountLines(void);
int32_t CountLines( etk::Vector<int8_t> &data); int32_t CountLines(etk::Vector<int8_t>& _data);
int32_t CountForwardNLines( int32_t startPos, int32_t nLines); int32_t CountForwardNLines(int32_t _startPos, int32_t _nLines);
int32_t CountBackwardNLines( int32_t startPos, int32_t nLines); int32_t CountBackwardNLines(int32_t _startPos, int32_t _nLines);
bool SearchForward( int32_t startPos, etk::UString &search, int32_t *foundPos, int32_t *foundPosEnd, bool caseSensitive = true); bool SearchForward(int32_t _startPos, etk::UString& _search, int32_t* _foundPos, int32_t* _foundPosEnd, bool _caseSensitive = true);
bool SearchBackward( int32_t startPos, etk::UString &search, int32_t *foundPos, int32_t *foundPosEnd, bool caseSensitive = true); bool SearchBackward(int32_t _startPos, etk::UString& _search, int32_t* _foundPos, int32_t* _foundPosEnd, bool _caseSensitive = true);
bool SearchForward( int32_t startPos, char searchChar, int32_t *foundPos); bool SearchForward(int32_t _startPos, char _searchChar, int32_t* _foundPos);
bool SearchBackward( int32_t startPos, char searchChar, int32_t *foundPos); bool SearchBackward(int32_t _startPos, char _searchChar, int32_t* _foundPos);
bool SelectAround( int32_t startPos, int32_t &beginPos, int32_t &endPos); bool SelectAround(int32_t _startPos, int32_t& _beginPos, int32_t& _endPos);
// Buffer Size system : // Buffer Size system :
int32_t Size(void) { return m_data.Size(); }; int32_t Size(void) { return m_data.Size(); };
int32_t NumberOfLines(void) { return m_nbLine; }; int32_t NumberOfLines(void) { return m_nbLine; };
// ----------------------------------------- // -----------------------------------------
// selection remember... // selection remember...
// ----------------------------------------- // -----------------------------------------
public: public:
bool SelectHasSelection(void); bool SelectHasSelection(void);
void Select( int32_t start, int32_t end); void Select(int32_t _start, int32_t _end);
void Unselect( void); void Unselect(void);
void RectSelect( int32_t start, int32_t end, int32_t rectStart, int32_t rectEnd); void RectSelect(int32_t _start, int32_t _end, int32_t _rectStart, int32_t _rectEnd);
bool GetSelectionPos( int32_t &start, int32_t &end, bool &isRect, int32_t &rectStart, int32_t &rectEnd); bool GetSelectionPos(int32_t& _start, int32_t& _end, bool& _isRect, int32_t& _rectStart, int32_t& _rectEnd);
void GetSelectionText( etk::Vector<int8_t> &text); void GetSelectionText(etk::Vector<int8_t>& _text);
void GetSelectionText( etk::UString &text); void GetSelectionText(etk::UString& _text);
void RemoveSelected( void); void RemoveSelected(void);
int32_t ReplaceSelected( etk::Vector<int8_t> &text); int32_t ReplaceSelected(etk::Vector<int8_t>& _text);
int32_t ReplaceSelected( etk::UString &text); int32_t ReplaceSelected(etk::UString& _text);
private: private:
// current selection of the buffer // current selection of the buffer
selection m_selectionList; //!< Selection area of the buffer selection m_selectionList; //!< Selection area of the buffer
void UpdateSelection( int32_t pos, int32_t nDeleted, int32_t nInserted); void UpdateSelection(int32_t _pos, int32_t _nDeleted, int32_t _nInserted);
// ----------------------------------------- // -----------------------------------------
// History section : // History section :
// ----------------------------------------- // -----------------------------------------
public: public:
int32_t Undo(void); int32_t Undo(void);
int32_t Redo(void); int32_t Redo(void);
private: private:
bool m_isUndoProcessing; bool m_isUndoProcessing;
bool m_isRedoProcessing; bool m_isRedoProcessing;
etk::Vector<EdnBufHistory*> m_historyUndo; etk::Vector<EdnBufHistory*> m_historyUndo;
etk::Vector<EdnBufHistory*> m_historyRedo; etk::Vector<EdnBufHistory*> m_historyRedo;
// ----------------------------------------- // -----------------------------------------
// hightlight section : // hightlight section :
// ----------------------------------------- // -----------------------------------------
private: private:
Highlight * m_Highlight; //!< internal link with the Highlight system Highlight * m_Highlight; //!< internal link with the Highlight system
etk::Vector<colorInformation_ts> m_HLDataPass1; //!< colorisation position in the current buffer pass 1 etk::Vector<colorInformation_ts> m_HLDataPass1; //!< colorisation position in the current buffer pass 1
void RegenerateHighLightAt(int32_t pos, int32_t nbDeleted, int32_t nbAdded); void RegenerateHighLightAt(int32_t _pos, int32_t _nbDeleted, int32_t _nbAdded);
void GenerateHighLightAt(int32_t pos, int32_t endPos, int32_t addinPos=0); void GenerateHighLightAt(int32_t _pos, int32_t _endPos, int32_t _addinPos=0);
void CleanHighLight(void); void CleanHighLight(void);
void FindMainHighLightPosition(int32_t startPos, int32_t endPos, int32_t &startId, int32_t &stopId, bool backPreviousNotEnded); void FindMainHighLightPosition(int32_t _startPos, int32_t _endPos, int32_t &_startId, int32_t &_stopId, bool _backPreviousNotEnded);
public: public:
void SetHLSystem( Highlight * newHLSystem); void SetHLSystem(Highlight* _newHLSystem);
void HightlightGenerateLines(displayHLData_ts & MData, int32_t startPos, int32_t nbLines); void HightlightGenerateLines(displayHLData_ts& _MData, int32_t _startPos, int32_t _nbLines);
colorInformation_ts * GetElementColorAtPosition(displayHLData_ts & MData, int32_t pos); colorInformation_ts* GetElementColorAtPosition(displayHLData_ts& _MData, int32_t _pos);
private: private:
colorInformation_ts * GetElementColorAtPosition(int32_t pos, int32_t &starPos); colorInformation_ts* GetElementColorAtPosition(int32_t _pos, int32_t &_starPos);
private: private:
etk::Buffer m_data; //!< buffer of the data in the mode int8_t etk::Buffer m_data; //!< buffer of the data in the mode int8_t
void CountNumberOfLines(void); void CountNumberOfLines(void);
int32_t m_nbLine; //!< Number of line in the biffer int32_t m_nbLine; //!< Number of line in the biffer
// ----------------------------------------- // -----------------------------------------
// Display property and charset ... // Display property and charset ...
// ----------------------------------------- // -----------------------------------------
public: public:
int32_t GetTabDistance(void) { return m_tabDist; } ; int32_t GetTabDistance(void) { return m_tabDist; } ;
void SetTabDistance(int32_t tabDist) { m_tabDist = tabDist; }; void SetTabDistance(int32_t _tabDist) { m_tabDist = _tabDist; };
unicode::charset_te GetCharsetType(void) { return m_charsetType; }; unicode::charset_te GetCharsetType(void) { return m_charsetType; };
void SetCharsetType(unicode::charset_te newOne) { m_charsetType = newOne; if (unicode::EDN_CHARSET_UTF8==newOne){m_isUtf8=true;} else {m_isUtf8=false;} }; void SetCharsetType(unicode::charset_te _newOne) { m_charsetType = _newOne; if (unicode::EDN_CHARSET_UTF8==_newOne){m_isUtf8=true;} else {m_isUtf8=false;} };
bool GetUTF8Mode(void) { return m_isUtf8; }; bool GetUTF8Mode(void) { return m_isUtf8; };
void SetUTF8Mode(bool newOne) { m_isUtf8 = newOne; m_charsetType=unicode::EDN_CHARSET_UTF8; }; void SetUTF8Mode(bool _newOne) { m_isUtf8 = _newOne; m_charsetType=unicode::EDN_CHARSET_UTF8; };
private: private:
// Special mode of the buffer : // Special mode of the buffer :
bool m_isUtf8; //!< true if we are in UTF8 mode ==> if true the size of a char is 0, otherwise .. 1->4 ( TODO : not now) bool m_isUtf8; //!< true if we are in UTF8 mode ==> if true the size of a char is 0, otherwise .. 1->4 ( TODO : not now)
unicode::charset_te m_charsetType; //!< if UTF8 mode is at false : the charset type of the buffer unicode::charset_te m_charsetType; //!< if UTF8 mode is at false : the charset type of the buffer
// Local Tabulation policies // Local Tabulation policies
int32_t m_tabDist; //!< equiv. number of characters in a tab int32_t m_tabDist; //!< equiv. number of characters in a tab
bool m_useTabs; //!< True if buffer routines are allowed to use tabs for padding in rectangular operations bool m_useTabs; //!< True if buffer routines are allowed to use tabs for padding in rectangular operations
// ----------------------------------------- // -----------------------------------------
// Local function : // Local function :
// ----------------------------------------- // -----------------------------------------
private: private:
void findRectSelBoundariesForCopy( int32_t lineStartPos, int32_t rectStart, int32_t rectEnd, int32_t *selStart, int32_t *selEnd); void findRectSelBoundariesForCopy(int32_t _lineStartPos, int32_t _rectStart, int32_t _rectEnd, int32_t *_selStart, int32_t *_selEnd);
char * getSelectionText( selection &sel); char* getSelectionText(selection& _sel);
void removeSelected( selection &sel); void removeSelected(selection& _sel);
void replaceSelected( selection &sel, const char *text); void replaceSelected(selection& _sel, const char* _text);
void eventModification(int32_t _pos, int32_t _nInserted, etk::Vector<int8_t>& _deletedText);
void eventModification( int32_t pos, int32_t nInserted, etk::Vector<int8_t> &deletedText); int32_t LocalInsert(int32_t _pos, etk::Vector<int8_t> &_insertText);
int32_t LocalInsert(int32_t _pos, etk::UString &_insertText);
bool charMatch(char _first, char _second, bool _caseSensitive = true);
int32_t LocalInsert( int32_t pos, etk::Vector<int8_t> &insertText);
int32_t LocalInsert( int32_t pos, etk::UString &insertText);
bool charMatch( char first, char second, bool caseSensitive = true);
}; };
#endif #endif

View File

@ -12,6 +12,7 @@
#include <MainWindows.h> #include <MainWindows.h>
#include <CodeView.h> #include <CodeView.h>
#include <BufferView.h> #include <BufferView.h>
#include <TextViewer.h>
#include <Search.h> #include <Search.h>
#include <ewol/widget/Button.h> #include <ewol/widget/Button.h>
@ -120,6 +121,7 @@ MainWindows::MainWindows(void)
widget::Sizer * mySizerHori = NULL; widget::Sizer * mySizerHori = NULL;
//ewol::Button * myButton = NULL; //ewol::Button * myButton = NULL;
CodeView * myCodeView = NULL; CodeView * myCodeView = NULL;
appl::TextViewer * myTextView = NULL;
BufferView * myBufferView = NULL; BufferView * myBufferView = NULL;
widget::Menu * myMenu = NULL; widget::Menu * myMenu = NULL;
@ -137,11 +139,16 @@ MainWindows::MainWindows(void)
mySizerHori->SubWidgetAdd(mySizerVert2); mySizerHori->SubWidgetAdd(mySizerVert2);
// main buffer Area : // main buffer Area :
myTextView = new appl::TextViewer("FreeMono;DejaVuSansMono", 11);
myTextView->SetExpand(bvec2(true,true));
myTextView->SetFill(bvec2(true,true));
mySizerVert2->SubWidgetAdd(myTextView);
/*
myCodeView = new CodeView("FreeMono;DejaVuSansMono", 11); myCodeView = new CodeView("FreeMono;DejaVuSansMono", 11);
myCodeView->SetExpand(bvec2(true,true)); myCodeView->SetExpand(bvec2(true,true));
myCodeView->SetFill(bvec2(true,true)); myCodeView->SetFill(bvec2(true,true));
mySizerVert2->SubWidgetAdd(myCodeView); mySizerVert2->SubWidgetAdd(myCodeView);
*/
// search area : // search area :
Search * mySearch = new Search(); Search * mySearch = new Search();
mySizerVert2->SubWidgetAdd(mySearch); mySizerVert2->SubWidgetAdd(mySearch);

View File

@ -0,0 +1,243 @@
/**
* @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),
m_displayText(_fontName, _fontSize)
{
SetCanHaveFocus(true);
RegisterMultiCast(ednMsgBufferId);
RegisterMultiCast(ednMsgGuiCopy);
RegisterMultiCast(ednMsgGuiPaste);
RegisterMultiCast(ednMsgGuiCut);
RegisterMultiCast(ednMsgGuiRedo);
RegisterMultiCast(ednMsgGuiUndo);
RegisterMultiCast(ednMsgGuiRm);
RegisterMultiCast(ednMsgGuiSelect);
RegisterMultiCast(ednMsgGuiChangeCharset);
RegisterMultiCast(ednMsgGuiFind);
RegisterMultiCast(ednMsgGuiReplace);
RegisterMultiCast(ednMsgGuiGotoLine);
SetLimitScrolling(0.2);
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;
}
m_buffer->LoadFile("./example.txt");
}
appl::TextViewer::~TextViewer(void)
{
}
bool appl::TextViewer::CalculateMinSize(void)
{
m_minSize.setValue(50,50);
return true;
}
void appl::TextViewer::CalculateMaxSize(void)
{
m_maxSize.setX(256);
m_maxSize.setY(256);
}
void appl::TextViewer::OnDraw(void)
{
m_displayDrawing.Draw();
m_displayText.Draw();
WidgetScrooled::OnDraw();
}
esize_t appl::TextViewer::Get(esize_t _pos, UniChar& _value, 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';
// transform ...
}
// TODO :: need to trancode iso ==> UNICODE ...
_value = m_buffer[_pos];
return _pos+1;
}
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("<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");
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<buf.Size(); ++iii) {
char c = buf.Get(iii);
etk::UniChar myChar(c);
if (myChar == etk::UniChar('\n')) {
countNbLine += 1;
countColomn = 0;
continue;
}
countColomn += 1;
m_displayText.SetPos(vec3(countColomn*tmpLetterSize.x(),
m_size.y() - countNbLine*tmpLetterSize.y(),
0.0f) );
m_displayText.Print(myChar);
//tmpLetterSize.x();
}
}
// 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();
}
return true;
}
// move events ...
if (_event.GetStatus() == ewol::keyEvent::statusDown) {
if (m_buffer != NULL) {
//tmpBuffer->cursorMove(_event.GetType());
}
MarkToRedraw();
}
return true;
}
void appl::TextViewer::OnEventClipboard(ewol::clipBoard::clipboardListe_te _clipboardID)
{
if (m_buffer != NULL) {
//tmpBuffer->Paste(_clipboardID);
}
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
MarkToRedraw();
}
void appl::TextViewer::OnGetFocus(void)
{
ShowKeyboard();
APPL_INFO("Focus - In");
}
void appl::TextViewer::OnLostFocus(void)
{
HideKeyboard();
APPL_INFO("Focus - out");
}
void appl::TextViewer::SetFontSize(int32_t _size)
{
m_displayText.SetFontSize(_size);
SetScrollingSize(_size*3.0*1.46); // 1.46 is a magic number ...
}
void appl::TextViewer::SetFontName(const etk::UString& _fontName)
{
m_displayText.SetFontName(_fontName);
}

View File

@ -0,0 +1,54 @@
/**
* @author Edouard DUPIN
*
* @copyright 2010, Edouard DUPIN, all right reserved
*
* @license GPL v3 (see license file)
*/
#ifndef __APPL_TEXT_VIEWER_H__
#define __APPL_TEXT_VIEWER_H__
#include <appl/Debug.h>
#include <CodeView.h>
#include <appl/Buffer/Buffer.h>
#include <appl/globalMsg.h>
#include <ewol/widget/WidgetScrolled.h>
#include <ewol/compositing/Text.h>
#include <ewol/compositing/Drawing.h>
namespace appl
{
class TextViewer : public widget::WidgetScrooled
{
public:
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;
public:
void SetFontSize(int32_t _size);
void SetFontName(const etk::UString& _fontName);
private:
void CalculateMaxSize(void);
protected: // derived function
virtual void OnDraw(void);
public: // Derived function
const char * const GetObjectType(void) { return "ApplCodeView"; };
virtual bool CalculateMinSize(void);
virtual void OnRegenerateDisplay(void);
virtual void OnReceiveMessage(const ewol::EMessage& _msg);
virtual bool OnEventInput(const ewol::EventInput& _event);
virtual bool OnEventEntry(const ewol::EventEntry& _event);
virtual void OnEventClipboard(ewol::clipBoard::clipboardListe_te clipboardID);
virtual void OnGetFocus(void);
virtual void OnLostFocus(void);
};
};
#endif

View File

@ -21,6 +21,7 @@ def Create(target):
myModule.AddSrcFile([ myModule.AddSrcFile([
'appl/Gui/BufferView.cpp', 'appl/Gui/BufferView.cpp',
'appl/Gui/CodeView.cpp', 'appl/Gui/CodeView.cpp',
'appl/Gui/TextViewer.cpp',
'appl/Gui/MainWindows.cpp', 'appl/Gui/MainWindows.cpp',
'appl/Gui/Search.cpp', 'appl/Gui/Search.cpp',
'appl/Gui/SearchData.cpp', 'appl/Gui/SearchData.cpp',
@ -29,6 +30,7 @@ def Create(target):
# All needed for the buffer management : # All needed for the buffer management :
myModule.AddSrcFile([ myModule.AddSrcFile([
'appl/Buffer/Buffer.cpp',
'appl/Buffer/EdnBuf/EdnBuf.cpp', 'appl/Buffer/EdnBuf/EdnBuf.cpp',
'appl/Buffer/EdnBuf/EdnBuf_HighLight.cpp', 'appl/Buffer/EdnBuf/EdnBuf_HighLight.cpp',
'appl/Buffer/EdnBuf/EdnBuf_History.cpp', 'appl/Buffer/EdnBuf/EdnBuf_History.cpp',