Cadabra
Computer algebra system for field theory problems
Loading...
Searching...
No Matches
CodeInput.hh
Go to the documentation of this file.
1
2#pragma once
3
4#include "GtkCompat.hh"
5#include "DataCell.hh"
6#include "DocumentThread.hh"
7#include <gtkmm/box.h>
8#include <gtkmm/textview.h>
9#include <gtkmm/separator.h>
10#ifdef USE_GTK4
11#include <gtkmm/snapshot.h>
12#include <gtkmm/eventcontrollerkey.h>
13#include <gtkmm/eventcontrollerfocus.h>
14#include <gtkmm/eventcontrollermotion.h>
15#endif
16
17namespace cadabra {
18
23
24 class CodeInput : public Gtk::Box {
25 public:
32
33 CodeInput(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale, double display_scale, const Prefs& prefs,
34 Glib::RefPtr<Gtk::Adjustment>);
35
39
40 CodeInput(DTree::iterator, const std::string&, double scale, double display_scale, const Prefs& prefs,
41 Glib::RefPtr<Gtk::Adjustment>);
42
43
44#ifndef USE_GTK4
45 // Chains to the base class only; not needed under GTK4.
46 virtual void on_size_allocate(Gtk::Allocation& allocation) override;
47#endif
48
50
51 class exp_input_tv : public Gtk::TextView {
52 public:
53 exp_input_tv(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>,
54 double scale,
55 double display_scale,
56 Glib::RefPtr<Gtk::Adjustment>);
57 virtual void on_show() override;
58
64 bool handle_key_press(guint keyval, Gdk::ModifierType state);
65
67 void on_focus_entered();
68 void on_focus_left();
69 void on_pointer_motion();
70
71#ifndef USE_GTK4
72 virtual bool on_key_press_event(GdkEventKey*) override;
73 virtual bool on_focus_in_event(GdkEventFocus *) override;
74 virtual bool on_focus_out_event(GdkEventFocus *) override;
75 virtual bool on_motion_notify_event(GdkEventMotion *event) override;
76#endif
77
78 virtual Gtk::SizeRequestMode get_request_mode_vfunc() const override;
79
82 void draw_gutter(const Cairo::RefPtr<Cairo::Context>& cr, int height);
83
87
88#ifdef USE_GTK4
89 void snapshot_vfunc(const Glib::RefPtr<Gtk::Snapshot>& snapshot) override;
90 void measure_vfunc(Gtk::Orientation orientation, int for_size,
91 int& minimum, int& natural,
92 int& minimum_baseline, int& natural_baseline) const override;
93#else
94 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>&) override;
95 virtual void get_preferred_width_for_height_vfunc(int height, int& minimum_width, int& natural_width) const override;
96 virtual void on_size_allocate(Gtk::Allocation& allocation) override;
97#endif
98
100 void on_textbuf_change();
101
102 sigc::signal<bool(DTree::iterator)> content_execute;
103 sigc::signal<bool(DTree::iterator)> content_changed;
104 sigc::signal<bool(std::string, int, DTree::iterator)> content_insert;
105 sigc::signal<bool(int, int, DTree::iterator)> content_erase;
106 sigc::signal<bool(DTree::iterator)> cell_got_focus;
107 sigc::signal<bool(DTree::iterator, int)> complete_request;
108
109 friend CodeInput;
110
111 int window_width = 100;
112 private:
114 DTree::iterator datacell;
115 Glib::RefPtr<Gtk::Adjustment> vadjustment;
116 double previous_value = -99.0;
117#ifdef USE_GTK4
118 Glib::RefPtr<Gtk::EventControllerKey> key_controller;
119 Glib::RefPtr<Gtk::EventControllerFocus> focus_controller;
120 Glib::RefPtr<Gtk::EventControllerMotion> motion_controller;
121#endif
122 };
123
125
126 void enable_highlighting(DataCell::CellType cell_type, const Prefs& prefs);
128
129 void relay_cursor_pos(std::function<void(int, int)> callback);
130
132
134 void handle_middle_click(double x, double y);
135#ifndef USE_GTK4
137#endif
138
144
145 void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
146
151
152 void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
153
156
157 void update_buffer();
158
161
162 void slice_cell(std::string& before, std::string& after);
163
168
169 Glib::RefPtr<Gtk::TextBuffer> buffer;
170
172
173 private:
174#ifdef USE_GTK4
177 Glib::RefPtr<cdb::ClickGesture> paste_gesture;
178#endif
179
180 void init(const Prefs& prefs, double display_scale);
181
182 void highlight_python();
183 void highlight_latex();
184
185 sigc::connection hl_conn; // Connection holding the syntax highlighting signal
186 };
187
188 }
Compatibility helpers that let the gtkmm frontend build against both gtkmm-3 and gtkmm-4 from a singl...
The actual text widget used by CodeInput.
Definition CodeInput.hh:51
void on_pointer_motion()
Definition CodeInput.cc:929
double display_scale_
Definition CodeInput.hh:113
virtual bool on_motion_notify_event(GdkEventMotion *event) override
Definition CodeInput.cc:950
virtual bool on_key_press_event(GdkEventKey *) override
Definition CodeInput.cc:772
DTree::iterator datacell
Definition CodeInput.hh:114
sigc::signal< bool(DTree::iterator)> cell_got_focus
Definition CodeInput.hh:106
virtual void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override
Definition CodeInput.cc:148
friend CodeInput
Definition CodeInput.hh:109
void shift_enter_pressed()
Definition CodeInput.cc:780
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition CodeInput.cc:938
virtual void on_show() override
Definition CodeInput.cc:974
sigc::signal< bool(DTree::iterator)> content_execute
Definition CodeInput.hh:102
virtual Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition CodeInput.cc:105
Glib::RefPtr< Gtk::Adjustment > vadjustment
Definition CodeInput.hh:115
void on_textbuf_change()
Definition CodeInput.cc:789
virtual void on_size_allocate(Gtk::Allocation &allocation) override
Definition CodeInput.cc:155
void on_focus_entered()
Side effects of focus and pointer motion, likewise shared.
Definition CodeInput.cc:915
bool handle_key_press(guint keyval, Gdk::ModifierType state)
Key handling, shared between the toolkits.
Definition CodeInput.cc:676
int window_width
Definition CodeInput.hh:111
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition CodeInput.cc:851
sigc::signal< bool(std::string, int, DTree::iterator)> content_insert
Definition CodeInput.hh:104
void on_focus_left()
Definition CodeInput.cc:923
bool measure_width_for_height(int &minimum_width, int &natural_width) const
Width logic for LaTeX cells, shared between the toolkits; returns false when the base class should de...
Definition CodeInput.cc:114
sigc::signal< bool(DTree::iterator)> content_changed
Definition CodeInput.hh:103
void draw_gutter(const Cairo::RefPtr< Cairo::Context > &cr, int height)
Paint the coloured bar down the left-hand side of the cell, on top of the TextView's own rendering.
Definition CodeInput.cc:873
double scale_
Definition CodeInput.hh:113
double previous_value
Definition CodeInput.hh:116
sigc::signal< bool(DTree::iterator, int)> complete_request
Definition CodeInput.hh:107
sigc::signal< bool(int, int, DTree::iterator)> content_erase
Definition CodeInput.hh:105
virtual bool on_focus_out_event(GdkEventFocus *) override
Definition CodeInput.cc:944
A text cell editor widget with support for editing Python and LaTeX.
Definition CodeInput.hh:24
void highlight_latex()
Definition CodeInput.cc:502
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition CodeInput.cc:980
sigc::connection hl_conn
Definition CodeInput.hh:185
void enable_highlighting(DataCell::CellType cell_type, const Prefs &prefs)
Set highlighting modes.
Definition CodeInput.cc:601
void disable_highlighting()
Definition CodeInput.cc:648
void relay_cursor_pos(std::function< void(int, int)> callback)
Definition CodeInput.cc:661
exp_input_tv edit
Definition CodeInput.hh:171
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition CodeInput.hh:169
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition CodeInput.cc:1030
void handle_insert(const Gtk::TextIter &pos, const Glib::ustring &text, int bytes)
Handle an insert event, which can consist of one or more inserted characters.
Definition CodeInput.cc:1009
void highlight_python()
Definition CodeInput.cc:266
void handle_middle_click(double x, double y)
Handle mouse buttons.
Definition CodeInput.cc:806
void init(const Prefs &prefs, double display_scale)
Definition CodeInput.cc:165
void slice_cell(std::string &before, std::string &after)
Return two strings corresponding to the text before and after the current cursor position.
Definition CodeInput.cc:1044
bool handle_button_press(GdkEventButton *)
Definition CodeInput.cc:827
virtual void on_size_allocate(Gtk::Allocation &allocation) override
Definition CodeInput.cc:85
CellType
Cells are labelled with the data type of its contents, which is stored in a textural representation b...
Definition DataCell.hh:34
Definition DocumentThread.hh:127
Functions to handle the exchange properties of two or more symbols in a product.
Definition Adjform.cc:83
void set(rset_t::iterator &num, multiplier_t fac)
Definition Storage.cc:1180