From: John L. <jr...@us...> - 2007-06-11 03:58:19
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv19140/wxLua/samples Modified Files: bindings.wx.lua printing.wx.lua scribble.wx.lua unittest.wx.lua Added Files: validator.wx.lua Log Message: Remove wxArrayString_FromLuaTable and wxArrayInt_FromLuaTable binding tag since we convert from wxArrayInt/String automatically Fix listctrl sorting Fix validator code using wxLuaObject Rename wxLuaState::LuaCall to LuaPCall since that what it calls Lots more cleanup and shuffling of code to more appropriate places --- NEW FILE: validator.wx.lua --- ----------------------------------------------------------------------------- -- Name: validator.wx.lua -- Purpose: wxLua validator test program -- Author: John Labenski -- Modified by: -- Created: 6/10/2007 -- RCS-ID: -- Copyright: (c) 2001 John Labenski -- Licence: wxWidgets licence ----------------------------------------------------------------------------- -- NOTES about validators! -- The controls apparently must be in a wxDialog and they must also -- be direct children of the dialog. You CANNOT put any controls that -- you want to use wxGenericValidators with on a panel that's a child of -- the dialog. -- You cannot seem to set a wxGenericValidator to a control and then -- check the value of the wxLuaObject that the validator uses at any -- time either since the validator only updates it's value when the -- function TransferDataFromWindow() is called. You cannot set a -- wxGenericValidator to a wxCheckBox and then call TransferDataFromWindow() -- on the validator to force it to update as this apparently does nothing. -- Finally, it appears that you need to have an wxID_OK button for the -- TransferDataTo/FromWindow() functions to be automatically called by the -- dialog. frame = nil ID_TEST_VALIDATORS = 1000 ID_CHECKBOX = 1001 ID_COMBOBOX = 1002 ID_TEXTCTRL = 1003 ID_SCROLLBAR = 1004 ID_CHECKLBOX = 1005 ID_TEXTCTRL_TVAL_NUM = 1006 -- Set up the initial values for the validators, we use the wxLuaObjects -- as proxies for the wxGenericValidators to pass the *int *bool, *string, etc, -- pointers from the validators to and from to lua. check_val = true combo_val = "Select Item" text_val = "Enter text" scroll_val = 10 checkl_val = { 0, 2 } text_alpha_val = "OnlyAlphabetCharsAllowed" checkObj = wx.wxLuaObject(check_val) comboObj = wx.wxLuaObject(combo_val) textObj = wx.wxLuaObject(text_val) scrollObj = wx.wxLuaObject(scroll_val) checklObj = wx.wxLuaObject(checkl_val) checklObj = wx.wxLuaObject(checkl_val) textAlphaObj = wx.wxLuaObject(text_alpha_val) function CreateDialog() dialog = wx.wxDialog(frame, wx.wxID_ANY, "Test Validators") checkBox = wx.wxCheckBox(dialog, ID_CHECKBOX, "Check me!", wx.wxDefaultPosition, wx.wxDefaultSize, 0, wx.wxGenericValidatorBool(checkObj)) comboBox = wx.wxComboBox(dialog, ID_COMBOBOX, "THIS WILL BE OVERWRITTEN", wx.wxDefaultPosition, wx.wxDefaultSize, {"Item0", "Item1", "Item2"}, 0, wx.wxGenericValidatorString(comboObj)) textCtrl = wx.wxTextCtrl(dialog, ID_TEXTCTRL, "THIS WILL BE OVERWRITTEN", wx.wxDefaultPosition, wx.wxDefaultSize, 0, wx.wxGenericValidatorString(textObj)) scrollBar = wx.wxScrollBar(dialog, ID_SCROLLBAR, wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxSB_HORIZONTAL, wx.wxGenericValidatorInt(scrollObj)) scrollBar:SetScrollbar(0, 10, 100, 5) checklBox = wx.wxCheckListBox(dialog, ID_CHECKLBOX, wx.wxDefaultPosition, wx.wxDefaultSize, {"Check 0", "Check 1", "Check 2", "Check 3"}, 0, wx.wxGenericValidatorArrayInt(checklObj)) textAlphaCtrl = wx.wxTextCtrl(dialog, ID_TEXTCTRL, "THIS WILL BE OVERWRITTEN", wx.wxDefaultPosition, wx.wxDefaultSize, 0, wx.wxTextValidator(wx.wxFILTER_ALPHA, textAlphaObj)) okButton = wx.wxButton(dialog, wx.wxID_OK, "Ok") -- NEED this for validators to work okButton:SetDefault() flexSizer = wx.wxFlexGridSizer(12, 1, 0, 0) flexSizer:AddGrowableCol(0) flexSizer:Add(checkBox, 1, wx.wxEXPAND+wx.wxALL, 5) flexSizer:Add(comboBox, 1, wx.wxEXPAND+wx.wxALL, 5) flexSizer:Add(textCtrl, 1, wx.wxEXPAND+wx.wxALL, 5) flexSizer:Add(scrollBar, 1, wx.wxEXPAND+wx.wxALL, 5) flexSizer:Add(checklBox, 1, wx.wxEXPAND+wx.wxALL, 5) flexSizer:Add(textAlphaCtrl, 1, wx.wxEXPAND+wx.wxALL, 5) flexSizer:Add(okButton, 1, wx.wxEXPAND+wx.wxALL, 5) dialog:SetSizer(flexSizer) flexSizer:SetSizeHints(dialog) dialog:ShowModal() end function main() frame = wx.wxFrame( wx.NULL, -- no parent for toplevel windows wx.wxID_ANY, -- don't need a wxWindow ID "wxLua Validator Demo", -- caption on the frame wx.wxDefaultPosition, -- let system place the frame wx.wxSize(450, 450), -- set the size of the frame wx.wxDEFAULT_FRAME_STYLE ) -- use default frame styles -- create a simple status bar frame:CreateStatusBar(1) frame:SetStatusText("Welcome to wxLua.") -- ----------------------------------------------------------------------- local fileMenu = wx.wxMenu() fileMenu:Append(ID_TEST_VALIDATORS, "&Test Validators...", "Show dialog to test validators") fileMenu:AppendSeparator() fileMenu:Append(wx.wxID_EXIT, "E&xit", "Quit the program") local helpMenu = wx.wxMenu() helpMenu:Append(wx.wxID_ABOUT, "&About", "About the wxLua Minimal Application") local menuBar = wx.wxMenuBar() menuBar:Append(fileMenu, "&File") menuBar:Append(helpMenu, "&Help") frame:SetMenuBar(menuBar) -- connect the selection event of the exit menu item to an frame:Connect(ID_TEST_VALIDATORS, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) -- update original values we'll use for the validators check_val = checkObj:GetObject() combo_val = comboObj:GetObject() text_val = textObj:GetObject() scroll_val = scrollObj:GetObject() checkl_val = checklObj:GetObject() text_alpha_val = textAlphaObj:GetObject() CreateDialog() local s = "" s = s.."wxCheckBox : '"..tostring(checkObj:GetObject()).."', Initial value : '"..tostring(check_val).."'\n\n" s = s.."wxComboBox : '"..tostring(comboObj:GetObject()).."', Initial value : '"..tostring(combo_val).."'\n\n" s = s.."wxTextCtrl : '"..tostring(textObj:GetObject()).."', Initial value : '"..tostring(text_val).."'\n\n" s = s.."wxScrollBar : '"..tostring(scrollObj:GetObject()).."', Initial value : '"..tostring(scroll_val).."'\n\n" s = s.."wxCheckListBox : '"..table.concat(checklObj:GetObject(), ", ").."', Initial value : '"..table.concat(checkl_val, ", ").."'\n\n" s = s.."wxTextCtrl alpha chars only: '"..tostring(textAlphaObj:GetObject()).."', Initial value : '"..tostring(text_alpha_val).."'\n\n" frameText:SetValue(s) end ) -- event handler that closes the window frame:Connect(wx.wxID_EXIT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) frame:Close(true) end ) -- connect the selection event of the about menu item frame:Connect(wx.wxID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) wx.wxMessageBox('This is the "About" dialog of the Validator wxLua sample.\n'.. wx.wxLUA_VERSION_STRING.." built with "..wx.wxVERSION_STRING, "About wxLua", wx.wxOK + wx.wxICON_INFORMATION, frame) end ) -- ----------------------------------------------------------------------- frameText = wx.wxTextCtrl(frame, wx.wxID_ANY, "Output of the validator test dialog will be shown here.", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxTE_MULTILINE) -- show the frame window frame:Show(true) end main() Index: scribble.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/scribble.wx.lua,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** scribble.wx.lua 31 May 2007 17:18:56 -0000 1.18 --- scribble.wx.lua 11 Jun 2007 03:58:11 -0000 1.19 *************** *** 392,396 **** memDC:SelectObject(colourWinBmp) memDC:SetPen(wx.wxBLACK_PEN) ! local w, h = colourWin:GetClientSize() local w2 = math.floor(w/8) local h2 = math.floor(h/2) --- 392,396 ---- memDC:SelectObject(colourWinBmp) memDC:SetPen(wx.wxBLACK_PEN) ! local w, h = colourWin:GetClientSizeWH() local w2 = math.floor(w/8) local h2 = math.floor(h/2) *************** *** 419,423 **** function(event) local x, y = event:GetPositionXY() ! local w, h = colourWin:GetClientSize() local i = math.floor(8*x/w)+1 + 8*math.floor(2*y/h) if colourWinColours[i] then --- 419,423 ---- function(event) local x, y = event:GetPositionXY() ! local w, h = colourWin:GetClientSizeWH() local i = math.floor(8*x/w)+1 + 8*math.floor(2*y/h) if colourWinColours[i] then *************** *** 508,512 **** wx.wxSAVE + wx.wxOVERWRITE_PROMPT) if fileDialog:ShowModal() == wx.wxID_OK then ! local w, h = panel:GetClientSize() local bmp = wx.wxBitmap(w, h) lastDrawn = 0 -- force redrawing all points --- 508,512 ---- wx.wxSAVE + wx.wxOVERWRITE_PROMPT) if fileDialog:ShowModal() == wx.wxID_OK then ! local w, h = panel:GetClientSizeWH() local bmp = wx.wxBitmap(w, h) lastDrawn = 0 -- force redrawing all points Index: bindings.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/bindings.wx.lua,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** bindings.wx.lua 8 Jun 2007 22:50:18 -0000 1.2 --- bindings.wx.lua 11 Jun 2007 03:58:11 -0000 1.3 *************** *** 10,17 **** ----------------------------------------------------------------------------- ! -- ---------------------------------------------------------------------------- -- Brute force dump of the binding info using print statements for debugging -- ---------------------------------------------------------------------------- function ColumnDumpTable(t, keys) --- 10,18 ---- ----------------------------------------------------------------------------- ! -- ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- -- Brute force dump of the binding info using print statements for debugging -- ---------------------------------------------------------------------------- + -- ---------------------------------------------------------------------------- function ColumnDumpTable(t, keys) *************** *** 118,121 **** --- 119,124 ---- img_normal = 0 -- a "file" image in the listctrl img_folder = 1 -- a "folder" image in the listctrl + img_sort_dn = 2 -- a down arrow + img_sort_up = 3 -- an up arrow listColWidths = {} -- stored by "object_type" name *************** *** 123,133 **** list_level = 1 -- where are we in the listData listData = {} -- store the table currently displayed by the listCtrl ! -- { {"col1", "col2", ... ["icon"] = img_normal, ["color"] = wx.wxBLUE }, ! -- {"col1", "col2", ... The icon and color are optional }, ! -- { ... }, ! -- ["col_labels"] = { "col label 1", "col label 2", ...}, ! -- ["col_icons"] = { nil, nil, img_folder,... }, -- the 3rd col has folder icon ! -- ["object_type"] = "wxLuaBindClass", -- or something else readable ! -- ["list_item"] = last selected list item or nil if not set -- ---------------------------------------------------------------------------- --- 126,136 ---- list_level = 1 -- where are we in the listData listData = {} -- store the table currently displayed by the listCtrl ! -- {{"col val 1", "val2", ... ["icon"] = img_normal, ["color"] = wx.wxBLUE }, ! -- {"col val 1", "val2", ... The icon and color are optional }, ! -- { ... these are numbered items for the rows }, ! -- ["col_labels"] = { "col label 1", "col label 2", ...}, ! -- ["col_icons"] = { nil, nil, img_folder,... }, -- the 3rd col has folder icon ! -- ["object_type"] = "wxLuaBindClass", -- or something else readable ! -- ["list_item"] = last selected list item or nil if not set -- ---------------------------------------------------------------------------- *************** *** 150,153 **** --- 153,157 ---- -- ---------------------------------------------------------------------------- function GotoBindingLevel(listCtrl, level) + wx.wxBeginBusyCursor(); local data = listData[level] *************** *** 171,178 **** listCtrl:InsertColumn(col-1, data.col_labels[col], wx.wxLIST_FORMAT_LEFT, -1) - if data.col_icons and data.col_icons[col] then - listCtrl:SetColumnImage(col-1, data.col_icons[col]) - end - if auto_col_widths then local w = listCtrl:GetTextExtent(data.col_labels[col]) --- 175,178 ---- *************** *** 195,198 **** --- 195,200 ---- info:SetId(lc_item+1) info:SetText(tostring(d[1])) + info:SetData(i) -- key into the listData table for sorting + if (d.icon) then info:SetImage(d.icon) *************** *** 215,218 **** --- 217,225 ---- listCtrl:SetItem(lc_item, col-1, tostring(d[col])) + if data.col_icons and data.col_icons[col] and + (d[col] ~= "") and (type(d[col]) ~= "function") then + listCtrl:SetItemColumnImage(lc_item, col-1, data.col_icons[col]) + end + if auto_col_widths then local w = listCtrl:GetTextExtent(tostring(d[col])) *************** *** 249,252 **** --- 256,261 ---- end frame:SetStatusText(table.concat(s, "->")) + + wx.wxEndBusyCursor(); end *************** *** 258,303 **** local t = t_ ! if (t - wx.WXLUAMETHOD_OVERLOAD_BASE) >= 0 then ! --table.insert(s, "OverloadBase") -- nobody should care about this ! t = t - wx.WXLUAMETHOD_OVERLOAD_BASE ! end ! if (t - wx.WXLUAMETHOD_OVERLOAD) >= 0 then ! table.insert(s, "Overload") ! t = t - wx.WXLUAMETHOD_OVERLOAD ! end ! if (t - wx.WXLUAMETHOD_STATIC) >= 0 then ! table.insert(s, "Static") ! t = t - wx.WXLUAMETHOD_STATIC ! end ! if (t - wx.WXLUAMETHOD_SETPROP) >= 0 then ! table.insert(s, "SetProp") ! t = t - wx.WXLUAMETHOD_SETPROP ! end ! if (t - wx.WXLUAMETHOD_GETPROP) >= 0 then ! table.insert(s, "GetProp") ! t = t - wx.WXLUAMETHOD_GETPROP ! end ! if (t - wx.WXLUAMETHOD_CFUNCTION) >= 0 then ! table.insert(s, "CFunc") ! t = t - wx.WXLUAMETHOD_CFUNCTION ! end ! if (t - wx.WXLUAMETHOD_METHOD) >= 0 then ! table.insert(s, "Method") ! t = t - wx.WXLUAMETHOD_METHOD ! end ! if (t - wx.WXLUAMETHOD_CONSTRUCTOR) >= 0 then ! table.insert(s, "Constructor") ! t = t - wx.WXLUAMETHOD_CONSTRUCTOR end ! assert(t == 0, "The wxLuaMethod_Type is not handled correctly "..tostring(t)) ! -- nobody should care about this and it's confusing ! t = t_ ! if (t - wx.WXLUAMETHOD_OVERLOAD_BASE) >= 0 then ! t = t - wx.WXLUAMETHOD_OVERLOAD_BASE ! end ! return string.format("0x%X (", t)..table.concat(s, ", ")..")" end --- 267,294 ---- local t = t_ ! local function HasBit(val, bit, tbl, name) ! if (val - bit) >= 0 then ! val = val - bit ! if tbl then table.insert(tbl, name) end ! end ! return val end ! -- subtract values from high to low value ! t = HasBit(t, wx.WXLUAMETHOD_OVERLOAD_BASE, nil, nil) -- nobody should care about this ! t = HasBit(t, wx.WXLUAMETHOD_OVERLOAD, s, "Overload") ! t = HasBit(t, wx.WXLUAMETHOD_STATIC, s, "Static") ! t = HasBit(t, wx.WXLUAMETHOD_SETPROP, s, "SetProp") ! t = HasBit(t, wx.WXLUAMETHOD_GETPROP, s, "GetProp") ! t = HasBit(t, wx.WXLUAMETHOD_CFUNCTION, s, "CFunc") ! t = HasBit(t, wx.WXLUAMETHOD_METHOD, s, "Method") ! t = HasBit(t, wx.WXLUAMETHOD_CONSTRUCTOR, s, "Constructor") ! assert(t == 0, "The wxLuaMethod_Type is not handled correctly, remainder "..tostring(t).." of "..tostring(t_)) ! -- remove this, nobody should care and it'll probably be confusing ! t = HasBit(t_, wx.WXLUAMETHOD_OVERLOAD_BASE, nil, nil) ! ! return string.format("0x%04X (%s)", t, table.concat(s, ", ")) end *************** *** 309,322 **** local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindClass") - -- Convert the classinfo userdata into something more readable for i = 2, #t do if (type(t[i][2]) == "table") then t[i].icon = img_folder end local classInfo = t[i][4] if type(classInfo) == "userdata" then ! local s = classInfo:GetClassName() ! local b1 = classInfo:GetBaseClassName1() local b2 = classInfo:GetBaseClassName2() --- 300,313 ---- local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindClass") for i = 2, #t do + -- This class has methods and can be expanded if (type(t[i][2]) == "table") then t[i].icon = img_folder end + -- Convert the wxClassInfo userdata into something more readable local classInfo = t[i][4] if type(classInfo) == "userdata" then ! local s = classInfo:GetClassName() local b1 = classInfo:GetBaseClassName1() local b2 = classInfo:GetBaseClassName2() *************** *** 329,333 **** end ! t[i][4] = s end end --- 320,324 ---- end ! t[i][4] = s -- replace with the string end end *************** *** 354,359 **** t[i][2] = ConvertwxLuaMethod_Type(t[i][2]) if (type(t[i][3]) == "table") then - local cfunc_t = CreatewxLuaBindCFunc(t[i][3]) t[i].color = wx.wxBLUE t[i][6] = "" --- 345,350 ---- t[i][2] = ConvertwxLuaMethod_Type(t[i][2]) + -- Add in the CFuncs if (type(t[i][3]) == "table") then t[i].color = wx.wxBLUE t[i][6] = "" *************** *** 361,367 **** t[i][8] = "" t[i][9] = "" -- keys for CFunc = { "func", "type", "minargs", "maxargs", "argtag_names", "argtags" } for j = 2, #cfunc_t do ! table.insert(t, i+j-1, {"", cfunc_t[j][2], cfunc_t[j][1], "", "", cfunc_t[j][3], cfunc_t[j][4], cfunc_t[j][5], cfunc_t[j][6]}) end --- 352,360 ---- t[i][8] = "" t[i][9] = "" + -- keys for CFunc = { "func", "type", "minargs", "maxargs", "argtag_names", "argtags" } + local cfunc_t = CreatewxLuaBindCFunc(t[i][3]) for j = 2, #cfunc_t do ! table.insert(t, i+j-1, {t[i][1].." "..j-1, cfunc_t[j][2], cfunc_t[j][1], "", "", cfunc_t[j][3], cfunc_t[j][4], cfunc_t[j][5], cfunc_t[j][6]}) end *************** *** 381,388 **** for i = 2, #t do -- these are often enums or flags, it's easier to see them as hex - local n = tonumber(t[i][2]) if n > 0 then ! t[i][2] = t[i][2]..string.format(" (0x%X)", n) end end --- 374,383 ---- for i = 2, #t do + local n = t[i][2] + t[i][3] = n -- store real number for sorting w/o hex + -- these are often enums or flags, it's easier to see them as hex if n > 0 then ! t[i][2] = n..string.format(" (0x%X)", n) end end *************** *** 398,404 **** local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindEvent") ! -- Add the tag name the event uses for i = 2, #t do ! t[i][3] = t[i][3].." ("..wx.wxlua_typename(t[i][3])..")" end --- 393,399 ---- local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindEvent") ! -- Add the class tag name for the event for i = 2, #t do ! t[i][3] = wx.wxlua_typename(t[i][3]).." ("..t[i][3]..")" end *************** *** 409,415 **** local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindObject") ! -- Add the tag name to the user data for i = 2, #t do ! t[i][3] = t[i][3].." ("..wx.wxlua_typename(t[i][3])..")" end --- 404,410 ---- local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindObject") ! -- Add the class tag name for the user data for i = 2, #t do ! t[i][3] = wx.wxlua_typename(t[i][3]).." ("..t[i][3]..")" end *************** *** 423,427 **** t.col_labels[6] ="argtags" ! -- we don't want to show the table, just show the values and convert them to strings for i = 2, #t do local args = t[i][5] --- 418,422 ---- t.col_labels[6] ="argtags" ! -- we don't want to show the table, just show the values for i = 2, #t do local args = t[i][5] *************** *** 450,454 **** local item = {} for k = 1, #keys do ! -- we need to force there to be something in each col, use a 0 local val = tbl[i][keys[k]] if val ~= nil then --- 445,449 ---- local item = {} for k = 1, #keys do ! -- we need to force there to be something in each col, use "" local val = tbl[i][keys[k]] if val ~= nil then *************** *** 464,471 **** --- 459,713 ---- end + -- ---------------------------------------------------------------------------- + -- Handle the wxEVT_COMMAND_LIST_COL_CLICK event when the mouse is clicked + -- ---------------------------------------------------------------------------- + function OnListColClicked(event) + local col = event:GetColumn() + + if not listData[list_level].col_sorted then + listData[list_level].col_sorted = {} + end + + local sorted = listData[list_level].col_sorted[col+1] + + local function SortListItems(item1, item2, col) + local data1 = listData[list_level][item1] + local data2 = listData[list_level][item2] + + if data1[1] == ".." then return -1 end + if data2[1] == ".." then return 1 end + + local i1 = data1[col] + local i2 = data2[col] + + if (listData[list_level].object_type == "wxLuaBindDefine") and (col == 2) then + -- sort on the real numbers, not the strings w/ hex + i1 = data1[3] + i2 = data2[3] + elseif ((listData[list_level].object_type == "wxLuaBindClass") and ((col == 3) or (col == 5) or (col == 9))) or + ((listData[list_level].object_type == "wxLuaBindMethod") and ((col == 4) or (col == 6) or (col == 7))) or + ((listData[list_level].object_type == "wxLuaBindCFunc") and ((col == 3) or (col == 4))) then + -- sort on the real numbers, but treat "" as lower + if (i1 == "") and (i2 == "") then + i1, i2 = 0, 0 + elseif (i1 == "") then + i1, i2 = 0, 1 + elseif (i2 == "") then + i1, i2 = 1, 0 + else + i1 = tonumber(i1) + i2 = tonumber(i2) + end + else + i1 = tostring(data1[col]) + i2 = tostring(data2[col]) + end + + if sorted then + if i1 < i2 then return 1 end + if i1 > i2 then return -1 end + else + if i1 < i2 then return -1 end + if i1 > i2 then return 1 end + end + + return 0 + end + + listCtrl:SortItems(SortListItems, col+1) + + for c = 1, listCtrl:GetColumnCount() do + listCtrl:SetColumnImage(c-1, -1) + end + + if not sorted then + listData[list_level].col_sorted[col+1] = true + listCtrl:SetColumnImage(col, img_sort_dn) + else + listData[list_level].col_sorted[col+1] = false + listCtrl:SetColumnImage(col, img_sort_up) + end + end + + -- ---------------------------------------------------------------------------- + -- Handle the wxEVT_COMMAND_LIST_ITEM_ACTIVATED event when the mouse is clicked + -- ---------------------------------------------------------------------------- + function OnListItemActivated(event) + local index = event:GetIndex() -- note: 0 based, lua tables start at 1 + local data_index = event:GetData() + local itemText = listCtrl:GetItemText(index) + + -- ----------------------------------------------------------------------- + -- Find what column we're in + -- local col = event:GetColumn() -- both of these don't work in MSW & GTK + -- local pt = event:GetPoint() + + local mousePos = wx.wxGetMousePosition() -- mouse pos on screen + local clientPos = listCtrl:ScreenToClient(mousePos) + local scrollPos = listCtrl:GetScrollPos(wx.wxHORIZONTAL) -- horiz scroll pos + + -- The wxGenericListCtrl (used in GTK at least) actually scrolls by 15 + genlistClassInfo = wx.wxClassInfo.FindClass("wxGenericListCtrl") + if genlistClassInfo and listCtrl:GetClassInfo():IsKindOf(genlistClassInfo) then + scrollPos = scrollPos * 15 + end + + local x = clientPos:GetX() + scrollPos + local w = 0 + local col = 0 + + --print(col, x, mousePos:GetX(), clientPos:GetX(), scrollPos) + + for c = 1, listCtrl:GetColumnCount() do + w = w + listCtrl:GetColumnWidth(c-1) + if x < w then + col = c-1 + break + end + end + + listData[list_level].list_item = index + SaveListColWidths(list_level) -- remember user's col widths + + if (itemText == "..") then + list_level = list_level - 1 + GotoBindingLevel(listCtrl, list_level) + elseif (list_level == 1) then + if itemText == "wxLua Types" then + local t = { + {"..", ["icon"] = img_folder}, + ["col_labels"] = {"wxLua Type", "none -1", "nil 0", "bool 1", "lightuserdata 2", "number 3", "string 4", "table 5", "function 6", "userdata 7", "thread 8"}, + ["object_type"] = "wxLua Types" + } + + local wxltype_names = { + "WXLUAARG_None", + "WXLUAARG_Nil", + "WXLUAARG_Boolean", + "WXLUAARG_LightUserData", + "WXLUAARG_Number", + "WXLUAARG_String", + "WXLUAARG_LuaTable", + "WXLUAARG_LuaFunction", + "WXLUAARG_UserData", + "WXLUAARG_LuaThread", + "WXLUAARG_Enum" + } + + for i = 1, #wxltype_names do + local wxltype = wx[wxltype_names[i]] + local row = { wxltype_names[i].." "..tostring(wxltype) } + for j = 2, #t.col_labels do + local ltype = j - 3 + local ok = wx.wxlua_iswxluatype(ltype, wxltype) + if ok == 1 then ok = "X" end + if ok == 0 then ok = "" end + if ok == -1 then ok = "?" end -- shouldn't happen! + table.insert(row, ok) + end + table.insert(t, row) + end + + list_level = list_level + 1 + listData[list_level] = t + GotoBindingLevel(listCtrl, list_level) + else + local binding = _G + for i = 1, #listData[1][data_index] do + binding = binding[listData[1][data_index][i]] + end + + listData[2] = { + {"..", ["icon"] = img_folder}, + {"GetBindingName", tostring(binding.GetBindingName)}, + {"GetLuaNamespace", tostring(binding.GetLuaNamespace)}, + + {"GetClassArray", "GetClassCount : "..tostring(binding.GetClassCount), ["icon"] = img_folder}, + {"GetFunctionArray", "GetFunctionCount : "..tostring(binding.GetFunctionCount), ["icon"] = img_folder}, + {"GetDefineArray", "GetDefineCount : "..tostring(binding.GetDefineCount), ["icon"] = img_folder}, + {"GetStringArray", "GetStringCount : "..tostring(binding.GetStringCount), ["icon"] = img_folder}, + {"GetEventArray", "GetEventCount : "..tostring(binding.GetEventCount), ["icon"] = img_folder}, + {"GetObjectArray", "GetObjectCount : "..tostring(binding.GetObjectCount), ["icon"] = img_folder}, + + ["col_labels"] = {"Function Name", "Value"}, + ["binding"] = binding, + ["object_type"] = "wxLuaBinding" + } + + list_level = list_level + 1 + GotoBindingLevel(listCtrl, list_level) + end + elseif (list_level == 2) then + local binding = listData[2].binding + + local t = nil + + if (itemText == "GetClassArray") then + t = CreatewxLuaBindClass(binding.GetClassArray) + elseif (itemText == "GetFunctionArray") then + t = CreatewxLuaBindMethod(binding.GetFunctionArray) + elseif (itemText == "GetDefineArray") then + t = CreatewxLuaBindDefine(binding.GetDefineArray) + elseif (itemText == "GetStringArray") then + t = CreatewxLuaBindString(binding.GetStringArray) + elseif (itemText == "GetEventArray") then + t = CreatewxLuaBindEvent(binding.GetEventArray) + elseif (itemText == "GetObjectArray") then + t = CreatewxLuaBindObject(binding.GetObjectArray) + end + + if t ~= nil then + list_level = list_level + 1 + listData[list_level] = t + GotoBindingLevel(listCtrl, list_level) + end + elseif (data_index > 1) and listData[list_level].object_type == "wxLuaBindClass" then + local t = nil + + if ((col == 0) or (col == 1)) and (type(listData[list_level][data_index][2]) == "table") then + t = CreatewxLuaBindMethod(listData[list_level][data_index][2]) + elseif (col == 6) and (type(listData[list_level][data_index][col+1]) == "userdata") then + t = CreatewxLuaBindClass({listData[list_level][data_index][col+1]}) + elseif (col == 7) and (type(listData[list_level][data_index][col+1]) == "table") then + t = CreatewxLuaBindDefine(listData[list_level][data_index][col+1]) + end + + if t ~= nil then + t.class_name = listCtrl:GetItemText(index) + + list_level = list_level + 1 + listData[list_level] = t + GotoBindingLevel(listCtrl, list_level) + end + elseif (data_index > 1) and listData[list_level].object_type == "wxLuaBindMethod" then + local t = nil + + if ((col == 0) or (col == 2)) and (type(listData[list_level][data_index][3]) == "table") then + t = CreatewxLuaBindCFunc(listData[list_level][data_index][3]) + t.class_name = listData[list_level].class_name + elseif (col == 4) and (type(listData[list_level][data_index][col+1]) == "userdata") then + t = CreatewxLuaBindMethod({listData[list_level][data_index][col+1]}) + t.class_name = listData[list_level][data_index][col+1].class_name + end + + if t ~= nil then + list_level = list_level + 1 + listData[list_level] = t + GotoBindingLevel(listCtrl, list_level) + end + end + + event:Skip(); + + end + + -- ---------------------------------------------------------------------------- + -- The main program, call this to start the program + -- ---------------------------------------------------------------------------- function main() frame = wx.wxFrame(wx.NULL, wx.wxID_ANY, "wxLua Binding Browser") + -- ----------------------------------------------------------------------- -- Create the menu bar local fileMenu = wx.wxMenu() *************** *** 490,494 **** "You can view the C++ bindings by navigating the wxListCtrl.\n".. wx.wxLUA_VERSION_STRING.." built with "..wx.wxVERSION_STRING, ! "About wxLua Bindings", wx.wxOK + wx.wxICON_INFORMATION, frame) --- 732,736 ---- "You can view the C++ bindings by navigating the wxListCtrl.\n".. wx.wxLUA_VERSION_STRING.." built with "..wx.wxVERSION_STRING, ! "About wxLua Binding Browser", wx.wxOK + wx.wxICON_INFORMATION, frame) *************** *** 496,514 **** frame:Connect(wx.wxID_HELP, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) ! wx.wxMessageBox("Select the C++ bindings to view and then you can see the items that\n".. ! "have been wrapped. You can expand items that have a folder icon \n".. ! " in the column header by double clicking on the item's column. \n".. ! "Use the '..' to go up a level.\n\n".. "This data is from the structs declared in \n".. "wxLua/modules/wxlua/include/wxlbind.h.", ! "Help on wxLua Bindings", wx.wxOK + wx.wxICON_INFORMATION, frame) end ) ! frame:CreateStatusBar(1) frame:SetStatusText("Welcome to wxLua.") -- Create the windows panel = wx.wxPanel(frame, wx.wxID_ANY) --- 738,759 ---- frame:Connect(wx.wxID_HELP, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) ! wx.wxMessageBox("Select the C++ bindings to view and then the items that\n".. ! "have been wrapped. You can expand items that have a folder\n".. ! "icon by double clicking on the item's column. \n".. ! "Use the '..' to go up a level.\n".. ! "Left-click column headers to sort.\n\n".. "This data is from the structs declared in \n".. "wxLua/modules/wxlua/include/wxlbind.h.", ! "Help on wxLua Binding Browser", wx.wxOK + wx.wxICON_INFORMATION, frame) end ) ! -- ----------------------------------------------------------------------- ! -- Create the status bar frame:CreateStatusBar(1) frame:SetStatusText("Welcome to wxLua.") + -- ----------------------------------------------------------------------- -- Create the windows panel = wx.wxPanel(frame, wx.wxID_ANY) *************** *** 520,526 **** --- 765,778 ---- imageList:Add(wx.wxArtProvider.GetBitmap(wx.wxART_NORMAL_FILE, wx.wxART_MENU, wx.wxSize(16,16))) imageList:Add(wx.wxArtProvider.GetBitmap(wx.wxART_FOLDER, wx.wxART_MENU, wx.wxSize(16,16))) + imageList:Add(wx.wxArtProvider.GetBitmap(wx.wxART_GO_DOWN, wx.wxART_MENU, wx.wxSize(16,16))) + imageList:Add(wx.wxArtProvider.GetBitmap(wx.wxART_GO_UP, wx.wxART_MENU, wx.wxSize(16,16))) listCtrl:SetImageList(imageList, wx.wxIMAGE_LIST_SMALL); + listCtrl:Connect(wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED, OnListItemActivated) + listCtrl:Connect(wx.wxEVT_COMMAND_LIST_COL_CLICK, OnListColClicked) + + list_level = 1 listData[1] = { + {"wxLua Types", "Compare Lua's type to wxLua's type", ["icon"] = img_folder }, {"wx", "wxLuaBinding_wx", ["icon"] = img_folder }, {"wx", "wxLuaBinding_wxstc", ["icon"] = img_folder }, *************** *** 532,662 **** GotoBindingLevel(listCtrl, 1) ! listCtrl:Connect(wx.wxEVT_COMMAND_LIST_ITEM_ACTIVATED, ! function(event) ! local index = event:GetIndex() ! local itemText = listCtrl:GetItemText(index) ! ! -- Find what column we're in ! --local col = event:GetColumn() -- both of these don't work in MSW ! --local pt = event:GetPoint() ! ! local mousePos = wx.wxGetMousePosition() ! local framePos = frame:GetPosition() ! local winPos = listCtrl:GetPosition() ! local scrollPos = listCtrl:GetScrollPos(wx.wxHORIZONTAL) ! local x = mousePos:GetX() + scrollPos - framePos:GetX() - winPos:GetX() ! local w = 0 ! ! --print(x, mousePos:GetX(), scrollPos, framePos:GetX(), winPos:GetX()) ! ! for c = 1, listCtrl:GetColumnCount() do ! w = w + listCtrl:GetColumnWidth(c-1) ! if x < w then ! col = c-1 ! break ! end ! end ! ! SaveListColWidths(list_level) ! ! if (itemText == "..") then ! list_level = list_level - 1 ! GotoBindingLevel(listCtrl, list_level) ! elseif (list_level == 1) then ! local binding = _G ! for i = 1, #listData[1][index+1] do ! binding = binding[listData[1][index+1][i]] ! end ! ! listData[2] = { ! {"..", ["icon"] = img_folder}, ! {"GetBindingName", tostring(binding.GetBindingName)}, ! {"GetLuaNamespace", tostring(binding.GetLuaNamespace)}, ! ! {"GetClassArray", "GetClassCount : "..tostring(binding.GetClassCount), ["icon"] = img_folder}, ! {"GetFunctionArray", "GetFunctionCount : "..tostring(binding.GetFunctionCount), ["icon"] = img_folder}, ! {"GetDefineArray", "GetDefineCount : "..tostring(binding.GetDefineCount), ["icon"] = img_folder}, ! {"GetStringArray", "GetStringCount : "..tostring(binding.GetStringCount), ["icon"] = img_folder}, ! {"GetEventArray", "GetEventCount : "..tostring(binding.GetEventCount), ["icon"] = img_folder}, ! {"GetObjectArray", "GetObjectCount : "..tostring(binding.GetObjectCount), ["icon"] = img_folder}, ! ! ["col_labels"] = {"Function Name", "Value"}, ! ["binding"] = binding, ! ["object_type"] = "wxLuaBinding" ! } ! ! listData[list_level].list_item = index ! list_level = list_level + 1 ! GotoBindingLevel(listCtrl, list_level) ! elseif (list_level == 2) then ! local binding = listData[2].binding ! ! local t = nil ! ! if (itemText == "GetClassArray") then ! t = CreatewxLuaBindClass(binding.GetClassArray) ! elseif (itemText == "GetFunctionArray") then ! t = CreatewxLuaBindMethod(binding.GetFunctionArray) ! elseif (itemText == "GetDefineArray") then ! t = CreatewxLuaBindDefine(binding.GetDefineArray) ! elseif (itemText == "GetStringArray") then ! t = CreatewxLuaBindString(binding.GetStringArray) ! elseif (itemText == "GetEventArray") then ! t = CreatewxLuaBindEvent(binding.GetEventArray) ! elseif (itemText == "GetObjectArray") then ! t = CreatewxLuaBindObject(binding.GetObjectArray) ! end ! ! if t ~= nil then ! listData[list_level].list_item = index ! list_level = list_level + 1 ! listData[list_level] = t ! GotoBindingLevel(listCtrl, list_level) ! end ! elseif (index > 0) and listData[list_level].object_type == "wxLuaBindClass" then ! local t = nil ! ! if ((col == 0) or (col == 1)) and (type(listData[list_level][index+1][2]) == "table") then ! t = CreatewxLuaBindMethod(listData[list_level][index+1][2]) ! elseif (col == 6) and (type(listData[list_level][index+1][col+1]) == "userdata") then ! t = CreatewxLuaBindClass({listData[list_level][index+1][col+1]}) ! elseif (col == 7) and (type(listData[list_level][index+1][col+1]) == "table") then ! t = CreatewxLuaBindDefine(listData[list_level][index+1][col+1]) ! end ! ! if t ~= nil then ! t.class_name = listCtrl:GetItemText(index) ! ! listData[list_level].list_item = index ! list_level = list_level + 1 ! listData[list_level] = t ! GotoBindingLevel(listCtrl, list_level) ! end ! elseif (index > 0) and listData[list_level].object_type == "wxLuaBindMethod" then ! local t = nil ! ! if ((col == 0) or (col == 2)) and (type(listData[list_level][index+1][3]) == "table") then ! t = CreatewxLuaBindCFunc(listData[list_level][index+1][3]) ! t.class_name = listData[list_level].class_name ! elseif (col == 4) and (type(listData[list_level][index+1][col+1]) == "userdata") then ! t = CreatewxLuaBindMethod({listData[list_level][index+1][col+1]}) ! t.class_name = listData[list_level][index+1][col+1].class_name ! end ! ! if t ~= nil then ! listData[list_level].list_item = index ! list_level = list_level + 1 ! listData[list_level] = t ! GotoBindingLevel(listCtrl, list_level) ! end ! end ! ! event:Skip(); ! end) ! ! rootSizer = wx.wxBoxSizer(wx.wxVERTICAL); rootSizer:Add(listCtrl, 1, wx.wxEXPAND + wx.wxALL, 0); ! rootSizer:SetMinSize(450, 400); panel:SetSizer(rootSizer); rootSizer:SetSizeHints(frame); --- 784,792 ---- GotoBindingLevel(listCtrl, 1) ! -- ----------------------------------------------------------------------- ! -- Create the sizer to layout the windows rootSizer = wx.wxBoxSizer(wx.wxVERTICAL); rootSizer:Add(listCtrl, 1, wx.wxEXPAND + wx.wxALL, 0); ! rootSizer:SetMinSize(600, 420); panel:SetSizer(rootSizer); rootSizer:SetSizeHints(frame); Index: unittest.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/unittest.wx.lua,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** unittest.wx.lua 5 Jun 2007 21:07:26 -0000 1.8 --- unittest.wx.lua 11 Jun 2007 03:58:11 -0000 1.9 *************** *** 75,78 **** --- 75,97 ---- PrintOk(a:FindOrCreatePen(wx.wxRED, 1, wx.wxSOLID):Ok(), "Test %define_pointer wxThePenList:FindOrCreatePen(wx.wxRED, 1, wx.wxSOLID) is Ok()") + a = wx.wxString("Hello") + PrintOk(a:GetData() == "Hello", "Test automatic overload of wxString(\"lua string\")") + b = wx.wxString(a) + PrintOk(b:GetData() == "Hello", "Test automatic overload of wxString(wxString)") + b = wx.wxFileName("Hello") + PrintOk(b:GetFullPath() == "Hello", "Test automatic overload of wxFileName(\"lua string\")") + b = wx.wxFileName(a) + PrintOk(b:GetFullPath() == "Hello", "Test automatic overload of wxFileName(wxString)") + + a = wx.wxArrayString({"a", "b", "c"}) + PrintOk((a:Item(0) == "a") and (a:GetCount() == 3), "Test automatic overload of wxArrayString(lua table)") + b = wx.wxArrayString(a) + PrintOk((b:Item(1) == "b") and (b:GetCount() == 3), "Test automatic overload of wxArrayString(wxArrayString)") + + a = wx.wxArrayInt({1, 2, 3}) + PrintOk((a:Item(0) == 1) and (a:GetCount() == 3), "Test automatic overload of wxArrayInt(lua table)") + b = wx.wxArrayInt(a) + PrintOk((b:Item(1) == 2) and (b:GetCount() == 3), "Test automatic overload of wxArrayInt(wxArrayInt)") + -- --------------------------------------------------------------------------- print("\nTest some binding class functions.\n") Index: printing.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/printing.wx.lua,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** printing.wx.lua 31 May 2007 17:18:56 -0000 1.13 --- printing.wx.lua 11 Jun 2007 03:58:11 -0000 1.14 *************** *** 164,168 **** ConnectPrintEvents(previewPrintout) ! local printDialogData = wx.wxPrintDialogDataFromPrintData(printData):GetPrintData() local preview = wx.wxPrintPreview(printerPrintout, previewPrintout, printDialogData) local result = preview:Ok() --- 164,168 ---- ConnectPrintEvents(previewPrintout) ! local printDialogData = wx.wxPrintDialogData(printData):GetPrintData() local preview = wx.wxPrintPreview(printerPrintout, previewPrintout, printDialogData) local result = preview:Ok() *************** *** 190,193 **** --- 190,194 ---- function PrintSetup() + -- NOTE : this function crashes in wxWidgets GTK wxWidgets 2.8.2 local printDialogData = wx.wxPrintDialogData(printData) local printerDialog = wx.wxPrintDialog(frame, printDialogData) *************** *** 219,223 **** dc:SetPen(wx.wxTRANSPARENT_PEN) dc:SetBrush(wx.wxWHITE_BRUSH) ! local w, h = frame:GetClientSize() dc:DrawRectangle(0, 0, w, h) -- draw our figure --- 220,224 ---- dc:SetPen(wx.wxTRANSPARENT_PEN) dc:SetBrush(wx.wxWHITE_BRUSH) ! local w, h = frame:GetClientSizeWH() dc:DrawRectangle(0, 0, w, h) -- draw our figure |