Source

LuaTools / Tools / LuaGUI.lua

Full commit
   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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
local modname = ...;

local realPrint = print;

package.cpath = package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;"
require("wx")

local LuaGUI = {};
_G[modname] = LuaGUI;

--Save the new print and restore the stdout one.
LuaGUI.MsgBoxPrint = print;
print = realPrint;

--Utility for ?: operator
local function iff(test, valTrue, valFalse)
	if(test) then return valTrue else return valFalse end
end

--Utility iterator over all child XML nodes. Nodes of ANY type.
local function ixmlnodes(parNode)
	local currNode = parNode:GetChildren();
	return function()
		local ret = currNode;
		if(currNode) then currNode = currNode:GetNext() end
		return ret;
	end
end

--Iterator over all child XML elements. ONLY elements.
local function ixmlelements(parNode)
	local currNode = parNode:GetChildren();
	return function()
		local ret = currNode;
		if(currNode) then
			repeat
				currNode = currNode:GetNext();
			until((not currNode) or currNode:GetType() == wx.wxXML_ELEMENT_NODE)
		end
		return ret;
	end
end

--Prepare our module data.
--Jump table must be stored in the module in order to survive garbage collection.
local elementJumpTable = {};
LuaGUI.elementJumpTable = elementJumpTable;

--List of all main windows.
local mainWnds = {};

--List of all accelerators for the application.
local accelList = {};

--List of all menu actions for the application, indexed by the id.
local menuActions = {};

--List of main window children by ID.
local idWnds = {};

--List of dialogs by ID.
local dialogs = {};

--List of dlgWnds by dialog ID and window ID.
local dlgWnds = {};

--List of lua functions to execute
local executeFuncs = {};

--Filled in with the filename we are parsing.
local baseFileName = "";

-- Used for adding windows by ID.
local currWindowList = nil;

--Interface functions
local function GetWindow(windowData, ...)
	local dlgName, idWnd = ...;

	--Two parameters only, must be the main window.
	if(not idWnd) then
		return windowData.idWnds[dlgName];
	end
	
	--Get from dialog
	return windowData.dlgWnds[dlgName][idWnd];
end

--Reserving the local variable. Function defined below.
local DoModalData = nil;


function LuaGUI.ParseFile(filename, ...)
	mainWnds = {};
	idWnds = {};
	
	baseFileName = string.match(filename, "[%\\%/]?([^%\\%/]*)$");
	
	local theXmlDoc = wx.wxXmlDocument(filename);
	assert(theXmlDoc, "Could not load XML file " .. filename);
	assert(theXmlDoc:GetRoot(), "Could not load XML file " .. filename);

	local ProcFunc = elementJumpTable[theXmlDoc:GetRoot():GetName()];
	if(ProcFunc) then ProcFunc(nil, nil, theXmlDoc:GetRoot()) end;
	
	local windowData = {};
	windowData.GetWindow = GetWindow;
	windowData.GetDialog = GetDialog;
	windowData.DoModalData = DoModalData;
	windowData.mainWnds = mainWnds;
	windowData.idWnds = idWnds;
	windowData.dialogs = dialogs;
	windowData.dlgWnds = dlgWnds;
	
	function windowData.GetDialog(windowData, idDialog)
		return windowData.dialogs[idDialog];
	end

	function windowData.GetMainWindow(windowData)
		return windowData.mainWnds[1].frameWnd;
	end
	
	function windowData.GetMainAuiManager(windowData)
		return windowData.mainWnds[1].auiMan;
	end
	
	local relativeDir = string.sub(filename, 1, #filename - #baseFileName);
	for i, execFunc in ipairs(executeFuncs) do
		if(type(execFunc) == "string") then
			execFunc = assert(loadfile(relativeDir .. execFunc));
		end
	
		execFunc(windowData, relativeDir, ...);
	end
	
	return windowData;
end


--[[***************************************************
Internal Functions
*******************************************************]]
local function GetNodeBoolProp(currNode, strName, default)
	local bHasProp, prop = currNode:GetPropVal(strName);
	if(bHasProp) then
		if(prop == "true") then return true end;
		if(prop == "false") then return false end;
	end

	return default;
end

local function GetNodeSize(currNode)
	local size = wx.wxSize(wx.wxDefaultSize);
	if(currNode) then
		local width = tonumber(currNode:GetPropVal("width", "-1")) or -1;
		local height = tonumber(currNode:GetPropVal("height", "-1")) or -1;

		if(width ~= -1) then size:SetWidth(width) end;
		if(height ~= -1) then size:SetHeight(height) end;
	end
	
	
	return size;
end

local function GetOrientation(currNode)
	local orientation = currNode:GetPropVal("orient", "vertical");
	if(orientation == "horizontal") then
		return wx.wxHORIZONTAL;
	else
		return wx.wxVERTICAL;
	end
	
	return orientation;
end

local function GetBoxSizerOrientation(currNode)
	local bHasProp, orientation = currNode:GetPropVal("box.orient");
	if(bHasProp) then
		if(orientation == "horizontal") then
			return wx.wxHORIZONTAL;
		else
			if(orientation == "vertical") then
				return wx.wxVERTICAL;
			else
				assert(0, "box.orient attribute must be 'horizontal' or 'vertical'.");
			end
		end
	else
		orientation = currNode:GetPropVal("orient", "vertical");
		if(orientation == "horizontal") then
			return wx.wxHORIZONTAL;
		else
			if(orientation == "vertical") then
				return wx.wxVERTICAL;
			else
				assert(0, "orient attribute must be 'horizontal' or 'vertical'.");
			end
		end
	end
	
	return nil;
end

local function CalcGridProportions(strGridProport)
	local ret = {};
	for colRow, proportion in strGridProport:gmatch("(%d+)=(%d+)") do
		ret[tonumber(colRow)] = tonumber(proportion);
	end
	return ret;
end

local function CreateStandardSizer(currNode)
	if(currNode:HasProp("grid.numCols") or currNode:HasProp("grid.numRows")) then
		local bFixed = GetNodeBoolProp(currNode, "grid.fixed", false);
		local numColumns = tonumber(currNode:GetPropVal("grid.numCols", "0"));
		local numRows = tonumber(currNode:GetPropVal("grid.numRows", "0"));
		local hGap = tonumber(currNode:GetPropVal("grid.hGap", "0"));
		local vGap = tonumber(currNode:GetPropVal("grid.vGap", "0"));
		
		if(bFixed) then
			return wx.wxGridSizer(numRows, numColumns, vGap, hGap);
		else
			local gridSizer = wx.wxFlexGridSizer(numRows, numColumns, vGap, hGap);
			
			local proportions = currNode:GetPropVal("grid.colProportion", "");
			
			proportions = CalcGridProportions(proportions);
			for column, proportion in pairs(proportions) do
				gridSizer:AddGrowableCol(column, proportion);
			end
			
			proportions = currNode:GetPropVal("grid.rowProportion", "");
			
			proportions = CalcGridProportions(proportions);
			for row, proportion in pairs(proportions) do
				gridSizer:AddGrowableRow(row, proportion);
			end
			
			return gridSizer;
		end
	else
		return wx.wxBoxSizer(GetBoxSizerOrientation(currNode));
	end
end

local horizontalAlignmentFlags =
{
	left = wx.wxALIGN_LEFT,
	right = wx.wxALIGN_RIGHT,
	center = wx.wxALIGN_CENTER_HORIZONTAL,
}

local verticalAlignmentFlags =
{
	top = wx.wxALIGN_TOP,
	bottom = wx.wxALIGN_BOTTOM,
	center = wx.wxALIGN_CENTER_VERTICAL,
}

local function GetSizerFlags(currNode)
	local flags = 0;
	local border = 0;
	local proportioned = 0;
	local bHasProp, prop = currNode:GetPropVal("align");
	if(bHasProp) then
		if(horizontalAlignmentFlags[prop]) then
			flags = flags + horizontalAlignmentFlags[prop];
		end
	else
		bHasProp, prop = currNode:GetPropVal("halign");
		if(horizontalAlignmentFlags[prop]) then
			flags = flags + horizontalAlignmentFlags[prop];
		end
	end

	bHasProp, prop = currNode:GetPropVal("valign");
	if(verticalAlignmentFlags[prop]) then
		flags = flags + verticalAlignmentFlags[prop];
	end
	
	if(GetNodeBoolProp(currNode, "expand", false)) then
		flags = flags + wx.wxEXPAND;
	end
	
	bHasProp, prop = currNode:GetPropVal("proportion");
	if(bHasProp) then proportioned = tonumber(prop) end;
	
	bHasProp, prop = currNode:GetPropVal("border");
	if(bHasProp) then border = tonumber(prop); flags = flags + wx.wxALL end;
	
	bHasProp, prop = currNode:GetPropVal("vborder");
	if(bHasProp) then border = tonumber(prop); flags = flags + (wx.wxTOP + wx.wxBOTTOM) end;
	
	bHasProp, prop = currNode:GetPropVal("hborder");
	if(bHasProp) then border = tonumber(prop); flags = flags + (wx.wxLEFT + wx.wxRIGHT) end;
	
	return proportioned, flags, border;
end

local function AddToSizer(currNode, wndToAdd, sizer)
	sizer:Add(wndToAdd, GetSizerFlags(currNode));
end

local function AddWithLabel(parent, label, currNode, wndToAdd, sizer, orient)
	local box = wx.wxBoxSizer(orient);
	local text = wx.wxStaticText(parent, wx.wxID_ANY, label, wx.wxDefaultPosition, wx.wxDefaultSize, 0);
	local tip = wndToAdd:GetToolTip();
	
	if(tip and (#tip:GetTip() ~= 0)) then
		text:SetToolTip(tip:GetTip());
	end
	
	box:Add(text, 0, wx.wxALIGN_CENTER_VERTICAL + wx.wxALIGN_LEFT);
	
	local spaceSize;
	if(orient == wx.wxHORIZONTAL) then spaceSize = 4 else spaceSize = 2 end
	box:AddSpacer(spaceSize);
	box:Add(wndToAdd, 1, wx.wxALIGN_CENTER_VERTICAL + wx.wxALIGN_LEFT + wx.wxEXPAND);
	sizer:Add(box, GetSizerFlags(currNode));
end

local function AddToSizerWithLabel(parent, currNode, wndToAdd, sizer)
	local bHasLabel, label = currNode:GetPropVal("label");
	if(bHasLabel) then
		AddWithLabel(parent, label, currNode, wndToAdd, sizer, wx.wxHORIZONTAL);
	else
		bHasLabel, label = currNode:GetPropVal("vlabel");
		if(bHasLabel) then
			AddWithLabel(parent, label, currNode, wndToAdd, sizer, wx.wxVERTICAL);
		else
			AddToSizer(currNode, wndToAdd, sizer);
		end
	end
end

local function AddTooltip(currNode, wndForTips)
	local bHasProp, prop = currNode:GetPropVal("tip");
	if(bHasProp) then
		wndForTips:SetToolTip(prop);
	end
end

local function AddCtrlId(wnd, id)
	assert(not currWindowList[id], "Identifier " .. id .. " is already in use.");
	currWindowList[id] = wnd;
end

--Adds tooltips, checks for an id, etc.
local function FinalizeControl(currNode, wnd)
	AddTooltip(currNode, wnd);
	local bHasProp, prop = currNode:GetPropVal("id");
	if(bHasProp) then
		assert(currWindowList, "No ID found. " .. prop);
		AddCtrlId(wnd, prop);
	end
end

local g_baseAuiNameString = "__LuaGuiNamedPanel__";
local currUnnamedPanel = 0;

local function GetAuiManInfo(currNode)
	local info = wxaui.wxAuiPaneInfo();
	
	local bHasProp, prop = currNode:GetPropVal("title");
	if(bHasProp) then
		info:Caption(prop);
		info:Name(prop);
	else
		bHasProp, prop = currNode:GetPropVal("id");
		if(bHasProp) then
			info:Name(prop);
		else
			info:Name(g_baseAuiNameString .. currUnnamedPanel);
			currUnnamedPanel = currUnnamedPanel + 1;
		end
	end

	local bIsToolbar = false;
	if(currNode:GetName() == "toolbar") then
		info:ToolbarPane();
		bIsToolbar = true;
	end
	
	bHasProp, prop = currNode:GetPropVal("direction");
	if(bHasProp) then
		if(prop == "left") then info:Left() end;
		if(prop == "right") then info:Right() end;
		if(prop == "top") then info:Top() end;
		if(prop == "bottom") then info:Bottom() end;
	end
	
	bHasProp, prop = currNode:GetPropVal("row");
	if(bHasProp) then info:Row(tonumber(prop)) end;
	
	if(GetNodeBoolProp(currNode, "centerpane", false)) then info:CenterPane() end;
	if(GetNodeBoolProp(currNode, "maximizebutton", false)) then info:MaximizeButton() end;
	
	info:BestSize(GetNodeSize(currNode));
	info:CloseButton(false);
	
	info:Resizable(GetNodeBoolProp(currNode, "resizable", iff(bIsToolbar, false, true)));
		
	if(not GetNodeBoolProp(currNode, "gripper", true)) then
		if(currNode:GetName() == "toolbar") then
			info:Gripper(false)
		else
			info:CaptionVisible(false)
		end
	end;

	if(not GetNodeBoolProp(currNode, "floatable", true)) then info:Floatable(false) end;


	return info;
end

local function RegisterEventHandlers(currNode, wnd, eventList, ConvertFunc)
	for i=1,#eventList do
		local currEvt = eventList[i];
		local bHasProp, prop = currNode:GetPropVal(currEvt.name);
		if(bHasProp) then
			local func = loadstring(prop);

			wnd:Connect(currEvt.event,
				function(event)
					if(ConvertFunc) then
						func(ConvertFunc(event));
					else
						func(event);
					end
					event:Skip();
				end);
		end
	end
end

local function ParseChildrenWithCallback(parWnd, sizer, currNode, notebook, auiNotebook, ChildFunc)
	local nextNode = currNode:GetChildren();
	while(nextNode) do
		if(nextNode:GetName() == "if") then
			local bHasProp, prop = nextNode:GetPropVal("script");
			if(not bHasProp) then
				bHasProp, prop = nextNode:GetPropVal("cond");
			end

			if(bHasProp) then
				local func = loadstring(prop);
				if(func and func()) then
					ParseChildrenWithCallback(parWnd, sizer, nextNode,
						notebook, auiNotebook, ChildFunc);
				end
			end
		else
			local ProcFunc = elementJumpTable[nextNode:GetName()];
			
			if(ProcFunc) then
				local retWnd = ProcFunc(parWnd, sizer, nextNode, notebook, auiNotebook)
				if(ChildFunc) then ChildFunc(retWnd, nextNode) end;
			else
				--Not in table. Try a user-defined function.
				local bHasScript, script = nextNode:GetPropVal("script");
				
				assert(bHasScript or (nextNode:GetType() ~= wx.wxXML_ELEMENT_NODE),
					"Unknown element named \"" .. nextNode:GetName() ..
					"\". Has no 'script' attribute, so not user-defined.");
					
				if(bHasScript) then
					local UserFunc = loadstring(script);
					assert(type(UserFunc) == "function", "The user-defined function could not be compiled.");
					local retWnd = UserFunc(parWnd, sizer, nextNode, notebook, auiNotebook,
						{
							["ParseChildrenWithCallback"] = ParseChildrenWithCallback,
							["AddToSizer"] = AddToSizer,
							["FinalizeControl"] = FinalizeControl,
							["GetNodeSize"] = GetNodeSize,
							["CreateStandardSizer"] = CreateStandardSizer,
						});
					if(ChildFunc) then ChildFunc(retWnd, nextNode) end;
				end
			end
		end
		
		nextNode = nextNode:GetNext();
	end
end

--This function iterates over the children, calling a function on each child node.
--It also uses the "if" node to filter things.
--The function is called with the node, followed by any additional parameters.
local function ConditionalIterateOverChildren(currNode, callback, ...)
	local nextNode = currNode:GetChildren();
	while(nextNode) do
		if(nextNode:GetName() == "if") then
			local bHasProp, prop = nextNode:GetPropVal("script");
			if(not bHasProp) then
				bHasProp, prop = nextNode:GetPropVal("cond");
			end

			assert(bHasProp, "An 'if' clause must have a 'script' or 'cond' statement");
			
			local func = loadstring(prop);
			if(func and func()) then
				ConditionalIterateOverChildren(nextNode, callback, ...);
			end
		else
			callback(nextNode, ...);
		end
		nextNode = nextNode:GetNext();
	end

end


-------------------------------------------------------
--Jump table functions.

function elementJumpTable.app(parWnd, sizer, currNode, notebook, auiNotebook)
	ParseChildrenWithCallback(parWnd, sizer, currNode);

	--Add accelerators.
	local accelTable = {}
	
	local frameWnd = mainWnds[1].frameWnd;
	
	for i, accel in ipairs(accelList) do
		accelTable[#accelTable + 1] = {accel.flags, accel.key, 1200 + i};
		
		frameWnd:Connect(1200 + i, wx.wxEVT_COMMAND_MENU_SELECTED, accel.func);
	end
	
	for id, menuFunc in pairs(menuActions) do
		frameWnd:Connect(id, wx.wxEVT_COMMAND_MENU_SELECTED, menuFunc)
	end
	
	if(#accelTable ~= 0) then
		frameWnd:SetAcceleratorTable(wx.wxAcceleratorTable(accelTable));
	end

	if(GetNodeBoolProp(currNode, "show", true)) then
		frameWnd:Show();
	end
end

function elementJumpTable.frame(parWnd, sizer, currNode, notebook, auiNotebook)
	local frameWnd = wx.wxFrame((parWnd or wx.NULL), wx.wxID_ANY,
		currNode:GetPropVal("title", "untitled"), wx.wxDefaultPosition, GetNodeSize(currNode));
		
	FinalizeControl(currNode, frameWnd);
	
	local auiMan = wxaui.wxAuiManager();
	auiMan:SetManagedWindow(frameWnd);
	
	local wndData = {};
	wndData.frameWnd = frameWnd;
	wndData.auiMan = auiMan;
	wndData.accels = {};
	
	currWindowList = idWnds;
	
	mainWnds[#mainWnds + 1] = wndData;
	
	frameWnd:SetSizer(CreateStandardSizer(currNode));
	
	frameWnd:Hide();
	
	local function AddChild(childWnd, newChild)
		if(childWnd) then
			auiMan:AddPane(childWnd, GetAuiManInfo(newChild));
		end
	end
	
	ParseChildrenWithCallback(frameWnd, frameWnd:GetSizer(), currNode, notebook, auiNotebook, AddChild);
	
	frameWnd:Layout();
	auiMan:Update();

	return frameWnd;
end

function elementJumpTable.dialog(parWnd, sizer, currNode, notebook, auiNotebook)
	local style = wx.wxDEFAULT_DIALOG_STYLE;
	if(GetNodeBoolProp(currNode, "resizeable", false)) then
		style = style + wx.wxRESIZE_BORDER;
	end
	
	local dialog = wx.wxDialog(mainWnds[1].frameWnd, wx.wxID_ANY,
		currNode:GetPropVal("title", "Dialog"), wx.wxDefaultPosition,
		GetNodeSize(currNode), style);

	dialog:SetSizer(CreateStandardSizer(currNode))
	
	local bHasProp, wndId = currNode:GetPropVal("id");
	
	assert(bHasProp, "Dialogs must have an identifier.");
	assert(not (dialogs[wndId]), "The dialog ID " .. wndId .. " is in use.");
	
	dialogs[wndId] = dialog;
	dlgWnds[wndId] = {};
	currWindowList = dlgWnds[wndId];
	
	ParseChildrenWithCallback(dialog, dialog:GetSizer(), currNode,
		notebook, auiNotebook, nil);

	dialog:Hide();
	
	return nil;
end

local menubarJumpTable = {}

local function ProcessMenues(parMenu, currNode, ChildFunc)
	local nextNode = currNode:GetChildren();
	while(nextNode) do
		ProcFunc = menubarJumpTable[nextNode:GetName()];
		assert(ProcFunc, "Bad menu node: " .. nextNode:GetName());
		local ret = ProcFunc(parMenu, nextNode);
		if(ChildFunc) then
			ChildFunc(ret);
		end
	
		nextNode = nextNode:GetNext();
	end
end

function menubarJumpTable.menu(parMenu, currNode)
	local name = currNode:GetPropVal("name", "Unnamed Menu")
	local menuName = "";
	if(not parMenu) then menuName = name end;
	local theMenu = wx.wxMenu(menuName, wx.wxMB_DOCKABLE);
	
	ProcessMenues(theMenu, currNode);
	
	if(parMenu) then
		--Must add the menu to this one.
		local menuItem = wx.wxMenuItem(parMenu, wx.wxID_ANY, name,
			"", wx.wxITEM_NORMAL, theMenu);
		parMenu:Append(menuItem);
	end
	
	return theMenu;
end

function menubarJumpTable.menuitem(parMenu, currNode)
	assert(parMenu, "Menu items cannot be top-level.");
	
	local id = wx.wxNewId();
	parMenu:Append(id,
		currNode:GetPropVal("name", "Unnamed Menu Item"),
		currNode:GetPropVal("tip", ""),
		wx.wxITEM_NORMAL);
		
	local bHasAction, actionCode = currNode:GetPropVal("action");
	if(bHasAction) then
		menuActions[id] = loadstring(actionCode);
	end

	return nil;
end

function menubarJumpTable.menuspacer(parMenu, currNode)
	assert(parMenu, "Menu Spacers cannot be top-level.");
	parMenu:AppendSeparator();
end

function elementJumpTable.menubar(parWnd, sizer, currNode, notebook, auiNotebook)
	local topMenus = {};
	
	function AddChild(child)
		topMenus[#topMenus + 1] = child
	end
	
	ProcessMenues(nil, currNode, AddChild);
	
	local menuBar = wx.wxMenuBar();
	for i, menu in ipairs(topMenus) do
		menuBar:Append(menu, menu:GetTitle());
		menu:SetTitle("");
	end
	
	parWnd:SetMenuBar(menuBar);
	
	return nil;
end

function elementJumpTable.toolbar(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local mySizer = CreateStandardSizer(currNode);
	mySizer:SetMinSize(size);
	
	local panel = wx.wxPanel(parWnd, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxDefaultSize,
		wx.wxTAB_TRAVERSAL + wx.wxNO_BORDER);
	panel:SetSizer(mySizer);
		
	ParseChildrenWithCallback(panel, mySizer, currNode, notebook, auiNotebook, nil);

	AddToSizer(currNode, panel, sizer);
	FinalizeControl(currNode, panel);

	return panel;
end

elementJumpTable.panel = elementJumpTable["toolbar"];

function elementJumpTable.box(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local staticBox = wx.wxStaticBox(parWnd, wx.wxID_ANY,
		currNode:GetPropVal("text", "Box With No Name"), wx.wxDefaultPosition, size);
	
	--Creates a sizer as needed for static box containment.
	local boxSizer = wx.wxStaticBoxSizer(staticBox, wx.wxVERTICAL);
	boxSizer:SetMinSize(size);
	
	--Creates a sizer the usual way.
	local newSizer = CreateStandardSizer(currNode);
	newSizer:SetMinSize(size);

	ParseChildrenWithCallback(parWnd, newSizer, currNode, notebook, auiNotebook, nil);
	
	--Make our internal sizer as big as is allowed. It is the only child of
	--the outer box sizer.
	boxSizer:Add(newSizer, 1, wx.wxEXPAND, 0);

	FinalizeControl(currNode, staticBox);
	AddToSizer(currNode, boxSizer, sizer);

	return staticBox;
end

function elementJumpTable.collpane(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	
	local collpane = wx.wxCollapsiblePane(parWnd, wx.wxID_ANY, 
		currNode:GetPropVal("text", "CP with no name"), wx.wxDefaultPosition, size,
		bit.bor(wx.wxCP_DEFAULT_STYLE, 2)); --2 means wxCP_NO_TLW_RESIZE, which wxLua doesn't expose.
		
	local mySizer = CreateStandardSizer(currNode);
--	mySizer:SetMinSize(size);
	collpane:GetPane():SetSizer(mySizer);
		
	ParseChildrenWithCallback(collpane:GetPane(), mySizer, currNode, notebook, auiNotebook, nil);
	
	local bCollapsed = GetNodeBoolProp(currNode, "collapsed", false)
	if(not bCollapsed) then
		collpane:Expand();
	end
	
	AddToSizer(currNode, collpane, sizer);
	FinalizeControl(currNode, collpane);
	
	if(collpane:IsExpanded()) then
		collpane:Collapse();
		collpane:Expand();
	end
	
	collpane:Connect(wx.wxEVT_COMMAND_COLLPANE_CHANGED,
		function(collPaneEvent)
			local parent = collpane:GetParent();
			while(parent) do
				parent:Layout();
				parent = parent:GetParent();
			end
			collPaneEvent:ResumePropagation(1);
			collPaneEvent:Skip();
		end);

	return collpane;
end

function elementJumpTable.scrollpane(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	
	local scrollpane = wx.wxScrolledWindow(parWnd, wx.wxID_ANY, 
		wx.wxDefaultPosition, size);
		
	local mySizer = CreateStandardSizer(currNode);
	scrollpane:SetSizer(mySizer);
	
	--Scroll increments.
	local hScroll = tonumber(currNode:GetPropVal("hscroll", "0"));
	local vScroll = tonumber(currNode:GetPropVal("vscroll", "0"));
	scrollpane:SetScrollRate(hScroll, vScroll);
		
	ParseChildrenWithCallback(scrollpane, mySizer, currNode, notebook, auiNotebook, nil);
	
	AddToSizer(currNode, scrollpane, sizer);
	FinalizeControl(currNode, scrollpane);
	
	return scrollpane;
end


function elementJumpTable.sizer(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local newSizer = CreateStandardSizer(currNode);
	newSizer:SetMinSize(size);

	ParseChildrenWithCallback(parWnd, newSizer, currNode, notebook, auiNotebook, nil);
	
	AddToSizer(currNode, newSizer, sizer);

	return nil;
end

function elementJumpTable.tabs(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local tabs = wx.wxNotebook(parWnd, wx.wxID_ANY, wx.wxDefaultPosition, size, wx.wxNB_TOP);

	ParseChildrenWithCallback(tabs, tabs:GetSizer(), currNode, tabs, nil, nil);
	
	AddToSizer(currNode, tabs, sizer);
	FinalizeControl(currNode, tabs);
	
	local bHasProp, prop = currNode:GetPropVal("onselchanged");
	if(bHasProp) then
		local func = loadstring(prop);
		local wndId = tabs:GetId();
		tabs:Connect(wx.wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
			function(notebookEvt)
				if(wndId == notebookEvt:GetId()) then
					func(notebookEvt);
				end
				notebookEvt:Skip();
			end
		);
	end

	return tabs;
end

function elementJumpTable.tab(parWnd, sizer, currNode, notebook, auiNotebook)
	if(not notebook) then return end;
	
	local size = GetNodeSize(currNode);
	local page = wx.wxPanel(parWnd, wx.wxID_ANY, wx.wxDefaultPosition, size,
		wx.wxTAB_TRAVERSAL + wx.wxNO_BORDER);
	page:SetSizer(CreateStandardSizer(currNode));

	ParseChildrenWithCallback(page, page:GetSizer(), currNode, nil, nil, nil);
	
	FinalizeControl(currNode, page);
	notebook:AddPage(page, currNode:GetPropVal("text", "tab"));

	return page;
end

local buttonEventTable = {
{name="action", event=wx.wxEVT_COMMAND_BUTTON_CLICKED}
};

function elementJumpTable.button(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	
	local button = wx.wxButton(parWnd, wx.wxID_ANY, currNode:GetPropVal("text", "button"),
		wx.wxDefaultPosition, size);

	if(currNode:GetPropVal("enabled", "true") ~= "true") then
		button:Enable(false);
	end
	
	RegisterEventHandlers(currNode, button, buttonEventTable);

	FinalizeControl(currNode, button);
	AddToSizer(currNode, button, sizer);

	return button;
end

function elementJumpTable.spacer(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = tonumber(currNode:GetPropVal("size", "0"));
	local proportion = tonumber(currNode:GetPropVal("proportion", "0"));
	sizer:Add(size, size, proportion);
	return nil;
end

function elementJumpTable.static(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local text = currNode:GetPropVal("text", "static text");
	
	local staticText = wx.wxStaticText(parWnd, wx.wxID_ANY, text, wx.wxDefaultPosition, size);
	AddToSizer(currNode, staticText, sizer);
	FinalizeControl(currNode, staticText);

	return staticText;
end

function elementJumpTable.checkbox(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local text = currNode:GetPropVal("text", "checkbox");

	local checkBox = wx.wxCheckBox(parWnd, wx.wxID_ANY, text, wx.wxDefaultPosition, size, wx.wxCHK_2STATE);
	
	if(GetNodeBoolProp(currNode, "default", false)) then checkBox:SetValue(true) end;

	local bHasCheck, strCheck = currNode:GetPropVal("oncheck");
	local bHasUncheck, strUncheck = currNode:GetPropVal("onuncheck");
	
	if(bHasCheck or bHasUncheck) then
		local CheckFunc = nil;
		local UncheckFunc = nil;
		
		if(bHasCheck) then CheckFunc = loadstring(strCheck); end
		if(bHasUncheck) then UncheckFunc = loadstring(strUncheck); end
		
		checkBox:Connect(wx.wxEVT_COMMAND_CHECKBOX_CLICKED,
			function(cmdEvent)
				if(checkBox:IsChecked() and CheckFunc) then CheckFunc(cmdEvent) cmdEvent:Skip() end
				if(not checkBox:IsChecked() and UncheckFunc) then UncheckFunc(cmdEvent) cmdEvent:Skip() end
			end);
	end
	
	AddToSizer(currNode, checkBox, sizer);
	FinalizeControl(currNode, checkBox);

	return checkBox;
end

function elementJumpTable.checkbox3(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local text = currNode:GetPropVal("text", "checkbox");
	
	local style = wx.wxCHK_3STATE;
	
	if(GetNodeBoolProp(currNode, "user", false)) then
		style = style + wx.wxCHK_ALLOW_3RD_STATE_FOR_USER;
	end
	
	local checkBox = wx.wxCheckBox(parWnd, wx.wxID_ANY, text, wx.wxDefaultPosition, size, style);
	
	if(GetNodeBoolProp(currNode, "default", false)) then checkBox:SetValue(true) end;

	local bHasAction, strAction = currNode:GetPropVal("action");
	
	if(bHasAction) then
		local ActionFunc = loadstring(strAction);
	
		checkBox:Connect(wx.wxEVT_COMMAND_CHECKBOX_CLICKED,
			function(cmdEvent) ActionFunc(checkBox:Get3StateValue(), cmdEvent) end);
	end
	
	AddToSizer(currNode, checkBox, sizer);
	FinalizeControl(currNode, checkBox);

	return checkBox;
end

local function BuildRadioList(currNode, theList)
	local nextNode = currNode:GetChildren();
	while(nextNode) do
		if(nextNode:GetName() == "if") then
			local bHasProp, prop = nextNode:GetPropVal("script");
			if(not bHasProp) then
				bHasProp, prop = nextNode:GetPropVal("cond");
			end

			assert(bHasProp, "An 'if' clause must have a 'script' or 'cond' statement");
			
			local func = loadstring(prop);
			if(func and func()) then
				BuildRadioList(nextNode, theList);
			end
		else
			assert(nextNode:GetName() == "radio", "Must have 'radio' elements in 'radiobuttons'.");
			
			local bHasName, name = nextNode:GetPropVal("name");
			local bHasValue, value = nextNode:GetPropVal("value");
			
			assert(bHasName, "'radio' elements must have a 'name' element");
			if(not value) then value = name end
			
			theList[#theList + 1] = {name = name, value = value};
		end
		nextNode = nextNode:GetNext();
	end
end


function elementJumpTable.radiobuttons(parWnd, sizer, currNode, notebook, auiNotebook)
	local orientation = GetOrientation(currNode);
	
	if(orientation == wx.wxHORIZONTAL) then
		orientation = wx.wxRA_SPECIFY_ROWS
	else
		orientation = wx.wxRA_SPECIFY_COLS
	end
	
	local radioName = currNode:GetPropVal("text", "radiobuttons");

	local size = GetNodeSize(currNode);
	
	local nameList = {};
	BuildRadioList(currNode, nameList);
	
	local nameArray = wx.wxArrayString();
	nameArray:Alloc(#nameList);
	for i, nameTbl in ipairs(nameList) do
		nameArray:Add(nameTbl.name);
	end
	
	local radio = wx.wxRadioBox(parWnd, wx.wxID_ANY, radioName,
		wx.wxDefaultPosition, size, nameArray, 1, orientation);
		
	radio.nameList = nameList;

	local bHasDefault, default = currNode:GetPropVal("default");
	
	if(bHasDefault) then
		for i, nameTbl in ipairs(nameList) do
			if(default == nameTbl.name) then
				radio:SetSelection(i)
				break
			end
		end
	end
	
	FinalizeControl(currNode, radio);
	AddToSizer(currNode, radio, sizer);
	
	local bHasAction, action = currNode:GetPropVal("action");
	
	if(bHasAction) then
		local func = loadstring(action);
		radio:Connect(wx.wxEVT_COMMAND_RADIOBOX_SELECTED,
			function(cmdEvent)
				func(nameList[cmdEvent:GetSelection() + 1].value, cmdEvent);
				cmdEvent:Skip();
			end);
	end

	return radio;
end

local editboxEventTable =
{
	{name="onentry", event=wx.wxEVT_COMMAND_TEXT_ENTER},
	{name="onchange", event=wx.wxEVT_COMMAND_TEXT_UPDATED},
}

function elementJumpTable.editbox(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local style = wx.wxTE_NOHIDESEL;
	
	if(GetNodeBoolProp(currNode, "multiline", false)) then style = style + wx.wxTE_MULTILINE; end
	if(GetNodeBoolProp(currNode, "readonly", false)) then style = style + wx.wxTE_READONLY; end
	
	local bHasEntry, strEntry = currNode:GetPropVal("onentry");
	
	if(bHasEntry) then style = style + wx.wxTE_PROCESS_ENTER end
	
	local editbox = wx.wxTextCtrl(parWnd, wx.wxID_ANY, currNode:GetPropVal("default", ""),
		wx.wxDefaultPosition, size, style);

	if(GetNodeBoolProp(currNode, "readonly", false)) then
		editbox:SetBackgroundColour(wx.wxSystemSettings.GetColour(wx.wxSYS_COLOUR_BTNFACE));
	end

	FinalizeControl(currNode, editbox);
	AddToSizerWithLabel(parWnd, currNode, editbox, sizer);
	
	RegisterEventHandlers(currNode, editbox, editboxEventTable,
		function(event)
			return event:GetString(), event;
		end);

	return editbox;
end

function elementJumpTable.spinner(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local style = wx.wxSP_ARROW_KEYS;
	
	local minValue = tonumber(currNode:GetPropVal("min", "0"));
	local maxValue = tonumber(currNode:GetPropVal("max", "100"));
	local startValue = tonumber(currNode:GetPropVal("default", "50"));
	
	if(GetNodeBoolProp(currNode, "wrap", false)) then style = style + wx.wxSP_WRAP; end
	
	local spinner = wx.wxSpinCtrl(parWnd, wx.wxID_ANY, "",
		wx.wxDefaultPosition, size, style, minValue, maxValue, startValue);

	FinalizeControl(currNode, spinner);
	AddToSizerWithLabel(parWnd, currNode, spinner, sizer);
	
	local bHasChange, strChange = currNode:GetPropVal("onchange");
	
	if(bHasChange) then
		local func = loadstring(strChange);
		spinner:Connect(wx.wxEVT_COMMAND_SPINCTRL_UPDATED,
			function(cmdEvent)
				func(cmdEvent:GetInt(), cmdEvent);
				cmdEvent:Skip();
			end);
	end

	return spinner;
end

function elementJumpTable.slider(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local style = 0;
	
	local orientation = currNode:GetPropVal("direction", "horizontal");
	if(orientation == "horizontal") then
		style = style + wx.wxSL_HORIZONTAL
	else
		style = style + wx.wxSL_VERTICAL
	end
	
	local minValue = tonumber(currNode:GetPropVal("min", "0"));
	local maxValue = tonumber(currNode:GetPropVal("max", "100"));
	local startValue = tonumber(currNode:GetPropVal("default", "50"));

	if(GetNodeBoolProp(currNode, "ticks", true)) then
		style = style + wx.wxSL_AUTOTICKS;
	end
	
	local slider = wx.wxSlider(parWnd, wx.wxID_ANY, startValue, minValue, maxValue,
		wx.wxDefaultPosition, size, style);
		
	local numTicks = tonumber(currNode:GetPropVal("numticks", "3"));
	local tickFreq = math.abs(maxValue - minValue) / numTicks;
	slider:SetTickFreq(tickFreq, 0);

	FinalizeControl(currNode, slider);
	AddToSizerWithLabel(parWnd, currNode, slider, sizer);
	
	local bHasChange, strChange = currNode:GetPropVal("onchange");
	
	if(bHasChange) then
		local func = loadstring(strChange);
		slider:Connect(wx.wxEVT_SCROLL_CHANGED,
			function(cmdEvent)
				func(cmdEvent:GetInt(), cmdEvent);
				cmdEvent:Skip();
			end);
	end

	return slider;
end

local listboxEventTable = {
{name="onselchange", event=wx.wxEVT_COMMAND_LISTBOX_SELECTED},
{name="ondblclick", event=wx.wxEVT_COMMAND_LISTBOX_DOUBLECLICKED}
};

function elementJumpTable.listbox(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local style = 0;
	
	local lbType = currNode:GetPropVal("type", "single");
	
	local lbTypes = {
		single = wx.wxLB_SINGLE,
		multichoice = wx.wxLB_MULTIPLE,
		multiple = wx.wxLB_EXTENDED
	}
	
	assert(lbTypes[lbType], "The type field for list boxes must be 'single', 'multichoice' or 'multiple'.");
	
	style = lbTypes[lbType];
	
	if(GetNodeBoolProp(currNode, "sort", false)) then style = style + wx.wxLB_SORT; end
	
	style = style + wx.wxLB_NEEDED_SB + wx.wxLB_HSCROLL;
	
	local listbox = wx.wxListBox(parWnd, wx.wxID_ANY, wx.wxDefaultPosition, size, 
		wx.wxArrayString(), style);

	FinalizeControl(currNode, listbox);
	AddToSizer(currNode, listbox, sizer);
	
	RegisterEventHandlers(currNode, listbox, listboxEventTable);

	local bHasCreate, strCreate = currNode:GetPropVal("oncreate");
	
	if(bHasCreate) then
		local func = loadstring(strCreate);
		func(listbox);
	end

	return listbox;
end

local dropdownEventTable = {
	{name="onselchange", event=wx.wxEVT_COMMAND_COMBOBOX_SELECTED},
	{name="onentry", event=wx.wxEVT_COMMAND_TEXT_ENTER}
};

function elementJumpTable.dropdown(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	local style = wx.wxCB_DROPDOWN;
	
	if(not GetNodeBoolProp(currNode, "edit", false)) then style = style + wx.wxCB_READONLY; end
	if(GetNodeBoolProp(currNode, "sort", false)) then style = style + wx.wxCB_SORT; end
	
	local dropdown = wx.wxComboBox(parWnd, wx.wxID_ANY, "", wx.wxDefaultPosition, size, 
		{}, style);

	FinalizeControl(currNode, dropdown);
	AddToSizerWithLabel(parWnd, currNode, dropdown, sizer);
	
	RegisterEventHandlers(currNode, dropdown, dropdownEventTable);

	local bHasCreate, strCreate = currNode:GetPropVal("oncreate");
	
	if(bHasCreate) then
		local func = loadstring(strCreate);
		func(dropdown);
	end

	return dropdown;
end

--[==[
function elementJumpTable.listctrl(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);

	local list = wx.wxListCtrl(parWnd, wx.wxID_ANY, wx.wxDefaultPosition, size,
	wx.wxLC_REPORT + wx.wxLC_EDIT_LABELS + wx.wxLC_HRULES + wx.wxLC_VRULES);

	list:InsertColumn(0, "Name");
	list:InsertColumn(1, "Gran");
	list:InsertItem(0, "foo");
	list:SetItem(0, 1, "Something more than that.");
	list:InsertItem(1, "bar");
	list:InsertItem(2, "fia");
	list:InsertItem(3, "lsia");

	list:Connect(wx.wxEVT_COMMAND_LIST_COL_CLICK,
		function(event)
			print(event:GetText(), event:GetColumn());
			event:Skip();
		end);
		
	

	FinalizeControl(currNode, list);
	AddToSizer(currNode, list, sizer);

	return list;
end
]==]


--[[
local uncheckedBox =
{
    "16 15 2 1",
    ". c None",
    "O c Black",
    ".OOOOOOOOOOOOOOO",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".O.............O",
    ".OOOOOOOOOOOOOOO",
}

local checkedBox =
{
    "16 15 2 1",
    ". c None",
    "O c Black",
    ".OOOOOOOOOOOOOOO",
    ".O.............O",
    ".O.............O",
    ".O..........O..O",
    ".O.........OO..O",
    ".O........OOO..O",
    ".O.......OOO...O",
    ".O..O...OOO....O",
    ".O..OO.OOO.....O",
    ".O..OOOOO......O",
    ".O...OOO.......O",
    ".O....O........O",
    ".O.............O",
    ".O.............O",
    ".OOOOOOOOOOOOOOO",
}


--New type of control. It is a list box, but the items can be checked and unchecked.
--The user can query all of the checked or unchecked items in the box.
function elementJumpTable.listcheckbox(parWnd, sizer, currNode, notebook, auiNotebook)
	local size = GetNodeSize(currNode);
	
	local panelStyle = wx.wxTAB_TRAVERSAL + wx.wxNO_BORDER;
	
	local panel = wx.wxPanel(parWnd, wx.wxID_ANY, wx.wxDefaultPosition, size, panelStyle);
	local panelSizer = wx.wxBoxSizer(wx.wxVERTICAL);
	panel:SetSizer(panelSizer);	
	
	local treeStyle = wx.wxTR_NO_BUTTONS + wx.wxTR_NO_LINES +
		wx.wxTR_FULL_ROW_HIGHLIGHT + wx.wxTR_HIDE_ROOT + wx.wxTR_SINGLE;

	local treeCtrl = wx.wxTreeCtrl(panel, wx.wxID_ANY, wx.wxDefaultPosition,
		wx.wxDefaultSize, treeStyle);

	treeCtrl:SetMinSize(size);
	treeCtrl:AddRoot("");
	
	panel.treeCtrl = treeCtrl;
	panelSizer:Add(treeCtrl, 1, wx.wxEXPAND);

	FinalizeControl(currNode, panel);
	AddToSizerWithLabel(parWnd, currNode, panel, sizer);
	
	do
		local icons = {};
		icons[1] = wx.wxIcon();
		icons[2] = wx.wxIcon();

		local tempBmp = wx.wxBitmap(uncheckedBox);
		icons[1]:CopyFromBitmap(tempBmp);
		tempBmp:delete();

		tempBmp = wx.wxBitmap(checkedBox);
		icons[2]:CopyFromBitmap(tempBmp);
		tempBmp:delete();
		
		local images = wx.wxImageList(icons[1]:GetWidth(), icons[1]:GetHeight(), true);
		images:Add(icons[1]);
		images:Add(icons[2]);
		
		panel.treeCtrl:AssignImageList(images);
	end
	
	local rootItem = panel.treeCtrl:GetRootItem();
	local item1 = panel.treeCtrl:InsertItem(rootItem, 0, "First Item");
	panel.treeCtrl:SetItemImage(item1, 0);
	local item2 = panel.treeCtrl:InsertItem(rootItem, 1, "Second Item");
	panel.treeCtrl:SetItemImage(item2, 1);
	
	local bHasCreate, strCreate = currNode:GetPropVal("oncreate");
	
	if(bHasCreate) then
		local func = loadstring(strCreate);
		func(treeCtrl);
	end

	return treeCtrl;
end
]]


local modifierList = {
	SHIFT = wx.wxACCEL_SHIFT,
	CTRL = wx.wxACCEL_CTRL,
	ATL = wx.wxACCEL_ALT,
}

local keyMapList = {
	F1		= wx.WXK_F1,
	F2		= wx.WXK_F2,
	F3		= wx.WXK_F3,
	F4		= wx.WXK_F4,
	F5		= wx.WXK_F5,
	F6		= wx.WXK_F6,
	F7		= wx.WXK_F7,
	F8		= wx.WXK_F8,
	F9		= wx.WXK_F9,
	F10		= wx.WXK_F10,
	F11		= wx.WXK_F11,
	F12		= wx.WXK_F12,
	TAB		= wx.WXK_TAB,
	ESC		= wx.WXK_ESCAPE,
	DEL		= wx.WXK_DELETE,
	INS		= wx.WXK_INSERT,
	HOME	= wx.WXK_HOME,
	END		= wx.WXK_END,
	PGUP	= wx.WXK_PAGEUP,
	PGDN	= wx.WXK_PAGEDOWN,
}

function elementJumpTable.accelerator(parWnd, sizer, currNode, notebook, auiNotebook)
	local bHasKey, strKeyCombo = currNode:GetPropVal("key");
	assert(bHasKey, "'accelerator' nodes must have a 'key' attribute.");
	
	strKeyCombo = string.upper(strKeyCombo);
	
	local bHasFunc, strFunc = currNode:GetPropVal("action");
	assert(bHasFunc, "'accelerator' nodes must have an 'action' attribute.");
	
	local modifyFlags = 0;
	
	for modifier in string.gmatch(strKeyCombo, "(%a+)[ ]*%+") do
		assert(modifierList[modifier], "The key modifier \"" .. modifier .. "\" is not a real modifier.");
		modifyFlags = modifyFlags + modifierList[modifier];
	end
	
	local strKey = string.match(strKeyCombo, "(%a+)[ ]*$");
	
	local key = keyMapList[strKey];
	
	--Not in list, so it must be a single letter.
	if(not key) then
		assert(#strKey == 1, "Invalid key name \"" .. strKey .. "\". Key not supported.");
		key = string.byte(strKey);
	end
	
	local accel = {};
	accel.flags = modifyFlags;
	accel.key = key;
	accel.func = loadstring(strFunc);

	accelList[#accelList + 1] = accel;
	
	return nil;
end

local dialogButtonLookup = {
	ok = {wx.wxOK, wx.wxID_OK},
	cancel = {wx.wxCANCEL, wx.wxID_CANCEL},
	yes = {wx.wxYES, wx.wxID_YES},
	no = {wx.wxNO, wx.wxID_NO},
}

elementJumpTable["dialog-panel"] =
	function(parWnd, sizer, currNode, notebook, auiNotebook)
	
	local dialog = parWnd;
	
	local flags = 0;
	local btnScripts = {};
	ConditionalIterateOverChildren(currNode, function(theNode)
		assert(dialogButtonLookup[theNode:GetName()],
			"Invalid child element of dialog-panel: " .. theNode:GetName());
		
		flags = flags + dialogButtonLookup[theNode:GetName()][1];
		
		local bHasScript, script = theNode:GetPropVal("script");
		if(bHasScript) then
			script = loadstring(script);
			btnScripts[dialogButtonLookup[theNode:GetName()][2]] = script;
		end
	end)

	local buttons = dialog:CreateButtonSizer(flags);
	AddToSizer(currNode, buttons, dialog:GetSizer());

	--Must connect the scripts *after* making the buttons.
	for ctrlId, script in pairs(btnScripts) do
		dialog:Connect(ctrlId, wx.wxEVT_COMMAND_BUTTON_CLICKED,
			--Ensure the propogation of the event, unless the function returns something.
			function(event, ...)
				if(not script(event, ...)) then
					if(event) then event:ResumePropagation(1) event:Skip() end
				end
			end);
	end
end

function elementJumpTable.execute(parWnd, sizer, currNode, notebook, auiNotebook)
	local bHasScriptFile, scriptFile = currNode:GetPropVal("script-file");
	if(bHasScriptFile) then
		executeFuncs[#executeFuncs + 1] = scriptFile
	else
		--Get all of the child nodes and concatenate them.
		local currString = "";
		for theNode in ixmlnodes(currNode) do
			if((theNode:GetType() == wx.wxXML_TEXT_NODE) or
				(theNode:GetType() == wx.wxXML_CDATA_SECTION_NODE)) then

				currString = currString .. theNode:GetContent();
			end
		end

		local scriptName = currNode:GetPropVal("script-name",
			baseFileName .. #executeFuncs);
		
		executeFuncs[#executeFuncs + 1] = assert(loadstring(currString, scriptName))
	end
end

local ModalDataUploadFuncs = {};
local ModalDataDownloadFuncs = {};

function ModalDataUploadFuncs.wxCheckBox(theCheckBox, value)
	if(value) then
		theCheckBox:SetValue(true);
	else
		theCheckBox:SetValue(false);
	end
end

function ModalDataDownloadFuncs.wxCheckBox(theCheckBox)
	return theCheckBox:GetValue();
end

function ModalDataUploadFuncs.wxSpinCtrl(theSpinCtrl, value)
	local number = tonumber(value);
	if(number) then theSpinCtrl:SetValue(number) end
end

function ModalDataDownloadFuncs.wxSpinCtrl(theSpinCtrl)
	return theSpinCtrl:GetValue();
end

function ModalDataUploadFuncs.wxSlider(theSlider, value)
	local number = tonumber(value);
	if(number) then theSlider:SetValue(number) end
end

function ModalDataDownloadFuncs.wxSlider(theSlider)
	return theSlider:GetValue();
end

function ModalDataUploadFuncs.wxTextCtrl(theTextCtrl, value)
	if(value) then theTextCtrl:SetValue(value) end
end

function ModalDataDownloadFuncs.wxTextCtrl(theTextCtrl)
	return theTextCtrl:GetValue();
end

function ModalDataUploadFuncs.wxRadioBox(theRadioBox, value)
	assert(theRadioBox.nameList);
	
	local theName = nil;
	for i, nameEntry in ipairs(theRadioBox.nameList) do
		if(value == nameEntry.value) then
			theName = nameEntry.name;
			break;
		end
	end
	
	if(not theName) then return end
	
	if(value) then theRadioBox:SetStringSelection(theName) end
end

function ModalDataDownloadFuncs.wxRadioBox(theRadioBox)
	local theName = theRadioBox:GetStringSelection();
	
	local theValue = nil;
	for i, nameEntry in ipairs(theRadioBox.nameList) do
		if(theName == nameEntry.name) then
			return nameEntry.value;
		end
	end
	
	return nil;
end

--Needed:
-- wxListBox
-- wxComboBox




DoModalData = function(windowData, idDialog, dataTable)
	local dialog = assert(windowData:GetDialog(idDialog),
		"Could not find the dialog named " .. idDialog);

	for id, value in pairs(dataTable) do
		local theControl = windowData:GetWindow(idDialog, id);
		if(not theControl) then
			LuaGUI.MsgBoxPrint("Could not find a window named " .. id);
		end
		
		local className = theControl:GetClassInfo():GetClassName();
		if(ModalDataUploadFuncs[className]) then
			ModalDataUploadFuncs[className](theControl, value);
		end
	end
	
	local ret = dialog:ShowModal();
	
	if(ret == wx.wxID_OK) then
		local temp = {}
	
		for id, value in pairs(dataTable) do
			local theControl = windowData:GetWindow(idDialog, id);

			local className = theControl:GetClassInfo():GetClassName();
			if(ModalDataDownloadFuncs[className]) then
				temp[id] = ModalDataDownloadFuncs[className](theControl);
			end
		end
		
		for id, value in pairs(temp) do
			dataTable[id] = value;
		end
	end
	
	return ret;
end



return LuaGUI;