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.

179 lines
4.9 KiB

  1. /**************************** Module Header ********************************\
  2. * Module Name: combodir.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * Directory Combo Box Routines
  7. *
  8. * History:
  9. * ??-???-???? ?????? Ported from Win 3.0 sources
  10. * 01-Feb-1991 mikeke Added Revalidation code
  11. \***************************************************************************/
  12. #include "ctlspriv.h"
  13. #pragma hdrstop
  14. #include "UsrCtl32.h"
  15. #include "Combo.h"
  16. #include "Listbox.h"
  17. /***************************************************************************\
  18. * CBDir
  19. *
  20. * Supports the CB_DIR message which adds a list of files from the
  21. * current directory to the combo box.
  22. *
  23. * History:
  24. \***************************************************************************/
  25. int CBDir(PCBOX pcbox, UINT attrib, LPWSTR pFileName)
  26. {
  27. PLBIV plb;
  28. int errorValue;
  29. UserAssert(pcbox->hwndList);
  30. plb = ListBox_GetPtr(pcbox->hwndList);
  31. errorValue = ListBox_DirHandler(plb, attrib, pFileName);
  32. switch (errorValue)
  33. {
  34. case LB_ERR:
  35. return CB_ERR;
  36. break;
  37. case LB_ERRSPACE:
  38. return CB_ERRSPACE;
  39. break;
  40. default:
  41. return errorValue;
  42. break;
  43. }
  44. }
  45. //#define INCLUDE_COMBOBOX_FUNCTIONS
  46. #ifdef INCLUDE_COMBOBOX_FUNCTIONS
  47. /***************************************************************************\
  48. * DlgDirSelectComboBoxEx
  49. *
  50. * Retrieves the current selection from the listbox of a combobox.
  51. * It assumes that the combo box was filled by DlgDirListComboBox()
  52. * and that the selection is a drive letter, a file, or a directory name.
  53. *
  54. * History:
  55. * 12-05-90 IanJa converted to internal version
  56. \***************************************************************************/
  57. int DlgDirSelectComboBoxExA(
  58. HWND hwndDlg,
  59. LPSTR pszOut,
  60. int cchOut,
  61. int idComboBox)
  62. {
  63. LPWSTR lpwsz;
  64. BOOL fRet;
  65. lpwsz = (LPWSTR)UserLocalAlloc(HEAP_ZERO_MEMORY, cchOut * sizeof(WCHAR));
  66. if (!lpwsz) {
  67. return FALSE;
  68. }
  69. fRet = DlgDirSelectComboBoxExW(hwndDlg, lpwsz, cchOut, idComboBox);
  70. WCSToMB(lpwsz, -1, &pszOut, cchOut, FALSE);
  71. UserLocalFree(lpwsz);
  72. return fRet;
  73. }
  74. int DlgDirSelectComboBoxExW(
  75. HWND hwndDlg,
  76. LPWSTR pwszOut,
  77. int cchOut,
  78. int idComboBox)
  79. {
  80. HWND hwndComboBox;
  81. PCBOX pcbox;
  82. if (hwndDlg == NULL)
  83. return FALSE;
  84. hwndComboBox = GetDlgItem(hwndDlg, idComboBox);
  85. if (hwndComboBox == NULL) {
  86. TraceMsg(TF_STANDARD, "ControlId = %d not found in Dlg = %#.4x", idComboBox, hwndDlg);
  87. return 0;
  88. }
  89. pcbox = ComboBox_GetPtr(hwndComboBox);
  90. if (pcbox == NULL) {
  91. TraceMsg(TF_STANDARD, "ControlId = %d is not a combobox", idComboBox);
  92. return 0;
  93. }
  94. return DlgDirSelectHelper(pwszOut, cchOut, pcbox->hwndList);
  95. }
  96. /***************************************************************************\
  97. * DlgDirListComboBox
  98. *
  99. * History:
  100. * 12-05-90 IanJa converted to internal version
  101. \***************************************************************************/
  102. int DlgDirListComboBoxA(
  103. HWND hwndDlg,
  104. LPSTR lpszPathSpecClient,
  105. int idComboBox,
  106. int idStaticPath,
  107. UINT attrib)
  108. {
  109. LPWSTR lpszPathSpec;
  110. BOOL fRet;
  111. if (hwndDlg == NULL)
  112. return FALSE;
  113. lpszPathSpec = NULL;
  114. if (lpszPathSpecClient) {
  115. if (!MBToWCS(lpszPathSpecClient, -1, &lpszPathSpec, -1, TRUE))
  116. return FALSE;
  117. }
  118. fRet = DlgDirListHelper(hwndDlg, lpszPathSpec, lpszPathSpecClient,
  119. idComboBox, idStaticPath, attrib, FALSE);
  120. if (lpszPathSpec) {
  121. if (fRet) {
  122. /*
  123. * Non-zero retval means some text to copy out. Copy out up to
  124. * the nul terminator (buffer will be big enough).
  125. */
  126. WCSToMB(lpszPathSpec, -1, &lpszPathSpecClient, MAXLONG, FALSE);
  127. }
  128. UserLocalFree(lpszPathSpec);
  129. }
  130. return fRet;
  131. }
  132. int DlgDirListComboBoxW(
  133. HWND hwndDlg,
  134. LPWSTR lpszPathSpecClient,
  135. int idComboBox,
  136. int idStaticPath,
  137. UINT attrib)
  138. {
  139. LPWSTR lpszPathSpec;
  140. BOOL fRet;
  141. if (hwndDlg == NULL)
  142. return FALSE;
  143. lpszPathSpec = lpszPathSpecClient;
  144. fRet = DlgDirListHelper(hwndDlg, lpszPathSpec, (LPBYTE)lpszPathSpecClient,
  145. idComboBox, idStaticPath, attrib, FALSE);
  146. return fRet;
  147. }
  148. #endif // INCLUDE_COMBOBOX_FUNCTIONS