LCL: Implementation of TControlBar. Issue #26478, patch from Vojtech Cihak

git-svn-id: trunk@45860 -
This commit is contained in:
juha 2014-07-13 22:48:27 +00:00
parent 8d79ffd221
commit 7ecca1cded
2 changed files with 1020 additions and 105 deletions

View File

@ -28,7 +28,7 @@ interface
uses uses
SysUtils, Types, Classes, LCLStrConsts, LCLType, LCLProc, LResources, Controls, SysUtils, Types, Classes, LCLStrConsts, LCLType, LCLProc, LResources, Controls,
Forms, StdCtrls, lMessages, GraphType, Graphics, LCLIntf, CustomTimer, Themes, Forms, StdCtrls, lMessages, GraphType, Graphics, LCLIntf, CustomTimer, Themes,
LCLClasses, Menus, PopupNotifier, ImgList, contnrs; LCLClasses, Menus, PopupNotifier, ImgList, contnrs, FGL;
type type
@ -1138,24 +1138,85 @@ type
{ TControlBar } { TControlBar }
TBandPaintOption = (bpoGrabber, bpoFrame); TBandDrawingStyle = (dsNormal, dsGradient);
TBandPaintOption = (bpoGrabber, bpoFrame, bpoGradient, bpoRoundRect);
TBandPaintOptions = set of TBandPaintOption; TBandPaintOptions = set of TBandPaintOption;
TBandDragEvent = procedure (Sender: TObject; Control: TControl; var Drag: Boolean) of object; TBandDragEvent = procedure (Sender: TObject; Control: TControl; var Drag: Boolean) of object;
TBandInfoEvent = procedure (Sender: TObject; Control: TControl; TBandInfoEvent = procedure (Sender: TObject; Control: TControl;
var Insets: TRect; var PreferredSize, RowCount: Integer) of object; var Insets: TRect; var PreferredSize, RowCount: Integer) of object;
TBandMoveEvent = procedure (Sender: TObject; Control: TControl; var ARect: TRect) of object; TBandMoveEvent = procedure (Sender: TObject; Control: TControl; var ARect: TRect) of object;
TBandPaintEvent = procedure (Sender: TObject; Control: TControl; Canvas: TCanvas; TBandPaintEvent = procedure (Sender: TObject; Control: TControl; Canvas: TCanvas;
var ARect: TRect; var Options: TBandPaintOptions) of object; var ARect: TRect; var Options: TBandPaintOptions) of object;
// TCheckDoAgainEvent = function (cbi: TControlBarInfo; const aPos: TPoint; aWidth: Integer): Boolean; of object;
TRowSize = 1..MaxInt; TRowSize = 1..MaxInt;
TBandMove = (bmNone, bmReady, bmMoving);
TCursorDesign = (cdDefault, cdGrabber, cdRestricted);
{ BiDi is Left to Right:
+----------------------------------------------------------------------------+
| cBandBorder + |cGrabWidth| + cBandBorder + [ Control.Width ] + cBandBorder |
+----------------------------------------------------------------------------+
| cFullGrabber | }
{ TCtrlBand }
TCtrlBand = class
private
FControl: TControl;
FControlHeight: Integer;
FControlLeft: Integer;
FControlTop: Integer;
FControlVisible: Boolean;
FControlWidth: Integer;
FHeight: Integer;
FInitLeft: Integer;
FInitTop: Integer;
FLeft: Integer;
FTop: Integer;
FVisible: Boolean;
FWidth: Integer;
function GetBandRect: TRect;
function GetBottom: Integer;
function GetRight: Integer;
procedure SetBandRect(AValue: TRect);
procedure SetRight(AValue: Integer);
public
property BandRect: TRect read GetBandRect write SetBandRect;
property Bottom: Integer read GetBottom;
property Control: TControl read FControl write FControl;
property ControlHeight: Integer read FControlHeight write FControlHeight;
property ControlLeft: Integer read FControlLeft write FControlLeft;
property ControlTop: Integer read FControlTop write FControlTop;
property ControlWidth: Integer read FControlWidth write FControlWidth;
property ControlVisible: Boolean read FControlVisible write FControlVisible;
property Height: Integer read FHeight write FHeight;
property InitLeft: Integer read FInitLeft write FInitLeft;
property InitTop: Integer read FInitTop write FInitTop;
property Left: Integer read FLeft write FLeft;
property Right: Integer read GetRight write SetRight;
property Top: Integer read FTop write FTop;
property Visible: Boolean read FVisible write FVisible;
property Width: Integer read FWidth write FWidth;
end;
{ TCtrlBands }
TCtrlBands = class (specialize TFPGObjectList<TCtrlBand>)
public
function GetIndex(AControl: TControl): Integer;
end;
{ TCustomControlBar } { TCustomControlBar }
TCustomControlBar = class(TCustomPanel) TCustomControlBar = class(TCustomPanel)
private private
FAutoDrag: Boolean; FAutoDrag: Boolean;
FAutoDock: Boolean; FAutoDock: Boolean;
FDragControl: TControl; FDrawingStyle: TBandDrawingStyle;
FGradientDirection: TGradientDirection;
FGradientEndColor: TColor;
FGradientStartColor: TColor;
FPicture: TPicture; FPicture: TPicture;
FRowSize: TRowSize; FRowSize: TRowSize;
FRowSnap: Boolean; FRowSnap: Boolean;
@ -1165,39 +1226,91 @@ type
FOnBandPaint: TBandPaintEvent; FOnBandPaint: TBandPaintEvent;
FOnCanResize: TCanResizeEvent; FOnCanResize: TCanResizeEvent;
FOnPaint: TNotifyEvent; FOnPaint: TNotifyEvent;
procedure SetDrawingStyle(AValue: TBandDrawingStyle);
procedure SetGradientDirection(AValue: TGradientDirection);
procedure SetGradientEndColor(AValue: TColor);
procedure SetGradientStartColor(AValue: TColor);
procedure SetPicture(aValue: TPicture); procedure SetPicture(aValue: TPicture);
procedure SetRowSize(AValue: TRowSize);
protected const
cBandBorderH: SmallInt = 4;
cBandBorderV: SmallInt = 2;
cGrabWidth: SmallInt = 3;
protected protected
procedure AlignControls(aControl: TControl; var aRect: TRect); override; class var cFullGrabber: SmallInt;
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override; protected
procedure CreateParams(var aParams: TCreateParams); override; FBands: TCtrlBands;
procedure DoBandMove(aControl: TControl; var aRect: TRect); virtual; FBandMove: TBandMove;
procedure DoBandPaint(aControl: TControl; aCanvas: TCanvas; FCursorLock: Boolean;
var aRect: TRect; var aOptions: TBandPaintOptions); virtual; FDefCursor: TCursor;
function DragControl(aControl: TControl; X, Y: Integer; FHoveredBand: TCtrlBand;
FInitDrag: TPoint;
FInnerBevelWidth: SmallInt;
FLockResize: Boolean;
FPrevWidth: Integer;
FVisiBands: array of TCtrlBand;
FVisiBandsEx: array of TCtrlBand;
procedure AlignControlToBand(ABand: TCtrlBand; ARightToLeft: Boolean);
procedure AlignControlsToBands;
function CalcBandHeight(AControl: TControl): Integer;
function CalcBandHeightSnapped(AControl: TControl): Integer;
function CalcInnerBevelWidth: Integer;
function CalcLowestBandBottomPx: Integer;
procedure CalculatePreferredSize(var PreferredWidth, PreferredHeight: Integer;
{%H-}WithThemeSpace: Boolean); override;
procedure ChangeCursor(ACursor: TCursorDesign);
procedure CheckBandsSizeAndVisibility;
procedure CMBiDiModeChanged(var Message: TLMessage); message CM_BIDIMODECHANGED;
procedure CMBorderChanged(var Message: TLMessage); message CM_BORDERCHANGED;
procedure CreateWnd; override;
procedure DoBandMove(AControl: TControl; var ARect: TRect); virtual;
procedure DoBandPaint(AControl: TControl; ACanvas: TCanvas; var ARect: TRect;
var AOptions: TBandPaintOptions); virtual;
function DragControl(AControl: TControl; X, Y: Integer;
KeepCapture: Boolean = False): Boolean; virtual; KeepCapture: Boolean = False): Boolean; virtual;
procedure GetControlInfo(aControl: TControl; var Insets: TRect; procedure DragOver(Source: TObject; X, Y: Integer; State: TDragState;
var PreferredSize, RowCount: Integer); virtual;
function GetPalette: HPALETTE; override;
function DoDragMsg(ADragMessage: TDragMessage; APosition: TPoint; ADragObject: TDragObject;
ATarget: TControl; ADocking: Boolean): LRESULT; override;
procedure DockOver(aSource: TDragDockObject; X, Y: Integer; aState: TDragState;
var Accept: Boolean); override; var Accept: Boolean); override;
procedure GetControlInfo(AControl: TControl; var Insets: TRect;
var PreferredSize, RowCount: Integer); virtual;
class constructor InitializeClass;
procedure InitializeBand(ABand: TCtrlBand; AKeepPos: Boolean);
procedure InitializeMove(AMovingBand: TCtrlBand);
procedure Loaded; override;
function IsBandOverlap(ARect, BRect: TRect): Boolean;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(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 MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MoveBand(AMoveBand: TCtrlBand; X, Y: Integer; ByMouse: Boolean);
procedure NormalizeRows;
procedure Paint; override; procedure Paint; override;
procedure PictureChanged(Sender: TObject);
procedure Resize; override;
procedure SetCursor(Value: TCursor); override;
procedure ShiftBands(AFrom, ATo, AShift, ALimit: Integer);
procedure SortVisibleBands;
procedure WMSize(var Message: TLMSize); message LM_SIZE;
public public
FUpdateCount: SmallInt;
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override; destructor Destroy; override;
procedure BeginUpdate;
procedure EndUpdate;
procedure FlipChildren(AllLevels: Boolean); override; procedure FlipChildren(AllLevels: Boolean); override;
procedure StickControls; virtual; function HitTest(X, Y: Integer): TControl;
property Picture: TPicture read FPicture write SetPicture; procedure InsertControl(AControl: TControl; Index: Integer); override;
protected function MouseToBandPos(X, Y: Integer; out AGrabber: Boolean): TCtrlBand;
procedure RemoveControl(AControl: TControl); override;
procedure StickControls; virtual;
property AutoDock: Boolean read FAutoDock write FAutoDock default True; property AutoDock: Boolean read FAutoDock write FAutoDock default True;
property AutoDrag: Boolean read FAutoDrag write FAutoDrag default True; property AutoDrag: Boolean read FAutoDrag write FAutoDrag default True;
property AutoSize; property AutoSize;
property DockSite default True; property DockSite default True;
property RowSize: TRowSize read FRowSize write FRowSize default 26; property DrawingStyle: TBandDrawingStyle read FDrawingStyle write SetDrawingStyle default dsNormal;
property GradientDirection: TGradientDirection read FGradientDirection write SetGradientDirection default gdVertical;
property GradientStartColor: TColor read FGradientStartColor write SetGradientStartColor default clDefault;
property GradientEndColor: TColor read FGradientEndColor write SetGradientEndColor default clDefault;
property Picture: TPicture read FPicture write SetPicture;
property RowSize: TRowSize read FRowSize write SetRowSize default 26;
property RowSnap: Boolean read FRowSnap write FRowSnap default True; property RowSnap: Boolean read FRowSnap write FRowSnap default True;
property OnBandDrag: TBandDragEvent read FOnBandDrag write FOnBandDrag; property OnBandDrag: TBandDragEvent read FOnBandDrag write FOnBandDrag;
property OnBandInfo: TBandInfoEvent read FOnBandInfo write FOnBandInfo; property OnBandInfo: TBandInfoEvent read FOnBandInfo write FOnBandInfo;
@ -1216,22 +1329,26 @@ type
property AutoDock; property AutoDock;
property AutoDrag; property AutoDrag;
property AutoSize; property AutoSize;
property BevelInner; property BevelInner default bvRaised;
property BevelOuter; property BevelOuter default bvLowered;
property BevelWidth; property BevelWidth;
property BiDiMode; property BiDiMode;
property BorderWidth; property BorderWidth;
property Color nodefault; property Color;
property Constraints; property Constraints;
property DockSite; property DockSite;
property DragCursor; property DragCursor;
property DragKind; property DragKind;
property DragMode; property DragMode;
property DrawingStyle;
property Enabled; property Enabled;
property GradientDirection;
property GradientEndColor;
property GradientStartColor;
property ParentColor; property ParentColor;
property ParentFont; property ParentFont;
property ParentShowHint; property ParentShowHint;
// property Picture; property Picture;
property PopupMenu; property PopupMenu;
property RowSize; property RowSize;
property RowSnap; property RowSnap;

File diff suppressed because it is too large Load Diff