~ubuntu-branches/ubuntu/quantal/vice/quantal

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * uirs232.c - Implementation of the RS232 settings dialog box.
 *
 * Written by
 *  Andreas Boose <viceteam@t-online.de>
 *
 * This file is part of VICE, the Versatile Commodore Emulator.
 * See README for copyright notice.
 *
 *  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.
 *
 */

#include "vice.h"

#include <stdio.h>
#include <windows.h>
#include <tchar.h>

#include "res.h"
#include "resources.h"
#include "system.h"
#include "translate.h"
#include "uirs232.h"
#include "winmain.h"


#define MAXRS232 4


static void init_rs232_dialog(HWND hwnd)
{
    const char *device;
    TCHAR *st_device;

    resources_get_value("RsDevice1", (void *)&device);
    st_device = system_mbstowcs_alloc(device);
    SetDlgItemText(hwnd, IDC_RS232_DEVICE1,
                   device != NULL ? st_device : TEXT(""));
    system_mbstowcs_free(st_device);

    resources_get_value("RsDevice2", (void *)&device);
    st_device = system_mbstowcs_alloc(device);
    SetDlgItemText(hwnd, IDC_RS232_DEVICE2,
                   device != NULL ? st_device : TEXT(""));
    system_mbstowcs_free(st_device);

    resources_get_value("RsDevice3", (void *)&device);
    st_device = system_mbstowcs_alloc(device);
    SetDlgItemText(hwnd, IDC_RS232_DEVICE3,
                   device != NULL ? st_device : TEXT(""));
    system_mbstowcs_free(st_device);

    resources_get_value("RsDevice4", (void *)&device);
    st_device = system_mbstowcs_alloc(device);
    SetDlgItemText(hwnd, IDC_RS232_DEVICE4,
                   device != NULL ? st_device : TEXT(""));
    system_mbstowcs_free(st_device);
}

static void end_rs232_dialog(HWND hwnd)
{
    TCHAR st[MAX_PATH];
    char s[MAX_PATH];

    GetDlgItemText(hwnd, IDC_RS232_DEVICE1, st, MAX_PATH);
    system_wcstombs(s, st, MAX_PATH);
    resources_set_value("RsDevice1", (resource_value_t)s);

    GetDlgItemText(hwnd, IDC_RS232_DEVICE2, st, MAX_PATH);
    system_wcstombs(s, st, MAX_PATH);
    resources_set_value("RsDevice2", (resource_value_t)s);

    GetDlgItemText(hwnd, IDC_RS232_DEVICE3, st, MAX_PATH);
    system_wcstombs(s, st, MAX_PATH);
    resources_set_value("RsDevice3", (resource_value_t)s);

    GetDlgItemText(hwnd, IDC_RS232_DEVICE4, st, MAX_PATH);
    system_wcstombs(s, st, MAX_PATH);
    resources_set_value("RsDevice4", (resource_value_t)s);
}

static BOOL CALLBACK dialog_proc(HWND hwnd, UINT msg, WPARAM wparam,
                                 LPARAM lparam)
{
    int command;

    switch (msg) {
      case WM_COMMAND:
        command = LOWORD(wparam);
        switch (command) {
          case IDOK:
            end_rs232_dialog(hwnd);
          case IDCANCEL:
            EndDialog(hwnd, 0);
            return TRUE;
        }
        return FALSE;
      case WM_CLOSE:
        EndDialog(hwnd, 0);
        return TRUE;
      case WM_INITDIALOG:
        init_rs232_dialog(hwnd);
        return TRUE;
    }
    return FALSE;
}

void ui_rs232_settings_dialog(HWND hwnd)
{
    DialogBox(winmain_instance, (LPCTSTR)translate_res(IDD_RS232_SETTINGS_DIALOG), hwnd,
              dialog_proc);
}