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