Mercurial > vim
comparison src/os_mswin.c @ 18810:44b855153d8e v8.1.2393
patch 8.1.2393: using old C style comments
Commit: https://github.com/vim/vim/commit/0f8737355d291679659579a48db1861b88970293
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 5 20:28:46 2019 +0100
patch 8.1.2393: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 05 Dec 2019 20:30:04 +0100 |
parents | 38a3bef525e6 |
children | 1fe99999625c |
comparison
equal
deleted
inserted
replaced
18809:8c6177fec9cb | 18810:44b855153d8e |
---|---|
40 # include <dlgs.h> | 40 # include <dlgs.h> |
41 # include <winspool.h> | 41 # include <winspool.h> |
42 # include <commdlg.h> | 42 # include <commdlg.h> |
43 # endif | 43 # endif |
44 | 44 |
45 #endif /* PROTO */ | 45 #endif // PROTO |
46 | 46 |
47 #ifdef __MINGW32__ | 47 #ifdef __MINGW32__ |
48 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED | 48 # ifndef FROM_LEFT_1ST_BUTTON_PRESSED |
49 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 | 49 # define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 |
50 # endif | 50 # endif |
120 typedef int WORD; | 120 typedef int WORD; |
121 typedef int WPARAM; | 121 typedef int WPARAM; |
122 typedef void VOID; | 122 typedef void VOID; |
123 #endif | 123 #endif |
124 | 124 |
125 /* Record all output and all keyboard & mouse input */ | 125 // Record all output and all keyboard & mouse input |
126 /* #define MCH_WRITE_DUMP */ | 126 // #define MCH_WRITE_DUMP |
127 | 127 |
128 #ifdef MCH_WRITE_DUMP | 128 #ifdef MCH_WRITE_DUMP |
129 FILE* fdDump = NULL; | 129 FILE* fdDump = NULL; |
130 #endif | 130 #endif |
131 | 131 |
134 #endif | 134 #endif |
135 | 135 |
136 #ifdef FEAT_GUI | 136 #ifdef FEAT_GUI |
137 extern HWND s_hwnd; | 137 extern HWND s_hwnd; |
138 #else | 138 #else |
139 static HWND s_hwnd = 0; /* console window handle, set by GetConsoleHwnd() */ | 139 static HWND s_hwnd = 0; // console window handle, set by GetConsoleHwnd() |
140 #endif | 140 #endif |
141 | 141 |
142 #ifdef FEAT_JOB_CHANNEL | 142 #ifdef FEAT_JOB_CHANNEL |
143 int WSInitialized = FALSE; /* WinSock is initialized */ | 143 int WSInitialized = FALSE; // WinSock is initialized |
144 #endif | 144 #endif |
145 | 145 |
146 /* Don't generate prototypes here, because some systems do have these | 146 // Don't generate prototypes here, because some systems do have these |
147 * functions. */ | 147 // functions. |
148 #if defined(__GNUC__) && !defined(PROTO) | 148 #if defined(__GNUC__) && !defined(PROTO) |
149 # ifndef __MINGW32__ | 149 # ifndef __MINGW32__ |
150 int _stricoll(char *a, char *b) | 150 int _stricoll(char *a, char *b) |
151 { | 151 { |
152 // the ANSI-ish correct way is to use strxfrm(): | 152 // the ANSI-ish correct way is to use strxfrm(): |
197 { | 197 { |
198 exiting = TRUE; | 198 exiting = TRUE; |
199 | 199 |
200 display_errors(); | 200 display_errors(); |
201 | 201 |
202 ml_close_all(TRUE); /* remove all memfiles */ | 202 ml_close_all(TRUE); // remove all memfiles |
203 | 203 |
204 # ifdef FEAT_OLE | 204 # ifdef FEAT_OLE |
205 UninitOLE(); | 205 UninitOLE(); |
206 # endif | 206 # endif |
207 # ifdef FEAT_JOB_CHANNEL | 207 # ifdef FEAT_JOB_CHANNEL |
223 # endif | 223 # endif |
224 | 224 |
225 exit(r); | 225 exit(r); |
226 } | 226 } |
227 | 227 |
228 #endif /* FEAT_GUI_MSWIN */ | 228 #endif // FEAT_GUI_MSWIN |
229 | 229 |
230 | 230 |
231 /* | 231 /* |
232 * Init the tables for toupper() and tolower(). | 232 * Init the tables for toupper() and tolower(). |
233 */ | 233 */ |
236 { | 236 { |
237 int i; | 237 int i; |
238 | 238 |
239 PlatformId(); | 239 PlatformId(); |
240 | 240 |
241 /* Init the tables for toupper() and tolower() */ | 241 // Init the tables for toupper() and tolower() |
242 for (i = 0; i < 256; ++i) | 242 for (i = 0; i < 256; ++i) |
243 toupper_tab[i] = tolower_tab[i] = i; | 243 toupper_tab[i] = tolower_tab[i] = i; |
244 CharUpperBuff((LPSTR)toupper_tab, 256); | 244 CharUpperBuff((LPSTR)toupper_tab, 256); |
245 CharLowerBuff((LPSTR)tolower_tab, 256); | 245 CharLowerBuff((LPSTR)tolower_tab, 256); |
246 } | 246 } |
254 { | 254 { |
255 #ifdef FEAT_GUI_MSWIN | 255 #ifdef FEAT_GUI_MSWIN |
256 # ifdef VIMDLL | 256 # ifdef VIMDLL |
257 if (gui.in_use) | 257 if (gui.in_use) |
258 # endif | 258 # endif |
259 return TRUE; /* GUI always has a tty */ | 259 return TRUE; // GUI always has a tty |
260 #endif | 260 #endif |
261 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) | 261 #if !defined(FEAT_GUI_MSWIN) || defined(VIMDLL) |
262 if (isatty(read_cmd_fd)) | 262 if (isatty(read_cmd_fd)) |
263 return TRUE; | 263 return TRUE; |
264 return FALSE; | 264 return FALSE; |
334 int | 334 int |
335 mch_can_restore_icon(void) | 335 mch_can_restore_icon(void) |
336 { | 336 { |
337 return FALSE; | 337 return FALSE; |
338 } | 338 } |
339 #endif /* FEAT_TITLE */ | 339 #endif // FEAT_TITLE |
340 | 340 |
341 | 341 |
342 /* | 342 /* |
343 * Get absolute file name into buffer "buf" of length "len" bytes, | 343 * Get absolute file name into buffer "buf" of length "len" bytes, |
344 * turning all '/'s into '\\'s and getting the correct case of each component | 344 * turning all '/'s into '\\'s and getting the correct case of each component |
385 * Return TRUE if "fname" does not depend on the current directory. | 385 * Return TRUE if "fname" does not depend on the current directory. |
386 */ | 386 */ |
387 int | 387 int |
388 mch_isFullName(char_u *fname) | 388 mch_isFullName(char_u *fname) |
389 { | 389 { |
390 /* WinNT and later can use _MAX_PATH wide characters for a pathname, which | 390 // WinNT and later can use _MAX_PATH wide characters for a pathname, which |
391 * means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is | 391 // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is |
392 * UTF-8. */ | 392 // UTF-8. |
393 char szName[_MAX_PATH * 3 + 1]; | 393 char szName[_MAX_PATH * 3 + 1]; |
394 | 394 |
395 /* A name like "d:/foo" and "//server/share" is absolute */ | 395 // A name like "d:/foo" and "//server/share" is absolute |
396 if ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) | 396 if ((fname[0] && fname[1] == ':' && (fname[2] == '/' || fname[2] == '\\')) |
397 || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))) | 397 || (fname[0] == fname[1] && (fname[0] == '/' || fname[0] == '\\'))) |
398 return TRUE; | 398 return TRUE; |
399 | 399 |
400 /* A name that can't be made absolute probably isn't absolute. */ | 400 // A name that can't be made absolute probably isn't absolute. |
401 if (mch_FullName(fname, (char_u *)szName, sizeof(szName) - 1, FALSE) == FAIL) | 401 if (mch_FullName(fname, (char_u *)szName, sizeof(szName) - 1, FALSE) == FAIL) |
402 return FALSE; | 402 return FALSE; |
403 | 403 |
404 return pathcmp((const char *)fname, (const char *)szName, -1) == 0; | 404 return pathcmp((const char *)fname, (const char *)szName, -1) == 0; |
405 } | 405 } |
422 | 422 |
423 if (*p == '`') | 423 if (*p == '`') |
424 { | 424 { |
425 size_t len = STRLEN(p); | 425 size_t len = STRLEN(p); |
426 | 426 |
427 /* don't replace backslash in backtick quoted strings */ | 427 // don't replace backslash in backtick quoted strings |
428 if (len > 2 && *(p + len - 1) == '`') | 428 if (len > 2 && *(p + len - 1) == '`') |
429 return; | 429 return; |
430 } | 430 } |
431 | 431 |
432 while (*p) | 432 while (*p) |
435 *p = psepc; | 435 *p = psepc; |
436 MB_PTR_ADV(p); | 436 MB_PTR_ADV(p); |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 /* Use 64-bit stat functions if available. */ | 440 // Use 64-bit stat functions if available. |
441 #ifdef HAVE_STAT64 | 441 #ifdef HAVE_STAT64 |
442 # undef stat | 442 # undef stat |
443 # undef _stat | 443 # undef _stat |
444 # undef _wstat | 444 # undef _wstat |
445 # undef _fstat | 445 # undef _fstat |
457 | 457 |
458 static int | 458 static int |
459 wstat_symlink_aware(const WCHAR *name, stat_T *stp) | 459 wstat_symlink_aware(const WCHAR *name, stat_T *stp) |
460 { | 460 { |
461 #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__) | 461 #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__MINGW32__) |
462 /* Work around for VC12 or earlier (and MinGW). _wstat() can't handle | 462 // Work around for VC12 or earlier (and MinGW). _wstat() can't handle |
463 * symlinks properly. | 463 // symlinks properly. |
464 * VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves | 464 // VC9 or earlier: _wstat() doesn't support a symlink at all. It retrieves |
465 * status of a symlink itself. | 465 // status of a symlink itself. |
466 * VC10: _wstat() supports a symlink to a normal file, but it doesn't | 466 // VC10: _wstat() supports a symlink to a normal file, but it doesn't |
467 * support a symlink to a directory (always returns an error). | 467 // support a symlink to a directory (always returns an error). |
468 * VC11 and VC12: _wstat() doesn't return an error for a symlink to a | 468 // VC11 and VC12: _wstat() doesn't return an error for a symlink to a |
469 * directory, but it doesn't set S_IFDIR flag. | 469 // directory, but it doesn't set S_IFDIR flag. |
470 * MinGW: Same as VC9. */ | 470 // MinGW: Same as VC9. |
471 int n; | 471 int n; |
472 BOOL is_symlink = FALSE; | 472 BOOL is_symlink = FALSE; |
473 HANDLE hFind, h; | 473 HANDLE hFind, h; |
474 DWORD attr = 0; | 474 DWORD attr = 0; |
475 WIN32_FIND_DATAW findDataW; | 475 WIN32_FIND_DATAW findDataW; |
511 * stat() can't handle a trailing '/' or '\', remove it first. | 511 * stat() can't handle a trailing '/' or '\', remove it first. |
512 */ | 512 */ |
513 int | 513 int |
514 vim_stat(const char *name, stat_T *stp) | 514 vim_stat(const char *name, stat_T *stp) |
515 { | 515 { |
516 /* WinNT and later can use _MAX_PATH wide characters for a pathname, which | 516 // WinNT and later can use _MAX_PATH wide characters for a pathname, which |
517 * means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is | 517 // means that the maximum pathname is _MAX_PATH * 3 bytes when 'enc' is |
518 * UTF-8. */ | 518 // UTF-8. |
519 char_u buf[_MAX_PATH * 3 + 1]; | 519 char_u buf[_MAX_PATH * 3 + 1]; |
520 char_u *p; | 520 char_u *p; |
521 WCHAR *wp; | 521 WCHAR *wp; |
522 int n; | 522 int n; |
523 | 523 |
524 vim_strncpy((char_u *)buf, (char_u *)name, sizeof(buf) - 1); | 524 vim_strncpy((char_u *)buf, (char_u *)name, sizeof(buf) - 1); |
525 p = buf + STRLEN(buf); | 525 p = buf + STRLEN(buf); |
526 if (p > buf) | 526 if (p > buf) |
527 MB_PTR_BACK(buf, p); | 527 MB_PTR_BACK(buf, p); |
528 | 528 |
529 /* Remove trailing '\\' except root path. */ | 529 // Remove trailing '\\' except root path. |
530 if (p > buf && (*p == '\\' || *p == '/') && p[-1] != ':') | 530 if (p > buf && (*p == '\\' || *p == '/') && p[-1] != ':') |
531 *p = NUL; | 531 *p = NUL; |
532 | 532 |
533 if ((buf[0] == '\\' && buf[1] == '\\') || (buf[0] == '/' && buf[1] == '/')) | 533 if ((buf[0] == '\\' && buf[1] == '\\') || (buf[0] == '/' && buf[1] == '/')) |
534 { | 534 { |
535 /* UNC root path must be followed by '\\'. */ | 535 // UNC root path must be followed by '\\'. |
536 p = vim_strpbrk(buf + 2, (char_u *)"\\/"); | 536 p = vim_strpbrk(buf + 2, (char_u *)"\\/"); |
537 if (p != NULL) | 537 if (p != NULL) |
538 { | 538 { |
539 p = vim_strpbrk(p + 1, (char_u *)"\\/"); | 539 p = vim_strpbrk(p + 1, (char_u *)"\\/"); |
540 if (p == NULL) | 540 if (p == NULL) |
553 | 553 |
554 #if (defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)) || defined(PROTO) | 554 #if (defined(FEAT_GUI_MSWIN) && !defined(VIMDLL)) || defined(PROTO) |
555 void | 555 void |
556 mch_settmode(int tmode UNUSED) | 556 mch_settmode(int tmode UNUSED) |
557 { | 557 { |
558 /* nothing to do */ | 558 // nothing to do |
559 } | 559 } |
560 | 560 |
561 int | 561 int |
562 mch_get_shellsize(void) | 562 mch_get_shellsize(void) |
563 { | 563 { |
564 /* never used */ | 564 // never used |
565 return OK; | 565 return OK; |
566 } | 566 } |
567 | 567 |
568 void | 568 void |
569 mch_set_shellsize(void) | 569 mch_set_shellsize(void) |
570 { | 570 { |
571 /* never used */ | 571 // never used |
572 } | 572 } |
573 | 573 |
574 /* | 574 /* |
575 * Rows and/or Columns has changed. | 575 * Rows and/or Columns has changed. |
576 */ | 576 */ |
577 void | 577 void |
578 mch_new_shellsize(void) | 578 mch_new_shellsize(void) |
579 { | 579 { |
580 /* never used */ | 580 // never used |
581 } | 581 } |
582 | 582 |
583 #endif | 583 #endif |
584 | 584 |
585 /* | 585 /* |
610 if (gui.in_use || gui.starting) | 610 if (gui.in_use || gui.starting) |
611 # endif | 611 # endif |
612 { | 612 { |
613 if (error_ga.ga_data != NULL) | 613 if (error_ga.ga_data != NULL) |
614 { | 614 { |
615 /* avoid putting up a message box with blanks only */ | 615 // avoid putting up a message box with blanks only |
616 for (p = (char *)error_ga.ga_data; *p; ++p) | 616 for (p = (char *)error_ga.ga_data; *p; ++p) |
617 if (!isspace(*p)) | 617 if (!isspace(*p)) |
618 { | 618 { |
619 (void)gui_mch_dialog( | 619 (void)gui_mch_dialog( |
620 gui.starting ? VIM_INFO : | 620 gui.starting ? VIM_INFO : |
684 mch_chdir(char *path) | 684 mch_chdir(char *path) |
685 { | 685 { |
686 WCHAR *p; | 686 WCHAR *p; |
687 int n; | 687 int n; |
688 | 688 |
689 if (path[0] == NUL) /* just checking... */ | 689 if (path[0] == NUL) // just checking... |
690 return -1; | 690 return -1; |
691 | 691 |
692 if (p_verbose >= 5) | 692 if (p_verbose >= 5) |
693 { | 693 { |
694 verbose_enter(); | 694 verbose_enter(); |
695 smsg("chdir(%s)", path); | 695 smsg("chdir(%s)", path); |
696 verbose_leave(); | 696 verbose_leave(); |
697 } | 697 } |
698 if (isalpha(path[0]) && path[1] == ':') /* has a drive name */ | 698 if (isalpha(path[0]) && path[1] == ':') // has a drive name |
699 { | 699 { |
700 /* If we can change to the drive, skip that part of the path. If we | 700 // If we can change to the drive, skip that part of the path. If we |
701 * can't then the current directory may be invalid, try using chdir() | 701 // can't then the current directory may be invalid, try using chdir() |
702 * with the whole path. */ | 702 // with the whole path. |
703 if (_chdrive(TOLOWER_ASC(path[0]) - 'a' + 1) == 0) | 703 if (_chdrive(TOLOWER_ASC(path[0]) - 'a' + 1) == 0) |
704 path += 2; | 704 path += 2; |
705 } | 705 } |
706 | 706 |
707 if (*path == NUL) /* drive name only */ | 707 if (*path == NUL) // drive name only |
708 return 0; | 708 return 0; |
709 | 709 |
710 p = enc_to_utf16((char_u *)path, NULL); | 710 p = enc_to_utf16((char_u *)path, NULL); |
711 if (p == NULL) | 711 if (p == NULL) |
712 return -1; | 712 return -1; |
722 * return non-zero if a character is available | 722 * return non-zero if a character is available |
723 */ | 723 */ |
724 int | 724 int |
725 mch_char_avail(void) | 725 mch_char_avail(void) |
726 { | 726 { |
727 /* never used */ | 727 // never used |
728 return TRUE; | 728 return TRUE; |
729 } | 729 } |
730 | 730 |
731 # if defined(FEAT_TERMINAL) || defined(PROTO) | 731 # if defined(FEAT_TERMINAL) || defined(PROTO) |
732 /* | 732 /* |
733 * Check for any pending input or messages. | 733 * Check for any pending input or messages. |
734 */ | 734 */ |
735 int | 735 int |
736 mch_check_messages(void) | 736 mch_check_messages(void) |
737 { | 737 { |
738 /* TODO: check for messages */ | 738 // TODO: check for messages |
739 return TRUE; | 739 return TRUE; |
740 } | 740 } |
741 # endif | 741 # endif |
742 #endif | 742 #endif |
743 | 743 |
776 MEMORY_BASIC_INFORMATION mbi; | 776 MEMORY_BASIC_INFORMATION mbi; |
777 size_t length = 0; | 777 size_t length = 0; |
778 size_t i; | 778 size_t i; |
779 const char_u *p; | 779 const char_u *p; |
780 | 780 |
781 /* get page size */ | 781 // get page size |
782 GetSystemInfo(&si); | 782 GetSystemInfo(&si); |
783 | 783 |
784 /* get memory information */ | 784 // get memory information |
785 if (VirtualQuery(str, &mbi, sizeof(mbi))) | 785 if (VirtualQuery(str, &mbi, sizeof(mbi))) |
786 { | 786 { |
787 /* pre cast these (typing savers) */ | 787 // pre cast these (typing savers) |
788 long_u dwStr = (long_u)str; | 788 long_u dwStr = (long_u)str; |
789 long_u dwBaseAddress = (long_u)mbi.BaseAddress; | 789 long_u dwBaseAddress = (long_u)mbi.BaseAddress; |
790 | 790 |
791 /* get start address of page that str is on */ | 791 // get start address of page that str is on |
792 long_u strPage = dwStr - (dwStr - dwBaseAddress) % si.dwPageSize; | 792 long_u strPage = dwStr - (dwStr - dwBaseAddress) % si.dwPageSize; |
793 | 793 |
794 /* get length from str to end of page */ | 794 // get length from str to end of page |
795 long_u pageLength = si.dwPageSize - (dwStr - strPage); | 795 long_u pageLength = si.dwPageSize - (dwStr - strPage); |
796 | 796 |
797 for (p = str; !IsBadReadPtr(p, (UINT)pageLength); | 797 for (p = str; !IsBadReadPtr(p, (UINT)pageLength); |
798 p += pageLength, pageLength = si.dwPageSize) | 798 p += pageLength, pageLength = si.dwPageSize) |
799 for (i = 0; i < pageLength; ++i, ++length) | 799 for (i = 0; i < pageLength; ++i, ++length) |
832 | 832 |
833 int | 833 int |
834 mch_libcall( | 834 mch_libcall( |
835 char_u *libname, | 835 char_u *libname, |
836 char_u *funcname, | 836 char_u *funcname, |
837 char_u *argstring, /* NULL when using a argint */ | 837 char_u *argstring, // NULL when using a argint |
838 int argint, | 838 int argint, |
839 char_u **string_result,/* NULL when using number_result */ | 839 char_u **string_result,// NULL when using number_result |
840 int *number_result) | 840 int *number_result) |
841 { | 841 { |
842 HINSTANCE hinstLib; | 842 HINSTANCE hinstLib; |
843 MYSTRPROCSTR ProcAdd; | 843 MYSTRPROCSTR ProcAdd; |
844 MYINTPROCSTR ProcAddI; | 844 MYINTPROCSTR ProcAddI; |
858 __try | 858 __try |
859 { | 859 { |
860 # endif | 860 # endif |
861 if (argstring != NULL) | 861 if (argstring != NULL) |
862 { | 862 { |
863 /* Call with string argument */ | 863 // Call with string argument |
864 ProcAdd = (MYSTRPROCSTR)GetProcAddress(hinstLib, (LPCSTR)funcname); | 864 ProcAdd = (MYSTRPROCSTR)GetProcAddress(hinstLib, (LPCSTR)funcname); |
865 if ((fRunTimeLinkSuccess = (ProcAdd != NULL)) != 0) | 865 if ((fRunTimeLinkSuccess = (ProcAdd != NULL)) != 0) |
866 { | 866 { |
867 if (string_result == NULL) | 867 if (string_result == NULL) |
868 retval_int = ((MYSTRPROCINT)ProcAdd)((LPSTR)argstring); | 868 retval_int = ((MYSTRPROCINT)ProcAdd)((LPSTR)argstring); |
870 retval_str = (char_u *)(ProcAdd)((LPSTR)argstring); | 870 retval_str = (char_u *)(ProcAdd)((LPSTR)argstring); |
871 } | 871 } |
872 } | 872 } |
873 else | 873 else |
874 { | 874 { |
875 /* Call with number argument */ | 875 // Call with number argument |
876 ProcAddI = (MYINTPROCSTR) GetProcAddress(hinstLib, (LPCSTR)funcname); | 876 ProcAddI = (MYINTPROCSTR) GetProcAddress(hinstLib, (LPCSTR)funcname); |
877 if ((fRunTimeLinkSuccess = (ProcAddI != NULL)) != 0) | 877 if ((fRunTimeLinkSuccess = (ProcAddI != NULL)) != 0) |
878 { | 878 { |
879 if (string_result == NULL) | 879 if (string_result == NULL) |
880 retval_int = ((MYINTPROCINT)ProcAddI)(argint); | 880 retval_int = ((MYINTPROCINT)ProcAddI)(argint); |
955 | 955 |
956 #endif //_DEBUG | 956 #endif //_DEBUG |
957 | 957 |
958 #if !defined(FEAT_GUI) || defined(VIMDLL) || defined(PROTO) | 958 #if !defined(FEAT_GUI) || defined(VIMDLL) || defined(PROTO) |
959 # ifdef FEAT_TITLE | 959 # ifdef FEAT_TITLE |
960 extern HWND g_hWnd; /* This is in os_win32.c. */ | 960 extern HWND g_hWnd; // This is in os_win32.c. |
961 # endif | 961 # endif |
962 | 962 |
963 /* | 963 /* |
964 * Showing the printer dialog is tricky since we have no GUI | 964 * Showing the printer dialog is tricky since we have no GUI |
965 * window to parent it. The following routines are needed to | 965 * window to parent it. The following routines are needed to |
966 * get the window parenting and Z-order to work properly. | 966 * get the window parenting and Z-order to work properly. |
967 */ | 967 */ |
968 static void | 968 static void |
969 GetConsoleHwnd(void) | 969 GetConsoleHwnd(void) |
970 { | 970 { |
971 /* Skip if it's already set. */ | 971 // Skip if it's already set. |
972 if (s_hwnd != 0) | 972 if (s_hwnd != 0) |
973 return; | 973 return; |
974 | 974 |
975 # ifdef FEAT_TITLE | 975 # ifdef FEAT_TITLE |
976 /* Window handle may have been found by init code (Windows NT only) */ | 976 // Window handle may have been found by init code (Windows NT only) |
977 if (g_hWnd != 0) | 977 if (g_hWnd != 0) |
978 { | 978 { |
979 s_hwnd = g_hWnd; | 979 s_hwnd = g_hWnd; |
980 return; | 980 return; |
981 } | 981 } |
1011 } | 1011 } |
1012 #endif | 1012 #endif |
1013 | 1013 |
1014 #if (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) || defined(PROTO) | 1014 #if (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) || defined(PROTO) |
1015 | 1015 |
1016 /*================================================================= | 1016 //================================================================= |
1017 * Win32 printer stuff | 1017 // Win32 printer stuff |
1018 */ | |
1019 | 1018 |
1020 static HFONT prt_font_handles[2][2][2]; | 1019 static HFONT prt_font_handles[2][2][2]; |
1021 static PRINTDLGW prt_dlg; | 1020 static PRINTDLGW prt_dlg; |
1022 static const int boldface[2] = {FW_REGULAR, FW_BOLD}; | 1021 static const int boldface[2] = {FW_REGULAR, FW_BOLD}; |
1023 static TEXTMETRIC prt_tm; | 1022 static TEXTMETRIC prt_tm; |
1029 static char_u szAppName[] = TEXT("VIM"); | 1028 static char_u szAppName[] = TEXT("VIM"); |
1030 static HWND hDlgPrint; | 1029 static HWND hDlgPrint; |
1031 static int *bUserAbort = NULL; | 1030 static int *bUserAbort = NULL; |
1032 static char_u *prt_name = NULL; | 1031 static char_u *prt_name = NULL; |
1033 | 1032 |
1034 /* Defines which are also in vim.rc. */ | 1033 // Defines which are also in vim.rc. |
1035 # define IDC_BOX1 400 | 1034 # define IDC_BOX1 400 |
1036 # define IDC_PRINTTEXT1 401 | 1035 # define IDC_PRINTTEXT1 401 |
1037 # define IDC_PRINTTEXT2 402 | 1036 # define IDC_PRINTTEXT2 402 |
1038 # define IDC_PROGRESS 403 | 1037 # define IDC_PROGRESS 403 |
1039 | 1038 |
1065 *(ptr ) = *(ptr + 2); | 1064 *(ptr ) = *(ptr + 2); |
1066 *(ptr + 2) = temp; | 1065 *(ptr + 2) = temp; |
1067 return colorref; | 1066 return colorref; |
1068 } | 1067 } |
1069 | 1068 |
1070 /* Attempt to make this work for old and new compilers */ | 1069 // Attempt to make this work for old and new compilers |
1071 # if !defined(_WIN64) && (!defined(_MSC_VER) || _MSC_VER < 1300) | 1070 # if !defined(_WIN64) && (!defined(_MSC_VER) || _MSC_VER < 1300) |
1072 # define PDP_RETVAL BOOL | 1071 # define PDP_RETVAL BOOL |
1073 # else | 1072 # else |
1074 # define PDP_RETVAL INT_PTR | 1073 # define PDP_RETVAL INT_PTR |
1075 # endif | 1074 # endif |
1098 0)) | 1097 0)) |
1099 { | 1098 { |
1100 char buff[MAX_PATH]; | 1099 char buff[MAX_PATH]; |
1101 int i; | 1100 int i; |
1102 | 1101 |
1103 /* Translate the dialog texts */ | 1102 // Translate the dialog texts |
1104 hfont = CreateFontIndirect(&nm.lfMessageFont); | 1103 hfont = CreateFontIndirect(&nm.lfMessageFont); |
1105 for (i = IDC_PRINTTEXT1; i <= IDC_PROGRESS; i++) | 1104 for (i = IDC_PRINTTEXT1; i <= IDC_PROGRESS; i++) |
1106 { | 1105 { |
1107 SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1); | 1106 SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1); |
1108 if (GetDlgItemText(hDlg,i, buff, sizeof(buff))) | 1107 if (GetDlgItemText(hDlg,i, buff, sizeof(buff))) |
1199 rcOwner.left + (rc.right / 2), | 1198 rcOwner.left + (rc.right / 2), |
1200 rcOwner.top + (rc.bottom / 2), | 1199 rcOwner.top + (rc.bottom / 2), |
1201 0, 0, // ignores size arguments | 1200 0, 0, // ignores size arguments |
1202 SWP_NOSIZE); | 1201 SWP_NOSIZE); |
1203 | 1202 |
1204 /* tackle the printdlg copiesctrl problem */ | 1203 // tackle the printdlg copiesctrl problem |
1205 pPD = (PRINTDLGW *)lParam; | 1204 pPD = (PRINTDLGW *)lParam; |
1206 pPD->nCopies = (WORD)pPD->lCustData; | 1205 pPD->nCopies = (WORD)pPD->lCustData; |
1207 SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE ); | 1206 SetDlgItemInt( hDlg, edt3, pPD->nCopies, FALSE ); |
1208 /* Bring the window to top */ | 1207 // Bring the window to top |
1209 BringWindowToTop(GetParent(hDlg)); | 1208 BringWindowToTop(GetParent(hDlg)); |
1210 SetForegroundWindow(hDlg); | 1209 SetForegroundWindow(hDlg); |
1211 } | 1210 } |
1212 | 1211 |
1213 return FALSE; | 1212 return FALSE; |
1321 | 1320 |
1322 rev_offset = phyw - (dvoff + vr); | 1321 rev_offset = phyw - (dvoff + vr); |
1323 | 1322 |
1324 prt_top_margin = to_device_units(OPT_PRINT_TOP, dpi, phyw, dvoff, 5); | 1323 prt_top_margin = to_device_units(OPT_PRINT_TOP, dpi, phyw, dvoff, 5); |
1325 | 1324 |
1326 /* adjust top margin if there is a header */ | 1325 // adjust top margin if there is a header |
1327 prt_top_margin += prt_line_height * prt_header_height(); | 1326 prt_top_margin += prt_line_height * prt_header_height(); |
1328 | 1327 |
1329 bottom_margin = vr - to_device_units(OPT_PRINT_BOT, dpi, phyw, | 1328 bottom_margin = vr - to_device_units(OPT_PRINT_BOT, dpi, phyw, |
1330 rev_offset, 5); | 1329 rev_offset, 5); |
1331 | 1330 |
1354 prt_dlg.lStructSize = sizeof(PRINTDLGW); | 1353 prt_dlg.lStructSize = sizeof(PRINTDLGW); |
1355 # if !defined(FEAT_GUI) || defined(VIMDLL) | 1354 # if !defined(FEAT_GUI) || defined(VIMDLL) |
1356 # ifdef VIMDLL | 1355 # ifdef VIMDLL |
1357 if (!gui.in_use) | 1356 if (!gui.in_use) |
1358 # endif | 1357 # endif |
1359 GetConsoleHwnd(); /* get value of s_hwnd */ | 1358 GetConsoleHwnd(); // get value of s_hwnd |
1360 # endif | 1359 # endif |
1361 prt_dlg.hwndOwner = s_hwnd; | 1360 prt_dlg.hwndOwner = s_hwnd; |
1362 prt_dlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; | 1361 prt_dlg.Flags = PD_NOPAGENUMS | PD_NOSELECTION | PD_RETURNDC; |
1363 if (!forceit) | 1362 if (!forceit) |
1364 { | 1363 { |
1426 emsg(_("E237: Printer selection failed")); | 1425 emsg(_("E237: Printer selection failed")); |
1427 mch_print_cleanup(); | 1426 mch_print_cleanup(); |
1428 return FALSE; | 1427 return FALSE; |
1429 } | 1428 } |
1430 | 1429 |
1431 /* Not all printer drivers report the support of color (or grey) in the | 1430 // Not all printer drivers report the support of color (or grey) in the |
1432 * same way. Let's set has_color if there appears to be some way to print | 1431 // same way. Let's set has_color if there appears to be some way to print |
1433 * more than B&W. */ | 1432 // more than B&W. |
1434 i = GetDeviceCaps(prt_dlg.hDC, NUMCOLORS); | 1433 i = GetDeviceCaps(prt_dlg.hDC, NUMCOLORS); |
1435 psettings->has_color = (GetDeviceCaps(prt_dlg.hDC, BITSPIXEL) > 1 | 1434 psettings->has_color = (GetDeviceCaps(prt_dlg.hDC, BITSPIXEL) > 1 |
1436 || GetDeviceCaps(prt_dlg.hDC, PLANES) > 1 | 1435 || GetDeviceCaps(prt_dlg.hDC, PLANES) > 1 |
1437 || i > 2 || i == -1); | 1436 || i > 2 || i == -1); |
1438 | 1437 |
1439 /* Ensure all font styles are baseline aligned */ | 1438 // Ensure all font styles are baseline aligned |
1440 SetTextAlign(prt_dlg.hDC, TA_BASELINE|TA_LEFT); | 1439 SetTextAlign(prt_dlg.hDC, TA_BASELINE|TA_LEFT); |
1441 | 1440 |
1442 /* | 1441 /* |
1443 * On some windows systems the nCopies parameter is not | 1442 * On some windows systems the nCopies parameter is not |
1444 * passed back correctly. It must be retrieved from the | 1443 * passed back correctly. It must be retrieved from the |
1535 | 1534 |
1536 if (err) | 1535 if (err) |
1537 { | 1536 { |
1538 char_u *buf; | 1537 char_u *buf; |
1539 | 1538 |
1540 /* I suspect FormatMessage() doesn't work for values returned by | 1539 // I suspect FormatMessage() doesn't work for values returned by |
1541 * CommDlgExtendedError(). What does? */ | 1540 // CommDlgExtendedError(). What does? |
1542 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | | 1541 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
1543 FORMAT_MESSAGE_FROM_SYSTEM | | 1542 FORMAT_MESSAGE_FROM_SYSTEM | |
1544 FORMAT_MESSAGE_IGNORE_INSERTS, | 1543 FORMAT_MESSAGE_IGNORE_INSERTS, |
1545 NULL, err, 0, (LPTSTR)(&buf), 0, NULL); | 1544 NULL, err, 0, (LPTSTR)(&buf), 0, NULL); |
1546 semsg(_("E238: Print error: %s"), | 1545 semsg(_("E238: Print error: %s"), |
1547 buf == NULL ? (char_u *)_("Unknown") : buf); | 1546 buf == NULL ? (char_u *)_("Unknown") : buf); |
1548 LocalFree((LPVOID)(buf)); | 1547 LocalFree((LPVOID)(buf)); |
1549 } | 1548 } |
1550 else | 1549 else |
1551 msg_clr_eos(); /* Maybe canceled */ | 1550 msg_clr_eos(); // Maybe canceled |
1552 | 1551 |
1553 mch_print_cleanup(); | 1552 mch_print_cleanup(); |
1554 return FALSE; | 1553 return FALSE; |
1555 } | 1554 } |
1556 } | 1555 } |
1580 ret = StartDocW(prt_dlg.hDC, &di); | 1579 ret = StartDocW(prt_dlg.hDC, &di); |
1581 vim_free(wp); | 1580 vim_free(wp); |
1582 } | 1581 } |
1583 | 1582 |
1584 # ifdef FEAT_GUI | 1583 # ifdef FEAT_GUI |
1585 /* Give focus back to main window (when using MDI). */ | 1584 // Give focus back to main window (when using MDI). |
1586 # ifdef VIMDLL | 1585 # ifdef VIMDLL |
1587 if (gui.in_use) | 1586 if (gui.in_use) |
1588 # endif | 1587 # endif |
1589 SetFocus(s_hwnd); | 1588 SetFocus(s_hwnd); |
1590 # endif | 1589 # endif |
1649 TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin, | 1648 TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin, |
1650 prt_pos_y + prt_top_margin, wp, wlen); | 1649 prt_pos_y + prt_top_margin, wp, wlen); |
1651 GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz); | 1650 GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz); |
1652 vim_free(wp); | 1651 vim_free(wp); |
1653 prt_pos_x += (sz.cx - prt_tm.tmOverhang); | 1652 prt_pos_x += (sz.cx - prt_tm.tmOverhang); |
1654 /* This is wrong when printing spaces for a TAB. */ | 1653 // This is wrong when printing spaces for a TAB. |
1655 if (p[len] != NUL) | 1654 if (p[len] != NUL) |
1656 { | 1655 { |
1657 wlen = mb_ptr2len(p + len); | 1656 wlen = mb_ptr2len(p + len); |
1658 wp = enc_to_utf16(p + len, &wlen); | 1657 wp = enc_to_utf16(p + len, &wlen); |
1659 if (wp != NULL) | 1658 if (wp != NULL) |
1692 { | 1691 { |
1693 SetTextColor(prt_dlg.hDC, GetNearestColor(prt_dlg.hDC, | 1692 SetTextColor(prt_dlg.hDC, GetNearestColor(prt_dlg.hDC, |
1694 swap_me((COLORREF)fgcol))); | 1693 swap_me((COLORREF)fgcol))); |
1695 } | 1694 } |
1696 | 1695 |
1697 #endif /*FEAT_PRINTER && !FEAT_POSTSCRIPT*/ | 1696 #endif // FEAT_PRINTER && !FEAT_POSTSCRIPT |
1698 | 1697 |
1699 | 1698 |
1700 | 1699 |
1701 #if defined(FEAT_SHORTCUT) || defined(PROTO) | 1700 #if defined(FEAT_SHORTCUT) || defined(PROTO) |
1702 # ifndef PROTO | 1701 # ifndef PROTO |
1828 char_u *rfname = NULL; | 1827 char_u *rfname = NULL; |
1829 int len; | 1828 int len; |
1830 IShellLinkW *pslw = NULL; | 1829 IShellLinkW *pslw = NULL; |
1831 WIN32_FIND_DATAW ffdw; // we get those free of charge | 1830 WIN32_FIND_DATAW ffdw; // we get those free of charge |
1832 | 1831 |
1833 /* Check if the file name ends in ".lnk". Avoid calling | 1832 // Check if the file name ends in ".lnk". Avoid calling |
1834 * CoCreateInstance(), it's quite slow. */ | 1833 // CoCreateInstance(), it's quite slow. |
1835 if (fname == NULL) | 1834 if (fname == NULL) |
1836 return rfname; | 1835 return rfname; |
1837 len = (int)STRLEN(fname); | 1836 len = (int)STRLEN(fname); |
1838 if (len <= 4 || STRNICMP(fname + len - 4, ".lnk", 4) != 0) | 1837 if (len <= 4 || STRNICMP(fname + len - 4, ".lnk", 4) != 0) |
1839 return rfname; | 1838 return rfname; |
1905 * Bring ourselves to the foreground. Does work if the OS doesn't allow it. | 1904 * Bring ourselves to the foreground. Does work if the OS doesn't allow it. |
1906 */ | 1905 */ |
1907 void | 1906 void |
1908 win32_set_foreground(void) | 1907 win32_set_foreground(void) |
1909 { | 1908 { |
1910 GetConsoleHwnd(); /* get value of s_hwnd */ | 1909 GetConsoleHwnd(); // get value of s_hwnd |
1911 if (s_hwnd != 0) | 1910 if (s_hwnd != 0) |
1912 SetForegroundWindow(s_hwnd); | 1911 SetForegroundWindow(s_hwnd); |
1913 } | 1912 } |
1914 #endif | 1913 #endif |
1915 | 1914 |
1918 * Client-server code for Vim | 1917 * Client-server code for Vim |
1919 * | 1918 * |
1920 * Originally written by Paul Moore | 1919 * Originally written by Paul Moore |
1921 */ | 1920 */ |
1922 | 1921 |
1923 /* In order to handle inter-process messages, we need to have a window. But | 1922 // In order to handle inter-process messages, we need to have a window. But |
1924 * the functions in this module can be called before the main GUI window is | 1923 // the functions in this module can be called before the main GUI window is |
1925 * created (and may also be called in the console version, where there is no | 1924 // created (and may also be called in the console version, where there is no |
1926 * GUI window at all). | 1925 // GUI window at all). |
1927 * | 1926 // |
1928 * So we create a hidden window, and arrange to destroy it on exit. | 1927 // So we create a hidden window, and arrange to destroy it on exit. |
1929 */ | 1928 HWND message_window = 0; // window that's handling messages |
1930 HWND message_window = 0; /* window that's handling messages */ | |
1931 | 1929 |
1932 # define VIM_CLASSNAME "VIM_MESSAGES" | 1930 # define VIM_CLASSNAME "VIM_MESSAGES" |
1933 # define VIM_CLASSNAME_LEN (sizeof(VIM_CLASSNAME) - 1) | 1931 # define VIM_CLASSNAME_LEN (sizeof(VIM_CLASSNAME) - 1) |
1934 | 1932 |
1935 /* Communication is via WM_COPYDATA messages. The message type is send in | 1933 // Communication is via WM_COPYDATA messages. The message type is send in |
1936 * the dwData parameter. Types are defined here. */ | 1934 // the dwData parameter. Types are defined here. |
1937 # define COPYDATA_KEYS 0 | 1935 # define COPYDATA_KEYS 0 |
1938 # define COPYDATA_REPLY 1 | 1936 # define COPYDATA_REPLY 1 |
1939 # define COPYDATA_EXPR 10 | 1937 # define COPYDATA_EXPR 10 |
1940 # define COPYDATA_RESULT 11 | 1938 # define COPYDATA_RESULT 11 |
1941 # define COPYDATA_ERROR_RESULT 12 | 1939 # define COPYDATA_ERROR_RESULT 12 |
1942 # define COPYDATA_ENCODING 20 | 1940 # define COPYDATA_ENCODING 20 |
1943 | 1941 |
1944 /* This is a structure containing a server HWND and its name. */ | 1942 // This is a structure containing a server HWND and its name. |
1945 struct server_id | 1943 struct server_id |
1946 { | 1944 { |
1947 HWND hwnd; | 1945 HWND hwnd; |
1948 char_u *name; | 1946 char_u *name; |
1949 }; | 1947 }; |
1950 | 1948 |
1951 /* Last received 'encoding' that the client uses. */ | 1949 // Last received 'encoding' that the client uses. |
1952 static char_u *client_enc = NULL; | 1950 static char_u *client_enc = NULL; |
1953 | 1951 |
1954 /* | 1952 /* |
1955 * Tell the other side what encoding we are using. | 1953 * Tell the other side what encoding we are using. |
1956 * Errors are ignored. | 1954 * Errors are ignored. |
1995 static LRESULT CALLBACK | 1993 static LRESULT CALLBACK |
1996 Messaging_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | 1994 Messaging_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
1997 { | 1995 { |
1998 if (msg == WM_COPYDATA) | 1996 if (msg == WM_COPYDATA) |
1999 { | 1997 { |
2000 /* This is a message from another Vim. The dwData member of the | 1998 // This is a message from another Vim. The dwData member of the |
2001 * COPYDATASTRUCT determines the type of message: | 1999 // COPYDATASTRUCT determines the type of message: |
2002 * COPYDATA_ENCODING: | 2000 // COPYDATA_ENCODING: |
2003 * The encoding that the client uses. Following messages will | 2001 // The encoding that the client uses. Following messages will |
2004 * use this encoding, convert if needed. | 2002 // use this encoding, convert if needed. |
2005 * COPYDATA_KEYS: | 2003 // COPYDATA_KEYS: |
2006 * A key sequence. We are a server, and a client wants these keys | 2004 // A key sequence. We are a server, and a client wants these keys |
2007 * adding to the input queue. | 2005 // adding to the input queue. |
2008 * COPYDATA_REPLY: | 2006 // COPYDATA_REPLY: |
2009 * A reply. We are a client, and a server has sent this message | 2007 // A reply. We are a client, and a server has sent this message |
2010 * in response to a request. (server2client()) | 2008 // in response to a request. (server2client()) |
2011 * COPYDATA_EXPR: | 2009 // COPYDATA_EXPR: |
2012 * An expression. We are a server, and a client wants us to | 2010 // An expression. We are a server, and a client wants us to |
2013 * evaluate this expression. | 2011 // evaluate this expression. |
2014 * COPYDATA_RESULT: | 2012 // COPYDATA_RESULT: |
2015 * A reply. We are a client, and a server has sent this message | 2013 // A reply. We are a client, and a server has sent this message |
2016 * in response to a COPYDATA_EXPR. | 2014 // in response to a COPYDATA_EXPR. |
2017 * COPYDATA_ERROR_RESULT: | 2015 // COPYDATA_ERROR_RESULT: |
2018 * A reply. We are a client, and a server has sent this message | 2016 // A reply. We are a client, and a server has sent this message |
2019 * in response to a COPYDATA_EXPR that failed to evaluate. | 2017 // in response to a COPYDATA_EXPR that failed to evaluate. |
2020 */ | |
2021 COPYDATASTRUCT *data = (COPYDATASTRUCT*)lParam; | 2018 COPYDATASTRUCT *data = (COPYDATASTRUCT*)lParam; |
2022 HWND sender = (HWND)wParam; | 2019 HWND sender = (HWND)wParam; |
2023 COPYDATASTRUCT reply; | 2020 COPYDATASTRUCT reply; |
2024 char_u *res; | 2021 char_u *res; |
2025 int retval; | 2022 int retval; |
2027 char_u *tofree; | 2024 char_u *tofree; |
2028 | 2025 |
2029 switch (data->dwData) | 2026 switch (data->dwData) |
2030 { | 2027 { |
2031 case COPYDATA_ENCODING: | 2028 case COPYDATA_ENCODING: |
2032 /* Remember the encoding that the client uses. */ | 2029 // Remember the encoding that the client uses. |
2033 vim_free(client_enc); | 2030 vim_free(client_enc); |
2034 client_enc = enc_canonize((char_u *)data->lpData); | 2031 client_enc = enc_canonize((char_u *)data->lpData); |
2035 return 1; | 2032 return 1; |
2036 | 2033 |
2037 case COPYDATA_KEYS: | 2034 case COPYDATA_KEYS: |
2038 /* Remember who sent this, for <client> */ | 2035 // Remember who sent this, for <client> |
2039 clientWindow = sender; | 2036 clientWindow = sender; |
2040 | 2037 |
2041 /* Add the received keys to the input buffer. The loop waiting | 2038 // Add the received keys to the input buffer. The loop waiting |
2042 * for the user to do something should check the input buffer. */ | 2039 // for the user to do something should check the input buffer. |
2043 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); | 2040 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); |
2044 server_to_input_buf(str); | 2041 server_to_input_buf(str); |
2045 vim_free(tofree); | 2042 vim_free(tofree); |
2046 | 2043 |
2047 # ifdef FEAT_GUI | 2044 # ifdef FEAT_GUI |
2048 /* Wake up the main GUI loop. */ | 2045 // Wake up the main GUI loop. |
2049 # ifdef VIMDLL | 2046 # ifdef VIMDLL |
2050 if (gui.in_use) | 2047 if (gui.in_use) |
2051 # endif | 2048 # endif |
2052 if (s_hwnd != 0) | 2049 if (s_hwnd != 0) |
2053 PostMessage(s_hwnd, WM_NULL, 0, 0); | 2050 PostMessage(s_hwnd, WM_NULL, 0, 0); |
2054 # endif | 2051 # endif |
2055 return 1; | 2052 return 1; |
2056 | 2053 |
2057 case COPYDATA_EXPR: | 2054 case COPYDATA_EXPR: |
2058 /* Remember who sent this, for <client> */ | 2055 // Remember who sent this, for <client> |
2059 clientWindow = sender; | 2056 clientWindow = sender; |
2060 | 2057 |
2061 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); | 2058 str = serverConvert(client_enc, (char_u *)data->lpData, &tofree); |
2062 res = eval_client_expr_to_string(str); | 2059 res = eval_client_expr_to_string(str); |
2063 | 2060 |
2112 return 0; | 2109 return 0; |
2113 } | 2110 } |
2114 | 2111 |
2115 else if (msg == WM_ACTIVATE && wParam == WA_ACTIVE) | 2112 else if (msg == WM_ACTIVATE && wParam == WA_ACTIVE) |
2116 { | 2113 { |
2117 /* When the message window is activated (brought to the foreground), | 2114 // When the message window is activated (brought to the foreground), |
2118 * this actually applies to the text window. */ | 2115 // this actually applies to the text window. |
2119 # if !defined(FEAT_GUI) || defined(VIMDLL) | 2116 # if !defined(FEAT_GUI) || defined(VIMDLL) |
2120 # ifdef VIMDLL | 2117 # ifdef VIMDLL |
2121 if (!gui.in_use) | 2118 if (!gui.in_use) |
2122 # endif | 2119 # endif |
2123 GetConsoleHwnd(); /* get value of s_hwnd */ | 2120 GetConsoleHwnd(); // get value of s_hwnd |
2124 # endif | 2121 # endif |
2125 if (s_hwnd != 0) | 2122 if (s_hwnd != 0) |
2126 { | 2123 { |
2127 SetForegroundWindow(s_hwnd); | 2124 SetForegroundWindow(s_hwnd); |
2128 return 0; | 2125 return 0; |
2139 void | 2136 void |
2140 serverInitMessaging(void) | 2137 serverInitMessaging(void) |
2141 { | 2138 { |
2142 WNDCLASS wndclass; | 2139 WNDCLASS wndclass; |
2143 | 2140 |
2144 /* Clean up on exit */ | 2141 // Clean up on exit |
2145 atexit(CleanUpMessaging); | 2142 atexit(CleanUpMessaging); |
2146 | 2143 |
2147 /* Register a window class - we only really care | 2144 // Register a window class - we only really care |
2148 * about the window procedure | 2145 // about the window procedure |
2149 */ | |
2150 wndclass.style = 0; | 2146 wndclass.style = 0; |
2151 wndclass.lpfnWndProc = Messaging_WndProc; | 2147 wndclass.lpfnWndProc = Messaging_WndProc; |
2152 wndclass.cbClsExtra = 0; | 2148 wndclass.cbClsExtra = 0; |
2153 wndclass.cbWndExtra = 0; | 2149 wndclass.cbWndExtra = 0; |
2154 wndclass.hInstance = g_hinst; | 2150 wndclass.hInstance = g_hinst; |
2157 wndclass.hbrBackground = NULL; | 2153 wndclass.hbrBackground = NULL; |
2158 wndclass.lpszMenuName = NULL; | 2154 wndclass.lpszMenuName = NULL; |
2159 wndclass.lpszClassName = VIM_CLASSNAME; | 2155 wndclass.lpszClassName = VIM_CLASSNAME; |
2160 RegisterClass(&wndclass); | 2156 RegisterClass(&wndclass); |
2161 | 2157 |
2162 /* Create the message window. It will be hidden, so the details don't | 2158 // Create the message window. It will be hidden, so the details don't |
2163 * matter. Don't use WS_OVERLAPPEDWINDOW, it will make a shortcut remove | 2159 // matter. Don't use WS_OVERLAPPEDWINDOW, it will make a shortcut remove |
2164 * focus from gvim. */ | 2160 // focus from gvim. |
2165 message_window = CreateWindow(VIM_CLASSNAME, "", | 2161 message_window = CreateWindow(VIM_CLASSNAME, "", |
2166 WS_POPUPWINDOW | WS_CAPTION, | 2162 WS_POPUPWINDOW | WS_CAPTION, |
2167 CW_USEDEFAULT, CW_USEDEFAULT, | 2163 CW_USEDEFAULT, CW_USEDEFAULT, |
2168 100, 100, NULL, NULL, | 2164 100, 100, NULL, NULL, |
2169 g_hinst, NULL); | 2165 g_hinst, NULL); |
2170 } | 2166 } |
2171 | 2167 |
2172 /* Used by serverSendToVim() to find an alternate server name. */ | 2168 // Used by serverSendToVim() to find an alternate server name. |
2173 static char_u *altname_buf_ptr = NULL; | 2169 static char_u *altname_buf_ptr = NULL; |
2174 | 2170 |
2175 /* | 2171 /* |
2176 * Get the title of the window "hwnd", which is the Vim server name, in | 2172 * Get the title of the window "hwnd", which is the Vim server name, in |
2177 * "name[namelen]" and return the length. | 2173 * "name[namelen]" and return the length. |
2181 getVimServerName(HWND hwnd, char *name, int namelen) | 2177 getVimServerName(HWND hwnd, char *name, int namelen) |
2182 { | 2178 { |
2183 int len; | 2179 int len; |
2184 char buffer[VIM_CLASSNAME_LEN + 1]; | 2180 char buffer[VIM_CLASSNAME_LEN + 1]; |
2185 | 2181 |
2186 /* Ignore windows which aren't Vim message windows */ | 2182 // Ignore windows which aren't Vim message windows |
2187 len = GetClassName(hwnd, buffer, sizeof(buffer)); | 2183 len = GetClassName(hwnd, buffer, sizeof(buffer)); |
2188 if (len != VIM_CLASSNAME_LEN || STRCMP(buffer, VIM_CLASSNAME) != 0) | 2184 if (len != VIM_CLASSNAME_LEN || STRCMP(buffer, VIM_CLASSNAME) != 0) |
2189 return 0; | 2185 return 0; |
2190 | 2186 |
2191 /* Get the title of the window */ | 2187 // Get the title of the window |
2192 return GetWindowText(hwnd, name, namelen); | 2188 return GetWindowText(hwnd, name, namelen); |
2193 } | 2189 } |
2194 | 2190 |
2195 static BOOL CALLBACK | 2191 static BOOL CALLBACK |
2196 enumWindowsGetServer(HWND hwnd, LPARAM lparam) | 2192 enumWindowsGetServer(HWND hwnd, LPARAM lparam) |
2197 { | 2193 { |
2198 struct server_id *id = (struct server_id *)lparam; | 2194 struct server_id *id = (struct server_id *)lparam; |
2199 char server[MAX_PATH]; | 2195 char server[MAX_PATH]; |
2200 | 2196 |
2201 /* Get the title of the window */ | 2197 // Get the title of the window |
2202 if (getVimServerName(hwnd, server, sizeof(server)) == 0) | 2198 if (getVimServerName(hwnd, server, sizeof(server)) == 0) |
2203 return TRUE; | 2199 return TRUE; |
2204 | 2200 |
2205 /* If this is the server we're looking for, return its HWND */ | 2201 // If this is the server we're looking for, return its HWND |
2206 if (STRICMP(server, id->name) == 0) | 2202 if (STRICMP(server, id->name) == 0) |
2207 { | 2203 { |
2208 id->hwnd = hwnd; | 2204 id->hwnd = hwnd; |
2209 return FALSE; | 2205 return FALSE; |
2210 } | 2206 } |
2211 | 2207 |
2212 /* If we are looking for an alternate server, remember this name. */ | 2208 // If we are looking for an alternate server, remember this name. |
2213 if (altname_buf_ptr != NULL | 2209 if (altname_buf_ptr != NULL |
2214 && STRNICMP(server, id->name, STRLEN(id->name)) == 0 | 2210 && STRNICMP(server, id->name, STRLEN(id->name)) == 0 |
2215 && vim_isdigit(server[STRLEN(id->name)])) | 2211 && vim_isdigit(server[STRLEN(id->name)])) |
2216 { | 2212 { |
2217 STRCPY(altname_buf_ptr, server); | 2213 STRCPY(altname_buf_ptr, server); |
2218 altname_buf_ptr = NULL; /* don't use another name */ | 2214 altname_buf_ptr = NULL; // don't use another name |
2219 } | 2215 } |
2220 | 2216 |
2221 /* Otherwise, keep looking */ | 2217 // Otherwise, keep looking |
2222 return TRUE; | 2218 return TRUE; |
2223 } | 2219 } |
2224 | 2220 |
2225 static BOOL CALLBACK | 2221 static BOOL CALLBACK |
2226 enumWindowsGetNames(HWND hwnd, LPARAM lparam) | 2222 enumWindowsGetNames(HWND hwnd, LPARAM lparam) |
2227 { | 2223 { |
2228 garray_T *ga = (garray_T *)lparam; | 2224 garray_T *ga = (garray_T *)lparam; |
2229 char server[MAX_PATH]; | 2225 char server[MAX_PATH]; |
2230 | 2226 |
2231 /* Get the title of the window */ | 2227 // Get the title of the window |
2232 if (getVimServerName(hwnd, server, sizeof(server)) == 0) | 2228 if (getVimServerName(hwnd, server, sizeof(server)) == 0) |
2233 return TRUE; | 2229 return TRUE; |
2234 | 2230 |
2235 /* Add the name to the list */ | 2231 // Add the name to the list |
2236 ga_concat(ga, (char_u *)server); | 2232 ga_concat(ga, (char_u *)server); |
2237 ga_concat(ga, (char_u *)"\n"); | 2233 ga_concat(ga, (char_u *)"\n"); |
2238 return TRUE; | 2234 return TRUE; |
2239 } | 2235 } |
2240 | 2236 |
2260 if ((ew->lpEnumFunc)(hwnd, ew->lParam)) | 2256 if ((ew->lpEnumFunc)(hwnd, ew->lParam)) |
2261 return TRUE; | 2257 return TRUE; |
2262 return EnumChildWindows(hwnd, enum_windows_child, lParam); | 2258 return EnumChildWindows(hwnd, enum_windows_child, lParam); |
2263 } | 2259 } |
2264 | 2260 |
2265 /* Enumerate all windows including children. */ | 2261 /* |
2262 * Enumerate all windows including children. | |
2263 */ | |
2266 static BOOL | 2264 static BOOL |
2267 enum_windows(WNDENUMPROC lpEnumFunc, LPARAM lParam) | 2265 enum_windows(WNDENUMPROC lpEnumFunc, LPARAM lParam) |
2268 { | 2266 { |
2269 struct enum_windows_s ew; | 2267 struct enum_windows_s ew; |
2270 | 2268 |
2292 char_u *ok_name; | 2290 char_u *ok_name; |
2293 HWND hwnd = 0; | 2291 HWND hwnd = 0; |
2294 int i = 0; | 2292 int i = 0; |
2295 char_u *p; | 2293 char_u *p; |
2296 | 2294 |
2297 /* Leave enough space for a 9-digit suffix to ensure uniqueness! */ | 2295 // Leave enough space for a 9-digit suffix to ensure uniqueness! |
2298 ok_name = alloc(STRLEN(name) + 10); | 2296 ok_name = alloc(STRLEN(name) + 10); |
2299 | 2297 |
2300 STRCPY(ok_name, name); | 2298 STRCPY(ok_name, name); |
2301 p = ok_name + STRLEN(name); | 2299 p = ok_name + STRLEN(name); |
2302 | 2300 |
2303 for (;;) | 2301 for (;;) |
2304 { | 2302 { |
2305 /* This is inefficient - we're doing an EnumWindows loop for each | 2303 // This is inefficient - we're doing an EnumWindows loop for each |
2306 * possible name. It would be better to grab all names in one go, | 2304 // possible name. It would be better to grab all names in one go, |
2307 * and scan the list each time... | 2305 // and scan the list each time... |
2308 */ | |
2309 hwnd = findServer(ok_name); | 2306 hwnd = findServer(ok_name); |
2310 if (hwnd == 0) | 2307 if (hwnd == 0) |
2311 break; | 2308 break; |
2312 | 2309 |
2313 ++i; | 2310 ++i; |
2319 | 2316 |
2320 if (hwnd != 0) | 2317 if (hwnd != 0) |
2321 vim_free(ok_name); | 2318 vim_free(ok_name); |
2322 else | 2319 else |
2323 { | 2320 { |
2324 /* Remember the name */ | 2321 // Remember the name |
2325 serverName = ok_name; | 2322 serverName = ok_name; |
2326 # ifdef FEAT_TITLE | 2323 # ifdef FEAT_TITLE |
2327 need_maketitle = TRUE; /* update Vim window title later */ | 2324 need_maketitle = TRUE; // update Vim window title later |
2328 # endif | 2325 # endif |
2329 | 2326 |
2330 /* Update the message window title */ | 2327 // Update the message window title |
2331 SetWindowText(message_window, (LPCSTR)ok_name); | 2328 SetWindowText(message_window, (LPCSTR)ok_name); |
2332 | 2329 |
2333 # ifdef FEAT_EVAL | 2330 # ifdef FEAT_EVAL |
2334 /* Set the servername variable */ | 2331 // Set the servername variable |
2335 set_vim_var_string(VV_SEND_SERVER, serverName, -1); | 2332 set_vim_var_string(VV_SEND_SERVER, serverName, -1); |
2336 # endif | 2333 # endif |
2337 } | 2334 } |
2338 } | 2335 } |
2339 | 2336 |
2350 return ga.ga_data; | 2347 return ga.ga_data; |
2351 } | 2348 } |
2352 | 2349 |
2353 int | 2350 int |
2354 serverSendReply( | 2351 serverSendReply( |
2355 char_u *name, /* Where to send. */ | 2352 char_u *name, // Where to send. |
2356 char_u *reply) /* What to send. */ | 2353 char_u *reply) // What to send. |
2357 { | 2354 { |
2358 HWND target; | 2355 HWND target; |
2359 COPYDATASTRUCT data; | 2356 COPYDATASTRUCT data; |
2360 long_u n = 0; | 2357 long_u n = 0; |
2361 | 2358 |
2362 /* The "name" argument is a magic cookie obtained from expand("<client>"). | 2359 // The "name" argument is a magic cookie obtained from expand("<client>"). |
2363 * It should be of the form 0xXXXXX - i.e. a C hex literal, which is the | 2360 // It should be of the form 0xXXXXX - i.e. a C hex literal, which is the |
2364 * value of the client's message window HWND. | 2361 // value of the client's message window HWND. |
2365 */ | |
2366 sscanf((char *)name, SCANF_HEX_LONG_U, &n); | 2362 sscanf((char *)name, SCANF_HEX_LONG_U, &n); |
2367 if (n == 0) | 2363 if (n == 0) |
2368 return -1; | 2364 return -1; |
2369 | 2365 |
2370 target = (HWND)n; | 2366 target = (HWND)n; |
2383 return -1; | 2379 return -1; |
2384 } | 2380 } |
2385 | 2381 |
2386 int | 2382 int |
2387 serverSendToVim( | 2383 serverSendToVim( |
2388 char_u *name, /* Where to send. */ | 2384 char_u *name, // Where to send. |
2389 char_u *cmd, /* What to send. */ | 2385 char_u *cmd, // What to send. |
2390 char_u **result, /* Result of eval'ed expression */ | 2386 char_u **result, // Result of eval'ed expression |
2391 void *ptarget, /* HWND of server */ | 2387 void *ptarget, // HWND of server |
2392 int asExpr, /* Expression or keys? */ | 2388 int asExpr, // Expression or keys? |
2393 int timeout, /* timeout in seconds or zero */ | 2389 int timeout, // timeout in seconds or zero |
2394 int silent) /* don't complain about no server */ | 2390 int silent) // don't complain about no server |
2395 { | 2391 { |
2396 HWND target; | 2392 HWND target; |
2397 COPYDATASTRUCT data; | 2393 COPYDATASTRUCT data; |
2398 char_u *retval = NULL; | 2394 char_u *retval = NULL; |
2399 int retcode = 0; | 2395 int retcode = 0; |
2400 char_u altname_buf[MAX_PATH]; | 2396 char_u altname_buf[MAX_PATH]; |
2401 | 2397 |
2402 /* Execute locally if no display or target is ourselves */ | 2398 // Execute locally if no display or target is ourselves |
2403 if (serverName != NULL && STRICMP(name, serverName) == 0) | 2399 if (serverName != NULL && STRICMP(name, serverName) == 0) |
2404 return sendToLocalVim(cmd, asExpr, result); | 2400 return sendToLocalVim(cmd, asExpr, result); |
2405 | 2401 |
2406 /* If the server name does not end in a digit then we look for an | 2402 // If the server name does not end in a digit then we look for an |
2407 * alternate name. e.g. when "name" is GVIM the we may find GVIM2. */ | 2403 // alternate name. e.g. when "name" is GVIM the we may find GVIM2. |
2408 if (STRLEN(name) > 1 && !vim_isdigit(name[STRLEN(name) - 1])) | 2404 if (STRLEN(name) > 1 && !vim_isdigit(name[STRLEN(name) - 1])) |
2409 altname_buf_ptr = altname_buf; | 2405 altname_buf_ptr = altname_buf; |
2410 altname_buf[0] = NUL; | 2406 altname_buf[0] = NUL; |
2411 target = findServer(name); | 2407 target = findServer(name); |
2412 altname_buf_ptr = NULL; | 2408 altname_buf_ptr = NULL; |
2413 if (target == 0 && altname_buf[0] != NUL) | 2409 if (target == 0 && altname_buf[0] != NUL) |
2414 /* Use another server name we found. */ | 2410 // Use another server name we found. |
2415 target = findServer(altname_buf); | 2411 target = findServer(altname_buf); |
2416 | 2412 |
2417 if (target == 0) | 2413 if (target == 0) |
2418 { | 2414 { |
2419 if (!silent) | 2415 if (!silent) |
2437 retval = serverGetReply(target, &retcode, TRUE, TRUE, timeout); | 2433 retval = serverGetReply(target, &retcode, TRUE, TRUE, timeout); |
2438 | 2434 |
2439 if (result == NULL) | 2435 if (result == NULL) |
2440 vim_free(retval); | 2436 vim_free(retval); |
2441 else | 2437 else |
2442 *result = retval; /* Caller assumes responsibility for freeing */ | 2438 *result = retval; // Caller assumes responsibility for freeing |
2443 | 2439 |
2444 return retcode; | 2440 return retcode; |
2445 } | 2441 } |
2446 | 2442 |
2447 /* | 2443 /* |
2454 | 2450 |
2455 if (target != 0) | 2451 if (target != 0) |
2456 SetForegroundWindow(target); | 2452 SetForegroundWindow(target); |
2457 } | 2453 } |
2458 | 2454 |
2459 /* Replies from server need to be stored until the client picks them up via | 2455 // Replies from server need to be stored until the client picks them up via |
2460 * remote_read(). So we maintain a list of server-id/reply pairs. | 2456 // remote_read(). So we maintain a list of server-id/reply pairs. |
2461 * Note that there could be multiple replies from one server pending if the | 2457 // Note that there could be multiple replies from one server pending if the |
2462 * client is slow picking them up. | 2458 // client is slow picking them up. |
2463 * We just store the replies in a simple list. When we remove an entry, we | 2459 // We just store the replies in a simple list. When we remove an entry, we |
2464 * move list entries down to fill the gap. | 2460 // move list entries down to fill the gap. |
2465 * The server ID is simply the HWND. | 2461 // The server ID is simply the HWND. |
2466 */ | |
2467 typedef struct | 2462 typedef struct |
2468 { | 2463 { |
2469 HWND server; /* server window */ | 2464 HWND server; // server window |
2470 char_u *reply; /* reply string */ | 2465 char_u *reply; // reply string |
2471 int expr_result; /* 0 for REPLY, 1 for RESULT 2 for error */ | 2466 int expr_result; // 0 for REPLY, 1 for RESULT 2 for error |
2472 } reply_T; | 2467 } reply_T; |
2473 | 2468 |
2474 static garray_T reply_list = {0, 0, sizeof(reply_T), 5, 0}; | 2469 static garray_T reply_list = {0, 0, sizeof(reply_T), 5, 0}; |
2475 | 2470 |
2476 # define REPLY_ITEM(i) ((reply_T *)(reply_list.ga_data) + (i)) | 2471 # define REPLY_ITEM(i) ((reply_T *)(reply_list.ga_data) + (i)) |
2477 # define REPLY_COUNT (reply_list.ga_len) | 2472 # define REPLY_COUNT (reply_list.ga_len) |
2478 | 2473 |
2479 /* Flag which is used to wait for a reply */ | 2474 // Flag which is used to wait for a reply |
2480 static int reply_received = 0; | 2475 static int reply_received = 0; |
2481 | 2476 |
2482 /* | 2477 /* |
2483 * Store a reply. "reply" must be allocated memory (or NULL). | 2478 * Store a reply. "reply" must be allocated memory (or NULL). |
2484 */ | 2479 */ |
2518 reply_T *rep; | 2513 reply_T *rep; |
2519 int did_process = FALSE; | 2514 int did_process = FALSE; |
2520 time_t start; | 2515 time_t start; |
2521 time_t now; | 2516 time_t now; |
2522 | 2517 |
2523 /* When waiting, loop until the message waiting for is received. */ | 2518 // When waiting, loop until the message waiting for is received. |
2524 time(&start); | 2519 time(&start); |
2525 for (;;) | 2520 for (;;) |
2526 { | 2521 { |
2527 /* Reset this here, in case a message arrives while we are going | 2522 // Reset this here, in case a message arrives while we are going |
2528 * through the already received messages. */ | 2523 // through the already received messages. |
2529 reply_received = 0; | 2524 reply_received = 0; |
2530 | 2525 |
2531 for (i = 0; i < REPLY_COUNT; ++i) | 2526 for (i = 0; i < REPLY_COUNT; ++i) |
2532 { | 2527 { |
2533 rep = REPLY_ITEM(i); | 2528 rep = REPLY_ITEM(i); |
2534 if (rep->server == server | 2529 if (rep->server == server |
2535 && ((rep->expr_result != 0) == (expr_res != NULL))) | 2530 && ((rep->expr_result != 0) == (expr_res != NULL))) |
2536 { | 2531 { |
2537 /* Save the values we've found for later */ | 2532 // Save the values we've found for later |
2538 reply = rep->reply; | 2533 reply = rep->reply; |
2539 if (expr_res != NULL) | 2534 if (expr_res != NULL) |
2540 *expr_res = rep->expr_result == 1 ? 0 : -1; | 2535 *expr_res = rep->expr_result == 1 ? 0 : -1; |
2541 | 2536 |
2542 if (remove) | 2537 if (remove) |
2543 { | 2538 { |
2544 /* Move the rest of the list down to fill the gap */ | 2539 // Move the rest of the list down to fill the gap |
2545 mch_memmove(rep, rep + 1, | 2540 mch_memmove(rep, rep + 1, |
2546 (REPLY_COUNT - i - 1) * sizeof(reply_T)); | 2541 (REPLY_COUNT - i - 1) * sizeof(reply_T)); |
2547 --REPLY_COUNT; | 2542 --REPLY_COUNT; |
2548 } | 2543 } |
2549 | 2544 |
2550 /* Return the reply to the caller, who takes on responsibility | 2545 // Return the reply to the caller, who takes on responsibility |
2551 * for freeing it if "remove" is TRUE. */ | 2546 // for freeing it if "remove" is TRUE. |
2552 return reply; | 2547 return reply; |
2553 } | 2548 } |
2554 } | 2549 } |
2555 | 2550 |
2556 /* If we got here, we didn't find a reply. Return immediately if the | 2551 // If we got here, we didn't find a reply. Return immediately if the |
2557 * "wait" parameter isn't set. */ | 2552 // "wait" parameter isn't set. |
2558 if (!wait) | 2553 if (!wait) |
2559 { | 2554 { |
2560 /* Process pending messages once. Without this, looping on | 2555 // Process pending messages once. Without this, looping on |
2561 * remote_peek() would never get the reply. */ | 2556 // remote_peek() would never get the reply. |
2562 if (!did_process) | 2557 if (!did_process) |
2563 { | 2558 { |
2564 did_process = TRUE; | 2559 did_process = TRUE; |
2565 serverProcessPendingMessages(); | 2560 serverProcessPendingMessages(); |
2566 continue; | 2561 continue; |
2567 } | 2562 } |
2568 break; | 2563 break; |
2569 } | 2564 } |
2570 | 2565 |
2571 /* We need to wait for a reply. Enter a message loop until the | 2566 // We need to wait for a reply. Enter a message loop until the |
2572 * "reply_received" flag gets set. */ | 2567 // "reply_received" flag gets set. |
2573 | 2568 |
2574 /* Loop until we receive a reply */ | 2569 // Loop until we receive a reply |
2575 while (reply_received == 0) | 2570 while (reply_received == 0) |
2576 { | 2571 { |
2577 # ifdef FEAT_TIMERS | 2572 # ifdef FEAT_TIMERS |
2578 /* TODO: use the return value to decide how long to wait. */ | 2573 // TODO: use the return value to decide how long to wait. |
2579 check_due_timer(); | 2574 check_due_timer(); |
2580 # endif | 2575 # endif |
2581 time(&now); | 2576 time(&now); |
2582 if (timeout > 0 && (now - start) >= timeout) | 2577 if (timeout > 0 && (now - start) >= timeout) |
2583 break; | 2578 break; |
2584 | 2579 |
2585 /* Wait for a SendMessage() call to us. This could be the reply | 2580 // Wait for a SendMessage() call to us. This could be the reply |
2586 * we are waiting for. Use a timeout of a second, to catch the | 2581 // we are waiting for. Use a timeout of a second, to catch the |
2587 * situation that the server died unexpectedly. */ | 2582 // situation that the server died unexpectedly. |
2588 MsgWaitForMultipleObjects(0, NULL, TRUE, 1000, QS_ALLINPUT); | 2583 MsgWaitForMultipleObjects(0, NULL, TRUE, 1000, QS_ALLINPUT); |
2589 | 2584 |
2590 /* If the server has died, give up */ | 2585 // If the server has died, give up |
2591 if (!IsWindow(server)) | 2586 if (!IsWindow(server)) |
2592 return NULL; | 2587 return NULL; |
2593 | 2588 |
2594 serverProcessPendingMessages(); | 2589 serverProcessPendingMessages(); |
2595 } | 2590 } |
2611 TranslateMessage(&msg); | 2606 TranslateMessage(&msg); |
2612 pDispatchMessage(&msg); | 2607 pDispatchMessage(&msg); |
2613 } | 2608 } |
2614 } | 2609 } |
2615 | 2610 |
2616 #endif /* FEAT_CLIENTSERVER */ | 2611 #endif // FEAT_CLIENTSERVER |
2617 | 2612 |
2618 #if defined(FEAT_GUI) || (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) \ | 2613 #if defined(FEAT_GUI) || (defined(FEAT_PRINTER) && !defined(FEAT_POSTSCRIPT)) \ |
2619 || defined(PROTO) | 2614 || defined(PROTO) |
2620 | 2615 |
2621 struct charset_pair | 2616 struct charset_pair |
2711 static const LOGFONTW s_lfDefault = | 2706 static const LOGFONTW s_lfDefault = |
2712 { | 2707 { |
2713 -12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, | 2708 -12, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, |
2714 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, | 2709 OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, |
2715 PROOF_QUALITY, FIXED_PITCH | FF_DONTCARE, | 2710 PROOF_QUALITY, FIXED_PITCH | FF_DONTCARE, |
2716 L"Fixedsys" /* see _ReadVimIni */ | 2711 L"Fixedsys" // see _ReadVimIni |
2717 }; | 2712 }; |
2718 | 2713 |
2719 // Initialise the "current height" to -12 (same as s_lfDefault) just | 2714 // Initialise the "current height" to -12 (same as s_lfDefault) just |
2720 // in case the user specifies a font in "guifont" with no size before a font | 2715 // in case the user specifies a font in "guifont" with no size before a font |
2721 // with an explicit size has been set. This defaults the size to this value | 2716 // with an explicit size has been set. This defaults the size to this value |
2722 // (-12 equates to roughly 9pt). | 2717 // (-12 equates to roughly 9pt). |
2723 int current_font_height = -12; // also used in gui_w32.c | 2718 int current_font_height = -12; // also used in gui_w32.c |
2724 | 2719 |
2725 /* Convert a string representing a point size into pixels. The string should | 2720 /* |
2721 * Convert a string representing a point size into pixels. The string should | |
2726 * be a positive decimal number, with an optional decimal point (eg, "12", or | 2722 * be a positive decimal number, with an optional decimal point (eg, "12", or |
2727 * "10.5"). The pixel value is returned, and a pointer to the next unconverted | 2723 * "10.5"). The pixel value is returned, and a pointer to the next unconverted |
2728 * character is stored in *end. The flag "vertical" says whether this | 2724 * character is stored in *end. The flag "vertical" says whether this |
2729 * calculation is for a vertical (height) size or a horizontal (width) one. | 2725 * calculation is for a vertical (height) size or a horizontal (width) one. |
2730 */ | 2726 */ |
2740 | 2736 |
2741 while (*str != NUL) | 2737 while (*str != NUL) |
2742 { | 2738 { |
2743 if (*str == L'.' && divisor == 0) | 2739 if (*str == L'.' && divisor == 0) |
2744 { | 2740 { |
2745 /* Start keeping a divisor, for later */ | 2741 // Start keeping a divisor, for later |
2746 divisor = 1; | 2742 divisor = 1; |
2747 } | 2743 } |
2748 else | 2744 else |
2749 { | 2745 { |
2750 if (!VIM_ISDIGIT(*str)) | 2746 if (!VIM_ISDIGIT(*str)) |
2784 ENUMLOGFONTW *elf, | 2780 ENUMLOGFONTW *elf, |
2785 NEWTEXTMETRICW *ntm UNUSED, | 2781 NEWTEXTMETRICW *ntm UNUSED, |
2786 DWORD type UNUSED, | 2782 DWORD type UNUSED, |
2787 LPARAM lparam) | 2783 LPARAM lparam) |
2788 { | 2784 { |
2789 /* Return value: | 2785 // Return value: |
2790 * 0 = terminate now (monospace & ANSI) | 2786 // 0 = terminate now (monospace & ANSI) |
2791 * 1 = continue, still no luck... | 2787 // 1 = continue, still no luck... |
2792 * 2 = continue, but we have an acceptable LOGFONTW | 2788 // 2 = continue, but we have an acceptable LOGFONTW |
2793 * (monospace, not ANSI) | 2789 // (monospace, not ANSI) |
2794 * We use these values, as EnumFontFamilies returns 1 if the | 2790 // We use these values, as EnumFontFamilies returns 1 if the |
2795 * callback function is never called. So, we check the return as | 2791 // callback function is never called. So, we check the return as |
2796 * 0 = perfect, 2 = OK, 1 = no good... | 2792 // 0 = perfect, 2 = OK, 1 = no good... |
2797 * It's not pretty, but it works! | 2793 // It's not pretty, but it works! |
2798 */ | |
2799 | 2794 |
2800 LOGFONTW *lf = (LOGFONTW *)(lparam); | 2795 LOGFONTW *lf = (LOGFONTW *)(lparam); |
2801 | 2796 |
2802 # ifndef FEAT_PROPORTIONAL_FONTS | 2797 # ifndef FEAT_PROPORTIONAL_FONTS |
2803 /* Ignore non-monospace fonts without further ado */ | 2798 // Ignore non-monospace fonts without further ado |
2804 if ((ntm->tmPitchAndFamily & 1) != 0) | 2799 if ((ntm->tmPitchAndFamily & 1) != 0) |
2805 return 1; | 2800 return 1; |
2806 # endif | 2801 # endif |
2807 | 2802 |
2808 /* Remember this LOGFONTW as a "possible" */ | 2803 // Remember this LOGFONTW as a "possible" |
2809 *lf = elf->elfLogFont; | 2804 *lf = elf->elfLogFont; |
2810 | 2805 |
2811 /* Terminate the scan as soon as we find an ANSI font */ | 2806 // Terminate the scan as soon as we find an ANSI font |
2812 if (lf->lfCharSet == ANSI_CHARSET | 2807 if (lf->lfCharSet == ANSI_CHARSET |
2813 || lf->lfCharSet == OEM_CHARSET | 2808 || lf->lfCharSet == OEM_CHARSET |
2814 || lf->lfCharSet == DEFAULT_CHARSET) | 2809 || lf->lfCharSet == DEFAULT_CHARSET) |
2815 return 0; | 2810 return 0; |
2816 | 2811 |
2817 /* Continue the scan - we have a non-ANSI font */ | 2812 // Continue the scan - we have a non-ANSI font |
2818 return 2; | 2813 return 2; |
2819 } | 2814 } |
2820 | 2815 |
2821 static int | 2816 static int |
2822 init_logfont(LOGFONTW *lf) | 2817 init_logfont(LOGFONTW *lf) |
2830 (FONTENUMPROCW)font_enumproc, | 2825 (FONTENUMPROCW)font_enumproc, |
2831 (LPARAM)lf); | 2826 (LPARAM)lf); |
2832 | 2827 |
2833 ReleaseDC(hwnd, hdc); | 2828 ReleaseDC(hwnd, hdc); |
2834 | 2829 |
2835 /* If we couldn't find a usable font, return failure */ | 2830 // If we couldn't find a usable font, return failure |
2836 if (n == 1) | 2831 if (n == 1) |
2837 return FAIL; | 2832 return FAIL; |
2838 | 2833 |
2839 /* Tidy up the rest of the LOGFONTW structure. We set to a basic | 2834 // Tidy up the rest of the LOGFONTW structure. We set to a basic |
2840 * font - get_logfont() sets bold, italic, etc based on the user's | 2835 // font - get_logfont() sets bold, italic, etc based on the user's |
2841 * input. | 2836 // input. |
2842 */ | |
2843 lf->lfHeight = current_font_height; | 2837 lf->lfHeight = current_font_height; |
2844 lf->lfWidth = 0; | 2838 lf->lfWidth = 0; |
2845 lf->lfItalic = FALSE; | 2839 lf->lfItalic = FALSE; |
2846 lf->lfUnderline = FALSE; | 2840 lf->lfUnderline = FALSE; |
2847 lf->lfStrikeOut = FALSE; | 2841 lf->lfStrikeOut = FALSE; |
2848 lf->lfWeight = FW_NORMAL; | 2842 lf->lfWeight = FW_NORMAL; |
2849 | 2843 |
2850 /* Return success */ | 2844 // Return success |
2851 return OK; | 2845 return OK; |
2852 } | 2846 } |
2853 | 2847 |
2854 /* | 2848 /* |
2855 * Compare a UTF-16 string and an ASCII string literally. | 2849 * Compare a UTF-16 string and an ASCII string literally. |
2895 | 2889 |
2896 if (wcscmp(wname, L"*") == 0) | 2890 if (wcscmp(wname, L"*") == 0) |
2897 { | 2891 { |
2898 # if defined(FEAT_GUI_MSWIN) | 2892 # if defined(FEAT_GUI_MSWIN) |
2899 CHOOSEFONTW cf; | 2893 CHOOSEFONTW cf; |
2900 /* if name is "*", bring up std font dialog: */ | 2894 // if name is "*", bring up std font dialog: |
2901 vim_memset(&cf, 0, sizeof(cf)); | 2895 vim_memset(&cf, 0, sizeof(cf)); |
2902 cf.lStructSize = sizeof(cf); | 2896 cf.lStructSize = sizeof(cf); |
2903 cf.hwndOwner = s_hwnd; | 2897 cf.hwndOwner = s_hwnd; |
2904 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT; | 2898 cf.Flags = CF_SCREENFONTS | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT; |
2905 if (lastlf != NULL) | 2899 if (lastlf != NULL) |
2916 * Split name up, it could be <name>:h<height>:w<width> etc. | 2910 * Split name up, it could be <name>:h<height>:w<width> etc. |
2917 */ | 2911 */ |
2918 for (p = wname; *p && *p != L':'; p++) | 2912 for (p = wname; *p && *p != L':'; p++) |
2919 { | 2913 { |
2920 if (p - wname + 1 >= LF_FACESIZE) | 2914 if (p - wname + 1 >= LF_FACESIZE) |
2921 goto theend; /* Name too long */ | 2915 goto theend; // Name too long |
2922 lf->lfFaceName[p - wname] = *p; | 2916 lf->lfFaceName[p - wname] = *p; |
2923 } | 2917 } |
2924 if (p != wname) | 2918 if (p != wname) |
2925 lf->lfFaceName[p - wname] = NUL; | 2919 lf->lfFaceName[p - wname] = NUL; |
2926 | 2920 |
2927 /* First set defaults */ | 2921 // First set defaults |
2928 lf->lfHeight = -12; | 2922 lf->lfHeight = -12; |
2929 lf->lfWidth = 0; | 2923 lf->lfWidth = 0; |
2930 lf->lfWeight = FW_NORMAL; | 2924 lf->lfWeight = FW_NORMAL; |
2931 lf->lfItalic = FALSE; | 2925 lf->lfItalic = FALSE; |
2932 lf->lfUnderline = FALSE; | 2926 lf->lfUnderline = FALSE; |
2950 } | 2944 } |
2951 | 2945 |
2952 while (*p == L':') | 2946 while (*p == L':') |
2953 p++; | 2947 p++; |
2954 | 2948 |
2955 /* Set the values found after ':' */ | 2949 // Set the values found after ':' |
2956 while (*p) | 2950 while (*p) |
2957 { | 2951 { |
2958 switch (*p++) | 2952 switch (*p++) |
2959 { | 2953 { |
2960 case L'h': | 2954 case L'h': |
3027 p++; | 3021 p++; |
3028 } | 3022 } |
3029 ret = OK; | 3023 ret = OK; |
3030 | 3024 |
3031 theend: | 3025 theend: |
3032 /* ron: init lastlf */ | 3026 // ron: init lastlf |
3033 if (ret == OK && printer_dc == NULL) | 3027 if (ret == OK && printer_dc == NULL) |
3034 { | 3028 { |
3035 vim_free(lastlf); | 3029 vim_free(lastlf); |
3036 lastlf = ALLOC_ONE(LOGFONTW); | 3030 lastlf = ALLOC_ONE(LOGFONTW); |
3037 if (lastlf != NULL) | 3031 if (lastlf != NULL) |
3040 vim_free(wname); | 3034 vim_free(wname); |
3041 | 3035 |
3042 return ret; | 3036 return ret; |
3043 } | 3037 } |
3044 | 3038 |
3045 #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */ | 3039 #endif // defined(FEAT_GUI) || defined(FEAT_PRINTER) |
3046 | 3040 |
3047 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) | 3041 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
3048 /* | 3042 /* |
3049 * Initialize the Winsock dll. | 3043 * Initialize the Winsock dll. |
3050 */ | 3044 */ |