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/>.
31 /** \file listbox-window.c
32 * \brief Source: Listbox widget, a listbox within dialog window
39 #include "lib/global.h"
40 #include "lib/tty/tty.h" /* COLS */
42 #include "lib/strutil.h" /* str_term_width1() */
43 #include "lib/widget.h"
45 /*** global variables ****************************************************************************/
47 /*** file scope macro definitions ****************************************************************/
49 /*** file scope type declarations ****************************************************************/
51 /*** file scope variables ************************************************************************/
53 /*** file scope functions ************************************************************************/
55 /* --------------------------------------------------------------------------------------------- */
56 /*** public functions ****************************************************************************/
57 /* --------------------------------------------------------------------------------------------- */
60 create_listbox_window_centered (int center_y
, int center_x
, int lines
, int cols
,
61 const char *title
, const char *help
)
63 const dlg_colors_t listbox_colors
= {
77 lines
= min (lines
, LINES
- 6);
81 len
= str_term_width1 (title
) + 4;
82 cols
= max (cols
, len
);
85 cols
= min (cols
, COLS
- 6);
88 if ((center_y
< 0) || (center_x
< 0))
102 if (ypos
+ lines
>= LINES
)
103 ypos
= LINES
- lines
- space
;
107 if (xpos
+ cols
>= COLS
)
108 xpos
= COLS
- cols
- space
;
112 listbox
= g_new (Listbox
, 1);
115 create_dlg (TRUE
, ypos
, xpos
, lines
+ space
, cols
+ space
,
116 listbox_colors
, NULL
, help
, title
, DLG_REVERSE
| DLG_TRYUP
);
118 listbox
->list
= listbox_new (2, 2, lines
, cols
, FALSE
, NULL
);
119 add_widget (listbox
->dlg
, listbox
->list
);
124 /* --------------------------------------------------------------------------------------------- */
127 create_listbox_window (int lines
, int cols
, const char *title
, const char *help
)
129 return create_listbox_window_centered (-1, -1, lines
, cols
, title
, help
);
132 /* --------------------------------------------------------------------------------------------- */
134 /** Returns the number of the item selected */
136 run_listbox (Listbox
* l
)
140 if (run_dlg (l
->dlg
) != B_CANCEL
)
142 destroy_dlg (l
->dlg
);
147 /* --------------------------------------------------------------------------------------------- */