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