2002-08-27 09:27:11 +04:00
|
|
|
/* User interface for charset selection.
|
|
|
|
|
|
|
|
Copyright (C) 2001 Walery Studennikov <despair@sama.ru>
|
|
|
|
|
|
|
|
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
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2001-06-01 03:56:27 +04:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-05-31 05:27:20 +04:00
|
|
|
#ifdef HAVE_CHARSET
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2001-09-07 21:52:19 +04:00
|
|
|
|
|
|
|
#include "global.h"
|
2001-05-31 05:27:20 +04:00
|
|
|
#include "dlg.h"
|
2001-06-06 02:28:11 +04:00
|
|
|
#include "dialog.h"
|
2001-05-31 05:27:20 +04:00
|
|
|
#include "widget.h"
|
|
|
|
#include "wtools.h"
|
|
|
|
#include "charsets.h"
|
2001-07-31 09:54:39 +04:00
|
|
|
#include "selcodepage.h"
|
2001-06-06 02:28:11 +04:00
|
|
|
#include "main.h"
|
2001-05-31 05:27:20 +04:00
|
|
|
|
|
|
|
#define ENTRY_LEN 35
|
|
|
|
|
|
|
|
/* Numbers of (file I/O) and (input/display) codepages. -1 if not selected */
|
|
|
|
int source_codepage = -1;
|
|
|
|
int display_codepage = -1;
|
|
|
|
|
2001-07-31 09:54:39 +04:00
|
|
|
static unsigned char get_hotkey( int n )
|
2001-05-31 05:27:20 +04:00
|
|
|
{
|
|
|
|
return (n <= 9) ? '0' + n : 'a' + n - 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
int select_charset( int current_charset, int seldisplay )
|
|
|
|
{
|
|
|
|
int i, menu_lines = n_codepages + 1;
|
2002-08-27 17:23:29 +04:00
|
|
|
char buffer[255];
|
2001-05-31 05:27:20 +04:00
|
|
|
|
|
|
|
/* Create listbox */
|
|
|
|
Listbox* listbox =
|
|
|
|
create_listbox_window ( ENTRY_LEN + 2, menu_lines,
|
|
|
|
_(" Choose input codepage "),
|
|
|
|
"[Codepages Translation]");
|
|
|
|
|
|
|
|
if (!seldisplay)
|
|
|
|
LISTBOX_APPEND_TEXT( listbox, '-', _("- < No translation >"), NULL );
|
|
|
|
|
|
|
|
/* insert all the items found */
|
|
|
|
for (i = 0; i < n_codepages; i++) {
|
2002-08-27 17:23:29 +04:00
|
|
|
char *name = codepages[i].name;
|
|
|
|
snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey(i), name);
|
2001-05-31 05:27:20 +04:00
|
|
|
LISTBOX_APPEND_TEXT( listbox, get_hotkey(i), buffer, NULL );
|
|
|
|
}
|
|
|
|
if (seldisplay) {
|
2002-08-27 17:23:29 +04:00
|
|
|
snprintf (buffer, sizeof (buffer), "%c %s", get_hotkey(n_codepages), _("Other 8 bit"));
|
2001-05-31 05:27:20 +04:00
|
|
|
LISTBOX_APPEND_TEXT( listbox, get_hotkey(n_codepages), buffer, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Select the default entry */
|
|
|
|
i = (seldisplay)
|
|
|
|
?
|
|
|
|
( (current_charset < 0) ? n_codepages : current_charset )
|
|
|
|
:
|
|
|
|
( current_charset + 1 );
|
|
|
|
|
|
|
|
listbox_select_by_number( listbox->list, i );
|
|
|
|
|
|
|
|
i = run_listbox( listbox );
|
|
|
|
|
|
|
|
return (seldisplay) ? ( (i >= n_codepages) ? -1 : i )
|
|
|
|
: ( i - 1 );
|
|
|
|
}
|
2001-06-06 02:28:11 +04:00
|
|
|
|
|
|
|
/* Helper functions for codepages support */
|
|
|
|
|
|
|
|
|
2001-07-31 09:54:39 +04:00
|
|
|
int do_select_codepage(void)
|
2001-06-06 02:28:11 +04:00
|
|
|
{
|
2001-06-08 02:36:45 +04:00
|
|
|
char *errmsg;
|
|
|
|
|
2001-06-06 02:28:11 +04:00
|
|
|
if (display_codepage > 0) {
|
|
|
|
source_codepage = select_charset( source_codepage, 0 );
|
|
|
|
errmsg = init_translation_table( source_codepage, display_codepage );
|
|
|
|
if (errmsg) {
|
2001-06-08 02:36:45 +04:00
|
|
|
message( 1, MSG_ERROR, "%s", errmsg );
|
2001-06-06 02:28:11 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
message( 1, _(" Warning "),
|
2001-06-08 02:36:45 +04:00
|
|
|
_("To use this feature select your codepage in\n"
|
2001-06-06 02:28:11 +04:00
|
|
|
"Setup / Display Bits dialog!\n"
|
2001-06-08 02:36:45 +04:00
|
|
|
"Do not forget to save options." ));
|
2001-06-06 02:28:11 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2001-06-11 16:11:06 +04:00
|
|
|
}
|
2001-06-06 02:28:11 +04:00
|
|
|
|
2001-05-31 05:27:20 +04:00
|
|
|
#endif /* HAVE_CHARSET */
|