BOOL CGridURLCell::Draw(CDC* pDC, int nRow, int nCol, CRect rect, BOOL bEraseBkgnd) { // If url is present then change text color if (HasUrl(GetText())) SetTextClr(m_clrUrl); // Good a place as any to store the bounds of the rect m_Rect = rect; return CGridCell::Draw(pDC, nRow, nCol, rect, bEraseBkgnd); }
bool ClipboardUtil::GetUrl(IDataObject* data_object, std::wstring* url, std::wstring* title, bool convert_filenames) { DCHECK(data_object && url && title); if(!HasUrl(data_object)) { return false; } // 尝试从|data_object|的多种格式中提取URL. STGMEDIUM store; if(GetUrlFromHDrop(data_object, url, title)) { return true; } if(SUCCEEDED(data_object->GetData(GetMozUrlFormat(), &store)) || SUCCEEDED(data_object->GetData(GetUrlWFormat(), &store))) { { // Mozilla URL格式或者unicode URL. base::win::ScopedHGlobal<wchar_t> data(store.hGlobal); SplitUrlAndTitle(data.get(), url, title); } ReleaseStgMedium(&store); return true; } if(SUCCEEDED(data_object->GetData(GetUrlFormat(), &store))) { { // URL使用ascii. base::win::ScopedHGlobal<char> data(store.hGlobal); SplitUrlAndTitle(UTF8ToWide(data.get()), url, title); } ReleaseStgMedium(&store); return true; } if(convert_filenames) { return GetFileUrl(data_object, url, title); } else { return false; } }
// here we figure out if we are over a URL or not BOOL CGridURLCell::OverURL(CPoint& pt, CString& strURL) { //TRACE2("Checking point %d,%d\n",pt.x,pt.y); BOOL bOverURL = FALSE; CSize size = GetTextExtent(GetText()); // Add left of cell so we know if we clicked on text or not pt.x += m_Rect.left; CPoint center = m_Rect.CenterPoint(); if ((m_nFormat & DT_RIGHT) && pt.x >= (m_Rect.right - size.cx)) { bOverURL = TRUE; } else if ((m_nFormat & DT_CENTER) && ((center.x - (size.cx/2)) <= pt.x) && (pt.x <= (center.x + (size.cx/2))) ) { bOverURL = TRUE; } else if (pt.x <= (size.cx + m_Rect.left)) { bOverURL = TRUE; } if (!bOverURL) return FALSE; // We are over text - but are we over a URL? bOverURL = FALSE; strURL = GetText(); // Use float, otherwise we get an incorrect letter from the point float width = (float)size.cx/(float)strURL.GetLength(); // remove left of cell so we have original point again pt.x -= m_Rect.left; if (m_nFormat & DT_RIGHT) { int wide = m_Rect.Width() - size.cx; pt.x -= wide; if (pt.x <= 0) return FALSE; } if (m_nFormat & DT_CENTER) { int wide = m_Rect.Width() - size.cx; pt.x -= (wide/2); if (pt.x <= 0 || pt.x > (size.cx + (wide/2))) return FALSE; } // Turn point into a letter int ltrs = (int)((float)pt.x/width); #if !defined(_WIN32_WCE) || (_WIN32_WCE > 210) // Find spaces before and after letter, process text between int endSpace = strURL.Find(_T(' '), ltrs); if (endSpace != -1) strURL.Delete(endSpace, strURL.GetLength()-endSpace); int beginSpace = strURL.ReverseFind(_T(' ')); if (beginSpace != -1) strURL.Delete(0, ++beginSpace); #endif // Does text have url return HasUrl(strURL); }