1998-02-27 07:54:42 +03:00
|
|
|
|
/* Widgets for the Midnight Commander
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1994, 1995, 1996 the Free Software Foundation
|
|
|
|
|
|
|
|
|
|
Authors: 1994, 1995 Radek Doulik
|
|
|
|
|
1994, 1995 Miguel de Icaza
|
|
|
|
|
1995 Jakub Jelinek
|
|
|
|
|
1996 Andrej Borsenkow
|
|
|
|
|
1997 Norbert Warmuth
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
2000-08-23 02:50:00 +04:00
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
|
|
|
|
|
#include <ctype.h>
|
1999-02-04 03:11:07 +03:00
|
|
|
|
#include <errno.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
1999-02-04 03:11:07 +03:00
|
|
|
|
#include <sys/types.h>
|
2005-02-08 12:04:03 +03:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
#include "global.h"
|
2001-09-03 09:07:40 +04:00
|
|
|
|
#include "tty.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
#include "color.h"
|
|
|
|
|
#include "mouse.h"
|
2003-10-25 03:20:30 +04:00
|
|
|
|
#include "dialog.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
#include "widget.h"
|
|
|
|
|
#include "win.h"
|
|
|
|
|
#include "complete.h"
|
2004-11-30 08:54:36 +03:00
|
|
|
|
#include "key.h" /* XCTRL and ALT macros */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
#include "profile.h" /* for history loading and saving */
|
2004-11-30 08:54:36 +03:00
|
|
|
|
#include "wtools.h" /* For common_dialog_repaint() */
|
|
|
|
|
#include "main.h" /* for `slow_terminal' */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2005-02-08 09:28:34 +03:00
|
|
|
|
#define HISTORY_FILE_NAME ".mc/history"
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
static int button_event (Gpm_Event *event, void *);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
int quote = 0;
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static cb_ret_t
|
2005-05-24 15:48:23 +04:00
|
|
|
|
button_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WButton *b = (WButton *) w;
|
2000-04-18 12:58:42 +04:00
|
|
|
|
char buf[BUF_SMALL];
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int stop = 0;
|
|
|
|
|
int off = 0;
|
2002-11-13 05:27:00 +03:00
|
|
|
|
Dlg_head *h = b->widget.parent;
|
2003-09-10 03:12:06 +04:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_HOTKEY:
|
2003-09-10 04:14:36 +04:00
|
|
|
|
/*
|
|
|
|
|
* Don't let the default button steal Enter from the current
|
|
|
|
|
* button. This is a workaround for the flawed event model
|
|
|
|
|
* when hotkeys are sent to all widgets before the key is
|
|
|
|
|
* handled by the current widget.
|
|
|
|
|
*/
|
2003-09-13 03:38:42 +04:00
|
|
|
|
if (parm == '\n' && h->current == &b->widget) {
|
2005-05-24 15:48:23 +04:00
|
|
|
|
button_callback (w, WIDGET_KEY, ' ');
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 04:14:36 +04:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (parm == '\n' && b->flags == DEFPUSH_BUTTON) {
|
2005-05-24 15:48:23 +04:00
|
|
|
|
button_callback (w, WIDGET_KEY, ' ');
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 03:12:06 +04:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-11 05:16:58 +04:00
|
|
|
|
if (b->hotkey == tolower (parm)) {
|
2005-05-24 15:48:23 +04:00
|
|
|
|
button_callback (w, WIDGET_KEY, ' ');
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 03:12:06 +04:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
2003-09-10 03:12:06 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_KEY:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (parm != ' ' && parm != '\n')
|
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
if (b->callback)
|
2003-09-10 03:12:06 +04:00
|
|
|
|
stop = (*b->callback) (b->action);
|
|
|
|
|
if (!b->callback || stop) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
h->ret_value = b->action;
|
1998-03-14 03:42:23 +03:00
|
|
|
|
dlg_stop (h);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case WIDGET_CURSOR:
|
1998-05-04 13:44:49 +04:00
|
|
|
|
switch (b->flags) {
|
2003-09-10 03:12:06 +04:00
|
|
|
|
case DEFPUSH_BUTTON:
|
|
|
|
|
off = 3;
|
|
|
|
|
break;
|
|
|
|
|
case NORMAL_BUTTON:
|
|
|
|
|
off = 2;
|
|
|
|
|
break;
|
|
|
|
|
case NARROW_BUTTON:
|
|
|
|
|
off = 1;
|
|
|
|
|
break;
|
|
|
|
|
case HIDDEN_BUTTON:
|
|
|
|
|
default:
|
|
|
|
|
off = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
1998-05-04 13:44:49 +04:00
|
|
|
|
widget_move (&b->widget, 0, b->hotpos + off);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case WIDGET_UNFOCUS:
|
|
|
|
|
case WIDGET_FOCUS:
|
|
|
|
|
case WIDGET_DRAW:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (msg == WIDGET_UNFOCUS)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
b->selected = 0;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
else if (msg == WIDGET_FOCUS)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
b->selected = 1;
|
|
|
|
|
|
2003-09-10 03:12:06 +04:00
|
|
|
|
switch (b->flags) {
|
|
|
|
|
case DEFPUSH_BUTTON:
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "[< %s >]", b->text);
|
|
|
|
|
off = 3;
|
|
|
|
|
break;
|
|
|
|
|
case NORMAL_BUTTON:
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "[ %s ]", b->text);
|
|
|
|
|
off = 2;
|
|
|
|
|
break;
|
|
|
|
|
case NARROW_BUTTON:
|
|
|
|
|
g_snprintf (buf, sizeof (buf), "[%s]", b->text);
|
|
|
|
|
off = 1;
|
|
|
|
|
break;
|
|
|
|
|
case HIDDEN_BUTTON:
|
|
|
|
|
default:
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
off = 0;
|
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrset ((b->selected) ? FOCUSC : NORMALC);
|
|
|
|
|
widget_move (&b->widget, 0, 0);
|
|
|
|
|
|
2000-04-18 12:58:42 +04:00
|
|
|
|
addstr (buf);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-10 03:12:06 +04:00
|
|
|
|
if (b->hotpos >= 0) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
attrset ((b->selected) ? HOT_FOCUSC : HOT_NORMALC);
|
2003-09-10 03:12:06 +04:00
|
|
|
|
widget_move (&b->widget, 0, b->hotpos + off);
|
|
|
|
|
addch ((unsigned char) b->text[b->hotpos]);
|
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
|
g_free (b->text);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
default:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return default_proc (msg, parm);
|
2003-09-10 03:12:06 +04:00
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2005-05-24 15:48:23 +04:00
|
|
|
|
button_event (Gpm_Event *event, void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WButton *b = data;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (event->type & (GPM_DOWN|GPM_UP)){
|
|
|
|
|
Dlg_head *h=b->widget.parent;
|
2005-05-21 00:22:06 +04:00
|
|
|
|
dlg_select_widget (b);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (event->type & GPM_UP){
|
2005-05-24 15:48:23 +04:00
|
|
|
|
button_callback ((Widget *) data, WIDGET_KEY, ' ');
|
2003-09-08 01:30:36 +04:00
|
|
|
|
(*h->callback) (h, DLG_POST_KEY, ' ');
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
button_len (const char *text, unsigned int flags)
|
|
|
|
|
{
|
|
|
|
|
int ret = strlen (text);
|
|
|
|
|
switch (flags){
|
|
|
|
|
case DEFPUSH_BUTTON:
|
|
|
|
|
ret += 6;
|
|
|
|
|
break;
|
|
|
|
|
case NORMAL_BUTTON:
|
|
|
|
|
ret += 4;
|
|
|
|
|
break;
|
|
|
|
|
case NARROW_BUTTON:
|
|
|
|
|
ret += 2;
|
|
|
|
|
break;
|
|
|
|
|
case HIDDEN_BUTTON:
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
1998-04-08 22:50:24 +04:00
|
|
|
|
/*
|
2002-12-15 22:42:04 +03:00
|
|
|
|
* Locate the hotkey and remove it from the button text. Assuming that
|
|
|
|
|
* the button text is g_malloc()ed, we can safely change and shorten it.
|
1998-04-08 22:50:24 +04:00
|
|
|
|
*/
|
2001-06-15 02:33:00 +04:00
|
|
|
|
static void
|
2003-09-22 23:40:07 +04:00
|
|
|
|
button_scan_hotkey (WButton *b)
|
1998-04-08 22:50:24 +04:00
|
|
|
|
{
|
2003-09-22 23:40:07 +04:00
|
|
|
|
char *cp = strchr (b->text, '&');
|
1998-04-16 08:27:44 +04:00
|
|
|
|
|
2003-09-22 23:40:07 +04:00
|
|
|
|
if (cp != NULL && cp[1] != '\0') {
|
|
|
|
|
g_strlcpy (cp, cp + 1, strlen (cp));
|
2005-05-11 05:16:58 +04:00
|
|
|
|
b->hotkey = tolower ((unsigned char) *cp);
|
1998-04-16 08:27:44 +04:00
|
|
|
|
b->hotpos = cp - b->text;
|
|
|
|
|
}
|
1998-04-08 22:50:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
WButton *
|
2004-08-17 04:00:32 +04:00
|
|
|
|
button_new (int y, int x, int action, int flags, const char *text,
|
2003-09-01 12:16:08 +04:00
|
|
|
|
bcback callback)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
WButton *b = g_new (WButton, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
init_widget (&b->widget, y, x, 1, button_len (text, flags),
|
2005-05-24 15:48:23 +04:00
|
|
|
|
button_callback, button_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
b->action = action;
|
|
|
|
|
b->flags = flags;
|
|
|
|
|
b->selected = 0;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
b->text = g_strdup (text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
b->callback = callback;
|
|
|
|
|
widget_want_hotkey (b->widget, 1);
|
|
|
|
|
b->hotkey = 0;
|
|
|
|
|
b->hotpos = -1;
|
1998-04-08 22:50:24 +04:00
|
|
|
|
|
|
|
|
|
button_scan_hotkey(b);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-07 02:08:02 +03:00
|
|
|
|
const char *
|
|
|
|
|
button_get_text (WButton *b)
|
|
|
|
|
{
|
|
|
|
|
return b->text;
|
|
|
|
|
}
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
void
|
2004-08-17 04:00:32 +04:00
|
|
|
|
button_set_text (WButton *b, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (b->text);
|
|
|
|
|
b->text = g_strdup (text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
b->widget.cols = button_len (text, b->flags);
|
1998-04-08 22:50:24 +04:00
|
|
|
|
button_scan_hotkey(b);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
dlg_redraw (b->widget.parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Radio button widget */
|
2005-05-24 15:48:23 +04:00
|
|
|
|
static int radio_event (Gpm_Event *event, void *);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static cb_ret_t
|
2005-05-24 15:48:23 +04:00
|
|
|
|
radio_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WRadio *r = (WRadio *) w;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int i;
|
2002-11-13 05:27:00 +03:00
|
|
|
|
Dlg_head *h = r->widget.parent;
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_HOTKEY:
|
Fri Apr 3 05:23:20 1998 Alex Tkachenko <alex@bcs.zp.ua>
* configure.in: ALL_LINGUAS test added, to allow specify list
of languages to be installed by setting env variable before
configure. If it is empty, it defaults to full list.
* src/menu.h menu_entry.{hot_pos, is_dupped} dropped
* src/menu.c: consistency fixes: pull-down menu items are now
accessible either with arrow keys or with hotkeys, denoted with &
(and highlighted). (key combinations, placed to the right of items
intended to be used from outside the menus). Freeing menu entries
removed as it no longer needed
* src/main.c, edit/editmenu.c: menubar init code is changed to conform
above fixes.
* edit/edit.h: use of "Cancel" in error_dialogs replaced with
"Dismiss", to avoid collisions in translation of "Cancel" in other
places with this case.
* src/boxes.c: select_format() and it's support removed, as it is
obsoleted by input line history feature. display_init()/display_callback
fixed to suite i18n changes. sort_box() - alike.
* src/option.c: pause_options added &'s and gettext calls to expand
statically assigned values.
* src/widget.c: (radio_callback) hotkey recognition is changed to
&-notation, rather than simple uppercase.
* src/dlg.c: (dlg_try_hotkey) plain symbol comparison replaced with
call to isalpha(), this fixes errorneous exit from input line, when
button hotkey is 8-bit NLS char.
1998-04-04 00:00:00 +04:00
|
|
|
|
{
|
2003-09-11 02:48:54 +04:00
|
|
|
|
int i, lp = tolower (parm);
|
2004-09-25 17:46:23 +04:00
|
|
|
|
const char *cp;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < r->count; i++) {
|
|
|
|
|
cp = strchr (r->texts[i], '&');
|
|
|
|
|
if (cp != NULL && cp[1] != '\0') {
|
2005-05-11 05:16:58 +04:00
|
|
|
|
int c = tolower ((unsigned char) cp[1]);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
|
1998-04-16 08:27:44 +04:00
|
|
|
|
if (c != lp)
|
|
|
|
|
continue;
|
|
|
|
|
r->pos = i;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
|
|
|
|
|
/* Take action */
|
2005-05-24 15:48:23 +04:00
|
|
|
|
radio_callback (w, WIDGET_KEY, ' ');
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-04-16 08:27:44 +04:00
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_KEY:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
switch (parm) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case ' ':
|
|
|
|
|
r->sel = r->pos;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
(*h->callback) (h, DLG_ACTION, 0);
|
2005-05-24 15:48:23 +04:00
|
|
|
|
radio_callback (w, WIDGET_FOCUS, ' ');
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case KEY_UP:
|
|
|
|
|
case KEY_LEFT:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (r->pos > 0) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
r->pos--;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case KEY_DOWN:
|
|
|
|
|
case KEY_RIGHT:
|
|
|
|
|
if (r->count - 1 > r->pos) {
|
|
|
|
|
r->pos++;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-03-11 08:55:05 +03:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_CURSOR:
|
2003-09-10 20:16:34 +04:00
|
|
|
|
(*h->callback) (h, DLG_ACTION, 0);
|
2005-05-24 15:48:23 +04:00
|
|
|
|
radio_callback (w, WIDGET_FOCUS, ' ');
|
1998-02-27 07:54:42 +03:00
|
|
|
|
widget_move (&r->widget, r->pos, 1);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_UNFOCUS:
|
|
|
|
|
case WIDGET_FOCUS:
|
|
|
|
|
case WIDGET_DRAW:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
for (i = 0; i < r->count; i++) {
|
2005-05-11 05:16:58 +04:00
|
|
|
|
register const char *cp;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
attrset ((i == r->pos
|
|
|
|
|
&& msg == WIDGET_FOCUS) ? FOCUSC : NORMALC);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
widget_move (&r->widget, i, 0);
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
printw ("(%c) ", (r->sel == i) ? '*' : ' ');
|
|
|
|
|
for (cp = r->texts[i]; *cp; cp++) {
|
|
|
|
|
if (*cp == '&') {
|
|
|
|
|
attrset ((i == r->pos && msg == WIDGET_FOCUS)
|
|
|
|
|
? HOT_FOCUSC : HOT_NORMALC);
|
|
|
|
|
addch (*++cp);
|
|
|
|
|
attrset ((i == r->pos
|
|
|
|
|
&& msg == WIDGET_FOCUS) ? FOCUSC : NORMALC);
|
|
|
|
|
} else
|
|
|
|
|
addch (*cp);
|
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2005-05-24 15:48:23 +04:00
|
|
|
|
radio_event (Gpm_Event *event, void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WRadio *r = data;
|
|
|
|
|
Widget *w = data;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (event->type & (GPM_DOWN|GPM_UP)){
|
|
|
|
|
Dlg_head *h = r->widget.parent;
|
|
|
|
|
|
|
|
|
|
r->pos = event->y - 1;
|
2005-05-21 00:22:06 +04:00
|
|
|
|
dlg_select_widget (r);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (event->type & GPM_UP){
|
2005-05-24 15:48:23 +04:00
|
|
|
|
radio_callback (w, WIDGET_KEY, ' ');
|
|
|
|
|
radio_callback (w, WIDGET_FOCUS, 0);
|
2003-09-08 01:30:36 +04:00
|
|
|
|
(*h->callback) (h, DLG_POST_KEY, ' ');
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WRadio *
|
2004-08-17 04:00:32 +04:00
|
|
|
|
radio_new (int y, int x, int count, const char **texts, int use_hotkey)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
WRadio *r = g_new (WRadio, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int i, max, m;
|
|
|
|
|
|
|
|
|
|
/* Compute the longest string */
|
|
|
|
|
max = 0;
|
|
|
|
|
for (i = 0; i < count; i++){
|
|
|
|
|
m = strlen (texts [i]);
|
|
|
|
|
if (m > max)
|
|
|
|
|
max = m;
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
init_widget (&r->widget, y, x, count, max, radio_callback, radio_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
r->state = 1;
|
|
|
|
|
r->pos = 0;
|
|
|
|
|
r->sel = 0;
|
|
|
|
|
r->count = count;
|
2004-08-30 03:54:47 +04:00
|
|
|
|
r->texts = texts;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
r->upper_letter_is_hotkey = use_hotkey;
|
|
|
|
|
widget_want_hotkey (r->widget, 1);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Checkbutton widget */
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
static int check_event (Gpm_Event *event, void *);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static cb_ret_t
|
2005-05-24 15:48:23 +04:00
|
|
|
|
check_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WCheck *c = (WCheck *) w;
|
2002-11-13 05:27:00 +03:00
|
|
|
|
Dlg_head *h = c->widget.parent;
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_HOTKEY:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (c->hotkey == parm
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|| (c->hotkey >= 'a' && c->hotkey <= 'z'
|
2003-09-11 02:48:54 +04:00
|
|
|
|
&& c->hotkey - 32 == parm)) {
|
2005-05-24 15:48:23 +04:00
|
|
|
|
check_callback (w, WIDGET_KEY, ' '); /* make action */
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case WIDGET_KEY:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (parm != ' ')
|
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
c->state ^= C_BOOL;
|
|
|
|
|
c->state ^= C_CHANGE;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
(*h->callback) (h, DLG_ACTION, 0);
|
2005-05-24 15:48:23 +04:00
|
|
|
|
check_callback (w, WIDGET_FOCUS, ' ');
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case WIDGET_CURSOR:
|
|
|
|
|
widget_move (&c->widget, 0, 1);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_FOCUS:
|
2003-09-10 22:21:40 +04:00
|
|
|
|
case WIDGET_UNFOCUS:
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_DRAW:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
attrset ((msg == WIDGET_FOCUS) ? FOCUSC : NORMALC);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
widget_move (&c->widget, 0, 0);
|
|
|
|
|
printw ("[%c] %s", (c->state & C_BOOL) ? 'x' : ' ', c->text);
|
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
if (c->hotpos >= 0) {
|
2003-09-11 02:48:54 +04:00
|
|
|
|
attrset ((msg == WIDGET_FOCUS) ? HOT_FOCUSC : HOT_NORMALC);
|
2003-09-10 22:21:40 +04:00
|
|
|
|
widget_move (&c->widget, 0, +c->hotpos + 4);
|
|
|
|
|
addch ((unsigned char) c->text[c->hotpos]);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
|
g_free (c->text);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
default:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2005-05-24 15:48:23 +04:00
|
|
|
|
check_event (Gpm_Event *event, void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WCheck *c = data;
|
|
|
|
|
Widget *w = data;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (event->type & (GPM_DOWN|GPM_UP)){
|
|
|
|
|
Dlg_head *h = c->widget.parent;
|
|
|
|
|
|
2005-05-21 00:22:06 +04:00
|
|
|
|
dlg_select_widget (c);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (event->type & GPM_UP){
|
2005-05-24 15:48:23 +04:00
|
|
|
|
check_callback (w, WIDGET_KEY, ' ');
|
|
|
|
|
check_callback (w, WIDGET_FOCUS, 0);
|
2003-09-08 01:30:36 +04:00
|
|
|
|
(*h->callback) (h, DLG_POST_KEY, ' ');
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WCheck *
|
2004-08-17 04:00:32 +04:00
|
|
|
|
check_new (int y, int x, int state, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
WCheck *c = g_new (WCheck, 1);
|
2004-08-17 04:00:32 +04:00
|
|
|
|
const char *s;
|
|
|
|
|
char *t;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
init_widget (&c->widget, y, x, 1, strlen (text),
|
2005-05-24 15:48:23 +04:00
|
|
|
|
check_callback, check_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
c->state = state ? C_BOOL : 0;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
c->text = g_strdup (text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
c->hotkey = 0;
|
|
|
|
|
c->hotpos = -1;
|
|
|
|
|
widget_want_hotkey (c->widget, 1);
|
|
|
|
|
|
|
|
|
|
/* Scan for the hotkey */
|
|
|
|
|
for (s = text, t = c->text; *s; s++, t++){
|
|
|
|
|
if (*s != '&'){
|
|
|
|
|
*t = *s;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
s++;
|
|
|
|
|
if (*s){
|
2005-05-11 05:16:58 +04:00
|
|
|
|
c->hotkey = tolower ((unsigned char) *s);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
c->hotpos = t - c->text;
|
|
|
|
|
}
|
|
|
|
|
*t = *s;
|
|
|
|
|
}
|
|
|
|
|
*t = 0;
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Label widget */
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
static cb_ret_t
|
|
|
|
|
label_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WLabel *l = (WLabel *) w;
|
2002-11-13 05:27:00 +03:00
|
|
|
|
Dlg_head *h = l->widget.parent;
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
switch (msg) {
|
2003-09-10 22:21:40 +04:00
|
|
|
|
case WIDGET_INIT:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
/* We don't want to get the focus */
|
|
|
|
|
case WIDGET_FOCUS:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
case WIDGET_DRAW:
|
|
|
|
|
{
|
2004-09-26 00:49:15 +04:00
|
|
|
|
char *p = l->text, *q, c = 0;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
int y = 0;
|
|
|
|
|
|
|
|
|
|
if (!l->text)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
if (l->transparent)
|
|
|
|
|
attrset (DEFAULT_COLOR);
|
|
|
|
|
else
|
|
|
|
|
attrset (NORMALC);
|
|
|
|
|
for (;;) {
|
|
|
|
|
int xlen;
|
|
|
|
|
|
|
|
|
|
q = strchr (p, '\n');
|
2004-09-26 00:49:15 +04:00
|
|
|
|
if (q) {
|
|
|
|
|
c = *q;
|
|
|
|
|
*q = 0;
|
|
|
|
|
}
|
2003-09-10 22:21:40 +04:00
|
|
|
|
widget_move (&l->widget, y, 0);
|
2004-09-26 00:49:15 +04:00
|
|
|
|
printw ("%s", p);
|
2003-09-10 22:21:40 +04:00
|
|
|
|
xlen = l->widget.cols - strlen (p);
|
|
|
|
|
if (xlen > 0)
|
|
|
|
|
printw ("%*s", xlen, " ");
|
|
|
|
|
if (!q)
|
|
|
|
|
break;
|
2004-09-26 00:49:15 +04:00
|
|
|
|
*q = c;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
p = q + 1;
|
|
|
|
|
y++;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
|
g_free (l->text);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
default:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2004-08-17 04:00:32 +04:00
|
|
|
|
label_set_text (WLabel *label, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
int newcols = label->widget.cols;
|
|
|
|
|
|
|
|
|
|
if (label->text && text && !strcmp (label->text, text))
|
|
|
|
|
return; /* Flickering is not nice */
|
|
|
|
|
|
2004-09-25 02:22:35 +04:00
|
|
|
|
g_free (label->text);
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (text){
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
label->text = g_strdup (text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (label->auto_adjust_cols) {
|
|
|
|
|
newcols = strlen (text);
|
|
|
|
|
if (newcols > label->widget.cols)
|
|
|
|
|
label->widget.cols = newcols;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
label->text = 0;
|
|
|
|
|
|
|
|
|
|
if (label->widget.parent)
|
2005-05-24 15:48:23 +04:00
|
|
|
|
label_callback ((Widget *) label, WIDGET_DRAW, 0);
|
2001-09-16 05:22:12 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (newcols < label->widget.cols)
|
|
|
|
|
label->widget.cols = newcols;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WLabel *
|
2003-09-01 04:18:37 +04:00
|
|
|
|
label_new (int y, int x, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2001-09-03 19:17:27 +04:00
|
|
|
|
WLabel *l;
|
|
|
|
|
int width;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2001-09-03 19:17:27 +04:00
|
|
|
|
/* Multiline labels are immutable - no need to compute their sizes */
|
|
|
|
|
if (!text || strchr(text, '\n'))
|
|
|
|
|
width = 1;
|
|
|
|
|
else
|
|
|
|
|
width = strlen (text);
|
|
|
|
|
|
|
|
|
|
l = g_new (WLabel, 1);
|
2005-05-24 15:48:23 +04:00
|
|
|
|
init_widget (&l->widget, y, x, 1, width, label_callback, NULL);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
l->text = text ? g_strdup (text) : 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
l->auto_adjust_cols = 1;
|
|
|
|
|
l->transparent = 0;
|
|
|
|
|
widget_want_cursor (l->widget, 0);
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Gauge widget (progress indicator) */
|
|
|
|
|
/* Currently width is hardcoded here for text mode */
|
|
|
|
|
#define gauge_len 47
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
static cb_ret_t
|
|
|
|
|
gauge_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WGauge *g = (WGauge *) w;
|
2002-11-13 05:27:00 +03:00
|
|
|
|
Dlg_head *h = g->widget.parent;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (msg == WIDGET_INIT)
|
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
/* We don't want to get the focus */
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (msg == WIDGET_FOCUS)
|
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (msg == WIDGET_DRAW){
|
1998-02-27 07:54:42 +03:00
|
|
|
|
widget_move (&g->widget, 0, 0);
|
|
|
|
|
attrset (NORMALC);
|
|
|
|
|
if (!g->shown)
|
|
|
|
|
printw ("%*s", gauge_len, "");
|
|
|
|
|
else {
|
2004-09-04 02:00:27 +04:00
|
|
|
|
int percentage, columns;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
long total = g->max, done = g->current;
|
|
|
|
|
|
|
|
|
|
if (total <= 0 || done < 0) {
|
|
|
|
|
done = 0;
|
|
|
|
|
total = 100;
|
|
|
|
|
}
|
|
|
|
|
if (done > total)
|
|
|
|
|
done = total;
|
|
|
|
|
while (total > 65535) {
|
|
|
|
|
total /= 256;
|
|
|
|
|
done /= 256;
|
|
|
|
|
}
|
|
|
|
|
percentage = (200 * done / total + 1) / 2;
|
|
|
|
|
columns = (2 * (gauge_len - 7) * done / total + 1) / 2;
|
|
|
|
|
addch ('[');
|
|
|
|
|
attrset (GAUGE_COLOR);
|
2004-08-16 03:09:36 +04:00
|
|
|
|
printw ("%*s", (int) columns, "");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
attrset (NORMALC);
|
2004-08-16 03:09:36 +04:00
|
|
|
|
printw ("%*s] %3d%%", (int)(gauge_len - 7 - columns), "", (int) percentage);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gauge_set_value (WGauge *g, int max, int current)
|
|
|
|
|
{
|
|
|
|
|
if (g->current == current && g->max == max)
|
|
|
|
|
return; /* Do not flicker */
|
|
|
|
|
if (max == 0)
|
|
|
|
|
max = 1; /* I do not like division by zero :) */
|
2001-09-16 05:22:12 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
g->current = current;
|
|
|
|
|
g->max = max;
|
2005-05-24 15:48:23 +04:00
|
|
|
|
gauge_callback ((Widget *) g, WIDGET_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gauge_show (WGauge *g, int shown)
|
|
|
|
|
{
|
|
|
|
|
if (g->shown == shown)
|
|
|
|
|
return;
|
|
|
|
|
g->shown = shown;
|
2005-05-24 15:48:23 +04:00
|
|
|
|
gauge_callback ((Widget *) g, WIDGET_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WGauge *
|
2003-09-01 04:18:37 +04:00
|
|
|
|
gauge_new (int y, int x, int shown, int max, int current)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
WGauge *g = g_new (WGauge, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
init_widget (&g->widget, y, x, 1, gauge_len, gauge_callback, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
g->shown = shown;
|
|
|
|
|
if (max == 0)
|
|
|
|
|
max = 1; /* I do not like division by zero :) */
|
|
|
|
|
g->max = max;
|
|
|
|
|
g->current = current;
|
|
|
|
|
widget_want_cursor (g->widget, 0);
|
|
|
|
|
return g;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Input widget */
|
|
|
|
|
|
|
|
|
|
/* {{{ history button */
|
|
|
|
|
|
|
|
|
|
#define LARGE_HISTORY_BUTTON 1
|
|
|
|
|
|
|
|
|
|
#ifdef LARGE_HISTORY_BUTTON
|
|
|
|
|
# define HISTORY_BUTTON_WIDTH 3
|
|
|
|
|
#else
|
|
|
|
|
# define HISTORY_BUTTON_WIDTH 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define should_show_history_button(in) \
|
|
|
|
|
(in->history && in->field_len > HISTORY_BUTTON_WIDTH * 2 + 1 && in->widget.parent)
|
|
|
|
|
|
|
|
|
|
static void draw_history_button (WInput * in)
|
|
|
|
|
{
|
|
|
|
|
char c;
|
|
|
|
|
c = in->history->next ? (in->history->prev ? '|' : 'v') : '^';
|
|
|
|
|
widget_move (&in->widget, 0, in->field_len - HISTORY_BUTTON_WIDTH);
|
|
|
|
|
#ifdef LARGE_HISTORY_BUTTON
|
|
|
|
|
{
|
|
|
|
|
Dlg_head *h;
|
|
|
|
|
h = in->widget.parent;
|
|
|
|
|
#if 0
|
2003-06-02 22:13:42 +04:00
|
|
|
|
attrset (NORMALC); /* button has the same color as other buttons */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
addstr ("[ ]");
|
|
|
|
|
attrset (HOT_NORMALC);
|
|
|
|
|
#else
|
|
|
|
|
attrset (NORMAL_COLOR);
|
|
|
|
|
addstr ("[ ]");
|
|
|
|
|
/* Too distracting: attrset (MARKED_COLOR); */
|
|
|
|
|
#endif
|
|
|
|
|
widget_move (&in->widget, 0, in->field_len - HISTORY_BUTTON_WIDTH + 1);
|
|
|
|
|
addch (c);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
attrset (MARKED_COLOR);
|
|
|
|
|
addch (c);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
1998-12-02 08:18:20 +03:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
/* }}} history button */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Input widgets now have a global kill ring */
|
|
|
|
|
/* Pointer to killed data */
|
|
|
|
|
static char *kill_buffer = 0;
|
|
|
|
|
|
|
|
|
|
void
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (WInput *in, int clear_first)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
int has_history = 0;
|
|
|
|
|
int i, j;
|
1998-06-01 00:27:44 +04:00
|
|
|
|
unsigned char c;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int buf_len = strlen (in->buffer);
|
|
|
|
|
|
|
|
|
|
if (should_show_history_button (in))
|
|
|
|
|
has_history = HISTORY_BUTTON_WIDTH;
|
|
|
|
|
|
|
|
|
|
if (in->disable_update)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* Make the point visible */
|
|
|
|
|
if ((in->point < in->first_shown) ||
|
|
|
|
|
(in->point >= in->first_shown+in->field_len - has_history)){
|
|
|
|
|
in->first_shown = in->point - (in->field_len / 3);
|
|
|
|
|
if (in->first_shown < 0)
|
|
|
|
|
in->first_shown = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Adjust the mark */
|
|
|
|
|
if (in->mark > buf_len)
|
|
|
|
|
in->mark = buf_len;
|
1998-04-09 08:58:24 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (has_history)
|
|
|
|
|
draw_history_button (in);
|
|
|
|
|
|
|
|
|
|
attrset (in->color);
|
|
|
|
|
|
|
|
|
|
widget_move (&in->widget, 0, 0);
|
|
|
|
|
for (i = 0; i < in->field_len - has_history; i++)
|
|
|
|
|
addch (' ');
|
|
|
|
|
widget_move (&in->widget, 0, 0);
|
|
|
|
|
|
|
|
|
|
for (i = 0, j = in->first_shown; i < in->field_len - has_history && in->buffer [j]; i++){
|
|
|
|
|
c = in->buffer [j++];
|
|
|
|
|
c = is_printable (c) ? c : '.';
|
|
|
|
|
if (in->is_password)
|
|
|
|
|
c = '*';
|
|
|
|
|
addch (c);
|
|
|
|
|
}
|
|
|
|
|
widget_move (&in->widget, 0, in->point - in->first_shown);
|
1998-04-09 08:58:24 +04:00
|
|
|
|
|
|
|
|
|
if (clear_first)
|
|
|
|
|
in->first = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
winput_set_origin (WInput *in, int x, int field_len)
|
|
|
|
|
{
|
|
|
|
|
in->widget.x = x;
|
|
|
|
|
in->field_len = in->widget.cols = field_len;
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* {{{ history saving and loading */
|
|
|
|
|
|
2003-02-18 08:25:45 +03:00
|
|
|
|
int num_history_items_recorded = 60;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
/*
|
|
|
|
|
This loads and saves the history of an input line to and from the
|
2003-09-01 05:34:17 +04:00
|
|
|
|
widget. It is called with the widgets history name on creation of the
|
2003-02-18 08:25:45 +03:00
|
|
|
|
widget, and returns the GList list. It stores histories in the file
|
1998-02-27 07:54:42 +03:00
|
|
|
|
~/.mc/history in using the profile code.
|
|
|
|
|
|
|
|
|
|
If def_text is passed as INPUT_LAST_TEXT (to the input_new()
|
|
|
|
|
function) then input_new assigns the default text to be the last text
|
|
|
|
|
entered, or "" if not found.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-02-18 08:25:45 +03:00
|
|
|
|
GList *
|
2004-08-17 04:00:32 +04:00
|
|
|
|
history_get (const char *input_name)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
int i;
|
2003-02-18 08:25:45 +03:00
|
|
|
|
GList *hist;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
char *profile;
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
|
|
|
|
hist = NULL;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!num_history_items_recorded) /* this is how to disable */
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!input_name)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!*input_name)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
|
|
|
|
|
for (i = 0;; i++) {
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
char key_name[BUF_TINY];
|
|
|
|
|
char this_entry[BUF_LARGE];
|
|
|
|
|
g_snprintf (key_name, sizeof (key_name), "%d", i);
|
2003-02-18 08:25:45 +03:00
|
|
|
|
GetPrivateProfileString (input_name, key_name, "", this_entry,
|
|
|
|
|
sizeof (this_entry), profile);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!*this_entry)
|
|
|
|
|
break;
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
2003-02-18 09:29:43 +03:00
|
|
|
|
hist = list_append_unique (hist, g_strdup (this_entry));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (profile);
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
2003-02-19 00:43:46 +03:00
|
|
|
|
/* return pointer to the last entry in the list */
|
|
|
|
|
hist = g_list_last (hist);
|
|
|
|
|
|
2003-02-18 08:25:45 +03:00
|
|
|
|
return hist;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2002-08-22 01:47:29 +04:00
|
|
|
|
void
|
2004-08-17 04:00:32 +04:00
|
|
|
|
history_put (const char *input_name, GList *h)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char *profile;
|
|
|
|
|
|
|
|
|
|
if (!input_name)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!*input_name)
|
|
|
|
|
return;
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!h)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!num_history_items_recorded) /* this is how to disable */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
profile = concat_dir_and_file (home_dir, HISTORY_FILE_NAME);
|
1999-02-04 02:19:40 +03:00
|
|
|
|
|
1999-02-04 03:11:07 +03:00
|
|
|
|
if ((i = open (profile, O_CREAT | O_EXCL, S_IRUSR | S_IWUSR)) != -1)
|
|
|
|
|
close (i);
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
|
|
|
|
/* Make sure the history is only readable by the user */
|
|
|
|
|
if (chmod (profile, S_IRUSR | S_IWUSR) == -1 && errno != ENOENT) {
|
2000-04-18 12:58:42 +04:00
|
|
|
|
g_free (profile);
|
1999-02-04 03:11:07 +03:00
|
|
|
|
return;
|
2000-04-18 12:58:42 +04:00
|
|
|
|
}
|
1999-02-04 03:11:07 +03:00
|
|
|
|
|
2003-02-18 08:25:45 +03:00
|
|
|
|
/* go to end of list */
|
|
|
|
|
h = g_list_last (h);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
/* go back 60 places */
|
2003-02-18 08:25:45 +03:00
|
|
|
|
for (i = 0; i < num_history_items_recorded - 1 && h->prev; i++)
|
|
|
|
|
h = g_list_previous (h);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
if (input_name)
|
|
|
|
|
profile_clean_section (input_name, profile);
|
|
|
|
|
|
|
|
|
|
/* dump histories into profile */
|
2003-02-18 08:25:45 +03:00
|
|
|
|
for (i = 0; h; h = g_list_next (h)) {
|
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
|
|
text = (char *) h->data;
|
|
|
|
|
|
|
|
|
|
/* We shouldn't have null entries, but let's be sure */
|
|
|
|
|
if (text && *text) {
|
|
|
|
|
char key_name[BUF_TINY];
|
|
|
|
|
g_snprintf (key_name, sizeof (key_name), "%d", i++);
|
|
|
|
|
WritePrivateProfileString (input_name, key_name, text,
|
|
|
|
|
profile);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (profile);
|
2000-04-18 12:58:42 +04:00
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
/* }}} history saving and loading */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* {{{ history display */
|
|
|
|
|
|
2004-09-19 19:55:58 +04:00
|
|
|
|
static const char *
|
1999-08-01 15:37:25 +04:00
|
|
|
|
i18n_htitle (void)
|
|
|
|
|
{
|
2004-09-19 19:55:58 +04:00
|
|
|
|
static const char *history_title = NULL;
|
1999-08-01 15:37:25 +04:00
|
|
|
|
|
|
|
|
|
if (history_title == NULL)
|
|
|
|
|
history_title = _(" History ");
|
|
|
|
|
return history_title;
|
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static inline cb_ret_t listbox_fwd (WListbox *l);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2002-08-22 01:47:29 +04:00
|
|
|
|
char *
|
2003-02-18 08:25:45 +03:00
|
|
|
|
show_hist (GList *history, int widget_x, int widget_y)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2003-02-18 08:25:45 +03:00
|
|
|
|
GList *hi, *z;
|
2002-09-02 12:01:35 +04:00
|
|
|
|
size_t maxlen = strlen (i18n_htitle ()), i, count = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int x, y, w, h;
|
1998-03-31 01:04:59 +04:00
|
|
|
|
char *q, *r = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
Dlg_head *query_dlg;
|
|
|
|
|
WListbox *query_list;
|
|
|
|
|
|
1998-03-31 01:04:59 +04:00
|
|
|
|
z = history;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!z)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-02-18 08:25:45 +03:00
|
|
|
|
z = g_list_first (history);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
hi = z;
|
|
|
|
|
while (hi) {
|
2003-02-18 08:25:45 +03:00
|
|
|
|
if ((i = strlen ((char *) hi->data)) > maxlen)
|
2002-09-02 12:01:35 +04:00
|
|
|
|
maxlen = i;
|
|
|
|
|
count++;
|
2003-02-18 08:25:45 +03:00
|
|
|
|
hi = g_list_next (hi);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-02 12:01:35 +04:00
|
|
|
|
y = widget_y;
|
|
|
|
|
h = count + 2;
|
|
|
|
|
if (h <= y || y > LINES - 6) {
|
|
|
|
|
h = min (h, y - 1);
|
|
|
|
|
y -= h;
|
|
|
|
|
} else {
|
|
|
|
|
y++;
|
|
|
|
|
h = min (h, LINES - y);
|
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2002-09-02 12:01:35 +04:00
|
|
|
|
if (widget_x > 2)
|
|
|
|
|
x = widget_x - 2;
|
|
|
|
|
else
|
|
|
|
|
x = 0;
|
|
|
|
|
if ((w = maxlen + 4) + x > COLS) {
|
|
|
|
|
w = min (w, COLS);
|
|
|
|
|
x = COLS - w;
|
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2002-09-02 12:01:35 +04:00
|
|
|
|
query_dlg =
|
2002-09-02 20:31:33 +04:00
|
|
|
|
create_dlg (y, x, h, w, dialog_colors, NULL, "[History-query]",
|
2003-09-13 02:08:09 +04:00
|
|
|
|
i18n_htitle (), DLG_COMPACT);
|
2003-09-01 11:31:56 +04:00
|
|
|
|
query_list = listbox_new (1, 1, w - 2, h - 2, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
add_widget (query_dlg, query_list);
|
|
|
|
|
hi = z;
|
1998-03-31 01:04:59 +04:00
|
|
|
|
if (y < widget_y) {
|
2003-02-18 08:25:45 +03:00
|
|
|
|
/* traverse */
|
|
|
|
|
while (hi) {
|
|
|
|
|
listbox_add_item (query_list, 0, 0, (char *) hi->data, NULL);
|
|
|
|
|
hi = g_list_next (hi);
|
2002-09-02 12:01:35 +04:00
|
|
|
|
}
|
|
|
|
|
while (listbox_fwd (query_list));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
} else {
|
2003-02-18 08:25:45 +03:00
|
|
|
|
/* traverse backwards */
|
|
|
|
|
hi = g_list_last (history);
|
|
|
|
|
while (hi) {
|
|
|
|
|
listbox_add_item (query_list, 0, 0, (char *) hi->data, NULL);
|
|
|
|
|
hi = g_list_previous (hi);
|
2002-09-02 12:01:35 +04:00
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
run_dlg (query_dlg);
|
|
|
|
|
q = NULL;
|
|
|
|
|
if (query_dlg->ret_value != B_CANCEL) {
|
2002-09-02 12:01:35 +04:00
|
|
|
|
listbox_get_current (query_list, &q, NULL);
|
|
|
|
|
if (q)
|
|
|
|
|
r = g_strdup (q);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
destroy_dlg (query_dlg);
|
1998-03-31 01:04:59 +04:00
|
|
|
|
return r;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
1998-03-31 01:04:59 +04:00
|
|
|
|
static void do_show_hist (WInput * in)
|
|
|
|
|
{
|
|
|
|
|
char *r;
|
|
|
|
|
r = show_hist (in->history, in->widget.x, in->widget.y);
|
|
|
|
|
if (r) {
|
|
|
|
|
assign_text (in, r);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (r);
|
1998-03-31 01:04:59 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
/* }}} history display */
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
input_destroy (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
if (!in){
|
|
|
|
|
fprintf (stderr, "Internal error: null Input *\n");
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_input (in);
|
|
|
|
|
|
2003-02-18 08:25:45 +03:00
|
|
|
|
if (in->history){
|
2001-09-16 05:10:09 +04:00
|
|
|
|
if (!in->is_password) /* don't save passwords ;-) */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
history_put (in->history_name, in->history);
|
|
|
|
|
|
2003-06-06 03:51:15 +04:00
|
|
|
|
in->history = g_list_first (in->history);
|
2003-02-18 08:25:45 +03:00
|
|
|
|
g_list_foreach (in->history, (GFunc) g_free, NULL);
|
|
|
|
|
g_list_free (in->history);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (in->buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
free_completions (in);
|
2003-09-10 22:21:40 +04:00
|
|
|
|
g_free (in->history_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char disable_update = 0;
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
input_disable_update (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
in->disable_update++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
input_enable_update (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
in->disable_update--;
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
1999-08-06 23:24:04 +04:00
|
|
|
|
#define ELEMENTS(a) (sizeof(a)/sizeof(a[0]))
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int
|
2004-08-17 04:00:32 +04:00
|
|
|
|
push_history (WInput *in, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
1999-08-06 23:24:04 +04:00
|
|
|
|
static int i18n;
|
|
|
|
|
/* input widget where urls with passwords are entered without any
|
|
|
|
|
vfs prefix */
|
|
|
|
|
static const char *password_input_fields[] = {
|
2000-04-18 12:58:42 +04:00
|
|
|
|
N_(" Link to a remote machine "),
|
|
|
|
|
N_(" FTP to machine "),
|
|
|
|
|
N_(" SMB link to machine ")
|
1999-08-06 23:24:04 +04:00
|
|
|
|
};
|
2003-02-18 08:25:45 +03:00
|
|
|
|
char *t;
|
2004-08-17 04:00:32 +04:00
|
|
|
|
const char *p;
|
2004-08-16 08:17:43 +04:00
|
|
|
|
size_t i;
|
1999-08-06 23:24:04 +04:00
|
|
|
|
|
|
|
|
|
if (!i18n) {
|
|
|
|
|
i18n = 1;
|
2003-02-18 08:25:45 +03:00
|
|
|
|
for (i = 0; i < ELEMENTS (password_input_fields); i++)
|
1999-08-06 23:24:04 +04:00
|
|
|
|
password_input_fields[i] = _(password_input_fields[i]);
|
|
|
|
|
}
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
for (p = text; *p == ' ' || *p == '\t'; p++);
|
|
|
|
|
if (!*p)
|
2003-02-18 08:25:45 +03:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (in->history) {
|
|
|
|
|
/* Avoid duplicated entries */
|
|
|
|
|
in->history = g_list_last (in->history);
|
|
|
|
|
if (!strcmp ((char *) in->history->data, text))
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return 1;
|
2003-02-18 08:25:45 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t = g_strdup (text);
|
|
|
|
|
|
1999-08-06 23:24:04 +04:00
|
|
|
|
if (in->history_name) {
|
2003-02-18 08:25:45 +03:00
|
|
|
|
p = in->history_name + 3;
|
|
|
|
|
for (i = 0; i < ELEMENTS (password_input_fields); i++)
|
|
|
|
|
if (strcmp (p, password_input_fields[i]) == 0)
|
|
|
|
|
break;
|
|
|
|
|
if (i < ELEMENTS (password_input_fields))
|
|
|
|
|
strip_password (t, 0);
|
|
|
|
|
else
|
|
|
|
|
strip_password (t, 1);
|
1999-02-05 05:45:43 +03:00
|
|
|
|
}
|
2003-02-18 08:25:45 +03:00
|
|
|
|
|
2003-02-18 09:12:57 +03:00
|
|
|
|
in->history = list_append_unique (in->history, t);
|
2003-02-18 08:25:45 +03:00
|
|
|
|
in->need_push = 0;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
1999-08-06 23:24:04 +04:00
|
|
|
|
#undef ELEMENTS
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
/* Cleans the input line and adds the current text to the history */
|
|
|
|
|
void
|
|
|
|
|
new_input (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
if (in->buffer)
|
|
|
|
|
push_history (in, in->buffer);
|
|
|
|
|
in->need_push = 1;
|
|
|
|
|
in->buffer [0] = 0;
|
|
|
|
|
in->point = 0;
|
|
|
|
|
in->mark = 0;
|
|
|
|
|
free_completions (in);
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static cb_ret_t
|
1998-02-27 07:54:42 +03:00
|
|
|
|
insert_char (WInput *in, int c_code)
|
|
|
|
|
{
|
2004-08-16 08:17:43 +04:00
|
|
|
|
size_t i;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
if (c_code == -1)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
in->need_push = 1;
|
2004-08-16 08:17:43 +04:00
|
|
|
|
if (strlen (in->buffer)+1 == (size_t) in->current_max_len){
|
1998-02-27 07:54:42 +03:00
|
|
|
|
/* Expand the buffer */
|
2004-03-07 10:29:12 +03:00
|
|
|
|
char *narea = g_realloc (in->buffer, in->current_max_len + in->field_len);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (narea){
|
|
|
|
|
in->buffer = narea;
|
|
|
|
|
in->current_max_len += in->field_len;
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-16 08:17:43 +04:00
|
|
|
|
if (strlen (in->buffer)+1 < (size_t) in->current_max_len){
|
|
|
|
|
size_t l = strlen (&in->buffer [in->point]);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
for (i = l+1; i > 0; i--)
|
|
|
|
|
in->buffer [in->point+i] = in->buffer [in->point+i-1];
|
|
|
|
|
in->buffer [in->point] = c_code;
|
|
|
|
|
in->point++;
|
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
beginning_of_line (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
in->point = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
end_of_line (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
in->point = strlen (in->buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
backward_char (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
if (in->point)
|
|
|
|
|
in->point--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
forward_char (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
if (in->buffer [in->point])
|
|
|
|
|
in->point++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-05-11 05:16:58 +04:00
|
|
|
|
forward_word (WInput * in)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-11 05:16:58 +04:00
|
|
|
|
char *p = in->buffer + in->point;
|
2001-03-18 20:46:07 +03:00
|
|
|
|
|
2005-05-11 05:16:58 +04:00
|
|
|
|
while (*p
|
|
|
|
|
&& (isspace ((unsigned char) *p)
|
|
|
|
|
|| ispunct ((unsigned char) *p)))
|
2001-03-18 20:46:07 +03:00
|
|
|
|
p++;
|
2005-05-11 05:16:58 +04:00
|
|
|
|
while (*p && isalnum ((unsigned char) *p))
|
2001-03-18 20:46:07 +03:00
|
|
|
|
p++;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->point = p - in->buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
backward_word (WInput *in)
|
|
|
|
|
{
|
2005-05-11 05:16:58 +04:00
|
|
|
|
char *p = in->buffer + in->point;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2005-05-11 05:16:58 +04:00
|
|
|
|
while (p - 1 > in->buffer - 1 && (isspace ((unsigned char) *(p - 1))
|
|
|
|
|
|| ispunct ((unsigned char)
|
|
|
|
|
*(p - 1))))
|
2001-03-18 20:46:07 +03:00
|
|
|
|
p--;
|
2005-05-11 05:16:58 +04:00
|
|
|
|
while (p - 1 > in->buffer - 1 && isalnum ((unsigned char) *(p - 1)))
|
2001-03-18 20:46:07 +03:00
|
|
|
|
p--;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->point = p - in->buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
key_left (WInput *in)
|
|
|
|
|
{
|
2002-12-21 11:43:15 +03:00
|
|
|
|
backward_char (in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
key_ctrl_left (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
backward_word (in);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
key_right (WInput *in)
|
|
|
|
|
{
|
2002-12-21 11:43:15 +03:00
|
|
|
|
forward_char (in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
key_ctrl_right (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
forward_word (in);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
static void
|
|
|
|
|
backward_delete (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (!in->point)
|
|
|
|
|
return;
|
|
|
|
|
for (i = in->point; in->buffer [i-1]; i++)
|
|
|
|
|
in->buffer [i-1] = in->buffer [i];
|
|
|
|
|
in->need_push = 1;
|
|
|
|
|
in->point--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
delete_char (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = in->point; in->buffer [i]; i++)
|
|
|
|
|
in->buffer [i] = in->buffer [i+1];
|
|
|
|
|
in->need_push = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
copy_region (WInput *in, int x_first, int x_last)
|
|
|
|
|
{
|
|
|
|
|
int first = min (x_first, x_last);
|
|
|
|
|
int last = max (x_first, x_last);
|
|
|
|
|
|
|
|
|
|
if (last == first)
|
|
|
|
|
return;
|
|
|
|
|
|
2004-09-04 02:00:27 +04:00
|
|
|
|
g_free (kill_buffer);
|
2004-09-02 03:25:21 +04:00
|
|
|
|
|
|
|
|
|
kill_buffer = g_strndup(in->buffer+first,last-first);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
delete_region (WInput *in, int x_first, int x_last)
|
|
|
|
|
{
|
|
|
|
|
int first = min (x_first, x_last);
|
|
|
|
|
int last = max (x_first, x_last);
|
2004-09-02 03:25:21 +04:00
|
|
|
|
size_t len = strlen (&in->buffer [last]) + 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
in->point = first;
|
|
|
|
|
in->mark = first;
|
2004-09-02 03:25:21 +04:00
|
|
|
|
memmove (&in->buffer [first], &in->buffer [last], len);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->need_push = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
kill_word (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
int old_point = in->point;
|
|
|
|
|
int new_point;
|
|
|
|
|
|
|
|
|
|
forward_word (in);
|
|
|
|
|
new_point = in->point;
|
|
|
|
|
in->point = old_point;
|
|
|
|
|
|
|
|
|
|
copy_region (in, old_point, new_point);
|
|
|
|
|
delete_region (in, old_point, new_point);
|
|
|
|
|
in->need_push = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
back_kill_word (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
int old_point = in->point;
|
|
|
|
|
int new_point;
|
|
|
|
|
|
|
|
|
|
backward_word (in);
|
|
|
|
|
new_point = in->point;
|
|
|
|
|
in->point = old_point;
|
|
|
|
|
|
|
|
|
|
copy_region (in, old_point, new_point);
|
|
|
|
|
delete_region (in, old_point, new_point);
|
|
|
|
|
in->need_push = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_mark (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
in->mark = in->point;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
kill_save (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
copy_region (in, in->mark, in->point);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
kill_region (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
kill_save (in);
|
|
|
|
|
delete_region (in, in->point, in->mark);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
yank (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
if (!kill_buffer)
|
|
|
|
|
return;
|
|
|
|
|
for (p = kill_buffer; *p; p++)
|
|
|
|
|
insert_char (in, *p);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
kill_line (WInput *in)
|
|
|
|
|
{
|
2004-09-04 02:00:27 +04:00
|
|
|
|
g_free (kill_buffer);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
kill_buffer = g_strdup (&in->buffer [in->point]);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->buffer [in->point] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2004-08-17 04:00:32 +04:00
|
|
|
|
assign_text (WInput *in, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
free_completions (in);
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (in->buffer);
|
|
|
|
|
in->buffer = g_strdup (text); /* was in->buffer->text */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->current_max_len = strlen (in->buffer) + 1;
|
|
|
|
|
in->point = strlen (in->buffer);
|
|
|
|
|
in->mark = 0;
|
|
|
|
|
in->need_push = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
hist_prev (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
if (!in->history)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (in->need_push) {
|
|
|
|
|
switch (push_history (in, in->buffer)) {
|
2003-02-18 08:25:45 +03:00
|
|
|
|
case 2:
|
|
|
|
|
in->history = g_list_previous (in->history);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if (in->history->prev)
|
|
|
|
|
in->history = g_list_previous (in->history);
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
} else if (in->history->prev)
|
2003-02-18 08:25:45 +03:00
|
|
|
|
in->history = g_list_previous (in->history);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
else
|
2003-02-18 08:25:45 +03:00
|
|
|
|
return;
|
|
|
|
|
assign_text (in, (char *) in->history->data);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->need_push = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
hist_next (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
if (in->need_push) {
|
|
|
|
|
switch (push_history (in, in->buffer)) {
|
|
|
|
|
case 2:
|
|
|
|
|
assign_text (in, "");
|
|
|
|
|
return;
|
|
|
|
|
case 0:
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!in->history)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!in->history->next) {
|
|
|
|
|
assign_text (in, "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2003-02-18 08:25:45 +03:00
|
|
|
|
in->history = g_list_next (in->history);
|
|
|
|
|
assign_text (in, (char *) in->history->data);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->need_push = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-18 12:58:42 +04:00
|
|
|
|
static const struct {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int key_code;
|
|
|
|
|
void (*fn)(WInput *in);
|
|
|
|
|
} input_map [] = {
|
|
|
|
|
/* Motion */
|
1998-03-12 06:29:45 +03:00
|
|
|
|
{ XCTRL('a'), beginning_of_line },
|
|
|
|
|
{ KEY_HOME, beginning_of_line },
|
|
|
|
|
{ KEY_A1, beginning_of_line },
|
2003-06-14 09:19:19 +04:00
|
|
|
|
{ ALT ('<'), beginning_of_line },
|
1998-03-12 06:29:45 +03:00
|
|
|
|
{ XCTRL('e'), end_of_line },
|
|
|
|
|
{ KEY_END, end_of_line },
|
|
|
|
|
{ KEY_C1, end_of_line },
|
2003-06-14 09:19:19 +04:00
|
|
|
|
{ ALT ('>'), end_of_line },
|
1998-03-12 06:29:45 +03:00
|
|
|
|
{ KEY_LEFT, key_left },
|
2002-12-21 11:43:15 +03:00
|
|
|
|
{ KEY_LEFT | KEY_M_CTRL, key_ctrl_left },
|
1998-03-12 06:29:45 +03:00
|
|
|
|
{ XCTRL('b'), backward_char },
|
|
|
|
|
{ ALT('b'), backward_word },
|
|
|
|
|
{ KEY_RIGHT, key_right },
|
2002-12-21 11:43:15 +03:00
|
|
|
|
{ KEY_RIGHT | KEY_M_CTRL, key_ctrl_right },
|
1998-03-12 06:29:45 +03:00
|
|
|
|
{ XCTRL('f'), forward_char },
|
|
|
|
|
{ ALT('f'), forward_word },
|
|
|
|
|
|
|
|
|
|
/* Editing */
|
|
|
|
|
{ KEY_BACKSPACE, backward_delete },
|
|
|
|
|
{ KEY_DC, delete_char },
|
|
|
|
|
{ ALT('d'), kill_word },
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{ ALT(KEY_BACKSPACE), back_kill_word },
|
|
|
|
|
|
|
|
|
|
/* Region manipulation */
|
1998-03-12 06:29:45 +03:00
|
|
|
|
{ 0, set_mark },
|
|
|
|
|
{ XCTRL('w'), kill_region },
|
|
|
|
|
{ ALT('w'), kill_save },
|
|
|
|
|
{ XCTRL('y'), yank },
|
|
|
|
|
{ XCTRL('k'), kill_line },
|
|
|
|
|
|
|
|
|
|
/* History */
|
|
|
|
|
{ ALT('p'), hist_prev },
|
|
|
|
|
{ ALT('n'), hist_next },
|
1998-03-31 01:04:59 +04:00
|
|
|
|
{ ALT('h'), do_show_hist },
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
/* Completion */
|
|
|
|
|
{ ALT('\t'), complete },
|
|
|
|
|
|
|
|
|
|
{ 0, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* This function is a test for a special input key used in complete.c */
|
|
|
|
|
/* Returns 0 if it is not a special key, 1 if it is a non-complete key
|
|
|
|
|
and 2 if it is a complete key */
|
|
|
|
|
int
|
|
|
|
|
is_in_input_map (WInput *in, int c_code)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2005-02-09 01:33:52 +03:00
|
|
|
|
|
|
|
|
|
(void) in;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
for (i = 0; input_map [i].fn; i++)
|
1999-05-03 22:57:48 +04:00
|
|
|
|
if (c_code == input_map [i].key_code) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (input_map [i].fn == complete)
|
|
|
|
|
return 2;
|
|
|
|
|
else
|
|
|
|
|
return 1;
|
1999-05-03 22:57:48 +04:00
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
1998-05-25 02:21:56 +04:00
|
|
|
|
static void
|
|
|
|
|
port_region_marked_for_delete (WInput *in)
|
|
|
|
|
{
|
|
|
|
|
*in->buffer = 0;
|
|
|
|
|
in->point = 0;
|
|
|
|
|
in->first = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
cb_ret_t
|
1998-02-27 07:54:42 +03:00
|
|
|
|
handle_char (WInput *in, int c_code)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int v;
|
|
|
|
|
|
|
|
|
|
v = 0;
|
|
|
|
|
|
|
|
|
|
if (quote){
|
|
|
|
|
free_completions (in);
|
|
|
|
|
v = insert_char (in, c_code);
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
quote = 0;
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; input_map [i].fn; i++){
|
|
|
|
|
if (c_code == input_map [i].key_code){
|
|
|
|
|
if (input_map [i].fn != complete)
|
|
|
|
|
free_completions (in);
|
|
|
|
|
(*input_map [i].fn)(in);
|
|
|
|
|
v = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!input_map [i].fn){
|
|
|
|
|
if (c_code > 255 || !is_printable (c_code))
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (in->first){
|
1998-05-25 02:21:56 +04:00
|
|
|
|
port_region_marked_for_delete (in);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
free_completions (in);
|
|
|
|
|
v = insert_char (in, c_code);
|
|
|
|
|
}
|
|
|
|
|
if (!disable_update)
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Inserts text in input line */
|
|
|
|
|
void
|
2004-08-17 04:00:32 +04:00
|
|
|
|
stuff (WInput *in, const char *text, int insert_extra_space)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
input_disable_update (in);
|
|
|
|
|
while (*text)
|
|
|
|
|
handle_char (in, *text++);
|
|
|
|
|
if (insert_extra_space)
|
|
|
|
|
handle_char (in, ' ');
|
|
|
|
|
input_enable_update (in);
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
input_set_point (WInput *in, int pos)
|
|
|
|
|
{
|
|
|
|
|
if (pos > in->current_max_len)
|
|
|
|
|
pos = in->current_max_len;
|
|
|
|
|
if (pos != in->point)
|
|
|
|
|
free_completions (in);
|
|
|
|
|
in->point = pos;
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
cb_ret_t
|
2005-05-24 15:48:23 +04:00
|
|
|
|
input_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WInput *in = (WInput *) w;
|
2002-12-26 02:15:48 +03:00
|
|
|
|
int v;
|
2002-11-13 05:27:00 +03:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_KEY:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (parm == XCTRL ('q')) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
quote = 1;
|
|
|
|
|
v = handle_char (in, mi_getch ());
|
|
|
|
|
quote = 0;
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-12 11:50:08 +04:00
|
|
|
|
/* Keys we want others to handle */
|
|
|
|
|
if (parm == KEY_UP || parm == KEY_DOWN || parm == ESC_CHAR
|
|
|
|
|
|| parm == KEY_F (10) || parm == XCTRL ('g') || parm == '\n')
|
|
|
|
|
return MSG_NOT_HANDLED;
|
2002-12-26 02:15:48 +03:00
|
|
|
|
|
|
|
|
|
/* When pasting multiline text, insert literal Enter */
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if ((parm & ~KEY_M_MASK) == '\n') {
|
2002-12-26 02:15:48 +03:00
|
|
|
|
quote = 1;
|
|
|
|
|
v = handle_char (in, '\n');
|
|
|
|
|
quote = 0;
|
|
|
|
|
return v;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return handle_char (in, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case WIDGET_FOCUS:
|
2002-12-26 02:15:48 +03:00
|
|
|
|
case WIDGET_UNFOCUS:
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_DRAW:
|
1998-04-09 08:58:24 +04:00
|
|
|
|
update_input (in, 0);
|
2003-09-12 11:50:08 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_CURSOR:
|
|
|
|
|
widget_move (&in->widget, 0, in->point - in->first_shown);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2002-12-26 02:15:48 +03:00
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
|
input_destroy (in);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
default:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-22 01:47:29 +04:00
|
|
|
|
static int
|
2005-05-24 15:48:23 +04:00
|
|
|
|
input_event (Gpm_Event * event, void *data)
|
2002-08-22 01:47:29 +04:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WInput *in = data;
|
|
|
|
|
|
2002-08-22 01:47:29 +04:00
|
|
|
|
if (event->type & (GPM_DOWN | GPM_DRAG)) {
|
2005-05-21 00:22:06 +04:00
|
|
|
|
dlg_select_widget (in);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2002-08-22 01:47:29 +04:00
|
|
|
|
if (event->x >= in->field_len - HISTORY_BUTTON_WIDTH + 1
|
|
|
|
|
&& should_show_history_button (in)) {
|
1998-03-31 01:04:59 +04:00
|
|
|
|
do_show_hist (in);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
} else {
|
|
|
|
|
in->point = strlen (in->buffer);
|
|
|
|
|
if (event->x - in->first_shown - 1 < in->point)
|
|
|
|
|
in->point = event->x - in->first_shown - 1;
|
|
|
|
|
if (in->point < 0)
|
|
|
|
|
in->point = 0;
|
2000-05-25 20:21:42 +04:00
|
|
|
|
}
|
|
|
|
|
update_input (in, 1);
|
2002-08-22 01:47:29 +04:00
|
|
|
|
}
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
1998-03-13 08:18:52 +03:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
WInput *
|
2003-09-01 04:18:37 +04:00
|
|
|
|
input_new (int y, int x, int color, int len, const char *def_text,
|
2004-08-17 04:00:32 +04:00
|
|
|
|
const char *histname)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
WInput *in = g_new (WInput, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int initial_buffer_len;
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
init_widget (&in->widget, y, x, 1, len, input_callback, input_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
/* history setup */
|
|
|
|
|
in->history = NULL;
|
|
|
|
|
in->history_name = 0;
|
2003-09-01 04:18:37 +04:00
|
|
|
|
if (histname) {
|
|
|
|
|
if (*histname) {
|
|
|
|
|
in->history_name = g_strdup (histname);
|
|
|
|
|
in->history = history_get (histname);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
1998-03-13 08:18:52 +03:00
|
|
|
|
}
|
2003-09-01 04:18:37 +04:00
|
|
|
|
|
2000-02-03 18:00:12 +03:00
|
|
|
|
if (!def_text)
|
2000-04-18 12:58:42 +04:00
|
|
|
|
def_text = "";
|
2003-09-01 04:18:37 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (def_text == INPUT_LAST_TEXT) {
|
|
|
|
|
def_text = "";
|
|
|
|
|
if (in->history)
|
2003-02-18 08:25:45 +03:00
|
|
|
|
if (in->history->data)
|
|
|
|
|
def_text = (char *) in->history->data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2004-08-16 08:17:43 +04:00
|
|
|
|
initial_buffer_len = 1 + max ((size_t) len, strlen (def_text));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->widget.options |= W_IS_INPUT;
|
|
|
|
|
in->completions = NULL;
|
|
|
|
|
in->completion_flags =
|
|
|
|
|
INPUT_COMPLETE_FILENAMES | INPUT_COMPLETE_HOSTNAMES |
|
|
|
|
|
INPUT_COMPLETE_VARIABLES | INPUT_COMPLETE_USERNAMES;
|
|
|
|
|
in->current_max_len = initial_buffer_len;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
in->buffer = g_malloc (initial_buffer_len);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
in->color = color;
|
|
|
|
|
in->field_len = len;
|
|
|
|
|
in->first = 1;
|
|
|
|
|
in->first_shown = 0;
|
|
|
|
|
in->disable_update = 0;
|
|
|
|
|
in->mark = 0;
|
|
|
|
|
in->need_push = 1;
|
|
|
|
|
in->is_password = 0;
|
|
|
|
|
|
|
|
|
|
strcpy (in->buffer, def_text);
|
|
|
|
|
in->point = strlen (in->buffer);
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Listbox widget */
|
|
|
|
|
|
|
|
|
|
/* Should draw the scrollbar, but currently draws only
|
|
|
|
|
* indications that there is more information
|
|
|
|
|
*/
|
|
|
|
|
static int listbox_cdiff (WLEntry *s, WLEntry *e);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
listbox_drawscroll (WListbox *l)
|
|
|
|
|
{
|
|
|
|
|
int line;
|
|
|
|
|
int i, top;
|
|
|
|
|
int max_line = l->height-1;
|
|
|
|
|
|
|
|
|
|
/* Are we at the top? */
|
|
|
|
|
widget_move (&l->widget, 0, l->width);
|
|
|
|
|
if (l->list == l->top)
|
|
|
|
|
one_vline ();
|
|
|
|
|
else
|
|
|
|
|
addch ('^');
|
|
|
|
|
|
|
|
|
|
/* Are we at the bottom? */
|
|
|
|
|
widget_move (&l->widget, max_line, l->width);
|
|
|
|
|
top = listbox_cdiff (l->list, l->top);
|
|
|
|
|
if ((top + l->height == l->count) || l->height >= l->count)
|
|
|
|
|
one_vline ();
|
|
|
|
|
else
|
|
|
|
|
addch ('v');
|
|
|
|
|
|
|
|
|
|
/* Now draw the nice relative pointer */
|
|
|
|
|
if (l->count)
|
|
|
|
|
line = 1+ ((l->pos * (l->height-2)) / l->count);
|
|
|
|
|
else
|
|
|
|
|
line = 0;
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < max_line; i++){
|
|
|
|
|
widget_move (&l->widget, i, l->width);
|
|
|
|
|
if (i != line)
|
|
|
|
|
one_vline ();
|
|
|
|
|
else
|
|
|
|
|
addch ('*');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2002-11-13 05:27:00 +03:00
|
|
|
|
listbox_draw (WListbox *l, int focused)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
WLEntry *e;
|
|
|
|
|
int i;
|
|
|
|
|
int sel_line;
|
2002-11-13 05:27:00 +03:00
|
|
|
|
Dlg_head *h = l->widget.parent;
|
2000-04-18 12:58:42 +04:00
|
|
|
|
int normalc = NORMALC;
|
|
|
|
|
int selc;
|
2004-08-30 03:54:47 +04:00
|
|
|
|
const char *text;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
if (focused){
|
|
|
|
|
selc = FOCUSC;
|
|
|
|
|
} else {
|
|
|
|
|
selc = HOT_FOCUSC;
|
|
|
|
|
}
|
|
|
|
|
sel_line = -1;
|
|
|
|
|
|
|
|
|
|
for (e = l->top, i = 0; (i < l->height); i++){
|
|
|
|
|
|
|
|
|
|
/* Display the entry */
|
|
|
|
|
if (e == l->current && sel_line == -1){
|
|
|
|
|
sel_line = i;
|
|
|
|
|
attrset (selc);
|
|
|
|
|
} else
|
|
|
|
|
attrset (normalc);
|
|
|
|
|
|
|
|
|
|
widget_move (&l->widget, i, 0);
|
|
|
|
|
|
|
|
|
|
if ((i > 0 && e == l->list) || !l->list)
|
|
|
|
|
text = "";
|
|
|
|
|
else {
|
|
|
|
|
text = e->text;
|
|
|
|
|
e = e->next;
|
|
|
|
|
}
|
|
|
|
|
printw (" %-*s ", l->width-2, name_trunc (text, l->width-2));
|
|
|
|
|
}
|
|
|
|
|
l->cursor_y = sel_line;
|
|
|
|
|
if (!l->scrollbar)
|
|
|
|
|
return;
|
|
|
|
|
attrset (normalc);
|
|
|
|
|
listbox_drawscroll (l);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns the number of items between s and e,
|
|
|
|
|
must be on the same linked list */
|
|
|
|
|
static int
|
|
|
|
|
listbox_cdiff (WLEntry *s, WLEntry *e)
|
|
|
|
|
{
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
for (count = 0; s != e; count++)
|
|
|
|
|
s = s->next;
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static WLEntry *
|
|
|
|
|
listbox_check_hotkey (WListbox *l, int key)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
WLEntry *e;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
i = 0;
|
|
|
|
|
e = l->list;
|
|
|
|
|
if (!e)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
while (1) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
/* If we didn't find anything, return */
|
|
|
|
|
if (i && e == l->list)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
if (e->hotkey == key)
|
|
|
|
|
return e;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
i++;
|
|
|
|
|
e = e->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Used only for display updating, for avoiding line at a time scroll */
|
|
|
|
|
void
|
|
|
|
|
listbox_select_last (WListbox *l, int set_top)
|
|
|
|
|
{
|
|
|
|
|
if (l->list){
|
|
|
|
|
l->current = l->list->prev;
|
|
|
|
|
l->pos = l->count - 1;
|
|
|
|
|
if (set_top)
|
|
|
|
|
l->top = l->list->prev;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
listbox_remove_list (WListbox *l)
|
|
|
|
|
{
|
|
|
|
|
WLEntry *p, *q;
|
|
|
|
|
|
|
|
|
|
if (!l->count)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
p = l->list;
|
|
|
|
|
|
|
|
|
|
while (l->count--) {
|
|
|
|
|
q = p->next;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (p->text);
|
|
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
p = q;
|
|
|
|
|
}
|
|
|
|
|
l->pos = l->count = 0;
|
|
|
|
|
l->list = l->top = l->current = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* bor 30.10.96: added force flag to remove *last* entry as well
|
|
|
|
|
* bor 30.10.96: corrected selection bug if last entry was removed
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
listbox_remove_current (WListbox *l, int force)
|
|
|
|
|
{
|
|
|
|
|
WLEntry *p;
|
|
|
|
|
|
|
|
|
|
/* Ok, note: this won't allow for emtpy lists */
|
|
|
|
|
if (!force && (!l->count || l->count == 1))
|
|
|
|
|
return;
|
2001-09-16 05:22:12 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
l->count--;
|
|
|
|
|
p = l->current;
|
|
|
|
|
|
|
|
|
|
if (l->count) {
|
|
|
|
|
l->current->next->prev = l->current->prev;
|
|
|
|
|
l->current->prev->next = l->current->next;
|
|
|
|
|
if (p->next == l->list) {
|
|
|
|
|
l->current = p->prev;
|
|
|
|
|
l->pos--;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
l->current = p->next;
|
|
|
|
|
|
|
|
|
|
if (p == l->list)
|
|
|
|
|
l->list = l->top = p->next;
|
|
|
|
|
} else {
|
|
|
|
|
l->pos = 0;
|
|
|
|
|
l->list = l->top = l->current = 0;
|
|
|
|
|
}
|
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
g_free (p->text);
|
|
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Makes *e the selected entry (sets current and pos) */
|
|
|
|
|
void
|
|
|
|
|
listbox_select_entry (WListbox *l, WLEntry *dest)
|
|
|
|
|
{
|
|
|
|
|
WLEntry *e;
|
|
|
|
|
int pos;
|
|
|
|
|
int top_seen;
|
|
|
|
|
|
|
|
|
|
top_seen = 0;
|
|
|
|
|
|
|
|
|
|
/* Special case */
|
|
|
|
|
for (pos = 0, e = l->list; pos < l->count; e = e->next, pos++){
|
|
|
|
|
|
|
|
|
|
if (e == l->top)
|
|
|
|
|
top_seen = 1;
|
|
|
|
|
|
|
|
|
|
if (e == dest){
|
|
|
|
|
l->current = e;
|
|
|
|
|
if (top_seen){
|
|
|
|
|
while (listbox_cdiff (l->top, l->current) >= l->height)
|
|
|
|
|
l->top = l->top->next;
|
|
|
|
|
} else {
|
|
|
|
|
l->top = l->current;
|
|
|
|
|
}
|
|
|
|
|
l->pos = pos;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* If we are unable to find it, set decent values */
|
|
|
|
|
l->current = l->top = l->list;
|
|
|
|
|
l->pos = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Selects from base the pos element */
|
|
|
|
|
static WLEntry *
|
|
|
|
|
listbox_select_pos (WListbox *l, WLEntry *base, int pos)
|
|
|
|
|
{
|
|
|
|
|
WLEntry *last = l->list->prev;
|
|
|
|
|
|
|
|
|
|
if (base == last)
|
|
|
|
|
return last;
|
|
|
|
|
while (pos--){
|
|
|
|
|
base = base->next;
|
|
|
|
|
if (base == last)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return base;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static inline cb_ret_t
|
1998-02-27 07:54:42 +03:00
|
|
|
|
listbox_back (WListbox *l)
|
|
|
|
|
{
|
|
|
|
|
if (l->pos){
|
|
|
|
|
listbox_select_entry (l, listbox_select_pos (l, l->list, l->pos-1));
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static inline cb_ret_t
|
1998-02-27 07:54:42 +03:00
|
|
|
|
listbox_fwd (WListbox *l)
|
|
|
|
|
{
|
|
|
|
|
if (l->current != l->list->prev){
|
|
|
|
|
listbox_select_entry (l, listbox_select_pos (l, l->list, l->pos+1));
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
/* Return MSG_HANDLED if we want a redraw */
|
|
|
|
|
static cb_ret_t
|
1998-02-27 07:54:42 +03:00
|
|
|
|
listbox_key (WListbox *l, int key)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int j = 0;
|
|
|
|
|
|
|
|
|
|
if (!l->list)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
switch (key){
|
|
|
|
|
case KEY_HOME:
|
|
|
|
|
case KEY_A1:
|
2003-06-14 09:19:19 +04:00
|
|
|
|
case ALT ('<'):
|
1998-02-27 07:54:42 +03:00
|
|
|
|
l->current = l->top = l->list;
|
|
|
|
|
l->pos = 0;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case KEY_END:
|
|
|
|
|
case KEY_C1:
|
2003-06-14 09:19:19 +04:00
|
|
|
|
case ALT ('>'):
|
1998-02-27 07:54:42 +03:00
|
|
|
|
l->current = l->top = l->list->prev;
|
|
|
|
|
for (i = min (l->height - 1, l->count - 1); i; i--)
|
|
|
|
|
l->top = l->top->prev;
|
|
|
|
|
l->pos = l->count - 1;
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case XCTRL('p'):
|
|
|
|
|
case KEY_UP:
|
|
|
|
|
listbox_back (l);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case XCTRL('n'):
|
|
|
|
|
case KEY_DOWN:
|
|
|
|
|
listbox_fwd (l);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case KEY_NPAGE:
|
|
|
|
|
case XCTRL('v'):
|
|
|
|
|
for (i = 0; i < l->height-1; i++)
|
|
|
|
|
j |= listbox_fwd (l);
|
|
|
|
|
return j > 0;
|
|
|
|
|
|
|
|
|
|
case KEY_PPAGE:
|
|
|
|
|
case ALT('v'):
|
|
|
|
|
for (i = 0; i < l->height-1; i++)
|
|
|
|
|
j |= listbox_back (l);
|
|
|
|
|
return j > 0;
|
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
static void
|
|
|
|
|
listbox_destroy (WListbox *l)
|
|
|
|
|
{
|
|
|
|
|
WLEntry *n, *p = l->list;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < l->count; i++){
|
|
|
|
|
n = p->next;
|
|
|
|
|
g_free (p->text);
|
|
|
|
|
g_free (p);
|
|
|
|
|
p = n;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
static cb_ret_t
|
|
|
|
|
listbox_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WListbox *l = (WListbox *) w;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int ret_code;
|
2003-09-01 11:31:56 +04:00
|
|
|
|
WLEntry *e;
|
|
|
|
|
Dlg_head *h = l->widget.parent;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
|
|
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_INIT:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_HOTKEY:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if ((e = listbox_check_hotkey (l, parm)) != NULL) {
|
2003-09-01 11:31:56 +04:00
|
|
|
|
int action;
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
listbox_select_entry (l, e);
|
|
|
|
|
|
2003-09-01 09:58:38 +04:00
|
|
|
|
if (l->cback)
|
2003-09-01 11:31:56 +04:00
|
|
|
|
action = (*l->cback) (l);
|
|
|
|
|
else
|
|
|
|
|
action = LISTBOX_DONE;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
|
2003-09-01 11:31:56 +04:00
|
|
|
|
if (action == LISTBOX_DONE) {
|
|
|
|
|
h->ret_value = B_ENTER;
|
|
|
|
|
dlg_stop (h);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
} else
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_KEY:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if ((ret_code = listbox_key (l, parm)))
|
2002-11-13 05:27:00 +03:00
|
|
|
|
listbox_draw (l, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return ret_code;
|
|
|
|
|
|
|
|
|
|
case WIDGET_CURSOR:
|
|
|
|
|
widget_move (&l->widget, l->cursor_y, 0);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_FOCUS:
|
|
|
|
|
case WIDGET_UNFOCUS:
|
|
|
|
|
case WIDGET_DRAW:
|
2002-11-13 05:27:00 +03:00
|
|
|
|
listbox_draw (l, msg != WIDGET_UNFOCUS);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
|
listbox_destroy (l);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
|
|
|
|
default:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2005-05-24 15:48:23 +04:00
|
|
|
|
listbox_event (Gpm_Event *event, void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WListbox *l = data;
|
|
|
|
|
Widget *w = data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int i;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
Dlg_head *h = l->widget.parent;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
/* Single click */
|
|
|
|
|
if (event->type & GPM_DOWN)
|
2005-05-21 00:22:06 +04:00
|
|
|
|
dlg_select_widget (l);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!l->list)
|
|
|
|
|
return MOU_NORMAL;
|
2003-09-01 09:58:38 +04:00
|
|
|
|
if (event->type & (GPM_DOWN | GPM_DRAG)) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (event->x < 0 || event->x >= l->width)
|
|
|
|
|
return MOU_REPEAT;
|
|
|
|
|
if (event->y < 1)
|
|
|
|
|
for (i = -event->y; i >= 0; i--)
|
|
|
|
|
listbox_back (l);
|
|
|
|
|
else if (event->y > l->height)
|
|
|
|
|
for (i = event->y - l->height; i > 0; i--)
|
|
|
|
|
listbox_fwd (l);
|
|
|
|
|
else
|
2003-09-01 09:58:38 +04:00
|
|
|
|
listbox_select_entry (l,
|
|
|
|
|
listbox_select_pos (l, l->top,
|
|
|
|
|
event->y - 1));
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
/* We need to refresh ourselves since the dialog manager doesn't */
|
|
|
|
|
/* know about this event */
|
2005-05-24 15:48:23 +04:00
|
|
|
|
listbox_callback (w, WIDGET_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
mc_refresh ();
|
|
|
|
|
return MOU_REPEAT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Double click */
|
2003-09-01 09:58:38 +04:00
|
|
|
|
if ((event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE)) {
|
2003-09-01 11:31:56 +04:00
|
|
|
|
int action;
|
|
|
|
|
|
2003-09-01 09:58:38 +04:00
|
|
|
|
if (event->x < 0 || event->x >= l->width)
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
if (event->y < 1 || event->y > l->height)
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
|
2005-05-21 00:22:06 +04:00
|
|
|
|
dlg_select_widget (l);
|
2003-09-01 09:58:38 +04:00
|
|
|
|
listbox_select_entry (l,
|
|
|
|
|
listbox_select_pos (l, l->top,
|
|
|
|
|
event->y - 1));
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-01 09:58:38 +04:00
|
|
|
|
if (l->cback)
|
2003-09-01 11:31:56 +04:00
|
|
|
|
action = (*l->cback) (l);
|
|
|
|
|
else
|
|
|
|
|
action = LISTBOX_DONE;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-01 11:31:56 +04:00
|
|
|
|
if (action == LISTBOX_DONE) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
h->ret_value = B_ENTER;
|
1998-03-14 03:42:23 +03:00
|
|
|
|
dlg_stop (h);
|
2002-09-22 09:49:17 +04:00
|
|
|
|
return MOU_NORMAL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WListbox *
|
2003-09-01 11:31:56 +04:00
|
|
|
|
listbox_new (int y, int x, int width, int height, lcback callback)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
WListbox *l = g_new (WListbox, 1);
|
2003-09-01 03:29:49 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
init_widget (&l->widget, y, x, height, width,
|
2005-05-24 15:48:23 +04:00
|
|
|
|
listbox_callback, listbox_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-01 03:29:49 +04:00
|
|
|
|
l->list = l->top = l->current = 0;
|
|
|
|
|
l->pos = 0;
|
|
|
|
|
l->width = width;
|
1999-01-02 21:16:09 +03:00
|
|
|
|
if (height <= 0)
|
2003-09-01 03:29:49 +04:00
|
|
|
|
l->height = 1;
|
1999-01-06 22:47:24 +03:00
|
|
|
|
else
|
2003-09-01 03:29:49 +04:00
|
|
|
|
l->height = height;
|
|
|
|
|
l->count = 0;
|
|
|
|
|
l->top = 0;
|
|
|
|
|
l->current = 0;
|
|
|
|
|
l->cback = callback;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
l->allow_duplicates = 1;
|
|
|
|
|
l->scrollbar = slow_terminal ? 0 : 1;
|
|
|
|
|
widget_want_hotkey (l->widget, 1);
|
2003-09-01 03:29:49 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Listbox item adding function. They still lack a lot of functionality */
|
|
|
|
|
/* any takers? */
|
|
|
|
|
/* 1.11.96 bor: added pos argument to control placement of new entry */
|
|
|
|
|
static void
|
|
|
|
|
listbox_append_item (WListbox *l, WLEntry *e, enum append_pos pos)
|
|
|
|
|
{
|
|
|
|
|
if (!l->list){
|
|
|
|
|
l->list = e;
|
|
|
|
|
l->top = e;
|
|
|
|
|
l->current = e;
|
|
|
|
|
e->next = l->list;
|
|
|
|
|
e->prev = l->list;
|
|
|
|
|
} else if (pos == LISTBOX_APPEND_AT_END) {
|
|
|
|
|
e->next = l->list;
|
|
|
|
|
e->prev = l->list->prev;
|
|
|
|
|
l->list->prev->next = e;
|
|
|
|
|
l->list->prev = e;
|
|
|
|
|
} else if (pos == LISTBOX_APPEND_BEFORE){
|
|
|
|
|
e->next = l->current;
|
|
|
|
|
e->prev = l->current->prev;
|
|
|
|
|
l->current->prev->next = e;
|
|
|
|
|
l->current->prev = e;
|
|
|
|
|
if (l->list == l->current) { /* move list one position down */
|
|
|
|
|
l->list = e;
|
|
|
|
|
l->top = e;
|
|
|
|
|
}
|
|
|
|
|
} else if (pos == LISTBOX_APPEND_AFTER) {
|
|
|
|
|
e->prev = l->current;
|
|
|
|
|
e->next = l->current->next;
|
|
|
|
|
l->current->next->prev = e;
|
|
|
|
|
l->current->next = e;
|
|
|
|
|
}
|
|
|
|
|
l->count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
2003-10-30 19:43:22 +03:00
|
|
|
|
listbox_add_item (WListbox *l, enum append_pos pos, int hotkey,
|
|
|
|
|
const char *text, void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
WLEntry *entry;
|
|
|
|
|
|
|
|
|
|
if (!l)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
if (!l->allow_duplicates)
|
|
|
|
|
if (listbox_search_text (l, text))
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
entry = g_new (WLEntry, 1);
|
|
|
|
|
entry->text = g_strdup (text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
entry->data = data;
|
|
|
|
|
entry->hotkey = hotkey;
|
|
|
|
|
|
|
|
|
|
listbox_append_item (l, entry, pos);
|
|
|
|
|
|
|
|
|
|
return entry->text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Selects the nth entry in the listbox */
|
|
|
|
|
void
|
|
|
|
|
listbox_select_by_number (WListbox *l, int n)
|
|
|
|
|
{
|
|
|
|
|
listbox_select_entry (l, listbox_select_pos (l, l->list, n));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WLEntry *
|
2003-10-30 19:43:22 +03:00
|
|
|
|
listbox_search_text (WListbox *l, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
WLEntry *e;
|
|
|
|
|
|
|
|
|
|
e = l->list;
|
|
|
|
|
if (!e)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if(!strcmp (e->text, text))
|
|
|
|
|
return e;
|
|
|
|
|
e = e->next;
|
|
|
|
|
} while (e!=l->list);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Returns the current string text as well as the associated extra data */
|
|
|
|
|
void
|
|
|
|
|
listbox_get_current (WListbox *l, char **string, char **extra)
|
|
|
|
|
{
|
|
|
|
|
if (!l->current){
|
|
|
|
|
*string = 0;
|
|
|
|
|
*extra = 0;
|
|
|
|
|
}
|
|
|
|
|
if (string && l->current)
|
|
|
|
|
*string = l->current->text;
|
|
|
|
|
if (extra && l->current)
|
|
|
|
|
*extra = l->current->data;
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
static cb_ret_t
|
|
|
|
|
buttonbar_callback (Widget *w, widget_msg_t msg, int parm)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WButtonBar *bb = (WButtonBar *) w;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int i;
|
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
switch (msg) {
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_FOCUS:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
case WIDGET_HOTKEY:
|
2003-09-10 22:21:40 +04:00
|
|
|
|
for (i = 0; i < 10; i++) {
|
2003-09-11 02:48:54 +04:00
|
|
|
|
if (parm == KEY_F (i + 1) && bb->labels[i].function) {
|
2003-09-10 22:21:40 +04:00
|
|
|
|
(*bb->labels[i].function) (bb->labels[i].data);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_NOT_HANDLED;
|
2003-09-10 22:21:40 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
case WIDGET_DRAW:
|
|
|
|
|
if (!bb->visible)
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
widget_move (&bb->widget, 0, 0);
|
|
|
|
|
attrset (DEFAULT_COLOR);
|
2002-08-22 02:52:29 +04:00
|
|
|
|
printw ("%-*s", bb->widget.cols, "");
|
2003-09-10 22:21:40 +04:00
|
|
|
|
for (i = 0; i < COLS / 8 && i < 10; i++) {
|
|
|
|
|
widget_move (&bb->widget, 0, i * 8);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
attrset (DEFAULT_COLOR);
|
2003-09-10 22:21:40 +04:00
|
|
|
|
printw ("%d", i + 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
attrset (SELECTED_COLOR);
|
2003-09-10 22:21:40 +04:00
|
|
|
|
printw ("%-*s", ((i + 1) * 8 == COLS ? 5 : 6),
|
|
|
|
|
bb->labels[i].text ? bb->labels[i].text : "");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
attrset (DEFAULT_COLOR);
|
|
|
|
|
}
|
|
|
|
|
attrset (SELECTED_COLOR);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
|
for (i = 0; i < 10; i++)
|
|
|
|
|
g_free (bb->labels[i].text);
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return MSG_HANDLED;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
default:
|
2003-09-11 02:48:54 +04:00
|
|
|
|
return default_proc (msg, parm);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2005-05-24 15:48:23 +04:00
|
|
|
|
buttonbar_event (Gpm_Event *event, void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WButtonBar *bb = data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
int button;
|
|
|
|
|
|
|
|
|
|
if (!(event->type & GPM_UP))
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
if (event->y == 2)
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
button = event->x / 8;
|
|
|
|
|
if (button < 10 && bb->labels [button].function)
|
|
|
|
|
(*bb->labels [button].function)(bb->labels [button].data);
|
|
|
|
|
return MOU_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WButtonBar *
|
|
|
|
|
buttonbar_new (int visible)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
Glibing..... (2)
Wed Jan 27 03:17:44 1999 Timur Bakeyev <mc@bat.ru>
* Converted memory managment to Glib. Now we use g_new()/g_malloc()/
g_strdup()/g_free() routings. Also, copy_strings() replaced by
g_strconcat(), strcasecmp() -> g_strcasecmp(),and sprintf() by
g_snprintf().
* Some sequences of malloc()/sprintf() changed to g_strdup_printf().
* mad.[ch]: Modified, to work with new GLib's memory managment. Fixed
a missing #undef for tempnam, which caused dead loop. Add several new
functions to emulate GLib memory managment.
*main.c, mad.[ch]: Add a new switch "-M", which allows to redirect MAD
messages to the file.
* util.[ch], utilunix.c: Modified, deleted our variants of strcasecmp()
and strdup() - we have g_ equivalences. Remove get_full_name() - it is
similar to concat_dir_and_file(). Some other tricks with g_* functions.
* global.h: Modified, extended. Now it is main memory mangment include -
i.e. all inclusions of <stdlib.h>, <malloc.h>, <glib.h>, "fs.h", "mem.h",
"util.h" and "mad.h" done there. This elimanates problem with proper or-
der of #include's.
* All around the source - changed order of #include's, most of them gone
to global.h (see above), minor changes, like "0" -> NULL in string func-
tions.
1999-01-27 04:08:30 +03:00
|
|
|
|
WButtonBar *bb = g_new (WButtonBar, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
init_widget (&bb->widget, LINES-1, 0, 1, COLS,
|
2005-05-24 15:48:23 +04:00
|
|
|
|
buttonbar_callback, buttonbar_event);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
|
|
bb->visible = visible;
|
|
|
|
|
for (i = 0; i < 10; i++){
|
|
|
|
|
bb->labels [i].text = 0;
|
|
|
|
|
bb->labels [i].function = 0;
|
|
|
|
|
}
|
|
|
|
|
widget_want_hotkey (bb->widget, 1);
|
|
|
|
|
widget_want_cursor (bb->widget, 0);
|
|
|
|
|
|
|
|
|
|
return bb;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-22 01:47:29 +04:00
|
|
|
|
static void
|
2004-08-16 08:17:43 +04:00
|
|
|
|
set_label_text (WButtonBar * bb, int index, const char *text)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2004-09-25 02:22:35 +04:00
|
|
|
|
g_free (bb->labels[index - 1].text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2002-08-22 01:47:29 +04:00
|
|
|
|
bb->labels[index - 1].text = g_strdup (text);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-13 02:33:15 +03:00
|
|
|
|
/* Find ButtonBar widget in the dialog */
|
|
|
|
|
WButtonBar *
|
|
|
|
|
find_buttonbar (Dlg_head *h)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
|
|
|
|
WButtonBar *bb;
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
bb = (WButtonBar *) find_widget_type (h, buttonbar_callback);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
return bb;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2005-02-08 12:40:52 +03:00
|
|
|
|
buttonbar_set_label_data (Dlg_head *h, int idx, const char *text, buttonbarfn cback,
|
2002-11-13 02:33:15 +03:00
|
|
|
|
void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2002-11-13 02:33:15 +03:00
|
|
|
|
WButtonBar *bb = find_buttonbar (h);
|
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
if (!bb)
|
|
|
|
|
return;
|
2002-08-22 01:47:29 +04:00
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
set_label_text (bb, idx, text);
|
2002-08-22 01:47:29 +04:00
|
|
|
|
bb->labels[idx - 1].function = cback;
|
|
|
|
|
bb->labels[idx - 1].data = data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2005-02-08 12:40:52 +03:00
|
|
|
|
buttonbar_set_label (Dlg_head *h, int idx, const char *text, void (*cback) (void))
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
buttonbar_set_label_data (h, idx, text, cback, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2005-02-08 12:40:52 +03:00
|
|
|
|
buttonbar_redraw (Dlg_head *h)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
{
|
2002-11-13 02:33:15 +03:00
|
|
|
|
WButtonBar *bb = find_buttonbar (h);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
2002-11-13 02:33:15 +03:00
|
|
|
|
if (!bb)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-11-13 05:56:40 +03:00
|
|
|
|
send_message ((Widget *) bb, WIDGET_DRAW, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
}
|
2001-09-16 05:22:12 +04:00
|
|
|
|
|
2003-09-11 02:48:54 +04:00
|
|
|
|
static cb_ret_t
|
2005-05-24 15:48:23 +04:00
|
|
|
|
groupbox_callback (Widget *w, widget_msg_t msg, int parm)
|
2003-09-08 02:42:22 +04:00
|
|
|
|
{
|
2005-05-24 15:48:23 +04:00
|
|
|
|
WGroupbox *g = (WGroupbox *) w;
|
|
|
|
|
|
2003-09-08 02:42:22 +04:00
|
|
|
|
switch (msg) {
|
|
|
|
|
case WIDGET_INIT:
|
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
|
|
|
|
case WIDGET_FOCUS:
|
|
|
|
|
return MSG_NOT_HANDLED;
|
|
|
|
|
|
|
|
|
|
case WIDGET_DRAW:
|
|
|
|
|
attrset (COLOR_NORMAL);
|
|
|
|
|
draw_box (g->widget.parent, g->widget.y - g->widget.parent->y,
|
|
|
|
|
g->widget.x - g->widget.parent->x, g->widget.lines,
|
|
|
|
|
g->widget.cols);
|
|
|
|
|
|
|
|
|
|
attrset (COLOR_HOT_NORMAL);
|
|
|
|
|
dlg_move (g->widget.parent, g->widget.y - g->widget.parent->y,
|
|
|
|
|
g->widget.x - g->widget.parent->x + 1);
|
|
|
|
|
addstr (g->title);
|
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
2003-09-10 22:21:40 +04:00
|
|
|
|
case WIDGET_DESTROY:
|
|
|
|
|
g_free (g->title);
|
|
|
|
|
return MSG_HANDLED;
|
|
|
|
|
|
2003-09-08 02:42:22 +04:00
|
|
|
|
default:
|
|
|
|
|
return default_proc (msg, parm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WGroupbox *
|
2004-08-29 20:42:40 +04:00
|
|
|
|
groupbox_new (int x, int y, int width, int height, const char *title)
|
2003-09-08 02:42:22 +04:00
|
|
|
|
{
|
|
|
|
|
WGroupbox *g = g_new (WGroupbox, 1);
|
|
|
|
|
|
2005-05-24 15:48:23 +04:00
|
|
|
|
init_widget (&g->widget, y, x, height, width, groupbox_callback, NULL);
|
2003-09-08 02:42:22 +04:00
|
|
|
|
|
|
|
|
|
g->widget.options &= ~W_WANT_CURSOR;
|
|
|
|
|
widget_want_hotkey (g->widget, 0);
|
|
|
|
|
|
|
|
|
|
/* Strip existing spaces, add one space before and after the title */
|
|
|
|
|
if (title) {
|
|
|
|
|
char *t;
|
|
|
|
|
t = g_strstrip (g_strdup (title));
|
2004-09-24 19:05:28 +04:00
|
|
|
|
g->title = g_strconcat (" ", t, " ", (char *) NULL);
|
2003-09-08 02:42:22 +04:00
|
|
|
|
g_free (t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g;
|
|
|
|
|
}
|