2011-09-02 20:51:20 +04:00
|
|
|
#ifndef window_hh_INCLUDED
|
|
|
|
#define window_hh_INCLUDED
|
|
|
|
|
|
|
|
#include <functional>
|
2011-09-05 23:06:31 +04:00
|
|
|
|
2011-09-17 18:13:33 +04:00
|
|
|
#include "line_and_column.hh"
|
2011-09-05 23:06:31 +04:00
|
|
|
|
2011-09-02 20:51:20 +04:00
|
|
|
#include "buffer.hh"
|
|
|
|
#include "display_buffer.hh"
|
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2011-09-17 18:13:33 +04:00
|
|
|
struct WindowCoord : LineAndColumn<WindowCoord>
|
2011-09-05 23:06:31 +04:00
|
|
|
{
|
|
|
|
WindowCoord(int line = 0, int column = 0)
|
|
|
|
: LineAndColumn(line, column) {}
|
|
|
|
};
|
|
|
|
|
2011-09-02 20:51:20 +04:00
|
|
|
struct Selection
|
|
|
|
{
|
|
|
|
Selection(const BufferIterator& begin, const BufferIterator& end)
|
2011-09-17 18:57:35 +04:00
|
|
|
: m_begin(begin), m_end(end) {}
|
|
|
|
|
|
|
|
const BufferIterator& begin() const { return m_begin; }
|
|
|
|
const BufferIterator& end() const { return m_end; }
|
|
|
|
|
|
|
|
void canonicalize()
|
|
|
|
{
|
|
|
|
if (m_end < m_begin)
|
|
|
|
std::swap(m_begin, m_end);
|
|
|
|
}
|
|
|
|
|
|
|
|
void offset(int offset)
|
|
|
|
{
|
|
|
|
m_begin += offset;
|
|
|
|
m_end += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BufferIterator m_begin;
|
|
|
|
BufferIterator m_end;
|
2011-09-02 20:51:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<Selection> SelectionList;
|
|
|
|
|
|
|
|
class Window
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef BufferString String;
|
|
|
|
typedef std::function<Selection (const BufferIterator&)> Selector;
|
|
|
|
|
|
|
|
void erase();
|
|
|
|
void insert(const String& string);
|
|
|
|
void append(const String& string);
|
|
|
|
|
2011-09-05 23:06:31 +04:00
|
|
|
const BufferCoord& position() const { return m_position; }
|
|
|
|
const WindowCoord& cursor_position() const { return m_cursor; }
|
2011-09-05 22:54:17 +04:00
|
|
|
|
2011-09-08 04:13:19 +04:00
|
|
|
Buffer& buffer() const { return m_buffer; }
|
2011-09-05 22:54:17 +04:00
|
|
|
|
2011-09-05 23:06:31 +04:00
|
|
|
BufferCoord window_to_buffer(const WindowCoord& window_pos) const;
|
|
|
|
WindowCoord buffer_to_window(const BufferCoord& buffer_pos) const;
|
|
|
|
|
|
|
|
BufferIterator iterator_at(const WindowCoord& window_pos) const;
|
|
|
|
WindowCoord line_and_column_at(const BufferIterator& iterator) const;
|
2011-09-02 20:51:20 +04:00
|
|
|
|
2011-09-05 23:06:31 +04:00
|
|
|
void move_cursor(const WindowCoord& offset);
|
2011-09-02 20:51:20 +04:00
|
|
|
|
|
|
|
const SelectionList& selections() const { return m_selections; }
|
|
|
|
|
2011-09-05 22:54:17 +04:00
|
|
|
void empty_selections();
|
|
|
|
void select(bool append, const Selector& selector);
|
|
|
|
|
2011-09-05 23:06:31 +04:00
|
|
|
void set_dimensions(const WindowCoord& dimensions);
|
2011-09-02 20:51:20 +04:00
|
|
|
|
|
|
|
const DisplayBuffer& display_buffer() const { return m_display_buffer; }
|
|
|
|
|
|
|
|
void update_display_buffer();
|
2011-09-05 22:54:17 +04:00
|
|
|
|
2011-09-06 22:52:52 +04:00
|
|
|
bool undo();
|
|
|
|
bool redo();
|
|
|
|
|
2011-09-02 20:51:20 +04:00
|
|
|
private:
|
2011-09-08 18:30:36 +04:00
|
|
|
friend class Buffer;
|
|
|
|
|
|
|
|
Window(Buffer& buffer);
|
|
|
|
Window(const Window&) = delete;
|
|
|
|
|
2011-09-05 22:55:31 +04:00
|
|
|
void scroll_to_keep_cursor_visible_ifn();
|
2011-09-02 20:51:20 +04:00
|
|
|
|
2011-09-08 04:13:19 +04:00
|
|
|
Buffer& m_buffer;
|
|
|
|
BufferCoord m_position;
|
|
|
|
WindowCoord m_cursor;
|
|
|
|
WindowCoord m_dimensions;
|
|
|
|
SelectionList m_selections;
|
|
|
|
DisplayBuffer m_display_buffer;
|
2011-09-02 20:51:20 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // window_hh_INCLUDED
|