Esempio n. 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;
}
Esempio n. 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;
}
//WM_COMMAND
void PBSettings_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
	(void) hwndCtl; //To avoid the warning
	//Get the PBSDP
	PenBrushSettingsDlgParam * pbsdp=(PenBrushSettingsDlgParam *)(LONG_PTR)GetWindowLongPtr(hwnd,GWLP_USERDATA);
	if(pbsdp==NULL)
		return;
	switch(id)
	{
	case IDOK: //OK button
		if(codeNotify==BN_CLICKED)
		{
			fgColor=pbsdp->workingFG;
			bgColor=pbsdp->workingBG;
		}
		//Note: no break
	case IDCANCEL: //Cancel button
		if(codeNotify==BN_CLICKED)
			EndDialog(hwnd,id);
		break; //case IDCANCEL: (and IDOK:)
	case IDC_PB_B_COLOR: //Click on the color pane: ask the user a new color and update the preview and the color pane
		if(codeNotify==BN_CLICKED)
		{
			pbsdp->GetCurrentCU().SetColor(GetColor(hwnd,pbsdp->GetCurrentCU().GetColor(),dsUpdater->GetDibSection()));
			InvalidateRect(GetDlgItem(hwnd,IDC_PB_B_COLOR),NULL,FALSE);
			UpdatePreviewPane(hwnd);
		}
		break; //case IDC_PB_B_COLOR:
	case IDC_PB_H_COLORP: //Click on the hatch color pane: ask the user a new color and update the preview and the hatch color pane
		if(codeNotify==BN_CLICKED)
		{
			pbsdp->workingBG.GetRefACUPs().bgColor=pbsdp->workingFG.GetRefACUPs().bgColor=GetColor(hwnd,pbsdp->workingBG.GetRefACUPs().bgColor,dsUpdater->GetDibSection());
			InvalidateRect(GetDlgItem(hwnd,IDC_PB_H_COLORP),NULL,FALSE);
			UpdatePreviewPane(hwnd);
		}
		break; //case IDC_PB_H_COLORP:
	case IDC_PB_H_COLOR: //Click on the transparent/opaque secondary hatch color radio buttons
	case IDC_PB_H_TRANSPARENT:
		if(codeNotify==BN_CLICKED)
		{
			//Update the ColorUtils
			CommonControls2ColorUtils(hwnd);
			//Update the preview pane
			UpdatePreviewPane(hwnd);
		}
		break; //case IDC_PB_H_COLOR: / IDC_PB_H_TRANSPARENT:
	case IDC_PB_PREVIEW: //Click on the preview pane
		if(codeNotify==BN_CLICKED)
		{
			pbsdp->swappedColors=!pbsdp->swappedColors;
			//Update the preview pane
			UpdatePreviewPane(hwnd);
		}
		break; //case IDC_PB_PREVIEW:
	case IDC_PB_TX_WIDTH:
		if(codeNotify==EN_CHANGE)
		{
			static UINT lastVal=pbsdp->workingFG.GetPenWidth();
			if(ValidateUIntFieldChange(hwnd,(WORD)id,lastVal,MINPENWIDTH,MAXPENWIDTH))
			{
				//Update the ColorUtils
				CommonControls2ColorUtils(hwnd);
				//Update the preview pane
				UpdatePreviewPane(hwnd);
			}
		}
	default: //Others
		//Brush radiobuttons: update the ColorUtils and the preview pane
		if(
			BETWEEN(id,IDC_PB_B_SOLID,IDC_PB_B_HDI) &&
			codeNotify == BN_CLICKED
			)
		{
			pbsdp->GetCurrentCU().SetBrushSettings(BrushFromCtrls(hwnd,pbsdp->GetCurrentCU().GetColor()));
			UpdatePreviewPane(hwnd);
			break;
		}
		//Pen radiobuttons: update the ColorUtils and the preview pane
		else if(
			BETWEEN(id,IDC_PB_P_SOLID,IDC_PB_P_CUSTOM) ||
			BETWEEN(id,IDC_PB_P_END_ROUND,IDC_PB_P_END_FLAT) ||
			BETWEEN(id,IDC_PB_P_LJ_ROUND,IDC_PB_P_LJ_MITER) ||
			id==IDC_PB_P_TX_CUSTOM && codeNotify == EN_CHANGE
			)
		{
			nEXTLOGPEN lp=PenFromCtrls(hwnd,pbsdp->GetCurrentCU().GetPenWidth());
			if(id == IDC_PB_P_CUSTOM)
			{
				EnableWindow(GetDlgItem(hwnd,IDC_PB_P_TX_CUSTOM),TRUE);
				ShowWindow(GetDlgItem(hwnd,IDC_PB_P_IS_CUSTOM),SW_SHOWNA);
			}
			else if(BETWEEN(id,IDC_PB_P_SOLID,IDC_PB_P_DASHDOTDOT))
			{
				EnableWindow(GetDlgItem(hwnd,IDC_PB_P_TX_CUSTOM),FALSE);
				ShowWindow(GetDlgItem(hwnd,IDC_PB_P_IS_CUSTOM),SW_HIDE);
			}
			pbsdp->GetCurrentCU().SetPenSettings(lp);
			if(((lp.dwPenStyle&PS_STYLE_MASK)==PS_USERSTYLE)&&lp.lpStyle!=NULL)
				delete[] lp.lpStyle;
			UpdatePreviewPane(hwnd);
			break;
		}
	}
}