summary refs log tree commit diff stats
path: root/tests/gtk/ex9.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andi>2008-06-22 16:14:11 +0200
committerAndreas Rumpf <andreas@andi>2008-06-22 16:14:11 +0200
commit405b86068e6a3d39970b9129ceec0a9108464b28 (patch)
treec0449946f54baae6ea88baf453157ddd7faa8f86 /tests/gtk/ex9.nim
downloadNim-405b86068e6a3d39970b9129ceec0a9108464b28.tar.gz
Initial import
Diffstat (limited to 'tests/gtk/ex9.nim')
-rwxr-xr-xtests/gtk/ex9.nim47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/gtk/ex9.nim b/tests/gtk/ex9.nim
new file mode 100755
index 000000000..79b335044
--- /dev/null
+++ b/tests/gtk/ex9.nim
@@ -0,0 +1,47 @@
+
+import 
+  gdk2, glib2, gtk2
+
+proc destroy(widget: pGtkWidget, data: pgpointer){.cdecl.} = 
+  gtk_main_quit()
+
+const 
+  Inside: cstring = "Mouse is over label"
+  OutSide: cstring = "Mouse is not over label"
+
+var 
+  window, button1, Button2, Alabel, stackbox: PGtkWidget
+  buttonstyle: pgtkstyle
+  OverButton: bool
+
+proc ChangeLabel(P: PGtkWidget, Event: PGdkEventCrossing, Data: var bool){.cdecl.} = 
+  if Not Data: gtk_label_set_text(GTKLABEL(ALabel), Inside)
+  else: gtk_label_set_text(GTKLABEL(ALabel), Outside)
+  Data = Not Data
+
+gtk_nimrod_init()
+window = gtk_window_new(GTK_WINDOW_TOPLEVEL)
+stackbox = gtk_vbox_new(TRUE, 10)
+button1 = gtk_button_new_with_label("Move mouse over button")
+buttonstyle = gtk_style_copy(gtk_widget_get_style(Button1))
+ButtonStyle.bg[GTK_STATE_PRELIGHT].pixel = 0
+ButtonStyle.bg[GTK_STATE_PRELIGHT].red = 0x0000FFFF
+ButtonStyle.bg[GTK_STATE_PRELIGHT].blue = 0
+ButtonStyle.bg[GTK_STATE_PRELIGHT].green = 0
+gtk_widget_set_style(button1, buttonstyle)
+button2 = gtk_button_new()
+ALabel = gtk_label_new(Outside)
+gtk_container_add(GTK_CONTAINER(button2), ALAbel)
+gtk_box_pack_start(GTK_BOX(stackbox), button1, TRUE, TRUE, 0)
+gtk_box_pack_start(GTK_BOX(stackbox), button2, TRUE, TRUE, 0)
+gtk_container_set_border_width(GTK_CONTAINER(Window), 5)
+gtk_container_add(GTK_Container(window), stackbox)
+discard gtk_signal_connect(GTKOBJECT(window), "destroy", 
+                   GTK_SIGNAL_FUNC(destroy), nil)
+overbutton = False
+discard gtk_signal_connect(GTKOBJECT(button1), "enter_notify_event", 
+                   GTK_SIGNAL_FUNC(ChangeLabel), addr(OverButton))
+discard gtk_signal_connect(GTKOBJECT(button1), "leave_notify_event", 
+                   GTK_SIGNAL_FUNC(ChangeLabel), addr(OverButton))
+gtk_widget_show_all(window)
+gtk_main()