notebook.pp 6.3 KB

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