7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
2 *
|
|
3 * VIM - Vi IMproved by Bram Moolenaar
|
|
4 * GUI/Motif support by Robert Webb
|
|
5 * Macintosh port by Dany St-Amant
|
|
6 * and Axel Kielhorn
|
|
7 * Port to MPW by Bernhard PrŸmmer
|
|
8 * Initial Carbon port by Ammon Skidmore
|
|
9 *
|
|
10 * Do ":help uganda" in Vim to read copying and usage conditions.
|
|
11 * Do ":help credits" in Vim to see a list of people who contributed.
|
|
12 * See README.txt for an overview of the Vim source code.
|
|
13 */
|
|
14
|
|
15 /*
|
593
|
16 * NOTES: - Vim 7+ does not support classic MacOS. Please use Vim 6.x
|
|
17 * - Comments mentioning FAQ refer to the book:
|
|
18 * "Macworld Mac Programming FAQs" from "IDG Books"
|
7
|
19 */
|
|
20
|
|
21 /*
|
|
22 * TODO: Change still to merge from the macvim's iDisk
|
|
23 *
|
|
24 * error_ga, mch_errmsg, Navigation's changes in gui_mch_browse
|
|
25 * uses of MenuItemIndex, changes in gui_mch_set_shellsize,
|
|
26 * ScrapManager error handling.
|
|
27 * Comments about function remaining to Carbonize.
|
|
28 *
|
|
29 */
|
|
30
|
593
|
31 /* TODO (Jussi)
|
|
32 * * Clipboard does not work (at least some cases)
|
|
33 * * ATSU font rendering has some problems
|
|
34 * * Investigate and remove dead code (there is still lots of that)
|
|
35 */
|
7
|
36
|
|
37 #include <Devices.h> /* included first to avoid CR problems */
|
|
38 #include "vim.h"
|
|
39
|
593
|
40 #define USE_CARBONIZED
|
|
41 #define USE_AEVENT /* Enable AEVENT */
|
|
42 #undef USE_OFFSETED_WINDOW /* Debugging feature: start Vim window OFFSETed */
|
7
|
43
|
|
44 /* Compile as CodeWarior External Editor */
|
|
45 #if defined(FEAT_CW_EDITOR) && !defined(USE_AEVENT)
|
|
46 # define USE_AEVENT /* Need Apple Event Support */
|
|
47 #endif
|
|
48
|
9
|
49 /* Vim's Scrap flavor. */
|
|
50 #define VIMSCRAPFLAVOR 'VIM!'
|
|
51
|
7
|
52 static EventHandlerUPP mouseWheelHandlerUPP = NULL;
|
593
|
53 SInt32 gMacSystemVersion;
|
|
54
|
766
|
55 #ifdef MACOS_CONVERT
|
|
56 # define USE_CARBONKEYHANDLER
|
168
|
57 static EventHandlerUPP keyEventHandlerUPP = NULL;
|
|
58 #endif
|
|
59
|
7
|
60
|
|
61 /* Include some file. TODO: move into os_mac.h */
|
|
62 #include <Menus.h>
|
|
63 #include <Resources.h>
|
|
64 #include <Processes.h>
|
|
65 #ifdef USE_AEVENT
|
|
66 # include <AppleEvents.h>
|
|
67 # include <AERegistry.h>
|
|
68 #endif
|
|
69 # include <Gestalt.h>
|
|
70 #if UNIVERSAL_INTERFACES_VERSION >= 0x0330
|
|
71 # include <ControlDefinitions.h>
|
|
72 # include <Navigation.h> /* Navigation only part of ?? */
|
|
73 #endif
|
|
74
|
593
|
75 /* Help Manager (balloon.h, HM prefixed functions) are not supported
|
|
76 * under Carbon (Jussi) */
|
|
77 # if 0
|
7
|
78 /* New Help Interface for Mac, not implemented yet.*/
|
593
|
79 # include <MacHelp.h>
|
|
80 # endif
|
7
|
81
|
|
82 /*
|
593
|
83 * These seem to be rectangle options. Why are they not found in
|
|
84 * headers? (Jussi)
|
7
|
85 */
|
|
86 #define kNothing 0
|
|
87 #define kCreateEmpty 2 /*1*/
|
|
88 #define kCreateRect 2
|
|
89 #define kDestroy 3
|
|
90
|
|
91 /*
|
|
92 * Dany: Don't like those...
|
|
93 */
|
|
94 #define topLeft(r) (((Point*)&(r))[0])
|
|
95 #define botRight(r) (((Point*)&(r))[1])
|
|
96
|
|
97
|
|
98 /* Time of last mouse click, to detect double-click */
|
|
99 static long lastMouseTick = 0;
|
|
100
|
|
101 /* ??? */
|
|
102 static RgnHandle cursorRgn;
|
|
103 static RgnHandle dragRgn;
|
|
104 static Rect dragRect;
|
|
105 static short dragRectEnbl;
|
|
106 static short dragRectControl;
|
|
107
|
|
108 /* This variable is set when waiting for an event, which is the only moment
|
|
109 * scrollbar dragging can be done directly. It's not allowed while commands
|
|
110 * are executed, because it may move the cursor and that may cause unexpected
|
|
111 * problems (e.g., while ":s" is working).
|
|
112 */
|
|
113 static int allow_scrollbar = FALSE;
|
|
114
|
|
115 /* Last mouse click caused contextual menu, (to provide proper release) */
|
|
116 static short clickIsPopup;
|
|
117
|
|
118 /* Feedback Action for Scrollbar */
|
|
119 ControlActionUPP gScrollAction;
|
|
120 ControlActionUPP gScrollDrag;
|
|
121
|
|
122 /* Keeping track of which scrollbar is being dragged */
|
|
123 static ControlHandle dragged_sb = NULL;
|
|
124
|
13
|
125 static struct
|
|
126 {
|
|
127 FMFontFamily family;
|
|
128 FMFontSize size;
|
|
129 FMFontStyle style;
|
|
130 Boolean isPanelVisible;
|
|
131 } gFontPanelInfo = { 0, 0, 0, false };
|
593
|
132
|
766
|
133 #ifdef MACOS_CONVERT
|
168
|
134 # define USE_ATSUI_DRAWING
|
|
135 ATSUStyle gFontStyle;
|
|
136 Boolean gIsFontFallbackSet;
|
|
137 #endif
|
|
138
|
7
|
139 /* Colors Macros */
|
|
140 #define RGB(r,g,b) ((r) << 16) + ((g) << 8) + (b)
|
|
141 #define Red(c) ((c & 0x00FF0000) >> 16)
|
|
142 #define Green(c) ((c & 0x0000FF00) >> 8)
|
|
143 #define Blue(c) ((c & 0x000000FF) >> 0)
|
|
144
|
|
145 /* Key mapping */
|
|
146
|
|
147 #define vk_Esc 0x35 /* -> 1B */
|
|
148
|
|
149 #define vk_F1 0x7A /* -> 10 */
|
|
150 #define vk_F2 0x78 /*0x63*/
|
|
151 #define vk_F3 0x63 /*0x76*/
|
|
152 #define vk_F4 0x76 /*0x60*/
|
|
153 #define vk_F5 0x60 /*0x61*/
|
|
154 #define vk_F6 0x61 /*0x62*/
|
|
155 #define vk_F7 0x62 /*0x63*/ /*?*/
|
|
156 #define vk_F8 0x64
|
|
157 #define vk_F9 0x65
|
|
158 #define vk_F10 0x6D
|
|
159 #define vk_F11 0x67
|
|
160 #define vk_F12 0x6F
|
|
161 #define vk_F13 0x69
|
|
162 #define vk_F14 0x6B
|
|
163 #define vk_F15 0x71
|
|
164
|
|
165 #define vk_Clr 0x47 /* -> 1B (ESC) */
|
|
166 #define vk_Enter 0x4C /* -> 03 */
|
|
167
|
|
168 #define vk_Space 0x31 /* -> 20 */
|
|
169 #define vk_Tab 0x30 /* -> 09 */
|
|
170 #define vk_Return 0x24 /* -> 0D */
|
|
171 /* This is wrong for OSX, what is it for? */
|
|
172 #define vk_Delete 0X08 /* -> 08 BackSpace */
|
|
173
|
|
174 #define vk_Help 0x72 /* -> 05 */
|
|
175 #define vk_Home 0x73 /* -> 01 */
|
|
176 #define vk_PageUp 0x74 /* -> 0D */
|
|
177 #define vk_FwdDelete 0x75 /* -> 7F */
|
|
178 #define vk_End 0x77 /* -> 04 */
|
|
179 #define vk_PageDown 0x79 /* -> 0C */
|
|
180
|
|
181 #define vk_Up 0x7E /* -> 1E */
|
|
182 #define vk_Down 0x7D /* -> 1F */
|
|
183 #define vk_Left 0x7B /* -> 1C */
|
|
184 #define vk_Right 0x7C /* -> 1D */
|
|
185
|
|
186 #define vk_Undo vk_F1
|
|
187 #define vk_Cut vk_F2
|
|
188 #define vk_Copy vk_F3
|
|
189 #define vk_Paste vk_F4
|
|
190 #define vk_PrintScreen vk_F13
|
|
191 #define vk_SCrollLock vk_F14
|
|
192 #define vk_Pause vk_F15
|
|
193 #define vk_NumLock vk_Clr
|
|
194 #define vk_Insert vk_Help
|
|
195
|
|
196 #define KeySym char
|
|
197
|
|
198 static struct
|
|
199 {
|
|
200 KeySym key_sym;
|
|
201 char_u vim_code0;
|
|
202 char_u vim_code1;
|
|
203 } special_keys[] =
|
|
204 {
|
|
205 {vk_Up, 'k', 'u'},
|
|
206 {vk_Down, 'k', 'd'},
|
|
207 {vk_Left, 'k', 'l'},
|
|
208 {vk_Right, 'k', 'r'},
|
|
209
|
|
210 {vk_F1, 'k', '1'},
|
|
211 {vk_F2, 'k', '2'},
|
|
212 {vk_F3, 'k', '3'},
|
|
213 {vk_F4, 'k', '4'},
|
|
214 {vk_F5, 'k', '5'},
|
|
215 {vk_F6, 'k', '6'},
|
|
216 {vk_F7, 'k', '7'},
|
|
217 {vk_F8, 'k', '8'},
|
|
218 {vk_F9, 'k', '9'},
|
|
219 {vk_F10, 'k', ';'},
|
|
220
|
|
221 {vk_F11, 'F', '1'},
|
|
222 {vk_F12, 'F', '2'},
|
|
223 {vk_F13, 'F', '3'},
|
|
224 {vk_F14, 'F', '4'},
|
|
225 {vk_F15, 'F', '5'},
|
|
226
|
|
227 /* {XK_Help, '%', '1'}, */
|
|
228 /* {XK_Undo, '&', '8'}, */
|
|
229 /* {XK_BackSpace, 'k', 'b'}, */
|
|
230 #ifndef MACOS_X
|
|
231 {vk_Delete, 'k', 'b'},
|
|
232 #endif
|
|
233 {vk_Insert, 'k', 'I'},
|
|
234 {vk_FwdDelete, 'k', 'D'},
|
|
235 {vk_Home, 'k', 'h'},
|
|
236 {vk_End, '@', '7'},
|
|
237 /* {XK_Prior, 'k', 'P'}, */
|
|
238 /* {XK_Next, 'k', 'N'}, */
|
|
239 /* {XK_Print, '%', '9'}, */
|
|
240
|
|
241 {vk_PageUp, 'k', 'P'},
|
|
242 {vk_PageDown, 'k', 'N'},
|
|
243
|
|
244 /* End of list marker: */
|
|
245 {(KeySym)0, 0, 0}
|
|
246 };
|
|
247
|
|
248 /*
|
|
249 * ------------------------------------------------------------
|
|
250 * Forward declaration (for those needed)
|
|
251 * ------------------------------------------------------------
|
|
252 */
|
|
253
|
|
254 #ifdef USE_AEVENT
|
9
|
255 OSErr HandleUnusedParms(const AppleEvent *theAEvent);
|
7
|
256 #endif
|
|
257
|
|
258 /*
|
|
259 * ------------------------------------------------------------
|
|
260 * Conversion Utility
|
|
261 * ------------------------------------------------------------
|
|
262 */
|
|
263
|
|
264 /*
|
|
265 * C2Pascal_save
|
|
266 *
|
|
267 * Allocate memory and convert the C-String passed in
|
|
268 * into a pascal string
|
|
269 *
|
|
270 */
|
|
271
|
593
|
272 char_u *
|
|
273 C2Pascal_save(char_u *Cstring)
|
7
|
274 {
|
|
275 char_u *PascalString;
|
|
276 int len;
|
|
277
|
|
278 if (Cstring == NULL)
|
|
279 return NULL;
|
|
280
|
|
281 len = STRLEN(Cstring);
|
|
282
|
|
283 if (len > 255) /* Truncate if necessary */
|
|
284 len = 255;
|
|
285
|
|
286 PascalString = alloc(len + 1);
|
|
287 if (PascalString != NULL)
|
|
288 {
|
|
289 mch_memmove(PascalString + 1, Cstring, len);
|
|
290 PascalString[0] = len;
|
|
291 }
|
|
292
|
|
293 return PascalString;
|
|
294 }
|
|
295
|
|
296 /*
|
|
297 * C2Pascal_save_and_remove_backslash
|
|
298 *
|
|
299 * Allocate memory and convert the C-String passed in
|
|
300 * into a pascal string. Also remove the backslash at the same time
|
|
301 *
|
|
302 */
|
|
303
|
593
|
304 char_u *
|
|
305 C2Pascal_save_and_remove_backslash(char_u *Cstring)
|
7
|
306 {
|
|
307 char_u *PascalString;
|
|
308 int len;
|
|
309 char_u *p, *c;
|
|
310
|
|
311 len = STRLEN(Cstring);
|
|
312
|
|
313 if (len > 255) /* Truncate if necessary */
|
|
314 len = 255;
|
|
315
|
|
316 PascalString = alloc(len + 1);
|
|
317 if (PascalString != NULL)
|
|
318 {
|
|
319 for (c = Cstring, p = PascalString+1, len = 0; (*c != 0) && (len < 255); c++)
|
|
320 {
|
|
321 if ((*c == '\\') && (c[1] != 0))
|
|
322 {
|
|
323 c++;
|
|
324 }
|
|
325 *p = *c;
|
|
326 p++;
|
|
327 len++;
|
|
328 }
|
|
329 PascalString[0] = len;
|
|
330 }
|
|
331
|
|
332 return PascalString;
|
|
333 }
|
|
334
|
|
335 /*
|
|
336 * Convert the modifiers of an Event into vim's modifiers (mouse)
|
|
337 */
|
|
338
|
|
339 int_u
|
|
340 EventModifiers2VimMouseModifiers(EventModifiers macModifiers)
|
|
341 {
|
|
342 int_u vimModifiers = 0x00;
|
|
343
|
|
344 if (macModifiers & (shiftKey | rightShiftKey))
|
|
345 vimModifiers |= MOUSE_SHIFT;
|
|
346 if (macModifiers & (controlKey | rightControlKey))
|
|
347 vimModifiers |= MOUSE_CTRL;
|
|
348 if (macModifiers & (optionKey | rightOptionKey))
|
|
349 vimModifiers |= MOUSE_ALT;
|
|
350 #if 0
|
|
351 /* Not yet supported */
|
|
352 if (macModifiers & (cmdKey)) /* There's no rightCmdKey */
|
|
353 vimModifiers |= MOUSE_CMD;
|
|
354 #endif
|
|
355 return (vimModifiers);
|
|
356 }
|
|
357
|
|
358 /*
|
|
359 * Convert the modifiers of an Event into vim's modifiers (keys)
|
|
360 */
|
|
361
|
|
362 static int_u
|
|
363 EventModifiers2VimModifiers(EventModifiers macModifiers)
|
|
364 {
|
|
365 int_u vimModifiers = 0x00;
|
|
366
|
|
367 if (macModifiers & (shiftKey | rightShiftKey))
|
|
368 vimModifiers |= MOD_MASK_SHIFT;
|
|
369 if (macModifiers & (controlKey | rightControlKey))
|
|
370 vimModifiers |= MOD_MASK_CTRL;
|
|
371 if (macModifiers & (optionKey | rightOptionKey))
|
|
372 vimModifiers |= MOD_MASK_ALT;
|
|
373 #ifdef USE_CMD_KEY
|
|
374 if (macModifiers & (cmdKey)) /* There's no rightCmdKey */
|
|
375 vimModifiers |= MOD_MASK_CMD;
|
|
376 #endif
|
|
377 return (vimModifiers);
|
|
378 }
|
|
379
|
|
380 /* Convert a string representing a point size into pixels. The string should
|
|
381 * be a positive decimal number, with an optional decimal point (eg, "12", or
|
|
382 * "10.5"). The pixel value is returned, and a pointer to the next unconverted
|
|
383 * character is stored in *end. The flag "vertical" says whether this
|
|
384 * calculation is for a vertical (height) size or a horizontal (width) one.
|
|
385 *
|
|
386 * From gui_w48.c
|
|
387 */
|
|
388 static int
|
|
389 points_to_pixels(char_u *str, char_u **end, int vertical)
|
|
390 {
|
|
391 int pixels;
|
|
392 int points = 0;
|
|
393 int divisor = 0;
|
|
394
|
|
395 while (*str)
|
|
396 {
|
|
397 if (*str == '.' && divisor == 0)
|
|
398 {
|
|
399 /* Start keeping a divisor, for later */
|
|
400 divisor = 1;
|
|
401 continue;
|
|
402 }
|
|
403
|
|
404 if (!isdigit(*str))
|
|
405 break;
|
|
406
|
|
407 points *= 10;
|
|
408 points += *str - '0';
|
|
409 divisor *= 10;
|
|
410
|
|
411 ++str;
|
|
412 }
|
|
413
|
|
414 if (divisor == 0)
|
|
415 divisor = 1;
|
|
416
|
|
417 pixels = points/divisor;
|
|
418 *end = str;
|
|
419 return pixels;
|
|
420 }
|
|
421
|
766
|
422 #ifdef MACOS_CONVERT
|
168
|
423 /*
|
|
424 * Deletes all traces of any Windows-style mnemonic text (including any
|
|
425 * parentheses) from a menu item and returns the cleaned menu item title.
|
|
426 * The caller is responsible for releasing the returned string.
|
|
427 */
|
|
428 static CFStringRef
|
593
|
429 menu_title_removing_mnemonic(vimmenu_T *menu)
|
168
|
430 {
|
|
431 CFStringRef name;
|
|
432 size_t menuTitleLen;
|
|
433 CFIndex displayLen;
|
|
434 CFRange mnemonicStart;
|
|
435 CFRange mnemonicEnd;
|
|
436 CFMutableStringRef cleanedName;
|
|
437
|
|
438 menuTitleLen = STRLEN(menu->dname);
|
|
439 name = mac_enc_to_cfstring(menu->dname, menuTitleLen);
|
|
440
|
|
441 if (name)
|
|
442 {
|
|
443 /* Simple mnemonic-removal algorithm, assumes single parenthesized
|
|
444 * mnemonic character towards the end of the menu text */
|
|
445 mnemonicStart = CFStringFind(name, CFSTR("("), kCFCompareBackwards);
|
|
446 displayLen = CFStringGetLength(name);
|
|
447
|
|
448 if (mnemonicStart.location != kCFNotFound
|
|
449 && (mnemonicStart.location + 2) < displayLen
|
|
450 && CFStringGetCharacterAtIndex(name,
|
|
451 mnemonicStart.location + 1) == (UniChar)menu->mnemonic)
|
|
452 {
|
|
453 if (CFStringFindWithOptions(name, CFSTR(")"),
|
|
454 CFRangeMake(mnemonicStart.location + 1,
|
|
455 displayLen - mnemonicStart.location - 1),
|
|
456 kCFCompareBackwards, &mnemonicEnd) &&
|
|
457 (mnemonicStart.location + 2) == mnemonicEnd.location)
|
|
458 {
|
|
459 cleanedName = CFStringCreateMutableCopy(NULL, 0, name);
|
|
460 if (cleanedName)
|
|
461 {
|
|
462 CFStringDelete(cleanedName,
|
|
463 CFRangeMake(mnemonicStart.location,
|
|
464 mnemonicEnd.location + 1 -
|
|
465 mnemonicStart.location));
|
|
466
|
|
467 CFRelease(name);
|
|
468 name = cleanedName;
|
|
469 }
|
|
470 }
|
|
471 }
|
|
472 }
|
|
473
|
|
474 return name;
|
|
475 }
|
|
476 #endif
|
|
477
|
7
|
478 /*
|
|
479 * Convert a list of FSSpec aliases into a list of fullpathname
|
|
480 * character strings.
|
|
481 */
|
|
482
|
593
|
483 char_u **
|
|
484 new_fnames_from_AEDesc(AEDesc *theList, long *numFiles, OSErr *error)
|
7
|
485 {
|
|
486 char_u **fnames = NULL;
|
|
487 OSErr newError;
|
|
488 long fileCount;
|
|
489 FSSpec fileToOpen;
|
|
490 long actualSize;
|
|
491 AEKeyword dummyKeyword;
|
|
492 DescType dummyType;
|
|
493
|
|
494 /* Get number of files in list */
|
|
495 *error = AECountItems(theList, numFiles);
|
|
496 if (*error)
|
|
497 {
|
|
498 return(fnames);
|
|
499 }
|
|
500
|
|
501 /* Allocate the pointer list */
|
|
502 fnames = (char_u **) alloc(*numFiles * sizeof(char_u *));
|
|
503
|
|
504 /* Empty out the list */
|
|
505 for (fileCount = 0; fileCount < *numFiles; fileCount++)
|
|
506 fnames[fileCount] = NULL;
|
|
507
|
|
508 /* Scan the list of FSSpec */
|
|
509 for (fileCount = 1; fileCount <= *numFiles; fileCount++)
|
|
510 {
|
|
511 /* Get the alias for the nth file, convert to an FSSpec */
|
|
512 newError = AEGetNthPtr(theList, fileCount, typeFSS,
|
|
513 &dummyKeyword, &dummyType,
|
|
514 (Ptr) &fileToOpen, sizeof(FSSpec), &actualSize);
|
|
515 if (newError)
|
|
516 {
|
|
517 /* Caller is able to clean up */
|
|
518 /* TODO: Should be clean up or not? For safety. */
|
|
519 return(fnames);
|
|
520 }
|
|
521
|
|
522 /* Convert the FSSpec to a pathname */
|
9
|
523 fnames[fileCount - 1] = FullPathFromFSSpec_save(fileToOpen);
|
7
|
524 }
|
|
525
|
|
526 return (fnames);
|
|
527 }
|
|
528
|
|
529 /*
|
|
530 * ------------------------------------------------------------
|
|
531 * CodeWarrior External Editor Support
|
|
532 * ------------------------------------------------------------
|
|
533 */
|
|
534 #ifdef FEAT_CW_EDITOR
|
|
535
|
|
536 /*
|
|
537 * Handle the Window Search event from CodeWarrior
|
|
538 *
|
|
539 * Description
|
|
540 * -----------
|
|
541 *
|
|
542 * The IDE sends the Window Search AppleEvent to the editor when it
|
|
543 * needs to know whether a particular file is open in the editor.
|
|
544 *
|
|
545 * Event Reply
|
|
546 * -----------
|
|
547 *
|
|
548 * None. Put data in the location specified in the structure received.
|
|
549 *
|
|
550 * Remarks
|
|
551 * -------
|
|
552 *
|
|
553 * When the editor receives this event, determine whether the specified
|
|
554 * file is open. If it is, return the modification date/time for that file
|
|
555 * in the appropriate location specified in the structure. If the file is
|
9
|
556 * not opened, put the value fnfErr(file not found) in that location.
|
7
|
557 *
|
|
558 */
|
|
559
|
|
560 typedef struct WindowSearch WindowSearch;
|
|
561 struct WindowSearch /* for handling class 'KAHL', event 'SRCH', keyDirectObject typeChar*/
|
|
562 {
|
|
563 FSSpec theFile; // identifies the file
|
|
564 long *theDate; // where to put the modification date/time
|
|
565 };
|
|
566
|
9
|
567 pascal OSErr
|
593
|
568 Handle_KAHL_SRCH_AE(
|
|
569 const AppleEvent *theAEvent,
|
|
570 AppleEvent *theReply,
|
|
571 long refCon)
|
7
|
572 {
|
|
573 OSErr error = noErr;
|
|
574 buf_T *buf;
|
|
575 int foundFile = false;
|
|
576 DescType typeCode;
|
|
577 WindowSearch SearchData;
|
|
578 Size actualSize;
|
|
579
|
|
580 error = AEGetParamPtr(theAEvent, keyDirectObject, typeChar, &typeCode, (Ptr) &SearchData, sizeof(WindowSearch), &actualSize);
|
|
581 if (error)
|
|
582 {
|
|
583 return(error);
|
|
584 }
|
|
585
|
9
|
586 error = HandleUnusedParms(theAEvent);
|
7
|
587 if (error)
|
|
588 {
|
|
589 return(error);
|
|
590 }
|
|
591
|
|
592 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
|
593 if (buf->b_ml.ml_mfp != NULL
|
|
594 && SearchData.theFile.parID == buf->b_FSSpec.parID
|
|
595 && SearchData.theFile.name[0] == buf->b_FSSpec.name[0]
|
|
596 && STRNCMP(SearchData.theFile.name, buf->b_FSSpec.name, buf->b_FSSpec.name[0] + 1) == 0)
|
|
597 {
|
|
598 foundFile = true;
|
|
599 break;
|
|
600 }
|
|
601
|
|
602 if (foundFile == false)
|
|
603 *SearchData.theDate = fnfErr;
|
|
604 else
|
|
605 *SearchData.theDate = buf->b_mtime;
|
|
606
|
|
607 return error;
|
|
608 };
|
|
609
|
|
610 /*
|
|
611 * Handle the Modified (from IDE to Editor) event from CodeWarrior
|
|
612 *
|
|
613 * Description
|
|
614 * -----------
|
|
615 *
|
|
616 * The IDE sends this event to the external editor when it wants to
|
|
617 * know which files that are open in the editor have been modified.
|
|
618 *
|
|
619 * Parameters None.
|
|
620 * ----------
|
|
621 *
|
|
622 * Event Reply
|
|
623 * -----------
|
|
624 * The reply for this event is:
|
|
625 *
|
|
626 * keyDirectObject typeAEList required
|
|
627 * each element in the list is a structure of typeChar
|
|
628 *
|
|
629 * Remarks
|
|
630 * -------
|
|
631 *
|
|
632 * When building the reply event, include one element in the list for
|
|
633 * each open file that has been modified.
|
|
634 *
|
|
635 */
|
|
636
|
|
637 typedef struct ModificationInfo ModificationInfo;
|
|
638 struct ModificationInfo /* for replying to class 'KAHL', event 'MOD ', keyDirectObject typeAEList*/
|
|
639 {
|
|
640 FSSpec theFile; // identifies the file
|
|
641 long theDate; // the date/time the file was last modified
|
|
642 short saved; // set this to zero when replying, unused
|
|
643 };
|
|
644
|
9
|
645 pascal OSErr
|
593
|
646 Handle_KAHL_MOD_AE(
|
|
647 const AppleEvent *theAEvent,
|
|
648 AppleEvent *theReply,
|
|
649 long refCon)
|
7
|
650 {
|
|
651 OSErr error = noErr;
|
|
652 AEDescList replyList;
|
|
653 long numFiles;
|
|
654 ModificationInfo theFile;
|
|
655 buf_T *buf;
|
|
656
|
|
657 theFile.saved = 0;
|
|
658
|
9
|
659 error = HandleUnusedParms(theAEvent);
|
7
|
660 if (error)
|
|
661 {
|
|
662 return(error);
|
|
663 }
|
|
664
|
|
665 /* Send the reply */
|
|
666 /* replyObject.descriptorType = typeNull;
|
|
667 replyObject.dataHandle = nil;*/
|
|
668
|
|
669 /* AECreateDesc(typeChar, (Ptr)&title[1], title[0], &data) */
|
|
670 error = AECreateList(nil, 0, false, &replyList);
|
|
671 if (error)
|
|
672 {
|
|
673 return(error);
|
|
674 }
|
|
675
|
|
676 #if 0
|
|
677 error = AECountItems(&replyList, &numFiles);
|
9
|
678
|
|
679 /* AEPutKeyDesc(&replyList, keyAEPnject, &aDesc)
|
|
680 * AEPutKeyPtr(&replyList, keyAEPosition, typeChar, (Ptr)&theType,
|
7
|
681 * sizeof(DescType))
|
|
682 */
|
|
683
|
|
684 /* AEPutDesc */
|
|
685 #endif
|
|
686
|
|
687 numFiles = 0;
|
|
688 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
|
689 if (buf->b_ml.ml_mfp != NULL)
|
|
690 {
|
|
691 /* Add this file to the list */
|
|
692 theFile.theFile = buf->b_FSSpec;
|
|
693 theFile.theDate = buf->b_mtime;
|
9
|
694 /* theFile.theDate = time(NULL) & (time_t) 0xFFFFFFF0; */
|
|
695 error = AEPutPtr(&replyList, numFiles, typeChar, (Ptr) &theFile, sizeof(theFile));
|
7
|
696 };
|
|
697
|
|
698 #if 0
|
|
699 error = AECountItems(&replyList, &numFiles);
|
|
700 #endif
|
|
701
|
|
702 /* We can add data only if something to reply */
|
9
|
703 error = AEPutParamDesc(theReply, keyDirectObject, &replyList);
|
7
|
704
|
|
705 if (replyList.dataHandle)
|
|
706 AEDisposeDesc(&replyList);
|
|
707
|
|
708 return error;
|
|
709 };
|
|
710
|
|
711 /*
|
|
712 * Handle the Get Text event from CodeWarrior
|
|
713 *
|
|
714 * Description
|
|
715 * -----------
|
|
716 *
|
|
717 * The IDE sends the Get Text AppleEvent to the editor when it needs
|
|
718 * the source code from a file. For example, when the user issues a
|
|
719 * Check Syntax or Compile command, the compiler needs access to
|
|
720 * the source code contained in the file.
|
|
721 *
|
|
722 * Event Reply
|
|
723 * -----------
|
|
724 *
|
|
725 * None. Put data in locations specified in the structure received.
|
|
726 *
|
|
727 * Remarks
|
|
728 * -------
|
|
729 *
|
|
730 * When the editor receives this event, it must set the size of the handle
|
|
731 * in theText to fit the data in the file. It must then copy the entire
|
|
732 * contents of the specified file into the memory location specified in
|
|
733 * theText.
|
|
734 *
|
|
735 */
|
|
736
|
|
737 typedef struct CW_GetText CW_GetText;
|
|
738 struct CW_GetText /* for handling class 'KAHL', event 'GTTX', keyDirectObject typeChar*/
|
|
739 {
|
|
740 FSSpec theFile; /* identifies the file */
|
|
741 Handle theText; /* the location where you return the text (must be resized properly) */
|
|
742 long *unused; /* 0 (not used) */
|
|
743 long *theDate; /* where to put the modification date/time */
|
|
744 };
|
|
745
|
9
|
746 pascal OSErr
|
593
|
747 Handle_KAHL_GTTX_AE(
|
|
748 const AppleEvent *theAEvent,
|
|
749 AppleEvent *theReply,
|
|
750 long refCon)
|
7
|
751 {
|
|
752 OSErr error = noErr;
|
|
753 buf_T *buf;
|
|
754 int foundFile = false;
|
|
755 DescType typeCode;
|
|
756 CW_GetText GetTextData;
|
|
757 Size actualSize;
|
|
758 char_u *line;
|
|
759 char_u *fullbuffer = NULL;
|
|
760 long linesize;
|
|
761 long lineStart;
|
|
762 long BufferSize;
|
|
763 long lineno;
|
|
764
|
|
765 error = AEGetParamPtr(theAEvent, keyDirectObject, typeChar, &typeCode, (Ptr) &GetTextData, sizeof(GetTextData), &actualSize);
|
|
766
|
|
767 if (error)
|
|
768 {
|
|
769 return(error);
|
|
770 }
|
|
771
|
|
772 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
|
773 if (buf->b_ml.ml_mfp != NULL)
|
|
774 if (GetTextData.theFile.parID == buf->b_FSSpec.parID)
|
|
775 {
|
|
776 foundFile = true;
|
|
777 break;
|
|
778 }
|
|
779
|
|
780 if (foundFile)
|
|
781 {
|
9
|
782 BufferSize = 0; /* GetHandleSize(GetTextData.theText); */
|
7
|
783 for (lineno = 0; lineno <= buf->b_ml.ml_line_count; lineno++)
|
|
784 {
|
|
785 /* Must use the right buffer */
|
|
786 line = ml_get_buf(buf, (linenr_T) lineno, FALSE);
|
|
787 linesize = STRLEN(line) + 1;
|
|
788 lineStart = BufferSize;
|
|
789 BufferSize += linesize;
|
|
790 /* Resize handle to linesize+1 to include the linefeed */
|
9
|
791 SetHandleSize(GetTextData.theText, BufferSize);
|
|
792 if (GetHandleSize(GetTextData.theText) != BufferSize)
|
7
|
793 {
|
|
794 break; /* Simple handling for now */
|
|
795 }
|
|
796 else
|
|
797 {
|
9
|
798 HLock(GetTextData.theText);
|
7
|
799 fullbuffer = (char_u *) *GetTextData.theText;
|
9
|
800 STRCPY((char_u *)(fullbuffer + lineStart), line);
|
7
|
801 fullbuffer[BufferSize-1] = '\r';
|
9
|
802 HUnlock(GetTextData.theText);
|
7
|
803 }
|
|
804 }
|
|
805 if (fullbuffer != NULL)
|
|
806 {
|
9
|
807 HLock(GetTextData.theText);
|
7
|
808 fullbuffer[BufferSize-1] = 0;
|
9
|
809 HUnlock(GetTextData.theText);
|
7
|
810 }
|
|
811 if (foundFile == false)
|
|
812 *GetTextData.theDate = fnfErr;
|
|
813 else
|
9
|
814 /* *GetTextData.theDate = time(NULL) & (time_t) 0xFFFFFFF0;*/
|
7
|
815 *GetTextData.theDate = buf->b_mtime;
|
|
816 }
|
9
|
817
|
|
818 error = HandleUnusedParms(theAEvent);
|
7
|
819 if (error)
|
|
820 {
|
|
821 return(error);
|
|
822 }
|
|
823
|
|
824 return(error);
|
|
825 }
|
|
826
|
|
827 /*
|
|
828 *
|
|
829 */
|
|
830
|
|
831 /* Taken from MoreAppleEvents:ProcessHelpers*/
|
593
|
832 pascal OSErr
|
|
833 FindProcessBySignature(
|
|
834 const OSType targetType,
|
|
835 const OSType targetCreator,
|
|
836 ProcessSerialNumberPtr psnPtr)
|
7
|
837 {
|
|
838 OSErr anErr = noErr;
|
|
839 Boolean lookingForProcess = true;
|
|
840
|
|
841 ProcessInfoRec infoRec;
|
|
842
|
9
|
843 infoRec.processInfoLength = sizeof(ProcessInfoRec);
|
7
|
844 infoRec.processName = nil;
|
|
845 infoRec.processAppSpec = nil;
|
|
846
|
|
847 psnPtr->lowLongOfPSN = kNoProcess;
|
|
848 psnPtr->highLongOfPSN = kNoProcess;
|
|
849
|
9
|
850 while (lookingForProcess)
|
7
|
851 {
|
9
|
852 anErr = GetNextProcess(psnPtr);
|
|
853 if (anErr != noErr)
|
7
|
854 lookingForProcess = false;
|
|
855 else
|
|
856 {
|
9
|
857 anErr = GetProcessInformation(psnPtr, &infoRec);
|
|
858 if ((anErr == noErr)
|
|
859 && (infoRec.processType == targetType)
|
|
860 && (infoRec.processSignature == targetCreator))
|
7
|
861 lookingForProcess = false;
|
|
862 }
|
|
863 }
|
|
864
|
|
865 return anErr;
|
|
866 }//end FindProcessBySignature
|
|
867
|
9
|
868 void
|
|
869 Send_KAHL_MOD_AE(buf_T *buf)
|
7
|
870 {
|
9
|
871 OSErr anErr = noErr;
|
|
872 AEDesc targetAppDesc = { typeNull, nil };
|
7
|
873 ProcessSerialNumber psn = { kNoProcess, kNoProcess };
|
|
874 AppleEvent theReply = { typeNull, nil };
|
|
875 AESendMode sendMode;
|
|
876 AppleEvent theEvent = {typeNull, nil };
|
|
877 AEIdleUPP idleProcUPP = nil;
|
|
878 ModificationInfo ModData;
|
|
879
|
|
880
|
9
|
881 anErr = FindProcessBySignature('APPL', 'CWIE', &psn);
|
|
882 if (anErr == noErr)
|
7
|
883 {
|
9
|
884 anErr = AECreateDesc(typeProcessSerialNumber, &psn,
|
|
885 sizeof(ProcessSerialNumber), &targetAppDesc);
|
|
886
|
|
887 if (anErr == noErr)
|
7
|
888 {
|
|
889 anErr = AECreateAppleEvent( 'KAHL', 'MOD ', &targetAppDesc,
|
|
890 kAutoGenerateReturnID, kAnyTransactionID, &theEvent);
|
|
891 }
|
|
892
|
9
|
893 AEDisposeDesc(&targetAppDesc);
|
7
|
894
|
|
895 /* Add the parms */
|
|
896 ModData.theFile = buf->b_FSSpec;
|
|
897 ModData.theDate = buf->b_mtime;
|
|
898
|
|
899 if (anErr == noErr)
|
9
|
900 anErr = AEPutParamPtr(&theEvent, keyDirectObject, typeChar, &ModData, sizeof(ModData));
|
|
901
|
|
902 if (idleProcUPP == nil)
|
7
|
903 sendMode = kAENoReply;
|
|
904 else
|
|
905 sendMode = kAEWaitReply;
|
|
906
|
9
|
907 if (anErr == noErr)
|
|
908 anErr = AESend(&theEvent, &theReply, sendMode, kAENormalPriority, kNoTimeOut, idleProcUPP, nil);
|
|
909 if (anErr == noErr && sendMode == kAEWaitReply)
|
7
|
910 {
|
9
|
911 /* anErr = AEHGetHandlerError(&theReply);*/
|
7
|
912 }
|
9
|
913 (void) AEDisposeDesc(&theReply);
|
7
|
914 }
|
|
915 }
|
|
916 #endif /* FEAT_CW_EDITOR */
|
|
917
|
|
918 /*
|
|
919 * ------------------------------------------------------------
|
|
920 * Apple Event Handling procedure
|
|
921 * ------------------------------------------------------------
|
|
922 */
|
|
923 #ifdef USE_AEVENT
|
|
924
|
|
925 /*
|
|
926 * Handle the Unused parms of an AppleEvent
|
|
927 */
|
|
928
|
9
|
929 OSErr
|
|
930 HandleUnusedParms(const AppleEvent *theAEvent)
|
7
|
931 {
|
|
932 OSErr error;
|
|
933 long actualSize;
|
|
934 DescType dummyType;
|
|
935 AEKeyword missedKeyword;
|
|
936
|
|
937 /* Get the "missed keyword" attribute from the AppleEvent. */
|
|
938 error = AEGetAttributePtr(theAEvent, keyMissedKeywordAttr,
|
|
939 typeKeyword, &dummyType,
|
|
940 (Ptr)&missedKeyword, sizeof(missedKeyword),
|
|
941 &actualSize);
|
|
942
|
|
943 /* If the descriptor isn't found, then we got the required parameters. */
|
|
944 if (error == errAEDescNotFound)
|
|
945 {
|
|
946 error = noErr;
|
|
947 }
|
|
948 else
|
|
949 {
|
|
950 #if 0
|
|
951 /* Why is this removed? */
|
|
952 error = errAEEventNotHandled;
|
|
953 #endif
|
|
954 }
|
|
955
|
|
956 return error;
|
|
957 }
|
|
958
|
|
959
|
|
960 /*
|
|
961 * Handle the ODoc AppleEvent
|
|
962 *
|
|
963 * Deals with all files dragged to the application icon.
|
|
964 *
|
|
965 */
|
|
966
|
|
967 typedef struct SelectionRange SelectionRange;
|
|
968 struct SelectionRange /* for handling kCoreClassEvent:kOpenDocuments:keyAEPosition typeChar */
|
|
969 {
|
|
970 short unused1; // 0 (not used)
|
|
971 short lineNum; // line to select (<0 to specify range)
|
|
972 long startRange; // start of selection range (if line < 0)
|
|
973 long endRange; // end of selection range (if line < 0)
|
|
974 long unused2; // 0 (not used)
|
|
975 long theDate; // modification date/time
|
|
976 };
|
|
977
|
|
978 /* The IDE uses the optional keyAEPosition parameter to tell the ed-
|
|
979 itor the selection range. If lineNum is zero or greater, scroll the text
|
|
980 to the specified line. If lineNum is less than zero, use the values in
|
|
981 startRange and endRange to select the specified characters. Scroll
|
|
982 the text to display the selection. If lineNum, startRange, and
|
|
983 endRange are all negative, there is no selection range specified.
|
|
984 */
|
|
985
|
9
|
986 pascal OSErr
|
|
987 HandleODocAE(const AppleEvent *theAEvent, AppleEvent *theReply, long refCon)
|
7
|
988 {
|
|
989 /*
|
|
990 * TODO: Clean up the code with convert the AppleEvent into
|
|
991 * a ":args"
|
|
992 */
|
|
993 OSErr error = noErr;
|
|
994 // OSErr firstError = noErr;
|
|
995 // short numErrors = 0;
|
|
996 AEDesc theList;
|
|
997 DescType typeCode;
|
|
998 long numFiles;
|
|
999 // long fileCount;
|
|
1000 char_u **fnames;
|
|
1001 // char_u fname[256];
|
|
1002 Size actualSize;
|
|
1003 SelectionRange thePosition;
|
|
1004 short gotPosition = false;
|
|
1005 long lnum;
|
|
1006
|
|
1007 /* the direct object parameter is the list of aliases to files (one or more) */
|
|
1008 error = AEGetParamDesc(theAEvent, keyDirectObject, typeAEList, &theList);
|
|
1009 if (error)
|
|
1010 {
|
|
1011 return(error);
|
|
1012 }
|
|
1013
|
|
1014
|
|
1015 error = AEGetParamPtr(theAEvent, keyAEPosition, typeChar, &typeCode, (Ptr) &thePosition, sizeof(SelectionRange), &actualSize);
|
|
1016 if (error == noErr)
|
|
1017 gotPosition = true;
|
|
1018 if (error == errAEDescNotFound)
|
|
1019 error = noErr;
|
|
1020 if (error)
|
|
1021 {
|
|
1022 return(error);
|
|
1023 }
|
|
1024
|
|
1025 /*
|
|
1026 error = AEGetParamDesc(theAEvent, keyAEPosition, typeChar, &thePosition);
|
|
1027
|
|
1028 if (^error) then
|
|
1029 {
|
|
1030 if (thePosition.lineNum >= 0)
|
|
1031 {
|
|
1032 // Goto this line
|
|
1033 }
|
|
1034 else
|
|
1035 {
|
|
1036 // Set the range char wise
|
|
1037 }
|
|
1038 }
|
|
1039 */
|
|
1040
|
|
1041
|
|
1042 #ifdef FEAT_VISUAL
|
|
1043 reset_VIsual();
|
|
1044 #endif
|
|
1045
|
|
1046 fnames = new_fnames_from_AEDesc(&theList, &numFiles, &error);
|
|
1047
|
|
1048 if (error)
|
|
1049 {
|
|
1050 /* TODO: empty fnames[] first */
|
|
1051 vim_free(fnames);
|
|
1052 return (error);
|
|
1053 }
|
|
1054
|
|
1055 if (starting > 0)
|
|
1056 {
|
|
1057 int i;
|
|
1058 char_u *p;
|
|
1059
|
|
1060 /* these are the initial files dropped on the Vim icon */
|
|
1061 for (i = 0 ; i < numFiles; i++)
|
|
1062 {
|
|
1063 if (ga_grow(&global_alist.al_ga, 1) == FAIL
|
|
1064 || (p = vim_strsave(fnames[i])) == NULL)
|
|
1065 mch_exit(2);
|
|
1066 else
|
|
1067 alist_add(&global_alist, p, 2);
|
|
1068 }
|
816
|
1069
|
|
1070 /* Change directory to the location of the first file. */
|
|
1071 if (GARGCOUNT > 0 && vim_chdirfile(alist_name(&GARGLIST[0])) == OK)
|
|
1072 shorten_fnames(TRUE);
|
|
1073
|
7
|
1074 goto finished;
|
|
1075 }
|
|
1076
|
|
1077 /* Handle the drop, :edit to get to the file */
|
|
1078 handle_drop(numFiles, fnames, FALSE);
|
|
1079
|
|
1080 /* TODO: Handle the goto/select line more cleanly */
|
|
1081 if ((numFiles == 1) & (gotPosition))
|
|
1082 {
|
|
1083 if (thePosition.lineNum >= 0)
|
|
1084 {
|
37
|
1085 lnum = thePosition.lineNum + 1;
|
7
|
1086 /* oap->motion_type = MLINE;
|
|
1087 setpcmark();*/
|
|
1088 if (lnum < 1L)
|
|
1089 lnum = 1L;
|
|
1090 else if (lnum > curbuf->b_ml.ml_line_count)
|
|
1091 lnum = curbuf->b_ml.ml_line_count;
|
|
1092 curwin->w_cursor.lnum = lnum;
|
37
|
1093 curwin->w_cursor.col = 0;
|
7
|
1094 /* beginline(BL_SOL | BL_FIX);*/
|
|
1095 }
|
|
1096 else
|
|
1097 goto_byte(thePosition.startRange + 1);
|
|
1098 }
|
|
1099
|
|
1100 /* Update the screen display */
|
|
1101 update_screen(NOT_VALID);
|
37
|
1102 #ifdef FEAT_VISUAL
|
|
1103 /* Select the text if possible */
|
|
1104 if (gotPosition)
|
|
1105 {
|
168
|
1106 VIsual_active = TRUE;
|
|
1107 VIsual_select = FALSE;
|
|
1108 VIsual = curwin->w_cursor;
|
|
1109 if (thePosition.lineNum < 0)
|
37
|
1110 {
|
168
|
1111 VIsual_mode = 'v';
|
|
1112 goto_byte(thePosition.endRange);
|
|
1113 }
|
|
1114 else
|
37
|
1115 {
|
168
|
1116 VIsual_mode = 'V';
|
|
1117 VIsual.col = 0;
|
|
1118 }
|
37
|
1119 }
|
|
1120 #endif
|
7
|
1121 setcursor();
|
|
1122 out_flush();
|
|
1123
|
37
|
1124 /* Fake mouse event to wake from stall */
|
|
1125 PostEvent(mouseUp, 0);
|
|
1126
|
7
|
1127 finished:
|
|
1128 AEDisposeDesc(&theList); /* dispose what we allocated */
|
|
1129
|
9
|
1130 error = HandleUnusedParms(theAEvent);
|
7
|
1131 if (error)
|
|
1132 {
|
|
1133 return(error);
|
|
1134 }
|
|
1135 return(error);
|
|
1136 }
|
|
1137
|
|
1138 /*
|
|
1139 *
|
|
1140 */
|
|
1141
|
9
|
1142 pascal OSErr
|
593
|
1143 Handle_aevt_oapp_AE(
|
|
1144 const AppleEvent *theAEvent,
|
|
1145 AppleEvent *theReply,
|
|
1146 long refCon)
|
7
|
1147 {
|
|
1148 OSErr error = noErr;
|
|
1149
|
9
|
1150 error = HandleUnusedParms(theAEvent);
|
7
|
1151 if (error)
|
|
1152 {
|
|
1153 return(error);
|
|
1154 }
|
|
1155
|
|
1156 return(error);
|
|
1157 }
|
|
1158
|
|
1159 /*
|
|
1160 *
|
|
1161 */
|
|
1162
|
9
|
1163 pascal OSErr
|
593
|
1164 Handle_aevt_quit_AE(
|
|
1165 const AppleEvent *theAEvent,
|
|
1166 AppleEvent *theReply,
|
|
1167 long refCon)
|
7
|
1168 {
|
|
1169 OSErr error = noErr;
|
|
1170
|
9
|
1171 error = HandleUnusedParms(theAEvent);
|
7
|
1172 if (error)
|
|
1173 {
|
|
1174 return(error);
|
|
1175 }
|
|
1176
|
|
1177 /* Need to fake a :confirm qa */
|
|
1178 do_cmdline_cmd((char_u *)"confirm qa");
|
|
1179
|
|
1180 return(error);
|
|
1181 }
|
|
1182
|
|
1183 /*
|
|
1184 *
|
|
1185 */
|
|
1186
|
9
|
1187 pascal OSErr
|
593
|
1188 Handle_aevt_pdoc_AE(
|
|
1189 const AppleEvent *theAEvent,
|
|
1190 AppleEvent *theReply,
|
|
1191 long refCon)
|
7
|
1192 {
|
|
1193 OSErr error = noErr;
|
|
1194
|
9
|
1195 error = HandleUnusedParms(theAEvent);
|
7
|
1196 if (error)
|
|
1197 {
|
|
1198 return(error);
|
|
1199 }
|
|
1200
|
|
1201 return(error);
|
|
1202 }
|
|
1203
|
|
1204 /*
|
|
1205 * Handling of unknown AppleEvent
|
|
1206 *
|
|
1207 * (Just get rid of all the parms)
|
|
1208 */
|
9
|
1209 pascal OSErr
|
593
|
1210 Handle_unknown_AE(
|
|
1211 const AppleEvent *theAEvent,
|
|
1212 AppleEvent *theReply,
|
|
1213 long refCon)
|
7
|
1214 {
|
|
1215 OSErr error = noErr;
|
|
1216
|
9
|
1217 error = HandleUnusedParms(theAEvent);
|
7
|
1218 if (error)
|
|
1219 {
|
|
1220 return(error);
|
|
1221 }
|
|
1222
|
|
1223 return(error);
|
|
1224 }
|
|
1225
|
|
1226
|
|
1227 /*
|
|
1228 * Install the various AppleEvent Handlers
|
|
1229 */
|
9
|
1230 OSErr
|
|
1231 InstallAEHandlers(void)
|
7
|
1232 {
|
|
1233 OSErr error;
|
|
1234
|
|
1235 /* install open application handler */
|
|
1236 error = AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
|
593
|
1237 NewAEEventHandlerUPP(Handle_aevt_oapp_AE), 0, false);
|
7
|
1238 if (error)
|
|
1239 {
|
|
1240 return error;
|
|
1241 }
|
|
1242
|
|
1243 /* install quit application handler */
|
|
1244 error = AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
|
593
|
1245 NewAEEventHandlerUPP(Handle_aevt_quit_AE), 0, false);
|
7
|
1246 if (error)
|
|
1247 {
|
|
1248 return error;
|
|
1249 }
|
|
1250
|
|
1251 /* install open document handler */
|
|
1252 error = AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
|
593
|
1253 NewAEEventHandlerUPP(HandleODocAE), 0, false);
|
7
|
1254 if (error)
|
|
1255 {
|
|
1256 return error;
|
|
1257 }
|
|
1258
|
|
1259 /* install print document handler */
|
|
1260 error = AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
|
593
|
1261 NewAEEventHandlerUPP(Handle_aevt_pdoc_AE), 0, false);
|
7
|
1262
|
|
1263 /* Install Core Suite */
|
|
1264 /* error = AEInstallEventHandler(kAECoreSuite, kAEClone,
|
593
|
1265 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1266
|
|
1267 error = AEInstallEventHandler(kAECoreSuite, kAEClose,
|
593
|
1268 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1269
|
|
1270 error = AEInstallEventHandler(kAECoreSuite, kAECountElements,
|
593
|
1271 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1272
|
|
1273 error = AEInstallEventHandler(kAECoreSuite, kAECreateElement,
|
593
|
1274 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1275
|
|
1276 error = AEInstallEventHandler(kAECoreSuite, kAEDelete,
|
593
|
1277 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1278
|
|
1279 error = AEInstallEventHandler(kAECoreSuite, kAEDoObjectsExist,
|
593
|
1280 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1281
|
|
1282 error = AEInstallEventHandler(kAECoreSuite, kAEGetData,
|
593
|
1283 NewAEEventHandlerUPP(Handle_unknown_AE), kAEGetData, false);
|
7
|
1284
|
|
1285 error = AEInstallEventHandler(kAECoreSuite, kAEGetDataSize,
|
593
|
1286 NewAEEventHandlerUPP(Handle_unknown_AE), kAEGetDataSize, false);
|
7
|
1287
|
|
1288 error = AEInstallEventHandler(kAECoreSuite, kAEGetClassInfo,
|
593
|
1289 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1290
|
|
1291 error = AEInstallEventHandler(kAECoreSuite, kAEGetEventInfo,
|
593
|
1292 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1293
|
|
1294 error = AEInstallEventHandler(kAECoreSuite, kAEMove,
|
593
|
1295 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1296
|
|
1297 error = AEInstallEventHandler(kAECoreSuite, kAESave,
|
593
|
1298 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1299
|
|
1300 error = AEInstallEventHandler(kAECoreSuite, kAESetData,
|
593
|
1301 NewAEEventHandlerUPP(Handle_unknown_AE), nil, false);
|
7
|
1302 */
|
|
1303
|
|
1304 #ifdef FEAT_CW_EDITOR
|
|
1305 /*
|
|
1306 * Bind codewarrior support handlers
|
|
1307 */
|
|
1308 error = AEInstallEventHandler('KAHL', 'GTTX',
|
593
|
1309 NewAEEventHandlerUPP(Handle_KAHL_GTTX_AE), 0, false);
|
7
|
1310 if (error)
|
|
1311 {
|
|
1312 return error;
|
|
1313 }
|
|
1314 error = AEInstallEventHandler('KAHL', 'SRCH',
|
593
|
1315 NewAEEventHandlerUPP(Handle_KAHL_SRCH_AE), 0, false);
|
7
|
1316 if (error)
|
|
1317 {
|
|
1318 return error;
|
|
1319 }
|
|
1320 error = AEInstallEventHandler('KAHL', 'MOD ',
|
593
|
1321 NewAEEventHandlerUPP(Handle_KAHL_MOD_AE), 0, false);
|
7
|
1322 if (error)
|
|
1323 {
|
|
1324 return error;
|
|
1325 }
|
|
1326 #endif
|
|
1327
|
|
1328 return error;
|
|
1329
|
|
1330 }
|
|
1331 #endif /* USE_AEVENT */
|
|
1332
|
13
|
1333
|
|
1334 /*
|
|
1335 * Callback function, installed by InstallFontPanelHandler(), below,
|
|
1336 * to handle Font Panel events.
|
|
1337 */
|
|
1338 static OSStatus
|
593
|
1339 FontPanelHandler(
|
|
1340 EventHandlerCallRef inHandlerCallRef,
|
|
1341 EventRef inEvent,
|
|
1342 void *inUserData)
|
13
|
1343 {
|
|
1344 if (GetEventKind(inEvent) == kEventFontPanelClosed)
|
|
1345 {
|
|
1346 gFontPanelInfo.isPanelVisible = false;
|
|
1347 return noErr;
|
|
1348 }
|
|
1349
|
|
1350 if (GetEventKind(inEvent) == kEventFontSelection)
|
|
1351 {
|
|
1352 OSStatus status;
|
|
1353 FMFontFamily newFamily;
|
|
1354 FMFontSize newSize;
|
|
1355 FMFontStyle newStyle;
|
|
1356
|
|
1357 /* Retrieve the font family ID number. */
|
|
1358 status = GetEventParameter(inEvent, kEventParamFMFontFamily,
|
|
1359 /*inDesiredType=*/typeFMFontFamily, /*outActualType=*/NULL,
|
|
1360 /*inBufferSize=*/sizeof(FMFontFamily), /*outActualSize=*/NULL,
|
|
1361 &newFamily);
|
|
1362 if (status == noErr)
|
|
1363 gFontPanelInfo.family = newFamily;
|
|
1364
|
|
1365 /* Retrieve the font size. */
|
|
1366 status = GetEventParameter(inEvent, kEventParamFMFontSize,
|
|
1367 typeFMFontSize, NULL, sizeof(FMFontSize), NULL, &newSize);
|
|
1368 if (status == noErr)
|
|
1369 gFontPanelInfo.size = newSize;
|
|
1370
|
|
1371 /* Retrieve the font style (bold, etc.). Currently unused. */
|
|
1372 status = GetEventParameter(inEvent, kEventParamFMFontStyle,
|
|
1373 typeFMFontStyle, NULL, sizeof(FMFontStyle), NULL, &newStyle);
|
|
1374 if (status == noErr)
|
|
1375 gFontPanelInfo.style = newStyle;
|
|
1376 }
|
|
1377 return noErr;
|
|
1378 }
|
|
1379
|
|
1380
|
|
1381 static void
|
593
|
1382 InstallFontPanelHandler(void)
|
13
|
1383 {
|
|
1384 EventTypeSpec eventTypes[2];
|
|
1385 EventHandlerUPP handlerUPP;
|
|
1386 /* EventHandlerRef handlerRef; */
|
|
1387
|
|
1388 eventTypes[0].eventClass = kEventClassFont;
|
|
1389 eventTypes[0].eventKind = kEventFontSelection;
|
|
1390 eventTypes[1].eventClass = kEventClassFont;
|
|
1391 eventTypes[1].eventKind = kEventFontPanelClosed;
|
|
1392
|
|
1393 handlerUPP = NewEventHandlerUPP(FontPanelHandler);
|
|
1394
|
|
1395 InstallApplicationEventHandler(handlerUPP, /*numTypes=*/2, eventTypes,
|
|
1396 /*userData=*/NULL, /*handlerRef=*/NULL);
|
|
1397 }
|
|
1398
|
|
1399
|
|
1400 /*
|
|
1401 * Fill the buffer pointed to by outName with the name and size
|
|
1402 * of the font currently selected in the Font Panel.
|
|
1403 */
|
168
|
1404 #define FONT_STYLE_BUFFER_SIZE 32
|
13
|
1405 static void
|
501
|
1406 GetFontPanelSelection(char_u *outName)
|
13
|
1407 {
|
168
|
1408 Str255 buf;
|
|
1409 ByteCount fontNameLen = 0;
|
|
1410 ATSUFontID fid;
|
|
1411 char_u styleString[FONT_STYLE_BUFFER_SIZE];
|
13
|
1412
|
|
1413 if (!outName)
|
|
1414 return;
|
|
1415
|
168
|
1416 if (FMGetFontFamilyName(gFontPanelInfo.family, buf) == noErr)
|
|
1417 {
|
|
1418 /* Canonicalize localized font names */
|
|
1419 if (FMGetFontFromFontFamilyInstance(gFontPanelInfo.family,
|
|
1420 gFontPanelInfo.style, &fid, NULL) != noErr)
|
|
1421 return;
|
|
1422
|
|
1423 /* Request font name with Mac encoding (otherwise we could
|
|
1424 * get an unwanted utf-16 name) */
|
|
1425 if (ATSUFindFontName(fid, kFontFullName, kFontMacintoshPlatform,
|
|
1426 kFontNoScriptCode, kFontNoLanguageCode,
|
501
|
1427 255, (char *)outName, &fontNameLen, NULL) != noErr)
|
168
|
1428 return;
|
|
1429
|
|
1430 /* Only encode font size, because style (bold, italic, etc) is
|
|
1431 * already part of the font full name */
|
501
|
1432 vim_snprintf((char *)styleString, FONT_STYLE_BUFFER_SIZE, ":h%d",
|
168
|
1433 gFontPanelInfo.size/*,
|
|
1434 ((gFontPanelInfo.style & bold)!=0 ? ":b" : ""),
|
|
1435 ((gFontPanelInfo.style & italic)!=0 ? ":i" : ""),
|
|
1436 ((gFontPanelInfo.style & underline)!=0 ? ":u" : "")*/);
|
|
1437
|
|
1438 if ((fontNameLen + STRLEN(styleString)) < 255)
|
|
1439 STRCPY(outName + fontNameLen, styleString);
|
|
1440 }
|
|
1441 else
|
|
1442 {
|
501
|
1443 *outName = NUL;
|
168
|
1444 }
|
13
|
1445 }
|
|
1446
|
|
1447
|
7
|
1448 /*
|
|
1449 * ------------------------------------------------------------
|
|
1450 * Unfiled yet
|
|
1451 * ------------------------------------------------------------
|
|
1452 */
|
|
1453
|
|
1454 /*
|
|
1455 * gui_mac_get_menu_item_index
|
|
1456 *
|
|
1457 * Returns the index inside the menu wher
|
|
1458 */
|
|
1459 short /* Shoulde we return MenuItemIndex? */
|
593
|
1460 gui_mac_get_menu_item_index(vimmenu_T *pMenu)
|
7
|
1461 {
|
|
1462 short index;
|
|
1463 short itemIndex = -1;
|
|
1464 vimmenu_T *pBrother;
|
|
1465
|
|
1466 /* Only menu without parent are the:
|
|
1467 * -menu in the menubar
|
|
1468 * -popup menu
|
|
1469 * -toolbar (guess)
|
|
1470 *
|
|
1471 * Which are not items anyway.
|
|
1472 */
|
|
1473 if (pMenu->parent)
|
|
1474 {
|
|
1475 /* Start from the Oldest Brother */
|
|
1476 pBrother = pMenu->parent->children;
|
|
1477 index = 1;
|
|
1478 while ((pBrother) && (itemIndex == -1))
|
|
1479 {
|
|
1480 if (pBrother == pMenu)
|
|
1481 itemIndex = index;
|
|
1482 index++;
|
|
1483 pBrother = pBrother->next;
|
|
1484 }
|
|
1485 }
|
|
1486 return itemIndex;
|
|
1487 }
|
|
1488
|
|
1489 static vimmenu_T *
|
593
|
1490 gui_mac_get_vim_menu(short menuID, short itemIndex, vimmenu_T *pMenu)
|
7
|
1491 {
|
|
1492 short index;
|
|
1493 vimmenu_T *pChildMenu;
|
|
1494 vimmenu_T *pElder = pMenu->parent;
|
|
1495
|
|
1496
|
|
1497 /* Only menu without parent are the:
|
|
1498 * -menu in the menubar
|
|
1499 * -popup menu
|
|
1500 * -toolbar (guess)
|
|
1501 *
|
|
1502 * Which are not items anyway.
|
|
1503 */
|
|
1504
|
|
1505 if ((pElder) && (pElder->submenu_id == menuID))
|
|
1506 {
|
|
1507 for (index = 1; (index != itemIndex) && (pMenu != NULL); index++)
|
|
1508 pMenu = pMenu->next;
|
|
1509 }
|
|
1510 else
|
|
1511 {
|
|
1512 for (; pMenu != NULL; pMenu = pMenu->next)
|
|
1513 {
|
|
1514 if (pMenu->children != NULL)
|
|
1515 {
|
|
1516 pChildMenu = gui_mac_get_vim_menu
|
|
1517 (menuID, itemIndex, pMenu->children);
|
|
1518 if (pChildMenu)
|
|
1519 {
|
|
1520 pMenu = pChildMenu;
|
|
1521 break;
|
|
1522 }
|
|
1523 }
|
|
1524 }
|
|
1525 }
|
|
1526 return pMenu;
|
|
1527 }
|
|
1528
|
|
1529 /*
|
|
1530 * ------------------------------------------------------------
|
|
1531 * MacOS Feedback procedures
|
|
1532 * ------------------------------------------------------------
|
|
1533 */
|
|
1534 pascal
|
|
1535 void
|
9
|
1536 gui_mac_drag_thumb(ControlHandle theControl, short partCode)
|
7
|
1537 {
|
|
1538 scrollbar_T *sb;
|
|
1539 int value, dragging;
|
|
1540 ControlHandle theControlToUse;
|
|
1541 int dont_scroll_save = dont_scroll;
|
|
1542
|
|
1543 theControlToUse = dragged_sb;
|
|
1544
|
9
|
1545 sb = gui_find_scrollbar((long) GetControlReference(theControlToUse));
|
7
|
1546
|
|
1547 if (sb == NULL)
|
|
1548 return;
|
|
1549
|
|
1550 /* Need to find value by diff between Old Poss New Pos */
|
9
|
1551 value = GetControl32BitValue(theControlToUse);
|
7
|
1552 dragging = (partCode != 0);
|
|
1553
|
|
1554 /* When "allow_scrollbar" is FALSE still need to remember the new
|
|
1555 * position, but don't actually scroll by setting "dont_scroll". */
|
|
1556 dont_scroll = !allow_scrollbar;
|
|
1557 gui_drag_scrollbar(sb, value, dragging);
|
|
1558 dont_scroll = dont_scroll_save;
|
|
1559 }
|
|
1560
|
|
1561 pascal
|
|
1562 void
|
9
|
1563 gui_mac_scroll_action(ControlHandle theControl, short partCode)
|
7
|
1564 {
|
|
1565 /* TODO: have live support */
|
|
1566 scrollbar_T *sb, *sb_info;
|
|
1567 long data;
|
|
1568 long value;
|
|
1569 int page;
|
|
1570 int dragging = FALSE;
|
|
1571 int dont_scroll_save = dont_scroll;
|
|
1572
|
9
|
1573 sb = gui_find_scrollbar((long)GetControlReference(theControl));
|
7
|
1574
|
|
1575 if (sb == NULL)
|
|
1576 return;
|
|
1577
|
|
1578 if (sb->wp != NULL) /* Left or right scrollbar */
|
|
1579 {
|
|
1580 /*
|
|
1581 * Careful: need to get scrollbar info out of first (left) scrollbar
|
|
1582 * for window, but keep real scrollbar too because we must pass it to
|
|
1583 * gui_drag_scrollbar().
|
|
1584 */
|
|
1585 sb_info = &sb->wp->w_scrollbars[0];
|
|
1586
|
|
1587 if (sb_info->size > 5)
|
|
1588 page = sb_info->size - 2; /* use two lines of context */
|
|
1589 else
|
|
1590 page = sb_info->size;
|
|
1591 }
|
|
1592 else /* Bottom scrollbar */
|
|
1593 {
|
|
1594 sb_info = sb;
|
|
1595 page = W_WIDTH(curwin) - 5;
|
|
1596 }
|
|
1597
|
|
1598 switch (partCode)
|
|
1599 {
|
|
1600 case kControlUpButtonPart: data = -1; break;
|
|
1601 case kControlDownButtonPart: data = 1; break;
|
|
1602 case kControlPageDownPart: data = page; break;
|
|
1603 case kControlPageUpPart: data = -page; break;
|
|
1604 default: data = 0; break;
|
|
1605 }
|
|
1606
|
|
1607 value = sb_info->value + data;
|
|
1608 /* if (value > sb_info->max)
|
|
1609 value = sb_info->max;
|
|
1610 else if (value < 0)
|
|
1611 value = 0;*/
|
|
1612
|
|
1613 /* When "allow_scrollbar" is FALSE still need to remember the new
|
|
1614 * position, but don't actually scroll by setting "dont_scroll". */
|
|
1615 dont_scroll = !allow_scrollbar;
|
|
1616 gui_drag_scrollbar(sb, value, dragging);
|
|
1617 dont_scroll = dont_scroll_save;
|
|
1618
|
|
1619 out_flush();
|
|
1620 gui_mch_set_scrollbar_thumb(sb, value, sb_info->size, sb_info->max);
|
|
1621
|
|
1622 /* if (sb_info->wp != NULL)
|
|
1623 {
|
|
1624 win_T *wp;
|
|
1625 int sb_num;
|
|
1626
|
|
1627 sb_num = 0;
|
|
1628 for (wp = firstwin; wp != sb->wp && wp != NULL; wp = W_NEXT(wp))
|
|
1629 sb_num++;
|
|
1630
|
|
1631 if (wp != NULL)
|
|
1632 {
|
|
1633 current_scrollbar = sb_num;
|
|
1634 scrollbar_value = value;
|
|
1635 gui_do_scroll();
|
|
1636 gui_mch_set_scrollbar_thumb(sb, value, sb_info->size, sb_info->max);
|
|
1637 }
|
|
1638 }*/
|
|
1639 }
|
|
1640
|
|
1641 /*
|
|
1642 * ------------------------------------------------------------
|
|
1643 * MacOS Click Handling procedures
|
|
1644 * ------------------------------------------------------------
|
|
1645 */
|
|
1646
|
|
1647
|
|
1648 /*
|
|
1649 * Handle a click inside the window, it may happens in the
|
|
1650 * scrollbar or the contents.
|
|
1651 *
|
|
1652 * TODO: Add support for potential TOOLBAR
|
|
1653 */
|
|
1654 void
|
593
|
1655 gui_mac_doInContentClick(EventRecord *theEvent, WindowPtr whichWindow)
|
7
|
1656 {
|
|
1657 Point thePoint;
|
|
1658 int_u vimModifiers;
|
|
1659 short thePortion;
|
|
1660 ControlHandle theControl;
|
|
1661 int vimMouseButton;
|
|
1662 short dblClick;
|
|
1663
|
|
1664 thePoint = theEvent->where;
|
9
|
1665 GlobalToLocal(&thePoint);
|
|
1666 SelectWindow(whichWindow);
|
|
1667
|
|
1668 thePortion = FindControl(thePoint, whichWindow, &theControl);
|
7
|
1669
|
|
1670 if (theControl != NUL)
|
|
1671 {
|
|
1672 /* We hit a scollbar */
|
|
1673
|
|
1674 if (thePortion != kControlIndicatorPart)
|
|
1675 {
|
|
1676 dragged_sb = theControl;
|
|
1677 TrackControl(theControl, thePoint, gScrollAction);
|
|
1678 dragged_sb = NULL;
|
|
1679 }
|
|
1680 else
|
|
1681 {
|
|
1682 dragged_sb = theControl;
|
|
1683 #if 1
|
|
1684 TrackControl(theControl, thePoint, gScrollDrag);
|
|
1685 #else
|
|
1686 TrackControl(theControl, thePoint, NULL);
|
|
1687 #endif
|
|
1688 /* pass 0 as the part to tell gui_mac_drag_thumb, that the mouse
|
|
1689 * button has been released */
|
9
|
1690 gui_mac_drag_thumb(theControl, 0); /* Should it be thePortion ? (Dany) */
|
7
|
1691 dragged_sb = NULL;
|
|
1692 }
|
|
1693 }
|
|
1694 else
|
|
1695 {
|
|
1696 /* We are inside the contents */
|
|
1697
|
|
1698 /* Convert the CTRL, OPTION, SHIFT and CMD key */
|
|
1699 vimModifiers = EventModifiers2VimMouseModifiers(theEvent->modifiers);
|
|
1700
|
|
1701 /* Defaults to MOUSE_LEFT as there's only one mouse button */
|
|
1702 vimMouseButton = MOUSE_LEFT;
|
|
1703
|
|
1704 /* Convert the CTRL_MOUSE_LEFT to MOUSE_RIGHT */
|
593
|
1705 /* TODO: NEEDED? */
|
7
|
1706 clickIsPopup = FALSE;
|
|
1707
|
|
1708 if ((gui.MacOSHaveCntxMenu) && (mouse_model_popup()))
|
|
1709 if (IsShowContextualMenuClick(theEvent))
|
|
1710 {
|
|
1711 vimMouseButton = MOUSE_RIGHT;
|
|
1712 vimModifiers &= ~MOUSE_CTRL;
|
|
1713 clickIsPopup = TRUE;
|
|
1714 }
|
|
1715
|
|
1716 /* Is it a double click ? */
|
|
1717 dblClick = ((theEvent->when - lastMouseTick) < GetDblTime());
|
|
1718
|
593
|
1719 /* Send the mouse click to Vim */
|
7
|
1720 gui_send_mouse_event(vimMouseButton, thePoint.h,
|
|
1721 thePoint.v, dblClick, vimModifiers);
|
|
1722
|
|
1723 /* Create the rectangle around the cursor to detect
|
|
1724 * the mouse dragging
|
|
1725 */
|
|
1726 #if 0
|
|
1727 /* TODO: Do we need to this even for the contextual menu?
|
|
1728 * It may be require for popup_setpos, but for popup?
|
|
1729 */
|
|
1730 if (vimMouseButton == MOUSE_LEFT)
|
|
1731 #endif
|
|
1732 {
|
9
|
1733 SetRect(&dragRect, FILL_X(X_2_COL(thePoint.h)),
|
7
|
1734 FILL_Y(Y_2_ROW(thePoint.v)),
|
|
1735 FILL_X(X_2_COL(thePoint.h)+1),
|
|
1736 FILL_Y(Y_2_ROW(thePoint.v)+1));
|
|
1737
|
|
1738 dragRectEnbl = TRUE;
|
|
1739 dragRectControl = kCreateRect;
|
|
1740 }
|
|
1741 }
|
|
1742 }
|
|
1743
|
|
1744 /*
|
|
1745 * Handle the click in the titlebar (to move the window)
|
|
1746 */
|
|
1747 void
|
593
|
1748 gui_mac_doInDragClick(Point where, WindowPtr whichWindow)
|
7
|
1749 {
|
|
1750 Rect movingLimits;
|
|
1751 Rect *movingLimitsPtr = &movingLimits;
|
|
1752
|
|
1753 /* TODO: may try to prevent move outside screen? */
|
9
|
1754 movingLimitsPtr = GetRegionBounds(GetGrayRgn(), &movingLimits);
|
|
1755 DragWindow(whichWindow, where, movingLimitsPtr);
|
7
|
1756 }
|
|
1757
|
|
1758 /*
|
|
1759 * Handle the click in the grow box
|
|
1760 */
|
|
1761 void
|
593
|
1762 gui_mac_doInGrowClick(Point where, WindowPtr whichWindow)
|
7
|
1763 {
|
|
1764
|
|
1765 long newSize;
|
|
1766 unsigned short newWidth;
|
|
1767 unsigned short newHeight;
|
|
1768 Rect resizeLimits;
|
|
1769 Rect *resizeLimitsPtr = &resizeLimits;
|
|
1770 Rect NewContentRect;
|
|
1771
|
9
|
1772 resizeLimitsPtr = GetRegionBounds(GetGrayRgn(), &resizeLimits);
|
7
|
1773
|
|
1774 /* Set the minimun size */
|
|
1775 /* TODO: Should this come from Vim? */
|
|
1776 resizeLimits.top = 100;
|
|
1777 resizeLimits.left = 100;
|
|
1778
|
|
1779 newSize = ResizeWindow(whichWindow, where, &resizeLimits, &NewContentRect);
|
|
1780 newWidth = NewContentRect.right - NewContentRect.left;
|
|
1781 newHeight = NewContentRect.bottom - NewContentRect.top;
|
|
1782 gui_resize_shell(newWidth, newHeight);
|
|
1783 gui_mch_set_bg_color(gui.back_pixel);
|
812
|
1784 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH);
|
7
|
1785 }
|
|
1786
|
|
1787 /*
|
|
1788 * Handle the click in the zoom box
|
|
1789 */
|
|
1790 static void
|
593
|
1791 gui_mac_doInZoomClick(EventRecord *theEvent, WindowPtr whichWindow)
|
7
|
1792 {
|
|
1793 Rect r;
|
|
1794 Point p;
|
|
1795 short thePart;
|
|
1796
|
|
1797 /* ideal width is current */
|
|
1798 p.h = Columns * gui.char_width + 2 * gui.border_offset;
|
|
1799 if (gui.which_scrollbars[SBAR_LEFT])
|
|
1800 p.h += gui.scrollbar_width;
|
|
1801 if (gui.which_scrollbars[SBAR_RIGHT])
|
|
1802 p.h += gui.scrollbar_width;
|
|
1803 /* ideal height is as heigh as we can get */
|
|
1804 p.v = 15 * 1024;
|
|
1805
|
|
1806 thePart = IsWindowInStandardState(whichWindow, &p, &r)
|
|
1807 ? inZoomIn : inZoomOut;
|
|
1808
|
|
1809 if (!TrackBox(whichWindow, theEvent->where, thePart))
|
|
1810 return;
|
|
1811
|
|
1812 /* use returned width */
|
|
1813 p.h = r.right - r.left;
|
|
1814 /* adjust returned height */
|
|
1815 p.v = r.bottom - r.top - 2 * gui.border_offset;
|
|
1816 if (gui.which_scrollbars[SBAR_BOTTOM])
|
|
1817 p.v -= gui.scrollbar_height;
|
|
1818 p.v -= p.v % gui.char_height;
|
|
1819 p.v += 2 * gui.border_width;
|
|
1820 if (gui.which_scrollbars[SBAR_BOTTOM]);
|
|
1821 p.v += gui.scrollbar_height;
|
|
1822
|
|
1823 ZoomWindowIdeal(whichWindow, thePart, &p);
|
|
1824
|
|
1825 GetWindowBounds(whichWindow, kWindowContentRgn, &r);
|
|
1826 gui_resize_shell(r.right - r.left, r.bottom - r.top);
|
|
1827 gui_mch_set_bg_color(gui.back_pixel);
|
812
|
1828 gui_set_shellsize(TRUE, FALSE, RESIZE_BOTH);
|
7
|
1829 }
|
|
1830
|
|
1831 /*
|
|
1832 * ------------------------------------------------------------
|
|
1833 * MacOS Event Handling procedure
|
|
1834 * ------------------------------------------------------------
|
|
1835 */
|
|
1836
|
|
1837 /*
|
|
1838 * Handle the Update Event
|
|
1839 */
|
|
1840
|
|
1841 void
|
593
|
1842 gui_mac_doUpdateEvent(EventRecord *event)
|
7
|
1843 {
|
|
1844 WindowPtr whichWindow;
|
|
1845 GrafPtr savePort;
|
|
1846 RgnHandle updateRgn;
|
|
1847 Rect updateRect;
|
|
1848 Rect *updateRectPtr;
|
|
1849 Rect rc;
|
|
1850 Rect growRect;
|
|
1851 RgnHandle saveRgn;
|
|
1852
|
|
1853
|
|
1854 updateRgn = NewRgn();
|
|
1855 if (updateRgn == NULL)
|
|
1856 return;
|
|
1857
|
|
1858 /* This could be done by the caller as we
|
|
1859 * don't require anything else out of the event
|
|
1860 */
|
|
1861 whichWindow = (WindowPtr) event->message;
|
|
1862
|
|
1863 /* Save Current Port */
|
9
|
1864 GetPort(&savePort);
|
7
|
1865
|
|
1866 /* Select the Window's Port */
|
9
|
1867 SetPortWindowPort(whichWindow);
|
7
|
1868
|
|
1869 /* Let's update the window */
|
9
|
1870 BeginUpdate(whichWindow);
|
7
|
1871 /* Redraw the biggest rectangle covering the area
|
|
1872 * to be updated.
|
|
1873 */
|
|
1874 GetPortVisibleRegion(GetWindowPort(whichWindow), updateRgn);
|
|
1875 # if 0
|
|
1876 /* Would be more appropriate to use the follwing but doesn't
|
|
1877 * seem to work under MacOS X (Dany)
|
|
1878 */
|
|
1879 GetWindowRegion(whichWindow, kWindowUpdateRgn, updateRgn);
|
|
1880 # endif
|
593
|
1881
|
7
|
1882 /* Use the HLock useless in Carbon? Is it harmful?*/
|
9
|
1883 HLock((Handle) updateRgn);
|
593
|
1884
|
9
|
1885 updateRectPtr = GetRegionBounds(updateRgn, &updateRect);
|
7
|
1886 # if 0
|
|
1887 /* Code from original Carbon Port (using GetWindowRegion.
|
|
1888 * I believe the UpdateRgn is already in local (Dany)
|
|
1889 */
|
|
1890 GlobalToLocal(&topLeft(updateRect)); /* preCarbon? */
|
|
1891 GlobalToLocal(&botRight(updateRect));
|
|
1892 # endif
|
|
1893 /* Update the content (i.e. the text) */
|
|
1894 gui_redraw(updateRectPtr->left, updateRectPtr->top,
|
|
1895 updateRectPtr->right - updateRectPtr->left,
|
|
1896 updateRectPtr->bottom - updateRectPtr->top);
|
|
1897 /* Clear the border areas if needed */
|
|
1898 gui_mch_set_bg_color(gui.back_pixel);
|
|
1899 if (updateRectPtr->left < FILL_X(0))
|
|
1900 {
|
9
|
1901 SetRect(&rc, 0, 0, FILL_X(0), FILL_Y(Rows));
|
|
1902 EraseRect(&rc);
|
7
|
1903 }
|
|
1904 if (updateRectPtr->top < FILL_Y(0))
|
|
1905 {
|
9
|
1906 SetRect(&rc, 0, 0, FILL_X(Columns), FILL_Y(0));
|
|
1907 EraseRect(&rc);
|
7
|
1908 }
|
|
1909 if (updateRectPtr->right > FILL_X(Columns))
|
|
1910 {
|
9
|
1911 SetRect(&rc, FILL_X(Columns), 0,
|
7
|
1912 FILL_X(Columns) + gui.border_offset, FILL_Y(Rows));
|
9
|
1913 EraseRect(&rc);
|
7
|
1914 }
|
|
1915 if (updateRectPtr->bottom > FILL_Y(Rows))
|
|
1916 {
|
9
|
1917 SetRect(&rc, 0, FILL_Y(Rows), FILL_X(Columns) + gui.border_offset,
|
7
|
1918 FILL_Y(Rows) + gui.border_offset);
|
9
|
1919 EraseRect(&rc);
|
7
|
1920 }
|
9
|
1921 HUnlock((Handle) updateRgn);
|
|
1922 DisposeRgn(updateRgn);
|
7
|
1923
|
|
1924 /* Update scrollbars */
|
9
|
1925 DrawControls(whichWindow);
|
7
|
1926
|
|
1927 /* Update the GrowBox */
|
|
1928 /* Taken from FAQ 33-27 */
|
|
1929 saveRgn = NewRgn();
|
|
1930 GetWindowBounds(whichWindow, kWindowGrowRgn, &growRect);
|
9
|
1931 GetClip(saveRgn);
|
|
1932 ClipRect(&growRect);
|
|
1933 DrawGrowIcon(whichWindow);
|
|
1934 SetClip(saveRgn);
|
|
1935 DisposeRgn(saveRgn);
|
|
1936 EndUpdate(whichWindow);
|
7
|
1937
|
|
1938 /* Restore original Port */
|
9
|
1939 SetPort(savePort);
|
7
|
1940 }
|
|
1941
|
|
1942 /*
|
|
1943 * Handle the activate/deactivate event
|
|
1944 * (apply to a window)
|
|
1945 */
|
|
1946 void
|
593
|
1947 gui_mac_doActivateEvent(EventRecord *event)
|
7
|
1948 {
|
|
1949 WindowPtr whichWindow;
|
|
1950
|
|
1951 whichWindow = (WindowPtr) event->message;
|
|
1952 if ((event->modifiers) & activeFlag)
|
|
1953 /* Activate */
|
|
1954 gui_focus_change(TRUE);
|
|
1955 else
|
|
1956 {
|
|
1957 /* Deactivate */
|
|
1958 gui_focus_change(FALSE);
|
|
1959 /* DON'T KNOW what the code below was doing
|
|
1960 found in the deactivate clause, but the
|
|
1961 clause writting TRUE into in_focus (BUG)
|
|
1962 */
|
|
1963
|
|
1964 #if 0 /* Removed by Dany as per above June 2001 */
|
|
1965 a_bool = false;
|
9
|
1966 SetPreserveGlyph(a_bool);
|
|
1967 SetOutlinePreferred(a_bool);
|
7
|
1968 #endif
|
|
1969 }
|
|
1970 }
|
|
1971
|
|
1972
|
|
1973 /*
|
|
1974 * Handle the suspend/resume event
|
|
1975 * (apply to the application)
|
|
1976 */
|
|
1977 void
|
593
|
1978 gui_mac_doSuspendEvent(EventRecord *event)
|
7
|
1979 {
|
|
1980 /* The frontmost application just changed */
|
|
1981
|
|
1982 /* NOTE: the suspend may happen before the deactivate
|
|
1983 * seen on MacOS X
|
|
1984 */
|
|
1985
|
|
1986 /* May not need to change focus as the window will
|
|
1987 * get an activate/desactivate event
|
|
1988 */
|
|
1989 if (event->message & 1)
|
|
1990 /* Resume */
|
|
1991 gui_focus_change(TRUE);
|
|
1992 else
|
|
1993 /* Suspend */
|
|
1994 gui_focus_change(FALSE);
|
|
1995 }
|
|
1996
|
|
1997 /*
|
|
1998 * Handle the key
|
|
1999 */
|
168
|
2000 #ifdef USE_CARBONKEYHANDLER
|
|
2001 # define INLINE_KEY_BUFFER_SIZE 80
|
|
2002 static pascal OSStatus
|
593
|
2003 gui_mac_doKeyEventCarbon(
|
|
2004 EventHandlerCallRef nextHandler,
|
|
2005 EventRef theEvent,
|
168
|
2006 void *data)
|
|
2007 {
|
|
2008 /* Multibyte-friendly key event handler */
|
|
2009 OSStatus e = -1;
|
|
2010 UInt32 actualSize;
|
|
2011 UniChar *text;
|
|
2012 char_u result[INLINE_KEY_BUFFER_SIZE];
|
|
2013 short len = 0;
|
|
2014 UInt32 key_sym;
|
|
2015 char charcode;
|
|
2016 int key_char;
|
|
2017 UInt32 modifiers;
|
|
2018 size_t encLen;
|
|
2019 char_u *to = NULL;
|
|
2020 Boolean isSpecial = FALSE;
|
|
2021 int i;
|
|
2022
|
|
2023 /* Mask the mouse (as per user setting) */
|
|
2024 if (p_mh)
|
|
2025 ObscureCursor();
|
|
2026
|
|
2027 do
|
|
2028 {
|
|
2029 if (noErr != GetEventParameter(theEvent, kEventParamTextInputSendText,
|
|
2030 typeUnicodeText, NULL, 0, &actualSize, NULL))
|
|
2031 break;
|
|
2032
|
|
2033 text = (UniChar *)alloc(actualSize);
|
|
2034
|
|
2035 if (text)
|
|
2036 {
|
|
2037 do
|
|
2038 {
|
|
2039 if (noErr != GetEventParameter(theEvent,
|
|
2040 kEventParamTextInputSendText,
|
|
2041 typeUnicodeText, NULL, actualSize, NULL, text))
|
|
2042 break;
|
|
2043 EventRef keyEvent;
|
|
2044 if (noErr != GetEventParameter(theEvent,
|
|
2045 kEventParamTextInputSendKeyboardEvent,
|
|
2046 typeEventRef, NULL, sizeof(EventRef), NULL, &keyEvent))
|
|
2047 break;
|
|
2048 if (noErr != GetEventParameter(keyEvent,
|
|
2049 kEventParamKeyModifiers,
|
|
2050 typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers))
|
|
2051 break;
|
|
2052 if (noErr != GetEventParameter(keyEvent,
|
|
2053 kEventParamKeyCode,
|
|
2054 typeUInt32, NULL, sizeof(UInt32), NULL, &key_sym))
|
|
2055 break;
|
|
2056 if (noErr != GetEventParameter(keyEvent,
|
|
2057 kEventParamKeyMacCharCodes,
|
|
2058 typeChar, NULL, sizeof(char), NULL, &charcode))
|
|
2059 break;
|
|
2060
|
|
2061 key_char = charcode;
|
|
2062
|
|
2063 if (modifiers & controlKey)
|
|
2064 {
|
|
2065 if ((modifiers & ~(controlKey|shiftKey)) == 0
|
|
2066 && (key_char == '2' || key_char == '6'))
|
|
2067 {
|
|
2068 /* CTRL-^ and CTRL-@ don't work in the normal way. */
|
|
2069 if (key_char == '2')
|
|
2070 key_char = Ctrl_AT;
|
|
2071 else
|
|
2072 key_char = Ctrl_HAT;
|
|
2073
|
|
2074 text[0] = (UniChar)key_char;
|
|
2075 modifiers = 0;
|
|
2076 }
|
|
2077 }
|
|
2078
|
|
2079 if (modifiers & cmdKey)
|
|
2080 #ifndef USE_CMD_KEY
|
|
2081 break; /* Let system handle Cmd+... */
|
|
2082 #else
|
|
2083 {
|
|
2084 /* Intercept CMD-. */
|
|
2085 if (key_char == '.')
|
|
2086 got_int = TRUE;
|
|
2087
|
|
2088 /* Convert the modifiers */
|
|
2089 modifiers = EventModifiers2VimModifiers(modifiers);
|
|
2090
|
|
2091 /* Following code to simplify and consolidate modifiers
|
|
2092 * taken liberally from gui_w48.c */
|
|
2093
|
|
2094 key_char = simplify_key(key_char, (int *)&modifiers);
|
|
2095
|
|
2096 /* remove SHIFT for keys that are already shifted, e.g.,
|
|
2097 * '(' and '*' */
|
|
2098 if (key_char < 0x100 &&
|
|
2099 !isalpha(key_char) && isprint(key_char))
|
|
2100 modifiers &= ~MOD_MASK_SHIFT;
|
|
2101
|
|
2102 /* Interpret META, include SHIFT, etc. */
|
|
2103 key_char = extract_modifiers(key_char, (int *)&modifiers);
|
|
2104 if (key_char == CSI)
|
|
2105 key_char = K_CSI;
|
|
2106
|
|
2107 if (modifiers)
|
|
2108 {
|
|
2109 result[len++] = CSI;
|
|
2110 result[len++] = KS_MODIFIER;
|
|
2111 result[len++] = modifiers;
|
|
2112 }
|
|
2113
|
|
2114 isSpecial = TRUE;
|
|
2115 }
|
|
2116 #endif
|
|
2117 else
|
|
2118 {
|
|
2119 /* Find the special key (eg., for cursor keys) */
|
|
2120 if (!(actualSize > sizeof(UniChar)) &&
|
|
2121 ((text[0] < 0x20) || (text[0] == 0x7f)))
|
|
2122 {
|
|
2123 for (i = 0; special_keys[i].key_sym != (KeySym)0; ++i)
|
|
2124 if (special_keys[i].key_sym == key_sym)
|
|
2125 {
|
|
2126 key_char = TO_SPECIAL(special_keys[i].vim_code0,
|
|
2127 special_keys[i].vim_code1);
|
|
2128 key_char = simplify_key(key_char,
|
|
2129 (int *)&modifiers);
|
|
2130 isSpecial = TRUE;
|
|
2131 break;
|
|
2132 }
|
|
2133 }
|
|
2134 }
|
|
2135
|
|
2136 if (isSpecial && IS_SPECIAL(key_char))
|
|
2137 {
|
|
2138 result[len++] = CSI;
|
|
2139 result[len++] = K_SECOND(key_char);
|
|
2140 result[len++] = K_THIRD(key_char);
|
|
2141 }
|
|
2142 else
|
|
2143 {
|
|
2144 encLen = actualSize;
|
|
2145 to = mac_utf16_to_enc(text, actualSize, &encLen);
|
|
2146 }
|
|
2147
|
|
2148 if (to)
|
|
2149 {
|
|
2150 /* This is basically add_to_input_buf_csi() */
|
|
2151 for (i = 0; i < encLen && len < (INLINE_KEY_BUFFER_SIZE-1); ++i)
|
|
2152 {
|
|
2153 result[len++] = to[i];
|
|
2154 if (to[i] == CSI)
|
|
2155 {
|
|
2156 result[len++] = KS_EXTRA;
|
|
2157 result[len++] = (int)KE_CSI;
|
|
2158 }
|
|
2159 }
|
|
2160 vim_free(to);
|
|
2161 }
|
|
2162
|
|
2163 add_to_input_buf(result, len);
|
|
2164 e = noErr;
|
|
2165 }
|
|
2166 while (0);
|
|
2167
|
|
2168 vim_free(text);
|
|
2169 if (e == noErr)
|
|
2170 {
|
|
2171 /* Fake event to wake up WNE (required to get
|
|
2172 * key repeat working */
|
|
2173 PostEvent(keyUp, 0);
|
|
2174 return noErr;
|
|
2175 }
|
|
2176 }
|
|
2177 }
|
|
2178 while (0);
|
|
2179
|
|
2180 return CallNextEventHandler(nextHandler, theEvent);
|
|
2181 }
|
|
2182 #else
|
7
|
2183 void
|
|
2184 gui_mac_doKeyEvent(EventRecord *theEvent)
|
|
2185 {
|
|
2186 /* TODO: add support for COMMAND KEY */
|
|
2187 long menu;
|
|
2188 unsigned char string[20];
|
|
2189 short num, i;
|
|
2190 short len = 0;
|
|
2191 KeySym key_sym;
|
|
2192 int key_char;
|
|
2193 int modifiers;
|
26
|
2194 int simplify = FALSE;
|
7
|
2195
|
|
2196 /* Mask the mouse (as per user setting) */
|
|
2197 if (p_mh)
|
|
2198 ObscureCursor();
|
|
2199
|
|
2200 /* Get the key code and it's ASCII representation */
|
|
2201 key_sym = ((theEvent->message & keyCodeMask) >> 8);
|
|
2202 key_char = theEvent->message & charCodeMask;
|
|
2203 num = 1;
|
|
2204
|
|
2205 /* Intercept CTRL-C */
|
|
2206 if (theEvent->modifiers & controlKey)
|
9
|
2207 {
|
7
|
2208 if (key_char == Ctrl_C && ctrl_c_interrupts)
|
|
2209 got_int = TRUE;
|
9
|
2210 else if ((theEvent->modifiers & ~(controlKey|shiftKey)) == 0
|
|
2211 && (key_char == '2' || key_char == '6'))
|
|
2212 {
|
|
2213 /* CTRL-^ and CTRL-@ don't work in the normal way. */
|
|
2214 if (key_char == '2')
|
|
2215 key_char = Ctrl_AT;
|
|
2216 else
|
|
2217 key_char = Ctrl_HAT;
|
|
2218 theEvent->modifiers = 0;
|
|
2219 }
|
|
2220 }
|
7
|
2221
|
|
2222 /* Intercept CMD-. */
|
|
2223 if (theEvent->modifiers & cmdKey)
|
|
2224 if (key_char == '.')
|
|
2225 got_int = TRUE;
|
|
2226
|
|
2227 /* Handle command key as per menu */
|
|
2228 /* TODO: should override be allowed? Require YAO or could use 'winaltkey' */
|
|
2229 if (theEvent->modifiers & cmdKey)
|
|
2230 /* Only accept CMD alone or with CAPLOCKS and the mouse button.
|
|
2231 * Why the mouse button? */
|
|
2232 if ((theEvent->modifiers & (~(cmdKey | btnState | alphaLock))) == 0)
|
|
2233 {
|
|
2234 menu = MenuKey(key_char);
|
|
2235 if (HiWord(menu))
|
|
2236 {
|
|
2237 gui_mac_handle_menu(menu);
|
|
2238 return;
|
|
2239 }
|
|
2240 }
|
|
2241
|
|
2242 /* Convert the modifiers */
|
|
2243 modifiers = EventModifiers2VimModifiers(theEvent->modifiers);
|
|
2244
|
|
2245
|
|
2246 /* Handle special keys. */
|
|
2247 #if 0
|
26
|
2248 /* Why has this been removed? */
|
7
|
2249 if (!(theEvent->modifiers & (cmdKey | controlKey | rightControlKey)))
|
|
2250 #endif
|
|
2251 {
|
|
2252 /* Find the special key (for non-printable keyt_char) */
|
|
2253 if ((key_char < 0x20) || (key_char == 0x7f))
|
|
2254 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++)
|
|
2255 if (special_keys[i].key_sym == key_sym)
|
|
2256 {
|
|
2257 # if 0
|
|
2258 /* We currently don't have not so special key */
|
|
2259 if (special_keys[i].vim_code1 == NUL)
|
|
2260 key_char = special_keys[i].vim_code0;
|
|
2261 else
|
|
2262 # endif
|
9
|
2263 key_char = TO_SPECIAL(special_keys[i].vim_code0,
|
|
2264 special_keys[i].vim_code1);
|
26
|
2265 simplify = TRUE;
|
7
|
2266 break;
|
|
2267 }
|
|
2268 }
|
|
2269
|
26
|
2270 /* For some keys the modifier is included in the char itself. */
|
|
2271 if (simplify || key_char == TAB || key_char == ' ')
|
|
2272 key_char = simplify_key(key_char, &modifiers);
|
7
|
2273
|
|
2274 /* Add the modifier to the input bu if needed */
|
|
2275 /* Do not want SHIFT-A or CTRL-A with modifier */
|
|
2276 if (!IS_SPECIAL(key_char)
|
|
2277 && key_sym != vk_Space
|
|
2278 && key_sym != vk_Tab
|
|
2279 && key_sym != vk_Return
|
|
2280 && key_sym != vk_Enter
|
|
2281 && key_sym != vk_Esc)
|
|
2282 {
|
|
2283 #if 1
|
|
2284 /* Clear modifiers when only one modifier is set */
|
9
|
2285 if ((modifiers == MOD_MASK_SHIFT)
|
|
2286 || (modifiers == MOD_MASK_CTRL)
|
|
2287 || (modifiers == MOD_MASK_ALT))
|
7
|
2288 modifiers = 0;
|
|
2289 #else
|
9
|
2290 if (modifiers & MOD_MASK_CTRL)
|
7
|
2291 modifiers = modifiers & ~MOD_MASK_CTRL;
|
9
|
2292 if (modifiers & MOD_MASK_ALT)
|
7
|
2293 modifiers = modifiers & ~MOD_MASK_ALT;
|
9
|
2294 if (modifiers & MOD_MASK_SHIFT)
|
7
|
2295 modifiers = modifiers & ~MOD_MASK_SHIFT;
|
|
2296 #endif
|
|
2297 }
|
9
|
2298 if (modifiers)
|
7
|
2299 {
|
9
|
2300 string[len++] = CSI;
|
|
2301 string[len++] = KS_MODIFIER;
|
|
2302 string[len++] = modifiers;
|
7
|
2303 }
|
|
2304
|
9
|
2305 if (IS_SPECIAL(key_char))
|
7
|
2306 {
|
9
|
2307 string[len++] = CSI;
|
|
2308 string[len++] = K_SECOND(key_char);
|
|
2309 string[len++] = K_THIRD(key_char);
|
7
|
2310 }
|
|
2311 else
|
|
2312 {
|
|
2313 #ifdef FEAT_MBYTE
|
9
|
2314 /* Convert characters when needed (e.g., from MacRoman to latin1).
|
|
2315 * This doesn't work for the NUL byte. */
|
|
2316 if (input_conv.vc_type != CONV_NONE && key_char > 0)
|
7
|
2317 {
|
|
2318 char_u from[2], *to;
|
|
2319 int l;
|
|
2320
|
|
2321 from[0] = key_char;
|
|
2322 from[1] = NUL;
|
|
2323 l = 1;
|
|
2324 to = string_convert(&input_conv, from, &l);
|
|
2325 if (to != NULL)
|
|
2326 {
|
|
2327 for (i = 0; i < l && len < 19; i++)
|
|
2328 {
|
|
2329 if (to[i] == CSI)
|
|
2330 {
|
|
2331 string[len++] = KS_EXTRA;
|
|
2332 string[len++] = KE_CSI;
|
|
2333 }
|
|
2334 else
|
|
2335 string[len++] = to[i];
|
|
2336 }
|
|
2337 vim_free(to);
|
|
2338 }
|
|
2339 else
|
|
2340 string[len++] = key_char;
|
|
2341 }
|
|
2342 else
|
|
2343 #endif
|
|
2344 string[len++] = key_char;
|
|
2345 }
|
|
2346
|
|
2347 if (len == 1 && string[0] == CSI)
|
|
2348 {
|
|
2349 /* Turn CSI into K_CSI. */
|
|
2350 string[ len++ ] = KS_EXTRA;
|
|
2351 string[ len++ ] = KE_CSI;
|
|
2352 }
|
|
2353
|
|
2354 add_to_input_buf(string, len);
|
|
2355 }
|
168
|
2356 #endif
|
7
|
2357
|
|
2358 /*
|
|
2359 * Handle MouseClick
|
|
2360 */
|
|
2361 void
|
593
|
2362 gui_mac_doMouseDownEvent(EventRecord *theEvent)
|
7
|
2363 {
|
|
2364 short thePart;
|
|
2365 WindowPtr whichWindow;
|
|
2366
|
9
|
2367 thePart = FindWindow(theEvent->where, &whichWindow);
|
7
|
2368
|
|
2369 switch (thePart)
|
|
2370 {
|
|
2371 case (inDesk):
|
|
2372 /* TODO: what to do? */
|
|
2373 break;
|
|
2374
|
|
2375 case (inMenuBar):
|
9
|
2376 gui_mac_handle_menu(MenuSelect(theEvent->where));
|
7
|
2377 break;
|
|
2378
|
|
2379 case (inContent):
|
9
|
2380 gui_mac_doInContentClick(theEvent, whichWindow);
|
7
|
2381 break;
|
|
2382
|
|
2383 case (inDrag):
|
9
|
2384 gui_mac_doInDragClick(theEvent->where, whichWindow);
|
7
|
2385 break;
|
|
2386
|
|
2387 case (inGrow):
|
9
|
2388 gui_mac_doInGrowClick(theEvent->where, whichWindow);
|
7
|
2389 break;
|
|
2390
|
|
2391 case (inGoAway):
|
|
2392 if (TrackGoAway(whichWindow, theEvent->where))
|
|
2393 gui_shell_closed();
|
|
2394 break;
|
|
2395
|
|
2396 case (inZoomIn):
|
|
2397 case (inZoomOut):
|
|
2398 gui_mac_doInZoomClick(theEvent, whichWindow);
|
|
2399 break;
|
|
2400 }
|
|
2401 }
|
|
2402
|
|
2403 /*
|
|
2404 * Handle MouseMoved
|
|
2405 * [this event is a moving in and out of a region]
|
|
2406 */
|
|
2407 void
|
593
|
2408 gui_mac_doMouseMovedEvent(EventRecord *event)
|
7
|
2409 {
|
|
2410 Point thePoint;
|
|
2411 int_u vimModifiers;
|
|
2412
|
|
2413 thePoint = event->where;
|
9
|
2414 GlobalToLocal(&thePoint);
|
7
|
2415 vimModifiers = EventModifiers2VimMouseModifiers(event->modifiers);
|
|
2416
|
|
2417 if (!Button())
|
9
|
2418 gui_mouse_moved(thePoint.h, thePoint.v);
|
7
|
2419 else
|
|
2420 if (!clickIsPopup)
|
|
2421 gui_send_mouse_event(MOUSE_DRAG, thePoint.h,
|
|
2422 thePoint.v, FALSE, vimModifiers);
|
|
2423
|
|
2424 /* Reset the region from which we move in and out */
|
9
|
2425 SetRect(&dragRect, FILL_X(X_2_COL(thePoint.h)),
|
7
|
2426 FILL_Y(Y_2_ROW(thePoint.v)),
|
|
2427 FILL_X(X_2_COL(thePoint.h)+1),
|
|
2428 FILL_Y(Y_2_ROW(thePoint.v)+1));
|
|
2429
|
|
2430 if (dragRectEnbl)
|
|
2431 dragRectControl = kCreateRect;
|
|
2432
|
|
2433 }
|
|
2434
|
|
2435 /*
|
|
2436 * Handle the mouse release
|
|
2437 */
|
|
2438 void
|
593
|
2439 gui_mac_doMouseUpEvent(EventRecord *theEvent)
|
7
|
2440 {
|
|
2441 Point thePoint;
|
|
2442 int_u vimModifiers;
|
|
2443
|
|
2444 /* TODO: Properly convert the Contextual menu mouse-up */
|
|
2445 /* Potential source of the double menu */
|
|
2446 lastMouseTick = theEvent->when;
|
|
2447 dragRectEnbl = FALSE;
|
|
2448 dragRectControl = kCreateEmpty;
|
|
2449 thePoint = theEvent->where;
|
9
|
2450 GlobalToLocal(&thePoint);
|
7
|
2451
|
|
2452 vimModifiers = EventModifiers2VimMouseModifiers(theEvent->modifiers);
|
|
2453 if (clickIsPopup)
|
|
2454 {
|
|
2455 vimModifiers &= ~MOUSE_CTRL;
|
|
2456 clickIsPopup = FALSE;
|
|
2457 }
|
9
|
2458 gui_send_mouse_event(MOUSE_RELEASE, thePoint.h, thePoint.v, FALSE, vimModifiers);
|
7
|
2459 }
|
|
2460
|
|
2461 static pascal OSStatus
|
|
2462 gui_mac_mouse_wheel(EventHandlerCallRef nextHandler, EventRef theEvent,
|
|
2463 void *data)
|
|
2464 {
|
|
2465 EventRef bogusEvent;
|
|
2466 Point point;
|
|
2467 Rect bounds;
|
|
2468 UInt32 mod;
|
|
2469 SInt32 delta;
|
|
2470 int_u vim_mod;
|
|
2471
|
|
2472 if (noErr != GetEventParameter(theEvent, kEventParamMouseWheelDelta,
|
|
2473 typeSInt32, NULL, sizeof(SInt32), NULL, &delta))
|
|
2474 goto bail;
|
|
2475 if (noErr != GetEventParameter(theEvent, kEventParamMouseLocation,
|
|
2476 typeQDPoint, NULL, sizeof(Point), NULL, &point))
|
|
2477 goto bail;
|
|
2478 if (noErr != GetEventParameter(theEvent, kEventParamKeyModifiers,
|
|
2479 typeUInt32, NULL, sizeof(UInt32), NULL, &mod))
|
|
2480 goto bail;
|
|
2481
|
|
2482 vim_mod = 0;
|
|
2483 if (mod & shiftKey)
|
|
2484 vim_mod |= MOUSE_SHIFT;
|
|
2485 if (mod & controlKey)
|
|
2486 vim_mod |= MOUSE_CTRL;
|
|
2487 if (mod & optionKey)
|
|
2488 vim_mod |= MOUSE_ALT;
|
|
2489
|
|
2490 /* post a bogus event to wake up WaitNextEvent */
|
|
2491 if (noErr != CreateEvent(NULL, kEventClassMouse, kEventMouseMoved, 0,
|
|
2492 kEventAttributeNone, &bogusEvent))
|
|
2493 goto bail;
|
|
2494 if (noErr != PostEventToQueue(GetMainEventQueue(), bogusEvent,
|
|
2495 kEventPriorityLow))
|
|
2496 goto bail;
|
|
2497
|
37
|
2498 ReleaseEvent(bogusEvent);
|
|
2499
|
7
|
2500 if (noErr == GetWindowBounds(gui.VimWindow, kWindowContentRgn, &bounds))
|
|
2501 {
|
|
2502 point.h -= bounds.left;
|
|
2503 point.v -= bounds.top;
|
|
2504 }
|
|
2505
|
|
2506 gui_send_mouse_event((delta > 0) ? MOUSE_4 : MOUSE_5,
|
|
2507 point.h, point.v, FALSE, vim_mod);
|
|
2508
|
|
2509 return noErr;
|
|
2510
|
|
2511 bail:
|
|
2512 /*
|
|
2513 * when we fail give any additional callback handler a chance to perform
|
|
2514 * it's actions
|
|
2515 */
|
|
2516 return CallNextEventHandler(nextHandler, theEvent);
|
|
2517 }
|
|
2518
|
|
2519 #if 0
|
|
2520
|
|
2521 /*
|
|
2522 * This would be the normal way of invoking the contextual menu
|
|
2523 * but the Vim API doesn't seem to a support a request to get
|
|
2524 * the menu that we should display
|
|
2525 */
|
|
2526 void
|
|
2527 gui_mac_handle_contextual_menu(event)
|
|
2528 EventRecord *event;
|
|
2529 {
|
|
2530 /*
|
|
2531 * Clone PopUp to use menu
|
|
2532 * Create a object descriptor for the current selection
|
|
2533 * Call the procedure
|
|
2534 */
|
|
2535
|
|
2536 // Call to Handle Popup
|
|
2537 OSStatus status = ContextualMenuSelect(CntxMenu, event->where, false, kCMHelpItemNoHelp, "", NULL, &CntxType, &CntxMenuID, &CntxMenuItem);
|
|
2538
|
|
2539 if (status != noErr)
|
|
2540 return;
|
|
2541
|
|
2542 if (CntxType == kCMMenuItemSelected)
|
|
2543 {
|
|
2544 /* Handle the menu CntxMenuID, CntxMenuItem */
|
|
2545 /* The submenu can be handle directly by gui_mac_handle_menu */
|
|
2546 /* But what about the current menu, is the meny changed by ContextualMenuSelect */
|
9
|
2547 gui_mac_handle_menu((CntxMenuID << 16) + CntxMenuItem);
|
7
|
2548 }
|
|
2549 else if (CntxMenuID == kCMShowHelpSelected)
|
|
2550 {
|
|
2551 /* Should come up with the help */
|
|
2552 }
|
|
2553
|
|
2554 }
|
|
2555 #endif
|
|
2556
|
|
2557 /*
|
|
2558 * Handle menubar selection
|
|
2559 */
|
|
2560 void
|
593
|
2561 gui_mac_handle_menu(long menuChoice)
|
7
|
2562 {
|
|
2563 short menu = HiWord(menuChoice);
|
|
2564 short item = LoWord(menuChoice);
|
|
2565 vimmenu_T *theVimMenu = root_menu;
|
|
2566
|
|
2567 if (menu == 256) /* TODO: use constant or gui.xyz */
|
|
2568 {
|
|
2569 if (item == 1)
|
|
2570 gui_mch_beep(); /* TODO: Popup dialog or do :intro */
|
|
2571 }
|
|
2572 else if (item != 0)
|
|
2573 {
|
|
2574 theVimMenu = gui_mac_get_vim_menu(menu, item, root_menu);
|
|
2575
|
|
2576 if (theVimMenu)
|
|
2577 gui_menu_cb(theVimMenu);
|
|
2578 }
|
9
|
2579 HiliteMenu(0);
|
7
|
2580 }
|
|
2581
|
|
2582 /*
|
|
2583 * Dispatch the event to proper handler
|
|
2584 */
|
|
2585
|
|
2586 void
|
593
|
2587 gui_mac_handle_event(EventRecord *event)
|
7
|
2588 {
|
|
2589 OSErr error;
|
|
2590
|
|
2591 /* Handle contextual menu right now (if needed) */
|
|
2592 if (gui.MacOSHaveCntxMenu)
|
|
2593 if (IsShowContextualMenuClick(event))
|
|
2594 {
|
|
2595 # if 0
|
|
2596 gui_mac_handle_contextual_menu(event);
|
|
2597 # else
|
|
2598 gui_mac_doMouseDownEvent(event);
|
|
2599 # endif
|
|
2600 return;
|
|
2601 }
|
|
2602
|
|
2603 /* Handle normal event */
|
|
2604 switch (event->what)
|
|
2605 {
|
168
|
2606 #ifndef USE_CARBONKEYHANDLER
|
7
|
2607 case (keyDown):
|
|
2608 case (autoKey):
|
9
|
2609 gui_mac_doKeyEvent(event);
|
7
|
2610 break;
|
168
|
2611 #endif
|
7
|
2612 case (keyUp):
|
|
2613 /* We don't care about when the key get release */
|
|
2614 break;
|
|
2615
|
|
2616 case (mouseDown):
|
|
2617 gui_mac_doMouseDownEvent(event);
|
|
2618 break;
|
|
2619
|
|
2620 case (mouseUp):
|
|
2621 gui_mac_doMouseUpEvent(event);
|
|
2622 break;
|
|
2623
|
|
2624 case (updateEvt):
|
9
|
2625 gui_mac_doUpdateEvent(event);
|
7
|
2626 break;
|
|
2627
|
|
2628 case (diskEvt):
|
|
2629 /* We don't need special handling for disk insertion */
|
|
2630 break;
|
|
2631
|
|
2632 case (activateEvt):
|
9
|
2633 gui_mac_doActivateEvent(event);
|
7
|
2634 break;
|
|
2635
|
|
2636 case (osEvt):
|
|
2637 switch ((event->message >> 24) & 0xFF)
|
|
2638 {
|
|
2639 case (0xFA): /* mouseMovedMessage */
|
9
|
2640 gui_mac_doMouseMovedEvent(event);
|
7
|
2641 break;
|
|
2642 case (0x01): /* suspendResumeMessage */
|
9
|
2643 gui_mac_doSuspendEvent(event);
|
7
|
2644 break;
|
|
2645 }
|
|
2646 break;
|
|
2647
|
|
2648 #ifdef USE_AEVENT
|
|
2649 case (kHighLevelEvent):
|
|
2650 /* Someone's talking to us, through AppleEvents */
|
|
2651 error = AEProcessAppleEvent(event); /* TODO: Error Handling */
|
|
2652 break;
|
|
2653 #endif
|
|
2654 }
|
|
2655 }
|
|
2656
|
|
2657 /*
|
|
2658 * ------------------------------------------------------------
|
|
2659 * Unknown Stuff
|
|
2660 * ------------------------------------------------------------
|
|
2661 */
|
|
2662
|
|
2663
|
|
2664 GuiFont
|
593
|
2665 gui_mac_find_font(char_u *font_name)
|
7
|
2666 {
|
|
2667 char_u c;
|
|
2668 char_u *p;
|
|
2669 char_u pFontName[256];
|
|
2670 Str255 systemFontname;
|
|
2671 short font_id;
|
|
2672 short size=9;
|
|
2673 GuiFont font;
|
|
2674 #if 0
|
|
2675 char_u *fontNamePtr;
|
|
2676 #endif
|
|
2677
|
|
2678 for (p = font_name; ((*p != 0) && (*p != ':')); p++)
|
|
2679 ;
|
|
2680
|
|
2681 c = *p;
|
|
2682 *p = 0;
|
|
2683
|
|
2684 #if 1
|
|
2685 STRCPY(&pFontName[1], font_name);
|
|
2686 pFontName[0] = STRLEN(font_name);
|
|
2687 *p = c;
|
|
2688
|
168
|
2689 /* Get the font name, minus the style suffix (:h, etc) */
|
|
2690 char_u fontName[256];
|
|
2691 char_u *styleStart = vim_strchr(font_name, ':');
|
|
2692 size_t fontNameLen = styleStart ? styleStart - font_name : STRLEN(fontName);
|
|
2693 vim_strncpy(fontName, font_name, fontNameLen);
|
|
2694
|
|
2695 ATSUFontID fontRef;
|
|
2696 FMFontStyle fontStyle;
|
|
2697 font_id = 0;
|
|
2698
|
|
2699 if (ATSUFindFontFromName(&pFontName[1], pFontName[0], kFontFullName,
|
|
2700 kFontMacintoshPlatform, kFontNoScriptCode, kFontNoLanguageCode,
|
|
2701 &fontRef) == noErr)
|
|
2702 {
|
|
2703 if (FMGetFontFamilyInstanceFromFont(fontRef, &font_id, &fontStyle) != noErr)
|
|
2704 font_id = 0;
|
|
2705 }
|
13
|
2706
|
|
2707 if (font_id == 0)
|
|
2708 {
|
|
2709 /*
|
|
2710 * Try again, this time replacing underscores in the font name
|
|
2711 * with spaces (:set guifont allows the two to be used
|
|
2712 * interchangeably; the Font Manager doesn't).
|
|
2713 */
|
|
2714 int i, changed = FALSE;
|
|
2715
|
|
2716 for (i = pFontName[0]; i > 0; --i)
|
|
2717 {
|
|
2718 if (pFontName[i] == '_')
|
|
2719 {
|
|
2720 pFontName[i] = ' ';
|
|
2721 changed = TRUE;
|
|
2722 }
|
|
2723 }
|
|
2724 if (changed)
|
168
|
2725 if (ATSUFindFontFromName(&pFontName[1], pFontName[0],
|
|
2726 kFontFullName, kFontNoPlatformCode, kFontNoScriptCode,
|
|
2727 kFontNoLanguageCode, &fontRef) == noErr)
|
|
2728 {
|
|
2729 if (FMGetFontFamilyInstanceFromFont(fontRef, &font_id, &fontStyle) != noErr)
|
|
2730 font_id = 0;
|
|
2731 }
|
13
|
2732 }
|
|
2733
|
7
|
2734 #else
|
|
2735 /* name = C2Pascal_save(menu->dname); */
|
|
2736 fontNamePtr = C2Pascal_save_and_remove_backslash(font_name);
|
|
2737
|
9
|
2738 GetFNum(fontNamePtr, &font_id);
|
7
|
2739 #endif
|
|
2740
|
|
2741
|
|
2742 if (font_id == 0)
|
|
2743 {
|
|
2744 /* Oups, the system font was it the one the user want */
|
|
2745
|
168
|
2746 if (FMGetFontFamilyName(systemFont, systemFontname) != noErr)
|
|
2747 return NOFONT;
|
7
|
2748 if (!EqualString(pFontName, systemFontname, false, false))
|
|
2749 return NOFONT;
|
|
2750 }
|
|
2751 if (*p == ':')
|
|
2752 {
|
|
2753 p++;
|
|
2754 /* Set the values found after ':' */
|
|
2755 while (*p)
|
|
2756 {
|
|
2757 switch (*p++)
|
|
2758 {
|
|
2759 case 'h':
|
|
2760 size = points_to_pixels(p, &p, TRUE);
|
|
2761 break;
|
|
2762 /*
|
|
2763 * TODO: Maybe accept width and styles
|
|
2764 */
|
|
2765 }
|
|
2766 while (*p == ':')
|
|
2767 p++;
|
|
2768 }
|
|
2769 }
|
|
2770
|
|
2771 if (size < 1)
|
|
2772 size = 1; /* Avoid having a size of 0 with system font */
|
|
2773
|
|
2774 font = (size << 16) + ((long) font_id & 0xFFFF);
|
|
2775
|
|
2776 return font;
|
|
2777 }
|
|
2778
|
|
2779 /*
|
|
2780 * ------------------------------------------------------------
|
|
2781 * GUI_MCH functionnality
|
|
2782 * ------------------------------------------------------------
|
|
2783 */
|
|
2784
|
|
2785 /*
|
|
2786 * Parse the GUI related command-line arguments. Any arguments used are
|
|
2787 * deleted from argv, and *argc is decremented accordingly. This is called
|
|
2788 * when vim is started, whether or not the GUI has been started.
|
|
2789 */
|
|
2790 void
|
593
|
2791 gui_mch_prepare(int *argc, char **argv)
|
7
|
2792 {
|
|
2793 /* TODO: Move most of this stuff toward gui_mch_init */
|
|
2794 #ifdef USE_EXE_NAME
|
|
2795 FSSpec applDir;
|
|
2796 # ifndef USE_FIND_BUNDLE_PATH
|
|
2797 short applVRefNum;
|
|
2798 long applDirID;
|
|
2799 Str255 volName;
|
|
2800 # else
|
|
2801 ProcessSerialNumber psn;
|
|
2802 FSRef applFSRef;
|
|
2803 # endif
|
|
2804 #endif
|
|
2805
|
|
2806 /* Why did I put that in? (Dany) */
|
|
2807 MoreMasterPointers (0x40 * 3); /* we love handles */
|
|
2808
|
|
2809 #if 0
|
|
2810 InitCursor();
|
|
2811
|
|
2812 RegisterAppearanceClient();
|
|
2813
|
|
2814 #ifdef USE_AEVENT
|
|
2815 (void) InstallAEHandlers();
|
|
2816 #endif
|
|
2817
|
|
2818 if (Gestalt(gestaltContextualMenuAttr, &gestalt_rc) == noErr)
|
|
2819 gui.MacOSHaveCntxMenu = BitTst(&gestalt_rc, 31-gestaltContextualMenuTrapAvailable);
|
|
2820 else
|
|
2821 gui.MacOSHaveCntxMenu = false;
|
|
2822
|
|
2823 if (gui.MacOSHaveCntxMenu)
|
|
2824 gui.MacOSHaveCntxMenu = (InitContextualMenus()==noErr);
|
9
|
2825
|
|
2826 pomme = NewMenu(256, "\p\024"); /* 0x14= = Apple Menu */
|
|
2827
|
|
2828 AppendMenu(pomme, "\pAbout VIM");
|
|
2829
|
|
2830 InsertMenu(pomme, 0);
|
7
|
2831
|
|
2832 DrawMenuBar();
|
|
2833
|
|
2834
|
|
2835 #ifndef USE_OFFSETED_WINDOW
|
9
|
2836 SetRect(&windRect, 10, 48, 10+80*7 + 16, 48+24*11);
|
7
|
2837 #else
|
9
|
2838 SetRect(&windRect, 300, 40, 300+80*7 + 16, 40+24*11);
|
7
|
2839 #endif
|
|
2840
|
|
2841
|
|
2842 CreateNewWindow(kDocumentWindowClass,
|
|
2843 kWindowResizableAttribute | kWindowCollapseBoxAttribute,
|
9
|
2844 &windRect, &gui.VimWindow);
|
|
2845 SetPortWindowPort(gui.VimWindow);
|
7
|
2846
|
|
2847 gui.char_width = 7;
|
|
2848 gui.char_height = 11;
|
|
2849 gui.char_ascent = 6;
|
|
2850 gui.num_rows = 24;
|
|
2851 gui.num_cols = 80;
|
|
2852 gui.in_focus = TRUE; /* For the moment -> syn. of front application */
|
|
2853
|
9
|
2854 gScrollAction = NewControlActionUPP(gui_mac_scroll_action);
|
|
2855 gScrollDrag = NewControlActionUPP(gui_mac_drag_thumb);
|
7
|
2856
|
|
2857 dragRectEnbl = FALSE;
|
|
2858 dragRgn = NULL;
|
|
2859 dragRectControl = kCreateEmpty;
|
|
2860 cursorRgn = NewRgn();
|
|
2861 #endif
|
|
2862 #ifdef USE_EXE_NAME
|
|
2863 # ifndef USE_FIND_BUNDLE_PATH
|
9
|
2864 HGetVol(volName, &applVRefNum, &applDirID);
|
7
|
2865 /* TN2015: mention a possible bad VRefNum */
|
9
|
2866 FSMakeFSSpec(applVRefNum, applDirID, "\p", &applDir);
|
7
|
2867 # else
|
|
2868 /* OSErr GetApplicationBundleFSSpec(FSSpecPtr theFSSpecPtr)
|
|
2869 * of TN2015
|
|
2870 * This technic remove the ../Contents/MacOS/etc part
|
|
2871 */
|
9
|
2872 (void)GetCurrentProcess(&psn);
|
7
|
2873 /* if (err != noErr) return err; */
|
|
2874
|
9
|
2875 (void)GetProcessBundleLocation(&psn, &applFSRef);
|
7
|
2876 /* if (err != noErr) return err; */
|
|
2877
|
9
|
2878 (void)FSGetCatalogInfo(&applFSRef, kFSCatInfoNone, NULL, NULL, &applDir, NULL);
|
7
|
2879
|
|
2880 /* This technic return NIL when we disallow_gui */
|
|
2881 # endif
|
9
|
2882 exe_name = FullPathFromFSSpec_save(applDir);
|
7
|
2883 #endif
|
|
2884 }
|
|
2885
|
|
2886 #ifndef ALWAYS_USE_GUI
|
|
2887 /*
|
|
2888 * Check if the GUI can be started. Called before gvimrc is sourced.
|
|
2889 * Return OK or FAIL.
|
|
2890 */
|
|
2891 int
|
|
2892 gui_mch_init_check(void)
|
|
2893 {
|
|
2894 /* TODO: For MacOS X find a way to return FAIL, if the user logged in
|
|
2895 * using the >console
|
|
2896 */
|
|
2897 if (disallow_gui) /* see main.c for reason to disallow */
|
|
2898 return FAIL;
|
|
2899 return OK;
|
|
2900 }
|
|
2901 #endif
|
|
2902
|
|
2903 static OSErr
|
|
2904 receiveHandler(WindowRef theWindow, void* handlerRefCon, DragRef theDrag)
|
|
2905 {
|
|
2906 int x, y;
|
|
2907 int_u modifiers;
|
|
2908 char_u **fnames = NULL;
|
|
2909 int count;
|
|
2910 int i, j;
|
|
2911
|
|
2912 /* Get drop position, modifiers and count of items */
|
|
2913 {
|
|
2914 Point point;
|
|
2915 SInt16 mouseUpModifiers;
|
|
2916 UInt16 countItem;
|
|
2917
|
|
2918 GetDragMouse(theDrag, &point, NULL);
|
|
2919 GlobalToLocal(&point);
|
|
2920 x = point.h;
|
|
2921 y = point.v;
|
|
2922 GetDragModifiers(theDrag, NULL, NULL, &mouseUpModifiers);
|
|
2923 modifiers = EventModifiers2VimMouseModifiers(mouseUpModifiers);
|
|
2924 CountDragItems(theDrag, &countItem);
|
|
2925 count = countItem;
|
|
2926 }
|
|
2927
|
|
2928 fnames = (char_u **)alloc(count * sizeof(char_u *));
|
|
2929 if (fnames == NULL)
|
|
2930 return dragNotAcceptedErr;
|
|
2931
|
|
2932 /* Get file names dropped */
|
|
2933 for (i = j = 0; i < count; ++i)
|
|
2934 {
|
|
2935 DragItemRef item;
|
|
2936 OSErr err;
|
|
2937 Size size;
|
|
2938 FlavorType type = flavorTypeHFS;
|
|
2939 HFSFlavor hfsFlavor;
|
|
2940
|
|
2941 fnames[i] = NULL;
|
|
2942 GetDragItemReferenceNumber(theDrag, i + 1, &item);
|
|
2943 err = GetFlavorDataSize(theDrag, item, type, &size);
|
|
2944 if (err != noErr || size > sizeof(hfsFlavor))
|
|
2945 continue;
|
|
2946 err = GetFlavorData(theDrag, item, type, &hfsFlavor, &size, 0);
|
|
2947 if (err != noErr)
|
|
2948 continue;
|
|
2949 fnames[j++] = FullPathFromFSSpec_save(hfsFlavor.fileSpec);
|
|
2950 }
|
|
2951 count = j;
|
|
2952
|
|
2953 gui_handle_drop(x, y, modifiers, fnames, count);
|
37
|
2954
|
|
2955 /* Fake mouse event to wake from stall */
|
|
2956 PostEvent(mouseUp, 0);
|
|
2957
|
7
|
2958 return noErr;
|
|
2959 }
|
|
2960
|
|
2961 /*
|
|
2962 * Initialise the GUI. Create all the windows, set up all the call-backs
|
|
2963 * etc.
|
|
2964 */
|
|
2965 int
|
593
|
2966 gui_mch_init(void)
|
7
|
2967 {
|
|
2968 /* TODO: Move most of this stuff toward gui_mch_init */
|
|
2969 Rect windRect;
|
|
2970 MenuHandle pomme;
|
|
2971 long gestalt_rc;
|
|
2972 EventTypeSpec eventTypeSpec;
|
|
2973 EventHandlerRef mouseWheelHandlerRef;
|
168
|
2974 #ifdef USE_CARBONKEYHANDLER
|
|
2975 EventHandlerRef keyEventHandlerRef;
|
|
2976 #endif
|
|
2977
|
|
2978 if (Gestalt(gestaltSystemVersion, &gMacSystemVersion) != noErr)
|
593
|
2979 gMacSystemVersion = 0x1000; /* TODO: Default to minimum sensible value */
|
168
|
2980
|
7
|
2981 #if 1
|
|
2982 InitCursor();
|
|
2983
|
|
2984 RegisterAppearanceClient();
|
|
2985
|
|
2986 #ifdef USE_AEVENT
|
|
2987 (void) InstallAEHandlers();
|
|
2988 #endif
|
|
2989
|
593
|
2990 /* Ctrl click */
|
7
|
2991 if (Gestalt(gestaltContextualMenuAttr, &gestalt_rc) == noErr)
|
|
2992 gui.MacOSHaveCntxMenu = BitTst(&gestalt_rc, 31-gestaltContextualMenuTrapAvailable);
|
|
2993 else
|
|
2994 gui.MacOSHaveCntxMenu = false;
|
|
2995
|
|
2996 if (gui.MacOSHaveCntxMenu)
|
|
2997 gui.MacOSHaveCntxMenu = (InitContextualMenus()==noErr);
|
9
|
2998
|
|
2999 pomme = NewMenu(256, "\p\024"); /* 0x14= = Apple Menu */
|
|
3000
|
|
3001 AppendMenu(pomme, "\pAbout VIM");
|
|
3002
|
|
3003 InsertMenu(pomme, 0);
|
7
|
3004
|
|
3005 DrawMenuBar();
|
|
3006
|
|
3007
|
|
3008 #ifndef USE_OFFSETED_WINDOW
|
9
|
3009 SetRect(&windRect, 10, 48, 10+80*7 + 16, 48+24*11);
|
7
|
3010 #else
|
9
|
3011 SetRect(&windRect, 300, 40, 300+80*7 + 16, 40+24*11);
|
7
|
3012 #endif
|
|
3013
|
|
3014 gui.VimWindow = NewCWindow(nil, &windRect, "\pgVim on Macintosh", true,
|
|
3015 zoomDocProc,
|
|
3016 (WindowPtr)-1L, true, 0);
|
|
3017 InstallReceiveHandler((DragReceiveHandlerUPP)receiveHandler,
|
|
3018 gui.VimWindow, NULL);
|
9
|
3019 SetPortWindowPort(gui.VimWindow);
|
7
|
3020
|
|
3021 gui.char_width = 7;
|
|
3022 gui.char_height = 11;
|
|
3023 gui.char_ascent = 6;
|
|
3024 gui.num_rows = 24;
|
|
3025 gui.num_cols = 80;
|
|
3026 gui.in_focus = TRUE; /* For the moment -> syn. of front application */
|
|
3027
|
9
|
3028 gScrollAction = NewControlActionUPP(gui_mac_scroll_action);
|
|
3029 gScrollDrag = NewControlActionUPP(gui_mac_drag_thumb);
|
593
|
3030
|
13
|
3031 /* Install Carbon event callbacks. */
|
|
3032 (void)InstallFontPanelHandler();
|
7
|
3033
|
|
3034 dragRectEnbl = FALSE;
|
|
3035 dragRgn = NULL;
|
|
3036 dragRectControl = kCreateEmpty;
|
|
3037 cursorRgn = NewRgn();
|
|
3038 #endif
|
|
3039 /* Display any pending error messages */
|
|
3040 display_errors();
|
|
3041
|
|
3042 /* Get background/foreground colors from system */
|
|
3043 /* TODO: do the approriate call to get real defaults */
|
|
3044 gui.norm_pixel = 0x00000000;
|
|
3045 gui.back_pixel = 0x00FFFFFF;
|
|
3046
|
|
3047 /* Get the colors from the "Normal" group (set in syntax.c or in a vimrc
|
|
3048 * file). */
|
|
3049 set_normal_colors();
|
|
3050
|
|
3051 /*
|
|
3052 * Check that none of the colors are the same as the background color.
|
|
3053 * Then store the current values as the defaults.
|
|
3054 */
|
|
3055 gui_check_colors();
|
|
3056 gui.def_norm_pixel = gui.norm_pixel;
|
|
3057 gui.def_back_pixel = gui.back_pixel;
|
|
3058
|
|
3059 /* Get the colors for the highlight groups (gui_check_colors() might have
|
|
3060 * changed them) */
|
|
3061 highlight_gui_started();
|
|
3062
|
|
3063 /*
|
|
3064 * Setting the gui constants
|
|
3065 */
|
|
3066 #ifdef FEAT_MENU
|
|
3067 gui.menu_height = 0;
|
|
3068 #endif
|
|
3069 gui.scrollbar_height = gui.scrollbar_width = 15; /* cheat 1 overlap */
|
|
3070 gui.border_offset = gui.border_width = 2;
|
|
3071
|
|
3072 /* If Quartz-style text antialiasing is available (see
|
|
3073 gui_mch_draw_string() below), enable it for all font sizes. */
|
|
3074 vim_setenv((char_u *)"QDTEXT_MINSIZE", (char_u *)"1");
|
593
|
3075
|
7
|
3076 eventTypeSpec.eventClass = kEventClassMouse;
|
|
3077 eventTypeSpec.eventKind = kEventMouseWheelMoved;
|
|
3078 mouseWheelHandlerUPP = NewEventHandlerUPP(gui_mac_mouse_wheel);
|
|
3079 if (noErr != InstallApplicationEventHandler(mouseWheelHandlerUPP, 1,
|
|
3080 &eventTypeSpec, NULL, &mouseWheelHandlerRef))
|
|
3081 {
|
|
3082 mouseWheelHandlerRef = NULL;
|
|
3083 DisposeEventHandlerUPP(mouseWheelHandlerUPP);
|
|
3084 mouseWheelHandlerUPP = NULL;
|
|
3085 }
|
|
3086
|
168
|
3087 #ifdef USE_CARBONKEYHANDLER
|
|
3088 eventTypeSpec.eventClass = kEventClassTextInput;
|
|
3089 eventTypeSpec.eventKind = kEventUnicodeForKeyEvent;
|
|
3090 keyEventHandlerUPP = NewEventHandlerUPP(gui_mac_doKeyEventCarbon);
|
|
3091 if (noErr != InstallApplicationEventHandler(keyEventHandlerUPP, 1,
|
|
3092 &eventTypeSpec, NULL, &keyEventHandlerRef))
|
|
3093 {
|
|
3094 keyEventHandlerRef = NULL;
|
|
3095 DisposeEventHandlerUPP(keyEventHandlerUPP);
|
|
3096 keyEventHandlerUPP = NULL;
|
|
3097 }
|
|
3098 #endif
|
|
3099
|
|
3100 /*
|
7
|
3101 #ifdef FEAT_MBYTE
|
168
|
3102 set_option_value((char_u *)"encoding", 0L, (char_u *)"utf-8", 0);
|
|
3103 #endif
|
|
3104 */
|
7
|
3105
|
|
3106 /* TODO: Load bitmap if using TOOLBAR */
|
|
3107 return OK;
|
|
3108 }
|
|
3109
|
|
3110 /*
|
|
3111 * Called when the foreground or background color has been changed.
|
|
3112 */
|
|
3113 void
|
593
|
3114 gui_mch_new_colors(void)
|
7
|
3115 {
|
|
3116 /* TODO:
|
|
3117 * This proc is called when Normal is set to a value
|
|
3118 * so what msut be done? I don't know
|
|
3119 */
|
|
3120 }
|
|
3121
|
|
3122 /*
|
|
3123 * Open the GUI window which was created by a call to gui_mch_init().
|
|
3124 */
|
|
3125 int
|
593
|
3126 gui_mch_open(void)
|
7
|
3127 {
|
|
3128 ShowWindow(gui.VimWindow);
|
|
3129
|
|
3130 if (gui_win_x != -1 && gui_win_y != -1)
|
|
3131 gui_mch_set_winpos(gui_win_x, gui_win_y);
|
|
3132
|
|
3133 /*
|
|
3134 * Make the GUI the foreground process (in case it was launched
|
|
3135 * from the Terminal or via :gui).
|
|
3136 */
|
|
3137 {
|
|
3138 ProcessSerialNumber psn;
|
|
3139 if (GetCurrentProcess(&psn) == noErr)
|
|
3140 SetFrontProcess(&psn);
|
|
3141 }
|
|
3142
|
|
3143 return OK;
|
|
3144 }
|
|
3145
|
|
3146 void
|
|
3147 gui_mch_exit(int rc)
|
|
3148 {
|
|
3149 /* TODO: find out all what is missing here? */
|
|
3150 DisposeRgn(cursorRgn);
|
|
3151
|
168
|
3152 #ifdef USE_CARBONKEYHANDLER
|
|
3153 if (keyEventHandlerUPP)
|
|
3154 DisposeEventHandlerUPP(keyEventHandlerUPP);
|
|
3155 #endif
|
|
3156
|
7
|
3157 if (mouseWheelHandlerUPP != NULL)
|
|
3158 DisposeEventHandlerUPP(mouseWheelHandlerUPP);
|
|
3159
|
168
|
3160 #ifdef USE_ATSUI_DRAWING
|
|
3161 if (gFontStyle)
|
|
3162 ATSUDisposeStyle(gFontStyle);
|
|
3163 #endif
|
|
3164
|
7
|
3165 /* Exit to shell? */
|
|
3166 exit(rc);
|
|
3167 }
|
|
3168
|
|
3169 /*
|
|
3170 * Get the position of the top left corner of the window.
|
|
3171 */
|
|
3172 int
|
|
3173 gui_mch_get_winpos(int *x, int *y)
|
|
3174 {
|
|
3175 /* TODO */
|
|
3176 Rect bounds;
|
|
3177 OSStatus status;
|
|
3178
|
|
3179 /* Carbon >= 1.0.2, MacOS >= 8.5 */
|
9
|
3180 status = GetWindowBounds(gui.VimWindow, kWindowStructureRgn, &bounds);
|
7
|
3181
|
|
3182 if (status != noErr)
|
|
3183 return FAIL;
|
|
3184 *x = bounds.left;
|
|
3185 *y = bounds.top;
|
|
3186 return OK;
|
|
3187 return FAIL;
|
|
3188 }
|
|
3189
|
|
3190 /*
|
|
3191 * Set the position of the top left corner of the window to the given
|
|
3192 * coordinates.
|
|
3193 */
|
|
3194 void
|
|
3195 gui_mch_set_winpos(int x, int y)
|
|
3196 {
|
|
3197 /* TODO: Should make sure the window is move within range
|
|
3198 * e.g.: y > ~16 [Menu bar], x > 0, x < screen width
|
|
3199 */
|
|
3200 MoveWindow(gui.VimWindow, x, y, TRUE);
|
|
3201 }
|
|
3202
|
|
3203 void
|
|
3204 gui_mch_set_shellsize(
|
|
3205 int width,
|
|
3206 int height,
|
|
3207 int min_width,
|
|
3208 int min_height,
|
|
3209 int base_width,
|
812
|
3210 int base_height,
|
|
3211 int direction)
|
7
|
3212 {
|
|
3213 CGrafPtr VimPort;
|
|
3214 Rect VimBound;
|
|
3215
|
|
3216 if (gui.which_scrollbars[SBAR_LEFT])
|
|
3217 {
|
9
|
3218 VimPort = GetWindowPort(gui.VimWindow);
|
|
3219 GetPortBounds(VimPort, &VimBound);
|
7
|
3220 VimBound.left = -gui.scrollbar_width; /* + 1;*/
|
9
|
3221 SetPortBounds(VimPort, &VimBound);
|
7
|
3222 /* GetWindowBounds(gui.VimWindow, kWindowGlobalPortRgn, &winPortRect); ??*/
|
|
3223 }
|
|
3224 else
|
|
3225 {
|
9
|
3226 VimPort = GetWindowPort(gui.VimWindow);
|
|
3227 GetPortBounds(VimPort, &VimBound);
|
7
|
3228 VimBound.left = 0;
|
9
|
3229 SetPortBounds(VimPort, &VimBound);
|
7
|
3230 }
|
|
3231
|
|
3232 SizeWindow(gui.VimWindow, width, height, TRUE);
|
|
3233
|
|
3234 gui_resize_shell(width, height);
|
|
3235 }
|
|
3236
|
|
3237 /*
|
|
3238 * Get the screen dimensions.
|
|
3239 * Allow 10 pixels for horizontal borders, 40 for vertical borders.
|
|
3240 * Is there no way to find out how wide the borders really are?
|
|
3241 * TODO: Add live udate of those value on suspend/resume.
|
|
3242 */
|
|
3243 void
|
593
|
3244 gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
|
7
|
3245 {
|
|
3246 GDHandle dominantDevice = GetMainDevice();
|
|
3247 Rect screenRect = (**dominantDevice).gdRect;
|
|
3248
|
|
3249 *screen_w = screenRect.right - 10;
|
|
3250 *screen_h = screenRect.bottom - 40;
|
|
3251 }
|
|
3252
|
|
3253
|
13
|
3254 /*
|
|
3255 * Open the Font Panel and wait for the user to select a font and
|
|
3256 * close the panel. Then fill the buffer pointed to by font_name with
|
|
3257 * the name and size of the selected font and return the font's handle,
|
|
3258 * or NOFONT in case of an error.
|
|
3259 */
|
|
3260 static GuiFont
|
|
3261 gui_mac_select_font(char_u *font_name)
|
|
3262 {
|
|
3263 GuiFont selected_font = NOFONT;
|
|
3264 OSStatus status;
|
|
3265 FontSelectionQDStyle curr_font;
|
|
3266
|
|
3267 /* Initialize the Font Panel with the current font. */
|
|
3268 curr_font.instance.fontFamily = gui.norm_font & 0xFFFF;
|
|
3269 curr_font.size = (gui.norm_font >> 16);
|
|
3270 /* TODO: set fontStyle once styles are supported in gui_mac_find_font() */
|
|
3271 curr_font.instance.fontStyle = 0;
|
|
3272 curr_font.hasColor = false;
|
|
3273 curr_font.version = 0; /* version number of the style structure */
|
|
3274 status = SetFontInfoForSelection(kFontSelectionQDType,
|
|
3275 /*numStyles=*/1, &curr_font, /*eventTarget=*/NULL);
|
|
3276
|
|
3277 gFontPanelInfo.family = curr_font.instance.fontFamily;
|
|
3278 gFontPanelInfo.style = curr_font.instance.fontStyle;
|
|
3279 gFontPanelInfo.size = curr_font.size;
|
|
3280
|
|
3281 /* Pop up the Font Panel. */
|
|
3282 status = FPShowHideFontPanel();
|
|
3283 if (status == noErr)
|
|
3284 {
|
|
3285 /*
|
|
3286 * The Font Panel is modeless. We really need it to be modal,
|
|
3287 * so we spin in an event loop until the panel is closed.
|
|
3288 */
|
|
3289 gFontPanelInfo.isPanelVisible = true;
|
|
3290 while (gFontPanelInfo.isPanelVisible)
|
|
3291 {
|
|
3292 EventRecord e;
|
|
3293 WaitNextEvent(everyEvent, &e, /*sleep=*/20, /*mouseRgn=*/NULL);
|
|
3294 }
|
|
3295
|
|
3296 GetFontPanelSelection(font_name);
|
|
3297 selected_font = gui_mac_find_font(font_name);
|
|
3298 }
|
|
3299 return selected_font;
|
|
3300 }
|
|
3301
|
7
|
3302
|
|
3303 /*
|
|
3304 * Initialise vim to use the font with the given name. Return FAIL if the font
|
|
3305 * could not be loaded, OK otherwise.
|
|
3306 */
|
|
3307 int
|
593
|
3308 gui_mch_init_font(char_u *font_name, int fontset)
|
7
|
3309 {
|
|
3310 /* TODO: Add support for bold italic underline proportional etc... */
|
|
3311 Str255 suggestedFont = "\pMonaco";
|
170
|
3312 int suggestedSize = 10;
|
7
|
3313 FontInfo font_info;
|
|
3314 short font_id;
|
|
3315 GuiFont font;
|
37
|
3316 char_u used_font_name[512];
|
7
|
3317
|
168
|
3318 #ifdef USE_ATSUI_DRAWING
|
|
3319 if (gFontStyle == NULL)
|
|
3320 {
|
|
3321 if (ATSUCreateStyle(&gFontStyle) != noErr)
|
|
3322 gFontStyle = NULL;
|
|
3323 }
|
|
3324 #endif
|
|
3325
|
7
|
3326 if (font_name == NULL)
|
|
3327 {
|
|
3328 /* First try to get the suggested font */
|
|
3329 GetFNum(suggestedFont, &font_id);
|
|
3330
|
|
3331 if (font_id == 0)
|
|
3332 {
|
|
3333 /* Then pickup the standard application font */
|
|
3334 font_id = GetAppFont();
|
37
|
3335 STRCPY(used_font_name, "default");
|
7
|
3336 }
|
37
|
3337 else
|
|
3338 STRCPY(used_font_name, "Monaco");
|
7
|
3339 font = (suggestedSize << 16) + ((long) font_id & 0xFFFF);
|
|
3340 }
|
13
|
3341 else if (STRCMP(font_name, "*") == 0)
|
|
3342 {
|
37
|
3343 char_u *new_p_guifont;
|
|
3344
|
|
3345 font = gui_mac_select_font(used_font_name);
|
13
|
3346 if (font == NOFONT)
|
|
3347 return FAIL;
|
|
3348
|
|
3349 /* Set guifont to the name of the selected font. */
|
37
|
3350 new_p_guifont = alloc(STRLEN(used_font_name) + 1);
|
13
|
3351 if (new_p_guifont != NULL)
|
|
3352 {
|
37
|
3353 STRCPY(new_p_guifont, used_font_name);
|
13
|
3354 vim_free(p_guifont);
|
|
3355 p_guifont = new_p_guifont;
|
|
3356 /* Replace spaces in the font name with underscores. */
|
|
3357 for ( ; *new_p_guifont; ++new_p_guifont)
|
|
3358 {
|
|
3359 if (*new_p_guifont == ' ')
|
|
3360 *new_p_guifont = '_';
|
|
3361 }
|
|
3362 }
|
|
3363 }
|
7
|
3364 else
|
|
3365 {
|
9
|
3366 font = gui_mac_find_font(font_name);
|
418
|
3367 vim_strncpy(used_font_name, font_name, sizeof(used_font_name) - 1);
|
7
|
3368
|
|
3369 if (font == NOFONT)
|
|
3370 return FAIL;
|
|
3371 }
|
37
|
3372
|
7
|
3373 gui.norm_font = font;
|
|
3374
|
37
|
3375 hl_set_font_name(used_font_name);
|
|
3376
|
9
|
3377 TextSize(font >> 16);
|
|
3378 TextFont(font & 0xFFFF);
|
|
3379
|
189
|
3380 GetFontInfo(&font_info);
|
|
3381
|
|
3382 gui.char_ascent = font_info.ascent;
|
|
3383 gui.char_width = CharWidth('_');
|
|
3384 gui.char_height = font_info.ascent + font_info.descent + p_linespace;
|
|
3385
|
168
|
3386 #ifdef USE_ATSUI_DRAWING
|
|
3387 ATSUFontID fontID;
|
|
3388 Fixed fontSize;
|
|
3389 ATSStyleRenderingOptions fontOptions;
|
|
3390
|
|
3391 if (gFontStyle)
|
|
3392 {
|
|
3393 fontID = font & 0xFFFF;
|
|
3394 fontSize = Long2Fix(font >> 16);
|
|
3395
|
|
3396 /* No antialiasing by default (do not attempt to touch antialising
|
|
3397 * options on pre-Jaguar) */
|
|
3398 fontOptions =
|
|
3399 (gMacSystemVersion >= 0x1020) ?
|
|
3400 kATSStyleNoAntiAliasing :
|
|
3401 kATSStyleNoOptions;
|
|
3402
|
|
3403 ATSUAttributeTag attribTags[] =
|
|
3404 {
|
|
3405 kATSUFontTag, kATSUSizeTag, kATSUStyleRenderingOptionsTag,
|
|
3406 kATSUMaxATSUITagValue+1
|
|
3407 };
|
|
3408 ByteCount attribSizes[] =
|
|
3409 {
|
|
3410 sizeof(ATSUFontID), sizeof(Fixed),
|
|
3411 sizeof(ATSStyleRenderingOptions), sizeof font
|
|
3412 };
|
|
3413 ATSUAttributeValuePtr attribValues[] =
|
|
3414 {
|
|
3415 &fontID, &fontSize, &fontOptions, &font
|
|
3416 };
|
|
3417
|
|
3418 /* Convert font id to ATSUFontID */
|
|
3419 if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr)
|
|
3420 {
|
|
3421 if (ATSUSetAttributes(gFontStyle,
|
|
3422 (sizeof attribTags)/sizeof(ATSUAttributeTag),
|
|
3423 attribTags, attribSizes, attribValues) != noErr)
|
|
3424 {
|
|
3425 ATSUDisposeStyle(gFontStyle);
|
|
3426 gFontStyle = NULL;
|
|
3427 }
|
|
3428 }
|
|
3429 }
|
|
3430 #endif
|
|
3431
|
7
|
3432 return OK;
|
|
3433 }
|
|
3434
|
444
|
3435 /*
|
|
3436 * Adjust gui.char_height (after 'linespace' was changed).
|
|
3437 */
|
7
|
3438 int
|
593
|
3439 gui_mch_adjust_charheight(void)
|
7
|
3440 {
|
|
3441 FontInfo font_info;
|
|
3442
|
9
|
3443 GetFontInfo(&font_info);
|
7
|
3444 gui.char_height = font_info.ascent + font_info.descent + p_linespace;
|
|
3445 gui.char_ascent = font_info.ascent + p_linespace / 2;
|
|
3446 return OK;
|
|
3447 }
|
|
3448
|
|
3449 /*
|
|
3450 * Get a font structure for highlighting.
|
|
3451 */
|
|
3452 GuiFont
|
593
|
3453 gui_mch_get_font(char_u *name, int giveErrorIfMissing)
|
7
|
3454 {
|
|
3455 GuiFont font;
|
|
3456
|
|
3457 font = gui_mac_find_font(name);
|
|
3458
|
|
3459 if (font == NOFONT)
|
|
3460 {
|
|
3461 if (giveErrorIfMissing)
|
|
3462 EMSG2(_(e_font), name);
|
|
3463 return NOFONT;
|
|
3464 }
|
|
3465 /*
|
|
3466 * TODO : Accept only monospace
|
|
3467 */
|
|
3468
|
|
3469 return font;
|
|
3470 }
|
|
3471
|
44
|
3472 #if defined(FEAT_EVAL) || defined(PROTO)
|
7
|
3473 /*
|
37
|
3474 * Return the name of font "font" in allocated memory.
|
|
3475 * Don't know how to get the actual name, thus use the provided name.
|
|
3476 */
|
|
3477 char_u *
|
593
|
3478 gui_mch_get_fontname(GuiFont font, char_u *name)
|
37
|
3479 {
|
|
3480 if (name == NULL)
|
|
3481 return NULL;
|
|
3482 return vim_strsave(name);
|
|
3483 }
|
44
|
3484 #endif
|
37
|
3485
|
|
3486 /*
|
7
|
3487 * Set the current text font.
|
|
3488 */
|
|
3489 void
|
593
|
3490 gui_mch_set_font(GuiFont font)
|
7
|
3491 {
|
168
|
3492 #ifdef USE_ATSUI_DRAWING
|
|
3493 GuiFont currFont;
|
|
3494 ByteCount actualFontByteCount;
|
|
3495 ATSUFontID fontID;
|
|
3496 Fixed fontSize;
|
|
3497 ATSStyleRenderingOptions fontOptions;
|
|
3498
|
|
3499 if (gFontStyle)
|
|
3500 {
|
|
3501 /* Avoid setting same font again */
|
|
3502 if (ATSUGetAttribute(gFontStyle, kATSUMaxATSUITagValue+1, sizeof font,
|
|
3503 &currFont, &actualFontByteCount) == noErr &&
|
|
3504 actualFontByteCount == (sizeof font))
|
|
3505 {
|
|
3506 if (currFont == font)
|
|
3507 return;
|
|
3508 }
|
|
3509
|
|
3510 fontID = font & 0xFFFF;
|
|
3511 fontSize = Long2Fix(font >> 16);
|
|
3512 /* Respect p_antialias setting only for wide font.
|
|
3513 * The reason for doing this at the moment is a bit complicated,
|
|
3514 * but it's mainly because a) latin (non-wide) aliased fonts
|
|
3515 * look bad in OS X 10.3.x and below (due to a bug in ATS), and
|
|
3516 * b) wide multibyte input does not suffer from that problem. */
|
593
|
3517 /*fontOptions =
|
168
|
3518 (p_antialias && (font == gui.wide_font)) ?
|
|
3519 kATSStyleNoOptions : kATSStyleNoAntiAliasing;
|
593
|
3520 */
|
|
3521 /*fontOptions = kATSStyleAntiAliasing;*/
|
168
|
3522
|
|
3523 ATSUAttributeTag attribTags[] =
|
|
3524 {
|
|
3525 kATSUFontTag, kATSUSizeTag, kATSUStyleRenderingOptionsTag,
|
|
3526 kATSUMaxATSUITagValue+1
|
|
3527 };
|
|
3528 ByteCount attribSizes[] =
|
|
3529 {
|
|
3530 sizeof(ATSUFontID), sizeof(Fixed),
|
|
3531 sizeof(ATSStyleRenderingOptions), sizeof font
|
|
3532 };
|
|
3533 ATSUAttributeValuePtr attribValues[] =
|
|
3534 {
|
|
3535 &fontID, &fontSize, &fontOptions, &font
|
|
3536 };
|
|
3537
|
|
3538 if (FMGetFontFromFontFamilyInstance(fontID, 0, &fontID, NULL) == noErr)
|
|
3539 {
|
|
3540 if (ATSUSetAttributes(gFontStyle,
|
|
3541 (sizeof attribTags)/sizeof(ATSUAttributeTag),
|
|
3542 attribTags, attribSizes, attribValues) != noErr)
|
|
3543 {
|
|
3544 #ifndef NDEBUG
|
|
3545 fprintf(stderr, "couldn't set font style\n");
|
|
3546 #endif
|
|
3547 ATSUDisposeStyle(gFontStyle);
|
|
3548 gFontStyle = NULL;
|
|
3549 }
|
|
3550 }
|
|
3551
|
|
3552 }
|
|
3553
|
|
3554 if (!gIsFontFallbackSet)
|
|
3555 {
|
|
3556 /* Setup automatic font substitution. The user's guifontwide
|
|
3557 * is tried first, then the system tries other fonts. */
|
|
3558 /*
|
|
3559 ATSUAttributeTag fallbackTags[] = { kATSULineFontFallbacksTag };
|
|
3560 ByteCount fallbackSizes[] = { sizeof(ATSUFontFallbacks) };
|
|
3561 ATSUCreateFontFallbacks(&gFontFallbacks);
|
|
3562 ATSUSetObjFontFallbacks(gFontFallbacks, );
|
|
3563 */
|
|
3564 if (gui.wide_font)
|
|
3565 {
|
|
3566 ATSUFontID fallbackFonts;
|
|
3567 gIsFontFallbackSet = TRUE;
|
|
3568
|
|
3569 if (FMGetFontFromFontFamilyInstance(
|
|
3570 (gui.wide_font & 0xFFFF),
|
|
3571 0,
|
|
3572 &fallbackFonts,
|
|
3573 NULL) == noErr)
|
|
3574 {
|
|
3575 ATSUSetFontFallbacks((sizeof fallbackFonts)/sizeof(ATSUFontID), &fallbackFonts, kATSUSequentialFallbacksPreferred);
|
|
3576 }
|
|
3577 /*
|
|
3578 ATSUAttributeValuePtr fallbackValues[] = { };
|
|
3579 */
|
|
3580 }
|
|
3581 }
|
|
3582 #endif
|
7
|
3583 TextSize(font >> 16);
|
|
3584 TextFont(font & 0xFFFF);
|
|
3585 }
|
|
3586
|
|
3587 /*
|
|
3588 * If a font is not going to be used, free its structure.
|
|
3589 */
|
|
3590 void
|
|
3591 gui_mch_free_font(font)
|
|
3592 GuiFont font;
|
|
3593 {
|
|
3594 /*
|
|
3595 * Free font when "font" is not 0.
|
|
3596 * Nothing to do in the current implementation, since
|
|
3597 * nothing is allocated for each font used.
|
|
3598 */
|
|
3599 }
|
|
3600
|
|
3601 static int
|
593
|
3602 hex_digit(int c)
|
7
|
3603 {
|
|
3604 if (isdigit(c))
|
|
3605 return c - '0';
|
|
3606 c = TOLOWER_ASC(c);
|
|
3607 if (c >= 'a' && c <= 'f')
|
|
3608 return c - 'a' + 10;
|
|
3609 return -1000;
|
|
3610 }
|
|
3611
|
|
3612 /*
|
|
3613 * Return the Pixel value (color) for the given color name. This routine was
|
|
3614 * pretty much taken from example code in the Silicon Graphics OSF/Motif
|
|
3615 * Programmer's Guide.
|
|
3616 * Return INVALCOLOR when failed.
|
|
3617 */
|
|
3618 guicolor_T
|
593
|
3619 gui_mch_get_color(char_u *name)
|
7
|
3620 {
|
|
3621 /* TODO: Add support for the new named color of MacOS 8
|
|
3622 */
|
|
3623 RGBColor MacColor;
|
|
3624 // guicolor_T color = 0;
|
|
3625
|
|
3626 typedef struct guicolor_tTable
|
|
3627 {
|
|
3628 char *name;
|
|
3629 guicolor_T color;
|
|
3630 } guicolor_tTable;
|
|
3631
|
|
3632 /*
|
|
3633 * The comment at the end of each line is the source
|
|
3634 * (Mac, Window, Unix) and the number is the unix rgb.txt value
|
|
3635 */
|
|
3636 static guicolor_tTable table[] =
|
|
3637 {
|
|
3638 {"Black", RGB(0x00, 0x00, 0x00)},
|
|
3639 {"darkgray", RGB(0x80, 0x80, 0x80)}, /*W*/
|
|
3640 {"darkgrey", RGB(0x80, 0x80, 0x80)}, /*W*/
|
|
3641 {"Gray", RGB(0xC0, 0xC0, 0xC0)}, /*W*/
|
|
3642 {"Grey", RGB(0xC0, 0xC0, 0xC0)}, /*W*/
|
|
3643 {"lightgray", RGB(0xE0, 0xE0, 0xE0)}, /*W*/
|
|
3644 {"lightgrey", RGB(0xE0, 0xE0, 0xE0)}, /*W*/
|
818
|
3645 {"gray90", RGB(0xE5, 0xE5, 0xE5)}, /*W*/
|
|
3646 {"grey90", RGB(0xE5, 0xE5, 0xE5)}, /*W*/
|
7
|
3647 {"white", RGB(0xFF, 0xFF, 0xFF)},
|
|
3648 {"darkred", RGB(0x80, 0x00, 0x00)}, /*W*/
|
|
3649 {"red", RGB(0xDD, 0x08, 0x06)}, /*M*/
|
|
3650 {"lightred", RGB(0xFF, 0xA0, 0xA0)}, /*W*/
|
|
3651 {"DarkBlue", RGB(0x00, 0x00, 0x80)}, /*W*/
|
|
3652 {"Blue", RGB(0x00, 0x00, 0xD4)}, /*M*/
|
|
3653 {"lightblue", RGB(0xA0, 0xA0, 0xFF)}, /*W*/
|
|
3654 {"DarkGreen", RGB(0x00, 0x80, 0x00)}, /*W*/
|
|
3655 {"Green", RGB(0x00, 0x64, 0x11)}, /*M*/
|
|
3656 {"lightgreen", RGB(0xA0, 0xFF, 0xA0)}, /*W*/
|
|
3657 {"DarkCyan", RGB(0x00, 0x80, 0x80)}, /*W ?0x307D7E */
|
|
3658 {"cyan", RGB(0x02, 0xAB, 0xEA)}, /*M*/
|
|
3659 {"lightcyan", RGB(0xA0, 0xFF, 0xFF)}, /*W*/
|
|
3660 {"darkmagenta", RGB(0x80, 0x00, 0x80)}, /*W*/
|
|
3661 {"magenta", RGB(0xF2, 0x08, 0x84)}, /*M*/
|
|
3662 {"lightmagenta",RGB(0xF0, 0xA0, 0xF0)}, /*W*/
|
|
3663 {"brown", RGB(0x80, 0x40, 0x40)}, /*W*/
|
|
3664 {"yellow", RGB(0xFC, 0xF3, 0x05)}, /*M*/
|
|
3665 {"lightyellow", RGB(0xFF, 0xFF, 0xA0)}, /*M*/
|
308
|
3666 {"darkyellow", RGB(0xBB, 0xBB, 0x00)}, /*U*/
|
7
|
3667 {"SeaGreen", RGB(0x2E, 0x8B, 0x57)}, /*W 0x4E8975 */
|
|
3668 {"orange", RGB(0xFC, 0x80, 0x00)}, /*W 0xF87A17 */
|
|
3669 {"Purple", RGB(0xA0, 0x20, 0xF0)}, /*W 0x8e35e5 */
|
|
3670 {"SlateBlue", RGB(0x6A, 0x5A, 0xCD)}, /*W 0x737CA1 */
|
|
3671 {"Violet", RGB(0x8D, 0x38, 0xC9)}, /*U*/
|
|
3672 };
|
|
3673
|
|
3674 int r, g, b;
|
|
3675 int i;
|
|
3676
|
|
3677 if (name[0] == '#' && strlen((char *) name) == 7)
|
|
3678 {
|
|
3679 /* Name is in "#rrggbb" format */
|
|
3680 r = hex_digit(name[1]) * 16 + hex_digit(name[2]);
|
|
3681 g = hex_digit(name[3]) * 16 + hex_digit(name[4]);
|
|
3682 b = hex_digit(name[5]) * 16 + hex_digit(name[6]);
|
|
3683 if (r < 0 || g < 0 || b < 0)
|
|
3684 return INVALCOLOR;
|
|
3685 return RGB(r, g, b);
|
|
3686 }
|
|
3687 else
|
|
3688 {
|
9
|
3689 if (STRICMP(name, "hilite") == 0)
|
7
|
3690 {
|
9
|
3691 LMGetHiliteRGB(&MacColor);
|
|
3692 return (RGB(MacColor.red >> 8, MacColor.green >> 8, MacColor.blue >> 8));
|
7
|
3693 }
|
|
3694 /* Check if the name is one of the colors we know */
|
|
3695 for (i = 0; i < sizeof(table) / sizeof(table[0]); i++)
|
|
3696 if (STRICMP(name, table[i].name) == 0)
|
|
3697 return table[i].color;
|
|
3698 }
|
|
3699
|
|
3700 /*
|
|
3701 * Last attempt. Look in the file "$VIM/rgb.txt".
|
|
3702 */
|
|
3703 {
|
|
3704 #define LINE_LEN 100
|
|
3705 FILE *fd;
|
|
3706 char line[LINE_LEN];
|
|
3707 char_u *fname;
|
|
3708
|
|
3709 fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt");
|
|
3710 if (fname == NULL)
|
|
3711 return INVALCOLOR;
|
|
3712
|
|
3713 fd = fopen((char *)fname, "rt");
|
|
3714 vim_free(fname);
|
|
3715 if (fd == NULL)
|
|
3716 return INVALCOLOR;
|
|
3717
|
|
3718 while (!feof(fd))
|
|
3719 {
|
|
3720 int len;
|
|
3721 int pos;
|
|
3722 char *color;
|
|
3723
|
|
3724 fgets(line, LINE_LEN, fd);
|
|
3725 len = strlen(line);
|
|
3726
|
|
3727 if (len <= 1 || line[len-1] != '\n')
|
|
3728 continue;
|
|
3729
|
|
3730 line[len-1] = '\0';
|
|
3731
|
|
3732 i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos);
|
|
3733 if (i != 3)
|
|
3734 continue;
|
|
3735
|
|
3736 color = line + pos;
|
|
3737
|
|
3738 if (STRICMP(color, name) == 0)
|
|
3739 {
|
|
3740 fclose(fd);
|
|
3741 return (guicolor_T) RGB(r, g, b);
|
|
3742 }
|
|
3743 }
|
|
3744 fclose(fd);
|
|
3745 }
|
|
3746
|
|
3747 return INVALCOLOR;
|
|
3748 }
|
|
3749
|
|
3750 /*
|
|
3751 * Set the current text foreground color.
|
|
3752 */
|
|
3753 void
|
593
|
3754 gui_mch_set_fg_color(guicolor_T color)
|
7
|
3755 {
|
|
3756 RGBColor TheColor;
|
|
3757
|
|
3758 TheColor.red = Red(color) * 0x0101;
|
|
3759 TheColor.green = Green(color) * 0x0101;
|
|
3760 TheColor.blue = Blue(color) * 0x0101;
|
|
3761
|
9
|
3762 RGBForeColor(&TheColor);
|
7
|
3763 }
|
|
3764
|
|
3765 /*
|
|
3766 * Set the current text background color.
|
|
3767 */
|
|
3768 void
|
593
|
3769 gui_mch_set_bg_color(guicolor_T color)
|
7
|
3770 {
|
|
3771 RGBColor TheColor;
|
|
3772
|
|
3773 TheColor.red = Red(color) * 0x0101;
|
|
3774 TheColor.green = Green(color) * 0x0101;
|
|
3775 TheColor.blue = Blue(color) * 0x0101;
|
|
3776
|
9
|
3777 RGBBackColor(&TheColor);
|
7
|
3778 }
|
|
3779
|
563
|
3780 RGBColor specialColor;
|
|
3781
|
212
|
3782 /*
|
563
|
3783 * Set the current text special color.
|
212
|
3784 */
|
|
3785 void
|
593
|
3786 gui_mch_set_sp_color(guicolor_T color)
|
212
|
3787 {
|
563
|
3788 specialColor.red = Red(color) * 0x0101;
|
|
3789 specialColor.green = Green(color) * 0x0101;
|
|
3790 specialColor.blue = Blue(color) * 0x0101;
|
|
3791 }
|
|
3792
|
|
3793 /*
|
|
3794 * Draw undercurl at the bottom of the character cell.
|
|
3795 */
|
|
3796 static void
|
|
3797 draw_undercurl(int flags, int row, int col, int cells)
|
|
3798 {
|
593
|
3799 int x;
|
563
|
3800 int offset;
|
|
3801 const static int val[8] = {1, 0, 0, 0, 1, 2, 2, 2 };
|
|
3802 int y = FILL_Y(row + 1) - 1;
|
|
3803
|
|
3804 RGBForeColor(&specialColor);
|
|
3805
|
|
3806 offset = val[FILL_X(col) % 8];
|
|
3807 MoveTo(FILL_X(col), y - offset);
|
|
3808
|
593
|
3809 for (x = FILL_X(col); x < FILL_X(col + cells); ++x)
|
563
|
3810 {
|
593
|
3811 offset = val[x % 8];
|
|
3812 LineTo(x, y - offset);
|
563
|
3813 }
|
212
|
3814 }
|
|
3815
|
593
|
3816 #ifndef USE_ATSUI_DRAWING
|
|
3817
|
|
3818 static void
|
|
3819 draw_string_QD(int row, int col, char_u *s, int len, int flags)
|
7
|
3820 {
|
|
3821 #ifdef FEAT_MBYTE
|
|
3822 char_u *tofree = NULL;
|
|
3823
|
|
3824 if (output_conv.vc_type != CONV_NONE)
|
|
3825 {
|
|
3826 tofree = string_convert(&output_conv, s, &len);
|
|
3827 if (tofree != NULL)
|
|
3828 s = tofree;
|
|
3829 }
|
|
3830 #endif
|
593
|
3831
|
7
|
3832 /*
|
|
3833 * On OS X, try using Quartz-style text antialiasing.
|
|
3834 */
|
189
|
3835 if (gMacSystemVersion >= 0x1020)
|
7
|
3836 {
|
|
3837 /* Quartz antialiasing is available only in OS 10.2 and later. */
|
|
3838 UInt32 qd_flags = (p_antialias ?
|
|
3839 kQDUseCGTextRendering | kQDUseCGTextMetrics : 0);
|
168
|
3840 QDSwapTextFlags(qd_flags);
|
7
|
3841 }
|
|
3842
|
36
|
3843 /*
|
|
3844 * When antialiasing we're using srcOr mode, we have to clear the block
|
|
3845 * before drawing the text.
|
|
3846 * Also needed when 'linespace' is non-zero to remove the cursor and
|
|
3847 * underlining.
|
|
3848 * But not when drawing transparently.
|
|
3849 * The following is like calling gui_mch_clear_block(row, col, row, col +
|
|
3850 * len - 1), but without setting the bg color to gui.back_pixel.
|
|
3851 */
|
189
|
3852 if (((gMacSystemVersion >= 0x1020 && p_antialias) || p_linespace != 0)
|
36
|
3853 && !(flags & DRAW_TRANSP))
|
|
3854 {
|
|
3855 Rect rc;
|
|
3856
|
|
3857 rc.left = FILL_X(col);
|
|
3858 rc.top = FILL_Y(row);
|
168
|
3859 #ifdef FEAT_MBYTE
|
|
3860 /* Multibyte computation taken from gui_w32.c */
|
|
3861 if (has_mbyte)
|
|
3862 {
|
|
3863 int cell_len = 0;
|
|
3864 int n;
|
|
3865
|
|
3866 /* Compute the length in display cells. */
|
|
3867 for (n = 0; n < len; n += MB_BYTE2LEN(s[n]))
|
|
3868 cell_len += (*mb_ptr2cells)(s + n);
|
|
3869 rc.right = FILL_X(col + cell_len);
|
|
3870 }
|
|
3871 else
|
|
3872 #endif
|
36
|
3873 rc.right = FILL_X(col + len) + (col + len == Columns);
|
|
3874 rc.bottom = FILL_Y(row + 1);
|
|
3875 EraseRect(&rc);
|
|
3876 }
|
|
3877
|
189
|
3878 if (gMacSystemVersion >= 0x1020 && p_antialias)
|
7
|
3879 {
|
|
3880 StyleParameter face;
|
|
3881
|
|
3882 face = normal;
|
|
3883 if (flags & DRAW_BOLD)
|
|
3884 face |= bold;
|
|
3885 if (flags & DRAW_UNDERL)
|
|
3886 face |= underline;
|
|
3887 TextFace(face);
|
|
3888
|
|
3889 /* Quartz antialiasing works only in srcOr transfer mode. */
|
|
3890 TextMode(srcOr);
|
|
3891
|
|
3892 MoveTo(TEXT_X(col), TEXT_Y(row));
|
|
3893 DrawText((char*)s, 0, len);
|
|
3894 }
|
|
3895 else
|
|
3896 {
|
|
3897 /* Use old-style, non-antialiased QuickDraw text rendering. */
|
9
|
3898 TextMode(srcCopy);
|
|
3899 TextFace(normal);
|
7
|
3900
|
|
3901 /* SelectFont(hdc, gui.currFont); */
|
|
3902
|
|
3903 if (flags & DRAW_TRANSP)
|
|
3904 {
|
9
|
3905 TextMode(srcOr);
|
7
|
3906 }
|
|
3907
|
9
|
3908 MoveTo(TEXT_X(col), TEXT_Y(row));
|
593
|
3909 DrawText((char *)s, 0, len);
|
|
3910
|
|
3911 if (flags & DRAW_BOLD)
|
|
3912 {
|
|
3913 TextMode(srcOr);
|
|
3914 MoveTo(TEXT_X(col) + 1, TEXT_Y(row));
|
|
3915 DrawText((char *)s, 0, len);
|
|
3916 }
|
|
3917
|
|
3918 if (flags & DRAW_UNDERL)
|
|
3919 {
|
|
3920 MoveTo(FILL_X(col), FILL_Y(row + 1) - 1);
|
|
3921 LineTo(FILL_X(col + len) - 1, FILL_Y(row + 1) - 1);
|
|
3922 }
|
|
3923 }
|
|
3924
|
|
3925 if (flags & DRAW_UNDERC)
|
|
3926 draw_undercurl(flags, row, col, len);
|
|
3927
|
|
3928 #ifdef FEAT_MBYTE
|
|
3929 vim_free(tofree);
|
|
3930 #endif
|
|
3931 }
|
|
3932
|
|
3933 #else /* USE_ATSUI_DRAWING */
|
|
3934
|
|
3935 static void
|
|
3936 draw_string_ATSUI(int row, int col, char_u *s, int len, int flags)
|
|
3937 {
|
|
3938 /* ATSUI requires utf-16 strings */
|
|
3939 UniCharCount utf16_len;
|
|
3940 UniChar *tofree = mac_enc_to_utf16(s, len, (size_t *)&utf16_len);
|
|
3941 utf16_len /= sizeof(UniChar);
|
|
3942
|
|
3943 /* - ATSUI automatically antialiases text (Someone)
|
|
3944 * - for some reason it does not work... (Jussi) */
|
|
3945
|
|
3946 /*
|
|
3947 * When antialiasing we're using srcOr mode, we have to clear the block
|
|
3948 * before drawing the text.
|
|
3949 * Also needed when 'linespace' is non-zero to remove the cursor and
|
|
3950 * underlining.
|
|
3951 * But not when drawing transparently.
|
|
3952 * The following is like calling gui_mch_clear_block(row, col, row, col +
|
|
3953 * len - 1), but without setting the bg color to gui.back_pixel.
|
|
3954 */
|
|
3955 if ((flags & DRAW_TRANSP) == 0)
|
|
3956 {
|
|
3957 Rect rc;
|
|
3958
|
|
3959 rc.left = FILL_X(col);
|
|
3960 rc.top = FILL_Y(row);
|
|
3961 /* Multibyte computation taken from gui_w32.c */
|
|
3962 if (has_mbyte)
|
|
3963 {
|
|
3964 int cell_len = 0;
|
|
3965 int n;
|
|
3966
|
|
3967 /* Compute the length in display cells. */
|
|
3968 for (n = 0; n < len; n += MB_BYTE2LEN(s[n]))
|
|
3969 cell_len += (*mb_ptr2cells)(s + n);
|
|
3970 rc.right = FILL_X(col + cell_len);
|
|
3971 }
|
|
3972 else
|
|
3973 rc.right = FILL_X(col + len) + (col + len == Columns);
|
|
3974
|
|
3975 rc.bottom = FILL_Y(row + 1);
|
|
3976 EraseRect(&rc);
|
|
3977 }
|
|
3978
|
|
3979 {
|
|
3980 /* Use old-style, non-antialiased QuickDraw text rendering. */
|
|
3981 TextMode(srcCopy);
|
|
3982 TextFace(normal);
|
|
3983
|
|
3984 /* SelectFont(hdc, gui.currFont); */
|
|
3985
|
|
3986 if (flags & DRAW_TRANSP)
|
|
3987 {
|
|
3988 TextMode(srcOr);
|
|
3989 }
|
|
3990
|
|
3991 MoveTo(TEXT_X(col), TEXT_Y(row));
|
168
|
3992 ATSUTextLayout textLayout;
|
|
3993
|
|
3994 if (ATSUCreateTextLayoutWithTextPtr(tofree,
|
|
3995 kATSUFromTextBeginning, kATSUToTextEnd,
|
|
3996 utf16_len,
|
|
3997 (gFontStyle ? 1 : 0), &utf16_len,
|
|
3998 (gFontStyle ? &gFontStyle : NULL),
|
|
3999 &textLayout) == noErr)
|
|
4000 {
|
|
4001 ATSUSetTransientFontMatching(textLayout, TRUE);
|
|
4002
|
|
4003 ATSUDrawText(textLayout,
|
|
4004 kATSUFromTextBeginning, kATSUToTextEnd,
|
|
4005 kATSUUseGrafPortPenLoc, kATSUUseGrafPortPenLoc);
|
|
4006
|
|
4007 ATSUDisposeTextLayout(textLayout);
|
|
4008 }
|
7
|
4009 }
|
|
4010
|
563
|
4011 if (flags & DRAW_UNDERC)
|
|
4012 draw_undercurl(flags, row, col, len);
|
|
4013
|
7
|
4014 vim_free(tofree);
|
593
|
4015 }
|
|
4016 #endif
|
|
4017
|
|
4018 void
|
|
4019 gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
|
|
4020 {
|
|
4021 #if defined(USE_ATSUI_DRAWING)
|
|
4022 draw_string_ATSUI(row, col, s, len, flags);
|
|
4023 #else
|
|
4024 draw_string_QD(row, col, s, len, flags);
|
7
|
4025 #endif
|
|
4026 }
|
|
4027
|
|
4028 /*
|
|
4029 * Return OK if the key with the termcap name "name" is supported.
|
|
4030 */
|
|
4031 int
|
593
|
4032 gui_mch_haskey(char_u *name)
|
7
|
4033 {
|
|
4034 int i;
|
|
4035
|
|
4036 for (i = 0; special_keys[i].key_sym != (KeySym)0; i++)
|
|
4037 if (name[0] == special_keys[i].vim_code0 &&
|
|
4038 name[1] == special_keys[i].vim_code1)
|
|
4039 return OK;
|
|
4040 return FAIL;
|
|
4041 }
|
|
4042
|
|
4043 void
|
593
|
4044 gui_mch_beep(void)
|
7
|
4045 {
|
9
|
4046 SysBeep(1); /* Should this be 0? (????) */
|
7
|
4047 }
|
|
4048
|
|
4049 void
|
593
|
4050 gui_mch_flash(int msec)
|
7
|
4051 {
|
|
4052 /* Do a visual beep by reversing the foreground and background colors */
|
|
4053 Rect rc;
|
|
4054
|
|
4055 /*
|
|
4056 * Note: InvertRect() excludes right and bottom of rectangle.
|
|
4057 */
|
|
4058 rc.left = 0;
|
|
4059 rc.top = 0;
|
|
4060 rc.right = gui.num_cols * gui.char_width;
|
|
4061 rc.bottom = gui.num_rows * gui.char_height;
|
|
4062 InvertRect(&rc);
|
|
4063
|
|
4064 ui_delay((long)msec, TRUE); /* wait for some msec */
|
|
4065
|
|
4066 InvertRect(&rc);
|
|
4067 }
|
|
4068
|
|
4069 /*
|
|
4070 * Invert a rectangle from row r, column c, for nr rows and nc columns.
|
|
4071 */
|
|
4072 void
|
593
|
4073 gui_mch_invert_rectangle(int r, int c, int nr, int nc)
|
7
|
4074 {
|
|
4075 Rect rc;
|
|
4076
|
|
4077 /*
|
|
4078 * Note: InvertRect() excludes right and bottom of rectangle.
|
|
4079 */
|
|
4080 rc.left = FILL_X(c);
|
|
4081 rc.top = FILL_Y(r);
|
|
4082 rc.right = rc.left + nc * gui.char_width;
|
|
4083 rc.bottom = rc.top + nr * gui.char_height;
|
|
4084 InvertRect(&rc);
|
|
4085 }
|
|
4086
|
|
4087 /*
|
|
4088 * Iconify the GUI window.
|
|
4089 */
|
|
4090 void
|
593
|
4091 gui_mch_iconify(void)
|
7
|
4092 {
|
|
4093 /* TODO: find out what could replace iconify
|
|
4094 * -window shade?
|
|
4095 * -hide application?
|
|
4096 */
|
|
4097 }
|
|
4098
|
|
4099 #if defined(FEAT_EVAL) || defined(PROTO)
|
|
4100 /*
|
|
4101 * Bring the Vim window to the foreground.
|
|
4102 */
|
|
4103 void
|
593
|
4104 gui_mch_set_foreground(void)
|
7
|
4105 {
|
|
4106 /* TODO */
|
|
4107 }
|
|
4108 #endif
|
|
4109
|
|
4110 /*
|
|
4111 * Draw a cursor without focus.
|
|
4112 */
|
|
4113 void
|
593
|
4114 gui_mch_draw_hollow_cursor(guicolor_T color)
|
7
|
4115 {
|
|
4116 Rect rc;
|
|
4117
|
|
4118 /*
|
|
4119 * Note: FrameRect() excludes right and bottom of rectangle.
|
|
4120 */
|
|
4121 rc.left = FILL_X(gui.col);
|
|
4122 rc.top = FILL_Y(gui.row);
|
|
4123 rc.right = rc.left + gui.char_width;
|
168
|
4124 #ifdef FEAT_MBYTE
|
|
4125 if (mb_lefthalve(gui.row, gui.col))
|
|
4126 rc.right += gui.char_width;
|
|
4127 #endif
|
7
|
4128 rc.bottom = rc.top + gui.char_height;
|
|
4129
|
|
4130 gui_mch_set_fg_color(color);
|
|
4131
|
9
|
4132 FrameRect(&rc);
|
7
|
4133 }
|
|
4134
|
|
4135 /*
|
|
4136 * Draw part of a cursor, only w pixels wide, and h pixels high.
|
|
4137 */
|
|
4138 void
|
593
|
4139 gui_mch_draw_part_cursor(int w, int h, guicolor_T color)
|
7
|
4140 {
|
|
4141 Rect rc;
|
|
4142
|
|
4143 #ifdef FEAT_RIGHTLEFT
|
|
4144 /* vertical line should be on the right of current point */
|
|
4145 if (CURSOR_BAR_RIGHT)
|
|
4146 rc.left = FILL_X(gui.col + 1) - w;
|
|
4147 else
|
|
4148 #endif
|
|
4149 rc.left = FILL_X(gui.col);
|
|
4150 rc.top = FILL_Y(gui.row) + gui.char_height - h;
|
|
4151 rc.right = rc.left + w;
|
|
4152 rc.bottom = rc.top + h;
|
|
4153
|
|
4154 gui_mch_set_fg_color(color);
|
|
4155
|
168
|
4156 FrameRect(&rc);
|
|
4157 // PaintRect(&rc);
|
7
|
4158 }
|
|
4159
|
|
4160
|
|
4161
|
|
4162 /*
|
|
4163 * Catch up with any queued X events. This may put keyboard input into the
|
|
4164 * input buffer, call resize call-backs, trigger timers etc. If there is
|
|
4165 * nothing in the X event queue (& no timers pending), then we return
|
|
4166 * immediately.
|
|
4167 */
|
|
4168 void
|
593
|
4169 gui_mch_update(void)
|
7
|
4170 {
|
|
4171 /* TODO: find what to do
|
|
4172 * maybe call gui_mch_wait_for_chars (0)
|
|
4173 * more like look at EventQueue then
|
|
4174 * call heart of gui_mch_wait_for_chars;
|
|
4175 *
|
|
4176 * if (eventther)
|
|
4177 * gui_mac_handle_event(&event);
|
|
4178 */
|
|
4179 EventRecord theEvent;
|
|
4180
|
9
|
4181 if (EventAvail(everyEvent, &theEvent))
|
7
|
4182 if (theEvent.what != nullEvent)
|
|
4183 gui_mch_wait_for_chars(0);
|
|
4184 }
|
|
4185
|
|
4186 /*
|
|
4187 * Simple wrapper to neglect more easily the time
|
|
4188 * spent inside WaitNextEvent while profiling.
|
|
4189 */
|
|
4190
|
|
4191 pascal
|
|
4192 Boolean
|
9
|
4193 WaitNextEventWrp(EventMask eventMask, EventRecord *theEvent, UInt32 sleep, RgnHandle mouseRgn)
|
7
|
4194 {
|
|
4195 if (((long) sleep) < -1)
|
|
4196 sleep = 32767;
|
|
4197 return WaitNextEvent(eventMask, theEvent, sleep, mouseRgn);
|
|
4198 }
|
|
4199
|
|
4200 /*
|
|
4201 * GUI input routine called by gui_wait_for_chars(). Waits for a character
|
|
4202 * from the keyboard.
|
|
4203 * wtime == -1 Wait forever.
|
|
4204 * wtime == 0 This should never happen.
|
|
4205 * wtime > 0 Wait wtime milliseconds for a character.
|
|
4206 * Returns OK if a character was found to be available within the given time,
|
|
4207 * or FAIL otherwise.
|
|
4208 */
|
|
4209 int
|
593
|
4210 gui_mch_wait_for_chars(int wtime)
|
7
|
4211 {
|
|
4212 EventMask mask = (everyEvent);
|
|
4213 EventRecord event;
|
|
4214 long entryTick;
|
|
4215 long currentTick;
|
|
4216 long sleeppyTick;
|
|
4217
|
|
4218 /* If we are providing life feedback with the scrollbar,
|
|
4219 * we don't want to try to wait for an event, or else
|
|
4220 * there won't be any life feedback.
|
|
4221 */
|
|
4222 if (dragged_sb != NULL)
|
|
4223 return FAIL;
|
|
4224 /* TODO: Check if FAIL is the proper return code */
|
|
4225
|
|
4226 entryTick = TickCount();
|
|
4227
|
|
4228 allow_scrollbar = TRUE;
|
|
4229
|
|
4230 do
|
|
4231 {
|
|
4232 /* if (dragRectControl == kCreateEmpty)
|
|
4233 {
|
|
4234 dragRgn = NULL;
|
|
4235 dragRectControl = kNothing;
|
|
4236 }
|
|
4237 else*/ if (dragRectControl == kCreateRect)
|
|
4238 {
|
|
4239 dragRgn = cursorRgn;
|
9
|
4240 RectRgn(dragRgn, &dragRect);
|
7
|
4241 dragRectControl = kNothing;
|
|
4242 }
|
|
4243 /*
|
|
4244 * Don't use gui_mch_update() because then we will spin-lock until a
|
|
4245 * char arrives, instead we use WaitNextEventWrp() to hang until an
|
|
4246 * event arrives. No need to check for input_buf_full because we are
|
|
4247 * returning as soon as it contains a single char.
|
|
4248 */
|
|
4249 /* TODO: reduce wtime accordinly??? */
|
|
4250 if (wtime > -1)
|
|
4251 sleeppyTick = 60*wtime/1000;
|
|
4252 else
|
|
4253 sleeppyTick = 32767;
|
9
|
4254 if (WaitNextEventWrp(mask, &event, sleeppyTick, dragRgn))
|
7
|
4255 {
|
9
|
4256 gui_mac_handle_event(&event);
|
7
|
4257 if (input_available())
|
|
4258 {
|
|
4259 allow_scrollbar = FALSE;
|
|
4260 return OK;
|
|
4261 }
|
|
4262 }
|
|
4263 currentTick = TickCount();
|
|
4264 }
|
|
4265 while ((wtime == -1) || ((currentTick - entryTick) < 60*wtime/1000));
|
|
4266
|
|
4267 allow_scrollbar = FALSE;
|
|
4268 return FAIL;
|
|
4269 }
|
|
4270
|
|
4271 /*
|
|
4272 * Output routines.
|
|
4273 */
|
|
4274
|
|
4275 /* Flush any output to the screen */
|
|
4276 void
|
593
|
4277 gui_mch_flush(void)
|
7
|
4278 {
|
|
4279 /* TODO: Is anything needed here? */
|
|
4280 }
|
|
4281
|
|
4282 /*
|
|
4283 * Clear a rectangular region of the screen from text pos (row1, col1) to
|
|
4284 * (row2, col2) inclusive.
|
|
4285 */
|
|
4286 void
|
593
|
4287 gui_mch_clear_block(int row1, int col1, int row2, int col2)
|
7
|
4288 {
|
|
4289 Rect rc;
|
|
4290
|
|
4291 /*
|
|
4292 * Clear one extra pixel at the far right, for when bold characters have
|
|
4293 * spilled over to the next column.
|
|
4294 */
|
|
4295 rc.left = FILL_X(col1);
|
|
4296 rc.top = FILL_Y(row1);
|
|
4297 rc.right = FILL_X(col2 + 1) + (col2 == Columns - 1);
|
|
4298 rc.bottom = FILL_Y(row2 + 1);
|
|
4299
|
|
4300 gui_mch_set_bg_color(gui.back_pixel);
|
9
|
4301 EraseRect(&rc);
|
7
|
4302 }
|
|
4303
|
|
4304 /*
|
|
4305 * Clear the whole text window.
|
|
4306 */
|
|
4307 void
|
593
|
4308 gui_mch_clear_all(void)
|
7
|
4309 {
|
|
4310 Rect rc;
|
|
4311
|
|
4312 rc.left = 0;
|
|
4313 rc.top = 0;
|
|
4314 rc.right = Columns * gui.char_width + 2 * gui.border_width;
|
|
4315 rc.bottom = Rows * gui.char_height + 2 * gui.border_width;
|
|
4316
|
|
4317 gui_mch_set_bg_color(gui.back_pixel);
|
|
4318 EraseRect(&rc);
|
|
4319 /* gui_mch_set_fg_color(gui.norm_pixel);
|
|
4320 FrameRect(&rc);
|
|
4321 */
|
|
4322 }
|
|
4323
|
|
4324 /*
|
|
4325 * Delete the given number of lines from the given row, scrolling up any
|
|
4326 * text further down within the scroll region.
|
|
4327 */
|
|
4328 void
|
593
|
4329 gui_mch_delete_lines(int row, int num_lines)
|
7
|
4330 {
|
|
4331 Rect rc;
|
|
4332
|
|
4333 /* changed without checking! */
|
|
4334 rc.left = FILL_X(gui.scroll_region_left);
|
|
4335 rc.right = FILL_X(gui.scroll_region_right + 1);
|
|
4336 rc.top = FILL_Y(row);
|
|
4337 rc.bottom = FILL_Y(gui.scroll_region_bot + 1);
|
|
4338
|
|
4339 gui_mch_set_bg_color(gui.back_pixel);
|
9
|
4340 ScrollRect(&rc, 0, -num_lines * gui.char_height, (RgnHandle) nil);
|
7
|
4341
|
|
4342 gui_clear_block(gui.scroll_region_bot - num_lines + 1,
|
|
4343 gui.scroll_region_left,
|
|
4344 gui.scroll_region_bot, gui.scroll_region_right);
|
|
4345 }
|
|
4346
|
|
4347 /*
|
|
4348 * Insert the given number of lines before the given row, scrolling down any
|
|
4349 * following text within the scroll region.
|
|
4350 */
|
|
4351 void
|
593
|
4352 gui_mch_insert_lines(int row, int num_lines)
|
7
|
4353 {
|
|
4354 Rect rc;
|
|
4355
|
|
4356 rc.left = FILL_X(gui.scroll_region_left);
|
|
4357 rc.right = FILL_X(gui.scroll_region_right + 1);
|
|
4358 rc.top = FILL_Y(row);
|
|
4359 rc.bottom = FILL_Y(gui.scroll_region_bot + 1);
|
|
4360
|
|
4361 gui_mch_set_bg_color(gui.back_pixel);
|
|
4362
|
9
|
4363 ScrollRect(&rc, 0, gui.char_height * num_lines, (RgnHandle) nil);
|
7
|
4364
|
|
4365 /* Update gui.cursor_row if the cursor scrolled or copied over */
|
|
4366 if (gui.cursor_row >= gui.row
|
|
4367 && gui.cursor_col >= gui.scroll_region_left
|
|
4368 && gui.cursor_col <= gui.scroll_region_right)
|
|
4369 {
|
|
4370 if (gui.cursor_row <= gui.scroll_region_bot - num_lines)
|
|
4371 gui.cursor_row += num_lines;
|
|
4372 else if (gui.cursor_row <= gui.scroll_region_bot)
|
|
4373 gui.cursor_is_valid = FALSE;
|
|
4374 }
|
|
4375
|
|
4376 gui_clear_block(row, gui.scroll_region_left,
|
|
4377 row + num_lines - 1, gui.scroll_region_right);
|
|
4378 }
|
|
4379
|
|
4380 /*
|
|
4381 * TODO: add a vim format to the clipboard which remember
|
|
4382 * LINEWISE, CHARWISE, BLOCKWISE
|
|
4383 */
|
|
4384
|
|
4385 void
|
593
|
4386 clip_mch_request_selection(VimClipboard *cbd)
|
7
|
4387 {
|
|
4388
|
|
4389 Handle textOfClip;
|
19
|
4390 int flavor = 0;
|
7
|
4391 Size scrapSize;
|
|
4392 ScrapFlavorFlags scrapFlags;
|
|
4393 ScrapRef scrap = nil;
|
|
4394 OSStatus error;
|
|
4395 int type;
|
|
4396 char *searchCR;
|
|
4397 char_u *tempclip;
|
|
4398
|
|
4399
|
9
|
4400 error = GetCurrentScrap(&scrap);
|
7
|
4401 if (error != noErr)
|
|
4402 return;
|
|
4403
|
9
|
4404 error = GetScrapFlavorFlags(scrap, VIMSCRAPFLAVOR, &scrapFlags);
|
|
4405 if (error == noErr)
|
|
4406 {
|
|
4407 error = GetScrapFlavorSize(scrap, VIMSCRAPFLAVOR, &scrapSize);
|
|
4408 if (error == noErr && scrapSize > 1)
|
|
4409 flavor = 1;
|
|
4410 }
|
|
4411
|
|
4412 if (flavor == 0)
|
|
4413 {
|
168
|
4414 error = GetScrapFlavorFlags(scrap, kScrapFlavorTypeUnicode, &scrapFlags);
|
9
|
4415 if (error != noErr)
|
|
4416 return;
|
|
4417
|
168
|
4418 error = GetScrapFlavorSize(scrap, kScrapFlavorTypeUnicode, &scrapSize);
|
9
|
4419 if (error != noErr)
|
|
4420 return;
|
|
4421 }
|
|
4422
|
|
4423 ReserveMem(scrapSize);
|
593
|
4424
|
7
|
4425 {
|
|
4426 /* In CARBON we don't need a Handle, a pointer is good */
|
9
|
4427 textOfClip = NewHandle(scrapSize);
|
7
|
4428 /* tempclip = lalloc(scrapSize+1, TRUE); */
|
9
|
4429 HLock(textOfClip);
|
|
4430 error = GetScrapFlavorData(scrap,
|
168
|
4431 flavor ? VIMSCRAPFLAVOR : kScrapFlavorTypeUnicode,
|
9
|
4432 &scrapSize, *textOfClip);
|
19
|
4433 scrapSize -= flavor;
|
7
|
4434
|
9
|
4435 if (flavor)
|
|
4436 type = **textOfClip;
|
|
4437 else
|
|
4438 type = (strchr(*textOfClip, '\r') != NULL) ? MLINE : MCHAR;
|
7
|
4439
|
19
|
4440 tempclip = lalloc(scrapSize + 1, TRUE);
|
593
|
4441 #if defined(FEAT_MBYTE)
|
168
|
4442 mch_memmove(tempclip, *textOfClip + flavor, scrapSize);
|
|
4443 #else
|
19
|
4444 STRNCPY(tempclip, *textOfClip + flavor, scrapSize);
|
168
|
4445 #endif
|
19
|
4446 tempclip[scrapSize] = 0;
|
7
|
4447
|
766
|
4448 #ifdef MACOS_CONVERT
|
168
|
4449 /* Convert from utf-16 (clipboard) */
|
|
4450 size_t encLen = 0;
|
|
4451 char_u *to = mac_utf16_to_enc((UniChar *)tempclip, scrapSize, &encLen);
|
|
4452 if (to)
|
7
|
4453 {
|
168
|
4454 scrapSize = encLen;
|
|
4455 vim_free(tempclip);
|
|
4456 tempclip = to;
|
7
|
4457 }
|
|
4458 #endif
|
502
|
4459
|
|
4460 searchCR = (char *)tempclip;
|
|
4461 while (searchCR != NULL)
|
|
4462 {
|
|
4463 searchCR = strchr(searchCR, '\r');
|
|
4464
|
|
4465 if (searchCR != NULL)
|
|
4466 searchCR[0] = '\n';
|
|
4467
|
|
4468 }
|
|
4469
|
7
|
4470 clip_yank_selection(type, tempclip, scrapSize, cbd);
|
|
4471
|
|
4472 vim_free(tempclip);
|
|
4473 HUnlock(textOfClip);
|
|
4474
|
|
4475 DisposeHandle(textOfClip);
|
|
4476 }
|
|
4477 }
|
|
4478
|
|
4479 void
|
593
|
4480 clip_mch_lose_selection(VimClipboard *cbd)
|
7
|
4481 {
|
|
4482 /*
|
|
4483 * TODO: Really nothing to do?
|
|
4484 */
|
|
4485 }
|
|
4486
|
|
4487 int
|
593
|
4488 clip_mch_own_selection(VimClipboard *cbd)
|
7
|
4489 {
|
|
4490 return OK;
|
|
4491 }
|
|
4492
|
|
4493 /*
|
|
4494 * Send the current selection to the clipboard.
|
|
4495 */
|
|
4496 void
|
593
|
4497 clip_mch_set_selection(VimClipboard *cbd)
|
7
|
4498 {
|
|
4499 Handle textOfClip;
|
|
4500 long scrapSize;
|
|
4501 int type;
|
|
4502 ScrapRef scrap;
|
|
4503
|
|
4504 char_u *str = NULL;
|
|
4505
|
|
4506 if (!cbd->owned)
|
|
4507 return;
|
|
4508
|
|
4509 clip_get_selection(cbd);
|
|
4510
|
|
4511 /*
|
|
4512 * Once we set the clipboard, lose ownership. If another application sets
|
|
4513 * the clipboard, we don't want to think that we still own it.
|
|
4514 *
|
|
4515 */
|
|
4516
|
|
4517 cbd->owned = FALSE;
|
|
4518
|
|
4519 type = clip_convert_selection(&str, (long_u *) &scrapSize, cbd);
|
|
4520
|
766
|
4521 #ifdef MACOS_CONVERT
|
168
|
4522 size_t utf16_len = 0;
|
|
4523 UniChar *to = mac_enc_to_utf16(str, scrapSize, &utf16_len);
|
|
4524 if (to)
|
7
|
4525 {
|
168
|
4526 scrapSize = utf16_len;
|
|
4527 vim_free(str);
|
|
4528 str = (char_u *)to;
|
7
|
4529 }
|
|
4530 #endif
|
|
4531
|
|
4532 if (type >= 0)
|
|
4533 {
|
|
4534 ClearCurrentScrap();
|
593
|
4535
|
9
|
4536 textOfClip = NewHandle(scrapSize + 1);
|
7
|
4537 HLock(textOfClip);
|
|
4538
|
9
|
4539 **textOfClip = type;
|
168
|
4540 mch_memmove(*textOfClip + 1, str, scrapSize);
|
9
|
4541 GetCurrentScrap(&scrap);
|
168
|
4542 PutScrapFlavor(scrap, kScrapFlavorTypeUnicode, kScrapFlavorMaskNone,
|
9
|
4543 scrapSize, *textOfClip + 1);
|
|
4544 PutScrapFlavor(scrap, VIMSCRAPFLAVOR, kScrapFlavorMaskNone,
|
|
4545 scrapSize + 1, *textOfClip);
|
7
|
4546 HUnlock(textOfClip);
|
|
4547 DisposeHandle(textOfClip);
|
|
4548 }
|
|
4549
|
|
4550 vim_free(str);
|
|
4551 }
|
|
4552
|
|
4553 void
|
593
|
4554 gui_mch_set_text_area_pos(int x, int y, int w, int h)
|
7
|
4555 {
|
|
4556 Rect VimBound;
|
|
4557
|
9
|
4558 /* HideWindow(gui.VimWindow); */
|
7
|
4559 GetWindowBounds(gui.VimWindow, kWindowGlobalPortRgn, &VimBound);
|
|
4560
|
|
4561 if (gui.which_scrollbars[SBAR_LEFT])
|
|
4562 {
|
|
4563 VimBound.left = -gui.scrollbar_width + 1;
|
|
4564 }
|
|
4565 else
|
|
4566 {
|
|
4567 VimBound.left = 0;
|
|
4568 }
|
|
4569
|
|
4570 SetWindowBounds(gui.VimWindow, kWindowGlobalPortRgn, &VimBound);
|
|
4571
|
9
|
4572 ShowWindow(gui.VimWindow);
|
7
|
4573 }
|
|
4574
|
|
4575 /*
|
|
4576 * Menu stuff.
|
|
4577 */
|
|
4578
|
|
4579 void
|
593
|
4580 gui_mch_enable_menu(int flag)
|
7
|
4581 {
|
|
4582 /*
|
444
|
4583 * Menu is always active.
|
7
|
4584 */
|
|
4585 }
|
|
4586
|
|
4587 void
|
593
|
4588 gui_mch_set_menu_pos(int x, int y, int w, int h)
|
7
|
4589 {
|
|
4590 /*
|
444
|
4591 * The menu is always at the top of the screen.
|
7
|
4592 */
|
|
4593 }
|
|
4594
|
|
4595 /*
|
|
4596 * Add a sub menu to the menu bar.
|
|
4597 */
|
|
4598 void
|
593
|
4599 gui_mch_add_menu(vimmenu_T *menu, int idx)
|
7
|
4600 {
|
|
4601 /*
|
|
4602 * TODO: Try to use only menu_id instead of both menu_id and menu_handle.
|
|
4603 * TODO: use menu->mnemonic and menu->actext
|
|
4604 * TODO: Try to reuse menu id
|
|
4605 * Carbon Help suggest to use only id between 1 and 235
|
|
4606 */
|
|
4607 static long next_avail_id = 128;
|
|
4608 long menu_after_me = 0; /* Default to the end */
|
593
|
4609 #if defined(FEAT_MBYTE)
|
168
|
4610 CFStringRef name;
|
|
4611 #else
|
7
|
4612 char_u *name;
|
168
|
4613 #endif
|
7
|
4614 short index;
|
|
4615 vimmenu_T *parent = menu->parent;
|
|
4616 vimmenu_T *brother = menu->next;
|
|
4617
|
|
4618 /* Cannot add a menu if ... */
|
|
4619 if ((parent != NULL && parent->submenu_id == 0))
|
|
4620 return;
|
|
4621
|
|
4622 /* menu ID greater than 1024 are reserved for ??? */
|
|
4623 if (next_avail_id == 1024)
|
|
4624 return;
|
|
4625
|
|
4626 /* My brother could be the PopUp, find my real brother */
|
|
4627 while ((brother != NULL) && (!menu_is_menubar(brother->name)))
|
|
4628 brother = brother->next;
|
|
4629
|
|
4630 /* Find where to insert the menu (for MenuBar) */
|
|
4631 if ((parent == NULL) && (brother != NULL))
|
|
4632 menu_after_me = brother->submenu_id;
|
|
4633
|
|
4634 /* If the menu is not part of the menubar (and its submenus), add it 'nowhere' */
|
|
4635 if (!menu_is_menubar(menu->name))
|
|
4636 menu_after_me = hierMenu;
|
|
4637
|
|
4638 /* Convert the name */
|
766
|
4639 #ifdef MACOS_CONVERT
|
168
|
4640 name = menu_title_removing_mnemonic(menu);
|
|
4641 #else
|
7
|
4642 name = C2Pascal_save(menu->dname);
|
168
|
4643 #endif
|
7
|
4644 if (name == NULL)
|
|
4645 return;
|
|
4646
|
|
4647 /* Create the menu unless it's the help menu */
|
|
4648 {
|
|
4649 /* Carbon suggest use of
|
9
|
4650 * OSStatus CreateNewMenu(MenuID, MenuAttributes, MenuRef *);
|
|
4651 * OSStatus SetMenuTitle(MenuRef, ConstStr255Param title);
|
7
|
4652 */
|
|
4653 menu->submenu_id = next_avail_id;
|
593
|
4654 #if defined(FEAT_MBYTE)
|
168
|
4655 if (CreateNewMenu(menu->submenu_id, 0, (MenuRef *)&menu->submenu_handle) == noErr)
|
|
4656 SetMenuTitleWithCFString((MenuRef)menu->submenu_handle, name);
|
|
4657 #else
|
9
|
4658 menu->submenu_handle = NewMenu(menu->submenu_id, name);
|
168
|
4659 #endif
|
7
|
4660 next_avail_id++;
|
|
4661 }
|
|
4662
|
|
4663 if (parent == NULL)
|
|
4664 {
|
|
4665 /* Adding a menu to the menubar, or in the no mans land (for PopUp) */
|
|
4666
|
|
4667 /* TODO: Verify if we could only Insert Menu if really part of the
|
|
4668 * menubar The Inserted menu are scanned or the Command-key combos
|
|
4669 */
|
|
4670
|
593
|
4671 /* Insert the menu */
|
|
4672 InsertMenu(menu->submenu_handle, menu_after_me); /* insert before */
|
7
|
4673 #if 1
|
|
4674 /* Vim should normally update it. TODO: verify */
|
|
4675 DrawMenuBar();
|
|
4676 #endif
|
|
4677 }
|
|
4678 else
|
|
4679 {
|
|
4680 /* Adding as a submenu */
|
|
4681
|
9
|
4682 index = gui_mac_get_menu_item_index(menu);
|
7
|
4683
|
|
4684 /* Call InsertMenuItem followed by SetMenuItemText
|
|
4685 * to avoid special character recognition by InsertMenuItem
|
|
4686 */
|
|
4687 InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */
|
593
|
4688 #if defined(FEAT_MBYTE)
|
168
|
4689 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name);
|
|
4690 #else
|
7
|
4691 SetMenuItemText(parent->submenu_handle, idx+1, name);
|
168
|
4692 #endif
|
7
|
4693 SetItemCmd(parent->submenu_handle, idx+1, 0x1B);
|
|
4694 SetItemMark(parent->submenu_handle, idx+1, menu->submenu_id);
|
|
4695 InsertMenu(menu->submenu_handle, hierMenu);
|
|
4696 }
|
|
4697
|
593
|
4698 #if defined(FEAT_MBYTE)
|
168
|
4699 CFRelease(name);
|
|
4700 #else
|
9
|
4701 vim_free(name);
|
168
|
4702 #endif
|
7
|
4703
|
|
4704 #if 0
|
|
4705 /* Done by Vim later on */
|
|
4706 DrawMenuBar();
|
|
4707 #endif
|
|
4708 }
|
|
4709
|
|
4710 /*
|
|
4711 * Add a menu item to a menu
|
|
4712 */
|
|
4713 void
|
593
|
4714 gui_mch_add_menu_item(vimmenu_T *menu, int idx)
|
7
|
4715 {
|
593
|
4716 #if defined(FEAT_MBYTE)
|
168
|
4717 CFStringRef name;
|
|
4718 #else
|
7
|
4719 char_u *name;
|
168
|
4720 #endif
|
7
|
4721 vimmenu_T *parent = menu->parent;
|
|
4722 int menu_inserted;
|
|
4723
|
|
4724 /* Cannot add item, if the menu have not been created */
|
|
4725 if (parent->submenu_id == 0)
|
|
4726 return;
|
|
4727
|
|
4728 /* Could call SetMenuRefCon [CARBON] to associate with the Menu,
|
|
4729 for older OS call GetMenuItemData (menu, item, isCommandID?, data) */
|
|
4730
|
|
4731 /* Convert the name */
|
766
|
4732 #ifdef MACOS_CONVERT
|
168
|
4733 name = menu_title_removing_mnemonic(menu);
|
|
4734 #else
|
7
|
4735 name = C2Pascal_save(menu->dname);
|
168
|
4736 #endif
|
7
|
4737
|
|
4738 /* Where are just a menu item, so no handle, no id */
|
|
4739 menu->submenu_id = 0;
|
|
4740 menu->submenu_handle = NULL;
|
|
4741
|
|
4742 menu_inserted = 0;
|
|
4743 if (menu->actext)
|
|
4744 {
|
|
4745 /* If the accelerator text for the menu item looks like it describes
|
|
4746 * a command key (e.g., "<D-S-t>" or "<C-7>"), display it as the
|
|
4747 * item's command equivalent.
|
|
4748 */
|
|
4749 int key = 0;
|
|
4750 int modifiers = 0;
|
|
4751 char_u *p_actext;
|
|
4752
|
|
4753 p_actext = menu->actext;
|
|
4754 key = find_special_key(&p_actext, &modifiers, /*keycode=*/0);
|
|
4755 if (*p_actext != 0)
|
|
4756 key = 0; /* error: trailing text */
|
|
4757 /* find_special_key() returns a keycode with as many of the
|
|
4758 * specified modifiers as appropriate already applied (e.g., for
|
|
4759 * "<D-C-x>" it returns Ctrl-X as the keycode and MOD_MASK_CMD
|
|
4760 * as the only modifier). Since we want to display all of the
|
|
4761 * modifiers, we need to convert the keycode back to a printable
|
|
4762 * character plus modifiers.
|
|
4763 * TODO: Write an alternative find_special_key() that doesn't
|
|
4764 * apply modifiers.
|
|
4765 */
|
|
4766 if (key > 0 && key < 32)
|
|
4767 {
|
|
4768 /* Convert a control key to an uppercase letter. Note that
|
|
4769 * by this point it is no longer possible to distinguish
|
|
4770 * between, e.g., Ctrl-S and Ctrl-Shift-S.
|
|
4771 */
|
|
4772 modifiers |= MOD_MASK_CTRL;
|
|
4773 key += '@';
|
|
4774 }
|
|
4775 /* If the keycode is an uppercase letter, set the Shift modifier.
|
|
4776 * If it is a lowercase letter, don't set the modifier, but convert
|
|
4777 * the letter to uppercase for display in the menu.
|
|
4778 */
|
|
4779 else if (key >= 'A' && key <= 'Z')
|
|
4780 modifiers |= MOD_MASK_SHIFT;
|
|
4781 else if (key >= 'a' && key <= 'z')
|
|
4782 key += 'A' - 'a';
|
|
4783 /* Note: keycodes below 0x22 are reserved by Apple. */
|
|
4784 if (key >= 0x22 && vim_isprintc_strict(key))
|
|
4785 {
|
|
4786 int valid = 1;
|
|
4787 char_u mac_mods = kMenuNoModifiers;
|
|
4788 /* Convert Vim modifier codes to Menu Manager equivalents. */
|
|
4789 if (modifiers & MOD_MASK_SHIFT)
|
|
4790 mac_mods |= kMenuShiftModifier;
|
|
4791 if (modifiers & MOD_MASK_CTRL)
|
|
4792 mac_mods |= kMenuControlModifier;
|
|
4793 if (!(modifiers & MOD_MASK_CMD))
|
|
4794 mac_mods |= kMenuNoCommandModifier;
|
|
4795 if (modifiers & MOD_MASK_ALT || modifiers & MOD_MASK_MULTI_CLICK)
|
|
4796 valid = 0; /* TODO: will Alt someday map to Option? */
|
|
4797 if (valid)
|
|
4798 {
|
|
4799 char_u item_txt[10];
|
|
4800 /* Insert the menu item after idx, with its command key. */
|
|
4801 item_txt[0] = 3; item_txt[1] = ' '; item_txt[2] = '/';
|
|
4802 item_txt[3] = key;
|
|
4803 InsertMenuItem(parent->submenu_handle, item_txt, idx);
|
|
4804 /* Set the modifier keys. */
|
|
4805 SetMenuItemModifiers(parent->submenu_handle, idx+1, mac_mods);
|
|
4806 menu_inserted = 1;
|
|
4807 }
|
|
4808 }
|
|
4809 }
|
|
4810 /* Call InsertMenuItem followed by SetMenuItemText
|
|
4811 * to avoid special character recognition by InsertMenuItem
|
|
4812 */
|
|
4813 if (!menu_inserted)
|
|
4814 InsertMenuItem(parent->submenu_handle, "\p ", idx); /* afterItem */
|
|
4815 /* Set the menu item name. */
|
593
|
4816 #if defined(FEAT_MBYTE)
|
168
|
4817 SetMenuItemTextWithCFString(parent->submenu_handle, idx+1, name);
|
|
4818 #else
|
7
|
4819 SetMenuItemText(parent->submenu_handle, idx+1, name);
|
168
|
4820 #endif
|
7
|
4821
|
|
4822 #if 0
|
|
4823 /* Called by Vim */
|
|
4824 DrawMenuBar();
|
|
4825 #endif
|
|
4826
|
593
|
4827 #if defined(FEAT_MBYTE)
|
168
|
4828 CFRelease(name);
|
|
4829 #else
|
7
|
4830 /* TODO: Can name be freed? */
|
|
4831 vim_free(name);
|
168
|
4832 #endif
|
7
|
4833 }
|
|
4834
|
|
4835 void
|
593
|
4836 gui_mch_toggle_tearoffs(int enable)
|
7
|
4837 {
|
|
4838 /* no tearoff menus */
|
|
4839 }
|
|
4840
|
|
4841 /*
|
|
4842 * Destroy the machine specific menu widget.
|
|
4843 */
|
|
4844 void
|
593
|
4845 gui_mch_destroy_menu(vimmenu_T *menu)
|
7
|
4846 {
|
9
|
4847 short index = gui_mac_get_menu_item_index(menu);
|
7
|
4848
|
|
4849 if (index > 0)
|
|
4850 {
|
|
4851 if (menu->parent)
|
|
4852 {
|
|
4853 {
|
|
4854 /* For now just don't delete help menu items. (Huh? Dany) */
|
9
|
4855 DeleteMenuItem(menu->parent->submenu_handle, index);
|
7
|
4856
|
|
4857 /* Delete the Menu if it was a hierarchical Menu */
|
|
4858 if (menu->submenu_id != 0)
|
|
4859 {
|
9
|
4860 DeleteMenu(menu->submenu_id);
|
|
4861 DisposeMenu(menu->submenu_handle);
|
7
|
4862 }
|
|
4863 }
|
|
4864 }
|
|
4865 #ifdef DEBUG_MAC_MENU
|
|
4866 else
|
|
4867 {
|
9
|
4868 printf("gmdm 2\n");
|
7
|
4869 }
|
|
4870 #endif
|
|
4871 }
|
|
4872 else
|
|
4873 {
|
|
4874 {
|
9
|
4875 DeleteMenu(menu->submenu_id);
|
|
4876 DisposeMenu(menu->submenu_handle);
|
7
|
4877 }
|
|
4878 }
|
|
4879 /* Shouldn't this be already done by Vim. TODO: Check */
|
|
4880 DrawMenuBar();
|
|
4881 }
|
|
4882
|
|
4883 /*
|
|
4884 * Make a menu either grey or not grey.
|
|
4885 */
|
|
4886 void
|
593
|
4887 gui_mch_menu_grey(vimmenu_T *menu, int grey)
|
7
|
4888 {
|
|
4889 /* TODO: Check if menu really exists */
|
9
|
4890 short index = gui_mac_get_menu_item_index(menu);
|
7
|
4891 /*
|
|
4892 index = menu->index;
|
|
4893 */
|
|
4894 if (grey)
|
|
4895 {
|
|
4896 if (menu->children)
|
|
4897 DisableMenuItem(menu->submenu_handle, index);
|
|
4898 if (menu->parent)
|
|
4899 if (menu->parent->submenu_handle)
|
|
4900 DisableMenuItem(menu->parent->submenu_handle, index);
|
|
4901 }
|
|
4902 else
|
|
4903 {
|
|
4904 if (menu->children)
|
|
4905 EnableMenuItem(menu->submenu_handle, index);
|
|
4906 if (menu->parent)
|
|
4907 if (menu->parent->submenu_handle)
|
|
4908 EnableMenuItem(menu->parent->submenu_handle, index);
|
|
4909 }
|
|
4910 }
|
|
4911
|
|
4912 /*
|
|
4913 * Make menu item hidden or not hidden
|
|
4914 */
|
|
4915 void
|
593
|
4916 gui_mch_menu_hidden(vimmenu_T *menu, int hidden)
|
7
|
4917 {
|
|
4918 /* There's no hidden mode on MacOS */
|
9
|
4919 gui_mch_menu_grey(menu, hidden);
|
7
|
4920 }
|
|
4921
|
|
4922
|
|
4923 /*
|
|
4924 * This is called after setting all the menus to grey/hidden or not.
|
|
4925 */
|
|
4926 void
|
593
|
4927 gui_mch_draw_menubar(void)
|
7
|
4928 {
|
|
4929 DrawMenuBar();
|
|
4930 }
|
|
4931
|
|
4932
|
|
4933 /*
|
|
4934 * Scrollbar stuff.
|
|
4935 */
|
|
4936
|
|
4937 void
|
593
|
4938 gui_mch_enable_scrollbar(
|
|
4939 scrollbar_T *sb,
|
|
4940 int flag)
|
7
|
4941 {
|
|
4942 if (flag)
|
|
4943 ShowControl(sb->id);
|
|
4944 else
|
|
4945 HideControl(sb->id);
|
|
4946
|
|
4947 #ifdef DEBUG_MAC_SB
|
9
|
4948 printf("enb_sb (%x) %x\n",sb->id, flag);
|
7
|
4949 #endif
|
|
4950 }
|
|
4951
|
|
4952 void
|
593
|
4953 gui_mch_set_scrollbar_thumb(
|
|
4954 scrollbar_T *sb,
|
|
4955 long val,
|
|
4956 long size,
|
|
4957 long max)
|
7
|
4958 {
|
|
4959 SetControl32BitMaximum (sb->id, max);
|
|
4960 SetControl32BitMinimum (sb->id, 0);
|
|
4961 SetControl32BitValue (sb->id, val);
|
|
4962 #ifdef DEBUG_MAC_SB
|
9
|
4963 printf("thumb_sb (%x) %x, %x,%x\n",sb->id, val, size, max);
|
7
|
4964 #endif
|
|
4965 }
|
|
4966
|
|
4967 void
|
593
|
4968 gui_mch_set_scrollbar_pos(
|
|
4969 scrollbar_T *sb,
|
|
4970 int x,
|
|
4971 int y,
|
|
4972 int w,
|
|
4973 int h)
|
7
|
4974 {
|
|
4975 gui_mch_set_bg_color(gui.back_pixel);
|
|
4976 /* if (gui.which_scrollbars[SBAR_LEFT])
|
|
4977 {
|
9
|
4978 MoveControl(sb->id, x-16, y);
|
|
4979 SizeControl(sb->id, w + 1, h);
|
7
|
4980 }
|
|
4981 else
|
|
4982 {
|
9
|
4983 MoveControl(sb->id, x, y);
|
|
4984 SizeControl(sb->id, w + 1, h);
|
7
|
4985 }*/
|
|
4986 if (sb == &gui.bottom_sbar)
|
|
4987 h += 1;
|
|
4988 else
|
|
4989 w += 1;
|
|
4990
|
|
4991 if (gui.which_scrollbars[SBAR_LEFT])
|
|
4992 x -= 15;
|
|
4993
|
9
|
4994 MoveControl(sb->id, x, y);
|
|
4995 SizeControl(sb->id, w, h);
|
7
|
4996 #ifdef DEBUG_MAC_SB
|
9
|
4997 printf("size_sb (%x) %x, %x, %x, %x\n",sb->id, x, y, w, h);
|
7
|
4998 #endif
|
|
4999 }
|
|
5000
|
|
5001 void
|
593
|
5002 gui_mch_create_scrollbar(
|
|
5003 scrollbar_T *sb,
|
|
5004 int orient) /* SBAR_VERT or SBAR_HORIZ */
|
7
|
5005 {
|
|
5006 Rect bounds;
|
|
5007
|
|
5008 bounds.top = -16;
|
|
5009 bounds.bottom = -10;
|
|
5010 bounds.right = -10;
|
|
5011 bounds.left = -16;
|
|
5012
|
9
|
5013 sb->id = NewControl(gui.VimWindow,
|
7
|
5014 &bounds,
|
|
5015 "\pScrollBar",
|
|
5016 TRUE,
|
|
5017 0, /* current*/
|
|
5018 0, /* top */
|
|
5019 0, /* bottom */
|
|
5020 kControlScrollBarLiveProc,
|
|
5021 (long) sb->ident);
|
|
5022 #ifdef DEBUG_MAC_SB
|
9
|
5023 printf("create_sb (%x) %x\n",sb->id, orient);
|
7
|
5024 #endif
|
|
5025 }
|
|
5026
|
|
5027 void
|
593
|
5028 gui_mch_destroy_scrollbar(scrollbar_T *sb)
|
7
|
5029 {
|
|
5030 gui_mch_set_bg_color(gui.back_pixel);
|
9
|
5031 DisposeControl(sb->id);
|
7
|
5032 #ifdef DEBUG_MAC_SB
|
9
|
5033 printf("dest_sb (%x) \n",sb->id);
|
7
|
5034 #endif
|
|
5035 }
|
|
5036
|
|
5037
|
|
5038 /*
|
|
5039 * Cursor blink functions.
|
|
5040 *
|
|
5041 * This is a simple state machine:
|
|
5042 * BLINK_NONE not blinking at all
|
|
5043 * BLINK_OFF blinking, cursor is not shown
|
|
5044 * BLINK_ON blinking, cursor is shown
|
|
5045 */
|
|
5046 void
|
|
5047 gui_mch_set_blinking(long wait, long on, long off)
|
|
5048 {
|
|
5049 /* TODO: TODO: TODO: TODO: */
|
|
5050 /* blink_waittime = wait;
|
|
5051 blink_ontime = on;
|
|
5052 blink_offtime = off;*/
|
|
5053 }
|
|
5054
|
|
5055 /*
|
|
5056 * Stop the cursor blinking. Show the cursor if it wasn't shown.
|
|
5057 */
|
|
5058 void
|
593
|
5059 gui_mch_stop_blink(void)
|
7
|
5060 {
|
|
5061 gui_update_cursor(TRUE, FALSE);
|
|
5062 /* TODO: TODO: TODO: TODO: */
|
|
5063 /* gui_w32_rm_blink_timer();
|
|
5064 if (blink_state == BLINK_OFF)
|
|
5065 gui_update_cursor(TRUE, FALSE);
|
|
5066 blink_state = BLINK_NONE;*/
|
|
5067 }
|
|
5068
|
|
5069 /*
|
|
5070 * Start the cursor blinking. If it was already blinking, this restarts the
|
|
5071 * waiting time and shows the cursor.
|
|
5072 */
|
|
5073 void
|
593
|
5074 gui_mch_start_blink(void)
|
7
|
5075 {
|
|
5076 gui_update_cursor(TRUE, FALSE);
|
|
5077 /* TODO: TODO: TODO: TODO: */
|
|
5078 /* gui_w32_rm_blink_timer(); */
|
|
5079
|
|
5080 /* Only switch blinking on if none of the times is zero */
|
|
5081 /* if (blink_waittime && blink_ontime && blink_offtime)
|
|
5082 {
|
|
5083 blink_timer = SetTimer(NULL, 0, (UINT)blink_waittime,
|
|
5084 (TIMERPROC)_OnBlinkTimer);
|
|
5085 blink_state = BLINK_ON;
|
|
5086 gui_update_cursor(TRUE, FALSE);
|
|
5087 }*/
|
|
5088 }
|
|
5089
|
|
5090 /*
|
|
5091 * Return the RGB value of a pixel as long.
|
|
5092 */
|
|
5093 long_u
|
|
5094 gui_mch_get_rgb(guicolor_T pixel)
|
|
5095 {
|
|
5096 return (Red(pixel) << 16) + (Green(pixel) << 8) + Blue(pixel);
|
|
5097 }
|
|
5098
|
|
5099
|
|
5100
|
|
5101 #ifdef FEAT_BROWSE
|
|
5102 /*
|
|
5103 * Pop open a file browser and return the file selected, in allocated memory,
|
|
5104 * or NULL if Cancel is hit.
|
|
5105 * saving - TRUE if the file will be saved to, FALSE if it will be opened.
|
|
5106 * title - Title message for the file browser dialog.
|
|
5107 * dflt - Default name of file.
|
|
5108 * ext - Default extension to be added to files without extensions.
|
|
5109 * initdir - directory in which to open the browser (NULL = current dir)
|
|
5110 * filter - Filter for matched files to choose from.
|
|
5111 * Has a format like this:
|
|
5112 * "C Files (*.c)\0*.c\0"
|
|
5113 * "All Files\0*.*\0\0"
|
|
5114 * If these two strings were concatenated, then a choice of two file
|
|
5115 * filters will be selectable to the user. Then only matching files will
|
|
5116 * be shown in the browser. If NULL, the default allows all files.
|
|
5117 *
|
|
5118 * *NOTE* - the filter string must be terminated with TWO nulls.
|
|
5119 */
|
|
5120 char_u *
|
|
5121 gui_mch_browse(
|
|
5122 int saving,
|
|
5123 char_u *title,
|
|
5124 char_u *dflt,
|
|
5125 char_u *ext,
|
|
5126 char_u *initdir,
|
|
5127 char_u *filter)
|
|
5128 {
|
|
5129 /* TODO: Add Ammon's safety checl (Dany) */
|
|
5130 NavReplyRecord reply;
|
|
5131 char_u *fname = NULL;
|
|
5132 char_u **fnames = NULL;
|
|
5133 long numFiles;
|
|
5134 NavDialogOptions navOptions;
|
|
5135 OSErr error;
|
|
5136
|
|
5137 /* Get Navigation Service Defaults value */
|
9
|
5138 NavGetDefaultDialogOptions(&navOptions);
|
7
|
5139
|
|
5140
|
|
5141 /* TODO: If we get a :browse args, set the Multiple bit. */
|
|
5142 navOptions.dialogOptionFlags = kNavAllowInvisibleFiles
|
|
5143 | kNavDontAutoTranslate
|
|
5144 | kNavDontAddTranslateItems
|
|
5145 /* | kNavAllowMultipleFiles */
|
|
5146 | kNavAllowStationery;
|
|
5147
|
9
|
5148 (void) C2PascalString(title, &navOptions.message);
|
|
5149 (void) C2PascalString(dflt, &navOptions.savedFileName);
|
7
|
5150 /* Could set clientName?
|
|
5151 * windowTitle? (there's no title bar?)
|
|
5152 */
|
|
5153
|
|
5154 if (saving)
|
|
5155 {
|
|
5156 /* Change first parm AEDesc (typeFSS) *defaultLocation to match dflt */
|
9
|
5157 NavPutFile(NULL, &reply, &navOptions, NULL, 'TEXT', 'VIM!', NULL);
|
7
|
5158 if (!reply.validRecord)
|
|
5159 return NULL;
|
|
5160 }
|
|
5161 else
|
|
5162 {
|
|
5163 /* Change first parm AEDesc (typeFSS) *defaultLocation to match dflt */
|
|
5164 NavGetFile(NULL, &reply, &navOptions, NULL, NULL, NULL, NULL, NULL);
|
|
5165 if (!reply.validRecord)
|
|
5166 return NULL;
|
|
5167 }
|
|
5168
|
|
5169 fnames = new_fnames_from_AEDesc(&reply.selection, &numFiles, &error);
|
|
5170
|
9
|
5171 NavDisposeReply(&reply);
|
7
|
5172
|
|
5173 if (fnames)
|
|
5174 {
|
|
5175 fname = fnames[0];
|
|
5176 vim_free(fnames);
|
|
5177 }
|
|
5178
|
|
5179 /* TODO: Shorten the file name if possible */
|
|
5180 return fname;
|
|
5181 }
|
|
5182 #endif /* FEAT_BROWSE */
|
|
5183
|
|
5184 #ifdef FEAT_GUI_DIALOG
|
|
5185 /*
|
|
5186 * Stuff for dialogues
|
|
5187 */
|
|
5188
|
|
5189 /*
|
|
5190 * Create a dialogue dynamically from the parameter strings.
|
|
5191 * type = type of dialogue (question, alert, etc.)
|
|
5192 * title = dialogue title. may be NULL for default title.
|
|
5193 * message = text to display. Dialogue sizes to accommodate it.
|
|
5194 * buttons = '\n' separated list of button captions, default first.
|
|
5195 * dfltbutton = number of default button.
|
|
5196 *
|
|
5197 * This routine returns 1 if the first button is pressed,
|
|
5198 * 2 for the second, etc.
|
|
5199 *
|
|
5200 * 0 indicates Esc was pressed.
|
|
5201 * -1 for unexpected error
|
|
5202 *
|
|
5203 * If stubbing out this fn, return 1.
|
|
5204 */
|
|
5205
|
|
5206 typedef struct
|
|
5207 {
|
|
5208 short idx;
|
|
5209 short width; /* Size of the text in pixel */
|
|
5210 Rect box;
|
|
5211 } vgmDlgItm; /* Vim Gui_Mac.c Dialog Item */
|
|
5212
|
|
5213 #define MoveRectTo(r,x,y) OffsetRect(r,x-r->left,y-r->top)
|
|
5214
|
|
5215 static void
|
|
5216 macMoveDialogItem(
|
|
5217 DialogRef theDialog,
|
|
5218 short itemNumber,
|
|
5219 short X,
|
|
5220 short Y,
|
|
5221 Rect *inBox)
|
|
5222 {
|
|
5223 #if 0 /* USE_CARBONIZED */
|
|
5224 /* Untested */
|
9
|
5225 MoveDialogItem(theDialog, itemNumber, X, Y);
|
7
|
5226 if (inBox != nil)
|
9
|
5227 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, inBox);
|
7
|
5228 #else
|
|
5229 short itemType;
|
|
5230 Handle itemHandle;
|
|
5231 Rect localBox;
|
|
5232 Rect *itemBox = &localBox;
|
|
5233
|
|
5234 if (inBox != nil)
|
|
5235 itemBox = inBox;
|
|
5236
|
9
|
5237 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, itemBox);
|
|
5238 OffsetRect(itemBox, -itemBox->left, -itemBox->top);
|
|
5239 OffsetRect(itemBox, X, Y);
|
7
|
5240 /* To move a control (like a button) we need to call both
|
|
5241 * MoveControl and SetDialogItem. FAQ 6-18 */
|
|
5242 if (1) /*(itemType & kControlDialogItem) */
|
9
|
5243 MoveControl((ControlRef) itemHandle, X, Y);
|
|
5244 SetDialogItem(theDialog, itemNumber, itemType, itemHandle, itemBox);
|
7
|
5245 #endif
|
|
5246 }
|
|
5247
|
|
5248 static void
|
|
5249 macSizeDialogItem(
|
|
5250 DialogRef theDialog,
|
|
5251 short itemNumber,
|
|
5252 short width,
|
|
5253 short height)
|
|
5254 {
|
|
5255 short itemType;
|
|
5256 Handle itemHandle;
|
|
5257 Rect itemBox;
|
|
5258
|
9
|
5259 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemBox);
|
7
|
5260
|
|
5261 /* When width or height is zero do not change it */
|
|
5262 if (width == 0)
|
|
5263 width = itemBox.right - itemBox.left;
|
|
5264 if (height == 0)
|
|
5265 height = itemBox.bottom - itemBox.top;
|
|
5266
|
|
5267 #if 0 /* USE_CARBONIZED */
|
9
|
5268 SizeDialogItem(theDialog, itemNumber, width, height); /* Untested */
|
7
|
5269 #else
|
|
5270 /* Resize the bounding box */
|
|
5271 itemBox.right = itemBox.left + width;
|
|
5272 itemBox.bottom = itemBox.top + height;
|
|
5273
|
|
5274 /* To resize a control (like a button) we need to call both
|
|
5275 * SizeControl and SetDialogItem. (deducted from FAQ 6-18) */
|
|
5276 if (itemType & kControlDialogItem)
|
9
|
5277 SizeControl((ControlRef) itemHandle, width, height);
|
7
|
5278
|
|
5279 /* Configure back the item */
|
9
|
5280 SetDialogItem(theDialog, itemNumber, itemType, itemHandle, &itemBox);
|
7
|
5281 #endif
|
|
5282 }
|
|
5283
|
|
5284 static void
|
|
5285 macSetDialogItemText(
|
|
5286 DialogRef theDialog,
|
|
5287 short itemNumber,
|
|
5288 Str255 itemName)
|
|
5289 {
|
|
5290 short itemType;
|
|
5291 Handle itemHandle;
|
|
5292 Rect itemBox;
|
|
5293
|
9
|
5294 GetDialogItem(theDialog, itemNumber, &itemType, &itemHandle, &itemBox);
|
7
|
5295
|
|
5296 if (itemType & kControlDialogItem)
|
9
|
5297 SetControlTitle((ControlRef) itemHandle, itemName);
|
7
|
5298 else
|
9
|
5299 SetDialogItemText(itemHandle, itemName);
|
7
|
5300 }
|
|
5301
|
593
|
5302 /* TODO: There have been some crashes with dialogs, check your inbox
|
|
5303 * (Jussi)
|
|
5304 */
|
7
|
5305 int
|
|
5306 gui_mch_dialog(
|
|
5307 int type,
|
|
5308 char_u *title,
|
|
5309 char_u *message,
|
|
5310 char_u *buttons,
|
|
5311 int dfltbutton,
|
|
5312 char_u *textfield)
|
|
5313 {
|
|
5314 Handle buttonDITL;
|
|
5315 Handle iconDITL;
|
|
5316 Handle inputDITL;
|
|
5317 Handle messageDITL;
|
|
5318 Handle itemHandle;
|
|
5319 Handle iconHandle;
|
|
5320 DialogPtr theDialog;
|
|
5321 char_u len;
|
|
5322 char_u PascalTitle[256]; /* place holder for the title */
|
|
5323 char_u name[256];
|
|
5324 GrafPtr oldPort;
|
|
5325 short itemHit;
|
|
5326 char_u *buttonChar;
|
|
5327 Rect box;
|
|
5328 short button;
|
|
5329 short lastButton;
|
|
5330 short itemType;
|
|
5331 short useIcon;
|
|
5332 short width;
|
|
5333 short totalButtonWidth = 0; /* the width of all button together incuding spacing */
|
|
5334 short widestButton = 0;
|
|
5335 short dfltButtonEdge = 20; /* gut feeling */
|
|
5336 short dfltElementSpacing = 13; /* from IM:V.2-29 */
|
|
5337 short dfltIconSideSpace = 23; /* from IM:V.2-29 */
|
|
5338 short maximumWidth = 400; /* gut feeling */
|
|
5339 short maxButtonWidth = 175; /* gut feeling */
|
|
5340
|
|
5341 short vertical;
|
|
5342 short dialogHeight;
|
|
5343 short messageLines = 3;
|
|
5344 FontInfo textFontInfo;
|
|
5345
|
|
5346 vgmDlgItm iconItm;
|
|
5347 vgmDlgItm messageItm;
|
|
5348 vgmDlgItm inputItm;
|
|
5349 vgmDlgItm buttonItm;
|
|
5350
|
|
5351 WindowRef theWindow;
|
|
5352
|
|
5353 /* Check 'v' flag in 'guioptions': vertical button placement. */
|
|
5354 vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);
|
|
5355
|
|
5356 /* Create a new Dialog Box from template. */
|
9
|
5357 theDialog = GetNewDialog(129, nil, (WindowRef) -1);
|
7
|
5358
|
|
5359 /* Get the WindowRef */
|
|
5360 theWindow = GetDialogWindow(theDialog);
|
|
5361
|
|
5362 /* Hide the window.
|
|
5363 * 1. to avoid seeing slow drawing
|
|
5364 * 2. to prevent a problem seen while moving dialog item
|
|
5365 * within a visible window. (non-Carbon MacOS 9)
|
|
5366 * Could be avoided by changing the resource.
|
|
5367 */
|
9
|
5368 HideWindow(theWindow);
|
7
|
5369
|
|
5370 /* Change the graphical port to the dialog,
|
|
5371 * so we can measure the text with the proper font */
|
9
|
5372 GetPort(&oldPort);
|
|
5373 SetPortDialogPort(theDialog);
|
7
|
5374
|
|
5375 /* Get the info about the default text,
|
|
5376 * used to calculate the height of the message
|
|
5377 * and of the text field */
|
|
5378 GetFontInfo(&textFontInfo);
|
|
5379
|
|
5380 /* Set the dialog title */
|
|
5381 if (title != NULL)
|
|
5382 {
|
9
|
5383 (void) C2PascalString(title, &PascalTitle);
|
|
5384 SetWTitle(theWindow, PascalTitle);
|
7
|
5385 }
|
|
5386
|
|
5387 /* Creates the buttons and add them to the Dialog Box. */
|
9
|
5388 buttonDITL = GetResource('DITL', 130);
|
7
|
5389 buttonChar = buttons;
|
|
5390 button = 0;
|
|
5391
|
|
5392 for (;*buttonChar != 0;)
|
|
5393 {
|
|
5394 /* Get the name of the button */
|
|
5395 button++;
|
|
5396 len = 0;
|
|
5397 for (;((*buttonChar != DLG_BUTTON_SEP) && (*buttonChar != 0) && (len < 255)); buttonChar++)
|
|
5398 {
|
|
5399 if (*buttonChar != DLG_HOTKEY_CHAR)
|
|
5400 name[++len] = *buttonChar;
|
|
5401 }
|
|
5402 if (*buttonChar != 0)
|
|
5403 buttonChar++;
|
|
5404 name[0] = len;
|
|
5405
|
|
5406 /* Add the button */
|
9
|
5407 AppendDITL(theDialog, buttonDITL, overlayDITL); /* appendDITLRight); */
|
7
|
5408
|
|
5409 /* Change the button's name */
|
9
|
5410 macSetDialogItemText(theDialog, button, name);
|
7
|
5411
|
|
5412 /* Resize the button to fit its name */
|
9
|
5413 width = StringWidth(name) + 2 * dfltButtonEdge;
|
7
|
5414 /* Limite the size of any button to an acceptable value. */
|
|
5415 /* TODO: Should be based on the message width */
|
|
5416 if (width > maxButtonWidth)
|
|
5417 width = maxButtonWidth;
|
9
|
5418 macSizeDialogItem(theDialog, button, width, 0);
|
7
|
5419
|
|
5420 totalButtonWidth += width;
|
|
5421
|
|
5422 if (width > widestButton)
|
|
5423 widestButton = width;
|
|
5424 }
|
9
|
5425 ReleaseResource(buttonDITL);
|
7
|
5426 lastButton = button;
|
|
5427
|
|
5428 /* Add the icon to the Dialog Box. */
|
|
5429 iconItm.idx = lastButton + 1;
|
9
|
5430 iconDITL = GetResource('DITL', 131);
|
7
|
5431 switch (type)
|
|
5432 {
|
|
5433 case VIM_GENERIC: useIcon = kNoteIcon;
|
|
5434 case VIM_ERROR: useIcon = kStopIcon;
|
|
5435 case VIM_WARNING: useIcon = kCautionIcon;
|
|
5436 case VIM_INFO: useIcon = kNoteIcon;
|
|
5437 case VIM_QUESTION: useIcon = kNoteIcon;
|
|
5438 default: useIcon = kStopIcon;
|
|
5439 };
|
9
|
5440 AppendDITL(theDialog, iconDITL, overlayDITL);
|
|
5441 ReleaseResource(iconDITL);
|
|
5442 GetDialogItem(theDialog, iconItm.idx, &itemType, &itemHandle, &box);
|
7
|
5443 /* TODO: Should the item be freed? */
|
9
|
5444 iconHandle = GetIcon(useIcon);
|
|
5445 SetDialogItem(theDialog, iconItm.idx, itemType, iconHandle, &box);
|
7
|
5446
|
|
5447 /* Add the message to the Dialog box. */
|
|
5448 messageItm.idx = lastButton + 2;
|
9
|
5449 messageDITL = GetResource('DITL', 132);
|
|
5450 AppendDITL(theDialog, messageDITL, overlayDITL);
|
|
5451 ReleaseResource(messageDITL);
|
|
5452 GetDialogItem(theDialog, messageItm.idx, &itemType, &itemHandle, &box);
|
|
5453 (void) C2PascalString(message, &name);
|
|
5454 SetDialogItemText(itemHandle, name);
|
|
5455 messageItm.width = StringWidth(name);
|
7
|
5456
|
|
5457 /* Add the input box if needed */
|
|
5458 if (textfield != NULL)
|
|
5459 {
|
|
5460 /* Cheat for now reuse the message and convet to text edit */
|
|
5461 inputItm.idx = lastButton + 3;
|
9
|
5462 inputDITL = GetResource('DITL', 132);
|
|
5463 AppendDITL(theDialog, inputDITL, overlayDITL);
|
|
5464 ReleaseResource(inputDITL);
|
|
5465 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &box);
|
|
5466 /* SetDialogItem(theDialog, inputItm.idx, kEditTextDialogItem, itemHandle, &box);*/
|
|
5467 (void) C2PascalString(textfield, &name);
|
|
5468 SetDialogItemText(itemHandle, name);
|
|
5469 inputItm.width = StringWidth(name);
|
7
|
5470 }
|
|
5471
|
|
5472 /* Set the <ENTER> and <ESC> button. */
|
9
|
5473 SetDialogDefaultItem(theDialog, dfltbutton);
|
|
5474 SetDialogCancelItem(theDialog, 0);
|
7
|
5475
|
|
5476 /* Reposition element */
|
|
5477
|
|
5478 /* Check if we need to force vertical */
|
|
5479 if (totalButtonWidth > maximumWidth)
|
|
5480 vertical = TRUE;
|
|
5481
|
|
5482 /* Place icon */
|
9
|
5483 macMoveDialogItem(theDialog, iconItm.idx, dfltIconSideSpace, dfltElementSpacing, &box);
|
7
|
5484 iconItm.box.right = box.right;
|
|
5485 iconItm.box.bottom = box.bottom;
|
|
5486
|
|
5487 /* Place Message */
|
|
5488 messageItm.box.left = iconItm.box.right + dfltIconSideSpace;
|
9
|
5489 macSizeDialogItem(theDialog, messageItm.idx, 0, messageLines * (textFontInfo.ascent + textFontInfo.descent));
|
|
5490 macMoveDialogItem(theDialog, messageItm.idx, messageItm.box.left, dfltElementSpacing, &messageItm.box);
|
7
|
5491
|
|
5492 /* Place Input */
|
|
5493 if (textfield != NULL)
|
|
5494 {
|
|
5495 inputItm.box.left = messageItm.box.left;
|
|
5496 inputItm.box.top = messageItm.box.bottom + dfltElementSpacing;
|
9
|
5497 macSizeDialogItem(theDialog, inputItm.idx, 0, textFontInfo.ascent + textFontInfo.descent);
|
|
5498 macMoveDialogItem(theDialog, inputItm.idx, inputItm.box.left, inputItm.box.top, &inputItm.box);
|
7
|
5499 /* Convert the static text into a text edit.
|
|
5500 * For some reason this change need to be done last (Dany) */
|
9
|
5501 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &inputItm.box);
|
|
5502 SetDialogItem(theDialog, inputItm.idx, kEditTextDialogItem, itemHandle, &inputItm.box);
|
7
|
5503 SelectDialogItemText(theDialog, inputItm.idx, 0, 32767);
|
|
5504 }
|
|
5505
|
|
5506 /* Place Button */
|
|
5507 if (textfield != NULL)
|
|
5508 {
|
|
5509 buttonItm.box.left = inputItm.box.left;
|
|
5510 buttonItm.box.top = inputItm.box.bottom + dfltElementSpacing;
|
|
5511 }
|
|
5512 else
|
|
5513 {
|
|
5514 buttonItm.box.left = messageItm.box.left;
|
|
5515 buttonItm.box.top = messageItm.box.bottom + dfltElementSpacing;
|
|
5516 }
|
|
5517
|
|
5518 for (button=1; button <= lastButton; button++)
|
|
5519 {
|
|
5520
|
9
|
5521 macMoveDialogItem(theDialog, button, buttonItm.box.left, buttonItm.box.top, &box);
|
7
|
5522 /* With vertical, it's better to have all button the same lenght */
|
|
5523 if (vertical)
|
|
5524 {
|
9
|
5525 macSizeDialogItem(theDialog, button, widestButton, 0);
|
|
5526 GetDialogItem(theDialog, button, &itemType, &itemHandle, &box);
|
7
|
5527 }
|
|
5528 /* Calculate position of next button */
|
|
5529 if (vertical)
|
|
5530 buttonItm.box.top = box.bottom + dfltElementSpacing;
|
|
5531 else
|
|
5532 buttonItm.box.left = box.right + dfltElementSpacing;
|
|
5533 }
|
|
5534
|
|
5535 /* Resize the dialog box */
|
|
5536 dialogHeight = box.bottom + dfltElementSpacing;
|
|
5537 SizeWindow(theWindow, maximumWidth, dialogHeight, TRUE);
|
|
5538
|
|
5539 /* Magic resize */
|
9
|
5540 AutoSizeDialog(theDialog);
|
7
|
5541 /* Need a horizontal resize anyway so not that useful */
|
|
5542
|
|
5543 /* Display it */
|
|
5544 ShowWindow(theWindow);
|
|
5545 /* BringToFront(theWindow); */
|
|
5546 SelectWindow(theWindow);
|
|
5547
|
9
|
5548 /* DrawDialog(theDialog); */
|
7
|
5549 #if 0
|
9
|
5550 GetPort(&oldPort);
|
|
5551 SetPortDialogPort(theDialog);
|
7
|
5552 #endif
|
|
5553
|
|
5554 /* Hang until one of the button is hit */
|
|
5555 do
|
|
5556 {
|
9
|
5557 ModalDialog(nil, &itemHit);
|
7
|
5558 } while ((itemHit < 1) || (itemHit > lastButton));
|
|
5559
|
|
5560 /* Copy back the text entered by the user into the param */
|
|
5561 if (textfield != NULL)
|
|
5562 {
|
9
|
5563 GetDialogItem(theDialog, inputItm.idx, &itemType, &itemHandle, &box);
|
|
5564 GetDialogItemText(itemHandle, (char_u *) &name);
|
7
|
5565 #if IOSIZE < 256
|
|
5566 /* Truncate the name to IOSIZE if needed */
|
|
5567 if (name[0] > IOSIZE)
|
|
5568 name[0] = IOSIZE - 1;
|
|
5569 #endif
|
418
|
5570 vim_strncpy(textfield, &name[1], name[0]);
|
7
|
5571 }
|
|
5572
|
|
5573 /* Restore the original graphical port */
|
9
|
5574 SetPort(oldPort);
|
7
|
5575
|
|
5576 /* Get ride of th edialog (free memory) */
|
9
|
5577 DisposeDialog(theDialog);
|
7
|
5578
|
|
5579 return itemHit;
|
|
5580 /*
|
|
5581 * Usefull thing which could be used
|
|
5582 * SetDialogTimeout(): Auto click a button after timeout
|
|
5583 * SetDialogTracksCursor() : Get the I-beam cursor over input box
|
|
5584 * MoveDialogItem(): Probably better than SetDialogItem
|
|
5585 * SizeDialogItem(): (but is it Carbon Only?)
|
|
5586 * AutoSizeDialog(): Magic resize of dialog based on text lenght
|
|
5587 */
|
|
5588 }
|
|
5589 #endif /* FEAT_DIALOG_GUI */
|
|
5590
|
|
5591 /*
|
|
5592 * Display the saved error message(s).
|
|
5593 */
|
|
5594 #ifdef USE_MCH_ERRMSG
|
|
5595 void
|
593
|
5596 display_errors(void)
|
7
|
5597 {
|
|
5598 char *p;
|
|
5599 char_u pError[256];
|
|
5600
|
593
|
5601 if (error_ga.ga_data == NULL)
|
|
5602 return;
|
|
5603
|
|
5604 /* avoid putting up a message box with blanks only */
|
|
5605 for (p = (char *)error_ga.ga_data; *p; ++p)
|
|
5606 if (!isspace(*p))
|
|
5607 {
|
|
5608 if (STRLEN(p) > 255)
|
|
5609 pError[0] = 255;
|
|
5610 else
|
|
5611 pError[0] = STRLEN(p);
|
|
5612
|
|
5613 STRNCPY(&pError[1], p, pError[0]);
|
|
5614 ParamText(pError, nil, nil, nil);
|
|
5615 Alert(128, nil);
|
|
5616 break;
|
|
5617 /* TODO: handled message longer than 256 chars
|
|
5618 * use auto-sizeable alert
|
|
5619 * or dialog with scrollbars (TextEdit zone)
|
|
5620 */
|
|
5621 }
|
|
5622 ga_clear(&error_ga);
|
7
|
5623 }
|
|
5624 #endif
|
|
5625
|
|
5626 /*
|
87
|
5627 * Get current mouse coordinates in text window.
|
7
|
5628 */
|
95
|
5629 void
|
|
5630 gui_mch_getmouse(int *x, int *y)
|
7
|
5631 {
|
|
5632 Point where;
|
|
5633
|
|
5634 GetMouse(&where);
|
|
5635
|
87
|
5636 *x = where.h;
|
|
5637 *y = where.v;
|
7
|
5638 }
|
|
5639
|
|
5640 void
|
593
|
5641 gui_mch_setmouse(int x, int y)
|
7
|
5642 {
|
|
5643 /* TODO */
|
|
5644 #if 0
|
|
5645 /* From FAQ 3-11 */
|
|
5646
|
|
5647 CursorDevicePtr myMouse;
|
|
5648 Point where;
|
|
5649
|
9
|
5650 if ( NGetTrapAddress(_CursorDeviceDispatch, ToolTrap)
|
|
5651 != NGetTrapAddress(_Unimplemented, ToolTrap))
|
7
|
5652 {
|
|
5653 /* New way */
|
|
5654
|
|
5655 /*
|
|
5656 * Get first devoice with one button.
|
|
5657 * This will probably be the standad mouse
|
|
5658 * startat head of cursor dev list
|
|
5659 *
|
|
5660 */
|
|
5661
|
|
5662 myMouse = nil;
|
|
5663
|
|
5664 do
|
|
5665 {
|
|
5666 /* Get the next cursor device */
|
|
5667 CursorDeviceNextDevice(&myMouse);
|
|
5668 }
|
9
|
5669 while ((myMouse != nil) && (myMouse->cntButtons != 1));
|
|
5670
|
|
5671 CursorDeviceMoveTo(myMouse, x, y);
|
7
|
5672 }
|
|
5673 else
|
|
5674 {
|
|
5675 /* Old way */
|
|
5676 where.h = x;
|
|
5677 where.v = y;
|
|
5678
|
|
5679 *(Point *)RawMouse = where;
|
|
5680 *(Point *)MTemp = where;
|
|
5681 *(Ptr) CrsrNew = 0xFFFF;
|
|
5682 }
|
|
5683 #endif
|
|
5684 }
|
|
5685
|
|
5686 void
|
593
|
5687 gui_mch_show_popupmenu(vimmenu_T *menu)
|
7
|
5688 {
|
|
5689 /*
|
|
5690 * Clone PopUp to use menu
|
|
5691 * Create a object descriptor for the current selection
|
|
5692 * Call the procedure
|
|
5693 */
|
|
5694
|
|
5695 MenuHandle CntxMenu;
|
|
5696 Point where;
|
|
5697 OSStatus status;
|
|
5698 UInt32 CntxType;
|
|
5699 SInt16 CntxMenuID;
|
|
5700 UInt16 CntxMenuItem;
|
|
5701 Str255 HelpName = "";
|
|
5702 GrafPtr savePort;
|
|
5703
|
|
5704 /* Save Current Port: On MacOS X we seem to lose the port */
|
9
|
5705 GetPort(&savePort); /*OSX*/
|
|
5706
|
|
5707 GetMouse(&where);
|
|
5708 LocalToGlobal(&where); /*OSX*/
|
7
|
5709 CntxMenu = menu->submenu_handle;
|
|
5710
|
|
5711 /* TODO: Get the text selection from Vim */
|
|
5712
|
|
5713 /* Call to Handle Popup */
|
|
5714 status = ContextualMenuSelect(CntxMenu, where, false, kCMHelpItemNoHelp, HelpName, NULL, &CntxType, &CntxMenuID, &CntxMenuItem);
|
|
5715
|
|
5716 if (status == noErr)
|
|
5717 {
|
|
5718 if (CntxType == kCMMenuItemSelected)
|
|
5719 {
|
|
5720 /* Handle the menu CntxMenuID, CntxMenuItem */
|
|
5721 /* The submenu can be handle directly by gui_mac_handle_menu */
|
|
5722 /* But what about the current menu, is the menu changed by ContextualMenuSelect */
|
9
|
5723 gui_mac_handle_menu((CntxMenuID << 16) + CntxMenuItem);
|
7
|
5724 }
|
|
5725 else if (CntxMenuID == kCMShowHelpSelected)
|
|
5726 {
|
|
5727 /* Should come up with the help */
|
|
5728 }
|
|
5729 }
|
|
5730
|
|
5731 /* Restore original Port */
|
9
|
5732 SetPort(savePort); /*OSX*/
|
7
|
5733 }
|
|
5734
|
|
5735 #if defined(FEAT_CW_EDITOR) || defined(PROTO)
|
|
5736 /* TODO: Is it need for MACOS_X? (Dany) */
|
|
5737 void
|
|
5738 mch_post_buffer_write(buf_T *buf)
|
|
5739 {
|
9
|
5740 GetFSSpecFromPath(buf->b_ffname, &buf->b_FSSpec);
|
|
5741 Send_KAHL_MOD_AE(buf);
|
7
|
5742 }
|
|
5743 #endif
|
|
5744
|
|
5745 #ifdef FEAT_TITLE
|
|
5746 /*
|
|
5747 * Set the window title and icon.
|
|
5748 * (The icon is not taken care of).
|
|
5749 */
|
|
5750 void
|
593
|
5751 gui_mch_settitle(char_u *title, char_u *icon)
|
7
|
5752 {
|
|
5753 /* TODO: Get vim to make sure maxlen (from p_titlelen) is smaller
|
|
5754 * that 256. Even better get it to fit nicely in the titlebar.
|
|
5755 */
|
766
|
5756 #ifdef MACOS_CONVERT
|
168
|
5757 CFStringRef windowTitle;
|
|
5758 size_t windowTitleLen;
|
|
5759 #else
|
7
|
5760 char_u *pascalTitle;
|
168
|
5761 #endif
|
7
|
5762
|
|
5763 if (title == NULL) /* nothing to do */
|
|
5764 return;
|
|
5765
|
766
|
5766 #ifdef MACOS_CONVERT
|
168
|
5767 windowTitleLen = STRLEN(title);
|
|
5768 windowTitle = mac_enc_to_cfstring(title, windowTitleLen);
|
|
5769
|
|
5770 if (windowTitle)
|
|
5771 {
|
|
5772 SetWindowTitleWithCFString(gui.VimWindow, windowTitle);
|
|
5773 CFRelease(windowTitle);
|
|
5774 }
|
|
5775 #else
|
7
|
5776 pascalTitle = C2Pascal_save(title);
|
|
5777 if (pascalTitle != NULL)
|
|
5778 {
|
|
5779 SetWTitle(gui.VimWindow, pascalTitle);
|
|
5780 vim_free(pascalTitle);
|
|
5781 }
|
168
|
5782 #endif
|
7
|
5783 }
|
|
5784 #endif
|
|
5785
|
|
5786 /*
|
|
5787 * Transfered from os_mac.c for MacOS X using os_unix.c prep work
|
|
5788 */
|
|
5789
|
|
5790 int
|
593
|
5791 C2PascalString(char_u *CString, Str255 *PascalString)
|
7
|
5792 {
|
|
5793 char_u *PascalPtr = (char_u *) PascalString;
|
|
5794 int len;
|
|
5795 int i;
|
|
5796
|
|
5797 PascalPtr[0] = 0;
|
|
5798 if (CString == NULL)
|
|
5799 return 0;
|
|
5800
|
|
5801 len = STRLEN(CString);
|
|
5802 if (len > 255)
|
|
5803 len = 255;
|
|
5804
|
|
5805 for (i = 0; i < len; i++)
|
|
5806 PascalPtr[i+1] = CString[i];
|
|
5807
|
|
5808 PascalPtr[0] = len;
|
|
5809
|
|
5810 return 0;
|
|
5811 }
|
|
5812
|
|
5813 int
|
593
|
5814 GetFSSpecFromPath(char_u *file, FSSpec *fileFSSpec)
|
7
|
5815 {
|
|
5816 /* From FAQ 8-12 */
|
|
5817 Str255 filePascal;
|
|
5818 CInfoPBRec myCPB;
|
|
5819 OSErr err;
|
|
5820
|
9
|
5821 (void) C2PascalString(file, &filePascal);
|
7
|
5822
|
|
5823 myCPB.dirInfo.ioNamePtr = filePascal;
|
|
5824 myCPB.dirInfo.ioVRefNum = 0;
|
|
5825 myCPB.dirInfo.ioFDirIndex = 0;
|
|
5826 myCPB.dirInfo.ioDrDirID = 0;
|
|
5827
|
9
|
5828 err= PBGetCatInfo(&myCPB, false);
|
7
|
5829
|
|
5830 /* vRefNum, dirID, name */
|
9
|
5831 FSMakeFSSpec(0, 0, filePascal, fileFSSpec);
|
7
|
5832
|
|
5833 /* TODO: Use an error code mechanism */
|
|
5834 return 0;
|
|
5835 }
|
|
5836
|
|
5837 /*
|
|
5838 * Convert a FSSpec to a fuill path
|
|
5839 */
|
|
5840
|
9
|
5841 char_u *FullPathFromFSSpec_save(FSSpec file)
|
7
|
5842 {
|
|
5843 /*
|
|
5844 * TODO: Add protection for 256 char max.
|
|
5845 */
|
|
5846
|
|
5847 CInfoPBRec theCPB;
|
|
5848 char_u fname[256];
|
|
5849 char_u *filenamePtr = fname;
|
|
5850 OSErr error;
|
|
5851 int folder = 1;
|
|
5852 #ifdef USE_UNIXFILENAME
|
|
5853 SInt16 dfltVol_vRefNum;
|
|
5854 SInt32 dfltVol_dirID;
|
|
5855 FSRef refFile;
|
|
5856 OSStatus status;
|
|
5857 UInt32 pathSize = 256;
|
|
5858 char_u pathname[256];
|
|
5859 char_u *path = pathname;
|
|
5860 #else
|
|
5861 Str255 directoryName;
|
|
5862 char_u temporary[255];
|
|
5863 char_u *temporaryPtr = temporary;
|
|
5864 #endif
|
|
5865
|
|
5866 #ifdef USE_UNIXFILENAME
|
|
5867 /* Get the default volume */
|
|
5868 /* TODO: Remove as this only work if Vim is on the Boot Volume*/
|
9
|
5869 error=HGetVol(NULL, &dfltVol_vRefNum, &dfltVol_dirID);
|
7
|
5870
|
|
5871 if (error)
|
|
5872 return NULL;
|
|
5873 #endif
|
|
5874
|
|
5875 /* Start filling fname with file.name */
|
418
|
5876 vim_strncpy(filenamePtr, &file.name[1], file.name[0]);
|
7
|
5877
|
|
5878 /* Get the info about the file specified in FSSpec */
|
|
5879 theCPB.dirInfo.ioFDirIndex = 0;
|
|
5880 theCPB.dirInfo.ioNamePtr = file.name;
|
|
5881 theCPB.dirInfo.ioVRefNum = file.vRefNum;
|
|
5882 /*theCPB.hFileInfo.ioDirID = 0;*/
|
|
5883 theCPB.dirInfo.ioDrDirID = file.parID;
|
|
5884
|
|
5885 /* As ioFDirIndex = 0, get the info of ioNamePtr,
|
|
5886 which is relative to ioVrefNum, ioDirID */
|
9
|
5887 error = PBGetCatInfo(&theCPB, false);
|
7
|
5888
|
|
5889 /* If we are called for a new file we expect fnfErr */
|
|
5890 if ((error) && (error != fnfErr))
|
|
5891 return NULL;
|
|
5892
|
|
5893 /* Check if it's a file or folder */
|
|
5894 /* default to file if file don't exist */
|
|
5895 if (((theCPB.hFileInfo.ioFlAttrib & ioDirMask) == 0) || (error))
|
|
5896 folder = 0; /* It's not a folder */
|
|
5897 else
|
|
5898 folder = 1;
|
|
5899
|
|
5900 #ifdef USE_UNIXFILENAME
|
|
5901 /*
|
|
5902 * The function used here are available in Carbon, but
|
|
5903 * do nothing une MacOS 8 and 9
|
|
5904 */
|
|
5905 if (error == fnfErr)
|
|
5906 {
|
|
5907 /* If the file to be saved does not already exist, it isn't possible
|
|
5908 to convert its FSSpec into an FSRef. But we can construct an
|
|
5909 FSSpec for the file's parent folder (since we have its volume and
|
|
5910 directory IDs), and since that folder does exist, we can convert
|
|
5911 that FSSpec into an FSRef, convert the FSRef in turn into a path,
|
|
5912 and, finally, append the filename. */
|
|
5913 FSSpec dirSpec;
|
|
5914 FSRef dirRef;
|
|
5915 Str255 emptyFilename = "\p";
|
|
5916 error = FSMakeFSSpec(theCPB.dirInfo.ioVRefNum,
|
|
5917 theCPB.dirInfo.ioDrDirID, emptyFilename, &dirSpec);
|
|
5918 if (error)
|
|
5919 return NULL;
|
|
5920
|
|
5921 error = FSpMakeFSRef(&dirSpec, &dirRef);
|
|
5922 if (error)
|
|
5923 return NULL;
|
|
5924
|
|
5925 status = FSRefMakePath(&dirRef, (UInt8*)path, pathSize);
|
|
5926 if (status)
|
|
5927 return NULL;
|
|
5928
|
|
5929 STRCAT(path, "/");
|
|
5930 STRCAT(path, filenamePtr);
|
|
5931 }
|
|
5932 else
|
|
5933 {
|
|
5934 /* If the file to be saved already exists, we can get its full path
|
|
5935 by converting its FSSpec into an FSRef. */
|
9
|
5936 error=FSpMakeFSRef(&file, &refFile);
|
7
|
5937 if (error)
|
|
5938 return NULL;
|
|
5939
|
9
|
5940 status=FSRefMakePath(&refFile, (UInt8 *) path, pathSize);
|
7
|
5941 if (status)
|
|
5942 return NULL;
|
|
5943 }
|
|
5944
|
|
5945 /* Add a slash at the end if needed */
|
|
5946 if (folder)
|
9
|
5947 STRCAT(path, "/");
|
|
5948
|
|
5949 return (vim_strsave(path));
|
7
|
5950 #else
|
|
5951 /* TODO: Get rid of all USE_UNIXFILENAME below */
|
|
5952 /* Set ioNamePtr, it's the same area which is always reused. */
|
|
5953 theCPB.dirInfo.ioNamePtr = directoryName;
|
|
5954
|
|
5955 /* Trick for first entry, set ioDrParID to the first value
|
|
5956 * we want for ioDrDirID*/
|
|
5957 theCPB.dirInfo.ioDrParID = file.parID;
|
|
5958 theCPB.dirInfo.ioDrDirID = file.parID;
|
|
5959
|
9
|
5960 if ((TRUE) && (file.parID != fsRtDirID /*fsRtParID*/))
|
7
|
5961 do
|
|
5962 {
|
|
5963 theCPB.dirInfo.ioFDirIndex = -1;
|
|
5964 /* theCPB.dirInfo.ioNamePtr = directoryName; Already done above. */
|
|
5965 theCPB.dirInfo.ioVRefNum = file.vRefNum;
|
|
5966 /* theCPB.dirInfo.ioDirID = irrevelant when ioFDirIndex = -1 */
|
|
5967 theCPB.dirInfo.ioDrDirID = theCPB.dirInfo.ioDrParID;
|
|
5968
|
|
5969 /* As ioFDirIndex = -1, get the info of ioDrDirID, */
|
|
5970 /* *ioNamePtr[0 TO 31] will be updated */
|
9
|
5971 error = PBGetCatInfo(&theCPB,false);
|
7
|
5972
|
|
5973 if (error)
|
|
5974 return NULL;
|
|
5975
|
|
5976 /* Put the new directoryName in front of the current fname */
|
|
5977 STRCPY(temporaryPtr, filenamePtr);
|
418
|
5978 vim_strncpy(filenamePtr, &directoryName[1], directoryName[0]);
|
7
|
5979 STRCAT(filenamePtr, ":");
|
|
5980 STRCAT(filenamePtr, temporaryPtr);
|
|
5981 }
|
|
5982 #if 1 /* def USE_UNIXFILENAME */
|
|
5983 while ((theCPB.dirInfo.ioDrParID != fsRtDirID) /* && */
|
|
5984 /* (theCPB.dirInfo.ioDrDirID != fsRtDirID)*/);
|
|
5985 #else
|
|
5986 while (theCPB.dirInfo.ioDrDirID != fsRtDirID);
|
|
5987 #endif
|
|
5988
|
|
5989 /* Get the information about the volume on which the file reside */
|
|
5990 theCPB.dirInfo.ioFDirIndex = -1;
|
|
5991 /* theCPB.dirInfo.ioNamePtr = directoryName; Already done above. */
|
|
5992 theCPB.dirInfo.ioVRefNum = file.vRefNum;
|
|
5993 /* theCPB.dirInfo.ioDirID = irrevelant when ioFDirIndex = -1 */
|
|
5994 theCPB.dirInfo.ioDrDirID = theCPB.dirInfo.ioDrParID;
|
|
5995
|
|
5996 /* As ioFDirIndex = -1, get the info of ioDrDirID, */
|
|
5997 /* *ioNamePtr[0 TO 31] will be updated */
|
9
|
5998 error = PBGetCatInfo(&theCPB,false);
|
7
|
5999
|
|
6000 if (error)
|
|
6001 return NULL;
|
|
6002
|
|
6003 /* For MacOS Classic always add the volume name */
|
|
6004 /* For MacOS X add the volume name preceded by "Volumes" */
|
|
6005 /* when we are not refering to the boot volume */
|
|
6006 #ifdef USE_UNIXFILENAME
|
|
6007 if (file.vRefNum != dfltVol_vRefNum)
|
|
6008 #endif
|
|
6009 {
|
|
6010 /* Add the volume name */
|
|
6011 STRCPY(temporaryPtr, filenamePtr);
|
418
|
6012 vim_strncpy(filenamePtr, &directoryName[1], directoryName[0]);
|
7
|
6013 STRCAT(filenamePtr, ":");
|
|
6014 STRCAT(filenamePtr, temporaryPtr);
|
|
6015
|
|
6016 #ifdef USE_UNIXFILENAME
|
|
6017 STRCPY(temporaryPtr, filenamePtr);
|
|
6018 filenamePtr[0] = 0; /* NULL terminate the string */
|
|
6019 STRCAT(filenamePtr, "Volumes:");
|
|
6020 STRCAT(filenamePtr, temporaryPtr);
|
|
6021 #endif
|
|
6022 }
|
|
6023
|
|
6024 /* Append final path separator if it's a folder */
|
|
6025 if (folder)
|
9
|
6026 STRCAT(fname, ":");
|
7
|
6027
|
|
6028 /* As we use Unix File Name for MacOS X convert it */
|
|
6029 #ifdef USE_UNIXFILENAME
|
|
6030 /* Need to insert leading / */
|
|
6031 /* TODO: get the above code to use directly the / */
|
|
6032 STRCPY(&temporaryPtr[1], filenamePtr);
|
|
6033 temporaryPtr[0] = '/';
|
|
6034 STRCPY(filenamePtr, temporaryPtr);
|
|
6035 {
|
|
6036 char *p;
|
|
6037 for (p = fname; *p; p++)
|
|
6038 if (*p == ':')
|
|
6039 *p = '/';
|
|
6040 }
|
|
6041 #endif
|
|
6042
|
9
|
6043 return (vim_strsave(fname));
|
7
|
6044 #endif
|
|
6045 }
|
|
6046
|
|
6047 #if defined(USE_IM_CONTROL) || defined(PROTO)
|
|
6048 /*
|
|
6049 * Input Method Control functions.
|
|
6050 */
|
|
6051
|
|
6052 /*
|
|
6053 * Notify cursor position to IM.
|
|
6054 */
|
|
6055 void
|
|
6056 im_set_position(int row, int col)
|
|
6057 {
|
|
6058 /* TODO: Implement me! */
|
|
6059 }
|
|
6060
|
|
6061 /*
|
|
6062 * Set IM status on ("active" is TRUE) or off ("active" is FALSE).
|
|
6063 */
|
|
6064 void
|
|
6065 im_set_active(int active)
|
|
6066 {
|
|
6067 KeyScript(active ? smKeySysScript : smKeyRoman);
|
|
6068 }
|
|
6069
|
|
6070 /*
|
|
6071 * Get IM status. When IM is on, return not 0. Else return 0.
|
|
6072 */
|
|
6073 int
|
593
|
6074 im_get_status(void)
|
7
|
6075 {
|
|
6076 SInt32 script = GetScriptManagerVariable(smKeyScript);
|
|
6077 return (script != smRoman
|
|
6078 && script == GetScriptManagerVariable(smSysScript)) ? 1 : 0;
|
|
6079 }
|
|
6080 #endif /* defined(USE_IM_CONTROL) || defined(PROTO) */
|