From: John L. <jr...@us...> - 2007-05-24 00:59:52
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv21191/wxLua/modules/wxluadebug/src Modified Files: Makefile Added Files: wxlstack.cpp Removed Files: splttree.cpp staktree.cpp Log Message: Removed dservice.h/cpp splttree.h/cpp, moved staktree.h/cpp to wxlstack.h/cpp Rebaked with the changes --- NEW FILE: wxlstack.cpp --- ///////////////////////////////////////////////////////////////////////////// // Name: StackTree.cpp // Purpose: Display the lua stack in a dialog. // Author: J. Winwood // Created: February 2002 // Copyright: (c) 2002 Lomtick Software. All rights reserved. // Licence: wxWidgets licence ///////////////////////////////////////////////////////////////////////////// #include "wx/wxprec.h" #ifdef __BORLANDC__ #pragma hdrstop #endif #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "wx/imaglist.h" #include "wx/artprov.h" #include "wxluadebug/include/wxlstack.h" #include "wxlua/include/wxlua.h" #include "wxlua/include/wxlcallb.h" #include "wxluadebug/include/wxldebug.h" #if defined(__WXGTK__) || defined(__WXMAC__) || defined(__WXMOTIF__) #include "art/wxlua.xpm" #endif // ---------------------------------------------------------------------------- // wxLuaStackDialog // ---------------------------------------------------------------------------- IMPLEMENT_ABSTRACT_CLASS(wxLuaStackDialog, wxDialog) BEGIN_EVENT_TABLE(wxLuaStackDialog, wxDialog) EVT_COMBOBOX( ID_WXLUA_STACKDIALOG_COMBO, wxLuaStackDialog::OnSelectStack) EVT_LIST_ITEM_ACTIVATED( ID_WXLUA_STACKDIALOG_LISTCTRL, wxLuaStackDialog::OnItemActivated) EVT_LIST_DELETE_ITEM( ID_WXLUA_STACKDIALOG_LISTCTRL, wxLuaStackDialog::OnItemDeleted) EVT_LIST_DELETE_ALL_ITEMS( ID_WXLUA_STACKDIALOG_LISTCTRL, wxLuaStackDialog::OnAllItemsDeleted) END_EVENT_TABLE() void wxLuaStackDialog::Init() { m_listCtrl = NULL; m_stackComboBox = NULL; m_stack_sel = -1; m_imageList = NULL; } bool wxLuaStackDialog::Create(const wxLuaState& wxlState, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size) { m_wxlState = wxlState; if (!wxDialog::Create(parent, id, title, pos, size, wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL | wxMAXIMIZE_BOX | wxRESIZE_BORDER)) return false; wxPanel* panel = new wxPanel(this, wxID_ANY); m_stackComboBox = new wxComboBox( panel, ID_WXLUA_STACKDIALOG_COMBO, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN | wxCB_READONLY); m_listCtrl = new wxListCtrl( panel, ID_WXLUA_STACKDIALOG_LISTCTRL, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_HRULES|wxLC_VRULES ); m_listCtrl->InsertColumn(0, wxT("Name"), wxLIST_FORMAT_LEFT, -1); m_listCtrl->InsertColumn(1, wxT("Type"), wxLIST_FORMAT_LEFT, -1); m_listCtrl->InsertColumn(2, wxT("Value"), wxLIST_FORMAT_LEFT, -1); m_listCtrl->SetColumnWidth(0, 250); m_listCtrl->SetColumnWidth(1, 100); m_listCtrl->SetColumnWidth(2, 100); m_imageList = new wxImageList(16, 16, true); m_imageList->Add(wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_TOOLBAR, wxSize(16,16))); // unknown m_imageList->Add(wxArtProvider::GetIcon(wxART_FOLDER, wxART_TOOLBAR, wxSize(16,16))); // table m_imageList->Add(wxArtProvider::GetIcon(wxART_NEW_DIR, wxART_TOOLBAR, wxSize(16,16))); // open table wxBitmap bmp(wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_TOOLBAR, wxSize(16,16))); m_imageList->Add(CreateBmpString(bmp, wxT("0"))); // nil m_imageList->Add(CreateBmpString(bmp, wxT("T"))); // bool m_imageList->Add(CreateBmpString(bmp, wxT("1"))); // number m_imageList->Add(CreateBmpString(bmp, wxT("a"))); // string m_imageList->Add(CreateBmpString(bmp, wxT("C"))); // C function m_imageList->Add(CreateBmpString(bmp, wxT("f"))); // Lua function m_imageList->Add(CreateBmpString(bmp, wxT("u"))); // user data m_imageList->Add(CreateBmpString(bmp, wxT("u"))); // light user data m_imageList->Add(CreateBmpString(bmp, wxT("t"))); // thread m_listCtrl->SetImageList(m_imageList, wxIMAGE_LIST_SMALL); // set the frame icon SetIcon(wxICON(LUA)); // use sizers to layout the windows in the panel of the dialog wxBoxSizer* rootSizer = new wxBoxSizer(wxVERTICAL); rootSizer->Add(m_stackComboBox, 0, wxEXPAND|wxBOTTOM, 4); rootSizer->Add(m_listCtrl, 1, wxEXPAND); rootSizer->SetMinSize(450, 400); panel->SetSizer(rootSizer); rootSizer->SetSizeHints(this); EnumerateStack(); return true; } wxLuaStackDialog::~wxLuaStackDialog() { DeleteAllListItemData(); if (m_listCtrl) m_listCtrl->SetImageList(NULL, wxIMAGE_LIST_SMALL); delete m_imageList; size_t n, count = m_wxlState.Ok() ? m_luaReferences.GetCount() : 0; for (n = 0; n < count; ++n) { int ref_idx = m_luaReferences.Item(n); m_wxlState.tremove(ref_idx); } } wxBitmap wxLuaStackDialog::CreateBmpString(const wxBitmap& bmp_, const wxString& s) { wxBitmap bmp(bmp_); // unconst it int bmp_w = bmp.GetWidth(); int bmp_h = bmp.GetHeight(); wxMemoryDC dc; dc.SelectObject(bmp); wxCoord w = 0, h = 0; for (int n = 14; n > 3; n--) { wxFont f(n, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL); dc.GetTextExtent(s, &w, &h, NULL, NULL, &f); if ((w < bmp_w) && (h < bmp_h)) { dc.SetFont(f); break; } } dc.DrawText(s, (bmp_w-w)/2, (bmp_h-h)/2); dc.SelectObject(wxNullBitmap); return bmp; } int wxLuaStackDialog::SetupListItem(const wxLuaDebugDataItem *dbgItem, wxListItem& lItem) { wxCHECK_MSG(dbgItem, IMG_UNKNOWN, wxT("Invalid wxLuaDebugDataItem")); wxString t(dbgItem->GetType()); int n, img = IMG_UNKNOWN; wxChar* strTypes[IMG_THREAD+1] = { wxT(""), // unknown wxT("Table"), wxT(""), // table open wxT("Nil"), wxT("Boolean"), wxT("Number"), wxT("String"), wxT("C Function"), wxT("Lua Function"), wxT("User Data"), wxT("Light User Data"), wxT("Thread") }; for (n = 0; n < IMG_THREAD+1; n++) { if (t == strTypes[n]) { img = n; break; } } // now fix up the images for special cases if (dbgItem->GetExpanded()) img = IMG_TABLE_OPEN; else if (t == wxT("wxLuaData")) // our internal data structs img = IMG_TABLE; lItem.SetImage(img); // Adjust the fonts to highlight some types wxFont f(m_listCtrl->GetFont()); if ((img == IMG_TABLE) || (img == IMG_TABLE_OPEN)) { f.SetWeight(wxFONTWEIGHT_BOLD); lItem.SetFont(f); } else if (img == IMG_STRING) { f.SetStyle(wxFONTSTYLE_ITALIC); lItem.SetFont(f); } return img; } void wxLuaStackDialog::EnumerateStack() { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); wxBusyCursor wait; wxLuaDebugData debugData; debugData.EnumerateStack(m_wxlState); FillStackCombobox(debugData); } void wxLuaStackDialog::EnumerateStackEntry(int nEntry) { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); wxBusyCursor wait; wxLuaDebugData debugData; debugData.EnumerateStackEntry(m_wxlState, nEntry, m_luaReferences); FillStackEntry(nEntry, debugData); } void wxLuaStackDialog::EnumerateTable(int nRef, int nEntry, long lc_item) { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); wxBusyCursor wait; wxLuaDebugData debugData; debugData.EnumerateTable(m_wxlState, nRef, nEntry, m_luaReferences); FillTableEntry(lc_item, debugData); } void wxLuaStackDialog::EnumerateGlobalData(long lc_item) { wxCHECK_RET(m_wxlState.Ok(), wxT("Invalid wxLuaState")); wxBusyCursor wait; wxLuaDebugData debugData; debugData.EnumerateTable(m_wxlState, -1, -1, m_luaReferences); // Get global table FillTableEntry(lc_item, debugData); } void wxLuaStackDialog::FillStackCombobox(const wxLuaDebugData& debugData) { m_stackComboBox->Clear(); m_stackEntries.Clear(); size_t n, count = debugData.GetCount(); for (n = 0; n < count; ++n) { const wxLuaDebugDataItem *item = debugData.Item(n); m_stackEntries.Add(item->GetReference()); m_stackComboBox->Append(item->GetName()); } if (debugData.GetCount() > 0) { m_stackComboBox->SetSelection(0); SelectStack(0); } } void wxLuaStackDialog::FillStackEntry(int WXUNUSED(nEntry), const wxLuaDebugData& debugData) { DeleteAllListItemData(); m_listCtrl->DeleteAllItems(); // Add the locals, fake a debug item to get it setup right wxLuaDebugDataItem* localItem = new wxLuaDebugDataItem(_("Locals"), wxT("Table"), wxString::Format(wxT("Count %d"), (int)debugData.GetCount()), wxT(""), 0, 0); wxLuaDebugData dataArr; // this deletes the items dataArr.Add(localItem); FillTableEntry(m_listCtrl->GetItemCount(), dataArr); if (debugData.GetCount() > 0u) FillTableEntry(m_listCtrl->GetItemCount()-1, debugData); // If at global scope, process globals if (m_stack_sel == (int)m_stackEntries.GetCount() - 1) EnumerateGlobalData(m_listCtrl->GetItemCount()); if (m_wxlState.Ok()) GetDerivedAndTrackedItems(); } void wxLuaStackDialog::FillTableEntry(long lc_item_, const wxLuaDebugData& debugData) { wxCHECK_RET(lc_item_ <= m_listCtrl->GetItemCount(), wxT("Attempting to add list item past end")); if (debugData.GetCount() == 0) return; //m_treeControl->SetItemHasChildren(treeId, false); else { wxString levelStr; // If less than the count we're expanding a item, else adding a new root if (lc_item_ < m_listCtrl->GetItemCount()) { wxString levelText(m_listCtrl->GetItemText(lc_item_).BeforeLast(wxT('>'))); if (levelText.Length() > 0) levelStr = levelText + wxT(">--> "); else levelStr = levelText + wxT("--> "); } else lc_item_--; size_t n, count = debugData.GetCount(); long lc_item = lc_item_; for (n = 0; n < count; ++n) { const wxLuaDebugDataItem *item = debugData.Item(n); //wxPrintf(wxT("FillTableEntry %ld %ld n %d %ld '%s'\n"), lc_item_, lc_item, n, (long)item, item->GetName().c_str()); wxListItem info; info.SetId(lc_item+1); info.SetText(levelStr + item->GetName()); info.SetData(new wxLuaDebugDataItem(*item)); SetupListItem(item, info); lc_item = m_listCtrl->InsertItem(info); info.SetId(lc_item); m_listCtrl->SetItem(lc_item, 1, item->GetType()); m_listCtrl->SetItem(lc_item, 2, item->GetValue()); } } } void wxLuaStackDialog::GetDerivedAndTrackedItems() { wxLuaState wxlState(m_wxlState); wxCHECK_RET(wxlState.Ok(), wxT("Invalid wxLuaState")); int trackedCount = wxlState.GetTrackedObjects()->size(); int callbackCount = wxlState.GetTrackedCallbackList()->GetCount(); int windowCount = wxlState.GetLuaStateData()->m_windowList.GetCount(); int destroyCount = wxlState.GetTrackedWinDestroyCallbackList()->GetCount(); // note: don't have spaces here since we use them to mark expanded levels wxLuaDebugDataItem* trackedItem = new wxLuaDebugDataItem(_("Tracked User Data"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), trackedCount), wxT(""), 1, 0); wxLuaDebugDataItem* callbackItem = new wxLuaDebugDataItem(_("wxEvent Callbacks"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), callbackCount), wxT(""), 1, 0); wxLuaDebugDataItem* windowItem = new wxLuaDebugDataItem(_("Top Level wxWindows"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), windowCount), wxT(""), 1, 0); wxLuaDebugDataItem* destroyItem = new wxLuaDebugDataItem(_("wxWindow Destroy List"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), destroyCount), wxT(""), 1, 0); wxLuaDebugData dataArr; // this deletes the items dataArr.Add(trackedItem); dataArr.Add(callbackItem); dataArr.Add(windowItem); dataArr.Add(destroyItem); FillTableEntry(m_listCtrl->GetItemCount(), dataArr); } void wxLuaStackDialog::OnItemDeleted(wxListEvent &event) { wxLuaDebugDataItem* wxlDItem = (wxLuaDebugDataItem*)event.GetData(); if (wxlDItem != NULL) delete wxlDItem; } void wxLuaStackDialog::OnAllItemsDeleted(wxListEvent &event) { DeleteAllListItemData(); event.Skip(); } void wxLuaStackDialog::OnSelectStack(wxCommandEvent &event) { if (event.GetSelection() >= 0) SelectStack(event.GetSelection()); } void wxLuaStackDialog::SelectStack(int stack_sel) { wxCHECK_RET((stack_sel >= 0) && (stack_sel < (int)m_stackEntries.GetCount()), wxT("Invalid stack index")); m_stack_sel = stack_sel; int n_entry = m_stackEntries[m_stack_sel]; EnumerateStackEntry(n_entry); } void wxLuaStackDialog::OnItemActivated(wxListEvent &event) { ItemExpanding(event.GetIndex()); //.GetIndex()); } void wxLuaStackDialog::ItemExpanding(long lc_item) { if (1) { wxLuaDebugDataItem *pDebugDataItem = (wxLuaDebugDataItem *)m_listCtrl->GetItemData(lc_item); // only expand items once if ((pDebugDataItem != NULL) && !pDebugDataItem->GetExpanded()) { // Check and block linked tables already shown if (pDebugDataItem->GetType() == wxT("Table")) { wxString val = pDebugDataItem->GetValue(); int n, count = m_listCtrl->GetItemCount(); for (n = 0; n < count; n++) { wxLuaDebugDataItem *itm = (wxLuaDebugDataItem *)m_listCtrl->GetItemData(n); if (itm && (itm != pDebugDataItem) && (itm->GetValue() == val) && itm->GetExpanded()) { wxMessageBox(wxT("Cannot expand linked tables,\nplease see the already expanded table."), wxT("wxLua Stack"), wxOK | wxCENTRE, this); m_listCtrl->SetItemState(n, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED); m_listCtrl->SetItemState(n, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); m_listCtrl->EnsureVisible(n); return; } } } int nRef = pDebugDataItem->GetReference(); if (m_wxlState.Ok() && ((pDebugDataItem->GetName() == _("Tracked User Data")) || (pDebugDataItem->GetName() == _("wxEvent Callbacks")) || (pDebugDataItem->GetName() == _("Top Level wxWindows")) || (pDebugDataItem->GetName() == _("wxWindow Destroy List")))) { wxLuaState wxlState(m_wxlState); wxArrayString names; wxArrayInt counts; if (pDebugDataItem->GetName() == _("Tracked User Data")) { wxLongToLongHashMap::iterator it; wxLongToLongHashMap* hashMap = wxlState.GetTrackedObjects(); for (it = hashMap->begin(); it != hashMap->end(); ++it) { wxString name(wxT("Unknown Tracked Item")); wxObject* obj = (wxObject*)it->second; if (obj && obj->GetClassInfo() && obj->GetClassInfo()->GetClassName()) name = obj->GetClassInfo()->GetClassName(); //name = wxString::Format(wxT("%p "), obj) + name; int idx = names.Index(name); if (idx == wxNOT_FOUND) { names.Add(name); counts.Add(1); } else counts[idx]++; } } else if (pDebugDataItem->GetName() == _("wxEvent Callbacks")) { wxList::compatibility_iterator node = wxlState.GetTrackedCallbackList()->GetFirst(); while (node) { wxLuaCallback *pCallback = (wxLuaCallback *) node->GetData(); wxCHECK_RET(pCallback, wxT("Invalid wxLuaCallback")); wxString evtName; if (wxlState.GetLuaBindingList()) { wxLuaBindingList::compatibility_iterator bindNode = wxlState.GetLuaBindingList()->GetFirst(); for (; bindNode; bindNode = bindNode->GetNext()) { wxLuaBinding* binding = bindNode->GetData(); evtName = binding->GetEventTypeName(pCallback->GetEventType()); if (!evtName.IsEmpty()) break; } } wxString name = wxString::Format(wxT("%d %s"), (int)pCallback->GetEventType(), evtName.c_str()); int idx = names.Index(name); if (idx == wxNOT_FOUND) { names.Add(name); counts.Add(1); } else counts[idx]++; node = node->GetNext(); } } else if (pDebugDataItem->GetName() == _("Top Level wxWindows")) { wxWindowList::compatibility_iterator node = wxlState.GetLuaStateData()->m_windowList.GetFirst(); while (node) { wxWindow *win= (wxWindow*)node->GetData(); wxCHECK_RET(win, wxT("Invalid wxLuaCallback")); if (win && win->GetClassInfo() && win->GetClassInfo()->GetClassName()) { wxString name(win->GetClassInfo()->GetClassName()); int idx = names.Index(name); if (idx == wxNOT_FOUND) { names.Add(name); counts.Add(1); } else counts[idx]++; } node = node->GetNext(); } } else if (pDebugDataItem->GetName() == _("wxWindow Destroy List")) { wxList::compatibility_iterator node = wxlState.GetTrackedWinDestroyCallbackList()->GetFirst(); while (node) { wxLuaWinDestroyCallback *pCallback = (wxLuaWinDestroyCallback *) node->GetData(); wxCHECK_RET(pCallback, wxT("Invalid wxLuaWinDestroyCallback")); wxString name(wxT("Unknown Tracked Window Type")); wxObject* obj = (wxObject*)pCallback->GetEvtHandler(); if (obj && obj->GetClassInfo() && obj->GetClassInfo()->GetClassName()) name = obj->GetClassInfo()->GetClassName(); names.Add(name); counts.Add(1); node = node->GetNext(); } } pDebugDataItem->SetExpanded(true); m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); wxLuaDebugData dataArr; size_t n, count = names.GetCount(); for (n = 0; n < count; n++) { wxLuaDebugDataItem *item = new wxLuaDebugDataItem(names[n], wxT(""), wxString::Format(wxT("Count %d"), counts[n]), wxT(""), LUA_NOREF, pDebugDataItem->GetIndex() + 1); dataArr.Add(item); } FillTableEntry(lc_item, dataArr); } else if (nRef != LUA_NOREF) { pDebugDataItem->SetExpanded(true); m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); int nIndex = pDebugDataItem->GetIndex() + 1; EnumerateTable(nRef, nIndex, lc_item); } } } } void wxLuaStackDialog::DeleteAllListItemData() { int i, count = m_listCtrl->GetItemCount(); for (i = 0; i < count; i++) { wxLuaDebugDataItem* wxlDItem = (wxLuaDebugDataItem*)m_listCtrl->GetItemData(i); m_listCtrl->SetItemData(i, 0); // null it so we won't try to delete it again if (wxlDItem != NULL) delete wxlDItem; } } --- splttree.cpp DELETED --- Index: Makefile =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/Makefile,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Makefile 24 May 2007 00:29:00 -0000 1.10 --- Makefile 24 May 2007 00:59:46 -0000 1.11 *************** *** 54,62 **** HEADERS = \ ../include/wxldebug.h \ ! ../include/staktree.h SOURCES = \ wxldebug.cpp \ ! staktree.cpp OBJECTS=$(SOURCES:.cpp=.o) --- 54,62 ---- HEADERS = \ ../include/wxldebug.h \ ! ../include/wxlstack.h SOURCES = \ wxldebug.cpp \ ! wxlstack.cpp OBJECTS=$(SOURCES:.cpp=.o) --- staktree.cpp DELETED --- |