wxFontEnumerator class for Motif/X
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3781 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
e1811a014b
commit
ddc8c2e3ab
@ -358,6 +358,7 @@ dcscreen.cpp X
|
||||
dialog.cpp X
|
||||
filedlg.cpp X
|
||||
font.cpp X
|
||||
fontenum.cpp X
|
||||
frame.cpp X
|
||||
gauge.cpp X
|
||||
gdiobj.cpp X
|
||||
|
51
include/wx/fontenum.h
Normal file
51
include/wx/fontenum.h
Normal file
@ -0,0 +1,51 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: fontenum.h
|
||||
// Purpose: wxFontEnumerator class for getting available fonts
|
||||
// Author: Julian Smart, Vadim Zeitlin
|
||||
// Modified by: extended to enumerate more than just font families and work ot
|
||||
// only on Windows (VZ)
|
||||
// Created: 04/01/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart, Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_FONTENUM_H_
|
||||
#define _WX_FONTENUM_H_
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma interface "fontenum.h"
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontEnumerator enumerates all available fonts on the system or only the
|
||||
// fonts with given attributes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class wxFontEnumerator
|
||||
{
|
||||
public:
|
||||
// start enumerating font families - will result in OnFontFamily() being
|
||||
// called for each available font family (unless it returns FALSE)
|
||||
virtual bool EnumerateFamilies(bool fixedWidthOnly = FALSE);
|
||||
|
||||
// enumerate the different encodings either for given font family or for
|
||||
// all font families - will result in OnFontEncoding() being called for
|
||||
// each available (family, encoding) couple
|
||||
virtual bool EnumerateEncodings(const wxString& family = _T(""));
|
||||
|
||||
// callbacks which are called after one of EnumerateXXX() functions from
|
||||
// above is invoked - all of them may return FALSE to stop enumeration or
|
||||
// TRUE to continue with it
|
||||
|
||||
// called by EnumerateFamilies
|
||||
virtual bool OnFontFamily(const wxString& WXUNUSED(family))
|
||||
{ return FALSE; }
|
||||
|
||||
// called by EnumerateEncodings
|
||||
virtual bool OnFontEncoding(const wxString& WXUNUSED(family),
|
||||
const wxString& WXUNUSED(encoding))
|
||||
{ return FALSE; }
|
||||
};
|
||||
|
||||
#endif // _WX_FONTENUM_H_
|
@ -395,6 +395,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
|
||||
|
||||
panel = new wxPanel(m_notebook);
|
||||
m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices );
|
||||
m_choice->SetSelection(2);
|
||||
m_choice->SetBackgroundColour( "red" );
|
||||
(void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) );
|
||||
(void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) );
|
||||
|
@ -25,6 +25,7 @@
|
||||
#endif
|
||||
|
||||
#include <wx/fontdlg.h>
|
||||
#include <wx/fontenum.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// private classes
|
||||
@ -81,8 +82,14 @@ public:
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
void OnSelectFont(wxCommandEvent& event);
|
||||
void OnCreateFont(wxCommandEvent& event);
|
||||
void OnEnumerateFamilies(wxCommandEvent& WXUNUSED(event))
|
||||
{ DoEnumerateFamilies(FALSE); }
|
||||
void OnEnumerateFixedFamilies(wxCommandEvent& WXUNUSED(event))
|
||||
{ DoEnumerateFamilies(TRUE); }
|
||||
|
||||
protected:
|
||||
void DoEnumerateFamilies(bool fixedWidthOnly);
|
||||
|
||||
MyCanvas *m_canvas;
|
||||
|
||||
private:
|
||||
@ -119,7 +126,10 @@ enum
|
||||
Font_Quit = 1,
|
||||
Font_About,
|
||||
Font_Choose = 100,
|
||||
Font_Create
|
||||
Font_Create,
|
||||
Font_EnumFamilies,
|
||||
Font_EnumFixedFamilies,
|
||||
Font_Max
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -134,6 +144,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(Font_About, MyFrame::OnAbout)
|
||||
EVT_MENU(Font_Choose, MyFrame::OnSelectFont)
|
||||
EVT_MENU(Font_Create, MyFrame::OnCreateFont)
|
||||
EVT_MENU(Font_EnumFamilies, MyFrame::OnEnumerateFamilies)
|
||||
EVT_MENU(Font_EnumFixedFamilies, MyFrame::OnEnumerateFixedFamilies)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// Create a new application object: this macro will allow wxWindows to create
|
||||
@ -155,7 +167,7 @@ IMPLEMENT_APP(MyApp)
|
||||
bool MyApp::OnInit()
|
||||
{
|
||||
// Create the main application window
|
||||
MyFrame *frame = new MyFrame("Minimal wxWindows App",
|
||||
MyFrame *frame = new MyFrame("Font wxWindows demo",
|
||||
wxPoint(50, 50), wxSize(450, 340));
|
||||
|
||||
// Show it and tell the application that it's our main window
|
||||
@ -176,9 +188,6 @@ bool MyApp::OnInit()
|
||||
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
: wxFrame((wxFrame *)NULL, -1, title, pos, size)
|
||||
{
|
||||
// set the frame icon
|
||||
SetIcon(wxICON(mondrian));
|
||||
|
||||
// create a menu bar
|
||||
wxMenu *menuFile = new wxMenu;
|
||||
|
||||
@ -187,10 +196,14 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
menuFile->Append(Font_Quit, "E&xit\tAlt-X", "Quit this program");
|
||||
|
||||
wxMenu *menuFont = new wxMenu;
|
||||
menuFont->Append(Font_Choose, "&Select font...\tCtrl-F",
|
||||
menuFont->Append(Font_Choose, "&Select font...\tCtrl-S",
|
||||
"Select a standard font");
|
||||
menuFont->Append(Font_Create, "&Create font...\tCtrl-C",
|
||||
"Create a custom font");
|
||||
menuFont->AppendSeparator();
|
||||
menuFont->Append(Font_EnumFamilies, "&Enumerate font families\tCtrl-E");
|
||||
menuFont->Append(Font_EnumFixedFamilies,
|
||||
"&Enumerate fixed font families\tCtrl-F");
|
||||
|
||||
// now append the freshly created menu to the menu bar...
|
||||
wxMenuBar *menuBar = new wxMenuBar;
|
||||
@ -210,6 +223,30 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
|
||||
// event handlers
|
||||
|
||||
void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly)
|
||||
{
|
||||
class MyFontEnumerator : public wxFontEnumerator
|
||||
{
|
||||
public:
|
||||
MyFontEnumerator() { m_n = 0; }
|
||||
|
||||
protected:
|
||||
virtual bool OnFontFamily(const wxString& family)
|
||||
{
|
||||
wxLogMessage("Font family %d: %s\n", ++m_n, family.c_str());
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_n;
|
||||
} fontEnumerator;
|
||||
|
||||
wxLogMessage("Enumerating %s font families:",
|
||||
fixedWidthOnly ? "fixed width" : "all");
|
||||
fontEnumerator.EnumerateFamilies(fixedWidthOnly);
|
||||
}
|
||||
|
||||
void MyFrame::OnCreateFont(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
MyFontDialog dialog(this);
|
||||
|
@ -13,7 +13,7 @@ top_srcdir = @top_srcdir@
|
||||
top_builddir = ../..
|
||||
program_dir = samples/text
|
||||
|
||||
DATAFILES = text.cpp
|
||||
DATAFILES = text.rc
|
||||
|
||||
PROGRAM=text
|
||||
|
||||
|
@ -32,10 +32,6 @@
|
||||
#include "wx/tooltip.h"
|
||||
#endif
|
||||
|
||||
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||
#include "mondrian.xpm"
|
||||
#endif
|
||||
|
||||
// We test for wxUSE_DRAG_AND_DROP also, because data objects may not be
|
||||
// implemented for compilers that can't cope with the OLE parts in
|
||||
// wxUSE_DRAG_AND_DROP.
|
||||
@ -171,8 +167,7 @@ bool MyApp::OnInit()
|
||||
{
|
||||
// Create the main frame window
|
||||
MyFrame *frame = new MyFrame((wxFrame *) NULL,
|
||||
"Text wxWindows App",
|
||||
50, 50, 640, 420);
|
||||
"Text wxWindows sample", 50, 50, 640, 420);
|
||||
frame->SetSizeHints( 500, 400 );
|
||||
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
@ -454,7 +449,8 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
|
||||
|
||||
m_horizontal = new MyTextCtrl( this, -1, "Multiline text control with a horizontal scrollbar.",
|
||||
wxPoint(10,170), wxSize(140,70), wxTE_MULTILINE | wxHSCROLL );
|
||||
m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxBOLD));
|
||||
m_horizontal->SetFont(wxFont(18, wxSWISS, wxNORMAL, wxNORMAL,
|
||||
FALSE, "", wxFONTENCODING_KOI8));
|
||||
|
||||
m_multitext = new MyTextCtrl( this, -1, "Multi line.",
|
||||
wxPoint(180,10), wxSize(240,70), wxTE_MULTILINE );
|
||||
@ -668,7 +664,7 @@ void MyFrame::OnToggleTooltips(wxCommandEvent& event)
|
||||
|
||||
void MyFrame::OnFileLoad(wxCommandEvent& event)
|
||||
{
|
||||
if ( m_panel->m_multitext->LoadFile("text.cpp") )
|
||||
if ( m_panel->m_multitext->LoadFile("text.rc") )
|
||||
wxLogStatus(this, _T("Successfully loaded file"));
|
||||
else
|
||||
wxLogStatus(this, _T("Couldn't load the file"));
|
||||
|
206
src/motif/fontenum.cpp
Normal file
206
src/motif/fontenum.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: src/motif/fontenum.cpp
|
||||
// Purpose: wxFontEnumerator class for X11/GDK
|
||||
// Author: Vadim Zeitlin
|
||||
// Modified by:
|
||||
// Created: 01.10.99
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Vadim Zeitlin
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ============================================================================
|
||||
// declarations
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "fontenum.h"
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/dynarray.h"
|
||||
#include "wx/string.h"
|
||||
#include "wx/utils.h"
|
||||
|
||||
#include "wx/fontenum.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// private functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// compare function for sorted array of strings
|
||||
static int CMPFUNC_CONV CompareStrings(const char *s1, const char *s2);
|
||||
|
||||
// create the list of all fonts with the given spacing
|
||||
static char **CreateFontList(wxChar spacing, int *nFonts);
|
||||
|
||||
// extract all font families from the given font list and call our
|
||||
// OnFontFamily() for each of them
|
||||
static bool ProcessFamiliesFromFontList(wxFontEnumerator *This,
|
||||
char **fonts,
|
||||
int nFonts);
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// private types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WX_DEFINE_SORTED_ARRAY(const char *, wxSortedStringArray);
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helpers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static int CMPFUNC_CONV CompareStrings(const char *s1, const char *s2)
|
||||
{
|
||||
return strcmp(s1, s2);
|
||||
}
|
||||
|
||||
static char **CreateFontList(wxChar spacing, int *nFonts)
|
||||
{
|
||||
wxString pattern;
|
||||
pattern.Printf(_T("-*-*-*-*-*-*-*-*-*-*-%c-*-*-*"), spacing);
|
||||
|
||||
// get the list of all fonts
|
||||
return XListFonts((Display *)wxGetDisplay(), pattern, 32767, nFonts);
|
||||
}
|
||||
|
||||
static bool ProcessFamiliesFromFontList(wxFontEnumerator *This,
|
||||
char **fonts,
|
||||
int nFonts)
|
||||
{
|
||||
// extract the list of (unique) font families
|
||||
wxSortedStringArray families(CompareStrings);
|
||||
for ( int n = 0; n < nFonts; n++ )
|
||||
{
|
||||
char *font = fonts[n];
|
||||
if ( !wxString(font).Matches("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
|
||||
{
|
||||
// it's not a full font name (probably an alias)
|
||||
continue;
|
||||
}
|
||||
|
||||
char *dash = strchr(font + 1, '-');
|
||||
char *family = dash + 1;
|
||||
dash = strchr(family, '-');
|
||||
*dash = '\0'; // !NULL because Matches() above succeeded
|
||||
|
||||
if ( families.Index(family) == wxNOT_FOUND )
|
||||
{
|
||||
if ( !This->OnFontFamily(family) )
|
||||
{
|
||||
// stop enumerating
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
families.Add(family);
|
||||
}
|
||||
//else: already seen
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxFontEnumerator
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxFontEnumerator::EnumerateFamilies(bool fixedWidthOnly)
|
||||
{
|
||||
int nFonts;
|
||||
char **fonts;
|
||||
|
||||
if ( fixedWidthOnly )
|
||||
{
|
||||
bool cont = TRUE;
|
||||
fonts = CreateFontList(_T('m'), &nFonts);
|
||||
if ( fonts )
|
||||
{
|
||||
cont = ProcessFamiliesFromFontList(this, fonts, nFonts);
|
||||
|
||||
XFreeFontNames(fonts);
|
||||
}
|
||||
|
||||
if ( !cont )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
fonts = CreateFontList(_T('c'), &nFonts);
|
||||
if ( !fonts )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fonts = CreateFontList(_T('*'), &nFonts);
|
||||
|
||||
if ( !fonts )
|
||||
{
|
||||
wxFAIL_MSG(_T("No fonts at all on this system?"));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
(void)ProcessFamiliesFromFontList(this, fonts, nFonts);
|
||||
|
||||
XFreeFontNames(fonts);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxFontEnumerator::EnumerateEncodings(const wxString& family)
|
||||
{
|
||||
#if 0
|
||||
wxString pattern;
|
||||
pattern.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-*-*"),
|
||||
family.IsEmpty() ? _T("*") : family.c_str());
|
||||
|
||||
// get the list of all fonts
|
||||
int nFonts;
|
||||
char **fonts = XListFonts((Display *)wxGetDisplay(), pattern,
|
||||
32767, nFonts);
|
||||
|
||||
if ( !fonts )
|
||||
{
|
||||
// unknown family?
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// extract the list of (unique) encodings
|
||||
wxSortedStringArray families(CompareStrings);
|
||||
for ( int n = 0; n < nFonts; n++ )
|
||||
{
|
||||
char *font = fonts[n];
|
||||
if ( !wxString(font).Matches("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
|
||||
{
|
||||
// it's not a full font name (probably an alias)
|
||||
continue;
|
||||
}
|
||||
|
||||
// extract the family
|
||||
char *dash = strchr(font + 1, '-');
|
||||
char *family = dash + 1;
|
||||
dash = strchr(family, '-');
|
||||
*dash = '\0'; // !NULL because Matches() above succeeded
|
||||
|
||||
// now extract the registry/encoding
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
#endif // 0
|
||||
|
||||
return FALSE; // TODO
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
# This file was automatically generated by tmake at 15:48, 1999/10/01
|
||||
# This file was automatically generated by tmake at 20:00, 1999/10/01
|
||||
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE B32.T!
|
||||
|
||||
#
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
# This file was automatically generated by tmake at 15:48, 1999/10/01
|
||||
# This file was automatically generated by tmake at 20:00, 1999/10/01
|
||||
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE BCC.T!
|
||||
|
||||
#
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
# This file was automatically generated by tmake at 15:48, 1999/10/01
|
||||
# This file was automatically generated by tmake at 20:00, 1999/10/01
|
||||
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE DOS.T!
|
||||
|
||||
#
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
# This file was automatically generated by tmake at 15:48, 1999/10/01
|
||||
# This file was automatically generated by tmake at 20:00, 1999/10/01
|
||||
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE G95.T!
|
||||
|
||||
#
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
# This file was automatically generated by tmake at 15:48, 1999/10/01
|
||||
# This file was automatically generated by tmake at 20:00, 1999/10/01
|
||||
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE SC.T!
|
||||
|
||||
# Symantec C++ makefile for the msw objects
|
||||
|
@ -1,4 +1,4 @@
|
||||
# This file was automatically generated by tmake at 15:48, 1999/10/01
|
||||
# This file was automatically generated by tmake at 20:01, 1999/10/01
|
||||
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE VC.T!
|
||||
|
||||
# File: makefile.vc
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
|
||||
# This file was automatically generated by tmake at 15:48, 1999/10/01
|
||||
# This file was automatically generated by tmake at 20:01, 1999/10/01
|
||||
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE WAT.T!
|
||||
|
||||
#!/binb/wmake.exe
|
||||
|
Loading…
Reference in New Issue
Block a user