Skip to content

Commit

Permalink
Up to 1.0.6
Browse files Browse the repository at this point in the history
* Sort columns by Ctrl + 1, Ctrl + 2, ...
* Fix issue for non-ANSI fonts
  • Loading branch information
little-brother committed Nov 20, 2023
1 parent 0d7db4f commit 2922eb2
Showing 1 changed file with 69 additions and 18 deletions.
87 changes: 69 additions & 18 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
#define WMU_UPDATE_HIGHLIGHT WM_USER + 11
#define WMU_HIDE_COLUMN WM_USER + 12
#define WMU_SHOW_COLUMNS WM_USER + 13
#define WMU_HOT_KEYS WM_USER + 14
#define WMU_HOT_CHARS WM_USER + 15
#define WMU_SORT_COLUMN WM_USER + 14
#define WMU_HOT_KEYS WM_USER + 15
#define WMU_HOT_CHARS WM_USER + 16

#define IDC_MAIN 100
#define IDC_TREE 101
Expand Down Expand Up @@ -65,7 +66,7 @@
#define MAX_COLUMN_COUNT 128
#define MAX_COLUMN_LENGTH 2000
#define APP_NAME TEXT("jsontab")
#define APP_VERSION TEXT("1.0.5")
#define APP_VERSION TEXT("1.0.6")

#define CP_UTF16LE 1200
#define CP_UTF16BE 1201
Expand Down Expand Up @@ -946,14 +947,7 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

if (pHdr->idFrom == IDC_GRID && pHdr->code == LVN_COLUMNCLICK) {
NMLISTVIEW* lv = (NMLISTVIEW*)lParam;
if (HIWORD(GetKeyState(VK_CONTROL)))
return SendMessage(hWnd, WMU_HIDE_COLUMN, lv->iSubItem, 0);

int colNo = lv->iSubItem + 1;
int* pOrderBy = (int*)GetProp(hWnd, TEXT("ORDERBY"));
int orderBy = *pOrderBy;
*pOrderBy = colNo == orderBy || colNo == -orderBy ? -orderBy : colNo;
SendMessage(hWnd, WMU_UPDATE_RESULTSET, 0, 0);
return SendMessage(hWnd, HIWORD(GetKeyState(VK_CONTROL)) ? WMU_HIDE_COLUMN : WMU_SORT_COLUMN, lv->iSubItem, 0);
}

if (pHdr->idFrom == IDC_GRID && (pHdr->code == (DWORD)NM_CLICK || pHdr->code == (DWORD)NM_RCLICK)) {
Expand Down Expand Up @@ -1014,9 +1008,26 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}

if (kd->wVKey == VK_LEFT || kd->wVKey == VK_RIGHT) {
HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB);
HWND hGridWnd = GetDlgItem(hTabWnd, IDC_GRID);
HWND hHeader = ListView_GetHeader(hGridWnd);

int colCount = Header_GetItemCount(ListView_GetHeader(pHdr->hwndFrom));
int colNo = *(int*)GetProp(hWnd, TEXT("CURRENTCOLNO")) + (kd->wVKey == VK_RIGHT ? 1 : -1);
colNo = colNo < 0 ? colCount - 1 : colNo > colCount - 1 ? 0 : colNo;
int colNo = *(int*)GetProp(hWnd, TEXT("CURRENTCOLNO"));

int* colOrder = calloc(colCount, sizeof(int));
Header_GetOrderArray(hHeader, colCount, colOrder);

int dir = kd->wVKey == VK_RIGHT ? 1 : -1;
int idx = 0;
for (idx; colOrder[idx] != colNo; idx++);
do {
idx = (colCount + idx + dir) % colCount;
} while (ListView_GetColumnWidth(hGridWnd, colOrder[idx]) == 0);

colNo = colOrder[idx];
free(colOrder);

SendMessage(hWnd, WMU_SET_CURRENT_CELL, *(int*)GetProp(hWnd, TEXT("CURRENTROWNO")), colNo);
return TRUE;
}
Expand Down Expand Up @@ -1085,7 +1096,20 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

InvalidateRect(hGridWnd, NULL, TRUE);
}
break;
break;

// wParam = colNo
case WMU_SORT_COLUMN: {
int colNo = (int)wParam + 1;
if (colNo <= 0)
return FALSE;

int* pOrderBy = (int*)GetProp(hWnd, TEXT("ORDERBY"));
int orderBy = *pOrderBy;
*pOrderBy = colNo == orderBy || colNo == -orderBy ? -orderBy : colNo;
SendMessage(hWnd, WMU_UPDATE_RESULTSET, 0, 0);
}
break;

case WMU_UPDATE_GRID: {
HWND hTreeWnd = GetDlgItem(hWnd, IDC_TREE);
Expand Down Expand Up @@ -1617,7 +1641,7 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
*pFontSize += wParam;
DeleteFont(GetProp(hWnd, TEXT("FONT")));

HFONT hFont = CreateFont (*pFontSize, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, (TCHAR*)GetProp(hWnd, TEXT("FONTFAMILY")));
HFONT hFont = CreateFont (*pFontSize, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, (TCHAR*)GetProp(hWnd, TEXT("FONTFAMILY")));
HWND hTreeWnd = GetDlgItem(hWnd, IDC_TREE);
HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB);
HWND hGridWnd = GetDlgItem(hTabWnd, IDC_GRID);
Expand Down Expand Up @@ -1723,15 +1747,42 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {

if (wParam == VK_ESCAPE || wParam == VK_F11 ||
wParam == VK_F3 || wParam == VK_F5 || wParam == VK_F7 || (isCtrl && wParam == 0x46) || // Ctrl + F
((wParam >= 0x31 && wParam <= 0x38) && !getStoredValue(TEXT("disable-num-keys"), 0) || // 1 - 8
((wParam >= 0x31 && wParam <= 0x38) && !getStoredValue(TEXT("disable-num-keys"), 0) && !isCtrl || // 1 - 8
(wParam == 0x4E || wParam == 0x50) && !getStoredValue(TEXT("disable-np-keys"), 0) || // N, P
wParam == 0x51 && getStoredValue(TEXT("exit-by-q"), 0)) && // Q
GetDlgCtrlID(GetFocus()) / 100 * 100 != IDC_HEADER_EDIT) {
SetFocus(GetParent(hWnd));
keybd_event(wParam, wParam, KEYEVENTF_EXTENDEDKEY, 0);

return TRUE;
}
}

if (isCtrl && wParam >= 0x30 && wParam <= 0x39 && !getStoredValue(TEXT("disable-num-keys"), 0)) {// 0-9
HWND hTabWnd = GetDlgItem(hWnd, IDC_TAB);
HWND hGridWnd = GetDlgItem(hTabWnd, IDC_GRID);
HWND hHeader = ListView_GetHeader(hGridWnd);
int colCount = Header_GetItemCount(ListView_GetHeader(hGridWnd));

BOOL isCurrent = wParam == 0x30;
int colNo = isCurrent ? *(int*)GetProp(hWnd, TEXT("CURRENTCOLNO")) : wParam - 0x30 - 1;
if (colNo < 0 || colNo > colCount - 1 || isCurrent && ListView_GetColumnWidth(hGridWnd, colNo) == 0)
return FALSE;

if (!isCurrent) {
int* colOrder = calloc(colCount, sizeof(int));
Header_GetOrderArray(hHeader, colCount, colOrder);

int hiddenColCount = 0;
for (int idx = 0; (idx < colCount) && (idx - hiddenColCount <= colNo); idx++)
hiddenColCount += ListView_GetColumnWidth(hGridWnd, colOrder[idx]) == 0;

colNo = colOrder[colNo + hiddenColCount];
free(colOrder);
}

SendMessage(hWnd, WMU_SORT_COLUMN, colNo, 0);
return TRUE;
}

return FALSE;
}
Expand All @@ -1741,7 +1792,7 @@ LRESULT CALLBACK cbNewMain(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
BOOL isCtrl = HIWORD(GetKeyState(VK_CONTROL));

unsigned char scancode = ((unsigned char*)&lParam)[2];
UINT key = MapVirtualKey(scancode,MAPVK_VSC_TO_VK);
UINT key = MapVirtualKey(scancode, MAPVK_VSC_TO_VK);

return !_istprint(wParam) && (
wParam == VK_ESCAPE || wParam == VK_F11 || wParam == VK_F1 ||
Expand Down

0 comments on commit 2922eb2

Please sign in to comment.