📄 ezcmdline.pas
字号:
Stream.Free;
End;
End;
{-------------------------------------------------------------------------------}
// Implements TEzDrawBoxItem
{-------------------------------------------------------------------------------}
Destructor TEzDrawBoxItem.Destroy;
Begin
SetDrawBox( Nil );
Inherited Destroy;
End;
Procedure TEzDrawBoxItem.Assign( Source: TPersistent );
Begin
If Source Is TEzDrawBoxItem Then
SetDrawBox( TEzDrawBoxItem(Source).FDrawBox )
Else
Inherited Assign( Source );
End;
Function TEzDrawBoxItem.GetDisplayName: String;
Begin
If FDrawBox <> Nil Then
result := FDrawBox.Name
Else
Result := Inherited GetDisplayName;
End;
Procedure TEzDrawBoxItem.SetDrawBox( Value: TEzBaseDrawBox );
var
cmdLine: TEzCmdLine;
Begin
If FDrawBox = Value Then Exit;
{ check if this is pointing to the same TEzBaseGIS component }
with Collection do
If (Value <> Nil) And (Count > 0) And
(TEzDrawBoxItem(Items[0]).FDrawBox <> Nil) And
(TEzDrawBoxItem(Items[0]).FDrawBox.GIS <> Value.GIS) Then
raise Exception.Create( sDrawBoxCollectionNotSame );
cmdLine:= TEzDrawBoxCollection( Collection ).FCmdLine;
{ remove free notification }
{$IFDEF LEVEL5}
If Assigned( Self.FDrawBox ) Then
Self.FDrawBox.RemoveFreeNotification( CmdLine );
{$ENDIF}
{$IFDEF SUBCLASS_DRAWBOX}
// Unhook previous
if Assigned(FNewWndProc) then
begin
if not( (csDestroying in Self.FDrawBox.ComponentState) Or
(csFreeNotification in Self.FDrawBox.ComponentState) ) then
SetWindowLong(Self.FDrawBox.Handle, GWL_WNDPROC, LongInt(FOldWndProc));
{$IFDEF LEVEL6}Classes.{$ENDIF}FreeObjectInstance(FNewWndProc);
FNewWndProc := nil;
end;
If Assigned(FDrawBox) Then
FDrawBox.OnPaint:= FSavedPaint;
// hook the event handlers
FDrawBox:= Value;
If Not (csDesigning In cmdLine.ComponentState) And Assigned(Value) Then
Begin
{ Define free notification}
Value.FreeNotification( CmdLine );
FNewWndProc := {$IFDEF LEVEL6}Classes.{$ENDIF}MakeObjectInstance(SubclassedWinProc);
FOldWndProc := Pointer(SetWindowLong(Value.Handle, GWL_WNDPROC, LongInt(FNewWndProc)));
FSavedPaint:= Value.OnPaint;
Value.OnPaint:= CmdLine.DoPaint;
End;
{$ELSE}
{ define free notification}
If Assigned( Value ) Then
Value.FreeNotification( CmdLine );
{ remove old hooked event handlers }
If Not (csDesigning In cmdLine.ComponentState) And Assigned(Self.FDrawBox) Then
Begin
with Self.FDrawBox do
begin
OnMouseDown2D := FSavedMouseDown;
OnMouseMove2D := FSavedMouseMove;
OnMouseUp2D := FSavedMouseUp;
OnClick := FSavedClick;
OnDblClick := FSavedDblClick;
OnKeyPress := FSavedKeyPress;
OnKeyDown := FSavedKeyDown;
OnKeyUp := FSavedKeyUp;
OnPaint := FSavedPaint;
OnMouseEnter:= FSavedMouseEnter;
OnMouseLeave:= FSavedMouseLeave;
end;
End;
{ hook the event handlers }
If Not (csDesigning In cmdLine.ComponentState) And Assigned(Value) Then
Begin
with Value do
begin
{ save the pointers to event handlers }
FSavedMouseDown := OnMouseDown2D;
FSavedMouseMove := OnMouseMove2D;
FSavedMouseUp := OnMouseUp2D;
FSavedClick := OnClick;
FSavedDblClick := OnDblClick;
FSavedKeyPress := OnKeyPress;
FSavedKeyDown := OnKeyDown;
FSavedKeyUp := OnKeyUp;
FSavedPaint := OnPaint;
FSavedMouseEnter:= OnMouseEnter;
FSavedMouseLeave:= OnMouseLeave;
{ set the event handlers pointing to methods on this class }
OnMouseDown2D := cmdLine.DoMouseDown;
OnMouseMove2D := cmdLine.DoMouseMove;
OnMouseUp2D := cmdLine.DoMouseUp;
//OnClick := cmdLine.DoClick;
OnDblClick := cmdLine.DoDblClick;
OnKeyPress := cmdLine.DoKeyPress;
OnKeyDown := cmdLine.DoKeyDown;
OnKeyUp := cmdLine.DoKeyUp;
OnPaint := cmdLine.DoPaint;
OnMouseEnter:= cmdLine.DoMouseEnter;
OnMouseLeave:= cmdLine.DoMouseLeave;
end;
End;
FDrawBox:= Value;
{$ENDIF}
End;
{$IFDEF SUBCLASS_DRAWBOX}
procedure TEzDrawBoxItem.SubclassedWinProc(var Msg: TMessage);
var
APt: TEzPoint;
Propagate: Boolean;
Ch: Char;
begin
if (csDesigning in FDrawBox.ComponentState) Or (FDrawBox = Nil) then Exit;
Propagate:= True;
with ( Collection as TEzDrawBoxCollection) do
case Msg.Msg of
WM_MOUSEMOVE:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
With TWMMouseMove(Msg) Do
Begin
APt := FDrawBox.Grapher.PointToReal(Point(XPos, YPos));
FCmdLine.DoMouseMove(FDrawBox, KeysToShiftState(Keys), XPos, YPos, APt.X, APt.Y);
End;
end;
{WM_PAINT, CM_INVALIDATE:
Begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
FCmdLine.DoPaint(FDrawBox);
End; }
WM_LBUTTONDOWN:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
with TWMMouse(Msg) do
begin
APt := FDrawBox.Grapher.PointToReal(Point(XPos, YPos));
FCmdLine.DoMouseDown(FDrawBox, mbLeft, KeysToShiftState(Keys), XPos, YPos, APt.X, APt.Y);
end;
end;
WM_RBUTTONDOWN:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
with TWMMouse(Msg) do
begin
APt := FDrawBox.Grapher.PointToReal(Point(XPos, YPos));
FCmdLine.DoMouseDown(FDrawBox, mbRight, KeysToShiftState(Keys), XPos, YPos, APt.X, APt.Y);
end;
end;
WM_LBUTTONUP:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
with TWMMouse(Msg) do
begin
APt := FDrawBox.Grapher.PointToReal(Point(XPos, YPos));
FCmdLine.DoMouseUp(FDrawBox, mbLeft, KeysToShiftState(Keys), XPos, YPos, APt.X, APt.Y);
end;
end;
WM_RBUTTONUP:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
with TWMMouse(Msg) do
begin
APt := FDrawBox.Grapher.PointToReal(Point(XPos, YPos));
FCmdLine.DoMouseUp(FDrawBox, mbRight, KeysToShiftState(Keys), XPos, YPos, APt.X, APt.Y);
end;
end;
WM_LBUTTONDBLCLK:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
FCmdLine.DoDblClick(FDrawBox);
with TWMMouse(Msg) do
begin
APt := FDrawBox.Grapher.PointToReal(Point(XPos, YPos));
FCmdLine.DoMouseDown(FDrawBox, mbLeft, KeysToShiftState(Keys), XPos, YPos, APt.X, APt.Y);
end;
end;
WM_RBUTTONDBLCLK:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
FCmdLine.DoDblClick(FDrawBox);
with TWMMouse(Msg) do
begin
APt := FDrawBox.Grapher.PointToReal(Point(XPos, YPos));
FCmdLine.DoMouseDown(FDrawBox, mbRight, KeysToShiftState(Keys), XPos, YPos, APt.X, APt.Y);
end;
end;
WM_CHAR:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
with TWMKey(Msg) do
begin
Ch := Char(CharCode);
FCmdLine.DoKeyPress( FDrawBox, Ch );
end;
end;
WM_KEYDOWN:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
with TWMKeyDown(Msg) do
FCmdLine.DoKeyDown( FDrawBox, CharCode, KeyDataToShiftState(KeyData) );
end;
WM_KEYUP:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
with TWMKeyUp(Msg) do
FCmdLine.DoKeyUp( FDrawBox, CharCode, KeyDataToShiftState(KeyData) );
end;
CM_MOUSEENTER:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
FCmdLine.DoMouseEnter(FDrawBox);
end;
CM_MOUSELEAVE:
begin
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
Propagate:= False;
FCmdLine.DoMouseLeave(FDrawBox);
end;
end;
// send message to original drawbox
If Propagate then
Msg.Result := CallWindowProc(FOldWndProc, FDrawBox.Handle, Msg.Msg, Msg.WParam, Msg.LParam);
end;
{$ENDIF}
Procedure TEzDrawBoxItem.SetCurrent( Value: Boolean );
Var
OldCurrent: Boolean;
I: Integer;
Begin
OldCurrent:= FCurrent;
// set all to false
For I:= 0 to Collection.Count-1 do
TEzDrawBoxItem(Collection.Items[I]).FCurrent:= False;
If OldCurrent And Not Value Then
Begin
{ if set to false, check that at least one is active }
TEzDrawBoxItem(Collection.Items[0]).FCurrent:= True;
If Index <> 0 Then
FCurrent:= Value;
End Else
FCurrent:= Value;
End;
{-------------------------------------------------------------------------------}
// Implements TEzDrawBoxCollection
{-------------------------------------------------------------------------------}
Constructor TEzDrawBoxCollection.Create( AOwner: TPersistent );
Begin
Inherited Create( AOwner, TEzDrawBoxItem );
FCmdLine:= AOwner As TEzCmdLine;
End;
function TEzDrawBoxCollection.Find(DrawBox: TEzBaseDrawBox): Boolean;
var
I: Integer;
Begin
Result:= False;
For I:= 0 to Count-1 do
If TEzDrawBoxItem( Items[I] ).FDrawBox = DrawBox Then
begin
Result:= True;
Exit;
end;
end;
Function TEzDrawBoxCollection.GetItem( Index: Integer ): TEzDrawBoxItem;
Begin
Result := TEzDrawBoxItem( Inherited GetItem( Index ) );
End;
Procedure TEzDrawBoxCollection.SetItem( Index: Integer; Value: TEzDrawBoxItem );
Begin
Inherited SetItem( Index, Value );
End;
Function TEzDrawBoxCollection.Add: TEzDrawBoxItem;
Begin
Result := TEzDrawBoxItem( Inherited Add );
End;
Function TEzDrawBoxCollection.FindCurrent: TEzDrawBoxItem;
var
I: Integer;
Begin
Result:= Nil;
For I:= 0 to Count-1 do
If TEzDrawBoxItem( Items[I] ).FCurrent Then
Begin
Result:= Items[I];
Break;
End;
If (Result=Nil) And (Count > 0) Then
Begin
TEzDrawBoxItem( Items[0] ).FCurrent:= True;
Result:= Items[0];
End;
End;
Function TEzDrawBoxCollection.FindItem(Sender: TObject): TEzDrawBoxItem;
var
I: Integer;
Begin
Result:= Nil;
For I:= 0 to Count-1 do
If TEzDrawBoxItem( Items[I] ).FDrawBox = Sender Then
Begin
Result:= Items[I];
Break;
End;
If (Result=Nil) And (Count > 0) Then
Begin
Result:= Items[0];
End;
End;
Procedure TEzDrawBoxCollection.SetCurrent( Value: TObject );
Var
I: Integer;
Begin
For I:= 0 to Count-1 do
If TEzDrawBoxItem(Items[I]).FDrawBox = Value Then
Begin
TEzDrawBoxItem(Items[I]).Current:= True;
Exit;
End;
End;
{-------------------------------------------------------------------------------}
// TEzCmdLineEdit
{-------------------------------------------------------------------------------}
Procedure TEzCmdLineEdit.KeyPress( Var Key: Char );
{Var
Item: TEzDrawBoxItem;}
Begin
With (Parent As TEzCmdLine) Do
Begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -