mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 15:59:13 +02:00
LCL-GTK3: Make drawtext use proper default color etc. Issue #38335, patch from Anton Kavalenka.
git-svn-id: trunk@64368 -
This commit is contained in:
parent
499bcaf7b1
commit
25f463a798
@ -1159,21 +1159,24 @@ const
|
|||||||
GTK_RECENT_MANAGER_ERROR_WRITE: TGtkRecentManagerError = 5;
|
GTK_RECENT_MANAGER_ERROR_WRITE: TGtkRecentManagerError = 5;
|
||||||
GTK_RECENT_MANAGER_ERROR_UNKNOWN: TGtkRecentManagerError = 6;
|
GTK_RECENT_MANAGER_ERROR_UNKNOWN: TGtkRecentManagerError = 6;
|
||||||
|
|
||||||
type
|
//type ???
|
||||||
TGtkResponseType = Integer;
|
// TGtkResponseType = integer;
|
||||||
|
//PPGtkResponseType = ^PGtkResponseType;
|
||||||
|
//PGtkResponseType = ^TGtkResponseType;
|
||||||
|
|
||||||
const
|
const
|
||||||
{ GtkResponseType }
|
{ GtkResponseType }
|
||||||
GTK_RESPONSE_NONE: TGtkResponseType = -1;
|
GTK_RESPONSE_NONE = -1;
|
||||||
GTK_RESPONSE_REJECT: TGtkResponseType = -2;
|
GTK_RESPONSE_REJECT = -2;
|
||||||
GTK_RESPONSE_ACCEPT: TGtkResponseType = -3;
|
GTK_RESPONSE_ACCEPT = -3;
|
||||||
GTK_RESPONSE_DELETE_EVENT: TGtkResponseType = -4;
|
GTK_RESPONSE_DELETE_EVENT = -4;
|
||||||
GTK_RESPONSE_OK: TGtkResponseType = -5;
|
GTK_RESPONSE_OK = -5;
|
||||||
GTK_RESPONSE_CANCEL: TGtkResponseType = -6;
|
GTK_RESPONSE_CANCEL = -6;
|
||||||
GTK_RESPONSE_CLOSE: TGtkResponseType = -7;
|
GTK_RESPONSE_CLOSE = -7;
|
||||||
GTK_RESPONSE_YES: TGtkResponseType = -8;
|
GTK_RESPONSE_YES = -8;
|
||||||
GTK_RESPONSE_NO: TGtkResponseType = -9;
|
GTK_RESPONSE_NO = -9;
|
||||||
GTK_RESPONSE_APPLY: TGtkResponseType = -10;
|
GTK_RESPONSE_APPLY = -10;
|
||||||
GTK_RESPONSE_HELP: TGtkResponseType = -11;
|
GTK_RESPONSE_HELP = -11;
|
||||||
|
|
||||||
type
|
type
|
||||||
TGtkScrollStep = Integer;
|
TGtkScrollStep = Integer;
|
||||||
@ -8960,16 +8963,9 @@ type
|
|||||||
natural_size: gint;
|
natural_size: gint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PPGtkResponseType = ^PGtkResponseType;
|
|
||||||
PGtkResponseType = ^TGtkResponseType;
|
|
||||||
|
|
||||||
TGtkScalePrivate = record
|
TGtkScalePrivate = record
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PPGtkScaleButton = ^PGtkScaleButton;
|
PPGtkScaleButton = ^PGtkScaleButton;
|
||||||
PGtkScaleButton = ^TGtkScaleButton;
|
PGtkScaleButton = ^TGtkScaleButton;
|
||||||
|
|
||||||
|
@ -115,15 +115,15 @@ end;
|
|||||||
class function TGtk3DialogFactory.gtk_resp_to_lcl(const gtk_resp:integer):integer;
|
class function TGtk3DialogFactory.gtk_resp_to_lcl(const gtk_resp:integer):integer;
|
||||||
begin
|
begin
|
||||||
case gtk_resp of
|
case gtk_resp of
|
||||||
-5{GTK_RESPONSE_OK}: Result:= ID_OK;
|
GTK_RESPONSE_OK: Result:=ID_OK;
|
||||||
-6{GTK_RESPONSE_CANCEL}: Result := id_Cancel;
|
GTK_RESPONSE_CANCEL: Result:=id_Cancel;
|
||||||
-7{GTK_RESPONSE_CLOSE}: Result:=id_Close;
|
GTK_RESPONSE_CLOSE: Result:=id_Close;
|
||||||
-8{GTK_RESPONSE_YES}: Result:=id_Yes;
|
GTK_RESPONSE_YES: Result:=id_Yes;
|
||||||
-9{GTK_RESPONSE_NO}: Result:=id_No;
|
GTK_RESPONSE_NO: Result:=id_No;
|
||||||
|
|
||||||
-1{GTK_RESPONSE_NONE}: Result:=0;
|
GTK_RESPONSE_NONE: Result:=0;
|
||||||
-2{GTK_RESPONSE_REJECT}: Result:=id_abort;
|
GTK_RESPONSE_REJECT: Result:=id_abort;
|
||||||
-3{GTK_RESPONSE_ACCEPT}: Result:=id_Yes;
|
GTK_RESPONSE_ACCEPT: Result:=id_Yes;
|
||||||
|
|
||||||
GTK_RESPONSE_LCL_RETRY: Result:=id_Retry;
|
GTK_RESPONSE_LCL_RETRY: Result:=id_Retry;
|
||||||
GTK_RESPONSE_LCL_IGNORE: Result:=id_Ignore;
|
GTK_RESPONSE_LCL_IGNORE: Result:=id_Ignore;
|
||||||
|
@ -183,8 +183,15 @@ type
|
|||||||
|
|
||||||
{ TGtk3Cursor }
|
{ TGtk3Cursor }
|
||||||
|
|
||||||
TGtk3Cursor = class(TGtk3ContextObject)
|
TGtk3Cursor = class(TGtk3Object)
|
||||||
// TODO
|
private
|
||||||
|
fHandle:PGdkCursor;
|
||||||
|
public
|
||||||
|
constructor Create(ACur:integer);overload;
|
||||||
|
constructor Create(pixbuf:PGdkPixbuf;x,y:gint);overload;
|
||||||
|
constructor Create(img:TGtk3Image);overload;
|
||||||
|
destructor Destroy;override;
|
||||||
|
property Handle:PGdkCursor read fHandle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TGtk3DeviceContext }
|
{ TGtk3DeviceContext }
|
||||||
@ -257,7 +264,7 @@ type
|
|||||||
procedure fillRect(x, y, w, h: Integer; ABrush: HBRUSH); overload;
|
procedure fillRect(x, y, w, h: Integer; ABrush: HBRUSH); overload;
|
||||||
procedure fillRect(x, y, w, h: Integer); overload;
|
procedure fillRect(x, y, w, h: Integer); overload;
|
||||||
function RoundRect(X1, Y1, X2, Y2: Integer; RX, RY: Integer): Boolean;
|
function RoundRect(X1, Y1, X2, Y2: Integer; RX, RY: Integer): Boolean;
|
||||||
|
function drawFocusRect(const aRect: TRect): boolean;
|
||||||
function getBpp: integer;
|
function getBpp: integer;
|
||||||
function getDepth: integer;
|
function getDepth: integer;
|
||||||
function getDeviceSize: TPoint;
|
function getDeviceSize: TPoint;
|
||||||
@ -299,7 +306,7 @@ function ReplaceAmpersandsWithUnderscores(const S: string): string; inline;
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses gtk3int;
|
uses gtk3int,controls;
|
||||||
|
|
||||||
const
|
const
|
||||||
PixelOffset = 0.5; // Cairo API needs 0.5 pixel offset to not make blurry lines
|
PixelOffset = 0.5; // Cairo API needs 0.5 pixel offset to not make blurry lines
|
||||||
@ -452,6 +459,40 @@ begin
|
|||||||
B := ((AColor shr 16) and $FF) / 255;
|
B := ((AColor shr 16) and $FF) / 255;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TGtk3Cursor }
|
||||||
|
|
||||||
|
constructor TGtk3Cursor.Create(ACur:integer);
|
||||||
|
var gdk_cur:integer;
|
||||||
|
begin
|
||||||
|
case ACur of
|
||||||
|
crArrow: gdk_cur:=GDK_ARROW;
|
||||||
|
else
|
||||||
|
gdk_cur:=GDK_ARROW;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Fhandle:=TGdkCursor.new(gdk_cur);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TGtk3Cursor.Create(pixbuf: PGdkPixbuf;x,y:gint);
|
||||||
|
begin
|
||||||
|
fHandle:=TGdkCursor.new_from_pixbuf(TGdkDisplay.get_default(),pixbuf,x,y);
|
||||||
|
end;
|
||||||
|
|
||||||
|
constructor TGtk3Cursor.Create(img: TGtk3Image);
|
||||||
|
var w,h:gint;
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
w:=img.width;
|
||||||
|
h:=img.height;
|
||||||
|
Create(img.Handle,w,h);
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TGtk3Cursor.Destroy;
|
||||||
|
begin
|
||||||
|
PGdkCursor(fHandle)^.unref();
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TGtk3ContextObject }
|
{ TGtk3ContextObject }
|
||||||
|
|
||||||
constructor TGtk3ContextObject.Create;
|
constructor TGtk3ContextObject.Create;
|
||||||
@ -1670,7 +1711,7 @@ begin
|
|||||||
ornt := Self.FCurrentFont.FLogFont.lfOrientation;
|
ornt := Self.FCurrentFont.FLogFont.lfOrientation;
|
||||||
if ornt<>0 then
|
if ornt<>0 then
|
||||||
cairo_rotate(pcr, - pi * (ornt / 10)/180);
|
cairo_rotate(pcr, - pi * (ornt / 10)/180);
|
||||||
ColorToCairoRGB(TColor(CurrentTextColor), R, G, B);
|
ColorToCairoRGB(ColorToRgb(TColor(CurrentTextColor)), R, G, B);
|
||||||
cairo_set_source_rgb(pcr, R, G, B);
|
cairo_set_source_rgb(pcr, R, G, B);
|
||||||
|
|
||||||
FCurrentFont.Layout^.set_text(AText, ALen);
|
FCurrentFont.Layout^.set_text(AText, ALen);
|
||||||
@ -2062,6 +2103,42 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TGtk3DeviceContext.drawFocusRect(const aRect: TRect): boolean;
|
||||||
|
var
|
||||||
|
Context: PGtkStyleContext;
|
||||||
|
AValue: TGValue;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
|
||||||
|
if Parent <> nil then
|
||||||
|
Context := Parent^.get_style_context
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Context:=TGtkStyleContext.new();
|
||||||
|
Context^.add_class('button');
|
||||||
|
//gtk_style_context_get(Context,GTK_STATE_NORMAL,[]);
|
||||||
|
{ if gtk_widget_get_default_style^.has_context then
|
||||||
|
begin
|
||||||
|
// Context := gtk_widget_get_default_style^.has_context
|
||||||
|
AValue.g_type := G_TYPE_POINTER;
|
||||||
|
AValue.set_pointer(nil);
|
||||||
|
g_object_get_property(gtk_widget_get_default_style,'context',@AValue);
|
||||||
|
Context := AValue.get_pointer;
|
||||||
|
AValue.unset;
|
||||||
|
end else
|
||||||
|
Context := nil;}
|
||||||
|
end;
|
||||||
|
if Context = nil then
|
||||||
|
begin
|
||||||
|
DebugLn('WARNING: TGtk3WidgetSet.DrawFocusRect drawing focus on non widget context isn''t implemented.');
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
with aRect do
|
||||||
|
gtk_render_focus(Context ,pcr, Left, Top, Right - Left, Bottom - Top);
|
||||||
|
|
||||||
|
Result := True;
|
||||||
|
end;
|
||||||
|
|
||||||
function TGtk3DeviceContext.getBpp: integer;
|
function TGtk3DeviceContext.getBpp: integer;
|
||||||
var
|
var
|
||||||
AVisual: PGdkVisual;
|
AVisual: PGdkVisual;
|
||||||
|
@ -1164,7 +1164,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
GDK_BUTTON_RELEASE:
|
GDK_BUTTON_RELEASE:
|
||||||
begin
|
begin
|
||||||
if not (csClickEvents in TGtk3Widget(Data).LCLObject.ControlStyle) then
|
//if not (csClickEvents in TGtk3Widget(Data).LCLObject.ControlStyle) then
|
||||||
Result := TGtk3Widget(Data).GtkEventMouse(Widget , Event);
|
Result := TGtk3Widget(Data).GtkEventMouse(Widget , Event);
|
||||||
end;
|
end;
|
||||||
GDK_KEY_PRESS:
|
GDK_KEY_PRESS:
|
||||||
|
@ -452,15 +452,17 @@ begin
|
|||||||
Result := HICON(TGtk3Image.Create(TGtk3Image(IconInfo^.hbmColor).Handle));
|
Result := HICON(TGtk3Image.Create(TGtk3Image(IconInfo^.hbmColor).Handle));
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
|
Result := HCURSOR({%H-}PtrUInt(gdk_cursor_new_from_pixbuf(gdk_display_get_default,
|
||||||
|
TGtk3Image(IconInfo^.hbmColor).Handle, IconInfo^.xHotSpot, IconInfo^.yHotSpot)));
|
||||||
// create cursor from pixbuf
|
// create cursor from pixbuf
|
||||||
W := gdk_pixbuf_get_width(TGtk3Image(IconInfo^.hbmColor).Handle);
|
{ W := gdk_pixbuf_get_width(TGtk3Image(IconInfo^.hbmColor).Handle);
|
||||||
H := gdk_pixbuf_get_height(TGtk3Image(IconInfo^.hbmColor).Handle);
|
H := gdk_pixbuf_get_height(TGtk3Image(IconInfo^.hbmColor).Handle);
|
||||||
DebugLn('TGtk3WidgetSet.CreateIconIndirect W=',dbgs(W),' H=',dbgs(H));
|
DebugLn('TGtk3WidgetSet.CreateIconIndirect W=',dbgs(W),' H=',dbgs(H));
|
||||||
PixBuf := gdk_pixbuf_new_subpixbuf(TGtk3Image(IconInfo^.hbmColor).Handle, 0, 0, W, H);
|
PixBuf := gdk_pixbuf_new_subpixbuf(TGtk3Image(IconInfo^.hbmColor).Handle, 0, 0, W, H);
|
||||||
Result := HCURSOR({%H-}PtrUInt(gdk_cursor_new_from_pixbuf(gdk_display_get_default,
|
Result := HCURSOR({%H-}PtrUInt(gdk_cursor_new_from_pixbuf(gdk_display_get_default,
|
||||||
pixbuf, IconInfo^.xHotSpot, IconInfo^.yHotSpot)));
|
pixbuf, IconInfo^.xHotSpot, IconInfo^.yHotSpot)));
|
||||||
if pixbuf <> nil then
|
if pixbuf <> nil then
|
||||||
g_object_unref(PixBuf);
|
g_object_unref(PixBuf); }
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -606,36 +608,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TGtk3WidgetSet.DrawFocusRect(DC: HDC; const aRect: TRect): boolean;
|
function TGtk3WidgetSet.DrawFocusRect(DC: HDC; const aRect: TRect): boolean;
|
||||||
var
|
|
||||||
Context: PGtkStyleContext;
|
|
||||||
AValue: TGValue;
|
|
||||||
begin
|
begin
|
||||||
Result := False;
|
Result := False;
|
||||||
if IsValidDC(DC) then
|
if IsValidDC(DC) then
|
||||||
begin
|
Result:=TGtk3DeviceContext(DC).drawFocusRect(aRect);
|
||||||
if TGtk3DeviceContext(DC).Parent <> nil then
|
|
||||||
Context := TGtk3DeviceContext(DC).Parent^.get_style_context
|
|
||||||
else
|
|
||||||
if gtk_widget_get_default_style^.has_context then
|
|
||||||
begin
|
|
||||||
// Context := gtk_widget_get_default_style^.has_context
|
|
||||||
AValue.g_type := G_TYPE_POINTER;
|
|
||||||
AValue.set_pointer(nil);
|
|
||||||
g_object_get_property(gtk_widget_get_default_style,'context',@AValue);
|
|
||||||
Context := AValue.get_pointer;
|
|
||||||
AValue.unset;
|
|
||||||
end else
|
|
||||||
Context := nil;
|
|
||||||
if Context = nil then
|
|
||||||
begin
|
|
||||||
DebugLn('WARNING: TGtk3WidgetSet.DrawFocusRect drawing focus on non widget context isn''t implemented.');
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
with aRect do
|
|
||||||
gtk_render_focus(Context ,TGtk3DeviceContext(DC).pcr, Left, Top, Right - Left, Bottom - Top);
|
|
||||||
|
|
||||||
Result := True;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TGtk3WidgetSet.DrawEdge(DC: HDC; var ARect: TRect; Edge: Cardinal;
|
function TGtk3WidgetSet.DrawEdge(DC: HDC; var ARect: TRect; Edge: Cardinal;
|
||||||
|
Loading…
Reference in New Issue
Block a user