<commit_before>// 31 july 2014
#include "windlgunits.h"

HFONT lfMessageFont;

struct mainwin {
	HWND hXCoord;
	HWND hYCoord;
	HWND hResults;
	UINT x;
	UINT y;
	int xs[nModes];
	int ys[nModes];
};

#define printf(...) abort()

static HFONT chooseFont(HWND parent)
{
	CHOOSEFONTW cf;
	LOGFONTW lf;
	HFONT font;

	ZeroMemory(&cf, sizeof (CHOOSEFONTW));
	ZeroMemory(&lf, sizeof (LOGFONTW));
	cf.lStructSize = sizeof (CHOOSEFONTW);
	cf.hwndOwner = parent;
	cf.lpLogFont = &lf;
	cf.Flags = CF_EFFECTS;		// TODO CF_FORCEFONTEXIST?
	cf.rgbColors = RGB(0, 0, 0);
	if (ChooseFontW(&cf) == FALSE) {
		DWORD err;

		err = CommDlgExtendedError();
		if (err == 0)		// user cancelled
			return NULL;
		printf("panic TODO\n");
	}
	font = CreateFontIndirectW(&lf);
	if (font == NULL)
		printf("panic TODO\n");
	return font;
}

static void recalc(HWND hwnd, struct mainwin *mainwin, HFONT font)
{
	runCalculations(hwnd, font, mainwin->x, mainwin->y, mainwin->xs, mainwin->ys);
	refreshResultsListView(mainwin->hResults);
}

INT_PTR CALLBACK mainwinDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	struct mainwin *mainwin;
	HFONT font;
	NMHDR *nmhdr = (NMHDR *) lParam;
	NMLVDISPINFOW *fill = (NMLVDISPINFO *) lParam;

	mainwin = (struct mainwin *) GetWindowLongPtr(hwnd, DWLP_USER);
	if (mainwin == NULL && uMsg != WM_INITDIALOG)		// skip if not ready yet
		return FALSE;
	switch (uMsg) {
	case WM_INITDIALOG:
		mainwin = (struct mainwin *) malloc(sizeof (struct mainwin));
		if (mainwin == NULL)
			printf("TODO panic\n");
		ZeroMemory(mainwin, sizeof (struct mainwin));
		mainwin->hXCoord = GetDlgItem(hwnd, ecXCoord);
		if (mainwin->hXCoord == NULL)
			printf("TODO panic\n");
		mainwin->hYCoord = GetDlgItem(hwnd, ecYCoord);
		if (mainwin->hYCoord == NULL)
			printf("TODO panic\n");
		mainwin->hResults = GetDlgItem(hwnd, lcResults);
		if (mainwin->hResults == NULL)
			printf("TODO panic\n");
		SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) mainwin);
		initResultsListView(mainwin->hResults);
		return TRUE;
	case WM_COMMAND:
		switch (HIWORD(wParam)) {
		case BN_CLICKED:
			switch (LOWORD(wParam)) {
			case bcChooseFont:
				font = chooseFont(hwnd);
				if (font == NULL)
					return TRUE;
				recalc(hwnd, mainwin, font);
				if (DeleteObject(font) == 0)
					printf("panic TODO\n");
				return TRUE;
			case bclfMessageFont:
				recalc(hwnd, mainwin, lfMessageFont);
				return TRUE;
			case bcDialogFont:
				font = (HFONT) SendMessageW(hwnd, WM_GETFONT, 0, 0);
				if (font == NULL)
					printf("panic TODO\n");
				recalc(hwnd, mainwin, font);
				return TRUE;
			}
			return FALSE;
		}
		return FALSE;
	case WM_NOTIFY:
		if (nmhdr->code == LVN_GETDISPINFO && nmhdr->idFrom == lcResults) {
			switch (fill->item.iSubItem) {
			case 0:		// mode name
				fill->item.pszText = modenames[fill->item.iItem];
				return TRUE;
			case 1:		// width
				swprintf_s(fill->item.pszText, fill->item.cchTextMax, L"%d", mainwin->xs[fill->item.iItem]);
				return TRUE;
			case 2:		// height
				swprintf_s(fill->item.pszText, fill->item.cchTextMax, L"%d", mainwin->ys[fill->item.iItem]);
				return TRUE;
			}
			// else fallthrough
		}
		return FALSE;
	case WM_CLOSE:
		if (EndDialog(hwnd, 1) == 0)
			printf("TODO panic\n");<commit_msg>Added code for handling typing in measurements. Program works!...almost. (First measurement busted.)<commit_after>// 31 july 2014
#include "windlgunits.h"

HFONT lfMessageFont;

struct mainwin {
	HWND hXCoord;
	HWND hYCoord;
	HWND hResults;
	int x;
	int y;
	int xs[nModes];
	int ys[nModes];
	HFONT font;
	BOOL freeFont;
};

#define printf(...) abort()

static HFONT chooseFont(HWND parent)
{
	CHOOSEFONTW cf;
	LOGFONTW lf;
	HFONT font;

	ZeroMemory(&cf, sizeof (CHOOSEFONTW));
	ZeroMemory(&lf, sizeof (LOGFONTW));
	cf.lStructSize = sizeof (CHOOSEFONTW);
	cf.hwndOwner = parent;
	cf.lpLogFont = &lf;
	cf.Flags = CF_EFFECTS;		// TODO CF_FORCEFONTEXIST?
	cf.rgbColors = RGB(0, 0, 0);
	if (ChooseFontW(&cf) == FALSE) {
		DWORD err;

		err = CommDlgExtendedError();
		if (err == 0)		// user cancelled
			return NULL;
		printf("panic TODO\n");
	}
	font = CreateFontIndirectW(&lf);
	if (font == NULL)
		printf("panic TODO\n");
	return font;
}

static void freefont(struct mainwin *mainwin)
{
	if (!mainwin->freeFont)		// only if we should
		return;
	if (DeleteObject(mainwin->font) == 0)
		printf("panic TODO\n");
}

static void recalc(HWND hwnd, struct mainwin *mainwin)
{
	runCalculations(hwnd, mainwin->font, mainwin->x, mainwin->y, mainwin->xs, mainwin->ys);
	refreshResultsListView(mainwin->hResults);
}

INT_PTR CALLBACK mainwinDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	struct mainwin *mainwin;
	HFONT font;
	NMHDR *nmhdr = (NMHDR *) lParam;
	NMLVDISPINFOW *fill = (NMLVDISPINFO *) lParam;
	UINT entry;
	BOOL valid;

	mainwin = (struct mainwin *) GetWindowLongPtr(hwnd, DWLP_USER);
	if (mainwin == NULL && uMsg != WM_INITDIALOG)		// skip if not ready yet
		return FALSE;
	switch (uMsg) {
	case WM_INITDIALOG:
		mainwin = (struct mainwin *) malloc(sizeof (struct mainwin));
		if (mainwin == NULL)
			printf("TODO panic\n");
		ZeroMemory(mainwin, sizeof (struct mainwin));
		mainwin->hXCoord = GetDlgItem(hwnd, ecXCoord);
		if (mainwin->hXCoord == NULL)
			printf("TODO panic\n");
		mainwin->hYCoord = GetDlgItem(hwnd, ecYCoord);
		if (mainwin->hYCoord == NULL)
			printf("TODO panic\n");
		mainwin->hResults = GetDlgItem(hwnd, lcResults);
		if (mainwin->hResults == NULL)
			printf("TODO panic\n");
		// let's avoid a crash at startup by using lfMessageFont by default
		mainwin->font = lfMessageFont;
		mainwin->freeFont = FALSE;
		SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR) mainwin);
		initResultsListView(mainwin->hResults);
		return TRUE;
	case WM_COMMAND:
		switch (HIWORD(wParam)) {
		case BN_CLICKED:
			switch (LOWORD(wParam)) {
			case bcChooseFont:
				font = chooseFont(hwnd);
				if (font == NULL)
					return TRUE;
				freefont(mainwin);
				mainwin->font = font;
				mainwin->freeFont = TRUE;
				recalc(hwnd, mainwin);
				return TRUE;
			case bclfMessageFont:
				freefont(mainwin);
				mainwin->font = lfMessageFont;
				mainwin->freeFont = FALSE;
				recalc(hwnd, mainwin);
				return TRUE;
			case bcDialogFont:
				freefont(mainwin);
				mainwin->font = (HFONT) SendMessageW(hwnd, WM_GETFONT, 0, 0);
				if (mainwin->font == NULL)
					printf("panic TODO\n");
				mainwin->freeFont = FALSE;
				recalc(hwnd, mainwin);
				return TRUE;
			}
			return FALSE;
		case EN_CHANGE:
			switch (LOWORD(wParam)) {
			case ecXCoord:
				entry = GetDlgItemInt(hwnd, ecXCoord, &valid, FALSE);
				if (!valid) {
					MessageBeep(-1);
					// TODO
					return TRUE;
				}
				mainwin->x = (int) entry;
				recalc(hwnd, mainwin);
				return TRUE;
			case ecYCoord:
				entry = GetDlgItemInt(hwnd, ecYCoord, &valid, FALSE);
				if (!valid) {
					MessageBeep(-1);
					// TODO
					return TRUE;
				}
				mainwin->y = (int) entry;
				recalc(hwnd, mainwin);
				return TRUE;
			}
			return FALSE;
		}
		return FALSE;
	case WM_NOTIFY:
		if (nmhdr->code == LVN_GETDISPINFO && nmhdr->idFrom == lcResults) {
			switch (fill->item.iSubItem) {
			case 0:		// mode name
				fill->item.pszText = modenames[fill->item.iItem];
				return TRUE;
			case 1:		// width
				swprintf_s(fill->item.pszText, fill->item.cchTextMax, L"%d", mainwin->xs[fill->item.iItem]);
				return TRUE;
			case 2:		// height
				swprintf_s(fill->item.pszText, fill->item.cchTextMax, L"%d", mainwin->ys[fill->item.iItem]);
				return TRUE;
			}
			// else fallthrough
		}
		return FALSE;
	case WM_CLOSE:
		if (EndDialog(hwnd, 1) == 0)
			printf("TODO panic\n");
{'fraction_non_alphanumeric': 0.142668776371308, 'fraction_numerical': 0.0050105485232067514, 'mean_word_length': 3.705334987593052, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1926085', 'n_tokens_mistral': 3328, 'n_tokens_neox': 2941, 'n_words': 683}