f07bfe5a12546a3ef6a8df7d541525b11a244823
[MacVim.git] / src / MacVim / MacVim.h
blobf07bfe5a12546a3ef6a8df7d541525b11a244823
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 ZoomMsgID,
194 LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM!
198 enum {
199 ClearAllDrawType = 1,
200 ClearBlockDrawType,
201 DeleteLinesDrawType,
202 DrawStringDrawType,
203 InsertLinesDrawType,
204 DrawCursorDrawType,
205 SetCursorPosDrawType,
206 DrawInvertedRectDrawType,
209 enum {
210 MMInsertionPointBlock,
211 MMInsertionPointHorizontal,
212 MMInsertionPointVertical,
213 MMInsertionPointHollow,
214 MMInsertionPointVerticalRight,
218 enum {
219 ToolbarLabelFlag = 1,
220 ToolbarIconFlag = 2,
221 ToolbarSizeRegularFlag = 4
225 enum {
226 MMTabLabel = 0,
227 MMTabToolTip,
228 MMTabInfoCount
232 // Create a string holding the labels of all messages in message queue for
233 // debugging purposes (condense some messages since there may typically be LOTS
234 // of them on a queue).
235 NSString *debugStringForMessageQueue(NSArray *queue);
238 // Shared user defaults (most user defaults are in Miscellaneous.h).
239 // Contrary to the user defaults in Miscellaneous.h these defaults are not
240 // intitialized to any default values. That is, unless the user sets them
241 // these keys will not be present in the user default database.
242 extern NSString *MMLogLevelKey;
243 extern NSString *MMLogToStdErrKey;
245 // Argument used to stop MacVim from opening an empty window on startup
246 // (techincally this is a user default but should not be used as such).
247 extern NSString *MMNoWindowKey;
249 extern NSString *MMAutosaveRowsKey;
250 extern NSString *MMAutosaveColumnsKey;
251 extern NSString *MMRendererKey;
253 enum {
254 MMRendererDefault = 0,
255 MMRendererATSUI,
256 MMRendererCoreText
260 // Vim pasteboard type (holds motion type + string)
261 extern NSString *VimPboardType;
262 extern NSString *VimFindPboardType;
267 @interface NSString (MMExtras)
268 - (NSString *)stringByEscapingSpecialFilenameCharacters;
269 - (NSString *)stringByRemovingFindPatterns;
270 @end
273 @interface NSColor (MMExtras)
274 + (NSColor *)colorWithRgbInt:(unsigned)rgb;
275 + (NSColor *)colorWithArgbInt:(unsigned)argb;
276 @end
279 @interface NSDictionary (MMExtras)
280 + (id)dictionaryWithData:(NSData *)data;
281 - (NSData *)dictionaryAsData;
282 @end
284 @interface NSMutableDictionary (MMExtras)
285 + (id)dictionaryWithData:(NSData *)data;
286 @end
291 // ODB Editor Suite Constants (taken from ODBEditorSuite.h)
292 #define keyFileSender 'FSnd'
293 #define keyFileSenderToken 'FTok'
294 #define keyFileCustomPath 'Burl'
295 #define kODBEditorSuite 'R*ch'
296 #define kAEModifiedFile 'FMod'
297 #define keyNewLocation 'New?'
298 #define kAEClosedFile 'FCls'
299 #define keySenderToken 'Tokn'
302 // MacVim Apple Event Constants
303 #define keyMMUntitledWindow 'MMuw'
308 #ifndef NSINTEGER_DEFINED
309 // NSInteger was introduced in 10.5
310 # if __LP64__ || NS_BUILD_32_LIKE_64
311 typedef long NSInteger;
312 typedef unsigned long NSUInteger;
313 # else
314 typedef int NSInteger;
315 typedef unsigned int NSUInteger;
316 # endif
317 # define NSINTEGER_DEFINED 1
318 #endif
320 #ifndef NSAppKitVersionNumber10_4 // Needed for pre-10.5 SDK
321 # define NSAppKitVersionNumber10_4 824
322 #endif
324 #ifndef CGFLOAT_DEFINED
325 // On Leopard, CGFloat is float on 32bit and double on 64bit. On Tiger,
326 // we can't use this anyways, so it's just here to keep the compiler happy.
327 // However, when we're compiling for Tiger and running on Leopard, we
328 // might need the correct typedef, so this piece is copied from ATSTypes.h
329 # ifdef __LP64__
330 typedef double CGFloat;
331 # else
332 typedef float CGFloat;
333 # endif
334 #endif
337 // Logging related functions and macros.
339 // This is a very simplistic logging facility built on top of ASL. Two user
340 // defaults allow for changing the local log filter level (MMLogLevel) and
341 // whether logs should be sent to stderr (MMLogToStdErr). (These user defaults
342 // are only checked during startup.) The default is to block level 6 (info)
343 // and 7 (debug) logs and _not_ to send logs to stderr. Apart from this
344 // "syslog" (see "man syslog") can be used to modify the ASL filters (it is
345 // currently not possible to change the local filter at runtime). For example:
346 // Enable all logs to reach the ASL database (by default 'debug' and 'info'
347 // are filtered out, see "man syslogd"):
348 // $ sudo syslog -c syslogd -d
349 // Reset the ASL database filter:
350 // $ sudo syslog -c syslogd off
351 // Change the master filter to block logs less severe than errors:
352 // $ sudo syslog -c 0 -e
353 // Change per-process filter for running MacVim process to block logs less
354 // severe than warnings:
355 // $ syslog -c MacVim -w
357 // Note that there are four ASL filters:
358 // 1) The ASL database filter (syslog -c syslogd ...)
359 // 2) The master filter (syslog -c 0 ...)
360 // 3) The per-process filter (syslog -c PID ...)
361 // 4) The local filter (MMLogLevel)
363 // To view the logs, either use "Console.app" or the "syslog" command:
364 // $ syslog -w | grep Vim
365 // To get the logs to show up in Xcode enable the MMLogToStdErr user default.
367 extern int ASLogLevel;
369 void ASLInit();
371 #define ASLog(level, fmt, ...) \
372 if (level <= ASLogLevel) { \
373 asl_log(NULL, NULL, level, "%s@%d: %s", \
374 __PRETTY_FUNCTION__, __LINE__, \
375 [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \
378 // Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C
379 // style specifiers (%@) are supported.
380 #define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__)
381 #define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__)
382 #define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__)
383 #define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)
384 #define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__)
385 #define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__)
386 #define ASLogTmp(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)