2 * a GUI application for displaying a console
5 * Copyright 2002 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * 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
22 /* Known issues & FIXME:
23 * - not all key mapping functions have been written
24 * - allow dyn loading of curses library (extreme care should be taken for
25 * functions which can be implemented as macros)
26 * - finish buffer scrolling (mainly, need to decide of a nice way for
27 * requesting the UP/DOWN operations
28 * - Resizing (unix) terminal does not change (Win32) console size.
29 * - Initial console size comes from registry and not from terminal size.
33 #include "wine/port.h"
40 #elif defined(HAVE_CURSES_H)
43 #undef KEY_EVENT /* avoid redefinition warning */
50 #include "winecon_private.h"
52 #include "wine/library.h"
53 #include "wine/server.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(curses);
58 #define PRIVATE(data) ((struct inner_data_curse*)((data)->private))
60 #if defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H)
63 # define CURSES_NAME "ncurses"
65 # define CURSES_NAME "curses"
68 struct inner_data_curse
70 mmask_t initial_mouse_mask;
78 static void *nc_handle = NULL;
80 #define MAKE_FUNCPTR(f) static typeof(f) * p_##f;
82 MAKE_FUNCPTR(curs_set)
85 MAKE_FUNCPTR(getmouse)
86 MAKE_FUNCPTR(has_colors)
87 MAKE_FUNCPTR(init_pair)
92 MAKE_FUNCPTR(intrflush)
95 MAKE_FUNCPTR(mouseinterval)
96 MAKE_FUNCPTR(mousemask)
104 MAKE_FUNCPTR(prefresh)
106 MAKE_FUNCPTR(start_color)
108 MAKE_FUNCPTR(waddchnstr)
114 /**********************************************************************/
116 static BOOL WCCURSES_bind_libcurses(void)
118 #ifdef HAVE_NCURSES_H
119 static const char *ncname = SONAME_LIBNCURSES;
121 static const char *ncname = SONAME_LIBCURSES;
124 nc_handle = wine_dlopen(ncname, RTLD_NOW, NULL, 0);
127 WINE_MESSAGE("Wine cannot find the " CURSES_NAME " library (%s).\n",
132 #define LOAD_FUNCPTR(f) \
133 if((p_##f = wine_dlsym(nc_handle, #f, NULL, 0)) == NULL) \
135 WINE_WARN("Can't find symbol %s\n", #f); \
136 goto sym_not_found; \
139 LOAD_FUNCPTR(curs_set)
142 LOAD_FUNCPTR(getmouse)
143 LOAD_FUNCPTR(has_colors)
144 LOAD_FUNCPTR(init_pair)
146 LOAD_FUNCPTR(initscr)
149 LOAD_FUNCPTR(intrflush)
152 LOAD_FUNCPTR(mouseinterval)
153 LOAD_FUNCPTR(mousemask)
156 LOAD_FUNCPTR(nodelay)
161 LOAD_FUNCPTR(prefresh)
163 LOAD_FUNCPTR(start_color)
165 LOAD_FUNCPTR(waddchnstr)
175 "Wine cannot find certain functions that it needs inside the "
176 CURSES_NAME "\nlibrary. To enable Wine to use " CURSES_NAME
177 " please upgrade your " CURSES_NAME "\nlibraries\n");
178 wine_dlclose(nc_handle, NULL, 0);
183 #define curs_set p_curs_set
184 #define delwin p_delwin
185 #define endwin p_endwin
186 #define getmouse p_getmouse
187 #define has_colors p_has_colors
188 #define init_pair p_init_pair
190 #define initscr p_initscr
193 #define intrflush p_intrflush
195 #define keypad p_keypad
196 #define mouseinterval p_mouseinterval
197 #define mousemask p_mousemask
198 #define newpad p_newpad
200 #define nodelay p_nodelay
203 #define noecho p_noecho
205 #define prefresh p_prefresh
207 #define start_color p_start_color
208 #define stdscr (*p_stdscr)
209 #define waddchnstr p_waddchnstr
210 #define wmove p_wmove
211 #define wgetch p_wgetch
213 /******************************************************************
214 * WCCURSES_ResizeScreenBuffer
218 static void WCCURSES_ResizeScreenBuffer(struct inner_data* data)
220 /* reallocate a new pad. next event would redraw the whole pad */
221 if (PRIVATE(data)->pad) delwin(PRIVATE(data)->pad);
222 PRIVATE(data)->pad = newpad(data->curcfg.sb_height, data->curcfg.sb_width);
223 if (!PRIVATE(data)->pad)
224 WINE_FIXME("Cannot create pad\n");
225 if (PRIVATE(data)->line)
226 PRIVATE(data)->line = HeapReAlloc(GetProcessHeap(), 0, PRIVATE(data)->line,
227 sizeof(chtype) * data->curcfg.sb_width);
229 PRIVATE(data)->line = HeapAlloc(GetProcessHeap(), 0,
230 sizeof(chtype) * data->curcfg.sb_width);
233 /******************************************************************
236 * Set a new position for the cursor (and refresh any modified part of our pad)
238 static void WCCURSES_PosCursor(const struct inner_data* data)
243 if (data->curcfg.cursor_visible &&
244 data->cursor.Y >= data->curcfg.win_pos.Y &&
245 data->cursor.Y < data->curcfg.win_pos.Y + data->curcfg.win_height &&
246 data->cursor.X >= data->curcfg.win_pos.X &&
247 data->cursor.X < data->curcfg.win_pos.X + data->curcfg.win_width)
249 if (curs_set(2) == ERR) curs_set(1);
250 wmove(PRIVATE(data)->pad, data->cursor.Y, data->cursor.X);
256 getmaxyx(stdscr, scr_height, scr_width);
257 prefresh(PRIVATE(data)->pad,
258 data->curcfg.win_pos.Y, data->curcfg.win_pos.X,
260 min(scr_height, data->curcfg.win_height) - 1,
261 min(scr_width, data->curcfg.win_width) - 1);
264 /******************************************************************
265 * WCCURSES_ShapeCursor
267 * Sets a new shape for the cursor
269 static void WCCURSES_ShapeCursor(struct inner_data* data, int size, int vis, BOOL force)
271 /* we can't do much about the size... */
272 data->curcfg.cursor_size = size;
273 data->curcfg.cursor_visible = vis ? TRUE : FALSE;
274 WCCURSES_PosCursor(data);
277 /******************************************************************
278 * WCCURSES_ComputePositions
280 * Recomputes all the components (mainly scroll bars) positions
282 static void WCCURSES_ComputePositions(struct inner_data* data)
286 getmaxyx(stdscr, y, x);
287 if ((data->curcfg.win_height && y < data->curcfg.win_height) ||
288 (data->curcfg.win_width && x < data->curcfg.win_width))
292 WINE_WARN("Window too large (%dx%d), adjusting to curses' size (%dx%d)\n",
293 data->curcfg.win_width, data->curcfg.win_height, x, y);
294 pos.Left = pos.Top = 0;
295 pos.Right = x - 1; pos.Bottom = y - 1;
296 SetConsoleWindowInfo(data->hConOut, FALSE, &pos);
297 return; /* we'll get called again upon event for new window size */
299 if (PRIVATE(data)->pad) WCCURSES_PosCursor(data);
302 /******************************************************************
305 * Sets the title to the wine console
307 static void WCCURSES_SetTitle(const struct inner_data* data)
311 if (WINECON_GetConsoleTitle(data->hConIn, wbuf, sizeof(wbuf)/sizeof(WCHAR)))
315 WideCharToMultiByte(CP_ACP, 0, wbuf, -1, buffer, sizeof(buffer),
317 fputs("\033]2;", stdout);
318 fputs(buffer, stdout);
324 /******************************************************************
329 static void WCCURSES_Refresh(const struct inner_data* data, int tp, int bm)
337 for (y = tp; y <= bm; y++)
339 cell = &data->cells[y * data->curcfg.sb_width];
340 for (x = 0; x < data->curcfg.sb_width; x++)
342 WideCharToMultiByte(CP_ACP, 0, &cell[x].Char.UnicodeChar, 1,
344 attr = ((BYTE)ch < 32 || (BYTE)ch > 127) ? 32 : (BYTE)ch;
346 if (cell[x].Attributes & FOREGROUND_RED) attr |= COLOR_PAIR(COLOR_RED);
347 if (cell[x].Attributes & FOREGROUND_BLUE) attr |= COLOR_PAIR(COLOR_BLUE);
348 if (cell[x].Attributes & FOREGROUND_GREEN) attr |= COLOR_PAIR(COLOR_GREEN);
349 if (cell[x].Attributes & BACKGROUND_RED) attr |= COLOR_PAIR(COLOR_RED << 3);
350 if (cell[x].Attributes & BACKGROUND_BLUE) attr |= COLOR_PAIR(COLOR_BLUE << 3);
351 if (cell[x].Attributes & BACKGROUND_GREEN) attr |= COLOR_PAIR(COLOR_GREEN << 3);
353 if (cell[x].Attributes & FOREGROUND_INTENSITY) attr |= A_BOLD;
354 PRIVATE(data)->line[x] = attr;
356 mvwaddchnstr(PRIVATE(data)->pad, y, 0, PRIVATE(data)->line, data->curcfg.sb_width);
359 WCCURSES_PosCursor(data);
362 /******************************************************************
367 static void WCCURSES_Scroll(struct inner_data* data, int pos, BOOL horz)
371 data->curcfg.win_pos.X = pos;
375 data->curcfg.win_pos.Y = pos;
377 WCCURSES_PosCursor(data);
380 /******************************************************************
385 static void WCCURSES_SetFont(struct inner_data* data, const WCHAR* font,
386 unsigned height, unsigned weight)
388 /* FIXME: really not much to do ? */
391 /******************************************************************
396 static void WCCURSES_ScrollV(struct inner_data* data, int delta)
398 int pos = data->curcfg.win_pos.Y;
401 if (pos < 0) pos = 0;
402 if (pos > data->curcfg.sb_height - data->curcfg.win_height)
403 pos = data->curcfg.sb_height - data->curcfg.win_height;
404 if (pos != data->curcfg.win_pos.Y)
406 data->curcfg.win_pos.Y = pos;
407 WCCURSES_PosCursor(data);
408 WINECON_NotifyWindowChange(data);
412 /* Ascii -> VK, generated by calling VkKeyScanA(i) */
413 static int vkkeyscan_table[256] =
415 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,
416 0,32,305,478,307,308,309,311,222,313,304,312,443,188,189,190,191,48,
417 49,50,51,52,53,54,55,56,57,442,186,444,187,446,447,306,321,322,323,
418 324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,
419 341,342,343,344,345,346,219,220,221,310,445,192,65,66,67,68,69,70,71,
420 72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,475,476,477,
421 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,
422 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,
423 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,
424 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
427 static int mapvkey_0[256] =
429 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,
430 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,
431 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,
432 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,
433 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,
434 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,
435 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,
436 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,
437 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
440 /******************************************************************
441 * WCCURSES_InitComplexChar
445 static inline void WCCURSES_InitComplexChar(INPUT_RECORD* ir, BOOL down, WORD vk, WORD kc, DWORD cks)
447 ir->EventType = KEY_EVENT;
448 ir->Event.KeyEvent.bKeyDown = down;
449 ir->Event.KeyEvent.wRepeatCount = 1;
451 ir->Event.KeyEvent.wVirtualScanCode = vk;
452 ir->Event.KeyEvent.wVirtualKeyCode = kc;
453 ir->Event.KeyEvent.dwControlKeyState = cks;
454 ir->Event.KeyEvent.uChar.UnicodeChar = 0;
457 /******************************************************************
458 * WCCURSES_FillSimpleChar
462 static unsigned WCCURSES_FillSimpleChar(INPUT_RECORD* ir, unsigned real_inchar)
466 unsigned numEvent = 0;
471 case 9: inchar = real_inchar;
472 real_inchar = 27; /* so that we don't think key is ctrl- something */
474 case 10: inchar = '\r';
475 real_inchar = 27; /* Fixme: so that we don't think key is ctrl- something */
477 case 127: inchar = '\b';
480 /* we assume that ESC & and the second character are atomically
481 * generated otherwise, we'll have a race here. FIXME: This gives 1 sec. delay
482 * because curses looks for a second character.
484 if ((inchar = wgetch(stdscr)) != ERR)
486 /* we got a alt-something key... */
487 cks = LEFT_ALT_PRESSED;
493 inchar = real_inchar;
496 if ((inchar & ~0xFF) != 0) WINE_FIXME("What a char (%u)\n", inchar);
497 vk = vkkeyscan_table[inchar];
499 WCCURSES_InitComplexChar(&ir[numEvent++], 1, 0x2a, 0x10, SHIFT_PRESSED);
500 if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
501 WCCURSES_InitComplexChar(&ir[numEvent++], 1, 0x1d, 0x11, LEFT_CTRL_PRESSED);
503 WCCURSES_InitComplexChar(&ir[numEvent++], 1, 0x38, 0x12, LEFT_ALT_PRESSED);
505 ir[numEvent].EventType = KEY_EVENT;
506 ir[numEvent].Event.KeyEvent.bKeyDown = 1;
507 ir[numEvent].Event.KeyEvent.wRepeatCount = 1;
508 ir[numEvent].Event.KeyEvent.dwControlKeyState = cks;
510 ir[numEvent].Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;
511 if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
512 ir[numEvent].Event.KeyEvent.dwControlKeyState |= LEFT_CTRL_PRESSED;
514 ir[numEvent].Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
515 ir[numEvent].Event.KeyEvent.wVirtualKeyCode = vk;
516 ir[numEvent].Event.KeyEvent.wVirtualScanCode = mapvkey_0[vk & 0x00ff]; /* VirtualKeyCodes to ScanCode */
517 ir[numEvent].Event.KeyEvent.uChar.UnicodeChar = (unsigned char)inchar;
519 ir[numEvent + 1] = ir[numEvent];
520 ir[numEvent + 1].Event.KeyEvent.bKeyDown = 0;
525 WCCURSES_InitComplexChar(&ir[numEvent++], 0, 0x38, 0x12, LEFT_ALT_PRESSED);
526 if ((vk & 0x0200) || (unsigned char)real_inchar <= 26)
527 WCCURSES_InitComplexChar(&ir[numEvent++], 0, 0x1d, 0x11, 0);
529 WCCURSES_InitComplexChar(&ir[numEvent++], 0, 0x2a, 0x10, 0);
534 /******************************************************************
535 * WCCURSES_FillComplexChar
539 static unsigned WCCURSES_FillComplexChar(INPUT_RECORD* ir, WORD vk, WORD kc, DWORD cks)
541 WCCURSES_InitComplexChar(&ir[0], 1, vk, kc, ENHANCED_KEY | cks);
542 WCCURSES_InitComplexChar(&ir[1], 0, vk, kc, ENHANCED_KEY | cks);
547 /******************************************************************
552 static unsigned WCCURSES_FillMouse(INPUT_RECORD* ir)
554 static unsigned bstate /* = 0 */;
555 static COORD pos /* = {0, 0} */;
559 if (getmouse(&mevt) == ERR)
562 WINE_TRACE("[%u]: (%d, %d) %08lx\n",
563 mevt.id, mevt.x, mevt.y, (unsigned long)mevt.bstate);
565 /* macros to ease mapping ncurse button numbering to windows's one */
566 #define BTN1_BIT FROM_LEFT_1ST_BUTTON_PRESSED
567 #define BTN2_BIT RIGHTMOST_BUTTON_PRESSED
568 #define BTN3_BIT FROM_LEFT_2ND_BUTTON_PRESSED
569 #define BTN4_BIT 0 /* not done yet */
571 if (mevt.bstate & BUTTON1_PRESSED) bstate |= BTN1_BIT;
572 if (mevt.bstate & BUTTON1_RELEASED) bstate &= ~BTN1_BIT;
573 if (mevt.bstate & BUTTON2_PRESSED) bstate |= BTN2_BIT;
574 if (mevt.bstate & BUTTON2_RELEASED) bstate &= ~BTN2_BIT;
575 if (mevt.bstate & BUTTON3_PRESSED) bstate |= BTN3_BIT;
576 if (mevt.bstate & BUTTON3_RELEASED) bstate &= ~BTN3_BIT;
578 ir->EventType = MOUSE_EVENT;
579 ir->Event.MouseEvent.dwMousePosition.X = mevt.x;
580 ir->Event.MouseEvent.dwMousePosition.Y = mevt.y;
582 ir->Event.MouseEvent.dwButtonState = bstate;
584 /* partial conversion */
585 ir->Event.MouseEvent.dwControlKeyState = 0;
586 if (mevt.bstate & BUTTON_SHIFT) ir->Event.MouseEvent.dwControlKeyState |= SHIFT_PRESSED;
587 /* choose to map to left ctrl... could use both ? */
588 if (mevt.bstate & BUTTON_CTRL) ir->Event.MouseEvent.dwControlKeyState |= LEFT_CTRL_PRESSED;
589 /* choose to map to left alt... could use both ? */
590 if (mevt.bstate & BUTTON_ALT) ir->Event.MouseEvent.dwControlKeyState |= LEFT_ALT_PRESSED;
591 /* FIXME: unsupported yet flags: CAPSLOCK_ON, ENHANCED_KEY (??), NUMLOCK_ON, SCROLLLOCK_ON
592 * could be reported from the key events...
595 ir->Event.MouseEvent.dwEventFlags = 0;
596 /* FIXME: we no longer generate double click events */
598 if (!(mevt.bstate & (BUTTON1_PRESSED|BUTTON1_RELEASED|BUTTON2_PRESSED|BUTTON2_RELEASED|BUTTON3_PRESSED|BUTTON3_RELEASED)) &&
599 (mevt.x != pos.X || mevt.y != pos.Y))
601 ir->Event.MouseEvent.dwEventFlags |= MOUSE_MOVED;
603 pos.X = mevt.x; pos.Y = mevt.y;
608 /******************************************************************
613 static unsigned WCCURSES_FillCode(struct inner_data* data, INPUT_RECORD* ir, int inchar)
615 unsigned numEvent = 0;
622 numEvent = WCCURSES_FillComplexChar(ir, 0x50, 0x28, 0);
625 numEvent = WCCURSES_FillComplexChar(ir, 0x48, 0x26, 0);
628 numEvent = WCCURSES_FillComplexChar(ir, 0x4b, 0x25, 0);
631 numEvent = WCCURSES_FillComplexChar(ir, 0x4d, 0x27, 0);
634 numEvent = WCCURSES_FillComplexChar(ir, 0x47, 0x24, 0);
637 numEvent = WCCURSES_FillSimpleChar(ir, 127);
640 case KEY_F0: /* up to F63 */
653 numEvent = WCCURSES_FillComplexChar(ir, 0x3b + inchar - KEY_F(1),
654 0x70 + inchar - KEY_F(1), 0);
658 if (PRIVATE(data)->allow_scroll)
660 WCCURSES_ScrollV(data, inchar == KEY_F(11) ? 8 : -8);
664 numEvent = WCCURSES_FillComplexChar(ir, 0xd9 + inchar - KEY_F(11),
665 0x7a + inchar - KEY_F(11), 0);
674 numEvent = WCCURSES_FillComplexChar(ir, 0x53, 0x2e, 0);
677 numEvent = WCCURSES_FillComplexChar(ir, 0x52, 0x2d, 0);
689 numEvent = WCCURSES_FillComplexChar(ir, 0x51, 0x22, 0);
692 numEvent = WCCURSES_FillComplexChar(ir, 0x49, 0x21, 0);
709 case KEY_BTAB: /* shift tab */
710 numEvent = WCCURSES_FillSimpleChar(ir, 0x9);
711 ir[0].Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;
712 ir[1].Event.KeyEvent.dwControlKeyState |= SHIFT_PRESSED;
713 if (numEvent != 2) WINE_ERR("FillsimpleChar has changed");
725 numEvent = WCCURSES_FillComplexChar(ir, 0x4f, 0x23, 0);
736 numEvent = WCCURSES_FillMouse(ir);
760 numEvent = WCCURSES_FillComplexChar(ir, 0x53, 0x2e, SHIFT_PRESSED);
767 numEvent = WCCURSES_FillComplexChar(ir, 0x4f, 0x23, SHIFT_PRESSED);
777 numEvent = WCCURSES_FillComplexChar(ir, 0x47, 0x24, SHIFT_PRESSED);
780 numEvent = WCCURSES_FillComplexChar(ir, 0x52, 0x2d, SHIFT_PRESSED);
783 numEvent = WCCURSES_FillComplexChar(ir, 0x4b, 0x25, SHIFT_PRESSED);
797 numEvent = WCCURSES_FillComplexChar(ir, 0x4d, 0x27, SHIFT_PRESSED);
807 WINE_FIXME("Not done yet (%o)\n", inchar);
810 WINE_ERR("Unknown val (%o)\n", inchar);
816 /******************************************************************
821 static void WCCURSES_GetEvents(struct inner_data* data)
828 if ((inchar = wgetch(stdscr)) == ERR) {WINE_FIXME("Ooch. somebody beat us\n");return;}
830 WINE_TRACE("Got o%o (0x%x)\n", inchar,inchar);
832 if (inchar & KEY_CODE_YES)
834 numEvent = WCCURSES_FillCode(data, ir, inchar);
838 numEvent = WCCURSES_FillSimpleChar(ir, inchar);
841 WriteConsoleInput(data->hConIn, ir, numEvent, &n);
844 /******************************************************************
845 * WCCURSES_DeleteBackend
849 static void WCCURSES_DeleteBackend(struct inner_data* data)
853 if (!PRIVATE(data)) return;
855 CloseHandle(PRIVATE(data)->hInput);
857 delwin(PRIVATE(data)->pad);
858 mousemask(PRIVATE(data)->initial_mouse_mask, &mm);
861 HeapFree(GetProcessHeap(), 0, PRIVATE(data)->line);
862 HeapFree(GetProcessHeap(), 0, PRIVATE(data));
863 data->private = NULL;
866 /******************************************************************
871 static int WCCURSES_MainLoop(struct inner_data* data)
875 hin[0] = PRIVATE(data)->hInput;
876 hin[1] = data->hSynchro;
880 unsigned ret = WaitForMultipleObjects(2, hin, FALSE, INFINITE);
884 WCCURSES_GetEvents(data);
886 case WAIT_OBJECT_0+1:
887 if (!WINECON_GrabChanges(data)) return 0;
890 WINE_ERR("got pb\n");
897 /******************************************************************
898 * WCCURSES_InitBackend
900 * Initialisation part II: creation of window.
903 enum init_return WCCURSES_InitBackend(struct inner_data* data)
905 if( !WCCURSES_bind_libcurses() )
908 data->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct inner_data_curse));
909 if (!data->private) return init_failed;
911 data->fnMainLoop = WCCURSES_MainLoop;
912 data->fnPosCursor = WCCURSES_PosCursor;
913 data->fnShapeCursor = WCCURSES_ShapeCursor;
914 data->fnComputePositions = WCCURSES_ComputePositions;
915 data->fnRefresh = WCCURSES_Refresh;
916 data->fnResizeScreenBuffer = WCCURSES_ResizeScreenBuffer;
917 data->fnSetTitle = WCCURSES_SetTitle;
918 data->fnScroll = WCCURSES_Scroll;
919 data->fnSetFont = WCCURSES_SetFont;
920 data->fnDeleteBackend = WCCURSES_DeleteBackend;
922 if (wine_server_fd_to_handle(0, GENERIC_READ|SYNCHRONIZE, 0,
923 (obj_handle_t*)&PRIVATE(data)->hInput))
925 WINE_FIXME("Cannot open 0\n");
929 /* FIXME: should find a good way to enable buffer scrolling
930 * For the time being, setting this to 1 will allow scrolling up/down
931 * on buffer with F11/F12.
933 /* PRIVATE(data)->allow_scroll = 1; */
937 /* creating the basic colors - FIXME intensity not handled yet */
943 for (i = 0; i < 8; i++)
944 for (j = 0; j < 8; j++)
945 init_pair(i | (j << 3), i, j);
950 intrflush(stdscr, FALSE);
951 nodelay(stdscr, TRUE);
952 keypad(stdscr, TRUE);
953 if (data->curcfg.quick_edit)
955 mousemask(BUTTON1_PRESSED|BUTTON1_RELEASED|
956 BUTTON2_PRESSED|BUTTON2_RELEASED|
957 BUTTON3_PRESSED|BUTTON3_RELEASED|
958 BUTTON_SHIFT|BUTTON_CTRL|BUTTON_ALT|REPORT_MOUSE_POSITION,
959 &PRIVATE(data)->initial_mouse_mask);
960 /* no click event generation... we just need button up/down events
961 * it doesn't seem that mouseinterval(-1) behaves as documented...
962 * 0 seems to be better value to disable click event generation
968 mousemask(0, &PRIVATE(data)->initial_mouse_mask);
975 enum init_return WCCURSES_InitBackend(struct inner_data* data)
977 return init_not_supported;