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 "DataCell.hh"
5#include "DocumentThread.hh"
6#include <gtkmm/box.h>
7#include <gtkmm/textview.h>
8#include <gtkmm/separator.h>
9
10namespace cadabra {
11
16
17 class CodeInput : public Gtk::Box {
18 public:
25
26 CodeInput(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale, double display_scale, const Prefs& prefs,
27 Glib::RefPtr<Gtk::Adjustment>);
28
32
33 CodeInput(DTree::iterator, const std::string&, double scale, double display_scale, const Prefs& prefs,
34 Glib::RefPtr<Gtk::Adjustment>);
35
36
37 virtual void on_size_allocate(Gtk::Allocation& allocation) override;
38
40
41 class exp_input_tv : public Gtk::TextView {
42 public:
43 exp_input_tv(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>,
44 double scale,
45 double display_scale,
46 Glib::RefPtr<Gtk::Adjustment>);
47 virtual bool on_key_press_event(GdkEventKey*) override;
48 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>&) override;
49 virtual bool on_focus_in_event(GdkEventFocus *) override;
50 virtual bool on_focus_out_event(GdkEventFocus *) override;
51 virtual void on_show() override;
52
53 virtual Gtk::SizeRequestMode get_request_mode_vfunc() const override;
54 virtual void get_preferred_width_for_height_vfunc(int height, int& minimum_width, int& natural_width) const override;
55 virtual bool on_motion_notify_event(GdkEventMotion *event) override;
56 virtual void on_size_allocate(Gtk::Allocation& allocation) override;
57
59 void on_textbuf_change();
60
61 sigc::signal1<bool, DTree::iterator> content_execute;
62 sigc::signal1<bool, DTree::iterator> content_changed;
63 sigc::signal3<bool, std::string, int, DTree::iterator> content_insert;
64 sigc::signal3<bool, int, int, DTree::iterator> content_erase;
65 sigc::signal1<bool, DTree::iterator> cell_got_focus;
66 sigc::signal2<bool, DTree::iterator, int> complete_request;
67
68 friend CodeInput;
69
70 int window_width = 100;
71 private:
73 DTree::iterator datacell;
74 Glib::RefPtr<Gtk::Adjustment> vadjustment;
75 double previous_value = -99.0;
76 };
77
79
80 void enable_highlighting(DataCell::CellType cell_type, const Prefs& prefs);
82
83 void relay_cursor_pos(std::function<void(int, int)> callback);
84
86
88
94
95 void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
96
101
102 void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
103
106
107 void update_buffer();
108
111
112 void slice_cell(std::string& before, std::string& after);
113
118
119 Glib::RefPtr<Gtk::TextBuffer> buffer;
120
122
123 private:
124 void init(const Prefs& prefs, double display_scale);
125
126 void highlight_python();
127 void highlight_latex();
128
129 sigc::connection hl_conn; // Connection holding the syntax highlighting signal
130 };
131
132 }
The actual text widget used by CodeInput.
Definition CodeInput.hh:41
double display_scale_
Definition CodeInput.hh:72
virtual bool on_motion_notify_event(GdkEventMotion *event) override
Definition CodeInput.cc:809
virtual bool on_key_press_event(GdkEventKey *) override
Definition CodeInput.cc:579
DTree::iterator datacell
Definition CodeInput.hh:73
sigc::signal2< bool, DTree::iterator, int > complete_request
Definition CodeInput.hh:66
virtual void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override
Definition CodeInput.cc:82
friend CodeInput
Definition CodeInput.hh:68
void shift_enter_pressed()
Definition CodeInput.cc:685
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition CodeInput.cc:793
virtual void on_show() override
Definition CodeInput.cc:833
sigc::signal3< bool, int, int, DTree::iterator > content_erase
Definition CodeInput.hh:64
virtual Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition CodeInput.cc:77
Glib::RefPtr< Gtk::Adjustment > vadjustment
Definition CodeInput.hh:74
sigc::signal3< bool, std::string, int, DTree::iterator > content_insert
Definition CodeInput.hh:63
void on_textbuf_change()
Definition CodeInput.cc:694
virtual void on_size_allocate(Gtk::Allocation &allocation) override
Definition CodeInput.cc:95
int window_width
Definition CodeInput.hh:70
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition CodeInput.cc:743
sigc::signal1< bool, DTree::iterator > content_execute
Definition CodeInput.hh:61
double scale_
Definition CodeInput.hh:72
double previous_value
Definition CodeInput.hh:75
sigc::signal1< bool, DTree::iterator > cell_got_focus
Definition CodeInput.hh:65
sigc::signal1< bool, DTree::iterator > content_changed
Definition CodeInput.hh:62
virtual bool on_focus_out_event(GdkEventFocus *) override
Definition CodeInput.cc:802
A text cell editor widget with support for editing Python and LaTeX.
Definition CodeInput.hh:17
void highlight_latex()
Definition CodeInput.cc:410
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition CodeInput.cc:839
sigc::connection hl_conn
Definition CodeInput.hh:129
void enable_highlighting(DataCell::CellType cell_type, const Prefs &prefs)
Set highlighting modes.
Definition CodeInput.cc:509
void disable_highlighting()
Definition CodeInput.cc:556
void relay_cursor_pos(std::function< void(int, int)> callback)
Definition CodeInput.cc:569
exp_input_tv edit
Definition CodeInput.hh:121
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition CodeInput.hh:119
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition CodeInput.cc:889
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:868
void highlight_python()
Definition CodeInput.cc:174
void init(const Prefs &prefs, double display_scale)
Definition CodeInput.cc:103
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:903
bool handle_button_press(GdkEventButton *)
Handle mouse buttons.
Definition CodeInput.cc:703
virtual void on_size_allocate(Gtk::Allocation &allocation) override
Definition CodeInput.cc:58
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:1179