1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Standard dialog functions for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// Copyright 1998-2005 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
2005-03-25 19:11:07 +03:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// Implementation of fl_message, fl_ask, fl_choice, fl_input
|
|
|
|
// The three-message fl_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.
|
|
|
|
|
1998-11-12 17:16:57 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2001-11-25 19:38:11 +03:00
|
|
|
#include "flstring.h"
|
1998-11-12 17:16:57 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
|
|
|
|
#include <FL/fl_ask.H>
|
|
|
|
|
|
|
|
#include <FL/Fl_Box.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Return_Button.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/Fl_Secret_Input.H>
|
1999-11-18 19:33:01 +03:00
|
|
|
#include <FL/x.H>
|
2002-03-23 18:35:08 +03:00
|
|
|
#include <FL/fl_draw.H>
|
1999-11-18 19:33:01 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
static Fl_Window *message_form;
|
1998-11-05 19:04:53 +03:00
|
|
|
static Fl_Box *message;
|
1998-10-06 22:21:25 +04:00
|
|
|
static Fl_Box *icon;
|
|
|
|
static Fl_Button *button[3];
|
|
|
|
static Fl_Input *input;
|
2000-08-20 08:35:17 +04:00
|
|
|
static const char *iconlabel = "?";
|
2002-03-23 18:35:08 +03:00
|
|
|
Fl_Font fl_message_font_ = FL_HELVETICA;
|
2000-04-12 08:32:05 +04:00
|
|
|
uchar fl_message_size_ = 14;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
static Fl_Window *makeform() {
|
2000-03-05 09:51:07 +03:00
|
|
|
if (message_form) {
|
2000-04-12 08:32:05 +04:00
|
|
|
message_form->size(410,103);
|
2000-03-05 09:51:07 +03:00
|
|
|
return message_form;
|
|
|
|
}
|
2005-03-21 14:38:52 +03:00
|
|
|
// make sure that the dialog does not become the child of some
|
|
|
|
// current group
|
|
|
|
Fl_Group *previously_current_group = Fl_Group::current();
|
|
|
|
Fl_Group::current(0);
|
|
|
|
// create a new top level window
|
2002-03-23 18:35:08 +03:00
|
|
|
Fl_Window *w = message_form = new Fl_Window(410,103,"");
|
1998-10-06 22:21:25 +04:00
|
|
|
// w->clear_border();
|
|
|
|
// w->box(FL_UP_BOX);
|
1998-11-05 19:04:53 +03:00
|
|
|
(message = new Fl_Box(60, 25, 340, 20))
|
1998-10-06 22:21:25 +04:00
|
|
|
->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
|
2000-04-12 08:32:05 +04:00
|
|
|
(input = new Fl_Input(60, 37, 340, 23))->hide();
|
1998-10-06 22:21:25 +04:00
|
|
|
{Fl_Box* o = icon = new Fl_Box(10, 10, 50, 50);
|
|
|
|
o->box(FL_THIN_UP_BOX);
|
|
|
|
o->labelfont(FL_TIMES_BOLD);
|
|
|
|
o->labelsize(34);
|
|
|
|
o->color(FL_WHITE);
|
|
|
|
o->labelcolor(FL_BLUE);
|
|
|
|
}
|
2002-08-30 20:58:16 +04:00
|
|
|
button[0] = new Fl_Button(310, 70, 90, 23);
|
|
|
|
button[0]->shortcut("^[");
|
2002-03-23 18:35:08 +03:00
|
|
|
button[0]->align(FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
|
2000-04-12 08:32:05 +04:00
|
|
|
button[1] = new Fl_Return_Button(210, 70, 90, 23);
|
2002-03-23 18:35:08 +03:00
|
|
|
button[1]->align(FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
|
2000-04-12 08:32:05 +04:00
|
|
|
button[2] = new Fl_Button(110, 70, 90, 23);
|
2002-03-23 18:35:08 +03:00
|
|
|
button[2]->align(FL_ALIGN_INSIDE|FL_ALIGN_WRAP);
|
2000-04-12 08:32:05 +04:00
|
|
|
w->resizable(new Fl_Box(60,10,110-60,27));
|
1998-10-06 22:21:25 +04:00
|
|
|
w->end();
|
|
|
|
w->set_modal();
|
2005-03-21 14:38:52 +03:00
|
|
|
Fl_Group::current(previously_current_group);
|
1998-10-06 22:21:25 +04:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2002-03-23 18:35:08 +03:00
|
|
|
/*
|
|
|
|
* 'resizeform()' - Resize the form and widgets so that they hold everything
|
|
|
|
* that is asked of them...
|
|
|
|
*/
|
|
|
|
|
|
|
|
void resizeform() {
|
|
|
|
int i;
|
|
|
|
int message_w, message_h;
|
|
|
|
int icon_size;
|
|
|
|
int button_w[3], button_h[3];
|
|
|
|
int x, w, h, max_w, max_h;
|
|
|
|
|
|
|
|
fl_font(fl_message_font_, fl_message_size_);
|
|
|
|
message_w = message_h = 0;
|
|
|
|
fl_measure(message->label(), message_w, message_h);
|
|
|
|
|
|
|
|
message_w += 10;
|
|
|
|
message_h += 10;
|
2002-04-02 23:30:52 +04:00
|
|
|
if (message_w < 340)
|
|
|
|
message_w = 340;
|
2002-03-23 18:35:08 +03:00
|
|
|
if (message_h < 30)
|
|
|
|
message_h = 30;
|
|
|
|
|
|
|
|
fl_font(button[0]->labelfont(), button[0]->labelsize());
|
2002-06-06 18:22:05 +04:00
|
|
|
|
|
|
|
memset(button_w, 0, sizeof(button_w));
|
|
|
|
memset(button_h, 0, sizeof(button_h));
|
|
|
|
|
2002-03-23 18:35:08 +03:00
|
|
|
for (max_h = 25, i = 0; i < 3; i ++)
|
|
|
|
if (button[i]->visible())
|
|
|
|
{
|
|
|
|
fl_measure(button[i]->label(), button_w[i], button_h[i]);
|
|
|
|
|
|
|
|
if (i == 1)
|
|
|
|
button_w[1] += 20;
|
|
|
|
|
|
|
|
button_w[i] += 30;
|
|
|
|
button_h[i] += 10;
|
|
|
|
|
|
|
|
if (button_h[i] > max_h)
|
|
|
|
max_h = button_h[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->visible()) icon_size = message_h + 25;
|
|
|
|
else icon_size = message_h;
|
|
|
|
|
|
|
|
max_w = message_w + 10 + icon_size;
|
|
|
|
w = button_w[0] + button_w[1] + button_w[2] - 10;
|
|
|
|
|
|
|
|
if (w > max_w)
|
|
|
|
max_w = w;
|
|
|
|
|
|
|
|
message_w = max_w - 10 - icon_size;
|
|
|
|
|
|
|
|
w = max_w + 20;
|
|
|
|
h = max_h + 30 + icon_size;
|
|
|
|
|
|
|
|
message_form->size(w, h);
|
|
|
|
message_form->size_range(w, h, w, h);
|
|
|
|
|
|
|
|
message->resize(20 + icon_size, 10, message_w, message_h);
|
|
|
|
icon->resize(10, 10, icon_size, icon_size);
|
2002-11-19 19:37:36 +03:00
|
|
|
icon->labelsize((uchar)(icon_size - 10));
|
2002-03-23 18:35:08 +03:00
|
|
|
input->resize(20 + icon_size, 10 + message_h, message_w, 25);
|
|
|
|
|
2002-08-30 20:58:16 +04:00
|
|
|
for (x = w, i = 0; i < 3; i ++)
|
2002-03-23 18:35:08 +03:00
|
|
|
if (button_w[i])
|
|
|
|
{
|
|
|
|
x -= button_w[i];
|
|
|
|
button[i]->resize(x, h - 10 - max_h, button_w[i] - 10, max_h);
|
2002-08-30 20:58:16 +04:00
|
|
|
|
|
|
|
// printf("button %d (%s) is %dx%d+%d,%d\n", i, button[i]->label(),
|
|
|
|
// button[i]->w(), button[i]->h(),
|
|
|
|
// button[i]->x(), button[i]->y());
|
2002-03-23 18:35:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
static int innards(const char* fmt, va_list ap,
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *b0,
|
|
|
|
const char *b1,
|
2000-04-12 08:32:05 +04:00
|
|
|
const char *b2)
|
1998-10-06 22:21:25 +04:00
|
|
|
{
|
|
|
|
makeform();
|
1998-11-05 19:04:53 +03:00
|
|
|
char buffer[1024];
|
|
|
|
if (!strcmp(fmt,"%s")) {
|
|
|
|
message->label(va_arg(ap, const char*));
|
|
|
|
} else {
|
2001-11-27 20:44:08 +03:00
|
|
|
//: matt: MacOS provides two equally named vsnprintf's...
|
|
|
|
::vsnprintf(buffer, 1024, fmt, ap);
|
1998-11-05 19:04:53 +03:00
|
|
|
message->label(buffer);
|
|
|
|
}
|
2002-03-23 18:35:08 +03:00
|
|
|
|
|
|
|
message->labelfont(fl_message_font_);
|
1998-12-02 18:39:39 +03:00
|
|
|
message->labelsize(fl_message_size_);
|
2000-04-12 08:32:05 +04:00
|
|
|
if (b0) {button[0]->show(); button[0]->label(b0); button[1]->position(210,70);}
|
1998-10-06 22:21:25 +04:00
|
|
|
else {button[0]->hide(); button[1]->position(310,70);}
|
|
|
|
if (b1) {button[1]->show(); button[1]->label(b1);}
|
|
|
|
else button[1]->hide();
|
|
|
|
if (b2) {button[2]->show(); button[2]->label(b2);}
|
|
|
|
else button[2]->hide();
|
|
|
|
const char* prev_icon_label = icon->label();
|
|
|
|
if (!prev_icon_label) icon->label(iconlabel);
|
2002-03-23 18:35:08 +03:00
|
|
|
|
|
|
|
resizeform();
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
message_form->hotspot(button[0]);
|
|
|
|
message_form->show();
|
|
|
|
int r;
|
|
|
|
for (;;) {
|
|
|
|
Fl_Widget *o = Fl::readqueue();
|
|
|
|
if (!o) Fl::wait();
|
|
|
|
else if (o == button[0]) {r = 0; break;}
|
|
|
|
else if (o == button[1]) {r = 1; break;}
|
|
|
|
else if (o == button[2]) {r = 2; break;}
|
|
|
|
else if (o == message_form) {r = 0; break;}
|
|
|
|
}
|
|
|
|
message_form->hide();
|
|
|
|
icon->label(prev_icon_label);
|
1998-11-05 19:04:53 +03:00
|
|
|
return r;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2001-11-18 15:48:38 +03:00
|
|
|
// pointers you can use to change FLTK to a foreign language:
|
1998-10-06 22:21:25 +04:00
|
|
|
const char* fl_no = "No";
|
|
|
|
const char* fl_yes= "Yes";
|
|
|
|
const char* fl_ok = "OK";
|
|
|
|
const char* fl_cancel= "Cancel";
|
2002-08-30 20:58:16 +04:00
|
|
|
const char* fl_close= "Close";
|
1998-10-06 22:21:25 +04:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
// fltk functions:
|
2001-11-17 19:37:48 +03:00
|
|
|
void fl_beep(int type) {
|
|
|
|
#ifdef WIN32
|
|
|
|
switch (type) {
|
|
|
|
case FL_BEEP_QUESTION :
|
|
|
|
case FL_BEEP_PASSWORD :
|
2001-11-18 15:48:38 +03:00
|
|
|
MessageBeep(MB_ICONQUESTION);
|
2001-11-17 19:37:48 +03:00
|
|
|
break;
|
|
|
|
case FL_BEEP_MESSAGE :
|
2001-11-18 15:48:38 +03:00
|
|
|
MessageBeep(MB_ICONASTERISK);
|
2001-11-17 19:37:48 +03:00
|
|
|
break;
|
|
|
|
case FL_BEEP_NOTIFICATION :
|
2001-11-18 15:48:38 +03:00
|
|
|
MessageBeep(MB_ICONASTERISK);
|
2001-11-17 19:37:48 +03:00
|
|
|
break;
|
2002-04-09 13:38:15 +04:00
|
|
|
case FL_BEEP_ERROR :
|
2001-11-18 15:48:38 +03:00
|
|
|
MessageBeep(MB_ICONERROR);
|
2001-11-17 19:37:48 +03:00
|
|
|
break;
|
2002-04-09 13:38:15 +04:00
|
|
|
default :
|
|
|
|
MessageBeep(0xFFFFFFFF);
|
|
|
|
break;
|
2001-11-17 19:37:48 +03:00
|
|
|
}
|
2001-11-27 20:44:08 +03:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
switch (type) {
|
|
|
|
case FL_BEEP_DEFAULT :
|
|
|
|
case FL_BEEP_ERROR :
|
2002-04-09 13:38:15 +04:00
|
|
|
SysBeep(30);
|
2001-11-27 20:44:08 +03:00
|
|
|
break;
|
|
|
|
default :
|
|
|
|
break;
|
|
|
|
}
|
2001-11-17 19:37:48 +03:00
|
|
|
#else
|
|
|
|
switch (type) {
|
|
|
|
case FL_BEEP_DEFAULT :
|
|
|
|
case FL_BEEP_ERROR :
|
|
|
|
if (!fl_display) fl_open_display();
|
|
|
|
|
|
|
|
XBell(fl_display, 100);
|
|
|
|
break;
|
|
|
|
default :
|
|
|
|
if (!fl_display) fl_open_display();
|
|
|
|
|
|
|
|
XBell(fl_display, 50);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif // WIN32
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
void fl_message(const char *fmt, ...) {
|
|
|
|
va_list ap;
|
1999-11-18 19:33:01 +03:00
|
|
|
|
2001-11-17 19:37:48 +03:00
|
|
|
fl_beep(FL_BEEP_MESSAGE);
|
1999-11-18 19:33:01 +03:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
va_start(ap, fmt);
|
1998-10-06 22:21:25 +04:00
|
|
|
iconlabel = "i";
|
2005-03-25 19:11:07 +03:00
|
|
|
innards(fmt, ap, 0, fl_close, 0);
|
1998-11-05 19:04:53 +03:00
|
|
|
va_end(ap);
|
|
|
|
iconlabel = "?";
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
void fl_alert(const char *fmt, ...) {
|
|
|
|
va_list ap;
|
1999-11-18 19:33:01 +03:00
|
|
|
|
2001-11-17 19:37:48 +03:00
|
|
|
fl_beep(FL_BEEP_ERROR);
|
1999-11-18 19:33:01 +03:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
va_start(ap, fmt);
|
1998-10-06 22:21:25 +04:00
|
|
|
iconlabel = "!";
|
2005-03-25 19:11:07 +03:00
|
|
|
innards(fmt, ap, 0, fl_close, 0);
|
1998-11-05 19:04:53 +03:00
|
|
|
va_end(ap);
|
1998-10-06 22:21:25 +04:00
|
|
|
iconlabel = "?";
|
|
|
|
}
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
int fl_ask(const char *fmt, ...) {
|
|
|
|
va_list ap;
|
1999-11-18 19:33:01 +03:00
|
|
|
|
2001-11-17 19:37:48 +03:00
|
|
|
fl_beep(FL_BEEP_QUESTION);
|
1999-11-18 19:33:01 +03:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
va_start(ap, fmt);
|
2000-04-12 08:32:05 +04:00
|
|
|
int r = innards(fmt, ap, fl_no, fl_yes, 0);
|
1998-11-05 19:04:53 +03:00
|
|
|
va_end(ap);
|
1999-11-18 19:33:01 +03:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
return r;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
int fl_choice(const char*fmt,const char *b0,const char *b1,const char *b2,...){
|
|
|
|
va_list ap;
|
1999-11-18 19:33:01 +03:00
|
|
|
|
2001-11-17 19:37:48 +03:00
|
|
|
fl_beep(FL_BEEP_QUESTION);
|
1999-11-18 19:33:01 +03:00
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
va_start(ap, b2);
|
2000-04-12 08:32:05 +04:00
|
|
|
int r = innards(fmt, ap, b0, b1, b2);
|
1998-11-05 19:04:53 +03:00
|
|
|
va_end(ap);
|
|
|
|
return r;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Widget *fl_message_icon() {makeform(); return icon;}
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
static const char* input_innards(const char* fmt, va_list ap,
|
|
|
|
const char* defstr, uchar type) {
|
1998-10-06 22:21:25 +04:00
|
|
|
makeform();
|
1998-11-05 19:04:53 +03:00
|
|
|
message->position(60,10);
|
1998-10-06 22:21:25 +04:00
|
|
|
input->type(type);
|
|
|
|
input->show();
|
|
|
|
input->value(defstr);
|
2004-10-19 00:22:25 +04:00
|
|
|
input->take_focus();
|
1999-11-18 19:33:01 +03:00
|
|
|
|
2000-04-12 08:32:05 +04:00
|
|
|
int r = innards(fmt, ap, fl_cancel, fl_ok, 0);
|
1998-10-06 22:21:25 +04:00
|
|
|
input->hide();
|
1998-11-05 19:04:53 +03:00
|
|
|
message->position(60,25);
|
|
|
|
return r ? input->value() : 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
const char* fl_input(const char *fmt, const char *defstr, ...) {
|
2001-11-17 19:37:48 +03:00
|
|
|
fl_beep(FL_BEEP_QUESTION);
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, defstr);
|
|
|
|
const char* r = input_innards(fmt, ap, defstr, FL_NORMAL_INPUT);
|
|
|
|
va_end(ap);
|
|
|
|
return r;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
const char *fl_password(const char *fmt, const char *defstr, ...) {
|
2001-11-17 19:37:48 +03:00
|
|
|
fl_beep(FL_BEEP_PASSWORD);
|
|
|
|
|
1998-11-05 19:04:53 +03:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, defstr);
|
|
|
|
const char* r = input_innards(fmt, ap, defstr, FL_SECRET_INPUT);
|
|
|
|
va_end(ap);
|
|
|
|
return r;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|