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.

190 lines
6.1 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. TBOOL(SetWindowPos(_hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE));
  54. (LRESULT)SendMessage(_hwnd, CCM_SETVERSION, COMCTL32_VERSION, 0);
  55. TOOLINFO toolInfo = { 0 };
  56. toolInfo.cbSize = sizeof(toolInfo);
  57. toolInfo.uFlags = TTF_TRANSPARENT | TTF_TRACK;
  58. toolInfo.uId = PtrToUint(_hwnd);
  59. (LRESULT)SendMessage(_hwnd, TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&toolInfo));
  60. (LRESULT)SendMessage(_hwnd, TTM_SETMAXTIPWIDTH, 0, 300);
  61. }
  62. }
  63. // --------------------------------------------------------------------------
  64. // CTooltip::~CTooltip
  65. //
  66. // Arguments: <none>
  67. //
  68. // Returns: <none>
  69. //
  70. // Purpose: Destructor for the CTooltip class. This destroys the tooltip
  71. // window created. If the parent of the tooltip window is
  72. // destroyed before this is invoked user32!DestroyWindow will
  73. // cause the trace to fire. The object's lifetime must be
  74. // carefully managed by the user of this class.
  75. //
  76. // History: 2000-06-12 vtan created
  77. // --------------------------------------------------------------------------
  78. CTooltip::~CTooltip (void)
  79. {
  80. if (_hwnd != NULL)
  81. {
  82. TBOOL(DestroyWindow(_hwnd));
  83. _hwnd = NULL;
  84. }
  85. }
  86. // --------------------------------------------------------------------------
  87. // CTooltip::SetPosition
  88. //
  89. // Arguments: lPosX = X position of the balloon tip window (screen).
  90. // lPosY = Y position of the balloon tip window (screen).
  91. //
  92. // Returns: <none>
  93. //
  94. // Purpose: Positions the tooltip window at the given screen co-ordinates.
  95. // If the parameters are defaulted then this positions the
  96. // tooltip relative to the parent.
  97. //
  98. // History: 2000-06-12 vtan created
  99. // --------------------------------------------------------------------------
  100. void CTooltip::SetPosition (LONG lPosX, LONG lPosY) const
  101. {
  102. if ((lPosX == LONG_MIN) && (lPosY == LONG_MIN))
  103. {
  104. RECT rc;
  105. TBOOL(GetWindowRect(_hwndParent, &rc));
  106. lPosX = (rc.left + rc.right) / 2;
  107. lPosY = rc.bottom;
  108. }
  109. (LRESULT)SendMessage(_hwnd, TTM_TRACKPOSITION, 0, MAKELONG(lPosX, lPosY));
  110. }
  111. // --------------------------------------------------------------------------
  112. // CTooltip::SetCaption
  113. //
  114. // Arguments: dwIcon = Icon type to set for the tooltip caption.
  115. // pszCaption = Caption of the tooltip.
  116. //
  117. // Returns: <none>
  118. //
  119. // Purpose: Sets the tooltip caption.
  120. //
  121. // History: 2000-06-12 vtan created
  122. // --------------------------------------------------------------------------
  123. void CTooltip::SetCaption (DWORD dwIcon, const TCHAR *pszCaption) const
  124. {
  125. (LRESULT)SendMessage(_hwnd, TTM_SETTITLE, dwIcon, reinterpret_cast<LPARAM>(pszCaption));
  126. }
  127. // --------------------------------------------------------------------------
  128. // CTooltip::SetText
  129. //
  130. // Arguments: pszText = Content of the actual tooltip.
  131. //
  132. // Returns: <none>
  133. //
  134. // Purpose: Sets the tooltip text.
  135. //
  136. // History: 2000-06-12 vtan created
  137. // --------------------------------------------------------------------------
  138. void CTooltip::SetText (const TCHAR *pszText) const
  139. {
  140. TOOLINFO toolInfo = { 0 };
  141. toolInfo.cbSize = sizeof(toolInfo);
  142. toolInfo.uId = PtrToUint(_hwnd);
  143. toolInfo.lpszText = const_cast<TCHAR*>(pszText);
  144. (LRESULT)SendMessage(_hwnd, TTM_UPDATETIPTEXT, 0, reinterpret_cast<LPARAM>(&toolInfo));
  145. }
  146. // --------------------------------------------------------------------------
  147. // CTooltip::Show
  148. //
  149. // Arguments: <none>
  150. //
  151. // Returns: <none>
  152. //
  153. // Purpose: Shows the tooltip window.
  154. //
  155. // History: 2000-06-12 vtan created
  156. // --------------------------------------------------------------------------
  157. void CTooltip::Show (void) const
  158. {
  159. TOOLINFO toolInfo = { 0 };
  160. toolInfo.cbSize = sizeof(toolInfo);
  161. toolInfo.uId = PtrToUint(_hwnd);
  162. (LRESULT)SendMessage(_hwnd, TTM_TRACKACTIVATE, TRUE, reinterpret_cast<LPARAM>(&toolInfo));
  163. }