| 1 | #ifdef RCSID |
| 2 | static char RCSid[] = |
| 3 | "$Header$"; |
| 4 | #endif |
| 5 | |
| 6 | /* |
| 7 | * Copyright (c) 1999, 2002 Michael J. Roberts. All Rights Reserved. |
| 8 | * |
| 9 | * Please see the accompanying license file, LICENSE.TXT, for information |
| 10 | * on using and copying this software. |
| 11 | */ |
| 12 | /* |
| 13 | Name |
| 14 | indlg_os.cpp - OS-dialog-based implementation of input_dialog |
| 15 | Function |
| 16 | Implements the input dialog using the OS-provided dialog |
| 17 | Notes |
| 18 | Only one of indlg_tx.c or indlg_os.c should be included in a given |
| 19 | executable. For a text-only version, include indlg_tx. For a version |
| 20 | where os_input_dialog() provides a system dialog, use indlg_os instead. |
| 21 | |
| 22 | We provide a choice of input_dialog() implementations in the portable |
| 23 | code (rather than only through the OS code) so that we can call |
| 24 | the formatted text output routines in this version. An OS-layer |
| 25 | implementation could not call the formatted output routines (it would |
| 26 | have to call os_printf directly), which would result in poor prompt |
| 27 | formatting any time a prompt exceeded a single line of text. |
| 28 | Modified |
| 29 | 09/27/99 MJRoberts - Creation |
| 30 | */ |
| 31 | |
| 32 | |
| 33 | #include "os.h" |
| 34 | #include "t3std.h" |
| 35 | #include "vmglob.h" |
| 36 | #include "vmconsol.h" |
| 37 | #include "charmap.h" |
| 38 | |
| 39 | /* |
| 40 | * formatted text-only file prompt |
| 41 | */ |
| 42 | int CVmConsole::input_dialog(VMG_ int icon_id, const char *prompt, |
| 43 | int standard_button_set, |
| 44 | const char **buttons, int button_count, |
| 45 | int default_index, int cancel_index, |
| 46 | int bypass_script) |
| 47 | { |
| 48 | char ui_prompt[256]; |
| 49 | const char *ui_buttons[10]; |
| 50 | char ui_button_buf[256]; |
| 51 | size_t ui_prompt_len; |
| 52 | char *dst; |
| 53 | size_t dstrem; |
| 54 | int i; |
| 55 | |
| 56 | /* flush any pending output */ |
| 57 | flush(vmg_ VM_NL_INPUT); |
| 58 | |
| 59 | /* convert the prompt to the local character set */ |
| 60 | ui_prompt_len = G_cmap_to_ui->map_utf8(ui_prompt, sizeof(ui_prompt) - 1, |
| 61 | prompt, strlen(prompt), 0); |
| 62 | |
| 63 | /* null-terminate the prompt text */ |
| 64 | ui_prompt[ui_prompt_len] = '\0'; |
| 65 | |
| 66 | /* convert the button labels to the local character set */ |
| 67 | if (button_count > (int)sizeof(ui_buttons)/sizeof(ui_buttons[0])) |
| 68 | button_count = (int)sizeof(ui_buttons)/sizeof(ui_buttons[0]); |
| 69 | for (i = 0, dst = ui_button_buf, dstrem = sizeof(ui_button_buf) ; |
| 70 | i < button_count ; ++i) |
| 71 | { |
| 72 | size_t len; |
| 73 | |
| 74 | /* set up this converted button pointer */ |
| 75 | ui_buttons[i] = dst; |
| 76 | |
| 77 | /* map this button's text, leaving room for a null terminator */ |
| 78 | len = G_cmap_to_ui->map_utf8(dst, dstrem - 1, |
| 79 | buttons[i], strlen(buttons[i]), 0); |
| 80 | |
| 81 | /* null-terminate it */ |
| 82 | dst[len++] = '\0'; |
| 83 | |
| 84 | /* advance past this label */ |
| 85 | dst += len; |
| 86 | dstrem -= len; |
| 87 | } |
| 88 | |
| 89 | /* ask the OS to do the work, and return the result */ |
| 90 | return os_input_dialog(icon_id, ui_prompt, standard_button_set, |
| 91 | ui_buttons, button_count, |
| 92 | default_index, cancel_index); |
| 93 | } |
| 94 |