Lots of Pango etc up-ports from HEAD.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@19179 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2003-02-11 11:35:15 +00:00
parent 7cc3aa347b
commit adb5f43a58
22 changed files with 447 additions and 266 deletions

View File

@@ -254,7 +254,7 @@ static char wxPostScriptHeaderReencodeISO2[] =
IMPLEMENT_DYNAMIC_CLASS(wxPostScriptDC, wxDC)
float wxPostScriptDC::ms_PSScaleFactor = 10.0;
float wxPostScriptDC::ms_PSScaleFactor = 1.0;
void wxPostScriptDC::SetResolution(int ppi)
{
@@ -1220,16 +1220,20 @@ void draw_bezier_outline(FILE *file,
fprintf(file, "gsave\n");
fprintf(file, "%d %d translate\n", pos_x, pos_y );
// FT2 scales outlines to 26.6 pixels so the code below
// should read 26600 instead of the 60000.
fprintf(file, "%d 60000 div %d 60000 div scale\n", scale_x, scale_y );
fprintf(file, "0 0 0 setrgbcolor\n");
// We have to replace the "," from the German
// locale with the Englich "." for PostScript
char buf[100];
sprintf(buf, "%.8f %.8f scale\n", scale_x, scale_y );
for (size_t i = 0; i < strlen(buf); i++)
if (buf[i] == ',') buf[i] = '.';
fprintf(file, buf);
FT_Load_Glyph(face, glyph_index, load_flags);
FT_Get_Glyph (face->glyph, &glyph);
FT_Outline_Decompose (&(((FT_OutlineGlyph)glyph)->outline),
&outlinefunc, &outline_info);
fprintf(file, "closepath fill grestore \n");
fprintf(file, "closepath fill grestore\n");
FT_Done_Glyph (glyph);
}
@@ -1240,78 +1244,6 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
{
wxCHECK_RET( m_ok && m_pstream, wxT("invalid postscript dc") );
#if wxUSE_PANGO
int dpi = GetResolution();
dpi = 300;
PangoContext *context = pango_ft2_get_context ( dpi, dpi );
pango_context_set_language (context, pango_language_from_string ("en_US"));
pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description );
PangoLayout *layout = pango_layout_new (context);
#if wxUSE_UNICODE
wxCharBuffer buffer = wxConvUTF8.cWC2MB( text );
#else
wxCharBuffer buffer = wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) );
#endif
pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) );
PangoRectangle rect;
pango_layout_get_extents(layout, NULL, &rect);
int xx = x * PANGO_SCALE;
int yy = y * PANGO_SCALE + (rect.height*2/3);
int scale_x = LogicalToDeviceXRel( 1000 );
int scale_y = LogicalToDeviceYRel( 1000 );
// Loop over lines in layout
int num_lines = pango_layout_get_line_count( layout );
for (int i = 0; i < num_lines; i++)
{
PangoLayoutLine *line = pango_layout_get_line( layout, i );
// Loop over runs in line
GSList *runs_list = line->runs;
while (runs_list)
{
PangoLayoutRun *run = (PangoLayoutRun*) runs_list->data;
PangoItem *item = run->item;
PangoGlyphString *glyphs = run->glyphs;
PangoAnalysis *analysis = &item->analysis;
PangoFont *font = analysis->font;
FT_Face ft_face = pango_ft2_font_get_face(font);
int num_glyphs = glyphs->num_glyphs;
for (int glyph_idx = 0; glyph_idx < num_glyphs; glyph_idx++)
{
PangoGlyphGeometry geometry = glyphs->glyphs[glyph_idx].geometry;
int pos_x = xx + geometry.x_offset;
int pos_y = yy - geometry.y_offset;
xx += geometry.width;
draw_bezier_outline( m_pstream, ft_face,
(FT_UInt)(glyphs->glyphs[glyph_idx].glyph),
LogicalToDeviceX( pos_x / PANGO_SCALE ),
LogicalToDeviceY( pos_y / PANGO_SCALE ),
scale_x, scale_y );
}
runs_list = runs_list->next;
}
}
g_object_unref( G_OBJECT( layout ) );
#else
wxCoord text_w, text_h, text_descent;
GetTextExtent(text, &text_w, &text_h, &text_descent);
// VZ: this seems to be unnecessary, so taking it out for now, if it
// doesn't create any problems, remove this comment entirely
//SetFont( m_font );
if (m_textForegroundColour.Ok())
{
unsigned char red = m_textForegroundColour.Red();
@@ -1352,6 +1284,90 @@ void wxPostScriptDC::DoDrawText( const wxString& text, wxCoord x, wxCoord y )
}
}
#if wxUSE_PANGO
int ps_dpi = 72;
int pango_dpi = 600;
PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
double scale = (double)pango_dpi / (double)ps_dpi;
scale /= m_userScaleY;
pango_context_set_language (context, pango_language_from_string ("en_US"));
pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
pango_context_set_font_description (context, m_font.GetNativeFontInfo()->description );
PangoLayout *layout = pango_layout_new (context);
#if wxUSE_UNICODE
wxCharBuffer buffer = wxConvUTF8.cWC2MB( text );
#else
wxCharBuffer buffer = wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC( text ) );
#endif
pango_layout_set_text( layout, (const char*) buffer, strlen(buffer) );
fprintf( m_pstream, "%%%% %s\n", (const char*)buffer );
PangoRectangle rect;
pango_layout_get_extents(layout, NULL, &rect);
int xx = LogicalToDeviceX( x );
int yy = LogicalToDeviceY( y );
int xxx = xx * PANGO_SCALE;
int yyy = yy * PANGO_SCALE - (int)(rect.height * 0.66 / scale); // Move down by estimated baseline. HACK.
#define ps_kludge_factor 2.8
// Loop over lines in layout
int num_lines = pango_layout_get_line_count( layout );
for (int i = 0; i < num_lines; i++)
{
PangoLayoutLine *line = pango_layout_get_line( layout, i );
// width of glyphs already printed
int all_width = 0;
// Loop over runs in line
GSList *runs_list = line->runs;
while (runs_list)
{
PangoLayoutRun *run = (PangoLayoutRun*) runs_list->data;
PangoItem *item = run->item;
PangoGlyphString *glyphs = run->glyphs;
PangoAnalysis *analysis = &item->analysis;
PangoFont *font = analysis->font;
FT_Face ft_face = pango_ft2_font_get_face(font);
int num_glyphs = glyphs->num_glyphs;
for (int glyph_idx = 0; glyph_idx < num_glyphs; glyph_idx++)
{
PangoGlyphGeometry geometry = glyphs->glyphs[glyph_idx].geometry;
int pos_x = xxx + (int)((double)(all_width+geometry.x_offset) / scale);
int pos_y = yyy + (int)((double)geometry.y_offset / scale );
all_width += geometry.width;
draw_bezier_outline( m_pstream, ft_face,
(FT_UInt)(glyphs->glyphs[glyph_idx].glyph),
pos_x / PANGO_SCALE,
pos_y / PANGO_SCALE,
1.0/(ps_kludge_factor * scale * 26.6),
1.0/(ps_kludge_factor * scale * 26.6) );
}
runs_list = runs_list->next;
}
}
g_object_unref( G_OBJECT( layout ) );
g_object_unref( G_OBJECT( context ) );
#else
wxCoord text_w, text_h, text_descent;
GetTextExtent(text, &text_w, &text_h, &text_descent);
// VZ: this seems to be unnecessary, so taking it out for now, if it
// doesn't create any problems, remove this comment entirely
//SetFont( m_font );
int size = m_font.GetPointSize();
// wxCoord by = y + (wxCoord)floor( double(size) * 2.0 / 3.0 ); // approximate baseline
@@ -1981,8 +1997,12 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
}
#if wxUSE_PANGO
int dpi = GetResolution();
PangoContext *context = pango_ft2_get_context ( dpi, dpi );
int wx_dpi = GetResolution();
int pango_dpi = 600;
PangoContext *context = pango_ft2_get_context ( pango_dpi, pango_dpi );
double scale = pango_dpi / wx_dpi;
scale /= m_userScaleY;
pango_context_set_language (context, pango_language_from_string ("en_US"));
pango_context_set_base_dir (context, PANGO_DIRECTION_LTR );
@@ -1992,20 +2012,19 @@ void wxPostScriptDC::DoGetTextExtent(const wxString& string,
PangoFontDescription *desc = fontToUse->GetNativeFontInfo()->description;
pango_layout_set_font_description(layout, desc);
#if wxUSE_UNICODE
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
#else
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
#endif
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
PangoRectangle rect;
pango_layout_line_get_extents(line, NULL, &rect);
if (x) (*x) = (wxCoord) ( m_scaleX * rect.width / PANGO_SCALE );
if (y) (*y) = (wxCoord) ( m_scaleY * rect.height / PANGO_SCALE );
if (x) (*x) = (wxCoord) ( rect.width / PANGO_SCALE / scale );
if (y) (*y) = (wxCoord) ( rect.height / PANGO_SCALE / scale );
if (descent)
{
// Do something about metrics here

View File

@@ -448,14 +448,11 @@ wxSize wxChoice::DoGetBestSize() const
ret.x = 0;
if ( m_widget )
{
GdkFont *font = m_font.GetInternalFont();
wxCoord width;
int width;
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
// FIXME GTK 2.0
width = (wxCoord)gdk_string_width(font, wxGTK_CONV( GetString(n) ) );
GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
if ( width > ret.x )
ret.x = width;
}
@@ -477,7 +474,7 @@ wxSize wxChoice::DoGetBestSize() const
if ( ret.x < 80 )
ret.x = 80;
ret.y = 16 + gdk_char_height(GET_STYLE_FONT( m_widget->style ), 'H' );
ret.y = 16 + GetCharHeight();
return ret;
}

View File

@@ -750,13 +750,11 @@ wxSize wxComboBox::DoGetBestSize() const
ret.x = 0;
if ( m_widget )
{
GdkFont *font = m_font.GetInternalFont();
wxCoord width;
size_t count = Number();
int width;
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
width = (wxCoord)gdk_string_width(font, wxGTK_CONV( GetString(n) ) );
GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
if ( width > ret.x )
ret.x = width;
}

View File

@@ -1436,27 +1436,56 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
#ifdef __WXGTK20__
// TODO: the layout engine should be abstracted at a higher level!
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
{
#if wxUSE_UNICODE
const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
#else
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
#endif
}
// Measure layout.
#if wxUSE_UNICODE
const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
#else
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
#endif
pango_layout_set_text( layout, (const char*)data, strlen((const char*)data) );
if (m_scaleY != 1.0)
{
// If there is a user or actually any scale applied to
// the device context, scale the font.
// scale font description
gint oldSize = pango_font_description_get_size( m_fontdesc );
double size = oldSize;
size = size * m_scaleY;
pango_font_description_set_size( m_fontdesc, (gint)size );
// actually apply scaled font
pango_layout_set_font_description( layout, m_fontdesc );
// Draw layout.
gdk_draw_layout( m_window, m_textGC, x, y, layout );
// reset unscaled size
pango_font_description_set_size( m_fontdesc, oldSize );
}
else
{
// actually apply font
pango_layout_set_font_description( layout, m_fontdesc );
// Draw layout.
gdk_draw_layout( m_window, m_textGC, x, y, layout );
}
#if 0
// Measure layout
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
pango_layout_get_pixel_size( m_layout, &w, &h );
#else
int w = 10;
int h = 10;
#endif
wxCoord width = w;
wxCoord height = h;
// Draw layout.
gdk_draw_layout( m_window, m_textGC, x, y, layout );
g_object_unref( G_OBJECT( layout ) );
#else // GTK+ 1.x
wxCoord width = gdk_string_width( font, text.mbc_str() );
@@ -1614,25 +1643,24 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
#ifdef __WXGTK20__
// Create layout and set font description
PangoLayout *layout = pango_layout_new(m_context);
PangoLayout *layout = pango_layout_new( m_context );
if (theFont)
pango_layout_set_font_description( layout, theFont->GetNativeFontInfo()->description );
else
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_font_description( layout, m_fontdesc );
// Set layout's text
#if wxUSE_UNICODE
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
#else
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
#endif
pango_layout_set_text( layout, (const char*) data, strlen((const char*)data) );
// Measure text.
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
pango_layout_get_pixel_size( layout, &w, &h );
if (width) (*width) = (wxCoord) w;
if (height) (*height) = (wxCoord) h;
@@ -1681,7 +1709,7 @@ wxCoord wxWindowDC::GetCharHeight() const
// There should be an easier way.
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_text(layout, "H", 1 );
pango_layout_set_text(layout, "H", 1);
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
g_object_unref( G_OBJECT( layout ) );

View File

@@ -64,6 +64,8 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
wxapp_install_idle_handler();
GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
#ifndef __WXGTK20__
GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
if (!gfont)
@@ -72,13 +74,10 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
wxOK | wxICON_ERROR);
return;
}
#endif
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
// printf( "font %s\n", fontname );
gchar *fontname = gtk_font_selection_dialog_get_font_name( fontdlg );
dialog->SetChosenFont( fontname);
g_free( fontname );
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);

View File

@@ -145,7 +145,7 @@ static wxString wxReplaceUnderscore( const wxString& title )
#endif
else
{
#if __WXGTK12__
#ifdef __WXGTK12__
if ( *pc == wxT('_') )
{
// underscores must be doubled to prevent them from being
@@ -907,7 +907,7 @@ void wxMenuItem::DoSetText( const wxString& str )
#if GTK_CHECK_VERSION(2, 0, 0)
else if ( *pc == wxT('_') ) // escape underscores
{
// m_text << wxT("__"); doesn't work
m_text << wxT("__");
}
else if (*pc == wxT('/')) // we have to escape slashes
{
@@ -1010,8 +1010,12 @@ wxString wxMenuItem::GetFactoryPath() const
{
if ( *pc == wxT('_') )
{
#ifdef __WXGTK20__
pc++;
#else
// remove '_' unconditionally
continue;
#endif
}
// don't remove ampersands '&' since if we have them in the menu item title

View File

@@ -82,28 +82,28 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g
0, 0,
win->m_width, win->m_height );
if (!win->m_title.IsEmpty() &&
if (!win->GetTitle().IsEmpty() &&
((win->GetWindowStyle() & wxCAPTION) ||
(win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
(win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
{
wxClientDC dc(win);
dc.SetFont( *wxSMALL_FONT );
int height = dc.GetCharHeight();
GdkGC *gc = gdk_gc_new( pizza->bin_window );
GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
3,
3,
win->m_width - 7,
font->ascent + font->descent+1 );
gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
gdk_draw_string( pizza->bin_window, font, gc,
6,
3+font->ascent,
wxGTK_CONV( win->m_title ) );
height+1 );
gdk_gc_unref( gc );
// Hack alert
dc.m_window = pizza->bin_window;
dc.SetTextForeground( *wxWHITE );
dc.DrawText( win->GetTitle(), 6, 3 );
}
}
@@ -111,6 +111,7 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g
// "draw" of m_mainWidget
//-----------------------------------------------------------------------------
#ifndef __WXGTK20__
static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win )
{
if (g_isIdle) wxapp_install_idle_handler();
@@ -131,25 +132,26 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU
(win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
(win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
{
wxClientDC dc(win);
dc.SetFont( *wxSMALL_FONT );
int height = dc.GetCharHeight();
GdkGC *gc = gdk_gc_new( pizza->bin_window );
GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
3,
3,
win->m_width - 7,
font->ascent + font->descent+1 );
gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
gdk_draw_string( pizza->bin_window, font, gc,
6,
3+font->ascent,
wxGTK_CONV( win->m_title ) );
height+1 );
gdk_gc_unref( gc );
// Hack alert
dc.m_window = pizza->bin_window;
dc.SetTextForeground( *wxWHITE );
dc.DrawText( win->GetTitle(), 6, 3 );
}
}
#endif
//-----------------------------------------------------------------------------
// "button_press_event" of m_mainWidget
@@ -167,9 +169,11 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
GtkPizza *pizza = GTK_PIZZA(widget);
if (gdk_event->window != pizza->bin_window) return TRUE;
wxClientDC dc(win);
dc.SetFont( *wxSMALL_FONT );
int height = dc.GetCharHeight() + 1;
GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
int height = font->ascent + font->descent+1;
if (gdk_event->y > height) return TRUE;
gdk_window_raise( win->m_widget->window );
@@ -364,8 +368,10 @@ bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title
gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
#ifndef __WXGTK20__
gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
#endif
/* these are required for dragging the mini frame around */
gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",

View File

@@ -328,21 +328,8 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
if (!g_systemFont)
{
#ifdef __WXGTK20__
GtkWidget *widget = gtk_button_new();
GtkStyle *def = gtk_rc_get_style( widget );
if (!def)
def = gtk_widget_get_default_style();
if (def)
{
wxNativeFontInfo info;
info.description = def->font_desc;
g_systemFont = new wxFont(info);
}
else
{
g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
}
gtk_widget_destroy( widget );
const gchar *font_name = _gtk_rc_context_get_default_font_name (gtk_settings_get_default ());
g_systemFont = new wxFont( wxString::FromAscii( font_name ) );
#else
g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
#endif

View File

@@ -343,8 +343,6 @@ bool wxToolBar::Create( wxWindow *parent,
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
SET_STYLE_FONT(g_style, GtkGetDefaultGuiFont());
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
m_parent->DoAddChild( this );

View File

@@ -76,8 +76,6 @@ void wxToolTip::Apply( wxWindow *win )
g_style->fg[GTK_STATE_NORMAL] = ss_fg;
g_style->bg[GTK_STATE_NORMAL] = ss_bg;
SET_STYLE_FONT( g_style, GtkGetDefaultGuiFont() );
gtk_widget_set_style( ss_tooltips->tip_window, g_style );
#else // GTK+ 1.0
gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg );

View File

@@ -1695,6 +1695,20 @@ static gint gtk_window_button_press_callback( GtkWidget *widget,
wxPrintf( wxT(".\n") );
*/
#ifndef __WXGTK20__
if (event_type == wxEVT_LEFT_DCLICK)
{
// GTK 1.2 crashes when intercepting double
// click events from both wxSpinButton and
// wxSpinCtrl
if (GTK_IS_SPIN_BUTTON(win->m_widget))
{
// Just disable this event for now.
return FALSE;
}
}
#endif
if (win->GetEventHandler()->ProcessEvent( event ))
{
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" );
@@ -3406,9 +3420,31 @@ int wxWindowGTK::GetCharHeight() const
wxCHECK_MSG( m_font.Ok(), 12, wxT("invalid font") );
#ifdef __WXGTK20__
PangoContext *context = NULL;
if (m_widget)
context = gtk_widget_get_pango_context( m_widget );
if (!context)
return 0;
PangoFontDescription *desc = m_font.GetNativeFontInfo()->description;
PangoLayout *layout = pango_layout_new(context);
pango_layout_set_font_description(layout, desc);
pango_layout_set_text(layout, "H", 1);
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
PangoRectangle rect;
pango_layout_line_get_extents(line, NULL, &rect);
g_object_unref( G_OBJECT( layout ) );
return (int) (rect.height / PANGO_SCALE);
#else
GdkFont *font = m_font.GetInternalFont( 1.0 );
return font->ascent + font->descent;
#endif
}
int wxWindowGTK::GetCharWidth() const
@@ -3417,9 +3453,31 @@ int wxWindowGTK::GetCharWidth() const
wxCHECK_MSG( m_font.Ok(), 8, wxT("invalid font") );
#ifdef __WXGTK20__
PangoContext *context = NULL;
if (m_widget)
context = gtk_widget_get_pango_context( m_widget );
if (!context)
return 0;
PangoFontDescription *desc = m_font.GetNativeFontInfo()->description;
PangoLayout *layout = pango_layout_new(context);
pango_layout_set_font_description(layout, desc);
pango_layout_set_text(layout, "H", 1);
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
PangoRectangle rect;
pango_layout_line_get_extents(line, NULL, &rect);
g_object_unref( G_OBJECT( layout ) );
return (int) (rect.width / PANGO_SCALE);
#else
GdkFont *font = m_font.GetInternalFont( 1.0 );
return gdk_string_width( font, "H" );
#endif
}
void wxWindowGTK::GetTextExtent( const wxString& string,
@@ -4089,7 +4147,13 @@ void wxWindowGTK::SetWidgetStyle()
if (m_font != wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ))
{
SET_STYLE_FONT(style, m_font.GetInternalFont( 1.0 ));
#ifdef __WXGTK20__
pango_font_description_free( style->font_desc );
pango_font_description_copy( m_font.GetNativeFontInfo()->description );
#else
gdk_font_unref( style->font );
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
#endif
}
if (m_foregroundColour.Ok())

View File

@@ -448,14 +448,11 @@ wxSize wxChoice::DoGetBestSize() const
ret.x = 0;
if ( m_widget )
{
GdkFont *font = m_font.GetInternalFont();
wxCoord width;
int width;
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
// FIXME GTK 2.0
width = (wxCoord)gdk_string_width(font, wxGTK_CONV( GetString(n) ) );
GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
if ( width > ret.x )
ret.x = width;
}
@@ -477,7 +474,7 @@ wxSize wxChoice::DoGetBestSize() const
if ( ret.x < 80 )
ret.x = 80;
ret.y = 16 + gdk_char_height(GET_STYLE_FONT( m_widget->style ), 'H' );
ret.y = 16 + GetCharHeight();
return ret;
}

View File

@@ -750,13 +750,11 @@ wxSize wxComboBox::DoGetBestSize() const
ret.x = 0;
if ( m_widget )
{
GdkFont *font = m_font.GetInternalFont();
wxCoord width;
size_t count = Number();
int width;
size_t count = GetCount();
for ( size_t n = 0; n < count; n++ )
{
width = (wxCoord)gdk_string_width(font, wxGTK_CONV( GetString(n) ) );
GetTextExtent( GetString(n), &width, NULL, NULL, NULL, &m_font );
if ( width > ret.x )
ret.x = width;
}

View File

@@ -1436,27 +1436,56 @@ void wxWindowDC::DoDrawText( const wxString &text, wxCoord x, wxCoord y )
#ifdef __WXGTK20__
// TODO: the layout engine should be abstracted at a higher level!
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
{
#if wxUSE_UNICODE
const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
#else
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
#endif
}
// Measure layout.
#if wxUSE_UNICODE
const wxCharBuffer data = wxConvUTF8.cWC2MB( text );
#else
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( text );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
#endif
pango_layout_set_text( layout, (const char*)data, strlen((const char*)data) );
if (m_scaleY != 1.0)
{
// If there is a user or actually any scale applied to
// the device context, scale the font.
// scale font description
gint oldSize = pango_font_description_get_size( m_fontdesc );
double size = oldSize;
size = size * m_scaleY;
pango_font_description_set_size( m_fontdesc, (gint)size );
// actually apply scaled font
pango_layout_set_font_description( layout, m_fontdesc );
// Draw layout.
gdk_draw_layout( m_window, m_textGC, x, y, layout );
// reset unscaled size
pango_font_description_set_size( m_fontdesc, oldSize );
}
else
{
// actually apply font
pango_layout_set_font_description( layout, m_fontdesc );
// Draw layout.
gdk_draw_layout( m_window, m_textGC, x, y, layout );
}
#if 0
// Measure layout
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
pango_layout_get_pixel_size( m_layout, &w, &h );
#else
int w = 10;
int h = 10;
#endif
wxCoord width = w;
wxCoord height = h;
// Draw layout.
gdk_draw_layout( m_window, m_textGC, x, y, layout );
g_object_unref( G_OBJECT( layout ) );
#else // GTK+ 1.x
wxCoord width = gdk_string_width( font, text.mbc_str() );
@@ -1614,25 +1643,24 @@ void wxWindowDC::DoGetTextExtent(const wxString &string,
#ifdef __WXGTK20__
// Create layout and set font description
PangoLayout *layout = pango_layout_new(m_context);
PangoLayout *layout = pango_layout_new( m_context );
if (theFont)
pango_layout_set_font_description( layout, theFont->GetNativeFontInfo()->description );
else
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_font_description( layout, m_fontdesc );
// Set layout's text
#if wxUSE_UNICODE
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
const wxCharBuffer data = wxConvUTF8.cWC2MB( string );
#else
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
pango_layout_set_text(layout, (const char*) data, strlen( (const char*) data ));
const wxWCharBuffer wdata = wxConvLocal.cMB2WC( string );
const wxCharBuffer data = wxConvUTF8.cWC2MB( wdata );
#endif
pango_layout_set_text( layout, (const char*) data, strlen((const char*)data) );
// Measure text.
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
pango_layout_get_pixel_size( layout, &w, &h );
if (width) (*width) = (wxCoord) w;
if (height) (*height) = (wxCoord) h;
@@ -1681,7 +1709,7 @@ wxCoord wxWindowDC::GetCharHeight() const
// There should be an easier way.
PangoLayout *layout = pango_layout_new(m_context);
pango_layout_set_font_description(layout, m_fontdesc);
pango_layout_set_text(layout, "H", 1 );
pango_layout_set_text(layout, "H", 1);
int w,h;
pango_layout_get_pixel_size(layout, &w, &h);
g_object_unref( G_OBJECT( layout ) );

View File

@@ -64,6 +64,8 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
wxapp_install_idle_handler();
GtkFontSelectionDialog *fontdlg = GTK_FONT_SELECTION_DIALOG(dialog->m_widget);
#ifndef __WXGTK20__
GdkFont *gfont = gtk_font_selection_dialog_get_font(fontdlg);
if (!gfont)
@@ -72,13 +74,10 @@ void gtk_fontdialog_ok_callback( GtkWidget *WXUNUSED(widget), wxFontDialog *dial
wxOK | wxICON_ERROR);
return;
}
#endif
gchar *fontname = gtk_font_selection_dialog_get_font_name(fontdlg);
// printf( "font %s\n", fontname );
gchar *fontname = gtk_font_selection_dialog_get_font_name( fontdlg );
dialog->SetChosenFont( fontname);
g_free( fontname );
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);

View File

@@ -145,7 +145,7 @@ static wxString wxReplaceUnderscore( const wxString& title )
#endif
else
{
#if __WXGTK12__
#ifdef __WXGTK12__
if ( *pc == wxT('_') )
{
// underscores must be doubled to prevent them from being
@@ -907,7 +907,7 @@ void wxMenuItem::DoSetText( const wxString& str )
#if GTK_CHECK_VERSION(2, 0, 0)
else if ( *pc == wxT('_') ) // escape underscores
{
// m_text << wxT("__"); doesn't work
m_text << wxT("__");
}
else if (*pc == wxT('/')) // we have to escape slashes
{
@@ -1010,8 +1010,12 @@ wxString wxMenuItem::GetFactoryPath() const
{
if ( *pc == wxT('_') )
{
#ifdef __WXGTK20__
pc++;
#else
// remove '_' unconditionally
continue;
#endif
}
// don't remove ampersands '&' since if we have them in the menu item title

View File

@@ -82,28 +82,28 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g
0, 0,
win->m_width, win->m_height );
if (!win->m_title.IsEmpty() &&
if (!win->GetTitle().IsEmpty() &&
((win->GetWindowStyle() & wxCAPTION) ||
(win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
(win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
{
wxClientDC dc(win);
dc.SetFont( *wxSMALL_FONT );
int height = dc.GetCharHeight();
GdkGC *gc = gdk_gc_new( pizza->bin_window );
GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
3,
3,
win->m_width - 7,
font->ascent + font->descent+1 );
gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
gdk_draw_string( pizza->bin_window, font, gc,
6,
3+font->ascent,
wxGTK_CONV( win->m_title ) );
height+1 );
gdk_gc_unref( gc );
// Hack alert
dc.m_window = pizza->bin_window;
dc.SetTextForeground( *wxWHITE );
dc.DrawText( win->GetTitle(), 6, 3 );
}
}
@@ -111,6 +111,7 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g
// "draw" of m_mainWidget
//-----------------------------------------------------------------------------
#ifndef __WXGTK20__
static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNUSED(rect), wxFrame *win )
{
if (g_isIdle) wxapp_install_idle_handler();
@@ -131,25 +132,26 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU
(win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) ||
(win->GetWindowStyle() & wxTINY_CAPTION_VERT)))
{
wxClientDC dc(win);
dc.SetFont( *wxSMALL_FONT );
int height = dc.GetCharHeight();
GdkGC *gc = gdk_gc_new( pizza->bin_window );
GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] );
gdk_draw_rectangle( pizza->bin_window, gc, TRUE,
3,
3,
win->m_width - 7,
font->ascent + font->descent+1 );
gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] );
gdk_draw_string( pizza->bin_window, font, gc,
6,
3+font->ascent,
wxGTK_CONV( win->m_title ) );
height+1 );
gdk_gc_unref( gc );
// Hack alert
dc.m_window = pizza->bin_window;
dc.SetTextForeground( *wxWHITE );
dc.DrawText( win->GetTitle(), 6, 3 );
}
}
#endif
//-----------------------------------------------------------------------------
// "button_press_event" of m_mainWidget
@@ -167,9 +169,11 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
GtkPizza *pizza = GTK_PIZZA(widget);
if (gdk_event->window != pizza->bin_window) return TRUE;
wxClientDC dc(win);
dc.SetFont( *wxSMALL_FONT );
int height = dc.GetCharHeight() + 1;
GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0);
int height = font->ascent + font->descent+1;
if (gdk_event->y > height) return TRUE;
gdk_window_raise( win->m_widget->window );
@@ -364,8 +368,10 @@ bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title
gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event",
GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this );
#ifndef __WXGTK20__
gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw",
GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this );
#endif
/* these are required for dragging the mini frame around */
gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event",

View File

@@ -328,21 +328,8 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index )
if (!g_systemFont)
{
#ifdef __WXGTK20__
GtkWidget *widget = gtk_button_new();
GtkStyle *def = gtk_rc_get_style( widget );
if (!def)
def = gtk_widget_get_default_style();
if (def)
{
wxNativeFontInfo info;
info.description = def->font_desc;
g_systemFont = new wxFont(info);
}
else
{
g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
}
gtk_widget_destroy( widget );
const gchar *font_name = _gtk_rc_context_get_default_font_name (gtk_settings_get_default ());
g_systemFont = new wxFont( wxString::FromAscii( font_name ) );
#else
g_systemFont = new wxFont( 12, wxSWISS, wxNORMAL, wxNORMAL );
#endif

View File

@@ -343,8 +343,6 @@ bool wxToolBar::Create( wxWindow *parent,
g_style->bg[GTK_STATE_NORMAL] = *m_bg;
SET_STYLE_FONT(g_style, GtkGetDefaultGuiFont());
gtk_widget_set_style( GTK_TOOLBAR(m_toolbar)->tooltips->tip_window, g_style );
m_parent->DoAddChild( this );

View File

@@ -76,8 +76,6 @@ void wxToolTip::Apply( wxWindow *win )
g_style->fg[GTK_STATE_NORMAL] = ss_fg;
g_style->bg[GTK_STATE_NORMAL] = ss_bg;
SET_STYLE_FONT( g_style, GtkGetDefaultGuiFont() );
gtk_widget_set_style( ss_tooltips->tip_window, g_style );
#else // GTK+ 1.0
gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg );

View File

@@ -1695,6 +1695,20 @@ static gint gtk_window_button_press_callback( GtkWidget *widget,
wxPrintf( wxT(".\n") );
*/
#ifndef __WXGTK20__
if (event_type == wxEVT_LEFT_DCLICK)
{
// GTK 1.2 crashes when intercepting double
// click events from both wxSpinButton and
// wxSpinCtrl
if (GTK_IS_SPIN_BUTTON(win->m_widget))
{
// Just disable this event for now.
return FALSE;
}
}
#endif
if (win->GetEventHandler()->ProcessEvent( event ))
{
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "button_press_event" );
@@ -3406,9 +3420,31 @@ int wxWindowGTK::GetCharHeight() const
wxCHECK_MSG( m_font.Ok(), 12, wxT("invalid font") );
#ifdef __WXGTK20__
PangoContext *context = NULL;
if (m_widget)
context = gtk_widget_get_pango_context( m_widget );
if (!context)
return 0;
PangoFontDescription *desc = m_font.GetNativeFontInfo()->description;
PangoLayout *layout = pango_layout_new(context);
pango_layout_set_font_description(layout, desc);
pango_layout_set_text(layout, "H", 1);
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
PangoRectangle rect;
pango_layout_line_get_extents(line, NULL, &rect);
g_object_unref( G_OBJECT( layout ) );
return (int) (rect.height / PANGO_SCALE);
#else
GdkFont *font = m_font.GetInternalFont( 1.0 );
return font->ascent + font->descent;
#endif
}
int wxWindowGTK::GetCharWidth() const
@@ -3417,9 +3453,31 @@ int wxWindowGTK::GetCharWidth() const
wxCHECK_MSG( m_font.Ok(), 8, wxT("invalid font") );
#ifdef __WXGTK20__
PangoContext *context = NULL;
if (m_widget)
context = gtk_widget_get_pango_context( m_widget );
if (!context)
return 0;
PangoFontDescription *desc = m_font.GetNativeFontInfo()->description;
PangoLayout *layout = pango_layout_new(context);
pango_layout_set_font_description(layout, desc);
pango_layout_set_text(layout, "H", 1);
PangoLayoutLine *line = (PangoLayoutLine *)pango_layout_get_lines(layout)->data;
PangoRectangle rect;
pango_layout_line_get_extents(line, NULL, &rect);
g_object_unref( G_OBJECT( layout ) );
return (int) (rect.width / PANGO_SCALE);
#else
GdkFont *font = m_font.GetInternalFont( 1.0 );
return gdk_string_width( font, "H" );
#endif
}
void wxWindowGTK::GetTextExtent( const wxString& string,
@@ -4089,7 +4147,13 @@ void wxWindowGTK::SetWidgetStyle()
if (m_font != wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ))
{
SET_STYLE_FONT(style, m_font.GetInternalFont( 1.0 ));
#ifdef __WXGTK20__
pango_font_description_free( style->font_desc );
pango_font_description_copy( m_font.GetNativeFontInfo()->description );
#else
gdk_font_unref( style->font );
style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
#endif
}
if (m_foregroundColour.Ok())

View File

@@ -132,26 +132,30 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
return wxFONTENCODING_SYSTEM;
}
bool wxNativeFontInfo::FromString(const wxString& s)
bool wxNativeFontInfo::FromString( const wxString& str )
{
if (description)
pango_font_description_free( description );
description = pango_font_description_from_string( wxGTK_CONV( s ) );
description = pango_font_description_from_string( wxGTK_CONV( str ) );
// wxPrintf( L"FromString result: %s\n", ToString().c_str() );
return TRUE;
}
wxString wxNativeFontInfo::ToString() const
{
wxString tmp = wxGTK_CONV_BACK( pango_font_description_to_string( description ) );
char *str = pango_font_description_to_string( description );
wxString tmp = wxGTK_CONV_BACK( str );
g_free( str );
return tmp;
}
bool wxNativeFontInfo::FromUserString(const wxString& s)
bool wxNativeFontInfo::FromUserString( const wxString& str )
{
return FromString( s );
return FromString( str );
}
wxString wxNativeFontInfo::ToUserString() const