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.

338 lines
7.6 KiB

  1. #include "precomp.h"
  2. /****************************************************************************
  3. *
  4. * FILE: ChConDlg.cpp
  5. *
  6. * CREATED: Chris Pirich (ChrisPi) 6-26-96
  7. *
  8. * CONTENTS: CChooseConfDlg object
  9. *
  10. ****************************************************************************/
  11. #include <ConfWnd.h>
  12. #include "resource.h"
  13. #include "ChConDlg.h"
  14. #include "help_ids.h"
  15. // Dialog ID to Help ID mapping
  16. static const DWORD rgHelpIdsChooseConf[] = {
  17. IDC_STATIC_CONFNAME, IDH_MCU_CONF_MAIN,
  18. IDC_CONFNAME_EDIT, IDH_MCU_CONF_NAME,
  19. IDC_CONFNAME_LISTVIEW, IDH_MCU_CONF_LIST,
  20. 0, 0 // terminator
  21. };
  22. /****************************************************************************
  23. *
  24. * CLASS: CChooseConfDlg
  25. *
  26. * MEMBER: CChooseConfDlg()
  27. *
  28. * PURPOSE: Constructor - initializes variables
  29. *
  30. ****************************************************************************/
  31. CChooseConfDlg::CChooseConfDlg( HWND hwndParent,
  32. PWSTR* ppwszConferences):
  33. m_hwndParent (hwndParent),
  34. m_ppwszConferences (ppwszConferences),
  35. m_hwnd (NULL)
  36. {
  37. DebugEntry(CChooseConfDlg::CChooseConfDlg);
  38. DebugExitVOID(CChooseConfDlg::CChooseConfDlg);
  39. }
  40. /****************************************************************************
  41. *
  42. * CLASS: CChooseConfDlg
  43. *
  44. * MEMBER: DoModal()
  45. *
  46. * PURPOSE: Brings up the modal dialog box
  47. *
  48. ****************************************************************************/
  49. INT_PTR CChooseConfDlg::DoModal()
  50. {
  51. DebugEntry(CChooseConfDlg::DoModal);
  52. INT_PTR nRet = DialogBoxParam( ::GetInstanceHandle(),
  53. MAKEINTRESOURCE(IDD_CHOOSECONF),
  54. m_hwndParent,
  55. CChooseConfDlg::ChooseConfDlgProc,
  56. (LPARAM) this);
  57. DebugExitINT_PTR(CChooseConfDlg::DoModal, nRet);
  58. return nRet;
  59. }
  60. /****************************************************************************
  61. *
  62. * CLASS: CChooseConfDlg
  63. *
  64. * MEMBER: ChooseConfDlgProc()
  65. *
  66. * PURPOSE: Dialog Proc - handles all messages
  67. *
  68. ****************************************************************************/
  69. INT_PTR CALLBACK CChooseConfDlg::ChooseConfDlgProc(HWND hDlg,
  70. UINT uMsg,
  71. WPARAM wParam,
  72. LPARAM lParam)
  73. {
  74. USES_CONVERSION;
  75. BOOL bMsgHandled = FALSE;
  76. // uMsg may be any value.
  77. // wparam may be any value.
  78. // lparam may be any value.
  79. ASSERT(IS_VALID_HANDLE(hDlg, WND));
  80. switch (uMsg)
  81. {
  82. case WM_INITDIALOG:
  83. {
  84. if (NULL != lParam)
  85. {
  86. ((CChooseConfDlg*) lParam)->m_hwnd = hDlg;
  87. ::SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  88. // Create image list and associate it with the list view:
  89. HWND hwndLV = ::GetDlgItem(hDlg, IDC_CONFNAME_LISTVIEW);
  90. if (NULL != hwndLV)
  91. {
  92. BOOL fLoadFail = FALSE;
  93. HIMAGELIST hIML;
  94. hIML = ImageList_Create( 16, 16, ILC_MASK, 1, 0 );
  95. if (NULL == hIML)
  96. {
  97. fLoadFail = TRUE;
  98. }
  99. else
  100. {
  101. HICON hIcon = ::LoadIcon( ::GetInstanceHandle(),
  102. MAKEINTRESOURCE(IDI_NET));
  103. if ((NULL == hIcon) ||
  104. (-1 == ImageList_AddIcon(hIML, hIcon)))
  105. {
  106. fLoadFail = TRUE;
  107. break;
  108. }
  109. ::DestroyIcon(hIcon);
  110. }
  111. if (FALSE == fLoadFail)
  112. {
  113. // Associate the image list with the list view
  114. ListView_SetImageList(hwndLV, hIML, LVSIL_SMALL);
  115. }
  116. // TODO: init conf list and name
  117. PWSTR* ppwszConfNames = ((CChooseConfDlg*) lParam)->m_ppwszConferences;
  118. ASSERT(ppwszConfNames);
  119. int i = 0;
  120. int iItems = 0;
  121. while (NULL != ppwszConfNames[i])
  122. {
  123. // skip empty strings
  124. if ( 0 != *ppwszConfNames[i] )
  125. {
  126. LV_ITEM lvI; // List view item structure
  127. // Fill in the LV_ITEM structure
  128. // The mask specifies the the .pszText, .iImage, .lParam and .state
  129. // members of the LV_ITEM structure are valid.
  130. lvI.mask = LVIF_TEXT | LVIF_IMAGE | /* LVIF_PARAM | */ LVIF_STATE;
  131. // put focus on first item
  132. lvI.state = (0 == iItems) ?
  133. (LVIS_FOCUSED | LVIS_SELECTED) : 0;
  134. lvI.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  135. lvI.iItem = iItems;
  136. lvI.iSubItem = 0;
  137. // The parent window is responsible for storing the text. The List view
  138. // window will send a LVN_GETDISPINFO when it needs the text to display/
  139. lvI.pszText = W2T(ppwszConfNames[i]);
  140. lvI.iImage = 0;
  141. // lvI.lParam = 0;
  142. if (-1 == ListView_InsertItem(hwndLV, &lvI))
  143. {
  144. ERROR_OUT(("Failed inserting item into list view"));
  145. }
  146. if (0 == iItems)
  147. {
  148. ::SetDlgItemText(hDlg, IDC_CONFNAME_EDIT, lvI.pszText);
  149. }
  150. iItems++;
  151. }
  152. i++;
  153. }
  154. }
  155. }
  156. ::SetFocus(::GetDlgItem(hDlg, IDC_CONFNAME_EDIT));
  157. ::SendDlgItemMessage(hDlg, IDC_CONFNAME_EDIT, EM_SETSEL, 0, (LPARAM)-1);
  158. RefreshOk(hDlg);
  159. bMsgHandled = FALSE; // return FALSE because we set the focus
  160. break;
  161. }
  162. case WM_CONTEXTMENU:
  163. DoHelpWhatsThis(wParam, rgHelpIdsChooseConf);
  164. break;
  165. case WM_HELP:
  166. DoHelp(lParam, rgHelpIdsChooseConf);
  167. break;
  168. default:
  169. {
  170. CChooseConfDlg* pccd = (CChooseConfDlg*) ::GetWindowLongPtr( hDlg,
  171. DWLP_USER);
  172. if (NULL != pccd)
  173. {
  174. bMsgHandled = pccd->ProcessMessage(uMsg, wParam, lParam);
  175. }
  176. }
  177. }
  178. return bMsgHandled;
  179. }
  180. /****************************************************************************
  181. *
  182. * CLASS: CChooseConfDlg
  183. *
  184. * MEMBER: ProcessMessage()
  185. *
  186. * PURPOSE: processes all messages except WM_INITDIALOG
  187. *
  188. ****************************************************************************/
  189. BOOL CChooseConfDlg::ProcessMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  190. {
  191. BOOL bRet = FALSE;
  192. ASSERT(m_hwnd);
  193. switch (uMsg)
  194. {
  195. case WM_COMMAND:
  196. {
  197. switch (LOWORD(wParam))
  198. {
  199. case IDOK:
  200. {
  201. // BUGBUG: how long can a conf name be?
  202. TCHAR szName[MAX_PATH];
  203. if (0 != ::GetDlgItemText( m_hwnd,
  204. IDC_CONFNAME_EDIT,
  205. szName,
  206. CCHMAX(szName)))
  207. {
  208. bRet = OnOk(szName);
  209. }
  210. break;
  211. }
  212. case IDCANCEL:
  213. {
  214. ::EndDialog(m_hwnd, LOWORD(wParam));
  215. bRet = TRUE;
  216. break;
  217. }
  218. case IDC_CONFNAME_EDIT:
  219. {
  220. if (EN_CHANGE == HIWORD(wParam))
  221. {
  222. RefreshOk(m_hwnd);
  223. }
  224. break;
  225. }
  226. }
  227. break;
  228. }
  229. case WM_NOTIFY:
  230. {
  231. if (IDC_CONFNAME_LISTVIEW == wParam)
  232. {
  233. NM_LISTVIEW* pnmv = (NM_LISTVIEW*) lParam;
  234. ASSERT(pnmv);
  235. if ((LVN_ITEMCHANGED == pnmv->hdr.code) &&
  236. (LVIS_SELECTED & pnmv->uNewState))
  237. {
  238. TCHAR szName[MAX_PATH];
  239. if (GetConferenceName(pnmv->iItem, szName, CCHMAX(szName)))
  240. {
  241. ::SetDlgItemText(m_hwnd, IDC_CONFNAME_EDIT, szName);
  242. }
  243. }
  244. else if (NM_DBLCLK == pnmv->hdr.code)
  245. {
  246. int idx = ListView_GetNextItem(
  247. ::GetDlgItem(m_hwnd, IDC_CONFNAME_LISTVIEW),
  248. -1,
  249. LVNI_FOCUSED | LVNI_SELECTED);
  250. if (idx != -1)
  251. {
  252. TCHAR szName[MAX_PATH];
  253. if (GetConferenceName(idx, szName, CCHMAX(szName)))
  254. {
  255. OnOk(szName);
  256. }
  257. }
  258. }
  259. }
  260. break;
  261. }
  262. default:
  263. break;
  264. }
  265. return bRet;
  266. }
  267. BOOL CChooseConfDlg::GetConferenceName(int iItem, LPTSTR pszName, int cchName)
  268. {
  269. LV_ITEM lvI;
  270. lvI.mask = LVIF_TEXT;
  271. lvI.iItem = iItem;
  272. lvI.iSubItem = 0;
  273. lvI.pszText = pszName;
  274. lvI.cchTextMax = cchName;
  275. return ListView_GetItem(
  276. ::GetDlgItem(m_hwnd, IDC_CONFNAME_LISTVIEW),
  277. &lvI);
  278. }
  279. void CChooseConfDlg::RefreshOk(HWND hwnd)
  280. {
  281. BOOL fEnable = 0 != ::GetWindowTextLength(
  282. GetDlgItem(hwnd, IDC_CONFNAME_EDIT));
  283. ::EnableWindow(GetDlgItem(hwnd, IDOK), fEnable);
  284. }
  285. BOOL CChooseConfDlg::OnOk(LPTSTR pszName)
  286. {
  287. DebugEntry(CChooseConfDlg::OnOk);
  288. BOOL bRet = TRUE;
  289. m_strConfName = pszName;
  290. ::EndDialog(m_hwnd, IDOK);
  291. DebugExitBOOL(CChooseConfDlg::OnOk, bRet);
  292. return bRet;
  293. }
  294.