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
Windows.TranslateMessage(@AMessage);
Windows.DispatchMessage(@AMessage);
if Application.Terminated then Break;
end;
end;

View File

@ -2508,12 +2508,14 @@ end;*)
------------------------------------------------------------------------------}
function TCDWidgetSet.GetClientBounds(handle : HWND; var ARect : TRect) : Boolean;
begin
{$ifdef VerboseWinAPI}
WriteLn('[WinAPI GetClientBounds]');
{$endif}
// ToDO check if the window is native or not and process accordingly
// For now just assume it is native
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;
{------------------------------------------------------------------------------
@ -2525,13 +2527,13 @@ end;
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
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;
begin
{$ifdef VerboseWinAPI}
WriteLn('[WinAPI GetClientRect]');
DebugLn('[WinAPI GetClientRect]');
{$endif}
GetClientBounds(Handle, ARect);
OffsetRect(ARect, -ARect.Left, -ARect.Top);

View File

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

View File

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

View File

@ -4294,7 +4294,7 @@ begin
ARect := Bounds(APos.X,APos.Y,R.Right-R.Left,R.Bottom-R.Top);
Result := -1;
end;
end;*)
{------------------------------------------------------------------------------
Function: GetWindowRelativePosition
@ -4304,20 +4304,20 @@ end;
returns the current widget Left, Top, relative to the client origin of its
parent
------------------------------------------------------------------------------}
function TQtWidgetSet.GetWindowRelativePosition(Handle: HWND; var Left, Top: integer): boolean;
function TCDWidgetSet.GetWindowRelativePosition(Handle: HWND; var Left, Top: integer): boolean;
var
R: TRect;
begin
{$ifdef VerboseQtWinAPI}
{$ifdef VerboseWinAPI}
WriteLn('[WinAPI GetWindowRelativePosition]');
{$endif}
if Handle = 0 then
{ if Handle = 0 then}
Exit(False);
R := TQtWidget(Handle).getFrameGeometry;
{ R := TQtWidget(Handle).getFrameGeometry;
Left := R.Left;
Top := R.Top;
Result := True;
end;*)
Result := True;}
end;
{------------------------------------------------------------------------------
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 GetWindowLong(Handle : hwnd; int: Integer): PtrInt; override;
function GetWindowOrgEx(dc : hdc; P : PPoint): Integer; override;
function GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; override;
function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;*)
function GetWindowRect(Handle: hwnd; var ARect: TRect): Integer; override;*)
function GetWindowRelativePosition(Handle: hwnd; var Left, Top: Integer): boolean; override;
function GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean; override;
(*function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint;
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;
begin
{$ifdef VerboseCDForms}
DebugLn(':>[TCDWSCustomForm.GetClientBounds]');
{$endif}
Result := LCLIntf.GetClientBounds(AWincontrol.Handle, ARect);
{$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,
ARect.Right-ARect.Left, ARect.Bottom-ARect.Top]));
{$endif}
@ -573,6 +576,9 @@ end;
class function TCDWSCustomForm.GetClientRect(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
begin
{$ifdef VerboseCDForms}
DebugLn('[TCDWSCustomForm.GetClientRect]');
{$endif}
Result := LCLIntf.GetClientRect(AWincontrol.Handle, ARect);
end;

View File

@ -161,6 +161,7 @@ Var
TargetObject: TObject;
WinProcess: Boolean;
NotifyUserInput: Boolean;
WindowPlacement: TWINDOWPLACEMENT;
OverlayWindow: HWND;
TargetWindow: HWND;
eraseBkgndCommand: TEraseBkgndCommand;
@ -249,6 +250,12 @@ Var
WindowInfo^.Bitmap := Windows.CreateCompatibleBitmap(DC, WindowWidth, WindowHeight);
WindowInfo^.DCBitmapOld := Windows.SelectObject(WindowInfo^.BitmapDC, WindowInfo^.Bitmap);
Windows.ReleaseDC(0, DC);
// Reset the image and canvas
WindowInfo^.Canvas.Free;
WindowInfo^.Canvas := nil;
WindowInfo^.Image.Free;
WindowInfo^.Image := nil;
end;
// Prepare the non-native Canvas if necessary
@ -1193,71 +1200,91 @@ begin
Msg := LM_MOVE;
// MoveType := WParam; WParam is not defined!
MoveType := Move_SourceIsInterface;
if (lWinControl is TCustomForm)
and (TCustomForm(lWinControl).Parent=nil) then
if GetWindowLong(Window, GWL_STYLE) and WS_CHILD = 0 then
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
XPos := R.Left;
YPos := R.Top;
end else begin
end
else
Msg := LM_NULL;
end;
end else begin
if GetWindowRelativePosition(Window,NewLeft,NewTop) then
end else
begin
if GetWindowRelativePosition(Window, NewLeft, NewTop) then
begin
XPos := NewLeft;
YPos := NewTop;
end else begin
end
else
Msg := LM_NULL;
end;
end;
if lWinControl <> nil then begin
if lWinControl <> nil then
begin
{$IFDEF VerboseSizeMsg}
DebugLn('WinCECallBack WM_MOVE ', dbgsName(lWinControl),
DebugLn('Win32CallBack WM_MOVE ', dbgsName(lWinControl),
' NewPos=',dbgs(XPos),',',dbgs(YPos));
{$ENDIF}
if (lWinControl.Left=XPos) and (lWinControl.Top=YPos) then
exit;
if (lWinControl.Left = XPos) and (lWinControl.Top = YPos) then
Exit;
end;
end;
end;
WM_SIZE:
begin
with TLMSize(LMessage) Do
with TLMSize(LMessage) do
begin
Msg := LM_SIZE;
SizeType := WParam or Size_SourceIsInterface;
if Window = TCDWidgetSet(WidgetSet).AppHandle then
if Window = CDWidgetSet.AppHandle then
begin
lWinControl := Application.MainForm;
Window := Application.MainForm.Handle;
if Assigned(Application.MainForm) and Application.MainForm.HandleAllocated then
begin
lWinControl := Application.MainForm;
Window := Application.MainFormHandle;
end;
end;
GetWindowSize(Window, NewWidth, NewHeight);
Width := NewWidth;
Height := NewHeight;
if lWinControl <> nil then
if Assigned(lWinControl) then
begin
{$IFDEF VerboseSizeMsg}
GetClientRect(Window,R);
DebugLn('WinCECallback: WM_SIZE '+ dbgsName(lWinControl)+
' NewSize='+ dbgs(Width)+','+dbgs(Height)+
DebugLn('Win32Callback: WM_SIZE '+ dbgsName(lWinControl)+
' 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)+
' NewClientSize='+dbgs(R.Right)+','+dbgs(R.Bottom));
{$ENDIF}
if (lWinControl.Width<>Width) or (lWinControl.Height<>Height)
or lWinControl.ClientRectNeedsInterfaceUpdate then
begin
lWinControl.DoAdjustClientRectChange;
end;
if (lWinControl.Width <> Width) or
(lWinControl.Height <> Height) or
lWinControl.ClientRectNeedsInterfaceUpdate then
lWinControl.DoAdjustClientRectChange
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;
OverlayWindow := GetWindowInfo(Window)^.Overlay;
if OverlayWindow <> 0 then
Windows.SetWindowPos(OverlayWindow, HWND_TOP, 0, 0, NewWidth, NewHeight, SWP_NOMOVE);
end;
end;
//roozbeh : do not have these on ce!
{WM_ENDSESSION:
begin
if (Application<>nil) and (TWinCEWidgetSet(WidgetSet).AppHandle=Window) and
@ -1267,9 +1294,9 @@ begin
Application.IntfEndSession();
LMessage.Result := 0;
end;
end;
end;}
WM_QUERYENDSESSION:
{WM_QUERYENDSESSION:
begin
if (Application<>nil) and (TWinCEWidgetSet(WidgetSet).AppHandle=Window) and
(LParam=0) then