Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
4.6 KiB

  1. /*++
  2. Copyright (C) 1997-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. // GetTextDlg.cpp : implementation file
  8. //
  9. #include "stdafx.h"
  10. #include "WMITest.h"
  11. #include "GetTextDlg.h"
  12. #include "ClassDlg.h"
  13. #include "QuerySheet.h"
  14. #include "QueryColPg.h"
  15. #include "ClassPg.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CGetTextDlg dialog
  23. CGetTextDlg::CGetTextDlg(CWnd* pParent /*=NULL*/) :
  24. CDialog(CGetTextDlg::IDD, pParent),
  25. m_dwTitleID(0),
  26. m_dwPromptID(0),
  27. m_dwOptionID(0),
  28. m_bEmptyOK(FALSE),
  29. m_bAllowClassBrowse(FALSE),
  30. m_bAllowQueryBrowse(FALSE),
  31. m_pNamespace(NULL)
  32. {
  33. //{{AFX_DATA_INIT(CGetTextDlg)
  34. m_bOptionChecked = FALSE;
  35. //}}AFX_DATA_INIT
  36. }
  37. void CGetTextDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CGetTextDlg)
  41. DDX_Control(pDX, IDC_STRINGS, m_ctlStrings);
  42. DDX_Check(pDX, IDC_OPTION, m_bOptionChecked);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CGetTextDlg, CDialog)
  46. //{{AFX_MSG_MAP(CGetTextDlg)
  47. ON_BN_CLICKED(IDOK, OnOk)
  48. ON_CBN_EDITCHANGE(IDC_STRINGS, OnEditchangeStrings)
  49. ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CGetTextDlg message handlers
  54. void CGetTextDlg::OnOk()
  55. {
  56. GetDlgItemText(IDC_STRINGS, m_strText);
  57. // If we need to save this into the registry, do so.
  58. if (!m_strSection.IsEmpty())
  59. {
  60. POSITION pos;
  61. // See if the item already exists in the list.
  62. if ((pos = m_listItems.Find(m_strText)) != NULL)
  63. m_listItems.RemoveAt(pos);
  64. m_listItems.AddHead(m_strText);
  65. SaveListToReg();
  66. }
  67. CDialog::OnOK();
  68. }
  69. void CGetTextDlg::LoadListViaReg(LPCTSTR szSection, int nItems)
  70. {
  71. m_listItems.RemoveAll();
  72. m_nItems = nItems;
  73. m_strSection = szSection;
  74. for (int i = 0; i < nItems; i++)
  75. {
  76. CString strItem,
  77. strTag;
  78. strTag.Format(_T("f%d"), i);
  79. strItem = theApp.GetProfileString(szSection, strTag, _T("\n"));
  80. if (strItem == _T("\n"))
  81. break;
  82. m_listItems.AddTail(strItem);
  83. }
  84. }
  85. void CGetTextDlg::SaveListToReg()
  86. {
  87. for (int i = 0; i < m_nItems && m_listItems.GetCount(); i++)
  88. {
  89. CString strItem,
  90. strTag;
  91. strTag.Format(_T("f%d"), i);
  92. strItem = m_listItems.RemoveHead();
  93. if (m_bEmptyOK || !strItem.IsEmpty())
  94. theApp.WriteProfileString(m_strSection, strTag, strItem);
  95. }
  96. }
  97. void CGetTextDlg::OnEditchangeStrings()
  98. {
  99. if (!m_bEmptyOK)
  100. {
  101. GetDlgItemText(IDC_STRINGS, m_strText);
  102. GetDlgItem(IDOK)->EnableWindow(!m_strText.IsEmpty());
  103. }
  104. }
  105. BOOL CGetTextDlg::OnInitDialog()
  106. {
  107. CDialog::OnInitDialog();
  108. //m_ctlStrings.LimitText(32000);
  109. for (POSITION pos = m_listItems.GetHeadPosition(); pos != NULL;
  110. m_listItems.GetNext(pos))
  111. {
  112. m_ctlStrings.AddString(m_listItems.GetAt(pos));
  113. }
  114. // Select the first one.
  115. m_ctlStrings.SetCurSel(0);
  116. CString strTemp;
  117. strTemp.LoadString(m_dwTitleID);
  118. SetWindowText(strTemp);
  119. strTemp.LoadString(m_dwPromptID);
  120. SetDlgItemText(IDS_TEXT_PROMPT, strTemp);
  121. if (m_dwOptionID)
  122. {
  123. strTemp.LoadString(m_dwOptionID);
  124. SetDlgItemText(IDC_OPTION, strTemp);
  125. GetDlgItem(IDC_OPTION)->ShowWindow(SW_SHOWNORMAL);
  126. }
  127. if (m_bAllowClassBrowse || m_bAllowQueryBrowse)
  128. GetDlgItem(IDC_BROWSE)->ShowWindow(SW_SHOWNORMAL);
  129. return TRUE; // return TRUE unless you set the focus to a control
  130. // EXCEPTION: OCX Property Pages should return FALSE
  131. }
  132. void CGetTextDlg::OnBrowse()
  133. {
  134. if (m_bAllowClassBrowse)
  135. {
  136. CClassDlg dlg;
  137. dlg.m_pNamespace = m_pNamespace;
  138. if (dlg.DoModal() == IDOK)
  139. m_ctlStrings.SetWindowText(dlg.m_strClass);
  140. }
  141. else if (m_bAllowQueryBrowse)
  142. {
  143. CQuerySheet sheet(IDS_QUERY_WIZARD, this);
  144. CClassPg pgClass;
  145. CQueryColPg pgCols;
  146. sheet.m_psh.dwFlags &= ~PSH_HASHELP;
  147. sheet.m_pNamespace = m_pNamespace;
  148. pgClass.m_psp.dwFlags &= ~PSH_HASHELP;
  149. pgClass.m_pSheet = &sheet;
  150. pgClass.m_strSuperClass = m_strSuperClass;
  151. sheet.AddPage(&pgClass);
  152. pgCols.m_psp.dwFlags &= ~PSH_HASHELP;
  153. pgCols.m_pSheet = &sheet;
  154. sheet.AddPage(&pgCols);
  155. sheet.SetWizardMode();
  156. if (sheet.DoModal() == ID_WIZFINISH)
  157. m_ctlStrings.SetWindowText(sheet.m_strQuery);
  158. }
  159. }