Update fullscreen background color immediately
[MacVim.git] / src / MacVim / MacVim.m
blobcc220ea1c21a8ef4f91aab5bcbb053f826a65c26
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     "OpenWindowMsgID",
20     "InsertTextMsgID",
21     "KeyDownMsgID",
22     "CmdKeyMsgID",
23     "BatchDrawMsgID",
24     "SelectTabMsgID",
25     "CloseTabMsgID",
26     "AddNewTabMsgID",
27     "DraggedTabMsgID",
28     "UpdateTabBarMsgID",
29     "ShowTabBarMsgID",
30     "HideTabBarMsgID",
31     "SetTextRowsMsgID",
32     "SetTextColumsMsgID",
33     "SetTextDimensionsMsgID",
34     "SetWindowTitleMsgID",
35     "ScrollWheelMsgID",
36     "MouseDownMsgID",
37     "MouseUpMsgID",
38     "MouseDraggedMsgID",
39     "FlushQueueMsgID",
40     "AddMenuMsgID",
41     "AddMenuItemMsgID",
42     "RemoveMenuItemMsgID",
43     "EnableMenuItemMsgID",
44     "ExecuteMenuMsgID",
45     "ShowToolbarMsgID",
46     "ToggleToolbarMsgID",
47     "CreateScrollbarMsgID",
48     "DestroyScrollbarMsgID",
49     "ShowScrollbarMsgID",
50     "SetScrollbarPositionMsgID",
51     "SetScrollbarThumbMsgID",
52     "ScrollbarEventMsgID",
53     "SetFontMsgID",
54     "SetWideFontMsgID",
55     "VimShouldCloseMsgID",
56     "SetDefaultColorsMsgID",
57     "ExecuteActionMsgID",
58     "DropFilesMsgID",
59     "DropStringMsgID",
60     "ShowPopupMenuMsgID",
61     "GotFocusMsgID",
62     "LostFocusMsgID",
63     "MouseMovedMsgID",
64     "SetMouseShapeMsgID",
65     "AdjustLinespaceMsgID",
66     "ActivateMsgID",
67     "SetServerNameMsgID",
68     "EnterFullscreenMsgID",
69     "LeaveFullscreenMsgID",
70     "BuffersNotModifiedMsgID",
71     "BuffersModifiedMsgID",
72     "AddInputMsgID",
73     "SetPreEditPositionMsgID",
74     "TerminateNowMsgID",
75     "XcodeModMsgID",
76     "LiveResizeMsgID",
77     "EnableAntialiasMsgID",
78     "DisableAntialiasMsgID",
79     "SetVimStateMsgID",
80     "SetDocumentFilenameMsgID",
81     "OpenWithArgumentsMsgID",
82     "CloseWindowMsgID",
83     "InterruptMsgID",
84     "SetFullscreenColorMsgID",
90 // Argument used to stop MacVim from opening an empty window on startup
91 // (techincally this is a user default but should not be used as such).
92 NSString *MMNoWindowKey = @"MMNoWindow";
94 // Vim pasteboard type (holds motion type + string)
95 NSString *VimPBoardType = @"VimPBoardType";
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 NSColor (MMExtras)
178 + (NSColor *)colorWithRgbInt:(unsigned)rgb
180     float r = ((rgb>>16) & 0xff)/255.0f;
181     float g = ((rgb>>8) & 0xff)/255.0f;
182     float b = (rgb & 0xff)/255.0f;
184     return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
187 + (NSColor *)colorWithArgbInt:(unsigned)argb
189     float a = ((argb>>24) & 0xff)/255.0f;
190     float r = ((argb>>16) & 0xff)/255.0f;
191     float g = ((argb>>8) & 0xff)/255.0f;
192     float b = (argb & 0xff)/255.0f;
194     return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:a];
197 @end // NSColor (MMExtras)
202 @implementation NSDictionary (MMExtras)
204 + (id)dictionaryWithData:(NSData *)data
206     id plist = [NSPropertyListSerialization
207             propertyListFromData:data
208                 mutabilityOption:NSPropertyListImmutable
209                           format:NULL
210                 errorDescription:NULL];
212     return [plist isKindOfClass:[NSDictionary class]] ? plist : nil;
215 - (NSData *)dictionaryAsData
217     return [NSPropertyListSerialization dataFromPropertyList:self
218             format:NSPropertyListBinaryFormat_v1_0 errorDescription:NULL];
221 @end
226 @implementation NSMutableDictionary (MMExtras)
228 + (id)dictionaryWithData:(NSData *)data
230     id plist = [NSPropertyListSerialization
231             propertyListFromData:data
232                 mutabilityOption:NSPropertyListMutableContainers
233                           format:NULL
234                 errorDescription:NULL];
236     return [plist isKindOfClass:[NSMutableDictionary class]] ? plist : nil;
239 @end