customdrawnws: Starts the process of harmonized the form handles of all backends to diminish the backend code. For now X11 and Android are harmonized and base on TCDForm. Cocoa and Win32 will need big adjustments

git-svn-id: trunk@33906 -
This commit is contained in:
sekelsenmat 2011-12-02 09:56:12 +00:00
parent c1779edcd8
commit bbf9512a32
15 changed files with 63 additions and 71 deletions

View File

@ -16,13 +16,9 @@ uses
customdrawnproc;
type
TX11WindowInfo = class
TX11WindowInfo = class(TCDForm)
public
Window: X.TWindow;
LCLControl: TWinControl;
Children: TFPList; // of TCDWinControl;
//
LastMouseDownControl: TWinControl; // Stores the control which should receive the next MouseUp
// Used and valid only during event processing
XEvent: PXEvent;
// X11 extra objects
@ -30,9 +26,6 @@ type
Colormap: TColormap;
GC: TGC;
ColorDepth: Byte;
// painting objects
Image: TLazIntfImage;
Canvas: TLazCanvas;
end;
function RectToXRect(const ARect: TRect): TXRectangle;

View File

@ -151,6 +151,7 @@ type
procedure BackendCreate;
procedure BackendDestroy;
public
ScreenDC: TLazCanvas;
constructor Create; override;
destructor Destroy; override;

View File

@ -33,6 +33,7 @@ begin
CDWidgetSet := Self;
FTerminating := False;
ScreenDC := TLazCanvas.Create(nil);
BackendCreate;
end;
@ -48,6 +49,7 @@ destructor TCDWidgetSet.Destroy;
begin
BackendDestroy;
CDWidgetSet := nil;
ScreenDC.Free;
inherited Destroy;
end;

View File

@ -34,7 +34,7 @@ begin
for i := 0 to Screen.FormCount - 1 do
begin
lWindowInfo := TX11WindowInfo(Screen.Forms[i].Handle);
Result := lWindowInfo.LCLControl;
Result := lWindowInfo.LCLForm;
AWindowInfo := lWindowInfo;
{$ifdef VerboseFindX11Window}

View File

@ -28,7 +28,7 @@ type
Children: TFPList;
end;
TCDNonNativeForm = class
TCDForm = class
public
LCLForm: TCustomForm;
Children: TFPList; // of TCDWinControl;
@ -39,12 +39,19 @@ type
Canvas: TLazCanvas;
end;
TCDNonNativeForm = class(TCDForm)
public
end;
TCDBitmap = class
public
Image: TLazIntfImage;
end;
// Routines for non-native form
// Routines for form managing (both native and non-native)
procedure AddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
function GetCDWinControlList(const AForm: TCustomForm): TFPList;
procedure InitNonNativeForms();
function GetCurrentForm(): TCDNonNativeForm;
@ -80,6 +87,24 @@ implementation
var
NonNativeForms: TFPList = nil;
procedure AddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
var
lWindowInfo: TCDForm;
begin
lWindowInfo := TCDForm(AForm.Handle);
if lWindowInfo.Children = nil then lWindowInfo.Children := TFPList.Create;
lWindowInfo.Children.Add(ACDWinControl);
end;
function GetCDWinControlList(const AForm: TCustomForm): TFPList;
var
lWindowInfo: TCDForm;
begin
lWindowInfo := TCDForm(AForm.Handle);
if lWindowInfo.Children = nil then lWindowInfo.Children := TFPList.Create;
Result := lWindowInfo.Children;
end;
procedure InitNonNativeForms();
begin
if NonNativeForms <> nil then Exit;

View File

@ -2743,33 +2743,43 @@ function TCDWidgetSet.GetDC(hWnd: HWND): HDC;
var
lObject: TObject;
lWinControl: TWinControl;
lFormHandle: HWND;
lFormHandle: TCDForm;
begin
{$ifdef VerboseCDWinAPI}
DebugLn(':>[WinAPI GetDC] hWnd: ', dbghex(hWnd));
{$endif}
if HWnd = 0 then
begin
Result := BackendGetDC(0);
Exit;
end;
Result := 0;
// Screen DC
if HWnd = 0 then Result := HDC(CDWidgetset.ScreenDC);
// Invalid DC
if not IsValidDC(HWnd) then Exit;
lObject := TObject(HWnd);
// Control DC -> Search for the corresponding form
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;
lFormHandle := TCDForm(lWinControl.Handle);
end
// Form DC
else if lObject is TCDForm then
lFormHandle := TCDForm(hWnd)
else
lFormHandle := hWnd;
raise Exception.Create('Invalid handle for GetDC');
Result := BackendGetDC(lFormHandle);
// Now get Form DC
Result := HDC(lFormHandle.Canvas);
// If the Form DC doesn't yet exist, just give the ScreenDC
// Anyone asking for a DC outside the Paint event can't expect
// to receive something which can be drawn to anyway
if Result = 0 then Result := HDC(CDWidgetset.ScreenDC);
{$ifdef VerboseCDWinAPI}
DebugLn(':<[WinAPI GetDC] Result: ', dbghex(Result));

View File

@ -2716,7 +2716,7 @@ begin
lpPoint.y := vPoint.y;
Result := True;
end;*)
end;
{------------------------------------------------------------------------------
Function: GetDC
@ -2743,7 +2743,7 @@ begin
Result := HDC(lFormHandle.Canvas);
end;
(*function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
WindowHandle: HWND; var OriginDiff: TPoint): boolean;
var
QtDC: TQtDeviceContext absolute PaintDC;

View File

@ -672,7 +672,7 @@ procedure TCocoaWidgetSet.LeaveCriticalSection(var CritSection: TCriticalSection
begin
if CritSection=0 then Exit;
NSRecursiveLock(CritSection).unlock;
end;*)
end;
{------------------------------- DEVICE CONTEXT -------------------------------}
@ -690,7 +690,7 @@ begin
{ // Form DC
if lFormHandle.Canvas = nil then lFormHandle.Canvas := TLazCanvas.create(nil);
Result := HDC(lFormHandle.Canvas);}
end;
end; *)
function TCDWidgetSet.GetWindowSize(Handle: hwnd; var Width, Height: Integer): boolean;
begin

View File

@ -1635,7 +1635,7 @@ end;
function TWin32WidgetSet.GetCursorPos(Var LPPoint: TPoint): Boolean;
begin
Result := Boolean(Windows.GetCursorPos(@LPPoint));
end;*)
end;
{------------------------------------------------------------------------------
Method: GetDC
@ -1675,7 +1675,7 @@ begin
end;
begin
(*{------------------------------------------------------------------------------
{------------------------------------------------------------------------------
Method: GetDeviceCaps
Params: DC - display device context
Index - index of needed capability

View File

@ -2716,7 +2716,7 @@ begin
lpPoint.y := vPoint.y;
Result := True;
end;*)
end;
{------------------------------------------------------------------------------
Function: GetDC
@ -2743,7 +2743,7 @@ begin
Result := HDC(lFormHandle.Canvas);
end;
(*function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
function TQtWidgetSet.GetDCOriginRelativeToWindow(PaintDC: HDC;
WindowHandle: HWND; var OriginDiff: TPoint): boolean;
var
QtDC: TQtDeviceContext absolute PaintDC;
@ -4643,7 +4643,7 @@ var
lFormHandle: TX11WindowInfo;
begin
lFormHandle := TX11WindowInfo(AHandle);
TCDWSCustomForm.EvPaint(lFormHandle.LCLControl, lFormHandle);
TCDWSCustomForm.EvPaint(lFormHandle.LCLForm, lFormHandle);
Result := True;
end;

View File

@ -107,7 +107,6 @@ 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

@ -263,7 +263,7 @@ begin
// Adding on a form
if AWinControl.Parent is TCustomForm then
begin
TCDWSCustomForm.BackendAddCDWinControlToForm(TCustomForm(AWinControl.Parent), lCDWinControl);
AddCDWinControlToForm(TCustomForm(AWinControl.Parent), lCDWinControl);
end
// Adding on another control
else if AWinControl.Parent is TWinControl then

View File

@ -79,8 +79,6 @@ type
TCDWSCustomForm = class(TWSCustomForm)
public
class procedure BackendAddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
class function BackendGetCDWinControlList(const AForm: TCustomForm): TFPList;
{$ifdef CD_Windows}
class function CalcBorderIconsFlags(const AForm: TCustomForm): dword;
class function CalcBorderIconsFlagsEx(const AForm: TCustomForm): DWORD;

View File

@ -2,24 +2,6 @@
{ TCDWSCustomForm }
class procedure TCDWSCustomForm.BackendAddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
var
lWindowInfo: TCDNonNativeForm;
begin
lWindowInfo := TCDNonNativeForm(AForm.Handle);
if lWindowInfo.Children = nil then lWindowInfo.Children := TFPList.Create;
lWindowInfo.Children.Add(ACDWinControl);
end;
class function TCDWSCustomForm.BackendGetCDWinControlList(const AForm: TCustomForm): TFPList;
var
lWindowInfo: TCDNonNativeForm;
begin
lWindowInfo := TCDNonNativeForm(AForm.Handle);
if lWindowInfo.Children = nil then lWindowInfo.Children := TFPList.Create;
Result := lWindowInfo.Children;
end;
{------------------------------------------------------------------------------
Method: TCDWSCustomForm.CreateHandle
Params: None

View File

@ -2,24 +2,6 @@
{ TCDWSCustomForm }
class procedure TCDWSCustomForm.BackendAddCDWinControlToForm(const AForm: TCustomForm; ACDWinControl: TCDWinControl);
var
lWindowInfo: TX11WindowInfo;
begin
lWindowInfo := TX11WindowInfo(AForm.Handle);
if lWindowInfo.Children = nil then lWindowInfo.Children := TFPList.Create;
lWindowInfo.Children.Add(ACDWinControl);
end;
class function TCDWSCustomForm.BackendGetCDWinControlList(const AForm: TCustomForm): TFPList;
var
lWindowInfo: TX11WindowInfo;
begin
lWindowInfo := TX11WindowInfo(AForm.Handle);
if lWindowInfo.Children = nil then lWindowInfo.Children := TFPList.Create;
Result := lWindowInfo.Children;
end;
class procedure TCDWSCustomForm.UpdateMotifWMHints(const AWinControl: TWinControl; CanMaximize: Boolean);
type
PMotifWmHints = ^TMotifWmHints;
@ -667,7 +649,7 @@ begin
// Now paint all child win controls
RenderChildWinControls(AWindowInfo.Image, AWindowInfo.Canvas,
BackendGetCDWinControlList(TCustomForm(AWinControl)));
GetCDWinControlList(TCustomForm(AWinControl)));
// Now render it into the control
AWindowInfo.Image.GetRawImage(lRawImage);
@ -856,7 +838,7 @@ begin
// Add the window to the list of windows
lWindowInfo := TX11WindowInfo.Create;
lWindowInfo.Window := lWindow;
lWindowInfo.LCLControl := AWinControl;
lWindowInfo.LCLForm := TCustomForm(AWinControl);
XGetWindowAttributes(CDWidgetSet.FDisplay, lWindow, @lWindowInfo.Attr);
lWindowInfo.Colormap := XDefaultColormap(CDWidgetSet.FDisplay, XDefaultScreen(CDWidgetSet.FDisplay));
lWindowInfo.ColorDepth := lWindowInfo.Attr.depth;