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