From 0748370917918fac28e8391a2fec4928dcf40a8f Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Wed, 23 Nov 2011 08:27:08 +0000 Subject: [PATCH] customdrawnws: Implements more skeletons for winapi canvas routines and fixes the color channels in Cocoa git-svn-id: trunk@33717 - --- lcl/interfaces/customdrawn/cocoaprivate.pas | 4 +- .../customdrawn/customdrawnproc.pas | 14 +++- .../customdrawn/customdrawnwinapi.inc | 72 +++++++++---------- .../customdrawn/customdrawnwinapih.inc | 12 ++-- 4 files changed, 55 insertions(+), 47 deletions(-) diff --git a/lcl/interfaces/customdrawn/cocoaprivate.pas b/lcl/interfaces/customdrawn/cocoaprivate.pas index 1845dda5a6..66e09d8268 100644 --- a/lcl/interfaces/customdrawn/cocoaprivate.pas +++ b/lcl/interfaces/customdrawn/cocoaprivate.pas @@ -673,6 +673,8 @@ var lWidth, lHeight: Integer; lBitmap, lMask: HBITMAP; lRawImage: TRawImage; + AImage: TLazIntfImage; + ACanvas: TLazCanvas; begin if not Assigned(Context) then Context:=TCocoaContext.Create; @@ -685,7 +687,7 @@ begin FillChar(struct, SizeOf(TPaintStruct), 0); UpdateControlLazImageAndCanvas(TCocoaCustomControl(Owner).Image, - TCocoaCustomControl(Owner).Canvas, lWidth, lHeight); + TCocoaCustomControl(Owner).Canvas, lWidth, lHeight, clfRGB24); struct.hdc := HDC(TCocoaCustomControl(Owner).Canvas); diff --git a/lcl/interfaces/customdrawn/customdrawnproc.pas b/lcl/interfaces/customdrawn/customdrawnproc.pas index d9a3d9052a..bfd9e00762 100644 --- a/lcl/interfaces/customdrawn/customdrawnproc.pas +++ b/lcl/interfaces/customdrawn/customdrawnproc.pas @@ -13,7 +13,11 @@ uses // GraphType, Controls, LCLMessageGlue, WSControls, LCLType, LCLProc; -procedure UpdateControlLazImageAndCanvas(var AImage: TLazIntfImage; var ACanvas: TLazCanvas; AWidth, AHeight: Integer); +type + TUpdateLazImageFormat = (clfRGB24, clfBGR24, clfBGRA32); + +procedure UpdateControlLazImageAndCanvas(var AImage: TLazIntfImage; + var ACanvas: TLazCanvas; AWidth, AHeight: Integer; AFormat: TUpdateLazImageFormat); function DateTimeToMilliseconds(aDateTime: TDateTime): Int64; function IsValidDC(ADC: HDC): Boolean; function IsValidGDIObject(AGDIObj: HGDIOBJ): Boolean; @@ -21,7 +25,7 @@ function IsValidGDIObject(AGDIObj: HGDIOBJ): Boolean; implementation procedure UpdateControlLazImageAndCanvas(var AImage: TLazIntfImage; - var ACanvas: TLazCanvas; AWidth, AHeight: Integer); + var ACanvas: TLazCanvas; AWidth, AHeight: Integer; AFormat: TUpdateLazImageFormat); var lRawImage: TRawImage; begin @@ -35,7 +39,11 @@ begin if (AImage <> nil) then AImage.Free; lRawImage.Init; - lRawImage.Description.Init_BPP32_B8G8R8A8_BIO_TTB(AWidth, AHeight); + case AFormat of + clfRGB24: lRawImage.Description.Init_BPP24_R8G8B8_BIO_TTB(AWidth, AHeight); + clfBGR24: lRawImage.Description.Init_BPP24_B8G8R8_BIO_TTB(AWidth, AHeight); + clfBGRA32: lRawImage.Description.Init_BPP32_B8G8R8A8_BIO_TTB(AWidth, AHeight); + end; lRawImage.CreateData(True); AImage := TLazIntfImage.Create(AWidth, AHeight); diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi.inc b/lcl/interfaces/customdrawn/customdrawnwinapi.inc index bac0fab882..a27a9247e5 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapi.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapi.inc @@ -784,7 +784,7 @@ begin if not IsValidDC(hDC) then exit; TQtDeviceContext(hDC).Free; -end; +end;*) {------------------------------------------------------------------------------ Function: DeleteObject @@ -792,31 +792,29 @@ end; Returns: Nothing ------------------------------------------------------------------------------} -function TQtWidgetSet.DeleteObject(GDIObject: HGDIOBJ): Boolean; +function TCDWidgetSet.DeleteObject(GDIObject: HGDIOBJ): Boolean; var aObject: TObject; - APaintEngine: QPaintEngineH; - APainter: QPainterH; - {$ifdef VerboseQtWinAPI} +// APaintEngine: QPaintEngineH; +// APainter: QPainterH; + {$ifdef VerboseWinAPI} ObjType: string; {$endif} begin - {$ifdef VerboseQtWinAPI} - WriteLn('Trace:> [WinAPI DeleteObject] GDIObject: ', dbghex(GDIObject)); + {$ifdef VerboseWinAPI} + DebugLn('Trace:> [WinAPI DeleteObject] GDIObject: ', dbghex(GDIObject)); ObjType := 'Unidentifyed'; {$endif} Result := False; - if GDIObject = 0 then - Exit(True); + if GDIObject = 0 then Exit(True); - if not IsValidGDIObject(GDIObject) then - Exit; + if not IsValidGDIObject(GDIObject) then Exit; aObject := TObject(GDIObject); - if (aObject is TQtResource) and TQtResource(aObject).FShared then +(* if (aObject is TQtResource) and TQtResource(aObject).FShared then Exit(True); {------------------------------------------------------------------------------ @@ -889,16 +887,16 @@ begin begin //WriteLn('Delete object: ', PtrUInt(AObject)); FreeThenNil(AObject); - end; + end;*) Result := True; - {$ifdef VerboseQtWinAPI} - WriteLn('Trace:< [WinAPI DeleteObject] Result=', dbgs(Result), ' ObjectType=', ObjType); + {$ifdef VerboseWinAPI} + DebugLn('Trace:< [WinAPI DeleteObject] Result=', dbgs(Result), ' ObjectType=', ObjType); {$endif} end; -function TQtWidgetSet.DestroyCaret(Handle: HWND): Boolean; +(*function TQtWidgetSet.DestroyCaret(Handle: HWND): Boolean; begin Result := (Handle <> 0) and QtCaret.DestroyCaret; end; @@ -4710,7 +4708,7 @@ var begin ACritSec:=System.PRTLCriticalSection(CritSection); System.LeaveCriticalsection(ACritSec^); -end; +end;*) {------------------------------------------------------------------------------ Function: LineTo @@ -4719,28 +4717,29 @@ end; ------------------------------------------------------------------------------} -function TQtWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean; +function TCDWidgetSet.LineTo(DC: HDC; X, Y: Integer): Boolean; var PenPos, LastPos: TPoint; + LazDC: TLazCanvas absolute DC; begin - {$ifdef VerboseQtWinAPI} - WriteLn('[WinAPI LineTo]'); + {$ifdef VerboseWinAPI} + DebugLn('[TCDWidgetSet.LineTo]'); {$endif} Result := False; if not IsValidDC(DC) then Exit; - TQtDeviceContext(DC).getPenPos(@PenPos); +(* TQtDeviceContext(DC).getPenPos(@PenPos); LastPos := Point(X, Y); if TQtDeviceContext(DC).pen.getCosmetic then LastPos := TQtDeviceContext(DC).GetLineLastPixelPos(PenPos, LastPos); TQtDeviceContext(DC).drawLine(PenPos.X, PenPos.Y, LastPos.X, LastPos.Y); - MoveToEx(DC, X, Y, nil); + MoveToEx(DC, X, Y, nil);*) Result := True; end; - +(* function TQtWidgetSet.LPtoDP(DC: HDC; var Points; Count: Integer): BOOL; var P: PPoint; @@ -4782,19 +4781,19 @@ begin TitleStr := GetUtf8String(lpCaption); OkStr := GetUtf8String('Ok'); Result := QMessageBox_information(TQtWidget(hWnd).Widget, @Str, @TitleStr, @OkStr); -end; +end;*) {------------------------------------------------------------------------------ Function: MoveToEx Params: none Returns: Nothing - - ------------------------------------------------------------------------------} -function TQtWidgetSet.MoveToEx(DC: HDC; X, Y: Integer; OldPoint: PPoint): Boolean; +function TCDWidgetSet.MoveToEx(DC: HDC; X, Y: Integer; OldPoint: PPoint): Boolean; +var + LazDC: TLazCanvas absolute DC; begin - {$ifdef VerboseQtWinAPI} - WriteLn('[WinAPI MoveToEx]', + {$ifdef VerboseWinAPI} + DebugLn('[WinAPI MoveToEx]', ' DC:', dbghex(DC), ' X:', dbgs(X), ' Y:', dbgs(Y)); @@ -4804,14 +4803,14 @@ begin if not IsValidDC(DC) then Exit; - if (OldPoint <> nil) then TQtDeviceContext(DC).getPenPos(OldPoint); + if (OldPoint <> nil) then OldPoint^ := LazDC.PenPos; - TQtDeviceContext(DC).setPenPos(X, Y); + LazDC.PenPos := Types.Point(X, Y); Result := True; end; -function TQtWidgetSet.OffsetRgn(RGN: HRGN; nXOffset, nYOffset: Integer): Integer; +(*function TQtWidgetSet.OffsetRgn(RGN: HRGN; nXOffset, nYOffset: Integer): Integer; var QtRgn: QRegionH; begin @@ -4937,8 +4936,6 @@ function TCDWidgetSet.Rectangle(DC: HDC; X1, Y1, X2, Y2: Integer): Boolean; var LazDC: TLazCanvas absolute DC; begin - if DC = 0 then Exit; - {$ifdef VerboseWinAPI} DebugLn(Format(':>[WinAPI Rectangle] DC=%s', [dbghex(DC)])); {$endif} @@ -4955,11 +4952,12 @@ begin DebugLn(Format('::[WinAPI Rectangle] DC.Width=%d DC.Height=%d', [LazDC.Width, LazDC.Height])); {$endif} - LazDC.Rectangle(X1, Y1, X2, Y2); + // ToDo: Normalize the rectangle, or improve TLazCanvas so that it accepts invalid coordinates { R := NormalizeRect(Rect(X1, Y1, X2, Y2)); - if IsRectEmpty(R) then Exit(True); + if IsRectEmpty(R) then Exit(True);} + + LazDC.Rectangle(X1, Y1, X2, Y2); - TQtDeviceContext(DC).drawRect(R.Left, R.Top, R.Right - R.Left - 1, R.Bottom - R.Top - 1);} Result := True; end; (* diff --git a/lcl/interfaces/customdrawn/customdrawnwinapih.inc b/lcl/interfaces/customdrawn/customdrawnwinapih.inc index 401b6538ba..5f39328de2 100644 --- a/lcl/interfaces/customdrawn/customdrawnwinapih.inc +++ b/lcl/interfaces/customdrawn/customdrawnwinapih.inc @@ -64,9 +64,9 @@ function CreatePolygonRgn(Points: PPoint; NumPts: Integer; FillMode: integer): H function CreateRectRgn(X1, Y1, X2, Y2: Integer): HRGN; override; procedure DeleteCriticalSection(var CritSection: TCriticalSection); override; -function DeleteDC(hDC: HDC): Boolean; override; +function DeleteDC(hDC: HDC): Boolean; override;*) function DeleteObject(GDIObject: HGDIOBJ): Boolean; override; -function DestroyCaret(Handle : HWND): Boolean; override; +(*function DestroyCaret(Handle : HWND): Boolean; override; function DestroyIcon(Handle: HICON): Boolean; override; function DPtoLP(DC: HDC; var Points; Count: Integer): BOOL; override; function DrawEdge(DC: HDC; var Rect: TRect; edge: Cardinal; grfFlags: Cardinal): Boolean; override; @@ -155,14 +155,14 @@ function IsWindowEnabled(Handle: HWND): boolean; override; function IsWindowVisible(Handle: HWND): boolean; override; function IsZoomed(Handle: HWND): boolean; override; -procedure LeaveCriticalSection(var CritSection: TCriticalSection); override; +procedure LeaveCriticalSection(var CritSection: TCriticalSection); override;*) function LineTo(DC: HDC; X, Y: Integer): Boolean; override; -function LPtoDP(DC: HDC; var Points; Count: Integer): BOOL; override; +(*function LPtoDP(DC: HDC; var Points; Count: Integer): BOOL; override; -function MessageBox(hWnd: HWND; lpText, lpCaption: PChar; uType: Cardinal): integer; override; +function MessageBox(hWnd: HWND; lpText, lpCaption: PChar; uType: Cardinal): integer; override;*) function MoveToEx(DC: HDC; X, Y: Integer; OldPoint: PPoint): Boolean; override; -function OffsetRgn(RGN: HRGN; nXOffset, nYOffset: Integer): Integer; override; +(*function OffsetRgn(RGN: HRGN; nXOffset, nYOffset: Integer): Integer; override; function PeekMessage(var lpMsg : TMsg; Handle : HWND; wMsgFilterMin, wMsgFilterMax,wRemoveMsg : UINT): Boolean; override; function PolyBezier(DC: HDC; Points: PPoint; NumPts: Integer; Filled, Continuous: boolean): boolean; override;