From: John L. <jr...@us...> - 2007-05-23 02:48:35
|
Update of /cvsroot/wxlua/wxLua/modules/wxluadebug/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv5256/wxLua/modules/wxluadebug/src Modified Files: staktree.cpp wxldebug.cpp Log Message: Make the stack dialog listctrl a little nicer with bold fonts clean up variable names Index: wxldebug.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/wxldebug.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** wxldebug.cpp 23 Mar 2007 04:27:24 -0000 1.29 --- wxldebug.cpp 23 May 2007 02:48:31 -0000 1.30 *************** *** 32,42 **** const wxString &itemValue, const wxString &itemSource, ! int nReference, ! int nIndex, ! bool fExpanded) :m_itemName(itemName), m_itemType(itemType), m_itemValue(itemValue), m_itemSource(itemSource), ! m_nReference(nReference), m_nIndex(nIndex), ! m_fExpanded(fExpanded) { } --- 32,42 ---- const wxString &itemValue, const wxString &itemSource, ! int lua_ref, ! int idx, ! bool expanded) :m_itemName(itemName), m_itemType(itemType), m_itemValue(itemValue), m_itemSource(itemSource), ! m_lua_ref(lua_ref), m_index(idx), ! m_expanded(expanded) { } *************** *** 45,50 **** :m_itemName(dataItem.m_itemName), m_itemType(dataItem.m_itemType), m_itemValue(dataItem.m_itemValue), m_itemSource(dataItem.m_itemSource), ! m_nReference(dataItem.m_nReference), m_nIndex(dataItem.m_nIndex), ! m_fExpanded(dataItem.m_fExpanded) { } --- 45,50 ---- :m_itemName(dataItem.m_itemName), m_itemType(dataItem.m_itemType), m_itemValue(dataItem.m_itemValue), m_itemSource(dataItem.m_itemSource), ! m_lua_ref(dataItem.m_lua_ref), m_index(dataItem.m_index), ! m_expanded(dataItem.m_expanded) { } *************** *** 236,240 **** wxlState.GetGlobals(); int nRef = wxlState.tinsert(-1); ! Add(new wxLuaDebugDataItem(wxT("Globals"), wxT(""), wxT(""), wxT(""), nRef, 0)); references.Add(nRef); } --- 236,240 ---- wxlState.GetGlobals(); int nRef = wxlState.tinsert(-1); ! Add(new wxLuaDebugDataItem(wxT("Globals"), wxT("Table"), wxT(""), wxT(""), nRef, 0)); references.Add(nRef); } *************** *** 291,294 **** --- 291,296 ---- type = wxT("None"); value = wxEmptyString; + break; + case LUA_TNIL: type = wxT("Nil"); *************** *** 381,396 **** const void *pItem = lua_topointer(L, index); ! if (nTag != TLUA_NOTAG) ! { ! if (nItems == 0) ! return wxString::Format(wxT("%p (tag %d)"), pItem, nTag); ! return wxString::Format(wxT("%p (approx %d items) (tag %d)"), pItem, nItems, nTag); ! } ! if (nItems == 0) ! return wxString::Format(wxT("%p"), pItem); ! return wxString::Format(wxT("%p (approx %d items)"), pItem, nItems); } --- 383,395 ---- const void *pItem = lua_topointer(L, index); ! wxString s = wxString::Format(wxT("%p"), pItem); ! if (nItems > 0) ! s += wxString::Format(wxT(" (approx %d items)"), nItems); ! if (nTag != TLUA_NOTAG) ! s += wxString::Format(wxT(" (tag %d)"), nTag); ! return s; } *************** *** 400,418 **** wxLuaState wxlState(wxlState_); // unconst wxLuaState lua_State* L = wxlState.GetLuaState(); if (full) { int nTag = wxlState.ttag(index); - wxString pTagName; if (nTag != TLUA_NOTAG) ! pTagName = wxlState.GetLuaTagName(nTag); ! ! if (!pTagName.IsEmpty()) ! return wxString::Format(wxT("%p (%s)"), lua_touserdata(L, index), pTagName.c_str()); ! return wxString::Format(wxT("%p (%d)"), lua_touserdata(L, index), nTag); } ! return wxString::Format(wxT("%p"), lua_touserdata(L, index)); } --- 399,420 ---- wxLuaState wxlState(wxlState_); // unconst wxLuaState lua_State* L = wxlState.GetLuaState(); + + wxString s = wxString::Format(wxT("%p"), lua_touserdata(L, index)); + if (full) { int nTag = wxlState.ttag(index); if (nTag != TLUA_NOTAG) ! { ! s += wxString::Format(wxT(" (tag %d)"), nTag); ! wxString pTagName = wxlState.GetLuaTagName(nTag); ! if (!pTagName.IsEmpty()) ! s += wxString::Format(wxT(" '%s'"), pTagName.c_str()); ! } } ! return s; } Index: staktree.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxluadebug/src/staktree.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** staktree.cpp 22 May 2007 03:27:54 -0000 1.39 --- staktree.cpp 23 May 2007 02:48:31 -0000 1.40 *************** *** 35,39 **** 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) --- 35,39 ---- 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) *************** *** 73,78 **** 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); --- 73,78 ---- 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); *************** *** 82,88 **** m_imageList = new wxImageList(16, 16, true); ! m_imageList->Add(wxArtProvider::GetIcon(wxART_FOLDER, wxART_TOOLBAR, wxSize(16,16))); ! m_imageList->Add(wxArtProvider::GetIcon(wxART_NEW_DIR, wxART_TOOLBAR, wxSize(16,16))); ! m_imageList->Add(wxArtProvider::GetIcon(wxART_NORMAL_FILE, wxART_TOOLBAR, wxSize(16,16))); m_listCtrl->SetImageList(m_imageList, wxIMAGE_LIST_SMALL); --- 82,101 ---- 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); *************** *** 118,121 **** --- 131,219 ---- } + 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() { *************** *** 176,183 **** m_listCtrl->DeleteAllItems(); ! long rootItem = m_listCtrl->InsertItem(0, _("Locals"), 0); if (debugData.GetCount() > 0u) ! FillTableEntry(rootItem, debugData); // If at global scope, process globals --- 274,285 ---- 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 *************** *** 202,207 **** if (lc_item_ < m_listCtrl->GetItemCount()) { ! wxString levelText(m_listCtrl->GetItemText(lc_item_).BeforeLast(wxT(' '))); ! levelStr = levelText + wxT("--> "); } else --- 304,312 ---- 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 *************** *** 219,226 **** info.SetText(levelStr + item->GetName()); info.SetData(new wxLuaDebugDataItem(*item)); ! if (item->GetReference() != LUA_NOREF) ! info.SetImage(0); ! else ! info.SetImage(2); lc_item = m_listCtrl->InsertItem(info); --- 324,328 ---- info.SetText(levelStr + item->GetName()); info.SetData(new wxLuaDebugDataItem(*item)); ! SetupListItem(item, info); lc_item = m_listCtrl->InsertItem(info); *************** *** 244,251 **** // note: don't have spaces here since we use them to mark expanded levels ! wxLuaDebugDataItem* trackedItem = new wxLuaDebugDataItem(_("Tracked_List"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), trackedCount), wxT(""), 1, 0); ! wxLuaDebugDataItem* callbackItem = new wxLuaDebugDataItem(_("Event_Callback_List"), wxT("wxLuaData"), wxString::Format(wxT("Count %d"), callbackCount), wxT(""), 1, 0); ! wxLuaDebugDataItem* windowItem = new wxLuaDebugDataItem(_("Top_Level_wxWindow_List"), 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 --- 346,353 ---- // 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 *************** *** 296,300 **** // only expand items once ! if ((pDebugDataItem != NULL) && !pDebugDataItem->IsExpanded()) { // Check and block linked tables already shown --- 398,402 ---- // only expand items once ! if ((pDebugDataItem != NULL) && !pDebugDataItem->GetExpanded()) { // Check and block linked tables already shown *************** *** 307,311 **** { wxLuaDebugDataItem *itm = (wxLuaDebugDataItem *)m_listCtrl->GetItemData(n); ! if (itm && (itm != pDebugDataItem) && (itm->GetValue() == val) && itm->IsExpanded()) { wxMessageBox(wxT("Cannot expand linked tables,\nplease see the already expanded table."), --- 409,413 ---- { 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."), *************** *** 323,330 **** int nRef = pDebugDataItem->GetReference(); if (m_wxlState.Ok() && ! ((pDebugDataItem->GetName() == _("Tracked_List")) || ! (pDebugDataItem->GetName() == _("Event_Callback_List")) || ! (pDebugDataItem->GetName() == _("Top_Level_wxWindow_List")) || ! (pDebugDataItem->GetName() == _("wxWindow_Destroy_List")))) { wxLuaState wxlState(m_wxlState); --- 425,432 ---- 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); *************** *** 333,337 **** wxArrayInt counts; ! if (pDebugDataItem->GetName() == _("Tracked_List")) { wxLongToLongHashMap::iterator it; --- 435,439 ---- wxArrayInt counts; ! if (pDebugDataItem->GetName() == _("Tracked User Data")) { wxLongToLongHashMap::iterator it; *************** *** 358,362 **** } } ! else if (pDebugDataItem->GetName() == _("Event_Callback_List")) { wxList::compatibility_iterator node = wxlState.GetTrackedCallbackList()->GetFirst(); --- 460,464 ---- } } ! else if (pDebugDataItem->GetName() == _("wxEvent Callbacks")) { wxList::compatibility_iterator node = wxlState.GetTrackedCallbackList()->GetFirst(); *************** *** 391,395 **** } } ! else if (pDebugDataItem->GetName() == _("Top_Level_wxWindow_List")) { wxWindowList::compatibility_iterator node = wxlState.GetLuaStateData()->m_windowList.GetFirst(); --- 493,497 ---- } } ! else if (pDebugDataItem->GetName() == _("Top Level wxWindows")) { wxWindowList::compatibility_iterator node = wxlState.GetLuaStateData()->m_windowList.GetFirst(); *************** *** 414,418 **** } } ! else if (pDebugDataItem->GetName() == _("wxWindow_Destroy_List")) { wxList::compatibility_iterator node = wxlState.GetTrackedWinDestroyCallbackList()->GetFirst(); --- 516,520 ---- } } ! else if (pDebugDataItem->GetName() == _("wxWindow Destroy List")) { wxList::compatibility_iterator node = wxlState.GetTrackedWinDestroyCallbackList()->GetFirst(); *************** *** 436,440 **** pDebugDataItem->SetExpanded(true); ! m_listCtrl->SetItemImage(lc_item, 1); wxLuaDebugData dataArr; --- 538,542 ---- pDebugDataItem->SetExpanded(true); ! m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); wxLuaDebugData dataArr; *************** *** 442,446 **** for (n = 0; n < count; n++) { ! wxLuaDebugDataItem *item = new wxLuaDebugDataItem(names[n], wxT("wxLuaData"), wxString::Format(wxT("%d"), counts[n]), wxT(""), LUA_NOREF, pDebugDataItem->GetIndex() + 1); dataArr.Add(item); } --- 544,548 ---- 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); } *************** *** 451,455 **** { pDebugDataItem->SetExpanded(true); ! m_listCtrl->SetItemImage(lc_item, 1); int nIndex = pDebugDataItem->GetIndex() + 1; --- 553,557 ---- { pDebugDataItem->SetExpanded(true); ! m_listCtrl->SetItemImage(lc_item, IMG_TABLE_OPEN); int nIndex = pDebugDataItem->GetIndex() + 1; *************** *** 466,469 **** --- 568,572 ---- { 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; |