PIPS
gtk_schoose2.c File Reference
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include "genC.h"
#include "misc.h"
#include <gtk/gtk.h>
#include "gpips.h"
+ Include dependency graph for gtk_schoose2.c:

Go to the source code of this file.

Enumerations

enum  { SC2_AVAILABLE_CHOICES_COLUMN_ID , SC2_COLUMNS_NUMBER }
 

Functions

static void schoose_ok_notify (GtkWidget *widget, gpointer data)
 called when the "ok button" is clicked to validate an entry or when you select something with the menu associated to the beforementionned entry. More...
 
void schoose_close ()
 schoose_close() can be called even when schoose window is already closed. More...
 
void schoose_cancel_notify (GtkWidget *widget, gpointer data)
 
static void schoose_choice_callback (GtkTreeSelection *selection, gpointer data)
 Function used to update the text panel according to the list panel: More...
 
static void schoose_window_done_callback (GtkWidget *window, GdkEvent *ev, gpointer data)
 Avoid the schoose_frame destruction and act as cancel: More...
 
void schoose (char *title, gen_array_t array, char *initial_choice, void(*function_for_ok)(const char *), void(*function_for_cancel)(void))
 
void create_schoose_window ()
 

Variables

static GtkWidget * choice_label
 Single choice handling. More...
 
static GtkWidget * choices_list
 
static GtkWidget * ok_button
 
static GtkWidget * help
 
static GtkWidget * cancel_button
 
static GtkListStore * choices
 
static void(* apply_on_choice )(const char *)
 
static void(* apply_on_cancel )(void)
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
SC2_AVAILABLE_CHOICES_COLUMN_ID 
SC2_COLUMNS_NUMBER 

Definition at line 56 of file gtk_schoose2.c.

56  {
58 };
@ SC2_COLUMNS_NUMBER
Definition: gtk_schoose2.c:57
@ SC2_AVAILABLE_CHOICES_COLUMN_ID
Definition: gtk_schoose2.c:57

Function Documentation

◆ create_schoose_window()

void create_schoose_window ( )

Definition at line 189 of file gtk_schoose2.c.

189  {
190  guint i;
191  GtkWidget *window_vbox, *buttons_hbox, *current_choice_hbox;
192  GtkTreeIter iter;
193  GtkTreeSelection * selection;
194 
195  window_vbox = gtk_vbox_new(FALSE, 0);
196  buttons_hbox = gtk_hbox_new(FALSE, 0);
197  current_choice_hbox = gtk_hbox_new(FALSE, 0);
198  gtk_box_pack_start(GTK_BOX(window_vbox), current_choice_hbox, FALSE, FALSE,
199  0);
200  gtk_container_add(GTK_CONTAINER(schoose_window), window_vbox);
201 
202  gtk_box_pack_start(GTK_BOX(current_choice_hbox), gtk_label_new(
203  "Current choice : "), FALSE, FALSE, 0);
204  choice_label = gtk_label_new("");
205  gtk_box_pack_start(GTK_BOX(current_choice_hbox), choice_label, FALSE,
206  FALSE, 0);
207 
208  choices = gtk_list_store_new(SC2_COLUMNS_NUMBER, G_TYPE_STRING);
209  for (i = 0; i < 5; i++) {
210  gtk_list_store_append(GTK_LIST_STORE(choices), &iter);
211  gtk_list_store_set(GTK_LIST_STORE(choices), &iter,
213  //gtk_tree_store_set(GTK_TREE_STORE(choices), &iter, SC2_AVAILABLE_CHOICES, "");
214  }
215 
216  // the "graphical" choice component is the GtkTreeView * choices_list
217  choices_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(choices));
218  GtkCellRenderer * renderer = gtk_cell_renderer_text_new();
219  GtkTreeViewColumn * column;
220  column = gtk_tree_view_column_new_with_attributes("Available choices",
221  renderer, "text", SC2_AVAILABLE_CHOICES_COLUMN_ID, NULL);
222  gtk_tree_view_append_column(GTK_TREE_VIEW(choices_list), column);
223 
224  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(choices_list));
225  gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection),
226  GTK_SELECTION_SINGLE);
227  g_signal_connect(selection, "changed", G_CALLBACK(schoose_choice_callback),
228  NULL);
229 
230  gtk_box_pack_start(GTK_BOX(window_vbox), choices_list, TRUE, FALSE, 0);
231  gtk_widget_show(choices_list);
232 
233  ok_button = gtk_button_new_with_label("OK");
234  g_signal_connect(GTK_OBJECT(ok_button), "clicked", G_CALLBACK(
235  schoose_ok_notify), NULL);
236  gtk_box_pack_start(GTK_BOX(buttons_hbox), ok_button, FALSE, FALSE, 5);
237 
238  cancel_button = gtk_button_new_with_label("Cancel");
239  g_signal_connect(GTK_OBJECT(cancel_button), "clicked", G_CALLBACK(
240  schoose_cancel_notify), NULL);
241  gtk_box_pack_start(GTK_BOX(buttons_hbox), cancel_button, FALSE, FALSE, 5);
242 
243  help = gtk_button_new_with_label("Help");
244  g_signal_connect(GTK_OBJECT(help), "clicked",
245  G_CALLBACK(schoose_ok_notify), NULL);
246  gtk_box_pack_start(GTK_BOX(buttons_hbox), help, FALSE, FALSE, 5);
247 
248  gtk_box_pack_start(GTK_BOX(window_vbox), buttons_hbox, FALSE, FALSE, 5);
249 
250  gtk_window_set_default(GTK_WINDOW(schoose_window), ok_button);
251 
252  g_signal_connect(GTK_OBJECT(schoose_window), "delete_event", G_CALLBACK(
254 
255  gtk_widget_show_all(window_vbox);
256 }
GtkWidget * schoose_window
Definition: gpips-local.h:36
static GtkWidget * ok_button
Definition: gtk_schoose2.c:52
static GtkWidget * choice_label
Single choice handling.
Definition: gtk_schoose2.c:52
static GtkListStore * choices
Definition: gtk_schoose2.c:54
static GtkWidget * help
Definition: gtk_schoose2.c:52
static GtkWidget * cancel_button
Definition: gtk_schoose2.c:53
static void schoose_ok_notify(GtkWidget *widget, gpointer data)
called when the "ok button" is clicked to validate an entry or when you select something with the men...
Definition: gtk_schoose2.c:71
static void schoose_choice_callback(GtkTreeSelection *selection, gpointer data)
Function used to update the text panel according to the list panel:
Definition: gtk_schoose2.c:125
static void schoose_window_done_callback(GtkWidget *window, GdkEvent *ev, gpointer data)
Avoid the schoose_frame destruction and act as cancel:
Definition: gtk_schoose2.c:144
void schoose_cancel_notify(GtkWidget *widget, gpointer data)
Definition: gtk_schoose2.c:119
static GtkWidget * choices_list
Definition: gtk_schoose2.c:52

References cancel_button, choice_label, choices, choices_list, help, ok_button, SC2_AVAILABLE_CHOICES_COLUMN_ID, SC2_COLUMNS_NUMBER, schoose_cancel_notify(), schoose_choice_callback(), schoose_ok_notify(), schoose_window, and schoose_window_done_callback().

Referenced by gpips_main(), and wpips_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ schoose()

void schoose ( char *  title,
gen_array_t  array,
char *  initial_choice,
void(*)(const char *)  function_for_ok,
void(*)(void)  function_for_cancel 
)

move the pointer to the center of the query window

Definition at line 150 of file gtk_schoose2.c.

151  {
152  guint i;
153  string name;
154  GtkTreeIter iter;
155  GtkTreeSelection * selection;
156  bool do_select = FALSE;
157  int argc = gen_array_nitems(array);
158 
159  apply_on_choice = function_for_ok;
160  apply_on_cancel = function_for_cancel;
161 
162  gtk_window_set_title(GTK_WINDOW(schoose_window), title);
163  gtk_list_store_clear(choices);
164 
165  if (initial_choice != NULL) {
166  do_select = TRUE;
167  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(choices_list));
168  }
169 
170  for (i = 0; i < argc; i++) {
171  name = gen_array_item(array, i);
172  gtk_list_store_append(GTK_LIST_STORE(choices), &iter);
173  gtk_list_store_set(choices, &iter, SC2_AVAILABLE_CHOICES_COLUMN_ID,
174  name, -1);
175  if (do_select) // Initialise au choix initial ou default le premier
176  if (i == 0 || strcmp(initial_choice, name) == 0)
177  gtk_tree_selection_select_iter(GTK_TREE_SELECTION(selection),
178  &iter);
179  }
180  gtk_widget_show(schoose_window);
181 
182  /* move the pointer to the center of the query window */
183  // Sans vouloir remettre en question le design de la chose
184  // A priori je ne traduirai pas ça à moins qu'on ne le
185  // demande expressément...
186  //pointer_in_center_of_frame(schoose_frame);
187 }
size_t gen_array_nitems(const gen_array_t a)
Definition: array.c:131
void * gen_array_item(const gen_array_t a, size_t i)
Definition: array.c:143
static void(* apply_on_cancel)(void)
Definition: gtk_schoose2.c:61
static void(* apply_on_choice)(const char *)
Definition: gtk_schoose2.c:60
static entity array

References apply_on_cancel, apply_on_choice, array, choices, choices_list, gen_array_item(), gen_array_nitems(), SC2_AVAILABLE_CHOICES_COLUMN_ID, and schoose_window.

Referenced by open_workspace_notify(), select_module_from_menubar_callback(), select_module_notify(), and start_delete_workspace_notify().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ schoose_cancel_notify()

void schoose_cancel_notify ( GtkWidget *  widget,
gpointer  data 
)

Definition at line 119 of file gtk_schoose2.c.

119  {
120  schoose_close();
121  (*apply_on_cancel)();
122 }
void schoose_close()
schoose_close() can be called even when schoose window is already closed.
Definition: gtk_schoose2.c:113

References schoose_close().

Referenced by create_schoose_window().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ schoose_choice_callback()

static void schoose_choice_callback ( GtkTreeSelection *  selection,
gpointer  data 
)
static

Function used to update the text panel according to the list panel:

Definition at line 125 of file gtk_schoose2.c.

125  {
126  GtkTreeIter iter;
127  GtkTreeModel * model;
128  gchar * gc_choice;
129 
130  // if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
131  // pips_assert("schoose_choice_notify: no item selected !", 0);
132  // return;
133  // }
134 
135  if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
136  gtk_tree_model_get(GTK_TREE_MODEL(model), &iter,
137  SC2_AVAILABLE_CHOICES_COLUMN_ID, &gc_choice, -1);
138  gtk_label_set_text(GTK_LABEL(choice_label), gc_choice);
139  g_free(gc_choice);
140  }
141 }

References choice_label, and SC2_AVAILABLE_CHOICES_COLUMN_ID.

Referenced by create_schoose_window().

+ Here is the caller graph for this function:

◆ schoose_close()

void schoose_close ( )

schoose_close() can be called even when schoose window is already closed.

Definition at line 113 of file gtk_schoose2.c.

113  {
114  hide_window(schoose_window, NULL, NULL);
115  gtk_list_store_clear(choices);
116  gtk_label_set_text(GTK_LABEL(choice_label), "");
117 }
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89

References choice_label, choices, hide_window(), and schoose_window.

Referenced by end_delete_workspace_notify(), end_open_workspace_notify(), schoose_cancel_notify(), and schoose_ok_notify().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ schoose_ok_notify()

static void schoose_ok_notify ( GtkWidget *  widget,
gpointer  data 
)
static

called when the "ok button" is clicked to validate an entry or when you select something with the menu associated to the beforementionned entry.

Definition at line 71 of file gtk_schoose2.c.

71  {
72  GtkTreeIter iter;
73  GtkTreeModel ** model = NULL;
74  gchar * gc_choice;
75 
76  GtkTreeSelection * selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(
77  choices_list));
78 
79  if (!gtk_tree_selection_get_selected(selection, model, &iter)) {
80  prompt_user("Choose one item or cancel");
81  return;
82  }
83 
84  // gtk_tree_model_get(GTK_TREE_MODEL(*model), &iter,
85  // SC2_AVAILABLE_CHOICES_COLUMN_ID, &gc_choice, -1);
86 
87  gc_choice = strdup(gtk_label_get_text(GTK_LABEL(choice_label)));
88  // ----
89 
90  // curchoice = strdup((char *) xv_get(choice, PANEL_VALUE, 0));
91  //
92  // /* Modified to verify that an correct item is selected.
93  // RK, 21/05/1993. */
94  // nchoices = (int) xv_get(choices, PANEL_LIST_NROWS, 0);
95  // item_is_in_the_list = FALSE;
96  // for (i = 0; i < nchoices; i++)
97  // if (strcmp((char *) xv_get(choices, PANEL_LIST_STRING, i), curchoice)
98  // == 0) {
99  // item_is_in_the_list = TRUE;
100  // break;
101  // }
102  // if (item_is_in_the_list == FALSE)
103  // prompt_user("You have to choose one item of the list!");
104  // else {
105  // /* Normal case : */
106  (*apply_on_choice)(gc_choice);
107  g_free(gc_choice);
108  schoose_close();
109 }
void prompt_user(string a_printf_format,...)
Definition: gtk_log.c:66
char * strdup()

References choice_label, choices_list, prompt_user(), schoose_close(), and strdup().

Referenced by create_schoose_window().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ schoose_window_done_callback()

static void schoose_window_done_callback ( GtkWidget *  window,
GdkEvent *  ev,
gpointer  data 
)
static

Avoid the schoose_frame destruction and act as cancel:

Definition at line 144 of file gtk_schoose2.c.

145  {
146  (*apply_on_cancel)();
147  hide_window(window, NULL, NULL);
148 }

References hide_window().

Referenced by create_schoose_window().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ apply_on_cancel

void(* apply_on_cancel) (void) ( void  )
static

Definition at line 61 of file gtk_schoose2.c.

Referenced by schoose().

◆ apply_on_choice

void(* apply_on_choice) (const char *) ( const char *  )
static

Definition at line 60 of file gtk_schoose2.c.

Referenced by schoose().

◆ cancel_button

GtkWidget * cancel_button
static

Definition at line 53 of file gtk_schoose2.c.

Referenced by create_schoose_window().

◆ choice_label

GtkWidget* choice_label
static

Single choice handling.

Difference with previous release: 1/ schoose_close() must be called in order to close the schoose window. 2/ schoose() has one more argument, because cancel button is created. bb 04.06.91

Definition at line 52 of file gtk_schoose2.c.

Referenced by create_schoose_window(), schoose_choice_callback(), schoose_close(), and schoose_ok_notify().

◆ choices

GtkListStore* choices
static

Definition at line 54 of file gtk_schoose2.c.

Referenced by create_schoose_window(), schoose(), and schoose_close().

◆ choices_list

GtkWidget * choices_list
static

Definition at line 52 of file gtk_schoose2.c.

Referenced by create_schoose_window(), schoose(), and schoose_ok_notify().

◆ help

GtkWidget * help
static

Definition at line 52 of file gtk_schoose2.c.

Referenced by create_schoose_window().

◆ ok_button

GtkWidget * ok_button
static

Definition at line 52 of file gtk_schoose2.c.

Referenced by create_schoose_window().