PIPS
gtk_mchoose.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_mchoose.c:

Go to the source code of this file.

Enumerations

enum  { M_AVAILABLE_CHOICES_COLUMN_ID , M_COLUMNS_NUMBER }
 

Functions

static void mchoose_ok_notify (GtkWidget *widget __attribute__((unused)), gpointer data __attribute__((unused)))
 
static void mchoose_cancel_notify (GtkWidget *widget __attribute__((unused)), gpointer data __attribute__((unused)))
 
static void mchoose_window_done_proc (GtkWidget *window __attribute__((unused)), gpointer data __attribute__((unused)))
 Avoid the mchoose_frame destruction and act as cancel: More...
 
static void concat_labels (gpointer _row, gpointer _label)
 
static void mchoose_callback (GtkTreeSelection *selection, gpointer data __attribute__((unused)))
 Function used to update the text panel according to the list panel: More...
 
static void mchoose_de_select_all_notify (GtkWidget *widget __attribute__((unused)), gpointer data __attribute__((unused)))
 When we press on the "(De)Select" all button, select or deselect all the items. More...
 
void mchoose (char *title, gen_array_t array, void(*function_ok)(gen_array_t), void(*function_cancel)(void))
 
void create_mchoose_window ()
 

Variables

static GtkWidget * mchoices_label
 Multiple choices handling. More...
 
static GtkWidget * choices_list
 
static GtkWidget * ok_button
 
static GtkWidget * cancel_button
 
static GtkWidget * help_button
 
static GtkListStore * choices
 
static void(* apply_on_mchoices )(gen_array_t) = NULL
 
static void(* cancel_on_mchoices )(void) = NULL
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
M_AVAILABLE_CHOICES_COLUMN_ID 
M_COLUMNS_NUMBER 

Definition at line 47 of file gtk_mchoose.c.

47  {
49 };
@ M_AVAILABLE_CHOICES_COLUMN_ID
Definition: gtk_mchoose.c:48
@ M_COLUMNS_NUMBER
Definition: gtk_mchoose.c:48

Function Documentation

◆ concat_labels()

static void concat_labels ( gpointer  _row,
gpointer  _label 
)
static

Definition at line 149 of file gtk_mchoose.c.

149  {
150  GtkTreePath * path = (GtkTreePath *) _row;
151  gchar ** label = (gchar **) _label;
152  gchar * new_label;
153 
154  GValue path_associated_value = { 0, };
155  GtkTreeIter iter;
156  gtk_tree_model_get_iter(GTK_TREE_MODEL(choices), &iter, path);
157  gtk_tree_model_get_value(GTK_TREE_MODEL(choices), &iter,
158  M_AVAILABLE_CHOICES_COLUMN_ID, &path_associated_value);
159  gchar * path_associated_value_string = (gchar *) g_value_get_string(
160  &path_associated_value);
161 
162  new_label = strdup(concatenate(*label, path_associated_value_string, " ",
163  NULL));
164  g_free(*label);
165  *label = new_label;
166 }
static GtkListStore * choices
Definition: gtk_mchoose.c:45
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
char * strdup()

References choices, concatenate(), M_AVAILABLE_CHOICES_COLUMN_ID, and strdup().

Referenced by mchoose_callback().

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

◆ create_mchoose_window()

void create_mchoose_window ( )

Definition at line 242 of file gtk_mchoose.c.

242  {
243  guint i;
244  GtkWidget *vbox, *buttons_hbox;
245  GtkTreeIter iter;
246  GtkTreeSelection * _select;
247  GtkWidget *deselect_button;
248 
249  GtkWidget * scrolled_window;
250  scrolled_window = gtk_scrolled_window_new(NULL, NULL);
251  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
252  GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
253 
254  vbox = gtk_vbox_new(FALSE, 0);
255  buttons_hbox = gtk_hbox_new(FALSE, 0);
256  gtk_container_add(GTK_CONTAINER(mchoose_window), vbox);
257 
258  // mchoose_panel = xv_create(mchoose_frame, PANEL, NULL);
259 
260 
261  // mchoices = xv_create(mchoose_panel, PANEL_TEXT, PANEL_LABEL_STRING,
262  // "Current choices", PANEL_VALUE_DISPLAY_LENGTH, 30,
263  // PANEL_VALUE_STORED_LENGTH, 12800,
264  // /* PANEL_NOTIFY_PROC, mchoose_ok_notify, */
265  // XV_X, xv_col(mchoose_panel, 0), NULL);
266  gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("Current choices : "),
267  FALSE, FALSE, 0);
268  mchoices_label = gtk_label_new("");
269  gtk_box_pack_start(GTK_BOX(vbox), mchoices_label, FALSE, FALSE, 0);
270  gtk_widget_show(mchoices_label);
271 
272  mchoose_frame = gtk_frame_new("test");
273 
274  // choices = xv_create(mchoose_panel, PANEL_LIST, PANEL_LABEL_STRING,
275  // "Available choices", PANEL_LIST_DISPLAY_ROWS, 5, PANEL_NOTIFY_PROC,
276  // mchoose_notify, PANEL_CHOOSE_ONE, FALSE, XV_X, xv_col(
277  // mchoose_panel, 0), XV_Y, xv_rows(mchoose_panel, 1), NULL);
278  choices = gtk_list_store_new(M_COLUMNS_NUMBER, G_TYPE_STRING);
279  for (i = 0; i < 5; i++) {
280  gtk_list_store_append(GTK_LIST_STORE(choices), &iter);
281  gtk_list_store_set(choices, &iter, M_AVAILABLE_CHOICES_COLUMN_ID, "",
282  -1);
283  }
284 
285  choices_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(choices));
286  GtkCellRenderer * renderer = gtk_cell_renderer_text_new();
287  GtkTreeViewColumn * column;
288  column = gtk_tree_view_column_new_with_attributes("Available choices",
289  renderer, "text", M_AVAILABLE_CHOICES_COLUMN_ID, NULL);
290  gtk_tree_view_append_column(GTK_TREE_VIEW(choices_list), column);
291 
292  _select = gtk_tree_view_get_selection(GTK_TREE_VIEW(choices_list));
293  gtk_tree_selection_set_mode(GTK_TREE_SELECTION(_select),
294  GTK_SELECTION_MULTIPLE);
295  g_signal_connect(_select, "changed", G_CALLBACK(mchoose_callback), NULL);
296 
297  gtk_container_add(GTK_CONTAINER(scrolled_window), choices_list);
298  gtk_container_add(GTK_CONTAINER(mchoose_frame), scrolled_window);
299  gtk_box_pack_start(GTK_BOX(vbox), mchoose_frame, TRUE, TRUE, 5);
300  // gtk_box_pack_start(GTK_BOX(window_vbox), choices_list, FALSE, FALSE, 0);
301  gtk_widget_show(choices_list);
302 
303  // ok = xv_create(mchoose_panel, PANEL_BUTTON, PANEL_LABEL_STRING, "OK",
304  // PANEL_NOTIFY_PROC, mchoose_ok_notify, XV_X,
305  // xv_col(mchoose_panel, 5), XV_Y, xv_rows(mchoose_panel, 5), NULL);
306  ok_button = gtk_button_new_with_label("OK");
307  gtk_signal_connect(GTK_OBJECT(ok_button), "clicked", GTK_SIGNAL_FUNC(
308  mchoose_ok_notify), NULL);
309  gtk_box_pack_start(GTK_BOX(buttons_hbox), ok_button, FALSE, FALSE, 5);
310 
311  // (void) xv_create(mchoose_panel, PANEL_BUTTON, PANEL_LABEL_STRING,
312  // "(De)Select all", PANEL_NOTIFY_PROC, mchoose_de_select_all_notify,
313  // NULL);
314  deselect_button = gtk_button_new_with_label("(De)Select all");
315  gtk_signal_connect(GTK_OBJECT(deselect_button), "clicked", GTK_SIGNAL_FUNC(
317  gtk_box_pack_start(GTK_BOX(buttons_hbox), deselect_button, FALSE, FALSE, 5);
318 
319  // cancel = xv_create(mchoose_panel, PANEL_BUTTON, PANEL_LABEL_STRING,
320  // "Cancel", PANEL_NOTIFY_PROC, mchoose_cancel_notify, NULL);
321  cancel_button = gtk_button_new_with_label("Cancel");
322  gtk_signal_connect(GTK_OBJECT(cancel_button), "clicked", GTK_SIGNAL_FUNC(
323  mchoose_cancel_notify), NULL);
324  gtk_box_pack_start(GTK_BOX(buttons_hbox), cancel_button, FALSE, FALSE, 5);
325 
326  // help = xv_create(mchoose_panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Help",
327  // PANEL_NOTIFY_PROC, mchoose_help_notify, NULL);
328  help_button = gtk_button_new_with_label("Help");
329  gtk_signal_connect(GTK_OBJECT(help_button), "clicked", GTK_SIGNAL_FUNC(
330  mchoose_ok_notify), NULL);
331  gtk_box_pack_start(GTK_BOX(buttons_hbox), help_button, FALSE, FALSE, 5);
332 
333  gtk_box_pack_start(GTK_BOX(vbox), buttons_hbox, FALSE, FALSE, 5);
334  // xv_set(mchoose_frame, FRAME_DONE_PROC, mchoose_frame_done_proc, NULL);
335  gtk_window_set_default(GTK_WINDOW(mchoose_window), ok_button);
336 
337  gtk_signal_connect(GTK_OBJECT(mchoose_window), "delete-event",
338  GTK_SIGNAL_FUNC(mchoose_window_done_proc), NULL);
339 
340  gtk_widget_show_all(vbox);
341 }
GtkWidget * mchoose_frame
Definition: gpips-local.h:42
GtkWidget * mchoose_window
Definition: gpips-local.h:36
static GtkWidget * ok_button
Definition: gtk_mchoose.c:43
static GtkWidget * help_button
Definition: gtk_mchoose.c:44
static void mchoose_callback(GtkTreeSelection *selection, gpointer data __attribute__((unused)))
Function used to update the text panel according to the list panel:
Definition: gtk_mchoose.c:171
static GtkWidget * cancel_button
Definition: gtk_mchoose.c:43
static void mchoose_ok_notify(GtkWidget *widget __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_mchoose.c:60
static GtkWidget * mchoices_label
Multiple choices handling.
Definition: gtk_mchoose.c:43
static GtkWidget * choices_list
Definition: gtk_mchoose.c:43
static void mchoose_de_select_all_notify(GtkWidget *widget __attribute__((unused)), gpointer data __attribute__((unused)))
When we press on the "(De)Select" all button, select or deselect all the items.
Definition: gtk_mchoose.c:192
static void mchoose_cancel_notify(GtkWidget *widget __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_mchoose.c:128
static void mchoose_window_done_proc(GtkWidget *window __attribute__((unused)), gpointer data __attribute__((unused)))
Avoid the mchoose_frame destruction and act as cancel:
Definition: gtk_mchoose.c:145

References cancel_button, choices, choices_list, help_button, M_AVAILABLE_CHOICES_COLUMN_ID, M_COLUMNS_NUMBER, mchoices_label, mchoose_callback(), mchoose_cancel_notify(), mchoose_de_select_all_notify(), mchoose_frame, mchoose_ok_notify(), mchoose_window, mchoose_window_done_proc(), and ok_button.

Referenced by gpips_main(), and wpips_main().

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

◆ mchoose()

void mchoose ( char *  title,
gen_array_t  array,
void(*)(gen_array_t function_ok,
void(*)(void)  function_cancel 
)

move the pointer to the center of the query window

Definition at line 212 of file gtk_mchoose.c.

213  {
214  int i, argc = gen_array_nitems(array);
215 
216  GtkTreeIter iter;
218 
219  apply_on_mchoices = function_ok;
220  cancel_on_mchoices = function_cancel;
221 
222  gtk_window_set_title(GTK_WINDOW(mchoose_window), title);
223  gtk_list_store_clear(choices);
224 
225  for (i = 0; i < argc; i++) {
226  string name = gen_array_item(array, i);
227  gtk_list_store_append(GTK_LIST_STORE(choices), &iter);
228  gtk_list_store_set(choices, &iter, M_AVAILABLE_CHOICES_COLUMN_ID, name,
229  -1);
230  }
231  gtk_widget_show(mchoose_window);
232 
233  /* move the pointer to the center of the query window */
234  // Sans vouloir remettre en question le design de la chose
235  // A priori je ne traduirai pas ça à moins qu'on ne le
236  // demande expressément...
237  //pointer_in_center_of_frame(mchoose_frame);
238  //?
239  // xv_set(mchoices, PANEL_NOTIFY_PROC, mchoose_ok_notify, NULL);
240 }
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_mchoices)(gen_array_t)
Definition: gtk_mchoose.c:51
static void(* cancel_on_mchoices)(void)
Definition: gtk_mchoose.c:52
static entity array

References apply_on_mchoices, array, cancel_on_mchoices, choices, gen_array_item(), gen_array_nitems(), M_AVAILABLE_CHOICES_COLUMN_ID, and mchoose_window.

Referenced by continue_create_workspace_notify().

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

◆ mchoose_callback()

static void mchoose_callback ( GtkTreeSelection *  selection,
gpointer data   __attribute__(unused) 
)
static

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

Make the PANEL_VALUE of mchoices a string that is all the names of the selected files:

Definition at line 171 of file gtk_mchoose.c.

171  {
172  GList * selected_rows;
173  gchar * new_mchoices_label;
174 
175  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(choices_list));
176  new_mchoices_label = strdup("");
177 
178  /* Make the PANEL_VALUE of mchoices a string that is all the
179  names of the selected files: */
180  selected_rows = gtk_tree_selection_get_selected_rows(GTK_TREE_SELECTION(
181  selection), (GtkTreeModel**)&choices);
182 
183  g_list_foreach(selected_rows, concat_labels, &new_mchoices_label);
184  g_list_free(selected_rows);
185 
186  gtk_label_set_text(GTK_LABEL(mchoices_label), new_mchoices_label);
187  g_free(new_mchoices_label);
188 }
static void concat_labels(gpointer _row, gpointer _label)
Definition: gtk_mchoose.c:149

References choices, choices_list, concat_labels(), mchoices_label, and strdup().

Referenced by create_mchoose_window(), and mchoose_de_select_all_notify().

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

◆ mchoose_cancel_notify()

static void mchoose_cancel_notify ( GtkWidget *widget   __attribute__(unused),
gpointer data   __attribute__(unused) 
)
static

Definition at line 128 of file gtk_mchoose.c.

128  {
129  hide_window(mchoose_window, NULL, NULL);
130 
131  // The OK button becomes inactive through RETURN:
132  gtk_window_set_default(GTK_WINDOW(mchoose_window), NULL);
133 
134  // ?
135  //xv_set(mchoices, PANEL_NOTIFY_PROC, NULL);
136 
137  (*cancel_on_mchoices)();
138 
139  gtk_list_store_clear(choices);
140 
141  gtk_label_set_text(GTK_LABEL(mchoices_label), "");
142 }
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89

References choices, hide_window(), mchoices_label, and mchoose_window.

Referenced by create_mchoose_window(), and mchoose_window_done_proc().

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

◆ mchoose_de_select_all_notify()

static void mchoose_de_select_all_notify ( GtkWidget *widget   __attribute__(unused),
gpointer data   __attribute__(unused) 
)
static

When we press on the "(De)Select" all button, select or deselect all the items.

Update the "Current choices":

Next time we press this button, do the opposite:

Definition at line 192 of file gtk_mchoose.c.

192  {
193  GtkTreeSelection * selection;
194 
195  selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(choices_list));
196 
197  static bool select_all_when_press_this_button = TRUE;
198 
199  if (select_all_when_press_this_button) {
200  gtk_tree_selection_select_all(GTK_TREE_SELECTION(selection));
201  } else {
202  gtk_tree_selection_unselect_all(GTK_TREE_SELECTION(selection));
203  }
204 
205  /* Update the "Current choices": */
206  mchoose_callback(selection, NULL);
207 
208  /* Next time we press this button, do the opposite: */
209  select_all_when_press_this_button = !select_all_when_press_this_button;
210 }

References choices_list, and mchoose_callback().

Referenced by create_mchoose_window().

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

◆ mchoose_ok_notify()

static void mchoose_ok_notify ( GtkWidget *widget   __attribute__(unused),
gpointer data   __attribute__(unused) 
)
static

Upperbound size for the scanf buffer:

Delay the graphics transformations. RK, 21/05/1993.

Definition at line 60 of file gtk_mchoose.c.

60  {
61  gen_array_t mchoices_args = gen_array_make(0);
62 
63  GtkTreeSelection * selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(
64  choices_list));
65 
66  gchar *buffer, *mchoices_notify_buffer;
67  int mchoices_length = 0;
68 // int nchoices;
69  int len;
70 // int item_is_in_the_list = FALSE;
71  char * p;
72 
73 // nchoices = (int) xv_get(choices, PANEL_LIST_NROWS, NULL);
74 
75  mchoices_notify_buffer = strdup(gtk_label_get_text(GTK_LABEL(mchoices_label)));
76  /* Upperbound size for the scanf buffer: */
77  buffer = (char *) malloc(strlen(mchoices_notify_buffer) + 1);
78 
79  p = mchoices_notify_buffer;
80  while (sscanf(p, "%s%n", buffer, &len) == 1) {
81  gen_array_dupaddto(mchoices_args, mchoices_length++, buffer);
82 // item_is_in_the_list = FALSE;
83 // for (int i = 0; i < nchoices; i++)
84 // if (strcmp((char *) xv_get(choices, PANEL_LIST_STRING, i), buffer)
85 // == 0) {
86 // item_is_in_the_list = TRUE;
87 // break;
88 // }
89 // if (item_is_in_the_list == FALSE)
90 // break;
91  p += len;
92  }
93 
94  g_free(mchoices_notify_buffer);
95  g_free(buffer);
96  //
97  // /* At least on item selected, and in the list.
98  // RK, 21/05/1993.
99  // */
100  // if (mchoices_length == 0 || item_is_in_the_list == FALSE) {
101  // char *s;
102  // s = mchoices_length == 0 ? "You have to select at least 1 item!"
103  // : "You have selected an item not in the choice list!";
104  // gen_array_full_free(mchoices_args);
105  // prompt_user(s);
106  // return;
107  // }
108  if (gtk_tree_selection_count_selected_rows(selection) == 0) {
109  prompt_user("You have to select at least 1 item !");
110  return;
111  }
112 
113  hide_window(mchoose_window, NULL, NULL);
114 
115  // ?
116  // xv_set(mchoices, PANEL_NOTIFY_PROC, NULL);
117 
118  (*apply_on_mchoices)(mchoices_args);
119  gen_array_full_free(mchoices_args);
120 
121  /* Delay the graphics transformations. RK, 21/05/1993. */
122 
123  gtk_list_store_clear(choices);
124 
125  gtk_label_set_text(GTK_LABEL(mchoices_label), "");
126 }
void gen_array_full_free(gen_array_t a)
Definition: array.c:77
gen_array_t gen_array_make(size_t size)
declarations...
Definition: array.c:40
void gen_array_dupaddto(gen_array_t a, size_t i, void *what)
Definition: array.c:111
void * malloc(YYSIZE_T)
void prompt_user(string a_printf_format,...)
Definition: gtk_log.c:66
static string buffer
Definition: string.c:113

References buffer, choices, choices_list, gen_array_dupaddto(), gen_array_full_free(), gen_array_make(), hide_window(), malloc(), mchoices_label, mchoose_window, prompt_user(), and strdup().

Referenced by create_mchoose_window().

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

◆ mchoose_window_done_proc()

static void mchoose_window_done_proc ( GtkWidget *window   __attribute__(unused),
gpointer data   __attribute__(unused) 
)
static

Avoid the mchoose_frame destruction and act as cancel:

Definition at line 145 of file gtk_mchoose.c.

145  {
146  mchoose_cancel_notify(NULL, NULL);
147 }

References mchoose_cancel_notify().

Referenced by create_mchoose_window().

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

Variable Documentation

◆ apply_on_mchoices

void(* apply_on_mchoices) (gen_array_t) ( gen_array_t  ) = NULL
static

Definition at line 51 of file gtk_mchoose.c.

Referenced by mchoose().

◆ cancel_button

GtkWidget * cancel_button
static

Definition at line 43 of file gtk_mchoose.c.

Referenced by create_mchoose_window().

◆ cancel_on_mchoices

void(* cancel_on_mchoices) (void) ( void  ) = NULL
static

Definition at line 52 of file gtk_mchoose.c.

Referenced by mchoose().

◆ choices

GtkListStore* choices
static

◆ choices_list

GtkWidget * choices_list
static

◆ help_button

GtkWidget * help_button
static

Definition at line 44 of file gtk_mchoose.c.

Referenced by create_mchoose_window(), and create_query_window().

◆ mchoices_label

GtkWidget* mchoices_label
static

Multiple choices handling.

Definition at line 43 of file gtk_mchoose.c.

Referenced by create_mchoose_window(), mchoose_callback(), mchoose_cancel_notify(), and mchoose_ok_notify().

◆ ok_button

GtkWidget * ok_button
static

Definition at line 43 of file gtk_mchoose.c.

Referenced by create_mchoose_window(), and create_query_window().