#include "vim.h"
#include <string.h>
extern int time_of_last_poll;
int task_handle = 0;
int child_handle = 0;
int *wimp_menu = (int *) -1;
int save_window = -1;
int *redraw_block = NULL;
int ro_return_early = FALSE;
int leaf_ref = 0;
char_u *leaf_name = NULL;
int default_columns = 120;
int default_rows = 32;
#define DRAG_FALSE 0
#define DRAG_SELECTION 1
#define DRAG_RESIZE_WINDOW 2
int ro_dragging = DRAG_FALSE;
int drag_button;
int drag_modifiers;
int drag_x_offset;
int drag_y_offset;
int nested_wimp = FALSE;
int changed_mode = FALSE;
int x_eigen_factor;
int y_eigen_factor;
int ro_current_font = 0;
int font_x_offset = 0;
int font_y_offset = 0;
int zap_redraw = FALSE;
int double_height = FALSE;
#define grgb(r,g,b) ((b<<16) + (g<<8) + (r))
#define UNUSED_COLOUR (gui.back_pixel)
#define RO_LOAD_CLIPBOARD -2
static struct
{
int r_flags;
int r_minx;
int r_miny;
int r_maxx;
int r_maxy;
int r_screen;
int r_bpl;
int r_bpp;
int r_charw;
int r_charh;
char *r_caddr;
int r_cbpl;
int r_cbpc;
int r_linesp;
int r_data;
int r_scrollx;
int r_scrolly;
int *r_palette;
int r_for;
int r_bac;
char *r_workarea;
int r_magx;
int r_magy;
int r_xsize;
int r_ysize;
int r_mode;
}
zap_redraw_block;
static int zap_redraw_initialised = FALSE;
static int zap_redraw_update_colours;
static int zap_redraw_colours[2];
static int zap_redraw_palette[16];
#define ZAP_NORMAL 0
#define ZAP_BOLD 1
#define ZAP_ITALIC 2
#define ZAP_BITALIC 3
#define ZAP_STYLES 4
static char *zap_file[ZAP_STYLES] = {NULL, NULL, NULL, NULL};
static char *zap_caddr[ZAP_STYLES] = {NULL, NULL, NULL, NULL};
static void ro_remove_menu(int *menu);
int
ro_zap_redraw_initialise()
{
int bytes_per_bitmap_char;
int first, last;
int i;
if (!zap_redraw_initialised)
{
zap_redraw_block.r_workarea = NULL;
zap_redraw_initialised = TRUE;
}
zap_redraw_block.r_flags = 0x0;
zap_redraw_block.r_screen = 0;
zap_redraw_block.r_charw = ((int *) zap_file[ZAP_NORMAL])[2];
zap_redraw_block.r_charh = ((int *) zap_file[ZAP_NORMAL])[3];
zap_redraw_block.r_linesp = 0;
zap_redraw_block.r_for = 1;
zap_redraw_block.r_bac = 0;
zap_redraw_block.r_palette = zap_redraw_palette;
if (zap_redraw_block.r_workarea != NULL)
free(zap_redraw_block.r_workarea);
zap_redraw_block.r_workarea = (char*) malloc(128);
if (!zap_redraw_block.r_workarea)
return FAIL;
if (xswi(ZapRedraw_ReadVduVars, 0, &zap_redraw_block) & v_flag)
return FAIL;
swi(ZapRedraw_CachedCharSize, zap_redraw_block.r_bpp, 0,
zap_redraw_block.r_charw, zap_redraw_block.r_charh);
zap_redraw_block.r_cbpl = r2;
zap_redraw_block.r_cbpc = r3;
if (zap_redraw_block.r_workarea != NULL)
free(zap_redraw_block.r_workarea);
zap_redraw_block.r_workarea = (char*) malloc(128 + zap_redraw_block.r_cbpl);
if (!zap_redraw_block.r_workarea)
return FAIL;
bytes_per_bitmap_char = (zap_redraw_block.r_charw * zap_redraw_block.r_charh + 7) / 8;
for (i = 0; i < ZAP_STYLES; i++)
{
first = ((int *) zap_file[i])[4];
last = ((int *) zap_file[i])[5];
if (last > 255)
last = 255;
vim_free(zap_caddr[i]);
if (zap_file[i])
zap_caddr[i] = (char*) malloc(zap_redraw_block.r_cbpc * 256);
else
zap_caddr[i] = NULL;
if (zap_caddr[i])
{
zap_redraw_block.r_caddr = zap_caddr[i];
swi(ZapRedraw_ConvertBitmap, 0, &zap_redraw_block,
first, last,
zap_file[i] + 0x20
- first * bytes_per_bitmap_char);
}
}
if (!zap_caddr[ZAP_NORMAL])
{
zap_redraw = FALSE;
return FAIL;
}
zap_redraw_update_colours = TRUE;
return OK;
}
int
ro_zap_redraw_draw_string(x, y, string, length, flags, clip)
int x;
int y;
char *string;
int length;
int flags;
int *clip;
{
char redraw_data[1024];
int clip_minx;
int clip_miny;
int clip_maxx;
int clip_maxy;
int os_xshift = zap_redraw_block.r_magx;
int os_yshift = zap_redraw_block.r_magy;
if (flags & DRAW_TRANSP)
return flags;
if (flags & DRAW_BOLD)
{
if (flags & DRAW_ITALIC && zap_caddr[ZAP_BITALIC])
zap_redraw_block.r_caddr = zap_caddr[ZAP_BITALIC];
else
zap_redraw_block.r_caddr = zap_caddr[ZAP_BOLD];
}
else
{
if (flags & DRAW_ITALIC)
zap_redraw_block.r_caddr = zap_caddr[ZAP_ITALIC];
else
zap_redraw_block.r_caddr = zap_caddr[ZAP_NORMAL];
}
if (!zap_redraw_block.r_caddr)
{
zap_redraw_block.r_caddr = zap_caddr[ZAP_NORMAL];
flags |= DRAW_UNDERL;
}
if (double_height)
zap_redraw_block.r_flags = 1 << 1;
else
zap_redraw_block.r_flags = 0;
if (zap_redraw_update_colours)
{
swi(ZapRedraw_CreatePalette, 2,
&zap_redraw_block,
zap_redraw_colours,
zap_redraw_block.r_palette, 2);
zap_redraw_update_colours = FALSE;
}
zap_redraw_block.r_minx = x >> os_xshift;
zap_redraw_block.r_miny = zap_redraw_block.r_ysize - (y >> os_yshift);
zap_redraw_block.r_maxx = (x + length * gui.char_width) >> os_xshift;
zap_redraw_block.r_maxy = zap_redraw_block.r_ysize - ((y - gui.char_height) >> os_yshift);
clip_minx = clip[0] >> os_xshift;
clip_miny = zap_redraw_block.r_ysize - (clip[3] >> os_yshift);
clip_maxx = clip[2] >> os_xshift;
clip_maxy = zap_redraw_block.r_ysize - (clip[1] >> os_yshift);
if (zap_redraw_block.r_minx < clip_minx)
{
zap_redraw_block.r_scrollx = clip_minx - zap_redraw_block.r_minx;
zap_redraw_block.r_minx = clip_minx;
}
else
zap_redraw_block.r_scrollx = 0;
if (zap_redraw_block.r_miny < clip_miny)
{
zap_redraw_block.r_scrolly = clip_miny - zap_redraw_block.r_miny;
zap_redraw_block.r_miny = clip_miny;
}
else
zap_redraw_block.r_scrolly = 0;
if (zap_redraw_block.r_maxx > clip_maxx)
zap_redraw_block.r_maxx = clip_maxx;
if (zap_redraw_block.r_maxy > clip_maxy)
zap_redraw_block.r_maxy = clip_maxy;
if (length > (sizeof(redraw_data) - 2 * 4 - 2))
length = sizeof(redraw_data) - 2 * 4 - 2;
((int*) redraw_data)[0] = 2 * 4;
((int*) redraw_data)[1] = 0;
strncpy(redraw_data + 2 * 4, string, length);
redraw_data[2 * 4 + length + 0] = '\0';
redraw_data[2 * 4 + length + 1] = '\x2';
zap_redraw_block.r_data = (int) redraw_data;
swi(ZapRedraw_RedrawArea, 0, &zap_redraw_block);
return flags;
}
void
gui_mch_prepare(int *argc, char **argv)
{
int arg = 1;
while (arg < *argc - 1)
{
if (strcmp(argv[arg], "--rows") == 0 || strcmp(argv[arg], "--columns") == 0)
{
int value;
value = atoi(argv[arg + 1]);
if (argv[arg][2] == 'r')
default_rows = value;
else
default_columns = value;
*argc -= 2;
if (*argc > arg)
mch_memmove(&argv[arg], &argv[arg + 2], (*argc - arg)
* sizeof(char *));
}
else
arg++;
}
}
void
ro_die(error)
char_u *error;
{
swi(Wimp_ReportError, error, 5, "GVim");
exit(EXIT_FAILURE);
}
void
ro_measure_tools()
{
int block[10];
int vdu[] = { 4, 5, -1};
int test_window[] =
{
-100, -100,
-50, -50,
0, 0,
-1,
0xd0800150,
0xff070207,
0x000c0103,
0, -0x4000,
0x4000, 0,
0x00000000,
0 << 12,
1,
0x00010001,
0, 0, 0,
0
};
int inner_max_x, inner_min_y;
swi(Wimp_CreateWindow, 0, test_window);
block[0] = r0;
swi(Wimp_OpenWindow, 0, block);
inner_max_x = block[3];
inner_min_y = block[2];
swi(Wimp_GetWindowOutline, 0, block);
gui.scrollbar_width = block[3] - inner_max_x;
gui.scrollbar_height = inner_min_y - block[2];
swi(Wimp_DeleteWindow, 0, block);
swi(OS_ReadVduVariables, vdu, vdu);
x_eigen_factor = vdu[0];
y_eigen_factor = vdu[1];
}
int
ro_load_template(str_name, title, title_size)
char_u *str_name;
char_u **title;
int *title_size;
{
int *window;
char *data;
int name[4];
strcpy( (char *) name, str_name);
if (xswi(Wimp_LoadTemplate, 0, 0, 0, 0, -1, name, 0) & v_flag)
ro_die( (char *) r0);
window = malloc(r1);
data = malloc(r2);
if (window == NULL || data == NULL)
ro_die("\0\0\0\0Out of memory - Can't load templates");
swi(Wimp_LoadTemplate, 0,
window,
data,
data + r2 + 1,
-1,
name, 0);
if (r6 == 0)
ro_die("\0\0\0\0Can't find window in Templates file");
if (xswi(Wimp_CreateWindow, 0, window) & v_flag)
ro_die( (char *) r0);
if (title)
*title = (char_u *) window[18];
if (title_size)
*title_size = window[20];
free(window);
return r0;
}
int
gui_mch_init_check()
{
return OK;
}
int
gui_mch_init()
{
int messages[] = {
1, 2, 3, 4,
8,
0xf,
0x10,
0x400c1,
0x400c3,
0x400c9,
0x808c1,
0x808c2,
0x808c3,
0x808c4,
0};
swi(Wimp_ReadSysInfo, 3);
if (r0 == 0)
swi(Wimp_CommandWindow, 0);
if (xswi(Wimp_Initialise, 310, 0x4b534154, "GVim", messages) & v_flag)
return FAIL;
nested_wimp = r0 >= 397;
task_handle = r1;
if (xswi(Wimp_OpenTemplate, 0, "Vim:Templates") & v_flag)
ro_die( (char *) r0);
gui.window_handle = ro_load_template("editor",
&gui.window_title,
&gui.window_title_size);
save_window = ro_load_template("save", NULL, NULL);
swi(Wimp_CloseTemplate);
gui.norm_pixel = gui.def_norm_pixel;
gui.back_pixel = gui.def_back_pixel;
set_normal_colors();
gui_check_colors();
highlight_gui_started();
gui.num_cols = Columns = default_columns;
gui.num_rows = Rows = default_rows;
ro_measure_tools();
return OK;
}
void
gui_mch_new_colors()
{
}
int
gui_mch_open(void)
{
int block[10];
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
block[7] = -1;
swi(Wimp_OpenWindow, 0, block);
swi(Wimp_SetCaretPosition, gui.window_handle, -1, 0, 0, -1, -1);
if (gui_win_x != -1 && gui_win_y != -1)
gui_mch_set_winpos(gui_win_x, gui_win_y);
return OK;
}
void
gui_mch_exit(int rc)
{
int block[64];
block[0] = gui.window_handle;
swi(Wimp_CloseWindow, 0, block);
if (child_handle)
{
block[0] = 20;
block[3] = 0;
block[4] = 0;
if ((xswi(Wimp_SendMessage, 17, block, child_handle) & v_flag) == 0)
{
while (child_handle)
{
process_event(wimp_poll(1, block), block);
}
}
}
exit(rc);
}
int
gui_mch_get_winpos(int *x, int *y)
{
return FAIL;
}
void
gui_mch_set_winpos(int x, int y)
{
}
void
gui_mch_set_shellsize(width, height, min_width, min_height, base_width, base_height, direction)
int width;
int height;
int min_width;
int min_height;
int base_width;
int base_height;
int direction;
{
int s_width, s_height;
int block[] = {
gui.window_handle,
0,
-height + 1,
width,
1};
gui_mch_get_screen_dimensions(&s_width, &s_height);
s_width -= base_width;
s_height -= base_height;
swi(Wimp_GetWindowState, 0, block);
block[3] = block[1] + width;
block[2] = block[4] - height;
if (block[3] > s_width)
{
block[3] = s_width;
block[1] = block[3] - width;
}
if (block[2] < gui.scrollbar_height)
{
block[2] = gui.scrollbar_height;
block[4] = block[2] + height;
}
swi(Wimp_OpenWindow, 0, block);
swi(Wimp_ForceRedraw, gui.window_handle, 0, -height, width, 0);
}
void
gui_mch_get_screen_dimensions(int *screen_w, int *screen_h)
{
int block[] = {4, 5, 11, 12, -1};
swi(OS_ReadVduVariables, block, block);
*screen_w = (block[2] + 1) << block[0];
*screen_h = (block[3] + 1) << block[1];
}
int
ro_get_font(fullname, weight)
char_u *fullname;
int weight;
{
char_u *arg;
char_u font[41];
int width = -1;
int height = -1;
int name_len;
int i;
char_u c;
for (i = 0; i < 39;)
{
c = fullname[i];
if (c == ':' || c == NUL || c == '.')
break;
font[i++] = c;
}
arg = strchr(fullname + i, ':');
while (arg)
{
switch (*++arg)
{
case 'h':
height = strtol(arg + 1, (char **) &arg, 10);
break;
case 'w':
width = strtol(arg + 1, (char **) &arg, 10);
break;
case 'b':
weight |= 1;
break;
case 'i':
weight |= 2;
break;
default:
return 0;
}
arg = strchr(arg, ':');
}
if ((weight & 1) && i < 35)
{
strncpy(font + i, ".Bold", 5);
i += 5;
}
else
{
while (i < 39)
{
c = fullname[i];
if (c == ':' || c == NUL)
break;
font[i++] = c;
}
}
if ((weight & 2) && i < 32)
{
strncpy(font + i, ".Oblique", 8);
i += 8;
}
font[i] = 0;
if (height < 1 && width < 1)
height = width = 10;
else if (height < 1)
height = width;
else if (width < 1)
width = height;
if (xswi(Font_FindFont, 0, font, width << 4, height << 4, 0, 0) & v_flag)
return NOFONT;
return r0;
}
char *
zap_load_file(name, style)
char_u *name;
char_u *style;
{
char_u fname[256];
char_u *file;
if (strlen(name) + strlen(style) > 254)
return NULL;
sprintf(fname, "%s.%s", name, style);
if (xswi(OS_File, 13, fname, 0, 0, "VimFonts:") & v_flag || r0 != 1)
return NULL;
file = (char *) alloc(r4);
if (!file)
return NULL;
if (xswi(OS_File, 12, fname, file, 0, "VimFonts:") & v_flag)
return NULL;
if (strncmp(file, "ZapFont\015", 8) == 0)
return file;
free(file);
return NULL;
}
int
zap_load_font(name)
char_u *name;
{
int i;
for (i = 0; i < ZAP_STYLES; i++)
{
vim_free(zap_file[i]);
zap_file[i] = NULL;
}
if (name && *name == '!')
{
name++;
double_height = TRUE;
}
else
double_height = FALSE;
if (name && *name)
{
zap_file[ZAP_NORMAL] = zap_load_file(name, "0");
if (!zap_file[ZAP_NORMAL])
return FAIL;
zap_file[ZAP_BOLD] = zap_load_file(name, "B");
zap_file[ZAP_ITALIC] = zap_load_file(name, "I");
zap_file[ZAP_BITALIC] = zap_load_file(name, "IB");
}
else
{
int *header;
char workarea[16];
char *old_wa;
header = (int *) alloc(0x20 + 8 * 256);
if (header == NULL)
return FAIL;
zap_file[ZAP_NORMAL] = (char *) header;
header[2] = 8;
header[3] = 8;
header[4] = 0;
header[5] = 255;
header[6] = header[7] = 0;
old_wa = zap_redraw_block.r_workarea;
zap_redraw_block.r_workarea = workarea;
swi(ZapRedraw_ReadSystemChars, zap_file[ZAP_NORMAL] + 0x20, &zap_redraw_block);
zap_redraw_block.r_workarea = old_wa;
}
return ro_zap_redraw_initialise();
}
int
gui_mch_init_font(char_u *font_name, int fontset)
{
int new_handle = 0;
if (font_name[0] == '!')
{
if (zap_load_font(font_name + 1))
zap_redraw = TRUE;
else
{
EMSG2(_("E610: Can't load Zap font '%s'"), font_name);
font_name = "System";
zap_redraw = FALSE;
}
}
else
{
zap_redraw = FALSE;
if (font_name)
{
new_handle = ro_get_font(font_name, 0);
if (!new_handle)
return FAIL;
}
else
font_name = "System";
}
gui_mch_free_font(gui.norm_font);
gui.norm_font = new_handle;
gui.char_ascent = 0;
if (new_handle)
{
swi(Font_ReadInfo, new_handle);
gui.char_width = r3 - r1;
gui.char_height = r4 - r2;
font_x_offset = -r1;
font_y_offset = -r4;
gui_mch_free_font(gui.bold_font);
gui.bold_font = ro_get_font(font_name, 1);
gui_mch_free_font(gui.ital_font);
gui.ital_font = ro_get_font(font_name, 2);
gui_mch_free_font(gui.boldital_font);
gui.boldital_font = ro_get_font(font_name, 3);
}
else
{
if (zap_redraw)
{
gui.char_width = zap_redraw_block.r_charw << zap_redraw_block.r_magx;
gui.char_height = zap_redraw_block.r_charh << zap_redraw_block.r_magy;
if (double_height)
gui.char_height <<= 1;
}
else
{
gui.char_width = 16;
gui.char_height = 32;
}
gui_mch_free_font(gui.bold_font);
gui.bold_font = 0;
gui_mch_free_font(gui.ital_font);
gui.ital_font = 0;
gui_mch_free_font(gui.boldital_font);
gui.boldital_font = 0;
}
hl_set_font_name(font_name);
must_redraw = CLEAR;
return OK;
}
int
gui_mch_adjust_charheight()
{
return FAIL;
}
GuiFont
gui_mch_get_font(name, giveErrorIfMissing)
char_u *name;
int giveErrorIfMissing;
{
int handle;
if (!name)
return NOFONT;
handle = ro_get_font(name, 0);
if (!handle)
{
if (giveErrorIfMissing)
EMSG2(_("E611: Can't use font %s"), name);
return NOFONT;
}
return handle;
}
#if defined(FEAT_EVAL) || defined(PROTO)
char_u *
gui_mch_get_fontname(font, name)
GuiFont font;
char_u *name;
{
if (name == NULL)
return NULL;
return vim_strsave(name);
}
#endif
void
gui_mch_set_font(GuiFont font)
{
ro_current_font = font;
if (font)
{
swi(Font_SetFont, font);
}
}
void
gui_mch_free_font(GuiFont font)
{
if (font)
swi(Font_LoseFont, font);
}
guicolor_T
gui_mch_get_color(char_u *name)
{
int i;
struct colour
{
char_u *name;
guicolor_T value;
} colours[] =
{
{ "Red", grgb(255, 0, 0) },
{ "LightRed", grgb(255, 0, 0) },
{ "DarkRed", grgb(139, 0, 0) },
{ "Green", grgb(50, 200, 50) },
{ "LightGreen", grgb(144, 238, 144) },
{ "DarkGreen", grgb(0, 100, 0) },
{ "SeaGreen", grgb(46, 139, 87) },
{ "Blue", grgb(0, 0, 255) },
{ "LightBlue", grgb(173, 216, 230) },
{ "DarkBlue", grgb(0, 0, 139) },
{ "SlateBlue", grgb(160, 90, 205) },
{ "Cyan", grgb(0, 255, 255) },
{ "LightCyan", grgb(224, 255, 255) },
{ "DarkCyan", grgb(0, 139, 139) },
{ "Magenta", grgb(255, 0, 255) },
{ "LightMagenta", grgb(255, 224, 255) },
{ "DarkMagenta", grgb(139, 0, 139) },
{ "Yellow", grgb(255, 255, 0) },
{ "LightYellow", grgb(255, 255, 224) },
{ "DarkYellow", grgb(139, 139, 0) },
{ "Brown", grgb(165, 42, 42) },
{ "Gray", grgb(190, 190, 190) },
{ "Grey", grgb(190, 190, 190) },
{ "LightGray", grgb(211, 211, 211) },
{ "LightGrey", grgb(211, 211, 211) },
{ "DarkGray", grgb(169, 169, 169) },
{ "DarkGrey", grgb(169, 169, 169) },
{ "Gray10", grgb(26, 26, 26) },
{ "Grey10", grgb(26, 26, 26) },
{ "Gray20", grgb(51, 51, 51) },
{ "Grey20", grgb(51, 51, 51) },
{ "Gray30", grgb(77, 77, 77) },
{ "Grey30", grgb(77, 77, 77) },
{ "Gray40", grgb(102, 102, 102) },
{ "Grey40", grgb(102, 102, 102) },
{ "Gray50", grgb(127, 127, 127) },
{ "Grey50", grgb(127, 127, 127) },
{ "Gray60", grgb(153, 153, 153) },
{ "Grey60", grgb(153, 153, 153) },
{ "Gray70", grgb(179, 179, 179) },
{ "Grey70", grgb(179, 179, 179) },
{ "Gray80", grgb(204, 204, 204) },
{ "Grey80", grgb(204, 204, 204) },
{ "Gray90", grgb(229, 229, 229) },
{ "Grey90", grgb(229, 229, 229) },
{ "Black", grgb(0, 0, 0) },
{ "White", grgb(255, 255, 255) },
{ "Orange", grgb(255, 165, 0) },
{ "Purple", grgb(160, 32, 240) },
{ "Violet", grgb(238, 130, 238) },
{NULL, 0}
};
if (name[0] == '#')
{
char *end;
int c;
c = strtol(name + 1, &end, 16);
return (guicolor_T) ((c >> 16) & 0xff) | (c & 0xff00) | ((c & 0xff) << 16);
}
for (i = 0; colours[i].name != NULL; i++)
{
if (STRICMP(name, colours[i].name) == 0)
return colours[i].value;
}
if (strnicmp(name, "grey", 4) == 0 || strnicmp(name, "gray", 4) == 0)
{
int level = (255 * atoi(name + 4)) / 100;
return (guicolor_T) grgb(level, level, level);
}
return INVALCOLOR;
}
void
gui_mch_set_colors(guicolor_T fg, guicolor_T bg)
{
zap_redraw_colours[0] = bg << 8;
zap_redraw_colours[1] = fg << 8;
zap_redraw_update_colours = TRUE;
swi(ColourTrans_ReturnGCOL, fg << 8);
gui.fg_colour = r0;
swi(ColourTrans_ReturnGCOL, bg << 8);
gui.bg_colour = r0;
if (ro_current_font)
swi(ColourTrans_SetFontColours, 0, bg << 8, fg << 8, 14);
}
void
ro_draw_string(x, y, s, len, flags, clip)
int x;
int y;
char_u *s;
int len;
int flags;
int* clip;
{
if (ro_current_font)
{
int fx;
int flen = len;
if (flags & DRAW_ITALIC && !gui.ital_font)
flags |= DRAW_UNDERL;
if ((flags & DRAW_TRANSP) == 0)
{
swi(ColourTrans_SetColour, gui.bg_colour, 0, 0, 0, 0);
swi(OS_Plot, 4, x, y - gui.char_height);
swi(OS_Plot, 96 + 5, x + len * gui.char_width - 1, y - 1);
}
fx = x + font_x_offset;
while (flen--)
{
swi(Font_Paint, 0, s++, 0x90, fx, y + font_y_offset, 0, 0, 1);
fx += gui.char_width;
}
}
else
{
if (zap_redraw)
{
flags = ro_zap_redraw_draw_string(x, y, s, len, flags, clip);
}
else
{
if (flags & DRAW_ITALIC)
flags |= DRAW_UNDERL;
if ((flags & DRAW_TRANSP) == 0)
{
swi(ColourTrans_SetColour, gui.bg_colour, 0, 0, 0, 0);
swi(OS_Plot, 4, x, y - gui.char_height);
swi(OS_Plot, 96 + 5, x + len * gui.char_width - 1, y - 1);
}
swi(OS_Plot, 4,
x,
y - 1);
swi(ColourTrans_SetColour, gui.fg_colour, 0, 0, 0, 0);
swi(OS_WriteN, s, len);
if (flags & DRAW_BOLD)
{
swi(OS_Plot, 4, x + (1 << x_eigen_factor), y - 1);
swi(OS_WriteN, s, len);
}
}
}
if (flags & DRAW_UNDERL)
{
if (ro_current_font || zap_redraw)
swi(ColourTrans_SetColour, gui.fg_colour, 0, 0, 0, 0);
swi(OS_Plot, 4, x, y - gui.char_height);
swi(OS_Plot, 1, gui.char_width * len, 0);
}
}
void
gui_mch_draw_string(int row, int col, char_u *s, int len, int flags)
{
int x, y;
x = col * gui.char_width;
y = -row * gui.char_height;
if (redraw_block)
{
ro_draw_string(x + redraw_block[1], y + redraw_block[4],
s, len, flags, &redraw_block[7]);
}
else
{
int block[44];
block[0] = gui.window_handle;
block[1] = x;
block[2] = y - gui.char_height;
block[3] = (col + len) * gui.char_width;
block[4] = y;
swi(Wimp_UpdateWindow, 0, block);
while (r0)
{
ro_draw_string(x + block[1], y + block[4],
s, len, flags, &block[7]);
swi(Wimp_GetRectangle, 0, block);
}
}
}
int
gui_mch_haskey(char_u *name)
{
return FAIL;
}
void
gui_mch_beep(void)
{
swi(OS_WriteI + 7);
}
void
gui_mch_flash(int msec)
{
}
void
plot_rectangle(plot, colour, minx, miny, maxx, maxy)
int plot;
int colour;
int minx;
int miny;
int maxx;
int maxy;
{
if (redraw_block)
{
swi(ColourTrans_SetColour, colour, 0, 0, 0, 0);
swi(OS_Plot, 4, minx + redraw_block[1], miny + redraw_block[4]);
swi(OS_Plot, plot, maxx + redraw_block[1], maxy + redraw_block[4]);
}
else
{
int block[44];
block[0] = gui.window_handle;
block[1] = minx;
block[2] = miny;
block[3] = maxx + 1;
block[4] = maxy + 1;
swi(Wimp_UpdateWindow, 0, block);
while (r0)
{
swi(ColourTrans_SetColour, colour, 0, 0, 0, 0);
swi(OS_Plot, 4, minx + block[1], miny + block[4]);
swi(OS_Plot, plot, maxx + block[1], maxy + block[4]);
swi(Wimp_GetRectangle, 0, block);
}
}
}
void
gui_mch_invert_rectangle(int r, int c, int nr, int nc)
{
plot_rectangle(96 + 6, 0, FILL_X(c), -FILL_Y(r + nr), FILL_X(c + nc), -FILL_Y(r));
}
void
gui_mch_iconify(void)
{
}
#if defined(FEAT_EVAL) || defined(PROTO)
void
gui_mch_set_foreground()
{
}
#endif
void
draw_hollow(w, h)
int w;
int h;
{
swi(OS_Plot, 1, w - 1, 0);
swi(OS_Plot, 1, 0, 1 - h);
swi(OS_Plot, 1, 1 - w, 0);
swi(OS_Plot, 1, 0, h - 1);
}
void
gui_mch_draw_hollow_cursor(guicolor_T colour)
{
int x = FILL_X(gui.cursor_col);
int y = -FILL_Y(gui.cursor_row);
if (redraw_block == NULL)
{
int block[11];
block[0] = gui.window_handle;
block[1] = x;
block[2] = y - gui.char_height;
block[3] = x + gui.char_width;
block[4] = y;
swi(Wimp_UpdateWindow, 0, block);
while (r0)
{
swi(ColourTrans_SetGCOL, colour << 8, 0, 0, 0, 0);
swi(OS_Plot, 4, x + block[1], y + block[4] - 1);
draw_hollow(gui.char_width, gui.char_height);
swi(Wimp_GetRectangle, 0, block);
}
}
else
{
swi(ColourTrans_SetGCOL, colour << 8, 0, 0, 0, 0);
swi(OS_Plot, 4, x + redraw_block[1], y + redraw_block[4] - 1);
draw_hollow(gui.char_width, gui.char_height);
}
}
void
gui_mch_draw_part_cursor(w, h, colour)
int w;
int h;
guicolor_T colour;
{
int x = FILL_X(gui.cursor_col);
int y = -FILL_Y(gui.cursor_row);
swi(ColourTrans_ReturnGCOL, colour << 8);
plot_rectangle(96 + 5, r0, x, y - h, x + w - 1, y - 1);
}
void
gui_mch_update(void)
{
int block[64];
int reason;
swi(OS_ReadMonotonicTime);
if ((r0 - time_of_last_poll) < 50)
return;
reason = wimp_poll(0, block);
if (reason)
process_event(reason, block);
ro_return_early = FALSE;
}
void
redraw_window(block)
int *block;
{
int x, y;
int width, height;
int blank_col;
swi(ColourTrans_ReturnGCOL, UNUSED_COLOUR << 8, 0, 0, 1<<7, 0);
blank_col = r0;
swi(Wimp_RedrawWindow, 0, block);
redraw_block = block;
while (r0)
{
x = block[7] - block[1];
y = block[4] - block[10];
width = block[9] - block[7];
height = block[10] - block[8];
if (height + y > Rows * gui.char_height)
{
plot_rectangle(96 + 5, blank_col,
0, block[8] - block[4],
block[9] - block[1], -FILL_Y(Rows) - 1);
height = Rows * gui.char_height;
}
if (width + x> Columns * gui.char_width)
{
plot_rectangle(96 + 5, blank_col,
FILL_X(Columns), block[8] - block[4],
block[9] - block[1], 0);
width = Columns * gui.char_width;
}
gui_redraw(x , y, width, height);
swi(Wimp_GetRectangle, 0, block);
}
redraw_block = NULL;
}
void
ro_prequit(block)
int *block;
{
if (!ro_ok_to_quit())
{
block[3] = block[2];
swi(Wimp_SendMessage, 19, block, block[1]);
}
}
int
ro_ok_to_quit()
{
int old_confirm = cmdmod.confirm;
cmdmod.confirm = FALSE;
if (check_changed_any(FALSE))
{
swi(Wimp_ReportError,
"\0\0\0\0Vim contains unsaved data - quit anyway?",
0x17,
"Vim");
cmdmod.confirm = old_confirm;
if (r1 != 1)
return FALSE;
}
cmdmod.confirm = old_confirm;
return TRUE;
}
void
ro_quit()
{
exiting = TRUE;
getout(0);
exiting = FALSE;
setcursor();
out_flush();
}
void
ro_press(a, b, modifier)
char a;
char b;
int modifier;
{
char_u buf[6];
int vim_mod;
int key;
vim_mod = ((modifier & 0x10) ? MOD_MASK_SHIFT : 0)
| ((modifier & 0x20) ? MOD_MASK_CTRL : 0);
key = simplify_key(TERMCAP2KEY(a, b), &vim_mod);
buf[3] = CSI;
buf[4] = KEY2TERMCAP0(key);
buf[5] = KEY2TERMCAP1(key);
if (vim_mod)
{
buf[0] = CSI;
buf[1] = KS_MODIFIER;
buf[2] = vim_mod;
add_to_input_buf(buf, 6);
}
else
add_to_input_buf(buf + 3, 3);
}
void
ro_insert_key(code)
char_u *code;
{
char a = code[0];
char b = code[1];
int base, modifier;
if (a == 3 && ctrl_c_interrupts)
got_int = TRUE;
if (a > 31 && a < 127)
{
add_to_input_buf(code, 1);
return;
}
switch (b)
{
case 0:
switch (a)
{
case 0x1e:
ro_press('k','h', 0);
return;
case 0x7f:
ro_press('k','D', 0);
return;
case CSI:
{
char_u string[3] = {CSI, KS_EXTRA, KE_CSI};
add_to_input_buf(string, 3);
return;
}
default:
add_to_input_buf(code, 1);
return;
}
case 1:
if ((a & 0xcf) == 0xcc)
{
swi(Wimp_ProcessKey, a | 0x100);
return;
}
base = a & 0xcf;
modifier = a & 0x30;
switch (base)
{
case 0x8a:
add_to_input_buf("\011", 1);
return;
case 0x8b:
return ro_press('@', '7', modifier);
case 0x8c:
return ro_press('k', 'l', modifier);
case 0x8d:
return ro_press('k', 'r', modifier);
case 0x8e:
if (modifier & 0x10)
return ro_press('k', 'N', modifier ^ 0x10);
else
return ro_press('k', 'd', modifier);
case 0x8f:
if (modifier & 0x10)
return ro_press('k', 'P', modifier ^ 0x10);
else
return ro_press('k', 'u', modifier);
case 0xca:
return ro_press('k', ';', modifier);
case 0xcb:
return ro_press('F', '1', modifier);
case 0xcd:
return ro_press('k', 'I', modifier);
default:
if (base > 0x80 && base < 0x18a)
{
return ro_press('k', '0' + (base & 15), modifier);
}
}
}
}
void
ro_mouse(block)
int *block;
{
int x, y, button, vim_button;
int modifiers = 0;
int min_x, min_y;
int max_x, max_y;
if (block[3] != gui.window_handle || ro_dragging)
return;
x = block[0];
y = block[1];
button = block[2];
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
min_x = block[1];
min_y = block[2];
max_x = block[3];
max_y = block[4];
if (block[3] - x < gui.scrollbar_width)
{
if (button & 0x444)
{
int front_block[10];
front_block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, front_block);
front_block[7] = -1;
ro_open_main(front_block);
}
block[0] = gui.window_handle;
block[1] = 7;
block[2] = block[4] = 0;
block[3] = block[5] = 0;
drag_x_offset = max_x - x;
drag_y_offset = min_y - y;
block[6] = min_x +
gui.scrollbar_width * 2 +
MIN_COLUMNS * gui.char_width;
block[7] = 0;
gui_mch_get_screen_dimensions(&block[8], &block[9]);
block[9] = max_y -
4 * gui.char_height -
gui.scrollbar_height;
swi(Wimp_DragBox, 0, block);
ro_dragging = DRAG_RESIZE_WINDOW;
drag_button = vim_button;
drag_modifiers = modifiers;
return;
}
if (button & 0x111)
vim_button = MOUSE_RIGHT;
else if (button & 0x222)
vim_button = MOUSE_MIDDLE;
else
vim_button = MOUSE_LEFT;
swi(OS_Byte, 121, 0x80);
if (r1 == 0xff)
modifiers |= MOUSE_SHIFT;
swi(OS_Byte, 121, 0x81);
if (r1 == 0xff)
modifiers |= MOUSE_CTRL;
swi(OS_Byte, 121, 0x82);
if (r1 == 0xff)
modifiers |= MOUSE_ALT;
if (button == 2)
{
modifiers ^= MOUSE_SHIFT;
if (modifiers && MOUSE_SHIFT)
{
vimmenu_T main;
main.dname = (char_u *) "Vim";
main.children = root_menu;
gui_mch_show_popupmenu(&main);
return;
}
}
swi(Wimp_SetCaretPosition, gui.window_handle, -1, 0, 0, -1, -1);
if (button & 0xf0)
{
block[1] = 7;
block[2] = block[4] = x;
block[3] = block[5] = y;
block[6] = 0;
block[7] = 0;
gui_mch_get_screen_dimensions(&block[8], &block[9]);
drag_x_offset = drag_y_offset = 0;
swi(Wimp_DragBox, 0, block);
ro_dragging = DRAG_SELECTION;
drag_button = vim_button;
drag_modifiers = modifiers;
vim_button |= MOUSE_DRAG;
}
gui_send_mouse_event(
vim_button,
x - min_x,
max_y - y,
button & 0xf ? TRUE : FALSE,
modifiers);
}
void
ro_continue_drag(block)
int *block;
{
int x, y;
swi(Wimp_GetPointerInfo, 0, block);
x = block[0] + drag_x_offset;
y = block[1] + drag_y_offset;
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
if (ro_dragging == DRAG_RESIZE_WINDOW)
{
block[2] = y;
block[3] = x;
ro_open_main(block);
}
else
{
gui_send_mouse_event(
drag_button | MOUSE_DRAG,
x - block[1],
block[4] - y,
FALSE,
drag_modifiers);
}
}
void
ro_drag_finished(block)
int *block;
{
int x;
int y;
int width, height;
swi(Wimp_GetPointerInfo, 0, block);
x = block[0] + drag_x_offset;
y = block[1] + drag_y_offset;
if (ro_dragging == DRAG_RESIZE_WINDOW)
{
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
block[2] = y;
block[3] = x;
ro_open_main(block);
width = (block[3] - block[1]);
height = (block[4] - block[2]);
swi(Wimp_ForceRedraw, gui.window_handle, 0, -height, width, 0);
gui_resize_shell(width, height);
}
else
{
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
gui_send_mouse_event(
MOUSE_RELEASE,
x - block[1],
block[4] - y,
FALSE,
drag_modifiers);
}
ro_dragging = DRAG_FALSE;
}
void
ro_dataload(block)
int *block;
{
char_u new_path[MAXPATHL];
char_u *path = ((char_u *) block) + 44;
int scrap = FALSE;
if (block[3] == leaf_ref && leaf_name)
scrap = TRUE;
switch (get_real_state() & 0xff)
{
case INSERT:
case CMDLINE:
case CMDLINE+LANGMAP:
swi(OS_Byte, 121, 0x80);
if (r1 == 0xff)
{
ins_typebuf(" ", REMAP_NONE, 0, TRUE, FALSE);
ins_typebuf(path, REMAP_NONE, 0, TRUE, FALSE);
ro_return_early = TRUE;
}
else
swi(Wimp_ReportError,
"\0\0\0\0Sorry, you can only load text in normal mode", 5, "Vim");
break;
case NORMAL:
ro_return_early = TRUE;
if (scrap)
ins_typebuf(":!~remove <Wimp$Scrap>\r", REMAP_NONE, 0, TRUE, FALSE);
ins_typebuf("\r", REMAP_NONE, 0, TRUE, FALSE);
ins_typebuf(path, REMAP_NONE, 0, TRUE, FALSE);
ins_typebuf(" ", REMAP_NONE, 0, TRUE, FALSE);
if (scrap)
{
ins_typebuf(leaf_name, REMAP_NONE, 0, TRUE, FALSE);
ins_typebuf(" +f\\ ", REMAP_NONE, 0, TRUE, FALSE);
leaf_ref = 0;
vim_free(leaf_name);
leaf_name = NULL;
}
swi(OS_Byte, 121, 0x81);
if (r1 == 0xff)
ins_typebuf(":sp", REMAP_NONE, 0, TRUE, FALSE);
else
ins_typebuf(":confirm e", REMAP_NONE, 0, TRUE, FALSE);
break;
default:
swi(Wimp_ReportError, "\0\0\0\0You can only load text in normal mode.", 5, "Vim");
}
block[3] = block[2];
block[4] = 4;
swi(Wimp_SendMessage, 17, block, block[1]);
}
void
ro_datasave(block)
int *block;
{
char_u *path = ((char_u *) block) + 44;
if (leaf_name)
vim_free(leaf_name);
leaf_name = vim_strsave(path);
block[9] = -1;
strcpy(path, "<Wimp$Scrap>");
block[0] = 60;
block[3] = block[2];
block[4] = 2;
swi(Wimp_SendMessage, 17, block, block[1]);
leaf_ref = block[2];
}
void
ro_message(block)
int *block;
{
char_u *buffer;
long_u len;
if (block[1] == task_handle)
return;
switch (block[4])
{
case 0:
if (block[4] == 0)
ro_quit();
break;
case 1:
ro_datasave(block);
break;
case 2:
if (clip_convert_selection(&buffer, &len, &clip_star) == -1)
return;
swi(OS_File, 10, ((char_u *) block) + 44, 0xfff, 0, buffer, buffer + len);
block[3] = block[2];
block[4] = 3;
block[9] = len;
swi(Wimp_SendMessage, 17, block, block[1]);
vim_free(buffer);
break;
case 3:
ro_dataload(block);
break;
case 8:
ro_prequit(block);
break;
case 0xf:
if (block[5] & 4)
{
clip_free_selection(&clip_star);
clip_star.owned = FALSE;
}
break;
case 0x10:
if (clip_star.owned)
{
int rows;
block[0] = 52;
block[3] = block[2];
block[4] = 1;
rows = clip_star.end.lnum - clip_star.start.lnum;
if (rows < 0)
rows = -rows;
block[9] = (rows + 1) * Columns + 1;
block[10] = 0xfff;
strcpy( ((char_u *) block) + 44, "VimClip");
swi(Wimp_SendMessage, 17, block, block[1]);
}
break;
case 0x400c1:
changed_mode = TRUE;
if (zap_redraw)
{
if (ro_zap_redraw_initialise() == FAIL)
zap_redraw = FALSE;
}
break;
case 0x400c3:
if (block[1] == child_handle)
child_handle = 0;
break;
}
}
scrollbar_T *
ro_find_sbar(id)
int id;
{
win_T *wp;
if (gui.bottom_sbar.id == id)
return &gui.bottom_sbar;
FOR_ALL_WINDOWS(wp)
{
if (wp->w_scrollbars[SBAR_LEFT].id == id)
return &wp->w_scrollbars[SBAR_LEFT];
if (wp->w_scrollbars[SBAR_RIGHT].id == id)
return &wp->w_scrollbars[SBAR_RIGHT];
}
return NULL;
}
void
scroll_to(line, sb)
int sb;
int line;
{
char_u code[8];
if (hold_gui_events)
return;
code[0] = CSI;
code[1] = KS_VER_SCROLLBAR;
code[2] = KE_FILLER;
code[3] = sb;
code[4] = line >> 24;
code[5] = line >> 16;
code[6] = line >> 8;
code[7] = line;
add_to_input_buf(code, 8);
}
void
h_scroll_to(col)
int col;
{
char_u code[8];
if (hold_gui_events)
return;
code[0] = CSI;
code[1] = KS_HOR_SCROLLBAR;
code[2] = KE_FILLER;
code[4] = col >> 24;
code[5] = col >> 16;
code[6] = col >> 8;
code[7] = col;
add_to_input_buf(code, 8);
}
void
ro_scroll(block)
int *block;
{
scrollbar_T *sb;
int offset;
win_T *wp;
sb = ro_find_sbar(block[0]);
if (!sb)
return;
wp = sb-> wp;
if (wp == NULL)
{
offset = block[8];
if (offset == -2)
offset = (block[1] - block[3]) / gui.char_width;
else if (offset == 2)
offset = (block[3] - block[1]) / gui.char_width;
block[5] += offset * gui.char_width;
gui_drag_scrollbar(sb, block[5] / gui.char_width, FALSE);
swi(Wimp_OpenWindow, 0, block);
}
else
{
offset = -block[9];
if (offset == -2)
offset = -(wp -> w_height - 1);
else if (offset == 2)
offset = wp -> w_height - 1;
gui_drag_scrollbar(sb, offset - (block[6] / gui.char_height), FALSE);
}
}
void
ro_move_child(window, x, y, pos_wanted, pos_got)
int window;
int x,y;
int pos_wanted, pos_got;
{
int block[10];
block[0] = window;
swi(Wimp_GetWindowState, 0, block);
block[1] += x;
block[2] += y;
block[3] += x;
block[4] += y;
if (pos_wanted == -1)
block[7] = -1;
else if (pos_wanted == -2)
block[7] = pos_got;
swi(Wimp_OpenWindow, 0, block);
}
void
ro_open_main(block)
int *block;
{
int toggle_size;
block[20] = block[0];
swi(Wimp_GetWindowState, 0, block + 20);
toggle_size = block[28] & (1 << 19);
if (nested_wimp)
{
swi(Wimp_OpenWindow, 0, block);
}
else
{
int old[10];
int x_offset, y_offset;
int pos_wanted, pos_got;
int left_bar = gui.which_scrollbars[SBAR_LEFT];
int right_bar = gui.which_scrollbars[SBAR_RIGHT];
win_T *wp;
old[0] = block[0];
swi(Wimp_GetWindowState, 0, old);
pos_wanted = block[7];
swi(Wimp_OpenWindow, 0, block);
swi(Wimp_GetWindowState, 0, block);
pos_got = block[7];
x_offset = block[1] - old[1];
y_offset = block[4] - old[4];
if (x_offset || y_offset || pos_wanted == -1 || pos_wanted == -2)
{
FOR_ALL_WINDOWS(wp)
{
if (left_bar)
ro_move_child(wp -> w_scrollbars[SBAR_LEFT].id,
x_offset, y_offset,
pos_wanted, pos_got);
if (right_bar)
ro_move_child(wp -> w_scrollbars[SBAR_RIGHT].id,
x_offset, y_offset,
pos_wanted, pos_got);
}
}
}
if (changed_mode || toggle_size)
{
int width, height;
if (changed_mode)
ro_measure_tools();
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
width = block[3] - block[1];
height = block[4] - block[2];
swi(Wimp_ForceRedraw, gui.window_handle, 0, -height, width, 0);
gui_resize_shell(width, height);
changed_mode = FALSE;
}
}
void
ro_open_window(block)
int *block;
{
int pos;
scrollbar_T *sb;
if (block[0] == gui.window_handle)
ro_open_main(block);
else
{
swi(Wimp_OpenWindow, 0, block);
if (block[0] != gui.window_handle)
{
sb = ro_find_sbar(block[0]);
if (sb)
{
if (sb-> wp != NULL)
gui_drag_scrollbar(sb, -block[6] / gui.char_height, FALSE);
else
gui_drag_scrollbar(sb, block[5] / gui.char_width, FALSE);
}
}
}
}
void
ro_menu_selection(block)
int *block;
{
int *item = wimp_menu + 7;
vimmenu_T *menu;
for (;;)
{
while (block[0]--)
item += 6;
if (block[1] == -1)
break;
item = ((int *) item[1]) + 7;
block++;
}
menu = (vimmenu_T *) item[5];
swi(Wimp_GetPointerInfo, 0, block);
if (block[2] == 1)
swi(Wimp_CreateMenu, 0, wimp_menu);
if (menu-> cb)
menu-> cb(menu);
}
void
ro_open_parent()
{
int head;
char_u *i = curbuf-> b_ffname;
char_u buffer[256];
head = 0;
for (; *i; i++)
{
if (*i == '.')
head = i - curbuf-> b_ffname;
}
if (head < 240 && curbuf-> b_ffname && head)
{
strcpy(buffer, "%filer_opendir ");
strncpy(buffer + 15, curbuf-> b_ffname, head);
buffer[15 + head] = '\0';
swi(OS_CLI, buffer);
}
}
void
process_event(event, block)
int event;
int *block;
{
switch (event)
{
case 0:
if (ro_dragging)
ro_continue_drag(block);
break;
case 1:
redraw_window(block);
break;
case 2:
ro_open_window(block);
break;
case 3:
swi(Wimp_GetPointerInfo, 0, block + 1);
if (block[3] == 1)
ro_open_parent();
else
if (ro_ok_to_quit())
ro_quit();
break;
case 6:
ro_mouse(block);
break;
case 7:
ro_drag_finished(block);
break;
case 8:
ro_insert_key((char_u *) &block[6]);
break;
case 9:
ro_menu_selection(block);
break;
case 10:
ro_scroll(block);
break;
case 11:
if (block[0] == gui.window_handle)
gui_focus_change(FALSE);
break;
case 12:
if (block[0] == gui.window_handle)
gui_focus_change(TRUE);
break;
case 17:
case 18:
ro_message(block);
break;
}
}
int
gui_mch_wait_for_chars(long wtime)
{
int block[64];
int reason;
int start_time = -1;
int ctime = wtime / 10;
if (wtime != -1)
{
swi(OS_ReadMonotonicTime);
start_time = r0;
}
for (;;)
{
if (ro_dragging)
reason = wimp_poll(0, block);
else if (wtime == -1)
reason = wimp_poll(1, block);
else
reason = wimp_pollidle(0, block, start_time + ctime);
process_event(reason, block);
if (input_available() || ro_return_early)
{
ro_return_early = FALSE;
return OK;
}
if (wtime != -1)
{
swi(OS_ReadMonotonicTime);
if (r0 - start_time > ctime)
return FAIL;
}
}
}
void
gui_mch_flush(void)
{
}
void
gui_mch_clear_block(int row1, int col1, int row2, int col2)
{
swi(ColourTrans_ReturnGCOL, gui.back_pixel << 8, 0, 0, 1<<7, 0);
plot_rectangle(96 + 5, r0,
FILL_X(col1), -FILL_Y(row2 + 1),
FILL_X(col2 + 1), -FILL_Y(row1));
}
void
gui_mch_clear_all(void)
{
if (redraw_block)
{
swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 1<<7, 0);
swi(OS_WriteI + 16);
}
else
{
int block[44];
block[0] = gui.window_handle;
block[1] = 0;
block[2] = -gui.num_rows * gui.char_height;
block[3] = gui.num_cols * gui.char_width;
block[4] = 0;
swi(Wimp_UpdateWindow, 0, block);
while (r0)
{
swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 1<<7, 0);
swi(OS_WriteI + 16);
swi(Wimp_GetRectangle, 0, block);
}
}
}
void
gui_mch_delete_lines(int row, int num_lines)
{
int top_from = -row - num_lines;
int bot_from = -gui.scroll_region_bot - 1;
int bot_to = bot_from + num_lines;
swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 0x80, 0);
swi(Wimp_BlockCopy, gui.window_handle,
gui.scroll_region_left * gui.char_width,
bot_from * gui.char_height,
(gui.scroll_region_right - gui.scroll_region_left
+ 1) * gui.char_width,
top_from * gui.char_height,
gui.scroll_region_left * gui.char_width,
bot_to * gui.char_height);
gui_clear_block(gui.scroll_region_bot - num_lines + 1,
gui.scroll_region_left,
gui.scroll_region_bot, gui.scroll_region_right);
}
void
gui_mch_insert_lines(int row, int num_lines)
{
int top_from = -row;
int bot_to = -gui.scroll_region_bot - 1;
int bot_from = bot_to + num_lines;
swi(ColourTrans_SetGCOL, gui.back_pixel << 8, 0, 0, 0x80, 0);
swi(Wimp_BlockCopy, gui.window_handle,
gui.scroll_region_left * gui.char_width,
bot_from * gui.char_height,
(gui.scroll_region_right - gui.scroll_region_left
+ 1) * gui.char_width,
top_from * gui.char_height,
gui.scroll_region_left * gui.char_width,
bot_to * gui.char_height);
gui_clear_block(row, gui.scroll_region_left,
row + num_lines - 1, gui.scroll_region_right);
}
void
clip_mch_request_selection(VimClipboard *cbd)
{
int block[64];
int reason;
char_u *buffer;
long_u length;
block[0] = 48;
block[3] = 0;
block[4] = 0x10;
block[5] = gui.window_handle;
block[6] = RO_LOAD_CLIPBOARD;
block[7] = block[8] = 0;
block[9] = 4;
block[10] = 0xfff;
block[11] = -1;
swi(Wimp_SendMessage, 17, block, 0);
for (;;)
{
reason = wimp_poll(0, block);
if (reason == 0)
return;
if ((reason == 17 || reason == 18) &&
block[4] == 1 && block[6] == RO_LOAD_CLIPBOARD)
break;
process_event(reason, block);
if (ro_return_early)
return;
}
block[0] = 60;
block[3] = block[2];
block[4] = 2;
block[9] = -1;
strcpy( ((char_u *) block) + 44, "<Wimp$Scrap>");
swi(Wimp_SendMessage, 17, block, block[1]);
for (;;)
{
reason = wimp_poll(0, block);
if (reason == 0)
return;
if ((reason == 17 || reason == 18) && block[4] == 3 && block[6] == RO_LOAD_CLIPBOARD)
break;
process_event(reason, block);
if (ro_return_early)
return;
}
if (xswi(OS_File, 17, "<Wimp$Scrap>") & v_flag)
return;
if (r0 != 1 && r0 != 3)
return;
length = r4;
buffer = lalloc(length, TRUE);
if (buffer == NULL)
return;
if (xswi(OS_File, 16, "<Wimp$Scrap>", buffer, 0) & v_flag)
return;
clip_yank_selection(MCHAR, buffer, length, cbd);
vim_free(buffer);
swi(OS_FSControl, 27, "<Wimp$Scrap>", 0, 0);
block[4] = 4;
block[3] = block[2];
swi(Wimp_SendMessage, 17, block, block[1]);
}
void
clip_mch_lose_selection(VimClipboard *cbd)
{
}
int
clip_mch_own_selection(VimClipboard *cbd)
{
int block[6];
block[0] = 24;
block[3] = 0;
block[4] = 0xf;
block[5] = 0x4;
swi(Wimp_SendMessage, 17, block, 0);
return OK;
}
void
clip_mch_set_selection(VimClipboard *cbd)
{
clip_get_selection(cbd);
}
void
gui_mch_menu_grey(vimmenu_T *menu, int grey)
{
menu-> greyed_out = grey;
}
void
gui_mch_menu_hidden(vimmenu_T *menu, int hidden)
{
menu-> hidden = hidden;
}
void
gui_mch_draw_menubar(void)
{
swi(Wimp_CreateMenu, 0, -1);
if (wimp_menu != (int *) -1)
{
ro_remove_menu(wimp_menu);
wimp_menu = (int *) -1;
}
}
void
gui_mch_enable_scrollbar(sb, flag)
scrollbar_T *sb;
int flag;
{
if (!flag)
swi(Wimp_CloseWindow, 0, & (sb->id) );
return;
}
void
gui_mch_set_blinking(long waittime, long on, long off)
{
}
void
gui_mch_stop_blink(void)
{
}
void
gui_mch_start_blink(void)
{
}
long_u
gui_mch_get_rgb(guicolor_T pixel)
{
return (long_u)pixel;
}
void
gui_mch_set_text_area_pos(int x, int y, int w, int h)
{
}
void
gui_mch_enable_menu(int flag)
{
}
void
gui_mch_set_menu_pos(int x, int y, int w, int h)
{
}
void
gui_mch_add_menu(vimmenu_T *menu, int idx)
{
}
void
gui_mch_add_menu_item(vimmenu_T *menu, int idx)
{
}
void
gui_mch_new_menu_colors(void)
{
}
void
gui_mch_destroy_menu(vimmenu_T *menu)
{
}
void
gui_mch_set_scrollbar_thumb(sb, val, size, max)
scrollbar_T *sb;
long val;
long size;
long max;
{
int block[10], width, height;
width = (max + 1) * gui.char_width;
height = (max + 1 + W_STATUS_HEIGHT(sb->wp)) * gui.char_height;
block[0] = block[3] = 0;
block[1] = -height + (1 << y_eigen_factor);
block[2] = width;
swi(Wimp_SetExtent, sb -> id, block);
block[0] = sb -> id;
swi(Wimp_GetWindowState, 0, block);
block[5] = val * gui.char_width;
block[6] = -val * gui.char_height;
swi(Wimp_OpenWindow, 0, block, 0x4b534154,
gui.window_handle,
(CHILD_FIX_TO_RIGHT << CHILD_LEFT ) |
(CHILD_FIX_TO_RIGHT << CHILD_RIGHT ) |
(CHILD_FIX_TO_BOTTOM << CHILD_TOP ) |
(CHILD_FIX_TO_BOTTOM << CHILD_BOTTOM) |
(CHILD_SELF_SCROLL << CHILD_SCROLL_X) |
(CHILD_SELF_SCROLL << CHILD_SCROLL_Y)
);
}
void
gui_mch_set_scrollbar_pos(sb, x, y, w, h)
scrollbar_T *sb;
int x;
int y;
int w;
int h;
{
int block[24];
int px1, py1;
int px2, py2;
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
px1 = block[1];
py1 = block[2];
px2 = block[3];
py2 = block[4];
block[0] = sb -> id;
swi(Wimp_GetWindowInfo, 0, ((char_u *)block) + 1);
if (block[13] < w || block[12] > -h)
{
if (block[12] > -h)
block[12] = -h;
if (block[13] < w)
block[13] = w;
swi(Wimp_SetExtent, block[0], block + 11);
}
if (sb-> wp)
{
block[1] = block[3] = px2 - gui.scrollbar_width + (1 << x_eigen_factor);
block[2] = 1 + py2 - (y + h) + (1 << y_eigen_factor);
block[4] = 1 + py2 - y;
}
else
{
block[2] = block[4] = py1 + gui.scrollbar_height;
block[1] = px1;
block[3] = px2 - gui.scrollbar_width;
}
block[5] = 0;
block[6] = 0;
block[7] = -1;
swi(Wimp_OpenWindow, 0, block, 0x4b534154,
gui.window_handle,
(CHILD_FIX_TO_RIGHT << CHILD_LEFT ) |
(CHILD_FIX_TO_RIGHT << CHILD_RIGHT ) |
(CHILD_FIX_TO_BOTTOM << CHILD_TOP ) |
(CHILD_FIX_TO_BOTTOM << CHILD_BOTTOM) |
(CHILD_SELF_SCROLL << CHILD_SCROLL_X) |
(CHILD_SELF_SCROLL << CHILD_SCROLL_Y)
);
}
void
gui_mch_create_scrollbar(sb, orient)
scrollbar_T *sb;
int orient;
{
int bar[] =
{
0, 0,
100, 100,
0, 0,
-1,
0x80800150 | (orient == SBAR_HORIZ ? (1 << 30) : (1 << 28)),
0xff070207,
0x000c0103,
0, -0x4000,
0x4000, 0,
0x00000000,
0 << 12,
1,
0x00010001,
0, 0, 0,
0
};
swi(Wimp_CreateWindow, 0, bar);
sb -> id = r0;
}
#if defined(FEAT_WINDOWS) || defined(PROTO)
void
gui_mch_destroy_scrollbar(scrollbar_T *sb)
{
swi(Wimp_DeleteWindow, 0, & (sb->id));
sb -> id = -1;
}
#endif
void
gui_mch_set_scrollbar_colors(scrollbar_T *sb)
{
}
void
gui_mch_getmouse(x, y)
int *x;
int *y;
{
int left;
int top;
int block[10];
block[0] = gui.window_handle;
swi(Wimp_GetWindowState, 0, block);
left = block[1];
top = block[4];
swi(Wimp_GetPointerInfo, 0, block);
*x = block[0] - left;
*y = top - block[1];
}
void
gui_mch_setmouse(x, y)
int x;
int y;
{
}
void
gui_mch_toggle_tearoffs(enable)
int enable;
{
}
void
ro_redraw_title(window)
int window;
{
if (nested_wimp)
{
swi(Wimp_ForceRedraw, window, 0x4b534154, 3);
}
else
{
int block[10];
int miny;
block[0] = window;
swi(Wimp_GetWindowState, 0, block);
miny = block[4];
swi(Wimp_GetWindowOutline, 0, block);
swi(Wimp_ForceRedraw, -1,
block[1], miny,
block[3], block[4]);
}
}
int *
ro_build_menu(menu)
vimmenu_T *menu;
{
int *wimp_menu;
int width = 4;
int w;
int size = 28;
vimmenu_T *item;
int *wimp_item;
for (item = menu-> children; item; item = item-> next)
{
if (item-> hidden == FALSE && !menu_is_separator(item->name))
size += 24;
}
if (size <= 28)
return (int *) -1;
wimp_menu = (int *) alloc(size);
wimp_menu[0] = (int) menu-> dname;
wimp_menu[1] = -1;
wimp_menu[2] = 0;
wimp_menu[3] = 0x00070207;
wimp_menu[5] = 44;
wimp_menu[6] = 0;
wimp_item = wimp_menu + 7;
for (item = menu-> children; item; item = item-> next)
{
if (menu_is_separator(item-> name))
{
if (wimp_item > wimp_menu + 7)
wimp_item[-6] |= 0x2;
}
else if (item-> hidden == FALSE)
{
wimp_item[0] = 0;
wimp_item[1] = item-> children ? (int) ro_build_menu(item) : -1;
wimp_item[2] = 0x07009131 | (item-> greyed_out << 22);
wimp_item[3] = (int) item-> dname;
wimp_item[4] = -1;
wimp_item[5] = (int) item;
w = strlen(item-> dname) + 1;
if (w > width)
width = w;
wimp_item += 6;
}
}
wimp_menu[4] = (width + 2) * 16;
wimp_menu[7] |= 0x100;
wimp_item[-6] |= 0x080;
return wimp_menu;
}
static void
ro_remove_menu(menu)
int *menu;
{
int *item = menu + 7;
if (menu == NULL || menu == (int *) -1)
return;
for (;;)
{
if (item[1] != -1)
ro_remove_menu((int *) item[1]);
if (item[0] & 0x80)
break;
item += 6;
}
vim_free(menu);
}
void
gui_mch_show_popupmenu(menu)
vimmenu_T *menu;
{
int block[10];
if (wimp_menu != (int *) -1)
{
swi(Wimp_CreateMenu, 0, -1);
ro_remove_menu(wimp_menu);
wimp_menu = (int *) -1;
}
wimp_menu = ro_build_menu(menu);
if (wimp_menu != (int *) -1)
{
swi(Wimp_GetPointerInfo, 0, block);
swi(Wimp_CreateMenu, 0, wimp_menu, block[0] - 64, block[1] + 64);
}
}
int
gui_mch_call_shell(cmd, options)
char_u *cmd;
int options;
{
char_u task_cmd[256];
int block[64];
int reason;
char_u *out;
char_u c;
int old_msg_col;
char_u *out_redir;
int length;
FILE *out_file = NULL;
out_redir = strstr(cmd, " > ");
if (out_redir == NULL)
length = strlen(cmd);
else
{
length = out_redir - cmd;
out_file = fopen(out_redir + 3, "wb");
if (out_file == NULL)
smsg("WARNING : Can't open file %s for writing\n", out_redir + 3);
}
if (length > 180)
{
if (out_file)
fclose(out_file);
return FAIL;
}
strcpy(task_cmd, "TaskWindow \"");
strncpy(task_cmd + 12, cmd, length);
sprintf(task_cmd + 12 + length,
"\" -task &%08x -ctrl -quit -name \"Vim command\"",
task_handle);
if (options & SHELL_COOKED)
settmode(TMODE_COOK);
if (xswi(Wimp_StartTask, task_cmd) & v_flag)
{
settmode(TMODE_RAW);
if (out_file)
fclose(out_file);
return FAIL;
}
child_handle = 0;
while (!child_handle)
{
reason = wimp_poll(0, block);
if ((reason == 17 || reason == 18) && block[4] == 0x808c2)
child_handle = block[1];
else
process_event(reason, block);
}
while (child_handle)
{
reason = wimp_poll(1, block);
if (reason == 3 || (reason == 8 && block[6] == 3))
{
block[0] = 20;
block[3] = 0;
block[4] = 0x808c4;
swi(Wimp_SendMessage, 17, block, child_handle);
MSG_PUTS(_("\nSending message to terminate child process.\n"));
continue;
}
else if (reason == 8)
{
block[0] = 28;
block[3] = 0;
block[4] = 0x808c0;
block[5] = 1;
swi(Wimp_SendMessage, 17, block, child_handle);
continue;
}
else if (reason == 17 || reason == 18)
{
if (block[4] == 0x808c1)
{
block[3] = block[2];
swi(Wimp_SendMessage, 19, block, block[1]);
out = (char_u *)block + 24;
old_msg_col = msg_col;
while (block[5]--)
{
c = *out++;
if (out_file && (c != '\r' || (options & SHELL_FILTER)))
fputc(c, out_file);
if ((options & SHELL_FILTER) == 0)
{
if (c == 127)
msg_puts("\b \b");
else if (c > 31)
msg_putchar(c);
else if (c == 10)
{
lines_left = 8;
msg_putchar(10);
}
}
}
windgoto(msg_row, msg_col);
out_flush();
continue;
}
}
process_event(reason, block);
}
msg_putchar('\n');
settmode(TMODE_RAW);
if (out_file)
fclose(out_file);
return OK;
}
char_u *
wimp_strsave(str)
char *str;
{
int strlen = 0;
char_u *retval;
while (str[strlen] > 31)
strlen++;
retval = alloc(strlen + 1);
if (retval)
{
memcpy(retval, str, strlen);
retval[strlen] = '\0';
}
return retval;
}
char_u *
gui_mch_browse(saving, title, dflt, ext, initdir, filter)
int saving;
char_u *title;
char_u *dflt;
char_u *ext;
char_u *initdir;
char_u *filter;
{
char command[256];
int length;
if (saving)
{
int block[64];
int reason;
int done_save = FALSE;
char_u *retval = NULL;
char_u *sprname;
char_u *fname;
int dragging_icon = FALSE;
int filetype;
if (!dflt)
dflt = "TextFile";
block[0] = save_window;
block[1] = 0;
swi(Wimp_GetIconState, 0, block);
sprname = ((char_u *) block[7]);
block[1] = 1;
swi(Wimp_GetIconState, 0, block);
fname = ((char *) block[7]);
strncpy(fname, dflt, 255);
if (xswi(OS_FSControl, 31, curbuf->b_p_oft) & v_flag)
{
filetype = 0xfff;
strcpy(sprname + 5, "xxx");
}
else
{
filetype = r2;
sprintf(sprname + 5, "%03x", filetype);
}
swi(Wimp_GetPointerInfo, 0, block);
swi(Wimp_CreateMenu, 0, save_window, block[0] - 64, block[1] + 64);
swi(Wimp_SetCaretPosition, save_window, 1, 0, 0, -1, -1);
while (!done_save)
{
reason = wimp_poll(1, block);
switch (reason)
{
case 1:
redraw_window(block);
break;
case 2:
if (block[0] == save_window)
swi(Wimp_OpenWindow, 0, block);
else
ro_open_window(block);
break;
case 3:
done_save = TRUE;
break;
case 6:
if (block[3] != save_window)
done_save = TRUE;
else
{
int drag_box[4];
int min_x, max_y;
switch (block[4])
{
case 0:
block[0] = save_window;
swi(Wimp_GetWindowState, 0, block);
min_x = block[1];
max_y = block[4];
block[1] = 0;
swi(Wimp_GetIconState, 0, block);
drag_box[0] = block[2] + min_x;
drag_box[1] = block[3] + max_y;
drag_box[2] = block[4] + min_x;
drag_box[3] = block[5] + max_y;
swi(DragASprite_Start,
0x45,
1,
sprname,
drag_box);
dragging_icon = TRUE;
break;
case 2:
retval = wimp_strsave(fname);
done_save = TRUE;
break;
case 3:
done_save = TRUE;
break;
}
}
break;
case 7:
if (dragging_icon)
{
int len = 0;
dragging_icon = FALSE;
swi(Wimp_GetPointerInfo, 0, block);
block[5] = block[3];
block[6] = block[4];
block[7] = block[0];
block[8] = block[1];
block[9] = 0;
block[10] = filetype;
while (fname[len] > 31)
{
if (fname[len] == '.')
{
fname += len + 1;
len = 0;
}
else
len++;
}
if (len > 211)
len = 211;
memcpy(((char_u *) block) + 44, fname, len);
((char_u *)block)[44 + len] = '\0';
block[0] = (len + 48) & 0xfc;
block[3] = 0;
block[4] = 1;
swi(Wimp_SendMessage, 17, block, block[5], block[6]);
}
else
ro_drag_finished(block);
break;
case 8:
if (block[6] == 13)
{
retval = wimp_strsave(fname);
done_save = TRUE;
}
else if (block[6] == 0x1b)
done_save = TRUE;
else
swi(Wimp_ProcessKey, block[6]);
break;
case 17:
case 18:
if (block[4] == 2 && block[9] != -1)
{
retval = wimp_strsave(((char_u *) block) + 44);
done_save = TRUE;
}
else if (block[4] == 0x400c9)
{
done_save = TRUE;
}
else
ro_message(block);
break;
}
}
block[0] = save_window;
swi(Wimp_CloseWindow, 0, block);
swi(Wimp_GetCaretPosition, 0, block);
if (block[0] == -1)
swi(Wimp_SetCaretPosition, gui.window_handle, -1, 0, 0, -1, -1);
return retval;
}
else if (initdir)
{
length = strlen(initdir);
if (length > 240)
return NULL;
length = sprintf(command, "Filer_OpenDir %s", initdir);
while (command[length - 1] == '.')
length--;
command[length] = '\0';
swi(OS_CLI, command);
}
return NULL;
}