mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-06 15:41:45 +02:00
THeaderControl:
- Allow to resize the buttons on the THeaderControl (patch from Benito van der Zander with small modifications issue #0011036) - Add MinWidth, MaxWidth to section to prevent resizing - correct build lazarus dialogs to prevent header resizing after this changes git-svn-id: trunk@14622 -
This commit is contained in:
parent
e6f62e71e9
commit
ad94ffd5fb
@ -757,26 +757,36 @@ begin
|
||||
with ItemListHeader.Sections.Add do
|
||||
begin
|
||||
Width := ButtonSize;
|
||||
MinWidth := Width;
|
||||
MaxWidth := Width;
|
||||
ImageIndex := IDEImages.LoadImage(16, 'menu_close');
|
||||
end;
|
||||
with ItemListHeader.Sections.Add do
|
||||
begin
|
||||
Width := ButtonSize;
|
||||
MinWidth := Width;
|
||||
MaxWidth := Width;
|
||||
ImageIndex := IDEImages.LoadImage(16, 'menu_build');
|
||||
end;
|
||||
with ItemListHeader.Sections.Add do
|
||||
begin
|
||||
Width := ButtonSize;
|
||||
MinWidth := Width;
|
||||
MaxWidth := Width;
|
||||
ImageIndex := IDEImages.LoadImage(16, 'menu_build_clean');
|
||||
end;
|
||||
with ItemListHeader.Sections.Add do
|
||||
begin
|
||||
Width := ItemListHeader.Width - 90 - 3 * ButtonSize;
|
||||
MinWidth := Width;
|
||||
MaxWidth := Width;
|
||||
Text := lisLazBuildABOPart;
|
||||
end;
|
||||
with ItemListHeader.Sections.Add do
|
||||
begin
|
||||
Width := 90;
|
||||
MinWidth := Width;
|
||||
MaxWidth := Width;
|
||||
Text := lisLazBuildABOAction;
|
||||
end;
|
||||
|
||||
|
@ -2520,7 +2520,6 @@ type
|
||||
|
||||
|
||||
{ THeaderSection }
|
||||
|
||||
THeaderSectionState =
|
||||
(
|
||||
hsNormal,
|
||||
@ -2530,17 +2529,22 @@ type
|
||||
THeaderSection = class(TCollectionItem)
|
||||
private
|
||||
FAlignment: TAlignment;
|
||||
FImageIndex: TImageIndex;
|
||||
FMinWidth: Integer;
|
||||
FMaxWidth: Integer;
|
||||
FState: THeaderSectionState;
|
||||
FText: string;
|
||||
FWidth: Integer;
|
||||
FImageIndex: TImageIndex;
|
||||
FState: THeaderSectionState;
|
||||
function GetLeft: Integer;
|
||||
function GetRight: Integer;
|
||||
procedure SetAlignment(const AValue: TAlignment);
|
||||
procedure SetMaxWidth(AValue: Integer);
|
||||
procedure SetMinWidth(AValue: Integer);
|
||||
procedure SetState(const AValue: THeaderSectionState);
|
||||
procedure SetText(const Value: string);
|
||||
procedure SetWidth(Value: Integer);
|
||||
procedure SetImageIndex(const Value: TImageIndex);
|
||||
procedure CheckConstraints; inline;
|
||||
public
|
||||
constructor Create(ACollection: TCollection); override;
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
@ -2550,6 +2554,8 @@ type
|
||||
published
|
||||
property Alignment: TAlignment read FAlignment write SetAlignment;
|
||||
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
|
||||
property MaxWidth: Integer read FMaxWidth write SetMaxWidth default 10000;
|
||||
property MinWidth: Integer read FMinWidth write SetMinWidth default 0;
|
||||
property Text: string read FText write SetText;
|
||||
property Width: Integer read FWidth write SetWidth;
|
||||
end;
|
||||
@ -2575,6 +2581,8 @@ type
|
||||
property Items[Index: Integer]: THeaderSection read GetItem write SetItem; default;
|
||||
end;
|
||||
|
||||
TSectionTrackState = (tsTrackBegin, tsTrackMove, tsTrackEnd);
|
||||
TCustomSectionTrackEvent = procedure(HeaderControl: TCustomHeaderControl; Section: THeaderSection; Width: Integer; State: TSectionTrackState) of object;
|
||||
TCustomSectionNotifyEvent = procedure(HeaderControl: TCustomHeaderControl;
|
||||
Section: THeaderSection) of object;
|
||||
TCustomHCCreateSectionClassEvent = procedure(Sender: TCustomHeaderControl;
|
||||
@ -2590,9 +2598,13 @@ type
|
||||
FPaintRect: TRect;
|
||||
FDown: Boolean;
|
||||
FDownPoint: TPoint;
|
||||
FTracking: Boolean;
|
||||
FSelectedSelection: longint;
|
||||
FMouseInControl: Boolean;
|
||||
|
||||
FOnSectionClick: TCustomSectionNotifyEvent;
|
||||
FOnSectionResize: TCustomSectionNotifyEvent;
|
||||
FOnSectionTrack: TCustomSectionTrackEvent;
|
||||
FOnCreateSectionClass: TCustomHCCreateSectionClassEvent;
|
||||
procedure SetImages(const AValue: TCustomImageList);
|
||||
procedure SetSections(const AValue: THeaderSections);
|
||||
@ -2603,6 +2615,8 @@ type
|
||||
function CreateSections: THeaderSections; virtual;
|
||||
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||
procedure SectionClick(Section: THeaderSection); dynamic;
|
||||
procedure SectionResize(Section: THeaderSection); dynamic;
|
||||
procedure SectionTrack(Section: THeaderSection; State: TSectionTrackState); dynamic;
|
||||
procedure MouseEnter; override;
|
||||
procedure MouseLeave; override;
|
||||
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
|
||||
@ -2626,6 +2640,10 @@ type
|
||||
|
||||
property OnSectionClick: TCustomSectionNotifyEvent read FOnSectionClick
|
||||
write FOnSectionClick;
|
||||
property OnSectionResize: TCustomSectionNotifyEvent read FOnSectionResize
|
||||
write FOnSectionResize;
|
||||
property OnSectionTrack: TCustomSectionTrackEvent read FOnSectionTrack
|
||||
write FOnSectionTrack;
|
||||
property OnCreateSectionClass: TCustomHCCreateSectionClassEvent read FOnCreateSectionClass
|
||||
write FOnCreateSectionClass;
|
||||
end;
|
||||
@ -2666,6 +2684,9 @@ type
|
||||
property OnMouseMove;
|
||||
property OnMouseUp;
|
||||
property OnResize;
|
||||
property OnSectionClick;
|
||||
property OnSectionResize;
|
||||
property OnSectionTrack;
|
||||
end;
|
||||
|
||||
function CompareExpandedNodes(Data1, Data2: Pointer): integer;
|
||||
@ -2697,7 +2718,6 @@ end;
|
||||
{$I tabsheet.inc}
|
||||
{$I pagecontrol.inc}
|
||||
{$I tabcontrol.inc}
|
||||
{ $I alignment.inc}
|
||||
{$I listcolumns.inc}
|
||||
{$I listcolumn.inc}
|
||||
{$I listitem.inc}
|
||||
|
@ -20,6 +20,8 @@
|
||||
}
|
||||
{ TCustomHeaderControl }
|
||||
|
||||
const HeaderBorderSize = 2;
|
||||
|
||||
procedure TCustomHeaderControl.SetImages(const AValue: TCustomImageList);
|
||||
begin
|
||||
FImages := AValue;
|
||||
@ -80,10 +82,13 @@ procedure TCustomHeaderControl.Click;
|
||||
var
|
||||
Index: Integer;
|
||||
begin
|
||||
inherited Click;
|
||||
Index := GetSectionAt(ScreenToClient(Mouse.CursorPos));
|
||||
if Index <> -1 then
|
||||
SectionClick(Sections[Index]);
|
||||
if not FTracking then
|
||||
begin
|
||||
inherited Click;
|
||||
Index := GetSectionAt(ScreenToClient(Mouse.CursorPos));
|
||||
if Index <> -1 then
|
||||
SectionClick(Sections[Index]);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCustomHeaderControl.GetSectionAt(P: TPoint): Integer;
|
||||
@ -113,6 +118,19 @@ begin
|
||||
OnSectionClick(Self, Section);
|
||||
end;
|
||||
|
||||
procedure TCustomHeaderControl.SectionResize(Section: THeaderSection);
|
||||
begin
|
||||
if Assigned(FOnSectionResize) then
|
||||
FOnSectionResize(Self, Section);
|
||||
end;
|
||||
|
||||
procedure TCustomHeaderControl.SectionTrack(Section: THeaderSection;
|
||||
State: TSectionTrackState);
|
||||
begin
|
||||
if Assigned(FOnSectionTrack) then
|
||||
FOnSectionTrack(Self, Section, Section.FWidth, State);
|
||||
end;
|
||||
|
||||
procedure TCustomHeaderControl.MouseEnter;
|
||||
begin
|
||||
inherited MouseEnter;
|
||||
@ -142,6 +160,21 @@ begin
|
||||
begin
|
||||
FDown := True;
|
||||
FDownPoint := Point(X, Y);
|
||||
if Button = mbLeft then
|
||||
if GetSectionAt(Point(X - HeaderBorderSize, Y))<>GetSectionAt(Point(X + HeaderBorderSize, Y)) then
|
||||
begin
|
||||
FTracking:=true;
|
||||
FSelectedSelection:=GetSectionAt(Point(X - HeaderBorderSize, Y));
|
||||
if FSelectedSelection = -1 then
|
||||
FTracking:=false
|
||||
else
|
||||
Cursor:=crSizeE;
|
||||
if FTracking then
|
||||
begin
|
||||
FDown := False;
|
||||
SectionTrack(Sections[FSelectedSelection], tsTrackBegin);
|
||||
end;
|
||||
end;
|
||||
UpdateState;
|
||||
end;
|
||||
end;
|
||||
@ -151,11 +184,25 @@ begin
|
||||
inherited MouseMove(Shift, X, Y);
|
||||
if not (csDesigning in ComponentState) then
|
||||
begin
|
||||
if FTracking and (ssLeft in shift) then
|
||||
begin
|
||||
if x>=FSections[FSelectedSelection].Left then
|
||||
begin
|
||||
FSections[FSelectedSelection].Width := X - FSections[FSelectedSelection].Left;
|
||||
SectionTrack(Sections[FSelectedSelection], tsTrackMove);
|
||||
end;
|
||||
end
|
||||
else
|
||||
if FDown then
|
||||
begin
|
||||
if GetSectionAt(Point(X, Y)) <> GetSectionAt(FDownPoint) then
|
||||
FDown := False;
|
||||
end;
|
||||
if shift = [] then
|
||||
if GetSectionAt(Point(X - HeaderBorderSize, Y))<>GetSectionAt(Point(X + HeaderBorderSize, Y)) then
|
||||
Cursor:=crSizeE
|
||||
else
|
||||
Cursor:=crDefault;
|
||||
UpdateState;
|
||||
end;
|
||||
end;
|
||||
@ -164,10 +211,14 @@ procedure TCustomHeaderControl.MouseUp(Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
inherited MouseUp(Button, Shift, X, Y);
|
||||
if FTracking then
|
||||
begin
|
||||
FDown := False;
|
||||
UpdateState;
|
||||
SectionTrack(Sections[FSelectedSelection],tsTrackEnd);
|
||||
SectionResize(Sections[FSelectedSelection]);
|
||||
end;
|
||||
FDown := False;
|
||||
FTracking:=false;
|
||||
UpdateState;
|
||||
end;
|
||||
|
||||
procedure TCustomHeaderControl.UpdateState;
|
||||
@ -335,6 +386,36 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure THeaderSection.SetMaxWidth(AValue: Integer);
|
||||
begin
|
||||
if AValue > 10000 then
|
||||
AValue := 10000;
|
||||
if AValue < FMinWidth then
|
||||
AValue := FMinWidth;
|
||||
|
||||
if FMaxWidth <> AValue then
|
||||
begin
|
||||
FMaxWidth := AValue;
|
||||
CheckConstraints;
|
||||
Changed(False);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure THeaderSection.SetMinWidth(AValue: Integer);
|
||||
begin
|
||||
if AValue < 0 then
|
||||
AValue := 0;
|
||||
if AValue > FMaxWidth then
|
||||
AValue := FMaxWidth;
|
||||
|
||||
if FMinWidth <> AValue then
|
||||
begin
|
||||
FMinWidth := AValue;
|
||||
CheckConstraints;
|
||||
Changed(False);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure THeaderSection.SetState(const AValue: THeaderSectionState);
|
||||
begin
|
||||
if FState <> AValue then
|
||||
@ -358,6 +439,7 @@ begin
|
||||
if FWidth <> Value then
|
||||
begin
|
||||
FWidth := Value;
|
||||
CheckConstraints;
|
||||
Changed(False);
|
||||
end;
|
||||
end;
|
||||
@ -371,6 +453,14 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure THeaderSection.CheckConstraints; inline;
|
||||
begin
|
||||
if FWidth < FMinWidth then
|
||||
FWidth := FMinWidth;
|
||||
if FWidth > FMaxWidth then
|
||||
FWidth := FMaxWidth;
|
||||
end;
|
||||
|
||||
constructor THeaderSection.Create(ACollection: TCollection);
|
||||
begin
|
||||
inherited Create(ACollection);
|
||||
@ -379,6 +469,8 @@ begin
|
||||
FText := '';
|
||||
FAlignment := taLeftJustify;
|
||||
FState := hsNormal;
|
||||
FMinWidth := 0;
|
||||
FMaxWidth := 10000;
|
||||
end;
|
||||
|
||||
procedure THeaderSection.Assign(Source: TPersistent);
|
||||
|
Loading…
Reference in New Issue
Block a user