TB2Reg.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. unit TB2Reg;
  2. {
  3. Toolbar2000
  4. Copyright (C) 1998-2005 by Jordan Russell
  5. All rights reserved.
  6. The contents of this file are subject to the "Toolbar2000 License"; you may
  7. not use or distribute this file except in compliance with the
  8. "Toolbar2000 License". A copy of the "Toolbar2000 License" may be found in
  9. TB2k-LICENSE.txt or at:
  10. https://jrsoftware.org/files/tb2k/TB2k-LICENSE.txt
  11. Alternatively, the contents of this file may be used under the terms of the
  12. GNU General Public License (the "GPL"), in which case the provisions of the
  13. GPL are applicable instead of those in the "Toolbar2000 License". A copy of
  14. the GPL may be found in GPL-LICENSE.txt or at:
  15. https://jrsoftware.org/files/tb2k/GPL-LICENSE.txt
  16. If you wish to allow use of your version of this file only under the terms of
  17. the GPL and not to allow others to use your version of this file under the
  18. "Toolbar2000 License", indicate your decision by deleting the provisions
  19. above and replace them with the notice and other provisions required by the
  20. GPL. If you do not delete the provisions above, a recipient may use your
  21. version of this file under either the "Toolbar2000 License" or the GPL.
  22. $jrsoftware: tb2k/Source/TB2Reg.pas,v 1.28 2005/01/06 03:56:50 jr Exp $
  23. }
  24. interface
  25. {$I TB2Ver.inc}
  26. uses
  27. Windows, SysUtils, Classes, Graphics, Controls, Dialogs, ActnList, ImgList,
  28. DesignIntf, DesignEditors, VCLEditors,
  29. TB2Toolbar, TB2Dock, TB2Item, TB2ExtItems,
  30. TB2DsgnItemEditor;
  31. { TTBImageIndexPropertyEditor }
  32. { Unfortunately TComponentImageIndexPropertyEditor seems to be gone in
  33. Delphi 6, so we have to use our own image index property editor class }
  34. type
  35. TTBImageIndexPropertyEditor = class(TIntegerProperty, ICustomPropertyListDrawing)
  36. public
  37. function GetAttributes: TPropertyAttributes; override;
  38. procedure GetValues(Proc: TGetStrProc); override;
  39. function GetImageListAt(Index: Integer): TCustomImageList; virtual;
  40. // ICustomPropertyListDrawing
  41. procedure ListMeasureHeight(const Value: string; ACanvas: TCanvas;
  42. var AHeight: Integer);
  43. procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas;
  44. var AWidth: Integer);
  45. procedure ListDrawValue(const Value: string; ACanvas: TCanvas;
  46. const ARect: TRect; ASelected: Boolean);
  47. end;
  48. { TTBItemImageIndexPropertyEditor }
  49. type
  50. TTBItemImageIndexPropertyEditor = class(TTBImageIndexPropertyEditor)
  51. public
  52. function GetImageListAt (Index: Integer): TCustomImageList; override;
  53. end;
  54. procedure Register;
  55. implementation
  56. uses
  57. ImgEdit, Actions, UITypes;
  58. function TTBImageIndexPropertyEditor.GetAttributes: TPropertyAttributes;
  59. begin
  60. Result := [paMultiSelect, paValueList, paRevertable];
  61. end;
  62. function TTBImageIndexPropertyEditor.GetImageListAt(Index: Integer): TCustomImageList;
  63. begin
  64. Result := nil;
  65. end;
  66. procedure TTBImageIndexPropertyEditor.GetValues(Proc: TGetStrProc);
  67. var
  68. ImgList: TCustomImageList;
  69. I: Integer;
  70. begin
  71. ImgList := GetImageListAt(0);
  72. if Assigned(ImgList) then
  73. for I := 0 to ImgList.Count-1 do
  74. Proc(IntToStr(I));
  75. end;
  76. procedure TTBImageIndexPropertyEditor.ListDrawValue(const Value: string;
  77. ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
  78. var
  79. ImgList: TCustomImageList;
  80. X: Integer;
  81. begin
  82. ImgList := GetImageListAt(0);
  83. ACanvas.FillRect(ARect);
  84. X := ARect.Left + 2;
  85. if Assigned(ImgList) then begin
  86. ImgList.Draw(ACanvas, X, ARect.Top + 2, StrToInt(Value));
  87. Inc(X, ImgList.Width);
  88. end;
  89. ACanvas.TextOut(X + 3, ARect.Top + 1, Value);
  90. end;
  91. procedure TTBImageIndexPropertyEditor.ListMeasureHeight(const Value: string;
  92. ACanvas: TCanvas; var AHeight: Integer);
  93. var
  94. ImgList: TCustomImageList;
  95. begin
  96. ImgList := GetImageListAt(0);
  97. AHeight := ACanvas.TextHeight(Value) + 2;
  98. if Assigned(ImgList) and (ImgList.Height + 4 > AHeight) then
  99. AHeight := ImgList.Height + 4;
  100. end;
  101. procedure TTBImageIndexPropertyEditor.ListMeasureWidth(const Value: string;
  102. ACanvas: TCanvas; var AWidth: Integer);
  103. var
  104. ImgList: TCustomImageList;
  105. begin
  106. ImgList := GetImageListAt(0);
  107. AWidth := ACanvas.TextWidth(Value) + 4;
  108. if Assigned(ImgList) then
  109. Inc(AWidth, ImgList.Width);
  110. end;
  111. { TTBItemImageIndexPropertyEditor }
  112. function TTBItemImageIndexPropertyEditor.GetImageListAt(Index: Integer): TCustomImageList;
  113. var
  114. C: TPersistent;
  115. Item: TTBCustomItem;
  116. begin
  117. Result := nil;
  118. { ? I'm guessing that the Index parameter is a component index (one that
  119. would be passed to the GetComponent function). }
  120. C := GetComponent(Index);
  121. if C is TTBCustomItem then begin
  122. Item := TTBCustomItem(C);
  123. repeat
  124. Result := Item.Images;
  125. if Assigned(Result) then
  126. Break;
  127. Item := Item.Parent;
  128. if Item = nil then
  129. Break;
  130. Result := Item.SubMenuImages;
  131. until Assigned(Result);
  132. end;
  133. end;
  134. { TTBCustomImageListEditor }
  135. type
  136. TTBCustomImageListEditor = class(TComponentEditor)
  137. public
  138. procedure Edit; override;
  139. procedure ExecuteVerb(Index: Integer); override;
  140. function GetVerb(Index: Integer): String; override;
  141. function GetVerbCount: Integer; override;
  142. end;
  143. TTBCustomImageListAccess = class(TTBCustomImageList);
  144. procedure TTBCustomImageListEditor.Edit;
  145. var
  146. ImgList: TTBCustomImageList;
  147. begin
  148. ImgList := Component as TTBCustomImageList;
  149. if not TTBCustomImageListAccess(ImgList).ImagesBitmap.Empty then begin
  150. if MessageDlg('The image list''s ImagesBitmap property has ' +
  151. 'a bitmap assigned. Because of this, any changes you make in the ' +
  152. 'Image List Editor will not be preserved when the form is saved.'#13#10#13#10 +
  153. 'Do you want to open the editor anyway?', mtWarning,
  154. [mbYes, mbNo], 0) <> mrYes then
  155. Exit;
  156. end;
  157. EditImageList(ImgList);
  158. end;
  159. procedure TTBCustomImageListEditor.ExecuteVerb(Index: Integer);
  160. begin
  161. if Index = 0 then
  162. Edit;
  163. end;
  164. function TTBCustomImageListEditor.GetVerbCount: Integer;
  165. begin
  166. Result := 1;
  167. end;
  168. function TTBCustomImageListEditor.GetVerb(Index: Integer): String;
  169. begin
  170. if Index = 0 then
  171. Result := 'ImageList Editor...'
  172. else
  173. Result := '';
  174. end;
  175. procedure Register;
  176. begin
  177. RegisterComponents('Toolbar2000', [TTBDock, TTBToolbar,
  178. TTBPopupMenu, TTBImageList, TTBItemContainer]);
  179. RegisterActions('', [TTBEditAction], nil);
  180. RegisterNoIcon([TTBItem, TTBGroupItem, TTBSubmenuItem, TTBSeparatorItem,
  181. TTBEditItem, TTBControlItem]);
  182. RegisterClasses([TTBItem, TTBGroupItem, TTBSubmenuItem, TTBSeparatorItem,
  183. TTBEditItem, TTBControlItem]);
  184. RegisterComponentEditor(TTBCustomToolbar, TTBItemsEditor);
  185. RegisterComponentEditor(TTBItemContainer, TTBItemsEditor);
  186. RegisterComponentEditor(TTBPopupMenu, TTBItemsEditor);
  187. RegisterComponentEditor(TTBCustomImageList, TTBCustomImageListEditor);
  188. RegisterPropertyEditor(TypeInfo(TTBRootItem), nil, '', TTBItemsPropertyEditor);
  189. RegisterPropertyEditor(TypeInfo(TImageIndex), TTBCustomItem, 'ImageIndex',
  190. TTBItemImageIndexPropertyEditor);
  191. { TShortCut properties show up like Integer properties in Delphi 6
  192. without this... }
  193. RegisterPropertyEditor(TypeInfo(TShortCut), TTBCustomItem, '',
  194. TShortCutProperty);
  195. { Link in images for the toolbar buttons }
  196. {$R TB2DsgnItemEditor.res}
  197. TBRegisterItemClass(TTBEditItem, 'New &Edit', HInstance);
  198. TBRegisterItemClass(TTBGroupItem, 'New &Group Item', HInstance);
  199. end;
  200. end.