bcmaterialedit.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. unit BCMaterialEdit;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, Controls, Dialogs, ExtCtrls, Forms, Graphics, {$IFDEF FPC} LCLType,
  6. LResources, {$ENDIF} Menus, StdCtrls, SysUtils;
  7. type
  8. { TBCMaterialEditBase }
  9. generic TBCMaterialEditBase<T> = class(TCustomPanel)
  10. private
  11. FAccentColor: TColor;
  12. FDisabledColor: TColor;
  13. FLabel: TBoundLabel;
  14. FFocused: boolean;
  15. function IsNeededAdjustSize: boolean;
  16. function GetOnEditChange: TNotifyEvent;
  17. function GetOnEditClick: TNotifyEvent;
  18. function GetOnEditEditingDone: TNotifyEvent;
  19. function GetOnEditEnter: TNotifyEvent;
  20. function GetOnEditExit: TNotifyEvent;
  21. function GetOnEditKeyDown: TKeyEvent;
  22. function GetOnEditKeyPress: TKeyPressEvent;
  23. function GetOnEditKeyUp: TKeyEvent;
  24. function GetOnEditMouseDown: TMouseEvent;
  25. function GetOnEditMouseEnter: TNotifyEvent;
  26. function GetOnEditMouseLeave: TNotifyEvent;
  27. function GetOnEditMouseMove: TMouseMoveEvent;
  28. function GetOnEditMouseUp: TMouseEvent;
  29. function GetOnEditMouseWheel: TMouseWheelEvent;
  30. function GetOnEditMouseWheelDown: TMouseWheelUpDownEvent;
  31. function GetOnEditMouseWheelUp: TMouseWheelUpDownEvent;
  32. function GetOnEditUTF8KeyPress: TUTF8KeyPressEvent;
  33. procedure SetOnEditChange(AValue: TNotifyEvent);
  34. procedure SetOnEditClick(AValue: TNotifyEvent);
  35. procedure SetOnEditEditingDone(AValue: TNotifyEvent);
  36. procedure SetOnEditEnter(AValue: TNotifyEvent);
  37. procedure SetOnEditExit(AValue: TNotifyEvent);
  38. procedure SetOnEditKeyDown(AValue: TKeyEvent);
  39. procedure SetOnEditKeyPress(AValue: TKeyPressEvent);
  40. procedure SetOnEditKeyUp(AValue: TKeyEvent);
  41. procedure SetOnEditMouseDown(AValue: TMouseEvent);
  42. procedure SetOnEditMouseEnter(AValue: TNotifyEvent);
  43. procedure SetOnEditMouseLeave(AValue: TNotifyEvent);
  44. procedure SetOnEditMouseMove(AValue: TMouseMoveEvent);
  45. procedure SetOnEditMouseUp(AValue: TMouseEvent);
  46. procedure SetOnEditMouseWheel(AValue: TMouseWheelEvent);
  47. procedure SetOnEditMouseWheelDown(AValue: TMouseWheelUpDownEvent);
  48. procedure SetOnEditMouseWheelUp(AValue: TMouseWheelUpDownEvent);
  49. procedure SetOnEditUTF8KeyPress(AValue: TUTF8KeyPressEvent);
  50. protected
  51. FEdit: T;
  52. function GetEditAlignment: TAlignment;
  53. function GetEditAutoSize: Boolean;
  54. function GetEditAutoSelect: Boolean;
  55. function GetEditCharCase: TEditCharCase;
  56. function GetEditCursor: TCursor;
  57. function GetEditDoubleBuffered: Boolean;
  58. function GetEditEchoMode: TEchoMode;
  59. function GetEditHideSelection: Boolean;
  60. function GetEditHint: TTranslateString;
  61. function GetEditMaxLength: Integer;
  62. function GetEditNumbersOnly: Boolean;
  63. function GetEditPasswordChar: Char;
  64. function GetEditParentColor: Boolean;
  65. function GetEditPopupMenu: TPopupMenu;
  66. function GetEditReadOnly: Boolean;
  67. function GetEditShowHint: Boolean;
  68. function GetEditTag: PtrInt;
  69. function GetEditTabStop: Boolean;
  70. function GetEditText: TCaption;
  71. function GetEditTextHint: TTranslateString;
  72. function GetLabelCaption: TCaption;
  73. function GetLabelSpacing: Integer;
  74. procedure SetAnchors(const AValue: TAnchors); override;
  75. procedure SetColor(AValue: TColor); override;
  76. procedure SetEditAlignment(const AValue: TAlignment);
  77. procedure SetEditAutoSize(AValue: Boolean);
  78. procedure SetEditAutoSelect(AValue: Boolean);
  79. procedure SetEditCharCase(AValue: TEditCharCase);
  80. procedure SetEditCursor(AValue: TCursor);
  81. procedure SetEditDoubleBuffered(AValue: Boolean);
  82. procedure SetEditEchoMode(AValue: TEchoMode);
  83. procedure SetEditHideSelection(AValue: Boolean);
  84. procedure SetEditHint(const AValue: TTranslateString);
  85. procedure SetEditMaxLength(AValue: Integer);
  86. procedure SetEditNumbersOnly(AValue: Boolean);
  87. procedure SetEditParentColor(AValue: Boolean);
  88. procedure SetEditPasswordChar(AValue: Char);
  89. procedure SetEditPopupMenu(AValue: TPopupmenu);
  90. procedure SetEditReadOnly(AValue: Boolean);
  91. procedure SetEditShowHint(AValue: Boolean);
  92. procedure SetEditTag(AValue: PtrInt);
  93. procedure SetEditTabStop(AValue: Boolean);
  94. procedure SetEditText(const AValue: TCaption);
  95. procedure SetEditTextHint(const Avalue: TTranslateString);
  96. procedure SetLabelCaption(const AValue: TCaption);
  97. procedure SetLabelSpacing(AValue: Integer);
  98. procedure SetName(const AValue: TComponentName); override;
  99. procedure DoEnter; override;
  100. procedure DoExit; override;
  101. procedure DoOnResize; override;
  102. procedure Paint; override;
  103. public
  104. constructor Create(AOwner: TComponent); override;
  105. published
  106. property Align;
  107. property Alignment: TAlignment read GetEditAlignment write SetEditAlignment default taLeftJustify;
  108. property AccentColor: TColor read FAccentColor write FAccentColor;
  109. property Anchors;
  110. property AutoSelect: Boolean read GetEditAutoSelect write SetEditAutoSelect default True;
  111. property AutoSize: Boolean read GetEditAutoSize write SetEditAutoSize default True;
  112. property BiDiMode;
  113. property BorderSpacing;
  114. property Caption: TCaption read GetLabelCaption write SetLabelCaption;
  115. property CharCase: TEditCharCase read GetEditCharCase write SetEditCharCase default ecNormal;
  116. property Color;
  117. property Constraints;
  118. property Cursor: TCursor read GetEditCursor write SetEditCursor default crDefault;
  119. property DisabledColor: TColor read FDisabledColor write FDisabledColor;
  120. property DoubleBuffered: Boolean read GetEditDoubleBuffered write SetEditDoubleBuffered;
  121. property EchoMode: TEchoMode read GetEditEchoMode write SetEditEchoMode default emNormal;
  122. property EditLabel: TBoundLabel read FLabel;
  123. property Enabled;
  124. property Font;
  125. property HideSelection: Boolean read GetEditHideSelection write SetEditHideSelection default True;
  126. property Hint: TTranslateString read GetEditHint write SetEditHint;
  127. property LabelSpacing: Integer read GetLabelSpacing write SetLabelSpacing default 4;
  128. property MaxLength: Integer read GetEditMaxLength write SetEditMaxLength default 0;
  129. property NumbersOnly: Boolean read GetEditNumbersOnly write SetEditNumbersOnly default False;
  130. property ParentBiDiMode;
  131. property ParentColor default False;
  132. property ParentFont default False;
  133. property PasswordChar: Char read GetEditPasswordChar write SetEditPasswordChar default #0;
  134. property PopupMenu: TPopupmenu read GetEditPopupMenu write SetEditPopupMenu;
  135. property ReadOnly: Boolean read GetEditReadOnly write SetEditReadOnly default False;
  136. property ShowHint: Boolean read GetEditShowHint write SetEditShowHint default False;
  137. property Tag: PtrInt read GetEditTag write SetEditTag default 0;
  138. property TabOrder;
  139. property TabStop: boolean read GetEditTabStop write SetEditTabStop default True;
  140. property Text: TCaption read GetEditText write SetEditText;
  141. property TextHint: TTranslateString read GetEditTextHint write SetEditTextHint;
  142. property Visible;
  143. property OnChange: TNotifyEvent read GetOnEditChange write SetOnEditChange;
  144. property OnChangeBounds;
  145. property OnClick: TNotifyEvent read GetOnEditClick write SetOnEditClick;
  146. property OnEditingDone: TNotifyEvent read GetOnEditEditingDone write SetOnEditEditingDone;
  147. property OnEnter: TNotifyEvent read GetOnEditEnter write SetOnEditEnter;
  148. property OnExit: TNotifyEvent read GetOnEditExit write SetOnEditExit;
  149. property OnKeyDown: TKeyEvent read GetOnEditKeyDown write SetOnEditKeyDown;
  150. property OnKeyPress: TKeyPressEvent read GetOnEditKeyPress write SetOnEditKeyPress;
  151. property OnKeyUp: TKeyEvent read GetOnEditKeyUp write SetOnEditKeyUp;
  152. property OnMouseDown: TMouseEvent read GetOnEditMouseDown write SetOnEditMouseDown;
  153. property OnMouseEnter: TNotifyEvent read GetOnEditMouseEnter write SetOnEditMouseEnter;
  154. property OnMouseLeave: TNotifyEvent read GetOnEditMouseLeave write SetOnEditMouseLeave;
  155. property OnMouseMove: TMouseMoveEvent read GetOnEditMouseMove write SetOnEditMouseMove;
  156. property OnMouseUp: TMouseEvent read GetOnEditMouseUp write SetOnEditMouseUp;
  157. property OnMouseWheel: TMouseWheelEvent read GetOnEditMouseWheel write SetOnEditMouseWheel;
  158. property OnMouseWheelDown: TMouseWheelUpDownEvent read GetOnEditMouseWheelDown write SetOnEditMouseWheelDown;
  159. property OnMouseWheelUp: TMouseWheelUpDownEvent read GetOnEditMouseWheelUp write SetOnEditMouseWheelUp;
  160. property OnResize;
  161. property OnUTF8KeyPress: TUTF8KeyPressEvent read GetOnEditUTF8KeyPress write SetOnEditUTF8KeyPress;
  162. end;
  163. { TBCMaterialEdit }
  164. TBCMaterialEdit = class(specialize TBCMaterialEditBase<TEdit>)
  165. private
  166. function GetEditDragCursor: TCursor;
  167. function GetEditDragMode: TDragMode;
  168. function GetOnEditContextPopup: TContextPopupEvent;
  169. function GetOnEditDblClick: TNotifyEvent;
  170. function GetOnEditDragDrop: TDragDropEvent;
  171. function GetOnEditDragOver: TDragOverEvent;
  172. function GetOnEditEndDrag: TEndDragEvent;
  173. function GetOnEditStartDrag: TStartDragEvent;
  174. procedure SetEditDragCursor(AValue: TCursor);
  175. procedure SetEditDragMode(AValue: TDragMode);
  176. procedure SetOnEditContextPopup(AValue: TContextPopupEvent);
  177. procedure SetOnEditDblClick(AValue: TNotifyEvent);
  178. procedure SetOnEditDragDrop(AValue: TDragDropEvent);
  179. procedure SetOnEditDragOver(AValue: TDragOverEvent);
  180. procedure SetOnEditEndDrag(AValue: TEndDragEvent);
  181. procedure SetOnEditStartDrag(AValue: TStartDragEvent);
  182. published
  183. property Align;
  184. property Alignment;
  185. property AccentColor;
  186. property Anchors;
  187. property AutoSelect;
  188. property AutoSize;
  189. property BiDiMode;
  190. property BorderSpacing;
  191. property Caption;
  192. property CharCase;
  193. property Color;
  194. property Constraints;
  195. property Cursor;
  196. property DisabledColor;
  197. property DoubleBuffered;
  198. property DragCursor: TCursor read GetEditDragCursor write SetEditDragCursor default crDrag;
  199. property DragMode: TDragMode read GetEditDragMode write SetEditDragMode default dmManual;
  200. property Font;
  201. property EchoMode;
  202. property Edit: TEdit read FEdit;
  203. property EditLabel;
  204. property Enabled;
  205. property HideSelection;
  206. property Hint;
  207. property LabelSpacing;
  208. property MaxLength;
  209. property NumbersOnly;
  210. property ParentBiDiMode;
  211. property ParentColor;
  212. property ParentFont;
  213. property PasswordChar;
  214. property PopupMenu;
  215. property ReadOnly;
  216. property ShowHint;
  217. property Tag;
  218. property TabOrder;
  219. property TabStop;
  220. property Text;
  221. property TextHint;
  222. property Visible;
  223. property OnChange;
  224. property OnChangeBounds;
  225. property OnClick;
  226. property OnContextPopup;
  227. property OnDbClick: TNotifyEvent read GetOnEditDblClick write SetOnEditDblClick;
  228. property OnDragDrop: TDragDropEvent read GetOnEditDragDrop write SetOnEditDragDrop;
  229. property OnDragOver: TDragOverEvent read GetOnEditDragOver write SetOnEditDragOver;
  230. property OnEditingDone;
  231. property OnEndDrag: TEndDragEvent read GetOnEditEndDrag write SetOnEditEndDrag;
  232. property OnEnter;
  233. property OnExit;
  234. property OnKeyDown;
  235. property OnKeyPress;
  236. property OnKeyUp;
  237. property OnMouseDown;
  238. property OnMouseEnter;
  239. property OnMouseLeave;
  240. property OnMouseMove;
  241. property OnMouseUp;
  242. property OnMouseWheel;
  243. property OnMouseWheelDown;
  244. property OnMouseWheelUp;
  245. property OnResize;
  246. property OnStartDrag: TStartDragEvent read GetOnEditStartDrag write SetOnEditStartDrag;
  247. property OnUTF8KeyPress;
  248. end;
  249. procedure Register;
  250. implementation
  251. procedure Register;
  252. begin
  253. {$IFDEF FPC}
  254. {$I icons\bcmaterialedit_icon.lrs}
  255. {$ENDIF}
  256. RegisterComponents('BGRA Controls', [TBCMaterialEdit]);
  257. end;
  258. { TBCMaterialEditBase }
  259. function TBCMaterialEditBase.GetEditAlignment: TAlignment;
  260. begin
  261. result := FEdit.Alignment;
  262. end;
  263. function TBCMaterialEditBase.GetEditAutoSize: Boolean;
  264. begin
  265. result := FEdit.AutoSize;
  266. end;
  267. function TBCMaterialEditBase.GetEditAutoSelect: Boolean;
  268. begin
  269. result := FEdit.AutoSelect;
  270. end;
  271. function TBCMaterialEditBase.GetEditCharCase: TEditCharCase;
  272. begin
  273. result := FEdit.CharCase;
  274. end;
  275. function TBCMaterialEditBase.GetEditCursor: TCursor;
  276. begin
  277. result := FEdit.Cursor;
  278. end;
  279. function TBCMaterialEditBase.GetEditDoubleBuffered: Boolean;
  280. begin
  281. result := FEdit.DoubleBuffered;
  282. end;
  283. function TBCMaterialEditBase.GetEditEchoMode: TEchoMode;
  284. begin
  285. result := FEdit.EchoMode;
  286. end;
  287. function TBCMaterialEditBase.GetEditHideSelection: Boolean;
  288. begin
  289. result := FEdit.HideSelection;
  290. end;
  291. function TBCMaterialEditBase.GetEditHint: TTranslateString;
  292. begin
  293. result := FEdit.Hint;
  294. end;
  295. function TBCMaterialEditBase.GetEditMaxLength: Integer;
  296. begin
  297. result := FEdit.MaxLength;
  298. end;
  299. function TBCMaterialEditBase.GetEditNumbersOnly: Boolean;
  300. begin
  301. result := FEdit.NumbersOnly;
  302. end;
  303. function TBCMaterialEditBase.GetEditPasswordChar: Char;
  304. begin
  305. result := FEdit.PasswordChar;
  306. end;
  307. function TBCMaterialEditBase.GetEditParentColor: Boolean;
  308. begin
  309. Result := Self.ParentColor;
  310. end;
  311. function TBCMaterialEditBase.GetEditPopupMenu: TPopupMenu;
  312. begin
  313. if (csDestroying in ComponentState) then Exit(nil);
  314. result := FEdit.PopupMenu;
  315. end;
  316. function TBCMaterialEditBase.GetEditReadOnly: Boolean;
  317. begin
  318. result := FEdit.ReadOnly;
  319. end;
  320. function TBCMaterialEditBase.GetEditShowHint: Boolean;
  321. begin
  322. result := FEdit.ShowHint;
  323. end;
  324. function TBCMaterialEditBase.GetEditTag: PtrInt;
  325. begin
  326. result := FEdit.Tag;
  327. end;
  328. function TBCMaterialEditBase.GetEditTabStop: Boolean;
  329. begin
  330. result := FEdit.TabStop;
  331. end;
  332. function TBCMaterialEditBase.GetEditText: TCaption;
  333. begin
  334. result := FEdit.Text;
  335. end;
  336. function TBCMaterialEditBase.GetEditTextHint: TCaption;
  337. begin
  338. result := FEdit.TextHint;
  339. end;
  340. function TBCMaterialEditBase.GetLabelCaption: TCaption;
  341. begin
  342. result := FLabel.Caption
  343. end;
  344. function TBCMaterialEditBase.GetLabelSpacing: Integer;
  345. begin
  346. result := FLabel.BorderSpacing.Bottom;
  347. end;
  348. function TBCMaterialEditBase.GetOnEditChange: TNotifyEvent;
  349. begin
  350. result := FEdit.OnChange;
  351. end;
  352. function TBCMaterialEditBase.GetOnEditClick: TNotifyEvent;
  353. begin
  354. result := FEdit.OnClick;
  355. end;
  356. function TBCMaterialEditBase.GetOnEditEditingDone: TNotifyEvent;
  357. begin
  358. result := FEdit.OnEditingDone;
  359. end;
  360. function TBCMaterialEditBase.GetOnEditEnter: TNotifyEvent;
  361. begin
  362. result := FEdit.OnEnter;
  363. end;
  364. function TBCMaterialEditBase.GetOnEditExit: TNotifyEvent;
  365. begin
  366. result := FEdit.OnExit;
  367. end;
  368. function TBCMaterialEditBase.GetOnEditKeyDown: TKeyEvent;
  369. begin
  370. result := FEdit.OnKeyDown;
  371. end;
  372. function TBCMaterialEditBase.GetOnEditKeyPress: TKeyPressEvent;
  373. begin
  374. result := FEdit.OnKeyPress;
  375. end;
  376. function TBCMaterialEditBase.GetOnEditKeyUp: TKeyEvent;
  377. begin
  378. result := FEdit.OnKeyUp;
  379. end;
  380. function TBCMaterialEditBase.GetOnEditMouseDown: TMouseEvent;
  381. begin
  382. result := FEdit.OnMouseDown;
  383. end;
  384. function TBCMaterialEditBase.GetOnEditMouseEnter: TNotifyEvent;
  385. begin
  386. result := FEdit.OnMouseEnter;
  387. end;
  388. function TBCMaterialEditBase.GetOnEditMouseLeave: TNotifyEvent;
  389. begin
  390. result := FEdit.OnMouseLeave;
  391. end;
  392. function TBCMaterialEditBase.GetOnEditMouseMove: TMouseMoveEvent;
  393. begin
  394. result := FEdit.OnMouseMove;
  395. end;
  396. function TBCMaterialEditBase.GetOnEditMouseUp: TMouseEvent;
  397. begin
  398. result := FEdit.OnMouseUp;
  399. end;
  400. function TBCMaterialEditBase.GetOnEditMouseWheel: TMouseWheelEvent;
  401. begin
  402. result := FEdit.OnMouseWheel;
  403. end;
  404. function TBCMaterialEditBase.GetOnEditMouseWheelDown: TMouseWheelUpDownEvent;
  405. begin
  406. result := FEdit.OnMouseWheelDown;
  407. end;
  408. function TBCMaterialEditBase.GetOnEditMouseWheelUp: TMouseWheelUpDownEvent;
  409. begin
  410. result := FEdit.OnMouseWheelUp;
  411. end;
  412. function TBCMaterialEditBase.GetOnEditUTF8KeyPress: TUTF8KeyPressEvent;
  413. begin
  414. result := FEdit.OnUTF8KeyPress;
  415. end;
  416. procedure TBCMaterialEditBase.SetOnEditChange(AValue: TNotifyEvent);
  417. begin
  418. FEdit.OnChange := AValue;
  419. end;
  420. procedure TBCMaterialEditBase.SetOnEditClick(AValue: TNotifyEvent);
  421. begin
  422. FEdit.OnClick := AValue;
  423. end;
  424. procedure TBCMaterialEditBase.SetOnEditEditingDone(AValue: TNotifyEvent);
  425. begin
  426. FEdit.OnEditingDone := AValue;
  427. end;
  428. procedure TBCMaterialEditBase.SetOnEditEnter(AValue: TNotifyEvent);
  429. begin
  430. FEdit.OnEnter := AValue;
  431. end;
  432. procedure TBCMaterialEditBase.SetOnEditExit(AValue: TNotifyEvent);
  433. begin
  434. FEdit.OnExit := AValue;
  435. end;
  436. procedure TBCMaterialEditBase.SetOnEditKeyDown(AValue: TKeyEvent);
  437. begin
  438. FEdit.OnKeyDown := AValue;
  439. end;
  440. procedure TBCMaterialEditBase.SetOnEditKeyPress(AValue: TKeyPressEvent);
  441. begin
  442. FEdit.OnKeyPress := AValue;
  443. end;
  444. procedure TBCMaterialEditBase.SetOnEditKeyUp(AValue: TKeyEvent);
  445. begin
  446. FEdit.OnKeyUp := AValue;
  447. end;
  448. procedure TBCMaterialEditBase.SetOnEditMouseDown(AValue: TMouseEvent);
  449. begin
  450. FEdit.OnMouseDown := AValue;
  451. end;
  452. procedure TBCMaterialEditBase.SetOnEditMouseEnter(AValue: TNotifyEvent);
  453. begin
  454. FEdit.OnMouseEnter := AValue;
  455. end;
  456. procedure TBCMaterialEditBase.SetOnEditMouseLeave(AValue: TNotifyEvent);
  457. begin
  458. FEdit.OnMouseLeave := AValue;
  459. end;
  460. procedure TBCMaterialEditBase.SetOnEditMouseMove(AValue: TMouseMoveEvent);
  461. begin
  462. FEdit.OnMouseMove := AValue;
  463. end;
  464. procedure TBCMaterialEditBase.SetOnEditMouseUp(AValue: TMouseEvent);
  465. begin
  466. FEdit.OnMouseUp := AValue;
  467. end;
  468. procedure TBCMaterialEditBase.SetOnEditMouseWheel(AValue: TMouseWheelEvent);
  469. begin
  470. FEdit.OnMouseWheel := AValue;
  471. end;
  472. procedure TBCMaterialEditBase.SetOnEditMouseWheelDown(AValue: TMouseWheelUpDownEvent);
  473. begin
  474. FEdit.OnMouseWheelDown := AValue;
  475. end;
  476. procedure TBCMaterialEditBase.SetOnEditMouseWheelUp(AValue: TMouseWheelUpDownEvent);
  477. begin
  478. FEdit.OnMouseWheelUp := AValue;
  479. end;
  480. procedure TBCMaterialEditBase.SetOnEditUTF8KeyPress(AValue: TUTF8KeyPressEvent);
  481. begin
  482. FEdit.OnUTF8KeyPress := AValue;
  483. end;
  484. function TBCMaterialEditBase.IsNeededAdjustSize: boolean;
  485. begin
  486. if (Self.Align in [alLeft, alRight, alClient]) then Exit(False);
  487. if (akTop in Self.Anchors) and (akBottom in Self.Anchors) then Exit(False);
  488. result := FEdit.AutoSize;
  489. end;
  490. procedure TBCMaterialEditBase.SetAnchors(const AValue: TAnchors);
  491. begin
  492. if (Self.Anchors = AValue) then Exit;
  493. inherited SetAnchors(AValue);
  494. if not (csLoading in ComponentState) then Self.DoOnResize;
  495. end;
  496. procedure TBCMaterialEditBase.SetColor(AValue: TColor);
  497. begin
  498. inherited SetColor(AValue);
  499. FEdit.Color := AValue;
  500. end;
  501. procedure TBCMaterialEditBase.SetEditAlignment(const AValue: TAlignment);
  502. begin
  503. FEdit.Alignment := AValue;
  504. end;
  505. procedure TBCMaterialEditBase.SetEditAutoSize(AValue: Boolean);
  506. begin
  507. if (FEdit.AutoSize = AValue) then Exit;
  508. FEdit.AutoSize := AValue;
  509. if not (csLoading in ComponentState) then Self.DoOnResize;
  510. end;
  511. procedure TBCMaterialEditBase.SetEditAutoSelect(AValue: Boolean);
  512. begin
  513. FEdit.AutoSelect := AValue;
  514. end;
  515. procedure TBCMaterialEditBase.SetEditCharCase(AValue: TEditCharCase);
  516. begin
  517. FEdit.CharCase := AValue;
  518. end;
  519. procedure TBCMaterialEditBase.SetEditCursor(AValue: TCursor);
  520. begin
  521. FEdit.Cursor := AValue;
  522. end;
  523. procedure TBCMaterialEditBase.SetEditDoubleBuffered(AValue: Boolean);
  524. begin
  525. FEdit.DoubleBuffered := AValue;
  526. end;
  527. procedure TBCMaterialEditBase.SetEditEchoMode(AValue: TEchoMode);
  528. begin
  529. FEdit.EchoMode := AValue;
  530. end;
  531. procedure TBCMaterialEditBase.SetEditHideSelection(AValue: Boolean);
  532. begin
  533. FEdit.HideSelection := AValue;
  534. end;
  535. procedure TBCMaterialEditBase.SetEditHint(const AValue: TTranslateString);
  536. begin
  537. FEdit.Hint := AValue;
  538. end;
  539. procedure TBCMaterialEditBase.SetEditMaxLength(AValue: Integer);
  540. begin
  541. FEdit.MaxLength := AValue;
  542. end;
  543. procedure TBCMaterialEditBase.SetEditNumbersOnly(AValue: Boolean);
  544. begin
  545. FEdit.NumbersOnly := AValue;
  546. end;
  547. procedure TBCMaterialEditBase.SetEditParentColor(AValue: Boolean);
  548. begin
  549. FEdit.ParentColor := AValue;
  550. FLabel.ParentColor := AValue;
  551. end;
  552. procedure TBCMaterialEditBase.SetEditPasswordChar(AValue: Char);
  553. begin
  554. FEdit.PasswordChar := AValue;
  555. end;
  556. procedure TBCMaterialEditBase.SetEditTabStop(AValue: Boolean);
  557. begin
  558. FEdit.TabStop := AValue;
  559. end;
  560. procedure TBCMaterialEditBase.SetEditPopupMenu(AValue: TPopupmenu);
  561. begin
  562. FEdit.PopupMenu := AValue;
  563. end;
  564. procedure TBCMaterialEditBase.SetEditReadOnly(AValue: Boolean);
  565. begin
  566. FEdit.ReadOnly := AValue;
  567. end;
  568. procedure TBCMaterialEditBase.SetEditShowHint(AValue: Boolean);
  569. begin
  570. FEdit.ShowHint := AValue;
  571. end;
  572. procedure TBCMaterialEditBase.SetEditTag(AValue: PtrInt);
  573. begin
  574. FEdit.Tag := AValue;
  575. end;
  576. procedure TBCMaterialEditBase.SetEditTextHint(const Avalue: TTranslateString);
  577. begin
  578. FEdit.TextHint := AValue;
  579. end;
  580. procedure TBCMaterialEditBase.SetEditText(const AValue: TCaption);
  581. begin
  582. FEdit.Text := AValue;
  583. end;
  584. procedure TBCMaterialEditBase.SetLabelCaption(const AValue: TCaption);
  585. begin
  586. FLabel.Caption := AValue;
  587. end;
  588. procedure TBCMaterialEditBase.SetLabelSpacing(AValue: Integer);
  589. begin
  590. if (FLabel.BorderSpacing.Bottom = AValue) then Exit;
  591. FLabel.BorderSpacing.Bottom := AValue;
  592. if not (csLoading in ComponentState) then Self.DoOnResize;
  593. end;
  594. procedure TBCMaterialEditBase.SetName(const AValue: TComponentName);
  595. begin
  596. if (csDesigning in ComponentState) then
  597. begin
  598. if (FLabel.Caption = '') or (AnsiSameText(FLabel.Caption, AValue)) then
  599. FLabel.Caption := 'Label';
  600. if (FLabel.Name = '') or (AnsiSameText(FLabel.Name, AValue)) then
  601. FLabel.Name := AValue + 'SubLabel';
  602. if (FEdit.Text = '') or (AnsiSameText(FEdit.Text, AValue)) then
  603. FEdit.Text := AValue;
  604. if (FEdit.Name = '') or (AnsiSameText(FEdit.Name, AValue)) then
  605. FEdit.Name := AValue + 'SubEdit';
  606. end;
  607. inherited SetName(AValue);
  608. end;
  609. procedure TBCMaterialEditBase.DoEnter;
  610. begin
  611. inherited DoEnter;
  612. FFocused := True;
  613. Invalidate;
  614. end;
  615. procedure TBCMaterialEditBase.DoExit;
  616. begin
  617. FFocused := False;
  618. Invalidate;
  619. inherited DoExit;
  620. end;
  621. procedure TBCMaterialEditBase.DoOnResize;
  622. var
  623. AutoSizedHeight: longint;
  624. begin
  625. if IsNeededAdjustSize then
  626. begin
  627. FEdit.Align := alBottom;
  628. AutoSizedHeight :=
  629. FLabel.Height +
  630. FLabel.BorderSpacing.Around +
  631. FLabel.BorderSpacing.Bottom +
  632. FLabel.BorderSpacing.Top +
  633. FEdit.Height +
  634. FEdit.BorderSpacing.Around +
  635. FEdit.BorderSpacing.Bottom +
  636. FEdit.BorderSpacing.Top;
  637. if Self.Height <> AutoSizedHeight then
  638. Self.Height := AutoSizedHeight;
  639. end else
  640. begin
  641. FEdit.Align := alClient;
  642. end;
  643. inherited DoOnResize;
  644. end;
  645. procedure TBCMaterialEditBase.Paint;
  646. var
  647. LeftPos, RightPos: integer;
  648. begin
  649. inherited Paint;
  650. Canvas.Brush.Color := Color;
  651. Canvas.Pen.Color := Color;
  652. Canvas.Rectangle(0, 0, Width, Height);
  653. if Assigned(Parent) and (Parent.Color = Color) then
  654. begin
  655. LeftPos := FEdit.Left;
  656. RightPos := FEdit.Left + FEdit.Width;
  657. end else
  658. begin
  659. LeftPos := 0;
  660. RightPos := Width;
  661. end;
  662. if (FFocused) and (Self.Enabled) then
  663. begin
  664. Canvas.Pen.Color := AccentColor;
  665. Canvas.Line(LeftPos, Height - 2, RightPos, Height - 2);
  666. Canvas.Line(LeftPos, Height - 1, RightPos, Height - 1);
  667. FLabel.Font.Color := AccentColor;
  668. end else
  669. begin
  670. Canvas.Pen.Color := DisabledColor;
  671. Canvas.Line(LeftPos, Height - 1, RightPos, Height - 1);
  672. FLabel.Font.Color := DisabledColor;
  673. end;
  674. end;
  675. constructor TBCMaterialEditBase.Create(AOwner: TComponent);
  676. begin
  677. FEdit := T.Create(Self);
  678. FLabel := TBoundLabel.Create(Self);
  679. inherited Create(AOwner);
  680. Self.AccentColor := clHighlight;
  681. Self.BorderStyle := bsNone;
  682. Self.Color := clWindow;
  683. Self.DisabledColor := $00B8AFA8;
  684. Self.ParentColor := False;
  685. FLabel.Align := alTop;
  686. FLabel.AutoSize := True;
  687. FLabel.BorderSpacing.Around := 0;
  688. FLabel.BorderSpacing.Bottom := 4;
  689. FLabel.BorderSpacing.Left := 4;
  690. FLabel.BorderSpacing.Right := 4;
  691. FLabel.BorderSpacing.Top := 4;
  692. FLabel.Font.Color := $00B8AFA8;
  693. FLabel.Font.Style := [fsBold];
  694. FLabel.Parent := Self;
  695. FLabel.ParentFont := False;
  696. FLabel.ParentBiDiMode := True;
  697. FLabel.SetSubComponent(True);
  698. FEdit.Align := alBottom;
  699. FEdit.AutoSelect := True;
  700. FEdit.AutoSize := True;
  701. FEdit.BorderSpacing.Around := 0;
  702. FEdit.BorderSpacing.Bottom := 4;
  703. FEdit.BorderSpacing.Left := 4;
  704. FEdit.BorderSpacing.Right := 4;
  705. FEdit.BorderSpacing.Top := 0;
  706. FEdit.BorderStyle := bsNone;
  707. FEdit.Color := Color;
  708. FEdit.Font.Color := clBlack;
  709. FEdit.Parent := Self;
  710. FEdit.ParentFont := True;
  711. FEdit.ParentBiDiMode := True;
  712. FEdit.TabStop := True;
  713. FEdit.SetSubComponent(True);
  714. end;
  715. { TBCMaterialEdit }
  716. function TBCMaterialEdit.GetEditDragCursor: TCursor;
  717. begin
  718. result := FEdit.DragCursor;
  719. end;
  720. function TBCMaterialEdit.GetEditDragMode: TDragMode;
  721. begin
  722. result := FEdit.DragMode;
  723. end;
  724. function TBCMaterialEdit.GetOnEditContextPopup: TContextPopupEvent;
  725. begin
  726. result := FEdit.OnContextPopup;
  727. end;
  728. function TBCMaterialEdit.GetOnEditDblClick: TNotifyEvent;
  729. begin
  730. result := FEdit.OnDblClick;
  731. end;
  732. function TBCMaterialEdit.GetOnEditDragDrop: TDragDropEvent;
  733. begin
  734. result := FEdit.OnDragDrop;
  735. end;
  736. function TBCMaterialEdit.GetOnEditDragOver: TDragOverEvent;
  737. begin
  738. result := FEdit.OnDragOver;
  739. end;
  740. function TBCMaterialEdit.GetOnEditEndDrag: TEndDragEvent;
  741. begin
  742. result := FEdit.OnEndDrag;
  743. end;
  744. function TBCMaterialEdit.GetOnEditStartDrag: TStartDragEvent;
  745. begin
  746. result := FEdit.OnStartDrag;
  747. end;
  748. procedure TBCMaterialEdit.SetEditDragCursor(AValue: TCursor);
  749. begin
  750. FEdit.DragCursor := AValue;
  751. end;
  752. procedure TBCMaterialEdit.SetEditDragMode(AValue: TDragMode);
  753. begin
  754. FEdit.DragMode := AValue;
  755. end;
  756. procedure TBCMaterialEdit.SetOnEditContextPopup(AValue: TContextPopupEvent);
  757. begin
  758. FEdit.OnContextPopup := AValue;
  759. end;
  760. procedure TBCMaterialEdit.SetOnEditDblClick(AValue: TNotifyEvent);
  761. begin
  762. FEdit.OnDblClick := AValue;
  763. end;
  764. procedure TBCMaterialEdit.SetOnEditDragDrop(AValue: TDragDropEvent);
  765. begin
  766. FEdit.OnDragDrop := AValue;
  767. end;
  768. procedure TBCMaterialEdit.SetOnEditDragOver(AValue: TDragOverEvent);
  769. begin
  770. FEdit.OnDragOver := AValue;
  771. end;
  772. procedure TBCMaterialEdit.SetOnEditEndDrag(AValue: TEndDragEvent);
  773. begin
  774. FEdit.OnEndDrag := AValue;
  775. end;
  776. procedure TBCMaterialEdit.SetOnEditStartDrag(AValue: TStartDragEvent);
  777. begin
  778. FEdit.OnStartDrag := AValue;
  779. end;
  780. end.