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.

283 lines
7.0 KiB

  1. /////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998 Active Voice Corporation. All Rights Reserved.
  4. //
  5. // Active Agent(r) and Unified Communications(tm) are trademarks of Active Voice Corporation.
  6. //
  7. // Other brand and product names used herein are trademarks of their respective owners.
  8. //
  9. // The entire program and user interface including the structure, sequence, selection,
  10. // and arrangement of the dialog, the exclusively "yes" and "no" choices represented
  11. // by "1" and "2," and each dialog message are protected by copyrights registered in
  12. // the United States and by international treaties.
  13. //
  14. // Protected by one or more of the following United States patents: 5,070,526, 5,488,650,
  15. // 5,434,906, 5,581,604, 5,533,102, 5,568,540, 5,625,676, 5,651,054.
  16. //
  17. // Active Voice Corporation
  18. // Seattle, Washington
  19. // USA
  20. //
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. ////
  23. // dlg.c - dialog box functions
  24. ////
  25. #include "winlocal.h"
  26. #include <stdlib.h>
  27. #include "dlg.h"
  28. #include "mem.h"
  29. #include "stack.h"
  30. #include "trace.h"
  31. #include "wnd.h"
  32. ////
  33. // private definitions
  34. ////
  35. // dlg control struct
  36. //
  37. typedef struct DLG
  38. {
  39. DWORD dwVersion;
  40. HINSTANCE hInst;
  41. HTASK hTask;
  42. HSTACK hStack;
  43. } DLG, FAR *LPDLG;
  44. // helper functions
  45. //
  46. static LPDLG DlgGetPtr(HDLG hDlg);
  47. static HDLG DlgGetHandle(LPDLG lpDlg);
  48. ////
  49. // public functions
  50. ////
  51. // DlgInit - initialize dlg engine
  52. // <dwVersion> (i) must be DLG_VERSION
  53. // <hInst> (i) instance handle of calling module
  54. // return handle (NULL if error)
  55. //
  56. HDLG DLLEXPORT WINAPI DlgInit(DWORD dwVersion, HINSTANCE hInst)
  57. {
  58. BOOL fSuccess = TRUE;
  59. LPDLG lpDlg = NULL;
  60. if (dwVersion != DLG_VERSION)
  61. fSuccess = TraceFALSE(NULL);
  62. else if (hInst == NULL)
  63. fSuccess = TraceFALSE(NULL);
  64. else if ((lpDlg = (LPDLG) MemAlloc(NULL, sizeof(DLG), 0)) == NULL)
  65. fSuccess = TraceFALSE(NULL);
  66. else if ((lpDlg->hStack = StackCreate(STACK_VERSION, hInst)) == NULL)
  67. fSuccess = TraceFALSE(NULL);
  68. else
  69. {
  70. lpDlg->dwVersion = dwVersion;
  71. lpDlg->hInst = hInst;
  72. lpDlg->hTask = GetCurrentTask();
  73. }
  74. if (!fSuccess)
  75. {
  76. DlgTerm(DlgGetHandle(lpDlg));
  77. lpDlg = NULL;
  78. }
  79. return fSuccess ? DlgGetHandle(lpDlg) : NULL;
  80. }
  81. // DlgTerm - shut down dlg engine
  82. // <hDlg> (i) handle returned from DlgInit
  83. // return 0 if success
  84. //
  85. int DLLEXPORT WINAPI DlgTerm(HDLG hDlg)
  86. {
  87. BOOL fSuccess = TRUE;
  88. LPDLG lpDlg;
  89. if ((lpDlg = DlgGetPtr(hDlg)) == NULL)
  90. fSuccess = TraceFALSE(NULL);
  91. else if (StackDestroy(lpDlg->hStack) != 0)
  92. fSuccess = TraceFALSE(NULL);
  93. else if ((lpDlg = MemFree(NULL, lpDlg)) != NULL)
  94. fSuccess = TraceFALSE(NULL);
  95. return fSuccess ? 0 : -1;
  96. }
  97. // DlgInitDialog - perform standard dialog box initialization
  98. // <hDlg> (i) handle returned from DlgInit
  99. // <hwndDlg> (i) dialog box to be initialized
  100. // <hwndCenter> (i) center dialog box upon this window
  101. // NULL center dialog box on its parent
  102. // <dwFlags> (i) control flags
  103. // DLG_NOCENTER do not center dialog box at all
  104. // return 0 if success
  105. //
  106. int DLLEXPORT WINAPI DlgInitDialog(HDLG hDlg, HWND hwndDlg, HWND hwndCenter, DWORD dwFlags)
  107. {
  108. BOOL fSuccess = TRUE;
  109. LPDLG lpDlg;
  110. HWND hwndParent;
  111. HTASK hTaskParent;
  112. if ((lpDlg = DlgGetPtr(hDlg)) == NULL)
  113. fSuccess = TraceFALSE(NULL);
  114. else if (hwndDlg == NULL)
  115. fSuccess = TraceFALSE(NULL);
  116. else if ((hTaskParent = lpDlg->hTask) == NULL, FALSE)
  117. ;
  118. else if ((hwndParent = GetParent(hwndDlg)) != NULL &&
  119. (hTaskParent = GetWindowTask(hwndParent)) == NULL, FALSE)
  120. ;
  121. // disable all task windows except dialog box
  122. //
  123. else if (WndEnableTaskWindows(hTaskParent, FALSE, hwndDlg) != 0)
  124. fSuccess = TraceFALSE(NULL);
  125. // center the dialog box if necessary
  126. //
  127. else if (!(dwFlags & DLG_NOCENTER) &&
  128. WndCenterWindow(hwndDlg, hwndCenter, 0, 0) != 0)
  129. fSuccess = TraceFALSE(NULL);
  130. // keep track of current dialog box
  131. //
  132. else if (StackPush(lpDlg->hStack, (STACKELEM) hwndDlg) != 0)
  133. fSuccess = TraceFALSE(NULL);
  134. return fSuccess ? 0 : -1;
  135. }
  136. // DlgEndDialog - perform standard dialog box shutdown
  137. // <hDlg> (i) handle returned from DlgInit
  138. // <hwndDlg> (i) dialog box to be shutdown
  139. // <nResult> (i) dialog box result code
  140. // return 0 if success
  141. //
  142. int DLLEXPORT WINAPI DlgEndDialog(HDLG hDlg, HWND hwndDlg, int nResult)
  143. {
  144. BOOL fSuccess = TRUE;
  145. LPDLG lpDlg;
  146. HWND hwndParent;
  147. HTASK hTaskParent;
  148. if ((lpDlg = DlgGetPtr(hDlg)) == NULL)
  149. fSuccess = TraceFALSE(NULL);
  150. else if (hwndDlg == NULL)
  151. fSuccess = TraceFALSE(NULL);
  152. else if ((hTaskParent = lpDlg->hTask) == NULL, FALSE)
  153. ;
  154. else if ((hwndParent = GetParent(hwndDlg)) != NULL &&
  155. (hTaskParent = GetWindowTask(hwndParent)) == NULL, FALSE)
  156. ;
  157. else if (hwndDlg != (HWND) StackPeek(lpDlg->hStack))
  158. fSuccess = TraceFALSE(NULL);
  159. else
  160. {
  161. // hide modal dialog box, nResult will be returned by DialogBox().
  162. //
  163. EndDialog(hwndDlg, nResult);
  164. // remove this dialog box handle from stack
  165. //
  166. StackPop(lpDlg->hStack);
  167. // enable all task windows
  168. //
  169. if (WndEnableTaskWindows(hTaskParent, TRUE, NULL) != 0)
  170. fSuccess = TraceFALSE(NULL);
  171. }
  172. return fSuccess ? 0 : -1;
  173. }
  174. // DlgGetCurrentDialog - get handle of current dialog box
  175. // <hDlg> (i) handle returned from DlgInit
  176. // return window handle (NULL if no dialog box up)
  177. //
  178. HWND DLLEXPORT WINAPI DlgGetCurrentDialog(HDLG hDlg)
  179. {
  180. BOOL fSuccess = TRUE;
  181. LPDLG lpDlg;
  182. if ((lpDlg = DlgGetPtr(hDlg)) == NULL)
  183. fSuccess = TraceFALSE(NULL);
  184. return fSuccess ? (HWND) StackPeek(lpDlg->hStack) : NULL;
  185. }
  186. // DlgOnCtlColor - handle WM_CTLCOLOR message sent to dialog
  187. // <hwndDlg> (i) dialog box handle
  188. // <hdc> (i) display context for child window
  189. // <hwndChild> (i) control window handle
  190. // <nCtlType> (i) control type (CTLCOLOR_BTN, CTLCOLOR_EDIT, etc)
  191. HBRUSH DLLEXPORT WINAPI DlgOnCtlColor(HWND hwndDlg, HDC hdc, HWND hwndChild, int nCtlType)
  192. {
  193. return (HBRUSH) NULL;
  194. }
  195. ////
  196. // helper functions
  197. ////
  198. // DlgGetPtr - verify that dlg handle is valid,
  199. // <hDlg> (i) handle returned from DlgInit
  200. // return corresponding dlg pointer (NULL if error)
  201. //
  202. static LPDLG DlgGetPtr(HDLG hDlg)
  203. {
  204. BOOL fSuccess = TRUE;
  205. LPDLG lpDlg;
  206. if ((lpDlg = (LPDLG) hDlg) == NULL)
  207. fSuccess = TraceFALSE(NULL);
  208. else if (IsBadWritePtr(lpDlg, sizeof(DLG)))
  209. fSuccess = TraceFALSE(NULL);
  210. #ifdef CHECKTASK
  211. // make sure current task owns the dlg handle
  212. //
  213. else if (lpDlg->hTask != GetCurrentTask())
  214. fSuccess = TraceFALSE(NULL);
  215. #endif
  216. return fSuccess ? lpDlg : NULL;
  217. }
  218. // DlgGetHandle - verify that dlg pointer is valid,
  219. // <lpDlg> (i) pointer to DLG struct
  220. // return corresponding dlg handle (NULL if error)
  221. //
  222. static HDLG DlgGetHandle(LPDLG lpDlg)
  223. {
  224. BOOL fSuccess = TRUE;
  225. HDLG hDlg;
  226. if ((hDlg = (HDLG) lpDlg) == NULL)
  227. fSuccess = TraceFALSE(NULL);
  228. return fSuccess ? hDlg : NULL;
  229. }