Cadabra
Computer algebra system for field theory problems
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CodeInput.hh
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "DataCell.hh"
5 #include <gtkmm/box.h>
6 #include <gtkmm/textview.h>
7 #include <gtkmm/separator.h>
8 
9 namespace cadabra {
10 
15 
16  class CodeInput : public Gtk::VBox {
17  public:
23 
24  CodeInput(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale, int font_step);
25 
29 
30  CodeInput(DTree::iterator, const std::string&, double scale, int font_step);
31 
33 
34  class exp_input_tv : public Gtk::TextView {
35  public:
36  exp_input_tv(DTree::iterator, Glib::RefPtr<Gtk::TextBuffer>, double scale);
37  virtual bool on_key_press_event(GdkEventKey*) override;
38  virtual bool on_draw(const Cairo::RefPtr<Cairo::Context>&) override;
39  virtual bool on_focus_in_event(GdkEventFocus *) override;
40  virtual void on_show() override;
41 
42  void shift_enter_pressed();
43 
44  sigc::signal1<bool, DTree::iterator> content_execute;
45  sigc::signal2<bool, std::string, DTree::iterator> content_changed;
46  sigc::signal3<bool, std::string, int, DTree::iterator> content_insert;
47  sigc::signal3<bool, int, int, DTree::iterator> content_erase;
48  sigc::signal1<bool, DTree::iterator> cell_got_focus;
49 
50  friend CodeInput;
51 
52  private:
53  double scale_;
54  DTree::iterator datacell;
55  };
56 
58 
59  void set_font_size(int num);
60 
62 
63  bool handle_button_press(GdkEventButton *);
64 
70 
71  void handle_insert(const Gtk::TextIter& pos, const Glib::ustring& text, int bytes);
72 
77 
78  void handle_erase(const Gtk::TextIter& start, const Gtk::TextIter& end);
79 
82 
83  void update_buffer();
84 
87 
88  void slice_cell(std::string& before, std::string& after);
89 
94 
95  Glib::RefPtr<Gtk::TextBuffer> buffer;
96 
98 
99  private:
100  void init(int font_step);
101  };
102 
103 }
sigc::signal1< bool, DTree::iterator > content_execute
Definition: CodeInput.hh:44
void handle_erase(const Gtk::TextIter &start, const Gtk::TextIter &end)
Handle an erase event.
Definition: CodeInput.cc:267
sigc::signal3< bool, int, int, DTree::iterator > content_erase
Definition: CodeInput.hh:47
sigc::signal1< bool, DTree::iterator > cell_got_focus
Definition: CodeInput.hh:48
exp_input_tv edit
Definition: CodeInput.hh:97
virtual void on_show() override
Definition: CodeInput.cc:239
virtual bool on_focus_in_event(GdkEventFocus *) override
Definition: CodeInput.cc:233
sigc::signal2< bool, std::string, DTree::iterator > content_changed
Definition: CodeInput.hh:45
The actual text widget used by CodeInput.
Definition: CodeInput.hh:34
sigc::signal3< bool, std::string, int, DTree::iterator > content_insert
Definition: CodeInput.hh:46
friend CodeInput
Definition: CodeInput.hh:50
bool handle_button_press(GdkEventButton *)
Handle mouse buttons.
Definition: CodeInput.cc:146
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:258
exp_input_tv(DTree::iterator, Glib::RefPtr< Gtk::TextBuffer >, double scale)
Definition: CodeInput.cc:22
virtual bool on_draw(const Cairo::RefPtr< Cairo::Context > &) override
Definition: CodeInput.cc:189
void shift_enter_pressed()
Definition: CodeInput.cc:137
A text cell editor widget with support for editing Python and LaTeX.
Definition: CodeInput.hh:16
Glib::RefPtr< Gtk::TextBuffer > buffer
We cannot edit the content of the DataCell directly, because Gtk needs a Gtk::TextBuffer.
Definition: CodeInput.hh:95
void set_font_size(int num)
Set the font size, 0 being default, negative smaller, positive larger.
Definition: CodeInput.cc:283
CodeInput(DTree::iterator, Glib::RefPtr< Gtk::TextBuffer >, double scale, int font_step)
Initialise with existing TextBuffer and a pointer to the Datacell corresponding to this CodeInput wid...
Definition: CodeInput.cc:36
virtual bool on_key_press_event(GdkEventKey *) override
Definition: CodeInput.cc:103
DTree::iterator datacell
Definition: CodeInput.hh:54
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:274
double scale_
Definition: CodeInput.hh:53
void init(int font_step)
Definition: CodeInput.cc:49
void update_buffer()
Ensure that the visual representation matches the DTree cell.
Definition: CodeInput.cc:245