From d85002d862c71aca47fbd328ed1b441d4d60ecde Mon Sep 17 00:00:00 2001 From: ptvoinfo Date: Wed, 19 Apr 2023 12:21:29 +0300 Subject: [PATCH] Gtk2: Add theme support to DrawFocusRect Paint a themed focus rectangle (color and width) with fallback to the default method. --- lcl/interfaces/gtk2/gtk2winapi.inc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lcl/interfaces/gtk2/gtk2winapi.inc b/lcl/interfaces/gtk2/gtk2winapi.inc index fc8ab9d85a..9fb5c20dea 100644 --- a/lcl/interfaces/gtk2/gtk2winapi.inc +++ b/lcl/interfaces/gtk2/gtk2winapi.inc @@ -2231,6 +2231,9 @@ var APen, TempPen: HPEN; LogPen : TLogPen; R: TRect; + P: Pointer; + AValue: TGValue; + Style: PGtkStyle; begin Result := False; if IsValidDC(DC) then @@ -2246,6 +2249,32 @@ begin else R := Rect; + // paint a themed focus rectangle with fallback to the default method + P := GetStyleWidget(lgsDefault); + if P <> nil then + begin + FillChar(AValue{%H-}, SizeOf(AValue), 0); + g_value_init(@AValue, G_TYPE_INT); + gtk_widget_style_get_property(P, 'focus-line-width', @AValue); + if AValue.data[0].v_int > 0 then + LogPen.lopnWidth.X := AValue.data[0].v_int; + end; + + if (DevCtx.Widget <> nil) then + begin + Style := gtk_widget_get_style(DevCtx.Widget); + if (Style <> nil) then + begin + gtk_paint_focus( + Style, DevCtx.Drawable, GTK_WIDGET_STATE(DevCtx.Widget){GTK_STATE_ACTIVE}, + nil, DevCtx.Widget, nil, + R.Left, R.Top, + R.Width, R.Height); + Result := True; + exit; + end; + end; + APen := CreatePenIndirect(LogPen); TempPen := SelectObject(DC, APen); OldRop := SetROP2(DC, R2_XORPEN);