-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmckObjs.pas
3462 lines (3263 loc) · 103 KB
/
mckObjs.pas
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
{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
KKKKK KKKKK OOOOOOOOO LLLLL
KKKKK KKKKK OOOOOOOOOOOOO LLLLL
KKKKK KKKKK OOOOO OOOOO LLLLL
KKKKK KKKKK OOOOO OOOOO LLLLL
KKKKKKKKKK OOOOO OOOOO LLLLL
KKKKK KKKKK OOOOO OOOOO LLLLL
KKKKK KKKKK OOOOO OOOOO LLLLL
KKKKK KKKKK OOOOOOOOOOOOO LLLLLLLLLLLLL kkkkk
KKKKK KKKKK OOOOOOOOO LLLLLLLLLLLLL kkkkk
kkkkk
mmmmm mmmmm mmmmmm cccccccccccc kkkkk kkkkk
mmmmmmmm mmmmm mmmmm cccccc ccccc kkkkk kkkkk
mmmmmmmm mmmmm mmmmm cccccc kkkkkkkk
mmmmm mmmmm mmmmm cccccc ccccc kkkkk kkkkk
mmmmm mmmmm mmmmm cccccccccccc kkkkk kkkkk
Key Objects Library (C) 2000 by Kladov Vladimir.
KOL Mirror Classes Kit (C) 2000 by Kladov Vladimir.
}
unit mckObjs;
interface
{$I KOLDEF.INC}
uses KOL, Classes, Forms, Controls, Dialogs, Windows, Messages, extctrls,
stdctrls, comctrls, SysUtils, Graphics, mirror, ShellAPI,
buttons, mckFileFilterEditor,
//////////////////////////////////////////
{$IFDEF _D6orHigher} //
DesignIntf, DesignEditors //
{$ELSE} //
//////////////////////////////////////////
DsgnIntf
//////////////////////////////////////////
{$ENDIF} //
//////////////////////////////////////////
{$IFNDEF _D2} {$IFNDEF _d3}, imglist {$ENDIF} {$ENDIF},
TypInfo, menus;
type
//============================================================================
//---- MIRROR FOR A TIMER ----
//---- ÇÅÐÊÀËÎ ÄËß ÒÀÉÌÅÐÀ ----
TKOLTimer = class(TKOLObj)
private
FEnabled: Boolean;
FInterval: Integer;
FOnTimer: TOnEvent;
FPeriodic: Boolean;
FMultimedia: Boolean;
FResolution: Integer;
procedure SetEnabled(const Value: Boolean);
procedure SetInterval(const Value: Integer);
procedure SetOnTimer(const Value: TOnEvent);
procedure SetMultimedia(const Value: Boolean);
procedure SetPeriodic(const Value: Boolean);
procedure SetResolution(const Value: Integer);
protected
procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String );
override;
procedure P_SetupFirst( SL: TStringList; const AName, AParent, Prefix: String );
override;
procedure AssignEvents( SL: TStringList; const AName: String ); override;
function P_AssignEvents( SL: TStringList; const AName: String; CheckOnly: Boolean ): Boolean; override;
procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String );
override;
procedure P_SetupLast( SL: TStringList; const AName, AParent, Prefix: String );
override;
public
function TypeName: String; override;
constructor Create( AOwner: TComponent ); override;
function Pcode_Generate: Boolean; override;
procedure P_DoProvideFakeType( SL: TStringList ); override;
published
property Interval: Integer read FInterval write SetInterval;
property Enabled: Boolean read FEnabled write SetEnabled;
property OnTimer: TOnEvent read FOnTimer write SetOnTimer;
property Multimedia: Boolean read FMultimedia write SetMultimedia;
property Resolution: Integer read FResolution write SetResolution;
property Periodic: Boolean read FPeriodic write SetPeriodic;
end;
//============================================================================
//---- MIRROR FOR A THREAD ----
//---- ÇÅÐÊÀËÎ ÄËß ÍÈÒÈ ----
TPriorityClass = ( pcNormal, pcIdle, pcHigh, pcRealTime );
TThreadPriority = ( tpNormal, tpBelowNormal, tpLowest, tpIdle, tpAboveNormal,
tpHighest, tpCritical );
TKOLThread = class(TKOLObj)
private
FPriorityClass: TPriorityClass;
FThreadPriority: TThreadPriority;
FOnExecute: TOnThreadExecute;
FOnSuspend: TObjectMethod;
FOnResume: TOnEvent;
FstartSuspended: Boolean;
F_AutoFree: Boolean;
FPriorityBoost: Boolean;
procedure SetPriorityClass(const Value: TPriorityClass);
procedure SetThreadPriority(const Value: TThreadPriority);
procedure SetOnExecute(const Value: TOnThreadExecute);
procedure SetOnSuspend(const Value: TObjectMethod);
procedure SetOnResume(const Value: TOnEvent);
procedure SetstartSuspended(const Value: Boolean);
procedure SetAutoFree(const Value: Boolean);
procedure SetPriorityBoost(const Value: Boolean);
protected
procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
function NotAutoFree: Boolean; override;
function BestEventName: String; override;
public
procedure AssignEvents( SL: TStringList; const AName: String ); override;
function P_AssignEvents( SL: TStringList; const AName: String;
CheckOnly: Boolean ): Boolean; override;
constructor Create( AOwner: TComponent ); override;
function Pcode_Generate: Boolean; override;
published
property PriorityClass: TPriorityClass read FPriorityClass write SetPriorityClass;
property ThreadPriority: TThreadPriority read FThreadPriority write SetThreadPriority;
property OnExecute: TOnThreadExecute read FOnExecute write SetOnExecute;
property OnSuspend: TObjectMethod read FOnSuspend write SetOnSuspend;
property OnResume: TOnEvent read FOnResume write SetOnResume;
property startSuspended: Boolean read FstartSuspended write SetstartSuspended;
property AutoFree: Boolean read F_AutoFree write SetAutoFree;
property PriorityBoost: Boolean read FPriorityBoost write SetPriorityBoost;
end;
//============================================================================
//---- MIRROR FOR AN IMAGELIST ----
//---- ÇÅÐÊÀËÎ ÄËß ÑÏÈÑÊÀ ÐÈÑÓÍÊÎÂ ----
TKOLImageList = class(TKOLObj)
private
FImgWidth: Integer;
FImgHeight: Integer;
FCount: Integer;
FBitmap: TBitmap;
FSystemImageList: Boolean;
FTransparentColor: TColor;
FColors: TImageListColors;
FMasked: Boolean;
FBkColor: TColor;
FAllowCompression: Boolean;
FForce32bit: Boolean;
procedure SetImgHeight(Value: Integer);
procedure SetImgWidth(Value: Integer);
procedure SetCount(const Value: Integer);
procedure SetBitmap(const Value: TBitmap);
procedure SetSystemImageList(const Value: Boolean);
function GetBitmap: TBitmap;
procedure SetTransparentColor(const Value: TColor);
function GetTransparentColor: TColor;
procedure SetColors(const Value: TImageListColors);
procedure SetMasked(const Value: Boolean);
procedure SetBkColor(const Value: TColor);
function GetImageListHandle: THandle;
procedure AssignBitmapToKOLImgList;
procedure SetAllowCompression(const Value: Boolean);
procedure SetForce32bit(const Value: Boolean);
protected
FKOLImgList: PImageList;
procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
//procedure BitmapChanged( Sender: TObject );
public
function Pcode_Generate: Boolean; override;
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
procedure Clear;
procedure Assign( Value: TPersistent ); override;
property Handle: THandle read GetImageListHandle;
published
property ImgWidth: Integer read FImgWidth write SetImgWidth;
property ImgHeight: Integer read FImgHeight write SetImgHeight;
property Count: Integer read FCount write SetCount;
property bitmap: TBitmap read GetBitmap write SetBitmap;
property TransparentColor: TColor read GetTransparentColor write SetTransparentColor;
property systemimagelist: Boolean read FSystemImageList write SetSystemImageList;
property Colors: TImageListColors read FColors write SetColors;
property Masked: Boolean read FMasked write SetMasked;
property BkColor: TColor read FBkColor write SetBkColor;
property AllowCompression: Boolean read FAllowCompression write SetAllowCompression
default TRUE;
property Force32bit: Boolean read FForce32bit write SetForce32bit;
end;
TKOLImageListEditor = class(TComponentEditor)
private
protected
public
procedure Edit; override;
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
end;
//----------------------------------------------------------------------------
//---- MIRROR FOR OPENSAVE FILE DIALOG ----
//---- ÇÅÐÊÀËÎ ÄËß ÄÈÀËÎÃÀ ÂÛÁÎÐÀ ÔÀÉËÀ ----
TKOLOpenSaveDialog = class(TKOLObj)
private
FOptions: TOpenSaveOptions;
FInitialDir: String;
FFilter: String;
FFilterIndex: Integer;
FTitle: String;
FDefExtension: String;
FOpenDialog: Boolean;
FTemplateName: String;
FNoPlaceBar: Boolean;
procedure SetOptions(const Value: TOpenSaveOptions);
procedure SetInitialDir(const Value: String);
procedure SetFilter(const Value: String);
procedure SetFilterIndex(const Value: Integer);
procedure SetTitle(const Value: String);
procedure SetDefExtension(const Value: String);
procedure SetOpenDialog(const Value: Boolean);
procedure SetTemplateName(const Value: String);
procedure SetNoPlaceBar(const Value: Boolean);
protected
procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
public
constructor Create( AOwner: TComponent ); override;
function Pcode_Generate: Boolean; override;
published
property Options: TOpenSaveOptions read FOptions write SetOptions;
property NoPlaceBar: Boolean read FNoPlaceBar write SetNoPlaceBar;
property Title: String read FTitle write SetTitle;
property TemplateName: String read FTemplateName write SetTemplateName;
property InitialDir: String read FInitialDir write SetInitialDir;
property Filter: String read FFilter write SetFilter;
property FilterIndex: Integer read FFilterIndex write SetFilterIndex;
property DefExtension: String read FDefExtension write SetDefExtension;
property OpenDialog: Boolean read FOpenDialog write SetOpenDialog;
property Localizy;
end;
TKOLFileFilter = class( TStringProperty )
private
protected
public
function GetAttributes: TPropertyAttributes; override;
procedure Edit; override;
end;
//----------------------------------------------------------------------------
//---- MIRROR FOR OPENDIR DIALOG ----
//---- ÇÅÐÊÀËÎ ÄËß ÄÈÀËÎÃÀ ÂÛÁÎÐÀ ÄÈÐÅÊÒÎÐÈß ----
TKOLOpenDirDialog = class( TKOLObj )
private
FTitle: String;
FOptions: TOpenDirOptions;
FInitialPath: String;
FCenterOnScreen: Boolean;
FOnSelChanged: TOnODSelChange;
FAltDialog: Boolean;
procedure SetTitle(const Value: String);
procedure SetOptions(const Value: TOpenDirOptions);
procedure SetInitialPath(const Value: String);
procedure SetCenterOnScreen(const Value: Boolean);
procedure SetOnSelChanged(const Value: TOnODSelChange);
procedure SetAltDialog(const Value: Boolean);
protected
procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
public
procedure AssignEvents( SL: TStringList; const AName: String ); override;
function P_AssignEvents( SL: TStringList; const AName: String;
CheckOnly: Boolean ): Boolean; override;
constructor Create( AOwner: TComponent ); override;
function TypeName: String; override;
function Pcode_Generate: Boolean; override;
function AdditionalUnits: String; override;
published
property Title: String read FTitle write SetTitle;
property Options: TOpenDirOptions read FOptions write SetOptions;
property InitialPath: String read FInitialPath write SetInitialPath;
property CenterOnScreen: Boolean read FCenterOnScreen write SetCenterOnScreen;
property OnSelChanged: TOnODSelChange read FOnSelChanged write SetOnSelChanged;
property Localizy;
property AltDialog: Boolean read FAltDialog write SetAltDialog;
end;
//----------------------------------------------------------------------------
//---- MIRROR FOR COLOR CHOOSING DIALOG ----
//---- ÇÅÐÊÀËÎ ÄËß ÄÈÀËÎÃÀ ÂÛÁÎÐÀ ÖÂÅÒÀ ----
TKOLColorDialog = class( TKOLObj )
private
FColorCustomOption: TColorCustomOption;
FCustomColors: array[ 1..16 ] of TColor;
procedure SetColorCustomOption(const Value: TColorCustomOption);
function GetCustomColor( const Index: Integer ): TColor;
procedure SetCustomColor(const Index: Integer; const Value: TColor);
protected
procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
public
constructor Create( AOwner: TComponent ); override;
function Pcode_Generate: Boolean; override;
published
property ColorCustomOption: TColorCustomOption read FColorCustomOption write SetColorCustomOption;
property CustomColor1: TColor index 1 read GetCustomColor write SetCustomColor;
property CustomColor2: TColor index 2 read GetCustomColor write SetCustomColor;
property CustomColor3: TColor index 3 read GetCustomColor write SetCustomColor;
property CustomColor4: TColor index 4 read GetCustomColor write SetCustomColor;
property CustomColor5: TColor index 5 read GetCustomColor write SetCustomColor;
property CustomColor6: TColor index 6 read GetCustomColor write SetCustomColor;
property CustomColor7: TColor index 7 read GetCustomColor write SetCustomColor;
property CustomColor8: TColor index 8 read GetCustomColor write SetCustomColor;
property CustomColor9: TColor index 9 read GetCustomColor write SetCustomColor;
property CustomColor10: TColor index 10 read GetCustomColor write SetCustomColor;
property CustomColor11: TColor index 11 read GetCustomColor write SetCustomColor;
property CustomColor12: TColor index 12 read GetCustomColor write SetCustomColor;
property CustomColor13: TColor index 13 read GetCustomColor write SetCustomColor;
property CustomColor14: TColor index 14 read GetCustomColor write SetCustomColor;
property CustomColor15: TColor index 15 read GetCustomColor write SetCustomColor;
property CustomColor16: TColor index 16 read GetCustomColor write SetCustomColor;
end;
//----------------------------------------------------------------------------
//---- MIRROR FOR TRAY ICON ----
//---- ÇÅÐÊÀËÎ ÄËß ÈÊÎÍÊÈ Â ÒÐÅÅ ----
TKOLTrayIcon = class( TKOLObj )
private
FIcon: TIcon;
FActive: Boolean;
FTooltip: String;
FAutoRecreate: Boolean;
FOnMouse: TOnTrayIconMouse;
FNoAutoDeactivate: Boolean;
procedure SetIcon(const Value: TIcon);
procedure SetActive(const Value: Boolean);
procedure SetTooltip(const Value: String);
procedure SetAutoRecreate(const Value: Boolean);
procedure SetOnMouse(const Value: TOnTrayIconMouse);
procedure SetNoAutoDeactivate(const Value: Boolean);
protected
procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure P_SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
procedure AssignEvents( SL: TStringList; const AName: String ); override;
function P_AssignEvents( SL: TStringList; const AName: String; CheckOnly: Boolean ): Boolean; override;
public
function Pcode_Generate: Boolean; override;
constructor Create( AOwner: TComponent ); override;
destructor Destroy; override;
published
property Icon: TIcon read FIcon write SetIcon;
property Active: Boolean read FActive write SetActive;
property NoAutoDeactivate: Boolean read FNoAutoDeactivate write SetNoAutoDeactivate;
property Tooltip: String read FTooltip write SetTooltip;
property AutoRecreate: Boolean read FAutoRecreate write SetAutoRecreate;
property OnMouse: TOnTrayIconMouse read FOnMouse write SetOnMouse;
property Localizy;
end;
type KOLTPixelFormat = KOL.TPixelFormat;
function CountSystemColorsUsedInBitmap( Bmp: KOL.PBitmap; ColorList: KOL.PList ): KOLTPixelFormat;
//function SaveBitmap( Bitmap: TBitmap; const Path: String ): Boolean;
procedure GenerateBitmapResource( Bitmap: TBitmap; const RsrcName, FileName: String;
var Updated: Boolean; AllowCompression: Boolean );
procedure GenerateIconResource( Icon: TIcon; const RsrcName, FileName: KOLString;
var Updated: Boolean );
procedure RemoveSelection( FD: IFormDesigner );
function String2Pascal( S: String; const Concatenator: String ): String;
function P_String2Pascal( S: String ): String;
//function GetBmpPixel( Bitmap: TBitmap; X, Y: Integer ): TColor;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents( 'KOL', [ TKOLTimer, TKOLThread, TKOLImageList, TKOLMainMenu, TKOLPopupMenu,
TKOLOpenSaveDialog, TKOLOpenDirDialog, TKOLColorDialog,
TKOLTrayIcon ] );
RegisterComponentEditor( TKOLImageList, TKOLImageListEditor );
RegisterPropertyEditor( TypeInfo( String ), TKOLOpenSaveDialog, 'Filter',
TKOLFileFilter );
RegisterPropertyEditor( TypeInfo( TOnODSelChange ), TKOLOpenDirDialog, 'OnSelChanged', TKOLOnEventPropEditor );
RegisterPropertyEditor( TypeInfo( TOnTrayIconMouse ), nil, '', TKOLOnEventPropEditor );
end;
function String2PascalStr1( const S : String; const Concatenator: String ) : String;
var I, Strt : Integer;
function String2DoubleQuotas( const S : String ) : String;
var I, J : Integer;
begin
//if IndexOfChar( S, '''' ) <= 0 then
if pos( '''', S ) <= 0 then
Result := S
else
begin
J := 0;
for I := 1 to Length( S ) do
if S[ I ] = '''' then Inc( J );
SetLength( Result, Length( S ) + J );
J := 1;
for I := 1 to Length( S ) do
begin
Result[ J ] := S[ I ];
Inc( J );
if S[ I ] = '''' then
begin
Result[ J ] := '''';
Inc( J );
end;
end;
end;
end;
begin
Result := '';
if S = '' then
begin
Result := '''''';
exit;
end;
Strt := 1;
for I := 1 to Length( S ) + 1 do
begin
if (I > Length( S )) or (S[ I ] < ' ') then
begin
if (I > Strt) and (I > 1) then
begin
if Result <> '' then
Result := Result + Concatenator;
Result := Result + '''' + String2DoubleQuotas( Copy( S, Strt, I - Strt ) ) + '''';
end;
if I > Length( S ) then break;
if Result <> '' then
Result := Result + Concatenator
else
Result := Result + '''''' + Concatenator;
// Result := Result + '''''';
//if IndexOfChar(Concatenator, ',') > 0 then
if pos( ',', Concatenator ) > 0 then
Result := Result + IntToStr( Integer( S[ I ] ) )
else Result := Result + '#' + IntToStr( Integer( S[ I ] ) );
Strt := I + 1;
end;
end;
end;
function String2Pascal( S: String; const Concatenator: String ): String;
begin
asm
jmp @@e_signature
DB '#$signature$#', 0
DB 'String2Pascal', 0
@@e_signature:
end;
if Length( S ) > 0 then
begin
Result := '';
while S <> '' do
begin
if Result <> '' then
Result := Result + Concatenator;
Result := Result + String2PascalStr1( Copy( S, 1, 255 ), Concatenator );
S := Copy( S, 256, MaxInt );
end;
end
else
Result := '''''';
end;
function P_String2Pascal( S: String ): String;
var i: Integer;
begin
if S <> '' then
begin
if Length( S ) <= 64 then
Result := String2Pascal( S, ',' ) + ' #0'
else
begin
i := 1;
Result := '';
while i <= Length( S ) do
begin
Result := Result + String2Pascal( Copy( S, i, 64 ), ',' ) + #13#10;
inc( i, 64 );
end;
Result := Copy( Result, 1, Length( Result )-2 ) + ' #0';
end;
end
else
Result := ' #0';
end;
procedure RemoveSelection( FD: IFormDesigner );
{$IFDEF _D2orD3}
var L: TComponentList;
{$ENDIF}
begin
asm
jmp @@e_signature
DB '#$signature$#', 0
DB 'RemoveSelection', 0
@@e_signature:
end;
try
{$IFDEF _D5orHigher}
FD.NoSelection;
{$ELSE}
{$IFDEF _D2orD3}
L := TComponentList.Create;
FD.SetSelections( L );
L.Free;
{$ELSE _D4}
FD.SetSelections( nil );
{$ENDIF}
{$ENDIF}
except
Rpt( '*/\* EXCEPTION - Could not remove current selection', WHITE );
end;
end;
function ColorsAreSystem16( ColorList: PList ): Boolean;
const SysColors: array[ 0..15 ] of TColor = ( 0, $800000, $8000, $808000, $80,
$800080, $8080, $808080, $C0C0C0, $FF0000, $FF00, $FFFF00, $FF, $FF00FF,
$FFFF, $FFFFFF );
var I, J: Integer;
C: TColor;
Found: Boolean;
begin
Result := TRUE;
for I := 0 to ColorList.Count-1 do
begin
C := TColor( ColorList.Items[ I ] );
Found := FALSE;
for J := 0 to 15 do
if SysColors[ J ] = C then
begin
Found := TRUE;
break;
end;
if not Found then
begin
Rpt( '***** Color ' + IntToHex( C, 8 ) + ' not found in system 16 colors',
WHITE );
Result := FALSE;
Exit;
end;
end;
end;
function ColorsAreSystem256( ColorList: PList ): Boolean;
const SysColors8bit: array[ 0..255 ] of DWORD = ( $000000,
$C0DCC0, $800000, $808000, $008000, $008080, $000080, $800080, $808080,
$00FF00, $0000FF, $00FFFF, $C0DCC0, $000040, $400040, $000000, $A0A0A4,
$C0C0C0, $C0DCC0, $FFFBF0, $FFFBF0, $FFFBF0, $FFFBF0, $FFFFFF, $FF0000,
$FFFF00, $FF00FF, $FFFFFF, $A6CAF0, $402000, $004040, $202040, $202040,
$606040, $404040, $E08080, $E00080, $C0DCC0, $A0A0A4, $800000, $C02000,
$404000, $A04000, $E04000, $406000, $A06000, $E06000, $40A000, $202040,
$404040, $404040, $E06040, $A6CAF0, $C0DCC0, $40E000, $800000, $004000,
$604000, $C04000, $006000, $606000, $C06000, $00A000, $60A000, $A0A000,
$E0A000, $40C000, $A0C000, $E0C000, $A0E000, $00E040, $600040, $C00040,
$0000FF, $604040, $C04040, $006040, $606040, $C06040, $00A040, $C0A000,
$00C000, $60C000, $C0C000, $60E000, $C0E000, $0000FF, $A00040, $E00040,
$404040, $A04040, $E04040, $406040, $A06040, $E06040, $40A040, $60A040,
$C0A040, $00C040, $60C040, $C0C040, $40E040, $A0E040, $E0E040, $400080,
$A00080, $E00080, $404080, $A04080, $E04080, $406080, $A06080, $A0A040,
$E0A040, $40C040, $A0C040, $E0C040, $60E040, $C0E040, $000080, $600080,
$C00080, $004080, $604080, $C04080, $006080, $606080, $C06080, $00A080,
$A0C080, $E0C080, $40E080, $C0E080, $FF00FF, $A04080, $C00080, $404080,
$C04080, $006080, $604080, $C06080, $40A080, $A0A0A4, $E0A080, $40C080,
$C0C080, $00E080, $A0E080, $E000C0, $00A080, $A00080, $000080, $600080,
$E00080, $406080, $A06080, $E04080, $60A080, $C0A080, $00C080, $40C080,
$A0C080, $E0C080, $40E080, $A0E080, $E0E080, $400080, $A000C0, $004080,
$6040C0, $C040C0, $0060C0, $606080, $C060C0, $00A0C0, $60A0C0, $60C080,
$C0C080, $00E080, $60C080, $C0E080, $0000C0, $6000C0, $C000C0, $4040C0,
$A040C0, $E040C0, $4060C0, $A060C0, $E06080, $40A0C0, $A0A0C0, $C0A0C0,
$00A0C0, $60A0C0, $C0A0C0, $00C0C0, $60C0C0, $C0C0C0, $00FFFF, $60E080,
$C0DCC0, $4000C0, $A000C0, $4040C0, $A040C0, $FF00FF, $4060C0, $E0A0C0,
$40A0C0, $A0A0C0, $E0A0C0, $40C0C0, $A0C0C0, $E0A0C0, $40C0C0, $C0DCC0,
$FFFBF0, $6000C0, $0040C0, $6040C0, $C040C0, $0060C0, $6060C0, $A060C0,
$E060C0, $40A0C0, $A6CAF0, $E0A0C0, $40C0C0, $A6CAF0, $FFFBF0, $60C0C0,
$FFFFFF, $60E080, $6060C0, $A6CAF0, $606040, $808080, $C0C0C0, $C060C0,
$00A0C0, $60A0C0, $A6CAF0, $00FFFF, $60C0C0, $A6CAF0, $00FFFF, $A6CAF0,
$E06080, $E0E080, $E060C0, $A00040, $808080, $A0A0A4, $C0C0C0 );
var I, J: Integer;
C: DWORD;
begin
Result := FALSE;
for I := 0 to ColorList.Count-1 do
begin
C := DWORD( ColorList.Items[ I ] );
for J := 0 to 255 do
begin
if SysColors8bit[ J ] = C then
begin
C := 0;
break;
end;
end;
if C <> 0 then
begin
//Rpt( '~~~ color not found: ' + Int2Hex( C, 6 ), WHITE );
Exit;
end;
end;
Result := TRUE;
end;
function ColorsAre64K( ColorList: PList ): Boolean;
var I: Integer;
C: DWORD;
begin
Result := FALSE;
for I := 0 to ColorList.Count-1 do
begin
C := DWORD( ColorList.Items[ I ] );
if (C and $E0C0E0) <> C then
begin
//Rpt( '~~~ color not found: ' + Int2Hex( C, 6 ), WHITE );
Exit;
end;
end;
Result := TRUE;
end;
function CountSystemColorsUsedInBitmap( Bmp: KOL.PBitmap; ColorList: KOL.PList ): KOL.TPixelFormat;
var Y, X: Integer;
L: PDWORD;
C: TColor;
R, G, B: Byte;
not_use_16bpp: Boolean;
begin
Rpt( 'CountSystemColorsUsedInBitmap()', YELLOW );
ColorList.Clear;
ColorList.Capacity := 65537;
TRY
not_use_16bpp := FALSE;
for Y := 0 to Bmp.Height - 1 do
begin
L := Bmp.ScanLine[ Y ];
for X := 0 to Bmp.Width - 1 do
begin
C := L^ and $FFFFFF;
if ((C and $E0C0E0) <> C) and not not_use_16bpp then
begin
R := C and $FF;
G := (C and $FF00) shr 8;
B := C shr 16;
if ((R and $E0) <> R) and (R <> $FF) or
((G and $C0) <> G) and (G <> $FF) or
((B and $E0) <> B) and (B <> $FF) then
begin
//Result := KOL.pf24bit;
//Rpt( '~~~ color not found: ' + Int2Hex( C, 6 ), WHITE );
//Exit;
not_use_16bpp := TRUE;
end;
end;
if ColorList.IndexOf( Pointer( C ) ) < 0 then
begin
ColorList.Add( Pointer( C ) );
if ColorList.Count > 65536 then
begin
//Result := KOL.pf24bit;
//Rpt( '~~~~~ pf24bit (break) ~~~~~ (' + IntToStr( ColorList.Count ) +
// ')', WHITE );
//Exit;
not_use_16bpp := TRUE;
break;
end;
if not_use_16bpp and (ColorList.Count > 256) then
end;
Inc( L );
end;
end;
if (ColorList.Count <= 2) {and
((ColorList.Count = 0) or
(ColorList.Count > 0) and (DWORD(ColorList.Items[ 0 ]) and $FFFFFF = $FFFFFF) and
((ColorList.Count < 2) or
(ColorList.Count = 2) and (DWORD( ColorList.Items[ 1 ] ) and $FFFFFF = 0) ))} then
begin
Result := KOL.pf1bit;
Rpt( '~~~~~ pf1bit ~~~~~', WHITE );
end else if (ColorList.Count <= 16) {and ColorsAreSystem16( ColorList )} then
begin
Result := KOL.pf4bit;
Rpt( '~~~~~ pf4bit ~~~~~', WHITE );
end else if (ColorList.Count <= 256) {and ColorsAreSystem256( ColorList )} then
begin
Result := KOL.pf8bit;
Rpt( '~~~~~ pf8bit ~~~~~', WHITE );
end else if (ColorList.Count <= 65536) and not not_use_16bpp
and ColorsAre64K( ColorList ) then
begin
Result := KOL.pf16bit;
Rpt( '~~~~~ pf16bit ~~~~~', WHITE );
end
else
begin
Result := KOL.pf24bit;
Rpt( '~~~~~ pf24bit ~~~~~ (' + IntToStr( ColorList.Count ) + ')', WHITE );
end;
FINALLY
Rpt( '------ Colors in bitmap: ' + IntToStr( ColorList.Count ), YELLOW );
//ColorList.Free;
END;
end;
{$IFDEF _D2}
procedure GenerateBitmapResource( Bitmap: TBitmap; const RsrcName, FileName: String;
var Updated: Boolean );
var RL: TStringList;
Buf1, Buf2: PChar;
I, J: Integer;
F: THandle;
S: String;
KOLBmp: KOL.PBitmap;
begin
asm
jmp @@e_signature
DB '#$signature$#', 0
DB 'GenerateBitmapResource', 0
@@e_signature:
end;
KOLBmp := NewDIBBitmap( Bitmap.Width, Bitmap.Height, KOL.pf32bit );
BitBlt( KOLBmp.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height,
Bitmap.Canvas.Handle, 0, 0, SRCCOPY );
KOLBmp.HandleType := KOL.bmDIB;
KOLBmp.PixelFormat := KOL.pf32bit;
KOLBmp.PixelFormat := CountSystemColorsUsedInBitmap( KOLBmp );
KOLBmp.SaveToFile( ProjectSourcePath + FileName + '.bmp' );
Buf1 := nil;
Buf2 := nil;
I := 0;
J := 0;
S := ProjectSourcePath + FileName + '.res';
if FileExists( S ) then
begin
I := FileSize( S );
if I > 0 then
begin
GetMem( Buf1, I );
F := KOL.FileCreate( S, ofOpenRead or ofShareDenyWrite or ofOpenExisting );
if F <> THandle( -1 ) then
begin
KOL.FileRead( F, Buf1^, I );
KOL.FileClose( F );
end;
end;
end;
RL := TStringList.Create;
RL.Add( UpperCase( RsrcName ) + ' BITMAP "' + FileName + '.bmp"' );
RL.SaveToFile( ProjectSourcePath + FileName + '.rc' );
RL.Free;
if not FileExists( ProjectSourcePath + FileName + '.rc' ) then
begin
ShowMessage( 'Can not save file: ' + ProjectSourcePath + FileName + '.rc' );
Exit;
end;
{ShellExecute( 0, 'open', PChar( ExtractFilePath( Application.ExeName ) + 'brcc32.exe' ),
PChar( ProjectSourcePath + FileName + '.rc' ), PChar( ProjectSourcePath ),
SW_HIDE );}
Rpt( 'Compiling resource ' + ProjectSourcePath + FileName + '.rc', WHITE );
if not ExecuteWait( ExtractFilePath( Application.ExeName ) + 'brcc32.exe',
'"' + ProjectSourcePath + FileName + '.rc"',
ProjectSourcePath, SW_HIDE, INFINITE, nil ) then
begin
Rpt( 'Can not compile resource with ' + ExtractFilePath( Application.ExeName ) + 'brcc32.exe', RED );
end;
if FileExists( S ) then
begin
J := FileSize( S );
if J > 0 then
begin
GetMem( Buf2, J );
F := KOL.FileCreate( S, ofOpenRead or ofShareDenyWrite or ofOpenExisting );
if F <> THandle( -1 ) then
begin
KOL.FileRead( F, Buf2^, J );
KOL.FileClose( F );
end;
end;
end;
if (Buf1 = nil) or (I <> J) or
(Buf2 <> nil) and not CompareMem( Buf1, Buf2, J ) then
begin
Rpt( 'Resource ' + FileName + ' changed.', WHITE );
Updated := TRUE;
end;
if Buf1 <> nil then FreeMem( Buf1 );
if Buf2 <> nil then FreeMem( Buf2 );
end;
{$ELSE not _D2}
procedure OptimizeKOLBitmapBeforeRLEEncoding( B: KOL.PBitmap );
var ColorCounts: array[ 0..255 ] of Integer;
x, y, N, i, M: Integer;
Src: PByte;
C1, C2: TColor;
Tmp: KOL.PBitmap;
begin
FillChar( ColorCounts, Sizeof( ColorCounts ), 0 );
N := 0;
for y := 0 to B.Height-1 do
begin
Src := B.ScanLine[y];
if B.PixelFormat = KOL.pf4bit then
begin
x := B.Width;
while x > 0 do
begin
inc( ColorCounts[ Src^ shr 4 ] );
if x > 1 then
inc( ColorCounts[ Src^ and 15 ] );
dec( x, 2 );
inc( Src );
end;
N := 16;
end else
begin
for x := B.Width downto 1 do
begin
inc( ColorCounts[ Src^ ] );
inc( Src );
end;
N := 256;
end;
end;
M := 0;
for i := 0 to N-1 do
begin
if ColorCounts[i] > ColorCounts[M] then
M := i;
end;
if M > 0 then
begin
C1 := B.DIBPalEntries[0];
C2 := B.DIBPalEntries[M];
Tmp := NewBitmap( 0, 0 );
TRY
Tmp.Assign( B );
B.DIBPalEntries[0] := C2;
B.DIBPalEntries[M] := C1;
Tmp.Draw( B.Canvas.Handle, 0, 0 );
FINALLY
Tmp.Free;
END;
end;
end;
// This version of GenerateBitmapResource provided by Alex Pravdin.
// It does not use brcc32.exe, and creates res-file directly, so
// it is fast and has no restrictions on bitmap format at all.
procedure GenerateBitmapResource( Bitmap: TBitmap; const RsrcName, FileName:
String; var Updated: Boolean; AllowCompression: Boolean );
var
HD1: packed record // First part of RESOURCEHEADER structure before
// Unicode string contained bitmap resource name
DataSize: cardinal;
HeaderSize: cardinal;
NFFFF: word;
DataType: word;
end;
HD2: packed record // Second part of RESOURCEHEADER
DataVersion: cardinal;
MemFlags: word;
PrimaryLang: byte;
SubLang: byte;
Version: cardinal;
Charact: cardinal;
end;
br, hFR, hFtm, DIBLen, WLen, RLen, tm: DWORD;
Buf1, Buf2: PByteArray;
FE: boolean;
Res: String;
Bmp: String;
tmStr: WideString;
KOLBmp: KOL.PBitmap;
KOLPF: KOL.TPixelFormat;
ColorList: KOL.PList;
N, i: Integer;
Mem, MemRLE: KOL.PStream;
begin
asm
jmp @@e_signature
DB '#$signature$#', 0
DB 'GenerateBitmapResource', 0
@@e_signature:
end;
Res := ProjectSourcePath + FileName + '.res';
Bmp := ProjectSourcePath + FileName + '.bmp';
FE := FileExists( Res );
Rpt( 'Generating resource ' + RsrcName, YELLOW );
//Bitmap.SaveToFile( Bmp );
KOLBmp := KOL.NewDIBBitmap( Bitmap.Width, Bitmap.Height, KOL.pf32bit );
BitBlt( KOLBmp.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height,
Bitmap.Canvas.Handle, 0, 0, SRCCOPY );
KOLBmp.HandleType := KOL.bmDIB;
KOLBmp.PixelFormat := KOL.pf32bit;
ColorList := NewList;
TRY
KOLPF := CountSystemColorsUsedInBitmap( KOLBmp, ColorList );
if ColorList.Count > 0 then
begin
KOLBmp.PixelFormat := KOLPF;
KOLBmp.HandleType := KOL.bmDIB;
N := 0;
CASE KOLPF OF
KOL.pf1bit: N := 2;
KOL.pf4bit: N := 16;
KOL.pf8bit: N := 256;
END;
if N > 0 then
begin
for i := 0 to min( ColorList.Count, N )-1 do
begin
KOLBmp.DIBPalEntries[i] := Integer( ColorList.Items[i] );
end;
//
BitBlt( KOLBmp.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height,
Bitmap.Canvas.Handle, 0, 0, SRCCOPY );
//
end;
//KOLBmp.SaveToFile( Bmp );
Mem := NewMemoryStream;
MemRLE := NewMemoryStream;
TRY
if AllowCompression then
KOLBmp.CoreSaveToStream( Mem )
else KOLBmp.SaveToStream( Mem );
if (N > 0) and AllowCompression then
begin
if KOLPF = KOL.pf1bit then
KOLBmp.PixelFormat := KOL.pf4bit;
OptimizeKOLBitmapBeforeRLEEncoding( KOLBmp );
KOLBmp.RLESaveToStream( MemRLE );
end;
if (MemRLE.Size > 0) and (MemRLE.Size < Mem.Size) then
KOL.Swap( Integer( Mem ), Integer( MemRLE ) );
Mem.Position := 0;
Mem.SaveToFile( Bmp, 0, Mem.Size );
FINALLY
Mem.Free;
MemRLE.Free;
END;
end
else
begin
Bitmap.SaveToFile( Bmp );
end;
Rpt( 'Bitmap saved to ' + Bmp, YELLOW );
KOLBmp.Free;
FINALLY
ColorList.Free;
END;
if FE then
begin
DeleteFile( PChar( Res + '_tmp' ) );
CopyFile( PChar(Res), PChar( (Res+'_tmp') ), False );
end;
hFR := CreateFile( PChar(Res), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ,
nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
if hFR = INVALID_HANDLE_VALUE then begin
Rpt( 'Can not create file ' + Res + #13#10'Error: ' + SysErrorMessage( GetLastError ), RED );
Exit;
end;
hFtm := CreateFile( PChar(Bmp), GENERIC_READ, FILE_SHARE_READ, nil,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
DIBLen := GetFileSize( hFtm, nil ) - 14{SizeOf( TBITMAPFILEHEADER )};
WLen := ( Length( RsrcName ) + 1 ) * 2;
HD1.DataSize := DIBLen;
HD1.HeaderSize := 12{SizeOf( HD1 )} + 16{SizeOf( HD2 )} + WLen;
HD1.NFFFF := $FFFF;
HD1.DataType := 2; // RT_BITMAP
HD2.DataVersion := 0;