Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / tools / relic / test / BrowserToolTip.cpp
bloba49330da54e6073c6792245d2f5b47c9c0ed47df
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: Mozilla-sample-code 1.0
4 * Copyright (c) 2002 Netscape Communications Corporation and
5 * other contributors
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this Mozilla sample software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to permit
12 * persons to whom the Software is furnished to do so, subject to the
13 * following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Contributor(s):
27 * Adam Lock <adamlock@netscape.com>
29 * ***** END LICENSE BLOCK ***** */
31 #include "stdafx.h"
33 #include "BrowserToolTip.h"
35 #ifdef _DEBUG
36 #define new DEBUG_NEW
37 #undef THIS_FILE
38 static char THIS_FILE[] = __FILE__;
39 #endif
41 /////////////////////////////////////////////////////////////////////////////
42 // CBrowserToolTip
44 CBrowserToolTip::CBrowserToolTip()
48 CBrowserToolTip::~CBrowserToolTip()
52 BEGIN_MESSAGE_MAP(CBrowserToolTip, CWnd)
53 //{{AFX_MSG_MAP(CBrowserToolTip)
54 ON_WM_PAINT()
55 //}}AFX_MSG_MAP
56 END_MESSAGE_MAP()
59 BOOL CBrowserToolTip::Create(CWnd *pParentWnd)
61 return CWnd::CreateEx(WS_EX_TOOLWINDOW,
62 AfxRegisterWndClass(CS_SAVEBITS, NULL, GetSysColorBrush(COLOR_INFOBK), NULL),
63 _T("ToolTip"), WS_POPUP | WS_BORDER, 0, 0, 1, 1, pParentWnd->GetSafeHwnd(), NULL);
66 /////////////////////////////////////////////////////////////////////////////
67 // CBrowserToolTip message handlers
69 void CBrowserToolTip::OnPaint()
71 CPaintDC dc(this); // device context for painting
73 CRect rcClient;
74 GetClientRect(&rcClient);
76 // Draw tip text
77 int oldBkMode = dc.SetBkMode(TRANSPARENT);
78 COLORREF oldTextColor = dc.SetTextColor(GetSysColor(COLOR_INFOTEXT));
79 HGDIOBJ oldFont = dc.SelectObject(GetStockObject(DEFAULT_GUI_FONT));
81 dc.DrawText(m_szTipText, -1, rcClient, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
83 dc.SetBkMode(oldBkMode);
84 dc.SetTextColor(oldTextColor);
85 dc.SelectObject(oldFont);
88 BOOL CBrowserToolTip::PreCreateWindow(CREATESTRUCT& cs)
90 return CWnd::PreCreateWindow(cs);
93 void CBrowserToolTip::SetTipText(const CString &szTipText)
95 m_szTipText = szTipText;
98 void CBrowserToolTip::Show(CWnd *pOverWnd, long left, long top)
100 // Calculate the client window size
101 CRect rcNewClient(0,0,0,0);
102 CDC *pdc = GetDC();
103 HGDIOBJ oldFont = pdc->SelectObject(GetStockObject(DEFAULT_GUI_FONT));
104 rcNewClient.bottom = pdc->DrawText(m_szTipText, -1, rcNewClient,
105 DT_SINGLELINE | DT_VCENTER | DT_CENTER | DT_CALCRECT);
106 pdc->SelectObject(oldFont);
107 ReleaseDC(pdc);
108 rcNewClient.right += 8;
109 rcNewClient.bottom += 8;
111 // Adjust the tooltip to new size
112 AdjustWindowRectEx(rcNewClient, GetWindowLong(m_hWnd, GWL_STYLE), FALSE, GetWindowLong(m_hWnd, GWL_EXSTYLE));
114 // Adjust the left, top position of the tooltip
115 CPoint ptTip(left, top);
116 pOverWnd->ClientToScreen(&ptTip);
118 // Make sure tip is below cursor
119 POINT ptCursor;
120 GetCursorPos(&ptCursor);
121 long cyCursor = GetSystemMetrics(SM_CYCURSOR);
122 if (ptTip.y < ptCursor.y + cyCursor)
123 ptTip.y = ptCursor.y + cyCursor;
125 // Make sure tip is fully visible
126 RECT rcScreen;
127 GetDesktopWindow()->GetClientRect(&rcScreen);
128 if (ptTip.x < 0)
129 ptTip.x = 0;
130 else if (ptTip.x + rcNewClient.Width() > rcScreen.right)
131 ptTip.x = rcScreen.right - rcNewClient.Width();
132 if (ptTip.y < 0)
133 ptTip.y = 0;
134 else if (ptTip.y + rcNewClient.Height() > rcScreen.bottom)
135 ptTip.y = rcScreen.bottom - rcNewClient.Height();
137 // Position and show the tip
138 SetWindowPos(&CWnd::wndTop, ptTip.x, ptTip.y, rcNewClient.Width(), rcNewClient.Height(),
139 SWP_NOACTIVATE | SWP_SHOWWINDOW);
142 void CBrowserToolTip::Hide()
144 ShowWindow(SW_HIDE);