change formatting of controlscrollbar.inc (since nobody from devels were against)

git-svn-id: trunk@12326 -
This commit is contained in:
paul 2007-10-05 01:42:04 +00:00
parent dde8cbb08a
commit 38c4cf597b

View File

@ -16,22 +16,29 @@
} }
const const
IntfBarKind: array[TScrollBarKind] of Integer = (SB_HORZ,SB_VERT); IntfBarKind: array[TScrollBarKind] of Integer =
(
SB_HORZ,
SB_VERT
);
procedure TControlScrollBar.SetPosition(const Value: Integer); procedure TControlScrollBar.SetPosition(const Value: Integer);
var var
OldPosition: Integer; OldPosition: Integer;
begin begin
if Value < 0 then begin if Value < 0 then
begin
SetPosition(0); SetPosition(0);
exit; exit;
end; end;
If ControlAutoScroll then begin if ControlAutoScroll then
begin
if FAutoRange < 0 then if FAutoRange < 0 then
AutoCalcRange; AutoCalcRange;
if Value > FAutoRange then begin if Value > FAutoRange then
begin
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
if Kind=sbHorizontal then if Kind=sbHorizontal then
DebugLn(['TControlScrollBar.SetPosition FAutoRange Value=',Value,' > AutoRange=',FAutoRange]); DebugLn(['TControlScrollBar.SetPosition FAutoRange Value=',Value,' > AutoRange=',FAutoRange]);
@ -41,9 +48,10 @@ begin
end; end;
end; end;
if Value>Range then begin if Value > Range then
begin
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
if Kind=sbHorizontal then if Kind = sbHorizontal then
DebugLn(['TControlScrollBar.SetPosition Range Value=',Value,' > Range=',Range]); DebugLn(['TControlScrollBar.SetPosition Range Value=',Value,' > Range=',Range]);
{$ENDIF} {$ENDIF}
SetPosition(Range); SetPosition(Range);
@ -51,23 +59,24 @@ begin
end; end;
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
if Kind=sbHorizontal then if Kind = sbHorizontal then
DebugLn(['TControlScrollBar.SetPosition Value=',Value,' FPosition=',FPosition]); DebugLn(['TControlScrollBar.SetPosition Value=',Value,' FPosition=',FPosition]);
{$ENDIF} {$ENDIF}
if Value=FPosition then exit; if Value = FPosition then
exit;
// scroll content of FControl // scroll content of FControl
OldPosition:=FPosition; OldPosition := FPosition;
FPosition := Value; FPosition := Value;
if FControl is TScrollingWinControl then if FControl is TScrollingWinControl then
TScrollingWinControl(FControl).ScrollbarHandler(Kind, OldPosition); TScrollingWinControl(FControl).ScrollbarHandler(Kind, OldPosition);
// check that the new position is also set on the scrollbar // check that the new position is also set on the scrollbar
if HandleAllocated if HandleAllocated and (GetScrollPos(ControlHandle, IntfBarKind[Kind]) <> FPosition) then
and (GetScrollPos(ControlHandle, IntfBarKind[Kind]) <> FPosition) then begin begin
InvalidateScollInfo; InvalidateScollInfo;
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
if Kind=sbHorizontal then if Kind = sbHorizontal then
DebugLn(['TControlScrollBar.SetPosition FPosition=',FPosition]); DebugLn(['TControlScrollBar.SetPosition FPosition=',FPosition]);
{$ENDIF} {$ENDIF}
SetScrollPos(ControlHandle, IntfBarKind[Kind], FPosition, Visible); SetScrollPos(ControlHandle, IntfBarKind[Kind], FPosition, Visible);
@ -76,107 +85,117 @@ end;
function TControlScrollBar.SmoothIsStored: boolean; function TControlScrollBar.SmoothIsStored: boolean;
begin begin
Result:=FSmooth; Result := FSmooth;
end; end;
function TControlScrollBar.GetIncrement: TScrollBarInc; function TControlScrollBar.GetIncrement: TScrollBarInc;
begin begin
Result:=FIncrement; Result := FIncrement;
end; end;
function TControlScrollBar.GetPage: TScrollBarInc; function TControlScrollBar.GetPage: TScrollBarInc;
var ScrollInfo: TScrollInfo; var
ScrollInfo: TScrollInfo;
begin begin
if HandleAllocated and (not (FControl is TScrollingWinControl)) then begin if HandleAllocated and (not (FControl is TScrollingWinControl)) then
ScrollInfo.fMask:=SIF_PAGE; begin
GetScrollInfo(ControlHandle,IntfBarKind[Kind],ScrollInfo); ScrollInfo.fMask := SIF_PAGE;
GetScrollInfo(ControlHandle, IntfBarKind[Kind], ScrollInfo);
InvalidateScollInfo; InvalidateScollInfo;
FPage:=ScrollInfo.nPage; FPage := ScrollInfo.nPage;
end; end;
Result:=FPage; Result := FPage;
end; end;
function TControlScrollBar.GetPosition: Integer; function TControlScrollBar.GetPosition: Integer;
var ScrollInfo: TScrollInfo; var
ScrollInfo: TScrollInfo;
begin begin
if HandleAllocated and (not (FControl is TScrollingWinControl)) then begin if HandleAllocated and (not (FControl is TScrollingWinControl)) then
ScrollInfo.fMask:=SIF_POS; begin
GetScrollInfo(ControlHandle,IntfBarKind[Kind],ScrollInfo); ScrollInfo.fMask := SIF_POS;
GetScrollInfo(ControlHandle, IntfBarKind[Kind], ScrollInfo);
InvalidateScollInfo; InvalidateScollInfo;
FPosition:=ScrollInfo.nPos; FPosition := ScrollInfo.nPos;
end; end;
Result:=FPosition; Result := FPosition;
end; end;
function TControlScrollBar.GetRange: Integer; function TControlScrollBar.GetRange: Integer;
var ScrollInfo: TScrollInfo; var
ScrollInfo: TScrollInfo;
begin begin
if HandleAllocated and (not (FControl is TScrollingWinControl)) then begin if HandleAllocated and (not (FControl is TScrollingWinControl)) then
ScrollInfo.fMask:=SIF_Range+SIF_Page; begin
GetScrollInfo(ControlHandle,IntfBarKind[Kind],ScrollInfo); ScrollInfo.fMask := SIF_Range + SIF_Page;
GetScrollInfo(ControlHandle, IntfBarKind[Kind], ScrollInfo);
InvalidateScollInfo; InvalidateScollInfo;
FRange:=ScrollInfo.nMax-ScrollInfo.nMin-integer(ScrollInfo.nPage); FRange := ScrollInfo.nMax - ScrollInfo.nMin - integer(ScrollInfo.nPage);
end; end;
Result:=FRange; Result := FRange;
end; end;
function TControlScrollBar.GetSmooth: Boolean; function TControlScrollBar.GetSmooth: Boolean;
begin begin
Result:=FSmooth; Result := FSmooth;
end; end;
function TControlScrollBar.GetVisible: Boolean; function TControlScrollBar.GetVisible: Boolean;
begin begin
if HandleAllocated and (not (FControl is TScrollingWinControl)) then begin if HandleAllocated and (not (FControl is TScrollingWinControl)) then
begin
InvalidateScollInfo; InvalidateScollInfo;
FVisible:=GetScrollbarVisible(Controlhandle,IntfBarKind[Kind]); FVisible := GetScrollbarVisible(Controlhandle, IntfBarKind[Kind]);
end; end;
Result:=FVisible; Result := FVisible;
end; end;
procedure TControlScrollBar.SetIncrement(const AValue: TScrollBarInc); procedure TControlScrollBar.SetIncrement(const AValue: TScrollBarInc);
begin begin
// This value is only used by the ScrollHandler procedure // This value is only used by the ScrollHandler procedure
FIncrement:=AValue; FIncrement := AValue;
end; end;
procedure TControlScrollBar.SetPage(const AValue: TScrollBarInc); procedure TControlScrollBar.SetPage(const AValue: TScrollBarInc);
begin begin
if FPage=AValue then exit; if FPage = AValue then exit;
FPage:=AValue; FPage := AValue;
ControlUpdateScrollBars; ControlUpdateScrollBars;
end; end;
function TControlScrollBar.VisibleIsStored: boolean; function TControlScrollBar.VisibleIsStored: boolean;
begin begin
Result:=FVisible; Result := FVisible;
end; end;
function TControlScrollBar.GetSize: integer; function TControlScrollBar.GetSize: integer;
var var
KindID: integer; KindID: integer;
begin begin
if Kind=sbHorizontal then if Kind = sbHorizontal then
KindID:=SM_CYHSCROLL KindID := SM_CYHSCROLL
else else
KindID:=SM_CXVSCROLL; KindID := SM_CXVSCROLL;
if HandleAllocated then begin if HandleAllocated then
Result:=LCLIntf.GetScrollBarSize(ControlHandle,KindID); begin
Result := LCLIntf.GetScrollBarSize(ControlHandle,KindID);
InvalidateScollInfo; InvalidateScollInfo;
end else end else
Result:=GetSystemMetrics(KindID); Result := GetSystemMetrics(KindID);
end; end;
procedure TControlScrollBar.SetRange(const Value: Integer); procedure TControlScrollBar.SetRange(const Value: Integer);
begin begin
If Value < 0 then begin if Value < 0 then
begin
Range := 0; Range := 0;
exit; exit;
end; end;
if FRange=Value then exit; if FRange = Value then
exit;
FRange := Value; FRange := Value;
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
if Kind=sbHorizontal then if Kind = sbHorizontal then
DebugLn(['TControlScrollBar.SetRange ',Self,' fRange=',FRange]); DebugLn(['TControlScrollBar.SetRange ',Self,' fRange=',FRange]);
{$ENDIF} {$ENDIF}
ControlUpdateScrollBars; ControlUpdateScrollBars;
@ -184,12 +203,13 @@ end;
procedure TControlScrollBar.SetSize(const AValue: integer); procedure TControlScrollBar.SetSize(const AValue: integer);
begin begin
Raise EScrollBar.Create('[TControlScrollBar.SetPage] Size is readonly'); raise EScrollBar.Create('[TControlScrollBar.SetPage] Size is readonly');
end; end;
procedure TControlScrollBar.SetVisible(const Value: Boolean); procedure TControlScrollBar.SetVisible(const Value: Boolean);
begin begin
if FVisible = Value then exit; if FVisible = Value then
exit;
FVisible := Value; FVisible := Value;
ControlUpdateScrollBars; ControlUpdateScrollBars;
end; end;
@ -204,14 +224,15 @@ procedure TControlScrollBar.AutoCalcRange;
procedure AutoCalcVRange; procedure AutoCalcVRange;
var var
I : Integer; I: Integer;
TmpRange : Longint; TmpRange: Longint;
begin begin
TmpRange := 0; TmpRange := 0;
For I := 0 to FControl.ControlCount - 1 do For I := 0 to FControl.ControlCount - 1 do
With FControl.Controls[I] do With FControl.Controls[I] do
if IsControlVisible then begin if IsControlVisible then
If (Align = alTop) or (Align = alNone) then begin
if (Align = alTop) or (Align = alNone) then
TmpRange := Max(TmpRange, Top + Height); TmpRange := Max(TmpRange, Top + Height);
end; end;
Range := TmpRange; Range := TmpRange;
@ -227,8 +248,10 @@ procedure TControlScrollBar.AutoCalcRange;
for i := 0 to FControl.ControlCount - 1 do for i := 0 to FControl.ControlCount - 1 do
begin begin
c := FControl.Controls[I]; c := FControl.Controls[I];
if not C.IsControlVisible then Continue; if not C.IsControlVisible then
if (c.Align <> alLeft) and (c.Align <> alNone) then Continue; Continue;
if (c.Align <> alLeft) and (c.Align <> alNone) then
Continue;
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
DebugLn(['AutoCalcHRange ',DbgSName(c),' Left=',c.Left]); DebugLn(['AutoCalcHRange ',DbgSName(c),' Left=',c.Left]);
{$ENDIF} {$ENDIF}
@ -238,7 +261,8 @@ procedure TControlScrollBar.AutoCalcRange;
end; end;
begin begin
if ControlAutoScroll then begin if ControlAutoScroll then
begin
FVisible := True; FVisible := True;
if Kind = sbVertical then if Kind = sbVertical then
AutoCalcVRange AutoCalcVRange
@ -251,8 +275,8 @@ procedure TControlScrollBar.UpdateScrollBar;
var var
ScrollInfo: TScrollInfo; ScrollInfo: TScrollInfo;
begin begin
if HandleAllocated if HandleAllocated and (FControl is TScrollingWinControl) then
and (FControl is TScrollingWinControl) then begin begin
FillChar(ScrollInfo,SizeOf(ScrollInfo),0); FillChar(ScrollInfo,SizeOf(ScrollInfo),0);
ScrollInfo.cbSize := SizeOf(ScrollInfo); ScrollInfo.cbSize := SizeOf(ScrollInfo);
ScrollInfo.fMask := SIF_ALL; ScrollInfo.fMask := SIF_ALL;
@ -261,15 +285,14 @@ begin
ScrollInfo.nPos := FPosition; ScrollInfo.nPos := FPosition;
ScrollInfo.nPage := FPage; ScrollInfo.nPage := FPage;
ScrollInfo.nTrackPos := FPosition; ScrollInfo.nTrackPos := FPosition;
if (not FOldScrollInfoValid) if (not FOldScrollInfoValid) or (not CompareMem(@ScrollInfo,@FOldScrollInfo,SizeOf(TScrollInfo))) then
or (not CompareMem(@ScrollInfo,@FOldScrollInfo,SizeOf(TScrollInfo))) then
begin begin
FOldScrollInfo:=ScrollInfo; FOldScrollInfo:=ScrollInfo;
FOldScrollInfoValid:=true; FOldScrollInfoValid := true;
SetScrollInfo(FControl.Handle, IntfBarKind[Kind], ScrollInfo, FVisible); SetScrollInfo(FControl.Handle, IntfBarKind[Kind], ScrollInfo, FVisible);
end; end;
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
if Kind=sbHorizontal then if Kind = sbHorizontal then
DebugLn(['TControlScrollBar.UpdateScrollBar ',DbgSName(FControl),' ',DbgSName(Self),' FVisible=',FVisible,' Range=',FRange,' FPosition=',FPosition,' FPage=',FPage,' FAutoRange=',FAutoRange]); DebugLn(['TControlScrollBar.UpdateScrollBar ',DbgSName(FControl),' ',DbgSName(Self),' FVisible=',FVisible,' Range=',FRange,' FPosition=',FPosition,' FPage=',FPage,' FAutoRange=',FAutoRange]);
{$ENDIF} {$ENDIF}
end; end;
@ -292,16 +315,16 @@ end;
function TControlScrollBar.ControlAutoScroll: boolean; function TControlScrollBar.ControlAutoScroll: boolean;
begin begin
if FControl is TScrollingWinControl then if FControl is TScrollingWinControl then
Result:=TScrollingWinControl(FControl).AutoScroll Result := TScrollingWinControl(FControl).AutoScroll
else else
Result:=false; Result := false;
end; end;
procedure TControlScrollBar.ScrollHandler(var Message: TLMScroll); procedure TControlScrollBar.ScrollHandler(var Message: TLMScroll);
var var
NewPos: Longint; NewPos: Longint;
begin begin
If (csDesigning in FControl.ComponentState) then if (csDesigning in FControl.ComponentState) then
exit; //prevent wierdness in IDE. exit; //prevent wierdness in IDE.
NewPos := FPosition; NewPos := FPosition;
@ -326,28 +349,32 @@ begin
{$IFDEF VerboseScrollingWinControl} {$IFDEF VerboseScrollingWinControl}
DebugLn(['TControlScrollBar.ScrollHandler Message.ScrollCode=',Message.ScrollCode,' FPosition=',FPosition,' NewPos=',NewPos,' Range=',Range]); DebugLn(['TControlScrollBar.ScrollHandler Message.ScrollCode=',Message.ScrollCode,' FPosition=',FPosition,' NewPos=',NewPos,' Range=',Range]);
{$ENDIF} {$ENDIF}
if NewPos < 0 then NewPos := 0; if NewPos < 0 then
if NewPos > Range then NewPos := Range; NewPos := 0;
if NewPos > FRange then
NewPos := FRange;
InvalidateScollInfo; InvalidateScollInfo;
SetPosition(NewPos); SetPosition(NewPos);
end; end;
procedure TControlScrollBar.ControlUpdateScrollBars; procedure TControlScrollBar.ControlUpdateScrollBars;
begin begin
if ([csLoading,csDestroying]*FControl.ComponentState<>[]) then exit; if ([csLoading, csDestroying] * FControl.ComponentState <> []) then
if not HandleAllocated then exit; exit;
if not HandleAllocated then
exit;
if FControl is TScrollingWinControl then if FControl is TScrollingWinControl then
TScrollingWinControl(FControl).UpdateScrollBars; TScrollingWinControl(FControl).UpdateScrollBars;
end; end;
function TControlScrollBar.HandleAllocated: boolean; function TControlScrollBar.HandleAllocated: boolean;
begin begin
Result:=(FControl<>nil) and (FControl.HandleAllocated); Result := (FControl<>nil) and (FControl.HandleAllocated);
end; end;
function TControlScrollBar.ControlHandle: HWnd; function TControlScrollBar.ControlHandle: HWnd;
begin begin
Result:=FControl.Handle; Result := FControl.Handle;
end; end;
constructor TControlScrollBar.Create(AControl: TWinControl; constructor TControlScrollBar.Create(AControl: TWinControl;
@ -366,8 +393,10 @@ end;
procedure TControlScrollBar.Assign(Source: TPersistent); procedure TControlScrollBar.Assign(Source: TPersistent);
begin begin
If Source is TControlScrollBar then begin if Source is TControlScrollBar then
With Source as TControlScrollBar do begin begin
with Source as TControlScrollBar do
begin
Self.Increment := Increment; Self.Increment := Increment;
Self.Position := Position; Self.Position := Position;
Self.Range := Range; Self.Range := Range;
@ -389,29 +418,29 @@ end;
function TControlScrollBar.ScrollPos: Integer; function TControlScrollBar.ScrollPos: Integer;
begin begin
if Visible then if Visible then
Result:=Position Result := Position
else else
Result:=0; Result := 0;
end; end;
function TControlScrollBar.GetOtherScrollBar: TControlScrollBar; function TControlScrollBar.GetOtherScrollBar: TControlScrollBar;
begin begin
if Kind=sbVertical then if Kind = sbVertical then
Result:=GetHorzScrollBar Result := GetHorzScrollBar
else else
Result:=GetVertSCrollbar; Result := GetVertSCrollbar;
end; end;
function TControlScrollBar.GetHorzScrollBar: TControlScrollBar; function TControlScrollBar.GetHorzScrollBar: TControlScrollBar;
begin begin
if FControl is TScrollingWinControl then if FControl is TScrollingWinControl then
Result:=TScrollingWinControl(FControl).HorzScrollBar; Result := TScrollingWinControl(FControl).HorzScrollBar;
end; end;
function TControlScrollBar.GetVertScrollBar: TControlScrollBar; function TControlScrollBar.GetVertScrollBar: TControlScrollBar;
begin begin
if FControl is TScrollingWinControl then if FControl is TScrollingWinControl then
Result:=TScrollingWinControl(FControl).VertScrollBar; Result := TScrollingWinControl(FControl).VertScrollBar;
end; end;
// included by forms.pp // included by forms.pp