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
|
{%MainUnit gtkwscomctrls.pp}
{ $Id$
*****************************************************************************
This file is part of the Lazarus Component Library (LCL)
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
}
{ TGtkWSCustomListView }
type
TLVHack = class(TCustomListView)
end;
PCustomListViewData = ^TCustomListViewData;
TCustomListViewData = record
ScrollingData: TBaseScrollingWinControlData;
ViewStyle: TViewStyle;
end;
////////////////////////////////////////////////////////////////////////////////
// Event code
////////////////////////////////////////////////////////////////////////////////
//----------------------
//HDN_ENDTRACK
//HDN_TRACK
function GtkWSCustomListView_AbortColumnResize(AList: PGTKCList; AInfo: PWidgetInfo): GBoolean; cdecl;
begin
//TODO: implement
Result := False;
end;
//----------------------
//HDN_ENDTRACK
//HDN_TRACK
//HDN_ITEMCHANGED
//HDN_ITEMCHANGING
function GtkWSCustomListView_ResizeColumn(AList: PGTKCList; AColumn, AWidth: Integer; AInfo: PWidgetInfo): GBoolean; cdecl;
begin
//TODO: implement
Result := False;
end;
//----------------------
//HDN_ITEMCLICK
//LVN_COLUMNCLICK
function GtkWSCustomListView_ClickColumn(AList: PGTKCList; AColumn: Integer; AInfo: PWidgetInfo): GBoolean; cdecl;
var
msg: TLMNotify;
NM: TNMListView;
ALV: TListView;
begin
// this can happen when no columns are added which crashes the program
ALV := TListView(AInfo^.LCLObject);
if AColumn > ALV.Columns.Count-1 then
Exit;
msg.Msg := CN_NOTIFY;
FillChar(NM, SizeOf(NM), 0);
NM.hdr.hwndfrom := PtrUInt(AList);
NM.hdr.code := LVN_COLUMNCLICK;
NM.iItem := -1;
NM.iSubItem := AColumn;
msg.NMHdr := @NM.hdr;
Result := DeliverMessage(AInfo^.LCLObject, msg) = 0;
end;
//----------------------
//LVN_DELETEITEM
//LVN_INSERTITEM
function GtkWSCustomListView_RowMove(AList: PGTKCList; AnOldIdx, ANewIdx: Integer; AInfo: PWidgetInfo): GBoolean; cdecl;
var
msg: TLMNotify;
NM: TNMListView;
r: Boolean;
begin
// Simulate move by remove and insert
msg.Msg := CN_NOTIFY;
FillChar(NM, SizeOf(NM), 0);
NM.hdr.hwndfrom := PtrUInt(AList);
NM.hdr.code := LVN_DELETEITEM;
NM.iItem := AnOldIdx;
msg.NMHdr := @NM.hdr;
r := DeliverMessage(AInfo^.LCLObject, msg) = 0;
NM.hdr.code := LVN_INSERTITEM;
NM.iItem := ANewIdx;
Result := (DeliverMessage(AInfo^.LCLObject, msg) = 0) and r;
end;
//----------------------
//LVN_ITEMCHANGED
//LVN_ITEMCHANGING
function GtkWSCustomListView_SelectRow(AList: PGTKCList; ARow, AColumn: Integer; AEvent: PGDKEventButton; AInfo: PWidgetInfo): GBoolean; cdecl;
var
msg: TLMNotify;
NM: TNMListView;
begin
msg.Msg := CN_NOTIFY;
FillChar(NM, SizeOf(NM), 0);
NM.hdr.hwndfrom := PtrUInt(AList);
NM.hdr.code := LVN_ITEMCHANGED;
NM.iItem := ARow;
NM.iSubItem := AColumn;
NM.uNewState := LVIS_SELECTED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
Result := DeliverMessage(AInfo^.LCLObject, msg) = 0;
end;
function GtkWSCustomListView_UnSelectRow(AList: PGTKCList; ARow, AColumn: Integer; AEvent: PGDKEventButton; AInfo: PWidgetInfo): GBoolean; cdecl;
var
msg: TLMNotify;
NM: TNMListView;
begin
msg.Msg := CN_NOTIFY;
FillChar(NM, SizeOf(NM), 0);
NM.hdr.hwndfrom := PtrUInt(AList);
NM.hdr.code := LVN_ITEMCHANGED;
NM.iItem := ARow;
NM.iSubItem := AColumn;
NM.uOldState := LVIS_SELECTED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
Result := DeliverMessage(AInfo^.LCLObject, msg) = 0;
end;
function GtkWSCustomListView_ToggleFocusRow(AList: PGTKCList; AInfo: PWidgetInfo): GBoolean; cdecl;
var
msg: TLMNotify;
NM: TNMListView;
begin
// the defocus of the oldrow isn't send
msg.Msg := CN_NOTIFY;
FillChar(NM, SizeOf(NM), 0);
NM.hdr.hwndfrom := PtrUInt(AList);
NM.hdr.code := LVN_ITEMCHANGED;
NM.iItem := AList^.focus_row;
NM.iSubItem := 0;
NM.uNewState := LVIS_FOCUSED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
Result := DeliverMessage(AInfo^.LCLObject, msg) = 0;
end;
function GtkWSCustomListView_SelectAll(AList: PGTKCList; AInfo: PWidgetInfo): GBoolean; cdecl;
var
msg: TLMNotify;
NM: TNMListView;
ListView: TListView;
n: Integer;
begin
msg.Msg := CN_NOTIFY;
ListView := AInfo^.LCLObject as TListView;
FillChar(NM, SizeOf(NM), 0);
NM.hdr.hwndfrom := PtrUInt(AList);
NM.hdr.code := LVN_ITEMCHANGED;
for n := 0 to Listview.Items.Count - 1 do
begin
if ListView.Items[n].Selected
then Continue;
NM.iItem := n;
NM.iSubItem := -1;
NM.uNewState := LVIS_SELECTED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
Result := DeliverMessage(AInfo^.LCLObject, msg) = 0;
end;
end;
function GtkWSCustomListView_UnSelectAll(AList: PGTKCList; AInfo: PWidgetInfo): GBoolean; cdecl;
var
msg: TLMNotify;
NM: TNMListView;
ListView: TListView;
n: Integer;
begin
msg.Msg := CN_NOTIFY;
ListView := AInfo^.LCLObject as TListView;
FillChar(NM, SizeOf(NM), 0);
NM.hdr.hwndfrom := PtrUInt(AList);
NM.hdr.code := LVN_ITEMCHANGED;
for n := 0 to Listview.Items.Count - 1 do
begin
if not ListView.Items[n].Selected
then Continue;
NM.iItem := n;
NM.iSubItem := -1;
NM.uOldState := LVIS_SELECTED;
NM.uChanged := LVIF_STATE;
msg.NMHdr := @NM.hdr;
Result := DeliverMessage(AInfo^.LCLObject, msg) = 0;
end;
end;
function GtkWSCustomListView_EndSelection(AList: PGTKCList; AInfo: PWidgetInfo): GBoolean; cdecl;
begin
Result:=true;
end;
////////////////////////////////////////////////////////////////////////////////
// Column code
////////////////////////////////////////////////////////////////////////////////
class procedure TGtkWSCustomListView.ColumnDelete(const ALV: TCustomListView; const AIndex: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnDelete') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget^.columns = TLVHack(ALV).Columns.Count then Exit; // possible delayed update
if AIndex >= CListWidget^.columns then Exit; // ???
RecreateWnd(ALV);
end;
class function TGtkWSCustomListView.ColumnGetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
CListColumn: PGtkCListColumn;
begin
Result := -1;
if not WSCheckHandleAllocated(ALV, 'ColumnGetSize') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
// there is no get width function, so we need some internal hacking
if AIndex >= CListWidget^.columns then Exit;
CListColumn := CListWidget^.Column;
Inc(CListColumn, AIndex);
Result := CListColumn^.width;
end;
class procedure TGtkWSCustomListView.ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnInsert') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget^.columns = TLVHack(ALV).Columns.Count then Exit; // possible delayed update
RecreateWnd(ALV);
end;
class procedure TGtkWSCustomListView.ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn);
procedure CopyColumn(const AList: PGtkCList; const AIndex: Integer; const ASrc: PGtkCListColumn);
begin
gtk_clist_set_column_title(AList, AIndex, ASrc^.title);
gtk_clist_set_column_min_width(AList, AIndex, ASrc^.min_width);
gtk_clist_set_column_max_width(AList, AIndex, ASrc^.max_width);
gtk_clist_set_column_width(AList, AIndex, ASrc^.width);
gtk_clist_set_column_justification(AList, AIndex, ASrc^.justification);
gtk_clist_set_column_visibility(AList, AIndex, (ASrc^.flag0 and bm_TGtkCListColumn_visible) <> 0);
gtk_clist_set_column_resizeable(AList, AIndex, (ASrc^.flag0 and bm_TGtkCListColumn_resizeable) <> 0);
gtk_clist_set_column_auto_resize(AList, AIndex, (ASrc^.flag0 and bm_TGtkCListColumn_auto_resize) <> 0);
if (ASrc^.flag0 and bm_TGtkCListColumn_button_passive) <> 0
then gtk_clist_column_title_passive(AList, AIndex)
else gtk_clist_column_title_active(AList, AIndex);
end;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
CListColumn: PGtkCListColumn;
OldCListColumn: TGtkCListColumn;
Count: Integer;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnMove') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
if AOldIndex = ANewIndex then Exit;
if AOldIndex < 0 then Exit;
if ANewIndex < 0 then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if AOldIndex >= CListWidget^.columns then Exit;
if ANewIndex >= CListWidget^.columns then Exit;
Count := AOldIndex - ANewIndex;
// Fetch old column values
CListColumn := CListWidget^.Column;
Inc(CListColumn, AOldIndex);
OldCListColumn := CListColumn^;
// Create copy of the title
OldCListColumn.title := StrNew(OldCListColumn.title);
while Count <> 0 do
begin
// move to next source
if Count < 0
then Inc(CListColumn)
else Dec(CListColumn);
CopyColumn(CListWidget, ANewIndex + Count, CListColumn);
if Count < 0
then Inc(Count)
else Dec(Count);
end;
// finally copy original data to new column
CopyColumn(CListWidget, ANewIndex, @OldCListColumn);
// dispose copy of the title
StrDispose(OldCListColumn.title);
end;
class procedure TGtkWSCustomListView.ColumnSetAlignment(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment);
const
JUSTIFICATION: array[TAlignment] of TGtkJustification = (
GTK_JUSTIFY_LEFT,
GTK_JUSTIFY_RIGHT,
GTK_JUSTIFY_CENTER
);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAlignment') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_set_column_justification(CListWidget, AIndex, JUSTIFICATION[AAlignment]);
end;
class procedure TGtkWSCustomListView.ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetAutoSize') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_set_column_auto_resize(CListWidget, AIndex, AAutoSize);
end;
class procedure TGtkWSCustomListView.ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ACaption: String);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetCaption') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_set_column_title(CListWidget, AIndex, PChar(ACaption));
end;
class procedure TGtkWSCustomListView.ColumnSetImage(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetImage') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
//TODO
if CListWidget=nil then exit;
end;
class procedure TGtkWSCustomListView.ColumnSetMaxWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMaxWidth: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetMaxWidth') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
// TODO: ? -1 -2
//LVSCW_AUTOSIZE = -1;
//LVSCW_AUTOSIZE_USEHEADER = -2;
if AMaxWidth <= 0 // unlimited
then gtk_clist_set_column_max_width(CListWidget, AIndex, -1)
else gtk_clist_set_column_max_width(CListWidget, AIndex, AMaxWidth);
end;
class procedure TGtkWSCustomListView.ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetMinWidth') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_set_column_min_width(CListWidget, AIndex, AMinWidth);
end;
class procedure TGtkWSCustomListView.ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetWidth') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_set_column_width(CListWidget, AIndex, AWidth);
end;
class procedure TGtkWSCustomListView.ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ColumnSetVisible') then Exit;
// allow only column modifications when in report mode
if TLVHack(ALV).ViewStyle <> vsReport then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_set_column_visibility(CListWidget, AIndex, AVisible);
end;
////////////////////////////////////////////////////////////////////////////////
// Item code
////////////////////////////////////////////////////////////////////////////////
class procedure TGtkWSCustomListView.ItemChangeInternal(const ACListWidget: PGtkCList; const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem);
var
ImageBitmap: TBitmap;
GDIObject: PGDIObject;
Pixmap: PGdkPixmap;
Mask: PGdkBitmap;
n, Count: integer;
begin
if (TLVHack(ALV).SmallImages <> nil)
and (AItem.ImageIndex >= 0)
and (AItem.ImageIndex < TLVHack(ALV).SmallImages.Count)
then begin
// set image & caption
ImageBitmap := TBitmap.Create;
Mask := nil;
try
TLVHack(ALV).SmallImages.GetBitmap(AItem.ImageIndex, ImageBitmap);
GDIObject := PGDIObject(ImageBitmap.Handle);
case GDIObject^.GDIBitmapType of
gbBitmap:
begin
Pixmap := GDIObject^.GDIBitmapObject;
Mask := nil;
end;
gbPixmap:
begin
Pixmap := GDIObject^.GDIPixmapObject.Image;
Mask := CreateGdkMaskBitmap(ImageBitmap.Handle, ImageBitmap.MaskHandle);
end;
gbPixbuf:
begin
Pixmap := nil;
Mask := nil;
gdk_pixbuf_render_pixmap_and_mask(GDIObject^.GDIPixbufObject, Pixmap, Mask, $80);
end;
end;
gtk_clist_set_pixtext(ACListWidget, AIndex, 0, PChar(AItem.Caption), 3, Pixmap, Mask);
finally
if Mask <> nil then
gdk_bitmap_unref(Mask);
if Pixmap <> GDIObject^.GDIPixmapObject.Image then
gdk_pixmap_unref(Pixmap);
ImageBitmap.Free;
end;
end
else begin
// set caption alone
gtk_clist_set_text(ACListWidget, AIndex, 0, PChar(AItem.Caption));
end;
// set the other column texts
Count := AItem.SubItems.Count + 1;
if Count > ACListWidget^.Columns
then Count := ACListWidget^.Columns;
// set the existing subitems
for n := 1 to Count - 1 do
gtk_clist_set_text(ACListWidget, AIndex, n, PChar(AItem.SubItems[n - 1]));
// fill remaining
for n := Count to ACListWidget^.Columns - 1 do
gtk_clist_set_text(ACListWidget, AIndex, n, #0);
end;
class procedure TGtkWSCustomListView.ItemDelete(const ALV: TCustomListView;
const AIndex: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ItemDelete')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_remove(CListWidget, AIndex);
end;
class procedure TGtkWSCustomListView.ItemExchange(const ALV: TCustomListView;
AItem: TListItem; const AIndex1, AIndex2: Integer);
begin
if not WSCheckHandleAllocated(ALV, 'ItemExchange') then
exit;
ItemMove(ALV, AItem, AIndex1, AIndex2);
if AIndex1 > AIndex2 then
ItemMove(ALV, AItem, AIndex2 + 1, AIndex1)
else
ItemMove(ALV, AItem, AIndex2 - 1, AIndex1);
end;
class procedure TGtkWSCustomListView.ItemMove(const ALV: TCustomListView;
AItem: TListItem; const AFromIndex, AToIndex: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ItemMove') then
exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_row_move(CListWidget, AFromIndex, AToIndex);
end;
class function TGtkWSCustomListView.ItemGetState(const ALV: TCustomListView;
const AIndex: Integer; const AItem: TListItem; const AState: TListItemState;
out AIsSet: Boolean): Boolean;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
Result := False;
if not WSCheckHandleAllocated(ALV, 'ItemGetState')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if (AIndex < 0) or (AIndex >= CListWidget^.rows)
then begin
DebugLN('[TGtkWSCustomListView.ItemGetState] Invalid row index: %d', [Aindex]);
Exit;
end;
case AState of
lisCut,
lisDropTarget: begin
//TODO: do something with the rowcolor ?
end;
lisFocused: begin
AIsSet := CListWidget^.focus_row = AIndex;
Result := True;
end;
lisSelected: begin
AIsSet := (CListWidget^.selection <> nil)
and (g_list_find(CListWidget^.selection, Pointer(PtrInt(Aindex))) <> nil);
Result := True;
end;
end;
end;
class procedure TGtkWSCustomListView.ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
Titles: PPGChar;
idx, Count: Integer;
begin
if not WSCheckHandleAllocated(ALV, 'ItemInsert')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
Count := CListWidget^.columns;
if Count = 0
then begin
DebugLn('WARNING: TGtkWSCustomListView.ItemInsert CListWidget^.columns = 0');
Exit;
end;
GetMem(Titles, SizeOf(PGChar) * Count);
FillChar(Titles^, SizeOf(PGChar) * Count, 0);
Titles[0] := #0;
idx := AIndex;
if idx = -1
then idx := gtk_clist_append(CListWidget, Titles)
else gtk_clist_insert(CListWidget, idx, Titles);
FreeMem(Titles);
ItemChangeInternal(CListWidget, ALV, idx, AItem);
end;
class procedure TGtkWSCustomListView.ItemSetImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AImageIndex: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
ImageBitmap: TBitmap;
Pixmap: PGdkPixmap;
Mask: PGdkBitmap;
Spacing: guint8;
Text: PChar;
Dummy1, Dummy2: PGdkBitmap;
CellType: TGtkCellType;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetImage')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
Pixmap := nil;
Mask := nil;
if (TLVHack(ALV).SmallImages <> nil)
and (AImageIndex >= 0)
and (AImageIndex < TLVHack(ALV).SmallImages.Count)
then begin
// set image & caption
ImageBitmap := TBitmap.Create;
try
TLVHack(ALV).SmallImages.GetBitmap(AImageIndex, ImageBitmap);
case PGDIObject(ImageBitmap.Handle)^.GDIBitmapType of
gbBitmap:
begin
Pixmap := PGDIObject(ImageBitmap.Handle)^.GDIBitmapObject;
gdk_pixmap_ref(Pixmap);
Mask := nil;
end;
gbPixmap:
begin
Pixmap := PGDIObject(ImageBitmap.Handle)^.GDIPixmapObject.Image;
Mask := CreateGdkMaskBitmap(ImageBitmap.Handle, ImageBitmap.MaskHandle);
gdk_pixmap_ref(Pixmap);
end;
gbPixbuf:
begin
Pixmap := nil;
Mask := nil;
gdk_pixbuf_render_pixmap_and_mask(PGDIObject(ImageBitmap.Handle)^.GDIPixbufObject, pixmap, mask, $80);
end;
end;
finally
ImageBitmap.Free;
end;
end;
CellType := gtk_clist_get_cell_type(CListWidget, AIndex, ASubIndex);
// Sigh.
// gtk returns -1 for an invalid cell (which is not part of the enum)
// so to handle it, we need a case based on integer
case Ord(CellType) of
Ord(GTK_CELL_TEXT),
Ord(GTK_CELL_PIXTEXT),
Ord(GTK_CELL_EMPTY),
Ord(GTK_CELL_PIXMAP): begin
if pixmap <> nil
then begin
case CellType of
GTK_CELL_TEXT: begin
// convert the cell
Text := nil;
gtk_clist_get_text(CListWidget, AIndex, ASubIndex, @Text);
gtk_clist_set_pixtext(CListWidget, AIndex, ASubIndex, Text, DEFAULT_IMAGE_SPACING, Pixmap, Mask);
end;
GTK_CELL_PIXTEXT: begin
if gtk_clist_get_pixtext(CListWidget, AIndex, ASubIndex, @Text, @Spacing, @Dummy2, @Dummy1) <> 0
then gtk_clist_set_pixtext(CListWidget, AIndex, ASubIndex, Text, Spacing, Pixmap, Mask)
else gtk_clist_set_pixmap(CListWidget, AIndex, ASubIndex, Pixmap, Mask);
end;
GTK_CELL_EMPTY,
GTK_CELL_PIXMAP: begin
gtk_clist_set_pixtext(CListWidget, AIndex, ASubIndex, '', DEFAULT_IMAGE_SPACING, Pixmap, Mask);
end;
end;
end
else begin
case CellType of
GTK_CELL_EMPTY,
GTK_CELL_TEXT:; // nothing to do
GTK_CELL_PIXTEXT: begin
Text := nil;
if gtk_clist_get_pixtext(CListWidget, AIndex, ASubIndex, @Text, @Spacing, @Dummy2, @Dummy1) <> 0
then gtk_clist_set_text(CListWidget, AIndex, ASubIndex, Text)
else gtk_clist_set_text(CListWidget, AIndex, ASubIndex, '');
end;
GTK_CELL_PIXMAP: begin
gtk_clist_set_text(CListWidget, AIndex, ASubIndex, '');
end;
end;
end;
end;
Ord(GTK_CELL_WIDGET): DebugLN('[TGtkWSCustomListView.ItemSetImage] Setting text of widget cell');
-1: DebugLN('[TGtkWSCustomListView.ItemSetText] Cell (%d,%d) not created', [AIndex, ASubIndex]);
else
DebugLN('[TGtkWSCustomListView.ItemSetImage] Unknown celltype %d', [Ord(CellType)]);
end;
if Pixmap <> nil then
gdk_pixmap_unref(Pixmap);
if Mask <> nil then
gdk_bitmap_unref(Mask);
end;
class procedure TGtkWSCustomListView.ItemSetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; const AIsSet: Boolean);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetState')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if (AIndex < 0) or (AIndex >= CListWidget^.rows)
then begin
DebugLN('[TGtkWSCustomListView.ItemSetState] Invalid row index: %d', [Aindex]);
Exit;
end;
case AState of
lisCut,
lisDropTarget: begin
//TODO: do something with the rowcolor ?
end;
lisFocused: begin
if AIsSet = (CListWidget^.focus_row = AIndex) then Exit;
// reset old focus
if (CListWidget^.focus_row <> -1)
and (gtk_widget_has_focus(PGtkWidget(CListWidget)))
then gtk_widget_draw_focus(PGtkWidget(CListWidget));
if AIsSet
then begin
CListWidget^.focus_row := AIndex;
if gtk_widget_has_focus(PGtkWidget(CListWidget))
then gtk_widget_draw_focus(PGtkWidget(CListWidget));
end
else CListWidget^.focus_row := -1;
end;
lisSelected: begin
if AIsSet
then begin
if (CListWidget^.selection_mode = GTK_SELECTION_SINGLE)
or (CListWidget^.selection_mode = GTK_SELECTION_BROWSE)
then begin
// check if the row is are already selected
// since we are in singleselect, the first item is checked
if (CListWidget^.selection <> nil)
and (PtrInt(PtrUInt(CListWidget^.selection^.Data)) = AIndex)
then Exit;
gtk_clist_unselect_all(CListWidget);
end;
gtk_clist_select_row(CListWidget, AIndex, 0);
end
else gtk_clist_unselect_row(CListWidget, AIndex, 0);
end;
end;
end;
class procedure TGtkWSCustomListView.ItemSetText(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer; const AText: String);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
Pixmap: PGdkPixmap;
Mask: PGdkBitmap;
Spacing: guint8;
Dummy: pgchar;
CellType: TGtkCellType;
begin
if not WSCheckHandleAllocated(ALV, 'ItemSetText')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
CellType := gtk_clist_get_cell_type(CListWidget, AIndex, ASubIndex);
// Sigh.
// gtk returns -1 for an invalid cell (which is not part of the enum)
// so to handle it, we need a case based on integer
case Ord(CellType) of
Ord(GTK_CELL_EMPTY),
Ord(GTK_CELL_TEXT): begin
// simply set the text
gtk_clist_set_text(CListWidget, AIndex, ASubIndex, PChar(AText));
end;
Ord(GTK_CELL_PIXTEXT): begin
if gtk_clist_get_pixtext(CListWidget, AIndex, ASubIndex, @Dummy, @Spacing, @Pixmap, @Mask) <> 0
then gtk_clist_set_pixtext(CListWidget, AIndex, ASubIndex, PChar(AText), Spacing, Pixmap, Mask)
else gtk_clist_set_text(CListWidget, AIndex, ASubIndex, PChar(AText));
end;
Ord(GTK_CELL_PIXMAP): begin
if gtk_clist_get_pixmap(CListWidget, AIndex, ASubIndex, @Pixmap, @Mask) <> 0
then gtk_clist_set_pixtext(CListWidget, AIndex, ASubIndex, PChar(AText), DEFAULT_IMAGE_SPACING, Pixmap, Mask)
else gtk_clist_set_text(CListWidget, AIndex, ASubIndex, PChar(AText));
end;
Ord(GTK_CELL_WIDGET): DebugLN('[TGtkWSCustomListView.ItemSetText] Setting text of widget cell');
-1: DebugLN('[TGtkWSCustomListView.ItemSetText] Cell (%d,%d) not created', [AIndex, ASubIndex]);
else
DebugLN('[TGtkWSCustomListView.ItemSetText] Unknown celltype %d', [Ord(CellType)]);
end;
end;
class procedure TGtkWSCustomListView.ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
RowTopY: Integer;
begin
if not WSCheckHandleAllocated(ALV, 'ItemShow')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
RowTopY := (CListWidget^.row_height * AIndex) + ((AIndex +1) *
{CELL} 1 {SPACING} + CListWidget^.voffset);
// 0=NotVisible
// 1=PartiallyVisible
// 2=Fully Visible
// |
if gtk_clist_row_is_visible(CListWidget, AIndex) < (2 - Ord(PartialOK)) then begin
if (RowTopY + CListWidget^.row_height > CListWidget^.clist_window_height) then begin
gtk_clist_moveto (CListWidget, AIndex, -1, 1, 0);
// | | | |
// The Row | | |
// The Column | |
// Row Align |
end // Column Align
else if (RowTopY < 0) then begin
gtk_clist_moveto (CListWidget, AIndex, -1, 0, 0);
end;// |
end; // |
// |
// 0 = your row will be at the top.
// 1 = it will be at the bottom.
end;
////////////////////////////////////////////////////////////////////////////////
// LV code
////////////////////////////////////////////////////////////////////////////////
class function TGtkWSCustomListView.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND;
var
ListView: TLVHack; //TCustomListView
WidgetInfo: PWidgetInfo;
ScrollingData: PBaseScrollingWinControlData;
ListViewData: PCustomListViewData;
ScrollWidget: PGtkScrolledWindow;
CListWidget: PGtkCList;
begin
ListView := TLVHack(AWinControl as TCustomListView);
Result := TGtkWSBaseScrollingWinControl.CreateHandle(AWinControl, AParams);
if Result = 0 then Exit;
ScrollWidget := PGtkScrolledWindow(Result);
if ListView.ViewStyle = vsReport
then begin
// precreate colums since they cannot be added or removed
CListWidget := PGtkCList(gtk_clist_new(Max(1, ListView.Columns.Count)));
gtk_clist_column_titles_passive(CListWidget);
end
else begin
CListWidget := PGtkCList(gtk_clist_new(1));
gtk_clist_column_titles_hide(CListWidget);
gtk_clist_set_column_auto_resize(CListWidget, 0, True);
end;
gtk_clist_set_shadow_type(CListWidget, GTK_SHADOW_IN);
gtk_container_add(PGtkContainer(ScrollWidget), PGtkWidget(CListWidget));
gtk_widget_unset_flags(ScrollWidget^.hscrollbar, GTK_CAN_FOCUS);
gtk_widget_unset_flags(ScrollWidget^.vscrollbar, GTK_CAN_FOCUS);
gtk_scrolled_window_set_policy(ScrollWidget, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
// the next is not really needed since the container has only one child
gtk_container_set_focus_vadjustment(PGtkContainer(CListWidget), gtk_scrolled_window_get_vadjustment(ScrollWidget));
gtk_container_set_focus_hadjustment(PGtkContainer(CListWidget), gtk_scrolled_window_get_hadjustment(ScrollWidget));
gtk_widget_show_all(PGtkWidget(CListWidget));
// create widget info
// already created in TGtkWSBaseScrollingWinControl
// Replace the ScrollingInfo with our info
WidgetInfo := GetWidgetInfo(ScrollWidget);
WidgetInfo^.CoreWidget := PGtkWidget(CListWidget);
ScrollingData := WidgetInfo^.UserData;
New(ListViewData);
ListViewData^.ScrollingData := ScrollingData^;
ListViewData^.ViewStyle := ListView.ViewStyle;
Dispose(ScrollingData);
WidgetInfo^.UserData := ListViewData;
//todo: obsolete
// SetMainWidget(ScrollWidget, CListWidget);
// set allocation
// already created in TGtkWSBaseScrollingWinControl
Set_RC_Name(AWinControl, PGtkWidget(ScrollWidget));
SetListCallbacks(PGtkWidget(ScrollWidget), PGtkWidget(CListWidget), WidgetInfo);
end;
class procedure TGtkWSCustomListView.SetListCallbacks(const AScrollWidget, AListWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
begin
TGtkWSBaseScrollingWinControl.SetCallbacks(AScrollWidget, AWidgetInfo);
SignalConnect(AListWidget, 'click-column', @GtkWSCustomListView_ClickColumn, AWidgetInfo);
SignalConnect(AListWidget, 'resize-column', @GtkWSCustomListView_ResizeColumn, AWidgetInfo);
SignalConnect(AListWidget, 'abort-column-resize', @GtkWSCustomListView_AbortColumnResize, AWidgetInfo);
// SignalConnect(AListWidget, 'row-move', @GtkWSCustomListView_RowMove, AWidgetInfo);
SignalConnect(AListWidget, 'select-row', @GtkWSCustomListView_SelectRow, AWidgetInfo);
SignalConnect(AListWidget, 'unselect-row', @GtkWSCustomListView_UnSelectRow, AWidgetInfo);
SignalConnect(AListWidget, 'toggle-focus-row', @GtkWSCustomListView_ToggleFocusRow, AWidgetInfo);
SignalConnect(AListWidget, 'select-all', @GtkWSCustomListView_SelectAll, AWidgetInfo);
SignalConnect(AListWidget, 'unselect-all', @GtkWSCustomListView_UnSelectAll, AWidgetInfo);
SignalConnect(AListWidget, 'end-selection', @GtkWSCustomListView_EndSelection, AWidgetInfo);
end;
class procedure TGtkWSCustomListView.BeginUpdate(const ALV: TCustomListView);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'BeginUpdate')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_freeze(CListWidget);
end;
class procedure TGtkWSCustomListView.EndUpdate(const ALV: TCustomListView);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'EndUpdate')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
gtk_clist_thaw(CListWidget);
end;
class function TGtkWSCustomListView.GetBoundingRect(const ALV: TCustomListView): TRect;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
Result:=Rect(0,0,0,0);
if not WSCheckHandleAllocated(ALV, 'GetBoundingRect')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
if TLVHack(ALV).ViewStyle in [vsIcon, vsSmallIcon]
then begin
// TODO: implement
end
else begin
Result := Rect(0,0,0,0);
end;
end;
class function TGtkWSCustomListView.GetDropTarget(const ALV: TCustomListView): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
Result:=0;
if not WSCheckHandleAllocated(ALV, 'GetDropTarget')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
// TODO: implement
Result := -1;
end;
class function TGtkWSCustomListView.GetFocused(const ALV: TCustomListView): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'GetFocused')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
Result := CListWidget^.focus_row;
end;
class function TGtkWSCustomListView.GetHoverTime(const ALV: TCustomListView): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
Result := -1; // = default
if not WSCheckHandleAllocated(ALV, 'GetHoverTime')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
// TODO: implement
Result := -1; // = default
end;
class function TGtkWSCustomListView.GetItemAt(const ALV: TCustomListView; x,
y: integer): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
I, FirstRowY, LastRowY: Integer;
ScrolledTop: Integer;
RowHeight: Integer;
begin
if not WSCheckHandleAllocated(ALV, 'GetItemAt')
then Exit(-1);
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
ScrolledTop := Trunc(CListWidget^.vadjustment^.value);
FirstRowY := ScrolledTop;
// For some reason the actual row height is one pixel more than the size it says
RowHeight := CListWidget^.row_height+1;
Dec(y, CListWidget^.column_title_area.height);
LastRowY := FirstRowY + CListWidget^.clist_window_height;
Inc(y, ScrolledTop);
for I := FirstRowY div RowHeight to LastRowY div RowHeight do
begin
if I > CListWidget^.rows-1 then
Exit;
if (I * RowHeight < y) and ((I+1) * RowHeight >= y-1) then
Exit(I);
end;
end;
class function TGtkWSCustomListView.GetSelCount(const ALV: TCustomListView): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'GetSelCount')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget^.selection = nil
then Result := 0
else Result := g_list_length(CListWidget^.selection);
end;
class function TGtkWSCustomListView.GetSelection(const ALV: TCustomListView): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'GetSelection')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget^.selection = nil
then Result := -1
else Result := PtrUInt(CListWidget^.selection^.data)
end;
class function TGtkWSCustomListView.GetTopItem(const ALV: TCustomListView): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'GetTopItem')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
// Result := ROW_FROM_YPIXEL(0)
// #define ROW_FROM_YPIXEL(clist, y) (((y) - (clist)->voffset) / \
// ((clist)->row_height + CELL_SPACING))
Result := -CListWidget^.voffset div (CListWidget^.row_height + 1);
end;
class function TGtkWSCustomListView.GetViewOrigin(const ALV: TCustomListView): TPoint;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'GetViewOrigin')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
Result.X := Round(CListWidget^.hAdjustment^.value);
Result.Y := Round(CListWidget^.vAdjustment^.value);
end;
class function TGtkWSCustomListView.GetVisibleRowCount(const ALV: TCustomListView): Integer;
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'GetVisibleRowCount')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
Result := CListWidget^.clist_window_height div (CListWidget^.row_height + 1);
end;
class procedure TGtkWSCustomListView.SetAllocBy(const ALV: TCustomListView;
const AValue: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'SetAllocBy')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
// TODO: implement ?
end;
class procedure TGtkWSCustomListView.SetDefaultItemHeight(const ALV: TCustomListView;
const AValue: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
const
GTK_CLIST_ROW_HEIGHT_SET = 1 shl 1;
begin
if not WSCheckHandleAllocated(ALV, 'SetDefaultItemHeight')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if (AValue = 0) and (CListWidget^.flags and GTK_CLIST_ROW_HEIGHT_SET = 0) then
exit;
gtk_clist_set_row_height(CListWidget, AValue);
end;
class procedure TGtkWSCustomListView.SetHotTrackStyles(const ALV: TCustomListView;
const AValue: TListHotTrackStyles);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'SetHotTrackStyles')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
// TODO: implement ?
end;
class procedure TGtkWSCustomListView.SetHoverTime(const ALV: TCustomListView;
const AValue: Integer);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'SetHoverTime')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
// TODO: implement ?
end;
class procedure TGtkWSCustomListView.SetImageList(const ALV: TCustomListView;
const AList: TListViewImageList; const AValue: TCustomImageListResolution);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'SetImageList')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
// TODO: implement
end;
class procedure TGtkWSCustomListView.SetPropertyInternal(
const ACListWidget: PGtkCList; const AInfo: PWidgetInfo;
const AProp: TListViewProperty; const AIsSet: Boolean);
var
ListViewData: PCustomListViewData;
begin
case AProp of
lvpAutoArrange: begin
// TODO: implement ??
end;
lvpCheckboxes: begin
// TODO: implement
end;
lvpColumnClick: begin
// allow only column modifications when in report mode
ListViewData := AInfo^.UserData;
if ListViewData^.ViewStyle <> vsReport then Exit;
if AIsSet
then gtk_clist_column_titles_active(ACListWidget)
else gtk_clist_column_titles_passive(ACListWidget);
end;
lvpFlatScrollBars: begin
// TODO: implement ??
end;
lvpFullDrag: begin
// TODO: implement ??
end;
lvpGridLines: begin
// TODO: implement
// maybe possible with some cellwidget hacking
end;
lvpHideSelection: begin
// TODO: implement
// should be possible with some focus in/out events
end;
lvpHotTrack: begin
// TODO: implement
// should be possible with some mouse tracking
end;
lvpMultiSelect: begin
if AIsSet
then gtk_clist_set_selection_mode(ACListWidget, GTK_SELECTION_EXTENDED)
else gtk_clist_set_selection_mode(ACListWidget, GTK_SELECTION_BROWSE);
end;
lvpOwnerDraw: begin
// TODO: implement
// use custom images/widgets ?
end;
lvpReadOnly: begin
// TODO: implement inline editor ?
end;
lvpRowSelect: begin
// TODO: implement ???
// how to do cell select
end;
lvpShowColumnHeaders: begin
// allow only column modifications when in report mode
ListViewData := AInfo^.UserData;
if ListViewData^.ViewStyle <> vsReport then Exit;
if AIsSet
then gtk_clist_column_titles_show(ACListWidget)
else gtk_clist_column_titles_hide(ACListWidget);
end;
lvpShowWorkAreas: begin
// TODO: implement ???
end;
lvpWrapText: begin
// TODO: implement ???
end;
end;
end;
class procedure TGtkWSCustomListView.SetProperty(const ALV: TCustomListView;
const AProp: TListViewProperty; const AIsSet: Boolean);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'SetProperty')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
SetPropertyInternal(CListWidget, WidgetInfo, AProp, AIsSet);
end;
class procedure TGtkWSCustomListView.SetProperties(const ALV: TCustomListView; const AProps: TListViewProperties);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
Prop: TListViewProperty;
begin
if not WSCheckHandleAllocated(ALV, 'SetProperties')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
for Prop := Low(TListViewProperty) to High(TListViewProperty) do
SetPropertyInternal(CListWidget, WidgetInfo, Prop, Prop in AProps);
end;
class procedure TGtkWSCustomListView.SetScrollBars(const ALV: TCustomListView; const AValue: TScrollStyle);
var
ScrollWidget: PGtkScrolledWindow;
hPolicy, vPolicy: TGtkPolicyType;
begin
if not WSCheckHandleAllocated(ALV, 'SetScrollBars')
then Exit;
ScrollWidget := PGtkScrolledWindow(ALV.Handle);
case AValue of
ssHorizontal, ssBoth: hPolicy := GTK_POLICY_ALWAYS;
ssAutoHorizontal, ssAutoBoth: hPolicy := GTK_POLICY_AUTOMATIC;
else
hPolicy := GTK_POLICY_NEVER;
end;
case AValue of
ssVertical, ssBoth: vPolicy := GTK_POLICY_ALWAYS;
ssAutoVertical, ssAutoBoth: vPolicy := GTK_POLICY_AUTOMATIC;
else
vPolicy := GTK_POLICY_NEVER;
end;
gtk_scrolled_window_set_policy(ScrollWidget, hPolicy, vPolicy);
end;
class procedure TGtkWSCustomListView.SetSort(const ALV: TCustomListView;
const AType: TSortType; const AColumn: Integer;
const ASortDirection: TSortDirection);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'SetSort')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
// TODO implement
end;
class procedure TGtkWSCustomListView.SetViewOrigin(const ALV: TCustomListView; const AValue: TPoint);
var
WidgetInfo: PWidgetInfo;
CListWidget: PGtkCList;
begin
if not WSCheckHandleAllocated(ALV, 'SetViewOrigin')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
CListWidget := PGtkCList(WidgetInfo^.CoreWidget);
if CListWidget=nil then exit;
gtk_adjustment_set_value(CListWidget^.hAdjustment, AValue.X);
gtk_adjustment_set_value(CListWidget^.vAdjustment, AValue.Y);
end;
class procedure TGtkWSCustomListView.SetViewStyle(const ALV: TCustomListView; const Avalue: TViewStyle);
var
WidgetInfo: PWidgetInfo;
ListViewData: PCustomListViewData;
begin
if not WSCheckHandleAllocated(ALV, 'SetViewStyle')
then Exit;
WidgetInfo := GetWidgetInfo(Pointer(ALV.Handle));
ListViewData := WidgetInfo^.UserData;
if ListViewData^.ViewStyle = AValue then Exit; // nothing to do
// We cannot change columns or viewstyle so we need to recreate
RecreateWnd(ALV);
end;
|