customdrawnws-win32: Fixes WM_MOVE, WM_SIZE and form closing

git-svn-id: trunk@33759 -
This commit is contained in:
sekelsenmat 2011-11-24 14:37:46 +00:00
parent e900ce2ba7
commit 46c5039ee7
8 changed files with 97 additions and 53 deletions

View File

@ -236,6 +236,7 @@ begin
begin begin
Windows.TranslateMessage(@AMessage); Windows.TranslateMessage(@AMessage);
Windows.DispatchMessage(@AMessage); Windows.DispatchMessage(@AMessage);
if Application.Terminated then Break;
end; end;
end; end;

View File

@ -2508,12 +2508,14 @@ end;*)
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCDWidgetSet.GetClientBounds(handle : HWND; var ARect : TRect) : Boolean; function TCDWidgetSet.GetClientBounds(handle : HWND; var ARect : TRect) : Boolean;
begin begin
{$ifdef VerboseWinAPI}
WriteLn('[WinAPI GetClientBounds]');
{$endif}
// ToDO check if the window is native or not and process accordingly // ToDO check if the window is native or not and process accordingly
// For now just assume it is native // For now just assume it is native
Result := BackendGetClientBounds(Handle, ARect); Result := BackendGetClientBounds(Handle, ARect);
{$ifdef VerboseWinAPI}
DebugLn(Format('[WinAPI GetClientBounds] ARect.Left=%d ARect.Top=%d'
+ ' ARect.Right=%d ARect.Bottom=%d',
[ARect.Left, ARect.Top, ARect.Right, ARect.Bottom]));
{$endif}
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -2525,13 +2527,13 @@ end;
Returns the client bounds of a control. The client bounds is the rectangle of Returns the client bounds of a control. The client bounds is the rectangle of
the inner area of a control, where the child controls are visible. The the inner area of a control, where the child controls are visible. The
coordinates are relative to the control's left and top. coordinates are relative to the control's left and top.
Left and Top are always 0,0
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCDWidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean; function TCDWidgetSet.GetClientRect(handle : HWND; var ARect : TRect) : Boolean;
begin begin
{$ifdef VerboseWinAPI} {$ifdef VerboseWinAPI}
WriteLn('[WinAPI GetClientRect]'); DebugLn('[WinAPI GetClientRect]');
{$endif} {$endif}
GetClientBounds(Handle, ARect); GetClientBounds(Handle, ARect);
OffsetRect(ARect, -ARect.Left, -ARect.Top); OffsetRect(ARect, -ARect.Left, -ARect.Top);

View File

@ -501,18 +501,18 @@ begin
Result:=HWND(NSObject(Handle).lclParent) Result:=HWND(NSObject(Handle).lclParent)
else else
Result:=0; Result:=0;
end; end;*)
function TCocoaWidgetSet.GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; function TCDWidgetSet.GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean;
begin begin
if Handle<>0 then begin if Handle<>0 then begin
Result:=True; Result:=True;
NSObject(handle).lclRelativePos(Left, Top); LCLObjectExtension(NSObject(handle)).lclRelativePos(Left, Top);
end else end else
Result:=False; Result:=False;
end; end;
function TCocoaWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; (*function TCocoaWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean;
var var
r : TRect; r : TRect;
begin begin

View File

@ -2204,7 +2204,7 @@ end;
function TWin32WidgetSet.GetWindowRect(Handle: HWND; Var Rect: TRect): Integer; function TWin32WidgetSet.GetWindowRect(Handle: HWND; Var Rect: TRect): Integer;
begin begin
Result := Integer(Windows.GetWindowRect(Handle, @Rect)); Result := Integer(Windows.GetWindowRect(Handle, @Rect));
end; end;*)
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: GetWindowRelativePosition Function: GetWindowRelativePosition
@ -2214,7 +2214,7 @@ end;
returns the current widget Left, Top, relative to the client origin of its returns the current widget Left, Top, relative to the client origin of its
parent parent
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TWin32WidgetSet.GetWindowRelativePosition(Handle: HWND; function TCDWidgetSet.GetWindowRelativePosition(Handle: HWND;
var Left, Top: Integer): Boolean; var Left, Top: Integer): Boolean;
var var
LeftTop:TPoint; LeftTop:TPoint;
@ -2247,7 +2247,7 @@ begin
Left := LeftTop.X; Left := LeftTop.X;
Top := LeftTop.Y; Top := LeftTop.Y;
Result := True; Result := True;
end;*) end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: GetWindowSize Function: GetWindowSize
@ -2282,12 +2282,20 @@ begin
Result := Boolean(Windows.GetWindowPlacement(Handle, WP)); Result := Boolean(Windows.GetWindowPlacement(Handle, WP));
if not Result then if not Result then
begin
{$ifdef VerboseWinAPI}
DebugLn(':<[TCDWidgetSet.GetWindowSize] GetWindowPlacement failed');
{$endif}
Exit; Exit;
end;
if (WP.showCmd = SW_MINIMIZE) or (WP.showCmd = SW_SHOWMINIMIZED) then if (WP.showCmd = SW_MINIMIZE) or (WP.showCmd = SW_SHOWMINIMIZED) then
begin begin
Width := 0; Width := 0;
Height := 0; Height := 0;
{$ifdef VerboseWinAPI}
DebugLn(':<[TCDWidgetSet.GetWindowSize] Minimized');
{$endif}
Exit; Exit;
end; end;

View File

@ -4294,7 +4294,7 @@ begin
ARect := Bounds(APos.X,APos.Y,R.Right-R.Left,R.Bottom-R.Top); ARect := Bounds(APos.X,APos.Y,R.Right-R.Left,R.Bottom-R.Top);
Result := -1; Result := -1;
end; end;*)
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: GetWindowRelativePosition Function: GetWindowRelativePosition
@ -4304,20 +4304,20 @@ end;
returns the current widget Left, Top, relative to the client origin of its returns the current widget Left, Top, relative to the client origin of its
parent parent
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TQtWidgetSet.GetWindowRelativePosition(Handle: HWND; var Left, Top: integer): boolean; function TCDWidgetSet.GetWindowRelativePosition(Handle: HWND; var Left, Top: integer): boolean;
var var
R: TRect; R: TRect;
begin begin
{$ifdef VerboseQtWinAPI} {$ifdef VerboseWinAPI}
WriteLn('[WinAPI GetWindowRelativePosition]'); WriteLn('[WinAPI GetWindowRelativePosition]');
{$endif} {$endif}
if Handle = 0 then { if Handle = 0 then}
Exit(False); Exit(False);
R := TQtWidget(Handle).getFrameGeometry; { R := TQtWidget(Handle).getFrameGeometry;
Left := R.Left; Left := R.Left;
Top := R.Top; Top := R.Top;
Result := True; Result := True;}
end;*) end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
Function: GetWindowSize Function: GetWindowSize

View File

@ -138,8 +138,8 @@ function GetViewPortOrgEx(DC: HDC; P: PPoint): Integer; override;
function GetWindowExtEx(DC: HDC; Size: PSize): Integer; override; function GetWindowExtEx(DC: HDC; Size: PSize): Integer; override;
function GetWindowLong(Handle : hwnd; int: Integer): PtrInt; override; function GetWindowLong(Handle : hwnd; int: Integer): PtrInt; override;
function GetWindowOrgEx(dc : hdc; P : PPoint): Integer; override; function GetWindowOrgEx(dc : hdc; P : PPoint): Integer; override;
function GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; override; function GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; override;*)
function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;*) function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;
function GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; override; function GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; override;
(*function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint; (*function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint;
Meshes: Pointer; NumMeshes : Longint; Mode : Longint): Boolean; override; Meshes: Pointer; NumMeshes : Longint; Mode : Longint): Boolean; override;

View File

@ -563,9 +563,12 @@ end;
class function TCDWSCustomForm.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean; class function TCDWSCustomForm.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
begin begin
{$ifdef VerboseCDForms}
DebugLn(':>[TCDWSCustomForm.GetClientBounds]');
{$endif}
Result := LCLIntf.GetClientBounds(AWincontrol.Handle, ARect); Result := LCLIntf.GetClientBounds(AWincontrol.Handle, ARect);
{$ifdef VerboseCDForms} {$ifdef VerboseCDForms}
DebugLn(Format('[TCDWSCustomForm.GetClientBounds] AWincontrol=%x Rect.left=%d Rect.Top=%d' DebugLn(Format(':<[TCDWSCustomForm.GetClientBounds] AWincontrol=%x Rect.left=%d Rect.Top=%d'
+ ' Rect.Width=%d Rect.Height=%d', [PtrInt(AWincontrol), ARect.Top, ARect.Left, + ' Rect.Width=%d Rect.Height=%d', [PtrInt(AWincontrol), ARect.Top, ARect.Left,
ARect.Right-ARect.Left, ARect.Bottom-ARect.Top])); ARect.Right-ARect.Left, ARect.Bottom-ARect.Top]));
{$endif} {$endif}
@ -573,6 +576,9 @@ end;
class function TCDWSCustomForm.GetClientRect(const AWincontrol: TWinControl; var ARect: TRect): Boolean; class function TCDWSCustomForm.GetClientRect(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
begin begin
{$ifdef VerboseCDForms}
DebugLn('[TCDWSCustomForm.GetClientRect]');
{$endif}
Result := LCLIntf.GetClientRect(AWincontrol.Handle, ARect); Result := LCLIntf.GetClientRect(AWincontrol.Handle, ARect);
end; end;

View File

@ -161,6 +161,7 @@ Var
TargetObject: TObject; TargetObject: TObject;
WinProcess: Boolean; WinProcess: Boolean;
NotifyUserInput: Boolean; NotifyUserInput: Boolean;
WindowPlacement: TWINDOWPLACEMENT;
OverlayWindow: HWND; OverlayWindow: HWND;
TargetWindow: HWND; TargetWindow: HWND;
eraseBkgndCommand: TEraseBkgndCommand; eraseBkgndCommand: TEraseBkgndCommand;
@ -249,6 +250,12 @@ Var
WindowInfo^.Bitmap := Windows.CreateCompatibleBitmap(DC, WindowWidth, WindowHeight); WindowInfo^.Bitmap := Windows.CreateCompatibleBitmap(DC, WindowWidth, WindowHeight);
WindowInfo^.DCBitmapOld := Windows.SelectObject(WindowInfo^.BitmapDC, WindowInfo^.Bitmap); WindowInfo^.DCBitmapOld := Windows.SelectObject(WindowInfo^.BitmapDC, WindowInfo^.Bitmap);
Windows.ReleaseDC(0, DC); Windows.ReleaseDC(0, DC);
// Reset the image and canvas
WindowInfo^.Canvas.Free;
WindowInfo^.Canvas := nil;
WindowInfo^.Image.Free;
WindowInfo^.Image := nil;
end; end;
// Prepare the non-native Canvas if necessary // Prepare the non-native Canvas if necessary
@ -1193,71 +1200,91 @@ begin
Msg := LM_MOVE; Msg := LM_MOVE;
// MoveType := WParam; WParam is not defined! // MoveType := WParam; WParam is not defined!
MoveType := Move_SourceIsInterface; MoveType := Move_SourceIsInterface;
if (lWinControl is TCustomForm) if GetWindowLong(Window, GWL_STYLE) and WS_CHILD = 0 then
and (TCustomForm(lWinControl).Parent=nil) then
begin begin
if Windows.GetWindowRect(Window,@R) then WindowPlacement.length := SizeOf(WindowPlacement);
if IsIconic(Window) and GetWindowPlacement(Window, @WindowPlacement) then
begin
with WindowPlacement.rcNormalPosition do
begin
XPos := Left;
YPos := Top;
end;
end
else
if Windows.GetWindowRect(Window, @R) then
begin begin
XPos := R.Left; XPos := R.Left;
YPos := R.Top; YPos := R.Top;
end else begin end
else
Msg := LM_NULL; Msg := LM_NULL;
end; end else
end else begin begin
if GetWindowRelativePosition(Window,NewLeft,NewTop) then if GetWindowRelativePosition(Window, NewLeft, NewTop) then
begin begin
XPos := NewLeft; XPos := NewLeft;
YPos := NewTop; YPos := NewTop;
end else begin end
else
Msg := LM_NULL; Msg := LM_NULL;
end;
end; end;
if lWinControl <> nil then begin if lWinControl <> nil then
begin
{$IFDEF VerboseSizeMsg} {$IFDEF VerboseSizeMsg}
DebugLn('WinCECallBack WM_MOVE ', dbgsName(lWinControl), DebugLn('Win32CallBack WM_MOVE ', dbgsName(lWinControl),
' NewPos=',dbgs(XPos),',',dbgs(YPos)); ' NewPos=',dbgs(XPos),',',dbgs(YPos));
{$ENDIF} {$ENDIF}
if (lWinControl.Left=XPos) and (lWinControl.Top=YPos) then if (lWinControl.Left = XPos) and (lWinControl.Top = YPos) then
exit; Exit;
end; end;
end; end;
end; end;
WM_SIZE: WM_SIZE:
begin begin
with TLMSize(LMessage) Do with TLMSize(LMessage) do
begin begin
Msg := LM_SIZE; Msg := LM_SIZE;
SizeType := WParam or Size_SourceIsInterface; SizeType := WParam or Size_SourceIsInterface;
if Window = TCDWidgetSet(WidgetSet).AppHandle then if Window = CDWidgetSet.AppHandle then
begin begin
lWinControl := Application.MainForm; if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then
Window := Application.MainForm.Handle; begin
lWinControl := Application.MainForm;
Window := Application.MainFormHandle;
end;
end; end;
GetWindowSize(Window, NewWidth, NewHeight); GetWindowSize(Window, NewWidth, NewHeight);
Width := NewWidth; Width := NewWidth;
Height := NewHeight; Height := NewHeight;
if lWinControl <> nil then if Assigned(lWinControl) then
begin begin
{$IFDEF VerboseSizeMsg} {$IFDEF VerboseSizeMsg}
GetClientRect(Window,R); GetClientRect(Window,R);
DebugLn('WinCECallback: WM_SIZE '+ dbgsName(lWinControl)+ DebugLn('Win32Callback: WM_SIZE '+ dbgsName(lWinControl)+
' NewSize='+ dbgs(Width)+','+dbgs(Height)+ ' NewSize=', dbgs(Width)+','+dbgs(Height)+
' HasVScroll='+dbgs((GetWindowLong(Window, GWL_STYLE) and WS_VSCROLL) <> 0)+
' HasHScroll='+dbgs((GetWindowLong(Window, GWL_STYLE) and WS_HSCROLL) <> 0)+
' OldClientSize='+dbgs(lWinControl.CachedClientWidth)+','+dbgs(lWinControl.CachedClientHeight)+ ' OldClientSize='+dbgs(lWinControl.CachedClientWidth)+','+dbgs(lWinControl.CachedClientHeight)+
' NewClientSize='+dbgs(R.Right)+','+dbgs(R.Bottom)); ' NewClientSize='+dbgs(R.Right)+','+dbgs(R.Bottom));
{$ENDIF} {$ENDIF}
if (lWinControl.Width<>Width) or (lWinControl.Height<>Height) if (lWinControl.Width <> Width) or
or lWinControl.ClientRectNeedsInterfaceUpdate then (lWinControl.Height <> Height) or
begin lWinControl.ClientRectNeedsInterfaceUpdate then
lWinControl.DoAdjustClientRectChange; lWinControl.DoAdjustClientRectChange
end; else
// If we get form size message then we probably changed it state
// (minimized/maximized -> normal). Form adjust its clientrect in the
// second WM_SIZE but WM_MOVE also updates clientrect without adjustment
// thus we need to call DoAdjustClientRectChange. It is safe since this
// methods checks whether it need to adjust something really.
if (lWinControl is TCustomForm) and (lWinControl.Parent = nil) and
(WParam = Size_Restored) then
lWinControl.DoAdjustClientRectChange(False);
end; end;
OverlayWindow := GetWindowInfo(Window)^.Overlay;
if OverlayWindow <> 0 then
Windows.SetWindowPos(OverlayWindow, HWND_TOP, 0, 0, NewWidth, NewHeight, SWP_NOMOVE);
end; end;
end; end;
//roozbeh : do not have these on ce!
{WM_ENDSESSION: {WM_ENDSESSION:
begin begin
if (Application<>nil) and (TWinCEWidgetSet(WidgetSet).AppHandle=Window) and if (Application<>nil) and (TWinCEWidgetSet(WidgetSet).AppHandle=Window) and
@ -1267,9 +1294,9 @@ begin
Application.IntfEndSession(); Application.IntfEndSession();
LMessage.Result := 0; LMessage.Result := 0;
end; end;
end; end;}
WM_QUERYENDSESSION: {WM_QUERYENDSESSION:
begin begin
if (Application<>nil) and (TWinCEWidgetSet(WidgetSet).AppHandle=Window) and if (Application<>nil) and (TWinCEWidgetSet(WidgetSet).AppHandle=Window) and
(LParam=0) then (LParam=0) then