LCL-CustomDrawn: Implements some more generic winapis

git-svn-id: trunk@37084 -
This commit is contained in:
sekelsenmat 2012-04-29 15:52:53 +00:00
parent b5a7e440c9
commit 4cd0f4db3c
6 changed files with 152 additions and 271 deletions

View File

@ -2034,108 +2034,44 @@ begin
Result := HPEN(lPen);
end;
(*function TQtWidgetSet.ExtSelectClipRGN(dc: hdc; rgn : hrgn; Mode : Longint) : Integer;
function TCDWidgetSet.ExtSelectClipRGN(dc: hdc; rgn: hrgn; Mode: Longint) : Integer;
var
Clip: HRGN = 0;
Tmp : hRGN;
DCOrigin: TPoint;
QtWidget: TQtWidget = nil;
QtDC: TQtDeviceContext;
QtRgn: TQtRegion;
R: TRect;
LazDC: TLazCanvas absolute DC;
lRegion: TLazRegion absolute rgn;
begin
{$ifdef VerboseQtWinAPI}
WriteLn('[WinAPI TQtWidgetSet.ExtSelectClipRGN]');
{$ifdef VerboseCDWinAPI}
DebugLn('[TCDWidgetSet.SelectClipRGN] DC=', dbgs(DC),' RGN=', dbghex(RGN));
{$endif}
if not IsValidDC(DC) then
Result := ERROR;
// Activating this code break the drawing of TStringGrid. ToDo: Find out why
{ if not IsValidDC(DC) then exit;
// RGN=0 indicates that the clipping region should be removed
if (RGN = 0) then
begin
Result := ERROR;
exit;
end else
Result := SIMPLEREGION;
TLazCanvas(LazDC.ClipRegion).Clear;
LazDC.Clipping := False;
Result := NullRegion;
Exit;
end;
QtDC := TQtDeviceContext(DC);
if LazDC.ClipRegion = nil then
LazDC.ClipRegion := TLazRegion.Create;
if Assigned(QtDC.Parent) then
QtWidget := QtObjectFromWidgetH(QtDC.Parent);
if Assigned(QtWidget) or
(not Assigned(QtWidget) and Assigned(QtDC.vImage)) then
begin
// there is no clipping region in the DC
case Mode of
RGN_COPY: Result := SelectClipRGN(DC, RGN);
RGN_OR,
RGN_XOR,
RGN_AND:
begin
// as MSDN says only RGN_COPY allows NULL RGN param.
if not IsValidGDIObject(RGN) then
begin
Result := ERROR;
exit;
end;
// get existing clip
QtRgn := QtDC.getClipRegion;
if (QtRgn = nil) or (QtRgn.GetRegionType = NULLREGION) then
begin
Result := SelectClipRGN(DC, RGN);
exit;
end;
// get transformation
GetWindowOrgEx(DC, @DCOrigin);
R := QtRgn.getBoundingRect;
Clip := CreateRectRGN(0, 0, R.Right - R.Left, R.Bottom - R.Top);
TQtRegion(Clip).translate(DCOrigin.X, DCOrigin.Y);
// create target clip
Tmp := CreateEmptyRegion;
// combine
Result := CombineRGN(Tmp, Clip, RGN, Mode);
// commit
SelectClipRGN(DC, Tmp);
// clean up
DeleteObject(Clip);
DeleteObject(Tmp);
end;
RGN_DIFF:
begin
// when substracting we must have active clipregion
// with all of its rects.
QtRgn := QtDC.getClipRegion;
if (QtRgn = nil) or (QtRgn.GetRegionType = NULLREGION) then
begin
Result := SelectClipRGN(DC, RGN);
exit;
end;
Tmp := CreateEmptyRegion;
Result := CombineRGN(Tmp, HRGN(QtRgn), RGN, MODE);
// X11 paintEngine comment only !
// we'll NOT reset num of rects here (performance problem) like we do
// in ExcludeClipRect, because this function must be correct,
// if someone want accurate ExcludeClipRect with X11 then
// use code from intfbasewinapi.inc TWidgetSet.ExcludeClipRect()
// which calls this function and then combineRgn.
SelectClipRGN(DC, Tmp);
DeleteObject(Tmp);
end;
end;
end
else
Result := inherited ExtSelectClipRGN(DC, RGN, Mode);
end;*)
// Never use LazDC.ClipRegion := RGN because we really need to make a copy of it
// The original handle might be freed afterwards
CombineRgn(HRGN(LazDC.ClipRegion), HRGN(LazDC.ClipRegion), RGN, Mode);
LazDC.Clipping := True;
Result := TLazRegion(RGN).GetRegionKind();}
end;
{$ifndef CD_UseNativeText}
{------------------------------------------------------------------------------
Function: ExtTextOut
Params: none
Returns: Nothing
------------------------------------------------------------------------------}
function TCDWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
@ -2257,71 +2193,44 @@ begin
Result := True;
end;
(*{------------------------------------------------------------------------------
{------------------------------------------------------------------------------
Function: FillRgn
Params: DC: HDC; RegionHnd: HRGN; hbr: HBRUSH
Returns: Boolean
------------------------------------------------------------------------------}
function TQtWidgetSet.FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool;
function TCDWidgetSet.FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool;
var
OldRgn: TQtRegion;
R: TRect;
hasClipping: Boolean;
QtDC: TQtDeviceContext;
LazDC: TLazCanvas absolute DC;
lRegion: TLazRegion absolute RegionHnd;
lRegionRect: TRect;
lOldBrush: HGDIOBJ;
lOldRegion: TLazRegion;
begin
{$ifdef VerboseQtWinAPI}
DebugLn('[WinAPI FillRgn Rgn=', dbgs(RegionHnd),' Brush=', dbghex(hbr));
{$ifdef VerboseCDWinAPI}
DebugLn('[TCDWidgetSet.FillRgn] Rgn=', dbgs(RegionHnd),' Brush=', dbghex(hbr));
{$endif}
Result := False;
if not IsValidDC(DC) then exit;
if hbr = 0 then Exit;
if RegionHnd = 0 then Exit;
QtDC := TQtDeviceContext(DC);
HasClipping := QtDC.getClipping;
QtDC.save;
if HasClipping then
OldRgn := TQtRegion.Create(True);
lOldBrush := SelectObject(DC, hbr);
try
if HasClipping then
QPainter_clipRegion(QtDC.Widget, OldRgn.FHandle);
if SelectClipRgn(DC, RegionHnd) <> ERROR then
begin
R := TQtRegion(RegionHnd).getBoundingRect;
QtDC.fillRect(@R, TQtBrush(hbr).FHandle);
if HasClipping then
SelectClipRgn(DC, HRGN(OldRgn));
Result := True;
end;
lOldRegion := TLazRegion.Create;
lOldRegion.Assign(TLazRegion(LazDC.ClipRegion));
lRegionRect := lRegion.GetBoundingRect();
LazDC.Rectangle(lRegionRect);
finally
if HasClipping then
OldRgn.Free;
QtDC.restore;
TLazRegion(LazDC.ClipRegion).Assign(lOldRegion);
lOldRegion.Free;
SelectObject(DC, lOldBrush);
end;
Result := True;
end;
{------------------------------------------------------------------------------
Function: Frame
Params: none
Returns: Nothing
Draws the border of a rectangle.
------------------------------------------------------------------------------}
function TQtWidgetSet.Frame(DC: HDC; const ARect: TRect): Integer;
begin
Result := 0;
if not IsValidDC(DC) then Exit;
TQtDeviceContext(DC).drawRect(ARect.Left, ARect.Top,
ARect.Right - ARect.Left, ARect.Bottom - ARect.Top);
Result := 1;
end;*)
{------------------------------------------------------------------------------
Function: Frame3D
Params: none
@ -3303,28 +3212,30 @@ begin
{$ifdef VerboseQtWinAPI}
WriteLn('Trace:< [WinAPI GetObject] Result=', dbgs(Result), ' ObjectType=', ObjType);
{$endif}
end;
function TQtWidgetSet.GetParent(Handle : HWND): HWND;
var
QtWidget: TQtWidget;
begin
{$ifdef VerboseQtWinAPI}
writeln('Trace:> [WinAPI GetParent] Handle: ' + dbghex(Handle));
{$endif}
Result := 0;
if Handle = 0 then
exit;
QtWidget := TQtWidget(Handle);
Result := HwndFromWidgetH(QtWidget.GetParent);
{$ifdef VerboseQtWinAPI}
writeln('Trace:< [WinAPI GetParent] : ' + dbghex(Result));
{$endif}
end;*)
function TCDWidgetSet.GetParent(Handle : HWND): HWND;
var
lHandle: TCDWinControl absolute Handle;
lWinControl: TWinControl;
begin
{$ifdef VerboseCDDrawing}
DebugLn(Format('[TCDWidgetSet.GetParent] Handle: ', [Handle]));
{$endif}
Result := 0;
// Invalid DC
if Handle = 0 then Exit;
if not IsValidDC(Handle) then Exit;
lWinControl := lHandle.GetWinControl();
if lWinControl = nil then Exit;
lWinControl := lWinControl.Parent;
if lWinControl = nil then Exit;
Result := lWinControl.Handle;
end;
function TCDWidgetSet.GetProp(Handle: hwnd; Str: PChar): Pointer;
begin
if Handle<>0 then
@ -5255,7 +5166,7 @@ begin
end;
Result := True;
end;
end;*)
{------------------------------------------------------------------------------
Function: SelectClipRGN
@ -5270,38 +5181,11 @@ end;
NullRegion
SimpleRegion
ComplexRegion
------------------------------------------------------------------------------}
function TQtWidgetSet.SelectClipRGN(DC: hDC; RGN: HRGN): Longint;
var
QtDC: TQtDeviceContext;
EmptyRegion: QRegionH;
P: TPoint;
function TCDWidgetSet.SelectClipRGN(DC: hDC; RGN: HRGN): Longint;
begin
Result := ERROR;
if IsValidDC(DC) then
begin
QtDC := TQtDeviceContext(DC);
if IsValidGDIObject(RGN) then
begin
Result := TQtRegion(Rgn).GetRegionType;
// RGN is in Device coordinates. Qt expects logical coordinates
// so we need to convert RGN coords.
GetWindowOrgEx(DC, @P);
TQtRegion(Rgn).translate(P.X, P.Y);
QtDC.setClipRegion(TQtRegion(Rgn).FHandle);
end else
begin
EmptyRegion := QRegion_create;
try
QtDC.setClipRegion(EmptyRegion, QtNoClip);
finally
QRegion_destroy(EmptyRegion);
end;
Result := NULLREGION;
end;
end;
end;*)
Result := ExtSelectClipRgn(DC, RGN, RGN_COPY);
end;
{------------------------------------------------------------------------------
Function: SelectObject

View File

@ -140,33 +140,17 @@ begin
WriteLn('***** [WinAPI TQtWidgetSet.CallWindowProc] missing implementation ');
{$endif}
Result := -1;
end;
end;*)
{------------------------------------------------------------------------------
Method: ClientToScreen
Params: Handle -
Returns:
------------------------------------------------------------------------------}
function TQtWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint) : Boolean;
var
APoint: TQtPoint;
Pt: TPoint;
function TCDWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint) : Boolean;
begin
Result := IsValidHandle(Handle);
if Result then
begin
APoint := QtPoint(P.X, P.Y);
QWidget_mapToGlobal(TQtWidget(Handle).GetContainerWidget, @APoint, @APoint);
if TQtWidget(Handle).ChildOfComplexWidget = ccwScrollingWinControl then
begin
Pt := TQtCustomControl(Handle).viewport.ScrolledOffset;
dec(APoint.X, Pt.X);
dec(APoint.Y, Pt.Y);
end;
P := Point(APoint.x, APoint.y);
end;
end;*)
Result := False;
end;
{------------------------------------------------------------------------------
Method: ClipboardGetData
@ -5144,28 +5128,19 @@ begin
{$ifdef VerboseQTWinAPI}
WriteLn('Trace:< [WinAPI SaveDC] result=', Result);
{$Endif}
end;
end;*)
{------------------------------------------------------------------------------
Function: ScreenToClient
Params: Handle: HWND; var P: TPoint
Returns:
-------------------------------------------------------------------------------}
function TQtWidgetSet.ScreenToClient(Handle : HWND; var P : TPoint) : Integer;
var
APoint: TQtPoint;
function TCDWidgetSet.ScreenToClient(Handle : HWND; var P : TPoint) : Integer;
begin
Result := 0;
if IsValidHandle(Handle) then
begin
APoint := QtPoint(P.X, P.Y);
QWidget_mapFromGlobal(TQtWidget(Handle).GetContainerWidget, @APoint, @APoint);
P := Point(APoint.x, APoint.y);
Result := 1;
end;
end;
{------------------------------------------------------------------------------
(*{------------------------------------------------------------------------------
Method: ScrollWindowEx
Params: HWnd - handle of window to scroll
DX - horizontal amount to scroll

View File

@ -20,6 +20,37 @@
*****************************************************************************
}
function TCDWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint) : Boolean;
var
ControlHandle: TCDBaseControl;
lControl: TWinControl;
winhandle: TCocoaWindow absolute Handle;
lPoint: NSPoint;
begin
Result := False;
if Handle = 0 then Exit;
// Go throught the non-native controls
ControlHandle := TCDBaseControl(Handle);
while not (ControlHandle is TCDForm) do
begin
lControl := ControlHandle.GetWinControl();
lControl := lControl.Parent;
if lControl = nil then Exit;
ControlHandle := TCDBaseControl(lControl.Handle);
P.X := P.X - lControl.Left;
P.Y := P.Y - lControl.Top;
end;
// Now actually do the convertion
lPoint.x := P.X;
lPoint.Y := P.Y;
lPoint := winhandle.CocoaForm.convertBaseToScreen(lPoint);
P.x := Round(lPoint.X);
P.Y := Round(lPoint.Y);
Result := True;
end;
function TCDWidgetSet.ClipboardGetData(ClipboardType: TClipboardType;
FormatID: TClipboardFormat; Stream: TStream): boolean;
begin
@ -995,4 +1026,20 @@ begin
end;
end;*)
{------------------------------------------------------------------------------
Method: ScreenToClient
Params: Handle - window handle for source coordinates
P - record containing coordinates
Returns: if the function succeeds, the return value is nonzero; if the
function fails, the return value is zero
Converts the screen coordinates of a specified point on the screen to client
coordinates.
------------------------------------------------------------------------------}
function TCDWidgetSet.ScreenToClient(Handle: HWND; Var P: TPoint): Integer;
begin
Result := 0;
//Result := Integer(Windows.ScreenToClient(Handle, @P));
end;
//##apiwiz##eps## // Do not remove, no wizard declaration after this line

View File

@ -270,7 +270,7 @@ function TWin32WidgetSet.CallWindowProc(LPPrevWndFunc: TFarProc; Handle: HWND;
Msg: UINT; WParam: WParam; LParam: LParam): Integer;
begin
Result := Windows.CallWindowProc(WNDPROC(LPPrevWndFunc), Handle, Msg, Windows.WPARAM(WParam), Windows.LPARAM(LParam));
end;
end;*)
{------------------------------------------------------------------------------
Method: ClientToScreen
@ -280,17 +280,16 @@ end;
Converts client coordinates to screen coordinates
------------------------------------------------------------------------------}
function TWin32WidgetSet.ClientToScreen(Handle: HWND; var P: TPoint): Boolean;
var
ORect: TRect;
function TCDWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint): Boolean;
begin
Result := Boolean(Windows.ClientToScreen(Handle, @P));
Result := False;
{ Result := Boolean(Windows.ClientToScreen(Handle, @P));
if not Result then exit;
Result := GetLCLClientBoundsOffset(Handle, ORect);
if not Result then exit;
inc(P.X, ORect.Left);
inc(P.Y, ORect.Top);
end;*)
inc(P.Y, ORect.Top);}
end;
{------------------------------------------------------------------------------
Method: ClipboardGetData
@ -2938,7 +2937,7 @@ end;
function TWin32WidgetSet.SaveDC(DC: HDC): Integer;
begin
Result := Windows.SaveDC(DC);
end;
end;*)
{------------------------------------------------------------------------------
Method: ScreenToClient
@ -2950,12 +2949,13 @@ end;
Converts the screen coordinates of a specified point on the screen to client
coordinates.
------------------------------------------------------------------------------}
function TWin32WidgetSet.ScreenToClient(Handle: HWND; Var P: TPoint): Integer;
function TCDWidgetSet.ScreenToClient(Handle: HWND; Var P: TPoint): Integer;
begin
Result := Integer(Windows.ScreenToClient(Handle, @P));
Result := 0;
//Result := Integer(Windows.ScreenToClient(Handle, @P));
end;
{------------------------------------------------------------------------------
(*{------------------------------------------------------------------------------
Method: ScrollWindowEx
Params: HWnd - handle of window to scroll
DX - horizontal amount to scroll

View File

@ -140,33 +140,17 @@ begin
WriteLn('***** [WinAPI TQtWidgetSet.CallWindowProc] missing implementation ');
{$endif}
Result := -1;
end;
end;*)
{------------------------------------------------------------------------------
Method: ClientToScreen
Params: Handle -
Returns:
------------------------------------------------------------------------------}
function TQtWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint) : Boolean;
var
APoint: TQtPoint;
Pt: TPoint;
function TCDWidgetSet.ClientToScreen(Handle: HWND; var P: TPoint) : Boolean;
begin
Result := IsValidHandle(Handle);
if Result then
begin
APoint := QtPoint(P.X, P.Y);
QWidget_mapToGlobal(TQtWidget(Handle).GetContainerWidget, @APoint, @APoint);
if TQtWidget(Handle).ChildOfComplexWidget = ccwScrollingWinControl then
begin
Pt := TQtCustomControl(Handle).viewport.ScrolledOffset;
dec(APoint.X, Pt.X);
dec(APoint.Y, Pt.Y);
end;
P := Point(APoint.x, APoint.y);
end;
end;*)
Result := False;
end;
function TCDWidgetSet.ClipboardGetData(ClipboardType: TClipboardType;
FormatID: TClipboardFormat; Stream: TStream): boolean;
@ -5130,28 +5114,19 @@ begin
{$ifdef VerboseQTWinAPI}
WriteLn('Trace:< [WinAPI SaveDC] result=', Result);
{$Endif}
end;
end;*)
{------------------------------------------------------------------------------
Function: ScreenToClient
Params: Handle: HWND; var P: TPoint
Returns:
-------------------------------------------------------------------------------}
function TQtWidgetSet.ScreenToClient(Handle : HWND; var P : TPoint) : Integer;
var
APoint: TQtPoint;
function TCDWidgetSet.ScreenToClient(Handle : HWND; var P : TPoint) : Integer;
begin
Result := 0;
if IsValidHandle(Handle) then
begin
APoint := QtPoint(P.X, P.Y);
QWidget_mapFromGlobal(TQtWidget(Handle).GetContainerWidget, @APoint, @APoint);
P := Point(APoint.x, APoint.y);
Result := 1;
end;
end;
{------------------------------------------------------------------------------
(*{------------------------------------------------------------------------------
Method: ScrollWindowEx
Params: HWnd - handle of window to scroll
DX - horizontal amount to scroll

View File

@ -40,8 +40,8 @@ function BeginPaint(Handle: hWnd; Var PS : TPaintStruct) : hdc; override;
function BitBlt(DestDC: HDC; X, Y, Width, Height: Integer; SrcDC: HDC; XSrc, YSrc: Integer; Rop: DWORD): Boolean; override;
(*function CallNextHookEx(hHk: HHOOK; ncode : Integer; wParam: WParam; lParam : LParam) : Integer; override;
function CallWindowProc(lpPrevWndFunc : TFarProc; Handle : HWND; Msg : UINT; wParam: WParam; lParam : lParam) : Integer; override;
function ClientToScreen(Handle: HWND; var P: TPoint) : Boolean; override;*)
function CallWindowProc(lpPrevWndFunc : TFarProc; Handle : HWND; Msg : UINT; wParam: WParam; lParam : lParam) : Integer; override;*)
function ClientToScreen(Handle: HWND; var P: TPoint) : Boolean; override;
function ClipboardFormatToMimeType(FormatID: TClipboardFormat): string; override;
function ClipboardGetData(ClipboardType: TClipboardType;
@ -93,11 +93,11 @@ procedure EnterCriticalSection(var CritSection: TCriticalSection); override;
function EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont; Callback: FontEnumExProc; Lparam: LParam; Flags: dword): longint; override;
//function ExcludeClipRect(dc: hdc; Left, Top, Right, Bottom : Integer) : Integer; override;
function ExtCreatePen(dwPenStyle, dwWidth: DWord; const lplb: TLogBrush; dwStyleCount: DWord; lpStyle: PDWord): HPEN; override;
//function ExtSelectClipRGN(dc: hdc; rgn : hrgn; Mode : Longint) : Integer; override;
function ExtSelectClipRGN(dc: hdc; rgn : hrgn; Mode : Longint) : Integer; override;
function ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint; Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean; override;
function FillRect(DC: HDC; const Rect: TRect; Brush: HBRUSH): Boolean; override;
//function FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool; override;
function FillRgn(DC: HDC; RegionHnd: HRGN; hbr: HBRUSH): Bool; override;
function Frame3d(DC: HDC; var ARect: TRect; const FrameWidth : integer; const Style : TBevelCut): Boolean; override;
function FrameRect(DC: HDC; const ARect: TRect; hBr: HBRUSH): Integer; override;
@ -126,8 +126,8 @@ function GetFocus: HWND; override;
function GetKeyState(nVirtKey: Integer): Smallint; override;
(*function GetMapMode(DC: HDC): Integer; override;
function GetMonitorInfo(Monitor: HMONITOR; lpmi: PMonitorInfo): Boolean; override;
function GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer; override;
function GetParent(Handle : HWND): HWND; override;*)
function GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer; override;*)
function GetParent(Handle : HWND): HWND; override;
function GetProp(Handle : hwnd; Str : PChar): Pointer; override;
function GetRgnBox(RGN : HRGN; lpRect : PRect) : Longint; override;
(*function GetROP2(DC: HDC): Integer; override;
@ -193,9 +193,9 @@ function RestoreDC(DC: HDC; SavedDC: Integer): Boolean; override;
//function RoundRect(DC : hDC; X1, Y1, X2, Y2: Integer; RX,RY : Integer): Boolean; override;
function SaveDC(DC: HDC): Integer; override;
//function ScreenToClient(Handle : HWND; var P : TPoint) : Integer; override;
function ScreenToClient(Handle : HWND; var P : TPoint) : Integer; override;
//function ScrollWindowEx(HWnd: HWND; DX, DY: Integer; PRcScroll, PRcClip: PRect; HRgnUpdate: HRGN; PRcUpdate: PRect; Flags: UINT): Boolean; override;
//function SelectClipRGN(DC : hDC; RGN : HRGN) : Longint; override;
function SelectClipRGN(DC : hDC; RGN : HRGN) : Longint; override;
function SelectObject(DC: HDC; GDIObj: HGDIOBJ): HGDIOBJ; override;
(*function SendMessage(HandleWnd: HWND; Msg: Cardinal; WParam: WParam; LParam: LParam): LResult; override;
function SetActiveWindow(Handle: HWND): HWND; override;