From: John L. <jr...@us...> - 2005-11-24 06:38:26
|
Update of /cvsroot/wxlua/wxLua/apps/wxluaedit/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5356/wxLua/apps/wxluaedit/src Added Files: Makefile wxledit.cpp wxledit.h wxluaedit.cpp wxluaedit.rc Log Message: remove more dead files add back univ platform for defsutils.i cleanup wx.rules add wxluaeditor, an embedded sample editor using wxSTEditor --- NEW FILE: wxluaedit.rc --- #include "wx/msw/wx.rc" --- NEW FILE: wxluaedit.cpp --- ///////////////////////////////////////////////////////////////////////////// // Name: wxluaedit.cpp // Purpose: wxLuaEditor app // Author: John Labenski // Modified by: // Created: 04/01/98 // RCS-ID: // Copyright: (c) John Labenski // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "wx/image.h" #include "wx/stedit/stedit.h" #include "wxledit.h" #include "wxlua/include/internal.h" // ---------------------------------------------------------------------------- // resources and constants // ---------------------------------------------------------------------------- #include "../../../art/wxlua.xpm" // ---------------------------------------------------------------------------- // wxLuaEditorApp // ---------------------------------------------------------------------------- class wxLuaEditorApp : public wxApp { public: virtual bool OnInit(); }; // ---------------------------------------------------------------------------- // wxLuaEditorFrame // ---------------------------------------------------------------------------- class wxLuaEditorFrame : public wxSTEditorFrame { public: wxLuaEditorFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long frame_style = wxDEFAULT_FRAME_STYLE) : wxSTEditorFrame() { Create(title, pos, size, frame_style); } bool Create(const wxString& title, const wxPoint& pos, const wxSize& size, long frame_style = wxDEFAULT_FRAME_STYLE); virtual bool HandleMenuEvent( wxCommandEvent &event ); void OnAbout(wxCommandEvent& event); wxLuaConsole *m_luaConsole; private: DECLARE_ABSTRACT_CLASS(wxLuaEditorFrame) DECLARE_EVENT_TABLE() }; // ---------------------------------------------------------------------------- // wxLuaEditorApp // ---------------------------------------------------------------------------- IMPLEMENT_APP(wxLuaEditorApp) bool wxLuaEditorApp::OnInit() { wxInitAllImageHandlers(); wxLuaEditorFrame *frame = new wxLuaEditorFrame(_T("wxLuaEditor"), wxPoint(20, 20), wxSize(600, 400)); long frameOpts = STF_DEFAULT_OPTIONS & (~STF_CREATE_NOTEBOOK) & (~STF_CREATE_SIDEBAR); wxSTEditorOptions steOptions(STE_DEFAULT_OPTIONS, STS_DEFAULT_OPTIONS, STN_DEFAULT_OPTIONS, STE_CONFIG_DEFAULT_OPTIONS, frameOpts, wxT("untitled.lua")); frame->CreateOptions(steOptions); wxIcon icon; icon.CopyFromBitmap(wxBitmap(LUA_xpm)); frame->SetIcon(icon); frame->GetToolBar()->AddSeparator(); frame->m_luaConsole->PopulateToolBar(frame->GetToolBar(), LUACON_TB_LUA); frame->m_luaConsole->SetToolBar(frame->GetToolBar()); frame->m_luaConsole->SetMenuBar(frame->GetMenuBar()); // The size of the frame isn't set when the splitter is created, resize it wxSplitterWindow *splitWin = frame->m_luaConsole->GetSplitterWin(); splitWin->SetSashPosition(splitWin->GetSize().y/2); frame->Show(TRUE); return TRUE; } // ---------------------------------------------------------------------------- // wxLuaEditorFrame // ---------------------------------------------------------------------------- IMPLEMENT_ABSTRACT_CLASS(wxLuaEditorFrame, wxSTEditorFrame) BEGIN_EVENT_TABLE(wxLuaEditorFrame, wxSTEditorFrame) END_EVENT_TABLE() bool wxLuaEditorFrame::Create(const wxString& title, const wxPoint& pos, const wxSize& size, long frame_style) { m_luaConsole = NULL; if (!wxSTEditorFrame::Create(NULL, -1, title, pos, size, frame_style)) return false; m_sideSplitter = new wxSplitterWindow(this, wxID_ANY); m_sideSplitter->SetMinimumPaneSize(10); m_sideNotebook = new wxNotebook(m_sideSplitter, wxID_ANY); m_fileListBox = new wxListBox(m_sideNotebook, ID_STF_FILELISTBOX, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE ); m_sideNotebook->AddPage(m_fileListBox, wxT("Files")); m_sideSplitterWin1 = m_sideNotebook; m_luaConsole = new wxLuaConsole(m_sideSplitter, -1, wxDefaultPosition, wxSize(400,600), 0, 0); m_editorNotebook = m_luaConsole->GetEditorNotebook(); m_sideSplitterWin2 = m_luaConsole; return true; } bool wxLuaEditorFrame::HandleMenuEvent(wxCommandEvent &event) { wxWindow *focusWin = FindFocus(); switch (event.GetId()) { case wxID_ABOUT : { OnAbout(event); return true; } case wxID_CUT : case wxID_COPY : case wxID_PASTE : case wxID_SELECTALL : { // These windows only handle these IDs if (focusWin == m_luaConsole->GetLuaOutputWin()) return m_luaConsole->GetLuaOutputWin()->HandleMenuEvent(event); if (focusWin == m_luaConsole->GetLuaShellWin()) return m_luaConsole->GetLuaShellWin()->HandleMenuEvent(event); break; } default : break; } if (!wxSTEditorFrame::HandleMenuEvent(event)) m_luaConsole->OnMenu(event); return true; } void wxLuaEditorFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { // since the dialog is modal, it's ok that the interpreter is created on the stack wxLuaInterpreter interpreter(NULL, -1); // Create a script to run // local msg = "Welcome to wxLua!\n" // msg = msg..string.format("%s", "This dialog is created from a wxLua script.") // wx.wxMessageBox(msg, "About wxLua Embedded", wx.wxOK + wx.wxICON_INFORMATION) wxString script; script += wxT("local msg = \"Welcome to wxLuaEditor!\\n\""); script += wxT("msg = msg..string.format(\"%s\", \"This dialog is created from a wxLua script.\")"); script += wxT("wx.wxMessageBox(msg, \"About wxLua Embedded\", wx.wxOK + wx.wxICON_INFORMATION)"); interpreter.RunString(script); // Equivalent code //wxString msg; //msg.Printf( _T("This is the About dialog of the minimal sample.\n") // _T("Welcome to %s"), wxVERSION_STRING); //wxMessageBox(msg, _T("About Minimal"), wxOK | wxICON_INFORMATION, this); } --- NEW FILE: wxledit.h --- ///////////////////////////////////////////////////////////////////////////// // Name: wxledit.h // Purpose: A shell, editor and IDE widget for wxLua // Author: John Labenski // Modified by: // Created: 11/05/2002 // Copyright: (c) John Labenski // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_LUAEDITOR_H_ #define _WX_LUAEDITOR_H_ #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma interface "wxledit.h" #endif class WXDLLEXPORT wxMenu; class WXDLLEXPORT wxKeyEvent; class WXDLLEXPORT wxNotebook; class WXDLLEXPORT wxSplitterWindow; class WXDLLEXPORT wxToolBar; class WXDLLEXPORT wxLuaInterpreter; class WXDLLEXPORT wxLuaEvent; #include "wx/stedit/stedit.h" #include "wx/stedit/steshell.h" enum { // buttons ID_LUACON_LOAD_LUA = ID_STE__LAST + 1, ID_LUACON_SAVEAS_LUA, ID_LUACON_RUN_LUA, ID_LUACON_BREAK_LUA, ID_LUACON_SHOW_STACK, ID_LUACON_TOGGLE_BREAKPOINT, // windows ID_LUACON_EDITOR_NOTEBOOK, ID_LUACON_MSG_NOTEBOOK, ID_LUACON_SHELL, ID_LUACON_OUTPUT_WIN }; //----------------------------------------------------------------------------- // Events for the wxLuaShell and wxLuaConsole when a wxLua interpreter is // being created. You may intercept this event to adjust or run strings // to finish creating the wxLua interpreter. // // EVT_LUASHELL_wxLUA_CREATION(id, wxLuaEvent& fn) // EVT_LUACONSOLE_wxLUA_CREATION(id, wxLuaEvent& fn) //----------------------------------------------------------------------------- BEGIN_DECLARE_EVENT_TYPES() DECLARE_LOCAL_EVENT_TYPE(wxEVT_LUASHELL_wxLUA_CREATION, 7000) DECLARE_LOCAL_EVENT_TYPE(wxEVT_LUACONSOLE_wxLUA_CREATION, 7001) END_DECLARE_EVENT_TYPES() #define EVT_LUASHELL_wxLUA_CREATION(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUASHELL_wxLUA_CREATION, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), #define EVT_LUACONSOLE_wxLUA_CREATION(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_LUACONSOLE_wxLUA_CREATION, id, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) (wxNotifyEventFunction) (wxLuaEventFunction) & fn, (wxObject *) NULL ), //----------------------------------------------------------------------------- // wxLuaShell - a basic console type interactive interpreter widget //----------------------------------------------------------------------------- class WXDLLEXPORT wxLuaShell : public wxSTEditorShell { public : wxLuaShell( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("wxLuaShell")); virtual ~wxLuaShell(); // Get the interpreter this shell uses wxLuaInterpreter *GetLuaInterpreter() const { return m_luaInterpreter; } // Set this shell to use another interpreter, will delete it if !is_static // note shell has built in function virtual void SetLuaInterpreter(wxLuaInterpreter *interp, bool is_static); // Used to create/recreate local interpreter // Can be subclassed to use your own interpreter derived from a wxLuaInterpreter // or a new interpreter can be set in by catching the wxEVT_LUASHELL_wxLUA_CREATION // wxLuaEvent that's sent with this control's id and *this as the GetEventObject // the preferred window ID is in event.GetExtraLong() // if you call event.SetLuaInterpreter(new wxLuaInterpreter(...)) // and event.SetInt(1 for static interpreter or 0 for not static) // then SetLuaIntpreter(event.GetLuaInterpreter(), event.GetInt() == 1) // is called. You'll probably want to set the lua interpreter's eventhandler // to this as well as it's win id virtual bool RecreateLuaInterpreter(wxEvtHandler *evtHandler, int win_id); // Run a string, append the string if append_text bool RunString(const wxString& string, bool append_text = false); // implementation void OnSTEEvent(wxSTEditorEvent& event); void OnLua(wxLuaEvent& event); protected: wxLuaInterpreter *m_luaInterpreter; bool m_luaInterpreter_static; private: void Init(); DECLARE_EVENT_TABLE(); DECLARE_CLASS(wxLuaShell); }; //----------------------------------------------------------------------------- // wxLuaEditor - a notebook page for editing a lua program //----------------------------------------------------------------------------- class WXDLLEXPORT wxLuaEditor : public wxSTEditor { public : wxLuaEditor(wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxT("wxLuaEditor")); virtual ~wxLuaEditor() {} enum mark_Type { marginError = STE_MARGIN_MARKER, marginBreak = STE_MARGIN_MARKER, markerError = 2, markerBreak = 3 }; void ClearBreakpoints(); bool HasBreakpoint(int line); // if line = -1 means has any breakpoints void AddBreakpoint(int line); void DeleteBreakpoint(int line); // implementation void OnMenu(wxCommandEvent& event); void OnMarginClick( wxStyledTextEvent &event ); private: DECLARE_EVENT_TABLE(); DECLARE_CLASS(wxLuaEditor); }; //----------------------------------------------------------------------------- // wxLuaConsole - toolbar at the top for open/save/run/stop lua programs // notebook with editors for editing lua programs // notebook with a console and an output window for above editors //----------------------------------------------------------------------------- enum wxLuaConsole_Styles { LUACON_TB_FILE = 0x0001, LUACON_TB_LUA = 0x0002, LUACON_TOOLBAR = LUACON_TB_FILE|LUACON_TB_LUA, LUACON_DEFAULT = LUACON_TOOLBAR }; class WXDLLEXPORT wxLuaConsole : public wxWindow { public: wxLuaConsole() : wxWindow() { Init(); } wxLuaConsole( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, long options = LUACON_DEFAULT, const wxString& name = wxT("wxLuaConsole")) : wxWindow() { Init(); Create(parent, id, pos, size, style, options, name); } bool Create( wxWindow *parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0, long options = LUACON_DEFAULT, const wxString& name = wxT("wxLuaConsole")); virtual ~wxLuaConsole(); // Get the interpreter this shell uses wxLuaInterpreter *GetLuaInterpreter() const { return m_luaInterpreter; } // Set this shell to use another interpreter, will delete it if !is_static // note shell has built in function virtual void SetLuaInterpreter(wxLuaInterpreter *interp, bool is_static); // Used to create/recreate local interpreter // Can be subclassed to use your own interpreter derived from a wxLuaInterpreter // or a new interpreter can be set in by catching the wxEVT_LUASHELL_wxLUA_CREATION // wxLuaEvent that's sent with this control's id and *this as the GetEventObject // the preferred window ID is in event.GetExtraLong() // if you call event.SetLuaInterpreter(new wxLuaInterpreter(...)) // and event.SetInt(1 for static interpreter or 0 for not static) // then SetLuaIntpreter(event.GetLuaInterpreter(), event.GetInt() == 1) // is called. You'll probably want to set the lua interpreter's eventhandler // to this as well as it's win id virtual bool RecreateLuaInterpreter(wxEvtHandler *evtHandler, int win_id); virtual void OutputLuaEvent(wxLuaEvent &event, wxLuaShell *outputWin); wxSplitterWindow *GetSplitterWin() const { return m_splitter; } wxSTEditorNotebook *GetEditorNotebook() const { return m_editorNotebook; } wxSTEditorNotebook *GetMsgNotebook() const { return m_msgNotebook; } wxLuaShell *GetLuaOutputWin() const { return m_luaOutput; } wxLuaShell *GetLuaShellWin() const { return m_luaShell; } // don't take ownership, just use void SetMenuBar(wxMenuBar *menuBar); wxMenuBar* GetMenuBar() const { return m_editorOptions.GetMenuBar(); } // may be NULL // don't take ownership, just use void SetToolBar(wxToolBar *toolbar); wxToolBar *GetToolBar() const { return m_editorOptions.GetToolBar(); } // may be NULL void PopulateToolBar(wxToolBar *toolBar, long options = LUACON_TOOLBAR); void EnableTool(int tool_id, bool enable); // implementation void OnMenu(wxCommandEvent &event); void OnLua(wxLuaEvent &event); void OnCreateEditor(wxCommandEvent &event); protected: virtual void DoSetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); wxLuaInterpreter *m_luaInterpreter; bool m_luaInterpreter_static; wxSplitterWindow *m_splitter; wxSTEditorNotebook *m_editorNotebook; wxSTEditorNotebook *m_msgNotebook; wxLuaShell *m_luaOutput; wxLuaShell *m_luaShell; wxToolBar *m_toolBar; wxSTEditorOptions m_editorOptions; wxSTEditorOptions m_shellOptions; long m_options; private: bool m_show_stack; void Init(); DECLARE_EVENT_TABLE(); DECLARE_DYNAMIC_CLASS(wxLuaConsole); }; #endif // _WX_LUAEDITOR_H_ --- NEW FILE: Makefile --- # File: Makefile # Author: John Labenski, J Winwood # Created: 2004 # Updated: # Copyright: (c) 2002. J Winwood # # Makefile for wxLuaEditor app using gmake # --- wxLua parameters ------------------------------------------------------- WXLUA_LIBVERSION_CURRENT = 1 WXLUA_LIBVERSION_REVISION = 5 WXLUA_LIBVERSION_AGE = 0 WXLUA_DIR = ../../.. WXLUA_LIBDIR = $(WXPREFIX)/lib LUA = $(WXLUA_DIR)/bin/lua # ---------------------------------------------------------------------------- # --- wxWidgets parameters from wx-config ------------------------------------ WXCONFIG := wx-config WXPREFIX = $(shell $(WXCONFIG) --prefix) WXBASENAME = $(shell $(WXCONFIG) --basename) WXVERSION = $(shell $(WXCONFIG) --version) WXRELEASE = $(shell $(WXCONFIG) --release) WXCXXFLAGS = $(shell $(WXCONFIG) --cxxflags) WXLDLIBS = $(shell $(WXCONFIG) --libs) WXCXX = $(shell $(WXCONFIG) --cxx) WXLIB_DIR = $(WXPREFIX)/lib # ---------------------------------------------------------------------------- CXXFLAGS = $(WXCXXFLAGS) -MMD -g -Wall LDLIBS = $(WXLDLIBS) CXX = $(WXCXX) PROGRAM = wxLuaEditor LUA_LIBS = $(WXLUA_DIR)/lib/liblua.a $(WXLUA_DIR)/lib/liblualib.a WXLUA_LIB = $(WXBASENAME)_wxlua-$(WXRELEASE) WXLUADEBUG_LIB = $(WXBASENAME)_wxluadebug-$(WXRELEASE) WXLUASOCKET_LIB = $(WXBASENAME)_wxluasocket-$(WXRELEASE) WXLUABIND_LIB = $(WXBASENAME)_wxluabind-$(WXRELEASE) WXSTC_LIB = $(WXBASENAME)_stc-$(WXRELEASE) WXXRC_LIB = $(WXBASENAME)_xrc-$(WXRELEASE) WXFL_LIB = $(WXBASENAME)_fl-$(WXRELEASE) # The wxSTEditor library name compiled from wxCode/components/wxstedit WXSTEDIT_LIB = $(WXBASENAME)_stedit-$(WXRELEASE) APPEXTRADEFS=-I$(WXCODE)/components/wxstedit/include -I$(WXLUA_DIR)/modules -I$(WXPREFIX)/contrib/include -fexceptions -DLUACALL= # This will build a static wxLua app, staticly linked to .a libs #APPEXTRALIBS=-L$(WXLIB_DIR) $(WXLIB_DIR)/lib$(WXLUA_LIB).a $(WXLIB_DIR)/lib$(STC_LIB).a $(WXLIB_DIR)/lib$(WXXRC_LIB).a $(WXLIB_DIR)/lib$(WXFL_LIB).a $(LUA_LIBS) # This will build a shared wxLua app, dynamicly linked to .so libs # -l$(WXFL_LIB) APPEXTRALIBS=-L$(WXLIB_DIR) -L$(WXLUA_LIBDIR) -l$(WXSTEDIT_LIB) -l$(WXLUA_LIB) -l$(WXLUADEBUG_LIB) -l$(WXLUASOCKET_LIB) -l$(WXSTC_LIB) -l$(WXXRC_LIB) $(LUA_LIBS) -l$(WXLUABIND_LIB) OBJECTS = wxluaedit.o wxledit.o DEPFILES = $(OBJECTS:.o=.d) .cpp.o: $(CXX) -c $(CXXFLAGS) $(APPEXTRADEFS) -o $@ $< all: lua wxLuaLib wxLuaDebugLib wxLuaSocketLib wxLuaBindings $(PROGRAM) $(PROGRAM): $(OBJECTS) $(LUA_LIBS) $(CXX) -o $@ $(OBJECTS) $(LDLIBS) $(APPEXTRALIBS) lua: @(cd $(WXLUA_DIR)/modules/lua && make) bindings: @(cd $(WXLUA_DIR)/bindings/wxwidgets && make) editor: $(LUA) $(WXLUA_DIR)/util/bin2c/bin2c.lua -t $(WXLUA_DIR)/samples/editor.wx.lua wxLuaEditor > editor.h wxLuaBindings: @(cd $(WXLUA_DIR)/modules/wxbind/src && make) wxLuaLib: @(cd $(WXLUA_DIR)/modules/wxlua/src && make) wxLuaDebugLib: @(cd $(WXLUA_DIR)/modules/wxluadebug/src && make) wxLuaSocketLib: @(cd $(WXLUA_DIR)/modules/wxluasocket/src && make) clean: rm -f $(OBJECTS) $(DEPFILES) $(PROGRAM) core cleanall: rm -f $(OBJECTS) $(DEPFILES) $(PROGRAM) core @(cd $(WXLUA_DIR)/modules/lua && make clean) @(cd $(WXLUA_DIR)/bindings/wxwidgets && make clean) @(cd $(WXLUA_DIR)/modules/wxbind/src && make clean) @(cd $(WXLUA_DIR)/modules/wxlua/src && make clean) @(cd $(WXLUA_DIR)/modules/wxluadebug/src && make clean) @(cd $(WXLUA_DIR)/modules/wxluasocket/src && make clean) -include $(DEPFILES) --- NEW FILE: wxledit.cpp --- ///////////////////////////////////////////////////////////////////////////// // Name: wxledit.cpp // Purpose: Different editors, consoles for wxLua // Author: John Labenski // Modified by: // Created: 11/05/2002 // RCS-ID: // Copyright: (c) John Labenski // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "wxledit.h" #endif // For compilers that support precompilation, includes "wx/wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif // WX_PRECOMP #include "wx/filename.h" #include "wx/splitter.h" #include "wxledit.h" #include "wxlua/include/interp.h" #include "wxluadebug/include/staktree.h" #include "wxluadebug/include/debug.h" #include "../../../art/wxlua.xpm" #include "../../../art/open.xpm" #include "../../../art/save.xpm" #include "../../../art/play.xpm" #include "../../../art/stop.xpm" #define STC_DEF_MARGIN_WIDTH 16 DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUASHELL_wxLUA_CREATION) DEFINE_LOCAL_EVENT_TYPE(wxEVT_LUACONSOLE_wxLUA_CREATION) //----------------------------------------------------------------------------- // wxLuaShell //----------------------------------------------------------------------------- IMPLEMENT_CLASS(wxLuaShell, wxSTEditorShell) BEGIN_EVENT_TABLE(wxLuaShell, wxSTEditorShell) EVT_STESHELL_ENTER ( wxID_ANY, wxLuaShell::OnSTEEvent ) EVT_LUA_CONSOLE ( wxID_ANY, wxLuaShell::OnLua ) EVT_LUA_WARNING ( wxID_ANY, wxLuaShell::OnLua ) EVT_LUA_ERROR ( wxID_ANY, wxLuaShell::OnLua ) END_EVENT_TABLE() void wxLuaShell::Init() { m_luaInterpreter = NULL; m_luaInterpreter_static = false; } wxLuaShell::wxLuaShell(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) { Init(); wxSTEditorShell::Create(parent, id, pos, size, style, name); SetFileName(name, false); SetLanguage(wxT("a.lua")); } wxLuaShell::~wxLuaShell() { if (m_luaInterpreter && !m_luaInterpreter_static) delete m_luaInterpreter; } void wxLuaShell::SetLuaInterpreter(wxLuaInterpreter *interp, bool is_static) { if (m_luaInterpreter && !m_luaInterpreter_static) { if (m_luaInterpreter->Ok() && m_luaInterpreter->IsRunning()) m_luaInterpreter->Break(); delete m_luaInterpreter; } m_luaInterpreter = interp; m_luaInterpreter_static = is_static; } bool wxLuaShell::RecreateLuaInterpreter(wxEvtHandler *evtHandler, int win_id) { wxLuaEvent event(wxEVT_LUASHELL_wxLUA_CREATION, GetId(), NULL); event.SetEventObject(this); event.SetInt(0); event.SetExtraLong(win_id); GetEventHandler()->ProcessEvent( event ); if (event.GetLuaInterpreter() != NULL) { SetLuaInterpreter(event.GetLuaInterpreter(), event.GetInt() == 1); return true; } wxLuaInterpreter *interp = new wxLuaInterpreter(evtHandler, win_id); interp->SetLuaDebugHook( 1000, 50, false, LUA_MASKCOUNT ); SetLuaInterpreter(interp, false); return true; } bool wxLuaShell::RunString(const wxString& string, bool append_text) { bool ret = false; if (string.IsEmpty()) return ret; if (append_text) { if (!GetLine(GetLineCount()).IsEmpty()) AppendText(wxT("\n")); AppendText(string); } AppendText(wxT("\n")); // restart the interpreter if (string == wxT("reset")) { if (m_luaInterpreter_static) { AppendText(wxT("Unable to reset lua, interpreter locked by another process.\n")); } else { if (RecreateLuaInterpreter(GetEventHandler(), GetId())) { AppendText(wxT("Sucessfully reset interpreter.\n")); ret = true; } else AppendText(wxT("Unsucessfully reset interpreter.\n")); } } else if (m_luaInterpreter) ret = m_luaInterpreter->RunString(string) == 0; else AppendText(wxT("The lua interpreter is not available - try running 'reset'.\n")); CheckPrompt(true); return ret; } void wxLuaShell::OnSTEEvent(wxSTEditorEvent& event) { event.Skip(); if (event.GetEventType() == wxEVT_STESHELL_ENTER) RunString(event.GetString(), false); } void wxLuaShell::OnLua(wxLuaEvent &event) { if (event.GetEventType() == wxEVT_LUA_CONSOLE) { AppendText(event.GetString() + wxT("\n")); } else if (event.GetEventType() == wxEVT_LUA_WARNING) { AppendText(wxT("\nWarning: ") + event.GetString() + wxT("\n")); } else if (event.GetEventType() == wxEVT_LUA_ERROR) { AppendText(wxT("\nErr: ") + event.GetString() + wxT("\n")); } else event.Skip(); } //----------------------------------------------------------------------------- // wxLuaEditor //----------------------------------------------------------------------------- IMPLEMENT_CLASS(wxLuaEditor, wxSTEditor) BEGIN_EVENT_TABLE(wxLuaEditor, wxSTEditor) EVT_STC_MARGINCLICK(wxID_ANY, wxLuaEditor::OnMarginClick) EVT_MENU(ID_LUACON_TOGGLE_BREAKPOINT, wxLuaEditor::OnMenu) END_EVENT_TABLE() wxLuaEditor::wxLuaEditor(wxWindow *parent, int id, const wxPoint& pos, const wxSize& size, long style, const wxString& name) : wxSTEditor() { wxSTEditor::Create(parent, id, pos, size, style, name); SetVisiblePolicy(wxSTC_VISIBLE_SLOP, 3); SetXCaretPolicy(wxSTC_CARET_SLOP, 10); SetYCaretPolicy(wxSTC_CARET_SLOP, 3); // click on margin to set breakpoint // wxSTC_MARK_CIRCLE MarkerDefine(markerBreak, wxSTC_MARK_SMALLRECT, *wxBLACK, *wxRED); MarkerDefine(markerError, wxSTC_MARK_SHORTARROW, *wxBLACK, *wxRED); SetMarginSensitive(marginBreak, true); SetMarginType(marginError, wxSTC_MARGIN_SYMBOL); SetMarginWidth(marginError, STC_DEF_MARGIN_WIDTH); //SetMarginMask(marginError, (1<<markerError)|(1<<markerBreak)|(1<<STE_BOOKMARK_MARKER)); SetFileName(wxT("untitled.lua")); SetLanguage(wxT("untitled.lua")); } void wxLuaEditor::OnMenu(wxCommandEvent& event) { int line = LineFromPosition(GetInsertionPoint()); switch (event.GetId()) { case ID_LUACON_TOGGLE_BREAKPOINT : { if (HasBreakpoint(line)) DeleteBreakpoint(line); else AddBreakpoint(line); return; } } event.Skip(); } void wxLuaEditor::OnMarginClick( wxStyledTextEvent &event ) { // unfortunately we can't get right or double clicks event.Skip(); //int line = event.GetLine(); - not implemented //wxPrintf(wxT("Margin line %d %d %d %d %d\n"), line, event.GetLine(), MarkerGet(line), event.GetModifiers(), event.GetKey()); fflush(stdout); } bool wxLuaEditor::HasBreakpoint(int line) { if (line < 0) return MarkerNext(markerBreak, 1<<markerBreak) >= 0; return (MarkerGet(line) & (1<<markerBreak)) != 0; } void wxLuaEditor::ClearBreakpoints() { MarkerDeleteAll(markerBreak); } void wxLuaEditor::AddBreakpoint(int line) { if (HasBreakpoint(line) || (line<0) || (line>GetLineCount())) return; (void)MarkerAdd(line, markerBreak); } void wxLuaEditor::DeleteBreakpoint(int line) { if (!HasBreakpoint(line)) return; MarkerDelete(line, markerBreak); } //----------------------------------------------------------------------------- // wxLuaConsole //----------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxLuaConsole, wxWindow); BEGIN_EVENT_TABLE(wxLuaConsole, wxWindow) EVT_MENU(ID_LUACON_LOAD_LUA, wxLuaConsole::OnMenu) EVT_MENU(ID_LUACON_SAVEAS_LUA, wxLuaConsole::OnMenu) EVT_MENU(ID_LUACON_RUN_LUA, wxLuaConsole::OnMenu) EVT_MENU(ID_LUACON_BREAK_LUA, wxLuaConsole::OnMenu) EVT_MENU(ID_LUACON_SHOW_STACK, wxLuaConsole::OnMenu) EVT_STS_CREATE_EDITOR(wxID_ANY, wxLuaConsole::OnCreateEditor) EVT_LUA_CONSOLE (wxID_ANY, wxLuaConsole::OnLua) EVT_LUA_WARNING (wxID_ANY, wxLuaConsole::OnLua) EVT_LUA_ERROR (wxID_ANY, wxLuaConsole::OnLua) EVT_LUA_DEBUG_HOOK (wxID_ANY, wxLuaConsole::OnLua) EVT_LUA_SHUTDOWN (wxID_ANY, wxLuaConsole::OnLua) END_EVENT_TABLE() void wxLuaConsole::Init() { m_luaInterpreter = NULL; m_luaInterpreter_static = false; m_splitter = NULL; m_editorNotebook = NULL; m_msgNotebook = NULL; m_luaOutput = NULL; m_luaShell = NULL; m_toolBar = NULL; m_options = 0; m_show_stack = false; } bool wxLuaConsole::Create( wxWindow *parent, int id, const wxPoint& pos, const wxSize& size, long style, long options, const wxString& name) { m_options = options; if (!wxWindow::Create(parent, id, pos, size, style, name)) return false; if ((m_options & LUACON_TOOLBAR) != 0) { m_toolBar = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize); PopulateToolBar(m_toolBar, m_options); EnableTool(ID_LUACON_BREAK_LUA, false); } m_splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxSize(200,400)); // Create the editor notebook m_editorOptions = wxSTEditorOptions(STE_DEFAULT_OPTIONS); m_editorOptions.SetToolBar(m_toolBar); // NULL is fine m_editorOptions.SetDefaultFileName(wxT("untitled.lua")); m_editorNotebook = new wxSTEditorNotebook(m_splitter, ID_LUACON_EDITOR_NOTEBOOK, wxDefaultPosition, wxSize(200,200), wxCLIP_CHILDREN); m_editorNotebook->CreateOptions(m_editorOptions); m_editorNotebook->InsertEditorSplitter(-1, wxID_ANY, wxT("untitled.lua"), true); m_editorNotebook->GetEditor()->MarkerDefine(wxLuaEditor::markerBreak, wxSTC_MARK_SMALLRECT, *wxBLACK, *wxRED); m_editorNotebook->GetEditor()->MarkerDefine(wxLuaEditor::markerError, wxSTC_MARK_SHORTARROW, *wxBLACK, *wxRED); wxMenu *breakPointMenu = new wxMenu; breakPointMenu->Append(ID_LUACON_TOGGLE_BREAKPOINT, wxT("&Toggle breakpoint")); m_editorOptions.GetEditorPopupMenu()->AppendSeparator(); m_editorOptions.GetEditorPopupMenu()->Append(wxID_ANY, wxT("Breakpoints"), breakPointMenu); // Create the message notebook for shell and output window m_shellOptions.SetSplitterOptions(STS_NO_EDITOR); m_shellOptions.SetEditorStyles(m_editorOptions.GetEditorStyles()); m_shellOptions.SetEditorLangs(m_editorOptions.GetEditorLangs()); m_shellOptions.SetMenuManager(m_editorOptions.GetMenuManager(), true); m_shellOptions.SetEditorPopupMenu(wxSTEditorMenuManager(0, 0, STE_MENU_EDIT_CUTCOPYPASTE).CreateEditMenu(), false); m_shellOptions.SetToolBar(m_toolBar); m_msgNotebook = new wxSTEditorNotebook(m_splitter, ID_LUACON_MSG_NOTEBOOK, wxDefaultPosition, wxSize(200,200), wxCLIP_CHILDREN); m_msgNotebook->CreateOptions(m_shellOptions); wxSTEditorSplitter *splitter = new wxSTEditorSplitter(m_msgNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D); splitter->CreateOptions(m_shellOptions); m_luaShell = new wxLuaShell(splitter, ID_LUACON_SHELL, wxDefaultPosition, wxSize(200,200), 0); m_luaShell->CreateOptions(m_shellOptions); m_luaShell->SetWrapMode(wxSTC_WRAP_WORD); m_luaShell->RecreateLuaInterpreter(m_luaShell->GetEventHandler(), m_luaShell->GetId()); m_luaShell->CheckPrompt(true); splitter->Initialize(m_luaShell); m_msgNotebook->InsertEditorSplitter(-1, splitter, true); splitter = new wxSTEditorSplitter(m_msgNotebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D); splitter->CreateOptions(m_shellOptions); m_luaOutput = new wxLuaShell(splitter, ID_LUACON_OUTPUT_WIN, wxDefaultPosition, wxSize(200,200), 0); m_luaOutput->CreateOptions(m_shellOptions); splitter->Initialize(m_luaOutput); m_luaOutput->MarkerDeleteAll(wxLuaShell::markerPrompt); m_luaOutput->SetLuaInterpreter(m_luaInterpreter, true); m_luaOutput->SetWrapMode(wxSTC_WRAP_NONE); m_luaOutput->SetFileName(wxT("Output")); m_msgNotebook->InsertEditorSplitter(-1, splitter, false); m_splitter->SetSashGravity(0.8); // let upper window grow more m_splitter->SetMinimumPaneSize(50); m_splitter->SplitHorizontally(m_editorNotebook, m_msgNotebook, GetClientSize().y/2); //RecreateLuaInterpreter(GetEventHandler(), m_editorNotebook->GetPage(0)->GetId()); return true; } wxLuaConsole::~wxLuaConsole() { delete m_luaInterpreter; } void wxLuaConsole::SetMenuBar(wxMenuBar *menuBar) { m_editorOptions.SetMenuBar(menuBar); m_shellOptions.SetMenuBar(menuBar); } void wxLuaConsole::SetToolBar(wxToolBar *toolBar) { m_editorOptions.SetToolBar(toolBar); m_shellOptions.SetToolBar(toolBar); m_toolBar = toolBar; if (!m_luaInterpreter || !m_luaInterpreter->IsRunning()) EnableTool(ID_LUACON_BREAK_LUA, false); } void wxLuaConsole::PopulateToolBar(wxToolBar *toolBar, long options) { bool add_sep = false; if ((options & LUACON_TB_FILE) != 0) { toolBar->AddTool( ID_LUACON_LOAD_LUA, wxT("Open file"), wxBitmap(open_xpm), wxT("Open lua program") ); toolBar->AddTool( ID_LUACON_SAVEAS_LUA, wxT("Save as..."), wxBitmap(save_xpm), wxT("Save lua program") ); add_sep = true; } if ((options & LUACON_TB_LUA) != 0) { if (add_sep) toolBar->AddSeparator(); toolBar->AddTool( ID_LUACON_RUN_LUA, wxT("Run Lua"), wxBitmap(play_xpm), wxT("Run the lua program") ); toolBar->AddTool( ID_LUACON_BREAK_LUA, wxT("Stop Lua"), wxBitmap(stop_xpm), wxT("Stop the running lua program") ); toolBar->AddSeparator(); toolBar->AddTool( ID_LUACON_SHOW_STACK, wxT("Stack Tree"), wxBitmap(LUA_xpm), wxT("Show the lua stack tree") ); } toolBar->Realize(); } void wxLuaConsole::EnableTool(int tool_id, bool enable) { wxSTEditorMenuManager::DoEnableItem(NULL, NULL, GetToolBar(), tool_id, enable); } void wxLuaConsole::SetLuaInterpreter(wxLuaInterpreter *interp, bool is_static) { if (m_luaInterpreter && !m_luaInterpreter_static) { if (m_luaInterpreter->Ok() && m_luaInterpreter->IsRunning()) m_luaInterpreter->Break(); delete m_luaInterpreter; } m_luaInterpreter = interp; m_luaInterpreter_static = is_static; } bool wxLuaConsole::RecreateLuaInterpreter(wxEvtHandler *evtHandler, int win_id) { wxLuaEvent event(wxEVT_LUACONSOLE_wxLUA_CREATION, GetId(), NULL); event.SetEventObject(this); event.SetInt(0); event.SetExtraLong(win_id); GetEventHandler()->ProcessEvent( event ); if (event.GetLuaInterpreter() != NULL) { SetLuaInterpreter(event.GetLuaInterpreter(), event.GetInt() == 1); return true; } wxLuaInterpreter *interp = new wxLuaInterpreter(evtHandler, win_id); interp->SetLuaDebugHook( 1000, 50, false, LUA_MASKCOUNT ); SetLuaInterpreter(interp, false); return true; } void wxLuaConsole::OnCreateEditor(wxCommandEvent &event) { wxWindow *win = (wxWindow*)event.GetEventObject(); wxLuaEditor *editor = new wxLuaEditor(win, event.GetInt(), wxDefaultPosition, wxDefaultSize, 0); editor->CreateOptions(m_editorOptions); event.SetEventObject(editor); } void wxLuaConsole::DoSetSize(int x, int y, int width, int height, int sizeFlags) { wxWindow::DoSetSize(x, y, width, height, sizeFlags); wxSize clientSize(GetClientSize()); if (width == -1) width = clientSize.x; if (height == -1) height = clientSize.y; int h = 0; if (m_toolBar && (m_toolBar->GetParent() == this)) { m_toolBar->SetSize(0, 1, width, -1); // y = 1 for wxGTK 2 at least h = m_toolBar->GetSize().y + 1; // another +1 for bottom for wxGTK2 } if (m_splitter) { m_splitter->SetSize(0, h, width, height-h); int sash = m_splitter->GetSashPosition(); if ((sash < 50) || (sash > height - 50)) m_splitter->SetSashPosition(wxMin(50, height/2)); } } void wxLuaConsole::OnMenu(wxCommandEvent &event) { wxLuaEditor *editor = wxDynamicCast(m_editorNotebook->GetEditor(), wxLuaEditor); wxCHECK_RET(editor, wxT("Invalid notebook page")); switch(event.GetId()) { case ID_LUACON_LOAD_LUA : { wxString filename = editor->GetFileName(); wxString path; if (!filename.IsEmpty()) { wxFileName fn(filename); path = fn.GetPath(); filename = fn.GetFullName(); } wxFileDialog dlg(this, wxT("Open file"), path, filename, wxT("Lua (*.lua)|*.lua|Any file (*)|*"), wxOPEN|wxFILE_MUST_EXIST); if (dlg.ShowModal() != wxID_OK) return; filename = dlg.GetPath(); if (!filename.IsEmpty()) editor->LoadFile(filename); break; } case ID_LUACON_SAVEAS_LUA : { editor->SaveFile(true); break; } case ID_LUACON_RUN_LUA : { wxString program = editor->GetText(); if (program.IsEmpty()) break; if (m_luaInterpreter) { wxCHECK_RET(m_luaInterpreter->Destroy(false), wxT("Can't destroy lua interpreter")); } // Fresh start! wxCHECK_RET(RecreateLuaInterpreter(GetEventHandler(), editor->GetId()), wxT("Can't recreate lua interpreter")); EnableTool(ID_LUACON_RUN_LUA, false); EnableTool(ID_LUACON_BREAK_LUA, true); EnableTool(ID_LUACON_SHOW_STACK, false); editor->MarkerDeleteAll(wxLuaEditor::markerError); m_luaOutput->SetReadOnly(false); m_luaOutput->ClearAll(); m_luaOutput->MarkerDeleteAll(wxLuaShell::markerPrompt); m_luaOutput->AppendText(wxT("Running lua script : ") + wxNow() + wxT("\n")); wxStopWatch stopWatch; //m_luaOutput->SetReadOnly(true); wxSafeYield(); // allow tools to adjust (sometimes necessary?) m_luaOutput->SetLuaInterpreter(m_luaInterpreter, true); if (editor->HasBreakpoint(-1)) m_luaInterpreter->SetLuaDebugHook(1, 50, true, LUA_MASKLINE); else m_luaInterpreter->SetLuaDebugHook(100, 50, false); m_luaOutput->SetReadOnly(true); editor->SetReadOnly(true); m_luaInterpreter->RunString(program); editor->SetReadOnly(false); m_luaOutput->SetReadOnly(false); m_luaOutput->AppendText(wxT("End lua script : ") + wxNow() + wxT("\n")); m_luaOutput->AppendText(wxString::Format(wxT("Execution time : %.3lf(s)\n"), stopWatch.Time()/1000.0)); m_luaOutput->CheckPrompt(true); EnableTool(ID_LUACON_RUN_LUA, true); EnableTool(ID_LUACON_BREAK_LUA, false); EnableTool(ID_LUACON_SHOW_STACK, true); // don't delete it since it may "exist" as a frame or something // also allows for showing stack frame //if (m_luaInterpreter) { delete m_luaInterpreter; m_luaInterpreter = NULL; } break; } case ID_LUACON_BREAK_LUA : { if (m_luaInterpreter && m_luaInterpreter->IsRunning()) { m_luaInterpreter->Break(wxT("Interpreter stopped")); } else if (m_luaShell->GetLuaInterpreter() && m_luaShell->GetLuaInterpreter()->IsRunning()) { m_luaShell->GetLuaInterpreter()->Break(wxT("Interpreter stopped")); } break; } case ID_LUACON_SHOW_STACK : { m_show_stack = true; // don't want recursive wxYields if some other interpreter is running bool err = true; wxLuaInterpreter *luaInterp = NULL; wxLuaShell *luaShell = NULL; if (m_msgNotebook->GetSelection() == 0) { luaInterp = m_luaShell ? m_luaShell->GetLuaInterpreter() : NULL; luaShell = m_luaShell; } else { luaInterp = m_luaInterpreter; luaShell = m_luaOutput; } if (luaShell && luaInterp) { int hook_count = luaInterp->GetLuaDebugHookCount(); int hook_yield = luaInterp->GetLuaDebugHookYield(); bool hook_send = luaInterp->GetLuaDebugHookSendEvt(); int hook_mask = luaInterp->GetLuaDebugHook(); luaInterp->SetLuaDebugHook(1, -1, true); luaInterp->RunString(wxT("print(\"Showing stack\")\n")); luaInterp->SetLuaDebugHook(hook_count, hook_yield, hook_send, hook_mask); luaShell->CheckPrompt(true); err = false; } if (err) wxMessageBox(wxT("Invalid lua interpreter."), wxT("Error showing stack"), wxOK, this); break; } default : break; } } void wxLuaConsole::OnLua(wxLuaEvent &event) { wxLuaShell *outEditor = NULL; if (event.GetLuaInterpreter() == m_luaInterpreter) outEditor = m_luaOutput; else if (event.GetLuaInterpreter() == m_luaShell->GetLuaInterpreter()) outEditor = m_luaShell; OutputLuaEvent(event, outEditor); } void wxLuaConsole::OutputLuaEvent(wxLuaEvent &event, wxLuaShell *outEditor) { // perhaps there was an error at startup, but editor isn't created yet if (outEditor == NULL) { return; } if (event.GetEventType() == wxEVT_LUA_DEBUG_HOOK) { if (m_show_stack) { wxLuaInterface luaInterface((lua_State*)event.GetLuaState()); wxLuaStackFrame StackFrame(this, wxT("wxLua stack frame"), wxDefaultPosition, wxSize(500, 250), &luaInterface); StackFrame.ShowModal(); m_show_stack = false; } else if (event.GetEventObject() == m_luaInterpreter) { wxLuaEditor *editor = wxDynamicCast(m_editorNotebook->FindWindow(event.GetId()), wxLuaEditor); //wxCHECK_RET(editor, wxT("Invalid notebook page")); if (editor != NULL) { int line = event.GetLineNum(); if (editor->HasBreakpoint(line-1)) m_luaInterpreter->Break(wxString::Format(wxT("Stopped at breakpoint, line: %d"), line)); } } } else if (event.GetEventType() == wxEVT_LUA_CONSOLE) { outEditor->AppendText(event.GetString() + wxT("\n")); } else if (event.GetEventType() == wxEVT_LUA_WARNING) { outEditor->AppendText(wxT("\nWarning: ") + event.GetString() + wxT("\n")); } else if (event.GetEventType() == wxEVT_LUA_ERROR) { outEditor->AppendText(wxT("\nErr: ") + event.GetString() + wxT("\n")); int line = event.GetLineNum(); // Put a marker where the error occurred if ((line >= 0) && (event.GetEventObject() == m_luaInterpreter)) { wxLuaEditor *editor = wxDynamicCast(m_editorNotebook->FindWindow(event.GetId()), wxLuaEditor); //wxCHECK_RET(editor, wxT("Invalid notebook page")); if (editor != NULL) { editor->MarkerDeleteAll(wxLuaEditor::markerError); editor->MarkerAdd(line-1, wxLuaEditor::markerError); editor->GotoLine(line-1); editor->EnsureCaretVisible(); } } } else if (event.GetEventType() == wxEVT_LUA_SHUTDOWN) { outEditor->AppendText(wxT("\nLua interpreter shutdown\n")); } } |