TB2Reg.pas 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. http://www.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. http://www.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. {$IFDEF JR_D6} DesignIntf, DesignEditors, VCLEditors, {$ELSE} DsgnIntf, {$ENDIF}
  29. TB2Toolbar, {$IFNDEF MPEXCLUDE}TB2ToolWindow,{$ENDIF} TB2Dock, TB2Item, TB2ExtItems, {$IFNDEF MPEXCLUDE} TB2MRU, TB2MDI, {$ENDIF}
  30. TB2DsgnItemEditor;
  31. {$IFDEF JR_D5}
  32. { TTBImageIndexPropertyEditor }
  33. { Unfortunately TComponentImageIndexPropertyEditor seems to be gone in
  34. Delphi 6, so we have to use our own image index property editor class }
  35. type
  36. TTBImageIndexPropertyEditor = class(TIntegerProperty
  37. {$IFDEF JR_D6} , ICustomPropertyListDrawing {$ENDIF})
  38. public
  39. function GetAttributes: TPropertyAttributes; override;
  40. procedure GetValues(Proc: TGetStrProc); override;
  41. function GetImageListAt(Index: Integer): TCustomImageList; virtual;
  42. // ICustomPropertyListDrawing
  43. procedure ListMeasureHeight(const Value: string; ACanvas: TCanvas;
  44. var AHeight: Integer); {$IFNDEF JR_D6} override; {$ENDIF}
  45. procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas;
  46. var AWidth: Integer); {$IFNDEF JR_D6} override; {$ENDIF}
  47. procedure ListDrawValue(const Value: string; ACanvas: TCanvas;
  48. const ARect: TRect; ASelected: Boolean); {$IFNDEF JR_D6} override; {$ENDIF}
  49. end;
  50. { TTBItemImageIndexPropertyEditor }
  51. type
  52. TTBItemImageIndexPropertyEditor = class(TTBImageIndexPropertyEditor)
  53. public
  54. function GetImageListAt (Index: Integer): TCustomImageList; override;
  55. end;
  56. {$ENDIF}
  57. procedure Register;
  58. implementation
  59. uses
  60. ImgEdit, Actions, UITypes;
  61. {$IFDEF JR_D5}
  62. function TTBImageIndexPropertyEditor.GetAttributes: TPropertyAttributes;
  63. begin
  64. Result := [paMultiSelect, paValueList, paRevertable];
  65. end;
  66. function TTBImageIndexPropertyEditor.GetImageListAt(Index: Integer): TCustomImageList;
  67. begin
  68. Result := nil;
  69. end;
  70. procedure TTBImageIndexPropertyEditor.GetValues(Proc: TGetStrProc);
  71. var
  72. ImgList: TCustomImageList;
  73. I: Integer;
  74. begin
  75. ImgList := GetImageListAt(0);
  76. if Assigned(ImgList) then
  77. for I := 0 to ImgList.Count-1 do
  78. Proc(IntToStr(I));
  79. end;
  80. procedure TTBImageIndexPropertyEditor.ListDrawValue(const Value: string;
  81. ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
  82. var
  83. ImgList: TCustomImageList;
  84. X: Integer;
  85. begin
  86. ImgList := GetImageListAt(0);
  87. ACanvas.FillRect(ARect);
  88. X := ARect.Left + 2;
  89. if Assigned(ImgList) then begin
  90. ImgList.Draw(ACanvas, X, ARect.Top + 2, StrToInt(Value));
  91. Inc(X, ImgList.Width);
  92. end;
  93. ACanvas.TextOut(X + 3, ARect.Top + 1, Value);
  94. end;
  95. procedure TTBImageIndexPropertyEditor.ListMeasureHeight(const Value: string;
  96. ACanvas: TCanvas; var AHeight: Integer);
  97. var
  98. ImgList: TCustomImageList;
  99. begin
  100. ImgList := GetImageListAt(0);
  101. AHeight := ACanvas.TextHeight(Value) + 2;
  102. if Assigned(ImgList) and (ImgList.Height + 4 > AHeight) then
  103. AHeight := ImgList.Height + 4;
  104. end;
  105. procedure TTBImageIndexPropertyEditor.ListMeasureWidth(const Value: string;
  106. ACanvas: TCanvas; var AWidth: Integer);
  107. var
  108. ImgList: TCustomImageList;
  109. begin
  110. ImgList := GetImageListAt(0);
  111. AWidth := ACanvas.TextWidth(Value) + 4;
  112. if Assigned(ImgList) then
  113. Inc(AWidth, ImgList.Width);
  114. end;
  115. { TTBItemImageIndexPropertyEditor }
  116. function TTBItemImageIndexPropertyEditor.GetImageListAt(Index: Integer): TCustomImageList;
  117. var
  118. C: TPersistent;
  119. Item: TTBCustomItem;
  120. begin
  121. Result := nil;
  122. { ? I'm guessing that the Index parameter is a component index (one that
  123. would be passed to the GetComponent function). }
  124. C := GetComponent(Index);
  125. if C is TTBCustomItem then begin
  126. Item := TTBCustomItem(C);
  127. repeat
  128. Result := Item.Images;
  129. if Assigned(Result) then
  130. Break;
  131. Item := Item.Parent;
  132. if Item = nil then
  133. Break;
  134. Result := Item.SubMenuImages;
  135. until Assigned(Result);
  136. end;
  137. end;
  138. {$ENDIF}
  139. { TTBCustomImageListEditor }
  140. type
  141. TTBCustomImageListEditor = class(TComponentEditor)
  142. public
  143. procedure Edit; override;
  144. procedure ExecuteVerb(Index: Integer); override;
  145. function GetVerb(Index: Integer): String; override;
  146. function GetVerbCount: Integer; override;
  147. end;
  148. TTBCustomImageListAccess = class(TTBCustomImageList);
  149. procedure TTBCustomImageListEditor.Edit;
  150. var
  151. ImgList: TTBCustomImageList;
  152. begin
  153. ImgList := Component as TTBCustomImageList;
  154. if not TTBCustomImageListAccess(ImgList).ImagesBitmap.Empty then begin
  155. if MessageDlg('The image list''s ImagesBitmap property has ' +
  156. 'a bitmap assigned. Because of this, any changes you make in the ' +
  157. 'Image List Editor will not be preserved when the form is saved.'#13#10#13#10 +
  158. 'Do you want to open the editor anyway?', mtWarning,
  159. [mbYes, mbNo], 0) <> mrYes then
  160. Exit;
  161. end;
  162. EditImageList(ImgList);
  163. end;
  164. procedure TTBCustomImageListEditor.ExecuteVerb(Index: Integer);
  165. begin
  166. if Index = 0 then
  167. Edit;
  168. end;
  169. function TTBCustomImageListEditor.GetVerbCount: Integer;
  170. begin
  171. Result := 1;
  172. end;
  173. function TTBCustomImageListEditor.GetVerb(Index: Integer): String;
  174. begin
  175. if Index = 0 then
  176. Result := 'ImageList Editor...'
  177. else
  178. Result := '';
  179. end;
  180. procedure Register;
  181. begin
  182. RegisterComponents('Toolbar2000', [TTBDock, TTBToolbar, {$IFNDEF MPEXCLUDE}TTBToolWindow,{$ENDIF}
  183. TTBPopupMenu, TTBImageList, TTBItemContainer{$IFNDEF MPEXCLUDE}, TTBBackground, TTBMRUList,
  184. TTBMDIHandler{$ENDIF}]);
  185. {$IFDEF JR_D4}
  186. RegisterActions('', [TTBEditAction], nil);
  187. {$ENDIF}
  188. RegisterNoIcon([TTBItem, TTBGroupItem, TTBSubmenuItem, TTBSeparatorItem,
  189. TTBEditItem, {$IFNDEF MPEXCLUDE} TTBMRUListItem,{$ENDIF} TTBControlItem{$IFNDEF MPEXCLUDE}, TTBMDIWindowItem,
  190. TTBVisibilityToggleItem{$ENDIF}]);
  191. RegisterClasses([TTBItem, TTBGroupItem, TTBSubmenuItem, TTBSeparatorItem,
  192. TTBEditItem, {$IFNDEF MPEXCLUDE}TTBMRUListItem,{$ENDIF} TTBControlItem{$IFNDEF MPEXCLUDE}, TTBMDIWindowItem,
  193. TTBVisibilityToggleItem{$ENDIF}]);
  194. RegisterComponentEditor(TTBCustomToolbar, TTBItemsEditor);
  195. RegisterComponentEditor(TTBItemContainer, TTBItemsEditor);
  196. RegisterComponentEditor(TTBPopupMenu, TTBItemsEditor);
  197. RegisterComponentEditor(TTBCustomImageList, TTBCustomImageListEditor);
  198. RegisterPropertyEditor(TypeInfo(TTBRootItem), nil, '', TTBItemsPropertyEditor);
  199. {$IFDEF JR_D5}
  200. RegisterPropertyEditor(TypeInfo(TImageIndex), TTBCustomItem, 'ImageIndex',
  201. TTBItemImageIndexPropertyEditor);
  202. {$ENDIF}
  203. {$IFDEF JR_D6}
  204. { TShortCut properties show up like Integer properties in Delphi 6
  205. without this... }
  206. RegisterPropertyEditor(TypeInfo(TShortCut), TTBCustomItem, '',
  207. TShortCutProperty);
  208. {$ENDIF}
  209. { Link in images for the toolbar buttons }
  210. {$R TB2DsgnItemEditor.res}
  211. TBRegisterItemClass(TTBEditItem, 'New &Edit', HInstance);
  212. TBRegisterItemClass(TTBGroupItem, 'New &Group Item', HInstance);
  213. {$IFNDEF MPEXCLUDE}
  214. TBRegisterItemClass(TTBMRUListItem, 'New &MRU List Item', HInstance);
  215. TBRegisterItemClass(TTBMDIWindowItem, 'New MDI &Windows List', HInstance);
  216. TBRegisterItemClass(TTBVisibilityToggleItem, 'New &Visibility-Toggle Item', HInstance);
  217. {$ENDIF}
  218. end;
  219. end.