Skip to content

Commit

Permalink
Up to 1.0.3
Browse files Browse the repository at this point in the history
* Custom colors for selection rows
  • Loading branch information
little-brother committed Dec 11, 2022
1 parent 3764607 commit 35c8e23
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
#define MAX_LENGTH 4096
#define MAX_COLUMN_LENGTH 2000
#define APP_NAME TEXT("xmltab")
#define APP_VERSION TEXT("1.0.2")
#define APP_VERSION TEXT("1.0.3")
#define LOADING TEXT("Loading...")
#define WHITESPACE " \t\r\n"

Expand Down Expand Up @@ -411,7 +411,9 @@ HWND APIENTRY ListLoadW (HWND hListerWnd, TCHAR* fileToLoad, int showFlags) {
SetProp(hMainWnd, TEXT("BACKCOLOR2"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("FILTERTEXTCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("FILTERBACKCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("CURRENTCELLCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("CURRENTCELLCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("SELECTIONTEXTCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("SELECTIONBACKCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("SPLITTERCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("XMLTEXTCOLOR"), calloc(1, sizeof(int)));
SetProp(hMainWnd, TEXT("XMLTAGCOLOR"), calloc(1, sizeof(int)));
Expand Down Expand Up @@ -459,7 +461,7 @@ HWND APIENTRY ListLoadW (HWND hListerWnd, TCHAR* fileToLoad, int showFlags) {
205, 0, 100, 100, hTabWnd, (HMENU)IDC_GRID, GetModuleHandle(0), NULL);

int noLines = getStoredValue(TEXT("disable-grid-lines"), 0);
ListView_SetExtendedListViewStyle(hGridWnd, LVS_EX_FULLROWSELECT | (noLines ? 0 : LVS_EX_GRIDLINES) | LVS_EX_LABELTIP);
ListView_SetExtendedListViewStyle(hGridWnd, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER | (noLines ? 0 : LVS_EX_GRIDLINES) | LVS_EX_LABELTIP);
SetProp(hGridWnd, TEXT("WNDPROC"), (HANDLE)SetWindowLongPtr(hGridWnd, GWLP_WNDPROC, (LONG_PTR)cbHotKey));

HWND hHeader = ListView_GetHeader(hGridWnd);
Expand Down Expand Up @@ -573,6 +575,8 @@ void __stdcall ListCloseWindow(HWND hWnd) {
free((int*)GetProp(hWnd, TEXT("FILTERTEXTCOLOR")));
free((int*)GetProp(hWnd, TEXT("FILTERBACKCOLOR")));
free((int*)GetProp(hWnd, TEXT("CURRENTCELLCOLOR")));
free((int*)GetProp(hWnd, TEXT("SELECTIONTEXTCOLOR")));
free((int*)GetProp(hWnd, TEXT("SELECTIONBACKCOLOR")));
free((int*)GetProp(hWnd, TEXT("SPLITTERCOLOR")));
free((int*)GetProp(hWnd, TEXT("XMLTEXTCOLOR")));
free((int*)GetProp(hWnd, TEXT("XMLTAGCOLOR")));
Expand Down Expand Up @@ -618,6 +622,8 @@ void __stdcall ListCloseWindow(HWND hWnd) {
RemoveProp(hWnd, TEXT("FILTERTEXTCOLOR"));
RemoveProp(hWnd, TEXT("FILTERBACKCOLOR"));
RemoveProp(hWnd, TEXT("CURRENTCELLCOLOR"));
RemoveProp(hWnd, TEXT("SELECTIONTEXTCOLOR"));
RemoveProp(hWnd, TEXT("SELECTIONBACKCOLOR"));
RemoveProp(hWnd, TEXT("SPLITTERCOLOR"));
RemoveProp(hWnd, TEXT("XMLTEXTCOLOR"));
RemoveProp(hWnd, TEXT("XMLTAGCOLOR"));
Expand Down Expand Up @@ -1211,39 +1217,26 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

if (pHdr->idFrom == IDC_GRID && pHdr->code == (UINT)NM_CUSTOMDRAW) {
int result = CDRF_DODEFAULT;

NMLVCUSTOMDRAW* pCustomDraw = (LPNMLVCUSTOMDRAW)lParam;
NMLVCUSTOMDRAW* pCustomDraw = (LPNMLVCUSTOMDRAW)lParam;
if (pCustomDraw->nmcd.dwDrawStage == CDDS_PREPAINT)
result = CDRF_NOTIFYITEMDRAW;

if (pCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
result = CDRF_NOTIFYSUBITEMDRAW | CDRF_NEWFONT;

if (pCustomDraw->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM)) {
pCustomDraw->clrTextBk = pCustomDraw->nmcd.dwItemSpec % 2 == 0 ? *(int*)GetProp(hWnd, TEXT("BACKCOLOR")) : *(int*)GetProp(hWnd, TEXT("BACKCOLOR2"));
result = CDRF_NOTIFYPOSTPAINT;
if (pCustomDraw->nmcd.dwDrawStage == CDDS_ITEMPREPAINT) {
if (ListView_GetItemState(pHdr->hwndFrom, pCustomDraw->nmcd.dwItemSpec, LVIS_SELECTED)) {
pCustomDraw->nmcd.uItemState &= ~CDIS_SELECTED;
result = CDRF_NOTIFYSUBITEMDRAW;
} else {
pCustomDraw->clrTextBk = *(int*)GetProp(hWnd, pCustomDraw->nmcd.dwItemSpec % 2 == 0 ? TEXT("BACKCOLOR") : TEXT("BACKCOLOR2"));
}
}

if ((pCustomDraw->nmcd.dwDrawStage == CDDS_POSTPAINT) | CDDS_SUBITEM) {
if (pCustomDraw->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM)) {
int rowNo = *(int*)GetProp(hWnd, TEXT("CURRENTROWNO"));
int colNo = *(int*)GetProp(hWnd, TEXT("CURRENTCOLNO"));
if ((pCustomDraw->nmcd.dwItemSpec == (DWORD)rowNo) && (pCustomDraw->iSubItem == colNo)) {
HPEN hPen = CreatePen(PS_DOT, 1, *(int*)GetProp(hWnd, TEXT("CURRENTCELLCOLOR")));
HDC hDC = pCustomDraw->nmcd.hdc;
SelectObject(hDC, hPen);

RECT rc = {0};
ListView_GetSubItemRect(pHdr->hwndFrom, rowNo, colNo, LVIR_BOUNDS, &rc);
if (colNo == 0)
rc.right = ListView_GetColumnWidth(pHdr->hwndFrom, 0);

MoveToEx(hDC, rc.left - 2, rc.top + 1, 0);
LineTo(hDC, rc.right - 1, rc.top + 1);
LineTo(hDC, rc.right - 1, rc.bottom - 2);
LineTo(hDC, rc.left + 1, rc.bottom - 2);
LineTo(hDC, rc.left + 1, rc.top);
DeleteObject(hPen);
}
BOOL isCurrCell = (pCustomDraw->nmcd.dwItemSpec == (DWORD)rowNo) && (pCustomDraw->iSubItem == colNo);
pCustomDraw->clrText = *(int*)GetProp(hWnd, TEXT("SELECTIONTEXTCOLOR"));
pCustomDraw->clrTextBk = *(int*)GetProp(hWnd, isCurrCell ? TEXT("CURRENTCELLCOLOR") : TEXT("SELECTIONBACKCOLOR"));
}

return result;
Expand Down Expand Up @@ -1738,9 +1731,8 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
ShowWindow(GetDlgItem(hHeader, IDC_HEADER_EDIT + colNo), isFilterRow ? SW_SHOW : SW_HIDE);

// Bug fix: force Windows to redraw header
int w = ListView_GetColumnWidth(hGridWnd, 0);
ListView_SetColumnWidth(hGridWnd, 0, w + 1);
ListView_SetColumnWidth(hGridWnd, 0, w);
SetWindowPos(hGridWnd, 0, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE);
SendMessage(getMainWindow(hWnd), WM_SIZE, 0, 0);

if (isFilterRow)
SendMessage(hWnd, WMU_UPDATE_FILTER_SIZE, 0, 0);
Expand Down Expand Up @@ -1919,15 +1911,19 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
int backColor2 = !isDark ? getStoredValue(TEXT("back-color2"), RGB(240, 240, 240)) : getStoredValue(TEXT("back-color2-dark"), RGB(52, 52, 52));
int filterTextColor = !isDark ? getStoredValue(TEXT("filter-text-color"), RGB(0, 0, 0)) : getStoredValue(TEXT("filter-text-color-dark"), RGB(255, 255, 255));
int filterBackColor = !isDark ? getStoredValue(TEXT("filter-back-color"), RGB(240, 240, 240)) : getStoredValue(TEXT("filter-back-color-dark"), RGB(60, 60, 60));
int currCellColor = !isDark ? getStoredValue(TEXT("current-cell-color"), RGB(20, 250, 250)) : getStoredValue(TEXT("current-cell-color-dark"), RGB(20, 250, 250));
int currCellColor = !isDark ? getStoredValue(TEXT("current-cell-back-color"), RGB(70, 96, 166)) : getStoredValue(TEXT("current-cell-back-color-dark"), RGB(32, 62, 62));
int selectionTextColor = !isDark ? getStoredValue(TEXT("selection-text-color"), RGB(255, 255, 255)) : getStoredValue(TEXT("selection-text-color-dark"), RGB(220, 220, 220));
int selectionBackColor = !isDark ? getStoredValue(TEXT("selection-back-color"), RGB(10, 36, 106)) : getStoredValue(TEXT("selection-back-color-dark"), RGB(72, 102, 102));
int splitterColor = !isDark ? getStoredValue(TEXT("splitter-color"), GetSysColor(COLOR_BTNFACE)) : getStoredValue(TEXT("splitter-color-dark"), GetSysColor(COLOR_BTNFACE));

*(int*)GetProp(hWnd, TEXT("TEXTCOLOR")) = textColor;
*(int*)GetProp(hWnd, TEXT("BACKCOLOR")) = backColor;
*(int*)GetProp(hWnd, TEXT("BACKCOLOR2")) = backColor2;
*(int*)GetProp(hWnd, TEXT("FILTERTEXTCOLOR")) = filterTextColor;
*(int*)GetProp(hWnd, TEXT("FILTERBACKCOLOR")) = filterBackColor;
*(int*)GetProp(hWnd, TEXT("CURRENTCELLCOLOR")) = currCellColor;
*(int*)GetProp(hWnd, TEXT("CURRENTCELLCOLOR")) = currCellColor;
*(int*)GetProp(hWnd, TEXT("SELECTIONTEXTCOLOR")) = selectionTextColor;
*(int*)GetProp(hWnd, TEXT("SELECTIONBACKCOLOR")) = selectionBackColor;
*(int*)GetProp(hWnd, TEXT("SPLITTERCOLOR")) = splitterColor;

*(int*)GetProp(hWnd, TEXT("XMLTEXTCOLOR")) = !isDark ? getStoredValue(TEXT("xml-text-color"), RGB(0, 0, 0)) : getStoredValue(TEXT("xml-text-color-dark"), RGB(220, 220, 220));
Expand Down

0 comments on commit 35c8e23

Please sign in to comment.