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::VBox {
18 public:
25
26 CodeInput(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale, const Prefs& prefs,
27 Glib::RefPtr<Gtk::Adjustment>);
28
32
33 CodeInput(DTree::iterator, const std::string&, double 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>, double scale,
44 Glib::RefPtr<Gtk::Adjustment>);
45 virtual bool on_key_press_event(GdkEventKey*) override;
46 virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>&) override;
47 virtual bool on_focus_in_event(GdkEventFocus *) override;
48 virtual bool on_focus_out_event(GdkEventFocus *) override;
49 virtual void on_show() override;
50
51 virtual Gtk::SizeRequestMode get_request_mode_vfunc() const override;
52 virtual void get_preferred_width_for_height_vfunc(int height, int& minimum_width, int& natural_width) const override;
53 virtual bool on_motion_notify_event(GdkEventMotion *event) override;
54 virtual void on_size_allocate(Gtk::Allocation& allocation) override;
55
57 void on_textbuf_change();
58
59 sigc::signal1<bool, DTree::iterator> content_execute;
60 sigc::signal1<bool, DTree::iterator> content_changed;
61 sigc::signal3<bool, std::string, int, DTree::iterator> content_insert;
62 sigc::signal3<bool, int, int, DTree::iterator> content_erase;
63 sigc::signal1<bool, DTree::iterator> cell_got_focus;
64 sigc::signal2<bool, DTree::iterator, int> complete_request;
65
66 friend CodeInput;
67
68 int window_width = 100;
69 private:
70 double scale_;
71 DTree::iterator datacell;
72 Glib::RefPtr<Gtk::Adjustment> vadjustment;
73 double previous_value = -99.0;
74 };
75
77
78 void enable_highlighting(DataCell::CellType cell_type, const Prefs& prefs);
80
81 void relay_cursor_pos(std::function<void(int, int)> callback);
82
84
86
92
93 void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
94
99
100 void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
101
104
105 void update_buffer();
106
109
110 void slice_cell(std::string& before, std::string& after);
111
116
117 Glib::RefPtr<Gtk::TextBuffer> buffer;
118
120
121 private:
122 void init(const Prefs& prefs);
123
124 void highlight_python();
125 void highlight_latex();
126
127 sigc::connection hl_conn; // Connection holding the syntax highlighting signal
128 };
129
130 }
The actual text widget used by CodeInput.
Definition CodeInput.hh:41
virtual bool on_motion_notify_event(GdkEventMotion *event) override
Definition CodeInput.cc:795
virtual bool on_key_press_event(GdkEventKey *) override
Definition CodeInput.cc:565
DTree::iterator datacell
Definition CodeInput.hh:71
sigc::signal2< bool, DTree::iterator, int > complete_request
Definition CodeInput.hh:64
virtual void get_preferred_width_for_height_vfunc(int height, int &minimum_width, int &natural_width) const override
Definition CodeInput.cc:75
friend CodeInput
Definition CodeInput.hh:66
void shift_enter_pressed()
Definition CodeInput.cc:671
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition CodeInput.cc:779
virtual void on_show() override
Definition CodeInput.cc:819
sigc::signal3< bool, int, int, DTree::iterator > content_erase
Definition CodeInput.hh:62
virtual Gtk::SizeRequestMode get_request_mode_vfunc() const override
Definition CodeInput.cc:70
Glib::RefPtr< Gtk::Adjustment > vadjustment
Definition CodeInput.hh:72
sigc::signal3< bool, std::string, int, DTree::iterator > content_insert
Definition CodeInput.hh:61
void on_textbuf_change()
Definition CodeInput.cc:680
virtual void on_size_allocate(Gtk::Allocation &allocation) override
Definition CodeInput.cc:88
int window_width
Definition CodeInput.hh:68
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition CodeInput.cc:729
sigc::signal1< bool, DTree::iterator > content_execute
Definition CodeInput.hh:59
double scale_
Definition CodeInput.hh:70
double previous_value
Definition CodeInput.hh:73
sigc::signal1< bool, DTree::iterator > cell_got_focus
Definition CodeInput.hh:63
sigc::signal1< bool, DTree::iterator > content_changed
Definition CodeInput.hh:60
virtual bool on_focus_out_event(GdkEventFocus *) override
Definition CodeInput.cc:788
A text cell editor widget with support for editing Python and LaTeX.
Definition CodeInput.hh:17
void highlight_latex()
Definition CodeInput.cc:396
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition CodeInput.cc:825
sigc::connection hl_conn
Definition CodeInput.hh:127
void enable_highlighting(DataCell::CellType cell_type, const Prefs &prefs)
Set highlighting modes.
Definition CodeInput.cc:495
void disable_highlighting()
Definition CodeInput.cc:542
void relay_cursor_pos(std::function< void(int, int)> callback)
Definition CodeInput.cc:555
exp_input_tv edit
Definition CodeInput.hh:119
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition CodeInput.hh:117
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition CodeInput.cc:875
void init(const Prefs &prefs)
Definition CodeInput.cc:96
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:854
void highlight_python()
Definition CodeInput.cc:167
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:889
bool handle_button_press(GdkEventButton *)
Handle mouse buttons.
Definition CodeInput.cc:689
virtual void on_size_allocate(Gtk::Allocation &allocation) override
Definition CodeInput.cc:51
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:105
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:1063