gtk_editor.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #include "lumacs/ui_interface.hpp"
  3. #include "lumacs/gtk_renderer.hpp"
  4. #include "lumacs/window.hpp"
  5. #include "lumacs/editor_core.hpp"
  6. #include "lumacs/face.hpp"
  7. #include <gtkmm.h>
  8. #include <pangomm.h>
  9. #include <memory>
  10. #include <vector>
  11. #include <map>
  12. // Forward declarations
  13. namespace lumacs {
  14. class EditorCore;
  15. class Window;
  16. }
  17. // Custom Gtk::ApplicationWindow to make constructor public
  18. class LumacsWindow : public Gtk::ApplicationWindow {
  19. public:
  20. explicit LumacsWindow(const Glib::RefPtr<Gtk::Application>& application);
  21. };
  22. namespace lumacs {
  23. class GtkEditor : public IEditorView {
  24. public:
  25. GtkEditor();
  26. ~GtkEditor() override;
  27. void init() override;
  28. void run() override;
  29. void handle_editor_event(EditorEvent event) override;
  30. void set_core(EditorCore* core) override;
  31. void queue_redraw_all_windows(Gtk::Widget* widget);
  32. private:
  33. EditorCore* core_;
  34. std::shared_ptr<Window> cached_active_window_;
  35. Glib::RefPtr<Gtk::Application> app_;
  36. Gtk::Window* window_ = nullptr;
  37. Gtk::DrawingArea* drawing_area_ = nullptr;
  38. Gtk::Widget* content_widget_ = nullptr;
  39. bool cursor_visible_ = true;
  40. sigc::connection cursor_timer_connection_;
  41. std::unique_ptr<GtkRenderer> gtk_renderer_;
  42. protected:
  43. void on_activate();
  44. void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
  45. bool on_cursor_blink();
  46. void rebuild_layout();
  47. Gtk::Widget* create_widget_for_layout_node(std::shared_ptr<LayoutNode> node);
  48. // Delegate these to GtkRenderer
  49. std::optional<Position> resolve_screen_pos(std::shared_ptr<Window> window, double x, double y);
  50. std::string resolve_key(guint keyval, Gdk::ModifierType state);
  51. bool on_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state);
  52. };
  53. std::unique_ptr<IEditorView> create_gtk_editor();
  54. } // namespace lumacs