- protect most qtwscontrols.pp class methods by WSCheckHandleAllocated
- cleanup

git-svn-id: trunk@12027 -
This commit is contained in:
paul 2007-09-14 05:05:19 +00:00
parent 5b1d9ef4a8
commit 7da6e8a36f
4 changed files with 80 additions and 71 deletions

View File

@ -1400,7 +1400,7 @@ begin
then msk := 0
else msk := AMask.Handle;
R := Rect(0, 0, FWidth, FHeight);
RawImage_FromBitmap(RawImage, AImage.Handle, AMask.Handle, R);
RawImage_FromBitmap(RawImage, AImage.Handle, msk, R);
ImgData := InternalSetImage(AIndex, RawImage);
if HandleAllocated
then TWSCustomImageListClass(WidgetSetClass).Replace(Self, AIndex, ImgData);

View File

@ -153,6 +153,7 @@ type
procedure setColor(const Value: PQColor); virtual;
procedure setCursor(const ACursor: QCursorH);
procedure setEnabled(p1: Boolean);
procedure setFont(AFont: QFontH);
procedure setGeometry(ARect: TRect); overload;
procedure setMaximumSize(AWidth, AHeight: Integer);
procedure setMinimumSize(AWidth, AHeight: Integer);
@ -167,6 +168,7 @@ type
procedure setHeight(p1: Integer);
procedure setTabOrder(p1, p2: TQtWidget);
procedure setWindowState(AState: QtWindowStates);
procedure sizeHint(size: PSize);
function windowFlags: QtWindowFlags;
function windowModality: QtWindowModality;
@ -2100,6 +2102,11 @@ begin
QWidget_setEnabled(Widget, p1);
end;
procedure TQtWidget.setFont(AFont: QFontH);
begin
QWidget_setFont(Widget, AFont);
end;
procedure TQtWidget.setGeometry(ARect: TRect);
begin
QWidget_setGeometry(Widget, @ARect);
@ -2183,6 +2190,11 @@ begin
QWidget_setWindowState(Widget, AState);
end;
procedure TQtWidget.sizeHint(size: PSize);
begin
QWidget_sizeHint(Widget, size);
end;
{------------------------------------------------------------------------------
Function: TQtWidget.QtKeyToLCLKey
Params: None

View File

@ -169,15 +169,12 @@ var
Widget: TQtWidget;
R: TRect;
begin
{$ifdef VerboseQt}
WriteLn('Trace:> [TQtWSCustomControl.ShowHide]');
{$endif}
if (AWinControl = nil) or not AWinControl.HandleAllocated then
exit;
if not WSCheckHandleAllocated(AWinControl, 'ShowHide') then
Exit;
Widget := TQtWidget(AWinControl.Handle);
{ if the widget is a form, this is a place to set the Tab order }
// if the widget is a form, this is a place to set the Tab order
if AWinControl.HandleObjectShouldBeVisible and (Widget is TQtMainWindow) then
begin
if fsModal in TForm(AWinControl).FormState then
@ -205,19 +202,6 @@ begin
end;
Widget.setVisible(AWinControl.HandleObjectShouldBeVisible);
{$ifdef VerboseQt}
Write('Trace:< [TQtWSCustomControl.ShowHide] ');
if AWinControl is TForm then
Write('Is TForm, ');
if AWinControl.HandleObjectShouldBeVisible then
WriteLn('Visible: True')
else
WriteLn('Visible: False');
{$endif}
end;
{------------------------------------------------------------------------------
@ -230,20 +214,20 @@ var
Widget: TQtWidget;
FocusWidget: QWidgetH;
begin
if AWinControl.HandleAllocated then
begin
Widget := TQtWidget(AWinControl.Handle);
if Assigned(Widget.LCLObject.Parent) then
FocusWidget := QWidget_focusWidget(TQtWidget(Widget.LCLObject.Parent.Handle).Widget)
else
FocusWidget := QWidget_focusWidget(Widget.Widget);
Result := (FocusWidget <> nil) and
QWidget_isEnabled(FocusWidget) and
QWidget_isVisible(FocusWidget) and
(QWidget_focusPolicy(FocusWidget) <> QtNoFocus);
end else
Result := False;
Result := False;
if not WSCheckHandleAllocated(AWinControl, 'CanFocus') then
Exit;
Widget := TQtWidget(AWinControl.Handle);
if Assigned(Widget.LCLObject.Parent) then
FocusWidget := QWidget_focusWidget(TQtWidget(Widget.LCLObject.Parent.Handle).Widget)
else
FocusWidget := QWidget_focusWidget(Widget.Widget);
Result := (FocusWidget <> nil) and
QWidget_isEnabled(FocusWidget) and
QWidget_isVisible(FocusWidget) and
(QWidget_focusPolicy(FocusWidget) <> QtNoFocus);
end;
{------------------------------------------------------------------------------
@ -291,6 +275,9 @@ end;
------------------------------------------------------------------------------}
class procedure TQtWSWinControl.Invalidate(const AWinControl: TWinControl);
begin
if not WSCheckHandleAllocated(AWinControl, 'Invalidate') then
Exit;
TQtWidget(AWinControl.Handle).Update;
end;
@ -303,6 +290,10 @@ end;
class function TQtWSWinControl.GetClientBounds(const AWincontrol: TWinControl;
var ARect: TRect): Boolean;
begin
Result := False;
if not WSCheckHandleAllocated(AWinControl, 'GetClientBounds') then
Exit;
ARect := TQtWidget(AWinControl.Handle).getClientBounds;
Result := True;
end;
@ -310,6 +301,10 @@ end;
class function TQtWSWinControl.GetClientRect(const AWincontrol: TWinControl;
var ARect: TRect): Boolean;
begin
Result := False;
if not WSCheckHandleAllocated(AWinControl, 'GetClientRect') then
Exit;
ARect := TQtWidget(AWinControl.Handle).getClientBounds;
OffsetRect(ARect, -ARect.Left, -ARect.Top);
Result := True;
@ -320,21 +315,21 @@ class procedure TQtWSWinControl.GetPreferredSize(const AWinControl: TWinControl;
var
PrefSize: TSize;
begin
{$ifdef VerboseQt}
WriteLn('> TQtWSWinControl.GetPreferredSSize for ',dbgsname(AWinControl));
{$endif}
QWidget_sizeHint(TQtWidget(AWinControl.Handle).Widget, @PrefSize);
if (PrefSize.cx >= 0)
and (PrefSize.cy >=0) then
if AWinControl.HandleAllocated then
begin
PreferredWidth := PrefSize.cx;
PreferredHeight := PrefSize.cy;
TQtWidget(AWinControl.Handle).sizeHint(@PrefSize);
if (PrefSize.cx >= 0) and (PrefSize.cy >=0) then
begin
PreferredWidth := PrefSize.cx;
PreferredHeight := PrefSize.cy;
end;
end;
end;
class function TQtWSWinControl.GetText(const AWinControl: TWinControl;
var AText: String): Boolean;
begin
Result := False;
if not WSCheckHandleAllocated(AWincontrol, 'SetChildZPosition') then
Exit;
@ -388,6 +383,9 @@ var
Widget: TQtWidget;
MaxW, MaxH: Integer;
begin
if not WSCheckHandleAllocated(AWincontrol, 'ConstraintsChange') then
Exit;
Widget := TQtWidget(AWinControl.Handle);
with AWinControl do
begin
@ -416,6 +414,9 @@ end;
class procedure TQtWSWinControl.SetBounds(const AWinControl: TWinControl;
const ALeft, ATop, AWidth, AHeight: Integer);
begin
if not WSCheckHandleAllocated(AWincontrol, 'SetBounds') then
Exit;
TQtWidget(AWinControl.Handle).move(ALeft, ATop);
TQtWidget(AWinControl.Handle).resize(AWidth, AHeight);
end;
@ -431,6 +432,9 @@ end;
class procedure TQtWSWinControl.SetPos(const AWinControl: TWinControl;
const ALeft, ATop: Integer);
begin
if not WSCheckHandleAllocated(AWincontrol, 'SetPos') then
Exit;
TQtWidget(AWinControl.Handle).move(ALeft, ATop);
end;
@ -445,6 +449,9 @@ end;
class procedure TQtWSWinControl.SetSize(const AWinControl: TWinControl;
const AWidth, AHeight: Integer);
begin
if not WSCheckHandleAllocated(AWincontrol, 'SetSize') then
Exit;
TQtWidget(AWinControl.Handle).resize(AWidth, AHeight);
end;
@ -460,31 +467,16 @@ class procedure TQtWSWinControl.ShowHide(const AWinControl: TWinControl);
var
Widget: TQtWidget;
begin
{$ifdef VerboseQt}
WriteLn('Trace:> [TQtWSWinControl.ShowHide]');
{$endif}
if (AWinControl = nil) or not AWinControl.HandleAllocated then
exit;
if not WSCheckHandleAllocated(AWincontrol, 'ShowHide') then
Exit;
Widget := TQtWidget(AWinControl.Handle);
{ if the widget is a form, this is a place to set the Tab order }
// if the widget is a form, this is a place to set the Tab order
if AWinControl.HandleObjectShouldBeVisible and (Widget is TQtMainWindow) then
TQtMainWindow(Widget).SetTabOrders;
Widget.setVisible(AWinControl.HandleObjectShouldBeVisible);
{$ifdef VerboseQt}
Write('Trace:< [TQtWSWinControl.ShowHide] ');
if AWinControl is TForm then
Write('Is TForm, ');
if AWinControl.HandleObjectShouldBeVisible then
WriteLn('Visible: True')
else
WriteLn('Visible: False');
{$endif}
end;
{------------------------------------------------------------------------------
@ -499,9 +491,8 @@ var
QColor: TQColor;
Color: TColor;
begin
if AWinControl = nil then exit;
if not AWinControl.HandleAllocated then exit;
if not WSCheckHandleAllocated(AWinControl, 'SetColor') then
Exit;
if AWinControl.Color = CLR_INVALID then exit;
@ -524,9 +515,9 @@ end;
------------------------------------------------------------------------------}
class procedure TQtWSWinControl.SetCursor(const AWinControl: TWinControl; const ACursor: HCursor);
begin
if AWinControl = nil then exit;
if not AWinControl.HandleAllocated then exit;
if not WSCheckHandleAllocated(AWinControl, 'SetCursor') then
Exit;
TQtWidget(AWinControl.Handle).SetCursor(QCursorH(ACursor));
end;
@ -542,8 +533,11 @@ var
QColor: TQColor;
Color: TColor;
begin
QWidget_setFont(TQtWidget(AWinControl.Handle).Widget, TQtFont(AFont.Handle).Widget);
if not WSCheckHandleAllocated(AWinControl, 'SetFont') then
Exit;
TQtWidget(AWinControl.Handle).setFont(TQtFont(AFont.Handle).Widget);
if AFont.Color = CLR_INVALID then exit;
Color := ColorToRGB(AFont.Color);
@ -556,6 +550,9 @@ class procedure TQtWSWinControl.SetBorderStyle(const AWinControl: TWinControl;
var
Widget: TQtWidget;
begin
if not WSCheckHandleAllocated(AWinControl, 'SetBorderStyle') then
Exit;
Widget := TQtWidget(AWinControl.Handle);
if Widget is TQtFrame then
TQtFrame(Widget).setFrameShape(TBorderStyleToQtFrameShapeMap[ABorderStyle]);

View File

@ -61,7 +61,7 @@ function WSCheckHandleAllocated(const AWincontrol: TWinControl;
DebugLn('[WARNING] %s called without handle for %s(%s)', [AProcName, AWincontrol.Name, AWincontrol.ClassName]);
end;
begin
Result := AWinControl.HandleAllocated;
Result := AWinControl.HandleAllocated;
if Result then Exit;
Warn;
end;