From: John L. <jr...@us...> - 2007-06-25 03:19:55
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv32516/wxLua/samples Modified Files: controls.wx.lua Log Message: Add %gc, %ungc, %gc_this, and %ungc_this for fine tuning of tracking or releasing the garbage collection of userdata objects that become owned or released by something other than wxLua. Added %delete to many more classes using the above tags to control when and if they should be deleted. Index: controls.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/controls.wx.lua,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** controls.wx.lua 22 Jun 2007 15:48:50 -0000 1.6 --- controls.wx.lua 25 Jun 2007 03:19:51 -0000 1.7 *************** *** 10,15 **** ----------------------------------------------------------------------------- ! frame = nil ! textCtrl = nil -- wxBitmap to use for controls that need one --- 10,16 ---- ----------------------------------------------------------------------------- ! frame = nil ! textCtrl = nil ! taskbarIcon = nil -- The wxTaskBarIcon that we install -- wxBitmap to use for controls that need one *************** *** 30,35 **** --- 31,42 ---- listImageList:Add(wx.wxArtProvider.GetBitmap(wx.wxART_ERROR, wx.wxART_TOOLBAR, wx.wxSize(16, 16))) + + controlTable = {} -- Table of { win_id = "win name" } + ignoreControls = {} -- Table of { win_id = "win name" } of controls to ignore events from + -- IDs for the windows that we show ID_PARENT_SCROLLEDWINDOW = 1000 + ID_EVENT_LISTCTRL = 5000 + ID_CONTROL_LISTCTRL = 5001 ID_ANIMATIONCTRL = 1001 *************** *** 105,108 **** --- 112,116 ---- ignoreEVTs = { ["wxEVT_CREATE"] = true, + ["wxEVT_DESTROY"] = true, ["wxEVT_ENTER_WINDOW"] = true, ["wxEVT_ERASE_BACKGROUND"] = true, *************** *** 268,271 **** --- 276,281 ---- s = s..typ_name.."!IsOk" end + elseif typ_name == "wxListItem" then + s = s..typ_name.."(GetId='"..v:GetId().."')" elseif typ_name == "wxWindow" then s = s..typ_name.."(GetName="..v:GetName()..")" *************** *** 300,304 **** -- during shutdown, we nil textCtrl since events are sent and we don't want them anymore ! if (not textCtrl) or ignoreEVTs[evtTypeStr] then event:Skip() return --- 310,314 ---- -- during shutdown, we nil textCtrl since events are sent and we don't want them anymore ! if (not textCtrl) or ignoreEVTs[evtTypeStr] or ignoreControls[event:GetId()] then event:Skip() return *************** *** 397,405 **** ConnectEvents(real_control or control) -- connect to the real control end -- ----------------------------------------------------------------------- ! function CreateBookPage(parent, num) local p = wx.wxPanel(parent, wx.wxID_ANY) local s = wx.wxBoxSizer(wx.wxVERTICAL) --- 407,424 ---- ConnectEvents(real_control or control) -- connect to the real control + + local a = string.find(txt, "\n", 1, 1) + if a then txt = string.sub(txt, 1, a-1) end + + if real_control and real_control:IsKindOf(wx.wxClassInfo.FindClass("wxWindow")) then + controlTable[real_control:GetId()] = txt + else + controlTable[control:GetId()] = txt + end end -- ----------------------------------------------------------------------- ! local function CreateBookPage(parent, num) local p = wx.wxPanel(parent, wx.wxID_ANY) local s = wx.wxBoxSizer(wx.wxVERTICAL) *************** *** 688,692 **** wx.wxDefaultPosition, wx.wxSize(200, 200)) control:SetScrollbars(10, 10, 100, 100) ! control:SetBackgroundColour(wx.wxRED) wx.wxButton(control, wx.wxID_ANY, "Child button of wxScrolledWindow", wx.wxPoint(50, 50)) AddControl("wxScrolledWindow\n pixelsPerUnit=10\n noUnits=100", control) --- 707,711 ---- wx.wxDefaultPosition, wx.wxSize(200, 200)) control:SetScrollbars(10, 10, 100, 100) ! control:SetBackgroundColour(colorList[1]) wx.wxButton(control, wx.wxID_ANY, "Child button of wxScrolledWindow", wx.wxPoint(50, 50)) AddControl("wxScrolledWindow\n pixelsPerUnit=10\n noUnits=100", control) *************** *** 741,745 **** control = wx.wxStaticBox(scrollWin, ID_STATICBOX, "wxStaticBox", wx.wxDefaultPosition, wx.wxSize(200, 100)) ! control:SetBackgroundColour(wx.wxRED) AddControl("wxStaticBox", control) --- 760,764 ---- control = wx.wxStaticBox(scrollWin, ID_STATICBOX, "wxStaticBox", wx.wxDefaultPosition, wx.wxSize(200, 100)) ! control:SetBackgroundColour(colorList[1]) AddControl("wxStaticBox", control) *************** *** 752,755 **** --- 771,786 ---- -- ----------------------------------------------------------------------- + do + local p = wx.wxStaticText(scrollWin, wx.wxID_ANY, "See taskbar for icon") + taskbarIcon = wx.wxTaskBarIcon() + local icon = wx.wxIcon() + icon:CopyFromBitmap(bmp) + taskbarIcon:SetIcon(icon, "Tooltop for wxTaskBarIcon from controls.wx.lua") + icon:delete() + AddControl("wxTextCtrl", p, taskbarIcon) + end + + -- ----------------------------------------------------------------------- + control = wx.wxTextCtrl(scrollWin, ID_TEXTCTRL, "wxTextCtrl", wx.wxDefaultPosition, wx.wxDefaultSize, *************** *** 839,842 **** --- 870,874 ---- textCtrl = nil -- stop processing events imageList:delete() + if taskbarIcon then taskbarIcon:RemoveIcon() end end) *************** *** 881,885 **** -- ----------------------------------------------------------------------- ! eventListCtrl = wx.wxListCtrl(splitter2, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxLC_REPORT) --- 913,921 ---- -- ----------------------------------------------------------------------- ! ! noteBook = wx.wxNotebook(splitter2, wx.wxID_ANY) ! ! -- ----------------------------------------------------------------------- ! eventListCtrl = wx.wxListCtrl(noteBook, ID_EVENT_LISTCTRL, wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxLC_REPORT) *************** *** 892,902 **** local col_widths = {200, 300} for n = 1, #wxEVT_List do ! if skipEVTs[wxEVT_List[n][2]] then ! li = eventListCtrl:InsertItem(li, wxEVT_List[n][1], 2) ! elseif ignoreEVTs[wxEVT_List[n][2]] then ! li = eventListCtrl:InsertItem(li, wxEVT_List[n][1], 0) ! else ! li = eventListCtrl:InsertItem(li, wxEVT_List[n][1], 1) ! end eventListCtrl:SetItem(li, 1, wxEVT_List[n][2]) --- 928,936 ---- local col_widths = {200, 300} for n = 1, #wxEVT_List do ! local img = 1 ! if skipEVTs[wxEVT_List[n][2]] then img = 2 ! elseif ignoreEVTs[wxEVT_List[n][2]] then img = 0 end ! ! li = eventListCtrl:InsertItem(li, wxEVT_List[n][1], img) eventListCtrl:SetItem(li, 1, wxEVT_List[n][2]) *************** *** 911,915 **** -- Handle selecting or deselecting events ! function OnEventListCtrl(event) event:Skip(false) local ignored_count = 0 --- 945,951 ---- -- Handle selecting or deselecting events ! function OnCheckListCtrl(event) ! local listCtrl = event:GetEventObject():DynamicCast("wxListCtrl") ! local win_id = event:GetId() event:Skip(false) local ignored_count = 0 *************** *** 917,927 **** -- Find all the selected items ! for n = 1, eventListCtrl:GetItemCount() do ! local s = eventListCtrl:GetItemState(n-1, wx.wxLIST_STATE_SELECTED) if s ~= 0 then local litem = wx.wxListItem() litem:SetId(n-1) litem:SetMask(wx.wxLIST_MASK_IMAGE) ! eventListCtrl:GetItem(litem) if litem:GetImage() < 2 then -- skipEVTs if litem:GetImage() == 0 then --- 953,963 ---- -- Find all the selected items ! for n = 1, listCtrl:GetItemCount() do ! local s = listCtrl:GetItemState(n-1, wx.wxLIST_STATE_SELECTED) if s ~= 0 then local litem = wx.wxListItem() litem:SetId(n-1) litem:SetMask(wx.wxLIST_MASK_IMAGE) ! listCtrl:GetItem(litem) if litem:GetImage() < 2 then -- skipEVTs if litem:GetImage() == 0 then *************** *** 931,935 **** litem:SetMask(wx.wxLIST_MASK_TEXT) litem:SetColumn(1) ! eventListCtrl:GetItem(litem) table.insert(sel, {n-1, litem:GetText()}) end --- 967,971 ---- litem:SetMask(wx.wxLIST_MASK_TEXT) litem:SetColumn(1) ! listCtrl:GetItem(litem) table.insert(sel, {n-1, litem:GetText()}) end *************** *** 941,950 **** for n = 1, #sel do ! eventListCtrl:SetItemImage(sel[n][1], img) ! if img == 0 then ! ignoreEVTs[sel[n][2]] = true ! else ! ignoreEVTs[sel[n][2]] = nil end end --- 977,995 ---- for n = 1, #sel do ! listCtrl:SetItemImage(sel[n][1], img) ! if win_id == ID_EVENT_LISTCTRL then ! if img == 0 then ! ignoreEVTs[sel[n][2]] = true ! else ! ignoreEVTs[sel[n][2]] = nil ! end ! elseif win_id == ID_CONTROL_LISTCTRL then ! print(sel[n][2], type(sel[n][2])) ! if img == 0 then ! ignoreControls[tonumber(sel[n][2])] = true ! else ! ignoreControls[tonumber(sel[n][2])] = nil ! end end end *************** *** 954,961 **** function(event) if event:GetKeyCode() == wx.WXK_SPACE then ! OnEventListCtrl(event) end end) ! eventListCtrl:Connect(wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED, OnEventListCtrl) -- ----------------------------------------------------------------------- --- 999,1034 ---- function(event) if event:GetKeyCode() == wx.WXK_SPACE then ! OnCheckListCtrl(event) ! else ! event:Skip() end end) ! eventListCtrl:Connect(wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED, OnCheckListCtrl) ! ! -- ----------------------------------------------------------------------- ! ! controlListCtrl = wx.wxListCtrl(noteBook, ID_CONTROL_LISTCTRL, ! wx.wxDefaultPosition, wx.wxDefaultSize, ! wx.wxLC_REPORT) ! controlListCtrl:SetImageList(listImageList, wx.wxIMAGE_LIST_SMALL) ! controlListCtrl:InsertColumn(0, "wxWindow Class") ! controlListCtrl:InsertColumn(1, "wxWindowID") ! ! -- We add the items after creating all the controls ! ! controlListCtrl:Connect(wx.wxEVT_COMMAND_LIST_KEY_DOWN, ! function(event) ! if event:GetKeyCode() == wx.WXK_SPACE then ! OnCheckListCtrl(event) ! else ! event:Skip() ! end ! end) ! controlListCtrl:Connect(wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED, OnCheckListCtrl) ! ! -- ----------------------------------------------------------------------- ! ! noteBook:AddPage(eventListCtrl, "wxEvents") ! noteBook:AddPage(controlListCtrl, "wxWindows") -- ----------------------------------------------------------------------- *************** *** 963,966 **** --- 1036,1060 ---- controlsWin = CreateControlsWindow(splitter2) + -- Add all the initial items and find the best fitting col widths + local li = 0 + local col_widths = {200, 300} + local cTable = {} + for k, v in pairs(controlTable) do table.insert(cTable, { k, v }) end + table.sort(cTable, function(t1, t2) return t1[2] > t2[2] end) + for n = 1, #cTable do + local img = 1 + + li = controlListCtrl:InsertItem(li, cTable[n][2], img) + controlListCtrl:SetItem(li, 1, tostring(cTable[n][1])) + + for i = 1, #col_widths do + local w = controlListCtrl:GetTextExtent(tostring(cTable[n][i])) + if w > col_widths[i] + 16 then w = col_widths[i] + 16 end + end + end + for i = 1, #col_widths do + controlListCtrl:SetColumnWidth(i-1, col_widths[i]) + end + -- ----------------------------------------------------------------------- *************** *** 972,976 **** splitter:SplitHorizontally(splitter2, textCtrl, 300) ! splitter2:SplitVertically(eventListCtrl, controlsWin, 300) -- ----------------------------------------------------------------------- --- 1066,1070 ---- splitter:SplitHorizontally(splitter2, textCtrl, 300) ! splitter2:SplitVertically(noteBook, controlsWin, 300) -- ----------------------------------------------------------------------- |