Implemented CoreText renderer
[MacVim.git] / src / MacVim / MacVim.h
blob0c8762bccb6682ad471459e549eca99ac8233ff1
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.
9 */
11 #import <Cocoa/Cocoa.h>
12 #import <asl.h>
16 // Uncomment to enable support for MacVim plugins (not to be confused with Vim
17 // plugins!).
19 //#define MM_ENABLE_PLUGINS
22 // Taken from /usr/include/AvailabilityMacros.h
23 #ifndef MAC_OS_X_VERSION_10_4
24 # define MAC_OS_X_VERSION_10_4 1040
25 #endif
26 #ifndef MAC_OS_X_VERSION_10_5
27 # define MAC_OS_X_VERSION_10_5 1050
28 #endif
29 #ifndef MAC_OS_X_VERSION_10_6
30 # define MAC_OS_X_VERSION_10_6 1060
31 #endif
35 // This is the protocol MMBackend implements.
37 // Only processInput:data: is allowed to cause state changes in Vim; all other
38 // messages should only read the Vim state. (Note that setDialogReturn: is an
39 // exception to this rule; there really is no other way to deal with dialogs
40 // since they work with callbacks, so we cannot wait for them to return.)
42 // Be careful with messages with return type other than 'oneway void' -- there
43 // is a reply timeout set in MMAppController, if a message fails to get a
44 // response within the given timeout an exception will be thrown. Use
45 // @try/@catch/@finally to deal with timeouts.
47 @protocol MMBackendProtocol
48 - (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data;
49 - (oneway void)setDialogReturn:(in bycopy id)obj;
50 - (NSString *)evaluateExpression:(in bycopy NSString *)expr;
51 - (id)evaluateExpressionCocoa:(in bycopy NSString *)expr
52 errorString:(out bycopy NSString **)errstr;
53 - (BOOL)starRegisterToPasteboard:(byref NSPasteboard *)pboard;
54 - (oneway void)acknowledgeConnection;
55 @end
59 // This is the protocol MMAppController implements.
61 // It handles connections between MacVim and Vim and communication from Vim to
62 // MacVim.
64 // Do not add methods to this interface without a _very_ good reason (if
65 // possible, instead add a new message to the *MsgID enum below and pass it via
66 // processInput:forIdentifier). Methods should not modify the state directly
67 // but should instead delay any potential modifications (see
68 // connectBackend:pid: and processInput:forIdentifier:).
70 @protocol MMAppProtocol
71 - (unsigned)connectBackend:(byref in id <MMBackendProtocol>)proxy pid:(int)pid;
72 - (oneway void)processInput:(in bycopy NSArray *)queue
73 forIdentifier:(unsigned)identifier;
74 - (NSArray *)serverList;
75 @end
78 @protocol MMVimServerProtocol;
81 // The Vim client protocol (implemented by MMBackend).
83 // The client needs to keep track of server replies. Take a look at MMBackend
84 // if you want to implement this protocol in another program.
86 @protocol MMVimClientProtocol
87 - (oneway void)addReply:(in bycopy NSString *)reply
88 server:(in byref id <MMVimServerProtocol>)server;
89 @end
93 // The Vim server protocol (implemented by MMBackend).
95 // Note that addInput:client: is not asynchronous, because otherwise Vim might
96 // quit before the message has been passed (e.g. if --remote was used on the
97 // command line).
99 @protocol MMVimServerProtocol
100 - (void)addInput:(in bycopy NSString *)input
101 client:(in byref id <MMVimClientProtocol>)client;
102 - (NSString *)evaluateExpression:(in bycopy NSString *)expr
103 client:(in byref id <MMVimClientProtocol>)client;
104 @end
109 // The following enum lists all messages that are passed between MacVim and
110 // Vim. These can be sent in processInput:data: and in processCommandQueue:.
113 // NOTE! This array must be updated whenever the enum below changes!
114 extern char *MessageStrings[];
116 enum {
117 OpenWindowMsgID = 1, // NOTE: FIRST IN ENUM MUST BE 1
118 KeyDownMsgID,
119 BatchDrawMsgID,
120 SelectTabMsgID,
121 CloseTabMsgID,
122 AddNewTabMsgID,
123 DraggedTabMsgID,
124 UpdateTabBarMsgID,
125 ShowTabBarMsgID,
126 HideTabBarMsgID,
127 SetTextRowsMsgID,
128 SetTextColumnsMsgID,
129 SetTextDimensionsMsgID,
130 LiveResizeMsgID,
131 SetTextDimensionsReplyMsgID,
132 SetWindowTitleMsgID,
133 ScrollWheelMsgID,
134 MouseDownMsgID,
135 MouseUpMsgID,
136 MouseDraggedMsgID,
137 FlushQueueMsgID,
138 AddMenuMsgID,
139 AddMenuItemMsgID,
140 RemoveMenuItemMsgID,
141 EnableMenuItemMsgID,
142 ExecuteMenuMsgID,
143 ShowToolbarMsgID,
144 ToggleToolbarMsgID,
145 CreateScrollbarMsgID,
146 DestroyScrollbarMsgID,
147 ShowScrollbarMsgID,
148 SetScrollbarPositionMsgID,
149 SetScrollbarThumbMsgID,
150 ScrollbarEventMsgID,
151 SetFontMsgID,
152 SetWideFontMsgID,
153 VimShouldCloseMsgID,
154 SetDefaultColorsMsgID,
155 ExecuteActionMsgID,
156 DropFilesMsgID,
157 DropStringMsgID,
158 ShowPopupMenuMsgID,
159 GotFocusMsgID,
160 LostFocusMsgID,
161 MouseMovedMsgID,
162 SetMouseShapeMsgID,
163 AdjustLinespaceMsgID,
164 ActivateMsgID,
165 SetServerNameMsgID,
166 EnterFullscreenMsgID,
167 LeaveFullscreenMsgID,
168 BuffersNotModifiedMsgID,
169 BuffersModifiedMsgID,
170 AddInputMsgID,
171 SetPreEditPositionMsgID,
172 TerminateNowMsgID,
173 XcodeModMsgID,
174 EnableAntialiasMsgID,
175 DisableAntialiasMsgID,
176 SetVimStateMsgID,
177 SetDocumentFilenameMsgID,
178 OpenWithArgumentsMsgID,
179 CloseWindowMsgID,
180 SetFullscreenColorMsgID,
181 ShowFindReplaceDialogMsgID,
182 FindReplaceMsgID,
183 ActivateKeyScriptMsgID,
184 DeactivateKeyScriptMsgID,
185 EnableImControlMsgID,
186 DisableImControlMsgID,
187 ActivatedImMsgID,
188 DeactivatedImMsgID,
189 BrowseForFileMsgID,
190 ShowDialogMsgID,
191 NetBeansMsgID,
192 SetMarkedTextMsgID,
193 LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM!
197 enum {
198 ClearAllDrawType = 1,
199 ClearBlockDrawType,
200 DeleteLinesDrawType,
201 DrawStringDrawType,
202 InsertLinesDrawType,
203 DrawCursorDrawType,
204 SetCursorPosDrawType,
205 DrawInvertedRectDrawType,
208 enum {
209 MMInsertionPointBlock,
210 MMInsertionPointHorizontal,
211 MMInsertionPointVertical,
212 MMInsertionPointHollow,
213 MMInsertionPointVerticalRight,
217 enum {
218 ToolbarLabelFlag = 1,
219 ToolbarIconFlag = 2,
220 ToolbarSizeRegularFlag = 4
224 enum {
225 MMTabLabel = 0,
226 MMTabToolTip,
227 MMTabInfoCount
231 // Create a string holding the labels of all messages in message queue for
232 // debugging purposes (condense some messages since there may typically be LOTS
233 // of them on a queue).
234 NSString *debugStringForMessageQueue(NSArray *queue);
237 // Shared user defaults (most user defaults are in Miscellaneous.h).
238 // Contrary to the user defaults in Miscellaneous.h these defaults are not
239 // intitialized to any default values. That is, unless the user sets them
240 // these keys will not be present in the user default database.
241 extern NSString *MMLogLevelKey;
242 extern NSString *MMLogToStdErrKey;
244 // Argument used to stop MacVim from opening an empty window on startup
245 // (techincally this is a user default but should not be used as such).
246 extern NSString *MMNoWindowKey;
248 extern NSString *MMAutosaveRowsKey;
249 extern NSString *MMAutosaveColumnsKey;
252 // Vim pasteboard type (holds motion type + string)
253 extern NSString *VimPBoardType;
258 @interface NSString (MMExtras)
259 - (NSString *)stringByEscapingSpecialFilenameCharacters;
260 @end
263 @interface NSColor (MMExtras)
264 + (NSColor *)colorWithRgbInt:(unsigned)rgb;
265 + (NSColor *)colorWithArgbInt:(unsigned)argb;
266 @end
269 @interface NSDictionary (MMExtras)
270 + (id)dictionaryWithData:(NSData *)data;
271 - (NSData *)dictionaryAsData;
272 @end
274 @interface NSMutableDictionary (MMExtras)
275 + (id)dictionaryWithData:(NSData *)data;
276 @end
281 // ODB Editor Suite Constants (taken from ODBEditorSuite.h)
282 #define keyFileSender 'FSnd'
283 #define keyFileSenderToken 'FTok'
284 #define keyFileCustomPath 'Burl'
285 #define kODBEditorSuite 'R*ch'
286 #define kAEModifiedFile 'FMod'
287 #define keyNewLocation 'New?'
288 #define kAEClosedFile 'FCls'
289 #define keySenderToken 'Tokn'
292 // MacVim Apple Event Constants
293 #define keyMMUntitledWindow 'MMuw'
298 #ifndef NSINTEGER_DEFINED
299 // NSInteger was introduced in 10.5
300 # if __LP64__ || NS_BUILD_32_LIKE_64
301 typedef long NSInteger;
302 typedef unsigned long NSUInteger;
303 # else
304 typedef int NSInteger;
305 typedef unsigned int NSUInteger;
306 # endif
307 # define NSINTEGER_DEFINED 1
308 #endif
310 #ifndef NSAppKitVersionNumber10_4 // Needed for pre-10.5 SDK
311 # define NSAppKitVersionNumber10_4 824
312 #endif
314 #ifndef CGFLOAT_DEFINED
315 // On Leopard, CGFloat is float on 32bit and double on 64bit. On Tiger,
316 // we can't use this anyways, so it's just here to keep the compiler happy.
317 // However, when we're compiling for Tiger and running on Leopard, we
318 // might need the correct typedef, so this piece is copied from ATSTypes.h
319 # ifdef __LP64__
320 typedef double CGFloat;
321 # else
322 typedef float CGFloat;
323 # endif
324 #endif
327 // Logging related functions and macros.
329 // This is a very simplistic logging facility built on top of ASL. Two user
330 // defaults allow for changing the local log filter level (MMLogLevel) and
331 // whether logs should be sent to stderr (MMLogToStdErr). (These user defaults
332 // are only checked during startup.) The default is to block level 6 (info)
333 // and 7 (debug) logs and _not_ to send logs to stderr. Apart from this
334 // "syslog" (see "man syslog") can be used to modify the ASL filters (it is
335 // currently not possible to change the local filter at runtime). For example:
336 // Enable all logs to reach the ASL database (by default 'debug' and 'info'
337 // are filtered out, see "man syslogd"):
338 // $ sudo syslog -c syslogd -d
339 // Reset the ASL database filter:
340 // $ sudo syslog -c syslogd off
341 // Change the master filter to block logs less severe than errors:
342 // $ sudo syslog -c 0 -e
343 // Change per-process filter for running MacVim process to block logs less
344 // severe than warnings:
345 // $ syslog -c MacVim -w
347 // Note that there are four ASL filters:
348 // 1) The ASL database filter (syslog -c syslogd ...)
349 // 2) The master filter (syslog -c 0 ...)
350 // 3) The per-process filter (syslog -c PID ...)
351 // 4) The local filter (MMLogLevel)
353 // To view the logs, either use "Console.app" or the "syslog" command:
354 // $ syslog -w | grep Vim
355 // To get the logs to show up in Xcode enable the MMLogToStdErr user default.
357 extern int ASLogLevel;
359 void ASLInit();
361 #define ASLog(level, fmt, ...) \
362 if (level <= ASLogLevel) { \
363 asl_log(NULL, NULL, level, "%s@%d: %s", \
364 __PRETTY_FUNCTION__, __LINE__, \
365 [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \
368 // Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C
369 // style specifiers (%@) are supported.
370 #define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__)
371 #define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__)
372 #define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__)
373 #define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)
374 #define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__)
375 #define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
376 #define ASLogTmp(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)