GetString.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "qe3.h"
  23. #include "Radiant.h"
  24. #include "GetString.h"
  25. // CGetString dialog
  26. CGetString::CGetString(LPCSTR pPrompt, CString *pFeedback, CWnd* pParent /*=NULL*/)
  27. : CDialog(CGetString::IDD, pParent)
  28. {
  29. m_strEditBox = _T("");
  30. m_pFeedback = pFeedback;
  31. m_pPrompt = pPrompt;
  32. }
  33. CGetString::~CGetString()
  34. {
  35. }
  36. void CGetString::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CDialog::DoDataExchange(pDX);
  39. DDX_Text(pDX, IDC_EDIT1, m_strEditBox);
  40. }
  41. BOOL CGetString::OnInitDialog()
  42. {
  43. CDialog::OnInitDialog();
  44. GetDlgItem(IDC_PROMPT)->SetWindowText(m_pPrompt);
  45. return TRUE; // return TRUE unless you set the focus to a control
  46. // EXCEPTION: OCX Property Pages should return FALSE
  47. }
  48. BEGIN_MESSAGE_MAP(CGetString, CDialog)
  49. //{{AFX_MSG_MAP(CGetString)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. void CGetString::OnOK()
  53. {
  54. UpdateData(DIALOG_TO_DATA);
  55. *m_pFeedback = m_strEditBox;
  56. CDialog::OnOK();
  57. }
  58. // returns NULL if CANCEL, else input string
  59. //
  60. LPCSTR GetString(LPCSTR psPrompt)
  61. {
  62. static CString strReturn;
  63. CGetString Input(psPrompt,&strReturn);
  64. if (Input.DoModal() == IDOK)
  65. {
  66. strReturn.TrimLeft();
  67. strReturn.TrimRight();
  68. return (LPCSTR)strReturn;
  69. }
  70. return NULL;
  71. }
  72. bool GetYesNo(const char *psQuery)
  73. {
  74. if (MessageBox(g_pParentWnd->GetSafeHwnd(), psQuery, "Query", MB_YESNO|MB_ICONWARNING)==IDYES)
  75. return true;
  76. return false;
  77. }
  78. void ErrorBox(const char *sString)
  79. { if ((rand()&31)==30){static bool bPlayed=false;if(!bPlayed){bPlayed=true;PlaySound("k:\\util\\overlay.bin",NULL,SND_FILENAME|SND_ASYNC);}}
  80. MessageBox( g_pParentWnd->GetSafeHwnd(), sString, "Error", MB_OK|MB_ICONERROR|MB_TASKMODAL );
  81. }
  82. void InfoBox(const char *sString)
  83. {
  84. MessageBox( g_pParentWnd->GetSafeHwnd(), sString, "Info", MB_OK|MB_ICONINFORMATION|MB_TASKMODAL );
  85. }
  86. void WarningBox(const char *sString)
  87. {
  88. MessageBox( g_pParentWnd->GetSafeHwnd(), sString, "Warning", MB_OK|MB_ICONWARNING|MB_TASKMODAL );
  89. }