]> granicus.if.org Git - nethack/commitdiff
win32gui (from <Someone>)
authornethack.allison <nethack.allison>
Sat, 27 Sep 2003 12:30:28 +0000 (12:30 +0000)
committernethack.allison <nethack.allison>
Sat, 27 Sep 2003 12:30:28 +0000 (12:30 +0000)
trunk and branch:
Do not limit role selection list by race/gender/alignment. The default.nh
selection will still be honored but the list itself will include every
possible role.

Some interface tweaks for main trunk:
- improved calculation of the size of the menu window
- made auto-arrange windows on/off option (it was reset automatically
  which was unintuitive and in some cases annoying, IMO)

doc/fixes34.3
doc/fixes35.0
win/win32/mhdlg.c
win/win32/mhmain.c
win/win32/mhmenu.c
win/win32/mswproc.c

index 93218facdc3e934005a79e770bd0f33fa4b955f8..6a650852379d3a33b5ae02b4393088ed35c61182 100644 (file)
@@ -38,6 +38,8 @@ Platform- and/or Interface-Specific Fixes
 -----------------------------------------
 win32tty: fix visible CRLF characters during lockfile error message
 win32gui: you couldn't specify an alignment in defaults.nh and have it stick
+win32gui: allow race/gender/alignment selections beyond those specified in
+       defaults.nh, while still honoring defaults.nh choices
 unix: don't define errno if NHSTDC
 
 
index 7e2a34e6c8041e3f30c3fb4a70024ac3b988d6c1..10252f7c2ca1479755b6ec9a219cbba90d75fbe8 100644 (file)
@@ -41,6 +41,9 @@ win32gui: better handling of "more" prompt for messages that would have scrolled
 win32gui: set correct checkmark on "Lock Windows" menu item on startup
 win32gui: redraw message window on resizing (it does not update properly otherwise)
 win32gui: fixed copy/paste error in read registry settings function
+win32gui: improved calculation of the size of the menu window
+win32gui: made auto-arrange windows on/off option (it was reset automatically
+       which was unintuitive and in some cases annoying
 platforms that support hangup: SAFERHANGUP to avoid losing objects in transit
        between lists when hangup occurs, and also avoid cheats due to
        well-timed hangups to stop a long melee
index d112c6b04123b3e3ccba61c2a5f5377ba5b0bf50..f155819ba2314b140271cf6ea63895e3501f5449 100644 (file)
@@ -559,17 +559,15 @@ void  plselAdjustLists(HWND hWnd, int changed_sel)
                /* reset content and populate the list */
                SendMessage(control_role, CB_RESETCONTENT, 0, 0); 
                for (i = 0; roles[i].name.m; i++) {
-                       if (ok_role(i, initrace, initgend, initalign)) {
-                           if (initgend>=0 && flags.female && roles[i].name.f)
-                                       ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)) );
-                               else 
-                                       ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)) );
-
-                               SendMessage(control_role, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
-                               if( i==initrole ) { 
-                                       SendMessage(control_role, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
-                                       valid_opt = 1;
-                               }
+                       if (initgend>=0 && flags.female && roles[i].name.f)
+                               ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.f, wbuf, sizeof(wbuf)) );
+                       else 
+                               ind = SendMessage(control_role, CB_ADDSTRING, (WPARAM)0, (LPARAM)NH_A2W(roles[i].name.m, wbuf, sizeof(wbuf)) );
+
+                       SendMessage(control_role, CB_SETITEMDATA, (WPARAM)ind, (LPARAM)i );
+                       if( i==initrole ) { 
+                               SendMessage(control_role, CB_SETCURSEL, (WPARAM)ind, (LPARAM)0 );
+                               valid_opt = 1;
                        }
                }
                
index 1ff7285851f93fa8cfcc3add9fd75e42e71268bf..440e4599a9fa6948239ee714352133551f07ee99 100644 (file)
@@ -196,6 +196,12 @@ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
                                (GetNHApp()->bWindowsLocked? MF_CHECKED : MF_UNCHECKED)
                        );
 
+                       CheckMenuItem(
+                               GetMenu(hWnd), 
+                               IDM_SETTING_AUTOLAYOUT, 
+                               GetNHApp()->bAutoLayout? MF_CHECKED : MF_UNCHECKED
+                       );
+
                        /* store handle to the mane menu in the application record */
                        GetNHApp()->hMainWnd = hWnd;
                break;
@@ -530,7 +536,6 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
                        mswin_select_map_mode(iflags.wc_map_mode);
                
                child = GetNHApp()->windowlist[msg_param->wid].win;
-               if( child ) mswin_layout_main_window(child);
        } break;
 
        }
@@ -559,6 +564,7 @@ void mswin_layout_main_window(HWND changed_child)
        SIZE msg_size;
        POINT map_org;
        SIZE map_size;
+       SIZE menu_size;
        HWND wnd_status, wnd_msg;
        PNHMainWindow  data;
 
@@ -581,6 +587,19 @@ void mswin_layout_main_window(HWND changed_child)
                        msg_size.cx = msg_size.cy = 0;
                }
 
+               /* find all menu windows and calculate the size */
+               menu_size.cx = menu_size.cy = 0;
+               for( i=0; i<MAXWINDOWS; i++ ) {
+                       SIZE tmp_size;
+                       if( GetNHApp()->windowlist[i].win 
+                               && !GetNHApp()->windowlist[i].dead
+                               && GetNHApp()->windowlist[i].type == NHW_MENU ) {
+                               mswin_menu_window_size(GetNHApp()->windowlist[i].win , &tmp_size);
+                               menu_size.cx = max(menu_size.cx, tmp_size.cx);
+                               menu_size.cy = max(menu_size.cy, tmp_size.cy);
+                       }
+               }
+
                /* set window positions */
                SetRect(&wnd_rect, client_rt.left, client_rt.top, client_rt.right, client_rt.bottom);
                switch(iflags.wc_align_status) {
@@ -676,10 +695,11 @@ void mswin_layout_main_window(HWND changed_child)
                GetNHApp()->rtMsgWindow.right    = msg_org.x + msg_size.cx;
                GetNHApp()->rtMsgWindow.bottom   = msg_org.y + msg_size.cy;
 
-               GetNHApp()->rtMenuWindow.left    = map_org.x + map_size.cx*2/3;
-               GetNHApp()->rtMenuWindow.top     = map_org.y;
-               GetNHApp()->rtMenuWindow.right   = map_org.x + map_size.cx;
-               GetNHApp()->rtMenuWindow.bottom  = map_org.y + map_size.cy;
+               /*  map_width/4 < menu_width < map_width*2/3 */
+               GetNHApp()->rtMenuWindow.left    = GetNHApp()->rtMapWindow.right - min(map_size.cx*2/3, max(map_size.cx/4, menu_size.cx));
+               GetNHApp()->rtMenuWindow.top     = GetNHApp()->rtMapWindow.top;
+               GetNHApp()->rtMenuWindow.right   = GetNHApp()->rtMapWindow.right;
+               GetNHApp()->rtMenuWindow.bottom  = GetNHApp()->rtMapWindow.bottom;
 
                GetNHApp()->rtInvenWindow.left   = GetNHApp()->rtMenuWindow.left;
                GetNHApp()->rtInvenWindow.top    = GetNHApp()->rtMenuWindow.top;
@@ -711,6 +731,8 @@ void mswin_layout_main_window(HWND changed_child)
                                          );
                }
        }
+       if( IsWindow(changed_child) ) 
+               SetForegroundWindow(changed_child);
 }
 
 LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
@@ -784,9 +806,15 @@ LRESULT onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
         }
 
                case IDM_SETTING_AUTOLAYOUT:
-                       GetNHApp()->bAutoLayout = TRUE;
+                       GetNHApp()->bAutoLayout = !GetNHApp()->bAutoLayout;
                        mswin_layout_main_window(NULL);
-                       GetNHApp()->bAutoLayout = FALSE;
+
+                       /* Update menu item check-mark */
+                       CheckMenuItem(
+                               GetMenu(GetNHApp()->hMainWnd), 
+                               IDM_SETTING_AUTOLAYOUT, 
+                               GetNHApp()->bAutoLayout? MF_CHECKED : MF_UNCHECKED
+                       );
                        break;
 
                case IDM_SETTING_LOCKWINDOWS:
@@ -901,7 +929,6 @@ void mswin_menu_check_intf_mode()
         CheckMenuItem(hMenu, IDM_NHMODE, MF_CHECKED);
     else
         CheckMenuItem(hMenu, IDM_NHMODE, MF_UNCHECKED);
-
 }
 
 void mswin_select_map_mode(int mode)
index 99bbf83c4b39c1344f22cb17c34fa3d09636ebd9..afc67f610c309335726a348baaf09378053b093e 100644 (file)
@@ -47,10 +47,12 @@ typedef struct mswin_nethack_menu_window {
                        BOOL                     counting;                      /* counting flag */
                        char                     prompt[QBUFSZ];                /* menu prompt */
                        int                      tab_stop_size[NUMTABS];/* tabstops to align option values */
+                       int                      menu_cx;               /* menu width */
                } menu;
 
                struct menu_text {
                        TCHAR*                  text;
+                       SIZE                    text_box_size;
                } text;
        };
        int result;
@@ -500,9 +502,12 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
        case MSNH_MSG_PUTSTR: 
        {
                PMSNHMsgPutstr msg_data = (PMSNHMsgPutstr)lParam;
-               HWND   text_view;
+               HWND    text_view;
                TCHAR   wbuf[BUFSZ];
-               size_t text_size;
+               size_t  text_size;
+               RECT    text_rt;
+               HGDIOBJ saveFont;
+               HDC             hdc;
 
                if( data->type!=MENU_TYPE_TEXT )
                        SetMenuType(hWnd, MENU_TYPE_TEXT);
@@ -523,6 +528,16 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
                text_view = GetDlgItem(hWnd, IDC_MENU_TEXT);
                if( !text_view ) panic("cannot get text view window");
                SetWindowText(text_view, data->text.text);
+
+               /* calculate dimensions of the added line of text */
+               hdc = GetDC(text_view);
+               saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
+               SetRect(&text_rt, 0, 0, 0, 0);
+               DrawText(hdc, msg_data->text, strlen(msg_data->text), &text_rt, DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX | DT_SINGLELINE);
+               data->text.text_box_size.cx = max(text_rt.right - text_rt.left, data->text.text_box_size.cx);
+               data->text.text_box_size.cy += text_rt.bottom - text_rt.top;
+               SelectObject(hdc, saveFont);
+               ReleaseDC(text_view, hdc);
        } break;
 
        case MSNH_MSG_STARTMENU:
@@ -550,6 +565,8 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
                HDC hDC;
                int column;
                HFONT saveFont;
+               LONG menuitemwidth = 0;
+               TEXTMETRIC tm;
                
                if( data->type!=MENU_TYPE_MENU ) break;
                if( strlen(msg_data->str)==0 ) break;
@@ -572,6 +589,7 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
                /* calculate tabstop size */
                hDC = GetDC(hWnd);
                saveFont = SelectObject(hDC, mswin_get_font(NHW_MENU, msg_data->attr, hDC, FALSE));
+               GetTextMetrics(hDC, &tm);
                p1 = data->menu.items[new_item].str;
                p = strchr(data->menu.items[new_item].str, '\t');
                column = 0;
@@ -588,9 +606,16 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
                        );
                        data->menu.tab_stop_size[column] =
                                max( data->menu.tab_stop_size[column], drawRect.right - drawRect.left );
+
+                       menuitemwidth += data->menu.tab_stop_size[column];
+
                        if (p != NULL) *p = '\t';
                        else /* last string so, */ break;
 
+                       /* add the separation only when not the last item */
+                       /* in the last item, we break out of the loop, in the statement just above */
+                       menuitemwidth += TAB_SEPARATION;
+
                        ++column;
                        p1 = p + 1;
                        p = strchr(p1, '\t');
@@ -598,6 +623,12 @@ void onMSNHCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
                SelectObject(hDC, saveFont);
                ReleaseDC(hWnd, hDC);
 
+               /* calculate new menu width */
+               data->menu.menu_cx = max(
+                       data->menu.menu_cx, 
+                       2*TILE_X + menuitemwidth + (tm.tmAveCharWidth+tm.tmOverhang)*12
+               );
+
                /* increment size */
                data->menu.size++;
        } break;
@@ -631,7 +662,6 @@ void LayoutMenu(HWND hWnd)
        /* get window coordinates */
        GetClientRect(hWnd, &clrt );
 
-
        // OK button
        if( data->is_active ) {
                GetWindowRect(menu_ok, &rt);
@@ -678,6 +708,15 @@ void LayoutMenu(HWND hWnd)
        } else {
                sz_elem.cy = (clrt.bottom - clrt.top) - 2*MENU_MARGIN;
        }
+
+       if( data->type == MENU_TYPE_MENU ) {
+               ListView_SetColumnWidth(
+                       GetMenuControl(hWnd), 
+                       0, 
+                       max(clrt.right - clrt.left - GetSystemMetrics(SM_CXVSCROLL), data->menu.menu_cx ) 
+               );
+       }
+
        MoveWindow(GetMenuControl(hWnd), pt_elem.x, pt_elem.y, sz_elem.cx, sz_elem.cy, TRUE );
 }
 /*-----------------------------------------------------------------------------*/
@@ -1002,7 +1041,11 @@ BOOL onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam)
                RECT client_rt;
 
                GetClientRect(lpdis->hwndItem, &client_rt);
-               SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom );
+               SetRect( &drawRect, 
+                                 client_rt.left, 
+                                 lpdis->rcItem.top, 
+                                 client_rt.left + ListView_GetColumnWidth(lpdis->hwndItem, 0),
+                                 lpdis->rcItem.bottom );
                DrawFocusRect(lpdis->hDC, &drawRect);
        }
 
@@ -1332,82 +1375,36 @@ BOOL onListChar(HWND hWnd, HWND hwndList, WORD ch)
 /*-----------------------------------------------------------------------------*/
 void mswin_menu_window_size (HWND hWnd, LPSIZE sz)
 {
-    TEXTMETRIC tm;
        HWND control;
-       HGDIOBJ saveFont;
-       HDC hdc;
        PNHMenuWindow data;
-       int i;
        RECT rt, wrt;
        int extra_cx;
 
-       GetClientRect(hWnd, &rt);
-       sz->cx = rt.right - rt.left;
-       sz->cy = rt.bottom - rt.top;
-
-       GetWindowRect(hWnd, &wrt);
-       extra_cx = (wrt.right-wrt.left) - sz->cx;
-
        data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA);
        if(data) {
                control = GetMenuControl(hWnd);
-               hdc = GetDC(control);
 
-               if( data->type==MENU_TYPE_MENU ) {
-                       /* Calculate the width of the list box. */
-                       saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
-                       GetTextMetrics(hdc, &tm);
-                       for(i=0; i<data->menu.size; i++ ) {
-                               LONG menuitemwidth = 0;
-                               int column;
-                               char *p, *p1;
-
-                               p1 = data->menu.items[i].str;
-                               p = strchr(data->menu.items[i].str, '\t');
-                               column = 0;
-                               for (;;) {
-                                       TCHAR wbuf[BUFSZ];
-                                       RECT tabRect;
-                                       SetRect ( &tabRect, 0, 0, 1, 1 );
-                                       if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */
-                                       DrawText(hdc,
-                                               NH_A2W(p1, wbuf, BUFSZ),
-                                               strlen(p1),
-                                               &tabRect,
-                                               DT_CALCRECT | DT_LEFT | DT_VCENTER | DT_SINGLELINE
-                                       );
-                                       /* it probably isn't necessary to recompute the tab width now, but do so
-                                        * just in case, honoring the previously computed value
-                                        */
-                                       menuitemwidth += max(data->menu.tab_stop_size[column],
-                                           tabRect.right - tabRect.left);
-                                       if (p != NULL) *p = '\t';
-                                       else /* last string so, */ break;
-                                       /* add the separation only when not the last item */
-                                       /* in the last item, we break out of the loop, in the statement just above */
-                                       menuitemwidth += TAB_SEPARATION;
-                                       ++column;
-                                       p1 = p + 1;
-                                       p = strchr(p1, '\t');
-                               }
+               /* get the control size */
+               GetClientRect(control, &rt);
+               sz->cx = rt.right - rt.left;
+               sz->cy = rt.bottom - rt.top;
 
-                               sz->cx = max(sz->cx, 
-                                       (LONG)(2*TILE_X + menuitemwidth + tm.tmAveCharWidth*12 + tm.tmOverhang));
-                       }
-                       SelectObject(hdc, saveFont);
+               /* calculate "extra" space around the control */
+               GetWindowRect(hWnd, &wrt);
+               extra_cx = (wrt.right-wrt.left) - sz->cx;
+
+               if( data->type==MENU_TYPE_MENU ) {
+                       sz->cx = max(sz->cx, data->menu.menu_cx + GetSystemMetrics(SM_CXVSCROLL) );
                } else {
-                       /* Calculate the width of the text box. */
-                       RECT text_rt;
-                       saveFont = SelectObject(hdc, mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE));
-                       GetTextMetrics(hdc, &tm);
-                       SetRect(&text_rt, 0, 0, sz->cx, sz->cy);
-                       DrawText(hdc, data->text.text, _tcslen(data->text.text), &text_rt, DT_CALCRECT | DT_TOP | DT_LEFT | DT_NOPREFIX);
-                       sz->cx = max(sz->cx, text_rt.right - text_rt.left + 5*tm.tmAveCharWidth + tm.tmOverhang);
-                       SelectObject(hdc, saveFont);
+                       /* Use the width of the text box */
+                       sz->cx = max( sz->cx, data->text.text_box_size.cx + 2*GetSystemMetrics(SM_CXVSCROLL));
                }
                sz->cx += extra_cx;
-
-               ReleaseDC(control, hdc);
+       } else { 
+               /* uninitilized window */
+               GetClientRect(hWnd, &rt);
+               sz->cx = rt.right - rt.left;
+               sz->cy = rt.bottom - rt.top;
        }
 }
 /*-----------------------------------------------------------------------------*/
index b8a43874b4528df56767700ceff11791f1bd5ed7..bc020a23a2c841e267ed37a1f538f89b8d5d1e9b 100644 (file)
@@ -817,6 +817,7 @@ void mswin_display_nhwindow(winid wid, BOOLEAN_P block)
        if (GetNHApp()->windowlist[wid].win != NULL)
        {
                ShowWindow(GetNHApp()->windowlist[wid].win, SW_SHOW);
+               mswin_layout_main_window(GetNHApp()->windowlist[wid].win);
                if (GetNHApp()->windowlist[wid].type == NHW_MENU) {
                        MENU_ITEM_P* p;
                        mswin_menu_window_select_menu(GetNHApp()->windowlist[wid].win, PICK_NONE, &p, TRUE);
@@ -2521,11 +2522,6 @@ void mswin_update_window_placement(int type, LPRECT rt)
                !EqualRect(rt_conf, rt) ) 
        {
                *rt_conf = *rt;
-
-               /* if window changed size while the game is in progess -
-                  it was most likely resized by the user */
-               if( program_state.something_worth_saving )
-                       GetNHApp()->bAutoLayout = FALSE;
        }
 }