PIPS
xv_mchoose.c File Reference
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/notice.h>
#include <xview/notify.h>
#include "genC.h"
#include "misc.h"
#include "wpips.h"
+ Include dependency graph for xv_mchoose.c:

Go to the source code of this file.

Functions

static void mchoose_help_notify (Panel_item item, Event *event)
 
static void mchoose_ok_notify (Panel_item item, Event *event)
 
static void mchoose_cancel_notify (Panel_item item, Event *event)
 
static void mchoose_frame_done_proc (Frame frame)
 Avoid the mchoose_frame destruction and act as cancel: More...
 
static int mchoose_notify (Panel_item item, char *item_string, Xv_opaque client_data, Panel_list_op op, Event *event, int row)
 Function used to update the text panel according to the list panel: More...
 
static void mchoose_de_select_all_notify (Panel_item item, Event *event)
 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 Panel_item mchoices
 Multiple choices handling. More...
 
static Panel_item choices
 
static Panel_item ok
 
static Panel_item cancel
 
static Panel_item help
 
static void(* apply_on_mchoices )(gen_array_t) = NULL
 
static void(* cancel_on_mchoices )(void) = NULL
 

Function Documentation

◆ create_mchoose_window()

void create_mchoose_window ( )

Carriage return enable for "OK". RK, 19/05/1993.

PANEL_NOTIFY_PROC, mchoose_ok_notify,

Avoid the mchoose_frame destruction:

Definition at line 290 of file xv_mchoose.c.

291 {
292  mchoose_panel = xv_create(mchoose_frame, PANEL, NULL);
293 
294 /* Carriage return enable for "OK". RK, 19/05/1993. */
295 
296  mchoices = xv_create(mchoose_panel, PANEL_TEXT,
297  PANEL_LABEL_STRING, "Current choices",
298  PANEL_VALUE_DISPLAY_LENGTH, 30,
299  PANEL_VALUE_STORED_LENGTH, 12800,
300  /* PANEL_NOTIFY_PROC, mchoose_ok_notify, */
301  XV_X, xv_col(mchoose_panel, 0),
302  NULL);
303 
304  choices = xv_create(mchoose_panel, PANEL_LIST,
305  PANEL_LABEL_STRING, "Available choices",
306  PANEL_LIST_DISPLAY_ROWS, 5,
307  PANEL_NOTIFY_PROC, mchoose_notify,
308  PANEL_CHOOSE_ONE, FALSE,
309  XV_X, xv_col(mchoose_panel, 0),
310  XV_Y, xv_rows(mchoose_panel, 1),
311  NULL);
312 
313  ok = xv_create(mchoose_panel, PANEL_BUTTON,
314  PANEL_LABEL_STRING, "OK",
315  PANEL_NOTIFY_PROC, mchoose_ok_notify,
316  XV_X, xv_col(mchoose_panel, 5),
317  XV_Y, xv_rows(mchoose_panel, 5),
318  NULL);
319 
320  (void) xv_create(mchoose_panel, PANEL_BUTTON,
321  PANEL_LABEL_STRING, "(De)Select all",
322  PANEL_NOTIFY_PROC, mchoose_de_select_all_notify,
323  NULL);
324 
325  cancel = xv_create(mchoose_panel, PANEL_BUTTON,
326  PANEL_LABEL_STRING, "Cancel",
327  PANEL_NOTIFY_PROC, mchoose_cancel_notify,
328  NULL);
329 
330  help = xv_create(mchoose_panel, PANEL_BUTTON,
331  PANEL_LABEL_STRING, "Help",
332  PANEL_NOTIFY_PROC, mchoose_help_notify,
333  NULL);
334 
335  window_fit(mchoose_panel);
336  window_fit(mchoose_frame);
337 
338  /*
339  Just to veto the xv_destroy():
340  (void) notify_interpose_destroy_func(mchoose_frame,
341  try_to_avoid_mchoose_destruction);
342  xv_set((Window) xv_get(mchoose_frame, XV_XID)
343  */
344  /* Avoid the mchoose_frame destruction: */
345  xv_set(mchoose_frame,
346  FRAME_DONE_PROC, mchoose_frame_done_proc,
347  NULL);
348 }
GtkWidget * mchoose_frame
Definition: gpips-local.h:42
Panel mchoose_panel
Definition: wpips-local.h:49
static void mchoose_cancel_notify(Panel_item item, Event *event)
Definition: xv_mchoose.c:126
static void mchoose_help_notify(Panel_item item, Event *event)
Definition: xv_mchoose.c:49
static Panel_item cancel
Definition: xv_mchoose.c:44
static Panel_item help
Definition: xv_mchoose.c:44
static Panel_item choices
Definition: xv_mchoose.c:44
static void mchoose_frame_done_proc(Frame frame)
Avoid the mchoose_frame destruction and act as cancel:
Definition: xv_mchoose.c:150
static void mchoose_ok_notify(Panel_item item, Event *event)
Definition: xv_mchoose.c:57
static void mchoose_de_select_all_notify(Panel_item item, Event *event)
When we press on the "(De)Select" all button, select or deselect all the items.
Definition: xv_mchoose.c:229
static Panel_item ok
Definition: xv_mchoose.c:44
static int mchoose_notify(Panel_item item, char *item_string, Xv_opaque client_data, Panel_list_op op, Event *event, int row)
Function used to update the text panel according to the list panel:
Definition: xv_mchoose.c:177
static Panel_item mchoices
Multiple choices handling.
Definition: xv_mchoose.c:44

References cancel, choices, help, mchoices, mchoose_cancel_notify(), mchoose_de_select_all_notify(), mchoose_frame, mchoose_frame_done_proc(), mchoose_help_notify(), mchoose_notify(), mchoose_ok_notify(), mchoose_panel, and ok.

+ Here is the call graph for this function:

◆ mchoose()

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

reset the choice set to empty

Delete all the rows, ie nchoices rows from row 0:

move the pointer to the center of the query window

The OK button becomes active through RETURN:

Definition at line 253 of file xv_mchoose.c.

257 {
258  int i, nchoices, argc = gen_array_nitems(array);
259 
260  apply_on_mchoices = function_ok;
261  cancel_on_mchoices = function_cancel;
262 
263  xv_set(mchoose_frame, FRAME_LABEL, title, NULL);
264 
265  /* reset the choice set to empty */
266  nchoices = (int) xv_get(choices, PANEL_LIST_NROWS, 0);
267 
268  /* Delete all the rows, ie nchoices rows from row 0: */
269  xv_set(choices,
270  PANEL_LIST_DELETE_ROWS, 0, nchoices,
271  NULL);
272 
273  for (i = 0; i < argc; i++) {
274  string mn = gen_array_item(array, i);
275  xv_set(choices, PANEL_LIST_STRING, i, mn, NULL);
276  }
277 
279 
280  /* move the pointer to the center of the query window */
282 
283  /* The OK button becomes active through RETURN: */
284  xv_set(mchoose_panel, PANEL_DEFAULT_ITEM, ok, NULL);
285  xv_set(mchoices, PANEL_NOTIFY_PROC, mchoose_ok_notify, NULL);
286 }
void const char const char const int
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 entity array
static void(* apply_on_mchoices)(gen_array_t)
Definition: xv_mchoose.c:46
static void(* cancel_on_mchoices)(void)
Definition: xv_mchoose.c:47
void unhide_window(Frame frame)
map a frame on the screen
Definition: xv_utils.c:55
void pointer_in_center_of_frame(Frame frame)
Centre la souris sur une fene^tre :
Definition: xv_utils.c:64

References apply_on_mchoices, array, cancel_on_mchoices, choices, gen_array_item(), gen_array_nitems(), int, mchoices, mchoose_frame, mchoose_ok_notify(), mchoose_panel, ok, pointer_in_center_of_frame(), and unhide_window().

+ Here is the call graph for this function:

◆ mchoose_cancel_notify()

static void mchoose_cancel_notify ( Panel_item  item,
Event *  event 
)
static

The OK button becomes inactive through RETURN:

Delete all the rows, ie nchoices rows from row 0:

Definition at line 126 of file xv_mchoose.c.

128 {
130 
131  /* The OK button becomes inactive through RETURN: */
132  xv_set(mchoose_panel, PANEL_DEFAULT_ITEM, NULL, NULL);
133  xv_set(mchoices, PANEL_NOTIFY_PROC, NULL);
134 
135  (*cancel_on_mchoices)();
136 
137  /* Delete all the rows, ie nchoices rows from row 0: */
138  xv_set(choices,
139  PANEL_LIST_DELETE_ROWS, 0, (int) xv_get(choices,
140  PANEL_LIST_NROWS,
141  NULL),
142  NULL);
143 
144  xv_set(mchoices, PANEL_VALUE, "", NULL);
145 }
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89

References choices, hide_window(), mchoices, mchoose_frame, and mchoose_panel.

Referenced by create_mchoose_window(), and mchoose_frame_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 ( Panel_item  item,
Event *  event 
)
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 229 of file xv_mchoose.c.

231 {
232  int i;
233  static bool select_all_when_press_this_button = TRUE;
234 
235  int nchoices = (int) xv_get(choices, PANEL_LIST_NROWS);
236 
237  for(i = nchoices - 1; i >= 0; i--)
238  xv_set (choices,
239  PANEL_LIST_SELECT, i, select_all_when_press_this_button,
240  NULL);
241 
242  /* Update the "Current choices": */
243  (void) mchoose_notify((Panel_item)NULL, NULL,
244  (Xv_opaque)NULL, PANEL_LIST_OP_SELECT,
245  (Event*) NULL, 0);
246 
247  /* Next time we press this button, do the opposite: */
248  select_all_when_press_this_button = !select_all_when_press_this_button;
249 }

References choices, int, and mchoose_notify().

Referenced by create_mchoose_window().

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

◆ mchoose_frame_done_proc()

static void mchoose_frame_done_proc ( Frame  frame)
static

Avoid the mchoose_frame destruction and act as cancel:

Definition at line 150 of file xv_mchoose.c.

151 {
152  mchoose_cancel_notify((Panel_item)NULL, (Event*)NULL);
153 }

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:

◆ mchoose_help_notify()

static void mchoose_help_notify ( Panel_item  item,
Event *  event 
)
static

Definition at line 49 of file xv_mchoose.c.

52 {
53  display_help("MultipleChoice");
54 }
void display_help(char *topic)
Definition: gtk_help.c:50

References display_help().

Referenced by create_mchoose_window().

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

◆ mchoose_notify()

static int mchoose_notify ( Panel_item  item,
char *  item_string,
Xv_opaque  client_data,
Panel_list_op  op,
Event *  event,
int  row 
)
static

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

Now it is mchoices_notify_buffer which is used for the selection. No size verification implemented yet... :-) RK, 19/05/1993.

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

Avoid deletion and insertion with the edit menu of button 3:

Accept the operation by default:

Definition at line 177 of file xv_mchoose.c.

183 {
184  switch (op) {
185  case PANEL_LIST_OP_SELECT:
186  case PANEL_LIST_OP_DESELECT:
187  {
188  int i;
189  int nchoices = (int) xv_get(choices, PANEL_LIST_NROWS);
190 
191  /* Now it is mchoices_notify_buffer which is used for the selection.
192  No size verification implemented yet... :-)
193  RK, 19/05/1993. */
194  /* Make the PANEL_VALUE of mchoices a string that is all the
195  names of the selected files: */
196  xv_set(mchoices, PANEL_VALUE, "", NULL);
197 
198  for(i = 0; i < nchoices; i++) {
199  if ((int) xv_get(choices, PANEL_LIST_SELECTED, i) == TRUE) {
200  xv_set(mchoices, PANEL_VALUE,
201  concatenate((char *) xv_get(mchoices, PANEL_VALUE),
202  (char *) xv_get(choices,
203  PANEL_LIST_STRING, i),
204  " ",
205  NULL),
206  NULL);
207  }
208  }
209  break;
210  }
211 
212  /* Avoid deletion and insertion with the edit menu of button 3: */
213  case PANEL_LIST_OP_DELETE:
214  case PANEL_LIST_OP_VALIDATE:
215  return XV_ERROR;
216 
217  default:
218  pips_assert("schoose_choice_notify: unknown operation !", 0);
219  }
220 
221  /* Accept the operation by default: */
222  return XV_OK;
223 }
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183

References choices, concatenate(), int, mchoices, and pips_assert.

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_ok_notify()

static void mchoose_ok_notify ( Panel_item  item,
Event *  event 
)
static

Upperbound size for the scanf buffer:

At least on item selected, and in the list. RK, 21/05/1993.

The OK button becomes inactive through RETURN:

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

Delete all the rows, ie nchoices rows from row 0:

Definition at line 57 of file xv_mchoose.c.

60 {
61  gen_array_t mchoices_args = gen_array_make(0);
62  char * buffer, * mchoices_notify_buffer;
63  int mchoices_length = 0;
64  int i, nchoices, len;
65  int item_is_in_the_list = FALSE;
66  char * p;
67 
68  nchoices = (int) xv_get(choices, PANEL_LIST_NROWS, NULL);
69  mchoices_length = 0;
70 
71  mchoices_notify_buffer = strdup((char *) xv_get(mchoices, PANEL_VALUE));
72  /* Upperbound size for the scanf buffer: */
73  buffer = (char *) malloc(strlen(mchoices_notify_buffer) + 1);
74 
75  p = mchoices_notify_buffer;
76  while(sscanf(p, "%s%n", buffer, &len) == 1) {
77  gen_array_dupaddto(mchoices_args, mchoices_length++, buffer);
78  item_is_in_the_list = FALSE;
79  for(i = 0; i < nchoices; i++)
80  if (strcmp((char *)
81  xv_get(choices, PANEL_LIST_STRING, i), buffer) == 0) {
82  item_is_in_the_list = TRUE;
83  break;
84  }
85  if (item_is_in_the_list == FALSE)
86  break;
87  p += len;
88  }
89 
90  free(mchoices_notify_buffer);
91  free(buffer);
92 
93  /* At least on item selected, and in the list.
94  RK, 21/05/1993.
95  */
96  if (mchoices_length == 0 || item_is_in_the_list == FALSE) {
97  char *s;
98  s = mchoices_length == 0 ? "You have to select at least 1 item!" :
99  "You have selected an item not in the choice list!";
100  gen_array_full_free(mchoices_args);
101  prompt_user(s);
102  return;
103  }
104 
106 
107  /* The OK button becomes inactive through RETURN: */
108  xv_set(mchoose_panel, PANEL_DEFAULT_ITEM, NULL, NULL);
109  xv_set(mchoices, PANEL_NOTIFY_PROC, NULL);
110 
111  (*apply_on_mchoices)(mchoices_args);
112  gen_array_full_free(mchoices_args);
113 
114  /* Delay the graphics transformations. RK, 21/05/1993. */
115 
116  /* Delete all the rows, ie nchoices rows from row 0: */
117  xv_set(choices,
118  PANEL_LIST_DELETE_ROWS, 0, nchoices,
119  NULL);
120 
121  xv_set(mchoices, PANEL_VALUE, "", NULL);
122 }
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 free(void *)
void prompt_user(string a_printf_format,...)
Definition: gtk_log.c:66
char * strdup()
static string buffer
Definition: string.c:113

References buffer, choices, free(), gen_array_dupaddto(), gen_array_full_free(), gen_array_make(), hide_window(), int, malloc(), mchoices, mchoose_frame, mchoose_panel, prompt_user(), and strdup().

Referenced by create_mchoose_window(), and mchoose().

+ 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 46 of file xv_mchoose.c.

Referenced by mchoose().

◆ cancel

Panel_item cancel
static

Definition at line 44 of file xv_mchoose.c.

Referenced by create_mchoose_window(), and loop_chunk_size_and_strip_mine().

◆ cancel_on_mchoices

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

Definition at line 47 of file xv_mchoose.c.

Referenced by mchoose().

◆ choices

◆ help

Panel_item help
static

Definition at line 44 of file xv_mchoose.c.

Referenced by create_mchoose_window().

◆ mchoices

Panel_item mchoices
static

Multiple choices handling.

Definition at line 44 of file xv_mchoose.c.

Referenced by create_mchoose_window(), mchoose(), mchoose_cancel_notify(), mchoose_notify(), and mchoose_ok_notify().

◆ ok

Panel_item ok
static

Definition at line 44 of file xv_mchoose.c.

Referenced by create_mchoose_window(), and mchoose().