~ubuntu-branches/ubuntu/maverick/vice/maverick

« back to all changes in this revision

Viewing changes to src/arch/win32/uiperipheral.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-02-01 11:30:26 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050201113026-3eyakzsmmheclvjg
Tags: 1.16-1
* New upstream version
* Fixes crash on 64-bit architectures (closes: #287640)
* x128 working again (closes: #286767)
* Works fine with /dev/dsp in use (not in the main changelog, but tested
  on my local machine as working).  Presumably, this also takes care of
  the issue with dsp being held.  I'm not sure if this is because I'm
  testing it on a 2.6 kernel now -- if you are still having problems
  with /dev/dsp, please reopen the bugs. (closes: #152952, #207942)
* Don't kill Makefile.in on clean

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
#include <stdio.h>
32
32
#include <windows.h>
 
33
#include <tchar.h>
33
34
 
34
35
#ifdef HAVE_SHLOBJ_H
35
36
#include <shlobj.h>
41
42
 
42
43
#include "attach.h"
43
44
#include "autostart.h"
 
45
#include "iecdrive.h"
44
46
#include "imagecontents.h"
45
47
#include "lib.h"
 
48
#include "opencbmlib.h"
 
49
#include "printer.h"
46
50
#include "res.h"
47
51
#include "resources.h"
 
52
#include "system.h"
48
53
#include "ui.h"
 
54
#include "uilib.h"
49
55
#include "uiperipheral.h"
50
 
#include "printer.h"
51
 
#include "iecdrive.h"
52
 
#include "system.h"
53
 
#include "uilib.h"
54
56
#include "winmain.h"
55
57
 
56
58
 
58
60
/*                             Disk Peripherals (8-11)                        */
59
61
/* -------------------------------------------------------------------------- */
60
62
 
61
 
static int  have_printer_userport = -1;
62
 
 
63
63
static void enable_controls_for_disk_device_type(HWND hwnd, int type)
64
64
{
65
65
    EnableWindow(GetDlgItem(hwnd, IDC_DISKIMAGE),
85
85
 
86
86
static void enable_controls(HWND hwnd)
87
87
{
88
 
  int drive_true_emulation, virtual_device_traps;
89
 
  BOOL haveIECDevice;
 
88
    int drive_true_emulation, virtual_device_traps;
 
89
    BOOL haveIECDevice;
90
90
 
91
 
  resources_get_value("DriveTrueEmulation", (void *)&drive_true_emulation);
92
 
  resources_get_value("VirtualDevices", (void *)&virtual_device_traps);
93
 
  haveIECDevice = IsDlgButtonChecked(hwnd, IDC_TOGGLE_USEIECDEVICE)==BST_CHECKED;
 
91
    resources_get_value("DriveTrueEmulation", (void *)&drive_true_emulation);
 
92
    resources_get_value("VirtualDevices", (void *)&virtual_device_traps);
 
93
    haveIECDevice = IsDlgButtonChecked(hwnd, IDC_TOGGLE_USEIECDEVICE)
 
94
                    == BST_CHECKED;
94
95
  
95
 
  if( (drive_true_emulation || !virtual_device_traps) && !haveIECDevice )
96
 
    {
97
 
      EnableWindow(GetDlgItem(hwnd, IDC_SELECTDISK),  FALSE);
98
 
      EnableWindow(GetDlgItem(hwnd, IDC_SELECTDIR),   FALSE);
99
 
      EnableWindow(GetDlgItem(hwnd, IDC_SELECTNONE),  FALSE);
100
 
      CheckRadioButton(hwnd, IDC_SELECTDISK, IDC_SELECTDIR, IDC_SELECTNONE);
101
 
      enable_controls_for_disk_device_type(hwnd, IDC_SELECTNONE);
102
 
    }
103
 
  else
104
 
    {
105
 
      EnableWindow(GetDlgItem(hwnd, IDC_SELECTDISK),  TRUE);
106
 
      EnableWindow(GetDlgItem(hwnd, IDC_SELECTDIR),   TRUE);
107
 
      EnableWindow(GetDlgItem(hwnd, IDC_SELECTNONE),  TRUE);
 
96
    if ((drive_true_emulation || !virtual_device_traps) && !haveIECDevice) {
 
97
        EnableWindow(GetDlgItem(hwnd, IDC_SELECTDISK),  FALSE);
 
98
        EnableWindow(GetDlgItem(hwnd, IDC_SELECTDIR),   FALSE);
 
99
        EnableWindow(GetDlgItem(hwnd, IDC_SELECTNONE),  FALSE);
 
100
#ifdef HAVE_OPENCBM
 
101
        EnableWindow(GetDlgItem(hwnd, IDC_SELECTREAL),  FALSE);
 
102
#endif
 
103
    } else {
 
104
        EnableWindow(GetDlgItem(hwnd, IDC_SELECTDISK),  TRUE);
 
105
        EnableWindow(GetDlgItem(hwnd, IDC_SELECTDIR),   TRUE);
 
106
        EnableWindow(GetDlgItem(hwnd, IDC_SELECTNONE),  TRUE);
 
107
#ifdef HAVE_OPENCBM
 
108
        if (opencbmlib_is_available())
 
109
            EnableWindow(GetDlgItem(hwnd, IDC_SELECTREAL), TRUE);
 
110
        else
 
111
            EnableWindow(GetDlgItem(hwnd, IDC_SELECTREAL), FALSE);
 
112
#endif
108
113
    }
109
114
}
110
115
 
111
116
static void init_dialog(HWND hwnd, unsigned int num)
112
117
{
113
118
    const char *disk_image, *dir;
114
 
    int enabled, n;
 
119
    TCHAR *st_disk_image, *st_dir;
 
120
    int devtype, n;
115
121
 
116
122
    if (num >= 8 && num <= 11) {
117
123
        disk_image = file_system_get_disk_name(num);
 
124
        st_disk_image = system_mbstowcs_alloc(disk_image);
118
125
        SetDlgItemText(hwnd, IDC_DISKIMAGE,
119
 
                       disk_image != NULL ? disk_image : "");
 
126
                       st_disk_image != NULL ? st_disk_image : TEXT(""));
 
127
        system_mbstowcs_free(st_disk_image);
120
128
 
121
129
        resources_get_sprintf("FSDevice%dDir", (void *)&dir, num);
122
 
        SetDlgItemText(hwnd, IDC_DIR, dir != NULL ? dir : "");
 
130
        st_dir = system_mbstowcs_alloc(dir);
 
131
        SetDlgItemText(hwnd, IDC_DIR, st_dir != NULL ? st_dir : TEXT(""));
 
132
        system_mbstowcs_free(st_dir);
123
133
 
124
134
        resources_get_sprintf("FSDevice%dConvertP00", (void *)&n, num);
125
135
        CheckDlgButton(hwnd, IDC_TOGGLE_READP00,
138
148
        CheckDlgButton(hwnd, IDC_TOGGLE_ATTACH_READONLY,
139
149
                       n ? BST_CHECKED : BST_UNCHECKED);
140
150
 
141
 
        
142
 
        resources_get_sprintf("FileSystemDevice%d", (void *)&enabled, num);
143
 
        if( !enabled )
144
 
          n = IDC_SELECTNONE;
145
 
        else if( disk_image != NULL )
146
 
          n = IDC_SELECTDISK;
147
 
        else
148
 
          n = IDC_SELECTDIR;
 
151
        resources_get_sprintf("FileSystemDevice%d", (void *)&devtype, num);
 
152
        switch (devtype) {
 
153
          case ATTACH_DEVICE_FS:
 
154
            if (disk_image != NULL)
 
155
                n = IDC_SELECTDISK;
 
156
            else
 
157
                n = IDC_SELECTDIR;
 
158
            break;
 
159
#ifdef HAVE_OPENCBM
 
160
          case ATTACH_DEVICE_REAL:
 
161
            n = IDC_SELECTREAL;
 
162
            break;
 
163
#endif
 
164
          default:
 
165
            n = IDC_SELECTNONE;
 
166
        }
149
167
 
 
168
#ifdef HAVE_OPENCBM
 
169
        CheckRadioButton(hwnd, IDC_SELECTDISK, IDC_SELECTREAL, n);
 
170
#else
150
171
        CheckRadioButton(hwnd, IDC_SELECTDISK, IDC_SELECTDIR, n);
 
172
#endif
151
173
        enable_controls_for_disk_device_type(hwnd, n);
152
174
 
153
 
        if( iec_available_busses() & IEC_BUS_IEC )
154
 
          {
 
175
        if (iec_available_busses() & IEC_BUS_IEC) {
155
176
            resources_get_sprintf("IECDevice%d", (void *)&n, num);
156
177
            CheckDlgButton(hwnd, IDC_TOGGLE_USEIECDEVICE,
157
178
                           n ? BST_CHECKED : BST_UNCHECKED);
158
 
          }
159
 
        else
160
 
          {
 
179
        } else {
161
180
            CheckDlgButton(hwnd, IDC_TOGGLE_USEIECDEVICE, BST_UNCHECKED);
162
181
            ShowWindow(GetDlgItem(hwnd, IDC_TOGGLE_USEIECDEVICE), FALSE);
163
 
          }
 
182
        }
164
183
        
165
184
        enable_controls(hwnd);
166
185
    }
168
187
 
169
188
static BOOL store_dialog_results(HWND hwnd, unsigned int num)
170
189
{
171
 
  char s[MAX_PATH];
 
190
    char s[MAX_PATH];
 
191
    TCHAR st[MAX_PATH];
 
192
    int devtype = ATTACH_DEVICE_NONE;
172
193
 
173
 
  if( IsDlgButtonChecked(hwnd, IDC_SELECTDISK) == BST_CHECKED ) 
174
 
    {
175
 
      GetDlgItemText(hwnd, IDC_DISKIMAGE, s, MAX_PATH);
176
 
      if( file_system_attach_disk(num, s) < 0 )
177
 
        {
178
 
          ui_error("Cannot attach specified file");
179
 
          return 0;
180
 
        }
 
194
    if (IsDlgButtonChecked(hwnd, IDC_SELECTDISK) == BST_CHECKED) {
 
195
        GetDlgItemText(hwnd, IDC_DISKIMAGE, st, MAX_PATH);
 
196
        system_wcstombs(s, st, MAX_PATH);
 
197
        if (file_system_attach_disk(num, s) < 0 ) {
 
198
            ui_error("Cannot attach specified file");
 
199
            return 0;
 
200
        }
 
201
    } else {
 
202
        if ((IsDlgButtonChecked(hwnd, IDC_SELECTDIR) == BST_CHECKED) &&
 
203
            file_system_get_disk_name(num))
 
204
            file_system_detach_disk(num);
181
205
    }
182
 
  else if( (IsDlgButtonChecked(hwnd, IDC_SELECTDIR) == BST_CHECKED) && 
183
 
           file_system_get_disk_name(num) )
184
 
    file_system_detach_disk(num);
185
 
 
186
 
  if( iec_available_busses() & IEC_BUS_IEC )
187
 
    resources_set_sprintf("IECDevice%d", 
188
 
                          (resource_value_t)(IsDlgButtonChecked(hwnd, IDC_TOGGLE_USEIECDEVICE)==BST_CHECKED), 
 
206
 
 
207
    if (iec_available_busses() & IEC_BUS_IEC)
 
208
        resources_set_sprintf("IECDevice%d", 
 
209
                              (resource_value_t)(IsDlgButtonChecked(hwnd,
 
210
                              IDC_TOGGLE_USEIECDEVICE)==BST_CHECKED), num);
 
211
 
 
212
    if (IsDlgButtonChecked(hwnd, IDC_SELECTDISK) == BST_CHECKED
 
213
        || IsDlgButtonChecked(hwnd, IDC_SELECTDIR) == BST_CHECKED)
 
214
        devtype = ATTACH_DEVICE_FS;
 
215
#ifdef HAVE_OPENCBM
 
216
    if (IsDlgButtonChecked(hwnd, IDC_SELECTREAL) == BST_CHECKED)
 
217
        devtype = ATTACH_DEVICE_REAL;
 
218
#endif
 
219
    resources_set_sprintf("FileSystemDevice%d", (resource_value_t)devtype,
189
220
                          num);
190
221
 
191
 
  resources_set_sprintf("FileSystemDevice%d", 
192
 
                        (resource_value_t)(IsDlgButtonChecked(hwnd, IDC_SELECTNONE) != BST_CHECKED),
193
 
                        num);
194
 
  resources_set_sprintf("FSDevice%dConvertP00", 
195
 
                        (resource_value_t)(IsDlgButtonChecked(hwnd, IDC_TOGGLE_READP00)==BST_CHECKED), 
196
 
                        num);
197
 
  resources_set_sprintf("FSDevice%dSaveP00", 
198
 
                        (resource_value_t)(IsDlgButtonChecked(hwnd, IDC_TOGGLE_WRITEP00)==BST_CHECKED), 
199
 
                        num);
200
 
  resources_set_sprintf("FSDevice%dHideCBMFiles", 
201
 
                        (resource_value_t)(IsDlgButtonChecked(hwnd, IDC_TOGGLE_HIDENONP00)==BST_CHECKED), 
202
 
                        num);
203
 
  resources_set_sprintf("AttachDevice%dReadonly", 
204
 
                        (resource_value_t)(IsDlgButtonChecked(hwnd, IDC_TOGGLE_ATTACH_READONLY)==BST_CHECKED), 
205
 
                        num);
206
 
  GetDlgItemText(hwnd, IDC_DIR, s, MAX_PATH);
207
 
  resources_set_sprintf("FSDevice%dDir", (resource_value_t)s, num);
208
 
 
209
 
  return 1;
 
222
    resources_set_sprintf("FSDevice%dConvertP00", 
 
223
                          (resource_value_t)(IsDlgButtonChecked(hwnd,
 
224
                          IDC_TOGGLE_READP00) == BST_CHECKED), num);
 
225
    resources_set_sprintf("FSDevice%dSaveP00", 
 
226
                          (resource_value_t)(IsDlgButtonChecked(hwnd,
 
227
                          IDC_TOGGLE_WRITEP00) == BST_CHECKED), num);
 
228
    resources_set_sprintf("FSDevice%dHideCBMFiles", 
 
229
                          (resource_value_t)(IsDlgButtonChecked(hwnd,
 
230
                          IDC_TOGGLE_HIDENONP00) == BST_CHECKED), num);
 
231
    resources_set_sprintf("AttachDevice%dReadonly", 
 
232
                          (resource_value_t)(IsDlgButtonChecked(hwnd,
 
233
                          IDC_TOGGLE_ATTACH_READONLY) == BST_CHECKED), num);
 
234
 
 
235
    GetDlgItemText(hwnd, IDC_DIR, st, MAX_PATH);
 
236
    system_wcstombs(s, st, MAX_PATH);
 
237
    resources_set_sprintf("FSDevice%dDir", (resource_value_t)s, num);
 
238
 
 
239
    return 1;
 
240
}
 
241
 
 
242
static void browse_diskimage(HWND hwnd)
 
243
{
 
244
    TCHAR *st_name;
 
245
 
 
246
    st_name = uilib_select_file(hwnd, TEXT("Attach disk image"),
 
247
                                UILIB_FILTER_ALL | UILIB_FILTER_DISK
 
248
                                | UILIB_FILTER_ZIP,
 
249
                                UILIB_SELECTOR_TYPE_FILE_LOAD,
 
250
                                UILIB_SELECTOR_STYLE_DISK);
 
251
 
 
252
    if (st_name != NULL) {
 
253
        SetDlgItemText(hwnd, IDC_DISKIMAGE, st_name);
 
254
        lib_free(st_name);
 
255
    }
 
256
}
 
257
 
 
258
static void autostart_diskimage(HWND hwnd)
 
259
{
 
260
    TCHAR *st_name;
 
261
 
 
262
    st_name = uilib_select_file(hwnd, TEXT("Autostart disk image"),
 
263
                                UILIB_FILTER_ALL | UILIB_FILTER_DISK
 
264
                                | UILIB_FILTER_ZIP,
 
265
                                UILIB_SELECTOR_TYPE_FILE_LOAD,
 
266
                                UILIB_SELECTOR_STYLE_DISK);
 
267
 
 
268
    if (st_name != NULL) {
 
269
        char *name;
 
270
 
 
271
        SetDlgItemText(hwnd, IDC_DISKIMAGE, st_name);
 
272
        name = system_wcstombs_alloc(st_name);
 
273
        if (autostart_autodetect(name, "*", 0, AUTOSTART_MODE_RUN) < 0)
 
274
            ui_error("Cannot autostart specified file.");
 
275
        system_wcstombs_free(name);
 
276
        lib_free(st_name);
 
277
    }
 
278
}
 
279
 
 
280
static void browse_dir(HWND hwnd)
 
281
{
 
282
    BROWSEINFO bi;
 
283
    TCHAR st[MAX_PATH];
 
284
    LPITEMIDLIST idlist;
 
285
 
 
286
    bi.hwndOwner = hwnd;
 
287
    bi.pidlRoot = NULL;
 
288
    bi.pszDisplayName = st;
 
289
    bi.lpszTitle = TEXT("Select file system directory");
 
290
    bi.ulFlags = 0;
 
291
    bi.lpfn = NULL;
 
292
    bi.lParam = 0;
 
293
    bi.iImage = 0;
 
294
    if ((idlist = SHBrowseForFolder(&bi)) != NULL) {
 
295
        SHGetPathFromIDList(idlist, st);
 
296
        LocalFree(idlist);
 
297
        /*
 
298
        If a root directory is selected, \ is appended
 
299
        and has to be deleted.
 
300
        */
 
301
        if (st[_tcslen(st) - 1] == '\\')
 
302
            st[_tcslen(st) - 1] = '\0';
 
303
        SetDlgItemText(hwnd, IDC_DIR, st);
 
304
    }
210
305
}
211
306
 
212
307
static BOOL CALLBACK dialog_proc(unsigned int num, HWND hwnd, UINT msg,
219
314
 
220
315
      case WM_NOTIFY:
221
316
        {
222
 
          NMHDR *nmhdr = (NMHDR *) (lparam);
 
317
            NMHDR *nmhdr = (NMHDR *)(lparam);
223
318
 
224
 
          switch( nmhdr->code )
225
 
            {
226
 
            case PSN_APPLY:
227
 
              SetWindowLong(hwnd, DWL_MSGRESULT, 
228
 
                            store_dialog_results(hwnd, num) ? PSNRET_NOERROR : PSNRET_INVALID);
229
 
              return TRUE;
 
319
            switch (nmhdr->code) {
 
320
              case PSN_APPLY:
 
321
                SetWindowLong(hwnd, DWL_MSGRESULT, 
 
322
                              store_dialog_results(hwnd, num)
 
323
                              ? PSNRET_NOERROR : PSNRET_INVALID);
 
324
                return TRUE;
230
325
            }
231
 
          break;
 
326
            break;
232
327
        }
233
328
 
234
329
      case WM_COMMAND:
235
330
        switch (LOWORD(wparam)) {
236
331
          case IDC_SELECTDIR:
237
332
          case IDC_SELECTDISK:
 
333
          case IDC_SELECTREAL:
238
334
          case IDC_SELECTNONE:
239
335
            enable_controls_for_disk_device_type(hwnd, LOWORD(wparam));
240
336
            break;
242
338
            enable_controls(hwnd);
243
339
            break;
244
340
          case IDC_BROWSEDISK:
245
 
            {
246
 
                char *s;
247
 
 
248
 
                s = ui_select_file(hwnd,"Attach disk image",
249
 
                    UI_LIB_FILTER_ALL | UI_LIB_FILTER_DISK | UI_LIB_FILTER_ZIP,
250
 
                    FILE_SELECTOR_DISK_STYLE,NULL);
251
 
 
252
 
                if (s != NULL) {
253
 
                    SetDlgItemText(hwnd, IDC_DISKIMAGE, s);
254
 
                    lib_free(s);
255
 
                }
256
 
            }
 
341
            browse_diskimage(hwnd);
257
342
            break;
258
343
          case IDC_AUTOSTART:
259
 
            {
260
 
                char *s;
261
 
 
262
 
                s = ui_select_file(hwnd,"Autostart disk image",
263
 
                    UI_LIB_FILTER_ALL | UI_LIB_FILTER_DISK | UI_LIB_FILTER_ZIP,
264
 
                    FILE_SELECTOR_DISK_STYLE,NULL);
265
 
 
266
 
                if (s != NULL) {
267
 
                    SetDlgItemText(hwnd, IDC_DISKIMAGE, s);
268
 
                    if (autostart_autodetect(s, "*", 0, AUTOSTART_MODE_RUN) < 0)
269
 
                        ui_error("Cannot autostart specified file.");
270
 
                    lib_free(s);
271
 
                }
272
 
            }
 
344
            autostart_diskimage(hwnd);
273
345
            break;
274
346
          case IDC_BROWSEDIR:
275
 
            {
276
 
                BROWSEINFO bi;
277
 
                char s[MAX_PATH];
278
 
                LPITEMIDLIST idlist;
279
 
 
280
 
                bi.hwndOwner = hwnd;
281
 
                bi.pidlRoot = NULL;
282
 
                bi.pszDisplayName = s;
283
 
                bi.lpszTitle = "Select file system directory";
284
 
                bi.ulFlags = 0;
285
 
                bi.lpfn = NULL;
286
 
                bi.lParam = 0;
287
 
                bi.iImage = 0;
288
 
                if ((idlist = SHBrowseForFolder(&bi)) != NULL) {
289
 
                    SHGetPathFromIDList(idlist, s);
290
 
                    LocalFree(idlist);
291
 
                    /*
292
 
                    If a root directory is selected, \ is appended
293
 
                    and has to be deleted.
294
 
                    */
295
 
                    if (s[strlen(s) - 1] == '\\')
296
 
                        s[strlen(s) - 1] = '\0';
297
 
                    SetDlgItemText(hwnd, IDC_DIR, s);
298
 
                }
299
 
            }
 
347
            browse_dir(hwnd);
300
348
            break;
301
349
        }
302
350
        return TRUE;
320
368
/*                           Printers (Userport, 4-5)                         */
321
369
/* -------------------------------------------------------------------------- */
322
370
 
323
 
static char *printertextdevice[3] = {NULL, NULL, NULL};
 
371
static int have_printer_userport = -1;
 
372
 
 
373
static char *printertextdevice[3] = { NULL, NULL, NULL };
324
374
 
325
375
static const TCHAR *ui_printer[] =
326
376
{
372
422
 
373
423
static void enable_printer_controls(unsigned int num, HWND hwnd)
374
424
{
375
 
  int res_value, is_enabled;
376
 
  int drive_true_emulation, virtual_device_traps;
377
 
  BOOL haveIECDevice;
378
 
  
379
 
  resources_get_value("DriveTrueEmulation", (void *)&drive_true_emulation);
380
 
  resources_get_value("VirtualDevices", (void *)&virtual_device_traps);
381
 
  haveIECDevice = IsDlgButtonChecked(hwnd, IDC_PRINTER_USEIECDEVICE)==BST_CHECKED;
382
 
  
383
 
  if( num>0 && ((drive_true_emulation || !virtual_device_traps) && !haveIECDevice) )
384
 
    {
385
 
      EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_TYPE), FALSE);
386
 
      SendMessage(GetDlgItem(hwnd, IDC_PRINTER_TYPE),
387
 
                  CB_SETCURSEL, 0, 0);
388
 
    }
389
 
  else
390
 
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_TYPE), TRUE);
 
425
    int res_value, is_enabled;
 
426
    int drive_true_emulation, virtual_device_traps;
 
427
    BOOL haveIECDevice;
 
428
  
 
429
    resources_get_value("DriveTrueEmulation", (void *)&drive_true_emulation);
 
430
    resources_get_value("VirtualDevices", (void *)&virtual_device_traps);
 
431
    haveIECDevice = IsDlgButtonChecked(hwnd,
 
432
                                       IDC_PRINTER_USEIECDEVICE) == BST_CHECKED;
 
433
  
 
434
    if (num > 0 && ((drive_true_emulation || !virtual_device_traps)
 
435
        && !haveIECDevice)) {
 
436
        EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_TYPE), FALSE);
 
437
        SendMessage(GetDlgItem(hwnd, IDC_PRINTER_TYPE),
 
438
                    CB_SETCURSEL, 0, 0);
 
439
    } else
 
440
        EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_TYPE), TRUE);
391
441
 
392
 
  res_value = SendMessage(GetDlgItem(hwnd, IDC_PRINTER_TYPE),
393
 
                          CB_GETCURSEL, 0, 0);
394
 
  
395
 
  is_enabled = res_value == PRINTER_DEVICE_FS;
396
 
  
397
 
  EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_FORMFEED), is_enabled);
398
 
  EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_DRIVER), is_enabled);
399
 
  EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT), is_enabled);
400
 
  EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_TEXTOUT), is_enabled);
401
 
  EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT_FILE1_NAME), is_enabled);
402
 
  EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT_FILE2_NAME), is_enabled);
403
 
  EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT_FILE3_NAME), is_enabled);
 
442
    res_value = SendMessage(GetDlgItem(hwnd, IDC_PRINTER_TYPE),
 
443
                            CB_GETCURSEL, 0, 0);
 
444
  
 
445
    is_enabled = res_value == PRINTER_DEVICE_FS;
 
446
  
 
447
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_FORMFEED), is_enabled);
 
448
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_DRIVER), is_enabled);
 
449
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT), is_enabled);
 
450
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_TEXTOUT), is_enabled);
 
451
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT_FILE1_NAME), is_enabled);
 
452
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT_FILE2_NAME), is_enabled);
 
453
    EnableWindow(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT_FILE3_NAME), is_enabled);
404
454
}
405
455
 
406
456
static void init_printer_dialog(unsigned int num, HWND hwnd)
411
461
    const char *res_string;
412
462
    int current = 0;
413
463
 
414
 
    if( num==0 )
415
 
      sprintf(printer_name, "PrinterUserport");
 
464
    if (num == 0)
 
465
        sprintf(printer_name, "PrinterUserport");
416
466
    else
417
 
      sprintf(printer_name, "Printer%d", num);
 
467
        sprintf(printer_name, "Printer%d", num);
418
468
 
419
469
    resources_get_value(printer_name, (void *)&res_value);
420
470
    printer_hwnd = GetDlgItem(hwnd, IDC_PRINTER_TYPE);
456
506
    }
457
507
    SendMessage(printer_hwnd, CB_SETCURSEL, (WPARAM)res_value, 0);
458
508
 
459
 
    if( num>0 && (iec_available_busses() & IEC_BUS_IEC) )
460
 
      {
 
509
    if (num > 0 && (iec_available_busses() & IEC_BUS_IEC)) {
461
510
        resources_get_sprintf("IECDevice%d", (void *)&res_value, num);
462
511
        CheckDlgButton(hwnd, IDC_PRINTER_USEIECDEVICE,
463
512
                       res_value ? BST_CHECKED : BST_UNCHECKED);
464
 
      }
465
 
    else
466
 
      {
 
513
    } else {
467
514
        ShowWindow(GetDlgItem(hwnd, IDC_PRINTER_USEIECDEVICE), FALSE);
468
515
        CheckDlgButton(hwnd, IDC_PRINTER_USEIECDEVICE, BST_UNCHECKED);
469
 
      }
 
516
    }
470
517
    
471
 
    for(i=0; i<3; i++)
472
 
      {
 
518
    for (i = 0; i < 3; i++) {
473
519
        resources_get_sprintf("PrinterTextDevice%d", (void *)&res_string, i+1);
474
 
        if( res_string )
475
 
          strncpy(printertextdevice[i], res_string, MAX_PATH);
476
 
      }
 
520
        if (res_string)
 
521
            strncpy(printertextdevice[i], res_string, MAX_PATH);
 
522
    }
477
523
 
478
524
    enable_printer_controls(num, hwnd);
479
525
}
480
526
 
481
527
static BOOL store_printer_dialog_results(HWND hwnd, unsigned int num)
482
528
{
483
 
  char printer_name[30];
484
 
  
485
 
  if( num==0 )
486
 
    sprintf(printer_name, "PrinterUserport");
487
 
  else
488
 
    sprintf(printer_name, "Printer%d", num);
489
 
 
490
 
  resources_set_value(printer_name, 
491
 
                      (resource_value_t) SendMessage(GetDlgItem(hwnd, IDC_PRINTER_TYPE),
492
 
                                                     CB_GETCURSEL, 0, 0));
493
 
 
494
 
  resources_set_sprintf("%sDriver", 
495
 
                        (resource_value_t) 
496
 
                        ui_printer_driver_ascii[SendMessage(GetDlgItem(hwnd, IDC_PRINTER_DRIVER),
497
 
                                                            CB_GETCURSEL, 0, 0)],
498
 
                        printer_name);
499
 
 
500
 
  resources_set_sprintf("%sOutput", 
501
 
                        (resource_value_t) 
502
 
                        ui_printer_output_ascii[SendMessage(GetDlgItem(hwnd, IDC_PRINTER_OUTPUT),
503
 
                                                            CB_GETCURSEL, 0, 0)],
504
 
                        printer_name);
505
 
 
506
 
  resources_set_sprintf("%sTextDevice", 
507
 
                        (resource_value_t)
508
 
                        SendMessage(GetDlgItem(hwnd, IDC_PRINTER_TEXTOUT), CB_GETCURSEL, 0, 0),
509
 
                        printer_name);
510
 
  
511
 
  
512
 
  resources_set_value("PrinterTextDevice1", (void *)printertextdevice[0]);
513
 
  resources_set_value("PrinterTextDevice2", (void *)printertextdevice[1]);
514
 
  resources_set_value("PrinterTextDevice3", (void *)printertextdevice[2]);
515
 
 
516
 
  if( num>0 && (iec_available_busses() & IEC_BUS_IEC) )
517
 
    resources_set_sprintf("IECDevice%d", 
518
 
                          (resource_value_t)(IsDlgButtonChecked(hwnd, IDC_PRINTER_USEIECDEVICE)==BST_CHECKED),
519
 
                          num);
520
 
 
521
 
 
522
 
  return 1;
 
529
    char printer_name[30];
 
530
  
 
531
    if (num == 0)
 
532
        sprintf(printer_name, "PrinterUserport");
 
533
    else
 
534
        sprintf(printer_name, "Printer%d", num);
 
535
 
 
536
    resources_set_value(printer_name, 
 
537
                        (resource_value_t)SendMessage(GetDlgItem(hwnd,
 
538
                        IDC_PRINTER_TYPE), CB_GETCURSEL, 0, 0));
 
539
 
 
540
    resources_set_sprintf("%sDriver", (resource_value_t)
 
541
                        ui_printer_driver_ascii[SendMessage(GetDlgItem(hwnd,
 
542
                        IDC_PRINTER_DRIVER), CB_GETCURSEL, 0, 0)],
 
543
                        printer_name);
 
544
 
 
545
    resources_set_sprintf("%sOutput", (resource_value_t)
 
546
                          ui_printer_output_ascii[SendMessage(GetDlgItem(hwnd,
 
547
                          IDC_PRINTER_OUTPUT), CB_GETCURSEL, 0, 0)],
 
548
                          printer_name);
 
549
 
 
550
    resources_set_sprintf("%sTextDevice", (resource_value_t)
 
551
                          SendMessage(GetDlgItem(hwnd, IDC_PRINTER_TEXTOUT),
 
552
                          CB_GETCURSEL, 0, 0), printer_name);
 
553
  
 
554
    resources_set_value("PrinterTextDevice1", (void *)printertextdevice[0]);
 
555
    resources_set_value("PrinterTextDevice2", (void *)printertextdevice[1]);
 
556
    resources_set_value("PrinterTextDevice3", (void *)printertextdevice[2]);
 
557
 
 
558
    if (num > 0 && (iec_available_busses() & IEC_BUS_IEC))
 
559
        resources_set_sprintf("IECDevice%d", (resource_value_t)
 
560
                          (IsDlgButtonChecked(hwnd,
 
561
                          IDC_PRINTER_USEIECDEVICE)==BST_CHECKED), num);
 
562
 
 
563
    return 1;
 
564
}
 
565
 
 
566
static void printer_set_active(HWND hwnd)
 
567
{
 
568
    TCHAR *st;
 
569
 
 
570
    st = system_mbstowcs_alloc(printertextdevice[0]);
 
571
    SetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE1_NAME, st);
 
572
    system_mbstowcs_free(st);
 
573
    st = system_mbstowcs_alloc(printertextdevice[1]);
 
574
    SetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE2_NAME, st);
 
575
    system_mbstowcs_free(st);
 
576
    st = system_mbstowcs_alloc(printertextdevice[2]);
 
577
    SetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE3_NAME, st);
 
578
    system_mbstowcs_free(st);
 
579
 
 
580
}
 
581
 
 
582
static void printer_kill_active(HWND hwnd)
 
583
{
 
584
    TCHAR st[MAX_PATH];
 
585
 
 
586
    GetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE1_NAME, st, MAX_PATH);
 
587
    system_wcstombs(printertextdevice[0], st, MAX_PATH);
 
588
    GetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE2_NAME, st, MAX_PATH);
 
589
    system_wcstombs(printertextdevice[1], st, MAX_PATH);
 
590
    GetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE3_NAME, st, MAX_PATH);
 
591
    system_wcstombs(printertextdevice[2], st, MAX_PATH);
523
592
}
524
593
 
525
594
static BOOL CALLBACK printer_dialog_proc(unsigned int num, HWND hwnd, UINT msg, 
532
601
        command = LOWORD(wparam);
533
602
        switch (command) {
534
603
          case IDC_PRINTER_TYPE:
535
 
          case IDC_PRINTER_USEIECDEVICE:
 
604
          case IDC_PRINTER_USEIECDEVICE:
536
605
            enable_printer_controls(num, hwnd);
537
606
            break;
538
 
          case IDC_PRINTER_FORMFEED:
539
 
            {
540
 
              switch( num )
541
 
                {
542
 
                case 4: printer_formfeed(0); break;
543
 
                case 5: printer_formfeed(1); break;
544
 
                case 0: printer_formfeed(2); break;
545
 
                }
546
 
              break;
547
 
            }
 
607
          case IDC_PRINTER_FORMFEED:
 
608
            switch (num) {
 
609
              case 4:
 
610
                printer_formfeed(0);
 
611
                break;
 
612
              case 5:
 
613
                printer_formfeed(1);
 
614
                break;
 
615
              case 0:
 
616
                printer_formfeed(2);
 
617
                break;
 
618
            }
 
619
            break;
548
620
        }
549
621
        return FALSE;
550
 
 
551
622
      case WM_NOTIFY:
552
623
        {
553
 
          NMHDR FAR *nmhdr = (NMHDR FAR *) (lparam);
554
 
 
555
 
          switch( nmhdr->code )
556
 
            {
557
 
            case PSN_APPLY:
558
 
              SetWindowLong(hwnd, DWL_MSGRESULT, 
559
 
                            store_printer_dialog_results(hwnd, num) ? PSNRET_NOERROR : PSNRET_INVALID);
560
 
              return TRUE;
561
 
 
562
 
            case PSN_SETACTIVE:
563
 
              {
564
 
                SetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE1_NAME, printertextdevice[0]);
565
 
                SetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE2_NAME, printertextdevice[1]);
566
 
                SetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE3_NAME, printertextdevice[2]);
567
 
                return TRUE;
568
 
              }
569
 
              
570
 
            case PSN_KILLACTIVE:
571
 
              {
572
 
                GetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE1_NAME, printertextdevice[0], MAX_PATH);
573
 
                GetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE2_NAME, printertextdevice[1], MAX_PATH);
574
 
                GetDlgItemText(hwnd, IDC_PRINTER_OUTPUT_FILE3_NAME, printertextdevice[2], MAX_PATH);
575
 
                return TRUE;
576
 
              }
 
624
            NMHDR FAR *nmhdr = (NMHDR FAR *)(lparam);
 
625
 
 
626
            switch (nmhdr->code) {
 
627
              case PSN_APPLY:
 
628
                SetWindowLong(hwnd, DWL_MSGRESULT, 
 
629
                              store_printer_dialog_results(hwnd, num)
 
630
                              ? PSNRET_NOERROR : PSNRET_INVALID);
 
631
                return TRUE;
 
632
              case PSN_SETACTIVE:
 
633
                printer_set_active(hwnd);
 
634
                return TRUE;
 
635
              case PSN_KILLACTIVE:
 
636
                printer_kill_active(hwnd);
 
637
                return TRUE;
577
638
            }
578
 
          break;
 
639
            break;
579
640
        }
580
 
 
581
641
      case WM_CLOSE:
582
642
        EndDialog(hwnd, 0);
583
643
        return TRUE;
591
651
}
592
652
 
593
653
 
594
 
#define _CALLBACK_PRINTER(num)                                            \
 
654
#define _CALLBACK_PRINTER(num)                                    \
595
655
static BOOL CALLBACK callback_##num(HWND dialog, UINT msg,        \
596
656
                                    WPARAM wparam, LPARAM lparam) \
597
657
{                                                                 \
598
 
    return printer_dialog_proc(num, dialog, msg, wparam, lparam);         \
 
658
    return printer_dialog_proc(num, dialog, msg, wparam, lparam); \
599
659
}
600
660
 
601
661
_CALLBACK_PRINTER(0)
602
662
_CALLBACK_PRINTER(4)
603
663
_CALLBACK_PRINTER(5)
604
664
 
 
665
 
605
666
/* -------------------------------------------------------------------------- */
606
667
/*                               Main Dialog                                  */
607
668
/* -------------------------------------------------------------------------- */
608
669
 
609
 
void ui_peripheral_dialog(HWND hwnd)
 
670
static void uiperipheral_dialog(HWND hwnd)
610
671
{
611
672
    PROPSHEETPAGE psp[7];
612
673
    PROPSHEETHEADER psh;
613
674
    int i, no_of_drives, no_of_printers;
614
675
 
615
 
    for( i = 0; i < 3; i++ )
616
 
      {
617
 
        printertextdevice[i] = (char *) lib_malloc(MAX_PATH);
 
676
    for (i = 0; i < 3; i++ ) {
 
677
        printertextdevice[i] = (char *)lib_malloc(MAX_PATH);
618
678
        strcpy(printertextdevice[i], "");
619
 
      }
 
679
    }
620
680
 
621
 
    no_of_drives   = 4;
 
681
    no_of_drives = 4;
622
682
    no_of_printers = 2;
623
683
 
624
 
    if( have_printer_userport<0 )
625
 
      have_printer_userport = (resources_touch("PrinterUserport"))<0 ? 0 : 1;
626
 
    if( have_printer_userport ) no_of_printers++;
 
684
    if (have_printer_userport < 0)
 
685
        have_printer_userport = (resources_touch("PrinterUserport")) < 0
 
686
                                ? 0 : 1;
 
687
    if (have_printer_userport)
 
688
        no_of_printers++;
627
689
 
628
690
    for (i = 0; i < no_of_printers; i++) {
629
691
        psp[i].dwSize = sizeof(PROPSHEETPAGE);
633
695
        psp[i].pszTemplate = MAKEINTRESOURCE(IDD_PRINTER_SETTINGS_DIALOG);
634
696
        psp[i].pszIcon = NULL;
635
697
#else
636
 
        psp[i].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_PRINTER_SETTINGS_DIALOG);
 
698
        psp[i].DUMMYUNIONNAME.pszTemplate
 
699
            = MAKEINTRESOURCE(IDD_PRINTER_SETTINGS_DIALOG);
637
700
        psp[i].u2.pszIcon = NULL;
638
701
#endif
639
702
        psp[i].lParam = 0;
641
704
    }
642
705
 
643
706
    for (i = 0; i < no_of_drives; i++) {
644
 
        psp[no_of_printers+i].dwSize = sizeof(PROPSHEETPAGE);
645
 
        psp[no_of_printers+i].dwFlags = PSP_USETITLE /*| PSP_HASHELP*/ ;
646
 
        psp[no_of_printers+i].hInstance = winmain_instance;
 
707
        psp[no_of_printers + i].dwSize = sizeof(PROPSHEETPAGE);
 
708
        psp[no_of_printers + i].dwFlags = PSP_USETITLE /*| PSP_HASHELP*/ ;
 
709
        psp[no_of_printers + i].hInstance = winmain_instance;
647
710
#ifdef _ANONYMOUS_UNION
648
 
        psp[no_of_printers+i].pszTemplate = MAKEINTRESOURCE(IDD_DISKDEVICE_DIALOG);
649
 
        psp[no_of_printers+i].pszIcon = NULL;
 
711
        psp[no_of_printers + i].pszTemplate
 
712
            = MAKEINTRESOURCE(IDD_DISKDEVICE_DIALOG);
 
713
        psp[no_of_printers + i].pszIcon = NULL;
650
714
#else
651
 
        psp[no_of_printers+i].DUMMYUNIONNAME.pszTemplate = MAKEINTRESOURCE(IDD_DISKDEVICE_DIALOG);
652
 
        psp[no_of_printers+i].u2.pszIcon = NULL;
 
715
        psp[no_of_printers + i].DUMMYUNIONNAME.pszTemplate
 
716
            = MAKEINTRESOURCE(IDD_DISKDEVICE_DIALOG);
 
717
        psp[no_of_printers + i].u2.pszIcon = NULL;
653
718
#endif
654
 
        psp[no_of_printers+i].lParam = 0;
655
 
        psp[no_of_printers+i].pfnCallback = NULL;
 
719
        psp[no_of_printers + i].lParam = 0;
 
720
        psp[no_of_printers + i].pfnCallback = NULL;
656
721
    }
657
722
 
658
 
    if( have_printer_userport )
659
 
      {
 
723
    if (have_printer_userport) {
660
724
        psp[0].pfnDlgProc = callback_0;
661
 
        psp[0].pszTitle = "Printer Userport";
 
725
        psp[0].pszTitle = TEXT("Printer Userport");
662
726
        i = 1;
663
 
      }
664
 
    else 
665
 
      i = 0;
666
 
    psp[i+0].pfnDlgProc = callback_4;
667
 
    psp[i+0].pszTitle = "Printer 4";
668
 
    psp[i+1].pfnDlgProc = callback_5;
669
 
    psp[i+1].pszTitle = "Printer 5";
670
 
    psp[i+2].pfnDlgProc = callback_8;
671
 
    psp[i+2].pszTitle = "Drive 8";
672
 
    psp[i+3].pfnDlgProc = callback_9;
673
 
    psp[i+3].pszTitle = "Drive 9";
674
 
    psp[i+4].pfnDlgProc = callback_10;
675
 
    psp[i+4].pszTitle = "Drive 10";
676
 
    psp[i+5].pfnDlgProc = callback_11;
677
 
    psp[i+5].pszTitle = "Drive 11";
 
727
    } else
 
728
        i = 0;
 
729
 
 
730
    psp[i + 0].pfnDlgProc = callback_4;
 
731
    psp[i + 0].pszTitle = TEXT("Printer 4");
 
732
    psp[i + 1].pfnDlgProc = callback_5;
 
733
    psp[i + 1].pszTitle = TEXT("Printer 5");
 
734
    psp[i + 2].pfnDlgProc = callback_8;
 
735
    psp[i + 2].pszTitle = TEXT("Drive 8");
 
736
    psp[i + 3].pfnDlgProc = callback_9;
 
737
    psp[i + 3].pszTitle = TEXT("Drive 9");
 
738
    psp[i + 4].pfnDlgProc = callback_10;
 
739
    psp[i + 4].pszTitle = TEXT("Drive 10");
 
740
    psp[i + 5].pfnDlgProc = callback_11;
 
741
    psp[i + 5].pszTitle = TEXT("Drive 11");
678
742
 
679
743
    psh.dwSize = sizeof(PROPSHEETHEADER);
680
744
    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
681
745
    psh.hwndParent = hwnd;
682
746
    psh.hInstance = winmain_instance;
683
 
    psh.pszCaption = "Peripheral Settings";
 
747
    psh.pszCaption = TEXT("Peripheral Settings");
684
748
    psh.nPages = no_of_drives + no_of_printers;
685
749
#ifdef _ANONYMOUS_UNION
686
750
    psh.pszIcon = NULL;
687
 
    psh.nStartPage = 0;
 
751
    psh.nStartPage = i + 2;
688
752
    psh.ppsp = psp;
689
753
#else
690
754
    psh.DUMMYUNIONNAME.pszIcon = NULL;
691
 
    psh.u2.nStartPage = 0;
 
755
    psh.u2.nStartPage = i + 2;
692
756
    psh.u3.ppsp = psp;
693
757
#endif
694
758
    psh.pfnCallback = NULL;
695
759
 
696
760
    PropertySheet(&psh);
697
761
 
698
 
    for( i = 0; i < 3; i++ )
699
 
      lib_free(printertextdevice[i]);
 
762
    for (i = 0; i < 3; i++)
 
763
        lib_free(printertextdevice[i]);
 
764
}
 
765
 
 
766
void uiperipheral_command(HWND hwnd, WPARAM wparam)
 
767
{
 
768
    switch (wparam) {
 
769
      case IDM_DEVICEMANAGER:
 
770
        uiperipheral_dialog(hwnd);
 
771
        break;
 
772
      case IDM_FORMFEED_PRINTERIEC4 | 0x00010000:
 
773
        printer_formfeed(0);
 
774
        break;
 
775
      case IDM_FORMFEED_PRINTERIEC5 | 0x00010000:
 
776
        printer_formfeed(1);
 
777
        break;
 
778
    }
700
779
}
701
780