1 /* User interface for charset selection.
3 Copyright (C) 2001 Walery Studennikov <despair@sama.ru>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 /** \file selcodepage.c
21 * \brief Source: user %interface for charset %selection
31 #include "lib/global.h"
32 #include "lib/widget.h"
33 #include "lib/charsets.h"
37 #include "selcodepage.h"
39 /*** global variables ****************************************************************************/
41 /*** file scope macro definitions ****************************************************************/
45 /*** file scope type declarations ****************************************************************/
47 /*** file scope variables ************************************************************************/
49 /*** file scope functions ************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
56 return (n
<= 9) ? '0' + n
: 'a' + n
- 10;
59 /* --------------------------------------------------------------------------------------------- */
60 /*** public functions ****************************************************************************/
61 /* --------------------------------------------------------------------------------------------- */
64 * -2 (SELECT_CHARSET_CANCEL) : Cancel
65 * -1 (SELECT_CHARSET_OTHER_8BIT) : "Other 8 bit" if seldisplay == TRUE
66 * -1 (SELECT_CHARSET_NO_TRANSLATE) : "No translation" if seldisplay == FALSE
67 * >= 0 : charset number
70 select_charset (int center_y
, int center_x
, int current_charset
, gboolean seldisplay
)
77 Listbox
*listbox
= create_listbox_window_centered (center_y
, center_x
,
78 codepages
->len
+ 1, ENTRY_LEN
+ 2,
80 "[Codepages Translation]");
83 LISTBOX_APPEND_TEXT (listbox
, '-', _("- < No translation >"), NULL
);
85 /* insert all the items found */
86 for (i
= 0; i
< codepages
->len
; i
++)
88 const char *name
= ((codepage_desc
*) g_ptr_array_index (codepages
, i
))->name
;
89 g_snprintf (buffer
, sizeof (buffer
), "%c %s", get_hotkey (i
), name
);
90 LISTBOX_APPEND_TEXT (listbox
, get_hotkey (i
), buffer
, NULL
);
94 unsigned char hotkey
= get_hotkey (codepages
->len
);
95 g_snprintf (buffer
, sizeof (buffer
), "%c %s", hotkey
, _("Other 8 bit"));
96 LISTBOX_APPEND_TEXT (listbox
, hotkey
, buffer
, NULL
);
99 /* Select the default entry */
101 ? ((current_charset
< 0) ? codepages
->len
: (size_t) current_charset
)
102 : ((size_t) current_charset
+ 1);
104 listbox_select_entry (listbox
->list
, i
);
106 listbox_result
= run_listbox (listbox
);
108 if (listbox_result
< 0)
111 return SELECT_CHARSET_CANCEL
;
115 /* some charset has been selected */
118 /* charset list is finished with "Other 8 bit" item */
119 return (listbox_result
>= (int) codepages
->len
)
120 ? SELECT_CHARSET_OTHER_8BIT
: listbox_result
;
124 /* charset list is began with "- < No translation >" item */
125 return (listbox_result
- 1);
131 /* --------------------------------------------------------------------------------------------- */
134 do_set_codepage (int codepage
)
139 source_codepage
= codepage
;
140 errmsg
= init_translation_table (codepage
== SELECT_CHARSET_NO_TRANSLATE
?
141 display_codepage
: source_codepage
, display_codepage
);
142 ret
= errmsg
== NULL
;
146 message (D_ERROR
, MSG_ERROR
, "%s", errmsg
);
153 /* --------------------------------------------------------------------------------------------- */
154 /** Show menu selecting codepage */
157 do_select_codepage (void)
161 r
= select_charset (-1, -1, default_source_codepage
, FALSE
);
162 if (r
== SELECT_CHARSET_CANCEL
)
165 default_source_codepage
= r
;
166 return do_set_codepage (default_source_codepage
);
169 /* --------------------------------------------------------------------------------------------- */
171 #endif /* HAVE_CHARSET */