Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[r8594]: ooDialog / trunk / ooDialog / oodTreeView.cpp Maximize Restore History

Download this file

oodTreeView.cpp    1541 lines (1350 with data), 48.5 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
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
/*----------------------------------------------------------------------------*/
/* */
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
/* Copyright (c) 2005-2012 Rexx Language Association. All rights reserved. */
/* */
/* This program and the accompanying materials are made available under */
/* the terms of the Common Public License v1.0 which accompanies this */
/* distribution. A copy is also available at the following address: */
/* http://www.oorexx.org/license.html */
/* */
/* Redistribution and use in source and binary forms, with or */
/* without modification, are permitted provided that the following */
/* conditions are met: */
/* */
/* Redistributions of source code must retain the above copyright */
/* notice, this list of conditions and the following disclaimer. */
/* Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in */
/* the documentation and/or other materials provided with the distribution. */
/* */
/* Neither the name of Rexx Language Association nor the names */
/* of its contributors may be used to endorse or promote products */
/* derived from this software without specific prior written permission. */
/* */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* */
/*----------------------------------------------------------------------------*/
/**
* oodTreeView.cpp
*
* Contains methods for the tree-view control.
*/
#include "ooDialog.hpp" // Must be first, includes windows.h, commctrl.h, and oorexxapi.h
#include <shlwapi.h>
#include "APICommon.hpp"
#include "oodCommon.hpp"
#include "oodMessaging.hpp"
#include "oodControl.hpp"
#include "oodResources.hpp"
/**
* Methods for the .TreeView class.
*/
#define TREEVIEW_CLASS "TreeView"
#define TVSTATE_ATTRIBUTE "TV!STATEIMAGELIST"
#define TVNORMAL_ATTRIBUTE "TV!NORMALIMAGELIST"
static CSTRING tvGetAttributeName(uint8_t type)
{
switch ( type )
{
case TVSIL_STATE :
return TVSTATE_ATTRIBUTE;
case TVSIL_NORMAL :
default :
return TVNORMAL_ATTRIBUTE;
}
}
static void parseTvModifyOpts(CSTRING opts, TVITEMEX *tvi)
{
if ( StrStrI(opts, "NOTBOLD") != NULL )
{
tvi->stateMask |= TVIS_BOLD;
}
else if ( StrStrI(opts, "BOLD") != NULL )
{
tvi->state |= TVIS_BOLD;
tvi->stateMask |= TVIS_BOLD;
}
if ( StrStrI(opts, "NOTDROP") != NULL )
{
tvi->stateMask |= TVIS_DROPHILITED;
}
else if ( StrStrI(opts, "DROP") != NULL )
{
tvi->state |= TVIS_DROPHILITED;
tvi->stateMask |= TVIS_DROPHILITED;
}
if ( StrStrI(opts, "NOTSELECTED") != NULL )
{
tvi->stateMask |= TVIS_SELECTED;
}
else if ( StrStrI(opts, "SELECTED") != NULL )
{
tvi->state |= TVIS_SELECTED;
tvi->stateMask |= TVIS_SELECTED;
}
if ( StrStrI(opts, "NOTCUT") != NULL )
{
tvi->stateMask |= TVIS_CUT;
}
else if ( StrStrI(opts, "CUT") != NULL )
{
tvi->state |= TVIS_CUT;
tvi->stateMask |= TVIS_CUT;
}
if ( StrStrI(opts, "NOTEXPANDEDONCE") != NULL )
{
tvi->stateMask |= TVIS_EXPANDEDONCE;
}
else if ( StrStrI(opts, "EXPANDEDONCE") != NULL )
{
tvi->state |= TVIS_EXPANDEDONCE;
tvi->stateMask |= TVIS_EXPANDEDONCE;
}
else if ( StrStrI(opts, "NOTEXPANDED") != NULL )
{
tvi->stateMask |= TVIS_EXPANDED;
}
else if ( StrStrI(opts, "EXPANDED") != NULL )
{
tvi->state |= TVIS_EXPANDED;
tvi->stateMask |= TVIS_EXPANDED;
}
else if ( StrStrI(opts, "NOTEXPANDPARTIAL") != NULL )
{
tvi->stateMask |= TVIS_EXPANDPARTIAL;
}
else if ( StrStrI(opts, "EXPANDPARTIAL") != NULL )
{
tvi->state |= TVIS_EXPANDPARTIAL;
tvi->stateMask |= TVIS_EXPANDPARTIAL;
}
if ( tvi->state != 0 || tvi->stateMask != 0 )
{
tvi->mask |= TVIF_STATE;
}
}
/**
* Finds the first tree-view item whose text matches the specified text.
*
* @param hTv
* @param text
*
* @return HTREEITEM
*
* @note Although the text for a tree-view item can be any length, only 260
* characters are displayed. The old IBM code used a huge buffer, twice
* 4096. I think we should limit the length of text a user can assign to
* a tree-view item, but for now we'll just go with 4096.
*/
HTREEITEM tvFindItem(HWND hTv, CSTRING text)
{
if ( *text == '\0' )
{
return NULL;
}
HTREEITEM hTreeItem = NULL;
HTREEITEM root = TreeView_GetRoot(hTv);
TVITEM tvi = {0};
char buff[4096];
tvi.hItem = root;
while ( tvi.hItem != NULL )
{
tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_CHILDREN;
tvi.pszText = buff;
tvi.cchTextMax = sizeof(buff) - 1;
if ( TreeView_GetItem(hTv, &tvi) )
{
if ( stricmp(tvi.pszText, text) == 0 )
{
return tvi.hItem;
}
else
{
if ( tvi.cChildren > 0 )
{
hTreeItem = TreeView_GetChild(hTv, tvi.hItem);
}
else
{
hTreeItem = TreeView_GetNextSibling(hTv, tvi.hItem);
}
while ( hTreeItem == NULL && tvi.hItem != NULL )
{
tvi.hItem = TreeView_GetParent(hTv, tvi.hItem);
hTreeItem = TreeView_GetNextSibling(hTv, tvi.hItem);
if ( hTreeItem == root )
{
return NULL;
}
}
if ( tvi.hItem == NULL )
{
return NULL;
}
tvi.hItem = hTreeItem;
}
}
else
{
tvi.hItem = NULL;
}
}
return NULL;
}
/**
* Returns the lParam user data for the specified tree-view item as a Rexx
* object
*
* @param hTree
*
* @return The Rexx object set as the user data, or the .nil object if no user
* data is set.
*/
static RexxObjectPtr getCurrentTviUserData(HWND hTree, HTREEITEM hTreeItem)
{
TVITEMEX tvi = {TVIF_PARAM, hTreeItem};
RexxObjectPtr result = TheNilObj;
if ( TreeView_GetItem(hTree, &tvi) != 0 )
{
if ( tvi.lParam != 0 )
{
result = (RexxObjectPtr)tvi.lParam;
}
}
return result;
}
/**
* This is the window procedure used to subclass the edit control used for label
* editing for the TreeView. We need to add the want all keys for
* WM_GETDLGCODE, or else ESC and ENTER close the dialog rather than end the
* editing session.
*
* Unlike other ooDialog subclass procedures, we don't need any extra data for
* this one. dwData is null. The edit control is destroyed by the OS as soon
* as the label editing is ended, so this subclass is very transient. We
* recieve the WM_NCDESTROY message and remove the subclass.
*/
LRESULT CALLBACK CatchReturnSubProc(HWND hwnd, uint32_t msg, WPARAM wParam, LPARAM lParam, UINT_PTR id, DWORD_PTR dwData)
{
switch ( msg )
{
case WM_GETDLGCODE:
return(DLGC_WANTALLKEYS | DefSubclassProc(hwnd, msg, wParam, lParam));
case WM_NCDESTROY:
{
RemoveWindowSubclass(hwnd, CatchReturnSubProc, id);
}
}
return DefSubclassProc(hwnd, msg, wParam, lParam);
}
/**
* Subclasses the edit control that is created when the user begins editing a
* tree-view item label. Without the subclass, if the user hits the ENTER or
* ESC key while editing, the dialog is closed.
*
* This is an older ooDialog method which used to be used for a list-view also.
* It is not needed for a list-view.
*
* @return True on success, otherwise false.
*
* @remarks We are called from the window message processing loop, so we know
* we are in the proper thread.
*
* We try to get the edit contol's ID. If we fail we use the
* tree-view's id.
*/
bool tvSubclassEdit(HWND hTV, HWND hEdit, uintptr_t tvID)
{
if ( hEdit == NULL )
{
return false;
}
int _id = GetDlgCtrlID(hEdit);
uintptr_t id = _id < 1 ? tvID : _id;
if ( SetWindowSubclass(hEdit, CatchReturnSubProc, id, NULL) == 0 )
{
return false;
}
return true;
}
/**
* A tree view item sort callback function that works by invoking a method in
* the Rexx dialog that does the actual comparison.
*
* @param lParam1
* @param lParam2
* @param lParamSort
*
* @return int32_t
*
* @remarks The Rexx programmer will have had to set the lParam user data field
* for each tree view item of this to work. If either lParam1 or
* lParam2 is null, indicating the user did not set a data value for
* the item, we simpley return 0.
*
* Testing shows that this call back is always invoked on the dialog's
* window message processing thread, so we do no need to worry about
* doing an AttachThread().
*
* Testing with the list-view compare function shows that doing
* ReleaseLocalReference, significantly increases the time it takes to
* sort 1000 items. Using the elapsed time count in the the Rexx shows
* shows an increase from 4.9 seconds to 6.9 seconds. Testing with
* the tree-view sort function has not been doen.
*/
int32_t CALLBACK TvRexxCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
if ( lParam1 == NULL || lParam2 == NULL )
{
return 0;
}
pCRexxSort pcrs = (pCRexxSort)lParamSort;
RexxThreadContext *c = pcrs->threadContext;
RexxArrayObject args = c->ArrayOfThree((RexxObjectPtr)lParam1, (RexxObjectPtr)lParam2, pcrs->param);
RexxObjectPtr reply = c->SendMessage(pcrs->rexxDlg, pcrs->method, args);
c->ReleaseLocalReference(args);
if ( msgReplyIsGood(c, pcrs->pcpbd, reply, pcrs->method, false) )
{
int32_t answer;
if ( c->Int32(reply, &answer) )
{
c->ReleaseLocalReference(reply);
return answer;
}
// We end the dialog on this error.
wrongReplyRangeException(c, pcrs->method, INT32_MIN, INT32_MAX, reply);
c->ReleaseLocalReference(reply);
endDialogPremature(pcrs->pcpbd, pcrs->pcpbd->hDlg, RexxConditionRaised);
}
else
{
if ( reply != NULLOBJECT )
{
c->ReleaseLocalReference(reply);
}
}
// There was some error if we are here ...
return 0;
}
/**
* Sets things up for a tree-view sort when the comparison function will invoke
* a method in the Rexx dialog to do the actual sorting.
*
* @param context
* @param sortInfo
* @param pcdc
*
* @return logical_t
*
* @note Testing shows that using a method in the Rexx dialog to do the sort
* works well and seems fast with a smallish number of tree-view items.
*
* However, the similar list-view sort, with large lists it is slow. This
* can be seen with lists containing a 1000 item. Haven't done any
* testing with a tree-view yet.
*
* @remarks The TreeView_SortChildrenCB() documentes the third argument as
* being: fRecurse Reserved. Must be zero. However, if it is 0 then
* the children of the item do not sort if the item is expanded. They
* do sort if the item is closed up. Testing shows that the compare
* function is never invoked.
*
* But, if I make the 3rd argument TRUE, the the items always sort,
* whether the parent is closed or expanded. Not sure what the deal
* is there, if it is just a MS doc problem, or what.
*/
logical_t rexxTreeViewSort(RexxMethodContext *context, HTREEITEM hItem, CSTRING method,
RexxObjectPtr sortInfo, pCDialogControl pcdc)
{
pCRexxSort pcrs = pcdc->pcrs;
if ( pcrs == NULL )
{
pcrs = (pCRexxSort)LocalAlloc(LPTR, sizeof(CRexxSort));
if ( pcrs == NULL )
{
outOfMemoryException(context->threadContext);
return FALSE;
}
pcdc->pcrs = pcrs;
}
safeLocalFree(pcrs->method);
memset(pcrs, 0, sizeof(CRexxSort));
pcrs->method = (char *)LocalAlloc(LPTR, strlen(method) + 1);
if ( pcrs->method == NULL )
{
outOfMemoryException(context->threadContext);
return FALSE;
}
strcpy(pcrs->method, method);
pcrs->pcpbd = pcdc->pcpbd;
pcrs->rexxDlg = pcdc->pcpbd->rexxSelf;
pcrs->rexxCtrl = pcdc->rexxSelf;
pcrs->threadContext = pcdc->pcpbd->dlgProcContext;
pcrs->hItem = hItem;
pcrs->param = (argumentExists(3) ? sortInfo : TheNilObj);
TVSORTCB tvscb;
tvscb.hParent = hItem;
tvscb.lParam = (LPARAM)pcrs;
tvscb.lpfnCompare = TvRexxCompareFunc;
return TreeView_SortChildrenCB(pcdc->hCtrl, &tvscb, TRUE);
}
/** TreeView::delete()
*
*
* @returns 0 on sucees, 1 on error, and -1 if hItem is not valid.
*
* @remarks The return codes for this are not optimal. But they are what was
* documented and used in the original ooDialog from IBM.
*
*/
RexxMethod2(RexxObjectPtr, tv_delete, CSTRING, _hItem, CSELF, pCSelf)
{
pCDialogControl pcdc = validateDCCSelf(context, pCSelf);
if ( pcdc == NULL )
{
return TheNegativeOneObj;
}
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
if ( hItem == NULL )
{
return TheNegativeOneObj;
}
if ( TreeView_GetCount(pcdc->hCtrl) < 1 )
{
return TheNegativeOneObj;
}
unProtectControlUserData(context, pcdc, getCurrentTviUserData(pcdc->hCtrl, hItem));
return TreeView_DeleteItem(pcdc->hCtrl, hItem) ? TheZeroObj : TheOneObj;
}
/** TreeView::deleteAll()
*
* @returns 0 on success, 1 on error. These are the original ooDialog return
* codes
*
*/
RexxMethod1(RexxObjectPtr, tv_deleteAll, CSELF, pCSelf)
{
pCDialogControl pcdc = validateDCCSelf(context, pCSelf);
if ( pcdc == NULL )
{
return TheOneObj;
}
if ( pcdc->rexxBag != NULL )
{
context->SendMessage0(pcdc->rexxBag, "EMPTY");
}
return TreeView_DeleteAllItems(pcdc->hCtrl) ? TheZeroObj : TheOneObj;
}
/** TreeView::insert()
*
*/
RexxMethod9(RexxObjectPtr, tv_insert, OPTIONAL_CSTRING, _hItem, OPTIONAL_CSTRING, _hAfter, OPTIONAL_CSTRING, label,
OPTIONAL_int32_t, imageIndex, OPTIONAL_int32_t, selectedImage, OPTIONAL_CSTRING, opts, OPTIONAL_uint32_t, children,
OPTIONAL_RexxObjectPtr, userData, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
TVINSERTSTRUCT ins;
TVITEMEX *tvi = &ins.itemex;
if ( argumentExists(1) )
{
if ( stricmp(_hItem, "ROOT") == 0 )
{
ins.hParent = TVI_ROOT;
}
else
{
ins.hParent = (HTREEITEM)string2pointer(_hItem);
}
}
else
{
ins.hParent = TVI_ROOT;
}
if ( argumentExists(2) )
{
if ( stricmp(_hAfter, "FIRST") == 0 ) ins.hInsertAfter = TVI_FIRST;
else if ( stricmp(_hAfter, "SORT") == 0 ) ins.hInsertAfter = TVI_SORT;
else if ( stricmp(_hAfter, "LAST") == 0 ) ins.hInsertAfter = TVI_LAST;
else ins.hInsertAfter = (HTREEITEM)string2pointer(_hAfter);
}
else
{
ins.hInsertAfter = TVI_LAST;
}
memset(tvi, 0, sizeof(TVITEMEX));
label = (argumentOmitted(3) ? "" : label);
imageIndex = (argumentOmitted(4) ? -1 : imageIndex);
selectedImage = (argumentOmitted(5) ? -1 : selectedImage);
tvi->mask = TVIF_TEXT;
tvi->pszText = (LPSTR)label;
tvi->cchTextMax = (int)strlen(label);
if ( imageIndex > -1 )
{
tvi->iImage = imageIndex;
tvi->mask |= TVIF_IMAGE;
}
if ( selectedImage > -1 )
{
tvi->iSelectedImage = selectedImage;
tvi->mask |= TVIF_SELECTEDIMAGE;
}
if ( argumentExists(6) )
{
if ( StrStrI(opts, "BOLD") != NULL ) tvi->state |= TVIS_BOLD;
if ( StrStrI(opts, "EXPANDED") != NULL ) tvi->state |= TVIS_EXPANDED;
if ( tvi->state != 0 )
{
tvi->stateMask = tvi->state;
tvi->mask |= TVIF_STATE;
}
}
if ( children > 0 )
{
tvi->cChildren = children;
tvi->mask |= TVIF_CHILDREN;
}
if ( argumentExists(8) && userData != TheNilObj)
{
protectControlUserData(context, (pCDialogControl)pCSelf, userData);
tvi->lParam = (LPARAM)userData;
tvi->mask |= TVIF_PARAM;
}
return pointer2string(context, TreeView_InsertItem(hwnd, &ins));
}
/** TreeView::itemInfo()
*
*/
RexxMethod2(RexxObjectPtr, tv_itemInfo, CSTRING, _hItem, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
TVITEM tvi = {0};
char buf[256];
tvi.hItem = (HTREEITEM)string2pointer(_hItem);
tvi.mask = TVIF_HANDLE | TVIF_TEXT | TVIF_STATE | TVIF_IMAGE | TVIF_CHILDREN | TVIF_SELECTEDIMAGE | TVIF_PARAM;
tvi.pszText = buf;
tvi.cchTextMax = 255;
tvi.stateMask = TVIS_EXPANDED | TVIS_BOLD | TVIS_SELECTED | TVIS_EXPANDEDONCE | TVIS_DROPHILITED | TVIS_CUT | TVIS_EXPANDPARTIAL;
if ( TreeView_GetItem(hwnd, &tvi) == 0 )
{
return TheNegativeOneObj;
}
RexxStemObject stem = context->NewStem("InternalTVItemInfo");
context->SetStemElement(stem, "!TEXT", context->String(tvi.pszText));
context->SetStemElement(stem, "!CHILDREN", (tvi.cChildren > 0 ? TheTrueObj : TheFalseObj));
context->SetStemElement(stem, "!IMAGE", context->Int32(tvi.iImage));
context->SetStemElement(stem, "!SELECTEDIMAGE", context->Int32(tvi.iSelectedImage));
*buf = '\0';
if ( tvi.state & TVIS_EXPANDED ) strcat(buf, "EXPANDED ");
if ( tvi.state & TVIS_BOLD ) strcat(buf, "BOLD ");
if ( tvi.state & TVIS_SELECTED ) strcat(buf, "SELECTED ");
if ( tvi.state & TVIS_EXPANDEDONCE ) strcat(buf, "EXPANDEDONCE ");
if ( tvi.state & TVIS_DROPHILITED ) strcat(buf, "INDROP ");
if ( tvi.state & TVIS_CUT ) strcat(buf, "CUT ");
if ( tvi.state & TVIS_EXPANDPARTIAL) strcat(buf, "EXPANDPARTIAL ");
if ( *buf != '\0' )
{
*(buf + strlen(buf) - 1) = '\0';
}
context->SetStemElement(stem, "!STATE", context->String(buf));
context->SetStemElement(stem, "!USERDATA", tvi.lParam ? (RexxObjectPtr)tvi.lParam : TheNilObj);
return stem;
}
/** TreeView::getImageList()
*
* Gets the tree-view's specifed image list.
*
* @param type [optional] Identifies which image list to get, normal, or
* state. Normal is the default.
*
* @return The image list, if it exists, otherwise .nil.
*/
RexxMethod2(RexxObjectPtr, tv_getImageList, OPTIONAL_uint8_t, type, OSELF, self)
{
if ( argumentOmitted(1) )
{
type = TVSIL_NORMAL;
}
else if ( type != TVSIL_STATE && type != TVSIL_NORMAL )
{
return invalidTypeException(context->threadContext, 2, "TVSIL_XXX flag");
}
RexxObjectPtr result = context->GetObjectVariable(tvGetAttributeName(type));
if ( result == NULLOBJECT )
{
result = TheNilObj;
}
return result;
}
/** TreeView::getItemData()
*
* Returns the user data associated with the specified tree-view item, or .nil
* if there is no user data associated.
*
* @param hItem [required] The handle of the item whose user data is to be
* retrieved.
*
* @return Returns the associated user data, or .nil if there is no associated
* data.
*/
RexxMethod2(RexxObjectPtr, tv_getItemData, CSTRING, _hItem, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
return getCurrentTviUserData(hwnd, hItem);
}
/** TreeView::getItemHeight()
*
* Returns the current height of the tree-view items.
*
* @return Returns the current height of the tree-view items in pixels.
*
* @remarks The tree-view uses the value returned for the height of all items.
* The value itself is the height of a single item. See the
* TreeView::setItemHeight() method.
*/
RexxMethod1(int32_t, tv_getItemHeight, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
return TreeView_GetItemHeight(hwnd);
}
/** TreeView::getItemRect()
*
* Retrieves the bounding rectangle for a tree-view item and indicates whether
* the item is visible.
*
* @param hItem [required] The handle of the item whose bounding rectangle
* is to be retrieved.
*
* @param rect [required in / out] A .Rect object used to return the
* bounding rectangle co-ordinates. Co-ordinates are client
* co-ordinates.
*
* @param textOnly [optional] If textOnly is true, the bounding rectangle
* returned is for the text portion only of the item. If
* false, the rectangle includes the entire line the item
* occupies in the tree-view control. If the argument is
* omitted, the default is true.
*
* @return Returns true if the item specified is visible and the bounding
* rectangle is filled in. Returns false if the item is not visible
* and the bounding rectangle is not filled in.
*
* @remarks The co-ordinates of the bounding rectangle are only filled in if
* the item is visible.
*/
RexxMethod4(logical_t, tv_getItemRect, CSTRING, _hItem, RexxObjectPtr, _rect, OPTIONAL_logical_t, textOnly, CSELF, pCSelf)
{
if ( ! context->IsOfType(_rect, "RECT") )
{
wrongClassException(context->threadContext, 2, "Rect", _rect);
return FALSE;
}
if ( argumentOmitted(3) )
{
textOnly = TRUE;
}
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
PRECT rect = (PRECT)context->ObjectToCSelf(_rect);
return TreeView_GetItemRect(hwnd, hItem, rect, textOnly);
}
/** TreeView::getItemPartRect()
*
* Retrieves the largest possible bounding rectangle that constitutes the "hit
* zone" for a specified part of a tree-view item.
*
* @param hItem [required] The handle of the item whose bounding rectangle
* is to be retrieved.
*
* @param rect [required in / out] A .Rect object used to return the
* bounding rectangle co-ordinates. Co-ordinates are client
* co-ordinates
*
* @param part [optional] A keyword specifying which part of the item the
* bounding rectangle is to be returned for. Currently the
* operating system only supplies one part ID, the button ID.
* Because of this, the "part" argument is simply ignored and
* the button ID is used.
*
*
* @return Returns true on success, otherwise false.
*
* @notes Requires Windows Vista or later.
*
* The largest possible bounding rectangle is such that for every
* (x,y) co-ordinate within the rectangle, a click by the user at that
* co-ordinate would constitute a hit on that part of the item. Note
* that the only part is the button part.
*
* @remarks This does not work due to a bug in the Windows SDK. Leaving the
* code here in case the bug is fixed. If this is added back in,
* then tv_getItemPartRect will need to be added back to
* oodPackageEntry.cpp and TreeView.cls.
*/
#if 0
RexxMethod4(logical_t, tv_getItemPartRect, CSTRING, _hItem, RexxObjectPtr, _rect, OPTIONAL_CSTRING, part, CSELF, pCSelf)
{
if ( ! context->IsOfType(_rect, "RECT") )
{
wrongClassException(context->threadContext, 2, "Rect", _rect);
return FALSE;
}
if ( requiredOS(context, "getItemPartRect", "Vista", Vista_OS) )
{
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
PRECT rect = (PRECT)context->ObjectToCSelf(_rect);
return TreeView_GetItemPartRect(hwnd, hItem, rect, TVGIPR_BUTTON);
}
return FALSE;
}
#endif
RexxMethod2(RexxObjectPtr, tv_getSpecificItem, NAME, method, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM result = NULL;
switch ( *method )
{
case 'R' :
result = TreeView_GetRoot(hwnd);
break;
case 'S' :
result = TreeView_GetSelection(hwnd);
break;
case 'D' :
result = TreeView_GetDropHilight(hwnd);
break;
case 'F' :
result = TreeView_GetFirstVisible(hwnd);
break;
}
return pointer2string(context, result);
}
/** TreeView::getNextItem()
*
*
*/
RexxMethod3(RexxObjectPtr, tv_getNextItem, CSTRING, _hItem, NAME, method, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
uint32_t flag = TVGN_PARENT;
if ( strcmp(method, "PARENT") == 0 ) flag = TVGN_PARENT;
else if ( strcmp(method, "CHILD") == 0 ) flag = TVGN_CHILD;
else if ( strcmp(method, "NEXT") == 0 ) flag = TVGN_NEXT;
else if ( strcmp(method, "NEXTVISIBLE") == 0 ) flag = TVGN_NEXTVISIBLE;
else if ( strcmp(method, "PREVIOUS") == 0 ) flag = TVGN_PREVIOUS;
else if ( strcmp(method, "PREVIOUSVISIBLE") == 0 ) flag = TVGN_PREVIOUSVISIBLE;
return pointer2string(context, TreeView_GetNextItem(hwnd, hItem, flag));
}
/** TreeView::itemText()
*
*
*
* @note Although the tree-view allows any length of text to be stored for an
* item, it only displays the first 260 characters. So, here that is
* all we return.
*/
RexxMethod2(RexxObjectPtr, tv_itemText, CSTRING, _hItem, CSELF, pCSelf)
{
char buf[261];
HWND hwnd = getDChCtrl(pCSelf);
TVITEMEX tvi = {0};
tvi.hItem = (HTREEITEM)string2pointer(_hItem);
tvi.mask = TVIF_HANDLE | TVIF_TEXT;
tvi.pszText = buf;
tvi.cchTextMax = 261;
RexxObjectPtr result = context->NullString();
if ( TreeView_GetItem(hwnd, &tvi) != 0 )
{
result = context->String(tvi.pszText);
}
return result;
}
/** TreeView::modify()
*
*
*/
RexxMethod8(int32_t, tv_modify, OPTIONAL_CSTRING, _hItem, OPTIONAL_CSTRING, label, OPTIONAL_int32_t, imageIndex,
OPTIONAL_int32_t, selectedImage, OPTIONAL_CSTRING, opts, OPTIONAL_uint32_t, children,
OPTIONAL_RexxObjectPtr, userData, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
TVITEMEX tvi = {0};
if ( argumentExists(1) )
{
tvi.hItem = (HTREEITEM)string2pointer(_hItem);
}
else
{
tvi.hItem = TreeView_GetSelection(hwnd);
}
if ( tvi.hItem == NULL )
{
return -1;
}
tvi.mask = TVIF_HANDLE;
if ( argumentExists(2) )
{
tvi.pszText = (LPSTR)label;
tvi.cchTextMax = (int)strlen(label);
tvi.mask |= TVIF_TEXT;
}
if ( argumentExists(3) && imageIndex > -1 )
{
tvi.iImage = imageIndex;
tvi.mask |= TVIF_IMAGE;
}
if ( argumentExists(4) && selectedImage > -1 )
{
tvi.iSelectedImage = selectedImage;
tvi.mask |= TVIF_SELECTEDIMAGE;
}
if ( argumentExists(5) && *opts != '\0' )
{
parseTvModifyOpts(opts, &tvi);
}
if ( argumentExists(6) )
{
tvi.cChildren = (children > 0 ? 1 : 0);
tvi.mask |= TVIF_CHILDREN;
}
if ( argumentExists(7) && userData != TheNilObj)
{
RexxObjectPtr oldData = getCurrentTviUserData(hwnd, tvi.hItem);
unProtectControlUserData(context, (pCDialogControl)pCSelf, oldData);
protectControlUserData(context, (pCDialogControl)pCSelf, userData);
tvi.lParam = (LPARAM)userData;
tvi.mask |= TVIF_PARAM;
}
return (TreeView_SetItem(hwnd, &tvi) == 0 ? 1 : 0);
}
/** TreeView::dropHighLight()
* TreeView::makeFirstVisible()
* TreeView::select()
*/
RexxMethod3(RexxObjectPtr, tv_selectItem, OPTIONAL_CSTRING, _hItem, NAME, method, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM hItem = NULL;
uint32_t flag;
if ( argumentExists(1) )
{
hItem = (HTREEITEM)string2pointer(_hItem);
}
switch ( *method )
{
case 'S' :
flag = TVGN_CARET;
break;
case 'M' :
flag = TVGN_FIRSTVISIBLE;
break;
default:
flag = TVGN_DROPHILITE;
}
return (TreeView_Select(hwnd, hItem, flag) ? TheZeroObj : TheOneObj);
}
/** TreeView::expand()
* TreeView::collapse()
* TreeView::collapseAndReset()
* TreeView::toggle()
*/
RexxMethod3(RexxObjectPtr, tv_expand, CSTRING, _hItem, NAME, method, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
uint32_t flag = TVE_EXPAND;
if ( *method == 'C' )
{
flag = (method[8] == 'A' ? (TVE_COLLAPSERESET | TVE_COLLAPSE) : TVE_COLLAPSE);
}
else if ( *method == 'T' )
{
flag = TVE_TOGGLE;
}
return (TreeView_Expand(hwnd, hItem, flag) ? TheZeroObj : TheOneObj);
}
/** TreeView::find()
*
* Finds the first item with the specified text.
*
*/
RexxMethod2(RexxObjectPtr, tv_find, CSTRING, text, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
HTREEITEM hItem = tvFindItem(hwnd, text);
return pointer2string(context, hItem);
}
/** TreeView::hitTestInfo()
*
* Determine the location of a point relative to the tree-view control.
*
* @param pHit The position, x and y co-ordinates of the point to test. This
* can be specified in two forms.
*
* Form 1: arg 1 is a .Point object.
* Form 2: arg 1 is the x co-ordinate and arg2 is the y co-ordinate.
*
* @return A directory object containing the result of the test in these
* indexes:
*
* hItem The handle to the tree-view item that occupies the
* point. This will be 0, if there is no item at the
* point.
*
* location A string of blank separated keywords describing the
* location of the point. For instance, the string might
* be "ONITEM ONLABEL" or it could be "ABOVE TORIGHT" if
* the point is not on the client area of the tree-view at
* all.
*
* @note Any x, y coordinates will work. I.e. -6000, -7000 will work. The
* hItem will be 0 and location will be "ABOVE TOLEFT"
*/
RexxMethod2(RexxObjectPtr, tv_hitTestInfo, ARGLIST, args, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
size_t sizeArray;
size_t argsUsed;
POINT point;
if ( ! getPointFromArglist(context, args, &point, 1, 2, &sizeArray, &argsUsed) )
{
return NULLOBJECT;
}
if ( argsUsed == 1 && sizeArray == 2)
{
return tooManyArgsException(context->threadContext, 1);
}
TVHITTESTINFO hti;
hti.pt.x = point.x;
hti.pt.y = point.y;
HTREEITEM hItem = TreeView_HitTest(hwnd, &hti);
RexxDirectoryObject result = context->NewDirectory();
context->DirectoryPut(result, pointer2string(context, hti.hItem), "HITEM");
char buf[128];
*buf = '\0';
if ( hti.flags & TVHT_ABOVE ) strcat(buf, "ABOVE ");
if ( hti.flags & TVHT_BELOW ) strcat(buf, "BELOW ");
if ( hti.flags & TVHT_NOWHERE ) strcat(buf, "NOWHERE ");
if ( hti.flags & TVHT_ONITEM ) strcat(buf, "ONITEM ");
if ( hti.flags & TVHT_ONITEMBUTTON ) strcat(buf, "ONBUTTON ");
if ( hti.flags & TVHT_ONITEMICON ) strcat(buf, "ONICON ");
if ( hti.flags & TVHT_ONITEMINDENT ) strcat(buf, "ONINDENT ");
if ( hti.flags & TVHT_ONITEMLABEL ) strcat(buf, "ONLABEL ");
if ( hti.flags & TVHT_ONITEMRIGHT ) strcat(buf, "ONRIGHT ");
if ( hti.flags & TVHT_ONITEMSTATEICON) strcat(buf, "ONSTATEICON ");
if ( hti.flags & TVHT_TOLEFT ) strcat(buf, "TOLEFT ");
if ( hti.flags & TVHT_TORIGHT ) strcat(buf, "TORIGHT ");
if ( *buf != '\0' )
{
*(buf + strlen(buf) - 1) = '\0';
}
context->DirectoryPut(result, context->String(buf),"LOCATION");
return result;
}
/** TreeView::removeItemData()
*
*/
RexxMethod2(RexxObjectPtr, tv_removeItemData, CSTRING, _hItem, CSELF, pCSelf)
{
pCDialogControl pcdc = validateDCCSelf(context, pCSelf);
if ( pcdc == NULL )
{
return TheNilObj;
}
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
RexxObjectPtr oldUserData = getCurrentTviUserData(pcdc->hCtrl, hItem);
RexxObjectPtr result = getCurrentTviUserData(pcdc->hCtrl, hItem);
if ( result != TheNilObj )
{
TVITEMEX tvi = {TVIF_PARAM, hItem};
if ( TreeView_SetItem(pcdc->hCtrl, &tvi) )
{
unProtectControlUserData(context, pcdc, result);
}
else
{
// Not removed, set result back to the .nil ojbect.
result = TheNilObj;
}
}
return result;
}
/** TreeView::setImageList()
*
* Sets or removes one of a tree-view's image lists.
*
* @param ilSrc The image list source. Either an .ImageList object that
* references the image list to be set, or a single bitmap from
* which the image list is constructed, or .nil. If ilSRC is
* .nil, an existing image list, if any is removed.
*
* @param width [optional] This arg serves two purposes. If ilSrc is .nil or
* an .ImageList object, this arg indentifies which of the
* tree-views image lists is being set, normal, or state. The
* default is TVSI_NORMAL.
*
* If ilSrc is a bitmap, then this arg is the width of a single
* image. The default is the height of the actual bitmap.
*
* @param height [optional] This arg is only used if ilSrc is a bitmap, in which case it
* is the height of the bitmap. The default is the height of the
* actual bitmap
*
* @return Returns the exsiting .ImageList object if there is one, or
* .nil if there is not an existing object.
*
* @note When the ilSrc is a single bitmap, an image list is created from the
* bitmap. This method is not as flexible as if the programmer created
* the image list herself. The bitmap must be a number of images, all
* the same size, side-by-side in the bitmap. The width of a single
* image determines the number of images. The image list is created
* using the ILC_COLOR8 flag, only. No mask can be used. No room is
* reserved for adding more images to the image list, etc..
*
* The image list can only be assigned to the normal image list. There
* is no way to use the image list for the state image list.
*/
RexxMethod4(RexxObjectPtr, tv_setImageList, RexxObjectPtr, ilSrc,
OPTIONAL_int32_t, width, OPTIONAL_int32_t, height, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
HWND hwnd = getDChCtrl(pCSelf);
HIMAGELIST himl = NULL;
int type = TVSIL_NORMAL;
RexxObjectPtr imageList = NULLOBJECT;
if ( ilSrc == TheNilObj )
{
imageList = ilSrc;
if ( argumentExists(2) )
{
type = width;
}
}
else if ( context->IsOfType(ilSrc, "IMAGELIST") )
{
imageList = ilSrc;
himl = rxGetImageList(context, imageList, 1);
if ( himl == NULL )
{
goto err_out;
}
if ( argumentExists(2) )
{
type = width;
}
}
else
{
imageList = oodILFromBMP(context, &himl, ilSrc, width, height, hwnd);
if ( imageList == NULLOBJECT )
{
goto err_out;
}
}
if ( type != TVSIL_STATE && type != TVSIL_NORMAL )
{
invalidTypeException(context->threadContext, 2, "TVSIL_XXX flag");
goto err_out;
}
TreeView_SetImageList(hwnd, himl, type);
return rxSetObjVar(context, tvGetAttributeName(type), imageList);
err_out:
return NULLOBJECT;
}
/** TreeView::setItemData()
*
* Assigns a user data value to the specified tree-view item.
*
* @param hItem [required] The handle of the item whose user data is to be
* set.
*
* @param data [optional] The user data to be set. If this argument is
* omitted, the current user data, if any, is removed.
*
* @return Returns the previous user data object for the specified tree-view
* item, if there was a user data object, or .nil if there wasn't.
*
* On error, .nil is returned. An error is very unlikely. An error
* can be checked for by examining the .systemErrorCode object.
*
* @notes Sets the .systemErrorCode. On error set to:
*
* 156 ERROR_SIGNAL_REFUSED The recipient process has refused the
* signal.
*
* This is not a system error, the code is just used here to indicate a
* tree-view error when setting the user data. The tree-view provides
* no information on why it failed.
*/
RexxMethod3(RexxObjectPtr, tv_setItemData, CSTRING, _hItem, OPTIONAL_RexxObjectPtr, data, CSELF, pCSelf)
{
oodResetSysErrCode(context->threadContext);
pCDialogControl pcdc = validateDCCSelf(context, pCSelf);
if ( pcdc == NULL )
{
return TheNilObj;
}
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
RexxObjectPtr oldUserData = getCurrentTviUserData(pcdc->hCtrl, hItem);
TVITEMEX tvi = {0};
tvi.hItem = hItem;
tvi.mask = TVIF_PARAM;
if ( argumentExists(2) )
{
tvi.lParam = (LPARAM)data;
if ( TreeView_SetItem(pcdc->hCtrl, &tvi) )
{
unProtectControlUserData(context, pcdc, oldUserData);
protectControlUserData(context, pcdc, data);
}
else
{
oldUserData = TheNilObj;
oodSetSysErrCode(context->threadContext, 156);
}
}
else
{
if ( TreeView_SetItem(pcdc->hCtrl, &tvi) )
{
unProtectControlUserData(context, pcdc, oldUserData);
}
else
{
oldUserData = TheNilObj;
oodSetSysErrCode(context->threadContext, 156);
}
}
return oldUserData;
}
/** TreeView::setItemHeight()
*
* Sets the height of the tree-view items.
*
* @param cyItem [required] The new height for every item in the tree view,
* in pixels. Heights less than 1 will be set to 1. If this
* argument is not even, it will be rounded down to the
* nearest even value. If this argument is -1, the control
* will revert to using its default item height.
*
* @return Returns the previous height of the tree-view items in pixels.
*
* @remarks The tree-view uses the value for the height of all items. The
* value itself is the height of a single item. See the
* TreeView::getItemHeight() method.
*/
RexxMethod2(int32_t, tv_setItemHeight, int32_t, cyItem, CSELF, pCSelf)
{
HWND hwnd = getDChCtrl(pCSelf);
return TreeView_SetItemHeight(hwnd, cyItem);
}
/** TreeView::sortChildrenCB()
*
* Tells the tree-view to sort the children of the specified parent item using
* a call back into a compare function in the Rexx dialog.
*
* @param hParent The parent item whose children will be sorted.
*
* @param method The name of the method in the Rexx dialog that will be
* invoked by the tree-view control.
*
*/
RexxMethod4(logical_t, tv_sortChildrenCB, CSTRING, _hItem, CSTRING, method, OPTIONAL_RexxObjectPtr, param, CSELF, pCSelf)
{
pCDialogControl pcdc = validateDCCSelf(context, pCSelf);
if ( pcdc == NULL )
{
return FALSE;
}
HTREEITEM hItem = (HTREEITEM)string2pointer(_hItem);
return rexxTreeViewSort(context, hItem, method, param, pcdc);
}
/**
* Methods for the .TvCustomDrawSimple class.
*/
#define TVCUSTOMDRAWSIMPLE_CLASS "TvCustomDrawSimple"
/**
* Handles the processing for the tree-view custom draw event for the basic
* case. That is, the user wants to change text color or font, for a tree-view
* item.
*
* @param c
* @param methodName
* @param lParam
* @param pcpbd
*
* @return MsgReplyType
*
* @notes In testing the list-view custom draw, we saw what seemed to be hangs
* if there was an uncleared condition on entry. That seemed to be
* fixed by checking for a condition and immediately returning
* CDRF_DODEFAULT if a condition was detected.
*
* The simple case is to only respond to item prepaint or subitem
* prepaint. If the user returns .false from the event handler, this has
* the effect of returning CDFR_DODEFAULT to the list-view.
*
* If the user returns .true, we not check the reply value in the
* CTvCustomDrawSimple struct, assuming the user has set the value to
* what they actually want. The user should use either CDRF_NEWFONT, or,
* CDRF_NOTIFYSUBITEMDRAW or (CDRF_NOTIFYSUBITEMDRAW | CDRF_NEFONT.)
* When .true is returned the colors are updated in the NMLVCUSTOMDRAW
* struct. If hFont in the LvCustomDrawSimple object is not null, the
* font is selected into the device context, which has the effect of
* changing the font.
*/
MsgReplyType tvSimpleCustomDraw(RexxThreadContext *c, CSTRING methodName, LPARAM lParam, pCPlainBaseDialog pcpbd)
{
LPNMTVCUSTOMDRAW tvcd = (LPNMTVCUSTOMDRAW)lParam;
LPARAM reply = CDRF_DODEFAULT;
if ( c->CheckCondition() )
{
goto done_out;
}
if ( tvcd->nmcd.dwDrawStage == CDDS_PREPAINT )
{
reply = CDRF_NOTIFYITEMDRAW;
}
else if ( tvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT )
{
RexxBufferObject tvcdsBuf = c->NewBuffer(sizeof(CTvCustomDrawSimple));
if ( tvcdsBuf == NULLOBJECT )
{
outOfMemoryException(c);
endDialogPremature(pcpbd, pcpbd->hDlg, RexxConditionRaised);
goto done_out;
}
pCTvCustomDrawSimple pctvcds = (pCTvCustomDrawSimple)c->BufferData(tvcdsBuf);
memset(pctvcds, 0, sizeof(CTvCustomDrawSimple));
pctvcds->drawStage = tvcd->nmcd.dwDrawStage;
pctvcds->item = (HTREEITEM)tvcd->nmcd.dwItemSpec;
pctvcds->id = (uint32_t)((NMHDR *)lParam)->idFrom;
pctvcds->level = tvcd->iLevel;
pctvcds->userData = tvcd->nmcd.lItemlParam ? (RexxObjectPtr)tvcd->nmcd.lItemlParam : TheNilObj;
RexxObjectPtr custDrawSimple = c->SendMessage1(TheTvCustomDrawSimpleClass, "NEW", tvcdsBuf);
if ( custDrawSimple != NULLOBJECT )
{
RexxObjectPtr msgReply = c->SendMessage1(pcpbd->rexxSelf, methodName, custDrawSimple);
msgReply = requiredBooleanReply(c, pcpbd, msgReply, methodName, false);
if ( msgReply == TheTrueObj )
{
tvcd->clrText = pctvcds->clrText;
tvcd->clrTextBk = pctvcds->clrTextBk;
if ( pctvcds->hFont != NULL )
{
// An example I've seen deletes the old font. Doesn't seem
// appropriate for ooRexx. The user would need to save the
// tree-view font and then add it back in. Not sure if
// there is a resource leak here.
HFONT hOldFont = (HFONT)SelectObject(tvcd->nmcd.hdc, pctvcds->hFont);
}
reply = pctvcds->reply;
}
c->ReleaseLocalReference(custDrawSimple);
}
c->ReleaseLocalReference(tvcdsBuf);
}
done_out:
setWindowPtr(pcpbd->hDlg, DWLP_MSGRESULT, (LPARAM)reply);
return ReplyTrue;
}
/** TvCustomDrawSimple::init() [class]
*
*
*/
RexxMethod1(RexxObjectPtr, tvcds_init_cls, OSELF, self)
{
if ( isOfClassType(context, self, TVCUSTOMDRAWSIMPLE_CLASS) )
{
TheTvCustomDrawSimpleClass = (RexxClassObject)self;
context->RequestGlobalReference(TheTvCustomDrawSimpleClass);
}
return NULLOBJECT;
}
/** TvCustomDrawSimple::init()
*
*/
RexxMethod2(RexxObjectPtr, tvcds_init, RexxObjectPtr, cself, OSELF, self)
{
if ( context->IsBuffer(cself) )
{
context->SetObjectVariable("CSELF", cself);
}
else
{
baseClassInitializationException(context, "TvCustomDrawSimple");
}
return NULLOBJECT;
}
/** TvCustomDrawSimple::clrText [attribute]
*/
RexxMethod2(uint32_t, tvcds_setClrText, uint32_t, clrText, CSELF, pCSelf)
{
((pCTvCustomDrawSimple)pCSelf)->clrText = clrText;
return NULLOBJECT;
}
/** TvCustomDrawSimple::clrTextBk [attribute]
*/
RexxMethod2(RexxObjectPtr, tvcds_setClrTextBk, uint32_t, clrTextBk, CSELF, pCSelf)
{
((pCTvCustomDrawSimple)pCSelf)->clrTextBk = clrTextBk;
return NULLOBJECT;
}
/** TvCustomDrawSimple::drawStage [attribute]
*/
RexxMethod1(uint32_t, tvcds_getDrawStage, CSELF, pCSelf)
{
return ((pCTvCustomDrawSimple)pCSelf)->drawStage;
}
/** TvCustomDrawSimple::font [attribute]
*/
RexxMethod2(RexxObjectPtr, tvcds_setFont, POINTERSTRING, font, CSELF, pCSelf)
{
((pCTvCustomDrawSimple)pCSelf)->hFont = (HFONT)font;
return NULLOBJECT;
}
/** TvCustomDrawSimple::id [attribute]
*/
RexxMethod1(uint32_t, tvcds_getID, CSELF, pCSelf)
{
return ((pCTvCustomDrawSimple)pCSelf)->id;
}
/** TvCustomDrawSimple::item [attribute]
*/
RexxMethod1(RexxStringObject, tvcds_getItem, CSELF, pCSelf)
{
return pointer2string(context, ((pCTvCustomDrawSimple)pCSelf)->item);
}
/** TvCustomDrawSimple::reply [attribute]
*/
RexxMethod2(RexxObjectPtr, tvcds_setReply, uint32_t, reply, CSELF, pCSelf)
{
((pCTvCustomDrawSimple)pCSelf)->reply = reply;
return NULLOBJECT;
}
/** TvCustomDrawSimple::level [attribute]
*/
RexxMethod1(uint32_t, tvcds_getLevel, CSELF, pCSelf)
{
return ((pCTvCustomDrawSimple)pCSelf)->level + 1;
}
/** TvCustomDrawSimple::userData [attribute]
*/
RexxMethod1(RexxObjectPtr, tvcds_getUserData, CSELF, pCSelf)
{
RexxObjectPtr data = (RexxObjectPtr)((pCTvCustomDrawSimple)pCSelf)->userData;
return data == NULLOBJECT ? TheNilObj : data;
}