📄 teelisb.pas
字号:
if not (csDestroying in ComponentState) then
begin
Items.Clear;
if Assigned(FOtherItems) then FOtherItems.Clear;
end;
end;
Procedure TChartListBox.SelectSeries(AIndex:Integer); { 5.01 }
begin
if MultiSelect then Selected[AIndex]:=True
else ItemIndex:=AIndex;
end;
procedure TChartListBox.SwapSeries(tmp1,tmp2:Integer);
var tmp : TCustomForm;
Series1 : TCustomChartSeries;
Series2 : TCustomChartSeries;
begin
Items.Exchange(tmp1,tmp2);
if Assigned(FOtherItems) then FOtherItems.Exchange(tmp1,tmp2);
if Assigned(Chart) then
begin
Series1:=Series[tmp1];
Series2:=Series[tmp2];
Chart.ExchangeSeries(Series1,Series2);
if Assigned(FOnChangeOrder) then
FOnChangeOrder(Self,Series1,Series2); // 5.03
end;
tmp:=GetParentForm(Self);
if Assigned(tmp) and CanFocus then tmp.ActiveControl:=Self;
SelectSeries(tmp2);
DoRefresh;
RefreshDesigner;
end;
procedure TChartListBox.LBSeriesClick(Sender: TObject);
begin
DoRefresh;
end;
Function TChartListBox.SectionLeft(ASection:Integer):Integer;
var t : Integer;
begin
result:=0;
for t:=0 to ASection-1 do
if Sections[t].Visible then Inc(result,Sections[t].Width);
end;
procedure TChartListBox.SetGroup(Value:TSeriesGroup);
begin
if FGroup<>Value then
begin
FGroup:=Value;
UpdateSeries;
end;
end;
type TSeriesAccess=class(TChartSeries);
{$IFDEF CLX}
procedure TChartListBox.LBSeriesDrawItem(Sender: TObject; Index: Integer;
Rect: TRect; State: TOwnerDrawState; var Handled: Boolean);
{$ELSE}
procedure TChartListBox.LBSeriesDrawItem(Control: TWinControl;
Index: Integer; Rect: TRect; State: TOwnerDrawState);
{$ENDIF}
Const BrushColors : Array[Boolean] of TColor=(clWindow,clHighLight);
FontColors : Array[Boolean] of TColor=(clWindowText,clHighlightText);
var tmp : Integer;
tmpSeries : TChartSeries;
tmpR : TRect;
tmpCanvas : TCanvas;
tmpSelected : Boolean;
begin
tmpCanvas:=Canvas;
tmpSelected:=(odSelected in State) or ((not Focused) and (Index=ItemIndex));
With tmpCanvas do
begin
if tmpSelected then
if (not Focused) and (Index=ItemIndex) then
Brush.Color:={$IFDEF CLX}clHighLight{$ELSE}clInactiveCaption{$ENDIF}
else
Brush.Color:=clHighLight
else
if odFocused in State then
Brush.Color:=clInactiveCaption
else
Brush.Color:=Self.Color;
{$IFDEF CLX}
Brush.Style:=bsSolid;
{$ENDIF}
FillRect(Rect);
Brush.Color:=Self.Color;
Brush.Style:=bsSolid;
tmpR:=Rect;
tmpR.Right:=SectionLeft(3)-2;
{$IFDEF CLX}
Inc(tmpR.Bottom);
{$ENDIF}
FillRect(tmpR);
tmpSeries:=Series[Index];
if Assigned(tmpSeries) then
begin
if ShowSeriesIcon then
TeeDrawBitmapEditor(tmpCanvas,tmpSeries,SectionLeft(0),Rect.Top);
if ShowSeriesColor and
(TSeriesAccess(tmpSeries).IUseSeriesColor) then
begin
tmp:=SectionLeft(2)-2;
tmpR:=TeeRect(tmp,Rect.Top,tmp+Sections[2].Width,Rect.Bottom);
InflateRect(tmpR,-4,-4);
PaintSeriesLegend(tmpSeries,tmpCanvas,tmpR,ReferenceChart);
end;
if ShowActiveCheck then
begin
tmp:=SectionLeft(1);
TeeDrawCheckBox(tmp+2,Rect.Top+((Rect.Bottom-Rect.Top-13) div 2),tmpCanvas,tmpSeries.Active,Self.Color,CheckStyle=cbsCheck);
end;
Brush.Style:=bsClear;
if ShowSeriesTitle then
begin
if tmpSelected then Font.Color:={$IFNDEF CLX}ColorToRGB{$ENDIF}(clHighlightText)
else Font.Color:=ColorToRGB(Self.Font.Color);
{$IFDEF CLX}
Start;
QPainter_setBackgroundMode(Handle,BGMode_TransparentMode);
Stop;
{$ELSE}
SetBkMode(Handle,Transparent);
{$ENDIF}
TextOut(SectionLeft(3)+1,Rect.Top+((ItemHeight-TextHeight('W')) div 2),Items[Index]);
{$IFDEF CLX}
Start;
QPainter_setBackgroundMode(Handle,BGMode_OpaqueMode);
Stop;
{$ELSE}
SetBkMode(Handle,Opaque);
{$ENDIF}
end
else TextOut(0,0,'');
end;
end;
end;
Function TChartListBox.GetSelectedSeries:TChartSeries;
begin
result:=Series[ItemIndex];
end;
procedure TChartListBox.SetNames(Value:Boolean);
begin
if FNames<>Value then
begin
FNames:=Value;
UpdateSeries;
end;
end;
Procedure TChartListBox.SetSelectedSeries(Value:TChartSeries);
begin
ItemIndex:=Items.IndexOfObject(Value);
if ItemIndex<>-1 then Selected[ItemIndex]:=True;
{$IFDEF CLX}
DoRefresh;
{$ENDIF}
end;
procedure TChartListBox.LBSeriesDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
Accept:=FEnableDragSeries and (Sender=Source);
end;
Function TChartListBox.SeriesAtMousePos(Var p:TPoint):Integer;
begin
p:=ScreenToClient(Mouse.CursorPos);
result:=ItemAtPos(p,True);
end;
Function TChartListBox.PointInSection(Const P:TPoint; ASection:Integer):Boolean;
Var tmpPos : Integer;
begin
if Sections[ASection].Visible then
begin
tmpPos:=SectionLeft(ASection);
result:=(p.x>tmpPos) and (p.x<tmpPos+Sections[ASection].Width);
end
else result:=False;
end;
Function TChartListBox.GetSeriesGroup:TCustomSeriesList;
begin
if Assigned(FGroup) then result:=FGroup.Series
else result:=Chart.SeriesList;
end;
procedure TChartListBox.FillSeries(OldSeries:TChartSeries);
var tmp : Integer;
Begin
ClearItems;
if Assigned(Chart) then
FillSeriesItems(Items,GetSeriesGroup,not FNames);
if Assigned(FOtherItems) then FOtherItems.Assign(Items);
tmp:=Items.IndexOfObject(OldSeries);
if (tmp=-1) and (Items.Count>0) then tmp:=0;
if (tmp<>-1) and (Items.Count>tmp) then SelectSeries(tmp);
if Assigned(FOtherItemsChange) then FOtherItemsChange(Self);
DoRefresh;
end;
Function TChartListBox.AnySelected:Boolean; { 5.01 }
begin
if MultiSelect then
begin
result:=SelCount>0;
// Workaround VCL bug:
if (not result) and (Items.Count>0) and (ItemIndex<>-1) then
begin
Selected[ItemIndex]:=True;
result:=True;
end;
end
else result:=ItemIndex<>-1;
end;
procedure TChartListBox.ChangeTypeSeries(Sender: TObject);
var tmpSeries : TChartSeries;
NewClass : TChartSeriesClass;
t : Integer;
tmp : Integer;
FirstTime : Boolean;
tmpList : TChartSeriesList;
begin
if AnySelected and Assigned(Chart) and Assigned(TeeChangeGalleryProc) then
begin
tmpList:=TChartSeriesList.Create;
try
{ get selected list of series }
if MultiSelect then { 5.01 }
begin
for t:=0 to Items.Count-1 do
if Selected[t] then tmpList.Add(Series[t])
end
else tmpList.Add(Series[ItemIndex]);
FirstTime:=True;
NewClass:=nil;
{ change all selected... }
for t:=0 to tmpList.Count-1 do
begin
tmpSeries:=tmpList[t];
if FirstTime then
begin
NewClass:=TeeChangeGalleryProc(Owner,tmpSeries);
FirstTime:=False;
end
else ChangeSeriesType(tmpSeries,NewClass);
tmpList[t]:=tmpSeries;
end;
{ reset the selected list... }
for t:=0 to tmpList.Count-1 do
begin
tmp:=Items.IndexOfObject(tmpList[t]);
if tmp<>-1 then SelectSeries(tmp);
end;
finally
tmpList.Free;
end;
{ refill and repaint list }
DoRefresh;
{ tell the series designer we have changed... }
RefreshDesigner;
end;
end;
procedure TChartListBox.DblClick;
Function IsSelected(tmp:Integer):Boolean; { 5.01 }
begin
if MultiSelect then result:=Selected[tmp]
else result:=ItemIndex=tmp;
end;
var p : TPoint;
tmp : Integer;
tmpColor : TColor;
begin
ComingFromDoubleClick:=True;
{ find series at mouse position "p" }
tmp:=SeriesAtMousePos(p);
if (tmp<>-1) and IsSelected(tmp) then
begin
if PointInSection(p,0) and FEnableChangeType then ChangeTypeSeries(Self)
else
if PointInSection(p,2) and FEnableChangeColor then
begin
if TSeriesAccess(Series[tmp]).IUseSeriesColor then
With Series[tmp] do
begin
tmpColor:=SeriesColor;
if EditColorDialog(Self,tmpColor) then
begin
SeriesColor:=tmpColor;
ColorEachPoint:=False;
if Assigned(FOnChangeColor) then
FOnChangeColor(Self,Series[tmp]);
end;
end;
end
else
if PointInSection(p,3) then
if Assigned(FOnEditSeries) then FOnEditSeries(Self,tmp);
end;
end;
{$IFNDEF CLX}
{$IFDEF D6}
function TChartListBox.GetItemIndex: Integer;
begin
result:=inherited GetItemIndex;
if Count=0 then result:=-1;
end;
{$ENDIF}
{$ENDIF}
procedure TChartListBox.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var tmp : Integer;
t : Integer;
p : TPoint;
begin
inherited; // 7.01
HideEditor;
if ItemIndex<>-1 then
begin
tmp:=SeriesAtMousePos(p);
if (tmp<>-1) and (PointInSection(p,1)) then
begin
if CheckStyle=cbsCheck then
with Series[tmp] do Active:=not Active
else
for t:=0 to Items.Count-1 do Series[t].Active:=t=tmp;
if not Assigned(Series[tmp].ParentChart) then Self.Repaint;
if Assigned(FOnChangeActive) then
FOnChangeActive(Self,Series[tmp]); // 6.02
end
else
if FEnableDragSeries and
PointInSection(p,3) and (not ComingFromDoubleClick) and
(not (ssShift in Shift)) and
(not (ssCtrl in Shift)) and
( ( ssLeft in Shift) ) then
BeginDrag(False);
ComingFromDoubleClick:=False;
if Assigned(FOtherItemsChange) then
FOtherItemsChange(Self);
end;
end;
Procedure TChartListBox.MoveCurrentUp;
begin
if ItemIndex>0 then SwapSeries(ItemIndex,ItemIndex-1);
end;
Procedure TChartListBox.MoveCurrentDown;
begin
if (ItemIndex<>-1) and (ItemIndex<Items.Count-1) then
SwapSeries(ItemIndex,ItemIndex+1);
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -