mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-14 21:39:43 +00:00
conhost: Initial support for creating console window.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
3c29108523
commit
bbd4196814
|
@ -1,8 +1,10 @@
|
|||
MODULE = conhost.exe
|
||||
IMPORTS = user32
|
||||
IMPORTS = user32 gdi32
|
||||
|
||||
EXTRADLLFLAGS = -mwindows -municode -mno-cygwin
|
||||
|
||||
C_SRCS = conhost.c
|
||||
C_SRCS = \
|
||||
conhost.c \
|
||||
window.c
|
||||
|
||||
RC_SRCS = version.rc
|
||||
|
|
|
@ -19,119 +19,15 @@
|
|||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <ntstatus.h>
|
||||
#define WIN32_NO_STATUS
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winuser.h>
|
||||
#include <winnls.h>
|
||||
#include <winternl.h>
|
||||
#include "conhost.h"
|
||||
|
||||
#include "wine/condrv.h"
|
||||
#include "wine/server.h"
|
||||
#include "wine/rbtree.h"
|
||||
#include "wine/debug.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(conhost);
|
||||
|
||||
struct history_line
|
||||
{
|
||||
size_t len;
|
||||
WCHAR text[1];
|
||||
};
|
||||
|
||||
struct font_info
|
||||
{
|
||||
short int width;
|
||||
short int height;
|
||||
short int weight;
|
||||
short int pitch_family;
|
||||
WCHAR *face_name;
|
||||
size_t face_len;
|
||||
};
|
||||
|
||||
struct edit_line
|
||||
{
|
||||
NTSTATUS status; /* edit status */
|
||||
WCHAR *buf; /* the line being edited */
|
||||
unsigned int len; /* number of chars in line */
|
||||
size_t size; /* buffer size */
|
||||
unsigned int cursor; /* offset for cursor in current line */
|
||||
WCHAR *yanked; /* yanked line */
|
||||
unsigned int mark; /* marked point (emacs mode only) */
|
||||
unsigned int history_index; /* history index */
|
||||
WCHAR *current_history; /* buffer for the recent history entry */
|
||||
BOOL insert_key; /* insert key state */
|
||||
BOOL insert_mode; /* insert mode */
|
||||
unsigned int update_begin; /* update region */
|
||||
unsigned int update_end;
|
||||
unsigned int end_offset; /* offset of the last written char */
|
||||
unsigned int home_x; /* home position */
|
||||
unsigned int home_y;
|
||||
};
|
||||
|
||||
struct console
|
||||
{
|
||||
HANDLE server; /* console server handle */
|
||||
unsigned int mode; /* input mode */
|
||||
struct screen_buffer *active; /* active screen buffer */
|
||||
int is_unix; /* UNIX terminal mode */
|
||||
INPUT_RECORD *records; /* input records */
|
||||
unsigned int record_count; /* number of input records */
|
||||
unsigned int record_size; /* size of input records buffer */
|
||||
WCHAR *read_buffer; /* buffer of data available for read */
|
||||
size_t read_buffer_count; /* size of available data */
|
||||
size_t read_buffer_size; /* size of buffer */
|
||||
unsigned int read_ioctl; /* current read ioctl */
|
||||
size_t pending_read; /* size of pending read buffer */
|
||||
struct edit_line edit_line; /* edit line context */
|
||||
WCHAR *title; /* console title */
|
||||
size_t title_len; /* length of console title */
|
||||
struct history_line **history; /* lines history */
|
||||
unsigned int history_size; /* number of entries in history array */
|
||||
unsigned int history_index; /* number of used entries in history array */
|
||||
unsigned int history_mode; /* mode of history (non zero means remove doubled strings */
|
||||
unsigned int edition_mode; /* index to edition mode flavors */
|
||||
unsigned int input_cp; /* console input codepage */
|
||||
unsigned int output_cp; /* console output codepage */
|
||||
unsigned int win; /* window handle if backend supports it */
|
||||
HANDLE input_thread; /* input thread handle */
|
||||
HANDLE tty_input; /* handle to tty input stream */
|
||||
HANDLE tty_output; /* handle to tty output stream */
|
||||
char tty_buffer[4096]; /* tty output buffer */
|
||||
size_t tty_buffer_count; /* tty buffer size */
|
||||
unsigned int tty_cursor_x; /* tty cursor position */
|
||||
unsigned int tty_cursor_y;
|
||||
unsigned int tty_attr; /* current tty char attributes */
|
||||
int tty_cursor_visible; /* tty cursor visibility flag */
|
||||
};
|
||||
|
||||
struct screen_buffer
|
||||
{
|
||||
struct console *console; /* console reference */
|
||||
unsigned int id; /* screen buffer id */
|
||||
unsigned int mode; /* output mode */
|
||||
unsigned int width; /* size (w-h) of the screen buffer */
|
||||
unsigned int height;
|
||||
unsigned int cursor_size; /* size of cursor (percentage filled) */
|
||||
unsigned int cursor_visible;/* cursor visibility flag */
|
||||
unsigned int cursor_x; /* position of cursor */
|
||||
unsigned int cursor_y; /* position of cursor */
|
||||
unsigned short attr; /* default fill attributes (screen colors) */
|
||||
unsigned short popup_attr; /* pop-up color attributes */
|
||||
unsigned int max_width; /* size (w-h) of the window given font size */
|
||||
unsigned int max_height;
|
||||
char_info_t *data; /* the data for each cell - a width x height matrix */
|
||||
unsigned int color_map[16]; /* color table */
|
||||
RECT win; /* current visible window on the screen buffer */
|
||||
struct font_info font; /* console font information */
|
||||
struct wine_rb_entry entry; /* map entry */
|
||||
};
|
||||
|
||||
static const char_info_t empty_char_info = { ' ', 0x0007 }; /* white on black space */
|
||||
|
||||
static CRITICAL_SECTION console_section;
|
||||
|
@ -2531,7 +2427,7 @@ static NTSTATUS console_input_ioctl( struct console *console, unsigned int code,
|
|||
info->edition_mode = console->edition_mode;
|
||||
info->input_cp = console->input_cp;
|
||||
info->output_cp = console->output_cp;
|
||||
info->win = console->win;
|
||||
info->win = condrv_handle( console->win );
|
||||
info->input_count = console->record_count;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -2588,7 +2484,7 @@ static NTSTATUS console_input_ioctl( struct console *console, unsigned int code,
|
|||
}
|
||||
if (params->mask & SET_CONSOLE_INPUT_INFO_WIN)
|
||||
{
|
||||
console->win = params->info.win;
|
||||
console->win = wine_server_ptr_handle( params->info.win );
|
||||
}
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
@ -2813,12 +2709,6 @@ int __cdecl wmain(int argc, WCHAR *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (!headless)
|
||||
{
|
||||
FIXME( "windowed mode not supported\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!console.server)
|
||||
{
|
||||
ERR( "no server handle\n" );
|
||||
|
@ -2836,6 +2726,11 @@ int __cdecl wmain(int argc, WCHAR *argv[])
|
|||
init_tty_output( &console );
|
||||
if (!console.is_unix && !ensure_tty_input_thread( &console )) return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!init_window( &console )) return 1;
|
||||
ShowWindow( console.win, SW_SHOW );
|
||||
}
|
||||
|
||||
return main_loop( &console, signal );
|
||||
}
|
||||
|
|
135
programs/conhost/conhost.h
Normal file
135
programs/conhost/conhost.h
Normal file
|
@ -0,0 +1,135 @@
|
|||
/*
|
||||
* Copyright 1998 Alexandre Julliard
|
||||
* Copyright 2001 Eric Pouech
|
||||
* Copyright 2012 Detlef Riekenberg
|
||||
* Copyright 2020 Jacek Caban
|
||||
*
|
||||
* 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
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef RC_INVOKED
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <ntstatus.h>
|
||||
#define WIN32_NO_STATUS
|
||||
#include <windef.h>
|
||||
#include <winbase.h>
|
||||
#include <winuser.h>
|
||||
#include <winnls.h>
|
||||
#include <winternl.h>
|
||||
|
||||
#include "wine/condrv.h"
|
||||
#include "wine/rbtree.h"
|
||||
|
||||
struct history_line
|
||||
{
|
||||
size_t len;
|
||||
WCHAR text[1];
|
||||
};
|
||||
|
||||
struct font_info
|
||||
{
|
||||
short int width;
|
||||
short int height;
|
||||
short int weight;
|
||||
short int pitch_family;
|
||||
WCHAR *face_name;
|
||||
size_t face_len;
|
||||
};
|
||||
|
||||
struct edit_line
|
||||
{
|
||||
NTSTATUS status; /* edit status */
|
||||
WCHAR *buf; /* the line being edited */
|
||||
unsigned int len; /* number of chars in line */
|
||||
size_t size; /* buffer size */
|
||||
unsigned int cursor; /* offset for cursor in current line */
|
||||
WCHAR *yanked; /* yanked line */
|
||||
unsigned int mark; /* marked point (emacs mode only) */
|
||||
unsigned int history_index; /* history index */
|
||||
WCHAR *current_history; /* buffer for the recent history entry */
|
||||
BOOL insert_key; /* insert key state */
|
||||
BOOL insert_mode; /* insert mode */
|
||||
unsigned int update_begin; /* update region */
|
||||
unsigned int update_end;
|
||||
unsigned int end_offset; /* offset of the last written char */
|
||||
unsigned int home_x; /* home position */
|
||||
unsigned int home_y;
|
||||
};
|
||||
|
||||
struct console
|
||||
{
|
||||
HANDLE server; /* console server handle */
|
||||
unsigned int mode; /* input mode */
|
||||
struct screen_buffer *active; /* active screen buffer */
|
||||
int is_unix; /* UNIX terminal mode */
|
||||
INPUT_RECORD *records; /* input records */
|
||||
unsigned int record_count; /* number of input records */
|
||||
unsigned int record_size; /* size of input records buffer */
|
||||
WCHAR *read_buffer; /* buffer of data available for read */
|
||||
size_t read_buffer_count; /* size of available data */
|
||||
size_t read_buffer_size; /* size of buffer */
|
||||
unsigned int read_ioctl; /* current read ioctl */
|
||||
size_t pending_read; /* size of pending read buffer */
|
||||
struct edit_line edit_line; /* edit line context */
|
||||
struct console_window *window;
|
||||
WCHAR *title; /* console title */
|
||||
size_t title_len; /* length of console title */
|
||||
struct history_line **history; /* lines history */
|
||||
unsigned int history_size; /* number of entries in history array */
|
||||
unsigned int history_index; /* number of used entries in history array */
|
||||
unsigned int history_mode; /* mode of history (non zero means remove doubled strings */
|
||||
unsigned int edition_mode; /* index to edition mode flavors */
|
||||
unsigned int input_cp; /* console input codepage */
|
||||
unsigned int output_cp; /* console output codepage */
|
||||
HWND win; /* window handle if backend supports it */
|
||||
HANDLE input_thread; /* input thread handle */
|
||||
HANDLE tty_input; /* handle to tty input stream */
|
||||
HANDLE tty_output; /* handle to tty output stream */
|
||||
char tty_buffer[4096]; /* tty output buffer */
|
||||
size_t tty_buffer_count; /* tty buffer size */
|
||||
unsigned int tty_cursor_x; /* tty cursor position */
|
||||
unsigned int tty_cursor_y;
|
||||
unsigned int tty_attr; /* current tty char attributes */
|
||||
int tty_cursor_visible; /* tty cursor visibility flag */
|
||||
};
|
||||
|
||||
struct screen_buffer
|
||||
{
|
||||
struct console *console; /* console reference */
|
||||
unsigned int id; /* screen buffer id */
|
||||
unsigned int mode; /* output mode */
|
||||
unsigned int width; /* size (w-h) of the screen buffer */
|
||||
unsigned int height;
|
||||
unsigned int cursor_size; /* size of cursor (percentage filled) */
|
||||
unsigned int cursor_visible; /* cursor visibility flag */
|
||||
unsigned int cursor_x; /* position of cursor */
|
||||
unsigned int cursor_y; /* position of cursor */
|
||||
unsigned short attr; /* default fill attributes (screen colors) */
|
||||
unsigned short popup_attr; /* pop-up color attributes */
|
||||
unsigned int max_width; /* size (w-h) of the window given font size */
|
||||
unsigned int max_height;
|
||||
char_info_t *data; /* the data for each cell - a width x height matrix */
|
||||
unsigned int color_map[16]; /* color table */
|
||||
RECT win; /* current visible window on the screen buffer */
|
||||
struct font_info font; /* console font information */
|
||||
struct wine_rb_entry entry; /* map entry */
|
||||
};
|
||||
|
||||
BOOL init_window( struct console *console );
|
||||
|
||||
#endif /* RC_INVOKED */
|
101
programs/conhost/window.c
Normal file
101
programs/conhost/window.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright 2001 Eric Pouech
|
||||
* Copyright 2020 Jacek Caban for CodeWeavers
|
||||
*
|
||||
* 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
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#define NONAMELESSUNION
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "conhost.h"
|
||||
|
||||
#include <commctrl.h>
|
||||
|
||||
#include "wine/debug.h"
|
||||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(conhost);
|
||||
|
||||
struct console_window
|
||||
{
|
||||
unsigned int ui_charset; /* default UI charset */
|
||||
};
|
||||
|
||||
static LRESULT window_create( HWND hwnd, const CREATESTRUCTW *create )
|
||||
{
|
||||
struct console *console = create->lpCreateParams;
|
||||
|
||||
TRACE( "%p\n", hwnd );
|
||||
|
||||
SetWindowLongPtrW( hwnd, 0, (DWORD_PTR)console );
|
||||
console->win = hwnd;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static LRESULT WINAPI window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
|
||||
{
|
||||
struct console *console = (struct console *)GetWindowLongPtrW( hwnd, 0 );
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
return window_create( hwnd, (const CREATESTRUCTW *)lparam );
|
||||
|
||||
case WM_DESTROY:
|
||||
console->win = NULL;
|
||||
PostQuitMessage( 0 );
|
||||
break;
|
||||
|
||||
default:
|
||||
return DefWindowProcW( hwnd, msg, wparam, lparam );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BOOL init_window( struct console *console )
|
||||
{
|
||||
WNDCLASSW wndclass;
|
||||
CHARSETINFO ci;
|
||||
|
||||
static struct console_window console_window;
|
||||
|
||||
console->window = &console_window;
|
||||
if (!TranslateCharsetInfo( (DWORD *)(INT_PTR)GetACP(), &ci, TCI_SRCCODEPAGE ))
|
||||
return FALSE;
|
||||
|
||||
console->window->ui_charset = ci.ciCharset;
|
||||
|
||||
wndclass.style = CS_DBLCLKS;
|
||||
wndclass.lpfnWndProc = window_proc;
|
||||
wndclass.cbClsExtra = 0;
|
||||
wndclass.cbWndExtra = sizeof(DWORD_PTR);
|
||||
wndclass.hInstance = GetModuleHandleW(NULL);
|
||||
wndclass.hIcon = LoadIconW( 0, (const WCHAR *)IDI_WINLOGO );
|
||||
wndclass.hCursor = LoadCursorW( 0, (const WCHAR *)IDC_ARROW );
|
||||
wndclass.hbrBackground = GetStockObject( BLACK_BRUSH );
|
||||
wndclass.lpszMenuName = NULL;
|
||||
wndclass.lpszClassName = L"WineConsoleClass";
|
||||
RegisterClassW(&wndclass);
|
||||
|
||||
if (!CreateWindowW( wndclass.lpszClassName, NULL,
|
||||
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|
|
||||
WS_MAXIMIZEBOX|WS_HSCROLL|WS_VSCROLL, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
0, 0, 0, 0, wndclass.hInstance, console ))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
Loading…
Reference in a new issue