gtk_editor.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 "lumacs/completion_common.hpp" // For CompletionCandidate
  8. #include <gtkmm.h>
  9. #include <pangomm.h>
  10. #include <memory>
  11. #include <vector>
  12. #include <map>
  13. namespace lumacs {
  14. // Forward declarations
  15. class EditorCore;
  16. class Window;
  17. class GtkCompletionPopup; // Forward declaration
  18. // Custom Gtk::ApplicationWindow to make constructor public
  19. class LumacsWindow : public Gtk::ApplicationWindow {
  20. public:
  21. explicit LumacsWindow(const Glib::RefPtr<Gtk::Application>& application);
  22. };
  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; // Raw pointer to the main drawing area if single window
  38. Gtk::Widget* content_widget_ = nullptr; // The root widget of the editor content (Paned or DrawingArea)
  39. bool cursor_visible_ = true;
  40. sigc::connection cursor_timer_connection_;
  41. std::unique_ptr<GtkRenderer> gtk_renderer_;
  42. std::unique_ptr<GtkCompletionPopup> completion_popup_; // Completion popup
  43. protected:
  44. void on_activate();
  45. void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
  46. bool on_cursor_blink();
  47. void rebuild_layout();
  48. Gtk::Widget* create_widget_for_layout_node(std::shared_ptr<LayoutNode> node);
  49. // Completion popup helpers
  50. void show_completion_popup();
  51. void hide_completion_popup();
  52. void on_completion_selected(CompletionCandidate candidate);
  53. void on_completion_cancelled();
  54. // Global key event handler
  55. std::string get_lumacs_key_name(guint keyval, Gdk::ModifierType state);
  56. bool on_global_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state);
  57. };
  58. std::unique_ptr<IEditorView> create_gtk_editor();
  59. } // namespace lumacs