test.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #include <gtk/gtk.h>
  2. /* This function rotates the position of the tabs */
  3. void rotate_book (GtkButton *button, GtkNotebook *notebook)
  4. {
  5. gtk_notebook_set_tab_pos (notebook, (notebook->tab_pos +1) %4);
  6. }
  7. /* Add/Remove the page tabs and the borders */
  8. void tabsborder_book (GtkButton *button, GtkNotebook *notebook)
  9. {
  10. gint tval = FALSE;
  11. gint bval = FALSE;
  12. if (notebook->show_tabs == 0)
  13. tval = TRUE;
  14. if (notebook->show_border == 0)
  15. bval = TRUE;
  16. gtk_notebook_set_show_tabs (notebook, tval);
  17. gtk_notebook_set_show_border (notebook, bval);
  18. }
  19. /* Remove a page from the notebook */
  20. void remove_book (GtkButton *button, GtkNotebook *notebook)
  21. {
  22. gint page;
  23. page = gtk_notebook_get_current_page(notebook);
  24. gtk_notebook_remove_page (notebook, page);
  25. /* Need to refresh the widget --
  26. This forces the widget to redraw itself. */
  27. gtk_widget_draw(GTK_WIDGET(notebook), NULL);
  28. }
  29. void delete (GtkWidget *widget, GtkWidget *event, gpointer data)
  30. {
  31. gtk_main_quit ();
  32. }
  33. void assign_new_style(GtkWidget *widget)
  34. {
  35. GtkStyle *default_style,*new_style;
  36. default_style = gtk_rc_get_style( widget );
  37. if (!default_style)
  38. default_style = gtk_widget_get_default_style();
  39. new_style = gtk_style_copy( default_style );
  40. new_style->engine_data = default_style->engine_data;
  41. new_style->klass = default_style->klass;
  42. gtk_widget_set_style( widget, new_style );
  43. }
  44. int main (int argc, char *argv[])
  45. {
  46. GtkWidget *window;
  47. GtkWidget *button;
  48. GtkWidget *table;
  49. GtkWidget *notebook;
  50. GtkWidget *frame;
  51. GtkWidget *label;
  52. gtk_init (&argc, &argv);
  53. window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  54. gtk_signal_connect (GTK_OBJECT (window), "delete_event",
  55. GTK_SIGNAL_FUNC (delete), NULL);
  56. gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  57. table = gtk_table_new(3,6,FALSE);
  58. gtk_container_add (GTK_CONTAINER (window), table);
  59. /* Create a new notebook, place the position of the tabs */
  60. notebook = gtk_notebook_new ();
  61. assign_new_style( notebook );
  62. gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
  63. gtk_table_attach_defaults(GTK_TABLE(table), notebook, 0,6,0,1);
  64. gtk_widget_show(notebook);
  65. /* Now finally let's prepend pages to the notebook */
  66. frame = gtk_frame_new ("frame");
  67. gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  68. gtk_widget_set_usize (frame, 100, 75);
  69. gtk_widget_show (frame);
  70. label = gtk_label_new ("label");
  71. assign_new_style( label );
  72. gtk_container_add (GTK_CONTAINER (frame), label);
  73. gtk_widget_show (label);
  74. label = gtk_label_new ("page");
  75. gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
  76. frame = gtk_frame_new ("frame");
  77. gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  78. gtk_widget_set_usize (frame, 100, 75);
  79. gtk_widget_show (frame);
  80. label = gtk_button_new_with_label ("button");
  81. assign_new_style( label );
  82. gtk_container_add (GTK_CONTAINER (frame), label);
  83. gtk_widget_show (label);
  84. label = gtk_label_new ("page");
  85. gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
  86. frame = gtk_frame_new ("frame");
  87. gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  88. gtk_widget_set_usize (frame, 100, 75);
  89. gtk_widget_show (frame);
  90. label = gtk_check_button_new_with_label ("check button");
  91. assign_new_style( label );
  92. gtk_container_add (GTK_CONTAINER (frame), label);
  93. gtk_widget_show (label);
  94. label = gtk_label_new ("page");
  95. gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
  96. frame = gtk_frame_new ("frame");
  97. gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  98. gtk_widget_set_usize (frame, 100, 75);
  99. gtk_widget_show (frame);
  100. label = gtk_radio_button_new_with_label (NULL, "radio button");
  101. assign_new_style( label );
  102. gtk_container_add (GTK_CONTAINER (frame), label);
  103. gtk_widget_show (label);
  104. label = gtk_label_new ("page");
  105. gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
  106. frame = gtk_frame_new ("frame");
  107. gtk_container_set_border_width (GTK_CONTAINER (frame), 10);
  108. gtk_widget_set_usize (frame, 100, 75);
  109. gtk_widget_show (frame);
  110. label = gtk_entry_new ();
  111. assign_new_style( label );
  112. gtk_container_add (GTK_CONTAINER (frame), label);
  113. gtk_widget_show (label);
  114. label = gtk_label_new ("page");
  115. gtk_notebook_append_page (GTK_NOTEBOOK (notebook), frame, label);
  116. /* Create a bunch of buttons */
  117. button = gtk_button_new_with_label ("close");
  118. gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  119. GTK_SIGNAL_FUNC (delete), NULL);
  120. gtk_table_attach_defaults(GTK_TABLE(table), button, 0,1,1,2);
  121. gtk_widget_show(button);
  122. button = gtk_button_new_with_label ("next page");
  123. gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  124. (GtkSignalFunc) gtk_notebook_next_page,
  125. GTK_OBJECT (notebook));
  126. gtk_table_attach_defaults(GTK_TABLE(table), button, 1,2,1,2);
  127. gtk_widget_show(button);
  128. button = gtk_button_new_with_label ("prev page");
  129. gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  130. (GtkSignalFunc) gtk_notebook_prev_page,
  131. GTK_OBJECT (notebook));
  132. gtk_table_attach_defaults(GTK_TABLE(table), button, 2,3,1,2);
  133. gtk_widget_show(button);
  134. button = gtk_button_new_with_label ("tab position");
  135. gtk_signal_connect (GTK_OBJECT (button), "clicked",
  136. (GtkSignalFunc) rotate_book, GTK_OBJECT(notebook));
  137. gtk_table_attach_defaults(GTK_TABLE(table), button, 3,4,1,2);
  138. gtk_widget_show(button);
  139. button = gtk_button_new_with_label ("tabs/border on/off");
  140. gtk_signal_connect (GTK_OBJECT (button), "clicked",
  141. (GtkSignalFunc) tabsborder_book,
  142. GTK_OBJECT (notebook));
  143. gtk_table_attach_defaults(GTK_TABLE(table), button, 4,5,1,2);
  144. gtk_widget_show(button);
  145. button = gtk_button_new_with_label ("remove page");
  146. gtk_signal_connect (GTK_OBJECT (button), "clicked",
  147. (GtkSignalFunc) remove_book,
  148. GTK_OBJECT(notebook));
  149. gtk_table_attach_defaults(GTK_TABLE(table), button, 5,6,1,2);
  150. gtk_widget_show(button);
  151. gtk_widget_show(table);
  152. gtk_widget_show(window);
  153. gtk_main ();
  154. return(0);
  155. }
  156. /* example-end */