4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: Mac: ATSUI and 'antialias' don't work properly together.
12 Solution: Fix this and the input method. (Jjgod Jiang)
13 Files: src/vim.h, src/gui_mac.c
16 *** ../vim-7.1.274/src/vim.h Wed Feb 20 12:22:59 2008
17 --- src/vim.h Wed Mar 12 13:18:58 2008
21 * Check input method control.
23 ! #if defined(FEAT_XIM) || \
24 ! (defined(FEAT_GUI) && (defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME)))
25 # define USE_IM_CONTROL
30 * Check input method control.
32 ! #if defined(FEAT_XIM) \
33 ! || (defined(FEAT_GUI) && (defined(FEAT_MBYTE_IME) || defined(GLOBAL_IME))) \
34 ! || defined(FEAT_GUI_MAC)
35 # define USE_IM_CONTROL
38 *** ../vim-7.1.274/src/gui_mac.c Sat Sep 29 13:15:29 2007
39 --- src/gui_mac.c Wed Mar 12 13:40:57 2008
45 # define USE_CARBONKEYHANDLER
47 + static int im_is_active = FALSE;
49 + static int im_start_row = 0;
50 + static int im_start_col = 0;
53 + #define NR_ELEMS(x) (sizeof(x) / sizeof(x[0]))
55 + static TSMDocumentID gTSMDocument;
57 + static void im_on_window_switch(int active);
58 static EventHandlerUPP keyEventHandlerUPP = NULL;
59 + static EventHandlerUPP winEventHandlerUPP = NULL;
61 + static pascal OSStatus gui_mac_handle_window_activate(
62 + EventHandlerCallRef nextHandler, EventRef theEvent, void *data);
64 + static pascal OSStatus gui_mac_handle_text_input(
65 + EventHandlerCallRef nextHandler, EventRef theEvent, void *data);
67 + static pascal OSStatus gui_mac_update_input_area(
68 + EventHandlerCallRef nextHandler, EventRef theEvent);
70 + static pascal OSStatus gui_mac_unicode_key_event(
71 + EventHandlerCallRef nextHandler, EventRef theEvent);
81 # define USE_ATSUI_DRAWING
82 + int p_macatsui_last;
85 + ATSUStyle gWideFontStyle;
87 Boolean gIsFontFallbackSet;
93 static WindowRef drawer = NULL; // TODO: put into gui.h
96 + #ifdef USE_ATSUI_DRAWING
97 + static void gui_mac_set_font_attributes(GuiFont font);
98 + static void gui_mac_dispose_atsui_style(void);
102 * ------------------------------------------------------------
107 if (whichWindow == gui.VimWindow)
109 ! ControlRef rootControl;
110 ! GetRootControl(gui.VimWindow, &rootControl);
111 ! if ((event->modifiers) & activeFlag)
112 ! ActivateControl(rootControl);
114 ! DeactivateControl(rootControl);
120 if (whichWindow == gui.VimWindow)
122 ! ControlRef rootControl;
123 ! GetRootControl(gui.VimWindow, &rootControl);
124 ! if ((event->modifiers) & activeFlag)
125 ! ActivateControl(rootControl);
127 ! DeactivateControl(rootControl);
135 #ifdef USE_CARBONKEYHANDLER
137 ! static int dialog_busy = FALSE; /* TRUE when gui_mch_dialog() wants the keys */
139 # define INLINE_KEY_BUFFER_SIZE 80
140 static pascal OSStatus
141 ! gui_mac_doKeyEventCarbon(
142 EventHandlerCallRef nextHandler,
146 /* Multibyte-friendly key event handler */
151 #ifdef USE_CARBONKEYHANDLER
152 + static pascal OSStatus
153 + gui_mac_handle_window_activate(
154 + EventHandlerCallRef nextHandler,
158 + UInt32 eventClass = GetEventClass(theEvent);
159 + UInt32 eventKind = GetEventKind(theEvent);
161 + if (eventClass == kEventClassWindow)
165 + case kEventWindowActivated:
166 + #if defined(USE_IM_CONTROL)
167 + im_on_window_switch(TRUE);
171 + case kEventWindowDeactivated:
172 + #if defined(USE_IM_CONTROL)
173 + im_on_window_switch(FALSE);
179 + return eventNotHandledErr;
182 + static pascal OSStatus
183 + gui_mac_handle_text_input(
184 + EventHandlerCallRef nextHandler,
188 + UInt32 eventClass = GetEventClass(theEvent);
189 + UInt32 eventKind = GetEventKind(theEvent);
191 + if (eventClass != kEventClassTextInput)
192 + return eventNotHandledErr;
194 ! if ((kEventTextInputUpdateActiveInputArea != eventKind) &&
195 ! (kEventTextInputUnicodeForKeyEvent != eventKind) &&
196 ! (kEventTextInputOffsetToPos != eventKind) &&
197 ! (kEventTextInputPosToOffset != eventKind) &&
198 ! (kEventTextInputGetSelectedText != eventKind))
199 ! return eventNotHandledErr;
203 ! case kEventTextInputUpdateActiveInputArea:
204 ! return gui_mac_update_input_area(nextHandler, theEvent);
205 ! case kEventTextInputUnicodeForKeyEvent:
206 ! return gui_mac_unicode_key_event(nextHandler, theEvent);
208 ! case kEventTextInputOffsetToPos:
209 ! case kEventTextInputPosToOffset:
210 ! case kEventTextInputGetSelectedText:
214 ! return eventNotHandledErr;
218 ! OSStatus gui_mac_update_input_area(
219 ! EventHandlerCallRef nextHandler,
222 ! return eventNotHandledErr;
225 ! static int dialog_busy = FALSE; /* TRUE when gui_mch_dialog() wants the
228 # define INLINE_KEY_BUFFER_SIZE 80
229 static pascal OSStatus
230 ! gui_mac_unicode_key_event(
231 EventHandlerCallRef nextHandler,
234 /* Multibyte-friendly key event handler */
239 Boolean isSpecial = FALSE;
243 /* Mask the mouse (as per user setting) */
247 Boolean isSpecial = FALSE;
251 /* Mask the mouse (as per user setting) */
256 /* Don't use the keys when the dialog wants them. */
258 ! return eventNotHandledErr;
260 if (noErr != GetEventParameter(theEvent, kEventParamTextInputSendText,
261 ! typeUnicodeText, NULL, 0, &actualSize, NULL))
262 ! return eventNotHandledErr;
264 text = (UniChar *)alloc(actualSize);
266 ! return eventNotHandledErr;
268 err = GetEventParameter(theEvent, kEventParamTextInputSendText,
269 ! typeUnicodeText, NULL, actualSize, NULL, text);
270 require_noerr(err, done);
272 err = GetEventParameter(theEvent, kEventParamTextInputSendKeyboardEvent,
273 ! typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent);
274 require_noerr(err, done);
276 err = GetEventParameter(keyEvent, kEventParamKeyModifiers,
277 ! typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
278 require_noerr(err, done);
280 err = GetEventParameter(keyEvent, kEventParamKeyCode,
281 ! typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym);
282 require_noerr(err, done);
284 err = GetEventParameter(keyEvent, kEventParamKeyMacCharCodes,
285 ! typeChar, NULL, sizeof(char), NULL, &charcode);
286 require_noerr(err, done);
289 if (modifiers & cmdKey)
290 ! goto done; /* Let system handle Cmd+... */
296 /* Don't use the keys when the dialog wants them. */
298 ! return eventNotHandledErr;
300 if (noErr != GetEventParameter(theEvent, kEventParamTextInputSendText,
301 ! typeUnicodeText, NULL, 0, &actualSize, NULL))
302 ! return eventNotHandledErr;
304 text = (UniChar *)alloc(actualSize);
306 ! return eventNotHandledErr;
308 err = GetEventParameter(theEvent, kEventParamTextInputSendText,
309 ! typeUnicodeText, NULL, actualSize, NULL, text);
310 require_noerr(err, done);
312 err = GetEventParameter(theEvent, kEventParamTextInputSendKeyboardEvent,
313 ! typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent);
314 require_noerr(err, done);
316 err = GetEventParameter(keyEvent, kEventParamKeyModifiers,
317 ! typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
318 require_noerr(err, done);
320 err = GetEventParameter(keyEvent, kEventParamKeyCode,
321 ! typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym);
322 require_noerr(err, done);
324 err = GetEventParameter(keyEvent, kEventParamKeyMacCharCodes,
325 ! typeChar, NULL, sizeof(char), NULL, &charcode);
326 require_noerr(err, done);
329 if (modifiers & cmdKey)
330 ! goto done; /* Let system handle Cmd+... */
337 /* Find the special key (eg., for cursor keys) */
338 if (actualSize <= sizeof(UniChar) &&
339 ! ((text[0] < 0x20) || (text[0] == 0x7f)))
341 ! for (i = 0; special_keys[i].key_sym != (KeySym)0; ++i)
342 ! if (special_keys[i].key_sym == key_sym)
344 ! key_char = TO_SPECIAL(special_keys[i].vim_code0,
345 ! special_keys[i].vim_code1);
346 ! key_char = simplify_key(key_char,
347 ! (int *)&vimModifiers);
353 /* Intercept CMD-. and CTRL-c */
354 if (((modifiers & controlKey) && key_char == 'c') ||
355 ! ((modifiers & cmdKey) && key_char == '.'))
360 ! /* remove SHIFT for keys that are already shifted, e.g.,
362 ! if (key_char < 0x100 && !isalpha(key_char) && isprint(key_char))
363 ! vimModifiers &= ~MOD_MASK_SHIFT;
365 ! /* remove CTRL from keys that already have it */
366 ! if (key_char < 0x20)
367 ! vimModifiers &= ~MOD_MASK_CTRL;
369 ! /* don't process unicode characters here */
370 ! if (!IS_SPECIAL(key_char))
372 ! /* Following code to simplify and consolidate vimModifiers
373 ! * taken liberally from gui_w48.c */
374 ! key_char = simplify_key(key_char, (int *)&vimModifiers);
376 ! /* Interpret META, include SHIFT, etc. */
377 ! key_char = extract_modifiers(key_char, (int *)&vimModifiers);
378 ! if (key_char == CSI)
381 ! if (IS_SPECIAL(key_char))
388 ! result[len++] = CSI;
389 ! result[len++] = KS_MODIFIER;
390 ! result[len++] = vimModifiers;
393 if (isSpecial && IS_SPECIAL(key_char))
395 ! result[len++] = CSI;
396 ! result[len++] = K_SECOND(key_char);
397 ! result[len++] = K_THIRD(key_char);
401 ! encLen = actualSize;
402 ! to = mac_utf16_to_enc(text, actualSize, &encLen);
405 ! /* This is basically add_to_input_buf_csi() */
406 ! for (i = 0; i < encLen && len < (INLINE_KEY_BUFFER_SIZE-1); ++i)
408 ! result[len++] = to[i];
411 ! result[len++] = KS_EXTRA;
412 ! result[len++] = (int)KE_CSI;
419 add_to_input_buf(result, len);
422 /* Find the special key (eg., for cursor keys) */
423 if (actualSize <= sizeof(UniChar) &&
424 ! ((text[0] < 0x20) || (text[0] == 0x7f)))
426 ! for (i = 0; special_keys[i].key_sym != (KeySym)0; ++i)
427 ! if (special_keys[i].key_sym == key_sym)
429 ! key_char = TO_SPECIAL(special_keys[i].vim_code0,
430 ! special_keys[i].vim_code1);
431 ! key_char = simplify_key(key_char,
432 ! (int *)&vimModifiers);
438 /* Intercept CMD-. and CTRL-c */
439 if (((modifiers & controlKey) && key_char == 'c') ||
440 ! ((modifiers & cmdKey) && key_char == '.'))
445 ! /* remove SHIFT for keys that are already shifted, e.g.,
447 ! if (key_char < 0x100 && !isalpha(key_char) && isprint(key_char))
448 ! vimModifiers &= ~MOD_MASK_SHIFT;
450 ! /* remove CTRL from keys that already have it */
451 ! if (key_char < 0x20)
452 ! vimModifiers &= ~MOD_MASK_CTRL;
454 ! /* don't process unicode characters here */
455 ! if (!IS_SPECIAL(key_char))
457 ! /* Following code to simplify and consolidate vimModifiers
458 ! * taken liberally from gui_w48.c */
459 ! key_char = simplify_key(key_char, (int *)&vimModifiers);
461 ! /* Interpret META, include SHIFT, etc. */
462 ! key_char = extract_modifiers(key_char, (int *)&vimModifiers);
463 ! if (key_char == CSI)
466 ! if (IS_SPECIAL(key_char))
473 ! result[len++] = CSI;
474 ! result[len++] = KS_MODIFIER;
475 ! result[len++] = vimModifiers;
478 if (isSpecial && IS_SPECIAL(key_char))
480 ! result[len++] = CSI;
481 ! result[len++] = K_SECOND(key_char);
482 ! result[len++] = K_THIRD(key_char);
486 ! encLen = actualSize;
487 ! to = mac_utf16_to_enc(text, actualSize, &encLen);
490 ! /* This is basically add_to_input_buf_csi() */
491 ! for (i = 0; i < encLen && len < (INLINE_KEY_BUFFER_SIZE-1); ++i)
493 ! result[len++] = to[i];
496 ! result[len++] = KS_EXTRA;
497 ! result[len++] = (int)KE_CSI;
504 add_to_input_buf(result, len);
510 ! /* Fake event to wake up WNE (required to get
511 ! * key repeat working */
512 ! PostEvent(keyUp, 0);
516 return eventNotHandledErr;
521 ! /* Fake event to wake up WNE (required to get
522 ! * key repeat working */
523 ! PostEvent(keyUp, 0);
527 return eventNotHandledErr;
530 /* prevent that the vim window size changes if it's activated by a
531 click into the tab pane */
532 if (whichWindow == drawer)
538 /* prevent that the vim window size changes if it's activated by a
539 click into the tab pane */
540 if (whichWindow == drawer)
547 if (IsShowContextualMenuClick(event))
550 ! gui_mac_handle_contextual_menu(event);
552 ! gui_mac_doMouseDownEvent(event);
557 /* Handle normal event */
559 if (IsShowContextualMenuClick(event))
562 ! gui_mac_handle_contextual_menu(event);
564 ! gui_mac_doMouseDownEvent(event);
569 /* Handle normal event */
573 /* OSErr GetApplicationBundleFSSpec(FSSpecPtr theFSSpecPtr)
575 - * This technic remove the ../Contents/MacOS/etc part
577 (void)GetCurrentProcess(&psn);
578 /* if (err != noErr) return err; */
582 /* TODO: Move most of this stuff toward gui_mch_init */
585 - EventTypeSpec eventTypeSpec;
586 EventHandlerRef mouseWheelHandlerRef;
587 #ifdef USE_CARBONKEYHANDLER
588 ! EventHandlerRef keyEventHandlerRef;
590 ControlRef rootControl;
593 /* TODO: Move most of this stuff toward gui_mch_init */
596 EventHandlerRef mouseWheelHandlerRef;
597 #ifdef USE_CARBONKEYHANDLER
598 ! EventTypeSpec eventTypeSpec;
600 ControlRef rootControl;
606 #ifdef USE_CARBONKEYHANDLER
607 ! eventTypeSpec.eventClass = kEventClassTextInput;
608 ! eventTypeSpec.eventKind = kEventUnicodeForKeyEvent;
609 ! keyEventHandlerUPP = NewEventHandlerUPP(gui_mac_doKeyEventCarbon);
610 ! if (noErr != InstallApplicationEventHandler(keyEventHandlerUPP, 1,
611 ! &eventTypeSpec, NULL, &keyEventHandlerRef))
613 - keyEventHandlerRef = NULL;
614 DisposeEventHandlerUPP(keyEventHandlerUPP);
615 keyEventHandlerUPP = NULL;
623 #ifdef USE_CARBONKEYHANDLER
624 ! InterfaceTypeList supportedServices = { kUnicodeDocument };
625 ! NewTSMDocument(1, supportedServices, &gTSMDocument, 0);
627 ! /* We don't support inline input yet, use input window by default */
628 ! UseInputWindow(gTSMDocument, TRUE);
630 ! /* Should we activate the document by default? */
631 ! // ActivateTSMDocument(gTSMDocument);
633 ! EventTypeSpec textEventTypes[] = {
634 ! { kEventClassTextInput, kEventTextInputUpdateActiveInputArea },
635 ! { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent },
636 ! { kEventClassTextInput, kEventTextInputPosToOffset },
637 ! { kEventClassTextInput, kEventTextInputOffsetToPos },
640 ! keyEventHandlerUPP = NewEventHandlerUPP(gui_mac_handle_text_input);
641 ! if (noErr != InstallApplicationEventHandler(keyEventHandlerUPP,
642 ! NR_ELEMS(textEventTypes),
643 ! textEventTypes, NULL, NULL))
645 DisposeEventHandlerUPP(keyEventHandlerUPP);
646 keyEventHandlerUPP = NULL;
649 + EventTypeSpec windowEventTypes[] = {
650 + { kEventClassWindow, kEventWindowActivated },
651 + { kEventClassWindow, kEventWindowDeactivated },
654 + /* Install window event handler to support TSMDocument activate and
656 + winEventHandlerUPP = NewEventHandlerUPP(gui_mac_handle_window_activate);
657 + if (noErr != InstallWindowEventHandler(gui.VimWindow,
658 + winEventHandlerUPP,
659 + NR_ELEMS(windowEventTypes),
660 + windowEventTypes, NULL, NULL))
662 + DisposeEventHandlerUPP(winEventHandlerUPP);
663 + winEventHandlerUPP = NULL;
674 + #ifdef USE_ATSUI_DRAWING
676 + gui_mac_dispose_atsui_style(void)
678 + if (p_macatsui && gFontStyle)
679 + ATSUDisposeStyle(gFontStyle);
681 + if (p_macatsui && gWideFontStyle)
682 + ATSUDisposeStyle(gWideFontStyle);
692 DisposeEventHandlerUPP(mouseWheelHandlerUPP);
694 #ifdef USE_ATSUI_DRAWING
695 ! if (p_macatsui && gFontStyle)
696 ! ATSUDisposeStyle(gFontStyle);
701 DisposeEventHandlerUPP(mouseWheelHandlerUPP);
703 #ifdef USE_ATSUI_DRAWING
704 ! gui_mac_dispose_atsui_style();
707 ! #ifdef USE_CARBONKEYHANDLER
708 ! FixTSMDocument(gTSMDocument);
709 ! DeactivateTSMDocument(gTSMDocument);
710 ! DeleteTSMDocument(gTSMDocument);
717 return selected_font;
720 + #ifdef USE_ATSUI_DRAWING
722 + gui_mac_create_atsui_style(void)
724 + if (p_macatsui && gFontStyle == NULL)
726 + if (ATSUCreateStyle(&gFontStyle) != noErr)
730 + if (p_macatsui && gWideFontStyle == NULL)
732 + if (ATSUCreateStyle(&gWideFontStyle) != noErr)
733 + gWideFontStyle = NULL;
737 + p_macatsui_last = p_macatsui;
742 * Initialise vim to use the font with the given name. Return FAIL if the font
745 char_u used_font_name[512];
747 #ifdef USE_ATSUI_DRAWING
748 ! if (p_macatsui && gFontStyle == NULL)
750 ! if (ATSUCreateStyle(&gFontStyle) != noErr)
755 if (font_name == NULL)
757 char_u used_font_name[512];
759 #ifdef USE_ATSUI_DRAWING
760 ! gui_mac_create_atsui_style();
763 if (font_name == NULL)
766 gui.char_height = font_info.ascent + font_info.descent + p_linespace;
768 #ifdef USE_ATSUI_DRAWING
771 - ATSStyleRenderingOptions fontOptions;
773 if (p_macatsui && gFontStyle)
775 ! fontID = font & 0xFFFF;
776 ! fontSize = Long2Fix(font >> 16);
778 ! /* No antialiasing by default (do not attempt to touch antialising
779 ! * options on pre-Jaguar) */
781 ! (gMacSystemVersion >= 0x1020) ?
782 ! kATSStyleNoAntiAliasing :
783 ! kATSStyleNoOptions;
785 ! ATSUAttributeTag attribTags[] =
787 ! kATSUFontTag, kATSUSizeTag, kATSUStyleRenderingOptionsTag,
788 ! kATSUMaxATSUITagValue+1
790 ! ByteCount attribSizes[] =
792 ! sizeof(ATSUFontID), sizeof(Fixed),
793 ! sizeof(ATSStyleRenderingOptions), sizeof font
795 ! ATSUAttributeValuePtr attribValues[] =
797 ! &fontID, &fontSize, &fontOptions, &font
800 ! /* Convert font id to ATSUFontID */
801 ! if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr)
803 ! if (ATSUSetAttributes(gFontStyle,
804 ! (sizeof attribTags)/sizeof(ATSUAttributeTag),
805 ! attribTags, attribSizes, attribValues) != noErr)
807 ! ATSUDisposeStyle(gFontStyle);
816 gui.char_height = font_info.ascent + font_info.descent + p_linespace;
818 #ifdef USE_ATSUI_DRAWING
819 if (p_macatsui && gFontStyle)
820 ! gui_mac_set_font_attributes(font);
830 + #ifdef USE_ATSUI_DRAWING
832 + gui_mac_set_font_attributes(GuiFont font)
838 + fontID = font & 0xFFFF;
839 + fontSize = Long2Fix(font >> 16);
840 + fontWidth = Long2Fix(gui.char_width);
842 + ATSUAttributeTag attribTags[] =
844 + kATSUFontTag, kATSUSizeTag, kATSUImposeWidthTag,
845 + kATSUMaxATSUITagValue + 1
848 + ByteCount attribSizes[] =
850 + sizeof(ATSUFontID), sizeof(Fixed), sizeof(fontWidth),
854 + ATSUAttributeValuePtr attribValues[] =
856 + &fontID, &fontSize, &fontWidth, &font
859 + if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr)
861 + if (ATSUSetAttributes(gFontStyle,
862 + (sizeof attribTags) / sizeof(ATSUAttributeTag),
863 + attribTags, attribSizes, attribValues) != noErr)
866 + fprintf(stderr, "couldn't set font style\n");
868 + ATSUDisposeStyle(gFontStyle);
875 + /* FIXME: we should use a more mbyte sensitive way to support
876 + * wide font drawing */
877 + fontWidth = Long2Fix(gui.char_width * 2);
879 + if (ATSUSetAttributes(gWideFontStyle,
880 + (sizeof attribTags) / sizeof(ATSUAttributeTag),
881 + attribTags, attribSizes, attribValues) != noErr)
883 + ATSUDisposeStyle(gWideFontStyle);
884 + gWideFontStyle = NULL;
893 * Set the current text font.
897 #ifdef USE_ATSUI_DRAWING
899 ByteCount actualFontByteCount;
902 - ATSStyleRenderingOptions fontOptions;
904 if (p_macatsui && gFontStyle)
906 /* Avoid setting same font again */
907 ! if (ATSUGetAttribute(gFontStyle, kATSUMaxATSUITagValue+1, sizeof font,
908 ! &currFont, &actualFontByteCount) == noErr &&
909 ! actualFontByteCount == (sizeof font))
911 if (currFont == font)
915 ! fontID = font & 0xFFFF;
916 ! fontSize = Long2Fix(font >> 16);
917 ! /* Respect p_antialias setting only for wide font.
918 ! * The reason for doing this at the moment is a bit complicated,
919 ! * but it's mainly because a) latin (non-wide) aliased fonts
920 ! * look bad in OS X 10.3.x and below (due to a bug in ATS), and
921 ! * b) wide multibyte input does not suffer from that problem. */
923 ! (p_antialias && (font == gui.wide_font)) ?
924 ! kATSStyleNoOptions : kATSStyleNoAntiAliasing;
926 ! /*fontOptions = kATSStyleAntiAliasing;*/
928 ! ATSUAttributeTag attribTags[] =
930 ! kATSUFontTag, kATSUSizeTag, kATSUStyleRenderingOptionsTag,
931 ! kATSUMaxATSUITagValue+1
933 ! ByteCount attribSizes[] =
935 ! sizeof(ATSUFontID), sizeof(Fixed),
936 ! sizeof(ATSStyleRenderingOptions), sizeof font
938 ! ATSUAttributeValuePtr attribValues[] =
940 ! &fontID, &fontSize, &fontOptions, &font
943 ! if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr)
945 ! if (ATSUSetAttributes(gFontStyle,
946 ! (sizeof attribTags)/sizeof(ATSUAttributeTag),
947 ! attribTags, attribSizes, attribValues) != noErr)
950 ! fprintf(stderr, "couldn't set font style\n");
952 ! ATSUDisposeStyle(gFontStyle);
959 if (p_macatsui && !gIsFontFallbackSet)
961 #ifdef USE_ATSUI_DRAWING
963 ByteCount actualFontByteCount;
965 if (p_macatsui && gFontStyle)
967 /* Avoid setting same font again */
968 ! if (ATSUGetAttribute(gFontStyle, kATSUMaxATSUITagValue + 1,
969 ! sizeof(font), &currFont, &actualFontByteCount) == noErr
970 ! && actualFontByteCount == (sizeof font))
972 if (currFont == font)
976 ! gui_mac_set_font_attributes(font);
979 if (p_macatsui && !gIsFontFallbackSet)
985 ! ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID), &fallbackFonts, kATSUSequentialFallbacksPreferred);
988 ATSUAttributeValuePtr fallbackValues[] = { };
993 ! ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID),
995 ! kATSUSequentialFallbacksPreferred);
998 ATSUAttributeValuePtr fallbackValues[] = { };
1002 /* - ATSUI automatically antialiases text (Someone)
1003 * - for some reason it does not work... (Jussi) */
1006 * When antialiasing we're using srcOr mode, we have to clear the block
1007 * before drawing the text.
1010 /* - ATSUI automatically antialiases text (Someone)
1011 * - for some reason it does not work... (Jussi) */
1012 ! #ifdef MAC_ATSUI_DEBUG
1013 ! fprintf(stderr, "row = %d, col = %d, len = %d: '%c'\n",
1014 ! row, col, len, len == 1 ? s[0] : ' ');
1017 * When antialiasing we're using srcOr mode, we have to clear the block
1018 * before drawing the text.
1024 - /* Use old-style, non-antialiased QuickDraw text rendering. */
1028 ! /* SelectFont(hdc, gui.currFont); */
1030 if (flags & DRAW_TRANSP)
1035 MoveTo(TEXT_X(col), TEXT_Y(row));
1036 - ATSUTextLayout textLayout;
1038 ! if (ATSUCreateTextLayoutWithTextPtr(tofree,
1039 ! kATSUFromTextBeginning, kATSUToTextEnd,
1041 ! (gFontStyle ? 1 : 0), &utf16_len,
1042 ! (gFontStyle ? &gFontStyle : NULL),
1043 ! &textLayout) == noErr)
1045 ! ATSUSetTransientFontMatching(textLayout, TRUE);
1047 ! ATSUDrawText(textLayout,
1048 ! kATSUFromTextBeginning, kATSUToTextEnd,
1049 ! kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
1051 ATSUDisposeTextLayout(textLayout);
1055 if (flags & DRAW_UNDERC)
1063 ! /* SelectFont(hdc, gui.currFont); */
1064 if (flags & DRAW_TRANSP)
1069 MoveTo(TEXT_X(col), TEXT_Y(row));
1071 ! if (gFontStyle && flags & DRAW_BOLD)
1073 ! Boolean attValue = true;
1074 ! ATSUAttributeTag attribTags[] = { kATSUQDBoldfaceTag };
1075 ! ByteCount attribSizes[] = { sizeof(Boolean) };
1076 ! ATSUAttributeValuePtr attribValues[] = { &attValue };
1078 ! ATSUSetAttributes(gFontStyle, 1, attribTags, attribSizes, attribValues);
1084 ! int n, width_in_cell, last_width_in_cell;
1085 ! UniCharArrayOffset offset = 0;
1086 ! UniCharCount yet_to_draw = 0;
1087 ! ATSUTextLayout textLayout;
1088 ! ATSUStyle textStyle;
1090 ! last_width_in_cell = 1;
1091 ! ATSUCreateTextLayout(&textLayout);
1092 ! ATSUSetTextPointerLocation(textLayout, tofree,
1093 ! kATSUFromTextBeginning,
1094 ! kATSUToTextEnd, utf16_len);
1096 ! ATSUSetRunStyle(textLayout, gFontStyle,
1097 ! kATSUFromTextBeginning, kATSUToTextEnd); */
1099 ! /* Compute the length in display cells. */
1100 ! for (n = 0; n < len; n += MB_BYTE2LEN(s[n]))
1102 ! width_in_cell = (*mb_ptr2cells)(s + n);
1104 ! /* probably we are switching from single byte character
1105 ! * to multibyte characters (which requires more than one
1106 ! * cell to draw) */
1107 ! if (width_in_cell != last_width_in_cell)
1109 ! #ifdef MAC_ATSUI_DEBUG
1110 ! fprintf(stderr, "\tn = %2d, (%d-%d), offset = %d, yet_to_draw = %d\n",
1111 ! n, last_width_in_cell, width_in_cell, offset, yet_to_draw);
1113 ! textStyle = last_width_in_cell > 1 ? gWideFontStyle
1116 ! ATSUSetRunStyle(textLayout, textStyle, offset, yet_to_draw);
1117 ! offset += yet_to_draw;
1119 ! last_width_in_cell = width_in_cell;
1127 + #ifdef MAC_ATSUI_DEBUG
1128 + fprintf(stderr, "\tn = %2d, (%d-%d), offset = %d, yet_to_draw = %d\n",
1129 + n, last_width_in_cell, width_in_cell, offset, yet_to_draw);
1131 + /* finish the rest style */
1132 + textStyle = width_in_cell > 1 ? gWideFontStyle : gFontStyle;
1133 + ATSUSetRunStyle(textLayout, textStyle, offset, kATSUToTextEnd);
1136 + ATSUSetTransientFontMatching(textLayout, TRUE);
1137 + ATSUDrawText(textLayout,
1138 + kATSUFromTextBeginning, kATSUToTextEnd,
1139 + kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
1140 ATSUDisposeTextLayout(textLayout);
1145 + ATSUTextLayout textLayout;
1147 + if (ATSUCreateTextLayoutWithTextPtr(tofree,
1148 + kATSUFromTextBeginning, kATSUToTextEnd,
1150 + (gFontStyle ? 1 : 0), &utf16_len,
1151 + (gFontStyle ? &gFontStyle : NULL),
1152 + &textLayout) == noErr)
1154 + ATSUSetTransientFontMatching(textLayout, TRUE);
1156 + ATSUDrawText(textLayout,
1157 + kATSUFromTextBeginning, kATSUToTextEnd,
1158 + kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
1160 + ATSUDisposeTextLayout(textLayout);
1164 + /* drawing is done, now reset bold to normal */
1165 + if (gFontStyle && flags & DRAW_BOLD)
1167 + Boolean attValue = false;
1169 + ATSUAttributeTag attribTags[] = { kATSUQDBoldfaceTag };
1170 + ByteCount attribSizes[] = { sizeof(Boolean) };
1171 + ATSUAttributeValuePtr attribValues[] = { &attValue };
1173 + ATSUSetAttributes(gFontStyle, 1, attribTags, attribSizes,
1178 if (flags & DRAW_UNDERC)
1182 gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
1184 #if defined(USE_ATSUI_DRAWING)
1185 + if (p_macatsui == 0 && p_macatsui_last != 0)
1186 + /* switch from macatsui to nomacatsui */
1187 + gui_mac_dispose_atsui_style();
1188 + else if (p_macatsui != 0 && p_macatsui_last == 0)
1189 + /* switch from nomacatsui to macatsui */
1190 + gui_mac_create_atsui_style();
1193 draw_string_ATSUI(row, col, s, len, flags);
1198 /* TODO: reduce wtime accordinly??? */
1200 ! sleeppyTick = 60*wtime/1000;
1202 sleeppyTick = 32767;
1203 if (WaitNextEventWrp(mask, &event, sleeppyTick, dragRgn))
1205 ! gui_mac_handle_event(&event);
1206 if (input_available())
1208 allow_scrollbar = FALSE;
1211 /* TODO: reduce wtime accordinly??? */
1213 ! sleeppyTick = 60 * wtime / 1000;
1215 sleeppyTick = 32767;
1217 if (WaitNextEventWrp(mask, &event, sleeppyTick, dragRgn))
1219 ! gui_mac_handle_event(&event);
1220 if (input_available())
1222 allow_scrollbar = FALSE;
1228 ! #if defined(USE_IM_CONTROL) || defined(PROTO)
1230 * Input Method Control functions.
1236 ! #if (defined(USE_IM_CONTROL) || defined(PROTO)) && defined(USE_CARBONKEYHANDLER)
1238 * Input Method Control functions.
1244 im_set_position(int row, int col)
1247 /* TODO: Implement me! */
1248 + im_start_row = row;
1249 + im_start_col = col;
1253 + static ScriptLanguageRecord gTSLWindow;
1254 + static ScriptLanguageRecord gTSLInsert;
1255 + static ScriptLanguageRecord gTSLDefault = { 0, 0 };
1257 + static Component gTSCWindow;
1258 + static Component gTSCInsert;
1259 + static Component gTSCDefault;
1261 + static int im_initialized = 0;
1264 + im_on_window_switch(int active)
1266 + ScriptLanguageRecord *slptr = NULL;
1272 + if (im_initialized == 0)
1274 + im_initialized = 1;
1276 + /* save default TSM component (should be U.S.) to default */
1277 + GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault,
1278 + kKeyboardInputMethodClass);
1281 + if (active == TRUE)
1283 + im_is_active = TRUE;
1284 + ActivateTSMDocument(gTSMDocument);
1285 + slptr = &gTSLWindow;
1289 + err = SetDefaultInputMethodOfClass(gTSCWindow, slptr,
1290 + kKeyboardInputMethodClass);
1292 + err = SetTextServiceLanguage(slptr);
1295 + KeyScript(slptr->fScript | smKeyForceKeyScriptMask);
1300 + err = GetTextServiceLanguage(&gTSLWindow);
1302 + slptr = &gTSLWindow;
1305 + GetDefaultInputMethodOfClass(&gTSCWindow, slptr,
1306 + kKeyboardInputMethodClass);
1308 + im_is_active = FALSE;
1309 + DeactivateTSMDocument(gTSMDocument);
1317 im_set_active(int active)
1319 ! KeyScript(active ? smKeySysScript : smKeyRoman);
1325 im_set_active(int active)
1327 ! ScriptLanguageRecord *slptr = NULL;
1333 ! if (im_initialized == 0)
1335 ! im_initialized = 1;
1337 ! /* save default TSM component (should be U.S.) to default */
1338 ! GetDefaultInputMethodOfClass(&gTSCDefault, &gTSLDefault,
1339 ! kKeyboardInputMethodClass);
1342 ! if (active == TRUE)
1344 ! im_is_active = TRUE;
1345 ! ActivateTSMDocument(gTSMDocument);
1346 ! slptr = &gTSLInsert;
1350 ! err = SetDefaultInputMethodOfClass(gTSCInsert, slptr,
1351 ! kKeyboardInputMethodClass);
1353 ! err = SetTextServiceLanguage(slptr);
1356 ! KeyScript(slptr->fScript | smKeyForceKeyScriptMask);
1361 ! err = GetTextServiceLanguage(&gTSLInsert);
1363 ! slptr = &gTSLInsert;
1366 ! GetDefaultInputMethodOfClass(&gTSCInsert, slptr,
1367 ! kKeyboardInputMethodClass);
1369 ! /* restore to default when switch to normal mode, so than we could
1370 ! * enter commands easier */
1371 ! SetDefaultInputMethodOfClass(gTSCDefault, &gTSLDefault,
1372 ! kKeyboardInputMethodClass);
1373 ! SetTextServiceLanguage(&gTSLDefault);
1375 ! im_is_active = FALSE;
1376 ! DeactivateTSMDocument(gTSMDocument);
1386 ! SInt32 script = GetScriptManagerVariable(smKeyScript);
1387 ! return (script != smRoman
1388 ! && script == GetScriptManagerVariable(smSysScript)) ? 1 : 0;
1391 #endif /* defined(USE_IM_CONTROL) || defined(PROTO) */
1399 ! return im_is_active;
1402 #endif /* defined(USE_IM_CONTROL) || defined(PROTO) */
1407 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
1415 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
1423 dbItemDataCallback(ControlRef browser,
1424 DataBrowserItemID itemID,
1425 ! DataBrowserPropertyID property /* column id */,
1426 ! DataBrowserItemDataRef itemData,
1427 Boolean changeValue)
1429 OSStatus status = noErr;
1432 dbItemDataCallback(ControlRef browser,
1433 DataBrowserItemID itemID,
1434 ! DataBrowserPropertyID property /* column id */,
1435 ! DataBrowserItemDataRef itemData,
1436 Boolean changeValue)
1438 OSStatus status = noErr;
1442 dbGetContextualMenuCallback(ControlRef browser,
1445 CFStringRef *helpItemString,
1446 ! AEDesc *selection)
1448 // on mac os 9: kCMHelpItemNoHelp, but it's not the same
1449 *helpType = kCMHelpItemRemoveHelp; // OS X only ;-)
1452 dbGetContextualMenuCallback(ControlRef browser,
1455 CFStringRef *helpItemString,
1456 ! AEDesc *selection)
1458 // on mac os 9: kCMHelpItemNoHelp, but it's not the same
1459 *helpType = kCMHelpItemRemoveHelp; // OS X only ;-)
1462 gui_mch_show_tabline(int showit)
1465 ! CloseDrawer(drawer, true);
1467 ! OpenDrawer(drawer, kWindowEdgeRight, true);
1472 gui_mch_show_tabline(int showit)
1475 ! CloseDrawer(drawer, true);
1477 ! OpenDrawer(drawer, kWindowEdgeRight, true);
1483 // adjust data browser
1484 if (tabLabels != NULL)
1488 ! for (i = 0; i < tabLabelsSize; ++i)
1489 ! CFRelease(tabLabels[i]);
1492 tabLabels = (CFStringRef *)malloc(numTabs * sizeof(CFStringRef));
1493 tabLabelsSize = numTabs;
1495 // adjust data browser
1496 if (tabLabels != NULL)
1500 ! for (i = 0; i < tabLabelsSize; ++i)
1501 ! CFRelease(tabLabels[i]);
1504 tabLabels = (CFStringRef *)malloc(numTabs * sizeof(CFStringRef));
1505 tabLabelsSize = numTabs;
1511 ! tabLabels[nr-1] = getTabLabel(tp);
1514 RemoveDataBrowserItems(dataBrowser, kDataBrowserNoItem, 0, NULL,
1519 ! tabLabels[nr-1] = getTabLabel(tp);
1522 RemoveDataBrowserItems(dataBrowser, kDataBrowserNoItem, 0, NULL,
1523 *** ../vim-7.1.274/src/version.c Wed Mar 12 13:45:34 2008
1524 --- src/version.c Wed Mar 12 14:31:37 2008
1528 { /* Add new patch number below this line */
1534 hundred-and-one symptoms of being an internet addict:
1535 115. You are late picking up your kid from school and try to explain
1536 to the teacher you were stuck in Web traffic.
1538 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
1539 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
1540 \\\ download, build and distribute -- http://www.A-A-P.org ///
1541 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///