gtk_editor.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "lumacs/cursor_blink.hpp"
  9. #include <chrono> // For std::chrono
  10. #include <gtkmm.h>
  11. #include <pangomm.h>
  12. #include <memory>
  13. #include <vector>
  14. #include <map>
  15. namespace lumacs {
  16. // Forward declarations
  17. class EditorCore;
  18. class Window;
  19. class GtkCompletionPopup; // Forward declaration
  20. class ModeActivator; // Forward declaration
  21. // Custom Gtk::ApplicationWindow to make constructor public
  22. class LumacsWindow : public Gtk::ApplicationWindow {
  23. public:
  24. explicit LumacsWindow(const Glib::RefPtr<Gtk::Application>& application);
  25. };
  26. class GtkEditor : public IEditorView {
  27. public:
  28. GtkEditor();
  29. ~GtkEditor() override;
  30. void init() override;
  31. void run() override;
  32. void handle_editor_event(EditorEvent event) override;
  33. void set_core(EditorCore* core) override;
  34. void queue_redraw_all_windows(Gtk::Widget* widget);
  35. private:
  36. EditorCore* core_;
  37. std::shared_ptr<Window> cached_active_window_;
  38. Glib::RefPtr<Gtk::Application> app_;
  39. Gtk::Window* window_ = nullptr;
  40. Gtk::DrawingArea* drawing_area_ = nullptr; // Raw pointer to the main drawing area if single window
  41. Gtk::DrawingArea* minibuffer_drawing_area_ = nullptr; // Dedicated drawing area for minibuffer
  42. Gtk::Widget* content_widget_ = nullptr; // The root widget of the editor content (Paned or DrawingArea)
  43. // Cursor blinking using shared controller
  44. CursorBlinkController cursor_blink_;
  45. sigc::connection cursor_timer_connection_;
  46. std::unique_ptr<GtkRenderer> gtk_renderer_;
  47. std::unique_ptr<GtkCompletionPopup> completion_popup_; // Completion popup
  48. std::unique_ptr<ModeActivator> mode_activator_;
  49. protected:
  50. void on_activate();
  51. void on_draw(const Cairo::RefPtr<Cairo::Context>& cr, int width, int height);
  52. bool on_cursor_blink();
  53. void rebuild_layout();
  54. Gtk::Widget* create_widget_for_layout_node(std::shared_ptr<LayoutNode> node);
  55. // Completion popup helpers
  56. void show_completion_popup();
  57. void hide_completion_popup();
  58. void on_completion_selected(CompletionCandidate candidate);
  59. void on_completion_cancelled();
  60. // Global key event handler
  61. std::string get_lumacs_key_name(guint keyval, Gdk::ModifierType state);
  62. bool on_global_key_pressed(guint keyval, guint keycode, Gdk::ModifierType state);
  63. };
  64. std::unique_ptr<IEditorView> create_gtk_editor();
  65. } // namespace lumacs