File: gtk1widgetset.inc

package info (click to toggle)
lazarus 4.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 275,760 kB
  • sloc: pascal: 2,341,904; xml: 509,420; makefile: 348,726; cpp: 93,608; sh: 3,387; java: 609; perl: 297; sql: 222; ansic: 137
file content (80 lines) | stat: -rw-r--r-- 2,571 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{%MainUnit gtk1int.pp}

{******************************************************************************
                                   TGtkWidgetSet
 ******************************************************************************

 *****************************************************************************
  This file is part of the Lazarus Component Library (LCL)

  See the file COPYING.modifiedLGPL.txt, included in this distribution,
  for details about the license.
 *****************************************************************************
}

{$IFOPT C-}
// Uncomment for local trace
//  {$C+}
//  {$DEFINE ASSERT_IS_ON}
{$ENDIF}

function TGTK1WidgetSet.GetDeviceContextClass: TGtkDeviceContextClass;
begin
  Result := TGtk1DeviceContext;
end;

{------------------------------------------------------------------------------
  procedure SetWidgetFont
    AWidget : PGtkWidget; const AFont: TFont
 ------------------------------------------------------------------------------}
procedure TGtk1WidgetSet.SetWidgetFont(const AWidget: PGtkWidget; const AFont: TFont);
var
  WindowStyle: PGtkStyle;
  FontGdiObject: PGdiObject;

begin
  if GtkWidgetIsA(AWidget,GTKAPIWidget_GetType) then
    Exit; // the GTKAPIWidget is self drawn, so no use to change the widget style.

  if (GTK_WIDGET_REALIZED(AWidget)) then
    WindowStyle := gtk_widget_get_style(AWidget)
  else
    WindowStyle := gtk_rc_get_style(AWidget);

  if WindowStyle <> nil then
    WindowStyle := gtk_style_copy(WindowStyle);

  if (Windowstyle = nil) then
    Windowstyle := gtk_style_new;

  FontGdiObject := PGdiObject(AFont.Reference.Handle);
  windowstyle^.font := Pointer(FontGdiObject^.GdiFontObject);
  gtk_widget_set_style(aWidget, windowStyle);
end;

procedure TGtk1WidgetSet.SetLabelCaption(const ALabel: PGtkLabel; const ACaption: String;
  const AComponent: TComponent = nil; const ASignalWidget: PGTKWidget = nil;
  const ASignal: PChar = nil);
var
  Caption, Pattern: String;
  CurText: PChar;
  AccelKey: Char;
begin
  Caption := ACaption;
  LabelFromAmpersands(Caption, Pattern, AccelKey);
  gtk_label_get(ALabel, @CurText);
  if Caption <> StrPas(CurText) then
  begin
    gtk_label_set_text(ALabel, PChar(Caption));
    gtk_label_set_pattern(ALabel, PChar(Pattern));
  end;

  if AComponent = nil then Exit;
  if ASignalWidget = nil then Exit;
  if ASignal = '' then Exit;

  // update the Accelerator
  if AccelKey = #0
  then Accelerate(AComponent, ASignalWidget, GDK_VOIDSYMBOL, 0, ASignal)
  else Accelerate(AComponent, ASignalWidget, Ord(AccelKey), 0, ASignal);
end;