diff --git a/components/tachart/demo/listbox/Unit1.lfm b/components/tachart/demo/listbox/Unit1.lfm index 71c41b861c..54feae5ff4 100644 --- a/components/tachart/demo/listbox/Unit1.lfm +++ b/components/tachart/demo/listbox/Unit1.lfm @@ -202,22 +202,13 @@ object Form1: TForm1 OnChange = CbCheckStyleChange TabOrder = 6 end - object CbMultiSelect: TCheckBox - Left = 8 - Height = 17 - Top = 344 - Width = 71 - Caption = 'MultiSelect' - OnChange = CbMultiSelectChange - TabOrder = 7 - end object Memo: TMemo Left = 9 Height = 106 Top = 104 Width = 275 ScrollBars = ssAutoVertical - TabOrder = 8 + TabOrder = 7 end object Label1: TLabel Left = 9 @@ -230,17 +221,17 @@ object Form1: TForm1 object EdColumns: TSpinEdit Left = 208 Height = 21 - Top = 340 + Top = 308 Width = 50 MinValue = 1 OnChange = EdColumnsChange - TabOrder = 9 + TabOrder = 8 Value = 1 end object Label2: TLabel Left = 152 Height = 14 - Top = 345 + Top = 313 Width = 45 Caption = 'Columns:' ParentColor = False @@ -252,7 +243,7 @@ object Form1: TForm1 Width = 81 Caption = 'Delete series' OnClick = BtnDeleteSeriesClick - TabOrder = 10 + TabOrder = 9 end object CbKeepSeriesOut: TCheckBox Left = 9 @@ -261,7 +252,7 @@ object Form1: TForm1 Width = 227 Caption = 'Keep sin and cos series out of ChartListBox' OnChange = CbKeepSeriesOutChange - TabOrder = 11 + TabOrder = 10 end object Bevel1: TBevel Left = 9 diff --git a/components/tachart/demo/listbox/Unit1.pas b/components/tachart/demo/listbox/Unit1.pas index a839af34da..27e11a8cb4 100644 --- a/components/tachart/demo/listbox/Unit1.pas +++ b/components/tachart/demo/listbox/Unit1.pas @@ -24,7 +24,6 @@ type CbShowCheckboxes: TCheckBox; CbShowSeriesIcon: TCheckBox; CbCheckStyle: TCheckBox; - CbMultiSelect: TCheckBox; CbKeepSeriesOut: TCheckBox; ChartListbox: TChartListbox; CheckListBox1: TCheckListBox; @@ -45,7 +44,6 @@ type procedure BtnToggleCOSClick(Sender: TObject); procedure BtnToggleChartClick(Sender: TObject); procedure BtnToggleSINClick(Sender: TObject); - procedure CbMultiSelectChange(Sender: TObject); procedure CbShowCheckboxesChange(Sender: TObject); procedure CbShowSeriesIconChange(Sender: TObject); procedure CbCheckStyleChange(Sender: TObject); @@ -138,19 +136,22 @@ begin SinSeries.Active := not SinSeries.Active; end; -procedure TForm1.CbMultiSelectChange(Sender: TObject); -begin - ChartListbox.MultiSelect := CbMultiSelect.Checked; -end; - procedure TForm1.CbShowCheckboxesChange(Sender: TObject); begin - ChartListbox.ShowCheckboxes := CbShowCheckboxes.Checked; + with ChartListbox do + if CbShowCheckboxes.Checked then + Options := Options + [cloShowCheckboxes] + else + Options := Options - [cloShowCheckboxes]; end; procedure TForm1.CbShowSeriesIconChange(Sender: TObject); begin - ChartListbox.ShowSeriesIcons := CbShowSeriesIcon.Checked; + with ChartListbox do + if CbShowSeriesIcon.Checked then + Options := Options + [cloShowIcons] + else + Options := Options - [cloShowIcons]; end; procedure TForm1.CbCheckStyleChange(Sender:TObject); diff --git a/components/tachart/tachartlistbox.pas b/components/tachart/tachartlistbox.pas index 47f0efe0ca..5bd924cbff 100644 --- a/components/tachart/tachartlistbox.pas +++ b/components/tachart/tachartlistbox.pas @@ -41,6 +41,13 @@ type TCheckBoxesStyle = (cbsCheckbox, cbsRadiobutton); + TChartListOption = (cloShowCheckboxes, cloShowIcons); + TChartListOptions = set of TChartListOption; + +const + SHOW_ALL = [cloShowCheckboxes, cloShowIcons]; + +type TChartListbox = class(TCustomListbox) private FChart: TChart; @@ -52,9 +59,8 @@ type FOnItemClick: TChartListboxIndexEvent; FOnPopulate: TNotifyEvent; FOnSeriesIconClick: TChartListboxIndexEvent; + FOptions: TChartListOptions; FSeriesIconClicked: Integer; - FShowCheckboxes: Boolean; - FShowSeriesIcons: Boolean; function GetChecked(AIndex: Integer): Boolean; function GetLegendItem(AIndex: Integer): TLegendItem; function GetSeries(AIndex: Integer): TCustomChartSeries; @@ -64,8 +70,7 @@ type procedure SetChecked(AIndex: Integer; AValue: Boolean); procedure SetCheckStyle(AValue: TCheckBoxesStyle); procedure SetOnPopulate(AValue: TNotifyEvent); - procedure SetShowCheckboxes(AValue: Boolean); - procedure SetShowSeriesIcons(AValue: Boolean); + procedure SetOptions(AValue: TChartListOptions); protected procedure DblClick; override; @@ -101,10 +106,8 @@ type property Chart: TChart read FChart write SetChart; property CheckStyle: TCheckBoxesStyle read FCheckStyle write SetCheckStyle default cbsCheckbox; - property ShowCheckboxes: Boolean - read FShowCheckboxes write SetShowCheckboxes default true; - property ShowSeriesIcons: Boolean - read FShowSeriesIcons write SetShowSeriesIcons default true; + property Options: TChartListOptions + read FOptions write SetOptions default SHOW_ALL; published property OnCheckboxClick: TChartListboxIndexEvent read FOnCheckboxClick write FOnCheckboxClick; @@ -191,8 +194,7 @@ begin inherited Create(AOwner); Style := lbOwnerDrawFixed; FListener := TListener.Create(@FChart, @SeriesChanged); - FShowSeriesIcons := true; - FShowCheckboxes := true; + FOptions := SHOW_ALL; end; destructor TChartListbox.Destroy; @@ -213,16 +215,16 @@ begin ASeriesIconRect := Rect(-1, -1, -1, -1); w := GetSystemMetrics(SM_CYMENUCHECK); x := 2; - if FShowCheckboxes then begin + if cloShowCheckboxes in Options then begin ACheckboxRect := Bounds(AItemRect.Left + 1, AItemRect.Top + 1, w, w); - if FShowSeriesIcons then + if cloShowIcons in Options then x += ACheckboxRect.Right; end else begin - if FShowSeriesIcons then + if cloShowIcons in Options then x += AItemRect.Left; end; - if FShowSeriesIcons then + if cloShowIcons in Options then ASeriesIconRect := Rect( x, AItemRect.Top + 2, x + FChart.Legend.SymbolWidth, AItemRect.Bottom - 2); end; @@ -297,7 +299,7 @@ begin CalcRects(ARect, rcb, ricon); - if FShowCheckboxes then begin + if cloShowCheckboxes in Options then begin ch := Checked[AIndex]; if ThemeServices.ThemesEnabled then begin te := ThemeServices.GetElementDetails(THEMED_FLAGS[FCheckStyle, ch]); @@ -311,7 +313,7 @@ begin else x := ARect.Left; - if FShowSeriesIcons then begin + if cloShowIcons in Options then begin id := TCanvasDrawer.Create(Canvas); id.Pen := Chart.Legend.SymbolFrame; FLegendItems[AIndex].Draw(id, ricon); @@ -380,7 +382,8 @@ end; procedure TChartListbox.KeyDown(var AKey: Word; AShift: TShiftState); { allows checking/unchecking of items by means of pressing the space bar } begin - if (AKey = VK_SPACE) and (AShift = []) and FShowCheckboxes then begin + if (AKey = VK_SPACE) and (AShift = []) and (cloShowCheckboxes in Options) then + begin ClickedCheckbox(ItemIndex); AKey := VK_UNKNOWN; end @@ -401,7 +404,7 @@ procedure TChartListbox.MeasureItem(AIndex: Integer; var AHeight: Integer); begin Unused(AIndex); AHeight := CalculateStandardItemHeight; - if FShowCheckboxes then + if cloShowCheckboxes in Options then AHeight := Max(AHeight, GetSystemMetrics(SM_CYMENUCHECK) + 2); end; @@ -428,9 +431,9 @@ begin index := GetIndexAtXY(AX, AY); if index < 0 then exit; CalcRects(ItemRect(index), rcb, ricon); - if FShowCheckboxes and IsPointInRect(p, rcb) then + if (cloShowCheckboxes in Options) and IsPointInRect(p, rcb) then ClickedCheckbox(index) - else if FShowSeriesIcons and IsPointInRect(p, ricon) then + else if (cloShowIcons in Options) and IsPointInRect(p, ricon) then // Remember clicked index for the double click event. FSeriesIconClicked := index else @@ -553,17 +556,10 @@ begin Populate; end; -procedure TChartListbox.SetShowCheckboxes(AValue: Boolean); +procedure TChartListbox.SetOptions(AValue: TChartListOptions); begin - if FShowCheckboxes = AValue then exit; - FShowCheckboxes := AValue; - Invalidate; -end; - -procedure TChartListbox.SetShowSeriesIcons(AValue: Boolean); -begin - if FShowSeriesIcons = AValue then exit; - FShowSeriesIcons := AValue; + if FOptions = AValue then exit; + FOptions := AValue; Invalidate; end;