浏览代码

Search for search string for color changes case insensitive

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@738 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 11 年之前
父节点
当前提交
481a5cebd4
共有 4 个文件被更改,包括 45 次插入7 次删除
  1. 41 0
      Misc.cpp
  2. 1 0
      Misc.h
  3. 3 6
      QListCtrl.cpp
  4. 0 1
      QListCtrl.h

+ 41 - 0
Misc.cpp

@@ -1011,4 +1011,45 @@ __int64 FileSize(const TCHAR *fileName)
 		return -1; // error, could use errno to find out more
 
 	return buf.st_size;
+}
+
+int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, CString postInsert)
+{
+	int replaceCount = 0;
+
+	//Prevent infinite loop when user tries to replace nothing.
+	if (findStr != "")
+	{
+		int oldLen = findStr.GetLength();
+
+		int nPos = 0;
+		int newPos = 0;
+		int insertedLength = 0;
+
+		//Copies of the main string and the string to be replaced that
+		//are made lower case
+		CString mainStr_low(mainStr);
+		CString findStr_low(findStr);
+		mainStr_low.MakeLower();
+		findStr_low.MakeLower();
+
+		int preLength = preInsert.GetLength();
+		int postLength = postInsert.GetLength();
+
+		while ((nPos = mainStr_low.Find(findStr_low, nPos)) != -1)
+		{
+			newPos = nPos + insertedLength;
+
+			mainStr.Insert(newPos, preInsert);
+			mainStr.Insert(newPos + preLength + oldLen, postInsert);
+
+			nPos += oldLen;
+
+			insertedLength += preLength + postLength;
+
+			replaceCount++;
+		}
+	}
+
+	return replaceCount;
 }

+ 1 - 0
Misc.h

@@ -142,5 +142,6 @@ void DeleteReceivedFiles(CString csDir);
 
 __int64 FileSize(const TCHAR *fileName);
 
+int FindNoCaseAndInsert(CString& mainStr, CString& findStr, CString preInsert, CString postInsert);
 
 #endif // !defined(AFX_CP_GUI_GLOBALS__FBCDED09_A6F2_47EB_873F_50A746EBC86B__INCLUDED_)

+ 3 - 6
QListCtrl.cpp

@@ -469,8 +469,7 @@ void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
 		if(DrawRtfText(nItem, rcText, pDC) == FALSE)
 		{
 			if (m_searchText.GetLength() > 0 &&
-				m_searchTextHtml.GetLength() > 0 &&
-				csText.Replace(m_searchText, m_searchTextHtml) > 0)
+				FindNoCaseAndInsert(csText, m_searchText, _T("<font color='#ff0000'>"), _T("</font>")) > 0)
 			{				
 				DrawHTML(pDC->m_hDC, csText, csText.GetLength(), rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
 			}
@@ -1466,7 +1465,5 @@ void CQListCtrl::StopHideScrollBarTimer()
 
 void CQListCtrl::SetSearchText(CString text) 
 { 
-	m_searchText = text; 
-
-	m_searchTextHtml.Format(_T("<font color='#ff0000'>%s</font>"), text);
-}
+	m_searchText = text;
+}

+ 0 - 1
QListCtrl.h

@@ -175,7 +175,6 @@ protected:
 	CGdiImageDrawer m_stickyImage;
 	int m_rowHeight;
 	CString m_searchText;
-	CString m_searchTextHtml;
 
 
 	// Generated message map functions