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.

192 lines
6.0 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: Tooltip.cpp
  3. //
  4. // Copyright (c) 2000, Microsoft Corporation
  5. //
  6. // Class that implements displaying a tooltip balloon.
  7. //
  8. // History: 2000-06-12 vtan created
  9. // --------------------------------------------------------------------------
  10. #include "shellprv.h"
  11. #include "Tooltip.h"
  12. BOOL IsBiDiLocalizedSystem( void );
  13. // --------------------------------------------------------------------------
  14. // CTooltip::CTooltip
  15. //
  16. // Arguments: hInstance = HINSTANCE of hosting process/DLL.
  17. // hwndParent = HWND of the parenting window.
  18. //
  19. // Returns: <none>
  20. //
  21. // Purpose: Constructor for CTooltip. Creates a tooltip window and
  22. // prepares it for display.
  23. //
  24. // History: 2000-06-12 vtan created
  25. // --------------------------------------------------------------------------
  26. CTooltip::CTooltip (HINSTANCE hInstance, HWND hwndParent) :
  27. _hwnd(NULL),
  28. _hwndParent(hwndParent)
  29. {
  30. DWORD dwExStyle;
  31. if (((GetWindowLongA(hwndParent, GWL_EXSTYLE) & WS_EX_LAYOUTRTL) != 0) || IsBiDiLocalizedSystem())
  32. {
  33. dwExStyle = WS_EX_LAYOUTRTL;
  34. }
  35. else
  36. {
  37. dwExStyle = 0;
  38. }
  39. _hwnd = CreateWindowEx(dwExStyle,
  40. TOOLTIPS_CLASS,
  41. NULL,
  42. WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP | TTS_BALLOON,
  43. CW_USEDEFAULT,
  44. CW_USEDEFAULT,
  45. CW_USEDEFAULT,
  46. CW_USEDEFAULT,
  47. hwndParent,
  48. NULL,
  49. hInstance,
  50. NULL);
  51. if (_hwnd != NULL)
  52. {
  53. TOOLINFO toolInfo;
  54. TBOOL(SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE));
  55. (LRESULT)SendMessage(_hwnd, CCM_SETVERSION, COMCTL32_VERSION, 0);
  56. ZeroMemory(&toolInfo, sizeof(toolInfo));
  57. toolInfo.cbSize = sizeof(toolInfo);
  58. toolInfo.uFlags = TTF_TRANSPARENT | TTF_TRACK;
  59. toolInfo.uId = PtrToUint(_hwnd);
  60. (LRESULT)SendMessage(_hwnd, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&toolInfo));
  61. (LRESULT)SendMessage(_hwnd, TTM_SETMAXTIPWIDTH, 0, 300);
  62. }
  63. }
  64. // --------------------------------------------------------------------------
  65. // CTooltip::~CTooltip
  66. //
  67. // Arguments: <none>
  68. //
  69. // Returns: <none>
  70. //
  71. // Purpose: Destructor for the CTooltip class. This destroys the tooltip
  72. // window created. If the parent of the tooltip window is
  73. // destroyed before this is invoked user32!DestroyWindow will
  74. // cause the trace to fire. The object's lifetime must be
  75. // carefully managed by the user of this class.
  76. //
  77. // History: 2000-06-12 vtan created
  78. // --------------------------------------------------------------------------
  79. CTooltip::~CTooltip (void)
  80. {
  81. if (_hwnd != NULL)
  82. {
  83. TBOOL(DestroyWindow(_hwnd));
  84. _hwnd = NULL;
  85. }
  86. }
  87. // --------------------------------------------------------------------------
  88. // CTooltip::SetPosition
  89. //
  90. // Arguments: lPosX = X position of the balloon tip window (screen).
  91. // lPosY = Y position of the balloon tip window (screen).
  92. //
  93. // Returns: <none>
  94. //
  95. // Purpose: Positions the tooltip window at the given screen co-ordinates.
  96. // If the parameters are defaulted then this positions the
  97. // tooltip relative to the parent.
  98. //
  99. // History: 2000-06-12 vtan created
  100. // --------------------------------------------------------------------------
  101. void CTooltip::SetPosition (LONG lPosX, LONG lPosY) const
  102. {
  103. if ((lPosX == LONG_MIN) && (lPosY == LONG_MIN))
  104. {
  105. RECT rc;
  106. TBOOL(GetWindowRect(_hwndParent, &rc));
  107. lPosX = (rc.left + rc.right) / 2;
  108. lPosY = rc.bottom;
  109. }
  110. (LRESULT)SendMessage(_hwnd, TTM_TRACKPOSITION, 0, MAKELONG(lPosX, lPosY));
  111. }
  112. // --------------------------------------------------------------------------
  113. // CTooltip::SetCaption
  114. //
  115. // Arguments: dwIcon = Icon type to set for the tooltip caption.
  116. // pszCaption = Caption of the tooltip.
  117. //
  118. // Returns: <none>
  119. //
  120. // Purpose: Sets the tooltip caption.
  121. //
  122. // History: 2000-06-12 vtan created
  123. // --------------------------------------------------------------------------
  124. void CTooltip::SetCaption (DWORD dwIcon, const TCHAR *pszCaption) const
  125. {
  126. (LRESULT)SendMessage(_hwnd, TTM_SETTITLE, dwIcon, reinterpret_cast<LPARAM>(pszCaption));
  127. }
  128. // --------------------------------------------------------------------------
  129. // CTooltip::SetText
  130. //
  131. // Arguments: pszText = Content of the actual tooltip.
  132. //
  133. // Returns: <none>
  134. //
  135. // Purpose: Sets the tooltip text.
  136. //
  137. // History: 2000-06-12 vtan created
  138. // --------------------------------------------------------------------------
  139. void CTooltip::SetText (const TCHAR *pszText) const
  140. {
  141. TOOLINFO toolInfo;
  142. ZeroMemory(&toolInfo, sizeof(toolInfo));
  143. toolInfo.cbSize = sizeof(toolInfo);
  144. toolInfo.uId = PtrToUint(_hwnd);
  145. toolInfo.lpszText = const_cast<TCHAR*>(pszText);
  146. (LRESULT)SendMessage(_hwnd, TTM_UPDATETIPTEXT, 0, reinterpret_cast<LPARAM>(&toolInfo));
  147. }
  148. // --------------------------------------------------------------------------
  149. // CTooltip::Show
  150. //
  151. // Arguments: <none>
  152. //
  153. // Returns: <none>
  154. //
  155. // Purpose: Shows the tooltip window.
  156. //
  157. // History: 2000-06-12 vtan created
  158. // --------------------------------------------------------------------------
  159. void CTooltip::Show (void) const
  160. {
  161. TOOLINFO toolInfo;
  162. ZeroMemory(&toolInfo, sizeof(toolInfo));
  163. toolInfo.cbSize = sizeof(toolInfo);
  164. toolInfo.uId = PtrToUint(_hwnd);
  165. (LRESULT)SendMessage(_hwnd, TTM_TRACKACTIVATE, TRUE, reinterpret_cast<LPARAM>(&toolInfo));
  166. }