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

« back to all changes in this revision

Viewing changes to src/arch/win32/uilib.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 "vice.h"
32
32
 
 
33
#include <stdio.h>
33
34
#include <string.h>
34
35
#include <windows.h>
35
36
#include <windowsx.h>
 
37
#include <tchar.h>
36
38
#include <commctrl.h>
 
39
#include <commdlg.h>
37
40
 
38
41
#include "archdep.h"
39
42
#include "cbmimage.h"
 
43
#include "cmdline.h"
40
44
#include "diskimage.h"
41
45
#include "fullscrn.h"
42
46
#include "imagecontents.h"
43
47
#include "lib.h"
44
48
#include "res.h"
45
49
#include "resources.h"
 
50
#include "system.h"
46
51
#include "ui.h"
47
52
#include "uilib.h"
48
53
#include "util.h"
60
65
static int *autostart_result;
61
66
static char* fontfile;
62
67
static int font_loaded;
63
 
 
64
 
static struct { char *name; char *pattern; } uilib_filefilter[] = {
65
 
    { "All files (*.*)", "*.*" },
66
 
    { "VICE palette files (*.vpl)", "*.vpl" },
67
 
    { "VICE snapshot files (*.vsf)", "*.vsf" },
68
 
    { "Disk image files (*.d64;*.d71;*.d80;*.d81;*.d82;*.g64;*.g41;*.x64)",
69
 
        "*.d64;*.d71;*.d80;*.d81;*.d82;*.g64;*.g41;*.x64" },
70
 
    { "Tape image files (*.t64;*.p00;*.tap;*.prg)",
71
 
        "*.t64;*.p00;*.tap;*.prg" },
72
 
    { "Zipped files (*.zip;*.bz2;*.gz;*.d6z;*.d7z;*.d8z;*.g6z;*.g4z;*.x6z)",
73
 
        "*.zip;*.bz2;*.gz;*.d6z;*.d7z;*.d8z;*.g6z;*.g4z;*.x6z" },
74
 
    { "CRT cartridge image files (*.crt)", "*.crt" },
75
 
    { "Raw cartridge image files (*.bin)", "*.bin" },
76
 
    { "Flip list files (*.vfl)", "*.vfl" },
 
68
static char *res_readonly;
 
69
 
 
70
struct uilib_filefilter_s {
 
71
    TCHAR *name;
 
72
    TCHAR *pattern;
 
73
};
 
74
typedef struct uilib_filefilter_s uilib_filefilter_t;
 
75
 
 
76
static uilib_filefilter_t uilib_filefilter[] = {
 
77
    { TEXT("All files (*.*)"), TEXT("*.*") },
 
78
    { TEXT("VICE palette files (*.vpl)"), TEXT("*.vpl") },
 
79
    { TEXT("VICE snapshot files (*.vsf)"), TEXT("*.vsf") },
 
80
    { TEXT("Disk image files (*.d64;*.d71;*.d80;*.d81;*.d82;*.g64;*.g41;*.x64)"),
 
81
      TEXT("*.d64;*.d71;*.d80;*.d81;*.d82;*.g64;*.g41;*.x64") },
 
82
    { TEXT("Tape image files (*.t64;*.p00;*.tap;*.prg)"),
 
83
      TEXT("*.t64;*.p00;*.tap;*.prg") },
 
84
    { TEXT("Zipped files (*.zip;*.bz2;*.gz;*.d6z;*.d7z;*.d8z;*.g6z;*.g4z;*.x6z)"),
 
85
      TEXT("*.zip;*.bz2;*.gz;*.d6z;*.d7z;*.d8z;*.g6z;*.g4z;*.x6z") },
 
86
    { TEXT("CRT cartridge image files (*.crt)"), TEXT("*.crt") },
 
87
    { TEXT("Raw cartridge image files (*.bin)"), TEXT("*.bin") },
 
88
    { TEXT("VICE flip list files (*.vfl)"), TEXT("*.vfl") },
 
89
    { TEXT("VICE romset files (*.vrs)"), TEXT("*.vrs") },
 
90
    { TEXT("VICE romset archives (*.vra)"), TEXT("*.vra") },
 
91
    { TEXT("VICE keymap files (*.vkm)"), TEXT("*.vkm") },
77
92
    { NULL, NULL }
78
93
};
79
94
 
80
 
typedef struct {
 
95
struct uilib_fs_style_type_s {
81
96
    char *(*content_read_function)(const char *);
82
97
    LPOFNHOOKPROC hook_proc;
83
98
    int TemplateID;
84
99
    char *initialdir_resource;
85
 
} ui_file_selector_style_type;
 
100
    char *file_resource;
 
101
};
 
102
typedef struct uilib_fs_style_type_s uilib_fs_style_type_t;
86
103
 
87
 
static UINT APIENTRY tape_hook_proc(HWND hwnd, UINT uimsg, WPARAM wparam,
88
 
                                    LPARAM lparam);
89
 
static UINT APIENTRY hook_proc(HWND hwnd, UINT uimsg, WPARAM wparam,
90
 
                               LPARAM lparam);
 
104
static UINT APIENTRY uilib_select_tape_hook_proc(HWND hwnd, UINT uimsg,
 
105
                                                 WPARAM wparam, LPARAM lparam);
 
106
static UINT APIENTRY uilib_select_hook_proc(HWND hwnd, UINT uimsg,
 
107
                                            WPARAM wparam, LPARAM lparam);
91
108
 
92
109
static char *read_disk_image_contents(const char *name);
93
110
static char *read_tape_image_contents(const char *name);
94
111
static char *read_disk_or_tape_image_contents(const char *name);
95
112
 
96
 
static ui_file_selector_style_type styles[NUM_OF_FILE_SELECTOR_STYLES + 1] = {
97
 
    /* FILE_SELECTOR_DEFAULT_STYLE */
 
113
static uilib_fs_style_type_t styles[UILIB_SELECTOR_STYLES_NUM + 1] = {
 
114
    /* UILIB_SELECTOR_STYLE_DEFAULT */
98
115
    { NULL,
99
 
      NULL, 0, "InitialDefaultDir" },
100
 
    /* FILE_SELECTOR_TAPE_STYLE */
 
116
      NULL, 0, "InitialDefaultDir", NULL },
 
117
    /* UILIB_SELECTOR_STYLE_TAPE */
101
118
    { read_tape_image_contents,
102
 
      tape_hook_proc, IDD_OPENTAPE_TEMPLATE, "InitialTapeDir" },
103
 
    /* FILE_SELECTOR_DISK_STYLE */
 
119
      uilib_select_tape_hook_proc, IDD_OPENTAPE_TEMPLATE, "InitialTapeDir",
 
120
      NULL },
 
121
    /* UILIB_SELECTOR_STYLE_DISK */
104
122
    { read_disk_image_contents,
105
 
      hook_proc, IDD_OPEN_TEMPLATE, "InitialDiskDir" },
106
 
    /* FILE_SELECTOR_DISK_AND_TAPE_STYLE */
 
123
      uilib_select_hook_proc, IDD_OPEN_TEMPLATE, "InitialDiskDir", NULL },
 
124
    /* UILIB_SELECTOR_STYLE_DISK_AND_TAPE */
107
125
    { read_disk_or_tape_image_contents,
108
 
      hook_proc, IDD_OPEN_TEMPLATE, "InitialAutostartDir"},
109
 
    /* FILE_SELECTOR_CART_STYLE */
110
 
    { NULL,
111
 
      NULL, 0, "InitialCartDir" },
112
 
    /* FILE_SELECTOR_SNAPSHOT_STYLE */
113
 
    { NULL,
114
 
      NULL, 0, "InitialSnapshotDir" },
115
 
    /* DIR_SELECTOR_EVENT_STYLE */
116
 
    { NULL,
117
 
      NULL, 0, "EventSnapshotDir" },
 
126
      uilib_select_hook_proc, IDD_OPEN_TEMPLATE, "InitialAutostartDir", NULL },
 
127
    /* UILIB_SELECTOR_STYLE_CART */
 
128
    { NULL,
 
129
      NULL, 0, "InitialCartDir", NULL },
 
130
    /* UILIB_SELECTOR_STYLE_SNAPSHOT */
 
131
    { NULL,
 
132
      NULL, 0, "InitialSnapshotDir", NULL },
 
133
    /* UILIB_SELECTOR_STYLE_EVENT_START */
 
134
    { NULL,
 
135
      NULL, 0, "EventSnapshotDir", "EventStartSnapshot" },
 
136
    /* UILIB_SELECTOR_STYLE_EVENT_END */
 
137
    { NULL,
 
138
      NULL, 0, "EventSnapshotDir", "EventEndSnapshot"  },
118
139
    /* DUMMY entry Insert new styles before this */
119
140
    { NULL,
120
 
      NULL, 0, NULL }
 
141
      NULL, 0, NULL, NULL }
121
142
};
122
143
 
123
 
static char *ui_file_selector_initialfile[NUM_OF_FILE_SELECTOR_STYLES];
 
144
static TCHAR *ui_file_selector_initialfile[UILIB_SELECTOR_STYLES_NUM];
124
145
 
125
146
 
126
147
static char *read_disk_image_contents(const char *name)
169
190
 
170
191
static HFONT hfont;
171
192
 
172
 
static UINT APIENTRY tape_hook_proc(HWND hwnd, UINT uimsg, WPARAM wparam,
173
 
                                    LPARAM lparam)
 
193
static UINT APIENTRY uilib_select_tape_hook_proc(HWND hwnd, UINT uimsg,
 
194
                                                 WPARAM wparam, LPARAM lparam)
174
195
{
175
196
    HWND preview;
176
197
    char *contents;
182
203
    preview = GetDlgItem(hwnd, IDC_PREVIEW);
183
204
    switch (uimsg) {
184
205
      case WM_INITDIALOG:
185
 
        SetWindowText(GetDlgItem(GetParent(hwnd), IDOK), "&Attach");
 
206
        SetWindowText(GetDlgItem(GetParent(hwnd), IDOK), TEXT("&Attach"));
186
207
 
187
208
        if (font_loaded)
188
209
            hfont = CreateFont(-12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
205
226
                if (!(GetFileAttributes(filename)
206
227
                    & FILE_ATTRIBUTE_DIRECTORY)) {
207
228
                    if (read_content_func != NULL) {
208
 
                        contents=read_content_func(filename);
 
229
                        contents = read_content_func(filename);
209
230
                        create_content_list(contents, preview);
 
231
                        lib_free(contents);
210
232
                    }
211
233
                }
212
234
            }
213
235
        } else if (((OFNOTIFY*)lparam)->hdr.code == CDN_FOLDERCHANGE) {
214
236
            SendMessage(preview, LB_RESETCONTENT, 0, 0);
215
 
            SetWindowText(GetDlgItem(GetParent(hwnd), 0x0480), "");
 
237
            SetWindowText(GetDlgItem(GetParent(hwnd), 0x0480), TEXT(""));
216
238
        }
217
239
        break;
218
240
      case WM_COMMAND:
235
257
                }
236
258
            }
237
259
            if (SendMessage(GetParent(hwnd),
238
 
                CDM_GETFILEPATH, 256, (LPARAM)filename) >= 0)
239
 
            {
 
260
                CDM_GETFILEPATH, 256, (LPARAM)filename) >= 0) {
240
261
                if (append_extension) {
241
262
                    strcat(filename, ".");
242
263
                    strcat(filename, "tap");
243
264
                }
244
265
                if (util_file_exists(filename)) {
245
266
                    int ret;
246
 
                    ret = ui_messagebox("Overwrite existing image?",
247
 
                                        "VICE question",
 
267
                    ret = ui_messagebox(TEXT("Overwrite existing image?"),
 
268
                                        TEXT("VICE question"),
248
269
                                        MB_YESNO | MB_ICONQUESTION);
249
270
                    if (ret != IDYES)
250
271
                        return -1;
282
303
    return 0;
283
304
}
284
305
 
285
 
static char *image_type_name[] = 
286
 
    { "d64", "d71", "d80", "d81", "d82", "g64", "x64", NULL };
 
306
static TCHAR *image_type_name[] = 
 
307
    { TEXT("d64"), TEXT("d71"), TEXT("d80"), TEXT("d81"), TEXT("d82"),
 
308
      TEXT("g64"), TEXT("x64"), NULL };
287
309
 
288
310
static int image_type[] = {
289
311
    DISK_IMAGE_TYPE_D64,
295
317
    DISK_IMAGE_TYPE_X64
296
318
};
297
319
 
298
 
static UINT APIENTRY hook_proc(HWND hwnd, UINT uimsg, WPARAM wparam,
299
 
                               LPARAM lparam)
 
320
static UINT APIENTRY uilib_select_hook_proc(HWND hwnd, UINT uimsg,
 
321
                                            WPARAM wparam, LPARAM lparam)
300
322
{
301
323
    HWND preview;
302
324
    HWND image_type_list;
303
325
    char *contents;
304
326
    char filename[256];
 
327
    TCHAR st_filename[256];
305
328
    int counter;
306
329
    int msg_type;
307
330
    int append_extension = 0;
308
 
    int is_it_standard_extension=0;
 
331
    int is_it_standard_extension = 0;
309
332
    char *extension;
310
333
    int index;
311
334
    LV_FINDINFO find;
312
335
    LV_ITEM item;
313
336
 
314
 
    preview = GetDlgItem(hwnd,IDC_PREVIEW);
 
337
    preview = GetDlgItem(hwnd, IDC_PREVIEW);
315
338
    switch (uimsg) {
316
339
      case WM_INITDIALOG:
317
340
        SetWindowText(GetDlgItem(GetParent(hwnd), IDOK), "&Attach");
325
348
        /* Try to use the cbm font */
326
349
        if (font_loaded)
327
350
            hfont = CreateFont(-12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
328
 
                0, 0, "cbm-directory-charset/ck!");
 
351
                               0, 0, "cbm-directory-charset/ck!");
329
352
        else
330
353
            /*  maybe there's a better font-definition (FIXME) */
331
354
            /*  I think it's OK now (Tibor) */
332
355
            hfont = CreateFont(-12, -7, 0, 0, 400, 0, 0, 0, 0, 0, 0,
333
 
                DRAFT_QUALITY, FIXED_PITCH | FF_MODERN, NULL);
 
356
                               DRAFT_QUALITY, FIXED_PITCH | FF_MODERN, NULL);
334
357
 
335
358
        if (hfont) {
336
359
            SendDlgItemMessage(hwnd, IDC_PREVIEW, WM_SETFONT,
337
360
                (WPARAM)hfont, MAKELPARAM(TRUE, 0));
338
361
        }
339
 
        SetDlgItemText(hwnd, IDC_BLANK_IMAGE_NAME, "vice");
340
 
        SetDlgItemText(hwnd, IDC_BLANK_IMAGE_ID, "1a");
 
362
        SetDlgItemText(hwnd, IDC_BLANK_IMAGE_NAME, TEXT("vice"));
 
363
        SetDlgItemText(hwnd, IDC_BLANK_IMAGE_ID, TEXT("1a"));
 
364
        if (res_readonly != NULL) {
 
365
            int ro;
 
366
            resources_get_value(res_readonly, &ro);
 
367
            CheckDlgButton(hwnd, IDC_TOGGLE_ATTACH_READONLY,
 
368
                       ro ? BST_CHECKED : BST_UNCHECKED);
 
369
        } else {
 
370
            EnableWindow(GetDlgItem(hwnd, IDC_TOGGLE_ATTACH_READONLY),  FALSE);
 
371
        }
341
372
        break;
342
373
      case WM_NOTIFY:
343
 
        if (((OFNOTIFY*)lparam)->hdr.code == CDN_SELCHANGE) {
 
374
        if (((OFNOTIFY *)lparam)->hdr.code == CDN_SELCHANGE) {
344
375
            SendMessage(preview, LB_RESETCONTENT, 0, 0);
345
376
            if (SendMessage(((OFNOTIFY*)lparam)->hdr.hwndFrom,
346
 
                CDM_GETFILEPATH, 256, (LPARAM)filename) >= 0) {
347
 
                     if (!(GetFileAttributes(filename)&FILE_ATTRIBUTE_DIRECTORY)) {
 
377
                CDM_GETFILEPATH, 256, (LPARAM)st_filename) >= 0) {
 
378
                     if (!(GetFileAttributes(st_filename)
 
379
                         & FILE_ATTRIBUTE_DIRECTORY)) {
348
380
                         if (read_content_func != NULL) {
 
381
                             system_wcstombs(filename, st_filename, 256);
349
382
                             contents = read_content_func(filename);
350
383
                             create_content_list(contents, preview);
 
384
                             lib_free(contents);
351
385
                         }
352
386
                     }
353
 
            } else if (((OFNOTIFY*)lparam)->hdr.code == CDN_FOLDERCHANGE) {
 
387
            } else if (((OFNOTIFY *)lparam)->hdr.code == CDN_FOLDERCHANGE) {
354
388
                SendMessage(preview, LB_RESETCONTENT, 0, 0);
355
389
                SetWindowText(GetDlgItem(GetParent(hwnd), 0x0480), "");
356
390
            }
359
393
      case WM_COMMAND:
360
394
        msg_type = LOWORD(wparam);
361
395
        switch (msg_type) {
 
396
          case IDC_TOGGLE_ATTACH_READONLY:
 
397
            if (res_readonly)
 
398
                resources_set_value(res_readonly, 
 
399
                          (resource_value_t)(IsDlgButtonChecked(hwnd,
 
400
                          IDC_TOGGLE_ATTACH_READONLY) == BST_CHECKED));
 
401
            break;
362
402
          case IDC_BLANK_IMAGE:
363
403
            if (SendMessage(GetParent(hwnd),
364
 
                CDM_GETSPEC, 256, (LPARAM)filename) <= 1) {
 
404
                CDM_GETSPEC, 256, (LPARAM)st_filename) <= 1) {
365
405
                ui_error("Please enter a filename.");
366
406
                return -1;
367
407
            }
368
 
            if (strchr(filename,'.') == NULL) {
 
408
            if (_tcschr(st_filename, '.') == NULL) {
369
409
                append_extension = 1;
370
410
                is_it_standard_extension = 1;
371
411
            } else {
372
412
                /*  Find last dot in name */
373
 
                extension = strrchr(filename, '.');
 
413
                extension = _tcsrchr(st_filename, '.');
374
414
                /*  Skip dot */
375
415
                extension++;
376
416
                /*  Figure out if it's a standard extension */
377
417
                for (counter = 0; image_type_name[counter]; counter++) {
378
 
                    if (strncasecmp(extension,image_type_name[counter],
 
418
                    if (strncasecmp(extension, image_type_name[counter],
379
419
                        strlen(image_type_name[counter])) == 0) {
380
420
                        is_it_standard_extension = 1;
381
421
                        break;
383
423
                }
384
424
            }
385
425
            if (SendMessage(GetParent(hwnd),
386
 
                CDM_GETFILEPATH, 256, (LPARAM)filename) >= 0) {
 
426
                CDM_GETFILEPATH, 256, (LPARAM)st_filename) >= 0) {
387
427
                char disk_name[32];
388
428
                char disk_id[3];
389
429
                char *format_name;
391
431
                counter = SendMessage(GetDlgItem(hwnd, IDC_BLANK_IMAGE_TYPE),
392
432
                                                 CB_GETCURSEL, 0, 0);
393
433
                if (append_extension) {
394
 
                    strcat(filename,".");
395
 
                    strcat(filename,image_type_name[counter]);
 
434
                    _tcscat(st_filename, TEXT("."));
 
435
                    _tcscat(st_filename, image_type_name[counter]);
396
436
                }
397
 
                if (util_file_exists(filename)) {
 
437
                system_wcstombs(filename, st_filename, 256);
 
438
                if (util_file_exists(st_filename)) {
398
439
                    int ret;
399
 
                    ret = ui_messagebox("Overwrite existing image?",
400
 
                                        "VICE question",
401
 
                                         MB_YESNO | MB_ICONQUESTION);
 
440
                    ret = ui_messagebox(TEXT("Overwrite existing image?"),
 
441
                                        TEXT("VICE question"),
 
442
                                        MB_YESNO | MB_ICONQUESTION);
402
443
                    if (ret != IDYES)
403
444
                        return -1;
404
445
                }
405
446
                GetDlgItemText(hwnd, IDC_BLANK_IMAGE_NAME, disk_name, 17);
406
447
                GetDlgItemText(hwnd, IDC_BLANK_IMAGE_ID, disk_id, 3);
407
448
                format_name = lib_msprintf("%s,%s", disk_name, disk_id);
408
 
                if (vdrive_internal_create_format_disk_image(filename,
 
449
                if (vdrive_internal_create_format_disk_image(st_filename,
409
450
                    format_name, image_type[counter]) < 0) {
410
451
                    ui_error("Cannot create image");
411
452
                    lib_free(format_name);
436
477
 
437
478
                /*  Now find filename in ListView & select it */
438
479
                SendMessage(GetParent(hwnd), CDM_GETSPEC, 256,
439
 
                            (LPARAM)filename);
 
480
                            (LPARAM)st_filename);
440
481
                if (append_extension) {
441
 
                    strcat(filename, ".");
442
 
                    strcat(filename, image_type_name[counter]);
 
482
                    _tcscat(st_filename, TEXT("."));
 
483
                    _tcscat(st_filename, image_type_name[counter]);
443
484
                }
444
485
                find.flags = LVFI_STRING;
445
 
                find.psz = filename;
 
486
                find.psz = st_filename;
446
487
                index = SendMessage(GetDlgItem(GetDlgItem(GetParent(hwnd),
447
488
                        0x461), 1), LVM_FINDITEM, -1, (LPARAM)&find);
448
489
                item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
453
494
            break;
454
495
        }
455
496
        switch (HIWORD(wparam)) {
456
 
            case LBN_DBLCLK:
457
 
                if (autostart_result != NULL) {
458
 
                    index = SendMessage((HWND)lparam, LB_GETCURSEL, 0, 0);
459
 
                    if (SendMessage(GetParent(hwnd),
460
 
                        CDM_GETFILEPATH, 256, (LPARAM)filename) >= 0) {
461
 
                        *autostart_result = index;
462
 
                        SendMessage(GetParent(hwnd), WM_COMMAND,
463
 
                                    MAKELONG(IDOK,BN_CLICKED),
464
 
                                    (LPARAM)GetDlgItem(GetParent(hwnd), IDOK));
465
 
                    }
 
497
          case LBN_DBLCLK:
 
498
            if (autostart_result != NULL) {
 
499
                index = SendMessage((HWND)lparam, LB_GETCURSEL, 0, 0);
 
500
                if (SendMessage(GetParent(hwnd),
 
501
                    CDM_GETFILEPATH, 256, (LPARAM)st_filename) >= 0) {
 
502
                    *autostart_result = index;
 
503
                    SendMessage(GetParent(hwnd), WM_COMMAND,
 
504
                                MAKELONG(IDOK,BN_CLICKED),
 
505
                                (LPARAM)GetDlgItem(GetParent(hwnd), IDOK));
466
506
                }
467
 
                break;
 
507
            }
 
508
            break;
468
509
        }
469
510
        break;
470
511
      case WM_DESTROY:
492
533
    DWORD b;
493
534
    int j = 0;
494
535
 
495
 
    for (b = 1; b <= filterbit; b <<=1) {
 
536
    for (b = 1; b <= filterbit; b <<= 1) {
496
537
        if (filterlist & b)
497
538
            j++;
498
539
        if (b == filterbit)
518
559
    }
519
560
}
520
561
 
521
 
static void set_filter(char *filter, DWORD filterlist, DWORD *filterindex)
 
562
static TCHAR *set_filter(DWORD filterlist, DWORD *filterindex)
522
563
{
523
564
    DWORD i, j, k, l;
524
565
    DWORD b;
525
 
    char *s = filter;
 
566
    TCHAR *filter, *current;
 
567
 
 
568
    filter = lib_malloc(UILIB_FILTER_LENGTH_MAX * sizeof(TCHAR));
 
569
 
 
570
    current = filter;
526
571
 
527
572
    last_filterlist = filterlist;
528
573
 
531
576
    /* create the strings for the file filters */
532
577
    for (i = 0, b = 1; uilib_filefilter[i].name != NULL; i++, b <<= 1) {
533
578
        if (filterlist & b) {
534
 
            j = strlen(uilib_filefilter[i].name) + 1;
535
 
            memcpy(s, uilib_filefilter[i].name, j);
536
 
            s += j;
537
 
 
538
 
            j = strlen(uilib_filefilter[i].pattern) + 1;
539
 
            memcpy(s, uilib_filefilter[i].pattern, j);
540
 
            s += j;
541
 
 
 
579
            j = _tcslen(uilib_filefilter[i].name) + 1;
 
580
            memcpy(current, uilib_filefilter[i].name, j * sizeof(TCHAR));
 
581
            current += j;
 
582
 
 
583
            j = _tcslen(uilib_filefilter[i].pattern) + 1;
 
584
            memcpy(current, uilib_filefilter[i].pattern, j * sizeof(TCHAR));
 
585
            current += j;
542
586
        }
543
587
    }
544
 
    *s = 0;
 
588
 
 
589
    *current = TEXT('\0');
545
590
 
546
591
    /* search for the most recent file filter */
547
592
    for (k = 1; k <= UI_LIB_FILTER_HISTORY_LENGTH && *filterindex == 0; k++) {
553
598
    if (*filterindex == 0)
554
599
        *filterindex = 1;    /* not in history: choose first filter */
555
600
 
 
601
    return filter;
556
602
}
557
603
 
558
604
static int CALLBACK EnumFontProc(
567
613
}
568
614
 
569
615
 
570
 
char *ui_select_file(HWND hwnd, const char *title, DWORD filterlist,
571
 
                     int style, int *autostart)
 
616
TCHAR *uilib_select_file_autostart(HWND hwnd, const TCHAR *title,
 
617
                                   DWORD filterlist, unsigned int type,
 
618
                                   int style, int *autostart,
 
619
                                   char *resource_readonly)
572
620
{
573
 
    char name[1024] = "";
574
 
    char *initialdir;
575
 
    char filter[UI_LIB_MAX_FILTER_LENGTH];
 
621
    TCHAR st_name[MAX_PATH];
 
622
    char name[MAX_PATH];
 
623
    char *initialdir = NULL;
 
624
    char *initialfile;
 
625
    TCHAR *filter;
576
626
    DWORD filterindex;
577
627
    OPENFILENAME ofn;
578
628
    int result;
 
629
    char *ret = NULL;
579
630
 
580
631
    if (styles[style].initialdir_resource != NULL)
581
632
        resources_get_value(styles[style].initialdir_resource,
582
633
            (void *)&initialdir);
583
634
 
584
 
    if (ui_file_selector_initialfile[style] != NULL)
585
 
        strcpy(name, ui_file_selector_initialfile[style]);
586
 
 
587
 
    if (style == DIR_SELECTOR_EVENT_STYLE)
588
 
        strcpy(name, "FilenameNotUsed");
 
635
    if (type == UILIB_SELECTOR_TYPE_DIR_EXIST)
 
636
        _tcscpy(st_name, TEXT("FilenameNotUsed"));
 
637
    else
 
638
        _tcscpy(st_name, TEXT(""));
 
639
 
 
640
    initialfile = ui_file_selector_initialfile[style];
 
641
    if (styles[style].file_resource != NULL)
 
642
        resources_get_value(styles[style].file_resource,
 
643
            (void *)&initialfile);
 
644
 
 
645
    if (initialfile != NULL)
 
646
        _tcscpy(st_name, initialfile);
589
647
 
590
648
    if (fontfile == NULL) {
591
649
        fontfile = util_concat(archdep_boot_path(), 
598
656
        }
599
657
    }
600
658
 
 
659
    filter = set_filter(filterlist, &filterindex);
 
660
 
601
661
    memset(&ofn, 0, sizeof(ofn));
602
662
    ofn.lStructSize = sizeof(ofn);
603
663
    ofn.hwndOwner = hwnd;
604
664
    ofn.hInstance = winmain_instance;
605
 
    set_filter(filter, filterlist, &filterindex);
606
665
    ofn.lpstrFilter = filter;
607
666
    ofn.lpstrCustomFilter = NULL;
608
667
    ofn.nMaxCustFilter = 0;
609
668
    ofn.nFilterIndex = filterindex;
610
 
    ofn.lpstrFile = name;
611
 
    ofn.nMaxFile = sizeof(name);
 
669
    ofn.lpstrFile = st_name;
 
670
    ofn.nMaxFile = sizeof(st_name);
612
671
    ofn.lpstrFileTitle = NULL;
613
672
    ofn.nMaxFileTitle = 0;
614
673
    ofn.lpstrInitialDir = initialdir;
615
674
    ofn.lpstrTitle = title;
616
 
    if (styles[style].TemplateID!=0) {
617
 
        ofn.Flags = (OFN_EXPLORER
618
 
                     | OFN_HIDEREADONLY
619
 
                     | OFN_NOTESTFILECREATE
620
 
                     | OFN_ENABLEHOOK
621
 
                     | OFN_ENABLETEMPLATE
622
 
                     | OFN_SHAREAWARE
623
 
                     | OFN_ENABLESIZING);
 
675
    ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOTESTFILECREATE
 
676
                | OFN_SHAREAWARE | OFN_ENABLESIZING;
 
677
    if (styles[style].TemplateID != 0) {
 
678
        ofn.Flags |= OFN_ENABLEHOOK | OFN_ENABLETEMPLATE;
624
679
        ofn.lpfnHook = styles[style].hook_proc;
625
680
        ofn.lpTemplateName = MAKEINTRESOURCE(styles[style].TemplateID);
626
681
    } else {
627
 
        ofn.Flags = (OFN_EXPLORER
628
 
                     | OFN_HIDEREADONLY
629
 
                     | OFN_NOTESTFILECREATE
630
 
                     | OFN_SHAREAWARE);
631
682
        ofn.lpfnHook = NULL;
632
683
        ofn.lpTemplateName = NULL;
633
684
    }
634
 
    if (style != DIR_SELECTOR_EVENT_STYLE)
 
685
    if (type == UILIB_SELECTOR_TYPE_FILE_LOAD)
635
686
        ofn.Flags |= OFN_FILEMUSTEXIST;
636
687
 
637
688
    ofn.nFileOffset = 0;
638
689
    ofn.nFileExtension = 0;
639
690
    ofn.lpstrDefExt = NULL;
640
691
 
641
 
    read_content_func=styles[style].content_read_function;
642
 
    autostart_result=autostart;
 
692
    read_content_func = styles[style].content_read_function;
 
693
    autostart_result = autostart;
 
694
    res_readonly = resource_readonly;
643
695
    vsync_suspend_speed_eval();
644
 
    result = GetOpenFileName(&ofn);
 
696
 
 
697
    if (type == UILIB_SELECTOR_TYPE_FILE_SAVE)
 
698
        result = GetSaveFileName(&ofn);
 
699
    else
 
700
        result = GetOpenFileName(&ofn);
 
701
 
645
702
    update_filter_history(ofn.nFilterIndex);
 
703
 
646
704
    if (result) {
 
705
        char *tmpdir, *tmpfile;
 
706
 
647
707
        if (ui_file_selector_initialfile[style] != NULL)
648
708
            lib_free(ui_file_selector_initialfile[style]);
649
 
        util_fname_split(name, &initialdir, 
650
 
            &ui_file_selector_initialfile[style]);
651
 
        resources_set_value(styles[style].initialdir_resource, initialdir);
652
 
        return lib_stralloc(name);
653
 
    } else {
654
 
        return NULL;
655
 
    }
656
 
}
657
 
 
 
709
        system_wcstombs(name, st_name, MAX_PATH);
 
710
        util_fname_split(name, &tmpdir, &tmpfile);
 
711
        if (styles[style].file_resource != NULL)
 
712
            resources_set_value(styles[style].file_resource, tmpfile);
 
713
        ui_file_selector_initialfile[style] = system_mbstowcs_alloc(tmpfile);
 
714
        resources_set_value(styles[style].initialdir_resource, tmpdir);
 
715
        ret = system_wcstombs_alloc(st_name);
 
716
 
 
717
        lib_free(tmpdir);
 
718
        lib_free(tmpfile);
 
719
    }
 
720
 
 
721
    lib_free(filter);
 
722
 
 
723
    return ret;
 
724
}
 
725
 
 
726
TCHAR *uilib_select_file(HWND hwnd, const TCHAR *title, DWORD filterlist,
 
727
                         unsigned int type, int style)
 
728
{
 
729
    return uilib_select_file_autostart(hwnd, title, filterlist, type, style,
 
730
                                       NULL, NULL);
 
731
}
 
732
 
 
733
void uilib_select_browse(HWND hwnd, const TCHAR *title, DWORD filterlist,
 
734
                         unsigned int type, int idc)
 
735
{
 
736
    TCHAR *st_name;
 
737
 
 
738
    st_name = uilib_select_file(hwnd, title, filterlist, type,
 
739
                                UILIB_SELECTOR_STYLE_DEFAULT);
 
740
    if (st_name != NULL) {
 
741
        SetDlgItemText(hwnd, idc, st_name);
 
742
        lib_free(st_name);
 
743
    }
 
744
}
658
745
 
659
746
BOOL CALLBACK GetParentEnumProc(HWND hwnd, LPARAM lParam)
660
747
{
800
887
    return FALSE;
801
888
}
802
889
 
 
890
void uilib_show_options(HWND param)
 
891
{
 
892
    char *options;
 
893
 
 
894
    options = cmdline_options_string();
 
895
    ui_show_text(param, "Command line options",
 
896
                 "Which command line options are available?", options);
 
897
    lib_free(options);
 
898
}
 
899
 
 
900
void uilib_shutdown(void)
 
901
{
 
902
    int i;
 
903
 
 
904
    for (i = 0; i < UILIB_SELECTOR_STYLES_NUM; i++)
 
905
        if (ui_file_selector_initialfile[i] != NULL)
 
906
            lib_free(ui_file_selector_initialfile[i]);
 
907
 
 
908
    lib_free(fontfile);
 
909
}
 
910
 
 
911
static uilib_dialogbox_param_t *uilib_dialogbox_param;
 
912
 
 
913
static BOOL CALLBACK uilib_dialogbox_dialog_proc(HWND hwnd, UINT msg,
 
914
                                                 WPARAM wparam, LPARAM lparam)
 
915
{
 
916
    switch (msg) {
 
917
      case WM_COMMAND:
 
918
        switch (LOWORD(wparam)) {
 
919
          case IDOK:
 
920
            GetDlgItemText(hwnd, uilib_dialogbox_param->idc_dialog,
 
921
                           uilib_dialogbox_param->string, UILIB_DIALOGBOX_MAX);
 
922
            uilib_dialogbox_param->updated = 1;
 
923
          case IDCANCEL:
 
924
            EndDialog(hwnd, 0);
 
925
            return TRUE;
 
926
        }
 
927
        return FALSE;
 
928
      case WM_CLOSE:
 
929
        EndDialog(hwnd, 0);
 
930
        return TRUE;
 
931
      case WM_INITDIALOG:
 
932
        SetDlgItemText(hwnd, uilib_dialogbox_param->idc_dialog,
 
933
                       uilib_dialogbox_param->string);
 
934
        return TRUE;
 
935
    }
 
936
    return FALSE;
 
937
}
 
938
 
 
939
 
 
940
void uilib_dialogbox(uilib_dialogbox_param_t *param)
 
941
{
 
942
    uilib_dialogbox_param = param;
 
943
    uilib_dialogbox_param->updated = 0;
 
944
    DialogBox(winmain_instance, (LPCTSTR)(uilib_dialogbox_param->idd_dialog),
 
945
              uilib_dialogbox_param->hwnd, uilib_dialogbox_dialog_proc);
 
946
 
 
947
}
 
948