Added speed-up for font-loading (a bit simplistic),

Moving between items in a radiobox works again,
  Tried to remove remaining gap in a wxStaticBox that
    has no text-label.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4642 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-11-21 11:32:06 +00:00
parent 7eef8db20d
commit 2e0e025ecd
6 changed files with 164 additions and 4 deletions

View File

@ -714,7 +714,7 @@ void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event))
void MyPanel::OnListBox( wxCommandEvent &event ) void MyPanel::OnListBox( wxCommandEvent &event )
{ {
GetParent()->Move(100, 100); // GetParent()->Move(100, 100);
wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox
: m_listboxSorted; : m_listboxSorted;

View File

@ -62,6 +62,57 @@ static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRad
rb->GetEventHandler()->ProcessEvent(event); rb->GetEventHandler()->ProcessEvent(event);
} }
//-----------------------------------------------------------------------------
// "key_press_event"
//-----------------------------------------------------------------------------
static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
{
if (g_isIdle)
wxapp_install_idle_handler();
if (!rb->m_hasVMT) return FALSE;
if (g_blockEventsOnDrag) return FALSE;
if ((gdk_event->keyval != GDK_Up) &&
(gdk_event->keyval != GDK_Down) &&
(gdk_event->keyval != GDK_Left) &&
(gdk_event->keyval != GDK_Right))
{
return FALSE;
}
wxNode *node = rb->m_boxes.Find( (wxObject*) widget );
if (!node)
{
return FALSE;
}
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
if ((gdk_event->keyval == GDK_Up) ||
(gdk_event->keyval == GDK_Left))
{
if (node == rb->m_boxes.First())
node = rb->m_boxes.Last();
else
node = node->Previous();
}
else
{
if (node == rb->m_boxes.Last())
node = rb->m_boxes.First();
else
node = node->Next();
}
GtkWidget *button = (GtkWidget*) node->Data();
gtk_widget_grab_focus( button );
return TRUE;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxRadioBox // wxRadioBox
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -111,6 +162,9 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) ); m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) );
gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );
m_boxes.Append( (wxObject*) m_radio ); m_boxes.Append( (wxObject*) m_radio );
ConnectWidget( GTK_WIDGET(m_radio) ); ConnectWidget( GTK_WIDGET(m_radio) );

View File

@ -50,7 +50,10 @@ bool wxStaticBox::Create( wxWindow *parent, wxWindowID id, const wxString &label
m_isStaticBox = TRUE; m_isStaticBox = TRUE;
m_widget = gtk_frame_new(m_label.mbc_str()); if (label.IsEmpty())
m_widget = gtk_frame_new( (char*) NULL );
else
m_widget = gtk_frame_new( m_label.mbc_str() );
m_parent->DoAddChild( this ); m_parent->DoAddChild( this );

View File

@ -62,6 +62,57 @@ static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRad
rb->GetEventHandler()->ProcessEvent(event); rb->GetEventHandler()->ProcessEvent(event);
} }
//-----------------------------------------------------------------------------
// "key_press_event"
//-----------------------------------------------------------------------------
static gint gtk_radiobox_keypress_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxRadioBox *rb )
{
if (g_isIdle)
wxapp_install_idle_handler();
if (!rb->m_hasVMT) return FALSE;
if (g_blockEventsOnDrag) return FALSE;
if ((gdk_event->keyval != GDK_Up) &&
(gdk_event->keyval != GDK_Down) &&
(gdk_event->keyval != GDK_Left) &&
(gdk_event->keyval != GDK_Right))
{
return FALSE;
}
wxNode *node = rb->m_boxes.Find( (wxObject*) widget );
if (!node)
{
return FALSE;
}
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
if ((gdk_event->keyval == GDK_Up) ||
(gdk_event->keyval == GDK_Left))
{
if (node == rb->m_boxes.First())
node = rb->m_boxes.Last();
else
node = node->Previous();
}
else
{
if (node == rb->m_boxes.Last())
node = rb->m_boxes.First();
else
node = node->Next();
}
GtkWidget *button = (GtkWidget*) node->Data();
gtk_widget_grab_focus( button );
return TRUE;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxRadioBox // wxRadioBox
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -111,6 +162,9 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) ); m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, label.mbc_str() ) );
gtk_signal_connect( GTK_OBJECT(m_radio), "key_press_event",
GTK_SIGNAL_FUNC(gtk_radiobox_keypress_callback), (gpointer)this );
m_boxes.Append( (wxObject*) m_radio ); m_boxes.Append( (wxObject*) m_radio );
ConnectWidget( GTK_WIDGET(m_radio) ); ConnectWidget( GTK_WIDGET(m_radio) );

View File

@ -50,7 +50,10 @@ bool wxStaticBox::Create( wxWindow *parent, wxWindowID id, const wxString &label
m_isStaticBox = TRUE; m_isStaticBox = TRUE;
m_widget = gtk_frame_new(m_label.mbc_str()); if (label.IsEmpty())
m_widget = gtk_frame_new( (char*) NULL );
else
m_widget = gtk_frame_new( m_label.mbc_str() );
m_parent->DoAddChild( this ); m_parent->DoAddChild( this );

View File

@ -48,6 +48,14 @@
#include "wx/fontutil.h" #include "wx/fontutil.h"
#include "wx/fontmap.h" #include "wx/fontmap.h"
#include "wx/tokenzr.h" #include "wx/tokenzr.h"
#include "wx/hash.h"
#include "wx/module.h"
// ----------------------------------------------------------------------------
// private data
// ----------------------------------------------------------------------------
static wxHashTable *g_fontHash = (wxHashTable*) NULL;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// private functions // private functions
@ -324,7 +332,16 @@ static bool wxTestFontSpec(const wxString& fontspec)
return TRUE; return TRUE;
} }
wxNativeFont test = wxLoadFont(fontspec); wxNativeFont test = (wxNativeFont) g_fontHash->Get( fontspec );
if (test)
{
// printf( "speed up\n" );
return TRUE;
}
test = wxLoadFont(fontspec);
g_fontHash->Put( fontspec, (wxObject*) test );
if ( test ) if ( test )
{ {
wxFreeFont(test); wxFreeFont(test);
@ -484,3 +501,32 @@ static wxNativeFont wxLoadQueryFont(int pointSize,
return wxLoadFont(fontSpec); return wxLoadFont(fontSpec);
} }
// ----------------------------------------------------------------------------
// wxFontModule
// ----------------------------------------------------------------------------
class wxFontModule : public wxModule
{
public:
bool OnInit();
void OnExit();
private:
DECLARE_DYNAMIC_CLASS(wxFontModule)
};
IMPLEMENT_DYNAMIC_CLASS(wxFontModule, wxModule)
bool wxFontModule::OnInit()
{
g_fontHash = new wxHashTable( wxKEY_STRING );
return TRUE;
}
void wxFontModule::OnExit()
{
delete g_fontHash;
g_fontHash = (wxHashTable *)NULL;
}