forked from pkulchenko/wxlua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbindings.wx.lua
More file actions
1576 lines (1282 loc) · 56.7 KB
/
bindings.wx.lua
File metadata and controls
1576 lines (1282 loc) · 56.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-----------------------------------------------------------------------------
-- Name: bindings.wx.lua
-- Purpose: Show wxLua bindings in a wxListCtrl or dump them using print
-- Author: john Labenski
-- Modified by:
-- Created: 5/7/2007
-- RCS-ID:
-- Copyright: (c) John Labenski
-- Licence: wxWidgets licence
-----------------------------------------------------------------------------
-- Load the wxLua module, does nothing if running from wxLua, wxLuaFreeze, or wxLuaEdit
package.cpath = package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;"
require("wx")
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Brute force dump of the binding info using print statements for debugging
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
function ColumnDumpTable(t, keys, funcs)
funcs = funcs or {}
local function GetTableValue(tbl, key)
if funcs[key] then
return funcs[key](tbl[key])
end
return tostring(tbl[key])
end
local lens = {}
for i = 1, #keys do
lens[i] = string.len(keys[i])
end
for i = 1, #t do
local u = t[i]
for k = 1, #keys do
local len = string.len(GetTableValue(u, keys[k]))
if (len > lens[k]) then
lens[k] = len
end
end
end
local s = ""
for k = 1, #keys do
local val = tostring(keys[k])
local buf = string.rep(" ", lens[k] - string.len(val) + 1)
s = s..val..buf
end
print(s)
for i = 1, #t do
local u = t[i]
local s = ""
for k = 1, #keys do
local val = GetTableValue(u, keys[k])
local buf = string.rep(" ", lens[k] - string.len(val) + 1)
s = s..val..buf
end
print(s)
end
end
function GetBindingObjectKeys(binding_obj)
local keys = {}
if type(binding_obj) == "table" then
for k, v in pairs(binding_obj) do
keys[#keys+1] = k
end
elseif (type(binding_obj) == "userdata") and (type(binding_obj.fields) == "table") then
keys = binding_obj.fields
end
return keys
end
function TableToString(tbl, sep, prefix, postfix)
if #tbl == 0 then return "" end
return (prefix or "")..table.concat(tbl, sep)..(postfix or "")
end
function iff(condition, return_if_true, return_if_false)
if condition then return return_if_true else return return_if_false end
end
function DumpBindingInfo(binding)
print("GetBindingName : "..tostring(binding.GetBindingName))
print("GetLuaNamespace : "..tostring(binding.GetLuaNamespace))
print("GetClassCount : "..tostring(binding.GetClassCount))
print("GetNumberCount : "..tostring(binding.GetNumberCount))
print("GetStringCount : "..tostring(binding.GetStringCount))
print("GetEventCount : "..tostring(binding.GetEventCount))
print("GetObjectCount : "..tostring(binding.GetObjectCount))
print("GetFunctionCount : "..tostring(binding.GetFunctionCount))
--print("GetClassArray : "..tostring(#binding.GetClassArray))
--print("GetFunctionArray : "..tostring(#binding.GetFunctionArray))
--print("GetNumberArray : "..tostring(#binding.GetNumberArray))
--print("GetStringArray : "..tostring(#binding.GetStringArray))
--print("GetEventArray : "..tostring(#binding.GetEventArray))
--print("GetObjectArray : "..tostring(#binding.GetObjectArray))
if true then
local classArray = binding.GetClassArray
print("\nDUMPING binding.GetClassArray ==================================\n")
--local keys = GetBindingObjectKeys(classArray[1])
local keys = { "name", --[["wxluamethods",]] "wxluamethods_n", "classInfo", --[["wxluatype",]] "baseclassNames", --[["baseBindClasses", "enums",]] "enums_n" }
ColumnDumpTable(classArray, keys,
{classInfo=function(ci) if ci then return ci:GetClassName() end return "" end,
baseclassNames=function(tbl) return table.concat(tbl, ",") end} )
print(" ")
for i, class in ipairs(classArray) do
print("class "..class.name..TableToString(class.baseclassNames, ", ", " : public ").."\n{")
if class.enums_n > 0 then
print(" enum\n {")
for j, enum in pairs(class.enums) do
print(" "..enum.name.." = "..enum.value..",")
end
print(" };\n")
end
for j, method in ipairs(class.wxluamethods) do
for j, func in ipairs(method.wxluacfuncs) do
local type_str = CreatewxLuaMethod_TypeString(func.method_type)
local s = iff(string.find(type_str, "static"), "static ", "")..method.name.."("..
CreateArgTagsString(func.argtypes, method.method_type)..");"
print(" "..s)
end
end
print("};\n")
end
end
if true then
print("\nDUMPING binding.GetFunctionArray ==================================\n")
--local keys = { "name", "method_type", "wxluacfuncs", "wxluacfuncs_n", "basemethod" }
--ColumnDumpTable(binding.GetFunctionArray, keys)
for j, method in ipairs(binding.GetFunctionArray) do
for j, func in ipairs(method.wxluacfuncs) do
local s = method.name.."("
s = s..CreateArgTagsString(func.argtypes, method.method_type)
print(s..");") -- ..CreatewxLuaMethod_TypeString(func.method_type))
end
end
end
if true then
print("\nDUMPING binding.GetNumberArray ==================================\n")
local keys = { "name", "value" }
ColumnDumpTable(binding.GetNumberArray, keys)
end
if true then
print("\nDUMPING binding.GetStringArray ==================================\n")
local keys = { "name", "value" }
ColumnDumpTable(binding.GetStringArray, keys, {value=function(v) return "'"..v.."'" end} )
end
if true then
print("\nDUMPING binding.GetEventArray ==================================\n")
local keys = { "name", "eventType", "wxLuaBindClass" }
ColumnDumpTable(binding.GetEventArray, keys, {wxLuaBindClass=function(c) return c.name end} )
end
if true then
print("\nDUMPING binding.GetObjectArray ==================================\n")
--local keys = { "name", "wxLuaBindClass" }
--ColumnDumpTable(binding.GetObjectArray, keys, {wxLuaBindClass=function(c) return c.name end})
for i, obj in ipairs(binding.GetObjectArray) do
print(obj.wxLuaBindClass.name.." "..obj.name..";")
end
end
end
-- Call DumpBindingInfo(...) on the binding you want to show
--DumpBindingInfo(wxlua.GetBindings()[1])
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- A wxLua program to view the bindings in a wxListCtrl
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
frame = nil
listCtrl = nil
ID_LISTCTRL = 1000 -- id of the listctrl
ID_VIEW_BASECLASS_FUNCTIONS = 1001
ID_STACK_DIALOG = 1002
list_images = {
["normal"] = 0, -- file image
["folder"] = 1, -- folder
["sort_dn"] = 2, -- down arrow
["sort_up"] = 3, -- up arrow
}
list_colors = {
["purple"] = wx.wxColour("purple"),
["green"] = wx.wxColour(0, 180, 0),
}
listColWidths = {} -- stored by "object_type" name
list_level = 1 -- where are we in the listData
listData = {} -- store the table currently displayed by the listCtrl
-- {{"col val 1", "val2", ... ["icon"] = list_images.normal, ["color"] = wx.wxBLUE },
-- {"col val 1", "val2", ... ["col_icons"] = {["col#"] = true, ...}},
-- {"col val 1", "val2", ... ["data"] = {["col#"] = some data, ...}},
-- {"col val 1", "val2", ... icon, color, col_icons, data are optional },
-- { ... these are numbered items for the rows },
-- ["col_labels"] = { "col label 1", "col label 2", ...},
-- ["object_type"] = "wxLuaBindClass", -- or something else readable
-- ["list_item"] = last selected list item or nil if not set
bindingList = wxlua.GetBindings() -- Table of {wxLuaBinding functions}
-- ----------------------------------------------------------------------------
-- Function to simulate var = cond ? a : b
-- ----------------------------------------------------------------------------
function iff(cond, a, b) if cond then return a else return b end end
-- ----------------------------------------------------------------------------
-- Save the current listctrl settings into the listColWidths table
-- ----------------------------------------------------------------------------
function SaveListColWidths(level)
local object_type = listData[level].object_type
if not listColWidths[object_type] then
listColWidths[object_type] = {}
end
for col = 1, listCtrl:GetColumnCount() do
listColWidths[object_type][col] = listCtrl:GetColumnWidth(col-1)
end
end
-- ----------------------------------------------------------------------------
-- Go to a binding level which already must exist in the listData table
-- ----------------------------------------------------------------------------
function GotoBindingLevel(listCtrl, level)
wx.wxBeginBusyCursor();
local data = listData[level]
-- Do we calculate what widths to use for the cols or use previous values?
local auto_col_widths = false
if listColWidths[data.object_type] == nil then
auto_col_widths = true
listColWidths[data.object_type] = {}
end
local function AutoColWidth(col, txt)
if auto_col_widths and txt then
local w = listCtrl:GetTextExtent(txt)
if w > (listColWidths[data.object_type][col] or 0) - 25 then
if w > 400 then w = 400 end
listColWidths[data.object_type][col] = w + 25
end
end
end
-- Wipe items and extra cols
listCtrl:DeleteAllItems()
while #data.col_labels < listCtrl:GetColumnCount() do
listCtrl:DeleteColumn(0)
end
-- Add the cols
for col = 1, #data.col_labels do
if col > listCtrl:GetColumnCount() then
listCtrl:InsertColumn(col-1, data.col_labels[col], wx.wxLIST_FORMAT_LEFT, -1)
else
local li = wx.wxListItem()
li:SetText(data.col_labels[col])
li:SetImage(-1)
listCtrl:SetColumn(col-1, li)
end
if data.col_sorted and data.col_sorted[col] then
listCtrl:SetColumnImage(col-1, data.col_sorted[col])
end
AutoColWidth(col, data.col_labels[col])
end
-- Add the items
local lc_item = 0
for i = 1, #data do
local d = data[i]
local li = wx.wxListItem()
li:SetId(lc_item+1)
li:SetText(tostring(d[1] or ""))
li:SetData(i) -- key into the listData table for sorting
if (d.icon) then li:SetImage(d.icon) end
if (d.color) then li:SetTextColour(d.color) end
lc_item = listCtrl:InsertItem(li)
AutoColWidth(1, tostring(d[1]))
for col = 2, #listData[level].col_labels do
listCtrl:SetItem(lc_item, col-1, tostring(d[col] or ""))
if d.col_icons and d.col_icons[col] then
listCtrl:SetItemColumnImage(lc_item, col-1, d.col_icons[col])
end
AutoColWidth(col, tostring(d[col]))
end
end
-- Set the column widths
if listColWidths[data.object_type] then
for col = 1, #listColWidths[data.object_type] do
listCtrl:SetColumnWidth(col-1, listColWidths[data.object_type][col])
end
end
-- Try to reselect the item if we're going up a level
if data.list_item and (data.list_item < listCtrl:GetItemCount()) then
listCtrl:SetItemState(data.list_item, wx.wxLIST_STATE_FOCUSED, wx.wxLIST_STATE_FOCUSED);
listCtrl:SetItemState(data.list_item, wx.wxLIST_STATE_SELECTED, wx.wxLIST_STATE_SELECTED);
listCtrl:EnsureVisible(data.list_item)
end
-- Finally set the status text of where we are
local s = {}
for i = 1, level do
table.insert(s, listData[i].object_type)
end
frame:SetStatusText(table.concat(s, "->"))
wx.wxEndBusyCursor();
end
-- ----------------------------------------------------------------------------
-- Convert the wxLuaMethod_Type enum into a readable string
-- ----------------------------------------------------------------------------
function CreatewxLuaMethod_TypeString(t_)
local s = {}
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, wxlua.WXLUAMETHOD_DELETE, s, "delete")
t = HasBit(t, wxlua.WXLUAMETHOD_STATIC, s, "static")
t = HasBit(t, wxlua.WXLUAMETHOD_SETPROP, s, "setprop")
t = HasBit(t, wxlua.WXLUAMETHOD_GETPROP, s, "getprop")
t = HasBit(t, wxlua.WXLUAMETHOD_CFUNCTION, s, "cfunc")
t = HasBit(t, wxlua.WXLUAMETHOD_METHOD, s, "method")
t = HasBit(t, wxlua.WXLUAMETHOD_CONSTRUCTOR, s, "constructor")
assert(t == 0, "The wxLuaMethod_Type is not handled correctly, remainder "..tostring(t).." of "..tostring(t_))
--return string.format("0x%04X (%s)", t_, table.concat(s, ", "))
return table.concat(s, ", ")
end
-- ----------------------------------------------------------------------------
-- Convert the argtypes table into a readable string
-- ----------------------------------------------------------------------------
function CreateArgTagsString(args_table, wxlua_type)
local arg_names = {}
for j = 1, #args_table do
local s = wxlua.typename(args_table[j])
-- The first arg for a class member function is the self
if (j == 1) and
(bit.band(wxlua_type, wxlua.WXLUAMETHOD_CFUNCTION) == 0) and
(bit.band(wxlua_type, wxlua.WXLUAMETHOD_CONSTRUCTOR) == 0) and
(bit.band(wxlua_type, wxlua.WXLUAMETHOD_STATIC) == 0) then
s = "self"
end
table.insert(arg_names, s)
end
return table.concat(arg_names, ", ")
end
-- ----------------------------------------------------------------------------
-- Create a list table from a wxLuaBindClass struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindClass(tbl)
local t = {
{"..", ["icon"] = list_images.folder},
["col_labels"] = { "Class Name", "# Methods", "wxClassInfo", "Class Tag", "Base Class Names", "# Enums", "VTable Offsets" },
["object_type"] = "wxLuaBindClass"
}
-- items in table from binding.GetClassArray are these
-- { "name", "wxluamethods", "wxluamethods_n", "classInfo", "wxluatype", "baseclassNames", "baseBindClasses", "baseclass_wxluatypes", "baseclass_vtable_offsets", "enums", "enums_n" }
local function GetClassInfoStr(classInfo)
local s = ""
if type(classInfo) == "userdata" then
s = classInfo:GetClassName()
local b1 = classInfo:GetBaseClassName1()
local b2 = classInfo:GetBaseClassName2()
if (string.len(b1) > 0) then
s = s.." ("..b1..")"
end
if (string.len(b2) > 0) then
s = s.."("..b2..")"
end
end
return s
end
local function GetVTableOffsets(cbind_tbl)
local s = ""
local baseclass_wxluatypes = cbind_tbl.baseclass_wxluatypes
local baseclass_vtable_offsets = cbind_tbl.baseclass_vtable_offsets
if baseclass_wxluatypes then
for i = 1, #baseclass_wxluatypes do
s = s..string.format("%s(+%d),", wxlua.typename(baseclass_wxluatypes[i]), baseclass_vtable_offsets[i])
end
s = string.sub(s, 1, -2)
end
return s
end
t.col_numbers = {}
t.col_numbers[2] = true
t.col_numbers[4] = true
t.col_numbers[6] = true
--{ "name"[data], "wxluamethods_n", "classInfo", "wxluatype", "baseclassNames"[data], "enums_n"[data] }
for i = 1, #tbl do
local item = {
tbl[i].name,
tbl[i].wxluamethods_n,
GetClassInfoStr(tbl[i].classInfo),
tbl[i].wxluatype,
table.concat(tbl[i].baseclassNames or {}, ","),
tbl[i].enums_n,
GetVTableOffsets(tbl[i]),
["col_icons"] = {},
["data"] = {}
}
-- This class has methods and can be expanded
if (type(tbl[i].wxluamethods) == "table") then
item.icon = list_images.folder
item.data[1] = tbl[i].wxluamethods
end
-- This class has a baseclass and can be expanded
if (type(tbl[i].baseBindClasses) == "table") then
item.col_icons[5] = list_images.folder
item.data[5] = tbl[i].baseBindClasses
end
-- This class has enums and can be expanded
if (type(tbl[i].enums) == "table") then
item.col_icons[6] = list_images.folder
item.data[6] = tbl[i].enums
end
-- some sanity checks to make sure the bindings are working
if (tbl[i].wxluamethods_n > 0) and (type(tbl[i].wxluamethods) ~= "table") then
print(tbl[i].name, "is missing methods table, please report this.")
end
if (tbl[i].baseclassNames) and (type(tbl[i].baseBindClasses) ~= "table") then
print(tbl[i].name, "is missing baseclass userdata, please report this.")
end
if (tbl[i].enums_n > 0) and (type(tbl[i].enums) ~= "table") then
print(tbl[i].name, "is missing enums table, please report this.")
end
table.insert(t, item)
end
return t
end
-- ----------------------------------------------------------------------------
-- Create a list table from a wxLuaBindMethod struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindMethod(tbl, classname)
local t = {
{"..", ["icon"] = list_images.folder},
["col_labels"] = { "name", "method_type", "function", "basemethod", "minargs", "maxargs", "argtype_names", "argtypes" },
["object_type"] = "wxLuaBindMethod"
}
-- items in table are
-- { "name", "type", "wxluacfuncs", "wxluacfuncs_n", "basemethod" }
t.col_numbers = {}
t.col_numbers[3] = true
t.col_numbers[5] = true
t.col_numbers[6] = true
for i = 1, #tbl do
local class_name = ""
if tbl[i].class_name then
class_name = tbl[i].class_name.."::"
end
if classname then
class_name = classname.."::"
end
-- keys for CFunc = { "lua_cfunc", "type", "minargs", "maxargs", "argtype_names", "argtypes" }
local cfunc_t = CreatewxLuaBindCFunc(tbl[i].wxluacfuncs)
for j = 2, #cfunc_t do
local cft = {
class_name..tbl[i].name,
cfunc_t[j][2],
tostring(cfunc_t[j][1]),
"",
cfunc_t[j][3],
cfunc_t[j][4],
cfunc_t[j][5],
cfunc_t[j][6],
["icon"] = nil,
["col_icons"] = {},
["data"] = {}
}
if string.find(cfunc_t[j][2], "Overload", 1, 1) then
cft.color = list_colors.green
end
if #cfunc_t > 2 then
cft[1] = cft[1].." "..tostring(j-1)
end
-- This method has a basemethod and can be expanded
if type(tbl[i].basemethod) == "userdata" then
cft[4] = tbl[i].basemethod.class_name
cft.data[4] = tbl[i].basemethod
cft.col_icons[4] = list_images.folder
end
table.insert(t, cft)
end
end
return t
end
-- ----------------------------------------------------------------------------
-- Create a list table from a wxLuaBindNumber struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindNumber(tbl)
local keys = { "name", "value" }
local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindNumber")
t.col_numbers = {}
t.col_numbers[2] = true
-- these are often enums or flags, it's easier to see them as hex
table.insert(t.col_labels, "hex")
for i = 2, #t do
-- print 0xffffffff for -1
t[i][3] = string.format("0x%X", (t[i][2] < 0) and (2^32 + t[i][2]) or t[i][2])
end
return t
end
-- ----------------------------------------------------------------------------
-- Create a list table from a wxLuaBindString struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindString(tbl)
local keys = { "name", "value" }
return CreatewxLuaBindTable(tbl, keys, "wxLuaBindString")
end
-- ----------------------------------------------------------------------------
-- Create a list table from a wxLuaBindEvent struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindEvent(tbl)
local keys = { "name", "eventType", "wxluatype", "wxLuaBindClass" }
local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindEvent")
t.col_numbers = {}
t.col_numbers[2] = true
-- Add the class tag name for the event
for i = 2, #t do
t[i][3] = wxlua.typename(t[i][3]).." ("..t[i][3]..")"
-- if t[i-1][2] == t[i][2] then t[i].color = wx.wxRED end -- see if there's dups, there's a couple, but they're right
-- Set the wxLuaBindClass for this event type
if type(t[i][4]) == "userdata" then
local c = t[i][4]
t[i][4] = c.name
t[i].data = {}
t[i].data[4] = c
t[i].col_icons = {}
t[i].col_icons[4] = list_images.folder
end
end
return t
end
-- ----------------------------------------------------------------------------
-- Create a list table from a wxLuaBindObject struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindObject(tbl)
local keys = { "name", "object", "wxluatype", "wxLuaBindClass" }
local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindObject")
-- Add the class tag name for the user data
for i = 2, #t do
t[i][3] = wxlua.typename(t[i][3]).." ("..t[i][3]..")"
-- Set the wxLuaBindClass for this object
if type(t[i][4]) == "userdata" then
local c = t[i][4]
t[i][4] = c.name
t[i].data = {}
t[i].data[4] = c
t[i].col_icons = {}
t[i].col_icons[4] = list_images.folder
end
end
return t
end
-- ----------------------------------------------------------------------------
-- Create a list table from a wxLuaBindCFunc struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindCFunc(tbl)
local keys = { "lua_cfunc", "method_type", "minargs", "maxargs", "argtypes" }
local t = CreatewxLuaBindTable(tbl, keys, "wxLuaBindCFunc")
t.col_labels[5] ="argtype_names" -- swap these two
t.col_labels[6] ="argtypes"
t.col_numbers = {}
t.col_numbers[3] = true
t.col_numbers[4] = true
-- we don't want to show the table, just show the values
for i = 2, #t do
local args = t[i][5]
t[i][5] = CreateArgTagsString(args, t[i][2]) -- swap these two
t[i][6] = table.concat(args, ", ")
t[i][2] = CreatewxLuaMethod_TypeString(t[i][2])
end
return t
end
-- ----------------------------------------------------------------------------
-- Generically Create a list table from a wxLuaBindXXX struct table
-- ----------------------------------------------------------------------------
function CreatewxLuaBindTable(tbl, cols, object_type)
local t = {
{"..", ["icon"] = list_images.folder},
["col_labels"] = cols,
["object_type"] = object_type
}
--local keys = {} -- used to find dups
for i = 1, #tbl do
local item = {}
for c = 1, #cols do
-- we need to force there to be something in each col, use ""
local val = tbl[i][cols[c]]
if val ~= nil then
table.insert(item, val)
else
table.insert(item, "")
end
end
--if keys[tbl[i]] then item.color = wx.wxRED end -- check dup keys
--keys[tbl[i]] = true
table.insert(t, item)
end
return t
end
-- ----------------------------------------------------------------------------
-- Sort items in the listctrl based on the column (0 based) and also the data table
-- ----------------------------------------------------------------------------
function SortListItems(col)
local data = listData[list_level]
local sorted = false
if data.col_sorted and data.col_sorted[col+1] then
sorted = data.col_sorted[col+1] == list_images.sort_dn
end
local function SortListItems(item1, item2, col)
local data1 = data[item1]
local data2 = data[item2]
if data1[1] == ".." then return -1 end
if data2[1] == ".." then return 1 end
local i1 = data1[col]
local i2 = data2[col]
if data.col_numbers and data.col_numbers[col] 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)
data.col_sorted = {} -- we only remember the last col sorted
if not sorted then
data.col_sorted[col+1] = list_images.sort_dn
else
data.col_sorted[col+1] = list_images.sort_up
end
-- now make the table of data match what's in the listctrl so when you
-- go up a level it'll stay sorted the same way
-- Note: it seems faster to let the listctrl sort and then match the lua table
-- rather than sort table, clear listctrl, and add it back.
local t = {}
for i = 1, listCtrl:GetItemCount() do
local d = listCtrl:GetItemData(i-1) -- old table indexes
table.insert(t, data[d]) -- table with listctrl order
end
for i = 1, #t do
listData[list_level][i] = t[i] -- update original table
listCtrl:SetItemData(i-1, i) -- fix itemdata to match table indexes
end
-- put the arrow in the col header that we've sorted this col and clear others
for c = 1, listCtrl:GetColumnCount() do
if c ~= col+1 then
listCtrl:SetColumnImage(c-1, -1)
elseif not sorted then
listCtrl:SetColumnImage(col, list_images.sort_dn)
else
listCtrl:SetColumnImage(col, list_images.sort_up)
end
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() -- this is the table index
local itemText = listCtrl:GetItemText(index)
local data = listData[list_level]
listData[list_level].list_item = index -- last clicked
SaveListColWidths(list_level) -- remember user's col widths
-- -----------------------------------------------------------------------
-- 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
-- Handle the different lists we may show
if (itemText == "..") then
list_level = list_level - 1
GotoBindingLevel(listCtrl, list_level)
elseif (list_level == 1) then
if itemText == "wxLua Types" then
list_level = list_level + 1
listData[list_level] = CreatewxLuaTypeTable()
GotoBindingLevel(listCtrl, list_level)
elseif itemText == "All wxLua Classes" then
list_level = list_level + 1
listData[list_level] = CreateAllClassesTable()
GotoBindingLevel(listCtrl, list_level)
elseif itemText == "All wxWidgets wxClassInfo" then
list_level = list_level + 1
listData[list_level] = CreatewxClassInfoTable()
GotoBindingLevel(listCtrl, list_level)
elseif itemText == "Overloaded Baseclass Functions" then
list_level = list_level + 1
listData[list_level] = CreateOverloadedBasecassFunctionsTable()
GotoBindingLevel(listCtrl, list_level)
else
local binding = data[data_index].binding
listData[2] = {
{"..", ["icon"] = list_images.folder},
{"GetBindingName", tostring(binding.GetBindingName)},
{"GetLuaNamespace", tostring(binding.GetLuaNamespace)},
{"GetClassArray", "GetClassCount : "..tostring(binding.GetClassCount), ["icon"] = list_images.folder},
{"GetFunctionArray", "GetFunctionCount : "..tostring(binding.GetFunctionCount), ["icon"] = list_images.folder},
{"GetNumberArray", "GetNumberCount : "..tostring(binding.GetNumberCount), ["icon"] = list_images.folder},
{"GetStringArray", "GetStringCount : "..tostring(binding.GetStringCount), ["icon"] = list_images.folder},
{"GetEventArray", "GetEventCount : "..tostring(binding.GetEventCount), ["icon"] = list_images.folder},
{"GetObjectArray", "GetObjectCount : "..tostring(binding.GetObjectCount), ["icon"] = list_images.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 == "GetNumberArray") then
t = CreatewxLuaBindNumber(binding.GetNumberArray)
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 (data.object_type == "wxLuaBindClass") then
local t = nil
if (col == 0) and (type(data[data_index].data[1]) == "table") then
t = CreatewxLuaBindMethod(data[data_index].data[1], data[data_index][1])
if frame:GetMenuBar():IsChecked(ID_VIEW_BASECLASS_FUNCTIONS) then
print("hi")
local ct = data[data_index].data[5]
local function recurse_baseclasstable(ct, t)
for i, c in ipairs(ct) do
print(c.name)
local tt = CreatewxLuaBindMethod(c.wxluamethods, c.name)
for i = 2, #tt do -- skip ".."
if not (string.find(tt[i][2], "Constructor", 1, 1) or
string.find(t[i][1], "delete", 1, 1)) then
--string.find(t[i][1], "::"..c.name, 1, 1)) then
table.insert(t, tt[i])
end
end
if c.baseBindClasses then
recurse_baseclasstable(c.baseBindClasses, t)
end
end
end
if type(ct) == "table" then
recurse_baseclasstable(ct, t)
end
--while type(ct) == "table" do
-- local tt = CreatewxLuaBindMethod(c.wxluamethods, c.name)
-- for i = 2, #tt do -- skip ".."
-- if not (string.find(tt[i][2], "Constructor", 1, 1) or
-- string.find(t[i][1], "delete", 1, 1)) then
-- --string.find(t[i][1], "::"..c.name, 1, 1)) then
-- table.insert(t, tt[i])
-- end
-- end
-- c = c.baseclass
--end
end
elseif (col == 4) and (type(data[data_index].data[col+1]) == "table") then
t = CreatewxLuaBindClass(data[data_index].data[col+1])
elseif (col == 5) and (type(data[data_index].data[col+1]) == "table") then
t = CreatewxLuaBindNumber(data[data_index].data[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 (data.object_type == "wxLuaBindMethod") then
local t = nil
if (col == 3) and (type(data[data_index].data[col+1]) == "userdata") then
t = CreatewxLuaBindMethod({data[data_index].data[col+1]})
t.class_name = data[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
elseif (data_index > 1) and (data.object_type == "wxLuaBindEvent") then
local t = nil
if (col == 3) and (type(data[data_index].data[col+1]) == "userdata") then
t = CreatewxLuaBindClass({data[data_index].data[col+1]})
end
if t ~= nil then
t.class_name = listCtrl:GetItemText(index)
list_level = list_level + 1