From bbf9512a32990538ef734a4956f48f33c9dd808e Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 2 Dec 2011 09:56:12 +0000 Subject: [PATCH] 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 - --- .../customdrawn/customdrawn_x11proc.pas | 9 +----- lcl/interfaces/customdrawn/customdrawnint.pas | 1 + .../customdrawn/customdrawnobject.inc | 2 ++ .../customdrawn/customdrawnobject_x11.inc | 2 +- .../customdrawn/customdrawnproc.pas | 29 +++++++++++++++++-- .../customdrawn/customdrawnwinapi.inc | 28 ++++++++++++------ .../customdrawn/customdrawnwinapi_android.inc | 4 +-- .../customdrawn/customdrawnwinapi_cocoa.inc | 4 +-- .../customdrawn/customdrawnwinapi_win.inc | 4 +-- .../customdrawn/customdrawnwinapi_x11.inc | 6 ++-- .../customdrawn/customdrawnwinapih.inc | 1 - .../customdrawn/customdrawnwscontrols.pp | 2 +- .../customdrawn/customdrawnwsforms.pp | 2 -- .../customdrawnwsforms_android.inc | 18 ------------ .../customdrawn/customdrawnwsforms_x11.inc | 22 ++------------ 15 files changed, 63 insertions(+), 71 deletions(-) diff --git a/lcl/interfaces/customdrawn/customdrawn_x11proc.pas b/lcl/interfaces/customdrawn/customdrawn_x11proc.pas index c237db6b7e..8d5bc001db 100644 --- a/lcl/interfaces/customdrawn/customdrawn_x11proc.pas +++ b/lcl/interfaces/customdrawn/customdrawn_x11proc.pas @@ -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; diff --git a/lcl/interfaces/customdrawn/customdrawnint.pas b/lcl/interfaces/customdrawn/customdrawnint.pas index 80ccb67d67..3116ce1666 100644 --- a/lcl/interfaces/customdrawn/customdrawnint.pas +++ b/lcl/interfaces/customdrawn/customdrawnint.pas @@ -151,6 +151,7 @@ type procedure BackendCreate; procedure BackendDestroy; public + ScreenDC: TLazCanvas; constructor Create; override; destructor Destroy; override; diff --git a/lcl/interfaces/customdrawn/customdrawnobject.inc b/lcl/interfaces/customdrawn/customdrawnobject.inc index bacab51fb2..e8b77d1f0b 100644 --- a/lcl/interfaces/customdrawn/customdrawnobject.inc +++ b/lcl/interfaces/customdrawn/customdrawnobject.inc @@ -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; diff --git a/lcl/interfaces/customdrawn/customdrawnobject_x11.inc b/lcl/interfaces/customdrawn/customdrawnobject_x11.inc index a4e2310fb9..8de86f77b6 100644 --- a/lcl/interfaces/customdrawn/customdrawnobject_x11.inc +++ b/lcl/interfaces/customdrawn/customdrawnobject_x11.inc @@ -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} diff --git a/lcl/interfaces/customdrawn/customdrawnproc.pas b/lcl/interfaces/customdrawn/customdrawnproc.pas index 1a11167aca..d49ee83520 100644 --- a/lcl/interfaces/customdrawn/customdrawnproc.pas +++ b/lcl/interfaces/customdrawn/customdrawnproc.pas @@ -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; diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi.inc b/lcl/interfaces/customdrawn/customdrawnwinapi.inc index ce9c81f1c2..46153754b2 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapi.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapi.inc @@ -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)); diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc b/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc index 97bb6f100a..e076ac1348 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapi_android.inc @@ -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; diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi_cocoa.inc b/lcl/interfaces/customdrawn/customdrawnwinapi_cocoa.inc index 18b566b907..e8c67cf24a 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapi_cocoa.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapi_cocoa.inc @@ -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 diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi_win.inc b/lcl/interfaces/customdrawn/customdrawnwinapi_win.inc index 5fd4d98669..bc6f1f3828 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapi_win.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapi_win.inc @@ -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 diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi_x11.inc b/lcl/interfaces/customdrawn/customdrawnwinapi_x11.inc index e1968c253e..35b115acd8 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapi_x11.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapi_x11.inc @@ -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; diff --git a/lcl/interfaces/customdrawn/customdrawnwinapih.inc b/lcl/interfaces/customdrawn/customdrawnwinapih.inc index 2b5a918114..61ca39b984 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapih.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapih.inc @@ -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; diff --git a/lcl/interfaces/customdrawn/customdrawnwscontrols.pp b/lcl/interfaces/customdrawn/customdrawnwscontrols.pp index fc48a2571b..9f139c41e5 100644 --- a/lcl/interfaces/customdrawn/customdrawnwscontrols.pp +++ b/lcl/interfaces/customdrawn/customdrawnwscontrols.pp @@ -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 diff --git a/lcl/interfaces/customdrawn/customdrawnwsforms.pp b/lcl/interfaces/customdrawn/customdrawnwsforms.pp index 7c83718ddc..711be7178e 100644 --- a/lcl/interfaces/customdrawn/customdrawnwsforms.pp +++ b/lcl/interfaces/customdrawn/customdrawnwsforms.pp @@ -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; diff --git a/lcl/interfaces/customdrawn/customdrawnwsforms_android.inc b/lcl/interfaces/customdrawn/customdrawnwsforms_android.inc index 07b438d8a9..f2c5d83b6c 100644 --- a/lcl/interfaces/customdrawn/customdrawnwsforms_android.inc +++ b/lcl/interfaces/customdrawn/customdrawnwsforms_android.inc @@ -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 diff --git a/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc b/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc index f6a30324ed..4dd1d11adf 100644 --- a/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc +++ b/lcl/interfaces/customdrawn/customdrawnwsforms_x11.inc @@ -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;