1. wxFontMapper almost finished

2. font helper functions are now in separate files, not utilsunx.cpp


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4376 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1999-11-05 19:03:19 +00:00
parent feef75abca
commit 7beba2fc73
32 changed files with 1331 additions and 679 deletions

View File

@@ -813,12 +813,16 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
wxCoord wxWindowDC::GetCharWidth() const
{
GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, _T("invalid font") );
return wxCoord(gdk_string_width( font, "H" ) / m_scaleX);
}
wxCoord wxWindowDC::GetCharHeight() const
{
GdkFont *font = m_font.GetInternalFont( m_scaleY );
wxCHECK_MSG( font, -1, _T("invalid font") );
return wxCoord((font->ascent + font->descent) / m_scaleY);
}

View File

@@ -168,16 +168,16 @@ gtk_dialog_realized_callback( GtkWidget *widget, wxDialog *win )
gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1);
/* set size hints */
gint flag = 0; // GDK_HINT_POS;
gint flag = 0; // GDK_HINT_POS;
if ((win->GetMinWidth() != -1) || (win->GetMinHeight() != -1)) flag |= GDK_HINT_MIN_SIZE;
if ((win->GetMaxWidth() != -1) || (win->GetMaxHeight() != -1)) flag |= GDK_HINT_MAX_SIZE;
if (flag)
{
gdk_window_set_hints( win->m_widget->window,
win->m_x, win->m_y,
win->GetMinWidth(), win->GetMinHeight(),
win->GetMaxWidth(), win->GetMaxHeight(),
flag );
win->m_x, win->m_y,
win->GetMinWidth(), win->GetMinHeight(),
win->GetMaxWidth(), win->GetMaxHeight(),
flag );
}
/* reset the icon */
@@ -262,7 +262,7 @@ bool wxDialog::Create( wxWindow *parent,
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
{
wxFAIL_MSG( wxT("wxDialog creation failed") );
return FALSE;
return FALSE;
}
m_insertCallback = (wxInsertChildFunction) wxInsertChildInDialog;
@@ -456,6 +456,7 @@ void wxDialog::DoSetSize( int x, int y, int width, int height, int sizeFlags )
int old_x = m_x;
int old_y = m_y;
int old_width = m_width;
int old_height = m_height;

View File

@@ -20,6 +20,8 @@
#endif
#include "wx/font.h"
#include "wx/fontutil.h"
#include "wx/cmndata.h"
#include "wx/utils.h"
#include "wx/log.h"
#include "wx/gdicmn.h"
@@ -122,7 +124,7 @@ wxFontRefData::wxFontRefData(int size, int family, int style,
int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding )
: m_scaled_xfonts(wxKEY_INTEGER)
{
Init(size, family, style, weight,
Init(size, family, style, weight,
underlined, faceName, encoding);
}
@@ -150,18 +152,16 @@ void wxFont::Init()
wxTheFontList->Append( this );
}
wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName )
wxFont::wxFont( const wxString& fontname, const wxFontData& fontdata )
{
if (!xFontName)
return;
Init();
wxCHECK_RET( !!fontname, _T("invalid font spec") );
m_refData = new wxFontRefData();
wxString tmp;
wxString fontname( xFontName );
wxStringTokenizer tn( fontname, wxT("-") );
tn.GetNextToken(); // foundry
@@ -177,7 +177,7 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName )
if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT;
if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT;
tmp = tn.GetNextToken().MakeUpper(); // slant
if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC;
if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC;
@@ -211,32 +211,36 @@ wxFont::wxFont( GdkFont *WXUNUSED(font), char *xFontName )
tn.GetNextToken(); // avg width
// deal with font encoding
wxString registry = tn.GetNextToken().MakeUpper(),
encoding = tn.GetNextToken().MakeUpper();
M_FONTDATA->m_encoding = fontdata.GetEncoding();
if ( M_FONTDATA->m_encoding == wxFONTENCODING_SYSTEM )
{
wxString registry = tn.GetNextToken().MakeUpper(),
encoding = tn.GetNextToken().MakeUpper();
if ( registry == _T("ISO8859") )
{
int cp;
if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
if ( registry == _T("ISO8859") )
{
M_FONTDATA->m_encoding =
(wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
int cp;
if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
{
M_FONTDATA->m_encoding =
(wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
}
}
}
else if ( registry == _T("MICROSOFT") )
{
int cp;
if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
else if ( registry == _T("MICROSOFT") )
{
M_FONTDATA->m_encoding =
(wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
int cp;
if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
{
M_FONTDATA->m_encoding =
(wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
}
}
else if ( registry == _T("KOI8") )
{
M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
}
//else: unknown encoding - may be give a warning here?
}
else if ( registry == _T("KOI8") )
{
M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
}
//else: unknown encoding - may be give a warning here?
}
bool wxFont::Create( int pointSize,
@@ -429,10 +433,9 @@ GdkFont *wxFont::GetInternalFont( float scale ) const
M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
}
if (!font)
{
wxLogError(wxT("could not load any font"));
}
// it's quite useless to make it a wxCHECK because we're going to crash
// anyhow...
wxASSERT_MSG( font, wxT("could not load any font?") );
return font;
}

View File

@@ -69,15 +69,53 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
}
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
wxFont font( gfont, fontname );
// extract the relevant bits from it
wxString xregistry, xencoding;
char *dash = strrchr(fontname, '-'); // find the last dash
if ( dash )
{
xencoding = dash + 1;
*dash = '\0';
dash = strrchr(fontname, '-'); // the last before one
if ( dash )
{
xregistry = dash + 1;
}
else
{
wxFAIL_MSG(_T("no registry in X font spec?"));
}
// restore the dash we changed to NUL above
*(fontname + strlen(fontname)) = '-';
}
else
{
wxFAIL_MSG(_T("no encoding in X font spec?"));
}
// transfer the X registry/encoding to wxFontData - they are used by
// wxFontMapper after wxFontDialog returns
wxFontData& fontdata = dialog->m_fontData;
// we ignore the facename here - should be enough to choose an arbitrary
// one if the registry/encoding are specified
// dialog->m_fontData.EncodingInfo().facename = xfamily;
fontdata.EncodingInfo().xregistry = xregistry;
fontdata.EncodingInfo().xencoding = xencoding;
// pass fontdata to wxFont ctor so that it can get the encoding from there
// if it is already known (otherwise it will try to deduce it itself)
dialog->m_fontData.SetChosenFont( wxFont(fontname, fontdata) );
g_free( fontname );
dialog->m_fontData.SetChosenFont( font );
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
event.SetEventObject( dialog );
dialog->GetEventHandler()->ProcessEvent( event );
}
#endif // GTK+ 1.2 andlater only
#endif // GTK+ 1.2 and later only
//-----------------------------------------------------------------------------
// "clicked" for Cancel-button
@@ -100,7 +138,8 @@ void gtk_fontdialog_cancel_callback( GtkWidget *WXUNUSED(w), wxFontDialog *dialo
IMPLEMENT_DYNAMIC_CLASS(wxFontDialog,wxDialog)
wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *WXUNUSED(data) )
wxFontDialog::wxFontDialog( wxWindow *parent, wxFontData *fontdata )
: m_fontData(*fontdata)
{
m_needParent = FALSE;

View File

@@ -85,7 +85,7 @@ static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation*
(int)alloc->width,
(int)alloc->height );
*/
win->m_width = alloc->width;
win->m_height = alloc->height;
win->UpdateSize();
@@ -164,14 +164,14 @@ static void gtk_toolbar_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidge
// "configure_event"
//-----------------------------------------------------------------------------
static gint
static gint
#if (GTK_MINOR_VERSON > 0)
gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *WXUNUSED(event), wxFrame *win )
#else
gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win )
#endif
{
if (g_isIdle)
if (g_isIdle)
wxapp_install_idle_handler();
if (!win->m_hasVMT) return FALSE;
@@ -255,13 +255,13 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win )
if ((win->GetMaxWidth() != -1) || (win->GetMaxHeight() != -1)) flag |= GDK_HINT_MAX_SIZE;
if (flag)
{
gdk_window_set_hints( win->m_widget->window,
win->m_x, win->m_y,
win->GetMinWidth(), win->GetMinHeight(),
win->GetMaxWidth(), win->GetMaxHeight(),
flag );
gdk_window_set_hints( win->m_widget->window,
win->m_x, win->m_y,
win->GetMinWidth(), win->GetMinHeight(),
win->GetMaxWidth(), win->GetMaxHeight(),
flag );
}
/* reset the icon */
if (win->m_icon != wxNullIcon)
{
@@ -300,7 +300,7 @@ gtk_frame_realized_callback( GtkWidget *widget, wxFrame *win )
static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child )
{
wxASSERT( GTK_IS_WIDGET(child->m_widget) );
if (!parent->m_insertInClientArea)
{
/* these are outside the client area */
@@ -397,7 +397,7 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
!CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
{
wxFAIL_MSG( wxT("wxFrame creation failed") );
return FALSE;
return FALSE;
}
m_title = title;
@@ -530,6 +530,7 @@ void wxFrame::DoSetSize( int x, int y, int width, int height, int sizeFlags )
int old_x = m_x;
int old_y = m_y;
int old_width = m_width;
int old_height = m_height;
@@ -693,7 +694,7 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
m_width = width;
m_height = height;
/* space occupied by m_frameToolBar and m_frameMenuBar */
int client_area_y_offset = 0;
@@ -737,7 +738,7 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
#if wxUSE_TOOLBAR
if ((m_frameToolBar) &&
(m_frameToolBar->m_widget->parent == m_mainWidget))
(m_frameToolBar->m_widget->parent == m_mainWidget))
{
int xx = m_miniEdge;
int yy = m_miniEdge + m_miniTitle;
@@ -750,7 +751,7 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
}
int ww = m_width - 2*m_miniEdge;
int hh = m_frameToolBar->m_height;
if (m_toolBarDetached) hh = wxPLACE_HOLDER;
if (m_toolBarDetached) hh = wxPLACE_HOLDER;
m_frameToolBar->m_x = xx;
m_frameToolBar->m_y = yy;
/* m_frameToolBar->m_height = hh; don't change the toolbar's reported size
@@ -798,7 +799,7 @@ void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height
m_sizeSet = TRUE;
// send size event to frame
wxSizeEvent event( wxSize(m_width,m_height), GetId() );
event.SetEventObject( this );
@@ -828,11 +829,11 @@ void wxFrame::OnInternalIdle()
if (!m_sizeSet && GTK_WIDGET_REALIZED(m_wxwindow))
{
GtkOnSize( m_x, m_y, m_width, m_height );
// we'll come back later
// we'll come back later
if (g_isIdle)
wxapp_install_idle_handler();
return;
return;
}
if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle();
@@ -920,8 +921,8 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_detached",
GTK_SIGNAL_FUNC(gtk_menu_detached_callback), (gpointer)this );
}
m_frameMenuBar->Show( TRUE );
m_frameMenuBar->Show( TRUE );
}
}
@@ -986,9 +987,9 @@ wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString&
return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name );
}
void wxFrame::SetToolBar(wxToolBar *toolbar)
{
m_frameToolBar = toolbar;
void wxFrame::SetToolBar(wxToolBar *toolbar)
{
m_frameToolBar = toolbar;
if (m_frameToolBar)
{
/* insert into toolbar area if not already there */
@@ -996,10 +997,10 @@ void wxFrame::SetToolBar(wxToolBar *toolbar)
(m_frameToolBar->m_widget->parent != m_mainWidget))
{
GetChildren().DeleteObject( m_frameToolBar );
gtk_widget_reparent( m_frameToolBar->m_widget, m_mainWidget );
UpdateSize();
}
gtk_widget_reparent( m_frameToolBar->m_widget, m_mainWidget );
UpdateSize();
}
}
}
@@ -1113,25 +1114,25 @@ void wxFrame::SetIcon( const wxIcon &icon )
gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
}
void wxFrame::Maximize(bool WXUNUSED(maximize))
void wxFrame::Maximize(bool WXUNUSED(maximize))
{
}
void wxFrame::Restore()
void wxFrame::Restore()
{
}
void wxFrame::Iconize( bool iconize )
{
void wxFrame::Iconize( bool iconize )
{
if (iconize)
{
XIconifyWindow( GDK_WINDOW_XDISPLAY( m_widget->window ),
GDK_WINDOW_XWINDOW( m_widget->window ),
DefaultScreen( GDK_DISPLAY() ) );
GDK_WINDOW_XWINDOW( m_widget->window ),
DefaultScreen( GDK_DISPLAY() ) );
}
}
bool wxFrame::IsIconized() const
{
return FALSE;
bool wxFrame::IsIconized() const
{
return FALSE;
}