From e9022da6e78d3b5a46f9b727042d4658be0f6866 Mon Sep 17 00:00:00 2001 From: sdottaka Date: Mon, 11 Feb 2013 23:58:34 -0800 Subject: [PATCH] Make a folder compare report with color --- Src/DirCmpReport.cpp | 18 +++++++++++++++--- Src/IListCtrl.h | 1 + Src/IListCtrlImpl.h | 50 +++++++++++++++++++++++++++++++------------------- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/Src/DirCmpReport.cpp b/Src/DirCmpReport.cpp index 8972d6bcd..6371d564d 100644 --- a/Src/DirCmpReport.cpp +++ b/Src/DirCmpReport.cpp @@ -39,9 +39,12 @@ static String GetCurrentTimeString() * @param [in] elName String to format as beginning tag. * @return String formatted as beginning tag. */ -static String BeginEl(const String& elName) +static String BeginEl(const String& elName, const String& attr = _T("")) { - return string_format(_T("<%s>"), elName.c_str()); + if (attr.empty()) + return string_format(_T("<%s>"), elName.c_str()); + else + return string_format(_T("<%s %s>"), elName.c_str(), attr.c_str()); } /** @@ -398,8 +401,17 @@ void DirCmpReport::GenerateXmlHtmlContent(bool xml) String rowEl = _T("tr"); if (xml) + { rowEl = _T("filediff"); - WriteString(BeginEl(rowEl)); + WriteString(BeginEl(rowEl)); + } + else + { + COLORREF color = m_pList->GetBackColor(currRow); + String attr = string_format(_T("style='background-color: #%02x%02x%02x'"), + GetRValue(color), GetGValue(color), GetBValue(color)); + WriteString(BeginEl(rowEl, attr)); + } for (int currCol = 0; currCol < m_nColumns; currCol++) { String colEl = _T("td"); diff --git a/Src/IListCtrl.h b/Src/IListCtrl.h index 7a43d4750..34cc84dae 100644 --- a/Src/IListCtrl.h +++ b/Src/IListCtrl.h @@ -9,6 +9,7 @@ struct IListCtrl virtual int GetRowCount() const = 0; virtual String GetColumnName(int col) const = 0; virtual String GetItemText(int row, int col) const = 0; + virtual int GetBackColor(int row) const = 0; }; #endif diff --git a/Src/IListCtrlImpl.h b/Src/IListCtrlImpl.h index 6552c8c2e..a78d09d0b 100644 --- a/Src/IListCtrlImpl.h +++ b/Src/IListCtrlImpl.h @@ -1,13 +1,13 @@ -#include "IListCtrl.h" -#include - -class IListCtrlImpl : public IListCtrl -{ -public: - IListCtrlImpl(HWND hwndListCtrl) : m_hwndListCtrl(hwndListCtrl) - { - } - +#include "IListCtrl.h" +#include + +class IListCtrlImpl : public IListCtrl +{ +public: + IListCtrlImpl(HWND hwndListCtrl) : m_hwndListCtrl(hwndListCtrl) + { + } + int GetColumnCount() const { return Header_GetItemCount(ListView_GetHeader(m_hwndListCtrl)); @@ -29,13 +29,25 @@ public: return lvc.pszText; } - String GetItemText(int row, int col) const - { + String GetItemText(int row, int col) const + { TCHAR text[512]; // Assuming max col header will never be > 512 - ListView_GetItemText(m_hwndListCtrl, row, col, text, sizeof(text)/sizeof(text[0])); - return text; - } - -protected: - HWND m_hwndListCtrl; -}; \ No newline at end of file + ListView_GetItemText(m_hwndListCtrl, row, col, text, sizeof(text)/sizeof(text[0])); + return text; + } + + int GetBackColor(int row) const + { + NMLVCUSTOMDRAW nmlvcd = {0}; + nmlvcd.nmcd.hdr.code = NM_CUSTOMDRAW; + nmlvcd.nmcd.hdr.idFrom = GetDlgCtrlID(m_hwndListCtrl); + nmlvcd.nmcd.hdr.hwndFrom = m_hwndListCtrl; + nmlvcd.nmcd.dwDrawStage = CDDS_ITEMPREPAINT | CDDS_SUBITEM; + nmlvcd.nmcd.dwItemSpec = row; + SendMessage(GetParent(m_hwndListCtrl), WM_NOTIFY, (WPARAM)m_hwndListCtrl, (LPARAM)&nmlvcd); + return nmlvcd.clrTextBk; + } + +protected: + HWND m_hwndListCtrl; +}; -- 2.11.0