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.

502 lines
14 KiB

  1. //---------------------------------------------------------------------------
  2. // rgndlg.h
  3. //---------------------------------------------------------------------------
  4. // Copyright (c) 1995 Microsoft Corporation
  5. // All Rights Reserved
  6. // Information Contained Herein Is Propretary and Confidential.
  7. //---------------------------------------------------------------------------
  8. //
  9. // This module contains header info for regional dialog boxes. The drawing and positioning
  10. // logic was adapted from the class CBobDialog. (Used in the Microsoft "Bob" product.)
  11. //
  12. //---------------------------------------------------------------------------
  13. /*
  14. * Important background information
  15. *
  16. CRgnDialog was taken from "CBobDialog" source. The CBobDialog class inherited from
  17. CDialog, and also had functionality specific to "Bob" (custom pallettes,
  18. global knowledge of the "guide" character, custom cursors for these dialogs,
  19. autoclose upon global system events).
  20. The first modification was to strip out all references to the "Bob" system. Next,
  21. MFC dependencies were also stripped out in order to provide a very lightweight
  22. implementation of the regional dialog functionality, and to provide C clients with
  23. APIs compatible with DialogBox(), DialogBoxParam(), CreateDialog(), and
  24. CreateDialogParam(). Many MFC references remain within "#ifdef MFC" directives.
  25. This will not compile if MFC is defined!
  26. The intent is to suppport MFC AND C clients from the same source base. This is the
  27. only way to ensure that appearance remains consistent across different build
  28. environments. The MFC references remain commented out so that re-integration will
  29. take less effort.
  30. *
  31. *
  32. */
  33. #if !defined(__RGNDLG_H__)
  34. #define __RGNDLG_H__
  35. #if !defined (STRICT)
  36. #define STRICT
  37. #endif // !defined(STRICT)
  38. #include <windows.h>
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. //
  43. // Dialog styles
  44. //
  45. #define RGNSTYLE_NOSTEM 0x00000000
  46. #define RGNSTYLE_SPEAK 0x00010000
  47. #define RGNSTYLE_THINK 0x00020000
  48. #define RGNSTYLE_ARROW 0x00030000
  49. #define RGNSTYLE_POINT 0x00040000
  50. //#define RGNSTYLE_TRANSPARENT 0x00050000 // not yet implemented
  51. #define RGNSTYLE_MINPOINTER RGNSTYLE_SPEAK
  52. #define RGNSTYLE_MAXPOINTER RGNSTYLE_POINT
  53. #define RGNSTYLE_MAX RGNSTYLE_POINT
  54. // RgnDialogBox, RgnDialogBoxParam flags
  55. #define RGNDLG_NOAUTOSIZE 0x00000008
  56. #define RGNDLG_NOMOVE 0x00000010
  57. // #define RGNDLG_ALLOWCAPTION 0x00000100 // future implementation
  58. //
  59. // C wrapper replacements for DialogBox[param]() and CreateDialog[param]()
  60. //
  61. int RgnDialogBox(RECT *pClientRect,ULONG fFlags,ULONG style,HINSTANCE hInst,
  62. LPCSTR lpszDlgTemp,HWND hWndOwner, DLGPROC ClientDlgPrc);
  63. int RgnDialogBoxParam(RECT *pClientRect,ULONG fFlags,ULONG style,HINSTANCE hInst,
  64. LPCSTR lpszDlgTemp, HWND hWndOwner, DLGPROC ClientDlgPrc, LPARAM lParamInit);
  65. HWND CreateRgnDialogParam(RECT *pClientRect,ULONG fFlags,ULONG style, HINSTANCE hInst,
  66. LPCSTR lpszDlgTemp,HWND hWndOwner,DLGPROC ClientDlgPrc,LPARAM lParamInit);
  67. HWND CreateRgnDialog(RECT *pClientRect,ULONG fFlags,ULONG style,HINSTANCE hInst,
  68. LPCSTR lpszDlgTemp,HWND hWndOwner, DLGPROC ClientDlgPrc);
  69. #ifdef __cplusplus
  70. } // extern "C"
  71. #endif
  72. //
  73. // C clients do not need the rest of this
  74. //
  75. #ifdef __cplusplus
  76. typedef ULONG RgnDlgStyle;
  77. #define MAKE_RGNDLG_VALID(f) ((f) & (RGNDLG_NOAUTOSIZE | RGNDLG_NOMOVE))
  78. #define IsStemValid(s) ((s == RGNSTYLE_NOSTEM) || ((s >= RGNSTYLE_MINPOINTER) && (s <= RGNSTYLE_MAXPOINTER)))
  79. #define StemFromStyle(s) (Stem)((IsStemValid(s))? (s) : RGNSTYLE_NOSTEM)
  80. // CRgnDialog flags
  81. const ULONG kfDlgAutoclose = 0x00000001;
  82. const ULONG kfDlgModal = 0x00000002;
  83. const ULONG kfDlgNoActivate = 0x00000004;
  84. const ULONG kfDlgNoSize = RGNDLG_NOAUTOSIZE;
  85. const ULONG kfDlgNoMove = RGNDLG_NOMOVE;
  86. const ULONG kfDlgAutodelete = 0x00000020;
  87. const ULONG kfDlgParamInit = 0x00000040;
  88. // Transparent dialogs have no stem. If this flag is set by C++ client and a stem type
  89. // also exists, the stem type is ignored.
  90. //const ULONG kfDlgTransparent = 0x00000080;
  91. // captions could be allowed if some cosmetic tweaking is applied
  92. // const ULONG kfDlgAllowCaption = RGNDLG_ALLOWCAPTION;
  93. const ULONG kfDlgValid = (kfDlgAutoclose | kfDlgModal | kfDlgNoActivate |
  94. kfDlgNoSize | kfDlgNoMove | kfDlgAutodelete | kfDlgParamInit);
  95. // Internal flag state
  96. const ULONG kfxDlgChildrenCreated = 0x00000001;
  97. const ULONG kfxDlgPosDone = 0x00000002;
  98. const ULONG kfxDlgSizeDone = 0x00000004;
  99. // Stem, StemSide, StemType
  100. typedef ULONG Stem; // st
  101. typedef ULONG StemSide; // ss
  102. typedef ULONG StemType; // stt
  103. // Stem types
  104. const StemType ksttNone = 0x00000000;
  105. const StemType ksttSpeak = 0x00010000;
  106. const StemType ksttThink = 0x00020000;
  107. const StemType ksttArrow = 0x00030000;
  108. const StemType ksttPoint = 0x00040000;
  109. const StemType ksttValid = 0x00070000;
  110. // Stem sides
  111. // (mikev) bit 0 indicates horisontal or vertical stem
  112. // 1 = Vertical, 0= horizontal
  113. // (mikev) bit 1 indicates left or right, top or bottom
  114. // 1 = right or bottom, 0= left or top
  115. const StemSide kssLeft = 0x00000000;
  116. const StemSide kssTop = 0x00000001;
  117. const StemSide kssRight = 0x00000002;
  118. const StemSide kssBottom = 0x00000003;
  119. const StemSide kssValid = 0x00000003;
  120. const StemSide kssIncr = 0x00000001;
  121. inline StemSide StemSideLeftTop(StemSide ss)
  122. {
  123. return (ss & ~2);
  124. }
  125. inline StemSide StemSideOpposite(StemSide ss) // (mikev) flip bit 1 (flip side)
  126. {
  127. return (ss ^ 2);
  128. }
  129. // Stem settings - these are passed to constructors
  130. #define MakeStem(stt, ss) (stt | ss)
  131. const Stem kstSquareLeft = MakeStem(ksttNone, kssLeft);
  132. const Stem kstSquareTop = MakeStem(ksttNone, kssTop);
  133. const Stem kstSquareRight = MakeStem(ksttNone, kssRight);
  134. const Stem kstSquareBottom = MakeStem(ksttNone, kssBottom);
  135. const Stem kstSpeakLeft = MakeStem(ksttSpeak, kssLeft);
  136. const Stem kstSpeakTop = MakeStem(ksttSpeak, kssTop);
  137. const Stem kstSpeakRight = MakeStem(ksttSpeak, kssRight);
  138. const Stem kstSpeakBottom = MakeStem(ksttSpeak, kssBottom);
  139. const Stem kstThinkLeft = MakeStem(ksttThink, kssLeft);
  140. const Stem kstThinkTop = MakeStem(ksttThink, kssTop);
  141. const Stem kstThinkRight = MakeStem(ksttThink, kssRight);
  142. const Stem kstThinkBottom = MakeStem(ksttThink, kssBottom);
  143. const Stem kstArrowLeft = MakeStem(ksttArrow, kssLeft);
  144. const Stem kstArrowTop = MakeStem(ksttArrow, kssTop);
  145. const Stem kstArrowRight = MakeStem(ksttArrow, kssRight);
  146. const Stem kstArrowBottom = MakeStem(ksttArrow, kssBottom);
  147. const Stem kstValid = MakeStem(ksttValid, kssValid);
  148. // The following is NOT a valid stem type, but is
  149. // converted to a valid stem type by CRgnDialog::Init().
  150. const Stem kstDefault = 0xFFFFFFFF;
  151. inline StemType GetStemType(Stem st)
  152. {
  153. return (StemType)(st & ksttValid);
  154. }
  155. inline StemSide GetStemSide(Stem st)
  156. {
  157. return (StemSide)(st & kssValid);
  158. }
  159. inline ULONG StemTypeIndex(StemType st)
  160. {
  161. return (st >> 16) & (ksttValid >> 16);
  162. }
  163. inline ULONG StemSideIndex(StemSide ss)
  164. {
  165. return ss & kssValid;
  166. }
  167. // Dialog metrics (refer to sdk documentation for meaning of fields)
  168. struct DialogMetrics // dm
  169. {
  170. DialogMetrics(ULONG cxCorner, ULONG cyCorner, ULONG cpStemBaseWidth,
  171. ULONG cpStemBaseShift, ULONG cpStemHeight, ULONG cpStemOffset);
  172. ULONG m_cxCorner;
  173. ULONG m_cyCorner;
  174. ULONG m_cpStemBaseWidth;
  175. ULONG m_cpStemBaseShift;
  176. ULONG m_cpStemHeight;
  177. ULONG m_cpStemOffset;
  178. static ULONG s_cxBorder;
  179. static ULONG s_cyBorder;
  180. };
  181. class CRgnDialog // dlg
  182. {
  183. private:
  184. #ifdef MFC
  185. DECLARE_DYNAMIC(CRgnDialog);
  186. #endif
  187. #ifndef MFC
  188. #define GetStyle() GetWindowLong(m_hWnd, GWL_STYLE)
  189. #endif
  190. // Declare first for inline use
  191. private:
  192. ULONG m_ff; // public flags passed to constructors
  193. ULONG m_ffx; // Internal flag state
  194. #ifdef MFC
  195. CRect m_rcTarget; // Target rect passed to constructors
  196. CRect m_rcClient; // Client rect in screen coordinates
  197. HCURSOR m_hcurMove; // Cursor while moving
  198. HCURSOR m_hcurNormal; // Normal cursor
  199. #else
  200. RECT m_rcTarget; // Target rect passed to constructors
  201. RECT m_rcClient; // Client rect in screen coordinates
  202. #endif
  203. Stem m_st; // Stem info passed to constructors
  204. ULONG m_cpStemOffset; // Stem offset from top or left of dialog
  205. DialogMetrics *m_pdm; // Precalculated dialog metrics
  206. HBRUSH m_hbrBackground; // Background brush
  207. #ifndef MFC
  208. HWND hWndClient;
  209. DLGPROC ClientDlgPrc;
  210. LPARAM lParamClient;
  211. HWND m_hWnd;
  212. #endif
  213. // Private helpers
  214. private:
  215. void Init(ULONG ff, RECT *prc, Stem st, /*HINSTANCE hInst, */ HWND hWndOwner,
  216. DLGPROC procClient, LPARAM lParamInit);
  217. //void Init(ULONG ff, RECT *prc, Stem st);
  218. #ifdef MFC
  219. void CalcClientRect(WINDOWPOS *ppos, CRect *prc);
  220. void OffsetClientRect(StemSide ss, CRect *prcClient, long cpInset);
  221. void CalcClientPos(CRect *prcClient, CRect *prcDst);
  222. void AdjustInsideBoundary(StemSide ss, CRect *prcDlg, CRect *prcClient,
  223. CRect *prcBoundary, ULONG *pcpStemOffset);
  224. BOOL FSideInBoundary(StemSide ss, RECT *prc, RECT *prcBoundary,
  225. long *pcpOverlap);
  226. void CalcWindowRgn(int xWindow, int yWindow);
  227. void OnNcPaint(HRGN hrgnUpdate);
  228. HRGN CreateSpeakRgn(CRect *prcBody);
  229. HRGN CreateArrowRgn(CRect *prcBody);
  230. HRGN CreateThinkRgn(CRect *prcBody);
  231. BOOL SendMessageToChildren(BOOL fStopOnSuccess, UINT wm, WPARAM wp,
  232. LPARAM lp);
  233. #else
  234. void CalcClientRect(WINDOWPOS *ppos, RECT *prc);
  235. void OffsetClientRect(StemSide ss, RECT *prcClient, long cpInset);
  236. void CalcClientPos(RECT *prcClient, RECT *prcDst);
  237. void AdjustInsideBoundary(StemSide ss, RECT *prcDlg, RECT *prcClient,
  238. RECT *prcBoundary, ULONG *pcpStemOffset);
  239. BOOL FSideInBoundary(StemSide ss, RECT *prc, RECT *prcBoundary,
  240. long *pcpOverlap);
  241. void CalcWindowRgn(int xWindow, int yWindow);
  242. void OnNcPaint(HRGN hrgnUpdate);
  243. HRGN CreatePointRgn(RECT *prcBody);
  244. HRGN CreateArrowRgn(RECT *prcBody);
  245. HRGN CreateThinkRgn(RECT *prcBody);
  246. public:
  247. BOOL DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  248. void PubInit(ULONG ff, RECT *prc, Stem st, /*HINSTANCE hInst, */ HWND hWndOwner,
  249. DLGPROC procClient, LPARAM lParamInit);
  250. #endif
  251. protected:
  252. void CalcWindowPos(WINDOWPOS *ppos);
  253. // For modeless construction
  254. public:
  255. inline CRgnDialog()
  256. {
  257. // Set dialog background color to NULL
  258. m_hbrBackground = NULL;
  259. // Initialize other variables
  260. Init(0, NULL, 0, NULL, NULL, 0);
  261. }
  262. #ifdef MFC
  263. inline BOOL Create(const char *pszTemplateName, CWnd *pwndParent = NULL,
  264. ULONG ff = 0, RECT *prc = NULL, Stem st = kstDefault)
  265. {
  266. Init(ff, prc, st, NULL, NULL, 0);
  267. return 1;
  268. }
  269. inline BOOL Create(ULONG idTemplate, CWnd *pwndParent = NULL,
  270. ULONG ff = 0, RECT *prc = NULL, Stem st = kstDefault)
  271. {
  272. Init(ff, prc, st, NULL, NULL, 0);
  273. return 1;
  274. }
  275. inline BOOL CreateIndirect(const DLGTEMPLATE *pvDialogTemplate,
  276. CWnd *pwndParent = NULL, ULONG ff = 0, RECT *prc = NULL,
  277. Stem st = kstDefault)
  278. {
  279. Init(ff, prc, st, NULL, NULL, 0);
  280. return 1;
  281. }
  282. inline BOOL CreateIndirect(HGLOBAL hDialogTemplate,
  283. CWnd* pwndParent = NULL, ULONG ff = 0, RECT *prc = NULL,
  284. Stem st = kstDefault)
  285. {
  286. Init(ff, prc, st, NULL, NULL, 0);
  287. return 1;
  288. }
  289. // For modal construction
  290. public:
  291. inline CRgnDialog(const char *pszTemplate, CWnd *pwndParent = NULL,
  292. ULONG ff = 0, RECT *prc = NULL, Stem st = kstDefault)
  293. {
  294. // Set dialog background color to NULL
  295. m_hbrBackground = NULL;
  296. // Initialize other variables
  297. Init(ff, prc, st, NULL, NULL, 0);
  298. }
  299. inline CRgnDialog(ULONG idTemplate, CWnd *pwndParent = NULL,
  300. ULONG ff = 0, RECT *prc = NULL, Stem st = kstDefault)
  301. {
  302. // Set dialog background color to NULL
  303. m_hbrBackground = NULL;
  304. // Initialize other variables
  305. Init(ff, prc, st, NULL, NULL, 0);
  306. }
  307. virtual int DoModal();
  308. #endif //MFC
  309. // Public methods
  310. public:
  311. // Destructor
  312. ~CRgnDialog()
  313. {
  314. if (m_hbrBackground != NULL)
  315. DeleteObject(m_hbrBackground);
  316. #ifdef MFC
  317. if (m_hcurMove != NULL)
  318. DestroyCursor(m_hcurMove);
  319. if (m_hcurNormal != NULL)
  320. DestroyCursor(m_hcurNormal);
  321. #endif MFC
  322. }
  323. #ifdef MFC
  324. // Returns flags passed into constructor
  325. inline ULONG GetFlags()
  326. {
  327. return m_ff;
  328. }
  329. // Returns target rect passed into constructor
  330. inline BOOL GetTargetRect(RECT *prc)
  331. {
  332. *prc = m_rcTarget;
  333. return TRUE;
  334. }
  335. // Returns stem info passed into constructor
  336. inline Stem GetStem()
  337. {
  338. return m_st;
  339. }
  340. // Set dialog background brush
  341. inline BOOL SetBackgroundBrush(HBRUSH hbr)
  342. {
  343. if (m_hbrBackground != NULL)
  344. DeleteObject(m_hbrBackground);
  345. m_hbrBackground = hbr;
  346. return TRUE;
  347. }
  348. // Get dialog background brush
  349. inline HBRUSH GetBackgroundBrush()
  350. {
  351. return m_hbrBackground;
  352. }
  353. #endif //MFC
  354. // Overridden methods
  355. public:
  356. void EndDialog(int n);
  357. virtual void CalcWindowRect(RECT *prcClient, UINT idAdjust);
  358. virtual BOOL OnInitDialog();
  359. protected:
  360. //virtual LRESULT WindowProc(UINT wm, WPARAM wp, LPARAM lp);
  361. virtual void PostNcDestroy();
  362. protected:
  363. #ifdef MFC
  364. //{{AFX_MSG(CRgnDialog)
  365. afx_msg int OnMouseActivate(CWnd *pwnd, UINT ht, UINT wm);
  366. afx_msg void OnNcCalcSize(BOOL fCalcValidRects, NCCALCSIZE_PARAMS *pcsz);
  367. afx_msg void OnWindowPosChanging(WINDOWPOS *ppos);
  368. afx_msg void OnWindowPosChanged(WINDOWPOS *ppos);
  369. afx_msg BOOL OnEraseBkgnd(CDC *pdc);
  370. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  371. afx_msg UINT OnNcHitTest(CPoint pt);
  372. afx_msg void OnPaint();
  373. afx_msg BOOL OnQueryNewPalette();
  374. afx_msg BOOL OnSetCursor(CWnd *pwnd, UINT ht, UINT wm);
  375. afx_msg void OnNcDestroy();
  376. afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
  377. //}}AFX_MSG
  378. DECLARE_MESSAGE_MAP()
  379. #else
  380. public:
  381. int OnMouseActivate(HWND hWnd, UINT ht, UINT wm);
  382. int OnNcCalcSize(BOOL fCalcValidRects, NCCALCSIZE_PARAMS *pcsz);
  383. int OnWindowPosChanging(WINDOWPOS *ppos);
  384. void OnWindowPosChanged(WINDOWPOS *ppos);
  385. BOOL OnEraseBkgnd(HDC hdc);
  386. int OnCreate(LPCREATESTRUCT lpCreateStruct);
  387. UINT OnNcHitTest(LPARAM lParam);
  388. void OnPaint();
  389. BOOL OnQueryNewPalette();
  390. BOOL OnSetCursor(HWND hWnd, UINT ht, UINT wm);
  391. void OnNcDestroy();
  392. void OnPaletteChanged(HWND hWndChanger);
  393. #endif
  394. };
  395. #endif // defined (_cplusplus)
  396. #endif // !defined(__RGNDLG_H__)