2 * a GUI application for displaying a console
4 * Copyright 2001 Eric Pouech
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.
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.
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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "winecon_user.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(wineconsole
);
29 WINE_DECLARE_DEBUG_CHANNEL(wc_font
);
31 UINT g_uiDefaultCharset
;
33 static BOOL
WCUSER_SetFont(struct inner_data
* data
, const LOGFONTW
* font
);
35 /******************************************************************
38 * Fills the Mem DC with current cells values
40 static void WCUSER_FillMemDC(const struct inner_data
* data
, int upd_tp
, int upd_bm
)
51 /* no font has been set up yet, don't worry about filling the bitmap,
52 * we'll do it once a font is chosen
54 if (!PRIVATE(data
)->hFont
) return;
56 /* FIXME: could set up a mechanism to reuse the line between different
57 * calls to this function
59 if (!(line
= HeapAlloc(GetProcessHeap(), 0, data
->curcfg
.sb_width
* sizeof(WCHAR
)))) return;
60 dx
= HeapAlloc( GetProcessHeap(), 0, data
->curcfg
.sb_width
* sizeof(*dx
) );
62 hOldFont
= SelectObject(PRIVATE(data
)->hMemDC
, PRIVATE(data
)->hFont
);
63 for (j
= upd_tp
; j
<= upd_bm
; j
++)
65 cell
= &data
->cells
[j
* data
->curcfg
.sb_width
];
66 for (i
= 0; i
< data
->curcfg
.sb_width
; i
++)
68 attr
= cell
[i
].Attributes
;
69 SetBkColor(PRIVATE(data
)->hMemDC
, data
->curcfg
.color_map
[(attr
>> 4) & 0x0F]);
70 SetTextColor(PRIVATE(data
)->hMemDC
, data
->curcfg
.color_map
[attr
& 0x0F]);
71 for (k
= i
; k
< data
->curcfg
.sb_width
&& cell
[k
].Attributes
== attr
; k
++)
73 line
[k
- i
] = cell
[k
].Char
.UnicodeChar
;
74 dx
[k
- i
] = data
->curcfg
.cell_width
;
76 ExtTextOutW( PRIVATE(data
)->hMemDC
, i
* data
->curcfg
.cell_width
, j
* data
->curcfg
.cell_height
,
77 0, NULL
, line
, k
- i
, dx
);
78 if (PRIVATE(data
)->ext_leading
&&
79 (hbr
= CreateSolidBrush(data
->curcfg
.color_map
[(attr
>> 4) & 0x0F])))
81 r
.left
= i
* data
->curcfg
.cell_width
;
82 r
.top
= (j
+ 1) * data
->curcfg
.cell_height
- PRIVATE(data
)->ext_leading
;
83 r
.right
= k
* data
->curcfg
.cell_width
;
84 r
.bottom
= (j
+ 1) * data
->curcfg
.cell_height
;
85 FillRect(PRIVATE(data
)->hMemDC
, &r
, hbr
);
91 SelectObject(PRIVATE(data
)->hMemDC
, hOldFont
);
92 HeapFree(GetProcessHeap(), 0, dx
);
93 HeapFree(GetProcessHeap(), 0, line
);
96 /******************************************************************
99 * Either the font geometry or the sb geometry has changed. we need
100 * to recreate the bitmap geometry.
102 static void WCUSER_NewBitmap(struct inner_data
* data
)
107 if (!data
->curcfg
.sb_width
|| !data
->curcfg
.sb_height
||
108 !PRIVATE(data
)->hFont
|| !(hDC
= GetDC(data
->hWnd
)))
110 hnew
= CreateCompatibleBitmap(hDC
,
111 data
->curcfg
.sb_width
* data
->curcfg
.cell_width
,
112 data
->curcfg
.sb_height
* data
->curcfg
.cell_height
);
113 ReleaseDC(data
->hWnd
, hDC
);
114 hold
= SelectObject(PRIVATE(data
)->hMemDC
, hnew
);
116 if (PRIVATE(data
)->hBitmap
)
118 if (hold
== PRIVATE(data
)->hBitmap
)
119 DeleteObject(PRIVATE(data
)->hBitmap
);
121 WINE_FIXME("leak\n");
123 PRIVATE(data
)->hBitmap
= hnew
;
124 WCUSER_FillMemDC(data
, 0, data
->curcfg
.sb_height
- 1);
127 /******************************************************************
128 * WCUSER_ResizeScreenBuffer
132 static void WCUSER_ResizeScreenBuffer(struct inner_data
* data
)
134 WCUSER_NewBitmap(data
);
137 /******************************************************************
140 * Set a new position for the cursor
142 static void WCUSER_PosCursor(const struct inner_data
* data
)
144 if (data
->hWnd
!= GetFocus() || !data
->curcfg
.cursor_visible
) return;
146 SetCaretPos((data
->cursor
.X
- data
->curcfg
.win_pos
.X
) * data
->curcfg
.cell_width
,
147 (data
->cursor
.Y
- data
->curcfg
.win_pos
.Y
) * data
->curcfg
.cell_height
);
148 ShowCaret(data
->hWnd
);
151 /******************************************************************
154 * Sets a new shape for the cursor
156 static void WCUSER_ShapeCursor(struct inner_data
* data
, int size
, int vis
, BOOL force
)
158 if (force
|| size
!= data
->curcfg
.cursor_size
)
160 if (data
->curcfg
.cursor_visible
&& data
->hWnd
== GetFocus()) DestroyCaret();
161 if (PRIVATE(data
)->cursor_bitmap
) DeleteObject(PRIVATE(data
)->cursor_bitmap
);
162 PRIVATE(data
)->cursor_bitmap
= NULL
;
165 int w16b
; /* number of bytes per row, aligned on word size */
169 w16b
= ((data
->curcfg
.cell_width
+ 15) & ~15) / 8;
170 ptr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, w16b
* data
->curcfg
.cell_height
);
172 nbl
= max((data
->curcfg
.cell_height
* size
) / 100, 1);
173 for (j
= data
->curcfg
.cell_height
- nbl
; j
< data
->curcfg
.cell_height
; j
++)
175 for (i
= 0; i
< data
->curcfg
.cell_width
; i
++)
177 ptr
[w16b
* j
+ (i
/ 8)] |= 0x80 >> (i
& 7);
180 PRIVATE(data
)->cursor_bitmap
= CreateBitmap(data
->curcfg
.cell_width
,
181 data
->curcfg
.cell_height
, 1, 1, ptr
);
182 HeapFree(GetProcessHeap(), 0, ptr
);
184 data
->curcfg
.cursor_size
= size
;
185 data
->curcfg
.cursor_visible
= -1;
189 if (force
|| vis
!= data
->curcfg
.cursor_visible
)
191 data
->curcfg
.cursor_visible
= vis
;
192 if (data
->hWnd
== GetFocus())
196 CreateCaret(data
->hWnd
, PRIVATE(data
)->cursor_bitmap
,
197 data
->curcfg
.cell_width
, data
->curcfg
.cell_height
);
198 WCUSER_PosCursor(data
);
206 WINECON_DumpConfig("crsr", &data
->curcfg
);
209 /******************************************************************
210 * WCUSER_ComputePositions
212 * Recomputes all the components (mainly scroll bars) positions
214 static void WCUSER_ComputePositions(struct inner_data
* data
)
219 /* compute window size from desired client size */
221 r
.right
= data
->curcfg
.win_width
* data
->curcfg
.cell_width
;
222 r
.bottom
= data
->curcfg
.win_height
* data
->curcfg
.cell_height
;
224 if (IsRectEmpty(&r
)) return;
226 AdjustWindowRect(&r
, GetWindowLongW(data
->hWnd
, GWL_STYLE
), FALSE
);
229 if (data
->curcfg
.sb_width
> data
->curcfg
.win_width
)
231 dy
= GetSystemMetrics(SM_CYHSCROLL
);
232 SetScrollRange(data
->hWnd
, SB_HORZ
, 0,
233 data
->curcfg
.sb_width
- data
->curcfg
.win_width
, FALSE
);
234 SetScrollPos(data
->hWnd
, SB_HORZ
, 0, FALSE
); /* FIXME */
235 ShowScrollBar(data
->hWnd
, SB_HORZ
, TRUE
);
239 ShowScrollBar(data
->hWnd
, SB_HORZ
, FALSE
);
242 if (data
->curcfg
.sb_height
> data
->curcfg
.win_height
)
244 dx
= GetSystemMetrics(SM_CXVSCROLL
);
245 SetScrollRange(data
->hWnd
, SB_VERT
, 0,
246 data
->curcfg
.sb_height
- data
->curcfg
.win_height
, FALSE
);
247 SetScrollPos(data
->hWnd
, SB_VERT
, 0, FALSE
); /* FIXME */
248 ShowScrollBar(data
->hWnd
, SB_VERT
, TRUE
);
252 ShowScrollBar(data
->hWnd
, SB_VERT
, FALSE
);
255 SetWindowPos(data
->hWnd
, 0, 0, 0, r
.right
- r
.left
+ dx
, r
.bottom
- r
.top
+ dy
,
256 SWP_NOMOVE
|SWP_NOZORDER
);
257 WCUSER_ShapeCursor(data
, data
->curcfg
.cursor_size
, data
->curcfg
.cursor_visible
, TRUE
);
258 WCUSER_PosCursor(data
);
261 /******************************************************************
264 * Sets the title to the wine console
266 static void WCUSER_SetTitle(const struct inner_data
* data
)
270 if (WINECON_GetConsoleTitle(data
->hConIn
, buffer
, sizeof(buffer
)))
271 SetWindowTextW(data
->hWnd
, buffer
);
274 void WCUSER_DumpLogFont(const char* pfx
, const LOGFONTW
* lf
, DWORD ft
)
276 WINE_TRACE_(wc_font
)("%s %s%s%s%s\n"
277 "\tlf.lfHeight=%d lf.lfWidth=%d lf.lfEscapement=%d lf.lfOrientation=%d\n"
278 "\tlf.lfWeight=%d lf.lfItalic=%u lf.lfUnderline=%u lf.lfStrikeOut=%u\n"
279 "\tlf.lfCharSet=%u lf.lfOutPrecision=%u lf.lfClipPrecision=%u lf.lfQuality=%u\n"
280 "\tlf->lfPitchAndFamily=%u lf.lfFaceName=%s\n",
282 (ft
& RASTER_FONTTYPE
) ? "raster" : "",
283 (ft
& TRUETYPE_FONTTYPE
) ? "truetype" : "",
284 ((ft
& (RASTER_FONTTYPE
|TRUETYPE_FONTTYPE
)) == 0) ? "vector" : "",
285 (ft
& DEVICE_FONTTYPE
) ? "|device" : "",
286 lf
->lfHeight
, lf
->lfWidth
, lf
->lfEscapement
, lf
->lfOrientation
,
287 lf
->lfWeight
, lf
->lfItalic
, lf
->lfUnderline
, lf
->lfStrikeOut
, lf
->lfCharSet
,
288 lf
->lfOutPrecision
, lf
->lfClipPrecision
, lf
->lfQuality
, lf
->lfPitchAndFamily
,
289 wine_dbgstr_w(lf
->lfFaceName
));
292 void WCUSER_DumpTextMetric(const TEXTMETRICW
* tm
, DWORD ft
)
294 WINE_TRACE_(wc_font
)("%s%s%s%s\n"
295 "\ttmHeight=%d tmAscent=%d tmDescent=%d tmInternalLeading=%d tmExternalLeading=%d\n"
296 "\ttmAveCharWidth=%d tmMaxCharWidth=%d tmWeight=%d tmOverhang=%d\n"
297 "\ttmDigitizedAspectX=%d tmDigitizedAspectY=%d\n"
298 "\ttmFirstChar=%d tmLastChar=%d tmDefaultChar=%d tmBreakChar=%d\n"
299 "\ttmItalic=%u tmUnderlined=%u tmStruckOut=%u tmPitchAndFamily=%u tmCharSet=%u\n",
300 (ft
& RASTER_FONTTYPE
) ? "raster" : "",
301 (ft
& TRUETYPE_FONTTYPE
) ? "truetype" : "",
302 ((ft
& (RASTER_FONTTYPE
|TRUETYPE_FONTTYPE
)) == 0) ? "vector" : "",
303 (ft
& DEVICE_FONTTYPE
) ? "|device" : "",
304 tm
->tmHeight
, tm
->tmAscent
, tm
->tmDescent
, tm
->tmInternalLeading
, tm
->tmExternalLeading
, tm
->tmAveCharWidth
,
305 tm
->tmMaxCharWidth
, tm
->tmWeight
, tm
->tmOverhang
, tm
->tmDigitizedAspectX
, tm
->tmDigitizedAspectY
,
306 tm
->tmFirstChar
, tm
->tmLastChar
, tm
->tmDefaultChar
, tm
->tmBreakChar
, tm
->tmItalic
, tm
->tmUnderlined
, tm
->tmStruckOut
,
307 tm
->tmPitchAndFamily
, tm
->tmCharSet
);
310 /******************************************************************
311 * WCUSER_AreFontsEqual
315 static BOOL
WCUSER_AreFontsEqual(const struct config_data
* config
, const LOGFONTW
* lf
)
317 return lf
->lfHeight
== config
->cell_height
&&
318 lf
->lfWeight
== config
->font_weight
&&
319 !lf
->lfItalic
&& !lf
->lfUnderline
&& !lf
->lfStrikeOut
&&
320 !lstrcmpW(lf
->lfFaceName
, config
->face_name
);
325 struct inner_data
* data
;
330 /******************************************************************
331 * WCUSER_ValidateFontMetric
333 * Returns true if the font described in tm is usable as a font for the renderer
335 BOOL
WCUSER_ValidateFontMetric(const struct inner_data
* data
, const TEXTMETRICW
* tm
,
336 DWORD type
, int pass
)
338 switch (pass
) /* we get increasingly lenient in later passes */
341 if (type
& RASTER_FONTTYPE
)
343 if (tm
->tmMaxCharWidth
* data
->curcfg
.win_width
>= GetSystemMetrics(SM_CXSCREEN
) ||
344 tm
->tmHeight
* data
->curcfg
.win_height
>= GetSystemMetrics(SM_CYSCREEN
))
349 if (tm
->tmCharSet
!= DEFAULT_CHARSET
&& tm
->tmCharSet
!= g_uiDefaultCharset
) return FALSE
;
352 if (tm
->tmItalic
|| tm
->tmUnderlined
|| tm
->tmStruckOut
) return FALSE
;
358 /******************************************************************
359 * WCUSER_ValidateFont
361 * Returns true if the font family described in lf is usable as a font for the renderer
363 BOOL
WCUSER_ValidateFont(const struct inner_data
* data
, const LOGFONTW
* lf
, int pass
)
365 switch (pass
) /* we get increasingly lenient in later passes */
369 if (lf
->lfCharSet
!= DEFAULT_CHARSET
&& lf
->lfCharSet
!= g_uiDefaultCharset
) return FALSE
;
372 if ((lf
->lfPitchAndFamily
& 3) != FIXED_PITCH
) return FALSE
;
375 if (lf
->lfFaceName
[0] == '@') return FALSE
;
381 /******************************************************************
382 * get_first_font_enum_2
383 * get_first_font_enum
385 * Helper functions to get a decent font for the renderer
387 static int CALLBACK
get_first_font_enum_2(const LOGFONTW
* lf
, const TEXTMETRICW
* tm
,
388 DWORD FontType
, LPARAM lParam
)
390 struct font_chooser
* fc
= (struct font_chooser
*)lParam
;
392 WCUSER_DumpTextMetric(tm
, FontType
);
393 if (WCUSER_ValidateFontMetric(fc
->data
, tm
, FontType
, fc
->pass
))
397 /* Use the default sizes for the font (this is needed, especially for
398 * TrueType fonts, so that we get a decent size, not the max size)
400 mlf
.lfWidth
= fc
->data
->curcfg
.cell_width
;
401 mlf
.lfHeight
= fc
->data
->curcfg
.cell_height
;
402 if (WCUSER_SetFont(fc
->data
, &mlf
))
404 struct config_data defcfg
;
406 WCUSER_DumpLogFont("InitChoosing: ", &mlf
, FontType
);
408 /* since we've modified the current config with new font information,
409 * set this information as the new default.
411 WINECON_RegLoad(NULL
, &defcfg
);
412 defcfg
.cell_width
= fc
->data
->curcfg
.cell_width
;
413 defcfg
.cell_height
= fc
->data
->curcfg
.cell_height
;
414 lstrcpyW(defcfg
.face_name
, fc
->data
->curcfg
.face_name
);
415 /* Force also its writing back to the registry so that we can get it
418 WINECON_RegSave(&defcfg
);
425 static int CALLBACK
get_first_font_enum(const LOGFONTW
* lf
, const TEXTMETRICW
* tm
,
426 DWORD FontType
, LPARAM lParam
)
428 struct font_chooser
* fc
= (struct font_chooser
*)lParam
;
430 WCUSER_DumpLogFont("InitFamily: ", lf
, FontType
);
431 if (WCUSER_ValidateFont(fc
->data
, lf
, fc
->pass
))
433 EnumFontFamiliesW(PRIVATE(fc
->data
)->hMemDC
, lf
->lfFaceName
,
434 get_first_font_enum_2
, lParam
);
435 return !fc
->done
; /* we just need the first matching one... */
440 /******************************************************************
443 * get the relevant information from the font described in lf and store them
446 HFONT
WCUSER_CopyFont(struct config_data
* config
, HWND hWnd
, const LOGFONTW
* lf
, LONG
* el
)
450 HFONT hFont
, hOldFont
;
453 if (!(hDC
= GetDC(hWnd
))) return NULL
;
454 if (!(hFont
= CreateFontIndirectW(lf
)))
456 ReleaseDC(hWnd
, hDC
);
459 hOldFont
= SelectObject(hDC
, hFont
);
460 GetTextMetricsW(hDC
, &tm
);
461 SelectObject(hDC
, hOldFont
);
462 ReleaseDC(hWnd
, hDC
);
464 config
->cell_width
= tm
.tmAveCharWidth
;
465 config
->cell_height
= tm
.tmHeight
+ tm
.tmExternalLeading
;
466 config
->font_weight
= tm
.tmWeight
;
467 lstrcpyW(config
->face_name
, lf
->lfFaceName
);
468 if (el
) *el
= tm
.tmExternalLeading
;
470 /* FIXME: use maximum width for DBCS codepages since some chars take two cells */
471 if (GetCPInfo( GetConsoleOutputCP(), &cpinfo
) && cpinfo
.MaxCharSize
> 1)
472 config
->cell_width
= tm
.tmMaxCharWidth
;
477 /******************************************************************
482 void WCUSER_FillLogFont(LOGFONTW
* lf
, const WCHAR
* name
, UINT height
, UINT weight
)
484 lf
->lfHeight
= height
;
486 lf
->lfEscapement
= 0;
487 lf
->lfOrientation
= 0;
488 lf
->lfWeight
= weight
;
489 lf
->lfItalic
= FALSE
;
490 lf
->lfUnderline
= FALSE
;
491 lf
->lfStrikeOut
= FALSE
;
492 lf
->lfCharSet
= DEFAULT_CHARSET
;
493 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
494 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
495 lf
->lfQuality
= DEFAULT_QUALITY
;
496 lf
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
497 lstrcpyW(lf
->lfFaceName
, name
);
500 /******************************************************************
503 * sets logfont as the new font for the console
505 BOOL
WCUSER_SetFont(struct inner_data
* data
, const LOGFONTW
* logfont
)
510 if (PRIVATE(data
)->hFont
!= 0 && WCUSER_AreFontsEqual(&data
->curcfg
, logfont
))
513 hFont
= WCUSER_CopyFont(&data
->curcfg
, data
->hWnd
, logfont
, &el
);
514 if (!hFont
) {WINE_ERR("wrong font\n"); return FALSE
;}
516 if (PRIVATE(data
)->hFont
) DeleteObject(PRIVATE(data
)->hFont
);
517 PRIVATE(data
)->hFont
= hFont
;
518 PRIVATE(data
)->ext_leading
= el
;
520 WCUSER_ComputePositions(data
);
521 WCUSER_NewBitmap(data
);
522 InvalidateRect(data
->hWnd
, NULL
, FALSE
);
523 UpdateWindow(data
->hWnd
);
528 /******************************************************************
531 * Sets a new font for the console.
532 * In fact a wrapper for WCUSER_SetFont
534 static void WCUSER_SetFontPmt(struct inner_data
* data
, const WCHAR
* font
,
535 unsigned height
, unsigned weight
)
538 struct font_chooser fc
;
540 WINE_TRACE_(wc_font
)("=> %s h=%u w=%u\n",
541 wine_dbgstr_wn(font
, -1), height
, weight
);
543 if (font
[0] != '\0' && height
!= 0 && weight
!= 0)
545 WCUSER_FillLogFont(&lf
, font
, height
, weight
);
546 if (WCUSER_SetFont(data
, &lf
))
548 WCUSER_DumpLogFont("InitReuses: ", &lf
, 0);
553 /* try to find an acceptable font */
554 WINE_WARN("Couldn't match the font from registry... trying to find one\n");
557 for (fc
.pass
= 0; fc
.pass
<= 4; fc
.pass
++)
559 EnumFontFamiliesW(PRIVATE(data
)->hMemDC
, NULL
, get_first_font_enum
, (LPARAM
)&fc
);
562 WINECON_Fatal("Couldn't find a decent font, aborting");
565 /******************************************************************
568 * Get a cell from a relative coordinate in window (takes into
569 * account the scrolling)
571 static COORD
WCUSER_GetCell(const struct inner_data
* data
, LPARAM lParam
)
575 c
.X
= data
->curcfg
.win_pos
.X
+ (short)LOWORD(lParam
) / data
->curcfg
.cell_width
;
576 c
.Y
= data
->curcfg
.win_pos
.Y
+ (short)HIWORD(lParam
) / data
->curcfg
.cell_height
;
581 /******************************************************************
582 * WCUSER_GetSelectionRect
584 * Get the selection rectangle
586 static void WCUSER_GetSelectionRect(const struct inner_data
* data
, LPRECT r
)
588 r
->left
= (min(PRIVATE(data
)->selectPt1
.X
, PRIVATE(data
)->selectPt2
.X
) - data
->curcfg
.win_pos
.X
) * data
->curcfg
.cell_width
;
589 r
->top
= (min(PRIVATE(data
)->selectPt1
.Y
, PRIVATE(data
)->selectPt2
.Y
) - data
->curcfg
.win_pos
.Y
) * data
->curcfg
.cell_height
;
590 r
->right
= (max(PRIVATE(data
)->selectPt1
.X
, PRIVATE(data
)->selectPt2
.X
) + 1 - data
->curcfg
.win_pos
.X
) * data
->curcfg
.cell_width
;
591 r
->bottom
= (max(PRIVATE(data
)->selectPt1
.Y
, PRIVATE(data
)->selectPt2
.Y
) + 1 - data
->curcfg
.win_pos
.Y
) * data
->curcfg
.cell_height
;
594 /******************************************************************
595 * WCUSER_SetSelection
599 static void WCUSER_SetSelection(const struct inner_data
* data
, HDC hRefDC
)
604 WCUSER_GetSelectionRect(data
, &r
);
605 hDC
= hRefDC
? hRefDC
: GetDC(data
->hWnd
);
608 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
609 HideCaret(data
->hWnd
);
612 ReleaseDC(data
->hWnd
, hDC
);
613 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
614 ShowCaret(data
->hWnd
);
618 /******************************************************************
619 * WCUSER_MoveSelection
623 static void WCUSER_MoveSelection(struct inner_data
* data
, COORD c1
, COORD c2
)
628 if (c1
.X
< 0 || c1
.X
>= data
->curcfg
.sb_width
||
629 c2
.X
< 0 || c2
.X
>= data
->curcfg
.sb_width
||
630 c1
.Y
< 0 || c1
.Y
>= data
->curcfg
.sb_height
||
631 c2
.Y
< 0 || c2
.Y
>= data
->curcfg
.sb_height
)
634 WCUSER_GetSelectionRect(data
, &r
);
635 hDC
= GetDC(data
->hWnd
);
638 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
639 HideCaret(data
->hWnd
);
642 PRIVATE(data
)->selectPt1
= c1
;
643 PRIVATE(data
)->selectPt2
= c2
;
646 WCUSER_GetSelectionRect(data
, &r
);
648 ReleaseDC(data
->hWnd
, hDC
);
649 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
650 ShowCaret(data
->hWnd
);
654 /******************************************************************
655 * WCUSER_CopySelectionToClipboard
657 * Copies the current selection into the clipboard
659 static void WCUSER_CopySelectionToClipboard(const struct inner_data
* data
)
665 w
= abs(PRIVATE(data
)->selectPt1
.X
- PRIVATE(data
)->selectPt2
.X
) + 2;
666 h
= abs(PRIVATE(data
)->selectPt1
.Y
- PRIVATE(data
)->selectPt2
.Y
) + 1;
668 if (!OpenClipboard(data
->hWnd
)) return;
671 hMem
= GlobalAlloc(GMEM_MOVEABLE
, (w
* h
) * sizeof(WCHAR
));
672 if (hMem
&& (p
= GlobalLock(hMem
)))
677 c
.X
= min(PRIVATE(data
)->selectPt1
.X
, PRIVATE(data
)->selectPt2
.X
);
678 c
.Y
= min(PRIVATE(data
)->selectPt1
.Y
, PRIVATE(data
)->selectPt2
.Y
);
680 for (y
= 0; y
< h
; y
++, c
.Y
++)
685 ReadConsoleOutputCharacterW(data
->hConOut
, p
, w
- 1, c
, &count
);
687 /* strip spaces from the end of the line */
689 while (end
> p
&& *(end
- 1) == ' ')
691 *end
= (y
< h
- 1) ? '\n' : '\0';
695 SetClipboardData(CF_UNICODETEXT
, hMem
);
700 /******************************************************************
701 * WCUSER_PasteFromClipboard
705 static void WCUSER_PasteFromClipboard(struct inner_data
* data
)
710 if (!OpenClipboard(data
->hWnd
)) return;
711 h
= GetClipboardData(CF_UNICODETEXT
);
712 if (h
&& (ptr
= GlobalLock(h
)))
714 int i
, len
= GlobalSize(h
) / sizeof(WCHAR
);
719 ir
[0].EventType
= KEY_EVENT
;
720 ir
[0].Event
.KeyEvent
.wRepeatCount
= 0;
721 ir
[0].Event
.KeyEvent
.dwControlKeyState
= 0;
722 ir
[0].Event
.KeyEvent
.bKeyDown
= TRUE
;
724 /* generate the corresponding input records */
725 for (i
= 0; i
< len
; i
++)
727 /* FIXME: the modifying keys are not generated (shift, ctrl...) */
728 sh
= VkKeyScanW(ptr
[i
]);
729 ir
[0].Event
.KeyEvent
.wVirtualKeyCode
= LOBYTE(sh
);
730 ir
[0].Event
.KeyEvent
.wVirtualScanCode
= MapVirtualKeyW(LOBYTE(sh
), 0);
731 ir
[0].Event
.KeyEvent
.uChar
.UnicodeChar
= ptr
[i
];
734 ir
[1].Event
.KeyEvent
.bKeyDown
= FALSE
;
736 WriteConsoleInputW(data
->hConIn
, ir
, 2, &n
);
743 /******************************************************************
748 static void WCUSER_Refresh(const struct inner_data
* data
, int tp
, int bm
)
750 WCUSER_FillMemDC(data
, tp
, bm
);
751 if (data
->curcfg
.win_pos
.Y
<= bm
&& data
->curcfg
.win_pos
.Y
+ data
->curcfg
.win_height
>= tp
)
756 r
.right
= data
->curcfg
.win_width
* data
->curcfg
.cell_width
;
757 r
.top
= (tp
- data
->curcfg
.win_pos
.Y
) * data
->curcfg
.cell_height
;
758 r
.bottom
= (bm
- data
->curcfg
.win_pos
.Y
+ 1) * data
->curcfg
.cell_height
;
759 InvalidateRect(data
->hWnd
, &r
, FALSE
);
760 UpdateWindow(data
->hWnd
);
764 /******************************************************************
769 static void WCUSER_Paint(const struct inner_data
* data
)
773 if (data
->in_set_config
) return; /* in order to avoid some flicker */
774 BeginPaint(data
->hWnd
, &ps
);
776 data
->curcfg
.win_width
* data
->curcfg
.cell_width
,
777 data
->curcfg
.win_height
* data
->curcfg
.cell_height
,
778 PRIVATE(data
)->hMemDC
,
779 data
->curcfg
.win_pos
.X
* data
->curcfg
.cell_width
,
780 data
->curcfg
.win_pos
.Y
* data
->curcfg
.cell_height
,
782 if (PRIVATE(data
)->has_selection
)
783 WCUSER_SetSelection(data
, ps
.hdc
);
784 EndPaint(data
->hWnd
, &ps
);
787 /******************************************************************
792 static void WCUSER_Scroll(struct inner_data
* data
, int pos
, BOOL horz
)
796 ScrollWindow(data
->hWnd
, (data
->curcfg
.win_pos
.X
- pos
) * data
->curcfg
.cell_width
, 0, NULL
, NULL
);
797 SetScrollPos(data
->hWnd
, SB_HORZ
, pos
, TRUE
);
798 data
->curcfg
.win_pos
.X
= pos
;
802 ScrollWindow(data
->hWnd
, 0, (data
->curcfg
.win_pos
.Y
- pos
) * data
->curcfg
.cell_height
, NULL
, NULL
);
803 SetScrollPos(data
->hWnd
, SB_VERT
, pos
, TRUE
);
804 data
->curcfg
.win_pos
.Y
= pos
;
806 InvalidateRect(data
->hWnd
, NULL
, FALSE
);
809 /******************************************************************
814 static BOOL
WCUSER_FillMenu(HMENU hMenu
, BOOL sep
)
817 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
820 if (!hMenu
) return FALSE
;
822 /* FIXME: error handling & memory cleanup */
823 hSubMenu
= CreateMenu();
824 if (!hSubMenu
) return FALSE
;
826 LoadStringW(hInstance
, IDS_MARK
, buff
, sizeof(buff
) / sizeof(buff
[0]));
827 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_MARK
, buff
);
828 LoadStringW(hInstance
, IDS_COPY
, buff
, sizeof(buff
) / sizeof(buff
[0]));
829 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_COPY
, buff
);
830 LoadStringW(hInstance
, IDS_PASTE
, buff
, sizeof(buff
) / sizeof(buff
[0]));
831 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_PASTE
, buff
);
832 LoadStringW(hInstance
, IDS_SELECTALL
, buff
, sizeof(buff
) / sizeof(buff
[0]));
833 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_SELECTALL
, buff
);
834 LoadStringW(hInstance
, IDS_SCROLL
, buff
, sizeof(buff
) / sizeof(buff
[0]));
835 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_SCROLL
, buff
);
836 LoadStringW(hInstance
, IDS_SEARCH
, buff
, sizeof(buff
) / sizeof(buff
[0]));
837 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_SEARCH
, buff
);
839 if (sep
) InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_SEPARATOR
, 0, NULL
);
840 LoadStringW(hInstance
, IDS_EDIT
, buff
, sizeof(buff
) / sizeof(buff
[0]));
841 InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_STRING
|MF_POPUP
, (UINT_PTR
)hSubMenu
, buff
);
842 LoadStringW(hInstance
, IDS_DEFAULT
, buff
, sizeof(buff
) / sizeof(buff
[0]));
843 InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_DEFAULT
, buff
);
844 LoadStringW(hInstance
, IDS_PROPERTIES
, buff
, sizeof(buff
) / sizeof(buff
[0]));
845 InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_PROPERTIES
, buff
);
850 /******************************************************************
851 * WCUSER_SetMenuDetails
853 * Grays / ungrays the menu items according to their state
855 static void WCUSER_SetMenuDetails(const struct inner_data
* data
, HMENU hMenu
)
857 if (!hMenu
) {WINE_ERR("Issue in getting menu bits\n");return;}
859 EnableMenuItem(hMenu
, IDS_COPY
,
860 MF_BYCOMMAND
|(PRIVATE(data
)->has_selection
? MF_ENABLED
: MF_GRAYED
));
861 EnableMenuItem(hMenu
, IDS_PASTE
,
862 MF_BYCOMMAND
|(IsClipboardFormatAvailable(CF_UNICODETEXT
)
863 ? MF_ENABLED
: MF_GRAYED
));
864 EnableMenuItem(hMenu
, IDS_SCROLL
, MF_BYCOMMAND
|MF_GRAYED
);
865 EnableMenuItem(hMenu
, IDS_SEARCH
, MF_BYCOMMAND
|MF_GRAYED
);
868 /******************************************************************
871 * Creates the window for the rendering
873 static LRESULT
WCUSER_Create(HWND hWnd
, LPCREATESTRUCTW lpcs
)
875 struct inner_data
* data
;
878 data
= lpcs
->lpCreateParams
;
879 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)data
);
882 hSysMenu
= GetSystemMenu(hWnd
, FALSE
);
883 if (!hSysMenu
) return 0;
884 PRIVATE(data
)->hPopMenu
= CreatePopupMenu();
885 if (!PRIVATE(data
)->hPopMenu
) return 0;
887 WCUSER_FillMenu(hSysMenu
, TRUE
);
888 WCUSER_FillMenu(PRIVATE(data
)->hPopMenu
, FALSE
);
890 PRIVATE(data
)->hMemDC
= CreateCompatibleDC(0);
891 if (!PRIVATE(data
)->hMemDC
) {WINE_ERR("no mem dc\n");return 0;}
893 data
->curcfg
.quick_edit
= FALSE
;
897 /******************************************************************
898 * WCUSER_GetCtrlKeyState
900 * Get the console bit mask equivalent to the VK_ status in keyState
902 static DWORD
WCUSER_GetCtrlKeyState(BYTE
* keyState
)
906 GetKeyboardState(keyState
);
907 if (keyState
[VK_SHIFT
] & 0x80) ret
|= SHIFT_PRESSED
;
908 if (keyState
[VK_LCONTROL
] & 0x80) ret
|= LEFT_CTRL_PRESSED
;
909 if (keyState
[VK_RCONTROL
] & 0x80) ret
|= RIGHT_CTRL_PRESSED
;
910 if (keyState
[VK_LMENU
] & 0x80) ret
|= LEFT_ALT_PRESSED
;
911 if (keyState
[VK_RMENU
] & 0x80) ret
|= RIGHT_ALT_PRESSED
;
912 if (keyState
[VK_CAPITAL
] & 0x01) ret
|= CAPSLOCK_ON
;
913 if (keyState
[VK_NUMLOCK
] & 0x01) ret
|= NUMLOCK_ON
;
914 if (keyState
[VK_SCROLL
] & 0x01) ret
|= SCROLLLOCK_ON
;
919 /******************************************************************
920 * WCUSER_HandleSelectionKey
922 * Handles keys while selecting an area
924 static void WCUSER_HandleSelectionKey(struct inner_data
* data
, BOOL down
,
925 WPARAM wParam
, LPARAM lParam
)
928 DWORD state
= WCUSER_GetCtrlKeyState(keyState
) & ~(CAPSLOCK_ON
|NUMLOCK_ON
|SCROLLLOCK_ON
);
939 PRIVATE(data
)->has_selection
= FALSE
;
940 WCUSER_SetSelection(data
, 0);
941 WCUSER_CopySelectionToClipboard(data
);
944 c1
= PRIVATE(data
)->selectPt1
;
945 c2
= PRIVATE(data
)->selectPt2
;
947 WCUSER_MoveSelection(data
, c1
, c2
);
950 c1
= PRIVATE(data
)->selectPt1
;
951 c2
= PRIVATE(data
)->selectPt2
;
953 WCUSER_MoveSelection(data
, c1
, c2
);
956 c1
= PRIVATE(data
)->selectPt1
;
957 c2
= PRIVATE(data
)->selectPt2
;
959 WCUSER_MoveSelection(data
, c1
, c2
);
962 c1
= PRIVATE(data
)->selectPt1
;
963 c2
= PRIVATE(data
)->selectPt2
;
965 WCUSER_MoveSelection(data
, c1
, c2
);
973 c1
= PRIVATE(data
)->selectPt1
;
974 c2
= PRIVATE(data
)->selectPt2
;
976 WCUSER_MoveSelection(data
, c1
, c2
);
979 c1
= PRIVATE(data
)->selectPt1
;
980 c2
= PRIVATE(data
)->selectPt2
;
982 WCUSER_MoveSelection(data
, c1
, c2
);
985 c1
= PRIVATE(data
)->selectPt1
;
986 c2
= PRIVATE(data
)->selectPt2
;
988 WCUSER_MoveSelection(data
, c1
, c2
);
991 c1
= PRIVATE(data
)->selectPt1
;
992 c2
= PRIVATE(data
)->selectPt2
;
994 WCUSER_MoveSelection(data
, c1
, c2
);
1000 if (wParam
< VK_SPACE
) /* Shift, Alt, Ctrl, Num Lock etc. */
1003 WCUSER_SetSelection(data
, 0);
1004 PRIVATE(data
)->has_selection
= FALSE
;
1007 /******************************************************************
1008 * WCUSER_GenerateKeyInputRecord
1010 * generates input_record from windows WM_KEYUP/WM_KEYDOWN messages
1012 static void WCUSER_GenerateKeyInputRecord(struct inner_data
* data
, BOOL down
,
1013 WPARAM wParam
, LPARAM lParam
)
1018 static WCHAR last
; /* keep last char seen as feed for key up message */
1021 ir
.EventType
= KEY_EVENT
;
1022 ir
.Event
.KeyEvent
.bKeyDown
= down
;
1023 ir
.Event
.KeyEvent
.wRepeatCount
= LOWORD(lParam
);
1024 ir
.Event
.KeyEvent
.wVirtualKeyCode
= wParam
;
1026 ir
.Event
.KeyEvent
.wVirtualScanCode
= HIWORD(lParam
) & 0xFF;
1028 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
= 0;
1029 ir
.Event
.KeyEvent
.dwControlKeyState
= WCUSER_GetCtrlKeyState(keyState
);
1030 if (lParam
& (1L << 24)) ir
.Event
.KeyEvent
.dwControlKeyState
|= ENHANCED_KEY
;
1034 switch (ToUnicode(wParam
, HIWORD(lParam
), keyState
, buf
, 2, 0))
1037 /* FIXME... should generate two events... */
1047 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
= last
; /* FIXME: HACKY... and buggy because it should be a stack, not a single value */
1048 if (!down
) last
= 0;
1050 WriteConsoleInputW(data
->hConIn
, &ir
, 1, &n
);
1053 /******************************************************************
1054 * WCUSER_GenerateMouseInputRecord
1058 static void WCUSER_GenerateMouseInputRecord(struct inner_data
* data
, COORD c
,
1059 WPARAM wParam
, DWORD event
)
1065 /* MOUSE_EVENTs shouldn't be sent unless ENABLE_MOUSE_INPUT is active */
1066 if (!GetConsoleMode(data
->hConIn
, &mode
) || !(mode
& ENABLE_MOUSE_INPUT
))
1069 ir
.EventType
= MOUSE_EVENT
;
1070 ir
.Event
.MouseEvent
.dwMousePosition
= c
;
1071 ir
.Event
.MouseEvent
.dwButtonState
= 0;
1072 if (wParam
& MK_LBUTTON
) ir
.Event
.MouseEvent
.dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1073 if (wParam
& MK_MBUTTON
) ir
.Event
.MouseEvent
.dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1074 if (wParam
& MK_RBUTTON
) ir
.Event
.MouseEvent
.dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1075 if (wParam
& MK_CONTROL
) ir
.Event
.MouseEvent
.dwButtonState
|= LEFT_CTRL_PRESSED
;
1076 if (wParam
& MK_SHIFT
) ir
.Event
.MouseEvent
.dwButtonState
|= SHIFT_PRESSED
;
1077 if (event
== MOUSE_WHEELED
) ir
.Event
.MouseEvent
.dwButtonState
|= wParam
& 0xFFFF0000;
1078 ir
.Event
.MouseEvent
.dwControlKeyState
= WCUSER_GetCtrlKeyState(keyState
);
1079 ir
.Event
.MouseEvent
.dwEventFlags
= event
;
1081 WriteConsoleInputW(data
->hConIn
, &ir
, 1, &n
);
1084 /******************************************************************
1089 static LRESULT CALLBACK
WCUSER_Proc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1091 struct inner_data
* data
= (struct inner_data
*)GetWindowLongPtrW(hWnd
, 0);
1096 return WCUSER_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
1106 if (PRIVATE(data
)->has_selection
)
1107 WCUSER_HandleSelectionKey(data
, uMsg
== WM_KEYDOWN
, wParam
, lParam
);
1109 WCUSER_GenerateKeyInputRecord(data
, uMsg
== WM_KEYDOWN
, wParam
, lParam
);
1113 WCUSER_GenerateKeyInputRecord(data
, uMsg
== WM_SYSKEYDOWN
, wParam
, lParam
);
1115 case WM_LBUTTONDOWN
:
1116 if (data
->curcfg
.quick_edit
|| PRIVATE(data
)->has_selection
)
1118 if (PRIVATE(data
)->has_selection
)
1119 WCUSER_SetSelection(data
, 0);
1121 if (data
->curcfg
.quick_edit
&& PRIVATE(data
)->has_selection
)
1123 PRIVATE(data
)->has_selection
= FALSE
;
1127 PRIVATE(data
)->selectPt1
= PRIVATE(data
)->selectPt2
= WCUSER_GetCell(data
, lParam
);
1128 SetCapture(data
->hWnd
);
1129 WCUSER_SetSelection(data
, 0);
1130 PRIVATE(data
)->has_selection
= TRUE
;
1135 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1139 if (data
->curcfg
.quick_edit
|| PRIVATE(data
)->has_selection
)
1141 if (GetCapture() == data
->hWnd
&& PRIVATE(data
)->has_selection
&&
1142 (wParam
& MK_LBUTTON
))
1144 WCUSER_MoveSelection(data
, PRIVATE(data
)->selectPt1
, WCUSER_GetCell(data
, lParam
));
1149 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, MOUSE_MOVED
);
1153 if (data
->curcfg
.quick_edit
|| PRIVATE(data
)->has_selection
)
1155 if (GetCapture() == data
->hWnd
&& PRIVATE(data
)->has_selection
)
1157 WCUSER_MoveSelection(data
, PRIVATE(data
)->selectPt1
, WCUSER_GetCell(data
, lParam
));
1163 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1166 case WM_RBUTTONDOWN
:
1167 if ((wParam
& (MK_CONTROL
|MK_SHIFT
)) == data
->curcfg
.menu_mask
)
1171 pt
.x
= (short)LOWORD(lParam
);
1172 pt
.y
= (short)HIWORD(lParam
);
1173 ClientToScreen(hWnd
, &pt
);
1174 WCUSER_SetMenuDetails(data
, PRIVATE(data
)->hPopMenu
);
1175 TrackPopupMenu(PRIVATE(data
)->hPopMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_RIGHTBUTTON
,
1176 pt
.x
, pt
.y
, 0, hWnd
, NULL
);
1180 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1184 /* no need to track for rbutton up when opening the popup... the event will be
1185 * swallowed by TrackPopupMenu */
1186 case WM_MBUTTONDOWN
:
1188 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1190 case WM_LBUTTONDBLCLK
:
1191 case WM_MBUTTONDBLCLK
:
1192 case WM_RBUTTONDBLCLK
:
1193 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, DOUBLE_CLICK
);
1196 if (data
->curcfg
.cursor_visible
)
1198 CreateCaret(data
->hWnd
, PRIVATE(data
)->cursor_bitmap
,
1199 data
->curcfg
.cell_width
, data
->curcfg
.cell_height
);
1200 WCUSER_PosCursor(data
);
1204 if (data
->curcfg
.cursor_visible
)
1209 struct config_data cfg
= data
->curcfg
;
1211 switch (LOWORD(wParam
))
1213 case SB_PAGEUP
: cfg
.win_pos
.X
-= 8; break;
1214 case SB_PAGEDOWN
: cfg
.win_pos
.X
+= 8; break;
1215 case SB_LINEUP
: cfg
.win_pos
.X
--; break;
1216 case SB_LINEDOWN
: cfg
.win_pos
.X
++; break;
1217 case SB_THUMBTRACK
: cfg
.win_pos
.X
= HIWORD(wParam
); break;
1220 if (cfg
.win_pos
.X
< 0) cfg
.win_pos
.X
= 0;
1221 if (cfg
.win_pos
.X
> data
->curcfg
.sb_width
- data
->curcfg
.win_width
)
1222 cfg
.win_pos
.X
= data
->curcfg
.sb_width
- data
->curcfg
.win_width
;
1223 if (cfg
.win_pos
.X
!= data
->curcfg
.win_pos
.X
)
1225 WINECON_SetConfig(data
, &cfg
);
1230 if (data
->curcfg
.sb_height
<= data
->curcfg
.win_height
)
1232 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, MOUSE_WHEELED
);
1235 /* else fallthrough */
1238 struct config_data cfg
= data
->curcfg
;
1240 if (uMsg
== WM_MOUSEWHEEL
)
1242 UINT scrollLines
= 3;
1243 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &scrollLines
, 0);
1244 scrollLines
*= -GET_WHEEL_DELTA_WPARAM(wParam
) / WHEEL_DELTA
;
1245 cfg
.win_pos
.Y
+= scrollLines
;
1247 switch (LOWORD(wParam
))
1249 case SB_PAGEUP
: cfg
.win_pos
.Y
-= 8; break;
1250 case SB_PAGEDOWN
: cfg
.win_pos
.Y
+= 8; break;
1251 case SB_LINEUP
: cfg
.win_pos
.Y
--; break;
1252 case SB_LINEDOWN
: cfg
.win_pos
.Y
++; break;
1253 case SB_THUMBTRACK
: cfg
.win_pos
.Y
= HIWORD(wParam
); break;
1258 if (cfg
.win_pos
.Y
< 0) cfg
.win_pos
.Y
= 0;
1259 if (cfg
.win_pos
.Y
> data
->curcfg
.sb_height
- data
->curcfg
.win_height
)
1260 cfg
.win_pos
.Y
= data
->curcfg
.sb_height
- data
->curcfg
.win_height
;
1261 if (cfg
.win_pos
.Y
!= data
->curcfg
.win_pos
.Y
)
1263 WINECON_SetConfig(data
, &cfg
);
1271 WCUSER_GetProperties(data
, FALSE
);
1273 case IDS_PROPERTIES
:
1274 WCUSER_GetProperties(data
, TRUE
);
1277 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1284 WCUSER_GetProperties(data
, FALSE
);
1286 case IDS_PROPERTIES
:
1287 WCUSER_GetProperties(data
, TRUE
);
1290 PRIVATE(data
)->selectPt1
.X
= PRIVATE(data
)->selectPt1
.Y
= 0;
1291 PRIVATE(data
)->selectPt2
.X
= PRIVATE(data
)->selectPt2
.Y
= 0;
1292 WCUSER_SetSelection(data
, 0);
1293 PRIVATE(data
)->has_selection
= TRUE
;
1296 if (PRIVATE(data
)->has_selection
)
1298 PRIVATE(data
)->has_selection
= FALSE
;
1299 WCUSER_SetSelection(data
, 0);
1300 WCUSER_CopySelectionToClipboard(data
);
1304 WCUSER_PasteFromClipboard(data
);
1307 PRIVATE(data
)->selectPt1
.X
= PRIVATE(data
)->selectPt1
.Y
= 0;
1308 PRIVATE(data
)->selectPt2
.X
= (data
->curcfg
.sb_width
- 1) * data
->curcfg
.cell_width
;
1309 PRIVATE(data
)->selectPt2
.Y
= (data
->curcfg
.sb_height
- 1) * data
->curcfg
.cell_height
;
1310 WCUSER_SetSelection(data
, 0);
1311 PRIVATE(data
)->has_selection
= TRUE
;
1315 WINE_FIXME("Unhandled yet command: %lx\n", wParam
);
1318 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1321 case WM_INITMENUPOPUP
:
1322 if (!HIWORD(lParam
)) return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1323 WCUSER_SetMenuDetails(data
, GetSystemMenu(data
->hWnd
, FALSE
));
1326 WINECON_ResizeWithContainer(data
, LOWORD(lParam
) / data
->curcfg
.cell_width
,
1327 HIWORD(lParam
) / data
->curcfg
.cell_height
);
1330 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1335 /******************************************************************
1336 * WCUSER_DeleteBackend
1340 static void WCUSER_DeleteBackend(struct inner_data
* data
)
1342 if (!PRIVATE(data
)) return;
1343 if (PRIVATE(data
)->hMemDC
) DeleteDC(PRIVATE(data
)->hMemDC
);
1344 if (data
->hWnd
) DestroyWindow(data
->hWnd
);
1345 if (PRIVATE(data
)->hFont
) DeleteObject(PRIVATE(data
)->hFont
);
1346 if (PRIVATE(data
)->cursor_bitmap
) DeleteObject(PRIVATE(data
)->cursor_bitmap
);
1347 if (PRIVATE(data
)->hBitmap
) DeleteObject(PRIVATE(data
)->hBitmap
);
1348 HeapFree(GetProcessHeap(), 0, PRIVATE(data
));
1351 /******************************************************************
1356 static int WCUSER_MainLoop(struct inner_data
* data
)
1360 ShowWindow(data
->hWnd
, data
->nCmdShow
);
1361 while (!data
->dying
|| !data
->curcfg
.exit_on_die
)
1363 switch (MsgWaitForMultipleObjects(1, &data
->hSynchro
, FALSE
, INFINITE
, QS_ALLINPUT
))
1366 WINECON_GrabChanges(data
);
1368 case WAIT_OBJECT_0
+1:
1369 /* need to use PeekMessageW loop instead of simple GetMessage:
1370 * multiple messages might have arrived in between,
1371 * so GetMessage would lead to delayed processing */
1372 while (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
))
1374 if (msg
.message
== WM_QUIT
) return 1;
1375 WINE_TRACE("dispatching msg %04x\n", msg
.message
);
1376 DispatchMessageW(&msg
);
1380 WINE_ERR("got pb\n");
1389 /******************************************************************
1390 * WCUSER_InitBackend
1392 * Initialisation part II: creation of window.
1395 enum init_return
WCUSER_InitBackend(struct inner_data
* data
)
1397 static const WCHAR wClassName
[] = {'W','i','n','e','C','o','n','s','o','l','e','C','l','a','s','s',0};
1402 if (!TranslateCharsetInfo((DWORD
*)(INT_PTR
)GetACP(), &ci
, TCI_SRCCODEPAGE
))
1404 g_uiDefaultCharset
= ci
.ciCharset
;
1405 WINE_TRACE_(wc_font
)("Code page %d => Default charset: %d\n", GetACP(), g_uiDefaultCharset
);
1407 data
->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct inner_data_user
));
1408 if (!data
->private) return init_failed
;
1410 data
->fnMainLoop
= WCUSER_MainLoop
;
1411 data
->fnPosCursor
= WCUSER_PosCursor
;
1412 data
->fnShapeCursor
= WCUSER_ShapeCursor
;
1413 data
->fnComputePositions
= WCUSER_ComputePositions
;
1414 data
->fnRefresh
= WCUSER_Refresh
;
1415 data
->fnResizeScreenBuffer
= WCUSER_ResizeScreenBuffer
;
1416 data
->fnSetTitle
= WCUSER_SetTitle
;
1417 data
->fnSetFont
= WCUSER_SetFontPmt
;
1418 data
->fnScroll
= WCUSER_Scroll
;
1419 data
->fnDeleteBackend
= WCUSER_DeleteBackend
;
1421 wndclass
.style
= CS_DBLCLKS
;
1422 wndclass
.lpfnWndProc
= WCUSER_Proc
;
1423 wndclass
.cbClsExtra
= 0;
1424 wndclass
.cbWndExtra
= sizeof(DWORD_PTR
);
1425 wndclass
.hInstance
= GetModuleHandleW(NULL
);
1426 wndclass
.hIcon
= LoadIconW(0, (LPCWSTR
)IDI_WINLOGO
);
1427 wndclass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
1428 wndclass
.hbrBackground
= GetStockObject(BLACK_BRUSH
);
1429 wndclass
.lpszMenuName
= NULL
;
1430 wndclass
.lpszClassName
= wClassName
;
1432 RegisterClassW(&wndclass
);
1434 data
->hWnd
= CreateWindowW(wndclass
.lpszClassName
, NULL
,
1435 WS_OVERLAPPED
|WS_CAPTION
|WS_SYSMENU
|WS_THICKFRAME
|WS_MINIMIZEBOX
|WS_HSCROLL
|WS_VSCROLL
,
1436 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0, 0, wndclass
.hInstance
, data
);
1437 if (!data
->hWnd
) return init_not_supported
;
1439 return init_success
;