~ubuntu-branches/ubuntu/quantal/glbsp/quantal

« back to all changes in this revision

Viewing changes to nodeview/dialog.cc

  • Committer: Bazaar Package Importer
  • Author(s): Darren Salt
  • Date: 2008-01-30 13:33:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080130133349-kgojg33vyiu8xbvp
Tags: 2.24-1
* New upstream release.
* Bumped the lib soname and the library package name due to one silly
  little binary incompatibility caused by changes in an exported struct.
  (Safe; nothing else currently in the archive has ever used libglbsp2.)
* Removed my patches since they're all applied upstream.
* Updated the list of documentation files.
* Build-time changes:
  - Switched from dh_movefiles to dh_install.
  - Updated my makefile to cope with upstream changes.
  - Corrected for debian-rules-ignores-make-clean-error.
  - Corrected for substvar-source-version-is-deprecated.
  - Link libglbsp, rather than glbsp, with libm and libz.
* Fixed shlibdeps. (Closes: #460387)
* Bumped standards version to 3.7.3 (no other changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------------------------
 
2
//  DIALOG : Pop-up dialog boxes
 
3
//------------------------------------------------------------------------
 
4
//
 
5
//  GL-Node Viewer (C) 2004-2007 Andrew Apted
 
6
//
 
7
//  This program is free software; you can redistribute it and/or
 
8
//  modify it under the terms of the GNU General Public License
 
9
//  as published by the Free Software Foundation; either version 2
 
10
//  of the License, or (at your option) any later version.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//------------------------------------------------------------------------
 
18
 
 
19
// this includes everything we need
 
20
#include "defs.h"
 
21
 
 
22
 
 
23
static Fl_Window *cur_diag;
 
24
static int cur_diag_result;
 
25
static bool cur_diag_done;
 
26
static const char *cur_diag_guess_name;
 
27
 
 
28
static int pref_dialog_x = -1;
 
29
static int pref_dialog_y = -1;
 
30
 
 
31
 
 
32
static void dialog_closed_CB(Fl_Widget *w, void *data)
 
33
{
 
34
  cur_diag_result = -1;
 
35
  cur_diag_done = true;
 
36
}
 
37
 
 
38
static void dialog_left_button_CB(Fl_Widget *w, void *data)
 
39
{
 
40
  cur_diag_result = 0;
 
41
  cur_diag_done = true;
 
42
}
 
43
 
 
44
static void dialog_middle_button_CB(Fl_Widget *w, void *data)
 
45
{
 
46
  cur_diag_result = 1;
 
47
  cur_diag_done = true;
 
48
}
 
49
 
 
50
static void dialog_right_button_CB(Fl_Widget *w, void *data)
 
51
{
 
52
  cur_diag_result = 2;
 
53
  cur_diag_done = true;
 
54
}
 
55
 
 
56
static void dialog_file_browse_CB(Fl_Widget *w, void *data)
 
57
{
 
58
  Fl_Input *inp_box = (Fl_Input *) data;
 
59
  const char *new_name; 
 
60
 
 
61
  new_name = fl_file_chooser("Select the log file", "*.log",
 
62
      inp_box->value());
 
63
 
 
64
  // cancelled ?
 
65
  if (! new_name)
 
66
    return;
 
67
 
 
68
  inp_box->value(new_name);
 
69
}
 
70
 
 
71
static void dialog_file_guess_CB(Fl_Widget *w, void *data)
 
72
{
 
73
  Fl_Input *inp_box = (Fl_Input *) data;
 
74
 
 
75
  if (cur_diag_guess_name)
 
76
  {
 
77
    inp_box->value(cur_diag_guess_name);
 
78
  }
 
79
}
 
80
 
 
81
 
 
82
//------------------------------------------------------------------------
 
83
 
 
84
static void DialogRun()
 
85
{
 
86
  cur_diag->set_modal();
 
87
  cur_diag->show();
 
88
 
 
89
  // read initial pos (same logic as in Guix_MainWin)
 
90
  WindowSmallDelay();
 
91
  int init_x = cur_diag->x(); 
 
92
  int init_y = cur_diag->y();
 
93
 
 
94
  // run the GUI and let user make their choice
 
95
  while (! cur_diag_done)
 
96
  {
 
97
    Fl::wait();
 
98
  }
 
99
 
 
100
  // check if the user moved/resized the window
 
101
  if (cur_diag->x() != init_x || cur_diag->y() != init_y)
 
102
  {
 
103
    pref_dialog_x = cur_diag->x();
 
104
    pref_dialog_y = cur_diag->y();
 
105
  }
 
106
}
 
107
 
 
108
 
 
109
//
 
110
// DialogShowAndGetChoice
 
111
//
 
112
// The `pic' parameter is the picture to show on the left, or NULL for
 
113
// none.  The message can contain newlines.  The right/middle/left
 
114
// parameters allow up to three buttons.
 
115
//
 
116
// Returns the button number pressed (0 for right, 1 for middle, 2 for
 
117
// left) or -1 if escape was pressed or window manually closed.
 
118
// 
 
119
int DialogShowAndGetChoice(const char *title, Fl_Pixmap *pic, 
 
120
    const char *message, const char *left, // = "OK", 
 
121
    const char *middle, // = NULL,
 
122
    const char *right)  // = NULL)
 
123
{
 
124
  cur_diag_result = -1;
 
125
  cur_diag_done = false;
 
126
 
 
127
  int but_width = right ? (120*3) : middle ? (120*2) : (120*1);
 
128
 
 
129
  // determine required size
 
130
  int width = 120 * 3;
 
131
  int height;
 
132
 
 
133
  // set current font for fl_measure()
 
134
  fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
 
135
 
 
136
  fl_measure(message, width, height);
 
137
 
 
138
  if (width < but_width)
 
139
    width = but_width;
 
140
 
 
141
  if (height < 16)
 
142
    height = 16;
 
143
 
 
144
  width  += 60 + 20 + 16;  // 16 extra, just in case
 
145
  height += 10 + 40 + 16;  // 
 
146
 
 
147
  // create window
 
148
  cur_diag = new Fl_Window(0, 0, width, height, title);
 
149
  cur_diag->end();
 
150
  cur_diag->size_range(width, height, width, height);
 
151
  cur_diag->callback((Fl_Callback *) dialog_closed_CB);
 
152
 
 
153
  if (pref_dialog_x >= 0)
 
154
    cur_diag->position(pref_dialog_x, pref_dialog_y);
 
155
 
 
156
  // set the resizable
 
157
  Fl_Box *box = new Fl_Box(60, 0, width - 3*120, height);
 
158
  cur_diag->add(box);
 
159
  cur_diag->resizable(box); 
 
160
 
 
161
  // create the image, if any
 
162
  if (pic)
 
163
  {
 
164
    box = new Fl_Box(5, 10, 50, 50);
 
165
    pic->label(box);
 
166
    cur_diag->add(box);
 
167
  }
 
168
 
 
169
  // create the message area
 
170
  box = new Fl_Box(60, 10, width-60 - 20, height-10 - 40, message);
 
171
  box->align(FL_ALIGN_LEFT | FL_ALIGN_TOP | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
 
172
  cur_diag->add(box);
 
173
 
 
174
  // create buttons
 
175
  Fl_Button *button;
 
176
 
 
177
  int CX = width - 120;
 
178
  int CY = height - 40;
 
179
 
 
180
  if (right)
 
181
  {
 
182
    button = new Fl_Return_Button(CX, CY, 104, 30, right);
 
183
    button->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
 
184
    button->callback((Fl_Callback *) dialog_right_button_CB);
 
185
    cur_diag->add(button);
 
186
 
 
187
    CX -= 120;
 
188
  }
 
189
 
 
190
  if (middle)
 
191
  {
 
192
    button = new Fl_Button(CX, CY, 104, 30, middle);
 
193
    button->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
 
194
    button->callback((Fl_Callback *) dialog_middle_button_CB);
 
195
    cur_diag->add(button);
 
196
 
 
197
    CX -= 120;
 
198
  }
 
199
 
 
200
  if (left)
 
201
  {
 
202
    button = new Fl_Button(CX, CY, 104, 30, left);
 
203
    button->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
 
204
    button->callback((Fl_Callback *) dialog_left_button_CB);
 
205
    cur_diag->add(button);
 
206
 
 
207
    CX -= 120;
 
208
  }
 
209
 
 
210
  // show time !
 
211
  DialogRun();
 
212
 
 
213
  // delete window (automatically deletes child widgets)
 
214
  delete cur_diag;
 
215
  cur_diag = NULL;
 
216
 
 
217
  return cur_diag_result;
 
218
}
 
219
 
 
220
 
 
221
//
 
222
// DialogQueryFilename
 
223
// 
 
224
// Shows the current filename (name_ptr) in an input box, and provides
 
225
// a browse button to choose a new filename, and an optional button to
 
226
// guess the new filename (if `guess_name' is NULL, then the button is
 
227
// disabled).
 
228
//
 
229
// This routine does NOT ensure that the filename is valid (or any
 
230
// other requirement, e.g. has a certain extension).
 
231
// 
 
232
// Returns 0 if "OK" was pressed, 1 if "Cancel" was pressed, or -1 if
 
233
// escape was pressed or the window was manually closed.
 
234
// 
 
235
int DialogQueryFilename(const char *message,
 
236
        const char ** name_ptr, const char *guess_name)
 
237
{
 
238
  cur_diag_result = -1;
 
239
  cur_diag_done = false;
 
240
  cur_diag_guess_name = guess_name;
 
241
 
 
242
  // determine required size
 
243
  int width = 400;
 
244
  int height;
 
245
 
 
246
  // set current font for fl_measure()
 
247
  fl_font(FL_HELVETICA, FL_NORMAL_SIZE);
 
248
 
 
249
  fl_measure(message, width, height);
 
250
 
 
251
  if (width < 400)
 
252
    width = 400;
 
253
 
 
254
  if (height < 16)
 
255
    height = 16;
 
256
 
 
257
  width  += 60 + 20 + 16;  // 16 extra, just in case
 
258
  height += 60 + 50 + 16;  // 
 
259
 
 
260
  // create window
 
261
  cur_diag = new Fl_Window(0, 0, width, height, PROG_NAME " Query");
 
262
  cur_diag->end();
 
263
  cur_diag->size_range(width, height, width, height);
 
264
  cur_diag->callback((Fl_Callback *) dialog_closed_CB);
 
265
 
 
266
  if (pref_dialog_x >= 0)
 
267
    cur_diag->position(pref_dialog_x, pref_dialog_y);
 
268
 
 
269
  // set the resizable
 
270
  Fl_Box *box = new Fl_Box(0, height-1, width, 1);
 
271
  cur_diag->add(box);
 
272
  cur_diag->resizable(box); 
 
273
 
 
274
  // create the message area
 
275
  box = new Fl_Box(14, 10, width-20 - 20, height-10 - 100, message);
 
276
  box->align(FL_ALIGN_LEFT | FL_ALIGN_TOP | FL_ALIGN_INSIDE | FL_ALIGN_WRAP);
 
277
  cur_diag->add(box);
 
278
 
 
279
  // create buttons
 
280
 
 
281
  int CX = width - 120;
 
282
  int CY = height - 50;
 
283
 
 
284
  Fl_Button *b_ok;
 
285
  Fl_Button *b_cancel;
 
286
 
 
287
  b_cancel = new Fl_Button(CX, CY, 104, 30, "Cancel");
 
288
  b_cancel->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
 
289
  b_cancel->callback((Fl_Callback *) dialog_middle_button_CB);
 
290
  cur_diag->add(b_cancel);
 
291
 
 
292
  CX -= 120;
 
293
 
 
294
  b_ok = new Fl_Return_Button(CX, CY, 104, 30, "OK");
 
295
  b_ok->align(FL_ALIGN_INSIDE | FL_ALIGN_CLIP);
 
296
  b_ok->callback((Fl_Callback *) dialog_left_button_CB);
 
297
  cur_diag->add(b_ok);
 
298
 
 
299
  // create input box
 
300
  Fl_Input *inp_box;
 
301
 
 
302
  CX = width - 120;
 
303
  CY = height - 100;
 
304
 
 
305
  inp_box = new Fl_Input(20, CY, CX - 20 - 90, 26);
 
306
  inp_box->value(*name_ptr);
 
307
  cur_diag->add(inp_box);
 
308
 
 
309
  // create the browse and guess button
 
310
  Fl_Button *b_browse;
 
311
  Fl_Button *b_guess;
 
312
 
 
313
  b_guess = new Fl_Button(CX, CY, 70, 26, "Guess");
 
314
  b_guess->align(FL_ALIGN_INSIDE);
 
315
  b_guess->callback((Fl_Callback *) dialog_file_guess_CB, inp_box);
 
316
  cur_diag->add(b_guess);
 
317
 
 
318
  CX -= 85;
 
319
 
 
320
  b_browse = new Fl_Button(CX, CY, 80, b_guess->h(), "Browse");
 
321
  b_browse->align(FL_ALIGN_INSIDE);
 
322
  b_browse->callback((Fl_Callback *) dialog_file_browse_CB, inp_box);
 
323
  cur_diag->add(b_browse);
 
324
 
 
325
  // show time !
 
326
  DialogRun();
 
327
 
 
328
  if (cur_diag_result == 0)
 
329
  {
 
330
    UtilFree((void *) *name_ptr);
 
331
 
 
332
    *name_ptr = UtilStrDup(inp_box->value());
 
333
  }
 
334
 
 
335
  // delete window (automatically deletes child widgets)
 
336
  delete cur_diag;
 
337
  cur_diag = NULL;
 
338
 
 
339
  return cur_diag_result;
 
340
}
 
341
 
 
342
 
 
343
//
 
344
// GUI_FatalError
 
345
//
 
346
// Terminates the program reporting an error.
 
347
//
 
348
void GUI_FatalError(const char *str, ...)
 
349
{
 
350
  char buffer[2048];
 
351
  char main_err[2048];
 
352
  char *m_ptr;
 
353
 
 
354
  // create message
 
355
  va_list args;
 
356
 
 
357
  va_start(args, str);
 
358
  vsprintf(main_err, str, args);
 
359
  va_end(args);
 
360
 
 
361
  // remove leading and trailing whitespace
 
362
  int len = strlen(main_err);
 
363
 
 
364
  for (; len > 0 && isspace(main_err[len-1]); len--)
 
365
  {
 
366
    main_err[len-1] = 0;
 
367
  }
 
368
 
 
369
  for (m_ptr = main_err; isspace(*m_ptr); m_ptr++)
 
370
  { /* nothing else needed */ }
 
371
 
 
372
  sprintf(buffer,
 
373
      "The following unexpected error occurred:\n"
 
374
      "\n"
 
375
      "      %s\n"
 
376
      "\n"
 
377
      PROG_NAME " will now shut down.",
 
378
      m_ptr);
 
379
 
 
380
  DialogShowAndGetChoice(PROG_NAME " Fatal Error", 0, buffer);
 
381
 
 
382
  // Q/ save cookies ?  
 
383
  // A/ no, we save them before each build begins.
 
384
 
 
385
  exit(5);
 
386
}
 
387