From 2e0e025ecd13ae6d1470e72b428e934748ce66d6 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 21 Nov 1999 11:32:06 +0000 Subject: [PATCH] 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 --- samples/controls/controls.cpp | 2 +- src/gtk/radiobox.cpp | 54 +++++++++++++++++++++++++++++++++++ src/gtk/statbox.cpp | 5 +++- src/gtk1/radiobox.cpp | 54 +++++++++++++++++++++++++++++++++++ src/gtk1/statbox.cpp | 5 +++- src/unix/fontutil.cpp | 48 ++++++++++++++++++++++++++++++- 6 files changed, 164 insertions(+), 4 deletions(-) diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index a12beef3b6..a7c43c9165 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -714,7 +714,7 @@ void MyPanel::OnChangeColour(wxCommandEvent& WXUNUSED(event)) void MyPanel::OnListBox( wxCommandEvent &event ) { - GetParent()->Move(100, 100); +// GetParent()->Move(100, 100); wxListBox *listbox = event.GetId() == ID_LISTBOX ? m_listbox : m_listboxSorted; diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index 05dde830a4..ec667046fe 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -62,6 +62,57 @@ static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRad 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 //----------------------------------------------------------------------------- @@ -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() ) ); + 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 ); ConnectWidget( GTK_WIDGET(m_radio) ); diff --git a/src/gtk/statbox.cpp b/src/gtk/statbox.cpp index d6a4a6852b..b7697b9ce7 100644 --- a/src/gtk/statbox.cpp +++ b/src/gtk/statbox.cpp @@ -50,7 +50,10 @@ bool wxStaticBox::Create( wxWindow *parent, wxWindowID id, const wxString &label 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 ); diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index 05dde830a4..ec667046fe 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -62,6 +62,57 @@ static void gtk_radiobutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxRad 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 //----------------------------------------------------------------------------- @@ -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() ) ); + 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 ); ConnectWidget( GTK_WIDGET(m_radio) ); diff --git a/src/gtk1/statbox.cpp b/src/gtk1/statbox.cpp index d6a4a6852b..b7697b9ce7 100644 --- a/src/gtk1/statbox.cpp +++ b/src/gtk1/statbox.cpp @@ -50,7 +50,10 @@ bool wxStaticBox::Create( wxWindow *parent, wxWindowID id, const wxString &label 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 ); diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index d1af8fa759..62b8e604f5 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -48,6 +48,14 @@ #include "wx/fontutil.h" #include "wx/fontmap.h" #include "wx/tokenzr.h" +#include "wx/hash.h" +#include "wx/module.h" + +// ---------------------------------------------------------------------------- +// private data +// ---------------------------------------------------------------------------- + +static wxHashTable *g_fontHash = (wxHashTable*) NULL; // ---------------------------------------------------------------------------- // private functions @@ -324,7 +332,16 @@ static bool wxTestFontSpec(const wxString& fontspec) 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 ) { wxFreeFont(test); @@ -484,3 +501,32 @@ static wxNativeFont wxLoadQueryFont(int pointSize, 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; +} -- 2.47.2