2 Widget based utility functions.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2008, 2009, 2010, 2011
6 The Free Software Foundation, Inc.
9 Miguel de Icaza, 1994, 1995, 1996
10 Radek Doulik, 1994, 1995
12 Andrej Borsenkow, 1995
13 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
15 This file is part of the Midnight Commander.
17 The Midnight Commander is free software: you can redistribute it
18 and/or modify it under the terms of the GNU General Public License as
19 published by the Free Software Foundation, either version 3 of the License,
20 or (at your option) any later version.
22 The Midnight Commander is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
27 You should have received a copy of the GNU General Public License
28 along with this program. If not, see <http://www.gnu.org/licenses/>.
32 * \brief Source: quick dialog engine
38 #include <stdio.h> /* fprintf() */
40 #include "lib/global.h"
41 #include "lib/util.h" /* tilde_expand() */
42 #include "lib/widget.h"
44 /*** global variables ****************************************************************************/
46 /*** file scope macro definitions ****************************************************************/
48 /*** file scope type declarations ****************************************************************/
50 /*** file scope variables ************************************************************************/
52 /*** file scope functions ************************************************************************/
54 /* --------------------------------------------------------------------------------------------- */
55 /*** public functions ****************************************************************************/
56 /* --------------------------------------------------------------------------------------------- */
59 quick_dialog_skip (QuickDialog
* qd
, int nskip
)
62 #define I18N(x) (x = !qd->i18n && x != NULL && *x != '\0' ? _(x): x)
64 #define I18N(x) (x = x)
74 if ((qd
->xpos
== -1) || (qd
->ypos
== -1))
75 dd
= create_dlg (TRUE
, 0, 0, qd
->ylen
, qd
->xlen
,
76 dialog_colors
, qd
->callback
, qd
->help
, qd
->title
,
77 DLG_CENTER
| DLG_TRYUP
| DLG_REVERSE
);
79 dd
= create_dlg (TRUE
, qd
->ypos
, qd
->xpos
, qd
->ylen
, qd
->xlen
,
80 dialog_colors
, qd
->callback
, qd
->help
, qd
->title
, DLG_REVERSE
);
82 for (qw
= qd
->widgets
; qw
->widget_type
!= quick_end
; qw
++)
87 xpos
= (qd
->xlen
* qw
->relative_x
) / qw
->x_divisions
;
88 ypos
= (qd
->ylen
* qw
->relative_y
) / qw
->y_divisions
;
90 switch (qw
->widget_type
)
94 (Widget
*) check_new (ypos
, xpos
, *qw
->u
.checkbox
.state
,
95 I18N (qw
->u
.checkbox
.text
));
99 qw
->widget
= (Widget
*) button_new (ypos
, xpos
, qw
->u
.button
.action
,
100 (qw
->u
.button
.action
==
101 B_ENTER
) ? DEFPUSH_BUTTON
: NORMAL_BUTTON
,
102 I18N (qw
->u
.button
.text
), qw
->u
.button
.callback
);
106 in
= input_new (ypos
, xpos
, input_get_default_colors (),
107 qw
->u
.input
.len
, qw
->u
.input
.text
, qw
->u
.input
.histname
,
108 INPUT_COMPLETE_DEFAULT
);
109 in
->is_password
= (qw
->u
.input
.flags
== 1);
110 if ((qw
->u
.input
.flags
& 2) != 0)
111 in
->completion_flags
|= INPUT_COMPLETE_CD
;
112 if ((qw
->u
.input
.flags
& 4) != 0)
113 in
->strip_password
= TRUE
;
114 qw
->widget
= (Widget
*) in
;
115 *qw
->u
.input
.result
= NULL
;
119 qw
->widget
= (Widget
*) label_new (ypos
, xpos
, I18N (qw
->u
.label
.text
));
123 qw
->widget
= (Widget
*) groupbox_new (ypos
, xpos
,
124 qw
->u
.groupbox
.height
,
125 qw
->u
.groupbox
.width
,
126 I18N (qw
->u
.groupbox
.title
));
134 /* create the copy of radio_items to avoid mwmory leak */
135 items
= g_new0 (char *, qw
->u
.radio
.count
+ 1);
138 for (i
= 0; i
< qw
->u
.radio
.count
; i
++)
139 items
[i
] = g_strdup (_(qw
->u
.radio
.items
[i
]));
141 for (i
= 0; i
< qw
->u
.radio
.count
; i
++)
142 items
[i
] = g_strdup (qw
->u
.radio
.items
[i
]);
144 r
= radio_new (ypos
, xpos
, qw
->u
.radio
.count
, (const char **) items
);
145 r
->pos
= r
->sel
= *qw
->u
.radio
.value
;
146 qw
->widget
= (Widget
*) r
;
153 fprintf (stderr
, "QuickWidget: unknown widget type\n");
157 if (qw
->widget
!= NULL
)
159 qw
->widget
->options
|= qw
->options
; /* FIXME: cannot reset flags, setup only */
160 add_widget (dd
, qw
->widget
);
166 dd
->current
= g_list_next (dd
->current
);
167 if (dd
->current
== NULL
)
168 dd
->current
= dd
->widgets
;
171 return_val
= run_dlg (dd
);
173 /* Get the data if we found something interesting */
174 if (return_val
!= B_CANCEL
)
176 for (qw
= qd
->widgets
; qw
->widget_type
!= quick_end
; qw
++)
178 switch (qw
->widget_type
)
181 *qw
->u
.checkbox
.state
= ((WCheck
*) qw
->widget
)->state
& C_BOOL
;
185 if ((qw
->u
.input
.flags
& 2) != 0)
186 *qw
->u
.input
.result
= tilde_expand (((WInput
*) qw
->widget
)->buffer
);
188 *qw
->u
.input
.result
= g_strdup (((WInput
*) qw
->widget
)->buffer
);
192 *qw
->u
.radio
.value
= ((WRadio
*) qw
->widget
)->sel
;
207 /* --------------------------------------------------------------------------------------------- */