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

📄 font-selector-box.zc

📁 实现树形结构
💻 ZC
字号:
//[c]The font selector dialog box.
//[c]
//[of]:license
//[c]    Code Browser - a folding text editor for programmers
//[c]    Copyright (C) 2003-07 Marc Kerbiquet
//[c]
//[c]    This program is free software; you can redistribute it and/or modify
//[c]    it under the terms of the GNU General Public License as published by
//[c]    the Free Software Foundation; either version 2 of the License, or
//[c]    (at your option) any later version.
//[c]
//[c]    This program is distributed in the hope that it will be useful,
//[c]    but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c]    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//[c]    GNU General Public License for more details.
//[c]
//[c]    You should have received a copy of the GNU General Public License
//[c]    along with this program; if not, write to the Free Software
//[c]    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//[cf]
//[of]:example of use
//[c]
/*
	// initialize a font selector object
	def fs: local font selector
	initialize (fs, m, "Arial", 16, 0)

	// open the dialog box
	def ok = open (fs)
	
	// do something if the user has clicked on the ok button
	if ok
		//...
	end
	
	// release all resources of the font selector object
	release (fs)
*/
//[cf]
//[of]:imports
//[c]
import "base/types"
import "base/memory-allocator"
import "text/string"
import "graphics/font"
import "user/box"
import "user/win-box"

import "private/sys-box"
import "private/windows"
import "private/commdlg"
//[cf]
//[of]:structures
//[c]
public struct font selector

	private p : CHOOSEFONTA
	private lf : LOGFONTA

	private parent : win box

	private fface : string
	private fsize : int
	private fstyle : int

end
//[cf]
//[c]
//[of]:initialize - release
//[of]:initialize (m, parent, face, size, int)
//[c]
public func initialize (
		s: font selector, 
		parent: win box,
		face: string, 
		size: int, 
		style: int)

	parent (s) = parent
	fface (s) = new string (face)
	fsize (s) = size
	fstyle (s) = style

end
//[cf]
//[of]:release (m)
//[c]
public func release (s: font selector)

	delete (fface (s))

end
//[cf]
//[cf]
//[of]:operations
//[of]:open (m)
//[c]Opens the font selector. Returns true if the choice is validated by the user.
//[c]
public func open (s: font selector)

	// Fill the logfont structure
	def hdc = GetDC (nil)
	def log pixel y = GetDeviceCaps (hdc, LOGPIXELSY)
	ReleaseDC (nil, hdc)

	equ b2b (x: int) = (x <> 0) -> 1:b, 0:b
	def st = font style (s)
	def lf = lf (s)
	lfHeight (lf) = - (font size (s) * log pixel y + 36) / 72
	lfWidth (lf) = 0
	lfEscapement (lf) = 0
	lfOrientation (lf) = 0
	lfWeight (lf) = ((st & fontstyle bold) <> 0 -> FW_BOLD, FW_NORMAL)
	lfItalic (lf) = b2b (st & fontstyle italic)
	lfUnderline (lf) = b2b (st & fontstyle underline)
	lfStrikeOut (lf) = FALSE : BYTE
	lfCharSet (lf) = ANSI_CHARSET : BYTE
	lfOutPrecision (lf) = OUT_DEFAULT_PRECIS : BYTE
	lfClipPrecision (lf) = CLIP_DEFAULT_PRECIS : BYTE
	lfQuality (lf) = DEFAULT_QUALITY : BYTE
	lfPitchAndFamily (lf) = (DEFAULT_PITCH | FF_DONTCARE) : BYTE
	copy (lfFaceName (lf), font face (s), LF_FACESIZE)

	// Fill the choosefont structure
	def p = p (s)
	p.lStructSize = sizeof CHOOSEFONTA
	p.hwndOwner = hwnd (parent (s))
	p.hDC = nil
	p.lpLogFont = lf (s)
	p.iPointSize = 10
	p.Flags = CF_FORCEFONTEXIST | CF_NOSCRIPTSEL | CF_NOVERTFONTS | CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT
	p.rgbColors = 0
	p.lCustData = 0
	p.lpfnHook = nil
	p.lpTemplateName = nil
	p.hInstance = nil
	p.lpszStyle = nil
	p.nFontType = 0:w
	p.nSizeMin = 0
	p.nSizeMax = 0

	// Open the dialog box
	def ok = ChooseFontA (p) <> 0

	// Decode result
	if ok
		delete (font face (s))
		font face (s) = new string (lfFaceName (lf))
		font size (s) = (72 * - lfHeight (lf) + log pixel y / 2) /  log pixel y
		st = 0
		if lfItalic (lf) <> 0:b
			st |= fontstyle italic
		end
		if lfWeight (lf) > FW_NORMAL
			st |= fontstyle bold
		end
		if lfUnderline (lf) <> 0:b
			st |= fontstyle underline
		end
		font style (s) = st
	end

	return ok
end
//[cf]
//[cf]
//[of]:accessing
//[of]:font face (m)
//[c]
public equ font face (s: font selector) = fface (s)
//[cf]
//[of]:font size (m)
//[c]
public equ font size (s: font selector) = fsize (s)
//[cf]
//[of]:font style (m)
//[c]
public equ font style (s: font selector) = fstyle (s)
//[cf]
//[cf]

⌨️ 快捷键说明

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