lcl: make ScrollBy more delphi compatible:

- invert direction of scroll
  - add TWinControl.ScrollBy to scroll inner controls
  - scroll controls in TScrollingWinControl (fixes issue #0016721)

git-svn-id: trunk@29944 -
This commit is contained in:
paul 2011-03-21 02:41:43 +00:00
parent a4d4972a0a
commit 0373c8de84
9 changed files with 53 additions and 37 deletions

View File

@ -1930,6 +1930,7 @@ type
procedure DisableAlign; procedure DisableAlign;
procedure EnableAlign; procedure EnableAlign;
procedure ReAlign; // realign all children procedure ReAlign; // realign all children
procedure ScrollBy(DeltaX, DeltaY: Integer); virtual;
procedure WriteLayoutDebugReport(const Prefix: string); override; procedure WriteLayoutDebugReport(const Prefix: string); override;
public public
constructor Create(TheOwner: TComponent);override; constructor Create(TheOwner: TComponent);override;

View File

@ -184,7 +184,7 @@ type
destructor Destroy; override; destructor Destroy; override;
procedure UpdateScrollbars; procedure UpdateScrollbars;
class function GetControlClassDefaultSize: TSize; override; class function GetControlClassDefaultSize: TSize; override;
procedure ScrollBy(DeltaX, DeltaY: Integer); procedure ScrollBy(DeltaX, DeltaY: Integer); override;
published published
property HorzScrollBar: TControlScrollBar property HorzScrollBar: TControlScrollBar
read FHorzScrollBar write SetHorzScrollBar stored StoreScrollBars; read FHorzScrollBar write SetHorzScrollBar stored StoreScrollBars;

View File

@ -189,21 +189,31 @@ begin
end; end;
procedure TScrollingWinControl.ScrollBy(DeltaX, DeltaY: Integer); procedure TScrollingWinControl.ScrollBy(DeltaX, DeltaY: Integer);
var
i: Integer;
Control: TControl;
begin begin
if HandleAllocated then if HandleAllocated and IsWindowVisible(Handle) then
begin begin
TWSScrollingWinControlClass(WidgetSetClass).ScrollBy(Self, DeltaX, DeltaY); TWSScrollingWinControlClass(WidgetSetClass).ScrollBy(Self, DeltaX, DeltaY);
// scroll inner controls
for i := 0 to ControlCount - 1 do
if not (Controls[i] is TWinControl) then
with Controls[i] do
SetBounds(Left + DeltaX, Top + DeltaY, Width, Height);
Invalidate; Invalidate;
end; end
else
inherited ScrollBy(DeltaX, DeltaY);
end; end;
procedure TScrollingWinControl.ScrollbarHandler(ScrollKind: TScrollBarKind; procedure TScrollingWinControl.ScrollbarHandler(ScrollKind: TScrollBarKind;
OldPosition: Integer); OldPosition: Integer);
begin begin
if ScrollKind = sbVertical then if ScrollKind = sbVertical then
ScrollBy(0, FVertScrollBar.Position - OldPosition) ScrollBy(0, OldPosition - FVertScrollBar.Position)
else else
ScrollBy(FHorzScrollBar.Position - OldPosition, 0); ScrollBy(OldPosition - FHorzScrollBar.Position, 0);
end; end;
procedure TScrollingWinControl.Loaded; procedure TScrollingWinControl.Loaded;

View File

@ -5997,6 +5997,17 @@ begin
AdjustSize; AdjustSize;
end; end;
procedure TWinControl.ScrollBy(DeltaX, DeltaY: Integer);
var
i: Integer;
Control: TControl;
begin
// scroll inner controls
for i := 0 to ControlCount - 1 do
with Controls[i] do
SetBounds(Left + DeltaX, Top + DeltaY, Width, Height);
end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
TWinControl Remove TWinControl Remove
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}

View File

@ -952,7 +952,7 @@ const
begin begin
OSError(HIViewGetBounds(Content, R), OSError(HIViewGetBounds(Content, R),
Self, SName, 'HIViewGetBounds'); Self, SName, 'HIViewGetBounds');
OSError(HIViewSetBoundsOrigin(Content, R.origin.x + DX, R.origin.y + DY), OSError(HIViewSetBoundsOrigin(Content, R.origin.x - DX, R.origin.y - DY),
Self, SName, 'HIViewSetBoundsOrigin'); Self, SName, 'HIViewSetBoundsOrigin');
end; end;

View File

@ -426,8 +426,7 @@ begin
g_idle_remove_by_data(Data); g_idle_remove_by_data(Data);
end; end;
class procedure TGtk2WSCustomForm.ScrollBy( class procedure TGtk2WSCustomForm.ScrollBy(const AWinControl: TScrollingWinControl; const DeltaX, DeltaY: integer);
const AWinControl: TScrollingWinControl; const DeltaX, DeltaY: integer);
var var
Layout: PGtkLayout; Layout: PGtkLayout;
WidgetInfo: PWidgetInfo; WidgetInfo: PWidgetInfo;
@ -443,8 +442,8 @@ begin
begin begin
h := gtk_adjustment_get_value(Adjustment); h := gtk_adjustment_get_value(Adjustment);
NewPos := Adjustment^.upper - Adjustment^.page_size; NewPos := Adjustment^.upper - Adjustment^.page_size;
if h + DeltaX <= NewPos then if h - DeltaX <= NewPos then
NewPos := h + DeltaX; NewPos := h - DeltaX;
if gtk_adjustment_get_value(Adjustment) <> NewPos then if gtk_adjustment_get_value(Adjustment) <> NewPos then
begin begin
gtk_adjustment_set_value(Adjustment, NewPos); gtk_adjustment_set_value(Adjustment, NewPos);
@ -459,8 +458,8 @@ begin
begin begin
v := gtk_adjustment_get_value(Adjustment); v := gtk_adjustment_get_value(Adjustment);
NewPos := Adjustment^.upper - Adjustment^.page_size; NewPos := Adjustment^.upper - Adjustment^.page_size;
if v + DeltaY <= NewPos then if v - DeltaY <= NewPos then
NewPos := v + DeltaY; NewPos := v - DeltaY;
if gtk_adjustment_get_value(Adjustment) <> NewPos then if gtk_adjustment_get_value(Adjustment) <> NewPos then
begin begin
gtk_adjustment_set_value(Adjustment, NewPos); gtk_adjustment_set_value(Adjustment, NewPos);
@ -768,8 +767,8 @@ begin
begin begin
h := gtk_adjustment_get_value(Adjustment); h := gtk_adjustment_get_value(Adjustment);
NewPos := Adjustment^.upper - Adjustment^.page_size; NewPos := Adjustment^.upper - Adjustment^.page_size;
if h + DeltaX <= NewPos then if h - DeltaX <= NewPos then
NewPos := h + DeltaX; NewPos := h - DeltaX;
gtk_adjustment_set_value(Adjustment, NewPos); gtk_adjustment_set_value(Adjustment, NewPos);
end; end;
Adjustment := gtk_scrolled_window_get_vadjustment(Scrolled); Adjustment := gtk_scrolled_window_get_vadjustment(Scrolled);
@ -777,8 +776,8 @@ begin
begin begin
v := gtk_adjustment_get_value(Adjustment); v := gtk_adjustment_get_value(Adjustment);
NewPos := Adjustment^.upper - Adjustment^.page_size; NewPos := Adjustment^.upper - Adjustment^.page_size;
if v + DeltaY <= NewPos then if v - DeltaY <= NewPos then
NewPos := v + DeltaY; NewPos := v - DeltaY;
gtk_adjustment_set_value(Adjustment, NewPos); gtk_adjustment_set_value(Adjustment, NewPos);
end; end;
end; end;

View File

@ -616,7 +616,7 @@ begin
if not WSCheckHandleAllocated(AWinControl, 'ScrollBy') then if not WSCheckHandleAllocated(AWinControl, 'ScrollBy') then
Exit; Exit;
Widget := TQtCustomControl(AWinControl.Handle); Widget := TQtCustomControl(AWinControl.Handle);
Widget.viewport.scroll(-DeltaX, -DeltaY); Widget.viewport.scroll(DeltaX, DeltaY);
end; end;
{ TQtWSCustomFrame } { TQtWSCustomFrame }
@ -629,7 +629,7 @@ begin
if not WSCheckHandleAllocated(AWinControl, 'ScrollBy') then if not WSCheckHandleAllocated(AWinControl, 'ScrollBy') then
Exit; Exit;
Widget := TQtCustomControl(AWinControl.Handle); Widget := TQtCustomControl(AWinControl.Handle);
Widget.viewport.scroll(-DeltaX, -DeltaY); Widget.viewport.scroll(DeltaX, DeltaY);
end; end;
end. end.

View File

@ -224,12 +224,9 @@ function ScrollWindowPtr(hWnd:HWND; XAmount:longint; YAmount:longint; lpRect: po
class procedure TWin32WSScrollingWinControl.ScrollBy(const AWinControl: TScrollingWinControl; class procedure TWin32WSScrollingWinControl.ScrollBy(const AWinControl: TScrollingWinControl;
const DeltaX, DeltaY: integer); const DeltaX, DeltaY: integer);
var
lVisible: boolean;
begin begin
lVisible := AWinControl.HandleAllocated and Windows.IsWindowVisible(AWinControl.Handle); if Windows.IsWindowVisible(AWinControl.Handle) then
if lVisible then ScrollWindowPtr(AWinControl.Handle, DeltaX, DeltaY, nil, nil);
ScrollWindowPtr(AWinControl.Handle, -DeltaX, -DeltaY, nil, nil);
end; end;
{ TWin32WSCustomForm } { TWin32WSCustomForm }

View File

@ -158,21 +158,19 @@ end;
class procedure TWinCEWSScrollingWinControl.ScrollBy(const AWinControl: TScrollingWinControl; class procedure TWinCEWSScrollingWinControl.ScrollBy(const AWinControl: TScrollingWinControl;
const DeltaX, DeltaY: integer); const DeltaX, DeltaY: integer);
var var
lVisible: boolean; rgn: HRGN;
rgn : HRGN; rect: trect;
rect : trect;
begin begin
lVisible := AWinControl.HandleAllocated and Windows.IsWindowVisible(AWinControl.Handle); rgn := 0; //roozbeh : seems to be ok?
rgn := 0; //roozbeh : seems to be ok? // GetClipRgn(AWinControl.Handle,rgn);
// GetClipRgn(AWinControl.Handle,rgn); // roozbeh:which flags really are required?!
// roozbeh:which flags really are required?! if Windows.IsWindowVisible(AWinControl.Handle) then
if lVisible then {$ifdef win32}
{$ifdef win32} ScrollWindowPtr(AWinControl.Handle, DeltaX, DeltaY, nil, nil);
ScrollWindowPtr(AWinControl.Handle, -DeltaX, -DeltaY, nil, nil); {$else}
{$else} ScrollWindowPtr(AWinControl.Handle, DeltaX, DeltaY, nil, nil,
ScrollWindowPtr(AWinControl.Handle, -DeltaX, -DeltaY, nil, nil, rgn, nil, SW_INVALIDATE or SW_ERASE or SW_SCROLLCHILDREN);
rgn, nil, SW_INVALIDATE or SW_ERASE or SW_SCROLLCHILDREN); {$endif}
{$endif}
end; end;
{ TWinCEWSCustomForm } { TWinCEWSCustomForm }