PageRenderTime 1311ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Components/FastReport3/Source/frxBarcodeEditor.pas

http://github.com/mitshel/tech-inv
Pascal | 246 lines | 193 code | 37 blank | 16 comment | 20 complexity | 8ca457bd04d79a2be17bf6ceb311d7f3 MD5 | raw file
Possible License(s): AGPL-3.0
  1. {******************************************}
  2. { }
  3. { FastReport v3.0 }
  4. { Barcode design editor }
  5. { }
  6. { Copyright (c) 1998-2004 }
  7. { by Alexander Tzyganenko, }
  8. { Fast Reports Inc. }
  9. { }
  10. {******************************************}
  11. unit frxBarcodeEditor;
  12. interface
  13. uses
  14. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  15. StdCtrls, Menus, ExtCtrls, Buttons, frxClass, frxBarcode, frxCustomEditors,
  16. frxBarcod, frxCtrls, ComCtrls
  17. {$IFDEF Delphi6}
  18. , Variants
  19. {$ENDIF};
  20. type
  21. TfrxBarcodeEditor = class(TfrxViewEditor)
  22. public
  23. function Edit: Boolean; override;
  24. function HasEditor: Boolean; override;
  25. procedure GetMenuItems; override;
  26. function Execute(Tag: Integer; Checked: Boolean): Boolean; override;
  27. end;
  28. TfrxBarcodeEditorForm = class(TForm)
  29. CancelB: TButton;
  30. OkB: TButton;
  31. CodeE: TfrxComboEdit;
  32. CodeLbl: TLabel;
  33. TypeCB: TComboBox;
  34. TypeLbl: TLabel;
  35. ZoomLbl: TLabel;
  36. CalcCheckSumCB: TCheckBox;
  37. ViewTextCB: TCheckBox;
  38. ZoomE: TEdit;
  39. Rotation0RB: TRadioButton;
  40. Rotation90RB: TRadioButton;
  41. Rotation180RB: TRadioButton;
  42. Rotation270RB: TRadioButton;
  43. OptionsLbl: TLabel;
  44. Bevel3: TBevel;
  45. RotationLbl: TLabel;
  46. Bevel1: TBevel;
  47. ExampleBvl: TBevel;
  48. ExamplePB: TPaintBox;
  49. UpDown1: TUpDown;
  50. procedure ExprBtnClick(Sender: TObject);
  51. procedure UpBClick(Sender: TObject);
  52. procedure DownBClick(Sender: TObject);
  53. procedure ExamplePBPaint(Sender: TObject);
  54. procedure FormShow(Sender: TObject);
  55. procedure FormHide(Sender: TObject);
  56. procedure FormCreate(Sender: TObject);
  57. private
  58. { Private declarations }
  59. FBarcode: TfrxBarcodeView;
  60. public
  61. { Public declarations }
  62. property Barcode: TfrxBarcodeView read FBarcode write FBarcode;
  63. end;
  64. implementation
  65. uses frxDsgnIntf, frxRes, frxUtils;
  66. {$R *.DFM}
  67. const
  68. cbDefaultText = '12345678';
  69. { TfrxBarcodeEditor }
  70. function TfrxBarcodeEditor.HasEditor: Boolean;
  71. begin
  72. Result := True;
  73. end;
  74. function TfrxBarcodeEditor.Edit: Boolean;
  75. begin
  76. with TfrxBarcodeEditorForm.Create(Designer) do
  77. begin
  78. Barcode := TfrxBarcodeView(Component);
  79. Result := ShowModal = mrOk;
  80. Free;
  81. end;
  82. end;
  83. function TfrxBarcodeEditor.Execute(Tag: Integer; Checked: Boolean): Boolean;
  84. var
  85. i: Integer;
  86. c: TfrxComponent;
  87. v: TfrxBarcodeView;
  88. begin
  89. Result := inherited Execute(Tag, Checked);
  90. for i := 0 to Designer.SelectedObjects.Count - 1 do
  91. begin
  92. c := Designer.SelectedObjects[i];
  93. if (c is TfrxBarcodeView) and not (rfDontModify in c.Restrictions) then
  94. begin
  95. v := TfrxBarcodeView(c);
  96. if Tag = 1 then
  97. v.CalcCheckSum := Checked
  98. else if Tag = 2 then
  99. v.ShowText := Checked;
  100. Result := True;
  101. end;
  102. end;
  103. end;
  104. procedure TfrxBarcodeEditor.GetMenuItems;
  105. var
  106. v: TfrxBarcodeView;
  107. begin
  108. v := TfrxBarcodeView(Component);
  109. AddItem(frxResources.Get('bcCalcChecksum'), 1, v.CalcCheckSum);
  110. AddItem(frxResources.Get('bcShowText'), 2, v.ShowText);
  111. inherited;
  112. end;
  113. { TfrxBarcodeEditorForm }
  114. procedure TfrxBarcodeEditorForm.FormShow(Sender: TObject);
  115. var
  116. i: TfrxBarcodeType;
  117. begin
  118. TypeCB.Items.Clear;
  119. for i := bcCode_2_5_interleaved to bcCodeEAN128C do
  120. TypeCB.Items.Add(bcData[i].Name);
  121. CodeE.Text := FBarcode.Text;
  122. TypeCB.ItemIndex := Integer(FBarcode.BarType);
  123. CalcCheckSumCB.Checked := FBarcode.CalcCheckSum;
  124. ViewTextCB.Checked := FBarcode.ShowText;
  125. ZoomE.Text := FloatToStr(FBarcode.Zoom);
  126. case FBarcode.Rotation of
  127. 90: Rotation90RB.Checked := True;
  128. 180: Rotation180RB.Checked := True;
  129. 270: Rotation270RB.Checked := True;
  130. else Rotation0RB.Checked := True;
  131. end;
  132. ExamplePBPaint(nil);
  133. end;
  134. procedure TfrxBarcodeEditorForm.FormHide(Sender: TObject);
  135. begin
  136. if ModalResult = mrOk then
  137. begin
  138. FBarcode.Text := CodeE.Text;
  139. FBarcode.BarType := TfrxBarcodeType(TypeCB.ItemIndex);
  140. FBarcode.CalcCheckSum := CalcCheckSumCB.Checked;
  141. FBarcode.ShowText := ViewTextCB.Checked;
  142. FBarcode.Zoom := frxStrToFloat(ZoomE.Text);
  143. if Rotation90RB.Checked then
  144. FBarcode.Rotation := 90
  145. else if Rotation180RB.Checked then
  146. FBarcode.Rotation := 180
  147. else if Rotation270RB.Checked then
  148. FBarcode.Rotation := 270
  149. else
  150. FBarcode.Rotation := 0;
  151. end;
  152. end;
  153. procedure TfrxBarcodeEditorForm.ExprBtnClick(Sender: TObject);
  154. var
  155. s: String;
  156. begin
  157. s := TfrxCustomDesigner(Owner).InsertExpression(CodeE.Text);
  158. if s <> '' then
  159. CodeE.Text := s;
  160. end;
  161. procedure TfrxBarcodeEditorForm.UpBClick(Sender: TObject);
  162. var
  163. i: Double;
  164. begin
  165. i := frxStrToFloat(ZoomE.Text);
  166. i := i + 0.1;
  167. ZoomE.Text := FloatToStr(i);
  168. end;
  169. procedure TfrxBarcodeEditorForm.DownBClick(Sender: TObject);
  170. var
  171. i: Double;
  172. begin
  173. i := frxStrToFloat(ZoomE.Text);
  174. i := i - 0.1;
  175. if i <= 0 then i := 1;
  176. ZoomE.Text := FloatToStr(i);
  177. end;
  178. procedure TfrxBarcodeEditorForm.ExamplePBPaint(Sender: TObject);
  179. var
  180. Barcode: TfrxBarcode;
  181. begin
  182. Barcode := TfrxBarcode.Create(Self);
  183. Barcode.Typ := TfrxBarcodeType(TypeCB.ItemIndex);
  184. Barcode.Text := '12345678';
  185. if Rotation0RB.Checked then
  186. Barcode.Angle := 0
  187. else if Rotation90RB.Checked then
  188. Barcode.Angle := 90
  189. else if Rotation180RB.Checked then
  190. Barcode.Angle := 180
  191. else
  192. Barcode.Angle := 270;
  193. Barcode.CheckSum := CalcCheckSumCB.Checked;
  194. with ExamplePB.Canvas do
  195. begin
  196. Brush.Color := clWhite;
  197. FillRect(Rect(0, 0, ExamplePB.Width, ExamplePB.Height));
  198. Barcode.DrawBarcode(ExamplePB.Canvas, Rect(40, 20, ExamplePB.Width - 40, 200),
  199. ViewTextCB.Checked);
  200. end;
  201. Barcode.Free;
  202. end;
  203. procedure TfrxBarcodeEditorForm.FormCreate(Sender: TObject);
  204. begin
  205. frxResources.LocalizeForm(Self);
  206. end;
  207. initialization
  208. frxComponentEditors.Register(TfrxBarcodeView, TfrxBarcodeEditor);
  209. end.