notebook.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. {
  2. This file extracted from the GTK tutorial.
  3. notebook.c
  4. Converted from C to Pascal by Frank Loemker
  5. <[email protected]>
  6. }
  7. program notebook;
  8. uses
  9. glib,gdk,gtk;
  10. Function itos (I : Longint) : String;
  11. Var S : String[15];
  12. begin
  13. Str (I,S);
  14. itos:=S;
  15. end;
  16. { This function rotates the position of the tabs }
  17. procedure rotate_book (notebook:pGtkNotebook ); cdecl;
  18. begin
  19. gtk_notebook_set_tab_pos (notebook, TGtkPositionType((tab_pos(notebook^) +1) mod 4));
  20. end;
  21. { Add/Remove the page tabs and the borders }
  22. procedure tabsborder_book (notebook:pGtkNotebook ); cdecl;
  23. var tval, bval : gboolean;
  24. begin
  25. tval := false;
  26. bval := false;
  27. if show_tabs(notebook^) = 0 then
  28. tval := true;
  29. if show_border(notebook^) = 0 then
  30. bval := true;
  31. gtk_notebook_set_show_tabs (notebook, tval);
  32. gtk_notebook_set_show_border (notebook, bval);
  33. end;
  34. { Remove a page from the notebook }
  35. procedure remove_book (notebook: pGtkNotebook ); cdecl;
  36. var page : gint ;
  37. begin
  38. page := gtk_notebook_get_current_page(notebook);
  39. gtk_notebook_remove_page (notebook, page);
  40. { Need to refresh the widget --
  41. This forces the widget to redraw itself. }
  42. gtk_widget_draw(pGTKWIDGET(notebook), NIL);
  43. end;
  44. procedure delete (widget : pGtkWidget ; event: pGdkEvent; data: pgpointer ); cdecl;
  45. begin
  46. gtk_main_quit ();
  47. end;
  48. var
  49. window, button, table, thenotebook, frame, thelabel, checkbutton : pGtkWidget;
  50. i : integer;
  51. bufferf, bufferl : string[33];
  52. begin
  53. gtk_init (@argc, @argv);
  54. window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  55. gtk_signal_connect (pGTKOBJECT (window), 'delete_event',
  56. GTK_SIGNAL_FUNC (@delete), NIL);
  57. gtk_container_set_border_width (pGTKCONTAINER (window), 10);
  58. table := gtk_table_new(2,6,FALSE);
  59. gtk_container_add (pGTKCONTAINER (window), table);
  60. { Create a new notebook, place the position of the tabs }
  61. thenotebook := gtk_notebook_new ();
  62. gtk_notebook_set_tab_pos (pGTKNOTEBOOK (thenotebook), GTK_POS_TOP);
  63. gtk_table_attach_defaults(pGTKTABLE(table), thenotebook, 0,6,0,1);
  64. { lets append a bunch of pages to the notebook }
  65. for i:=0 to 4 do begin
  66. bufferf := 'Append Frame '+itos(i+1)+#0;
  67. bufferl := 'Page '+itos(i+1)+#0;
  68. frame := gtk_frame_new (pchar(@bufferf[1]));
  69. gtk_container_set_border_width (pGTKCONTAINER (frame), 10);
  70. gtk_widget_set_usize (frame, 100, 75);
  71. thelabel := gtk_label_new (pchar(@bufferf[1]));
  72. gtk_container_add (pGTKCONTAINER (frame), thelabel);
  73. thelabel := gtk_label_new (pchar(@bufferl[1]));
  74. gtk_notebook_append_page (pGTKNOTEBOOK (thenotebook), frame, thelabel);
  75. end;
  76. { now lets add a page to a specific spot }
  77. checkbutton := gtk_check_button_new_with_label ('Check me please!');
  78. gtk_widget_set_usize(checkbutton, 100, 75);
  79. thelabel := gtk_label_new ('Add page');
  80. gtk_notebook_insert_page (pGTKNOTEBOOK (thenotebook), checkbutton, thelabel, 2);
  81. { Now finally lets prepend pages to the notebook }
  82. for i:=0 to 4 do begin
  83. bufferf := 'Prepend Frame '+itos(i+1)+#0;
  84. bufferl := 'PPage '+itos(i+1)+#0;
  85. frame := gtk_frame_new (pchar(@bufferf[1]));
  86. gtk_container_set_border_width (pGTKCONTAINER (frame), 10);
  87. gtk_widget_set_usize (frame, 100, 75);
  88. thelabel := gtk_label_new (pchar(@bufferf[1]));
  89. gtk_container_add (pGTKCONTAINER (frame), thelabel);
  90. thelabel := gtk_label_new (pchar(@bufferl[1]));
  91. gtk_notebook_prepend_page (pGTKNOTEBOOK(thenotebook), frame, thelabel);
  92. gtk_widget_show (frame);
  93. end;
  94. { Set what page to start at (page 4) }
  95. gtk_notebook_set_page (pGTKNOTEBOOK(thenotebook), 3);
  96. { create a bunch of buttons }
  97. button := gtk_button_new_with_label ('close');
  98. gtk_signal_connect_object (pGTKOBJECT (button), 'clicked',
  99. GTK_SIGNAL_FUNC (@delete), NIL);
  100. gtk_table_attach(pGTKTABLE(table), button, 0,1,1,2,
  101. GTK_FILL or GTK_EXPAND,GTK_FILL,0,0);
  102. button := gtk_button_new_with_label ('next page');
  103. gtk_signal_connect_object (pGTKOBJECT (button), 'clicked',
  104. GTK_SIGNAL_FUNC (@gtk_notebook_next_page),
  105. pGTKOBJECT (thenotebook));
  106. gtk_table_attach(pGTKTABLE(table), button, 1,2,1,2,
  107. GTK_FILL or GTK_EXPAND,GTK_FILL,0,0);
  108. button := gtk_button_new_with_label ('prev page');
  109. gtk_signal_connect_object (pGTKOBJECT (button), 'clicked',
  110. GTK_SIGNAL_FUNC (@gtk_notebook_prev_page),
  111. pGTKOBJECT (thenotebook));
  112. gtk_table_attach(pGTKTABLE(table), button, 2,3,1,2,
  113. GTK_FILL or GTK_EXPAND,GTK_FILL,0,0);
  114. button := gtk_button_new_with_label ('tab position');
  115. gtk_signal_connect_object (pGTKOBJECT (button), 'clicked',
  116. GTK_SIGNAL_FUNC (@rotate_book), pGTKOBJECT(thenotebook));
  117. gtk_table_attach(pGTKTABLE(table), button, 3,4,1,2,
  118. GTK_FILL or GTK_EXPAND,GTK_FILL,0,0);
  119. button := gtk_button_new_with_label ('tabs/border on/off');
  120. gtk_signal_connect_object (pGTKOBJECT (button), 'clicked',
  121. GTK_SIGNAL_FUNC (@tabsborder_book),
  122. pGTKOBJECT (thenotebook));
  123. gtk_table_attach(pGTKTABLE(table), button, 4,5,1,2,
  124. GTK_FILL or GTK_EXPAND,GTK_FILL,0,0);
  125. button := gtk_button_new_with_label ('remove page');
  126. gtk_signal_connect_object (pGTKOBJECT (button), 'clicked',
  127. GTK_SIGNAL_FUNC (@remove_book),
  128. pGTKOBJECT(thenotebook));
  129. gtk_table_attach(pGTKTABLE(table), button, 5,6,1,2,
  130. GTK_FILL ,GTK_FILL,0,0);
  131. gtk_widget_show_all(window);
  132. gtk_main ();
  133. end.