| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | --- HISTORICAL COMMENTS FOLLOW --- |
| 19 | |
| 20 | * $Logfile: /DescentIII/Main/editor/KeypadDialog.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:38 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Generic Keypad Dialog base class |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 7 3/15/99 5:22p Chris |
| 30 | * Fixed bug where the last entered data would be lost when a keypad was |
| 31 | * scrolled |
| 32 | * |
| 33 | * 6 10/01/98 10:48a Samir |
| 34 | * hopefully fixced scrolling problem. |
| 35 | * |
| 36 | * 5 10/02/97 6:47p Samir |
| 37 | * Made m_Active static, so deactivating one keypad deactivates all. |
| 38 | * |
| 39 | * 4 8/25/97 12:08p Samir |
| 40 | * Damn, another fuckup. |
| 41 | * |
| 42 | * 3 8/25/97 12:05p Samir |
| 43 | * Oops, a fuckup fixed. |
| 44 | * |
| 45 | * 2 8/25/97 12:03p Samir |
| 46 | * Fixed a lot of scrolling problems. |
| 47 | * |
| 48 | * 6 2/21/97 5:04p Samir |
| 49 | * Set active flag to false when destroying to prevent corruption of |
| 50 | * memory for some reason. |
| 51 | * |
| 52 | * 5 2/20/97 6:05p Samir |
| 53 | * Allow for clean activation and deactivation of surfaces in editor when |
| 54 | * going into fullscreen mode. |
| 55 | * |
| 56 | * 4 2/19/97 7:31p Samir |
| 57 | * now scrolling for child and sibling windows. |
| 58 | * |
| 59 | * 3 1/27/97 11:38a Samir |
| 60 | * Added horizontal scrolling of keypad modeless dialog. |
| 61 | * |
| 62 | * $NoKeywords: $ |
| 63 | */ |
| 64 | |
| 65 | // KeypadDialog.cpp : implementation file |
| 66 | // |
| 67 | |
| 68 | #include "stdafx.h" |
| 69 | #include "editor.h" |
| 70 | #include "KeypadDialog.h" |
| 71 | #include "mono.h" |
| 72 | |
| 73 | #ifdef _DEBUG |
| 74 | #define new DEBUG_NEW |
| 75 | #undef THIS_FILE |
| 76 | static char THIS_FILE[] = __FILE__; |
| 77 | #endif |
| 78 | |
| 79 | ///////////////////////////////////////////////////////////////////////////// |
| 80 | // CKeypadDialog dialog |
| 81 | |
| 82 | BOOL CKeypadDialog::m_Active = TRUE; |
| 83 | |
| 84 | CKeypadDialog::CKeypadDialog(UINT id, CWnd *pParent /*=NULL*/) : CDialog(id, pParent) { |
| 85 | //{{AFX_DATA_INIT(CKeypadDialog) |
| 86 | // NOTE: the ClassWizard will add member initialization here |
| 87 | //}}AFX_DATA_INIT |
| 88 | |
| 89 | m_IDD = id; |
| 90 | m_wndParent = pParent; |
| 91 | } |
| 92 | |
| 93 | void CKeypadDialog::DoDataExchange(CDataExchange *pDX) { |
| 94 | CDialog::DoDataExchange(pDX); |
| 95 | //{{AFX_DATA_MAP(CKeypadDialog) |
| 96 | // NOTE: the ClassWizard will add DDX and DDV calls here |
| 97 | //}}AFX_DATA_MAP |
| 98 | } |
| 99 | |
| 100 | BEGIN_MESSAGE_MAP(CKeypadDialog, CDialog) |
| 101 | //{{AFX_MSG_MAP(CKeypadDialog) |
| 102 | ON_WM_SIZE() |
| 103 | ON_WM_VSCROLL() |
| 104 | ON_WM_HSCROLL() |
| 105 | ON_WM_DESTROY() |
| 106 | //}}AFX_MSG_MAP |
| 107 | END_MESSAGE_MAP() |
| 108 | |
| 109 | ///////////////////////////////////////////////////////////////////////////// |
| 110 | // CKeypadDialog message handlers |
| 111 | |
| 112 | BOOL CKeypadDialog::OnInitDialog() { |
| 113 | CDialog::OnInitDialog(); |
| 114 | |
| 115 | m_hpos = m_vpos = m_fullheight = m_fullwidth = 0; |
| 116 | |
| 117 | // get dimensions of dialog. |
| 118 | return TRUE; // return TRUE unless you set the focus to a control |
| 119 | // EXCEPTION: OCX Property Pages should return FALSE |
| 120 | } |
| 121 | |
| 122 | void CKeypadDialog::OnSize(UINT nType, int cx, int cy) { |
| 123 | RECT rect; |
| 124 | LONG style; |
| 125 | |
| 126 | CDialog::OnSize(nType, cx, cy); |
| 127 | |
| 128 | if (!m_sized) { |
| 129 | // first time sizing initialization. |
| 130 | m_fullwidth = cx; |
| 131 | m_fullheight = cy; |
| 132 | m_sized = true; |
| 133 | } |
| 134 | |
| 135 | rect.left = 0; |
| 136 | rect.right = cx; |
| 137 | rect.top = 0; |
| 138 | rect.bottom = cy; |
| 139 | style = GetWindowLong(m_hWnd, GWL_STYLE); |
| 140 | style = style & (WS_VSCROLL + WS_HSCROLL); |
| 141 | AdjustWindowRect(&rect, style, FALSE); |
| 142 | |
| 143 | InitScrollBars(rect.right - rect.left, rect.bottom - rect.top); |
| 144 | } |
| 145 | |
| 146 | void CKeypadDialog::PostNcDestroy() { |
| 147 | // TODO: Add your specialized code here and/or call the base class |
| 148 | |
| 149 | delete this; |
| 150 | } |
| 151 | |
| 152 | void CKeypadDialog::OnCancel() { |
| 153 | // Do nothing:: So we force the program to manual close this modeless dialog |
| 154 | } |
| 155 | |
| 156 | BOOL CKeypadDialog::Create() { |
| 157 | BOOL res; |
| 158 | |
| 159 | m_sized = false; |
| 160 | res = CDialog::Create(m_IDD, m_wndParent); |
| 161 | |
| 162 | return res; |
| 163 | } |
| 164 | |
| 165 | void CKeypadDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 166 | SCROLLINFO si; |
| 167 | int new_pos = 0; |
| 168 | |
| 169 | CDialog::SetFocus(); |
| 170 | |
| 171 | if (!pScrollBar) { |
| 172 | si.cbSize = sizeof(SCROLLINFO); |
| 173 | si.fMask = SIF_ALL; |
| 174 | GetScrollInfo(SB_VERT, &si); |
| 175 | switch (nSBCode) { |
| 176 | case SB_LINEUP: |
| 177 | new_pos = si.nPos - 4; |
| 178 | break; |
| 179 | |
| 180 | case SB_LINEDOWN: |
| 181 | new_pos = si.nPos + 4; |
| 182 | break; |
| 183 | |
| 184 | case SB_PAGEUP: |
| 185 | new_pos = si.nPos - si.nPage; |
| 186 | break; |
| 187 | |
| 188 | case SB_PAGEDOWN: |
| 189 | new_pos = si.nPos + si.nPage; |
| 190 | break; |
| 191 | |
| 192 | case SB_THUMBPOSITION: |
| 193 | new_pos = nPos; |
| 194 | break; |
| 195 | |
| 196 | case SB_THUMBTRACK: |
| 197 | new_pos = nPos; |
| 198 | break; |
| 199 | |
| 200 | default: |
| 201 | new_pos = si.nPos; |
| 202 | } |
| 203 | |
| 204 | // make sure new_pos is in a valid range |
| 205 | if (new_pos > (int)((si.nMax - si.nPage) + 1)) |
| 206 | new_pos = (si.nMax - si.nPage) + 1; |
| 207 | if (new_pos < 0) |
| 208 | new_pos = 0; |
| 209 | |
| 210 | if (new_pos != si.nPos) { |
| 211 | // We will use ScrollWindowEx to scroll the child windows of this dialog box. |
| 212 | ScrollWindowEx(0, -(new_pos - si.nPos), NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE); |
| 213 | UpdateWindow(); |
| 214 | |
| 215 | si.cbSize = sizeof(si); |
| 216 | si.fMask = SIF_POS; |
| 217 | si.nPos = new_pos; |
| 218 | SetScrollInfo(SB_VERT, &si, TRUE); |
| 219 | } |
| 220 | |
| 221 | m_vpos = new_pos; |
| 222 | } |
| 223 | CDialog::OnVScroll(nSBCode, nPos, pScrollBar); |
| 224 | } |
| 225 | |
| 226 | void CKeypadDialog::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) { |
| 227 | SCROLLINFO si; |
| 228 | int new_pos = 0; |
| 229 | |
| 230 | CDialog::SetFocus(); |
| 231 | |
| 232 | if (!pScrollBar) { |
| 233 | si.cbSize = sizeof(SCROLLINFO); |
| 234 | si.fMask = SIF_ALL; |
| 235 | GetScrollInfo(SB_HORZ, &si); |
| 236 | switch (nSBCode) { |
| 237 | case SB_LINELEFT: |
| 238 | new_pos = si.nPos - 4; |
| 239 | break; |
| 240 | |
| 241 | case SB_LINERIGHT: |
| 242 | new_pos = si.nPos + 4; |
| 243 | break; |
| 244 | |
| 245 | case SB_PAGELEFT: |
| 246 | new_pos = si.nPos - si.nPage; |
| 247 | break; |
| 248 | |
| 249 | case SB_PAGERIGHT: |
| 250 | new_pos = si.nPos + si.nPage; |
| 251 | break; |
| 252 | |
| 253 | case SB_THUMBPOSITION: |
| 254 | new_pos = nPos; |
| 255 | break; |
| 256 | |
| 257 | case SB_THUMBTRACK: |
| 258 | new_pos = nPos; |
| 259 | break; |
| 260 | |
| 261 | default: |
| 262 | new_pos = si.nPos; |
| 263 | } |
| 264 | |
| 265 | // make sure new_pos is in a valid range |
| 266 | if (new_pos > (int)((si.nMax - si.nPage) + 1)) |
| 267 | new_pos = (si.nMax - si.nPage) + 1; |
| 268 | if (new_pos < 0) |
| 269 | new_pos = 0; |
| 270 | |
| 271 | if (new_pos != si.nPos) { |
| 272 | // We will use ScrollWindowEx to scroll the child windows of this dialog box. |
| 273 | ScrollWindowEx(-(new_pos - si.nPos), 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE); |
| 274 | UpdateWindow(); |
| 275 | |
| 276 | si.cbSize = sizeof(si); |
| 277 | si.fMask = SIF_POS; |
| 278 | si.nPos = new_pos; |
| 279 | SetScrollInfo(SB_HORZ, &si, TRUE); |
| 280 | } |
| 281 | |
| 282 | m_hpos = new_pos; |
| 283 | } |
| 284 | |
| 285 | CDialog::OnHScroll(nSBCode, nPos, pScrollBar); |
| 286 | } |
| 287 | |
| 288 | void CKeypadDialog::OnDestroy() { |
| 289 | m_Active = FALSE; |
| 290 | |
| 291 | CDialog::OnDestroy(); |
| 292 | } |
| 293 | |
| 294 | void CKeypadDialog::InitScrollBars(int vis_w, int vis_h) { |
| 295 | SCROLLINFO si; |
| 296 | bool hscroll = false, vscroll = false; |
| 297 | |
| 298 | si.cbSize = sizeof(si); |
| 299 | si.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; |
| 300 | si.nMin = 0; |
| 301 | |
| 302 | // mprintf(0, "%d,%d -> %d,%d\n", m_fullwidth, m_fullheight, vis_w, vis_h); |
| 303 | |
| 304 | if (m_fullwidth > vis_w) |
| 305 | hscroll = true; |
| 306 | if (m_fullheight > vis_h) |
| 307 | vscroll = true; |
| 308 | |
| 309 | if (hscroll) { |
| 310 | ScrollWindowEx(m_hpos, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE); |
| 311 | si.nMax = m_fullwidth - 1; |
| 312 | si.nPage = vis_w - (vscroll ? GetSystemMetrics(SM_CXVSCROLL) : 0); |
| 313 | si.nPos = 0; |
| 314 | SetScrollInfo(SB_HORZ, &si); |
| 315 | ShowScrollBar(SB_HORZ, TRUE); |
| 316 | } else { |
| 317 | ShowScrollBar(SB_HORZ, FALSE); |
| 318 | ScrollWindowEx(m_hpos, 0, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE); |
| 319 | // mprintf(0, "hoff=%d\n", m_hpos); |
| 320 | } |
| 321 | |
| 322 | if (vscroll) { |
| 323 | ScrollWindowEx(0, m_vpos, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE); |
| 324 | si.nMax = m_fullheight - 1; |
| 325 | si.nPage = vis_h - (hscroll ? GetSystemMetrics(SM_CYHSCROLL) : 0); |
| 326 | si.nPos = 0; |
| 327 | SetScrollInfo(SB_VERT, &si); |
| 328 | ShowScrollBar(SB_VERT, TRUE); |
| 329 | m_vpos = 0; |
| 330 | } else { |
| 331 | ShowScrollBar(SB_VERT, FALSE); |
| 332 | ScrollWindowEx(0, m_vpos, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE); |
| 333 | // mprintf(0, "voff=%d\n", m_vpos); |
| 334 | } |
| 335 | |
| 336 | m_hpos = 0; |
| 337 | m_vpos = 0; |
| 338 | } |