Leaked source code of windows server 2003
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.

353 lines
8.8 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. #include "ConfUtil.h"
  16. // Dialog ID to Help ID mapping
  17. static const DWORD rgHelpIdsChooseConf[] = {
  18. IDC_STATIC_CONFNAME, IDH_MCU_CONF_MAIN,
  19. IDC_CONFNAME_EDIT, IDH_MCU_CONF_NAME,
  20. IDC_CONFNAME_LISTVIEW, IDH_MCU_CONF_LIST,
  21. 0, 0 // terminator
  22. };
  23. /****************************************************************************
  24. *
  25. * CLASS: CChooseConfDlg
  26. *
  27. * MEMBER: CChooseConfDlg()
  28. *
  29. * PURPOSE: Constructor - initializes variables
  30. *
  31. ****************************************************************************/
  32. CChooseConfDlg::CChooseConfDlg( HWND hwndParent,
  33. PWSTR* ppwszConferences):
  34. m_hwndParent (hwndParent),
  35. m_ppwszConferences (ppwszConferences),
  36. m_hwnd (NULL)
  37. {
  38. DebugEntry(CChooseConfDlg::CChooseConfDlg);
  39. DebugExitVOID(CChooseConfDlg::CChooseConfDlg);
  40. }
  41. /****************************************************************************
  42. *
  43. * CLASS: CChooseConfDlg
  44. *
  45. * MEMBER: DoModal()
  46. *
  47. * PURPOSE: Brings up the modal dialog box
  48. *
  49. ****************************************************************************/
  50. INT_PTR CChooseConfDlg::DoModal()
  51. {
  52. DebugEntry(CChooseConfDlg::DoModal);
  53. INT_PTR nRet = DialogBoxParam( ::GetInstanceHandle(),
  54. MAKEINTRESOURCE(IDD_CHOOSECONF),
  55. m_hwndParent,
  56. CChooseConfDlg::ChooseConfDlgProc,
  57. (LPARAM) this);
  58. DebugExitINT_PTR(CChooseConfDlg::DoModal, nRet);
  59. return nRet;
  60. }
  61. /****************************************************************************
  62. *
  63. * CLASS: CChooseConfDlg
  64. *
  65. * MEMBER: ChooseConfDlgProc()
  66. *
  67. * PURPOSE: Dialog Proc - handles all messages
  68. *
  69. ****************************************************************************/
  70. INT_PTR CALLBACK CChooseConfDlg::ChooseConfDlgProc(HWND hDlg,
  71. UINT uMsg,
  72. WPARAM wParam,
  73. LPARAM lParam)
  74. {
  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. LPTSTR szName;
  140. BSTR bstrName = ::SysAllocString(ppwszConfNames[i]);
  141. if(bstrName)
  142. {
  143. if(SUCCEEDED(BSTR_to_LPTSTR(&szName,bstrName)))
  144. {
  145. lvI.pszText = szName;
  146. lvI.iImage = 0;
  147. // lvI.lParam = 0;
  148. if (-1 == ListView_InsertItem(hwndLV, &lvI))
  149. {
  150. ERROR_OUT(("Failed inserting item into list view"));
  151. }
  152. if (0 == iItems)
  153. {
  154. ::SetDlgItemText(hDlg, IDC_CONFNAME_EDIT, lvI.pszText);
  155. }
  156. iItems++;
  157. delete szName;
  158. }
  159. SysFreeString(bstrName);
  160. }
  161. }
  162. i++;
  163. }
  164. }
  165. }
  166. ::SetFocus(::GetDlgItem(hDlg, IDC_CONFNAME_EDIT));
  167. ::SendDlgItemMessage(hDlg, IDC_CONFNAME_EDIT, EM_SETSEL, 0, (LPARAM)-1);
  168. RefreshOk(hDlg);
  169. bMsgHandled = FALSE; // return FALSE because we set the focus
  170. break;
  171. }
  172. case WM_CONTEXTMENU:
  173. DoHelpWhatsThis(wParam, rgHelpIdsChooseConf);
  174. break;
  175. case WM_HELP:
  176. DoHelp(lParam, rgHelpIdsChooseConf);
  177. break;
  178. default:
  179. {
  180. CChooseConfDlg* pccd = (CChooseConfDlg*) ::GetWindowLongPtr( hDlg,
  181. DWLP_USER);
  182. if (NULL != pccd)
  183. {
  184. bMsgHandled = pccd->ProcessMessage(uMsg, wParam, lParam);
  185. }
  186. }
  187. }
  188. return bMsgHandled;
  189. }
  190. /****************************************************************************
  191. *
  192. * CLASS: CChooseConfDlg
  193. *
  194. * MEMBER: ProcessMessage()
  195. *
  196. * PURPOSE: processes all messages except WM_INITDIALOG
  197. *
  198. ****************************************************************************/
  199. BOOL CChooseConfDlg::ProcessMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  200. {
  201. BOOL bRet = FALSE;
  202. ASSERT(m_hwnd);
  203. switch (uMsg)
  204. {
  205. case WM_COMMAND:
  206. {
  207. switch (LOWORD(wParam))
  208. {
  209. case IDOK:
  210. {
  211. // BUGBUG: how long can a conf name be?
  212. TCHAR szName[MAX_PATH];
  213. if (0 != ::GetDlgItemText( m_hwnd,
  214. IDC_CONFNAME_EDIT,
  215. szName,
  216. CCHMAX(szName)))
  217. {
  218. bRet = OnOk(szName);
  219. }
  220. break;
  221. }
  222. case IDCANCEL:
  223. {
  224. ::EndDialog(m_hwnd, LOWORD(wParam));
  225. bRet = TRUE;
  226. break;
  227. }
  228. case IDC_CONFNAME_EDIT:
  229. {
  230. if (EN_CHANGE == HIWORD(wParam))
  231. {
  232. RefreshOk(m_hwnd);
  233. }
  234. break;
  235. }
  236. }
  237. break;
  238. }
  239. case WM_NOTIFY:
  240. {
  241. if (IDC_CONFNAME_LISTVIEW == wParam)
  242. {
  243. NM_LISTVIEW* pnmv = (NM_LISTVIEW*) lParam;
  244. ASSERT(pnmv);
  245. if ((LVN_ITEMCHANGED == pnmv->hdr.code) &&
  246. (LVIS_SELECTED & pnmv->uNewState))
  247. {
  248. TCHAR szName[MAX_PATH];
  249. if (GetConferenceName(pnmv->iItem, szName, CCHMAX(szName)))
  250. {
  251. ::SetDlgItemText(m_hwnd, IDC_CONFNAME_EDIT, szName);
  252. }
  253. }
  254. else if (NM_DBLCLK == pnmv->hdr.code)
  255. {
  256. int idx = ListView_GetNextItem(
  257. ::GetDlgItem(m_hwnd, IDC_CONFNAME_LISTVIEW),
  258. -1,
  259. LVNI_FOCUSED | LVNI_SELECTED);
  260. if (idx != -1)
  261. {
  262. TCHAR szName[MAX_PATH];
  263. if (GetConferenceName(idx, szName, CCHMAX(szName)))
  264. {
  265. OnOk(szName);
  266. }
  267. }
  268. }
  269. }
  270. break;
  271. }
  272. default:
  273. break;
  274. }
  275. return bRet;
  276. }
  277. BOOL CChooseConfDlg::GetConferenceName(int iItem, LPTSTR pszName, int cchName)
  278. {
  279. LV_ITEM lvI;
  280. lvI.mask = LVIF_TEXT;
  281. lvI.iItem = iItem;
  282. lvI.iSubItem = 0;
  283. lvI.pszText = pszName;
  284. lvI.cchTextMax = cchName;
  285. return ListView_GetItem(
  286. ::GetDlgItem(m_hwnd, IDC_CONFNAME_LISTVIEW),
  287. &lvI);
  288. }
  289. void CChooseConfDlg::RefreshOk(HWND hwnd)
  290. {
  291. BOOL fEnable = 0 != ::GetWindowTextLength(
  292. GetDlgItem(hwnd, IDC_CONFNAME_EDIT));
  293. ::EnableWindow(GetDlgItem(hwnd, IDOK), fEnable);
  294. }
  295. BOOL CChooseConfDlg::OnOk(LPTSTR pszName)
  296. {
  297. DebugEntry(CChooseConfDlg::OnOk);
  298. BOOL bRet = TRUE;
  299. m_strConfName = pszName;
  300. ::EndDialog(m_hwnd, IDOK);
  301. DebugExitBOOL(CChooseConfDlg::OnOk, bRet);
  302. return bRet;
  303. }
  304.