/Turbo5/TurboPhp/bin/Palette.pas

http://turbophp.googlecode.com/ · Pascal · 289 lines · 180 code · 26 blank · 83 comment · 7 complexity · a022d9c9e930c51a445988563a172e54 MD5 · raw file

  1. unit Palette;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, ImgList, ComCtrls, ExtCtrls,
  6. DCPalette, dcpalet, DCGen,
  7. LMDCustomComponent, LMDBaseController, LMDCustomContainer,
  8. LMDCustomImageList, LMDImageList, LMDControl, LMDBaseControl,
  9. LMDBaseGraphicControl, LMDBaseLabel, LMDCustomGlyphLabel, LMDGlyphLabel,
  10. LMDGraph,
  11. LrCollapsable;
  12. type
  13. TPaletteForm = class(TForm)
  14. PaletteScroll: TScrollBox;
  15. DCCompPalette1: TDCCompPalette;
  16. LMDImageList1: TLMDImageList;
  17. LrCollapsable1: TLrCollapsable;
  18. LMDGlyphLabel3: TLMDGlyphLabel;
  19. procedure FormCreate(Sender: TObject);
  20. procedure FormShow(Sender: TObject);
  21. private
  22. { Private declarations }
  23. FSelectedLabel: TControl;
  24. procedure PaletteLabelClick(Sender: TObject);
  25. procedure PaletteLabelMouseDown(Sender: TObject; Button: TMouseButton;
  26. Shift: TShiftState; X, Y: Integer);
  27. procedure PaletteLabelMouseEnter(Sender: TObject);
  28. procedure PaletteLabelMouseExit(Sender: TObject);
  29. procedure SetSelectedLabel(const Value: TControl);
  30. protected
  31. procedure CreateWnd; override;
  32. public
  33. { Public declarations }
  34. procedure BuildPalette;
  35. procedure GetAddClass(Sender: TObject; var ioClass: String);
  36. property SelectedLabel: TControl read FSelectedLabel write SetSelectedLabel;
  37. end;
  38. var
  39. PaletteForm: TPaletteForm;
  40. implementation
  41. uses
  42. LrUtils, DesignManager;
  43. {$R *.dfm}
  44. procedure TPaletteForm.FormCreate(Sender: TObject);
  45. begin
  46. BuildPalette;
  47. Width := Width + 1;
  48. DesignMgr.OnGetAddClass := GetAddClass;
  49. end;
  50. procedure TPaletteForm.BuildPalette;
  51. var
  52. i, j: Integer;
  53. l: TLMDGlyphLabel;
  54. // r: TJvRollOut;
  55. // r: TFoldingPanelForm;
  56. // r: TLrGroup;
  57. r: TLrCollapsable;
  58. // r: TPanel;
  59. {
  60. procedure CreateGroup;
  61. begin
  62. r := TJvRollOut.Create(Self);
  63. r.ParentColor := false;
  64. //
  65. r.Colors.ButtonBottom := clBlack;
  66. r.Colors.ButtonColor := $00BEF3CA; //$00FDF9F7;
  67. //r.Colors.ButtonTop := clRed;
  68. r.Colors.FrameBottom := clWhite;
  69. r.Colors.FrameTop := $0094EBA7; //$00F3D1BE;
  70. //r.Colors.HotTrackText := clGray;
  71. r.Colors.Color := clWhite; //$00EFF7F8;
  72. //
  73. r.ChildOffset := 1;
  74. r.Parent := PaletteScroll;
  75. r.Top := 9999;
  76. r.Align := alTop;
  77. r.AutoSize := true;
  78. r.Caption := DCCompPalette1.Tabs[i];
  79. end;
  80. }
  81. {
  82. procedure CreateGroup;
  83. begin
  84. AddForm(r, TFoldingPanelForm, PaletteScroll);
  85. r.Top := 9999;
  86. r.Align := alTop;
  87. end;
  88. }
  89. {
  90. procedure CreateGroup(const inCaption: string);
  91. begin
  92. r := TLrGroup.Create(Self);
  93. r.Caption := inCaption;
  94. r.AutoSize := true;
  95. r.Margin := 2;
  96. r.Special := true;
  97. r.Parent := LrBar1;
  98. r.Top := 9999;
  99. r.Align := alTop;
  100. end;
  101. }
  102. procedure CreateGroup(const inCaption: string);
  103. begin
  104. r := TLrCollapsable.Create(Self);
  105. r.Caption := inCaption;
  106. r.AutoSize := true;
  107. r.Parent := PaletteScroll;
  108. r.Color := $F9F9F9;
  109. r.HeaderColor := $E1E1E1;
  110. r.ParentFont := true;
  111. r.Font.Style := [ fsBold ];
  112. //r.Top := 9999;
  113. r.Align := alTop;
  114. SetBounds(0, 0, 120, 120);
  115. r.Visible := true;
  116. end;
  117. {
  118. procedure CreateGroup(const inCaption: string);
  119. begin
  120. r := TPanel.Create(Self);
  121. r.AutoSize := true;
  122. r.BevelInner := TBevelCut(0);
  123. r.BevelOuter := TBevelCut(0);
  124. with LMDExplorerBar1.Sections.Add do
  125. begin
  126. Caption := inCaption;
  127. HeaderSize := 20;
  128. Style := ebsContainer;
  129. LinkedControl := r;
  130. Height := 120;
  131. end;
  132. end;
  133. }
  134. function AddImage(const inClass: TClass): Integer;
  135. var
  136. b, c: TBitmap;
  137. begin
  138. b := TBitmap.Create;
  139. try
  140. LoadBitmapForClass(b, inClass);
  141. b.Transparent := true;
  142. if (b.Width <> 16) then
  143. begin
  144. c := b;
  145. b := TBitmap.Create;
  146. try
  147. b.Width := c.Width;
  148. b.Height := c.Height;
  149. b.Canvas.Brush.Color := clWhite;
  150. b.Canvas.FillRect(Rect(0, 0, c.Width, c.Height));
  151. b.Canvas.Draw(0, 0, c);
  152. finally
  153. c.Free;
  154. end;
  155. c := b;
  156. b := TBitmap.Create;
  157. try
  158. b.Width := 16;
  159. b.Height := 16;
  160. b.Canvas.StretchDraw(Rect(0,0,15,15), c);
  161. finally
  162. c.Free;
  163. end;
  164. end;
  165. Result := LMDImageList1.Items[0].Add(b, nil);
  166. finally
  167. b.Free;
  168. end;
  169. end;
  170. procedure CreateLabel(inButton: TDCPaletteButton);
  171. begin
  172. l := TLMDGlyphLabel.Create(Self);
  173. //
  174. //l.Caption := TurboClassInfo.DisplayName[inButton.ButtonName];
  175. l.Caption := inButton.ButtonName;
  176. l.Hint := inButton.ButtonName;
  177. //
  178. l.Align := alTop;
  179. l.Cursor := crHandPoint;
  180. l.Bevel.StandardStyle := lsSingle;
  181. l.Alignment.Alignment := agCenterLeft;
  182. l.Color := clLime;
  183. //l.DragMode := dmAutomatic;
  184. //
  185. l.OnMouseEnter := PaletteLabelMouseEnter;
  186. l.OnMouseExit := PaletteLabelMouseExit;
  187. l.OnClick := PaletteLabelClick;
  188. //l.OnStartDrag := PaletteLabelStartDrag;
  189. l.OnMouseDown := PaletteLabelMouseDown;
  190. //
  191. l.ImageList := LMDImageList1;
  192. l.ListIndex := 0;
  193. //l.ImageIndex := inButton.ImageIndex;
  194. l.ImageIndex := AddImage(TDCCompButton(inButton).ComponentClass);
  195. //
  196. l.AutoSize := false;
  197. l.Height := l.Height + 4;
  198. //
  199. l.Parent := r;
  200. l.Font.Style := [];
  201. //l.Parent := r.ContentPanel;
  202. end;
  203. begin
  204. for i := 0 to Pred(DCCompPalette1.PageCount) do
  205. begin
  206. CreateGroup(DCCompPalette1.Tabs[i]);
  207. with DCCompPalette1.ButtonTabs[i] do
  208. begin
  209. //r.Height := ButtonCount * 16 + 20;
  210. for j := Pred(ButtonCount) downto 0 do
  211. CreateLabel(Buttons[j]);
  212. //r.Height := 0;
  213. end;
  214. end;
  215. end;
  216. procedure TPaletteForm.CreateWnd;
  217. begin
  218. inherited;
  219. // if PaletteScroll <> nil then
  220. // PaletteScroll.Realign;
  221. end;
  222. procedure TPaletteForm.FormShow(Sender: TObject);
  223. begin
  224. with PaletteScroll do
  225. Width := Width + 1;
  226. end;
  227. procedure TPaletteForm.SetSelectedLabel(const Value: TControl);
  228. begin
  229. if (SelectedLabel <> nil) then
  230. TLMDGlyphLabel(SelectedLabel).Font.Style := [ ];
  231. FSelectedLabel := Value;
  232. if (SelectedLabel <> nil) then
  233. TLMDGlyphLabel(Value).Font.style := [ fsBold ];
  234. end;
  235. procedure TPaletteForm.PaletteLabelMouseEnter(Sender: TObject);
  236. begin
  237. with TLMDGlyphLabel(Sender) do
  238. Font.Style := Font.Style + [ fsUnderline ];
  239. end;
  240. procedure TPaletteForm.PaletteLabelMouseExit(Sender: TObject);
  241. begin
  242. with TLMDGlyphLabel(Sender) do
  243. Font.Style := Font.Style - [ fsUnderline ];
  244. end;
  245. procedure TPaletteForm.PaletteLabelMouseDown(Sender: TObject;
  246. Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  247. begin
  248. if Button = mbLeft then
  249. TControl(Sender).BeginDrag(False);
  250. end;
  251. procedure TPaletteForm.PaletteLabelClick(Sender: TObject);
  252. begin
  253. SelectedLabel := TControl(Sender);
  254. end;
  255. procedure TPaletteForm.GetAddClass(Sender: TObject; var ioClass: String);
  256. begin
  257. if SelectedLabel <> nil then
  258. begin
  259. ioClass := SelectedLabel.Hint;
  260. SelectedLabel := nil;
  261. end;
  262. end;
  263. end.