21#pragma implementation "wxterm.h"
44#include <wx/clipbrd.h>
45#include <wx/dataobj.h>
46#include "../globals.hpp"
50#define CURSOR_BLINK_DEFAULT_TIMEOUT 500
51#define CURSOR_BLINK_MAX_TIMEOUT 2000
52#define KERNEL_THREAD_STACK_SIZE 4194304
53#define MEASURING_STRING "The quick brown fox jumps over a lazy dog."
85NumeReTerminal::
NumeReTerminal(wxWindow* parent, wxWindowID
id,
Options* _option, const wxString& sPath, const wxPoint& pos,
int width,
int height, const wxString&
name) : wxWindow(parent,
id, pos, wxSize(-1, -1), wxWANTS_CHARS,
name),
GenericTerminal(width, height)
93 m_inUpdateSize =
false;
96 m_scrollBarWidth = wxSystemSettings::GetMetric(wxSYS_VSCROLL_ARROW_X);
98 m_charsInLine = width;
99 m_linesDisplayed = height;
101 m_selx1 = m_sely1 = m_selx2 = m_sely2 = 0;
106 m_timer.SetOwner(
this);
112 m_wxParent =
nullptr;
115 SetCursor(wxCursor(wxCURSOR_IBEAM));
118 _kernel.StartUp(
this, sPath.ToStdString(), getSyntax()->getFunctions());
119 m_options->copySettings(_kernel.getKernelSettings());
128 m_callTip =
new TerminalCallTip(
this, wxSize(100*m_charWidth, 2*m_charHeight));
130 SetClientSize(m_charsInLine * 8, m_linesDisplayed * 16);
137 m_timer.Start(m_curBlinkRate);
141 wxLog::SetActiveTarget(
new wxLogWindow(
this,
"Logger"));
149 m_bCommandAvailable =
false;
150 m_bTableEditAvailable =
false;
151 m_bTableEditCanceled =
false;
158 wxCriticalSectionLocker lock(m_kernelCS);
159 getSyntax()->addPlugins(_kernel.getPluginCommands());
172 m_memDC.SelectObject(wxNullBitmap);
419 wxLogError(
"Could not create kernel thread!");
422 if (GetThread()->Run() != wxTHREAD_NO_ERROR)
424 wxLogError(
"Could not run the kernel thread!");
440 std::string sCommand;
441 bool bCommandAvailable;
448 while (!GetThread()->TestDestroy())
465 if (!sCommand.length() && bCommandAvailable)
468 wxQueueEvent(GetEventHandler(),
new wxThreadEvent());
481 if (bCommandAvailable)
508 wxQueueEvent(GetEventHandler(),
new wxThreadEvent());
522 wxQueueEvent(GetEventHandler(),
new wxThreadEvent());
523 return (wxThread::ExitCode)0;
537 if (GetThread() && GetThread()->IsRunning())
540 GetThread()->Delete();
556 if (GetThread() && GetThread()->IsRunning())
575 bool Closing =
false;
576 bool changedSettings =
false;
578 bool refreshFunctionTree =
false;
579 std::queue<NumeReTask> taskQueue;
580 std::string sAnswer =
"";
625 sAnswer +=
"|\n|<- ";
647 while (taskQueue.size())
659 if (task.
sString.find(
".png") != std::string::npos
660 || task.
sString.find(
".jpg") != std::string::npos
661 || task.
sString.find(
".jpeg") != std::string::npos
662 || task.
sString.find(
".gif") != std::string::npos
663 || task.
sString.find(
".bmp") != std::string::npos)
693 refreshFunctionTree =
true;
716 if (refreshFunctionTree)
727 if (sAnswer ==
"|\n|<- " &&
GetTM()->getPreviousLine() ==
"|")
754 wxWindow::SetFont(font);
802 for (
size_t i = 0; i < 16; i++)
849 colors[i] = *wxBLACK;
928 if (!command.length())
933 wxLogDebug(
"Event: '%s'", command);
1014 if (!(
GetMode() &
PC) && event.AltDown())
1022 int keyCode = (int)event.GetKeyCode();
1029 if (keyCode == WXK_DELETE || keyCode == WXK_BACK)
1035 else if (keyCode < WXK_START)
1045 std::string buf =
" ";
1046 buf[0] = (char)keyCode;
1049 wxClientDC dc(
this);
1149 if (keyCode >= WXK_START || keyCode < WXK_SPACE)
1189 if (!(
GetMode() &
PC) && event.AltDown())
1191 else if (event.ControlDown() && event.ShiftDown())
1195 if (event.GetKeyCode() ==
'C' || event.GetKeyCode() ==
'V')
1200 else if (event.GetKeyCode() ==
'V')
1206 else if (event.GetKeyCode() == WXK_ESCAPE)
1238 wxLogDebug(
"Painting");
1267 this->CaptureMouse();
1282 if (this->GetCapture() ==
this)
1285 this->ReleaseMouse();
1305 if (this->GetCapture() ==
this)
1307 this->ReleaseMouse();
1341 if (event.AltDown())
1441 for (x = 0; x <
Width(); x++)
1445 for (x = 0; x <=
m_selx2; x++)
1450 for (x = 0; x <=
m_selx1; x++)
1455 for (x = 0; x <
Width(); x++)
1511 if (!sSelection.length())
1514 if (wxTheClipboard->Open())
1516 wxTheClipboard->SetData(
new wxTextDataObject(sSelection));
1517 wxTheClipboard->Close();
1531 if (wxTheClipboard->Open())
1533 if (wxTheClipboard->IsSupported(wxDF_TEXT))
1535 wxTextDataObject data;
1536 wxTheClipboard->GetData(data);
1541 wxTheClipboard->Close();
1635 m_curDC->SetBackgroundMode(wxSOLID);
1642 m_curDC->DrawText(str, x + 1, y);
1721 m_curDC->SetBackgroundMode(wxSOLID);
1728 m_curDC->DrawText(str, x + 1, y);
1788 wxClientDC* dc =
nullptr;
1806 dc =
new wxClientDC(
this);
1900 m_curDC->DrawRectangle(x, y, w , h );
1962 int charWidth, charHeight;
1963 wxClientDC* dc =
nullptr;
1967 dc =
new wxClientDC(
this);
1980 wxSize currentClientSize = GetClientSize();
1983 int numCharsInLine = currentClientSize.GetX() / charWidth;
1984 int numLinesShown = currentClientSize.GetY() / charHeight;
1993 if ( (numCharsInLine > 0) && (numLinesShown > 0))
2028 m_parent->SetBackgroundColour(
m_colors[0]);
2030 for (
int i = 0; i < 16; i++)
2079 m_memDC.SelectObject(wxNullBitmap);
2104 e.SetEventObject(
this);
2105 GetParent()->GetEventHandler()->ProcessEvent(e);
void addBreakpoint(const std::string &_sFilename, size_t nLine)
void removeBreakpoint(const std::string &_sFilename, size_t nLine)
void clearBreakpoints(const std::string &_sFilename)
An implementation of a generic terminal, which has to be specialized in the child classes.
bool cursor_up()
Either moves the cursor up or performs a history jump.
bool del()
Perform a delete key operation.
void clear_mode_flag(int flag)
Clears a mode flag (mainly used to make the cursor visible again).
void erase_line()
Erases the current line in the internal buffer.
TextManager * GetTM()
Get a pointer to the internal text buffer.
bool Scroll(int numLines, bool scrollUp)
virtual void ProcessInput(int len, const std::string &sData)
void set_mode_flag(int flag)
Sets a mode flag (only used to make the cursor invisble).
std::string get_selected_text()
Gets the selected text (if any).
virtual void Update()
Simple wrapper around update_changes()
bool cursor_right()
Moves the cursor to the right.
void tab()
Evaluate the tab key (do not insert a tab character but try to autocomplete the current input).
virtual void ModeChange(int state)
virtual void ProcessOutput(int len, const std::string &sData)
Processes output returned from the kernel and hands it over to the internal buffer.
bool cursor_down()
Either moves the cursor down or performs a history jump.
void resetAutoComp(int mode)
Reset the current autocompletion list and the corresponding variables.
virtual void Select(int x, int y, int select)
bool cursor_left()
Moves the cursor to the left.
virtual void ResizeTerminal(int _width, int _height)
bool end()
Moves the cursor to the rightmost position in the current line.
bool home()
Moves the cursor to the leftmost position in the current line.
NumeReSyntax * getSyntax()
bool delSelected()
Delete a selected block.
bool ctrl_left()
Moves the cursor one word to the left.
void cr()
Insert a carriage return.
bool bs()
Perform a backspace operation.
void move_cursor_editable_area(int x, int y)
Moves the cursor to a location, if this location is editable.
void erase_usercontent_line()
Erases alle user-written contents from the current line.
bool IsScrolledUp()
Determine, whether the terminal is scrolled up.
bool ctrl_right()
Moves the cursor one word to the right.
void lf()
Insert a line feed.
This data container is a copy- efficient table to interchange data between Kernel and GUI.
BreakpointManager & getBreakpointManager()
static ProcedureLibrary ProcLibrary
std::map< std::string, std::string > getPluginLanguageStrings()
This member function returns a map of language strings for the installed plugins, which will be used ...
Settings getKernelSettings()
Get the settings available in the Settings class.
std::vector< std::string > getDocIndex()
This member function returns the documentation index as a string vector, which can be used to fill th...
static NumeRe::Table getTable()
This member function is used by the kernel to be notified when the user finished the table edit proce...
void updateLineLenght(int nLength)
This member function is used to update the internal terminal line length information after the termin...
static void printPreFmt(const std::string &__sLine, bool printingEnabled=true)
This member function appends the pre- formatted string to the buffer and informs the terminal that we...
bool SettingsModified()
Returns true, if the user changed any internal settings using the set command.
static std::queue< NumeReTask > taskQueue
std::vector< std::string > getPluginCommands()
This member function is used by the syntax highlighter to hightlight the plugin commands.
NumeReDebugger & getDebugger()
int getAutosaveInterval() const
std::map< std::string, std::string > getMenuMap() const
Returns the menu map used to construct the package menu.
KernelStatus MainLoop(const std::string &sCommand)
This is the main loop for the core of NumeRe.
std::string getDocumentation(const std::string &sCommand)
This member function returns the documentation for the passed command string as HTML string prepared ...
@ NUMERE_INSTALLATION_DONE
@ NUMERE_REFRESH_FUNCTIONTREE
@ NUMERE_SHOW_STRING_TABLE
static NumeRe::Table table
std::map< std::string, std::string > getFunctionLanguageStrings()
This member function returns a map of language strings for the declared functions,...
void CloseSession()
This member function shuts the kernel down and terminates the kernel instance. Every call to NumeReKe...
NumeRe::Container< std::string > getStringTable(const std::string &sStringTableName)
This member function creates the table container for the string table or the clusters.
const std::vector< Package > & getInstalledPackages() const
Returns a vector containing the names and the version info of each installed plugin.
void printVersionInfo()
This member function prints the version headline and the version information to the console.
NumeReVariables getVariableList()
This member function returns a structure containing all currently declared variables,...
int ReadOpenFileFlag()
This member function returns the mode, how a file shall be opened in the editor, when called by the k...
void setKernelSettings(const Settings &_settings)
Update the internal settings.
long long int getLastSavedTime() const
Procedure & getProcedureInterpreter()
void initializeStackTracker()
Starts the stack tracker, which will prevent stack overflows.
std::vector< std::string > getPathSettings() const
This member function returns a vector containing all currently declared paths in a distinct order.
void Autosave()
Saves the allocated memories by the tables automatically.
void addPlugins(const std::vector< std::string > &vPlugins)
Add the plugin definitions to the command strings. Will reload the standard settings in advance to re...
The terminal class for the GUI. It's a specialisation of the GenericTerminal.
std::vector< std::string > getDocIndex()
Gets the contents of the documentation index as a vector.
TerminalCallTip * m_callTip
NumeReVariables getVariableList()
This will return the variable list from the kernel to be shown in the variable viewer.
void OnPaint(wxPaintEvent &event)
NumeReKernel::KernelStatus m_KernelStatus
void OnThreadUpdate(wxThreadEvent &event)
This function is the thread update event handler member function. Here are all returned messages from...
wxFont m_boldUnderlinedFont
virtual void UpdateRemoteSize(int width, int height)
Fallback for the virtual definition.
std::map< std::string, std::string > getPluginLanguageStrings()
This will return the language strings for the plugins used by the language class for filling the symb...
bool m_bTableEditAvailable
void passEditedTable(NumeRe::Table _table)
Passes a table (as a container) to the kernel.
void OnSize(wxSizeEvent &event)
void cutText()
Implements copy to clip board and deleting the selection.
void DoDrawCursor(int fg_color, int bg_color, int flags, int x, int y, unsigned char c)
void pipe_command(const std::string &sCommand)
Pass the entered command line to the kernel.
void EndKernelTask()
This function forces the thread to terminate so that the application may be shut down.
NumeRe::Table getTable(const std::string &sTableName)
This function will return the named table from the kernel to be shown in a GUI window.
virtual void Bell() override
virtual void Calltip(int x, int y, NumeRe::CallTip &_cTip) override
Function reimplementation to display a tooltip requested by the GenericTerminal.
void OnGainFocus(wxFocusEvent &event)
virtual void DrawCursor(int fg_color, int bg_color, int flags, int x, int y, unsigned char c) override
void StartKernelTask()
This member function will start the managed, second thread, in which the kernel will operate.
void OnLoseMouseCapture(wxMouseCaptureLostEvent &event)
This member function handles the "MouseCaptureLostEvent" and releases the mouse.
void clearTerminal()
This member function clears the terminal.
virtual ~NumeReTerminal()
Terminal destructor.
virtual void ModeChange(int state) override
void OnLeftDown(wxMouseEvent &event)
const std::vector< Package > & getInstalledPackages()
Returns the installed plugins as a STL vector.
void copyText()
Implements copy to clip board.
virtual void ProcessOutput(int len, const std::string &sData) override
Processes text received from the kernel.
void Busy()
Inform the GUI that the kernel is currently busy.
bool filterKeyCodes(int keyCode, bool ctrlDown)
This private member function filters special key codes and handles them.
virtual void CalltipCancel() override
Function reimplementation to close the previously opened calltip.
void OnClose(wxCloseEvent &event)
This function forces the thread to terminate immediately. Should only occur in situations,...
void pasteText()
Implements paste from clip board.
void OnLoseFocus(wxFocusEvent &event)
std::string m_sCommandLine
void MarkSelection(bool bRectangular=false)
virtual void ClearChars(int bg_color, int x, int y, int w, int h) override
void OnKeyDown(wxKeyEvent &event)
void ScrollTerminal(int numLines, bool scrollUp=true)
void pass_command(const std::string &command, bool isEvent)
Pass the external command to the kernel without printing it to the console.
void updatePackage(const std::string &package)
Updates an installed package with new information after the user created a package with the package c...
virtual void DrawText(int fg_color, int bg_color, int flags, int x, int y, const std::string &sText) override
Settings getKernelSettings()
This will return a copy of the internal settings object of the kernel.
void CancelCalculation()
Inform the kernel to stop the current calculation. Used to handle the ESC key press.
NumeReWindow * m_wxParent
bool m_updateProcedureLibrary
void UpdateColors()
This member function sets the new colors to the internal pen definitions.
virtual void ResizeTerminal(int width, int height) override
void clearBreakpoints(const std::string &_sFilename)
This member function removes all breakpoints from the passed file.
void GetDefColors(wxColor colors[16], NumeReTerminal::BOLDSTYLE boldStyle=NumeReTerminal::DEFAULT)
wxCriticalSection m_kernelCS
void scrollToInput()
This private member function scrolls the terminal all the way down.
std::map< std::string, std::string > getMenuMap()
Returns the menu map of the installed plugins as a STL map.
NumeRe::Container< std::string > getStringTable(const std::string &sStringTableName)
This member function will return the named table containing strings.
void removeBreakpoint(const std::string &_sFilename, size_t nLine)
This member function removes a breakpoint from the passed file at the indicated line number.
void OnTimer(wxTimerEvent &event)
void OnEnter(wxMouseEvent &event)
This member function handles the "Mouse Enter" event.
std::string getDocumentation(const std::string &sCommand)
Gets the desired documentation article as a HTML string.
void OnChar(wxKeyEvent &event)
virtual void ProcessInput(int len, const std::string &sData) override
Processes text received from the keybord or clipboard.
void setKernelSettings(const Settings &)
This will pass the new kernel settings to the kernel.
void SetCursorBlinkRate(int rate)
std::map< std::string, std::string > getFunctionLanguageStrings()
This will return the language strings for the custom defined functions used by the language class for...
wxColour m_color_defs[16]
std::vector< std::string > getPathSettings()
Returns the standard paths as a STL vector.
void OnActivate(wxActivateEvent &event)
void Ready()
Inform the GUI that the kernel is ready for calculation.
bool SetFont(const wxFont &font)
void OnMouseMove(wxMouseEvent &event)
wxPen m_colorPen_defs[16]
void OnLeftUp(wxMouseEvent &event)
virtual wxThread::ExitCode Entry()
This is the main thread function and will be called repeatedly from the wxWidgets library.
void addBreakpoint(const std::string &_sFilename, size_t nLine)
This member function adds a breakpoint to the passed file at the indicated line number.
void editTable(NumeRe::Container< std::string > _stringTable, const std::string &tableDisplayName)
This member function displays the contents of the "string()" table or a cluster and enables editing i...
void AddToHistory(const wxString &sCommand)
This function is a wrapper for the corresponding function from the history widget and stores the pass...
void Ready()
This member function tells NumeRe that it shall display the "ready" state to the user.
void openTable(NumeRe::Container< std::string > _stringTable, const std::string &tableDisplayName, const std::string &sIntName)
This member function displays the contents of the "string()" table or a cluster.
void showWindow(NumeRe::Window &window)
This public member function handles the creation of windows requested by the kernel.
void Busy()
This member function tells NumeRe that it shall display the "busy" state to the user.
void notifyInstallationDone()
Notifies all instances of the PackagRepoBrowser to refresh its internal list of installed packages an...
bool ShowHelp(const wxString &sDocId)
This member function displays the help page for the selected documentation ID.
void openImage(wxFileName filename)
This member function opens the selected image in the image viewer window.
void OpenSourceFile(wxArrayString fnames, unsigned int nLine=0, int nOpenFileFlag=OPENFILE_NOTHING)
Opens the given list of source files in the editor.
void closeWindows(WindowType type=WT_ALL)
Close all windows of the selected WindowType or simply use WT_ALL to close all terminal-closable floa...
void evaluateDebugInfo(const std::vector< std::string > &vDebugInfo)
This function will pass the obtained debugging information to the debug viewer. If this object does n...
void refreshFunctionTree()
This member function is a simple wrapper for refreshing the contents of the function tree.
This class implements an interface of the internal Settings object adapted to be usable from the GUI.
SyntaxStyles GetSyntaxStyle(size_t i) const
Return the selected syntax style by constructing it from the style string.
bool declareNewPackage(const std::string &sInstallInfoString)
This member function declares a new plugin from the passed install information string.
void updateLibrary()
Perform an update, e.g. if a procedure was deleted.
This class manages the setting values of the internal (kernel) settings of this application.
SettingsValue & getSetting(const std::string &value)
Returns a reference to the setting value, which corresponds to the passed string. Throws an exception...
void copySettings(const Settings &_settings)
This member function is an alias for the assignment operator overload.
bool & active()
Returns a reference to a boolean value type setting.
This class represents the calltip in the terminal. The associated window will only be shown and hidde...
void Highlight(size_t start, size_t len)
Hightlight the section of the text in the calltip.
void Resize(const wxSize &s)
Change the calltip's size.
void Dismiss()
Remove the shown calltip.
void PopUp(const wxPoint &pos, const wxString &text)
Show the calltip at the desired position. This function does not check, whether the calltip is acutal...
void ChangeFont(const wxFont &font)
Changes the font of the calltip.
void ChangeEditableState()
Removes the editable flag from the managed text.
std::string getCurrentInputLine() const
Returns the contents of the input line.
void unselectAll()
This member function unselects the whole text at once.
WindowType
This enumeration defines all terminal- closable window types.
FindReplaceDialog * g_findReplace
value_type rint(value_type v)
#define SETTING_B_SMARTSENSE
#define SETTING_S_TERMINALFONT
This structure contains the data for a single calltip, which might be shown in the editor or the term...
This structure abstracts the necessary information for a task to be done by the graphical user interf...
NumeRe::Container< std::string > stringTable
std::vector< std::string > vDebugEvent
This structure combines a vector of declared variables including their values and respective sizes wi...
#define KERNEL_THREAD_STACK_SIZE
#define CURSOR_BLINK_DEFAULT_TIMEOUT
#define CURSOR_BLINK_MAX_TIMEOUT
#define wxEVT_COMMAND_TERM_RESIZE