PageRenderTime 53ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/mckObjs.pas

http://github.com/rofl0r/KOL
Pascal | 2466 lines | 2129 code | 155 blank | 182 comment | 191 complexity | c93219512da4ee8549868c5039b6a414 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. {=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  2. KKKKK KKKKK OOOOOOOOO LLLLL
  3. KKKKK KKKKK OOOOOOOOOOOOO LLLLL
  4. KKKKK KKKKK OOOOO OOOOO LLLLL
  5. KKKKK KKKKK OOOOO OOOOO LLLLL
  6. KKKKKKKKKK OOOOO OOOOO LLLLL
  7. KKKKK KKKKK OOOOO OOOOO LLLLL
  8. KKKKK KKKKK OOOOO OOOOO LLLLL
  9. KKKKK KKKKK OOOOOOOOOOOOO LLLLLLLLLLLLL kkkkk
  10. KKKKK KKKKK OOOOOOOOO LLLLLLLLLLLLL kkkkk
  11. kkkkk
  12. mmmmm mmmmm mmmmmm cccccccccccc kkkkk kkkkk
  13. mmmmmmmm mmmmm mmmmm cccccc ccccc kkkkk kkkkk
  14. mmmmmmmm mmmmm mmmmm cccccc kkkkkkkk
  15. mmmmm mmmmm mmmmm cccccc ccccc kkkkk kkkkk
  16. mmmmm mmmmm mmmmm cccccccccccc kkkkk kkkkk
  17. Key Objects Library (C) 2000 by Kladov Vladimir.
  18. KOL Mirror Classes Kit (C) 2000 by Kladov Vladimir.
  19. }
  20. unit mckObjs;
  21. interface
  22. {$I KOLDEF.INC}
  23. uses KOL, Classes, Forms, Controls, Dialogs, Windows, Messages, extctrls,
  24. stdctrls, comctrls, SysUtils, Graphics, mirror, ShellAPI,
  25. buttons, mckFileFilterEditor,
  26. //////////////////////////////////////////
  27. {$IFDEF _D6orHigher} //
  28. DesignIntf, DesignEditors //
  29. {$ELSE} //
  30. //////////////////////////////////////////
  31. DsgnIntf
  32. //////////////////////////////////////////
  33. {$ENDIF} //
  34. //////////////////////////////////////////
  35. {$IFNDEF _D2} {$IFNDEF _d3}, imglist {$ENDIF} {$ENDIF},
  36. TypInfo, menus;
  37. type
  38. //============================================================================
  39. //---- MIRROR FOR A TIMER ----
  40. //---- ÇÅÐÊÀËÎ ÄËß ÒÀÉÌÅÐÀ ----
  41. TKOLTimer = class(TKOLObj)
  42. private
  43. FEnabled: Boolean;
  44. FInterval: Integer;
  45. FOnTimer: TOnEvent;
  46. FPeriodic: Boolean;
  47. FMultimedia: Boolean;
  48. FResolution: Integer;
  49. procedure SetEnabled(const Value: Boolean);
  50. procedure SetInterval(const Value: Integer);
  51. procedure SetOnTimer(const Value: TOnEvent);
  52. procedure SetMultimedia(const Value: Boolean);
  53. procedure SetPeriodic(const Value: Boolean);
  54. procedure SetResolution(const Value: Integer);
  55. protected
  56. procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String );
  57. override;
  58. procedure AssignEvents( SL: TStringList; const AName: String ); override;
  59. procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String );
  60. override;
  61. public
  62. function TypeName: String; override;
  63. constructor Create( AOwner: TComponent ); override;
  64. published
  65. property Interval: Integer read FInterval write SetInterval;
  66. property Enabled: Boolean read FEnabled write SetEnabled;
  67. property OnTimer: TOnEvent read FOnTimer write SetOnTimer;
  68. property Multimedia: Boolean read FMultimedia write SetMultimedia;
  69. property Resolution: Integer read FResolution write SetResolution;
  70. property Periodic: Boolean read FPeriodic write SetPeriodic;
  71. end;
  72. //============================================================================
  73. //---- MIRROR FOR A THREAD ----
  74. //---- ÇÅÐÊÀËÎ ÄËß ÍÈÒÈ ----
  75. TPriorityClass = ( pcNormal, pcIdle, pcHigh, pcRealTime );
  76. TThreadPriority = ( tpNormal, tpBelowNormal, tpLowest, tpIdle, tpAboveNormal,
  77. tpHighest, tpCritical );
  78. TKOLThread = class(TKOLObj)
  79. private
  80. FPriorityClass: TPriorityClass;
  81. FThreadPriority: TThreadPriority;
  82. FOnExecute: TOnThreadExecute;
  83. FOnSuspend: TObjectMethod;
  84. FOnResume: TOnEvent;
  85. FstartSuspended: Boolean;
  86. F_AutoFree: Boolean;
  87. procedure SetPriorityClass(const Value: TPriorityClass);
  88. procedure SetThreadPriority(const Value: TThreadPriority);
  89. procedure SetOnExecute(const Value: TOnThreadExecute);
  90. procedure SetOnSuspend(const Value: TObjectMethod);
  91. procedure SetOnResume(const Value: TOnEvent);
  92. procedure SetstartSuspended(const Value: Boolean);
  93. procedure SetAutoFree(const Value: Boolean);
  94. protected
  95. procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
  96. procedure AssignEvents( SL: TStringList; const AName: String ); override;
  97. function NotAutoFree: Boolean; override;
  98. function BestEventName: String; override;
  99. public
  100. published
  101. property PriorityClass: TPriorityClass read FPriorityClass write SetPriorityClass;
  102. property ThreadPriority: TThreadPriority read FThreadPriority write SetThreadPriority;
  103. property OnExecute: TOnThreadExecute read FOnExecute write SetOnExecute;
  104. property OnSuspend: TObjectMethod read FOnSuspend write SetOnSuspend;
  105. property OnResume: TOnEvent read FOnResume write SetOnResume;
  106. property startSuspended: Boolean read FstartSuspended write SetstartSuspended;
  107. property AutoFree: Boolean read F_AutoFree write SetAutoFree;
  108. end;
  109. //============================================================================
  110. //---- MIRROR FOR AN IMAGELIST ----
  111. //---- ÇÅÐÊÀËÎ ÄËß ÑÏÈÑÊÀ ÐÈÑÓÍÊÎÂ ----
  112. TKOLImageList = class(TKOLObj)
  113. private
  114. FImgWidth: Integer;
  115. FImgHeight: Integer;
  116. FCount: Integer;
  117. FBitmap: TBitmap;
  118. FSystemImageList: Boolean;
  119. FTransparentColor: TColor;
  120. FColors: TImageListColors;
  121. FMasked: Boolean;
  122. FBkColor: TColor;
  123. procedure SetImgHeight(Value: Integer);
  124. procedure SetImgWidth(Value: Integer);
  125. procedure SetCount(const Value: Integer);
  126. procedure SetBitmap(const Value: TBitmap);
  127. procedure SetSystemImageList(const Value: Boolean);
  128. function GetBitmap: TBitmap;
  129. procedure SetTransparentColor(const Value: TColor);
  130. function GetTransparentColor: TColor;
  131. procedure SetColors(const Value: TImageListColors);
  132. procedure SetMasked(const Value: Boolean);
  133. procedure SetBkColor(const Value: TColor);
  134. function GetImageListHandle: THandle;
  135. procedure AssignBitmapToKOLImgList;
  136. protected
  137. FKOLImgList: PImageList;
  138. procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
  139. procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String );
  140. override;
  141. //procedure BitmapChanged( Sender: TObject );
  142. public
  143. constructor Create( AOwner: TComponent ); override;
  144. destructor Destroy; override;
  145. procedure Clear;
  146. procedure Assign( Value: TPersistent ); override;
  147. property Handle: THandle read GetImageListHandle;
  148. published
  149. property ImgWidth: Integer read FImgWidth write SetImgWidth;
  150. property ImgHeight: Integer read FImgHeight write SetImgHeight;
  151. property Count: Integer read FCount write SetCount;
  152. property bitmap: TBitmap read GetBitmap write SetBitmap;
  153. property TransparentColor: TColor read GetTransparentColor write SetTransparentColor;
  154. property systemimagelist: Boolean read FSystemImageList write SetSystemImageList;
  155. property Colors: TImageListColors read FColors write SetColors;
  156. property Masked: Boolean read FMasked write SetMasked;
  157. property BkColor: TColor read FBkColor write SetBkColor;
  158. end;
  159. TKOLImageListEditor = class(TComponentEditor)
  160. private
  161. protected
  162. public
  163. procedure Edit; override;
  164. procedure ExecuteVerb(Index: Integer); override;
  165. function GetVerb(Index: Integer): string; override;
  166. function GetVerbCount: Integer; override;
  167. end;
  168. //----------------------------------------------------------------------------
  169. //---- MIRROR FOR OPENSAVE FILE DIALOG ----
  170. //---- ÇÅÐÊÀËÎ ÄËß ÄÈÀËÎÃÀ ÂÛÁÎÐÀ ÔÀÉËÀ ----
  171. TKOLOpenSaveDialog = class(TKOLObj)
  172. private
  173. FOptions: TOpenSaveOptions;
  174. FInitialDir: String;
  175. FFilter: String;
  176. FFilterIndex: Integer;
  177. FTitle: String;
  178. FDefExtension: String;
  179. FOpenDialog: Boolean;
  180. FTemplateName: String;
  181. procedure SetOptions(const Value: TOpenSaveOptions);
  182. procedure SetInitialDir(const Value: String);
  183. procedure SetFilter(const Value: String);
  184. procedure SetFilterIndex(const Value: Integer);
  185. procedure SetTitle(const Value: String);
  186. procedure SetDefExtension(const Value: String);
  187. procedure SetOpenDialog(const Value: Boolean);
  188. procedure SetTemplateName(const Value: String);
  189. protected
  190. procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
  191. procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
  192. public
  193. constructor Create( AOwner: TComponent ); override;
  194. published
  195. property Options: TOpenSaveOptions read FOptions write SetOptions;
  196. property Title: String read FTitle write SetTitle;
  197. property TemplateName: String read FTemplateName write SetTemplateName;
  198. property InitialDir: String read FInitialDir write SetInitialDir;
  199. property Filter: String read FFilter write SetFilter;
  200. property FilterIndex: Integer read FFilterIndex write SetFilterIndex;
  201. property DefExtension: String read FDefExtension write SetDefExtension;
  202. property OpenDialog: Boolean read FOpenDialog write SetOpenDialog;
  203. property Localizy;
  204. end;
  205. TKOLFileFilter = class( TStringProperty )
  206. private
  207. protected
  208. public
  209. function GetAttributes: TPropertyAttributes; override;
  210. procedure Edit; override;
  211. end;
  212. //----------------------------------------------------------------------------
  213. //---- MIRROR FOR OPENDIR DIALOG ----
  214. //---- ÇÅÐÊÀËÎ ÄËß ÄÈÀËÎÃÀ ÂÛÁÎÐÀ ÄÈÐÅÊÒÎÐÈß ----
  215. TKOLOpenDirDialog = class( TKOLObj )
  216. private
  217. FTitle: String;
  218. FOptions: TOpenDirOptions;
  219. FInitialPath: String;
  220. FCenterOnScreen: Boolean;
  221. FOnSelChanged: TOnODSelChange;
  222. procedure SetTitle(const Value: String);
  223. procedure SetOptions(const Value: TOpenDirOptions);
  224. procedure SetInitialPath(const Value: String);
  225. procedure SetCenterOnScreen(const Value: Boolean);
  226. procedure SetOnSelChanged(const Value: TOnODSelChange);
  227. protected
  228. procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
  229. procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
  230. procedure AssignEvents( SL: TStringList; const AName: String ); override;
  231. public
  232. constructor Create( AOwner: TComponent ); override;
  233. published
  234. property Title: String read FTitle write SetTitle;
  235. property Options: TOpenDirOptions read FOptions write SetOptions;
  236. property InitialPath: String read FInitialPath write SetInitialPath;
  237. property CenterOnScreen: Boolean read FCenterOnScreen write SetCenterOnScreen;
  238. property OnSelChanged: TOnODSelChange read FOnSelChanged write SetOnSelChanged;
  239. property Localizy;
  240. end;
  241. //----------------------------------------------------------------------------
  242. //---- MIRROR FOR COLOR CHOOSING DIALOG ----
  243. //---- ÇÅÐÊÀËÎ ÄËß ÄÈÀËÎÃÀ ÂÛÁÎÐÀ ÖÂÅÒÀ ----
  244. TKOLColorDialog = class( TKOLObj )
  245. private
  246. FColorCustomOption: TColorCustomOption;
  247. FCustomColors: array[ 1..16 ] of TColor;
  248. procedure SetColorCustomOption(const Value: TColorCustomOption);
  249. function GetCustomColor( const Index: Integer ): TColor;
  250. procedure SetCustomColor(const Index: Integer; const Value: TColor);
  251. protected
  252. procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
  253. public
  254. constructor Create( AOwner: TComponent ); override;
  255. published
  256. property ColorCustomOption: TColorCustomOption read FColorCustomOption write SetColorCustomOption;
  257. property CustomColor1: TColor index 1 read GetCustomColor write SetCustomColor;
  258. property CustomColor2: TColor index 2 read GetCustomColor write SetCustomColor;
  259. property CustomColor3: TColor index 3 read GetCustomColor write SetCustomColor;
  260. property CustomColor4: TColor index 4 read GetCustomColor write SetCustomColor;
  261. property CustomColor5: TColor index 5 read GetCustomColor write SetCustomColor;
  262. property CustomColor6: TColor index 6 read GetCustomColor write SetCustomColor;
  263. property CustomColor7: TColor index 7 read GetCustomColor write SetCustomColor;
  264. property CustomColor8: TColor index 8 read GetCustomColor write SetCustomColor;
  265. property CustomColor9: TColor index 9 read GetCustomColor write SetCustomColor;
  266. property CustomColor10: TColor index 10 read GetCustomColor write SetCustomColor;
  267. property CustomColor11: TColor index 11 read GetCustomColor write SetCustomColor;
  268. property CustomColor12: TColor index 12 read GetCustomColor write SetCustomColor;
  269. property CustomColor13: TColor index 13 read GetCustomColor write SetCustomColor;
  270. property CustomColor14: TColor index 14 read GetCustomColor write SetCustomColor;
  271. property CustomColor15: TColor index 15 read GetCustomColor write SetCustomColor;
  272. property CustomColor16: TColor index 16 read GetCustomColor write SetCustomColor;
  273. end;
  274. //----------------------------------------------------------------------------
  275. //---- MIRROR FOR TRAY ICON ----
  276. //---- ÇÅÐÊÀËÎ ÄËß ÈÊÎÍÊÈ Â ÒÐÅÅ ----
  277. TKOLTrayIcon = class( TKOLObj )
  278. private
  279. FIcon: TIcon;
  280. FActive: Boolean;
  281. FTooltip: String;
  282. FAutoRecreate: Boolean;
  283. FOnMouse: TOnTrayIconMouse;
  284. FNoAutoDeactivate: Boolean;
  285. procedure SetIcon(const Value: TIcon);
  286. procedure SetActive(const Value: Boolean);
  287. procedure SetTooltip(const Value: String);
  288. procedure SetAutoRecreate(const Value: Boolean);
  289. procedure SetOnMouse(const Value: TOnTrayIconMouse);
  290. procedure SetNoAutoDeactivate(const Value: Boolean);
  291. protected
  292. procedure SetupFirst( SL: TStringList; const AName, AParent, Prefix: String ); override;
  293. procedure SetupLast( SL: TStringList; const AName, AParent, Prefix: String ); override;
  294. procedure AssignEvents( SL: TStringList; const AName: String ); override;
  295. public
  296. constructor Create( AOwner: TComponent ); override;
  297. destructor Destroy; override;
  298. published
  299. property Icon: TIcon read FIcon write SetIcon;
  300. property Active: Boolean read FActive write SetActive;
  301. property NoAutoDeactivate: Boolean read FNoAutoDeactivate write SetNoAutoDeactivate;
  302. property Tooltip: String read FTooltip write SetTooltip;
  303. property AutoRecreate: Boolean read FAutoRecreate write SetAutoRecreate;
  304. property OnMouse: TOnTrayIconMouse read FOnMouse write SetOnMouse;
  305. property Localizy;
  306. end;
  307. type KOLTPixelFormat = KOL.TPixelFormat;
  308. function CountSystemColorsUsedInBitmap( Bmp: KOL.PBitmap ): KOLTPixelFormat;
  309. //function SaveBitmap( Bitmap: TBitmap; const Path: String ): Boolean;
  310. procedure GenerateBitmapResource( Bitmap: TBitmap; const RsrcName, FileName: String;
  311. var Updated: Boolean );
  312. procedure GenerateIconResource( Icon: TIcon; const RsrcName, FileName: String;
  313. var Updated: Boolean );
  314. procedure RemoveSelection( FD: IFormDesigner );
  315. function String2Pascal( S: String ): String;
  316. //function GetBmpPixel( Bitmap: TBitmap; X, Y: Integer ): TColor;
  317. procedure Register;
  318. implementation
  319. procedure Register;
  320. begin
  321. RegisterComponents( 'KOL', [ TKOLTimer, TKOLThread, TKOLImageList, TKOLMainMenu, TKOLPopupMenu,
  322. TKOLOpenSaveDialog, TKOLOpenDirDialog, TKOLColorDialog,
  323. TKOLTrayIcon ] );
  324. RegisterComponentEditor( TKOLImageList, TKOLImageListEditor );
  325. RegisterPropertyEditor( TypeInfo( String ), TKOLOpenSaveDialog, 'Filter',
  326. TKOLFileFilter );
  327. RegisterPropertyEditor( TypeInfo( TOnODSelChange ), TKOLOpenDirDialog, 'OnSelChanged', TKOLOnEventPropEditor );
  328. RegisterPropertyEditor( TypeInfo( TOnTrayIconMouse ), nil, '', TKOLOnEventPropEditor );
  329. end;
  330. function String2Pascal( S: String ): String;
  331. begin
  332. asm
  333. jmp @@e_signature
  334. DB '#$signature$#', 0
  335. DB 'String2Pascal', 0
  336. @@e_signature:
  337. end;
  338. if Length( S ) > 0 then
  339. begin
  340. Result := '';
  341. while S <> '' do
  342. begin
  343. if Result <> '' then
  344. Result := Result + ' + ';
  345. Result := Result + String2PascalStrExpr( Copy( S, 1, 255 ) );
  346. S := Copy( S, 256, MaxInt );
  347. end;
  348. end
  349. else
  350. Result := '''''';
  351. end;
  352. procedure RemoveSelection( FD: IFormDesigner );
  353. {$IFDEF _D2orD3}
  354. var L: TComponentList;
  355. {$ENDIF}
  356. begin
  357. asm
  358. jmp @@e_signature
  359. DB '#$signature$#', 0
  360. DB 'RemoveSelection', 0
  361. @@e_signature:
  362. end;
  363. try
  364. {$IFDEF _D5orHigher}
  365. FD.NoSelection;
  366. {$ELSE}
  367. {$IFDEF _D2orD3}
  368. L := TComponentList.Create;
  369. FD.SetSelections( L );
  370. L.Free;
  371. {$ELSE _D4}
  372. FD.SetSelections( nil );
  373. {$ENDIF}
  374. {$ENDIF}
  375. except
  376. Rpt( '*/\* EXCEPTION - Could not remove current selection' );
  377. end;
  378. end;
  379. function ColorsAreSystem16( ColorList: PList ): Boolean;
  380. const SysColors: array[ 0..15 ] of TColor = ( 0, $800000, $8000, $808000, $80,
  381. $800080, $8080, $808080, $C0C0C0, $FF0000, $FF00, $FFFF00, $FF, $FF00FF,
  382. $FFFF, $FFFFFF );
  383. var I, J: Integer;
  384. C: TColor;
  385. Found: Boolean;
  386. begin
  387. Result := TRUE;
  388. for I := 0 to ColorList.Count-1 do
  389. begin
  390. C := TColor( ColorList.Items[ I ] );
  391. Found := FALSE;
  392. for J := 0 to 15 do
  393. if SysColors[ J ] = C then
  394. begin
  395. Found := TRUE;
  396. break;
  397. end;
  398. if not Found then
  399. begin
  400. Rpt( '***** Color ' + Int2Hex( C, 8 ) + ' not found in system 16 colors' );
  401. Result := FALSE;
  402. Exit;
  403. end;
  404. end;
  405. end;
  406. function ColorsAreSystem256( ColorList: PList ): Boolean;
  407. const SysColors8bit: array[ 0..255 ] of DWORD = ( $000000,
  408. $C0DCC0, $800000, $808000, $008000, $008080, $000080, $800080, $808080,
  409. $00FF00, $0000FF, $00FFFF, $C0DCC0, $000040, $400040, $000000, $A0A0A4,
  410. $C0C0C0, $C0DCC0, $FFFBF0, $FFFBF0, $FFFBF0, $FFFBF0, $FFFFFF, $FF0000,
  411. $FFFF00, $FF00FF, $FFFFFF, $A6CAF0, $402000, $004040, $202040, $202040,
  412. $606040, $404040, $E08080, $E00080, $C0DCC0, $A0A0A4, $800000, $C02000,
  413. $404000, $A04000, $E04000, $406000, $A06000, $E06000, $40A000, $202040,
  414. $404040, $404040, $E06040, $A6CAF0, $C0DCC0, $40E000, $800000, $004000,
  415. $604000, $C04000, $006000, $606000, $C06000, $00A000, $60A000, $A0A000,
  416. $E0A000, $40C000, $A0C000, $E0C000, $A0E000, $00E040, $600040, $C00040,
  417. $0000FF, $604040, $C04040, $006040, $606040, $C06040, $00A040, $C0A000,
  418. $00C000, $60C000, $C0C000, $60E000, $C0E000, $0000FF, $A00040, $E00040,
  419. $404040, $A04040, $E04040, $406040, $A06040, $E06040, $40A040, $60A040,
  420. $C0A040, $00C040, $60C040, $C0C040, $40E040, $A0E040, $E0E040, $400080,
  421. $A00080, $E00080, $404080, $A04080, $E04080, $406080, $A06080, $A0A040,
  422. $E0A040, $40C040, $A0C040, $E0C040, $60E040, $C0E040, $000080, $600080,
  423. $C00080, $004080, $604080, $C04080, $006080, $606080, $C06080, $00A080,
  424. $A0C080, $E0C080, $40E080, $C0E080, $FF00FF, $A04080, $C00080, $404080,
  425. $C04080, $006080, $604080, $C06080, $40A080, $A0A0A4, $E0A080, $40C080,
  426. $C0C080, $00E080, $A0E080, $E000C0, $00A080, $A00080, $000080, $600080,
  427. $E00080, $406080, $A06080, $E04080, $60A080, $C0A080, $00C080, $40C080,
  428. $A0C080, $E0C080, $40E080, $A0E080, $E0E080, $400080, $A000C0, $004080,
  429. $6040C0, $C040C0, $0060C0, $606080, $C060C0, $00A0C0, $60A0C0, $60C080,
  430. $C0C080, $00E080, $60C080, $C0E080, $0000C0, $6000C0, $C000C0, $4040C0,
  431. $A040C0, $E040C0, $4060C0, $A060C0, $E06080, $40A0C0, $A0A0C0, $C0A0C0,
  432. $00A0C0, $60A0C0, $C0A0C0, $00C0C0, $60C0C0, $C0C0C0, $00FFFF, $60E080,
  433. $C0DCC0, $4000C0, $A000C0, $4040C0, $A040C0, $FF00FF, $4060C0, $E0A0C0,
  434. $40A0C0, $A0A0C0, $E0A0C0, $40C0C0, $A0C0C0, $E0A0C0, $40C0C0, $C0DCC0,
  435. $FFFBF0, $6000C0, $0040C0, $6040C0, $C040C0, $0060C0, $6060C0, $A060C0,
  436. $E060C0, $40A0C0, $A6CAF0, $E0A0C0, $40C0C0, $A6CAF0, $FFFBF0, $60C0C0,
  437. $FFFFFF, $60E080, $6060C0, $A6CAF0, $606040, $808080, $C0C0C0, $C060C0,
  438. $00A0C0, $60A0C0, $A6CAF0, $00FFFF, $60C0C0, $A6CAF0, $00FFFF, $A6CAF0,
  439. $E06080, $E0E080, $E060C0, $A00040, $808080, $A0A0A4, $C0C0C0 );
  440. var I, J: Integer;
  441. C: DWORD;
  442. begin
  443. Result := FALSE;
  444. for I := 0 to ColorList.Count-1 do
  445. begin
  446. C := DWORD( ColorList.Items[ I ] );
  447. for J := 0 to 255 do
  448. begin
  449. if SysColors8bit[ J ] = C then
  450. begin
  451. C := 0;
  452. break;
  453. end;
  454. end;
  455. if C <> 0 then
  456. begin
  457. Rpt( '~~~ color not found: ' + Int2Hex( C, 6 ) );
  458. Exit;
  459. end;
  460. end;
  461. Result := TRUE;
  462. end;
  463. function ColorsAre64K( ColorList: PList ): Boolean;
  464. var I: Integer;
  465. C: DWORD;
  466. begin
  467. Result := FALSE;
  468. for I := 0 to ColorList.Count-1 do
  469. begin
  470. C := DWORD( ColorList.Items[ I ] );
  471. if (C and $E0C0E0) <> C then
  472. begin
  473. Rpt( '~~~ color not found: ' + Int2Hex( C, 6 ) );
  474. Exit;
  475. end;
  476. end;
  477. Result := TRUE;
  478. end;
  479. function CountSystemColorsUsedInBitmap( Bmp: KOL.PBitmap ): KOL.TPixelFormat;
  480. var Y, X: Integer;
  481. L: PDWORD;
  482. ColorList: KOL.PList;
  483. C: TColor;
  484. R, G, B: Byte;
  485. begin
  486. ColorList := NewList;
  487. ColorList.Capacity := 65537;
  488. TRY
  489. for Y := 0 to Bmp.Height - 1 do
  490. begin
  491. L := Bmp.ScanLine[ Y ];
  492. for X := 0 to Bmp.Width - 1 do
  493. begin
  494. C := L^ and $FFFFFF;
  495. if (C and $E0C0E0) <> C then
  496. begin
  497. R := C and $FF;
  498. G := (C and $FF00) shr 8;
  499. B := C shr 16;
  500. if ((R and $E0) <> R) and (R <> $FF) or
  501. ((G and $C0) <> G) and (G <> $FF) or
  502. ((B and $E0) <> B) and (B <> $FF) then
  503. begin
  504. Result := KOL.pf24bit;
  505. Rpt( '~~~ color not found: ' + Int2Hex( C, 6 ) );
  506. Exit;
  507. end;
  508. end;
  509. if ColorList.IndexOf( Pointer( C ) ) < 0 then
  510. begin
  511. ColorList.Add( Pointer( C ) );
  512. if ColorList.Count > 65536 then
  513. begin
  514. Result := KOL.pf24bit;
  515. Rpt( '~~~~~ pf24bit (break) ~~~~~ (' + Int2Str( ColorList.Count ) + ')' );
  516. Exit;
  517. end;
  518. end;
  519. Inc( L );
  520. end;
  521. end;
  522. //Rpt( '------ Colors in bitmap: ' + Int2Str( ColorList.Count ) );
  523. if (ColorList.Count <= 2) and
  524. ((ColorList.Count = 0) or
  525. (ColorList.Count > 0) and (DWORD(ColorList.Items[ 0 ]) and $FFFFFF = $FFFFFF) and
  526. ((ColorList.Count < 2) or
  527. (ColorList.Count = 2) and (DWORD( ColorList.Items[ 1 ] ) and $FFFFFF = 0) )) then
  528. begin
  529. Result := KOL.pf1bit;
  530. Rpt( '~~~~~ pf1bit ~~~~~' );
  531. end else if (ColorList.Count <= 16) and ColorsAreSystem16( ColorList ) then
  532. begin
  533. Result := KOL.pf4bit;
  534. Rpt( '~~~~~ pf4bit ~~~~~' );
  535. end else if (ColorList.Count <= 256) and ColorsAreSystem256( ColorList ) then
  536. begin
  537. Result := KOL.pf8bit;
  538. Rpt( '~~~~~ pf8bit ~~~~~' );
  539. end else if (ColorList.Count <= 65536) and ColorsAre64K( ColorList ) then
  540. begin
  541. Result := KOL.pf16bit;
  542. Rpt( '~~~~~ pf16bit ~~~~~' );
  543. end
  544. else
  545. begin
  546. Result := KOL.pf24bit;
  547. Rpt( '~~~~~ pf24bit ~~~~~ (' + Int2Str( ColorList.Count ) + ')' );
  548. end;
  549. FINALLY
  550. ColorList.Free;
  551. END;
  552. end;
  553. {$IFDEF _D2}
  554. procedure GenerateBitmapResource( Bitmap: TBitmap; const RsrcName, FileName: String;
  555. var Updated: Boolean );
  556. var RL: TStringList;
  557. Buf1, Buf2: PChar;
  558. I, J: Integer;
  559. F: THandle;
  560. S: String;
  561. KOLBmp: KOL.PBitmap;
  562. begin
  563. asm
  564. jmp @@e_signature
  565. DB '#$signature$#', 0
  566. DB 'GenerateBitmapResource', 0
  567. @@e_signature:
  568. end;
  569. KOLBmp := NewDIBBitmap( Bitmap.Width, Bitmap.Height, KOL.pf32bit );
  570. BitBlt( KOLBmp.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height,
  571. Bitmap.Canvas.Handle, 0, 0, SRCCOPY );
  572. KOLBmp.HandleType := KOL.bmDIB;
  573. KOLBmp.PixelFormat := KOL.pf32bit;
  574. KOLBmp.PixelFormat := CountSystemColorsUsedInBitmap( KOLBmp );
  575. KOLBmp.SaveToFile( ProjectSourcePath + FileName + '.bmp' );
  576. Buf1 := nil;
  577. Buf2 := nil;
  578. I := 0;
  579. J := 0;
  580. S := ProjectSourcePath + FileName + '.res';
  581. if FileExists( S ) then
  582. begin
  583. I := FileSize( S );
  584. if I > 0 then
  585. begin
  586. GetMem( Buf1, I );
  587. F := KOL.FileCreate( S, ofOpenRead or ofShareDenyWrite or ofOpenExisting );
  588. if F <> THandle( -1 ) then
  589. begin
  590. KOL.FileRead( F, Buf1^, I );
  591. KOL.FileClose( F );
  592. end;
  593. end;
  594. end;
  595. RL := TStringList.Create;
  596. RL.Add( UpperCase( RsrcName ) + ' BITMAP "' + FileName + '.bmp"' );
  597. RL.SaveToFile( ProjectSourcePath + FileName + '.rc' );
  598. RL.Free;
  599. if not FileExists( ProjectSourcePath + FileName + '.rc' ) then
  600. begin
  601. ShowMessage( 'Can not save file: ' + ProjectSourcePath + FileName + '.rc' );
  602. Exit;
  603. end;
  604. {ShellExecute( 0, 'open', PChar( ExtractFilePath( Application.ExeName ) + 'brcc32.exe' ),
  605. PChar( ProjectSourcePath + FileName + '.rc' ), PChar( ProjectSourcePath ),
  606. SW_HIDE );}
  607. Rpt( 'Compiling resource ' + ProjectSourcePath + FileName + '.rc' );
  608. if not ExecuteWait( ExtractFilePath( Application.ExeName ) + 'brcc32.exe',
  609. '"' + ProjectSourcePath + FileName + '.rc"',
  610. ProjectSourcePath, SW_HIDE, INFINITE, nil ) then
  611. begin
  612. Rpt( 'Can not compile resource with ' + ExtractFilePath( Application.ExeName ) + 'brcc32.exe' );
  613. end;
  614. if FileExists( S ) then
  615. begin
  616. J := FileSize( S );
  617. if J > 0 then
  618. begin
  619. GetMem( Buf2, J );
  620. F := KOL.FileCreate( S, ofOpenRead or ofShareDenyWrite or ofOpenExisting );
  621. if F <> THandle( -1 ) then
  622. begin
  623. KOL.FileRead( F, Buf2^, J );
  624. KOL.FileClose( F );
  625. end;
  626. end;
  627. end;
  628. if (Buf1 = nil) or (I <> J) or
  629. (Buf2 <> nil) and not CompareMem( Buf1, Buf2, J ) then
  630. begin
  631. Rpt( 'Resource ' + FileName + ' changed.' );
  632. Updated := TRUE;
  633. end;
  634. if Buf1 <> nil then FreeMem( Buf1 );
  635. if Buf2 <> nil then FreeMem( Buf2 );
  636. end;
  637. {$ELSE not _D2}
  638. // This version of GenerateBitmapResource provided by Alex Pravdin.
  639. // It does not use brcc32.exe, and creates res-file directly, so
  640. // it is fast and has no restrictions on bitmap format at all.
  641. procedure GenerateBitmapResource( Bitmap: TBitmap; const RsrcName, FileName:
  642. String; var Updated: Boolean );
  643. var
  644. HD1: packed record // First part of RESOURCEHEADER structure before
  645. // Unicode string contained bitmap resource name
  646. DataSize: cardinal;
  647. HeaderSize: cardinal;
  648. NFFFF: word;
  649. DataType: word;
  650. end;
  651. HD2: packed record // Second part of RESOURCEHEADER
  652. DataVersion: cardinal;
  653. MemFlags: word;
  654. PrimaryLang: byte;
  655. SubLang: byte;
  656. Version: cardinal;
  657. Charact: cardinal;
  658. end;
  659. br, hFR, hFtm, DIBLen, WLen, RLen, tm: DWORD;
  660. Buf1, Buf2: PByteArray;
  661. FE: boolean;
  662. Res, Bmp: string;
  663. tmStr: WideString;
  664. KOLBmp: KOL.PBitmap;
  665. KOLPF: KOL.TPixelFormat;
  666. begin
  667. asm
  668. jmp @@e_signature
  669. DB '#$signature$#', 0
  670. DB 'GenerateBitmapResource', 0
  671. @@e_signature:
  672. end;
  673. Res := ProjectSourcePath + FileName + '.res';
  674. Bmp := ProjectSourcePath + FileName + '.bmp';
  675. FE := FileExists( Res );
  676. //Bitmap.SaveToFile( Bmp );
  677. KOLBmp := KOL.NewDIBBitmap( Bitmap.Width, Bitmap.Height, KOL.pf32bit );
  678. BitBlt( KOLBmp.Canvas.Handle, 0, 0, Bitmap.Width, Bitmap.Height,
  679. Bitmap.Canvas.Handle, 0, 0, SRCCOPY );
  680. KOLBmp.HandleType := KOL.bmDIB;
  681. KOLBmp.PixelFormat := KOL.pf32bit;
  682. KOLPF := CountSystemColorsUsedInBitmap( KOLBmp );
  683. KOLBmp.PixelFormat := KOLPF;
  684. KOLBmp.SaveToFile( Bmp );
  685. KOLBmp.Free;
  686. if FE then
  687. begin
  688. DeleteFile( PChar( Res + '_tmp' ) );
  689. CopyFile( PChar(Res), PChar( (Res+'_tmp') ), False );
  690. end;
  691. hFR := CreateFile( PChar(Res), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ,
  692. nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 );
  693. if hFR = INVALID_HANDLE_VALUE then begin
  694. Rpt( 'Can not create file ' + Res + #13#10'Error: ' + SysErrorMessage( GetLastError ) );
  695. Exit;
  696. end;
  697. hFtm := CreateFile( PChar(Bmp), GENERIC_READ, FILE_SHARE_READ, nil,
  698. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
  699. DIBLen := GetFileSize( hFtm, nil ) - 14{SizeOf( TBITMAPFILEHEADER )};
  700. WLen := ( Length( RsrcName ) + 1 ) * 2;
  701. HD1.DataSize := DIBLen;
  702. HD1.HeaderSize := 12{SizeOf( HD1 )} + 16{SizeOf( HD2 )} + WLen;
  703. HD1.NFFFF := $FFFF;
  704. HD1.DataType := 2; // RT_BITMAP
  705. HD2.DataVersion := 0;
  706. HD2.MemFlags := 0;
  707. HD2.PrimaryLang := LANG_NEUTRAL;
  708. HD2.SubLang := SUBLANG_DEFAULT;
  709. HD2.Version := 0;
  710. HD2.Charact := 0;
  711. RLen := HD1.HeaderSize + DIBLen + 32;
  712. GetMem( Buf1, RLen );
  713. FillChar( Buf1[0], RLen, 0 );
  714. Buf1[4]:=$20; Buf1[8]:=$FF; Buf1[9]:=$FF; Buf1[12]:=$FF; Buf1[13]:=$FF;
  715. tmStr := UpperCase( RsrcName ) + #0;
  716. CopyMemory( @Buf1[32], @HD1, 12 );
  717. CopyMemory( @Buf1[32+12], @tmStr[1], WLen );
  718. CopyMemory( @Buf1[32+12+WLen], @HD2, 16 );
  719. SetFilePointer( hFtm, 14{SizeOf( TBITMAPFILEHEADER )}, nil, FILE_BEGIN);
  720. ReadFile( hFtm, Buf1[32+12+16+WLen], DIBLen, br, nil );
  721. WriteFile( hFR, Buf1[0], RLen, br, nil );
  722. CloseHandle( hFtm );
  723. CloseHandle( hFR );
  724. DeleteFile( Bmp );
  725. if FE then begin
  726. hFtm := CreateFile( PChar( (Res+'_tmp') ), GENERIC_READ,
  727. FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 );
  728. tm := GetFileSize( hFtm, nil );
  729. GetMem( Buf2, tm );
  730. ReadFile( hFtm, Buf2[0], tm, br, nil );
  731. CloseHandle( hFtm );
  732. DeleteFile( Res + '_tmp' );
  733. if ( RLen <> tm ) or (not CompareMem( @Buf1[0], @Buf2[0], Min( RLen,
  734. tm ) )) then begin
  735. Rpt( 'Resource ' + Res + ' changed.' );
  736. Updated := True;
  737. end;
  738. FreeMem( Buf2 );
  739. end;
  740. FreeMem( Buf1 );
  741. end;
  742. {$ENDIF}
  743. function SaveIcon( Icon: TIcon; const Path: String ): Boolean;
  744. var MS, MS2: TMemoryStream;
  745. begin
  746. asm
  747. jmp @@e_signature
  748. DB '#$signature$#', 0
  749. DB 'SaveIcon', 0
  750. @@e_signature:
  751. end;
  752. Result := TRUE;
  753. MS := TMemoryStream.Create;
  754. MS2 := TMemoryStream.Create;
  755. try
  756. Icon.SaveToStream( MS );
  757. if FileExists( Path ) then
  758. begin
  759. MS2.LoadFromFile( Path );
  760. if (MS.Size = MS2.Size) and CompareMem( MS.Memory, MS2.Memory, MS.Size ) then
  761. Exit;
  762. if FileExists( Path + '.$$$' ) then
  763. DeleteFile( Path + '.$$$' );
  764. MoveFile( PChar( Path ), PChar( Path + '.$$$' ) );
  765. end;
  766. MS.Position := 0;
  767. MS.SaveToFile( Path );
  768. //Result := True;
  769. //Rpt( 'Icon stored to ' + Path );
  770. finally
  771. MS.Free;
  772. MS2.Free;
  773. end;
  774. end;
  775. procedure GenerateIconResource( Icon: TIcon; const RsrcName, FileName: String;
  776. var Updated: Boolean );
  777. var RL: TStringList;
  778. Buf1, Buf2: PChar;
  779. S: String;
  780. I, J: Integer;
  781. F: THandle;
  782. begin
  783. asm
  784. jmp @@e_signature
  785. DB '#$signature$#', 0
  786. DB 'GenerateIconResource', 0
  787. @@e_signature:
  788. end;
  789. {if not SaveIcon( Icon, ProjectSourcePath + FileName + '.ico' )
  790. and FileExists( ProjectSourcePath + FileName + '.res' ) then Exit;}
  791. if not SaveIcon( Icon, ProjectSourcePath + FileName + '.ico' ) then
  792. Exit;
  793. RL := TStringList.Create;
  794. RL.Add( UpperCase( RsrcName ) + ' ICON "' + FileName + '.ico"' );
  795. RL.SaveToFile( ProjectSourcePath + FileName + '.rc' );
  796. RL.Free;
  797. Buf1 := nil;
  798. Buf2 := nil;
  799. I := 0; J := 0;
  800. S := ProjectSourcePath + FileName + '.res';
  801. if FileExists( S ) then
  802. begin
  803. I := FileSize( S );
  804. if I > 0 then
  805. begin
  806. GetMem( Buf1, I );
  807. F := KOL.FileCreate( S, ofOpenRead or ofShareDenyWrite or ofOpenExisting );
  808. if F <> THandle( -1 ) then
  809. begin
  810. KOL.FileRead( F, Buf1^, I );
  811. KOL.FileClose( F );
  812. end;
  813. end;
  814. end;
  815. {ShellExecute( 0, 'open', PChar( ExtractFilePath( Application.ExeName ) + 'brcc32.exe' ),
  816. PChar( ProjectSourcePath + FileName + '.rc' ), PChar( ProjectSourcePath ),
  817. SW_HIDE );}
  818. ExecuteWait( ExtractFilePath( Application.ExeName ) + 'brcc32.exe',
  819. '"' + ProjectSourcePath + FileName + '.rc"',
  820. ProjectSourcePath, SW_HIDE, INFINITE, nil );
  821. if FileExists( S ) then
  822. begin
  823. J := FileSize( S );
  824. if J > 0 then
  825. begin
  826. GetMem( Buf2, J );
  827. F := KOL.FileCreate( S, ofOpenRead or ofShareDenyWrite or ofOpenExisting );
  828. if F <> THandle( -1 ) then
  829. begin
  830. KOL.FileRead( F, Buf2^, J );
  831. KOL.FileClose( F );
  832. end;
  833. end;
  834. end;
  835. if (Buf1 = nil) or (I <> J) or
  836. (Buf2 <> nil) and not CompareMem( Buf1, Buf2, J ) then
  837. begin
  838. Updated := TRUE;
  839. end;
  840. if Buf1 <> nil then FreeMem( Buf1 );
  841. if Buf2 <> nil then FreeMem( Buf2 );
  842. end;
  843. { TKOLTimer }
  844. procedure TKOLTimer.AssignEvents(SL: TStringList; const AName: String);
  845. begin
  846. asm
  847. jmp @@e_signature
  848. DB '#$signature$#', 0
  849. DB 'TKOLTimer.AssignEvents', 0
  850. @@e_signature:
  851. end;
  852. inherited;
  853. DoAssignEvents( SL, AName, [ 'OnTimer' ], [ @OnTimer ] );
  854. end;
  855. constructor TKOLTimer.Create(AOwner: TComponent);
  856. begin
  857. asm
  858. jmp @@e_signature
  859. DB '#$signature$#', 0
  860. DB 'TKOLTimer.Create', 0
  861. @@e_signature:
  862. end;
  863. inherited;
  864. fInterval := 1000;
  865. fEnabled := True;
  866. FPeriodic := TRUE;
  867. FResolution := 0;
  868. end;
  869. procedure TKOLTimer.SetEnabled(const Value: Boolean);
  870. begin
  871. asm
  872. jmp @@e_signature
  873. DB '#$signature$#', 0
  874. DB 'TKOLTimer.SetEnabled', 0
  875. @@e_signature:
  876. end;
  877. FEnabled := Value;
  878. Change;
  879. end;
  880. procedure TKOLTimer.SetInterval(const Value: Integer);
  881. begin
  882. asm
  883. jmp @@e_signature
  884. DB '#$signature$#', 0
  885. DB 'TKOLTimer.SetInterval', 0
  886. @@e_signature:
  887. end;
  888. FInterval := Value;
  889. Change;
  890. end;
  891. procedure TKOLTimer.SetMultimedia(const Value: Boolean);
  892. begin
  893. FMultimedia := Value;
  894. Change;
  895. end;
  896. procedure TKOLTimer.SetOnTimer(const Value: TOnEvent);
  897. begin
  898. asm
  899. jmp @@e_signature
  900. DB '#$signature$#', 0
  901. DB 'TKOLTimer.SetOnTimer', 0
  902. @@e_signature:
  903. end;
  904. FOnTimer := Value;
  905. Change;
  906. end;
  907. procedure TKOLTimer.SetPeriodic(const Value: Boolean);
  908. begin
  909. FPeriodic := Value;
  910. Change;
  911. end;
  912. procedure TKOLTimer.SetResolution(const Value: Integer);
  913. begin
  914. FResolution := Value;
  915. Change;
  916. end;
  917. procedure TKOLTimer.SetupFirst(SL: TStringList; const AName,
  918. AParent, Prefix: String);
  919. begin
  920. asm
  921. jmp @@e_signature
  922. DB '#$signature$#', 0
  923. DB 'TKOLTimer.SetupFirst', 0
  924. @@e_signature:
  925. end;
  926. if Multimedia then
  927. begin
  928. SL.Add( Prefix + AName + ' := NewMMTimer( ' + IntToStr( Interval ) + ' );' );
  929. if not Periodic then
  930. SL.Add( Prefix + 'PMMTimer(' + AName + ').Periodic := FALSE;' );
  931. if Resolution > 0 then
  932. SL.Add( Prefix + 'PMMTimer(' + AName + ').Resolution := ' + IntToStr( Resolution ) + ';' );
  933. end
  934. else
  935. SL.Add( Prefix + AName + ' := NewTimer( ' + IntToStr( Interval ) + ' );' );
  936. //AssignEvents( SL, AName );
  937. GenerateTag( SL, AName, Prefix );
  938. end;
  939. procedure TKOLTimer.SetupLast(SL: TStringList; const AName,
  940. AParent, Prefix: String);
  941. begin
  942. asm
  943. jmp @@e_signature
  944. DB '#$signature$#', 0
  945. DB 'TKOLTimer.SetupLast', 0
  946. @@e_signature:
  947. end;
  948. if Enabled then
  949. SL.Add( Prefix + AName + '.Enabled := True;' );
  950. end;
  951. function TKOLTimer.TypeName: String;
  952. begin
  953. if Multimedia then Result := 'TMMTimer'
  954. else Result := inherited TypeName;
  955. end;
  956. { TKOLImageList }
  957. procedure TKOLImageList.Assign(Value: TPersistent);
  958. var IL: TKOLImageList;
  959. begin
  960. asm
  961. jmp @@e_signature
  962. DB '#$signature$#', 0
  963. DB 'TKOLImageList.Assign', 0
  964. @@e_signature:
  965. end;
  966. if (Value <> nil) and (Value is TKOLImageList) then
  967. begin
  968. IL := Value as TKOLImageList;
  969. FImgWidth := IL.ImgWidth;
  970. FImgHeight := IL.ImgHeight;
  971. FCount := IL.Count;
  972. FBitmap.Assign( IL.Bitmap );
  973. FSystemImageList := IL.SystemImageList;
  974. FTransparentColor := IL.TransparentColor;
  975. end
  976. else
  977. inherited;
  978. Change;
  979. end;
  980. procedure TKOLImageList.AssignBitmapToKOLImgList;
  981. var R: Integer;
  982. TmpBmp: TBitmap;
  983. begin
  984. if FKOLImgList = nil then Exit;
  985. if Bitmap <> nil then
  986. begin
  987. //Bitmap.SaveToFile( 'c:\test1.bmp' );
  988. //ShowMessage( 'Bitmap.Handle=' + Int2Str( Bitmap.Handle ) );
  989. FKOLImgList.Clear;
  990. FKOLImgList.Colors := Colors;
  991. //FKOLImgList.BkColor := Color2RGB( BkColor );
  992. FKOLImgList.ImgWidth := ImgWidth;
  993. FKOLImgList.ImgHeight := ImgHeight;
  994. {$IFDEF _D3orHigher}
  995. {Bitmap.HandleType := bmDIB;
  996. Bitmap.PixelFormat := pf24bit;}
  997. {$ENDIF}
  998. //ShowMessage( Int2Hex( Color2RGB( BkColor ), 8 ) );
  999. if not Bitmap.Empty then
  1000. begin
  1001. //Bitmap.SaveToFile( 'c:\test2.bmp' );
  1002. TmpBmp := TBitmap.Create;
  1003. TRY
  1004. TmpBmp.Assign( Bitmap );
  1005. if Masked then
  1006. R := FKOLImgList.AddMasked( TmpBmp.Handle, Color2RGB( TransparentColor ) )
  1007. else
  1008. begin
  1009. FKOLImgList.Masked := FALSE;
  1010. R := FKOLImgList.Add( TmpBmp.Handle, 0 );
  1011. end;
  1012. if R < 0 then
  1013. ShowMessage( 'Error adding bitmap: ' + SysErrorMessage( GetLastError ) )
  1014. else
  1015. begin
  1016. DoNotifyLinkedComponents( noChanged );
  1017. end;
  1018. FINALLY
  1019. TmpBmp.Free;
  1020. END;
  1021. //Bitmap.SaveToFile( 'c:\test3.bmp' );
  1022. //ShowMessage( 'Result := ' + Int2Str( R ) );
  1023. //ShowMessage( 'FKOLImgList.Handle=' + Int2Str( FKOLImgList.Handle ) );
  1024. end;
  1025. end;
  1026. end;
  1027. {procedure TKOLImageList.BitmapChanged(Sender: TObject);
  1028. begin
  1029. AssignBitmapToKOLImgList;
  1030. end;}
  1031. procedure TKOLImageList.Clear;
  1032. begin
  1033. asm
  1034. jmp @@e_signature
  1035. DB '#$signature$#', 0
  1036. DB 'TKOLImageList.Clear', 0
  1037. @@e_signature:
  1038. end;
  1039. if FBitmap <> nil then
  1040. begin
  1041. FBitmap.Width := 0;
  1042. FBitmap.Height := 0;
  1043. end;
  1044. FCount := 0;
  1045. end;
  1046. constructor TKOLImageList.Create( AOwner: TComponent );
  1047. begin
  1048. asm
  1049. jmp @@e_signature
  1050. DB '#$signature$#', 0
  1051. DB 'TKOLImageList.Create', 0
  1052. @@e_signature:
  1053. end;
  1054. inherited Create( AOwner );
  1055. FBkColor := clNone;
  1056. FBitmap := TBitmap.Create;
  1057. //FBitmap.OnChange := BitmapChanged;
  1058. FImgWidth := 32;
  1059. FImgHeight := 32;
  1060. FTransparentColor := clDefault;
  1061. FMasked := TRUE;
  1062. NeedFree := False; // ImageList in KOL destroyes self when its parent
  1063. // control is destroyed - automatically.
  1064. fCreationPriority := 10;
  1065. end;
  1066. destructor TKOLImageList.Destroy;
  1067. begin
  1068. asm
  1069. jmp @@e_signature
  1070. DB '#$signature$#', 0
  1071. DB 'TKOLImageList.Destroy', 0
  1072. @@e_signature:
  1073. end;
  1074. FKOLImgList.Free;
  1075. FBitmap.Free;
  1076. inherited;
  1077. end;
  1078. function TKOLImageList.GetBitmap: TBitmap;
  1079. begin
  1080. asm
  1081. jmp @@e_signature
  1082. DB '#$signature$#', 0
  1083. DB 'TKOLImageList.GetBitmap', 0
  1084. @@e_signature:
  1085. end;
  1086. if SystemImageList then
  1087. Result := nil
  1088. else
  1089. Result := FBitmap;
  1090. end;
  1091. function TKOLImageList.GetImageListHandle: THandle;
  1092. begin
  1093. if FKOLImgList = nil then
  1094. begin
  1095. FKOLImgList := NewImageList( nil );
  1096. AssignBitmapToKOLImgList;
  1097. end;
  1098. Result := FKOLImgList.Handle;
  1099. end;
  1100. function TKOLImageList.GetTransparentColor: TColor;
  1101. begin
  1102. asm
  1103. jmp @@e_signature
  1104. DB '#$signature$#', 0
  1105. DB 'TKOLImageList.GetTransparentColor', 0
  1106. @@e_signature:
  1107. end;
  1108. Result := FTransparentColor;
  1109. if Result = clDefault then
  1110. if FBitmap <> nil then
  1111. if (FBitmap.Width <> 0) and (FBitmap.Height <> 0) then
  1112. Result := FBitmap.Canvas.Pixels[ 0, FBitmap.Height - 1 ];
  1113. end;
  1114. procedure TKOLImageList.SetBitmap(const Value: TBitmap);
  1115. {$IFDEF _D2}
  1116. var KOLBmp: KOL.PBitmap;
  1117. {$ENDIF}
  1118. begin
  1119. asm
  1120. jmp @@e_signature
  1121. DB '#$signature$#', 0
  1122. DB 'TKOLImageList.SetBitmap', 0
  1123. @@e_signature:
  1124. end;
  1125. if FBitmap = Value then Exit;
  1126. FBitmap.Assign( Value );
  1127. if (FBitmap.Height <> 0) and (FBitmap.Width <> 0) then
  1128. begin
  1129. FImgHeight := FBitmap.Height;
  1130. {AK->}if FImgWidth<=0 then{<-AK} FImgWidth := FImgHeight;
  1131. FCount := FBitmap.Width div FImgWidth;
  1132. end;
  1133. {$IFDEF _D2}
  1134. KOLBmp := NewBitmap( Value.Width, Value.Height );
  1135. TRY
  1136. KOLBmp.HandleType := KOL.bmDIB;
  1137. KOLBmp.PixelFormat := KOL.pf32bit;
  1138. BitBlt( KOLBmp.Canvas.Handle, 0, 0, Value.Width, Value.Height,
  1139. Value.Canvas.Handle, 0, 0, SrcCopy );
  1140. case CountSystemColorsUsedInBitmap( KOLBmp ) of
  1141. KOL.pf1bit, KOL.pf4bit: Colors := ilcColor4;
  1142. KOL.pf8bit: Colors := ilcColor8;
  1143. KOL.pf32bit: Colors := ilcColor32;
  1144. else Colors := ilcColor24;
  1145. end;
  1146. FINALLY
  1147. KOLBmp.Free;
  1148. END;
  1149. {$ELSE}
  1150. if FBitmap.HandleType = bmDDB then
  1151. Colors := ilcColorDDB
  1152. else
  1153. begin
  1154. case FBitmap.PixelFormat of
  1155. pf1bit,
  1156. pf4bit: Colors := ilcColor4;
  1157. pf8bit: Colors := ilcColor8;
  1158. pf32bit: Colors := ilcColor32;
  1159. //pf24bit:
  1160. else Colors := ilcColor24;
  1161. end;
  1162. end;
  1163. {$ENDIF}
  1164. if (FBitmap.Height <> 0) and (FBitmap.Width <> 0) then
  1165. begin
  1166. TransparentColor := FBitmap.Canvas.Pixels[ 0, FBitmap.Height - 1 ];
  1167. end;
  1168. if FKOLImgList <> nil then
  1169. AssignBitmapToKOLImgList;
  1170. Change;
  1171. end;
  1172. procedure TKOLImageList.SetBkColor(const Value: TColor);
  1173. begin
  1174. asm
  1175. jmp @@e_signature
  1176. DB '#$signature$#', 0
  1177. DB 'TKOLImageList.SetBkColor', 0
  1178. @@e_signature:
  1179. end;
  1180. FBkColor := Value;
  1181. AssignBitmapToKOLImgList;
  1182. Change;
  1183. end;
  1184. procedure TKOLImageList.SetColors(const Value: TImageListColors);
  1185. //{$IFDEF _D2}
  1186. var KOLBmp: KOL.PBitmap;
  1187. //{$ENDIF}
  1188. begin
  1189. asm
  1190. jmp @@e_signature
  1191. DB '#$signature$#', 0
  1192. DB 'TKOLImageList.SetColors', 0
  1193. @@e_signature:
  1194. end;
  1195. if FColors = Value then Exit;
  1196. FColors := Value;
  1197. if FBitmap = nil then Exit;
  1198. if FBitmap.Width * FBitmap.Height = 0 then Exit;
  1199. //{$IFDEF _D2}
  1200. KOLBmp := NewBitmap( FBitmap.Width, FBitmap.Height );
  1201. TRY
  1202. KOLBmp.HandleType := KOL.bmDIB;
  1203. KOLBmp.PixelFormat := KOL.pf32bit;
  1204. BitBlt( KOLBmp.Canvas.Handle, 0, 0, FBitmap.Width, FBitmap.Height,
  1205. FBitmap.Canvas.Handle, 0, 0, SrcCopy );
  1206. case Value of
  1207. ilcColor4: KOLBmp.PixelFormat := KOL.pf4bit;
  1208. ilcColor8: KOLBmp.PixelFormat := KOL.pf8bit;
  1209. ilcColor24: KOLBmp.PixelFormat := KOL.pf24bit;
  1210. ilcColor32: KOLBmp.PixelFormat := KOL.pf32bit;
  1211. else KOLBmp.HandleType := KOL.bmDDB;
  1212. end;
  1213. FBitmap.Handle := KOLBmp.ReleaseHandle;
  1214. FINALLY
  1215. KOLBmp.Free;
  1216. END;
  1217. (*{$ELSE}
  1218. if Assigned( FBitmap ) then
  1219. begin
  1220. if FColors = ilcColorDDB then
  1221. FBitmap.HandleType := bmDDB
  1222. else
  1223. begin
  1224. FBitmap.HandleType := bmDIB;
  1225. case Value of
  1226. ilcColor4: FBitmap.PixelFormat := pf4bit;
  1227. ilcColor8: FBitmap.PixelFormat := pf8bit;
  1228. ilcColor24: FBitmap.PixelFormat := pf24bit;
  1229. ilcColor32: FBitmap.PixelFormat := pf32bit;
  1230. end;
  1231. end;
  1232. end;
  1233. {$ENDIF}*)
  1234. Change;
  1235. end;
  1236. procedure TKOLImageList.SetCount(const Value: Integer);
  1237. begin
  1238. asm
  1239. jmp @@e_signature
  1240. DB '#$signature$#', 0
  1241. DB 'TKOLImageList.SetCount', 0
  1242. @@e_signature:
  1243. end;
  1244. FCount := Value;
  1245. if Value > 0 then
  1246. begin
  1247. {AK->} if FImgWidth <= 0 then {<-AK} // change by Andrzej Kubaszek 28-Jan-2002
  1248. FImgWidth := FImgHeight;
  1249. if FBitmap <> nil then
  1250. if FBitmap.Width > 0 then
  1251. FImgWidth := FBitmap.Width div FCount;
  1252. end;
  1253. Change;
  1254. end;
  1255. procedure TKOLImageList.SetImgHeight(Value: Integer);
  1256. var I: Integer;
  1257. begin
  1258. asm
  1259. jmp @@e_signature
  1260. DB '#$signature$#', 0
  1261. DB 'TKOLImageList.SetImgHeight', 0
  1262. @@e_signature:
  1263. end;
  1264. if Value < 0 then
  1265. Value := 0;
  1266. if SystemImageList then
  1267. if Value >= 32 then
  1268. Value := 32
  1269. else
  1270. Value := 16
  1271. else
  1272. if FBitmap <> nil then
  1273. begin
  1274. if not FBitmap.Empty then
  1275. if (FBitmap.Height <> 0) and (FBitmap.Width <> 0) then
  1276. if Value <> FBitmap.Height then
  1277. Value := FBitmap.Height;
  1278. end;
  1279. if FImgHeight = Value then Exit;
  1280. if Count > 0 then
  1281. if not( csLoading in ComponentState ) then
  1282. begin
  1283. I := MessageBox( 0, 'Changing image list height will lead to clearing it. Are ' +
  1284. 'You sure You want to change height now?',
  1285. 'TKOLImageList.ImgHeight change', MB_YESNO or
  1286. MB_DEFBUTTON2 or MB_SETFOREGROUND );
  1287. if I = ID_NO then Exit;
  1288. Clear;
  1289. end;
  1290. FImgHeight := Value;
  1291. if SystemImageList then
  1292. FImgWidth := FImgHeight;
  1293. Change;
  1294. end;
  1295. procedure TKOLImageList.SetImgWidth(Value: Integer);
  1296. var I: Integer;
  1297. begin
  1298. asm
  1299. jmp @@e_signature
  1300. DB '#$signature$#', 0
  1301. DB 'TKOLImageList.SetImgWidth', 0
  1302. @@e_signature:
  1303. end;
  1304. if Value < 0 then Value := 0;
  1305. if SystemImageList then
  1306. begin
  1307. if Value >= 32 then
  1308. Value := 32
  1309. else
  1310. Value := 16;
  1311. end
  1312. else
  1313. if FBitmap <> nil then
  1314. begin
  1315. if not FBitmap.Empty then
  1316. if (FBitmap.Width <> 0) and (FBitmap.Height <> 0) then
  1317. if Value > FBitmap.Width then
  1318. Value := FBitmap.Width;
  1319. end;
  1320. if FImgWidth = Value then Exit;
  1321. if Count > 0 then
  1322. if not( csLoading in ComponentState ) then
  1323. begin
  1324. I := MessageBox( 0, 'Changing image list width will lead to clearing it. Are ' +
  1325. 'You sure You want to change width now?',
  1326. 'TKOLImageList.ImgWidth change', MB_YESNO or
  1327. MB_DEFBUTTON2 or MB_SETFOREGROUND );
  1328. if I = ID_NO then Exit;
  1329. Clear;
  1330. end;
  1331. FImgWidth := Value;
  1332. if SystemImageList then
  1333. FImgHeight := FImgWidth;
  1334. Change;
  1335. end;
  1336. procedure TKOLImageList.SetMasked(const Value: Boolean);
  1337. begin
  1338. asm
  1339. jmp @@e_signature
  1340. DB '#$signature$#', 0
  1341. DB 'TKOLImageList.SetMasked', 0
  1342. @@e_signature:
  1343. end;
  1344. FMasked := Value;
  1345. Change;
  1346. end;
  1347. procedure TKOLImageList.SetSystemImageList(const Value: Boolean);
  1348. begin
  1349. asm
  1350. jmp @@e_signature
  1351. DB '#$signature$#', 0
  1352. DB 'TKOLImageList.SetSystemImageList', 0
  1353. @@e_signature:
  1354. end;
  1355. if Value = FSystemImageList then Exit;
  1356. FSystemImageList := Value;
  1357. if Value then
  1358. begin
  1359. Clear;
  1360. SetImgHeight( ImgHeight );
  1361. SetImgWidth( ImgHeight );
  1362. end
  1363. else
  1364. Clear;
  1365. Change;
  1366. end;
  1367. procedure TKOLImageList.SetTransparentColor(const Value: TColor);
  1368. begin
  1369. asm
  1370. jmp @@e_signature
  1371. DB '#$signature$#', 0
  1372. DB 'TKOLImageList.SetTransparentColor', 0
  1373. @@e_signature:
  1374. end;
  1375. FTransparentColor := Value;
  1376. AssignBitmapToKOLImgList;
  1377. Change;
  1378. end;
  1379. procedure TKOLImageList.SetupFirst(SL: TStringList; const AName,
  1380. AParent, Prefix: String);
  1381. const Booleans: array[ Boolean ] of String = ( 'False', 'True' );
  1382. const ColorsValues: array[ TImageListColors ] of String = ( 'ilcColor', 'ilcColor4',
  1383. 'ilcColor8', 'ilcColor16', 'ilcColor24', 'ilcColor32', 'ilcColorDDB',
  1384. 'ilcDefault' );
  1385. var RsrcName, RsrcFile: String;
  1386. begin
  1387. asm
  1388. jmp @@e_signature
  1389. DB '#$signature$#', 0
  1390. DB 'TKOLImageList.SetupFirst', 0
  1391. @@e_signature:
  1392. end;
  1393. SL.Add( Prefix + AName + ' := NewImageList( ' + AParent + ' );' );
  1394. GenerateTag( SL, AName, Prefix );
  1395. if SystemImageList then
  1396. SL.Add( Prefix + AName + '.LoadSystemIcons( ' + Booleans[ ImgHeight = 16 ] + ' );' )
  1397. else
  1398. begin
  1399. if Colors <> ilcDefault then
  1400. SL.Add( Prefix + AName + '.Colors := ' + ColorsValues[ Colors ] + ';' );
  1401. if not Masked then
  1402. begin
  1403. SL.Add( Prefix + AName + '.Masked := FALSE;' );
  1404. if BkColor <> clNone then
  1405. SL.Add( Prefix + AName + '.BkColor := ' + Color2Str( BkColor ) +
  1406. ';' );
  1407. end;
  1408. if FImgWidth <> 32 then
  1409. SL.Add( Prefix + ' ' + AName + '.ImgWidth := ' + IntToStr( FImgWidth ) + ';' );
  1410. if FImgHeight <> 32 then
  1411. SL.Add( Prefix + ' ' + AName + '.ImgHeight := ' + IntToStr( FImgHeight ) + ';' );
  1412. end;
  1413. if (FBitmap.Width <> 0) and (FBitmap.Height <> 0) then
  1414. begin
  1415. if (FImgHeight = 32) and (FImgWidth <> FImgHeight) then
  1416. SL.Add( Prefix + ' ' + AName + '.ImgWidth := ' + IntToStr( FImgWidth ) + ';' );
  1417. RsrcName := UpperCase( ParentKOLForm.FormName + '_' + Name );
  1418. RsrcFile := ParentKOLForm.FormName + '_' + Name;
  1419. SL.Add( Prefix + ' {$R ' + RsrcFile + '.res}' );
  1420. if Masked then
  1421. SL.Add( Prefix + AName + '.AddMasked( LoadBmp( hInstance, ''' +
  1422. RsrcName + ''', ' +
  1423. AName + ' ), ' + Color2Str( TransparentColor ) + ' );' )
  1424. else
  1425. SL.Add( Prefix + AName + '.Add( LoadBmp( hInstance, ''' +
  1426. RsrcName + ''', ' +
  1427. AName + ' ), 0 );' );
  1428. //Rpt( 'Generating resource: ' + ProjectSourcePath + RsrcFile + '.res' );
  1429. GenerateBitmapResource( FBitmap, RsrcName, RsrcFile, fUpdated );
  1430. end;
  1431. end;
  1432. procedure TKOLImageList.SetupLast(SL: TStringList; const AName, AParent,
  1433. Prefix: String);
  1434. begin
  1435. asm
  1436. jmp @@e_signature
  1437. DB '#$signature$#', 0
  1438. DB 'TKOLImageList.SetupLast', 0
  1439. @@e_signature:
  1440. end;
  1441. inherited;
  1442. end;
  1443. { TKOLImageListEditor }
  1444. procedure TKOLImageListEditor.Edit;
  1445. var IL: TImageList; //Invisible;
  1446. {$IFDEF _D6orHigher}
  1447. ILCE: IComponentEditor;
  1448. {$ELSE}
  1449. ILCE: TComponentEditor;
  1450. {$ENDIF}
  1451. ILH: THandle;
  1452. KIL: TKOLImageList;
  1453. KName: String;
  1454. I: Integer;
  1455. //TrColor: TColor;
  1456. begin
  1457. asm
  1458. jmp @@e_signature
  1459. DB '#$signature$#', 0
  1460. DB 'TKOLImageListEditor.Edit', 0
  1461. @@e_signature:
  1462. end;
  1463. if Component = nil then Exit;
  1464. if not ( Component is TKOLImageList ) then Exit;
  1465. KIL := Component as TKOLImageList;
  1466. if KIL.SystemImageList then
  1467. begin
  1468. ShowMessage( 'It is not possible to edit system image list!' );
  1469. Exit;
  1470. end;
  1471. …

Large files files are truncated, but you can click here to view the full file