TBXReg.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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. {$I TBX.inc}
  10. uses
  11. Windows, Classes, Controls, SysUtils, Graphics, ImgList, Dialogs,
  12. {$IFDEF JR_D6} DesignIntf, DesignEditors, VCLEditors, {$ELSE} DsgnIntf, {$ENDIF}
  13. TB2Reg, TB2Toolbar, TB2Item, TBX, {$IFNDEF MPEXCLUDE}TBXMDI, TBXSwitcher,{$ENDIF} TB2DsgnItemEditor,
  14. TBXExtItems, TBXLists, {$IFNDEF MPEXCLUDE}TBXDkPanels,{$ENDIF} TBXToolPals, TBXStatusBars;
  15. procedure Register;
  16. type
  17. TThemeProperty = class(TStringProperty)
  18. function GetAttributes: TPropertyAttributes; override;
  19. procedure GetValues(Proc: TGetStrProc); override;
  20. end;
  21. TMLStringProperty = class(TCaptionProperty)
  22. function GetAttributes: TPropertyAttributes; override;
  23. procedure Edit; override;
  24. end;
  25. {$IFDEF JR_D5}
  26. TTBXLinkImageIndexPropertyEditor = class(TTBImageIndexPropertyEditor)
  27. public
  28. function GetImageListAt(Index: Integer): TCustomImageList; override;
  29. end;
  30. {$ENDIF}
  31. TTBXColorProperty = class(TColorProperty)
  32. public
  33. function GetValue: string; override;
  34. procedure GetValues(Proc: TGetStrProc); override;
  35. procedure SetValue(const Value: string); override;
  36. {$IFDEF JR_D5}
  37. procedure ListDrawValue(const Value: string; ACanvas: TCanvas;
  38. const ARect: TRect; ASelected: Boolean);{$IFNDEF JR_D6} override;{$ENDIF}
  39. {$ENDIF}
  40. end;
  41. TTBXStatusBarEditor = class(TDefaultEditor)
  42. protected
  43. {$IFDEF JR_D6}
  44. procedure GetPanelsProp(const Prop: IProperty);
  45. {$ELSE}
  46. procedure GetPanelsProp(Prop: TPropertyEditor);
  47. {$ENDIF}
  48. public
  49. procedure Edit; override;
  50. procedure ExecuteVerb(Index: Integer); override;
  51. function GetVerb(Index: Integer): string; override;
  52. function GetVerbCount: Integer; override;
  53. end;
  54. TTBXItemsEditor = class(TTBItemsEditor)
  55. public
  56. procedure ExecuteVerb(Index: Integer); override;
  57. end;
  58. implementation
  59. uses
  60. Forms, TBXThemes, TBXStrEdit, TBXUtils, TypInfo, TB2Version;
  61. {$IFNDEF MPEXCLUDE}
  62. type
  63. TTBXLinkAccess = class(TTBXCustomLink);
  64. TTBXButtonAccess = class(TTBXCustomButton);
  65. {$ENDIF}
  66. { TThemeProperty }
  67. function TThemeProperty.GetAttributes: TPropertyAttributes;
  68. begin
  69. Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  70. end;
  71. procedure TThemeProperty.GetValues(Proc: TGetStrProc);
  72. var
  73. SL: TStringList;
  74. I: Integer;
  75. begin
  76. SL := TStringList.Create;
  77. GetAvailableTBXThemes(SL);
  78. for I := 0 to SL.Count - 1 do Proc(SL[I]);
  79. SL.Free;
  80. end;
  81. { TMLStringProperty }
  82. function WordCount(const S: string; const Delims: TSysCharSet): Integer;
  83. var
  84. L, I: Cardinal;
  85. begin
  86. Result := 0;
  87. I := 1;
  88. L := Length(S);
  89. while I <= L do
  90. begin
  91. while (I <= L) and {MP}CharInSet(S[I], Delims) do Inc(I);
  92. if I <= L then Inc(Result);
  93. while (I <= L) and not {MP}CharInSet(S[I], Delims) do Inc(I);
  94. end;
  95. end;
  96. function WordPosition(const N: Integer; const S: string;
  97. const WordDelims: TSysCharSet): Integer;
  98. var
  99. Count, I: Integer;
  100. begin
  101. Count := 0;
  102. I := 1;
  103. Result := 0;
  104. while (I <= Length(S)) and (Count <> N) do begin
  105. { skip over delimiters }
  106. while (I <= Length(S)) and {MP}CharInSet(S[I], WordDelims) do Inc(I);
  107. { if we're not beyond end of S, we're at the start of a word }
  108. if I <= Length(S) then Inc(Count);
  109. { if not finished, find the end of the current word }
  110. if Count <> N then
  111. while (I <= Length(S)) and not CharInSet(S[I], WordDelims) do Inc(I)
  112. else Result := I;
  113. end;
  114. end;
  115. function ExtractWord(N: Integer; const S: string;
  116. const WordDelims: TSysCharSet): string;
  117. var
  118. I: Integer;
  119. Len: Integer;
  120. begin
  121. Len := 0;
  122. I := WordPosition(N, S, WordDelims);
  123. if I <> 0 then
  124. { find the end of the current word }
  125. while (I <= Length(S)) and not CharInSet(S[I], WordDelims) do begin
  126. { add the I'th character to result }
  127. Inc(Len);
  128. SetLength(Result, Len);
  129. Result[Len] := S[I];
  130. Inc(I);
  131. end;
  132. SetLength(Result, Len);
  133. end;
  134. procedure TMLStringProperty.Edit;
  135. var
  136. Temp: string;
  137. Component: TPersistent;
  138. I, N: Integer;
  139. begin
  140. with TStrEditDlg.Create(Application) do
  141. try
  142. Component := GetComponent(0);
  143. if Component is TComponent then Caption := TComponent(Component).Name + '.' + GetName
  144. else Caption := GetName;
  145. Temp := GetStrValue;
  146. N := WordCount(Temp, [#13, #10]);
  147. for I := 1 to N do Memo.Lines.Add(ExtractWord(I, Temp, [#13, #10]));
  148. Memo.MaxLength := GetEditLimit;
  149. if ShowModal = mrOk then
  150. begin
  151. Temp := Memo.Text;
  152. while (Length(Temp) > 0) and (Temp[Length(Temp)] < ' ') do
  153. System.Delete(Temp, Length(Temp), 1);
  154. SetStrValue(Temp);
  155. end;
  156. finally
  157. Free;
  158. end;
  159. end;
  160. function TMLStringProperty.GetAttributes: TPropertyAttributes;
  161. begin
  162. Result := inherited GetAttributes + [paDialog];
  163. end;
  164. {$IFDEF JR_D5}
  165. { TTBXLinkImageIndexPropertyEditor }
  166. function TTBXLinkImageIndexPropertyEditor.GetImageListAt(Index: Integer): TCustomImageList;
  167. {$IFNDEF MPEXCLUDE}
  168. var
  169. C: TPersistent;
  170. {$ENDIF}
  171. begin
  172. Result := nil;
  173. {$IFNDEF MPEXCLUDE}
  174. C := GetComponent(Index);
  175. if C is TTBXCustomLink then
  176. Result := TTBXLinkAccess(C).Images
  177. else if C is TTBXCustomButton then
  178. Result := TTBXButtonAccess(C).Images;
  179. {$ENDIF}
  180. end;
  181. {$ENDIF}
  182. { TTBXColorProperty }
  183. function TTBXColorProperty.GetValue: string;
  184. begin
  185. Result := TBXColorToString(TColor(GetOrdValue));
  186. end;
  187. procedure TTBXColorProperty.GetValues(Proc: TGetStrProc);
  188. begin
  189. TBXGetColorValues(Proc);
  190. end;
  191. procedure TTBXColorProperty.SetValue(const Value: string);
  192. begin
  193. SetOrdValue(TBXStringToColor(Value));
  194. end;
  195. {$IFDEF JR_D5}
  196. procedure TTBXColorProperty.ListDrawValue(const Value: string; ACanvas: TCanvas;
  197. const ARect: TRect; ASelected: Boolean);
  198. function ColorToBorderColor(AColor: TColor): TColor;
  199. begin
  200. if IsDarkColor(AColor) then
  201. begin
  202. Result := AColor;
  203. SetContrast(Result, AColor, 40);
  204. end
  205. else Result := clBlack;
  206. end;
  207. var
  208. R: TRect;
  209. C: TColor;
  210. OldPenColor, OldBrushColor: TColor;
  211. begin
  212. R := ARect;
  213. with ACanvas do
  214. try
  215. OldPenColor := Pen.Color;
  216. OldBrushColor := Brush.Color;
  217. Pen.Color := Brush.Color;
  218. Rectangle(R);
  219. R.Right := (ARect.Bottom - ARect.Top) + ARect.Left;
  220. InflateRect(R, -1, -1);
  221. C := TBXStringToColor(Value);
  222. if C <> clNone then
  223. begin
  224. Brush.Color := C;
  225. Pen.Color := ColorToBorderColor(ColorToRGB(C));
  226. Rectangle(R);
  227. end
  228. else
  229. begin
  230. Brush.Color := clWindow;
  231. Pen.Color := clBtnShadow;
  232. Rectangle(R);
  233. MoveTo(R.Left, R.Bottom - 1);
  234. LineTo(R.Right - 1, R.Top);
  235. MoveTo(R.Left, R.Top);
  236. LineTo(R.Right, R.Bottom);
  237. end;
  238. Brush.Color := OldBrushColor;
  239. Pen.Color := OldPenColor;
  240. finally
  241. R.Left := R.Right;
  242. R.Right := ARect.Right;
  243. ACanvas.TextRect(R, R.Left + 1, R.Top + 1, Value);
  244. end;
  245. end;
  246. {$ENDIF}
  247. { TTBXStatusBarEditor }
  248. procedure TTBXStatusBarEditor.Edit;
  249. var
  250. {$IFDEF JR_D6}
  251. Components: IDesignerSelections;
  252. {$ELSE}
  253. {$IFDEF JR_D5}
  254. Components: TDesignerSelectionList;
  255. {$ELSE}
  256. Components: TComponentList;
  257. {$ENDIF}
  258. {$ENDIF}
  259. begin
  260. {$IFDEF JR_D6}
  261. Components := CreateSelectionList;
  262. {$ELSE}
  263. {$IFDEF JR_D5}
  264. Components := TDesignerSelectionList.Create;
  265. {$ELSE}
  266. Components := TComponentList.Create;
  267. {$ENDIF}
  268. {$ENDIF}
  269. try
  270. Components.Add(Component);
  271. GetComponentProperties(Components, [tkClass], Designer, GetPanelsProp);
  272. finally
  273. {$IFNDEF JR_D6}
  274. Components.Free;
  275. {$ENDIF}
  276. end;
  277. end;
  278. procedure TTBXStatusBarEditor.ExecuteVerb(Index: Integer);
  279. begin
  280. if Index = 0 then Edit;
  281. end;
  282. function TTBXStatusBarEditor.GetVerb(Index: Integer): string;
  283. begin
  284. if Index = 0 then Result := '&Panels Editor...';
  285. end;
  286. function TTBXStatusBarEditor.GetVerbCount: Integer;
  287. begin
  288. Result := 1;
  289. end;
  290. {$IFDEF JR_D6}
  291. procedure TTBXStatusBarEditor.GetPanelsProp(const Prop: IProperty);
  292. begin
  293. if SameText(Prop.GetName, 'Panels') then Prop.Edit;
  294. end;
  295. {$ELSE}
  296. procedure TTBXStatusBarEditor.GetPanelsProp(Prop: TPropertyEditor);
  297. begin
  298. if CompareText(Prop.GetName, 'Panels') = 0 then Prop.Edit;
  299. end;
  300. {$ENDIF}
  301. { TTBXItemsEditor }
  302. procedure TTBXItemsEditor.ExecuteVerb(Index: Integer);
  303. const
  304. AboutText =
  305. '%s'#13#10 +
  306. '©2001–2004 Alex A. Denisov'#13#10 +
  307. 'For conditions of distribution and use, see TBX documentation.'#13#10 +
  308. 'Visit http://g32.org/tbx/ for the latest versions of TBX'#13#10 +
  309. #13#10 +
  310. 'Running on'#13#10 +
  311. '%s'#13#10 +
  312. '©1998-2004 by Jordan Russell'#13#10 +
  313. 'For conditions of distribution and use, see Toolbar2000 documentation.'#13#10 +
  314. #13#10 +
  315. 'Visit http://www.jrsoftware.org/ for the latest versions of Toolbar2000'#13#10 +
  316. '';
  317. begin
  318. case Index of
  319. 0: Edit;
  320. 1:
  321. begin
  322. MessageDlg(
  323. Format(AboutText,
  324. [TBXVersionText, Toolbar2000VersionPropText]),
  325. mtInformation, [mbOK], 0);
  326. end;
  327. end;
  328. end;
  329. { THookObj }
  330. type
  331. THookObj = class
  332. procedure HookProc(Sender: TTBItemEditForm);
  333. end;
  334. var O: THookObj;
  335. procedure THookObj.HookProc(Sender: TTBItemEditForm);
  336. var
  337. TB: TTBToolbar;
  338. Item: TTBCustomItem;
  339. NewItem: TTBItem;
  340. S: string;
  341. I: Integer;
  342. begin
  343. TB := TTBToolbar.Create(Sender);
  344. TB.Top := Sender.Height;
  345. TB.Parent := Sender;
  346. TB.Align := alTop;
  347. TB.Images := Sender.ToolbarItems.SubMenuImages;
  348. TB.ShowHint := True;
  349. for I := 0 to Sender.MoreMenu.Count - 1 do
  350. begin
  351. Item := Sender.MoreMenu.Items[I];
  352. if Item is TTBCustomItem then
  353. begin
  354. S := TTBCustomItemClass(Item.Tag).ClassName;
  355. if StrLComp(PChar(S), 'TTBX', 4) = 0 then
  356. begin
  357. NewItem := TTBItem.Create(TB);
  358. TB.Items.Add(NewItem);
  359. NewItem.Caption := Item.Caption;
  360. NewItem.ImageIndex := Item.ImageIndex;
  361. NewItem.Tag := Item.Tag;
  362. NewItem.Hint := S;
  363. NewItem.OnClick := Item.OnClick;
  364. end;
  365. end;
  366. end;
  367. end;
  368. procedure Register;
  369. begin
  370. RegisterComponents('Toolbar2000', [TTBXDock, {$IFNDEF MPEXCLUDE}TTBXMultiDock,{$ENDIF} TTBXToolbar,
  371. {$IFNDEF MPEXCLUDE}TTBXToolWindow, TTBXDockablePanel,{$ENDIF} TTBXPopupMenu, {$IFNDEF MPEXCLUDE}TTBXSwitcher, TTBXMRUList,
  372. TTBXMDIHandler, TTBXPageScroller,{$ENDIF} TTBXColorSet, {$IFNDEF MPEXCLUDE}TTBXAlignmentPanel,
  373. TTBXLabel, TTBXLink, TTBXButton, TTBXCheckBox, TTBXRadioButton,{$ENDIF} TTBXStatusBar]);
  374. RegisterNoIcon([TTBXItem, TTBXSubMenuItem, TTBXSeparatorItem,
  375. {$IFNDEF MPEXCLUDE}TTBXVisibilityToggleItem,{$ENDIF} TTBXLabelItem, {$IFNDEF MPEXCLUDE}TTBXMRUListItem,{$ENDIF} TTBXColorItem,
  376. {$IFNDEF MPEXCLUDE}TTBXMDIWindowItem, TTBXEditItem, TTBXSpinEditItem,{$ENDIF} TTBXDropDownItem,
  377. TTBXComboBoxItem, TTBXStringList{$IFNDEF MPEXCLUDE}, TTBXUndoList, TTBXToolPalette{$ENDIF}, TTBXColorPalette]);
  378. {$IFDEF COMPATIBLE_CTL}
  379. RegisterNoIcon([TTBXList, TTBXComboItem, TTBXComboList]);
  380. {$ENDIF}
  381. RegisterClasses([TTBXItem, TTBXSubMenuItem, TTBXSeparatorItem,
  382. {$IFNDEF MPEXCLUDE}TTBXVisibilityToggleItem,{$ENDIF} TTBXLabelItem, {$IFNDEF MPEXCLUDE}TTBXMRUListItem,{$ENDIF} TTBXColorItem,
  383. {$IFNDEF MPEXCLUDE}TTBXMDIWindowItem, TTBXEditItem, TTBXSpinEditItem,{$ENDIF} TTBXDropDownItem,
  384. TTBXComboBoxItem, TTBXStringList{$IFNDEF MPEXCLUDE}, TTBXUndoList, TTBXToolPalette{$ENDIF}, TTBXColorPalette]);
  385. {$IFDEF COMPATIBLE_CTL}
  386. RegisterClasses([TTBXList, TTBXComboItem, TTBXComboList]);
  387. {$ENDIF}
  388. RegisterComponentEditor(TTBXToolbar, TTBXItemsEditor);
  389. RegisterComponentEditor(TTBXPopupMenu, TTBXItemsEditor);
  390. RegisterPropertyEditor(TypeInfo(string), TTBXCustomItem, 'Caption', TMLStringProperty);
  391. RegisterPropertyEditor(TypeInfo(string), TTBXCustomItem, 'Hint', TMLStringProperty);
  392. RegisterPropertyEditor(TypeInfo(string), TTBXLabelItem, 'Caption', TCaptionProperty);
  393. RegisterPropertyEditor(TypeInfo(string), TTBToolbar, 'ChevronHint', TMLStringProperty);
  394. RegisterPropertyEditor(TypeInfo(string), TTBXToolbar, 'ChevronHint', TMLStringProperty);
  395. {$IFNDEF MPEXCLUDE}
  396. RegisterPropertyEditor(TypeInfo(string), TTBXSwitcher, 'Theme', TThemeProperty);
  397. {$ENDIF}
  398. {$IFDEF JR_D5}
  399. {$IFNDEF MPEXCLUDE}
  400. RegisterPropertyEditor(TypeInfo(TImageIndex), TTBXCustomLink, 'ImageIndex', TTBXLinkImageIndexPropertyEditor);
  401. RegisterPropertyEditor(TypeInfo(TImageIndex), TTBXCustomButton, 'ImageIndex', TTBXLinkImageIndexPropertyEditor);
  402. {$ENDIF}
  403. {$ENDIF}
  404. {$IFDEF NEWCOLORPROPERTY}
  405. RegisterPropertyEditor(TypeInfo(TColor), TPersistent, '', TTBXColorProperty);
  406. {$ENDIF}
  407. RegisterComponentEditor(TTBXStatusBar, TTBXStatusBarEditor);
  408. TBRegisterItemClass(TTBXItem, 'New &TBX Item', HInstance);
  409. TBRegisterItemClass(TTBXSubMenuItem, 'New TBX Submenu Item', HInstance);
  410. TBRegisterItemClass(TTBXSeparatorItem, 'New TBX Separator Item', HInstance);
  411. {$IFNDEF MPEXCLUDE}
  412. TBRegisterItemClass(TTBXVisibilityToggleItem, 'New TBX Visibility Toggle Item', HInstance);
  413. {$ENDIF}
  414. TBRegisterItemClass(TTBXLabelItem, 'New TBX Label Item', HInstance);
  415. {$IFNDEF MPEXCLUDE}
  416. TBRegisterItemClass(TTBXMRUListItem, 'New TBX MRU List Item', HInstance);
  417. {$ENDIF}
  418. TBRegisterItemClass(TTBXColorItem, 'New TBX Color Item', HInstance);
  419. {$IFNDEF MPEXCLUDE}
  420. TBRegisterItemClass(TTBXMDIWindowItem, 'New TBX MDI Window Item', HInstance);
  421. TBRegisterItemClass(TTBXEditItem, 'New TBX Edit Item', HInstance);
  422. TBRegisterItemClass(TTBXSpinEditItem, 'New TBX Spin Edit Item', HInstance);
  423. {$ENDIF}
  424. TBRegisterItemClass(TTBXDropDownItem, 'New TBX Drop Down Item', HInstance);
  425. TBRegisterItemClass(TTBXComboBoxItem, 'New TBX Combo Box Item', HInstance);
  426. TBRegisterItemClass(TTBXStringList, 'New TBX String List', HInstance);
  427. {$IFNDEF MPEXCLUDE}
  428. TBRegisterItemClass(TTBXUndoList, 'New TBX Undo List', HInstance);
  429. TBRegisterItemClass(TTBXToolPalette, 'New TBX Tool Palette', HInstance);
  430. {$ENDIF}
  431. TBRegisterItemClass(TTBXColorPalette, 'New TBX Color Palette', HInstance);
  432. {$IFDEF COMPATIBLE_CTL}
  433. TBRegisterItemClass(TTBXComboItem, 'New TBX Combo Item (use TBX DropDown instead)', HInstance);
  434. TBRegisterItemClass(TTBXList, 'New TBX List (use TBX String List instead)', HInstance);
  435. TBRegisterItemClass(TTBXComboList, 'New TBX Combo List (use TBX Combo Box Instead)', HInstance);
  436. {$ENDIF}
  437. end;
  438. initialization
  439. O := THookObj.Create;
  440. TBUnregisterDsgnEditorHook(O.HookProc);
  441. TBRegisterDsgnEditorHook(O.HookProc);
  442. finalization
  443. TBUnregisterDsgnEditorHook(O.HookProc);
  444. O.Free;
  445. end.