~ubuntu-branches/ubuntu/raring/vice/raring

« back to all changes in this revision

Viewing changes to src/arch/unix/uikeyboard.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-02-01 11:30:26 UTC
  • mto: (9.1.1 lenny) (1.1.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20050201113026-6gy97mcqlg2ykg4z
Tags: upstream-1.16
Import upstream version 1.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * uikeyboard.c
 
3
 *
 
4
 * Written by
 
5
 *  Andreas Boose <viceteam@t-online.de>
 
6
 *  Andr� Fachat <fachat@physik.tu-chemnitz.de>
 
7
 *
 
8
 * This file is part of VICE, the Versatile Commodore Emulator.
 
9
 * See README for copyright notice.
 
10
 *
 
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.
 
15
 *
 
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.
 
20
 *
 
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., 59 Temple Place, Suite 330, Boston, MA
 
24
 *  02111-1307  USA.
 
25
 *
 
26
 */
 
27
 
 
28
#include "vice.h"
 
29
 
 
30
#include <errno.h>
 
31
#include <stdio.h>
 
32
#include <stdlib.h>
 
33
 
 
34
#include "ioutil.h"
 
35
#include "keyboard.h"
 
36
#include "lib.h"
 
37
#include "machine.h"
 
38
#include "resources.h"
 
39
#include "uikeyboard.h"
 
40
#include "uimenu.h"
 
41
#include "util.h"
 
42
#include "vsync.h"
 
43
 
 
44
 
 
45
static UI_CALLBACK(set_keymap_type)
 
46
{
 
47
     int kindex, newindex = (int)UI_MENU_CB_PARAM;
 
48
 
 
49
     if (resources_get_value("KeymapIndex", (void *)&kindex) < 0)
 
50
         return;
 
51
 
 
52
     if (!CHECK_MENUS) {
 
53
        if ((kindex & 1) != newindex) {
 
54
            resources_set_value("KeymapIndex", (resource_value_t)
 
55
                                ((kindex & ~1) + newindex));
 
56
            ui_update_menus();
 
57
        }
 
58
     } else {
 
59
        ui_menu_set_tick(w, (kindex & 1) == newindex);
 
60
     }
 
61
}
 
62
 
 
63
static ui_menu_entry_t keyboard_maptype_submenu[] = {
 
64
    { N_("*Symbolic mapping"), (ui_callback_t)set_keymap_type,
 
65
      (ui_callback_data_t)0, NULL },
 
66
    { N_("*Positional mapping (US)"), (ui_callback_t)set_keymap_type,
 
67
      (ui_callback_data_t)1, NULL },
 
68
    { NULL }
 
69
};
 
70
 
 
71
static UI_CALLBACK(select_user_keymap)
 
72
{
 
73
    char *filename;
 
74
    const char *resname;
 
75
    ui_button_t button;
 
76
    int kindex;
 
77
    static char *last_dir;
 
78
 
 
79
    resources_get_value("KeymapIndex", (void *)&kindex);
 
80
    kindex = (kindex & ~1) + (int)UI_MENU_CB_PARAM;
 
81
    resname = machine_keymap_res_name_list[kindex];
 
82
 
 
83
    vsync_suspend_speed_eval();
 
84
    filename = ui_select_file(_("Read Keymap File"), NULL, 0, False, last_dir,
 
85
                              "*.vkm", &button, False, NULL);
 
86
 
 
87
    switch (button) {
 
88
      case UI_BUTTON_OK:
 
89
        resources_set_value(resname, (resource_value_t)filename);
 
90
        if (last_dir)
 
91
            lib_free(last_dir);
 
92
        util_fname_split(filename, &last_dir, NULL);
 
93
        break;
 
94
      default:
 
95
        /* Do nothing special.  */
 
96
        break;
 
97
    }
 
98
    if (filename != NULL)
 
99
        lib_free(filename);
 
100
}
 
101
 
 
102
static UI_CALLBACK(dump_keymap)
 
103
{
 
104
    char *wd;
 
105
    int len;
 
106
 
 
107
    len = ioutil_maxpathlen();
 
108
    wd = lib_malloc(len);
 
109
 
 
110
    ioutil_getcwd(wd, len);
 
111
    vsync_suspend_speed_eval();
 
112
    if (ui_input_string(_("VICE setting"), _("Write to Keymap File:"),
 
113
                        wd, len) == UI_BUTTON_OK) {
 
114
        if (keyboard_keymap_dump(wd) < 0)
 
115
            ui_error(strerror(errno));
 
116
    }
 
117
    lib_free(wd);
 
118
}
 
119
 
 
120
static ui_menu_entry_t keyboard_settings_submenu[] = {
 
121
    { N_("Keyboard mapping type"),
 
122
      NULL, NULL, keyboard_maptype_submenu },
 
123
    { "--" },
 
124
    { N_("Set symbolic keymap file"), (ui_callback_t)select_user_keymap,
 
125
                (ui_callback_data_t)0, NULL},
 
126
    { N_("Set positional keymap file"), (ui_callback_t)select_user_keymap,
 
127
                (ui_callback_data_t)1, NULL},
 
128
    { "--" },
 
129
    { N_("Dump keymap to file"),
 
130
      (ui_callback_t) dump_keymap, NULL, NULL },
 
131
    { NULL }
 
132
};
 
133
 
 
134
ui_menu_entry_t uikeyboard_settings_menu[] = {
 
135
    { N_("Keyboard settings"),
 
136
      NULL, NULL, keyboard_settings_submenu },
 
137
    { NULL }
 
138
};
 
139