Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.79 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <gtk/gtk.h>
  3.  
  4. void creationWindows ();
  5. void mainWindowCreation(int argc, char *argv[]);
  6. void buttonCreation(GtkWidget **win);
  7. int main (int argc, char *argv[]);
  8. void singup(GtkWidget **pWindow);
  9. void OnValider(GtkWidget *pBtn, gpointer data);
  10.  
  11.  
  12. void singup(GtkWidget **pWindow){
  13. GtkWidget *pVBox;
  14. GtkWidget *pFrame;
  15. GtkWidget *pVBoxFrame;
  16. GtkWidget *pSeparator;
  17. GtkWidget *pEntry;
  18. GtkWidget *pLabel;
  19.  
  20. GtkWidget *pRadio1;
  21. GtkWidget *pRadio2;
  22. GtkWidget *pValider;
  23.  
  24. gchar *sUtf8;
  25.  
  26. pVBox = gtk_vbox_new(TRUE, 0);
  27. gtk_container_add(GTK_CONTAINER(*pWindow), pVBox);
  28.  
  29. /* Creation du premier GtkFrame */
  30. pFrame = gtk_frame_new("Profil");
  31. gtk_box_pack_start(GTK_BOX(pVBox), pFrame, TRUE, FALSE, 0);
  32.  
  33. /* Creation et insertion d une boite pour le premier GtkFrame */
  34. pVBoxFrame = gtk_vbox_new(TRUE, 0);
  35. gtk_container_add(GTK_CONTAINER(pFrame), pVBoxFrame);
  36.  
  37. /* Creation et insertion des elements contenus dans le premier GtkFrame */
  38. sUtf8 = g_locale_to_utf8("Prénom :", -1, NULL, NULL, NULL);
  39. pLabel = gtk_label_new(sUtf8);
  40. g_free(sUtf8);
  41. gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0);
  42. pEntry = gtk_entry_new();
  43. gtk_box_pack_start(GTK_BOX(pVBoxFrame), pEntry, TRUE, FALSE, 0);
  44.  
  45. /* Creation d un GtkHSeparator */
  46. pSeparator = gtk_hseparator_new();
  47. gtk_box_pack_start(GTK_BOX(pVBoxFrame), pSeparator, TRUE, FALSE, 0);
  48.  
  49. sUtf8 = g_locale_to_utf8("âge :", -1, NULL, NULL, NULL);
  50. pLabel = gtk_label_new(sUtf8);
  51. g_free(sUtf8);
  52. gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0);
  53. pEntry = gtk_entry_new();
  54. gtk_box_pack_start(GTK_BOX(pVBoxFrame), pEntry, TRUE, FALSE, 0);
  55.  
  56.  
  57.  
  58. //---------------------------
  59. /* Creation du deuxieme GtkFrame */
  60. pFrame = gtk_frame_new("Avez vous une salle de sport ?");
  61. gtk_box_pack_start(GTK_BOX(pVBox), pFrame, TRUE, FALSE, 0);
  62.  
  63. /* Creation et insertion d une boite pour le deuxieme GtkFrame */
  64. pVBoxFrame = gtk_vbox_new(TRUE, 0);
  65. gtk_container_add(GTK_CONTAINER(pFrame), pVBoxFrame);
  66.  
  67.  
  68. /* Création du premier bouton radio */
  69. pRadio1 = gtk_radio_button_new_with_label(NULL, "Pour");
  70. gtk_box_pack_start(GTK_BOX (pVBoxFrame), pRadio1, TRUE, FALSE, 0);
  71. /* Ajout du deuxieme */
  72. pRadio2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (pRadio1), "Contre");
  73. gtk_box_pack_start(GTK_BOX (pVBoxFrame), pRadio2, TRUE, FALSE, 0);
  74.  
  75. //------------------------------------------
  76. /* Creation du deuxieme GtkFrame */
  77. pFrame = gtk_frame_new("Votre objectif");
  78. gtk_box_pack_start(GTK_BOX(pVBox), pFrame, TRUE, FALSE, 0);
  79.  
  80. /* Creation et insertion d une boite pour le deuxieme GtkFrame */
  81. pVBoxFrame = gtk_vbox_new(TRUE, 0);
  82. gtk_container_add(GTK_CONTAINER(pFrame), pVBoxFrame);
  83.  
  84.  
  85. /* Création du premier bouton radio */
  86. pRadio1 = gtk_radio_button_new_with_label(NULL, "Pour");
  87. gtk_box_pack_start(GTK_BOX (pVBoxFrame), pRadio1, TRUE, FALSE, 0);
  88. /* Ajout du deuxieme */
  89. pRadio2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (pRadio1), "Contre");
  90. gtk_box_pack_start(GTK_BOX (pVBoxFrame), pRadio2, TRUE, FALSE, 0);
  91.  
  92.  
  93. //---------------------------
  94.  
  95. /* Creation du deuxieme GtkFrame */
  96. pFrame = gtk_frame_new("maladies");
  97. gtk_box_pack_start(GTK_BOX(pVBox), pFrame, TRUE, FALSE, 0);
  98.  
  99. /* Creation et insertion d une boite pour le deuxieme GtkFrame */
  100. pVBoxFrame = gtk_vbox_new(TRUE, 0);
  101. gtk_container_add(GTK_CONTAINER(pFrame), pVBoxFrame);
  102.  
  103. pEntry = gtk_entry_new();
  104. gtk_box_pack_start(GTK_BOX(pVBoxFrame), pEntry, TRUE, FALSE, 0);
  105.  
  106.  
  107. pValider = gtk_button_new_from_stock(GTK_STOCK_OK);
  108. gtk_box_pack_start(GTK_BOX (pVBoxFrame), pValider, TRUE, FALSE, 0);
  109.  
  110. g_signal_connect(G_OBJECT(pValider), "clicked", G_CALLBACK(OnValider), pRadio1);
  111. }
  112.  
  113. void OnValider(GtkWidget *pBtn, gpointer data)
  114. {
  115. GtkWidget *pInfo;
  116. GtkWidget *pWindow;
  117. GSList *pList;
  118. const gchar *sLabel;
  119. /* Récupération de la liste des boutons */
  120. pList = gtk_radio_button_get_group(GTK_RADIO_BUTTON(data));
  121.  
  122. /* Parcours de la liste */
  123. while(pList)
  124. {
  125. /* Le bouton est-il sélectionné */
  126. if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pList->data)))
  127. {
  128. /* OUI -> on copie le label du bouton */
  129. sLabel = gtk_button_get_label(GTK_BUTTON(pList->data));
  130. /* On met la liste a NULL pour sortir de la boucle */
  131. pList = NULL;
  132. }
  133. else
  134. {
  135. /* NON -> on passe au bouton suivant */
  136. pList = g_slist_next(pList);
  137. }
  138. }
  139.  
  140. pInfo = gtk_message_dialog_new(GTK_WINDOW(pWindow),
  141. GTK_DIALOG_MODAL,
  142. GTK_MESSAGE_INFO,
  143. GTK_BUTTONS_OK,
  144. "Vous avez choisi : %s", sLabel);
  145.  
  146.  
  147. gtk_dialog_run(GTK_DIALOG(pInfo));
  148.  
  149. gtk_widget_destroy(pInfo);
  150. }
  151.  
  152. void creationWindows (){
  153. GtkWidget *s_window = NULL;
  154.  
  155. s_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  156. gtk_container_set_border_width (GTK_CONTAINER(s_window), 30);
  157. gtk_window_set_title(GTK_WINDOW(s_window),"Fenetre secondaire");
  158. gtk_window_set_default_size(GTK_WINDOW(s_window),600,400);
  159. gtk_window_set_position(GTK_WINDOW(s_window),GTK_WIN_POS_CENTER);
  160. gtk_widget_realize(s_window);
  161. gtk_widget_show(s_window);
  162.  
  163. singup(&s_window);
  164. gtk_widget_show_all (s_window);
  165.  
  166. }
  167.  
  168.  
  169. void mainWindowCreation(int argc, char *argv[]){
  170.  
  171. /* Initialize GTK+ */
  172. gtk_init (&argc, &argv);
  173. GtkWidget *win = NULL;
  174. /* Create the main window */
  175. win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  176. gtk_container_set_border_width (GTK_CONTAINER (win), 30);
  177. gtk_window_set_title (GTK_WINDOW (win), "Programme personalisé");
  178. gtk_window_set_default_size(GTK_WINDOW(win), 600, 400);
  179. gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  180. gtk_widget_realize (win);
  181. g_signal_connect (win, "destroy", gtk_main_quit, NULL);
  182. buttonCreation(&win);
  183. gtk_widget_show_all (win);
  184.  
  185. }
  186.  
  187. void buttonCreation(GtkWidget **win){
  188. /* Create a vertical box with buttons */
  189. GtkWidget *vbox = gtk_vbox_new (FALSE, 6);
  190. gtk_container_add (GTK_CONTAINER (*win), vbox);
  191.  
  192. GtkWidget *button = gtk_button_new_from_stock (GTK_STOCK_CONNECT);
  193. g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (creationWindows),NULL);
  194. gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
  195.  
  196. button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
  197. g_signal_connect (button, "clicked", gtk_main_quit, NULL);
  198. gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
  199. }
  200.  
  201. int main (int argc, char *argv[])
  202. {
  203. mainWindowCreation(argc, argv);
  204.  
  205. /* Enter the main loop */
  206. gtk_main ();
  207. return 0;
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement