ex9.pp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. program ex9;
  2. uses
  3. gdk,glib,gtk,strings;
  4. procedure destroy(widget : pGtkWidget ; data: pgpointer ); cdecl;
  5. begin
  6. gtk_main_quit();
  7. end;
  8. Const
  9. Inside : PChar ='Mouse is over label';
  10. OutSide : PChar ='Mouse is not over label';
  11. var
  12. window, button1,Button2, Alabel,stackbox : PGtkWidget;
  13. buttonstyle : pgtkstyle;
  14. OverButton : boolean;
  15. Procedure ChangeLabel(P : PGtkWidget;
  16. Event : PGdkEventCrossing;
  17. Var Data : Boolean);cdecl;
  18. begin
  19. If Not Data then
  20. gtk_label_set_text(PGTKLABEL(ALabel),Inside)
  21. else
  22. gtk_label_set_text(PGTKLABEL(ALabel),Outside);
  23. Data := Not Data;
  24. end;
  25. begin
  26. gtk_init (@argc, @argv);
  27. window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  28. stackbox:=gtk_vbox_new(TRUE,10);
  29. button1 := gtk_button_new_with_label(strnew('Move mouse over button'));
  30. buttonstyle := gtk_style_copy(gtk_widget_get_style(Button1));
  31. With ButtonStyle^.bg[GTK_STATE_PRELIGHT] do
  32. begin
  33. pixel:=0;
  34. red:=$ffff;
  35. blue:=0;
  36. green:=0;
  37. end;
  38. gtk_widget_set_style(button1,buttonstyle);
  39. button2 := gtk_button_new;
  40. ALabel:=gtk_label_new(Outside);
  41. gtk_container_add(GTK_CONTAINER(button2),ALAbel);
  42. gtk_box_pack_start(GTK_BOX(stackbox),button1,TRUE,TRUE,0);
  43. gtk_box_pack_start(GTK_BOX(stackbox),button2,TRUE,TRUE,0);
  44. gtk_container_set_border_width(GTK_CONTAINER(Window),5);
  45. gtk_container_add(GTK_Container(window),stackbox);
  46. gtk_signal_connect(PGTKOBJECT (window), 'destroy',
  47. GTK_SIGNAL_FUNC (@destroy), NULL);
  48. overbutton:=False;
  49. gtk_signal_connect(PGTKOBJECT(button1),'enter_notify_event',
  50. GTK_SIGNAL_FUNC (@ChangeLabel), @OverButton);
  51. gtk_signal_connect(PGTKOBJECT(button1),'leave_notify_event',
  52. GTK_SIGNAL_FUNC (@ChangeLabel), @OverButton);
  53. gtk_widget_show_all (window);
  54. gtk_main ();
  55. end.