⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ezmiscelctrls.pas

📁 很管用的GIS控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:

  { TEzBrushPatternGridBox }

  TEzBrushPatternGridBox = Class( TEzCustomGridBox )
  protected
    Function CreateDropDownList: TEzDropDownList; override;
    Procedure PaintClientArea( Grapher: TEzGrapher; Canvas: TCanvas; Index: Integer;
      Rect: TRect; State: TOwnerDrawState; FillColor: TColor;
      ShowIndex, ShowHexa: Boolean; Clear: Boolean; Edged: Boolean ); override;
  end;

  { TEzBrushPatternListBox }

  TEzBrushPatternListBox = Class( TEzCustomListBox )
  Private
    FForeColor: TColor;
    FBackColor: TColor;
    function GetBackColor: TColor;
    function GetForeColor: TColor;
    procedure SetBackColor(const Value: TColor);
    procedure SetForeColor(const Value: TColor);
  protected
    procedure DrawItem(Index: Integer; Rect: TRect;
      State: TOwnerDrawState); override;
  Public
    constructor Create(AOwner: TComponent); Override;
    procedure Populate; override;
  Published
    Property ForeColor: TColor read GetForeColor write SetForeColor default clBlack;
    Property BackColor: TColor read GetBackColor write SetBackColor default clWhite;
  End;

  { TEzBlocksGridBox }

  TEzBlocksGridBox = Class( TEzCustomGridBox )
  private
    FBlockList: TStrings;
  protected
    Function CreateDropDownList: TEzDropDownList; override;
    Procedure PaintClientArea( Grapher: TEzGrapher; Canvas: TCanvas; Index: Integer;
      Rect: TRect; State: TOwnerDrawState; FillColor: TColor;
      ShowIndex, ShowHexa: Boolean; Clear: Boolean; Edged: Boolean ); override;
  public
    Constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure Populate;

    property BlockList: TStrings read FBlockList;
  end;

  { TEzBlocksListBox }

  TEzBlocksListBox = Class( TEzCustomListBox )
  protected
    procedure DrawItem(Index: Integer; Rect: TRect;
      State: TOwnerDrawState); override;
  Public
    procedure Populate; override;
  End;

  TEzColumnData = (cdLayerName, cdLayerFullPath, cdCurrent, cdVisible, cdSelectable );

  TEzLayerListBox = class;
  TEzLayerBoxColumn = class;

  { TEzLayerColumnTitle }
  TEzLayerColumnTitle = Class(TPersistent)
  Private
    FColumn: TEzLayerBoxColumn;
    FCaption: string;
    FFont: TFont;
    FColor: TColor;
    FAlignment: TAlignment;
    procedure SetAlignment(const Value: TAlignment);
    procedure SetCaption(const Value: string);
    procedure SetColor(const Value: TColor);
    procedure SetFont(const Value: TFont);
  public
    constructor Create(Column: TEzLayerBoxColumn);
    destructor Destroy; override;
  published
    property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
    property Caption: string read FCaption write SetCaption;
    property Color: TColor read FColor write SetColor default clWindow;
    property Font: TFont read FFont write SetFont;
  end;

  { TEzLayerBoxColumn }

  TEzLayerBoxColumn = Class( TCollectionItem )
  Private
    FColumnData: TEzColumnData;
    FWidth: Integer;
    FAlignment: TAlignment;
    FColor: TColor;
    FReadOnly: Boolean;
    FFont: TFont;
    FTitle: TEzLayerColumnTitle;
    FBitmapEnabled: TBitmap;
    FBitmapDisabled: TBitmap;
    procedure SetBitmapEnabled(const Value: TBitmap);
    procedure SetBitmapDisabled(const Value: TBitmap);
    procedure SetColor(const Value: TColor);
    procedure SetFont(const Value: TFont);
    procedure SetReadOnly(const Value: Boolean);
    procedure SetTitle(const Value: TEzLayerColumnTitle);
    procedure SetColumnData(const Value: TEzColumnData);
    procedure RefreshLayout;
    procedure ChangeLayout;
    function GetListBox: TEzLayerListBox;
    procedure SetAlignment(const Value: TAlignment);
    procedure SetWidth(const Value: Integer);
  Protected
    Function GetDisplayName: String; Override;
  Public
    constructor Create(Collection: TCollection); override;
    destructor Destroy; Override;
    Procedure Assign( Source: TPersistent ); Override;
  Published
    Property ColumnData: TEzColumnData read FColumnData write SetColumnData;
    Property Alignment: TAlignment read FAlignment write SetAlignment;
    Property Color: TColor Read FColor Write SetColor;
    Property ReadOnly: Boolean read FReadOnly write SetReadOnly;
    Property Font: TFont read FFont write SetFont;
    Property Title: TEzLayerColumnTitle read FTitle write SetTitle;
    Property BitmapEnabled: TBitmap read FBitmapEnabled write SetBitmapEnabled;
    Property BitmapDisabled: TBitmap read FBitmapDisabled write SetBitmapDisabled;
    Property Width: Integer read FWidth write SetWidth default 48;
  End;

  TEzColumnClass = class of TEzLayerBoxColumn;

  { TEzLayerBoxColumns}
  TEzLayerBoxColumns = Class( TOwnedCollection )
  Private
    FListBox: TEzLayerListBox;
    Function GetColumn( Index: Integer ): TEzLayerBoxColumn;
    Procedure SetColumn( Index: Integer; Value: TEzLayerBoxColumn );
  Protected
    function GetOwner: TPersistent; override;
    procedure Update(Item: TCollectionItem); Override;
  Public
    constructor Create(ListBox: TEzLayerListBox; ColumnClass: TEzColumnClass);
    Function Add: TEzLayerBoxColumn;

    Property Items[Index: Integer]: TEzLayerBoxColumn Read GetColumn Write SetColumn; Default;
  End;

  { TEzLayerListBox }

  TEzLayerListBox = class(TDrawGrid)
  private
    FGIS: TEzBaseGis;
    FColumns: TEzLayerBoxColumns;
    FInLayout: Boolean;
    FCurrentTextColor: TColor;
    FLockedTextColor: TColor;
    FVirtualLayerTextColor: TColor;
    procedure SetGis(Value: TEzBaseGis);
    procedure SetColumns(const Value: TEzLayerBoxColumns);
    procedure SetCurrentTextColor(const Value: TColor);
    procedure SetLockedTextColor(const Value: TColor);
    function GetAbout: TEzAbout;
    procedure SetAbout(const Value: TEzAbout);
  protected
    Procedure Notification( AComponent: TComponent; Operation: TOperation ); Override;
    procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
      AState: TGridDrawState); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
      X, Y: Integer); override;
    procedure Loaded; Override;
  public
    constructor Create(AOwner: TComponent); Override;
    destructor Destroy; Override;
    procedure BeginLayout;
    procedure EndLayout;
    procedure LayoutChanged;
    Function Selected: string;
    function SelectedLayer: TEzBaseLayer;
  published
    Property About: TEzAbout read GetAbout write SetAbout;
    property GIS: TEzBaseGis read FGIS write SetGis;
    property Columns: TEzLayerBoxColumns read FColumns write SetColumns;
    Property CurrentTextColor: TColor read FCurrentTextColor write SetCurrentTextColor default clBlack;
    Property LockedTextColor: TColor read FLockedTextColor write SetLockedTextColor default clRed;
    Property VirtualLayerTextColor: TColor read FVirtualLayerTextColor write FVirtualLayerTextColor;

    property Align;
    property Anchors;
    property BiDiMode;
    property BorderStyle;
    property Color;
    property Constraints;
    property Ctl3D;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property ImeMode;
    property ImeName;
    property ParentBiDiMode;
    property ParentColor;
    property ParentCtl3D;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;
    property OnClick;
{$IFDEF LEVEL5}
    property OnContextPopup;
{$ENDIF}
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
  end;

  Procedure DrawPattern( Canvas: TCanvas; Index: Integer;
    ForeColor, BackColor, FillColor: TColor; Rect: TRect;
    ShowIndex: Boolean ; State: TOwnerDrawState; ShowHexa: Boolean;
    Clear: Boolean = true; Edged: Boolean = False);

  Procedure DrawSymbol( Grapher: TEzGrapher; Canvas: TCanvas; Index: Integer;
    Rect: TRect; State: TOwnerDrawState; FillColor: TColor;
    ShowIndex, ShowHexa: Boolean; Clear: Boolean = true; Edged: Boolean=False );

  Procedure DrawLinetype(Grapher: TEzGrapher; Canvas: TCanvas; Index: Integer;
    Rect: TRect; State: TOwnerDrawState; LineColor, FillColor: TColor;
    ShowIndex: Boolean; const Scale: Double; Repit: Integer;
    ShowHexa: Boolean; Clear: Boolean = true; Edged: Boolean=False );

  procedure DrawBlock(Grapher: TEzGrapher; Canvas: TCanvas;
    Rect: TRect; State: TOwnerDrawState; FillColor: TColor; Block: TEzSymbol;
    Clear: Boolean = true; Edged: Boolean = False );

implementation

uses
  EzConsts, ezsystem, EzLineDraw, EzGraphics, EzBasicCtrls;


function IsChildOf(const AChild, AParent: HWND): Boolean;
var
  lParent: HWND;
begin
 {determines whether one control is the child (or grand^x-child) of another}
  lParent := AChild;
  repeat
    lParent := GetParent(lParent);
  until(lParent = AParent) or(lParent = 0);
  result := lParent = AParent;
end;

Procedure DrawSymbol( Grapher: TEzGrapher; Canvas: TCanvas; Index: Integer;
  Rect: TRect; State: TOwnerDrawState; FillColor: TColor;
  ShowIndex, ShowHexa: Boolean; Clear: Boolean = true; Edged: Boolean=False );
var
  Boundsr:TRect;
  Symbol: TEzSymbol;
  Rgn: HRgn;
  TmpMarginX, TmpMarginY: Double;
  ARect: TRect;
  TmpHeight: Integer;
  sTmp: string;
  aedge: word;
begin
  if ( Index < 0 ) Or (Index > EzSystem.Ez_Symbols.Count-1) then Exit;
  Grapher.Clear;
  with Canvas do
  begin
    Brush.Color:= FillColor;
    ARect:= Rect;

    If Clear And Not ( odSelected in State ) then
      FillRect( Rect );

    If Edged then
    begin
      InflateRect( ARect, -1, -1 );
      aedge:= EDGE_BUMP;
      DrawEdge(Canvas.Handle, ARect, aedge, BF_RECT OR BF_ADJUST);
      InflateRect( ARect, -2, -2 );
    end;

    Boundsr:= ARect;
    if ShowIndex then
    begin
      SetBkMode(Handle, TRANSPARENT);
      if odSelected in State then
        Canvas.Font.Color:= clHighlightText
      else
        Canvas.Font.Color:= clBtnShadow;
      if Ez_Symbols.Count > 255 then
      begin
        If ShowHexa then
          sTmp:= IntToHex( Index, 3 )
        else
          sTmp:= Inttostr( Index );
      end else
      begin
        if ShowHexa then
          sTmp:= IntToHex( Index, 2 )
        else
          sTmp:= Inttostr( Index );
      end;
      TextOut(Boundsr.Left + 1, Boundsr.Top + 1, sTmp);
      TmpHeight:= TextHeight(sTmp) div 2;
      Boundsr.Top:= Boundsr.Top + TmpHeight;
      Boundsr.Left := Boundsr.Left + TmpHeight;
      Boundsr.Right := Boundsr.Right - TmpHeight;
    end;

    Symbol:= Ez_Symbols[Index];
    if (Symbol.Count=0) or EqualRect2D(Symbol.Extension, INVALID_EXTENSION) then Exit;
    with Boundsr do
      Grapher.SetViewport(Left, Top, Right, Bottom);
    with Symbol.Extension do
    begin
      TmpMarginX:= (Emax.X - Emin.X) / 20;
      TmpMarginY:= (Emax.Y - Emin.Y) / 20;
      Grapher.SetWindow(Emin.X - TmpMarginX, Emax.X + TmpMarginX, Emin.Y - TmpMarginY, Emax.Y + TmpMarginY);
    end;
    with Canvas do
    begin
      with Boundsr do
        Rgn:= CreateRectRgn(Left, Top, Right, Bottom);
      SelectClipRgn(Handle, Rgn);
      try
        Symbol.Draw(Grapher, Canvas,
          Grapher.CurrentParams.VisualWindow, IDENTITY_MATRIX2D, dmNormal);
      finally
        SelectClipRgn(Handle, 0);
        DeleteObject(Rgn);
      end;
    end;
  end;
End;

Procedure DrawLinetype(Grapher: TEzGrapher; Canvas: TCanvas; Index: Integer;
  Rect: TRect; State: TOwnerDrawState; LineColor, FillColor: TColor;
  ShowIndex: Boolean; const Scale: Double; Repit: Integer;
  ShowHexa: Boolean; Clear: Boolean = true; Edged: Boolean=False );
var
  PenWidth:integer;
  Boundsr:TRect;
  Symbol: TEzSymbol;
  Rgn: HRgn;
  temp,tempx,tempy,tmpMarginX, tmpMarginY: Double;
  linetype: Integer;
  e:TEzRect;
  dist,FourthPI:Double;
  V:TEzVector;
  PenStyle: TEzPenStyle;
  PtArr: Array[0..5] of TPoint;
  I: Integer;
  Parts: Array[0..0] of Integer;
  S: string;
  aedge: Word;
  ALineColor: TColor;
begin
  if Index < 0 then Exit;
  Grapher.Clear;
  with Canvas do
  begin
     Boundsr:= Rect;

     Brush.Color:= FillColor;
     If Clear And Not ( odSelected in State ) then FillRect( Boundsr );

     If Edged then
     begin
       InflateRect( Boundsr, -1, -1 );
       aedge:= EDGE_BUMP;
       DrawEdge(Canvas.Handle, Boundsr, aedge, BF_RECT OR BF_ADJUST);
       InflateRect( Boundsr, -2, -2 );
     end;

     if ShowIndex then
     begin
       SetBkMode(Canvas.Handle, TRANSPARENT);
       if odSelected in State then
         Canvas.Font.Color:= clHighlightText
       else
         Canvas.Font.Color:= clBtnShadow;
       If ShowHexa then
        S:= IntToHex( Index, 2 )
       else
        S:= IntToStr( Index );
       Canvas.TextOut(Boundsr.Left + 1, Boundsr.Top + 1, S);
     end;
     if Index = 0 then
     begin
       //DrawEdge(Handle,Boundsr,EDGE_SUNKEN, BF_RECT {or BF_MIDDLE or BF_FLAT});
       S:= 'None';
       DrawText(Canvas.Handle, PChar(S), Length(s), Boundsr,
         DT_CENTER or DT_SINGLELINE or DT_VCENTER);
       Exit;
     end;
     Pen.Style := psSolid;
     if odSelected in State then
       ALineColor:= clHighlightText
     else
       ALineColor:= LineColor;
     Pen.Color := ALineColor;
     PenWidth := Trunc(Scale);
     linetype:= Index-2;

     { DRAW THE LINE TYPE }
     Symbol:= Nil;
     if linetype>=MAX_LINETYPES then
     begin
       Symbol:= Ez_Linetypes[linetype-MAX_LINETYPES];
       if EqualRect2D(Symbol.Extension, INVALID_EXTENSION) then Exit;
     end;
     with Boundsr do
       Grapher.SetViewport(Left, Top, Right, Bottom);
     dist:=0;
     if linetype>=MAX_LINETYPES then
     begin
       e:= Symbol.Extension;
       dist:=(e.Emax.X - e.Emin.X);
     end;
     V:=TEzVector.Create(2);
     try
       V.Add(Point2d(0, 0));

       temp:= Dist2d(Point2d(0,100),Point2d(125,0)) / 3;
       FourthPI:=System.PI/4;
       tempx:= Cos(FourthPI)*temp;
       tempy:= Sin(FourthPI)*temp;
       V.Add(Point2d(tempx, 100-tempy));

       tempx:= Cos(FourthPI)*temp*2;
       tempy:= Sin(FourthPI)*temp*2;
       V.Add(Point2d(tempx, 100-tempy));

       V.Add(Point2d(125, 100));
       e:=V.Extension;
       with e do
       begin
         TmpMarginX:= (Emax.X - Emin.X) / 20;
         TmpMarginY:= (Emax.Y - Emin.Y) / 20;
         Grapher.SetWindow( Emin.X - TmpMarginX,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -