gtk_editor.hpp 2.8 KB

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