diff src/win32/Hyperlink.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/Hyperlink.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,93 @@
     1.4 +// Hyperlink.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "Hyperlink.h"
     1.9 +
    1.10 +/////////////////////////////////////////////////////////////////////////////
    1.11 +// Hyperlink
    1.12 +
    1.13 +Hyperlink::Hyperlink()
    1.14 +{
    1.15 +  m_over = false;
    1.16 +}
    1.17 +
    1.18 +Hyperlink::~Hyperlink()
    1.19 +{
    1.20 +  m_underlineFont.DeleteObject();
    1.21 +}
    1.22 +
    1.23 +
    1.24 +BEGIN_MESSAGE_MAP(Hyperlink, CStatic)
    1.25 +  //{{AFX_MSG_MAP(Hyperlink)
    1.26 +  ON_WM_CTLCOLOR_REFLECT()
    1.27 +  ON_WM_ERASEBKGND()
    1.28 +  ON_WM_MOUSEMOVE()
    1.29 +  //}}AFX_MSG_MAP
    1.30 +  ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
    1.31 +END_MESSAGE_MAP()
    1.32 +
    1.33 +  /////////////////////////////////////////////////////////////////////////////
    1.34 +// Hyperlink message handlers
    1.35 +
    1.36 +void Hyperlink::PreSubclassWindow() 
    1.37 +{
    1.38 +  DWORD dwStyle = GetStyle();
    1.39 +  ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
    1.40 +
    1.41 +  // 32649 is the hand cursor
    1.42 +  m_cursor = LoadCursor(NULL, MAKEINTRESOURCE(32649));
    1.43 +
    1.44 +  CFont *font = GetFont();
    1.45 +
    1.46 +  LOGFONT lg;
    1.47 +  font->GetLogFont(&lg);
    1.48 +
    1.49 +  lg.lfUnderline = TRUE;
    1.50 +  
    1.51 +  m_underlineFont.CreateFontIndirect(&lg);
    1.52 +  SetFont(&m_underlineFont);
    1.53 +	
    1.54 +  CStatic::PreSubclassWindow();
    1.55 +}
    1.56 +
    1.57 +void Hyperlink::OnClicked()
    1.58 +{
    1.59 +  CString url;
    1.60 +  GetWindowText(url);
    1.61 +  ::ShellExecute(0, _T("open"), url, 
    1.62 +                 0, 0, SW_SHOWNORMAL);
    1.63 +}
    1.64 +
    1.65 +HBRUSH Hyperlink::CtlColor(CDC* pDC, UINT nCtlColor) 
    1.66 +{
    1.67 +  pDC->SetTextColor(RGB(0,0,240));
    1.68 +	
    1.69 +  return (HBRUSH)GetStockObject(NULL_BRUSH);
    1.70 +}
    1.71 +
    1.72 +BOOL Hyperlink::OnEraseBkgnd(CDC* pDC) 
    1.73 +{
    1.74 +  CRect rect;
    1.75 +  GetClientRect(rect);
    1.76 +  pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
    1.77 +
    1.78 +  return TRUE;
    1.79 +}
    1.80 +
    1.81 +void Hyperlink::OnMouseMove(UINT nFlags, CPoint point) 
    1.82 +{
    1.83 +  if(!m_over) {
    1.84 +    m_over = true;
    1.85 +    SetCapture();
    1.86 +    ::SetCursor(m_cursor);
    1.87 +  } else {
    1.88 +    CRect r;
    1.89 +    GetClientRect(&r);
    1.90 +
    1.91 +    if(!r.PtInRect(point)) {
    1.92 +      m_over = false;
    1.93 +      ReleaseCapture();
    1.94 +    }
    1.95 +  }
    1.96 +}