File: checkbuttononfixed.lpr

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 (60 lines) | stat: -rw-r--r-- 1,969 bytes parent folder | download | duplicates (12)
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
program CheckButtonOnFixed;

{$mode objfpc}{$H+}

uses
  Classes, Gtk2, Gdk2, Glib2;

function gtkExposeEventAfter(Widget: PGtkWidget; Event : PGDKEventExpose;
  Data: gPointer): GBoolean; cdecl;
var
  children: PGList;
begin
  Result:=false;
  writeln('gtkExposeEventAfter ',PChar(Data));

  // Some widgets in gtk2 don't have their own exclusive "windows" so a synthetic event must be sent
  // MG: That is already done by the gtk2. For which widgets does this not work?
  //     Enabling this results in double painting, which is slower and
  //     wrong for anitaliased text.
  if GTK_IS_FIXED(Widget) then begin
    children := gtk_container_get_children(PGtkContainer(Widget));
    while children <> nil do begin
      if (children^.data <> nil) then begin
        if GTK_WIDGET_NO_WINDOW(PGtkWidget(children^.data)) then
          gtk_container_propagate_expose(PGtkContainer(Widget), PGtkWidget(children^.data), Event);
        if children^.next = nil then break;
        children := children^.next;
      end;
    end;
    g_list_free(children);
  end;
end;

var
  GtkWindow: PGtkWidget;
  GtkFixed: PGtkWidget;
  GtkCheckButton: PGtkWidget;
  FixedName: String;
  CheckButtonName: String;
begin
  gtk_init(@ARGC,@ARGV);
  GtkWindow:=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GtkFixed := gtk_fixed_new ();
  gtk_fixed_set_has_window(PGtkFixed(GtkFixed), True);
  FixedName:='GtkFixed';
  g_signal_connect_after(PGtkObject(GtkFixed), 'expose-event',
                         TGTKSignalFunc(@gtkExposeEventAfter), PChar(FixedName));

  gtk_container_add (PGtkContainer(GtkWindow), GtkFixed);
  
  GtkCheckButton:=gtk_check_button_new_with_label('Second');
  CheckButtonName:='GtkCheckButton';
  g_signal_connect_after(PGtkObject(GtkCheckButton), 'expose-event',
                         TGTKSignalFunc(@gtkExposeEventAfter), PChar(CheckButtonName));
  gtk_fixed_put(PGtkFixed(GtkFixed),GtkCheckButton,10,10);
  
  gtk_widget_show_all(GtkWindow);
  gtk_main;
end.