window.hh (2472B)
1 #ifndef window_hh_INCLUDED 2 #define window_hh_INCLUDED 3 4 #include "display_buffer.hh" 5 #include "highlighter_group.hh" 6 #include "option.hh" 7 #include "optional.hh" 8 #include "safe_ptr.hh" 9 #include "selection.hh" 10 #include "scope.hh" 11 12 namespace Kakoune 13 { 14 15 enum class Hook; 16 class Client; 17 18 // A Window is a view onto a Buffer 19 class Window final : public SafeCountable, public Scope, private OptionWatcher 20 { 21 public: 22 Window(Buffer& buffer); 23 ~Window(); 24 25 const DisplayCoord& position() const { return m_position; } 26 void set_position(DisplayCoord position); 27 28 const DisplayCoord& dimensions() const { return m_dimensions; } 29 void set_dimensions(DisplayCoord dimensions); 30 31 void scroll(LineCount offset); 32 void center_line(LineCount buffer_line); 33 void display_line_at(LineCount buffer_line, LineCount display_line); 34 35 void scroll(ColumnCount offset); 36 void center_column(ColumnCount buffer_column); 37 void display_column_at(ColumnCount buffer_column, ColumnCount display_column); 38 39 const DisplayBuffer& update_display_buffer(const Context& context); 40 41 Optional<DisplayCoord> display_coord(BufferCoord coord) const; 42 Optional<BufferCoord> buffer_coord(DisplayCoord coord) const; 43 44 Buffer& buffer() const { return *m_buffer; } 45 46 bool needs_redraw(const Context& context) const; 47 48 void set_client(Client* client); 49 50 void clear_display_buffer(); 51 void run_resize_hook_ifn(); 52 53 const DisplaySetup& last_display_setup() const { return m_last_display_setup; } 54 55 private: 56 Window(const Window&) = delete; 57 58 DisplaySetup compute_display_setup(const Context& context) const; 59 void on_option_changed(const Option& option) override; 60 61 friend class ClientManager; 62 void run_hook_in_own_context(Hook hook, StringView param, 63 String client_name = ""); 64 65 SafePtr<Buffer> m_buffer; 66 SafePtr<Client> m_client; 67 68 DisplayCoord m_position; 69 DisplayCoord m_dimensions; 70 DisplayBuffer m_display_buffer; 71 72 Highlighters m_builtin_highlighters; 73 bool m_resize_hook_pending = false; 74 DisplaySetup m_last_display_setup; 75 76 struct Setup 77 { 78 DisplayCoord position; 79 DisplayCoord dimensions; 80 size_t timestamp; 81 size_t faces_hash; 82 size_t main_selection; 83 Vector<BasicSelection, MemoryDomain::Display> selections; 84 }; 85 Setup build_setup(const Context& context) const; 86 Setup m_last_setup; 87 }; 88 89 } 90 91 #endif // window_hh_INCLUDED