Carbon intf: finally fixed 0009921: Carbon ClientToScreen does not agree with GetCursorPos, caused by wrong window resizing and client rect updating

git-svn-id: trunk@13091 -
This commit is contained in:
tombo 2007-11-30 20:32:20 +00:00
parent 08608057d5
commit 5f40a1f362
4 changed files with 65 additions and 23 deletions

View File

@ -65,6 +65,7 @@ type
FProperties: TStringList;
FCursor: HCURSOR;
FHasCaret: Boolean;
FResizing: Boolean;
function GetPainting: Boolean;
function GetProperty(AIndex: String): Pointer;
procedure SetProperty(AIndex: String; const AValue: Pointer);
@ -126,6 +127,7 @@ type
property HasCaret: Boolean read FHasCaret write FHasCaret;
property Painting: Boolean read GetPainting;
property Properties[AIndex: String]: Pointer read GetProperty write SetProperty;
property Resizing: Boolean read FResizing write FResizing;
end;
type
@ -422,8 +424,10 @@ var
WidgetClient,
{$ENDIF}
WidgetBounds, OldBounds: TRect;
Resized, ClientResized: Boolean;
Resized, ClientResized, Moved: Boolean;
PosMsg: TLMWindowPosChanged;
begin
if FResizing then Exit;
{$IFDEF VerboseBounds}
DebugLn('TCarbonWidget.BoundsChanged ' + LCLObject.Name);
{$ENDIF}
@ -439,20 +443,38 @@ begin
DebugLn('TCarbonWidget.BoundsChanged LCL old client: ' + DbgS(LCLObject.ClientRect));
{$ENDIF}
Resized := False;
Resized :=
(OldBounds.Right - OldBounds.Left <> WidgetBounds.Right - WidgetBounds.Left) or
(OldBounds.Bottom - OldBounds.Top <> WidgetBounds.Bottom - WidgetBounds.Top);
Moved :=
(OldBounds.Left <> WidgetBounds.Left) or
(OldBounds.Top <> WidgetBounds.Top);
ClientResized := False;
// then send a LM_SIZE message
if (OldBounds.Right - OldBounds.Left <> WidgetBounds.Right - WidgetBounds.Left) or
(OldBounds.Bottom - OldBounds.Top <> WidgetBounds.Bottom - WidgetBounds.Top) then
// send window pos changed
if Resized or Moved then
begin
LCLSendSizeMsg(LCLObject, WidgetBounds.Right - WidgetBounds.Left,
WidgetBounds.Bottom - WidgetBounds.Top, Size_SourceIsInterface);
Resized := True;
PosMsg.Msg := LM_WINDOWPOSCHANGED;
PosMsg.Result := 0;
New(PosMsg.WindowPos);
try
with PosMsg.WindowPos^ do
begin
hWndInsertAfter := 0;
x := WidgetBounds.Left;
y := WidgetBounds.Right;
cx := WidgetBounds.Right - WidgetBounds.Left;
cy := WidgetBounds.Bottom - WidgetBounds.Top;
flags := 0;
end;
DeliverMessage(LCLObject, PosMsg);
finally
Dispose(PosMsg.WindowPos);
end;
end;
if Resized or LCLObject.ClientRectNeedsInterfaceUpdate then
// update client rect
//if Resized or LCLObject.ClientRectNeedsInterfaceUpdate then
begin
{$IFDEF VerboseBounds}
DebugLn('TCarbonWidget.BoundsChanged Update client rects cache');
@ -461,10 +483,16 @@ begin
LCLObject.DoAdjustClientRectChange;
ClientResized := True;
end;
// then send a LM_SIZE message
if Resized then
begin
LCLSendSizeMsg(LCLObject, WidgetBounds.Right - WidgetBounds.Left,
WidgetBounds.Bottom - WidgetBounds.Top, Size_SourceIsInterface);
end;
// then send a LM_MOVE message
if (OldBounds.Left <> WidgetBounds.Left) or
(OldBounds.Top <> WidgetBounds.Top) then
if Moved then
begin
LCLSendMoveMsg(LCLObject, WidgetBounds.Left,
WidgetBounds.Top, Move_SourceIsInterface);
@ -511,18 +539,19 @@ begin
Widget := nil;
Context := nil;
FHasCaret := False;
FResizing := False;
CreateWidget(AParams);
BoundsChanged;
{$IFDEF VerboseWidget}
DebugLn('TCarbonWidget.Create ', ClassName, ' ', LCLObject.Name, ': ',
LCLObject.ClassName);
{$ENDIF}
RegisterEvents;
LCLObject.InvalidateClientRectCache(True);
BoundsChanged;
{$IFDEF VerboseBounds}
DebugLn('TCarbonWidget.Create LCL bounds: ' + DbgS(LCLObject.BoundsRect));

View File

@ -156,9 +156,9 @@ const
SName = 'CarbonCommon_Track';
SControlAction = 'kEventParamControlAction';
begin
{$IFDEF VerboseMouse}
//{$IFDEF VerboseMouse}
DebugLn('CarbonCommon_Track ', DbgSName(AWidget.LCLObject));
{$ENDIF}
//{$ENDIF}
if OSError(
GetEventParameter(AEvent, kEventParamControlAction, typeControlActionUPP,
nil, SizeOf(ActionUPP), nil, @OldActionUPP), SName, SGetEvent,

View File

@ -64,7 +64,6 @@ var
// or the window's widgetinfo if none found
const
SName = 'CarbonWindow_MouseProc';
AGetEvent = 'GetEventParameter';
//
// helper functions used commonly
@ -78,7 +77,7 @@ const
if OSError(
GetEventParameter(AEvent, kEventParamClickCount, typeUInt32, nil,
SizeOf(ClickCount), nil, @ClickCount),
SName, AGetEvent, 'kEventParamClickCount') then Exit;
SName, SGetEvent, 'kEventParamClickCount') then Exit;
Result := ClickCount;
//debugln('GetClickCount ClickCount=',dbgs(ClickCount));
@ -94,7 +93,7 @@ const
if OSError(
GetEventParameter(AEvent, kEventParamMouseButton, typeMouseButton, nil,
SizeOf(MouseButton), nil, @MouseButton),
SName, AGetEvent, 'kEventParamMouseButton') then Exit;
SName, SGetEvent, 'kEventParamMouseButton') then Exit;
Result := MouseButton;
end;
@ -106,7 +105,7 @@ const
if OSError(
GetEventParameter(AEvent, kEventParamWindowMouseLocation, typeHIPoint, nil,
SizeOf(MousePoint), nil, @MousePoint),
SName, AGetEvent, 'kEventParamWindowMouseLocation') then Exit;
SName, SGetEvent, 'kEventParamWindowMouseLocation') then Exit;
OSError(HIViewConvertPoint(MousePoint, nil, Widget.Content), SName, SViewConvert);
Result.X := Trunc(MousePoint.X);
@ -122,7 +121,7 @@ const
if OSError(
GetEventParameter(AEvent, kEventParamMouseWheelDelta, typeSInt32, nil,
SizeOf(WheelDelta), nil, @WheelDelta),
SName, AGetEvent, 'kEventParamMouseWheelDelta') then Exit;
SName, SGetEvent, 'kEventParamMouseWheelDelta') then Exit;
Result := WheelDelta;
{$IFDEF VerboseMouse}
@ -251,10 +250,20 @@ var
Extra: array[0..20] of Byte; // some messages are a bit larger, make some room
end;
EventKind: UInt32;
Part: WindowPartCode;
begin
Result := EventNotHandledErr;
// check window part code
if not OSError(
GetEventParameter(AEvent, kEventParamWindowPartCode, typeWindowPartCode, nil,
SizeOf(WindowPartCode), nil, @Part),
SName, SGetEvent, 'kEventParamWindowPartCode') then
begin
if Part <> inContent then Exit;
end;
//Find out which control the mouse event should occur for
Control := nil;
if OSError(HIViewGetViewForMouseEvent(AWidget.Content, AEvent, Control),
@ -286,7 +295,9 @@ begin
// Msg is set in the Appropriate HandleMousexxx procedure
if DeliverMessage(Widget.LCLObject, Msg) = 0 then
begin
Result := EventNotHandledErr //CallNextEventHandler(ANextHandler, AEvent);
end
else
// the LCL does not want the event propagated
Result := noErr;
@ -1233,6 +1244,7 @@ begin
Result := False;
BeginUpdate(WindowRef(Widget));
Resizing := True;
try
// set window width, height
if OSError(FPCMacOSAll.SetWindowBounds(WindowRef(Widget), kWindowContentRgn,
@ -1241,6 +1253,7 @@ begin
if OSError(MoveWindowStructure(WindowRef(Widget), ARect.Left, ARect.Top),
Self, SName, 'MoveWindowStructure') then Exit;
finally
Resizing := False;
EndUpdate(WindowRef(Widget));
end;

View File

@ -241,7 +241,7 @@ class procedure TCarbonWSCustomPage.UpdateProperties(const ACustomPage: TCustomP
begin
if not CheckHandle(ACustomPage, Self, 'UpdateProperties') then Exit;
TCarbonTab(ACustomPage.Handle).Update;
TCarbonTab(ACustomPage.Handle).UpdateTab;
end;
{ TCarbonWSCustomNotebook }