Add IM control support
[MacVim/jjgod.git] / src / MacVim / MacVim.m
blobb9a5df8cdf99d9010a044582a4081f95eab456e2
1 /* vi:set ts=8 sts=4 sw=4 ft=objc:
2  *
3  * VIM - Vi IMproved            by Bram Moolenaar
4  *                              MacVim GUI port by Bjorn Winckler
5  *
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.
9  */
11  * MacVim.m:  Code shared between Vim and MacVim.
12  */
14 #import "MacVim.h"
16 char *MessageStrings[] = 
18     "INVALID MESSAGE ID",
19     "OpenVimWindowMsgID",
20     "InsertTextMsgID",
21     "KeyDownMsgID",
22     "CmdKeyMsgID",
23     "BatchDrawMsgID",
24     "SelectTabMsgID",
25     "CloseTabMsgID",
26     "AddNewTabMsgID",
27     "DraggedTabMsgID",
28     "UpdateTabBarMsgID",
29     "ShowTabBarMsgID",
30     "HideTabBarMsgID",
31     "SetTextDimensionsMsgID",
32     "SetWindowTitleMsgID",
33     "ScrollWheelMsgID",
34     "MouseDownMsgID",
35     "MouseUpMsgID",
36     "MouseDraggedMsgID",
37     "FlushQueueMsgID",
38     "AddMenuMsgID",
39     "AddMenuItemMsgID",
40     "RemoveMenuItemMsgID",
41     "EnableMenuItemMsgID",
42     "ExecuteMenuMsgID",
43     "ShowToolbarMsgID",
44     "ToggleToolbarMsgID",
45     "CreateScrollbarMsgID",
46     "DestroyScrollbarMsgID",
47     "ShowScrollbarMsgID",
48     "SetScrollbarPositionMsgID",
49     "SetScrollbarThumbMsgID",
50     "ScrollbarEventMsgID",
51     "SetFontMsgID",
52     "SetWideFontMsgID",
53     "VimShouldCloseMsgID",
54     "SetDefaultColorsMsgID",
55     "ExecuteActionMsgID",
56     "DropFilesMsgID",
57     "DropStringMsgID",
58     "ShowPopupMenuMsgID",
59     "GotFocusMsgID",
60     "LostFocusMsgID",
61     "MouseMovedMsgID",
62     "SetMouseShapeMsgID",
63     "AdjustLinespaceMsgID",
64     "ActivateMsgID",
65     "SetServerNameMsgID",
66     "EnterFullscreenMsgID",
67     "LeaveFullscreenMsgID",
68     "BuffersNotModifiedMsgID",
69     "BuffersModifiedMsgID",
70     "AddInputMsgID",
71     "SetPreEditPositionMsgID",
77 // NSUserDefaults keys
78 NSString *MMNoWindowKey                 = @"MMNoWindow";
79 NSString *MMTabMinWidthKey              = @"MMTabMinWidth";
80 NSString *MMTabMaxWidthKey              = @"MMTabMaxWidth";
81 NSString *MMTabOptimumWidthKey          = @"MMTabOptimumWidth";
82 NSString *MMTextInsetLeftKey            = @"MMTextInsetLeft";
83 NSString *MMTextInsetRightKey           = @"MMTextInsetRight";
84 NSString *MMTextInsetTopKey             = @"MMTextInsetTop";
85 NSString *MMTextInsetBottomKey          = @"MMTextInsetBottom";
86 NSString *MMTerminateAfterLastWindowClosedKey
87                                         = @"MMTerminateAfterLastWindowClosed";
88 NSString *MMTypesetterKey               = @"MMTypesetter";
89 NSString *MMCellWidthMultiplierKey      = @"MMCellWidthMultiplier";
90 NSString *MMBaselineOffsetKey           = @"MMBaselineOffset";
91 NSString *MMTranslateCtrlClickKey       = @"MMTranslateCtrlClick";
92 NSString *MMTopLeftPointKey             = @"MMTopLeftPoint";
93 NSString *MMOpenFilesInTabsKey          = @"MMOpenFilesInTabs";
94 NSString *MMNoFontSubstitutionKey       = @"MMNoFontSubstitution";
95 NSString *MMLoginShellKey               = @"MMLoginShell";
100     ATSFontContainerRef
101 loadFonts()
103     // This loads all fonts from the Resources folder.  The fonts are only
104     // available to the process which loaded them, so loading has to be done
105     // once for MacVim and an additional time for each Vim process.  The
106     // returned container ref should be used to deactiave the font.
107     //
108     // (Code taken from cocoadev.com)
109     ATSFontContainerRef fontContainerRef = 0;
110     NSString *fontsFolder = [[NSBundle mainBundle] resourcePath];    
111     if (fontsFolder) {
112         NSURL *fontsURL = [NSURL fileURLWithPath:fontsFolder];
113         if (fontsURL) {
114             FSRef fsRef;
115             FSSpec fsSpec;
116             CFURLGetFSRef((CFURLRef)fontsURL, &fsRef);
118             if (FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fsSpec,
119                         NULL) == noErr) {
120                 ATSFontActivateFromFileSpecification(&fsSpec,
121                         kATSFontContextLocal, kATSFontFormatUnspecified, NULL,
122                         kATSOptionFlagsDefault, &fontContainerRef);
123             }
124         }
125     }
127     return fontContainerRef;
133 @implementation NSString (MMExtras)
135 - (NSString *)stringByEscapingSpecialFilenameCharacters
137     // NOTE: This code assumes that no characters already have been escaped.
138     NSMutableString *string = [self mutableCopy];
140     [string replaceOccurrencesOfString:@"\\"
141                             withString:@"\\\\"
142                                options:NSLiteralSearch
143                                  range:NSMakeRange(0, [string length])];
144     [string replaceOccurrencesOfString:@" "
145                             withString:@"\\ "
146                                options:NSLiteralSearch
147                                  range:NSMakeRange(0, [string length])];
148     [string replaceOccurrencesOfString:@"\t"
149                             withString:@"\\\t "
150                                options:NSLiteralSearch
151                                  range:NSMakeRange(0, [string length])];
152     [string replaceOccurrencesOfString:@"%"
153                             withString:@"\\%"
154                                options:NSLiteralSearch
155                                  range:NSMakeRange(0, [string length])];
156     [string replaceOccurrencesOfString:@"#"
157                             withString:@"\\#"
158                                options:NSLiteralSearch
159                                  range:NSMakeRange(0, [string length])];
160     [string replaceOccurrencesOfString:@"|"
161                             withString:@"\\|"
162                                options:NSLiteralSearch
163                                  range:NSMakeRange(0, [string length])];
164     [string replaceOccurrencesOfString:@"\""
165                             withString:@"\\\""
166                                options:NSLiteralSearch
167                                  range:NSMakeRange(0, [string length])];
169     return [string autorelease];
172 @end // NSString (MMExtras)
176 @implementation NSIndexSet (MMExtras)
178 + (id)indexSetWithVimList:(NSString *)list
180     NSMutableIndexSet *idxSet = [NSMutableIndexSet indexSet];
181     NSArray *array = [list componentsSeparatedByString:@"\n"];
182     unsigned i, count = [array count];
184     for (i = 0; i < count; ++i) {
185         NSString *entry = [array objectAtIndex:i];
186         if ([entry intValue] > 0)
187             [idxSet addIndex:i];
188     }
190     return idxSet;
193 @end // NSIndexSet (MMExtras)