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 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | * See README.txt for an overview of the Vim source code. |
| 8 | */ |
| 9 | |
| 10 | #include "vim.h" |
| 11 | #include <string.h> |
| 12 | |
| 13 | /* |
| 14 | * gui_riscos.c |
| 15 | * |
| 16 | * Thomas Leonard <tal197@ecs.soton.ac.uk> |
| 17 | * Updated by Andy Wingate <andy@sparse.net> |
| 18 | */ |
| 19 | |
| 20 | extern int time_of_last_poll; |
| 21 | |
| 22 | int task_handle = 0; /* Zero means we are not yet a Wimp task */ |
| 23 | int child_handle = 0; /* Task handle of our child process (zero if none). */ |
| 24 | int *wimp_menu = (int *) -1; /* Pointer to a Wimp menu structure (or -1) */ |
| 25 | int save_window = -1; /* Save As window handle */ |
| 26 | |
| 27 | int *redraw_block = NULL; /* NULL means not in a redraw loop. */ |
| 28 | int ro_return_early = FALSE; /* Break out of gui_mch_wait_for_chars() */ |
| 29 | |
| 30 | int leaf_ref = 0; /* Wimp message number - send via Wimp$Scrap */ |
| 31 | char_u *leaf_name = NULL; /* Leaf name from DataSave */ |
| 32 | |
| 33 | int default_columns = 120; /* These values are used if the --rows and --columns */ |
| 34 | int default_rows = 32; /* options aren't used on startup. */ |
| 35 | |
| 36 | #define DRAG_FALSE 0 |
| 37 | #define DRAG_SELECTION 1 |
| 38 | #define DRAG_RESIZE_WINDOW 2 |
| 39 | int ro_dragging = DRAG_FALSE; |
| 40 | int drag_button; |
| 41 | int drag_modifiers; |
| 42 | int drag_x_offset; |
| 43 | int drag_y_offset; |
| 44 | |
| 45 | int nested_wimp = FALSE; /* Bool - can we use the new wimp? */ |
| 46 | |
| 47 | int changed_mode = FALSE; |
| 48 | int x_eigen_factor; |
| 49 | int y_eigen_factor; |
| 50 | |
| 51 | /* If ro_current_font is non-zero then use the outline font with that handle, |
| 52 | * otherwise, if zap_redraw is TRUE then use ZapRedraw, otherwise use the |
| 53 | * system font. |
| 54 | * |
| 55 | * If zap_redraw is TRUE then zap_file[] contains valid Zap font file |
| 56 | * pointers (or NULLs). |
| 57 | */ |
| 58 | int ro_current_font = 0; /* 0 is system font, or ZapRedraw */ |
| 59 | int font_x_offset = 0; /* Where to position each char in its box */ |
| 60 | int font_y_offset = 0; |
| 61 | |
| 62 | int zap_redraw = FALSE; |
| 63 | int double_height = FALSE; /* Plot each line twice? */ |
| 64 | |
| 65 | #define grgb(r,g,b) ((b<<16) + (g<<8) + (r)) |
| 66 | #define UNUSED_COLOUR (gui.back_pixel) |
| 67 | |
| 68 | #define RO_LOAD_CLIPBOARD -2 /* Internal handle for DataSave message. */ |
| 69 | |
| 70 | /* Changes by John Kortink, 22-23 July 1998 |
| 71 | * |
| 72 | * Stuff to make redraw a lot faster. Almost all of it is right here below, |
| 73 | * elsewhere changes are marked with 'JK230798'. Apart from a small change in |
| 74 | * 'gui.c' all changes are limited to this file, 'gui_riscos.c'. The change in |
| 75 | * 'gui.c' is to make Vim stop being 'smart' not redrawing characters that are |
| 76 | * 'already there' (i.e. from the previous line, by coincidence). This caused a |
| 77 | * lot more calls to the redraw code, which we want to avoid because a few nice |
| 78 | * big strings at a time is a lot faster than a truckload of small ones. ('Dear |
| 79 | * Bram ...'). |
| 80 | */ |
| 81 | |
| 82 | /* The ZapRedraw structure */ |
| 83 | |
| 84 | static struct |
| 85 | { |
| 86 | int r_flags; |
| 87 | int r_minx; |
| 88 | int r_miny; |
| 89 | int r_maxx; |
| 90 | int r_maxy; |
| 91 | int r_screen; |
| 92 | int r_bpl; |
| 93 | int r_bpp; |
| 94 | int r_charw; |
| 95 | int r_charh; |
| 96 | char *r_caddr; |
| 97 | int r_cbpl; |
| 98 | int r_cbpc; |
| 99 | int r_linesp; |
| 100 | int r_data; |
| 101 | int r_scrollx; |
| 102 | int r_scrolly; |
| 103 | int *r_palette; |
| 104 | int r_for; |
| 105 | int r_bac; |
| 106 | char *r_workarea; |
| 107 | int r_magx; |
| 108 | int r_magy; |
| 109 | int r_xsize; |
| 110 | int r_ysize; |
| 111 | int r_mode; |
| 112 | } |
| 113 | zap_redraw_block; |
| 114 | |
| 115 | /* Other globals */ |
| 116 | |
| 117 | static int zap_redraw_initialised = FALSE; |
| 118 | static int zap_redraw_update_colours; |
| 119 | static int zap_redraw_colours[2]; |
| 120 | static int zap_redraw_palette[16]; |
| 121 | |
| 122 | /* Holds the current Zap font file(s). |
| 123 | * The font is recreated from this block on a mode change. |
| 124 | * When using zap, element ZAP_NORMAL is always valid, but |
| 125 | * the others can be NULL. |
| 126 | */ |
| 127 | |
| 128 | #define ZAP_NORMAL 0 |
| 129 | #define ZAP_BOLD 1 |
| 130 | #define ZAP_ITALIC 2 |
| 131 | #define ZAP_BITALIC 3 |
| 132 | #define ZAP_STYLES 4 |
| 133 | |
| 134 | /* Zap font file format data */ |
| 135 | static char *zap_file[ZAP_STYLES] = {NULL, NULL, NULL, NULL}; |
| 136 | |
| 137 | /* r_caddr format for current mode */ |
| 138 | static char *zap_caddr[ZAP_STYLES] = {NULL, NULL, NULL, NULL}; |
| 139 | |
| 140 | static void ro_remove_menu(int *menu); |
| 141 | |
| 142 | /* |
| 143 | * Initialise all the ZapRedraw stuff. |
| 144 | * Call this when changing font and after each mode change. |
| 145 | * zap_redraw_bitmap must contain a valid Zap font file (possibly |
| 146 | * created from the system font). |
| 147 | * |
| 148 | * Return FAIL to revert to system font (if we can't use ZapRedraw). |
| 149 | */ |
| 150 | int |
| 151 | ro_zap_redraw_initialise() |
| 152 | { |
| 153 | int bytes_per_bitmap_char; |
| 154 | int first, last; |
| 155 | int i; |
| 156 | |
| 157 | /* Can't have initialisers for struct members :-(, ok, this way then ... */ |
| 158 | if (!zap_redraw_initialised) |
| 159 | { |
| 160 | zap_redraw_block.r_workarea = NULL; |
| 161 | zap_redraw_initialised = TRUE; |
| 162 | } |
| 163 | |
| 164 | /* We redraw in DSA mode */ |
| 165 | zap_redraw_block.r_flags = 0x0; |
| 166 | |
| 167 | /* Let ZapRedraw get the screen address for us */ |
| 168 | zap_redraw_block.r_screen = 0; |
| 169 | |
| 170 | /* Read the font width and height from the font file header. |
| 171 | * Assume that all styles are the same size. |
| 172 | * ZAP_NORMAL is always present. |
| 173 | */ |
| 174 | zap_redraw_block.r_charw = ((int *) zap_file[ZAP_NORMAL])[2]; |
| 175 | zap_redraw_block.r_charh = ((int *) zap_file[ZAP_NORMAL])[3]; |
| 176 | |
| 177 | /* We have no linespacing */ |
| 178 | zap_redraw_block.r_linesp = 0; |
| 179 | |
| 180 | /* Fix foreground = colour 1 */ |
| 181 | zap_redraw_block.r_for = 1; |
| 182 | |
| 183 | /* Fix background = colour 0 */ |
| 184 | zap_redraw_block.r_bac = 0; |
| 185 | |
| 186 | /* Colour mask buffer */ |
| 187 | zap_redraw_block.r_palette = zap_redraw_palette; |
| 188 | |
| 189 | /* Allocate local workspace (for the few calls following here) */ |
| 190 | if (zap_redraw_block.r_workarea != NULL) |
| 191 | free(zap_redraw_block.r_workarea); |
| 192 | zap_redraw_block.r_workarea = (char*) malloc(128); |
| 193 | if (!zap_redraw_block.r_workarea) |
| 194 | return FAIL; /* Out of memory */ |
| 195 | |
| 196 | /* Fill in VDU variables */ |
| 197 | if (xswi(ZapRedraw_ReadVduVars, 0, &zap_redraw_block) & v_flag) |
| 198 | return FAIL; /* Can't find ZapRedraw module - use VDU instead */ |
| 199 | |
| 200 | /* Determine cbpl and cbpc */ |
| 201 | swi(ZapRedraw_CachedCharSize, zap_redraw_block.r_bpp, 0, |
| 202 | zap_redraw_block.r_charw, zap_redraw_block.r_charh); |
| 203 | zap_redraw_block.r_cbpl = r2; |
| 204 | zap_redraw_block.r_cbpc = r3; |
| 205 | |
| 206 | /* Allocate general workspace (for the calls outside) */ |
| 207 | if (zap_redraw_block.r_workarea != NULL) |
| 208 | free(zap_redraw_block.r_workarea); |
| 209 | zap_redraw_block.r_workarea = (char*) malloc(128 + zap_redraw_block.r_cbpl); |
| 210 | if (!zap_redraw_block.r_workarea) |
| 211 | return FAIL; /* Out of memory */ |
| 212 | |
| 213 | /* Now convert the 1 bpp character data ready for the current mode */ |
| 214 | |
| 215 | bytes_per_bitmap_char = (zap_redraw_block.r_charw * zap_redraw_block.r_charh + 7) / 8; |
| 216 | |
| 217 | /* Convert the fonts from 1bpp to a format suitable for the |
| 218 | * current mode. |
| 219 | */ |
| 220 | for (i = 0; i < ZAP_STYLES; i++) |
| 221 | { |
| 222 | first = ((int *) zap_file[i])[4]; |
| 223 | last = ((int *) zap_file[i])[5]; |
| 224 | |
| 225 | if (last > 255) |
| 226 | last = 255; /* Don't convert cursors (overwrites memory!) */ |
| 227 | |
| 228 | /* Allocate the font cache */ |
| 229 | vim_free(zap_caddr[i]); |
| 230 | if (zap_file[i]) |
| 231 | zap_caddr[i] = (char*) malloc(zap_redraw_block.r_cbpc * 256); |
| 232 | else |
| 233 | zap_caddr[i] = NULL; /* No file for this style */ |
| 234 | |
| 235 | if (zap_caddr[i]) |
| 236 | { |
| 237 | zap_redraw_block.r_caddr = zap_caddr[i]; |
| 238 | |
| 239 | swi(ZapRedraw_ConvertBitmap, 0, &zap_redraw_block, |
| 240 | first, last, /* Range of characters to convert */ |
| 241 | zap_file[i] + 0x20 /* Addr of first char provided by font */ |
| 242 | - first * bytes_per_bitmap_char); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | if (!zap_caddr[ZAP_NORMAL]) |
| 247 | { |
| 248 | zap_redraw = FALSE; /* Out of memory */ |
| 249 | return FAIL; |
| 250 | } |
| 251 | |
| 252 | /* Next time we need them, we have to update the colour masks */ |
| 253 | zap_redraw_update_colours = TRUE; |
| 254 | |
| 255 | return OK; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * Redraw a string at OS coordinates <x,y> (top-left, x inclusive, y exclusive). |
| 260 | * Graphics clip window is window[0..3] as in R1+28..40 of Wimp_RedrawWindow. |
| 261 | * Returns (possibly modified) flags. |
| 262 | */ |
| 263 | int |
| 264 | ro_zap_redraw_draw_string(x, y, string, length, flags, clip) |
| 265 | int x; |
| 266 | int y; |
| 267 | char *string; |
| 268 | int length; |
| 269 | int flags; /* DRAW_TRANSP, DRAW_BOLD, DRAW_UNDERL, DRAW_ITALIC */ |
| 270 | int *clip; |
| 271 | { |
| 272 | char redraw_data[1024]; |
| 273 | int clip_minx; |
| 274 | int clip_miny; |
| 275 | int clip_maxx; |
| 276 | int clip_maxy; |
| 277 | int os_xshift = zap_redraw_block.r_magx; |
| 278 | int os_yshift = zap_redraw_block.r_magy; |
| 279 | |
| 280 | if (flags & DRAW_TRANSP) |
| 281 | return flags; /* We don't do transparent plotting yet. */ |
| 282 | |
| 283 | if (flags & DRAW_BOLD) |
| 284 | { |
| 285 | if (flags & DRAW_ITALIC && zap_caddr[ZAP_BITALIC]) |
| 286 | zap_redraw_block.r_caddr = zap_caddr[ZAP_BITALIC]; |
| 287 | else |
| 288 | zap_redraw_block.r_caddr = zap_caddr[ZAP_BOLD]; |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | if (flags & DRAW_ITALIC) |
| 293 | zap_redraw_block.r_caddr = zap_caddr[ZAP_ITALIC]; |
| 294 | else |
| 295 | zap_redraw_block.r_caddr = zap_caddr[ZAP_NORMAL]; |
| 296 | } |
| 297 | if (!zap_redraw_block.r_caddr) |
| 298 | { |
| 299 | zap_redraw_block.r_caddr = zap_caddr[ZAP_NORMAL]; |
| 300 | flags |= DRAW_UNDERL; /* Style missing - we can always underline */ |
| 301 | } |
| 302 | |
| 303 | /* Set the vertical scaling flag */ |
| 304 | if (double_height) |
| 305 | zap_redraw_block.r_flags = 1 << 1; |
| 306 | else |
| 307 | zap_redraw_block.r_flags = 0; |
| 308 | |
| 309 | /* Update the colour masks (if needed) */ |
| 310 | if (zap_redraw_update_colours) |
| 311 | { |
| 312 | swi(ZapRedraw_CreatePalette, 2, |
| 313 | &zap_redraw_block, |
| 314 | zap_redraw_colours, |
| 315 | zap_redraw_block.r_palette, 2); |
| 316 | zap_redraw_update_colours = FALSE; |
| 317 | } |
| 318 | |
| 319 | /* Target rectangle in ZapRedraw rectangle coordinates (pixels, Y-min/max reversed !!!) */ |
| 320 | zap_redraw_block.r_minx = x >> os_xshift; /* inclusive */ |
| 321 | zap_redraw_block.r_miny = zap_redraw_block.r_ysize - (y >> os_yshift); /* inclusive */ |
| 322 | zap_redraw_block.r_maxx = (x + length * gui.char_width) >> os_xshift; /* exclusive */ |
| 323 | zap_redraw_block.r_maxy = zap_redraw_block.r_ysize - ((y - gui.char_height) >> os_yshift); |
| 324 | /* exclusive */ |
| 325 | |
| 326 | /* Clip rectangle in ZapRedraw rectangle coordinates (pixels, Y-min/max reversed !!!) */ |
| 327 | clip_minx = clip[0] >> os_xshift; /* inclusive */ |
| 328 | clip_miny = zap_redraw_block.r_ysize - (clip[3] >> os_yshift); /* inclusive */ |
| 329 | clip_maxx = clip[2] >> os_xshift; /* exclusive */ |
| 330 | clip_maxy = zap_redraw_block.r_ysize - (clip[1] >> os_yshift); /* exclusive */ |
| 331 | |
| 332 | /* Clip target rectangle against the current graphics window */ |
| 333 | if (zap_redraw_block.r_minx < clip_minx) |
| 334 | { |
| 335 | zap_redraw_block.r_scrollx = clip_minx - zap_redraw_block.r_minx; |
| 336 | zap_redraw_block.r_minx = clip_minx; |
| 337 | } |
| 338 | else |
| 339 | zap_redraw_block.r_scrollx = 0; |
| 340 | if (zap_redraw_block.r_miny < clip_miny) |
| 341 | { |
| 342 | zap_redraw_block.r_scrolly = clip_miny - zap_redraw_block.r_miny; |
| 343 | zap_redraw_block.r_miny = clip_miny; |
| 344 | } |
| 345 | else |
| 346 | zap_redraw_block.r_scrolly = 0; |
| 347 | if (zap_redraw_block.r_maxx > clip_maxx) |
| 348 | zap_redraw_block.r_maxx = clip_maxx; |
| 349 | if (zap_redraw_block.r_maxy > clip_maxy) |
| 350 | zap_redraw_block.r_maxy = clip_maxy; |
| 351 | |
| 352 | /* Fill in the character data structure */ |
| 353 | if (length > (sizeof(redraw_data) - 2 * 4 - 2)) |
| 354 | length = sizeof(redraw_data) - 2 * 4 - 2; |
| 355 | ((int*) redraw_data)[0] = 2 * 4; |
| 356 | ((int*) redraw_data)[1] = 0; |
| 357 | strncpy(redraw_data + 2 * 4, string, length); |
| 358 | redraw_data[2 * 4 + length + 0] = '\0'; |
| 359 | redraw_data[2 * 4 + length + 1] = '\x2'; |
| 360 | zap_redraw_block.r_data = (int) redraw_data; |
| 361 | |
| 362 | /* Perform the draw */ |
| 363 | swi(ZapRedraw_RedrawArea, 0, &zap_redraw_block); |
| 364 | |
| 365 | return flags; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Okay that was it from me, back to Thomas ... |
| 370 | */ |
| 371 | |
| 372 | /* |
| 373 | * Parse the GUI related command-line arguments. Any arguments used are |
| 374 | * deleted from argv, and *argc is decremented accordingly. This is called |
| 375 | * when vim is started, whether or not the GUI has been started. |
| 376 | */ |
| 377 | void |
| 378 | gui_mch_prepare(int *argc, char **argv) |
| 379 | { |
| 380 | int arg = 1; |
| 381 | |
| 382 | while (arg < *argc - 1) |
| 383 | { |
| 384 | if (strcmp(argv[arg], "--rows") == 0 || strcmp(argv[arg], "--columns") == 0) |
| 385 | { |
| 386 | int value; |
| 387 | |
| 388 | value = atoi(argv[arg + 1]); |
| 389 | |
| 390 | if (argv[arg][2] == 'r') |
| 391 | default_rows = value; |
| 392 | else |
| 393 | default_columns = value; |
| 394 | |
| 395 | /* Delete argument from argv[]. (hope this is read/write!) */ |
| 396 | |
| 397 | *argc -= 2; |
| 398 | if (*argc > arg) |
| 399 | mch_memmove(&argv[arg], &argv[arg + 2], (*argc - arg) |
| 400 | * sizeof(char *)); |
| 401 | } |
| 402 | else |
| 403 | arg++; |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | /* Fatal error on initialisation - report it and die. */ |
| 408 | void |
| 409 | ro_die(error) |
| 410 | char_u *error; /* RISC OS error block */ |
| 411 | { |
| 412 | swi(Wimp_ReportError, error, 5, "GVim"); |
| 413 | exit(EXIT_FAILURE); |
| 414 | } |
| 415 | |
| 416 | /* Find the sizes of the window tools: |
| 417 | * |
| 418 | * Create a test window. |
| 419 | * Find inner and outer sizes. |
| 420 | * Find the difference. |
| 421 | * Delete window. |
| 422 | * |
| 423 | * While we're here, find the eigen values too. |
| 424 | */ |
| 425 | void |
| 426 | ro_measure_tools() |
| 427 | { |
| 428 | int block[10]; |
| 429 | int vdu[] = { 4, 5, -1}; |
| 430 | int test_window[] = |
| 431 | { |
| 432 | -100, -100, /* Visible area : min X,Y */ |
| 433 | -50, -50, /* max X,Y */ |
| 434 | 0, 0, /* Scroll offsets */ |
| 435 | -1, /* Window in front */ |
| 436 | 0xd0800150, /* Window flags */ |
| 437 | 0xff070207, /* Colours */ |
| 438 | 0x000c0103, /* More colours */ |
| 439 | 0, -0x4000, /* Workarea extent */ |
| 440 | 0x4000, 0, /* max X,Y */ |
| 441 | 0x00000000, /* No title */ |
| 442 | 0 << 12, /* No workarea button type */ |
| 443 | 1, /* Wimp sprite area */ |
| 444 | 0x00010001, /* Minimum width, height */ |
| 445 | 0, 0, 0, /* Title data (none) */ |
| 446 | 0 /* No icons */ |
| 447 | }; |
| 448 | int inner_max_x, inner_min_y; |
| 449 | |
| 450 | swi(Wimp_CreateWindow, 0, test_window); |
| 451 | |
| 452 | block[0] = r0; |
| 453 | /* Open the window (and read state). |
| 454 | * GetWindowOutline needs it too if the wimp isn't nested. |
| 455 | */ |
| 456 | swi(Wimp_OpenWindow, 0, block); |
| 457 | inner_max_x = block[3]; |
| 458 | inner_min_y = block[2]; |
| 459 | |
| 460 | swi(Wimp_GetWindowOutline, 0, block); |
| 461 | |
| 462 | gui.scrollbar_width = block[3] - inner_max_x; |
| 463 | gui.scrollbar_height = inner_min_y - block[2]; |
| 464 | |
| 465 | swi(Wimp_DeleteWindow, 0, block); |
| 466 | |
| 467 | /* Read the size of one pixel. */ |
| 468 | swi(OS_ReadVduVariables, vdu, vdu); |
| 469 | x_eigen_factor = vdu[0]; |
| 470 | y_eigen_factor = vdu[1]; |
| 471 | } |
| 472 | |
| 473 | /* Load a template from the current templates file. |
| 474 | * Create the window and return its handle. |
| 475 | */ |
| 476 | int |
| 477 | ro_load_template(str_name, title, title_size) |
| 478 | char_u *str_name; /* Identifier of window in file (max 12 chars) */ |
| 479 | char_u **title; /* If not NULL then return pointer to title here */ |
| 480 | int *title_size; /* If not NULL then return the title length here */ |
| 481 | { |
| 482 | int *window; |
| 483 | char *data; |
| 484 | int name[4]; |
| 485 | |
| 486 | strcpy( (char *) name, str_name); |
| 487 | |
| 488 | /* Find how big we must make the buffers */ |
| 489 | |
| 490 | if (xswi(Wimp_LoadTemplate, 0, 0, 0, 0, -1, name, 0) & v_flag) |
| 491 | ro_die( (char *) r0); |
| 492 | |
| 493 | window = malloc(r1); /* Don't print text messages from alloc() */ |
| 494 | data = malloc(r2); |
| 495 | if (window == NULL || data == NULL) |
| 496 | ro_die("\0\0\0\0Out of memory - Can't load templates"); |
| 497 | |
| 498 | /* Load the template into the buffers */ |
| 499 | |
| 500 | swi(Wimp_LoadTemplate, 0, |
| 501 | window, /* Temp block */ |
| 502 | data, /* Icon data */ |
| 503 | data + r2 + 1, /* End of icon data */ |
| 504 | -1, /* No fonts */ |
| 505 | name, 0); /* First match */ |
| 506 | if (r6 == 0) |
| 507 | ro_die("\0\0\0\0Can't find window in Templates file"); |
| 508 | |
| 509 | /* Create the window */ |
| 510 | |
| 511 | if (xswi(Wimp_CreateWindow, 0, window) & v_flag) |
| 512 | ro_die( (char *) r0); |
| 513 | |
| 514 | if (title) |
| 515 | *title = (char_u *) window[18]; |
| 516 | if (title_size) |
| 517 | *title_size = window[20]; |
| 518 | |
| 519 | free(window); /* Free temp block */ |
| 520 | return r0; /* Return the window handle */ |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Check if the GUI can be started. Called before gvimrc is sourced. |
| 525 | * Return OK or FAIL. |
| 526 | */ |
| 527 | int |
| 528 | gui_mch_init_check() |
| 529 | { |
| 530 | return OK; /* TODO: GUI can always be started? */ |
| 531 | } |
| 532 | |
| 533 | /* |
| 534 | * Initialise the RISC OS GUI. |
| 535 | * Create all the windows. |
| 536 | * Returns OK for success, FAIL when the GUI can't be started. |
| 537 | */ |
| 538 | int |
| 539 | gui_mch_init() |
| 540 | { |
| 541 | int messages[] = { |
| 542 | 1, 2, 3, 4, /* DataSave, DataSaveAck, DataLoad, DataLoadAck */ |
| 543 | 8, /* PreQuit */ |
| 544 | 0xf, /* ClaimEntity (for clipboard) */ |
| 545 | 0x10, /* DataRequest (for clipboard) */ |
| 546 | 0x400c1, /* Mode change */ |
| 547 | 0x400c3, /* TaskCloseDown */ |
| 548 | 0x400c9, /* MenusDeleted */ |
| 549 | 0x808c1, /* TW_Output */ |
| 550 | 0x808c2, /* TW_Ego */ |
| 551 | 0x808c3, /* TW_Morio */ |
| 552 | 0x808c4, /* TW_Morite */ |
| 553 | 0}; /* End-of-list. */ |
| 554 | |
| 555 | |
| 556 | /* There may have been some errors reported in the |
| 557 | * command window before we get here. Wait if so. |
| 558 | */ |
| 559 | swi(Wimp_ReadSysInfo, 3); |
| 560 | if (r0 == 0) |
| 561 | swi(Wimp_CommandWindow, 0); /* Window opened - close with prompt */ |
| 562 | |
| 563 | if (xswi(Wimp_Initialise, 310, 0x4b534154, "GVim", messages) & v_flag) |
| 564 | return FAIL; |
| 565 | nested_wimp = r0 >= 397; |
| 566 | task_handle = r1; |
| 567 | |
| 568 | /* Load the templates. */ |
| 569 | |
| 570 | if (xswi(Wimp_OpenTemplate, 0, "Vim:Templates") & v_flag) |
| 571 | ro_die( (char *) r0); |
| 572 | |
| 573 | gui.window_handle = ro_load_template("editor", |
| 574 | &gui.window_title, |
| 575 | &gui.window_title_size); |
| 576 | |
| 577 | save_window = ro_load_template("save", NULL, NULL); |
| 578 | |
| 579 | swi(Wimp_CloseTemplate); |
| 580 | |
| 581 | /* Set default foreground and background colours. */ |
| 582 | |
| 583 | gui.norm_pixel = gui.def_norm_pixel; |
| 584 | gui.back_pixel = gui.def_back_pixel; |
| 585 | |
| 586 | /* Get the colours from the "Normal" and "Menu" group (set in syntax.c or |
| 587 | * in a vimrc file) */ |
| 588 | |
| 589 | set_normal_colors(); |
| 590 | |
| 591 | /* |
| 592 | * Check that none of the colors are the same as the background color |
| 593 | */ |
| 594 | |
| 595 | gui_check_colors(); |
| 596 | |
| 597 | /* Get the colours for the highlight groups (gui_check_colors() might have |
| 598 | * changed them) */ |
| 599 | |
| 600 | highlight_gui_started(); /* re-init colours and fonts */ |
| 601 | |
| 602 | /* Set geometry based on values read on initialisation. */ |
| 603 | |
| 604 | gui.num_cols = Columns = default_columns; |
| 605 | gui.num_rows = Rows = default_rows; |
| 606 | |
| 607 | /* Get some information about our environment. */ |
| 608 | |
| 609 | ro_measure_tools(); |
| 610 | |
| 611 | return OK; |
| 612 | } |
| 613 | |
| 614 | /* |
| 615 | * Called when the foreground or background colour has been changed. |
| 616 | */ |
| 617 | void |
| 618 | gui_mch_new_colors() |
| 619 | { |
| 620 | } |
| 621 | |
| 622 | /* |
| 623 | * Open the GUI window which was created by a call to gui_mch_init(). |
| 624 | */ |
| 625 | int |
| 626 | gui_mch_open(void) |
| 627 | { |
| 628 | int block[10]; |
| 629 | |
| 630 | block[0] = gui.window_handle; |
| 631 | swi(Wimp_GetWindowState, 0, block); |
| 632 | block[7] = -1; /* Open at the top of the stack */ |
| 633 | swi(Wimp_OpenWindow, 0, block); |
| 634 | |
| 635 | /* Give the new window the input focus */ |
| 636 | swi(Wimp_SetCaretPosition, gui.window_handle, -1, 0, 0, -1, -1); |
| 637 | |
| 638 | if (gui_win_x != -1 && gui_win_y != -1) |
| 639 | gui_mch_set_winpos(gui_win_x, gui_win_y); |
| 640 | |
| 641 | return OK; |
| 642 | } |
| 643 | |
| 644 | void |
| 645 | gui_mch_exit(int rc) |
| 646 | { |
| 647 | int block[64]; |
| 648 | |
| 649 | /* Close window. Stops us from getting troublesome events |
| 650 | * if we take a while to die. |
| 651 | */ |
| 652 | block[0] = gui.window_handle; |
| 653 | swi(Wimp_CloseWindow, 0, block); |
| 654 | |
| 655 | if (child_handle) |
| 656 | { |
| 657 | /* We still have a sub-task running - kill it */ |
| 658 | block[0] = 20; |
| 659 | block[3] = 0; |
| 660 | block[4] = 0; /* Quit */ |
| 661 | if ((xswi(Wimp_SendMessage, 17, block, child_handle) & v_flag) == 0) |
| 662 | { |
| 663 | /* Idle until child dies. */ |
| 664 | while (child_handle) |
| 665 | { |
| 666 | process_event(wimp_poll(1, block), block); |
| 667 | } |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | exit(rc); |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | * Get the position of the top left corner of the window. |
| 676 | */ |
| 677 | int |
| 678 | gui_mch_get_winpos(int *x, int *y) |
| 679 | { |
| 680 | /* TODO */ |
| 681 | return FAIL; |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | * Set the position of the top left corner of the window to the given |
| 686 | * coordinates. |
| 687 | */ |
| 688 | void |
| 689 | gui_mch_set_winpos(int x, int y) |
| 690 | { |
| 691 | /* TODO */ |
| 692 | } |
| 693 | |
| 694 | void |
Bram Moolenaar | 2e2a281 | 2006-03-27 20:55:21 +0000 | [diff] [blame] | 695 | gui_mch_set_shellsize(width, height, min_width, min_height, base_width, base_height, direction) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 696 | int width; /* In OS units */ |
| 697 | int height; |
| 698 | int min_width; /* Smallest permissable window size (ignored) */ |
| 699 | int min_height; |
| 700 | int base_width; /* Space for scroll bars, etc */ |
| 701 | int base_height; |
Bram Moolenaar | 2e2a281 | 2006-03-27 20:55:21 +0000 | [diff] [blame] | 702 | int direction; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 703 | { |
| 704 | int s_width, s_height; |
| 705 | int block[] = { |
| 706 | gui.window_handle, |
| 707 | 0, |
| 708 | -height + 1, |
| 709 | width, |
| 710 | 1}; |
| 711 | |
| 712 | gui_mch_get_screen_dimensions(&s_width, &s_height); |
| 713 | s_width -= base_width; |
| 714 | s_height -= base_height; /* Underestimate - ignores titlebar */ |
| 715 | |
| 716 | swi(Wimp_GetWindowState, 0, block); |
| 717 | block[3] = block[1] + width; |
| 718 | block[2] = block[4] - height; |
| 719 | if (block[3] > s_width) |
| 720 | { |
| 721 | block[3] = s_width; |
| 722 | block[1] = block[3] - width; |
| 723 | } |
| 724 | if (block[2] < gui.scrollbar_height) |
| 725 | { |
| 726 | block[2] = gui.scrollbar_height; |
| 727 | block[4] = block[2] + height; |
| 728 | } |
| 729 | swi(Wimp_OpenWindow, 0, block); |
| 730 | swi(Wimp_ForceRedraw, gui.window_handle, 0, -height, width, 0); |
| 731 | } |
| 732 | |
| 733 | void |
| 734 | gui_mch_get_screen_dimensions(int *screen_w, int *screen_h) |
| 735 | { |
| 736 | int block[] = {4, 5, 11, 12, -1}; |
| 737 | |
| 738 | swi(OS_ReadVduVariables, block, block); |
| 739 | *screen_w = (block[2] + 1) << block[0]; |
| 740 | *screen_h = (block[3] + 1) << block[1]; |
| 741 | } |
| 742 | |
| 743 | /* Take a font name with options and return a font handle, or |
| 744 | * zero for failure. |
| 745 | * Replace extension with 'Bold' or 'Italic' depending on modifiers. |
| 746 | */ |
| 747 | int |
| 748 | ro_get_font(fullname, weight) |
| 749 | char_u *fullname; |
| 750 | int weight; /* Initial weights: |
| 751 | * BIT MEANING |
| 752 | * 0 bold |
| 753 | * 1 italic |
| 754 | */ |
| 755 | { |
| 756 | char_u *arg; |
| 757 | char_u font[41]; |
| 758 | int width = -1; |
| 759 | int height = -1; |
| 760 | int name_len; |
| 761 | int i; |
| 762 | char_u c; |
| 763 | |
| 764 | for (i = 0; i < 39;) |
| 765 | { |
| 766 | c = fullname[i]; |
| 767 | if (c == ':' || c == NUL || c == '.') |
| 768 | break; |
| 769 | font[i++] = c; |
| 770 | } |
| 771 | |
| 772 | /* find the first modifier, NULL if none */ |
| 773 | arg = strchr(fullname + i, ':'); |
| 774 | |
| 775 | while (arg) |
| 776 | { |
| 777 | switch (*++arg) |
| 778 | { |
| 779 | case 'h': |
| 780 | height = strtol(arg + 1, (char **) &arg, 10); |
| 781 | break; |
| 782 | case 'w': |
| 783 | width = strtol(arg + 1, (char **) &arg, 10); |
| 784 | break; |
| 785 | case 'b': |
| 786 | weight |= 1; |
| 787 | break; |
| 788 | case 'i': |
| 789 | weight |= 2; |
| 790 | break; |
| 791 | default: |
| 792 | return 0; |
| 793 | } |
| 794 | arg = strchr(arg, ':'); |
| 795 | } |
| 796 | |
| 797 | if ((weight & 1) && i < 35) |
| 798 | { |
| 799 | /* Bold goes instead of given suffix */ |
| 800 | strncpy(font + i, ".Bold", 5); |
| 801 | i += 5; |
| 802 | } |
| 803 | else |
| 804 | { |
| 805 | /* Copy rest of name unless we are using Bold */ |
| 806 | while (i < 39) |
| 807 | { |
| 808 | c = fullname[i]; |
| 809 | if (c == ':' || c == NUL) |
| 810 | break; |
| 811 | font[i++] = c; |
| 812 | } |
| 813 | } |
| 814 | if ((weight & 2) && i < 32) |
| 815 | { |
| 816 | strncpy(font + i, ".Oblique", 8); |
| 817 | i += 8; |
| 818 | } |
| 819 | |
| 820 | font[i] = 0; |
| 821 | |
| 822 | if (height < 1 && width < 1) |
| 823 | height = width = 10; /* Default to 10pt */ |
| 824 | else if (height < 1) |
| 825 | height = width; |
| 826 | else if (width < 1) |
| 827 | width = height; |
| 828 | |
| 829 | if (xswi(Font_FindFont, 0, font, width << 4, height << 4, 0, 0) & v_flag) |
| 830 | return NOFONT; /* Can't find font */ |
| 831 | |
| 832 | return r0; |
| 833 | } |
| 834 | |
| 835 | /* Load a file into allocated memory and check it is valid. |
| 836 | * Return a pointer to the allocated block on success. |
| 837 | */ |
| 838 | char * |
| 839 | zap_load_file(name, style) |
| 840 | char_u *name; /* Name of directory containing styles */ |
| 841 | char_u *style; /* Name of style within directory */ |
| 842 | { |
| 843 | char_u fname[256]; |
| 844 | char_u *file; |
| 845 | |
| 846 | if (strlen(name) + strlen(style) > 254) |
| 847 | return NULL; /* Names too long */ |
| 848 | |
| 849 | sprintf(fname, "%s.%s", name, style); |
| 850 | |
| 851 | /* Load the named font in 1bpp format. */ |
| 852 | if (xswi(OS_File, 13, fname, 0, 0, "VimFonts:") & v_flag || r0 != 1) |
| 853 | return NULL; /* Error reading file info, or not a file */ |
| 854 | |
| 855 | /* Allocate enough memory to load the whole file */ |
| 856 | file = (char *) alloc(r4); |
| 857 | if (!file) |
| 858 | return NULL; /* Out of memory */ |
| 859 | |
| 860 | if (xswi(OS_File, 12, fname, file, 0, "VimFonts:") & v_flag) |
| 861 | return NULL; /* Unable to load file */ |
| 862 | |
| 863 | if (strncmp(file, "ZapFont\015", 8) == 0) |
| 864 | return file; /* Loaded OK! */ |
| 865 | |
| 866 | free(file); |
| 867 | return NULL; /* Not a valid font file */ |
| 868 | } |
| 869 | |
| 870 | /* Load and convert the named font. |
| 871 | * If name is NULL or a null string then convert the system font. |
| 872 | * Return OK on success; FAIL and we revert to using the VDU drivers. |
| 873 | * |
| 874 | * 'name' is the name of a directory. |
| 875 | * Tries to load 'name.0', 'name.B', 'name.I' and 'name.IB'. |
| 876 | */ |
| 877 | int |
| 878 | zap_load_font(name) |
| 879 | char_u *name; |
| 880 | { |
| 881 | int i; |
| 882 | |
| 883 | /* Free the existing font files, if any */ |
| 884 | for (i = 0; i < ZAP_STYLES; i++) |
| 885 | { |
| 886 | vim_free(zap_file[i]); |
| 887 | zap_file[i] = NULL; |
| 888 | } |
| 889 | |
| 890 | if (name && *name == '!') |
| 891 | { |
| 892 | name++; |
| 893 | double_height = TRUE; |
| 894 | } |
| 895 | else |
| 896 | double_height = FALSE; |
| 897 | |
| 898 | if (name && *name) |
| 899 | { |
| 900 | zap_file[ZAP_NORMAL] = zap_load_file(name, "0"); |
| 901 | if (!zap_file[ZAP_NORMAL]) |
| 902 | return FAIL; /* Can't load the 'normal' style - error */ |
| 903 | |
| 904 | zap_file[ZAP_BOLD] = zap_load_file(name, "B"); |
| 905 | zap_file[ZAP_ITALIC] = zap_load_file(name, "I"); |
| 906 | zap_file[ZAP_BITALIC] = zap_load_file(name, "IB"); |
| 907 | } |
| 908 | else |
| 909 | { |
| 910 | int *header; |
| 911 | char workarea[16]; |
| 912 | char *old_wa; |
| 913 | |
| 914 | /* Allocate memory for system font (8 x 8 x 256 bits, plus header) */ |
| 915 | header = (int *) alloc(0x20 + 8 * 256); |
| 916 | if (header == NULL) |
| 917 | return FAIL; |
| 918 | zap_file[ZAP_NORMAL] = (char *) header; |
| 919 | |
| 920 | /* Store details about the system font */ |
| 921 | header[2] = 8; /* Width */ |
| 922 | header[3] = 8; /* Height */ |
| 923 | header[4] = 0; /* First char */ |
| 924 | header[5] = 255; /* Last char */ |
| 925 | header[6] = header[7] = 0; /* Reserved */ |
| 926 | |
| 927 | /* Get system font bitmap */ |
| 928 | old_wa = zap_redraw_block.r_workarea; |
| 929 | zap_redraw_block.r_workarea = workarea; |
| 930 | swi(ZapRedraw_ReadSystemChars, zap_file[ZAP_NORMAL] + 0x20, &zap_redraw_block); |
| 931 | zap_redraw_block.r_workarea = old_wa; |
| 932 | } |
| 933 | |
| 934 | return ro_zap_redraw_initialise(); |
| 935 | } |
| 936 | |
| 937 | /* |
| 938 | * Initialise vim to use the font with the given name. |
| 939 | * Return FAIL if the font could not be loaded, OK otherwise. |
| 940 | */ |
| 941 | int |
| 942 | gui_mch_init_font(char_u *font_name, int fontset) |
| 943 | { |
| 944 | int new_handle = 0; /* Use the system font by default */ |
| 945 | |
| 946 | if (font_name[0] == '!') |
| 947 | { |
| 948 | /* Select a ZapRedraw font */ |
| 949 | if (zap_load_font(font_name + 1)) |
| 950 | zap_redraw = TRUE; |
| 951 | else |
| 952 | { |
| 953 | EMSG2(_("E610: Can't load Zap font '%s'"), font_name); |
| 954 | font_name = "System"; /* Error - use system font */ |
| 955 | zap_redraw = FALSE; |
| 956 | } |
| 957 | } |
| 958 | else |
| 959 | { |
| 960 | zap_redraw = FALSE; |
| 961 | |
| 962 | if (font_name) |
| 963 | { |
| 964 | /* Extract any extra details about the font */ |
| 965 | new_handle = ro_get_font(font_name, 0); |
| 966 | if (!new_handle) |
| 967 | return FAIL; |
| 968 | } |
| 969 | else |
| 970 | font_name = "System"; |
| 971 | } |
| 972 | |
| 973 | /* Free the previous font, if any */ |
| 974 | gui_mch_free_font(gui.norm_font); |
| 975 | gui.norm_font = new_handle; |
| 976 | gui.char_ascent = 0; |
| 977 | |
| 978 | if (new_handle) |
| 979 | { |
| 980 | /* Read details about the chosen font */ |
| 981 | swi(Font_ReadInfo, new_handle); |
| 982 | |
| 983 | gui.char_width = r3 - r1; |
| 984 | gui.char_height = r4 - r2; |
| 985 | |
| 986 | font_x_offset = -r1; /* Where to position each char in its box */ |
| 987 | font_y_offset = -r4; |
| 988 | |
| 989 | /* Try to load other fonts for bold, italic, and bold-italic */ |
| 990 | gui_mch_free_font(gui.bold_font); |
| 991 | gui.bold_font = ro_get_font(font_name, 1); |
| 992 | gui_mch_free_font(gui.ital_font); |
| 993 | gui.ital_font = ro_get_font(font_name, 2); |
| 994 | gui_mch_free_font(gui.boldital_font); |
| 995 | gui.boldital_font = ro_get_font(font_name, 3); |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | /* Use the system font or ZapRedraw. */ |
| 1000 | if (zap_redraw) |
| 1001 | { |
| 1002 | gui.char_width = zap_redraw_block.r_charw << zap_redraw_block.r_magx; |
| 1003 | gui.char_height = zap_redraw_block.r_charh << zap_redraw_block.r_magy; |
| 1004 | if (double_height) |
| 1005 | gui.char_height <<= 1; |
| 1006 | } |
| 1007 | else |
| 1008 | { |
| 1009 | gui.char_width = 16; |
| 1010 | gui.char_height = 32; |
| 1011 | } |
| 1012 | |
| 1013 | gui_mch_free_font(gui.bold_font); |
| 1014 | gui.bold_font = 0; |
| 1015 | gui_mch_free_font(gui.ital_font); |
| 1016 | gui.ital_font = 0; |
| 1017 | gui_mch_free_font(gui.boldital_font); |
| 1018 | gui.boldital_font = 0; |
| 1019 | } |
| 1020 | hl_set_font_name(font_name); |
| 1021 | |
| 1022 | must_redraw = CLEAR; |
| 1023 | return OK; |
| 1024 | } |
| 1025 | |
Bram Moolenaar | 0274363 | 2005-07-25 20:42:36 +0000 | [diff] [blame] | 1026 | /* |
| 1027 | * Adjust gui.char_height (after 'linespace' was changed). |
| 1028 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1029 | int |
Bram Moolenaar | 0274363 | 2005-07-25 20:42:36 +0000 | [diff] [blame] | 1030 | gui_mch_adjust_charheight() |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1031 | { |
| 1032 | return FAIL; |
| 1033 | } |
| 1034 | |
| 1035 | /* |
| 1036 | * Get a font structure for highlighting. |
| 1037 | */ |
| 1038 | GuiFont |
| 1039 | gui_mch_get_font(name, giveErrorIfMissing) |
| 1040 | char_u *name; |
| 1041 | int giveErrorIfMissing; |
| 1042 | { |
| 1043 | int handle; |
| 1044 | |
| 1045 | if (!name) |
| 1046 | return NOFONT; /* System font if no name */ |
| 1047 | |
| 1048 | handle = ro_get_font(name, 0); |
| 1049 | if (!handle) |
| 1050 | { |
| 1051 | if (giveErrorIfMissing) |
| 1052 | EMSG2(_("E611: Can't use font %s"), name); |
| 1053 | return NOFONT; |
| 1054 | } |
| 1055 | |
| 1056 | return handle; |
| 1057 | } |
| 1058 | |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1059 | #if defined(FEAT_EVAL) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1060 | /* |
Bram Moolenaar | d8b0cf1 | 2004-12-12 11:33:30 +0000 | [diff] [blame] | 1061 | * Return the name of font "font" in allocated memory. |
| 1062 | * Don't know how to get the actual name, thus use the provided name. |
| 1063 | */ |
| 1064 | char_u * |
| 1065 | gui_mch_get_fontname(font, name) |
| 1066 | GuiFont font; |
| 1067 | char_u *name; |
| 1068 | { |
| 1069 | if (name == NULL) |
| 1070 | return NULL; |
| 1071 | return vim_strsave(name); |
| 1072 | } |
Bram Moolenaar | dfccaf0 | 2004-12-31 20:56:11 +0000 | [diff] [blame] | 1073 | #endif |
Bram Moolenaar | d8b0cf1 | 2004-12-12 11:33:30 +0000 | [diff] [blame] | 1074 | |
| 1075 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1076 | * Set the current text font. |
| 1077 | */ |
| 1078 | void |
| 1079 | gui_mch_set_font(GuiFont font) |
| 1080 | { |
| 1081 | ro_current_font = font; |
| 1082 | |
| 1083 | if (font) |
| 1084 | { |
| 1085 | /* Not the system font or ZapRedraw font - select it */ |
| 1086 | swi(Font_SetFont, font); |
| 1087 | } |
| 1088 | } |
| 1089 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1090 | /* |
| 1091 | * If a font is not going to be used, free its structure. |
| 1092 | */ |
| 1093 | void |
| 1094 | gui_mch_free_font(GuiFont font) |
| 1095 | { |
| 1096 | if (font) |
| 1097 | swi(Font_LoseFont, font); |
| 1098 | } |
| 1099 | |
| 1100 | /* |
| 1101 | * Return the Pixel value (colour) for the given colour name. |
| 1102 | * Return INVALCOLOR for error. |
| 1103 | * NB: I've changed Green for now, since it looked really sick |
| 1104 | */ |
| 1105 | guicolor_T |
| 1106 | gui_mch_get_color(char_u *name) |
| 1107 | { |
| 1108 | int i; |
| 1109 | struct colour |
| 1110 | { |
| 1111 | char_u *name; |
| 1112 | guicolor_T value; |
| 1113 | } colours[] = |
| 1114 | { |
| 1115 | { "Red", grgb(255, 0, 0) }, |
| 1116 | { "LightRed", grgb(255, 0, 0) }, |
| 1117 | { "DarkRed", grgb(139, 0, 0) }, |
| 1118 | |
| 1119 | { "Green", grgb(50, 200, 50) }, |
| 1120 | { "LightGreen", grgb(144, 238, 144) }, |
| 1121 | { "DarkGreen", grgb(0, 100, 0) }, |
| 1122 | { "SeaGreen", grgb(46, 139, 87) }, |
| 1123 | |
| 1124 | { "Blue", grgb(0, 0, 255) }, |
| 1125 | { "LightBlue", grgb(173, 216, 230) }, |
| 1126 | { "DarkBlue", grgb(0, 0, 139) }, |
| 1127 | { "SlateBlue", grgb(160, 90, 205) }, |
| 1128 | |
| 1129 | { "Cyan", grgb(0, 255, 255) }, |
| 1130 | { "LightCyan", grgb(224, 255, 255) }, |
| 1131 | { "DarkCyan", grgb(0, 139, 139) }, |
| 1132 | |
| 1133 | { "Magenta", grgb(255, 0, 255) }, |
| 1134 | { "LightMagenta", grgb(255, 224, 255) }, |
| 1135 | { "DarkMagenta", grgb(139, 0, 139) }, |
| 1136 | |
| 1137 | { "Yellow", grgb(255, 255, 0) }, |
| 1138 | { "LightYellow", grgb(255, 255, 224) }, |
| 1139 | { "DarkYellow", grgb(139, 139, 0) }, |
| 1140 | { "Brown", grgb(165, 42, 42) }, |
| 1141 | |
| 1142 | { "Gray", grgb(190, 190, 190) }, |
| 1143 | { "Grey", grgb(190, 190, 190) }, |
| 1144 | { "LightGray", grgb(211, 211, 211) }, |
| 1145 | { "LightGrey", grgb(211, 211, 211) }, |
| 1146 | { "DarkGray", grgb(169, 169, 169) }, |
| 1147 | { "DarkGrey", grgb(169, 169, 169) }, |
Bram Moolenaar | e2f98b9 | 2006-03-29 21:18:24 +0000 | [diff] [blame^] | 1148 | { "Grey90", grgb(229, 229, 229) }, |
| 1149 | { "Gray90", grgb(229, 229, 229) }, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1150 | |
| 1151 | { "Black", grgb(0, 0, 0) }, |
| 1152 | { "White", grgb(255, 255, 255) }, |
| 1153 | |
| 1154 | { "Orange", grgb(255, 165, 0) }, |
| 1155 | { "Purple", grgb(160, 32, 240) }, |
| 1156 | { "Violet", grgb(238, 130, 238) }, |
| 1157 | {NULL, 0} |
| 1158 | }; |
| 1159 | |
| 1160 | if (name[0] == '#') |
| 1161 | { |
| 1162 | char *end; |
| 1163 | int c; |
| 1164 | |
| 1165 | c = strtol(name + 1, &end, 16); |
| 1166 | return (guicolor_T) ((c >> 16) & 0xff) | (c & 0xff00) | ((c & 0xff) << 16); |
| 1167 | } |
| 1168 | |
| 1169 | for (i = 0; colours[i].name != NULL; i++) |
| 1170 | { |
| 1171 | if (STRICMP(name, colours[i].name) == 0) |
| 1172 | return colours[i].value; |
| 1173 | } |
| 1174 | if (strnicmp(name, "grey", 4) == 0 || strnicmp(name, "gray", 4) == 0) |
| 1175 | { |
| 1176 | int level = (255 * atoi(name + 4)) / 100; |
| 1177 | return (guicolor_T) grgb(level, level, level); |
| 1178 | } |
| 1179 | return INVALCOLOR; |
| 1180 | } |
| 1181 | |
| 1182 | /* |
| 1183 | * Set the current text colours. |
| 1184 | * If we are using fonts then set the antialiasing colours too. |
| 1185 | */ |
| 1186 | void |
| 1187 | gui_mch_set_colors(guicolor_T fg, guicolor_T bg) |
| 1188 | { |
| 1189 | zap_redraw_colours[0] = bg << 8; /* JK230798, register new background colour */ |
| 1190 | zap_redraw_colours[1] = fg << 8; /* JK230798, register new foreground colour */ |
| 1191 | zap_redraw_update_colours = TRUE; /* JK230798, need update of colour masks */ |
| 1192 | |
| 1193 | swi(ColourTrans_ReturnGCOL, fg << 8); |
| 1194 | gui.fg_colour = r0; |
| 1195 | swi(ColourTrans_ReturnGCOL, bg << 8); |
| 1196 | gui.bg_colour = r0; |
| 1197 | |
| 1198 | if (ro_current_font) |
| 1199 | swi(ColourTrans_SetFontColours, 0, bg << 8, fg << 8, 14); |
| 1200 | } |
| 1201 | |
| 1202 | void |
| 1203 | ro_draw_string(x, y, s, len, flags, clip) |
| 1204 | int x; /* Top-left coord to plot at (x incl, y excl) */ |
| 1205 | int y; /* (screen coords) */ |
| 1206 | char_u *s; /* String to plot */ |
| 1207 | int len; /* Length of string */ |
| 1208 | int flags; /* DRAW_TRANSP, DRAW_BOLD, DRAW_UNDERL */ |
| 1209 | int* clip; /* JK230798, added clip window */ |
| 1210 | { |
| 1211 | if (ro_current_font) |
| 1212 | { |
| 1213 | int fx; |
| 1214 | int flen = len; /* Preserve for underline */ |
| 1215 | |
| 1216 | /* Use the Font manager to paint the string. |
| 1217 | * Must do one char at a time to get monospacing. |
| 1218 | */ |
| 1219 | |
| 1220 | if (flags & DRAW_ITALIC && !gui.ital_font) |
| 1221 | flags |= DRAW_UNDERL; /* No italic - underline instead */ |
| 1222 | |
| 1223 | if ((flags & DRAW_TRANSP) == 0) |
| 1224 | { |
| 1225 | swi(ColourTrans_SetColour, gui.bg_colour, 0, 0, 0, 0); |
| 1226 | swi(OS_Plot, 4, x, y - gui.char_height); |
| 1227 | swi(OS_Plot, 96 + 5, x + len * gui.char_width - 1, y - 1); |
| 1228 | } |
| 1229 | |
| 1230 | fx = x + font_x_offset; |
| 1231 | while (flen--) |
| 1232 | { |
| 1233 | swi(Font_Paint, 0, s++, 0x90, fx, y + font_y_offset, 0, 0, 1); |
| 1234 | fx += gui.char_width; |
| 1235 | } |
| 1236 | } |
| 1237 | else |
| 1238 | { |
| 1239 | if (zap_redraw) |
| 1240 | { |
| 1241 | /* Using fast Zap redraw. */ |
| 1242 | flags = ro_zap_redraw_draw_string(x, y, s, len, flags, clip); |
| 1243 | } |
| 1244 | else |
| 1245 | { |
| 1246 | /* Using the system font */ |
| 1247 | if (flags & DRAW_ITALIC) |
| 1248 | flags |= DRAW_UNDERL; |
| 1249 | |
| 1250 | if ((flags & DRAW_TRANSP) == 0) |
| 1251 | { |
| 1252 | swi(ColourTrans_SetColour, gui.bg_colour, 0, 0, 0, 0); |
| 1253 | swi(OS_Plot, 4, x, y - gui.char_height); |
| 1254 | swi(OS_Plot, 96 + 5, x + len * gui.char_width - 1, y - 1); |
| 1255 | } |
| 1256 | swi(OS_Plot, 4, /* Move the drawing cursor */ |
| 1257 | x, |
| 1258 | y - 1); |
| 1259 | swi(ColourTrans_SetColour, gui.fg_colour, 0, 0, 0, 0); |
| 1260 | swi(OS_WriteN, s, len); |
| 1261 | |
| 1262 | if (flags & DRAW_BOLD) |
| 1263 | { |
| 1264 | swi(OS_Plot, 4, x + (1 << x_eigen_factor), y - 1); |
| 1265 | swi(OS_WriteN, s, len); |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | if (flags & DRAW_UNDERL) |
| 1271 | { |
| 1272 | if (ro_current_font || zap_redraw) |
| 1273 | swi(ColourTrans_SetColour, gui.fg_colour, 0, 0, 0, 0); |
| 1274 | /* Underlined is the same with all plotting methods */ |
| 1275 | swi(OS_Plot, 4, x, y - gui.char_height); |
| 1276 | swi(OS_Plot, 1, gui.char_width * len, 0); |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | void |
| 1281 | gui_mch_draw_string(int row, int col, char_u *s, int len, int flags) |
| 1282 | { |
| 1283 | int x, y; /* Workarea x,y */ |
| 1284 | x = col * gui.char_width; |
| 1285 | y = -row * gui.char_height; |
| 1286 | |
| 1287 | if (redraw_block) |
| 1288 | { |
| 1289 | ro_draw_string(x + redraw_block[1], y + redraw_block[4], |
| 1290 | s, len, flags, &redraw_block[7]); /* JK230798, added clip window */ |
| 1291 | } |
| 1292 | else |
| 1293 | { |
| 1294 | int block[44]; |
| 1295 | block[0] = gui.window_handle; |
| 1296 | block[1] = x; |
| 1297 | block[2] = y - gui.char_height; |
| 1298 | block[3] = (col + len) * gui.char_width; |
| 1299 | block[4] = y; |
| 1300 | swi(Wimp_UpdateWindow, 0, block); |
| 1301 | while (r0) |
| 1302 | { |
| 1303 | ro_draw_string(x + block[1], y + block[4], |
| 1304 | s, len, flags, &block[7]); /* JK230798, added clip window */ |
| 1305 | swi(Wimp_GetRectangle, 0, block); |
| 1306 | } |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | * Return OK if the key with the termcap name "name" is supported. |
| 1312 | */ |
| 1313 | int |
| 1314 | gui_mch_haskey(char_u *name) |
| 1315 | { |
| 1316 | return FAIL; |
| 1317 | } |
| 1318 | |
| 1319 | void |
| 1320 | gui_mch_beep(void) |
| 1321 | { |
| 1322 | swi(OS_WriteI + 7); |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * Visual bell. |
| 1327 | */ |
| 1328 | void |
| 1329 | gui_mch_flash(int msec) |
| 1330 | { |
| 1331 | /* TODO */ |
| 1332 | } |
| 1333 | |
| 1334 | |
| 1335 | /* |
| 1336 | * Plot a solid rectangle using the given plot action and colour. |
| 1337 | * Coordinates are inclusive and window-relative. |
| 1338 | */ |
| 1339 | void |
| 1340 | plot_rectangle(plot, colour, minx, miny, maxx, maxy) |
| 1341 | int plot; /* OS_Plot action */ |
| 1342 | int colour; |
| 1343 | int minx; |
| 1344 | int miny; |
| 1345 | int maxx; |
| 1346 | int maxy; |
| 1347 | { |
| 1348 | if (redraw_block) |
| 1349 | { |
| 1350 | swi(ColourTrans_SetColour, colour, 0, 0, 0, 0); |
| 1351 | swi(OS_Plot, 4, minx + redraw_block[1], miny + redraw_block[4]); |
| 1352 | swi(OS_Plot, plot, maxx + redraw_block[1], maxy + redraw_block[4]); |
| 1353 | } |
| 1354 | else |
| 1355 | { |
| 1356 | int block[44]; |
| 1357 | block[0] = gui.window_handle; |
| 1358 | block[1] = minx; |
| 1359 | block[2] = miny; |
| 1360 | block[3] = maxx + 1; |
| 1361 | block[4] = maxy + 1; |
| 1362 | swi(Wimp_UpdateWindow, 0, block); |
| 1363 | while (r0) |
| 1364 | { |
| 1365 | swi(ColourTrans_SetColour, colour, 0, 0, 0, 0); |
| 1366 | swi(OS_Plot, 4, minx + block[1], miny + block[4]); |
| 1367 | swi(OS_Plot, plot, maxx + block[1], maxy + block[4]); |
| 1368 | swi(Wimp_GetRectangle, 0, block); |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | /* |
| 1374 | * Invert a rectangle from row r, column c, for nr rows and nc columns. |
| 1375 | */ |
| 1376 | void |
| 1377 | gui_mch_invert_rectangle(int r, int c, int nr, int nc) |
| 1378 | { |
| 1379 | plot_rectangle(96 + 6, 0, FILL_X(c), -FILL_Y(r + nr), FILL_X(c + nc), -FILL_Y(r)); |
| 1380 | } |
| 1381 | |
| 1382 | /* |
| 1383 | * Iconify the GUI window. |
| 1384 | */ |
| 1385 | void |
| 1386 | gui_mch_iconify(void) |
| 1387 | { |
| 1388 | } |
| 1389 | |
| 1390 | #if defined(FEAT_EVAL) || defined(PROTO) |
| 1391 | /* |
| 1392 | * Bring the Vim window to the foreground. |
| 1393 | */ |
| 1394 | void |
| 1395 | gui_mch_set_foreground() |
| 1396 | { |
| 1397 | /* TODO */ |
| 1398 | } |
| 1399 | #endif |
| 1400 | |
| 1401 | /* Draw a hollow rectangle relative to the current |
| 1402 | * graphics cursor position, with the given width |
| 1403 | * and height. Start position is top-left. |
| 1404 | */ |
| 1405 | void |
| 1406 | draw_hollow(w, h) |
| 1407 | int w; |
| 1408 | int h; |
| 1409 | { |
| 1410 | swi(OS_Plot, 1, w - 1, 0); |
| 1411 | swi(OS_Plot, 1, 0, 1 - h); |
| 1412 | swi(OS_Plot, 1, 1 - w, 0); |
| 1413 | swi(OS_Plot, 1, 0, h - 1); |
| 1414 | } |
| 1415 | |
| 1416 | /* |
| 1417 | * Draw a cursor without focus. |
| 1418 | */ |
| 1419 | void |
| 1420 | gui_mch_draw_hollow_cursor(guicolor_T colour) |
| 1421 | { |
| 1422 | int x = FILL_X(gui.cursor_col); /* Window relative, top-left */ |
| 1423 | int y = -FILL_Y(gui.cursor_row); |
| 1424 | if (redraw_block == NULL) |
| 1425 | { |
| 1426 | int block[11]; |
| 1427 | |
| 1428 | block[0] = gui.window_handle; |
| 1429 | block[1] = x; |
| 1430 | block[2] = y - gui.char_height; |
| 1431 | block[3] = x + gui.char_width; |
| 1432 | block[4] = y; |
| 1433 | swi(Wimp_UpdateWindow, 0, block); |
| 1434 | while (r0) |
| 1435 | { |
| 1436 | swi(ColourTrans_SetGCOL, colour << 8, 0, 0, 0, 0); |
| 1437 | |
| 1438 | swi(OS_Plot, 4, x + block[1], y + block[4] - 1); |
| 1439 | draw_hollow(gui.char_width, gui.char_height); |
| 1440 | |
| 1441 | swi(Wimp_GetRectangle, 0, block); |
| 1442 | } |
| 1443 | } |
| 1444 | else |
| 1445 | { |
| 1446 | swi(ColourTrans_SetGCOL, colour << 8, 0, 0, 0, 0); |
| 1447 | |
| 1448 | swi(OS_Plot, 4, x + redraw_block[1], y + redraw_block[4] - 1); |
| 1449 | draw_hollow(gui.char_width, gui.char_height); |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | /* |
| 1454 | * Draw part of a cursor, "w" pixels wide, and "h" pixels high, using |
| 1455 | * color "color". |
| 1456 | */ |
| 1457 | void |
| 1458 | gui_mch_draw_part_cursor(w, h, colour) |
| 1459 | int w; |
| 1460 | int h; |
| 1461 | guicolor_T colour; |
| 1462 | { |
| 1463 | int x = FILL_X(gui.cursor_col); |
| 1464 | int y = -FILL_Y(gui.cursor_row); |
| 1465 | swi(ColourTrans_ReturnGCOL, colour << 8); |
| 1466 | plot_rectangle(96 + 5, r0, x, y - h, x + w - 1, y - 1); |
| 1467 | } |
| 1468 | |
| 1469 | /* |
| 1470 | * Catch up with any queued events. This may put keyboard input into the |
| 1471 | * input buffer, call resize call-backs, trigger timers etc. |
| 1472 | * If there is nothing in the event queue(& no timers pending), then we return |
| 1473 | * immediately (well, after a Wimp_Poll). |
| 1474 | */ |
| 1475 | void |
| 1476 | gui_mch_update(void) |
| 1477 | { |
| 1478 | int block[64]; |
| 1479 | int reason; |
| 1480 | |
| 1481 | swi(OS_ReadMonotonicTime); |
| 1482 | if ((r0 - time_of_last_poll) < 50) |
| 1483 | return; /* Don't return too often */ |
| 1484 | |
| 1485 | reason = wimp_poll(0, block); |
| 1486 | if (reason) |
| 1487 | process_event(reason, block); |
| 1488 | ro_return_early = FALSE; /* We're returning anyway. */ |
| 1489 | } |
| 1490 | |
| 1491 | void |
| 1492 | redraw_window(block) |
| 1493 | int *block; |
| 1494 | { |
| 1495 | int x, y; /* Vim workarea coords */ |
| 1496 | int width, height; |
| 1497 | int blank_col; |
| 1498 | |
| 1499 | swi(ColourTrans_ReturnGCOL, UNUSED_COLOUR << 8, 0, 0, 1<<7, 0); |
| 1500 | blank_col = r0; |
| 1501 | |
| 1502 | swi(Wimp_RedrawWindow, 0, block); |
| 1503 | redraw_block = block; |
| 1504 | while (r0) |
| 1505 | { |
| 1506 | x = block[7] - block[1]; |
| 1507 | y = block[4] - block[10]; |
| 1508 | width = block[9] - block[7]; |
| 1509 | height = block[10] - block[8]; |
| 1510 | |
| 1511 | if (height + y > Rows * gui.char_height) |
| 1512 | { |
| 1513 | /* Blank everything off the bottom. */ |
| 1514 | plot_rectangle(96 + 5, blank_col, |
| 1515 | 0, block[8] - block[4], |
| 1516 | block[9] - block[1], -FILL_Y(Rows) - 1); |
| 1517 | height = Rows * gui.char_height; |
| 1518 | } |
| 1519 | if (width + x> Columns * gui.char_width) |
| 1520 | { |
| 1521 | /* Blank everything off to the right. */ |
| 1522 | plot_rectangle(96 + 5, blank_col, |
| 1523 | FILL_X(Columns), block[8] - block[4], |
| 1524 | block[9] - block[1], 0); |
| 1525 | width = Columns * gui.char_width; |
| 1526 | } |
| 1527 | gui_redraw(x , y, width, height); |
| 1528 | swi(Wimp_GetRectangle, 0, block); |
| 1529 | } |
| 1530 | redraw_block = NULL; |
| 1531 | } |
| 1532 | |
| 1533 | /* Check if we have modified data. |
| 1534 | * If we do then ack the message to stop the shutdown. |
| 1535 | * Otherwise, ignore the message. |
| 1536 | */ |
| 1537 | void |
| 1538 | ro_prequit(block) |
| 1539 | int *block; |
| 1540 | { |
| 1541 | if (!ro_ok_to_quit()) |
| 1542 | { |
| 1543 | /* Not OK to quit - stop shutdown */ |
| 1544 | block[3] = block[2]; |
| 1545 | swi(Wimp_SendMessage, 19, block, block[1]); |
| 1546 | } |
| 1547 | /* Do nothing. We may get a Message_Quit later. */ |
| 1548 | } |
| 1549 | |
| 1550 | /* If there is unsaved data then ask the user if they mind losing it. |
| 1551 | * Return TRUE if we can quit without saving, FALSE to halt the |
| 1552 | * shutdown. |
| 1553 | */ |
| 1554 | int |
| 1555 | ro_ok_to_quit() |
| 1556 | { |
| 1557 | int old_confirm = cmdmod.confirm; |
| 1558 | |
| 1559 | cmdmod.confirm = FALSE; /* Use our own, single tasking, box */ |
| 1560 | |
| 1561 | if (check_changed_any(FALSE)) |
| 1562 | { |
| 1563 | swi(Wimp_ReportError, |
| 1564 | "\0\0\0\0Vim contains unsaved data - quit anyway?", |
| 1565 | 0x17, |
| 1566 | "Vim"); |
| 1567 | cmdmod.confirm = old_confirm; |
| 1568 | if (r1 != 1) |
| 1569 | return FALSE; |
| 1570 | } |
| 1571 | cmdmod.confirm = old_confirm; |
| 1572 | return TRUE; |
| 1573 | } |
| 1574 | |
| 1575 | /* Quit without checking for unsaved data. */ |
| 1576 | void |
| 1577 | ro_quit() |
| 1578 | { |
| 1579 | exiting = TRUE; |
| 1580 | getout(0); |
| 1581 | |
| 1582 | exiting = FALSE; /* probably can't get here */ |
| 1583 | setcursor(); /* position cursor */ |
| 1584 | out_flush(); |
| 1585 | } |
| 1586 | |
| 1587 | /* Insent the given vim special code into the input buffer */ |
| 1588 | void |
| 1589 | ro_press(a, b, modifier) |
| 1590 | char a; |
| 1591 | char b; |
| 1592 | int modifier; /* %<Ctrl><Shift> 0000 0000 */ |
| 1593 | { |
| 1594 | char_u buf[6]; |
| 1595 | int vim_mod; |
| 1596 | int key; |
| 1597 | |
| 1598 | |
| 1599 | /* Convert RISC OS modifier to Vim modifier. */ |
| 1600 | vim_mod = ((modifier & 0x10) ? MOD_MASK_SHIFT : 0) |
| 1601 | | ((modifier & 0x20) ? MOD_MASK_CTRL : 0); |
| 1602 | key = simplify_key(TERMCAP2KEY(a, b), &vim_mod); |
| 1603 | |
| 1604 | buf[3] = CSI; |
| 1605 | buf[4] = KEY2TERMCAP0(key); |
| 1606 | buf[5] = KEY2TERMCAP1(key); |
| 1607 | if (vim_mod) |
| 1608 | { |
| 1609 | buf[0] = CSI; |
| 1610 | buf[1] = KS_MODIFIER; |
| 1611 | buf[2] = vim_mod; |
| 1612 | add_to_input_buf(buf, 6); |
| 1613 | } |
| 1614 | else |
| 1615 | add_to_input_buf(buf + 3, 3); |
| 1616 | } |
| 1617 | |
| 1618 | /* Take a wimp key code and insert the vim equivalent |
| 1619 | * into vim's input buffer. |
| 1620 | * CTRL-C also sets got_int. |
| 1621 | */ |
| 1622 | void |
| 1623 | ro_insert_key(code) |
| 1624 | char_u *code; /* Wimp_ProcessKey code (4 bytes) */ |
| 1625 | { |
| 1626 | char a = code[0]; |
| 1627 | char b = code[1]; |
| 1628 | int base, modifier; |
| 1629 | |
| 1630 | if (a == 3 && ctrl_c_interrupts) |
| 1631 | got_int = TRUE; |
| 1632 | |
| 1633 | /* Is it a normal key? */ |
| 1634 | if (a > 31 && a < 127) |
| 1635 | { |
| 1636 | add_to_input_buf(code, 1); |
| 1637 | return; |
| 1638 | } |
| 1639 | |
| 1640 | /* We should pass any unrecognised keys on, but |
| 1641 | * for now just pass on F12 combinations. |
| 1642 | */ |
| 1643 | switch (b) |
| 1644 | { |
| 1645 | case 0: |
| 1646 | /* Home and Delete are the only special cases */ |
| 1647 | switch (a) |
| 1648 | { |
| 1649 | case 0x1e: |
| 1650 | ro_press('k','h', 0); /* Home */ |
| 1651 | return; |
| 1652 | case 0x7f: |
| 1653 | ro_press('k','D', 0); /* Delete */ |
| 1654 | return; |
| 1655 | case CSI: |
| 1656 | { |
| 1657 | /* Turn CSI into K_CSI. Untested! */ |
| 1658 | char_u string[3] = {CSI, KS_EXTRA, KE_CSI}; |
| 1659 | |
| 1660 | add_to_input_buf(string, 3); |
| 1661 | return; |
| 1662 | } |
| 1663 | default: |
| 1664 | add_to_input_buf(code, 1); |
| 1665 | return; |
| 1666 | } |
| 1667 | case 1: |
| 1668 | if ((a & 0xcf) == 0xcc) |
| 1669 | { |
| 1670 | /* F12 pressed - pass it on (quick hack) */ |
| 1671 | swi(Wimp_ProcessKey, a | 0x100); |
| 1672 | return; |
| 1673 | } |
| 1674 | base = a & 0xcf; |
| 1675 | modifier = a & 0x30; |
| 1676 | switch (base) |
| 1677 | { |
| 1678 | case 0x8a: /* Tab */ |
| 1679 | add_to_input_buf("\011", 1); |
| 1680 | return; |
| 1681 | case 0x8b: /* Copy (End) */ |
| 1682 | return ro_press('@', '7', modifier); |
| 1683 | case 0x8c: /* Left */ |
| 1684 | return ro_press('k', 'l', modifier); |
| 1685 | case 0x8d: /* Right */ |
| 1686 | return ro_press('k', 'r', modifier); |
| 1687 | case 0x8e: /* Down */ |
| 1688 | if (modifier & 0x10) |
| 1689 | return ro_press('k', 'N', modifier ^ 0x10); |
| 1690 | else |
| 1691 | return ro_press('k', 'd', modifier); |
| 1692 | case 0x8f: /* Up */ |
| 1693 | if (modifier & 0x10) |
| 1694 | return ro_press('k', 'P', modifier ^ 0x10); |
| 1695 | else |
| 1696 | return ro_press('k', 'u', modifier); |
| 1697 | case 0xca: /* F10 */ |
| 1698 | return ro_press('k', ';', modifier); |
| 1699 | case 0xcb: /* F11 */ |
| 1700 | return ro_press('F', '1', modifier); |
| 1701 | case 0xcd: /* Insert */ |
| 1702 | return ro_press('k', 'I', modifier); |
| 1703 | default: |
| 1704 | if (base > 0x80 && base < 0x18a) |
| 1705 | { |
| 1706 | /* One of the other function keys */ |
| 1707 | return ro_press('k', '0' + (base & 15), modifier); |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | } |
| 1712 | |
| 1713 | /* Process a mouse event. */ |
| 1714 | void |
| 1715 | ro_mouse(block) |
| 1716 | int *block; |
| 1717 | { |
| 1718 | int x, y, button, vim_button; |
| 1719 | int modifiers = 0; |
| 1720 | int min_x, min_y; /* Visible area of editor window */ |
| 1721 | int max_x, max_y; |
| 1722 | |
| 1723 | if (block[3] != gui.window_handle || ro_dragging) |
| 1724 | return; /* Not our window or ignoring clicks*/ |
| 1725 | |
| 1726 | x = block[0]; /* Click position - screen coords */ |
| 1727 | y = block[1]; |
| 1728 | button = block[2]; |
| 1729 | |
| 1730 | block[0] = gui.window_handle; |
| 1731 | swi(Wimp_GetWindowState, 0, block); |
| 1732 | min_x = block[1]; |
| 1733 | min_y = block[2]; |
| 1734 | max_x = block[3]; |
| 1735 | max_y = block[4]; |
| 1736 | |
| 1737 | if (block[3] - x < gui.scrollbar_width) |
| 1738 | { |
| 1739 | /* Click in that blank area under the scrollbars */ |
| 1740 | |
| 1741 | if (button & 0x444) |
| 1742 | { |
| 1743 | int front_block[10]; |
| 1744 | /* Dragging with Select - bring window to front first */ |
| 1745 | front_block[0] = gui.window_handle; |
| 1746 | swi(Wimp_GetWindowState, 0, front_block); |
| 1747 | front_block[7] = -1; |
| 1748 | ro_open_main(front_block); |
| 1749 | } |
| 1750 | |
| 1751 | block[0] = gui.window_handle; |
| 1752 | block[1] = 7; /* Drag point */ |
| 1753 | block[2] = block[4] = 0; /* Coords of point. */ |
| 1754 | block[3] = block[5] = 0; |
| 1755 | drag_x_offset = max_x - x; |
| 1756 | drag_y_offset = min_y - y; |
| 1757 | |
| 1758 | /* Parent box. */ |
| 1759 | block[6] = min_x + |
| 1760 | gui.scrollbar_width * 2 + |
| 1761 | MIN_COLUMNS * gui.char_width; |
| 1762 | block[7] = 0; |
| 1763 | gui_mch_get_screen_dimensions(&block[8], &block[9]); |
| 1764 | block[9] = max_y - |
| 1765 | 4 * gui.char_height - |
| 1766 | gui.scrollbar_height; |
| 1767 | |
| 1768 | swi(Wimp_DragBox, 0, block); |
| 1769 | ro_dragging = DRAG_RESIZE_WINDOW; |
| 1770 | drag_button = vim_button; |
| 1771 | drag_modifiers = modifiers; |
| 1772 | return; |
| 1773 | } |
| 1774 | |
| 1775 | if (button & 0x111) |
| 1776 | vim_button = MOUSE_RIGHT; |
| 1777 | else if (button & 0x222) |
| 1778 | vim_button = MOUSE_MIDDLE; |
| 1779 | else |
| 1780 | vim_button = MOUSE_LEFT; |
| 1781 | |
| 1782 | swi(OS_Byte, 121, 0x80); |
| 1783 | if (r1 == 0xff) |
| 1784 | modifiers |= MOUSE_SHIFT; |
| 1785 | swi(OS_Byte, 121, 0x81); |
| 1786 | if (r1 == 0xff) |
| 1787 | modifiers |= MOUSE_CTRL; |
| 1788 | swi(OS_Byte, 121, 0x82); |
| 1789 | if (r1 == 0xff) |
| 1790 | modifiers |= MOUSE_ALT; |
| 1791 | |
| 1792 | if (button == 2) |
| 1793 | { |
| 1794 | /* Menu click: |
| 1795 | * If shift was pressed then do the paste action. |
| 1796 | * If not, then open the pop-up menu. |
| 1797 | */ |
| 1798 | modifiers ^= MOUSE_SHIFT; |
| 1799 | if (modifiers && MOUSE_SHIFT) |
| 1800 | { |
| 1801 | vimmenu_T main; |
| 1802 | /* Shift was NOT pressed - show menu */ |
| 1803 | main.dname = (char_u *) "Vim"; |
| 1804 | main.children = root_menu; |
| 1805 | gui_mch_show_popupmenu(&main); |
| 1806 | return; |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | /* Gain the input focus */ |
| 1811 | swi(Wimp_SetCaretPosition, gui.window_handle, -1, 0, 0, -1, -1); |
| 1812 | |
| 1813 | if (button & 0xf0) |
| 1814 | { |
| 1815 | /* Drag operation: |
| 1816 | * |
| 1817 | * Tell the Wimp to start a drag. |
| 1818 | * Monitor null events. |
| 1819 | */ |
| 1820 | block[1] = 7; /* Drag a point. */ |
| 1821 | block[2] = block[4] = x; /* Coords of point. */ |
| 1822 | block[3] = block[5] = y; |
| 1823 | block[6] = 0; /* Coords of bounding box. */ |
| 1824 | block[7] = 0; |
| 1825 | gui_mch_get_screen_dimensions(&block[8], &block[9]); |
| 1826 | |
| 1827 | drag_x_offset = drag_y_offset = 0; |
| 1828 | |
| 1829 | swi(Wimp_DragBox, 0, block); |
| 1830 | ro_dragging = DRAG_SELECTION; |
| 1831 | drag_button = vim_button; |
| 1832 | drag_modifiers = modifiers; |
| 1833 | |
| 1834 | vim_button |= MOUSE_DRAG; |
| 1835 | } |
| 1836 | |
| 1837 | gui_send_mouse_event( |
| 1838 | vim_button, |
| 1839 | x - min_x, |
| 1840 | max_y - y, |
| 1841 | button & 0xf ? TRUE : FALSE, /* dclick */ |
| 1842 | modifiers); |
| 1843 | } |
| 1844 | |
| 1845 | void |
| 1846 | ro_continue_drag(block) |
| 1847 | int *block; /* Just used as scrap. */ |
| 1848 | { |
| 1849 | int x, y; |
| 1850 | |
| 1851 | /* Get screen coords of pointer. */ |
| 1852 | swi(Wimp_GetPointerInfo, 0, block); |
| 1853 | x = block[0] + drag_x_offset; |
| 1854 | y = block[1] + drag_y_offset; |
| 1855 | |
| 1856 | block[0] = gui.window_handle; |
| 1857 | swi(Wimp_GetWindowState, 0, block); |
| 1858 | |
| 1859 | if (ro_dragging == DRAG_RESIZE_WINDOW) |
| 1860 | { |
| 1861 | /* Resizeing the main window. */ |
| 1862 | block[2] = y; |
| 1863 | block[3] = x; |
| 1864 | ro_open_main(block); |
| 1865 | } |
| 1866 | else |
| 1867 | { |
| 1868 | /* Selecting some text. */ |
| 1869 | gui_send_mouse_event( |
| 1870 | drag_button | MOUSE_DRAG, /* Always report the same button */ |
| 1871 | x - block[1], |
| 1872 | block[4] - y, |
| 1873 | FALSE, /* Not a double click. */ |
| 1874 | drag_modifiers); |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | /* User has released all mouse buttons, marking the end of a drag. */ |
| 1879 | void |
| 1880 | ro_drag_finished(block) |
| 1881 | int *block; |
| 1882 | { |
| 1883 | int x; |
| 1884 | int y; |
| 1885 | int width, height; |
| 1886 | |
| 1887 | /* I don't trust the box returned by Wimp_Poll; look at the pointer |
| 1888 | * ourselves. |
| 1889 | */ |
| 1890 | swi(Wimp_GetPointerInfo, 0, block); |
| 1891 | x = block[0] + drag_x_offset; |
| 1892 | y = block[1] + drag_y_offset; |
| 1893 | |
| 1894 | if (ro_dragging == DRAG_RESIZE_WINDOW) |
| 1895 | { |
| 1896 | block[0] = gui.window_handle; |
| 1897 | swi(Wimp_GetWindowState, 0, block); |
| 1898 | block[2] = y; |
| 1899 | block[3] = x; |
| 1900 | ro_open_main(block); |
| 1901 | |
| 1902 | width = (block[3] - block[1]); |
| 1903 | height = (block[4] - block[2]); |
| 1904 | |
| 1905 | swi(Wimp_ForceRedraw, gui.window_handle, 0, -height, width, 0); |
| 1906 | gui_resize_shell(width, height); |
| 1907 | } |
| 1908 | else |
| 1909 | { |
| 1910 | block[0] = gui.window_handle; |
| 1911 | swi(Wimp_GetWindowState, 0, block); |
| 1912 | gui_send_mouse_event( |
| 1913 | MOUSE_RELEASE, |
| 1914 | x - block[1], |
| 1915 | block[4] - y, |
| 1916 | FALSE, /* not a double click */ |
| 1917 | drag_modifiers); |
| 1918 | } |
| 1919 | ro_dragging = DRAG_FALSE; |
| 1920 | } |
| 1921 | |
| 1922 | /* Load the file/pathname given in block into a [new] buffer. |
| 1923 | * |
| 1924 | * Modifier Action |
| 1925 | * |
| 1926 | * None :confirm e <file> |
| 1927 | * Ctrl :sp <file> |
| 1928 | * Shift <file> |
| 1929 | * |
| 1930 | * Insert into typebuf, at the start. |
| 1931 | * If loading from !Scrap then use saved leafname instead, and |
| 1932 | * delete the scrap file. Also, ignore shift key. |
| 1933 | * |
| 1934 | * NB: Doesn't send DataLoadAck (other app might delete temp file?). |
| 1935 | */ |
| 1936 | void |
| 1937 | ro_dataload(block) |
| 1938 | int *block; |
| 1939 | { |
| 1940 | char_u new_path[MAXPATHL]; |
| 1941 | char_u *path = ((char_u *) block) + 44; |
| 1942 | int scrap = FALSE; |
| 1943 | |
| 1944 | if (block[3] == leaf_ref && leaf_name) |
| 1945 | scrap = TRUE; |
| 1946 | |
| 1947 | switch (get_real_state() & 0xff) |
| 1948 | { |
| 1949 | case INSERT: |
| 1950 | case CMDLINE: |
| 1951 | case CMDLINE+LANGMAP: |
| 1952 | /* For insert mode we can only insert the pathname (currently) |
| 1953 | * Make sure Shift is pressed. |
| 1954 | */ |
| 1955 | swi(OS_Byte, 121, 0x80); /* Is Shift pressed? */ |
| 1956 | if (r1 == 0xff) |
| 1957 | { |
| 1958 | ins_typebuf(" ", REMAP_NONE, 0, TRUE, FALSE); |
| 1959 | ins_typebuf(path, REMAP_NONE, 0, TRUE, FALSE); |
| 1960 | ro_return_early = TRUE; /* Return even though nothing was typed. */ |
| 1961 | } |
| 1962 | else |
| 1963 | swi(Wimp_ReportError, |
| 1964 | "\0\0\0\0Sorry, you can only load text in normal mode", 5, "Vim"); |
| 1965 | break; |
| 1966 | |
| 1967 | case NORMAL: |
| 1968 | ro_return_early = TRUE; /* Return even though nothing was typed. */ |
| 1969 | |
| 1970 | if (scrap) /* Remove <Wimp$Scrap>. Later. */ |
| 1971 | ins_typebuf(":!~remove <Wimp$Scrap>\r", REMAP_NONE, 0, TRUE, FALSE); |
| 1972 | |
| 1973 | /* Insert {:sp ,:confirm e }[+f\ <leaf> ]<file><CR> */ |
| 1974 | ins_typebuf("\r", REMAP_NONE, 0, TRUE, FALSE); |
| 1975 | ins_typebuf(path, REMAP_NONE, 0, TRUE, FALSE); |
| 1976 | ins_typebuf(" ", REMAP_NONE, 0, TRUE, FALSE); |
| 1977 | |
| 1978 | if (scrap) |
| 1979 | { |
| 1980 | /* Loading via !Scrap - change pathname to stored leafname */ |
| 1981 | ins_typebuf(leaf_name, REMAP_NONE, 0, TRUE, FALSE); |
| 1982 | ins_typebuf(" +f\\ ", REMAP_NONE, 0, TRUE, FALSE); |
| 1983 | leaf_ref = 0; |
| 1984 | vim_free(leaf_name); |
| 1985 | leaf_name = NULL; |
| 1986 | } |
| 1987 | |
| 1988 | swi(OS_Byte, 121, 0x81); /* Is Ctrl pressed? */ |
| 1989 | if (r1 == 0xff) |
| 1990 | /* Yes, split window */ |
| 1991 | ins_typebuf(":sp", REMAP_NONE, 0, TRUE, FALSE); |
| 1992 | else |
| 1993 | ins_typebuf(":confirm e", REMAP_NONE, 0, TRUE, FALSE); |
| 1994 | break; |
| 1995 | |
| 1996 | default: |
| 1997 | swi(Wimp_ReportError, "\0\0\0\0You can only load text in normal mode.", 5, "Vim"); |
| 1998 | } |
| 1999 | /* Send DataSaveAck so other program doesn't think we died |
| 2000 | * and delete <Wimp$Scrap>. |
| 2001 | */ |
| 2002 | block[3] = block[2]; |
| 2003 | block[4] = 4; |
| 2004 | swi(Wimp_SendMessage, 17, block, block[1]); |
| 2005 | } |
| 2006 | |
| 2007 | void |
| 2008 | ro_datasave(block) |
| 2009 | int *block; |
| 2010 | { |
| 2011 | char_u *path = ((char_u *) block) + 44; |
| 2012 | |
| 2013 | /* Preserve the name given so we can use it, not <Wimp$Scrap> */ |
| 2014 | if (leaf_name) |
| 2015 | vim_free(leaf_name); |
| 2016 | leaf_name = vim_strsave(path); |
| 2017 | |
| 2018 | block[9] = -1; /* File is unsafe. */ |
| 2019 | strcpy(path, "<Wimp$Scrap>"); |
| 2020 | block[0] = 60; |
| 2021 | block[3] = block[2]; |
| 2022 | block[4] = 2; |
| 2023 | swi(Wimp_SendMessage, 17, block, block[1]); |
| 2024 | |
| 2025 | leaf_ref = block[2]; |
| 2026 | } |
| 2027 | |
| 2028 | void |
| 2029 | ro_message(block) |
| 2030 | int *block; |
| 2031 | { |
| 2032 | char_u *buffer; |
| 2033 | long_u len; |
| 2034 | |
| 2035 | if (block[1] == task_handle) |
| 2036 | return; /* Don't talk to ourself! */ |
| 2037 | switch (block[4]) |
| 2038 | { |
| 2039 | case 0: /* Quit. */ |
| 2040 | if (block[4] == 0) |
| 2041 | ro_quit(); |
| 2042 | break; |
| 2043 | case 1: /* DataSave */ |
| 2044 | ro_datasave(block); |
| 2045 | break; |
| 2046 | case 2: /* DataSaveAck. */ |
| 2047 | if (clip_convert_selection(&buffer, &len, &clip_star) == -1) |
| 2048 | return; |
| 2049 | |
| 2050 | /* Save the clipboard contents to a file. */ |
| 2051 | swi(OS_File, 10, ((char_u *) block) + 44, 0xfff, 0, buffer, buffer + len); |
| 2052 | |
| 2053 | /* Ack with DataLoad message. */ |
| 2054 | block[3] = block[2]; |
| 2055 | block[4] = 3; |
| 2056 | block[9] = len; |
| 2057 | swi(Wimp_SendMessage, 17, block, block[1]); |
| 2058 | |
| 2059 | vim_free(buffer); |
| 2060 | break; |
| 2061 | case 3: /* DataLoad */ |
| 2062 | ro_dataload(block); |
| 2063 | break; |
| 2064 | case 8: /* PreQuit */ |
| 2065 | ro_prequit(block); |
| 2066 | break; |
| 2067 | case 0xf: /* Lose clipboard. */ |
| 2068 | if (block[5] & 4) |
| 2069 | { |
| 2070 | clip_free_selection(&clip_star); |
| 2071 | clip_star.owned = FALSE; |
| 2072 | } |
| 2073 | break; |
| 2074 | case 0x10: /* DataRequest (clip_star) */ |
| 2075 | if (clip_star.owned) |
| 2076 | { |
| 2077 | int rows; |
| 2078 | |
| 2079 | /* Tell other program that we have the clipboard. */ |
| 2080 | block[0] = 52; |
| 2081 | block[3] = block[2]; /* Copy myref to yourref. */ |
| 2082 | block[4] = 1; /* DataSave message. */ |
| 2083 | /* Create an estimate for the size (larger or same as true |
| 2084 | * value) */ |
| 2085 | rows = clip_star.end.lnum - clip_star.start.lnum; |
| 2086 | if (rows < 0) |
| 2087 | rows = -rows; |
| 2088 | block[9] = (rows + 1) * Columns + 1; /* Add one for possible |
| 2089 | final newline. */ |
| 2090 | block[10] = 0xfff; /* Clipboard is text. */ |
| 2091 | strcpy( ((char_u *) block) + 44, "VimClip"); |
| 2092 | swi(Wimp_SendMessage, 17, block, block[1]); |
| 2093 | } |
| 2094 | break; |
| 2095 | case 0x400c1: /* Mode change */ |
| 2096 | changed_mode = TRUE; /* Flag - update on next OpenWindow */ |
| 2097 | if (zap_redraw) |
| 2098 | { |
| 2099 | /* JK230798, re-initialise ZapRedraw stuff */ |
| 2100 | if (ro_zap_redraw_initialise() == FAIL) |
| 2101 | zap_redraw = FALSE; |
| 2102 | } |
| 2103 | break; |
| 2104 | case 0x400c3: /* TaskCloseDown */ |
| 2105 | if (block[1] == child_handle) |
| 2106 | child_handle = 0; |
| 2107 | break; |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | /* |
| 2112 | * Converts a scrollbar's window handle into a scrollbar pointer. |
| 2113 | * NULL on failure. |
| 2114 | */ |
| 2115 | scrollbar_T * |
| 2116 | ro_find_sbar(id) |
| 2117 | int id; |
| 2118 | { |
| 2119 | win_T *wp; |
| 2120 | |
| 2121 | if (gui.bottom_sbar.id == id) |
| 2122 | return &gui.bottom_sbar; |
| 2123 | FOR_ALL_WINDOWS(wp) |
| 2124 | { |
| 2125 | if (wp->w_scrollbars[SBAR_LEFT].id == id) |
| 2126 | return &wp->w_scrollbars[SBAR_LEFT]; |
| 2127 | if (wp->w_scrollbars[SBAR_RIGHT].id == id) |
| 2128 | return &wp->w_scrollbars[SBAR_RIGHT]; |
| 2129 | } |
| 2130 | return NULL; |
| 2131 | } |
| 2132 | |
| 2133 | void |
| 2134 | scroll_to(line, sb) |
| 2135 | int sb; /* Scrollbar number */ |
| 2136 | int line; |
| 2137 | { |
| 2138 | char_u code[8]; |
| 2139 | |
| 2140 | /* Don't put events in the input queue now. */ |
| 2141 | if (hold_gui_events) |
| 2142 | return; |
| 2143 | |
| 2144 | /* Send a scroll event: |
| 2145 | * |
| 2146 | * A scrollbar event is CSI (NOT K_SPECIAL), KS_VER_SCROLLBAR, |
| 2147 | * KE_FILLER followed by: |
| 2148 | * one byte representing the scrollbar number, and then four bytes |
| 2149 | * representing a long_u which is the new value of the scrollbar. |
| 2150 | */ |
| 2151 | code[0] = CSI; |
| 2152 | code[1] = KS_VER_SCROLLBAR; |
| 2153 | code[2] = KE_FILLER; |
| 2154 | code[3] = sb; |
| 2155 | code[4] = line >> 24; |
| 2156 | code[5] = line >> 16; |
| 2157 | code[6] = line >> 8; |
| 2158 | code[7] = line; |
| 2159 | add_to_input_buf(code, 8); |
| 2160 | } |
| 2161 | |
| 2162 | void |
| 2163 | h_scroll_to(col) |
| 2164 | int col; |
| 2165 | { |
| 2166 | char_u code[8]; |
| 2167 | |
| 2168 | /* Don't put events in the input queue now. */ |
| 2169 | if (hold_gui_events) |
| 2170 | return; |
| 2171 | |
| 2172 | /* Send a scroll event: |
| 2173 | * |
| 2174 | * A scrollbar event is CSI (NOT K_SPECIAL) |
| 2175 | * |
| 2176 | * A horizontal scrollbar event is K_SPECIAL, KS_HOR_SCROLLBAR, |
| 2177 | * KE_FILLER followed by four bytes representing a long_u which is the |
| 2178 | * new value of the scrollbar. |
| 2179 | */ |
| 2180 | code[0] = CSI; |
| 2181 | code[1] = KS_HOR_SCROLLBAR; |
| 2182 | code[2] = KE_FILLER; |
| 2183 | code[4] = col >> 24; |
| 2184 | code[5] = col >> 16; |
| 2185 | code[6] = col >> 8; |
| 2186 | code[7] = col; |
| 2187 | add_to_input_buf(code, 8); |
| 2188 | } |
| 2189 | |
| 2190 | void |
| 2191 | ro_scroll(block) |
| 2192 | int *block; |
| 2193 | { |
| 2194 | scrollbar_T *sb; |
| 2195 | int offset; |
| 2196 | win_T *wp; |
| 2197 | |
| 2198 | /* Block is ready for Wimp_OpenWindow, and also contains: |
| 2199 | * |
| 2200 | * +32 = scroll X direction (-2 .. +2) |
| 2201 | * +36 = scroll Y direction (-2 .. +2) |
| 2202 | */ |
| 2203 | |
| 2204 | sb = ro_find_sbar(block[0]); |
| 2205 | if (!sb) |
| 2206 | return; /* Window not found (error). */ |
| 2207 | |
| 2208 | wp = sb-> wp; |
| 2209 | |
| 2210 | if (wp == NULL) |
| 2211 | { |
| 2212 | /* Horizontal bar. */ |
| 2213 | offset = block[8]; |
| 2214 | if (offset == -2) |
| 2215 | offset = (block[1] - block[3]) / gui.char_width; |
| 2216 | else if (offset == 2) |
| 2217 | offset = (block[3] - block[1]) / gui.char_width; |
| 2218 | |
| 2219 | block[5] += offset * gui.char_width; |
| 2220 | |
| 2221 | gui_drag_scrollbar(sb, block[5] / gui.char_width, FALSE); |
| 2222 | |
| 2223 | swi(Wimp_OpenWindow, 0, block); |
| 2224 | } |
| 2225 | else |
| 2226 | { |
| 2227 | offset = -block[9]; |
| 2228 | if (offset == -2) |
| 2229 | offset = -(wp -> w_height - 1); |
| 2230 | else if (offset == 2) |
| 2231 | offset = wp -> w_height - 1; |
| 2232 | |
| 2233 | /* Possibly we should reposition the scrollbar? |
| 2234 | * Vim seems to update the bar anyway... |
| 2235 | */ |
| 2236 | gui_drag_scrollbar(sb, offset - (block[6] / gui.char_height), FALSE); |
| 2237 | } |
| 2238 | } |
| 2239 | |
| 2240 | /* Move a window by a given offset. Used to simulate the function of the |
| 2241 | * nested wimp. |
| 2242 | */ |
| 2243 | void |
| 2244 | ro_move_child(window, x, y, pos_wanted, pos_got) |
| 2245 | int window; |
| 2246 | int x,y; /* offset to move by */ |
| 2247 | int pos_wanted, pos_got; |
| 2248 | { |
| 2249 | int block[10]; |
| 2250 | |
| 2251 | block[0] = window; |
| 2252 | swi(Wimp_GetWindowState, 0, block); |
| 2253 | block[1] += x; |
| 2254 | block[2] += y; |
| 2255 | block[3] += x; |
| 2256 | block[4] += y; |
| 2257 | if (pos_wanted == -1) |
| 2258 | block[7] = -1; |
| 2259 | else if (pos_wanted == -2) |
| 2260 | block[7] = pos_got; |
| 2261 | swi(Wimp_OpenWindow, 0, block); |
| 2262 | } |
| 2263 | |
| 2264 | /* Open the main window. Also updates scrollbars if we are not |
| 2265 | * using the nested Wimp. |
| 2266 | * If we have just changed mode then re-read all values. |
| 2267 | */ |
| 2268 | void |
| 2269 | ro_open_main(block) |
| 2270 | int *block; |
| 2271 | { |
| 2272 | int toggle_size; |
| 2273 | |
| 2274 | /* Find out if the user clicked on the toggle size icon. */ |
| 2275 | block[20] = block[0]; |
| 2276 | swi(Wimp_GetWindowState, 0, block + 20); |
| 2277 | toggle_size = block[28] & (1 << 19); |
| 2278 | |
| 2279 | if (nested_wimp) |
| 2280 | { |
| 2281 | swi(Wimp_OpenWindow, 0, block); |
| 2282 | } |
| 2283 | else |
| 2284 | { |
| 2285 | int old[10]; |
| 2286 | int x_offset, y_offset; /* Move children same as parent. */ |
| 2287 | int pos_wanted, pos_got; |
| 2288 | int left_bar = gui.which_scrollbars[SBAR_LEFT]; |
| 2289 | int right_bar = gui.which_scrollbars[SBAR_RIGHT]; |
| 2290 | win_T *wp; |
| 2291 | |
| 2292 | /* Three cases to think about: |
| 2293 | * 1) Move to top. Open each window at the top. |
| 2294 | * 2) Same stack position. Open each with same position. |
| 2295 | * 3) Open at bottom. Open children with parent's new position. |
| 2296 | */ |
| 2297 | |
| 2298 | old[0] = block[0]; |
| 2299 | swi(Wimp_GetWindowState, 0, old); |
| 2300 | pos_wanted = block[7]; |
| 2301 | swi(Wimp_OpenWindow, 0, block); |
| 2302 | /* Block updated by OpenWindow? I don't think so! */ |
| 2303 | swi(Wimp_GetWindowState, 0, block); |
| 2304 | pos_got = block[7]; |
| 2305 | |
| 2306 | x_offset = block[1] - old[1]; |
| 2307 | y_offset = block[4] - old[4]; |
| 2308 | if (x_offset || y_offset || pos_wanted == -1 || pos_wanted == -2) |
| 2309 | { |
| 2310 | /* If parent has moved, re-open all the child windows. */ |
| 2311 | FOR_ALL_WINDOWS(wp) |
| 2312 | { |
| 2313 | /* Reopen scrollbars for this window. */ |
| 2314 | if (left_bar) |
| 2315 | ro_move_child(wp -> w_scrollbars[SBAR_LEFT].id, |
| 2316 | x_offset, y_offset, |
| 2317 | pos_wanted, pos_got); |
| 2318 | if (right_bar) |
| 2319 | ro_move_child(wp -> w_scrollbars[SBAR_RIGHT].id, |
| 2320 | x_offset, y_offset, |
| 2321 | pos_wanted, pos_got); |
| 2322 | } |
| 2323 | } |
| 2324 | } |
| 2325 | if (changed_mode || toggle_size) |
| 2326 | { |
| 2327 | int width, height; |
| 2328 | |
| 2329 | if (changed_mode) |
| 2330 | ro_measure_tools(); |
| 2331 | block[0] = gui.window_handle; |
| 2332 | swi(Wimp_GetWindowState, 0, block); |
| 2333 | |
| 2334 | width = block[3] - block[1]; |
| 2335 | height = block[4] - block[2]; |
| 2336 | swi(Wimp_ForceRedraw, gui.window_handle, 0, -height, width, 0); |
| 2337 | gui_resize_shell(width, height); |
| 2338 | changed_mode = FALSE; |
| 2339 | } |
| 2340 | } |
| 2341 | |
| 2342 | void |
| 2343 | ro_open_window(block) |
| 2344 | int *block; |
| 2345 | { |
| 2346 | int pos; |
| 2347 | scrollbar_T *sb; |
| 2348 | |
| 2349 | if (block[0] == gui.window_handle) |
| 2350 | ro_open_main(block); |
| 2351 | else |
| 2352 | { |
| 2353 | swi(Wimp_OpenWindow, 0, block); |
| 2354 | if (block[0] != gui.window_handle) |
| 2355 | { |
| 2356 | sb = ro_find_sbar(block[0]); |
| 2357 | if (sb) |
| 2358 | { |
| 2359 | if (sb-> wp != NULL) |
| 2360 | gui_drag_scrollbar(sb, -block[6] / gui.char_height, FALSE); |
| 2361 | else |
| 2362 | gui_drag_scrollbar(sb, block[5] / gui.char_width, FALSE); |
| 2363 | } |
| 2364 | } |
| 2365 | } |
| 2366 | } |
| 2367 | |
| 2368 | void |
| 2369 | ro_menu_selection(block) |
| 2370 | int *block; |
| 2371 | { |
| 2372 | int *item = wimp_menu + 7; |
| 2373 | vimmenu_T *menu; |
| 2374 | /* wimp_menu points to a wimp menu structure */ |
| 2375 | |
| 2376 | for (;;) |
| 2377 | { |
| 2378 | while (block[0]--) |
| 2379 | item += 6; |
| 2380 | if (block[1] == -1) |
| 2381 | break; |
| 2382 | item = ((int *) item[1]) + 7; |
| 2383 | block++; |
| 2384 | } |
| 2385 | /* item points to the wimp menu item structure chosen */ |
| 2386 | menu = (vimmenu_T *) item[5]; |
| 2387 | |
| 2388 | swi(Wimp_GetPointerInfo, 0, block); |
| 2389 | if (block[2] == 1) |
| 2390 | /* Adjust used - keep menu open */ |
| 2391 | swi(Wimp_CreateMenu, 0, wimp_menu); |
| 2392 | |
| 2393 | if (menu-> cb) |
| 2394 | menu-> cb(menu); |
| 2395 | } |
| 2396 | |
| 2397 | void |
| 2398 | ro_open_parent() |
| 2399 | { |
| 2400 | int head; |
| 2401 | char_u *i = curbuf-> b_ffname; |
| 2402 | char_u buffer[256]; |
| 2403 | |
| 2404 | head = 0; |
| 2405 | for (; *i; i++) |
| 2406 | { |
| 2407 | if (*i == '.') |
| 2408 | head = i - curbuf-> b_ffname; |
| 2409 | } |
| 2410 | |
| 2411 | /* Append head chars to buffer */ |
| 2412 | if (head < 240 && curbuf-> b_ffname && head) |
| 2413 | { |
| 2414 | strcpy(buffer, "%filer_opendir "); |
| 2415 | strncpy(buffer + 15, curbuf-> b_ffname, head); |
| 2416 | buffer[15 + head] = '\0'; |
| 2417 | swi(OS_CLI, buffer); |
| 2418 | } |
| 2419 | } |
| 2420 | |
| 2421 | void |
| 2422 | process_event(event, block) |
| 2423 | int event; |
| 2424 | int *block; |
| 2425 | { |
| 2426 | switch (event) |
| 2427 | { |
| 2428 | case 0: /* Nothing - update drag state. */ |
| 2429 | if (ro_dragging) |
| 2430 | ro_continue_drag(block); |
| 2431 | break; |
| 2432 | case 1: /* Redraw window. */ |
| 2433 | redraw_window(block); |
| 2434 | break; |
| 2435 | case 2: /* Open window. */ |
| 2436 | ro_open_window(block); |
| 2437 | break; |
| 2438 | case 3: /* Close window. */ |
| 2439 | swi(Wimp_GetPointerInfo, 0, block + 1); |
| 2440 | if (block[3] == 1) |
| 2441 | ro_open_parent(); |
| 2442 | else |
| 2443 | if (ro_ok_to_quit()) |
| 2444 | ro_quit(); |
| 2445 | break; |
| 2446 | case 6: /* Mouse click. */ |
| 2447 | ro_mouse(block); |
| 2448 | break; |
| 2449 | case 7: /* Finished drag. */ |
| 2450 | ro_drag_finished(block); |
| 2451 | break; |
| 2452 | case 8: /* Key pressed. */ |
| 2453 | ro_insert_key((char_u *) &block[6]); |
| 2454 | break; |
| 2455 | case 9: |
| 2456 | ro_menu_selection(block); |
| 2457 | break; |
| 2458 | case 10: /* Scroll request. */ |
| 2459 | ro_scroll(block); |
| 2460 | break; |
| 2461 | case 11: /* Lose caret. */ |
| 2462 | if (block[0] == gui.window_handle) |
| 2463 | gui_focus_change(FALSE); |
| 2464 | break; |
| 2465 | case 12: /* Gain caret. */ |
| 2466 | if (block[0] == gui.window_handle) |
| 2467 | gui_focus_change(TRUE); |
| 2468 | break; |
| 2469 | case 17: /* User message. */ |
| 2470 | case 18: /* User message recorded. */ |
| 2471 | ro_message(block); |
| 2472 | break; |
| 2473 | } |
| 2474 | } |
| 2475 | |
| 2476 | /* |
| 2477 | * GUI input routine called by gui_wait_for_chars(). Waits for a character |
| 2478 | * from the keyboard. |
| 2479 | * wtime == -1 Wait forever. |
| 2480 | * wtime == 0 This should never happen. |
| 2481 | * wtime > 0 Wait wtime milliseconds for a character. |
| 2482 | * Returns OK if a character was found to be available within the given time, |
| 2483 | * or FAIL otherwise. |
| 2484 | */ |
| 2485 | int |
| 2486 | gui_mch_wait_for_chars(long wtime) |
| 2487 | { |
| 2488 | int block[64]; |
| 2489 | int reason; |
| 2490 | int start_time = -1; |
| 2491 | int ctime = wtime / 10; /* delay in cs */ |
| 2492 | |
| 2493 | if (wtime != -1) |
| 2494 | { |
| 2495 | swi(OS_ReadMonotonicTime); |
| 2496 | start_time = r0; |
| 2497 | } |
| 2498 | |
| 2499 | for (;;) |
| 2500 | { |
| 2501 | if (ro_dragging) |
| 2502 | reason = wimp_poll(0, block); /* Always return immediately */ |
| 2503 | else if (wtime == -1) |
| 2504 | reason = wimp_poll(1, block); |
| 2505 | else |
| 2506 | reason = wimp_pollidle(0, block, start_time + ctime); |
| 2507 | |
| 2508 | process_event(reason, block); |
| 2509 | |
| 2510 | if (input_available() || ro_return_early) |
| 2511 | { |
| 2512 | ro_return_early = FALSE; |
| 2513 | return OK; /* There is something to process (key / menu event) */ |
| 2514 | } |
| 2515 | |
| 2516 | if (wtime != -1) |
| 2517 | { |
| 2518 | swi(OS_ReadMonotonicTime); |
| 2519 | if (r0 - start_time > ctime) |
| 2520 | return FAIL; /* We've been waiting too long - return failure */ |
| 2521 | } |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | /* Flush any output to the screen */ |
| 2526 | void |
| 2527 | gui_mch_flush(void) |
| 2528 | { |
| 2529 | } |
| 2530 | |
| 2531 | /* |
| 2532 | * Clear a rectangular region of the screen from text pos(row1, col1) to |
| 2533 | * (row2, col2) inclusive. |
| 2534 | */ |
| 2535 | void |
| 2536 | gui_mch_clear_block(int row1, int col1, int row2, int col2) |
| 2537 | { |
| 2538 | swi(ColourTrans_ReturnGCOL, gui.back_pixel << 8, 0, 0, 1<<7, 0); |
| 2539 | plot_rectangle(96 + 5, r0, |
| 2540 | FILL_X(col1), -FILL_Y(row2 + 1), |
| 2541 | FILL_X(col2 + 1), -FILL_Y(row1)); |
| 2542 | } |
| 2543 | |
| 2544 | void |
| 2545 | gui_mch_clear_all(void) |
| 2546 | { |
| 2547 | if (redraw_block) |
| 2548 | { |
| 2549 | swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 1<<7, 0); |
| 2550 | swi(OS_WriteI + 16); |
| 2551 | } |
| 2552 | else |
| 2553 | { |
| 2554 | int block[44]; |
| 2555 | block[0] = gui.window_handle; |
| 2556 | block[1] = 0; |
| 2557 | block[2] = -gui.num_rows * gui.char_height; |
| 2558 | block[3] = gui.num_cols * gui.char_width; |
| 2559 | block[4] = 0; |
| 2560 | swi(Wimp_UpdateWindow, 0, block); |
| 2561 | while (r0) |
| 2562 | { |
| 2563 | swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 1<<7, 0); |
| 2564 | swi(OS_WriteI + 16); |
| 2565 | swi(Wimp_GetRectangle, 0, block); |
| 2566 | } |
| 2567 | } |
| 2568 | } |
| 2569 | |
| 2570 | /* |
| 2571 | * Delete the given number of lines from the given row, scrolling up any |
| 2572 | * text further down within the scroll region. |
| 2573 | */ |
| 2574 | void |
| 2575 | gui_mch_delete_lines(int row, int num_lines) |
| 2576 | { |
| 2577 | int top_from = -row - num_lines; |
| 2578 | int bot_from = -gui.scroll_region_bot - 1; |
| 2579 | int bot_to = bot_from + num_lines; |
| 2580 | |
| 2581 | swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 0x80, 0); |
| 2582 | |
| 2583 | /* Changed without checking! */ |
| 2584 | swi(Wimp_BlockCopy, gui.window_handle, |
| 2585 | gui.scroll_region_left * gui.char_width, |
| 2586 | bot_from * gui.char_height, |
| 2587 | (gui.scroll_region_right - gui.scroll_region_left |
| 2588 | + 1) * gui.char_width, |
| 2589 | top_from * gui.char_height, |
| 2590 | |
| 2591 | gui.scroll_region_left * gui.char_width, |
| 2592 | bot_to * gui.char_height); |
| 2593 | |
| 2594 | gui_clear_block(gui.scroll_region_bot - num_lines + 1, |
| 2595 | gui.scroll_region_left, |
| 2596 | gui.scroll_region_bot, gui.scroll_region_right); |
| 2597 | } |
| 2598 | |
| 2599 | /* |
| 2600 | * Insert the given number of lines before the given row, scrolling down any |
| 2601 | * following text within the scroll region. |
| 2602 | */ |
| 2603 | void |
| 2604 | gui_mch_insert_lines(int row, int num_lines) |
| 2605 | { |
| 2606 | int top_from = -row; |
| 2607 | int bot_to = -gui.scroll_region_bot - 1; |
| 2608 | int bot_from = bot_to + num_lines; |
| 2609 | |
| 2610 | swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 0x80, 0); |
| 2611 | |
| 2612 | swi(Wimp_BlockCopy, gui.window_handle, |
| 2613 | gui.scroll_region_left * gui.char_width, |
| 2614 | bot_from * gui.char_height, |
| 2615 | (gui.scroll_region_right - gui.scroll_region_left |
| 2616 | + 1) * gui.char_width, |
| 2617 | top_from * gui.char_height, |
| 2618 | |
| 2619 | gui.scroll_region_left * gui.char_width, |
| 2620 | bot_to * gui.char_height); |
| 2621 | |
| 2622 | gui_clear_block(row, gui.scroll_region_left, |
| 2623 | row + num_lines - 1, gui.scroll_region_right); |
| 2624 | } |
| 2625 | |
| 2626 | /* Put selection in clipboard buffer. |
| 2627 | * Should we become the new owner? |
| 2628 | */ |
| 2629 | void |
| 2630 | clip_mch_request_selection(VimClipboard *cbd) |
| 2631 | { |
| 2632 | int block[64]; /* Will be used in Wimp_Poll. */ |
| 2633 | int reason; |
| 2634 | char_u *buffer; |
| 2635 | long_u length; |
| 2636 | |
| 2637 | block[0] = 48; /* Size of block. */ |
| 2638 | block[3] = 0; /* Orinial message. */ |
| 2639 | block[4] = 0x10; /* Data request. */ |
| 2640 | block[5] = gui.window_handle; |
| 2641 | block[6] = RO_LOAD_CLIPBOARD; /* Internal handle. */ |
| 2642 | block[7] = block[8] = 0; /* (x,y) not used. */ |
| 2643 | block[9] = 4; |
| 2644 | block[10] = 0xfff; /* We want text files if possible, I think. */ |
| 2645 | block[11] = -1; /* End of list. */ |
| 2646 | swi(Wimp_SendMessage, 17, block, 0); /* Broadcast request. */ |
| 2647 | |
| 2648 | /* OK, we've sent the request. Poll until we get a null poll (failure) or |
| 2649 | * we load the clipboard. |
| 2650 | * If we receive a DataSave event with icon handle = -2 then put it on the |
| 2651 | * clipboard. RISC OS should ensure that key events will not be delivered |
| 2652 | * until the clipboard operation completes (unless the owner starts idling |
| 2653 | * - we can't wait forever!). |
| 2654 | */ |
| 2655 | for (;;) |
| 2656 | { |
| 2657 | reason = wimp_poll(0, block); |
| 2658 | if (reason == 0) |
| 2659 | return; /* Failed to get clipboard. */ |
| 2660 | if ((reason == 17 || reason == 18) && |
| 2661 | block[4] == 1 && block[6] == RO_LOAD_CLIPBOARD) |
| 2662 | break; /* Got it - stop waiting. */ |
| 2663 | process_event(reason, block); |
| 2664 | if (ro_return_early) |
| 2665 | return; |
| 2666 | } |
| 2667 | /* Tell owner to save data in <Wimp$Scrap>. */ |
| 2668 | block[0] = 60; |
| 2669 | block[3] = block[2]; /* Copy myref -> yourref */ |
| 2670 | block[4] = 2; /* DataSaveAck. */ |
| 2671 | block[9] = -1; /* Data is unsafe. */ |
| 2672 | strcpy( ((char_u *) block) + 44, "<Wimp$Scrap>"); |
| 2673 | swi(Wimp_SendMessage, 17, block, block[1]); |
| 2674 | |
| 2675 | /* Wait again for reply. */ |
| 2676 | for (;;) |
| 2677 | { |
| 2678 | reason = wimp_poll(0, block); |
| 2679 | if (reason == 0) |
| 2680 | return; /* Other program has given up! */ |
| 2681 | if ((reason == 17 || reason == 18) && block[4] == 3 && block[6] == RO_LOAD_CLIPBOARD) |
| 2682 | break; /* Clipboard data saved to <Wimp$Scrap> */ |
| 2683 | process_event(reason, block); |
| 2684 | if (ro_return_early) |
| 2685 | return; |
| 2686 | } |
| 2687 | |
| 2688 | /* <Wimp$Scrap> contains clipboard - load it. */ |
| 2689 | if (xswi(OS_File, 17, "<Wimp$Scrap>") & v_flag) |
| 2690 | return; /* Error! */ |
| 2691 | if (r0 != 1 && r0 != 3) |
| 2692 | return; |
| 2693 | length = r4; |
| 2694 | |
| 2695 | buffer = lalloc(length, TRUE); /* Claim memory (and report errors). */ |
| 2696 | if (buffer == NULL) |
| 2697 | return; |
| 2698 | |
| 2699 | if (xswi(OS_File, 16, "<Wimp$Scrap>", buffer, 0) & v_flag) |
| 2700 | return; |
| 2701 | |
| 2702 | clip_yank_selection(MCHAR, buffer, length, cbd); |
| 2703 | |
| 2704 | vim_free(buffer); |
| 2705 | |
| 2706 | swi(OS_FSControl, 27, "<Wimp$Scrap>", 0, 0); /* Delete temp file. */ |
| 2707 | |
| 2708 | block[4] = 4; /* Send DataLoadAck. */ |
| 2709 | block[3] = block[2]; /* Copy myref -> yourref. */ |
| 2710 | swi(Wimp_SendMessage, 17, block, block[1]); |
| 2711 | } |
| 2712 | |
| 2713 | /* Not sure what this means under RISC OS. */ |
| 2714 | void |
| 2715 | clip_mch_lose_selection(VimClipboard *cbd) |
| 2716 | { |
| 2717 | } |
| 2718 | |
| 2719 | /* Tell everyone that we now own the clipboard. |
| 2720 | * Return OK if our claim is accepted (always, under RISC OS) |
| 2721 | */ |
| 2722 | int |
| 2723 | clip_mch_own_selection(VimClipboard *cbd) |
| 2724 | { |
| 2725 | int block[6]; |
| 2726 | block[0] = 24; /* Length of block. */ |
| 2727 | block[3] = 0; /* Original message. */ |
| 2728 | block[4] = 0xf; /* ClaimEntity. */ |
| 2729 | block[5] = 0x4; /* Claim clipboard only. */ |
| 2730 | swi(Wimp_SendMessage, 17, block, 0); |
| 2731 | return OK; |
| 2732 | } |
| 2733 | |
| 2734 | /* |
| 2735 | * Send the current selection to the clipboard. Do nothing for X because we |
| 2736 | * will fill in the selection only when requested by another app. Sounds good |
| 2737 | * for RISC OS too. |
| 2738 | */ |
| 2739 | void |
| 2740 | clip_mch_set_selection(VimClipboard *cbd) |
| 2741 | { |
| 2742 | clip_get_selection(cbd); |
| 2743 | } |
| 2744 | |
| 2745 | /* |
| 2746 | * Make a menu either grey or not grey. |
| 2747 | */ |
| 2748 | void |
| 2749 | gui_mch_menu_grey(vimmenu_T *menu, int grey) |
| 2750 | { |
| 2751 | menu-> greyed_out = grey; |
| 2752 | } |
| 2753 | |
| 2754 | /* |
| 2755 | * Make menu item hidden or not hidden |
| 2756 | */ |
| 2757 | void |
| 2758 | gui_mch_menu_hidden(vimmenu_T *menu, int hidden) |
| 2759 | { |
| 2760 | menu-> hidden = hidden; |
| 2761 | } |
| 2762 | |
| 2763 | /* |
| 2764 | * This is called after setting all the menus to grey/hidden or not. |
| 2765 | */ |
| 2766 | void |
| 2767 | gui_mch_draw_menubar(void) |
| 2768 | { |
| 2769 | swi(Wimp_CreateMenu, 0, -1); |
| 2770 | if (wimp_menu != (int *) -1) |
| 2771 | { |
| 2772 | ro_remove_menu(wimp_menu); |
| 2773 | wimp_menu = (int *) -1; |
| 2774 | } |
| 2775 | } |
| 2776 | |
| 2777 | /* Add or remove a scrollbar. Note that this is only called when |
| 2778 | * the scrollbar state is changing. |
| 2779 | * The scroll bar window has already been created. |
| 2780 | * We can't do anything except remove the scroll bar |
| 2781 | * until we know what size to use. |
| 2782 | */ |
| 2783 | void |
| 2784 | gui_mch_enable_scrollbar(sb, flag) |
| 2785 | scrollbar_T *sb; |
| 2786 | int flag; |
| 2787 | { |
| 2788 | if (!flag) |
| 2789 | swi(Wimp_CloseWindow, 0, & (sb->id) ); |
| 2790 | return; |
| 2791 | } |
| 2792 | |
| 2793 | void |
| 2794 | gui_mch_set_blinking(long waittime, long on, long off) |
| 2795 | { |
| 2796 | } |
| 2797 | |
| 2798 | /* |
| 2799 | * Stop the cursor blinking. Show the cursor if it wasn't shown. |
| 2800 | */ |
| 2801 | void |
| 2802 | gui_mch_stop_blink(void) |
| 2803 | { |
| 2804 | } |
| 2805 | |
| 2806 | /* |
| 2807 | * Start the cursor blinking. If it was already blinking, this restarts the |
| 2808 | * waiting time and shows the cursor. |
| 2809 | */ |
| 2810 | void |
| 2811 | gui_mch_start_blink(void) |
| 2812 | { |
| 2813 | } |
| 2814 | |
| 2815 | /* |
| 2816 | * Return the RGB value of a pixel as a long. |
| 2817 | */ |
| 2818 | long_u |
| 2819 | gui_mch_get_rgb(guicolor_T pixel) |
| 2820 | { |
| 2821 | return (long_u)pixel; |
| 2822 | } |
| 2823 | |
| 2824 | void |
| 2825 | gui_mch_set_text_area_pos(int x, int y, int w, int h) |
| 2826 | { |
| 2827 | } |
| 2828 | |
| 2829 | void |
| 2830 | gui_mch_enable_menu(int flag) |
| 2831 | { |
| 2832 | } |
| 2833 | |
| 2834 | void |
| 2835 | gui_mch_set_menu_pos(int x, int y, int w, int h) |
| 2836 | { |
| 2837 | } |
| 2838 | |
| 2839 | void |
| 2840 | gui_mch_add_menu(vimmenu_T *menu, int idx) |
| 2841 | { |
| 2842 | } |
| 2843 | |
| 2844 | void |
| 2845 | gui_mch_add_menu_item(vimmenu_T *menu, int idx) |
| 2846 | { |
| 2847 | } |
| 2848 | |
| 2849 | void |
| 2850 | gui_mch_new_menu_colors(void) |
| 2851 | { |
| 2852 | } |
| 2853 | |
| 2854 | void |
| 2855 | gui_mch_destroy_menu(vimmenu_T *menu) |
| 2856 | { |
| 2857 | } |
| 2858 | |
| 2859 | /* Size of buffer has changed. |
| 2860 | * Add one to max since gui.c substracts one more than it should! |
| 2861 | */ |
| 2862 | void |
| 2863 | gui_mch_set_scrollbar_thumb(sb, val, size, max) |
| 2864 | scrollbar_T *sb; |
| 2865 | long val; |
| 2866 | long size; |
| 2867 | long max; |
| 2868 | { |
| 2869 | int block[10], width, height; |
| 2870 | |
| 2871 | width = (max + 1) * gui.char_width; |
| 2872 | height = (max + 1 + W_STATUS_HEIGHT(sb->wp)) * gui.char_height; |
| 2873 | |
| 2874 | block[0] = block[3] = 0; |
| 2875 | block[1] = -height + (1 << y_eigen_factor); |
| 2876 | block[2] = width; |
| 2877 | |
| 2878 | swi(Wimp_SetExtent, sb -> id, block); |
| 2879 | |
| 2880 | block[0] = sb -> id; |
| 2881 | swi(Wimp_GetWindowState, 0, block); |
| 2882 | block[5] = val * gui.char_width; |
| 2883 | block[6] = -val * gui.char_height; |
| 2884 | swi(Wimp_OpenWindow, 0, block, 0x4b534154, |
| 2885 | gui.window_handle, /* Parent window handle. */ |
| 2886 | (CHILD_FIX_TO_RIGHT << CHILD_LEFT ) | |
| 2887 | (CHILD_FIX_TO_RIGHT << CHILD_RIGHT ) | |
| 2888 | (CHILD_FIX_TO_BOTTOM << CHILD_TOP ) | |
| 2889 | (CHILD_FIX_TO_BOTTOM << CHILD_BOTTOM) | |
| 2890 | (CHILD_SELF_SCROLL << CHILD_SCROLL_X) | |
| 2891 | (CHILD_SELF_SCROLL << CHILD_SCROLL_Y) |
| 2892 | ); |
| 2893 | } |
| 2894 | |
| 2895 | /* Set the position of the scrollbar within the editor |
| 2896 | * window. Note that, for vertical scrollbars, x and w |
| 2897 | * are ignored. For horizontal bars y and h are ignored. |
| 2898 | */ |
| 2899 | void |
| 2900 | gui_mch_set_scrollbar_pos(sb, x, y, w, h) |
| 2901 | scrollbar_T *sb; |
| 2902 | int x; /* Horizontal sb position */ |
| 2903 | int y; /* Top of scroll bar */ |
| 2904 | int w; /* Width */ |
| 2905 | int h; /* Height */ |
| 2906 | { |
| 2907 | int block[24]; |
| 2908 | int px1, py1; /* Parent window min coords */ |
| 2909 | int px2, py2; /* Parent window max coords */ |
| 2910 | |
| 2911 | /* Find where the parent window is. */ |
| 2912 | block[0] = gui.window_handle; |
| 2913 | swi(Wimp_GetWindowState, 0, block); |
| 2914 | px1 = block[1]; |
| 2915 | py1 = block[2]; |
| 2916 | px2 = block[3]; |
| 2917 | py2 = block[4]; |
| 2918 | |
| 2919 | block[0] = sb -> id; |
| 2920 | |
| 2921 | /* Find out how big the scroll window is at the moment. */ |
| 2922 | swi(Wimp_GetWindowInfo, 0, ((char_u *)block) + 1); |
| 2923 | |
| 2924 | if (block[13] < w || block[12] > -h) |
| 2925 | { |
| 2926 | /* Current window is too small! */ |
| 2927 | if (block[12] > -h) |
| 2928 | block[12] = -h; |
| 2929 | if (block[13] < w) |
| 2930 | block[13] = w; |
| 2931 | swi(Wimp_SetExtent, block[0], block + 11); |
| 2932 | } |
| 2933 | |
| 2934 | /* This works better on the nested_wimp. */ |
| 2935 | if (sb-> wp) |
| 2936 | { |
| 2937 | /* This is a vertical scrollbar. */ |
| 2938 | block[1] = block[3] = px2 - gui.scrollbar_width + (1 << x_eigen_factor); |
| 2939 | block[2] = 1 + py2 - (y + h) + (1 << y_eigen_factor); |
| 2940 | block[4] = 1 + py2 - y; |
| 2941 | } |
| 2942 | else |
| 2943 | { |
| 2944 | /* This is a horizontal scrollbar. */ |
| 2945 | block[2] = block[4] = py1 + gui.scrollbar_height; |
| 2946 | block[1] = px1; |
| 2947 | block[3] = px2 - gui.scrollbar_width; |
| 2948 | } |
| 2949 | |
| 2950 | block[5] = 0; |
| 2951 | block[6] = 0; |
| 2952 | block[7] = -1; |
| 2953 | |
| 2954 | swi(Wimp_OpenWindow, 0, block, 0x4b534154, |
| 2955 | gui.window_handle, /* Parent window handle. */ |
| 2956 | (CHILD_FIX_TO_RIGHT << CHILD_LEFT ) | |
| 2957 | (CHILD_FIX_TO_RIGHT << CHILD_RIGHT ) | |
| 2958 | (CHILD_FIX_TO_BOTTOM << CHILD_TOP ) | |
| 2959 | (CHILD_FIX_TO_BOTTOM << CHILD_BOTTOM) | |
| 2960 | (CHILD_SELF_SCROLL << CHILD_SCROLL_X) | |
| 2961 | (CHILD_SELF_SCROLL << CHILD_SCROLL_Y) |
| 2962 | ); |
| 2963 | } |
| 2964 | |
| 2965 | /* Create a window with no workarea to place inside editor window. |
| 2966 | * (what happens without the nested wimp?) |
| 2967 | * Data for scrollbar is invalid. |
| 2968 | */ |
| 2969 | void |
| 2970 | gui_mch_create_scrollbar(sb, orient) |
| 2971 | scrollbar_T *sb; |
| 2972 | int orient; /* orient is SBAR_HORIZ or SBAR_VERT */ |
| 2973 | { |
| 2974 | int bar[] = |
| 2975 | { |
| 2976 | 0, 0, /* Visible area : min X,Y */ |
| 2977 | 100, 100, /* max X,Y */ |
| 2978 | 0, 0, /* Scroll offsets */ |
| 2979 | -1, /* Window in front */ |
| 2980 | 0x80800150 | (orient == SBAR_HORIZ ? (1 << 30) : (1 << 28)), |
| 2981 | 0xff070207, /* Colours */ |
| 2982 | 0x000c0103, /* More colours */ |
| 2983 | 0, -0x4000, /* Workarea extent */ |
| 2984 | 0x4000, 0, /* max X,Y */ |
| 2985 | 0x00000000, /* No title */ |
| 2986 | 0 << 12, /* No workarea button type */ |
| 2987 | 1, /* Wimp sprite area */ |
| 2988 | 0x00010001, /* Minimum width, height */ |
| 2989 | 0, 0, 0, /* Title data (none) */ |
| 2990 | 0 /* No icons */ |
| 2991 | }; |
| 2992 | swi(Wimp_CreateWindow, 0, bar); |
| 2993 | sb -> id = r0; |
| 2994 | } |
| 2995 | |
| 2996 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 2997 | void |
| 2998 | gui_mch_destroy_scrollbar(scrollbar_T *sb) |
| 2999 | { |
| 3000 | swi(Wimp_DeleteWindow, 0, & (sb->id)); |
| 3001 | sb -> id = -1; |
| 3002 | } |
| 3003 | #endif |
| 3004 | |
| 3005 | void |
| 3006 | gui_mch_set_scrollbar_colors(scrollbar_T *sb) |
| 3007 | { |
| 3008 | /* Always use default RO colour scheme. */ |
| 3009 | } |
| 3010 | |
| 3011 | /* |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 3012 | * Get current mouse coordinates in text window. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3013 | * Note: (0,0) is the bottom left corner, positive y is UP. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3014 | */ |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 3015 | void |
| 3016 | gui_mch_getmouse(x, y) |
| 3017 | int *x; |
| 3018 | int *y; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3019 | { |
| 3020 | int left; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3021 | int top; |
| 3022 | int block[10]; |
| 3023 | |
| 3024 | block[0] = gui.window_handle; |
| 3025 | swi(Wimp_GetWindowState, 0, block); |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 3026 | left = block[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3027 | top = block[4]; |
| 3028 | |
| 3029 | swi(Wimp_GetPointerInfo, 0, block); |
Bram Moolenaar | 9588a0f | 2005-01-08 21:45:39 +0000 | [diff] [blame] | 3030 | *x = block[0] - left; |
| 3031 | *y = top - block[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3032 | } |
| 3033 | |
| 3034 | /* MouseTo(x, y) */ |
| 3035 | void |
| 3036 | gui_mch_setmouse(x, y) |
| 3037 | int x; |
| 3038 | int y; |
| 3039 | { |
| 3040 | } |
| 3041 | |
| 3042 | void |
| 3043 | gui_mch_toggle_tearoffs(enable) |
| 3044 | int enable; |
| 3045 | { |
| 3046 | /* no tearoff menus */ |
| 3047 | } |
| 3048 | |
| 3049 | /* Redraw a window's title. |
| 3050 | * For the nested wimp we use the new 'redraw-title-bar' reason code. |
| 3051 | * For older wimps we mark the area of the screen where the title bar |
| 3052 | * is as invalid. |
| 3053 | */ |
| 3054 | void |
| 3055 | ro_redraw_title(window) |
| 3056 | int window; |
| 3057 | { |
| 3058 | if (nested_wimp) |
| 3059 | { |
| 3060 | swi(Wimp_ForceRedraw, window, 0x4b534154, 3); |
| 3061 | } |
| 3062 | else |
| 3063 | { |
| 3064 | int block[10]; |
| 3065 | int miny; |
| 3066 | |
| 3067 | block[0] = window; |
| 3068 | swi(Wimp_GetWindowState, 0, block); |
| 3069 | miny = block[4]; |
| 3070 | swi(Wimp_GetWindowOutline, 0, block); |
| 3071 | swi(Wimp_ForceRedraw, -1, |
| 3072 | block[1], miny, |
| 3073 | block[3], block[4]); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | /* Turn a vimmenu_T structure into a wimp menu structure. |
| 3078 | * -1 if resulting menu is empty. |
| 3079 | * Only the children and dname items in the root menu are used. |
| 3080 | */ |
| 3081 | int * |
| 3082 | ro_build_menu(menu) |
| 3083 | vimmenu_T *menu; |
| 3084 | { |
| 3085 | int *wimp_menu; |
| 3086 | int width = 4; |
| 3087 | int w; |
| 3088 | int size = 28; |
| 3089 | vimmenu_T *item; |
| 3090 | int *wimp_item; |
| 3091 | |
| 3092 | /* Find out how big the menu is so we can allocate memory for it */ |
| 3093 | for (item = menu-> children; item; item = item-> next) |
| 3094 | { |
| 3095 | if (item-> hidden == FALSE && !menu_is_separator(item->name)) |
| 3096 | size += 24; |
| 3097 | } |
| 3098 | |
| 3099 | if (size <= 28) |
| 3100 | return (int *) -1; /* No children - shouldn't happen */ |
| 3101 | |
| 3102 | wimp_menu = (int *) alloc(size); |
| 3103 | |
| 3104 | wimp_menu[0] = (int) menu-> dname; |
| 3105 | wimp_menu[1] = -1; |
| 3106 | wimp_menu[2] = 0; |
| 3107 | wimp_menu[3] = 0x00070207; |
| 3108 | wimp_menu[5] = 44; |
| 3109 | wimp_menu[6] = 0; |
| 3110 | |
| 3111 | wimp_item = wimp_menu + 7; |
| 3112 | |
| 3113 | for (item = menu-> children; item; item = item-> next) |
| 3114 | { |
| 3115 | if (menu_is_separator(item-> name)) |
| 3116 | { |
| 3117 | /* This menu entry is actually a separator. If it is not the first |
| 3118 | * menu entry then mark the previous menu item as needing a dotted |
| 3119 | * line after it. |
| 3120 | */ |
| 3121 | if (wimp_item > wimp_menu + 7) |
| 3122 | wimp_item[-6] |= 0x2; |
| 3123 | } |
| 3124 | else if (item-> hidden == FALSE) |
| 3125 | { |
| 3126 | wimp_item[0] = 0; |
| 3127 | wimp_item[1] = item-> children ? (int) ro_build_menu(item) : -1; |
| 3128 | wimp_item[2] = 0x07009131 | (item-> greyed_out << 22); |
| 3129 | wimp_item[3] = (int) item-> dname; |
| 3130 | wimp_item[4] = -1; |
| 3131 | wimp_item[5] = (int) item; /* Stuff the menu address in this unused space */ |
| 3132 | |
| 3133 | w = strlen(item-> dname) + 1; |
| 3134 | if (w > width) |
| 3135 | width = w; |
| 3136 | wimp_item += 6; |
| 3137 | } |
| 3138 | } |
| 3139 | |
| 3140 | wimp_menu[4] = (width + 2) * 16; |
| 3141 | wimp_menu[7] |= 0x100; /* Menu title is indirected */ |
| 3142 | wimp_item[-6] |= 0x080; /* Last entry in menu */ |
| 3143 | return wimp_menu; |
| 3144 | } |
| 3145 | |
| 3146 | static void |
| 3147 | ro_remove_menu(menu) |
| 3148 | int *menu; |
| 3149 | { |
| 3150 | int *item = menu + 7; |
| 3151 | |
| 3152 | if (menu == NULL || menu == (int *) -1) |
| 3153 | return; |
| 3154 | |
| 3155 | for (;;) |
| 3156 | { |
| 3157 | if (item[1] != -1) |
| 3158 | ro_remove_menu((int *) item[1]); /* Remove sub-menu */ |
| 3159 | if (item[0] & 0x80) |
| 3160 | break; /* This was the last entry */ |
| 3161 | item += 6; |
| 3162 | } |
| 3163 | vim_free(menu); |
| 3164 | } |
| 3165 | |
| 3166 | void |
| 3167 | gui_mch_show_popupmenu(menu) |
| 3168 | vimmenu_T *menu; |
| 3169 | { |
| 3170 | int block[10]; |
| 3171 | |
| 3172 | /* Remove the existing menu, if any */ |
| 3173 | if (wimp_menu != (int *) -1) |
| 3174 | { |
| 3175 | swi(Wimp_CreateMenu, 0, -1); |
| 3176 | ro_remove_menu(wimp_menu); |
| 3177 | wimp_menu = (int *) -1; |
| 3178 | } |
| 3179 | |
| 3180 | wimp_menu = ro_build_menu(menu); |
| 3181 | if (wimp_menu != (int *) -1) |
| 3182 | { |
| 3183 | swi(Wimp_GetPointerInfo, 0, block); |
| 3184 | swi(Wimp_CreateMenu, 0, wimp_menu, block[0] - 64, block[1] + 64); |
| 3185 | } |
| 3186 | } |
| 3187 | |
| 3188 | /* Run a command using the TaskWindow module. |
| 3189 | * If SHELL_FILTER is set then output is not echoed to the screen, |
| 3190 | * If it is not set, then \r is not sent to the output file. |
| 3191 | */ |
| 3192 | int |
| 3193 | gui_mch_call_shell(cmd, options) |
| 3194 | char_u *cmd; |
| 3195 | int options; /* SHELL_FILTER if called by do_filter() */ |
| 3196 | /* SHELL_COOKED if term needs cooked mode */ |
| 3197 | { |
| 3198 | char_u task_cmd[256]; /* Contains *TaskWindow command. */ |
| 3199 | int block[64]; |
| 3200 | int reason; |
| 3201 | char_u *out; |
| 3202 | char_u c; |
| 3203 | int old_msg_col; |
| 3204 | char_u *out_redir; |
| 3205 | int length; |
| 3206 | FILE *out_file = NULL; |
| 3207 | |
| 3208 | out_redir = strstr(cmd, " > "); |
| 3209 | if (out_redir == NULL) |
| 3210 | length = strlen(cmd); /* No redirection. */ |
| 3211 | else |
| 3212 | { |
| 3213 | length = out_redir - cmd; |
| 3214 | out_file = fopen(out_redir + 3, "wb"); |
| 3215 | if (out_file == NULL) |
Bram Moolenaar | 051b782 | 2005-05-19 21:00:46 +0000 | [diff] [blame] | 3216 | smsg("WARNING : Can't open file %s for writing\n", out_redir + 3); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | if (length > 180) |
| 3220 | { |
| 3221 | if (out_file) |
| 3222 | fclose(out_file); |
| 3223 | return FAIL; /* Command too long. */ |
| 3224 | } |
| 3225 | |
| 3226 | strcpy(task_cmd, "TaskWindow \""); |
| 3227 | strncpy(task_cmd + 12, cmd, length); |
| 3228 | sprintf(task_cmd + 12 + length, |
| 3229 | "\" -task &%08x -ctrl -quit -name \"Vim command\"", |
| 3230 | task_handle); |
| 3231 | |
| 3232 | if (options & SHELL_COOKED) |
| 3233 | settmode(TMODE_COOK); |
| 3234 | |
| 3235 | if (xswi(Wimp_StartTask, task_cmd) & v_flag) |
| 3236 | { |
| 3237 | /* Failed to even start a new task (out of memory?) */ |
| 3238 | settmode(TMODE_RAW); |
| 3239 | if (out_file) |
| 3240 | fclose(out_file); |
| 3241 | return FAIL; |
| 3242 | } |
| 3243 | |
| 3244 | /* Wait for the child process to initialise. */ |
| 3245 | child_handle = 0; |
| 3246 | while (!child_handle) |
| 3247 | { |
| 3248 | reason = wimp_poll(0, block); |
| 3249 | if ((reason == 17 || reason == 18) && block[4] == 0x808c2) |
| 3250 | child_handle = block[1]; |
| 3251 | else |
| 3252 | process_event(reason, block); |
| 3253 | } |
| 3254 | |
| 3255 | /* Block until finished */ |
| 3256 | while (child_handle) |
| 3257 | { |
| 3258 | reason = wimp_poll(1, block); |
| 3259 | if (reason == 3 || (reason == 8 && block[6] == 3)) |
| 3260 | { |
| 3261 | /* Close window request or CTRL-C - kill child task. */ |
| 3262 | block[0] = 20; |
| 3263 | block[3] = 0; |
| 3264 | block[4] = 0x808c4; /* Morite */ |
| 3265 | swi(Wimp_SendMessage, 17, block, child_handle); |
| 3266 | MSG_PUTS(_("\nSending message to terminate child process.\n")); |
| 3267 | continue; |
| 3268 | } |
| 3269 | else if (reason == 8) |
| 3270 | { |
| 3271 | block[0] = 28; |
| 3272 | block[3] = 0; |
| 3273 | block[4] = 0x808c0; /* Input */ |
| 3274 | block[5] = 1; |
| 3275 | /* Block[6] is OK as it is! */ |
| 3276 | swi(Wimp_SendMessage, 17, block, child_handle); |
| 3277 | continue; |
| 3278 | } |
| 3279 | else if (reason == 17 || reason == 18) |
| 3280 | { |
| 3281 | if (block[4] == 0x808c1) |
| 3282 | { |
| 3283 | /* Ack message. */ |
| 3284 | block[3] = block[2]; |
| 3285 | swi(Wimp_SendMessage, 19, block, block[1]); |
| 3286 | out = (char_u *)block + 24; |
| 3287 | old_msg_col = msg_col; |
| 3288 | while (block[5]--) |
| 3289 | { |
| 3290 | c = *out++; |
| 3291 | if (out_file && (c != '\r' || (options & SHELL_FILTER))) |
| 3292 | fputc(c, out_file); |
| 3293 | if ((options & SHELL_FILTER) == 0) |
| 3294 | { |
| 3295 | if (c == 127) |
| 3296 | msg_puts("\b \b"); |
| 3297 | else if (c > 31) |
| 3298 | msg_putchar(c); |
| 3299 | else if (c == 10) |
| 3300 | { |
| 3301 | lines_left = 8; /* Don't do More prompt! */ |
| 3302 | msg_putchar(10); |
| 3303 | } |
| 3304 | } |
| 3305 | } |
| 3306 | /* Flush output to the screen. */ |
| 3307 | windgoto(msg_row, msg_col); |
| 3308 | out_flush(); |
| 3309 | continue; |
| 3310 | } |
| 3311 | } |
| 3312 | process_event(reason, block); |
| 3313 | } |
| 3314 | msg_putchar('\n'); |
| 3315 | settmode(TMODE_RAW); |
| 3316 | if (out_file) |
| 3317 | fclose(out_file); |
| 3318 | return OK; |
| 3319 | } |
| 3320 | |
| 3321 | /* Like strsave(), but stops at any control char */ |
| 3322 | char_u * |
| 3323 | wimp_strsave(str) |
| 3324 | char *str; |
| 3325 | { |
| 3326 | int strlen = 0; |
| 3327 | char_u *retval; |
| 3328 | while (str[strlen] > 31) |
| 3329 | strlen++; |
| 3330 | retval = alloc(strlen + 1); |
| 3331 | if (retval) |
| 3332 | { |
| 3333 | memcpy(retval, str, strlen); |
| 3334 | retval[strlen] = '\0'; |
| 3335 | } |
| 3336 | return retval; |
| 3337 | } |
| 3338 | |
| 3339 | /* If we are saving then pop up a standard RISC OS save box. |
| 3340 | * Otherwise, open a directory viewer on the given directory (and return NULL) |
| 3341 | * The string we return will be freed later. |
| 3342 | */ |
| 3343 | char_u * |
| 3344 | gui_mch_browse(saving, title, dflt, ext, initdir, filter) |
| 3345 | int saving; /* write action */ |
| 3346 | char_u *title; /* title for the window */ |
| 3347 | char_u *dflt; /* default file name */ |
| 3348 | char_u *ext; /* extension added */ |
| 3349 | char_u *initdir; /* initial directory, NULL for current dir */ |
| 3350 | char_u *filter; /* file name filter */ |
| 3351 | { |
| 3352 | char command[256]; |
| 3353 | int length; |
| 3354 | |
| 3355 | if (saving) |
| 3356 | { |
| 3357 | int block[64]; |
| 3358 | int reason; |
| 3359 | int done_save = FALSE; |
| 3360 | char_u *retval = NULL; |
| 3361 | char_u *sprname; |
| 3362 | char_u *fname; |
| 3363 | int dragging_icon = FALSE; |
| 3364 | int filetype; |
| 3365 | |
| 3366 | if (!dflt) |
| 3367 | dflt = "TextFile"; |
| 3368 | |
| 3369 | block[0] = save_window; |
| 3370 | block[1] = 0; |
| 3371 | swi(Wimp_GetIconState, 0, block); |
| 3372 | sprname = ((char_u *) block[7]); |
| 3373 | block[1] = 1; |
| 3374 | swi(Wimp_GetIconState, 0, block); |
| 3375 | fname = ((char *) block[7]); |
| 3376 | strncpy(fname, dflt, 255); |
| 3377 | |
| 3378 | if (xswi(OS_FSControl, 31, curbuf->b_p_oft) & v_flag) |
| 3379 | { |
| 3380 | filetype = 0xfff; |
| 3381 | strcpy(sprname + 5, "xxx"); |
| 3382 | } |
| 3383 | else |
| 3384 | { |
| 3385 | filetype = r2; |
| 3386 | sprintf(sprname + 5, "%03x", filetype); |
| 3387 | } |
| 3388 | |
| 3389 | /* Open the save box */ |
| 3390 | |
| 3391 | swi(Wimp_GetPointerInfo, 0, block); |
| 3392 | swi(Wimp_CreateMenu, 0, save_window, block[0] - 64, block[1] + 64); |
| 3393 | swi(Wimp_SetCaretPosition, save_window, 1, 0, 0, -1, -1); |
| 3394 | |
| 3395 | while (!done_save) |
| 3396 | { |
| 3397 | reason = wimp_poll(1, block); |
| 3398 | switch (reason) |
| 3399 | { |
| 3400 | case 1: |
| 3401 | redraw_window(block); |
| 3402 | break; |
| 3403 | case 2: |
| 3404 | if (block[0] == save_window) |
| 3405 | swi(Wimp_OpenWindow, 0, block); |
| 3406 | else |
| 3407 | ro_open_window(block); |
| 3408 | break; |
| 3409 | case 3: |
| 3410 | done_save = TRUE; |
| 3411 | break; |
| 3412 | case 6: |
| 3413 | if (block[3] != save_window) |
| 3414 | done_save = TRUE; |
| 3415 | else |
| 3416 | { |
| 3417 | int drag_box[4]; |
| 3418 | int min_x, max_y; |
| 3419 | |
| 3420 | switch (block[4]) |
| 3421 | { |
| 3422 | case 0: /* Start drag */ |
| 3423 | block[0] = save_window; |
| 3424 | swi(Wimp_GetWindowState, 0, block); |
| 3425 | min_x = block[1]; |
| 3426 | max_y = block[4]; |
| 3427 | block[1] = 0; |
| 3428 | swi(Wimp_GetIconState, 0, block); |
| 3429 | drag_box[0] = block[2] + min_x; |
| 3430 | drag_box[1] = block[3] + max_y; |
| 3431 | drag_box[2] = block[4] + min_x; |
| 3432 | drag_box[3] = block[5] + max_y; |
| 3433 | |
| 3434 | swi(DragASprite_Start, |
| 3435 | 0x45, |
| 3436 | 1, |
| 3437 | sprname, |
| 3438 | drag_box); |
| 3439 | dragging_icon = TRUE; |
| 3440 | break; |
| 3441 | case 2: /* OK */ |
| 3442 | retval = wimp_strsave(fname); |
| 3443 | done_save = TRUE; |
| 3444 | break; |
| 3445 | case 3: /* Cancel */ |
| 3446 | done_save = TRUE; |
| 3447 | break; |
| 3448 | } |
| 3449 | } |
| 3450 | break; |
| 3451 | case 7: |
| 3452 | if (dragging_icon) |
| 3453 | { |
| 3454 | int len = 0; |
| 3455 | |
| 3456 | dragging_icon = FALSE; |
| 3457 | swi(Wimp_GetPointerInfo, 0, block); |
| 3458 | block[5] = block[3]; |
| 3459 | block[6] = block[4]; |
| 3460 | block[7] = block[0]; |
| 3461 | block[8] = block[1]; |
| 3462 | block[9] = 0; /* Don't know the size */ |
| 3463 | block[10] = filetype; |
| 3464 | |
| 3465 | while (fname[len] > 31) |
| 3466 | { |
| 3467 | if (fname[len] == '.') |
| 3468 | { |
| 3469 | fname += len + 1; |
| 3470 | len = 0; |
| 3471 | } |
| 3472 | else |
| 3473 | len++; |
| 3474 | } |
| 3475 | if (len > 211) |
| 3476 | len = 211; |
| 3477 | |
| 3478 | memcpy(((char_u *) block) + 44, fname, len); |
| 3479 | ((char_u *)block)[44 + len] = '\0'; |
| 3480 | |
| 3481 | block[0] = (len + 48) & 0xfc; |
| 3482 | block[3] = 0; |
| 3483 | block[4] = 1; /* DataSave */ |
| 3484 | |
| 3485 | swi(Wimp_SendMessage, 17, block, block[5], block[6]); |
| 3486 | } |
| 3487 | else |
| 3488 | ro_drag_finished(block); |
| 3489 | break; |
| 3490 | case 8: |
| 3491 | if (block[6] == 13) |
| 3492 | { |
| 3493 | retval = wimp_strsave(fname); |
| 3494 | done_save = TRUE; |
| 3495 | } |
| 3496 | else if (block[6] == 0x1b) |
| 3497 | done_save = TRUE; |
| 3498 | else |
| 3499 | swi(Wimp_ProcessKey, block[6]); |
| 3500 | break; |
| 3501 | case 17: |
| 3502 | case 18: |
| 3503 | if (block[4] == 2 && block[9] != -1) |
| 3504 | { |
| 3505 | /* DataSaveAck from dragging icon. */ |
| 3506 | retval = wimp_strsave(((char_u *) block) + 44); |
| 3507 | done_save = TRUE; |
| 3508 | } |
| 3509 | else if (block[4] == 0x400c9) |
| 3510 | { |
| 3511 | /* MenusDeleted */ |
| 3512 | done_save = TRUE; |
| 3513 | } |
| 3514 | else |
| 3515 | ro_message(block); |
| 3516 | break; |
| 3517 | } |
| 3518 | } |
| 3519 | block[0] = save_window; |
| 3520 | swi(Wimp_CloseWindow, 0, block); |
| 3521 | swi(Wimp_GetCaretPosition, 0, block); |
| 3522 | if (block[0] == -1) |
| 3523 | swi(Wimp_SetCaretPosition, gui.window_handle, -1, 0, 0, -1, -1); |
| 3524 | |
| 3525 | return retval; |
| 3526 | } |
| 3527 | else if (initdir) |
| 3528 | { |
| 3529 | /* Open a directory viewer */ |
| 3530 | length = strlen(initdir); |
| 3531 | |
| 3532 | if (length > 240) |
| 3533 | return NULL; /* Path too long! */ |
| 3534 | |
| 3535 | length = sprintf(command, "Filer_OpenDir %s", initdir); |
| 3536 | while (command[length - 1] == '.') |
| 3537 | length--; |
| 3538 | command[length] = '\0'; |
| 3539 | swi(OS_CLI, command); |
| 3540 | } |
| 3541 | return NULL; |
| 3542 | } |