curses.c 34.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*
 * a GUI application for displaying a console
 *	(N)Curses back end
 *
 * Copyright 2002 Eric Pouech
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23 24 25
 */

/* Known issues & FIXME:
 * - not all key mapping functions have been written
 * - allow dyn loading of curses library (extreme care should be taken for 
 *   functions which can be implemented as macros)
26 27
 * - finish buffer scrolling (mainly, need to decide of a nice way for 
 *   requesting the UP/DOWN operations
28 29 30
 */

#include "config.h"
31
#include "wine/port.h"
32 33

#include <stdio.h>
34
#include <stdarg.h>
35
#include <stdlib.h>
36 37 38
#ifdef HAVE_POLL_H
# include <poll.h>
#endif
39
#ifdef HAVE_NCURSES_H
40 41 42
# include <ncurses.h>
#elif defined(HAVE_CURSES_H)
# include <curses.h>
43
#endif
44 45 46 47
/* avoid redefinition warnings */
#undef KEY_EVENT
#undef MOUSE_MOVED

48
#ifdef HAVE_UNISTD_H
49
#include <unistd.h>
50
#endif
51
#include <windef.h>
52
#include <winbase.h>
53 54 55
#include <winnls.h>
#include "winecon_private.h"

56
#include "wine/library.h"
57
#include "wine/debug.h"
58 59
#undef ERR
#define ERR (-1)
60

61
WINE_DEFAULT_DEBUG_CHANNEL(curses);
62 63 64

#define PRIVATE(data)   ((struct inner_data_curse*)((data)->private))

65
#if defined(SONAME_LIBCURSES) || defined(SONAME_LIBNCURSES)
66

67
#ifdef HAVE_NCURSES_H
68
# define CURSES_NAME "ncurses"
69
#else
70
# define CURSES_NAME "curses"
71 72
#endif

73 74
struct inner_data_curse 
{
75
    unsigned long       initial_mouse_mask;
76 77
    int                 sync_pipe[2];
    HANDLE              input_thread;
78
    CRITICAL_SECTION    lock;
79 80
    WINDOW*             pad;
    chtype*             line;
81
    int                 allow_scroll;
82 83
};

84 85
static void *nc_handle = NULL;

86 87 88 89 90
#ifdef initscr  /* work around Solaris breakage */
#undef initscr
extern WINDOW *initscr(void);
#endif

91 92 93 94 95
#define MAKE_FUNCPTR(f) static typeof(f) * p_##f;

MAKE_FUNCPTR(curs_set)
MAKE_FUNCPTR(delwin)
MAKE_FUNCPTR(endwin)
96 97 98 99 100 101
#ifndef getmaxx
MAKE_FUNCPTR(getmaxx)
#endif
#ifndef getmaxy
MAKE_FUNCPTR(getmaxy)
#endif
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
MAKE_FUNCPTR(has_colors)
MAKE_FUNCPTR(init_pair)
MAKE_FUNCPTR(initscr)
#ifndef intrflush
MAKE_FUNCPTR(intrflush)
#endif
MAKE_FUNCPTR(keypad)
MAKE_FUNCPTR(newpad)
#ifndef nodelay
MAKE_FUNCPTR(nodelay)
#endif
#ifndef noecho
MAKE_FUNCPTR(noecho)
#endif
MAKE_FUNCPTR(prefresh)
MAKE_FUNCPTR(raw)
MAKE_FUNCPTR(start_color)
MAKE_FUNCPTR(stdscr)
MAKE_FUNCPTR(waddchnstr)
MAKE_FUNCPTR(wmove)
MAKE_FUNCPTR(wgetch)
123
#ifdef HAVE_MOUSEMASK
124
MAKE_FUNCPTR(getmouse)
125 126 127
MAKE_FUNCPTR(mouseinterval)
MAKE_FUNCPTR(mousemask)
#endif
128
MAKE_FUNCPTR(acs_map)
129 130 131 132 133 134 135

#undef MAKE_FUNCPTR

/**********************************************************************/

static BOOL WCCURSES_bind_libcurses(void)
{
136
#ifdef SONAME_LIBNCURSES
137
    static const char ncname[] = SONAME_LIBNCURSES;
138
#else
139
    static const char ncname[] = SONAME_LIBCURSES;
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
#endif

    nc_handle = wine_dlopen(ncname, RTLD_NOW, NULL, 0);
    if(!nc_handle)
    {
        WINE_MESSAGE("Wine cannot find the " CURSES_NAME " library (%s).\n",
                     ncname);
        return FALSE;
    }

#define LOAD_FUNCPTR(f)                                      \
    if((p_##f = wine_dlsym(nc_handle, #f, NULL, 0)) == NULL) \
    {                                                        \
        WINE_WARN("Can't find symbol %s\n", #f);             \
        goto sym_not_found;                                  \
    }

    LOAD_FUNCPTR(curs_set)
    LOAD_FUNCPTR(delwin)
    LOAD_FUNCPTR(endwin)
160 161 162 163 164 165
#ifndef getmaxx
    LOAD_FUNCPTR(getmaxx)
#endif
#ifndef getmaxy
    LOAD_FUNCPTR(getmaxy)
#endif
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
    LOAD_FUNCPTR(has_colors)
    LOAD_FUNCPTR(init_pair)
    LOAD_FUNCPTR(initscr)
#ifndef intrflush
    LOAD_FUNCPTR(intrflush)
#endif
    LOAD_FUNCPTR(keypad)
    LOAD_FUNCPTR(newpad)
#ifndef nodelay
    LOAD_FUNCPTR(nodelay)
#endif
#ifndef noecho
    LOAD_FUNCPTR(noecho)
#endif
    LOAD_FUNCPTR(prefresh)
    LOAD_FUNCPTR(raw)
    LOAD_FUNCPTR(start_color)
    LOAD_FUNCPTR(stdscr)
    LOAD_FUNCPTR(waddchnstr)
    LOAD_FUNCPTR(wmove)
    LOAD_FUNCPTR(wgetch)
187
#ifdef HAVE_MOUSEMASK
188
    LOAD_FUNCPTR(getmouse)
189 190 191
    LOAD_FUNCPTR(mouseinterval)
    LOAD_FUNCPTR(mousemask)
#endif
192
    LOAD_FUNCPTR(acs_map)
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

#undef LOAD_FUNCPTR

    return TRUE;

sym_not_found:
    WINE_MESSAGE(
      "Wine cannot find certain functions that it needs inside the "
       CURSES_NAME "\nlibrary.  To enable Wine to use " CURSES_NAME 
      " please upgrade your " CURSES_NAME "\nlibraries\n");
    wine_dlclose(nc_handle, NULL, 0);
    nc_handle = NULL;
    return FALSE;
}

#define curs_set p_curs_set
#define delwin p_delwin
#define endwin p_endwin
211 212 213 214 215 216
#ifndef getmaxx
#define getmaxx p_getmaxx
#endif
#ifndef getmaxy
#define getmaxy p_getmaxy
#endif
217 218 219 220 221 222 223
#define has_colors p_has_colors
#define init_pair p_init_pair
#define initscr p_initscr
#ifndef intrflush
#define intrflush p_intrflush
#endif
#define keypad p_keypad
224 225
#ifdef HAVE_MOUSEMASK
#define getmouse p_getmouse
226 227
#define mouseinterval p_mouseinterval
#define mousemask p_mousemask
228
#endif
229 230 231 232 233 234 235 236 237 238 239 240 241 242
#define newpad p_newpad
#ifndef nodelay
#define nodelay p_nodelay
#endif
#ifndef noecho
#define noecho p_noecho
#endif
#define prefresh p_prefresh
#define raw p_raw
#define start_color p_start_color
#define stdscr (*p_stdscr)
#define waddchnstr p_waddchnstr
#define wmove p_wmove
#define wgetch p_wgetch
243
#define acs_map (*p_acs_map)
244

245
/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
246
 *		WCCURSES_ResizeScreenBuffer
247 248 249
 *
 *
 */
Eric Pouech's avatar
Eric Pouech committed
250
static void WCCURSES_ResizeScreenBuffer(struct inner_data* data)
251 252 253 254 255 256
{
    /* reallocate a new pad. next event would redraw the whole pad */
    if (PRIVATE(data)->pad) delwin(PRIVATE(data)->pad);
    PRIVATE(data)->pad = newpad(data->curcfg.sb_height, data->curcfg.sb_width);
    if (!PRIVATE(data)->pad)
        WINE_FIXME("Cannot create pad\n");
257 258 259 260 261
    if (PRIVATE(data)->line) 
	PRIVATE(data)->line = HeapReAlloc(GetProcessHeap(), 0, PRIVATE(data)->line, 
                                      sizeof(chtype) * data->curcfg.sb_width);
    else 
	PRIVATE(data)->line = HeapAlloc(GetProcessHeap(), 0, 
262 263 264 265
                                      sizeof(chtype) * data->curcfg.sb_width);
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
266
 *		WCCURSES_PosCursor
267 268 269
 *
 * Set a new position for the cursor (and refresh any modified part of our pad)
 */
Eric Pouech's avatar
Eric Pouech committed
270
static void	WCCURSES_PosCursor(const struct inner_data* data)
271
{
272 273 274
    int scr_width;
    int scr_height;

275 276 277 278 279 280 281 282 283 284 285 286 287
    if (data->curcfg.cursor_visible &&
        data->cursor.Y >= data->curcfg.win_pos.Y &&
        data->cursor.Y < data->curcfg.win_pos.Y + data->curcfg.win_height &&
        data->cursor.X >= data->curcfg.win_pos.X &&
        data->cursor.X < data->curcfg.win_pos.X + data->curcfg.win_width)
    {
        if (curs_set(2) == ERR) curs_set(1);
        wmove(PRIVATE(data)->pad, data->cursor.Y, data->cursor.X);
    }
    else
    {
        curs_set(0);
    }
288
    getmaxyx(stdscr, scr_height, scr_width); 
289 290
    prefresh(PRIVATE(data)->pad,
             data->curcfg.win_pos.Y, data->curcfg.win_pos.X,
291 292 293
             0, 0, 
             min(scr_height, data->curcfg.win_height) - 1, 
             min(scr_width, data->curcfg.win_width) - 1);
294 295 296
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
297
 *		WCCURSES_ShapeCursor
298 299 300
 *
 * Sets a new shape for the cursor
 */
301
static void	WCCURSES_ShapeCursor(struct inner_data* data, int size, int vis, BOOL force)
302
{
303 304
    /* we can't do much about the size... */
    data->curcfg.cursor_size = size;
305
    data->curcfg.cursor_visible = vis != 0;
306
    WCCURSES_PosCursor(data);
307 308 309
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
310
 *		WCCURSES_ComputePositions
311 312 313
 *
 * Recomputes all the components (mainly scroll bars) positions
 */
314
static void	WCCURSES_ComputePositions(struct inner_data* data)
315
{
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
    int         x, y;

    getmaxyx(stdscr, y, x);
    if ((data->curcfg.win_height && y < data->curcfg.win_height) ||
        (data->curcfg.win_width && x < data->curcfg.win_width))
    {
        SMALL_RECT  pos;

        WINE_WARN("Window too large (%dx%d), adjusting to curses' size (%dx%d)\n",
                  data->curcfg.win_width, data->curcfg.win_height, x, y);
        pos.Left = pos.Top = 0;
        pos.Right = x - 1; pos.Bottom = y - 1;
        SetConsoleWindowInfo(data->hConOut, FALSE, &pos);
        return; /* we'll get called again upon event for new window size */
    }
Eric Pouech's avatar
Eric Pouech committed
331
    if (PRIVATE(data)->pad) WCCURSES_PosCursor(data);
332 333 334
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
335
 *		WCCURSES_SetTitle
336 337 338
 *
 * Sets the title to the wine console
 */
Eric Pouech's avatar
Eric Pouech committed
339
static void	WCCURSES_SetTitle(const struct inner_data* data)
340 341 342 343 344 345
{
    WCHAR   wbuf[256];

    if (WINECON_GetConsoleTitle(data->hConIn, wbuf, sizeof(wbuf)/sizeof(WCHAR)))
    {
        char        buffer[256];
346 347

        WideCharToMultiByte(CP_UNIXCP, 0, wbuf, -1, buffer, sizeof(buffer),
348 349 350 351 352 353 354 355 356
                            NULL, NULL);
        fputs("\033]2;", stdout);
        fputs(buffer, stdout);
        fputc('\a', stdout);
        fflush(stdout);
    }
}

/******************************************************************
357
 *		WCCURSES_Refresh
358 359 360
 *
 *
 */
Eric Pouech's avatar
Eric Pouech committed
361
static void WCCURSES_Refresh(const struct inner_data* data, int tp, int bm)
362
{
363 364
    unsigned int x;
    int         y;
365
    CHAR_INFO*	cell;
Eric Pouech's avatar
Eric Pouech committed
366
    DWORD       attr;
367 368 369 370 371 372

    for (y = tp; y <= bm; y++)
    {
	cell = &data->cells[y * data->curcfg.sb_width];
        for (x = 0; x < data->curcfg.sb_width; x++)
        {
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440
            /* check for some mapping to ACS characters (drawing boxes, arrows) */
            if ((cell[x].Char.UnicodeChar >= 0x2500 && cell[x].Char.UnicodeChar <= 0x257F) ||
                (cell[x].Char.UnicodeChar >= 0x2190 && cell[x].Char.UnicodeChar <= 0x21FF))
            {
                /* FIXME: we're also mapping heavy and lines item to single lines
                 * (that's ugly, but that's better than crap)
                 * Moreover, as the ACS_ macros refer to values in array acs_map[], we
                 * cannot simply build static tables for the mapping (FIXME: this could be done
                 * at load time)
                 */
                switch (cell[x].Char.UnicodeChar)
                {
                case 0x2190: case 0x219E: case 0x21A2: case 0x21A4:
                case 0x21BC: case 0x21BD: case 0x21D0: case 0x21E6: attr = ACS_LARROW;   break;
                case 0x2191: case 0x219F: case 0x21A3: case 0x21A5:
                case 0x21BE: case 0x21BF: case 0x21D1: case 0x21E7: attr = ACS_UARROW;   break;
                case 0x2192: case 0x21A0: case 0x21A6: case 0x21C0:
                case 0x21C1: case 0x21D2: case 0x21E8:              attr = ACS_RARROW;   break;
                case 0x2193: case 0x21A1: case 0x21A7: case 0x21C2:
                case 0x21C3: case 0x21D3: case 0x21E9:              attr = ACS_DARROW;   break;

                case 0x2500: case 0x2501: case 0x257C: case 0x257E: attr = ACS_HLINE;    break;
                case 0x2502: case 0x2503: case 0x257D: case 0x257F: attr = ACS_VLINE;    break;
                case 0x250C: case 0x250D: case 0x250E: case 0x250F: attr = ACS_ULCORNER; break;
                case 0x2510: case 0x2511: case 0x2512: case 0x2513: attr = ACS_URCORNER; break;
                case 0x2514: case 0x2515: case 0x2516: case 0x2517: attr = ACS_LLCORNER; break;
                case 0x2518: case 0x2519: case 0x251A: case 0x251B: attr = ACS_LRCORNER; break;
                case 0x251C: case 0x251D: case 0x251E: case 0x251F:
                case 0x2520: case 0x2521: case 0x2522: case 0x2523: attr = ACS_LTEE;     break;
                case 0x2524: case 0x2525: case 0x2526: case 0x2527:
                case 0x2528: case 0x2529: case 0x252A: case 0x252B: attr = ACS_RTEE;     break;

                case 0x252C: case 0x252D: case 0x252E: case 0x252F:
                case 0x2530: case 0x2531: case 0x2532: case 0x2533: attr = ACS_TTEE;     break;
                case 0x2534: case 0x2535: case 0x2536: case 0x2537:
                case 0x2538: case 0x2539: case 0x253A: case 0x253B: attr = ACS_BTEE;     break;

                case 0x253C: case 0x253D: case 0x253E: case 0x253F:
                case 0x2540: case 0x2541: case 0x2542: case 0x2543:
                case 0x2544: case 0x2545: case 0x2546: case 0x2547:
                case 0x2548: case 0x2549: case 0x254A: case 0x254B: attr = ACS_PLUS;     break;

                case 0x2550:                                        attr = ACS_HLINE;    break;
                case 0x2551:                                        attr = ACS_VLINE;    break;
                case 0x2552: case 0x2553: case 0x2554:              attr = ACS_ULCORNER; break;
                case 0x2555: case 0x2556: case 0x2557:              attr = ACS_URCORNER; break;
                case 0x2558: case 0x2559: case 0x255A:              attr = ACS_LLCORNER; break;
                case 0x255B: case 0x255C: case 0x255D:              attr = ACS_LRCORNER; break;
                case 0x255E: case 0x255F: case 0x2560:              attr = ACS_LTEE;     break;
                case 0x2561: case 0x2562: case 0x2563:              attr = ACS_RTEE;     break;
                case 0x2564: case 0x2565: case 0x2566:              attr = ACS_TTEE;     break;
                case 0x2567: case 0x2568: case 0x2569:              attr = ACS_BTEE;     break;
                case 0x256A: case 0x256B: case 0x256C:              attr = ACS_PLUS;     break;
                default:
                    WINE_FIXME("Unmapped special character (%x)\n", cell[x].Char.UnicodeChar);
                    attr = ' ';
                }
            }
            else
            {
                char     ch[2];

                if (WideCharToMultiByte(CP_UNIXCP, 0, &cell[x].Char.UnicodeChar, 1,
                                        ch, sizeof(ch), NULL, NULL) == 1)
                    attr = ((BYTE)ch[0] < 32) ? 32 : (BYTE)ch[0];
                else
                    attr = 32;
            }
441

Eric Pouech's avatar
Eric Pouech committed
442 443 444 445 446 447 448 449 450
            if (cell[x].Attributes & FOREGROUND_RED)       attr |= COLOR_PAIR(COLOR_RED);
            if (cell[x].Attributes & FOREGROUND_BLUE)      attr |= COLOR_PAIR(COLOR_BLUE);
            if (cell[x].Attributes & FOREGROUND_GREEN)     attr |= COLOR_PAIR(COLOR_GREEN);
            if (cell[x].Attributes & BACKGROUND_RED)       attr |= COLOR_PAIR(COLOR_RED << 3);
            if (cell[x].Attributes & BACKGROUND_BLUE)      attr |= COLOR_PAIR(COLOR_BLUE << 3);
            if (cell[x].Attributes & BACKGROUND_GREEN)     attr |= COLOR_PAIR(COLOR_GREEN << 3);

            if (cell[x].Attributes & FOREGROUND_INTENSITY) attr |= A_BOLD;
            PRIVATE(data)->line[x] = attr;
451 452 453
        }
        mvwaddchnstr(PRIVATE(data)->pad, y, 0, PRIVATE(data)->line, data->curcfg.sb_width);
    }
454 455

    WCCURSES_PosCursor(data);
456 457 458
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
459
 *		WCCURSES_Scroll
460 461 462
 *
 *
 */
Eric Pouech's avatar
Eric Pouech committed
463
static void WCCURSES_Scroll(struct inner_data* data, int pos, BOOL horz)
464 465 466 467 468 469 470 471 472
{
    if (horz)
    {
	data->curcfg.win_pos.X = pos;
    }
    else
    {
	data->curcfg.win_pos.Y = pos;
    }
473
    WCCURSES_PosCursor(data);
474 475 476
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
477
 *		WCCURSES_SetFont
478 479 480
 *
 *
 */
Eric Pouech's avatar
Eric Pouech committed
481
static void WCCURSES_SetFont(struct inner_data* data, const WCHAR* font, 
482 483 484 485 486
                            unsigned height, unsigned weight)
{
    /* FIXME: really not much to do ? */
}

487 488 489 490 491 492 493 494 495 496 497 498
/******************************************************************
 *		WCCURSES_Resize
 *
 */
static void WCCURSES_Resize(struct inner_data* data)
{
    int width, height;

    getmaxyx(stdscr, height, width);
    WINECON_ResizeWithContainer(data, width, height);
}

499 500 501 502 503 504 505
/******************************************************************
 *		WCCURSES_ScrollV
 *
 *
 */
static void WCCURSES_ScrollV(struct inner_data* data, int delta)
{
506
    struct config_data  cfg = data->curcfg;
507

508 509 510 511 512
    cfg.win_pos.Y += delta;
    if (cfg.win_pos.Y < 0) cfg.win_pos.Y = 0;
    if (cfg.win_pos.Y > data->curcfg.sb_height - data->curcfg.win_height)
        cfg.win_pos.Y = data->curcfg.sb_height - data->curcfg.win_height;
    if (cfg.win_pos.Y != data->curcfg.win_pos.Y)
513 514
    {
        WCCURSES_PosCursor(data);
515
        WINECON_SetConfig(data, &cfg);
516 517 518
    }
}

519
/* Ascii -> VK, generated by calling VkKeyScanA(i) */
520
static const int vkkeyscan_table[256] =
521 522 523 524 525 526 527 528 529 530 531 532 533
{
     0,0,0,0,0,0,0,0,8,9,0,0,0,13,0,0,0,0,0,19,145,556,0,0,0,0,0,27,0,0,0,
     0,32,305,478,307,308,309,311,222,313,304,312,443,188,189,190,191,48,
     49,50,51,52,53,54,55,56,57,442,186,444,187,446,447,306,321,322,323,
     324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,
     341,342,343,344,345,346,219,220,221,310,445,192,65,66,67,68,69,70,71,
     72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,475,476,477,
     448,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,400,0,0,0,0,0,0
};

534
static const int mapvkey_0[256] =
535 536 537 538 539 540 541 542 543 544 545 546
{
     0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,69,58,0,0,0,0,0,0,1,0,0,
     0,0,57,73,81,79,71,75,72,77,80,0,0,0,55,82,83,0,11,2,3,4,5,6,7,8,9,
     10,0,0,0,0,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,
     19,31,20,22,47,17,45,21,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,78,0,74,
     0,53,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,76,96,0,0,0,0,0,0,0,0,
     0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
}; 

547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
/******************************************************************
 *		WCCURSES_InitComplexChar
 *
 *
 */
static inline void WCCURSES_InitComplexChar(INPUT_RECORD* ir, BOOL down, WORD vk, WORD kc, DWORD cks)
{
    ir->EventType			 = KEY_EVENT;
    ir->Event.KeyEvent.bKeyDown	         = down;
    ir->Event.KeyEvent.wRepeatCount	 = 1;
    
    ir->Event.KeyEvent.wVirtualScanCode  = vk;
    ir->Event.KeyEvent.wVirtualKeyCode   = kc;
    ir->Event.KeyEvent.dwControlKeyState = cks;
    ir->Event.KeyEvent.uChar.UnicodeChar = 0;
}

564
/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
565
 *		WCCURSES_FillSimpleChar
566 567 568
 *
 *
 */
569
static unsigned WCCURSES_FillSimpleChar(INPUT_RECORD* ir, unsigned real_inchar)
570
{
571 572
    unsigned vk;
    unsigned inchar;
573
    char ch;
574 575 576 577 578
    unsigned numEvent = 0;
    DWORD    cks = 0;

    switch (real_inchar)
    {
579 580 581 582 583 584 585 586
    case   9: inchar = real_inchar;
              real_inchar = 27; /* so that we don't think key is ctrl- something */ 	
	      break;
    case  10: inchar = '\r'; 
              real_inchar = 27; /* Fixme: so that we don't think key is ctrl- something */ 
	      break;
    case 127: inchar = '\b'; 
	      break;
587
    case  27:
588 589 590
        /* we assume that ESC & and the second character are atomically
         * generated otherwise, we'll have a race here. FIXME: This gives 1 sec. delay
         * because curses looks for a second character.
591 592 593
         */
        if ((inchar = wgetch(stdscr)) != ERR)
        {
594
            /* we got an alt-something key... */
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
            cks = LEFT_ALT_PRESSED;
        }
        else
            inchar = 27;
        break;
    default:
        inchar = real_inchar;
        break;
    }
    if ((inchar & ~0xFF) != 0) WINE_FIXME("What a char (%u)\n", inchar);
    vk = vkkeyscan_table[inchar];
    if (vk & 0x0100)
        WCCURSES_InitComplexChar(&ir[numEvent++], 1, 0x2a, 0x10, SHIFT_PRESSED);
    if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
        WCCURSES_InitComplexChar(&ir[numEvent++], 1, 0x1d, 0x11, LEFT_CTRL_PRESSED);
    if (vk & 0x0400)
        WCCURSES_InitComplexChar(&ir[numEvent++], 1, 0x38, 0x12, LEFT_ALT_PRESSED);

    ir[numEvent].EventType                        = KEY_EVENT;
    ir[numEvent].Event.KeyEvent.bKeyDown          = 1;
    ir[numEvent].Event.KeyEvent.wRepeatCount      = 1;
    ir[numEvent].Event.KeyEvent.dwControlKeyState = cks;
    if (vk & 0x0100)
        ir[numEvent].Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;
    if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
        ir[numEvent].Event.KeyEvent.dwControlKeyState |= LEFT_CTRL_PRESSED;
    if (vk & 0x0400)
        ir[numEvent].Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
    ir[numEvent].Event.KeyEvent.wVirtualKeyCode = vk;
    ir[numEvent].Event.KeyEvent.wVirtualScanCode = mapvkey_0[vk & 0x00ff]; /* VirtualKeyCodes to ScanCode */

626 627
    ch = inchar;
    MultiByteToWideChar(CP_UNIXCP, 0,&ch,1,&ir[numEvent].Event.KeyEvent.uChar.UnicodeChar, 1);
628 629 630 631 632 633 634 635 636 637 638 639 640
    ir[numEvent + 1] = ir[numEvent];
    ir[numEvent + 1].Event.KeyEvent.bKeyDown      = 0;

    numEvent += 2;

    if (vk & 0x0400)
        WCCURSES_InitComplexChar(&ir[numEvent++], 0, 0x38, 0x12, LEFT_ALT_PRESSED);
    if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
        WCCURSES_InitComplexChar(&ir[numEvent++], 0, 0x1d, 0x11, 0);
    if (vk & 0x0100)
        WCCURSES_InitComplexChar(&ir[numEvent++], 0, 0x2a, 0x10, 0);

    return numEvent;
641 642 643
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
644
 *		WCCURSES_FillComplexChar
645 646 647
 *
 *
 */
648
static unsigned WCCURSES_FillComplexChar(INPUT_RECORD* ir, WORD vk, WORD kc, DWORD cks)
649
{
650 651 652 653
    WCCURSES_InitComplexChar(&ir[0], 1, vk, kc, ENHANCED_KEY | cks);
    WCCURSES_InitComplexChar(&ir[1], 0, vk, kc, ENHANCED_KEY | cks);

    return 2;
654 655 656
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
657
 *		WCCURSES_FillMouse
658 659 660
 *
 *
 */
Eric Pouech's avatar
Eric Pouech committed
661
static unsigned WCCURSES_FillMouse(INPUT_RECORD* ir)
662
{
663
#ifdef HAVE_MOUSEMASK
664 665 666 667 668 669 670 671 672 673 674
    static	unsigned	bstate /* = 0 */;
    static	COORD 		pos /* = {0, 0} */;

    MEVENT	mevt;

    if (getmouse(&mevt) == ERR)
        return 0;

    WINE_TRACE("[%u]: (%d, %d) %08lx\n", 
               mevt.id, mevt.x, mevt.y, (unsigned long)mevt.bstate);

675
    /* macros to ease mapping ncurses button numbering to windows' one */
676 677 678 679
#define	BTN1_BIT	FROM_LEFT_1ST_BUTTON_PRESSED
#define	BTN2_BIT	RIGHTMOST_BUTTON_PRESSED
#define	BTN3_BIT	FROM_LEFT_2ND_BUTTON_PRESSED
#define	BTN4_BIT	0 /* not done yet */
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715

    if (mevt.bstate & BUTTON1_PRESSED)	 bstate |= BTN1_BIT;
    if (mevt.bstate & BUTTON1_RELEASED)  bstate &= ~BTN1_BIT;
    if (mevt.bstate & BUTTON2_PRESSED)	 bstate |= BTN2_BIT;
    if (mevt.bstate & BUTTON2_RELEASED)  bstate &= ~BTN2_BIT;
    if (mevt.bstate & BUTTON3_PRESSED)	 bstate |= BTN3_BIT;
    if (mevt.bstate & BUTTON3_RELEASED)  bstate &= ~BTN3_BIT;

    ir->EventType = MOUSE_EVENT;
    ir->Event.MouseEvent.dwMousePosition.X = mevt.x;
    ir->Event.MouseEvent.dwMousePosition.Y = mevt.y;

    ir->Event.MouseEvent.dwButtonState = bstate;

    /* partial conversion */
    ir->Event.MouseEvent.dwControlKeyState = 0;
    if (mevt.bstate & BUTTON_SHIFT)	ir->Event.MouseEvent.dwControlKeyState |= SHIFT_PRESSED;
    /* choose to map to left ctrl... could use both ? */
    if (mevt.bstate & BUTTON_CTRL)	ir->Event.MouseEvent.dwControlKeyState |= LEFT_CTRL_PRESSED;
    /* choose to map to left alt... could use both ? */
    if (mevt.bstate & BUTTON_ALT)	ir->Event.MouseEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
    /* FIXME: unsupported yet flags: CAPSLOCK_ON, ENHANCED_KEY (??), NUMLOCK_ON, SCROLLLOCK_ON 
     * could be reported from the key events...
     */

    ir->Event.MouseEvent.dwEventFlags = 0;
    /* FIXME: we no longer generate double click events */

    if (!(mevt.bstate & (BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED)) &&
        (mevt.x != pos.X || mevt.y != pos.Y))
    {
        ir->Event.MouseEvent.dwEventFlags |= MOUSE_MOVED;
    }
    pos.X = mevt.x; pos.Y = mevt.y;

    return 1;
716 717 718
#else
    return 0;
#endif
719 720 721
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
722
 *		WCCURSES_FillCode
723 724 725
 *
 *
 */
726
static unsigned WCCURSES_FillCode(struct inner_data* data, INPUT_RECORD* ir, int inchar)
727
{
728 729
    unsigned numEvent = 0;
    
730 731 732 733 734
    switch (inchar)
    {
    case KEY_BREAK:
        goto notFound;
    case KEY_DOWN:
735
        numEvent = WCCURSES_FillComplexChar(ir, 0x50, 0x28, 0);
736 737
        break;
    case KEY_UP:
738
        numEvent = WCCURSES_FillComplexChar(ir, 0x48, 0x26, 0);
739 740
        break;
    case KEY_LEFT:
741
        numEvent = WCCURSES_FillComplexChar(ir, 0x4b, 0x25, 0);
742 743
        break;
    case KEY_RIGHT:
744
        numEvent = WCCURSES_FillComplexChar(ir, 0x4d, 0x27, 0);
745 746
        break;
    case KEY_HOME:
747
        numEvent = WCCURSES_FillComplexChar(ir, 0x47, 0x24, 0);
748 749
        break;
    case KEY_BACKSPACE:
750
        numEvent = WCCURSES_FillSimpleChar(ir, 127);
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765
        break;
        
    case KEY_F0: /* up to F63 */
        goto notFound;
		    
    case KEY_F( 1):
    case KEY_F( 2):
    case KEY_F( 3):
    case KEY_F( 4):
    case KEY_F( 5):
    case KEY_F( 6):
    case KEY_F( 7):
    case KEY_F( 8):
    case KEY_F( 9):
    case KEY_F(10):
766 767
        numEvent = WCCURSES_FillComplexChar(ir, 0x3b + inchar - KEY_F(1),
                                            0x70 + inchar - KEY_F(1), 0);
768 769 770
        break;
    case KEY_F(11):
    case KEY_F(12):
771 772 773 774 775 776
        if (PRIVATE(data)->allow_scroll)
        {
            WCCURSES_ScrollV(data, inchar == KEY_F(11) ? 8 : -8);
        }
        else
        {
777 778
            numEvent = WCCURSES_FillComplexChar(ir, 0xd9 + inchar - KEY_F(11),
                                                0x7a + inchar - KEY_F(11), 0);
779
        }
780 781 782 783
        break;
		    
    case KEY_DL:
    case KEY_IL:
784 785
        goto notFound;

786
    case KEY_DC:
787 788
        numEvent = WCCURSES_FillComplexChar(ir, 0x53, 0x2e, 0);
        break;
789
    case KEY_IC:
790 791 792
        numEvent = WCCURSES_FillComplexChar(ir, 0x52, 0x2d, 0);
        break;

793 794 795 796 797 798 799 800 801
    case KEY_EIC:
    case KEY_CLEAR:
    case KEY_EOS:
    case KEY_EOL:
    case KEY_SF:
    case KEY_SR:
        goto notFound;
		    
    case KEY_NPAGE:
802
        numEvent = WCCURSES_FillComplexChar(ir, 0x51, 0x22, 0);
803 804
        break;
    case KEY_PPAGE:
805
        numEvent = WCCURSES_FillComplexChar(ir, 0x49, 0x21, 0);
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820
        break;
        
    case KEY_STAB:
    case KEY_CTAB:
    case KEY_CATAB:
    case KEY_ENTER:
    case KEY_SRESET:
    case KEY_RESET:
    case KEY_PRINT:
    case KEY_LL:
    case KEY_A1:
    case KEY_A3:
    case KEY_B2:
    case KEY_C1:
    case KEY_C3:
821 822 823 824 825
        goto notFound;
    case KEY_BTAB:      /* shift tab */
        numEvent = WCCURSES_FillSimpleChar(ir, 0x9);
	ir[0].Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;
	ir[1].Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;	
826
	if (numEvent != 2) WINE_ERR("FillsimpleChar has changed\n");
827 828
	break;

829 830 831 832 833 834
    case KEY_BEG:
    case KEY_CANCEL:
    case KEY_CLOSE:
    case KEY_COMMAND:
    case KEY_COPY:
    case KEY_CREATE:
835 836
        goto notFound;

837
    case KEY_END:
838 839 840
        numEvent = WCCURSES_FillComplexChar(ir, 0x4f, 0x23, 0);
        break;
        
841 842 843 844 845 846 847 848
    case KEY_EXIT:
    case KEY_FIND:
    case KEY_HELP:
    case KEY_MARK:
    case KEY_MESSAGE:
        goto notFound;
		    
    case KEY_MOUSE:
849
        numEvent = WCCURSES_FillMouse(ir);
850
        break;
851 852 853 854 855 856
#ifdef KEY_RESIZE
    case KEY_RESIZE:
        WCCURSES_Resize(data);
        break;
#endif

857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
    case KEY_MOVE:
    case KEY_NEXT:
    case KEY_OPEN:
    case KEY_OPTIONS:
    case KEY_PREVIOUS:
    case KEY_REDO:
    case KEY_REFERENCE:
    case KEY_REFRESH:
    case KEY_REPLACE:
    case KEY_RESTART:
    case KEY_RESUME:
    case KEY_SAVE:
    case KEY_SBEG:
    case KEY_SCANCEL:
    case KEY_SCOMMAND:
    case KEY_SCOPY:
    case KEY_SCREATE:
874 875
        goto notFound;

876
    case KEY_SDC:
877 878
        numEvent = WCCURSES_FillComplexChar(ir, 0x53, 0x2e, SHIFT_PRESSED);
        break;
879 880
    case KEY_SDL:
    case KEY_SELECT:
881 882
        goto notFound;

883
    case KEY_SEND:
884 885 886
        numEvent = WCCURSES_FillComplexChar(ir, 0x4f, 0x23, SHIFT_PRESSED);
        break;

887 888 889 890
    case KEY_SEOL:
    case KEY_SEXIT:
    case KEY_SFIND:
    case KEY_SHELP:
891 892
        goto notFound;

893
    case KEY_SHOME:
894 895
        numEvent = WCCURSES_FillComplexChar(ir, 0x47, 0x24, SHIFT_PRESSED);
        break;
896
    case KEY_SIC:
897 898
        numEvent = WCCURSES_FillComplexChar(ir, 0x52, 0x2d, SHIFT_PRESSED);
        break;
899
    case KEY_SLEFT:
900 901 902
        numEvent = WCCURSES_FillComplexChar(ir, 0x4b, 0x25, SHIFT_PRESSED);
        break;

903 904 905 906 907 908 909 910
    case KEY_SMESSAGE:
    case KEY_SMOVE:
    case KEY_SNEXT:
    case KEY_SOPTIONS:
    case KEY_SPREVIOUS:
    case KEY_SPRINT:
    case KEY_SREDO:
    case KEY_SREPLACE:
911 912
        goto notFound;

913
    case KEY_SRIGHT:
914 915 916
        numEvent = WCCURSES_FillComplexChar(ir, 0x4d, 0x27, SHIFT_PRESSED);
        break;

917 918 919 920 921 922 923
    case KEY_SRSUME:
    case KEY_SSAVE:
    case KEY_SSUSPEND:
    case KEY_SUNDO:
    case KEY_SUSPEND:
    case KEY_UNDO:
    notFound:
924
        WINE_FIXME("Not done yet (%o)\n", inchar);
925 926
        break;
    default:
927
        WINE_ERR("Unknown val (%o)\n", inchar);
928 929
        break;
    }
930
    return numEvent;
931 932 933
}

/******************************************************************
934
 *		input_thread
935
 */
936
static DWORD CALLBACK input_thread( void *arg )
937
{
938
    struct inner_data* data = arg;
939 940 941 942
    int		        inchar;
    INPUT_RECORD        ir[8];
    unsigned		numEvent;
    DWORD               n;
943 944 945 946 947 948 949 950
    struct pollfd pfd[2];

    pfd[0].fd = 0;
    pfd[0].events = POLLIN;
    pfd[1].fd = PRIVATE(data)->sync_pipe[0];
    pfd[1].events = POLLHUP;

    for (;;)
951
    {
952 953 954 955 956 957
        pfd[0].revents = pfd[1].revents = 0;
        if (poll( pfd, 2, -1 ) == -1) break;
        if (pfd[0].revents & (POLLHUP|POLLERR)) break;
        if (pfd[1].revents & (POLLHUP|POLLERR)) break;
        if (!(pfd[0].revents & POLLIN)) continue;

958
        /* we're called from input thread (not main thread), so force unique access */
959
        EnterCriticalSection(&PRIVATE(data)->lock);
960 961 962
        if ((inchar = wgetch(stdscr)) != ERR)
        {
            WINE_TRACE("Got o%o (0x%x)\n", inchar,inchar);
963

964 965 966 967
            if (inchar >= KEY_MIN && inchar <= KEY_MAX)
                numEvent = WCCURSES_FillCode(data, ir, inchar);
            else
                numEvent = WCCURSES_FillSimpleChar(ir, inchar);
968

969 970
            if (numEvent) WriteConsoleInputW(data->hConIn, ir, numEvent, &n);
        }
971
        LeaveCriticalSection(&PRIVATE(data)->lock);
972
    }
973 974
    close( PRIVATE(data)->sync_pipe[0] );
    return 0;
975 976 977
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
978
 *		WCCURSES_DeleteBackend
979 980 981
 *
 *
 */
Eric Pouech's avatar
Eric Pouech committed
982
static void WCCURSES_DeleteBackend(struct inner_data* data)
983 984 985
{
    if (!PRIVATE(data)) return;

986 987 988 989 990 991
    if (PRIVATE(data)->input_thread)
    {
        close( PRIVATE(data)->sync_pipe[1] );
        WaitForSingleObject( PRIVATE(data)->input_thread, INFINITE );
        CloseHandle( PRIVATE(data)->input_thread );
    }
992
    PRIVATE(data)->lock.DebugInfo->Spare[0] = 0;
993
    DeleteCriticalSection(&PRIVATE(data)->lock);
994 995

    delwin(PRIVATE(data)->pad);
996 997 998 999 1000 1001
#ifdef HAVE_MOUSEMASK
    {
        mmask_t mm;
        mousemask(PRIVATE(data)->initial_mouse_mask, &mm);
    }
#endif
1002 1003
    endwin();

1004
    if (data->hWnd) DestroyWindow(data->hWnd);
1005 1006
    HeapFree(GetProcessHeap(), 0, PRIVATE(data)->line);
    HeapFree(GetProcessHeap(), 0, PRIVATE(data));
1007
    data->private = NULL;
1008 1009 1010
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
1011
 *		WCCURSES_MainLoop
1012 1013 1014
 *
 *
 */
Eric Pouech's avatar
Eric Pouech committed
1015
static int WCCURSES_MainLoop(struct inner_data* data)
1016
{
1017 1018 1019
    DWORD       id;

    WCCURSES_Resize(data);
1020

1021
    if (pipe( PRIVATE(data)->sync_pipe ) == -1) return 1;
1022
    PRIVATE(data)->input_thread = CreateThread( NULL, 0, input_thread, data, 0, &id );
1023

1024
    while (!data->dying && WaitForSingleObject(data->hSynchro, INFINITE) == WAIT_OBJECT_0)
1025
    {
1026
        EnterCriticalSection(&PRIVATE(data)->lock);
1027
        WINECON_GrabChanges(data);
1028
        LeaveCriticalSection(&PRIVATE(data)->lock);
1029
    }
1030 1031 1032 1033 1034 1035

    close( PRIVATE(data)->sync_pipe[1] );
    WaitForSingleObject( PRIVATE(data)->input_thread, INFINITE );
    CloseHandle( PRIVATE(data)->input_thread );
    PRIVATE(data)->input_thread = 0;
    return 0;
1036 1037 1038
}

/******************************************************************
Eric Pouech's avatar
Eric Pouech committed
1039
 *		WCCURSES_InitBackend
1040 1041 1042 1043
 *
 * Initialisation part II: creation of window.
 *
 */
1044
enum init_return WCCURSES_InitBackend(struct inner_data* data)
1045
{
1046 1047
    static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};

1048
    if( !WCCURSES_bind_libcurses() )
1049
        return init_not_supported;
1050

1051
    data->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct inner_data_curse));
1052
    if (!data->private) return init_failed;
1053

Eric Pouech's avatar
Eric Pouech committed
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
    data->fnMainLoop           = WCCURSES_MainLoop;
    data->fnPosCursor          = WCCURSES_PosCursor;
    data->fnShapeCursor        = WCCURSES_ShapeCursor;
    data->fnComputePositions   = WCCURSES_ComputePositions;
    data->fnRefresh            = WCCURSES_Refresh;
    data->fnResizeScreenBuffer = WCCURSES_ResizeScreenBuffer;
    data->fnSetTitle           = WCCURSES_SetTitle;
    data->fnScroll             = WCCURSES_Scroll;
    data->fnSetFont            = WCCURSES_SetFont;
    data->fnDeleteBackend      = WCCURSES_DeleteBackend;
1064 1065
    data->hWnd                 = CreateWindowW(messageW, NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0,
                                               GetModuleHandleW(0), NULL);
1066

1067 1068 1069 1070
    /* FIXME: should find a good way to enable buffer scrolling
     * For the time being, setting this to 1 will allow scrolling up/down 
     * on buffer with F11/F12.
     */
1071
    /* PRIVATE(data)->allow_scroll = 1; */
1072

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
    initscr();

    /* creating the basic colors - FIXME intensity not handled yet */
    if (has_colors())
    {
        int i, j;

        start_color();
        for (i = 0; i < 8; i++)
            for (j = 0; j < 8; j++)
                init_pair(i | (j << 3), i, j);
    }

    raw();
    noecho();
    intrflush(stdscr, FALSE);
    nodelay(stdscr, TRUE);
    keypad(stdscr, TRUE);
1091
#ifdef HAVE_MOUSEMASK
1092 1093
    if (data->curcfg.quick_edit)
    {
1094
        mmask_t mm;
1095 1096 1097 1098
        mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|
                  BUTTON2_PRESSED|BUTTON2_RELEASED|
                  BUTTON3_PRESSED|BUTTON3_RELEASED|
                  BUTTON_SHIFT|BUTTON_CTRL|BUTTON_ALT|REPORT_MOUSE_POSITION,
1099
                  &mm);
1100 1101 1102 1103 1104
        /* no click event generation... we just need button up/down events
         * it doesn't seem that mouseinterval(-1) behaves as documented... 
         * 0 seems to be better value to disable click event generation
         */
        mouseinterval(0);
1105
        PRIVATE(data)->initial_mouse_mask = mm;
1106 1107 1108
    }
    else
    {
1109 1110 1111
        mmask_t mm;
        mousemask(0, &mm);
        PRIVATE(data)->initial_mouse_mask = mm;
1112
    }
1113
#endif
1114
    InitializeCriticalSection(&PRIVATE(data)->lock);
1115
    PRIVATE(data)->lock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": curses");
1116

1117
    return init_success;
1118 1119 1120
}

#else
1121
enum init_return WCCURSES_InitBackend(struct inner_data* data)
1122
{
1123 1124
    WINE_ERR("(n)curses was not found at configuration time.\n"
             "If you want (n)curses support, please install relevant packages.\n");
1125
    return init_not_supported;
1126 1127
}
#endif