⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmtbar.c

📁 文本编辑器
💻 C
📖 第 1 页 / 共 3 页
字号:
				GetWindowText(pfbs->hwndName, pfbs->cf.szFaceName,
							sizeof(pfbs->cf.szFaceName) / sizeof(TCHAR));
				pfbs->cf.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
				pfbs->cf.bCharSet = DEFAULT_CHARSET;
			}
			else
			{
				SendMessage(pfbs->hwndName, CB_GETLBTEXT, (WPARAM) iSel,
							(LPARAM) pfbs->cf.szFaceName);

				// Pull the other bits of data we had packed away.
				dw = ComboBox_GetItemData(pfbs->hwndName, iSel);
				dw >>= 16;
				pfbs->cf.bPitchAndFamily = (BYTE) dw & 0xFF;
				dw >>= 8;
				pfbs->cf.bCharSet = (BYTE) dw & 0xFF;
			}

			// Update the list of font sizes
			FFillSizes(hwnd);
			pfbs->fExpectChoice = FALSE;
		}
		break;

	case TBI_Size:
		if (pfbs->fExpectChoice)
		{
			TCHAR	szT[10];
			TCHAR *	pch = szT;
			LONG	lSize = 0;

			// Get the new font size
			pfbs->cf.dwMask |= CFM_SIZE;
			pfbs->dwCFMaskChange = CFM_SIZE;
			szT[0] = 0;

			// Get the new selection
			iSel = SendMessage(pfbs->hwndSize, CB_GETCURSEL, 0, 0);
			if (iSel < 0)
			{
	//	DebugStr("\pBefore GetWindowText in Format.c2");
				GetWindowText(pfbs->hwndSize, szT, sizeof(szT) / sizeof(TCHAR));
			}
			else
				SendMessage(pfbs->hwndSize, CB_GETLBTEXT, (WPARAM) iSel,
							(LPARAM) szT);

			while (*pch)
			{
				if (TEXT('0') <= *pch && *pch <= TEXT('9'))
				{
					lSize *= 10;
					lSize += *pch - '0';
				}
				else
				{
					// Got a bad character, reject the user's input
					lSize = 0;
					break;
				}
				*pch++;
			}

			if (lSize > 0 && lSize <= yHeightCharPtsMost)
				pfbs->cf.yHeight = lSize * 20;		// Make twips
			else
				MessageBox(hwnd, "Size must be between 1 and 1638", "Font",
							MB_ICONINFORMATION | MB_OK);
			pfbs->fExpectChoice = FALSE;
		}
		break;

	case TBI_Color:
		if (pfbs->fExpectChoice)
		{
			LONG ilSel = SendMessage(pfbs->hwndColor, CB_GETCURSEL, 0, 0);

			// Remember that we are picking a color
			pfbs->cf.dwMask |= CFM_COLOR;
			pfbs->dwCFMaskChange = CFM_COLOR;

			//$ FUTURE: For now always turn-off autocolor, but later we'll
			//			have to handle picking autocolor
			pfbs->cf.dwEffects &= ~CFE_AUTOCOLOR;

			if (ilSel < 0)
				pfbs->cf.crTextColor = 0;
			else
				pfbs->cf.crTextColor = (COLORREF) SendMessage(pfbs->hwndColor,
											CB_GETITEMDATA, (WPARAM) ilSel, 0);
			pfbs->fExpectChoice = FALSE;
		}
		break;

	case TBI_Bold:
	case TBI_Italic:
	case TBI_Underline:
	
		// NOTE: We reverse the if condition because by the time we get the
		//		 notification, the button has already been pressed.
		pfbs->dwCFMaskChange = rgdwCFEffect[nID - TBI_Bold];
		pfbs->cf.dwMask |= rgdwCFEffect[nID - TBI_Bold];
#ifdef NEVER
		if (!SendMessage(pfbs->hwndToolbar, TB_ISBUTTONCHECKED, nID, 0))
			pfbs->cf.dwEffects &= ~rgdwCFEffect[nID - TBI_Bold];
		else
			pfbs->cf.dwEffects |= rgdwCFEffect[nID - TBI_Bold];
#else
		pfbs->cf.dwEffects ^= rgdwCFEffect[nID - TBI_Bold];
#endif
		pfbs->fGiveUpFocus = TRUE;
		break;

	case TBI_Bullet:
		// NOTE: The button has already been pushed,
		// so the checked state is accurate
		pfbs->pf.dwMask |= PFM_NUMBERING | PFM_OFFSET;
		if (SendMessage(pfbs->hwndToolbar, TB_ISBUTTONCHECKED, nID, 0))
		{
			pfbs->pf.wNumbering = PFN_BULLET;
			pfbs->pf.dxOffset = cxBulletIndent;
		}
		else
		{
			pfbs->pf.wNumbering = 0;
			pfbs->pf.dxOffset = 0;
		}
		pfbs->fGiveUpFocus = TRUE;
		break;

	case TBI_IncreaseIndent:
	case TBI_DecreaseIndent:
		pfbs->fGiveUpFocus = TRUE;
		break;

	case TBI_Left:
	case TBI_Center:
	case TBI_Right:
		pfbs->pf.dwMask |= PFM_ALIGNMENT;
		pfbs->pf.wAlignment = rgwPFAlignment[nID - TBI_Left];
		pfbs->fGiveUpFocus = TRUE;
		PaintAlignment(pfbs);
		break;



	}



	// Give up the focus ?
	if (pfbs->fGiveUpFocus)
	{
		pfbs->fGiveUpFocus = FALSE;
		SetFocus(hwnd);
	}

	// Go tell our parent
	SendMessage(GetParent(hwnd), WM_COMMAND,
				GET_WM_COMMAND_MPS(nID, hwndCtl, nNotify));
}


/*
 *	FB_OnPaint
 *
 *	Purpose:
 *		Update our screen
 *
 *	Arguments:
 *		hwnd		The window
 *
 *	Returns:
 *		None.
 */
LOCAL void FB_OnPaint(HWND hwnd)
{
	FormatBarState *	pfbs = PfbsGetWindowPtr(hwnd);
	PAINTSTRUCT			ps;

	// Repaint the toolbar as needed
	BeginPaint(hwnd, &ps);
//	PaintName(pfbs);
//	PaintSize(pfbs);
//	PaintColor(pfbs);
//	PaintEffects(pfbs);
//	PaintAlignment(pfbs);
	SendMessage(pfbs->hwndToolbar, WM_PAINT, 0, 0);
	EndPaint(hwnd, &ps);
}


/*
 *	SetCharFormat
 *
 *	Purpose:
 *		Set the current char format
 *
 *	Arguments:
 *		hwnd		The format bar window
 *		pcfNew		The new formatting
 *
 *	Returns:
 *		None.
 */
LOCAL VOID SetCharFormat(HWND hwnd, CHARFORMAT *pcfNew)
{
	FormatBarState *	pfbs = PfbsGetWindowPtr(hwnd);
	CHARFORMAT *		pcf = &pfbs->cf;
	DWORD				dwMask;
	DWORD				dwEffects;

	TraceCharFormat("EM_SETCHARFORMAT", pcfNew);

	if(pcfNew->cbSize != sizeof(CHARFORMAT))
		return;

	// Change in font name ?
	if (lstrcmpi(pcf->szFaceName, pcfNew->szFaceName) ||
		(pcf->bPitchAndFamily != pcfNew->bPitchAndFamily) ||
		(pcf->dwMask & CFM_FACE) != (pcfNew->dwMask & CFM_FACE))
	{
		pcf->dwMask &= ~CFM_FACE;
		pcf->dwMask |= pcfNew->dwMask & CFM_FACE;
		lstrcpy(pcf->szFaceName, pcfNew->szFaceName);
		pcf->bPitchAndFamily = pcfNew->bPitchAndFamily;
		PaintName(pfbs);
	}

	// Change in charset ?
	if (pcf->bCharSet != pcfNew->bCharSet ||
		(pcf->dwMask & CFM_CHARSET) != (pcfNew->dwMask & CFM_CHARSET))
	{
		pcf->dwMask &= ~CFM_CHARSET;
		pcf->dwMask |= pcfNew->dwMask & CFM_CHARSET;
		pcf->bCharSet = pcfNew->bCharSet;
		PaintSize(pfbs);
	}

	// Change in font size ?
	if (pcf->yHeight != pcfNew->yHeight ||
		(pcf->dwMask & CFM_SIZE) != (pcfNew->dwMask & CFM_SIZE))
	{
		pcf->dwMask &= ~CFM_SIZE;
		pcf->dwMask |= pcfNew->dwMask & CFM_SIZE;
		pcf->yHeight = pcfNew->yHeight;
		PaintSize(pfbs);
	}

	// Change in font color ?
	if (pcf->crTextColor != pcfNew->crTextColor ||
		(pcf->dwMask & CFM_COLOR) != (pcfNew->dwMask & CFM_COLOR))
	{		
		pcf->dwMask &= ~CFM_COLOR;
		pcf->dwMask |= pcfNew->dwMask & CFM_COLOR;
		pcf->crTextColor = pcfNew->crTextColor;
		PaintColor(pfbs);
	}

	// Change in effects ?
	dwMask = pcf->dwMask & CFM_MASKS;
	dwEffects = pcf->dwEffects & CFE_EFFECTS;
	if (((pcfNew->dwMask & CFM_MASKS) != dwMask) ||
		((pcfNew->dwEffects & CFE_EFFECTS) != dwEffects))
	{
		pcf->dwMask &= ~CFM_MASKS;
		pcf->dwMask |= pcfNew->dwMask & CFM_MASKS;
		pcf->dwEffects = pcfNew->dwEffects & CFE_EFFECTS;
		PaintEffects(pfbs);
	}
}


/*
 *	SetParaFormat
 *
 *	Purpose:
 *		Set the current char format
 *
 *	Arguments:
 *		hwnd		The format bar window
 *		ppfNew		The new formatting
 *
 *	Returns:
 *		None.
 */
LOCAL VOID SetParaFormat(HWND hwnd, PARAFORMAT *ppfNew)
{
	FormatBarState *	pfbs = PfbsGetWindowPtr(hwnd);
	PARAFORMAT *		ppf = &pfbs->pf;
	DWORD				dwMaskOld = ppf->dwMask;
	BOOL				fChanged = FALSE;

	// update the mask for tri-state sake
	ppf->dwMask = (ppf->dwMask & ~(PFM_NUMBERING | PFM_ALIGNMENT)) |
		(ppfNew->dwMask & (PFM_NUMBERING | PFM_ALIGNMENT));

	// Change in numbering ?
	if (ppf->wNumbering != ppfNew->wNumbering)
	{
		const BOOL fBulleted = ppfNew->wNumbering == PFN_BULLET;

		ppf->wNumbering = ppfNew->wNumbering;
		SendMessage(pfbs->hwndToolbar, TB_CHECKBUTTON, TBI_Bullet, MAKELONG(fBulleted, 0));
	}

	// Change in alignment ?
	if (ppf->wAlignment != ppfNew->wAlignment)
	{
		ppf->wAlignment = ppfNew->wAlignment;
		fChanged |= TRUE;
	}

	if (fChanged || dwMaskOld != ppf->dwMask)
		PaintAlignment(pfbs);
}


/*
 *	LFormatBarWndProc
 *
 *	Purpose:
 *		Take care of handling the notifications from the combobox controls we
 *		get from the format bar
 *
 *	Arguments:
 *		hwnd
 *		wMsg
 *		wParam
 *		lParam
 *
 *	Returns:
 *		LRESULT
 */
LRESULT CALLBACK LFormatBarWndProc(HWND hwnd, UINT wMsg, WPARAM wParam,
									LPARAM lParam)
{
	FormatBarState *pfbs = PfbsGetWindowPtr(hwnd);
	BOOL fShift;

	switch(wMsg)
	{
	HANDLE_MSG(hwnd, WM_MEASUREITEM, FB_OnMeasureItem);

	case WM_COMMAND:
		FB_OnCommand(hwnd, GET_WM_COMMAND_ID(wParam, lParam),
					 GET_WM_COMMAND_HWND(wParam, lParam),
					 GET_WM_COMMAND_CMD(wParam, lParam));
		return 0;

	case WM_NCCREATE:
		return FB_OnNcCreate(hwnd, (CREATESTRUCT *) lParam);


	case WM_DRAWITEM:
		FB_OnDrawItem(hwnd, (DRAWITEMSTRUCT *) lParam);
		return TRUE;

	case WM_PAINT:
		FB_OnPaint(hwnd);
		break;

	case WM_DESTROY:
		if (pfbs)
		{
			if (pfbs->hwndName)
				DestroyWindow(pfbs->hwndName);
			if (pfbs->hwndSize)
				DestroyWindow(pfbs->hwndSize);
			if (pfbs->hwndColor)
				DestroyWindow(pfbs->hwndColor);
			if (pfbs->hwndToolbar)
				DestroyWindow(pfbs->hwndToolbar);
			if (pfbs->hbrushWindow)
				DeleteObject(pfbs->hbrushWindow);
			if (pfbs->hbrushHighlight)
				DeleteObject(pfbs->hbrushHighlight);
			if (pfbs->hbrushButtonFace)
				DeleteObject(pfbs->hbrushButtonFace);
			if (pfbs->hdc)
				DeleteDC(pfbs->hdc);
			GlobalFreePtr(pfbs);
			SetWindowPtr(hwnd, NULL);
		}
		break;

	case WM_SHOWWINDOW:
		if (pfbs)
		{
			INT	nCmd =	wParam ? SW_SHOW : SW_HIDE;

			ShowWindow(pfbs->hwndToolbar, nCmd);
			SendMessage(pfbs->hwndToolbar, WM_SIZE, 0, 0);
			ShowWindow(pfbs->hwndName, nCmd);
			ShowWindow(pfbs->hwndSize, nCmd);
			ShowWindow(pfbs->hwndColor, nCmd);
		}
		return 0;

	case WM_SIZE:
		if (pfbs)
		{
			RECT	rcMe;
			RECT	rcParent;

			// Get our current dimensions
			GetClientRect(pfbs->hwndToolbar, &rcMe);
			rcMe.bottom += 3;

			// We want to fit our parent's width
			GetClientRect(GetParent(hwnd), &rcParent);

			// Make it so
			SetWindowPos(hwnd, HWND_TOP, 0, 0, rcParent.right - rcParent.left,
						rcMe.bottom - rcMe.top, SWP_NOMOVE | SWP_NOZORDER);
		}
		return 0;

	case WM_ENABLE:
		if (pfbs)
		{
			INT	nID;

			EnableWindow(pfbs->hwndToolbar, wParam);
			EnableWindow(pfbs->hwndName, wParam);
			EnableWindow(pfbs->hwndSize, wParam);
			EnableWindow(pfbs->hwndColor, wParam);
			for (nID = TBI_Bold; nID <= TBI_Right; nID++)
				SendMessage(pfbs->hwndToolbar, TB_ENABLEBUTTON, nID,
							MAKELONG(wParam, 0));
		}
		break;

	case WM_SYSCOLORCHANGE:
		// Update our concept of the brushes
		if (pfbs)
			UpdateBrushes(hwnd);
		break;

	case EM_GETPARAFORMAT:
		Assert(lParam);
		if (lParam)
		{
			PARAFORMAT * const ppf = (PARAFORMAT *) lParam;

			if(ppf->cbSize == sizeof(PARAFORMAT))
			{
				CopyMemory(((LPBYTE) ppf) + sizeof(ppf->cbSize),
					((LPBYTE) &pfbs->pf) + sizeof(ppf->cbSize),
					sizeof(PARAFORMAT) - sizeof(ppf->cbSize));
			}
		}
		return 0;

	case EM_SETPARAFORMAT:
		Assert(lParam);
		if (lParam)
			SetParaFormat(hwnd, (PARAFORMAT *) lParam);
		return TRUE;

	case EM_GETCHARFORMAT:
		Assert(lParam);
		if (lParam)
		{
			CHARFORMAT * const pcf = (CHARFORMAT *) lParam;

			if(pcf->cbSize == sizeof(CHARFORMAT))
			{
				CopyMemory(((LPBYTE) pcf) + sizeof(pcf->cbSize),
					((LPBYTE) &pfbs->cf) + sizeof(pcf->cbSize),
					sizeof(CHARFORMAT) - sizeof(pcf->cbSize));
				pcf->dwMask &= pfbs->dwCFMaskChange;
				TraceCharFormat("EM_GETCHARFORMAT", pcf);
			}
		}
		return 0;

	case EM_SETCHARFORMAT:
		Assert(lParam);
		if (lParam)
			SetCharFormat(hwnd, (CHARFORMAT *) lParam);
		return TRUE;

	case WM_RETURN:
		// The user made a choice
		pfbs->fExpectChoice = TRUE;
		pfbs->fGiveUpFocus = TRUE;
		FB_OnCommand(hwnd, wParam, (HWND) lParam, CBN_SELCHANGE);
		return 0;

	case WM_TAB:
		// Only change the choice if TAB was pressed on a closed dropdown
		pfbs->fExpectChoice = !SendMessage((HWND) lParam, CB_GETDROPPEDSTATE,
											0, 0);
		FB_OnCommand(hwnd, wParam, (HWND) lParam, CBN_SELCHANGE);

		// Change focus, FB_OnCommand will take care of copying changed data
		fShift = GetKeyState(VK_SHIFT) & 0x8000 ? TRUE : FALSE;
		switch (wParam)
		{
		case TBI_Name:
			SetFocus(fShift ? pfbs->hwndColor : pfbs->hwndSize);
			break;

		case TBI_Size:
			SetFocus(fShift ? pfbs->hwndName : pfbs->hwndColor);
			break;

		case TBI_Color:
			SetFocus(fShift ? pfbs->hwndSize : pfbs->hwndName);
			break;
		}
		return 0;

	case WM_ESCAPE:
		SetFocus(hwnd);
		FB_OnPaint(hwnd);
		return 0;
	}

	return DefWindowProc(hwnd, wMsg, wParam, lParam);
}


/*
 *	FInitFormatBarClass()
 *
 *	Purpose:
 *		Superclasses the toolbar so that we get support for a format bar
 *
 *	Arguments:
 *		hinst		This instance
 *
 *	Returns:
 *		TRUE if class is successfully initialized.
 */
BOOL FInitFormatBarClass(HINSTANCE hinst)
{
	WNDCLASS wc;

	// Are format bars registered yet ?
	if (!GetClassInfo(hinst, szFormatBar, &wc))
	{
		wc.style = CS_HREDRAW | CS_VREDRAW;
		wc.lpfnWndProc = LFormatBarWndProc;
		wc.cbClsExtra = 0;
		wc.cbWndExtra = sizeof(FormatBarState *);
		wc.hInstance = hinst;
		wc.hIcon = NULL;
		wc.hCursor = LoadCursor(NULL, IDC_ARROW);
		wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
		wc.lpszMenuName = NULL;
		wc.lpszClassName = szFormatBar;
	
		if (!RegisterClass(&wc))
		{
			TraceError("FInitFormatBarClass: Couldn't register", -1);
			return FALSE;
		}
	}
	return TRUE;
}


/*
 *	FCreateFormatBar
 *
 *	Purpose:
 *		Creates a format bar
 *
 *	Arguments:
 *		hwndParent		The parent of this format bar
 *		wID				The control ID to be associated with this format bar
 *		hdc				A device context that we can copy so we can do various
 *						font information functions
 *
 *	Returns:
 *		The window handle of the format bar
 */
HWND HwndCreateFormatBar(HWND hwndParent, WORD wID, HDC hdc)
{
	HWND		hwndFormatBar = NULL;
	HINSTANCE	hinst = (HINSTANCE) GetWindowLong(hwndParent, GWL_HINSTANCE);
	RECT		rc;

	// Initialize the format bar class
	//$ REVIEW: Move into WinMain or LibMain
	if (!FInitFormatBarClass(hinst))
	{
		TraceError("HwndCreateFormatBar: Not registered", -1);
		return NULL;
	}

	// Create the main toolbar
	GetClientRect(hwndParent, &rc);
	hwndFormatBar = CreateWindow(szFormatBar, NULL, WS_CHILD | WS_VISIBLE,
									0, 0, rc.right - rc.left, 29,
									hwndParent, (HMENU) wID, hinst,
									(LPVOID) (hdc ? &hdc : NULL));
	if (!hwndFormatBar)
	{
		TraceError("HwndCreateFormatBar: Can't create", -1);
		goto Error;
	}

	// Return a pointer to our state information
	return hwndFormatBar;
	
Error:
	return NULL;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -