wxArt2D
wxledit.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wxledit.h
3 // Purpose: A shell, editor and IDE widget for wxLua
4 // Author: John Labenski
5 // Modified by:
6 // Created: 11/05/2002
7 // Copyright: (c) John Labenski
8 // Licence: wxWidgets licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_LUAEDITOR_H_
12 #define _WX_LUAEDITOR_H_
13 
14 #include "wxlua/wxlstate.h"
15 
16 class WXDLLIMPEXP_FWD_CORE wxMenu;
17 class WXDLLIMPEXP_FWD_CORE wxKeyEvent;
18 class WXDLLIMPEXP_FWD_CORE wxNotebook;
19 class WXDLLIMPEXP_FWD_CORE wxSplitterWindow;
20 class WXDLLIMPEXP_FWD_CORE wxToolBar;
21 class WXDLLIMPEXP_FWD_WXLUA wxLuaState;
22 class WXDLLIMPEXP_FWD_WXLUA wxLuaEvent;
23 class wxLuaIDE;
24 
25 // Note: If you get a compilation error on the next two lines you need to
26 // specify the #include path to the wxStEdit project that's part of wxCode.
27 #include "wx/stedit/stedit.h"
28 #include "wx/stedit/steshell.h"
29 
30 // For non-Unix systems (i.e. when building without a configure script),
31 // we use the following macro to do a compile-time check of wxLuaEdit version
32 #if !defined(wxCHECK_STE_VERSION)
33  #error "wxStEdit version is too old, need at least version 1.6.0"
34 #endif
35 #if !wxCHECK_STE_VERSION(1, 6, 0)
36  #error "wxStEdit version is too old, need at least version 1.6.0"
37 #endif
38 
39 //-----------------------------------------------------------------------------
40 
41 enum
42 {
43  // buttons
44  ID_WXLUAIDE_LOAD_LUA = ID_STE__LAST + 1,
45  ID_WXLUAIDE_SAVEAS_LUA,
46  ID_WXLUAIDE_RUN_LUA,
47  ID_WXLUAIDE_BREAK_LUA,
48  ID_WXLUAIDE_SHOW_STACK,
49 
50  ID_WXLUAIDE_TOGGLE_BREAKPOINT,
51 
52  // windows
53  ID_WXLUAIDE_EDITOR_NOTEBOOK,
54  ID_WXLUAIDE_MSG_NOTEBOOK,
55  ID_WXLUAIDE_SHELL,
56  ID_WXLUAIDE_OUTPUT_WIN,
57 
58  ID_WXLUAIDE__LAST
59 };
60 
61 //-----------------------------------------------------------------------------
62 // Events for the wxLuaShell and wxLuaIDE when a wxLua interpreter is
63 // being created. You may intercept this event to adjust or run strings
64 // to finish creating the wxLua interpreter.
65 //
66 // EVT_LUASHELL_wxLUA_CREATION(id, wxLuaEvent& fn)
67 // EVT_LUAIDE_wxLUA_CREATION(id, wxLuaEvent& fn)
68 //-----------------------------------------------------------------------------
69 
70 BEGIN_DECLARE_EVENT_TYPES()
71  DECLARE_LOCAL_EVENT_TYPE(wxEVT_LUASHELL_wxLUA_CREATION, 7000)
72  DECLARE_LOCAL_EVENT_TYPE(wxEVT_LUAIDE_wxLUA_CREATION, 7001)
73 END_DECLARE_EVENT_TYPES()
74 
75 #define EVT_LUASHELL_wxLUA_CREATION(id, fn) wx__DECLARE_WXLUAEVT(wxEVT_LUASHELL_wxLUA_CREATION, id, fn)
76 #define EVT_LUAIDE_wxLUA_CREATION(id, fn) wx__DECLARE_WXLUAEVT(wxEVT_LUAIDE_wxLUA_CREATION, id, fn)
77 
78 //-----------------------------------------------------------------------------
79 // wxLuaShell - a basic console type interactive interpreter widget
80 //-----------------------------------------------------------------------------
81 
82 class wxLuaShell : public wxSTEditorShell
83 {
84 public :
85  wxLuaShell() : wxSTEditorShell() { Init(); }
86 
87  wxLuaShell(wxWindow *parent, wxWindowID id,
88  const wxPoint& pos = wxDefaultPosition,
89  const wxSize& size = wxDefaultSize,
90  long style = 0,
91  const wxString& name = wxT("wxLuaShell")) : wxSTEditorShell()
92  {
93  Init();
94  Create(parent, id, pos, size, style, name);
95  }
96 
97  bool Create(wxWindow *parent, wxWindowID id,
98  const wxPoint& pos = wxDefaultPosition,
99  const wxSize& size = wxDefaultSize,
100  long style = 0,
101  const wxString& name = wxT("wxLuaShell"));
102 
103  virtual ~wxLuaShell();
104 
105  // Get the interpreter this shell uses
106  wxLuaState GetwxLuaState() const { return m_wxlState; }
107  // Set this shell to use another interpreter, will close it if !is_static
108  virtual void SetwxLuaState(const wxLuaState& wxlState, bool is_static);
109  // RecreatewxLuaState - Used to create/recreate local interpreter
110  // Can be subclassed to use your own interpreter derived from a wxLuaState.
111  //
112  // Using a customized wxLuaState by handling wxEVT_LUASHELL_wxLUA_CREATION event:
113  // The RecreatewxLuaState function sends a wxLuaEvent with this control's id
114  // in GetId(), *this as the GetEventObject(), and the preferred window ID
115  // for the new wxLuaState in event.GetExtraLong() (typically wxID_ANY) and
116  // the current wxLuaState in GetwxLuaState().
117  //
118  // Your wxEVT_LUASHELL_wxLUA_CREATION event handler can set the new wxLuaState
119  // by calling event.SetwxLuaState(wxLuaState(...))
120  // and event.SetInt(1 for static interpreter or 0 for not static), where
121  // static means that the wxLuaShell will not close the wxLuaState on exit.
122  // You'll probably want to set the new wxLuaState's eventhandler and id
123  // to that of this window so this can handle the events.
124  //
125  // If the event is skipped or not handled the RecreatewxLuaState function
126  // will call SetLuaIntpreter(event.GetLuaInterpreter(), event.GetInt() == 1)
127  // if the event's wxLuaState is valid. You can Skip(false) the event to
128  // not have the wxLuaState recreated at all.
129  virtual bool RecreatewxLuaState(wxEvtHandler *wxlStateEvtHandler, int win_id);
130 
131  // Run a string, append the string to the editor control if append_text
132  bool RunString(const wxString& string, bool append_text = false);
133 
134 
135  // Override wxSTEditor function to get autocomplete words.
136  virtual size_t DoGetAutoCompleteKeyWords(const wxString& root, wxArrayString& words);
137 
138  // implementation
139  void OnSTEEvent(wxSTEditorEvent& event);
140  void OnLua(wxLuaEvent& event);
141 
142  virtual void UpdateItems(wxMenu *menu, wxMenuBar *menuBar, wxToolBar *toolBar);
143 
144 protected:
145  wxLuaState m_wxlState;
146  bool m_wxlstate_static;
147 
148 private:
149  void Init();
150  DECLARE_EVENT_TABLE();
151  DECLARE_ABSTRACT_CLASS(wxLuaShell);
152 };
153 
154 //-----------------------------------------------------------------------------
155 // wxLuaEditor - a notebook page for editing a lua program
156 //-----------------------------------------------------------------------------
157 
158 class wxLuaEditor : public wxSTEditor
159 {
160 public :
161  wxLuaEditor() : wxSTEditor() { Init(); }
162 
163  wxLuaEditor(wxWindow *parent, wxWindowID id,
164  const wxPoint& pos = wxDefaultPosition,
165  const wxSize& size = wxDefaultSize,
166  long style = 0,
167  const wxString& name = wxT("wxLuaEditor")) : wxSTEditor()
168  {
169  Init();
170  Create(parent, id, pos, size, style, name);
171  }
172 
173  bool Create(wxWindow *parent, wxWindowID id,
174  const wxPoint& pos = wxDefaultPosition,
175  const wxSize& size = wxDefaultSize,
176  long style = 0,
177  const wxString& name = wxT("wxLuaEditor"));
178 
179  virtual ~wxLuaEditor() {}
180 
181  wxLuaIDE* GetwxLuaIDE() const { return m_wxluaIDE; }
182  void SetwxLuaIDE(wxLuaIDE* wxluaIDE) { m_wxluaIDE = wxluaIDE; }
183 
184  enum mark_Type
185  {
186  marginError = STE_MARGIN_MARKER,
187  marginBreak = STE_MARGIN_MARKER,
188 
189  markerError = STE_MARKER__MAX,
190  markerBreak
191  };
192 
193  void ClearBreakpoints();
194  bool HasBreakpoint(int line); // if line = -1 means has any breakpoints
195  void AddBreakpoint(int line);
196  void DeleteBreakpoint(int line);
197 
198  // implementation
199  void OnMenu(wxCommandEvent& event);
200  virtual bool HandleMenuEvent(wxCommandEvent& event);
201 
202  void OnMarginClick( wxStyledTextEvent &event );
203 
204  virtual void UpdateItems(wxMenu *menu, wxMenuBar *menuBar, wxToolBar *toolBar);
205 
206 protected:
207  wxLuaIDE* m_wxluaIDE;
208 
209 private:
210  void Init();
211  DECLARE_EVENT_TABLE();
212  DECLARE_ABSTRACT_CLASS(wxLuaEditor);
213 };
214 
215 //-----------------------------------------------------------------------------
216 // wxLuaIDE - toolbar at the top for open/save/run/stop lua programs
217 // notebook with editors for editing lua programs
218 // notebook with a console and an output window for above editors
219 //-----------------------------------------------------------------------------
220 
221 enum wxLuaIDE_Styles
222 {
223  WXLUAIDE_TB_FILE = 0x0001, // Add Open/Save items in PopulateToolBar
224  WXLUAIDE_TB_LUA = 0x0002, // Add Run/Stop/Stack Dlg in PopulateToolBar
225  WXLUAIDE_TOOLBAR = WXLUAIDE_TB_FILE|WXLUAIDE_TB_LUA,
226  WXLUAIDE_DEFAULT = WXLUAIDE_TOOLBAR
227 };
228 
229 class wxLuaIDE : public wxWindow
230 {
231 public:
232  wxLuaIDE() : wxWindow() { Init(); }
233  wxLuaIDE( wxWindow *parent, wxWindowID id,
234  const wxPoint& pos = wxDefaultPosition,
235  const wxSize& size = wxDefaultSize,
236  long style = 0,
237  long options = WXLUAIDE_DEFAULT,
238  const wxString& name = wxT("wxLuaIDE")) : wxWindow()
239  {
240  Init();
241  Create(parent, id, pos, size, style, options, name);
242  }
243 
244  bool Create( wxWindow *parent, wxWindowID id,
245  const wxPoint& pos = wxDefaultPosition,
246  const wxSize& size = wxDefaultSize,
247  long style = 0,
248  long options = WXLUAIDE_DEFAULT,
249  const wxString& name = wxT("wxLuaIDE"));
250 
251  virtual ~wxLuaIDE();
252 
253  // Get the interpreter this shell uses
254  wxLuaState GetwxLuaState() const { return m_wxlState; }
255  // Set this shell to use another interpreter, will delete it if !is_static
256  // note shell has built in function
257  void SetwxLuaState(const wxLuaState& wxlState, bool is_static);
258  // Used to create/recreate local interpreter
259  // Can be subclassed to use your own interpreter derived from a wxLuaState
260  // or a new interpreter can be set by catching the EVT_LUAIDE_wxLUA_CREATION
261  // wxLuaEvent that's sent with this control's id and *this as the GetEventObject
262  // the preferred window ID is in event.GetExtraLong()
263  // if you call event.SetLuaInterpreter(wxLuaState(...))
264  // and event.SetInt(1 for static interpreter or 0 for not static)
265  // then SetLuaIntpreter(event.GetLuaInterpreter(), event.GetInt() == 1)
266  // is called. You'll probably want to set the lua interpreter's eventhandler
267  // to this as well as it's win id
268  virtual bool RecreatewxLuaState(wxEvtHandler *wxlStateEvtHandler, int win_id);
269 
270  // Direct the string output of the wxLuaEvent to the given wxLuaShell
271  virtual void OutputLuaEvent(wxLuaEvent &event, wxLuaShell *outputWin);
272 
273  // Write the string to the given shell and make it visible if it's in the
274  // GetMsgNotebook.
275  virtual void WriteMessage(wxLuaShell *outputWin, const wxString& str);
276 
277  // Get or adjust the child windows of this control
278  wxSplitterWindow *GetSplitterWin() const { return m_splitter; }
279  wxSTEditorNotebook *GetEditorNotebook() const { return m_editorNotebook; }
280  wxSTEditorNotebook *GetMsgNotebook() const { return m_msgNotebook; }
281  wxLuaShell *GetLuaOutputWin() const { return m_luaOutput; }
282  wxLuaShell *GetLuaShellWin() const { return m_luaShell; }
283 
284  // doesn't take ownership of the menubar, updates it when focused
285  void SetMenuBar(wxMenuBar *menuBar);
286  wxMenuBar* GetMenuBar() const { return m_editorOptions.GetMenuBar(); } // may be NULL
287  // doesn't take ownership of the toolbar, updates it when focused
288  void SetToolBar(wxToolBar *toolbar);
289  wxToolBar *GetToolBar() const { return m_editorOptions.GetToolBar(); } // may be NULL
290  // add our own tools to the toolbar, see WXLUAIDE_TB_FILE, WXLUAIDE_TB_LUA
291  void PopulateToolBar(wxToolBar *toolBar, long options = WXLUAIDE_TOOLBAR) const;
292  // create a "new" wxMenu to add to the menubar and popupmenu
293  wxMenu* CreatewxLuaMenu() const;
294 
295  // implementation
296  void OnMenu(wxCommandEvent &event);
297  virtual bool HandleMenuEvent(wxCommandEvent& event);
298  void OnLua(wxLuaEvent &event);
299  void OnSize(wxSizeEvent& event);
300  void OnCreateEditor(wxCommandEvent &event);
301 
302 protected:
303 
304  wxLuaState m_wxlState;
305  bool m_wxlstate_static;
306 
307  wxSplitterWindow *m_splitter; // left/right splitter sidebar/notebook
308  wxSTEditorNotebook *m_editorNotebook;
309  wxSTEditorNotebook *m_msgNotebook; // bottom
310  wxLuaShell *m_luaOutput; // output of the editor program + shell
311  wxLuaShell *m_luaShell; // user interactive shell
312  wxToolBar *m_toolBar; // a toolbar that is a child of this
313  wxSTEditorOptions m_editorOptions;
314  wxSTEditorOptions m_shellOptions;
315 
316  long m_options;
317 
318  wxSTERecursionGuardFlag m_rGuard_OnMenu;
319  wxSTERecursionGuardFlag m_rGuard_HandleMenuEvent;
320 
321 private:
322  bool m_show_stack;
323  void Init();
324 
325  DECLARE_EVENT_TABLE();
326  DECLARE_DYNAMIC_CLASS(wxLuaIDE);
327 };
328 
329 #endif // _WX_LUAEDITOR_H_
wxledit.h Source File -- Sun Oct 12 2014 17:04:26 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation