download fl_ask.cxx
Language: C++
Copyright: Copyright 1998-2003 by Bill Spitzak and others.
LOC: 183
Project Info
Fast Light Tool Kit(fltk)
Server: SourceForge
Type: cvs
...Forge\f\fltk\fltk\fltk\src\
   allfiles.xbm
   ARRAY.h
   browser_minus.xbm
   browser_plus.xbm
   cmap.cxx
   CycleButton.cxx
   d1.xbm
   d1_mask.xbm
   dlload_osx.cxx
   dump_compose.c
   ew.xbm
   ew_mask.xbm
   fastarrow.h
   filename_absolute.cxx
   filename_expand.cxx
   filename_ext.cxx
   filename_isdir.cxx
   filename_list.cxx
   filename_match.cxx
   filename_setext.cxx
   Fl.cxx
   Fl_abort.cxx
   Fl_add_idle.cxx
   Fl_Adjuster.cxx
   Fl_Align_Group.cxx
   fl_arc.cxx
   fl_arci.cxx
   Fl_arg.cxx
   fl_ask.cxx
   Fl_Bar.cxx
   Fl_Bitmap.cxx
   fl_bmp.cxx
   Fl_Box.cxx
   Fl_Boxtype.cxx
   Fl_Browser.cxx
   Fl_Browser_load.cxx
   Fl_Button.cxx
   fl_call_main.c
   Fl_Check_Button.cxx
   Fl_Choice.cxx
   fl_clip.cxx
   Fl_Clock.cxx
   fl_cmap.h
   fl_color.cxx
   Fl_Color_Chooser.cxx
   fl_color_mac.cxx
   fl_color_win32.cxx
   fl_color_x.cxx
   Fl_compose.cxx
   fl_cursor.cxx
   fl_curve.cxx
   Fl_Dial.cxx
   fl_diamond_box.cxx
   Fl_display.cxx
   fl_dnd.cxx
   fl_dnd_mac.cxx
   fl_dnd_win32.cxx
   fl_dnd_x.cxx
   fl_draw.cxx
   fl_draw_image.cxx
   fl_draw_image_mac.cxx
   fl_draw_image_win32.cxx
   fl_draw_image_x.cxx
   fl_draw_pixmap.cxx
   fl_engraved_label.cxx
   fl_file_chooser.cxx
   Fl_FileBrowser.cxx
   Fl_FileChooser.cxx
   Fl_FileChooser.fl
   Fl_FileChooser2.cxx
   Fl_FileIcon.cxx
   Fl_FileIcon2.cxx
   Fl_FileInput.cxx
   Fl_Float_Input.cxx
   fl_font.cxx
   fl_font_mac.cxx
   fl_font_win32.cxx
   fl_font_x.cxx
   fl_font_xft.cxx
   Fl_get_key.cxx
   Fl_get_key_mac.cxx
   Fl_get_key_win32.cxx
   fl_gif.cxx
   fl_glyph.cxx
   Fl_Group.cxx
   Fl_Help_Dialog.cxx
   Fl_Help_View.cxx
   Fl_Highlight_Button.cxx
   Fl_Image.cxx
   Fl_Input.cxx
   Fl_Input_Browser.cxx
   Fl_Item.cxx
   Fl_key_name.cxx
   fl_labeltype.cxx
   Fl_Light_Button.cxx
   fl_list_fonts.cxx
   fl_list_fonts_mac.cxx
   fl_list_fonts_win32.cxx
   fl_list_fonts_x.cxx
   fl_load_plugin.cxx
   Fl_lock.cxx
   Fl_mac.cxx
   Fl_Menu.cxx
   Fl_Menu_.cxx
   Fl_Menu_add.cxx
   Fl_Menu_Bar.cxx
   Fl_Menu_Button.cxx
   Fl_Menu_global.cxx
   Fl_Menu_Item.cxx
   Fl_Menu_Window.cxx
   Fl_Multi_Image.cxx
   Fl_Numeric_Input.cxx
   Fl_Output.cxx
   fl_oval_box.cxx
   fl_overlay.cxx
   fl_overlay_visual.cxx
   Fl_own_colormap.cxx
   Fl_Pack.cxx
   Fl_Pixmap.cxx
   fl_plastic_box.cxx
   Fl_ProgressBar.cxx
   Fl_Radio_Button.cxx
   fl_rect.cxx
   Fl_Repeat_Button.cxx
   Fl_Return_Button.cxx
   fl_rgb.cxx
   Fl_RGB_Image.cxx
   Fl_Roller.cxx
   fl_round_box.cxx
   fl_rounded_box.cxx
   Fl_Scroll.cxx
   fl_scroll_area.cxx
   Fl_Scrollbar.cxx
   fl_set_fonts_mac.cxx
   fl_shadow_box.cxx
   Fl_Shaped_Window.cxx
   Fl_Shared_Image.cxx
   fl_show_colormap.cxx
   Fl_Single_Window.cxx
   Fl_Slider.cxx
   Fl_String_List.cxx
   Fl_Style.cxx
   Fl_Style_Set.cxx
   fl_symbols.cxx
   Fl_Tabs.cxx
   Fl_Text_Buffer.cxx
   Fl_Text_Display.cxx
   Fl_Text_Editor.cxx
   Fl_Tile.cxx
   Fl_Tiled_Image.cxx
   Fl_Tooltip.cxx
   Fl_Valuator.cxx
   Fl_Value_Input.cxx
   Fl_Value_Slider.cxx
   fl_vertex.cxx
   Fl_visual.cxx
   Fl_Widget.cxx
   Fl_win32.cxx
   Fl_Window.cxx
   Fl_Window_fullscreen.cxx
   Fl_Window_hotspot.cxx
   Fl_Window_iconize.cxx
   Fl_x.cxx
   Fl_XColor.h
   fl_xpm.cxx
   fltk_theme.cxx
   fltk_theme_win32.cxx
   fltk_theme_x.cxx
   IFont.h
   mediumarrow.h
   new.xbm
   ns.xbm
   ns_mask.xbm
   pktdef.h
   scandir.c
   scandir_win32.c
   shortcuts.cxx
   slowarrow.h
   string.c
   up.xbm
   utf.c
   ValueOutput.cxx
   vsnprintf.c
   wintab.h
   wintabx.h
   XColorMap.h
   xutf8.cxx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//
// "$Id: fl_ask.cxx,v 1.41 2005/01/24 08:07:52 spitzak Exp $"
//
// Copyright 1998-2003 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "fltk-bugs@fltk.org".
//

// Implementation of message, ask, choice, input
// The three-message show_x functions are for forms compatibility
// mostly.  In most cases it is easier to get a multi-line message
// by putting newlines in the message.

#include <fltk/draw.h>
#include <fltk/ask.h>
#include <fltk/Button.h>
#include <fltk/ReturnButton.h>
#include <fltk/Window.h>
#include <fltk/Input.h>
#include <fltk/SecretInput.h>
#include <fltk/string.h>

using namespace fltk;

/*! \addtogroup dialogs

  FLTK provides a number of functions that create a popup window and
  Window::exec() it. These functions return when the user OK's or
  Cancels the window, returning the value the user chose.

  Currently these are all built using normal fltk widgets. In theory
  these should be services provided by the operating system or desktop
  environment, but so far no non-ugly scheme has been developed for
  that. Unfortunatly the space for these dialogs can often end up being
  the majority of an FLTK program's size.

*/

static void m_revert(Style* s) {
  s->box_ = NO_BOX;
}
static NamedStyle m_style("Message", m_revert, &message_style);
/*! This Style is used for the label area for all the popup windows.
  You can change the textfont() or textsize() to make them print
  differently.
*/
NamedStyle* fltk::message_style = &m_style;

static void i_revert(Style* s) {
  s->box_ = THIN_UP_BOX;
  s->labelfont_ = TIMES_BOLD;
  s->labelsize_ = 34;
  s->color_ = WHITE;
  s->textcolor_ = s->labelcolor_ = BLUE;
}
static NamedStyle i_style("Icon", i_revert, &fltk::icon_style);
/*! This Style is used for the 50x50 icon area on the left of all
  the popup windows. You can change the colors or font used here.
*/
NamedStyle* fltk::icon_style = &i_style;

static int button_number;
static void set_button_number(Widget* w, long a) {
  button_number = a;
  w->window()->hide();
}

#define ICON_W 50
#define ICON_H 50
#define BORDER_W 10
#define BORDER_H 10
#define INPUT_W 270
#define BUTTON_W 75
#define BUTTON_H 21

static Input *textfield;

// In this call the buttons are in backwards order from right to left,
// this is because "no" (0) is on the right.
static int innards(
  const char* iconlabel,
  const char *istr, int itype,
  const char* fmt, va_list ap,
  const char *b0,
  const char *b1,
  const char *b2)
{
  Group* saved_current_group = Group::current();
  load_theme();
  Window window(3*BORDER_W+ICON_W+INPUT_W, 3*BORDER_H+ICON_H+BUTTON_H);
  window.begin();

  // This keeps the icon from resizing.
  Group ig(BORDER_W, BORDER_H, ICON_W, ICON_H);
  ig.begin();
  Widget icon(0, 0, ICON_W, ICON_H);
  icon.style(icon_style);
  icon.label(iconlabel);
  ig.end();

  Widget message(2*BORDER_W+ICON_W, 0, INPUT_W, 2*BORDER_H+ICON_H);
  message.set_flag(ALIGN_LEFT|ALIGN_INSIDE|ALIGN_WRAP);
  message.style(message_style);

  if (istr) {
    if (textfield)
      window.add(textfield);
    else
      textfield = new Input(2*BORDER_W+ICON_W, 0, INPUT_W, 0);
    textfield->h(int(textfield->textsize())+10);
    textfield->y(BORDER_H+ICON_H-textfield->h());
    textfield->w(INPUT_W);
    message.h(textfield->y());
    textfield->type(itype);
    textfield->value(istr);
    window.set_focus(textfield);
  }

  window.resizable(message);
  window.resize_align(ALIGN_RIGHT);
//  w->size_range(window.w(), window.h(), 0, window.h());

  char buffer[1024];
  if (!strcmp(fmt,"%s")) {
    message.label(va_arg(ap, const char*));
  } else if (!strchr(fmt, '%')) {
    message.label(fmt);
  } else {
    vsnprintf(buffer, 1024, fmt, ap);
    message.label(buffer);
  }

  window.end();
  window.layout();
  setfont(message.labelfont(), message.labelsize());
  int w = 800;
  int h = 0;
  measure(message.label(), w, h, message.flags());
  w+=6; h+=6;
  w -= message.w(); if (w < 0) w = 0;
  h -= message.h(); if (h < 0) h = 0;
  window.resize(window.x(),window.y(),window.w()+w, window.h()+h);
  window.layout();

  window.begin();

  const char* blabels[3];
  blabels[0] = b0;
  blabels[1] = b1;
  blabels[2] = b2;

  // Button with '*' is default, if none the left-most one is:
  int default_button = 0;
  int i;
  for (i = 2; i >= 0; i--) if (blabels[i]) {
    if (!default_button) default_button = i;
    if (blabels[i][0] == '*') {blabels[i]++; default_button = i;}
  }

  for (i = 3; i--;) if (blabels[i]) {
    Button* button;
    if (i == default_button) {
      button = new ReturnButton(
	window.w()-(BUTTON_W+BORDER_W)*(i+1),
	window.h()-(BORDER_H+BUTTON_H), BUTTON_W, BUTTON_H, blabels[i]);
      window.hotspot(button);
      if (!istr) window.set_focus(button);
    } else {
      button = new Button(
	window.w()-(BUTTON_W+BORDER_W)*(i+1),
	window.h()-(BORDER_H+BUTTON_H), BUTTON_W, BUTTON_H, blabels[i]);
    }
    button->callback(set_button_number, i);
  }

  window.end();
  button_number = 0;
  window.exec();
  if (istr)
    window.remove(textfield); // don't destroy it yet
  Group::current(saved_current_group);
  return button_number;
}

/*! You can change this string to convert fltk to a foreign language. */
const char* fltk::no = "No";
/*! You can change this string to convert fltk to a foreign language. */
const char* fltk::yes= "Yes";
/*! You can change this string to convert fltk to a foreign language. */
const char* fltk::ok = "OK";
/*! You can change this string to convert fltk to a foreign language. */
const char* fltk::cancel= "Cancel";

/*!
  \image html fl_message.gif
  Displays a printf-style message in a pop-up box with an "OK" button,
  waits for the user to hit the button. The message will wrap to fit
  the window, or may be many lines by putting '\\n' characters into
  it. The enter key is a shortcut for the OK button.
*/
void fltk::message(const char *fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  innards("i", 0, 0, fmt, ap, ok, 0, 0);
  va_end(ap);
}

/*!
  \image html fl_alert.gif
  Same as fltk::message() except for the "!" symbol. 
*/
void fltk::alert(const char *fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  innards("!", 0, 0, fmt, ap, ok, 0, 0);
  va_end(ap);
}

/*!
  \image html fl_ask.gif
  Displays a printf-style message in a pop-up box with an "Yes" and
  "No" button and waits for the user to hit a button. The return value
  is 1 if the user hits Yes, 0 if they pick No. The enter key is a
  shortcut for Yes and ESC is a shortcut for No.
*/
int fltk::ask(const char *fmt, ...) {
  va_list ap;
  va_start(ap, fmt);
  int r = innards("?", 0, 0, fmt, ap, no, yes, 0);
  va_end(ap);
  return r;
}

/*!
  \image html fl_choice.gif
  Shows the message with three buttons below it marked with the
  strings b0, b1, and b2. Returns 0, 1, or 2 depending on which button
  is hit. If one of the strings begins with the special character '*'
  then the associated button will be the default which is selected
  when the enter key is pressed. ESC is a shortcut for b2.
*/
int fltk::choice(const char*fmt,const char *b0,const char *b1,const char *b2,...){
  va_list ap;
  va_start(ap, b2);
  int r = innards("?", 0, 0, fmt, ap, b2, b1, b0);
  va_end(ap);
  return 2-r;
}

/*! Same as choice() except a "!" icon is used instead of a "?" */
int fltk::choice_alert(const char*fmt,const char *b0,const char *b1,const char *b2,...){
  va_list ap;
  va_start(ap, b2);
  int r = innards("!", 0, 0, fmt, ap, b2, b1, b0);
  va_end(ap);
  return 2-r;
}

static const char* input_innards(const char* fmt, va_list ap,
				 const char* defstr, uchar type) {
  int r = innards("?", defstr ? defstr : "", type,
		  fmt, ap, cancel, ok, 0);
  return r ? textfield->value() : 0;
}

/*!
  \image html fl_input.gif
  Pops up a window displaying a string, lets the user edit it, and
  return the new value. The cancel button returns NULL. The returned
  pointer is only valid until the next time fltk::input() is
  called. Due to back-compatability, the arguments to any printf
  commands in the label are after the default value.
*/
const char* fltk::input(const char *fmt, const char *defstr, ...) {
  va_list ap;
  va_start(ap, defstr);
  const char* r = input_innards(fmt, ap, defstr, Input::NORMAL);
  va_end(ap);
  return r;
}

/*!
  \image html fl_password.gif
  Same as fltk::input() except an fltk::SecretInput field is used. 
*/
const char *fltk::password(const char *fmt, const char *defstr, ...) {
  va_list ap;
  va_start(ap, defstr);
  const char* r = input_innards(fmt, ap, defstr, Input::SECRET);
  va_end(ap);
  return r;
}

//
// End of "$Id: fl_ask.cxx,v 1.41 2005/01/24 08:07:52 spitzak Exp $".
//

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us