;
SetCapture();
}
}
BOOL CMapHyperLink::OnSetCursor(CWnd* /*pWnd*/, UINT /*nHitTest*/, UINT /*message*/)
{
if (m_hLinkCursor)
{
::SetCursor(m_hLinkCursor);
return TRUE;
}
return FALSE;
}
void CMapHyperLink::PreSubclassWindow()
{
// We want to get mouse clicks via STN_CLICKED
DWORD dwStyle = GetStyle();
::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
SetDefaultCursor(); // Try and load up a "hand" cursor
// Create the tooltip
CRect rect;
GetClientRect(rect);
m_ToolTip.Create(this);
if (m_strTipText.IsEmpty())
{
m_strTipText = m_strURL;
}
m_ToolTip.AddTool(this, m_strTipText, rect, TOOLTIP_ID);
CStatic::PreSubclassWindow();
}
////////////////////////////////////////////// CMapHyperLink operations
void CMapHyperLink::SetURL(CString strURL)
{
m_strURL = strURL;
if (::IsWindow(GetSafeHwnd())) {
PositionWindow();
if (m_strTipText.IsEmpty())
{
m_strTipText = strURL;
}
m_ToolTip.UpdateTipText(m_strTipText, this, TOOLTIP_ID);
}
}
CString CMapHyperLink::GetURL() const
{
return m_strURL;
}
void CMapHyperLink::SetTipText(CString strTipText)
{
m_strTipText = strTipText;
if (::IsWindow(GetSafeHwnd())) {
PositionWindow();
m_ToolTip.UpdateTipText(m_strTipText, this, TOOLTIP_ID);
}
}
CString CMapHyperLink::GetTipText() const
{
return m_strTipText;
}
void CMapHyperLink::SetVisited(BOOL bVisited /* = TRUE */)
{
m_bVisited = bVisited;
if (::IsWindow(GetSafeHwnd()))
Invalidate();
}
BOOL CMapHyperLink::GetVisited() const
{
return m_bVisited;
}
void CMapHyperLink::SetLinkCursor(HCURSOR hCursor)
{
m_hLinkCursor = hCursor;
if (m_hLinkCursor == NULL)
SetDefaultCursor();
}
HCURSOR CMapHyperLink::GetLinkCursor() const
{
return m_hLinkCursor;
}
void CMapHyperLink::SetAutoSize(BOOL bAutoSize /* = TRUE */)
{
m_bAdjustToFit = bAutoSize;
if (::IsWindow(GetSafeHwnd()))
PositionWindow();
}
BOOL CMapHyperLink::GetAutoSize() const
{
return m_bAdjustToFit;
}
// Move and resize the window so that the window is the same size
void CMapHyperLink::PositionWindow()
{
if (!::IsWindow(GetSafeHwnd()) || !m_bAdjustToFit)
return;
// Get the current window position
CRect rect;
GetWindowRect(rect);
CWnd* pParent = GetParent();
if (pParent)
pParent->ScreenToClient(rect);
CRect rectMap;
GetClientRect(rectMap);
// Get the text justification via the window style
DWORD dwStyle = GetStyle();
// Recalc the window size and position based on the text justification
if (dwStyle & SS_CENTERIMAGE)
rect.DeflateRect(0, (rect.Height() - rectMap.Height())/2);
else
rect.bottom = rect.top + rectMap.Height();
if (dwStyle & SS_CENTER)
rect.DeflateRect((rect.Width() - rectMap.Width())/2, 0);
else if (dwStyle & SS_RIGHT)
rect.left = rect.right - rectMap.Width();
else // SS_LEFT = 0, so we can''''t test for it explicitly
rect.right = rect.left + rectMap.Width();
// Move the window
SetWindowPos(NULL, rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOZORDER);