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