qt: redo sizing and positioning

git-svn-id: trunk@15143 -
This commit is contained in:
paul 2008-05-15 02:51:30 +00:00
parent ed0d3ad781
commit 25093a929a
3 changed files with 106 additions and 66 deletions

View File

@ -156,6 +156,7 @@ type
procedure ShowMaximized; procedure ShowMaximized;
function getActionByIndex(AIndex: Integer): QActionH; function getActionByIndex(AIndex: Integer): QActionH;
function getClientBounds: TRect; virtual; function getClientBounds: TRect; virtual;
function getClientOffset: TPoint;
function getEnabled: Boolean; function getEnabled: Boolean;
function getFocusPolicy: QtFocusPolicy; function getFocusPolicy: QtFocusPolicy;
function getFrameGeometry: TRect; function getFrameGeometry: TRect;
@ -402,6 +403,7 @@ type
TQtMainWindow = class(TQtWidget) TQtMainWindow = class(TQtWidget)
private private
LayoutWidget: QBoxLayoutH; LayoutWidget: QBoxLayoutH;
FCWEventHook: QObject_hookH;
protected protected
function CreateWidget(const AParams: TCreateParams):QWidgetH; override; function CreateWidget(const AParams: TCreateParams):QWidgetH; override;
public public
@ -411,7 +413,6 @@ type
ToolBar: TQtToolBar; ToolBar: TQtToolBar;
StatusBar: TQtStatusBar; StatusBar: TQtStatusBar;
destructor Destroy; override; destructor Destroy; override;
function getClientBounds: TRect; override;
function getText: WideString; override; function getText: WideString; override;
function getTextStatic: Boolean; override; function getTextStatic: Boolean; override;
procedure setText(const W: WideString); override; procedure setText(const W: WideString); override;
@ -421,6 +422,10 @@ type
procedure OffsetMousePos(APoint: PQtPoint); override; procedure OffsetMousePos(APoint: PQtPoint); override;
procedure SlotWindowStateChange; cdecl; procedure SlotWindowStateChange; cdecl;
procedure setShowInTaskBar(AValue: Boolean); procedure setShowInTaskBar(AValue: Boolean);
public
procedure AttachEvents; override;
procedure DetachEvents; override;
function CWEventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
end; end;
{ TQtHintWindow } { TQtHintWindow }
@ -1197,6 +1202,7 @@ begin
inherited Create; inherited Create;
FOwner := nil; FOwner := nil;
FCentralWidget := nil;
FOwnWidget := True; FOwnWidget := True;
// Initializes the properties // Initializes the properties
FProps := nil; FProps := nil;
@ -1215,6 +1221,7 @@ begin
FOwner := nil; FOwner := nil;
FOwnWidget := False; FOwnWidget := False;
FCentralWidget := nil;
// Initializes the properties // Initializes the properties
FProps := niL; FProps := niL;
LCLObject := AWinControl; LCLObject := AWinControl;
@ -2210,8 +2217,8 @@ begin
Msg.PaintStruct^.hdc := FContext; Msg.PaintStruct^.hdc := FContext;
with getClientBounds do with getClientOffset do
SetWindowOrgEx(Msg.DC, -Left, -Top, nil); SetWindowOrgEx(Msg.DC, -X, -Y, nil);
// send paint message // send paint message
try try
@ -2344,10 +2351,10 @@ end;
procedure TQtWidget.OffsetMousePos(APoint: PQtPoint); procedure TQtWidget.OffsetMousePos(APoint: PQtPoint);
begin begin
with getClientBounds do with getClientOffset do
begin begin
dec(APoint^.x, Left); dec(APoint^.x, x);
dec(APoint^.y, Top); dec(APoint^.y, y);
end; end;
end; end;
@ -2546,7 +2553,17 @@ end;
function TQtWidget.getClientBounds: TRect; function TQtWidget.getClientBounds: TRect;
begin begin
QWidget_contentsRect(Widget, @Result); QWidget_contentsRect(getContainerWidget, @Result);
end;
function TQtWidget.getClientOffset: TPoint;
var
P: TQtPoint;
R: TRect;
begin
QWidget_pos(GetContainerWidget, @P);
R := getClientBounds;
Result := Point(P.x + R.Left, P.y + R.Top);
end; end;
procedure TQtWidget.grabMouse; procedure TQtWidget.grabMouse;
@ -3649,20 +3666,6 @@ begin
inherited Destroy; inherited Destroy;
end; end;
function TQtMainWindow.getClientBounds: TRect;
var
R: TRect;
begin
Result := inherited getClientBounds;
if (MenuBar <> nil) and (MenuBar.getVisible) and
not (TCustomForm(LCLObject).FormStyle in [fsMDIForm, fsMDIChild]) then
begin
R := MenuBar.getGeometry;
if TCustomForm(LCLObject).FormStyle <> fsMDIChild then
inc(Result.Top, R.Bottom - R.Top);
end;
end;
function TQtMainWindow.getText: WideString; function TQtMainWindow.getText: WideString;
begin begin
WindowTitle(@Result); WindowTitle(@Result);
@ -3779,6 +3782,46 @@ begin
end; end;
end; end;
procedure TQtMainWindow.AttachEvents;
var
Method: TMethod;
begin
inherited AttachEvents;
if FCentralWidget <> nil then
begin
FCWEventHook := QObject_hook_create(FCentralWidget);
TEventFilterMethod(Method) := @CWEventFilter;
QObject_hook_hook_events(FCWEventHook, Method);
end;
end;
procedure TQtMainWindow.DetachEvents;
begin
if FCWEventHook <> nil then
begin
QObject_hook_destroy(FCWEventHook);
FCWEventHook := nil;
end;
inherited DetachEvents;
end;
function TQtMainWindow.CWEventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
Result := False;
if LCLObject <> nil then
begin
case QEvent_type(Event) of
QEventResize:
begin
LCLObject.InvalidateClientRectCache(true);
LCLObject.DoAdjustClientRectChange;
end;
end;
end;
end;
{ TQtStaticText } { TQtStaticText }
function TQtStaticText.CreateWidget(const AParams: TCreateParams): QWidgetH; function TQtStaticText.CreateWidget(const AParams: TCreateParams): QWidgetH;
@ -7389,7 +7432,10 @@ end;
function TQtAbstractScrollArea.GetContainerWidget: QWidgetH; function TQtAbstractScrollArea.GetContainerWidget: QWidgetH;
begin begin
Result := viewport.Widget; if ClassType = TQtAbstractScrollArea then
Result := viewport.Widget
else
Result := Widget;
end; end;
function TQtAbstractScrollArea.getClientBounds: TRect; function TQtAbstractScrollArea.getClientBounds: TRect;
@ -8188,8 +8234,8 @@ begin
Msg.PaintStruct^.hdc := FDesignContext; Msg.PaintStruct^.hdc := FDesignContext;
with getClientBounds do with getClientOffset do
SetWindowOrgEx(Msg.DC, -Left, -Top, nil); SetWindowOrgEx(Msg.DC, -X, -Y, nil);
// send paint message // send paint message
try try

View File

@ -148,20 +148,14 @@ end;
function TQtWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint) : Boolean; function TQtWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint) : Boolean;
var var
APoint: TQtPoint; APoint: TQtPoint;
R: TRect;
begin begin
Result := True; Result := Handle <> 0;
if Handle <> 0 then if Result then
begin begin
APoint.x := P.X; APoint := QtPoint(P.X, P.Y);
APoint.y := P.Y;
QWidget_mapToGlobal(TQtWidget(Handle).Widget, @APoint, @APoint); QWidget_mapToGlobal(TQtWidget(Handle).GetContainerWidget, @APoint, @APoint);
P.X := APoint.x; P := Point(APoint.x, APoint.y);
P.Y := APoint.y;
R := TQtWidget(Handle).getClientBounds;
inc(P.X, R.Left);
inc(P.Y, R.Top);
end; end;
end; end;
@ -1806,7 +1800,6 @@ begin
{$endif} {$endif}
ARect := TQtWidget(handle).getClientBounds; ARect := TQtWidget(handle).getClientBounds;
Result := True; Result := True;
end; end;
@ -1826,9 +1819,8 @@ begin
WriteLn('[WinAPI GetClientRect]'); WriteLn('[WinAPI GetClientRect]');
{$endif} {$endif}
ARect := TQtWidget(handle).getClientBounds; GetClientBounds(Handle, ARect);
OffsetRect(ARect, -ARect.Left, -ARect.Top); OffsetRect(ARect, -ARect.Left, -ARect.Top);
//WriteLn('ClientRect: ', dbgsName(TQtWidget(handle).LCLObject), ' Width = ', ARect.Right, ' Height = ', ARect.Bottom);
Result := True; Result := True;
end; end;
@ -3102,6 +3094,7 @@ function TQtWidgetSet.GetWindowRect(Handle: HWND; var ARect: TRect): Integer;
var var
APos: TQtPoint; APos: TQtPoint;
AParent: QWidgetH; AParent: QWidgetH;
R1: TRect;
begin begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetWindowRect]'); WriteLn('[WinAPI GetWindowRect]');
@ -3122,10 +3115,15 @@ begin
if AParent <> nil then if AParent <> nil then
QWidget_mapToGlobal(AParent, @APos, @APos); QWidget_mapToGlobal(AParent, @APos, @APos);
R1 := TQtWidget(Handle).getFrameGeometry;
ARect.Left := APos.x; ARect.Left := APos.x;
ARect.Top := APos.y; ARect.Top := APos.y;
ARect.Bottom := ARect.Top + TQtWidget(Handle).getHeight; with R1 do
ARect.Right := ARect.Left + TQtWidget(Handle).getWidth; begin
ARect.Right := ARect.Left + (Right - Left);
ARect.Bottom := ARect.Top + (Bottom - Top);
end;
Result := -1; Result := -1;
end; end;
@ -3165,10 +3163,11 @@ begin
WriteLn('[WinAPI GetWindowSize]'); WriteLn('[WinAPI GetWindowSize]');
{$endif} {$endif}
Result := False; with TQtWidget(Handle).getSize do
begin
Height := TQtWidget(Handle).getHeight; Height := cy;
Width := TQtWidget(Handle).getWidth; Width := cx;
end;
Result := True; Result := True;
@ -3446,8 +3445,6 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TQtWidgetSet.InvalidateRect(aHandle: HWND; Rect: pRect; bErase: Boolean): Boolean; function TQtWidgetSet.InvalidateRect(aHandle: HWND; Rect: pRect; bErase: Boolean): Boolean;
var
R: TRect;
begin begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI Invalidate Rect]'); WriteLn('[WinAPI Invalidate Rect]');
@ -3455,8 +3452,8 @@ begin
if Rect <> nil then if Rect <> nil then
begin begin
R := TQtWidget(aHandle).getClientBounds; with TQtWidget(aHandle).getClientOffset do
OffsetRect(Rect^, R.Left, R.Top); OffsetRect(Rect^, x, y);
// no need to handle bErase. Qt automatically erase rect on paint event according to docs // no need to handle bErase. Qt automatically erase rect on paint event according to docs
TQtWidget(aHandle).Update(Rect); TQtWidget(aHandle).Update(Rect);
end else end else
@ -3822,19 +3819,13 @@ end;
function TQtWidgetSet.ScreenToClient(Handle : HWND; var P : TPoint) : Integer; function TQtWidgetSet.ScreenToClient(Handle : HWND; var P : TPoint) : Integer;
var var
APoint: TQtPoint; APoint: TQtPoint;
R: TRect;
begin begin
Result := 0; Result := 0;
if Handle <> 0 then if Handle <> 0 then
begin begin
APoint.x := P.X; APoint := QtPoint(P.X, P.Y);
APoint.y := P.Y; QWidget_mapFromGlobal(TQtWidget(Handle).GetContainerWidget, @APoint, @APoint);
QWidget_mapFromGlobal(TQtWidget(Handle).Widget, @APoint, @APoint); P := Point(APoint.x, APoint.y);
P.X := APoint.x;
P.Y := APoint.y;
R := TQtWidget(Handle).getClientBounds;
dec(P.X, R.Left);
dec(P.Y, R.Top);
Result := 1; Result := 1;
end; end;
end; end;
@ -4687,8 +4678,7 @@ var
Widget: QWidgetH; Widget: QWidgetH;
APoint: TQtPoint; APoint: TQtPoint;
begin begin
APoint.x := Point.x; APoint := QtPoint(Point.x, Point.y);
APoint.y := Point.y;
Widget := QApplication_widgetAt(@APoint); Widget := QApplication_widgetAt(@APoint);
if Widget <> nil then if Widget <> nil then
begin begin

View File

@ -416,23 +416,27 @@ class procedure TQtWSWinControl.PaintTo(const AWinControl: TWinControl;
ADC: HDC; X, Y: Integer); ADC: HDC; X, Y: Integer);
var var
Context: TQtDeviceContext absolute ADC; Context: TQtDeviceContext absolute ADC;
Widget: TQtWidget;
Pixmap: TQtPixmap; Pixmap: TQtPixmap;
DCSize: TSize; DCSize: TSize;
APoint: TQtPoint; APoint: TQtPoint;
ARect: TRect; ARect, GRect: TRect;
begin begin
if not WSCheckHandleAllocated(AWincontrol, 'PaintTo') or (ADC = 0) then if not WSCheckHandleAllocated(AWincontrol, 'PaintTo') or (ADC = 0) then
Exit; Exit;
with DCSize, TQtWidget(AWinControl.Handle) do Widget := TQtWidget(AWinControl.Handle);
ARect := Widget.getFrameGeometry;
GRect := Widget.getGeometry;
with DCSize, ARect do
begin begin
cx := getWidth; cx := Right - Left;
cy := getHeight; cy := Bottom - Top;
end; end;
Pixmap := TQtPixmap.Create(@DCSize); Pixmap := TQtPixmap.Create(@DCSize);
Pixmap.grabWidget(TQtWidget(AWinControl.Handle).Widget, 0, 0); OffsetRect(GRect, -ARect.Left, -ARect.Top);
APoint.x := X; Pixmap.grabWidget(Widget.Widget, 0, 0);
APoint.Y := Y; APoint := QtPoint(X + GRect.Left, Y + GRect.Top);
ARect := Rect(0, 0, Pixmap.getWidth, Pixmap.getHeight); ARect := Rect(0, 0, Pixmap.getWidth, Pixmap.getHeight);
Context.drawPixmap(@APoint, Pixmap.Handle, @ARect); Context.drawPixmap(@APoint, Pixmap.Handle, @ARect);
Pixmap.Free; Pixmap.Free;