wxlstack.h

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 // Name:         wxLuaStackTree.h
00003 // Purpose:      Interface to display the Lua stack in wxLua
00004 // Author:       J. Winwood, John Labenski
00005 // Created:      April 2002
00006 // Copyright:    (c) 2002. Lomtick Software. All rights reserved.
00007 // Licence:      wxWidgets license.
00008 /////////////////////////////////////////////////////////////////////////////
00009 
00010 #ifndef _WX_LUA_STACKTREE_H_
00011 #define _WX_LUA_STACKTREE_H_
00012 
00013 #include "wx/dialog.h"
00014 #include "wx/listctrl.h"
00015 #include "wx/treectrl.h"
00016 
00017 class WXDLLEXPORT wxListCtrl;
00018 class WXDLLEXPORT wxListEvent;
00019 class WXDLLEXPORT wxSplitterWindow;
00020 class WXDLLEXPORT wxProgressDialog;
00021 
00022 #include "wxluadebug/include/wxluadebugdefs.h"
00023 #include "wxluadebug/include/wxldebug.h"
00024 
00025 class WXDLLIMPEXP_WXLUADEBUG wxLuaDebugData;
00026 
00027 // ----------------------------------------------------------------------------
00028 // wxWindowIds for the wxLuaStackDialog
00029 // ----------------------------------------------------------------------------
00030 
00031 enum
00032 {
00033     ID_WXLUA_STACK_CHOICE = 2000,
00034     ID_WXLUA_STACK_EXPAND_BUTTON,
00035     ID_WXLUA_STACK_COLLAPSE_BUTTON,
00036 
00037     ID_WXLUA_STACK_FIND_COMBO,
00038     ID_WXLUA_STACK_FINDNEXT_BUTTON,
00039     ID_WXLUA_STACK_FINDPREV_BUTTON,
00040     ID_WXLUA_STACK_FINDMENU_BUTTON,
00041 
00042     ID_WXLUA_STACK_SPLITTERWIN,
00043     ID_WXLUA_STACK_LISTCTRL,
00044     ID_WXLUA_STACK_TREECTRL,
00045 
00046     ID_WXLUA_STACK_LISTMENU_COPY0,
00047     ID_WXLUA_STACK_LISTMENU_COPY1,
00048     ID_WXLUA_STACK_LISTMENU_COPY2,
00049     ID_WXLUA_STACK_LISTMENU_COPY3,
00050     ID_WXLUA_STACK_LISTMENU_COPY4,
00051 
00052     ID_WXLUA_STACK_FINDMENU_CASE,
00053     ID_WXLUA_STACK_FINDMENU_WHOLE_STRING,
00054     ID_WXLUA_STACK_FINDMENU_ALL,
00055     ID_WXLUA_STACK_FINDMENU_NAME,
00056     ID_WXLUA_STACK_FINDMENU_LEVEL,
00057     ID_WXLUA_STACK_FINDMENU_KEYTYPE,
00058     ID_WXLUA_STACK_FINDMENU_VALUETYPE,
00059     ID_WXLUA_STACK_FINDMENU_VALUE
00060 };
00061 
00062 // ----------------------------------------------------------------------------
00063 // wxLuaStackListData - the data we store for the listctrl.
00064 //
00065 // Note: We do not use a tree structure for speed at the expense of memory.
00066 // ----------------------------------------------------------------------------
00067 
00068 class WXDLLIMPEXP_WXLUADEBUG wxLuaStackListData
00069 {
00070 public:
00071     wxLuaStackListData(int item_idx, int level,
00072                        const wxLuaDebugData& parentDebugData,
00073                        const wxLuaDebugData& childrenDebugData = wxNullLuaDebugData) :
00074                        m_item_idx(item_idx), m_level(level),
00075                        m_parentDebugData(parentDebugData),
00076                        m_childrenDebugData(childrenDebugData) {}
00077 
00078     wxLuaDebugItem* GetDebugItem() { return m_parentDebugData.Item(m_item_idx); }
00079 
00080     int             m_item_idx;
00081     int             m_level;
00082     wxLuaDebugData  m_parentDebugData;
00083     wxLuaDebugData  m_childrenDebugData;
00084     wxTreeItemId    m_treeId;
00085 };
00086 
00087 // ----------------------------------------------------------------------------
00088 // wxLuaStackTreeData - the data we store in the wxTreeCtrl item's data
00089 // ----------------------------------------------------------------------------
00090 
00091 class WXDLLIMPEXP_WXLUADEBUG wxLuaStackTreeData : public wxTreeItemData
00092 {
00093 public:
00094     wxLuaStackTreeData(wxLuaStackListData* stkData) : m_stkListData(stkData) {}
00095 
00096     wxLuaStackListData*  m_stkListData; // we don't delete this
00097 };
00098 
00099 // ----------------------------------------------------------------------------
00100 // wxLuaStackDialog
00101 // ----------------------------------------------------------------------------
00102 
00103 class WXDLLIMPEXP_WXLUADEBUG wxLuaStackDialog : public wxDialog
00104 {
00105 public:
00106     wxLuaStackDialog() { Init(); }
00107 
00108     wxLuaStackDialog(const wxLuaState& wxlState,
00109                      wxWindow* parent, wxWindowID id = wxID_ANY,
00110                      const wxString& title = wxT("wxLua Stack"),
00111                      const wxPoint& pos = wxDefaultPosition,
00112                      const wxSize& size = wxDefaultSize)
00113     {
00114         Init();
00115         Create(wxlState, parent, id, title, pos, size);
00116     }
00117 
00118     virtual ~wxLuaStackDialog();
00119 
00120     bool Create(const wxLuaState& wxlState,
00121                 wxWindow* parent, wxWindowID id = wxID_ANY,
00122                 const wxString& title = wxT("wxLua Stack"),
00123                 const wxPoint& pos = wxDefaultPosition,
00124                 const wxSize& size = wxDefaultSize);
00125 
00126     // Icon indexes for image list used in the listctrl
00127     enum
00128     {
00129         IMG_UNKNOWN,
00130         IMG_NONE,
00131         IMG_NIL,
00132         IMG_BOOLEAN,
00133         IMG_LIGHTUSERDATA,
00134         IMG_NUMBER,
00135         IMG_STRING,
00136         IMG_TABLE,
00137         IMG_LUAFUNCTION,
00138         IMG_USERDATA,
00139         IMG_THREAD,
00140         IMG_INTEGER,
00141         IMG_CFUNCTION,
00142 
00143         IMG_TABLE_OPEN,
00144         IMG__COUNT
00145     };
00146 
00147     // Columns in the wxListCtrl
00148     enum
00149     {
00150         LIST_COL_KEY,
00151         LIST_COL_LEVEL,
00152         LIST_COL_KEY_TYPE,
00153         LIST_COL_VALUE_TYPE,
00154         LIST_COL_VALUE
00155     };
00156 
00157 
00158     // Draw the string centered in the bitmap
00159     virtual wxBitmap CreateBmpString(const wxBitmap& bmp, const wxString& s);
00160     // Get the IMG_XXX enum to use for this dataitem
00161     virtual int GetItemImage(const wxLuaDebugItem *dbgItem);
00162     // Get the string to show in the wxListCtrl
00163     virtual wxString GetItemText(long item, long column, bool exact_value = false);
00164 
00165     // Override these functions if you need to provide an alternate way to get
00166     //   the wxLuaDebugData. See wxluasocket lib and wxLuaDebuggerStackDialog
00167     virtual void EnumerateStack();
00168     virtual void EnumerateStackEntry(int nEntry);
00169     virtual void EnumerateTable(int nRef, int nEntry, long lc_item);
00170     virtual void EnumerateGlobalData(long lc_item);
00171 
00172     // Fill the combobox with the stack entries in the debug data and select
00173     //  the first stack item.
00174     void FillStackCombobox(const wxLuaDebugData& debugData);
00175     // Clear the listctrl and add debug data into tree root. If at the top of
00176     //  the stack, enumerate the global stack data.
00177     void FillStackEntry(int nEntry, const wxLuaDebugData& debugData);
00178     // Fill a listctrl item with children from the debug data
00179     void FillTableEntry(long lc_item, const wxLuaDebugData& debugData);
00180 
00181     // implementation
00182 
00183     // Put BeginBatch() before adding/removing items and EndBatch() afterwards for speed.
00184     void BeginBatch();
00185     void EndBatch();
00186 
00187     long FindListItem(wxLuaStackListData* stkListData, bool get_parent = false) const;
00188 
00189     void OnExpandButton(wxCommandEvent& event);
00190     void OnMenu(wxCommandEvent& event);
00191     void OnFind(wxCommandEvent& event);
00192 
00193     // Handle and set the stack from the stack combo selection
00194     void OnSelectStack(wxCommandEvent &event);
00195     void SelectStack(int stack_sel);
00196     // Handle all wxTreeCtrl events
00197     void OnTreeItem(wxTreeEvent &event);
00198     // Handle and expand/collapse a listctrl item
00199     void OnListItem(wxListEvent &event);
00200     // Popup menu on right click
00201     void OnListRightClick(wxListEvent &event);
00202 
00203     // Expand a single list item
00204     bool ExpandItem(long lc_item);
00205     // Expand a list item and all its children
00206     bool ExpandItemChildren(long lc_item);
00207     // Collapse an item and its children
00208     bool CollapseItem(long lc_item);
00209 
00210     // Don't warn about expanding duplicate tables
00211     void SetShowDuplicateExpandMessage(bool show) { m_show_dup_expand_msg = show; }
00212 
00213 //protected:
00214     void DeleteAllListItemData();
00215     void RemoveAllLuaReferences();
00216 
00217     wxSplitterWindow* m_splitterWin;
00218     wxListCtrl*       m_listCtrl;
00219     wxTreeCtrl*       m_treeCtrl;
00220     wxMenu*           m_listMenu;
00221 
00222     wxChoice*    m_stackChoice;   // display stack entries
00223     int          m_stack_sel;     // current stack selection
00224     wxArrayInt   m_stackEntries;  // stack entry references
00225 
00226     wxComboBox*  m_findComboBox;  // Find string combobox
00227     wxMenu*      m_findMenu;
00228 
00229     wxLuaState   m_wxlState;      // lua_State to show stack for
00230     wxArrayInt   m_luaReferences; // references from m_wxlState.wxluaR_Ref()
00231 
00232     wxImageList* m_imageList;     // image list for listctrl
00233     wxColour     m_typeColours[IMG__COUNT];
00234     int          m_img_font_size;
00235 
00236     bool m_show_dup_expand_msg;
00237     int  m_batch_count;
00238 
00239     wxLongToLongHashMap m_expandedItems; // map[long Lua table ptr] = &wxLuaStackListData
00240 
00241     wxArrayPtrVoid m_listData;    // array of wxLuaStackListData
00242 
00243     static wxSize m_defaultSize;  // remember last dialog size
00244 
00245 private:
00246     void Init();
00247 
00248     DECLARE_ABSTRACT_CLASS(wxLuaStackDialog)
00249     DECLARE_EVENT_TABLE()
00250 };
00251 
00252 #endif //_WX_LUA_STACKTREE_H_
Generated on Tue Jul 13 10:30:39 2010 for wxLua by  doxygen 1.6.3