1 /* aNetHack 0.0.1 mhtext.c $ANH-Date: 1432512802 2015/05/25 00:13:22 $ $ANH-Branch: master $:$ANH-Revision: 1.22 $ */
2 /* Copyright (C) 2001 by Alex Kompel */
3 /* aNetHack may be freely redistributed. See license for details. */
12 typedef struct mswin_anethack_text_window
{
13 PNHTextBuffer window_text
;
15 } NHTextWindow
, *PNHTextWindow
;
17 static WNDPROC editControlWndProc
= NULL
;
19 LRESULT CALLBACK
TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
20 LRESULT CALLBACK
NHTextControlWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
21 static void onMSNHCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
22 static void LayoutText(HWND hwnd
);
23 static void ToggleWrapStatus(HWND hDlg
, BOOL bWrap
);
26 mswin_init_text_window()
31 ret
= CreateDialog(GetNHApp()->hApp
, MAKEINTRESOURCE(IDD_NHTEXT
),
32 GetNHApp()->hMainWnd
, TextWndProc
);
34 panic("Cannot create text window");
36 data
= (PNHTextWindow
) malloc(sizeof(NHTextWindow
));
38 panic("out of memory");
40 ZeroMemory(data
, sizeof(NHTextWindow
));
41 data
->window_text
= mswin_init_text_buffer(
42 program_state
.gameover
? FALSE
: GetNHApp()->bWrapText
);
43 SetWindowLong(ret
, GWL_USERDATA
, (LONG
) data
);
48 mswin_display_text_window(HWND hWnd
)
52 data
= (PNHTextWindow
) GetWindowLong(hWnd
, GWL_USERDATA
);
54 ToggleWrapStatus(hWnd
, mswin_get_text_wrap(data
->window_text
));
56 mswin_popup_display(hWnd
, &data
->done
);
57 mswin_popup_destroy(hWnd
);
62 TextWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
68 data
= (PNHTextWindow
) GetWindowLong(hWnd
, GWL_USERDATA
);
71 /* set text control font */
72 control
= GetDlgItem(hWnd
, IDC_TEXT_CONTROL
);
74 panic("cannot get text view window");
78 SendMessage(control
, WM_SETFONT
,
79 (WPARAM
) mswin_get_font(NHW_TEXT
, ATR_NONE
, hdc
, FALSE
),
81 ReleaseDC(control
, hdc
);
83 #if defined(WIN_CE_SMARTPHONE)
84 /* special initialization for SmartPhone dialogs */
85 NHSPhoneDialogSetup(hWnd
, IDC_SPHONE_TEXTDIALOGBAR
, FALSE
,
86 GetNHApp()->bFullScreen
);
88 /* subclass edit control */
89 editControlWndProc
= (WNDPROC
) GetWindowLong(control
, GWL_WNDPROC
);
90 SetWindowLong(control
, GWL_WNDPROC
, (LONG
) NHTextControlWndProc
);
96 onMSNHCommand(hWnd
, wParam
, lParam
);
104 switch (LOWORD(wParam
)) {
109 case IDC_TEXT_TOGGLE_WRAP
:
110 ToggleWrapStatus(hWnd
, !mswin_get_text_wrap(data
->window_text
));
116 case WM_CTLCOLOREDIT
:
117 case WM_CTLCOLORSTATIC
: { /* sent by edit control before it is drawn */
118 HDC hdcEdit
= (HDC
) wParam
;
119 HWND hwndEdit
= (HWND
) lParam
;
120 if (hwndEdit
== GetDlgItem(hWnd
, IDC_TEXT_CONTROL
)) {
121 SetBkColor(hdcEdit
, mswin_get_color(NHW_TEXT
, MSWIN_COLOR_BG
));
122 SetTextColor(hdcEdit
, mswin_get_color(NHW_TEXT
, MSWIN_COLOR_FG
));
123 return (BOOL
) mswin_get_brush(NHW_TEXT
, MSWIN_COLOR_BG
);
130 mswin_free_text_buffer(data
->window_text
);
132 SetWindowLong(hWnd
, GWL_USERDATA
, (LONG
) 0);
140 onMSNHCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
144 data
= (PNHTextWindow
) GetWindowLong(hWnd
, GWL_USERDATA
);
146 case MSNH_MSG_PUTSTR
: {
147 PMSNHMsgPutstr msg_data
= (PMSNHMsgPutstr
) lParam
;
148 mswin_add_text(data
->window_text
, msg_data
->attr
, msg_data
->text
);
155 ToggleWrapStatus(HWND hDlg
, BOOL bWrap
)
162 data
= (PNHTextWindow
) GetWindowLong(hDlg
, GWL_USERDATA
);
164 control
= GetDlgItem(hDlg
, IDC_TEXT_CONTROL
);
166 panic("cannot get text view window");
169 /* set horizontal scrollbar status */
170 styles
= GetWindowLong(control
, GWL_STYLE
);
172 SetWindowLong(control
, GWL_STYLE
, (bWrap
? (styles
& (~WS_HSCROLL
))
173 : (styles
| WS_HSCROLL
)));
174 SetWindowPos(control
, NULL
, 0, 0, 0, 0,
175 SWP_FRAMECHANGED
| SWP_NOZORDER
| SWP_NOMOVE
179 /* set text wrap mode */
180 mswin_set_text_wrap(data
->window_text
, bWrap
);
181 mswin_render_text(data
->window_text
, control
);
183 /* change button status */
184 ZeroMemory(wbuf
, sizeof(wbuf
));
185 if (!LoadString(GetNHApp()->hApp
,
186 (bWrap
? IDS_TEXT_UNWRAP
: IDS_TEXT_WRAP
), wbuf
, BUFSZ
)) {
187 panic("cannot load text window strings");
190 #if defined(WIN_CE_SMARTPHONE)
194 ZeroMemory(&tbbi
, sizeof(tbbi
));
195 tbbi
.cbSize
= sizeof(tbbi
);
196 tbbi
.dwMask
= TBIF_TEXT
;
198 if (!SendMessage(SHFindMenuBar(hDlg
), TB_SETBUTTONINFO
,
199 IDC_TEXT_TOGGLE_WRAP
, (LPARAM
) &tbbi
)) {
200 error("Cannot update IDC_TEXT_TOGGLE_WRAP menu item.");
204 SendDlgItemMessage(hDlg
, IDC_TEXT_TOGGLE_WRAP
, WM_SETTEXT
, (WPARAM
) 0,
210 LayoutText(HWND hWnd
)
212 HWND btn_ok
, btn_wrap
;
215 POINT pt_elem
, pt_ok
, pt_wrap
;
216 SIZE sz_elem
, sz_ok
, sz_wrap
;
218 text
= GetDlgItem(hWnd
, IDC_TEXT_CONTROL
);
219 btn_ok
= GetDlgItem(hWnd
, IDOK
);
220 btn_wrap
= GetDlgItem(hWnd
, IDC_TEXT_TOGGLE_WRAP
);
222 /* get window coordinates */
223 GetClientRect(hWnd
, &clrt
);
225 /* set window placements */
226 if (IsWindow(btn_ok
)) {
227 GetWindowRect(btn_ok
, &rt
);
228 sz_ok
.cx
= (clrt
.right
- clrt
.left
) / 2;
229 sz_ok
.cy
= rt
.bottom
- rt
.top
;
231 pt_ok
.y
= clrt
.bottom
- sz_ok
.cy
;
232 MoveWindow(btn_ok
, pt_ok
.x
, pt_ok
.y
, sz_ok
.cx
, sz_ok
.cy
, TRUE
);
234 sz_wrap
.cx
= (clrt
.right
- clrt
.left
) / 2;
235 sz_wrap
.cy
= rt
.bottom
- rt
.top
;
236 pt_wrap
.x
= clrt
.left
+ sz_ok
.cx
;
237 pt_wrap
.y
= clrt
.bottom
- sz_ok
.cy
;
238 MoveWindow(btn_wrap
, pt_wrap
.x
, pt_wrap
.y
, sz_wrap
.cx
, sz_wrap
.cy
,
241 pt_elem
.x
= clrt
.left
;
242 pt_elem
.y
= clrt
.top
;
243 sz_elem
.cx
= clrt
.right
- clrt
.left
;
244 sz_elem
.cy
= pt_ok
.y
;
245 MoveWindow(text
, pt_elem
.x
, pt_elem
.y
, sz_elem
.cx
, sz_elem
.cy
, TRUE
);
247 pt_elem
.x
= clrt
.left
;
248 pt_elem
.y
= clrt
.top
;
249 sz_elem
.cx
= clrt
.right
- clrt
.left
;
250 sz_elem
.cy
= clrt
.bottom
- clrt
.top
;
251 MoveWindow(text
, pt_elem
.x
, pt_elem
.y
, sz_elem
.cx
, sz_elem
.cy
, TRUE
);
255 /* Text control window proc - implements close on space and scrolling on
258 NHTextControlWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
261 /* tell Windows not to process arrow keys (we want them) */
263 return DLGC_WANTARROWS
;
270 PostMessage(GetParent(hWnd
), WM_COMMAND
, MAKELONG(IDOK
, 0), 0);
275 PostMessage(hWnd
, WM_VSCROLL
, MAKEWPARAM(SB_LINEUP
, 0),
281 PostMessage(hWnd
, WM_VSCROLL
, MAKEWPARAM(SB_LINEDOWN
, 0),
287 PostMessage(hWnd
, WM_HSCROLL
, MAKEWPARAM(SB_LINELEFT
, 0),
293 PostMessage(hWnd
, WM_HSCROLL
, MAKEWPARAM(SB_LINERIGHT
, 0),
297 break; /* case WM_KEYDOWN: */
300 if (editControlWndProc
)
301 return CallWindowProc(editControlWndProc
, hWnd
, message
, wParam
,