customdrawnws: Consolidates the GetDC implementation into a generic part and backends, starts checkbox although it crashes in Android and works (except for text drawing) in X11

git-svn-id: trunk@33886 -
This commit is contained in:
sekelsenmat 2011-12-01 12:29:15 +00:00
parent d8e0da0ae5
commit 108f8bc596
11 changed files with 112 additions and 89 deletions

View File

@ -3,6 +3,16 @@
{$modeswitch objectivec1}
{$endif}
{
vm^^.GetEnv crashes HTC Wildfire, Alcatel and the Emulator for unknown reasons,
see: http://groups.google.com/group/android-ndk/browse_thread/thread/ba542483f062a828/ef9077617794e0f5
This prevents using Pascal to Java calls completely in those platforms.
To turn on a work around one can use CD_Android_DontUsePascalToJNI
and then try to implement the missing functionality by other means.
Not that Java to Pascal calls always work
}
{$define CD_Android_DontUsePascalToJNI}
// For now default to Android for arm-linux,

View File

@ -134,16 +134,6 @@ function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
begin
curVM:=vm;
{
vm^^.GetEnv crashes HTC Wildfire, Alcatel and the Emulator for unknown reasons,
see: http://groups.google.com/group/android-ndk/browse_thread/thread/ba542483f062a828/ef9077617794e0f5
This prevents using Pascal to Java calls completely in those platforms.
To turn on a work around one can use CD_Android_DontUsePascalToJNI
and then try to implement the missing functionality by other means.
Not that Java to Pascal calls always work
}
{$ifndef CD_Android_DontUsePascalToJNI}
__android_log_write(ANDROID_LOG_INFO, 'lclapp', 'JNI_OnLoad called');
__android_log_write(ANDROID_LOG_INFO, 'lclapp', PChar(Format('CurVM=%x', [PtrInt(CurVM)])));

View File

@ -156,6 +156,12 @@ begin
or AForceUpdate then
begin
if (AImage <> nil) and AFreeImageOnUpdate then AImage.Free;
// Free the canvas and create a new one if it is a dummy Canvas created for text metrics reading by GetDC(control)
if (ACanvas <> nil) and ACanvas.HasNoImage then
begin
ACanvas.Free;
ACanvas := nil;
end;
lRawImage.Init;
case AFormat of

View File

@ -2728,7 +2728,7 @@ begin
lpPoint.y := vPoint.y;
Result := True;
end;
end;*)
{------------------------------------------------------------------------------
Function: GetDC
@ -2739,29 +2739,44 @@ end;
- Once on app startup with hWnd = 0
- Twice for every TLabel on the TCustomLabel.CalcSize function
------------------------------------------------------------------------------}
function TQtWidgetSet.GetDC(hWnd: HWND): HDC;
function TCDWidgetSet.GetDC(hWnd: HWND): HDC;
var
Widget: TQtWidget;
lObject: TObject;
lWinControl: TWinControl;
lFormHandle: HWND;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('Trace:> [WinAPI GetDC] hWnd: ', dbghex(hWnd));
{$ifdef VerboseCDWinAPI}
WriteLn(':>[WinAPI GetDC] hWnd: ', dbghex(hWnd));
{$endif}
if QtWidgetSet.IsValidHandle(hWnd) then
if HWnd = 0 then
begin
Widget := TQtWidget(hWnd);
Result := Widget.Context;
if Result = 0 then
Result := HDC(QtDefaultContext);
end else
Result := HDC(QtScreenContext);
Result := BackendGetDC(0);
Exit;
end;
{$ifdef VerboseQtWinAPI}
WriteLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));
if not IsValidDC(HWnd) then Exit;
lObject := TObject(HWnd);
if lObject is TCDWinControl then
begin
lWinControl := TCDWinControl(lObject).WinControl;
while (lWinControl <> nil) and (not (lWinControl is TCustomForm)) do
lWinControl := lWinControl.Parent;
lFormHandle := lWinControl.Handle;
end
else
lFormHandle := hWnd;
Result := BackendGetDC(lFormHandle);
{$ifdef VerboseCDWinAPI}
WriteLn(':<[WinAPI GetDC] Result: ', dbghex(Result));
{$endif}
end;
function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
(*function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
WindowHandle: HWND; var OriginDiff: TPoint): boolean;
var
QtDC: TQtDeviceContext absolute PaintDC;

View File

@ -2727,27 +2727,20 @@ end;*)
- Once on app startup with hWnd = 0
- Twice for every TLabel on the TCustomLabel.CalcSize function
------------------------------------------------------------------------------}
function TCDWidgetSet.GetDC(hWnd: HWND): HDC;
function TCDWidgetSet.BackendGetDC(hWnd: HWND): HDC;
var
lFormHandle: TCDNonNativeForm;
begin
{$ifdef VerboseCDWinAPI}
DebugLn('Trace:> [WinAPI GetDC] hWnd: ', dbghex(hWnd));
{$endif}
lFormHandle := TCDNonNativeForm(hWnd);
Result := 0;
// Screen DC
if hWnd = 0 then Exit;
{ if QtWidgetSet.IsValidHandle(hWnd) then
begin
Widget := TQtWidget(hWnd);
Result := Widget.Context;
if Result = 0 then
Result := HDC(QtDefaultContext);
end else
Result := HDC(QtScreenContext);}
{$ifdef VerboseCDWinAPI}
DebugLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));
{$endif}
// Form DC
if lFormHandle.Canvas = nil then lFormHandle.Canvas := TLazCanvas.create(nil);
Result := HDC(lFormHandle.Canvas);
end;
(*function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;

View File

@ -676,13 +676,20 @@ end;*)
{------------------------------- DEVICE CONTEXT -------------------------------}
function TCDWidgetSet.GetDC(hWnd: HWND): HDC;
function TCDWidgetSet.BackendGetDC(hWnd: HWND): HDC;
{var
lFormHandle: TCDNonNativeForm;}
begin
// lFormHandle := TCDNonNativeForm(hWnd);
Result := 0;
{$IFDEF VerboseWinAPI}
DebugLn('[TCocoaWidgetSet.GetDC] hWnd: %x Result: %x', [hWnd, Result]);
{$ENDIF}
// Screen DC
if hWnd = 0 then Exit;
{ // Form DC
if lFormHandle.Canvas = nil then lFormHandle.Canvas := TLazCanvas.create(nil);
Result := HDC(lFormHandle.Canvas);}
end;
function TCDWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean;

View File

@ -1646,9 +1646,10 @@ end;*)
Retrieves a handle of a display device context (DC) for the client area of
the specified window.
------------------------------------------------------------------------------}
function TCDWidgetSet.GetDC(hWnd: HWND): HDC;
function TCDWidgetSet.BackendGetDC(hWnd: HWND): HDC;
var
lWindowInfo: PWindowInfo;
// ORect: TRect;
begin
{$ifdef VerboseCDWinAPI}
DebugLn('Trace:> [WinAPI GetDC] hWnd: ', dbghex(hWnd));
@ -1659,30 +1660,22 @@ begin
// screenshot taking
if hWnd = 0 then Exit;
// Form Canvas
lWindowInfo := GetWindowInfo(hWNd);
if lWindowInfo^.Canvas = nil then lWindowInfo^.Canvas := TLazCanvas.create(nil);
Result := HDC(lWindowInfo^.Canvas);
// if QtWidgetSet.IsValidHandle(hWnd) then
// begin
// Widget := TQtWidget(hWnd);
// Result := Widget.Context;
// if Result = 0 then
// Result := HDC(QtDefaultContext);
// end else
// Result := HDC(QtScreenContext);
{ Result := Windows.GetDC(HWnd);
if (Result <> 0) and (HWnd <> 0) and GetLCLClientBoundsOffset(HWnd, ORect) then
MoveWindowOrgEx(Result, ORect.Left, ORect.Top);}
{$ifdef VerboseCDWinAPI}
DebugLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));
{$endif}
end;
{var
ORect: TRect;
begin
Result := Windows.GetDC(HWnd);
if (Result <> 0) and (HWnd <> 0) and GetLCLClientBoundsOffset(HWnd, ORect) then
MoveWindowOrgEx(Result, ORect.Left, ORect.Top);
end;}
(*
{------------------------------------------------------------------------------
(*{------------------------------------------------------------------------------
Method: GetDeviceCaps
Params: DC - display device context
Index - index of needed capability

View File

@ -2727,27 +2727,20 @@ end;*)
- Once on app startup with hWnd = 0
- Twice for every TLabel on the TCustomLabel.CalcSize function
------------------------------------------------------------------------------}
function TCDWidgetSet.GetDC(hWnd: HWND): HDC;
function TCDWidgetSet.BackendGetDC(hWnd: HWND): HDC;
var
lFormHandle: TX11WindowInfo;
begin
{$ifdef VerboseCDWinAPI}
DebugLn('Trace:> [WinAPI GetDC] hWnd: ', dbghex(hWnd));
{$endif}
lFormHandle := TX11WindowInfo(hWnd);
Result := 0;
// Screen DC
if hWnd = 0 then Exit;
{ if QtWidgetSet.IsValidHandle(hWnd) then
begin
Widget := TQtWidget(hWnd);
Result := Widget.Context;
if Result = 0 then
Result := HDC(QtDefaultContext);
end else
Result := HDC(QtScreenContext);}
{$ifdef VerboseCDWinAPI}
DebugLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));
{$endif}
// Form DC
if lFormHandle.Canvas = nil then lFormHandle.Canvas := TLazCanvas.create(nil);
Result := HDC(lFormHandle.Canvas);
end;
(*function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;

View File

@ -107,6 +107,7 @@ function GetCmdLineParamDescForInterface: string; override;
function GetCurrentObject(DC: HDC; uObjectType: UINT): HGDIOBJ; override;
function GetCursorPos(var lpPoint: TPoint ): Boolean; override;*)
function GetDC(hWnd: HWND): HDC; override;
function BackendGetDC(hWnd: HWND): HDC;
(*function GetDCOriginRelativeToWindow(PaintDC: HDC; WindowHandle: HWND; var OriginDiff: TPoint): boolean; override;
function GetDeviceCaps(DC: HDC; Index: Integer): Integer; override;
function GetDeviceSize(DC: HDC; var P: TPoint): Boolean; Override;

View File

@ -302,8 +302,8 @@ end;
function RegisterCustomCheckBox: Boolean; alias : 'WSRegisterCustomCheckBox';
begin
// RegisterWSComponent(TCustomCheckBox, TWinCEWSCustomCheckBox);
Result := False;
RegisterWSComponent(TCustomCheckBox, TCDWSCustomCheckBox);
Result := True;
end;
function RegisterToggleBox: Boolean; alias : 'WSRegisterToggleBox';

View File

@ -215,10 +215,11 @@ type
TCDWSCustomCheckBox = class(TWSCustomCheckBox)
published
{ class function CreateHandle(const AWinControl: TWinControl;
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLIntfHandle; override;
class procedure ShowHide(const AWinControl: TWinControl); override;
class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const ShortCutK1, ShortCutK2: TShortCut); override;
{ class procedure SetShortCut(const ACustomCheckBox: TCustomCheckBox; const ShortCutK1, ShortCutK2: TShortCut); override;
class procedure SetState(const ACustomCheckBox: TCustomCheckBox; const NewState: TCheckBoxState); override;
class function RetrieveState(const ACustomCheckBox: TCustomCheckBox): TCheckBoxState; override;}
@ -1193,7 +1194,7 @@ begin
QtCheckBox.setCheckState(QtUnchecked);
end;
QtCheckBox.EndUpdate;
end;
end; *)
{------------------------------------------------------------------------------
Method: TCDWSCustomCheckBox.CreateHandle
@ -1204,18 +1205,32 @@ end;
------------------------------------------------------------------------------}
class function TCDWSCustomCheckBox.CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLIntfHandle;
var
QtCheckBox: TQtCheckBox;
lCDWinControl: TCDWinControl;
begin
QtCheckBox := TQtCheckBox.Create(AWinControl, AParams);
QtCheckBox.setTriState(TCustomCheckBox(AWinControl).AllowGrayed);
QtCheckBox.AttachEvents;
Result := TCDWSWinControl.CreateHandle(AWinControl, AParams);
lCDWinControl := TCDWinControl(Result);
end;
Result := TLCLIntfHandle(QtCheckBox);
class procedure TCDWSCustomCheckBox.ShowHide(const AWinControl: TWinControl);
var
lCDWinControl: TCDWinControl;
begin
lCDWinControl := TCDWinControl(AWinControl.Handle);
TCDWSWinControl.ShowHide(AWinControl);
if lCDWinControl.CDControl = nil then
begin
lCDWinControl.CDControl := TCDCheckBox.Create(AWinControl);
// TCDIntfButton(lCDWinControl.CDControl).LCLButton := TButton(AWinControl);
lCDWinControl.CDControl.Parent := AWinControl;
lCDWinControl.CDControl.Align := alClient;
end;
end;
{ TCDWSRadioButton }
{------------------------------------------------------------------------------
(*{------------------------------------------------------------------------------
Method: TCDWSRadioButton.RetrieveState
Params: None
Returns: The state of the control