TBXReg.pas 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. unit TBXReg;
  2. // TBX Package
  3. // Copyright 2001-2004 Alex A. Denisov. All Rights Reserved
  4. // See TBX.chm for license and installation instructions
  5. //
  6. // Id: TBXReg.pas 16 2004-05-26 02:02:55Z Alex@ZEISS
  7. interface
  8. {$I TB2Ver.inc}
  9. uses
  10. Windows, Classes, Controls, SysUtils, Graphics, ImgList, Dialogs,
  11. DesignIntf, DesignEditors, VCLEditors,
  12. TB2Reg, TB2Toolbar, TB2Item, TBX, TB2DsgnItemEditor,
  13. TBXExtItems, TBXLists, TBXToolPals, TBXStatusBars;
  14. procedure Register;
  15. type
  16. TThemeProperty = class(TStringProperty)
  17. function GetAttributes: TPropertyAttributes; override;
  18. procedure GetValues(Proc: TGetStrProc); override;
  19. end;
  20. TMLStringProperty = class(TCaptionProperty)
  21. function GetAttributes: TPropertyAttributes; override;
  22. procedure Edit; override;
  23. end;
  24. TTBXColorProperty = class(TColorProperty)
  25. public
  26. function GetValue: string; override;
  27. procedure GetValues(Proc: TGetStrProc); override;
  28. procedure SetValue(const Value: string); override;
  29. procedure ListDrawValue(const Value: string; ACanvas: TCanvas;
  30. const ARect: TRect; ASelected: Boolean);
  31. end;
  32. TTBXStatusBarEditor = class(TDefaultEditor)
  33. protected
  34. procedure GetPanelsProp(const Prop: IProperty);
  35. public
  36. procedure Edit; override;
  37. procedure ExecuteVerb(Index: Integer); override;
  38. function GetVerb(Index: Integer): string; override;
  39. function GetVerbCount: Integer; override;
  40. end;
  41. TTBXItemsEditor = class(TTBItemsEditor)
  42. public
  43. procedure ExecuteVerb(Index: Integer); override;
  44. end;
  45. implementation
  46. uses
  47. Forms, TBXThemes, TBXStrEdit, TBXUtils, TypInfo, TB2Version;
  48. { TThemeProperty }
  49. function TThemeProperty.GetAttributes: TPropertyAttributes;
  50. begin
  51. Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  52. end;
  53. procedure TThemeProperty.GetValues(Proc: TGetStrProc);
  54. var
  55. SL: TStringList;
  56. I: Integer;
  57. begin
  58. SL := TStringList.Create;
  59. GetAvailableTBXThemes(SL);
  60. for I := 0 to SL.Count - 1 do Proc(SL[I]);
  61. SL.Free;
  62. end;
  63. { TMLStringProperty }
  64. function WordCount(const S: string; const Delims: TSysCharSet): Integer;
  65. var
  66. L, I: Cardinal;
  67. begin
  68. Result := 0;
  69. I := 1;
  70. L := Length(S);
  71. while I <= L do
  72. begin
  73. while (I <= L) and {MP}CharInSet(S[I], Delims) do Inc(I);
  74. if I <= L then Inc(Result);
  75. while (I <= L) and not {MP}CharInSet(S[I], Delims) do Inc(I);
  76. end;
  77. end;
  78. function WordPosition(const N: Integer; const S: string;
  79. const WordDelims: TSysCharSet): Integer;
  80. var
  81. Count, I: Integer;
  82. begin
  83. Count := 0;
  84. I := 1;
  85. Result := 0;
  86. while (I <= Length(S)) and (Count <> N) do begin
  87. { skip over delimiters }
  88. while (I <= Length(S)) and {MP}CharInSet(S[I], WordDelims) do Inc(I);
  89. { if we're not beyond end of S, we're at the start of a word }
  90. if I <= Length(S) then Inc(Count);
  91. { if not finished, find the end of the current word }
  92. if Count <> N then
  93. while (I <= Length(S)) and not CharInSet(S[I], WordDelims) do Inc(I)
  94. else Result := I;
  95. end;
  96. end;
  97. function ExtractWord(N: Integer; const S: string;
  98. const WordDelims: TSysCharSet): string;
  99. var
  100. I: Integer;
  101. Len: Integer;
  102. begin
  103. Len := 0;
  104. I := WordPosition(N, S, WordDelims);
  105. if I <> 0 then
  106. { find the end of the current word }
  107. while (I <= Length(S)) and not CharInSet(S[I], WordDelims) do begin
  108. { add the I'th character to result }
  109. Inc(Len);
  110. SetLength(Result, Len);
  111. Result[Len] := S[I];
  112. Inc(I);
  113. end;
  114. SetLength(Result, Len);
  115. end;
  116. procedure TMLStringProperty.Edit;
  117. var
  118. Temp: string;
  119. Component: TPersistent;
  120. I, N: Integer;
  121. begin
  122. with TStrEditDlg.Create(Application) do
  123. try
  124. Component := GetComponent(0);
  125. if Component is TComponent then Caption := TComponent(Component).Name + '.' + GetName
  126. else Caption := GetName;
  127. Temp := GetStrValue;
  128. N := WordCount(Temp, [#13, #10]);
  129. for I := 1 to N do Memo.Lines.Add(ExtractWord(I, Temp, [#13, #10]));
  130. Memo.MaxLength := GetEditLimit;
  131. if ShowModal = mrOk then
  132. begin
  133. Temp := Memo.Text;
  134. while (Length(Temp) > 0) and (Temp[Length(Temp)] < ' ') do
  135. System.Delete(Temp, Length(Temp), 1);
  136. SetStrValue(Temp);
  137. end;
  138. finally
  139. Free;
  140. end;
  141. end;
  142. function TMLStringProperty.GetAttributes: TPropertyAttributes;
  143. begin
  144. Result := inherited GetAttributes + [paDialog];
  145. end;
  146. { TTBXColorProperty }
  147. function TTBXColorProperty.GetValue: string;
  148. begin
  149. Result := TBXColorToString(TColor(GetOrdValue));
  150. end;
  151. procedure TTBXColorProperty.GetValues(Proc: TGetStrProc);
  152. begin
  153. TBXGetColorValues(Proc);
  154. end;
  155. procedure TTBXColorProperty.SetValue(const Value: string);
  156. begin
  157. SetOrdValue(TBXStringToColor(Value));
  158. end;
  159. procedure TTBXColorProperty.ListDrawValue(const Value: string; ACanvas: TCanvas;
  160. const ARect: TRect; ASelected: Boolean);
  161. function ColorToBorderColor(AColor: TColor): TColor;
  162. begin
  163. if IsDarkColor(AColor) then
  164. begin
  165. Result := AColor;
  166. SetContrast(Result, AColor, 40);
  167. end
  168. else Result := clBlack;
  169. end;
  170. var
  171. R: TRect;
  172. C: TColor;
  173. OldPenColor, OldBrushColor: TColor;
  174. begin
  175. R := ARect;
  176. with ACanvas do
  177. try
  178. OldPenColor := Pen.Color;
  179. OldBrushColor := Brush.Color;
  180. Pen.Color := Brush.Color;
  181. Rectangle(R);
  182. R.Right := (ARect.Bottom - ARect.Top) + ARect.Left;
  183. InflateRect(R, -1, -1);
  184. C := TBXStringToColor(Value);
  185. if C <> clNone then
  186. begin
  187. Brush.Color := C;
  188. Pen.Color := ColorToBorderColor(ColorToRGB(C));
  189. Rectangle(R);
  190. end
  191. else
  192. begin
  193. Brush.Color := clWindow;
  194. Pen.Color := clBtnShadow;
  195. Rectangle(R);
  196. MoveTo(R.Left, R.Bottom - 1);
  197. LineTo(R.Right - 1, R.Top);
  198. MoveTo(R.Left, R.Top);
  199. LineTo(R.Right, R.Bottom);
  200. end;
  201. Brush.Color := OldBrushColor;
  202. Pen.Color := OldPenColor;
  203. finally
  204. R.Left := R.Right;
  205. R.Right := ARect.Right;
  206. ACanvas.TextRect(R, R.Left + 1, R.Top + 1, Value);
  207. end;
  208. end;
  209. { TTBXStatusBarEditor }
  210. procedure TTBXStatusBarEditor.Edit;
  211. var
  212. Components: IDesignerSelections;
  213. begin
  214. Components := CreateSelectionList;
  215. Components.Add(Component);
  216. GetComponentProperties(Components, [tkClass], Designer, GetPanelsProp);
  217. end;
  218. procedure TTBXStatusBarEditor.ExecuteVerb(Index: Integer);
  219. begin
  220. if Index = 0 then Edit;
  221. end;
  222. function TTBXStatusBarEditor.GetVerb(Index: Integer): string;
  223. begin
  224. if Index = 0 then Result := '&Panels Editor...';
  225. end;
  226. function TTBXStatusBarEditor.GetVerbCount: Integer;
  227. begin
  228. Result := 1;
  229. end;
  230. procedure TTBXStatusBarEditor.GetPanelsProp(const Prop: IProperty);
  231. begin
  232. if SameText(Prop.GetName, 'Panels') then Prop.Edit;
  233. end;
  234. { TTBXItemsEditor }
  235. procedure TTBXItemsEditor.ExecuteVerb(Index: Integer);
  236. const
  237. AboutText =
  238. '%s'#13#10 +
  239. '©2001–2004 Alex A. Denisov'#13#10 +
  240. 'For conditions of distribution and use, see TBX documentation.'#13#10 +
  241. #13#10 +
  242. 'Running on'#13#10 +
  243. '%s'#13#10 +
  244. '©1998-2004 by Jordan Russell'#13#10 +
  245. 'For conditions of distribution and use, see Toolbar2000 documentation.'#13#10 +
  246. #13#10 +
  247. 'Visit https://jrsoftware.org/ for the latest versions of Toolbar2000'#13#10 +
  248. '';
  249. begin
  250. case Index of
  251. 0: Edit;
  252. 1:
  253. begin
  254. MessageDlg(
  255. Format(AboutText,
  256. [TBXVersionText, Toolbar2000VersionPropText]),
  257. mtInformation, [mbOK], 0);
  258. end;
  259. end;
  260. end;
  261. { THookObj }
  262. type
  263. THookObj = class
  264. procedure HookProc(Sender: TTBItemEditForm);
  265. end;
  266. var O: THookObj;
  267. procedure THookObj.HookProc(Sender: TTBItemEditForm);
  268. var
  269. TB: TTBToolbar;
  270. Item: TTBCustomItem;
  271. NewItem: TTBItem;
  272. S: string;
  273. I: Integer;
  274. begin
  275. TB := TTBToolbar.Create(Sender);
  276. TB.Top := Sender.Height;
  277. TB.Parent := Sender;
  278. TB.Align := alTop;
  279. TB.Images := Sender.ToolbarItems.SubMenuImages;
  280. TB.ShowHint := True;
  281. for I := 0 to Sender.MoreMenu.Count - 1 do
  282. begin
  283. Item := Sender.MoreMenu.Items[I];
  284. if Item is TTBCustomItem then
  285. begin
  286. S := TTBCustomItemClass(Item.Tag).ClassName;
  287. if StrLComp(PChar(S), 'TTBX', 4) = 0 then
  288. begin
  289. NewItem := TTBItem.Create(TB);
  290. TB.Items.Add(NewItem);
  291. NewItem.Caption := Item.Caption;
  292. NewItem.ImageIndex := Item.ImageIndex;
  293. NewItem.Tag := Item.Tag;
  294. NewItem.Hint := S;
  295. NewItem.OnClick := Item.OnClick;
  296. end;
  297. end;
  298. end;
  299. end;
  300. procedure Register;
  301. begin
  302. RegisterComponents('Toolbar2000', [TTBXDock, TTBXToolbar,
  303. TTBXPopupMenu, TTBXColorSet, TTBXStatusBar]);
  304. RegisterNoIcon([TTBXItem, TTBXSubMenuItem, TTBXSeparatorItem,
  305. TTBXLabelItem, TTBXColorItem,
  306. TTBXDropDownItem,
  307. TTBXComboBoxItem, TTBXStringList, TTBXColorPalette]);
  308. RegisterClasses([TTBXItem, TTBXSubMenuItem, TTBXSeparatorItem,
  309. TTBXLabelItem, TTBXColorItem,
  310. TTBXDropDownItem,
  311. TTBXComboBoxItem, TTBXStringList, TTBXColorPalette]);
  312. RegisterComponentEditor(TTBXToolbar, TTBXItemsEditor);
  313. RegisterComponentEditor(TTBXPopupMenu, TTBXItemsEditor);
  314. RegisterPropertyEditor(TypeInfo(string), TTBXCustomItem, 'Caption', TMLStringProperty);
  315. RegisterPropertyEditor(TypeInfo(string), TTBXCustomItem, 'Hint', TMLStringProperty);
  316. RegisterPropertyEditor(TypeInfo(string), TTBXLabelItem, 'Caption', TCaptionProperty);
  317. RegisterPropertyEditor(TypeInfo(string), TTBToolbar, 'ChevronHint', TMLStringProperty);
  318. RegisterPropertyEditor(TypeInfo(string), TTBXToolbar, 'ChevronHint', TMLStringProperty);
  319. RegisterPropertyEditor(TypeInfo(TColor), TPersistent, '', TTBXColorProperty);
  320. RegisterComponentEditor(TTBXStatusBar, TTBXStatusBarEditor);
  321. TBRegisterItemClass(TTBXItem, 'New &TBX Item', HInstance);
  322. TBRegisterItemClass(TTBXSubMenuItem, 'New TBX Submenu Item', HInstance);
  323. TBRegisterItemClass(TTBXSeparatorItem, 'New TBX Separator Item', HInstance);
  324. TBRegisterItemClass(TTBXLabelItem, 'New TBX Label Item', HInstance);
  325. TBRegisterItemClass(TTBXColorItem, 'New TBX Color Item', HInstance);
  326. TBRegisterItemClass(TTBXDropDownItem, 'New TBX Drop Down Item', HInstance);
  327. TBRegisterItemClass(TTBXComboBoxItem, 'New TBX Combo Box Item', HInstance);
  328. TBRegisterItemClass(TTBXStringList, 'New TBX String List', HInstance);
  329. TBRegisterItemClass(TTBXColorPalette, 'New TBX Color Palette', HInstance);
  330. end;
  331. initialization
  332. O := THookObj.Create;
  333. TBUnregisterDsgnEditorHook(O.HookProc);
  334. TBRegisterDsgnEditorHook(O.HookProc);
  335. finalization
  336. TBUnregisterDsgnEditorHook(O.HookProc);
  337. O.Free;
  338. end.