mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 04:59:20 +02:00
gtk: fix resetting color property of some controls (issue #0007555, using Zeljan patch but with many modifications)
git-svn-id: trunk@20441 -
This commit is contained in:
parent
b3dfa327cd
commit
cbea652f5f
@ -1022,53 +1022,75 @@ procedure TGtkWidgetSet.SetWidgetColor(const AWidget: PGtkWidget;
|
|||||||
const FGColor, BGColor: TColor; const Mask: TGtkStateEnum);
|
const FGColor, BGColor: TColor; const Mask: TGtkStateEnum);
|
||||||
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, RCStyle: PGtkStyle;
|
||||||
begin
|
begin
|
||||||
ChangeFGColor := (FGColor and SYS_COLOR_BASE = 0) and (FGColor<>clNone);
|
ChangeFGColor := (FGColor <> clNone);
|
||||||
ChangeBGColor := (BGColor and SYS_COLOR_BASE = 0) and (BGColor<>clNone);
|
ChangeBGColor := (BGColor <> clNone);
|
||||||
if (not ChangeFGColor) and (not ChangeBGColor) then exit;
|
if (not ChangeFGColor) and (not ChangeBGColor) then Exit;
|
||||||
|
|
||||||
// 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;
|
if GtkWidgetIsA(AWidget, GTKAPIWidget_GetType) then Exit;
|
||||||
|
|
||||||
{$IFDEF DisableWidgetColor}
|
{$IFDEF DisableWidgetColor}
|
||||||
exit;
|
exit;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
if (GTK_WIDGET_REALIZED(AWidget)) then begin
|
if (GTK_WIDGET_REALIZED(AWidget)) then
|
||||||
WindowStyle := gtk_style_copy(gtk_widget_get_style (AWidget));
|
WindowStyle := gtk_style_copy(gtk_widget_get_style(AWidget))
|
||||||
end else begin
|
else
|
||||||
WindowStyle := gtk_style_copy(gtk_rc_get_style(AWidget));
|
WindowStyle := gtk_style_copy(gtk_rc_get_style(AWidget));
|
||||||
end;
|
|
||||||
if (Windowstyle = nil) then begin
|
if (Windowstyle = nil) then
|
||||||
Windowstyle := gtk_style_new;
|
Windowstyle := gtk_style_new;
|
||||||
end;
|
|
||||||
|
|
||||||
//DebugLn('TGtkWidgetSet.SetWidgetColor ',GetWidgetDebugReport(AWidget),' ',hexstr(FGColor,8),' ',hexstr(BGColor,8));
|
//DebugLn('TGtkWidgetSet.SetWidgetColor ',GetWidgetDebugReport(AWidget),' ',hexstr(FGColor,8),' ',hexstr(BGColor,8));
|
||||||
//RaiseGDBException('');
|
//RaiseGDBException('');
|
||||||
if ChangeFGColor then begin
|
if ChangeFGColor then
|
||||||
|
begin
|
||||||
xfg := AllocGDKColor(colorToRGB(FGColor));
|
xfg := AllocGDKColor(colorToRGB(FGColor));
|
||||||
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do begin
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do
|
||||||
if i in mask then begin
|
begin
|
||||||
if GTK_STYLE_TEXT in mask then begin
|
if i in mask then
|
||||||
windowStyle^.text[i]:=xfg;
|
begin
|
||||||
end else begin
|
if GTK_STYLE_TEXT in mask then
|
||||||
|
windowStyle^.text[i] := xfg
|
||||||
|
else
|
||||||
windowStyle^.fg[i] := xfg;
|
windowStyle^.fg[i] := xfg;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if ChangeBGColor then
|
||||||
|
begin
|
||||||
|
if BGColor = clBackground then
|
||||||
|
begin
|
||||||
|
RCStyle := gtk_rc_get_style(AWidget);
|
||||||
|
if RCStyle <> nil then
|
||||||
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do
|
||||||
|
begin
|
||||||
|
if i in mask then
|
||||||
|
begin
|
||||||
|
if GTK_STYLE_BASE in mask then
|
||||||
|
windowStyle^.base[i] := RCStyle^.base[i]
|
||||||
|
else
|
||||||
|
windowStyle^.bg[i] := RCStyle^.bg[i];
|
||||||
end;
|
end;
|
||||||
if ChangeBGColor then begin
|
end;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
xbg := AllocGDKColor(colorToRGB(BGColor));
|
xbg := AllocGDKColor(colorToRGB(BGColor));
|
||||||
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do begin
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do
|
||||||
if i in mask then begin
|
begin
|
||||||
if GTK_STYLE_BASE in mask then begin
|
if i in mask then
|
||||||
windowStyle^.base[i]:=xbg;
|
begin
|
||||||
end else begin
|
if GTK_STYLE_BASE in mask then
|
||||||
|
windowStyle^.base[i] := xbg
|
||||||
|
else
|
||||||
windowStyle^.bg[i] := xbg;
|
windowStyle^.bg[i] := xbg;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -1078,13 +1100,15 @@ begin
|
|||||||
gtk_widget_set_style(aWidget, windowStyle);
|
gtk_widget_set_style(aWidget, windowStyle);
|
||||||
end;
|
end;
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
|
NewColor: PGdkColor;
|
||||||
begin
|
begin
|
||||||
ChangeFGColor := (FGColor<>clNone) and (BGColor<>clBtnFace);
|
ChangeFGColor := (FGColor <> clNone);
|
||||||
ChangeBGColor := (BGColor<>clNone) and (BGColor<>clBtnFace);
|
ChangeBGColor := (BGColor <> clNone);
|
||||||
if (not ChangeFGColor) and (not ChangeBGColor) then exit;
|
|
||||||
|
if (not ChangeFGColor) and (not ChangeBGColor) then Exit;
|
||||||
|
|
||||||
// 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;
|
if GtkWidgetIsA(AWidget, GTKAPIWidget_GetType) then Exit;
|
||||||
|
|
||||||
{$IFDEF DisableWidgetColor}
|
{$IFDEF DisableWidgetColor}
|
||||||
exit;
|
exit;
|
||||||
@ -1106,17 +1130,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if ChangeBGColor then
|
if ChangeBGColor then
|
||||||
|
begin
|
||||||
|
if BGColor = clBackground then
|
||||||
|
NewColor := nil
|
||||||
|
else
|
||||||
begin
|
begin
|
||||||
xbg := AllocGDKColor(ColorToRGB(BGColor));
|
xbg := AllocGDKColor(ColorToRGB(BGColor));
|
||||||
|
NewColor := @xbg;
|
||||||
|
end;
|
||||||
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do
|
for i := GTK_STATE_NORMAL to GTK_STATE_INSENSITIVE do
|
||||||
begin
|
begin
|
||||||
if i in mask then
|
if i in mask then
|
||||||
begin
|
begin
|
||||||
if GTK_STYLE_BASE in mask then
|
if GTK_STYLE_BASE in mask then
|
||||||
gtk_widget_modify_base(AWidget, i ,@xbg)
|
gtk_widget_modify_base(AWidget, i, NewColor)
|
||||||
else
|
else
|
||||||
gtk_widget_modify_bg(AWidget, i ,@xbg);
|
gtk_widget_modify_bg(AWidget, i, NewColor);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -1279,7 +1279,7 @@ begin
|
|||||||
AWidget := PGtkWidget(AWinControl.Handle);
|
AWidget := PGtkWidget(AWinControl.Handle);
|
||||||
// don't change selected state
|
// don't change selected state
|
||||||
GtkWidgetSet.SetWidgetColor(AWidget, clNone, AWinControl.Color,
|
GtkWidgetSet.SetWidgetColor(AWidget, clNone, AWinControl.Color,
|
||||||
[GTK_STATE_NORMAL, GTK_STATE_ACTIVE, GTK_STATE_PRELIGHT, GTK_STYLE_BASE]);
|
[GTK_STATE_NORMAL, GTK_STYLE_BASE]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TGtkWSCustomStaticText }
|
{ TGtkWSCustomStaticText }
|
||||||
|
Loading…
Reference in New Issue
Block a user