1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
3 * VIM - Vi IMproved by Bram Moolenaar
4 * MacVim GUI port by Bjorn Winckler
6 * Do ":help uganda" in Vim to read copying and usage conditions.
7 * Do ":help credits" in Vim to see a list of people who contributed.
8 * See README.txt for an overview of the Vim source code.
11 #import <Foundation/Foundation.h>
17 static BOOL gui_cocoa_is_valid_action(NSString *action);
20 // -- Initialization --------------------------------------------------------
23 * Parse the GUI related command-line arguments. Any arguments used are
24 * deleted from argv, and *argc is decremented accordingly. This is called
25 * when vim is started, whether or not the GUI has been started.
28 gui_mch_prepare(int *argc, char **argv)
30 //NSLog(@"gui_mch_prepare(argc=%d)", *argc);
32 // Set environment variables $VIM and $VIMRUNTIME
33 // NOTE! If vim_getenv is called with one of these as parameters before
34 // they have been set here, they will most likely end up with the wrong
38 // - ensure this is called first to avoid above problem
41 NSString *path = [[[NSBundle mainBundle] resourcePath]
42 stringByAppendingPathComponent:@"vim"];
43 vim_setenv((char_u*)"VIM", (char_u*)[path UTF8String]);
45 path = [path stringByAppendingPathComponent:@"runtime"];
46 vim_setenv((char_u*)"VIMRUNTIME", (char_u*)[path UTF8String]);
51 * Check if the GUI can be started. Called before gvimrc is sourced.
55 gui_mch_init_check(void)
57 //NSLog(@"gui_mch_init_check()");
63 * Initialise the GUI. Create all the windows, set up all the call-backs etc.
64 * Returns OK for success, FAIL when the GUI can't be started.
69 //NSLog(@"gui_mch_init()");
71 if (![[MMBackend sharedInstance] checkin])
74 // HACK! Force the 'termencoding to utf-8. For the moment also force
75 // 'encoding', although this will change in the future. The user can still
76 // change 'encoding'; doing so WILL crash the program.
77 set_option_value((char_u *)"termencoding", 0L, (char_u *)"utf-8", 0);
78 set_option_value((char_u *)"encoding", 0L, (char_u *)"utf-8", 0);
80 // Set values so that pixels and characters are in one-to-one
81 // correspondence (assuming all characters have the same dimensions).
82 gui.scrollbar_width = gui.scrollbar_height = 0;
90 [[MMBackend sharedInstance]
91 setDefaultColorsBackground:gui.back_pixel foreground:gui.norm_pixel];
92 [[MMBackend sharedInstance] setBackgroundColor:gui.back_pixel];
93 [[MMBackend sharedInstance] setForegroundColor:gui.norm_pixel];
95 // NOTE: If this call is left out the cursor is opaque.
96 highlight_gui_started();
106 //NSLog(@"gui_mch_exit(rc=%d)", rc);
108 [[MMBackend sharedInstance] exit];
113 * Open the GUI window which was created by a call to gui_mch_init().
118 //NSLog(@"gui_mch_open()");
120 return [[MMBackend sharedInstance] openVimWindow];
124 // -- Updating --------------------------------------------------------------
128 * Catch up with any queued X events. This may put keyboard input into the
129 * input buffer, call resize call-backs, trigger timers etc. If there is
130 * nothing in the X event queue (& no timers pending), then we return
136 [[MMBackend sharedInstance] flushQueue:NO];
140 /* Flush any output to the screen */
144 [[MMBackend sharedInstance] flushQueue:NO];
149 * GUI input routine called by gui_wait_for_chars(). Waits for a character
151 * wtime == -1 Wait forever.
152 * wtime == 0 This should never happen.
153 * wtime > 0 Wait wtime milliseconds for a character.
154 * Returns OK if a character was found to be available within the given time,
158 gui_mch_wait_for_chars(int wtime)
160 // NOTE! In all likelihood Vim will take a nap when waitForInput: is
161 // called, so force a flush of the command queue here.
162 [[MMBackend sharedInstance] flushQueue:YES];
164 return [[MMBackend sharedInstance] waitForInput:wtime];
168 // -- Drawing ---------------------------------------------------------------
172 * Clear the whole text window.
175 gui_mch_clear_all(void)
177 [[MMBackend sharedInstance] clearAll];
182 * Clear a rectangular region of the screen from text pos (row1, col1) to
183 * (row2, col2) inclusive.
186 gui_mch_clear_block(int row1, int col1, int row2, int col2)
188 [[MMBackend sharedInstance] clearBlockFromRow:row1 column:col1
189 toRow:row2 column:col2];
194 * Delete the given number of lines from the given row, scrolling up any
195 * text further down within the scroll region.
198 gui_mch_delete_lines(int row, int num_lines)
200 [[MMBackend sharedInstance] deleteLinesFromRow:row count:num_lines
201 scrollBottom:gui.scroll_region_bot
202 left:gui.scroll_region_left
203 right:gui.scroll_region_right];
208 gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
210 [[MMBackend sharedInstance] replaceString:(char*)s length:len
211 row:row column:col flags:flags];
216 gui_macvim_draw_string(int row, int col, char_u *s, int len, int flags)
219 NSString *string = [[NSString alloc]
220 initWithBytesNoCopy:(void*)s
222 encoding:NSUTF8StringEncoding
224 int cells = [string length];
227 NSLog(@"gui_macvim_draw_string(row=%d, col=%d, len=%d, cells=%d, flags=%d)",
228 row, col, len, cells, flags);
230 [[MMBackend sharedInstance] replaceString:(char*)s length:len
231 row:row column:col flags:flags];
243 MMBackend *backend = [MMBackend sharedInstance];
245 for (i = 0; i < len; i += cl) {
246 c = utf_ptr2char(s + i);
247 cl = utf_ptr2len(s + i);
248 cn = utf_char2cells(c);
249 comping = utf_iscomposing(c);
254 if (cn > 1 && !wide) {
255 // Start of wide characters.
258 // Output non-wide characters.
260 NSLog(@"Outputting %d non-wide chars (%d bytes)",
261 endcol-startcol, start-i);
262 [backend replaceString:(char*)(s+start) length:start-i
263 row:row column:startcol flags:flags];
267 } else if (cn <= 1 && !comping && wide) {
268 // End of wide characters.
271 // Output wide characters.
273 NSLog(@"Outputting %d wide chars (%d bytes)",
274 endcol-startcol, start-i);
275 [backend replaceString:(char*)(s+start) length:start-i
276 row:row column:startcol flags:(flags|0x80)];
283 // Output remaining characters.
284 flags = wide ? flags|0x80 : flags;
285 NSLog(@"Outputting %d %s chars (%d bytes)", endcol-startcol, wide ? "wide"
286 : "non-wide", len-start);
287 [backend replaceString:(char*)(s+start) length:len-start
288 row:row column:startcol flags:flags];
293 // Output chars until a wide char found. If a wide char is found, output a
294 // zero-width space after it so that a wide char looks like two chars to
295 // MMTextStorage. This way 1 char corresponds to 1 column.
306 MMBackend *backend = [MMBackend sharedInstance];
307 static char ZeroWidthSpace[] = { 0xe2, 0x80, 0x8b };
309 char_u *conv_str = NULL;
311 if (output_conv.vc_type != CONV_NONE) {
312 char_u *conv_str = string_convert(&output_conv, s, &len);
318 for (i = 0; i < len; i += cl) {
319 c = utf_ptr2char(s + i);
320 cl = utf_ptr2len(s + i);
321 cn = utf_char2cells(c);
323 if (!utf_iscomposing(c)) {
327 NSString *string = [[NSString alloc]
328 initWithBytesNoCopy:(void*)(s+start)
330 encoding:NSUTF8StringEncoding
332 NSLog(@"Flushing string=%@ len=%d row=%d col=%d end=%d",
333 string, i-start, row, startcol, endcol);
336 [backend replaceString:(char*)(s+start) length:i-start
337 row:row column:startcol flags:flags];
341 NSLog(@"Padding len=%d row=%d col=%d", sizeof(ZeroWidthSpace),
344 [backend replaceString:ZeroWidthSpace
345 length:sizeof(ZeroWidthSpace)
346 row:row column:endcol-1 flags:flags];
354 NSLog(@"Wide char detected! (char=%C hex=%x cells=%d)", c, c, cn);
362 NSString *string = [[NSString alloc]
363 initWithBytesNoCopy:(void*)(s+start)
365 encoding:NSUTF8StringEncoding
367 NSLog(@"Output string=%@ len=%d row=%d col=%d", string, len-start, row,
373 // Output remaining characters.
374 [backend replaceString:(char*)(s+start) length:len-start
375 row:row column:startcol flags:flags];
379 NSLog(@"Padding len=%d row=%d col=%d", sizeof(ZeroWidthSpace), row,
382 [backend replaceString:ZeroWidthSpace
383 length:sizeof(ZeroWidthSpace)
384 row:row column:endcol-1 flags:flags];
394 // This will fail abysmally when wide or composing characters are used.
395 [[MMBackend sharedInstance]
396 replaceString:(char*)s length:len row:row column:col flags:flags];
398 int i, c, cl, cn, cells = 0;
399 for (i = 0; i < len; i += cl) {
400 c = utf_ptr2char(s + i);
401 cl = utf_ptr2len(s + i);
402 cn = utf_char2cells(c);
404 if (!utf_iscomposing(c))
414 * Insert the given number of lines before the given row, scrolling down any
415 * following text within the scroll region.
418 gui_mch_insert_lines(int row, int num_lines)
420 [[MMBackend sharedInstance] insertLinesFromRow:row count:num_lines
421 scrollBottom:gui.scroll_region_bot
422 left:gui.scroll_region_left
423 right:gui.scroll_region_right];
427 // -- Tab line --------------------------------------------------------------
431 * Set the current tab to "nr". First tab is 1.
434 gui_mch_set_curtab(int nr)
436 //NSLog(@"gui_mch_set_curtab(nr=%d)", nr);
437 [[MMBackend sharedInstance] selectTab:nr];
442 * Return TRUE when tabline is displayed.
445 gui_mch_showing_tabline(void)
447 //NSLog(@"gui_mch_showing_tabline()");
448 return [[MMBackend sharedInstance] tabBarVisible];
452 * Update the labels of the tabline.
455 gui_mch_update_tabline(void)
457 //NSLog(@"gui_mch_update_tabline()");
458 [[MMBackend sharedInstance] updateTabBar];
462 * Show or hide the tabline.
465 gui_mch_show_tabline(int showit)
467 //NSLog(@"gui_mch_show_tabline(showit=%d)", showit);
468 [[MMBackend sharedInstance] showTabBar:showit];
472 // -- Clipboard -------------------------------------------------------------
476 clip_mch_lose_selection(VimClipboard *cbd)
482 clip_mch_own_selection(VimClipboard *cbd)
489 clip_mch_request_selection(VimClipboard *cbd)
491 NSPasteboard *pb = [NSPasteboard generalPasteboard];
492 NSString *pbType = [pb availableTypeFromArray:
493 [NSArray arrayWithObject:NSStringPboardType]];
495 NSMutableString *string =
496 [[pb stringForType:NSStringPboardType] mutableCopy];
498 // Replace unrecognized end-of-line sequences with \x0a (line feed).
499 NSRange range = { 0, [string length] };
500 unsigned n = [string replaceOccurrencesOfString:@"\x0d\x0a"
501 withString:@"\x0a" options:0
504 n = [string replaceOccurrencesOfString:@"\x0d" withString:@"\x0a"
505 options:0 range:range];
508 // Scan for newline character to decide whether the string should be
509 // pasted linewise or characterwise.
511 if (0 < n || NSNotFound != [string rangeOfString:@"\n"].location)
514 char_u *str = (char_u*)[string UTF8String];
515 int len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
518 if (input_conv.vc_type != CONV_NONE) {
519 NSLog(@"Converting from: '%@'", string);
520 char_u *conv_str = string_convert(&input_conv, str, &len);
522 NSLog(@" to: '%s'", conv_str);
523 clip_yank_selection(type, conv_str, len, cbd);
530 clip_yank_selection(type, str, len, cbd);
536 * Send the current selection to the clipboard.
539 clip_mch_set_selection(VimClipboard *cbd)
541 // If the '*' register isn't already filled in, fill it in now.
543 clip_get_selection(cbd);
546 // Get the text to put on the pasteboard.
547 long_u llen = 0; char_u *str = 0;
548 int type = clip_convert_selection(&str, &llen, cbd);
552 // TODO: Avoid overflow.
555 if (output_conv.vc_type != CONV_NONE) {
556 char_u *conv_str = string_convert(&output_conv, str, &len);
565 NSString *string = [[NSString alloc]
566 initWithBytes:str length:len encoding:NSUTF8StringEncoding];
568 NSPasteboard *pb = [NSPasteboard generalPasteboard];
569 [pb declareTypes:[NSArray arrayWithObject:NSStringPboardType]
571 [pb setString:string forType:NSStringPboardType];
580 // -- Menu ------------------------------------------------------------------
584 * Add a sub menu to the menu bar.
587 gui_mch_add_menu(vimmenu_T *menu, int idx)
589 //NSLog(@"gui_mch_add_menu(name=%s, idx=%d)", menu->name, idx);
591 // HACK! If menu has no parent, then we set the parent tag to the type of
592 // menu it is. This will not mix up tag and type because pointers can not
593 // take values close to zero (and the tag is simply the value of the
595 int parent = (int)menu->parent;
597 parent = menu_is_popup(menu->name) ? MenuPopupType :
598 menu_is_toolbar(menu->name) ? MenuToolbarType :
602 [[MMBackend sharedInstance]
603 addMenuWithTag:(int)menu parent:parent name:(char*)menu->dname
609 * Add a menu item to a menu
612 gui_mch_add_menu_item(vimmenu_T *menu, int idx)
614 //NSLog(@"gui_mch_add_menu_item(name=%s, accel=%s idx=%d)", menu->dname,
615 // menu->actext, idx);
617 // NOTE! If 'iconfile' is not set but 'iconidx' is, use the name of the
618 // menu item. (Should correspond to a stock item.)
619 char *icon = menu->iconfile ? (char*)menu->iconfile :
620 menu->iconidx >= 0 ? (char*)menu->dname :
622 //char *name = menu_is_separator(menu->name) ? NULL : (char*)menu->dname;
623 char *name = (char*)menu->dname;
624 char *tip = menu->strings[MENU_INDEX_TIP]
625 ? (char*)menu->strings[MENU_INDEX_TIP] : (char*)menu->actext;
627 // HACK! Check if menu is mapped to ':action actionName:'; if so, pass the
628 // action along so that MacVim can bind the menu item to this action. This
629 // means that if a menu item maps to an action in normal mode, then all
630 // other modes will also use the same action.
631 NSString *action = nil;
632 char_u *map_str = menu->strings[MENU_INDEX_NORMAL];
634 NSString *mapping = [NSString stringWithCString:(char*)map_str
635 encoding:NSUTF8StringEncoding];
636 NSArray *parts = [mapping componentsSeparatedByString:@" "];
637 if ([parts count] >=2
638 && [[parts objectAtIndex:0] isEqual:@":action"]) {
639 action = [parts objectAtIndex:1];
640 action = [action stringByTrimmingCharactersInSet:
641 [NSCharacterSet whitespaceAndNewlineCharacterSet]];
642 if (!gui_cocoa_is_valid_action(action))
647 [[MMBackend sharedInstance]
648 addMenuItemWithTag:(int)menu
649 parent:(int)menu->parent
653 keyEquivalent:menu->ke_key
654 modifiers:menu->ke_mods
661 * Destroy the machine specific menu widget.
664 gui_mch_destroy_menu(vimmenu_T *menu)
666 //NSLog(@"gui_mch_destroy_menu(name=%s)", menu->name);
668 [[MMBackend sharedInstance] removeMenuItemWithTag:(int)menu];
673 * Make a menu either grey or not grey.
676 gui_mch_menu_grey(vimmenu_T *menu, int grey)
678 //NSLog(@"gui_mch_menu_grey(name=%s, grey=%d)", menu->name, grey);
679 [[MMBackend sharedInstance]
680 enableMenuItemWithTag:(int)menu state:!grey];
685 * Make menu item hidden or not hidden
688 gui_mch_menu_hidden(vimmenu_T *menu, int hidden)
690 //NSLog(@"gui_mch_menu_hidden(name=%s, hidden=%d)", menu->name, hidden);
692 // HACK! There is no (obvious) way to hide a menu item, so simply
693 // enable/disable it instead.
694 [[MMBackend sharedInstance]
695 enableMenuItemWithTag:(int)menu state:!hidden];
700 * This is called when user right clicks.
703 gui_mch_show_popupmenu(vimmenu_T *menu)
705 //NSLog(@"gui_mch_show_popupmenu(name=%s)", menu->name);
707 [[MMBackend sharedInstance] showPopupMenuWithName:(char*)menu->name
708 atMouseLocation:YES];
713 * This is called when a :popup command is executed.
716 gui_make_popup(char_u *path_name, int mouse_pos)
718 // TODO: Unless mouse_pos set, popup at cursor location.
719 [[MMBackend sharedInstance] showPopupMenuWithName:(char*)path_name
720 atMouseLocation:mouse_pos];
725 * This is called after setting all the menus to grey/hidden or not.
728 gui_mch_draw_menubar(void)
730 // The (main) menu draws itself in Mac OS X.
735 gui_mch_enable_menu(int flag)
737 // The (main) menu is always enabled in Mac OS X.
743 gui_mch_set_menu_pos(int x, int y, int w, int h)
745 // The (main) menu cannot be moved in Mac OS X.
751 gui_mch_show_toolbar(int showit)
754 if (toolbar_flags & TOOLBAR_TEXT) flags |= ToolbarLabelFlag;
755 if (toolbar_flags & TOOLBAR_ICONS) flags |= ToolbarIconFlag;
756 if (tbis_flags & (TBIS_MEDIUM|TBIS_LARGE)) flags |= ToolbarSizeRegularFlag;
758 //NSLog(@"gui_mch_show_toolbar(showit=%d, flags=%d)", showit, flags);
760 [[MMBackend sharedInstance] showToolbar:showit flags:flags];
766 // -- Fonts -----------------------------------------------------------------
770 * If a font is not going to be used, free its structure.
773 gui_mch_free_font(font)
780 * Get a font structure for highlighting.
783 gui_mch_get_font(char_u *name, int giveErrorIfMissing)
785 //NSLog(@"gui_mch_get_font(name=%s, giveErrorIfMissing=%d)", name,
786 // giveErrorIfMissing);
791 #if defined(FEAT_EVAL) || defined(PROTO)
793 * Return the name of font "font" in allocated memory.
794 * Don't know how to get the actual name, thus use the provided name.
797 gui_mch_get_fontname(GuiFont font, char_u *name)
799 //NSLog(@"gui_mch_get_fontname(font=%d, name=%s)", font, name);
806 * Initialise vim to use the font with the given name. Return FAIL if the font
807 * could not be loaded, OK otherwise.
810 gui_mch_init_font(char_u *font_name, int fontset)
812 //NSLog(@"gui_mch_init_font(font_name=%s, fontset=%d)", font_name, fontset);
814 // HACK! This gets called whenever the user types :set gfn=fontname, so
815 // for now we set the font here.
816 // TODO! Proper font handling, the way Vim expects it.
817 return [[MMBackend sharedInstance]
818 setFontWithName:(char*)font_name];
823 * Set the current text font.
826 gui_mch_set_font(GuiFont font)
833 // -- Scrollbars ------------------------------------------------------------
837 gui_mch_create_scrollbar(
839 int orient) /* SBAR_VERT or SBAR_HORIZ */
841 //NSLog(@"gui_mch_create_scrollbar(id=%d, orient=%d, type=%d)",
842 // sb->ident, orient, sb->type);
844 [[MMBackend sharedInstance]
845 createScrollbarWithIdentifier:sb->ident type:sb->type];
850 gui_mch_destroy_scrollbar(scrollbar_T *sb)
852 //NSLog(@"gui_mch_destroy_scrollbar(id=%d)", sb->ident);
854 [[MMBackend sharedInstance]
855 destroyScrollbarWithIdentifier:sb->ident];
860 gui_mch_enable_scrollbar(
864 //NSLog(@"gui_mch_enable_scrollbar(id=%d, flag=%d)", sb->ident, flag);
866 [[MMBackend sharedInstance]
867 showScrollbarWithIdentifier:sb->ident state:flag];
872 gui_mch_set_scrollbar_pos(
879 //NSLog(@"gui_mch_set_scrollbar_pos(id=%d, x=%d, y=%d, w=%d, h=%d)",
880 // sb->ident, x, y, w, h);
884 if (SBAR_BOTTOM == sb->type) {
889 [[MMBackend sharedInstance]
890 setScrollbarPosition:pos length:len identifier:sb->ident];
895 gui_mch_set_scrollbar_thumb(
901 //NSLog(@"gui_mch_set_scrollbar_thumb(id=%d, val=%d, size=%d, max=%d)",
902 // sb->ident, val, size, max);
904 [[MMBackend sharedInstance]
905 setScrollbarThumbValue:val size:size max:max identifier:sb->ident];
912 // -- Unsorted --------------------------------------------------------------
920 EMSG(_("E???: Command only available in GUI mode"));
924 NSString *name = [NSString stringWithCString:(char*)eap->arg
925 encoding:NSUTF8StringEncoding];
926 if (gui_cocoa_is_valid_action(name)) {
927 [[MMBackend sharedInstance] executeActionWithName:name];
929 EMSG2(_("E???: \"%s\" is not a valid action"), eap->arg);
935 * Adjust gui.char_height (after 'linespace' was changed).
938 gui_mch_adjust_charheight(void)
953 * Pop open a file browser and return the file selected, in allocated memory,
954 * or NULL if Cancel is hit.
955 * saving - TRUE if the file will be saved to, FALSE if it will be opened.
956 * title - Title message for the file browser dialog.
957 * dflt - Default name of file.
958 * ext - Default extension to be added to files without extensions.
959 * initdir - directory in which to open the browser (NULL = current dir)
960 * filter - Filter for matched files to choose from.
961 * Has a format like this:
962 * "C Files (*.c)\0*.c\0"
963 * "All Files\0*.*\0\0"
964 * If these two strings were concatenated, then a choice of two file
965 * filters will be selectable to the user. Then only matching files will
966 * be shown in the browser. If NULL, the default allows all files.
968 * *NOTE* - the filter string must be terminated with TWO nulls.
979 //NSLog(@"gui_mch_browse(saving=%d, title=%s, dflt=%s, ext=%s, initdir=%s,"
980 // " filter=%s", saving, title, dflt, ext, initdir, filter);
982 char_u *s = (char_u*)[[MMBackend sharedInstance]
983 browseForFileInDirectory:(char*)initdir title:(char*)title
988 #endif /* FEAT_BROWSE */
1001 //NSLog(@"gui_mch_dialog(type=%d title=%s message=%s buttons=%s "
1002 // "dfltbutton=%d textfield=%s)", type, title, message, buttons,
1003 // dfltbutton, textfield);
1005 return [[MMBackend sharedInstance] presentDialogWithType:type
1007 message:(char*)message
1008 buttons:(char*)buttons
1009 textField:(char*)textfield];
1014 * Draw a cursor without focus.
1017 gui_mch_draw_hollow_cursor(guicolor_T color)
1023 * Draw part of a cursor, only w pixels wide, and h pixels high.
1026 gui_mch_draw_part_cursor(int w, int h, guicolor_T color)
1032 gui_mch_flash(int msec)
1038 * Return the Pixel value (color) for the given color name. This routine was
1039 * pretty much taken from example code in the Silicon Graphics OSF/Motif
1040 * Programmer's Guide.
1041 * Return INVALCOLOR when failed.
1044 gui_mch_get_color(char_u *name)
1046 NSString *key = [NSString stringWithUTF8String:(char*)name];
1047 return [[MMBackend sharedInstance] lookupColorWithKey:key];
1052 * Return the RGB value of a pixel as long.
1055 gui_mch_get_rgb(guicolor_T pixel)
1057 // This is only implemented so that vim can guess the correct value for
1058 // 'background' (which otherwise defaults to 'dark'); it is not used for
1059 // anything else (as far as I know).
1060 // The implementation is simple since colors are stored in an int as
1067 * Get the screen dimensions.
1068 * Allow 10 pixels for horizontal borders, 40 for vertical borders.
1069 * Is there no way to find out how wide the borders really are?
1070 * TODO: Add live udate of those value on suspend/resume.
1073 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
1075 //NSLog(@"gui_mch_get_screen_dimensions()");
1076 *screen_w = Columns;
1082 * Get the position of the top left corner of the window.
1085 gui_mch_get_winpos(int *x, int *y)
1093 * Get current mouse coordinates in text window.
1096 gui_mch_getmouse(int *x, int *y)
1102 * Return OK if the key with the termcap name "name" is supported.
1105 gui_mch_haskey(char_u *name)
1107 NSLog(@"gui_mch_haskey(name=%s)", name);
1113 * Iconify the GUI window.
1116 gui_mch_iconify(void)
1122 * Invert a rectangle from row r, column c, for nr rows and nc columns.
1125 gui_mch_invert_rectangle(int r, int c, int nr, int nc)
1131 * Called when the foreground or background color has been changed.
1134 gui_mch_new_colors(void)
1136 gui.def_back_pixel = gui.back_pixel;
1137 gui.def_norm_pixel = gui.norm_pixel;
1139 //NSLog(@"gui_mch_new_colors(back=%x, norm=%x)", gui.def_back_pixel,
1140 // gui.def_norm_pixel);
1142 [[MMBackend sharedInstance]
1143 setDefaultColorsBackground:gui.def_back_pixel
1144 foreground:gui.def_norm_pixel];
1149 gui_mch_def_colors()
1151 // Default foreground and background colors are black and white.
1152 gui.def_norm_pixel = gui.norm_pixel = 0;
1153 gui.def_back_pixel = gui.back_pixel = 0xffffff;
1158 * Set the current text background color.
1161 gui_mch_set_bg_color(guicolor_T color)
1163 [[MMBackend sharedInstance] setBackgroundColor:color];
1168 * Cursor blink functions.
1170 * This is a simple state machine:
1171 * BLINK_NONE not blinking at all
1172 * BLINK_OFF blinking, cursor is not shown
1173 * BLINK_ON blinking, cursor is shown
1176 gui_mch_set_blinking(long wait, long on, long off)
1182 * Set the current text foreground color.
1185 gui_mch_set_fg_color(guicolor_T color)
1187 [[MMBackend sharedInstance] setForegroundColor:color];
1191 #if defined(FEAT_EVAL) || defined(PROTO)
1193 * Bring the Vim window to the foreground.
1196 gui_mch_set_foreground(void)
1204 gui_mch_set_shellsize(
1213 //NSLog(@"gui_mch_set_shellsize(width=%d, height=%d, min_width=%d,"
1214 // " min_height=%d, base_width=%d, base_height=%d, direction=%d)",
1215 // width, height, min_width, min_height, base_width, base_height,
1217 [[MMBackend sharedInstance] setRows:height columns:width];
1222 * Set the current text special color.
1225 gui_mch_set_sp_color(guicolor_T color)
1231 gui_mch_set_text_area_pos(int x, int y, int w, int h)
1236 * Set the position of the top left corner of the window to the given
1240 gui_mch_set_winpos(int x, int y)
1246 gui_mch_setmouse(int x, int y)
1253 * Set the window title and icon.
1254 * (The icon is not taken care of).
1257 gui_mch_settitle(char_u *title, char_u *icon)
1259 //NSLog(@"gui_mch_settitle(title=%s, icon=%s)", title, icon);
1261 [[MMBackend sharedInstance] setVimWindowTitle:(char*)title];
1267 * Start the cursor blinking. If it was already blinking, this restarts the
1268 * waiting time and shows the cursor.
1271 gui_mch_start_blink(void)
1277 * Stop the cursor blinking. Show the cursor if it wasn't shown.
1280 gui_mch_stop_blink(void)
1286 gui_mch_toggle_tearoffs(int enable)
1292 mch_set_mouse_shape(int shape)
1298 gui_cocoa_is_valid_action(NSString *action)
1300 static NSDictionary *actionDict = nil;
1303 NSBundle *mainBundle = [NSBundle mainBundle];
1304 NSString *path = [mainBundle pathForResource:@"Actions"
1307 actionDict = [[NSDictionary alloc] initWithContentsOfFile:path];
1309 // Allocate bogus dictionary so that error only pops up once.
1310 actionDict = [NSDictionary new];
1311 EMSG(_("E???: Failed to load action dictionary"));
1315 return [actionDict objectForKey:action] != nil;