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