2013-09-19 22:23:31 +02:00
|
|
|
/**
|
|
|
|
* @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>
|
2013-09-26 22:15:39 +02:00
|
|
|
#include <ewol/widget/Widget.h>
|
2013-10-09 22:00:24 +02:00
|
|
|
#include <ewol/compositing/Text.h>
|
2013-09-19 22:23:31 +02:00
|
|
|
|
2013-10-09 22:00:24 +02:00
|
|
|
namespace appl {
|
|
|
|
class Buffer : public ewol::EObject {
|
2013-09-19 22:23:31 +02:00
|
|
|
public:
|
2013-09-26 22:15:39 +02:00
|
|
|
Buffer(void);
|
2013-09-19 22:23:31 +02:00
|
|
|
~Buffer(void) { };
|
|
|
|
private:
|
|
|
|
etk::UString m_fileName; //!< name of the file (with his path)
|
|
|
|
public:
|
|
|
|
/**
|
2013-10-07 22:04:21 +02:00
|
|
|
* @brief get the curent filename of the Buffer
|
2013-09-19 22:23:31 +02:00
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
const etk::UString& getFileName(void) {
|
|
|
|
return m_fileName;
|
|
|
|
}
|
2013-10-07 22:04:21 +02:00
|
|
|
bool loadFile(const etk::UString& _name);
|
|
|
|
void setFileName(const etk::UString& _name);
|
2013-09-19 22:23:31 +02:00
|
|
|
bool m_isModify; //!< true if the file is modify
|
|
|
|
etk::Buffer m_data; //!< copy of the file buffer
|
|
|
|
public:
|
2013-10-09 22:00:24 +02:00
|
|
|
etk::Buffer& getData(void) {
|
|
|
|
return m_data;
|
|
|
|
};
|
2013-09-19 22:23:31 +02:00
|
|
|
/*
|
|
|
|
appl::History m_history;
|
|
|
|
Highlight m_highlight;
|
|
|
|
ejson::Value* m_property;
|
|
|
|
appl::Selection m_selection;
|
|
|
|
*/
|
2013-09-26 22:15:39 +02:00
|
|
|
public:
|
|
|
|
esize_t m_cursorPos; //!< cursor position.
|
2013-09-30 00:08:52 +02:00
|
|
|
int32_t m_cursorPreferredCol; //!< position of the cursor when up and down is done.
|
2013-10-09 22:00:24 +02:00
|
|
|
// note : We need the text drawer interface due to the fact that the move depend on the text display properties.
|
|
|
|
bool onEventEntry(const ewol::EventEntry& _event, ewol::Text& _testDrawer);
|
2013-09-26 22:16:40 +02:00
|
|
|
/**
|
2013-10-07 22:04:21 +02:00
|
|
|
* @brief get the next element in the buffer.
|
2013-09-26 22:16:40 +02:00
|
|
|
* @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)
|
|
|
|
*/
|
2013-10-07 22:04:21 +02:00
|
|
|
esize_t get(esize_t _pos, etk::UniChar& _value, unicode::charset_te _charset = unicode::EDN_CHARSET_UTF8) const;
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
2013-10-07 22:04:21 +02:00
|
|
|
* @brief get the previous element in the buffer.
|
2013-09-27 23:02:30 +02:00
|
|
|
* @param[in] _pos Position in the buffer (last element of the element)
|
|
|
|
* @param[out] _value Unicode value read in the buffer
|
|
|
|
* @param[in] _charset Charset used to parse the current buffer
|
|
|
|
* @return number of element read in the buffer (to increment the position)
|
|
|
|
*/
|
2013-10-07 22:04:21 +02:00
|
|
|
esize_t getBack(esize_t _pos, etk::UniChar& _value, unicode::charset_te _charset = unicode::EDN_CHARSET_UTF8) const;
|
2013-09-30 00:08:52 +02:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
void expand(esize_t& _indent, const etk::UniChar& _value, etk::UString& _out) const;
|
2013-09-27 23:02:30 +02:00
|
|
|
private:
|
|
|
|
enum moveMode {
|
|
|
|
moveLetter,
|
|
|
|
moveWord,
|
|
|
|
moveEnd
|
2013-09-30 00:08:52 +02:00
|
|
|
};
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
|
|
|
* Move the cursor right in the line (no stop of a new line)
|
|
|
|
* @param[in] _mode Moving mode char, word, ...
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
void moveCursorRight(moveMode _mode = moveLetter);
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
|
|
|
* Move the cursor left in the line (no stop of a new line)
|
|
|
|
* @param[in] _mode Moving mode char, word, ...
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
void moveCursorLeft(moveMode _mode = moveLetter);
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
|
|
|
* @brief Move the cursor at an other position upper.
|
|
|
|
* @param[in] _nbLine number of up line that might be moved
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
void moveCursorUp(esize_t _nbLine);
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
|
|
|
* @brief Move the cursor at an other position under.
|
|
|
|
* @param[in] _nbLine number of down line that might be moved
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
void moveCursorDown(esize_t _nbLine);
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
2013-10-07 22:04:21 +02:00
|
|
|
* @brief get the start of a line with the position in the buffer.
|
2013-09-27 23:02:30 +02:00
|
|
|
* @param[in] _pos position in the buffer.
|
|
|
|
* @return The position in the buffer of the start of the line.
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
esize_t startLine(esize_t _pos);
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
2013-10-07 22:04:21 +02:00
|
|
|
* @brief get the end of a line with the position in the buffer.
|
2013-09-27 23:02:30 +02:00
|
|
|
* @param[in] _pos position in the buffer.
|
|
|
|
* @return The position in the buffer of the end of the line.
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
esize_t endLine(esize_t _pos);
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
|
|
|
* @brief Search a character in the buffer.
|
|
|
|
* @param[in] _pos Position to start the search of the element.
|
|
|
|
* @param[in] _search Character to search.
|
|
|
|
* @param[out] _result Research position.
|
|
|
|
* @return true if pos if fined.
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
bool search(esize_t _pos, const etk::UniChar& _search, esize_t& _result);
|
2013-09-27 23:02:30 +02:00
|
|
|
/**
|
|
|
|
* @brief Search a character in the buffer in back mode.
|
|
|
|
* @param[in] _pos Position to start the search of the element.
|
|
|
|
* @param[in] _search Character to search.
|
|
|
|
* @param[out] _result Research position.
|
|
|
|
* @return true if pos if fined.
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
bool searchBack(esize_t _pos, const etk::UniChar& _search, esize_t& _result);
|
2013-09-30 00:08:52 +02:00
|
|
|
/**
|
|
|
|
* @brief Count the number of displayed characters between buffer position
|
2013-10-07 22:04:21 +02:00
|
|
|
* displayed characters are the characters shown on the screen to represent characters in the
|
2013-09-30 00:08:52 +02:00
|
|
|
* buffer, where tabs and control characters are expanded
|
|
|
|
* @param[in] _posStart start position
|
|
|
|
* @param[in] _posEnd End position
|
|
|
|
* @return the ID in the buffer of the requested char
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
int32_t countDispChars(esize_t _posStart, esize_t _posEnd);
|
2013-09-30 00:08:52 +02:00
|
|
|
/**
|
|
|
|
* @brief Return the position of the nth diplaye char
|
|
|
|
* @param[in] _posStart Position of the start
|
|
|
|
* @param[in] _nChars search in the next nChars elements
|
|
|
|
* @return position of the char i the buffer
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
esize_t countForwardDispChars(esize_t _posStart, int32_t _nChars);
|
2013-09-30 00:08:52 +02:00
|
|
|
/**
|
2013-10-07 22:04:21 +02:00
|
|
|
* @brief find the first character of the line "nLines" forward
|
2013-09-30 00:08:52 +02:00
|
|
|
* @param[in,out] _startPos Start position.
|
|
|
|
* @param[in,out] _nLines Number of line to count.
|
|
|
|
* @return position of the starting the line.
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
esize_t countForwardNLines(esize_t _startPos, int32_t _nLines);
|
2013-09-30 00:08:52 +02:00
|
|
|
/**
|
2013-10-07 22:04:21 +02:00
|
|
|
* @brief find the first character of the line "nLines" backwards
|
2013-09-30 00:08:52 +02:00
|
|
|
* @param[in,out] _startPos Start position to count (this caracter is not counted)
|
2013-10-07 22:04:21 +02:00
|
|
|
* @param[in,out] _nLines Number of line to count (if == 0 means find the beginning of the line)
|
2013-09-30 00:08:52 +02:00
|
|
|
* @return position of the starting the line
|
|
|
|
*/
|
2013-10-09 22:00:24 +02:00
|
|
|
esize_t countBackwardNLines(esize_t _startPos, int32_t _nLines);
|
2013-09-27 23:02:30 +02:00
|
|
|
|
2013-09-19 22:23:31 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|