예제 #1
0
BOOL InitFontOptionsDlg(HWND hwnd)
{
	HWND	hwndPreview;
	int		i;
	LOGFONT lf;
	HFONT   hDlgFont;
	TCHAR	ach[LF_FACESIZE];

	// make a temporary copy of the current colour settings
	memcpy(g_rgbTempColourList, g_rgbColourList, sizeof(COLORREF) * TXC_MAX_COLOURS);

	//
	//	Load the TrueType icon for the font-list
	//
	g_hIcon2 = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON2), IMAGE_ICON, 16, 16, 0);
	g_hIcon3 = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON3), IMAGE_ICON, 16, 16, 0);
	
	//
	//	Create two fonts (normal+bold) based on current dialog's font settings
	//
	hDlgFont = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
	GetObject(hDlgFont, sizeof(lf), &lf);
		
	g_hNormalFont = CreateFontIndirect(&lf);
	lf.lfWeight   = FW_BOLD;
	g_hBoldFont   = CreateFontIndirect(&lf);

	//
	//	Manually set the COMBO item-heights because WM_MEASUREITEM has already
	//  been sent and we missed it..
	//
	SetComboItemHeight(GetDlgItem(hwnd, IDC_FGCOLCOMBO), 14);
	SetComboItemHeight(GetDlgItem(hwnd, IDC_BGCOLCOMBO), 14);
	SetComboItemHeight(GetDlgItem(hwnd, IDC_FONTLIST), 16);
	
	g_tempFontSmoothing = g_nFontSmoothing;
	g_hPreviewFont = EasyCreateFont(g_nFontSize, g_fFontBold, g_tempFontSmoothing, g_szFontName);

	// Create the list of fonts
	FillFontComboList(GetDlgItem(hwnd, IDC_FONTLIST));

	// Update the font-size-list
	InitSizeList(hwnd);
	
	//
	//	Subclass the PREVIEW static control so we can custom-draw it
	//
	hwndPreview = GetDlgItem(hwnd, IDC_PREVIEW);
	oldPreviewProc = (WNDPROC)SetWindowLongPtr(hwndPreview, GWLP_WNDPROC, (LONG)PreviewWndProc);
	
//	g_rgbAutoColourList[TXC_LONGLINE]	= MixRGB(GetSysColor(COLOR_3DFACE), GetSysColor(COLOR_WINDOW));
//	g_rgbAutoColourList[TXC_LINENUMBER]	= MixRGB(GetSysColor(COLOR_3DFACE), GetSysColor(COLOR_WINDOW));
//	g_rgbAutoColourList[TXC_LINENUMBER] = MixRGB(g_rgbAutoColourList[TXC_LINENUMBER], GetSysColor(COLOR_WINDOW));

	//g_rgbAutoColourList[TXC_LONGLINE]	= MixRGB(GetSysColor(COLOR_3DFACE), GetSysColor(COLOR_WINDOW));
	//g_rgbAutoColourList[TXC_LINENUMBER]	= MixRGB(GetSysColor(COLOR_3DFACE), GetSysColor(COLOR_WINDOW));
	//g_rgbAutoColourList[TXC_LINENUMBER] = MixRGB(g_rgbAutoColourList[TXC_LINENUMBER], GetSysColor(COLOR_WINDOW));

	AddColourListItem(hwnd, IDC_LIST1, TXC_FOREGROUND,		TXC_BACKGROUND,   _T("Text"));
	AddColourListItem(hwnd, IDC_LIST1, TXC_HIGHLIGHTTEXT,	TXC_HIGHLIGHT,    _T("Selected Text"));
	AddColourListItem(hwnd, IDC_LIST1, TXC_HIGHLIGHTTEXT2,  TXC_HIGHLIGHT2,   _T("Inactive Selection"));
	AddColourListItem(hwnd, IDC_LIST1, TXC_SELMARGIN1,		TXC_SELMARGIN2,   _T("Left Margin"));
	AddColourListItem(hwnd, IDC_LIST1, TXC_LINENUMBERTEXT,  TXC_LINENUMBER,   _T("Line Numbers"));
	AddColourListItem(hwnd, IDC_LIST1, -1,					TXC_LONGLINE,	  _T("Long Lines"));
	AddColourListItem(hwnd, IDC_LIST1, TXC_CURRENTLINETEXT, TXC_CURRENTLINE,  _T("Current Line"));
	
	SendDlgItemMessage(hwnd, IDC_ITEMLIST, LB_SETCURSEL, 0, 0);
	PostMessage(hwnd, WM_COMMAND, MAKEWPARAM(IDC_ITEMLIST, LBN_SELCHANGE), (LPARAM)GetDlgItem(hwnd, IDC_ITEMLIST));

	for(i = 0; i < NUM_DEFAULT_COLOURS; i++)
	{
		AddColourComboItem(hwnd, IDC_FGCOLCOMBO, CUSTCOL[i].cr, CUSTCOL[i].szName);
		AddColourComboItem(hwnd, IDC_BGCOLCOMBO, CUSTCOL[i].cr, CUSTCOL[i].szName);
	}
	
	SendDlgItemMessage(hwnd, IDC_FGCOLCOMBO, CB_SETCURSEL, 1, 0);
	SendDlgItemMessage(hwnd, IDC_BGCOLCOMBO, CB_SETCURSEL, 0, 0);
	
	SendDlgItemMessage(hwnd, IDC_SPIN1, UDM_SETRANGE, 0, MAKELONG(10,0));
	SendDlgItemMessage(hwnd, IDC_SPIN2, UDM_SETRANGE, 0, MAKELONG(10,0));

	//
	//	Select
	//
	_stprintf(ach, _T("%d"), g_nFontSize);

	SendDlgItemMessage(hwnd, IDC_SIZELIST, CB_SELECTSTRING, -1, (LONG)ach);
	SendDlgItemMessage(hwnd, IDC_FONTLIST, CB_SELECTSTRING, -1, (LONG)g_szFontName);

	SetDlgItemInt(hwnd, IDC_PADDINGA, g_nPaddingAbove, 0);
	SetDlgItemInt(hwnd, IDC_PADDINGB, g_nPaddingBelow, 0);

	if((g_fPaddingFlags & COURIERNEW) && lstrcmpi(g_szFontName, _T("Courier New")) == 0)
	{
		SetDlgItemInt(hwnd, IDC_PADDINGA, g_nPaddingAbove, 0);
		SetDlgItemInt(hwnd, IDC_PADDINGB, g_nPaddingBelow, 1);
	}

	if((g_fPaddingFlags & LUCIDACONS) && lstrcmpi(g_szFontName, _T("Lucida Console")) == 0)
	{
		//SetDlgItemInt(hwnd, IDC_PADDINGA, g_nPaddingAbove, 2);
		//SetDlgItemInt(hwnd, IDC_PADDINGB, g_nPaddingBelow, 1);
		//SendDlgItemMessage(hwnd, IDC_
	}

	CheckDlgButton(hwnd, IDC_BOLD,    g_fFontBold);

	UpdatePreviewPane(hwnd);

	return TRUE;
}
예제 #2
0
//BOOL FontOptions(HWND hwnd, WPARAM wParam, 
//
//	Dialogbox procedure for the FONT pane
//
BOOL CALLBACK FontOptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	PSHNOTIFY *pshn;

	switch(msg)
	{
	case WM_INITDIALOG:
		CenterWindow(GetParent(hwnd));
		return InitFontOptionsDlg(hwnd);

	case MSG_UPDATE_PREVIEW:
		UpdatePreviewPane(hwnd);
		return TRUE;

	case WM_DESTROY:
		DeleteObject(g_hNormalFont);
		DeleteObject(g_hBoldFont);
		DeleteObject(g_hPreviewFont);
		return TRUE;

	case WM_MEASUREITEM:
		// can't do anything here because we haven't created
		// the fonts yet, so send a manual CB_SETITEMHEIGHT instead
		return FALSE;

	case WM_DRAWITEM:

		if(wParam == IDC_FONTLIST)
			return FontCombo_DrawItem(hwnd, (DRAWITEMSTRUCT *)lParam);

		else if(wParam == IDC_FGCOLCOMBO || wParam == IDC_BGCOLCOMBO)
			return ColourCombo_DrawItem(hwnd, wParam, (DRAWITEMSTRUCT *)lParam, FALSE);

		return FALSE;

	case WM_NOTIFY:

		pshn = (PSHNOTIFY *)lParam;

		if(pshn->hdr.code == NM_CUSTOMDRAW)
		{
			if(pshn->hdr.idFrom == IDC_FONTLIST)
			{
				return FALSE;
			}
			return FALSE;
		}		
		else if(pshn->hdr.code == PSN_APPLY)
		{
			g_nFontSize = GetDlgItemInt(hwnd, IDC_SIZELIST, 0, 0);
			g_fFontBold = IsDlgButtonChecked(hwnd, IDC_BOLD);

			GetDlgItemText(hwnd, IDC_FONTLIST, g_szFontName, LF_FACESIZE);	

			g_nPaddingAbove = GetDlgItemInt(hwnd, IDC_PADDINGA, 0, 0);
			g_nPaddingBelow = GetDlgItemInt(hwnd, IDC_PADDINGB, 0, 0);

			memcpy(g_rgbColourList, g_rgbTempColourList, sizeof(COLORREF) * TXC_MAX_COLOURS);

			g_nFontSmoothing = g_tempFontSmoothing;
			
			return TRUE;
		}

		return FALSE;

	case WM_COMMAND:

		switch(LOWORD(wParam))
		{
		case IDC_ADVANCED:
	
			if(DialogBoxParam(g_hResourceModule, MAKEINTRESOURCE(IDD_FONTEXTRA), hwnd, AdvancedDlgProc, 0))
			{
				UpdatePreviewPane(hwnd);
			}

			return TRUE;

		case IDCANCEL:
			return TRUE;

		case IDC_FONTLIST:
			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				InitSizeList(hwnd);
			}
				
			PostMessage(hwnd, MSG_UPDATE_PREVIEW, 0, 0);
			return TRUE;

		case IDC_ITEMLIST:

			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				DWORD itemidx = GetCurrentListData(hwnd, IDC_ITEMLIST);

				SelectColorInList(hwnd, IDC_FGCOLCOMBO, LOWORD(itemidx));
				SelectColorInList(hwnd, IDC_BGCOLCOMBO, HIWORD(itemidx));

				UpdatePreviewPane(hwnd);
			}

			return TRUE;

		case IDC_SIZELIST:
			
			if(HIWORD(wParam) == CBN_SELCHANGE || 
			   HIWORD(wParam) == CBN_EDITCHANGE)
			{
				PostMessage(hwnd, MSG_UPDATE_PREVIEW, 0, 0);
			}

			return TRUE;

		case IDC_FGCOLCOMBO:
		case IDC_BGCOLCOMBO:
			
			if(HIWORD(wParam) == CBN_SELCHANGE)
			{
				short fgidx = LOWORD(GetCurrentListData(hwnd, IDC_ITEMLIST));
				short bgidx = HIWORD(GetCurrentListData(hwnd, IDC_ITEMLIST));

				if(fgidx >= 0)
					g_rgbTempColourList[fgidx] = GetCurrentComboData(hwnd, IDC_FGCOLCOMBO);
				
				if(bgidx >= 0)
					g_rgbTempColourList[bgidx] = GetCurrentComboData(hwnd, IDC_BGCOLCOMBO);

				PostMessage(hwnd, MSG_UPDATE_PREVIEW, 0, 0);
			}

			return TRUE;
			
		case IDC_BOLD:
			PostMessage(hwnd, MSG_UPDATE_PREVIEW, 0, 0);
			return TRUE;

		case IDC_CUSTBUT1:
			{
				COLORREF col = 0;
				int idx = LOWORD(GetCurrentListData(hwnd, IDC_ITEMLIST));

				if(idx >= 0)
					col = REALIZE_SYSCOL(g_rgbTempColourList[idx]);
				
				if(PickColour(hwnd, &col, g_rgbCustColours))
				{
					g_rgbTempColourList[idx] = col;
					SelectColorInList(hwnd, IDC_FGCOLCOMBO, (short)idx);
					UpdatePreviewPane(hwnd);
				}
			}
			return TRUE;

		case IDC_CUSTBUT2:
			{
				COLORREF col = 0;
				int idx = HIWORD(GetCurrentListData(hwnd, IDC_ITEMLIST));
				
				if(idx >= 0)
					col = REALIZE_SYSCOL(g_rgbTempColourList[idx]);
				
				if(PickColour(hwnd, &col, g_rgbCustColours))
				{
					g_rgbTempColourList[idx] = col;
					SelectColorInList(hwnd, IDC_BGCOLCOMBO, (short)idx);
					UpdatePreviewPane(hwnd);
				}
			}
			return TRUE;
		}

		return FALSE;
	}

	return FALSE;
}
예제 #3
0
파일: Options.c 프로젝트: HTshandou/HexEdit
INT_PTR CALLBACK DisplayOptionsDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND	hwndPreview;

	switch(msg)
	{
	case WM_INITDIALOG:

		MakeFontCombo(hwnd, GetDlgItem(hwnd, IDC_FONTLIST));

		MakeColourCombo(GetDlgItem(hwnd, IDC_FGCOLCOMBO), crDefault, szTextList, 17);
		MakeColourCombo(GetDlgItem(hwnd, IDC_BGCOLCOMBO), crDefault, szTextList, 17);

		SetComboItemHeight(GetDlgItem(hwnd, IDC_FGCOLCOMBO), 14);
		SetComboItemHeight(GetDlgItem(hwnd, IDC_BGCOLCOMBO), 14);

		InitSizeList(GetDlgItem(hwnd, IDC_SIZELIST), TEXT("Courier New"));

		InitHexPreview(GetDlgItem(hwnd, IDC_HEXVIEW_PREVIEW));

	//
	//	Subclass the PREVIEW static control so we can custom-draw it
	//
	hwndPreview = GetDlgItem(hwnd, IDC_PREVIEW);
	oldPreviewProc = (WNDPROC)SetWindowLongPtr(hwndPreview, GWLP_WNDPROC, (LONG_PTR)PreviewWndProc);

		//AddColourListItem(hwnd, IDC_ITEMLIST, -1,				HVC_BACKGROUND,   TEXT("Background"));	
		AddColourListItem(hwnd, IDC_ITEMLIST, HVC_ADDRESS,		HVC_BACKGROUND,   TEXT("Address Column"));
		AddColourListItem(hwnd, IDC_ITEMLIST, HVC_HEXEVEN,		HVC_BACKGROUND,   TEXT("Hex Odd Columns"));
		AddColourListItem(hwnd, IDC_ITEMLIST, HVC_HEXODD,		HVC_BACKGROUND,   TEXT("Hex Even Columns"));
		AddColourListItem(hwnd, IDC_ITEMLIST, HVC_ASCII,		HVC_BACKGROUND,   TEXT("Ascii Column"));
		AddColourListItem(hwnd, IDC_ITEMLIST, HVC_SELECTION,	HVC_SELECTION,	  TEXT("Selected Data"));
		AddColourListItem(hwnd, IDC_ITEMLIST, HVC_SELECTION,	HVC_SELECTION,	  TEXT("Inactive Selection"));
		//AddColourListItem(hwnd, IDC_ITEMLIST, -1,					HVC_LONGLINE,	  TEXT("Modified Bytes"));
		//AddColourListItem(hwnd, IDC_ITEMLIST, HVC_CURRENTLINETEXT, HVC_CURRENTLINE,  TEXT("Current Line"));

		return TRUE;

	case WM_COMMAND:
		
		if(HIWORD(wParam) == LBN_SELCHANGE || HIWORD(wParam) == CBN_SELCHANGE)
		{
			int idx;
			

			switch(LOWORD(wParam))
			{
			case IDC_ITEMLIST:
				idx = SendDlgItemMessage(hwnd, IDC_ITEMLIST, LB_GETCURSEL, 0, 0);
				g_crPreviewFG = HexView_RealiseColour(g_colorItem[idx].fgColor);
				g_crPreviewBG = HexView_RealiseColour(g_colorItem[idx].bgColor);
				InvalidateRect(GetDlgItem(hwnd, IDC_PREVIEW), 0, 0);

				break;

			case IDC_SIZELIST:
			case IDC_FONTLIST:
				UpdateFontPreview(hwnd);
				break;
			}
		}
		


		return 0;

	case WM_MEASUREITEM:
		// can't do anything here because we haven't created
		// the fonts yet, so send a manual CB_SETITEMHEIGHT instead
		return FALSE;
	}

	return FALSE;
}