FindTextureDlg.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // FindTextureDlg.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "Radiant.h"
  22. #include "FindTextureDlg.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CFindTextureDlg dialog
  30. CFindTextureDlg g_TexFindDlg;
  31. CFindTextureDlg& g_dlgFind = g_TexFindDlg;
  32. static bool g_bFindActive = true;
  33. void CFindTextureDlg::updateTextures(const char *p)
  34. {
  35. if (isOpen())
  36. {
  37. if (g_bFindActive)
  38. {
  39. setFindStr(p);
  40. }
  41. else
  42. {
  43. setReplaceStr(p);
  44. }
  45. }
  46. }
  47. CFindTextureDlg::CFindTextureDlg(CWnd* pParent /*=NULL*/)
  48. : CDialog(CFindTextureDlg::IDD, pParent)
  49. {
  50. //{{AFX_DATA_INIT(CFindTextureDlg)
  51. m_bSelectedOnly = FALSE;
  52. m_strFind = _T("");
  53. m_strReplace = _T("");
  54. m_bForce = FALSE;
  55. m_bLive = TRUE;
  56. //}}AFX_DATA_INIT
  57. }
  58. void CFindTextureDlg::DoDataExchange(CDataExchange* pDX)
  59. {
  60. CDialog::DoDataExchange(pDX);
  61. //{{AFX_DATA_MAP(CFindTextureDlg)
  62. DDX_Check(pDX, IDC_CHECK_SELECTED, m_bSelectedOnly);
  63. DDX_Text(pDX, IDC_EDIT_FIND, m_strFind);
  64. DDX_Text(pDX, IDC_EDIT_REPLACE, m_strReplace);
  65. DDX_Check(pDX, IDC_CHECK_FORCE, m_bForce);
  66. DDX_Check(pDX, IDC_CHECK_LIVE, m_bLive);
  67. //}}AFX_DATA_MAP
  68. }
  69. BEGIN_MESSAGE_MAP(CFindTextureDlg, CDialog)
  70. //{{AFX_MSG_MAP(CFindTextureDlg)
  71. ON_BN_CLICKED(ID_BTN_APPLY, OnBtnApply)
  72. ON_EN_SETFOCUS(IDC_EDIT_FIND, OnSetfocusEditFind)
  73. ON_EN_SETFOCUS(IDC_EDIT_REPLACE, OnSetfocusEditReplace)
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. void CFindTextureDlg::OnBtnApply()
  77. {
  78. UpdateData(TRUE);
  79. CRect rct;
  80. GetWindowRect(rct);
  81. SaveRegistryInfo("Radiant::TextureFindWindow", &rct, sizeof(rct));
  82. FindReplaceTextures(m_strFind, m_strReplace, m_bSelectedOnly, m_bForce);
  83. }
  84. void CFindTextureDlg::OnOK()
  85. {
  86. UpdateData(TRUE);
  87. CRect rct;
  88. GetWindowRect(rct);
  89. SaveRegistryInfo("Radiant::TextureFindWindow", &rct, sizeof(rct));
  90. FindReplaceTextures(m_strFind, m_strReplace, m_bSelectedOnly, m_bForce);
  91. CDialog::OnOK();
  92. }
  93. void CFindTextureDlg::show()
  94. {
  95. if (g_dlgFind.GetSafeHwnd() == NULL || IsWindow(g_dlgFind.GetSafeHwnd()) == FALSE)
  96. {
  97. g_dlgFind.Create(IDD_DIALOG_FINDREPLACE);
  98. g_dlgFind.ShowWindow(SW_SHOW);
  99. }
  100. else
  101. {
  102. g_dlgFind.ShowWindow(SW_SHOW);
  103. }
  104. CRect rct;
  105. LONG lSize = sizeof(rct);
  106. if (LoadRegistryInfo("Radiant::TextureFindWindow", &rct, &lSize))
  107. g_dlgFind.SetWindowPos(NULL, rct.left, rct.top, 0,0, SWP_NOSIZE | SWP_SHOWWINDOW);
  108. }
  109. bool CFindTextureDlg::isOpen()
  110. {
  111. return (g_dlgFind.GetSafeHwnd() == NULL || ::IsWindowVisible(g_dlgFind.GetSafeHwnd()) == FALSE) ? false : true;
  112. }
  113. void CFindTextureDlg::setFindStr(const char * p)
  114. {
  115. g_dlgFind.UpdateData(TRUE);
  116. if (g_dlgFind.m_bLive)
  117. {
  118. g_dlgFind.m_strFind = p;
  119. g_dlgFind.UpdateData(FALSE);
  120. }
  121. }
  122. void CFindTextureDlg::setReplaceStr(const char * p)
  123. {
  124. g_dlgFind.UpdateData(TRUE);
  125. if (g_dlgFind.m_bLive)
  126. {
  127. g_dlgFind.m_strReplace = p;
  128. g_dlgFind.UpdateData(FALSE);
  129. }
  130. }
  131. void CFindTextureDlg::OnCancel()
  132. {
  133. CRect rct;
  134. GetWindowRect(rct);
  135. SaveRegistryInfo("Radiant::TextureFindWindow", &rct, sizeof(rct));
  136. CDialog::OnCancel();
  137. }
  138. BOOL CFindTextureDlg::DestroyWindow()
  139. {
  140. return CDialog::DestroyWindow();
  141. }
  142. void CFindTextureDlg::OnSetfocusEditFind()
  143. {
  144. g_bFindActive = true;
  145. }
  146. void CFindTextureDlg::OnSetfocusEditReplace()
  147. {
  148. g_bFindActive = false;
  149. }