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