FlatEditor.pas 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. unit FlatEditor;
  2. interface
  3. {$I FlatStyle.inc}
  4. uses
  5. {$IFDEF DELPHI_6_UP}
  6. DesignIntf, DesignEditors, DesignMenus,
  7. {$ELSE}
  8. DsgnIntf,
  9. {$ENDIF}
  10. Classes, MaskUtils, SysUtils, Controls, Forms, TypInfo;
  11. procedure Register;
  12. implementation
  13. uses
  14. FlatCtrls, FlatSysex, FlatUtils, FlatAttrib, FlatVersion, FlatWatfm;
  15. { TWaterEditor }
  16. type TWaterEditor = class(TStringProperty)
  17. public
  18. procedure Edit; override;
  19. function GetValue: string; override;
  20. function GetWater: TDefineWater;
  21. function GetAttributes: TPropertyAttributes; override;
  22. property Water: TDefineWater read GetWater;
  23. end;
  24. procedure TWaterEditor.Edit;
  25. begin
  26. with TWaterForm.Create(WaterForm) do
  27. begin
  28. try
  29. WaterList.Items.Assign(Water.Items);
  30. FlatWater.Items.Assign(Water.Items);
  31. ShowModal;
  32. if ModalResult = mrOk then
  33. begin
  34. Water.Items.Assign(WaterList.Items);
  35. TWaterEditor(self).Designer.Modified;
  36. end;
  37. finally
  38. Free;
  39. end;
  40. end;
  41. end;
  42. function TWaterEditor.GetAttributes: TPropertyAttributes;
  43. begin
  44. Result := [paDialog];
  45. end;
  46. function TWaterEditor.GetValue: string;
  47. begin
  48. Result := '(Editor)';
  49. end;
  50. function TWaterEditor.GetWater: TDefineWater;
  51. begin
  52. result := (GetComponent(0) as TDefineWater);
  53. end;
  54. { TMaskEditor }
  55. type TMaskEditor = class(TStringProperty)
  56. public
  57. procedure Edit; override;
  58. function GetValue: string; override;
  59. function GetMask: TDefineMask;
  60. function GetAttributes: TPropertyAttributes; override;
  61. property Mask: TDefineMask read GetMask;
  62. end;
  63. function TMaskEditor.GetAttributes: TPropertyAttributes;
  64. begin
  65. Result := [paDialog];
  66. end;
  67. function TMaskEditor.GetValue: string;
  68. begin
  69. Result := Mask.Text;
  70. end;
  71. function TMaskEditor.GetMask: TDefineMask;
  72. begin
  73. result := (GetComponent(0) as TDefineMask);
  74. end;
  75. procedure TMaskEditor.Edit;
  76. begin
  77. with TMaskForm.Create(MaskForm) do
  78. begin
  79. try
  80. Font.Assign(Screen.MenuFont);
  81. EditText.EditMask := Mask.EditMask;
  82. EditText.Text := Mask.Text;
  83. if Mask.EditMask <> '' then
  84. EditMask.Text := Mask.EditMask;
  85. ShowModal;
  86. if ModalResult = mrOk then
  87. begin
  88. Mask.Text := EditText.Text;
  89. TMaskEditor(Self).Designer.Modified;
  90. end;
  91. finally
  92. Free;
  93. end;
  94. end;
  95. end;
  96. { TVersionEditor }
  97. type TVersionEditor = class(TPropertyEditor)
  98. private
  99. function GetGropName: TComponent;
  100. public
  101. procedure Edit; override;
  102. function GetValue: string; override;
  103. function GetAttributes: TPropertyAttributes; override;
  104. property GropName:TComponent read GetGropName;
  105. end;
  106. procedure TVersionEditor.Edit;
  107. const
  108. AboutStr = '1.Information' +#13+
  109. '>>Control: %s' +#13+
  110. '>>Version: %s' +#13+
  111. '>>In Unit: %s.pas'+#13+
  112. '2.Packages' +#13+
  113. '>>Version: %s' +#13+
  114. '>>Copyright: %s'+#13+
  115. '3.Compile Platform'+#13+
  116. '>>Version: %s' +#13+
  117. '4.Completion Date'+#13+
  118. '>>Date: %s'+#13+
  119. '5.This version by the comerose update!';
  120. var
  121. vName,vUnit:String;
  122. vInfo: PTypeData;
  123. begin
  124. with TVersionForm.Create(VersionForm) do begin
  125. try
  126. Font.Assign(Screen.MenuFont);
  127. Caption := 'About FlatStyle components';
  128. if GropName <> nil then begin
  129. vInfo := GetTypeData(PTypeInfo(GropName.ClassInfo));
  130. vName := GropName.ClassName;
  131. vUnit := vInfo.UnitName;
  132. end else
  133. vName := 'Unkown class';
  134. About.Caption := format(AboutStr,[vName,FileVersion,vUnit,FileVersion,
  135. FileCopyright,CompilePlat,FileFinish]);
  136. Height := About.Top*2 + About.Height + OkBtn.Height*3;
  137. Width := About.Left*2 + About.Width;
  138. OkBtn.Top := About.Height + OkBtn.Height;
  139. OkBtn.Left := (Width-OkBtn.Width) div 2;
  140. ShowModal;
  141. finally
  142. Free;
  143. end;
  144. end;
  145. end;
  146. function TVersionEditor.GetAttributes: TPropertyAttributes;
  147. begin
  148. Result := [paDialog];
  149. end;
  150. function TVersionEditor.GetGropName: TComponent;
  151. var
  152. Vers:TPersistent;
  153. begin
  154. Vers := GetComponent(0);
  155. if Vers is TVersionEdit then
  156. result := TVersionEdit(Vers)
  157. else if Vers is TVersionComboBox then
  158. result := TVersionComboBox(Vers)
  159. else if Vers is TVersionControl then
  160. result := TVersionControl(Vers)
  161. else if Vers is TVersionGraphic then
  162. result := TVersionGraphic(Vers)
  163. else if Vers is TVersionTreeView then
  164. result := TVersionTreeView(Vers)
  165. else if Vers is TVersionListView then
  166. result := TVersionListView(Vers)
  167. else if Vers is TVersionComponent then
  168. result := TVersionComponent(Vers)
  169. else if Vers is TVersionMemo then
  170. result := TVersionMemo(Vers)
  171. else if Vers is TVersionPages then
  172. result := TVersionPages(Vers)
  173. else if Vers is TVersionSheet then
  174. result := TVersionSheet(Vers)
  175. else if Vers is TVersionCtrlExt then
  176. result := TVersionCtrlExt(Vers)
  177. else if Vers is TVersionDBGrid then
  178. result := TVersionDBGrid(Vers)
  179. else if Vers is TVersionDrawGrid then
  180. result := TVersionDrawGrid(Vers)
  181. else
  182. result := nil;
  183. end;
  184. function TVersionEditor.GetValue: string;
  185. begin
  186. result := FileVersion;
  187. end;
  188. type
  189. TExcelEditor = class(TDefaultEditor)
  190. private
  191. function GetDefineExcel: TDefineExcel;
  192. public
  193. procedure ExecuteVerb(index: Integer); override;
  194. function GetVerb(index: Integer): String; override;
  195. function GetVerbCount: Integer; override;
  196. property Excel:TDefineExcel read GetDefineExcel;
  197. end;
  198. procedure TExcelEditor.ExecuteVerb(index: Integer);
  199. begin
  200. case index of
  201. 0: Excel.InitFields;
  202. 1: Excel.RestoreFields;
  203. 2: Excel.ClearFields;
  204. end;
  205. TExcelEditor(self).Designer.Modified;
  206. end;
  207. function TExcelEditor.GetDefineExcel: TDefineExcel;
  208. begin
  209. result := (Component as TDefineExcel);
  210. end;
  211. function TExcelEditor.GetVerb(index: Integer): String;
  212. begin
  213. case index of
  214. 0: result := '添加全部字段';
  215. 1: result := '还原--->字段';
  216. 2: result := '清除全部字段';
  217. end;
  218. end;
  219. function TExcelEditor.GetVerbCount: Integer;
  220. begin
  221. result := 3;
  222. end;
  223. type
  224. TFlatActivePage = class(TComponentProperty)
  225. public
  226. function GetAttributes: TPropertyAttributes; override;
  227. procedure GetValues(Proc: TGetStrProc); override;
  228. end;
  229. function TFlatActivePage.GetAttributes: TPropertyAttributes;
  230. begin
  231. Result := [paValueList];
  232. end;
  233. procedure TFlatActivePage.GetValues(Proc: TGetStrProc);
  234. var
  235. I: Integer;
  236. Component: TComponent;
  237. begin
  238. for I := 0 to Designer.GetRoot.ComponentCount - 1 do
  239. begin
  240. Component := Designer.GetRoot.Components[I];
  241. if (Component.Name <> '') and (Component is TFlatSheet) and
  242. (TFlatSheet(Component).PageControl = GetComponent(0)) then
  243. Proc(Component.Name);
  244. end;
  245. end;
  246. type
  247. TPagesEditor = class(TComponentEditor)
  248. public
  249. procedure ExecuteVerb(Index: Integer); override;
  250. function GetVerb(Index: Integer): string; override;
  251. function GetVerbCount: Integer; override;
  252. end;
  253. procedure TPagesEditor.ExecuteVerb(Index: Integer);
  254. var
  255. Pages: TFlatPages;
  256. Sheet: TFlatSheet;
  257. {$IFDEF DELPHI3}
  258. ADesigner: TFormDesigner;
  259. {$ELSE}
  260. {$IFDEF DELPHI_6_UP}
  261. ADesigner: IDesigner;
  262. {$ELSE}
  263. ADesigner: IFormDesigner;
  264. {$ENDIF}
  265. {$ENDIF}
  266. begin
  267. if Component is TFlatSheet then
  268. Pages := TFlatSheet(Component).PageControl as TFlatPages
  269. else
  270. Pages := TFlatPages(Component);
  271. if Pages <> nil then
  272. begin
  273. ADesigner := Self.Designer;
  274. case Index of
  275. 0: begin
  276. {$IFDEF DELPHI_6_UP}
  277. Sheet := TFlatSheet.Create(ADesigner.Root);
  278. {$ELSE}
  279. Sheet := TFlatSheet.Create(ADesigner.Form);
  280. {$ENDIF}
  281. try
  282. Sheet.Name := ADesigner.UniqueName(TFlatSheet.ClassName);
  283. Sheet.Parent := Pages;
  284. Sheet.PageControl := Pages;
  285. Sheet.ImageIndex := Sheet.TabIndex;
  286. except
  287. Sheet.Free;
  288. raise
  289. end;
  290. Pages.ActivePage := Sheet;
  291. Pages.UpdateGlyphs;
  292. ADesigner.SelectComponent(Sheet);
  293. end;
  294. 1,2:begin
  295. Sheet := Pages.FindNextPage(Pages.ActivePage,Index=1,False) as TFlatSheet;
  296. if (Sheet <> nil) then begin
  297. if (Sheet <> Pages.ActivePage) then begin
  298. Pages.ActivePage := Sheet;
  299. ADesigner.SelectComponent(Sheet);
  300. end;
  301. end;
  302. end;
  303. 3:if (Pages.ActivePage <> nil) then
  304. begin
  305. Designer.SelectComponent(Pages.ActivePage as TFlatSheet);
  306. Pages.ActivePage.Free;
  307. end;
  308. end;
  309. ADesigner.Modified
  310. end
  311. end;
  312. function TPagesEditor.GetVerb(Index: Integer): string;
  313. begin
  314. case Index of
  315. 0:result:='New Page';
  316. 1:result:='Next Page';
  317. 2:result:='Previous Page';
  318. 3:result:='Delete Page';
  319. end
  320. end;
  321. function TPagesEditor.GetVerbCount: Integer;
  322. begin
  323. Result := 4
  324. end;
  325. procedure Register;
  326. begin
  327. RegisterComponentEditor(TFlatPages, TPagesEditor);
  328. RegisterComponentEditor(TFlatSheet, TPagesEditor);
  329. RegisterPropertyEditor(TypeInfo(TFlatSheet), TFlatPages, 'ActivePage', TFlatActivePage);
  330. RegisterPropertyEditor(TypeInfo(TMaskedText), TDefineMask, 'Text', TMaskEditor);
  331. RegisterPropertyEditor(TypeInfo(String), TVersionEdit, 'Version', TVersionEditor);
  332. RegisterPropertyEditor(TypeInfo(String), TVersionMemo, 'Version', TVersionEditor);
  333. RegisterPropertyEditor(TypeInfo(String), TVersionComboBox, 'Version', TVersionEditor);
  334. RegisterPropertyEditor(TypeInfo(String), TVersionControl, 'Version', TVersionEditor);
  335. RegisterPropertyEditor(TypeInfo(String), TVersionGraphic, 'Version', TVersionEditor);
  336. RegisterPropertyEditor(TypeInfo(String), TVersionTreeView, 'Version', TVersionEditor);
  337. RegisterPropertyEditor(TypeInfo(String), TVersionListView, 'Version', TVersionEditor);
  338. RegisterPropertyEditor(TypeInfo(String), TVersionComponent, 'Version', TVersionEditor);
  339. RegisterPropertyEditor(TypeInfo(String), TVersionPages, 'Version', TVersionEditor);
  340. RegisterPropertyEditor(TypeInfo(String), TVersionSheet, 'Version', TVersionEditor);
  341. RegisterPropertyEditor(TypeInfo(String), TVersionCtrlExt, 'Version', TVersionEditor);
  342. RegisterPropertyEditor(TypeInfo(String), TVersionDBGrid, 'Version', TVersionEditor);
  343. RegisterPropertyEditor(TypeInfo(String), TVersionDrawGrid, 'Version', TVersionEditor);
  344. RegisterPropertyEditor(TypeInfo(TStringList), TDefineWater, 'Items', TWaterEditor);
  345. RegisterComponentEditor(TDefineExcel, TExcelEditor);
  346. RegisterClasses([TFlatSheet]);
  347. end;
  348. end.