gtk_editor.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // Custom Gtk::ApplicationWindow to make constructor public
  20. class LumacsWindow : public Gtk::ApplicationWindow {
  21. public:
  22. explicit LumacsWindow(const Glib::RefPtr<Gtk::Application>& application);
  23. };
  24. class GtkEditor : public IEditorView {
  25. public:
  26. GtkEditor();
  27. ~GtkEditor() override;
  28. void init() override;
  29. void run() override;
  30. void handle_editor_event(EditorEvent event) override;
  31. void set_core(EditorCore* core) override;
  32. void queue_redraw_all_windows(Gtk::Widget* widget);
  33. private:
  34. EditorCore* core_;
  35. std::shared_ptr<Window> cached_active_window_;
  36. Glib::RefPtr<Gtk::Application> app_;
  37. Gtk::Window* window_ = nullptr;
  38. Gtk::DrawingArea* drawing_area_ = nullptr; // Raw pointer to the main drawing area if single window
  39. Gtk::DrawingArea* minibuffer_drawing_area_ = nullptr; // Dedicated drawing area for minibuffer
  40. Gtk::Widget* content_widget_ = nullptr; // The root widget of the editor content (Paned or DrawingArea)
  41. // For cursor blinking logic
  42. bool cursor_visible_ = true;
  43. sigc::connection cursor_timer_connection_;
  44. std::chrono::steady_clock::time_point last_cursor_move_time_;
  45. static constexpr std::chrono::milliseconds BLINK_INTERVAL = std::chrono::milliseconds(500);
  46. static constexpr std::chrono::milliseconds BLINK_STATIONARY_THRESHOLD = std::chrono::milliseconds(1000); // 1 second
  47. std::unique_ptr<GtkRenderer> gtk_renderer_;
  48. std::unique_ptr<GtkCompletionPopup> completion_popup_; // Completion popup
  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