2
0

bclistbox.pas 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // SPDX-License-Identifier: LGPL-3.0-linking-exception
  2. {******************************* CONTRIBUTOR(S) ******************************
  3. - Edivando S. Santos Brasil | [email protected]
  4. (Compatibility with delphi VCL 11/2018)
  5. ***************************** END CONTRIBUTOR(S) *****************************}
  6. unit BCListBox;
  7. {$I bgracontrols.inc}
  8. interface
  9. uses
  10. Classes, SysUtils, {$IFDEF FPC}LCLType, LResources, {$ENDIF}
  11. Forms, Controls, Graphics, Dialogs, StdCtrls,
  12. {$IFNDEF FPC}Types, BGRAGraphics, GraphType, FPImage, BCBaseCtrls,{$ENDIF}
  13. BGRAVirtualScreen, BGRABitmap, BGRASliceScaling;
  14. type
  15. TBCListBox = class;
  16. TBCPaperPanel = class;
  17. { TBCPaperPanel }
  18. TBCPaperPanel = class(TBGRAVirtualScreen)
  19. private
  20. FShadow: TBGRASliceScaling;
  21. procedure LoadShadowFromBitmapResource;
  22. protected
  23. procedure BCRedraw(Sender: TObject; ABitmap: TBGRABitmap);
  24. public
  25. constructor Create(TheOwner: TComponent); override;
  26. destructor Destroy; override;
  27. published
  28. end;
  29. { TBCListBox }
  30. TBCListBox = class(TListBox)
  31. private
  32. { Private declarations }
  33. protected
  34. procedure BCDrawItem(Control: TWinControl; Index: integer;
  35. ARect: TRect; State: TOwnerDrawState);
  36. { Protected declarations }
  37. public
  38. { Public declarations }
  39. constructor Create(TheOwner: TComponent); override;
  40. published
  41. { Published declarations }
  42. end;
  43. { TBCPaperListBox }
  44. TBCPaperListBox = class(TBCPaperPanel)
  45. private
  46. FListBox: TBCListBox;
  47. public
  48. constructor Create(TheOwner: TComponent); override;
  49. published
  50. property ListBox: TBCListBox read FListBox write FListBox;
  51. end;
  52. {$IFDEF FPC}procedure Register;{$ENDIF}
  53. implementation
  54. {$IFDEF FPC}
  55. uses
  56. PropEdits;
  57. {$ENDIF}
  58. {$IFDEF FPC}
  59. procedure Register;
  60. begin
  61. RegisterComponents('BGRA Controls', [TBCListBox]);
  62. RegisterComponents('BGRA Controls', [TBCPaperPanel]);
  63. RegisterComponents('BGRA Controls', [TBCPaperListBox]);
  64. {$IFDEF FPC}//#
  65. RegisterPropertyEditor(TypeInfo(TBCListBox),
  66. TBCPaperListBox, 'ListBox', TClassPropertyEditor);
  67. {$ENDIF}
  68. end;
  69. {$ENDIF}
  70. { TBCPaperListBox }
  71. constructor TBCPaperListBox.Create(TheOwner: TComponent);
  72. begin
  73. inherited Create(TheOwner);
  74. Self.ChildSizing.ControlsPerLine := 1;
  75. Self.ChildSizing.LeftRightSPacing := 4;
  76. Self.ChildSizing.TopBottomSpacing := 5;
  77. FListBox := TBCListBox.Create(Self);
  78. FListBox.Align := alClient;
  79. FListBox.Parent := Self;
  80. FListBox.SetSubComponent(true);
  81. end;
  82. { TBCPaperListBox }
  83. procedure TBCPaperPanel.LoadShadowFromBitmapResource;
  84. {$IFDEF FPC}
  85. var
  86. res: TLazarusResourceStream;
  87. {$ENDIF}
  88. begin
  89. {$IFDEF FPC}
  90. res := TLazarusResourceStream.Create('SHADOW', nil);
  91. FShadow := TBGRASliceScaling.Create(res);
  92. FShadow.Margins := Margins(6, 9, 6, 9);
  93. res.Free;
  94. {$ENDIF}
  95. end;
  96. procedure TBCPaperPanel.BCRedraw(Sender: TObject; ABitmap: TBGRABitmap);
  97. begin
  98. FShadow.Draw(ABitmap, 0, 0, ABitmap.Width, ABitmap.Height);
  99. end;
  100. constructor TBCPaperPanel.Create(TheOwner: TComponent);
  101. begin
  102. inherited Create(TheOwner);
  103. LoadShadowFromBitmapResource;
  104. Self.OnRedraw := BCRedraw;
  105. end;
  106. destructor TBCPaperPanel.Destroy;
  107. begin
  108. inherited Destroy;
  109. FShadow.Free;
  110. end;
  111. { TBCListBox }
  112. procedure TBCListBox.BCDrawItem(Control: TWinControl; Index: integer;
  113. ARect: TRect; State: TOwnerDrawState);
  114. var
  115. lb: TListBox;
  116. hg: integer;
  117. begin
  118. {$IFDEF FPC}
  119. lb := TListBox(Control);
  120. lb.Canvas.Clipping := False;
  121. if odFocused in State then
  122. lb.Canvas.Brush.Color := $00e4e4e4
  123. else
  124. lb.Canvas.Brush.Color := clWhite;
  125. if odSelected in State then
  126. lb.Canvas.Font.Style := [fsBold];
  127. lb.Canvas.FillRect(ARect);
  128. hg := lb.Canvas.TextHeight(lb.Items[Index]);
  129. lb.Canvas.Font.Color := clBlack;
  130. lb.Canvas.TextOut(ARect.Left + ScaleX(16, 96), ARect.Top +
  131. (lb.ItemHeight - hg) div 2, lb.Items[Index]);
  132. lb.Canvas.Clipping := True;
  133. lb.Canvas.ClipRect := Rect(0, 0, 0, 0);
  134. {$ENDIF}
  135. end;
  136. constructor TBCListBox.Create(TheOwner: TComponent);
  137. begin
  138. inherited Create(TheOwner);
  139. Self.Style := lbOwnerDrawFixed;
  140. Self.OnDrawItem := BCDrawItem;
  141. {$IFDEF FPC}
  142. Self.ItemHeight := ScaleY(48, 96);
  143. {$ENDIF}
  144. Self.BorderStyle := bsNone;
  145. end;
  146. initialization
  147. {$I bcpaperlistbox.lrs}
  148. end.