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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
|
|
/* mapping console colors to RGB values */
|
2001-12-04 21:46:54 +01:00
|
|
|
|
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),
|
|
|
|
|
RGB(0x80, 0x00, 0x00), RGB(0x80, 0x00, 0x80), RGB(0x80, 0x80, 0x00), RGB(0x80, 0x80, 0x80),
|
2001-12-04 21:46:54 +01:00
|
|
|
|
RGB(0xC0, 0xC0, 0xC0), 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),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* 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;
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!(line = HeapAlloc(GetProcessHeap(), 0, data->curcfg.sb_width * sizeof(WCHAR))))
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{Trace(0, "OOM\n"); return;}
|
|
|
|
|
|
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];
|
|
|
|
|
for (i = 0; i < data->curcfg.win_width; i++)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
|
|
|
|
attr = cell[i].Attributes;
|
2001-12-31 23:20:56 +01:00
|
|
|
|
SetBkColor(PRIVATE(data)->hMemDC,WCUSER_ColorMap[(attr>>4)&0x0F]);
|
|
|
|
|
SetTextColor(PRIVATE(data)->hMemDC, WCUSER_ColorMap[attr&0x0F]);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
for (k = i; k < data->curcfg.win_width && cell[k].Attributes == attr; k++)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
|
|
|
|
line[k - i] = cell[k].Char.UnicodeChar;
|
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
TextOut(PRIVATE(data)->hMemDC, i * data->curcfg.cell_width, j * data->curcfg.cell_height,
|
2001-11-24 00:04:58 +01:00
|
|
|
|
line, k - i);
|
|
|
|
|
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
|
|
|
|
|
*
|
|
|
|
|
* Either the font geometry or the sb geometry has changed. we need to recreate the
|
|
|
|
|
* bitmap geometry
|
|
|
|
|
*/
|
|
|
|
|
static void WCUSER_NewBitmap(struct inner_data* data, BOOL fill)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
HDC hDC;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
HBITMAP hnew, hold;
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!data->curcfg.sb_width || !data->curcfg.sb_height || !(hDC = GetDC(PRIVATE(data)->hWnd)))
|
|
|
|
|
return;
|
|
|
|
|
hnew = CreateCompatibleBitmap(hDC,
|
|
|
|
|
data->curcfg.sb_width * data->curcfg.cell_width,
|
|
|
|
|
data->curcfg.sb_height * data->curcfg.cell_height);
|
|
|
|
|
ReleaseDC(PRIVATE(data)->hWnd, hDC);
|
|
|
|
|
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
|
|
|
|
|
Trace(0, "leak\n");
|
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
PRIVATE(data)->hBitmap = hnew;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
if (fill)
|
2001-12-04 21:46:54 +01: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)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_NewBitmap(data, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_PosCursor
|
|
|
|
|
*
|
|
|
|
|
* Set a new position for the cursor
|
|
|
|
|
*/
|
|
|
|
|
static void WCUSER_PosCursor(const struct inner_data* data)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (PRIVATE(data)->hWnd != GetFocus() || !data->curcfg.cursor_visible) return;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
SetCaretPos((data->cursor.X - data->curcfg.win_pos.X) * data->curcfg.cell_width,
|
|
|
|
|
(data->cursor.Y - data->curcfg.win_pos.Y) * data->curcfg.cell_height);
|
|
|
|
|
ShowCaret(PRIVATE(data)->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_ShapeCursor
|
|
|
|
|
*
|
|
|
|
|
* Sets a new shape for the cursor
|
|
|
|
|
*/
|
|
|
|
|
void WCUSER_ShapeCursor(struct inner_data* data, int size, int vis, BOOL force)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (force || size != data->curcfg.cursor_size)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (data->curcfg.cursor_visible && PRIVATE(data)->hWnd == GetFocus()) DestroyCaret();
|
|
|
|
|
if (PRIVATE(data)->cursor_bitmap) DeleteObject(PRIVATE(data)->cursor_bitmap);
|
|
|
|
|
PRIVATE(data)->cursor_bitmap = (HBITMAP)0;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
if (size != 100)
|
|
|
|
|
{
|
|
|
|
|
int w16b; /* number of byets per row, aligned on word size */
|
|
|
|
|
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);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
if (!ptr) {Trace(0, "OOM\n"); return;}
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
PRIVATE(data)->cursor_bitmap = CreateBitmap(data->curcfg.cell_width,
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vis = (vis) ? TRUE : FALSE;
|
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;
|
|
|
|
|
if (PRIVATE(data)->hWnd == GetFocus())
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
|
|
|
|
if (vis)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
CreateCaret(PRIVATE(data)->hWnd, PRIVATE(data)->cursor_bitmap,
|
|
|
|
|
data->curcfg.cell_width, data->curcfg.cell_height);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
WCUSER_PosCursor(data);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DestroyCaret();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* INECON_ComputePositions
|
|
|
|
|
*
|
|
|
|
|
* Recomputes all the components (mainly scroll bars) positions
|
|
|
|
|
*/
|
|
|
|
|
void WCUSER_ComputePositions(struct inner_data* data)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
if (IsRectEmpty(&r))
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
ShowWindow(PRIVATE(data)->hWnd, SW_HIDE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
AdjustWindowRect(&r, GetWindowLong(PRIVATE(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);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
SetScrollRange(PRIVATE(data)->hWnd, SB_HORZ, 0,
|
|
|
|
|
data->curcfg.sb_width - data->curcfg.win_width, FALSE);
|
|
|
|
|
SetScrollPos(PRIVATE(data)->hWnd, SB_HORZ, 0, FALSE); /* FIXME */
|
|
|
|
|
ShowScrollBar(PRIVATE(data)->hWnd, SB_HORZ, TRUE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
ShowScrollBar(PRIVATE(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);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
SetScrollRange(PRIVATE(data)->hWnd, SB_VERT, 0,
|
|
|
|
|
data->curcfg.sb_height - data->curcfg.win_height, FALSE);
|
|
|
|
|
SetScrollPos(PRIVATE(data)->hWnd, SB_VERT, 0, FALSE); /* FIXME */
|
|
|
|
|
ShowScrollBar(PRIVATE(data)->hWnd, SB_VERT, TRUE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
ShowScrollBar(PRIVATE(data)->hWnd, SB_VERT, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
SetWindowPos(PRIVATE(data)->hWnd, 0, 0, 0, r.right - r.left + dx, r.bottom - r.top + dy,
|
2001-11-24 00:04:58 +01:00
|
|
|
|
SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW);
|
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)
|
|
|
|
|
{
|
|
|
|
|
WCHAR buffer[256];
|
|
|
|
|
|
|
|
|
|
if (WINECON_GetConsoleTitle(data->hConIn, buffer, sizeof(buffer)))
|
2001-12-04 21:46:54 +01:00
|
|
|
|
SetWindowText(PRIVATE(data)->hWnd, buffer);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
2001-12-04 21:46:54 +01:00
|
|
|
|
* FontEqual
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
BOOL WCUSER_AreFontsEqual(const struct config_data* config, const LOGFONT* lf)
|
|
|
|
|
{
|
|
|
|
|
return lf->lfHeight == config->cell_height &&
|
|
|
|
|
lf->lfWeight == config->font_weight &&
|
|
|
|
|
!lf->lfItalic && !lf->lfUnderline && !lf->lfStrikeOut &&
|
2002-03-23 21:14:04 +01:00
|
|
|
|
!lstrcmp(lf->lfFaceName, config->face_name);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-23 21:14:04 +01:00
|
|
|
|
struct font_chooser {
|
|
|
|
|
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
|
|
|
|
|
*/
|
|
|
|
|
BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRIC* tm, DWORD fontType)
|
|
|
|
|
{
|
|
|
|
|
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 &&
|
|
|
|
|
(tm->tmCharSet == DEFAULT_CHARSET /*|| tm->tmCharSet == ANSI_CHARSET*/);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* 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
|
|
|
|
*/
|
2002-03-23 21:14:04 +01:00
|
|
|
|
BOOL WCUSER_ValidateFont(const struct inner_data* data, const LOGFONT* lf)
|
2001-12-04 21:46:54 +01:00
|
|
|
|
{
|
2002-03-23 21:14:04 +01:00
|
|
|
|
return (lf->lfPitchAndFamily & 3) == FIXED_PITCH &&
|
|
|
|
|
/* (lf->lfPitchAndFamily & 0xF0) == FF_MODERN && */
|
|
|
|
|
(lf->lfCharSet == DEFAULT_CHARSET || lf->lfCharSet == ANSI_CHARSET);
|
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
|
|
|
|
*/
|
2002-03-23 21:14:04 +01:00
|
|
|
|
static int CALLBACK get_first_font_enum_2(const LOGFONT* lf, const TEXTMETRIC* 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-03-23 21:14:04 +01:00
|
|
|
|
if (WCUSER_ValidateFontMetric(fc->data, tm, FontType))
|
|
|
|
|
{
|
|
|
|
|
WCUSER_SetFont(fc->data, lf);
|
|
|
|
|
fc->done = 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int CALLBACK get_first_font_enum(const LOGFONT* lf, const TEXTMETRIC* tm,
|
|
|
|
|
DWORD FontType, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
struct font_chooser* fc = (struct font_chooser*)lParam;
|
|
|
|
|
|
|
|
|
|
if (WCUSER_ValidateFont(fc->data, lf))
|
|
|
|
|
{
|
|
|
|
|
EnumFontFamilies(PRIVATE(fc->data)->hMemDC, lf->lfFaceName, get_first_font_enum_2, lParam);
|
|
|
|
|
return !fc->done; /* we just need the first matching one... */
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* CopyFont
|
|
|
|
|
*
|
|
|
|
|
* get the relevant information from the font described in lf and store them
|
|
|
|
|
* in config
|
|
|
|
|
*/
|
|
|
|
|
HFONT WCUSER_CopyFont(struct config_data* config, HWND hWnd, const LOGFONT* lf)
|
|
|
|
|
{
|
|
|
|
|
TEXTMETRIC tm;
|
|
|
|
|
HDC hDC;
|
|
|
|
|
HFONT hFont, hOldFont;
|
|
|
|
|
int w, i, buf[256];
|
|
|
|
|
|
|
|
|
|
if (!(hDC = GetDC(hWnd))) return (HFONT)0;
|
|
|
|
|
if (!(hFont = CreateFontIndirect(lf))) goto err1;
|
|
|
|
|
|
|
|
|
|
hOldFont = SelectObject(hDC, hFont);
|
|
|
|
|
GetTextMetrics(hDC, &tm);
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
* In Windows, those fonts are expectes to return the same value for
|
|
|
|
|
* - the average width
|
|
|
|
|
* - the largest width
|
|
|
|
|
* - the width of all characters in the font
|
|
|
|
|
* This isn't true in Wine. As a temporary workaound, we get as the width of the
|
|
|
|
|
* cell, the width of the first character in the font, after checking that all
|
|
|
|
|
* characters in the font have the same width (I hear parano<EFBFBD>a coming)
|
|
|
|
|
* when this gets fixed, the should be using tm.tmAveCharWidth or tm.tmMaxCharWidth
|
|
|
|
|
* as the cell width.
|
|
|
|
|
*/
|
|
|
|
|
GetCharWidth32(hDC, tm.tmFirstChar, tm.tmFirstChar, &w);
|
|
|
|
|
for (i = tm.tmFirstChar + 1; i <= tm.tmLastChar; i += sizeof(buf) / sizeof(buf[0]))
|
|
|
|
|
{
|
|
|
|
|
int j, l;
|
|
|
|
|
|
|
|
|
|
l = min(tm.tmLastChar - i, sizeof(buf) / sizeof(buf[0]) - 1);
|
|
|
|
|
GetCharWidth32(hDC, i, i + l, buf);
|
|
|
|
|
for (j = 0; j <= l; j++)
|
|
|
|
|
{
|
|
|
|
|
if (buf[j] != w)
|
|
|
|
|
{
|
|
|
|
|
Trace(0, "Non uniform cell width: [%d]=%d [%d]=%d\n",
|
|
|
|
|
i + j, buf[j], tm.tmFirstChar, w);
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SelectObject(hDC, hOldFont);
|
|
|
|
|
ReleaseDC(hWnd, hDC);
|
|
|
|
|
|
|
|
|
|
config->cell_width = w;
|
|
|
|
|
config->cell_height = tm.tmHeight;
|
|
|
|
|
config->font_weight = tm.tmWeight;
|
|
|
|
|
lstrcpy(config->face_name, lf->lfFaceName);
|
|
|
|
|
|
|
|
|
|
return hFont;
|
|
|
|
|
err:
|
|
|
|
|
if (hDC && hOldFont) SelectObject(hDC, hOldFont);
|
|
|
|
|
if (hFont) DeleteObject(hFont);
|
|
|
|
|
err1:
|
|
|
|
|
if (hDC) ReleaseDC(hWnd, hDC);
|
|
|
|
|
|
|
|
|
|
return (HFONT)0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_FillLogFont
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void WCUSER_FillLogFont(LOGFONT* lf, const WCHAR* name, UINT height, UINT weight)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
|
|
|
|
|
lf->lfQuality = DEFAULT_QUALITY;
|
|
|
|
|
lf->lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
|
|
|
|
|
lstrcpy(lf->lfFaceName, name);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_SetFont
|
|
|
|
|
*
|
|
|
|
|
* sets logfont as the new font for the console
|
|
|
|
|
*/
|
|
|
|
|
BOOL WCUSER_SetFont(struct inner_data* data, const LOGFONT* logfont)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (WCUSER_AreFontsEqual(&data->curcfg, logfont)) return TRUE;
|
|
|
|
|
if (PRIVATE(data)->hFont) DeleteObject(PRIVATE(data)->hFont);
|
2002-03-23 21:14:04 +01:00
|
|
|
|
|
|
|
|
|
PRIVATE(data)->hFont = WCUSER_CopyFont(&data->curcfg, PRIVATE(data)->hWnd, logfont);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!PRIVATE(data)->hFont) {Trace(0, "wrong font\n");return FALSE;}
|
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
|
WCUSER_ComputePositions(data);
|
|
|
|
|
WCUSER_NewBitmap(data, TRUE);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
InvalidateRect(PRIVATE(data)->hWnd, NULL, FALSE);
|
|
|
|
|
UpdateWindow(PRIVATE(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
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_InitFont
|
|
|
|
|
*
|
|
|
|
|
* create a hFont from the settings saved in registry...
|
|
|
|
|
* (called on init, assuming no font has been created before)
|
|
|
|
|
*/
|
|
|
|
|
static BOOL WCUSER_InitFont(struct inner_data* data)
|
|
|
|
|
{
|
|
|
|
|
LOGFONT lf;
|
|
|
|
|
struct font_chooser fc;
|
|
|
|
|
|
|
|
|
|
WCUSER_FillLogFont(&lf, data->curcfg.face_name,
|
|
|
|
|
data->curcfg.cell_height, data->curcfg.font_weight);
|
|
|
|
|
data->curcfg.face_name[0] = 0;
|
|
|
|
|
data->curcfg.cell_height = data->curcfg.font_weight = 0;
|
|
|
|
|
|
|
|
|
|
if (WCUSER_SetFont(data, &lf)) return TRUE;
|
|
|
|
|
|
|
|
|
|
/* try to find an acceptable font */
|
|
|
|
|
Trace(0, "Couldn't match the font from registry... trying to find one\n");
|
|
|
|
|
fc.data = data;
|
|
|
|
|
fc.done = 0;
|
|
|
|
|
EnumFontFamilies(PRIVATE(data)->hMemDC, NULL, get_first_font_enum, (LPARAM)&fc);
|
|
|
|
|
return fc.done;
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_GetCell
|
|
|
|
|
*
|
|
|
|
|
* Get a cell from the a relative coordinate in window (takes into
|
|
|
|
|
* 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)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
r->left = (min(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X) ) * data->curcfg.cell_width;
|
|
|
|
|
r->top = (min(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y) ) * data->curcfg.cell_height;
|
|
|
|
|
r->right = (max(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X) + 1) * data->curcfg.cell_width;
|
|
|
|
|
r->bottom = (max(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y) + 1) * 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);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
hDC = hRefDC ? hRefDC : GetDC(PRIVATE(data)->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
if (hDC)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (PRIVATE(data)->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
|
HideCaret(PRIVATE(data)->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
InvertRect(hDC, &r);
|
|
|
|
|
if (hDC != hRefDC)
|
2001-12-04 21:46:54 +01:00
|
|
|
|
ReleaseDC(PRIVATE(data)->hWnd, hDC);
|
|
|
|
|
if (PRIVATE(data)->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
|
ShowCaret(PRIVATE(data)->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_MoveSelection
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
2002-02-04 19:41:32 +01:00
|
|
|
|
static void WCUSER_MoveSelection(struct inner_data* data, COORD c1, COORD c2, BOOL final)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
|
|
|
|
RECT r;
|
|
|
|
|
HDC hDC;
|
|
|
|
|
|
|
|
|
|
WCUSER_GetSelectionRect(data, &r);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
hDC = GetDC(PRIVATE(data)->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
if (hDC)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (PRIVATE(data)->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
|
HideCaret(PRIVATE(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);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
ReleaseDC(PRIVATE(data)->hWnd, hDC);
|
|
|
|
|
if (PRIVATE(data)->hWnd == GetFocus() && data->curcfg.cursor_visible)
|
|
|
|
|
ShowCaret(PRIVATE(data)->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
if (final)
|
|
|
|
|
{
|
|
|
|
|
ReleaseCapture();
|
2002-02-04 19:41:32 +01:00
|
|
|
|
PRIVATE(data)->has_selection = TRUE;
|
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
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!OpenClipboard(PRIVATE(data)->hWnd)) return;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
EmptyClipboard();
|
|
|
|
|
|
|
|
|
|
hMem = GlobalAlloc(GMEM_MOVEABLE, (w * h - 1) * sizeof(WCHAR));
|
|
|
|
|
if (hMem && (p = GlobalLock(hMem)))
|
|
|
|
|
{
|
|
|
|
|
COORD c;
|
|
|
|
|
int y;
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
c.X = data->curcfg.win_pos.X + min(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X);
|
|
|
|
|
c.Y = data->curcfg.win_pos.Y + min(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
|
|
for (y = 0; y < h; y++, c.Y++)
|
|
|
|
|
{
|
|
|
|
|
ReadConsoleOutputCharacter(data->hConOut, &p[y * w], w - 1, c, NULL);
|
|
|
|
|
if (y < h - 1) p[y * w + w - 1] = '\n';
|
|
|
|
|
}
|
|
|
|
|
GlobalUnlock(hMem);
|
|
|
|
|
SetClipboardData(CF_UNICODETEXT, hMem);
|
|
|
|
|
}
|
|
|
|
|
CloseClipboard();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_PasteFromClipboard
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void WCUSER_PasteFromClipboard(struct inner_data* data)
|
|
|
|
|
{
|
|
|
|
|
HANDLE h;
|
|
|
|
|
WCHAR* ptr;
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!OpenClipboard(PRIVATE(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...) */
|
|
|
|
|
sh = VkKeyScan(ptr[i]);
|
|
|
|
|
ir[0].Event.KeyEvent.wVirtualKeyCode = LOBYTE(sh);
|
|
|
|
|
ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(LOBYTE(sh), 0);
|
|
|
|
|
ir[0].Event.KeyEvent.uChar.UnicodeChar = ptr[i];
|
|
|
|
|
|
|
|
|
|
ir[1] = ir[0];
|
|
|
|
|
ir[1].Event.KeyEvent.bKeyDown = FALSE;
|
|
|
|
|
|
|
|
|
|
WriteConsoleInput(data->hConIn, ir, 2, &n);
|
|
|
|
|
}
|
|
|
|
|
GlobalUnlock(h);
|
|
|
|
|
}
|
|
|
|
|
CloseClipboard();
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
/******************************************************************
|
|
|
|
|
* Refresh
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
2001-11-24 00:04:58 +01:00
|
|
|
|
static void WCUSER_Refresh(const struct inner_data* data, int tp, int 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;
|
|
|
|
|
InvalidateRect(PRIVATE(data)->hWnd, &r, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
WCUSER_FillMemDC(data, tp, bm);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
UpdateWindow(PRIVATE(data)->hWnd);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_Paint
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void WCUSER_Paint(const struct inner_data* data)
|
|
|
|
|
{
|
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
BeginPaint(PRIVATE(data)->hWnd, &ps);
|
|
|
|
|
BitBlt(ps.hdc, 0, 0,
|
|
|
|
|
data->curcfg.win_width * data->curcfg.cell_width,
|
|
|
|
|
data->curcfg.win_height * data->curcfg.cell_height,
|
|
|
|
|
PRIVATE(data)->hMemDC,
|
|
|
|
|
data->curcfg.win_pos.X * data->curcfg.cell_width,
|
|
|
|
|
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);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
EndPaint(PRIVATE(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)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
SetScrollPos(PRIVATE(data)->hWnd, SB_HORZ, pos, TRUE);
|
|
|
|
|
data->curcfg.win_pos.X = pos;
|
|
|
|
|
InvalidateRect(PRIVATE(data)->hWnd, NULL, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
SetScrollPos(PRIVATE(data)->hWnd, SB_VERT, pos, TRUE);
|
|
|
|
|
data->curcfg.win_pos.Y = pos;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
2001-12-04 21:46:54 +01:00
|
|
|
|
InvalidateRect(PRIVATE(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
|
|
|
|
{
|
|
|
|
|
HMENU hSubMenu;
|
|
|
|
|
HINSTANCE hInstance = GetModuleHandle(NULL);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
LoadString(hInstance, IDS_MARK, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_MARK, buff);
|
|
|
|
|
LoadString(hInstance, IDS_COPY, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_COPY, buff);
|
|
|
|
|
LoadString(hInstance, IDS_PASTE, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_PASTE, buff);
|
|
|
|
|
LoadString(hInstance, IDS_SELECTALL, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SELECTALL, buff);
|
|
|
|
|
LoadString(hInstance, IDS_SCROLL, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SCROLL, buff);
|
|
|
|
|
LoadString(hInstance, IDS_SEARCH, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SEARCH, buff);
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (sep) InsertMenu(hMenu, -1, MF_BYPOSITION|MF_SEPARATOR, 0, NULL);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
LoadString(hInstance, IDS_EDIT, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, buff);
|
|
|
|
|
LoadString(hInstance, IDS_DEFAULT, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, IDS_DEFAULT, buff);
|
|
|
|
|
LoadString(hInstance, IDS_PROPERTY, buff, sizeof(buff) / sizeof(WCHAR));
|
|
|
|
|
InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, IDS_PROPERTY, buff);
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_Create
|
|
|
|
|
*
|
|
|
|
|
* Creates the window for the rendering
|
|
|
|
|
*/
|
|
|
|
|
static LRESULT WCUSER_Create(HWND hWnd, LPCREATESTRUCT lpcs)
|
|
|
|
|
{
|
|
|
|
|
struct inner_data* data;
|
|
|
|
|
HMENU hSysMenu;
|
|
|
|
|
|
|
|
|
|
data = lpcs->lpCreateParams;
|
|
|
|
|
SetWindowLong(hWnd, 0L, (DWORD)data);
|
|
|
|
|
PRIVATE(data)->hWnd = hWnd;
|
|
|
|
|
|
|
|
|
|
data->curcfg.cursor_size = 101; /* invalid value, will trigger a complete cleanup */
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if (!PRIVATE(data)->hMemDC) {Trace(0, "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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_SetMenuDetails
|
|
|
|
|
*
|
|
|
|
|
* Grays / ungrays the menu items according to their state
|
|
|
|
|
*/
|
2002-02-04 19:41:32 +01:00
|
|
|
|
static void WCUSER_SetMenuDetails(const struct inner_data* data, HMENU hMenu)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
|
|
|
|
if (!hMenu) {Trace(0, "Issue in getting menu bits\n");return;}
|
|
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
|
EnableMenuItem(hMenu, IDS_COPY,
|
|
|
|
|
MF_BYCOMMAND|(PRIVATE(data)->has_selection ? MF_ENABLED : MF_GRAYED));
|
2001-11-24 00:04:58 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
|
/******************************************************************
|
|
|
|
|
* CUSER_GetCtrlKeyState
|
|
|
|
|
*
|
|
|
|
|
* 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_CONTROL] & 0x80) ret |= LEFT_CTRL_PRESSED; /* FIXME: gotta choose one */
|
|
|
|
|
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;
|
|
|
|
|
if (keyState[VK_CAPITAL] & 0x01) ret |= CAPSLOCK_ON;
|
|
|
|
|
if (keyState[VK_NUMLOCK] & 0x01) ret |= NUMLOCK_ON;
|
|
|
|
|
if (keyState[VK_SCROLL] & 0x01) ret |= SCROLLLOCK_ON;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_HandleSelectionKey
|
|
|
|
|
*
|
|
|
|
|
* Handles keys while selecting an area
|
|
|
|
|
*/
|
|
|
|
|
static void WCUSER_HandleSelectionKey(struct inner_data* data, BOOL down,
|
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
BYTE keyState[256];
|
|
|
|
|
DWORD state = WCUSER_GetCtrlKeyState(keyState) & ~(CAPSLOCK_ON|NUMLOCK_ON|SCROLLLOCK_ON);
|
|
|
|
|
COORD c1, c2;
|
|
|
|
|
|
|
|
|
|
if (down) return;
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
switch (wParam)
|
|
|
|
|
{
|
|
|
|
|
case VK_RETURN:
|
|
|
|
|
PRIVATE(data)->has_selection = FALSE;
|
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
|
WCUSER_CopySelectionToClipboard(data);
|
|
|
|
|
break;
|
|
|
|
|
case VK_RIGHT:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c1.X++; c2.X++;
|
|
|
|
|
if (c1.X < data->curcfg.sb_width && c2.X < data->curcfg.sb_width)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VK_LEFT:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c1.X--; c2.X--;
|
|
|
|
|
if (c1.X >= 0 && c2.X >= 0)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VK_UP:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c1.Y--; c2.Y--;
|
|
|
|
|
if (c1.Y >= 0 && c2.Y >= 0)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VK_DOWN:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c1.Y++; c2.Y++;
|
|
|
|
|
if (c1.X < data->curcfg.sb_height && c2.X < data->curcfg.sb_height)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case SHIFT_PRESSED:
|
|
|
|
|
switch (wParam)
|
|
|
|
|
{
|
|
|
|
|
case VK_RIGHT:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c2.X++;
|
|
|
|
|
if (c2.X < data->curcfg.sb_width)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VK_LEFT:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c2.X--;
|
|
|
|
|
if (c2.X >= c1.X)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VK_UP:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c2.Y--;
|
|
|
|
|
if (c2.Y >= c1.Y)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VK_DOWN:
|
|
|
|
|
c1 = PRIVATE(data)->selectPt1;
|
|
|
|
|
c2 = PRIVATE(data)->selectPt2;
|
|
|
|
|
c2.Y++;
|
|
|
|
|
if (c2.X < data->curcfg.sb_height)
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, c1, c2, FALSE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
*/
|
2001-12-04 21:46:54 +01:00
|
|
|
|
static void WCUSER_GenerateKeyInputRecord(struct inner_data* data, BOOL down,
|
|
|
|
|
WPARAM wParam, LPARAM lParam, BOOL sys)
|
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;
|
|
|
|
|
|
|
|
|
|
ir.Event.KeyEvent.wVirtualScanCode = HIWORD(lParam) & 0xFF;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
if (sys) ir.Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED; /* FIXME: gotta choose one */
|
2002-02-04 19:41:32 +01:00
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
|
if (!(ir.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
|
|
|
|
|
{
|
|
|
|
|
if (down)
|
|
|
|
|
{
|
|
|
|
|
switch (ToUnicode(wParam, HIWORD(lParam), keyState, buf, 2, 0))
|
|
|
|
|
{
|
|
|
|
|
case 2:
|
|
|
|
|
/* FIXME... should generate two events... */
|
|
|
|
|
/* fall thru */
|
|
|
|
|
case 1:
|
|
|
|
|
last = buf[0];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
last = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ir.Event.KeyEvent.uChar.UnicodeChar = last; /* FIXME HACKY... and buggy 'coz it should be a stack, not a single value */
|
|
|
|
|
if (!down) last = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
WriteConsoleInput(data->hConIn, &ir, 1, &n);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_GenerateMouseInputRecord
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void WCUSER_GenerateMouseInputRecord(struct inner_data* data, COORD c,
|
|
|
|
|
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;
|
|
|
|
|
ir.Event.MouseEvent.dwControlKeyState = WCUSER_GetCtrlKeyState(keyState);
|
|
|
|
|
ir.Event.MouseEvent.dwEventFlags = event;
|
|
|
|
|
|
|
|
|
|
WriteConsoleInput(data->hConIn, &ir, 1, &n);
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-24 00:04:58 +01:00
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_Proc
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static LRESULT CALLBACK WCUSER_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
|
{
|
|
|
|
|
struct inner_data* data = (struct inner_data*)GetWindowLong(hWnd, 0);
|
|
|
|
|
|
|
|
|
|
switch (uMsg)
|
|
|
|
|
{
|
|
|
|
|
case WM_CREATE:
|
|
|
|
|
return WCUSER_Create(hWnd, (LPCREATESTRUCT)lParam);
|
|
|
|
|
case WM_DESTROY:
|
2001-12-04 21:46:54 +01:00
|
|
|
|
PRIVATE(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
|
|
|
|
|
WCUSER_GenerateKeyInputRecord(data, uMsg == WM_KEYDOWN, wParam, lParam, FALSE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
break;
|
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
|
case WM_SYSKEYUP:
|
2001-12-04 21:46:54 +01:00
|
|
|
|
WCUSER_GenerateKeyInputRecord(data, uMsg == WM_SYSKEYDOWN, wParam, lParam, TRUE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
break;
|
|
|
|
|
case WM_LBUTTONDOWN:
|
2002-02-04 19:41:32 +01:00
|
|
|
|
if (data->curcfg.quick_edit)
|
|
|
|
|
{
|
|
|
|
|
if (PRIVATE(data)->has_selection)
|
|
|
|
|
{
|
|
|
|
|
PRIVATE(data)->has_selection = FALSE;
|
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PRIVATE(data)->selectPt1 = PRIVATE(data)->selectPt2 = WCUSER_GetCell(data, lParam);
|
|
|
|
|
SetCapture(PRIVATE(data)->hWnd);
|
|
|
|
|
WCUSER_SetSelection(data, 0);
|
|
|
|
|
PRIVATE(data)->has_selection = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0);
|
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
|
break;
|
|
|
|
|
case WM_MOUSEMOVE:
|
2002-02-04 19:41:32 +01:00
|
|
|
|
if (data->curcfg.quick_edit)
|
|
|
|
|
{
|
|
|
|
|
if (GetCapture() == PRIVATE(data)->hWnd && PRIVATE(data)->has_selection &&
|
|
|
|
|
(wParam & MK_LBUTTON))
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, PRIVATE(data)->selectPt1, WCUSER_GetCell(data, lParam), FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, MOUSE_MOVED);
|
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
|
break;
|
|
|
|
|
case WM_LBUTTONUP:
|
2002-02-04 19:41:32 +01:00
|
|
|
|
if (data->curcfg.quick_edit)
|
|
|
|
|
{
|
|
|
|
|
if (GetCapture() == PRIVATE(data)->hWnd && PRIVATE(data)->has_selection &&
|
|
|
|
|
(wParam& MK_LBUTTON))
|
|
|
|
|
{
|
|
|
|
|
WCUSER_MoveSelection(data, PRIVATE(data)->selectPt1, WCUSER_GetCell(data, lParam), TRUE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
RECT r;
|
|
|
|
|
|
|
|
|
|
GetWindowRect(hWnd, &r);
|
|
|
|
|
WCUSER_SetMenuDetails(data, PRIVATE(data)->hPopMenu);
|
|
|
|
|
TrackPopupMenu(PRIVATE(data)->hPopMenu, TPM_LEFTALIGN|TPM_TOPALIGN,
|
|
|
|
|
r.left + LOWORD(lParam), r.top + HIWORD(lParam), 0, hWnd, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
|
/* no need to track for rbutton up when opening the popup... the event will be
|
|
|
|
|
* swallowed by TrackPopupMenu */
|
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0);
|
|
|
|
|
break;
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
|
/* FIXME: should we scroll too ? */
|
|
|
|
|
WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, MOUSE_WHEELED);
|
|
|
|
|
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
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
CreateCaret(PRIVATE(data)->hWnd, PRIVATE(data)->cursor_bitmap,
|
|
|
|
|
data->curcfg.cell_width, data->curcfg.cell_height);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
WCUSER_PosCursor(data);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_KILLFOCUS:
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (data->curcfg.cursor_visible)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
DestroyCaret();
|
|
|
|
|
break;
|
|
|
|
|
case WM_HSCROLL:
|
|
|
|
|
{
|
2002-02-04 19:41:32 +01:00
|
|
|
|
int pos = data->curcfg.win_pos.X;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
2002-02-04 19:41:32 +01:00
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
2001-11-24 00:04:58 +01:00
|
|
|
|
case SB_PAGEUP: pos -= 8; break;
|
|
|
|
|
case SB_PAGEDOWN: pos += 8; break;
|
|
|
|
|
case SB_LINEUP: pos--; break;
|
2002-02-04 19:41:32 +01:00
|
|
|
|
case SB_LINEDOWN: pos++; break;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
case SB_THUMBTRACK: pos = HIWORD(wParam); break;
|
|
|
|
|
default: break;
|
2002-02-04 19:41:32 +01:00
|
|
|
|
}
|
|
|
|
|
if (pos < 0) pos = 0;
|
|
|
|
|
if (pos > data->curcfg.sb_width - data->curcfg.win_width)
|
2001-12-04 21:46:54 +01:00
|
|
|
|
pos = data->curcfg.sb_width - data->curcfg.win_width;
|
2002-02-04 19:41:32 +01:00
|
|
|
|
if (pos != data->curcfg.win_pos.X)
|
|
|
|
|
{
|
|
|
|
|
ScrollWindow(hWnd, (data->curcfg.win_pos.X - pos) * data->curcfg.cell_width, 0,
|
2001-12-04 21:46:54 +01:00
|
|
|
|
NULL, NULL);
|
2002-02-04 19:41:32 +01:00
|
|
|
|
data->curcfg.win_pos.X = pos;
|
|
|
|
|
SetScrollPos(hWnd, SB_HORZ, pos, TRUE);
|
|
|
|
|
UpdateWindow(hWnd);
|
|
|
|
|
WCUSER_PosCursor(data);
|
|
|
|
|
WINECON_NotifyWindowChange(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-11-24 00:04:58 +01:00
|
|
|
|
break;
|
|
|
|
|
case WM_VSCROLL:
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
int pos = data->curcfg.win_pos.Y;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
|
|
|
|
case SB_PAGEUP: pos -= 8; break;
|
|
|
|
|
case SB_PAGEDOWN: pos += 8; break;
|
|
|
|
|
case SB_LINEUP: pos--; break;
|
|
|
|
|
case SB_LINEDOWN: pos++; break;
|
|
|
|
|
case SB_THUMBTRACK: pos = HIWORD(wParam); break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
if (pos < 0) pos = 0;
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (pos > data->curcfg.sb_height - data->curcfg.win_height)
|
|
|
|
|
pos = data->curcfg.sb_height - data->curcfg.win_height;
|
|
|
|
|
if (pos != data->curcfg.win_pos.Y)
|
2001-11-24 00:04:58 +01:00
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
ScrollWindow(hWnd, 0, (data->curcfg.win_pos.Y - pos) * data->curcfg.cell_height,
|
|
|
|
|
NULL, NULL);
|
|
|
|
|
data->curcfg.win_pos.Y = pos;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
SetScrollPos(hWnd, SB_VERT, pos, TRUE);
|
|
|
|
|
UpdateWindow(hWnd);
|
|
|
|
|
WCUSER_PosCursor(data);
|
|
|
|
|
WINECON_NotifyWindowChange(data);
|
|
|
|
|
}
|
2002-02-04 19:41:32 +01:00
|
|
|
|
|
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;
|
|
|
|
|
case IDS_PROPERTY:
|
2001-12-04 21:46:54 +01:00
|
|
|
|
WCUSER_GetProperties(data, TRUE);
|
2001-11-24 00:04:58 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (wParam)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
case IDS_DEFAULT:
|
|
|
|
|
WCUSER_GetProperties(data, FALSE);
|
|
|
|
|
break;
|
|
|
|
|
case IDS_PROPERTY:
|
|
|
|
|
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:
|
|
|
|
|
Trace(0, "unhandled yet command: %x\n", wParam);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_INITMENUPOPUP:
|
|
|
|
|
if (!HIWORD(lParam)) return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
2002-02-04 19:41:32 +01:00
|
|
|
|
WCUSER_SetMenuDetails(data, GetSystemMenu(PRIVATE(data)->hWnd, FALSE));
|
2001-11-24 00:04:58 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_DeleteBackend
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void WCUSER_DeleteBackend(struct inner_data* data)
|
|
|
|
|
{
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!PRIVATE(data)) return;
|
|
|
|
|
if (PRIVATE(data)->hWnd) DestroyWindow(PRIVATE(data)->hWnd);
|
|
|
|
|
if (PRIVATE(data)->hFont) DeleteObject(PRIVATE(data)->hFont);
|
|
|
|
|
if (PRIVATE(data)->cursor_bitmap) DeleteObject(PRIVATE(data)->cursor_bitmap);
|
|
|
|
|
if (PRIVATE(data)->hMemDC) DeleteDC(PRIVATE(data)->hMemDC);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
switch (MsgWaitForMultipleObjects(1, &data->hSynchro, FALSE, INFINITE, QS_ALLINPUT))
|
|
|
|
|
{
|
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
|
if (!WINECON_GrabChanges(data))
|
|
|
|
|
PostQuitMessage(0);
|
|
|
|
|
break;
|
|
|
|
|
case WAIT_OBJECT_0+1:
|
|
|
|
|
switch (GetMessage(&msg, 0, 0, 0))
|
|
|
|
|
{
|
|
|
|
|
case -1: /* the event handle became invalid, so exit */
|
|
|
|
|
return -1;
|
|
|
|
|
case 0: /* WM_QUIT has been posted */
|
|
|
|
|
return 0;
|
|
|
|
|
default:
|
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Trace(0, "got pb\n");
|
|
|
|
|
/* err */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
|
* WCUSER_InitBackend
|
|
|
|
|
*
|
|
|
|
|
* Initialisation part II: creation of window.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
BOOL WCUSER_InitBackend(struct inner_data* data)
|
|
|
|
|
{
|
|
|
|
|
static WCHAR wClassName[] = {'W','i','n','e','C','o','n','s','o','l','e','C','l','a','s','s',0};
|
|
|
|
|
|
|
|
|
|
WNDCLASS wndclass;
|
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));
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!data->private) return FALSE;
|
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;
|
|
|
|
|
data->fnScroll = WCUSER_Scroll;
|
|
|
|
|
data->fnDeleteBackend = WCUSER_DeleteBackend;
|
|
|
|
|
|
|
|
|
|
wndclass.style = 0;
|
|
|
|
|
wndclass.lpfnWndProc = WCUSER_Proc;
|
|
|
|
|
wndclass.cbClsExtra = 0;
|
|
|
|
|
wndclass.cbWndExtra = sizeof(DWORD);
|
|
|
|
|
wndclass.hInstance = GetModuleHandle(NULL);
|
|
|
|
|
wndclass.hIcon = LoadIcon(0, IDI_WINLOGO);
|
|
|
|
|
wndclass.hCursor = LoadCursor(0, IDC_ARROW);
|
|
|
|
|
wndclass.hbrBackground = GetStockObject(BLACK_BRUSH);
|
|
|
|
|
wndclass.lpszMenuName = NULL;
|
|
|
|
|
wndclass.lpszClassName = wClassName;
|
|
|
|
|
|
|
|
|
|
RegisterClass(&wndclass);
|
|
|
|
|
|
|
|
|
|
CreateWindow(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);
|
2001-12-04 21:46:54 +01:00
|
|
|
|
if (!PRIVATE(data)->hWnd) return FALSE;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
|
|
|
|
/* force update of current data */
|
2002-02-04 19:41:32 +01:00
|
|
|
|
if (!WINECON_GrabChanges(data)) return FALSE;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
|
2002-03-23 21:14:04 +01:00
|
|
|
|
if (!WCUSER_InitFont(data)) return FALSE;
|
|
|
|
|
|
2001-12-04 21:46:54 +01:00
|
|
|
|
return TRUE;
|
2001-11-24 00:04:58 +01:00
|
|
|
|
}
|
|
|
|
|
|