Mercurial > vim
comparison src/gui_w32.c @ 158:78423945b251
updated for version 7.0048
author | vimboss |
---|---|
date | Sat, 05 Feb 2005 21:39:53 +0000 |
parents | 19670b05ee32 |
children | 8c60f65311fa |
comparison
equal
deleted
inserted
replaced
157:5242c44962c2 | 158:78423945b251 |
---|---|
2530 int editboxheight; | 2530 int editboxheight; |
2531 int horizWidth = 0; | 2531 int horizWidth = 0; |
2532 int msgheight; | 2532 int msgheight; |
2533 char_u *pstart; | 2533 char_u *pstart; |
2534 char_u *pend; | 2534 char_u *pend; |
2535 char_u *last_white; | |
2535 char_u *tbuffer; | 2536 char_u *tbuffer; |
2536 RECT rect; | 2537 RECT rect; |
2537 HWND hwnd; | 2538 HWND hwnd; |
2538 HDC hdc; | 2539 HDC hdc; |
2539 HFONT font, oldFont; | 2540 HFONT font, oldFont; |
2548 int dlgPaddingY; | 2549 int dlgPaddingY; |
2549 #ifdef USE_SYSMENU_FONT | 2550 #ifdef USE_SYSMENU_FONT |
2550 LOGFONT lfSysmenu; | 2551 LOGFONT lfSysmenu; |
2551 int use_lfSysmenu = FALSE; | 2552 int use_lfSysmenu = FALSE; |
2552 #endif | 2553 #endif |
2554 garray_T ga; | |
2555 int l; | |
2553 | 2556 |
2554 #ifndef NO_CONSOLE | 2557 #ifndef NO_CONSOLE |
2555 /* Don't output anything in silent mode ("ex -s") */ | 2558 /* Don't output anything in silent mode ("ex -s") */ |
2556 if (silent_mode) | 2559 if (silent_mode) |
2557 return dfltbutton; /* return default option */ | 2560 return dfltbutton; /* return default option */ |
2569 if ((type < 0) || (type > VIM_LAST_TYPE)) | 2572 if ((type < 0) || (type > VIM_LAST_TYPE)) |
2570 type = 0; | 2573 type = 0; |
2571 | 2574 |
2572 /* allocate some memory for dialog template */ | 2575 /* allocate some memory for dialog template */ |
2573 /* TODO should compute this really */ | 2576 /* TODO should compute this really */ |
2574 pdlgtemplate = p = (PWORD)LocalAlloc(LPTR, DLG_ALLOC_SIZE); | 2577 pdlgtemplate = p = (PWORD)LocalAlloc(LPTR, |
2578 DLG_ALLOC_SIZE + STRLEN(message)); | |
2575 | 2579 |
2576 if (p == NULL) | 2580 if (p == NULL) |
2577 return -1; | 2581 return -1; |
2578 | 2582 |
2579 /* | 2583 /* |
2639 | 2643 |
2640 /* Minimum width for horizontal button */ | 2644 /* Minimum width for horizontal button */ |
2641 minButtonWidth = GetTextWidth(hdc, "Cancel", 6); | 2645 minButtonWidth = GetTextWidth(hdc, "Cancel", 6); |
2642 | 2646 |
2643 /* Maximum width of a dialog, if possible */ | 2647 /* Maximum width of a dialog, if possible */ |
2644 GetWindowRect(s_hwnd, &rect); | 2648 if (s_hwnd == NULL) |
2645 maxDialogWidth = rect.right - rect.left | 2649 { |
2646 - GetSystemMetrics(SM_CXFRAME) * 2; | 2650 RECT workarea_rect; |
2647 if (maxDialogWidth < DLG_MIN_MAX_WIDTH) | 2651 |
2648 maxDialogWidth = DLG_MIN_MAX_WIDTH; | 2652 /* We don't have a window, use the desktip area. */ |
2649 | 2653 get_work_area(&workarea_rect); |
2650 maxDialogHeight = rect.bottom - rect.top - GetSystemMetrics(SM_CXFRAME) * 2; | 2654 maxDialogWidth = workarea_rect.right - workarea_rect.left - 100; |
2651 if (maxDialogHeight < DLG_MIN_MAX_HEIGHT) | 2655 if (maxDialogWidth > 600) |
2652 maxDialogHeight = DLG_MIN_MAX_HEIGHT; | 2656 maxDialogWidth = 600; |
2653 | 2657 maxDialogHeight = workarea_rect.bottom - workarea_rect.top - 100; |
2654 /* Set dlgwidth to width of message */ | 2658 } |
2659 else | |
2660 { | |
2661 /* Use our own window for the size, unless it's very small. */ | |
2662 GetWindowRect(s_hwnd, &rect); | |
2663 maxDialogWidth = rect.right - rect.left | |
2664 - GetSystemMetrics(SM_CXFRAME) * 2; | |
2665 if (maxDialogWidth < DLG_MIN_MAX_WIDTH) | |
2666 maxDialogWidth = DLG_MIN_MAX_WIDTH; | |
2667 | |
2668 maxDialogHeight = rect.bottom - rect.top | |
2669 - GetSystemMetrics(SM_CXFRAME) * 2; | |
2670 if (maxDialogHeight < DLG_MIN_MAX_HEIGHT) | |
2671 maxDialogHeight = DLG_MIN_MAX_HEIGHT; | |
2672 } | |
2673 | |
2674 /* Set dlgwidth to width of message. | |
2675 * Copy the message into "ga", changing NL to CR-NL and inserting line | |
2676 * breaks where needed. */ | |
2655 pstart = message; | 2677 pstart = message; |
2656 messageWidth = 0; | 2678 messageWidth = 0; |
2657 msgheight = fontHeight; | 2679 msgheight = 0; |
2680 ga_init2(&ga, sizeof(char), 500); | |
2658 do | 2681 do |
2659 { | 2682 { |
2660 pend = vim_strchr(pstart, DLG_BUTTON_SEP); | 2683 msgheight += fontHeight; /* at least one line */ |
2661 if (pend == NULL) | 2684 |
2662 pend = pstart + STRLEN(pstart); /* Last line of message. */ | 2685 /* Need to figure out where to break the string. The system does it |
2663 msgheight += fontHeight; | 2686 * at a word boundary, which would mean we can't compute the number of |
2664 textWidth = GetTextWidth(hdc, pstart, (int)(pend - pstart)); | 2687 * wrapped lines. */ |
2665 if (textWidth >= maxDialogWidth) | 2688 textWidth = 0; |
2666 { | 2689 last_white = NULL; |
2667 /* Line will wrap. This doesn't work correctly, because the wrap | 2690 for (pend = pstart; *pend != NUL && *pend != '\n'; ) |
2668 * happens at a word boundary! */ | 2691 { |
2669 messageWidth = maxDialogWidth; | 2692 #ifdef FEAT_MBYTE |
2670 while (textWidth >= maxDialogWidth) | 2693 l = mb_ptr2len_check(pend); |
2694 #else | |
2695 l = 1; | |
2696 #endif | |
2697 if (l == 1 && vim_iswhite(*pend) | |
2698 && textWidth > maxDialogWidth * 3 / 4) | |
2699 last_white = pend; | |
2700 textWidth += GetTextWidth(hdc, pend, l); | |
2701 if (textWidth >= maxDialogWidth) | |
2671 { | 2702 { |
2703 /* Line will wrap. */ | |
2704 messageWidth = maxDialogWidth; | |
2672 msgheight += fontHeight; | 2705 msgheight += fontHeight; |
2673 textWidth -= maxDialogWidth; | 2706 textWidth = 0; |
2707 | |
2708 if (last_white != NULL) | |
2709 { | |
2710 /* break the line just after a space */ | |
2711 ga.ga_len -= pend - (last_white + 1); | |
2712 pend = last_white + 1; | |
2713 last_white = NULL; | |
2714 } | |
2715 ga_append(&ga, '\r'); | |
2716 ga_append(&ga, '\n'); | |
2717 continue; | |
2674 } | 2718 } |
2675 } | 2719 |
2676 else if (textWidth > messageWidth) | 2720 while (--l >= 0) |
2721 ga_append(&ga, *pend++); | |
2722 } | |
2723 if (textWidth > messageWidth) | |
2677 messageWidth = textWidth; | 2724 messageWidth = textWidth; |
2725 | |
2726 ga_append(&ga, '\r'); | |
2727 ga_append(&ga, '\n'); | |
2678 pstart = pend + 1; | 2728 pstart = pend + 1; |
2679 } while (*pend != NUL); | 2729 } while (*pend != NUL); |
2680 | 2730 |
2731 if (ga.ga_data != NULL) | |
2732 message = ga.ga_data; | |
2733 | |
2681 messageWidth += 10; /* roundoff space */ | 2734 messageWidth += 10; /* roundoff space */ |
2682 | 2735 |
2683 /* Restrict the size to a maximum. Causes a scrollbar to show up. */ | 2736 /* Restrict the size to a maximum. Causes a scrollbar to show up. */ |
2684 if (msgheight > maxDialogHeight) | 2737 if (msgheight > maxDialogHeight) |
2685 { | 2738 { |
2686 msgheight = maxDialogHeight; | 2739 msgheight = maxDialogHeight; |
2687 scroll_flag = WS_VSCROLL; | 2740 scroll_flag = WS_VSCROLL; |
2741 messageWidth += GetSystemMetrics(SM_CXVSCROLL); | |
2688 } | 2742 } |
2689 | 2743 |
2690 /* Add width of icon to dlgwidth, and some space */ | 2744 /* Add width of icon to dlgwidth, and some space */ |
2691 dlgwidth = messageWidth + DLG_ICON_WIDTH + 3 * dlgPaddingX; | 2745 dlgwidth = messageWidth + DLG_ICON_WIDTH + 3 * dlgPaddingX; |
2692 | 2746 |
2931 | 2985 |
2932 LocalFree(LocalHandle(pdlgtemplate)); | 2986 LocalFree(LocalHandle(pdlgtemplate)); |
2933 vim_free(tbuffer); | 2987 vim_free(tbuffer); |
2934 vim_free(buttonWidths); | 2988 vim_free(buttonWidths); |
2935 vim_free(buttonPositions); | 2989 vim_free(buttonPositions); |
2990 vim_free(ga.ga_data); | |
2936 | 2991 |
2937 /* Focus back to our window (for when MDI is used). */ | 2992 /* Focus back to our window (for when MDI is used). */ |
2938 (void)SetFocus(s_hwnd); | 2993 (void)SetFocus(s_hwnd); |
2939 | 2994 |
2940 return nchar; | 2995 return nchar; |