NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
gterm.cpp
Go to the documentation of this file.
1
2// Copyright Timothy Miller, 1999
3
4#ifdef __GNUG__
5#pragma implementation "gterm.hpp"
6#endif
7
8#include "gterm.hpp"
9#include <wx/stdpaths.h>
10#include <wx/wx.h>
11#include <wx/filename.h>
12
20{
22}
23
24
36void GenericTerminal::ProcessInput(int len, const std::string& sData)
37{
38 // Copy the input
39 data_len = sData.length();
40 sInput_Data = sData;
41
44
45 // Evaluate the input and update the GUI
48 return;
49
50}
51
52
63void GenericTerminal::ProcessOutput(int len, const std::string& sData)
64{
65 // Copy the input
66 data_len += sData.length();
67 sInput_Data += sData;
68
69 // Evaluate the input and update the GUI
73 return;
74}
75
76
84{
85 reset();
86}
87
88
101void GenericTerminal::ResizeTerminal(int _width, int _height)
102{
103 // Create an invalid cursor
104 LogicalCursor cursor;
105
106 // If the current terminal is not scrolled up
107 // use the current view cursor
108 if (!IsScrolledUp())
109 {
110 cursor = tm.toLogicalCursor(termCursor);
111 }
112
113#ifdef DO_LOG
114 wxLogDebug("Resizing terminal: _width = %d, _height = %d", _width, _height);
115#endif
116
117 // Perform the resize in the internal buffer
118 tm.Resize(_width, _height);
119
120 // If the cursor is valid and has a non-zero position
121 if (cursor && (cursor.pos || cursor.line))
122 {
123 // Use it as the new terminal view cursor
124 termCursor = tm.toViewCursor(cursor);
125 if (!termCursor)
127 }
128
129 width = _width;
130
131 // Does the height change?
132 if (_height != height)
133 {
134 height = _height;
135
136 // Update the scroll indicators
137 scroll_bot = height - 1;
138 if (scroll_top >= height)
139 scroll_top = 0;
140 }
141
142 // Update the GUI
144}
145
146
154GenericTerminal::GenericTerminal(int w, int h) : width(w), height(h), m_useSmartSense(false)
155{
156 doing_update = 0;
157
158 // Create the text manager
159 tm = TextManager(this, w, h, MAXWIDTH, MAXHEIGHT);
160
161 // Load the syntax
162 wxFileName f(wxStandardPaths::Get().GetExecutablePath());
163 _syntax.loadSyntax(f.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR).ToStdString());
164
165 // Set the terminal view cursor to top left
166 // To make the cursor valid, we have to instantiate it with zeros
167 termCursor = ViewCursor(0, 0);
168 mode_flags = 0;
169 reset();
171}
172
173
178{
179}
180
181
193int
195{
196 if (x >= 0 && x < Width() && y >= 0 && y < Height())
197 return tm.isSelected(ViewCursor(x, y));
198 return 0;
199}
200
201
214void
215GenericTerminal::Select(int x, int y, int select)
216{
217 if (x >= 0 && x < Width() && y >= 0 && y < Height())
218 {
219 tm.selectText(ViewCursor(x, y), select);
220 }
221}
222
223
233unsigned char GenericTerminal::GetChar(int x, int y)
234{
235 if (x >= 0 && x < Width() && y >= 0 && y < Height())
236 return tm.GetCharAdjusted(y, x);
237
238 return 0;
239}
240
241
249{
250 return tm.getSelectedText();
251}
252
253
262{
263 return &tm;
264}
265
266
278bool GenericTerminal::Scroll(int numLines, bool scrollUp)
279{
280 // Scroll and update the GUI
281 if (tm.Scroll(numLines, scrollUp))
282 {
285 return true;
286 }
287 return false;
288}
289
290
299{
300 return (tm.GetNumLinesScrolled() != 0);
301}
302
303
313{
314 int scrollHeight = tm.GetLinesReceived();
315
316 int maxSize = tm.GetMaxSize();
317
318 if (scrollHeight > maxSize)
319 scrollHeight = maxSize;
320
321 return scrollHeight;
322}
323
324
332{
333 return tm.GetNumLinesScrolled();
334}
335
336
349{
350 tm.SetMaxSize(size);
351}
352
TextManager * GetTM()
Get a pointer to the internal text buffer.
Definition: gterm.cpp:261
virtual ~GenericTerminal()
Empty destructor.
Definition: gterm.cpp:177
bool Scroll(int numLines, bool scrollUp)
Definition: gterm.cpp:278
virtual void Reset()
Simple wrapper around reset().
Definition: gterm.cpp:83
int scroll_bot
Definition: gterm.hpp:77
virtual void ProcessInput(int len, const std::string &sData)
Definition: gterm.cpp:36
int GetScrollHeight()
Definition: gterm.cpp:312
ViewCursor termCursor
Definition: gterm.hpp:85
std::string get_selected_text()
Gets the selected text (if any).
Definition: gterm.cpp:248
virtual unsigned char GetChar(int x, int y)
Gets the character at the selected location.
Definition: gterm.cpp:233
virtual void Update()
Simple wrapper around update_changes()
Definition: gterm.cpp:19
virtual void CalltipCancel()
Definition: gterm.hpp:189
std::string sInput_Data
Definition: gterm.hpp:97
virtual void ProcessOutput(int len, const std::string &sData)
Processes output returned from the kernel and hands it over to the internal buffer.
Definition: gterm.cpp:63
void update_changes()
Definition: utils.cpp:37
int Width() const
Definition: gterm.hpp:152
int scroll_top
Definition: gterm.hpp:77
int doing_update
Definition: gterm.hpp:103
void resetAutoComp(int mode)
Reset the current autocompletion list and the corresponding variables.
Definition: actions.cpp:120
void normal_input()
Definition: actions.cpp:21
virtual void Select(int x, int y, int select)
Definition: gterm.cpp:215
GenericTerminal(int w, int h)
Constructor.
Definition: gterm.cpp:154
virtual void ResizeTerminal(int _width, int _height)
Definition: gterm.cpp:101
TextManager tm
Definition: gterm.hpp:80
void SetTerminalHistory(int size)
Set the terminal buffer size (not the length of the input history). The length of the history (i....
Definition: gterm.cpp:348
int GetScrollPosition()
Returns the current scroll position.
Definition: gterm.cpp:331
int Height() const
Definition: gterm.hpp:156
void handle_calltip(int x, int y)
Check, whether a calltip is needed and select the corresponding text from the CallTipProvider.
Definition: utils.cpp:193
void reset()
Resets the terminal, so that it starts with an empty buffer.
Definition: actions.cpp:409
virtual int IsSelected(int x, int y)
Definition: gterm.cpp:194
bool IsScrolledUp()
Determine, whether the terminal is scrolled up.
Definition: gterm.cpp:298
void normal_output()
This member function is for printing the kernel's output to the console.
Definition: actions.cpp:59
int mode_flags
Definition: gterm.hpp:87
NumeReSyntax _syntax
Definition: gterm.hpp:99
void loadSyntax(const std::string &_sPath="")
Member function for loading the syntax element definitions.
Definition: syntax.cpp:89
This class manages the actual text by storing it in an internal buffer. During an update the TextMana...
Definition: TextManager.h:486
std::string getSelectedText() const
This member function returns the selected text.
bool Scroll(int numLines, bool scrollUp)
ViewCursor toViewCursor(const LogicalCursor &logCursor) const
Convert a logical cursor to a view cursor.
void Resize(int width, int height)
char GetCharAdjusted(int y, int x) const
void selectText(const ViewCursor &viewCursor, bool bSelect=true)
Selects the text at the view cursor position.
void SetMaxSize(int newSize)
ViewCursor getCurrentViewPos() const
Returns the current cursor position as view cursor.
bool isSelected(const ViewCursor &viewCursor) const
Determines, whether the pointed character is selected.
LogicalCursor toLogicalCursor(const ViewCursor &viewCursor) const
Convert a view cursor into a logical cursor.
int GetLinesReceived() const
int GetNumLinesScrolled() const
int GetMaxSize() const
Returns the buffer size of the terminal.
#define MAXWIDTH
Definition: gterm.hpp:26
#define MAXHEIGHT
Definition: gterm.hpp:27
Cursor, which is used in the TextManager to identify the actual line and position in the m_text varia...
Definition: TextManager.h:38
Cursor, which is used in the terminal. The TextManager is able to convert this cursor into a LogicalC...
Definition: TextManager.h:124
size_t y
Definition: TextManager.h:126
size_t x
Definition: TextManager.h:125