mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 20:49:30 +02:00
Adapts lazcanvas to the new fpcanvas capabilities, Improves the region sizing, adapts the customdrawn backends to support selecting native vs non-native text, removes an undesired resourcestring usage from customdrawncontrols and fixes the checkbox in all customdrawn platforms
git-svn-id: trunk@34022 -
This commit is contained in:
parent
c98a4639c4
commit
68d181cd00
@ -645,7 +645,7 @@ type
|
||||
|
||||
implementation
|
||||
|
||||
resourcestring
|
||||
const
|
||||
sTABSHEET_DEFAULT_NAME = 'CTabSheet';
|
||||
|
||||
{ TCDPanel }
|
||||
|
@ -34,6 +34,18 @@ begin
|
||||
CDWidgetSet := Self;
|
||||
FTerminating := False;
|
||||
|
||||
{$ifndef CD_UseNativeText}
|
||||
// Create the dummy screen DC
|
||||
ScreenBitmapRawImage.Init;
|
||||
ScreenBitmapHeight := 100;
|
||||
ScreenBitmapWidth := 100;
|
||||
ScreenBitmapRawImage.Description.Init_BPP32_A8R8G8B8_BIO_TTB(ScreenBitmapWidth, ScreenBitmapHeight);
|
||||
ScreenBitmapRawImage.CreateData(True);
|
||||
ScreenImage := TLazIntfImage.Create(0, 0);
|
||||
ScreenImage.SetRawImage(ScreenBitmapRawImage);
|
||||
ScreenDC := TLazCanvas.Create(ScreenImage);
|
||||
{$endif}
|
||||
|
||||
BackendCreate;
|
||||
end;
|
||||
|
||||
@ -48,6 +60,12 @@ destructor TCDWidgetSet.Destroy;
|
||||
begin
|
||||
BackendDestroy;
|
||||
|
||||
{$ifndef CD_UseNativeText}
|
||||
// Free the dummy screen DC
|
||||
ScreenImage.Free;
|
||||
ScreenDC.Free;
|
||||
{$endif}
|
||||
|
||||
CDWidgetSet := nil;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
@ -106,6 +106,7 @@ begin
|
||||
{ Creates the AutoreleasePool }
|
||||
pool := NSAutoreleasePool(NSAutoreleasePool.alloc).init;
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{ Prepares the Native DC for the ScreenDC }
|
||||
|
||||
{ NSImage / NSBitmapImageRep are very limited. They simply don't support
|
||||
@ -139,6 +140,7 @@ begin
|
||||
ScreenDC := TLazCanvas.Create(ScreenImage);
|
||||
ScreenDC.NativeDC := PtrInt(TCocoaContext.Create);
|
||||
TCocoaContext(ScreenDC.NativeDC).cgctx := ScreenBitmapContext; //NSGraphicsContext.graphicsContextWithBitmapImageRep(ScreenBitmap.imagerep);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -151,10 +153,12 @@ begin
|
||||
{ Releases the AutoreleasePool }
|
||||
pool.release;
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{ Release the screen DC and Image}
|
||||
ScreenDC.Free;
|
||||
ScreenImage.Free;
|
||||
// ScreenBitmap.Free;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -57,7 +57,6 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCDWidgetSet.BackendCreate;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -69,7 +68,6 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TCDWidgetSet.BackendDestroy;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
|
@ -304,7 +304,6 @@ begin
|
||||
ACanvas.Clipping := True;
|
||||
lCDWinControl.Region.Rect := Bounds(lBaseWindowOrg.X, lBaseWindowOrg.Y, lWinControl.Width, lWinControl.Height);
|
||||
ACanvas.ClipRegion := lCDWinControl.Region;
|
||||
ACanvas.UseRegionClipping := True;
|
||||
|
||||
// Save the Canvas state
|
||||
ACanvas.SaveState;
|
||||
|
@ -2175,8 +2175,9 @@ begin
|
||||
end
|
||||
else
|
||||
Result := inherited ExtSelectClipRGN(DC, RGN, Mode);
|
||||
end;
|
||||
end;*)
|
||||
|
||||
{$ifndef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Function: ExtTextOut
|
||||
Params: none
|
||||
@ -2184,20 +2185,20 @@ end;
|
||||
|
||||
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
|
||||
function TCDWidgetSet.ExtTextOut(DC: HDC; X, Y: Integer; Options: Longint;
|
||||
Rect: PRect; Str: PChar; Count: Longint; Dx: PInteger): Boolean;
|
||||
var
|
||||
{var
|
||||
WideStr: WideString;
|
||||
QtDC: TQtDeviceContext absolute DC;
|
||||
B: Boolean;
|
||||
B: Boolean; }
|
||||
begin
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
{$ifdef VerboseCDWinAPI}
|
||||
WriteLn('[WinAPI ExtTextOut]');
|
||||
{$endif}
|
||||
|
||||
Result := False;
|
||||
|
||||
if ((Options and (ETO_OPAQUE + ETO_CLIPPED)) <> 0) and (Rect = nil) then
|
||||
{if ((Options and (ETO_OPAQUE + ETO_CLIPPED)) <> 0) and (Rect = nil) then
|
||||
exit;
|
||||
|
||||
if not IsValidDC(DC) then Exit;
|
||||
@ -2225,10 +2226,11 @@ begin
|
||||
QtDC.restore;
|
||||
end else
|
||||
QtDC.drawText(X, Y, @WideStr);
|
||||
end;
|
||||
end;}
|
||||
|
||||
Result := True;
|
||||
end;*)
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
Function: FillRect
|
||||
@ -4021,24 +4023,27 @@ begin
|
||||
ColorRefToTQColor(TColorRef(QtDC.vTextColor), Color);
|
||||
TQColorToColorRef(Color, Result);
|
||||
end;
|
||||
end;
|
||||
end;*)
|
||||
|
||||
{$ifndef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Function: GetTextExtentExPoint
|
||||
Params: http://msdn.microsoft.com/en-us/library/dd144935%28VS.85%29.aspx
|
||||
Returns: True on success
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.GetTextExtentExPoint(DC: HDC; Str: PChar; Count,
|
||||
function TCDWidgetSet.GetTextExtentExPoint(DC: HDC; Str: PChar; Count,
|
||||
MaxWidth: Integer; MaxCount, PartialWidths: PInteger; var Size: TSize
|
||||
): Boolean;
|
||||
var
|
||||
{var
|
||||
i: Integer;
|
||||
w: Integer;
|
||||
AStr: WideString;
|
||||
Accu: Integer;
|
||||
Accu: Integer; }
|
||||
begin
|
||||
Result := False;
|
||||
if not IsValidDC(DC) then Exit;
|
||||
// Result := False;
|
||||
Result := inherited GetTextExtentExPoint(DC, Str, Count, MaxWidth,
|
||||
MaxCount, PartialWidths, Size);
|
||||
{if not IsValidDC(DC) then Exit;
|
||||
with TQtDeviceContext(DC) do
|
||||
begin
|
||||
AStr := GetUtf8String(Str);
|
||||
@ -4087,7 +4092,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
Result := True;
|
||||
Result := True;}
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -4095,10 +4100,10 @@ end;
|
||||
Params: none
|
||||
Returns: Nothing
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
|
||||
var
|
||||
function TCDWidgetSet.GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean;
|
||||
{var
|
||||
WideStr: WideString;
|
||||
QtDC: TQtDeviceContext absolute DC;
|
||||
QtDC: TQtDeviceContext absolute DC; }
|
||||
begin
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
WriteLn('[WinAPI GetTextExtentPoint]');
|
||||
@ -4106,11 +4111,11 @@ begin
|
||||
|
||||
Result := False;
|
||||
|
||||
if not IsValidDC(DC) then Exit;
|
||||
{ if not IsValidDC(DC) then Exit;
|
||||
|
||||
WideStr := GetUtf8String(Str);
|
||||
Size.cx := QtDC.Metrics.width(@WideStr, Count);
|
||||
Size.cy := QtDC.Metrics.height;
|
||||
Size.cy := QtDC.Metrics.height; }
|
||||
|
||||
Result := True;
|
||||
end;
|
||||
@ -4121,12 +4126,12 @@ end;
|
||||
TM - The structure to receive the font information
|
||||
Returns: If successfull
|
||||
------------------------------------------------------------------------------}
|
||||
function TQtWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
|
||||
var
|
||||
function TCDWidgetSet.GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean;
|
||||
{var
|
||||
QtFontMetrics: TQtFontMetrics;
|
||||
FontFamily: WideString;
|
||||
QtDC: TQtDeviceContext absolute DC;
|
||||
FontWeight: Integer;
|
||||
FontWeight: Integer; }
|
||||
begin
|
||||
{$ifdef VerboseQtWinAPI}
|
||||
WriteLn('[WinAPI GetTextMetrics]');
|
||||
@ -4134,7 +4139,7 @@ begin
|
||||
|
||||
Result := IsValidDC(DC);
|
||||
|
||||
if Result then
|
||||
(* if Result then
|
||||
begin
|
||||
QtFontMetrics := QtDC.Metrics;
|
||||
TM.tmHeight := QtFontMetrics.height;
|
||||
@ -4184,10 +4189,11 @@ begin
|
||||
TM.tmPitchAndFamily := FIXED_PITCH or TRUETYPE_FONTTYPE;
|
||||
|
||||
TM.tmCharSet := DEFAULT_CHARSET;
|
||||
end;
|
||||
end;*)
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
function TQtWidgetSet.GetViewPortExtEx(DC: HDC; Size: PSize): Integer;
|
||||
(*function TQtWidgetSet.GetViewPortExtEx(DC: HDC; Size: PSize): Integer;
|
||||
var
|
||||
R: TRect;
|
||||
begin
|
||||
|
@ -2170,6 +2170,7 @@ begin
|
||||
Result := inherited ExtSelectClipRGN(DC, RGN, Mode);
|
||||
end;*)
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Function: ExtTextOut
|
||||
Params: none
|
||||
@ -2242,6 +2243,7 @@ begin
|
||||
|
||||
Result := True;}
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
(*{------------------------------------------------------------------------------
|
||||
Function: FillRect
|
||||
@ -4099,6 +4101,7 @@ begin
|
||||
Result := True;
|
||||
end;*)
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Function: GetTextExtentPoint
|
||||
Params: none
|
||||
@ -4207,6 +4210,7 @@ begin
|
||||
TM.tmCharSet := DEFAULT_CHARSET;
|
||||
end; *)
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
(*function TQtWidgetSet.GetViewPortExtEx(DC: HDC; Size: PSize): Integer;
|
||||
var
|
||||
|
@ -1348,6 +1348,7 @@ begin
|
||||
Result := Windows.ExtCreatePen(dwPenStyle, dwWidth, LB, dwStyleCount, lpStyle);
|
||||
end;*)
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Method: ExtTextOut
|
||||
Params: DC - handle to device context
|
||||
@ -1380,6 +1381,7 @@ begin
|
||||
W := UTF8ToUTF16(S);
|
||||
Result := Windows.ExtTextOutW(DC, X, Y, Options, LPRECT(Rect), PWideChar(W), Length(W), Dx);
|
||||
end;
|
||||
{$ifdef CD_UseNativeText}
|
||||
|
||||
(*{------------------------------------------------------------------------------
|
||||
Function: ExtSelectClipRGN
|
||||
@ -2067,6 +2069,7 @@ begin
|
||||
end;
|
||||
end;*)
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Method: GetTextExtentPoint
|
||||
Params: DC - handle of device context
|
||||
@ -2109,6 +2112,7 @@ function TCDWidgetSet.GetTextMetrics(DC: HDC; Var TM: TTextMetric): Boolean;
|
||||
begin
|
||||
Result := Boolean(Windows.GetTextMetrics(DC, @TM));
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
(*function TWin32WidgetSet.GetViewPortExtEx(DC: HDC; Size: PSize): Integer;
|
||||
begin
|
||||
|
@ -2170,6 +2170,7 @@ begin
|
||||
Result := inherited ExtSelectClipRGN(DC, RGN, Mode);
|
||||
end;*)
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Function: ExtTextOut
|
||||
Params: none
|
||||
@ -2222,6 +2223,7 @@ begin
|
||||
|
||||
Result := True; }
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
(*{------------------------------------------------------------------------------
|
||||
Function: FillRect
|
||||
@ -4079,6 +4081,7 @@ begin
|
||||
Result := True;
|
||||
end;*)
|
||||
|
||||
{$ifdef CD_UseNativeText}
|
||||
{------------------------------------------------------------------------------
|
||||
Function: GetTextExtentPoint
|
||||
Params: none
|
||||
@ -4170,6 +4173,7 @@ begin
|
||||
TM.tmCharSet := DEFAULT_CHARSET;
|
||||
end; }
|
||||
end;
|
||||
{$endif}
|
||||
|
||||
(*function TQtWidgetSet.GetViewPortExtEx(DC: HDC; Size: PSize): Integer;
|
||||
var
|
||||
|
@ -129,8 +129,8 @@ function GetStockObject(Value: Integer): THandle; override;*)
|
||||
function GetSysColor(nIndex: Integer): DWORD; override;
|
||||
(*function GetSysColorBrush(nIndex: Integer): HBrush; override;
|
||||
function GetSystemMetrics(nIndex: Integer): Integer; override;
|
||||
function GetTextColor(DC: HDC) : TColorRef; Override;
|
||||
function GetTextExtentExPoint(DC: HDC; Str: PChar; Count, MaxWidth: Integer; MaxCount, PartialWidths: PInteger; var Size: TSize): Boolean; override;*)
|
||||
function GetTextColor(DC: HDC) : TColorRef; Override;*)
|
||||
function GetTextExtentExPoint(DC: HDC; Str: PChar; Count, MaxWidth: Integer; MaxCount, PartialWidths: PInteger; var Size: TSize): Boolean; override;
|
||||
function GetTextExtentPoint(DC: HDC; Str: PChar; Count: Integer; var Size: TSize): Boolean; override;
|
||||
function GetTextMetrics(DC: HDC; var TM: TTextMetric): Boolean; override;
|
||||
(*function GetViewPortExtEx(DC: HDC; Size: PSize): Integer; override;
|
||||
|
@ -67,8 +67,9 @@ type
|
||||
FAssignedBrush: TFPCustomBrush;
|
||||
FAssignedPen: TFPCustomPen;
|
||||
FBaseWindowOrg: TPoint;
|
||||
FUseRegionClipping: Boolean;
|
||||
{$if defined(ver2_4) or defined(ver2_5) or defined(ver2_6)}
|
||||
FLazClipRegion: TLazRegion;
|
||||
{$endif}
|
||||
FWindowOrg: TPoint; // already in absolute coords with BaseWindowOrg summed up
|
||||
GraphicStateStack: TObjectStack; // TLazCanvasState
|
||||
function GetAssignedBrush: TFPCustomBrush;
|
||||
@ -117,8 +118,9 @@ type
|
||||
// because operations of SetWindowOrg inside a non-native wincontrol will be
|
||||
// based upon the BaseWindowOrg which is set relative to the Form canvas
|
||||
property BaseWindowOrg: TPoint read FBaseWindowOrg write FBaseWindowOrg;
|
||||
{$if defined(ver2_4) or defined(ver2_5) or defined(ver2_6)}
|
||||
property ClipRegion: TLazRegion read FLazClipRegion write FLazClipRegion;
|
||||
property UseRegionClipping: Boolean read FUseRegionClipping write FUseRegionClipping; // when false ClipRect is used
|
||||
{$endif}
|
||||
property WindowOrg: TPoint read GetWindowOrg write SetWindowOrg;
|
||||
end;
|
||||
|
||||
@ -165,16 +167,20 @@ end;
|
||||
procedure TLazCanvas.SetColor(x, y: integer; const AValue: TFPColor);
|
||||
var
|
||||
lx, ly: Integer;
|
||||
OldClipping: Boolean;
|
||||
begin
|
||||
lx := x + FWindowOrg.X;
|
||||
ly := y + FWindowOrg.Y;
|
||||
if Clipping and FUseRegionClipping and (not FLazClipRegion.IsPointInRegion(lx, ly)) then
|
||||
{$if defined(ver2_4) or defined(ver2_5) or defined(ver2_6)}
|
||||
if Clipping and (not FLazClipRegion.IsPointInRegion(lx, ly)) then
|
||||
Exit;
|
||||
OldClipping := Clipping;
|
||||
Clipping := False; // Work around to FImage being private in FPC 2.6 or inferior =(
|
||||
inherited SetColor(lx, ly, AValue);
|
||||
Clipping := OldClipping;
|
||||
if (lx >= 0) and (lx < width) and (ly >= 0) and (ly < height) then
|
||||
Image.Colors[lx,ly] := AValue;
|
||||
{$else}
|
||||
if Clipping and (not FClipRegion.IsPointInRegion(lx, ly)) then
|
||||
Exit;
|
||||
if (lx >= 0) and (lx < width) and (ly >= 0) and (ly < height) then
|
||||
FImage.Colors[lx,ly] := AValue;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
procedure TLazCanvas.DoPolygonFill(const points: array of TPoint);
|
||||
@ -437,6 +443,7 @@ var
|
||||
srcx, srcy: Integer; // current coordinates in the source image
|
||||
dx, dy: Integer; // current coordinates in the destination canvas
|
||||
lWidth, lHeight: Integer; // Image size
|
||||
lColor: TFPColor;
|
||||
begin
|
||||
if (w<=0) or (h<=0) or (image.Width=0) or (image.Height=0) then
|
||||
exit;
|
||||
@ -448,8 +455,9 @@ begin
|
||||
for dy := 0 to h-1 do
|
||||
begin
|
||||
srcx := Round((dx / w) * lWidth);
|
||||
srcy := Round((dy / w) * lHeight);
|
||||
Canvas.Colors[dx+x, dy+y] := Image.Colors[srcx, srcy];
|
||||
srcy := Round((dy / h) * lHeight);
|
||||
lColor := Image.Colors[srcx, srcy];
|
||||
Canvas.Colors[dx+x, dy+y] := lColor;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -170,8 +170,8 @@ var
|
||||
begin
|
||||
if IsSimpleRectRegion then
|
||||
begin
|
||||
Result := (AX >= Rect.Left) and (AX < Rect.Right) and
|
||||
(AY >= Rect.Top) and (AY < Rect.Bottom);
|
||||
Result := (AX >= Rect.Left) and (AX <= Rect.Right) and
|
||||
(AY >= Rect.Top) and (AY <= Rect.Bottom);
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
Loading…
Reference in New Issue
Block a user