From b3417655da0e455063f63e8a42358a0cb6a9ee35 Mon Sep 17 00:00:00 2001 From: "nethack.allison" Date: Wed, 21 Aug 2002 23:14:27 +0000 Subject: [PATCH] B08002 - win32gui: message window sizing (from ) >>> - When I set font and font size of the message window, the >>> message window size doesn't calculate correctly to show the >>> number of message lines specified. For example, I set the font >>> size to 6, and the number of messages to display to 8. Now >>> there is whitespace at the top of my message window. When I >>> set the font size to 14 now, I see only 5.5 message lines. >>> This is unintuitive: the interface should recalculate the >>> window size needed to display the correct number of lines. >>> >> I agree, especially since the message window size is >> recalculated correctly if you save and restore. An easy way out >> would be to set those options to DISP_IN_GAME. > > That seems like a good work-around until the proper fix is done. The patch is attached. I moved the code that was computing the font size to mswin_message_window_size(). This will cause the message window to resize properly if the message font size changes. There are also 2 minor bits in mswproc.c to invalidate the message window when the font changes. --- win/win32/mhmsgwnd.c | 53 +++++++++++++++++++++----------------------- win/win32/mswproc.c | 2 ++ 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/win/win32/mhmsgwnd.c b/win/win32/mhmsgwnd.c index 440631d96..eaab27777 100644 --- a/win/win32/mhmsgwnd.c +++ b/win/win32/mhmsgwnd.c @@ -60,7 +60,6 @@ static void onMSNH_HScroll(HWND hWnd, WPARAM wParam, LPARAM lParam); static COLORREF setMsgTextColor(HDC hdc, int gray); static void onPaint(HWND hWnd); static void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam); -static HDC prepareDC( HDC hdc ); HWND mswin_init_message_window () { static int run_once = 0; @@ -679,10 +678,8 @@ void onPaint(HWND hWnd) void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) { - HDC hdc; - TEXTMETRIC tm; PNHMessageWindow data; - HGDIOBJ saveFont; + SIZE dummy; /* set window data */ data = (PNHMessageWindow)malloc(sizeof(NHMessageWindow)); @@ -691,8 +688,24 @@ void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) data->max_text = MAXWINDOWTEXT; SetWindowLong(hWnd, GWL_USERDATA, (LONG)data); + /* re-calculate window size (+ font size) */ + mswin_message_window_size(hWnd, &dummy); +} + +void mswin_message_window_size (HWND hWnd, LPSIZE sz) +{ + HDC hdc; + HGDIOBJ saveFont; + TEXTMETRIC tm; + PNHMessageWindow data; + RECT rt, client_rt; + + data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); + if( !data ) return; + + /* -- Calculate the font size -- */ /* Get the handle to the client area's device context. */ - hdc = prepareDC( GetDC(hWnd) ); + hdc = GetDC(hWnd); saveFont = SelectObject(hdc, mswin_get_font(NHW_MESSAGE, ATR_NONE, hdc, FALSE)); /* Extract font dimensions from the text metrics. */ @@ -705,31 +718,15 @@ void onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam) /* Free the device context. */ SelectObject(hdc, saveFont); ReleaseDC (hWnd, hdc); -} - -HDC prepareDC( HDC hdc ) -{ - // set font here - return hdc; -} - - -void mswin_message_window_size (HWND hWnd, LPSIZE sz) -{ - PNHMessageWindow data; - RECT rt, client_rt; - + + /* -- calculate window size -- */ GetWindowRect(hWnd, &rt); - sz->cx = rt.right - rt.left; sz->cy = rt.bottom - rt.top; - data = (PNHMessageWindow)GetWindowLong(hWnd, GWL_USERDATA); - if(data) { - /* set size to accomodate MSG_VISIBLE_LINES, highligh rectangle and - horizontal scroll bar (difference between window rect and client rect */ - GetClientRect(hWnd, &client_rt); - sz->cy = sz->cy-(client_rt.bottom - client_rt.top) + - data->yChar * MSG_VISIBLE_LINES + 4; - } + /* set size to accomodate MSG_VISIBLE_LINES and + horizontal scroll bar (difference between window rect and client rect */ + GetClientRect(hWnd, &client_rt); + sz->cy = sz->cy - (client_rt.bottom - client_rt.top) + + data->yChar * MSG_VISIBLE_LINES; } \ No newline at end of file diff --git a/win/win32/mswproc.c b/win/win32/mswproc.c index 7a559dcfa..eca61105f 100644 --- a/win/win32/mswproc.c +++ b/win/win32/mswproc.c @@ -1782,6 +1782,7 @@ void mswin_preference_update(const char *pref) mswin_get_font(NHW_STATUS, ATR_INVERSE, hdc, TRUE); ReleaseDC(GetNHApp()->hMainWnd, hdc); + InvalidateRect(mswin_hwnd_from_winid(WIN_STATUS), NULL, TRUE); mswin_layout_main_window(NULL); return; } @@ -1802,6 +1803,7 @@ void mswin_preference_update(const char *pref) mswin_get_font(NHW_MESSAGE, ATR_INVERSE, hdc, TRUE); ReleaseDC(GetNHApp()->hMainWnd, hdc); + InvalidateRect(mswin_hwnd_from_winid(WIN_MESSAGE), NULL, TRUE); mswin_layout_main_window(NULL); return; }