- postoned Destroying of widgets in case of destroy during event processing (introduced Release method)
- safer DeliverMessage
- cleanup

git-svn-id: trunk@11933 -
This commit is contained in:
paul 2007-09-04 02:28:26 +00:00
parent c640644c8f
commit 3d77f2e0a2
7 changed files with 77 additions and 37 deletions

View File

@ -375,7 +375,7 @@ var
Desc: TRawImageDescription absolute ARawImage.Description;
IsDesktopDC: Boolean;
SrcWidth, SrcHeight: Integer;
//SrcWidth, SrcHeight: Integer;
WinID: Cardinal;
desktop: QDesktopWidgetH;
ScreenSize: TSize;
@ -392,8 +392,8 @@ begin
FillStandardDescription(ARawImage.Description);
SrcWidth := ARect.Right - ARect.Left;
SrcHeight := ARect.Bottom - ARect.Top;
//SrcWidth := ARect.Right - ARect.Left;
//SrcHeight := ARect.Bottom - ARect.Top;
IsDesktopDC := True; // Hard-coded, but a real check should be made

View File

@ -45,15 +45,20 @@ type
TQtObject = class(TObject)
private
FUpdateCount: Integer;
FInEventCount: Integer;
FReleaseInEvent: Boolean;
public
FEventHook: QObject_hookH;
TheObject: QObjectH;
// TODO: base virtual constructor with initialization
constructor Create; virtual;
destructor Destroy; override;
procedure Release;
public
procedure AttachEvents; virtual;
procedure DetachEvents; virtual;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; virtual; abstract;
procedure BeginEventProcessing;
procedure EndEventProcessing;
public
procedure BeginUpdate; virtual;
procedure EndUpdate; virtual;
@ -356,7 +361,7 @@ type
FClipBoardFormats: TStringList;
FOnClipBoardRequest: TClipboardRequestEvent;
public
constructor Create;
constructor Create; override;
destructor Destroy; override;
function EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl; override;
@ -507,6 +512,13 @@ end;
{ TQtObject }
constructor TQtObject.Create;
begin
FUpdateCount := 0;
FInEventCount := 0;
FReleaseInEvent := False;
end;
destructor TQtObject.Destroy;
begin
if TheObject <> nil then
@ -518,6 +530,19 @@ begin
inherited Destroy;
end;
procedure TQtObject.Release;
begin
if Self <> nil then
begin
if FInEventCount > 0 then
begin
FReleaseInEvent := True;
end
else
Free;
end;
end;
procedure TQtObject.AttachEvents;
var
Method: TMethod;
@ -536,6 +561,19 @@ begin
end;
end;
procedure TQtObject.BeginEventProcessing;
begin
inc(FInEventCount);
end;
procedure TQtObject.EndEventProcessing;
begin
if FInEventCount > 0 then
dec(FInEventCount);
if (FInEventCount = 0) and FReleaseInEvent then
Free;
end;
procedure TQtObject.BeginUpdate;
begin
inc(FUpdateCount);
@ -2063,6 +2101,7 @@ end;
constructor TQtClipboard.Create;
begin
inherited Create;
FOnClipBoardRequest := nil;
FClipBoardFormats := TStringList.Create;
FClipBoardFormats.Add('foo'); // 0 is reserved
@ -2079,6 +2118,7 @@ end;
function TQtClipboard.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
BeginEventProcessing;
Result := False;
if QEvent_type(Event) = QEventClipboard then
@ -2090,6 +2130,7 @@ begin
// Clipboard is changed, but we have no ability at moment to pass that info
// to LCL since LCL has no support for that event
end;
EndEventProcessing;
end;
function TQtClipboard.Clipboard: QClipboardH;
@ -2249,6 +2290,7 @@ end;
constructor TQtTimer.CreateTimer(Interval: integer;
const TimerFunc: TFNTimerProc; App: QObjectH);
begin
inherited Create;
FAppObject := App;
FCallbackFunc := TimerFunc;
@ -2290,6 +2332,7 @@ end;
------------------------------------------------------------------------------}
function TQtTimer.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
BeginEventProcessing;
Result := False;
if QEvent_type(Event) = QEventTimer then
@ -2301,6 +2344,7 @@ begin
if Assigned(FCallbackFunc) then
FCallbackFunc;
end;
EndEventProcessing;
end;
{ TQtIcon }

View File

@ -819,10 +819,11 @@ var
------------------------------------------------------------------------------}
constructor TQtWidget.Create(const AWinControl: TWinControl; const AParams: TCreateParams);
begin
FOwnWidget := True;
inherited Create;
FOwnWidget := True;
// Initializes the properties
FProps := NiL;
FProps := nil;
LCLObject := AWinControl;
// Creates the widget
@ -852,8 +853,9 @@ end;
constructor TQtWidget.CreateFrom(const AWinControl: TWinControl;
AWidget: QWidgetH);
begin
inherited Create;
FOwnWidget := False;
// Initializes the properties
FProps := niL;
LCLObject := AWinControl;
@ -1055,6 +1057,7 @@ end;
------------------------------------------------------------------------------}
function TQtWidget.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
BeginEventProcessing;
Result := False;
QEvent_accept(Event);
@ -1120,20 +1123,7 @@ begin
else
QEvent_ignore(Event);
end;
{ GtkWidgetSet.SetCallback(LM_WINDOWPOSCHANGED, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_EXPOSEEVENT, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_KEYDOWN, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_KEYUP, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_CHAR, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_MOUSEMOVE, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_LBUTTONDOWN, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_LBUTTONUP, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_RBUTTONDOWN, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_RBUTTONUP, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_MBUTTONDOWN, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_MBUTTONUP, AGTKObject, AComponent);
GtkWidgetSet.SetCallback(LM_MOUSEWHEEL, AGTKObject, AComponent);}
EndEventProcessing;
end;
{------------------------------------------------------------------------------
@ -2396,8 +2386,12 @@ end;
function TQtWidget.DeliverMessage(var Msg): LRESULT;
begin
try
LCLObject.WindowProc(TLMessage(Msg));
Result := TLMessage(Msg).Result;
if LCLObject.HandleAllocated then
begin
LCLObject.WindowProc(TLMessage(Msg));
Result := TLMessage(Msg).Result;
end else
Result := 0;
except
Application.HandleException(nil);
end;
@ -2840,19 +2834,15 @@ end;
function TQtMainWindow.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
cdecl;
begin
BeginEventProcessing;
Result := False;
case QEvent_type(Event) of
QEventWindowStateChange: SlotWindowStateChange;
QEventClose:
begin
Result:=True;
QEvent_ignore(Event);
SlotClose;
end;
else
inherited EventFilter(Sender, Event);
end;
EndEventProcessing;
end;
procedure TQtMainWindow.OffsetMousePos(APoint: PQtPoint);
@ -3743,7 +3733,7 @@ end;
------------------------------------------------------------------------------}
function TQtLineEdit.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
Result := False;
BeginEventProcessing;
case QEvent_type(Event) of
QEventFocusIn:
begin
@ -3758,7 +3748,8 @@ begin
end;
end;
end;
inherited EventFilter(Sender, Event);
Result := inherited EventFilter(Sender, Event);
EndEventProcessing;
end;
{------------------------------------------------------------------------------
@ -4168,6 +4159,7 @@ end;
function TQtComboBox.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
BeginEventProcessing;
if (FDropList <> nil) and (Sender = FDropList.Widget) then
begin
Result := False;
@ -4182,6 +4174,7 @@ begin
end;
end else
Result := inherited EventFilter(Sender, Event);
EndEventProcessing;
end;
procedure TQtComboBox.SlotChange(p1: PWideString); cdecl;
@ -5078,12 +5071,14 @@ end;
constructor TQtMenu.Create(const AParent: QWidgetH);
begin
Create;
Widget := QMenu_Create(AParent);
FIcon := nil;
end;
constructor TQtMenu.Create(const AHandle: QMenuH);
begin
Create;
Widget := AHandle;
FIcon := nil;
end;
@ -5237,17 +5232,20 @@ end;
function TQtMenu.EventFilter(Sender: QObjectH; Event: QEventH): Boolean; cdecl;
begin
BeginEventProcessing;
Result := False;
case QEvent_type(Event) of
QEventDestroy: SlotDestroy;
end;
EndEventProcessing;
end;
{ TQtMenuBar }
constructor TQtMenuBar.Create(const AParent: QWidgetH);
begin
Create;
Widget := QMenuBar_create(AParent);
FHeight := QWidget_height(Widget);
FVisible := False;

View File

@ -2019,8 +2019,6 @@ end;
Return the size of a device
------------------------------------------------------------------------------}
function TQtWidgetSet.GetDeviceSize(DC: HDC; var P: TPoint): Boolean;
var
Size: TSize;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI GetDeviceSize]');

View File

@ -550,7 +550,7 @@ begin
SetLength(QtStatusBar.APanels, 0);
end;
TQtStatusBar(AWinControl.Handle).Free;
TQtStatusBar(AWinControl.Handle).Release;
AWinControl.Handle := 0;
end;

View File

@ -279,7 +279,7 @@ end;
------------------------------------------------------------------------------}
class procedure TQtWSWinControl.DestroyHandle(const AWinControl: TWinControl);
begin
TQtWidget(AWinControl.Handle).Free;
TQtWidget(AWinControl.Handle).Release;
AWinControl.Handle := 0;
end;

View File

@ -253,7 +253,7 @@ begin
Obj := TObject(AMenuItem.Handle);
if Obj is TQtMenu then
Obj.Free;
TQtMenu(Obj).Release;
end;
{------------------------------------------------------------------------------