Mirror of the Vim source from https://github.com/vim/vim
Révision | 437fb19625c9e24e2157563cf0a55aeb432b2990 (tree) |
---|---|
l'heure | 2008-03-12 22:40:54 |
Auteur | vimboss |
Commiter | vimboss |
updated for version 7.1-275
@@ -59,7 +59,33 @@ | ||
59 | 59 | |
60 | 60 | #ifdef MACOS_CONVERT |
61 | 61 | # define USE_CARBONKEYHANDLER |
62 | + | |
63 | +static int im_is_active = FALSE; | |
64 | +#if 0 | |
65 | +static int im_start_row = 0; | |
66 | +static int im_start_col = 0; | |
67 | +#endif | |
68 | + | |
69 | +#define NR_ELEMS(x) (sizeof(x) / sizeof(x[0])) | |
70 | + | |
71 | +static TSMDocumentID gTSMDocument; | |
72 | + | |
73 | +static void im_on_window_switch(int active); | |
62 | 74 | static EventHandlerUPP keyEventHandlerUPP = NULL; |
75 | +static EventHandlerUPP winEventHandlerUPP = NULL; | |
76 | + | |
77 | +static pascal OSStatus gui_mac_handle_window_activate( | |
78 | + EventHandlerCallRef nextHandler, EventRef theEvent, void *data); | |
79 | + | |
80 | +static pascal OSStatus gui_mac_handle_text_input( | |
81 | + EventHandlerCallRef nextHandler, EventRef theEvent, void *data); | |
82 | + | |
83 | +static pascal OSStatus gui_mac_update_input_area( | |
84 | + EventHandlerCallRef nextHandler, EventRef theEvent); | |
85 | + | |
86 | +static pascal OSStatus gui_mac_unicode_key_event( | |
87 | + EventHandlerCallRef nextHandler, EventRef theEvent); | |
88 | + | |
63 | 89 | #endif |
64 | 90 | |
65 | 91 |
@@ -137,7 +163,11 @@ | ||
137 | 163 | |
138 | 164 | #ifdef MACOS_CONVERT |
139 | 165 | # define USE_ATSUI_DRAWING |
166 | +int p_macatsui_last; | |
140 | 167 | ATSUStyle gFontStyle; |
168 | +# ifdef FEAT_MBYTE | |
169 | +ATSUStyle gWideFontStyle; | |
170 | +# endif | |
141 | 171 | Boolean gIsFontFallbackSet; |
142 | 172 | #endif |
143 | 173 |
@@ -265,6 +295,11 @@ | ||
265 | 295 | static WindowRef drawer = NULL; // TODO: put into gui.h |
266 | 296 | #endif |
267 | 297 | |
298 | +#ifdef USE_ATSUI_DRAWING | |
299 | +static void gui_mac_set_font_attributes(GuiFont font); | |
300 | +static void gui_mac_dispose_atsui_style(void); | |
301 | +#endif | |
302 | + | |
268 | 303 | /* |
269 | 304 | * ------------------------------------------------------------ |
270 | 305 | * Conversion Utility |
@@ -1935,12 +1970,12 @@ | ||
1935 | 1970 | /* Dim scrollbars */ |
1936 | 1971 | if (whichWindow == gui.VimWindow) |
1937 | 1972 | { |
1938 | - ControlRef rootControl; | |
1939 | - GetRootControl(gui.VimWindow, &rootControl); | |
1940 | - if ((event->modifiers) & activeFlag) | |
1941 | - ActivateControl(rootControl); | |
1942 | - else | |
1943 | - DeactivateControl(rootControl); | |
1973 | + ControlRef rootControl; | |
1974 | + GetRootControl(gui.VimWindow, &rootControl); | |
1975 | + if ((event->modifiers) & activeFlag) | |
1976 | + ActivateControl(rootControl); | |
1977 | + else | |
1978 | + DeactivateControl(rootControl); | |
1944 | 1979 | } |
1945 | 1980 | |
1946 | 1981 | /* Activate */ |
@@ -1976,15 +2011,87 @@ | ||
1976 | 2011 | * Handle the key |
1977 | 2012 | */ |
1978 | 2013 | #ifdef USE_CARBONKEYHANDLER |
1979 | - | |
1980 | -static int dialog_busy = FALSE; /* TRUE when gui_mch_dialog() wants the keys */ | |
2014 | + static pascal OSStatus | |
2015 | +gui_mac_handle_window_activate( | |
2016 | + EventHandlerCallRef nextHandler, | |
2017 | + EventRef theEvent, | |
2018 | + void *data) | |
2019 | +{ | |
2020 | + UInt32 eventClass = GetEventClass(theEvent); | |
2021 | + UInt32 eventKind = GetEventKind(theEvent); | |
2022 | + | |
2023 | + if (eventClass == kEventClassWindow) | |
2024 | + { | |
2025 | + switch (eventKind) | |
2026 | + { | |
2027 | + case kEventWindowActivated: | |
2028 | +#if defined(USE_IM_CONTROL) | |
2029 | + im_on_window_switch(TRUE); | |
2030 | +#endif | |
2031 | + return noErr; | |
2032 | + | |
2033 | + case kEventWindowDeactivated: | |
2034 | +#if defined(USE_IM_CONTROL) | |
2035 | + im_on_window_switch(FALSE); | |
2036 | +#endif | |
2037 | + return noErr; | |
2038 | + } | |
2039 | + } | |
2040 | + | |
2041 | + return eventNotHandledErr; | |
2042 | +} | |
2043 | + | |
2044 | + static pascal OSStatus | |
2045 | +gui_mac_handle_text_input( | |
2046 | + EventHandlerCallRef nextHandler, | |
2047 | + EventRef theEvent, | |
2048 | + void *data) | |
2049 | +{ | |
2050 | + UInt32 eventClass = GetEventClass(theEvent); | |
2051 | + UInt32 eventKind = GetEventKind(theEvent); | |
2052 | + | |
2053 | + if (eventClass != kEventClassTextInput) | |
2054 | + return eventNotHandledErr; | |
2055 | + | |
2056 | + if ((kEventTextInputUpdateActiveInputArea != eventKind) && | |
2057 | + (kEventTextInputUnicodeForKeyEvent != eventKind) && | |
2058 | + (kEventTextInputOffsetToPos != eventKind) && | |
2059 | + (kEventTextInputPosToOffset != eventKind) && | |
2060 | + (kEventTextInputGetSelectedText != eventKind)) | |
2061 | + return eventNotHandledErr; | |
2062 | + | |
2063 | + switch (eventKind) | |
2064 | + { | |
2065 | + case kEventTextInputUpdateActiveInputArea: | |
2066 | + return gui_mac_update_input_area(nextHandler, theEvent); | |
2067 | + case kEventTextInputUnicodeForKeyEvent: | |
2068 | + return gui_mac_unicode_key_event(nextHandler, theEvent); | |
2069 | + | |
2070 | + case kEventTextInputOffsetToPos: | |
2071 | + case kEventTextInputPosToOffset: | |
2072 | + case kEventTextInputGetSelectedText: | |
2073 | + break; | |
2074 | + } | |
2075 | + | |
2076 | + return eventNotHandledErr; | |
2077 | +} | |
2078 | + | |
2079 | + static pascal | |
2080 | +OSStatus gui_mac_update_input_area( | |
2081 | + EventHandlerCallRef nextHandler, | |
2082 | + EventRef theEvent) | |
2083 | +{ | |
2084 | + return eventNotHandledErr; | |
2085 | +} | |
2086 | + | |
2087 | +static int dialog_busy = FALSE; /* TRUE when gui_mch_dialog() wants the | |
2088 | + keys */ | |
1981 | 2089 | |
1982 | 2090 | # define INLINE_KEY_BUFFER_SIZE 80 |
1983 | 2091 | static pascal OSStatus |
1984 | -gui_mac_doKeyEventCarbon( | |
2092 | +gui_mac_unicode_key_event( | |
1985 | 2093 | EventHandlerCallRef nextHandler, |
1986 | - EventRef theEvent, | |
1987 | - void *data) | |
2094 | + EventRef theEvent) | |
1988 | 2095 | { |
1989 | 2096 | /* Multibyte-friendly key event handler */ |
1990 | 2097 | OSStatus err = -1; |
@@ -2000,7 +2107,7 @@ | ||
2000 | 2107 | char_u *to = NULL; |
2001 | 2108 | Boolean isSpecial = FALSE; |
2002 | 2109 | int i; |
2003 | - EventRef keyEvent; | |
2110 | + EventRef keyEvent; | |
2004 | 2111 | |
2005 | 2112 | /* Mask the mouse (as per user setting) */ |
2006 | 2113 | if (p_mh) |
@@ -2008,39 +2115,39 @@ | ||
2008 | 2115 | |
2009 | 2116 | /* Don't use the keys when the dialog wants them. */ |
2010 | 2117 | if (dialog_busy) |
2011 | - return eventNotHandledErr; | |
2118 | + return eventNotHandledErr; | |
2012 | 2119 | |
2013 | 2120 | if (noErr != GetEventParameter(theEvent, kEventParamTextInputSendText, |
2014 | - typeUnicodeText, NULL, 0, &actualSize, NULL)) | |
2015 | - return eventNotHandledErr; | |
2121 | + typeUnicodeText, NULL, 0, &actualSize, NULL)) | |
2122 | + return eventNotHandledErr; | |
2016 | 2123 | |
2017 | 2124 | text = (UniChar *)alloc(actualSize); |
2018 | 2125 | if (!text) |
2019 | - return eventNotHandledErr; | |
2126 | + return eventNotHandledErr; | |
2020 | 2127 | |
2021 | 2128 | err = GetEventParameter(theEvent, kEventParamTextInputSendText, |
2022 | - typeUnicodeText, NULL, actualSize, NULL, text); | |
2129 | + typeUnicodeText, NULL, actualSize, NULL, text); | |
2023 | 2130 | require_noerr(err, done); |
2024 | 2131 | |
2025 | 2132 | err = GetEventParameter(theEvent, kEventParamTextInputSendKeyboardEvent, |
2026 | - typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent); | |
2133 | + typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent); | |
2027 | 2134 | require_noerr(err, done); |
2028 | 2135 | |
2029 | 2136 | err = GetEventParameter(keyEvent, kEventParamKeyModifiers, |
2030 | - typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
2137 | + typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); | |
2031 | 2138 | require_noerr(err, done); |
2032 | 2139 | |
2033 | 2140 | err = GetEventParameter(keyEvent, kEventParamKeyCode, |
2034 | - typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym); | |
2141 | + typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym); | |
2035 | 2142 | require_noerr(err, done); |
2036 | 2143 | |
2037 | 2144 | err = GetEventParameter(keyEvent, kEventParamKeyMacCharCodes, |
2038 | - typeChar, NULL, sizeof(char), NULL, &charcode); | |
2145 | + typeChar, NULL, sizeof(char), NULL, &charcode); | |
2039 | 2146 | require_noerr(err, done); |
2040 | 2147 | |
2041 | 2148 | #ifndef USE_CMD_KEY |
2042 | 2149 | if (modifiers & cmdKey) |
2043 | - goto done; /* Let system handle Cmd+... */ | |
2150 | + goto done; /* Let system handle Cmd+... */ | |
2044 | 2151 | #endif |
2045 | 2152 | |
2046 | 2153 | key_char = charcode; |
@@ -2048,84 +2155,84 @@ | ||
2048 | 2155 | |
2049 | 2156 | /* Find the special key (eg., for cursor keys) */ |
2050 | 2157 | if (actualSize <= sizeof(UniChar) && |
2051 | - ((text[0] < 0x20) || (text[0] == 0x7f))) | |
2052 | - { | |
2053 | - for (i = 0; special_keys[i].key_sym != (KeySym)0; ++i) | |
2054 | - if (special_keys[i].key_sym == key_sym) | |
2055 | - { | |
2056 | - key_char = TO_SPECIAL(special_keys[i].vim_code0, | |
2057 | - special_keys[i].vim_code1); | |
2058 | - key_char = simplify_key(key_char, | |
2059 | - (int *)&vimModifiers); | |
2060 | - isSpecial = TRUE; | |
2061 | - break; | |
2062 | - } | |
2158 | + ((text[0] < 0x20) || (text[0] == 0x7f))) | |
2159 | + { | |
2160 | + for (i = 0; special_keys[i].key_sym != (KeySym)0; ++i) | |
2161 | + if (special_keys[i].key_sym == key_sym) | |
2162 | + { | |
2163 | + key_char = TO_SPECIAL(special_keys[i].vim_code0, | |
2164 | + special_keys[i].vim_code1); | |
2165 | + key_char = simplify_key(key_char, | |
2166 | + (int *)&vimModifiers); | |
2167 | + isSpecial = TRUE; | |
2168 | + break; | |
2169 | + } | |
2063 | 2170 | } |
2064 | 2171 | |
2065 | 2172 | /* Intercept CMD-. and CTRL-c */ |
2066 | 2173 | if (((modifiers & controlKey) && key_char == 'c') || |
2067 | - ((modifiers & cmdKey) && key_char == '.')) | |
2068 | - got_int = TRUE; | |
2174 | + ((modifiers & cmdKey) && key_char == '.')) | |
2175 | + got_int = TRUE; | |
2069 | 2176 | |
2070 | 2177 | if (!isSpecial) |
2071 | 2178 | { |
2072 | - /* remove SHIFT for keys that are already shifted, e.g., | |
2073 | - * '(' and '*' */ | |
2074 | - if (key_char < 0x100 && !isalpha(key_char) && isprint(key_char)) | |
2075 | - vimModifiers &= ~MOD_MASK_SHIFT; | |
2076 | - | |
2077 | - /* remove CTRL from keys that already have it */ | |
2078 | - if (key_char < 0x20) | |
2079 | - vimModifiers &= ~MOD_MASK_CTRL; | |
2080 | - | |
2081 | - /* don't process unicode characters here */ | |
2082 | - if (!IS_SPECIAL(key_char)) | |
2083 | - { | |
2084 | - /* Following code to simplify and consolidate vimModifiers | |
2085 | - * taken liberally from gui_w48.c */ | |
2086 | - key_char = simplify_key(key_char, (int *)&vimModifiers); | |
2087 | - | |
2088 | - /* Interpret META, include SHIFT, etc. */ | |
2089 | - key_char = extract_modifiers(key_char, (int *)&vimModifiers); | |
2090 | - if (key_char == CSI) | |
2091 | - key_char = K_CSI; | |
2092 | - | |
2093 | - if (IS_SPECIAL(key_char)) | |
2094 | - isSpecial = TRUE; | |
2095 | - } | |
2179 | + /* remove SHIFT for keys that are already shifted, e.g., | |
2180 | + * '(' and '*' */ | |
2181 | + if (key_char < 0x100 && !isalpha(key_char) && isprint(key_char)) | |
2182 | + vimModifiers &= ~MOD_MASK_SHIFT; | |
2183 | + | |
2184 | + /* remove CTRL from keys that already have it */ | |
2185 | + if (key_char < 0x20) | |
2186 | + vimModifiers &= ~MOD_MASK_CTRL; | |
2187 | + | |
2188 | + /* don't process unicode characters here */ | |
2189 | + if (!IS_SPECIAL(key_char)) | |
2190 | + { | |
2191 | + /* Following code to simplify and consolidate vimModifiers | |
2192 | + * taken liberally from gui_w48.c */ | |
2193 | + key_char = simplify_key(key_char, (int *)&vimModifiers); | |
2194 | + | |
2195 | + /* Interpret META, include SHIFT, etc. */ | |
2196 | + key_char = extract_modifiers(key_char, (int *)&vimModifiers); | |
2197 | + if (key_char == CSI) | |
2198 | + key_char = K_CSI; | |
2199 | + | |
2200 | + if (IS_SPECIAL(key_char)) | |
2201 | + isSpecial = TRUE; | |
2202 | + } | |
2096 | 2203 | } |
2097 | 2204 | |
2098 | 2205 | if (vimModifiers) |
2099 | 2206 | { |
2100 | - result[len++] = CSI; | |
2101 | - result[len++] = KS_MODIFIER; | |
2102 | - result[len++] = vimModifiers; | |
2207 | + result[len++] = CSI; | |
2208 | + result[len++] = KS_MODIFIER; | |
2209 | + result[len++] = vimModifiers; | |
2103 | 2210 | } |
2104 | 2211 | |
2105 | 2212 | if (isSpecial && IS_SPECIAL(key_char)) |
2106 | 2213 | { |
2107 | - result[len++] = CSI; | |
2108 | - result[len++] = K_SECOND(key_char); | |
2109 | - result[len++] = K_THIRD(key_char); | |
2214 | + result[len++] = CSI; | |
2215 | + result[len++] = K_SECOND(key_char); | |
2216 | + result[len++] = K_THIRD(key_char); | |
2110 | 2217 | } |
2111 | 2218 | else |
2112 | 2219 | { |
2113 | - encLen = actualSize; | |
2114 | - to = mac_utf16_to_enc(text, actualSize, &encLen); | |
2115 | - if (to) | |
2116 | - { | |
2117 | - /* This is basically add_to_input_buf_csi() */ | |
2118 | - for (i = 0; i < encLen && len < (INLINE_KEY_BUFFER_SIZE-1); ++i) | |
2119 | - { | |
2120 | - result[len++] = to[i]; | |
2121 | - if (to[i] == CSI) | |
2122 | - { | |
2123 | - result[len++] = KS_EXTRA; | |
2124 | - result[len++] = (int)KE_CSI; | |
2125 | - } | |
2126 | - } | |
2127 | - vim_free(to); | |
2128 | - } | |
2220 | + encLen = actualSize; | |
2221 | + to = mac_utf16_to_enc(text, actualSize, &encLen); | |
2222 | + if (to) | |
2223 | + { | |
2224 | + /* This is basically add_to_input_buf_csi() */ | |
2225 | + for (i = 0; i < encLen && len < (INLINE_KEY_BUFFER_SIZE-1); ++i) | |
2226 | + { | |
2227 | + result[len++] = to[i]; | |
2228 | + if (to[i] == CSI) | |
2229 | + { | |
2230 | + result[len++] = KS_EXTRA; | |
2231 | + result[len++] = (int)KE_CSI; | |
2232 | + } | |
2233 | + } | |
2234 | + vim_free(to); | |
2235 | + } | |
2129 | 2236 | } |
2130 | 2237 | |
2131 | 2238 | add_to_input_buf(result, len); |
@@ -2135,10 +2242,10 @@ | ||
2135 | 2242 | vim_free(text); |
2136 | 2243 | if (err == noErr) |
2137 | 2244 | { |
2138 | - /* Fake event to wake up WNE (required to get | |
2139 | - * key repeat working */ | |
2140 | - PostEvent(keyUp, 0); | |
2141 | - return noErr; | |
2245 | + /* Fake event to wake up WNE (required to get | |
2246 | + * key repeat working */ | |
2247 | + PostEvent(keyUp, 0); | |
2248 | + return noErr; | |
2142 | 2249 | } |
2143 | 2250 | |
2144 | 2251 | return eventNotHandledErr; |
@@ -2334,7 +2441,7 @@ | ||
2334 | 2441 | /* prevent that the vim window size changes if it's activated by a |
2335 | 2442 | click into the tab pane */ |
2336 | 2443 | if (whichWindow == drawer) |
2337 | - return; | |
2444 | + return; | |
2338 | 2445 | #endif |
2339 | 2446 | |
2340 | 2447 | switch (thePart) |
@@ -2569,11 +2676,11 @@ | ||
2569 | 2676 | if (IsShowContextualMenuClick(event)) |
2570 | 2677 | { |
2571 | 2678 | # if 0 |
2572 | - gui_mac_handle_contextual_menu(event); | |
2679 | + gui_mac_handle_contextual_menu(event); | |
2573 | 2680 | # else |
2574 | - gui_mac_doMouseDownEvent(event); | |
2681 | + gui_mac_doMouseDownEvent(event); | |
2575 | 2682 | # endif |
2576 | - return; | |
2683 | + return; | |
2577 | 2684 | } |
2578 | 2685 | |
2579 | 2686 | /* Handle normal event */ |
@@ -2832,7 +2939,6 @@ | ||
2832 | 2939 | # else |
2833 | 2940 | /* OSErr GetApplicationBundleFSSpec(FSSpecPtr theFSSpecPtr) |
2834 | 2941 | * of TN2015 |
2835 | - * This technic remove the ../Contents/MacOS/etc part | |
2836 | 2942 | */ |
2837 | 2943 | (void)GetCurrentProcess(&psn); |
2838 | 2944 | /* if (err != noErr) return err; */ |
@@ -2933,10 +3039,9 @@ | ||
2933 | 3039 | /* TODO: Move most of this stuff toward gui_mch_init */ |
2934 | 3040 | Rect windRect; |
2935 | 3041 | MenuHandle pomme; |
2936 | - EventTypeSpec eventTypeSpec; | |
2937 | 3042 | EventHandlerRef mouseWheelHandlerRef; |
2938 | 3043 | #ifdef USE_CARBONKEYHANDLER |
2939 | - EventHandlerRef keyEventHandlerRef; | |
3044 | + EventTypeSpec eventTypeSpec; | |
2940 | 3045 | #endif |
2941 | 3046 | ControlRef rootControl; |
2942 | 3047 |
@@ -3042,16 +3147,47 @@ | ||
3042 | 3147 | } |
3043 | 3148 | |
3044 | 3149 | #ifdef USE_CARBONKEYHANDLER |
3045 | - eventTypeSpec.eventClass = kEventClassTextInput; | |
3046 | - eventTypeSpec.eventKind = kEventUnicodeForKeyEvent; | |
3047 | - keyEventHandlerUPP = NewEventHandlerUPP(gui_mac_doKeyEventCarbon); | |
3048 | - if (noErr != InstallApplicationEventHandler(keyEventHandlerUPP, 1, | |
3049 | - &eventTypeSpec, NULL, &keyEventHandlerRef)) | |
3050 | - { | |
3051 | - keyEventHandlerRef = NULL; | |
3150 | + InterfaceTypeList supportedServices = { kUnicodeDocument }; | |
3151 | + NewTSMDocument(1, supportedServices, &gTSMDocument, 0); | |
3152 | + | |
3153 | + /* We don't support inline input yet, use input window by default */ | |
3154 | + UseInputWindow(gTSMDocument, TRUE); | |
3155 | + | |
3156 | + /* Should we activate the document by default? */ | |
3157 | + // ActivateTSMDocument(gTSMDocument); | |
3158 | + | |
3159 | + EventTypeSpec textEventTypes[] = { | |
3160 | + { kEventClassTextInput, kEventTextInputUpdateActiveInputArea }, | |
3161 | + { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, | |
3162 | + { kEventClassTextInput, kEventTextInputPosToOffset }, | |
3163 | + { kEventClassTextInput, kEventTextInputOffsetToPos }, | |
3164 | + }; | |
3165 | + | |
3166 | + keyEventHandlerUPP = NewEventHandlerUPP(gui_mac_handle_text_input); | |
3167 | + if (noErr != InstallApplicationEventHandler(keyEventHandlerUPP, | |
3168 | + NR_ELEMS(textEventTypes), | |
3169 | + textEventTypes, NULL, NULL)) | |
3170 | + { | |
3052 | 3171 | DisposeEventHandlerUPP(keyEventHandlerUPP); |
3053 | 3172 | keyEventHandlerUPP = NULL; |
3054 | 3173 | } |
3174 | + | |
3175 | + EventTypeSpec windowEventTypes[] = { | |
3176 | + { kEventClassWindow, kEventWindowActivated }, | |
3177 | + { kEventClassWindow, kEventWindowDeactivated }, | |
3178 | + }; | |
3179 | + | |
3180 | + /* Install window event handler to support TSMDocument activate and | |
3181 | + * deactivate */ | |
3182 | + winEventHandlerUPP = NewEventHandlerUPP(gui_mac_handle_window_activate); | |
3183 | + if (noErr != InstallWindowEventHandler(gui.VimWindow, | |
3184 | + winEventHandlerUPP, | |
3185 | + NR_ELEMS(windowEventTypes), | |
3186 | + windowEventTypes, NULL, NULL)) | |
3187 | + { | |
3188 | + DisposeEventHandlerUPP(winEventHandlerUPP); | |
3189 | + winEventHandlerUPP = NULL; | |
3190 | + } | |
3055 | 3191 | #endif |
3056 | 3192 | |
3057 | 3193 | /* |
@@ -3107,6 +3243,19 @@ | ||
3107 | 3243 | return OK; |
3108 | 3244 | } |
3109 | 3245 | |
3246 | +#ifdef USE_ATSUI_DRAWING | |
3247 | + static void | |
3248 | +gui_mac_dispose_atsui_style(void) | |
3249 | +{ | |
3250 | + if (p_macatsui && gFontStyle) | |
3251 | + ATSUDisposeStyle(gFontStyle); | |
3252 | +#ifdef FEAT_MBYTE | |
3253 | + if (p_macatsui && gWideFontStyle) | |
3254 | + ATSUDisposeStyle(gWideFontStyle); | |
3255 | +#endif | |
3256 | +} | |
3257 | +#endif | |
3258 | + | |
3110 | 3259 | void |
3111 | 3260 | gui_mch_exit(int rc) |
3112 | 3261 | { |
@@ -3122,8 +3271,13 @@ | ||
3122 | 3271 | DisposeEventHandlerUPP(mouseWheelHandlerUPP); |
3123 | 3272 | |
3124 | 3273 | #ifdef USE_ATSUI_DRAWING |
3125 | - if (p_macatsui && gFontStyle) | |
3126 | - ATSUDisposeStyle(gFontStyle); | |
3274 | + gui_mac_dispose_atsui_style(); | |
3275 | +#endif | |
3276 | + | |
3277 | +#ifdef USE_CARBONKEYHANDLER | |
3278 | + FixTSMDocument(gTSMDocument); | |
3279 | + DeactivateTSMDocument(gTSMDocument); | |
3280 | + DeleteTSMDocument(gTSMDocument); | |
3127 | 3281 | #endif |
3128 | 3282 | |
3129 | 3283 | /* Exit to shell? */ |
@@ -3263,6 +3417,26 @@ | ||
3263 | 3417 | return selected_font; |
3264 | 3418 | } |
3265 | 3419 | |
3420 | +#ifdef USE_ATSUI_DRAWING | |
3421 | + static void | |
3422 | +gui_mac_create_atsui_style(void) | |
3423 | +{ | |
3424 | + if (p_macatsui && gFontStyle == NULL) | |
3425 | + { | |
3426 | + if (ATSUCreateStyle(&gFontStyle) != noErr) | |
3427 | + gFontStyle = NULL; | |
3428 | + } | |
3429 | +#ifdef FEAT_MBYTE | |
3430 | + if (p_macatsui && gWideFontStyle == NULL) | |
3431 | + { | |
3432 | + if (ATSUCreateStyle(&gWideFontStyle) != noErr) | |
3433 | + gWideFontStyle = NULL; | |
3434 | + } | |
3435 | +#endif | |
3436 | + | |
3437 | + p_macatsui_last = p_macatsui; | |
3438 | +} | |
3439 | +#endif | |
3266 | 3440 | |
3267 | 3441 | /* |
3268 | 3442 | * Initialise vim to use the font with the given name. Return FAIL if the font |
@@ -3280,11 +3454,7 @@ | ||
3280 | 3454 | char_u used_font_name[512]; |
3281 | 3455 | |
3282 | 3456 | #ifdef USE_ATSUI_DRAWING |
3283 | - if (p_macatsui && gFontStyle == NULL) | |
3284 | - { | |
3285 | - if (ATSUCreateStyle(&gFontStyle) != noErr) | |
3286 | - gFontStyle = NULL; | |
3287 | - } | |
3457 | + gui_mac_create_atsui_style(); | |
3288 | 3458 | #endif |
3289 | 3459 | |
3290 | 3460 | if (font_name == NULL) |
@@ -3348,49 +3518,8 @@ | ||
3348 | 3518 | gui.char_height = font_info.ascent + font_info.descent + p_linespace; |
3349 | 3519 | |
3350 | 3520 | #ifdef USE_ATSUI_DRAWING |
3351 | - ATSUFontID fontID; | |
3352 | - Fixed fontSize; | |
3353 | - ATSStyleRenderingOptions fontOptions; | |
3354 | - | |
3355 | 3521 | if (p_macatsui && gFontStyle) |
3356 | - { | |
3357 | - fontID = font & 0xFFFF; | |
3358 | - fontSize = Long2Fix(font >> 16); | |
3359 | - | |
3360 | - /* No antialiasing by default (do not attempt to touch antialising | |
3361 | - * options on pre-Jaguar) */ | |
3362 | - fontOptions = | |
3363 | - (gMacSystemVersion >= 0x1020) ? | |
3364 | - kATSStyleNoAntiAliasing : | |
3365 | - kATSStyleNoOptions; | |
3366 | - | |
3367 | - ATSUAttributeTag attribTags[] = | |
3368 | - { | |
3369 | - kATSUFontTag, kATSUSizeTag, kATSUStyleRenderingOptionsTag, | |
3370 | - kATSUMaxATSUITagValue+1 | |
3371 | - }; | |
3372 | - ByteCount attribSizes[] = | |
3373 | - { | |
3374 | - sizeof(ATSUFontID), sizeof(Fixed), | |
3375 | - sizeof(ATSStyleRenderingOptions), sizeof font | |
3376 | - }; | |
3377 | - ATSUAttributeValuePtr attribValues[] = | |
3378 | - { | |
3379 | - &fontID, &fontSize, &fontOptions, &font | |
3380 | - }; | |
3381 | - | |
3382 | - /* Convert font id to ATSUFontID */ | |
3383 | - if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr) | |
3384 | - { | |
3385 | - if (ATSUSetAttributes(gFontStyle, | |
3386 | - (sizeof attribTags)/sizeof(ATSUAttributeTag), | |
3387 | - attribTags, attribSizes, attribValues) != noErr) | |
3388 | - { | |
3389 | - ATSUDisposeStyle(gFontStyle); | |
3390 | - gFontStyle = NULL; | |
3391 | - } | |
3392 | - } | |
3393 | - } | |
3522 | + gui_mac_set_font_attributes(font); | |
3394 | 3523 | #endif |
3395 | 3524 | |
3396 | 3525 | return OK; |
@@ -3447,6 +3576,68 @@ | ||
3447 | 3576 | } |
3448 | 3577 | #endif |
3449 | 3578 | |
3579 | +#ifdef USE_ATSUI_DRAWING | |
3580 | + static void | |
3581 | +gui_mac_set_font_attributes(GuiFont font) | |
3582 | +{ | |
3583 | + ATSUFontID fontID; | |
3584 | + Fixed fontSize; | |
3585 | + Fixed fontWidth; | |
3586 | + | |
3587 | + fontID = font & 0xFFFF; | |
3588 | + fontSize = Long2Fix(font >> 16); | |
3589 | + fontWidth = Long2Fix(gui.char_width); | |
3590 | + | |
3591 | + ATSUAttributeTag attribTags[] = | |
3592 | + { | |
3593 | + kATSUFontTag, kATSUSizeTag, kATSUImposeWidthTag, | |
3594 | + kATSUMaxATSUITagValue + 1 | |
3595 | + }; | |
3596 | + | |
3597 | + ByteCount attribSizes[] = | |
3598 | + { | |
3599 | + sizeof(ATSUFontID), sizeof(Fixed), sizeof(fontWidth), | |
3600 | + sizeof(font) | |
3601 | + }; | |
3602 | + | |
3603 | + ATSUAttributeValuePtr attribValues[] = | |
3604 | + { | |
3605 | + &fontID, &fontSize, &fontWidth, &font | |
3606 | + }; | |
3607 | + | |
3608 | + if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr) | |
3609 | + { | |
3610 | + if (ATSUSetAttributes(gFontStyle, | |
3611 | + (sizeof attribTags) / sizeof(ATSUAttributeTag), | |
3612 | + attribTags, attribSizes, attribValues) != noErr) | |
3613 | + { | |
3614 | +# ifndef NDEBUG | |
3615 | + fprintf(stderr, "couldn't set font style\n"); | |
3616 | +# endif | |
3617 | + ATSUDisposeStyle(gFontStyle); | |
3618 | + gFontStyle = NULL; | |
3619 | + } | |
3620 | + | |
3621 | +#ifdef FEAT_MBYTE | |
3622 | + if (has_mbyte) | |
3623 | + { | |
3624 | + /* FIXME: we should use a more mbyte sensitive way to support | |
3625 | + * wide font drawing */ | |
3626 | + fontWidth = Long2Fix(gui.char_width * 2); | |
3627 | + | |
3628 | + if (ATSUSetAttributes(gWideFontStyle, | |
3629 | + (sizeof attribTags) / sizeof(ATSUAttributeTag), | |
3630 | + attribTags, attribSizes, attribValues) != noErr) | |
3631 | + { | |
3632 | + ATSUDisposeStyle(gWideFontStyle); | |
3633 | + gWideFontStyle = NULL; | |
3634 | + } | |
3635 | + } | |
3636 | +#endif | |
3637 | + } | |
3638 | +} | |
3639 | +#endif | |
3640 | + | |
3450 | 3641 | /* |
3451 | 3642 | * Set the current text font. |
3452 | 3643 | */ |
@@ -3456,63 +3647,19 @@ | ||
3456 | 3647 | #ifdef USE_ATSUI_DRAWING |
3457 | 3648 | GuiFont currFont; |
3458 | 3649 | ByteCount actualFontByteCount; |
3459 | - ATSUFontID fontID; | |
3460 | - Fixed fontSize; | |
3461 | - ATSStyleRenderingOptions fontOptions; | |
3462 | 3650 | |
3463 | 3651 | if (p_macatsui && gFontStyle) |
3464 | 3652 | { |
3465 | 3653 | /* Avoid setting same font again */ |
3466 | - if (ATSUGetAttribute(gFontStyle, kATSUMaxATSUITagValue+1, sizeof font, | |
3467 | - &currFont, &actualFontByteCount) == noErr && | |
3468 | - actualFontByteCount == (sizeof font)) | |
3654 | + if (ATSUGetAttribute(gFontStyle, kATSUMaxATSUITagValue + 1, | |
3655 | + sizeof(font), &currFont, &actualFontByteCount) == noErr | |
3656 | + && actualFontByteCount == (sizeof font)) | |
3469 | 3657 | { |
3470 | 3658 | if (currFont == font) |
3471 | 3659 | return; |
3472 | 3660 | } |
3473 | 3661 | |
3474 | - fontID = font & 0xFFFF; | |
3475 | - fontSize = Long2Fix(font >> 16); | |
3476 | - /* Respect p_antialias setting only for wide font. | |
3477 | - * The reason for doing this at the moment is a bit complicated, | |
3478 | - * but it's mainly because a) latin (non-wide) aliased fonts | |
3479 | - * look bad in OS X 10.3.x and below (due to a bug in ATS), and | |
3480 | - * b) wide multibyte input does not suffer from that problem. */ | |
3481 | - /*fontOptions = | |
3482 | - (p_antialias && (font == gui.wide_font)) ? | |
3483 | - kATSStyleNoOptions : kATSStyleNoAntiAliasing; | |
3484 | - */ | |
3485 | - /*fontOptions = kATSStyleAntiAliasing;*/ | |
3486 | - | |
3487 | - ATSUAttributeTag attribTags[] = | |
3488 | - { | |
3489 | - kATSUFontTag, kATSUSizeTag, kATSUStyleRenderingOptionsTag, | |
3490 | - kATSUMaxATSUITagValue+1 | |
3491 | - }; | |
3492 | - ByteCount attribSizes[] = | |
3493 | - { | |
3494 | - sizeof(ATSUFontID), sizeof(Fixed), | |
3495 | - sizeof(ATSStyleRenderingOptions), sizeof font | |
3496 | - }; | |
3497 | - ATSUAttributeValuePtr attribValues[] = | |
3498 | - { | |
3499 | - &fontID, &fontSize, &fontOptions, &font | |
3500 | - }; | |
3501 | - | |
3502 | - if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr) | |
3503 | - { | |
3504 | - if (ATSUSetAttributes(gFontStyle, | |
3505 | - (sizeof attribTags)/sizeof(ATSUAttributeTag), | |
3506 | - attribTags, attribSizes, attribValues) != noErr) | |
3507 | - { | |
3508 | -# ifndef NDEBUG | |
3509 | - fprintf(stderr, "couldn't set font style\n"); | |
3510 | -# endif | |
3511 | - ATSUDisposeStyle(gFontStyle); | |
3512 | - gFontStyle = NULL; | |
3513 | - } | |
3514 | - } | |
3515 | - | |
3662 | + gui_mac_set_font_attributes(font); | |
3516 | 3663 | } |
3517 | 3664 | |
3518 | 3665 | if (p_macatsui && !gIsFontFallbackSet) |
@@ -3536,7 +3683,9 @@ | ||
3536 | 3683 | &fallbackFonts, |
3537 | 3684 | NULL) == noErr) |
3538 | 3685 | { |
3539 | - ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID), &fallbackFonts, kATSUSequentialFallbacksPreferred); | |
3686 | + ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID), | |
3687 | + &fallbackFonts, | |
3688 | + kATSUSequentialFallbacksPreferred); | |
3540 | 3689 | } |
3541 | 3690 | /* |
3542 | 3691 | ATSUAttributeValuePtr fallbackValues[] = { }; |
@@ -3921,7 +4070,10 @@ | ||
3921 | 4070 | |
3922 | 4071 | /* - ATSUI automatically antialiases text (Someone) |
3923 | 4072 | * - for some reason it does not work... (Jussi) */ |
3924 | - | |
4073 | +#ifdef MAC_ATSUI_DEBUG | |
4074 | + fprintf(stderr, "row = %d, col = %d, len = %d: '%c'\n", | |
4075 | + row, col, len, len == 1 ? s[0] : ' '); | |
4076 | +#endif | |
3925 | 4077 | /* |
3926 | 4078 | * When antialiasing we're using srcOr mode, we have to clear the block |
3927 | 4079 | * before drawing the text. |
@@ -3956,35 +4108,122 @@ | ||
3956 | 4108 | } |
3957 | 4109 | |
3958 | 4110 | { |
3959 | - /* Use old-style, non-antialiased QuickDraw text rendering. */ | |
3960 | 4111 | TextMode(srcCopy); |
3961 | 4112 | TextFace(normal); |
3962 | 4113 | |
3963 | - /* SelectFont(hdc, gui.currFont); */ | |
3964 | - | |
4114 | + /* SelectFont(hdc, gui.currFont); */ | |
3965 | 4115 | if (flags & DRAW_TRANSP) |
3966 | 4116 | { |
3967 | 4117 | TextMode(srcOr); |
3968 | 4118 | } |
3969 | 4119 | |
3970 | 4120 | MoveTo(TEXT_X(col), TEXT_Y(row)); |
3971 | - ATSUTextLayout textLayout; | |
3972 | - | |
3973 | - if (ATSUCreateTextLayoutWithTextPtr(tofree, | |
3974 | - kATSUFromTextBeginning, kATSUToTextEnd, | |
3975 | - utf16_len, | |
3976 | - (gFontStyle ? 1 : 0), &utf16_len, | |
3977 | - (gFontStyle ? &gFontStyle : NULL), | |
3978 | - &textLayout) == noErr) | |
4121 | + | |
4122 | + if (gFontStyle && flags & DRAW_BOLD) | |
3979 | 4123 | { |
4124 | + Boolean attValue = true; | |
4125 | + ATSUAttributeTag attribTags[] = { kATSUQDBoldfaceTag }; | |
4126 | + ByteCount attribSizes[] = { sizeof(Boolean) }; | |
4127 | + ATSUAttributeValuePtr attribValues[] = { &attValue }; | |
4128 | + | |
4129 | + ATSUSetAttributes(gFontStyle, 1, attribTags, attribSizes, attribValues); | |
4130 | + } | |
4131 | + | |
4132 | +#ifdef FEAT_MBYTE | |
4133 | + if (has_mbyte) | |
4134 | + { | |
4135 | + int n, width_in_cell, last_width_in_cell; | |
4136 | + UniCharArrayOffset offset = 0; | |
4137 | + UniCharCount yet_to_draw = 0; | |
4138 | + ATSUTextLayout textLayout; | |
4139 | + ATSUStyle textStyle; | |
4140 | + | |
4141 | + last_width_in_cell = 1; | |
4142 | + ATSUCreateTextLayout(&textLayout); | |
4143 | + ATSUSetTextPointerLocation(textLayout, tofree, | |
4144 | + kATSUFromTextBeginning, | |
4145 | + kATSUToTextEnd, utf16_len); | |
4146 | + /* | |
4147 | + ATSUSetRunStyle(textLayout, gFontStyle, | |
4148 | + kATSUFromTextBeginning, kATSUToTextEnd); */ | |
4149 | + | |
4150 | + /* Compute the length in display cells. */ | |
4151 | + for (n = 0; n < len; n += MB_BYTE2LEN(s[n])) | |
4152 | + { | |
4153 | + width_in_cell = (*mb_ptr2cells)(s + n); | |
4154 | + | |
4155 | + /* probably we are switching from single byte character | |
4156 | + * to multibyte characters (which requires more than one | |
4157 | + * cell to draw) */ | |
4158 | + if (width_in_cell != last_width_in_cell) | |
4159 | + { | |
4160 | +#ifdef MAC_ATSUI_DEBUG | |
4161 | + fprintf(stderr, "\tn = %2d, (%d-%d), offset = %d, yet_to_draw = %d\n", | |
4162 | + n, last_width_in_cell, width_in_cell, offset, yet_to_draw); | |
4163 | +#endif | |
4164 | + textStyle = last_width_in_cell > 1 ? gWideFontStyle | |
4165 | + : gFontStyle; | |
4166 | + | |
4167 | + ATSUSetRunStyle(textLayout, textStyle, offset, yet_to_draw); | |
4168 | + offset += yet_to_draw; | |
4169 | + yet_to_draw = 0; | |
4170 | + last_width_in_cell = width_in_cell; | |
4171 | + } | |
4172 | + | |
4173 | + yet_to_draw++; | |
4174 | + } | |
4175 | + | |
4176 | + if (yet_to_draw) | |
4177 | + { | |
4178 | +#ifdef MAC_ATSUI_DEBUG | |
4179 | + fprintf(stderr, "\tn = %2d, (%d-%d), offset = %d, yet_to_draw = %d\n", | |
4180 | + n, last_width_in_cell, width_in_cell, offset, yet_to_draw); | |
4181 | +#endif | |
4182 | + /* finish the rest style */ | |
4183 | + textStyle = width_in_cell > 1 ? gWideFontStyle : gFontStyle; | |
4184 | + ATSUSetRunStyle(textLayout, textStyle, offset, kATSUToTextEnd); | |
4185 | + } | |
4186 | + | |
3980 | 4187 | ATSUSetTransientFontMatching(textLayout, TRUE); |
3981 | - | |
3982 | 4188 | ATSUDrawText(textLayout, |
3983 | - kATSUFromTextBeginning, kATSUToTextEnd, | |
3984 | - kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | |
3985 | - | |
4189 | + kATSUFromTextBeginning, kATSUToTextEnd, | |
4190 | + kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | |
3986 | 4191 | ATSUDisposeTextLayout(textLayout); |
3987 | 4192 | } |
4193 | + else | |
4194 | +#endif | |
4195 | + { | |
4196 | + ATSUTextLayout textLayout; | |
4197 | + | |
4198 | + if (ATSUCreateTextLayoutWithTextPtr(tofree, | |
4199 | + kATSUFromTextBeginning, kATSUToTextEnd, | |
4200 | + utf16_len, | |
4201 | + (gFontStyle ? 1 : 0), &utf16_len, | |
4202 | + (gFontStyle ? &gFontStyle : NULL), | |
4203 | + &textLayout) == noErr) | |
4204 | + { | |
4205 | + ATSUSetTransientFontMatching(textLayout, TRUE); | |
4206 | + | |
4207 | + ATSUDrawText(textLayout, | |
4208 | + kATSUFromTextBeginning, kATSUToTextEnd, | |
4209 | + kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc); | |
4210 | + | |
4211 | + ATSUDisposeTextLayout(textLayout); | |
4212 | + } | |
4213 | + } | |
4214 | + | |
4215 | + /* drawing is done, now reset bold to normal */ | |
4216 | + if (gFontStyle && flags & DRAW_BOLD) | |
4217 | + { | |
4218 | + Boolean attValue = false; | |
4219 | + | |
4220 | + ATSUAttributeTag attribTags[] = { kATSUQDBoldfaceTag }; | |
4221 | + ByteCount attribSizes[] = { sizeof(Boolean) }; | |
4222 | + ATSUAttributeValuePtr attribValues[] = { &attValue }; | |
4223 | + | |
4224 | + ATSUSetAttributes(gFontStyle, 1, attribTags, attribSizes, | |
4225 | + attribValues); | |
4226 | + } | |
3988 | 4227 | } |
3989 | 4228 | |
3990 | 4229 | if (flags & DRAW_UNDERC) |
@@ -3998,6 +4237,13 @@ | ||
3998 | 4237 | gui_mch_draw_string(int row, int col, char_u *s, int len, int flags) |
3999 | 4238 | { |
4000 | 4239 | #if defined(USE_ATSUI_DRAWING) |
4240 | + if (p_macatsui == 0 && p_macatsui_last != 0) | |
4241 | + /* switch from macatsui to nomacatsui */ | |
4242 | + gui_mac_dispose_atsui_style(); | |
4243 | + else if (p_macatsui != 0 && p_macatsui_last == 0) | |
4244 | + /* switch from nomacatsui to macatsui */ | |
4245 | + gui_mac_create_atsui_style(); | |
4246 | + | |
4001 | 4247 | if (p_macatsui) |
4002 | 4248 | draw_string_ATSUI(row, col, s, len, flags); |
4003 | 4249 | else |
@@ -4228,12 +4474,13 @@ | ||
4228 | 4474 | */ |
4229 | 4475 | /* TODO: reduce wtime accordinly??? */ |
4230 | 4476 | if (wtime > -1) |
4231 | - sleeppyTick = 60*wtime/1000; | |
4477 | + sleeppyTick = 60 * wtime / 1000; | |
4232 | 4478 | else |
4233 | 4479 | sleeppyTick = 32767; |
4480 | + | |
4234 | 4481 | if (WaitNextEventWrp(mask, &event, sleeppyTick, dragRgn)) |
4235 | 4482 | { |
4236 | - gui_mac_handle_event(&event); | |
4483 | + gui_mac_handle_event(&event); | |
4237 | 4484 | if (input_available()) |
4238 | 4485 | { |
4239 | 4486 | allow_scrollbar = FALSE; |
@@ -6031,7 +6278,7 @@ | ||
6031 | 6278 | #endif |
6032 | 6279 | } |
6033 | 6280 | |
6034 | -#if defined(USE_IM_CONTROL) || defined(PROTO) | |
6281 | +#if (defined(USE_IM_CONTROL) || defined(PROTO)) && defined(USE_CARBONKEYHANDLER) | |
6035 | 6282 | /* |
6036 | 6283 | * Input Method Control functions. |
6037 | 6284 | */ |
@@ -6042,7 +6289,71 @@ | ||
6042 | 6289 | void |
6043 | 6290 | im_set_position(int row, int col) |
6044 | 6291 | { |
6292 | +#if 0 | |
6045 | 6293 | /* TODO: Implement me! */ |
6294 | + im_start_row = row; | |
6295 | + im_start_col = col; | |
6296 | +#endif | |
6297 | +} | |
6298 | + | |
6299 | +static ScriptLanguageRecord gTSLWindow; | |
6300 | +static ScriptLanguageRecord gTSLInsert; | |
6301 | +static ScriptLanguageRecord gTSLDefault = { 0, 0 }; | |
6302 | + | |
6303 | +static Component gTSCWindow; | |
6304 | +static Component gTSCInsert; | |
6305 | +static Component gTSCDefault; | |
6306 | + | |
6307 | +static int im_initialized = 0; | |
6308 | + | |
6309 | + static void | |
6310 | +im_on_window_switch(int active) | |
6311 | +{ | |
6312 | + ScriptLanguageRecord *slptr = NULL; | |
6313 | + OSStatus err; | |
6314 | + | |
6315 | + if (! gui.in_use) | |
6316 | + return; | |
6317 | + | |
6318 | + if (im_initialized == 0) | |
6319 | + { | |
6320 | + im_initialized = 1; | |
6321 | + | |
6322 | + /* save default TSM component (should be U.S.) to default */ | |
6323 | + GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault, | |
6324 | + kKeyboardInputMethodClass); | |
6325 | + } | |
6326 | + | |
6327 | + if (active == TRUE) | |
6328 | + { | |
6329 | + im_is_active = TRUE; | |
6330 | + ActivateTSMDocument(gTSMDocument); | |
6331 | + slptr = &gTSLWindow; | |
6332 | + | |
6333 | + if (slptr) | |
6334 | + { | |
6335 | + err = SetDefaultInputMethodOfClass(gTSCWindow, slptr, | |
6336 | + kKeyboardInputMethodClass); | |
6337 | + if (err == noErr) | |
6338 | + err = SetTextServiceLanguage(slptr); | |
6339 | + | |
6340 | + if (err == noErr) | |
6341 | + KeyScript(slptr->fScript | smKeyForceKeyScriptMask); | |
6342 | + } | |
6343 | + } | |
6344 | + else | |
6345 | + { | |
6346 | + err = GetTextServiceLanguage(&gTSLWindow); | |
6347 | + if (err == noErr) | |
6348 | + slptr = &gTSLWindow; | |
6349 | + | |
6350 | + if (slptr) | |
6351 | + GetDefaultInputMethodOfClass(&gTSCWindow, slptr, | |
6352 | + kKeyboardInputMethodClass); | |
6353 | + | |
6354 | + im_is_active = FALSE; | |
6355 | + DeactivateTSMDocument(gTSMDocument); | |
6356 | + } | |
6046 | 6357 | } |
6047 | 6358 | |
6048 | 6359 | /* |
@@ -6051,7 +6362,57 @@ | ||
6051 | 6362 | void |
6052 | 6363 | im_set_active(int active) |
6053 | 6364 | { |
6054 | - KeyScript(active ? smKeySysScript : smKeyRoman); | |
6365 | + ScriptLanguageRecord *slptr = NULL; | |
6366 | + OSStatus err; | |
6367 | + | |
6368 | + if (! gui.in_use) | |
6369 | + return; | |
6370 | + | |
6371 | + if (im_initialized == 0) | |
6372 | + { | |
6373 | + im_initialized = 1; | |
6374 | + | |
6375 | + /* save default TSM component (should be U.S.) to default */ | |
6376 | + GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault, | |
6377 | + kKeyboardInputMethodClass); | |
6378 | + } | |
6379 | + | |
6380 | + if (active == TRUE) | |
6381 | + { | |
6382 | + im_is_active = TRUE; | |
6383 | + ActivateTSMDocument(gTSMDocument); | |
6384 | + slptr = &gTSLInsert; | |
6385 | + | |
6386 | + if (slptr) | |
6387 | + { | |
6388 | + err = SetDefaultInputMethodOfClass(gTSCInsert, slptr, | |
6389 | + kKeyboardInputMethodClass); | |
6390 | + if (err == noErr) | |
6391 | + err = SetTextServiceLanguage(slptr); | |
6392 | + | |
6393 | + if (err == noErr) | |
6394 | + KeyScript(slptr->fScript | smKeyForceKeyScriptMask); | |
6395 | + } | |
6396 | + } | |
6397 | + else | |
6398 | + { | |
6399 | + err = GetTextServiceLanguage(&gTSLInsert); | |
6400 | + if (err == noErr) | |
6401 | + slptr = &gTSLInsert; | |
6402 | + | |
6403 | + if (slptr) | |
6404 | + GetDefaultInputMethodOfClass(&gTSCInsert, slptr, | |
6405 | + kKeyboardInputMethodClass); | |
6406 | + | |
6407 | + /* restore to default when switch to normal mode, so than we could | |
6408 | + * enter commands easier */ | |
6409 | + SetDefaultInputMethodOfClass(gTSCDefault, &gTSLDefault, | |
6410 | + kKeyboardInputMethodClass); | |
6411 | + SetTextServiceLanguage(&gTSLDefault); | |
6412 | + | |
6413 | + im_is_active = FALSE; | |
6414 | + DeactivateTSMDocument(gTSMDocument); | |
6415 | + } | |
6055 | 6416 | } |
6056 | 6417 | |
6057 | 6418 | /* |
@@ -6060,9 +6421,10 @@ | ||
6060 | 6421 | int |
6061 | 6422 | im_get_status(void) |
6062 | 6423 | { |
6063 | - SInt32 script = GetScriptManagerVariable(smKeyScript); | |
6064 | - return (script != smRoman | |
6065 | - && script == GetScriptManagerVariable(smSysScript)) ? 1 : 0; | |
6424 | + if (! gui.in_use) | |
6425 | + return 0; | |
6426 | + | |
6427 | + return im_is_active; | |
6066 | 6428 | } |
6067 | 6429 | |
6068 | 6430 | #endif /* defined(USE_IM_CONTROL) || defined(PROTO) */ |
@@ -6118,7 +6480,7 @@ | ||
6118 | 6480 | int numTabs = 0; |
6119 | 6481 | |
6120 | 6482 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
6121 | - ++numTabs; | |
6483 | + ++numTabs; | |
6122 | 6484 | return numTabs; |
6123 | 6485 | } |
6124 | 6486 |
@@ -6126,8 +6488,8 @@ | ||
6126 | 6488 | static OSStatus |
6127 | 6489 | dbItemDataCallback(ControlRef browser, |
6128 | 6490 | DataBrowserItemID itemID, |
6129 | - DataBrowserPropertyID property /* column id */, | |
6130 | - DataBrowserItemDataRef itemData, | |
6491 | + DataBrowserPropertyID property /* column id */, | |
6492 | + DataBrowserItemDataRef itemData, | |
6131 | 6493 | Boolean changeValue) |
6132 | 6494 | { |
6133 | 6495 | OSStatus status = noErr; |
@@ -6170,9 +6532,9 @@ | ||
6170 | 6532 | static void |
6171 | 6533 | dbGetContextualMenuCallback(ControlRef browser, |
6172 | 6534 | MenuRef *menu, |
6173 | - UInt32 *helpType, | |
6535 | + UInt32 *helpType, | |
6174 | 6536 | CFStringRef *helpItemString, |
6175 | - AEDesc *selection) | |
6537 | + AEDesc *selection) | |
6176 | 6538 | { |
6177 | 6539 | // on mac os 9: kCMHelpItemNoHelp, but it's not the same |
6178 | 6540 | *helpType = kCMHelpItemRemoveHelp; // OS X only ;-) |
@@ -6395,9 +6757,9 @@ | ||
6395 | 6757 | gui_mch_show_tabline(int showit) |
6396 | 6758 | { |
6397 | 6759 | if (showit == 0) |
6398 | - CloseDrawer(drawer, true); | |
6760 | + CloseDrawer(drawer, true); | |
6399 | 6761 | else |
6400 | - OpenDrawer(drawer, kWindowEdgeRight, true); | |
6762 | + OpenDrawer(drawer, kWindowEdgeRight, true); | |
6401 | 6763 | } |
6402 | 6764 | |
6403 | 6765 | /* |
@@ -6425,11 +6787,11 @@ | ||
6425 | 6787 | // adjust data browser |
6426 | 6788 | if (tabLabels != NULL) |
6427 | 6789 | { |
6428 | - int i; | |
6429 | - | |
6430 | - for (i = 0; i < tabLabelsSize; ++i) | |
6431 | - CFRelease(tabLabels[i]); | |
6432 | - free(tabLabels); | |
6790 | + int i; | |
6791 | + | |
6792 | + for (i = 0; i < tabLabelsSize; ++i) | |
6793 | + CFRelease(tabLabels[i]); | |
6794 | + free(tabLabels); | |
6433 | 6795 | } |
6434 | 6796 | tabLabels = (CFStringRef *)malloc(numTabs * sizeof(CFStringRef)); |
6435 | 6797 | tabLabelsSize = numTabs; |
@@ -6438,7 +6800,7 @@ | ||
6438 | 6800 | { |
6439 | 6801 | if (tp == curtab) |
6440 | 6802 | curtabidx = nr; |
6441 | - tabLabels[nr-1] = getTabLabel(tp); | |
6803 | + tabLabels[nr-1] = getTabLabel(tp); | |
6442 | 6804 | } |
6443 | 6805 | |
6444 | 6806 | RemoveDataBrowserItems(dataBrowser, kDataBrowserNoItem, 0, NULL, |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 275, | |
671 | +/**/ | |
670 | 672 | 274, |
671 | 673 | /**/ |
672 | 674 | 273, |
@@ -461,8 +461,9 @@ | ||
461 | 461 | /* |
462 | 462 | * Check input method control. |
463 | 463 | */ |
464 | -#if defined(FEAT_XIM) || \ | |
465 | - (defined(FEAT_GUI) && (defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME))) | |
464 | +#if defined(FEAT_XIM) \ | |
465 | + || (defined(FEAT_GUI) && (defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME))) \ | |
466 | + || defined(FEAT_GUI_MAC) | |
466 | 467 | # define USE_IM_CONTROL |
467 | 468 | #endif |
468 | 469 |