home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / wcedlgfr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  10.1 KB  |  366 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12. #if !defined(_WIN32_WCE_NO_FINDREPLACE)
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CFindReplaceDialog message handlers
  16.  
  17. BEGIN_MESSAGE_MAP(CFindReplaceDialog, CCommonDialog)
  18.     //{{AFX_MSG_MAP(CFindReplaceDialog)
  19.     ON_CONTROL(BN_CLICKED, ID_BUTTON1, OnReplace)
  20.     ON_CONTROL(BN_CLICKED, ID_BUTTON2, OnReplaceAll)
  21.     ON_CONTROL(BN_CLICKED, ID_BUTTON_HELP, OnHelp)
  22.     ON_CONTROL(EN_CHANGE,  ID_EDIT1, OnFindTextChanged)
  23.     //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25.  
  26. void CFindReplaceDialog::DoDataExchange(CDataExchange* pDX)
  27. {
  28.     CDialog::DoDataExchange(pDX);
  29.     //{{AFX_DATA_MAP(CFindReplaceDialog)
  30.     //}}AFX_DATA_MAP
  31. }
  32.  
  33. void CFindReplaceDialog::OnOK() 
  34. {
  35.     // Check this is a valid call
  36.     ASSERT_VALID(this);
  37.  
  38.     if (!UpdateData(TRUE))
  39.     {
  40.         TRACE0("UpdateData failed during dialog termination.\n");
  41.         // the UpdateData routine will set focus to correct item
  42.         return;
  43.     }
  44.  
  45.     // Prepare m_fr for parent notification
  46.     m_fr.Flags = FR_ENABLEHOOK | FR_FINDNEXT;
  47.  
  48.     // Get 'Find what' value
  49.     GetDlgItem(ID_EDIT1)->GetWindowText(m_fr.lpstrFindWhat, 
  50.         m_fr.wFindWhatLen);
  51.  
  52.     // If find/replace dialog, get 'Replace with' value
  53.     if (m_nIDHelp == AFX_IDD_REPLACE)
  54.         GetDlgItem(ID_EDIT2)->GetWindowText(m_fr.lpstrReplaceWith,
  55.         m_fr.wReplaceWithLen);
  56.  
  57.     // Get state of 'Match whole word' check box
  58.     if (((CButton*)GetDlgItem(ID_CHECK1))->GetCheck() > 0)
  59.         m_fr.Flags |= FR_WHOLEWORD;
  60.  
  61.     // Get state of 'Match case' check box
  62.     if (((CButton*)GetDlgItem(ID_CHECK2))->GetCheck() > 0)
  63.         m_fr.Flags |= FR_MATCHCASE;
  64.  
  65.     // Get 'Direction' state
  66.     m_fr.Flags |= FR_DOWN;
  67.     if (m_nIDHelp == AFX_IDD_FIND)
  68.     {
  69.         if (IsDlgButtonChecked(ID_RADIO1))
  70.             m_fr.Flags &= ~FR_DOWN; // "up" direction (for Find dialog only)
  71.     }
  72.  
  73.     // Notify parent window of user input to find replace dialog
  74.     ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
  75.         0, (LPARAM)&m_fr);
  76. }
  77.  
  78.  
  79. void CFindReplaceDialog::OnCancel() 
  80. {
  81.     ASSERT_VALID(this);
  82.  
  83.     // Do not modify the flags, except to add
  84.     // FR_DIALOGTERM
  85.     m_fr.Flags |= FR_DIALOGTERM;
  86.  
  87.     // Delete other flags which may be left from
  88.     // the last button press
  89.     if ((m_fr.Flags & FR_FINDNEXT) == FR_FINDNEXT)
  90.         m_fr.Flags &= ~FR_FINDNEXT;
  91.     if ((m_fr.Flags & FR_REPLACE) == FR_REPLACE)
  92.         m_fr.Flags &= ~FR_REPLACE;
  93.     if ((m_fr.Flags & FR_REPLACEALL) == FR_REPLACEALL)
  94.         m_fr.Flags &= ~FR_REPLACEALL;
  95.  
  96.     // Notify parent window of user input to find replace dialog
  97.     // NOTE: This activates CEditView::OnFindReplaceCmd(), which
  98.     //       in turn calls CFindReplaceDialog::GetNotifier().
  99.     //       
  100.     ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
  101.         0, (LPARAM)&m_fr);
  102.  
  103.     EndDialog(IDCANCEL);
  104. }
  105.  
  106.  
  107. void CFindReplaceDialog::EndDialog(int nEndID)
  108. {
  109.     ASSERT_VALID(this);
  110.  
  111.     m_nModalResult = nEndID;
  112.     // For modeless, call DestroyWindow().
  113.     // NOTE: For modal, we would have called PostMessage(WM_COMMAND, IDCANCEL);
  114.     DestroyWindow();
  115. }
  116.  
  117.  
  118. void CFindReplaceDialog::OnReplace()
  119. {
  120.     ASSERT_VALID(this);
  121.  
  122.     if (!UpdateData(TRUE))
  123.     {
  124.         TRACE0("UpdateData failed (psh1).\n");
  125.         // the UpdateData routine will set focus to correct item
  126.         return;
  127.     }
  128.  
  129.     // Prepare m_fr for parent notification
  130.     m_fr.Flags = FR_ENABLEHOOK | FR_REPLACE | FR_DOWN;
  131.  
  132.     // Get 'Find what' value
  133.     GetDlgItem(ID_EDIT1)->GetWindowText(m_fr.lpstrFindWhat,
  134.         m_fr.wFindWhatLen);
  135.  
  136.     // Get 'Replace with' value
  137.     GetDlgItem(ID_EDIT2)->GetWindowText(m_fr.lpstrReplaceWith,
  138.         m_fr.wReplaceWithLen);
  139.  
  140.     // Get state of 'Match whole word' check box
  141.     if (((CButton*)GetDlgItem(ID_CHECK1))->GetCheck() > 0)
  142.         m_fr.Flags |= FR_WHOLEWORD;
  143.  
  144.     // Get state of 'Match case' check box
  145.     if (((CButton*)GetDlgItem(ID_CHECK2))->GetCheck() > 0)
  146.         m_fr.Flags |= FR_MATCHCASE;
  147.  
  148.     // Notify parent window of user input to find replace dialog
  149.     ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
  150.         0, (LPARAM)&m_fr);
  151. }
  152.  
  153. void CFindReplaceDialog::OnReplaceAll()
  154. {
  155.     ASSERT_VALID(this);
  156.  
  157.     if (!UpdateData(TRUE))
  158.     {
  159.         TRACE0("UpdateData failed (psh1).\n");
  160.         // the UpdateData routine will set focus to correct item
  161.         return;
  162.     }
  163.  
  164.     // Prepare m_fr for parent notification
  165.     m_fr.Flags = FR_ENABLEHOOK | FR_REPLACEALL | FR_DOWN;
  166.  
  167.     // Get 'Find what' value
  168.     GetDlgItem(ID_EDIT1)->GetWindowText(m_fr.lpstrFindWhat,
  169.         m_fr.wFindWhatLen);
  170.  
  171.     // Get 'Replace with' value
  172.     GetDlgItem(ID_EDIT2)->GetWindowText(m_fr.lpstrReplaceWith,
  173.         m_fr.wReplaceWithLen);
  174.  
  175.     // Get state of 'Match whole word' check box
  176.     if (((CButton*)GetDlgItem(ID_CHECK1))->GetCheck() > 0)
  177.         m_fr.Flags |= FR_WHOLEWORD;
  178.  
  179.     // Get state of 'Match case' check box
  180.     if (((CButton*)GetDlgItem(ID_CHECK2))->GetCheck() > 0)
  181.         m_fr.Flags |= FR_MATCHCASE;
  182.  
  183.     // Notify parent window of user input to find replace dialog
  184.     ::SendMessage(m_fr.hwndOwner, RegisterWindowMessage(FINDMSGSTRING),
  185.         0, (LPARAM)&m_fr);
  186. }
  187.  
  188. void CFindReplaceDialog::OnHelp()
  189. {
  190.     SendMessage(m_nIDHelp);
  191. }
  192.  
  193. void CFindReplaceDialog::OnFindTextChanged()
  194. {
  195.     CString strFind;
  196.  
  197.     GetDlgItemText(ID_EDIT1, strFind);
  198.     BOOL bEnable = !strFind.IsEmpty();
  199.  
  200.     GetDlgItem(IDOK)->EnableWindow(bEnable);
  201.     if (m_nIDHelp != AFX_IDD_FIND)
  202.     {
  203.         GetDlgItem(ID_BUTTON1)->EnableWindow(bEnable);
  204.         GetDlgItem(ID_BUTTON2)->EnableWindow(bEnable);
  205.     }
  206. }
  207.  
  208.  
  209. HWND wce_FindText(LPFINDREPLACE lpfr)
  210. {
  211.     // Create a modeless dialog.
  212.     HINSTANCE hInst = AfxFindResourceHandle( _T("WCE_FINDDLG"), RT_DIALOG );
  213.     if(!hInst)
  214.         return (NULL);
  215.     HWND hwnd = ::CreateDialog(hInst, _T("WCE_FINDDLG"), lpfr->hwndOwner, 
  216.                     (DLGPROC)lpfr->lpfnHook );
  217.  
  218.     // Check it has been created successfully
  219.     ASSERT(hwnd != NULL);
  220.  
  221.     // Set the value for the 'Find what' edit box
  222.     if (SetWindowText(
  223.         GetDlgItem(hwnd, ID_EDIT1),    // Handle of ID_EDIT1
  224.         lpfr->lpstrFindWhat))
  225.         TRACE0("Setting ID_EDIT1 successful\n");
  226.  
  227.     // Hide/Show 'Whole word only' check box
  228.     if (lpfr->Flags & FR_HIDEWHOLEWORD) 
  229.         ShowWindow(GetDlgItem(hwnd, ID_CHECK1), SW_HIDE);
  230.     else
  231.     {
  232.         // Disable/Enable 'Whole word only' check box
  233.         if (lpfr->Flags & FR_NOWHOLEWORD) 
  234.             EnableWindow(GetDlgItem(hwnd, ID_CHECK1), FALSE);
  235.         else
  236.             ShowWindow(GetDlgItem(hwnd, ID_CHECK1), SW_SHOW);
  237.     }
  238.  
  239.     // Hide/Show 'Match case' check box
  240.     if (lpfr->Flags & FR_HIDEMATCHCASE) 
  241.         ShowWindow(GetDlgItem(hwnd, ID_CHECK2), SW_HIDE);
  242.     else
  243.     {
  244.         // Disable/Enable 'Match case' check box
  245.         if (lpfr->Flags & FR_NOMATCHCASE) 
  246.             EnableWindow(GetDlgItem(hwnd, ID_CHECK2), FALSE);
  247.         else
  248.             ShowWindow(GetDlgItem(hwnd, ID_CHECK2), SW_SHOW);
  249.     }
  250.  
  251.     // Check Up/Down radio button
  252.     if (lpfr->Flags & FR_DOWN) 
  253.     {
  254.         SendMessage(GetDlgItem(hwnd, ID_RADIO1), BM_SETCHECK, 0, 0);
  255.         SendMessage(GetDlgItem(hwnd, ID_RADIO2), BM_SETCHECK, 1, 0);
  256.     }
  257.     else
  258.     {
  259.         SendMessage(GetDlgItem(hwnd, ID_RADIO1), BM_SETCHECK, 1, 0);
  260.         SendMessage(GetDlgItem(hwnd, ID_RADIO2), BM_SETCHECK, 0, 0);
  261.     }
  262.  
  263.     // Hide/Show 'Direction' radio buttons
  264.     if (lpfr->Flags & FR_HIDEUPDOWN) 
  265.     {
  266.         ShowWindow(GetDlgItem(hwnd, ID_GROUP1), SW_HIDE);
  267.         ShowWindow(GetDlgItem(hwnd, ID_RADIO1), SW_HIDE);
  268.         ShowWindow(GetDlgItem(hwnd, ID_RADIO2), SW_HIDE);
  269.     }
  270.     else
  271.     {
  272.         // Disable/Enable 'Direction radio buttons'
  273.         if (lpfr->Flags & FR_NOUPDOWN) 
  274.         {
  275.             EnableWindow(GetDlgItem(hwnd, ID_GROUP1), FALSE);
  276.             EnableWindow(GetDlgItem(hwnd, ID_RADIO1), FALSE);
  277.             EnableWindow(GetDlgItem(hwnd, ID_RADIO2), FALSE);
  278.         }
  279.         else
  280.         {
  281.             ShowWindow(GetDlgItem(hwnd, ID_GROUP1), SW_SHOW);
  282.             ShowWindow(GetDlgItem(hwnd, ID_RADIO1), SW_SHOW);
  283.             ShowWindow(GetDlgItem(hwnd, ID_RADIO2), SW_SHOW);
  284.         }
  285.     }
  286.  
  287.     // Show/Hide Help button
  288.     if (lpfr->Flags & FR_SHOWHELP) 
  289.         ShowWindow(GetDlgItem(hwnd, ID_BUTTON_HELP), SW_SHOW);
  290.     else
  291.         ShowWindow(GetDlgItem(hwnd, ID_BUTTON_HELP), SW_HIDE);
  292.     
  293.     SetFocus(GetDlgItem(hwnd, ID_EDIT1));
  294.  
  295.     // Show find dialog
  296.     ShowWindow(hwnd, SW_SHOW);
  297.     UpdateWindow(hwnd);
  298.  
  299.     return hwnd;
  300. }
  301.  
  302.  
  303. HWND wce_ReplaceText(LPFINDREPLACE lpfr)
  304. {
  305.     // Create a modeless dialog.
  306.     HINSTANCE hInst = AfxFindResourceHandle( _T("WCE_REPLACEDLG"), RT_DIALOG );
  307.     if(!hInst)
  308.         return (NULL);
  309.     HWND hWnd = ::CreateDialog(hInst, _T("WCE_REPLACEDLG"), lpfr->hwndOwner, 
  310.                     (DLGPROC)lpfr->lpfnHook );
  311.     
  312.     // Check it has been created successfully
  313.     ASSERT(hWnd != NULL);
  314.  
  315.     // Set the value for the 'Find what' edit box
  316.     if (SetWindowText(
  317.         GetDlgItem(hWnd, ID_EDIT1),    // Handle of ID_EDIT1
  318.         lpfr->lpstrFindWhat))
  319.         TRACE0("Setting ID_EDIT1 successful\n");
  320.  
  321.     // Set the value for the 'Replace with' edit box
  322.     if (SetWindowText(
  323.         GetDlgItem(hWnd, ID_EDIT2),    // Handle of ID_EDIT2
  324.         lpfr->lpstrReplaceWith))
  325.         TRACE0("Setting ID_EDIT2 successful\n");
  326.  
  327.     // Hide/Show 'Whole word only' check box
  328.     if ((lpfr->Flags & FR_HIDEWHOLEWORD) == FR_HIDEWHOLEWORD)
  329.         ShowWindow(GetDlgItem(hWnd, ID_CHECK1), SW_HIDE);
  330.     else
  331.     {
  332.         // Disable/Enable 'Whole word only' check box
  333.         if ((lpfr->Flags & FR_NOWHOLEWORD) == FR_NOWHOLEWORD)
  334.             EnableWindow(GetDlgItem(hWnd, ID_CHECK1), FALSE);
  335.         else
  336.             ShowWindow(GetDlgItem(hWnd, ID_CHECK1), SW_SHOW);
  337.     }
  338.  
  339.     // Hide/Show 'Match case' check box
  340.     if ((lpfr->Flags & FR_HIDEMATCHCASE) == FR_HIDEMATCHCASE)
  341.         ShowWindow(GetDlgItem(hWnd, ID_CHECK2), SW_HIDE);
  342.     else
  343.     {
  344.         // Disable/Enable 'Match case' check box
  345.         if ((lpfr->Flags & FR_NOMATCHCASE) == FR_NOMATCHCASE)
  346.             EnableWindow(GetDlgItem(hWnd, ID_CHECK2), FALSE);
  347.         else
  348.             ShowWindow(GetDlgItem(hWnd, ID_CHECK2), SW_SHOW);
  349.     }
  350.  
  351.     // Show/Hide Help button
  352.     if ((lpfr->Flags & FR_SHOWHELP) == FR_SHOWHELP)
  353.         ShowWindow(GetDlgItem(hWnd, ID_BUTTON_HELP), SW_SHOW);
  354.     else
  355.         ShowWindow(GetDlgItem(hWnd, ID_BUTTON_HELP), SW_HIDE);
  356.  
  357.     // Show find/replace dialog
  358.     ShowWindow(hWnd, SW_SHOW);
  359.     UpdateWindow(hWnd);
  360.  
  361.     return hWnd;
  362. }
  363.  
  364. /////////////////////////////////////////////////////////////////////////////
  365. #endif // _WIN32_WCE_NO_FINDREPLACE
  366.