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

📄 dcoutbar.pas

📁 XP风格的outbar.rar.有DELPHI,C++BULIDER的例子及源码
💻 PAS
📖 第 1 页 / 共 5 页
字号:
{**************************************************}
{                                                  }
{  Dream OutBar                                    }
{  Copyright (c) 1997-2001 Dream Company           }
{  http://www.dream-com.com                        }
{  e-mail: contact@dream-com.com                   }
{                                                  }
{**************************************************}
Unit dcOutBar;

Interface

{$I Outbar.inc}

Uses Windows, Messages, SysUtils, Classes, Controls, Menus, Graphics, Forms,
     StdCtrls, ExtCtrls, CommCtrl, ComCtrls, dcOutConst,
     {$IFDEF D6} RTLConsts, {$ENDIF}
     Consts, ShellApi{$IFNDEF D3},d2Canvas{$ENDIF}, dcOutCommon;

{$IFNDEF D3}
Const
  crHandPoint=1;
{$ENDIF}
{$IFNDEF CPB3}
Const
  NM_CUSTOMDRAW = NM_FIRST - 12 ;
  CDRF_DODEFAULT          = $00000000;
  CDRF_NEWFONT            = $00000002;
  CDRF_SKIPDEFAULT        = $00000004;
  CDRF_NOTIFYPOSTPAINT    = $00000010;
  CDRF_NOTIFYITEMDRAW     = $00000020;
  CDRF_NOTIFYSUBITEMDRAW  = $00000020;
  CDRF_NOTIFYPOSTERASE    = $00000040;
  CDDS_PREPAINT           = $00000001;
  CDDS_POSTPAINT          = $00000002;
  CDDS_PREERASE           = $00000003;
  CDDS_POSTERASE          = $00000004;
  CDDS_ITEM               = $00010000;
  CDDS_ITEMPREPAINT       = CDDS_ITEM or CDDS_PREPAINT;
  CDDS_ITEMPOSTPAINT      = CDDS_ITEM or CDDS_POSTPAINT;
  CDDS_ITEMPREERASE       = CDDS_ITEM or CDDS_PREERASE;
  CDDS_ITEMPOSTERASE      = CDDS_ITEM or CDDS_POSTERASE;
  CDDS_SUBITEM            = $00020000;

  {$IFNDEF D3}
  SPI_GETWHEELSCROLLLINES =$0068;
  WM_MOUSEWHEEL           =$020A;
  {$ENDIF}
Type

  tagNMCUSTOMDRAWINFO = packed record
    hdr: TNMHdr;
    dwDrawStage: DWORD;
    hdc: HDC;
    rc: TRect;
    dwItemSpec: DWORD;  // this is control specific, but it's how to specify an item.  valid only with CDDS_ITEM bit set
    uItemState: UINT;
    lItemlParam: LPARAM;
  end;
  PNMCustomDraw = ^TNMCustomDraw;
  TNMCustomDraw = tagNMCUSTOMDRAWINFO;

  tagNMLVCUSTOMDRAW = packed record
    nmcd: TNMCustomDraw;
    clrText: COLORREF;
    clrTextBk: COLORREF;
    iSubItem: Integer;
  end;
  PNMLVCustomDraw = ^TNMLVCustomDraw;
  TNMLVCustomDraw = tagNMLVCUSTOMDRAW;
  {$ENDIF}

Type
  TBackgroundMode=TBackgroundModeGlobal;
  TCustomDCTranspScrollBar = Class (TGraphicControl)
  Private
    FTimer : TTimer ;
    FAutoSize : Boolean ;
    FMax : Integer ;
    FMin : Integer ;
    FPosition : Integer ;
    FFrequency : Integer ;
    FKind : TScrollBarKind ;
    FOnChange : TNotifyEvent ;
    FShift : Integer ;
    FAddSize : Integer ;
    FButtonsDown : Boolean ;
    FActiveButtonDown : Boolean ;
    FVersion:TDCVersion;

    Procedure InternalSetAutoSize(Value:Boolean);
    Procedure SetMax (Value : Integer) ;
    Procedure SetMin (Value : Integer) ;
    Procedure SetPosition (Value : Integer) ;
    Procedure SetKind (Value : TScrollBarKind) ;
    Procedure SetTransparent (Value : Boolean) ;
    Function  GetTransparent : Boolean ;
    Procedure SetFrequency (Value : Integer) ;
    Procedure SetShift (Value : Integer) ;
    Procedure WMSize (Var Message : TWMSize) ; Message WM_SIZE ;
    Procedure OnTimer (Sender : TObject) ;
    Function  DoPosition : Boolean ;
    Procedure DrawButton (Tip : Boolean ; State : Boolean) ;

  Protected
    Procedure InitAutoSize ;
    Function  GetButtonRect (Tip : Boolean) : TRect ;
    Procedure Paint ; Override ;
    Procedure Loaded ; Override ;
    Procedure MouseDown (Button : TMouseButton ; Shift : TShiftState ; X, Y : Integer) ; Override ;
    Procedure MouseMove (Shift : TShiftState ; X, Y : Integer) ; Override ;
    Procedure MouseUp (Button : TMouseButton ; Shift : TShiftState ; X, Y: Integer) ; Override ;

  Public
    Constructor Create (AOwner : TComponent) ; Override ;
    Destructor Destroy ; Override ;

    Property AutoSize : Boolean Read FAutoSize Write InternalSetAutoSize ;
    Property Max : Integer Read FMax Write SetMax ;
    Property Min : Integer Read FMin Write SetMin ;
    Property Position : Integer Read FPosition Write SetPosition ;
    Property Kind : TScrollBarKind Read FKind Write SetKind ;
    Property Transparent : Boolean Read GetTransparent Write SetTransparent ;
    Property Frequency : Integer Read FFrequency Write SetFrequency ;
    Property Shift : Integer Read FShift Write SetShift ;
    Property OnChange : TNotifyEvent Read FOnChange Write FOnChange ;
  Published  
    Property Version:TDCVersion read FVersion write FVersion stored False;

  End ;

  TDCTranspScrollBar = Class (TCustomDCTranspScrollBar)
  Published
    Property AutoSize ;
    Property Max ;
    Property Min ;
    Property Position ;
    Property Kind ;
    Property Transparent ;
    Property Frequency ;
    Property Shift ;
    Property OnChange ;

    Property Align ;
    Property Color ;
    Property Hint ;
    Property ShowHint ;
    property Visible ;
    property ParentShowHint ;
    property OnClick ;
    property OnDblClick ;
    property OnMouseDown ;
    property OnMouseMove ;
    property OnMouseUp ;
  End ;

  TDCScrollButtonStyle = (dcsbs_ScrollDown, dcsbs_ScrollLeft, dcsbs_ScrollRight,
                          dcsbs_ScrollUp, dcsbs_CaptionClose, dcsbs_CaptionHelp,
                          dcsbs_CaptionMAX, dcsbs_CaptionMIN, dcsbs_CaptionRestore) ;

  TCustomDCScrollButton = Class (TCustomControl)
  Private
    FTimer : TTimer ;
    FAutoSize : Boolean ;
    FButtonStyle : TDCScrollButtonStyle ;
    FDownFlag : Boolean ;
    FFrequency : Integer ;
    FOnSelect : TNotifyEvent ;
    FVersion:TDCVersion;
    Procedure InternalSetAutoSize (Value : Boolean) ;
    Procedure SetButtonStyle (Value : TDCScrollButtonStyle) ;
    Procedure SetFrequency (Value : Integer) ;
    Procedure OnTimer (Sender : TObject) ;
    Procedure WMEraseBkgnd (Var Message : TWmEraseBkgnd) ; Message WM_ERASEBKGND ;

  Protected
    Procedure CMVisibleChanged(Var Message:TMessage);Message CM_VISIBLECHANGED;
    Procedure DoOnSelect;virtual;
    Procedure DrawButton (State : Boolean) ;
    Procedure InitAutoSize ;
    Procedure MouseDown (Button : TMouseButton ; Shift : TShiftState ; X, Y : Integer) ; Override ;
    Procedure MouseMove (Shift : TShiftState ; X, Y : Integer) ; Override ;
    Procedure MouseUp (Button : TMouseButton ; Shift : TShiftState ; X, Y: Integer) ; Override ;
    Procedure Paint ; Override ;
  Public
    Constructor Create (AOwner : TComponent) ; Override ;
    Destructor Destroy ; Override ;

    Property AutoSize : Boolean Read FAutoSize Write InternalSetAutoSize ;
    Property ButtonStyle : TDCScrollButtonStyle Read FButtonStyle Write SetButtonStyle ;
    Property Frequency : Integer Read FFrequency Write SetFrequency ;
    Property OnSelect : TNotifyEvent Read FOnSelect Write FOnSelect ;
  Published
    Property Version:TDCVersion read FVersion write FVersion stored False;
  End ;

  TDCScrollButton = Class (TCustomDCScrollButton)
  Published
    Property AutoSize ;
    Property ButtonStyle ;
    Property Frequency ;
    Property OnSelect ;

    Property Enabled ;
    Property Align ;
    Property Hint ;
    Property ShowHint ;
    property Visible ;
    property ParentShowHint ;
    property OnClick ;
    property OnDblClick ;
    property OnMouseDown ;
    property OnMouseMove ;
    property OnMouseUp ;
  End ;

  TCustomDCListViewEx=Class(TCustomListView)
  Private
    FBackground:TBitmap;
    FBackgroundMode:TBackgroundMode;
    {$IFNDEF D4}
    FCanvas:TCanvas;
    {$ENDIF}
    FGradientBeginColor:TColor;
    FGradientEndColor:TColor;
    Procedure OnBkChange(Sender:TObject);
    Procedure UpdateBackground;
  Protected
    {$IFNDEF D3}
    Procedure DestroyWnd;override;
    {$ENDIF}
    Procedure DrawBackGround(ARect:TRect);virtual;
    Procedure LastPaint;virtual;
    Procedure SetBackground(Value:TBitmap);virtual;
    Procedure SetBackgroundMode(Value:TBackgroundMode);virtual;
    Procedure SetGradientBeginColor(Value:TColor);virtual;
    Procedure SetGradientEndColor(Value:TColor);virtual;
    {$IFNDEF D3}
    Procedure WndProc(var Message:TMessage);override;
    {$ENDIF}
    Procedure WMPaint(Var Message:TMessage);message WM_PAINT;
  Public
    Constructor Create(AOwner:TComponent);override;
    Destructor Destroy;override;

    {$IFDEF D4}
    Property Canvas;
    {$ELSE}
    Property Canvas:TCanvas read FCanvas;
    {$ENDIF}
  Published
    Property Background:TBitmap read FBackground write SetBackground;
    Property BackgroundMode:TBackgroundMode read FBackgroundMode write SetBackgroundMode default bkmNone;
    Property BorderStyle;
    Property Ctl3D;
    Property GradientBeginColor:TColor read FGradientBeginColor write SetGradientBeginColor default clBlue;
    Property GradientEndColor:TColor read FGradientEndColor write SetGradientEndColor default clBlack;
  End;

  TSelectionType=(stStandard,stExpanded);
  TPopupMenuEvent=Procedure(Sender:TObject;Item:TListItem;Var PopupMenu:TPopupMenu) Of Object;

  TDCVertListItem=Class(TListItem)
  Private
    FFileName:String;
    FHotTrackIndex:Integer;
    FOnClick:TNotifyEvent;
    FParams:String;
    FSelectedIndex:Integer;
    Procedure DoClick;
    Procedure SetHotTrackIndex(Value:Integer);
    Procedure SetSelectedIndex(Value:Integer);
  Public
    Destructor Destroy;override;

    Property FileName:String read FFileName write FFileName;
    Property HotTrackIndex:Integer read FHotTrackIndex write SetHotTrackIndex;
    Property OnClick:TNotifyEvent read FOnClick write FOnClick;
    Property Params:String read FParams write FParams;
    Property SelectedIndex:Integer read FSelectedIndex write SetSelectedIndex;
  End;

  TExecuteItemEvent=Procedure(Sender:TObject;Item:TDCVertListItem;Var Processed:Boolean) Of Object;
  TBeforeMouseDownEvent = Procedure(Sender:TObject;X, Y : integer) Of Object;
  TListItemEvent=procedure(Sender:TObject;Item:TListItem) Of Object;
  TScrollButtonsPos=(spTopAndBottom,spTop,spBottom);


  TDCVertListView=class(TCustomDCListViewEx)
  private
    FCheckMouseTimer:TTimer;
    FDisableChangeSelected:Boolean;
    FDestroying:Boolean;
    FDownButton:TDCScrollButton;
    FDragEnabled:Boolean;
    FDragItem:TListItem;
    FDragNewPlace:Integer;
    FDragPlace:Integer;
    FDragX,
    FDragY:Integer;
    FDragPlaceColor:TColor;
    FEditHandle:Integer;
    FEditItem:TListItem;
    FEditProc:Pointer;
    FEditPos:TPoint;
    FFontHeight:Integer;
    FHalfItemSpace:Integer;
    FIsDrag:Boolean;
    FIsCopy:Boolean;
    FIsEscape:Boolean;
    FIsDown:Boolean;//timer autoscroll;
    FIsMouseDown:Boolean;
    FItemSpace:Integer;
    FLastDragResult:Boolean;
    FLockCount:Integer;
    FHighlightColor:TColor;
    FHighlightFontColor:TColor;
    FHighlightSelection:Boolean;
    FHotItem:TListItem;
    FOldEditProc:Integer;
    FOldSelected:TListItem;
    FOrigin:TPoint;
    FOnAfterScroll:TNotifyEvent;
    FOnBeforeScroll:TNotifyEvent;
    FOnBeforeMouseDown:TBeforeMouseDownEvent;
    FOnButtonClick:TListItemEvent;
    FOnExecuteItem:TExecuteItemEvent;
    FOnHotTrackItem:TListItemEvent;
    FOnPopupMenu:TPopupMenuEvent;
    FSaveCursor:Integer;
    FScrollButtonsPos:TScrollButtonsPos;
    FScrollTimer:TTimer;
    FSelectionType:TSelectionType;
    FSetText:Boolean;
    FSourceControl:TWinControl;
    FSourceX:Integer;
    FSourceY:Integer;
    FSunkSelected:Boolean;
    FTargetControl:TWinControl;
    FUpButton:TDCScrollButton;
    FVertAddSpace:Integer;
    FUpdateCount:Integer;
    FUseDblClick:Boolean;
    FVersion:TDCVersion;
    FWheelDelta:Integer;
    FWrapLineCount:Integer;
    Procedure AssignItem(ItemTo,ItemFrom:TListItem);
    Procedure CalcFontHeight;
    Function CreateScrollButton(Style:TDCScrollButtonStyle):TDCScrollButton;
    Procedure DoMouseDown(var Message: TWMMouse; Button: TMouseButton;
                          Shift: TShiftState);
    Procedure DeselectItems;
    Procedure DrawDragPlace(X,Y:Integer;IsClear:Boolean);
    Procedure DrawSelectedFrame(Item:TListItem;Color1,Color2:TColor);
    Procedure DrawTriangle(X,Y:Integer;IsLeft,Up,Down:Boolean;TriangleColor:TColor);
    Procedure EditWndProc(Var Message:TMessage);
    Function GetDragPlace(X,Y:Integer):Integer;
    Function GetFont:TFont;
    Function GetSelectedItem:TListItem;
    Function GetTopItem:TListItem;
    Function GetTriangleTopBottom(Y:Integer):TPoint;
    Function GetViewStyle:TViewStyle;
    Function  GrowItemRect(Item:TListItem):TRect;
    Procedure InitScrollTimer(Source:TWinControl;X,Y:Integer;Button:TCustomDCScrollButton);
    Procedure InvalidateItem(Item:TListItem);
    Function IsScrollDown:Boolean;
    Function IsScrollUp:Boolean;
    Function IsVisible(Item:TListItem;ParitalOk:Boolean):Boolean;
    Procedure NormalDisplayRect(Var Rect:TRect);
    Function NotifyControl(Control:TWinControl;X,Y:Integer):Boolean;
    Procedure NotifyDrag;
    Procedure OnCheckMouse(Sender:TObject);
    Procedure OnDownButton(Sender:TObject);
    Procedure OnScrollTimer(Sender:TObject);
    Procedure OnUpButton(Sender:TObject);
    Procedure ProcessBeginDrag(Shift:TShiftState;X,Y:Integer);
    Procedure ProcessCancelDrag;
    Procedure ProcessDragOver(Shift:TShiftState;X,Y:Integer);
    Procedure ProcessEndDrag(Shift:TShiftState;X,Y:Integer);
    Procedure ProcessTryDrag(Shift:TShiftState;X,Y:Integer);
    Procedure ReAlignItems;

⌨️ 快捷键说明

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