home *** CD-ROM | disk | FTP | other *** search
- {****************************************************************************}
- { Data Master 2000 }
- {****************************************************************************}
- unit SerieDlg;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Spin, ComCtrls, ImgList, Buttons, ExtCtrls, ColorGrd, Data, Plot;
-
- type
- TSeriePropsForm = class(TForm)
- OkBitBtn: TBitBtn;
- CancelBitBtn: TBitBtn;
- HelpBitBtn: TBitBtn;
- ImageList: TImageList;
- ColorDialog: TColorDialog;
- PageControl: TPageControl;
- DataTabSheet: TTabSheet;
- ViewTabSheet: TTabSheet;
- XGroupBox: TGroupBox;
- GridIntervalsLabel: TLabel;
- XColumnRadioButton: TRadioButton;
- XExpressionRadioButton: TRadioButton;
- XGridRadioButton: TRadioButton;
- XExpressionComboBox: TComboBox;
- GridIntervalsSpinEdit: TSpinEdit;
- YGroupBox: TGroupBox;
- YColumnRadioButton: TRadioButton;
- YExpressionRadioButton: TRadioButton;
- YExpressionComboBox: TComboBox;
- FirstLineLabel: TLabel;
- FirstLineSpinEdit: TSpinEdit;
- LastLineLabel: TLabel;
- LastLineSpinEdit: TSpinEdit;
- InterleaveSpinEdit: TSpinEdit;
- InterleaveLabel: TLabel;
- WorksheetLabel: TLabel;
- WorksheetComboBox: TComboBox;
- PointsCheckBox: TCheckBox;
- PointsPanel: TPanel;
- PointSizeLabel: TLabel;
- PointSizeSpinEdit: TSpinEdit;
- PointTypeComboBox: TComboBox;
- PointTypeLabel: TLabel;
- LinePanel: TPanel;
- LineWidthLabel: TLabel;
- LineTypeLabel: TLabel;
- LineWidthSpinEdit: TSpinEdit;
- LineTypeComboBox: TComboBox;
- LineCheckBox: TCheckBox;
- PreviewPaintBox: TPaintBox;
- CaptionLabel: TLabel;
- CaptionEdit: TEdit;
- XColumnComboBox: TComboBox;
- YColumnComboBox: TComboBox;
- PointsColorGroupBox: TGroupBox;
- PointsColorGrid: TColorGrid;
- PointsColorBitBtn: TBitBtn;
- LineColorGroupBox: TGroupBox;
- LineColorGrid: TColorGrid;
- LineColorBitBtn: TBitBtn;
- InfoTabSheet: TTabSheet;
- BestFitCheckBox: TCheckBox;
- BestFitBevel: TBevel;
- BestFitLabel: TLabel;
- BestFitEdit: TEdit;
- LimitsGroupBox: TGroupBox;
- X1Label: TLabel;
- X2Label: TLabel;
- Y1Label: TLabel;
- Y2Label: TLabel;
- X1Edit: TEdit;
- X2Edit: TEdit;
- Y1Edit: TEdit;
- Y2Edit: TEdit;
- SetScaleBitBtn: TBitBtn;
- XTextSpeedButton: TSpeedButton;
- YTextSpeedButton: TSpeedButton;
- procedure PointPanelCheckBoxClick(Sender: TObject);
- procedure ColumnRadioButtonClick(Sender: TObject);
- procedure XExpressionComboBoxChange(Sender: TObject);
- procedure YExpressionComboBoxChange(Sender: TObject);
- procedure PreviewPaintBoxPaint(Sender: TObject);
- procedure ColorGridChange(Sender: TObject);
- procedure PointsColorBitBtnClick(Sender: TObject);
- procedure LineColorBitBtnClick(Sender: TObject);
- procedure LineTypeComboBoxDrawItem(Control: TWinControl;
- Index: Integer; R: TRect; State: TOwnerDrawState);
- procedure PointTypeComboBoxDrawItem(Control: TWinControl;
- Index: Integer; R: TRect; State: TOwnerDrawState);
- procedure WorksheetComboBoxChange(Sender: TObject);
- procedure SetScaleBitBtnClick(Sender: TObject);
- procedure XTextSpeedButtonClick(Sender: TObject);
- procedure YTextSpeedButtonClick(Sender: TObject);
- procedure WorksheetComboBoxDropDown(Sender: TObject);
- private
- { Private declarations }
- PointColorBuf,LineColorBuf: TColor;
- FPlot: TPlot; FSerie: TSerie;
- procedure UpdateBlockControls;
- public
- { Public declarations }
- function Execute(Serie: TSerie): boolean;
- end;
-
- var SeriePropsForm: TSeriePropsForm;
-
- resourcestring
- strNotScaled='Unavailable (serie not scaled)';
-
- implementation
-
- uses TypInfo, TextDlg;
-
- {$R *.DFM}
-
- { TSeriePropsForm }
-
- {prior to Execute() call, following comboboxes MUST be initialized:
- 1) Columns combos - with valid column number and labels;
- 2) Worksheet combo: Clear, then AddObjects(<Window caption/Filename>,
- <Pointer to TContainer>) + ItemIndex set to serie's container (or -1);
- 3) Expressions combos - assigned expressions history list.}
- function TSeriePropsForm.Execute(Serie: TSerie): boolean;
- var BX,BY: boolean; I: integer;
- begin
- FPlot:=(Serie.Collection as TSeries).Plot; {save reference for PaintPoint()}
- FSerie:=Serie; {for SetScaleBitBtnClick()}
- XColumnRadioButton.Checked:=true; YColumnRadioButton.Checked:=true; {reset}
- XColumnComboBox.ItemIndex:=Serie.XColumn-1; {copy properties from serie}
- YColumnComboBox.ItemIndex:=Serie.YColumn-1;
- XExpressionComboBox.Text:=Serie.XExpression; XExpressionComboBoxChange(nil);
- YExpressionComboBox.Text:=Serie.YExpression; YExpressionComboBoxChange(nil);
- if Assigned(Serie.Container) then
- begin
- FirstLineSpinEdit.MaxValue:=Serie.Container.Items.Count-1;
- LastLineSpinEdit.MaxValue:=Serie.Container.Items.Count-1;
- end else
- begin
- FirstLineSpinEdit.MaxValue:=-1; LastLineSpinEdit.MaxValue:=-1;
- end;
- FirstLineSpinEdit.Value:=Serie.FirstLine;
- LastLineSpinEdit.Value:=Serie.LastLine;
- InterleaveSpinEdit.Value:=Serie.Interleave;
- PointsCheckBox.Checked:=Serie.PointVisible; {handler called implicitly!}
- LineCheckBox.Checked:=Serie.LineVisible;
- CaptionEdit.Text:=Serie.Text;
- PointsColorGrid.ForegroundIndex:=-1;
- LineColorGrid.ForegroundIndex:=-1;
- PointColorBuf:=Serie.Brush.Color;
- LineColorBuf:=Serie.Pen.Color;
- PointSizeSpinEdit.Value:=Serie.PointSize;
- PointTypeComboBox.ItemIndex:=ord(Serie.PointType);
- LineWidthSpinEdit.Value:=Serie.Pen.Width;
- case Serie.Pen.Style of
- psSolid: LineTypeComboBox.ItemIndex:=0;
- psDash: LineTypeComboBox.ItemIndex:=1;
- psDot: LineTypeComboBox.ItemIndex:=2;
- psDashDot: LineTypeComboBox.ItemIndex:=3;
- else LineTypeComboBox.ItemIndex:=-1;
- end;
- if Serie.IsFunction then
- begin
- XGridRadioButton.Checked:=true;
- GridIntervalsSpinEdit.Value:=Serie.LastLine-Serie.FirstLine;
- end;
- if Serie.Scaled then
- begin
- BestFitEdit.Text:='Y=X*'+FloatToStr(Serie.bfA);
- if Serie.bfB>0
- then BestFitEdit.Text:=BestFitEdit.Text+'+'+FloatToStr(Serie.bfB)
- else BestFitEdit.Text:=BestFitEdit.Text+FloatToStr(Serie.bfB);
- X1Edit.Text:=FloatToStr(Serie.X1); X2Edit.Text:=FloatToStr(Serie.X2);
- Y1Edit.Text:=FloatToStr(Serie.Y1); Y2Edit.Text:=FloatToStr(Serie.Y2);
- end else
- begin
- X1Edit.Text:=strNotScaled; X2Edit.Text:=strNotScaled;
- Y1Edit.Text:=strNotScaled; Y2Edit.Text:=strNotScaled;
- BestFitEdit.Text:=strNotScaled;
- end;
- LimitsGroupBox.Enabled:=Serie.Scaled; SetScaleBitBtn.Enabled:=Serie.Scaled;
- BestFitCheckBox.Checked:=Serie.ShowBestFit;
- Result:=ShowModal=mrOK; if not Result then Exit; {cancelled}
- Serie.ShowBestFit:=BestFitCheckBox.Checked;
- Serie.XColumn:=XColumnComboBox.ItemIndex+1; {copy properties to serie}
- Serie.YColumn:=YColumnComboBox.ItemIndex+1;
- Serie.XExpression:=XExpressionComboBox.Text;
- Serie.YExpression:=YExpressionComboBox.Text;
- Serie.FirstLine:=FirstLineSpinEdit.Value;
- Serie.LastLine:=LastLineSpinEdit.Value;
- Serie.Interleave:=InterleaveSpinEdit.Value;
- with WorksheetComboBox do if (ItemIndex>=0)
- and (Items.Objects[ItemIndex] is TContainer)
- then Serie.Container:=Items.Objects[ItemIndex] as TContainer;
- Serie.IsFunction:=XGridRadioButton.Checked;
- if Serie.IsFunction
- then Serie.LastLine:=Serie.FirstLine+GridIntervalsSpinEdit.Value;
- Serie.PointVisible:=PointsCheckBox.Checked;
- Serie.LineVisible:=LineCheckBox.Checked;
- Serie.Text:=CaptionEdit.Text;
- Serie.Brush.Color:=PointColorBuf;
- Serie.Pen.Color:=LineColorBuf;
- Serie.PointSize:=PointSizeSpinEdit.Value;
- Serie.PointType:=TPointType(PointTypeComboBox.ItemIndex);
- Serie.Pen.Width:=LineWidthSpinEdit.Value;
- case LineTypeComboBox.ItemIndex of
- 0: Serie.Pen.Style:=psSolid;
- 1: Serie.Pen.Style:=psDash;
- 2: Serie.Pen.Style:=psDot;
- 3: Serie.Pen.Style:=psDashDot;
- end;
- BX:=true; BY:=true; {add expressions to historylist}
- with XExpressionComboBox.Items do for I:=0 to Count-1 do
- begin
- if Strings[I]=XExpressionComboBox.Text then BX:=false;
- if Strings[I]=YExpressionComboBox.Text then BY:=false;
- end;
- with XExpressionComboBox do {result saved only in XExpressionComboBox!}
- begin
- if BX and (Text<>'') then Items.Insert(0, Text);
- if BY and (YExpressionComboBox.Text<>'')
- then Items.Insert(0, YExpressionComboBox.Text);
- end;
- end;
-
- procedure TSeriePropsForm.PointPanelCheckBoxClick(Sender: TObject);
- var I: integer; B: boolean; P: TPanel; PropInfo: PPropInfo;
- begin
- B:=(Sender as TCheckBox).Checked;
- if Sender=PointsCheckBox then P:=PointsPanel else P:=LinePanel;
- P.Enabled:=B;
- for I:=0 to P.ControlCount-1 do
- begin
- PropInfo:=GetPropInfo(P.Controls[I].ClassInfo,'Enabled');
- if (PropInfo<>nil) then SetOrdProp(P.Controls[I],PropInfo,integer(B));
- end;
- PreviewPaintBoxPaint(nil);
- end;
-
- procedure TSeriePropsForm.UpdateBlockControls;
- begin
- XColumnComboBox.Enabled:=XColumnRadioButton.Checked;
- if XColumnRadioButton.Checked then XExpressionComboBox.Text:='';
- if XExpressionRadioButton.Checked and (XColumnComboBox.ItemIndex<0)
- then XColumnComboBox.ItemIndex:=0;
- GridIntervalsLabel.Enabled:=XGridRadioButton.Checked;
- GridIntervalsSpinEdit.Enabled:=XGridRadioButton.Checked;
- XExpressionComboBox.Enabled:=not XGridRadioButton.Checked;
- XTextSpeedButton.Enabled:=XExpressionComboBox.Enabled;
- FirstLineSpinEdit.Enabled:=not XGridRadioButton.Checked;
- LastLineSpinEdit.Enabled:=not XGridRadioButton.Checked;
- InterleaveSpinEdit.Enabled:=not XGridRadioButton.Checked;
- FirstLineLabel.Enabled:=not XGridRadioButton.Checked;
- LastLineLabel.Enabled:=not XGridRadioButton.Checked;
- InterleaveLabel.Enabled:=not XGridRadioButton.Checked;
- YColumnRadioButton.Enabled:=not XGridRadioButton.Checked;
- if XGridRadioButton.Checked then YExpressionRadioButton.Checked:=true;
- YColumnComboBox.Enabled:=YColumnRadioButton.Checked;
- if YColumnRadioButton.Checked then YExpressionComboBox.Text:='';
- if YExpressionRadioButton.Checked and (YColumnComboBox.ItemIndex<0)
- then YColumnComboBox.ItemIndex:=0;
- WorksheetComboBox.Enabled:=not XGridRadioButton.Checked;
- WorksheetLabel.Enabled:=not XGridRadioButton.Checked;
- if XGridRadioButton.Checked then WorksheetComboBox.ItemIndex:=-1;
- end;
-
- procedure TSeriePropsForm.ColumnRadioButtonClick(Sender: TObject);
- begin UpdateBlockControls; end;
-
- procedure TSeriePropsForm.XExpressionComboBoxChange(Sender: TObject);
- begin
- if XExpressionComboBox.Text<>'' then XExpressionRadioButton.Checked:=true;
- end;
-
- procedure TSeriePropsForm.YExpressionComboBoxChange(Sender: TObject);
- begin
- if YExpressionComboBox.Text<>'' then YExpressionRadioButton.Checked:=true;
- end;
-
- procedure TSeriePropsForm.PreviewPaintBoxPaint(Sender: TObject);
- begin
- with PreviewPaintBox do
- begin
- Canvas.Brush.Color:=Color;
- Canvas.FillRect(Rect(0,0,Width,Height));
- Canvas.Pen.Color:=LineColorBuf;
- case LineTypeComboBox.ItemIndex of
- 0: Canvas.Pen.Style:=psSolid;
- 1: Canvas.Pen.Style:=psDash;
- 2: Canvas.Pen.Style:=psDot;
- 3: Canvas.Pen.Style:=psDashDot;
- end;
- Canvas.Pen.Width:=LineWidthSpinEdit.Value;
- Canvas.Brush.Color:=PointColorBuf;
- Canvas.MoveTo(1, Height div 2);
- if LineCheckBox.Checked then Canvas.LineTo(Width-1, Height div 2);
- if PointsCheckBox.Checked then FPlot.PaintPoint(Width div 2, Height div 2,
- TPointType(PointTypeComboBox.ItemIndex),PointSizeSpinEdit.Value,Canvas);
- end;
- end;
-
- procedure TSeriePropsForm.ColorGridChange(Sender: TObject);
- begin
- if Sender=PointsColorGrid then
- PointColorBuf:=PointsColorGrid.ForegroundColor;
- if Sender=LineColorGrid then LineColorBuf:=LineColorGrid.ForegroundColor;
- PreviewPaintBoxPaint(nil);
- end;
-
- procedure TSeriePropsForm.PointsColorBitBtnClick(Sender: TObject);
- begin
- ColorDialog.Color:=PointColorBuf; if not ColorDialog.Execute then Exit;
- PointsColorGrid.ForegroundIndex:=-1; PointColorBuf:=ColorDialog.Color;
- PreviewPaintBoxPaint(nil);
- end;
-
- procedure TSeriePropsForm.LineColorBitBtnClick(Sender: TObject);
- begin
- ColorDialog.Color:=LineColorBuf; if not ColorDialog.Execute then Exit;
- LineColorGrid.ForegroundIndex:=-1; LineColorBuf:=ColorDialog.Color;
- PreviewPaintBoxPaint(nil);
- end;
-
- procedure TSeriePropsForm.LineTypeComboBoxDrawItem(Control: TWinControl;
- Index: Integer; R: TRect; State: TOwnerDrawState);
- var PSBuf: TPenStyle;
- begin
- with LineTypeComboBox do
- begin
- Canvas.FillRect(R); PSBuf:=Canvas.Pen.Style;
- case Index of
- 0: Canvas.Pen.Style:=psSolid;
- 1: Canvas.Pen.Style:=psDash;
- 2: Canvas.Pen.Style:=psDot;
- 3: Canvas.Pen.Style:=psDashDot;
- end;
- Canvas.MoveTo(R.Left, R.Top+(R.Bottom-R.Top) div 2);
- Canvas.LineTo(R.Right, R.Top+(R.Bottom-R.Top) div 2);
- Canvas.Pen.Style:=PSBuf;
- end;
- end;
-
- procedure TSeriePropsForm.PointTypeComboBoxDrawItem(Control: TWinControl;
- Index: Integer; R: TRect; State: TOwnerDrawState);
- begin
- with PointTypeComboBox do
- begin
- Canvas.FillRect(R);
- FPlot.PaintPoint((R.Left+R.Right) div 2, R.Top+((R.Bottom-R.Top) div 2),
- TPointType(Index), ((R.Bottom-R.Top) div 2)+2, Canvas);
- end;
- end;
-
- procedure TSeriePropsForm.WorksheetComboBoxChange(Sender: TObject);
- begin
- with WorksheetComboBox do if (ItemIndex>=0)
- and (Items.Objects[ItemIndex] is TContainer) then
- with (Items.Objects[ItemIndex] as TContainer) do
- begin
- FirstLineSpinEdit.MaxValue:=Items.Count-1;
- with FirstLineSpinEdit do if Value>MaxValue then Value:=MaxValue;
- LastLineSpinEdit.MaxValue:=Items.Count-1;
- with LastLineSpinEdit do if Value>MaxValue then Value:=MaxValue;
- end else
- begin
- FirstLineSpinEdit.MaxValue:=-1; LastLineSpinEdit.MaxValue:=-1;
- end;
- end;
-
- procedure TSeriePropsForm.SetScaleBitBtnClick(Sender: TObject);
- begin
- FPlot.XAxis.Autoscale:=false; FPlot.YAxis.Autoscale:=false;
- FPlot.XAxis.Min:=FSerie.X1; FPlot.XAxis.Max:=FSerie.X2;
- FPlot.YAxis.Min:=FSerie.Y1; FPlot.YAxis.Max:=FSerie.Y2;
- end;
-
- procedure TSeriePropsForm.XTextSpeedButtonClick(Sender: TObject);
- var S: string;
- begin
- S:=XExpressionComboBox.Text;
- if InputText(S,XExpressionComboBox) then XExpressionComboBox.Text:=S;
- end;
-
- procedure TSeriePropsForm.YTextSpeedButtonClick(Sender: TObject);
- var S: string;
- begin
- S:=YExpressionComboBox.Text;
- if InputText(S,YExpressionComboBox) then YExpressionComboBox.Text:=S;
- end;
-
- procedure TSeriePropsForm.WorksheetComboBoxDropDown(Sender: TObject);
- var I,N: integer; // correct list size for long fnames (font must be fixed!)
- begin
- N:=0; with Sender as TComboBox do
- begin
- for I:=0 to Items.Count-1 do
- if N<length(Items[I]) then N:=length(Items[I]); // get max string length
- N:=Round(-N*Font.Height/1.5); if N<Width then N:=Width;
- SendMessage(Handle,CB_SETDROPPEDWIDTH,N,0); // do it!
- end;
- end;
-
- end.
-
-