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
) return FALSE
;
344 if (type
& RASTER_FONTTYPE
)
346 if (tm
->tmMaxCharWidth
* data
->curcfg
.win_width
>= GetSystemMetrics(SM_CXSCREEN
) ||
347 tm
->tmHeight
* data
->curcfg
.win_height
>= GetSystemMetrics(SM_CYSCREEN
))
352 if (tm
->tmCharSet
!= DEFAULT_CHARSET
&& tm
->tmCharSet
!= g_uiDefaultCharset
) return FALSE
;
355 if (tm
->tmItalic
|| tm
->tmUnderlined
|| tm
->tmStruckOut
) return FALSE
;
361 /******************************************************************
362 * WCUSER_ValidateFont
364 * Returns true if the font family described in lf is usable as a font for the renderer
366 BOOL
WCUSER_ValidateFont(const struct inner_data
* data
, const LOGFONTW
* lf
, int pass
)
368 switch (pass
) /* we get increasingly lenient in later passes */
373 if (lf
->lfCharSet
!= DEFAULT_CHARSET
&& lf
->lfCharSet
!= g_uiDefaultCharset
) return FALSE
;
376 if ((lf
->lfPitchAndFamily
& 3) != FIXED_PITCH
) return FALSE
;
379 if (lf
->lfFaceName
[0] == '@') return FALSE
;
385 /******************************************************************
386 * get_first_font_enum_2
387 * get_first_font_enum
389 * Helper functions to get a decent font for the renderer
391 static int CALLBACK
get_first_font_enum_2(const LOGFONTW
* lf
, const TEXTMETRICW
* tm
,
392 DWORD FontType
, LPARAM lParam
)
394 struct font_chooser
* fc
= (struct font_chooser
*)lParam
;
396 WCUSER_DumpTextMetric(tm
, FontType
);
397 if (WCUSER_ValidateFontMetric(fc
->data
, tm
, FontType
, fc
->pass
))
401 /* Use the default sizes for the font (this is needed, especially for
402 * TrueType fonts, so that we get a decent size, not the max size)
404 mlf
.lfWidth
= fc
->data
->curcfg
.cell_width
;
405 mlf
.lfHeight
= fc
->data
->curcfg
.cell_height
;
406 if (WCUSER_SetFont(fc
->data
, &mlf
))
408 struct config_data defcfg
;
410 WCUSER_DumpLogFont("InitChoosing: ", &mlf
, FontType
);
412 /* since we've modified the current config with new font information,
413 * set this information as the new default.
415 WINECON_RegLoad(NULL
, &defcfg
);
416 defcfg
.cell_width
= fc
->data
->curcfg
.cell_width
;
417 defcfg
.cell_height
= fc
->data
->curcfg
.cell_height
;
418 lstrcpyW(defcfg
.face_name
, fc
->data
->curcfg
.face_name
);
419 /* Force also its writing back to the registry so that we can get it
422 WINECON_RegSave(&defcfg
);
429 static int CALLBACK
get_first_font_enum(const LOGFONTW
* lf
, const TEXTMETRICW
* tm
,
430 DWORD FontType
, LPARAM lParam
)
432 struct font_chooser
* fc
= (struct font_chooser
*)lParam
;
434 WCUSER_DumpLogFont("InitFamily: ", lf
, FontType
);
435 if (WCUSER_ValidateFont(fc
->data
, lf
, fc
->pass
))
437 EnumFontFamiliesW(PRIVATE(fc
->data
)->hMemDC
, lf
->lfFaceName
,
438 get_first_font_enum_2
, lParam
);
439 return !fc
->done
; /* we just need the first matching one... */
444 /******************************************************************
447 * get the relevant information from the font described in lf and store them
450 HFONT
WCUSER_CopyFont(struct config_data
* config
, HWND hWnd
, const LOGFONTW
* lf
, LONG
* el
)
454 HFONT hFont
, hOldFont
;
457 if (!(hDC
= GetDC(hWnd
))) return NULL
;
458 if (!(hFont
= CreateFontIndirectW(lf
)))
460 ReleaseDC(hWnd
, hDC
);
463 hOldFont
= SelectObject(hDC
, hFont
);
464 GetTextMetricsW(hDC
, &tm
);
465 SelectObject(hDC
, hOldFont
);
466 ReleaseDC(hWnd
, hDC
);
468 config
->cell_width
= tm
.tmAveCharWidth
;
469 config
->cell_height
= tm
.tmHeight
+ tm
.tmExternalLeading
;
470 config
->font_weight
= tm
.tmWeight
;
471 lstrcpyW(config
->face_name
, lf
->lfFaceName
);
472 if (el
) *el
= tm
.tmExternalLeading
;
474 /* FIXME: use maximum width for DBCS codepages since some chars take two cells */
475 if (GetCPInfo( GetConsoleOutputCP(), &cpinfo
) && cpinfo
.MaxCharSize
> 1)
476 config
->cell_width
= tm
.tmMaxCharWidth
;
481 /******************************************************************
486 void WCUSER_FillLogFont(LOGFONTW
* lf
, const WCHAR
* name
, UINT height
, UINT weight
)
488 lf
->lfHeight
= height
;
490 lf
->lfEscapement
= 0;
491 lf
->lfOrientation
= 0;
492 lf
->lfWeight
= weight
;
493 lf
->lfItalic
= FALSE
;
494 lf
->lfUnderline
= FALSE
;
495 lf
->lfStrikeOut
= FALSE
;
496 lf
->lfCharSet
= DEFAULT_CHARSET
;
497 lf
->lfOutPrecision
= OUT_DEFAULT_PRECIS
;
498 lf
->lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
499 lf
->lfQuality
= DEFAULT_QUALITY
;
500 lf
->lfPitchAndFamily
= FIXED_PITCH
| FF_DONTCARE
;
501 lstrcpyW(lf
->lfFaceName
, name
);
504 /******************************************************************
507 * sets logfont as the new font for the console
509 BOOL
WCUSER_SetFont(struct inner_data
* data
, const LOGFONTW
* logfont
)
514 if (PRIVATE(data
)->hFont
!= 0 && WCUSER_AreFontsEqual(&data
->curcfg
, logfont
))
517 hFont
= WCUSER_CopyFont(&data
->curcfg
, data
->hWnd
, logfont
, &el
);
518 if (!hFont
) {WINE_ERR("wrong font\n"); return FALSE
;}
520 if (PRIVATE(data
)->hFont
) DeleteObject(PRIVATE(data
)->hFont
);
521 PRIVATE(data
)->hFont
= hFont
;
522 PRIVATE(data
)->ext_leading
= el
;
524 WCUSER_ComputePositions(data
);
525 WCUSER_NewBitmap(data
);
526 InvalidateRect(data
->hWnd
, NULL
, FALSE
);
527 UpdateWindow(data
->hWnd
);
532 /******************************************************************
535 * Sets a new font for the console.
536 * In fact a wrapper for WCUSER_SetFont
538 static void WCUSER_SetFontPmt(struct inner_data
* data
, const WCHAR
* font
,
539 unsigned height
, unsigned weight
)
542 struct font_chooser fc
;
544 WINE_TRACE_(wc_font
)("=> %s h=%u w=%u\n",
545 wine_dbgstr_wn(font
, -1), height
, weight
);
547 if (font
[0] != '\0' && height
!= 0 && weight
!= 0)
549 WCUSER_FillLogFont(&lf
, font
, height
, weight
);
550 if (WCUSER_SetFont(data
, &lf
))
552 WCUSER_DumpLogFont("InitReuses: ", &lf
, 0);
557 /* try to find an acceptable font */
558 WINE_WARN("Couldn't match the font from registry... trying to find one\n");
561 for (fc
.pass
= 0; fc
.pass
<= 5; fc
.pass
++)
563 EnumFontFamiliesW(PRIVATE(data
)->hMemDC
, NULL
, get_first_font_enum
, (LPARAM
)&fc
);
566 WINECON_Fatal("Couldn't find a decent font, aborting");
569 /******************************************************************
572 * Get a cell from a relative coordinate in window (takes into
573 * account the scrolling)
575 static COORD
WCUSER_GetCell(const struct inner_data
* data
, LPARAM lParam
)
579 c
.X
= data
->curcfg
.win_pos
.X
+ (short)LOWORD(lParam
) / data
->curcfg
.cell_width
;
580 c
.Y
= data
->curcfg
.win_pos
.Y
+ (short)HIWORD(lParam
) / data
->curcfg
.cell_height
;
585 /******************************************************************
586 * WCUSER_GetSelectionRect
588 * Get the selection rectangle
590 static void WCUSER_GetSelectionRect(const struct inner_data
* data
, LPRECT r
)
592 r
->left
= (min(PRIVATE(data
)->selectPt1
.X
, PRIVATE(data
)->selectPt2
.X
) - data
->curcfg
.win_pos
.X
) * data
->curcfg
.cell_width
;
593 r
->top
= (min(PRIVATE(data
)->selectPt1
.Y
, PRIVATE(data
)->selectPt2
.Y
) - data
->curcfg
.win_pos
.Y
) * data
->curcfg
.cell_height
;
594 r
->right
= (max(PRIVATE(data
)->selectPt1
.X
, PRIVATE(data
)->selectPt2
.X
) + 1 - data
->curcfg
.win_pos
.X
) * data
->curcfg
.cell_width
;
595 r
->bottom
= (max(PRIVATE(data
)->selectPt1
.Y
, PRIVATE(data
)->selectPt2
.Y
) + 1 - data
->curcfg
.win_pos
.Y
) * data
->curcfg
.cell_height
;
598 /******************************************************************
599 * WCUSER_SetSelection
603 static void WCUSER_SetSelection(const struct inner_data
* data
, HDC hRefDC
)
608 WCUSER_GetSelectionRect(data
, &r
);
609 hDC
= hRefDC
? hRefDC
: GetDC(data
->hWnd
);
612 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
613 HideCaret(data
->hWnd
);
616 ReleaseDC(data
->hWnd
, hDC
);
617 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
618 ShowCaret(data
->hWnd
);
622 /******************************************************************
623 * WCUSER_MoveSelection
627 static void WCUSER_MoveSelection(struct inner_data
* data
, COORD c1
, COORD c2
)
632 if (c1
.X
< 0 || c1
.X
>= data
->curcfg
.sb_width
||
633 c2
.X
< 0 || c2
.X
>= data
->curcfg
.sb_width
||
634 c1
.Y
< 0 || c1
.Y
>= data
->curcfg
.sb_height
||
635 c2
.Y
< 0 || c2
.Y
>= data
->curcfg
.sb_height
)
638 WCUSER_GetSelectionRect(data
, &r
);
639 hDC
= GetDC(data
->hWnd
);
642 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
643 HideCaret(data
->hWnd
);
646 PRIVATE(data
)->selectPt1
= c1
;
647 PRIVATE(data
)->selectPt2
= c2
;
650 WCUSER_GetSelectionRect(data
, &r
);
652 ReleaseDC(data
->hWnd
, hDC
);
653 if (data
->hWnd
== GetFocus() && data
->curcfg
.cursor_visible
)
654 ShowCaret(data
->hWnd
);
658 /******************************************************************
659 * WCUSER_CopySelectionToClipboard
661 * Copies the current selection into the clipboard
663 static void WCUSER_CopySelectionToClipboard(const struct inner_data
* data
)
669 w
= abs(PRIVATE(data
)->selectPt1
.X
- PRIVATE(data
)->selectPt2
.X
) + 2;
670 h
= abs(PRIVATE(data
)->selectPt1
.Y
- PRIVATE(data
)->selectPt2
.Y
) + 1;
672 if (!OpenClipboard(data
->hWnd
)) return;
675 hMem
= GlobalAlloc(GMEM_MOVEABLE
, (w
* h
) * sizeof(WCHAR
));
676 if (hMem
&& (p
= GlobalLock(hMem
)))
681 c
.X
= min(PRIVATE(data
)->selectPt1
.X
, PRIVATE(data
)->selectPt2
.X
);
682 c
.Y
= min(PRIVATE(data
)->selectPt1
.Y
, PRIVATE(data
)->selectPt2
.Y
);
684 for (y
= 0; y
< h
; y
++, c
.Y
++)
689 ReadConsoleOutputCharacterW(data
->hConOut
, p
, w
- 1, c
, &count
);
691 /* strip spaces from the end of the line */
693 while (end
> p
&& *(end
- 1) == ' ')
695 *end
= (y
< h
- 1) ? '\n' : '\0';
699 SetClipboardData(CF_UNICODETEXT
, hMem
);
704 /******************************************************************
705 * WCUSER_PasteFromClipboard
709 static void WCUSER_PasteFromClipboard(struct inner_data
* data
)
714 if (!OpenClipboard(data
->hWnd
)) return;
715 h
= GetClipboardData(CF_UNICODETEXT
);
716 if (h
&& (ptr
= GlobalLock(h
)))
718 int i
, len
= GlobalSize(h
) / sizeof(WCHAR
);
723 ir
[0].EventType
= KEY_EVENT
;
724 ir
[0].Event
.KeyEvent
.wRepeatCount
= 0;
725 ir
[0].Event
.KeyEvent
.dwControlKeyState
= 0;
726 ir
[0].Event
.KeyEvent
.bKeyDown
= TRUE
;
728 /* generate the corresponding input records */
729 for (i
= 0; i
< len
; i
++)
731 /* FIXME: the modifying keys are not generated (shift, ctrl...) */
732 sh
= VkKeyScanW(ptr
[i
]);
733 ir
[0].Event
.KeyEvent
.wVirtualKeyCode
= LOBYTE(sh
);
734 ir
[0].Event
.KeyEvent
.wVirtualScanCode
= MapVirtualKeyW(LOBYTE(sh
), 0);
735 ir
[0].Event
.KeyEvent
.uChar
.UnicodeChar
= ptr
[i
];
738 ir
[1].Event
.KeyEvent
.bKeyDown
= FALSE
;
740 WriteConsoleInputW(data
->hConIn
, ir
, 2, &n
);
747 /******************************************************************
752 static void WCUSER_Refresh(const struct inner_data
* data
, int tp
, int bm
)
754 WCUSER_FillMemDC(data
, tp
, bm
);
755 if (data
->curcfg
.win_pos
.Y
<= bm
&& data
->curcfg
.win_pos
.Y
+ data
->curcfg
.win_height
>= tp
)
760 r
.right
= data
->curcfg
.win_width
* data
->curcfg
.cell_width
;
761 r
.top
= (tp
- data
->curcfg
.win_pos
.Y
) * data
->curcfg
.cell_height
;
762 r
.bottom
= (bm
- data
->curcfg
.win_pos
.Y
+ 1) * data
->curcfg
.cell_height
;
763 InvalidateRect(data
->hWnd
, &r
, FALSE
);
764 UpdateWindow(data
->hWnd
);
768 /******************************************************************
773 static void WCUSER_Paint(const struct inner_data
* data
)
777 if (data
->in_set_config
) return; /* in order to avoid some flicker */
778 BeginPaint(data
->hWnd
, &ps
);
780 data
->curcfg
.win_width
* data
->curcfg
.cell_width
,
781 data
->curcfg
.win_height
* data
->curcfg
.cell_height
,
782 PRIVATE(data
)->hMemDC
,
783 data
->curcfg
.win_pos
.X
* data
->curcfg
.cell_width
,
784 data
->curcfg
.win_pos
.Y
* data
->curcfg
.cell_height
,
786 if (PRIVATE(data
)->has_selection
)
787 WCUSER_SetSelection(data
, ps
.hdc
);
788 EndPaint(data
->hWnd
, &ps
);
791 /******************************************************************
796 static void WCUSER_Scroll(struct inner_data
* data
, int pos
, BOOL horz
)
800 ScrollWindow(data
->hWnd
, (data
->curcfg
.win_pos
.X
- pos
) * data
->curcfg
.cell_width
, 0, NULL
, NULL
);
801 SetScrollPos(data
->hWnd
, SB_HORZ
, pos
, TRUE
);
802 data
->curcfg
.win_pos
.X
= pos
;
806 ScrollWindow(data
->hWnd
, 0, (data
->curcfg
.win_pos
.Y
- pos
) * data
->curcfg
.cell_height
, NULL
, NULL
);
807 SetScrollPos(data
->hWnd
, SB_VERT
, pos
, TRUE
);
808 data
->curcfg
.win_pos
.Y
= pos
;
810 InvalidateRect(data
->hWnd
, NULL
, FALSE
);
813 /******************************************************************
818 static BOOL
WCUSER_FillMenu(HMENU hMenu
, BOOL sep
)
821 HINSTANCE hInstance
= GetModuleHandleW(NULL
);
824 if (!hMenu
) return FALSE
;
826 /* FIXME: error handling & memory cleanup */
827 hSubMenu
= CreateMenu();
828 if (!hSubMenu
) return FALSE
;
830 LoadStringW(hInstance
, IDS_MARK
, buff
, ARRAY_SIZE(buff
));
831 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_MARK
, buff
);
832 LoadStringW(hInstance
, IDS_COPY
, buff
, ARRAY_SIZE(buff
));
833 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_COPY
, buff
);
834 LoadStringW(hInstance
, IDS_PASTE
, buff
, ARRAY_SIZE(buff
));
835 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_PASTE
, buff
);
836 LoadStringW(hInstance
, IDS_SELECTALL
, buff
, ARRAY_SIZE(buff
));
837 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_SELECTALL
, buff
);
838 LoadStringW(hInstance
, IDS_SCROLL
, buff
, ARRAY_SIZE(buff
));
839 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_SCROLL
, buff
);
840 LoadStringW(hInstance
, IDS_SEARCH
, buff
, ARRAY_SIZE(buff
));
841 InsertMenuW(hSubMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_SEARCH
, buff
);
843 if (sep
) InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_SEPARATOR
, 0, NULL
);
844 LoadStringW(hInstance
, IDS_EDIT
, buff
, ARRAY_SIZE(buff
));
845 InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_STRING
|MF_POPUP
, (UINT_PTR
)hSubMenu
, buff
);
846 LoadStringW(hInstance
, IDS_DEFAULT
, buff
, ARRAY_SIZE(buff
));
847 InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_DEFAULT
, buff
);
848 LoadStringW(hInstance
, IDS_PROPERTIES
, buff
, ARRAY_SIZE(buff
));
849 InsertMenuW(hMenu
, -1, MF_BYPOSITION
|MF_STRING
, IDS_PROPERTIES
, buff
);
854 /******************************************************************
855 * WCUSER_SetMenuDetails
857 * Grays / ungrays the menu items according to their state
859 static void WCUSER_SetMenuDetails(const struct inner_data
* data
, HMENU hMenu
)
861 if (!hMenu
) {WINE_ERR("Issue in getting menu bits\n");return;}
863 EnableMenuItem(hMenu
, IDS_COPY
,
864 MF_BYCOMMAND
|(PRIVATE(data
)->has_selection
? MF_ENABLED
: MF_GRAYED
));
865 EnableMenuItem(hMenu
, IDS_PASTE
,
866 MF_BYCOMMAND
|(IsClipboardFormatAvailable(CF_UNICODETEXT
)
867 ? MF_ENABLED
: MF_GRAYED
));
868 EnableMenuItem(hMenu
, IDS_SCROLL
, MF_BYCOMMAND
|MF_GRAYED
);
869 EnableMenuItem(hMenu
, IDS_SEARCH
, MF_BYCOMMAND
|MF_GRAYED
);
872 /******************************************************************
875 * Creates the window for the rendering
877 static LRESULT
WCUSER_Create(HWND hWnd
, LPCREATESTRUCTW lpcs
)
879 struct inner_data
* data
;
882 data
= lpcs
->lpCreateParams
;
883 SetWindowLongPtrW(hWnd
, 0, (DWORD_PTR
)data
);
886 hSysMenu
= GetSystemMenu(hWnd
, FALSE
);
887 if (!hSysMenu
) return 0;
888 PRIVATE(data
)->hPopMenu
= CreatePopupMenu();
889 if (!PRIVATE(data
)->hPopMenu
) return 0;
891 WCUSER_FillMenu(hSysMenu
, TRUE
);
892 WCUSER_FillMenu(PRIVATE(data
)->hPopMenu
, FALSE
);
894 PRIVATE(data
)->hMemDC
= CreateCompatibleDC(0);
895 if (!PRIVATE(data
)->hMemDC
) {WINE_ERR("no mem dc\n");return 0;}
897 data
->curcfg
.quick_edit
= FALSE
;
901 /******************************************************************
902 * WCUSER_GetCtrlKeyState
904 * Get the console bit mask equivalent to the VK_ status in keyState
906 static DWORD
WCUSER_GetCtrlKeyState(BYTE
* keyState
)
910 GetKeyboardState(keyState
);
911 if (keyState
[VK_SHIFT
] & 0x80) ret
|= SHIFT_PRESSED
;
912 if (keyState
[VK_LCONTROL
] & 0x80) ret
|= LEFT_CTRL_PRESSED
;
913 if (keyState
[VK_RCONTROL
] & 0x80) ret
|= RIGHT_CTRL_PRESSED
;
914 if (keyState
[VK_LMENU
] & 0x80) ret
|= LEFT_ALT_PRESSED
;
915 if (keyState
[VK_RMENU
] & 0x80) ret
|= RIGHT_ALT_PRESSED
;
916 if (keyState
[VK_CAPITAL
] & 0x01) ret
|= CAPSLOCK_ON
;
917 if (keyState
[VK_NUMLOCK
] & 0x01) ret
|= NUMLOCK_ON
;
918 if (keyState
[VK_SCROLL
] & 0x01) ret
|= SCROLLLOCK_ON
;
923 /******************************************************************
924 * WCUSER_HandleSelectionKey
926 * Handles keys while selecting an area
928 static void WCUSER_HandleSelectionKey(struct inner_data
* data
, BOOL down
,
929 WPARAM wParam
, LPARAM lParam
)
932 DWORD state
= WCUSER_GetCtrlKeyState(keyState
) & ~(CAPSLOCK_ON
|NUMLOCK_ON
|SCROLLLOCK_ON
);
943 PRIVATE(data
)->has_selection
= FALSE
;
944 WCUSER_SetSelection(data
, 0);
945 WCUSER_CopySelectionToClipboard(data
);
948 c1
= PRIVATE(data
)->selectPt1
;
949 c2
= PRIVATE(data
)->selectPt2
;
951 WCUSER_MoveSelection(data
, c1
, c2
);
954 c1
= PRIVATE(data
)->selectPt1
;
955 c2
= PRIVATE(data
)->selectPt2
;
957 WCUSER_MoveSelection(data
, c1
, c2
);
960 c1
= PRIVATE(data
)->selectPt1
;
961 c2
= PRIVATE(data
)->selectPt2
;
963 WCUSER_MoveSelection(data
, c1
, c2
);
966 c1
= PRIVATE(data
)->selectPt1
;
967 c2
= PRIVATE(data
)->selectPt2
;
969 WCUSER_MoveSelection(data
, c1
, c2
);
977 c1
= PRIVATE(data
)->selectPt1
;
978 c2
= PRIVATE(data
)->selectPt2
;
980 WCUSER_MoveSelection(data
, c1
, c2
);
983 c1
= PRIVATE(data
)->selectPt1
;
984 c2
= PRIVATE(data
)->selectPt2
;
986 WCUSER_MoveSelection(data
, c1
, c2
);
989 c1
= PRIVATE(data
)->selectPt1
;
990 c2
= PRIVATE(data
)->selectPt2
;
992 WCUSER_MoveSelection(data
, c1
, c2
);
995 c1
= PRIVATE(data
)->selectPt1
;
996 c2
= PRIVATE(data
)->selectPt2
;
998 WCUSER_MoveSelection(data
, c1
, c2
);
1004 if (wParam
< VK_SPACE
) /* Shift, Alt, Ctrl, Num Lock etc. */
1007 WCUSER_SetSelection(data
, 0);
1008 PRIVATE(data
)->has_selection
= FALSE
;
1011 /******************************************************************
1012 * WCUSER_GenerateKeyInputRecord
1014 * generates input_record from windows WM_KEYUP/WM_KEYDOWN messages
1016 static void WCUSER_GenerateKeyInputRecord(struct inner_data
* data
, BOOL down
,
1017 WPARAM wParam
, LPARAM lParam
)
1022 static WCHAR last
; /* keep last char seen as feed for key up message */
1025 ir
.EventType
= KEY_EVENT
;
1026 ir
.Event
.KeyEvent
.bKeyDown
= down
;
1027 ir
.Event
.KeyEvent
.wRepeatCount
= LOWORD(lParam
);
1028 ir
.Event
.KeyEvent
.wVirtualKeyCode
= wParam
;
1030 ir
.Event
.KeyEvent
.wVirtualScanCode
= HIWORD(lParam
) & 0xFF;
1032 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
= 0;
1033 ir
.Event
.KeyEvent
.dwControlKeyState
= WCUSER_GetCtrlKeyState(keyState
);
1034 if (lParam
& (1L << 24)) ir
.Event
.KeyEvent
.dwControlKeyState
|= ENHANCED_KEY
;
1038 switch (ToUnicode(wParam
, HIWORD(lParam
), keyState
, buf
, 2, 0))
1041 /* FIXME... should generate two events... */
1051 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
= last
; /* FIXME: HACKY... and buggy because it should be a stack, not a single value */
1052 if (!down
) last
= 0;
1054 WriteConsoleInputW(data
->hConIn
, &ir
, 1, &n
);
1057 /******************************************************************
1058 * WCUSER_GenerateMouseInputRecord
1062 static void WCUSER_GenerateMouseInputRecord(struct inner_data
* data
, COORD c
,
1063 WPARAM wParam
, DWORD event
)
1069 /* MOUSE_EVENTs shouldn't be sent unless ENABLE_MOUSE_INPUT is active */
1070 if (!GetConsoleMode(data
->hConIn
, &mode
) || !(mode
& ENABLE_MOUSE_INPUT
))
1073 ir
.EventType
= MOUSE_EVENT
;
1074 ir
.Event
.MouseEvent
.dwMousePosition
= c
;
1075 ir
.Event
.MouseEvent
.dwButtonState
= 0;
1076 if (wParam
& MK_LBUTTON
) ir
.Event
.MouseEvent
.dwButtonState
|= FROM_LEFT_1ST_BUTTON_PRESSED
;
1077 if (wParam
& MK_MBUTTON
) ir
.Event
.MouseEvent
.dwButtonState
|= FROM_LEFT_2ND_BUTTON_PRESSED
;
1078 if (wParam
& MK_RBUTTON
) ir
.Event
.MouseEvent
.dwButtonState
|= RIGHTMOST_BUTTON_PRESSED
;
1079 if (wParam
& MK_CONTROL
) ir
.Event
.MouseEvent
.dwButtonState
|= LEFT_CTRL_PRESSED
;
1080 if (wParam
& MK_SHIFT
) ir
.Event
.MouseEvent
.dwButtonState
|= SHIFT_PRESSED
;
1081 if (event
== MOUSE_WHEELED
) ir
.Event
.MouseEvent
.dwButtonState
|= wParam
& 0xFFFF0000;
1082 ir
.Event
.MouseEvent
.dwControlKeyState
= WCUSER_GetCtrlKeyState(keyState
);
1083 ir
.Event
.MouseEvent
.dwEventFlags
= event
;
1085 WriteConsoleInputW(data
->hConIn
, &ir
, 1, &n
);
1088 /******************************************************************
1093 static LRESULT CALLBACK
WCUSER_Proc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1095 struct inner_data
* data
= (struct inner_data
*)GetWindowLongPtrW(hWnd
, 0);
1100 return WCUSER_Create(hWnd
, (LPCREATESTRUCTW
)lParam
);
1110 if (PRIVATE(data
)->has_selection
)
1111 WCUSER_HandleSelectionKey(data
, uMsg
== WM_KEYDOWN
, wParam
, lParam
);
1113 WCUSER_GenerateKeyInputRecord(data
, uMsg
== WM_KEYDOWN
, wParam
, lParam
);
1117 WCUSER_GenerateKeyInputRecord(data
, uMsg
== WM_SYSKEYDOWN
, wParam
, lParam
);
1119 case WM_LBUTTONDOWN
:
1120 if (data
->curcfg
.quick_edit
|| PRIVATE(data
)->has_selection
)
1122 if (PRIVATE(data
)->has_selection
)
1123 WCUSER_SetSelection(data
, 0);
1125 if (data
->curcfg
.quick_edit
&& PRIVATE(data
)->has_selection
)
1127 PRIVATE(data
)->has_selection
= FALSE
;
1131 PRIVATE(data
)->selectPt1
= PRIVATE(data
)->selectPt2
= WCUSER_GetCell(data
, lParam
);
1132 SetCapture(data
->hWnd
);
1133 WCUSER_SetSelection(data
, 0);
1134 PRIVATE(data
)->has_selection
= TRUE
;
1139 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1143 if (data
->curcfg
.quick_edit
|| PRIVATE(data
)->has_selection
)
1145 if (GetCapture() == data
->hWnd
&& PRIVATE(data
)->has_selection
&&
1146 (wParam
& MK_LBUTTON
))
1148 WCUSER_MoveSelection(data
, PRIVATE(data
)->selectPt1
, WCUSER_GetCell(data
, lParam
));
1153 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, MOUSE_MOVED
);
1157 if (data
->curcfg
.quick_edit
|| PRIVATE(data
)->has_selection
)
1159 if (GetCapture() == data
->hWnd
&& PRIVATE(data
)->has_selection
)
1161 WCUSER_MoveSelection(data
, PRIVATE(data
)->selectPt1
, WCUSER_GetCell(data
, lParam
));
1167 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1170 case WM_RBUTTONDOWN
:
1171 if ((wParam
& (MK_CONTROL
|MK_SHIFT
)) == data
->curcfg
.menu_mask
)
1175 pt
.x
= (short)LOWORD(lParam
);
1176 pt
.y
= (short)HIWORD(lParam
);
1177 ClientToScreen(hWnd
, &pt
);
1178 WCUSER_SetMenuDetails(data
, PRIVATE(data
)->hPopMenu
);
1179 TrackPopupMenu(PRIVATE(data
)->hPopMenu
, TPM_LEFTALIGN
|TPM_TOPALIGN
|TPM_RIGHTBUTTON
,
1180 pt
.x
, pt
.y
, 0, hWnd
, NULL
);
1184 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1188 /* no need to track for rbutton up when opening the popup... the event will be
1189 * swallowed by TrackPopupMenu */
1190 case WM_MBUTTONDOWN
:
1192 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, 0);
1194 case WM_LBUTTONDBLCLK
:
1195 case WM_MBUTTONDBLCLK
:
1196 case WM_RBUTTONDBLCLK
:
1197 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, DOUBLE_CLICK
);
1200 if (data
->curcfg
.cursor_visible
)
1202 CreateCaret(data
->hWnd
, PRIVATE(data
)->cursor_bitmap
,
1203 data
->curcfg
.cell_width
, data
->curcfg
.cell_height
);
1204 WCUSER_PosCursor(data
);
1208 if (data
->curcfg
.cursor_visible
)
1213 struct config_data cfg
= data
->curcfg
;
1215 switch (LOWORD(wParam
))
1217 case SB_PAGEUP
: cfg
.win_pos
.X
-= 8; break;
1218 case SB_PAGEDOWN
: cfg
.win_pos
.X
+= 8; break;
1219 case SB_LINEUP
: cfg
.win_pos
.X
--; break;
1220 case SB_LINEDOWN
: cfg
.win_pos
.X
++; break;
1221 case SB_THUMBTRACK
: cfg
.win_pos
.X
= HIWORD(wParam
); break;
1224 if (cfg
.win_pos
.X
< 0) cfg
.win_pos
.X
= 0;
1225 if (cfg
.win_pos
.X
> data
->curcfg
.sb_width
- data
->curcfg
.win_width
)
1226 cfg
.win_pos
.X
= data
->curcfg
.sb_width
- data
->curcfg
.win_width
;
1227 if (cfg
.win_pos
.X
!= data
->curcfg
.win_pos
.X
)
1229 WINECON_SetConfig(data
, &cfg
);
1234 if (data
->curcfg
.sb_height
<= data
->curcfg
.win_height
)
1236 WCUSER_GenerateMouseInputRecord(data
, WCUSER_GetCell(data
, lParam
), wParam
, MOUSE_WHEELED
);
1239 /* else fallthrough */
1242 struct config_data cfg
= data
->curcfg
;
1244 if (uMsg
== WM_MOUSEWHEEL
)
1246 UINT scrollLines
= 3;
1247 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
, 0, &scrollLines
, 0);
1248 scrollLines
*= -GET_WHEEL_DELTA_WPARAM(wParam
) / WHEEL_DELTA
;
1249 cfg
.win_pos
.Y
+= scrollLines
;
1251 switch (LOWORD(wParam
))
1253 case SB_PAGEUP
: cfg
.win_pos
.Y
-= 8; break;
1254 case SB_PAGEDOWN
: cfg
.win_pos
.Y
+= 8; break;
1255 case SB_LINEUP
: cfg
.win_pos
.Y
--; break;
1256 case SB_LINEDOWN
: cfg
.win_pos
.Y
++; break;
1257 case SB_THUMBTRACK
: cfg
.win_pos
.Y
= HIWORD(wParam
); break;
1262 if (cfg
.win_pos
.Y
< 0) cfg
.win_pos
.Y
= 0;
1263 if (cfg
.win_pos
.Y
> data
->curcfg
.sb_height
- data
->curcfg
.win_height
)
1264 cfg
.win_pos
.Y
= data
->curcfg
.sb_height
- data
->curcfg
.win_height
;
1265 if (cfg
.win_pos
.Y
!= data
->curcfg
.win_pos
.Y
)
1267 WINECON_SetConfig(data
, &cfg
);
1275 WCUSER_GetProperties(data
, FALSE
);
1277 case IDS_PROPERTIES
:
1278 WCUSER_GetProperties(data
, TRUE
);
1281 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1288 WCUSER_GetProperties(data
, FALSE
);
1290 case IDS_PROPERTIES
:
1291 WCUSER_GetProperties(data
, TRUE
);
1294 PRIVATE(data
)->selectPt1
.X
= PRIVATE(data
)->selectPt1
.Y
= 0;
1295 PRIVATE(data
)->selectPt2
.X
= PRIVATE(data
)->selectPt2
.Y
= 0;
1296 WCUSER_SetSelection(data
, 0);
1297 PRIVATE(data
)->has_selection
= TRUE
;
1300 if (PRIVATE(data
)->has_selection
)
1302 PRIVATE(data
)->has_selection
= FALSE
;
1303 WCUSER_SetSelection(data
, 0);
1304 WCUSER_CopySelectionToClipboard(data
);
1308 WCUSER_PasteFromClipboard(data
);
1311 PRIVATE(data
)->selectPt1
.X
= PRIVATE(data
)->selectPt1
.Y
= 0;
1312 PRIVATE(data
)->selectPt2
.X
= (data
->curcfg
.sb_width
- 1) * data
->curcfg
.cell_width
;
1313 PRIVATE(data
)->selectPt2
.Y
= (data
->curcfg
.sb_height
- 1) * data
->curcfg
.cell_height
;
1314 WCUSER_SetSelection(data
, 0);
1315 PRIVATE(data
)->has_selection
= TRUE
;
1319 WINE_FIXME("Unhandled yet command: %lx\n", wParam
);
1322 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1325 case WM_INITMENUPOPUP
:
1326 if (!HIWORD(lParam
)) return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1327 WCUSER_SetMenuDetails(data
, GetSystemMenu(data
->hWnd
, FALSE
));
1330 WINECON_ResizeWithContainer(data
, LOWORD(lParam
) / data
->curcfg
.cell_width
,
1331 HIWORD(lParam
) / data
->curcfg
.cell_height
);
1334 return DefWindowProcW(hWnd
, uMsg
, wParam
, lParam
);
1339 /******************************************************************
1340 * WCUSER_DeleteBackend
1344 static void WCUSER_DeleteBackend(struct inner_data
* data
)
1346 if (!PRIVATE(data
)) return;
1347 if (PRIVATE(data
)->hMemDC
) DeleteDC(PRIVATE(data
)->hMemDC
);
1348 if (data
->hWnd
) DestroyWindow(data
->hWnd
);
1349 if (PRIVATE(data
)->hFont
) DeleteObject(PRIVATE(data
)->hFont
);
1350 if (PRIVATE(data
)->cursor_bitmap
) DeleteObject(PRIVATE(data
)->cursor_bitmap
);
1351 if (PRIVATE(data
)->hBitmap
) DeleteObject(PRIVATE(data
)->hBitmap
);
1352 HeapFree(GetProcessHeap(), 0, PRIVATE(data
));
1355 /******************************************************************
1360 static int WCUSER_MainLoop(struct inner_data
* data
)
1364 ShowWindow(data
->hWnd
, data
->nCmdShow
);
1365 while (!data
->dying
|| !data
->curcfg
.exit_on_die
)
1367 switch (MsgWaitForMultipleObjects(1, &data
->hSynchro
, FALSE
, INFINITE
, QS_ALLINPUT
))
1370 WINECON_GrabChanges(data
);
1372 case WAIT_OBJECT_0
+1:
1373 /* need to use PeekMessageW loop instead of simple GetMessage:
1374 * multiple messages might have arrived in between,
1375 * so GetMessage would lead to delayed processing */
1376 while (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
))
1378 if (msg
.message
== WM_QUIT
) return 1;
1379 WINE_TRACE("dispatching msg %04x\n", msg
.message
);
1380 DispatchMessageW(&msg
);
1384 WINE_ERR("got pb\n");
1393 /******************************************************************
1394 * WCUSER_InitBackend
1396 * Initialisation part II: creation of window.
1399 enum init_return
WCUSER_InitBackend(struct inner_data
* data
)
1401 static const WCHAR wClassName
[] = {'W','i','n','e','C','o','n','s','o','l','e','C','l','a','s','s',0};
1406 if (!TranslateCharsetInfo((DWORD
*)(INT_PTR
)GetACP(), &ci
, TCI_SRCCODEPAGE
))
1408 g_uiDefaultCharset
= ci
.ciCharset
;
1409 WINE_TRACE_(wc_font
)("Code page %d => Default charset: %d\n", GetACP(), g_uiDefaultCharset
);
1411 data
->private = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct inner_data_user
));
1412 if (!data
->private) return init_failed
;
1414 data
->fnMainLoop
= WCUSER_MainLoop
;
1415 data
->fnPosCursor
= WCUSER_PosCursor
;
1416 data
->fnShapeCursor
= WCUSER_ShapeCursor
;
1417 data
->fnComputePositions
= WCUSER_ComputePositions
;
1418 data
->fnRefresh
= WCUSER_Refresh
;
1419 data
->fnResizeScreenBuffer
= WCUSER_ResizeScreenBuffer
;
1420 data
->fnSetTitle
= WCUSER_SetTitle
;
1421 data
->fnSetFont
= WCUSER_SetFontPmt
;
1422 data
->fnScroll
= WCUSER_Scroll
;
1423 data
->fnDeleteBackend
= WCUSER_DeleteBackend
;
1425 wndclass
.style
= CS_DBLCLKS
;
1426 wndclass
.lpfnWndProc
= WCUSER_Proc
;
1427 wndclass
.cbClsExtra
= 0;
1428 wndclass
.cbWndExtra
= sizeof(DWORD_PTR
);
1429 wndclass
.hInstance
= GetModuleHandleW(NULL
);
1430 wndclass
.hIcon
= LoadIconW(0, (LPCWSTR
)IDI_WINLOGO
);
1431 wndclass
.hCursor
= LoadCursorW(0, (LPCWSTR
)IDC_ARROW
);
1432 wndclass
.hbrBackground
= GetStockObject(BLACK_BRUSH
);
1433 wndclass
.lpszMenuName
= NULL
;
1434 wndclass
.lpszClassName
= wClassName
;
1436 RegisterClassW(&wndclass
);
1438 data
->hWnd
= CreateWindowW(wndclass
.lpszClassName
, NULL
,
1439 WS_OVERLAPPED
|WS_CAPTION
|WS_SYSMENU
|WS_THICKFRAME
|WS_MINIMIZEBOX
|WS_HSCROLL
|WS_VSCROLL
,
1440 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0, 0, wndclass
.hInstance
, data
);
1441 if (!data
->hWnd
) return init_not_supported
;
1443 return init_success
;