2001-11-24 00:04:58 +01:00
|
|
|
/*
|
|
|
|
* a GUI application for displaying a console
|
|
|
|
* USER32 back end
|
|
|
|
* Copyright 2001 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-11-24 00:04:58 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2002-01-01 01:14:02 +01:00
|
|
|
#include <stdlib.h>
|
2001-12-04 21:46:54 +01:00
|
|
|
#include "winecon_user.h"
|
2006-10-03 21:08:32 +02:00
|
|
|
#include "winnls.h"
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-05-14 23:45:13 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wineconsole);
|
|
|
|
WINE_DECLARE_DEBUG_CHANNEL(wc_font);
|
|
|
|
|
2006-10-03 21:08:32 +02:00
|
|
|
UINT g_uiDefaultCharset;
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/* mapping console colors to RGB values */
|
2007-01-10 08:27:24 +01:00
|
|
|
const COLORREF WCUSER_ColorMap[16] =
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
RGB(0x00, 0x00, 0x00), RGB(0x00, 0x00, 0x80), RGB(0x00, 0x80, 0x00), RGB(0x00, 0x80, 0x80),
|
2011-12-20 22:35:33 +01:00
|
|
|
RGB(0x80, 0x00, 0x00), RGB(0x80, 0x00, 0x80), RGB(0x80, 0x80, 0x00), RGB(0xC0, 0xC0, 0xC0),
|
|
|
|
RGB(0x80, 0x80, 0x80), RGB(0x00, 0x00, 0xFF), RGB(0x00, 0xFF, 0x00), RGB(0x00, 0xFF, 0xFF),
|
2001-11-24 00:04:58 +01:00
|
|
|
RGB(0xFF, 0x00, 0x00), RGB(0xFF, 0x00, 0xFF), RGB(0xFF, 0xFF, 0x00), RGB(0xFF, 0xFF, 0xFF),
|
|
|
|
};
|
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
static BOOL WCUSER_SetFont(struct inner_data* data, const LOGFONTW* font);
|
2002-09-04 20:41:52 +02:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_FillMemDC
|
|
|
|
*
|
|
|
|
* Fills the Mem DC with current cells values
|
|
|
|
*/
|
|
|
|
static void WCUSER_FillMemDC(const struct inner_data* data, int upd_tp, int upd_bm)
|
|
|
|
{
|
|
|
|
unsigned i, j, k;
|
|
|
|
CHAR_INFO* cell;
|
|
|
|
HFONT hOldFont;
|
|
|
|
WORD attr;
|
|
|
|
WCHAR* line;
|
2005-11-03 10:51:00 +01:00
|
|
|
RECT r;
|
|
|
|
HBRUSH hbr;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* no font has been set up yet, don't worry about filling the bitmap,
|
2002-05-14 23:45:13 +02:00
|
|
|
* we'll do it once a font is chosen
|
|
|
|
*/
|
|
|
|
if (!PRIVATE(data)->hFont) return;
|
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
/* FIXME: could set up a mechanism to reuse the line between different
|
|
|
|
* calls to this function
|
|
|
|
*/
|
2001-12-04 21:46:54 +01:00
|
|
|
if (!(line = HeapAlloc(GetProcessHeap(), 0, data->curcfg.sb_width * sizeof(WCHAR))))
|
2002-09-04 20:41:52 +02:00
|
|
|
WINECON_Fatal("OOM\n");
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
hOldFont = SelectObject(PRIVATE(data)->hMemDC, PRIVATE(data)->hFont);
|
2001-11-24 00:04:58 +01:00
|
|
|
for (j = upd_tp; j <= upd_bm; j++)
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
cell = &data->cells[j * data->curcfg.sb_width];
|
2002-05-14 23:45:13 +02:00
|
|
|
for (i = 0; i < data->curcfg.sb_width; i++)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
attr = cell[i].Attributes;
|
2002-05-21 20:05:16 +02:00
|
|
|
SetBkColor(PRIVATE(data)->hMemDC, WCUSER_ColorMap[(attr>>4)&0x0F]);
|
2001-12-31 23:20:56 +01:00
|
|
|
SetTextColor(PRIVATE(data)->hMemDC, WCUSER_ColorMap[attr&0x0F]);
|
2002-05-14 23:45:13 +02:00
|
|
|
for (k = i; k < data->curcfg.sb_width && cell[k].Attributes == attr; k++)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
line[k - i] = cell[k].Char.UnicodeChar;
|
|
|
|
}
|
2010-04-28 01:07:52 +02:00
|
|
|
TextOutW(PRIVATE(data)->hMemDC, i * data->curcfg.cell_width,
|
|
|
|
j * data->curcfg.cell_height, line, k - i);
|
2005-11-03 10:51:00 +01:00
|
|
|
if (PRIVATE(data)->ext_leading &&
|
|
|
|
(hbr = CreateSolidBrush(WCUSER_ColorMap[(attr>>4)&0x0F])))
|
|
|
|
{
|
|
|
|
r.left = i * data->curcfg.cell_width;
|
|
|
|
r.top = (j + 1) * data->curcfg.cell_height - PRIVATE(data)->ext_leading;
|
|
|
|
r.right = k * data->curcfg.cell_width;
|
|
|
|
r.bottom = (j + 1) * data->curcfg.cell_height;
|
|
|
|
FillRect(PRIVATE(data)->hMemDC, &r, hbr);
|
|
|
|
DeleteObject(hbr);
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
i = k - 1;
|
|
|
|
}
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
SelectObject(PRIVATE(data)->hMemDC, hOldFont);
|
2001-11-24 00:04:58 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, line);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_NewBitmap
|
|
|
|
*
|
2002-07-23 04:02:46 +02:00
|
|
|
* Either the font geometry or the sb geometry has changed. we need
|
|
|
|
* to recreate the bitmap geometry.
|
2001-11-24 00:04:58 +01:00
|
|
|
*/
|
2002-09-04 20:41:52 +02:00
|
|
|
static void WCUSER_NewBitmap(struct inner_data* data)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
HDC hDC;
|
2001-11-24 00:04:58 +01:00
|
|
|
HBITMAP hnew, hold;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!data->curcfg.sb_width || !data->curcfg.sb_height ||
|
2007-08-23 17:14:58 +02:00
|
|
|
!PRIVATE(data)->hFont || !(hDC = GetDC(data->hWnd)))
|
2001-12-04 21:46:54 +01:00
|
|
|
return;
|
2002-06-01 01:06:46 +02:00
|
|
|
hnew = CreateCompatibleBitmap(hDC,
|
|
|
|
data->curcfg.sb_width * data->curcfg.cell_width,
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.sb_height * data->curcfg.cell_height);
|
2007-08-23 17:14:58 +02:00
|
|
|
ReleaseDC(data->hWnd, hDC);
|
2001-12-04 21:46:54 +01:00
|
|
|
hold = SelectObject(PRIVATE(data)->hMemDC, hnew);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
if (PRIVATE(data)->hBitmap)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
if (hold == PRIVATE(data)->hBitmap)
|
|
|
|
DeleteObject(PRIVATE(data)->hBitmap);
|
2001-11-24 00:04:58 +01:00
|
|
|
else
|
2002-05-14 23:45:13 +02:00
|
|
|
WINE_FIXME("leak\n");
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
PRIVATE(data)->hBitmap = hnew;
|
2002-09-04 20:41:52 +02:00
|
|
|
WCUSER_FillMemDC(data, 0, data->curcfg.sb_height - 1);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_ResizeScreenBuffer
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void WCUSER_ResizeScreenBuffer(struct inner_data* data)
|
|
|
|
{
|
2002-09-04 20:41:52 +02:00
|
|
|
WCUSER_NewBitmap(data);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_PosCursor
|
|
|
|
*
|
|
|
|
* Set a new position for the cursor
|
|
|
|
*/
|
|
|
|
static void WCUSER_PosCursor(const struct inner_data* data)
|
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
if (data->hWnd != GetFocus() || !data->curcfg.cursor_visible) return;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
SetCaretPos((data->cursor.X - data->curcfg.win_pos.X) * data->curcfg.cell_width,
|
2001-12-04 21:46:54 +01:00
|
|
|
(data->cursor.Y - data->curcfg.win_pos.Y) * data->curcfg.cell_height);
|
2007-08-23 17:14:58 +02:00
|
|
|
ShowCaret(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_ShapeCursor
|
|
|
|
*
|
|
|
|
* Sets a new shape for the cursor
|
|
|
|
*/
|
2002-09-04 20:41:52 +02:00
|
|
|
static void WCUSER_ShapeCursor(struct inner_data* data, int size, int vis, BOOL force)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
if (force || size != data->curcfg.cursor_size)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
if (data->curcfg.cursor_visible && data->hWnd == GetFocus()) DestroyCaret();
|
2001-12-04 21:46:54 +01:00
|
|
|
if (PRIVATE(data)->cursor_bitmap) DeleteObject(PRIVATE(data)->cursor_bitmap);
|
2002-12-02 19:10:57 +01:00
|
|
|
PRIVATE(data)->cursor_bitmap = NULL;
|
2001-11-24 00:04:58 +01:00
|
|
|
if (size != 100)
|
|
|
|
{
|
2002-07-23 04:02:46 +02:00
|
|
|
int w16b; /* number of bytes per row, aligned on word size */
|
2001-11-24 00:04:58 +01:00
|
|
|
BYTE* ptr;
|
|
|
|
int i, j, nbl;
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
w16b = ((data->curcfg.cell_width + 15) & ~15) / 8;
|
|
|
|
ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, w16b * data->curcfg.cell_height);
|
2002-09-04 20:41:52 +02:00
|
|
|
if (!ptr) WINECON_Fatal("OOM");
|
2001-12-04 21:46:54 +01:00
|
|
|
nbl = max((data->curcfg.cell_height * size) / 100, 1);
|
|
|
|
for (j = data->curcfg.cell_height - nbl; j < data->curcfg.cell_height; j++)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
for (i = 0; i < data->curcfg.cell_width; i++)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
ptr[w16b * j + (i / 8)] |= 0x80 >> (i & 7);
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
PRIVATE(data)->cursor_bitmap = CreateBitmap(data->curcfg.cell_width,
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.cell_height, 1, 1, ptr);
|
2001-11-24 00:04:58 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.cursor_size = size;
|
|
|
|
data->curcfg.cursor_visible = -1;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2012-08-27 13:29:31 +02:00
|
|
|
vis = vis != 0;
|
2001-12-04 21:46:54 +01:00
|
|
|
if (force || vis != data->curcfg.cursor_visible)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.cursor_visible = vis;
|
2007-08-23 17:14:58 +02:00
|
|
|
if (data->hWnd == GetFocus())
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
if (vis)
|
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
CreateCaret(data->hWnd, PRIVATE(data)->cursor_bitmap,
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.cell_width, data->curcfg.cell_height);
|
2001-11-24 00:04:58 +01:00
|
|
|
WCUSER_PosCursor(data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DestroyCaret();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-09-04 20:41:52 +02:00
|
|
|
WINECON_DumpConfig("crsr", &data->curcfg);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2002-07-23 04:02:46 +02:00
|
|
|
* WCUSER_ComputePositions
|
2001-11-24 00:04:58 +01:00
|
|
|
*
|
|
|
|
* Recomputes all the components (mainly scroll bars) positions
|
|
|
|
*/
|
2004-11-29 19:00:10 +01:00
|
|
|
static void WCUSER_ComputePositions(struct inner_data* data)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
int dx, dy;
|
|
|
|
|
|
|
|
/* compute window size from desired client size */
|
|
|
|
r.left = r.top = 0;
|
2001-12-04 21:46:54 +01:00
|
|
|
r.right = data->curcfg.win_width * data->curcfg.cell_width;
|
|
|
|
r.bottom = data->curcfg.win_height * data->curcfg.cell_height;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
if (IsRectEmpty(&r)) return;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
AdjustWindowRect(&r, GetWindowLongW(data->hWnd, GWL_STYLE), FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
dx = dy = 0;
|
2001-12-04 21:46:54 +01:00
|
|
|
if (data->curcfg.sb_width > data->curcfg.win_width)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
dy = GetSystemMetrics(SM_CYHSCROLL);
|
2007-08-23 17:14:58 +02:00
|
|
|
SetScrollRange(data->hWnd, SB_HORZ, 0,
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.sb_width - data->curcfg.win_width, FALSE);
|
2007-08-23 17:14:58 +02:00
|
|
|
SetScrollPos(data->hWnd, SB_HORZ, 0, FALSE); /* FIXME */
|
|
|
|
ShowScrollBar(data->hWnd, SB_HORZ, TRUE);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
ShowScrollBar(data->hWnd, SB_HORZ, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
if (data->curcfg.sb_height > data->curcfg.win_height)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
dx = GetSystemMetrics(SM_CXVSCROLL);
|
2007-08-23 17:14:58 +02:00
|
|
|
SetScrollRange(data->hWnd, SB_VERT, 0,
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.sb_height - data->curcfg.win_height, FALSE);
|
2007-08-23 17:14:58 +02:00
|
|
|
SetScrollPos(data->hWnd, SB_VERT, 0, FALSE); /* FIXME */
|
|
|
|
ShowScrollBar(data->hWnd, SB_VERT, TRUE);
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
else
|
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
ShowScrollBar(data->hWnd, SB_VERT, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2007-08-23 17:14:58 +02:00
|
|
|
SetWindowPos(data->hWnd, 0, 0, 0, r.right - r.left + dx, r.bottom - r.top + dy,
|
2002-09-04 20:41:52 +02:00
|
|
|
SWP_NOMOVE|SWP_NOZORDER);
|
2001-12-04 21:46:54 +01:00
|
|
|
WCUSER_ShapeCursor(data, data->curcfg.cursor_size, data->curcfg.cursor_visible, TRUE);
|
2001-11-24 00:04:58 +01:00
|
|
|
WCUSER_PosCursor(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_SetTitle
|
|
|
|
*
|
|
|
|
* Sets the title to the wine console
|
|
|
|
*/
|
|
|
|
static void WCUSER_SetTitle(const struct inner_data* data)
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
WCHAR buffer[256];
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
if (WINECON_GetConsoleTitle(data->hConIn, buffer, sizeof(buffer)))
|
2010-04-28 01:07:52 +02:00
|
|
|
SetWindowTextW(data->hWnd, buffer);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
void WCUSER_DumpLogFont(const char* pfx, const LOGFONTW* lf, DWORD ft)
|
2002-05-14 23:45:13 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE_(wc_font)("%s %s%s%s%s\n"
|
2006-10-02 23:22:34 +02:00
|
|
|
"\tlf.lfHeight=%d lf.lfWidth=%d lf.lfEscapement=%d lf.lfOrientation=%d\n"
|
|
|
|
"\tlf.lfWeight=%d lf.lfItalic=%u lf.lfUnderline=%u lf.lfStrikeOut=%u\n"
|
2002-05-14 23:45:13 +02:00
|
|
|
"\tlf.lfCharSet=%u lf.lfOutPrecision=%u lf.lfClipPrecision=%u lf.lfQuality=%u\n"
|
|
|
|
"\tlf->lfPitchAndFamily=%u lf.lfFaceName=%s\n",
|
|
|
|
pfx,
|
2002-06-01 01:06:46 +02:00
|
|
|
(ft & RASTER_FONTTYPE) ? "raster" : "",
|
|
|
|
(ft & TRUETYPE_FONTTYPE) ? "truetype" : "",
|
|
|
|
((ft & (RASTER_FONTTYPE|TRUETYPE_FONTTYPE)) == 0) ? "vector" : "",
|
|
|
|
(ft & DEVICE_FONTTYPE) ? "|device" : "",
|
|
|
|
lf->lfHeight, lf->lfWidth, lf->lfEscapement, lf->lfOrientation,
|
2002-05-14 23:45:13 +02:00
|
|
|
lf->lfWeight, lf->lfItalic, lf->lfUnderline, lf->lfStrikeOut, lf->lfCharSet,
|
2002-06-01 01:06:46 +02:00
|
|
|
lf->lfOutPrecision, lf->lfClipPrecision, lf->lfQuality, lf->lfPitchAndFamily,
|
2002-05-14 23:45:13 +02:00
|
|
|
wine_dbgstr_w(lf->lfFaceName));
|
|
|
|
}
|
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
void WCUSER_DumpTextMetric(const TEXTMETRICW* tm, DWORD ft)
|
2002-05-14 23:45:13 +02:00
|
|
|
{
|
|
|
|
WINE_TRACE_(wc_font)("%s%s%s%s\n"
|
2006-10-02 23:22:34 +02:00
|
|
|
"\ttmHeight=%d tmAscent=%d tmDescent=%d tmInternalLeading=%d tmExternalLeading=%d\n"
|
|
|
|
"\ttmAveCharWidth=%d tmMaxCharWidth=%d tmWeight=%d tmOverhang=%d\n"
|
|
|
|
"\ttmDigitizedAspectX=%d tmDigitizedAspectY=%d\n"
|
2002-05-14 23:45:13 +02:00
|
|
|
"\ttmFirstChar=%d tmLastChar=%d tmDefaultChar=%d tmBreakChar=%d\n"
|
|
|
|
"\ttmItalic=%u tmUnderlined=%u tmStruckOut=%u tmPitchAndFamily=%u tmCharSet=%u\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
(ft & RASTER_FONTTYPE) ? "raster" : "",
|
|
|
|
(ft & TRUETYPE_FONTTYPE) ? "truetype" : "",
|
|
|
|
((ft & (RASTER_FONTTYPE|TRUETYPE_FONTTYPE)) == 0) ? "vector" : "",
|
|
|
|
(ft & DEVICE_FONTTYPE) ? "|device" : "",
|
|
|
|
tm->tmHeight, tm->tmAscent, tm->tmDescent, tm->tmInternalLeading, tm->tmExternalLeading, tm->tmAveCharWidth,
|
|
|
|
tm->tmMaxCharWidth, tm->tmWeight, tm->tmOverhang, tm->tmDigitizedAspectX, tm->tmDigitizedAspectY,
|
|
|
|
tm->tmFirstChar, tm->tmLastChar, tm->tmDefaultChar, tm->tmBreakChar, tm->tmItalic, tm->tmUnderlined, tm->tmStruckOut,
|
2002-05-14 23:45:13 +02:00
|
|
|
tm->tmPitchAndFamily, tm->tmCharSet);
|
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
2002-07-23 04:02:46 +02:00
|
|
|
* WCUSER_AreFontsEqual
|
2001-12-04 21:46:54 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
static BOOL WCUSER_AreFontsEqual(const struct config_data* config, const LOGFONTW* lf)
|
2001-12-04 21:46:54 +01:00
|
|
|
{
|
|
|
|
return lf->lfHeight == config->cell_height &&
|
|
|
|
lf->lfWeight == config->font_weight &&
|
|
|
|
!lf->lfItalic && !lf->lfUnderline && !lf->lfStrikeOut &&
|
2010-04-28 01:07:52 +02:00
|
|
|
!lstrcmpW(lf->lfFaceName, config->face_name);
|
2001-12-04 21:46:54 +01:00
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
struct font_chooser
|
2002-05-14 23:45:13 +02:00
|
|
|
{
|
2002-03-23 21:14:04 +01:00
|
|
|
struct inner_data* data;
|
|
|
|
int done;
|
|
|
|
};
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
/******************************************************************
|
2002-03-23 21:14:04 +01:00
|
|
|
* WCUSER_ValidateFontMetric
|
2001-11-24 00:04:58 +01:00
|
|
|
*
|
2002-03-23 21:14:04 +01:00
|
|
|
* Returns true if the font described in tm is usable as a font for the renderer
|
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRICW* tm, DWORD fontType)
|
2002-03-23 21:14:04 +01:00
|
|
|
{
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
if (fontType & RASTER_FONTTYPE)
|
|
|
|
ret = (tm->tmMaxCharWidth * data->curcfg.win_width < GetSystemMetrics(SM_CXSCREEN) &&
|
|
|
|
tm->tmHeight * data->curcfg.win_height < GetSystemMetrics(SM_CYSCREEN));
|
|
|
|
return ret && !tm->tmItalic && !tm->tmUnderlined && !tm->tmStruckOut &&
|
2006-10-03 21:08:32 +02:00
|
|
|
(tm->tmCharSet == DEFAULT_CHARSET || tm->tmCharSet == g_uiDefaultCharset);
|
2002-03-23 21:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_ValidateFont
|
2001-11-24 00:04:58 +01:00
|
|
|
*
|
2002-03-23 21:14:04 +01:00
|
|
|
* Returns true if the font family described in lf is usable as a font for the renderer
|
2001-11-24 00:04:58 +01:00
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
BOOL WCUSER_ValidateFont(const struct inner_data* data, const LOGFONTW* lf)
|
2001-12-04 21:46:54 +01:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
return (lf->lfPitchAndFamily & 3) == FIXED_PITCH &&
|
2002-03-23 21:14:04 +01:00
|
|
|
/* (lf->lfPitchAndFamily & 0xF0) == FF_MODERN && */
|
2013-06-25 18:07:24 +02:00
|
|
|
lf->lfFaceName[0] != '@' &&
|
2006-10-03 21:08:32 +02:00
|
|
|
(lf->lfCharSet == DEFAULT_CHARSET || lf->lfCharSet == g_uiDefaultCharset);
|
2001-12-04 21:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2002-03-23 21:14:04 +01:00
|
|
|
* get_first_font_enum_2
|
|
|
|
* get_first_font_enum
|
2001-12-04 21:46:54 +01:00
|
|
|
*
|
2002-03-23 21:14:04 +01:00
|
|
|
* Helper functions to get a decent font for the renderer
|
2001-12-04 21:46:54 +01:00
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
static int CALLBACK get_first_font_enum_2(const LOGFONTW* lf, const TEXTMETRICW* tm,
|
|
|
|
DWORD FontType, LPARAM lParam)
|
2001-12-04 21:46:54 +01:00
|
|
|
{
|
2002-03-23 21:14:04 +01:00
|
|
|
struct font_chooser* fc = (struct font_chooser*)lParam;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-05-14 23:45:13 +02:00
|
|
|
WCUSER_DumpTextMetric(tm, FontType);
|
2002-05-21 20:05:16 +02:00
|
|
|
if (WCUSER_ValidateFontMetric(fc->data, tm, FontType))
|
2002-03-23 21:14:04 +01:00
|
|
|
{
|
2010-04-28 01:07:52 +02:00
|
|
|
LOGFONTW mlf = *lf;
|
2002-05-21 20:05:16 +02:00
|
|
|
|
|
|
|
/* Use the default sizes for the font (this is needed, especially for
|
2002-06-01 01:06:46 +02:00
|
|
|
* TrueType fonts, so that we get a decent size, not the max size)
|
2002-05-14 23:45:13 +02:00
|
|
|
*/
|
2002-05-21 20:05:16 +02:00
|
|
|
mlf.lfWidth = fc->data->curcfg.cell_width;
|
|
|
|
mlf.lfHeight = fc->data->curcfg.cell_height;
|
|
|
|
if (WCUSER_SetFont(fc->data, &mlf))
|
|
|
|
{
|
2002-09-04 20:41:52 +02:00
|
|
|
struct config_data defcfg;
|
|
|
|
|
2002-05-21 20:05:16 +02:00
|
|
|
WCUSER_DumpLogFont("InitChoosing: ", &mlf, FontType);
|
|
|
|
fc->done = 1;
|
2002-06-01 01:06:46 +02:00
|
|
|
/* since we've modified the current config with new font information,
|
2002-05-21 20:05:16 +02:00
|
|
|
* set this information as the new default.
|
|
|
|
*/
|
2002-09-04 20:41:52 +02:00
|
|
|
WINECON_RegLoad(NULL, &defcfg);
|
|
|
|
defcfg.cell_width = fc->data->curcfg.cell_width;
|
|
|
|
defcfg.cell_height = fc->data->curcfg.cell_height;
|
|
|
|
lstrcpyW(defcfg.face_name, fc->data->curcfg.face_name);
|
2002-05-21 20:05:16 +02:00
|
|
|
/* Force also its writing back to the registry so that we can get it
|
|
|
|
* the next time.
|
|
|
|
*/
|
2002-09-04 20:41:52 +02:00
|
|
|
WINECON_RegSave(&defcfg);
|
2002-05-21 20:05:16 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2002-03-23 21:14:04 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
static int CALLBACK get_first_font_enum(const LOGFONTW* lf, const TEXTMETRICW* tm,
|
|
|
|
DWORD FontType, LPARAM lParam)
|
2002-03-23 21:14:04 +01:00
|
|
|
{
|
|
|
|
struct font_chooser* fc = (struct font_chooser*)lParam;
|
|
|
|
|
2002-05-21 20:05:16 +02:00
|
|
|
WCUSER_DumpLogFont("InitFamily: ", lf, FontType);
|
2002-03-23 21:14:04 +01:00
|
|
|
if (WCUSER_ValidateFont(fc->data, lf))
|
|
|
|
{
|
2010-04-28 01:07:52 +02:00
|
|
|
EnumFontFamiliesW(PRIVATE(fc->data)->hMemDC, lf->lfFaceName,
|
|
|
|
get_first_font_enum_2, lParam);
|
2002-03-23 21:14:04 +01:00
|
|
|
return !fc->done; /* we just need the first matching one... */
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2002-07-23 04:02:46 +02:00
|
|
|
* WCUSER_CopyFont
|
2002-03-23 21:14:04 +01:00
|
|
|
*
|
|
|
|
* get the relevant information from the font described in lf and store them
|
|
|
|
* in config
|
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
HFONT WCUSER_CopyFont(struct config_data* config, HWND hWnd, const LOGFONTW* lf, LONG* el)
|
2002-03-23 21:14:04 +01:00
|
|
|
{
|
2010-04-28 01:07:52 +02:00
|
|
|
TEXTMETRICW tm;
|
2002-03-23 21:14:04 +01:00
|
|
|
HDC hDC;
|
|
|
|
HFONT hFont, hOldFont;
|
|
|
|
int w, i, buf[256];
|
|
|
|
|
2002-12-02 19:10:57 +01:00
|
|
|
if (!(hDC = GetDC(hWnd))) return NULL;
|
2010-04-28 01:07:52 +02:00
|
|
|
if (!(hFont = CreateFontIndirectW(lf))) goto err1;
|
2002-03-23 21:14:04 +01:00
|
|
|
|
|
|
|
hOldFont = SelectObject(hDC, hFont);
|
2010-04-28 01:07:52 +02:00
|
|
|
GetTextMetricsW(hDC, &tm);
|
2002-03-23 21:14:04 +01:00
|
|
|
|
|
|
|
/* FIXME:
|
|
|
|
* the current freetype engine (at least 2.0.x with x <= 8) and its implementation
|
|
|
|
* in Wine don't return adequate values for fixed fonts
|
2002-07-23 04:02:46 +02:00
|
|
|
* In Windows, those fonts are expected to return the same value for
|
2002-03-23 21:14:04 +01:00
|
|
|
* - the average width
|
|
|
|
* - the largest width
|
|
|
|
* - the width of all characters in the font
|
2002-07-23 04:02:46 +02:00
|
|
|
* This isn't true in Wine. As a temporary workaround, we get as the width of the
|
2002-03-23 21:14:04 +01:00
|
|
|
* cell, the width of the first character in the font, after checking that all
|
2011-07-27 11:46:59 +02:00
|
|
|
* characters in the font have the same width (I hear paranoia coming)
|
2002-07-23 04:02:46 +02:00
|
|
|
* when this gets fixed, the code should be using tm.tmAveCharWidth
|
|
|
|
* or tm.tmMaxCharWidth as the cell width.
|
2002-03-23 21:14:04 +01:00
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
GetCharWidth32W(hDC, tm.tmFirstChar, tm.tmFirstChar, &w);
|
2002-03-23 21:14:04 +01:00
|
|
|
for (i = tm.tmFirstChar + 1; i <= tm.tmLastChar; i += sizeof(buf) / sizeof(buf[0]))
|
|
|
|
{
|
2004-09-22 21:12:38 +02:00
|
|
|
int j, k;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-09-22 21:12:38 +02:00
|
|
|
k = min(tm.tmLastChar - i, sizeof(buf) / sizeof(buf[0]) - 1);
|
2010-04-28 01:07:52 +02:00
|
|
|
GetCharWidth32W(hDC, i, i + k, buf);
|
2004-09-22 21:12:38 +02:00
|
|
|
for (j = 0; j <= k; j++)
|
2002-03-23 21:14:04 +01:00
|
|
|
{
|
|
|
|
if (buf[j] != w)
|
|
|
|
{
|
2002-05-21 20:05:16 +02:00
|
|
|
WINE_WARN("Non uniform cell width: [%d]=%d [%d]=%d\n"
|
2002-06-01 01:06:46 +02:00
|
|
|
"This may be caused by old freetype libraries, >= 2.0.8 is recommended\n",
|
2002-05-14 23:45:13 +02:00
|
|
|
i + j, buf[j], tm.tmFirstChar, w);
|
2002-03-23 21:14:04 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SelectObject(hDC, hOldFont);
|
|
|
|
ReleaseDC(hWnd, hDC);
|
|
|
|
|
|
|
|
config->cell_width = w;
|
2002-06-02 23:20:43 +02:00
|
|
|
config->cell_height = tm.tmHeight + tm.tmExternalLeading;
|
2002-03-23 21:14:04 +01:00
|
|
|
config->font_weight = tm.tmWeight;
|
2010-04-28 01:07:52 +02:00
|
|
|
lstrcpyW(config->face_name, lf->lfFaceName);
|
2005-11-03 10:51:00 +01:00
|
|
|
if (el) *el = tm.tmExternalLeading;
|
2002-03-23 21:14:04 +01:00
|
|
|
|
|
|
|
return hFont;
|
|
|
|
err:
|
|
|
|
if (hDC && hOldFont) SelectObject(hDC, hOldFont);
|
|
|
|
if (hFont) DeleteObject(hFont);
|
|
|
|
err1:
|
|
|
|
if (hDC) ReleaseDC(hWnd, hDC);
|
|
|
|
|
2002-12-02 19:10:57 +01:00
|
|
|
return NULL;
|
2002-03-23 21:14:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_FillLogFont
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
void WCUSER_FillLogFont(LOGFONTW* lf, const WCHAR* name, UINT height, UINT weight)
|
2002-03-23 21:14:04 +01:00
|
|
|
{
|
|
|
|
lf->lfHeight = height;
|
|
|
|
lf->lfWidth = 0;
|
|
|
|
lf->lfEscapement = 0;
|
|
|
|
lf->lfOrientation = 0;
|
|
|
|
lf->lfWeight = weight;
|
|
|
|
lf->lfItalic = FALSE;
|
|
|
|
lf->lfUnderline = FALSE;
|
|
|
|
lf->lfStrikeOut = FALSE;
|
|
|
|
lf->lfCharSet = DEFAULT_CHARSET;
|
|
|
|
lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
|
2002-06-01 01:06:46 +02:00
|
|
|
lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
2002-03-23 21:14:04 +01:00
|
|
|
lf->lfQuality = DEFAULT_QUALITY;
|
|
|
|
lf->lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
|
2010-04-28 01:07:52 +02:00
|
|
|
lstrcpyW(lf->lfFaceName, name);
|
2001-12-04 21:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_SetFont
|
|
|
|
*
|
|
|
|
* sets logfont as the new font for the console
|
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
BOOL WCUSER_SetFont(struct inner_data* data, const LOGFONTW* logfont)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2002-05-14 23:45:13 +02:00
|
|
|
HFONT hFont;
|
2005-11-03 10:51:00 +01:00
|
|
|
LONG el;
|
2002-05-14 23:45:13 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (PRIVATE(data)->hFont != 0 && WCUSER_AreFontsEqual(&data->curcfg, logfont))
|
2002-05-14 23:45:13 +02:00
|
|
|
return TRUE;
|
2002-03-23 21:14:04 +01:00
|
|
|
|
2007-08-23 17:14:58 +02:00
|
|
|
hFont = WCUSER_CopyFont(&data->curcfg, data->hWnd, logfont, &el);
|
2002-05-14 23:45:13 +02:00
|
|
|
if (!hFont) {WINE_ERR("wrong font\n"); return FALSE;}
|
|
|
|
|
|
|
|
if (PRIVATE(data)->hFont) DeleteObject(PRIVATE(data)->hFont);
|
|
|
|
PRIVATE(data)->hFont = hFont;
|
2005-11-03 10:51:00 +01:00
|
|
|
PRIVATE(data)->ext_leading = el;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
WCUSER_ComputePositions(data);
|
2002-09-04 20:41:52 +02:00
|
|
|
WCUSER_NewBitmap(data);
|
2007-08-23 17:14:58 +02:00
|
|
|
InvalidateRect(data->hWnd, NULL, FALSE);
|
|
|
|
UpdateWindow(data->hWnd);
|
2002-03-23 21:14:04 +01:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-03-23 21:14:04 +01:00
|
|
|
/******************************************************************
|
2002-09-04 20:41:52 +02:00
|
|
|
* WCUSER_SetFontPmt
|
2002-03-23 21:14:04 +01:00
|
|
|
*
|
2002-09-04 20:41:52 +02:00
|
|
|
* Sets a new font for the console.
|
|
|
|
* In fact a wrapper for WCUSER_SetFont
|
2002-03-23 21:14:04 +01:00
|
|
|
*/
|
2002-09-04 20:41:52 +02:00
|
|
|
static void WCUSER_SetFontPmt(struct inner_data* data, const WCHAR* font,
|
|
|
|
unsigned height, unsigned weight)
|
2002-03-23 21:14:04 +01:00
|
|
|
{
|
2010-04-28 01:07:52 +02:00
|
|
|
LOGFONTW lf;
|
2002-03-23 21:14:04 +01:00
|
|
|
struct font_chooser fc;
|
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
WINE_TRACE_(wc_font)("=> %s h=%u w=%u\n",
|
|
|
|
wine_dbgstr_wn(font, -1), height, weight);
|
2002-05-14 23:45:13 +02:00
|
|
|
|
2002-09-04 20:41:52 +02:00
|
|
|
if (font[0] != '\0' && height != 0 && weight != 0)
|
|
|
|
{
|
|
|
|
WCUSER_FillLogFont(&lf, font, height, weight);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (WCUSER_SetFont(data, &lf))
|
2002-05-21 20:05:16 +02:00
|
|
|
{
|
|
|
|
WCUSER_DumpLogFont("InitReuses: ", &lf, 0);
|
2002-09-04 20:41:52 +02:00
|
|
|
return;
|
2002-05-21 20:05:16 +02:00
|
|
|
}
|
2002-05-14 23:45:13 +02:00
|
|
|
}
|
2002-03-23 21:14:04 +01:00
|
|
|
|
|
|
|
/* try to find an acceptable font */
|
2002-05-14 23:45:13 +02:00
|
|
|
WINE_WARN("Couldn't match the font from registry... trying to find one\n");
|
2002-03-23 21:14:04 +01:00
|
|
|
fc.data = data;
|
|
|
|
fc.done = 0;
|
2010-04-28 01:07:52 +02:00
|
|
|
EnumFontFamiliesW(PRIVATE(data)->hMemDC, NULL, get_first_font_enum, (LPARAM)&fc);
|
2002-09-04 20:41:52 +02:00
|
|
|
if (!fc.done) WINECON_Fatal("Couldn't find a decent font, aborting\n");
|
2002-03-23 21:14:04 +01:00
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_GetCell
|
|
|
|
*
|
2002-07-23 04:02:46 +02:00
|
|
|
* Get a cell from a relative coordinate in window (takes into
|
2001-11-24 00:04:58 +01:00
|
|
|
* account the scrolling)
|
|
|
|
*/
|
|
|
|
static COORD WCUSER_GetCell(const struct inner_data* data, LPARAM lParam)
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
c.X = data->curcfg.win_pos.X + (short)LOWORD(lParam) / data->curcfg.cell_width;
|
|
|
|
c.Y = data->curcfg.win_pos.Y + (short)HIWORD(lParam) / data->curcfg.cell_height;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_GetSelectionRect
|
|
|
|
*
|
|
|
|
* Get the selection rectangle
|
|
|
|
*/
|
|
|
|
static void WCUSER_GetSelectionRect(const struct inner_data* data, LPRECT r)
|
|
|
|
{
|
2002-06-02 23:20:43 +02:00
|
|
|
r->left = (min(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X) - data->curcfg.win_pos.X) * data->curcfg.cell_width;
|
|
|
|
r->top = (min(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y) - data->curcfg.win_pos.Y) * data->curcfg.cell_height;
|
|
|
|
r->right = (max(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X) + 1 - data->curcfg.win_pos.X) * data->curcfg.cell_width;
|
|
|
|
r->bottom = (max(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y) + 1 - data->curcfg.win_pos.Y) * data->curcfg.cell_height;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_SetSelection
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void WCUSER_SetSelection(const struct inner_data* data, HDC hRefDC)
|
|
|
|
{
|
|
|
|
HDC hDC;
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
WCUSER_GetSelectionRect(data, &r);
|
2007-08-23 17:14:58 +02:00
|
|
|
hDC = hRefDC ? hRefDC : GetDC(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
if (hDC)
|
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
if (data->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
HideCaret(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
InvertRect(hDC, &r);
|
|
|
|
if (hDC != hRefDC)
|
2007-08-23 17:14:58 +02:00
|
|
|
ReleaseDC(data->hWnd, hDC);
|
|
|
|
if (data->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
ShowCaret(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_MoveSelection
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2003-02-25 04:58:22 +01:00
|
|
|
static void WCUSER_MoveSelection(struct inner_data* data, COORD c1, COORD c2)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
HDC hDC;
|
|
|
|
|
2003-02-25 04:58:22 +01:00
|
|
|
if (c1.X < 0 || c1.X >= data->curcfg.sb_width ||
|
|
|
|
c2.X < 0 || c2.X >= data->curcfg.sb_width ||
|
|
|
|
c1.Y < 0 || c1.Y >= data->curcfg.sb_height ||
|
|
|
|
c2.Y < 0 || c2.Y >= data->curcfg.sb_height)
|
|
|
|
return;
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
WCUSER_GetSelectionRect(data, &r);
|
2007-08-23 17:14:58 +02:00
|
|
|
hDC = GetDC(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
if (hDC)
|
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
if (data->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
HideCaret(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
InvertRect(hDC, &r);
|
|
|
|
}
|
2002-02-04 19:41:32 +01:00
|
|
|
PRIVATE(data)->selectPt1 = c1;
|
|
|
|
PRIVATE(data)->selectPt2 = c2;
|
2001-11-24 00:04:58 +01:00
|
|
|
if (hDC)
|
|
|
|
{
|
|
|
|
WCUSER_GetSelectionRect(data, &r);
|
|
|
|
InvertRect(hDC, &r);
|
2007-08-23 17:14:58 +02:00
|
|
|
ReleaseDC(data->hWnd, hDC);
|
|
|
|
if (data->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
ShowCaret(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_CopySelectionToClipboard
|
|
|
|
*
|
|
|
|
* Copies the current selection into the clipboard
|
|
|
|
*/
|
|
|
|
static void WCUSER_CopySelectionToClipboard(const struct inner_data* data)
|
|
|
|
{
|
|
|
|
HANDLE hMem;
|
|
|
|
LPWSTR p;
|
|
|
|
unsigned w, h;
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
w = abs(PRIVATE(data)->selectPt1.X - PRIVATE(data)->selectPt2.X) + 2;
|
|
|
|
h = abs(PRIVATE(data)->selectPt1.Y - PRIVATE(data)->selectPt2.Y) + 1;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2007-08-23 17:14:58 +02:00
|
|
|
if (!OpenClipboard(data->hWnd)) return;
|
2001-11-24 00:04:58 +01:00
|
|
|
EmptyClipboard();
|
|
|
|
|
2002-06-02 23:20:43 +02:00
|
|
|
hMem = GlobalAlloc(GMEM_MOVEABLE, (w * h) * sizeof(WCHAR));
|
2001-11-24 00:04:58 +01:00
|
|
|
if (hMem && (p = GlobalLock(hMem)))
|
|
|
|
{
|
|
|
|
COORD c;
|
|
|
|
int y;
|
|
|
|
|
2002-06-02 23:20:43 +02:00
|
|
|
c.X = min(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X);
|
|
|
|
c.Y = min(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
for (y = 0; y < h; y++, c.Y++)
|
|
|
|
{
|
2006-10-19 19:25:08 +02:00
|
|
|
LPWSTR end;
|
2011-01-11 12:11:48 +01:00
|
|
|
DWORD count;
|
|
|
|
|
|
|
|
ReadConsoleOutputCharacterW(data->hConOut, p, w - 1, c, &count);
|
2010-04-28 01:07:52 +02:00
|
|
|
|
2006-10-19 19:25:08 +02:00
|
|
|
/* strip spaces from the end of the line */
|
|
|
|
end = p + w - 1;
|
|
|
|
while (end > p && *(end - 1) == ' ')
|
|
|
|
end--;
|
|
|
|
*end = (y < h - 1) ? '\n' : '\0';
|
|
|
|
p = end + 1;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
GlobalUnlock(hMem);
|
|
|
|
SetClipboardData(CF_UNICODETEXT, hMem);
|
|
|
|
}
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_PasteFromClipboard
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void WCUSER_PasteFromClipboard(struct inner_data* data)
|
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
WCHAR* ptr;
|
|
|
|
|
2007-08-23 17:14:58 +02:00
|
|
|
if (!OpenClipboard(data->hWnd)) return;
|
2001-11-24 00:04:58 +01:00
|
|
|
h = GetClipboardData(CF_UNICODETEXT);
|
|
|
|
if (h && (ptr = GlobalLock(h)))
|
|
|
|
{
|
|
|
|
int i, len = GlobalSize(h) / sizeof(WCHAR);
|
|
|
|
INPUT_RECORD ir[2];
|
|
|
|
DWORD n;
|
|
|
|
SHORT sh;
|
|
|
|
|
|
|
|
ir[0].EventType = KEY_EVENT;
|
|
|
|
ir[0].Event.KeyEvent.wRepeatCount = 0;
|
|
|
|
ir[0].Event.KeyEvent.dwControlKeyState = 0;
|
|
|
|
ir[0].Event.KeyEvent.bKeyDown = TRUE;
|
|
|
|
|
|
|
|
/* generate the corresponding input records */
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
{
|
|
|
|
/* FIXME: the modifying keys are not generated (shift, ctrl...) */
|
2010-04-28 01:07:52 +02:00
|
|
|
sh = VkKeyScanW(ptr[i]);
|
2001-11-24 00:04:58 +01:00
|
|
|
ir[0].Event.KeyEvent.wVirtualKeyCode = LOBYTE(sh);
|
2010-04-28 01:07:52 +02:00
|
|
|
ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKeyW(LOBYTE(sh), 0);
|
2001-11-24 00:04:58 +01:00
|
|
|
ir[0].Event.KeyEvent.uChar.UnicodeChar = ptr[i];
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
ir[1] = ir[0];
|
|
|
|
ir[1].Event.KeyEvent.bKeyDown = FALSE;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
WriteConsoleInputW(data->hConIn, ir, 2, &n);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
GlobalUnlock(h);
|
|
|
|
}
|
|
|
|
CloseClipboard();
|
|
|
|
}
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
/******************************************************************
|
2002-07-23 04:02:46 +02:00
|
|
|
* WCUSER_Refresh
|
2001-12-04 21:46:54 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2001-11-24 00:04:58 +01:00
|
|
|
static void WCUSER_Refresh(const struct inner_data* data, int tp, int bm)
|
|
|
|
{
|
2002-05-14 23:45:13 +02:00
|
|
|
WCUSER_FillMemDC(data, tp, bm);
|
2001-12-04 21:46:54 +01:00
|
|
|
if (data->curcfg.win_pos.Y <= bm && data->curcfg.win_pos.Y + data->curcfg.win_height >= tp)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
r.left = 0;
|
2001-12-04 21:46:54 +01:00
|
|
|
r.right = data->curcfg.win_width * data->curcfg.cell_width;
|
|
|
|
r.top = (tp - data->curcfg.win_pos.Y) * data->curcfg.cell_height;
|
|
|
|
r.bottom = (bm - data->curcfg.win_pos.Y + 1) * data->curcfg.cell_height;
|
2007-08-23 17:14:58 +02:00
|
|
|
InvalidateRect(data->hWnd, &r, FALSE);
|
|
|
|
UpdateWindow(data->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_Paint
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void WCUSER_Paint(const struct inner_data* data)
|
|
|
|
{
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
|
2010-11-15 21:36:02 +01:00
|
|
|
if (data->in_set_config) return; /* in order to avoid some flicker */
|
2007-08-23 17:14:58 +02:00
|
|
|
BeginPaint(data->hWnd, &ps);
|
2002-06-01 01:06:46 +02:00
|
|
|
BitBlt(ps.hdc, 0, 0,
|
|
|
|
data->curcfg.win_width * data->curcfg.cell_width,
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.win_height * data->curcfg.cell_height,
|
2002-06-01 01:06:46 +02:00
|
|
|
PRIVATE(data)->hMemDC,
|
|
|
|
data->curcfg.win_pos.X * data->curcfg.cell_width,
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.win_pos.Y * data->curcfg.cell_height,
|
2001-11-24 00:04:58 +01:00
|
|
|
SRCCOPY);
|
2002-02-04 19:41:32 +01:00
|
|
|
if (PRIVATE(data)->has_selection)
|
2001-11-24 00:04:58 +01:00
|
|
|
WCUSER_SetSelection(data, ps.hdc);
|
2007-08-23 17:14:58 +02:00
|
|
|
EndPaint(data->hWnd, &ps);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_Scroll
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void WCUSER_Scroll(struct inner_data* data, int pos, BOOL horz)
|
|
|
|
{
|
|
|
|
if (horz)
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
ScrollWindow(data->hWnd, (data->curcfg.win_pos.X - pos) * data->curcfg.cell_width, 0, NULL, NULL);
|
2007-08-23 17:14:58 +02:00
|
|
|
SetScrollPos(data->hWnd, SB_HORZ, pos, TRUE);
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.win_pos.X = pos;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
ScrollWindow(data->hWnd, 0, (data->curcfg.win_pos.Y - pos) * data->curcfg.cell_height, NULL, NULL);
|
2007-08-23 17:14:58 +02:00
|
|
|
SetScrollPos(data->hWnd, SB_VERT, pos, TRUE);
|
2001-12-04 21:46:54 +01:00
|
|
|
data->curcfg.win_pos.Y = pos;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2007-08-23 17:14:58 +02:00
|
|
|
InvalidateRect(data->hWnd, NULL, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2001-12-04 21:46:54 +01:00
|
|
|
* WCUSER_FillMenu
|
|
|
|
*
|
2001-11-24 00:04:58 +01:00
|
|
|
*
|
|
|
|
*/
|
2001-12-04 21:46:54 +01:00
|
|
|
static BOOL WCUSER_FillMenu(HMENU hMenu, BOOL sep)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2010-04-28 01:07:52 +02:00
|
|
|
HMENU hSubMenu;
|
|
|
|
HINSTANCE hInstance = GetModuleHandleW(NULL);
|
|
|
|
WCHAR buff[256];
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
if (!hMenu) return FALSE;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
/* FIXME: error handling & memory cleanup */
|
|
|
|
hSubMenu = CreateMenu();
|
2001-12-04 21:46:54 +01:00
|
|
|
if (!hSubMenu) return FALSE;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
LoadStringW(hInstance, IDS_MARK, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_MARK, buff);
|
|
|
|
LoadStringW(hInstance, IDS_COPY, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_COPY, buff);
|
|
|
|
LoadStringW(hInstance, IDS_PASTE, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_PASTE, buff);
|
|
|
|
LoadStringW(hInstance, IDS_SELECTALL, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SELECTALL, buff);
|
|
|
|
LoadStringW(hInstance, IDS_SCROLL, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SCROLL, buff);
|
|
|
|
LoadStringW(hInstance, IDS_SEARCH, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SEARCH, buff);
|
|
|
|
|
|
|
|
if (sep) InsertMenuW(hMenu, -1, MF_BYPOSITION|MF_SEPARATOR, 0, NULL);
|
|
|
|
LoadStringW(hInstance, IDS_EDIT, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hMenu, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, buff);
|
|
|
|
LoadStringW(hInstance, IDS_DEFAULT, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hMenu, -1, MF_BYPOSITION|MF_STRING, IDS_DEFAULT, buff);
|
|
|
|
LoadStringW(hInstance, IDS_PROPERTIES, buff, sizeof(buff) / sizeof(buff[0]));
|
|
|
|
InsertMenuW(hMenu, -1, MF_BYPOSITION|MF_STRING, IDS_PROPERTIES, buff);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-07-23 04:02:46 +02:00
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_SetMenuDetails
|
|
|
|
*
|
|
|
|
* Grays / ungrays the menu items according to their state
|
|
|
|
*/
|
|
|
|
static void WCUSER_SetMenuDetails(const struct inner_data* data, HMENU hMenu)
|
|
|
|
{
|
|
|
|
if (!hMenu) {WINE_ERR("Issue in getting menu bits\n");return;}
|
|
|
|
|
|
|
|
EnableMenuItem(hMenu, IDS_COPY,
|
|
|
|
MF_BYCOMMAND|(PRIVATE(data)->has_selection ? MF_ENABLED : MF_GRAYED));
|
|
|
|
EnableMenuItem(hMenu, IDS_PASTE,
|
|
|
|
MF_BYCOMMAND|(IsClipboardFormatAvailable(CF_UNICODETEXT)
|
|
|
|
? MF_ENABLED : MF_GRAYED));
|
|
|
|
EnableMenuItem(hMenu, IDS_SCROLL, MF_BYCOMMAND|MF_GRAYED);
|
|
|
|
EnableMenuItem(hMenu, IDS_SEARCH, MF_BYCOMMAND|MF_GRAYED);
|
|
|
|
}
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_Create
|
|
|
|
*
|
|
|
|
* Creates the window for the rendering
|
|
|
|
*/
|
2010-04-28 01:07:52 +02:00
|
|
|
static LRESULT WCUSER_Create(HWND hWnd, LPCREATESTRUCTW lpcs)
|
2001-12-04 21:46:54 +01:00
|
|
|
{
|
|
|
|
struct inner_data* data;
|
|
|
|
HMENU hSysMenu;
|
|
|
|
|
|
|
|
data = lpcs->lpCreateParams;
|
2010-04-28 01:07:52 +02:00
|
|
|
SetWindowLongPtrW(hWnd, 0, (DWORD_PTR)data);
|
2007-08-23 17:14:58 +02:00
|
|
|
data->hWnd = hWnd;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
|
|
|
hSysMenu = GetSystemMenu(hWnd, FALSE);
|
|
|
|
if (!hSysMenu) return 0;
|
|
|
|
PRIVATE(data)->hPopMenu = CreatePopupMenu();
|
|
|
|
if (!PRIVATE(data)->hPopMenu) return 0;
|
|
|
|
|
|
|
|
WCUSER_FillMenu(hSysMenu, TRUE);
|
|
|
|
WCUSER_FillMenu(PRIVATE(data)->hPopMenu, FALSE);
|
|
|
|
|
|
|
|
PRIVATE(data)->hMemDC = CreateCompatibleDC(0);
|
2002-05-14 23:45:13 +02:00
|
|
|
if (!PRIVATE(data)->hMemDC) {WINE_ERR("no mem dc\n");return 0;}
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
data->curcfg.quick_edit = FALSE;
|
2001-11-24 00:04:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
/******************************************************************
|
2002-10-29 00:51:27 +01:00
|
|
|
* WCUSER_GetCtrlKeyState
|
2002-02-04 19:41:32 +01:00
|
|
|
*
|
|
|
|
* Get the console bit mask equivalent to the VK_ status in keyState
|
|
|
|
*/
|
|
|
|
static DWORD WCUSER_GetCtrlKeyState(BYTE* keyState)
|
|
|
|
{
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
|
|
|
GetKeyboardState(keyState);
|
|
|
|
if (keyState[VK_SHIFT] & 0x80) ret |= SHIFT_PRESSED;
|
|
|
|
if (keyState[VK_LCONTROL] & 0x80) ret |= LEFT_CTRL_PRESSED;
|
|
|
|
if (keyState[VK_RCONTROL] & 0x80) ret |= RIGHT_CTRL_PRESSED;
|
|
|
|
if (keyState[VK_LMENU] & 0x80) ret |= LEFT_ALT_PRESSED;
|
|
|
|
if (keyState[VK_RMENU] & 0x80) ret |= RIGHT_ALT_PRESSED;
|
2002-06-01 01:06:46 +02:00
|
|
|
if (keyState[VK_CAPITAL] & 0x01) ret |= CAPSLOCK_ON;
|
2002-02-04 19:41:32 +01:00
|
|
|
if (keyState[VK_NUMLOCK] & 0x01) ret |= NUMLOCK_ON;
|
|
|
|
if (keyState[VK_SCROLL] & 0x01) ret |= SCROLLLOCK_ON;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_HandleSelectionKey
|
|
|
|
*
|
|
|
|
* Handles keys while selecting an area
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static void WCUSER_HandleSelectionKey(struct inner_data* data, BOOL down,
|
2002-02-04 19:41:32 +01:00
|
|
|
WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
BYTE keyState[256];
|
|
|
|
DWORD state = WCUSER_GetCtrlKeyState(keyState) & ~(CAPSLOCK_ON|NUMLOCK_ON|SCROLLLOCK_ON);
|
|
|
|
COORD c1, c2;
|
|
|
|
|
2006-10-19 19:22:24 +02:00
|
|
|
if (!down) return;
|
2002-02-04 19:41:32 +01:00
|
|
|
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case VK_RETURN:
|
|
|
|
PRIVATE(data)->has_selection = FALSE;
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
WCUSER_CopySelectionToClipboard(data);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
case VK_RIGHT:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c1.X++; c2.X++;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
case VK_LEFT:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c1.X--; c2.X--;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
case VK_UP:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c1.Y--; c2.Y--;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
case VK_DOWN:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c1.Y++; c2.Y++;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SHIFT_PRESSED:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case VK_RIGHT:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c2.X++;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
case VK_LEFT:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c2.X--;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
case VK_UP:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c2.Y--;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
case VK_DOWN:
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
c2.Y++;
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, c1, c2);
|
2006-10-19 19:36:30 +02:00
|
|
|
return;
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-10-19 19:36:30 +02:00
|
|
|
|
|
|
|
if (wParam < VK_SPACE) /* Shift, Alt, Ctrl, Num Lock etc. */
|
|
|
|
return;
|
|
|
|
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
PRIVATE(data)->has_selection = FALSE;
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
2001-12-04 21:46:54 +01:00
|
|
|
* WCUSER_GenerateKeyInputRecord
|
2001-11-24 00:04:58 +01:00
|
|
|
*
|
|
|
|
* generates input_record from windows WM_KEYUP/WM_KEYDOWN messages
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static void WCUSER_GenerateKeyInputRecord(struct inner_data* data, BOOL down,
|
2009-11-12 18:36:08 +01:00
|
|
|
WPARAM wParam, LPARAM lParam)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
DWORD n;
|
|
|
|
WCHAR buf[2];
|
|
|
|
static WCHAR last; /* keep last char seen as feed for key up message */
|
2002-02-04 19:41:32 +01:00
|
|
|
BYTE keyState[256];
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
ir.EventType = KEY_EVENT;
|
|
|
|
ir.Event.KeyEvent.bKeyDown = down;
|
|
|
|
ir.Event.KeyEvent.wRepeatCount = LOWORD(lParam);
|
|
|
|
ir.Event.KeyEvent.wVirtualKeyCode = wParam;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
ir.Event.KeyEvent.wVirtualScanCode = HIWORD(lParam) & 0xFF;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
ir.Event.KeyEvent.uChar.UnicodeChar = 0;
|
2002-02-04 19:41:32 +01:00
|
|
|
ir.Event.KeyEvent.dwControlKeyState = WCUSER_GetCtrlKeyState(keyState);
|
2001-11-24 00:04:58 +01:00
|
|
|
if (lParam & (1L << 24)) ir.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY;
|
2002-02-04 19:41:32 +01:00
|
|
|
|
2008-10-27 12:14:05 +01:00
|
|
|
if (down)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2008-10-27 12:14:05 +01:00
|
|
|
switch (ToUnicode(wParam, HIWORD(lParam), keyState, buf, 2, 0))
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
/* FIXME... should generate two events... */
|
2012-05-15 10:15:32 +02:00
|
|
|
/* fall through */
|
2008-10-27 12:14:05 +01:00
|
|
|
case 1:
|
|
|
|
last = buf[0];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
last = 0;
|
|
|
|
break;
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2008-10-27 12:14:05 +01:00
|
|
|
ir.Event.KeyEvent.uChar.UnicodeChar = last; /* FIXME: HACKY... and buggy because it should be a stack, not a single value */
|
|
|
|
if (!down) last = 0;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
WriteConsoleInputW(data->hConIn, &ir, 1, &n);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_GenerateMouseInputRecord
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
static void WCUSER_GenerateMouseInputRecord(struct inner_data* data, COORD c,
|
2002-02-04 19:41:32 +01:00
|
|
|
WPARAM wParam, DWORD event)
|
|
|
|
{
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
BYTE keyState[256];
|
|
|
|
DWORD mode, n;
|
|
|
|
|
|
|
|
/* MOUSE_EVENTs shouldn't be sent unless ENABLE_MOUSE_INPUT is active */
|
|
|
|
if (!GetConsoleMode(data->hConIn, &mode) || !(mode & ENABLE_MOUSE_INPUT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ir.EventType = MOUSE_EVENT;
|
|
|
|
ir.Event.MouseEvent.dwMousePosition = c;
|
|
|
|
ir.Event.MouseEvent.dwButtonState = 0;
|
|
|
|
if (wParam & MK_LBUTTON) ir.Event.MouseEvent.dwButtonState |= FROM_LEFT_1ST_BUTTON_PRESSED;
|
|
|
|
if (wParam & MK_MBUTTON) ir.Event.MouseEvent.dwButtonState |= FROM_LEFT_2ND_BUTTON_PRESSED;
|
|
|
|
if (wParam & MK_RBUTTON) ir.Event.MouseEvent.dwButtonState |= RIGHTMOST_BUTTON_PRESSED;
|
2005-10-10 12:26:46 +02:00
|
|
|
if (wParam & MK_CONTROL) ir.Event.MouseEvent.dwButtonState |= LEFT_CTRL_PRESSED;
|
|
|
|
if (wParam & MK_SHIFT) ir.Event.MouseEvent.dwButtonState |= SHIFT_PRESSED;
|
|
|
|
if (event == MOUSE_WHEELED) ir.Event.MouseEvent.dwButtonState |= wParam & 0xFFFF0000;
|
2002-02-04 19:41:32 +01:00
|
|
|
ir.Event.MouseEvent.dwControlKeyState = WCUSER_GetCtrlKeyState(keyState);
|
|
|
|
ir.Event.MouseEvent.dwEventFlags = event;
|
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
WriteConsoleInputW(data->hConIn, &ir, 1, &n);
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_Proc
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static LRESULT CALLBACK WCUSER_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2010-04-28 01:07:52 +02:00
|
|
|
struct inner_data* data = (struct inner_data*)GetWindowLongPtrW(hWnd, 0);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_CREATE:
|
2010-04-28 01:07:52 +02:00
|
|
|
return WCUSER_Create(hWnd, (LPCREATESTRUCTW)lParam);
|
2001-11-24 00:04:58 +01:00
|
|
|
case WM_DESTROY:
|
2007-08-23 17:14:58 +02:00
|
|
|
data->hWnd = 0;
|
2001-11-24 00:04:58 +01:00
|
|
|
PostQuitMessage(0);
|
|
|
|
break;
|
|
|
|
case WM_PAINT:
|
|
|
|
WCUSER_Paint(data);
|
|
|
|
break;
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
2002-02-04 19:41:32 +01:00
|
|
|
if (PRIVATE(data)->has_selection)
|
|
|
|
WCUSER_HandleSelectionKey(data, uMsg == WM_KEYDOWN, wParam, lParam);
|
|
|
|
else
|
2009-11-12 18:36:08 +01:00
|
|
|
WCUSER_GenerateKeyInputRecord(data, uMsg == WM_KEYDOWN, wParam, lParam);
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_SYSKEYUP:
|
2009-11-12 18:36:08 +01:00
|
|
|
WCUSER_GenerateKeyInputRecord(data, uMsg == WM_SYSKEYDOWN, wParam, lParam);
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
|
|
|
case WM_LBUTTONDOWN:
|
2006-10-19 19:35:02 +02:00
|
|
|
if (data->curcfg.quick_edit || PRIVATE(data)->has_selection)
|
2002-02-04 19:41:32 +01:00
|
|
|
{
|
|
|
|
if (PRIVATE(data)->has_selection)
|
2006-10-19 19:35:02 +02:00
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
|
|
|
|
if (data->curcfg.quick_edit && PRIVATE(data)->has_selection)
|
2002-02-04 19:41:32 +01:00
|
|
|
{
|
|
|
|
PRIVATE(data)->has_selection = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PRIVATE(data)->selectPt1 = PRIVATE(data)->selectPt2 = WCUSER_GetCell(data, lParam);
|
2007-08-23 17:14:58 +02:00
|
|
|
SetCapture(data->hWnd);
|
2002-02-04 19:41:32 +01:00
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
PRIVATE(data)->has_selection = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
else
|
2002-02-04 19:41:32 +01:00
|
|
|
{
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0);
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
|
|
|
case WM_MOUSEMOVE:
|
2006-10-19 19:35:02 +02:00
|
|
|
if (data->curcfg.quick_edit || PRIVATE(data)->has_selection)
|
2002-02-04 19:41:32 +01:00
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
if (GetCapture() == data->hWnd && PRIVATE(data)->has_selection &&
|
2002-02-04 19:41:32 +01:00
|
|
|
(wParam & MK_LBUTTON))
|
|
|
|
{
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, PRIVATE(data)->selectPt1, WCUSER_GetCell(data, lParam));
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, MOUSE_MOVED);
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
|
|
|
case WM_LBUTTONUP:
|
2006-10-19 19:35:02 +02:00
|
|
|
if (data->curcfg.quick_edit || PRIVATE(data)->has_selection)
|
2002-02-04 19:41:32 +01:00
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
if (GetCapture() == data->hWnd && PRIVATE(data)->has_selection)
|
2002-02-04 19:41:32 +01:00
|
|
|
{
|
2003-02-25 04:58:22 +01:00
|
|
|
WCUSER_MoveSelection(data, PRIVATE(data)->selectPt1, WCUSER_GetCell(data, lParam));
|
|
|
|
ReleaseCapture();
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0);
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
2002-02-04 19:41:32 +01:00
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
if ((wParam & (MK_CONTROL|MK_SHIFT)) == data->curcfg.menu_mask)
|
|
|
|
{
|
2006-10-19 19:38:01 +02:00
|
|
|
POINT pt;
|
2002-02-04 19:41:32 +01:00
|
|
|
|
2006-10-25 17:43:02 +02:00
|
|
|
pt.x = (short)LOWORD(lParam);
|
|
|
|
pt.y = (short)HIWORD(lParam);
|
2006-10-19 19:38:01 +02:00
|
|
|
ClientToScreen(hWnd, &pt);
|
2002-02-04 19:41:32 +01:00
|
|
|
WCUSER_SetMenuDetails(data, PRIVATE(data)->hPopMenu);
|
2010-09-22 19:29:53 +02:00
|
|
|
TrackPopupMenu(PRIVATE(data)->hPopMenu, TPM_LEFTALIGN|TPM_TOPALIGN|TPM_RIGHTBUTTON,
|
2006-10-19 19:38:01 +02:00
|
|
|
pt.x, pt.y, 0, hWnd, NULL);
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
break;
|
2002-02-04 19:41:32 +01:00
|
|
|
case WM_RBUTTONUP:
|
|
|
|
/* no need to track for rbutton up when opening the popup... the event will be
|
|
|
|
* swallowed by TrackPopupMenu */
|
2005-10-10 12:26:46 +02:00
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_MBUTTONUP:
|
2002-02-04 19:41:32 +01:00
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0);
|
2002-06-01 01:06:46 +02:00
|
|
|
break;
|
2005-10-10 12:26:46 +02:00
|
|
|
case WM_LBUTTONDBLCLK:
|
|
|
|
case WM_MBUTTONDBLCLK:
|
|
|
|
case WM_RBUTTONDBLCLK:
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, DOUBLE_CLICK);
|
|
|
|
break;
|
2001-11-24 00:04:58 +01:00
|
|
|
case WM_SETFOCUS:
|
2001-12-04 21:46:54 +01:00
|
|
|
if (data->curcfg.cursor_visible)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2007-08-23 17:14:58 +02:00
|
|
|
CreateCaret(data->hWnd, PRIVATE(data)->cursor_bitmap,
|
2002-06-01 01:06:46 +02:00
|
|
|
data->curcfg.cell_width, data->curcfg.cell_height);
|
2001-11-24 00:04:58 +01:00
|
|
|
WCUSER_PosCursor(data);
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
break;
|
|
|
|
case WM_KILLFOCUS:
|
2001-12-04 21:46:54 +01:00
|
|
|
if (data->curcfg.cursor_visible)
|
2002-06-01 01:06:46 +02:00
|
|
|
DestroyCaret();
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
case WM_HSCROLL:
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
struct config_data cfg = data->curcfg;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
case SB_PAGEUP: cfg.win_pos.X -= 8; break;
|
|
|
|
case SB_PAGEDOWN: cfg.win_pos.X += 8; break;
|
|
|
|
case SB_LINEUP: cfg.win_pos.X--; break;
|
|
|
|
case SB_LINEDOWN: cfg.win_pos.X++; break;
|
|
|
|
case SB_THUMBTRACK: cfg.win_pos.X = HIWORD(wParam); break;
|
|
|
|
default: break;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2010-11-15 21:35:55 +01:00
|
|
|
if (cfg.win_pos.X < 0) cfg.win_pos.X = 0;
|
|
|
|
if (cfg.win_pos.X > data->curcfg.sb_width - data->curcfg.win_width)
|
|
|
|
cfg.win_pos.X = data->curcfg.sb_width - data->curcfg.win_width;
|
|
|
|
if (cfg.win_pos.X != data->curcfg.win_pos.X)
|
2002-02-04 19:41:32 +01:00
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
WINECON_SetConfig(data, &cfg);
|
2002-02-04 19:41:32 +01:00
|
|
|
}
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
2010-02-26 01:15:13 +01:00
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
if (data->curcfg.sb_height <= data->curcfg.win_height)
|
|
|
|
{
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, MOUSE_WHEELED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* else fallthrough */
|
2002-06-01 01:06:46 +02:00
|
|
|
case WM_VSCROLL:
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
struct config_data cfg = data->curcfg;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2010-02-26 01:15:13 +01:00
|
|
|
if (uMsg == WM_MOUSEWHEEL)
|
|
|
|
{
|
|
|
|
UINT scrollLines = 3;
|
|
|
|
SystemParametersInfoW(SPI_GETWHEELSCROLLLINES, 0, &scrollLines, 0);
|
|
|
|
scrollLines *= -GET_WHEEL_DELTA_WPARAM(wParam) / WHEEL_DELTA;
|
2010-11-15 21:35:55 +01:00
|
|
|
cfg.win_pos.Y += scrollLines;
|
2010-02-26 01:15:13 +01:00
|
|
|
} else {
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
case SB_PAGEUP: cfg.win_pos.Y -= 8; break;
|
|
|
|
case SB_PAGEDOWN: cfg.win_pos.Y += 8; break;
|
|
|
|
case SB_LINEUP: cfg.win_pos.Y--; break;
|
|
|
|
case SB_LINEDOWN: cfg.win_pos.Y++; break;
|
|
|
|
case SB_THUMBTRACK: cfg.win_pos.Y = HIWORD(wParam); break;
|
|
|
|
default: break;
|
2010-02-26 01:15:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-15 21:35:55 +01:00
|
|
|
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)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2010-11-15 21:35:55 +01:00
|
|
|
WINECON_SetConfig(data, &cfg);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2010-02-26 01:15:13 +01:00
|
|
|
break;
|
2001-11-24 00:04:58 +01:00
|
|
|
case WM_SYSCOMMAND:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
|
|
|
case IDS_DEFAULT:
|
2001-12-04 21:46:54 +01:00
|
|
|
WCUSER_GetProperties(data, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
2002-07-02 01:22:48 +02:00
|
|
|
case IDS_PROPERTIES:
|
2001-12-04 21:46:54 +01:00
|
|
|
WCUSER_GetProperties(data, TRUE);
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
default:
|
2010-04-28 01:07:52 +02:00
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (wParam)
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
case IDS_DEFAULT:
|
|
|
|
WCUSER_GetProperties(data, FALSE);
|
|
|
|
break;
|
2002-07-02 01:22:48 +02:00
|
|
|
case IDS_PROPERTIES:
|
2001-12-04 21:46:54 +01:00
|
|
|
WCUSER_GetProperties(data, TRUE);
|
|
|
|
break;
|
2001-11-24 00:04:58 +01:00
|
|
|
case IDS_MARK:
|
2002-02-04 19:41:32 +01:00
|
|
|
PRIVATE(data)->selectPt1.X = PRIVATE(data)->selectPt1.Y = 0;
|
|
|
|
PRIVATE(data)->selectPt2.X = PRIVATE(data)->selectPt2.Y = 0;
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
PRIVATE(data)->has_selection = TRUE;
|
|
|
|
break;
|
2001-11-24 00:04:58 +01:00
|
|
|
case IDS_COPY:
|
2002-02-04 19:41:32 +01:00
|
|
|
if (PRIVATE(data)->has_selection)
|
|
|
|
{
|
|
|
|
PRIVATE(data)->has_selection = FALSE;
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
WCUSER_CopySelectionToClipboard(data);
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
|
|
|
case IDS_PASTE:
|
|
|
|
WCUSER_PasteFromClipboard(data);
|
|
|
|
break;
|
|
|
|
case IDS_SELECTALL:
|
2002-02-04 19:41:32 +01:00
|
|
|
PRIVATE(data)->selectPt1.X = PRIVATE(data)->selectPt1.Y = 0;
|
|
|
|
PRIVATE(data)->selectPt2.X = (data->curcfg.sb_width - 1) * data->curcfg.cell_width;
|
|
|
|
PRIVATE(data)->selectPt2.Y = (data->curcfg.sb_height - 1) * data->curcfg.cell_height;
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
PRIVATE(data)->has_selection = TRUE;
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
|
|
|
case IDS_SCROLL:
|
|
|
|
case IDS_SEARCH:
|
2007-05-24 16:41:17 +02:00
|
|
|
WINE_FIXME("Unhandled yet command: %lx\n", wParam);
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
2002-06-01 01:06:46 +02:00
|
|
|
default:
|
2010-04-28 01:07:52 +02:00
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_INITMENUPOPUP:
|
2010-04-28 01:07:52 +02:00
|
|
|
if (!HIWORD(lParam)) return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
2007-08-23 17:14:58 +02:00
|
|
|
WCUSER_SetMenuDetails(data, GetSystemMenu(data->hWnd, FALSE));
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
2010-11-15 21:36:02 +01:00
|
|
|
case WM_SIZE:
|
|
|
|
WINECON_ResizeWithContainer(data, LOWORD(lParam) / data->curcfg.cell_width,
|
|
|
|
HIWORD(lParam) / data->curcfg.cell_height);
|
|
|
|
break;
|
2001-11-24 00:04:58 +01:00
|
|
|
default:
|
2010-04-28 01:07:52 +02:00
|
|
|
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_DeleteBackend
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2004-11-29 19:00:10 +01:00
|
|
|
static void WCUSER_DeleteBackend(struct inner_data* data)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
if (!PRIVATE(data)) return;
|
2002-05-21 20:05:16 +02:00
|
|
|
if (PRIVATE(data)->hMemDC) DeleteDC(PRIVATE(data)->hMemDC);
|
2007-08-23 17:14:58 +02:00
|
|
|
if (data->hWnd) DestroyWindow(data->hWnd);
|
2001-12-04 21:46:54 +01:00
|
|
|
if (PRIVATE(data)->hFont) DeleteObject(PRIVATE(data)->hFont);
|
|
|
|
if (PRIVATE(data)->cursor_bitmap) DeleteObject(PRIVATE(data)->cursor_bitmap);
|
|
|
|
if (PRIVATE(data)->hBitmap) DeleteObject(PRIVATE(data)->hBitmap);
|
|
|
|
HeapFree(GetProcessHeap(), 0, PRIVATE(data));
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_MainLoop
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int WCUSER_MainLoop(struct inner_data* data)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
2007-08-23 17:14:58 +02:00
|
|
|
ShowWindow(data->hWnd, data->nCmdShow);
|
2011-03-20 09:18:10 +01:00
|
|
|
while (!data->dying || !data->curcfg.exit_on_die)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2002-09-04 20:41:52 +02:00
|
|
|
switch (MsgWaitForMultipleObjects(1, &data->hSynchro, FALSE, INFINITE, QS_ALLINPUT))
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
2011-03-20 09:18:10 +01:00
|
|
|
WINECON_GrabChanges(data);
|
2001-11-24 00:04:58 +01:00
|
|
|
break;
|
|
|
|
case WAIT_OBJECT_0+1:
|
2010-04-28 01:07:52 +02:00
|
|
|
/* need to use PeekMessageW loop instead of simple GetMessage:
|
2002-07-02 01:22:48 +02:00
|
|
|
* multiple messages might have arrived in between,
|
|
|
|
* so GetMessage would lead to delayed processing */
|
2010-04-28 01:07:52 +02:00
|
|
|
while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2002-07-02 04:14:08 +02:00
|
|
|
if (msg.message == WM_QUIT) return 0;
|
|
|
|
WINE_TRACE("dispatching msg %04x\n", msg.message);
|
2010-04-28 01:07:52 +02:00
|
|
|
DispatchMessageW(&msg);
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2002-05-14 23:45:13 +02:00
|
|
|
WINE_ERR("got pb\n");
|
2001-11-24 00:04:58 +01:00
|
|
|
/* err */
|
|
|
|
break;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2011-03-20 09:18:10 +01:00
|
|
|
PostQuitMessage(0);
|
|
|
|
return 0;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* WCUSER_InitBackend
|
|
|
|
*
|
|
|
|
* Initialisation part II: creation of window.
|
|
|
|
*
|
|
|
|
*/
|
2003-06-13 18:32:52 +02:00
|
|
|
enum init_return WCUSER_InitBackend(struct inner_data* data)
|
2001-11-24 00:04:58 +01:00
|
|
|
{
|
2004-04-20 02:34:52 +02:00
|
|
|
static const WCHAR wClassName[] = {'W','i','n','e','C','o','n','s','o','l','e','C','l','a','s','s',0};
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
WNDCLASSW wndclass;
|
|
|
|
CHARSETINFO ci;
|
|
|
|
|
2006-10-03 21:08:32 +02:00
|
|
|
if (!TranslateCharsetInfo((DWORD *)(INT_PTR)GetACP(), &ci, TCI_SRCCODEPAGE))
|
|
|
|
return init_failed;
|
|
|
|
g_uiDefaultCharset = ci.ciCharset;
|
|
|
|
WINE_TRACE_(wc_font)("Code page %d => Default charset: %d\n", GetACP(), g_uiDefaultCharset);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
2002-01-02 22:45:47 +01:00
|
|
|
data->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct inner_data_user));
|
2003-06-13 18:32:52 +02:00
|
|
|
if (!data->private) return init_failed;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
data->fnMainLoop = WCUSER_MainLoop;
|
|
|
|
data->fnPosCursor = WCUSER_PosCursor;
|
|
|
|
data->fnShapeCursor = WCUSER_ShapeCursor;
|
|
|
|
data->fnComputePositions = WCUSER_ComputePositions;
|
|
|
|
data->fnRefresh = WCUSER_Refresh;
|
|
|
|
data->fnResizeScreenBuffer = WCUSER_ResizeScreenBuffer;
|
|
|
|
data->fnSetTitle = WCUSER_SetTitle;
|
2002-09-04 20:41:52 +02:00
|
|
|
data->fnSetFont = WCUSER_SetFontPmt;
|
2001-11-24 00:04:58 +01:00
|
|
|
data->fnScroll = WCUSER_Scroll;
|
|
|
|
data->fnDeleteBackend = WCUSER_DeleteBackend;
|
|
|
|
|
2005-10-10 12:26:46 +02:00
|
|
|
wndclass.style = CS_DBLCLKS;
|
2001-11-24 00:04:58 +01:00
|
|
|
wndclass.lpfnWndProc = WCUSER_Proc;
|
|
|
|
wndclass.cbClsExtra = 0;
|
2006-05-31 09:27:39 +02:00
|
|
|
wndclass.cbWndExtra = sizeof(DWORD_PTR);
|
2010-04-28 01:07:52 +02:00
|
|
|
wndclass.hInstance = GetModuleHandleW(NULL);
|
|
|
|
wndclass.hIcon = LoadIconW(0, (LPCWSTR)IDI_WINLOGO);
|
|
|
|
wndclass.hCursor = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
|
2001-11-24 00:04:58 +01:00
|
|
|
wndclass.hbrBackground = GetStockObject(BLACK_BRUSH);
|
|
|
|
wndclass.lpszMenuName = NULL;
|
|
|
|
wndclass.lpszClassName = wClassName;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
RegisterClassW(&wndclass);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2010-04-28 01:07:52 +02:00
|
|
|
data->hWnd = CreateWindowW(wndclass.lpszClassName, NULL,
|
|
|
|
WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_HSCROLL|WS_VSCROLL,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0, 0, wndclass.hInstance, data);
|
2007-09-26 14:21:46 +02:00
|
|
|
if (!data->hWnd) return init_not_supported;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
2003-06-13 18:32:52 +02:00
|
|
|
return init_success;
|
2001-11-24 00:04:58 +01:00
|
|
|
}
|