1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
| unit KGF_TAB_Component;
{
This unit includes a Panoramic wrapper for the KGFTab component.
It's presence is selectable by conditional compilation, using the PanoramicWrapper symbol.
The Panoramic wrapper is just an add-on built on top of the KGFTab control. The control
itself is fully operational without the wrapper. The wrapper exports the following functions:
CreateKGFTab, ConfigureKGFTab, DeleteKGFTab and GetKGFTabHandles
A special unit implementing buttons with color attribute is added by the conditional compiler ColorButton symbol.
From this unit, the TBitBtnWithColor object is used thus allowing to manage the colors of the buttons.
Just remove the symbol to eliminate the dependancy and fall back to standard TBitBtn.
KGFTab is a visual composed control implementing a tabbed interface.
Basically, the clickable tabs are implemented by standard TBitBtn buttons.
The associated pages are standard TPanel controls.
Called directly from Delphi, any Delphi control can be directly placed into these pages.
Via the Panoramic wrapper, this is not possible. TWincontrol descendants can be placed
using their ParentWindow handle with the handle of the desired TKGFTab page (TPanel object).
Controls without a handle (like TImage aso) must be placed on a TPanel of same size, and this
TPanel can than be placed into a TKGFTab page in standard way. A TLabel control is better
replaced by a well dimensioned TPanel which can be inserted freely. By the way, the same
restrictions apply if the TKGFTab control is placed into a DLL. When placed into a packet or
compiled directly with the source program there is no problem.
A special method of a TKGFTab object is Configure. This method can process a script accessing
virtually all methods and functionalities of the TKGFTab object, thus acheiving 2 mail goals:
1. ability to configure the control at runtime without programming
2. effectively reducing the number of dedicated functions to manage the control
The second point is particlarly interresting for use by a third party language where a whole set of
dedicated fonctions and procédures would be required. The process is comparable to an SQL script
in database managment.
A method allows to specify a handle (typically the mainform handle) where the component will send
via SEND_MESSAGE a USER_EVENT identifying an occurd action (actually "selection of a tab")
and the number of the concerned tab.
The WParam word contains $xxyynnnn where xx=18 (KGFTab) and yy=01 (selection of a tab=) and nnnn=numéro de la page TAB
The LParam word contains l'objet KGFTab (résultar de la fonction CreateKGFTag)
Actually, the following scripting commands are available (insensibles à la casse):
(les signes <...> indiquent la plade d'une valeur numérique ou textuelle, selon les circonstances)
Les paramères sont séparées par des virgules et la commande est terminée par un sémicolon.
Tout ce qui suit un ";" est ignoré et considéré comme commentaire.
parent,<handle>; handle de l'objet dans lequel le TKGFTab doit apparaître
left,<position>; position gauche en pixels du TKGFTab
top,<position>; position haute en pixels du TKGFTab
width,<dimension>; largeur en pixels du TKGFTab
height,<dimension>; hauteur en pixels du TKGFTab
label,<ind>,<libellé>; index et libelle d'un bouton existant
addtab,<libellé>; libellé du nouveau bouton
inserttab,<ind>,<libellé>; index d'un bouton existant pour l'insertion et le nouveau libellé
deletetab,<Ind>; index du bouton et de la feuille à supprimer
glyph,<ind>,<fichier>; index (0...3) de la partie du glupf à charger par l'image dans le fichier
buttonglyph,<ind>; index du bouton dans lequel installer le glyph assemblé avec 4 images
tabpagehandles; (retourne la liste des handles des pages)
buttonheight,<dimension>; hauteur des boutons
buttonwidth,<dimension>; largeur des boutons
buttonposition,<choix>; choix de la position des boutons (0...3)
tabcolor,<ind>,<couleur>; index d'une page et sa culeur de fond (RGB en hexa précédé par un "$")
tabactivate,<ind>,<état>; index d'une page et etat d'activation (1=inactive <>0 = active)
multirow,<choix>; gérer les boutons sur lignes/clonnes multiples 0=désactivé 1=activé
glyphsize,<dimension>; définir la taille des icônes (défaut: 16 pixels)
userevent,<handle>; définir le handle de destination pour l'envoi d'u USER_EVENT
insertcontrol,<ind>,<handle>; insérer dans la page ind le contrôle dont le handle est indiqué
buttoncolor,<ind>,<couleur> index d'un bouton et sa couleur de fond
De façon interne, un TKGFTab contient 4 petites images invisibles servant à construire un glyph.
Il faut charger les 4 images par des fichiers BMP toutes de la même dimension ( 16 x 16 par exemple), commande "glyph"
Lorsque les 4 images sont chargées, on peut charger le glyph par la commande "buttonglyph"
Les positions possibles des boutons sont 0=Top 1=Left 2=Bottom 3=Right
Les couleurs sont par exemple: $FF pour Rouge, $FF0000 pour Bleu, etc
}
{$define PanoramicWrapper}
{$define ColorButton}
interface
uses
Windows, forms, SysUtils, Controls, Classes, ExtCtrls, StdCtrls, Buttons,
Contnrs, Graphics, StrUtils, Messages , Dialogs
{$ifdef ColorButton}
, KGF_unit_ButtonWithColor // Copyright (c) 1999, UtilMind Solutions
{$endif}
{$ifdef PanoramicWrapper}
, KGF_unit_data
{$endif}
;
const
CM_PANORAMIC_USER = WM_USER + 3000; // commande pour SendMessage pour déclencher le ON_USER_EVENT de Panoramic
UserEventKGFTab = $18000000; // identifiant dans WParam
UserEventTabSelect = $00010000; // clic dans un bouton d'un TAB ou sélection par programme
{$ifdef PanoramicWrapper}
{$else}
var
PCompiledMode: boolean;
{$endif}
const StringParameterMethod = 2;
type
TButtonPosition = (bpTop, bpLeft, bpBottom, bpRight); // position des boutons par rapport aux pages
{
Cette classe permet de regrouper des boutons pour le traitement du survol.
Elle sera enregistrée dans KGFTab et est valable pour tous les boutons de ce KGFTab.
TMyBitBTN n'est pas conçu pour être utilisé en-dehors d'un composant TKGFTab,
sauf à créer explicitement un TPseudoContainer pour chaque ensemble cohérent de boutons
afin de gérer correctementn les transitions de survol.
}
type
TPseudoContainer = class
private
fHoverButton: integer;
published
property HoverButton: integer read fHoverButton write fHoverButton;
end;
{
TMyBitBtn est exactement TBitBtn, avec une méthode pour construire le glyph et une propriété de couleur pour le bouton.
}
{$ifdef ColorButton}
type TMyBitBtn = class(TBitBtnWithColor)
{$else}
type TMyBitBtn = class(TBitBtn)
{$endif}
private
fKGFTab: integer;
fOldColor: TColor;
fHoovering: boolean;
published
property KGFTab: integer read fKGFTab write fKGFTab;
property OldColor: TColor read fOldColor write fOldColor;
property Hoovering: boolean read fHoovering write fHoovering;
function SetGlyph(gs: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean;
constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
procedure MyBtnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
end;
{
Définition du contrôle TKGFTab
}
type
TKGFTab = class(TPanel)
private
fKGFTabHandle: HWND; // handle de cet objet
fTabIndex: integer; // index de l'onglet sélectionné
fTabLabels: TStringList; // liste des libellés des boutons (sera sprrimé plus tard)
fButtons: TObjectList; // liste des boutons, dans l'ordre
fSheets: TObjectList; // liste des pages (dans l'ordre)
fButtonPosition: TButtonPosition; // position des boutons (haut, gauche, bas, droite)
fButtonHeight: integer; // hauteur de tous les boutons
fButtonWidth: integer; // largeur de tous les boutons
fMultiRowButtons: boolean; // flag "permettre l'organisation des boutons en lignes multiples"
fGlyphSize: integer; // hauteur et largeur d'une icône des glyphs
fUserEventHandle: HWND; // handle pour l'envoi d'un USER_EVENT
fPseudoContainer: TPseudoContainer; // serrt à regrouper les boutons pour le survom
procedure SetTabIndex(aIndex: integer); // méthode: sélection et affichage d'un onglet avec sa page
procedure OnClick(Sender: TObject); // évènement: clic sur les boutons représentant les onglets
procedure SetButtonPosition(aPosition: TButtonPosition); // méthode: changer le positionnement des boutons
procedure SetButtonHeight(aHeight: integer); // méthode: changer la hauteur des boutons
procedure SetButtonWidth(aWidth: integer); // méthode: changer la largeur des boutons
procedure SetMultiRowButtons(aMode: boolean); // méthode gérer le mode de boutons en lignes multiples
published
property KGFTabHandle: HWND read fKGFTabHandle write fKGFTabHandle;
property TabIndex: integer read fTabIndex write SetTabIndex;
property ButtonPosition: TButtonPosition read fButtonPosition write SetButtonPosition;
property ButtonHeight: integer read fButtonHeight write SetButtonHeight;
property ButtonWidth: integer read fButtonWidth write SetButtonWidth;
property MultiRowButtons: boolean read fMultiRowButtons write SetMultiRowButtons;
property GlyphSize: integer read fGlyphSize write fGlyphSize;
property UserEventHandle: HWND read fUserEventHandle write fUserEventHandle;
property PseudoContainer: TPseudoContainer read fPseudoContainer write fPseudoContainer;
procedure SetTabLabel(aIndex: integer; aLabel: string); // méthode: changer un libellé d'un onglet (bouton)
procedure AddTab(aLabel: string); // méthode; ajouter un onglet (bouton et page)
procedure InsertTab(aIndex: integer; aLabel: string); // méthode; insérer un onglet (bouton et page)
procedure DeleteTab(aIndex: integer); // méthode; supprimer un onglet (bouton et page)
procedure Refresh; // méthode: réafficher le cotrôle (après reconfiguration)
function SetButtonGlyph(aIndex: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean; // méthode: construire le glyphe d'un bouton
function Configure(n: integer; aScript: TStrings): integer; // méthode: exécution d'un script pour configurer le contrôle
function GetTabPageHandles: string; // méthode: retourner la liste des handles des pages (provisoire)
constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
end;
{$ifdef PanoramicWrapper} // doit être défini UNIQUEMENT si ce module est utilisé dans KGF.dmm avec un programmePanoramic !
var
TempForm: TForm;
function CreateKGFTab(hDest: HWND): integer; stdcall;
function ConfigureKGFTab(KT: TKGFTab; aScript: integer): integer; stdcall;
{$endif}
implementation
procedure TMyBitBtn.MyBtnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if TMyBitBtn(Sender).Hoovering then exit;
if not assigned(TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer) then exit;
TMyBitBtn(Sender).Hoovering := true;
if TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton<>0 then
if TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton<>integer(Sender) then
TMyBitBtn(TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton).Font.Style := [];
TKGFTab(TMyBitBtn(Sender).KGFTab).fPseudoContainer.HoverButton := integer(Sender);
TMyBitBtn(Sender).Font.Style := [fsBold, fsItalic];
TMyBitBtn(Sender).Hoovering := false;
end;
{
Les 3 procédures suivantes sont utilisées dans le cadre du wrapper Panoramic.
Mais elles peuvent servir partiellement dans un environnement généraL;
C'est pourquoi les parties spécifiques à Panoramic ont été entourées de compilation conditionnelle.
procédures et fonctions:
Délay attente de quelques milli-secondes, nécessaire dans certains cas
CopyStringToPanoramic procédure envoyant un string à une destination généralisée
GetStringFromPanoramic fonction récupérant un string à partir d'une origine généralisée
Une origine ou destination "généralisée" est une valeur entière pouvant être, indifféremment:
- adresse une variable string
adr(text$) en Panoramic
une valeur PString en Delphi
- le handle d'un objet TMemo
- le handle d'un objet TListBox
}
procedure Delay(AMSecs: Cardinal);
var
iStop : cardinal;
begin
iStop := GetTickCount + AMsecs;
while GetTickCount < iStop do
begin
Forms.Application.ProcessMessages; // <=================== où est "Application" ?
sleep(1);
end
end;
// procédure compatible avec la version compilée de PANORAMIC
// s = string (éventuellement multi-ligne) à envoyer à Panoramic
// par = identifiant de destination soit ADR(s$) soit HANDLE(memo%)
procedure CopyStringToPanoramic(s: string; par: integer);
var
p1, p2: pchar;
n, p: integer;
memo: TMemo;
s1, s2: string;
control: TWinControl;
pi, po: pbyte;
zero: byte;
function GetClassName(Handle: THandle): String;
var
Buffer: array[0..MAX_PATH] of Char;
begin
Windows.GetClassName(Handle, @Buffer, MAX_PATH);
Result := String(Buffer);
end;
begin
if par=0 then exit;
try
memo := TMemo(par);
if memo.ClassName='TMemo' then begin
s1 := s;
memo.Text := trim(s1+' ');
exit;
end;
except
end;
try
if GetClassName(par)='TMemo' then begin
s1 := s;
SendMessage(par,WM_SETTEXT,0,integer(pchar(s1)));
exit;
end;
except
end;
try
if GetClassName(par)='TListBox' then begin
SendMessage(par,LB_RESETCONTENT,0,0);
s1 := s + #13#10;
while s1<>'' do begin
p := pos(#13#10,s1);
if p>0 then begin
s2 := LeftStr(s1,p-1);
s1 := MidStr(s1,p+2,Length(s1));
SendMessage(par,LB_ADDSTRING,0,integer(pchar(s2)));
end;
end;
if s1<>'' then SendMessage(par,LB_ADDSTRING,0,integer(pchar(s1)));
exit;
end;
except
end;
zero := 0;
p1 := @zero;
n := length(s);
if n>0 then p1 := @s[1];
{$ifdef PanoramicWrapper}
if PCompiledMode then begin
// mode compilé
pi := pbyte(@s[1]);
{$if StringParameterMethod=1}
po := pbyte(par); // méthode V1 (Jack): ADR(s$) pointe vers l'adresse du premier caractère
{$else}
po := pbyte(pinteger(par)^); // méthode V2 (Jack): ADR(s$) pointe vers un mot contenant l'adresse du premier caractère
{$ifend}
while po^<>0 do begin
if pi^<>0 then begin
po^ := pi^;
inc(po);
inc(pi);
end else begin
po^ := 32;
inc(po);
end;
end;
end else begin
{$endif}
//mode interprété
if n>0 then p1 := pchar(@s[1]);
p2 := pchar(pinteger(par)^);
while p2^<>#0 do begin
if n>0 then begin
if p1<>#0 then p2^ := p1^
else dec(p2);
end else begin
p2^ := #32;
end;
inc(p1);
inc(p2);
dec(n);
end;
{$ifdef PanoramicWrapper}
end;
{$endif}
end;
// fonction compatible avec la version compilée de PANORAMIC
// par = identifiant de destination soit ADR(s$) soit HANDLE(memo%)
function GetStringFromPanoramic(par: integer): string;
var
n, Len, cnt, i: integer;
memo: TMemo;
lb: TListBox;
s1, s2: string;
pb: pbyte;
pi: pinteger;
function GetClassName(Handle: THandle): String;
var
Buffer: array[0..MAX_PATH] of Char;
begin
Windows.GetClassName(Handle, @Buffer, MAX_PATH);
Result := String(Buffer);
end;
begin
result := '';
if par=0 then exit;
try
memo := TMemo(par);
if memo.ClassName='TMemo' then begin
result := memo.Text;
exit;
end;
except
end;
try
if GetClassName(par)='TMemo' then begin
Len := SendMessage(par, WM_GETTEXTLENGTH, 0, 0);
if Len>0 then begin
SetLength(s1, Len+1);
Len := SendMessage(par, WM_GETTEXT, Len+1, LPARAM(PChar(s1)));
delay(100);
SetLength(s1, Len);
end;
result := Trim(s1);
exit;
end;
except
end;
try
if GetClassName(par)='TListBox' then begin
cnt := SendMessage(par, LB_GETCOUNT, 0, 0);
s1 := '';
if cnt<>LB_ERR then begin
for i:=0 to cnt-1 do begin
s2 := '';
Len := SendMessage(par, LB_GETTEXTLEN, i, 0);
if Len>0 then begin
SetLength(s2, Len+1);
SendMessage(par, LB_GETTEXT, i, LPARAM(PChar(s2)));
delay(100);
s1 := s1 + Trim(s2) + #13#10;
end else begin
s1 := s1 + #13#10;
end;
end;
end;
result := Trim(s1);
exit;
end;
except
end;
{$ifdef PanoramicWrapper}
if PCompiledMode then begin
cnt := 0;
{$if StringParameterMethod=1}
pb := pbyte(par); // méthode V1 (Jack): ADR(s$) pointe vers l'adresse du premier caractère
{$else}
if pinteger(par)^<>0 then begin
pb := pbyte(pinteger(par)^); // méthode V2 (Jack): ADR(s$) pointe vers un mot contenant l'adresse du premier caractère
{$ifend}
while pb^<>0 do begin
inc(pb);
inc(cnt);
end;
end;
SetLength(result,cnt);
if cnt>0 then begin
pb := pbyte(pinteger(par)^);
for i:=1 to cnt do begin
result[i] := chr(pb^);
inc(pb);
end;
end;
end else begin
result := pstring(par)^;
end;
{$else}
result := pstring(par)^;
{$endif}
end;
{
fin des 3 procédures spécifiques à l'environnement Panoramic
}
function TMyBitBtn.SetGlyph(gs: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean;
// dimensions Delphi d'un TBitBtn par défaut: 25 x 75 pixels, tous ajustavles.
// les icônes sont placées dans un Glyph avec 4 images carrées distinctes de dimensions identiques.
// la longueur d'un côté est éterminé par la hauteur de la première bitmap.
// le glyphe a donc les dimensions (hauteur) sur (4 x hauteur).
var
n, ng: integer;
bmp, bmp1: TBitmap;
rct: TRect;
begin
result := false;
if not assigned(aImage1) then exit; // au moins la première bitmap doit exieter !
if aImage1.ClassName<>'TImage' then exit;
n := aImage1.Height; // prendre la hauteur
if n<>aImage1.Width then exit; // l'mage doit être carrée
ng := 1; // ici, on a la première image
if assigned(aImage2) then begin // les autres images doivent avoir les mêmes dimensions
if aImage2.ClassName<>'TImage' then exit;
if (aImage2.Height=n) and (aImage2.Width=n) then begin
ng := 2;
if assigned(aImage3) then begin
if aImage3.ClassName<>'TImage' then exit;
if (aImage3.Height=n) and (aImage3.Width=n) then begin
ng := 3;
if assigned(aImage4) then begin
if aImage4.ClassName<>'TImage' then exit;
if (aImage4.Height=n) and (aImage4.Width=n) then ng := 4;
end;
end;
end;
end;
end;
// copier les images dans le glyph
bmp1 := TBitmap.Create;
bmp1.Width := gs * ng;
bmp1.Height := gs;
bmp1.PixelFormat := pf24bit ;
if n>=1 then begin
bmp := TBitmap.Create; // bitmap temporaire
bmp.PixelFormat := pf24bit ;
Bmp.Assign(aImage1.Picture.Graphic);
rct := Rect(0,0,gs-1,gs-1); // rectangle cible pour l'image 1
bmp1.Canvas.StretchDraw(rct,bmp);
bmp.Free;
end;
if n>=2 then begin
bmp := TBitmap.Create; // bitmap temporaire
bmp.PixelFormat := pf24bit ;
Bmp.Assign(aImage2.Picture.Graphic);
rct := Rect(gs,0,2*gs-1,gs-1); // rectangle cible pour l'image 2
bmp1.Canvas.StretchDraw(rct,bmp);
bmp.Free;
end;
if n>=3 then begin
bmp := TBitmap.Create; // bitmap temporaire
bmp.PixelFormat := pf24bit ;
Bmp.Assign(aImage3.Picture.Graphic);
rct := Rect(2*gs,0,3*gs-1,gs-1); // rectangle cible pour l'image 3
bmp1.Canvas.StretchDraw(rct,bmp);
bmp.Free;
end;
if n>=4 then begin
bmp := TBitmap.Create; // bitmap temporaire
bmp.PixelFormat := pf24bit ;
Bmp.Assign(aImage4.Picture.Graphic);
rct := Rect(3*gs,0,4*gs-1,gs-1); // rectangle cible pour l'image 4
bmp1.Canvas.StretchDraw(rct,bmp);
bmp.Free;
end;
Glyph.Assign(bmp1);
NumGlyphs := ng;
bmp1.Free;
result := true;
end;
{
icônes dans le bitmap d'un glyph (toutes de la même taille):
Premier - Haut - Cette image apparaît quand le bouton n'est pas sélectionné (l'état normal d'un bouton). Cette image est aussi utilisée lorsque le bouton détient la focalisation (par exemple, si vous le sélectionnez au moyen de la touche tab). Dans ce cas, un rectangle de focalisation est dessiné autour du bouton. S'il n'y a pas d'autres images dans le bitmap, les boutons bitmaps utilisent aussi cette image pour tous les autres états.
Second - Désactivé - Cette image apparaît, en général, estompée, pour indiquer que le bouton ne peut être sélectionné.
Troisième - Cliqué - Cette image apparaît quand le bouton est cliqué. L'image de l'état haut réapparaît quand l'utilisateur relâche le bouton de la souris.
Quatrième - Bas - Cette image apparaît quand le bouton reste enfoncé, indiquant qu'il reste sélectionné.
}
constructor TMyBitBtn.Create(AOwner: TComponent);
begin
inherited Create(aOwner);
fKGFTab := integer(aOwner);
self.Layout := blGlyphLeft; // le glyph est forcé sur le côté gauche du bouton.
OldColor := Color; // mémoriser la couleur d'origine
fHoovering := false;
OnMouseMove := MyBtnMouseMove;
end;
Destructor TMyBitBtn.Destroy;
begin
OnMouseMove := nil;
inherited;
end;
// création de l'objet TKGFTab
constructor TKGFTab.Create(AOwner: TComponent);
var
btn: TMyBitBtn;
sht: TPanel;
begin
inherited Create(nil); // créer l'objet selon le modèle TPanel
if assigned(AOwner) then self.ParentWindow := TWinControl(aOwner).Handle; // et le faire apparaître dans l'objet cible
fKGFTabHandle := self.Handle;
{$ifdef PanoramicWrapper}
{$else}
PCompiledMode := false;
{$endif}
// installer les valeurs par défaut
fButtonPosition := bpTop; // boutons en haut
fButtonHeight := 25; // dimensions s'un TBitBtn par défaut
fButtonWidth := 75;
fGlyphSize := 16; // dimensions par défaut des icônes des glyphs
fTabLabels := TStringList.Create;
fTabLabels.Add('Default'); // ajouter un onglet par défaut avec son bouton
fButtons := TObjectList.Create;
fButtons.OwnsObjects := true; // les listes des boutons et pages "possèdent" leurs objets
fSheets := TObjectList.Create;
fSheets.OwnsObjects := true;
fPseudoContainer := TPseudoContainer.Create;
fPseudoContainer.HoverButton := 0; // actuellement, pas de bouton en survol
Width := 300; // dimensions par défaut de l'objet TKGFTab
Height := 200;
// creation du bouton de la page par défaut
btn := TMyBitBtn.Create(self);
btn.Height := fButtonHeight;
btn.Width := fButtonWidth;
btn.Caption := fTabLabels.Strings[0];
if self.Handle<>0 then btn.ParentWindow := self.Handle; // placer le nouveau bouton dans l'objet TKGFTab
btn.OnClick := OnClick;
btn.Tag := 0; // mémoriser l'indice de la page dans le bouton
fButtons.Add(btn);
// création de la page par défaut
sht := TPanel.Create(self);
sht.ParentWindow := self.Handle; // placer la nouvelle page dans l'objet TKGFTab
case ButtonPosition of
bpTop: begin
sht.Top := btn.Height;
sht.Left := 0;
sht.Width := Width;
sht.Height := Height - btn.Height;
end;
bpLeft: begin
sht.Top := 0;
sht.Left := btn.Width;
sht.Width := Width - sht.Left;
sht.Height := Height;
end;
bpBottom: begin
sht.Top := 0;
sht.Left := 0;
sht.Width := Width;
sht.Height := Height - btn.Height;
end;
bpRight: begin
sht.Top := 0;
sht.Left := 0;
sht.Width := Width - btn.Width;
sht.Height := Height;
end;
end;
fSheets.Add(sht);
fTabIndex := 0; // sélectionner l'unique page
end;
destructor TKGFTab.Destroy;
begin
fTabLabels.Clear;
fTabLabels.Free;
fTabLabels := nil;
fButtons.Free;
fButtons := nil;
fSheets.Free;
fSheets := nil;
fPseudoContainer.Free;
inherited;
end;
// évènement appelé lors d'un click sur un des boutons de page pour faire apparaître cette page
procedure TKGFTab.OnClick(Sender: TObject);
var
n, res, WP, LP: integer;
begin
n := TMyBitBtn(Sender).Tag; // ici, on sait quelle page est associée
if n<>fTabIndex then begin // uniquement si la page actuelle n'est pas celle quiest ciblée
TPanel(fSheets.Items[fTabIndex]).Visible := false; // cacher la page actuellement visible
TPanel(fSheets.Items[n]).Visible := true; // montrer la page ciblée
TMyBitBtn(fButtons.Items[n]).SetFocus; // et sélectionner le bouton associé
fTabIndex := n;
if TKGFTab(TMyBitBtn(Sender).KGFTab).fUserEventHandle<>0 then begin // est-ce qu'il faut envoyer un USER_EVENT ?
WP := UserEventKGFTab or UserEventTabSelect or TMyBitBtn(Sender).Tag; // signaler origine KGFTab cause sélection
LP := TMyBitBtn(Sender).KGFTab; // donner l'identifiant du KGFTab à l'origine de l'évènement
res := SendMessage(fUserEventHandle, CM_PANORAMIC_USER, WP, LP); // envoyer le USER_EVENT
end;
end;
end;
// sélectionner un onglet et une page par programme
procedure TKGFTab.SetTabIndex(aIndex: integer);
begin
if aIndex<0 then exit;
if aIndex>=fSheets.Count then exit;
if aIndex=fTabIndex then exit;
if not TMyBitBtn(fButtons.Items[aIndex]).Enabled then exit;
TPanel(fSheets.Items[fTabIndex]).Visible := false;
TPanel(fSheets.Items[aIndex]).Visible := true;
TMyBitBtn(fButtons.Items[aIndex]).SetFocus;
fTabIndex := aIndex;
end;
// changer le libellé d'un bouton
procedure TKGFTab.SetTabLabel(aIndex: integer; aLabel: string);
begin
if aIndex<0 then exit;
if aIndex>=fSheets.Count then exit;
fTabLabels.Delete(aIndex);
fTabLabels.Insert(aIndex,aLabel);
TMyBitBtn(fButtons.Items[aIndex]).Caption := aLabel;
end;
// ajouter un nouvel onglet
procedure TKGFTab.AddTab(aLabel: string);
var
btn: TMyBitBtn;
sht: TPanel;
n: integer;
begin
fTabLabels.Add(aLabel);
// créer le nouveau bouton
btn := TMyBitBtn.Create(self);
btn.Height := fButtonHeight;
btn.Width := fButtonWidth;
btn.Caption := aLabel;
btn.ParentWindow := self.Handle;
btn.OnClick := OnClick;
n := fButtons.Count;
btn.Tag := n; // mémoriser l'indexe (l'identification) de ce bouton
fButtons.Add(btn);
// créer la nouvelle page
sht := TPanel.Create(self);
sht.ParentWindow := self.Handle;
sht.Visible := false; // cacher le nouvel onglet
fSheets.Add(sht);
Refresh;
TMyBitBtn(fButtons.Items[fTabIndex]).SetFocus; // réactiver l'onglet actuellement ciblé
end;
// insérer un nouvel onglet en position aIndex
procedure TKGFTab.InsertTab(aIndex: integer; aLabel: string);
var
btn: TMyBitBtn;
sht: TPanel;
n, i: integer;
begin
n := fButtons.Count;
if aIndex<0 then exit;
if aIndex>=n then exit;
fTabLabels.Insert(aIndex,aLabel);
btn := TMyBitBtn.Create(self);
btn.Height := fButtonHeight;
btn.Width := fButtonWidth;
btn.Caption := aLabel;
btn.ParentWindow := self.Handle;
btn.OnClick := OnClick;
btn.Tag := aindex;
if aIndex<=fTabIndex then fTabIndex := fTabIndex + 1;
fButtons.Insert(aIndex,btn);
sht := TPanel.Create(self);
sht.ParentWindow := self.Handle;
sht.Visible := false;
fSheets.Insert(aIndex,sht);
for i:=0 to fSheets.Count-1 do TMyBitBtn(fButtons.Items[i]).Tag := i;
Refresh;
TMyBitBtn(fButtons.Items[fTabIndex]).SetFocus;
end;
// supprimer un onglet avec son bouton et sa page
procedure TKGFTab.DeleteTab(aIndex: integer);
var
n, i, d: integer;
begin
n := fButtons.Count;
if n<0 then exit;
if aIndex<0 then exit;
if aIndex>=n then exit;
fTabLabels.Delete(aIndex);
n := fButtons.Count;
fButtons.Delete(aIndex);
n := n - 1;
fSheets.Delete(aIndex);
if fTabIndex>=n then begin
fTabIndex := n-1;
end else begin
fTabIndex := -1;
end;
if n>0 then begin
for i:=0 to n-1 do begin
TMyBitBtn(fButtons.Items[fTabIndex]).Tag := i;
if i=fTabIndex then TMyBitBtn(fButtons.Items[fTabIndex]).SetFocus;
end;
end;
Refresh;
end;
// créer le glyp d'un bouton à partir de 4 images (icônes) de dimensions identiques
function TKGFTab.SetButtonGlyph(aIndex: integer; aImage1, aImage2, aImage3, aImage4: TImage): boolean;
begin
result := false;
if (aIndex<0) or (aIndex>=fButtons.Count) then exit;
result := TMyBitBtn(fButtons.Items[aIndex]).SetGlyph(fGlyphSize,aImage1, aImage2, aImage3, aImage4);
end;
{
Cette méthode permet de scripter la configuration d'un objet KGFTab.
Toutes les méthodes sont accessibles via le script.
Elles sont accédées par des "commandes" sous forme d'une seule ligne dans le script.
Chaque commande est composée d'un mot-cle suivi de paramètres séparés par des ","
et terminés par un ";". Ce qui suit le ";" est considéré comme comentaire.
Les commandes sont insensibles à la casse.
Format général: commende,par1,...,parn;
Exemple: Left,100;
; ajout de nouveaux TABs
AddTab,text;
InsertTab,3,Autre text; insérer un TAB devant le 4ème TAB
Un tel script peut être passé par la partie Strings d'un TStringList ou d'un TMemo.
Toutes les commandes seront exécutées dans l'ordre. Le script est interrompue à
la première erreur. Le résultat de la fonction est 0 en cas de terminaison normale,
ou n>=1 en cas d'erreur. Alors, cette valeur indique le numéro de la ligne en erreur du script.
Chaque commande individuelle est implémentée par une procédure locale.
}
function TKGFTab.Configure(n: integer; aScript: TStrings): integer;
var
i, p: integer;
err: boolean;
cmd, command, params: string;
GlyphNames: array [0..3] of string;
procedure C_Parent(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
if opt=0 then exit;
self.ParentWindow := TWinControl(opt).Handle;
err := false;
end;
procedure C_Left(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.Left := opt;
err := false;
end;
procedure C_Top(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.Top := opt;
err := false;
end;
procedure C_Width(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.Width := opt;
err := false;
Refresh;
end;
procedure C_Height(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.Height := opt;
err := false;
Refresh;
end;
procedure C_Label(par: string);
var
p, ind: integer;
s, spar: string;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fButtons.Count) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
self.SetTabLabel(ind,spar);
err := false;
end;
procedure C_AddTab(par: string);
var
p: integer;
s: string;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
s := LeftStr(par,Length(par)-1);
self.AddTab(s);
err := false;
end;
procedure C_InsertTab(par: string);
var
p, ind: integer;
s, spar: string;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fButtons.Count) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
self.InsertTab(ind,spar);
err := false;
end;
procedure C_DeleteTab(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.DeleteTab(opt);
err := false;
end;
{ procedure C_InsertControl(par: string);
var
p, ind: integer;
s, spar: string;
ct: TControl;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fButtons.Count) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
try
ct := TControl(StrToInt(spar));
except
exit;
end;
self.InsertControl(ind,ct);
err := false;
end; }
procedure C_Glyph(par: string);
var
p, ind: integer;
s, spar: string;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>3) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
GlyphNames[ind] := spar;
err := false;
end;
procedure C_ButtonGlyph(par: string);
var
ind, i: integer;
s, spar: string;
img0, img1, img2, img3: TImage;
begin
err := true;
for i:=0 to 3 do begin
if GlyphNames[i]='' then exit;
if not FileExists(GlyphNames[i]) then exit;
end;
if Length(par)<2 then exit;
s := LeftStr(par,Length(par)-1);
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fButtons.Count) then exit;
if pos(',',spar)>0 then exit;
img0 := TImage.Create(nil);
img0.Width := fGlyphSize;
img0.Height := fGlyphSize;
img0.Picture.LoadFromFile(GlyphNames[0]);
img1 := TImage.Create(nil);
img1.Width := fGlyphSize;
img1.Height := fGlyphSize;
img1.Picture.LoadFromFile(GlyphNames[1]);
img2 := TImage.Create(nil);
img2.Width := fGlyphSize;
img2.Height := fGlyphSize;
img2.Picture.LoadFromFile(GlyphNames[2]);
img3 := TImage.Create(nil);
img3.Width := fGlyphSize;
img3.Height := fGlyphSize;
img3.Picture.LoadFromFile(GlyphNames[3]);
if self.SetButtonGlyph(ind,img0,img1,img2,img3) then err := false;
img0.Free;
img1.Free;
img2.Free;
img3.Free;
end;
procedure C_TabPageHandles(par: string);
// var
// s, spar : string;
begin
err := true;
if Length(par)<>1 then exit;
{s := } self.GetTabPageHandles();
err := false;
end;
procedure C_ButtonHeight(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.fButtonHeight := opt;
Refresh;
err := false;
end;
procedure C_ButtonWidth(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.fButtonWidth := opt;
Refresh;
err := false;
end;
procedure C_ButtonPosition(par: string);
var
p, opt: integer;
begin
err := true;
if Length(par)<2 then exit;
p := pos(',',par);
if p>0 then exit;
try
opt := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
if (opt<0) or (opt>3) then exit;
self.SetButtonPosition(TButtonPosition(opt));
err := false;
end;
procedure C_TabColor(par: string);
var
p, ind: integer;
s, spar: string;
clr: TColor;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fButtons.Count) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
try
clr := TColor(StrToInt(spar));
except
exit;
end;
TPanel(self.fSheets.Items[ind]).Color := clr;
err := false;
end;
procedure C_TabActivate(par: string);
var
p, ind, act: integer;
s, spar: string;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fButtons.Count) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
try
act := StrToInt(spar);
except
exit;
end;
TMyBitBtn(self.fButtons.Items[ind]).Enabled := (act <> 0);
err := false;
end;
procedure C_MultiRow(par: string);
var
p, ind, act: integer;
begin
err := true;
if Length(par)<2 then exit;
if pos(',',par)>0 then exit;
try
act := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.fMultiRowButtons := (act <> 0);
err := false;
Refresh;
end;
procedure C_GlyphSize(par: string);
var
p, ind, act: integer;
begin
err := true;
if Length(par)<2 then exit;
if pos(',',par)>0 then exit;
try
act := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
if (act<8) or (act>64) then exit;
self.fGlyphSize := act;
err := false;
Refresh;
end;
procedure C_UserEvent(par: string);
var
p, ind, act: integer;
begin
err := true;
if Length(par)<2 then exit;
if pos(',',par)>0 then exit;
try
act := StrToInt(LeftStr(par,Length(par)-1));
except
exit;
end;
self.fUSerEventHandle := act;
err := false;
Refresh;
end;
procedure C_InsertControl(par: string);
var
p, ind, act: integer;
s, spar: string;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fSheets.Count) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
try
act := StrToInt(spar);
except
exit;
end;
Windows.SetParent(act,TPanel(fSheets[ind]).Handle);
err := false;
end;
{$ifdef ColorButton}
procedure C_ButtonColor(par: string);
var
p, ind, act: integer;
s, spar: string;
clr: TColor;
begin
err := true;
if Length(par)<4 then exit;
p := pos(',',par);
if p=0 then exit;
s := LeftStr(par,p-1);
spar := MidStr(par,p+1,Length(par));
try
ind := StrToInt(s);
except
exit;
end;
if (ind<0) or (ind>=fButtons.Count) then exit;
if pos(',',spar)>0 then exit;
spar := LeftStr(spar,Length(spar)-1);
try
act := StrToInt(spar);
if act=-1 then clr := tMyBitBtn(fButtons[ind]).OldColor
else clr := TColor(act);
except
exit;
end;
TMyBitBtn(fButtons[ind]).Color := clr;
err := false;
end;
{$endif}
// procédure principale pour le tratement du script
begin
result := -1; // script manquant
if n<=0 then exit;
for i:=0 to n-1 do begin
err := false; // supposer "commande correcte"
result := i+1; // retourner le numéro de ligne en cas d'erreur
cmd := aScript.Strings[i]; // prendre une ligne de commande
p := Pos(';',cmd); // chercher la fin de la comande
if p=0 then exit; // syntaxe invalide ?
if p<Length(cmd) then cmd := LeftStr(cmd,p); // ignorer le commentaire
if cmd<>';' then begin // ignorer les lignes vides
// identifier le mot-clé de la commande
p := pos(',',cmd);
if p=0 then begin
command := LowerCase(LeftStr(cmd,Length(cmd)-1));
params := ';';
end else begin
command := LowerCase(LeftStr(cmd,p-1));
params := MidStr(cmd,p+1,300);
end;
// appel des procédures spécifiques pour chaque commande
if command='parent' then C_Parent(params);
if command='left' then C_Left(params);
if command='top' then C_Top(params);
if command='width' then C_Width(params);
if command='height' then C_Height(params);
if command='label' then C_Label(params);
if command='addtab' then C_AddTab(params);
if command='inserttab' then C_InsertTab(params);
if command='deletetab' then C_DeleteTab(params);
if command='insertcontrol' then C_InsertControl(params);
if command='glyph' then C_Glyph(params);
if command='buttonglyph' then C_ButtonGlyph(params);
if command='tabhandles' then C_TabPageHandles(params);
if command='buttonheight' then C_ButtonHeight(params);
if command='buttonwidth' then C_ButtonWidth(params);
if command='buttonposition' then C_Buttonposition(params);
if command='tabcolor' then C_TabColor(params);
if command='tabActivate' then C_TabActivate(params);
if command='multirow' then C_MultiRow(params);
if command='glyphsize' then C_GlyphSize(params);
if command='userevent' then C_UserEvent(params);
if command='insertcontrol' then C_InsertControl(params);
{$ifdef ColorButton}
if command='buttoncolor' then C_ButtonColor(params);
{$endif}
if err then exit; // commande en erreur ? abandonner l'analyse
end;
end;
result := 0;
end;
// cette méthode réaffiche l'ensemble de l'objet TKGFTab (après un changement des paramètres de cofiguration)
procedure TKGFTab.Refresh;
var
n, i: integer;
nBoutons, nSheets, maxbtn: integer; // limites
xTop, xLeft, nbtn: integer; // situation dynamique en cours de traitement
begin
nBoutons := fButtons.Count; // nombre de boutons au total
nsheets := fSheets.Count; // nombre de pages au total
maxbtn:= 3000; // nombre maxi de boutons par ligne
nbtn := 0; // nombre de boutons dans la ligne actuelle
case ButtonPosition of
bpTop: begin
if fMultiRowButtons then maxbtn := Trunc(Width / ButtonWidth);
if nBoutons>0 then begin
xLeft := - ButtonWidth;
xTop := 0;
for i:=0 to nBoutons-1 do begin
TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
if fMultiRowButtons then begin
if nbtn>=maxbtn then begin
nbtn := 0;
xtop := xtop + ButtonHeight;
xLeft := 0;
end else begin
xLeft := xLeft + ButtonWidth;
end;
end else begin
xTop := 0;
xLeft := i * ButtonWidth;
end;
TMyBitBtn(fButtons.Items[i]).Left := xLeft;
TMyBitBtn(fButtons.Items[i]).Top := xTop;
nbtn := nbtn + 1;
end;
end;
if nsheets>0 then begin
xTop := TMyBitBtn(fButtons.Items[nBoutons-1]).Top;
for i:=0 to nsheets-1 do begin
TPanel(fSheets.Items[i]).Left := 0;
TPanel(fSheets.Items[i]).Top := xTop + TMyBitBtn(fButtons.Items[nBoutons-1]).Height;
TPanel(fSheets.Items[i]).Width := self.Width;
TPanel(fSheets.Items[i]).Height := self.Height - xTop;
end;
end;
end;
bpLeft: begin
if fMultiRowButtons then maxbtn := Trunc(Height / ButtonHeight);
if nBoutons>0 then begin
xLeft := 0;
xTop := - ButtonHeight;
for i:=0 to nBoutons-1 do begin
TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
if fMultiRowButtons then begin
if nbtn>=maxbtn then begin
nbtn := 0;
xleft := xLeft + ButtonWidth;
xTop := 0;
end else begin
xTop := xTop + ButtonHeight;
end;
end else begin
xLeft := 0;
xTop := i * ButtonHeight;
end;
TMyBitBtn(fButtons.Items[i]).Left := xLeft;
TMyBitBtn(fButtons.Items[i]).Top := xTop;
nbtn := nbtn + 1;
end;
end;
if nsheets>0 then begin
xLeft := TMyBitBtn(fButtons.Items[nBoutons-1]).Left + TMyBitBtn(fButtons.Items[nBoutons-1]).Width;
for i:=0 to nsheets-1 do begin
TPanel(fSheets.Items[i]).Left := xLeft;
TPanel(fSheets.Items[i]).Top := 0;
TPanel(fSheets.Items[i]).Width := self.Width - xLeft;
TPanel(fSheets.Items[i]).Height := self.Height;
end;
end;
end;
bpBottom: begin
if fMultiRowButtons then maxbtn := Trunc(Width / ButtonWidth);
if nBoutons>0 then begin
xLeft := - ButtonWidth;
xTop := height - ButtonHeight;
for i:=0 to nBoutons-1 do begin
TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
if fMultiRowButtons then begin
if nbtn>=maxbtn then begin
nbtn := 0;
xtop := xtop - ButtonHeight;
xLeft := 0;
end else begin
xLeft := xLeft + ButtonWidth;
end;
end else begin
xTop := Height - ButtonHeight;
xLeft := i * ButtonWidth;
end;
TMyBitBtn(fButtons.Items[i]).Left := xLeft;
TMyBitBtn(fButtons.Items[i]).Top := xTop;
nbtn := nbtn + 1;
end;
end;
if nsheets>0 then begin
xTop := TMyBitBtn(fButtons.Items[nBoutons-1]).Top;
for i:=0 to nsheets-1 do begin
TPanel(fSheets.Items[i]).Left := 0;
TPanel(fSheets.Items[i]).Top := 0;
TPanel(fSheets.Items[i]).Width := self.Width;
TPanel(fSheets.Items[i]).Height := xTop;
end;
end;
end;
bpRight: begin
if fMultiRowButtons then maxbtn := Trunc(Height / ButtonHeight);
if nBoutons>0 then begin
xLeft := Width - ButtonWidth;
xTop := - ButtonHeight;
for i:=0 to nBoutons-1 do begin
TMyBitBtn(fButtons.Items[i]).Width := fButtonWidth;
TMyBitBtn(fButtons.Items[i]).Height := fButtonHeight;
if fMultiRowButtons then begin
if nbtn>=maxbtn then begin
nbtn := 0;
xleft := xLeft - ButtonWidth;
xTop := 0;
end else begin
xTop := xTop + ButtonHeight;
end;
end else begin
xTop := i * ButtonHeight;
end;
TMyBitBtn(fButtons.Items[i]).Left := xLeft;
TMyBitBtn(fButtons.Items[i]).Top := xTop;
nbtn := nbtn + 1;
end;
end;
if nsheets>0 then begin
xLeft := TMyBitBtn(fButtons.Items[nBoutons-1]).Left;
for i:=0 to nsheets-1 do begin
TPanel(fSheets.Items[i]).Left := 0;
TPanel(fSheets.Items[i]).Top := 0;
TPanel(fSheets.Items[i]).Width := xLeft;
TPanel(fSheets.Items[i]).Height := self.Height;
end;
end;
end;
end;
end;
// déplacer les boutons (haut, gauche, bas, droite)
procedure TKGFTab.SetButtonPosition(aPosition: TButtonPosition);
begin
fButtonPosition := aPosition;
Refresh;
end;
// adapter la hauteur des boutons
procedure TKGFTab.SetButtonHeight(aHeight: integer);
var
n, i: integer;
begin
if fButtonHeight=aHeight then exit;
if (aHeight<18) or (aHeight>66) then exit;
fButtonHeight := aHeight;
Refresh;
end;
// adapter la largeur des boutons
procedure TKGFTab.SetButtonWidth(aWidth: integer);
var
n, i: integer;
begin
if fButtonWidth=aWidth then exit;
if (aWidth<18) or (aWidth>250) then exit;
fButtonWidth := aWidth;
Refresh;
end;
// gérer le mode de boutons en lignes multiples
procedure TKGFTab.SetMultiRowButtons(aMode: boolean);
begin
if MultiRowButtons<>aMode then begin
fMultiRowButtons := aMode;
Refresh;
end;
end;
// retourner la liste des handles des pages du TKGFTab.
// Ceci servira pour placer des objets dans les pages si le contrôle est dans une DLL, par exemple
function TKGFTab.GetTabPageHandles: string;
var
n, i: integer;
s: string;
begin
n := fSheets.Count;
s := '';
if n>0 then begin
for i:=0 to n-1 do s := s + IntToStr(TPanel(fSheets.Items[i]).Handle) + #13#10;
end;
result := s;
end;
{
*************************************************************
*************************************************************
**************** Interface PANORAMIC ************************
*************************************************************
*************************************************************
}
{$ifdef PanoramicWrapper}
function CreateKGFTab(hDest: HWND): integer; stdcall; export;
var
KT: TKGFTab;
begin
result := 0;
try
if hDest=0 then exit;
TempForm := TForm.Create(nil); // nécessaire !
TempForm.Visible := false; // nécessaire !
KT := TKGFTab.Create(TempForm);
KT.ParentWindow := hDest;
result := integer(KT);
except
end;
end;
exports CreateKGFTab;
function ConfigureKGFTab(KT: TKGFTab; aScript: integer): integer; stdcall; export;
var
sl: TStringList;
begin
result := -1;
try
if not assigned(KT) then exit;
if KT.ClassName<>'TKGFTab' then exit;
if aScript=0 then exit;
sl := TStringList.Create;
sl.Text := GetStringFromPanoramic(aScript);
result := KT.Configure(sl.Count,sl);
sl.Free;
except
if assigned(sl) then sl.Free;
end;
end;
exports ConfigureKGFTab;
function DeleteKGFTab(KT: TKGFTab): integer; stdcall; export;
begin
result := integer(KT);
try
if not assigned(KT) then exit;
if KT.ClassName<>'TKGFTab' then exit;
KT.Free;
result := 0;
except
end;
end;
exports DeleteKGFTab;
function GetKGFTabPageHandles(KT: TKGFTab; dest: integer): integer; stdcall; export;
var
s: string;
begin
result := -1;
try
if not assigned(KT) then exit;
if KT.ClassName<>'TKGFTab' then exit;
s := KT.GetTabPageHandles;
CopyStringToPanoramic(s,dest);
result := 0;
except
end;
end;
exports GetKGFTabPageHandles;
function GetKGFTabHandle(KT: TKGFTab): integer; stdcall; export;
begin
result := 0;
try
if not assigned(KT) then exit;
if KT.ClassName<>'TKGFTab' then exit;
result := KT.KGFTabHandle;
except
end;
end;
exports GetKGFTabHandle;
{$endif}
end. |
Partager