Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * a GUI application for displaying a console |
| 3 | * USER32 back end |
| 4 | * Copyright 2001 Eric Pouech |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <stdio.h> |
James Juran | 424a080 | 2002-01-01 00:14:02 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 23 | #include "winecon_user.h" |
Mikołaj Zalewski | 2fb8ea4 | 2006-10-03 21:08:32 +0200 | [diff] [blame] | 24 | #include "winnls.h" |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 25 | |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 26 | #include "wine/debug.h" |
| 27 | |
| 28 | WINE_DEFAULT_DEBUG_CHANNEL(wineconsole); |
| 29 | WINE_DECLARE_DEBUG_CHANNEL(wc_font); |
| 30 | |
Mikołaj Zalewski | 2fb8ea4 | 2006-10-03 21:08:32 +0200 | [diff] [blame] | 31 | UINT g_uiDefaultCharset; |
| 32 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 33 | /* mapping console colors to RGB values */ |
Dmitry Timoshkov | 9e357cd | 2007-01-10 15:27:24 +0800 | [diff] [blame] | 34 | const COLORREF WCUSER_ColorMap[16] = |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 35 | { |
| 36 | RGB(0x00, 0x00, 0x00), RGB(0x00, 0x00, 0x80), RGB(0x00, 0x80, 0x00), RGB(0x00, 0x80, 0x80), |
| 37 | RGB(0x80, 0x00, 0x00), RGB(0x80, 0x00, 0x80), RGB(0x80, 0x80, 0x00), RGB(0x80, 0x80, 0x80), |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 38 | RGB(0xC0, 0xC0, 0xC0), RGB(0x00, 0x00, 0xFF), RGB(0x00, 0xFF, 0x00), RGB(0x00, 0xFF, 0xFF), |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 39 | RGB(0xFF, 0x00, 0x00), RGB(0xFF, 0x00, 0xFF), RGB(0xFF, 0xFF, 0x00), RGB(0xFF, 0xFF, 0xFF), |
| 40 | }; |
| 41 | |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 42 | static BOOL WCUSER_SetFont(struct inner_data* data, const LOGFONT* font); |
| 43 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 44 | /****************************************************************** |
| 45 | * WCUSER_FillMemDC |
| 46 | * |
| 47 | * Fills the Mem DC with current cells values |
| 48 | */ |
| 49 | static void WCUSER_FillMemDC(const struct inner_data* data, int upd_tp, int upd_bm) |
| 50 | { |
| 51 | unsigned i, j, k; |
| 52 | CHAR_INFO* cell; |
| 53 | HFONT hOldFont; |
| 54 | WORD attr; |
| 55 | WCHAR* line; |
Eric Pouech | 8ad685c | 2005-11-03 09:51:00 +0000 | [diff] [blame] | 56 | RECT r; |
| 57 | HBRUSH hbr; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 58 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 59 | /* no font has been set up yet, don't worry about filling the bitmap, |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 60 | * we'll do it once a font is chosen |
| 61 | */ |
| 62 | if (!PRIVATE(data)->hFont) return; |
| 63 | |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 64 | /* FIXME: could set up a mechanism to reuse the line between different |
| 65 | * calls to this function |
| 66 | */ |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 67 | if (!(line = HeapAlloc(GetProcessHeap(), 0, data->curcfg.sb_width * sizeof(WCHAR)))) |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 68 | WINECON_Fatal("OOM\n"); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 69 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 70 | hOldFont = SelectObject(PRIVATE(data)->hMemDC, PRIVATE(data)->hFont); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 71 | for (j = upd_tp; j <= upd_bm; j++) |
| 72 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 73 | cell = &data->cells[j * data->curcfg.sb_width]; |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 74 | for (i = 0; i < data->curcfg.sb_width; i++) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 75 | { |
| 76 | attr = cell[i].Attributes; |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 77 | SetBkColor(PRIVATE(data)->hMemDC, WCUSER_ColorMap[(attr>>4)&0x0F]); |
Marcus Meissner | 09534f3 | 2001-12-31 22:20:56 +0000 | [diff] [blame] | 78 | SetTextColor(PRIVATE(data)->hMemDC, WCUSER_ColorMap[attr&0x0F]); |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 79 | for (k = i; k < data->curcfg.sb_width && cell[k].Attributes == attr; k++) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 80 | { |
| 81 | line[k - i] = cell[k].Char.UnicodeChar; |
| 82 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 83 | TextOut(PRIVATE(data)->hMemDC, i * data->curcfg.cell_width, j * data->curcfg.cell_height, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 84 | line, k - i); |
Eric Pouech | 8ad685c | 2005-11-03 09:51:00 +0000 | [diff] [blame] | 85 | if (PRIVATE(data)->ext_leading && |
| 86 | (hbr = CreateSolidBrush(WCUSER_ColorMap[(attr>>4)&0x0F]))) |
| 87 | { |
| 88 | r.left = i * data->curcfg.cell_width; |
| 89 | r.top = (j + 1) * data->curcfg.cell_height - PRIVATE(data)->ext_leading; |
| 90 | r.right = k * data->curcfg.cell_width; |
| 91 | r.bottom = (j + 1) * data->curcfg.cell_height; |
| 92 | FillRect(PRIVATE(data)->hMemDC, &r, hbr); |
| 93 | DeleteObject(hbr); |
| 94 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 95 | i = k - 1; |
| 96 | } |
| 97 | } |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 98 | SelectObject(PRIVATE(data)->hMemDC, hOldFont); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 99 | HeapFree(GetProcessHeap(), 0, line); |
| 100 | } |
| 101 | |
| 102 | /****************************************************************** |
| 103 | * WCUSER_NewBitmap |
| 104 | * |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 105 | * Either the font geometry or the sb geometry has changed. we need |
| 106 | * to recreate the bitmap geometry. |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 107 | */ |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 108 | static void WCUSER_NewBitmap(struct inner_data* data) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 109 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 110 | HDC hDC; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 111 | HBITMAP hnew, hold; |
| 112 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 113 | if (!data->curcfg.sb_width || !data->curcfg.sb_height || |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 114 | !PRIVATE(data)->hFont || !(hDC = GetDC(data->hWnd))) |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 115 | return; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 116 | hnew = CreateCompatibleBitmap(hDC, |
| 117 | data->curcfg.sb_width * data->curcfg.cell_width, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 118 | data->curcfg.sb_height * data->curcfg.cell_height); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 119 | ReleaseDC(data->hWnd, hDC); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 120 | hold = SelectObject(PRIVATE(data)->hMemDC, hnew); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 121 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 122 | if (PRIVATE(data)->hBitmap) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 123 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 124 | if (hold == PRIVATE(data)->hBitmap) |
| 125 | DeleteObject(PRIVATE(data)->hBitmap); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 126 | else |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 127 | WINE_FIXME("leak\n"); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 128 | } |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 129 | PRIVATE(data)->hBitmap = hnew; |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 130 | WCUSER_FillMemDC(data, 0, data->curcfg.sb_height - 1); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /****************************************************************** |
| 134 | * WCUSER_ResizeScreenBuffer |
| 135 | * |
| 136 | * |
| 137 | */ |
| 138 | static void WCUSER_ResizeScreenBuffer(struct inner_data* data) |
| 139 | { |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 140 | WCUSER_NewBitmap(data); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /****************************************************************** |
| 144 | * WCUSER_PosCursor |
| 145 | * |
| 146 | * Set a new position for the cursor |
| 147 | */ |
| 148 | static void WCUSER_PosCursor(const struct inner_data* data) |
| 149 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 150 | if (data->hWnd != GetFocus() || !data->curcfg.cursor_visible) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 151 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 152 | SetCaretPos((data->cursor.X - data->curcfg.win_pos.X) * data->curcfg.cell_width, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 153 | (data->cursor.Y - data->curcfg.win_pos.Y) * data->curcfg.cell_height); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 154 | ShowCaret(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /****************************************************************** |
| 158 | * WCUSER_ShapeCursor |
| 159 | * |
| 160 | * Sets a new shape for the cursor |
| 161 | */ |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 162 | static void WCUSER_ShapeCursor(struct inner_data* data, int size, int vis, BOOL force) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 163 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 164 | if (force || size != data->curcfg.cursor_size) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 165 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 166 | if (data->curcfg.cursor_visible && data->hWnd == GetFocus()) DestroyCaret(); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 167 | if (PRIVATE(data)->cursor_bitmap) DeleteObject(PRIVATE(data)->cursor_bitmap); |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 168 | PRIVATE(data)->cursor_bitmap = NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 169 | if (size != 100) |
| 170 | { |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 171 | int w16b; /* number of bytes per row, aligned on word size */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 172 | BYTE* ptr; |
| 173 | int i, j, nbl; |
| 174 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 175 | w16b = ((data->curcfg.cell_width + 15) & ~15) / 8; |
| 176 | ptr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, w16b * data->curcfg.cell_height); |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 177 | if (!ptr) WINECON_Fatal("OOM"); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 178 | nbl = max((data->curcfg.cell_height * size) / 100, 1); |
| 179 | for (j = data->curcfg.cell_height - nbl; j < data->curcfg.cell_height; j++) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 180 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 181 | for (i = 0; i < data->curcfg.cell_width; i++) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 182 | { |
| 183 | ptr[w16b * j + (i / 8)] |= 0x80 >> (i & 7); |
| 184 | } |
| 185 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 186 | PRIVATE(data)->cursor_bitmap = CreateBitmap(data->curcfg.cell_width, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 187 | data->curcfg.cell_height, 1, 1, ptr); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 188 | HeapFree(GetProcessHeap(), 0, ptr); |
| 189 | } |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 190 | data->curcfg.cursor_size = size; |
| 191 | data->curcfg.cursor_visible = -1; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | vis = (vis) ? TRUE : FALSE; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 195 | if (force || vis != data->curcfg.cursor_visible) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 196 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 197 | data->curcfg.cursor_visible = vis; |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 198 | if (data->hWnd == GetFocus()) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 199 | { |
| 200 | if (vis) |
| 201 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 202 | CreateCaret(data->hWnd, PRIVATE(data)->cursor_bitmap, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 203 | data->curcfg.cell_width, data->curcfg.cell_height); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 204 | WCUSER_PosCursor(data); |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | DestroyCaret(); |
| 209 | } |
| 210 | } |
| 211 | } |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 212 | WINECON_DumpConfig("crsr", &data->curcfg); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /****************************************************************** |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 216 | * WCUSER_ComputePositions |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 217 | * |
| 218 | * Recomputes all the components (mainly scroll bars) positions |
| 219 | */ |
Eric Pouech | 5c2a891 | 2004-11-29 18:00:10 +0000 | [diff] [blame] | 220 | static void WCUSER_ComputePositions(struct inner_data* data) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 221 | { |
| 222 | RECT r; |
| 223 | int dx, dy; |
| 224 | |
| 225 | /* compute window size from desired client size */ |
| 226 | r.left = r.top = 0; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 227 | r.right = data->curcfg.win_width * data->curcfg.cell_width; |
| 228 | r.bottom = data->curcfg.win_height * data->curcfg.cell_height; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 229 | |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 230 | if (IsRectEmpty(&r)) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 231 | |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 232 | AdjustWindowRect(&r, GetWindowLong(data->hWnd, GWL_STYLE), FALSE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 233 | |
| 234 | dx = dy = 0; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 235 | if (data->curcfg.sb_width > data->curcfg.win_width) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 236 | { |
| 237 | dy = GetSystemMetrics(SM_CYHSCROLL); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 238 | SetScrollRange(data->hWnd, SB_HORZ, 0, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 239 | data->curcfg.sb_width - data->curcfg.win_width, FALSE); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 240 | SetScrollPos(data->hWnd, SB_HORZ, 0, FALSE); /* FIXME */ |
| 241 | ShowScrollBar(data->hWnd, SB_HORZ, TRUE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 242 | } |
| 243 | else |
| 244 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 245 | ShowScrollBar(data->hWnd, SB_HORZ, FALSE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 248 | if (data->curcfg.sb_height > data->curcfg.win_height) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 249 | { |
| 250 | dx = GetSystemMetrics(SM_CXVSCROLL); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 251 | SetScrollRange(data->hWnd, SB_VERT, 0, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 252 | data->curcfg.sb_height - data->curcfg.win_height, FALSE); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 253 | SetScrollPos(data->hWnd, SB_VERT, 0, FALSE); /* FIXME */ |
| 254 | ShowScrollBar(data->hWnd, SB_VERT, TRUE); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 255 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 256 | else |
| 257 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 258 | ShowScrollBar(data->hWnd, SB_VERT, FALSE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 261 | SetWindowPos(data->hWnd, 0, 0, 0, r.right - r.left + dx, r.bottom - r.top + dy, |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 262 | SWP_NOMOVE|SWP_NOZORDER); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 263 | WCUSER_ShapeCursor(data, data->curcfg.cursor_size, data->curcfg.cursor_visible, TRUE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 264 | WCUSER_PosCursor(data); |
| 265 | } |
| 266 | |
| 267 | /****************************************************************** |
| 268 | * WCUSER_SetTitle |
| 269 | * |
| 270 | * Sets the title to the wine console |
| 271 | */ |
| 272 | static void WCUSER_SetTitle(const struct inner_data* data) |
| 273 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 274 | WCHAR buffer[256]; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 275 | |
| 276 | if (WINECON_GetConsoleTitle(data->hConIn, buffer, sizeof(buffer))) |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 277 | SetWindowText(data->hWnd, buffer); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 280 | void WCUSER_DumpLogFont(const char* pfx, const LOGFONT* lf, DWORD ft) |
| 281 | { |
| 282 | WINE_TRACE_(wc_font)("%s %s%s%s%s\n" |
Michael Stefaniuc | ae48a51 | 2006-10-02 23:22:34 +0200 | [diff] [blame] | 283 | "\tlf.lfHeight=%d lf.lfWidth=%d lf.lfEscapement=%d lf.lfOrientation=%d\n" |
| 284 | "\tlf.lfWeight=%d lf.lfItalic=%u lf.lfUnderline=%u lf.lfStrikeOut=%u\n" |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 285 | "\tlf.lfCharSet=%u lf.lfOutPrecision=%u lf.lfClipPrecision=%u lf.lfQuality=%u\n" |
| 286 | "\tlf->lfPitchAndFamily=%u lf.lfFaceName=%s\n", |
| 287 | pfx, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 288 | (ft & RASTER_FONTTYPE) ? "raster" : "", |
| 289 | (ft & TRUETYPE_FONTTYPE) ? "truetype" : "", |
| 290 | ((ft & (RASTER_FONTTYPE|TRUETYPE_FONTTYPE)) == 0) ? "vector" : "", |
| 291 | (ft & DEVICE_FONTTYPE) ? "|device" : "", |
| 292 | lf->lfHeight, lf->lfWidth, lf->lfEscapement, lf->lfOrientation, |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 293 | lf->lfWeight, lf->lfItalic, lf->lfUnderline, lf->lfStrikeOut, lf->lfCharSet, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 294 | lf->lfOutPrecision, lf->lfClipPrecision, lf->lfQuality, lf->lfPitchAndFamily, |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 295 | wine_dbgstr_w(lf->lfFaceName)); |
| 296 | } |
| 297 | |
| 298 | void WCUSER_DumpTextMetric(const TEXTMETRIC* tm, DWORD ft) |
| 299 | { |
| 300 | WINE_TRACE_(wc_font)("%s%s%s%s\n" |
Michael Stefaniuc | ae48a51 | 2006-10-02 23:22:34 +0200 | [diff] [blame] | 301 | "\ttmHeight=%d tmAscent=%d tmDescent=%d tmInternalLeading=%d tmExternalLeading=%d\n" |
| 302 | "\ttmAveCharWidth=%d tmMaxCharWidth=%d tmWeight=%d tmOverhang=%d\n" |
| 303 | "\ttmDigitizedAspectX=%d tmDigitizedAspectY=%d\n" |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 304 | "\ttmFirstChar=%d tmLastChar=%d tmDefaultChar=%d tmBreakChar=%d\n" |
| 305 | "\ttmItalic=%u tmUnderlined=%u tmStruckOut=%u tmPitchAndFamily=%u tmCharSet=%u\n", |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 306 | (ft & RASTER_FONTTYPE) ? "raster" : "", |
| 307 | (ft & TRUETYPE_FONTTYPE) ? "truetype" : "", |
| 308 | ((ft & (RASTER_FONTTYPE|TRUETYPE_FONTTYPE)) == 0) ? "vector" : "", |
| 309 | (ft & DEVICE_FONTTYPE) ? "|device" : "", |
| 310 | tm->tmHeight, tm->tmAscent, tm->tmDescent, tm->tmInternalLeading, tm->tmExternalLeading, tm->tmAveCharWidth, |
| 311 | tm->tmMaxCharWidth, tm->tmWeight, tm->tmOverhang, tm->tmDigitizedAspectX, tm->tmDigitizedAspectY, |
| 312 | tm->tmFirstChar, tm->tmLastChar, tm->tmDefaultChar, tm->tmBreakChar, tm->tmItalic, tm->tmUnderlined, tm->tmStruckOut, |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 313 | tm->tmPitchAndFamily, tm->tmCharSet); |
| 314 | } |
| 315 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 316 | /****************************************************************** |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 317 | * WCUSER_AreFontsEqual |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 318 | * |
| 319 | * |
| 320 | */ |
| 321 | BOOL WCUSER_AreFontsEqual(const struct config_data* config, const LOGFONT* lf) |
| 322 | { |
| 323 | return lf->lfHeight == config->cell_height && |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 324 | lf->lfWeight == config->font_weight && |
| 325 | !lf->lfItalic && !lf->lfUnderline && !lf->lfStrikeOut && |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 326 | !lstrcmp(lf->lfFaceName, config->face_name); |
| 327 | } |
| 328 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 329 | struct font_chooser |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 330 | { |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 331 | struct inner_data* data; |
| 332 | int done; |
| 333 | }; |
| 334 | |
| 335 | /****************************************************************** |
| 336 | * WCUSER_ValidateFontMetric |
| 337 | * |
| 338 | * Returns true if the font described in tm is usable as a font for the renderer |
| 339 | */ |
| 340 | BOOL WCUSER_ValidateFontMetric(const struct inner_data* data, const TEXTMETRIC* tm, DWORD fontType) |
| 341 | { |
| 342 | BOOL ret = TRUE; |
| 343 | |
| 344 | if (fontType & RASTER_FONTTYPE) |
| 345 | ret = (tm->tmMaxCharWidth * data->curcfg.win_width < GetSystemMetrics(SM_CXSCREEN) && |
| 346 | tm->tmHeight * data->curcfg.win_height < GetSystemMetrics(SM_CYSCREEN)); |
| 347 | return ret && !tm->tmItalic && !tm->tmUnderlined && !tm->tmStruckOut && |
Mikołaj Zalewski | 2fb8ea4 | 2006-10-03 21:08:32 +0200 | [diff] [blame] | 348 | (tm->tmCharSet == DEFAULT_CHARSET || tm->tmCharSet == g_uiDefaultCharset); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /****************************************************************** |
| 352 | * WCUSER_ValidateFont |
| 353 | * |
| 354 | * Returns true if the font family described in lf is usable as a font for the renderer |
| 355 | */ |
| 356 | BOOL WCUSER_ValidateFont(const struct inner_data* data, const LOGFONT* lf) |
| 357 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 358 | return (lf->lfPitchAndFamily & 3) == FIXED_PITCH && |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 359 | /* (lf->lfPitchAndFamily & 0xF0) == FF_MODERN && */ |
Mikołaj Zalewski | 2fb8ea4 | 2006-10-03 21:08:32 +0200 | [diff] [blame] | 360 | (lf->lfCharSet == DEFAULT_CHARSET || lf->lfCharSet == g_uiDefaultCharset); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /****************************************************************** |
| 364 | * get_first_font_enum_2 |
| 365 | * get_first_font_enum |
| 366 | * |
| 367 | * Helper functions to get a decent font for the renderer |
| 368 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 369 | static int CALLBACK get_first_font_enum_2(const LOGFONT* lf, const TEXTMETRIC* tm, |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 370 | DWORD FontType, LPARAM lParam) |
| 371 | { |
| 372 | struct font_chooser* fc = (struct font_chooser*)lParam; |
| 373 | |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 374 | WCUSER_DumpTextMetric(tm, FontType); |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 375 | if (WCUSER_ValidateFontMetric(fc->data, tm, FontType)) |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 376 | { |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 377 | LOGFONT mlf = *lf; |
| 378 | |
| 379 | /* Use the default sizes for the font (this is needed, especially for |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 380 | * TrueType fonts, so that we get a decent size, not the max size) |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 381 | */ |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 382 | mlf.lfWidth = fc->data->curcfg.cell_width; |
| 383 | mlf.lfHeight = fc->data->curcfg.cell_height; |
| 384 | if (WCUSER_SetFont(fc->data, &mlf)) |
| 385 | { |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 386 | struct config_data defcfg; |
| 387 | |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 388 | WCUSER_DumpLogFont("InitChoosing: ", &mlf, FontType); |
| 389 | fc->done = 1; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 390 | /* since we've modified the current config with new font information, |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 391 | * set this information as the new default. |
| 392 | */ |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 393 | WINECON_RegLoad(NULL, &defcfg); |
| 394 | defcfg.cell_width = fc->data->curcfg.cell_width; |
| 395 | defcfg.cell_height = fc->data->curcfg.cell_height; |
| 396 | lstrcpyW(defcfg.face_name, fc->data->curcfg.face_name); |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 397 | /* Force also its writing back to the registry so that we can get it |
| 398 | * the next time. |
| 399 | */ |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 400 | WINECON_RegSave(&defcfg); |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 401 | return 0; |
| 402 | } |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 403 | } |
| 404 | return 1; |
| 405 | } |
| 406 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 407 | static int CALLBACK get_first_font_enum(const LOGFONT* lf, const TEXTMETRIC* tm, |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 408 | DWORD FontType, LPARAM lParam) |
| 409 | { |
| 410 | struct font_chooser* fc = (struct font_chooser*)lParam; |
| 411 | |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 412 | WCUSER_DumpLogFont("InitFamily: ", lf, FontType); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 413 | if (WCUSER_ValidateFont(fc->data, lf)) |
| 414 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 415 | EnumFontFamilies(PRIVATE(fc->data)->hMemDC, lf->lfFaceName, |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 416 | get_first_font_enum_2, lParam); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 417 | return !fc->done; /* we just need the first matching one... */ |
| 418 | } |
| 419 | return 1; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /****************************************************************** |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 423 | * WCUSER_CopyFont |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 424 | * |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 425 | * get the relevant information from the font described in lf and store them |
| 426 | * in config |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 427 | */ |
Eric Pouech | 8ad685c | 2005-11-03 09:51:00 +0000 | [diff] [blame] | 428 | HFONT WCUSER_CopyFont(struct config_data* config, HWND hWnd, const LOGFONT* lf, LONG* el) |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 429 | { |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 430 | TEXTMETRIC tm; |
| 431 | HDC hDC; |
| 432 | HFONT hFont, hOldFont; |
| 433 | int w, i, buf[256]; |
| 434 | |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 435 | if (!(hDC = GetDC(hWnd))) return NULL; |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 436 | if (!(hFont = CreateFontIndirect(lf))) goto err1; |
| 437 | |
| 438 | hOldFont = SelectObject(hDC, hFont); |
| 439 | GetTextMetrics(hDC, &tm); |
| 440 | |
| 441 | /* FIXME: |
| 442 | * the current freetype engine (at least 2.0.x with x <= 8) and its implementation |
| 443 | * in Wine don't return adequate values for fixed fonts |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 444 | * In Windows, those fonts are expected to return the same value for |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 445 | * - the average width |
| 446 | * - the largest width |
| 447 | * - the width of all characters in the font |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 448 | * This isn't true in Wine. As a temporary workaround, we get as the width of the |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 449 | * cell, the width of the first character in the font, after checking that all |
| 450 | * characters in the font have the same width (I hear paranoïa coming) |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 451 | * when this gets fixed, the code should be using tm.tmAveCharWidth |
| 452 | * or tm.tmMaxCharWidth as the cell width. |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 453 | */ |
| 454 | GetCharWidth32(hDC, tm.tmFirstChar, tm.tmFirstChar, &w); |
| 455 | for (i = tm.tmFirstChar + 1; i <= tm.tmLastChar; i += sizeof(buf) / sizeof(buf[0])) |
| 456 | { |
Richard Cohen | 6cbc861 | 2004-09-22 19:12:38 +0000 | [diff] [blame] | 457 | int j, k; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 458 | |
Richard Cohen | 6cbc861 | 2004-09-22 19:12:38 +0000 | [diff] [blame] | 459 | k = min(tm.tmLastChar - i, sizeof(buf) / sizeof(buf[0]) - 1); |
| 460 | GetCharWidth32(hDC, i, i + k, buf); |
| 461 | for (j = 0; j <= k; j++) |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 462 | { |
| 463 | if (buf[j] != w) |
| 464 | { |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 465 | WINE_WARN("Non uniform cell width: [%d]=%d [%d]=%d\n" |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 466 | "This may be caused by old freetype libraries, >= 2.0.8 is recommended\n", |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 467 | i + j, buf[j], tm.tmFirstChar, w); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 468 | goto err; |
| 469 | } |
| 470 | } |
| 471 | } |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 472 | SelectObject(hDC, hOldFont); |
| 473 | ReleaseDC(hWnd, hDC); |
| 474 | |
| 475 | config->cell_width = w; |
Eric Pouech | 5e765fb | 2002-06-02 21:20:43 +0000 | [diff] [blame] | 476 | config->cell_height = tm.tmHeight + tm.tmExternalLeading; |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 477 | config->font_weight = tm.tmWeight; |
| 478 | lstrcpy(config->face_name, lf->lfFaceName); |
Eric Pouech | 8ad685c | 2005-11-03 09:51:00 +0000 | [diff] [blame] | 479 | if (el) *el = tm.tmExternalLeading; |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 480 | |
| 481 | return hFont; |
| 482 | err: |
| 483 | if (hDC && hOldFont) SelectObject(hDC, hOldFont); |
| 484 | if (hFont) DeleteObject(hFont); |
| 485 | err1: |
| 486 | if (hDC) ReleaseDC(hWnd, hDC); |
| 487 | |
Francois Gouget | d2667a4 | 2002-12-02 18:10:57 +0000 | [diff] [blame] | 488 | return NULL; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /****************************************************************** |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 492 | * WCUSER_FillLogFont |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 493 | * |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 494 | * |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 495 | */ |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 496 | void WCUSER_FillLogFont(LOGFONT* lf, const WCHAR* name, UINT height, UINT weight) |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 497 | { |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 498 | lf->lfHeight = height; |
| 499 | lf->lfWidth = 0; |
| 500 | lf->lfEscapement = 0; |
| 501 | lf->lfOrientation = 0; |
| 502 | lf->lfWeight = weight; |
| 503 | lf->lfItalic = FALSE; |
| 504 | lf->lfUnderline = FALSE; |
| 505 | lf->lfStrikeOut = FALSE; |
| 506 | lf->lfCharSet = DEFAULT_CHARSET; |
| 507 | lf->lfOutPrecision = OUT_DEFAULT_PRECIS; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 508 | lf->lfClipPrecision = CLIP_DEFAULT_PRECIS; |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 509 | lf->lfQuality = DEFAULT_QUALITY; |
| 510 | lf->lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; |
| 511 | lstrcpy(lf->lfFaceName, name); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /****************************************************************** |
| 515 | * WCUSER_SetFont |
| 516 | * |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 517 | * sets logfont as the new font for the console |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 518 | */ |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 519 | BOOL WCUSER_SetFont(struct inner_data* data, const LOGFONT* logfont) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 520 | { |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 521 | HFONT hFont; |
Eric Pouech | 8ad685c | 2005-11-03 09:51:00 +0000 | [diff] [blame] | 522 | LONG el; |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 523 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 524 | if (PRIVATE(data)->hFont != 0 && WCUSER_AreFontsEqual(&data->curcfg, logfont)) |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 525 | return TRUE; |
| 526 | |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 527 | hFont = WCUSER_CopyFont(&data->curcfg, data->hWnd, logfont, &el); |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 528 | if (!hFont) {WINE_ERR("wrong font\n"); return FALSE;} |
| 529 | |
| 530 | if (PRIVATE(data)->hFont) DeleteObject(PRIVATE(data)->hFont); |
| 531 | PRIVATE(data)->hFont = hFont; |
Eric Pouech | 8ad685c | 2005-11-03 09:51:00 +0000 | [diff] [blame] | 532 | PRIVATE(data)->ext_leading = el; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 533 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 534 | WCUSER_ComputePositions(data); |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 535 | WCUSER_NewBitmap(data); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 536 | InvalidateRect(data->hWnd, NULL, FALSE); |
| 537 | UpdateWindow(data->hWnd); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 538 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 539 | return TRUE; |
| 540 | } |
| 541 | |
| 542 | /****************************************************************** |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 543 | * WCUSER_SetFontPmt |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 544 | * |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 545 | * Sets a new font for the console. |
| 546 | * In fact a wrapper for WCUSER_SetFont |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 547 | */ |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 548 | static void WCUSER_SetFontPmt(struct inner_data* data, const WCHAR* font, |
| 549 | unsigned height, unsigned weight) |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 550 | { |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 551 | LOGFONT lf; |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 552 | struct font_chooser fc; |
| 553 | |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 554 | WINE_TRACE_(wc_font)("=> %s h=%u w=%u\n", |
| 555 | wine_dbgstr_wn(font, -1), height, weight); |
| 556 | |
| 557 | if (font[0] != '\0' && height != 0 && weight != 0) |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 558 | { |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 559 | WCUSER_FillLogFont(&lf, font, height, weight); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 560 | if (WCUSER_SetFont(data, &lf)) |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 561 | { |
| 562 | WCUSER_DumpLogFont("InitReuses: ", &lf, 0); |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 563 | return; |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 564 | } |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 565 | } |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 566 | |
| 567 | /* try to find an acceptable font */ |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 568 | WINE_WARN("Couldn't match the font from registry... trying to find one\n"); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 569 | fc.data = data; |
| 570 | fc.done = 0; |
| 571 | EnumFontFamilies(PRIVATE(data)->hMemDC, NULL, get_first_font_enum, (LPARAM)&fc); |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 572 | if (!fc.done) WINECON_Fatal("Couldn't find a decent font, aborting\n"); |
Eric Pouech | be9268a | 2002-03-23 20:14:04 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | /****************************************************************** |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 576 | * WCUSER_GetCell |
| 577 | * |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 578 | * Get a cell from a relative coordinate in window (takes into |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 579 | * account the scrolling) |
| 580 | */ |
| 581 | static COORD WCUSER_GetCell(const struct inner_data* data, LPARAM lParam) |
| 582 | { |
| 583 | COORD c; |
| 584 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 585 | c.X = data->curcfg.win_pos.X + (short)LOWORD(lParam) / data->curcfg.cell_width; |
| 586 | c.Y = data->curcfg.win_pos.Y + (short)HIWORD(lParam) / data->curcfg.cell_height; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 587 | |
| 588 | return c; |
| 589 | } |
| 590 | |
| 591 | /****************************************************************** |
| 592 | * WCUSER_GetSelectionRect |
| 593 | * |
| 594 | * Get the selection rectangle |
| 595 | */ |
| 596 | static void WCUSER_GetSelectionRect(const struct inner_data* data, LPRECT r) |
| 597 | { |
Eric Pouech | 5e765fb | 2002-06-02 21:20:43 +0000 | [diff] [blame] | 598 | r->left = (min(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X) - data->curcfg.win_pos.X) * data->curcfg.cell_width; |
| 599 | r->top = (min(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y) - data->curcfg.win_pos.Y) * data->curcfg.cell_height; |
| 600 | r->right = (max(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X) + 1 - data->curcfg.win_pos.X) * data->curcfg.cell_width; |
| 601 | r->bottom = (max(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y) + 1 - data->curcfg.win_pos.Y) * data->curcfg.cell_height; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /****************************************************************** |
| 605 | * WCUSER_SetSelection |
| 606 | * |
| 607 | * |
| 608 | */ |
| 609 | static void WCUSER_SetSelection(const struct inner_data* data, HDC hRefDC) |
| 610 | { |
| 611 | HDC hDC; |
| 612 | RECT r; |
| 613 | |
| 614 | WCUSER_GetSelectionRect(data, &r); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 615 | hDC = hRefDC ? hRefDC : GetDC(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 616 | if (hDC) |
| 617 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 618 | if (data->hWnd == GetFocus() && data->curcfg.cursor_visible) |
| 619 | HideCaret(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 620 | InvertRect(hDC, &r); |
| 621 | if (hDC != hRefDC) |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 622 | ReleaseDC(data->hWnd, hDC); |
| 623 | if (data->hWnd == GetFocus() && data->curcfg.cursor_visible) |
| 624 | ShowCaret(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | /****************************************************************** |
| 629 | * WCUSER_MoveSelection |
| 630 | * |
| 631 | * |
| 632 | */ |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 633 | static void WCUSER_MoveSelection(struct inner_data* data, COORD c1, COORD c2) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 634 | { |
| 635 | RECT r; |
| 636 | HDC hDC; |
| 637 | |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 638 | if (c1.X < 0 || c1.X >= data->curcfg.sb_width || |
| 639 | c2.X < 0 || c2.X >= data->curcfg.sb_width || |
| 640 | c1.Y < 0 || c1.Y >= data->curcfg.sb_height || |
| 641 | c2.Y < 0 || c2.Y >= data->curcfg.sb_height) |
| 642 | return; |
| 643 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 644 | WCUSER_GetSelectionRect(data, &r); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 645 | hDC = GetDC(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 646 | if (hDC) |
| 647 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 648 | if (data->hWnd == GetFocus() && data->curcfg.cursor_visible) |
| 649 | HideCaret(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 650 | InvertRect(hDC, &r); |
| 651 | } |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 652 | PRIVATE(data)->selectPt1 = c1; |
| 653 | PRIVATE(data)->selectPt2 = c2; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 654 | if (hDC) |
| 655 | { |
| 656 | WCUSER_GetSelectionRect(data, &r); |
| 657 | InvertRect(hDC, &r); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 658 | ReleaseDC(data->hWnd, hDC); |
| 659 | if (data->hWnd == GetFocus() && data->curcfg.cursor_visible) |
| 660 | ShowCaret(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 661 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | /****************************************************************** |
| 665 | * WCUSER_CopySelectionToClipboard |
| 666 | * |
| 667 | * Copies the current selection into the clipboard |
| 668 | */ |
| 669 | static void WCUSER_CopySelectionToClipboard(const struct inner_data* data) |
| 670 | { |
| 671 | HANDLE hMem; |
| 672 | LPWSTR p; |
| 673 | unsigned w, h; |
| 674 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 675 | w = abs(PRIVATE(data)->selectPt1.X - PRIVATE(data)->selectPt2.X) + 2; |
| 676 | h = abs(PRIVATE(data)->selectPt1.Y - PRIVATE(data)->selectPt2.Y) + 1; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 677 | |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 678 | if (!OpenClipboard(data->hWnd)) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 679 | EmptyClipboard(); |
| 680 | |
Eric Pouech | 5e765fb | 2002-06-02 21:20:43 +0000 | [diff] [blame] | 681 | hMem = GlobalAlloc(GMEM_MOVEABLE, (w * h) * sizeof(WCHAR)); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 682 | if (hMem && (p = GlobalLock(hMem))) |
| 683 | { |
| 684 | COORD c; |
| 685 | int y; |
| 686 | |
Eric Pouech | 5e765fb | 2002-06-02 21:20:43 +0000 | [diff] [blame] | 687 | c.X = min(PRIVATE(data)->selectPt1.X, PRIVATE(data)->selectPt2.X); |
| 688 | c.Y = min(PRIVATE(data)->selectPt1.Y, PRIVATE(data)->selectPt2.Y); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 689 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 690 | for (y = 0; y < h; y++, c.Y++) |
| 691 | { |
Mikołaj Zalewski | c52238d | 2006-10-19 19:25:08 +0200 | [diff] [blame] | 692 | LPWSTR end; |
| 693 | ReadConsoleOutputCharacter(data->hConOut, p, w - 1, c, NULL); |
| 694 | |
| 695 | /* strip spaces from the end of the line */ |
| 696 | end = p + w - 1; |
| 697 | while (end > p && *(end - 1) == ' ') |
| 698 | end--; |
| 699 | *end = (y < h - 1) ? '\n' : '\0'; |
| 700 | p = end + 1; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 701 | } |
| 702 | GlobalUnlock(hMem); |
| 703 | SetClipboardData(CF_UNICODETEXT, hMem); |
| 704 | } |
| 705 | CloseClipboard(); |
| 706 | } |
| 707 | |
| 708 | /****************************************************************** |
| 709 | * WCUSER_PasteFromClipboard |
| 710 | * |
| 711 | * |
| 712 | */ |
| 713 | static void WCUSER_PasteFromClipboard(struct inner_data* data) |
| 714 | { |
| 715 | HANDLE h; |
| 716 | WCHAR* ptr; |
| 717 | |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 718 | if (!OpenClipboard(data->hWnd)) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 719 | h = GetClipboardData(CF_UNICODETEXT); |
| 720 | if (h && (ptr = GlobalLock(h))) |
| 721 | { |
| 722 | int i, len = GlobalSize(h) / sizeof(WCHAR); |
| 723 | INPUT_RECORD ir[2]; |
| 724 | DWORD n; |
| 725 | SHORT sh; |
| 726 | |
| 727 | ir[0].EventType = KEY_EVENT; |
| 728 | ir[0].Event.KeyEvent.wRepeatCount = 0; |
| 729 | ir[0].Event.KeyEvent.dwControlKeyState = 0; |
| 730 | ir[0].Event.KeyEvent.bKeyDown = TRUE; |
| 731 | |
| 732 | /* generate the corresponding input records */ |
| 733 | for (i = 0; i < len; i++) |
| 734 | { |
| 735 | /* FIXME: the modifying keys are not generated (shift, ctrl...) */ |
| 736 | sh = VkKeyScan(ptr[i]); |
| 737 | ir[0].Event.KeyEvent.wVirtualKeyCode = LOBYTE(sh); |
| 738 | ir[0].Event.KeyEvent.wVirtualScanCode = MapVirtualKey(LOBYTE(sh), 0); |
| 739 | ir[0].Event.KeyEvent.uChar.UnicodeChar = ptr[i]; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 740 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 741 | ir[1] = ir[0]; |
| 742 | ir[1].Event.KeyEvent.bKeyDown = FALSE; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 743 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 744 | WriteConsoleInput(data->hConIn, ir, 2, &n); |
| 745 | } |
| 746 | GlobalUnlock(h); |
| 747 | } |
| 748 | CloseClipboard(); |
| 749 | } |
| 750 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 751 | /****************************************************************** |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 752 | * WCUSER_Refresh |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 753 | * |
| 754 | * |
| 755 | */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 756 | static void WCUSER_Refresh(const struct inner_data* data, int tp, int bm) |
| 757 | { |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 758 | WCUSER_FillMemDC(data, tp, bm); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 759 | if (data->curcfg.win_pos.Y <= bm && data->curcfg.win_pos.Y + data->curcfg.win_height >= tp) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 760 | { |
| 761 | RECT r; |
| 762 | |
| 763 | r.left = 0; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 764 | r.right = data->curcfg.win_width * data->curcfg.cell_width; |
| 765 | r.top = (tp - data->curcfg.win_pos.Y) * data->curcfg.cell_height; |
| 766 | r.bottom = (bm - data->curcfg.win_pos.Y + 1) * data->curcfg.cell_height; |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 767 | InvalidateRect(data->hWnd, &r, FALSE); |
| 768 | UpdateWindow(data->hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 769 | } |
| 770 | } |
| 771 | |
| 772 | /****************************************************************** |
| 773 | * WCUSER_Paint |
| 774 | * |
| 775 | * |
| 776 | */ |
| 777 | static void WCUSER_Paint(const struct inner_data* data) |
| 778 | { |
| 779 | PAINTSTRUCT ps; |
| 780 | |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 781 | BeginPaint(data->hWnd, &ps); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 782 | BitBlt(ps.hdc, 0, 0, |
| 783 | data->curcfg.win_width * data->curcfg.cell_width, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 784 | data->curcfg.win_height * data->curcfg.cell_height, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 785 | PRIVATE(data)->hMemDC, |
| 786 | data->curcfg.win_pos.X * data->curcfg.cell_width, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 787 | data->curcfg.win_pos.Y * data->curcfg.cell_height, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 788 | SRCCOPY); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 789 | if (PRIVATE(data)->has_selection) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 790 | WCUSER_SetSelection(data, ps.hdc); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 791 | EndPaint(data->hWnd, &ps); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /****************************************************************** |
| 795 | * WCUSER_Scroll |
| 796 | * |
| 797 | * |
| 798 | */ |
| 799 | static void WCUSER_Scroll(struct inner_data* data, int pos, BOOL horz) |
| 800 | { |
| 801 | if (horz) |
| 802 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 803 | SetScrollPos(data->hWnd, SB_HORZ, pos, TRUE); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 804 | data->curcfg.win_pos.X = pos; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 805 | } |
| 806 | else |
| 807 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 808 | SetScrollPos(data->hWnd, SB_VERT, pos, TRUE); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 809 | data->curcfg.win_pos.Y = pos; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 810 | } |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 811 | InvalidateRect(data->hWnd, NULL, FALSE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 814 | /****************************************************************** |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 815 | * WCUSER_FillMenu |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 816 | * |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 817 | * |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 818 | */ |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 819 | static BOOL WCUSER_FillMenu(HMENU hMenu, BOOL sep) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 820 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 821 | HMENU hSubMenu; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 822 | HINSTANCE hInstance = GetModuleHandle(NULL); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 823 | WCHAR buff[256]; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 824 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 825 | if (!hMenu) return FALSE; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 826 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 827 | /* FIXME: error handling & memory cleanup */ |
| 828 | hSubMenu = CreateMenu(); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 829 | if (!hSubMenu) return FALSE; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 830 | |
| 831 | LoadString(hInstance, IDS_MARK, buff, sizeof(buff) / sizeof(WCHAR)); |
| 832 | InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_MARK, buff); |
| 833 | LoadString(hInstance, IDS_COPY, buff, sizeof(buff) / sizeof(WCHAR)); |
| 834 | InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_COPY, buff); |
| 835 | LoadString(hInstance, IDS_PASTE, buff, sizeof(buff) / sizeof(WCHAR)); |
| 836 | InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_PASTE, buff); |
| 837 | LoadString(hInstance, IDS_SELECTALL, buff, sizeof(buff) / sizeof(WCHAR)); |
| 838 | InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SELECTALL, buff); |
| 839 | LoadString(hInstance, IDS_SCROLL, buff, sizeof(buff) / sizeof(WCHAR)); |
| 840 | InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SCROLL, buff); |
| 841 | LoadString(hInstance, IDS_SEARCH, buff, sizeof(buff) / sizeof(WCHAR)); |
| 842 | InsertMenu(hSubMenu, -1, MF_BYPOSITION|MF_STRING, IDS_SEARCH, buff); |
| 843 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 844 | if (sep) InsertMenu(hMenu, -1, MF_BYPOSITION|MF_SEPARATOR, 0, NULL); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 845 | LoadString(hInstance, IDS_EDIT, buff, sizeof(buff) / sizeof(WCHAR)); |
| 846 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING|MF_POPUP, (UINT_PTR)hSubMenu, buff); |
| 847 | LoadString(hInstance, IDS_DEFAULT, buff, sizeof(buff) / sizeof(WCHAR)); |
| 848 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, IDS_DEFAULT, buff); |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 849 | LoadString(hInstance, IDS_PROPERTIES, buff, sizeof(buff) / sizeof(WCHAR)); |
| 850 | InsertMenu(hMenu, -1, MF_BYPOSITION|MF_STRING, IDS_PROPERTIES, buff); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 851 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 852 | return TRUE; |
| 853 | } |
| 854 | |
| 855 | /****************************************************************** |
Andreas Mohr | 029b948 | 2002-07-23 02:02:46 +0000 | [diff] [blame] | 856 | * WCUSER_SetMenuDetails |
| 857 | * |
| 858 | * Grays / ungrays the menu items according to their state |
| 859 | */ |
| 860 | static void WCUSER_SetMenuDetails(const struct inner_data* data, HMENU hMenu) |
| 861 | { |
| 862 | if (!hMenu) {WINE_ERR("Issue in getting menu bits\n");return;} |
| 863 | |
| 864 | EnableMenuItem(hMenu, IDS_COPY, |
| 865 | MF_BYCOMMAND|(PRIVATE(data)->has_selection ? MF_ENABLED : MF_GRAYED)); |
| 866 | EnableMenuItem(hMenu, IDS_PASTE, |
| 867 | MF_BYCOMMAND|(IsClipboardFormatAvailable(CF_UNICODETEXT) |
| 868 | ? MF_ENABLED : MF_GRAYED)); |
| 869 | EnableMenuItem(hMenu, IDS_SCROLL, MF_BYCOMMAND|MF_GRAYED); |
| 870 | EnableMenuItem(hMenu, IDS_SEARCH, MF_BYCOMMAND|MF_GRAYED); |
| 871 | } |
| 872 | |
| 873 | /****************************************************************** |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 874 | * WCUSER_Create |
| 875 | * |
| 876 | * Creates the window for the rendering |
| 877 | */ |
| 878 | static LRESULT WCUSER_Create(HWND hWnd, LPCREATESTRUCT lpcs) |
| 879 | { |
| 880 | struct inner_data* data; |
| 881 | HMENU hSysMenu; |
| 882 | |
| 883 | data = lpcs->lpCreateParams; |
Mike McCormack | 899840c | 2006-05-31 16:27:39 +0900 | [diff] [blame] | 884 | SetWindowLongPtr(hWnd, 0L, (DWORD_PTR)data); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 885 | data->hWnd = hWnd; |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 886 | |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 887 | hSysMenu = GetSystemMenu(hWnd, FALSE); |
| 888 | if (!hSysMenu) return 0; |
| 889 | PRIVATE(data)->hPopMenu = CreatePopupMenu(); |
| 890 | if (!PRIVATE(data)->hPopMenu) return 0; |
| 891 | |
| 892 | WCUSER_FillMenu(hSysMenu, TRUE); |
| 893 | WCUSER_FillMenu(PRIVATE(data)->hPopMenu, FALSE); |
| 894 | |
| 895 | PRIVATE(data)->hMemDC = CreateCompatibleDC(0); |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 896 | if (!PRIVATE(data)->hMemDC) {WINE_ERR("no mem dc\n");return 0;} |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 897 | |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 898 | data->curcfg.quick_edit = FALSE; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 899 | return 0; |
| 900 | } |
| 901 | |
| 902 | /****************************************************************** |
Andreas Mohr | 90ce2c8 | 2002-10-28 23:51:27 +0000 | [diff] [blame] | 903 | * WCUSER_GetCtrlKeyState |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 904 | * |
| 905 | * Get the console bit mask equivalent to the VK_ status in keyState |
| 906 | */ |
| 907 | static DWORD WCUSER_GetCtrlKeyState(BYTE* keyState) |
| 908 | { |
| 909 | DWORD ret = 0; |
| 910 | |
| 911 | GetKeyboardState(keyState); |
| 912 | if (keyState[VK_SHIFT] & 0x80) ret |= SHIFT_PRESSED; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 913 | if (keyState[VK_LCONTROL] & 0x80) ret |= LEFT_CTRL_PRESSED; |
| 914 | if (keyState[VK_RCONTROL] & 0x80) ret |= RIGHT_CTRL_PRESSED; |
| 915 | if (keyState[VK_LMENU] & 0x80) ret |= LEFT_ALT_PRESSED; |
| 916 | if (keyState[VK_RMENU] & 0x80) ret |= RIGHT_ALT_PRESSED; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 917 | if (keyState[VK_CAPITAL] & 0x01) ret |= CAPSLOCK_ON; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 918 | if (keyState[VK_NUMLOCK] & 0x01) ret |= NUMLOCK_ON; |
| 919 | if (keyState[VK_SCROLL] & 0x01) ret |= SCROLLLOCK_ON; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 920 | |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 921 | return ret; |
| 922 | } |
| 923 | |
| 924 | /****************************************************************** |
| 925 | * WCUSER_HandleSelectionKey |
| 926 | * |
| 927 | * Handles keys while selecting an area |
| 928 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 929 | static void WCUSER_HandleSelectionKey(struct inner_data* data, BOOL down, |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 930 | WPARAM wParam, LPARAM lParam) |
| 931 | { |
| 932 | BYTE keyState[256]; |
| 933 | DWORD state = WCUSER_GetCtrlKeyState(keyState) & ~(CAPSLOCK_ON|NUMLOCK_ON|SCROLLLOCK_ON); |
| 934 | COORD c1, c2; |
| 935 | |
Mikołaj Zalewski | 2750a74 | 2006-10-19 19:22:24 +0200 | [diff] [blame] | 936 | if (!down) return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 937 | |
| 938 | switch (state) |
| 939 | { |
| 940 | case 0: |
| 941 | switch (wParam) |
| 942 | { |
| 943 | case VK_RETURN: |
| 944 | PRIVATE(data)->has_selection = FALSE; |
| 945 | WCUSER_SetSelection(data, 0); |
| 946 | WCUSER_CopySelectionToClipboard(data); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 947 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 948 | case VK_RIGHT: |
| 949 | c1 = PRIVATE(data)->selectPt1; |
| 950 | c2 = PRIVATE(data)->selectPt2; |
| 951 | c1.X++; c2.X++; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 952 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 953 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 954 | case VK_LEFT: |
| 955 | c1 = PRIVATE(data)->selectPt1; |
| 956 | c2 = PRIVATE(data)->selectPt2; |
| 957 | c1.X--; c2.X--; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 958 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 959 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 960 | case VK_UP: |
| 961 | c1 = PRIVATE(data)->selectPt1; |
| 962 | c2 = PRIVATE(data)->selectPt2; |
| 963 | c1.Y--; c2.Y--; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 964 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 965 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 966 | case VK_DOWN: |
| 967 | c1 = PRIVATE(data)->selectPt1; |
| 968 | c2 = PRIVATE(data)->selectPt2; |
| 969 | c1.Y++; c2.Y++; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 970 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 971 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 972 | } |
| 973 | break; |
| 974 | case SHIFT_PRESSED: |
| 975 | switch (wParam) |
| 976 | { |
| 977 | case VK_RIGHT: |
| 978 | c1 = PRIVATE(data)->selectPt1; |
| 979 | c2 = PRIVATE(data)->selectPt2; |
| 980 | c2.X++; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 981 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 982 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 983 | case VK_LEFT: |
| 984 | c1 = PRIVATE(data)->selectPt1; |
| 985 | c2 = PRIVATE(data)->selectPt2; |
| 986 | c2.X--; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 987 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 988 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 989 | case VK_UP: |
| 990 | c1 = PRIVATE(data)->selectPt1; |
| 991 | c2 = PRIVATE(data)->selectPt2; |
| 992 | c2.Y--; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 993 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 994 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 995 | case VK_DOWN: |
| 996 | c1 = PRIVATE(data)->selectPt1; |
| 997 | c2 = PRIVATE(data)->selectPt2; |
| 998 | c2.Y++; |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 999 | WCUSER_MoveSelection(data, c1, c2); |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 1000 | return; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1001 | } |
| 1002 | break; |
| 1003 | } |
Mikołaj Zalewski | bf42a34 | 2006-10-19 19:36:30 +0200 | [diff] [blame] | 1004 | |
| 1005 | if (wParam < VK_SPACE) /* Shift, Alt, Ctrl, Num Lock etc. */ |
| 1006 | return; |
| 1007 | |
| 1008 | WCUSER_SetSelection(data, 0); |
| 1009 | PRIVATE(data)->has_selection = FALSE; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | /****************************************************************** |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1013 | * WCUSER_GenerateKeyInputRecord |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1014 | * |
| 1015 | * generates input_record from windows WM_KEYUP/WM_KEYDOWN messages |
| 1016 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1017 | static void WCUSER_GenerateKeyInputRecord(struct inner_data* data, BOOL down, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1018 | WPARAM wParam, LPARAM lParam, BOOL sys) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1019 | { |
| 1020 | INPUT_RECORD ir; |
| 1021 | DWORD n; |
| 1022 | WCHAR buf[2]; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1023 | static WCHAR last; /* keep last char seen as feed for key up message */ |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1024 | BYTE keyState[256]; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1025 | |
| 1026 | ir.EventType = KEY_EVENT; |
| 1027 | ir.Event.KeyEvent.bKeyDown = down; |
| 1028 | ir.Event.KeyEvent.wRepeatCount = LOWORD(lParam); |
| 1029 | ir.Event.KeyEvent.wVirtualKeyCode = wParam; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1030 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1031 | ir.Event.KeyEvent.wVirtualScanCode = HIWORD(lParam) & 0xFF; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1032 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1033 | ir.Event.KeyEvent.uChar.UnicodeChar = 0; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1034 | ir.Event.KeyEvent.dwControlKeyState = WCUSER_GetCtrlKeyState(keyState); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1035 | if (lParam & (1L << 24)) ir.Event.KeyEvent.dwControlKeyState |= ENHANCED_KEY; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1036 | if (sys) ir.Event.KeyEvent.dwControlKeyState |= LEFT_ALT_PRESSED; /* FIXME: gotta choose one */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1037 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1038 | if (!(ir.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY)) |
| 1039 | { |
| 1040 | if (down) |
| 1041 | { |
| 1042 | switch (ToUnicode(wParam, HIWORD(lParam), keyState, buf, 2, 0)) |
| 1043 | { |
| 1044 | case 2: |
| 1045 | /* FIXME... should generate two events... */ |
| 1046 | /* fall thru */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1047 | case 1: |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1048 | last = buf[0]; |
| 1049 | break; |
| 1050 | default: |
| 1051 | last = 0; |
| 1052 | break; |
| 1053 | } |
| 1054 | } |
| 1055 | ir.Event.KeyEvent.uChar.UnicodeChar = last; /* FIXME HACKY... and buggy 'coz it should be a stack, not a single value */ |
| 1056 | if (!down) last = 0; |
| 1057 | } |
| 1058 | |
| 1059 | WriteConsoleInput(data->hConIn, &ir, 1, &n); |
| 1060 | } |
| 1061 | |
| 1062 | /****************************************************************** |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1063 | * WCUSER_GenerateMouseInputRecord |
| 1064 | * |
| 1065 | * |
| 1066 | */ |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1067 | static void WCUSER_GenerateMouseInputRecord(struct inner_data* data, COORD c, |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1068 | WPARAM wParam, DWORD event) |
| 1069 | { |
| 1070 | INPUT_RECORD ir; |
| 1071 | BYTE keyState[256]; |
| 1072 | DWORD mode, n; |
| 1073 | |
| 1074 | /* MOUSE_EVENTs shouldn't be sent unless ENABLE_MOUSE_INPUT is active */ |
| 1075 | if (!GetConsoleMode(data->hConIn, &mode) || !(mode & ENABLE_MOUSE_INPUT)) |
| 1076 | return; |
| 1077 | |
| 1078 | ir.EventType = MOUSE_EVENT; |
| 1079 | ir.Event.MouseEvent.dwMousePosition = c; |
| 1080 | ir.Event.MouseEvent.dwButtonState = 0; |
| 1081 | if (wParam & MK_LBUTTON) ir.Event.MouseEvent.dwButtonState |= FROM_LEFT_1ST_BUTTON_PRESSED; |
| 1082 | if (wParam & MK_MBUTTON) ir.Event.MouseEvent.dwButtonState |= FROM_LEFT_2ND_BUTTON_PRESSED; |
| 1083 | if (wParam & MK_RBUTTON) ir.Event.MouseEvent.dwButtonState |= RIGHTMOST_BUTTON_PRESSED; |
Eric Pouech | 05ce225 | 2005-10-10 10:26:46 +0000 | [diff] [blame] | 1084 | if (wParam & MK_CONTROL) ir.Event.MouseEvent.dwButtonState |= LEFT_CTRL_PRESSED; |
| 1085 | if (wParam & MK_SHIFT) ir.Event.MouseEvent.dwButtonState |= SHIFT_PRESSED; |
| 1086 | if (event == MOUSE_WHEELED) ir.Event.MouseEvent.dwButtonState |= wParam & 0xFFFF0000; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1087 | ir.Event.MouseEvent.dwControlKeyState = WCUSER_GetCtrlKeyState(keyState); |
| 1088 | ir.Event.MouseEvent.dwEventFlags = event; |
| 1089 | |
| 1090 | WriteConsoleInput(data->hConIn, &ir, 1, &n); |
| 1091 | } |
| 1092 | |
| 1093 | /****************************************************************** |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1094 | * WCUSER_Proc |
| 1095 | * |
| 1096 | * |
| 1097 | */ |
| 1098 | static LRESULT CALLBACK WCUSER_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
| 1099 | { |
Mike McCormack | 899840c | 2006-05-31 16:27:39 +0900 | [diff] [blame] | 1100 | struct inner_data* data = (struct inner_data*)GetWindowLongPtr(hWnd, 0); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1101 | |
| 1102 | switch (uMsg) |
| 1103 | { |
| 1104 | case WM_CREATE: |
| 1105 | return WCUSER_Create(hWnd, (LPCREATESTRUCT)lParam); |
| 1106 | case WM_DESTROY: |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1107 | data->hWnd = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1108 | PostQuitMessage(0); |
| 1109 | break; |
| 1110 | case WM_PAINT: |
| 1111 | WCUSER_Paint(data); |
| 1112 | break; |
| 1113 | case WM_KEYDOWN: |
| 1114 | case WM_KEYUP: |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1115 | if (PRIVATE(data)->has_selection) |
| 1116 | WCUSER_HandleSelectionKey(data, uMsg == WM_KEYDOWN, wParam, lParam); |
| 1117 | else |
| 1118 | WCUSER_GenerateKeyInputRecord(data, uMsg == WM_KEYDOWN, wParam, lParam, FALSE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1119 | break; |
| 1120 | case WM_SYSKEYDOWN: |
| 1121 | case WM_SYSKEYUP: |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1122 | WCUSER_GenerateKeyInputRecord(data, uMsg == WM_SYSKEYDOWN, wParam, lParam, TRUE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1123 | break; |
| 1124 | case WM_LBUTTONDOWN: |
Mikołaj Zalewski | 4a94d09 | 2006-10-19 19:35:02 +0200 | [diff] [blame] | 1125 | if (data->curcfg.quick_edit || PRIVATE(data)->has_selection) |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1126 | { |
| 1127 | if (PRIVATE(data)->has_selection) |
Mikołaj Zalewski | 4a94d09 | 2006-10-19 19:35:02 +0200 | [diff] [blame] | 1128 | WCUSER_SetSelection(data, 0); |
| 1129 | |
| 1130 | if (data->curcfg.quick_edit && PRIVATE(data)->has_selection) |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1131 | { |
| 1132 | PRIVATE(data)->has_selection = FALSE; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1133 | } |
| 1134 | else |
| 1135 | { |
| 1136 | PRIVATE(data)->selectPt1 = PRIVATE(data)->selectPt2 = WCUSER_GetCell(data, lParam); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1137 | SetCapture(data->hWnd); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1138 | WCUSER_SetSelection(data, 0); |
| 1139 | PRIVATE(data)->has_selection = TRUE; |
| 1140 | } |
| 1141 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1142 | else |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1143 | { |
| 1144 | WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0); |
| 1145 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1146 | break; |
| 1147 | case WM_MOUSEMOVE: |
Mikołaj Zalewski | 4a94d09 | 2006-10-19 19:35:02 +0200 | [diff] [blame] | 1148 | if (data->curcfg.quick_edit || PRIVATE(data)->has_selection) |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1149 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1150 | if (GetCapture() == data->hWnd && PRIVATE(data)->has_selection && |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1151 | (wParam & MK_LBUTTON)) |
| 1152 | { |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 1153 | WCUSER_MoveSelection(data, PRIVATE(data)->selectPt1, WCUSER_GetCell(data, lParam)); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | else |
| 1157 | { |
| 1158 | WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, MOUSE_MOVED); |
| 1159 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1160 | break; |
| 1161 | case WM_LBUTTONUP: |
Mikołaj Zalewski | 4a94d09 | 2006-10-19 19:35:02 +0200 | [diff] [blame] | 1162 | if (data->curcfg.quick_edit || PRIVATE(data)->has_selection) |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1163 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1164 | if (GetCapture() == data->hWnd && PRIVATE(data)->has_selection) |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1165 | { |
Eric Pouech | abef9da | 2003-02-25 03:58:22 +0000 | [diff] [blame] | 1166 | WCUSER_MoveSelection(data, PRIVATE(data)->selectPt1, WCUSER_GetCell(data, lParam)); |
| 1167 | ReleaseCapture(); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | else |
| 1171 | { |
| 1172 | WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0); |
| 1173 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1174 | break; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1175 | case WM_RBUTTONDOWN: |
| 1176 | if ((wParam & (MK_CONTROL|MK_SHIFT)) == data->curcfg.menu_mask) |
| 1177 | { |
Mikołaj Zalewski | a5e9241 | 2006-10-19 19:38:01 +0200 | [diff] [blame] | 1178 | POINT pt; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1179 | |
Alexandre Julliard | f51c400 | 2006-10-25 17:43:02 +0200 | [diff] [blame] | 1180 | pt.x = (short)LOWORD(lParam); |
| 1181 | pt.y = (short)HIWORD(lParam); |
Mikołaj Zalewski | a5e9241 | 2006-10-19 19:38:01 +0200 | [diff] [blame] | 1182 | ClientToScreen(hWnd, &pt); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1183 | WCUSER_SetMenuDetails(data, PRIVATE(data)->hPopMenu); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1184 | TrackPopupMenu(PRIVATE(data)->hPopMenu, TPM_LEFTALIGN|TPM_TOPALIGN, |
Mikołaj Zalewski | a5e9241 | 2006-10-19 19:38:01 +0200 | [diff] [blame] | 1185 | pt.x, pt.y, 0, hWnd, NULL); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1186 | } |
| 1187 | else |
| 1188 | { |
| 1189 | WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0); |
| 1190 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1191 | break; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1192 | case WM_RBUTTONUP: |
| 1193 | /* no need to track for rbutton up when opening the popup... the event will be |
| 1194 | * swallowed by TrackPopupMenu */ |
Eric Pouech | 05ce225 | 2005-10-10 10:26:46 +0000 | [diff] [blame] | 1195 | case WM_MBUTTONDOWN: |
| 1196 | case WM_MBUTTONUP: |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1197 | WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, 0); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1198 | break; |
Eric Pouech | 05ce225 | 2005-10-10 10:26:46 +0000 | [diff] [blame] | 1199 | case WM_LBUTTONDBLCLK: |
| 1200 | case WM_MBUTTONDBLCLK: |
| 1201 | case WM_RBUTTONDBLCLK: |
| 1202 | WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, DOUBLE_CLICK); |
| 1203 | break; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1204 | case WM_MOUSEWHEEL: |
Eric Pouech | 05ce225 | 2005-10-10 10:26:46 +0000 | [diff] [blame] | 1205 | WCUSER_GenerateMouseInputRecord(data, WCUSER_GetCell(data, lParam), wParam, MOUSE_WHEELED); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1206 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1207 | case WM_SETFOCUS: |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1208 | if (data->curcfg.cursor_visible) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1209 | { |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1210 | CreateCaret(data->hWnd, PRIVATE(data)->cursor_bitmap, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1211 | data->curcfg.cell_width, data->curcfg.cell_height); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1212 | WCUSER_PosCursor(data); |
| 1213 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1214 | break; |
| 1215 | case WM_KILLFOCUS: |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1216 | if (data->curcfg.cursor_visible) |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1217 | DestroyCaret(); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1218 | break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1219 | case WM_HSCROLL: |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1220 | { |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1221 | int pos = data->curcfg.win_pos.X; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1222 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1223 | switch (LOWORD(wParam)) |
| 1224 | { |
| 1225 | case SB_PAGEUP: pos -= 8; break; |
| 1226 | case SB_PAGEDOWN: pos += 8; break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1227 | case SB_LINEUP: pos--; break; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1228 | case SB_LINEDOWN: pos++; break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1229 | case SB_THUMBTRACK: pos = HIWORD(wParam); break; |
| 1230 | default: break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1231 | } |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1232 | if (pos < 0) pos = 0; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1233 | if (pos > data->curcfg.sb_width - data->curcfg.win_width) |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1234 | pos = data->curcfg.sb_width - data->curcfg.win_width; |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1235 | if (pos != data->curcfg.win_pos.X) |
| 1236 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1237 | ScrollWindow(hWnd, (data->curcfg.win_pos.X - pos) * data->curcfg.cell_width, 0, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1238 | NULL, NULL); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1239 | data->curcfg.win_pos.X = pos; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1240 | SetScrollPos(hWnd, SB_HORZ, pos, TRUE); |
| 1241 | UpdateWindow(hWnd); |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1242 | WCUSER_PosCursor(data); |
| 1243 | WINECON_NotifyWindowChange(data); |
| 1244 | } |
| 1245 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1246 | break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1247 | case WM_VSCROLL: |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1248 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1249 | int pos = data->curcfg.win_pos.Y; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1250 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1251 | switch (LOWORD(wParam)) |
| 1252 | { |
| 1253 | case SB_PAGEUP: pos -= 8; break; |
| 1254 | case SB_PAGEDOWN: pos += 8; break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1255 | case SB_LINEUP: pos--; break; |
| 1256 | case SB_LINEDOWN: pos++; break; |
| 1257 | case SB_THUMBTRACK: pos = HIWORD(wParam); break; |
| 1258 | default: break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1259 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1260 | if (pos < 0) pos = 0; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1261 | if (pos > data->curcfg.sb_height - data->curcfg.win_height) |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1262 | pos = data->curcfg.sb_height - data->curcfg.win_height; |
| 1263 | if (pos != data->curcfg.win_pos.Y) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1264 | { |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1265 | ScrollWindow(hWnd, 0, (data->curcfg.win_pos.Y - pos) * data->curcfg.cell_height, |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1266 | NULL, NULL); |
| 1267 | data->curcfg.win_pos.Y = pos; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1268 | SetScrollPos(hWnd, SB_VERT, pos, TRUE); |
| 1269 | UpdateWindow(hWnd); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1270 | WCUSER_PosCursor(data); |
| 1271 | WINECON_NotifyWindowChange(data); |
| 1272 | } |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1273 | |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1274 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1275 | case WM_SYSCOMMAND: |
| 1276 | switch (wParam) |
| 1277 | { |
| 1278 | case IDS_DEFAULT: |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1279 | WCUSER_GetProperties(data, FALSE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1280 | break; |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 1281 | case IDS_PROPERTIES: |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1282 | WCUSER_GetProperties(data, TRUE); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1283 | break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1284 | default: |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1285 | return DefWindowProc(hWnd, uMsg, wParam, lParam); |
| 1286 | } |
| 1287 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1288 | case WM_COMMAND: |
| 1289 | switch (wParam) |
| 1290 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1291 | case IDS_DEFAULT: |
| 1292 | WCUSER_GetProperties(data, FALSE); |
| 1293 | break; |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 1294 | case IDS_PROPERTIES: |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1295 | WCUSER_GetProperties(data, TRUE); |
| 1296 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1297 | case IDS_MARK: |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1298 | PRIVATE(data)->selectPt1.X = PRIVATE(data)->selectPt1.Y = 0; |
| 1299 | PRIVATE(data)->selectPt2.X = PRIVATE(data)->selectPt2.Y = 0; |
| 1300 | WCUSER_SetSelection(data, 0); |
| 1301 | PRIVATE(data)->has_selection = TRUE; |
| 1302 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1303 | case IDS_COPY: |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1304 | if (PRIVATE(data)->has_selection) |
| 1305 | { |
| 1306 | PRIVATE(data)->has_selection = FALSE; |
| 1307 | WCUSER_SetSelection(data, 0); |
| 1308 | WCUSER_CopySelectionToClipboard(data); |
| 1309 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1310 | break; |
| 1311 | case IDS_PASTE: |
| 1312 | WCUSER_PasteFromClipboard(data); |
| 1313 | break; |
| 1314 | case IDS_SELECTALL: |
Eric Pouech | 5ef8871 | 2002-02-04 18:41:32 +0000 | [diff] [blame] | 1315 | PRIVATE(data)->selectPt1.X = PRIVATE(data)->selectPt1.Y = 0; |
| 1316 | PRIVATE(data)->selectPt2.X = (data->curcfg.sb_width - 1) * data->curcfg.cell_width; |
| 1317 | PRIVATE(data)->selectPt2.Y = (data->curcfg.sb_height - 1) * data->curcfg.cell_height; |
| 1318 | WCUSER_SetSelection(data, 0); |
| 1319 | PRIVATE(data)->has_selection = TRUE; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1320 | break; |
| 1321 | case IDS_SCROLL: |
| 1322 | case IDS_SEARCH: |
Dmitry Timoshkov | 3c9e7a7 | 2007-05-24 23:41:17 +0900 | [diff] [blame] | 1323 | WINE_FIXME("Unhandled yet command: %lx\n", wParam); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1324 | break; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1325 | default: |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1326 | return DefWindowProc(hWnd, uMsg, wParam, lParam); |
| 1327 | } |
| 1328 | break; |
| 1329 | case WM_INITMENUPOPUP: |
| 1330 | if (!HIWORD(lParam)) return DefWindowProc(hWnd, uMsg, wParam, lParam); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1331 | WCUSER_SetMenuDetails(data, GetSystemMenu(data->hWnd, FALSE)); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1332 | break; |
| 1333 | default: |
| 1334 | return DefWindowProc(hWnd, uMsg, wParam, lParam); |
| 1335 | } |
| 1336 | return 0; |
| 1337 | } |
| 1338 | |
| 1339 | /****************************************************************** |
| 1340 | * WCUSER_DeleteBackend |
| 1341 | * |
| 1342 | * |
| 1343 | */ |
Eric Pouech | 5c2a891 | 2004-11-29 18:00:10 +0000 | [diff] [blame] | 1344 | static void WCUSER_DeleteBackend(struct inner_data* data) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1345 | { |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1346 | if (!PRIVATE(data)) return; |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 1347 | if (PRIVATE(data)->hMemDC) DeleteDC(PRIVATE(data)->hMemDC); |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1348 | if (data->hWnd) DestroyWindow(data->hWnd); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1349 | if (PRIVATE(data)->hFont) DeleteObject(PRIVATE(data)->hFont); |
| 1350 | if (PRIVATE(data)->cursor_bitmap) DeleteObject(PRIVATE(data)->cursor_bitmap); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1351 | if (PRIVATE(data)->hBitmap) DeleteObject(PRIVATE(data)->hBitmap); |
| 1352 | HeapFree(GetProcessHeap(), 0, PRIVATE(data)); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | /****************************************************************** |
| 1356 | * WCUSER_MainLoop |
| 1357 | * |
| 1358 | * |
| 1359 | */ |
| 1360 | static int WCUSER_MainLoop(struct inner_data* data) |
| 1361 | { |
| 1362 | MSG msg; |
| 1363 | |
Kirill K. Smirnov | 945f4a79 | 2007-08-23 19:14:58 +0400 | [diff] [blame] | 1364 | ShowWindow(data->hWnd, data->nCmdShow); |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1365 | for (;;) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1366 | { |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 1367 | switch (MsgWaitForMultipleObjects(1, &data->hSynchro, FALSE, INFINITE, QS_ALLINPUT)) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1368 | { |
| 1369 | case WAIT_OBJECT_0: |
Eric Pouech | 0587a47 | 2002-05-21 18:05:16 +0000 | [diff] [blame] | 1370 | if (!WINECON_GrabChanges(data) && data->curcfg.exit_on_die) |
| 1371 | PostQuitMessage(0); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1372 | break; |
| 1373 | case WAIT_OBJECT_0+1: |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 1374 | /* need to use PeekMessage loop instead of simple GetMessage: |
| 1375 | * multiple messages might have arrived in between, |
| 1376 | * so GetMessage would lead to delayed processing */ |
Alexandre Julliard | 01c1466 | 2002-07-02 02:14:08 +0000 | [diff] [blame] | 1377 | while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1378 | { |
Alexandre Julliard | 01c1466 | 2002-07-02 02:14:08 +0000 | [diff] [blame] | 1379 | if (msg.message == WM_QUIT) return 0; |
| 1380 | WINE_TRACE("dispatching msg %04x\n", msg.message); |
| 1381 | DispatchMessage(&msg); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1382 | } |
| 1383 | break; |
| 1384 | default: |
Eric Pouech | e53cd36 | 2002-05-14 21:45:13 +0000 | [diff] [blame] | 1385 | WINE_ERR("got pb\n"); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1386 | /* err */ |
| 1387 | break; |
| 1388 | } |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1389 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | /****************************************************************** |
| 1393 | * WCUSER_InitBackend |
| 1394 | * |
| 1395 | * Initialisation part II: creation of window. |
| 1396 | * |
| 1397 | */ |
Eric Pouech | 99bc640 | 2003-06-13 16:32:52 +0000 | [diff] [blame] | 1398 | enum init_return WCUSER_InitBackend(struct inner_data* data) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1399 | { |
Francois Gouget | ebf0eb3 | 2004-04-20 00:34:52 +0000 | [diff] [blame] | 1400 | static const WCHAR wClassName[] = {'W','i','n','e','C','o','n','s','o','l','e','C','l','a','s','s',0}; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1401 | |
| 1402 | WNDCLASS wndclass; |
Mikołaj Zalewski | 2fb8ea4 | 2006-10-03 21:08:32 +0200 | [diff] [blame] | 1403 | CHARSETINFO ci; |
| 1404 | |
| 1405 | if (!TranslateCharsetInfo((DWORD *)(INT_PTR)GetACP(), &ci, TCI_SRCCODEPAGE)) |
| 1406 | return init_failed; |
| 1407 | g_uiDefaultCharset = ci.ciCharset; |
| 1408 | WINE_TRACE_(wc_font)("Code page %d => Default charset: %d\n", GetACP(), g_uiDefaultCharset); |
Eric Pouech | 94719d4 | 2001-12-04 20:46:54 +0000 | [diff] [blame] | 1409 | |
Eric Pouech | a908756 | 2002-01-02 21:45:47 +0000 | [diff] [blame] | 1410 | data->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct inner_data_user)); |
Eric Pouech | 99bc640 | 2003-06-13 16:32:52 +0000 | [diff] [blame] | 1411 | if (!data->private) return init_failed; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1412 | |
| 1413 | data->fnMainLoop = WCUSER_MainLoop; |
| 1414 | data->fnPosCursor = WCUSER_PosCursor; |
| 1415 | data->fnShapeCursor = WCUSER_ShapeCursor; |
| 1416 | data->fnComputePositions = WCUSER_ComputePositions; |
| 1417 | data->fnRefresh = WCUSER_Refresh; |
| 1418 | data->fnResizeScreenBuffer = WCUSER_ResizeScreenBuffer; |
| 1419 | data->fnSetTitle = WCUSER_SetTitle; |
Eric Pouech | 0589f72 | 2002-09-04 18:41:52 +0000 | [diff] [blame] | 1420 | data->fnSetFont = WCUSER_SetFontPmt; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1421 | data->fnScroll = WCUSER_Scroll; |
| 1422 | data->fnDeleteBackend = WCUSER_DeleteBackend; |
| 1423 | |
Eric Pouech | 05ce225 | 2005-10-10 10:26:46 +0000 | [diff] [blame] | 1424 | wndclass.style = CS_DBLCLKS; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1425 | wndclass.lpfnWndProc = WCUSER_Proc; |
| 1426 | wndclass.cbClsExtra = 0; |
Mike McCormack | 899840c | 2006-05-31 16:27:39 +0900 | [diff] [blame] | 1427 | wndclass.cbWndExtra = sizeof(DWORD_PTR); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1428 | wndclass.hInstance = GetModuleHandle(NULL); |
| 1429 | wndclass.hIcon = LoadIcon(0, IDI_WINLOGO); |
| 1430 | wndclass.hCursor = LoadCursor(0, IDC_ARROW); |
| 1431 | wndclass.hbrBackground = GetStockObject(BLACK_BRUSH); |
| 1432 | wndclass.lpszMenuName = NULL; |
| 1433 | wndclass.lpszClassName = wClassName; |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1434 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1435 | RegisterClass(&wndclass); |
| 1436 | |
| 1437 | CreateWindow(wndclass.lpszClassName, NULL, |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1438 | WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_HSCROLL|WS_VSCROLL, |
| 1439 | CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0, 0, wndclass.hInstance, data); |
Alexandre Julliard | d082517 | 2007-09-26 14:21:46 +0200 | [diff] [blame] | 1440 | if (!data->hWnd) return init_not_supported; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1441 | |
Eric Pouech | 99bc640 | 2003-06-13 16:32:52 +0000 | [diff] [blame] | 1442 | return init_success; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1443 | } |