1 /* Widget based utility functions.
2 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 Authors: 1994, 1995, 1996 Miguel de Icaza
6 1994, 1995 Radek Doulik
9 2009, 2010 Andrew Borodin
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 * \brief Source: quick dialog engine
34 #include <stdio.h> /* fprintf() */
36 #include "lib/global.h"
37 #include "lib/util.h" /* tilde_expand() */
38 #include "lib/widget.h"
40 /*** global variables ****************************************************************************/
42 /*** file scope macro definitions ****************************************************************/
44 /*** file scope type declarations ****************************************************************/
46 /*** file scope variables ************************************************************************/
48 /*** file scope functions ************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
51 /*** public functions ****************************************************************************/
52 /* --------------------------------------------------------------------------------------------- */
55 quick_dialog_skip (QuickDialog
* qd
, int nskip
)
58 #define I18N(x) (x = !qd->i18n && x != NULL && *x != '\0' ? _(x): x)
60 #define I18N(x) (x = x)
70 if ((qd
->xpos
== -1) || (qd
->ypos
== -1))
71 dd
= create_dlg (TRUE
, 0, 0, qd
->ylen
, qd
->xlen
,
72 dialog_colors
, qd
->callback
, qd
->help
, qd
->title
,
73 DLG_CENTER
| DLG_TRYUP
| DLG_REVERSE
);
75 dd
= create_dlg (TRUE
, qd
->ypos
, qd
->xpos
, qd
->ylen
, qd
->xlen
,
76 dialog_colors
, qd
->callback
, qd
->help
, qd
->title
, DLG_REVERSE
);
78 for (qw
= qd
->widgets
; qw
->widget_type
!= quick_end
; qw
++)
83 xpos
= (qd
->xlen
* qw
->relative_x
) / qw
->x_divisions
;
84 ypos
= (qd
->ylen
* qw
->relative_y
) / qw
->y_divisions
;
86 switch (qw
->widget_type
)
90 (Widget
*) check_new (ypos
, xpos
, *qw
->u
.checkbox
.state
,
91 I18N (qw
->u
.checkbox
.text
));
95 qw
->widget
= (Widget
*) button_new (ypos
, xpos
, qw
->u
.button
.action
,
96 (qw
->u
.button
.action
==
97 B_ENTER
) ? DEFPUSH_BUTTON
: NORMAL_BUTTON
,
98 I18N (qw
->u
.button
.text
), qw
->u
.button
.callback
);
102 in
= input_new (ypos
, xpos
, input_get_default_colors (),
103 qw
->u
.input
.len
, qw
->u
.input
.text
, qw
->u
.input
.histname
,
104 INPUT_COMPLETE_DEFAULT
);
105 in
->is_password
= (qw
->u
.input
.flags
== 1);
106 if ((qw
->u
.input
.flags
& 2) != 0)
107 in
->completion_flags
|= INPUT_COMPLETE_CD
;
108 qw
->widget
= (Widget
*) in
;
109 *qw
->u
.input
.result
= NULL
;
113 qw
->widget
= (Widget
*) label_new (ypos
, xpos
, I18N (qw
->u
.label
.text
));
117 qw
->widget
= (Widget
*) groupbox_new (ypos
, xpos
,
118 qw
->u
.groupbox
.height
,
119 qw
->u
.groupbox
.width
,
120 I18N (qw
->u
.groupbox
.title
));
128 /* create the copy of radio_items to avoid mwmory leak */
129 items
= g_new0 (char *, qw
->u
.radio
.count
+ 1);
132 for (i
= 0; i
< qw
->u
.radio
.count
; i
++)
133 items
[i
] = g_strdup (_(qw
->u
.radio
.items
[i
]));
135 for (i
= 0; i
< qw
->u
.radio
.count
; i
++)
136 items
[i
] = g_strdup (qw
->u
.radio
.items
[i
]);
138 r
= radio_new (ypos
, xpos
, qw
->u
.radio
.count
, (const char **) items
);
139 r
->pos
= r
->sel
= *qw
->u
.radio
.value
;
140 qw
->widget
= (Widget
*) r
;
147 fprintf (stderr
, "QuickWidget: unknown widget type\n");
151 if (qw
->widget
!= NULL
)
153 qw
->widget
->options
|= qw
->options
; /* FIXME: cannot reset flags, setup only */
154 add_widget (dd
, qw
->widget
);
160 dd
->current
= g_list_next (dd
->current
);
161 if (dd
->current
== NULL
)
162 dd
->current
= dd
->widgets
;
165 return_val
= run_dlg (dd
);
167 /* Get the data if we found something interesting */
168 if (return_val
!= B_CANCEL
)
170 for (qw
= qd
->widgets
; qw
->widget_type
!= quick_end
; qw
++)
172 switch (qw
->widget_type
)
175 *qw
->u
.checkbox
.state
= ((WCheck
*) qw
->widget
)->state
& C_BOOL
;
179 if ((qw
->u
.input
.flags
& 2) != 0)
180 *qw
->u
.input
.result
= tilde_expand (((WInput
*) qw
->widget
)->buffer
);
182 *qw
->u
.input
.result
= g_strdup (((WInput
*) qw
->widget
)->buffer
);
186 *qw
->u
.radio
.value
= ((WRadio
*) qw
->widget
)->sel
;
201 /* --------------------------------------------------------------------------------------------- */