PIPS
xv_query.c
Go to the documentation of this file.
1 /*
2 
3  $Id: xv_query.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 
31 #include <sys/time.h>
32 #include <sys/resource.h>
33 #include <xview/xview.h>
34 #include <xview/panel.h>
35 #include <xview/text.h>
36 
37 #include "xv_sizes.h"
38 
39 #include "genC.h"
40 #include "misc.h"
41 
42 #include "wpips.h"
43 
44 static Panel_item query_pad;
45 static Panel_item query_cancel_button;
46 
47 static char *query_help_topic;
48 static success (*apply_on_query)(char *);
49 
50 void
51 start_query(char * window_title,
52  char * query_title,
53  char * help_topic,
54  success (* ok_func)(char *),
55  void (* cancel_func)(Panel_item, Event *))
56 {
57  xv_set(query_frame, FRAME_LABEL, window_title, NULL);
58  /* PANEL_NOTIFY_PROC, cancel_query_notify, */
59 
60  if (cancel_func == NULL)
61  /* No cancel button requested: */
62  xv_set(query_cancel_button,
63  PANEL_INACTIVE, TRUE,
64  NULL);
65  else
66  xv_set(query_cancel_button, PANEL_NOTIFY_PROC, cancel_func,
67  PANEL_INACTIVE, FALSE,
68  NULL);
69 
70  xv_set(query_pad, PANEL_LABEL_STRING, query_title, NULL);
71 
72  xv_set(query_pad, PANEL_VALUE, "", NULL);
73 
74  query_help_topic = help_topic;
75 
76  apply_on_query = ok_func;
77 
79 
80  /* move the pointer to the center of the query window */
82 
83  /* Valide le focus sur l'entrĂ©e : */
84  /* J'ai l'impression que le code pre'ce'dent est pluto^t obsole`te... RK. */
85  /* Mais pourquoi cela ne marche pas ??? */
86  win_set_kbd_focus(query_frame, xv_get(query_panel, XV_XID));
87  /* xv_set(query_xwindow , WIN_SET_FOCUS, NULL); */
88  xv_set(query_panel, PANEL_CARET_ITEM, query_pad, NULL);
89 }
90 
91 void query_canvas_event_proc(window, event)
92 Xv_Window window;
93 Event *event;
94 {
95  debug_on("WPIPS_EVENT_DEBUG_LEVEL");
96  debug(2,"query_canvas_event_proc",
97  "Event_id %d, event_action %d\n",
98  event_id(event), event_action(event));
99  debug_off();
100  switch(event_id(event)) {
101  case LOC_WINENTER :
102  /* enter_window(window); */
103  break;
104  case '\r' :
105  /* ie. return key pressed */
106  if (event_is_up(event))
107  /* ie. key is released. It is necessary to use this event
108  because notice_prompt() (in prompt_user() (in
109  end_query_notify() )) also returns on up RETURN.
110  This can cause the notice to return immediately when it is
111  called on down RETURN.
112  There schould be another possibility: put a mask to ignore
113  key release events on the window which owns notice_prompt().
114  This was done in create_main_window() but seems without
115  effect.
116  */
117  end_query_notify(NULL, event);
118  break;
119  default : ;
120  }
121 }
122 
123 /* Pour debug seulement : */
124 void end_query_pad_notify(Panel_item item, Event *event)
125 {
126  debug_on("WPIPS_EVENT_DEBUG_LEVEL");
127  debug(2,"find_dead_code",
128  "end_query_pad_notify: Event_id %d, event_action %d\n",
129  event_id(event), event_action(event));
130  debug_off();
131 }
132 
133 
134 void end_query_notify(item, event)
135 Panel_item item;
136 Event *event;
137 {
138 
139  char *s = (char *) xv_get(query_pad, PANEL_VALUE);
140 
141  /* Dans le cas ou` on vient d'un retour charriot dans le texte : */
142 /* Cela ne peut bien entendu pas marcher... :-( */
143 /*
144  xv_set(xv_get(query_panel, PANEL_DEFAULT_ITEM, NULL),
145  PANEL_BUSY, FALSE,
146  NULL);
147 */
148  if (apply_on_query(s)) {
150  /* Remet le bouton OK a l'e'tat normal : */
151 /* xv_set(xv_get(query_panel, PANEL_DEFAULT_ITEM, NULL),
152  PANEL_BUSY, FALSE,
153  NULL);
154 */
155  }
156 }
157 
158 void help_query_notify(item, event)
159 Panel_item item;
160 Event *event;
161 {
163 }
164 
165 /* Ne fait rien d'autre que de fermer la fene^tre... */
166 void
167 cancel_query_notify(Panel_item item,
168  Event * event)
169 {
171 }
172 
173 
174 /* Cancel clear the string value and return: */
175 void
177  Event * event)
178 {
179  xv_set(query_pad, PANEL_VALUE, "", NULL);
181  /* Just return the "": */
182  xv_window_return((Xv_opaque) xv_get(query_pad, PANEL_VALUE));
183 }
184 
185 
186 success
187 end_user_request_notify(char * the_answer)
188 {
190  xv_window_return((Xv_opaque) the_answer);
191  /* In fact, the function above never return... */
192  return TRUE;
193 }
194 
195 
196 string
197 wpips_user_request(char * a_printf_format,
198  va_list args)
199 {
200  char * the_answer;
201 
202  static char message_buffer[SMALL_BUFFER_LENGTH];
203 
204  (void) vsprintf(message_buffer, a_printf_format, args);
205 
206  start_query("User Query",
207  message_buffer,
208  "UserQuery",
211 
212  user_log("User Request...\n");
213 
214  /* Loop on the Query window: */
215  the_answer = (string) xv_window_loop(query_frame);
216 
217  /* Log the answer for possible rerun through tpips: */
218  user_log("%s\n\"%s\"\nEnd User Request\n",
219  message_buffer, the_answer);
220 
221  /* returns a newly allocated string...
222  */
223  if (the_answer && !string_undefined_p(the_answer))
224  the_answer = strdup(the_answer);
225 
226  return the_answer;
227 }
228 
229 
231 {
232  query_panel = xv_create(query_frame, PANEL, NULL);
233 
234 /* Semble ne servir a` rien. RK, 9/11/93. */
235  xv_set(canvas_paint_window(query_panel),
236  WIN_CONSUME_EVENT, LOC_WINENTER, NULL,
237 /* WIN_IGNORE_X_EVENT_MASK, KeyReleaseMask, */
238  WIN_EVENT_PROC, query_canvas_event_proc,
239  NULL);
240 
241 
242  query_pad = xv_create(query_panel, PANEL_TEXT,
243  PANEL_VALUE_DISPLAY_LENGTH, 20,
244  PANEL_VALUE_STORED_LENGTH, 128,
245  PANEL_NOTIFY_PROC, end_query_notify,
246  NULL);
247 
248  xv_set(query_panel, PANEL_DEFAULT_ITEM,
249  xv_create(query_panel, PANEL_BUTTON,
250  PANEL_LABEL_STRING, " OK ",
251  XV_Y, xv_row(query_panel, 2),
252  XV_X, QUERY_WIDTH/2-100,
253  PANEL_NOTIFY_PROC, end_query_notify,
254  NULL),NULL);
255 
256  (void) xv_create(query_panel, PANEL_BUTTON,
257  PANEL_LABEL_STRING, "Help",
258  PANEL_NOTIFY_PROC, help_query_notify,
259  NULL);
260 
261  query_cancel_button = xv_create(query_panel, PANEL_BUTTON,
262  PANEL_LABEL_STRING, "Cancel",
263  NULL);
264 }
void user_log(const char *format,...)
Definition: message.c:234
#define SMALL_BUFFER_LENGTH
Definition: gpips-local.h:24
bool success
Definition: gpips-local.h:59
GtkWidget * query_frame
Definition: gpips-local.h:42
void display_help(char *topic)
Definition: gtk_help.c:50
#define QUERY_WIDTH
Definition: gtk_sizes.h:50
gint hide_window(GtkWidget *window, GdkEvent *ev __attribute__((unused)), gpointer data __attribute__((unused)))
Definition: gtk_utils.c:89
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
char * string
STRING.
Definition: newgen_types.h:39
#define string_undefined_p(s)
Definition: newgen_types.h:41
char * strdup()
Panel query_panel
Definition: wpips-local.h:48
static char * query_help_topic
Definition: xv_query.c:47
void query_canvas_event_proc(Xv_Window window, Event *event)
Definition: xv_query.c:91
void create_query_window()
Definition: xv_query.c:230
void cancel_user_request_notify(Panel_item item, Event *event)
Cancel clear the string value and return:
Definition: xv_query.c:176
static Panel_item query_cancel_button
Definition: xv_query.c:45
void end_query_notify(Panel_item item, Event *event)
Definition: xv_query.c:134
static success(* apply_on_query)(char *)
Definition: xv_query.c:48
static Panel_item query_pad
Definition: xv_query.c:44
success end_user_request_notify(char *the_answer)
Definition: xv_query.c:187
void start_query(char *window_title, char *query_title, char *help_topic, success(*ok_func)(char *), void(*cancel_func)(Panel_item, Event *))
Definition: xv_query.c:51
void cancel_query_notify(Panel_item item, Event *event)
Ne fait rien d'autre que de fermer la fene^tre...
Definition: xv_query.c:167
string wpips_user_request(char *a_printf_format, va_list args)
Definition: xv_query.c:197
void end_query_pad_notify(Panel_item item, Event *event)
Pour debug seulement :
Definition: xv_query.c:124
void help_query_notify(Panel_item item, Event *event)
Definition: xv_query.c:158
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