📄 jvpanel.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: JvPanel.pas, released on 2001-02-28.
The Initial Developer of the Original Code is S閎astien Buysse [sbuysse att buypin dott com]
Portions created by S閎astien Buysse are Copyright (C) 2001 S閎astien Buysse.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck att bigfoot dott com].
pongtawat
Peter Thornqvist [peter3 at sourceforge dot net]
Jens Fudickar [jens dott fudickar att oratool dott de]
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:
-----------------------------------------------------------------------------}
// $Id: JvPanel.pas,v 1.60 2005/03/09 14:57:28 marquardt Exp $
unit JvPanel;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, Messages,
SysUtils, Classes, Graphics, Controls, Forms, ExtCtrls,
{$IFDEF VisualCLX}
Qt,
{$ENDIF VisualCLX}
JvThemes, JvComponent, JvExControls, JvJCLUtils;
type
TJvPanelResizeParentEvent = procedure(Sender: TObject; nLeft, nTop, nWidth, nHeight: Integer) of object;
TJvPanelChangedSizeEvent = procedure(Sender: TObject; ChangedSize : Integer) of object;
TJvAutoSizePanel = (asNone, asWidth, asHeight, asBoth);
TJvPanel = class;
TJvArrangeSettings = class(TPersistent)
private
FPanel: TJvPanel;
FAutoArrange: Boolean;
FAutoSize: TJvAutoSizePanel;
FWrapControls: Boolean;
FBorderLeft: Integer;
FBorderTop: Integer;
FDistanceVertical: Integer;
FDistanceHorizontal: Integer;
FShowNotVisibleAtDesignTime: Boolean;
FMaxWidth: Integer;
procedure SetWrapControls(Value: Boolean);
procedure SetAutoArrange(Value: Boolean);
procedure SetAutoSize(Value: TJvAutoSizePanel);
procedure SetBorderLeft(Value: Integer);
procedure SetBorderTop(Value: Integer);
procedure SetDistanceVertical(Value: Integer);
procedure SetDistanceHorizontal(Value: Integer);
procedure SetMaxWidth(Value: Integer);
procedure Rearrange;
public
constructor Create(APanel: TJvPanel);
procedure Assign(Source: TPersistent); override;
published
property WrapControls: Boolean read FWrapControls write SetWrapControls default True;
property BorderLeft: Integer read FBorderLeft write SetBorderLeft default 0;
property BorderTop: Integer read FBorderTop write SetBorderTop default 0;
property DistanceVertical: Integer read FDistanceVertical write SetDistanceVertical default 0;
property DistanceHorizontal: Integer read FDistanceHorizontal write SetDistanceHorizontal default 0;
property ShowNotVisibleAtDesignTime: Boolean read FShowNotVisibleAtDesignTime write FShowNotVisibleAtDesignTime default True;
property AutoSize: TJvAutoSizePanel read FAutoSize write SetAutoSize default asNone;
property AutoArrange: Boolean read FAutoArrange write SetAutoArrange default False;
property MaxWidth: Integer read FMaxWidth write SetMaxWidth default 0;
end;
TJvPanelMoveEvent = procedure(Sender: TObject; X, Y: Integer; var Allow: Boolean) of object;
TJvPanel = class(TJvCustomPanel, IJvDenySubClassing)
private
FTransparent: Boolean;
FFlatBorder: Boolean;
FFlatBorderColor: TColor;
FMultiLine: Boolean;
FOldColor: TColor;
FHotColor: TColor;
FSizeable: Boolean;
FDragging: Boolean;
FLastPos: TPoint;
FArrangeSettings: TJvArrangeSettings;
FEnableArrangeCount: Integer;
FArrangeControlActive: Boolean;
FArrangeWidth: Integer;
FArrangeHeight: Integer;
FOnResizeParent: TJvPanelResizeParentEvent;
FOnChangedWidth: TJvPanelChangedSizeEvent;
FOnChangedHeight: TJvPanelChangedSizeEvent;
FOnPaint: TNotifyEvent;
FMovable: Boolean;
FWasMoved: Boolean;
FOnAfterMove: TNotifyEvent;
FOnBeforeMove: TJvPanelMoveEvent;
{$IFDEF VisualCLX}
FMoving: Boolean;
FGripBmp: TBitmap;
procedure CreateSizeGrip;
function GetFrameWidth: Integer;
function IsInsideGrip(X, Y: Integer): Boolean;
{$ENDIF VisualCLX}
function GetHeight: Integer;
procedure SetHeight(Value: Integer);
function GetWidth: Integer;
procedure SetWidth(Value: Integer);
procedure SetArrangeSettings(Value: TJvArrangeSettings);
procedure SetTransparent(const Value: Boolean);
procedure SetFlatBorder(const Value: Boolean);
procedure SetFlatBorderColor(const Value: TColor);
procedure DrawCaption;
procedure DrawCaptionTo(ACanvas: TCanvas {$IFDEF VisualCLX}; DrawingMask: Boolean = False {$ENDIF});
procedure DrawBorders;
procedure SetMultiLine(const Value: Boolean);
procedure SetHotColor(const Value: TColor);
procedure SetSizeable(const Value: Boolean);
protected
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 MouseEnter(Control: TControl); override;
procedure MouseLeave(Control: TControl); override;
procedure ParentColorChanged; override;
procedure TextChanged; override;
procedure Paint; override;
function DoEraseBackground(Canvas: TCanvas; Param: Integer): Boolean; override;
{$IFDEF VCL}
procedure AdjustSize; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure WMNCHitTest(var Msg: TWMNCHitTest); message WM_NCHITTEST;
procedure WMExitSizeMove(var Msg: TMessage); message WM_EXITSIZEMOVE;
{$ENDIF VCL}
function DoBeforeMove(X, Y: Integer): Boolean; dynamic;
procedure DoAfterMove; dynamic;
{$IFDEF VisualCLX}
procedure DrawMask(ACanvas: TCanvas); override;
{$ENDIF VisualCLX}
procedure Loaded; override;
procedure Resize; override;
procedure AlignControls(AControl: TControl; var Rect: TRect); override;
function GetNextControlByTabOrder(ATabOrder: Integer): TWinControl;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Invalidate; override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
procedure ArrangeControls;
procedure EnableArrange;
procedure DisableArrange;
function ArrangeEnabled: Boolean;
property ArrangeWidth: Integer read FArrangeWidth;
property ArrangeHeight: Integer read FArrangeHeight;
{$IFDEF VCL}
property DockManager;
{$ENDIF VCL}
property Canvas;
published
property Movable: Boolean read FMovable write FMovable default False;
property Sizeable: Boolean read FSizeable write SetSizeable default False;
property HintColor;
property HotColor: TColor read FHotColor write SetHotColor default clBtnFace;
property Transparent: Boolean read FTransparent write SetTransparent default False;
property MultiLine: Boolean read FMultiLine write SetMultiLine;
property FlatBorder: Boolean read FFlatBorder write SetFlatBorder default False;
property FlatBorderColor: TColor read FFlatBorderColor write SetFlatBorderColor default clBtnShadow;
property OnMouseEnter;
property OnMouseLeave;
property OnBeforeMove: TJvPanelMoveEvent read FOnBeforeMove write FOnBeforeMove;
property OnAfterMove: TNotifyEvent Read FOnAfterMove write FOnAfterMove;
property OnParentColorChange;
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
property ArrangeSettings: TJvArrangeSettings read FArrangeSettings write SetArrangeSettings;
property Width: Integer read GetWidth write SetWidth;
property Height: Integer read GetHeight write SetHeight;
property OnResizeParent: TJvPanelResizeParentEvent read FOnResizeParent write FOnResizeParent;
property OnChangedWidth: TJvPanelChangedSizeEvent read FOnChangedWidth write FOnChangedWidth;
property OnChangedHeight: TJvPanelChangedSizeEvent read FOnChangedHeight write FOnChangedHeight;
property Align;
property Alignment;
property Anchors;
{$IFDEF VCL}
property AutoSize;
property BiDiMode;
property UseDockManager default True;
property DockSite;
property DragCursor;
property DragKind;
property FullRepaint;
property Locked;
property ParentBiDiMode;
property OnCanResize;
property OnDockDrop;
property OnDockOver;
property OnEndDock;
property OnGetSiteInfo;
property OnStartDock;
property OnUnDock;
{$ENDIF VCL}
property BevelInner;
property BevelOuter;
property BevelWidth;
property BorderWidth;
property BorderStyle;
property Caption;
property Color;
property Constraints;
property DragMode;
property Enabled;
property Font;
{$IFDEF JVCLThemesEnabled}
property ParentBackground default True;
{$ENDIF JVCLThemesEnabled}
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnStartDrag;
end;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$RCSfile: JvPanel.pas,v $';
Revision: '$Revision: 1.60 $';
Date: '$Date: 2005/03/09 14:57:28 $';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
{$IFDEF HAS_UNIT_TYPES}
Types,
{$ENDIF HAS_UNIT_TYPES}
JvMouseTimer;
const
BkModeTransparent = TRANSPARENT;
function IsThemed: Boolean;
begin
{$IFDEF JVCLThemesEnabled}
Result := ThemeServices.ThemesEnabled;
{$ELSE}
Result := False;
{$ENDIF JVCLThemesEnabled}
end;
//=== { TJvArrangeSettings } =================================================
constructor TJvArrangeSettings.Create(APanel: TJvPanel);
begin
inherited Create;
FPanel := APanel;
FMaxWidth := 0;
FBorderLeft := 0;
FBorderTop := 0;
FDistanceVertical := 0;
FDistanceHorizontal := 0;
WrapControls := True;
ShowNotVisibleAtDesignTime := True;
FAutoSize := asNone;
AutoArrange := False;
end;
procedure TJvArrangeSettings.SetWrapControls(Value: Boolean);
begin
if Value <> FWrapControls then
begin
FWrapControls := Value;
Rearrange;
end;
end;
procedure TJvArrangeSettings.SetAutoArrange(Value: Boolean);
begin
if Value <> FAutoArrange then
begin
FAutoArrange := Value;
if Value then
Rearrange;
end;
end;
procedure TJvArrangeSettings.SetAutoSize(Value: TJvAutoSizePanel);
begin
if Value <> FAutoSize then
begin
FAutoSize := Value;
if AutoSize <> asNone then
Rearrange;
end;
end;
procedure TJvArrangeSettings.SetBorderLeft(Value: Integer);
begin
if Value <> FBorderLeft then
begin
FBorderLeft := Value;
Rearrange;
end;
end;
procedure TJvArrangeSettings.SetBorderTop(Value: Integer);
begin
if Value <> FBorderTop then
begin
FBorderTop := Value;
Rearrange;
end;
end;
procedure TJvArrangeSettings.SetDistanceVertical(Value: Integer);
begin
if Value <> FDistanceVertical then
begin
FDistanceVertical := Value;
Rearrange;
end;
end;
procedure TJvArrangeSettings.SetDistanceHorizontal(Value: Integer);
begin
if Value <> FDistanceHorizontal then
begin
FDistanceHorizontal := Value;
Rearrange;
end;
end;
procedure TJvArrangeSettings.SetMaxWidth(Value: Integer);
begin
if Value <> FMaxWidth then
begin
FMaxWidth := Value;
Rearrange;
end;
end;
procedure TJvArrangeSettings.Assign(Source: TPersistent);
var
A: TJvArrangeSettings;
begin
if Source is TJvArrangeSettings then
begin
A := TJvArrangeSettings(Source);
FAutoArrange := A.AutoArrange;
FAutoSize := A.AutoSize;
FWrapControls := A.WrapControls;
FBorderLeft := A.BorderLeft;
FBorderTop := A.BorderTop;
FDistanceVertical := A.DistanceVertical;
FDistanceHorizontal := A.DistanceHorizontal;
FShowNotVisibleAtDesignTime := A.ShowNotVisibleAtDesignTime;
FMaxWidth := A.MaxWidth;
Rearrange;
end
else
inherited Assign(Source);
end;
procedure TJvArrangeSettings.Rearrange;
begin
if (FPanel <> nil) and AutoArrange and
not (csLoading in FPanel.ComponentState) then
FPanel.ArrangeControls;
end;
//=== { TJvPanel } ===========================================================
constructor TJvPanel.Create(AOwner: TComponent);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -