| 1333 | } |
| 1334 | |
| 1335 | void |
| 1336 | mswin_menu_window_size(HWND hWnd, LPSIZE sz) |
| 1337 | { |
| 1338 | TEXTMETRIC tm; |
| 1339 | HWND control; |
| 1340 | HGDIOBJ saveFont; |
| 1341 | HDC hdc; |
| 1342 | PNHMenuWindow data; |
| 1343 | int i; |
| 1344 | RECT rt, wrt; |
| 1345 | int extra_cx; |
| 1346 | |
| 1347 | GetClientRect(hWnd, &rt); |
| 1348 | sz->cx = rt.right - rt.left; |
| 1349 | sz->cy = rt.bottom - rt.top; |
| 1350 | |
| 1351 | GetWindowRect(hWnd, &wrt); |
| 1352 | extra_cx = (wrt.right - wrt.left) - sz->cx; |
| 1353 | |
| 1354 | data = (PNHMenuWindow) GetWindowLong(hWnd, GWL_USERDATA); |
| 1355 | if (data) { |
| 1356 | control = GetMenuControl(hWnd); |
| 1357 | hdc = GetDC(control); |
| 1358 | |
| 1359 | if (data->type == MENU_TYPE_MENU) { |
| 1360 | /* Calculate the width of the list box. */ |
| 1361 | saveFont = SelectObject( |
| 1362 | hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE)); |
| 1363 | GetTextMetrics(hdc, &tm); |
| 1364 | for (i = 0; i < data->menu.size; i++) { |
| 1365 | LONG menuitemwidth = 0; |
| 1366 | int column; |
| 1367 | char *p, *p1; |
| 1368 | |
| 1369 | p1 = data->menu.items[i].str; |
| 1370 | p = strchr(data->menu.items[i].str, '\t'); |
| 1371 | column = 0; |
| 1372 | for (;;) { |
| 1373 | TCHAR wbuf[BUFSZ]; |
| 1374 | RECT tabRect; |
| 1375 | SetRect(&tabRect, 0, 0, 1, 1); |
| 1376 | if (p != NULL) |
| 1377 | *p = '\0'; /* for time being, view tab field as |
| 1378 | zstring */ |
| 1379 | DrawText(hdc, NH_A2W(p1, wbuf, BUFSZ), strlen(p1), |
| 1380 | &tabRect, DT_CALCRECT | DT_LEFT | DT_VCENTER |
| 1381 | | DT_SINGLELINE); |
| 1382 | /* it probably isn't necessary to recompute the tab width |
| 1383 | * now, but do so |
| 1384 | * just in case, honoring the previously computed value |
| 1385 | */ |
| 1386 | menuitemwidth += max(data->menu.tab_stop_size[column], |
| 1387 | tabRect.right - tabRect.left); |
| 1388 | if (p != NULL) |
| 1389 | *p = '\t'; |
| 1390 | else /* last string so, */ |
| 1391 | break; |
| 1392 | /* add the separation only when not the last item */ |
no test coverage detected