NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/vibrant/vibutils.c |
source navigation diff markup identifier search freetext search file search |
1 /* vibutils.c 2 * =========================================================================== 3 * 4 * PUBLIC DOMAIN NOTICE 5 * National Center for Biotechnology Information (NCBI) 6 * 7 * This software/database is a "United States Government Work" under the 8 * terms of the United States Copyright Act. It was written as part of 9 * the author's official duties as a United States Government employee and 10 * thus cannot be copyrighted. This software/database is freely available 11 * to the public for use. The National Library of Medicine and the U.S. 12 * Government do not place any restriction on its use or reproduction. 13 * We would, however, appreciate having the NCBI and the author cited in 14 * any work or product based on this material 15 * 16 * Although all reasonable efforts have been taken to ensure the accuracy 17 * and reliability of the software and data, the NLM and the U.S. 18 * Government do not and cannot warrant the performance or results that 19 * may be obtained by using this software or data. The NLM and the U.S. 20 * Government disclaim all warranties, express or implied, including 21 * warranties of performance, merchantability or fitness for any particular 22 * purpose. 23 * 24 * =========================================================================== 25 * 26 * File Name: vibutils.c 27 * 28 * Author: Jonathan Kans 29 * 30 * Version Creation Date: 7/1/91 31 * 32 * $Revision: 6.78 $ 33 * 34 * File Description: 35 * Vibrant miscellaneous functions 36 * 37 * Modifications: 38 * -------------------------------------------------------------------------- 39 * 40 * ========================================================================== 41 */ 42 43 #include <ncbilcl.h> 44 45 #ifdef WIN_MAC 46 #ifdef __MWERKS__ 47 # if TARGET_API_MAC_CARBON 48 /* Use non-session APIs of the Carbon Printing Manager, for easy porting */ 49 # include <PMApplication.h> 50 # ifndef OS_UNIX_DARWIN 51 # include <FullPath.h> 52 #endif 53 # endif 54 # ifdef OS_UNIX_DARWIN 55 # include <LaunchServices.h> 56 # include <Files.h> 57 # endif 58 # include <Navigation.h> 59 #endif 60 #endif 61 62 #include <vibtypes.h> 63 #include <vibprocs.h> 64 #include <vibincld.h> 65 #include <ncbiport.h> 66 67 68 #ifdef WIN_MOTIF 69 #include <sys/times.h> 70 #include <limits.h> 71 #endif 72 73 #ifdef WIN_MAC 74 Nlm_Int2 Nlm_nextIdNumber = 2; 75 #endif 76 #ifdef WIN_MSWIN 77 #include <CommCtrl.h> 78 Nlm_Int2 Nlm_nextIdNumber = 102; 79 #endif 80 #ifdef WIN_MOTIF 81 Nlm_Int2 Nlm_nextIdNumber = 1; 82 #endif 83 84 Nlm_PoinT Nlm_globalMouse; 85 Nlm_PoinT Nlm_localMouse; 86 87 Nlm_Int2 Nlm_hScrollBarHeight; 88 Nlm_Int2 Nlm_vScrollBarWidth; 89 90 Nlm_Int2 Nlm_dialogTextHeight; 91 Nlm_Int2 Nlm_popupMenuHeight; 92 93 Nlm_Char Nlm_currentKey = '\0'; 94 95 Nlm_Boolean Nlm_cmmdKey = FALSE; 96 Nlm_Boolean Nlm_ctrlKey = FALSE; 97 Nlm_Boolean Nlm_optKey = FALSE; 98 Nlm_Boolean Nlm_shftKey = FALSE; 99 Nlm_Boolean Nlm_dblClick = FALSE; 100 101 #ifndef WIN_MSWIN 102 static Nlm_Boolean errorBoxUp = FALSE; 103 static Nlm_Int2 errorBoxRsult = 0; 104 #endif 105 106 static Nlm_GraphiC recentGraphic = NULL; 107 static Nlm_GraphicData recentGraphicData; 108 109 static Nlm_BoX recentBox = NULL; 110 static Nlm_BoxData recentBoxData; 111 112 #ifdef WIN_MAC 113 # if TARGET_API_MAC_CARBON 114 static PMPrintSession printSession; 115 116 static PMPageFormat pageFormat = kPMNoPageFormat; 117 static PMPrintSettings printSettings = kPMNoPrintSettings; 118 static PMPrintContext thePrintingPort = kPMNoReference; 119 # else 120 static THPrint prHdl = NULL; 121 static TPPrPort prPort = NULL; 122 static Nlm_Int2 prerr; 123 static Nlm_Char fileTypes [32] = {0}; 124 # endif 125 #endif 126 127 #ifdef WIN_MSWIN 128 static Nlm_Boolean abortPrint; 129 static HDC hPr = NULL; 130 static int prerr; 131 /* 132 static int vibrant_disabled = 0; 133 */ 134 static int disabled_count = 0; 135 static PRINTDLG pd; 136 static OPENFILENAME ofn; 137 #endif 138 139 #ifdef WIN_MOTIF 140 static Widget fileDialog = NULL; 141 static Nlm_Boolean fileBoxUp; 142 static Nlm_Boolean fileBoxRsult; 143 static Nlm_Char filePath [256]; 144 #endif 145 146 extern Nlm_Boolean Nlm_usesMacNavServices; 147 148 extern Nlm_CharPtr Nlm_StrngPrintable(const Nlm_Char PNTR str) 149 { 150 #ifdef WIN_MAC 151 Nlm_CharPtr s, x_str, tmp; 152 153 if (str == NULL) return NULL; 154 tmp = Nlm_StringSave (str); 155 for (s = tmp; *s; s++) { 156 if (*s == '\r') { 157 *s = '\n'; /* convert 015 in text object to newline for StringPrintable */ 158 } 159 } 160 x_str = Nlm_StringPrintable(tmp, FALSE); 161 Nlm_MemFree (tmp); 162 if ( !x_str ) 163 return NULL; 164 165 for (s = x_str; *s; s++) { 166 if (*s == '\n' || *s == '\r') { 167 *s = '\015'; /* convert back for text object */ 168 } 169 } 170 return x_str; 171 #else 172 return Nlm_StringPrintable(str, TRUE); 173 #endif 174 } 175 176 177 extern Nlm_Uint4 Nlm_StrngLen (Nlm_CharPtr string) 178 { 179 Nlm_Uint4 len; 180 181 len = 0; 182 if (string != NULL) { 183 while (*string != '\0') { 184 string++; 185 len++; 186 } 187 } 188 return len; 189 } 190 191 extern void Nlm_StrngCat (Nlm_CharPtr dest, Nlm_CharPtr source, size_t maxsize) 192 193 { 194 Nlm_Uint4 count; 195 Nlm_Uint4 i; 196 197 if (dest != NULL && source != NULL && maxsize > 0) { 198 count = Nlm_StrngLen (source); 199 i = Nlm_StrngLen (dest); 200 if (count + i >= maxsize) { 201 count = maxsize - i - 1; 202 } 203 dest += i; 204 while (count > 0) { 205 *dest = *source; 206 dest++; 207 source++; 208 count--; 209 } 210 *dest = '\0'; 211 } 212 } 213 214 extern void Nlm_StrngCpy (Nlm_CharPtr dest, Nlm_CharPtr source, size_t maxsize) 215 216 { 217 Nlm_Uint4 count; 218 219 if (dest != NULL && maxsize > 0) { 220 count = Nlm_StrngLen (source); 221 if (count >= maxsize) { 222 count = maxsize - 1; 223 } 224 while (count > 0) { 225 *dest = *source; 226 dest++; 227 source++; 228 count--; 229 } 230 *dest = '\0'; 231 } 232 } 233 234 static Nlm_Boolean Nlm_InNumber (Nlm_Char ch) 235 236 { 237 return (Nlm_Boolean) (ch >= '0' && ch <= '9') ; 238 } 239 240 static Nlm_Char Nlm_Cap (Nlm_Char ch, Nlm_Boolean caseCounts) 241 242 { 243 if (caseCounts) { 244 return ch; 245 } else if (ch >= 'a' && ch <= 'z') { 246 return (Nlm_Char) (ch - ' '); 247 } else { 248 return ch; 249 } 250 } 251 252 extern Nlm_Boolean Nlm_StrngPos (Nlm_CharPtr str, Nlm_CharPtr sub, 253 Nlm_Uint4 start, Nlm_Boolean caseCounts, 254 Nlm_Uint4Ptr match) 255 256 { 257 Nlm_Char ch1; 258 Nlm_Char ch2; 259 Nlm_Uint4 count; 260 Nlm_Boolean found; 261 Nlm_Uint4 i; 262 Nlm_Uint4 j; 263 Nlm_Uint4 len; 264 Nlm_Uint4 max; 265 Nlm_Uint4 sublen; 266 267 found = FALSE; 268 if (str != NULL && sub != NULL) { 269 len = Nlm_StrngLen (str); 270 sublen = Nlm_StrngLen (sub); 271 if (len < sublen) { 272 sublen = len; 273 } 274 max = len - sublen; 275 i = start; 276 if (match != NULL) { 277 *match = 0; 278 } 279 if (start < len) { 280 do { 281 found = TRUE; 282 j = 0; 283 count = sublen; 284 while (found && count > 0) { 285 ch1 = Nlm_Cap (str [i + j], caseCounts); 286 ch2 = Nlm_Cap (sub [j], caseCounts); 287 if (ch1 != ch2) { 288 found = FALSE; 289 } 290 j++; 291 count--; 292 } 293 if (found && match != NULL) { 294 *match = i; 295 } 296 i++; 297 } while ((! found) && (i <= max)); 298 } 299 else { 300 found = FALSE; 301 } 302 } 303 return found; 304 } 305 306 extern void Nlm_StrngSeg (Nlm_CharPtr dest, Nlm_CharPtr source, 307 Nlm_Uint4 start, Nlm_Uint4 length, 308 size_t maxsize) 309 310 { 311 Nlm_Uint4 count; 312 Nlm_Uint4 len; 313 314 if (dest != NULL && source != NULL && maxsize > 0) { 315 count = length; 316 len = Nlm_StrngLen (source); 317 if (start + length > len) { 318 count = len - start; 319 } 320 if (count >= maxsize) { 321 count = maxsize - 1; 322 } 323 source += start; 324 while (count > 0) { 325 *dest = *source; 326 dest++; 327 source++; 328 count--; 329 } 330 *dest = '\0'; 331 } 332 } 333 334 extern void Nlm_StrngRep (Nlm_CharPtr dest, Nlm_CharPtr source, 335 Nlm_Uint4 start, size_t maxsize) 336 337 { 338 Nlm_Uint4 count; 339 340 if (dest != NULL && source != NULL && maxsize > 0) { 341 count = Nlm_StrngLen (source); 342 if (count + start >= maxsize) { 343 count = maxsize - start - 1; 344 } 345 dest += start; 346 while (count > 0) { 347 *dest = *source; 348 dest++; 349 source++; 350 count--; 351 } 352 } 353 } 354 355 extern Nlm_Boolean Nlm_StrngEql (Nlm_CharPtr str1, Nlm_CharPtr str2, 356 Nlm_Boolean caseCounts) 357 358 { 359 return (Nlm_Boolean) (Nlm_StrngCmp (str1, str2, caseCounts) == 0); 360 } 361 362 extern Nlm_Int2 Nlm_StrngCmp (Nlm_CharPtr str1, Nlm_CharPtr str2, 363 Nlm_Boolean caseCounts) 364 365 { 366 Nlm_Uint4 count; 367 Nlm_Uint4 i; 368 Nlm_Uint4 len1; 369 Nlm_Uint4 len2; 370 Nlm_Int2 rsult; 371 372 rsult = 0; 373 if (str1 != NULL && str2 != NULL) { 374 len1 = Nlm_StrngLen (str1); 375 len2 = Nlm_StrngLen (str2); 376 if (len1 > len2) { 377 count = len2; 378 } else { 379 count = len1; 380 } 381 i = 0; 382 while (count > 0 && Nlm_Cap (str1 [i], caseCounts) == Nlm_Cap (str2 [i], caseCounts)) { 383 i++; 384 count--; 385 } 386 if (count > 0) { 387 if (Nlm_Cap (str1 [i], caseCounts) > Nlm_Cap (str2 [i], caseCounts)) { 388 rsult = 1; 389 } else { 390 rsult = -1; 391 } 392 } else { 393 if (len1 > len2) { 394 rsult = 1; 395 } else if (len1 < len2) { 396 rsult = -1; 397 } else { 398 rsult = 0; 399 } 400 } 401 } 402 return rsult; 403 } 404 405 extern Nlm_Int2 Nlm_SymblCmp (Nlm_CharPtr str1, Nlm_CharPtr str2, 406 Nlm_Boolean caseCounts) 407 408 { 409 Nlm_Boolean cont; 410 Nlm_Boolean done; 411 Nlm_Uint4 i; 412 Nlm_Uint4 j; 413 Nlm_Uint4 len1; 414 Nlm_Uint4 len2; 415 Nlm_Uint4 num1; 416 Nlm_Uint4 num2; 417 Nlm_Int2 rsult; 418 419 rsult = 0; 420 if (str1 != NULL && str2 != NULL) { 421 done = FALSE; 422 len1 = Nlm_StrngLen (str1); 423 len2 = Nlm_StrngLen (str2); 424 i = 0; 425 j = 0; 426 cont = (Nlm_Boolean) (len1 > 0 && len2 > 0); 427 while (cont) { 428 if (Nlm_InNumber (str1 [i]) && Nlm_InNumber (str2 [j])) { 429 num1 = 0; 430 while (i < len1 && Nlm_InNumber (str1 [i]) && (num1 < 429496729)) { 431 num1 *= 10; 432 num1 += (str1 [i] - '0'); 433 i++; 434 } 435 num2 = 0; 436 while (j < len2 && Nlm_InNumber (str2 [j]) && (num2 < 429496729)) { 437 num2 *= 10; 438 num2 += (str2 [j] - '0'); 439 j++; 440 } 441 if (num1 > num2) { 442 rsult = 1; 443 done = TRUE; 444 cont = FALSE; 445 } else if (num1 < num2) { 446 rsult = -1; 447 done = TRUE; 448 cont = FALSE; 449 } else { 450 cont = (Nlm_Boolean) (i < len1 && j < len2); 451 } 452 } else if (Nlm_Cap (str1 [i], caseCounts) > Nlm_Cap (str2 [j], caseCounts)) { 453 rsult = 1; 454 done = TRUE; 455 cont = FALSE; 456 } else if (Nlm_Cap (str1 [i], caseCounts) < Nlm_Cap (str2 [j], caseCounts)) { 457 rsult = -1; 458 done = TRUE; 459 cont = FALSE; 460 } else { 461 i++; 462 j++; 463 cont = (Nlm_Boolean) (i < len1 && j < len2); 464 } 465 } 466 if (done) { 467 } else if (i < len1 && j == len2) { 468 rsult = 1; 469 } else if (i == len1 && j < len2) { 470 rsult = -1; 471 } else { 472 rsult = 0; 473 } 474 } 475 return rsult; 476 } 477 478 extern Nlm_Handle Nlm_SetString (Nlm_Handle h, Nlm_CharPtr str) 479 480 { 481 size_t len; 482 Nlm_CharPtr pp; 483 484 len = 0; 485 if (str != NULL) { 486 len = Nlm_StringLen (str); 487 if (len > 0) { 488 if (h != NULL) { 489 h = Nlm_HandMore (h, len + 1); 490 } else { 491 h = Nlm_HandNew (len + 1); 492 } 493 } else if (h != NULL) { 494 Nlm_HandFree (h); 495 h = NULL; 496 } 497 } else if (h != NULL) { 498 Nlm_HandFree (h); 499 h = NULL; 500 } 501 if (h != NULL) { 502 pp = (Nlm_CharPtr) Nlm_HandLock (h); 503 if (pp != NULL) { 504 Nlm_StringNCpy (pp, str, len + 1); /* remains StringNCpy, not _0 */ 505 } 506 Nlm_HandUnlock (h); 507 } 508 return h; 509 } 510 511 512 extern void Nlm_GetString (Nlm_Handle h, Nlm_CharPtr str, size_t maxsize) 513 { 514 if (str == NULL || maxsize <= 0) 515 return; 516 517 str[0] = '\0'; 518 519 if (h == NULL) 520 return; 521 522 {{ 523 Nlm_CharPtr pp = (Nlm_CharPtr)Nlm_HandLock( h ); 524 if (pp != NULL) 525 Nlm_StringNCpy_0 (str, pp, maxsize); 526 Nlm_HandUnlock( h ); 527 }} 528 } 529 530 #ifndef WIN_MSWIN 531 static void Nlm_MssgErrorProc (Nlm_ButtoN b) 532 { 533 errorBoxUp = FALSE; 534 errorBoxRsult = ANS_NO; 535 } 536 537 static void Nlm_MssgFatalProc (Nlm_ButtoN b) 538 { 539 errorBoxUp = FALSE; 540 errorBoxRsult = ANS_NO; 541 } 542 543 static void Nlm_MssgNoProc (Nlm_ButtoN b) 544 { 545 errorBoxUp = FALSE; 546 errorBoxRsult = ANS_NO; 547 } 548 549 static void Nlm_MssgYesProc (Nlm_ButtoN b) 550 { 551 errorBoxUp = FALSE; 552 errorBoxRsult = ANS_YES; 553 } 554 555 static void Nlm_MssgOkayProc (Nlm_ButtoN b) 556 { 557 errorBoxUp = FALSE; 558 errorBoxRsult = ANS_OK; 559 } 560 561 static void Nlm_MssgRetryProc (Nlm_ButtoN b) 562 { 563 errorBoxUp = FALSE; 564 errorBoxRsult = ANS_RETRY; 565 } 566 567 static void Nlm_MssgAbortProc (Nlm_ButtoN b) 568 { 569 errorBoxUp = FALSE; 570 errorBoxRsult = ANS_ABORT; 571 } 572 573 static void Nlm_MssgCancelProc (Nlm_ButtoN b) 574 { 575 errorBoxUp = FALSE; 576 errorBoxRsult = ANS_CANCEL; 577 } 578 579 static void Nlm_MssgIgnoreProc (Nlm_ButtoN b) 580 { 581 errorBoxUp = FALSE; 582 errorBoxRsult = ANS_IGNORE; 583 } 584 #endif /* ndef WIN_MSWIN */ 585 586 587 static void s_CloseAWindow(Nlm_WindoW w) 588 { 589 Nlm_Reset((Nlm_TexT) Nlm_GetObjectExtra(w)); 590 Nlm_Hide(w); 591 } 592 593 594 static Nlm_Boolean s_FatalModalWindowUp; 595 static void s_CloseFatalModalWindow_W(Nlm_WindoW w) 596 { 597 s_FatalModalWindowUp = FALSE; 598 } 599 /* 600 static void s_CloseFatalModalWindow_B(Nlm_ButtoN b) 601 { 602 s_CloseFatalModalWindow_W( Nlm_Parent(b) ); 603 } 604 */ 605 606 607 static MsgAnswer LIBCALLBACK Nlm_VibMessageHook (MsgKey key, ErrSev severity, 608 const char * caption, 609 const char * message) 610 { 611 Nlm_Int2 rsult = 0; 612 #if defined(WIN_MAC) || defined(WIN_MOTIF) 613 size_t len; 614 Nlm_CharPtr buf = NULL; 615 Nlm_ButtoN b[3]; 616 Nlm_Char ch; 617 Nlm_Int2 delta; 618 Nlm_GrouP g; 619 Nlm_Int2 i; 620 Nlm_Int2 j; 621 Nlm_Int2 k; 622 Nlm_Int2 margin; 623 Nlm_Int2 maxWidth; 624 Nlm_PoinT npt; 625 Nlm_Int4 percent; 626 Nlm_RecT r; 627 Nlm_WindoW w; 628 Nlm_Int2 width; 629 #endif 630 #ifdef WIN_MSWIN 631 Nlm_Int4 answer; 632 Nlm_Int2 wtype; 633 #endif 634 635 const char* x_caption = caption ? caption : "Message"; 636 637 /* Use a window (or a modal dialog) to accumulate & post the message */ 638 if (key == KEY_NONE || severity >= ErrGetFatalLevel()) { 639 static Nlm_WindoW postWindow = 0; 640 static Nlm_TexT postText = 0; 641 Nlm_WindoW tempPort = Nlm_CurrentWindow(); 642 643 /* Prepare the message text (concat with the previous text, if any) */ 644 char* x_text = NULL; 645 const char* add_mess = message ? message : "<no message posted>"; 646 if ( postText ) { 647 size_t curr_len = Nlm_TextLength(postText); 648 size_t add_len = Nlm_StringLen( message ); 649 if (curr_len < 1000000 && add_len < 1000000) { 650 char* buf = (char*) Nlm_MemNew(add_len+1 + curr_len + 1); 651 Nlm_MemCpy(buf, add_mess, add_len); 652 buf[add_len++] = '\n'; 653 Nlm_GetTitle(postText, buf+add_len, curr_len+1); 654 x_text = Nlm_StrngPrintable(buf); 655 Nlm_MemFree(buf); 656 } else { 657 x_text = Nlm_StrngPrintable ("VibMessageHook allocation failure\n"); 658 } 659 } else { 660 x_text = Nlm_StrngPrintable(add_mess); 661 } 662 663 /* Fatal or non-fatal error severity (modal or non-modal dialog) */ 664 if (severity >= ErrGetFatalLevel()) { 665 /* Fatal error -- use modal dialog window */ 666 Nlm_WindoW modalWindow = Nlm_ModalWindow(-50, -90, -20, -20, 667 s_CloseFatalModalWindow_W); 668 Nlm_TexT modalText = Nlm_ScrollText(modalWindow, 64, 16, 669 Nlm_systemFont, TRUE, NULL); 670 Nlm_SetObjectExtra(modalWindow, modalText, NULL); 671 Nlm_SetTextEditable(modalText, FALSE); 672 Nlm_SetTitle(modalText, x_text); 673 674 /* hide the regular message posting window */ 675 if (postWindow && Nlm_Visible(postWindow)) 676 Nlm_Hide(postWindow); 677 678 /* show the modal dialog */ 679 Nlm_Show(modalWindow); 680 Nlm_PopupParentWindow(modalWindow); 681 s_FatalModalWindowUp = TRUE; 682 Nlm_WaitForCondition(s_FatalModalWindowUp); 683 Nlm_ProcessAnEvent(); 684 Nlm_Remove(modalWindow); 685 } else { 686 /* Non-Fatal error -- use normal window */ 687 if ( !postWindow ) { 688 /* create normal message posting window */ 689 postWindow = Nlm_FixedWindow(-50, -90, -20, -20, (char*)x_caption, 690 s_CloseAWindow); 691 postText = Nlm_ScrollText(postWindow, (Nlm_Int2)32, (Nlm_Int2)5, 692 Nlm_systemFont, TRUE, NULL); 693 Nlm_SetObjectExtra(postWindow, postText, NULL); 694 if ( postText ) 695 Nlm_SetTextEditable(postText, FALSE); 696 } 697 698 /* set the message text and popup the window */ 699 if ( postText ) 700 Nlm_SetTitle(postText, x_text); 701 Nlm_PopupParentWindow( postWindow ); 702 } 703 704 Nlm_MemFree(x_text); 705 Nlm_RestorePort( tempPort ); 706 return (MsgAnswer)ANS_NONE; 707 } 708 709 #ifdef WIN_MSWIN 710 wtype = MB_OK; 711 switch (key) { 712 case KEY_OK: 713 if (severity == SEV_ERROR) { 714 wtype = MB_OK; 715 } else if (severity == SEV_FATAL) { 716 wtype = MB_OK; 717 } else { 718 wtype = MB_OK; 719 } 720 break; 721 case KEY_RC: 722 wtype = MB_RETRYCANCEL; 723 break; 724 case KEY_ARI: 725 wtype = MB_ABORTRETRYIGNORE; 726 break; 727 case KEY_YN: 728 wtype = MB_YESNO; 729 break; 730 case KEY_YNC: 731 wtype = MB_YESNOCANCEL; 732 break; 733 case KEY_OKC: 734 wtype = MB_OKCANCEL; 735 break; 736 case KEY_NONE: 737 wtype = MB_OK; 738 break; 739 default: 740 break; 741 } 742 743 answer = MessageBox(NULL, message, x_caption, wtype | MB_TASKMODAL); 744 switch (answer) { 745 case IDNO: 746 rsult = ANS_NO; 747 break; 748 case IDYES: 749 rsult = ANS_YES; 750 break; 751 case IDOK: 752 rsult = ANS_OK; 753 break; 754 case IDRETRY: 755 rsult = ANS_RETRY; 756 break; 757 case IDABORT: 758 rsult = ANS_ABORT; 759 break; 760 case IDCANCEL: 761 rsult = ANS_CANCEL; 762 break; 763 case IDIGNORE: 764 rsult = ANS_IGNORE; 765 break; 766 default: 767 break; 768 } 769 #endif /* WIN_MSWIN */ 770 771 #if defined(WIN_MOTIF) || defined(WIN_MAC) 772 len = MIN(Nlm_StringLen(message) + 1, 4096); 773 buf = (Nlm_CharPtr) Nlm_MemNew(len); 774 Nlm_StringNCpy_0(buf, message, len); 775 776 percent = (Nlm_Int4)Nlm_GetAppProperty( "VibrantMessageWidthMax" ); 777 if (percent <= 0 || 95 < percent) 778 percent = 95; 779 else if (percent < 25) 780 percent = 25; 781 782 maxWidth = (Nlm_Int2)(percent * 783 (Nlm_screenRect.right - Nlm_screenRect.left) / 100 - 40); 784 maxWidth = MAX (maxWidth, 100); 785 786 w = Nlm_MovableModalWindow (-50, -20, -20, -20, (char*)x_caption, NULL); 787 g = Nlm_HiddenGroup (w, 0, 10, NULL); 788 Nlm_GetNextPosition (g, &npt); 789 npt.x += 6; 790 Nlm_SetNextPosition (g, npt); 791 792 i = 0; 793 while (buf[i] != '\0') { 794 width = 0; 795 j = 0; 796 while (buf [i + j] == ' ') { 797 i++; 798 } 799 ch = buf [i + j]; 800 width += Nlm_CharWidth (ch); 801 while (ch != '\0' && ch != '\n' && ch != '\r' && width <= maxWidth && j < 125) { 802 j++; 803 ch = buf [i + j]; 804 width += Nlm_CharWidth (ch); 805 } 806 if (width > maxWidth) { 807 ch = buf [i + j]; 808 while (j > 0 && ch != ' ' && ch != '-') { 809 j--; 810 ch = buf [i + j]; 811 } 812 } else if (j >= 125) { 813 k = j; 814 ch = buf [i + k]; 815 while (k > 0 && ch != ' ' && ch != '-') { 816 k--; 817 ch = buf [i + k]; 818 } 819 if (k > 80) { 820 j = k; 821 } 822 ch = buf [i + j]; 823 } 824 if (ch == '\n' || ch == '\r') { 825 buf [i + j] = '\0'; 826 Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l'); 827 i += j + 1; 828 } else { 829 buf [i + j] = '\0'; 830 Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l'); 831 buf [i + j] = ch; 832 i += j; 833 } 834 } 835 Nlm_MemFree( buf ); 836 837 Nlm_GetPosition (g, &r); 838 margin = r.right; 839 Nlm_Break ((Nlm_GraphiC) w); 840 b [0] = NULL; 841 b [1] = NULL; 842 b [2] = NULL; 843 switch (key) { 844 case KEY_OK: 845 if (severity == SEV_ERROR) { 846 b [0] = Nlm_DefaultButton (w, "OK", Nlm_MssgErrorProc); 847 } else if (severity == SEV_FATAL) { 848 b [0] = Nlm_DefaultButton (w, "OK", Nlm_MssgFatalProc); 849 } else { 850 b [0] = Nlm_DefaultButton (w, "OK", Nlm_MssgOkayProc); 851 } 852 break; 853 case KEY_RC: 854 b [0] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc); 855 Nlm_Advance ((Nlm_GraphiC) w); 856 b [1] = Nlm_DefaultButton (w, "Cancel", Nlm_MssgCancelProc); 857 break; 858 case KEY_ARI: 859 b [0] = Nlm_PushButton (w, "Abort", Nlm_MssgAbortProc); 860 Nlm_Advance ((Nlm_GraphiC) w); 861 b [1] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc); 862 Nlm_Advance ((Nlm_GraphiC) w); 863 b [2] = Nlm_DefaultButton (w, "Ignore", Nlm_MssgIgnoreProc); 864 break; 865 case KEY_YN: 866 b [0] = Nlm_DefaultButton (w, "Yes", Nlm_MssgYesProc); 867 Nlm_Advance ((Nlm_GraphiC) w); 868 b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc); 869 break; 870 case KEY_YNC: 871 b [0] = Nlm_DefaultButton (w, "Yes", Nlm_MssgYesProc); 872 Nlm_Advance ((Nlm_GraphiC) w); 873 b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc); 874 Nlm_Advance ((Nlm_GraphiC) w); 875 b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc); 876 break; 877 case KEY_OKC: 878 b [1] = Nlm_DefaultButton (w, "OK", Nlm_MssgOkayProc); 879 Nlm_Advance ((Nlm_GraphiC) w); 880 b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc); 881 break; 882 case KEY_NONE: 883 b [0] = Nlm_DefaultButton (w, "OK", Nlm_MssgOkayProc); 884 break; 885 default: 886 b [0] = Nlm_DefaultButton (w, "OK", Nlm_MssgOkayProc); 887 break; 888 } 889 i = 2; 890 while (i >= 0 && b [i] == NULL) { 891 i--; 892 } 893 if (i >= 0) { 894 Nlm_GetPosition (b [i], &r); 895 delta = (margin - r.right) / 2; 896 if (delta > 0) { 897 while (i >= 0) { 898 Nlm_GetPosition (b [i], &r); 899 Nlm_OffsetRect (&r, delta, 0); 900 Nlm_SetPosition (b [i], &r); 901 i--; 902 } 903 } else if (delta < 0) { 904 Nlm_GetPosition (g, &r); 905 Nlm_OffsetRect (&r, -delta, 0); 906 Nlm_SetPosition (g, &r); 907 } 908 } 909 Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE); 910 errorBoxUp = TRUE; 911 errorBoxRsult = 0; 912 913 #ifdef WIN_MAC 914 while (errorBoxUp) { 915 Nlm_ProcessExternalEvent (); 916 Nlm_Update (); 917 } 918 #else /* i.e. WIN_MOTIF */ 919 Nlm_WaitForCondition(errorBoxUp); 920 #endif 921 922 Nlm_ProcessAnEvent (); 923 Nlm_DoRemove ((Nlm_GraphiC) w, TRUE); 924 rsult = errorBoxRsult; 925 #endif /* WIN_MOTIF || WIN_MAC */ 926 927 return (MsgAnswer) rsult; 928 } 929 930 931 typedef struct monitextra { 932 Nlm_WindoW wind; 933 Nlm_PaneL pnl; 934 Nlm_Boolean cancel; 935 } Nlm_VibMonExtra, PNTR Nlm_VibMonPtr; 936 937 static void Nlm_SelectMonitor (Nlm_WindoW w) 938 { 939 Nlm_WindowTool wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w); 940 #ifdef WIN_MAC 941 /* SelectWindow (wptr); */ 942 SetPortWindowPort(wptr); 943 Nlm_SetUpdateRegion (wptr); 944 Nlm_ResetDrawingTools (); 945 #endif 946 #ifdef WIN_MSWIN 947 /* BringWindowToTop (wptr); */ 948 Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) w); 949 Nlm_currentHWnd = wptr; 950 #endif 951 #ifdef WIN_MOTIF 952 /* Nlm_Select ( w ); */ 953 #endif 954 Nlm_currentWindowTool = wptr; 955 } 956 957 static int Nlm_VibMonStrValue (Nlm_MonitorPtr mon) 958 959 { 960 Nlm_VibMonPtr vmp; 961 Nlm_PaneL pnl; 962 Nlm_RecT r; 963 Nlm_WindoW tempPort; 964 Nlm_WindoW wind; 965 #ifdef WIN_MOTIF 966 XEvent event; 967 Nlm_Uint4 tempBackColor; 968 Nlm_Uint4 tempForeColor; 969 Nlm_Int2 tempXOffset; 970 Nlm_Int2 tempYOffset; 971 Window tempXWind; 972 GC tempXGC; 973 #endif 974 975 if (mon == NULL || mon->type != MonType_Str || mon->extra == NULL) { 976 return 0; 977 } 978 vmp = (Nlm_VibMonPtr) mon->extra; 979 pnl = vmp->pnl; 980 wind = vmp->wind; 981 tempPort = Nlm_CurrentWindow (); 982 #ifdef WIN_MOTIF 983 tempXWind = Nlm_currentXWindow; 984 tempXGC = Nlm_currentXGC; 985 tempBackColor = Nlm_XbackColor; 986 tempForeColor = Nlm_XforeColor; 987 tempXOffset = Nlm_XOffset; 988 tempYOffset = Nlm_YOffset; 989 #endif 990 Nlm_UseWindow (wind); 991 Nlm_SelectMonitor (wind); 992 Nlm_Select (pnl); 993 Nlm_GetRect ((Nlm_GraphiC) pnl, &r); 994 Nlm_InsetRect (&r, 2, 2); 995 Nlm_DrawString (&r, (Nlm_CharPtr) mon->strValue, 'l', FALSE); 996 Nlm_UseWindow (tempPort); 997 #ifdef WIN_MOTIF 998 Nlm_currentXWindow = tempXWind; 999 Nlm_currentXGC = tempXGC; 1000 Nlm_XbackColor = tempBackColor; 1001 Nlm_XforeColor = tempForeColor; 1002 Nlm_XOffset = tempXOffset; 1003 Nlm_YOffset = tempYOffset; 1004 #endif 1005 1006 Nlm_Update (); 1007 1008 #if defined(WIN_MAC) || defined(WIN_MSWIN) 1009 while (Nlm_MouseButton ()) { 1010 Nlm_ProcessExternalEvent (); 1011 } 1012 #endif 1013 #ifdef WIN_MOTIF 1014 while (XCheckTypedEvent (Nlm_currentXDisplay, ButtonPress, &event) || 1015 XCheckTypedEvent (Nlm_currentXDisplay, ButtonRelease, &event)) 1016 { 1017 XtDispatchEvent( &event ); 1018 } 1019 #endif 1020 Nlm_ProcessAnEvent (); 1021 1022 mon->cancel = vmp->cancel; 1023 return 0; 1024 } 1025 1026 static int Nlm_VibMonIntValue (Nlm_MonitorPtr mon) 1027 1028 { 1029 Nlm_Int4 from; 1030 Nlm_VibMonPtr vmp; 1031 Nlm_PaneL pnl; 1032 Nlm_RecT r; 1033 Nlm_Int4 range; 1034 Nlm_Int2 right; 1035 Nlm_WindoW tempPort; 1036 Nlm_Int4 to; 1037 Nlm_Int4 value; 1038 Nlm_Int4 width; 1039 Nlm_WindoW wind; 1040 #ifdef WIN_MOTIF 1041 XEvent event; 1042 Nlm_Uint4 tempBackColor; 1043 Nlm_Uint4 tempForeColor; 1044 Nlm_Int2 tempXOffset; 1045 Nlm_Int2 tempYOffset; 1046 Window tempXWind; 1047 GC tempXGC; 1048 #endif 1049 1050 if (mon == NULL || mon->type != MonType_Int || mon->extra == NULL) { 1051 return 0; 1052 } 1053 vmp = (Nlm_VibMonPtr) mon->extra; 1054 from = MIN (mon->num1, mon->num2); 1055 to = MAX (mon->num1, mon->num2); 1056 range = to - from; 1057 value = mon->intValue; 1058 value = MAX (value, from); 1059 value = MIN (value, to); 1060 value -= from; 1061 pnl = vmp->pnl; 1062 wind = vmp->wind; 1063 tempPort = Nlm_CurrentWindow (); 1064 #ifdef WIN_MOTIF 1065 tempXWind = Nlm_currentXWindow; 1066 tempXGC = Nlm_currentXGC; 1067 tempBackColor = Nlm_XbackColor; 1068 tempForeColor = Nlm_XforeColor; 1069 tempXOffset = Nlm_XOffset; 1070 tempYOffset = Nlm_YOffset; 1071 #endif 1072 Nlm_UseWindow (wind); 1073 Nlm_SelectMonitor (wind); 1074 Nlm_Select (pnl); 1075 Nlm_GetRect ((Nlm_GraphiC) pnl, &r); 1076 Nlm_FrameRect (&r); 1077 Nlm_InsetRect (&r, 2, 2); 1078 value = MAX (value, 0); 1079 value = MIN (value, range); 1080 width = (Nlm_Int4) (r.right - r.left); 1081 right = r.right; 1082 r.right = (Nlm_Int2)(r.left + (width * value / range)); 1083 Nlm_Black (); 1084 Nlm_PaintRect (&r); 1085 r.left = r.right; 1086 r.right = right; 1087 Nlm_EraseRect (&r); 1088 Nlm_UseWindow (tempPort); 1089 #ifdef WIN_MOTIF 1090 Nlm_currentXWindow = tempXWind; 1091 Nlm_currentXGC = tempXGC; 1092 Nlm_XbackColor = tempBackColor; 1093 Nlm_XforeColor = tempForeColor; 1094 Nlm_XOffset = tempXOffset; 1095 Nlm_YOffset = tempYOffset; 1096 #endif 1097 1098 Nlm_Update (); 1099 1100 #if defined(WIN_MAC) || defined(WIN_MSWIN) 1101 while (Nlm_MouseButton ()) { 1102 Nlm_ProcessExternalEvent (); 1103 } 1104 #endif 1105 #ifdef WIN_MOTIF 1106 while (XCheckTypedEvent (Nlm_currentXDisplay, ButtonPress, &event) || 1107 XCheckTypedEvent (Nlm_currentXDisplay, ButtonRelease, &event)) 1108 { 1109 XtDispatchEvent( &event ); 1110 } 1111 #endif 1112 Nlm_ProcessAnEvent (); 1113 1114 mon->cancel = vmp->cancel; 1115 return 0; 1116 } 1117 1118 static void Nlm_CancelMonitorProc (Nlm_ButtoN b) 1119 1120 { 1121 Nlm_VibMonPtr vmp; 1122 1123 vmp = (Nlm_VibMonPtr) Nlm_GetObjectExtra (b); 1124 if (vmp != NULL) { 1125 vmp->cancel = TRUE; 1126 } 1127 } 1128 1129 static int Nlm_VibMonCreate (Nlm_MonitorPtr mon) 1130 1131 { 1132 Nlm_ButtoN b; 1133 Nlm_VibMonPtr vmp; 1134 Nlm_PaneL pnl; 1135 Nlm_WindoW wind; 1136 1137 if (mon != NULL) { 1138 vmp = (Nlm_VibMonPtr) Nlm_MemNew (sizeof (Nlm_VibMonExtra)); 1139 mon->extra = (Nlm_VoidPtr) vmp; 1140 if (vmp != NULL) { 1141 wind = Nlm_FixedWindow (-50, -90, -10, -10, (Nlm_CharPtr) mon->strTitle, NULL); 1142 if (mon->type == MonType_Int) { 1143 pnl = Nlm_SimplePanel (wind, 200, 20, NULL); 1144 } else if (mon->type == MonType_Str) { 1145 pnl = Nlm_SimplePanel(wind, (Nlm_Int2)(Nlm_stdCharWidth*mon->num1+6), 1146 (Nlm_Int2)(Nlm_stdLineHeight + 4), NULL); 1147 } else { 1148 pnl = Nlm_SimplePanel (wind, 200, 20, NULL); 1149 } 1150 Nlm_Advance (wind); 1151 b = NULL; 1152 if ((Nlm_Boolean) mon->hasCancelBtn) { 1153 b = Nlm_DefaultButton (wind, "Cancel", Nlm_CancelMonitorProc); 1154 Nlm_SetObjectExtra (b, (Nlm_VoidPtr) vmp, NULL); 1155 } 1156 Nlm_AlignObjects (ALIGN_MIDDLE, (Nlm_HANDLE) pnl, (Nlm_HANDLE) b, NULL); 1157 vmp->wind = wind; 1158 vmp->pnl = pnl; 1159 vmp->cancel = FALSE; 1160 Nlm_Show (wind); 1161 #ifndef WIN_MOTIF 1162 Nlm_Select (wind); 1163 #endif 1164 Nlm_Update (); 1165 } 1166 } 1167 return TRUE; 1168 } 1169 1170 static int Nlm_VibMonDestroy (Nlm_MonitorPtr mon) 1171 1172 { 1173 Nlm_VibMonPtr vmp; 1174 1175 if (mon != NULL) { 1176 vmp = (Nlm_VibMonPtr) mon->extra; 1177 if (vmp != NULL) { 1178 Nlm_Remove (vmp->wind); 1179 Nlm_MemFree (vmp); 1180 } 1181 } 1182 return 0; 1183 } 1184 1185 1186 static int LIBCALLBACK Nlm_VibMonitorHook(Nlm_MonitorPtr mon, MonCode code) 1187 { 1188 switch ( code ) 1189 { 1190 case MonCode_Create: 1191 return Nlm_VibMonCreate( mon ); 1192 case MonCode_Destroy: 1193 return Nlm_VibMonDestroy( mon ); 1194 case MonCode_IntValue: 1195 return Nlm_VibMonIntValue( mon ); 1196 case MonCode_StrValue: 1197 return Nlm_VibMonStrValue( mon ); 1198 } 1199 1200 return 0; 1201 } 1202 1203 static void LIBCALLBACK Nlm_VibBeepHook (void) 1204 1205 { 1206 #ifdef WIN_MAC 1207 SysBeep (60); 1208 #endif 1209 #ifdef WIN_MSWIN 1210 MessageBeep (0); 1211 #endif 1212 #ifdef WIN_MOTIF 1213 if (Nlm_currentXDisplay != NULL) { 1214 XBell (Nlm_currentXDisplay, 0); 1215 } 1216 #endif 1217 } 1218 1219 extern void Nlm_InitVibrantHooks (void) 1220 1221 { 1222 Nlm_SetBeepHook (Nlm_VibBeepHook); 1223 Nlm_SetMonitorHook (Nlm_VibMonitorHook); 1224 Nlm_SetMessageHook (Nlm_VibMessageHook); 1225 } 1226 1227 extern void Nlm_MousePosition (Nlm_PointPtr pt) 1228 1229 { 1230 #ifdef WIN_MAC 1231 Nlm_PointTool ptool; 1232 1233 GetMouse (&ptool); 1234 if (pt != NULL) { 1235 Nlm_PointToolToPoinT (ptool, pt); 1236 } 1237 #endif 1238 #ifdef WIN_MSWIN 1239 Nlm_PointTool ptool; 1240 1241 if (pt != NULL && Nlm_currentHWnd != NULL) { 1242 GetCursorPos (&ptool); 1243 ScreenToClient (Nlm_currentHWnd, &ptool); 1244 Nlm_PointToolToPoinT (ptool, pt); 1245 } 1246 #endif 1247 #ifdef WIN_MOTIF 1248 #endif 1249 } 1250 1251 extern Nlm_Boolean Nlm_MouseButton (void) 1252 1253 { 1254 #ifdef WIN_MAC 1255 return (Button ()); 1256 #endif 1257 #ifdef WIN_MSWIN 1258 return (Nlm_Boolean) ((GetAsyncKeyState (VK_LBUTTON) & 0x8000) != 0); 1259 #endif 1260 #ifdef WIN_MOTIF 1261 return FALSE; 1262 #endif 1263 } 1264 1265 extern Nlm_Int4 Nlm_ComputerTime (void) 1266 1267 { 1268 #ifdef WIN_MAC 1269 return (TickCount ()); 1270 #endif 1271 #ifdef WIN_MSWIN 1272 return (GetCurrentTime ()); 1273 #endif 1274 #ifdef WIN_MOTIF 1275 struct tms buffer; 1276 return (Nlm_Int4) times (&buffer); 1277 #endif 1278 } 1279 1280 1281 extern void Nlm_Version (Nlm_CharPtr vsn, size_t maxsize) 1282 { 1283 Nlm_StringNCpy_0 (vsn, "NCBI VIBRANT Version 2.0 (29 Jan 97)", maxsize); 1284 } 1285 1286 1287 extern void Nlm_Advance (Nlm_Handle a) 1288 1289 { 1290 Nlm_BoxData bdata; 1291 1292 if (a != NULL) { 1293 Nlm_GetBoxData ((Nlm_BoX) a, &bdata); 1294 bdata.nextPoint.y = bdata.topRow; 1295 bdata.nextPoint.x = bdata.nextCol; 1296 Nlm_SetBoxData ((Nlm_BoX) a, &bdata); 1297 } 1298 } 1299 1300 extern void Nlm_Break (Nlm_Handle a) 1301 1302 { 1303 Nlm_BoxData bdata; 1304 1305 if (a != NULL) { 1306 Nlm_GetBoxData ((Nlm_BoX) a, &bdata); 1307 bdata.topRow = (Nlm_Int2)(bdata.limitPoint.y + bdata.ySpacing); 1308 bdata.nextCol = bdata.resetPoint.x; 1309 bdata.nextPoint.y = bdata.topRow; 1310 bdata.nextPoint.x = bdata.nextCol; 1311 Nlm_SetBoxData ((Nlm_BoX) a, &bdata); 1312 } 1313 } 1314 1315 extern void Nlm_RecordRect (Nlm_GraphiC a, Nlm_RectPtr r) 1316 1317 { 1318 Nlm_BoxData bdata; 1319 Nlm_Int2 nc; 1320 Nlm_Int2 nr; 1321 1322 if (a != NULL && r != NULL) { 1323 Nlm_GetBoxData ((Nlm_BoX) a, &bdata); 1324 nr = r->bottom; 1325 if (nr > bdata.limitPoint.y) { 1326 bdata.limitPoint.y = nr; 1327 } 1328 nc = r->right; 1329 if (nc > bdata.limitPoint.x) { 1330 bdata.limitPoint.x = nc; 1331 } 1332 nc = (Nlm_Int2)(r->right + bdata.xSpacing); 1333 if (nc > bdata.nextCol) { 1334 bdata.nextCol = nc; 1335 } 1336 Nlm_SetBoxData ((Nlm_BoX) a, &bdata); 1337 } 1338 } 1339 1340 extern void Nlm_NextPosition (Nlm_GraphiC a, Nlm_RectPtr r) 1341 1342 { 1343 Nlm_BoxData bdata; 1344 1345 if (a != NULL && r != NULL) { 1346 Nlm_GetBoxData ((Nlm_BoX) a, &bdata); 1347 bdata.nextPoint.y = (Nlm_Int2)(r->bottom + bdata.ySpacing); 1348 Nlm_SetBoxData ((Nlm_BoX) a, &bdata); 1349 } 1350 } 1351 1352 extern void Nlm_SetNextPosition (Nlm_Handle a, Nlm_PoinT nps) 1353 1354 { 1355 Nlm_BoxData bdata; 1356 1357 if (a != NULL) { 1358 Nlm_GetBoxData ((Nlm_BoX) a, &bdata); 1359 bdata.nextPoint = nps; 1360 bdata.topRow = nps.y; 1361 Nlm_SetBoxData ((Nlm_BoX) a, &bdata); 1362 } 1363 } 1364 1365 extern void Nlm_GetNextPosition (Nlm_Handle a, Nlm_PointPtr nps) 1366 1367 { 1368 Nlm_BoxData bdata; 1369 1370 if (a != NULL && nps != NULL) { 1371 Nlm_GetBoxData ((Nlm_BoX) a, &bdata); 1372 *nps = bdata.nextPoint; 1373 } 1374 } 1375 1376 extern Nlm_GphPrcsPtr Nlm_GetClassPtr (Nlm_GraphiC a) 1377 1378 { 1379 Nlm_GphPrcsPtr classPtr; 1380 Nlm_GraphicData gdata; 1381 1382 classPtr = NULL; 1383 if (a != NULL) { 1384 Nlm_GetGraphicData (a, &gdata); 1385 classPtr = gdata.classptr; 1386 } 1387 return classPtr; 1388 } 1389 1390 #ifdef WIN_MAC 1391 extern Nlm_Boolean Nlm_DoClick (Nlm_GraphiC a, Nlm_PoinT pt) 1392 1393 { 1394 Nlm_GphPrcsPtr classPtr; 1395 Nlm_Boolean cont; 1396 Nlm_Boolean (*clk) PROTO((Nlm_GraphiC, Nlm_PoinT)); 1397 Nlm_Boolean rsult; 1398 1399 rsult = FALSE; 1400 cont = TRUE; 1401 classPtr = Nlm_GetClassPtr (a); 1402 while (classPtr != NULL && cont) { 1403 clk = classPtr->click; 1404 if (clk != NULL) { 1405 rsult = clk (a, pt); 1406 cont = FALSE; 1407 } else { 1408 classPtr = classPtr->ancestor; 1409 } 1410 } 1411 return rsult; 1412 } 1413 1414 extern Nlm_Boolean Nlm_DoKey (Nlm_GraphiC a, Nlm_Char ch) 1415 1416 { 1417 Nlm_GphPrcsPtr classPtr; 1418 Nlm_Boolean cont; 1419 Nlm_Boolean (*ky) PROTO((Nlm_GraphiC, Nlm_Char)); 1420 Nlm_Boolean rsult; 1421 1422 rsult = FALSE; 1423 cont = TRUE; 1424 classPtr = Nlm_GetClassPtr (a); 1425 while (classPtr != NULL && cont) { 1426 ky = classPtr->key; 1427 if (ky != NULL) { 1428 rsult = ky (a, ch); 1429 cont = FALSE; 1430 } else { 1431 classPtr = classPtr->ancestor; 1432 } 1433 } 1434 return rsult; 1435 } 1436 1437 extern void Nlm_DoDraw (Nlm_GraphiC a) 1438 1439 { 1440 Nlm_GphPrcsPtr classPtr; 1441 Nlm_Boolean cont; 1442 void (*drw) PROTO((Nlm_GraphiC)); 1443 1444 cont = TRUE; 1445 classPtr = Nlm_GetClassPtr (a); 1446 while (classPtr != NULL && cont) { 1447 drw = classPtr->draw; 1448 if (drw != NULL) { 1449 drw (a); 1450 cont = FALSE; 1451 } else { 1452 classPtr = classPtr->ancestor; 1453 } 1454 } 1455 } 1456 1457 extern Nlm_Boolean Nlm_DoIdle (Nlm_GraphiC a, Nlm_PoinT pt) 1458 1459 { 1460 Nlm_GphPrcsPtr classPtr; 1461 Nlm_Boolean cont; 1462 Nlm_Boolean (*idl) PROTO((Nlm_GraphiC, Nlm_PoinT)); 1463 Nlm_Boolean rsult; 1464 1465 rsult = FALSE; 1466 cont = TRUE; 1467 classPtr = Nlm_GetClassPtr (a); 1468 while (classPtr != NULL && cont) { 1469 idl = classPtr->idle; 1470 if (idl != NULL) { 1471 rsult = idl (a, pt); 1472 cont = FALSE; 1473 } else { 1474 classPtr = classPtr->ancestor; 1475 } 1476 } 1477 return rsult; 1478 } 1479 #endif 1480 1481 #ifdef WIN_MSWIN 1482 extern Nlm_Boolean Nlm_DoCommand (Nlm_GraphiC a) 1483 1484 { 1485 Nlm_GphPrcsPtr classPtr; 1486 Nlm_Boolean cont; 1487 Nlm_Boolean (*cmd) PROTO((Nlm_GraphiC)); 1488 Nlm_Boolean rsult; 1489 1490 rsult = FALSE; 1491 cont = TRUE; 1492 classPtr = Nlm_GetClassPtr (a); 1493 while (classPtr != NULL && cont) { 1494 cmd = classPtr->command; 1495 if (cmd != NULL) { 1496 rsult = cmd (a); 1497 cont = FALSE; 1498 } else { 1499 classPtr = classPtr->ancestor; 1500 } 1501 } 1502 return rsult; 1503 } 1504 #endif 1505 1506 #ifdef WIN_MOTIF 1507 extern void Nlm_DoCallback (Nlm_GraphiC a) 1508 1509 { 1510 Nlm_GphPrcsPtr classPtr; 1511 Nlm_Boolean cont; 1512 void (*clb) PROTO((Nlm_GraphiC)); 1513 1514 cont = TRUE; 1515 classPtr = Nlm_GetClassPtr (a); 1516 while (classPtr != NULL && cont) { 1517 clb = classPtr->callback; 1518 if (clb != NULL) { 1519 clb (a); 1520 cont = FALSE; 1521 } else { 1522 classPtr = classPtr->ancestor; 1523 } 1524 } 1525 } 1526 #endif 1527 1528 extern void Nlm_DoShow (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort) 1529 1530 { 1531 Nlm_GphPrcsPtr classPtr; 1532 Nlm_Boolean cont; 1533 void (*shw) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean)); 1534 1535 cont = TRUE; 1536 classPtr = Nlm_GetClassPtr (a); 1537 while (classPtr != NULL && cont) { 1538 shw = classPtr->show; 1539 if (shw != NULL) { 1540 shw (a, setFlag, savePort); 1541 cont = FALSE; 1542 } else { 1543 classPtr = classPtr->ancestor; 1544 } 1545 } 1546 } 1547 1548 extern void Nlm_DoHide (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort) 1549 1550 { 1551 Nlm_GphPrcsPtr classPtr; 1552 Nlm_Boolean cont; 1553 void (*hid) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean)); 1554 1555 cont = TRUE; 1556 classPtr = Nlm_GetClassPtr (a); 1557 while (classPtr != NULL && cont) { 1558 hid = classPtr->hide; 1559 if (hid != NULL) { 1560 hid (a, setFlag, savePort); 1561 cont = FALSE; 1562 } else { 1563 classPtr = classPtr->ancestor; 1564 } 1565 } 1566 } 1567 1568 extern void Nlm_DoEnable (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort) 1569 1570 { 1571 Nlm_GphPrcsPtr classPtr; 1572 Nlm_Boolean cont; 1573 void (*enbl) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean)); 1574 1575 cont = TRUE; 1576 classPtr = Nlm_GetClassPtr (a); 1577 while (classPtr != NULL && cont) { 1578 enbl = classPtr->enable; 1579 if (enbl != NULL) { 1580 enbl (a, setFlag, savePort); 1581 cont = FALSE; 1582 } else { 1583 classPtr = classPtr->ancestor; 1584 } 1585 } 1586 } 1587 1588 extern void Nlm_DoDisable (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort) 1589 1590 { 1591 Nlm_GphPrcsPtr classPtr; 1592 Nlm_Boolean cont; 1593 void (*dsbl) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean)); 1594 1595 cont = TRUE; 1596 classPtr = Nlm_GetClassPtr (a); 1597 while (classPtr != NULL && cont) { 1598 dsbl = classPtr->disable; 1599 if (dsbl != NULL) { 1600 dsbl (a, setFlag, savePort); 1601 cont = FALSE; 1602 } else { 1603 classPtr = classPtr->ancestor; 1604 } 1605 } 1606 } 1607 1608 extern void Nlm_DoActivate (Nlm_GraphiC a, Nlm_Boolean savePort) 1609 1610 { 1611 void (*actvate) PROTO((Nlm_GraphiC, Nlm_Boolean)); 1612 Nlm_Boolean cont; 1613 Nlm_GphPrcsPtr classPtr; 1614 1615 cont = TRUE; 1616 classPtr = Nlm_GetClassPtr (a); 1617 while (classPtr != NULL && cont) { 1618 actvate = classPtr->activate; 1619 if (actvate != NULL) { 1620 actvate (a, savePort); 1621 cont = FALSE; 1622 } else { 1623 classPtr = classPtr->ancestor; 1624 } 1625 } 1626 } 1627 1628 extern void Nlm_DoDeactivate (Nlm_GraphiC a, Nlm_Boolean savePort) 1629 1630 { 1631 Nlm_GphPrcsPtr classPtr; 1632 Nlm_Boolean cont; 1633 void (*deactvate) PROTO((Nlm_GraphiC, Nlm_Boolean)); 1634 1635 cont = TRUE; 1636 classPtr = Nlm_GetClassPtr (a); 1637 while (classPtr != NULL && cont) { 1638 deactvate = classPtr->deactivate; 1639 if (deactvate != NULL) { 1640 deactvate (a, savePort); 1641 cont = FALSE; 1642 } else { 1643 classPtr = classPtr->ancestor; 1644 } 1645 } 1646 } 1647 1648 extern Nlm_Handle Nlm_DoRemove (Nlm_GraphiC a, Nlm_Boolean savePort) 1649 1650 { 1651 Nlm_GphPrcsPtr classPtr; 1652 Nlm_Boolean cont; 1653 void (*rmv) PROTO((Nlm_GraphiC, Nlm_Boolean)); 1654 1655 cont = TRUE; 1656 1657 #if !defined(WIN_MOTIF) || !defined(LESSTIF_VERSION) 1658 /* using LessTif (on Linux), this eventually causes a segfault down the 1659 line when quitting the application - is this really necessary? (thiessen) */ 1660 Nlm_DoHide (a, TRUE, savePort); 1661 #endif 1662 1663 classPtr = Nlm_GetClassPtr (a); 1664 while (classPtr != NULL && cont) { 1665 rmv = classPtr->remove; 1666 if (rmv != NULL) { 1667 rmv (a, savePort); 1668 cont = FALSE; 1669 } else { 1670 classPtr = classPtr->ancestor; 1671 } 1672 recentGraphic = NULL; 1673 recentBox = NULL; 1674 } 1675 return NULL; 1676 } 1677 1678 extern void Nlm_DoReset (Nlm_GraphiC a, Nlm_Boolean savePort) 1679 1680 { 1681 Nlm_GphPrcsPtr classPtr; 1682 Nlm_Boolean cont; 1683 void (*rst) PROTO((Nlm_GraphiC, Nlm_Boolean)); 1684 1685 cont = TRUE; 1686 classPtr = Nlm_GetClassPtr (a); 1687 while (classPtr != NULL && cont) { 1688 rst = classPtr->reset; 1689 if (rst != NULL) { 1690 rst (a, TRUE); 1691 cont = FALSE; 1692 } else { 1693 classPtr = classPtr->ancestor; 1694 } 1695 } 1696 } 1697 1698 extern void Nlm_DoSelect (Nlm_GraphiC a, Nlm_Boolean savePort) 1699 1700 { 1701 Nlm_GphPrcsPtr classPtr; 1702 Nlm_Boolean cont; 1703 void (*sel) PROTO((Nlm_GraphiC, Nlm_Boolean)); 1704 1705 cont = TRUE; 1706 classPtr = Nlm_GetClassPtr (a); 1707 while (classPtr != NULL && cont) { 1708 sel = classPtr->select; 1709 if (sel != NULL) { 1710 sel (a, savePort); 1711 cont = FALSE; 1712 } else { 1713 classPtr = classPtr->ancestor; 1714 } 1715 } 1716 } 1717 1718 extern Nlm_Int2 Nlm_CountItems (Nlm_Handle a) 1719 1720 { 1721 Nlm_GphPrcsPtr classPtr; 1722 Nlm_Boolean cont; 1723 Nlm_Int2 (*cntitm) PROTO((Nlm_GraphiC)); 1724 Nlm_Int2 len; 1725 1726 cont = TRUE; 1727 len = 0; 1728 classPtr = Nlm_GetClassPtr ((Nlm_GraphiC)a); 1729 while (classPtr != NULL && cont) { 1730 cntitm = classPtr->countItems; 1731 if (cntitm != NULL) { 1732 len = cntitm ((Nlm_GraphiC)a); 1733 cont = FALSE; 1734 } else { 1735 classPtr = classPtr->ancestor; 1736 } 1737 } 1738 return len; 1739 } 1740 1741 extern Nlm_GraphiC Nlm_DoLinkIn (Nlm_GraphiC a, Nlm_GraphiC prnt) 1742 1743 { 1744 Nlm_GphPrcsPtr prntClassPtr; 1745 Nlm_Boolean cont; 1746 Nlm_GraphiC (*lnkIn) PROTO((Nlm_GraphiC, Nlm_GraphiC)); 1747 Nlm_GraphiC rsult; 1748 1749 cont = TRUE; 1750 rsult = NULL; 1751 if (a != NULL && prnt != NULL) { 1752 cont = TRUE; 1753 prntClassPtr = Nlm_GetClassPtr (prnt); 1754 while (prntClassPtr != NULL && cont) { 1755 lnkIn = prntClassPtr->linkIn; 1756 if (lnkIn != NULL) { 1757 rsult = lnkIn (a, prnt); 1758 cont = FALSE; 1759 } else { 1760 prntClassPtr = prntClassPtr->ancestor; 1761 } 1762 } 1763 } 1764 return rsult; 1765 } 1766 1767 extern void Nlm_DoAdjustPrnt (Nlm_GraphiC a, Nlm_RectPtr r, 1768 Nlm_Boolean align, Nlm_Boolean savePort) 1769 1770 { 1771 void (*adjst) PROTO((Nlm_GraphiC, Nlm_RectPtr, Nlm_Boolean, Nlm_Boolean)); 1772 Nlm_Boolean cont; 1773 Nlm_GraphiC p; 1774 Nlm_GphPrcsPtr prntClassPtr; 1775 1776 cont = TRUE; 1777 if (a != NULL) { 1778 p = Nlm_GetParent (a); 1779 prntClassPtr = Nlm_GetClassPtr (p); 1780 while (prntClassPtr != NULL && cont) { 1781 adjst = prntClassPtr->adjustPrnt; 1782 if (adjst != NULL) { 1783 adjst (a, r, align, savePort); 1784 cont = FALSE; 1785 } else { 1786 prntClassPtr = prntClassPtr->ancestor; 1787 } 1788 } 1789 } 1790 } 1791 1792 1793 extern void Nlm_DoSetTitle (Nlm_GraphiC a, Nlm_Int2 item, 1794 Nlm_CharPtr title, Nlm_Boolean savePort) 1795 1796 { 1797 Nlm_GphPrcsPtr classPtr; 1798 Nlm_Boolean cont; 1799 void (*stttl) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_CharPtr, Nlm_Boolean)); 1800 1801 cont = TRUE; 1802 classPtr = Nlm_GetClassPtr (a); 1803 while (classPtr != NULL && cont) { 1804 stttl = classPtr->setTitle; 1805 if (stttl != NULL) { 1806 stttl (a, item, title, savePort); 1807 cont = FALSE; 1808 } else { 1809 classPtr = classPtr->ancestor; 1810 } 1811 } 1812 } 1813 1814 extern void Nlm_DoGetTitle (Nlm_GraphiC a, Nlm_Int2 item, 1815 Nlm_CharPtr title, size_t maxsize) 1816 1817 { 1818 Nlm_GphPrcsPtr classPtr; 1819 Nlm_Boolean cont; 1820 Nlm_Boolean failed; 1821 void (*gtttl) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_CharPtr, size_t)); 1822 1823 cont = TRUE; 1824 failed = TRUE; 1825 classPtr = Nlm_GetClassPtr (a); 1826 while (classPtr != NULL && cont) { 1827 gtttl = classPtr->getTitle; 1828 if (gtttl != NULL) { 1829 gtttl (a, item, title, maxsize); 1830 failed = FALSE; 1831 cont = FALSE; 1832 } else { 1833 classPtr = classPtr->ancestor; 1834 } 1835 } 1836 1837 if (failed && maxsize > 0) 1838 title[0] = '\0'; 1839 } 1840 1841 extern void Nlm_DoSetValue (Nlm_GraphiC a, Nlm_Int2 value, Nlm_Boolean savePort) 1842 1843 { 1844 Nlm_GphPrcsPtr classPtr; 1845 Nlm_Boolean cont; 1846 void (*stval) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Boolean)); 1847 1848 cont = TRUE; 1849 classPtr = Nlm_GetClassPtr (a); 1850 while (classPtr != NULL && cont) { 1851 stval = classPtr->setValue; 1852 if (stval != NULL) { 1853 stval (a, value, savePort); 1854 cont = FALSE; 1855 } else { 1856 classPtr = classPtr->ancestor; 1857 } 1858 } 1859 } 1860 1861 extern Nlm_Int2 Nlm_DoGetValue (Nlm_GraphiC a) 1862 1863 { 1864 Nlm_GphPrcsPtr classPtr; 1865 Nlm_Boolean cont; 1866 Nlm_Int2 (*gtval) PROTO((Nlm_GraphiC)); 1867 Nlm_Int2 value; 1868 1869 cont = TRUE; 1870 value = 0; 1871 classPtr = Nlm_GetClassPtr (a); 1872 while (classPtr != NULL && cont) { 1873 gtval = classPtr->getValue; 1874 if (gtval != NULL) { 1875 value = gtval (a); 1876 cont = FALSE; 1877 } else { 1878 classPtr = classPtr->ancestor; 1879 } 1880 } 1881 return value; 1882 } 1883 1884 extern void Nlm_DoSetStatus (Nlm_GraphiC a, Nlm_Int2 item, 1885 Nlm_Boolean status, Nlm_Boolean savePort) 1886 1887 { 1888 Nlm_GphPrcsPtr classPtr; 1889 Nlm_Boolean cont; 1890 void (*ststs) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Boolean, Nlm_Boolean)); 1891 1892 cont = TRUE; 1893 classPtr = Nlm_GetClassPtr (a); 1894 while (classPtr != NULL && cont) { 1895 ststs = classPtr->setStatus; 1896 if (ststs != NULL) { 1897 ststs (a, item, status, savePort); 1898 cont = FALSE; 1899 } else { 1900 classPtr = classPtr->ancestor; 1901 } 1902 } 1903 } 1904 1905 extern Nlm_Boolean Nlm_DoGetStatus (Nlm_GraphiC a, Nlm_Int2 item) 1906 1907 { 1908 Nlm_GphPrcsPtr classPtr; 1909 Nlm_Boolean cont; 1910 Nlm_Boolean (*gtsts) PROTO((Nlm_GraphiC, Nlm_Int2)); 1911 Nlm_Boolean val; 1912 1913 cont = TRUE; 1914 val = FALSE; 1915 classPtr = Nlm_GetClassPtr (a); 1916 while (classPtr != NULL && cont) { 1917 gtsts = classPtr->getStatus; 1918 if (gtsts != NULL) { 1919 val = gtsts (a, item); 1920 cont = FALSE; 1921 } else { 1922 classPtr = classPtr->ancestor; 1923 } 1924 } 1925 return val; 1926 } 1927 1928 extern void Nlm_DoSetOffset (Nlm_GraphiC a, Nlm_Int2 horiz, 1929 Nlm_Int2 vert,Nlm_Boolean savePort) 1930 1931 { 1932 Nlm_GphPrcsPtr classPtr; 1933 Nlm_Boolean cont; 1934 void (*stoff) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Int2, Nlm_Boolean)); 1935 1936 cont = TRUE; 1937 classPtr = Nlm_GetClassPtr (a); 1938 while (classPtr != NULL && cont) { 1939 stoff = classPtr->setOffset; 1940 if (stoff != NULL) { 1941 stoff (a, horiz, vert, savePort); 1942 cont = FALSE; 1943 } else { 1944 classPtr = classPtr->ancestor; 1945 } 1946 } 1947 } 1948 1949 extern void Nlm_DoGetOffset (Nlm_GraphiC a, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert) 1950 1951 { 1952 Nlm_GphPrcsPtr classPtr; 1953 Nlm_Boolean cont; 1954 Nlm_Boolean failed; 1955 void (*gtoff) PROTO((Nlm_GraphiC, Nlm_Int2Ptr, Nlm_Int2Ptr)); 1956 1957 cont = TRUE; 1958 failed = TRUE; 1959 classPtr = Nlm_GetClassPtr (a); 1960 while (classPtr != NULL && cont) { 1961 gtoff = classPtr->getOffset; 1962 if (gtoff != NULL) { 1963 gtoff (a, horiz, vert); 1964 failed = FALSE; 1965 cont = FALSE; 1966 } else { 1967 classPtr = classPtr->ancestor; 1968 } 1969 } 1970 if (failed) { 1971 if (horiz != NULL) { 1972 *horiz = 0; 1973 } 1974 if (vert != NULL) { 1975 *vert = 0; 1976 } 1977 } 1978 } 1979 1980 extern void Nlm_DoSetPosition (Nlm_GraphiC a, Nlm_RectPtr r, Nlm_Boolean savePort, Nlm_Boolean force) 1981 1982 { 1983 Nlm_GphPrcsPtr classPtr; 1984 1985 classPtr = Nlm_GetClassPtr( a ); 1986 while (classPtr != NULL) 1987 { 1988 if ( classPtr->setPosition ) 1989 { 1990 (*classPtr->setPosition)(a, r, savePort, force); 1991 break; 1992 } 1993 else 1994 { 1995 classPtr = classPtr->ancestor; 1996 } 1997 } 1998 } 1999 2000 extern void Nlm_DoGetPosition (Nlm_GraphiC a, Nlm_RectPtr r) 2001 2002 { 2003 Nlm_GphPrcsPtr classPtr; 2004 Nlm_Boolean cont; 2005 Nlm_Boolean failed; 2006 void (*gtpos) PROTO((Nlm_GraphiC, Nlm_RectPtr)); 2007 2008 cont = TRUE; 2009 failed = TRUE; 2010 classPtr = Nlm_GetClassPtr (a); 2011 while (classPtr != NULL && cont) { 2012 gtpos = classPtr->getPosition; 2013 if (gtpos != NULL) { 2014 gtpos (a, r); 2015 failed = FALSE; 2016 cont = FALSE; 2017 } else { 2018 classPtr = classPtr->ancestor; 2019 } 2020 } 2021 if (failed) { 2022 if (r != NULL) { 2023 Nlm_LoadRect (r, 0, 0, 0, 0); 2024 } 2025 } 2026 } 2027 2028 extern void Nlm_DoSetRange (Nlm_GraphiC a, Nlm_Int2 pgUp, 2029 Nlm_Int2 pgDn, Nlm_Int2 max, 2030 Nlm_Boolean savePort) 2031 2032 { 2033 Nlm_GphPrcsPtr classPtr; 2034 Nlm_Boolean cont; 2035 void (*rng) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Int2, Nlm_Int2, Nlm_Boolean)); 2036 2037 2038 cont = TRUE; 2039 classPtr = Nlm_GetClassPtr (a); 2040 while (classPtr != NULL && cont) { 2041 rng = classPtr->setRange; 2042 if (rng != NULL) { 2043 rng (a, pgUp, pgDn, max, savePort); 2044 cont = FALSE; 2045 } else { 2046 classPtr = classPtr->ancestor; 2047 } 2048 } 2049 } 2050 2051 extern Nlm_GraphiC Nlm_DoGainFocus (Nlm_GraphiC a, Nlm_Char ch, Nlm_Boolean savePort) 2052 2053 { 2054 Nlm_GphPrcsPtr classPtr; 2055 Nlm_Boolean cont; 2056 Nlm_GraphiC rsult; 2057 Nlm_GraphiC (*gainFcs) PROTO((Nlm_GraphiC, Nlm_Char, Nlm_Boolean)); 2058 2059 cont = TRUE; 2060 rsult = NULL; 2061 classPtr = Nlm_GetClassPtr (a); 2062 while (classPtr != NULL && cont) { 2063 gainFcs = classPtr->gainFocus; 2064 if (gainFcs != NULL) { 2065 rsult = gainFcs (a, ch, savePort); 2066 cont = FALSE; 2067 } else { 2068 classPtr = classPtr->ancestor; 2069 } 2070 } 2071 return rsult; 2072 } 2073 2074 extern void Nlm_DoLoseFocus (Nlm_GraphiC a, Nlm_GraphiC excpt, Nlm_Boolean savePort) 2075 2076 { 2077 Nlm_GphPrcsPtr classPtr; 2078 Nlm_Boolean cont; 2079 void (*loseFcs) PROTO((Nlm_GraphiC, Nlm_GraphiC, Nlm_Boolean)); 2080 2081 cont = TRUE; 2082 classPtr = Nlm_GetClassPtr (a); 2083 while (classPtr != NULL && cont) { 2084 loseFcs = classPtr->loseFocus; 2085 if (loseFcs != NULL) { 2086 loseFcs (a, excpt, savePort); 2087 cont = FALSE; 2088 } else { 2089 classPtr = classPtr->ancestor; 2090 } 2091 } 2092 } 2093 2094 extern void Nlm_DoSendChar (Nlm_GraphiC a, Nlm_Char ch, Nlm_Boolean savePort) 2095 2096 { 2097 Nlm_GphPrcsPtr classPtr; 2098 Nlm_Boolean cont; 2099 void (*sendCh) PROTO((Nlm_GraphiC, Nlm_Char, Nlm_Boolean)); 2100 2101 cont = TRUE; 2102 classPtr = Nlm_GetClassPtr (a); 2103 while (classPtr != NULL && cont) { 2104 sendCh = classPtr->sendChar; 2105 if (sendCh != NULL) { 2106 sendCh (a, ch, savePort); 2107 cont = FALSE; 2108 } else { 2109 classPtr = classPtr->ancestor; 2110 } 2111 } 2112 } 2113 2114 static Nlm_GraphiC Nlm_CheckThisLevel (Nlm_GraphiC a, Nlm_Char ch) 2115 2116 { 2117 Nlm_GraphiC p; 2118 Nlm_GraphiC q; 2119 Nlm_GraphiC n; 2120 2121 q = NULL; 2122 p = a; 2123 while (p != NULL && q == NULL) { 2124 n = Nlm_GetNext (p); 2125 q = Nlm_DoGainFocus (p, ch, FALSE); 2126 p = n; 2127 } 2128 return q; 2129 } 2130 2131 extern void Nlm_DoSendFocus (Nlm_GraphiC a, Nlm_Char ch) 2132 2133 { 2134 Nlm_GraphiC cur; 2135 Nlm_GraphiC nxt; 2136 Nlm_GraphiC q; 2137 2138 q = NULL; 2139 nxt = (Nlm_GraphiC) a; 2140 while (q == NULL && nxt != NULL) { 2141 cur = nxt; 2142 nxt = Nlm_GetParent (cur); 2143 if (nxt != NULL) { 2144 cur = Nlm_GetNext (cur); 2145 } 2146 q = Nlm_CheckThisLevel (cur, ch); 2147 } 2148 } 2149 2150 extern void Nlm_DoAction (Nlm_GraphiC a) 2151 2152 { 2153 void (*act) PROTO((Nlm_GraphiC)); 2154 Nlm_GraphicData gdata; 2155 2156 if (a != NULL) { 2157 Nlm_GetGraphicData (a, &gdata); 2158 act = gdata.action; 2159 if (act != NULL) { 2160 act (a); 2161 } 2162 } 2163 } 2164 2165 extern void Nlm_Show (Nlm_Handle a) 2166 2167 { 2168 Nlm_DoShow ((Nlm_GraphiC) a, TRUE, TRUE); 2169 } 2170 2171 extern void Nlm_Hide (Nlm_Handle a) 2172 2173 { 2174 Nlm_DoHide ((Nlm_GraphiC) a, TRUE, TRUE); 2175 } 2176 2177 extern void Nlm_Enable (Nlm_Handle a) 2178 2179 { 2180 Nlm_DoEnable ((Nlm_GraphiC) a, TRUE, TRUE); 2181 } 2182 2183 extern void Nlm_Disable (Nlm_Handle a) 2184 2185 { 2186 Nlm_DoDisable ((Nlm_GraphiC) a, TRUE, TRUE); 2187 } 2188 2189 extern Nlm_Handle Nlm_Remove (Nlm_Handle a) 2190 2191 { 2192 return Nlm_DoRemove ((Nlm_GraphiC) a, TRUE); 2193 } 2194 2195 extern void Nlm_Reset (Nlm_Handle a) 2196 2197 { 2198 Nlm_DoReset ((Nlm_GraphiC) a, TRUE); 2199 } 2200 2201 extern void Nlm_Select (Nlm_Handle a) 2202 2203 { 2204 Nlm_DoSelect ((Nlm_GraphiC) a, TRUE); 2205 } 2206 2207 extern void Nlm_SetTitle (Nlm_Handle a, Nlm_CharPtr title) 2208 2209 { 2210 Nlm_DoSetTitle ((Nlm_GraphiC) a, 0, title, TRUE); 2211 } 2212 2213 extern void Nlm_GetTitle (Nlm_Handle a, Nlm_CharPtr title, size_t maxsize) 2214 2215 { 2216 Nlm_DoGetTitle ((Nlm_GraphiC) a, 0, title, maxsize); 2217 } 2218 2219 extern void Nlm_SetValue (Nlm_Handle a, Nlm_Int2 value) 2220 2221 { 2222 Nlm_DoSetValue ((Nlm_GraphiC) a, value, TRUE); 2223 } 2224 2225 extern Nlm_Int2 Nlm_GetValue (Nlm_Handle a) 2226 2227 { 2228 return (Nlm_DoGetValue ((Nlm_GraphiC) a)); 2229 } 2230 2231 extern void Nlm_SetStatus (Nlm_Handle a, Nlm_Boolean status) 2232 2233 { 2234 Nlm_DoSetStatus ((Nlm_GraphiC) a, 0, status, TRUE); 2235 } 2236 2237 extern Nlm_Boolean Nlm_GetStatus (Nlm_Handle a) 2238 2239 { 2240 return (Nlm_DoGetStatus ((Nlm_GraphiC) a, 0)); 2241 } 2242 2243 extern void Nlm_SetOffset (Nlm_Handle a, Nlm_Int2 horiz, Nlm_Int2 vert) 2244 2245 { 2246 Nlm_DoSetOffset ((Nlm_GraphiC) a, horiz, vert, TRUE); 2247 } 2248 2249 extern void Nlm_GetOffset (Nlm_Handle a, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert) 2250 2251 { 2252 Nlm_DoGetOffset ((Nlm_GraphiC) a, horiz, vert); 2253 } 2254 2255 extern void Nlm_SetPosition (Nlm_Handle a, Nlm_RectPtr r) 2256 2257 { 2258 Nlm_DoSetPosition ((Nlm_GraphiC) a, r, TRUE, FALSE); 2259 } 2260 2261 extern void Nlm_GetPosition (Nlm_Handle a, Nlm_RectPtr r) 2262 2263 { 2264 Nlm_DoGetPosition ((Nlm_GraphiC) a, r); 2265 } 2266 2267 extern void Nlm_SetRange (Nlm_Handle a, Nlm_Int2 pgUp, 2268 Nlm_Int2 pgDn, Nlm_Int2 max) 2269 2270 { 2271 Nlm_DoSetRange ((Nlm_GraphiC) a, pgUp, pgDn, max, TRUE); 2272 } 2273 2274 extern void Nlm_AdjustPrnt (Nlm_Handle a, Nlm_RectPtr r, Nlm_Boolean align) 2275 2276 { 2277 Nlm_DoAdjustPrnt ((Nlm_GraphiC) a, r, align, TRUE); 2278 } 2279 2280 extern void Nlm_SetItemTitle (Nlm_Handle a, Nlm_Int2 item, Nlm_CharPtr title) 2281 2282 { 2283 Nlm_DoSetTitle ((Nlm_GraphiC) a, item, title, TRUE); 2284 } 2285 2286 extern void Nlm_GetItemTitle (Nlm_Handle a, Nlm_Int2 item, Nlm_CharPtr title, size_t maxsize) 2287 2288 { 2289 Nlm_DoGetTitle ((Nlm_GraphiC) a, item, title, maxsize); 2290 } 2291 2292 extern void Nlm_SetItemStatus (Nlm_Handle a, Nlm_Int2 item, Nlm_Boolean status) 2293 2294 { 2295 Nlm_DoSetStatus ((Nlm_GraphiC) a, item, status, TRUE); 2296 } 2297 2298 extern Nlm_Boolean Nlm_GetItemStatus (Nlm_Handle a, Nlm_Int2 item) 2299 2300 { 2301 return (Nlm_DoGetStatus ((Nlm_GraphiC) a, item)); 2302 } 2303 2304 extern Nlm_Int2 Nlm_GetNextItem (Nlm_Handle a, Nlm_Int2 prev) 2305 2306 { 2307 Nlm_GphPrcsPtr classPtr; 2308 Nlm_Int2 (*cntitm) PROTO((Nlm_GraphiC)); 2309 Nlm_Int2 count; 2310 Nlm_Boolean (*gtsts) PROTO((Nlm_GraphiC, Nlm_Int2)); 2311 Nlm_Boolean found; 2312 Nlm_Int2 rsult; 2313 2314 rsult = 0; 2315 if (a != NULL && prev >= 0) { 2316 classPtr = Nlm_GetClassPtr ((Nlm_GraphiC) a); 2317 if (classPtr != NULL) { 2318 cntitm = classPtr->countItems; 2319 gtsts = classPtr->getStatus; 2320 if (cntitm != NULL && gtsts != NULL) { 2321 count = cntitm ((Nlm_GraphiC) a); 2322 found = FALSE; 2323 while (prev < count && (! found)) { 2324 prev++; 2325 found = gtsts ((Nlm_GraphiC) a, prev); 2326 } 2327 if (found) { 2328 rsult = prev; 2329 } 2330 } 2331 } 2332 } 2333 return rsult; 2334 } 2335 2336 extern void Nlm_ClearItemsInGroup (Nlm_GraphiC a, Nlm_GraphiC excpt, Nlm_Boolean savePort) 2337 2338 { 2339 Nlm_GraphiC g; 2340 2341 if (a != NULL) { 2342 g = Nlm_GetChild (a); 2343 while (g != NULL) { 2344 if (g != excpt) { 2345 Nlm_DoSetStatus (g, 0, FALSE, savePort); 2346 } 2347 g = Nlm_GetNext (g); 2348 } 2349 } 2350 } 2351 2352 extern Nlm_Int2 Nlm_CountGroupItems (Nlm_GraphiC a) 2353 2354 { 2355 Nlm_GraphiC g; 2356 Nlm_Int2 i; 2357 2358 i = 0; 2359 if (a != NULL) { 2360 g = Nlm_GetChild (a); 2361 while (g != NULL) { 2362 i++; 2363 g = Nlm_GetNext (g); 2364 } 2365 } 2366 return i; 2367 } 2368 2369 extern Nlm_GraphiC Nlm_LinkIn (Nlm_GraphiC a, Nlm_GraphiC prnt) 2370 2371 { 2372 Nlm_GraphiC first; 2373 Nlm_GraphiC g; 2374 Nlm_GphPtr gp; 2375 Nlm_GraphiC last; 2376 Nlm_GphPtr lastp; 2377 Nlm_GraphiC p; 2378 Nlm_GphPtr prntp; 2379 2380 if (prnt != NULL) { 2381 g = (Nlm_GraphiC) a; 2382 prntp = (Nlm_GphPtr) Nlm_HandLock (prnt); 2383 first = prntp->children; 2384 last = prntp->lastChild; 2385 Nlm_HandUnlock (prnt); 2386 if (last != NULL) { 2387 lastp = (Nlm_GphPtr) Nlm_HandLock (last); 2388 lastp->next = g; 2389 Nlm_HandUnlock (last); 2390 prntp = (Nlm_GphPtr) Nlm_HandLock (prnt); 2391 prntp->lastChild = g; 2392 Nlm_HandUnlock (prnt); 2393 } else if (first != NULL) { 2394 p = first; 2395 while (p != NULL) { 2396 last = p; 2397 p = Nlm_GetNext (p); 2398 } 2399 lastp = (Nlm_GphPtr) Nlm_HandLock (last); 2400 lastp->next = g; 2401 Nlm_HandUnlock (last); 2402 prntp = (Nlm_GphPtr) Nlm_HandLock (prnt); 2403 prntp->lastChild = g; 2404 Nlm_HandUnlock (prnt); 2405 } else { 2406 prntp = (Nlm_GphPtr) Nlm_HandLock (prnt); 2407 prntp->children = g; 2408 prntp->lastChild = g; 2409 Nlm_HandUnlock (prnt); 2410 } 2411 gp = (Nlm_GphPtr) Nlm_HandLock (g); 2412 gp->next = NULL; 2413 gp->parent = prnt; 2414 gp->children = NULL; 2415 gp->lastChild = NULL; 2416 Nlm_HandUnlock (g); 2417 } 2418 recentGraphic = NULL; 2419 recentBox = NULL; 2420 return a; 2421 } 2422 2423 extern void Nlm_LoadAction (Nlm_GraphiC a, Nlm_ActnProc actnProc) 2424 2425 { 2426 Nlm_GraphicData gdata; 2427 2428 if (a != NULL) { 2429 Nlm_GetGraphicData (a, &gdata); 2430 gdata.action = actnProc; 2431 Nlm_SetGraphicData (a, &gdata); 2432 } 2433 } 2434 2435 extern void Nlm_LoadGraphicData (Nlm_GraphiC a, Nlm_GraphiC nxt, 2436 Nlm_GraphiC prnt, Nlm_GraphiC chld, 2437 Nlm_GraphiC lstchd, Nlm_GphPrcs PNTR classPtr, 2438 Nlm_ActnProc actnProc, Nlm_RectPtr r, 2439 Nlm_Boolean enabl, Nlm_Boolean vis, 2440 Nlm_VoidPtr dat, Nlm_FreeProc cln) 2441 { 2442 Nlm_GphPtr ptr; 2443 2444 if (a != NULL) { 2445 ptr = (Nlm_GphPtr) Nlm_HandLock (a); 2446 ptr->next = nxt; 2447 ptr->parent = prnt; 2448 ptr->children = chld; 2449 ptr->lastChild = lstchd; 2450 ptr->classptr = classPtr; 2451 ptr->action = actnProc; 2452 if (r != NULL) { 2453 ptr->rect = *r; 2454 } else { 2455 Nlm_LoadRect (&(ptr->rect), 0, 0, 0, 0); 2456 } 2457 ptr->enabled = enabl; 2458 ptr->visible = vis; 2459 ptr->data = dat; 2460 ptr->cleanup = cln; 2461 ptr->realized = (Nlm_Boolean)(prnt ? Nlm_GetRealized(prnt) : FALSE); 2462 Nlm_HandUnlock (a); 2463 recentGraphic = NULL; 2464 } 2465 } 2466 2467 extern void Nlm_LoadBoxData (Nlm_BoX a, Nlm_PoinT nxt, 2468 Nlm_PoinT lmt, Nlm_PoinT rst, 2469 Nlm_Int2 top, Nlm_Int2 ncol, 2470 Nlm_Int2 xMrg, Nlm_Int2 yMrg, 2471 Nlm_Int2 xSpc, Nlm_Int2 ySpc, 2472 Nlm_Int2 wid, Nlm_Int2 hgt) 2473 2474 { 2475 Nlm_BoxPtr bp; 2476 Nlm_BoxData PNTR bptr; 2477 2478 if (a != NULL) { 2479 bp = (Nlm_BoxPtr) Nlm_HandLock (a); 2480 bptr = &(bp->box); 2481 bptr->nextPoint = nxt; 2482 bptr->limitPoint = lmt; 2483 bptr->resetPoint = rst; 2484 bptr->topRow = top; 2485 bptr->nextCol = ncol; 2486 bptr->xMargin = xMrg; 2487 bptr->yMargin = yMrg; 2488 bptr->xSpacing = xSpc; 2489 bptr->ySpacing = ySpc; 2490 bptr->boxWidth = wid; 2491 bptr->boxHeight = hgt; 2492 Nlm_HandUnlock (a); 2493 recentBox = NULL; 2494 } 2495 } 2496 2497 extern void Nlm_SetAction (Nlm_Handle a, Nlm_ActnProc actn) 2498 2499 { 2500 Nlm_GraphiC g; 2501 Nlm_GraphicData gdata; 2502 2503 if (a != NULL) { 2504 g = (Nlm_GraphiC) a; 2505 if (g != NULL) { 2506 Nlm_GetGraphicData (g, &gdata); 2507 gdata.action = actn; 2508 Nlm_SetGraphicData (g, &gdata); 2509 } 2510 } 2511 } 2512 2513 extern Nlm_GraphiC Nlm_CreateLink (Nlm_GraphiC prnt, Nlm_RectPtr r, 2514 Nlm_Int2 recordSize, Nlm_GphPrcs PNTR classPtr) 2515 2516 { 2517 Nlm_GraphiC a; 2518 Nlm_GraphiC rsult; 2519 2520 rsult = NULL; 2521 a = NULL; 2522 if (prnt != NULL) { 2523 a = (Nlm_GraphiC) Nlm_HandNew (recordSize); 2524 if (a != NULL) { 2525 Nlm_LoadGraphicData (a, NULL, prnt, NULL, NULL, classPtr, 2526 NULL, r, TRUE, FALSE, NULL, NULL); 2527 rsult = Nlm_DoLinkIn (a, prnt); 2528 if (rsult != NULL) { 2529 if (Nlm_nextIdNumber < 32767) { 2530 Nlm_nextIdNumber++; 2531 } 2532 } else { 2533 Nlm_HandFree (a); 2534 } 2535 } 2536 } 2537 return rsult; 2538 } 2539 2540 extern void Nlm_RemoveLink (Nlm_GraphiC g) 2541 2542 { 2543 Nlm_GraphiC prev; 2544 Nlm_GraphicData gdata; 2545 Nlm_GraphiC prnt; 2546 Nlm_GphPtr prntp; 2547 2548 if (g == NULL) 2549 return; 2550 2551 /* exclude from the parent's children list */ 2552 prnt = Nlm_GetParent( g ); 2553 prntp = (Nlm_GphPtr)Nlm_HandLock( prnt ); 2554 prev = Nlm_GetChild( prnt ); 2555 if (g == prev) 2556 { 2557 prntp->children = Nlm_GetNext( g ); 2558 if (prntp->lastChild == g) 2559 { 2560 ASSERT ( prntp->children == NULL ); 2561 prntp->lastChild = NULL; 2562 } 2563 } 2564 else if (prev != NULL) 2565 { 2566 Nlm_GraphiC next = Nlm_GetNext( prev ); 2567 while (next != NULL && next != g) 2568 { 2569 prev = next; 2570 next = Nlm_GetNext( prev ); 2571 } 2572 if (next == g) 2573 { 2574 Nlm_GphPtr prev_ptr; 2575 next = Nlm_GetNext( g ); 2576 prev_ptr = (Nlm_GphPtr)Nlm_HandLock( prev ); 2577 prev_ptr->next = next; 2578 Nlm_HandUnlock( prev ); 2579 if (prntp->lastChild == g) 2580 { 2581 ASSERT ( prev != NULL && prev_ptr->next == NULL ); 2582 prntp->lastChild = prev; 2583 } 2584 } 2585 } 2586 Nlm_HandUnlock( prnt ); 2587 2588 /* call cleanup procedure; then dispose the object */ 2589 Nlm_GetGraphicData(g, &gdata); 2590 if (gdata.data != NULL && gdata.cleanup != NULL) 2591 gdata.cleanup((Nlm_GraphiC)g, gdata.data); 2592 Nlm_HandFree( g ); 2593 2594 recentGraphic = NULL; 2595 recentBox = NULL; 2596 } 2597 2598 extern Nlm_GraphiC Nlm_FindItem (Nlm_GraphiC a, Nlm_Int2 item) 2599 2600 { 2601 Nlm_GraphiC g; 2602 2603 g = NULL; 2604 if (a != NULL && item > 0) { 2605 g = Nlm_GetChild (a); 2606 while (g != NULL && item > 1) { 2607 item--; 2608 g = Nlm_GetNext (g); 2609 } 2610 } 2611 return g; 2612 } 2613 2614 extern Nlm_Int2 Nlm_GetItemIndex (Nlm_GraphiC a) 2615 2616 { 2617 Nlm_GraphiC g; 2618 Nlm_Int2 index; 2619 Nlm_Int2 rsult; 2620 2621 rsult = 0; 2622 if (a != NULL) { 2623 index = 1; 2624 g = Nlm_GetChild (a); 2625 while (g != NULL && g != a) { 2626 index++; 2627 g = Nlm_GetNext (g); 2628 } 2629 if (g == a) { 2630 rsult = index; 2631 } else { 2632 rsult = 0; 2633 } 2634 } 2635 return rsult; 2636 } 2637 2638 extern Nlm_Boolean Nlm_GetAllParentsEnabled (Nlm_GraphiC a) 2639 2640 { 2641 Nlm_GraphiC p; 2642 2643 p = NULL; 2644 if (a != NULL) { 2645 p = Nlm_GetParent (a); 2646 while (p != NULL && Nlm_GetEnabled (p)) { 2647 p = Nlm_GetParent (p); 2648 } 2649 } 2650 return (Nlm_Boolean) (p == NULL); 2651 } 2652 2653 extern Nlm_Boolean Nlm_AllParentsEnabled (Nlm_Handle a) 2654 2655 { 2656 return Nlm_GetAllParentsEnabled ((Nlm_GraphiC) a); 2657 } 2658 2659 extern Nlm_Boolean Nlm_AllParentsButWindowVisible (Nlm_GraphiC a) 2660 2661 { 2662 Nlm_GraphiC p; 2663 2664 p = NULL; 2665 if (a != NULL) { 2666 p = Nlm_GetParent (a); 2667 while (p != NULL && Nlm_GetVisible (p)) { 2668 p = Nlm_GetParent (p); 2669 } 2670 } 2671 return (Nlm_Boolean) (p == NULL || Nlm_GetParent (p) == NULL); 2672 } 2673 2674 extern Nlm_Boolean Nlm_GetAllParentsVisible (Nlm_GraphiC a) 2675 2676 { 2677 Nlm_GraphiC p; 2678 2679 p = NULL; 2680 if (a != NULL) { 2681 p = Nlm_GetParent (a); 2682 while (p != NULL && Nlm_GetVisible (p)) { 2683 p = Nlm_GetParent (p); 2684 } 2685 } 2686 return (Nlm_Boolean) (p == NULL); 2687 } 2688 2689 extern Nlm_Boolean Nlm_AllParentsVisible (Nlm_Handle a) 2690 2691 { 2692 return Nlm_GetAllParentsVisible ((Nlm_GraphiC) a); 2693 } 2694 2695 extern void Nlm_SetNext (Nlm_GraphiC a, Nlm_GraphiC nxt) 2696 2697 { 2698 Nlm_GraphicData gdata; 2699 2700 if (a != NULL) { 2701 Nlm_GetGraphicData (a, &gdata); 2702 gdata.next = nxt; 2703 Nlm_SetGraphicData (a, &gdata); 2704 } 2705 } 2706 2707 extern Nlm_GraphiC Nlm_GetNext (Nlm_GraphiC a) 2708 2709 { 2710 Nlm_GraphicData gdata; 2711 Nlm_GraphiC rsult; 2712 2713 rsult = NULL; 2714 if (a != NULL) { 2715 Nlm_GetGraphicData (a, &gdata); 2716 rsult = gdata.next; 2717 } 2718 return rsult; 2719 } 2720 2721 extern void Nlm_SetParent (Nlm_GraphiC a, Nlm_GraphiC prnt) 2722 2723 { 2724 Nlm_GraphicData gdata; 2725 2726 if (a != NULL) { 2727 Nlm_GetGraphicData (a, &gdata); 2728 gdata.parent = prnt; 2729 Nlm_SetGraphicData (a, &gdata); 2730 } 2731 } 2732 2733 extern Nlm_GraphiC Nlm_GetParent (Nlm_GraphiC a) 2734 2735 { 2736 Nlm_GraphicData gdata; 2737 Nlm_GraphiC rsult; 2738 2739 rsult = NULL; 2740 if (a != NULL) { 2741 Nlm_GetGraphicData (a, &gdata); 2742 rsult = gdata.parent; 2743 } 2744 return rsult; 2745 } 2746 2747 extern Nlm_Handle Nlm_Parent (Nlm_Handle a) 2748 2749 { 2750 return Nlm_GetParent ((Nlm_GraphiC) a); 2751 } 2752 2753 extern void Nlm_SetChild (Nlm_GraphiC a, Nlm_GraphiC chld) 2754 2755 { 2756 Nlm_GraphicData gdata; 2757 2758 if (a != NULL) { 2759 Nlm_GetGraphicData (a, &gdata); 2760 gdata.children = chld; 2761 Nlm_SetGraphicData (a, &gdata); 2762 } 2763 } 2764 2765 extern Nlm_GraphiC Nlm_GetChild (Nlm_GraphiC a) 2766 2767 { 2768 Nlm_GraphicData gdata; 2769 Nlm_GraphiC rsult; 2770 2771 rsult = NULL; 2772 if (a != NULL) { 2773 Nlm_GetGraphicData (a, &gdata); 2774 rsult = gdata.children; 2775 } 2776 return rsult; 2777 } 2778 2779 extern void Nlm_SetRect (Nlm_GraphiC a, Nlm_RectPtr r) 2780 2781 { 2782 Nlm_GraphicData gdata; 2783 2784 if (a != NULL && r != NULL) { 2785 Nlm_GetGraphicData (a, &gdata); 2786 gdata.rect = *r; 2787 Nlm_SetGraphicData (a, &gdata); 2788 } 2789 } 2790 2791 extern void Nlm_GetRect (Nlm_GraphiC a, Nlm_RectPtr r) 2792 2793 { 2794 Nlm_GraphicData gdata; 2795 2796 if (a != NULL && r != NULL) { 2797 Nlm_GetGraphicData (a, &gdata); 2798 *r = gdata.rect; 2799 } 2800 } 2801 2802 extern void Nlm_ObjectRect (Nlm_Handle a, Nlm_RectPtr r) 2803 2804 { 2805 Nlm_GetRect ((Nlm_GraphiC) a, r); 2806 } 2807 2808 extern void Nlm_InvalObject (Nlm_Handle a) 2809 2810 { 2811 Nlm_RecT r; 2812 Nlm_WindoW tempPort; /* M.I */ 2813 2814 if (a != NULL) { 2815 tempPort = Nlm_CurrentWindow (); /* M.I */ 2816 Nlm_GetRect ((Nlm_GraphiC) a, &r); 2817 Nlm_InsetRect (&r, -1, -1); 2818 Nlm_UseWindow( Nlm_ParentWindow( a ) ); /* M.I */ 2819 Nlm_InvalRect (&r); 2820 Nlm_RestorePort (tempPort); /* M.I */ 2821 } 2822 } 2823 2824 extern void Nlm_SetEnabled (Nlm_GraphiC a, Nlm_Boolean enabld) 2825 2826 { 2827 Nlm_GraphicData gdata; 2828 2829 if (a != NULL) { 2830 Nlm_GetGraphicData (a, &gdata); 2831 gdata.enabled = enabld; 2832 Nlm_SetGraphicData (a, &gdata); 2833 } 2834 } 2835 2836 extern Nlm_Boolean Nlm_GetEnabled (Nlm_GraphiC a) 2837 2838 { 2839 Nlm_GraphicData gdata; 2840 Nlm_Boolean rsult; 2841 2842 rsult = FALSE; 2843 if (a != NULL) { 2844 Nlm_GetGraphicData (a, &gdata); 2845 rsult = gdata.enabled; 2846 } 2847 return rsult; 2848 } 2849 2850 extern Nlm_Boolean Nlm_Enabled (Nlm_Handle a) 2851 2852 { 2853 return Nlm_GetEnabled ((Nlm_GraphiC) a); 2854 } 2855 2856 extern void Nlm_SetVisible (Nlm_GraphiC a, Nlm_Boolean visibl) 2857 2858 { 2859 Nlm_GraphicData gdata; 2860 2861 if (a != NULL) { 2862 Nlm_GetGraphicData (a, &gdata); 2863 gdata.visible = visibl; 2864 Nlm_SetGraphicData (a, &gdata); 2865 } 2866 } 2867 2868 extern Nlm_Boolean Nlm_GetVisible (Nlm_GraphiC a) 2869 2870 { 2871 Nlm_GraphicData gdata; 2872 Nlm_Boolean rsult; 2873 2874 rsult = FALSE; 2875 if (a != NULL) { 2876 Nlm_GetGraphicData (a, &gdata); 2877 rsult = gdata.visible; 2878 } 2879 return rsult; 2880 } 2881 2882 extern Nlm_Boolean Nlm_Visible (Nlm_Handle a) 2883 2884 { 2885 return Nlm_GetVisible ((Nlm_GraphiC) a); 2886 } 2887 2888 extern void Nlm_SetObjectExtra (Nlm_Handle a, Nlm_VoidPtr data, Nlm_FreeProc cleanup) 2889 2890 { 2891 Nlm_GraphicData gdata; 2892 2893 if (a != NULL) { 2894 Nlm_GetGraphicData ((Nlm_GraphiC) a, &gdata); 2895 gdata.data = data; 2896 gdata.cleanup = cleanup; 2897 Nlm_SetGraphicData ((Nlm_GraphiC) a, &gdata); 2898 } 2899 } 2900 2901 extern Nlm_VoidPtr Nlm_GetObjectExtra (Nlm_Handle a) 2902 2903 { 2904 Nlm_GraphicData gdata; 2905 2906 if (a != NULL) { 2907 Nlm_GetGraphicData ((Nlm_GraphiC) a, &gdata); 2908 return gdata.data; 2909 } else { 2910 return NULL; 2911 } 2912 } 2913 2914 extern void Nlm_SetGraphicData (Nlm_GraphiC a, Nlm_GraphicData PNTR gdata) 2915 2916 { 2917 Nlm_GphPtr gp; 2918 2919 if (a != NULL && gdata != NULL) { 2920 gp = (Nlm_GphPtr) Nlm_HandLock (a); 2921 *gp = *gdata; 2922 Nlm_HandUnlock (a); 2923 recentGraphic = a; 2924 recentGraphicData = *gdata; 2925 } 2926 } 2927 2928 extern void Nlm_GetGraphicData (Nlm_GraphiC a, Nlm_GraphicData PNTR gdata) 2929 2930 { 2931 Nlm_GphPtr gp; 2932 2933 if (a != NULL && gdata != NULL) { 2934 if (a == recentGraphic && NLM_RISKY) { 2935 *gdata = recentGraphicData; 2936 } else { 2937 gp = (Nlm_GphPtr) Nlm_HandLock (a); 2938 *gdata = *gp; 2939 Nlm_HandUnlock (a); 2940 recentGraphic = a; 2941 recentGraphicData = *gdata; 2942 } 2943 } 2944 } 2945 2946 extern void Nlm_SetBoxData (Nlm_BoX a, Nlm_BoxData PNTR bdata) 2947 2948 { 2949 Nlm_BoxPtr bp; 2950 2951 if (a != NULL && bdata != NULL) { 2952 bp = (Nlm_BoxPtr) Nlm_HandLock (a); 2953 bp->box = *bdata; 2954 Nlm_HandUnlock (a); 2955 recentBox = a; 2956 recentBoxData = *bdata; 2957 } 2958 } 2959 2960 extern void Nlm_GetBoxData (Nlm_BoX a, Nlm_BoxData PNTR bdata) 2961 2962 { 2963 Nlm_BoxPtr bp; 2964 2965 if (a != NULL && bdata != NULL) { 2966 if (a == recentBox && NLM_RISKY) { 2967 *bdata = recentBoxData; 2968 } else { 2969 bp = (Nlm_BoxPtr) Nlm_HandLock (a); 2970 *bdata = bp->box; 2971 Nlm_HandUnlock (a); 2972 recentBox = a; 2973 recentBoxData = *bdata; 2974 } 2975 } 2976 } 2977 2978 extern void Nlm_SetExtraData (Nlm_GraphiC a, Nlm_VoidPtr dptr, 2979 Nlm_Int2 start, Nlm_Int2 extra) 2980 2981 { 2982 Nlm_BytePtr dst; 2983 Nlm_GphPtr gp; 2984 Nlm_BytePtr src; 2985 2986 if (a != NULL && dptr != NULL) { 2987 gp = (Nlm_GphPtr) Nlm_HandLock (a); 2988 dst = (Nlm_BytePtr) gp + start; 2989 src = (Nlm_BytePtr) dptr; 2990 while (extra > 0) { 2991 *dst = *src; 2992 dst++; 2993 src++; 2994 extra--; 2995 } 2996 Nlm_HandUnlock (a); 2997 } 2998 } 2999 3000 extern void Nlm_GetExtraData (Nlm_GraphiC a, Nlm_VoidPtr dptr, 3001 Nlm_Int2 start, Nlm_Int2 extra) 3002 3003 { 3004 Nlm_BytePtr dst; 3005 Nlm_GphPtr gp; 3006 Nlm_BytePtr src; 3007 3008 if (a != NULL && dptr != NULL) { 3009 gp = (Nlm_GphPtr) Nlm_HandLock (a); 3010 src = (Nlm_BytePtr) gp + start; 3011 dst = (Nlm_BytePtr) dptr; 3012 while (extra > 0) { 3013 *dst = *src; 3014 dst++; 3015 src++; 3016 extra--; 3017 } 3018 Nlm_HandUnlock (a); 3019 } 3020 } 3021 3022 extern void Nlm_PointToolToPoinT (Nlm_PointTool src, Nlm_PointPtr dst) 3023 3024 { 3025 if (dst != NULL) { 3026 #ifdef WIN_MAC 3027 dst->x = src.h; 3028 dst->y = src.v; 3029 #endif 3030 #ifdef WIN_MSWIN 3031 dst->x = (Nlm_Int2) src.x; 3032 dst->y = (Nlm_Int2) src.y; 3033 #endif 3034 #ifdef WIN_MOTIF 3035 dst->x = src.x; 3036 dst->y = src.y; 3037 #endif 3038 } 3039 } 3040 3041 extern void Nlm_PoinTToPointTool (Nlm_PoinT src, Nlm_PointTool PNTR dst) 3042 3043 { 3044 if (dst != NULL) { 3045 #ifdef WIN_MAC 3046 dst->h = src.x; 3047 dst->v = src.y; 3048 #endif 3049 #ifdef WIN_MSWIN 3050 dst->x = src.x; 3051 dst->y = src.y; 3052 #endif 3053 #ifdef WIN_MOTIF 3054 dst->x = src.x; 3055 dst->y = src.y; 3056 #endif 3057 } 3058 } 3059 3060 extern void Nlm_RectToolToRecT (Nlm_RectTool PNTR src, Nlm_RectPtr dst) 3061 3062 { 3063 if (dst != NULL && src != NULL) { 3064 #ifdef WIN_MAC 3065 dst->left = src->left; 3066 dst->top = src->top; 3067 dst->right = src->right; 3068 dst->bottom = src->bottom; 3069 #endif 3070 #ifdef WIN_MSWIN 3071 dst->left = (Nlm_Int2) src->left; 3072 dst->top = (Nlm_Int2) src->top; 3073 dst->right = (Nlm_Int2) src->right; 3074 dst->bottom = (Nlm_Int2) src->bottom; 3075 #endif 3076 #ifdef WIN_MOTIF 3077 dst->left = src->x; 3078 dst->top = src->y; 3079 dst->right = src->x + src->width; 3080 dst->bottom = src->y + src->height; 3081 #endif 3082 } 3083 } 3084 3085 extern void Nlm_RecTToRectTool (Nlm_RectPtr src, Nlm_RectTool PNTR dst) 3086 3087 { 3088 if (dst != NULL && src != NULL) { 3089 #ifdef WIN_MAC 3090 dst->left = MIN (src->left, src->right); 3091 dst->top = MIN (src->top, src->bottom); 3092 dst->right = MAX (src->left, src->right); 3093 dst->bottom = MAX (src->top, src->bottom); 3094 #endif 3095 #ifdef WIN_MSWIN 3096 dst->left = MIN (src->left, src->right); 3097 dst->top = MIN (src->top, src->bottom); 3098 dst->right = MAX (src->left, src->right); 3099 dst->bottom = MAX (src->top, src->bottom); 3100 #endif 3101 #ifdef WIN_MOTIF 3102 dst->x = MIN (src->left, src->right); 3103 dst->y = MIN (src->top, src->bottom); 3104 dst->width = ABS (src->right - src->left); 3105 dst->height = ABS (src->bottom - src->top); 3106 #endif 3107 } 3108 } 3109 3110 #ifdef WIN_MAC_QUARTZ 3111 extern CGRect Nlm_RecTToCGRect(Nlm_RecT r) 3112 { 3113 CGRect cgr; 3114 3115 cgr.origin.x = r.left; 3116 cgr.origin.y = r.top; 3117 cgr.size.width = r.right - r.left; 3118 cgr.size.height = r.bottom - r.top; 3119 3120 return cgr; 3121 } 3122 3123 extern Nlm_RecT Nlm_CGRectToRecT(CGRect cgr) 3124 { 3125 Nlm_RecT r; 3126 r.left = cgr.origin.x; 3127 r.top = cgr.origin.y; 3128 r.right = cgr.size.width + cgr.origin.x; 3129 r.bottom = cgr.size.height + cgr.origin.y; 3130 return r; 3131 } 3132 3133 CGRect Nlm_RectQDToCG(Rect r) 3134 { 3135 Nlm_RecT rt; 3136 Nlm_RectToolToRecT (&r, &rt); 3137 return Nlm_RecTToCGRect (rt); 3138 } 3139 3140 Rect Nlm_RectCGToQD(CGRect r) 3141 { 3142 Nlm_RecT rt = Nlm_CGRectToRecT (r); 3143 Rect rq; 3144 Nlm_RecTToRectTool (&rt, &rq); 3145 return rq; 3146 } 3147 3148 extern CGPoint Nlm_PoinTToCGPoint(Nlm_PoinT np) 3149 { 3150 CGPoint qp; 3151 qp.x = (float) np.x; 3152 qp.y = (float) np.y; 3153 return qp; 3154 } 3155 3156 extern Nlm_PoinT Nlm_CGPointToPoinT(CGPoint qp) 3157 { 3158 Nlm_PoinT np; 3159 np.x = (float) qp.x; 3160 np.y = (float) qp.y; 3161 return np; 3162 } 3163 #endif 3164 3165 3166 extern void Nlm_LocalToGlobal (Nlm_PointPtr pt) 3167 3168 { 3169 #ifdef WIN_MAC 3170 Nlm_PointTool ptool; 3171 3172 if (pt != NULL) { 3173 Nlm_PoinTToPointTool (*pt, &ptool); 3174 #ifdef WIN_MAC_QUARTZ 3175 /* This function is deprecated on 10.4+ but there is no replacement 3176 available until 10.5, so we have to use it anyway */ 3177 QDLocalToGlobalPoint (GetWindowPort(Nlm_GetQuartzCurrentWindow()), &ptool); 3178 #else 3179 LocalToGlobal (&ptool); 3180 #endif 3181 Nlm_PointToolToPoinT (ptool, pt); 3182 } 3183 #endif 3184 #ifdef WIN_MSWIN 3185 Nlm_PointTool ptool; 3186 3187 if (pt != NULL && Nlm_currentHWnd != NULL) { 3188 Nlm_PoinTToPointTool (*pt, &ptool); 3189 ClientToScreen (Nlm_currentHWnd, &ptool); 3190 Nlm_PointToolToPoinT (ptool, pt); 3191 } 3192 #endif 3193 #ifdef WIN_MOTIF 3194 #endif 3195 } 3196 3197 extern void Nlm_GlobalToLocal (Nlm_PointPtr pt) 3198 3199 { 3200 #ifdef WIN_MAC 3201 Nlm_PointTool ptool; 3202 3203 if (pt != NULL) { 3204 Nlm_PoinTToPointTool (*pt, &ptool); 3205 #ifdef WIN_MAC_QUARTZ 3206 /* This function is deprecated on 10.4+ but there is no replacement 3207 available until 10.5, so we have to use it anyway */ 3208 QDGlobalToLocalPoint (GetWindowPort(Nlm_GetQuartzCurrentWindow()), &ptool); 3209 #else 3210 GlobalToLocal (&ptool); 3211 #endif 3212 Nlm_PointToolToPoinT (ptool, pt); 3213 } 3214 #endif 3215 #ifdef WIN_MSWIN 3216 Nlm_PointTool ptool; 3217 3218 if (pt != NULL && Nlm_currentHWnd != NULL) { 3219 Nlm_PoinTToPointTool (*pt, &ptool); 3220 ScreenToClient (Nlm_currentHWnd, &ptool); 3221 Nlm_PointToolToPoinT (ptool, pt); 3222 } 3223 #endif 3224 #ifdef WIN_MOTIF 3225 #endif 3226 } 3227 3228 #ifdef WIN_MSWIN 3229 extern Nlm_Boolean Nlm_VibrantDisabled (void) 3230 3231 { 3232 if (Nlm_GetAppProperty("disable_vibrant") != NULL) { 3233 disabled_count++; 3234 return TRUE; 3235 } 3236 return FALSE; 3237 } 3238 #endif 3239 3240 #ifdef WIN_MAC 3241 static PicHandle picHdl = NULL; 3242 #endif 3243 3244 #ifdef WIN_MSWIN 3245 static HDC picHDC = NULL; 3246 static HDC picWinHDC = NULL; 3247 static HWND picHWND = NULL; 3248 static Nlm_RecT picRect; 3249 #endif 3250 3251 extern void Nlm_CopyWindowImage (void) 3252 3253 { 3254 Nlm_RecT r; 3255 Nlm_WindoW w; 3256 #ifdef WIN_MSWIN 3257 Nlm_RecT realr; 3258 HBITMAP winBitMap, oldBitMap; 3259 HDC hdcMemory; 3260 HDC hdcWindow; 3261 int fStatus = 0; 3262 #endif 3263 3264 w = Nlm_CurrentWindow (); 3265 if (w != NULL) { 3266 Nlm_ObjectRect (w, &r); 3267 #ifdef WIN_MSWIN 3268 Nlm_SectRect ( &r, &Nlm_screenRect, &realr ); 3269 hdcWindow = GetDC(NULL) ; 3270 if ( hdcWindow != NULL ) { 3271 fStatus = 1; 3272 hdcMemory = CreateCompatibleDC(hdcWindow); 3273 if ( hdcMemory != NULL ){ 3274 fStatus = 2; 3275 winBitMap = CreateCompatibleBitmap ( hdcWindow, 3276 realr.right - realr.left, realr.bottom - realr.top ); 3277 if ( winBitMap != NULL ){ 3278 fStatus = 3; 3279 oldBitMap = SelectObject ( hdcMemory, winBitMap ); 3280 BitBlt ( hdcMemory, 0, 0, realr.right - realr.left, 3281 realr.bottom - realr.top, hdcWindow, 3282 realr.left, realr.top, SRCCOPY ); 3283 SelectObject ( hdcMemory, oldBitMap ); 3284 if ( OpenClipboard (Nlm_currentHWnd) ){ 3285 EmptyClipboard (); 3286 if ( SetClipboardData (CF_BITMAP, winBitMap) != NULL ){ 3287 fStatus = 2; 3288 } 3289 CloseClipboard (); 3290 } 3291 } 3292 } 3293 } 3294 switch ( fStatus ) { 3295 case 3: 3296 DeleteObject ( (HGDIOBJ)winBitMap ); 3297 case 2: 3298 DeleteDC (hdcMemory); 3299 case 1: 3300 ReleaseDC (NULL,hdcWindow); 3301 } 3302 #else 3303 Nlm_OffsetRect (&r, -r.left, -r.top); 3304 Nlm_InvalRect (&r); 3305 w = Nlm_StartPicture (&r); 3306 Nlm_Update (); 3307 Nlm_EndPicture (w); 3308 #endif 3309 } 3310 } 3311 3312 #ifdef WIN_MSWIN 3313 extern HDC Nlm_GetPicWinHDC ( void ) 3314 3315 { 3316 return picWinHDC; 3317 } 3318 #endif 3319 3320 3321 #ifdef WIN_MAC_QUARTZ 3322 static CFMutableDataRef Nlm_PictureData = 0; 3323 #endif 3324 3325 extern Nlm_WindoW Nlm_StartPicture (Nlm_RectPtr r) 3326 { 3327 Nlm_WindoW w; 3328 #ifdef WIN_MAC 3329 Nlm_RectTool rtool; 3330 #endif 3331 3332 w = Nlm_CurrentWindow (); 3333 if (r == NULL) 3334 return w; 3335 3336 #ifdef WIN_MAC 3337 #ifdef WIN_MAC_QUARTZ 3338 CGRect cgr = CGRectMake (r->left, r->top, r->right - r->left, r->bottom - r->top); 3339 Nlm_PictureData = CFDataCreateMutable (NULL, 0); 3340 3341 CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData (Nlm_PictureData); 3342 CGContextRef ctx = CGPDFContextCreate (consumer, &cgr, NULL); 3343 CGContextBeginPage (ctx, &cgr); 3344 Nlm_PushPort (ctx); 3345 CGDataConsumerRelease (consumer); 3346 #else 3347 Nlm_RecTToRectTool (r, &rtool); 3348 picHdl = OpenPicture (&rtool); 3349 #endif 3350 #endif 3351 #ifdef WIN_MSWIN 3352 picRect = *r; 3353 picHWND = Nlm_currentHWnd; 3354 picWinHDC = GetWindowDC(picHWND); 3355 picHDC = CreateMetaFile (NULL); 3356 if (picHDC != NULL) 3357 { 3358 SetWindowOrgEx(picHDC, picRect.left, picRect.top, NULL); 3359 SetWindowExtEx(picHDC, picRect.right - picRect.left, 3360 picRect.bottom - picRect.top, NULL); 3361 Nlm_SetPort((HWND) NULL, picHDC); 3362 } 3363 #endif 3364 #ifdef WIN_MOTIF 3365 #endif 3366 3367 return w; 3368 } 3369 3370 3371 extern void Nlm_EndPicture (Nlm_WindoW w) 3372 3373 { 3374 #ifdef WIN_MAC 3375 #ifdef WIN_MAC_QUARTZ 3376 CGContextRef ctx = Nlm_PopPort(); 3377 CGContextEndPage (ctx); 3378 CGContextRelease (ctx); 3379 3380 PasteboardRef pasteboard = 0; 3381 PasteboardCreate (kPasteboardClipboard, &pasteboard); 3382 PasteboardPutItemFlavor (pasteboard, (PasteboardItemID)1, CFSTR("com.adobe.pdf"), Nlm_PictureData, 0); 3383 CFRelease (pasteboard); 3384 CFRelease (Nlm_PictureData); 3385 #else 3386 long len; 3387 PicPtr picPtr; 3388 3389 ClosePicture (); 3390 #if TARGET_API_MAC_CARBON 3391 ClearCurrentScrap(); 3392 #else 3393 ZeroScrap (); 3394 #endif 3395 Nlm_textScrapFull = FALSE; 3396 if (picHdl != NULL) { 3397 len = GetHandleSize ((Handle) picHdl); 3398 picPtr = (PicPtr) Nlm_HandLock (picHdl); 3399 #if TARGET_API_MAC_CARBON 3400 { 3401 OSStatus status; 3402 ScrapRef scrap; 3403 ScrapFlavorFlags flags = 0; 3404 status = GetCurrentScrap(&scrap); 3405 status = PutScrapFlavor(scrap, kScrapFlavorTypePicture, flags, len, picPtr); 3406 } 3407 #else 3408 { OSErr err = PutScrap (len, 'PICT', (Ptr) picPtr); } 3409 #endif 3410 Nlm_HandUnlock (picHdl); 3411 KillPicture (picHdl); 3412 } 3413 picHdl = NULL; 3414 #endif 3415 #endif 3416 #ifdef WIN_MSWIN 3417 GLOBALHANDLE hGMem = NULL; 3418 HMETAFILE hmf = NULL; 3419 LPMETAFILEPICT lpMFP; 3420 int fileSend = 0; 3421 3422 if (picWinHDC != NULL) { 3423 ReleaseDC(picHWND,picWinHDC); 3424 picWinHDC = NULL; 3425 } 3426 if (picHDC != NULL) { 3427 hmf = CloseMetaFile (picHDC); 3428 if ( hmf != NULL ) { 3429 hGMem = GlobalAlloc (GHND, (DWORD) sizeof (METAFILEPICT)); 3430 if ( hGMem != NULL ) { 3431 lpMFP = (LPMETAFILEPICT) GlobalLock (hGMem); 3432 if ( lpMFP != NULL ){ 3433 lpMFP->mm = MM_ANISOTROPIC; 3434 lpMFP->xExt = (picRect.right - picRect.left) * 25; 3435 lpMFP->yExt = (picRect.bottom - picRect.top) * 25; 3436 lpMFP->hMF = hmf; 3437 GlobalUnlock (hGMem); 3438 if ( OpenClipboard (picHWND) ){ 3439 EmptyClipboard (); 3440 if ( SetClipboardData (CF_METAFILEPICT, hGMem) != NULL ){ 3441 fileSend = 1; 3442 } 3443 CloseClipboard (); 3444 } 3445 } 3446 } 3447 } 3448 } 3449 if ( !fileSend ){ 3450 if ( hGMem != NULL ) GlobalFree ( hGMem ); 3451 if ( hmf != NULL ) DeleteMetaFile ( hmf ); 3452 } 3453 picHDC = NULL; 3454 picHWND = NULL; 3455 #endif 3456 #ifdef WIN_MOTIF 3457 #endif 3458 if (w != NULL) { 3459 Nlm_UseWindow (w); 3460 } 3461 } 3462 3463 #ifdef WIN_MOTIF 3464 static Window Nlm_GetAnyX11Window (void) 3465 { 3466 Window wX11; 3467 Nlm_WindoW wVibrant; 3468 Nlm_ShellTool wShell; 3469 3470 wX11 = (Window) 0; 3471 wShell = (Nlm_ShellTool) 0; 3472 wVibrant = Nlm_desktopWindow; 3473 while ( wVibrant != NULL ){ 3474 wShell = Nlm_GetWindowShell ( wVibrant ); 3475 if ( wShell ) 3476 break; 3477 wVibrant = (Nlm_WindoW) Nlm_GetNext ((Nlm_GraphiC)wVibrant); 3478 } 3479 if ( wShell ){ 3480 wX11 = XtWindow ( wShell ); 3481 } 3482 return wX11; 3483 } 3484 #endif 3485 3486 extern void Nlm_StringToClipboard (Nlm_CharPtr str) 3487 3488 { 3489 #ifdef WIN_MAC 3490 #ifdef WIN_MAC_QUARTZ 3491 PasteboardRef pasteboard = 0; 3492 PasteboardCreate (kPasteboardClipboard, &pasteboard); 3493 PasteboardClear (pasteboard); 3494 3495 CFDataRef asciidata = CFDataCreate (NULL, (UInt8 *)str, (CFIndex)strlen (str)); 3496 CFStringRef cfstr = CFStringCreateFromExternalRepresentation (NULL, asciidata, kCFStringEncodingMacRoman); 3497 CFDataRef data = CFStringCreateExternalRepresentation (NULL, cfstr, kCFStringEncodingUnicode, '?'); 3498 PasteboardPutItemFlavor (pasteboard, (PasteboardItemID)1, CFSTR("public.utf16-plain-text"), data, 0); 3499 3500 CFRelease (data); 3501 CFRelease (cfstr); 3502 CFRelease (asciidata); 3503 CFRelease (pasteboard); 3504 #else 3505 long len; 3506 OSErr err; 3507 3508 # if TARGET_API_MAC_CARBON 3509 ClearCurrentScrap(); 3510 # else 3511 ZeroScrap (); 3512 # endif 3513 Nlm_textScrapFull = FALSE; 3514 len = (long) Nlm_StringLen (str); 3515 if (len > 0) { 3516 # if TARGET_API_MAC_CARBON 3517 OSStatus status; 3518 ScrapRef scrap; 3519 ScrapFlavorFlags flags = 0; 3520 status = GetCurrentScrap(&scrap); 3521 status = PutScrapFlavor(scrap, kScrapFlavorTypeText, flags, len, str); 3522 # else 3523 PutScrap (len, 'TEXT', (Ptr) str); 3524 # endif 3525 err = TEFromScrap (); 3526 } 3527 #endif 3528 #endif 3529 #ifdef WIN_MSWIN 3530 HGLOBAL hMem; 3531 DWORD len; 3532 DWORD n; 3533 LPSTR pMem; 3534 LPSTR pStr; 3535 3536 if (Nlm_currentHWnd != NULL) { 3537 if (OpenClipboard (Nlm_currentHWnd)) { 3538 EmptyClipboard (); 3539 len = (long) Nlm_StringLen (str); 3540 if (len > 0) { 3541 hMem = GlobalAlloc (GHND, (DWORD) len + 1); 3542 if (hMem != NULL) { 3543 pMem = GlobalLock (hMem); 3544 if (pMem != NULL) { 3545 pStr = (LPSTR) str; 3546 for (n = 0; n < len; n++) { 3547 *pMem++ = *pStr++; 3548 } 3549 } 3550 GlobalUnlock (hMem); 3551 SetClipboardData (CF_TEXT, hMem); 3552 } 3553 } 3554 CloseClipboard (); 3555 } 3556 } 3557 #endif 3558 #ifdef WIN_MOTIF 3559 XmString clip_label; 3560 long item_id; 3561 Window w; 3562 int status; 3563 char nchar = 0; 3564 3565 if (Nlm_currentXDisplay != NULL && 3566 (w = Nlm_GetAnyX11Window()) != (Window)0) { 3567 clip_label = XmStringCreateSimple ( "vibrant_to_clibboard" ); 3568 do { 3569 status = XmClipboardStartCopy ( Nlm_currentXDisplay, w, 3570 clip_label, CurrentTime, NULL, NULL, 3571 &item_id ); 3572 } while ( status == ClipboardLocked ); 3573 XmStringFree ( clip_label ); 3574 do { 3575 if ( str == NULL ){ 3576 status = XmClipboardCopy ( Nlm_currentXDisplay, w, 3577 item_id, "STRING", &nchar, 3578 (long)1, 3579 0, NULL ); 3580 } else { 3581 status = XmClipboardCopy ( Nlm_currentXDisplay, w, 3582 item_id, "STRING", str, 3583 (long)Nlm_StringLen(str), 3584 0, NULL ); 3585 } 3586 } while ( status == ClipboardLocked ); 3587 do { 3588 status = XmClipboardEndCopy ( Nlm_currentXDisplay, w, 3589 item_id); 3590 } while ( status == ClipboardLocked ); 3591 } 3592 #endif 3593 } 3594 3595 #ifdef WIN_MAC_QUARTZ 3596 static CFDataRef Nlm_CopyClipboardTextData (void) 3597 { 3598 PasteboardRef pasteboard = 0; 3599 PasteboardCreate (kPasteboardClipboard, &pasteboard); 3600 PasteboardSynchronize (pasteboard); 3601 3602 ItemCount itemCount = 0; 3603 PasteboardGetItemCount (pasteboard, &itemCount); 3604 3605 CFDataRef flavorData = 0; 3606 3607 UInt32 index; 3608 for (index = 1; index <= itemCount && !flavorData; index++) 3609 { 3610 PasteboardItemID itemID = 0; 3611 CFArrayRef flavorTypeArray = 0; 3612 CFIndex flavorCount = 0; 3613 3614 PasteboardGetItemIdentifier (pasteboard, index, &itemID); 3615 PasteboardCopyItemFlavors (pasteboard, itemID, &flavorTypeArray); 3616 flavorCount = CFArrayGetCount (flavorTypeArray); 3617 CFIndex i; 3618 for (i = 0; i < flavorCount; i++) 3619 { 3620 CFStringRef flavorType = (CFStringRef)CFArrayGetValueAtIndex (flavorTypeArray, i); 3621 if (UTTypeConformsTo (flavorType, CFSTR("public.utf16-plain-text"))) 3622 { 3623 PasteboardCopyItemFlavorData (pasteboard, itemID, flavorType, &flavorData); 3624 break; 3625 } 3626 } 3627 } 3628 3629 if (flavorData) 3630 { 3631 CFStringRef cfstr = CFStringCreateFromExternalRepresentation (NULL, flavorData, kCFStringEncodingUnicode); 3632 CFDataRef data = CFStringCreateExternalRepresentation (NULL, cfstr, kCFStringEncodingMacRoman, '?'); 3633 CFRelease (flavorData); 3634 CFRelease (cfstr); 3635 return data; 3636 } 3637 3638 return NULL; 3639 } 3640 #endif 3641 3642 extern Nlm_Boolean Nlm_ClipboardHasString (void) 3643 3644 { 3645 #ifdef WIN_MAC 3646 #ifdef WIN_MAC_QUARTZ 3647 CFDataRef data = Nlm_CopyClipboardTextData(); 3648 if (data) 3649 CFRelease (data); 3650 return data != 0; 3651 #else 3652 long len; 3653 OSErr err; 3654 3655 # if TARGET_API_MAC_CARBON 3656 OSStatus status; 3657 ScrapRef scrap; 3658 ScrapFlavorFlags flags = 0; 3659 status = GetCurrentScrap(&scrap); 3660 3661 err = TEFromScrap(); 3662 len = TEGetScrapLength(); 3663 return (Nlm_Boolean) (len > 0); 3664 #endif 3665 #endif 3666 #endif 3667 3668 #ifdef WIN_MSWIN 3669 return (Nlm_Boolean) (IsClipboardFormatAvailable (CF_TEXT)); 3670 #endif 3671 3672 #ifdef WIN_MOTIF 3673 Nlm_Boolean result = FALSE; 3674 Nlm_Char str[2]; 3675 unsigned long len; 3676 unsigned long rlen; 3677 Window w; 3678 int status; 3679 3680 if (Nlm_currentXDisplay != NULL && 3681 (w = Nlm_GetAnyX11Window()) != (Window)0) { 3682 do { 3683 status = XmClipboardLock ( Nlm_currentXDisplay, w ); 3684 } while ( status == ClipboardLocked ); 3685 status = XmClipboardInquireLength ( Nlm_currentXDisplay, w, 3686 "STRING", &len ); 3687 if ( (status != ClipboardSuccess) || (len==0) ) { 3688 XmClipboardUnlock ( Nlm_currentXDisplay, w, FALSE ); 3689 return result; 3690 } 3691 str[0] = 0; 3692 XmClipboardRetrieve ( Nlm_currentXDisplay, w, 3693 "STRING", str, 1, &rlen, NULL ); 3694 XmClipboardUnlock ( Nlm_currentXDisplay, w, FALSE ); 3695 if ( str[0] != 0 ) result = TRUE; 3696 } 3697 return result; 3698 #endif 3699 } 3700 3701 extern Nlm_CharPtr Nlm_ClipboardToString (void) 3702 3703 { 3704 #ifdef WIN_MAC 3705 #ifdef WIN_MAC_QUARTZ 3706 Nlm_CharPtr str = 0; 3707 3708 CFDataRef data = Nlm_CopyClipboardTextData(); 3709 if (data) 3710 { 3711 str = Nlm_MemNew (CFDataGetLength (data)); 3712 CFDataGetBytes (data, CFRangeMake (0, CFDataGetLength (data)), (UInt8 *)str); 3713 CFRelease (data); 3714 } 3715 return str; 3716 #else 3717 long len; 3718 Nlm_CharPtr str; 3719 Handle hdl; 3720 3721 # if TARGET_API_MAC_CARBON 3722 TEFromScrap(); 3723 # endif 3724 hdl = TEScrapHandle(); 3725 len = TEGetScrapLength(); 3726 if (len > 0 && len < 32766) { 3727 str = (Nlm_CharPtr) Nlm_MemNew ((size_t) len + 2); 3728 if (str != NULL) { 3729 str [len] = '\0'; 3730 if (hdl != NULL) { 3731 Nlm_CharPtr ptr; 3732 ptr = (Nlm_CharPtr) *hdl; 3733 Nlm_MemCpy (str, ptr, (size_t) len); 3734 } 3735 } 3736 } 3737 return str; 3738 #endif 3739 #endif 3740 #ifdef WIN_MSWIN 3741 HANDLE hClip; 3742 LPSTR pStr; 3743 Nlm_CharPtr str; 3744 3745 str = NULL; 3746 if (Nlm_currentHWnd != NULL && IsClipboardFormatAvailable (CF_TEXT)) { 3747 if (OpenClipboard (Nlm_currentHWnd)) { 3748 hClip = GetClipboardData (CF_TEXT); 3749 if (hClip != NULL) { 3750 pStr = GlobalLock (hClip); 3751 if (pStr != NULL) { 3752 str = Nlm_StringSave (pStr); 3753 } 3754 GlobalUnlock (hClip); 3755 } 3756 CloseClipboard (); 3757 } 3758 } 3759 return str; 3760 #endif 3761 #ifdef WIN_MOTIF 3762 Nlm_CharPtr str; 3763 unsigned long len; 3764 unsigned long rlen; 3765 Window w; 3766 int status; 3767 3768 if (Nlm_currentXDisplay != NULL && 3769 (w=Nlm_GetAnyX11Window()) != (Window)0) { 3770 do { 3771 status = XmClipboardLock ( Nlm_currentXDisplay, w ); 3772 } while ( status == ClipboardLocked ); 3773 status = XmClipboardInquireLength ( Nlm_currentXDisplay, w, 3774 "STRING", &len ); 3775 if ( status != ClipboardSuccess ) { 3776 XmClipboardUnlock ( Nlm_currentXDisplay, w, FALSE ); 3777 return NULL; 3778 } 3779 str = (Nlm_CharPtr)MemNew(len+1); 3780 XmClipboardRetrieve ( Nlm_currentXDisplay, w, 3781 "STRING", str, len+1, &rlen, NULL ); 3782 XmClipboardUnlock ( Nlm_currentXDisplay, w, FALSE ); 3783 return str; 3784 } 3785 return NULL; 3786 #endif 3787 } 3788 3789 #ifdef WIN_MSWIN 3790 static void Nlm_SetupPrinterDeviceContext(HDC prHDC) 3791 { 3792 if ( !prHDC ) 3793 return; 3794 3795 Nlm_SetPort((HWND)0, prHDC); 3796 SetMapMode(prHDC, MM_ANISOTROPIC); 3797 3798 {{ 3799 HWND screenHwnd = GetDesktopWindow(); 3800 HDC screenDC = GetDC( screenHwnd ); 3801 3802 /* NOTE: for video devices, the logical inch IS NOT == physical inch! */ 3803 SetWindowExtEx(prHDC, GetDeviceCaps(screenDC, LOGPIXELSX), 3804 GetDeviceCaps(screenDC, LOGPIXELSY), NULL); 3805 SetViewportExtEx(prHDC, GetDeviceCaps(prHDC, LOGPIXELSX), 3806 GetDeviceCaps(prHDC, LOGPIXELSY), NULL); 3807 3808 ReleaseDC(screenHwnd, screenDC); 3809 }} 3810 } 3811 #endif 3812 3813 #ifdef WIN_MAC 3814 # if TARGET_API_MAC_CARBON 3815 3816 extern Nlm_WindoW Nlm_StartPrinting (void) 3817 { 3818 OSStatus status; 3819 Boolean accepted; 3820 3821 /* status = PMBegin(); */ 3822 status = PMCreateSession(&printSession); 3823 if (status != noErr) return NULL; 3824 /* status = PMNewPageFormat(&pageFormat); */ 3825 status = PMCreatePageFormat(&pageFormat); 3826 if (status != noErr || pageFormat == kPMNoPageFormat) return NULL; 3827 /* status = PMDefaultPageFormat(pageFormat); */ 3828 status = PMSessionDefaultPageFormat(printSession, pageFormat); 3829 if (status != noErr) return NULL; 3830 /* status = PMPageSetupDialog(pageFormat, &accepted); */ 3831 status = PMSessionPageSetupDialog(printSession, pageFormat, &accepted); 3832 if (status != noErr) return NULL; 3833 /* status = PMNewPrintSettings(&printSettings); */ 3834 status = PMCreatePrintSettings(&printSettings); 3835 if (status != noErr || printSettings == kPMNoPrintSettings) return NULL; 3836 /* status = PMDefaultPrintSettings(printSettings); */ 3837 status = PMSessionDefaultPrintSettings (printSession, printSettings); 3838 if (status != noErr) return NULL; 3839 /* status = PMPrintDialog(printSettings, pageFormat, &accepted); */ 3840 status = PMSessionPrintDialog(printSession, printSettings, pageFormat, &accepted); 3841 if (!accepted) status = kPMCancel; 3842 if (status != noErr) return NULL; 3843 3844 /* status = PMBeginDocument(printSettings, pageFormat, &thePrintingPort); */ 3845 status = PMSessionBeginDocument(printSession, printSettings, pageFormat); 3846 if (status != noErr) return NULL; 3847 3848 return Nlm_CurrentWindow(); 3849 } 3850 3851 # else /* not TARGET_API_MAC_CARBON */ 3852 3853 extern Nlm_WindoW Nlm_StartPrinting (void) 3854 { 3855 Nlm_WindoW w = Nlm_CurrentWindow (); 3856 3857 PrOpen (); 3858 if (prHdl == NULL) { 3859 prHdl = (THPrint) Nlm_HandNew (sizeof (TPrint)); 3860 if (prHdl != NULL) { 3861 PrintDefault (prHdl); 3862 prerr = PrError (); 3863 if (prerr != noErr) { 3864 Nlm_Message (MSG_ERROR, "PrintDefault error %d", (int) prerr); 3865 } 3866 if (! PrStlDialog (prHdl)) { 3867 prHdl = Nlm_HandFree (prHdl); 3868 w = NULL; 3869 } 3870 } else { 3871 Nlm_Message (MSG_ERROR, "Unable to create print handle"); 3872 } 3873 } 3874 if (prHdl != NULL) { 3875 if (PrJobDialog (prHdl)) { 3876 prPort = PrOpenDoc (prHdl, NULL, NULL); 3877 Nlm_SetPort ((GrafPtr) prPort); 3878 prerr = PrError (); 3879 if (prerr != noErr) { 3880 Nlm_Message (MSG_ERROR, "PrOpenDoc error %d", prerr); 3881 } else { 3882 Nlm_nowPrinting = TRUE; 3883 } 3884 } else { 3885 w = NULL; 3886 } 3887 } else { 3888 w = NULL; 3889 } 3890 return w; 3891 } 3892 # endif /* not TARGET_API_MAC_CARBON */ 3893 #endif /* WIN_MAC */ 3894 3895 #ifdef WIN_MSWIN 3896 extern Nlm_WindoW Nlm_StartPrinting (void) 3897 { 3898 Nlm_WindoW w = Nlm_CurrentWindow (); 3899 DWORD commdlgerr; 3900 DOCINFO di; 3901 char docName [256]; 3902 3903 abortPrint = FALSE; 3904 memset (&pd, 0, sizeof (PRINTDLG)); 3905 pd.lStructSize = sizeof (PRINTDLG); 3906 pd.hwndOwner = Nlm_currentHWnd; 3907 pd.Flags = PD_RETURNDC; 3908 if (PrintDlg (&pd) != 0) { 3909 hPr = pd.hDC; 3910 if (hPr != NULL) { 3911 Nlm_SetupPrinterDeviceContext (hPr); 3912 Nlm_StringCpy (docName, "Vibrant"); 3913 Nlm_MemSet(&di, '\0', sizeof(DOCINFO)); 3914 di.cbSize = sizeof (DOCINFO); 3915 di.lpszDocName = (LPCSTR) docName; 3916 prerr = StartDoc (hPr, &di); 3917 if (prerr < 1) { 3918 abortPrint = TRUE; 3919 Nlm_Message (MSG_ERROR, "StartDoc error %d", prerr); 3920 w = NULL; 3921 } else { 3922 Nlm_nowPrinting = TRUE; 3923 } 3924 } else { 3925 commdlgerr = CommDlgExtendedError (); 3926 Nlm_Message (MSG_ERROR, "Unable to create print context, error %lu", 3927 (unsigned long) commdlgerr); 3928 w = NULL; 3929 } 3930 } else { 3931 w = NULL; 3932 } 3933 return w; 3934 } 3935 #endif /* WIN_MSWIN */ 3936 3937 #ifdef WIN_MOTIF 3938 extern Nlm_WindoW Nlm_StartPrinting (void) 3939 { 3940 return NULL; 3941 } 3942 #endif 3943 3944 3945 #ifdef WIN_MAC 3946 # if TARGET_API_MAC_CARBON 3947 3948 extern void Nlm_EndPrinting (Nlm_WindoW w) 3949 { 3950 OSStatus status; 3951 3952 Nlm_nowPrinting = FALSE; 3953 if (w != NULL) { 3954 status = PMSessionError(printSession); 3955 if (status != noErr) { 3956 Nlm_Message (MSG_ERROR, "PM Session error %d", status); 3957 } 3958 /* (void)PMEndDocument(thePrintingPort); */ 3959 PMSessionEndDocument (printSession); 3960 } 3961 if (pageFormat != kPMNoPageFormat) { 3962 /* (void)PMDisposePageFormat(pageFormat); */ 3963 PMRelease(pageFormat); 3964 pageFormat = kPMNoPageFormat; 3965 } 3966 if (printSettings != kPMNoPrintSettings) { 3967 /* (void)PMDisposePrintSettings(printSettings); */ 3968 PMRelease(printSettings); 3969 printSettings = kPMNoPrintSettings; 3970 } 3971 /* (void)PMEnd(); */ 3972 PMRelease(printSession); 3973 } 3974 3975 # else /* not TARGET_API_MAC_CARBON */ 3976 3977 extern void Nlm_EndPrinting (Nlm_WindoW w) 3978 { 3979 TPrStatus prStat; 3980 3981 Nlm_nowPrinting = FALSE; 3982 if (w != NULL) { 3983 PrCloseDoc (prPort); 3984 prerr = PrError (); 3985 if (prerr != noErr) { 3986 Nlm_Message (MSG_ERROR, "PrCloseDoc error %d", prerr); 3987 } 3988 /* This call is not supported under Carbon, need to figure out 3989 how Apple wants us to deal with this ... churchill 12/28/99 */ 3990 PrPicFile (prHdl, 0L, 0L, 0L, &prStat); 3991 prerr = PrError (); 3992 if (prerr != noErr) { 3993 Nlm_Message (MSG_ERROR, "PrPicFile error %d", prerr); 3994 } 3995 prPort = NULL; 3996 Nlm_UseWindow (w); 3997 } 3998 PrClose (); 3999 } 4000 4001 # endif /* not TARGET_API_MAC_CARBON */ 4002 #endif 4003 4004 4005 #ifdef WIN_MSWIN 4006 extern void Nlm_EndPrinting (Nlm_WindoW w) 4007 { 4008 Nlm_nowPrinting = FALSE; 4009 if (w != NULL) { 4010 if (hPr != NULL) { 4011 if (! abortPrint) { 4012 prerr = EndDoc (hPr); 4013 if (prerr < 0) { 4014 Nlm_Message (MSG_ERROR, "EndDoc error %d", prerr); 4015 } 4016 } 4017 DeleteDC (hPr); 4018 if (pd.hDevMode != NULL) { 4019 GlobalFree (pd.hDevMode); 4020 } 4021 if (pd.hDevNames != NULL) { 4022 GlobalFree (pd.hDevNames); 4023 } 4024 } 4025 Nlm_UseWindow (w); 4026 } 4027 } 4028 #endif 4029 4030 #ifdef WIN_MOTIF 4031 extern void Nlm_EndPrinting (Nlm_WindoW w) 4032 { 4033 Nlm_nowPrinting = FALSE; 4034 } 4035 #endif 4036 4037 4038 #ifdef WIN_MAC 4039 4040 extern Nlm_Boolean Nlm_ClipPrintingRect(const Nlm_RecT PNTR rpt) 4041 { 4042 Nlm_RecT r; 4043 4044 if (rpt == NULL || 4045 #if TARGET_API_MAC_CARBON 4046 thePrintingPort == kPMNoReference) 4047 #else 4048 prHdl == NULL || *prHdl == NULL) 4049 #endif 4050 { 4051 return FALSE; 4052 } 4053 4054 r = *rpt; 4055 Nlm_InsetRect(&r, -1, -1); 4056 4057 Nlm_ClipRect( &r ); 4058 return TRUE; 4059 } 4060 4061 #endif /* WIN_MAC */ 4062 4063 4064 #ifdef WIN_MSWIN 4065 4066 extern Nlm_Boolean Nlm_ClipPrintingRect(const Nlm_RecT PNTR rpt) 4067 { 4068 Nlm_RecT r; 4069 4070 POINT pt; 4071 4072 if (rpt == NULL) 4073 return FALSE; 4074 4075 r = *rpt; 4076 Nlm_InsetRect(&r, -1, -1); 4077 4078 if (hPr == NULL) 4079 return FALSE; 4080 4081 pt.x = r.left; 4082 pt.y = r.bottom; 4083 LPtoDP(hPr, &pt, 1); 4084 r.left = (Nlm_Int2)pt.x; 4085 r.bottom = (Nlm_Int2)pt.y; 4086 4087 pt.x = r.right; 4088 pt.y = r.top; 4089 LPtoDP(hPr, &pt, 1); 4090 r.right = (Nlm_Int2)pt.x; 4091 r.top = (Nlm_Int2)pt.y; 4092 4093 Nlm_ClipRect( &r ); 4094 return TRUE; 4095 } 4096 4097 #endif 4098 4099 #if !defined(WIN_MAC) && !defined(WIN_MSWIN) 4100 4101 extern Nlm_Boolean Nlm_ClipPrintingRect(const Nlm_RecT PNTR rpt) 4102 { 4103 return FALSE; 4104 } 4105 4106 #endif 4107 4108 4109 #ifdef WIN_MAC 4110 # if TARGET_API_MAC_CARBON 4111 4112 extern Nlm_Boolean Nlm_PrintingRect(Nlm_RectPtr rpt) 4113 { 4114 OSStatus status; 4115 PMRect pmRect; 4116 SInt16 left, top, right, bottom; 4117 4118 if (rpt == NULL) 4119 return FALSE; 4120 4121 Nlm_LoadRect (rpt, 0, 0, 0, 0); 4122 4123 status = PMGetAdjustedPageRect(pageFormat, &pmRect); 4124 if (status != noErr) return FALSE; 4125 4126 left = pmRect.left; 4127 top = pmRect.top; 4128 right = pmRect.right; 4129 bottom = pmRect.bottom; 4130 4131 Nlm_LoadRect (rpt, left, top, right, bottom); 4132 4133 return TRUE; 4134 } 4135 4136 # else /* not TARGET_API_MAC_CARBON */ 4137 4138 extern Nlm_Boolean Nlm_PrintingRect(Nlm_RectPtr rpt) 4139 { 4140 if (rpt == NULL) 4141 return FALSE; 4142 4143 Nlm_LoadRect (rpt, 0, 0, 0, 0); 4144 4145 if (prHdl == NULL) { 4146 return FALSE; 4147 } else { 4148 TPPrint prPtr; 4149 Nlm_RectTool rtool; 4150 prPtr = (TPPrint)Nlm_HandLock( prHdl ); 4151 if (prPtr == NULL) 4152 return FALSE; 4153 4154 rtool = prPtr->prInfo.rPage; 4155 Nlm_RectToolToRecT(&rtool, rpt); 4156 Nlm_InsetRect(rpt, 10, 10); 4157 Nlm_HandUnlock (prHdl); 4158 } 4159 4160 return TRUE; 4161 } 4162 4163 # endif /* not TARGET_API_MAC_CARBON */ 4164 #endif /* WIN_MAC */ 4165 4166 #ifdef WIN_MSWIN 4167 4168 extern Nlm_Boolean Nlm_PrintingRect(Nlm_RectPtr rpt) 4169 { 4170 POINT physPageSize; 4171 POINT pixelsPerInch; 4172 Nlm_PoinT pt; 4173 4174 if (rpt == NULL) 4175 return FALSE; 4176 4177 Nlm_LoadRect (rpt, 0, 0, 0, 0); 4178 4179 if (hPr == NULL) 4180 return FALSE; 4181 4182 physPageSize.x = GetDeviceCaps(hPr, HORZRES); 4183 physPageSize.y = GetDeviceCaps(hPr, VERTRES); 4184 DPtoLP(hPr, &physPageSize, 1); 4185 Nlm_PointToolToPoinT(physPageSize, &pt); 4186 rpt->right = pt.x; 4187 rpt->bottom = pt.y; 4188 pixelsPerInch.x = GetDeviceCaps(hPr, LOGPIXELSX); 4189 pixelsPerInch.y = GetDeviceCaps(hPr, LOGPIXELSY); 4190 DPtoLP(hPr, &pixelsPerInch, 1); 4191 Nlm_InsetRect(rpt, (Nlm_Int2)(pixelsPerInch.x / 4), 4192 (Nlm_Int2)(pixelsPerInch.y / 4)); 4193 4194 return TRUE; 4195 } 4196 4197 #endif /* WIN_MSWIN */ 4198 4199 #ifdef WIN_MOTIF 4200 4201 extern Nlm_Boolean Nlm_PrintingRect(Nlm_RectPtr rpt) 4202 { 4203 if (rpt != NULL) 4204 Nlm_LoadRect (rpt, 0, 0, 0, 0); 4205 4206 return FALSE; 4207 } 4208 4209 #endif /* WIN_MOTIF */ 4210 4211 4212 #ifdef WIN_MAC 4213 # if TARGET_API_MAC_CARBON 4214 4215 extern Nlm_Boolean Nlm_StartPage (void) 4216 { 4217 OSStatus status; 4218 4219 /* status = PMBeginPage(thePrintingPort, NULL); */ 4220 status = PMSessionBeginPage(printSession, pageFormat, NULL); 4221 if (status != noErr) return false; /* ?? */ 4222 4223 return true; 4224 } 4225 4226 # else 4227 4228 extern Nlm_Boolean Nlm_StartPage (void) 4229 { 4230 Nlm_Boolean rsult; 4231 4232 rsult = TRUE; 4233 if (prPort != NULL) { 4234 PrOpenPage (prPort, NULL); 4235 prerr = PrError (); 4236 if (prerr != noErr) { 4237 Nlm_Message (MSG_ERROR, "PrOpenPage error %d", prerr); 4238 rsult = FALSE; 4239 } 4240 } else { 4241 rsult = FALSE; 4242 } 4243 return rsult; 4244 } 4245 4246 # endif 4247 #endif 4248 4249 4250 #ifdef WIN_MSWIN 4251 4252 extern Nlm_Boolean Nlm_StartPage (void) 4253 { 4254 Nlm_Boolean rsult; 4255 4256 rsult = TRUE; 4257 if (hPr != NULL) { 4258 Nlm_SetupPrinterDeviceContext (hPr); 4259 prerr = StartPage (hPr); 4260 if (prerr < 0) { 4261 Nlm_Message (MSG_ERROR, "StartPage error %d", prerr); 4262 rsult = FALSE; 4263 } 4264 Nlm_SetPort ((HWND) NULL, (HDC) hPr); 4265 } 4266 return rsult; 4267 } 4268 4269 #endif 4270 4271 4272 #ifdef WIN_MOTIF 4273 4274 extern Nlm_Boolean Nlm_StartPage (void) 4275 { 4276 return FALSE; 4277 } 4278 4279 #endif 4280 4281 4282 #ifdef WIN_MAC 4283 # if TARGET_API_MAC_CARBON 4284 4285 extern Nlm_Boolean Nlm_EndPage (void) 4286 { 4287 OSStatus status; 4288 4289 /* status = PMEndPage(thePrintingPort); */ 4290 status = PMSessionEndPage(printSession); 4291 if (status != noErr) return false; /* ?? */ 4292 4293 return true; 4294 } 4295 4296 # else 4297 4298 extern Nlm_Boolean Nlm_EndPage (void) 4299 { 4300 Nlm_Boolean rsult; 4301 4302 rsult = TRUE; 4303 if (prPort != NULL) { 4304 PrClosePage (prPort); 4305 prerr = PrError (); 4306 if (prerr != noErr) { 4307 Nlm_Message (MSG_ERROR, "PrClosePage error %d", prerr); 4308 rsult = FALSE; 4309 } 4310 } else { 4311 rsult = FALSE; 4312 } 4313 return rsult; 4314 } 4315 4316 # endif 4317 #endif 4318 4319 4320 #ifdef WIN_MSWIN 4321 extern Nlm_Boolean Nlm_EndPage (void) 4322 { 4323 Nlm_Boolean rsult; 4324 4325 rsult = TRUE; 4326 if (hPr != NULL) { 4327 prerr = EndPage (hPr); 4328 if (prerr < 0) { 4329 abortPrint = TRUE; 4330 Nlm_Message (MSG_ERROR, "EndPage error %d", prerr); 4331 rsult = FALSE; 4332 } 4333 } else { 4334 rsult = FALSE; 4335 } 4336 return rsult; 4337 } 4338 #endif 4339 4340 #ifdef WIN_MOTIF 4341 extern Nlm_Boolean Nlm_EndPage (void) 4342 { 4343 return FALSE; 4344 } 4345 #endif 4346 4347 #ifdef WIN_MAC 4348 # if !TARGET_API_MAC_CARBON 4349 static OSType Nlm_GetOSType (Nlm_CharPtr str, OSType dfault) 4350 4351 { 4352 OSType rsult; 4353 4354 rsult = dfault; 4355 if (str != NULL && str [0] != '\0') { 4356 rsult = *(OSType*) str; 4357 } 4358 return rsult; 4359 } 4360 #endif 4361 4362 /* 4363 2001-03-22: Joshua Juran 4364 Working directory records are gone in Carbon. 4365 However, so is Standard File. The code which calls Nav Services instead of SF 4366 doesn't need this function, so we don't define it. 4367 */ 4368 # if !TARGET_API_MAC_CARBON 4369 static void Nlm_GetFilePath (Nlm_Int2 currentVol, Nlm_CharPtr path, size_t maxsize) 4370 4371 { 4372 WDPBRec block; 4373 Nlm_Char directory [256]; 4374 Nlm_Int4 dirID; 4375 OSErr err; 4376 CInfoPBRec params; 4377 Nlm_Char temp [256]; 4378 Nlm_Int2 vRefNum; 4379 4380 block.ioNamePtr = NULL; 4381 block.ioVRefNum = currentVol; 4382 block.ioWDIndex = 0; 4383 block.ioWDProcID = 0; 4384 PBGetWDInfoSync(&block); 4385 dirID = block.ioWDDirID; 4386 vRefNum = block.ioWDVRefNum; 4387 temp [0] = '\0'; 4388 params.dirInfo.ioNamePtr = (StringPtr) directory; 4389 params.dirInfo.ioDrParID = dirID; 4390 do { 4391 params.dirInfo.ioVRefNum = vRefNum; 4392 params.dirInfo.ioFDirIndex = -1; 4393 params.dirInfo.ioDrDirID = params.dirInfo.ioDrParID; 4394 err = PBGetCatInfo (¶ms, FALSE); 4395 Nlm_PtoCstr (directory); 4396 Nlm_StrngCat (directory, ":", sizeof (directory)); 4397 Nlm_StrngCat (directory, temp, sizeof (directory)); 4398 Nlm_StrngCpy (temp, directory, sizeof (temp)); 4399 } while (params.dirInfo.ioDrDirID != fsRtDirID); 4400 Nlm_StringNCpy_0 (path, temp, maxsize); 4401 } 4402 # endif /* !TARGET_API_MAC_CARBON */ 4403 #endif 4404 4405 #ifdef WIN_MOTIF 4406 static void Nlm_CreateFileDialogShell (void) 4407 { 4408 Cardinal n = 0; 4409 Arg wargs[8]; 4410 4411 if (Nlm_fileDialogShell != NULL) 4412 return; 4413 4414 XtSetArg (wargs[n], XmNdefaultFontList, Nlm_XfontList); n++; 4415 XtSetArg (wargs[n], XmNdeleteResponse, XmDO_NOTHING); n++; 4416 Nlm_fileDialogShell = XtAppCreateShell((String) NULL, (String) "Vibrant", 4417 applicationShellWidgetClass, 4418 Nlm_currentXDisplay, wargs, n); 4419 } 4420 4421 4422 static void Nlm_FileCancelCallback (Widget fs, XtPointer client_data, XtPointer call_data) 4423 4424 { 4425 fileBoxUp = FALSE; 4426 fileBoxRsult = FALSE; 4427 } 4428 4429 static void Nlm_FileOkCallback (Widget fs, XtPointer client_data, XtPointer call_data) 4430 4431 { 4432 XmFileSelectionBoxCallbackStruct *cbs; 4433 char *filename; 4434 4435 cbs = (XmFileSelectionBoxCallbackStruct *) call_data; 4436 fileBoxUp = FALSE; 4437 if (! XmStringGetLtoR (cbs->value, XmSTRING_DEFAULT_CHARSET, &filename)) { 4438 return; 4439 } 4440 if (! *filename) { 4441 XtFree (filename); 4442 fileBoxRsult = FALSE; 4443 return; 4444 } 4445 Nlm_StringNCpy_0(filePath, filename, sizeof(filePath)); 4446 XtFree (filename); 4447 fileBoxRsult = TRUE; 4448 } 4449 4450 static void Nlm_FileNoMatchCallback (Widget fs, XtPointer client_data, XtPointer call_data) 4451 4452 { 4453 fileBoxUp = FALSE; 4454 fileBoxRsult = FALSE; 4455 } 4456 4457 static void Nlm_FileMapCallback (Widget fs, XtPointer client_data, XtPointer call_data) 4458 4459 { 4460 Position x, y; 4461 Dimension w, h; 4462 4463 XtVaGetValues (fs, XmNwidth, &w, XmNheight, &h, NULL); 4464 x = (Position) (Nlm_screenRect.right - w) / (Position) 2; 4465 y = (Position) (Nlm_screenRect.bottom - h) / (Position) 3; 4466 XtVaSetValues (fs, XmNx, x, XmNy, y, NULL); 4467 } 4468 #endif 4469 4470 #ifdef WIN_MAC 4471 extern void Nlm_ConvertFilename ( FSSpec *fss, Nlm_CharPtr filename ); 4472 4473 #if TARGET_API_MAC_CARBON 4474 4475 /* new code calling MoreFiles */ 4476 extern void Nlm_ConvertFilename ( FSSpec *fss, Nlm_CharPtr filename ) 4477 { 4478 OSErr err; 4479 #ifdef OS_UNIX_DARWIN 4480 const Nlm_Int4 maxPathLen = 256; 4481 FSRef fsref; 4482 4483 err = FSpMakeFSRef(fss, &fsref); 4484 if (err == noErr) { 4485 /* if the file exists we can use this. */ 4486 err = FSRefMakePath(&fsref, (Nlm_UcharPtr) filename, maxPathLen); 4487 } else if (err == fnfErr) { 4488 /* if the file does not exist we make the path of the parent directory 4489 and tack on the name of the file when done. */ 4490 FSSpec parentFSS = *fss; 4491 parentFSS.name[0] = '\0'; 4492 err = FSpMakeFSRef(&parentFSS, &fsref); 4493 if (err == noErr) { 4494 err = FSRefMakePath(&fsref, (Nlm_UcharPtr) filename, maxPathLen); 4495 if (err == noErr) { 4496 Nlm_StrCat(filename, "/"); 4497 /* fss->name is a pascal string. */ 4498 Nlm_StrNCat(filename, (char *) &fss->name[1], fss->name[0]); 4499 } 4500 } 4501 } 4502 4503 /* if there were any errors make sure the filename is blank. */ 4504 if (err != noErr) { 4505 filename[0] = '\0'; 4506 } 4507 4508 #else // OS_UNIX_DARWIN 4509 4510 short fullPathLen; 4511 Handle fullPath = NULL; 4512 Nlm_CharPtr str; 4513 4514 if (fss == NULL || filename == NULL) return; 4515 *filename = '\0'; 4516 /* 4517 FSMakePath (fss->vRefNum, fss->parID, (ConstStr255Param) fss->name, (UInt8 *) filename, 255); 4518 */ 4519 err = GetFullPath (fss->vRefNum, fss->parID, (ConstStr255Param) fss->name, &fullPathLen, &fullPath); 4520 if (fullPath == NULL || fullPathLen < 1) return; 4521 HLock ((Ptr *) fullPath); 4522 str = (Nlm_CharPtr) *((Ptr *) fullPath); 4523 /* 4524 str = Nlm_HandLock (fullPath); 4525 */ 4526 if (str != NULL) { 4527 if (fullPathLen > 0 && fullPathLen < 255) { 4528 str [(int) fullPathLen] = '\0'; 4529 } 4530 Nlm_StringCpy (filename, str); 4531 } 4532 HUnlock ((Ptr *) fullPath); 4533 DisposeHandle ((Ptr *) fullPath); 4534 /* 4535 Nlm_HandUnlock (fullPath); 4536 Nlm_HandFree (fullPath); 4537 */ 4538 #endif // OS_UNIX_DARWIN 4539 } 4540 4541 4542 #else 4543 4544 /* AppleEvent handlers modified from Roger Sayle's RasMol code */ 4545 extern void Nlm_ConvertFilename ( FSSpec *fss, Nlm_CharPtr filename ) 4546 4547 { 4548 register char *src; 4549 register char *dst; 4550 register int i; 4551 char buffer [256]; 4552 4553 Str255 dirname; 4554 DirInfo dinfo; 4555 4556 src = buffer; 4557 dinfo.ioDrParID = fss->parID; 4558 dinfo.ioNamePtr = dirname; 4559 do { 4560 dinfo.ioVRefNum = fss->vRefNum; 4561 dinfo.ioFDirIndex = -1; 4562 dinfo.ioDrDirID = dinfo.ioDrParID; 4563 PBGetCatInfo ((CInfoPBPtr) &dinfo, 0); 4564 4565 *src++ = ':'; 4566 for ( i=dirname[0]; i; i-- ) 4567 *src++ = dirname [i]; 4568 } while ( dinfo.ioDrDirID != 2 ); 4569 4570 /* Reverse the file path! */ 4571 dst = filename; 4572 while ( src != buffer ) 4573 *dst++ = *(--src); 4574 for( i = 1; i <= fss->name [0]; i++ ) 4575 *dst++ = fss->name [i]; 4576 *dst = '\0'; 4577 } 4578 4579 #endif 4580 #endif 4581 4582 #ifdef WIN_MAC 4583 #if defined(PROC_PPC) || defined(OS_UNIX_DARWIN) 4584 static pascal void MyNavEventProc (NavEventCallbackMessage callBackSelector, 4585 NavCBRecPtr callBackParms, 4586 NavCallBackUserData callBackUD) 4587 4588 { 4589 } 4590 4591 static pascal Boolean MyNavTextFilterProc (AEDesc* theItem, void* info, 4592 NavCallBackUserData callBackUD, 4593 NavFilterModes filterMode) 4594 4595 { 4596 Boolean display = true; 4597 NavFileOrFolderInfo* theInfo = (NavFileOrFolderInfo*)info; 4598 OSType fdType; 4599 4600 if (theItem->descriptorType == typeFSS) { 4601 if (!theInfo->isFolder) { 4602 fdType = theInfo->fileAndFolder.fileInfo.finderInfo.fdType; 4603 #ifdef OS_UNIX_DARWIN 4604 /* on Darwin, desired files may not have type set, so also allow type 0 */ 4605 if (fdType != 'TEXT' && fdType != 0) { 4606 display = false; 4607 } 4608 #else 4609 if (fdType != 'TEXT') { 4610 display = false; 4611 } 4612 #endif 4613 } 4614 } 4615 return display; 4616 } 4617 4618 static pascal Boolean MyNavFilterProc (AEDesc* theItem, void* info, 4619 NavCallBackUserData callBackUD, 4620 NavFilterModes filterMode) 4621 4622 { 4623 return true; 4624 } 4625 #endif 4626 #endif 4627 4628 #ifdef WIN_MAC 4629 #if defined(PROC_PPC) || defined(OS_UNIX_DARWIN) 4630 static Nlm_Boolean Nlm_NavServGetInputFileName (Nlm_CharPtr fileName, size_t maxsize, 4631 Nlm_CharPtr extType, Nlm_CharPtr macType) 4632 4633 { 4634 NavDialogOptions dialogOptions; 4635 AEDesc defaultLocation; 4636 NavEventUPP eventProc = NewNavEventUPP(MyNavEventProc); 4637 NavObjectFilterUPP filterProc; 4638 OSErr anErr = noErr; 4639 FSSpec fss; 4640 char filename [256]; 4641 Nlm_Boolean rsult = FALSE; 4642 4643 if (StringCmp (macType, "TEXT") == 0) { 4644 filterProc = NewNavObjectFilterUPP(MyNavTextFilterProc); 4645 } else { 4646 filterProc = NewNavObjectFilterUPP(MyNavFilterProc); 4647 } 4648 4649 /* Specify default options for dialog box */ 4650 anErr = NavGetDefaultDialogOptions(&dialogOptions); 4651 if (anErr == noErr) 4652 { 4653 /* Adjust the options to fit our needs */ 4654 /* Set this option */ 4655 dialogOptions.dialogOptionFlags |= kNavSelectDefaultLocation; 4656 /* Clear this one */ 4657 dialogOptions.dialogOptionFlags ^= kNavAllowPreviews; 4658 4659 anErr = AECreateDesc(typeFSS, &fss, 4660 sizeof(fss), 4661 &defaultLocation ); 4662 if (anErr == noErr) 4663 { 4664 /* Get 'open' resource. A nil handle being returned is OK, 4665 this simply means no automatic file filtering. */ 4666 NavTypeListHandle typeList = (NavTypeListHandle)GetResource( 4667 'open', 128); 4668 NavReplyRecord reply; 4669 4670 anErr = NavChooseFile (&defaultLocation, &reply, &dialogOptions, 4671 eventProc, nil, filterProc, 4672 typeList, 0); 4673 if (anErr == noErr && reply.validRecord) 4674 { 4675 /* Deal with multiple file selection */ 4676 long count; 4677 4678 anErr = AECountItems(&(reply.selection), &count); 4679 if (count > 1) { 4680 count = 1; /* force to 1 */ 4681 } 4682 if (anErr == noErr) 4683 { 4684 long index; 4685 4686 for (index = 1; index <= count; index++) 4687 { 4688 AEKeyword theKeyword; 4689 DescType actualType; 4690 Size actualSize; 4691 FSSpec documentFSSpec; 4692 4693 anErr = AEGetNthPtr(&(reply.selection), index, 4694 typeFSS, &theKeyword, 4695 &actualType,&documentFSSpec, 4696 sizeof(documentFSSpec), 4697 &actualSize); 4698 if (anErr == noErr) 4699 { 4700 Nlm_ConvertFilename (&documentFSSpec, filename); 4701 Nlm_StringNCpy_0 (fileName, filename, maxsize); 4702 rsult = TRUE; 4703 } 4704 } 4705 } 4706 /* Dispose of NavReplyRecord, resources, descriptors */ 4707 anErr = NavDisposeReply(&reply); 4708 } 4709 if (typeList != NULL) 4710 { 4711 ReleaseResource( (Handle)typeList); 4712 } 4713 (void) AEDisposeDesc(&defaultLocation); 4714 } 4715 } 4716 DisposeNavEventUPP(eventProc); 4717 DisposeNavObjectFilterUPP(filterProc); 4718 return rsult; 4719 } 4720 #endif 4721 #endif 4722 4723 #ifdef WIN_MSWIN 4724 4725 #ifndef TTM_POP 4726 #define TTM_POP (WM_USER + 28) 4727 #endif 4728 4729 static LRESULT CALLBACK StopToolTips(int nCode, 4730 WPARAM wParam, 4731 LPARAM lParam 4732 ) 4733 { 4734 PCWPSTRUCT msg; 4735 4736 msg = (PCWPSTRUCT) lParam; 4737 4738 if (nCode < 0) { 4739 return CallNextHookEx (NULL, nCode, wParam, lParam); 4740 } 4741 if (msg != NULL) { 4742 4743 if (msg->message > TTM_ACTIVATE 4744 #ifdef TTM_GETTITLE 4745 && msg->message <= TTM_GETTITLE 4746 #elif defined(TTM_SETTITLEW) 4747 && msg->message <= TTM_SETTITLEW 4748 #elif defined(TTM_UPDATE) 4749 && msg->message <= TTM_UPDATE 4750 #else 4751 && msg->message <= TTM_POP 4752 #endif 4753 && msg->message != TTM_RELAYEVENT 4754 && msg->message != TTM_GETTEXTA) { 4755 SendMessage (msg->hwnd, TTM_ACTIVATE, 0, 0); 4756 return 1; 4757 } 4758 } 4759 return 0; 4760 } 4761 4762 #endif 4763 4764 extern Nlm_Boolean Nlm_GetInputFileName (Nlm_CharPtr fileName, size_t maxsize, 4765 Nlm_CharPtr extType, Nlm_CharPtr macType) 4766 4767 { 4768 #ifdef WIN_MAC 4769 # if TARGET_API_MAC_CARBON 4770 return Nlm_NavServGetInputFileName (fileName, maxsize, extType, macType); 4771 # else 4772 Nlm_Char currentFileName [64]; 4773 Nlm_Char currentPath [256]; 4774 SFTypeList fTypeList; 4775 Nlm_Int2 i; 4776 Nlm_Int2 lengthTypes; 4777 Nlm_Int2 numTypes; 4778 Nlm_PointTool ptool; 4779 Nlm_RecT r; 4780 SFReply reply; 4781 Nlm_Boolean rsult; 4782 Nlm_RectTool rtool; 4783 GrafPtr tempPort; 4784 PenState state; 4785 Nlm_Char str [5]; 4786 Nlm_PoinT where; 4787 4788 if (Nlm_usesMacNavServices) { 4789 return Nlm_NavServGetInputFileName (fileName, maxsize, extType, macType); 4790 } 4791 where.x = 90; 4792 where.y = 100; 4793 lengthTypes = sizeof (fileTypes); 4794 for (i = 0; i < lengthTypes; i++) { 4795 fileTypes [i] = '\0'; 4796 } 4797 if (macType != NULL && macType [0] != '\0') { 4798 Nlm_StringNCpy (fileTypes, macType, 6); /* remains StringNCpy, not _0 */ 4799 fileTypes [4] = '\0'; 4800 } 4801 if (fileTypes [0] != '\0') { 4802 numTypes = 0; 4803 i = 0; 4804 while (numTypes < 4 && i <= lengthTypes) { 4805 Nlm_StrngSeg (str, fileTypes, i, 4, sizeof (str)); 4806 fTypeList [numTypes] = Nlm_GetOSType (str, ' '); 4807 numTypes++; 4808 i += 4; 4809 } 4810 } else { 4811 numTypes = -1; 4812 } 4813 GetPenState (&state); 4814 GetPort (&tempPort); 4815 Nlm_PoinTToPointTool (where, &ptool); 4816 SFGetFile (ptool, NULL, NULL, numTypes, fTypeList, NULL, &reply); 4817 SetPort (tempPort); 4818 SetPenState (&state); 4819 Nlm_GetRect ((Nlm_GraphiC) Nlm_desktopWindow, &r); 4820 Nlm_RecTToRectTool (&r, &rtool); 4821 ClipRect (&rtool); 4822 if (reply.good != 0 && fileName != NULL && maxsize > 0) { 4823 Nlm_StringNCpy_0(currentFileName, (Nlm_CharPtr) &(reply.fName), 4824 sizeof(currentFileName)); 4825 Nlm_PtoCstr (currentFileName); 4826 currentPath[0] = '\0'; 4827 Nlm_GetFilePath (reply.vRefNum, currentPath, sizeof (currentPath)); 4828 Nlm_StringNCat(currentPath, currentFileName, 4829 sizeof(currentPath) - Nlm_StringLen(currentPath) - 1); 4830 Nlm_StringNCpy_0(fileName, currentPath, maxsize); 4831 rsult = TRUE; 4832 } else { 4833 rsult = FALSE; 4834 } 4835 Nlm_Update (); 4836 return rsult; 4837 # endif 4838 #endif /* WIN_MAC */ 4839 4840 #ifdef WIN_MSWIN 4841 char szDirName [256]; 4842 char szFile [256]; 4843 char szFileTitle [256]; 4844 UINT i; 4845 UINT cbString; 4846 char chReplace; 4847 char szFilter [256]; 4848 Nlm_Boolean rval; 4849 HHOOK hook; 4850 DWORD thread_id; 4851 4852 /* Get the current working directory: */ 4853 szDirName[0] = '\0'; 4854 _getcwd(szDirName, sizeof (szDirName)); 4855 szFile [0] = '\0'; 4856 memset (szFilter, 0, sizeof(szFilter)); 4857 if (extType != NULL && extType [0] != '\0') { 4858 Nlm_StringCpy (szFilter, "Filtered Files (*"); 4859 if (extType [0] != '.') { 4860 Nlm_StringCat (szFilter, "."); 4861 } 4862 Nlm_StringNCat (szFilter, extType, 5); 4863 Nlm_StringCat (szFilter, ")|*"); 4864 if (extType [0] != '.') { 4865 Nlm_StringCat (szFilter, "."); 4866 } 4867 Nlm_StringNCat (szFilter, extType, 5); 4868 Nlm_StringCat (szFilter, "|"); 4869 } else { 4870 Nlm_StringCpy (szFilter, "All Files (*.*)|*.*|"); 4871 } 4872 cbString = (UINT) Nlm_StringLen (szFilter); 4873 chReplace = szFilter [cbString - 1]; 4874 for (i = 0; szFilter [i] != '\0'; i++) { 4875 if (szFilter [i] == chReplace) { 4876 szFilter [i] = '\0'; 4877 } 4878 } 4879 memset (&ofn, 0, sizeof(OPENFILENAME)); 4880 ofn.lStructSize = sizeof(OPENFILENAME); 4881 ofn.hwndOwner = Nlm_currentHWnd; 4882 ofn.lpstrFilter = szFilter; 4883 ofn.nFilterIndex = 1; 4884 ofn.lpstrFile = szFile; 4885 ofn.nMaxFile = sizeof (szFile); 4886 ofn.lpstrFileTitle = szFileTitle; 4887 ofn.nMaxFileTitle = sizeof (szFileTitle); 4888 ofn.lpstrInitialDir = szDirName; 4889 ofn.Flags = 4890 OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; 4891 /* turn off tooltips, because they were causing Windows 2000 to crash when opening desktop files */ 4892 thread_id = GetCurrentThreadId(); 4893 hook = SetWindowsHookEx (WH_CALLWNDPROC, StopToolTips, NULL, thread_id); 4894 if (GetOpenFileName (&ofn) && fileName != NULL && maxsize > 0) { 4895 Nlm_StringNCpy_0(fileName, ofn.lpstrFile, maxsize); 4896 AnsiToOemBuff (fileName, fileName, maxsize); 4897 4898 rval = TRUE; 4899 } else { 4900 rval = FALSE; 4901 } 4902 UnhookWindowsHookEx (hook); 4903 return rval; 4904 #endif 4905 4906 #ifdef WIN_MOTIF 4907 XmString dirmask; 4908 char *lastSlash; 4909 char str [256]; 4910 char *text; 4911 Widget txt; 4912 4913 Nlm_CreateFileDialogShell (); 4914 if (Nlm_fileDialogShell != NULL && fileName != NULL) { 4915 if (fileDialog == NULL) { 4916 Cardinal n = 0; 4917 Arg wargs[4]; 4918 XtSetArg (wargs[n], XmNcolormap, Nlm_VibrantDefaultColormap()); n++; 4919 XtSetArg (wargs[n], XmNvisual, Nlm_VibrantDefaultVisual ()); n++; 4920 XtSetArg (wargs[n], XmNdepth, Nlm_VibrantDefaultDepth ()); n++; 4921 fileDialog = XmCreateFileSelectionDialog (Nlm_fileDialogShell, 4922 (String) "file_selection", wargs, n); 4923 XtAddCallback (fileDialog, XmNcancelCallback, Nlm_FileCancelCallback, NULL); 4924 XtAddCallback (fileDialog, XmNokCallback, Nlm_FileOkCallback, NULL); 4925 XtAddCallback (fileDialog, XmNnoMatchCallback, Nlm_FileNoMatchCallback, NULL); 4926 XtAddCallback (fileDialog, XmNmapCallback, Nlm_FileMapCallback, NULL); 4927 XtVaSetValues (fileDialog, XmNdefaultPosition, FALSE, 4928 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL); 4929 } 4930 if (fileDialog != NULL) { 4931 txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_FILTER_TEXT); 4932 text = XmTextGetString (txt); 4933 Nlm_StringNCpy_0(str, text, sizeof(str)); 4934 lastSlash = Nlm_StringRChr (str, DIRDELIMCHR); 4935 if (lastSlash != NULL) { 4936 lastSlash [1] = '\0'; 4937 } else { 4938 lastSlash = &(str [Nlm_StringLen (str) - 1]); 4939 } 4940 if (extType != NULL && extType [0] != '\0') { 4941 Nlm_StringCat (str, "*"); 4942 if (extType [0] != '.') { 4943 Nlm_StringCat (str, "."); 4944 } 4945 Nlm_StringNCat (str, extType, 5); 4946 dirmask = XmStringCreateLtoR (str, XmSTRING_DEFAULT_CHARSET); 4947 XmFileSelectionDoSearch (fileDialog, dirmask); 4948 XmStringFree (dirmask); 4949 if (lastSlash != NULL) { 4950 lastSlash [1] = '\0'; 4951 } 4952 } 4953 XtFree (text); 4954 txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_TEXT); 4955 XmTextSetString (txt, str); 4956 XtVaSetValues (fileDialog, XmNmustMatch, TRUE, NULL); 4957 fileBoxUp = TRUE; 4958 fileBoxRsult = FALSE; 4959 XtManageChild (fileDialog); 4960 XSync (Nlm_currentXDisplay, FALSE); 4961 while (fileBoxUp) { 4962 XEvent event; 4963 XPeekEvent(Nlm_currentXDisplay, &event); 4964 Nlm_ProcessAnEvent (); 4965 } 4966 if (fileBoxRsult) { 4967 Nlm_StringNCpy_0(fileName, filePath, maxsize); 4968 } 4969 XtUnmanageChild (fileDialog); 4970 XSync (Nlm_currentXDisplay, FALSE); 4971 } 4972 } 4973 return fileBoxRsult; 4974 #endif 4975 } 4976 4977 #ifdef WIN_MSWIN 4978 static void Nlm_CopyDefaultName (Nlm_CharPtr dst, Nlm_CharPtr src) 4979 { 4980 /* 4981 Nlm_Char ch; 4982 Nlm_Int2 i; 4983 Nlm_Int2 j; 4984 Nlm_Int2 k; 4985 */ 4986 4987 if (dst == NULL || src == NULL) 4988 return; 4989 Nlm_StringCpy(dst, src); 4990 4991 /* 4992 i = 0; 4993 j = 0; 4994 k = 0; 4995 ch = src[i]; 4996 while (k < 8 && ch != '\0' && (IS_ALPHANUM(ch) || ch == '_')) 4997 { 4998 dst [j] = ch; 4999 i++; j++; k++; 5000 ch = src [i]; 5001 } 5002 while (ch != '\0' && ch != '.') 5003 { 5004 i++; 5005 ch = src [i]; 5006 } 5007 if (ch == '.') 5008 { 5009 dst[j] = ch; 5010 i++; 5011 j++; 5012 ch = src[i]; 5013 k = 0; 5014 while (k < 3 && ch != '\0' && (IS_ALPHANUM(ch) || ch == '_')) 5015 { 5016 dst [j] = ch; 5017 i++; j++; k++; 5018 ch = src[i]; 5019 } 5020 if (k == 0) 5021 j--; 5022 } 5023 5024 dst[j] = '\0'; 5025 */ 5026 } 5027 #endif 5028 5029 #ifdef WIN_MAC 5030 #if defined(PROC_PPC) || defined(OS_UNIX_DARWIN) 5031 static Nlm_Boolean Nlm_NavServGetOutputFileName (Nlm_CharPtr fileName, size_t maxsize, 5032 Nlm_CharPtr dfault) 5033 5034 { 5035 OSErr anErr = noErr; 5036 NavReplyRecord reply; 5037 NavDialogOptions dialogOptions; 5038 AEDesc defaultLocation; 5039 FSSpec fss; 5040 OSType fileTypeToSave = 'TEXT'; 5041 OSType creatorType; 5042 NavEventUPP eventProc = NewNavEventUPP (MyNavEventProc); 5043 char filename [256]; 5044 Nlm_Boolean rsult = FALSE; 5045 5046 anErr = NavGetDefaultDialogOptions (&dialogOptions); 5047 if (anErr == noErr) 5048 { 5049 /* Adjust the options to fit our needs */ 5050 /* Set this option */ 5051 dialogOptions.dialogOptionFlags |= kNavNoTypePopup; 5052 /* Clear this one */ 5053 dialogOptions.dialogOptionFlags ^= kNavAllowStationery; 5054 5055 anErr = AECreateDesc(typeFSS, &fss, 5056 sizeof(fss), 5057 &defaultLocation ); 5058 if (anErr == noErr) { 5059 5060 /* One way to get the name for the file to be saved. */ 5061 Nlm_StringNCpy_0 ((Nlm_CharPtr) dialogOptions.savedFileName, dfault, 255); 5062 Nlm_CtoPstr ((Nlm_CharPtr) dialogOptions.savedFileName); 5063 5064 Nlm_MemSet ((void *) &creatorType, '?', 4); 5065 anErr = NavPutFile( &defaultLocation, &reply, &dialogOptions, eventProc, 5066 fileTypeToSave, creatorType, 0 ); 5067 if (anErr == noErr && reply.validRecord) 5068 { 5069 AEKeyword theKeyword; 5070 DescType actualType; 5071 Size actualSize; 5072 FSSpec documentFSSpec; 5073 5074 anErr = AEGetNthPtr(&(reply.selection), 1, typeFSS, 5075 &theKeyword, &actualType, 5076 &documentFSSpec, sizeof(documentFSSpec), 5077 &actualSize ); 5078 if (anErr == noErr) 5079 { 5080 if (reply.replacing) 5081 { 5082 /* 5083 Make sure you save a temporary file 5084 so you can check for problems before replacing 5085 an existing file. Once the save is confirmed, 5086 swap the files and delete the original. 5087 */ 5088 Nlm_ConvertFilename (&documentFSSpec, filename); 5089 Nlm_StringNCpy_0 (fileName, filename, maxsize); 5090 rsult = TRUE; 5091 } 5092 else 5093 { 5094 Nlm_ConvertFilename (&documentFSSpec, filename); 5095 Nlm_StringNCpy_0 (fileName, filename, maxsize); 5096 rsult = TRUE; 5097 } 5098 5099 if ( anErr == noErr) 5100 { 5101 /* DO NOT call NavCompleteSave() to complete */ 5102 /* anErr = NavCompleteSave(&reply, 5103 kNavTranslateInPlace); */ 5104 } 5105 } 5106 (void) NavDisposeReply(&reply); 5107 } 5108 } 5109 (void) AEDisposeDesc(&defaultLocation); 5110 DisposeNavEventUPP(eventProc); 5111 } 5112 return rsult; 5113 } 5114 #endif 5115 #endif 5116 5117 extern Nlm_Boolean Nlm_GetOutputFileName (Nlm_CharPtr fileName, size_t maxsize, 5118 Nlm_CharPtr dfault) 5119 5120 { 5121 #ifdef WIN_MAC 5122 # if TARGET_API_MAC_CARBON 5123 return Nlm_NavServGetOutputFileName (fileName, maxsize, dfault); 5124 # else /* not TARGET_API_MAC_CARBON */ 5125 Nlm_Char currentFileName [64]; 5126 Nlm_Char currentPath [256]; 5127 unsigned char original [256]; 5128 unsigned char promptStr [256]; 5129 Nlm_PointTool ptool; 5130 Nlm_RecT r; 5131 SFReply reply; 5132 Nlm_Boolean rsult; 5133 Nlm_RectTool rtool; 5134 GrafPtr tempPort; 5135 PenState state; 5136 Nlm_PoinT where; 5137 5138 if (Nlm_usesMacNavServices) { 5139 return Nlm_NavServGetOutputFileName (fileName, maxsize, dfault); 5140 } 5141 5142 where.x = 90; 5143 where.y = 100; 5144 GetPenState (&state); 5145 GetPort (&tempPort); 5146 Nlm_PoinTToPointTool (where, &ptool); 5147 Nlm_StringNCpy_0((Nlm_CharPtr)original, dfault, sizeof(original)); 5148 Nlm_CtoPstr ((Nlm_CharPtr) original); 5149 Nlm_StringNCpy_0((Nlm_CharPtr)promptStr, "Save File As:", sizeof(promptStr)); 5150 Nlm_CtoPstr ((Nlm_CharPtr) promptStr); 5151 SFPutFile (ptool, promptStr, original, NULL, &reply); 5152 SetPort (tempPort); 5153 SetPenState (&state); 5154 Nlm_GetRect ((Nlm_GraphiC) Nlm_desktopWindow, &r); 5155 Nlm_RecTToRectTool (&r, &rtool); 5156 ClipRect (&rtool); 5157 if (reply.good != 0 && fileName != NULL && maxsize > 0) { 5158 Nlm_StringNCpy_0(currentFileName, (Nlm_CharPtr) &(reply.fName), 5159 sizeof (currentFileName)); 5160 Nlm_PtoCstr (currentFileName); 5161 currentPath[0] = '\0'; 5162 Nlm_GetFilePath (reply.vRefNum, currentPath, sizeof (currentPath)); 5163 Nlm_StringNCat(currentPath, currentFileName, 5164 sizeof(currentPath) - Nlm_StringLen(currentPath) - 1); 5165 Nlm_StringNCpy_0(fileName, currentPath, maxsize); 5166 rsult = TRUE; 5167 } else { 5168 rsult = FALSE; 5169 } 5170 Nlm_Update (); 5171 return rsult; 5172 # endif /* not TARGET_API_MAC_CARBON */ 5173 #endif /* ifdef WIN_MAC */ 5174 5175 #ifdef WIN_MSWIN 5176 char szDirName [256]; 5177 char szFile [256]; 5178 char szFileTitle [256]; 5179 UINT i; 5180 UINT cbString; 5181 char chReplace; 5182 char szFilter [256]; 5183 Nlm_Boolean rval; 5184 HHOOK hook; 5185 DWORD thread_id; 5186 5187 /* Get the current working directory: */ 5188 szDirName[0] = '\0'; 5189 _getcwd(szDirName, sizeof (szDirName)); 5190 szFile [0] = '\0'; 5191 Nlm_CopyDefaultName ((Nlm_CharPtr) szFile, dfault); 5192 Nlm_StringCpy (szFilter, "All Files (*.*)|*.*|"); 5193 cbString = (UINT) Nlm_StringLen (szFilter); 5194 chReplace = szFilter [cbString - 1]; 5195 for (i = 0; szFilter [i] != '\0'; i++) { 5196 if (szFilter [i] == chReplace) { 5197 szFilter [i] = '\0'; 5198 } 5199 } 5200 memset (&ofn, 0, sizeof (OPENFILENAME)); 5201 ofn.lStructSize = sizeof (OPENFILENAME); 5202 ofn.hwndOwner = Nlm_currentHWnd; 5203 ofn.lpstrFilter = szFilter; 5204 ofn.lpstrFile = szFile; 5205 ofn.nMaxFile = sizeof (szFile); 5206 ofn.lpstrFileTitle = szFileTitle; 5207 ofn.nMaxFileTitle = sizeof (szFileTitle); 5208 ofn.lpstrInitialDir = szDirName; 5209 /* 5210 ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT; 5211 */ 5212 /* OFN_OVERWRITEPROMPT causes crashes for some unknown reason */ 5213 ofn.Flags = OFN_SHOWHELP | OFN_NOCHANGEDIR; 5214 5215 /* turn off tooltips, because they were causing Windows 2000 to crash when opening desktop files */ 5216 thread_id = GetCurrentThreadId(); 5217 hook = SetWindowsHookEx (WH_CALLWNDPROC, StopToolTips, NULL, thread_id); 5218 5219 if (GetSaveFileName (&ofn) && fileName != NULL) { 5220 Nlm_StringNCpy_0(fileName, ofn.lpstrFile, maxsize); 5221 AnsiToOemBuff (fileName, fileName, maxsize); 5222 if (Nlm_FileLengthEx(fileName) != -1) { 5223 if (Nlm_Message (MSG_YN, "Replace existing file?") == ANS_NO) { 5224 rval = FALSE; 5225 } else { 5226 rval = TRUE; 5227 } 5228 } else { 5229 rval = TRUE; 5230 } 5231 } else { 5232 rval = FALSE; 5233 } 5234 UnhookWindowsHookEx (hook); 5235 return rval; 5236 5237 #endif 5238 5239 #ifdef WIN_MOTIF 5240 char *lastSlash; 5241 char str [256]; 5242 char *text; 5243 Widget txt; 5244 char *lastDot; 5245 XmString dirmask; 5246 5247 Nlm_CreateFileDialogShell (); 5248 if (Nlm_fileDialogShell != NULL && fileName != NULL) { 5249 if (fileDialog == NULL) { 5250 Cardinal n = 0; 5251 Arg wargs[4]; 5252 XtSetArg (wargs[n], XmNcolormap, Nlm_VibrantDefaultColormap()); n++; 5253 XtSetArg (wargs[n], XmNvisual, Nlm_VibrantDefaultVisual ()); n++; 5254 XtSetArg (wargs[n], XmNdepth, Nlm_VibrantDefaultDepth ()); n++; 5255 fileDialog = XmCreateFileSelectionDialog (Nlm_fileDialogShell, 5256 (String) "file_selection", wargs, n); 5257 XtAddCallback (fileDialog, XmNcancelCallback, Nlm_FileCancelCallback, NULL); 5258 XtAddCallback (fileDialog, XmNokCallback, Nlm_FileOkCallback, NULL); 5259 XtAddCallback (fileDialog, XmNnoMatchCallback, Nlm_FileNoMatchCallback, NULL); 5260 XtAddCallback (fileDialog, XmNmapCallback, Nlm_FileMapCallback, NULL); 5261 XtVaSetValues (fileDialog, XmNdefaultPosition, FALSE, 5262 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL); 5263 } 5264 if (fileDialog != NULL) { 5265 txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_FILTER_TEXT); 5266 text = XmTextGetString (txt); 5267 Nlm_StringNCpy_0(str, text, sizeof(str)); 5268 lastSlash = Nlm_StringRChr (str, DIRDELIMCHR); 5269 if (lastSlash != NULL) { 5270 lastSlash [1] = '\0'; 5271 } 5272 5273 /* V.L. */ 5274 lastDot=dfault ? Nlm_StringRChr(dfault,'.') : (Nlm_CharPtr)NULL; 5275 Nlm_StringNCat(str, "*", sizeof(str) - Nlm_StringLen(str) - 1); 5276 if (lastDot) 5277 Nlm_StringNCat(str, lastDot, sizeof(str) - Nlm_StringLen(str) - 1); 5278 dirmask = XmStringCreateLtoR (str, XmSTRING_DEFAULT_CHARSET); 5279 XmFileSelectionDoSearch (fileDialog, dirmask); 5280 XmStringFree (dirmask); 5281 if (lastSlash != NULL) { 5282 lastSlash [1] = '\0'; 5283 } 5284 5285 XtFree (text); 5286 if (dfault != NULL) { 5287 Nlm_StringNCat(str, dfault, sizeof(str) - Nlm_StringLen(str) - 1); 5288 } 5289 txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_TEXT); 5290 XmTextSetString (txt, str); 5291 XtVaSetValues (fileDialog, XmNmustMatch, FALSE, NULL); 5292 fileBoxUp = TRUE; 5293 fileBoxRsult = FALSE; 5294 XtManageChild (fileDialog); 5295 while (fileBoxUp) { 5296 XEvent event; 5297 XPeekEvent(Nlm_currentXDisplay, &event); 5298 Nlm_ProcessAnEvent (); 5299 } 5300 if (fileBoxRsult) { 5301 Nlm_StringNCpy_0(fileName, filePath, maxsize); 5302 } 5303 XtUnmanageChild (fileDialog); 5304 } 5305 } 5306 return fileBoxRsult; 5307 #endif 5308 } 5309 5310 extern Nlm_Boolean Nlm_LaunchAppEx (Nlm_CharPtr fileName, Nlm_VoidPtr serialNumPtr, Nlm_CharPtr sig); 5311 extern Nlm_Boolean Nlm_LaunchAppEx (Nlm_CharPtr fileName, Nlm_VoidPtr serialNumPtr, Nlm_CharPtr sig) 5312 5313 { 5314 #ifdef WIN_MAC 5315 #ifdef OS_UNIX_DARWIN 5316 OSErr err; 5317 Nlm_Boolean rsult = FALSE; 5318 OSType appCreator = 0; 5319 CFStringRef appName = NULL; 5320 FSRef appRef; 5321 5322 if (fileName != NULL && fileName [0] != '\0') { 5323 appName = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingMacRoman); 5324 } 5325 if (sig != NULL && sig [0] != '\0') { 5326 appCreator = *(OSType*) sig; 5327 } 5328 if (appCreator == 0 && appName == NULL) 5329 return rsult; 5330 5331 err = LSFindApplicationForInfo( appCreator, NULL, appName, &appRef, NULL); 5332 if (err == noErr) { 5333 err = LSOpenFSRef(&appRef, NULL); 5334 rsult = (err == noErr); 5335 } 5336 return rsult; 5337 5338 #else 5339 OSErr err; 5340 Nlm_Boolean rsult = FALSE; 5341 FSSpec fsspec; 5342 long gval; 5343 LaunchParamBlockRec myLaunchParams; 5344 Nlm_Boolean okay = FALSE; 5345 unsigned char pathname [256]; 5346 ProcessSerialNumberPtr psnp; 5347 Nlm_CharPtr ptr; 5348 OSType theSignature; 5349 ProcessSerialNumber psn; 5350 ProcessInfoRec pir; 5351 Nlm_Boolean found; 5352 DTPBRec dtpb; 5353 short ioDTRefNum; 5354 long dirID; 5355 short vRefNum; 5356 long ioAPPLParID; 5357 5358 if (Gestalt (gestaltSystemVersion, &gval) == noErr && (short) gval >= 7 * 256) { 5359 if (fileName != NULL && fileName [0] != '\0') { 5360 if (Nlm_StringChr (fileName, DIRDELIMCHR) != NULL) { 5361 Nlm_StringNCpy_0((Nlm_CharPtr)pathname, fileName, sizeof(pathname)); 5362 } else { 5363 Nlm_ProgramPath ((Nlm_CharPtr) pathname, sizeof (pathname)); 5364 ptr = Nlm_StringRChr ((Nlm_CharPtr) pathname, DIRDELIMCHR); 5365 if (ptr != NULL) { 5366 *ptr = '\0'; 5367 } 5368 Nlm_FileBuildPath ((Nlm_CharPtr) pathname, NULL, fileName); 5369 } 5370 Nlm_CtoPstr ((Nlm_CharPtr) pathname); 5371 err = FSMakeFSSpec (0, 0, pathname, &(fsspec)); 5372 okay = (Nlm_Boolean) (err == noErr); 5373 } else if (sig != NULL && sig [0] != '\0') { 5374 theSignature = *(OSType*) sig; 5375 psn.highLongOfPSN = 0; 5376 psn.lowLongOfPSN = kNoProcess; 5377 found = FALSE; 5378 while (GetNextProcess (&psn) != noErr) { 5379 if (GetProcessInformation (&psn, &pir) != noErr) { 5380 if (pir.processSignature == theSignature) { 5381 found = TRUE; 5382 } 5383 } 5384 } 5385 if (found) return TRUE; /* no need to launch if already running */ 5386 if (! found) { 5387 err = FindFolder (kOnSystemDisk, kTemporaryFolderType, 5388 kCreateFolder, &vRefNum, &dirID); 5389 if (err == noErr) { 5390 memset (&dtpb, 0, sizeof (DTPBRec)); 5391 dtpb.ioNamePtr = NULL; 5392 dtpb.ioVRefNum = vRefNum; 5393 err = PBDTGetPath (&dtpb); 5394 if (err == noErr) { 5395 ioDTRefNum = dtpb.ioDTRefNum; 5396 if (ioDTRefNum != 0) { 5397 memset (&dtpb, 0, sizeof (DTPBRec)); 5398 dtpb.ioDTRefNum = ioDTRefNum; 5399 dtpb.ioFileCreator = theSignature; 5400 dtpb.ioNamePtr = (StringPtr) pathname; 5401 dtpb.ioIndex = 0; 5402 memset (&pathname, 0, sizeof (pathname)); 5403 err = PBDTGetAPPL (&dtpb, FALSE); 5404 if (err == noErr) { 5405 ioAPPLParID = dtpb.ioAPPLParID; 5406 if (pathname [0] != '\0') { 5407 err = FSMakeFSSpec (vRefNum, ioAPPLParID, 5408 (ConstStr255Param) pathname, &fsspec); 5409 okay = (Nlm_Boolean) (err == noErr); 5410 } 5411 } 5412 } 5413 } 5414 } 5415 } 5416 } 5417 if (okay) { 5418 myLaunchParams.launchBlockID = extendedBlock; 5419 myLaunchParams.launchEPBLength = extendedBlockLen; 5420 myLaunchParams.launchFileFlags = 0; 5421 myLaunchParams.launchControlFlags = launchContinue + launchNoFileFlags; 5422 myLaunchParams.launchAppParameters = NULL; 5423 myLaunchParams.launchAppSpec = &fsspec; 5424 rsult = (Nlm_Boolean) (LaunchApplication (&myLaunchParams) == noErr); 5425 if (serialNumPtr != NULL) { 5426 psnp = (ProcessSerialNumberPtr) serialNumPtr; 5427 *psnp = myLaunchParams.launchProcessSN; 5428 } 5429 SetFrontProcess (&myLaunchParams.launchProcessSN); 5430 } 5431 } 5432 return rsult; 5433 #endif /* OS_UNIX_DARWIN */ 5434 #endif /* WIN_MAC */ 5435 #ifdef WIN_MSWIN 5436 Nlm_Char ch; 5437 Nlm_Int2 i; 5438 Nlm_Int2 j; 5439 Nlm_Int2 k; 5440 char lpszCmdLine [256]; 5441 Nlm_Boolean rsult; 5442 5443 rsult = FALSE; 5444 if (fileName != NULL && fileName [0] != '\0') { 5445 Nlm_StringNCpy_0((Nlm_CharPtr)lpszCmdLine, fileName, sizeof(lpszCmdLine)); 5446 i = 0; 5447 j = 0; 5448 k = 0; 5449 ch = fileName [j]; 5450 while (i < 8 && ch != '\0') { 5451 if (ch == '_' || IS_ALPHANUM (ch)) { 5452 lpszCmdLine [k] = ch; 5453 j++; 5454 k++; 5455 ch = fileName [j]; 5456 } 5457 i++; 5458 } 5459 while (ch != '\0' && ch != '.') { 5460 j++; 5461 ch = fileName [j]; 5462 } 5463 if (ch == '.') { 5464 lpszCmdLine [k] = ch; 5465 j++; 5466 k++; 5467 ch = fileName [j]; 5468 i = 0; 5469 while (i < 3 && ch != '\0') { 5470 if (ch == '_' || IS_ALPHANUM (ch)) { 5471 lpszCmdLine [k] = ch; 5472 j++; 5473 k++; 5474 ch = fileName [j]; 5475 } 5476 i++; 5477 } 5478 } 5479 if (k > 0 && lpszCmdLine [k - 1] == '.') { 5480 lpszCmdLine [k - 1] = '\0'; 5481 } 5482 lpszCmdLine [k] = '\0'; 5483 rsult = (Nlm_Boolean) (WinExec (lpszCmdLine, SW_SHOW) >= 32); 5484 } 5485 return rsult; 5486 #endif 5487 #ifdef WIN_MOTIF 5488 Nlm_Boolean rsult; 5489 int status; 5490 5491 rsult = FALSE; 5492 if (fileName != NULL && fileName [0] != '\0') { 5493 #ifdef OS_UNIX 5494 status = (int) fork (); 5495 if (status == 0) { 5496 execlp (fileName, fileName, (char *) 0); 5497 Nlm_Message (MSG_FATAL, "Application launch failed"); 5498 } else if (status != -1) { 5499 rsult = TRUE; 5500 } 5501 #endif 5502 #ifdef OS_VMS 5503 status = execl (fileName, fileName, (char *) 0); 5504 if ( status == -1 ) { 5505 Nlm_Message (MSG_FATAL, "Application launch failed"); 5506 } else { 5507 rsult = TRUE; 5508 } 5509 #endif 5510 } 5511 return rsult; 5512 #endif 5513 } 5514 5515 extern Nlm_Boolean Nlm_LaunchApp (Nlm_CharPtr fileName) 5516 5517 { 5518 return Nlm_LaunchAppEx (fileName, NULL, NULL); 5519 } 5520 5521 5522 extern Nlm_Boolean Nlm_Execv(const Nlm_Char* path, Nlm_Char *const *argv) 5523 { 5524 if (!path || !*path) 5525 return FALSE; 5526 5527 #if defined(WIN_MSWIN) 5528 {{ 5529 int argc; 5530 char cmdline[256]; 5531 5532 size_t len = Nlm_StrLen(path); 5533 for (argc = 0; argv[argc]; argc++) { 5534 len += 1 + Nlm_StrLen(argv[argc]); 5535 } 5536 if (len >= sizeof(cmdline)) { 5537 Nlm_Message(MSG_ERROR, "Nlm_Execv() failed: command line is too long"); 5538 return FALSE; 5539 } 5540 5541 Nlm_StrCpy(cmdline, path); 5542 for (argc = 0; argv[argc]; argc++) { 5543 Nlm_StrCat(cmdline, " "); 5544 Nlm_StrCat(cmdline, argv[argc]); 5545 } 5546 ASSERT( StrLen(cmdline) < sizeof(cmdline) ); 5547 5548 return (Nlm_Boolean)(WinExec(cmdline, SW_SHOW) > 31); 5549 }} 5550 5551 #elif defined(OS_UNIX) 5552 {{ 5553 int fork_code; 5554 /* Attention! 5555 * -- do not move this code to the "child part"; 5556 * it's tempting, but dangerous in the case of MT applications! 5557 */ 5558 int x_argc; 5559 char **x_argv; 5560 for (x_argc = 0; argv[x_argc]; x_argc++) continue; 5561 x_argv = (char**)Nlm_MemNew((1 + x_argc + 1) * sizeof(char*)); 5562 x_argv[0] = (char *)path; 5563 Nlm_MemCpy(&x_argv[1], &argv[0], (x_argc + 1) * sizeof(char*)); 5564 5565 /* Fork the process 5566 */ 5567 #ifdef SOLARIS_THREADS_AVAIL 5568 fork_code = fork1(); 5569 #else 5570 fork_code = fork(); 5571 #endif 5572 5573 /* Child 5574 */ 5575 if (fork_code == 0) { 5576 execv(path, x_argv); 5577 Nlm_Message(MSG_FATAL, "Nlm_Execv() failed: cannot execv()"); 5578 ASSERT( 0 ); 5579 return FALSE; 5580 } 5581 5582 /* Parent 5583 */ 5584 Nlm_MemFree(x_argv); 5585 if (fork_code == -1) { 5586 Nlm_Message(MSG_ERROR, "Nlm_Execv() failed: cannot fork()"); 5587 return FALSE; 5588 } 5589 return TRUE; 5590 }} 5591 5592 #else 5593 return FALSE; 5594 #endif 5595 } 5596 5597 5598 /* ++dgg -- added by d.gilbert, dec'93, for use w/ DCLAP c++ library */ 5599 5600 extern void Nlm_SetObject (Nlm_GraphiC a, Nlm_VoidPtr thisobject) 5601 { 5602 Nlm_GraphicData gdata; 5603 if (a != NULL && thisobject != NULL) { 5604 Nlm_GetGraphicData (a, &gdata); 5605 gdata.thisobject = thisobject; 5606 Nlm_SetGraphicData (a, &gdata); 5607 } 5608 } 5609 5610 extern Nlm_VoidPtr Nlm_GetObject (Nlm_GraphiC a) 5611 { 5612 Nlm_GraphicData gdata; 5613 if (a != NULL) { 5614 Nlm_GetGraphicData (a, &gdata); 5615 return gdata.thisobject; 5616 } else { 5617 return NULL; 5618 } 5619 } 5620 5621 #ifdef WIN_MAC 5622 extern void Nlm_SendOpenDocAppleEventEx (Nlm_CharPtr datafile, Nlm_CharPtr sig, Nlm_CharPtr prog, Nlm_Boolean wantReply) 5623 5624 { 5625 long gval; 5626 OSErr theErr = noErr; 5627 AEAddressDesc theAddress; 5628 AEDesc docDesc; 5629 AppleEvent theEvent; 5630 AppleEvent theReply; 5631 OSType theSignature; 5632 AEDescList theList; 5633 CFURLRef cfurl; 5634 ProcessSerialNumber psn; 5635 Nlm_Boolean okay = FALSE; 5636 5637 if (Gestalt (gestaltSystemVersion, &gval) == noErr && (short) gval >= 7 * 256) { 5638 theSignature = 'RSML'; 5639 if (sig != NULL && sig [0] != '\0') { 5640 theSignature = *(OSType*) sig; 5641 } 5642 if (prog != NULL && prog [0] != '\0') { 5643 if (Nlm_LaunchAppEx (prog, (Nlm_VoidPtr) &psn, NULL)) { 5644 theErr = AECreateDesc(typeProcessSerialNumber, (Ptr)&psn, 5645 sizeof(psn), &theAddress); 5646 okay = (Nlm_Boolean) (theErr == noErr); 5647 } 5648 } else if (sig != NULL && sig [0] != '\0') { 5649 if (Nlm_LaunchAppEx (prog, NULL, sig)) { 5650 theSignature = *(OSType*) sig; 5651 theErr = AECreateDesc(typeApplSignature, (Ptr)&theSignature, 5652 sizeof(theSignature), &theAddress); 5653 okay = (Nlm_Boolean) (theErr == noErr); 5654 } 5655 } 5656 if (okay) { 5657 theErr = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments, &theAddress, 5658 kAutoGenerateReturnID, kAnyTransactionID, &theEvent); 5659 if (theErr == noErr) { 5660 theErr = AECreateList(NULL, 0, FALSE, &theList); 5661 if (theErr == noErr) { 5662 cfurl = CFURLCreateFromFileSystemRepresentation (NULL, (const UInt8 *)datafile, strlen (datafile), 0); 5663 if (cfurl) { 5664 CFDataRef cfdata = CFURLCreateData (NULL, cfurl, kCFStringEncodingUTF8, 1); 5665 theErr = AECreateDesc(typeFileURL, CFDataGetBytePtr (cfdata), CFDataGetLength (cfdata), &docDesc); 5666 CFRelease (cfdata); 5667 if (theErr == noErr) { 5668 theErr = AEPutDesc(&theList, 0, &docDesc); 5669 if (theErr == noErr) { 5670 theErr = AEPutParamDesc(&theEvent, keyDirectObject, &theList); 5671 if (theErr == noErr) { 5672 if (wantReply) { 5673 AESend (&theEvent, &theReply, kAEQueueReply, kAENormalPriority, 120, NULL, NULL); 5674 } else { 5675 AESend (&theEvent, &theReply, kAENoReply, kAENormalPriority, 120, NULL, NULL); 5676 } 5677 } 5678 } 5679 AEDisposeDesc(&docDesc); 5680 } 5681 } 5682 AEDisposeDesc(&theList); 5683 } 5684 AEDisposeDesc(&theEvent); 5685 } 5686 AEDisposeDesc(&theAddress); 5687 } 5688 } 5689 } 5690 5691 extern void Nlm_SendOpenDocAppleEvent (Nlm_CharPtr datafile, Nlm_CharPtr sig) 5692 5693 { 5694 Nlm_SendOpenDocAppleEventEx (datafile, sig, NULL, FALSE); 5695 } 5696 5697 extern void Nlm_SendURLAppleEvent (Nlm_CharPtr urlString, Nlm_CharPtr sig, Nlm_CharPtr prog) 5698 5699 { 5700 #ifdef OS_UNIX_DARWIN 5701 OSStatus err; 5702 CFURLRef urlRef; 5703 5704 /* on OS X ignore the sig and prog and open the url with the default browser */ 5705 urlRef = CFURLCreateWithBytes (NULL, (const UInt8 *) urlString, Nlm_StrLen( urlString), kCFStringEncodingMacRoman, NULL); 5706 err = LSOpenCFURLRef(urlRef, NULL); 5707 5708 #else 5709 long gval; 5710 OSErr theErr = noErr; 5711 AEAddressDesc theAddress; 5712 AEDesc urlEvent; 5713 AppleEvent theEvent; 5714 AppleEvent theReply; 5715 OSType theSignature; 5716 ProcessSerialNumber psn; 5717 Nlm_Boolean okay = FALSE; 5718 5719 if (Gestalt (gestaltSystemVersion, &gval) == noErr && (short) gval >= 7 * 256) { 5720 theSignature = 'RSML'; 5721 if (sig != NULL && sig [0] != '\0') { 5722 theSignature = *(OSType*) sig; 5723 } 5724 if (prog != NULL && prog [0] != '\0') { 5725 if (Nlm_LaunchAppEx (prog, (Nlm_VoidPtr) &psn, NULL)) { 5726 theErr = AECreateDesc(typeProcessSerialNumber, (Ptr)&psn, 5727 sizeof(psn), &theAddress); 5728 okay = (Nlm_Boolean) (theErr == noErr); 5729 } 5730 } else if (sig != NULL && sig [0] != '\0') { 5731 if (Nlm_LaunchAppEx (prog, NULL, sig)) { 5732 theSignature = *(OSType*) sig; 5733 theErr = AECreateDesc(typeApplSignature, (Ptr)&theSignature, 5734 sizeof(theSignature), &theAddress); 5735 okay = (Nlm_Boolean) (theErr == noErr); 5736 } 5737 } 5738 if (okay) { 5739 theErr = AECreateAppleEvent('WWW!', 'OURL', &theAddress, 5740 kAutoGenerateReturnID, kAnyTransactionID, &theEvent); 5741 if (theErr == noErr) { 5742 theErr = AECreateDesc(typeChar, urlString, Nlm_StringLen (urlString), &urlEvent); 5743 if (theErr == noErr) { 5744 theErr = AEPutParamDesc(&theEvent, keyDirectObject, &urlEvent); 5745 if (theErr == noErr) { 5746 AESend (&theEvent, &theReply, kAEWaitReply, kAEHighPriority, 500, NULL, NULL); 5747 AEDisposeDesc(&theReply); 5748 } 5749 AEDisposeDesc(&urlEvent); 5750 } 5751 AEDisposeDesc(&theEvent); 5752 } 5753 AEDisposeDesc(&theAddress); 5754 } 5755 } 5756 #endif 5757 } 5758 5759 5760 /* Modified from http://developer.apple.com/qa/qa2001/qa1026.html */ 5761 5762 #if TARGET_API_MAC_CARBON 5763 #ifdef __APPLE_CC__ 5764 #include <Carbon/Carbon.h> 5765 #else 5766 #include <Carbon.h> 5767 #endif 5768 #else 5769 #include <Types.h> 5770 #include <OSA.h> 5771 #include <AppleScript.h> 5772 #endif 5773 #include <string.h> 5774 /* LowRunAppleScript compiles and runs an AppleScript 5775 provided as text in the buffer pointed to by text. textLength 5776 bytes will be compiled from this buffer and run as an AppleScript 5777 using all of the default environment and execution settings. If 5778 resultData is not NULL, then the result returned by the execution 5779 command will be returned as typeChar in this descriptor record 5780 (or typeNull if there is no result information). If the function 5781 returns errOSAScriptError, then resultData will be set to a 5782 descriptive error message describing the error (if one is 5783 available). */ 5784 5785 static OSStatus LowRunAppleScript ( 5786 const void* text, 5787 long textLength, 5788 AEDesc *resultData 5789 ) 5790 5791 { 5792 ComponentInstance theComponent; 5793 AEDesc scriptTextDesc; 5794 OSStatus err; 5795 OSAID scriptID, resultID; 5796 5797 /* set up locals to a known state */ 5798 theComponent = NULL; 5799 AECreateDesc (typeNull, NULL, 0, &scriptTextDesc); 5800 scriptID = kOSANullScript; 5801 resultID = kOSANullScript; 5802 5803 /* open the scripting component */ 5804 theComponent = OpenDefaultComponent (kOSAComponentType, typeAppleScript); 5805 if (theComponent == NULL) { 5806 err = paramErr; 5807 goto bail; 5808 } 5809 5810 /* put the script text into an aedesc */ 5811 err = AECreateDesc (typeChar, text, textLength, &scriptTextDesc); 5812 if (err != noErr) goto bail; 5813 5814 /* compile the script */ 5815 err = OSACompile (theComponent, &scriptTextDesc, kOSAModeNull, &scriptID); 5816 if (err != noErr) goto bail; 5817 5818 /* run the script */ 5819 err = OSAExecute (theComponent, scriptID, kOSANullScript, kOSAModeNull, &resultID); 5820 5821 /* collect the results - if any */ 5822 if (resultData != NULL) { 5823 AECreateDesc (typeNull, NULL, 0, resultData); 5824 if (err == errOSAScriptError) { 5825 OSAScriptError (theComponent, kOSAErrorMessage, typeChar, resultData); 5826 } else if (err == noErr && resultID != kOSANullScript) { 5827 OSADisplay (theComponent, resultID, typeChar, kOSAModeNull, resultData); 5828 } 5829 } 5830 bail: 5831 AEDisposeDesc (&scriptTextDesc); 5832 if (scriptID != kOSANullScript) OSADispose (theComponent, scriptID); 5833 if (resultID != kOSANullScript) OSADispose (theComponent, resultID); 5834 if (theComponent != NULL) CloseComponent (theComponent); 5835 return err; 5836 } 5837 5838 5839 extern void Nlm_SendAppleScriptString (Nlm_CharPtr script) 5840 5841 { 5842 if (Nlm_StringHasNoText (script)) return; 5843 LowRunAppleScript ((const char*) script, Nlm_StringLen (script), NULL); 5844 } 5845 5846 5847 extern void Nlm_GetFileTypeAndCreator (Nlm_CharPtr filename, Nlm_CharPtr type, Nlm_CharPtr creator); 5848 #if TARGET_API_MAC_CARBON 5849 extern void Nlm_GetFileTypeAndCreator (Nlm_CharPtr filename, Nlm_CharPtr type, Nlm_CharPtr creator) 5850 { 5851 OSType fCreator; 5852 Nlm_Int2 fError; 5853 FInfo fInfo; 5854 OSType fType; 5855 Nlm_Char temp [256]; 5856 5857 if (type != NULL) { 5858 *type = '\0'; 5859 } 5860 if (creator != NULL) { 5861 *creator = '\0'; 5862 } 5863 Nlm_StringNCpy_0 (temp, filename, sizeof(temp)); 5864 Nlm_CtoPstr ((Nlm_CharPtr) temp); 5865 fError = HGetFInfo ( 0, 0, (StringPtr) temp, &fInfo); 5866 if (fError == 0) { 5867 fType = fInfo.fdType; 5868 fCreator = fInfo.fdCreator; 5869 StringNCpy_0 (type, (Nlm_CharPtr) (&fType), 5); 5870 StringNCpy_0 (creator, (Nlm_CharPtr) (&fCreator), 5); 5871 } 5872 } 5873 5874 #else 5875 extern void Nlm_GetFileTypeAndCreator (Nlm_CharPtr filename, Nlm_CharPtr type, Nlm_CharPtr creator) 5876 { 5877 OSStatus err; 5878 FSRef fsref; 5879 FSCatalogInfo catinfo; 5880 5881 if (type != NULL) { 5882 *type = '\0'; 5883 } 5884 if (creator != NULL) { 5885 *creator = '\0'; 5886 } 5887 5888 err = FSPathMakeRef ((const UInt8 *)filename, &fsref, NULL); 5889 if (err) 5890 return; 5891 5892 err = FSGetCatalogInfo (&fsref, kFSCatInfoGettableInfo, &catinfo, NULL, NULL, NULL); 5893 5894 if (err == noErr && (catinfo.nodeFlags & kFSNodeIsDirectoryMask) == 0) 5895 { 5896 FileInfo finfo; 5897 memcpy(&finfo, &catinfo.finderInfo, sizeof(finfo)); 5898 5899 if (type) 5900 { 5901 *type = htonl (finfo.fileType); 5902 type[4] = 0; 5903 } 5904 if (creator) 5905 { 5906 *(Nlm_Int4 *)creator = htonl (finfo.fileCreator); 5907 creator[4] = 0; 5908 } 5909 } 5910 } 5911 #endif 5912 #endif 5913 5914 5915 #ifdef WIN_MSWIN 5916 extern Nlm_Boolean Nlm_MSWin_OpenDocument(const Nlm_Char* doc_name) 5917 { 5918 int status = (int)ShellExecute(0, "open", doc_name, 5919 NULL, NULL, SW_SHOWNORMAL); 5920 if (status <= 32) { 5921 Nlm_ErrPostEx(SEV_WARNING, 0, 0, 5922 "Unable to open document \"%s\", error=%d", 5923 doc_name, status); 5924 return FALSE; 5925 } 5926 return TRUE; 5927 } 5928 5929 extern Nlm_Boolean Nlm_MSWin_OpenApplication(const Nlm_Char* program, const Nlm_Char* parameters) 5930 { 5931 int status = (int)ShellExecute(0, "open", program, 5932 parameters, NULL, SW_SHOWNORMAL); 5933 if (status <= 32) { 5934 Nlm_ErrPostEx(SEV_WARNING, 0, 0, 5935 "Unable to open document, error=%d", status); 5936 return FALSE; 5937 } 5938 return TRUE; 5939 } 5940 5941 /***************************************************************************** 5942 5943 Function: Nlm_GetExecPath() 5944 5945 Purpose: Gets the path for an executable under Windows 5946 5947 Parameters: filetype: the name of the filetype (e.g. "valfile" for Cn3D) 5948 buf: the buffer to put the path into 5949 buflen: the length of buf 5950 5951 5952 *****************************************************************************/ 5953 5954 extern void Nlm_GetExecPath(char *filetype, char *buf, int buflen) 5955 { 5956 HKEY hkResult; 5957 int i; 5958 char key[256]; 5959 DWORD len; 5960 5961 if(buf == NULL || filetype == NULL || buflen < 1) return; 5962 if(strlen(filetype)>220) return; 5963 key[0] = '\0'; 5964 strcat(key, filetype); 5965 strcat(key, "\\Shell\\open\\command"); 5966 RegOpenKeyEx(HKEY_CLASSES_ROOT, key, 0, KEY_READ, 5967 &hkResult); 5968 if(hkResult == NULL) { 5969 buf[0] = '\0'; 5970 return; 5971 } 5972 5973 len = (DWORD) buflen; 5974 RegQueryValueEx(hkResult,"", NULL, NULL, (LPBYTE) buf, (LPDWORD) &len); 5975 buflen = (int) len; 5976 RegCloseKey(hkResult); 5977 5978 for (i=1; i<buflen && buf[i] != '"'; i++) {} 5979 buf[i-1] = '\0'; 5980 } 5981 5982 #endif 5983 5984 5985 /* esl: ChooseFont implementation */ 5986 5987 #ifdef WIN_MSWIN 5988 5989 static void Nlm_LOGFONTToFontSpec (LOGFONT *lfp, Nlm_FontSpecPtr fsp) 5990 { 5991 if (fsp == NULL || lfp == NULL) return; 5992 5993 /* size */ 5994 if (lfp->lfHeight == 0) { /* lfHeight is not specified */ 5995 fsp->size = 12; /* use default height */ 5996 } else { 5997 int sizelp; /* size in logical points */ 5998 if (lfp->lfHeight < 0) { /* -lfHeight is character height */ 5999 sizelp = -lfp->lfHeight; 6000 } else { /* lfHeight is cell height */ 6001 sizelp = lfp->lfHeight; 6002 sizelp -= sizelp / 10; /* adhoc: 10% for internal leading */ 6003 } 6004 { /* determine size in typographical points */ 6005 HDC hDC = GetDC (NULL); 6006 fsp->size = (Nlm_Int2)MulDiv(sizelp, 72, GetDeviceCaps(hDC, LOGPIXELSY)); 6007 ReleaseDC (NULL, hDC); 6008 } 6009 } 6010 6011 { /* style */ 6012 int style = 0; 6013 if (lfp->lfWeight > 600) style |= STYLE_BOLD; 6014 if (lfp->lfItalic != 0) style |= STYLE_ITALIC; 6015 if (lfp->lfUnderline != 0) style |= STYLE_UNDERLINE; 6016 if (lfp->lfStrikeOut != 0) style |= 128; /* Windows-specific */ 6017 fsp->style = (Nlm_Uint1)style; 6018 } 6019 6020 /* character set */ 6021 switch (lfp->lfCharSet) { 6022 case SYMBOL_CHARSET: fsp->charset = CHARSET_SYMBOL; break; 6023 case ANSI_CHARSET: fsp->charset = CHARSET_ANSI; break; 6024 default: fsp->charset = CHARSET_NULL; 6025 } 6026 6027 /* pitch */ 6028 switch (lfp->lfPitchAndFamily & 0x0F) { 6029 case FIXED_PITCH: fsp->pitch = PITCH_FIXED; break; 6030 case VARIABLE_PITCH: fsp->pitch = PITCH_VARIABLE; break; 6031 default: fsp->pitch = PITCH_NULL; 6032 } 6033 6034 /* family */ 6035 switch (lfp->lfPitchAndFamily & 0xF0) { 6036 case FF_ROMAN: fsp->family = FAMILY_ROMAN; break; 6037 case FF_SWISS: fsp->family = FAMILY_SWISS; break; 6038 case FF_MODERN: fsp->family = FAMILY_MODERN; break; 6039 case FF_SCRIPT: fsp->family = FAMILY_SCRIPT; break; 6040 case FF_DECORATIVE: fsp->family = FAMILY_DECORATIVE; break; 6041 default: fsp->family = FAMILY_NULL; 6042 } 6043 6044 /* name */ 6045 Nlm_StringNCpy_0(fsp->name, lfp->lfFaceName, FONT_NAME_SIZE); 6046 } 6047 6048 extern Nlm_Boolean Nlm_ChooseFont (Nlm_FontSpecPtr fsp, 6049 Nlm_Uint2 flags, 6050 Nlm_VoidPtr null) 6051 { 6052 Nlm_Boolean initToFsp = (Nlm_Boolean)((flags & CFF_READ_FSP) != 0); 6053 Nlm_Boolean fixedOnly = (Nlm_Boolean)((flags & CFF_MONOSPACE) != 0); 6054 LOGFONT lf; 6055 CHOOSEFONT cf; 6056 if (fsp == NULL) { /* ERROR */ return FALSE; } 6057 if (initToFsp) Nlm_FontSpecToLOGFONT (fsp, &lf); 6058 memset (&cf, 0, sizeof (CHOOSEFONT)); 6059 cf.lStructSize = sizeof (CHOOSEFONT); 6060 cf.hwndOwner = Nlm_currentHWnd; 6061 cf.hDC = NULL; 6062 cf.lpLogFont = &lf; 6063 cf.Flags = CF_SCREENFONTS | CF_NOVECTORFONTS | CF_EFFECTS; 6064 if (initToFsp) cf.Flags |= CF_INITTOLOGFONTSTRUCT; 6065 if (fixedOnly) cf.Flags |= CF_FIXEDPITCHONLY; 6066 if (ChooseFont (&cf)) { 6067 Nlm_LOGFONTToFontSpec (&lf, fsp); 6068 return TRUE; 6069 } else 6070 return FALSE; 6071 } 6072 6073 #else /* !WIN_MSWIN */ 6074 6075 static Nlm_FontSpec fntDlgFontSpec; 6076 static Nlm_Boolean fntDlgUp; 6077 static Nlm_Boolean fntDlgResult; 6078 #ifdef WIN_MAC 6079 static Nlm_PopuP fntDlgFontList = NULL; 6080 static Nlm_PopuP fntDlgSizeList = NULL; 6081 #endif 6082 #ifdef WIN_MOTIF 6083 static Nlm_LisT fntDlgFontList = NULL; 6084 static Nlm_LisT fntDlgSizeList = NULL; 6085 #endif 6086 static Nlm_ButtoN fntDlgBoldBox = NULL; 6087 static Nlm_ButtoN fntDlgItalicBox = NULL; 6088 static Nlm_ButtoN fntDlgUnderlineBox = NULL; 6089 static Nlm_PaneL fntDlgSample = NULL; 6090 6091 #define NLM_STYLE_BOLD_ON 0x1 6092 #define NLM_STYLE_BOLD_OFF 0x2 6093 #define NLM_STYLE_ITALIC_ON 0x4 6094 #define NLM_STYLE_ITALIC_OFF 0x8 6095 #define NLM_STYLE_UNDERLINE_ON 0x10 6096 #define NLM_STYLE_UNDERLINE_OFF 0x20 6097 6098 static void Nlm_FntDlgDrawSampleProc (Nlm_PaneL p) 6099 { 6100 Nlm_FonT font = Nlm_CreateFont (&fntDlgFontSpec); 6101 Nlm_RecT r; 6102 Nlm_ObjectRect (p, &r); 6103 Nlm_SelectFont (font); 6104 Nlm_DrawString (&r, "The Quick Brown Fox", 'c', FALSE); 6105 Nlm_SelectFont (Nlm_systemFont); 6106 Nlm_DeleteFont (font); 6107 } 6108 6109 static void Nlm_FntDlgRedrawSample (void) 6110 { 6111 Nlm_RecT r; 6112 Nlm_WindoW tmpPort; 6113 6114 Nlm_ObjectRect (fntDlgSample, &r); 6115 tmpPort = Nlm_SavePort (fntDlgSample); 6116 Nlm_Select (fntDlgSample); 6117 Nlm_InvalRect (&r); 6118 Nlm_RestorePort (tmpPort); 6119 } 6120 6121 /* simple font name/size enum interface (platform-dependent) */ 6122 /* alexs (01-16-95): add platform-dependent for MAC */ 6123 #ifdef WIN_MAC 6124 6125 MenuHandle menuHforFontList; 6126 6127 static Nlm_Int2 Nlm_FntDlgGetSysFontList (Nlm_Boolean monoSpace) 6128 { 6129 CreateNewMenu (100, 0, &menuHforFontList); 6130 CreateStandardFontMenu (menuHforFontList, 0, 0, 0, NULL); 6131 6132 if (monoSpace) 6133 { 6134 int item; 6135 int size; 6136 char *name; 6137 Nlm_FonT font; 6138 int i; 6139 int M; 6140 int s; 6141 6142 for (item = CountMenuItems (menuHforFontList); item > 0; item--) 6143 { 6144 CFStringRef cfname = NULL; 6145 CopyMenuItemTextAsCFString (menuHforFontList, item, &cfname); 6146 6147 size = CFStringGetMaximumSizeForEncoding (CFStringGetLength (cfname), kCFStringEncodingUTF8); 6148 name = malloc (size + 1); 6149 CFStringGetCString (cfname, name, size + 1, kCFStringEncodingUTF8); 6150 6151 font = Nlm_GetFont (name, 12, 0, 0, 0, ""); 6152 6153 i = Nlm_CharWidth ('i'); 6154 M = Nlm_CharWidth ('M'); 6155 s = Nlm_CharWidth (' '); 6156 if( i != M || i != s ) 6157 DeleteMenuItem (menuHforFontList, item); 6158 6159 free (name); 6160 CFRelease (cfname); 6161 } 6162 } 6163 6164 return CountMenuItems (menuHforFontList); 6165 } 6166 6167 static void Nlm_FntDlgGetSysFontName (Nlm_Int2 n, Nlm_CharPtr buf, 6168 Nlm_Int2 blen) 6169 { 6170 char fontName[256]; 6171 6172 GetMenuItemText ( menuHforFontList, n+1, (StringPtr) fontName ); 6173 Nlm_PtoCstr ( fontName ); 6174 Nlm_StringNCpy_0(buf, fontName, blen); 6175 } 6176 6177 static Nlm_Byte fontSizes [] = {9, 10, 12, 14, 18, 20, 24, 36}; 6178 static Nlm_Int2 fontSizesCnt = sizeof(fontSizes) / sizeof(fontSizes[0]); 6179 6180 static Nlm_Int2 Nlm_FntDlgGetSysFontSize (Nlm_Int2 n, 6181 Nlm_BytePtr PNTR sizePtr ) 6182 { 6183 n = n; 6184 *sizePtr = &(fontSizes[0]); 6185 return fontSizesCnt; 6186 } 6187 6188 static Nlm_Byte Nlm_FntDlgGetSysFontStyle (Nlm_Int2 n) 6189 { 6190 return ( NLM_STYLE_BOLD_ON | 6191 NLM_STYLE_BOLD_OFF | 6192 NLM_STYLE_ITALIC_ON | 6193 NLM_STYLE_ITALIC_OFF | 6194 NLM_STYLE_UNDERLINE_ON | 6195 NLM_STYLE_UNDERLINE_OFF ); 6196 } 6197 6198 static void Nlm_FntDlgFreeSysFontList () 6199 { 6200 DisposeMenu (menuHforFontList); 6201 } 6202 6203 #endif 6204 #ifdef WIN_MOTIF 6205 6206 /* alexs (01-16-95): add platform-dependent for X_WIN */ 6207 #define NLM_X11_MAXSIZECOUNT 64 6208 6209 typedef struct { 6210 Nlm_Char fontName[FONT_NAME_SIZE]; 6211 Nlm_Byte styleInter; 6212 Nlm_Byte sizeFound; 6213 Nlm_Byte sizes[NLM_X11_MAXSIZECOUNT]; 6214 } Nlm_X11_FontDsc, * Nlm_X11_FontDscPtr; 6215 6216 static Nlm_X11_FontDscPtr fontNamesArray = NULL; 6217 6218 static Nlm_Byte Nlm_FntGetFontStyle ( char * fontSpec ) 6219 { 6220 Nlm_Byte fStyle = 0; 6221 6222 fontSpec = Nlm_StringChr ( fontSpec, '-' ); 6223 if ( fontSpec == NULL ) return 0; 6224 fontSpec = Nlm_StringChr ( fontSpec+1, '-'); 6225 if ( fontSpec == NULL ) return 0; 6226 fontSpec = Nlm_StringChr ( fontSpec+1, '-'); 6227 if ( fontSpec == NULL ) return 0; 6228 fontSpec++; 6229 if ( *fontSpec == 'b' ) fStyle |= NLM_STYLE_BOLD_ON; 6230 else fStyle |= NLM_STYLE_BOLD_OFF; 6231 fontSpec = Nlm_StringChr ( fontSpec, '-'); 6232 if ( fontSpec == NULL ) return fStyle; 6233 fontSpec++; 6234 /* VL */ 6235 if ( *fontSpec == 'i' || *fontSpec == 'o' ) fStyle |= NLM_STYLE_ITALIC_ON; 6236 else fStyle |= NLM_STYLE_ITALIC_OFF; 6237 return fStyle; 6238 } 6239 6240 static void Nlm_FntAddSize ( Nlm_X11_FontDscPtr fontDsc, 6241 char * fontSpec ) 6242 { 6243 int i; 6244 int curSize = 12; 6245 char sizeStr[16]; 6246 6247 if ( fontDsc->sizeFound == NLM_X11_MAXSIZECOUNT ) return; 6248 for ( i=0; i<8; i++ ){ 6249 fontSpec = Nlm_StringChr ( fontSpec, '-' ); 6250 if ( fontSpec == NULL ) break; 6251 fontSpec++; 6252 } 6253 if ( fontSpec != NULL ){ 6254 Nlm_StringNCpy_0(sizeStr, fontSpec, sizeof(sizeStr)); 6255 fontSpec = Nlm_StringChr ( sizeStr, '-' ); 6256 if ( fontSpec != NULL ) *fontSpec = '\0'; 6257 curSize = atoi ( sizeStr ) / 10 ; 6258 if ( (curSize <= 0) || (curSize > 128) ) curSize = 12; 6259 } 6260 for ( i=0; i < (int)fontDsc->sizeFound; i++ ){ 6261 if ( curSize == (int)fontDsc->sizes[i] ) break; 6262 if ( curSize < (int)fontDsc->sizes[i] ) { 6263 Nlm_MemMove ( &(fontDsc->sizes[i+1]), &(fontDsc->sizes[i]), 6264 fontDsc->sizeFound - i ); 6265 fontDsc->sizes[i] = (Nlm_Byte)curSize; 6266 fontDsc->sizeFound++; 6267 break; 6268 } 6269 } 6270 if ( i == fontDsc->sizeFound ){ 6271 fontDsc->sizes[fontDsc->sizeFound] = (Nlm_Byte)curSize; 6272 fontDsc->sizeFound++; 6273 } 6274 } 6275 6276 static Nlm_Int2 Nlm_FntDlgGetSysFontList (Nlm_Boolean mono) 6277 { 6278 char ** fontNames; 6279 char * curFontPtr; 6280 Nlm_X11_FontDscPtr curFontDsc; 6281 int fontNamesCount; 6282 int fontsFound = 0; 6283 int i, ifound; 6284 char curFontName[FONT_NAME_SIZE]; 6285 6286 if (mono) { 6287 fontNames = XListFonts ( Nlm_currentXDisplay, 6288 "-*-*-*-*-*-*-*-*-*-M-*", 6289 4096, &fontNamesCount ); 6290 } else { 6291 fontNames = XListFonts ( Nlm_currentXDisplay, 6292 "-*-*-*-*-*-*-*-*-*-*-*", 6293 4096, &fontNamesCount ); 6294 } 6295 if ( fontNames == NULL ) return 0; 6296 fontNamesArray = (Nlm_X11_FontDscPtr)Nlm_MemNew ( 6297 sizeof(Nlm_X11_FontDsc) * fontNamesCount ); 6298 for ( i=0; i<fontNamesCount; i++ ){ 6299 curFontPtr = Nlm_StringChr (fontNames[i], '-' ); 6300 if ( curFontPtr == NULL ) continue; 6301 curFontPtr++; 6302 curFontPtr = Nlm_StringChr (curFontPtr, '-' ); 6303 if ( curFontPtr == NULL ) continue; 6304 curFontPtr++; 6305 Nlm_StringNCpy_0(curFontName, curFontPtr, FONT_NAME_SIZE); 6306 curFontPtr = Nlm_StringChr ( curFontName, '-' ); 6307 if ( curFontPtr != NULL ) *curFontPtr = '\0'; 6308 if ( Nlm_StringLen(curFontName) == 0 ) continue; 6309 for ( ifound = 0, curFontDsc=fontNamesArray; 6310 ifound < fontsFound; 6311 ifound++, curFontDsc ++ ){ 6312 if ( Nlm_StrCmp ( curFontDsc->fontName, curFontName ) == 0 ) { 6313 curFontDsc->styleInter |= Nlm_FntGetFontStyle ( (char*)fontNames[i]) ; 6314 Nlm_FntAddSize ( curFontDsc, (char*)fontNames[i] ); 6315 break; 6316 } 6317 } 6318 if ( ifound == fontsFound ){ 6319 Nlm_StrCpy ( curFontDsc->fontName, curFontName ); 6320 curFontDsc->styleInter = Nlm_FntGetFontStyle ( (char*)fontNames[i]) ; 6321 Nlm_FntAddSize ( curFontDsc, (char*)fontNames[i] ); 6322 fontsFound++; 6323 } 6324 } 6325 XFreeFontNames ( fontNames ); 6326 return fontsFound; 6327 } 6328 6329 static void Nlm_FntDlgGetSysFontName (Nlm_Int2 n, Nlm_CharPtr buf, 6330 Nlm_Int2 blen) 6331 { 6332 Nlm_StringNCpy_0(buf, fontNamesArray[n].fontName, blen); 6333 } 6334 6335 static Nlm_Int2 Nlm_FntDlgGetSysFontSize (Nlm_Int2 n, 6336 Nlm_BytePtr PNTR sizePtr ) 6337 { 6338 *sizePtr = fontNamesArray[n].sizes; 6339 return (fontNamesArray[n].sizeFound ); 6340 } 6341 6342 static Nlm_Byte Nlm_FntDlgGetSysFontStyle (Nlm_Int2 n) 6343 { 6344 return ( fontNamesArray[n].styleInter ); 6345 } 6346 6347 static void Nlm_FntDlgFreeSysFontList(void) 6348 { 6349 if ( fontNamesArray != NULL ){ 6350 Nlm_MemFree ( fontNamesArray ); 6351 fontNamesArray = NULL; 6352 } 6353 } 6354 #endif 6355 6356 /* simple font name/size enum interface (platform-independent) */ 6357 static Nlm_Int2 sysFontCnt; 6358 6359 6360 /* init FontList */ 6361 static void Nlm_FntDlgInitFontList (void) 6362 { 6363 Nlm_Int2 i; 6364 Nlm_Char buf [FONT_NAME_SIZE]; 6365 for (i = 0; i < sysFontCnt; i++) { 6366 Nlm_FntDlgGetSysFontName (i, buf, FONT_NAME_SIZE); 6367 #ifdef WIN_MAC 6368 Nlm_PopupItem (fntDlgFontList, buf); 6369 #endif 6370 #ifdef WIN_MOTIF 6371 Nlm_ListItem (fntDlgFontList, buf); 6372 #endif 6373 } 6374 } 6375 6376 static void Nlm_FntDlgInitSizeList ( Nlm_Int2 n, Nlm_Int2 oldSize ) 6377 { 6378 Nlm_BytePtr sizePtr; 6379 Nlm_Int2 i; 6380 Nlm_Int2 setThis; 6381 Nlm_Int2 fontCnt; 6382 Nlm_Char buf [10]; 6383 6384 fontCnt = Nlm_FntDlgGetSysFontSize ( n, &sizePtr ); 6385 setThis = 0; 6386 for (i = 0; i < fontCnt; i++) { 6387 if ( !setThis ){ 6388 if ( (Nlm_Int2)sizePtr[i] >= oldSize ) setThis = i+1; 6389 } 6390 sprintf (buf, "%d", (int)sizePtr[i]); 6391 #ifdef WIN_MAC 6392 Nlm_PopupItem (fntDlgSizeList, buf); 6393 #endif 6394 #ifdef WIN_MOTIF 6395 Nlm_ListItem (fntDlgSizeList, buf); 6396 #endif 6397 } 6398 if ( !setThis ) setThis = fontCnt; 6399 Nlm_SetValue (fntDlgSizeList, setThis); 6400 } 6401 6402 static void Nlm_FntDlgInitStyles ( Nlm_Int2 n, Nlm_Int2 oldStyle ) 6403 { 6404 Nlm_Byte styles; 6405 6406 styles = Nlm_FntDlgGetSysFontStyle (n); 6407 if ( (styles & NLM_STYLE_BOLD_ON) && (styles & NLM_STYLE_BOLD_OFF) ){ 6408 Nlm_Enable (fntDlgBoldBox); 6409 if ( oldStyle & STYLE_BOLD ){ 6410 Nlm_SetStatus (fntDlgBoldBox, TRUE); 6411 } else { 6412 Nlm_SetStatus (fntDlgBoldBox, FALSE); 6413 } 6414 }else{ 6415 Nlm_Disable (fntDlgBoldBox); 6416 if ( styles & NLM_STYLE_BOLD_ON ){ 6417 Nlm_SetStatus (fntDlgBoldBox, TRUE); 6418 } else { 6419 Nlm_SetStatus (fntDlgBoldBox, FALSE); 6420 } 6421 } 6422 if ( (styles & NLM_STYLE_ITALIC_ON) && (styles & NLM_STYLE_ITALIC_OFF) ){ 6423 Nlm_Enable (fntDlgItalicBox); 6424 if ( oldStyle & STYLE_ITALIC ){ 6425 Nlm_SetStatus (fntDlgItalicBox, TRUE); 6426 } else { 6427 Nlm_SetStatus (fntDlgItalicBox, FALSE); 6428 } 6429 }else{ 6430 Nlm_Disable (fntDlgItalicBox); 6431 if ( styles & NLM_STYLE_ITALIC_ON ){ 6432 Nlm_SetStatus (fntDlgItalicBox, TRUE); 6433 } else { 6434 Nlm_SetStatus (fntDlgItalicBox, FALSE); 6435 } 6436 } 6437 if ( (styles & NLM_STYLE_UNDERLINE_ON) && 6438 (styles & NLM_STYLE_UNDERLINE_OFF) ){ 6439 Nlm_Enable (fntDlgUnderlineBox); 6440 if ( oldStyle & STYLE_UNDERLINE ){ 6441 Nlm_SetStatus (fntDlgUnderlineBox, TRUE); 6442 } else { 6443 Nlm_SetStatus (fntDlgUnderlineBox, FALSE); 6444 } 6445 }else{ 6446 Nlm_Disable (fntDlgUnderlineBox); 6447 if ( styles & NLM_STYLE_UNDERLINE_ON ){ 6448 Nlm_SetStatus (fntDlgUnderlineBox, TRUE); 6449 } else { 6450 Nlm_SetStatus (fntDlgUnderlineBox, FALSE); 6451 } 6452 } 6453 } 6454 6455 static void Nlm_FntDlgUpdate (Nlm_Boolean writep) 6456 { 6457 if (writep) { 6458 Nlm_BytePtr sizes; 6459 Nlm_Int2 i; 6460 Nlm_Int2 sizeCount; 6461 6462 /* name and family/pitch/charset */ 6463 i = Nlm_GetValue (fntDlgFontList); 6464 if (i > 0 && i <= sysFontCnt) { 6465 Nlm_MemSet (fntDlgFontSpec.name, 0, FONT_NAME_SIZE); 6466 Nlm_FntDlgGetSysFontName (i - 1, fntDlgFontSpec.name, FONT_NAME_SIZE); 6467 /* name is set! clear family/pitch/charset fields */ 6468 fntDlgFontSpec.family = FAMILY_NULL; 6469 fntDlgFontSpec.pitch = PITCH_NULL; 6470 fntDlgFontSpec.charset = CHARSET_NULL; 6471 /* size */ 6472 sizeCount = Nlm_FntDlgGetSysFontSize (i-1, &sizes ); 6473 i = Nlm_GetValue (fntDlgSizeList); 6474 if (i > 0 && i <= sizeCount ){ 6475 fntDlgFontSpec.size = sizes[i - 1]; 6476 } 6477 } 6478 /* style */ 6479 i = 0; 6480 if (Nlm_GetStatus (fntDlgBoldBox)) i |= STYLE_BOLD; 6481 if (Nlm_GetStatus (fntDlgItalicBox)) i |= STYLE_ITALIC; 6482 if (Nlm_GetStatus (fntDlgUnderlineBox)) i |= STYLE_UNDERLINE; 6483 fntDlgFontSpec.style = (Nlm_Uint1) i; 6484 } else { 6485 Nlm_Int2 i = 0; 6486 Nlm_Int2 valSet = 0; 6487 Nlm_Char buf[FONT_NAME_SIZE]; 6488 /* name */ 6489 if (fntDlgFontSpec.name [0] != '\0'){ 6490 for (i = 0; i < sysFontCnt; i++) { 6491 Nlm_FntDlgGetSysFontName (i, buf, FONT_NAME_SIZE); 6492 if (Nlm_StrNICmp (buf, fntDlgFontSpec.name, FONT_NAME_SIZE) == 0) { 6493 Nlm_SetValue (fntDlgFontList, i + 1); 6494 valSet = 1; 6495 break; 6496 } 6497 } 6498 } 6499 if ( !valSet ){ 6500 Nlm_SetValue (fntDlgFontList,1); 6501 i = 0; 6502 } 6503 Nlm_FntDlgInitSizeList ( i, fntDlgFontSpec.size ); 6504 Nlm_FntDlgInitStyles ( i, fntDlgFontSpec.style ); 6505 } 6506 } 6507 6508 static void Nlm_FntDlgOKProc (Nlm_ButtoN b) 6509 { 6510 fntDlgUp = FALSE; fntDlgResult = TRUE; 6511 } 6512 6513 static void Nlm_FntDlgCancelProc (Nlm_ButtoN b) 6514 { 6515 fntDlgUp = FALSE; fntDlgResult = FALSE; 6516 } 6517 6518 static void Nlm_FntDlgCheckBoxProc (Nlm_ButtoN b) 6519 { 6520 Nlm_FntDlgUpdate (TRUE); 6521 Nlm_FntDlgRedrawSample (); 6522 } 6523 6524 #ifdef WIN_MAC 6525 static void Nlm_FntDlgPopupProc (Nlm_PopuP p) 6526 { 6527 Nlm_FntDlgUpdate (TRUE); 6528 Nlm_FntDlgRedrawSample (); 6529 } 6530 #endif 6531 6532 #ifdef WIN_MOTIF 6533 static void Nlm_FntDlgListProc (Nlm_LisT l) 6534 { 6535 Nlm_Int2 i; 6536 6537 i = Nlm_GetValue (fntDlgFontList); 6538 if (i > 0 && i <= sysFontCnt) { 6539 Nlm_Hide ( fntDlgSizeList ); 6540 Nlm_Reset ( fntDlgSizeList ); 6541 Nlm_FntDlgInitSizeList ( i-1, fntDlgFontSpec.size ); 6542 Nlm_Show ( fntDlgSizeList ); 6543 Nlm_FntDlgInitStyles ( i-1, fntDlgFontSpec.style ); 6544 } 6545 Nlm_FntDlgUpdate (TRUE); 6546 Nlm_FntDlgRedrawSample (); 6547 } 6548 6549 static void Nlm_FntDlgListSizeProc (Nlm_LisT l) 6550 { 6551 Nlm_FntDlgUpdate (TRUE); 6552 Nlm_FntDlgRedrawSample (); 6553 } 6554 #endif 6555 6556 extern Nlm_Boolean Nlm_ChooseFont (Nlm_FontSpecPtr fsp, 6557 Nlm_Uint2 flags, 6558 Nlm_VoidPtr null) 6559 { 6560 Nlm_Boolean initToFsp = (Nlm_Boolean)((flags & CFF_READ_FSP) != 0); 6561 Nlm_Boolean fixedOnly = (Nlm_Boolean)((flags & CFF_MONOSPACE) != 0); 6562 Nlm_WindoW w = Nlm_MovableModalWindow (-50, -20, -20, -20, "Font", NULL); 6563 Nlm_GrouP gfontsize, gstysamp, gbuttons; 6564 6565 sysFontCnt = Nlm_FntDlgGetSysFontList (fixedOnly); 6566 { Nlm_GrouP g = Nlm_HiddenGroup (w, 10, 0, NULL); 6567 gfontsize = g; 6568 Nlm_SetGroupSpacing (g, 10, 5); 6569 Nlm_StaticPrompt (g, "Font:", 0, 0, Nlm_systemFont, 'r'); 6570 #ifdef WIN_MAC 6571 fntDlgFontList = Nlm_PopupList (g, TRUE, Nlm_FntDlgPopupProc); 6572 #endif 6573 #ifdef WIN_MOTIF 6574 fntDlgFontList = Nlm_SingleList (g, 16, 6, Nlm_FntDlgListProc); 6575 #endif 6576 Nlm_FntDlgInitFontList (); 6577 Nlm_StaticPrompt (g, "Size:", 0, 0, Nlm_systemFont, 'r'); 6578 #ifdef WIN_MAC 6579 fntDlgSizeList = Nlm_PopupList (g, TRUE, Nlm_FntDlgPopupProc); 6580 #endif 6581 #ifdef WIN_MOTIF 6582 fntDlgSizeList = Nlm_SingleList (g, 3, 5, Nlm_FntDlgListSizeProc); 6583 #endif 6584 } 6585 { Nlm_GrouP g = Nlm_HiddenGroup (w, 10, 0, NULL); 6586 Nlm_GrouP gstyle, gsample; 6587 gstysamp = g; 6588 Nlm_SetGroupSpacing (g, 10, 5); 6589 { Nlm_GrouP s = Nlm_NormalGroup (g, 0, 3, "Style:", NULL, NULL); 6590 gstyle = s; 6591 Nlm_SetGroupMargins (s, 10, 5); 6592 Nlm_SetGroupSpacing (s, 10, 5); 6593 fntDlgBoldBox = Nlm_CheckBox (s, "Bold", Nlm_FntDlgCheckBoxProc); 6594 fntDlgItalicBox = Nlm_CheckBox (s, "Italic", Nlm_FntDlgCheckBoxProc); 6595 fntDlgUnderlineBox = Nlm_CheckBox (s, "Underline", Nlm_FntDlgCheckBoxProc); 6596 } 6597 { Nlm_GrouP s = Nlm_NormalGroup (g, 0, 10, "Sample", NULL, NULL); 6598 Nlm_Int2 pixwidth = Nlm_stdCharWidth * 15; 6599 Nlm_Int2 pixheight = Nlm_stdLineHeight * 5; 6600 gsample = s; 6601 Nlm_SetGroupSpacing (s, 10, 5); 6602 fntDlgSample = Nlm_SimplePanel (s, pixwidth, pixheight, 6603 Nlm_FntDlgDrawSampleProc); 6604 } 6605 /* 6606 Nlm_AlignObjects (ALIGN_RIGHT, (Nlm_HANDLE) fntDlgSizeList, 6607 (Nlm_HANDLE) gsample, NULL); 6608 */ 6609 Nlm_AlignObjects (ALIGN_LOWER, (Nlm_HANDLE) gstyle, 6610 (Nlm_HANDLE) gsample, NULL); 6611 } 6612 { Nlm_GrouP g = Nlm_HiddenGroup (w, 10, 0, NULL); 6613 gbuttons = g; 6614 Nlm_SetGroupSpacing (g, 10, 5); 6615 Nlm_DefaultButton (g, " OK ", Nlm_FntDlgOKProc); 6616 Nlm_PushButton (g, "Cancel", Nlm_FntDlgCancelProc); 6617 } 6618 Nlm_AlignObjects (ALIGN_CENTER, (Nlm_HANDLE) gfontsize, 6619 (Nlm_HANDLE) gstysamp, 6620 (Nlm_HANDLE) gbuttons, NULL); 6621 /* init fontspec */ 6622 if (initToFsp && fsp != NULL) { 6623 fntDlgFontSpec = *fsp; 6624 } else { 6625 Nlm_GetFontSpec (fixedOnly ? Nlm_programFont : Nlm_systemFont, 6626 &fntDlgFontSpec); 6627 } 6628 /* update controls */ 6629 Nlm_FntDlgUpdate (FALSE); 6630 /* show dialog */ 6631 Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE); 6632 Nlm_ArrowCursor (); 6633 fntDlgUp = TRUE; 6634 fntDlgResult = FALSE; 6635 Nlm_WaitForCondition( fntDlgUp ); 6636 Nlm_ProcessAnEvent (); 6637 /* update FontSpec */ 6638 Nlm_FntDlgUpdate (TRUE); 6639 Nlm_DoRemove ((Nlm_GraphiC) w, TRUE); 6640 if (fntDlgResult == TRUE && fsp != NULL) *fsp = fntDlgFontSpec; 6641 Nlm_FntDlgFreeSysFontList (); 6642 return fntDlgResult; 6643 } 6644 6645 #endif /* !WIN_MSWIN */ 6646 6647 /* FontSpec/string conversions */ 6648 6649 extern Nlm_Boolean Nlm_StrToFontSpec (Nlm_CharPtr str, Nlm_FontSpecPtr fsp) 6650 { 6651 Nlm_CharPtr cp; 6652 6653 if (fsp == NULL || str == NULL) 6654 return FALSE; 6655 6656 /* get name */ 6657 if ((cp = Nlm_StrChr(str, ',')) == NULL) 6658 return FALSE; 6659 6660 Nlm_StringNCpy_0(fsp->name, str, MIN(cp - str + 1, FONT_NAME_SIZE)); 6661 6662 {{ /* get other parameters */ 6663 int size, style, charset, pitch, family; 6664 int n = sscanf (cp, ",%d,%d,%d,%d,%d", 6665 &size, &style, &charset, &pitch, &family); 6666 fsp->size = (Nlm_Int2) size; 6667 fsp->style = (Nlm_Uint1) style; 6668 fsp->charset = (Nlm_Uint1) charset; 6669 fsp->pitch = (Nlm_Uint1) pitch; 6670 fsp->family = (Nlm_Uint1) family; 6671 return (Nlm_Boolean)(n == 5); 6672 }} 6673 } 6674 6675 extern void Nlm_FontSpecToStr (Nlm_FontSpecPtr fsp, Nlm_CharPtr str, size_t maxsize) 6676 { 6677 Nlm_Char temp [80]; 6678 if (fsp == NULL) { 6679 temp[0] = '\0'; 6680 } else { 6681 sprintf (temp, "%s,%d,%d,%d,%d,%d", fsp->name, 6682 (int) fsp->size, (int) fsp->style, 6683 (int) fsp->charset, (int) fsp->pitch, 6684 (int) fsp->family); 6685 } 6686 Nlm_StringNCpy_0(str, temp, maxsize); 6687 } 6688 6689 6690 6691 #ifdef OS_UNIX 6692 extern void Nlm_FineGranularitySleep (Nlm_Int4 seconds, Nlm_Int4 microseconds) 6693 { 6694 struct timeval tv; 6695 6696 tv.tv_sec = seconds; 6697 tv.tv_usec = microseconds; 6698 select(1, NULL, NULL, NULL, &tv); /* fine granularity sleep */ 6699 } 6700 #endif /* OS_UNIX */ 6701 6702 #ifdef WIN_MOTIF 6703 extern void Nlm_WaitForXEvent( void ) 6704 { 6705 XEvent event; 6706 XPeekEvent(Nlm_currentXDisplay, &event); 6707 } 6708 #endif 6709 6710 extern void Nlm_SetRealized(Nlm_GraphiC a, Nlm_Boolean realizd) 6711 { 6712 Nlm_Boolean switched; 6713 6714 if ( !a ) return; 6715 6716 {{ 6717 Nlm_GraphicData gdata; 6718 Nlm_GetGraphicData (a, &gdata); 6719 switched = (Nlm_Boolean)(gdata.realized != realizd); 6720 gdata.realized = realizd; 6721 Nlm_SetGraphicData (a, &gdata); 6722 }} 6723 6724 if (switched && realizd) 6725 { 6726 Nlm_RecT r; 6727 Nlm_GetPosition(a, &r); 6728 Nlm_DoSetPosition(a, &r, TRUE, TRUE); 6729 } 6730 6731 for (a = Nlm_GetChild( a ); a; a = Nlm_GetNext( a )) 6732 { 6733 Nlm_SetRealized(a, realizd); 6734 } 6735 } 6736 6737 6738 extern Nlm_Boolean Nlm_GetRealized(Nlm_GraphiC a) 6739 { 6740 Nlm_GraphicData gdata; 6741 6742 if ( a ) 6743 { 6744 Nlm_GetGraphicData(a, &gdata); 6745 return gdata.realized; 6746 } 6747 6748 return FALSE; 6749 } 6750 6751 #ifdef WIN_MSWIN 6752 #ifdef WIN16 6753 extern Nlm_Uint2 Nlm_GetDriveType (int driveNumber); 6754 extern Nlm_Uint2 Nlm_GetDriveType (int driveNumber) 6755 6756 { 6757 return (Nlm_Uint2) GetDriveType (driveNumber); 6758 } 6759 #else 6760 extern Nlm_Uint2 Nlm_GetDriveType (char* path); 6761 extern Nlm_Uint2 Nlm_GetDriveType (char* path) 6762 6763 { 6764 return (Nlm_Uint2) GetDriveType (path); 6765 } 6766 #endif 6767 #endif 6768 6769 /* 6770 * Navigation and special key translation and rendering 6771 */ 6772 6773 6774 #ifdef WIN_MOTIF 6775 extern Nlm_Char Nlm_GetInputChar(XKeyEvent *event) 6776 { 6777 KeySym keysym; 6778 char keystr[16]; 6779 int charcount = XLookupString(event, keystr, sizeof(keystr), 6780 &keysym, NULL); 6781 switch ( keysym ) 6782 { 6783 case XK_Left: 6784 return NLM_LEFT; 6785 case XK_Right: 6786 return NLM_RIGHT; 6787 case XK_Up: 6788 return NLM_UP; 6789 case XK_Down: 6790 return NLM_DOWN; 6791 case XK_Prior: 6792 return NLM_PREV; 6793 case XK_Next: 6794 return NLM_NEXT; 6795 case XK_End: 6796 return NLM_END; 6797 case XK_Home: 6798 return NLM_HOME; 6799 case XK_Delete: 6800 return NLM_DEL; 6801 case XK_Insert: 6802 return NLM_INS; 6803 case XK_Escape: 6804 return NLM_ESC; 6805 } 6806 6807 return (charcount == 1) ? keystr[0] : '\0'; 6808 } 6809 6810 6811 static void Nlm_StdTranslationCB(Widget w, XEvent *event, 6812 String *args, Cardinal *num_args) 6813 { 6814 Nlm_Char ch; 6815 XtPointer ptr; 6816 6817 XtVaGetValues(w, XmNuserData, &ptr, NULL); 6818 ASSERT ( ptr ); 6819 6820 ch = Nlm_GetInputChar( &event->xkey ); 6821 ASSERT ( ch ); 6822 6823 Nlm_DoSendFocus((Nlm_GraphiC)ptr, ch); 6824 } 6825 6826 6827 extern void Nlm_RegisterStdTranslations( void ) 6828 { 6829 XtActionsRec actions; 6830 6831 actions.string = "Nlm_StdTranslation"; 6832 actions.proc = Nlm_StdTranslationCB; 6833 XtAppAddActions(Nlm_appContext, &actions, 1); 6834 } 6835 6836 6837 extern void Nlm_OverrideStdTranslations(Nlm_GraphiC g, Widget w, 6838 Nlm_Int4 filter) 6839 { 6840 if ( !(filter & (VERT_PAGE | VERT_ARROW | HORIZ_PAGE | HORIZ_ARROW)) ) 6841 return; 6842 6843 #ifdef _DEBUG 6844 {{ 6845 XtPointer ptr; 6846 XtVaGetValues(w, XmNuserData, &ptr, NULL); 6847 ASSERT ( !ptr ); 6848 }} 6849 #endif 6850 XtVaSetValues(w, XmNuserData, (XtPointer)g, NULL); 6851 6852 if (filter & VERT_PAGE) 6853 { 6854 XtOverrideTranslations(w, XtParseTranslationTable( "\ 6855 <Key>osfPageUp: Nlm_StdTranslation() \n\ 6856 <Key>osfPageDown: Nlm_StdTranslation()" )); 6857 } 6858 6859 if (filter & VERT_ARROW) 6860 { 6861 XtOverrideTranslations(w, XtParseTranslationTable( "\ 6862 <Key>osfUp: Nlm_StdTranslation() \n\ 6863 <Key>osfDown: Nlm_StdTranslation()" )); 6864 } 6865 6866 if (filter & HORIZ_PAGE) 6867 { 6868 XtOverrideTranslations(w, XtParseTranslationTable( "\ 6869 <Key>osfBeginLine: Nlm_StdTranslation() \n\ 6870 <Key>osfEndLine: Nlm_StdTranslation()" )); 6871 } 6872 6873 if (filter & HORIZ_ARROW) 6874 { 6875 XtOverrideTranslations(w, XtParseTranslationTable( "\ 6876 <Key>osfLeft: Nlm_StdTranslation() \n\ 6877 <Key>osfRight: Nlm_StdTranslation()" )); 6878 } 6879 } 6880 #endif 6881 6882 6883 #ifdef WIN_MSWIN 6884 extern Nlm_Char Nlm_KeydownToChar(WPARAM wParam) 6885 { 6886 switch ( wParam ) 6887 { 6888 case VK_LEFT: 6889 return NLM_LEFT; 6890 case VK_RIGHT: 6891 return NLM_RIGHT; 6892 case VK_UP: 6893 return NLM_UP; 6894 case VK_DOWN: 6895 return NLM_DOWN; 6896 case VK_PRIOR: 6897 return NLM_PREV; 6898 case VK_NEXT: 6899 return NLM_NEXT; 6900 case VK_HOME: 6901 return NLM_HOME; 6902 case VK_END: 6903 return NLM_END; 6904 case VK_INSERT: 6905 return NLM_INS; 6906 case VK_DELETE: 6907 return NLM_DEL; 6908 case VK_ESCAPE: 6909 return NLM_ESC; 6910 } 6911 6912 return '\0'; 6913 } 6914 6915 6916 extern Nlm_Boolean Nlm_ProcessKeydown(Nlm_GraphiC g, WPARAM wParam, 6917 Nlm_Int4 filter) 6918 { 6919 Nlm_Char ch = Nlm_KeydownToChar( wParam ); 6920 6921 switch ( ch ) 6922 { 6923 case '\0': 6924 return FALSE; 6925 6926 case NLM_LEFT: 6927 case NLM_RIGHT: 6928 if (filter & HORIZ_ARROW) 6929 break; 6930 return FALSE; 6931 6932 case NLM_UP: 6933 case NLM_DOWN: 6934 if (filter & VERT_ARROW) 6935 break; 6936 return FALSE; 6937 6938 6939 case NLM_HOME: 6940 case NLM_END: 6941 if (filter & HORIZ_PAGE) 6942 break; 6943 return FALSE; 6944 6945 case NLM_PREV: 6946 case NLM_NEXT: 6947 if (filter & VERT_PAGE) 6948 break; 6949 return FALSE; 6950 6951 default: 6952 return FALSE; 6953 } 6954 6955 Nlm_DoSendFocus(g, ch); 6956 return TRUE; 6957 } 6958 #endif 6959 6960 6961 #ifdef WIN_MOTIF 6962 typedef struct Nlm_IOstruct 6963 { 6964 int fd; 6965 Nlm_IOtype type; 6966 XtInputId id; 6967 Nlm_IOcallback ufunc; 6968 Nlm_VoidPtr udata; 6969 } Nlm_IOstruct; 6970 6971 6972 static void io_callback(XtPointer client_data, int *source, XtInputId *id) 6973 { 6974 Nlm_IO io = (Nlm_IO)client_data; 6975 (*io->ufunc)(io, io->fd, io->type, io->udata); 6976 } 6977 6978 /* register IO callback "ufunc"; return IO handler. 6979 * NOTE: "type" cannot be IO_CLEANUP! 6980 */ 6981 extern Nlm_IO Nlm_RegisterIO(int fd, 6982 Nlm_IOcallback ufunc, Nlm_VoidPtr udata, 6983 Nlm_IOtype type) 6984 { 6985 Nlm_IO io; 6986 XtPointer cond; 6987 6988 if ( !ufunc ) 6989 return NULL; 6990 6991 switch ( type ) 6992 { 6993 case Nlm_IO_READ: 6994 cond = (XtPointer)XtInputReadMask; 6995 break; 6996 case Nlm_IO_WRITE: 6997 cond = (XtPointer)XtInputWriteMask; 6998 break; 6999 case Nlm_IO_ERROR: 7000 cond = (XtPointer)XtInputExceptMask; 7001 break; 7002 default: 7003 ASSERT ( FALSE ); 7004 return NULL; 7005 } 7006 7007 io = (Nlm_IO)Nlm_MemNew( sizeof(Nlm_IOstruct) ); 7008 io->fd = fd; 7009 io->type = type; 7010 io->ufunc = ufunc; 7011 io->udata = udata; 7012 io->id = XtAppAddInput(Nlm_appContext, fd, cond, io_callback, io); 7013 return io; 7014 } 7015 7016 extern void Nlm_UnregisterIO(Nlm_IO io) 7017 { 7018 if ( !io ) 7019 return; 7020 7021 if ( io->ufunc ) 7022 (*io->ufunc)(io, io->fd, Nlm_IO_CLEANUP, io->udata); 7023 7024 XtRemoveInput( io->id ); 7025 Nlm_MemFree( io ); 7026 } 7027 #endif 7028
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |