📄 jvcomctrls.pas
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvComCtrls.PAS, released Oct 10, 1999.
The Initial Developer of the Original Code is Petr Vones (petr dott v att mujmail dott cz)
Portions created by Petr Vones are Copyright (C) 1999 Petr Vones.
Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
All Rights Reserved.
Contributor(s):
Peter Below [100113 dott 1101 att compuserve dott com] - alternate TJvPageControl.OwnerDraw routine
Peter Th鰎nqvist [peter3 at sourceforge dot net] added TJvIPAddress.AddressValues and TJvPageControl.ReduceMemoryUse
Alfi [alioscia_alessi att onde dott net] alternate TJvPageControl.OwnerDraw routine
Rudy Velthuis - ShowRange in TJvTrackBar
Andreas Hausladen - TJvIPAddress designtime bug, components changed to JvExVCL
Kai Gossens - TJvIPAddress: changing Color, drawing bug on XP (fat frame on edits removed)
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
TJvTreeView:
When dragging an item and MultiSelect is True droptarget node is not painted
correctly.
-----------------------------------------------------------------------------}
// $Id: JvComCtrls.pas,v 1.84 2005/03/09 07:24:56 marquardt Exp $
unit JvComCtrls;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, Messages, Contnrs, Graphics, Controls, Forms,
Classes, // (ahuser) "Classes" after "Forms" (D5 warning)
Menus, ComCtrls, ImgList, Buttons,
{$IFDEF VCL}
CommCtrl,
{$ENDIF VCL}
{$IFDEF VisualCLX}
Qt, QExtCtrls,
{$ENDIF VisualCLX}
JvJVCLUtils, JvComponent, JvExControls, JvExComCtrls;
const
JvDefPageControlBorder = 4;
{$IFDEF VCL}
TVM_SETLINECOLOR = TV_FIRST + 40;
{$EXTERNALSYM TVM_SETLINECOLOR}
TVM_GETLINECOLOR = TV_FIRST + 41;
{$EXTERNALSYM TVM_GETLINECOLOR}
{$ENDIF VCL}
JvDefaultInactiveColorFrom = TColor($D7D7D7);
JvDefaultInactiveColorTo= TColor($ADADAD);
type
{$IFDEF VCL}
TJvIPAddress = class;
TJvIPAddressMinMax = record
Min: Byte;
Max: Byte;
end;
TJvIPEditControlHelper = class(TObject)
private
FHandle: THandle;
FInstance: Pointer;
FIPAddress: TJvIPAddress;
FOrgWndProc: Pointer;
procedure SetHandle(const Value: THandle);
protected
procedure WndProc(var Msg: TMessage); virtual;
property Handle: THandle read FHandle write SetHandle;
public
constructor Create(AIPAddress: TJvIPAddress);
destructor Destroy; override;
procedure SetFocus;
function Focused: Boolean;
procedure DefaultHandler(var Msg); override;
end;
TJvIPAddressRange = class(TPersistent)
private
FControl: TWinControl;
FRange: array [0..3] of TJvIPAddressMinMax;
function GetMaxRange(Index: Integer): Byte;
function GetMinRange(Index: Integer): Byte;
procedure SetMaxRange(const Index: Integer; const Value: Byte);
procedure SetMinRange(const Index: Integer; const Value: Byte);
protected
procedure AssignTo(Dest: TPersistent); override;
procedure Change(Index: Integer);
public
constructor Create(Control: TWinControl);
published
property Field1Min: Byte index 0 read GetMinRange write SetMinRange default 0;
property Field1Max: Byte index 0 read GetMaxRange write SetMaxRange default 255;
property Field2Min: Byte index 1 read GetMinRange write SetMinRange default 0;
property Field2Max: Byte index 1 read GetMaxRange write SetMaxRange default 255;
property Field3Min: Byte index 2 read GetMinRange write SetMinRange default 0;
property Field3Max: Byte index 2 read GetMaxRange write SetMaxRange default 255;
property Field4Min: Byte index 3 read GetMinRange write SetMinRange default 0;
property Field4Max: Byte index 3 read GetMaxRange write SetMaxRange default 255;
end;
TJvIpAddrFieldChangeEvent = procedure(Sender: TJvIPAddress; FieldIndex: Integer;
FieldRange: TJvIPAddressMinMax; var Value: Integer) of object;
TJvIPAddressChanging = procedure(Sender: TObject; Index: Integer; Value: Byte; var AllowChange: Boolean) of object;
TJvIPAddressValues = class(TPersistent)
private
FValues: array [0..3] of Byte;
FOnChange: TNotifyEvent;
FOnChanging: TJvIPAddressChanging;
function GetValue: Cardinal;
procedure SetValue(const AValue: Cardinal);
procedure SetValues(Index: Integer; Value: Byte);
function GetValues(Index: Integer): Byte;
protected
procedure Change; virtual;
function Changing(Index: Integer; Value: Byte): Boolean; virtual;
public
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnChanging: TJvIPAddressChanging read FOnChanging write FOnChanging;
published
property Address: Cardinal read GetValue write SetValue;
property Value1: Byte index 0 read GetValues write SetValues;
property Value2: Byte index 1 read GetValues write SetValues;
property Value3: Byte index 2 read GetValues write SetValues;
property Value4: Byte index 3 read GetValues write SetValues;
end;
TJvIPAddress = class(TJvCustomControl)
private
FEditControls: array [0..3] of TJvIPEditControlHelper;
FEditControlCount: Integer;
FAddress: LongWord;
FChanging: Boolean;
FRange: TJvIPAddressRange;
FAddressValues: TJvIPAddressValues;
FSaveBlank: Boolean;
FTabThroughFields: Boolean;
FLocalFont: HFONT;
FOnFieldChange: TJvIpAddrFieldChangeEvent;
FOnChange: TNotifyEvent;
FFocusFromField: Boolean;
procedure ClearEditControls;
procedure DestroyLocalFont;
procedure SetAddress(const Value: LongWord);
procedure SetAddressValues(const Value: TJvIPAddressValues);
procedure CNCommand(var Msg: TWMCommand); message CN_COMMAND;
procedure CNNotify(var Msg: TWMNotify); message CN_NOTIFY;
procedure WMDestroy(var Msg: TWMNCDestroy); message WM_DESTROY;
procedure WMParentNotify(var Msg: TWMParentNotify); message WM_PARENTNOTIFY;
procedure WMSetFont(var Msg: TWMSetFont); message WM_SETFONT;
procedure WMSetFocus(var Msg: TWMSetFocus); message WM_SETFOCUS;
procedure WMSetText(var Msg: TWMSetText); message WM_SETTEXT;
procedure WMCtlColorEdit(var Msg: TWMCtlColorEdit); message WM_CTLCOLOREDIT;
procedure WMKeyDown(var Msg: TWMKeyDown); message WM_KEYDOWN;
procedure WMKeyUp(var Msg: TWMKeyUp); message WM_KEYUP;
//procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
procedure SelectTabControl(Previous: Boolean);
protected
procedure GetDlgCode(var Code: TDlgCodes); override;
procedure EnabledChanged; override;
procedure ColorChanged; override;
procedure FontChanged; override;
function DoEraseBackground(Canvas: TCanvas; Param: Integer): Boolean; override;
procedure AdjustHeight;
procedure AdjustSize; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure DoChange; dynamic;
procedure Paint; override;
procedure DoAddressChange(Sender: TObject); virtual;
procedure DoAddressChanging(Sender: TObject; Index: Integer;
Value: Byte; var AllowChange: Boolean); virtual;
procedure DoFieldChange(FieldIndex: Integer; var FieldValue: Integer); dynamic;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ClearAddress;
function IsBlank: Boolean;
published
property Address: LongWord read FAddress write SetAddress default 0;
property AddressValues: TJvIPAddressValues read FAddressValues write SetAddressValues;
property Anchors;
property Color;
property Constraints;
{$IFDEF VCL}
property DragCursor;
property DragKind;
property OnStartDock;
property OnEndDock;
{$ENDIF VCL}
property DragMode;
property Enabled;
property Font;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property Range: TJvIPAddressRange read FRange write FRange;
property ShowHint;
property TabOrder;
property TabStop default True;
property TabThroughFields: Boolean read FTabThroughFields write FTabThroughFields default True;
property Text;
property Visible;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnFieldChange: TJvIpAddrFieldChangeEvent read FOnFieldChange write FOnFieldChange;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnStartDrag;
end;
{$ENDIF VCL}
// TJvHintSource is a hint enumeration type to describe how to display hints for
// controls that have hint properties both for the main control as well as
// for it's subitems (like a PageControl)
// TODO: (p3) this should really be moved to JvTypes or something...
TJvHintSource =
(
hsDefault, // use default hint behaviour (i.e as regular control)
hsForceMain, // use the main hint even if subitems have hints
hsForceChildren, // always use subitems hints even if empty
hsPreferMain, // use main control hint unless empty then use subitems hints
hsPreferChildren // use subitems hints unless empty then use main control hint
);
// painters that can be used to draw the tabs of a TPageControl or TTabControl
TJvTabControlPainter = class(TJvComponent)
private
FClients: TList;
protected
// descendants must override and implement this method
procedure DrawTab(AControl: TCustomTabControl; Canvas: TCanvas;
Images: TCustomImageList; ImageIndex: Integer; const Caption: string;
const Rect: TRect; Active, Enabled: Boolean); virtual; abstract;
procedure Change; virtual;
procedure RegisterChange(AControl: TCustomTabControl);
procedure UnRegisterChange(AControl: TCustomTabControl);
procedure Notification(AComponent: TComponent; Operation: TOperation);
override;
public
destructor Destroy; override;
end;
TJvTabDefaultPainter = class(TJvTabControlPainter)
private
FActiveFont: TFont;
FDisabledFont: TFont;
FInactiveFont: TFont;
FInactiveColorTo: TColor;
FActiveColorTo: TColor;
FDisabledColorTo: TColor;
FInactiveColorFrom: TColor;
FActiveColorFrom: TColor;
FDisabledColorFrom: TColor;
FActiveGradientDirection: TFillDirection;
FInactiveGradientDirection: TFillDirection;
FDisabledGradientDirection: TFillDirection;
FGlyphLayout: TButtonLayout;
FDivider: Boolean;
FShowFocus: Boolean;
procedure SetActiveFont(const Value: TFont);
procedure SetDisabledFont(const Value: TFont);
procedure SetInactiveFont(const Value: TFont);
procedure SetActiveColorFrom(const Value: TColor);
procedure SetActiveColorTo(const Value: TColor);
procedure SetActiveGradientDirection(const Value: TFillDirection);
procedure SetDisabledColorFrom(const Value: TColor);
procedure SetDisabledColorTo(const Value: TColor);
procedure SetDisabledGradientDirection(const Value: TFillDirection);
procedure SetInactiveColorFrom(const Value: TColor);
procedure SetInactiveColorTo(const Value: TColor);
procedure SetInactiveGradientDirection(const Value: TFillDirection);
function IsActiveFontStored: Boolean;
function IsInactiveFontStored: Boolean;
function IsDisabledFontStored: Boolean;
procedure SetGlyphLayout(const Value: TButtonLayout);
procedure SetDivider(const Value: Boolean);
procedure SetShowFocus(const Value: Boolean);
protected
procedure DrawTab(AControl: TCustomTabControl; Canvas: TCanvas;
Images: TCustomImageList; ImageIndex: Integer; const Caption: string;
const Rect: TRect; Active, Enabled: Boolean); override;
procedure DoFontChange(Sender: TObject);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ActiveFont: TFont read FActiveFont write SetActiveFont stored IsActiveFontStored;
property ActiveColorFrom: TColor read FActiveColorFrom write SetActiveColorFrom default clWhite;
property ActiveColorTo: TColor read FActiveColorTo write SetActiveColorTo default clBtnFace;
property ActiveGradientDirection: TFillDirection read FActiveGradientDirection write SetActiveGradientDirection default fdTopToBottom;
property InactiveFont: TFont read FInactiveFont write SetInactiveFont stored IsInactiveFontStored;
property InactiveColorFrom: TColor read FInactiveColorFrom write SetInactiveColorFrom default JvDefaultInactiveColorFrom;
property InactiveColorTo: TColor read FInactiveColorTo write SetInactiveColorTo default JvDefaultInactiveColorTo;
property InactiveGradientDirection: TFillDirection read FInactiveGradientDirection write SetInactiveGradientDirection default fdTopToBottom;
property DisabledFont: TFont read FDisabledFont write SetDisabledFont stored IsDisabledFontStored;
property DisabledColorFrom: TColor read FDisabledColorFrom write SetDisabledColorFrom default clBtnFace;
property DisabledColorTo: TColor read FDisabledColorTo write SetDisabledColorTo default clBtnFace;
property DisabledGradientDirection: TFillDirection read FDisabledGradientDirection write SetDisabledGradientDirection default fdTopToBottom;
property GlyphLayout: TButtonLayout read FGlyphLayout write SetGlyphLayout default blGlyphLeft;
property Divider: Boolean read FDivider write SetDivider default False;
property ShowFocus: Boolean read FShowFocus write SetShowFocus default False;
end;
TJvTabControl = class(TJvExTabControl)
private
FTabPainter: TJvTabControlPainter;
FRightClickSelect: Boolean;
{$IFDEF VCL}
procedure CMDialogKey(var Msg: TWMKey); message CM_DIALOGKEY;
procedure WMRButtonDown(var Msg: TWMRButtonDown); message WM_RBUTTONDOWN;
{$ENDIF VCL}
procedure SetTabPainter(const Value: TJvTabControlPainter); // not WantKeys
protected
{$IFDEF VisualCLX}
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
function DrawTab(TabIndex: Integer; const Rect: TRect; Active: Boolean): Boolean; override;
{$ENDIF VisualCLX}
{$IFDEF VCL}
procedure DrawTab(TabIndex: Integer; const Rect: TRect; Active: Boolean); override;
{$ENDIF VCL}
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
public
constructor Create(AOwner: TComponent); override;
published
property RightClickSelect: Boolean read FRightClickSelect write FRightClickSelect default False;
property TabPainter: TJvTabControlPainter read FTabPainter write SetTabPainter;
property HintColor;
property OnMouseEnter;
property OnMouseLeave;
property OnParentColorChange;
property Color;
end;
TJvPageControl = class(TJvExPageControl)
private
FClientBorderWidth: TBorderWidth;
FHideAllTabs: Boolean;
FHandleGlobalTab: Boolean;
FHintSource: TJvHintSource;
FReduceMemoryUse: Boolean;
FTabPainter: TJvTabControlPainter;
FRightClickSelect: Boolean;
procedure SetClientBorderWidth(const Value: TBorderWidth);
{$IFDEF VCL}
procedure TCMAdjustRect(var Msg: TMessage); message TCM_ADJUSTRECT;
{$ENDIF VCL}
procedure SetHideAllTabs(const Value: Boolean);
function FormKeyPreview: Boolean;
procedure SetReduceMemoryUse(const Value: Boolean);
procedure SetTabPainter(const Value: TJvTabControlPainter);
protected
function HintShow(var HintInfo: THintInfo): Boolean; override;
function WantKey(Key: Integer; Shift: TShiftState;
const KeyText: WideString): Boolean; override;
procedure Loaded; override;
function CanChange: Boolean; override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
{$IFDEF VisualCLX}
function DrawTab(TabIndex: Integer; const Rect: TRect; Active: Boolean): Boolean; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
{$ENDIF VisualCLX}
{$IFDEF VCL}
procedure DrawTab(TabIndex: Integer; const Rect: TRect; Active: Boolean); override;
procedure WMLButtonDown(var Msg: TWMLButtonDown); message WM_LBUTTONDOWN;
procedure WMRButtonDown(var Msg: TWMRButtonDown); message WM_RBUTTONDOWN;
{$ENDIF VCL}
public
constructor Create(AOwner: TComponent); override;
procedure UpdateTabImages;
published
property TabPainter: TJvTabControlPainter read FTabPainter write SetTabPainter;
property HintSource: TJvHintSource read FHintSource write FHintSource default hsDefault;
property HandleGlobalTab: Boolean read FHandleGlobalTab write FHandleGlobalTab default False;
property ClientBorderWidth: TBorderWidth read FClientBorderWidth write SetClientBorderWidth default JvDefPageControlBorder;
property ParentColor;
property RightClickSelect: Boolean read FRightClickSelect write FRightClickSelect default False;
property ReduceMemoryUse: Boolean read FReduceMemoryUse write SetReduceMemoryUse default False;
property HideAllTabs: Boolean read FHideAllTabs write SetHideAllTabs default False;
property HintColor;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -