Mercurial > vim
comparison src/gui_mac.c @ 15595:1ec942f1b648 v8.1.0805
patch 8.1.0805: too many #ifdefs
commit https://github.com/vim/vim/commit/135059724f140ceac889c9f8136bd1bf5c41d49d
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 24 15:04:48 2019 +0100
patch 8.1.0805: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 1.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 24 Jan 2019 15:15:06 +0100 |
parents | 55ccc2d353bd |
children | ddd82b1c9e9d |
comparison
equal
deleted
inserted
replaced
15594:7a8983fe4f97 | 15595:1ec942f1b648 |
---|---|
46 # define USE_AEVENT /* Need Apple Event Support */ | 46 # define USE_AEVENT /* Need Apple Event Support */ |
47 #endif | 47 #endif |
48 | 48 |
49 /* Vim's Scrap flavor. */ | 49 /* Vim's Scrap flavor. */ |
50 #define VIMSCRAPFLAVOR 'VIM!' | 50 #define VIMSCRAPFLAVOR 'VIM!' |
51 #ifdef FEAT_MBYTE | 51 #define SCRAPTEXTFLAVOR kScrapFlavorTypeUnicode |
52 # define SCRAPTEXTFLAVOR kScrapFlavorTypeUnicode | |
53 #else | |
54 # define SCRAPTEXTFLAVOR kScrapFlavorTypeText | |
55 #endif | |
56 | 52 |
57 static EventHandlerUPP mouseWheelHandlerUPP = NULL; | 53 static EventHandlerUPP mouseWheelHandlerUPP = NULL; |
58 SInt32 gMacSystemVersion; | 54 SInt32 gMacSystemVersion; |
59 | 55 |
60 #ifdef MACOS_CONVERT | 56 #ifdef MACOS_CONVERT |
167 | 163 |
168 #ifdef MACOS_CONVERT | 164 #ifdef MACOS_CONVERT |
169 # define USE_ATSUI_DRAWING | 165 # define USE_ATSUI_DRAWING |
170 int p_macatsui_last; | 166 int p_macatsui_last; |
171 ATSUStyle gFontStyle; | 167 ATSUStyle gFontStyle; |
172 # ifdef FEAT_MBYTE | |
173 ATSUStyle gWideFontStyle; | 168 ATSUStyle gWideFontStyle; |
174 # endif | |
175 Boolean gIsFontFallbackSet; | 169 Boolean gIsFontFallbackSet; |
176 UInt32 useAntialias_cached = 0x0; | 170 UInt32 useAntialias_cached = 0x0; |
177 #endif | 171 #endif |
178 | 172 |
179 /* Colors Macros */ | 173 /* Colors Macros */ |
2033 if (eventClass == kEventClassWindow) | 2027 if (eventClass == kEventClassWindow) |
2034 { | 2028 { |
2035 switch (eventKind) | 2029 switch (eventKind) |
2036 { | 2030 { |
2037 case kEventWindowActivated: | 2031 case kEventWindowActivated: |
2038 # if defined(FEAT_MBYTE) | |
2039 im_on_window_switch(TRUE); | 2032 im_on_window_switch(TRUE); |
2040 # endif | |
2041 return noErr; | 2033 return noErr; |
2042 | 2034 |
2043 case kEventWindowDeactivated: | 2035 case kEventWindowDeactivated: |
2044 # if defined(FEAT_MBYTE) | |
2045 im_on_window_switch(FALSE); | 2036 im_on_window_switch(FALSE); |
2046 # endif | |
2047 return noErr; | 2037 return noErr; |
2048 } | 2038 } |
2049 } | 2039 } |
2050 | 2040 |
2051 return eventNotHandledErr; | 2041 return eventNotHandledErr; |
2389 string[len++] = K_SECOND(key_char); | 2379 string[len++] = K_SECOND(key_char); |
2390 string[len++] = K_THIRD(key_char); | 2380 string[len++] = K_THIRD(key_char); |
2391 } | 2381 } |
2392 else | 2382 else |
2393 { | 2383 { |
2394 #ifdef FEAT_MBYTE | |
2395 /* Convert characters when needed (e.g., from MacRoman to latin1). | 2384 /* Convert characters when needed (e.g., from MacRoman to latin1). |
2396 * This doesn't work for the NUL byte. */ | 2385 * This doesn't work for the NUL byte. */ |
2397 if (input_conv.vc_type != CONV_NONE && key_char > 0) | 2386 if (input_conv.vc_type != CONV_NONE && key_char > 0) |
2398 { | 2387 { |
2399 char_u from[2], *to; | 2388 char_u from[2], *to; |
2419 } | 2408 } |
2420 else | 2409 else |
2421 string[len++] = key_char; | 2410 string[len++] = key_char; |
2422 } | 2411 } |
2423 else | 2412 else |
2424 #endif | |
2425 string[len++] = key_char; | 2413 string[len++] = key_char; |
2426 } | 2414 } |
2427 | 2415 |
2428 if (len == 1 && string[0] == CSI) | 2416 if (len == 1 && string[0] == CSI) |
2429 { | 2417 { |
3193 DisposeEventHandlerUPP(winEventHandlerUPP); | 3181 DisposeEventHandlerUPP(winEventHandlerUPP); |
3194 winEventHandlerUPP = NULL; | 3182 winEventHandlerUPP = NULL; |
3195 } | 3183 } |
3196 #endif | 3184 #endif |
3197 | 3185 |
3198 /* | |
3199 #ifdef FEAT_MBYTE | |
3200 set_option_value((char_u *)"encoding", 0L, (char_u *)"utf-8", 0); | |
3201 #endif | |
3202 */ | |
3203 | |
3204 #ifdef FEAT_GUI_TABLINE | 3186 #ifdef FEAT_GUI_TABLINE |
3205 /* | 3187 /* |
3206 * Create the tabline | 3188 * Create the tabline |
3207 */ | 3189 */ |
3208 initialise_tabline(); | 3190 initialise_tabline(); |
3252 static void | 3234 static void |
3253 gui_mac_dispose_atsui_style(void) | 3235 gui_mac_dispose_atsui_style(void) |
3254 { | 3236 { |
3255 if (p_macatsui && gFontStyle) | 3237 if (p_macatsui && gFontStyle) |
3256 ATSUDisposeStyle(gFontStyle); | 3238 ATSUDisposeStyle(gFontStyle); |
3257 #ifdef FEAT_MBYTE | |
3258 if (p_macatsui && gWideFontStyle) | 3239 if (p_macatsui && gWideFontStyle) |
3259 ATSUDisposeStyle(gWideFontStyle); | 3240 ATSUDisposeStyle(gWideFontStyle); |
3260 #endif | |
3261 } | 3241 } |
3262 #endif | 3242 #endif |
3263 | 3243 |
3264 void | 3244 void |
3265 gui_mch_exit(int rc) | 3245 gui_mch_exit(int rc) |
3428 if (p_macatsui && gFontStyle == NULL) | 3408 if (p_macatsui && gFontStyle == NULL) |
3429 { | 3409 { |
3430 if (ATSUCreateStyle(&gFontStyle) != noErr) | 3410 if (ATSUCreateStyle(&gFontStyle) != noErr) |
3431 gFontStyle = NULL; | 3411 gFontStyle = NULL; |
3432 } | 3412 } |
3433 #ifdef FEAT_MBYTE | |
3434 if (p_macatsui && gWideFontStyle == NULL) | 3413 if (p_macatsui && gWideFontStyle == NULL) |
3435 { | 3414 { |
3436 if (ATSUCreateStyle(&gWideFontStyle) != noErr) | 3415 if (ATSUCreateStyle(&gWideFontStyle) != noErr) |
3437 gWideFontStyle = NULL; | 3416 gWideFontStyle = NULL; |
3438 } | 3417 } |
3439 #endif | |
3440 | 3418 |
3441 p_macatsui_last = p_macatsui; | 3419 p_macatsui_last = p_macatsui; |
3442 } | 3420 } |
3443 #endif | 3421 #endif |
3444 | 3422 |
3620 # endif | 3598 # endif |
3621 ATSUDisposeStyle(gFontStyle); | 3599 ATSUDisposeStyle(gFontStyle); |
3622 gFontStyle = NULL; | 3600 gFontStyle = NULL; |
3623 } | 3601 } |
3624 | 3602 |
3625 #ifdef FEAT_MBYTE | |
3626 if (has_mbyte) | 3603 if (has_mbyte) |
3627 { | 3604 { |
3628 /* FIXME: we should use a more mbyte sensitive way to support | 3605 /* FIXME: we should use a more mbyte sensitive way to support |
3629 * wide font drawing */ | 3606 * wide font drawing */ |
3630 fontWidth = Long2Fix(gui.char_width * 2); | 3607 fontWidth = Long2Fix(gui.char_width * 2); |
3635 { | 3612 { |
3636 ATSUDisposeStyle(gWideFontStyle); | 3613 ATSUDisposeStyle(gWideFontStyle); |
3637 gWideFontStyle = NULL; | 3614 gWideFontStyle = NULL; |
3638 } | 3615 } |
3639 } | 3616 } |
3640 #endif | |
3641 } | 3617 } |
3642 } | 3618 } |
3643 #endif | 3619 #endif |
3644 | 3620 |
3645 /* | 3621 /* |
3809 | 3785 |
3810 | 3786 |
3811 static void | 3787 static void |
3812 draw_string_QD(int row, int col, char_u *s, int len, int flags) | 3788 draw_string_QD(int row, int col, char_u *s, int len, int flags) |
3813 { | 3789 { |
3814 #ifdef FEAT_MBYTE | |
3815 char_u *tofree = NULL; | 3790 char_u *tofree = NULL; |
3816 | 3791 |
3817 if (output_conv.vc_type != CONV_NONE) | 3792 if (output_conv.vc_type != CONV_NONE) |
3818 { | 3793 { |
3819 tofree = string_convert(&output_conv, s, &len); | 3794 tofree = string_convert(&output_conv, s, &len); |
3820 if (tofree != NULL) | 3795 if (tofree != NULL) |
3821 s = tofree; | 3796 s = tofree; |
3822 } | 3797 } |
3823 #endif | |
3824 | 3798 |
3825 /* | 3799 /* |
3826 * On OS X, try using Quartz-style text antialiasing. | 3800 * On OS X, try using Quartz-style text antialiasing. |
3827 */ | 3801 */ |
3828 if (gMacSystemVersion >= 0x1020) | 3802 if (gMacSystemVersion >= 0x1020) |
3847 { | 3821 { |
3848 Rect rc; | 3822 Rect rc; |
3849 | 3823 |
3850 rc.left = FILL_X(col); | 3824 rc.left = FILL_X(col); |
3851 rc.top = FILL_Y(row); | 3825 rc.top = FILL_Y(row); |
3852 #ifdef FEAT_MBYTE | |
3853 /* Multibyte computation taken from gui_w32.c */ | 3826 /* Multibyte computation taken from gui_w32.c */ |
3854 if (has_mbyte) | 3827 if (has_mbyte) |
3855 { | 3828 { |
3856 /* Compute the length in display cells. */ | 3829 /* Compute the length in display cells. */ |
3857 rc.right = FILL_X(col + mb_string2cells(s, len)); | 3830 rc.right = FILL_X(col + mb_string2cells(s, len)); |
3858 } | 3831 } |
3859 else | 3832 else |
3860 #endif | 3833 rc.right = FILL_X(col + len) + (col + len == Columns); |
3861 rc.right = FILL_X(col + len) + (col + len == Columns); | |
3862 rc.bottom = FILL_Y(row + 1); | 3834 rc.bottom = FILL_Y(row + 1); |
3863 EraseRect(&rc); | 3835 EraseRect(&rc); |
3864 } | 3836 } |
3865 | 3837 |
3866 if (gMacSystemVersion >= 0x1020 && p_antialias) | 3838 if (gMacSystemVersion >= 0x1020 && p_antialias) |
3916 } | 3888 } |
3917 | 3889 |
3918 if (flags & DRAW_UNDERC) | 3890 if (flags & DRAW_UNDERC) |
3919 draw_undercurl(flags, row, col, len); | 3891 draw_undercurl(flags, row, col, len); |
3920 | 3892 |
3921 #ifdef FEAT_MBYTE | |
3922 vim_free(tofree); | 3893 vim_free(tofree); |
3923 #endif | |
3924 } | 3894 } |
3925 | 3895 |
3926 #ifdef USE_ATSUI_DRAWING | 3896 #ifdef USE_ATSUI_DRAWING |
3927 | 3897 |
3928 static void | 3898 static void |
4005 attribSizes, attribValues); | 3975 attribSizes, attribValues); |
4006 | 3976 |
4007 useAntialias_cached = useAntialias; | 3977 useAntialias_cached = useAntialias; |
4008 } | 3978 } |
4009 | 3979 |
4010 #ifdef FEAT_MBYTE | |
4011 if (has_mbyte) | 3980 if (has_mbyte) |
4012 { | 3981 { |
4013 int n, width_in_cell, last_width_in_cell; | 3982 int n, width_in_cell, last_width_in_cell; |
4014 UniCharArrayOffset offset = 0; | 3983 UniCharArrayOffset offset = 0; |
4015 UniCharCount yet_to_draw = 0; | 3984 UniCharCount yet_to_draw = 0; |
4067 kATSUFromTextBeginning, kATSUToTextEnd, | 4036 kATSUFromTextBeginning, kATSUToTextEnd, |
4068 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | 4037 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); |
4069 ATSUDisposeTextLayout(textLayout); | 4038 ATSUDisposeTextLayout(textLayout); |
4070 } | 4039 } |
4071 else | 4040 else |
4072 #endif | |
4073 { | 4041 { |
4074 ATSUTextLayout textLayout; | 4042 ATSUTextLayout textLayout; |
4075 | 4043 |
4076 if (ATSUCreateTextLayoutWithTextPtr(tofree, | 4044 if (ATSUCreateTextLayoutWithTextPtr(tofree, |
4077 kATSUFromTextBeginning, kATSUToTextEnd, | 4045 kATSUFromTextBeginning, kATSUToTextEnd, |
4223 * Note: FrameRect() excludes right and bottom of rectangle. | 4191 * Note: FrameRect() excludes right and bottom of rectangle. |
4224 */ | 4192 */ |
4225 rc.left = FILL_X(gui.col); | 4193 rc.left = FILL_X(gui.col); |
4226 rc.top = FILL_Y(gui.row); | 4194 rc.top = FILL_Y(gui.row); |
4227 rc.right = rc.left + gui.char_width; | 4195 rc.right = rc.left + gui.char_width; |
4228 #ifdef FEAT_MBYTE | |
4229 if (mb_lefthalve(gui.row, gui.col)) | 4196 if (mb_lefthalve(gui.row, gui.col)) |
4230 rc.right += gui.char_width; | 4197 rc.right += gui.char_width; |
4231 #endif | |
4232 rc.bottom = rc.top + gui.char_height; | 4198 rc.bottom = rc.top + gui.char_height; |
4233 | 4199 |
4234 gui_mch_set_fg_color(color); | 4200 gui_mch_set_fg_color(color); |
4235 | 4201 |
4236 FrameRect(&rc); | 4202 FrameRect(&rc); |
4703 * TODO: Try to reuse menu id | 4669 * TODO: Try to reuse menu id |
4704 * Carbon Help suggest to use only id between 1 and 235 | 4670 * Carbon Help suggest to use only id between 1 and 235 |
4705 */ | 4671 */ |
4706 static long next_avail_id = 128; | 4672 static long next_avail_id = 128; |
4707 long menu_after_me = 0; /* Default to the end */ | 4673 long menu_after_me = 0; /* Default to the end */ |
4708 #if defined(FEAT_MBYTE) | |
4709 CFStringRef name; | 4674 CFStringRef name; |
4710 #else | |
4711 char_u *name; | |
4712 #endif | |
4713 short index; | 4675 short index; |
4714 vimmenu_T *parent = menu->parent; | 4676 vimmenu_T *parent = menu->parent; |
4715 vimmenu_T *brother = menu->next; | 4677 vimmenu_T *brother = menu->next; |
4716 | 4678 |
4717 /* Cannot add a menu if ... */ | 4679 /* Cannot add a menu if ... */ |
4748 /* Carbon suggest use of | 4710 /* Carbon suggest use of |
4749 * OSStatus CreateNewMenu(MenuID, MenuAttributes, MenuRef *); | 4711 * OSStatus CreateNewMenu(MenuID, MenuAttributes, MenuRef *); |
4750 * OSStatus SetMenuTitle(MenuRef, ConstStr255Param title); | 4712 * OSStatus SetMenuTitle(MenuRef, ConstStr255Param title); |
4751 */ | 4713 */ |
4752 menu->submenu_id = next_avail_id; | 4714 menu->submenu_id = next_avail_id; |
4753 #if defined(FEAT_MBYTE) | |
4754 if (CreateNewMenu(menu->submenu_id, 0, (MenuRef *)&menu->submenu_handle) == noErr) | 4715 if (CreateNewMenu(menu->submenu_id, 0, (MenuRef *)&menu->submenu_handle) == noErr) |
4755 SetMenuTitleWithCFString((MenuRef)menu->submenu_handle, name); | 4716 SetMenuTitleWithCFString((MenuRef)menu->submenu_handle, name); |
4756 #else | |
4757 menu->submenu_handle = NewMenu(menu->submenu_id, name); | |
4758 #endif | |
4759 next_avail_id++; | 4717 next_avail_id++; |
4760 } | 4718 } |
4761 | 4719 |
4762 if (parent == NULL) | 4720 if (parent == NULL) |
4763 { | 4721 { |
4782 | 4740 |
4783 /* Call InsertMenuItem followed by SetMenuItemText | 4741 /* Call InsertMenuItem followed by SetMenuItemText |
4784 * to avoid special character recognition by InsertMenuItem | 4742 * to avoid special character recognition by InsertMenuItem |
4785 */ | 4743 */ |
4786 InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */ | 4744 InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */ |
4787 #if defined(FEAT_MBYTE) | |
4788 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name); | 4745 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name); |
4789 #else | |
4790 SetMenuItemText(parent->submenu_handle, idx+1, name); | |
4791 #endif | |
4792 SetItemCmd(parent->submenu_handle, idx+1, 0x1B); | 4746 SetItemCmd(parent->submenu_handle, idx+1, 0x1B); |
4793 SetItemMark(parent->submenu_handle, idx+1, menu->submenu_id); | 4747 SetItemMark(parent->submenu_handle, idx+1, menu->submenu_id); |
4794 InsertMenu(menu->submenu_handle, hierMenu); | 4748 InsertMenu(menu->submenu_handle, hierMenu); |
4795 } | 4749 } |
4796 | 4750 |
4797 #if defined(FEAT_MBYTE) | |
4798 CFRelease(name); | 4751 CFRelease(name); |
4799 #else | |
4800 vim_free(name); | |
4801 #endif | |
4802 | 4752 |
4803 #if 0 | 4753 #if 0 |
4804 /* Done by Vim later on */ | 4754 /* Done by Vim later on */ |
4805 DrawMenuBar(); | 4755 DrawMenuBar(); |
4806 #endif | 4756 #endif |
4810 * Add a menu item to a menu | 4760 * Add a menu item to a menu |
4811 */ | 4761 */ |
4812 void | 4762 void |
4813 gui_mch_add_menu_item(vimmenu_T *menu, int idx) | 4763 gui_mch_add_menu_item(vimmenu_T *menu, int idx) |
4814 { | 4764 { |
4815 #if defined(FEAT_MBYTE) | |
4816 CFStringRef name; | 4765 CFStringRef name; |
4817 #else | |
4818 char_u *name; | |
4819 #endif | |
4820 vimmenu_T *parent = menu->parent; | 4766 vimmenu_T *parent = menu->parent; |
4821 int menu_inserted; | 4767 int menu_inserted; |
4822 | 4768 |
4823 /* Cannot add item, if the menu have not been created */ | 4769 /* Cannot add item, if the menu have not been created */ |
4824 if (parent->submenu_id == 0) | 4770 if (parent->submenu_id == 0) |
4910 * to avoid special character recognition by InsertMenuItem | 4856 * to avoid special character recognition by InsertMenuItem |
4911 */ | 4857 */ |
4912 if (!menu_inserted) | 4858 if (!menu_inserted) |
4913 InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */ | 4859 InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */ |
4914 /* Set the menu item name. */ | 4860 /* Set the menu item name. */ |
4915 #if defined(FEAT_MBYTE) | |
4916 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name); | 4861 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name); |
4917 #else | |
4918 SetMenuItemText(parent->submenu_handle, idx+1, name); | |
4919 #endif | |
4920 | 4862 |
4921 #if 0 | 4863 #if 0 |
4922 /* Called by Vim */ | 4864 /* Called by Vim */ |
4923 DrawMenuBar(); | 4865 DrawMenuBar(); |
4924 #endif | 4866 #endif |
4925 | 4867 |
4926 #if defined(FEAT_MBYTE) | |
4927 CFRelease(name); | 4868 CFRelease(name); |
4928 #else | |
4929 /* TODO: Can name be freed? */ | |
4930 vim_free(name); | |
4931 #endif | |
4932 } | 4869 } |
4933 | 4870 |
4934 void | 4871 void |
4935 gui_mch_toggle_tearoffs(int enable) | 4872 gui_mch_toggle_tearoffs(int enable) |
4936 { | 4873 { |
6240 | 6177 |
6241 return (vim_strsave(fname)); | 6178 return (vim_strsave(fname)); |
6242 #endif | 6179 #endif |
6243 } | 6180 } |
6244 | 6181 |
6245 #if (defined(FEAT_MBYTE) && defined(USE_CARBONKEYHANDLER)) || defined(PROTO) | 6182 #if defined(USE_CARBONKEYHANDLER) || defined(PROTO) |
6246 /* | 6183 /* |
6247 * Input Method Control functions. | 6184 * Input Method Control functions. |
6248 */ | 6185 */ |
6249 | 6186 |
6250 /* | 6187 /* |
6389 return 0; | 6326 return 0; |
6390 | 6327 |
6391 return im_is_active; | 6328 return im_is_active; |
6392 } | 6329 } |
6393 | 6330 |
6394 #endif /* defined(FEAT_MBYTE) || defined(PROTO) */ | 6331 #endif |
6395 | |
6396 | 6332 |
6397 | 6333 |
6398 | 6334 |
6399 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) | 6335 #if defined(FEAT_GUI_TABLINE) || defined(PROTO) |
6400 // drawer implementation | 6336 // drawer implementation |