Browse Source

add Clear, fix Canvas in draw event

Johann 6 years ago
parent
commit
905be5dd58
1 changed files with 23 additions and 1 deletions
  1. 23 1
      bccombobox.pas

+ 23 - 1
bccombobox.pas

@@ -28,9 +28,11 @@ type
     FDropDownBorderColor: TColor;
     FDropDownBorderColor: TColor;
     FOnDrawItem: TDrawItemEvent;
     FOnDrawItem: TDrawItemEvent;
     FOnChange: TNotifyEvent;
     FOnChange: TNotifyEvent;
+    FDrawingDropDown: boolean;
     procedure ButtonClick(Sender: TObject);
     procedure ButtonClick(Sender: TObject);
     procedure FormDeactivate(Sender: TObject);
     procedure FormDeactivate(Sender: TObject);
     procedure FormHide(Sender: TObject);
     procedure FormHide(Sender: TObject);
+    function GetComboCanvas: TCanvas;
     function GetItemText: string;
     function GetItemText: string;
     function GetDropDownBorderStyle: TBorderStyle;
     function GetDropDownBorderStyle: TBorderStyle;
     function GetDropDownColor: TColor;
     function GetDropDownColor: TColor;
@@ -50,11 +52,13 @@ type
     procedure SetItems(AValue: TStrings);
     procedure SetItems(AValue: TStrings);
   public
   public
     constructor Create(AOwner: TComponent); override;
     constructor Create(AOwner: TComponent); override;
+    procedure Clear;
     property HoverItem: integer read FHoverItem;
     property HoverItem: integer read FHoverItem;
     property Button: TBCButton read FButton write FButton;
     property Button: TBCButton read FButton write FButton;
     property ListBox: TListBox read FListBox write FListBox;
     property ListBox: TListBox read FListBox write FListBox;
     property Text: string read GetItemText;
     property Text: string read GetItemText;
   published
   published
+    property Canvas: TCanvas read GetComboCanvas;
     property Items: TStrings read GetItems write SetItems;
     property Items: TStrings read GetItems write SetItems;
     property ItemIndex: integer read GetItemIndex write SetItemIndex;
     property ItemIndex: integer read GetItemIndex write SetItemIndex;
     property ItemHeight: integer read FItemHeight write FItemHeight default 0;
     property ItemHeight: integer read FItemHeight write FItemHeight default 0;
@@ -137,6 +141,14 @@ begin
   FFormHideDate := Now;
   FFormHideDate := Now;
 end;
 end;
 
 
+function TBCComboBox.GetComboCanvas: TCanvas;
+begin
+  if FDrawingDropDown then
+    result := ListBox.Canvas
+  else
+    result := inherited Canvas;
+end;
+
 function TBCComboBox.GetItemText: string;
 function TBCComboBox.GetItemText: string;
 begin
 begin
   if FListBox.ItemIndex<>-1 then
   if FListBox.ItemIndex<>-1 then
@@ -207,7 +219,12 @@ var
 begin
 begin
   if Assigned(FOnDrawItem) then
   if Assigned(FOnDrawItem) then
   begin
   begin
-    FOnDrawItem(Control, Index, ARect, State);
+    FDrawingDropDown := true;
+    try
+      FOnDrawItem(Control, Index, ARect, State);
+    finally
+      FDrawingDropDown := false;
+    end;
     exit;
     exit;
   end;
   end;
 
 
@@ -279,4 +296,9 @@ begin
   FDropDownFontHighlight:= clHighlightText;
   FDropDownFontHighlight:= clHighlightText;
 end;
 end;
 
 
+procedure TBCComboBox.Clear;
+begin
+  Items.Clear;
+end;
+
 end.
 end.