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 /* avoid redefinition warnings */
53 #include "winecon_private.h"
55 #include "wine/library.h"
56 #include "wine/server.h"
57 #include "wine/debug.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(curses
);
61 #define PRIVATE(data) ((struct inner_data_curse*)((data)->private))
63 #if defined(HAVE_CURSES_H) || defined(HAVE_NCURSES_H)
66 # define CURSES_NAME "ncurses"
68 # define CURSES_NAME "curses"
71 struct inner_data_curse
73 unsigned long initial_mouse_mask
;
81 static void *nc_handle
= NULL
;
83 #ifdef initscr /* work around Solaris breakage */
85 extern WINDOW
*initscr(void);
88 #define MAKE_FUNCPTR(f) static typeof(f) * p_##f;
90 MAKE_FUNCPTR(curs_set
)
99 MAKE_FUNCPTR(getmouse
)
100 MAKE_FUNCPTR(has_colors
)
101 MAKE_FUNCPTR(init_pair
)
102 MAKE_FUNCPTR(initscr
)
104 MAKE_FUNCPTR(intrflush
)
109 MAKE_FUNCPTR(nodelay
)
114 MAKE_FUNCPTR(prefresh
)
116 MAKE_FUNCPTR(start_color
)
118 MAKE_FUNCPTR(waddchnstr
)
121 #ifdef HAVE_MOUSEMASK
122 MAKE_FUNCPTR(mouseinterval
)
123 MAKE_FUNCPTR(mousemask
)
128 /**********************************************************************/
130 static BOOL
WCCURSES_bind_libcurses(void)
132 #ifdef HAVE_NCURSES_H
133 static const char *ncname
= SONAME_LIBNCURSES
;
135 static const char *ncname
= SONAME_LIBCURSES
;
138 nc_handle
= wine_dlopen(ncname
, RTLD_NOW
, NULL
, 0);
141 WINE_MESSAGE("Wine cannot find the " CURSES_NAME
" library (%s).\n",
146 #define LOAD_FUNCPTR(f) \
147 if((p_##f = wine_dlsym(nc_handle, #f, NULL, 0)) == NULL) \
149 WINE_WARN("Can't find symbol %s\n", #f); \
150 goto sym_not_found; \
153 LOAD_FUNCPTR(curs_set
)
157 LOAD_FUNCPTR(getmaxx
)
160 LOAD_FUNCPTR(getmaxy
)
162 LOAD_FUNCPTR(getmouse
)
163 LOAD_FUNCPTR(has_colors
)
164 LOAD_FUNCPTR(init_pair
)
165 LOAD_FUNCPTR(initscr
)
167 LOAD_FUNCPTR(intrflush
)
172 LOAD_FUNCPTR(nodelay
)
177 LOAD_FUNCPTR(prefresh
)
179 LOAD_FUNCPTR(start_color
)
181 LOAD_FUNCPTR(waddchnstr
)
184 #ifdef HAVE_MOUSEMASK
185 LOAD_FUNCPTR(mouseinterval
)
186 LOAD_FUNCPTR(mousemask
)
195 "Wine cannot find certain functions that it needs inside the "
196 CURSES_NAME
"\nlibrary. To enable Wine to use " CURSES_NAME
197 " please upgrade your " CURSES_NAME
"\nlibraries\n");
198 wine_dlclose(nc_handle
, NULL
, 0);
203 #define curs_set p_curs_set
204 #define delwin p_delwin
205 #define endwin p_endwin
207 #define getmaxx p_getmaxx
210 #define getmaxy p_getmaxy
212 #define getmouse p_getmouse
213 #define has_colors p_has_colors
214 #define init_pair p_init_pair
215 #define initscr p_initscr
217 #define intrflush p_intrflush
219 #define keypad p_keypad
220 #define mouseinterval p_mouseinterval
221 #define mousemask p_mousemask
222 #define newpad p_newpad
224 #define nodelay p_nodelay
227 #define noecho p_noecho
229 #define prefresh p_prefresh
231 #define start_color p_start_color
232 #define stdscr (*p_stdscr)
233 #define waddchnstr p_waddchnstr
234 #define wmove p_wmove
235 #define wgetch p_wgetch
237 /******************************************************************
238 * WCCURSES_ResizeScreenBuffer
242 static void WCCURSES_ResizeScreenBuffer(struct inner_data
* data
)
244 /* reallocate a new pad. next event would redraw the whole pad */
245 if (PRIVATE(data
)->pad
) delwin(PRIVATE(data
)->pad
);
246 PRIVATE(data
)->pad
= newpad(data
->curcfg
.sb_height
, data
->curcfg
.sb_width
);
247 if (!PRIVATE(data
)->pad
)
248 WINE_FIXME("Cannot create pad\n");
249 if (PRIVATE(data
)->line
)
250 PRIVATE(data
)->line
= HeapReAlloc(GetProcessHeap(), 0, PRIVATE(data
)->line
,
251 sizeof(chtype
) * data
->curcfg
.sb_width
);
253 PRIVATE(data
)->line
= HeapAlloc(GetProcessHeap(), 0,
254 sizeof(chtype
) * data
->curcfg
.sb_width
);
257 /******************************************************************
260 * Set a new position for the cursor (and refresh any modified part of our pad)
262 static void WCCURSES_PosCursor(const struct inner_data
* data
)
267 if (data
->curcfg
.cursor_visible
&&
268 data
->cursor
.Y
>= data
->curcfg
.win_pos
.Y
&&
269 data
->cursor
.Y
< data
->curcfg
.win_pos
.Y
+ data
->curcfg
.win_height
&&
270 data
->cursor
.X
>= data
->curcfg
.win_pos
.X
&&
271 data
->cursor
.X
< data
->curcfg
.win_pos
.X
+ data
->curcfg
.win_width
)
273 if (curs_set(2) == ERR
) curs_set(1);
274 wmove(PRIVATE(data
)->pad
, data
->cursor
.Y
, data
->cursor
.X
);
280 getmaxyx(stdscr
, scr_height
, scr_width
);
281 prefresh(PRIVATE(data
)->pad
,
282 data
->curcfg
.win_pos
.Y
, data
->curcfg
.win_pos
.X
,
284 min(scr_height
, data
->curcfg
.win_height
) - 1,
285 min(scr_width
, data
->curcfg
.win_width
) - 1);
288 /******************************************************************
289 * WCCURSES_ShapeCursor
291 * Sets a new shape for the cursor
293 static void WCCURSES_ShapeCursor(struct inner_data
* data
, int size
, int vis
, BOOL force
)
295 /* we can't do much about the size... */
296 data
->curcfg
.cursor_size
= size
;
297 data
->curcfg
.cursor_visible
= vis
? TRUE
: FALSE
;
298 WCCURSES_PosCursor(data
);
301 /******************************************************************
302 * WCCURSES_ComputePositions
304 * Recomputes all the components (mainly scroll bars) positions
306 static void WCCURSES_ComputePositions(struct inner_data
* data
)
310 getmaxyx(stdscr
, y
, x
);
311 if ((data
->curcfg
.win_height
&& y
< data
->curcfg
.win_height
) ||
312 (data
->curcfg
.win_width
&& x
< data
->curcfg
.win_width
))
316 WINE_WARN("Window too large (%dx%d), adjusting to curses' size (%dx%d)\n",
317 data
->curcfg
.win_width
, data
->curcfg
.win_height
, x
, y
);
318 pos
.Left
= pos
.Top
= 0;
319 pos
.Right
= x
- 1; pos
.Bottom
= y
- 1;
320 SetConsoleWindowInfo(data
->hConOut
, FALSE
, &pos
);
321 return; /* we'll get called again upon event for new window size */
323 if (PRIVATE(data
)->pad
) WCCURSES_PosCursor(data
);
326 /******************************************************************
329 * Sets the title to the wine console
331 static void WCCURSES_SetTitle(const struct inner_data
* data
)
335 if (WINECON_GetConsoleTitle(data
->hConIn
, wbuf
, sizeof(wbuf
)/sizeof(WCHAR
)))
339 WideCharToMultiByte(CP_ACP
, 0, wbuf
, -1, buffer
, sizeof(buffer
),
341 fputs("\033]2;", stdout
);
342 fputs(buffer
, stdout
);
348 /******************************************************************
353 static void WCCURSES_Refresh(const struct inner_data
* data
, int tp
, int bm
)
361 for (y
= tp
; y
<= bm
; y
++)
363 cell
= &data
->cells
[y
* data
->curcfg
.sb_width
];
364 for (x
= 0; x
< data
->curcfg
.sb_width
; x
++)
366 WideCharToMultiByte(CP_ACP
, 0, &cell
[x
].Char
.UnicodeChar
, 1,
368 attr
= ((BYTE
)ch
< 32 || (BYTE
)ch
> 127) ? 32 : (BYTE
)ch
;
370 if (cell
[x
].Attributes
& FOREGROUND_RED
) attr
|= COLOR_PAIR(COLOR_RED
);
371 if (cell
[x
].Attributes
& FOREGROUND_BLUE
) attr
|= COLOR_PAIR(COLOR_BLUE
);
372 if (cell
[x
].Attributes
& FOREGROUND_GREEN
) attr
|= COLOR_PAIR(COLOR_GREEN
);
373 if (cell
[x
].Attributes
& BACKGROUND_RED
) attr
|= COLOR_PAIR(COLOR_RED
<< 3);
374 if (cell
[x
].Attributes
& BACKGROUND_BLUE
) attr
|= COLOR_PAIR(COLOR_BLUE
<< 3);
375 if (cell
[x
].Attributes
& BACKGROUND_GREEN
) attr
|= COLOR_PAIR(COLOR_GREEN
<< 3);
377 if (cell
[x
].Attributes
& FOREGROUND_INTENSITY
) attr
|= A_BOLD
;
378 PRIVATE(data
)->line
[x
] = attr
;
380 mvwaddchnstr(PRIVATE(data
)->pad
, y
, 0, PRIVATE(data
)->line
, data
->curcfg
.sb_width
);
383 WCCURSES_PosCursor(data
);
386 /******************************************************************
391 static void WCCURSES_Scroll(struct inner_data
* data
, int pos
, BOOL horz
)
395 data
->curcfg
.win_pos
.X
= pos
;
399 data
->curcfg
.win_pos
.Y
= pos
;
401 WCCURSES_PosCursor(data
);
404 /******************************************************************
409 static void WCCURSES_SetFont(struct inner_data
* data
, const WCHAR
* font
,
410 unsigned height
, unsigned weight
)
412 /* FIXME: really not much to do ? */
415 /******************************************************************
420 static void WCCURSES_ScrollV(struct inner_data
* data
, int delta
)
422 int pos
= data
->curcfg
.win_pos
.Y
;
425 if (pos
< 0) pos
= 0;
426 if (pos
> data
->curcfg
.sb_height
- data
->curcfg
.win_height
)
427 pos
= data
->curcfg
.sb_height
- data
->curcfg
.win_height
;
428 if (pos
!= data
->curcfg
.win_pos
.Y
)
430 data
->curcfg
.win_pos
.Y
= pos
;
431 WCCURSES_PosCursor(data
);
432 WINECON_NotifyWindowChange(data
);
436 /* Ascii -> VK, generated by calling VkKeyScanA(i) */
437 static int vkkeyscan_table
[256] =
439 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,
440 0,32,305,478,307,308,309,311,222,313,304,312,443,188,189,190,191,48,
441 49,50,51,52,53,54,55,56,57,442,186,444,187,446,447,306,321,322,323,
442 324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,
443 341,342,343,344,345,346,219,220,221,310,445,192,65,66,67,68,69,70,71,
444 72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,475,476,477,
445 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,
446 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,
447 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,
448 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
451 static int mapvkey_0
[256] =
453 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,
454 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,
455 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,
456 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,
457 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,
458 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,
459 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,
460 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,
461 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
464 /******************************************************************
465 * WCCURSES_InitComplexChar
469 static inline void WCCURSES_InitComplexChar(INPUT_RECORD
* ir
, BOOL down
, WORD vk
, WORD kc
, DWORD cks
)
471 ir
->EventType
= KEY_EVENT
;
472 ir
->Event
.KeyEvent
.bKeyDown
= down
;
473 ir
->Event
.KeyEvent
.wRepeatCount
= 1;
475 ir
->Event
.KeyEvent
.wVirtualScanCode
= vk
;
476 ir
->Event
.KeyEvent
.wVirtualKeyCode
= kc
;
477 ir
->Event
.KeyEvent
.dwControlKeyState
= cks
;
478 ir
->Event
.KeyEvent
.uChar
.UnicodeChar
= 0;
481 /******************************************************************
482 * WCCURSES_FillSimpleChar
486 static unsigned WCCURSES_FillSimpleChar(INPUT_RECORD
* ir
, unsigned real_inchar
)
490 unsigned numEvent
= 0;
495 case 9: inchar
= real_inchar
;
496 real_inchar
= 27; /* so that we don't think key is ctrl- something */
498 case 10: inchar
= '\r';
499 real_inchar
= 27; /* Fixme: so that we don't think key is ctrl- something */
501 case 127: inchar
= '\b';
504 /* we assume that ESC & and the second character are atomically
505 * generated otherwise, we'll have a race here. FIXME: This gives 1 sec. delay
506 * because curses looks for a second character.
508 if ((inchar
= wgetch(stdscr
)) != ERR
)
510 /* we got a alt-something key... */
511 cks
= LEFT_ALT_PRESSED
;
517 inchar
= real_inchar
;
520 if ((inchar
& ~0xFF) != 0) WINE_FIXME("What a char (%u)\n", inchar
);
521 vk
= vkkeyscan_table
[inchar
];
523 WCCURSES_InitComplexChar(&ir
[numEvent
++], 1, 0x2a, 0x10, SHIFT_PRESSED
);
524 if ((vk
& 0x0200) || (unsigned char)real_inchar
<= 26)
525 WCCURSES_InitComplexChar(&ir
[numEvent
++], 1, 0x1d, 0x11, LEFT_CTRL_PRESSED
);
527 WCCURSES_InitComplexChar(&ir
[numEvent
++], 1, 0x38, 0x12, LEFT_ALT_PRESSED
);
529 ir
[numEvent
].EventType
= KEY_EVENT
;
530 ir
[numEvent
].Event
.KeyEvent
.bKeyDown
= 1;
531 ir
[numEvent
].Event
.KeyEvent
.wRepeatCount
= 1;
532 ir
[numEvent
].Event
.KeyEvent
.dwControlKeyState
= cks
;
534 ir
[numEvent
].Event
.KeyEvent
.dwControlKeyState
|= SHIFT_PRESSED
;
535 if ((vk
& 0x0200) || (unsigned char)real_inchar
<= 26)
536 ir
[numEvent
].Event
.KeyEvent
.dwControlKeyState
|= LEFT_CTRL_PRESSED
;
538 ir
[numEvent
].Event
.KeyEvent
.dwControlKeyState
|= LEFT_ALT_PRESSED
;
539 ir
[numEvent
].Event
.KeyEvent
.wVirtualKeyCode
= vk
;
540 ir
[numEvent
].Event
.KeyEvent
.wVirtualScanCode
= mapvkey_0
[vk
& 0x00ff]; /* VirtualKeyCodes to ScanCode */
541 ir
[numEvent
].Event
.KeyEvent
.uChar
.UnicodeChar
= (unsigned char)inchar
;
543 ir
[numEvent
+ 1] = ir
[numEvent
];
544 ir
[numEvent
+ 1].Event
.KeyEvent
.bKeyDown
= 0;
549 WCCURSES_InitComplexChar(&ir
[numEvent
++], 0, 0x38, 0x12, LEFT_ALT_PRESSED
);
550 if ((vk
& 0x0200) || (unsigned char)real_inchar
<= 26)
551 WCCURSES_InitComplexChar(&ir
[numEvent
++], 0, 0x1d, 0x11, 0);
553 WCCURSES_InitComplexChar(&ir
[numEvent
++], 0, 0x2a, 0x10, 0);
558 /******************************************************************
559 * WCCURSES_FillComplexChar
563 static unsigned WCCURSES_FillComplexChar(INPUT_RECORD
* ir
, WORD vk
, WORD kc
, DWORD cks
)
565 WCCURSES_InitComplexChar(&ir
[0], 1, vk
, kc
, ENHANCED_KEY
| cks
);
566 WCCURSES_InitComplexChar(&ir
[1], 0, vk
, kc
, ENHANCED_KEY
| cks
);
571 /******************************************************************
576 static unsigned WCCURSES_FillMouse(INPUT_RECORD
* ir
)
578 #ifdef HAVE_MOUSEMASK
579 static unsigned bstate
/* = 0 */;
580 static COORD pos
/* = {0, 0} */;
584 if (getmouse(&mevt
) == ERR
)
587 WINE_TRACE("[%u]: (%d, %d) %08lx\n",
588 mevt
.id
, mevt
.x
, mevt
.y
, (unsigned long)mevt
.bstate
);
590 /* macros to ease mapping ncurse button numbering to windows's one */
591 #define BTN1_BIT FROM_LEFT_1ST_BUTTON_PRESSED
592 #define BTN2_BIT RIGHTMOST_BUTTON_PRESSED
593 #define BTN3_BIT FROM_LEFT_2ND_BUTTON_PRESSED
594 #define BTN4_BIT 0 /* not done yet */
596 if (mevt
.bstate
& BUTTON1_PRESSED
) bstate
|= BTN1_BIT
;
597 if (mevt
.bstate
& BUTTON1_RELEASED
) bstate
&= ~BTN1_BIT
;
598 if (mevt
.bstate
& BUTTON2_PRESSED
) bstate
|= BTN2_BIT
;
599 if (mevt
.bstate
& BUTTON2_RELEASED
) bstate
&= ~BTN2_BIT
;
600 if (mevt
.bstate
& BUTTON3_PRESSED
) bstate
|= BTN3_BIT
;
601 if (mevt
.bstate
& BUTTON3_RELEASED
) bstate
&= ~BTN3_BIT
;
603 ir
->EventType
= MOUSE_EVENT
;
604 ir
->Event
.MouseEvent
.dwMousePosition
.X
= mevt
.x
;
605 ir
->Event
.MouseEvent
.dwMousePosition
.Y
= mevt
.y
;
607 ir
->Event
.MouseEvent
.dwButtonState
= bstate
;
609 /* partial conversion */
610 ir
->Event
.MouseEvent
.dwControlKeyState
= 0;
611 if (mevt
.bstate
& BUTTON_SHIFT
) ir
->Event
.MouseEvent
.dwControlKeyState
|= SHIFT_PRESSED
;
612 /* choose to map to left ctrl... could use both ? */
613 if (mevt
.bstate
& BUTTON_CTRL
) ir
->Event
.MouseEvent
.dwControlKeyState
|= LEFT_CTRL_PRESSED
;
614 /* choose to map to left alt... could use both ? */
615 if (mevt
.bstate
& BUTTON_ALT
) ir
->Event
.MouseEvent
.dwControlKeyState
|= LEFT_ALT_PRESSED
;
616 /* FIXME: unsupported yet flags: CAPSLOCK_ON, ENHANCED_KEY (??), NUMLOCK_ON, SCROLLLOCK_ON
617 * could be reported from the key events...
620 ir
->Event
.MouseEvent
.dwEventFlags
= 0;
621 /* FIXME: we no longer generate double click events */
623 if (!(mevt
.bstate
& (BUTTON1_PRESSED
|BUTTON1_RELEASED
|BUTTON2_PRESSED
|BUTTON2_RELEASED
|BUTTON3_PRESSED
|BUTTON3_RELEASED
)) &&
624 (mevt
.x
!= pos
.X
|| mevt
.y
!= pos
.Y
))
626 ir
->Event
.MouseEvent
.dwEventFlags
|= MOUSE_MOVED
;
628 pos
.X
= mevt
.x
; pos
.Y
= mevt
.y
;
636 /******************************************************************
641 static unsigned WCCURSES_FillCode(struct inner_data
* data
, INPUT_RECORD
* ir
, int inchar
)
643 unsigned numEvent
= 0;
650 numEvent
= WCCURSES_FillComplexChar(ir
, 0x50, 0x28, 0);
653 numEvent
= WCCURSES_FillComplexChar(ir
, 0x48, 0x26, 0);
656 numEvent
= WCCURSES_FillComplexChar(ir
, 0x4b, 0x25, 0);
659 numEvent
= WCCURSES_FillComplexChar(ir
, 0x4d, 0x27, 0);
662 numEvent
= WCCURSES_FillComplexChar(ir
, 0x47, 0x24, 0);
665 numEvent
= WCCURSES_FillSimpleChar(ir
, 127);
668 case KEY_F0
: /* up to F63 */
681 numEvent
= WCCURSES_FillComplexChar(ir
, 0x3b + inchar
- KEY_F(1),
682 0x70 + inchar
- KEY_F(1), 0);
686 if (PRIVATE(data
)->allow_scroll
)
688 WCCURSES_ScrollV(data
, inchar
== KEY_F(11) ? 8 : -8);
692 numEvent
= WCCURSES_FillComplexChar(ir
, 0xd9 + inchar
- KEY_F(11),
693 0x7a + inchar
- KEY_F(11), 0);
702 numEvent
= WCCURSES_FillComplexChar(ir
, 0x53, 0x2e, 0);
705 numEvent
= WCCURSES_FillComplexChar(ir
, 0x52, 0x2d, 0);
717 numEvent
= WCCURSES_FillComplexChar(ir
, 0x51, 0x22, 0);
720 numEvent
= WCCURSES_FillComplexChar(ir
, 0x49, 0x21, 0);
737 case KEY_BTAB
: /* shift tab */
738 numEvent
= WCCURSES_FillSimpleChar(ir
, 0x9);
739 ir
[0].Event
.KeyEvent
.dwControlKeyState
|= SHIFT_PRESSED
;
740 ir
[1].Event
.KeyEvent
.dwControlKeyState
|= SHIFT_PRESSED
;
741 if (numEvent
!= 2) WINE_ERR("FillsimpleChar has changed");
753 numEvent
= WCCURSES_FillComplexChar(ir
, 0x4f, 0x23, 0);
764 numEvent
= WCCURSES_FillMouse(ir
);
790 numEvent
= WCCURSES_FillComplexChar(ir
, 0x53, 0x2e, SHIFT_PRESSED
);
797 numEvent
= WCCURSES_FillComplexChar(ir
, 0x4f, 0x23, SHIFT_PRESSED
);
807 numEvent
= WCCURSES_FillComplexChar(ir
, 0x47, 0x24, SHIFT_PRESSED
);
810 numEvent
= WCCURSES_FillComplexChar(ir
, 0x52, 0x2d, SHIFT_PRESSED
);
813 numEvent
= WCCURSES_FillComplexChar(ir
, 0x4b, 0x25, SHIFT_PRESSED
);
827 numEvent
= WCCURSES_FillComplexChar(ir
, 0x4d, 0x27, SHIFT_PRESSED
);
837 WINE_FIXME("Not done yet (%o)\n", inchar
);
840 WINE_ERR("Unknown val (%o)\n", inchar
);
846 /******************************************************************
851 static void WCCURSES_GetEvents(struct inner_data
* data
)
858 if ((inchar
= wgetch(stdscr
)) == ERR
) {WINE_FIXME("Ooch. somebody beat us\n");return;}
860 WINE_TRACE("Got o%o (0x%x)\n", inchar
,inchar
);
862 if (inchar
>= KEY_MIN
&& inchar
<= KEY_MAX
)
864 numEvent
= WCCURSES_FillCode(data
, ir
, inchar
);
868 numEvent
= WCCURSES_FillSimpleChar(ir
, inchar
);
871 WriteConsoleInput(data
->hConIn
, ir
, numEvent
, &n
);
874 /******************************************************************
875 * WCCURSES_DeleteBackend
879 static void WCCURSES_DeleteBackend(struct inner_data
* data
)
881 if (!PRIVATE(data
)) return;
883 CloseHandle(PRIVATE(data
)->hInput
);
885 delwin(PRIVATE(data
)->pad
);
886 #ifdef HAVE_MOUSEMASK
889 mousemask(PRIVATE(data
)->initial_mouse_mask
, &mm
);
894 HeapFree(GetProcessHeap(), 0, PRIVATE(data
)->line
);
895 HeapFree(GetProcessHeap(), 0, PRIVATE(data
));
896 data
->private = NULL
;
899 /******************************************************************
904 static int WCCURSES_MainLoop(struct inner_data
* data
)
908 hin
[0] = PRIVATE(data
)->hInput
;
909 hin
[1] = data
->hSynchro
;
913 unsigned ret
= WaitForMultipleObjects(2, hin
, FALSE
, INFINITE
);
917 WCCURSES_GetEvents(data
);
919 case WAIT_OBJECT_0
+1:
920 if (!WINECON_GrabChanges(data
)) return 0;
923 WINE_ERR("got pb\n");
930 /******************************************************************
931 * WCCURSES_InitBackend
933 * Initialisation part II: creation of window.
936 enum init_return
WCCURSES_InitBackend(struct inner_data
* data
)
938 if( !WCCURSES_bind_libcurses() )
941 data
->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct inner_data_curse
));
942 if (!data
->private) return init_failed
;
944 data
->fnMainLoop
= WCCURSES_MainLoop
;
945 data
->fnPosCursor
= WCCURSES_PosCursor
;
946 data
->fnShapeCursor
= WCCURSES_ShapeCursor
;
947 data
->fnComputePositions
= WCCURSES_ComputePositions
;
948 data
->fnRefresh
= WCCURSES_Refresh
;
949 data
->fnResizeScreenBuffer
= WCCURSES_ResizeScreenBuffer
;
950 data
->fnSetTitle
= WCCURSES_SetTitle
;
951 data
->fnScroll
= WCCURSES_Scroll
;
952 data
->fnSetFont
= WCCURSES_SetFont
;
953 data
->fnDeleteBackend
= WCCURSES_DeleteBackend
;
955 if (wine_server_fd_to_handle(0, GENERIC_READ
|SYNCHRONIZE
, 0,
956 (obj_handle_t
*)&PRIVATE(data
)->hInput
))
958 WINE_FIXME("Cannot open 0\n");
962 /* FIXME: should find a good way to enable buffer scrolling
963 * For the time being, setting this to 1 will allow scrolling up/down
964 * on buffer with F11/F12.
966 /* PRIVATE(data)->allow_scroll = 1; */
970 /* creating the basic colors - FIXME intensity not handled yet */
976 for (i
= 0; i
< 8; i
++)
977 for (j
= 0; j
< 8; j
++)
978 init_pair(i
| (j
<< 3), i
, j
);
983 intrflush(stdscr
, FALSE
);
984 nodelay(stdscr
, TRUE
);
985 keypad(stdscr
, TRUE
);
986 #ifdef HAVE_MOUSEMASK
987 if (data
->curcfg
.quick_edit
)
990 mousemask(BUTTON1_PRESSED
|BUTTON1_RELEASED
|
991 BUTTON2_PRESSED
|BUTTON2_RELEASED
|
992 BUTTON3_PRESSED
|BUTTON3_RELEASED
|
993 BUTTON_SHIFT
|BUTTON_CTRL
|BUTTON_ALT
|REPORT_MOUSE_POSITION
,
995 /* no click event generation... we just need button up/down events
996 * it doesn't seem that mouseinterval(-1) behaves as documented...
997 * 0 seems to be better value to disable click event generation
1000 PRIVATE(data
)->initial_mouse_mask
= mm
;
1006 PRIVATE(data
)->initial_mouse_mask
= mm
;
1010 return init_success
;
1014 enum init_return
WCCURSES_InitBackend(struct inner_data
* data
)
1016 return init_not_supported
;