/** * @file XTPFontComboBox.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPFONTCOMBOBOX_H__) # define __XTPFONTCOMBOBOX_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** * @brief * List used for enumerating CXTPLogFont structures. * @details * CList definition used by the CXTPFontEnum class to maintain * a list of CXTPLogFont objects representing each font displayed * for a CXTPFontListBox control. * @see * CXTPFontEnum::GetFontList */ typedef CList CXTPFontList; /** * @brief * CXTPFontEnum is a standalone singleton font enumeration class. It is * used to enumerate a list of fonts found installed for the operating system. * @details * CXTPFontEnum is a singleton class, which means that it can only be * instantiated a single time. The constructor is private, so the only * way to access members of this class is to use the object's Get() method. * To retrieve a list of available fonts for your operating system, you * would make the following call: * Example: * The following example demonstrates the use of the CXTPFontEnum class: *
 * CXTPFontEnum::Get().GetFontList()
 * 
*/ class _XTP_EXT_CLASS CXTPFontEnum { friend class CXTPSingleton; protected: /** * @brief * Constructs a CXTPFontEnum object. CXTPFontEnum is a singleton * class. To instantiate an object, use the static method Get(). */ CXTPFontEnum(); public: /** * @brief * Destroys a CXTPFontEnum object, handles cleanup and deallocation. */ virtual ~CXTPFontEnum(); public: /** * @brief * This static member function will return a reference to the one * and only CXTPFontEnum object. You can use this function to access * data members for the CXTPFontEnum class. * Example: * The following example demonstrates the use of Get(): *
	 * CXTPFontEnum::Get().GetFontList()
	 * 
* @return * A reference to a CXTPFontEnum object. */ static CXTPFontEnum& AFX_CDECL Get(); /** * @brief * This member function is used to determine the existence of the font * specified by 'strFaceName'. * @param strFaceName Reference to a NULL-terminated string that represents * the font name. * @return * true if the font exists, otherwise false. */ bool DoesFontExist(CString& strFaceName); /** * @brief * This member function is used to get a pointer to the font specified * by 'strFaceName'. * @param strFaceName A NULL-terminated string that represents the font * name. * @return * A pointer to the CXTPLogFont structure for the specified item, * or NULL if no font was found. */ CXTPLogFont* GetLogFont(const CString& strFaceName); /** * @brief * This member function is used by the callback function to retrieve the * current width for the longest font name in the list. * @return * An integer value that represents the width for the * longest font name in the list. */ int GetMaxWidth(); /** * @brief * Retrieves the widest size of a string provided using available fonts. * @param lpString * @return * An integer value that represents the widest size of a string. */ int GetMaxWidth(LPCTSTR lpString); /** * @brief * This member function is used to get a reference to the font list. * @return * A reference to the CXTPFontList used by this class. */ CXTPFontList& GetFontList(); /** * @brief * This member function is called by the CXTPFontEnum class to initialize * the font list. You can also call this member function to reinitialize * the font enumeration. For example, if you changed printers and you * want to enumerate printer fonts, or you wanted to use a different * character set. * @param pDC Pointer to a valid device context. If NULL, then the * screen device context is used. * @param nCharSet Represents the character set to enumerate. */ void Init(CDC* pDC = NULL, BYTE nCharSet = DEFAULT_CHARSET); protected: /** * @brief * The EnumFontFamExProc function is an application defined-callback * function used with the EnumFontFamiliesEx function. It is used to process * the fonts and is called once for each enumerated font. The FONTENUMPROC * type defines a pointer to this callback function. EnumFontFamExProc * is a placeholder for the application defined-function name. * @param pelf Pointer to an ENUMLOGFONTEX structure that contains * information about the logical attributes of the font. * @param lpntm Pointer to a structure that contains information * about the physical attributes of a font. The function * uses the NEWTEXTMETRICEX structure for TrueType fonts * and the TEXTMETRIC structure for other fonts. * @param dwFontType Specifies the type of the font. This parameter can be a * combination of the values in the Remarks section. * @param lParam Specifies the application-defined data passed by the * EnumFontFamiliesEx function. * @details * Styles to be added or removed can be combined by using the bitwise * OR (|) operator. It can be one or more of the following:

* DEVICE_FONTTYPE: The font is a device font. * RASTER_FONTTYPE: The font is a raster font. * TRUETYPE_FONTTYPE: The font is a TrueType font. * @return * To continue enumeration, the return value must be a nonzero value. * To stop enumeration, the return value must be zero. */ static BOOL CALLBACK EnumFontFamExProc(ENUMLOGFONTEX* pelf, NEWTEXTMETRICEX* lpntm, DWORD dwFontType, LPARAM lParam); /** * @brief * This member function is called by the font enumeration callback to * add a font to the font list. * @param pLF Pointer to a valid LOGFONT structure. * @param dwType Specifies the type of the font. This parameter can be a combination * of the values in the Remarks section. * @details * Styles to be added or removed can be combined by using the bitwise * OR (|) operator. It can be one or more of the following:

* DEVICE_FONTTYPE: The font is a device font. * RASTER_FONTTYPE: The font is a raster font. * TRUETYPE_FONTTYPE: The font is a TrueType font. * @return * true if successful, otherwise false. */ bool AddFont(const LOGFONT* pLF, DWORD dwType); protected: CXTPFontList m_listFonts; /**< List of fonts found during enumeration. */ CDC* m_pDC; }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE CXTPFontList& CXTPFontEnum::GetFontList() { return m_listFonts; } /** @endcond */ /** * @brief * Enumeration used to determine font display. * @details * XTPFontStyle type defines the constants used by the CXTPFontListBox class to * determine how the fonts will be displayed in the CXTPFontListBox control. * @see * CXTPFontListBox, CXTPFontListBox::SetListStyle * @see * xtpFontGUI, xtpFontSample, xtpFontBoth> */ enum XTPFontStyle { xtpFontUnknown = 0x00, /**< Display type not defined. */ xtpFontGUI = 0x01, /**< Display font name with GUI font style. */ xtpFontSample = 0x02, /**< Display font name with its own font style. */ xtpFontBoth = 0x03, /**< Display font name with GUI font style, then a sample display to the right. */ }; class CXTPFontListBox; class CXTPFontComboBox; /** * @brief * CXTPFontCtrlBase is a base class used by CXTPFontListBox and * CXTPFontComboBox controls to perform common drawing routines. */ class _XTP_EXT_CLASS CXTPFontCtrlBase { public: /** * @brief * Standard constructor. */ CXTPFontCtrlBase(); /** * @brief * Handles object destruction. */ virtual ~CXTPFontCtrlBase(); /** * @brief * Call this member function to retrieve the default height for * combo or list items. * @return * The default height, in pixels, for combo or list items. */ static int AFX_CDECL GetFontItemHeight(); /** * @brief * Call this member function to create a default font for a * combo or list box. * @param font Reference to a CFont object. * @return * TRUE if successful, otherwise FALSE. */ static BOOL AFX_CDECL CreateUIFont(CFont& font); /** * @brief * Call this member function to get the font for the currently * selected item. * @param lf Reference to a CXTPLogFont structure. * @details * The first version of GetSelFont will retrieve the selected font * name. The second version will get the CXTPLogFont for the * currently selected item. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL GetSelFont(CXTPLogFont& lf); /** * @brief * Call this member function to get the font for the currently * selected item. * @param strFaceName A reference to a valid CString object to receive * the logfont face name. * @details * The first version of GetSelFont will retrieve the selected font * name. The second version will get the CXTPLogFont for the * currently selected item. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL GetSelFont(CString& strFaceName); /** * @brief * Call this member function to select the font for the list box. * @param lf Reference to a CXTPLogFont structure. * @details * The first version of SetSelFont will set the selected font by * using its face name. The second version will set the * selected font by using a CXTPLogFont object. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL SetSelFont(CXTPLogFont& lf); /** * @brief * Call this member function to select the font for the list box. * @param strFaceName A reference to a valid CString object to receive * the logfont face name. * @details * The first version of SetSelFont will set the selected font by * using its face name. The second version will set the * selected font by using a CXTPLogFont object. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL SetSelFont(const CString& strFaceName); protected: /** * @brief * This method is called by the framework when a visual aspect * of an owner-drawn combo or list box changes. * @param lpDIS A pointer to a DRAWITEMSTRUCT structure that contains * information about the type of drawing required. */ virtual void OnDrawItem(LPDRAWITEMSTRUCT lpDIS); /** * @brief * This method is called by the framework when a combo or list * box with an owner-drawn style is created. * @param lpMIS A long pointer to a MEASUREITEMSTRUCT structure. */ virtual void OnMeasureItem(LPMEASUREITEMSTRUCT lpMIS); /** * @brief * Called by the framework to determine the relative position * of a new item in the list-box portion of a sorted owner-draw * combobox. By default, this member function does nothing. * @param lpCIS A long pointer to a COMPAREITEMSTRUCT structure. * @return * Indicates the relative position of the two items described * in the COMPAREITEMSTRUCT structure. It can be any of the * following values: * * Value Meaning: * -1: Item 1 sorts before item 2. * 0: Item 1 and item 2 sort the same. * 1: Item 1 sorts after item 2. */ virtual int OnCompareItem(LPCOMPAREITEMSTRUCT lpCIS); /** * @brief * Call this member function to set the listbox pointer * for the base class. * @param pListBox Pointer to a valid CXTPFontListBox object. */ virtual void OnInit(CXTPFontListBox* pListBox); /** * @brief * Call this member function to set the combobox pointer * for the base class. * @param pComboBox Pointer to a valid CXTPFontComboBox object. */ virtual void OnInit(CXTPFontComboBox* pComboBox); protected: DWORD m_dwStyle; /**< Display style indicating how to render the font list. */ CString m_csSymbol; /**< String displayed for the symbol characters. */ CXTPFontListBox* m_pListBox; /**< Pointer to the owner list box. */ CXTPFontComboBox* m_pComboBox; /**< Pointer to the owner combobox. */ enum { FontTypeWidth = 16 }; }; /** * @brief * CXTPFontListBox is a CXTPListBox derived class. It is used to create * a font selection list box. * @details * You can choose to display the font name with the GUI font style, display * the font name with its own font style, or display the font name with * the default GUI font style and a sample display to the right. */ class _XTP_EXT_CLASS CXTPFontListBox : public CXTPListBox , public CXTPFontCtrlBase { public: /** * @brief * Constructs a CXTPFontListBox object. */ CXTPFontListBox(); /** * @brief * Destroys a CXTPFontListBox object, handles cleanup and deallocation. */ virtual ~CXTPFontListBox(); /** * @brief * Call this member function to set the font display style for the font * list box. There are three styles to choose from that include displaying * the font in the default GUI font, displaying the font in its own font * style, or displaying both the font name in the default GUI font and * a sample to the right. * @param dwStyle Specifies the style for the font list box. See XTPFontStyle for * a list of available styles. * @see * XTPFontStyle */ void SetListStyle(DWORD dwStyle); /** * @brief * Call this member function to initialize the font list box and populate it * with a list of available fonts. This method should be called directly * after creating or sub-classing the control. * @param bAutoFont true to enable automatic font initialization. */ virtual void Initialize(bool bAutoFont = true); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPFontListBox) virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct); virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPFontListBox) //}}AFX_MSG /** @endcond */ }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE void CXTPFontListBox::SetListStyle(DWORD dwStyle) { m_dwStyle = dwStyle; } /** @endcond */ /** * @brief * CXTPFontComboBox is a CXTPComboBox derived class. It is used to create * a combobox that displays a drop list of available fonts for your system. * The fonts are displayed in their various styles. */ class _XTP_EXT_CLASS CXTPFontComboBox : public CXTPComboBox , public CXTPFontCtrlBase { /** @cond */ DECLARE_DYNAMIC(CXTPFontComboBox) /** @endcond */ public: /** * @brief * Constructs a CXTPFontComboBox object. */ CXTPFontComboBox(); /** * @brief * Destroys a CXTPFontComboBox object, handles cleanup and deallocation. */ virtual ~CXTPFontComboBox(); public: /** * @brief * Sets the font style for the CXTPFontComboBox control. * @param dwStyle Specifies the style for the font list box. Styles can be any * one of the values in the Remarks section. * @details * Call this member function to set the font display style for the * font list box. There are three styles to choose from that include * displaying the font in the default GUI font, displaying the font * in its own font style, or displaying both the font name in the * default GUI font and a sample to the right. * * The style can be any of the following values: * * xtpFontGUI: Display font name with GUI font style. * xtpFontSample: Display font name with its own font style. * xtpFontBoth: Display font name with GUI font style, * then a sample display to the right. */ void SetListStyle(DWORD dwStyle); /** * @brief * Initializes the CXTPFontComboBox control. * @param lpszFaceName A NULL-terminated string that represents the logfont * face name. * @param nWidth The minimum allowable width of the list box portion of * the combobox in pixels. * @param bEnable TRUE to enable auto-completion, otherwise FALSE. * @details * Call this member function to initialize the font list box and * populate it with a list of available fonts. */ virtual void InitControl(LPCTSTR lpszFaceName = NULL, UINT nWidth = 0, BOOL bEnable = TRUE); protected: /** * @brief * Called by the font combobox to send CBN notifications to the owner * window to support keyboard navigation. * @param nCode CBN notification message to send. */ virtual void NotifyOwner(UINT nCode); /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPFontComboBox) virtual void DrawItem(LPDRAWITEMSTRUCT); virtual void MeasureItem(LPMEASUREITEMSTRUCT); virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct); virtual BOOL PreTranslateMessage(MSG* pMsg); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPFontComboBox) afx_msg BOOL OnDropDown(); afx_msg BOOL OnCloseUp(); //}}AFX_MSG /** @endcond */ /** @cond */ public: # ifdef _DEBUG virtual void AssertValid() const; # endif /** @endcond */ private: CString m_csSelected; /**< Selected text set when CBN_DROPDOWN is called. */ BOOL m_bIsOpen; }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE void CXTPFontComboBox::SetListStyle(DWORD dwStyle) { m_dwStyle = dwStyle; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTPFONTCOMBOBOX_H__) /** @endcond */