mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-04-21 13:05:04 -05:00
Got a bit of a better handle on the whole GDI `logical units' mess,
and sorted out the static-control text wrapping rather better. Now it works under both large fonts and small fonts on Win2K, so I have high hopes that it's actually correct this time. [originally from svn r2917]
This commit is contained in:
parent
88d0a45b0f
commit
9e0a7aa86d
18
winctrls.c
18
winctrls.c
@ -393,6 +393,7 @@ char *staticwrap(struct ctlpos *cp, HWND hwnd, char *text, int *lines)
|
|||||||
SIZE size;
|
SIZE size;
|
||||||
char *ret, *p, *q;
|
char *ret, *p, *q;
|
||||||
RECT r;
|
RECT r;
|
||||||
|
HFONT oldfont, newfont;
|
||||||
|
|
||||||
ret = smalloc(1+strlen(text));
|
ret = smalloc(1+strlen(text));
|
||||||
p = text;
|
p = text;
|
||||||
@ -403,18 +404,22 @@ char *staticwrap(struct ctlpos *cp, HWND hwnd, char *text, int *lines)
|
|||||||
* Work out the width the text will need to fit in, by doing
|
* Work out the width the text will need to fit in, by doing
|
||||||
* the same adjustment that the `statictext' function itself
|
* the same adjustment that the `statictext' function itself
|
||||||
* will perform.
|
* will perform.
|
||||||
*
|
|
||||||
* We must first convert from dialog-box units into pixels, and
|
|
||||||
* then from pixels into the `logical units' that Windows uses
|
|
||||||
* within GDI. You can't make this stuff up.
|
|
||||||
*/
|
*/
|
||||||
|
SetMapMode(hdc, MM_TEXT); /* ensure logical units == pixels */
|
||||||
r.left = r.top = r.bottom = 0;
|
r.left = r.top = r.bottom = 0;
|
||||||
r.right = cp->width;
|
r.right = cp->width;
|
||||||
MapDialogRect(hwnd, &r);
|
MapDialogRect(hwnd, &r);
|
||||||
width = MulDiv(r.right, lpx, 72);
|
width = r.right;
|
||||||
|
|
||||||
nlines = 1;
|
nlines = 1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We must select the correct font into the HDC before calling
|
||||||
|
* GetTextExtent*, or silly things will happen.
|
||||||
|
*/
|
||||||
|
newfont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
|
||||||
|
oldfont = SelectObject(hdc, newfont);
|
||||||
|
|
||||||
while (*p) {
|
while (*p) {
|
||||||
if (!GetTextExtentExPoint(hdc, p, strlen(p), width,
|
if (!GetTextExtentExPoint(hdc, p, strlen(p), width,
|
||||||
&nfit, pwidths, &size) ||
|
&nfit, pwidths, &size) ||
|
||||||
@ -453,6 +458,7 @@ char *staticwrap(struct ctlpos *cp, HWND hwnd, char *text, int *lines)
|
|||||||
nlines++;
|
nlines++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SelectObject(hdc, oldfont);
|
||||||
ReleaseDC(cp->hwnd, hdc);
|
ReleaseDC(cp->hwnd, hdc);
|
||||||
|
|
||||||
if (lines) *lines = nlines;
|
if (lines) *lines = nlines;
|
||||||
@ -1748,6 +1754,8 @@ int winctrl_handle_command(struct dlgparam *dp, UINT msg,
|
|||||||
RECT r = di->rcItem;
|
RECT r = di->rcItem;
|
||||||
SIZE s;
|
SIZE s;
|
||||||
|
|
||||||
|
SetMapMode(hdc, MM_TEXT); /* ensure logical units == pixels */
|
||||||
|
|
||||||
GetTextExtentPoint32(hdc, (char *)c->data,
|
GetTextExtentPoint32(hdc, (char *)c->data,
|
||||||
strlen((char *)c->data), &s);
|
strlen((char *)c->data), &s);
|
||||||
DrawEdge(hdc, &r, EDGE_ETCHED, BF_ADJUST | BF_RECT);
|
DrawEdge(hdc, &r, EDGE_ETCHED, BF_ADJUST | BF_RECT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user