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.

197 lines
5.1 KiB

  1. #include "priv.h"
  2. #include <commctrl.h>
  3. #include "EBalloon.h"
  4. #undef ASSERT
  5. #define ASSERT(x)
  6. BOOL g_bMirroredOS = false;
  7. CErrorBalloon::CErrorBalloon()
  8. {
  9. // our allocation function should have zeroed our memory. Check to make sure:
  10. ASSERT(0==m_hwndToolTip);
  11. ASSERT(0==m_uTimerID);
  12. g_bMirroredOS = IS_MIRRORING_ENABLED();
  13. }
  14. CErrorBalloon::~CErrorBalloon()
  15. {
  16. }
  17. LRESULT CALLBACK CErrorBalloon::SubclassProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uID, ULONG_PTR dwRefData)
  18. {
  19. UNREFERENCED_PARAMETER(uID);
  20. CErrorBalloon * pthis = (CErrorBalloon*)dwRefData;
  21. switch (uMsg)
  22. {
  23. // Do not autodismiss until after markup has had a chance to
  24. // parse the WM_LBUTTONUP to see if it's a link click or not
  25. case WM_LBUTTONUP:
  26. DefSubclassProc(hwnd, uMsg, wParam, lParam);
  27. pthis->HideToolTip();
  28. return 0;
  29. case WM_TIMER:
  30. if (wParam == ERRORBALLOONTIMERID)
  31. {
  32. pthis->HideToolTip();
  33. return 0;
  34. }
  35. break;
  36. default:
  37. break;
  38. }
  39. return DefSubclassProc(hwnd, uMsg, wParam, lParam);
  40. }
  41. void CErrorBalloon::ShowToolTip(HINSTANCE hInstance, HWND hwndTarget, const POINT *ppt, LPTSTR pszMessage, LPTSTR pszTitle, DWORD dwIconIndex, DWORD dwFlags, int iTimeout)
  42. {
  43. hinst = hInstance;
  44. if (m_hwndToolTip)
  45. {
  46. HideToolTip();
  47. }
  48. m_hwndTarget = hwndTarget;
  49. m_dwIconIndex = dwIconIndex;
  50. if ( !m_hwndToolTip )
  51. {
  52. CreateToolTipWindow();
  53. }
  54. int x, y;
  55. x = ppt->x;
  56. y = ppt->y;
  57. SendMessage(m_hwndToolTip, TTM_TRACKPOSITION, 0, MAKELONG(x,y));
  58. if (pszTitle)
  59. {
  60. SendMessage(m_hwndToolTip, TTM_SETTITLE, (WPARAM)dwIconIndex, (LPARAM)pszTitle);
  61. }
  62. TOOLINFO ti = {0};
  63. ti.cbSize = TTTOOLINFOW_V2_SIZE;
  64. ti.hwnd = m_hwndTarget;
  65. ti.uId = 1;
  66. SendMessage(m_hwndToolTip, TTM_GETTOOLINFO, 0, (LPARAM)&ti);
  67. ti.uFlags &= ~TTF_PARSELINKS;
  68. if (dwFlags & EB_MARKUP)
  69. {
  70. ti.uFlags |= TTF_PARSELINKS;
  71. }
  72. ti.lpszText = pszMessage;
  73. SendMessage(m_hwndToolTip, TTM_SETTOOLINFO, 0, (LPARAM)&ti);
  74. // Show the tooltip
  75. SendMessage(m_hwndToolTip, TTM_TRACKACTIVATE, TRUE, (LPARAM)&ti);
  76. // Set a timer to hide the tooltip
  77. if ( m_uTimerID )
  78. {
  79. KillTimer(NULL,ERRORBALLOONTIMERID);
  80. }
  81. m_uTimerID = SetTimer(m_hwndToolTip, ERRORBALLOONTIMERID, iTimeout, NULL);
  82. SetWindowSubclass(m_hwndToolTip, CErrorBalloon::SubclassProc, (UINT_PTR)this, (LONG_PTR)this);
  83. }
  84. void CErrorBalloon::ShowToolTip(HINSTANCE hInstance, HWND hwndTarget, LPTSTR pszMessage, LPTSTR pszTitle, DWORD dwIconIndex, DWORD dwFlags, int iTimeout)
  85. {
  86. // Set the tooltip display point
  87. RECT rc;
  88. GetWindowRect(hwndTarget, &rc);
  89. POINT pt;
  90. pt.x = (rc.left+rc.right)/2;
  91. if ( EB_WARNINGABOVE & dwFlags )
  92. {
  93. pt.y = rc.top;
  94. }
  95. else if ( EB_WARNINGCENTERED & dwFlags )
  96. {
  97. pt.y = (rc.top+rc.bottom)/2;
  98. }
  99. else
  100. {
  101. pt.y = rc.bottom;
  102. }
  103. ShowToolTip(hInstance, hwndTarget, &pt, pszMessage, pszTitle, dwIconIndex, dwFlags, iTimeout);
  104. }
  105. // CreateToolTipWindow
  106. //
  107. // Creates our tooltip control. We share this one tooltip control and use it for all invalid
  108. // input messages. The control is hiden when not in use and then shown when needed.
  109. //
  110. void CErrorBalloon::CreateToolTipWindow()
  111. {
  112. DWORD dwExStyle = 0;
  113. if (IS_BIDI_LOCALIZED_SYSTEM())
  114. dwExStyle |= WS_EX_LAYOUTRTL;
  115. m_hwndToolTip = CreateWindowEx(
  116. dwExStyle,
  117. TOOLTIPS_CLASS,
  118. NULL,
  119. WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON,
  120. CW_USEDEFAULT,
  121. CW_USEDEFAULT,
  122. CW_USEDEFAULT,
  123. CW_USEDEFAULT,
  124. m_hwndTarget,
  125. NULL,
  126. GetModuleHandle(NULL),
  127. NULL);
  128. if (m_hwndToolTip)
  129. {
  130. TOOLINFO ti = {0};
  131. ti.cbSize = TTTOOLINFOW_V2_SIZE;
  132. ti.uFlags = TTF_TRACK;
  133. ti.hwnd = m_hwndTarget;
  134. ti.uId = 1;
  135. ti.hinst = hinst;
  136. ti.lpszText = NULL;
  137. // set the version so we can have non buggy mouse event forwarding
  138. SendMessage(m_hwndToolTip, CCM_SETVERSION, COMCTL32_VERSION, 0);
  139. SendMessage(m_hwndToolTip, TTM_ADDTOOL, 0, (LPARAM)&ti);
  140. SendMessage(m_hwndToolTip, TTM_SETMAXTIPWIDTH, 0, 300);
  141. }
  142. else
  143. {
  144. // failed to create tool tip window, now what should we do? Unsubclass ourselves?
  145. }
  146. }
  147. void CErrorBalloon::HideToolTip()
  148. {
  149. // When the timer fires we hide the tooltip window
  150. if ( m_uTimerID )
  151. {
  152. KillTimer(m_hwndTarget,ERRORBALLOONTIMERID);
  153. m_uTimerID = 0;
  154. }
  155. if ( m_hwndToolTip )
  156. {
  157. HWND hwndTip = m_hwndToolTip;
  158. m_hwndToolTip = NULL;
  159. SendMessage(hwndTip, TTM_TRACKACTIVATE, FALSE, 0);
  160. DestroyWindow(hwndTip);
  161. }
  162. }