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

📄 flatview.pas

📁 comerose_flatstyle_v4.42.9.0_d7.rar
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit FlatView;

interface

{$I FlatStyle.inc}
{$R-,T-,H+,X+}

uses Windows, Messages, Classes, Graphics, Controls, ComCtrls, Forms,
     Menus, commCtrl, ExtCtrls, FlatUtils;

type
  { TDefineTreeView }
  TDefineTreeView = class(TVersionTreeView)
  private
    FParentColor: Boolean;
    FFocusedColor: TColor;
    FBorderColor: TColor;
    FFlatColor: TColor;
    FMouseIn: Boolean;
    FInterDrawing: boolean;
    procedure SetColors(Index: Integer; Value: TColor);
    procedure SetParentColor(Value: Boolean);
    function  GetItemsCount: Integer;
  protected
    procedure RedrawBorder(const Clip: HRGN = 0);
    procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
    procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
    procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
    procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
    procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
    procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
    procedure Loaded; override;
    property ColorFocused: TColor index 0 read FFocusedColor write SetColors default clWhite;
    property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
    property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
    property ParentColor: Boolean read FParentColor write SetParentColor default false;
    property ParentFont default True;
    property AutoSize default False;
    property Ctl3D default False;
    property BorderStyle default bsNone;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property ItemsCount: Integer read GetItemsCount;
  end;

  { TFlatTreeView }
  TFlatTreeView = class(TDefineTreeView)
  published
    property ColorFocused;
    property ColorBorder;
    property ColorFlat;
    property ParentColor;
    property Anchors;
    property AutoExpand;
    property BiDiMode;
    property ChangeDelay;
    property Constraints;
    property DragKind;
    property HotTrack;
    property Images;
    property Indent;
    property MultiSelect;
    property MultiSelectStyle;
    property ParentBiDiMode;
    property RightClickSelect;
    property RowSelect;
    property ShowButtons;
    property ShowLines;
    property ShowRoot;
    property SortType;
    property StateImages;
    property ToolTips;
    property Align;
    property DragCursor;
    property DragMode;
    property Enabled;
    property Font;
    property HideSelection;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ReadOnly;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property Visible;

    property OnChange;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDrag;
    property OnAddition;
    property OnAdvancedCustomDraw;
    property OnAdvancedCustomDrawItem;
    property OnChanging;
    property OnCollapsed;
    property OnCollapsing;
    property OnCompare;
    property OnContextPopup;
    property OnCreateNodeClass;
    property OnCustomDraw;
    property OnCustomDrawItem;
    property OnDeletion;
    property OnEdited;
    property OnEditing;
    property OnEndDock;
    property OnExpanding;
    property OnExpanded;
    property OnGetImageIndex;
    property OnGetSelectedIndex;
    property OnStartDock;
    { Items must be published after OnGetImageIndex and OnGetSelectedIndex }
    property Items;
  end;

  TDrawTitleEvent = procedure (Cnvs: TCanvas; Column: TListColumn;
                               Pressed: Boolean; R: TRect) of object;

  TDefineListView = class(TVersionListView)
  private
    FHeaderHandle: HWND;
    FHeaderInstance: Pointer;
    FDefHeaderProc: Pointer;
    FActiveSection: Integer;
    FHeaderDown: Boolean;
    FParentColor: Boolean;
    FFocusedColor: TColor;
    FBorderColor: TColor;
    FFlatColor: TColor;
    FMouseIn: Boolean;
    FOnDrawTitle: TDrawTitleEvent;
    FTitleFaceColor: TColor;
    FTitleCheckColor: TColor;
    FGroundPic: TPicture;
    FGroundHas: Boolean;
    FOnDrawBackground: TLVCustomDrawEvent;
    FGroundStretch: Boolean;
    FAllCheck: Boolean;
    procedure SetColors(Index: Integer; Value: TColor);
    procedure SetParentColor(Value: Boolean);
    function  GetColumnCount: Integer;
    function  GetItemsCount: Integer;
    procedure SetGroundPic(const Value: TPicture);
    procedure SetGroundHas(const Value: Boolean);
    function  GetHeaderHeight: Integer;
    procedure SetGroundStretch(const Value: Boolean);
    procedure SetAllCheck(const Value: Boolean);
    function GetListCount: integer;
    function GetCheckCount: integer;
  protected
    FCheckInBox: Boolean;
    procedure RedrawBorder(const Clip: HRGN = 0);
    procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
    procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
    procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
    procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
    procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
    procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
    procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
    procedure HeaderWndProc(var Message: TMessage);
    procedure DrawTitle(Cnvs: TCanvas; Column: TListColumn; Active, Pressed: Boolean; R: TRect);
    procedure DrawHeader(DC: HDC);
    procedure WndProc(var Message: TMessage); override;
    procedure DrawBackground(Sender: TCustomListView; const ARect: TRect; var DefaultDraw: Boolean);
    procedure Loaded; override;
    function  GetHeaderSectionRect(Index: Integer): TRect;
    property HeaderHeight: Integer read GetHeaderHeight;
    property ColorFocused: TColor index 0 read FFocusedColor write SetColors default clWhite;
    property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
    property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
    property ColorTitleFace: TColor index 3 read FTitleFaceColor write SetColors default DefaultTitleFaceColor;
    property ColorTitleCheck: TColor index 4 read FTitleCheckColor write SetColors default DefaultTitleCheckColor;
    property ParentColor: Boolean read FParentColor write SetParentColor default false;
    property GroundHas: Boolean read FGroundHas write SetGroundHas default false;
    property GroundPic: TPicture read FGroundPic write SetGroundPic;
    property GroundStretch: Boolean read FGroundStretch write SetGroundStretch default false;
    property OnDrawBackground: TLVCustomDrawEvent read FOnDrawBackground write FOnDrawBackground;
    property OnDrawTitle: TDrawTitleEvent read FOnDrawTitle write FOnDrawTitle;
    property ParentFont default True;
    property AutoSize default False;
    property Ctl3D default False;
    property BorderStyle default bsNone;
    property FlatScrollBars default true;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    property AllCheck: Boolean read FAllCheck write SetAllCheck default false;
    property ColCount: Integer read GetColumnCount;
    property Count: integer read GetListCount;
    property CheckCount: integer read GetCheckCount;
    property ItemCount: Integer read GetItemsCount;
  end;

  { TFlatListView }

  TFlatListView = class(TDefineListView)
  published
    property ColorFocused;
    property ColorBorder;
    property ColorFlat;
    property ColorTitleFace;
    property ColorTitleCheck;
    property GroundHas;
    property GroundPic;
    property GroundStretch;
    property Action;
    property Align;
    property AllocBy;
    property Anchors;
    property Checkboxes;
    property Columns;
    property ColumnClick;
    property Enabled;
    property Font;
    property FlatScrollBars;
    property FullDrag;
    property GridLines;
    property HideSelection;
    property HotTrack;
    property HotTrackStyles;
    property HoverTime;
    property IconOptions;
    property Items;
    property LargeImages;
    property MultiSelect;
    property OwnerData;
    property OwnerDraw;
    property ReadOnly default False;
    property RowSelect;
    property ParentBiDiMode;
    property ParentColor default False;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowColumnHeaders;
    property ShowWorkAreas;
    property ShowHint;
    property SmallImages;
    property SortType;
    property StateImages;
    property TabOrder;
    property TabStop default True;
    property ViewStyle;
    property Visible;
    property OnAdvancedCustomDraw;
    property OnAdvancedCustomDrawItem;
    property OnAdvancedCustomDrawSubItem;
    property OnDrawTitle;
    property OnChange;
    property OnChanging;
    property OnClick;
    property OnColumnClick;
    property OnColumnDragged;
    property OnColumnRightClick;
    property OnCompare;
    property OnContextPopup;
    //property OnCustomDraw;
    property OnDrawBackground;
    property OnCustomDrawItem;
    property OnCustomDrawSubItem;
    property OnData;
    property OnDataFind;
    property OnDataHint;
    property OnDataStateChange;
    property OnDblClick;
    property OnDeletion;
    property OnDrawItem;
    property OnEdited;
    property OnEditing;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnGetImageIndex;
    property OnGetSubItemImage;
    property OnDragDrop;
    property OnDragOver;
    property OnInfoTip;
    property OnInsert;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnSelectItem;
    property OnStartDock;
    property OnStartDrag;
  end;

implementation

{ TDefineTreeView }
constructor TDefineTreeView.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  ControlStyle  := ControlStyle - [csOpaque];
  ParentFont     := True;
  AutoSize       := False;
  Ctl3D          := False;
  BorderStyle    := bsNone;
  Width          := 185;
  Height         := 89;
  FFocusedColor  := clWhite;
  FBorderColor   := DefaultBorderColor;
  FFlatColor     := DefaultFlatColor;
  FParentColor   := True;
  FInterDrawing  := False;
end;

destructor TDefineTreeView.Destroy;
begin
  inherited Destroy;
end;

procedure TDefineTreeView.SetParentColor(Value: Boolean);
begin
  if Value <> FParentColor then
  begin
    FParentColor := Value;
    if FParentColor then
    begin
      if Parent <> nil then
        FFlatColor := TForm(Parent).Color;
      RedrawBorder;
    end;
  end;
end;

procedure TDefineTreeView.CMSysColorChange(var Message: TMessage);
begin
  if FParentColor then
  begin
      if Parent <> nil then
         FFlatColor := TForm(Parent).Color;
  end;
  RedrawBorder;
end;

procedure TDefineTreeView.CMParentColorChanged(var Message: TWMNoParams);
begin
  if FParentColor then
  begin
      if Parent <> nil then
         FFlatColor := TForm(Parent).Color;
  end;
  RedrawBorder;
end;

procedure TDefineTreeView.SetColors(Index: Integer; Value: TColor);
begin
  case Index of
    0: FFocusedColor := Value;
    1: FBorderColor := Value;
    2: begin
       FFlatColor := Value;
       FParentColor := False;
       end;
  end;
  RedrawBorder;
end;

procedure TDefineTreeView.CMMouseEnter(var Message: TMessage);
begin
  inherited;
  if (GetActiveWindow <> 0) then
  begin
    FMouseIn := True;
    RedrawBorder;
  end;
end;

procedure TDefineTreeView.CMMouseLeave(var Message: TMessage);
begin
  inherited;
  FMouseIn := False;
  RedrawBorder;
end;

procedure TDefineTreeView.CMEnabledChanged(var Message: TMessage);
begin
  inherited;
  RedrawBorder;
end;

procedure TDefineTreeView.WMSetFocus(var Message: TWMSetFocus);
begin
  inherited;
  if not(csDesigning in ComponentState) then
    RedrawBorder;
end;

procedure TDefineTreeView.WMKillFocus(var Message: TWMKillFocus);
begin
  inherited;
  if not(csDesigning in ComponentState) then
    RedrawBorder;
end;

procedure TDefineTreeView.WMNCCalcSize(var Message: TWMNCCalcSize);
begin
  inherited;
  InflateRect(Message.CalcSize_Params^.rgrc[0], -1, -1);
end;

procedure TDefineTreeView.WMNCPaint(var Message: TMessage);
begin
  inherited;
  RedrawBorder(HRGN(Message.WParam));
end;

procedure TDefineTreeView.RedrawBorder(const Clip: HRGN = 0);
var ViewBorder:TBorderAttrib;
begin
  with ViewBorder do
  begin
    Ctrl := Self;
    BorderColor := ColorBorder;
    if Enabled then
    begin
       FlatColor   := ColorFlat;
       FocusColor  := ColorFocused;
    end
    else
    begin
       FlatColor   := clSilver;
       FocusColor  := clSilver;
    end;
    MouseState  := FMouseIn;
    DesignState := ComponentState;
    FocusState  := Focused;
    HasBars     := False;
  end;
  Color := DrawViewBorder(ViewBorder);
end;

function TDefineTreeView.GetItemsCount: Integer;
begin
  result := inherited Items.Count;
end;

procedure TDefineTreeView.Loaded;
begin
  inherited;
end;

{ TDefineListView }

constructor TDefineListView.Create(AOwner: TComponent);
begin
  FHeaderInstance := MakeObjectInstance(HeaderWndProc);
  FGroundPic      := TPicture.Create;
  inherited Create(AOwner);
  ParentFont         := True;
  AutoSize           := False;
  Ctl3D              := False;
  BorderStyle        := bsNone;
  FlatScrollBars     := True;
  Width              := 185;
  Height             := 89;
  FFocusedColor      := clWhite;
  FBorderColor       := DefaultBorderColor;
  FFlatColor         := DefaultFlatColor;
  FTitleFaceColor    := DefaultTitleFaceColor;
  FTitleCheckColor   := DefaultTitleCheckColor;
  FParentColor       := True;
  FGroundHas         := False;
  FGroundStretch     := False;
  FAllCheck          := False;
  FHeaderHandle      := 0;
  FDefHeaderProc     := nil;
end;

destructor TDefineListView.Destroy;
begin
  if FHeaderHandle <> 0 then
     SetWindowLong(FHeaderHandle, GWL_WNDPROC, LongInt(FDefHeaderProc));
  FreeObjectInstance(FHeaderInstance);
  FHeaderHandle  := 0;
  FDefHeaderProc := nil;
  FGroundPic.Free;
  FGroundPic     := nil;
  OnCustomDraw   := nil;
  inherited Destroy;
end;

procedure TDefineListView.DrawTitle(Cnvs: TCanvas; Column: TListColumn; Active, Pressed: Boolean; R: TRect);
var

⌨️ 快捷键说明

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