| 1 |
#ifdef RCSID |
| 2 |
static char RCSid[] = |
| 3 |
"$Header: d:/cvsroot/tads/TADS2/msdos/OSWIN.C,v 1.4 1999/07/11 00:46:37 MJRoberts Exp $"; |
| 4 |
#endif |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#include <string.h> |
| 25 |
#include <stdio.h> |
| 26 |
#include <stdarg.h> |
| 27 |
|
| 28 |
#include <windows.h> |
| 29 |
#include <Wincrypt.h> |
| 30 |
|
| 31 |
#include "std.h" |
| 32 |
#include "os.h" |
| 33 |
#include "trd.h" |
| 34 |
|
| 35 |
|
| 36 |
static char default_saved_game_ext[OSFNMAX] = ""; |
| 37 |
|
| 38 |
|
| 39 |
static char S_open_file_dir[OSFNMAX]; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
extern HINSTANCE oss_G_hinstance; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
void oss_set_open_file_dir(const char *dir) |
| 55 |
{ |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
if (dir != 0) |
| 61 |
strcpy(S_open_file_dir, dir); |
| 62 |
else |
| 63 |
S_open_file_dir[0] = '\0'; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
static UINT APIENTRY filedlg_hook(HWND dlg, UINT msg, |
| 71 |
WPARAM wpar, LPARAM lpar) |
| 72 |
{ |
| 73 |
|
| 74 |
if (msg == WM_NOTIFY |
| 75 |
&& ((NMHDR *)lpar)->code == CDN_INITDONE) |
| 76 |
{ |
| 77 |
RECT deskrc; |
| 78 |
RECT dlgrc; |
| 79 |
int deskwid, deskht; |
| 80 |
int dlgwid, dlght; |
| 81 |
|
| 82 |
|
| 83 |
GetWindowRect(GetDesktopWindow(), &deskrc); |
| 84 |
deskwid = deskrc.right - deskrc.left; |
| 85 |
deskht = deskrc.bottom - deskrc.top; |
| 86 |
|
| 87 |
|
| 88 |
GetWindowRect(((NMHDR *)lpar)->hwndFrom, &dlgrc); |
| 89 |
dlgwid = dlgrc.right - dlgrc.left; |
| 90 |
dlght = dlgrc.bottom - dlgrc.top; |
| 91 |
|
| 92 |
|
| 93 |
MoveWindow(((NMHDR *)lpar)->hwndFrom, |
| 94 |
deskrc.left + (deskwid - dlgwid)/2, |
| 95 |
deskrc.top + (deskht - dlght)/2, dlgwid, dlght, TRUE); |
| 96 |
|
| 97 |
|
| 98 |
return 1; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
return 0; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
int os_askfile(const char *prompt, char *fname_buf, int fname_buf_len, |
| 110 |
int prompt_type, int file_type) |
| 111 |
{ |
| 112 |
OPENFILENAME info; |
| 113 |
int ret; |
| 114 |
char filter[256]; |
| 115 |
const char *def_ext; |
| 116 |
const char *save_def_ext; |
| 117 |
static char lastsave[OSFNMAX] = ""; |
| 118 |
|
| 119 |
|
| 120 |
def_ext = 0; |
| 121 |
save_def_ext = 0; |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
if (file_type == OSFTSAVE |
| 132 |
|| file_type == OSFTT3SAV |
| 133 |
|| file_type == OSFTUNK) |
| 134 |
{ |
| 135 |
static const char filter_start[] = |
| 136 |
"Saved Game Positions\0*."; |
| 137 |
static const char filter_end_sav[] = |
| 138 |
"All Files\0*.*\0\0"; |
| 139 |
static const char filter_end_unk[] = |
| 140 |
"TADS Games\0*.GAM\0" |
| 141 |
"Text Files\0*.TXT\0" |
| 142 |
"Log Files\0*.LOG\0" |
| 143 |
"All Files\0*.*\0\0"; |
| 144 |
size_t totlen; |
| 145 |
size_t extlen; |
| 146 |
const char *save_filter; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
if (default_saved_game_ext[0] != '\0') |
| 154 |
{ |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
save_filter = default_saved_game_ext; |
| 160 |
save_def_ext = default_saved_game_ext; |
| 161 |
} |
| 162 |
else if (file_type == OSFTSAVE) |
| 163 |
{ |
| 164 |
|
| 165 |
save_filter = "sav"; |
| 166 |
save_def_ext = "sav"; |
| 167 |
} |
| 168 |
else if (file_type == OSFTT3SAV) |
| 169 |
{ |
| 170 |
|
| 171 |
save_filter = "t3v"; |
| 172 |
save_def_ext = "t3v"; |
| 173 |
} |
| 174 |
else |
| 175 |
{ |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
save_filter = "sav;*.t3v"; |
| 186 |
save_def_ext = 0; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
memcpy(filter, filter_start, sizeof(filter_start) - 1); |
| 197 |
totlen = sizeof(filter_start) - 1; |
| 198 |
|
| 199 |
|
| 200 |
extlen = strlen(save_filter) + 1; |
| 201 |
memcpy(filter + totlen, save_filter, extlen); |
| 202 |
totlen += extlen; |
| 203 |
|
| 204 |
|
| 205 |
if (file_type == OSFTSAVE || file_type == OSFTT3SAV) |
| 206 |
{ |
| 207 |
|
| 208 |
memcpy(filter + totlen, filter_end_sav, sizeof(filter_end_sav)); |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
if (prompt_type == OS_AFP_SAVE) |
| 215 |
def_ext = save_def_ext; |
| 216 |
} |
| 217 |
else |
| 218 |
{ |
| 219 |
|
| 220 |
memcpy(filter + totlen, filter_end_unk, sizeof(filter_end_unk)); |
| 221 |
} |
| 222 |
} |
| 223 |
else |
| 224 |
{ |
| 225 |
static const struct |
| 226 |
{ |
| 227 |
const char *disp; |
| 228 |
const char *pat; |
| 229 |
const char *def_ext; |
| 230 |
} |
| 231 |
filters[] = |
| 232 |
{ |
| 233 |
{ "TADS Games", "*.gam", "gam" }, |
| 234 |
{ 0, 0 }, |
| 235 |
{ "Transcripts", "*.log", "log" }, |
| 236 |
{ "Swap Files", "*.dat", "dat" }, |
| 237 |
{ "Data Files", "*.dat", "dat" }, |
| 238 |
{ "Command Scripts", "*.cmd", "cmd" }, |
| 239 |
{ "Message Files", "*.msg", "msg" }, |
| 240 |
{ "Text Files", "*.txt", "txt" }, |
| 241 |
{ "Binary Files", "*.dat", "dat" }, |
| 242 |
{ "Character Maps", "*.tcp", "tcp" }, |
| 243 |
{ "Preference Files","*.dat", "dat" }, |
| 244 |
{ 0, 0, 0 }, |
| 245 |
{ "T3 Applications", "*.t3" , "t3" }, |
| 246 |
{ "T3 Object Files", "*.t3o", "t3o" }, |
| 247 |
{ "T3 Symbol Files", "*.t3s", "t3s" }, |
| 248 |
{ 0, 0, 0 } |
| 249 |
}; |
| 250 |
static const char filter_end[] = "All Files\0*.*\0\0"; |
| 251 |
char *p; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
strcpy(filter, filters[file_type].disp); |
| 258 |
|
| 259 |
|
| 260 |
p = filter + strlen(filter) + 1; |
| 261 |
strcpy(p, filters[file_type].pat); |
| 262 |
|
| 263 |
|
| 264 |
p += strlen(p) + 1; |
| 265 |
memcpy(p, filter_end, sizeof(filter_end)); |
| 266 |
|
| 267 |
|
| 268 |
save_def_ext = def_ext = filters[file_type].def_ext; |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
info.lStructSize = sizeof(info); |
| 273 |
info.hwndOwner = GetActiveWindow(); |
| 274 |
info.hInstance = oss_G_hinstance; |
| 275 |
info.lpstrFilter = filter; |
| 276 |
info.lpstrCustomFilter = 0; |
| 277 |
info.nFilterIndex = 0; |
| 278 |
info.lpstrFile = fname_buf; |
| 279 |
fname_buf[0] = '\0'; |
| 280 |
info.nMaxFile = fname_buf_len; |
| 281 |
info.lpstrFileTitle = 0; |
| 282 |
info.nMaxFileTitle = 0; |
| 283 |
info.lpstrInitialDir = (S_open_file_dir[0] != '\0' ? S_open_file_dir : 0); |
| 284 |
info.lpstrTitle = prompt; |
| 285 |
info.nFileOffset = 0; |
| 286 |
info.nFileExtension = 0; |
| 287 |
info.lpstrDefExt = def_ext; |
| 288 |
info.lCustData = 0; |
| 289 |
info.lpfnHook = filedlg_hook; |
| 290 |
info.Flags = OFN_ENABLEHOOK | OFN_EXPLORER | OFN_NOCHANGEDIR; |
| 291 |
info.lpTemplateName = 0; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
if (file_type == OSFTSAVE || file_type == OSFTT3SAV) |
| 301 |
{ |
| 302 |
|
| 303 |
strncpy(fname_buf, lastsave, fname_buf_len); |
| 304 |
fname_buf[fname_buf_len - 1] = '\0'; |
| 305 |
|
| 306 |
|
| 307 |
if (fname_buf[0] == '\0' && G_os_gamename[0] != '\0') |
| 308 |
{ |
| 309 |
|
| 310 |
strncpy(fname_buf, G_os_gamename, fname_buf_len); |
| 311 |
fname_buf[fname_buf_len - 1] = '\0'; |
| 312 |
|
| 313 |
|
| 314 |
os_remext(fname_buf); |
| 315 |
|
| 316 |
|
| 317 |
if (save_def_ext != 0 |
| 318 |
&& strlen(fname_buf) + strlen(save_def_ext) + 1 |
| 319 |
< (size_t)fname_buf_len) |
| 320 |
os_defext(fname_buf, save_def_ext); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
if (prompt_type == OS_AFP_OPEN && osfacc(fname_buf)) |
| 329 |
fname_buf[0] = '\0'; |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
if (prompt_type == OS_AFP_SAVE) |
| 334 |
{ |
| 335 |
info.Flags |= OFN_NOCHANGEDIR | OFN_OVERWRITEPROMPT; |
| 336 |
ret = GetSaveFileName(&info); |
| 337 |
} |
| 338 |
else |
| 339 |
{ |
| 340 |
|
| 341 |
ret = GetOpenFileName(&info); |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
if (ret == 0) |
| 346 |
{ |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
ret = (CommDlgExtendedError() == 0 ? OS_AFE_CANCEL : OS_AFE_FAILURE); |
| 353 |
} |
| 354 |
else |
| 355 |
{ |
| 356 |
char path[OSFNMAX]; |
| 357 |
|
| 358 |
|
| 359 |
ret = OS_AFE_SUCCESS; |
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
os_get_path_name(path, sizeof(path), fname_buf); |
| 367 |
oss_set_open_file_dir(path); |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
if (file_type == OSFTSAVE || file_type == OSFTT3SAV) |
| 374 |
strcpy(lastsave, fname_buf); |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
return ret; |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
int os_paramfile(char *buf) |
| 388 |
{ |
| 389 |
|
| 390 |
return 0; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
void os_set_pwd(const char *dir) |
| 398 |
{ |
| 399 |
SetCurrentDirectory(dir); |
| 400 |
} |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
void os_set_pwd_file(const char *fname) |
| 406 |
{ |
| 407 |
char buf[OSFNMAX]; |
| 408 |
char *p; |
| 409 |
char *last_sep; |
| 410 |
|
| 411 |
|
| 412 |
strcpy(buf, fname); |
| 413 |
|
| 414 |
|
| 415 |
for (p = buf, last_sep = 0 ; *p != '\0' ; ++p) |
| 416 |
{ |
| 417 |
switch(*p) |
| 418 |
{ |
| 419 |
case '/': |
| 420 |
case '\\': |
| 421 |
case ':': |
| 422 |
|
| 423 |
last_sep = p; |
| 424 |
break; |
| 425 |
} |
| 426 |
} |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
if (last_sep != 0) |
| 434 |
{ |
| 435 |
*last_sep = '\0'; |
| 436 |
os_set_pwd(buf); |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
static void set_reg_key(char *keyname, char *valname, char *val) |
| 445 |
{ |
| 446 |
DWORD disposition; |
| 447 |
HKEY hkey; |
| 448 |
|
| 449 |
|
| 450 |
if (RegCreateKeyEx(HKEY_CLASSES_ROOT, keyname, 0, 0, 0, KEY_ALL_ACCESS, |
| 451 |
0, &hkey, &disposition) == ERROR_SUCCESS) |
| 452 |
{ |
| 453 |
|
| 454 |
RegSetValueEx(hkey, valname, 0, REG_SZ, (BYTE *)val, strlen(val) + 1); |
| 455 |
|
| 456 |
|
| 457 |
RegCloseKey(hkey); |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
void os_set_save_ext(const char *ext) |
| 466 |
{ |
| 467 |
HKEY hkey; |
| 468 |
char keyname[MAX_PATH]; |
| 469 |
|
| 470 |
|
| 471 |
strcpy(default_saved_game_ext, ext); |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
sprintf(keyname, ".%s", ext); |
| 478 |
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, keyname, 0, KEY_ALL_ACCESS, &hkey) |
| 479 |
== ERROR_SUCCESS) |
| 480 |
{ |
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
RegCloseKey(hkey); |
| 486 |
} |
| 487 |
else |
| 488 |
{ |
| 489 |
char modname[MAX_PATH]; |
| 490 |
char val[MAX_PATH]; |
| 491 |
char classname[MAX_PATH]; |
| 492 |
char cmd[MAX_PATH + 30]; |
| 493 |
char *p; |
| 494 |
char *rootname; |
| 495 |
char *lastdot; |
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
GetModuleFileName(0, modname, sizeof(modname)); |
| 510 |
for (p = rootname = modname ; *p != '\0' ; ++p) |
| 511 |
{ |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
if (*p == '\\' || *p == '/' || *p == ':') |
| 518 |
rootname = p + 1; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
sprintf(classname, "%s.SavedGame", rootname); |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
set_reg_key(keyname, "", classname); |
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
for (p = rootname, lastdot = p + strlen(p) ; *p != '\0' ; ++p) |
| 537 |
{ |
| 538 |
|
| 539 |
if (*p == '.') |
| 540 |
lastdot = p; |
| 541 |
} |
| 542 |
sprintf(val, "\"%.*s\" Saved Game", lastdot - rootname, rootname); |
| 543 |
set_reg_key(classname, "", val); |
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
sprintf(cmd, "\"%s\" -r \"%%1\"", modname); |
| 551 |
sprintf(keyname, "%s\\Shell\\Open\\Command", classname); |
| 552 |
set_reg_key(keyname, "", cmd); |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
sprintf(cmd, "%s,2", modname); |
| 559 |
sprintf(keyname, "%s\\DefaultIcon", classname); |
| 560 |
set_reg_key(keyname, "", cmd); |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
const char *os_get_save_ext() |
| 565 |
{ |
| 566 |
return (default_saved_game_ext[0] != '\0' ? default_saved_game_ext : 0); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
void os_gen_charmap_filename(char *filename, char *internal_id, |
| 576 |
char *argv0) |
| 577 |
{ |
| 578 |
char *p; |
| 579 |
char *rootname; |
| 580 |
size_t pathlen; |
| 581 |
|
| 582 |
|
| 583 |
for (p = rootname = argv0 ; *p != '\0' ; ++p) |
| 584 |
{ |
| 585 |
if (*p == '/' || *p == '\\' || *p == ':') |
| 586 |
rootname = p + 1; |
| 587 |
} |
| 588 |
|
| 589 |
|
| 590 |
pathlen = rootname - argv0; |
| 591 |
memcpy(filename, argv0, pathlen); |
| 592 |
|
| 593 |
|
| 594 |
if (pathlen == 0 || filename[pathlen - 1] != '\\') |
| 595 |
filename[pathlen++] = '\\'; |
| 596 |
|
| 597 |
|
| 598 |
strcpy(filename + pathlen, "win_"); |
| 599 |
strcat(filename + pathlen, internal_id); |
| 600 |
strcat(filename + pathlen, ".tcp"); |
| 601 |
} |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
void os_get_charmap(char *mapname, int charmap_id) |
| 608 |
{ |
| 609 |
|
| 610 |
sprintf(mapname, "CP%d", GetACP()); |
| 611 |
} |
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
void os_sleep_ms(long delay_in_milliseconds) |
| 624 |
{ |
| 625 |
long done_time; |
| 626 |
|
| 627 |
|
| 628 |
done_time = os_get_sys_clock_ms() + delay_in_milliseconds; |
| 629 |
|
| 630 |
|
| 631 |
for (;;) |
| 632 |
{ |
| 633 |
long cur_time; |
| 634 |
os_event_info_t info; |
| 635 |
|
| 636 |
|
| 637 |
cur_time = GetTickCount(); |
| 638 |
|
| 639 |
|
| 640 |
if (cur_time >= done_time) |
| 641 |
break; |
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
if (os_get_event(done_time - cur_time, TRUE, &info) == OS_EVT_EOF) |
| 648 |
break; |
| 649 |
} |
| 650 |
} |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
static struct |
| 662 |
{ |
| 663 |
|
| 664 |
int default_id; |
| 665 |
|
| 666 |
|
| 667 |
int cancel_id; |
| 668 |
} S_dlg_params; |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
static BOOL CALLBACK oss_input_dialog_proc(HWND hwnd, UINT msg, |
| 674 |
WPARAM wpar, LPARAM lpar) |
| 675 |
{ |
| 676 |
switch(msg) |
| 677 |
{ |
| 678 |
case WM_INITDIALOG: |
| 679 |
|
| 680 |
if (S_dlg_params.default_id != 0) |
| 681 |
{ |
| 682 |
|
| 683 |
SetFocus(GetDlgItem(hwnd, S_dlg_params.default_id)); |
| 684 |
|
| 685 |
|
| 686 |
return 0; |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
return 1; |
| 691 |
|
| 692 |
case WM_COMMAND: |
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
if (wpar == IDCANCEL || wpar == IDCLOSE) |
| 698 |
{ |
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
if (S_dlg_params.cancel_id != 0) |
| 705 |
EndDialog(hwnd, S_dlg_params.cancel_id); |
| 706 |
|
| 707 |
|
| 708 |
return 1; |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
if (wpar == IDOK) |
| 716 |
{ |
| 717 |
|
| 718 |
if (S_dlg_params.default_id != 0) |
| 719 |
EndDialog(hwnd, S_dlg_params.default_id); |
| 720 |
|
| 721 |
|
| 722 |
return 1; |
| 723 |
} |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
EndDialog(hwnd, wpar); |
| 731 |
return 1; |
| 732 |
|
| 733 |
default: |
| 734 |
|
| 735 |
return 0; |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
#define OS_ID_CMD_BASE 100 |
| 741 |
|
| 742 |
|
| 743 |
#define OS_ID_ICON_X 32 |
| 744 |
#define OS_ID_ICON_Y 32 |
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
int os_input_dialog(int icon_id, const char *prompt, int standard_button_set, |
| 751 |
const char **buttons, int button_count, |
| 752 |
int default_index, int cancel_index) |
| 753 |
{ |
| 754 |
|
| 755 |
if (standard_button_set != 0) |
| 756 |
{ |
| 757 |
DWORD flags; |
| 758 |
int ret; |
| 759 |
|
| 760 |
|
| 761 |
switch(standard_button_set) |
| 762 |
{ |
| 763 |
case OS_INDLG_OK: |
| 764 |
flags = MB_OK; |
| 765 |
break; |
| 766 |
|
| 767 |
case OS_INDLG_OKCANCEL: |
| 768 |
flags = MB_OKCANCEL; |
| 769 |
break; |
| 770 |
|
| 771 |
case OS_INDLG_YESNO: |
| 772 |
flags = MB_YESNO; |
| 773 |
break; |
| 774 |
|
| 775 |
case OS_INDLG_YESNOCANCEL: |
| 776 |
flags = MB_YESNOCANCEL; |
| 777 |
break; |
| 778 |
|
| 779 |
default: |
| 780 |
|
| 781 |
return 0; |
| 782 |
} |
| 783 |
|
| 784 |
|
| 785 |
switch(icon_id) |
| 786 |
{ |
| 787 |
case OS_INDLG_ICON_NONE: |
| 788 |
break; |
| 789 |
|
| 790 |
case OS_INDLG_ICON_WARNING: |
| 791 |
flags |= MB_ICONWARNING; |
| 792 |
break; |
| 793 |
|
| 794 |
case OS_INDLG_ICON_INFO: |
| 795 |
flags |= MB_ICONINFORMATION; |
| 796 |
break; |
| 797 |
|
| 798 |
case OS_INDLG_ICON_QUESTION: |
| 799 |
flags |= MB_ICONQUESTION; |
| 800 |
break; |
| 801 |
|
| 802 |
case OS_INDLG_ICON_ERROR: |
| 803 |
flags |= MB_ICONERROR; |
| 804 |
break; |
| 805 |
} |
| 806 |
|
| 807 |
|
| 808 |
flags |= MB_TASKMODAL; |
| 809 |
|
| 810 |
|
| 811 |
switch(default_index) |
| 812 |
{ |
| 813 |
case 1: |
| 814 |
flags |= MB_DEFBUTTON1; |
| 815 |
break; |
| 816 |
|
| 817 |
case 2: |
| 818 |
flags |= MB_DEFBUTTON2; |
| 819 |
break; |
| 820 |
|
| 821 |
case 3: |
| 822 |
flags |= MB_DEFBUTTON3; |
| 823 |
break; |
| 824 |
|
| 825 |
case 4: |
| 826 |
flags |= MB_DEFBUTTON4; |
| 827 |
break; |
| 828 |
} |
| 829 |
|
| 830 |
|
| 831 |
ret = MessageBox(0, prompt, "TADS", flags); |
| 832 |
|
| 833 |
|
| 834 |
switch(ret) |
| 835 |
{ |
| 836 |
case 0: |
| 837 |
default: |
| 838 |
|
| 839 |
return 0; |
| 840 |
|
| 841 |
case IDYES: |
| 842 |
|
| 843 |
return 1; |
| 844 |
|
| 845 |
case IDNO: |
| 846 |
|
| 847 |
return 2; |
| 848 |
|
| 849 |
case IDCANCEL: |
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
switch(standard_button_set) |
| 855 |
{ |
| 856 |
case OS_INDLG_OKCANCEL: |
| 857 |
return 2; |
| 858 |
|
| 859 |
case OS_INDLG_YESNOCANCEL: |
| 860 |
return 3; |
| 861 |
} |
| 862 |
|
| 863 |
|
| 864 |
return 0; |
| 865 |
|
| 866 |
case IDOK: |
| 867 |
|
| 868 |
return 1; |
| 869 |
} |
| 870 |
} |
| 871 |
else |
| 872 |
{ |
| 873 |
#define MAX_BUTTONS 16 |
| 874 |
#define MAX_LABEL_CHARS 1024 |
| 875 |
struct |
| 876 |
{ |
| 877 |
DLGTEMPLATE hdr; |
| 878 |
WORD menu_arr[1]; |
| 879 |
WORD class_arr[1]; |
| 880 |
|
| 881 |
|
| 882 |
wchar_t title_arr[128]; |
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
WORD buf[sizeof(DLGITEMTEMPLATE)*MAX_BUTTONS/2 |
| 891 |
+ MAX_LABEL_CHARS |
| 892 |
+ 2*MAX_BUTTONS]; |
| 893 |
} tpl; |
| 894 |
DLGITEMTEMPLATE *itm; |
| 895 |
int chrem = MAX_LABEL_CHARS; |
| 896 |
int chcur; |
| 897 |
wchar_t *p; |
| 898 |
int i; |
| 899 |
HDC dc = GetDC(GetDesktopWindow()); |
| 900 |
SIZE txtsiz; |
| 901 |
TEXTMETRIC tm; |
| 902 |
LONG dlg_base_units; |
| 903 |
int dlgx, dlgy; |
| 904 |
int btn_total_wid; |
| 905 |
int curx; |
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
if (button_count > MAX_BUTTONS) |
| 912 |
button_count = MAX_BUTTONS; |
| 913 |
|
| 914 |
|
| 915 |
dlg_base_units = GetDialogBaseUnits(); |
| 916 |
dlgx = LOWORD(dlg_base_units); |
| 917 |
dlgy = HIWORD(dlg_base_units); |
| 918 |
|
| 919 |
|
| 920 |
tpl.hdr.style = DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SETFONT; |
| 921 |
tpl.hdr.dwExtendedStyle = 0; |
| 922 |
tpl.hdr.x = 0; |
| 923 |
tpl.hdr.y = 0; |
| 924 |
tpl.hdr.cx = 300; |
| 925 |
tpl.hdr.cy = 94; |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
GetTextMetrics(dc, &tm); |
| 934 |
i = MulDiv(tm.tmHeight, 8, dlgy) + 8; |
| 935 |
if (i > 14) |
| 936 |
tpl.hdr.cy += 14 - i; |
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
tpl.hdr.cdit = 1 + (icon_id != 0 ? 1 : 0) + button_count; |
| 943 |
|
| 944 |
|
| 945 |
tpl.menu_arr[0] = 0; |
| 946 |
tpl.class_arr[0] = 0; |
| 947 |
|
| 948 |
|
| 949 |
wcscpy(tpl.title_arr, (const wchar_t *)L"TADS"); |
| 950 |
|
| 951 |
|
| 952 |
p = tpl.title_arr + wcslen(tpl.title_arr) + 1; |
| 953 |
|
| 954 |
|
| 955 |
*p++ = 8; |
| 956 |
wcscpy(p, (const wchar_t *)L"MS Sans Serif"); |
| 957 |
|
| 958 |
|
| 959 |
p += wcslen(p) + 1; |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
itm = (DLGITEMTEMPLATE *)((((unsigned long)(p)) + 3) & ~3); |
| 966 |
|
| 967 |
|
| 968 |
switch(icon_id) |
| 969 |
{ |
| 970 |
case OS_INDLG_ICON_WARNING: |
| 971 |
icon_id = (int)IDI_EXCLAMATION; |
| 972 |
break; |
| 973 |
|
| 974 |
case OS_INDLG_ICON_INFO: |
| 975 |
icon_id = (int)IDI_ASTERISK; |
| 976 |
break; |
| 977 |
|
| 978 |
case OS_INDLG_ICON_QUESTION: |
| 979 |
icon_id = (int)IDI_QUESTION; |
| 980 |
break; |
| 981 |
|
| 982 |
case OS_INDLG_ICON_ERROR: |
| 983 |
icon_id = (int)IDI_HAND; |
| 984 |
break; |
| 985 |
|
| 986 |
default: |
| 987 |
|
| 988 |
icon_id = 0; |
| 989 |
break; |
| 990 |
} |
| 991 |
|
| 992 |
|
| 993 |
if (icon_id != 0) |
| 994 |
{ |
| 995 |
|
| 996 |
itm->style = SS_ICON | WS_VISIBLE | WS_CHILD; |
| 997 |
itm->dwExtendedStyle = 0; |
| 998 |
itm->x = 10; |
| 999 |
itm->y = 10; |
| 1000 |
itm->cx = OS_ID_ICON_X; |
| 1001 |
itm->cy = OS_ID_ICON_Y; |
| 1002 |
itm->id = (WORD)-1; |
| 1003 |
|
| 1004 |
|
| 1005 |
p = (WORD *)(itm + 1); |
| 1006 |
*p++ = 0xffff; |
| 1007 |
*p++ = 0x0082; |
| 1008 |
|
| 1009 |
|
| 1010 |
*p++ = 0xffff; |
| 1011 |
*p++ = icon_id; |
| 1012 |
|
| 1013 |
|
| 1014 |
*p++ = 0; |
| 1015 |
|
| 1016 |
|
| 1017 |
itm = (DLGITEMTEMPLATE *)((((unsigned long)(p)) + 3) & ~3); |
| 1018 |
} |
| 1019 |
|
| 1020 |
|
| 1021 |
itm->style = WS_VISIBLE | WS_CHILD; |
| 1022 |
itm->dwExtendedStyle = 0; |
| 1023 |
itm->x = 10 + (icon_id == 0 ? 0 : OS_ID_ICON_X + 2); |
| 1024 |
itm->y = 10; |
| 1025 |
itm->cx = tpl.hdr.cx - 14 - (icon_id == 0 ? 0 : OS_ID_ICON_X + 2); |
| 1026 |
itm->cy = 32; |
| 1027 |
itm->id = (WORD)-1; |
| 1028 |
|
| 1029 |
|
| 1030 |
p = (WORD *)(itm + 1); |
| 1031 |
*p++ = 0xffff; |
| 1032 |
*p++ = 0x0082; |
| 1033 |
|
| 1034 |
|
| 1035 |
chcur = MultiByteToWideChar(CP_ACP, 0, prompt, -1, p, chrem); |
| 1036 |
chrem -= chcur; |
| 1037 |
p += chcur; |
| 1038 |
|
| 1039 |
|
| 1040 |
*p++ = 0; |
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
for (btn_total_wid = 0, i = 0 ; i < button_count ; ++i) |
| 1048 |
{ |
| 1049 |
short wid; |
| 1050 |
|
| 1051 |
|
| 1052 |
GetTextExtentPoint32(dc, buttons[i], strlen(buttons[i]), &txtsiz); |
| 1053 |
wid = (short)MulDiv(txtsiz.cx, 4, dlgx); |
| 1054 |
|
| 1055 |
|
| 1056 |
wid += 8; |
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
if (wid < 64) |
| 1063 |
wid = 64; |
| 1064 |
|
| 1065 |
|
| 1066 |
btn_total_wid += wid; |
| 1067 |
|
| 1068 |
|
| 1069 |
if (i != 0) |
| 1070 |
btn_total_wid += 4; |
| 1071 |
} |
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
if (tpl.hdr.cx < btn_total_wid + 8) |
| 1079 |
tpl.hdr.cx = btn_total_wid + 8; |
| 1080 |
|
| 1081 |
|
| 1082 |
itm = (DLGITEMTEMPLATE *)((((unsigned long)(p)) + 3) & ~3); |
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
curx = (tpl.hdr.cx - btn_total_wid) / 2; |
| 1089 |
|
| 1090 |
|
| 1091 |
for (i = 0 ; i < button_count ; ++i) |
| 1092 |
{ |
| 1093 |
|
| 1094 |
itm->style = BS_PUSHBUTTON | WS_VISIBLE | WS_TABSTOP |
| 1095 |
| WS_CHILD; |
| 1096 |
itm->dwExtendedStyle = 0; |
| 1097 |
itm->id = i + 1 + OS_ID_CMD_BASE; |
| 1098 |
|
| 1099 |
|
| 1100 |
GetTextExtentPoint32(dc, buttons[i], strlen(buttons[i]), &txtsiz); |
| 1101 |
GetTextMetrics(dc, &tm); |
| 1102 |
itm->cx = (short)MulDiv(txtsiz.cx, 4, dlgx) + 8; |
| 1103 |
itm->cy = (short)MulDiv(tm.tmHeight, 8, dlgy) + 8; |
| 1104 |
|
| 1105 |
|
| 1106 |
if (itm->cx < 64) |
| 1107 |
itm->cx = 64; |
| 1108 |
|
| 1109 |
|
| 1110 |
itm->x = curx; |
| 1111 |
itm->y = tpl.hdr.cy - itm->cy - 18; |
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
curx += itm->cx + 4; |
| 1118 |
|
| 1119 |
|
| 1120 |
p = (WORD *)(itm + 1); |
| 1121 |
*p++ = 0xffff; |
| 1122 |
*p++ = 0x0080; |
| 1123 |
|
| 1124 |
|
| 1125 |
chcur = MultiByteToWideChar(CP_ACP, 0, buttons[i], -1, p, chrem); |
| 1126 |
chrem -= chcur; |
| 1127 |
p += chcur; |
| 1128 |
|
| 1129 |
|
| 1130 |
*p++ = 0; |
| 1131 |
|
| 1132 |
|
| 1133 |
itm = (DLGITEMTEMPLATE *)((((unsigned long)(p)) + 3) & ~3); |
| 1134 |
} |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
S_dlg_params.default_id = (default_index == 0 |
| 1142 |
? 0 : default_index + OS_ID_CMD_BASE); |
| 1143 |
S_dlg_params.cancel_id = (cancel_index == 0 |
| 1144 |
? 0 : cancel_index + OS_ID_CMD_BASE); |
| 1145 |
|
| 1146 |
|
| 1147 |
ReleaseDC(GetDesktopWindow(), dc); |
| 1148 |
|
| 1149 |
|
| 1150 |
os_flush(); |
| 1151 |
|
| 1152 |
|
| 1153 |
i = DialogBoxIndirect(oss_G_hinstance, &tpl.hdr, GetActiveWindow(), |
| 1154 |
(DLGPROC)oss_input_dialog_proc); |
| 1155 |
|
| 1156 |
|
| 1157 |
if (i >= OS_ID_CMD_BASE) |
| 1158 |
{ |
| 1159 |
|
| 1160 |
i -= OS_ID_CMD_BASE; |
| 1161 |
} |
| 1162 |
else |
| 1163 |
{ |
| 1164 |
|
| 1165 |
i = 0; |
| 1166 |
} |
| 1167 |
|
| 1168 |
|
| 1169 |
return i; |
| 1170 |
|
| 1171 |
#undef MAX_LABEL_CHARS |
| 1172 |
#undef MAX_BUTTONS |
| 1173 |
} |
| 1174 |
} |
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
int os_get_str_rsc(int id, char *buf, size_t buflen) |
| 1184 |
{ |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
return (LoadString(oss_G_hinstance, id + 61000, buf, buflen) == 0); |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
char *os_strlwr(char *s) |
| 1196 |
{ |
| 1197 |
return strlwr(s); |
| 1198 |
} |
| 1199 |
|