1998-03-05 07:53:47 +03:00
|
|
|
/*
|
|
|
|
* (C) 1998 the Free Software Foundation
|
|
|
|
*
|
|
|
|
* Written by Miguel de Icaza
|
|
|
|
*/
|
1998-03-23 08:27:15 +03:00
|
|
|
#include <config.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "util.h"
|
|
|
|
#include <gnome.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
1998-03-05 07:53:47 +03:00
|
|
|
#include "gconf.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "myslang.h"
|
|
|
|
#include "dlg.h"
|
|
|
|
#undef HAVE_LIBGPM
|
|
|
|
#include "mouse.h"
|
|
|
|
#include "key.h"
|
|
|
|
#include "widget.h"
|
|
|
|
#include "wtools.h"
|
|
|
|
#include "dialog.h"
|
1998-03-05 07:53:47 +03:00
|
|
|
#include "color.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-03-14 03:42:23 +03:00
|
|
|
Dlg_head *last_query_dlg;
|
1998-02-27 07:54:42 +03:00
|
|
|
static int sel_pos;
|
|
|
|
|
|
|
|
void query_set_sel (int new_sel)
|
|
|
|
{
|
|
|
|
sel_pos = new_sel;
|
|
|
|
}
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
static void
|
|
|
|
pack_button (WButton *button, GtkBox *box)
|
|
|
|
{
|
|
|
|
if (!button)
|
|
|
|
return;
|
1998-03-15 01:36:06 +03:00
|
|
|
gtk_box_pack_start (GTK_BOX (box), GTK_WIDGET (button->widget.wdata), 0, 0, 0);
|
1998-03-05 07:53:47 +03:00
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
int query_dialog (char *header, char *text, int flags, int count, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
1998-03-05 07:53:47 +03:00
|
|
|
Dlg_head *h;
|
|
|
|
WLabel *label;
|
1998-02-27 07:54:42 +03:00
|
|
|
GtkDialog *dialog;
|
1998-03-05 07:53:47 +03:00
|
|
|
GList *list;
|
|
|
|
int i, result = -1;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-03-30 01:07:37 +04:00
|
|
|
if (header == MSG_ERROR)
|
|
|
|
header = _("Error");
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
h = create_dlg (0, 0, 0, 0, dialog_colors, default_dlg_callback, "[QueryBox]", "query",
|
1998-03-15 02:20:51 +03:00
|
|
|
DLG_NO_TED | DLG_NO_TOPLEVEL);
|
1998-02-27 07:54:42 +03:00
|
|
|
dialog = GTK_DIALOG (gtk_dialog_new ());
|
1998-03-15 02:20:51 +03:00
|
|
|
x_dlg_set_window (h, dialog);
|
|
|
|
gtk_window_set_policy (GTK_WINDOW (dialog), 0, 0, 0);
|
1998-03-14 03:42:23 +03:00
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
x_set_dialog_title (h, header);
|
|
|
|
|
|
|
|
label = label_new (0, 0, text, NULL);
|
|
|
|
add_widget (h, label);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (flags & D_ERROR)
|
|
|
|
fprintf (stderr, "Messagebox: this should be displayed like an error\n");
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
va_start (ap, count);
|
|
|
|
list = g_list_alloc ();
|
1998-02-27 07:54:42 +03:00
|
|
|
for (i = 0; i < count; i++){
|
1998-03-05 07:53:47 +03:00
|
|
|
WButton *button;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *cur_name = va_arg (ap, char *);
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
button = button_new (0, 0, B_USER+i, NORMAL_BUTTON, cur_name, 0, 0, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
add_widget (h, button);
|
|
|
|
list = g_list_append (list, button);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
if (i == sel_pos)
|
|
|
|
h->initfocus = h->current;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-03-05 07:53:47 +03:00
|
|
|
va_end (ap);
|
|
|
|
|
|
|
|
/* Init the widgets */
|
|
|
|
init_dlg (h);
|
1998-03-14 03:42:23 +03:00
|
|
|
if (!(flags & D_INSERT))
|
|
|
|
gtk_grab_add (GTK_WIDGET (dialog));
|
1998-03-05 07:53:47 +03:00
|
|
|
|
|
|
|
/* Now do the GTK stuff */
|
|
|
|
gtk_container_add (GTK_CONTAINER (dialog->vbox), GTK_WIDGET (label->widget.wdata));
|
|
|
|
gtk_container_border_width (GTK_CONTAINER (dialog->vbox), 5);
|
|
|
|
|
|
|
|
g_list_foreach (list, (GFunc) pack_button, dialog->action_area);
|
|
|
|
g_list_free (list);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (dialog));
|
|
|
|
|
1998-03-14 03:42:23 +03:00
|
|
|
if (flags & D_INSERT){
|
|
|
|
last_query_dlg = h;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
frontend_run_dlg (h);
|
|
|
|
dlg_run_done (h);
|
1998-03-14 03:42:23 +03:00
|
|
|
last_query_dlg = h;
|
1998-03-07 06:02:01 +03:00
|
|
|
gtk_grab_remove (GTK_WIDGET (dialog));
|
1998-03-14 03:42:23 +03:00
|
|
|
|
1998-03-05 07:53:47 +03:00
|
|
|
switch (h->ret_value){
|
|
|
|
case B_CANCEL:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = h->ret_value - B_USER;
|
|
|
|
}
|
|
|
|
destroy_dlg (h);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
sel_pos = 0;
|
1998-03-05 07:53:47 +03:00
|
|
|
return result;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* To show nice messages to the users */
|
|
|
|
Dlg_head *message (int error, char *header, char *text, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char buffer [4096];
|
|
|
|
Dlg_head *d;
|
1998-03-25 08:16:00 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Setup the display information */
|
|
|
|
strcpy (buffer, "\n");
|
|
|
|
va_start (args, text);
|
|
|
|
vsprintf (&buffer [1], text, args);
|
|
|
|
strcat (buffer, "\n");
|
|
|
|
va_end (args);
|
|
|
|
|
1998-03-25 08:16:00 +03:00
|
|
|
query_dialog (header, buffer, error, 1, _("&Ok"));
|
1998-03-14 03:42:23 +03:00
|
|
|
d = last_query_dlg;
|
1998-03-11 00:10:30 +03:00
|
|
|
|
1998-03-14 03:42:23 +03:00
|
|
|
if (error & D_INSERT){
|
|
|
|
x_flush_events ();
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
return d;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
translate_gdk_keysym_to_curses (GdkEventKey *event)
|
|
|
|
{
|
|
|
|
int keyval = event->keyval;
|
|
|
|
|
|
|
|
switch (keyval){
|
|
|
|
case GDK_BackSpace:
|
|
|
|
return KEY_BACKSPACE;
|
|
|
|
case GDK_Tab:
|
1998-03-10 09:31:01 +03:00
|
|
|
if (event->state & GDK_SHIFT_MASK)
|
1998-03-23 10:12:13 +03:00
|
|
|
return '\t'; /* return KEY_BTAB */
|
1998-02-27 07:54:42 +03:00
|
|
|
return '\t';
|
|
|
|
case GDK_KP_Enter:
|
|
|
|
case GDK_Return:
|
|
|
|
return '\n';
|
|
|
|
case GDK_Escape:
|
|
|
|
return 27;
|
|
|
|
case GDK_Delete:
|
|
|
|
case GDK_KP_Delete:
|
|
|
|
return KEY_DC;
|
|
|
|
case GDK_KP_Home:
|
|
|
|
case GDK_Home:
|
|
|
|
return KEY_HOME;
|
|
|
|
case GDK_KP_End:
|
|
|
|
case GDK_End:
|
|
|
|
return KEY_END;
|
|
|
|
case GDK_KP_Left:
|
|
|
|
case GDK_Left:
|
|
|
|
return KEY_LEFT;
|
|
|
|
case GDK_KP_Right:
|
|
|
|
case GDK_Right:
|
|
|
|
return KEY_RIGHT;
|
|
|
|
case GDK_KP_Up:
|
|
|
|
case GDK_Up:
|
|
|
|
return KEY_UP;
|
|
|
|
case GDK_KP_Down:
|
|
|
|
case GDK_Down:
|
|
|
|
return KEY_DOWN;
|
|
|
|
case GDK_KP_Page_Up:
|
|
|
|
case GDK_Page_Up:
|
|
|
|
return KEY_PPAGE;
|
|
|
|
case GDK_KP_Page_Down:
|
|
|
|
case GDK_Page_Down:
|
|
|
|
return KEY_NPAGE;
|
|
|
|
case GDK_KP_Insert:
|
|
|
|
case GDK_Insert:
|
|
|
|
return KEY_IC;
|
|
|
|
case GDK_Menu:
|
|
|
|
return KEY_F(9);
|
|
|
|
case GDK_F1:
|
|
|
|
return KEY_F(1);
|
|
|
|
case GDK_F2:
|
|
|
|
return KEY_F(2);
|
|
|
|
case GDK_F3:
|
|
|
|
return KEY_F(3);
|
|
|
|
case GDK_F4:
|
|
|
|
return KEY_F(4);
|
|
|
|
case GDK_F5:
|
|
|
|
return KEY_F(5);
|
|
|
|
case GDK_F6:
|
|
|
|
return KEY_F(6);
|
|
|
|
case GDK_F7:
|
|
|
|
return KEY_F(7);
|
|
|
|
case GDK_F8:
|
|
|
|
return KEY_F(8);
|
|
|
|
case GDK_F9:
|
|
|
|
return KEY_F(9);
|
|
|
|
case GDK_F10:
|
|
|
|
return KEY_F(10);
|
|
|
|
case GDK_F11:
|
|
|
|
return KEY_F(11);
|
|
|
|
case GDK_F12:
|
|
|
|
return KEY_F(12);
|
|
|
|
case GDK_F13:
|
|
|
|
return KEY_F(13);
|
|
|
|
case GDK_F14:
|
|
|
|
return KEY_F(14);
|
|
|
|
case GDK_F15:
|
|
|
|
return KEY_F(15);
|
|
|
|
case GDK_F16:
|
|
|
|
return KEY_F(16);
|
|
|
|
case GDK_F17:
|
|
|
|
return KEY_F(17);
|
|
|
|
case GDK_F18:
|
|
|
|
return KEY_F(18);
|
|
|
|
case GDK_F19:
|
|
|
|
return KEY_F(19);
|
|
|
|
case GDK_F20:
|
|
|
|
return KEY_F(20);
|
|
|
|
|
|
|
|
/* The keys we ignore */
|
|
|
|
case GDK_Control_L:
|
|
|
|
case GDK_Control_R:
|
|
|
|
case GDK_Meta_L:
|
|
|
|
case GDK_Meta_R:
|
|
|
|
case GDK_Alt_L:
|
|
|
|
case GDK_Alt_R:
|
|
|
|
case GDK_Shift_L:
|
|
|
|
case GDK_Shift_R:
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if ((event->keyval >= 0x20) && (event->keyval <= 0xff)){
|
|
|
|
int key = event->keyval;
|
|
|
|
|
|
|
|
if (event->state & GDK_CONTROL_MASK){
|
|
|
|
return key - 'a' + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->state & GDK_MOD1_MASK){
|
|
|
|
return ALT (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
1998-03-11 00:10:30 +03:00
|
|
|
|
|
|
|
return -1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|