ex3.pp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. program ex3;
  2. {$mode objfpc}
  3. uses
  4. glib,gtk;
  5. function newbutton(ALabel : PChar) : PGtkWidget;
  6. begin
  7. Result:=gtk_button_new_with_label(ALabel);
  8. gtk_widget_show(result);
  9. end;
  10. procedure destroy(widget : pGtkWidget ; data: pgpointer ); cdecl;
  11. begin
  12. gtk_main_quit();
  13. end;
  14. var
  15. window,
  16. totalbox,
  17. hbox,vbox : PgtkWidget;
  18. begin
  19. gtk_init (@argc, @argv);
  20. window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  21. // Box to divide window in 2 halves:
  22. totalbox := gtk_vbox_new(true,10);
  23. gtk_widget_show(totalbox);
  24. // A box for each half of the screen:
  25. hbox := gtk_hbox_new(false,5);
  26. gtk_widget_show(hbox);
  27. vbox := gtk_vbox_new(true,5);
  28. gtk_widget_show(vbox);
  29. // Put boxes in their halves
  30. gtk_box_pack_start(GTK_BOX(totalbox),hbox,true,true,0);
  31. gtk_box_pack_start(GTK_BOX(totalbox),vbox,true,true,0);
  32. // Now fill boxes with buttons.
  33. // Horizontal box
  34. gtk_box_pack_start(GTK_BOX(hbox),newbutton('Button 1'),false,false,0);
  35. gtk_box_pack_start(GTK_BOX(hbox),newbutton('Button 2'),false,false,0);
  36. gtk_box_pack_start(GTK_BOX(hbox),newbutton('Button 3'),false,false,0);
  37. // Vertical box
  38. gtk_box_pack_start(GTK_BOX(vbox),newbutton('Button A'),true,true,0);
  39. gtk_box_pack_start(GTK_BOX(vbox),newbutton('Button B'),true,true,0);
  40. gtk_box_pack_start(GTK_BOX(vbox),newbutton('Button C'),true,true,0);
  41. // Put totalbox in window
  42. gtk_container_set_border_width(GTK_CONTAINER(Window),5);
  43. gtk_container_add(GTK_Container(window),totalbox);
  44. gtk_signal_connect (PGTKOBJECT (window), 'destroy',
  45. GTK_SIGNAL_FUNC (@destroy), NULL);
  46. gtk_widget_show (window);
  47. gtk_main ();
  48. end.