Quake-III-Arena

Quake III Arena GPL Source Release
Log | Files | Refs

FindTextureDlg.cpp (4327B)


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