• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Révision437fb19625c9e24e2157563cf0a55aeb432b2990 (tree)
l'heure2008-03-12 22:40:54
Auteurvimboss
Commitervimboss

Message de Log

updated for version 7.1-275

Change Summary

Modification

diff -r a83f48a17efb -r 437fb19625c9 src/gui_mac.c
--- a/src/gui_mac.c Wed Mar 12 12:46:13 2008 +0000
+++ b/src/gui_mac.c Wed Mar 12 13:40:54 2008 +0000
@@ -59,7 +59,33 @@
5959
6060 #ifdef MACOS_CONVERT
6161 # 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);
6274 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+
6389 #endif
6490
6591
@@ -137,7 +163,11 @@
137163
138164 #ifdef MACOS_CONVERT
139165 # define USE_ATSUI_DRAWING
166+int p_macatsui_last;
140167 ATSUStyle gFontStyle;
168+# ifdef FEAT_MBYTE
169+ATSUStyle gWideFontStyle;
170+# endif
141171 Boolean gIsFontFallbackSet;
142172 #endif
143173
@@ -265,6 +295,11 @@
265295 static WindowRef drawer = NULL; // TODO: put into gui.h
266296 #endif
267297
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+
268303 /*
269304 * ------------------------------------------------------------
270305 * Conversion Utility
@@ -1935,12 +1970,12 @@
19351970 /* Dim scrollbars */
19361971 if (whichWindow == gui.VimWindow)
19371972 {
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);
19441979 }
19451980
19461981 /* Activate */
@@ -1976,15 +2011,87 @@
19762011 * Handle the key
19772012 */
19782013 #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 */
19812089
19822090 # define INLINE_KEY_BUFFER_SIZE 80
19832091 static pascal OSStatus
1984-gui_mac_doKeyEventCarbon(
2092+gui_mac_unicode_key_event(
19852093 EventHandlerCallRef nextHandler,
1986- EventRef theEvent,
1987- void *data)
2094+ EventRef theEvent)
19882095 {
19892096 /* Multibyte-friendly key event handler */
19902097 OSStatus err = -1;
@@ -2000,7 +2107,7 @@
20002107 char_u *to = NULL;
20012108 Boolean isSpecial = FALSE;
20022109 int i;
2003- EventRef keyEvent;
2110+ EventRef keyEvent;
20042111
20052112 /* Mask the mouse (as per user setting) */
20062113 if (p_mh)
@@ -2008,39 +2115,39 @@
20082115
20092116 /* Don't use the keys when the dialog wants them. */
20102117 if (dialog_busy)
2011- return eventNotHandledErr;
2118+ return eventNotHandledErr;
20122119
20132120 if (noErr != GetEventParameter(theEvent, kEventParamTextInputSendText,
2014- typeUnicodeText, NULL, 0, &actualSize, NULL))
2015- return eventNotHandledErr;
2121+ typeUnicodeText, NULL, 0, &actualSize, NULL))
2122+ return eventNotHandledErr;
20162123
20172124 text = (UniChar *)alloc(actualSize);
20182125 if (!text)
2019- return eventNotHandledErr;
2126+ return eventNotHandledErr;
20202127
20212128 err = GetEventParameter(theEvent, kEventParamTextInputSendText,
2022- typeUnicodeText, NULL, actualSize, NULL, text);
2129+ typeUnicodeText, NULL, actualSize, NULL, text);
20232130 require_noerr(err, done);
20242131
20252132 err = GetEventParameter(theEvent, kEventParamTextInputSendKeyboardEvent,
2026- typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent);
2133+ typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent);
20272134 require_noerr(err, done);
20282135
20292136 err = GetEventParameter(keyEvent, kEventParamKeyModifiers,
2030- typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
2137+ typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
20312138 require_noerr(err, done);
20322139
20332140 err = GetEventParameter(keyEvent, kEventParamKeyCode,
2034- typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym);
2141+ typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym);
20352142 require_noerr(err, done);
20362143
20372144 err = GetEventParameter(keyEvent, kEventParamKeyMacCharCodes,
2038- typeChar, NULL, sizeof(char), NULL, &charcode);
2145+ typeChar, NULL, sizeof(char), NULL, &charcode);
20392146 require_noerr(err, done);
20402147
20412148 #ifndef USE_CMD_KEY
20422149 if (modifiers & cmdKey)
2043- goto done; /* Let system handle Cmd+... */
2150+ goto done; /* Let system handle Cmd+... */
20442151 #endif
20452152
20462153 key_char = charcode;
@@ -2048,84 +2155,84 @@
20482155
20492156 /* Find the special key (eg., for cursor keys) */
20502157 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+ }
20632170 }
20642171
20652172 /* Intercept CMD-. and CTRL-c */
20662173 if (((modifiers & controlKey) && key_char == 'c') ||
2067- ((modifiers & cmdKey) && key_char == '.'))
2068- got_int = TRUE;
2174+ ((modifiers & cmdKey) && key_char == '.'))
2175+ got_int = TRUE;
20692176
20702177 if (!isSpecial)
20712178 {
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+ }
20962203 }
20972204
20982205 if (vimModifiers)
20992206 {
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;
21032210 }
21042211
21052212 if (isSpecial && IS_SPECIAL(key_char))
21062213 {
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);
21102217 }
21112218 else
21122219 {
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+ }
21292236 }
21302237
21312238 add_to_input_buf(result, len);
@@ -2135,10 +2242,10 @@
21352242 vim_free(text);
21362243 if (err == noErr)
21372244 {
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;
21422249 }
21432250
21442251 return eventNotHandledErr;
@@ -2334,7 +2441,7 @@
23342441 /* prevent that the vim window size changes if it's activated by a
23352442 click into the tab pane */
23362443 if (whichWindow == drawer)
2337- return;
2444+ return;
23382445 #endif
23392446
23402447 switch (thePart)
@@ -2569,11 +2676,11 @@
25692676 if (IsShowContextualMenuClick(event))
25702677 {
25712678 # if 0
2572- gui_mac_handle_contextual_menu(event);
2679+ gui_mac_handle_contextual_menu(event);
25732680 # else
2574- gui_mac_doMouseDownEvent(event);
2681+ gui_mac_doMouseDownEvent(event);
25752682 # endif
2576- return;
2683+ return;
25772684 }
25782685
25792686 /* Handle normal event */
@@ -2832,7 +2939,6 @@
28322939 # else
28332940 /* OSErr GetApplicationBundleFSSpec(FSSpecPtr theFSSpecPtr)
28342941 * of TN2015
2835- * This technic remove the ../Contents/MacOS/etc part
28362942 */
28372943 (void)GetCurrentProcess(&psn);
28382944 /* if (err != noErr) return err; */
@@ -2933,10 +3039,9 @@
29333039 /* TODO: Move most of this stuff toward gui_mch_init */
29343040 Rect windRect;
29353041 MenuHandle pomme;
2936- EventTypeSpec eventTypeSpec;
29373042 EventHandlerRef mouseWheelHandlerRef;
29383043 #ifdef USE_CARBONKEYHANDLER
2939- EventHandlerRef keyEventHandlerRef;
3044+ EventTypeSpec eventTypeSpec;
29403045 #endif
29413046 ControlRef rootControl;
29423047
@@ -3042,16 +3147,47 @@
30423147 }
30433148
30443149 #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+ {
30523171 DisposeEventHandlerUPP(keyEventHandlerUPP);
30533172 keyEventHandlerUPP = NULL;
30543173 }
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+ }
30553191 #endif
30563192
30573193 /*
@@ -3107,6 +3243,19 @@
31073243 return OK;
31083244 }
31093245
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+
31103259 void
31113260 gui_mch_exit(int rc)
31123261 {
@@ -3122,8 +3271,13 @@
31223271 DisposeEventHandlerUPP(mouseWheelHandlerUPP);
31233272
31243273 #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);
31273281 #endif
31283282
31293283 /* Exit to shell? */
@@ -3263,6 +3417,26 @@
32633417 return selected_font;
32643418 }
32653419
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
32663440
32673441 /*
32683442 * Initialise vim to use the font with the given name. Return FAIL if the font
@@ -3280,11 +3454,7 @@
32803454 char_u used_font_name[512];
32813455
32823456 #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();
32883458 #endif
32893459
32903460 if (font_name == NULL)
@@ -3348,49 +3518,8 @@
33483518 gui.char_height = font_info.ascent + font_info.descent + p_linespace;
33493519
33503520 #ifdef USE_ATSUI_DRAWING
3351- ATSUFontID fontID;
3352- Fixed fontSize;
3353- ATSStyleRenderingOptions fontOptions;
3354-
33553521 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);
33943523 #endif
33953524
33963525 return OK;
@@ -3447,6 +3576,68 @@
34473576 }
34483577 #endif
34493578
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+
34503641 /*
34513642 * Set the current text font.
34523643 */
@@ -3456,63 +3647,19 @@
34563647 #ifdef USE_ATSUI_DRAWING
34573648 GuiFont currFont;
34583649 ByteCount actualFontByteCount;
3459- ATSUFontID fontID;
3460- Fixed fontSize;
3461- ATSStyleRenderingOptions fontOptions;
34623650
34633651 if (p_macatsui && gFontStyle)
34643652 {
34653653 /* 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))
34693657 {
34703658 if (currFont == font)
34713659 return;
34723660 }
34733661
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);
35163663 }
35173664
35183665 if (p_macatsui && !gIsFontFallbackSet)
@@ -3536,7 +3683,9 @@
35363683 &fallbackFonts,
35373684 NULL) == noErr)
35383685 {
3539- ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID), &fallbackFonts, kATSUSequentialFallbacksPreferred);
3686+ ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID),
3687+ &fallbackFonts,
3688+ kATSUSequentialFallbacksPreferred);
35403689 }
35413690 /*
35423691 ATSUAttributeValuePtr fallbackValues[] = { };
@@ -3921,7 +4070,10 @@
39214070
39224071 /* - ATSUI automatically antialiases text (Someone)
39234072 * - 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
39254077 /*
39264078 * When antialiasing we're using srcOr mode, we have to clear the block
39274079 * before drawing the text.
@@ -3956,35 +4108,122 @@
39564108 }
39574109
39584110 {
3959- /* Use old-style, non-antialiased QuickDraw text rendering. */
39604111 TextMode(srcCopy);
39614112 TextFace(normal);
39624113
3963- /* SelectFont(hdc, gui.currFont); */
3964-
4114+ /* SelectFont(hdc, gui.currFont); */
39654115 if (flags & DRAW_TRANSP)
39664116 {
39674117 TextMode(srcOr);
39684118 }
39694119
39704120 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)
39794123 {
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+
39804187 ATSUSetTransientFontMatching(textLayout, TRUE);
3981-
39824188 ATSUDrawText(textLayout,
3983- kATSUFromTextBeginning, kATSUToTextEnd,
3984- kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
3985-
4189+ kATSUFromTextBeginning, kATSUToTextEnd,
4190+ kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
39864191 ATSUDisposeTextLayout(textLayout);
39874192 }
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+ }
39884227 }
39894228
39904229 if (flags & DRAW_UNDERC)
@@ -3998,6 +4237,13 @@
39984237 gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
39994238 {
40004239 #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+
40014247 if (p_macatsui)
40024248 draw_string_ATSUI(row, col, s, len, flags);
40034249 else
@@ -4228,12 +4474,13 @@
42284474 */
42294475 /* TODO: reduce wtime accordinly??? */
42304476 if (wtime > -1)
4231- sleeppyTick = 60*wtime/1000;
4477+ sleeppyTick = 60 * wtime / 1000;
42324478 else
42334479 sleeppyTick = 32767;
4480+
42344481 if (WaitNextEventWrp(mask, &event, sleeppyTick, dragRgn))
42354482 {
4236- gui_mac_handle_event(&event);
4483+ gui_mac_handle_event(&event);
42374484 if (input_available())
42384485 {
42394486 allow_scrollbar = FALSE;
@@ -6031,7 +6278,7 @@
60316278 #endif
60326279 }
60336280
6034-#if defined(USE_IM_CONTROL) || defined(PROTO)
6281+#if (defined(USE_IM_CONTROL) || defined(PROTO)) && defined(USE_CARBONKEYHANDLER)
60356282 /*
60366283 * Input Method Control functions.
60376284 */
@@ -6042,7 +6289,71 @@
60426289 void
60436290 im_set_position(int row, int col)
60446291 {
6292+#if 0
60456293 /* 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+ }
60466357 }
60476358
60486359 /*
@@ -6051,7 +6362,57 @@
60516362 void
60526363 im_set_active(int active)
60536364 {
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+ }
60556416 }
60566417
60576418 /*
@@ -6060,9 +6421,10 @@
60606421 int
60616422 im_get_status(void)
60626423 {
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;
60666428 }
60676429
60686430 #endif /* defined(USE_IM_CONTROL) || defined(PROTO) */
@@ -6118,7 +6480,7 @@
61186480 int numTabs = 0;
61196481
61206482 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
6121- ++numTabs;
6483+ ++numTabs;
61226484 return numTabs;
61236485 }
61246486
@@ -6126,8 +6488,8 @@
61266488 static OSStatus
61276489 dbItemDataCallback(ControlRef browser,
61286490 DataBrowserItemID itemID,
6129- DataBrowserPropertyID property /* column id */,
6130- DataBrowserItemDataRef itemData,
6491+ DataBrowserPropertyID property /* column id */,
6492+ DataBrowserItemDataRef itemData,
61316493 Boolean changeValue)
61326494 {
61336495 OSStatus status = noErr;
@@ -6170,9 +6532,9 @@
61706532 static void
61716533 dbGetContextualMenuCallback(ControlRef browser,
61726534 MenuRef *menu,
6173- UInt32 *helpType,
6535+ UInt32 *helpType,
61746536 CFStringRef *helpItemString,
6175- AEDesc *selection)
6537+ AEDesc *selection)
61766538 {
61776539 // on mac os 9: kCMHelpItemNoHelp, but it's not the same
61786540 *helpType = kCMHelpItemRemoveHelp; // OS X only ;-)
@@ -6395,9 +6757,9 @@
63956757 gui_mch_show_tabline(int showit)
63966758 {
63976759 if (showit == 0)
6398- CloseDrawer(drawer, true);
6760+ CloseDrawer(drawer, true);
63996761 else
6400- OpenDrawer(drawer, kWindowEdgeRight, true);
6762+ OpenDrawer(drawer, kWindowEdgeRight, true);
64016763 }
64026764
64036765 /*
@@ -6425,11 +6787,11 @@
64256787 // adjust data browser
64266788 if (tabLabels != NULL)
64276789 {
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);
64336795 }
64346796 tabLabels = (CFStringRef *)malloc(numTabs * sizeof(CFStringRef));
64356797 tabLabelsSize = numTabs;
@@ -6438,7 +6800,7 @@
64386800 {
64396801 if (tp == curtab)
64406802 curtabidx = nr;
6441- tabLabels[nr-1] = getTabLabel(tp);
6803+ tabLabels[nr-1] = getTabLabel(tp);
64426804 }
64436805
64446806 RemoveDataBrowserItems(dataBrowser, kDataBrowserNoItem, 0, NULL,
diff -r a83f48a17efb -r 437fb19625c9 src/version.c
--- a/src/version.c Wed Mar 12 12:46:13 2008 +0000
+++ b/src/version.c Wed Mar 12 13:40:54 2008 +0000
@@ -667,6 +667,8 @@
667667 static int included_patches[] =
668668 { /* Add new patch number below this line */
669669 /**/
670+ 275,
671+/**/
670672 274,
671673 /**/
672674 273,
diff -r a83f48a17efb -r 437fb19625c9 src/vim.h
--- a/src/vim.h Wed Mar 12 12:46:13 2008 +0000
+++ b/src/vim.h Wed Mar 12 13:40:54 2008 +0000
@@ -461,8 +461,9 @@
461461 /*
462462 * Check input method control.
463463 */
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)
466467 # define USE_IM_CONTROL
467468 #endif
468469
Afficher sur ancien navigateur de dépôt.