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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-03-31 00:37:15 UTC
  • mfrom: (1.1.7 upstream) (9.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090331003715-i5yisvcfv7mgz3eh
Tags: 2.1.dfsg-1
* New major upstream release (closes: #495937).
* Add desktop files (closes: #501181).

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "vice.h"
30
30
 
 
31
#include <assert.h>
31
32
#include <stdio.h>
32
33
#include <string.h>
33
34
#include <windows.h>
40
41
#include "attach.h"
41
42
#include "autostart.h"
42
43
#include "archdep.h"
 
44
#include "charset.h"
 
45
#include "clipboard.h"
43
46
#include "debug.h"
44
47
#include "drive.h"
45
48
#include "drivecpu.h"
47
50
#include "fullscrn.h"
48
51
#include "imagecontents.h"
49
52
#include "interrupt.h"
 
53
#include "intl.h"
50
54
#include "kbd.h"
 
55
#include "kbdbuf.h"
51
56
#include "lib.h"
52
57
#include "log.h"
53
58
#include "machine.h"
70
75
#include "uifliplist.h"
71
76
#include "uihelp.h"
72
77
#include "uijoystick.h"
 
78
#include "uikeyboard.h"
73
79
#include "uilib.h"
74
80
#include "uimediafile.h"
75
81
#include "uinetwork.h"
124
130
    { "Sound", IDM_TOGGLE_SOUND },
125
131
    { "DriveTrueEmulation", IDM_TOGGLE_DRIVE_TRUE_EMULATION },
126
132
    { "WarpMode", IDM_TOGGLE_WARP_MODE },
127
 
    { "WarpMode", IDM_TOGGLE_WARP_MODE|0x00010000 },
128
133
    { "VirtualDevices", IDM_TOGGLE_VIRTUAL_DEVICES },
129
134
    { "SaveResourcesOnExit", IDM_TOGGLE_SAVE_SETTINGS_ON_EXIT },
130
135
    { "ConfirmOnExit", IDM_TOGGLE_CONFIRM_ON_EXIT },
131
136
    { "FullScreenEnabled", IDM_TOGGLE_FULLSCREEN },
132
137
    { "AlwaysOnTop", IDM_TOGGLE_ALWAYSONTOP },
 
138
    { "KeySetEnable", IDM_JOYKEYS_TOGGLE },
133
139
#ifdef DEBUG
134
140
    { "MainCPU_TRACE", IDM_TOGGLE_MAINCPU_TRACE },
135
 
    { "MainCPU_TRACE", IDM_TOGGLE_MAINCPU_TRACE|0x00010000 },
136
141
    { "Drive0CPU_TRACE", IDM_TOGGLE_DRIVE0CPU_TRACE },
137
 
    { "Drive0CPU_TRACE", IDM_TOGGLE_DRIVE0CPU_TRACE|0x00010000 },
138
142
    { "Drive1CPU_TRACE", IDM_TOGGLE_DRIVE1CPU_TRACE },
139
 
    { "Drive1CPU_TRACE", IDM_TOGGLE_DRIVE1CPU_TRACE|0x00010000 },
140
143
#endif
141
144
    { NULL, 0 }
142
145
};
219
222
    { NULL, 0}
220
223
};
221
224
 
 
225
ui_menu_translation_table_t monitor_trans_popup_table[] = {
 
226
    { 1, IDS_MP_FILE },
 
227
    { 1, IDS_MP_DEBUG },
 
228
    { 1, IDS_MP_VIEW },
 
229
    { 1, IDS_MP_WINDOW },
 
230
    { 0, 0 }
 
231
};
 
232
 
 
233
ui_popup_translation_table_t monitor_trans_item_table[] = {
 
234
    { IDM_MON_OPEN, IDS_MI_MON_OPEN },
 
235
    { IDM_MON_SAVE, IDS_MI_MON_SAVE },
 
236
    { IDM_MON_PRINT, IDS_MI_MON_PRINT },
 
237
    { IDM_EXIT, IDS_MI_MON_EXIT },
 
238
    { IDM_MON_STOP_DEBUG, IDS_MI_MON_STOP_DEBUG },
 
239
    { IDM_MON_STOP_EXEC, IDS_MI_MON_STOP_EXEC },
 
240
    { IDM_MON_STEP_INTO, IDS_MI_MON_STEP_INTO },
 
241
    { IDM_MON_STEP_OVER, IDS_MI_MON_STEP_OVER },
 
242
    { IDM_MON_SKIP_RETURN, IDS_MI_MON_SKIP_RETURN },
 
243
    { IDM_MON_GOTO_CURSOR, IDS_MI_MON_GOTO_CURSOR },
 
244
    { IDM_MON_EVAL, IDS_MI_MON_EVAL },
 
245
    { IDM_MON_CURRENT, IDS_MI_MON_CURRENT },
 
246
    { IDM_MON_WND_EVAL, IDS_MI_MON_WND_EVAL },
 
247
    { IDM_MON_WND_REG, IDS_MI_MON_WND_REG },
 
248
    { IDM_MON_WND_MEM, IDS_MI_MON_WND_MEM },
 
249
    { IDM_MON_WND_DIS, IDS_MI_MON_WND_DIS },
 
250
    { IDM_MON_WND_CONSOLE, IDS_MI_MON_WND_CONSOLE },
 
251
    { IDM_MON_COMPUTER, IDS_MI_MON_COMPUTER },
 
252
    { IDM_MON_DRIVE8, IDS_MI_MON_DRIVE8 },
 
253
    { IDM_MON_DRIVE9, IDS_MI_MON_DRIVE9 },
 
254
    { IDM_MON_CASCADE, IDS_MI_MON_CASCADE },
 
255
    { IDM_MON_TILE_VERT, IDS_MI_MON_TILE_VERT },
 
256
    { IDM_MON_TILE_HORIZ, IDS_MI_MON_TILE_HORIZ },
 
257
    { IDM_MON_ARRANGE_ICONS, IDS_MI_MON_ARRANGE_ICONS },
 
258
    { 0, 0 }
 
259
};
 
260
 
222
261
/* ------------------------------------------------------------------------ */
223
 
#ifdef DEBUG
224
 
#define UI_DEBUG_HOTKEYS                                                \
225
 
    { FVIRTKEY | FALT | FNOINVERT, VK_F10, IDM_TOGGLE_MAINCPU_TRACE },     \
226
 
    { FVIRTKEY | FALT | FNOINVERT, VK_F11, IDM_TOGGLE_DRIVE0CPU_TRACE },   \
227
 
    { FVIRTKEY | FALT | FNOINVERT, VK_F12, IDM_TOGGLE_DRIVE1CPU_TRACE },
228
 
#else
229
 
#define UI_DEBUG_HOTKEYS
230
 
#endif /* DEBUG*/
231
 
 
232
 
#define UI_COMMON_HOTKEYS                                                   \
233
 
    { FVIRTKEY | FCONTROL | FALT | FNOINVERT, 'R', IDM_RESET_HARD },        \
234
 
    { FVIRTKEY | FALT | FNOINVERT, 'R', IDM_RESET_SOFT },                   \
235
 
    { FVIRTKEY | FALT | FNOINVERT, '4', IDM_FORMFEED_PRINTERIEC4 },         \
236
 
    { FVIRTKEY | FALT | FNOINVERT, '5', IDM_FORMFEED_PRINTERIEC5 },         \
237
 
    { FVIRTKEY | FALT | FNOINVERT, '8', IDM_ATTACH_8 },                     \
238
 
    { FVIRTKEY | FALT | FNOINVERT, '9', IDM_ATTACH_9 },                     \
239
 
    { FVIRTKEY | FALT | FNOINVERT, '0', IDM_ATTACH_10 },                    \
240
 
    { FVIRTKEY | FALT | FNOINVERT, '1', IDM_ATTACH_11 },                    \
241
 
    { FVIRTKEY | FALT | FNOINVERT, 'A', IDM_DETACH_ALL },                   \
242
 
    { FVIRTKEY | FALT | FNOINVERT, 'T', IDM_ATTACH_TAPE },                  \
243
 
    { FVIRTKEY | FALT | FNOINVERT, 'L', IDM_LOADQUICK },                    \
244
 
    { FVIRTKEY | FALT | FNOINVERT, 'S', IDM_SAVEQUICK },                    \
245
 
    { FVIRTKEY | FALT | FNOINVERT, 'M', IDM_MONITOR },                      \
246
 
    { FVIRTKEY | FALT | FNOINVERT, 'X', IDM_EXIT },                         \
247
 
    { FVIRTKEY | FALT | FNOINVERT, 'W', IDM_TOGGLE_WARP_MODE },             \
248
 
    { FVIRTKEY | FALT | FNOINVERT, 'I', IDM_FLIP_ADD },                     \
249
 
    { FVIRTKEY | FALT | FNOINVERT, 'K', IDM_FLIP_REMOVE },                  \
250
 
    { FVIRTKEY | FALT | FNOINVERT, 'N', IDM_FLIP_NEXT },                    \
251
 
    { FVIRTKEY | FALT | FNOINVERT, 'B', IDM_FLIP_PREVIOUS },                \
252
 
    { FVIRTKEY | FALT | FNOINVERT, 'J', IDM_SWAP_JOYSTICK },                \
253
 
    { FVIRTKEY | FALT | FNOINVERT, 'C', IDM_MEDIAFILE },                    \
254
 
    { FVIRTKEY | FALT | FNOINVERT, 'G', IDM_EVENT_SETMILESTONE },           \
255
 
    { FVIRTKEY | FALT | FNOINVERT, 'H', IDM_EVENT_RESETMILESTONE },         \
256
 
    { FVIRTKEY | FALT | FNOINVERT, 'D', IDM_TOGGLE_FULLSCREEN },            \
257
 
    { FVIRTKEY | FALT | FNOINVERT, VK_RETURN, IDM_TOGGLE_FULLSCREEN },      \
258
 
    { FVIRTKEY | FALT | FNOINVERT, VK_PAUSE, IDM_PAUSE },                   \
259
 
    { FVIRTKEY | FALT | FNOINVERT, VK_OEM_PLUS, IDM_SINGLE_FRAME_ADVANCE }, \
260
 
    { FVIRTKEY | FALT | FNOINVERT, VK_ADD, IDM_SINGLE_FRAME_ADVANCE }
261
 
 
262
 
static ACCEL c64_accel[] = {
263
 
    { FVIRTKEY | FALT | FNOINVERT, 'Z', IDM_CART_FREEZE },
264
 
    { FVIRTKEY | FALT | FNOINVERT, 'Q', IDM_MOUSE },
265
 
    UI_DEBUG_HOTKEYS
266
 
    UI_COMMON_HOTKEYS
267
 
};
268
 
 
269
 
static ACCEL c128_accel[] = {
270
 
    { FVIRTKEY | FALT | FNOINVERT, 'Q', IDM_MOUSE },
271
 
    UI_DEBUG_HOTKEYS
272
 
    UI_COMMON_HOTKEYS
273
 
};
274
 
 
275
 
static ACCEL cbm2_accel[] = {
276
 
    UI_DEBUG_HOTKEYS
277
 
    UI_COMMON_HOTKEYS
278
 
};
279
 
 
280
 
static ACCEL vic_accel[] = {
281
 
    UI_DEBUG_HOTKEYS
282
 
    UI_COMMON_HOTKEYS
283
 
};
284
 
 
285
 
static ACCEL pet_accel[] = {
286
 
    UI_DEBUG_HOTKEYS
287
 
    UI_COMMON_HOTKEYS
288
 
};
289
 
 
290
 
static ACCEL plus4_accel[] = {
291
 
    UI_DEBUG_HOTKEYS
292
 
    UI_COMMON_HOTKEYS
293
 
};
294
 
 
295
 
/*static HBRUSH led_red;
296
 
static HBRUSH led_green;
297
 
static HBRUSH led_black;
298
 
static HBRUSH tape_motor_on_brush;
299
 
static HBRUSH tape_motor_off_brush;
300
 
*/
301
262
static HWND main_hwnd;
302
 
static HWND slider_hwnd;
303
263
 
304
264
static int emu_menu;
305
265
 
306
266
static int pause_pending;
307
267
 
 
268
static ui_menu_translation_table_t *menu_translation_table;
 
269
static ui_popup_translation_table_t *popup_translation_table;
 
270
 
 
271
void ui_register_translation_tables(ui_menu_translation_table_t *menu_table, ui_popup_translation_table_t *popup_table)
 
272
{
 
273
    menu_translation_table = menu_table;
 
274
    popup_translation_table = popup_table;
 
275
    ui_update_menu();
 
276
}
 
277
 
308
278
/* Initialize the UI before setting all the resource values.  */
309
279
int ui_init(int *argc, char **argv)
310
280
{
313
283
    switch (machine_class) {
314
284
      case VICE_MACHINE_C64:
315
285
        emu_menu = IDR_MENUC64;
316
 
        ui_accelerator = CreateAcceleratorTable(c64_accel, 
317
 
            sizeof(c64_accel) / sizeof(ACCEL));
 
286
        break;
 
287
      case VICE_MACHINE_C64DTV:
 
288
        emu_menu = IDR_MENUC64DTV;
318
289
        break;
319
290
      case VICE_MACHINE_C128:
320
291
        emu_menu = IDR_MENUC128;
321
 
        ui_accelerator = CreateAcceleratorTable(c128_accel, 
322
 
            sizeof(c128_accel) / sizeof(ACCEL));
323
292
        break;
324
293
      case VICE_MACHINE_VIC20:
325
294
        emu_menu = IDR_MENUVIC;
326
 
        ui_accelerator = CreateAcceleratorTable(vic_accel,
327
 
            sizeof(vic_accel)/ sizeof(ACCEL));
328
295
        break;
329
296
      case VICE_MACHINE_PET:
330
297
        emu_menu = IDR_MENUPET;
331
 
        ui_accelerator = CreateAcceleratorTable(pet_accel,
332
 
            sizeof(pet_accel) / sizeof(ACCEL));
333
298
        break;
334
299
      case VICE_MACHINE_PLUS4:
335
300
        emu_menu = IDR_MENUPLUS4;
336
 
        ui_accelerator = CreateAcceleratorTable(plus4_accel,
337
 
            sizeof(plus4_accel) / sizeof(ACCEL));
338
301
        break;
339
302
      case VICE_MACHINE_CBM2:
340
303
        emu_menu = IDR_MENUCBM2;
341
 
        ui_accelerator = CreateAcceleratorTable(cbm2_accel,
342
 
            sizeof(cbm2_accel) / sizeof(ACCEL));
343
304
        break;
344
305
      default:
345
306
        log_debug("UI: No menu entries for this machine defined!");
346
307
        log_debug("UI: Using C64 type UI menues.");
347
308
        emu_menu = IDR_MENUC64;
348
 
        ui_accelerator = CreateAcceleratorTable(c64_accel,
349
 
            sizeof(c64_accel) / sizeof(ACCEL));
350
309
    }
351
310
 
352
311
    /* Register the window class.  */
383
342
       needs an application window to be created to initialize itself, and
384
343
       because this might allow us to support more than one emulation window
385
344
       in the future.  */
386
 
#if 1
387
345
    main_hwnd = CreateWindow(APPLICATION_CLASS_MAIN,
388
346
                             TEXT("No title"), /* (for now) */
389
347
                             WS_OVERLAPPED | WS_CLIPCHILDREN | WS_BORDER
397
355
                             NULL,
398
356
                             winmain_instance,
399
357
                             NULL);
400
 
#endif
401
358
    InitCommonControls();
402
359
 
403
360
    number_of_windows = 0;
410
367
void ui_shutdown(void)
411
368
{
412
369
   statusbar_delete_brushes();
 
370
   uikeyboard_shutdown();
413
371
}
414
372
 
415
373
/* Initialize the UI after setting all the resource values.  */
416
374
int ui_init_finish(void)
417
375
{
 
376
    ui_accelerator = uikeyboard_create_accelerator_table();
418
377
    ui_fullscreen_init();
419
378
    atexit(ui_exit);
420
379
    return 0;
441
400
    uilib_shutdown();
442
401
}
443
402
 
 
403
static void ui_translate_menu_popups(HMENU menu, ui_popup_translation_table_t *trans_table)
 
404
{
 
405
    int pos1 = -1;
 
406
    int pos2 = -1;
 
407
    int pos3 = -1;
 
408
 
 
409
    HMENU menu1 = NULL;
 
410
    HMENU menu2 = NULL;
 
411
    HMENU menu3 = NULL;
 
412
 
 
413
    int i = 0;
 
414
 
 
415
    if (trans_table == NULL)
 
416
        return;
 
417
 
 
418
    while (trans_table[i].level != 0)
 
419
    {
 
420
        switch (trans_table[i].level)
 
421
        {
 
422
            case 1:
 
423
                menu1 = NULL;
 
424
                while (menu1 == NULL)
 
425
                {
 
426
                    pos1++;
 
427
                    menu1 = GetSubMenu(menu, pos1);
 
428
                }
 
429
                if (trans_table[i].ids != 0)
 
430
                    ModifyMenu(menu, (UINT)pos1, MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT)menu1, translate_text(trans_table[i].ids));
 
431
                pos2 = -1;
 
432
                pos3 = -1;
 
433
                break;
 
434
            case 2:
 
435
                menu2 = NULL;
 
436
                while (menu2 == NULL)
 
437
                {
 
438
                    pos2++;
 
439
                    menu2 = GetSubMenu(menu1, pos2);
 
440
                }
 
441
                ModifyMenu(menu1, (UINT)pos2, MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT)menu2, translate_text(trans_table[i].ids));
 
442
                pos3 = -1;
 
443
                break;
 
444
            case 3:
 
445
                menu3 = NULL;
 
446
                while (menu3 == NULL)
 
447
                {
 
448
                    pos3++;
 
449
                    menu3 = GetSubMenu(menu2, pos3);
 
450
                }
 
451
                ModifyMenu(menu2, (UINT)pos3, MF_BYPOSITION | MF_STRING | MF_POPUP, (UINT)menu3, translate_text(trans_table[i].ids));
 
452
                break;
 
453
        }
 
454
        i++;
 
455
    }
 
456
}
 
457
 
 
458
static void ui_translate_menu_items(HMENU menu, ui_menu_translation_table_t *trans_table)
 
459
{
 
460
    int i = 0;
 
461
 
 
462
    if (trans_table == NULL)
 
463
        return;
 
464
 
 
465
    while (trans_table[i].idm != 0)
 
466
    {
 
467
        ModifyMenu(menu, trans_table[i].idm, MF_BYCOMMAND | MF_STRING, trans_table[i].idm, translate_text(trans_table[i].ids));
 
468
        i++;
 
469
    }
 
470
}
 
471
 
 
472
void ui_translate_monitor_menu(HMENU menu)
 
473
{
 
474
  ui_translate_menu_popups(menu, (ui_popup_translation_table_t *)monitor_trans_popup_table);
 
475
  ui_translate_menu_items(menu, (ui_menu_translation_table_t *)monitor_trans_item_table);
 
476
}
 
477
 
444
478
/*  Create a Window for the emulation.  */
445
479
HWND ui_open_canvas_window(const char *title, unsigned int width,
446
 
                           unsigned int height, int fullscreen)
 
480
                           unsigned int height)
447
481
{
448
482
    HWND hwnd;
449
483
    int xpos, ypos;
475
509
    window_canvas_ysize[number_of_windows] = height;
476
510
    number_of_windows++;
477
511
 
478
 
    if (!fullscreen) {
479
 
        statusbar_create(hwnd);
480
 
    }
 
512
    statusbar_create(hwnd);
481
513
 
482
514
    ui_resize_canvas_window(hwnd, width, height);
483
515
 
484
 
    menu=LoadMenu(winmain_instance, MAKEINTRESOURCE(translate_res(emu_menu)));
 
516
    menu=LoadMenu(winmain_instance, MAKEINTRESOURCE(emu_menu));
 
517
    ui_translate_menu_items(menu, menu_translation_table);
 
518
    ui_translate_menu_popups(menu, popup_translation_table);
485
519
    SetMenu(hwnd,menu);
 
520
    uikeyboard_menu_shortcuts(menu);
486
521
    ShowWindow(hwnd, winmain_cmd_show);
487
522
    return hwnd;
488
523
 
493
528
HMENU menu;
494
529
int   i;
495
530
 
496
 
    menu = LoadMenu(winmain_instance, MAKEINTRESOURCE(translate_res(emu_menu)));
 
531
    menu = LoadMenu(winmain_instance, MAKEINTRESOURCE(emu_menu));
 
532
    if (menu_translation_table != NULL)
 
533
    {
 
534
        ui_translate_menu_items(menu, menu_translation_table);
 
535
        ui_translate_menu_popups(menu, popup_translation_table);
 
536
        uikeyboard_menu_shortcuts(menu);
 
537
    }
497
538
    for (i = 0; i < number_of_windows; i++) {
498
539
        SetMenu(window_handles[i], menu);
499
540
    }
579
620
static void update_menus(HWND hwnd)
580
621
{
581
622
    HMENU menu = GetMenu(hwnd);
582
 
    int i, j;
 
623
    unsigned int i, j;
583
624
    int value;
584
625
    int result;
585
626
    const char *lang;
661
702
 
662
703
static void ui_set_language(unsigned int lang_id)
663
704
{
664
 
    int i;
 
705
    unsigned int i;
665
706
 
666
707
    for (i = 0; (ui_lang_menu_entries[i].lang_code != NULL)
667
708
        && (i < countof(ui_lang_menu_entries)); i++) {
731
772
    lib_free(tmp);
732
773
}
733
774
 
 
775
/* Let the user browse for a filename */
 
776
char *ui_get_file(const char *format,...)
 
777
{
 
778
    char *tmp;
 
779
    char *st;
 
780
    va_list args;
 
781
 
 
782
    va_start(args, format);
 
783
    tmp = lib_mvsprintf(format, args);
 
784
    va_end(args);
 
785
 
 
786
    st = uilib_select_file(NULL, tmp, UILIB_FILTER_ALL,
 
787
                                UILIB_SELECTOR_TYPE_FILE_LOAD,
 
788
                                UILIB_SELECTOR_STYLE_DISK);
 
789
    lib_free(tmp);
 
790
 
 
791
    return st;
 
792
}
 
793
 
734
794
/* Handle the "CPU JAM" case.  */
735
795
ui_jam_action_t ui_jam_dialog(const char *format,...)
736
796
{
743
803
    txt = lib_mvsprintf(format, ap);
744
804
    txt2 = lib_msprintf(translate_text(IDS_START_MONITOR), txt);
745
805
    st = system_mbstowcs_alloc(txt2);
746
 
    ret = ui_messagebox(st, translate_text(IDS_VICE_CPU_JAM), MB_YESNO);
 
806
    ret = ui_messagebox(st, translate_text(IDS_VICE_CPU_JAM), MB_YESNOCANCEL);
747
807
    system_mbstowcs_free(st);
748
808
    lib_free(txt2);
749
809
    lib_free(txt);
750
 
    return (ret == IDYES) ? UI_JAM_MONITOR : UI_JAM_HARD_RESET;
 
810
    switch (ret) {
 
811
        case IDYES:
 
812
            return UI_JAM_MONITOR;
 
813
        case IDNO:
 
814
            return UI_JAM_HARD_RESET;
 
815
        case IDCANCEL:
 
816
            return UI_JAM_NONE;
 
817
    }
 
818
    return UI_JAM_NONE;
751
819
//    UI_JAM_RESET, UI_JAM_HARD_RESET, UI_JAM_MONITOR
752
820
}
753
821
 
1065
1133
 
1066
1134
/* ------------------------------------------------------------------------ */
1067
1135
 
 
1136
static void ui_copy_clipboard(HWND window)
 
1137
{
 
1138
    BOOL clipboard_is_open = FALSE;
 
1139
    char * text = NULL;
 
1140
    HGLOBAL globaltext = NULL;
 
1141
 
 
1142
    do {
 
1143
        char * p;
 
1144
 
 
1145
        if ( ! OpenClipboard(window) ) {
 
1146
            break;
 
1147
        }
 
1148
        clipboard_is_open = TRUE;
 
1149
 
 
1150
        if ( ! EmptyClipboard() ) {
 
1151
            break;
 
1152
        }
 
1153
 
 
1154
        text = clipboard_read_screen_output("\r\n");
 
1155
        if (text == NULL) {
 
1156
            break;
 
1157
        }
 
1158
 
 
1159
        globaltext = GlobalAlloc(GMEM_DDESHARE, strlen(text) + 1);
 
1160
        if (globaltext == NULL) {
 
1161
            break;
 
1162
        }
 
1163
 
 
1164
        p = GlobalLock(globaltext);
 
1165
        strcpy(p, text);
 
1166
 
 
1167
        SetClipboardData(CF_TEXT, globaltext);
 
1168
 
 
1169
    } while (0);
 
1170
 
 
1171
    if (globaltext) {
 
1172
        GlobalUnlock(globaltext);
 
1173
    }
 
1174
 
 
1175
    if (text) {
 
1176
        lib_free(text);
 
1177
    }
 
1178
 
 
1179
    if (clipboard_is_open) {
 
1180
        CloseClipboard();
 
1181
    }
 
1182
}
 
1183
 
 
1184
static void ui_paste_clipboard_text(HWND window)
 
1185
{
 
1186
    HANDLE hdata;
 
1187
    BOOL clipboard_is_open = FALSE;
 
1188
    char * text = NULL;
 
1189
    char * text_in_petscii = NULL;
 
1190
    
 
1191
    do {
 
1192
        DWORD size;
 
1193
 
 
1194
        if ( ! OpenClipboard(window) ) {
 
1195
            break;
 
1196
        }
 
1197
 
 
1198
        clipboard_is_open = TRUE;
 
1199
 
 
1200
        hdata = GetClipboardData(CF_TEXT);
 
1201
 
 
1202
        if ( ! hdata ) {
 
1203
            break;
 
1204
        }
 
1205
 
 
1206
        text = GlobalLock(hdata);
 
1207
 
 
1208
        if (text == NULL) {
 
1209
            break;
 
1210
        }
 
1211
 
 
1212
        size = GlobalSize(hdata);
 
1213
 
 
1214
        if (size < 1) {
 
1215
            break;
 
1216
        }
 
1217
 
 
1218
        /*
 
1219
         * Allocate memmory for the string to convert in petscii.
 
1220
         * Note: As we are not sure if the original text is null-terminated,
 
1221
         *       do *not* use lib_stralloc()!
 
1222
         */
 
1223
        text_in_petscii = lib_malloc(size + 1);
 
1224
 
 
1225
        if (text_in_petscii == NULL) {
 
1226
            break;
 
1227
        }
 
1228
 
 
1229
        memcpy(text_in_petscii, text, size);
 
1230
        text_in_petscii[size] = 0;
 
1231
 
 
1232
        charset_petconvstring(text_in_petscii, 0);
 
1233
 
 
1234
        kbdbuf_feed(text_in_petscii);
 
1235
 
 
1236
    } while (0);
 
1237
 
 
1238
    if (text_in_petscii) {
 
1239
        lib_free(text_in_petscii);
 
1240
    }
 
1241
 
 
1242
    if (text) {
 
1243
        GlobalUnlock(text);
 
1244
    }
 
1245
 
 
1246
    if (clipboard_is_open) {
 
1247
        CloseClipboard();
 
1248
    }
 
1249
}
 
1250
 
 
1251
 
 
1252
/* ------------------------------------------------------------------------ */
 
1253
 
1068
1254
/* FIXME: tmp hack.  */
1069
1255
int syscolorchanged, displaychanged, querynewpalette, palettechanged;
1070
1256
 
1115
1301
    }
1116
1302
}
1117
1303
 
 
1304
static void handle_wm_initmenupopup(HMENU menu)
 
1305
{
 
1306
    /* enable PASTE iff the clipboard contains "our" format: */
 
1307
 
 
1308
    EnableMenuItem(menu, IDM_EDIT_PASTE, 
 
1309
        MF_BYCOMMAND 
 
1310
        | ( IsClipboardFormatAvailable(CF_TEXT) ? MF_ENABLED : MF_GRAYED));
 
1311
}
 
1312
 
1118
1313
static void handle_wm_command(WPARAM wparam, LPARAM lparam, HWND hwnd)
1119
1314
{
 
1315
    TCHAR *st_name;
 
1316
 
 
1317
    wparam &= 0xffff;
1120
1318
    /* Handle machine specific commands first.  */
1121
1319
    if (ui_machine_specific)
1122
1320
        ui_machine_specific(wparam, hwnd);
1123
1321
 
1124
1322
    switch (wparam) {
1125
1323
      case IDM_DEVICEMANAGER:
1126
 
      case IDM_FORMFEED_PRINTERIEC4 | 0x00010000:
1127
 
      case IDM_FORMFEED_PRINTERIEC5 | 0x00010000:
 
1324
      case IDM_FORMFEED_PRINTERIEC4:
 
1325
      case IDM_FORMFEED_PRINTERIEC5:
1128
1326
        uiperipheral_command(hwnd, wparam);
1129
1327
        break;
1130
 
      case IDM_EXIT | 0x00010000:
1131
1328
      case IDM_EXIT:
1132
1329
        PostMessage(hwnd, WM_CLOSE, wparam, lparam);
1133
1330
        break;
 
1331
      case IDM_EDIT_COPY:
 
1332
        ui_copy_clipboard(hwnd);
 
1333
        break;
 
1334
      case IDM_EDIT_PASTE:
 
1335
        ui_paste_clipboard_text(hwnd);
 
1336
        break;
1134
1337
      case IDM_ABOUT:
1135
1338
      case IDM_HELP:
1136
1339
      case IDM_CONTRIBUTORS:
1139
1342
      case IDM_CMDLINE:
1140
1343
        uihelp_dialog(hwnd, wparam);
1141
1344
        break;
1142
 
      case IDM_ATTACH_8 | 0x00010000:
1143
 
      case IDM_ATTACH_9 | 0x00010000:
1144
 
      case IDM_ATTACH_10 | 0x00010000:
1145
 
      case IDM_ATTACH_11 | 0x00010000:
1146
1345
      case IDM_ATTACH_8:
1147
1346
      case IDM_ATTACH_9:
1148
1347
      case IDM_ATTACH_10:
1151
1350
      case IDM_DETACH_9:
1152
1351
      case IDM_DETACH_10:
1153
1352
      case IDM_DETACH_11:
1154
 
      case IDM_DETACH_ALL | 0x00010000:
1155
1353
      case IDM_DETACH_ALL:
1156
 
      case IDM_ATTACH_TAPE | 0x00010000:
1157
1354
      case IDM_ATTACH_TAPE:
1158
1355
      case IDM_DETACH_TAPE:
1159
1356
      case IDM_AUTOSTART:
1160
1357
        uiattach_command(hwnd, wparam);
1161
1358
        break;
1162
 
      case IDM_FLIP_ADD | 0x00010000:
1163
1359
      case IDM_FLIP_ADD:
1164
 
      case IDM_FLIP_REMOVE | 0x00010000:
1165
1360
      case IDM_FLIP_REMOVE:
1166
 
      case IDM_FLIP_NEXT | 0x00010000:
1167
1361
      case IDM_FLIP_NEXT:
1168
 
      case IDM_FLIP_PREVIOUS | 0x00010000:
1169
1362
      case IDM_FLIP_PREVIOUS:
1170
1363
      case IDM_FLIP_LOAD:
1171
1364
      case IDM_FLIP_SAVE:
1181
1374
      case IDM_DATASETTE_RESET_COUNTER:
1182
1375
        uidatasette_command(hwnd, wparam);
1183
1376
        break;
1184
 
      case IDM_SNAPSHOT_LOAD | 0x00010000:
1185
1377
      case IDM_SNAPSHOT_LOAD:
1186
1378
        ui_snapshot_load(hwnd);
1187
1379
        break;
1188
 
      case IDM_SNAPSHOT_SAVE | 0x00010000:
1189
1380
      case IDM_SNAPSHOT_SAVE:
1190
1381
        ui_snapshot_save(hwnd);
1191
1382
        break;
1192
 
      case IDM_SAVEQUICK | 0x00010000:
1193
1383
      case IDM_SAVEQUICK:
1194
1384
        ui_quicksnapshot_save(hwnd);
1195
1385
        break;
1196
 
      case IDM_LOADQUICK | 0x00010000:
1197
1386
      case IDM_LOADQUICK:
1198
1387
        ui_quicksnapshot_load(hwnd);
1199
1388
        break;
1200
 
      case IDM_MEDIAFILE | 0x00010000:
1201
1389
      case IDM_MEDIAFILE:
1202
1390
        SuspendFullscreenModeKeep(hwnd);
1203
1391
        ui_mediafile_save_dialog(hwnd);
1204
1392
        ResumeFullscreenModeKeep(hwnd);
1205
1393
        break;
1206
1394
      case IDM_SINGLE_FRAME_ADVANCE:
1207
 
      case IDM_SINGLE_FRAME_ADVANCE | 0x00010000:
1208
1395
        pause_pending = 1;
1209
1396
        if (!is_paused) {
1210
1397
            break;
1211
1398
        }
1212
1399
        // fall through
1213
1400
      case IDM_PAUSE:
1214
 
      case IDM_PAUSE | 0x00010000:
1215
1401
        ui_pause_emulation();
1216
1402
        break;
1217
 
      case IDM_MONITOR | 0x00010000:
1218
1403
      case IDM_MONITOR:
1219
1404
        if (!ui_emulation_is_paused())
1220
1405
            monitor_startup_trap();
1223
1408
            monitor_startup();
1224
1409
*/
1225
1410
        break;
1226
 
      case IDM_RESET_HARD + 0x00010000:
1227
 
      case IDM_RESET_SOFT + 0x00010000:
1228
1411
      case IDM_RESET_HARD:
1229
1412
      case IDM_RESET_SOFT:
1230
1413
        reset_dialog_proc(wparam);
1251
1434
      case IDM_JOY_SETTINGS:
1252
1435
        ui_joystick_settings_dialog(hwnd);
1253
1436
        break;
1254
 
      case IDM_SWAP_JOYSTICK | 0x00010000:
1255
1437
      case IDM_SWAP_JOYSTICK:
1256
1438
        ui_joystick_swap_joystick();
1257
1439
        break;
1261
1443
      case IDM_RAM_SETTINGS:
1262
1444
        ui_ram_settings_dialog(hwnd);
1263
1445
        break;
1264
 
      case IDM_TOGGLE_FULLSCREEN | 0x00010000:
1265
1446
      case IDM_TOGGLE_FULLSCREEN:
1266
1447
        vsync_suspend_speed_eval();
1267
1448
        SwitchFullscreenMode(hwnd);
1268
1449
        break;
 
1450
      case IDM_SETTINGS_SAVE_FILE:
 
1451
          if ((st_name = uilib_select_file(hwnd, translate_text(IDS_SAVE_CONFIG_FILE),
 
1452
              UILIB_FILTER_ALL, UILIB_SELECTOR_TYPE_FILE_SAVE,
 
1453
              UILIB_SELECTOR_STYLE_DEFAULT)) != NULL)
 
1454
          {
 
1455
              char *name;
 
1456
 
 
1457
              name = system_wcstombs_alloc(st_name);
 
1458
 
 
1459
              if (resources_save(st_name) < 0)
 
1460
              {
 
1461
                  ui_error(translate_text(IDS_CANNOT_SAVE_SETTINGS));
 
1462
              }
 
1463
              else
 
1464
              {
 
1465
                  ui_message(translate_text(IDS_SETTINGS_SAVED_SUCCESS));
 
1466
              }
 
1467
              uifliplist_save_settings();
 
1468
              system_wcstombs_free(name);
 
1469
              lib_free(st_name);
 
1470
          }
 
1471
          break;
 
1472
      case IDM_SETTINGS_LOAD_FILE:
 
1473
          if ((st_name = uilib_select_file(hwnd, translate_text(IDS_LOAD_CONFIG_FILE),
 
1474
              UILIB_FILTER_ALL, UILIB_SELECTOR_TYPE_FILE_LOAD,
 
1475
              UILIB_SELECTOR_STYLE_DEFAULT)) != NULL)
 
1476
          {
 
1477
              char *name;
 
1478
 
 
1479
              name = system_wcstombs_alloc(st_name);
 
1480
 
 
1481
              if (resources_load(st_name) < 0)
 
1482
              {
 
1483
                  ui_error(translate_text(IDS_CANNOT_LOAD_SETTINGS));
 
1484
              }
 
1485
              else
 
1486
              {
 
1487
                  ui_message(translate_text(IDS_SETTINGS_LOADED_SUCCESS));
 
1488
              }
 
1489
              uifliplist_save_settings();
 
1490
              system_wcstombs_free(name);
 
1491
              lib_free(st_name);
 
1492
          }
 
1493
          break;
1269
1494
      case IDM_SETTINGS_SAVE:
1270
1495
        if (resources_save(NULL) < 0)
1271
1496
            ui_error(translate_text(IDS_CANNOT_SAVE_SETTINGS));
1288
1513
      case IDM_EVENT_TOGGLE_RECORD:
1289
1514
      case IDM_EVENT_TOGGLE_PLAYBACK:
1290
1515
      case IDM_EVENT_SETMILESTONE:
1291
 
      case IDM_EVENT_SETMILESTONE | 0x00010000:
1292
1516
      case IDM_EVENT_RESETMILESTONE:
1293
 
      case IDM_EVENT_RESETMILESTONE | 0x00010000:
1294
1517
        uievent_command(hwnd, wparam);
1295
1518
        break;
1296
1519
      case IDM_NETWORK_SETTINGS:
1427
1650
    DragFinish(hDrop);
1428
1651
}
1429
1652
 
 
1653
static void ui_redraw_all_windows(void)
 
1654
{
 
1655
    int i;
 
1656
 
 
1657
    for (i = 0; i < number_of_windows; i++) {
 
1658
        InvalidateRect(window_handles[i], NULL, FALSE);
 
1659
    }
 
1660
}
 
1661
 
1430
1662
/* Window procedure.  All messages are handled here.  */
1431
1663
static long CALLBACK window_proc(HWND window, UINT msg,
1432
1664
                                 WPARAM wparam, LPARAM lparam)
1442
1674
      case WM_CREATE:
1443
1675
        DragAcceptFiles(window, TRUE);
1444
1676
        return 0;
 
1677
      case WM_WINDOWPOSCHANGED:
 
1678
        /* SRT: if focus is changed in full-screen mode, this message is sent 
 
1679
          Make sure that all windows are repainted.*/
 
1680
        ui_redraw_all_windows();
 
1681
        break;
1445
1682
      case WM_SETREDRAW:
1446
1683
//      log_debug("WM_SETREDRAW %s", wparam == TRUE? "TRUE" : "FALSE");
1447
1684
        break;
1485
1722
        return 0;
1486
1723
      case WM_DRAWITEM:
1487
1724
        statusbar_handle_WMDRAWITEM(wparam,lparam);
 
1725
        /* SRT: Make sure that all windows are repainted.
 
1726
          This message seems to be a good candidate for the remote desktop. */
 
1727
        ui_redraw_all_windows();
1488
1728
        return 0;
 
1729
      case WM_INITMENUPOPUP:
 
1730
        handle_wm_initmenupopup((HMENU)wparam);
 
1731
        break;
1489
1732
      case WM_COMMAND:
1490
1733
        handle_wm_command(wparam, lparam, window);
1491
1734
        return 0;
1575
1818
      case WM_NCLBUTTONDOWN:
1576
1819
        vsync_suspend_speed_eval();
1577
1820
        break;
 
1821
      case WM_RBUTTONDOWN:
 
1822
        ui_paste_clipboard_text(window);
 
1823
        break;
1578
1824
      case WM_NOTIFY:
1579
1825
        statusbar_notify(window, window_index, wparam, lparam);
1580
1826
        break;