mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 14:11:32 +02:00
Implements setting system colors for controls under gtk2.
git-svn-id: trunk@14834 -
This commit is contained in:
parent
542dbfa485
commit
9bbcc202e4
@ -1009,38 +1009,47 @@ begin
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{
|
||||||
|
Changes some colors of the widget style
|
||||||
|
|
||||||
|
IMPORTANT:
|
||||||
|
SystemColors like clBtnFace depend on the theme and widget class, so they
|
||||||
|
must be read from the theme. But many gtk themes do not provide all colors
|
||||||
|
and instead only provide bitmaps.
|
||||||
|
Since we don't have good fallbacks yet, and many controls use SystemColors
|
||||||
|
for Delphi compatibility: ignore SystemColors from the following list:
|
||||||
|
|
||||||
|
Gtk 2:
|
||||||
|
|
||||||
|
clNone (should be ignored anyway),
|
||||||
|
clBtnFace,
|
||||||
|
|
||||||
|
Gtk 1:
|
||||||
|
|
||||||
|
clNone,
|
||||||
|
Any system color
|
||||||
|
}
|
||||||
procedure TGtkWidgetSet.SetWidgetColor(const AWidget: PGtkWidget;
|
procedure TGtkWidgetSet.SetWidgetColor(const AWidget: PGtkWidget;
|
||||||
const FGColor, BGColor: TColor; const Mask: tGtkStateEnum);
|
const FGColor, BGColor: TColor; const Mask: TGtkStateEnum);
|
||||||
// Changes some colors of the widget style
|
|
||||||
// IMPORTANT:
|
|
||||||
// SystemColors like clBtnFace depend on the theme and widget class, so they
|
|
||||||
// must be read from the theme. But many gtk themes do not provide all colors
|
|
||||||
// and instead only provide bitmaps.
|
|
||||||
// Since we don't have good fallbacks yet, and many controls use SystemColors
|
|
||||||
// for Delphi compatibility: ignore SystemColors.
|
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
xfg,xbg: TGDKColor;
|
xfg,xbg: TGDKColor;
|
||||||
ChangeFGColor: Boolean;
|
ChangeFGColor: Boolean;
|
||||||
ChangeBGColor: Boolean;
|
ChangeBGColor: Boolean;
|
||||||
{$IFDEF Gtk1}
|
{$IFDEF Gtk1}
|
||||||
WindowStyle: PGtkStyle;
|
WindowStyle: PGtkStyle;
|
||||||
{$ENDIF}
|
|
||||||
begin
|
begin
|
||||||
ChangeFGColor:=((FGColor and SYS_COLOR_BASE)=0) and (FGColor<>clNone);
|
ChangeFGColor := (FGColor and SYS_COLOR_BASE = 0) and (FGColor<>clNone);
|
||||||
ChangeBGColor:=((BGColor and SYS_COLOR_BASE)=0) and (BGColor<>clNone);
|
ChangeBGColor := (BGColor and SYS_COLOR_BASE = 0) and (BGColor<>clNone);
|
||||||
if (not ChangeFGColor) and (not ChangeBGColor) then exit;
|
if (not ChangeFGColor) and (not ChangeBGColor) then exit;
|
||||||
|
|
||||||
if GtkWidgetIsA(AWidget,GTKAPIWidget_GetType) then begin
|
// the GTKAPIWidget is self drawn, so no use to change the widget style.
|
||||||
// the GTKAPIWidget is self drawn, so no use to change the widget style.
|
if GtkWidgetIsA(AWidget,GTKAPIWidget_GetType) then exit;
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{$IFDEF DisableWidgetColor}
|
{$IFDEF DisableWidgetColor}
|
||||||
exit;
|
exit;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
{$IFDEF Gtk1}
|
|
||||||
if (GTK_WIDGET_REALIZED(AWidget)) then begin
|
if (GTK_WIDGET_REALIZED(AWidget)) then begin
|
||||||
WindowStyle := gtk_style_copy(gtk_widget_get_style (AWidget));
|
WindowStyle := gtk_style_copy(gtk_widget_get_style (AWidget));
|
||||||
end else begin
|
end else begin
|
||||||
@ -1049,7 +1058,6 @@ begin
|
|||||||
if (Windowstyle = nil) then begin
|
if (Windowstyle = nil) then begin
|
||||||
Windowstyle := gtk_style_new;
|
Windowstyle := gtk_style_new;
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
//DebugLn('TGtkWidgetSet.SetWidgetColor ',GetWidgetDebugReport(AWidget),' ',hexstr(FGColor,8),' ',hexstr(BGColor,8));
|
//DebugLn('TGtkWidgetSet.SetWidgetColor ',GetWidgetDebugReport(AWidget),' ',hexstr(FGColor,8),' ',hexstr(BGColor,8));
|
||||||
//RaiseGDBException('');
|
//RaiseGDBException('');
|
||||||
@ -1058,17 +1066,9 @@ begin
|
|||||||
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do begin
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do begin
|
||||||
if i in mask then begin
|
if i in mask then begin
|
||||||
if GTK_STYLE_TEXT in mask then begin
|
if GTK_STYLE_TEXT in mask then begin
|
||||||
{$IFDEF Gtk1}
|
|
||||||
windowStyle^.text[i]:=xfg;
|
windowStyle^.text[i]:=xfg;
|
||||||
{$ELSE}
|
|
||||||
gtk_widget_modify_text(AWidget, i ,@xfg);
|
|
||||||
{$ENDIF}
|
|
||||||
end else begin
|
end else begin
|
||||||
{$IFDEF Gtk1}
|
|
||||||
windowStyle^.fg[i]:=xfg;
|
windowStyle^.fg[i]:=xfg;
|
||||||
{$ELSE}
|
|
||||||
gtk_widget_modify_fg(AWidget, i ,@xfg);
|
|
||||||
{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1078,25 +1078,59 @@ begin
|
|||||||
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do begin
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do begin
|
||||||
if i in mask then begin
|
if i in mask then begin
|
||||||
if GTK_STYLE_BASE in mask then begin
|
if GTK_STYLE_BASE in mask then begin
|
||||||
{$IFDEF Gtk1}
|
|
||||||
windowStyle^.base[i]:=xbg;
|
windowStyle^.base[i]:=xbg;
|
||||||
{$ELSE}
|
|
||||||
gtk_widget_modify_base(AWidget, i ,@xbg);
|
|
||||||
{$ENDIF}
|
|
||||||
end else begin
|
end else begin
|
||||||
{$IFDEF Gtk1}
|
|
||||||
windowStyle^.bg[i]:=xbg;
|
windowStyle^.bg[i]:=xbg;
|
||||||
{$ELSE}
|
|
||||||
gtk_widget_modify_bg(AWidget, i ,@xbg);
|
|
||||||
{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$IFDEF Gtk1}
|
|
||||||
gtk_widget_set_style(aWidget,windowStyle);
|
gtk_widget_set_style(aWidget,windowStyle);
|
||||||
{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
|
{$ELSE}
|
||||||
|
begin
|
||||||
|
ChangeFGColor := (FGColor<>clNone) and (BGColor<>clBtnFace);
|
||||||
|
ChangeBGColor := (BGColor<>clNone) and (BGColor<>clBtnFace);
|
||||||
|
if (not ChangeFGColor) and (not ChangeBGColor) then exit;
|
||||||
|
|
||||||
|
// the GTKAPIWidget is self drawn, so no use to change the widget style.
|
||||||
|
if GtkWidgetIsA(AWidget,GTKAPIWidget_GetType) then exit;
|
||||||
|
|
||||||
|
{$IFDEF DisableWidgetColor}
|
||||||
|
exit;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
//DebugLn('TGtkWidgetSet.SetWidgetColor ',GetWidgetDebugReport(AWidget),' ',hexstr(FGColor,8),' ',hexstr(BGColor,8));
|
||||||
|
//RaiseGDBException('');
|
||||||
|
if ChangeFGColor then
|
||||||
|
begin
|
||||||
|
xfg := AllocGDKColor(colorToRGB(FGColor));
|
||||||
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do
|
||||||
|
begin
|
||||||
|
if i in mask then
|
||||||
|
begin
|
||||||
|
if GTK_STYLE_TEXT in mask then
|
||||||
|
gtk_widget_modify_text(AWidget, i ,@xfg)
|
||||||
|
else gtk_widget_modify_fg(AWidget, i ,@xfg);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if ChangeBGColor then
|
||||||
|
begin
|
||||||
|
xbg := AllocGDKColor(colorToRGB(BGColor));
|
||||||
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do
|
||||||
|
begin
|
||||||
|
if i in mask then
|
||||||
|
begin
|
||||||
|
if GTK_STYLE_BASE in mask then
|
||||||
|
gtk_widget_modify_base(AWidget, i ,@xbg)
|
||||||
|
else gtk_widget_modify_bg(AWidget, i ,@xbg);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
Method: TGtkWidgetSet.AppProcessMessages
|
Method: TGtkWidgetSet.AppProcessMessages
|
||||||
|
Loading…
Reference in New Issue
Block a user