Some work on tabbing and menu accels,

Added a missing "Activate()" to docvwmdi sample.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4271 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-10-30 15:08:33 +00:00
parent cb36238601
commit 354aa1e366
18 changed files with 292 additions and 156 deletions

View File

@ -30,7 +30,7 @@ public:
~wxMenuItem(); ~wxMenuItem();
// implement base class virtuals // implement base class virtuals
virtual void SetText( const wxString& str ) { DoSetText(str); } virtual void SetText( const wxString& str );
virtual void Enable( bool enable = TRUE ); virtual void Enable( bool enable = TRUE );
virtual void Check( bool check = TRUE ); virtual void Check( bool check = TRUE );
virtual bool IsChecked() const; virtual bool IsChecked() const;
@ -38,6 +38,7 @@ public:
// implementation // implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; } GtkWidget *GetMenuItem() const { return m_menuItem; }
wxString GetFactoryPath() const;
wxString GetHotKey() const { return m_hotKey; } wxString GetHotKey() const { return m_hotKey; }

View File

@ -30,7 +30,7 @@ public:
~wxMenuItem(); ~wxMenuItem();
// implement base class virtuals // implement base class virtuals
virtual void SetText( const wxString& str ) { DoSetText(str); } virtual void SetText( const wxString& str );
virtual void Enable( bool enable = TRUE ); virtual void Enable( bool enable = TRUE );
virtual void Check( bool check = TRUE ); virtual void Check( bool check = TRUE );
virtual bool IsChecked() const; virtual bool IsChecked() const;
@ -38,6 +38,7 @@ public:
// implementation // implementation
void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; } void SetMenuItem(GtkWidget *menuItem) { m_menuItem = menuItem; }
GtkWidget *GetMenuItem() const { return m_menuItem; } GtkWidget *GetMenuItem() const { return m_menuItem; }
wxString GetFactoryPath() const;
wxString GetHotKey() const { return m_hotKey; } wxString GetHotKey() const { return m_hotKey; }

View File

@ -407,10 +407,10 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
wxPanel *panel = new wxPanel(m_notebook); wxPanel *panel = new wxPanel(m_notebook);
m_listbox = new wxListBox( panel, ID_LISTBOX, m_listbox = new wxListBox( panel, ID_LISTBOX,
wxPoint(10,10), wxSize(120,70), wxPoint(10,10), wxSize(120,70),
5, choices, wxLB_ALWAYS_SB | wxLB_MULTIPLE ); 5, choices, wxLB_ALWAYS_SB );
m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED, m_listboxSorted = new wxListBox( panel, ID_LISTBOX_SORTED,
wxPoint(10,90), wxSize(120,70), wxPoint(10,90), wxSize(120,70),
5, choices, wxLB_SORT | wxLB_EXTENDED ); 5, choices, wxLB_SORT );
SetControlClientData("listbox", m_listbox); SetControlClientData("listbox", m_listbox);
SetControlClientData("listbox", m_listboxSorted); SetControlClientData("listbox", m_listboxSorted);

View File

@ -871,10 +871,13 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{ {
// start drag operation // start drag operation
wxTextDataObject textData(m_strText); wxTextDataObject textData(m_strText);
wxDropSource source(textData, this, wxDropSource source(textData, this
wxCURSOR_PENCIL, // for copy #ifdef __WXMSW__
,wxCURSOR_PENCIL, // for copy
wxCURSOR_SPRAYCAN, // for move wxCURSOR_SPRAYCAN, // for move
wxCURSOR_QUESTION_ARROW); // for nothing wxCURSOR_QUESTION_ARROW // for nothing
#endif
);
const char *pc; const char *pc;

View File

@ -57,6 +57,7 @@ bool DrawingView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
frame->SetSize(-1, -1, x, y); frame->SetSize(-1, -1, x, y);
#endif #endif
frame->Show(TRUE); frame->Show(TRUE);
Activate(TRUE);
return TRUE; return TRUE;
} }

View File

@ -20,19 +20,20 @@
class MyCanvas: public wxScrolledWindow class MyCanvas: public wxScrolledWindow
{ {
public: public:
wxView *view; wxView *view;
MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style); MyCanvas(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style);
virtual void OnDraw(wxDC& dc); virtual void OnDraw(wxDC& dc);
void OnMouseEvent(wxMouseEvent& event); void OnMouseEvent(wxMouseEvent& event);
DECLARE_EVENT_TABLE() private:
DECLARE_EVENT_TABLE()
}; };
class MyTextWindow: public wxTextCtrl class MyTextWindow: public wxTextCtrl
{ {
public: public:
wxView *view; wxView *view;
MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style); MyTextWindow(wxView *v, wxFrame *frame, const wxPoint& pos, const wxSize& size, long style);
@ -40,40 +41,41 @@ class MyTextWindow: public wxTextCtrl
class DrawingView: public wxView class DrawingView: public wxView
{ {
DECLARE_DYNAMIC_CLASS(DrawingView) public:
private: wxFrame *frame;
public: MyCanvas *canvas;
wxFrame *frame;
MyCanvas *canvas;
DrawingView(void) { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; }; DrawingView() { canvas = (MyCanvas *) NULL; frame = (wxFrame *) NULL; }
~DrawingView(void) {}; ~DrawingView() {}
bool OnCreate(wxDocument *doc, long flags); bool OnCreate(wxDocument *doc, long flags);
void OnDraw(wxDC *dc); void OnDraw(wxDC *dc);
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
bool OnClose(bool deleteWindow = TRUE); bool OnClose(bool deleteWindow = TRUE);
void OnCut(wxCommandEvent& event); void OnCut(wxCommandEvent& event);
DECLARE_EVENT_TABLE() private:
DECLARE_DYNAMIC_CLASS(DrawingView)
DECLARE_EVENT_TABLE()
}; };
class TextEditView: public wxView class TextEditView: public wxView
{ {
DECLARE_DYNAMIC_CLASS(TextEditView) public:
private: wxFrame *frame;
public: MyTextWindow *textsw;
wxFrame *frame;
MyTextWindow *textsw;
TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; } TextEditView(): wxView() { frame = (wxFrame *) NULL; textsw = (MyTextWindow *) NULL; }
~TextEditView(void) {} ~TextEditView() {}
bool OnCreate(wxDocument *doc, long flags); bool OnCreate(wxDocument *doc, long flags);
void OnDraw(wxDC *dc); void OnDraw(wxDC *dc);
void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL); void OnUpdate(wxView *sender, wxObject *hint = (wxObject *) NULL);
bool OnClose(bool deleteWindow = TRUE); bool OnClose(bool deleteWindow = TRUE);
private:
DECLARE_DYNAMIC_CLASS(TextEditView)
}; };
#endif #endif

View File

@ -80,16 +80,37 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
return FALSE; return FALSE;
} }
/*
m_widget = gtk_button_new_with_label( "" ); wxString label2( label );
for (size_t i = 0; i < label2.Len(); i++)
{
if (label2.GetChar(i) == wxT('&'))
label2.SetChar(i,wxT('_'));
}
GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
gtk_widget_show( accel_label );
m_widget = gtk_button_new();
gtk_container_add( GTK_CONTAINER(m_widget), accel_label );
gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget );
guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() );
gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) );
wxControl::SetLabel( label );
*/
m_widget = gtk_button_new_with_label("");
SetLabel( label );
#if (GTK_MINOR_VERSION > 0) #if (GTK_MINOR_VERSION > 0)
if (style & wxNO_BORDER) if (style & wxNO_BORDER)
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
#endif #endif
SetLabel(label);
int x = 0; int y = 0; int x = 0; int y = 0;
wxFont new_font( parent->GetFont() ); wxFont new_font( parent->GetFont() );
GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font ); GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font );

View File

@ -26,12 +26,9 @@
#include "wx/tooltip.h" #include "wx/tooltip.h"
#endif #endif
#if wxUSE_DRAG_AND_DROP
#include "wx/dnd.h"
#endif
#include "gdk/gdk.h" #include "gdk/gdk.h"
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "gdk/gdkkeysyms.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// idle system // idle system
@ -170,32 +167,52 @@ gtk_listbox_button_press_callback( GtkWidget *widget,
// "key_press_event" // "key_press_event"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if wxUSE_CHECKLISTBOX
static gint static gint
gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox )
{ {
if (g_isIdle) wxapp_install_idle_handler(); if (g_isIdle)
wxapp_install_idle_handler();
if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnDrag)
return FALSE;
if (!listbox->m_hasVMT) return FALSE; bool ret = FALSE;
if (gdk_event->keyval != ' ') return FALSE; if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
{
wxNavigationKeyEvent new_event;
/* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
/* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
new_event.SetCurrentFocus( listbox );
ret = listbox->GetEventHandler()->ProcessEvent( new_event );
}
#if wxUSE_CHECKLISTBOX
if ((gdk_event->keyval != ' ') && (listbox->m_hasCheckBoxes) && (!ret))
{
int sel = listbox->GtkGetIndex( widget );
int sel = listbox->GtkGetIndex( widget ); wxCheckListBox *clb = (wxCheckListBox *)listbox;
wxCheckListBox *clb = (wxCheckListBox *)listbox; clb->Check( sel, !clb->IsChecked(sel) );
clb->Check( sel, !clb->IsChecked(sel) ); wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
new_event.SetEventObject( listbox );
new_event.SetInt( sel );
ret = listbox->GetEventHandler()->ProcessEvent( new_event );
}
#endif // wxUSE_CHECKLISTBOX
wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); if (ret)
event.SetEventObject( listbox ); {
event.SetInt( sel ); gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
listbox->GetEventHandler()->ProcessEvent( event ); return TRUE;
}
return FALSE; return FALSE;
} }
#endif // wxUSE_CHECKLISTBOX
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "select" and "deselect" // "select" and "deselect"
@ -461,15 +478,10 @@ void wxListBox::GtkAddItem( const wxString &item, int pos )
(GtkSignalFunc)gtk_listbox_button_release_callback, (GtkSignalFunc)gtk_listbox_button_release_callback,
(gpointer) this ); (gpointer) this );
#if wxUSE_CHECKLISTBOX gtk_signal_connect( GTK_OBJECT(list_item),
if (m_hasCheckBoxes)
{
gtk_signal_connect( GTK_OBJECT(list_item),
"key_press_event", "key_press_event",
(GtkSignalFunc)gtk_listbox_key_press_callback, (GtkSignalFunc)gtk_listbox_key_press_callback,
(gpointer)this ); (gpointer)this );
}
#endif // wxUSE_CHECKLISTBOX
gtk_widget_show( list_item ); gtk_widget_show( list_item );

View File

@ -561,7 +561,6 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu,
m_menuItem = (GtkWidget *) NULL; m_menuItem = (GtkWidget *) NULL;
// call it after initializing m_menuItem to NULL
DoSetText(text); DoSetText(text);
} }
@ -570,6 +569,23 @@ wxMenuItem::~wxMenuItem()
// don't delete menu items, the menus take care of that // don't delete menu items, the menus take care of that
} }
void wxMenuItem::SetText( const wxString& str )
{
DoSetText(str);
if (m_menuItem)
{
GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
/* set new text */
gtk_label_set( label, m_text.mb_str());
/* reparse key accel */
guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() );
gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) );
}
}
// it's valid for this function to be called even if m_menuItem == NULL // it's valid for this function to be called even if m_menuItem == NULL
void wxMenuItem::DoSetText( const wxString& str ) void wxMenuItem::DoSetText( const wxString& str )
{ {
@ -593,7 +609,7 @@ void wxMenuItem::DoSetText( const wxString& str )
#endif #endif
} }
else else
m_text << *pc; m_text << *pc;
} }
/* only GTK 1.2 knows about hot keys */ /* only GTK 1.2 knows about hot keys */
@ -605,12 +621,6 @@ void wxMenuItem::DoSetText( const wxString& str )
m_hotKey = pc; m_hotKey = pc;
} }
#endif #endif
if (m_menuItem)
{
GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
gtk_label_set( label, m_text.mb_str());
}
} }
void wxMenuItem::Check( bool check ) void wxMenuItem::Check( bool check )
@ -644,6 +654,19 @@ bool wxMenuItem::IsChecked() const
return ((GtkCheckMenuItem*)m_menuItem)->active != 0; return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
} }
wxString wxMenuItem::GetFactoryPath() const
{
/* in order to get the pointer to the item we need the item text _without_ underscores */
wxString path( wxT("<main>/") );
for ( const wxChar *pc = m_text; *pc != wxT('\0'); pc++ )
{
while (*pc == wxT('_')) pc++; /* skip it */
path << *pc;
}
return path;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenu // wxMenu
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -848,20 +871,13 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool
strncpy(s_accel, GetHotKey(*mitem).mb_str(), WXSIZEOF(s_accel)); strncpy(s_accel, GetHotKey(*mitem).mb_str(), WXSIZEOF(s_accel));
entry.accelerator = s_accel; entry.accelerator = s_accel;
#else #else
entry.accelerator = NULL; entry.accelerator = (char*) NULL;
#endif #endif
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */ wxString path( mitem->GetFactoryPath() );
wxString s = wxT("<main>/"); GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() );
for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ )
{
while (*pc == wxT('_')) pc++; /* skip it */
s << *pc;
}
GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() );
#else #else
@ -911,15 +927,8 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */ wxString path( mitem->GetFactoryPath() );
wxString s = wxT("<main>/"); GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() );
for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ )
{
if (*pc == wxT('_')) pc++; /* skip it */
s << *pc;
}
GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, s.mb_str() );
#else #else
@ -990,6 +999,8 @@ void wxMenu::Delete( int id )
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetId() == id) if (item->GetId() == id)
{ {
/* TODO: this code doesn't delete the item factory item and
this seems impossible as of GTK 1.2.6. */
gtk_widget_destroy( item->GetMenuItem() ); gtk_widget_destroy( item->GetMenuItem() );
m_items.DeleteNode( node ); m_items.DeleteNode( node );
return; return;

View File

@ -20,6 +20,7 @@
#include "gdk/gdk.h" #include "gdk/gdk.h"
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "gdk/gdkkeysyms.h"
#include "wx/gtk/win_gtk.h" #include "wx/gtk/win_gtk.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -117,7 +118,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow), gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow),
GTK_WIDGET(m_radio), GTK_WIDGET(m_radio),

View File

@ -97,6 +97,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
const wxString& name) const wxString& name)
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
wxSize new_size = size; wxSize new_size = size;
if (new_size.y == -1) if (new_size.y == -1)

View File

@ -2486,19 +2486,37 @@ void wxWindow::SetFocus()
{ {
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
GtkWidget *connect_widget = GetConnectWidget(); wxNode *node = m_children.First();
if (connect_widget) while (node)
{ {
if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) wxWindow *child = (wxWindow*) node->Data();
if (child->AcceptsFocus())
{
child->SetFocus();
return;
}
node = node->Next();
}
if (m_wxwindow)
{
gtk_widget_grab_focus (m_wxwindow);
return;
}
if (m_widget)
{
if (GTK_WIDGET_CAN_FOCUS(m_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
{ {
gtk_widget_grab_focus (connect_widget); gtk_widget_grab_focus (m_widget);
} }
else if (GTK_IS_CONTAINER(connect_widget)) else if (GTK_IS_CONTAINER(m_widget))
{ {
gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD ); gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD );
} }
else else
{ {
// ?
} }
} }
} }

View File

@ -80,16 +80,37 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
return FALSE; return FALSE;
} }
/*
m_widget = gtk_button_new_with_label( "" ); wxString label2( label );
for (size_t i = 0; i < label2.Len(); i++)
{
if (label2.GetChar(i) == wxT('&'))
label2.SetChar(i,wxT('_'));
}
GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
gtk_widget_show( accel_label );
m_widget = gtk_button_new();
gtk_container_add( GTK_CONTAINER(m_widget), accel_label );
gtk_accel_label_set_accel_widget( GTK_ACCEL_LABEL(accel_label), m_widget );
guint accel_key = gtk_label_parse_uline (GTK_LABEL(accel_label), label2.mb_str() );
gtk_accel_label_refetch( GTK_ACCEL_LABEL(accel_label) );
wxControl::SetLabel( label );
*/
m_widget = gtk_button_new_with_label("");
SetLabel( label );
#if (GTK_MINOR_VERSION > 0) #if (GTK_MINOR_VERSION > 0)
if (style & wxNO_BORDER) if (style & wxNO_BORDER)
gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE ); gtk_button_set_relief( GTK_BUTTON(m_widget), GTK_RELIEF_NONE );
#endif #endif
SetLabel(label);
int x = 0; int y = 0; int x = 0; int y = 0;
wxFont new_font( parent->GetFont() ); wxFont new_font( parent->GetFont() );
GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font ); GetTextExtent( m_label, &x, &y, (int*)NULL, (int*)NULL, &new_font );

View File

@ -26,12 +26,9 @@
#include "wx/tooltip.h" #include "wx/tooltip.h"
#endif #endif
#if wxUSE_DRAG_AND_DROP
#include "wx/dnd.h"
#endif
#include "gdk/gdk.h" #include "gdk/gdk.h"
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "gdk/gdkkeysyms.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// idle system // idle system
@ -170,32 +167,52 @@ gtk_listbox_button_press_callback( GtkWidget *widget,
// "key_press_event" // "key_press_event"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#if wxUSE_CHECKLISTBOX
static gint static gint
gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox ) gtk_listbox_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxListBox *listbox )
{ {
if (g_isIdle) wxapp_install_idle_handler(); if (g_isIdle)
wxapp_install_idle_handler();
if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnDrag)
return FALSE;
if (!listbox->m_hasVMT) return FALSE; bool ret = FALSE;
if (gdk_event->keyval != ' ') return FALSE; if ((gdk_event->keyval == GDK_Tab) || (gdk_event->keyval == GDK_ISO_Left_Tab))
{
wxNavigationKeyEvent new_event;
/* GDK reports GDK_ISO_Left_Tab for SHIFT-TAB */
new_event.SetDirection( (gdk_event->keyval == GDK_Tab) );
/* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
new_event.SetWindowChange( (gdk_event->state & GDK_CONTROL_MASK) );
new_event.SetCurrentFocus( listbox );
ret = listbox->GetEventHandler()->ProcessEvent( new_event );
}
#if wxUSE_CHECKLISTBOX
if ((gdk_event->keyval != ' ') && (listbox->m_hasCheckBoxes) && (!ret))
{
int sel = listbox->GtkGetIndex( widget );
int sel = listbox->GtkGetIndex( widget ); wxCheckListBox *clb = (wxCheckListBox *)listbox;
wxCheckListBox *clb = (wxCheckListBox *)listbox; clb->Check( sel, !clb->IsChecked(sel) );
clb->Check( sel, !clb->IsChecked(sel) ); wxCommandEvent new_event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() );
new_event.SetEventObject( listbox );
new_event.SetInt( sel );
ret = listbox->GetEventHandler()->ProcessEvent( new_event );
}
#endif // wxUSE_CHECKLISTBOX
wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, listbox->GetId() ); if (ret)
event.SetEventObject( listbox ); {
event.SetInt( sel ); gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
listbox->GetEventHandler()->ProcessEvent( event ); return TRUE;
}
return FALSE; return FALSE;
} }
#endif // wxUSE_CHECKLISTBOX
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "select" and "deselect" // "select" and "deselect"
@ -461,15 +478,10 @@ void wxListBox::GtkAddItem( const wxString &item, int pos )
(GtkSignalFunc)gtk_listbox_button_release_callback, (GtkSignalFunc)gtk_listbox_button_release_callback,
(gpointer) this ); (gpointer) this );
#if wxUSE_CHECKLISTBOX gtk_signal_connect( GTK_OBJECT(list_item),
if (m_hasCheckBoxes)
{
gtk_signal_connect( GTK_OBJECT(list_item),
"key_press_event", "key_press_event",
(GtkSignalFunc)gtk_listbox_key_press_callback, (GtkSignalFunc)gtk_listbox_key_press_callback,
(gpointer)this ); (gpointer)this );
}
#endif // wxUSE_CHECKLISTBOX
gtk_widget_show( list_item ); gtk_widget_show( list_item );

View File

@ -561,7 +561,6 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu,
m_menuItem = (GtkWidget *) NULL; m_menuItem = (GtkWidget *) NULL;
// call it after initializing m_menuItem to NULL
DoSetText(text); DoSetText(text);
} }
@ -570,6 +569,23 @@ wxMenuItem::~wxMenuItem()
// don't delete menu items, the menus take care of that // don't delete menu items, the menus take care of that
} }
void wxMenuItem::SetText( const wxString& str )
{
DoSetText(str);
if (m_menuItem)
{
GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
/* set new text */
gtk_label_set( label, m_text.mb_str());
/* reparse key accel */
guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() );
gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) );
}
}
// it's valid for this function to be called even if m_menuItem == NULL // it's valid for this function to be called even if m_menuItem == NULL
void wxMenuItem::DoSetText( const wxString& str ) void wxMenuItem::DoSetText( const wxString& str )
{ {
@ -593,7 +609,7 @@ void wxMenuItem::DoSetText( const wxString& str )
#endif #endif
} }
else else
m_text << *pc; m_text << *pc;
} }
/* only GTK 1.2 knows about hot keys */ /* only GTK 1.2 knows about hot keys */
@ -605,12 +621,6 @@ void wxMenuItem::DoSetText( const wxString& str )
m_hotKey = pc; m_hotKey = pc;
} }
#endif #endif
if (m_menuItem)
{
GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
gtk_label_set( label, m_text.mb_str());
}
} }
void wxMenuItem::Check( bool check ) void wxMenuItem::Check( bool check )
@ -644,6 +654,19 @@ bool wxMenuItem::IsChecked() const
return ((GtkCheckMenuItem*)m_menuItem)->active != 0; return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
} }
wxString wxMenuItem::GetFactoryPath() const
{
/* in order to get the pointer to the item we need the item text _without_ underscores */
wxString path( wxT("<main>/") );
for ( const wxChar *pc = m_text; *pc != wxT('\0'); pc++ )
{
while (*pc == wxT('_')) pc++; /* skip it */
path << *pc;
}
return path;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenu // wxMenu
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -848,20 +871,13 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool
strncpy(s_accel, GetHotKey(*mitem).mb_str(), WXSIZEOF(s_accel)); strncpy(s_accel, GetHotKey(*mitem).mb_str(), WXSIZEOF(s_accel));
entry.accelerator = s_accel; entry.accelerator = s_accel;
#else #else
entry.accelerator = NULL; entry.accelerator = (char*) NULL;
#endif #endif
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */ wxString path( mitem->GetFactoryPath() );
wxString s = wxT("<main>/"); GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() );
for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ )
{
while (*pc == wxT('_')) pc++; /* skip it */
s << *pc;
}
GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() );
#else #else
@ -911,15 +927,8 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */ wxString path( mitem->GetFactoryPath() );
wxString s = wxT("<main>/"); GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() );
for ( const wxChar *pc = text; *pc != wxT('\0'); pc++ )
{
if (*pc == wxT('_')) pc++; /* skip it */
s << *pc;
}
GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, s.mb_str() );
#else #else
@ -990,6 +999,8 @@ void wxMenu::Delete( int id )
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->GetId() == id) if (item->GetId() == id)
{ {
/* TODO: this code doesn't delete the item factory item and
this seems impossible as of GTK 1.2.6. */
gtk_widget_destroy( item->GetMenuItem() ); gtk_widget_destroy( item->GetMenuItem() );
m_items.DeleteNode( node ); m_items.DeleteNode( node );
return; return;

View File

@ -20,6 +20,7 @@
#include "gdk/gdk.h" #include "gdk/gdk.h"
#include "gtk/gtk.h" #include "gtk/gtk.h"
#include "gdk/gdkkeysyms.h"
#include "wx/gtk/win_gtk.h" #include "wx/gtk/win_gtk.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -117,7 +118,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE );
gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", gtk_signal_connect( GTK_OBJECT(m_radio), "clicked",
GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this );
gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow), gtk_pizza_put( GTK_PIZZA(m_parent->m_wxwindow),
GTK_WIDGET(m_radio), GTK_WIDGET(m_radio),

View File

@ -97,6 +97,7 @@ bool wxSpinCtrl::Create(wxWindow *parent, wxWindowID id,
const wxString& name) const wxString& name)
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
wxSize new_size = size; wxSize new_size = size;
if (new_size.y == -1) if (new_size.y == -1)

View File

@ -2486,19 +2486,37 @@ void wxWindow::SetFocus()
{ {
wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); wxCHECK_RET( (m_widget != NULL), wxT("invalid window") );
GtkWidget *connect_widget = GetConnectWidget(); wxNode *node = m_children.First();
if (connect_widget) while (node)
{ {
if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ ) wxWindow *child = (wxWindow*) node->Data();
if (child->AcceptsFocus())
{
child->SetFocus();
return;
}
node = node->Next();
}
if (m_wxwindow)
{
gtk_widget_grab_focus (m_wxwindow);
return;
}
if (m_widget)
{
if (GTK_WIDGET_CAN_FOCUS(m_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
{ {
gtk_widget_grab_focus (connect_widget); gtk_widget_grab_focus (m_widget);
} }
else if (GTK_IS_CONTAINER(connect_widget)) else if (GTK_IS_CONTAINER(m_widget))
{ {
gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD ); gtk_container_focus( GTK_CONTAINER(m_widget), GTK_DIR_TAB_FORWARD );
} }
else else
{ {
// ?
} }
} }
} }