home *** CD-ROM | disk | FTP | other *** search
- // This is a part of the Microsoft Foundation Classes C++ library.
- // Copyright (C) 1992-1998 Microsoft Corporation
- // All rights reserved.
- //
- // This source code is only intended as a supplement to the
- // Microsoft Foundation Classes Reference and related
- // electronic documentation provided with the library.
- // See these sources for detailed information regarding the
- // Microsoft Foundation Classes product.
-
- #include "stdafx.h"
- #if !defined(_WIN32_WCE_NO_FINDREPLACE)
-
- /////////////////////////////////////////////////////////////////////////////
- // CFindReplaceDialog message handlers
-
- BEGIN_MESSAGE_MAP(CFindReplaceDialog, CCommonDialog)
- //{{AFX_MSG_MAP(CFindReplaceDialog)
- ON_CONTROL(BN_CLICKED, ID_BUTTON1, OnReplace)
- ON_CONTROL(BN_CLICKED, ID_BUTTON2, OnReplaceAll)
- ON_CONTROL(BN_CLICKED, ID_BUTTON_HELP, OnHelp)
- ON_CONTROL(EN_CHANGE, ID_EDIT1, OnFindTextChanged)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- void CFindReplaceDialog::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CFindReplaceDialog)
- //}}AFX_DATA_MAP
- }
-
- void CFindReplaceDialog::OnOK()
- {
- // Check this is a valid call
- ASSERT_VALID(this);
-
- if (!UpdateData(TRUE))
- {
- TRACE0("UpdateData failed during dialog termination.\n");
- // the UpdateData routine will set focus to correct item
- return;
- }
-
- // Prepare m_fr for parent notification
- m_fr.Flags = FR_ENABLEHOOK | FR_FINDNEXT;
-
- // Get 'Find what' value
- GetDlgItem(ID_EDIT1)->GetWindowText(m_fr.lpstrFindWhat,
- m_fr.wFindWhatLen);
-
- // If find/replace dialog, get 'Replace with' value
- if (m_nIDHelp == AFX_IDD_REPLACE)
- GetDlgItem(ID_EDIT2)->GetWindowText(m_fr.lpstrReplaceWith,
- m_fr.wReplaceWithLen);
-
- // Get state of 'Match whole word' check box
- if (((CButton*)GetDlgItem(ID_CHECK1))->GetCheck() > 0)
- m_fr.Flags |= FR_WHOLEWORD;
-
- // Get state of 'Match case' check box
- if (((CButton*)GetDlgItem(ID_CHECK2))->GetCheck() > 0)
- m_fr.Flags |= FR_MATCHCASE;
-
- // Get 'Direction' state
- m_fr.Flags |= FR_DOWN;
- if (m_nIDHelp == AFX_IDD_FIND)
- {
- if (IsDlgButtonChecked(ID_RADIO1))
- m_fr.Flags &= ~FR_DOWN; // "up" direction (for Find dialog only)
- }
-
- // Notify parent window of user input to find replace dialog
- ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
- 0, (LPARAM)&m_fr);
- }
-
-
- void CFindReplaceDialog::OnCancel()
- {
- ASSERT_VALID(this);
-
- // Do not modify the flags, except to add
- // FR_DIALOGTERM
- m_fr.Flags |= FR_DIALOGTERM;
-
- // Delete other flags which may be left from
- // the last button press
- if ((m_fr.Flags & FR_FINDNEXT) == FR_FINDNEXT)
- m_fr.Flags &= ~FR_FINDNEXT;
- if ((m_fr.Flags & FR_REPLACE) == FR_REPLACE)
- m_fr.Flags &= ~FR_REPLACE;
- if ((m_fr.Flags & FR_REPLACEALL) == FR_REPLACEALL)
- m_fr.Flags &= ~FR_REPLACEALL;
-
- // Notify parent window of user input to find replace dialog
- // NOTE: This activates CEditView::OnFindReplaceCmd(), which
- // in turn calls CFindReplaceDialog::GetNotifier().
- //
- ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
- 0, (LPARAM)&m_fr);
-
- EndDialog(IDCANCEL);
- }
-
-
- void CFindReplaceDialog::EndDialog(int nEndID)
- {
- ASSERT_VALID(this);
-
- m_nModalResult = nEndID;
- // For modeless, call DestroyWindow().
- // NOTE: For modal, we would have called PostMessage(WM_COMMAND, IDCANCEL);
- DestroyWindow();
- }
-
-
- void CFindReplaceDialog::OnReplace()
- {
- ASSERT_VALID(this);
-
- if (!UpdateData(TRUE))
- {
- TRACE0("UpdateData failed (psh1).\n");
- // the UpdateData routine will set focus to correct item
- return;
- }
-
- // Prepare m_fr for parent notification
- m_fr.Flags = FR_ENABLEHOOK | FR_REPLACE | FR_DOWN;
-
- // Get 'Find what' value
- GetDlgItem(ID_EDIT1)->GetWindowText(m_fr.lpstrFindWhat,
- m_fr.wFindWhatLen);
-
- // Get 'Replace with' value
- GetDlgItem(ID_EDIT2)->GetWindowText(m_fr.lpstrReplaceWith,
- m_fr.wReplaceWithLen);
-
- // Get state of 'Match whole word' check box
- if (((CButton*)GetDlgItem(ID_CHECK1))->GetCheck() > 0)
- m_fr.Flags |= FR_WHOLEWORD;
-
- // Get state of 'Match case' check box
- if (((CButton*)GetDlgItem(ID_CHECK2))->GetCheck() > 0)
- m_fr.Flags |= FR_MATCHCASE;
-
- // Notify parent window of user input to find replace dialog
- ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
- 0, (LPARAM)&m_fr);
- }
-
- void CFindReplaceDialog::OnReplaceAll()
- {
- ASSERT_VALID(this);
-
- if (!UpdateData(TRUE))
- {
- TRACE0("UpdateData failed (psh1).\n");
- // the UpdateData routine will set focus to correct item
- return;
- }
-
- // Prepare m_fr for parent notification
- m_fr.Flags = FR_ENABLEHOOK | FR_REPLACEALL | FR_DOWN;
-
- // Get 'Find what' value
- GetDlgItem(ID_EDIT1)->GetWindowText(m_fr.lpstrFindWhat,
- m_fr.wFindWhatLen);
-
- // Get 'Replace with' value
- GetDlgItem(ID_EDIT2)->GetWindowText(m_fr.lpstrReplaceWith,
- m_fr.wReplaceWithLen);
-
- // Get state of 'Match whole word' check box
- if (((CButton*)GetDlgItem(ID_CHECK1))->GetCheck() > 0)
- m_fr.Flags |= FR_WHOLEWORD;
-
- // Get state of 'Match case' check box
- if (((CButton*)GetDlgItem(ID_CHECK2))->GetCheck() > 0)
- m_fr.Flags |= FR_MATCHCASE;
-
- // Notify parent window of user input to find replace dialog
- ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
- 0, (LPARAM)&m_fr);
- }
-
- void CFindReplaceDialog::OnHelp()
- {
- SendMessage(m_nIDHelp);
- }
-
- void CFindReplaceDialog::OnFindTextChanged()
- {
- CString strFind;
-
- GetDlgItemText(ID_EDIT1, strFind);
- BOOL bEnable = !strFind.IsEmpty();
-
- GetDlgItem(IDOK)->EnableWindow(bEnable);
- if (m_nIDHelp != AFX_IDD_FIND)
- {
- GetDlgItem(ID_BUTTON1)->EnableWindow(bEnable);
- GetDlgItem(ID_BUTTON2)->EnableWindow(bEnable);
- }
- }
-
-
- HWND wce_FindText(LPFINDREPLACE lpfr)
- {
- // Create a modeless dialog.
- HINSTANCE hInst = AfxFindResourceHandle( _T("WCE_FINDDLG"), RT_DIALOG );
- if(!hInst)
- return (NULL);
- HWND hwnd = ::CreateDialog(hInst, _T("WCE_FINDDLG"), lpfr->hwndOwner,
- (DLGPROC)lpfr->lpfnHook );
-
- // Check it has been created successfully
- ASSERT(hwnd != NULL);
-
- // Set the value for the 'Find what' edit box
- if (SetWindowText(
- GetDlgItem(hwnd, ID_EDIT1), // Handle of ID_EDIT1
- lpfr->lpstrFindWhat))
- TRACE0("Setting ID_EDIT1 successful\n");
-
- // Hide/Show 'Whole word only' check box
- if (lpfr->Flags & FR_HIDEWHOLEWORD)
- ShowWindow(GetDlgItem(hwnd, ID_CHECK1), SW_HIDE);
- else
- {
- // Disable/Enable 'Whole word only' check box
- if (lpfr->Flags & FR_NOWHOLEWORD)
- EnableWindow(GetDlgItem(hwnd, ID_CHECK1), FALSE);
- else
- ShowWindow(GetDlgItem(hwnd, ID_CHECK1), SW_SHOW);
- }
-
- // Hide/Show 'Match case' check box
- if (lpfr->Flags & FR_HIDEMATCHCASE)
- ShowWindow(GetDlgItem(hwnd, ID_CHECK2), SW_HIDE);
- else
- {
- // Disable/Enable 'Match case' check box
- if (lpfr->Flags & FR_NOMATCHCASE)
- EnableWindow(GetDlgItem(hwnd, ID_CHECK2), FALSE);
- else
- ShowWindow(GetDlgItem(hwnd, ID_CHECK2), SW_SHOW);
- }
-
- // Check Up/Down radio button
- if (lpfr->Flags & FR_DOWN)
- {
- SendMessage(GetDlgItem(hwnd, ID_RADIO1), BM_SETCHECK, 0, 0);
- SendMessage(GetDlgItem(hwnd, ID_RADIO2), BM_SETCHECK, 1, 0);
- }
- else
- {
- SendMessage(GetDlgItem(hwnd, ID_RADIO1), BM_SETCHECK, 1, 0);
- SendMessage(GetDlgItem(hwnd, ID_RADIO2), BM_SETCHECK, 0, 0);
- }
-
- // Hide/Show 'Direction' radio buttons
- if (lpfr->Flags & FR_HIDEUPDOWN)
- {
- ShowWindow(GetDlgItem(hwnd, ID_GROUP1), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, ID_RADIO1), SW_HIDE);
- ShowWindow(GetDlgItem(hwnd, ID_RADIO2), SW_HIDE);
- }
- else
- {
- // Disable/Enable 'Direction radio buttons'
- if (lpfr->Flags & FR_NOUPDOWN)
- {
- EnableWindow(GetDlgItem(hwnd, ID_GROUP1), FALSE);
- EnableWindow(GetDlgItem(hwnd, ID_RADIO1), FALSE);
- EnableWindow(GetDlgItem(hwnd, ID_RADIO2), FALSE);
- }
- else
- {
- ShowWindow(GetDlgItem(hwnd, ID_GROUP1), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, ID_RADIO1), SW_SHOW);
- ShowWindow(GetDlgItem(hwnd, ID_RADIO2), SW_SHOW);
- }
- }
-
- // Show/Hide Help button
- if (lpfr->Flags & FR_SHOWHELP)
- ShowWindow(GetDlgItem(hwnd, ID_BUTTON_HELP), SW_SHOW);
- else
- ShowWindow(GetDlgItem(hwnd, ID_BUTTON_HELP), SW_HIDE);
-
- SetFocus(GetDlgItem(hwnd, ID_EDIT1));
-
- // Show find dialog
- ShowWindow(hwnd, SW_SHOW);
- UpdateWindow(hwnd);
-
- return hwnd;
- }
-
-
- HWND wce_ReplaceText(LPFINDREPLACE lpfr)
- {
- // Create a modeless dialog.
- HINSTANCE hInst = AfxFindResourceHandle( _T("WCE_REPLACEDLG"), RT_DIALOG );
- if(!hInst)
- return (NULL);
- HWND hWnd = ::CreateDialog(hInst, _T("WCE_REPLACEDLG"), lpfr->hwndOwner,
- (DLGPROC)lpfr->lpfnHook );
-
- // Check it has been created successfully
- ASSERT(hWnd != NULL);
-
- // Set the value for the 'Find what' edit box
- if (SetWindowText(
- GetDlgItem(hWnd, ID_EDIT1), // Handle of ID_EDIT1
- lpfr->lpstrFindWhat))
- TRACE0("Setting ID_EDIT1 successful\n");
-
- // Set the value for the 'Replace with' edit box
- if (SetWindowText(
- GetDlgItem(hWnd, ID_EDIT2), // Handle of ID_EDIT2
- lpfr->lpstrReplaceWith))
- TRACE0("Setting ID_EDIT2 successful\n");
-
- // Hide/Show 'Whole word only' check box
- if ((lpfr->Flags & FR_HIDEWHOLEWORD) == FR_HIDEWHOLEWORD)
- ShowWindow(GetDlgItem(hWnd, ID_CHECK1), SW_HIDE);
- else
- {
- // Disable/Enable 'Whole word only' check box
- if ((lpfr->Flags & FR_NOWHOLEWORD) == FR_NOWHOLEWORD)
- EnableWindow(GetDlgItem(hWnd, ID_CHECK1), FALSE);
- else
- ShowWindow(GetDlgItem(hWnd, ID_CHECK1), SW_SHOW);
- }
-
- // Hide/Show 'Match case' check box
- if ((lpfr->Flags & FR_HIDEMATCHCASE) == FR_HIDEMATCHCASE)
- ShowWindow(GetDlgItem(hWnd, ID_CHECK2), SW_HIDE);
- else
- {
- // Disable/Enable 'Match case' check box
- if ((lpfr->Flags & FR_NOMATCHCASE) == FR_NOMATCHCASE)
- EnableWindow(GetDlgItem(hWnd, ID_CHECK2), FALSE);
- else
- ShowWindow(GetDlgItem(hWnd, ID_CHECK2), SW_SHOW);
- }
-
- // Show/Hide Help button
- if ((lpfr->Flags & FR_SHOWHELP) == FR_SHOWHELP)
- ShowWindow(GetDlgItem(hWnd, ID_BUTTON_HELP), SW_SHOW);
- else
- ShowWindow(GetDlgItem(hWnd, ID_BUTTON_HELP), SW_HIDE);
-
- // Show find/replace dialog
- ShowWindow(hWnd, SW_SHOW);
- UpdateWindow(hWnd);
-
- return hWnd;
- }
-
- /////////////////////////////////////////////////////////////////////////////
- #endif // _WIN32_WCE_NO_FINDREPLACE
-