Refactor keyboard input code
[MacVim.git] / src / MacVim / MacVim.h
blob4c49e3b41e53ff5ae0e3954a45585457ddaba483
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 // Enable support for MacVim plugins (not to be confused with Vim plugins!).
18 #define MM_ENABLE_PLUGINS
23 // This is the protocol MMBackend implements.
25 // Only processInput:data: is allowed to cause state changes in Vim; all other
26 // messages should only read the Vim state. (Note that setDialogReturn: is an
27 // exception to this rule; there really is no other way to deal with dialogs
28 // since they work with callbacks, so we cannot wait for them to return.)
30 // Be careful with messages with return type other than 'oneway void' -- there
31 // is a reply timeout set in MMAppController, if a message fails to get a
32 // response within the given timeout an exception will be thrown. Use
33 // @try/@catch/@finally to deal with timeouts.
35 @protocol MMBackendProtocol
36 - (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data;
37 - (oneway void)setDialogReturn:(in bycopy id)obj;
38 - (NSString *)evaluateExpression:(in bycopy NSString *)expr;
39 - (id)evaluateExpressionCocoa:(in bycopy NSString *)expr
40 errorString:(out bycopy NSString **)errstr;
41 - (BOOL)starRegisterToPasteboard:(byref NSPasteboard *)pboard;
42 - (oneway void)acknowledgeConnection;
43 @end
47 // This is the protocol MMAppController implements.
49 // It handles connections between MacVim and Vim and communication from Vim to
50 // MacVim.
52 // Do not add methods to this interface without a _very_ good reason (if
53 // possible, instead add a new message to the *MsgID enum below and pass it via
54 // processInput:forIdentifier). Methods should not modify the state directly
55 // but should instead delay any potential modifications (see
56 // connectBackend:pid: and processInput:forIdentifier:).
58 @protocol MMAppProtocol
59 - (unsigned)connectBackend:(byref in id <MMBackendProtocol>)proxy pid:(int)pid;
60 - (oneway void)processInput:(in bycopy NSArray *)queue
61 forIdentifier:(unsigned)identifier;
62 - (NSArray *)serverList;
63 @end
66 @protocol MMVimServerProtocol;
69 // The Vim client protocol (implemented by MMBackend).
71 // The client needs to keep track of server replies. Take a look at MMBackend
72 // if you want to implement this protocol in another program.
74 @protocol MMVimClientProtocol
75 - (oneway void)addReply:(in bycopy NSString *)reply
76 server:(in byref id <MMVimServerProtocol>)server;
77 @end
81 // The Vim server protocol (implemented by MMBackend).
83 // Note that addInput:client: is not asynchronous, because otherwise Vim might
84 // quit before the message has been passed (e.g. if --remote was used on the
85 // command line).
87 @protocol MMVimServerProtocol
88 - (void)addInput:(in bycopy NSString *)input
89 client:(in byref id <MMVimClientProtocol>)client;
90 - (NSString *)evaluateExpression:(in bycopy NSString *)expr
91 client:(in byref id <MMVimClientProtocol>)client;
92 @end
97 // The following enum lists all messages that are passed between MacVim and
98 // Vim. These can be sent in processInput:data: and in processCommandQueue:.
101 // NOTE! This array must be updated whenever the enum below changes!
102 extern char *MessageStrings[];
104 enum {
105 OpenWindowMsgID = 1, // NOTE: FIRST IN ENUM MUST BE 1
106 KeyDownMsgID,
107 BatchDrawMsgID,
108 SelectTabMsgID,
109 CloseTabMsgID,
110 AddNewTabMsgID,
111 DraggedTabMsgID,
112 UpdateTabBarMsgID,
113 ShowTabBarMsgID,
114 HideTabBarMsgID,
115 SetTextRowsMsgID,
116 SetTextColumnsMsgID,
117 SetTextDimensionsMsgID,
118 LiveResizeMsgID,
119 SetTextDimensionsReplyMsgID,
120 SetWindowTitleMsgID,
121 ScrollWheelMsgID,
122 MouseDownMsgID,
123 MouseUpMsgID,
124 MouseDraggedMsgID,
125 FlushQueueMsgID,
126 AddMenuMsgID,
127 AddMenuItemMsgID,
128 RemoveMenuItemMsgID,
129 EnableMenuItemMsgID,
130 ExecuteMenuMsgID,
131 ShowToolbarMsgID,
132 ToggleToolbarMsgID,
133 CreateScrollbarMsgID,
134 DestroyScrollbarMsgID,
135 ShowScrollbarMsgID,
136 SetScrollbarPositionMsgID,
137 SetScrollbarThumbMsgID,
138 ScrollbarEventMsgID,
139 SetFontMsgID,
140 SetWideFontMsgID,
141 VimShouldCloseMsgID,
142 SetDefaultColorsMsgID,
143 ExecuteActionMsgID,
144 DropFilesMsgID,
145 DropStringMsgID,
146 ShowPopupMenuMsgID,
147 GotFocusMsgID,
148 LostFocusMsgID,
149 MouseMovedMsgID,
150 SetMouseShapeMsgID,
151 AdjustLinespaceMsgID,
152 ActivateMsgID,
153 SetServerNameMsgID,
154 EnterFullscreenMsgID,
155 LeaveFullscreenMsgID,
156 BuffersNotModifiedMsgID,
157 BuffersModifiedMsgID,
158 AddInputMsgID,
159 SetPreEditPositionMsgID,
160 TerminateNowMsgID,
161 XcodeModMsgID,
162 EnableAntialiasMsgID,
163 DisableAntialiasMsgID,
164 SetVimStateMsgID,
165 SetDocumentFilenameMsgID,
166 OpenWithArgumentsMsgID,
167 CloseWindowMsgID,
168 SetFullscreenColorMsgID,
169 ShowFindReplaceDialogMsgID,
170 FindReplaceMsgID,
171 ActivateKeyScriptMsgID,
172 DeactivateKeyScriptMsgID,
173 EnableImControlMsgID,
174 DisableImControlMsgID,
175 ActivatedImMsgID,
176 DeactivatedImMsgID,
177 BrowseForFileMsgID,
178 ShowDialogMsgID,
179 NetBeansMsgID,
180 LastMsgID // NOTE: MUST BE LAST MESSAGE IN ENUM!
184 #define DRAW_WIDE 0x40 /* draw wide text */
186 enum {
187 ClearAllDrawType = 1,
188 ClearBlockDrawType,
189 DeleteLinesDrawType,
190 DrawStringDrawType,
191 InsertLinesDrawType,
192 DrawCursorDrawType,
193 SetCursorPosDrawType,
194 DrawInvertedRectDrawType,
197 enum {
198 MMInsertionPointBlock,
199 MMInsertionPointHorizontal,
200 MMInsertionPointVertical,
201 MMInsertionPointHollow,
202 MMInsertionPointVerticalRight,
206 enum {
207 ToolbarLabelFlag = 1,
208 ToolbarIconFlag = 2,
209 ToolbarSizeRegularFlag = 4
213 enum {
214 MMTabLabel = 0,
215 MMTabToolTip,
216 MMTabInfoCount
220 // Create a string holding the labels of all messages in message queue for
221 // debugging purposes (condense some messages since there may typically be LOTS
222 // of them on a queue).
223 NSString *debugStringForMessageQueue(NSArray *queue);
226 // Shared user defaults (most user defaults are in Miscellaneous.h).
227 // Contrary to the user defaults in Miscellaneous.h these defaults are not
228 // intitialized to any default values. That is, unless the user sets them
229 // these keys will not be present in the user default database.
230 extern NSString *MMLogLevelKey;
231 extern NSString *MMLogToStdErrKey;
233 // Argument used to stop MacVim from opening an empty window on startup
234 // (techincally this is a user default but should not be used as such).
235 extern NSString *MMNoWindowKey;
238 // Vim pasteboard type (holds motion type + string)
239 extern NSString *VimPBoardType;
244 @interface NSString (MMExtras)
245 - (NSString *)stringByEscapingSpecialFilenameCharacters;
246 @end
249 @interface NSColor (MMExtras)
250 + (NSColor *)colorWithRgbInt:(unsigned)rgb;
251 + (NSColor *)colorWithArgbInt:(unsigned)argb;
252 @end
255 @interface NSDictionary (MMExtras)
256 + (id)dictionaryWithData:(NSData *)data;
257 - (NSData *)dictionaryAsData;
258 @end
260 @interface NSMutableDictionary (MMExtras)
261 + (id)dictionaryWithData:(NSData *)data;
262 @end
267 // ODB Editor Suite Constants (taken from ODBEditorSuite.h)
268 #define keyFileSender 'FSnd'
269 #define keyFileSenderToken 'FTok'
270 #define keyFileCustomPath 'Burl'
271 #define kODBEditorSuite 'R*ch'
272 #define kAEModifiedFile 'FMod'
273 #define keyNewLocation 'New?'
274 #define kAEClosedFile 'FCls'
275 #define keySenderToken 'Tokn'
278 // MacVim Apple Event Constants
279 #define keyMMUntitledWindow 'MMuw'
284 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
285 // NSInteger was introduced in 10.5
286 # if __LP64__ || NS_BUILD_32_LIKE_64
287 typedef long NSInteger;
288 typedef unsigned long NSUInteger;
289 # else
290 typedef int NSInteger;
291 typedef unsigned int NSUInteger;
292 # endif
293 #endif
295 #ifndef NSAppKitVersionNumber10_4 // Needed for pre-10.5 SDK
296 # define NSAppKitVersionNumber10_4 824
297 #endif
300 // Logging related functions and macros.
302 // This is a very simplistic logging facility built on top of ASL. Two user
303 // defaults allow for changing the local log filter level (MMLogLevel) and
304 // whether logs should be sent to stderr (MMLogToStdErr). (These user defaults
305 // are only checked during startup.) The default is to block level 6 (info)
306 // and 7 (debug) logs and _not_ to send logs to stderr. Apart from this
307 // "syslog" (see "man syslog") can be used to modify the ASL filters (it is
308 // currently not possible to change the local filter at runtime). For example:
309 // Enable all logs to reach the ASL database (by default 'debug' and 'info'
310 // are filtered out, see "man syslogd"):
311 // $ sudo syslog -c syslogd -d
312 // Reset the ASL database filter:
313 // $ sudo syslog -c syslogd off
314 // Change the master filter to block logs less severe than errors:
315 // $ sudo syslog -c 0 -e
316 // Change per-process filter for running MacVim process to block logs less
317 // severe than warnings:
318 // $ syslog -c MacVim -w
320 // Note that there are four ASL filters:
321 // 1) The ASL database filter (syslog -c syslogd ...)
322 // 2) The master filter (syslog -c 0 ...)
323 // 3) The per-process filter (syslog -c PID ...)
324 // 4) The local filter (MMLogLevel)
326 // To view the logs, either use "Console.app" or the "syslog" command:
327 // $ syslog -w | grep Vim
328 // To get the logs to show up in Xcode enable the MMLogToStdErr user default.
330 extern int ASLogLevel;
332 void ASLInit();
334 #define ASLog(level, fmt, ...) \
335 if (level <= ASLogLevel) { \
336 asl_log(NULL, NULL, level, "%s@%d: %s", \
337 __PRETTY_FUNCTION__, __LINE__, \
338 [[NSString stringWithFormat:fmt, ##__VA_ARGS__] UTF8String]); \
341 // Note: These macros are used like ASLogErr(@"text num=%d", 42). Objective-C
342 // style specifiers (%@) are supported.
343 #define ASLogCrit(fmt, ...) ASLog(ASL_LEVEL_CRIT, fmt, ##__VA_ARGS__)
344 #define ASLogErr(fmt, ...) ASLog(ASL_LEVEL_ERR, fmt, ##__VA_ARGS__)
345 #define ASLogWarn(fmt, ...) ASLog(ASL_LEVEL_WARNING, fmt, ##__VA_ARGS__)
346 #define ASLogNotice(fmt, ...) ASLog(ASL_LEVEL_NOTICE, fmt, ##__VA_ARGS__)
347 #define ASLogInfo(fmt, ...) ASLog(ASL_LEVEL_INFO, fmt, ##__VA_ARGS__)
348 #define ASLogDebug(fmt, ...) ASLog(ASL_LEVEL_DEBUG, fmt, ##__VA_ARGS__)