home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 September
/
Chip_2002-09_cd1.bin
/
zkuste
/
delphi
/
kompon
/
d6
/
YPPARSER.ZIP
/
GraphX
/
GraphImpl.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
2002-06-14
|
19KB
|
702 lines
{********************************************************}
{ }
{ GraphX }
{ IMPORTANT-READ CAREFULLY: }
{ }
{ This End-User License Agreement is a legal }
{ agreement between you (either an individual }
{ or a single entity) and Pisarev Yuriy for }
{ the software product identified above, which }
{ includes computer software and may include }
{ associated media, printed materials, and "online" }
{ or electronic documentation ("SOFTWARE PRODUCT"). }
{ By installing, copying, or otherwise using the }
{ SOFTWARE PRODUCT, you agree to be bound by the }
{ terms of this LICENSE AGREEMENT. }
{ }
{ If you do not agree to the terms of this }
{ LICENSE AGREEMENT, do not install or use }
{ the SOFTWARE PRODUCT. }
{ }
{ License conditions }
{ }
{ No part of the software or the manual may be }
{ multiplied, disseminated or processed in any }
{ way without the written consent of Pisarev }
{ Yuriy. Violations of these conditions will be }
{ prosecuted in every case. }
{ }
{ The use of the software is done at your own }
{ risk. The manufacturer and developer accepts }
{ no liability for any damages, either as direct }
{ or indirect consequence of the use of this }
{ product or software. }
{ }
{ Only observance of these conditions allows you }
{ to use the hardware and software in your computer }
{ system. }
{ }
{ All rights reserved. }
{ Copyright 2002 Pisarev Yuriy }
{ }
{ yuriy_mbox@hotmail.com }
{ }
{********************************************************}
unit GraphImpl;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ActiveX, AxCtrls, XGraph_TLB, StdVcl, ActnList, ActnMan, ImgList,
ComCtrls, StdCtrls, ExtCtrls, ToolWin, ClipBrd, GraphBldr, Menus;
type
TGraphX = class(TActiveForm, IGraphX)
ControlBar1: TControlBar;
ToolBar1: TToolBar;
Panel1: TPanel;
tbCalculate: TToolButton;
tbDelete: TToolButton;
tbShowGrid: TToolButton;
tbCopy: TToolButton;
ToolButton1: TToolButton;
tbDetailLevel: TTrackBar;
tbGraphColor: TToolButton;
ToolButton2: TToolButton;
StatusBar: TStatusBar;
ImageList1: TImageList;
ActionManager1: TActionManager;
EditCalculate: TAction;
EditShowGrid: TAction;
EditTrace: TAction;
EditCopy: TAction;
EditDelete: TAction;
EditGraphColor: TAction;
ColorDialog: TColorDialog;
HelpAbout: TAction;
GraphBldr: TGraphBldr;
ToolBar2: TToolBar;
Panel2: TPanel;
edXMaxValue: TEdit;
udXMaxValue: TUpDown;
ToolButton4: TToolButton;
Panel3: TPanel;
edYMaxValue: TEdit;
udYMaxValue: TUpDown;
ToolButton5: TToolButton;
Panel4: TPanel;
edPenWidth: TEdit;
udPenWidth: TUpDown;
ToolButton6: TToolButton;
Panel6: TPanel;
edHorzSpacing: TEdit;
udHorzSpacing: TUpDown;
ToolButton7: TToolButton;
Panel7: TPanel;
edVertSpacing: TEdit;
udVertSpacing: TUpDown;
EditAxis: TAction;
tbHelp: TToolButton;
tbAxis: TToolButton;
ToolButton3: TToolButton;
RichEdit: TRichEdit;
tbTrace: TToolButton;
procedure EditCalculateExecute(Sender: TObject);
procedure EditShowGridExecute(Sender: TObject);
procedure EditAxisExecute(Sender: TObject);
procedure EditTraceExecute(Sender: TObject);
procedure EditCopyExecute(Sender: TObject);
procedure EditDeleteExecute(Sender: TObject);
procedure EditGraphColorExecute(Sender: TObject);
procedure GraphBldrMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure GraphBldrTrace(Sender: TObject; X, Y: Double);
procedure edTextKeyPress(Sender: TObject; var Key: Char);
procedure tbDetailLevelChange(Sender: TObject);
procedure RichEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure edXMaxValueChange(Sender: TObject);
procedure edYMaxValueChange(Sender: TObject);
procedure edPenWidthChange(Sender: TObject);
procedure edHorzSpacingChange(Sender: TObject);
procedure edVertSpacingChange(Sender: TObject);
procedure EditKeyPress(Sender: TObject; var Key: Char);
procedure HelpAboutExecute(Sender: TObject);
private
FEvents: IGraphXEvents;
procedure ActivateEvent(Sender: TObject);
procedure ClickEvent(Sender: TObject);
procedure CreateEvent(Sender: TObject);
procedure DblClickEvent(Sender: TObject);
procedure DeactivateEvent(Sender: TObject);
procedure DestroyEvent(Sender: TObject);
procedure KeyPressEvent(Sender: TObject; var Key: Char);
procedure PaintEvent(Sender: TObject);
protected
procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
procedure EventSinkChanged(const EventSink: IUnknown); override;
function Get_Active: WordBool; safecall;
function Get_AlignDisabled: WordBool; safecall;
function Get_AutoScroll: WordBool; safecall;
function Get_AutoSize: WordBool; safecall;
function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
function Get_Caption: WideString; safecall;
function Get_Color: OLE_COLOR; safecall;
function Get_Cursor: Smallint; safecall;
function Get_DoubleBuffered: WordBool; safecall;
function Get_DropTarget: WordBool; safecall;
function Get_Enabled: WordBool; safecall;
function Get_Font: IFontDisp; safecall;
function Get_HelpFile: WideString; safecall;
function Get_HelpKeyword: WideString; safecall;
function Get_HelpType: TxHelpType; safecall;
function Get_KeyPreview: WordBool; safecall;
function Get_PixelsPerInch: Integer; safecall;
function Get_PrintScale: TxPrintScale; safecall;
function Get_Scaled: WordBool; safecall;
function Get_Visible: WordBool; safecall;
function Get_VisibleDockClientCount: Integer; safecall;
procedure _Set_Font(var Value: IFontDisp); safecall;
procedure AboutBox; safecall;
procedure Set_AutoScroll(Value: WordBool); safecall;
procedure Set_AutoSize(Value: WordBool); safecall;
procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
procedure Set_Caption(const Value: WideString); safecall;
procedure Set_Color(Value: OLE_COLOR); safecall;
procedure Set_Cursor(Value: Smallint); safecall;
procedure Set_DoubleBuffered(Value: WordBool); safecall;
procedure Set_DropTarget(Value: WordBool); safecall;
procedure Set_Enabled(Value: WordBool); safecall;
procedure Set_Font(const Value: IFontDisp); safecall;
procedure Set_HelpFile(const Value: WideString); safecall;
procedure Set_HelpKeyword(const Value: WideString); safecall;
procedure Set_HelpType(Value: TxHelpType); safecall;
procedure Set_KeyPreview(Value: WordBool); safecall;
procedure Set_PixelsPerInch(Value: Integer); safecall;
procedure Set_PrintScale(Value: TxPrintScale); safecall;
procedure Set_Scaled(Value: WordBool); safecall;
procedure Set_Visible(Value: WordBool); safecall;
function Get_Detailization: Integer; safecall;
procedure Set_Detailization(Value: Integer); safecall;
function Get_XMaxValue: Integer; safecall;
procedure Set_XMaxValue(Value: Integer); safecall;
function Get_YMaxValue: Integer; safecall;
procedure Set_YMaxValue(Value: Integer); safecall;
function Get_PenWidth: Integer; safecall;
procedure Set_PenWidth(Value: Integer); safecall;
function Get_Text: WideString; safecall;
procedure Set_Text(const Value: WideString); safecall;
public
procedure Initialize; override;
end;
implementation
uses ComObj, ComServ, About;
{$R *.DFM}
{ TGraphX }
procedure TGraphX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
begin
{ Define property pages here. Property pages are defined by calling
DefinePropertyPage with the class id of the page. For example,
DefinePropertyPage(Class_GraphXPage); }
end;
procedure TGraphX.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as IGraphXEvents;
inherited EventSinkChanged(EventSink);
end;
procedure TGraphX.Initialize;
begin
inherited Initialize;
OnActivate := ActivateEvent;
OnClick := ClickEvent;
OnCreate := CreateEvent;
OnDblClick := DblClickEvent;
OnDeactivate := DeactivateEvent;
OnDestroy := DestroyEvent;
OnKeyPress := KeyPressEvent;
OnPaint := PaintEvent;
GraphBldr.DataEditor.AttrsManager.Add(RichEdit);
end;
function TGraphX.Get_Active: WordBool;
begin
Result := Active;
end;
function TGraphX.Get_AlignDisabled: WordBool;
begin
Result := AlignDisabled;
end;
function TGraphX.Get_AutoScroll: WordBool;
begin
Result := AutoScroll;
end;
function TGraphX.Get_AutoSize: WordBool;
begin
Result := AutoSize;
end;
function TGraphX.Get_AxBorderStyle: TxActiveFormBorderStyle;
begin
Result := Ord(AxBorderStyle);
end;
function TGraphX.Get_Caption: WideString;
begin
Result := WideString(Caption);
end;
function TGraphX.Get_Color: OLE_COLOR;
begin
Result := OLE_COLOR(Color);
end;
function TGraphX.Get_Cursor: Smallint;
begin
Result := Smallint(Cursor);
end;
function TGraphX.Get_DoubleBuffered: WordBool;
begin
Result := DoubleBuffered;
end;
function TGraphX.Get_DropTarget: WordBool;
begin
Result := DropTarget;
end;
function TGraphX.Get_Enabled: WordBool;
begin
Result := Enabled;
end;
function TGraphX.Get_Font: IFontDisp;
begin
GetOleFont(Font, Result);
end;
function TGraphX.Get_HelpFile: WideString;
begin
Result := WideString(HelpFile);
end;
function TGraphX.Get_HelpKeyword: WideString;
begin
Result := WideString(HelpKeyword);
end;
function TGraphX.Get_HelpType: TxHelpType;
begin
Result := Ord(HelpType);
end;
function TGraphX.Get_KeyPreview: WordBool;
begin
Result := KeyPreview;
end;
function TGraphX.Get_PixelsPerInch: Integer;
begin
Result := PixelsPerInch;
end;
function TGraphX.Get_PrintScale: TxPrintScale;
begin
Result := Ord(PrintScale);
end;
function TGraphX.Get_Scaled: WordBool;
begin
Result := Scaled;
end;
function TGraphX.Get_Visible: WordBool;
begin
Result := Visible;
end;
function TGraphX.Get_VisibleDockClientCount: Integer;
begin
Result := VisibleDockClientCount;
end;
procedure TGraphX._Set_Font(var Value: IFontDisp);
begin
SetOleFont(Font, Value);
end;
procedure TGraphX.AboutBox;
begin
ShowGraphXAbout;
end;
procedure TGraphX.ActivateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnActivate;
end;
procedure TGraphX.ClickEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnClick;
end;
procedure TGraphX.CreateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnCreate;
end;
procedure TGraphX.DblClickEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDblClick;
end;
procedure TGraphX.DeactivateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDeactivate;
end;
procedure TGraphX.DestroyEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDestroy;
end;
procedure TGraphX.KeyPressEvent(Sender: TObject; var Key: Char);
var
TempKey: Smallint;
begin
TempKey := Smallint(Key);
if FEvents <> nil then FEvents.OnKeyPress(TempKey);
Key := Char(TempKey);
end;
procedure TGraphX.PaintEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnPaint;
end;
procedure TGraphX.Set_AutoScroll(Value: WordBool);
begin
AutoScroll := Value;
end;
procedure TGraphX.Set_AutoSize(Value: WordBool);
begin
AutoSize := Value;
end;
procedure TGraphX.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
begin
AxBorderStyle := TActiveFormBorderStyle(Value);
end;
procedure TGraphX.Set_Caption(const Value: WideString);
begin
Caption := TCaption(Value);
end;
procedure TGraphX.Set_Color(Value: OLE_COLOR);
begin
Color := TColor(Value);
end;
procedure TGraphX.Set_Cursor(Value: Smallint);
begin
Cursor := TCursor(Value);
end;
procedure TGraphX.Set_DoubleBuffered(Value: WordBool);
begin
DoubleBuffered := Value;
end;
procedure TGraphX.Set_DropTarget(Value: WordBool);
begin
DropTarget := Value;
end;
procedure TGraphX.Set_Enabled(Value: WordBool);
begin
Enabled := Value;
end;
procedure TGraphX.Set_Font(const Value: IFontDisp);
begin
SetOleFont(Font, Value);
end;
procedure TGraphX.Set_HelpFile(const Value: WideString);
begin
HelpFile := String(Value);
end;
procedure TGraphX.Set_HelpKeyword(const Value: WideString);
begin
HelpKeyword := String(Value);
end;
procedure TGraphX.Set_HelpType(Value: TxHelpType);
begin
HelpType := THelpType(Value);
end;
procedure TGraphX.Set_KeyPreview(Value: WordBool);
begin
KeyPreview := Value;
end;
procedure TGraphX.Set_PixelsPerInch(Value: Integer);
begin
PixelsPerInch := Value;
end;
procedure TGraphX.Set_PrintScale(Value: TxPrintScale);
begin
PrintScale := TPrintScale(Value);
end;
procedure TGraphX.Set_Scaled(Value: WordBool);
begin
Scaled := Value;
end;
procedure TGraphX.Set_Visible(Value: WordBool);
begin
Visible := Value;
end;
function TGraphX.Get_Detailization: Integer;
begin
Result := GraphBldr.DetailLevel;
end;
procedure TGraphX.Set_Detailization(Value: Integer);
begin
GraphBldr.DetailLevel := Value;
end;
function TGraphX.Get_XMaxValue: Integer;
begin
Result := GraphBldr.XMaxValue;
end;
procedure TGraphX.Set_XMaxValue(Value: Integer);
begin
GraphBldr.XMaxValue := Value;
end;
function TGraphX.Get_YMaxValue: Integer;
begin
Result := GraphBldr.YMaxValue;
end;
procedure TGraphX.Set_YMaxValue(Value: Integer);
begin
GraphBldr.YMaxValue := Value;
end;
function TGraphX.Get_PenWidth: Integer;
begin
Result := GraphBldr.GraphPen.Width;
end;
procedure TGraphX.Set_PenWidth(Value: Integer);
begin
GraphBldr.GraphPen.Width := Value;
end;
function TGraphX.Get_Text: WideString;
begin
Result := GraphBldr.Text;
end;
procedure TGraphX.Set_Text(const Value: WideString);
begin
GraphBldr.Text := Value;
end;
procedure TGraphX.EditCalculateExecute(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
try
with GraphBldr do begin
Text := RichEdit.Text;
try
Calculate;
StatusBar.Panels[2].Text := '';
except
on E: Exception do begin
Clear;
StatusBar.Panels[2].Text := E.Message;
end;
end;
Draw;
end;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TGraphX.EditShowGridExecute(Sender: TObject);
begin
EditShowGrid.Checked := not EditShowGrid.Checked;
with GraphBldr do begin
ShowGrid := EditShowGrid.Checked;
Draw;
end;
end;
procedure TGraphX.EditAxisExecute(Sender: TObject);
begin
EditAxis.Checked := not EditAxis.Checked;
with GraphBldr do begin
ShowAxis := EditAxis.Checked;
Draw;
end;
end;
procedure TGraphX.EditTraceExecute(Sender: TObject);
begin
EditTrace.Checked := not EditTrace.Checked;
with GraphBldr do begin
Tracing := EditTrace.Checked;
if not Tracing then StatusBar.Panels[1].Text := '';
Draw;
end;
end;
procedure TGraphX.EditCopyExecute(Sender: TObject);
begin
ClipBoard.Assign(GraphBldr.Picture);
end;
procedure TGraphX.EditDeleteExecute(Sender: TObject);
begin
with GraphBldr do begin
Clear;
with StatusBar do begin
Panels[1].Text := '';
Panels[2].Text := '';
end;
Draw;
end;
end;
procedure TGraphX.EditGraphColorExecute(Sender: TObject);
begin
ColorDialog.Color := GraphBldr.GraphPen.Color;
if ColorDialog.Execute then with GraphBldr do begin
GraphPen.Color := ColorDialog.Color;
Draw;
end;
end;
procedure TGraphX.GraphBldrMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
StatusBar.Panels[0].Text := Format('%f: %f',
[GraphBldr.XCoord(X), GraphBldr.YCoord(Y)]);
PostMessage(StatusBar.Handle, WM_PAINT, 0, 0);
end;
procedure TGraphX.GraphBldrTrace(Sender: TObject; X, Y: Double);
begin
StatusBar.Panels[2].Text := Format('Tracing: %f: %f', [X, Y]);
end;
procedure TGraphX.edTextKeyPress(Sender: TObject; var Key: Char);
begin
if Key = #13 then begin
Key := #0;
EditCalculateExecute(nil);
end;
end;
procedure TGraphX.RichEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = VK_RETURN then EditCalculate.Execute;
end;
procedure TGraphX.tbDetailLevelChange(Sender: TObject);
begin
GraphBldr.DetailLevel := tbDetailLevel.Position;
end;
procedure TGraphX.edXMaxValueChange(Sender: TObject);
begin
with GraphBldr do begin
XMaxValue := udXMaxValue.Position;
if Trim(Text) <> '' then Calculate;
Draw;
end;
end;
procedure TGraphX.edYMaxValueChange(Sender: TObject);
begin
with GraphBldr do begin
YMaxValue := udYMaxValue.Position;
if Trim(Text) <> '' then Calculate;
Draw;
end;
end;
procedure TGraphX.edPenWidthChange(Sender: TObject);
begin
with GraphBldr do begin
GraphPen.Width := udPenWidth.Position;
Draw;
end;
end;
procedure TGraphX.edHorzSpacingChange(Sender: TObject);
begin
with GraphBldr do begin
HorzSpacing := udHorzSpacing.Position;
Draw;
end;
end;
procedure TGraphX.edVertSpacingChange(Sender: TObject);
begin
with GraphBldr do begin
VertSpacing := udVertSpacing.Position;
Draw;
end;
end;
procedure TGraphX.EditKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #8]) then Key := #0;
end;
procedure TGraphX.HelpAboutExecute(Sender: TObject);
begin
AboutBox;
end;
initialization
TActiveFormFactory.Create(
ComServer,
TActiveFormControl,
TGraphX,
Class_GraphX,
1,
'',
OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
tmApartment);
end.