mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-26 12:03:51 +02:00
implemented setting font for gtk widgets from Darek
git-svn-id: trunk@8754 -
This commit is contained in:
parent
c0e1ccde8a
commit
a88db22c6c
lcl
include
interfaces/gtk
@ -50,8 +50,7 @@ end;
|
||||
|
||||
function TCustomPage.GetTabVisible: Boolean;
|
||||
begin
|
||||
Result := fTabVisible;
|
||||
|
||||
Result := fTabVisible;
|
||||
end;
|
||||
|
||||
procedure TCustomPage.SetTabVisible(const AValue: Boolean);
|
||||
|
@ -4339,14 +4339,12 @@ begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TWinControl GetHandle }
|
||||
{------------------------------------------------------------------------------}
|
||||
{------------------------------------------------------------------------------
|
||||
TWinControl GetHandle
|
||||
------------------------------------------------------------------------------}
|
||||
function TWinControl.GetHandle: HWND;
|
||||
begin
|
||||
if not HandleAllocated then
|
||||
//Assert(False, Format('Trace:[TWinControl.GetHandle] %s(%s)', [ClassNAme, Name]))
|
||||
;
|
||||
//if not HandleAllocated then DebugLn('TWinControl.GetHandle Creating handle on the fly: ',DbgSName(Self));
|
||||
HandleNeeded;
|
||||
Result := FHandle;
|
||||
end;
|
||||
@ -5143,11 +5141,15 @@ begin
|
||||
DoSendBoundsToInterface;
|
||||
TWSWinControlClass(WidgetSetClass).ShowHide(Self);
|
||||
|
||||
if [wcfColorChanged,wcfFontChanged]*FWinControlFlags<>[]
|
||||
then begin
|
||||
if wcfColorChanged in FWinControlFlags then begin
|
||||
// replace by update style call
|
||||
TWSWinControlClass(WidgetSetClass).SetColor(Self);
|
||||
FWinControlFlags:=FWinControlFlags-[wcfColorChanged,wcfFontChanged];
|
||||
FWinControlFlags:=FWinControlFlags-[wcfColorChanged];
|
||||
end;
|
||||
if wcfFontChanged in FWinControlFlags then begin
|
||||
// replace by update style call
|
||||
TWSWinControlClass(WidgetSetClass).SetFont(Self,Font);
|
||||
FWinControlFlags:=FWinControlFlags-[wcfFontChanged];
|
||||
end;
|
||||
|
||||
if not (csDesigning in ComponentState) then
|
||||
@ -5245,12 +5247,16 @@ begin
|
||||
TWSWinControlClass(WidgetSetClass).SetText(Self, CachedText);
|
||||
InvalidatePreferredSize;
|
||||
|
||||
if [wcfColorChanged,wcfFontChanged]*FWinControlFlags<>[] then begin
|
||||
if wcfColorChanged in FWinControlFlags then begin
|
||||
TWSWinControlClass(WidgetSetClass).SetColor(Self);
|
||||
Exclude(FWinControlFlags,wcfColorChanged);
|
||||
end;
|
||||
if wcfFontChanged in FWinControlFlags then begin
|
||||
TWSWinControlClass(WidgetSetClass).SetFont(Self,Font);
|
||||
NotifyControls(CM_PARENTCOLORCHANGED);
|
||||
for i := 0 to ControlCount - 1 do
|
||||
Controls[i].ParentFontChanged;
|
||||
FWinControlFlags:=FWinControlFlags-[wcfColorChanged,wcfFontChanged];
|
||||
FWinControlFlags:=FWinControlFlags-[wcfFontChanged];
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -268,6 +268,7 @@ type
|
||||
procedure SetWidgetColor(const AWidget : PGtkWidget;
|
||||
const FGColor,BGColor : TColor;
|
||||
const Mask : tGtkStateEnum);
|
||||
procedure SetWidgetFont(const AWidget : PGtkWidget;const AFONT : tFont);
|
||||
procedure SetCallback(const AMsg: LongInt; const AGTKObject: PGTKObject;
|
||||
const ALCLObject: TObject); virtual;
|
||||
procedure SendPaintMessagesForInternalWidgets(AWinControl: TWinControl);
|
||||
|
@ -1334,11 +1334,15 @@ begin
|
||||
ChangeFGColor:=((FGColor and SYS_COLOR_BASE)=0) and (FGColor<>clNone);
|
||||
ChangeBGColor:=((BGColor and SYS_COLOR_BASE)=0) and (BGColor<>clNone);
|
||||
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.
|
||||
exit;
|
||||
end;
|
||||
|
||||
{$IFDEF DisableWidgetColor}
|
||||
exit;
|
||||
{$ENDIF}
|
||||
|
||||
if (GTK_WIDGET_REALIZED(AWidget)) then begin
|
||||
WindowStyle := gtk_style_copy(gtk_widget_get_style (AWidget));
|
||||
end else begin
|
||||
@ -1369,6 +1373,40 @@ begin
|
||||
gtk_widget_set_style(aWidget,windowStyle);
|
||||
end;
|
||||
|
||||
|
||||
procedure TGtkWidgetSet.SetWidgetFont(const AWidget : PGtkWidget;
|
||||
const AFont: TFont);
|
||||
{$IFDEF GTK1}
|
||||
var
|
||||
WindowStyle: PGtkStyle;
|
||||
FontGdiObject: PGdiObject;
|
||||
|
||||
begin
|
||||
if GtkWidgetIsA(AWidget,GTKAPIWidget_GetType) then begin
|
||||
// the GTKAPIWidget is self drawn, so no use to change the widget style.
|
||||
exit;
|
||||
end;
|
||||
|
||||
if (GTK_WIDGET_REALIZED(AWidget)) then begin
|
||||
WindowStyle := gtk_style_copy(gtk_widget_get_style (AWidget));
|
||||
end else begin
|
||||
WindowStyle := gtk_style_copy(gtk_rc_get_style (AWidget));
|
||||
end;
|
||||
if (Windowstyle = nil) then begin
|
||||
Windowstyle := gtk_style_new ;
|
||||
end;
|
||||
|
||||
FontGdiObject:=PGdiObject(AFont.Handle);
|
||||
windowstyle^.font:=pointer(FontGdiObject^.GdiFontObject);
|
||||
gtk_widget_set_style(aWidget,windowStyle);
|
||||
|
||||
{$ELSE}
|
||||
begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
procedure TGtkWidgetSet.RealizeWidgetSize(Widget: PGtkWidget; NewWidth,
|
||||
NewHeight: integer);
|
||||
|
@ -62,6 +62,8 @@ type
|
||||
class function GetText(const AWinControl: TWinControl; var AText: String): Boolean; override;
|
||||
class procedure SetShortcut(const AButton: TCustomButton; const OldShortcut, NewShortcut: TShortcut); override;
|
||||
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
|
||||
class procedure SetColor(const AWinControl: TWinControl); override;
|
||||
class procedure SetFont(const AWinControl: TWinControl; const AFont : tFont); override;
|
||||
class procedure GetPreferredSize(const AWinControl: TWinControl;
|
||||
var PreferredWidth, PreferredHeight: integer); override;
|
||||
end;
|
||||
@ -81,6 +83,7 @@ type
|
||||
class procedure SetSpacing(const ABitBtn: TCustomBitBtn; const AValue: Integer); override;
|
||||
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
|
||||
class procedure SetColor(const AWinControl: TWinControl); override;
|
||||
class procedure SetFont(const AWinControl: TWinControl; const AFont : tFont); override;
|
||||
|
||||
end;
|
||||
|
||||
@ -201,6 +204,42 @@ begin
|
||||
GtkWidgetSet.SetLabelCaption(LblWidget, AText, AWinControl, PGtkWidget(BtnWidget), 'clicked');
|
||||
end;
|
||||
|
||||
procedure TGtkWSButton.SetColor(const AWinControl: TWinControl);
|
||||
var
|
||||
Widget: PGTKWidget;
|
||||
LblWidget: PGtkWidget;
|
||||
begin
|
||||
Widget:= PGtkWidget(AWinControl.Handle);
|
||||
{$IFDEF GTK2}
|
||||
LblWidget := (PGtkBin(Widget)^.Child);
|
||||
{$ELSE}
|
||||
LblWidget := (pGtkBin(Widget)^.Child);
|
||||
{$ENDIF}
|
||||
GtkWidgetSet.SetWidgetColor(Widget, AWinControl.font.color, AWinControl.color,[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
if LblWidget <> nil then
|
||||
GtkWidgetSet.SetWidgetColor(LblWidget, AWinControl.font.color, AWinControl.color,[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
|
||||
end;
|
||||
procedure TGtkWSButton.SetFont(const AWinControl: TWinControl; const AFont : TFont);
|
||||
var
|
||||
Widget: PGTKWidget;
|
||||
LblWidget: PGtkWidget;
|
||||
begin
|
||||
Widget:= PGtkWidget(AWinControl.Handle);
|
||||
{$IFDEF GTK2}
|
||||
LblWidget := (PGtkBin(Widget)^.Child);
|
||||
{$ELSE}
|
||||
LblWidget := (pGtkBin(Widget)^.Child);
|
||||
{$ENDIF}
|
||||
|
||||
// GtkWidgetSet.SetWidgetColor(Widget, AWinControl.font.color, AWinControl.color,[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
if LblWidget<>nil then begin
|
||||
GtkWidgetSet.SetWidgetColor(LblWidget, AWinControl.font.color, AWinControl.color,[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
GtkWidgetSet.SetWidgetFont(LblWidget, AFont);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TGtkWSButton.GetPreferredSize(const AWinControl: TWinControl;
|
||||
var PreferredWidth, PreferredHeight: integer);
|
||||
begin
|
||||
@ -388,8 +427,39 @@ begin
|
||||
GtkWidgetSet.SetWidgetColor(BitBtnInfo^.LabelWidget, AWinControl.font.color,
|
||||
AWinControl.color,
|
||||
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
|
||||
|
||||
end;
|
||||
|
||||
procedure TGtkWSBitBtn.SetFont(const AWinControl: TWinControl;
|
||||
const AFont: TFont);
|
||||
var
|
||||
WidgetInfo: PWidgetInfo;
|
||||
BitBtnInfo: PBitBtnWidgetInfo;
|
||||
Widget: PGTKWidget;
|
||||
begin
|
||||
if not AWinControl.HandleAllocated then exit;
|
||||
|
||||
if AFont.IsDefault then exit;
|
||||
Widget:= PGtkWidget(AWinControl.Handle);
|
||||
WidgetInfo := GetWidgetInfo(Widget);
|
||||
BitBtnInfo := WidgetInfo^.UserData;
|
||||
|
||||
|
||||
// GtkWidgetSet.SetWidgetColor(Widget, AWinControl.font.color, clNone,
|
||||
// [GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
|
||||
if (BitBtnInfo=nil) or (BitBtnInfo^.LabelWidget = nil) then Exit;
|
||||
GtkWidgetSet.SetWidgetColor(BitBtnInfo^.LabelWidget, AWinControl.font.color,
|
||||
AWinControl.color,
|
||||
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
GtkWidgetSet.SetWidgetFont(BitBtnInfo^.LabelWidget, AFont);
|
||||
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TGtkWSBitBtn.UpdateLayout(const AInfo: PBitBtnWidgetInfo;
|
||||
const ALayout: TButtonLayout; const AMargin: Integer);
|
||||
begin
|
||||
|
@ -390,10 +390,20 @@ end;
|
||||
|
||||
procedure TGtkWSWinControl.SetFont(const AWinControl: TWinControl;
|
||||
const AFont: TFont);
|
||||
var
|
||||
Widget: PGtkWidget;
|
||||
begin
|
||||
DebugLn('TGtkWSWinControl.SetFont: implement me!');
|
||||
{$NOTE TGtkWSWinControl.SetFont: implement me!'}
|
||||
// TODO: implement me!
|
||||
if not AWinControl.HandleAllocated then exit;
|
||||
Widget:=pGtkWidget(AWinControl.handle);
|
||||
if GtkWidgetIsA(Widget,GTKAPIWidget_GetType) then
|
||||
exit;
|
||||
|
||||
if AFont.IsDefault then exit;
|
||||
DebugLn('TGtkWSWinControl.SetFont ',DbgSName(AWinControl));
|
||||
GtkWidgetSet.SetWidgetFont(Widget,Afont);
|
||||
GtkWidgetSet.SetWidgetColor(Widget,AWinControl.font.color, clNone,
|
||||
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,
|
||||
GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
end;
|
||||
|
||||
procedure TGtkWSWinControl.SetPos(const AWinControl: TWinControl;
|
||||
@ -431,10 +441,12 @@ begin
|
||||
if ((csOpaque in AWinControl.ControlStyle)
|
||||
and GtkWidgetIsA(pGtkWidget(AWinControl.handle),GTKAPIWidget_GetType)) then
|
||||
exit;
|
||||
//DebugLn('TGtkWSWinControl.SetColor ',DbgSName(AWinControl));
|
||||
GtkWidgetSet.SetWidgetColor(pGtkWidget(AWinControl.handle),
|
||||
AWinControl.font.color, AWinControl.color,
|
||||
[GTK_STATE_NORMAL,GTK_STATE_ACTIVE,
|
||||
GTK_STATE_PRELIGHT,GTK_STATE_SELECTED]);
|
||||
// GtkWidgetSet.setWidgetFont(pGtkWidget(AWinControl.handle),aWinControl.font);
|
||||
UpdateWidgetStyleOfControl(AWinControl);
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user