UserTextEdit.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. // UserTextEdit.cpp : implementation file
  5. //
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "UserTextEdit.h"
  9. #include "assert.h"
  10. #include "../MCLib/Utilities.h" /*for cLoadString*/
  11. #include "TextMessageDlg.h"
  12. #include "ResourceStringSelectionDlg.h"
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CUserTextEdit dialog
  20. CUserTextEdit::CUserTextEdit(CWnd* pParent /*=NULL*/)
  21. : CDialog(CUserTextEdit::IDD, pParent)
  22. {
  23. m_UseResourceString = false;
  24. m_ResourceStringID = 0;
  25. //{{AFX_DATA_INIT(CUserTextEdit)
  26. m_Edit = _T("");
  27. m_ResourceStringIDEdit = _T("");
  28. //}}AFX_DATA_INIT
  29. }
  30. void CUserTextEdit::DoDataExchange(CDataExchange* pDX)
  31. {
  32. CDialog::DoDataExchange(pDX);
  33. //{{AFX_DATA_MAP(CUserTextEdit)
  34. DDX_Text(pDX, IDC_USER_TEXT_EDIT_EDIT, m_Edit);
  35. DDX_Text(pDX, IDC_USER_TEXT_EDIT_RESOURCE_STRING_ID_EDIT, m_ResourceStringIDEdit);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(CUserTextEdit, CDialog)
  39. //{{AFX_MSG_MAP(CUserTextEdit)
  40. ON_BN_CLICKED(IDC_USER_TEXT_EDIT_ENTER_TEXT_BUTTON, OnUserTextEditEnterTextButton)
  41. ON_BN_CLICKED(IDC_USER_TEXT_EDIT_SELECT_RESOURCE_STRING_BUTTON, OnUserTextEditSelectResourceStringButton)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CUserTextEdit message handlers
  46. static BOOL CSLoadString(int resourceID, CString &targetStr) {
  47. char szTmp[16384/*max string length*/];
  48. cLoadString( resourceID, szTmp, 16384/*max string length*/ );
  49. targetStr = szTmp;
  50. CString tmpStr;
  51. tmpStr.Format("mc2res.dll:%d Not defined", resourceID);
  52. if (0 == strcmp(tmpStr.GetBuffer(0), szTmp)) {
  53. return (0);
  54. }
  55. return (!0);
  56. }
  57. void CUserTextEdit::UpdateTextDisplay() {
  58. UpdateData(TRUE);
  59. if (m_UseResourceString) {
  60. m_ResourceStringIDEdit.Format("%d", m_ResourceStringID);
  61. int ret = CSLoadString(m_ResourceStringID, m_Edit);
  62. if (0 == ret) {
  63. m_Edit = _TEXT("");
  64. }
  65. } else {
  66. m_ResourceStringIDEdit = _TEXT("");
  67. m_Edit = m_UnlocalizedText;
  68. }
  69. UpdateData(FALSE);
  70. }
  71. void CUserTextEdit::OnUserTextEditEnterTextButton()
  72. {
  73. TextMessageDlg textMessageDlg;
  74. textMessageDlg.m_TextMessage = m_UnlocalizedText;
  75. int ret = textMessageDlg.DoModal();
  76. if (IDOK == ret) {
  77. m_UnlocalizedText = textMessageDlg.m_TextMessage;
  78. /*remove trailing "new line"s and "carriage return"s because the game doesn't like them*/
  79. while (("\n" == m_UnlocalizedText.Right(1)) || ("\r" == m_UnlocalizedText.Right(1))) {
  80. m_UnlocalizedText = m_UnlocalizedText.Left(m_UnlocalizedText.GetLength() - 1);
  81. }
  82. m_UseResourceString = false;
  83. UpdateTextDisplay();
  84. }
  85. }
  86. void CUserTextEdit::OnUserTextEditSelectResourceStringButton()
  87. {
  88. ResourceStringSelectionDlg resourceStringSelectionDlg;
  89. resourceStringSelectionDlg.m_SelectedResourceStringID = m_ResourceStringID;
  90. int ret = resourceStringSelectionDlg.DoModal();
  91. if (IDOK == ret) {
  92. m_ResourceStringID = resourceStringSelectionDlg.m_SelectedResourceStringID;
  93. m_UseResourceString = true;
  94. UpdateTextDisplay();
  95. }
  96. }
  97. BOOL CUserTextEdit::OnInitDialog()
  98. {
  99. CDialog::OnInitDialog();
  100. UpdateTextDisplay();
  101. return TRUE; // return TRUE unless you set the focus to a control
  102. // EXCEPTION: OCX Property Pages should return FALSE
  103. }