I've put live into Vadim's wxNavigationKeyEvent idea

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1212 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1998-12-17 08:40:34 +00:00
parent 105e45b9d0
commit b292e2f512
42 changed files with 1038 additions and 624 deletions

View File

@@ -624,6 +624,8 @@ class wxListCtrl: public wxControl
else return wxColour(); } else return wxColour(); }
bool PopupMenu( wxMenu *menu, int x, int y ) bool PopupMenu( wxMenu *menu, int x, int y )
{ return m_mainWin->PopupMenu( menu, x, y ); } { return m_mainWin->PopupMenu( menu, x, y ); }
void SetFocus()
{ m_mainWin->SetFocus(); }
// implementation // implementation

View File

@@ -20,7 +20,7 @@
WXDLLEXPORT_DATA(extern const char*) wxPanelNameStr; WXDLLEXPORT_DATA(extern const char*) wxPanelNameStr;
// Dialog boxes
class WXDLLEXPORT wxPanel: public wxWindow class WXDLLEXPORT wxPanel: public wxWindow
{ {
public: public:
@@ -56,17 +56,12 @@ public:
// to the dialog via validators. // to the dialog via validators.
virtual void InitDialog(); virtual void InitDialog();
// overriden base class virtuals
virtual void SetFocus();
// callbacks
// Responds to colour changes // Responds to colour changes
void OnSysColourChanged(wxSysColourChangedEvent& event); void OnSysColourChanged(wxSysColourChangedEvent& event);
// Process a keyboard navigation message (Tab traversal) // Process a keyboard navigation message (Tab traversal)
void OnNavigationKey(wxNavigationKeyEvent& event); void OnNavigationKey(wxNavigationKeyEvent& event);
protected:
bool SetFocusToNextChild(wxNode *nodeCurrent = (wxNode *) NULL, bool bForward = TRUE);
DECLARE_DYNAMIC_CLASS(wxPanel) DECLARE_DYNAMIC_CLASS(wxPanel)
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()

View File

@@ -7,7 +7,6 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __GTKCONTROLH__ #ifndef __GTKCONTROLH__
#define __GTKCONTROLH__ #define __GTKCONTROLH__
@@ -46,10 +45,11 @@ public:
// char (the one immediately after '&') into m_chAccel (@@ not yet) // char (the one immediately after '&') into m_chAccel (@@ not yet)
virtual void SetLabel( const wxString &label ); virtual void SetLabel( const wxString &label );
virtual wxString GetLabel() const; virtual wxString GetLabel() const;
protected: protected:
wxString m_label; wxString m_label;
char m_chAccel; // enabled to avoid breaking binary compatibility later on char m_chAccel; // enabled to avoid breaking binary compatibility later on
}; };
#endif // __GTKCONTROLH__ #endif // __GTKCONTROLH__

View File

@@ -146,7 +146,7 @@ public:
// don't delete it yourself). If bSelect, this page becomes active. // don't delete it yourself). If bSelect, this page becomes active.
bool AddPage(wxWindow *pPage, bool AddPage(wxWindow *pPage,
const wxString& strText, const wxString& strText,
bool bSelect = FALSE, bool select = FALSE,
int imageId = -1); int imageId = -1);
// @@@@ VZ: I don't know how to implement InsertPage() // @@@@ VZ: I don't know how to implement InsertPage()

View File

@@ -80,6 +80,7 @@ class wxRadioBox: public wxControl
void SetNumberOfRowsOrCols( int n ); void SetNumberOfRowsOrCols( int n );
void OnSize( wxSizeEvent &event ); void OnSize( wxSizeEvent &event );
void SetFocus();
// implementation // implementation

View File

@@ -88,6 +88,16 @@ private:
wxString m_data; wxString m_data;
}; };
//-----------------------------------------------------------------------------
// (debug)
//-----------------------------------------------------------------------------
#ifdef __WXDEBUG__
void debug_focus_in( GtkWidget* widget, const char* name, const char* window );
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxWindow // wxWindow
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -151,9 +161,11 @@ public:
virtual void MakeModal( bool modal ); virtual void MakeModal( bool modal );
virtual bool IsEnabled() const { return m_isEnabled; } virtual bool IsEnabled() const { return m_isEnabled; }
inline bool Enabled() const { return IsEnabled(); } inline bool Enabled() const { return IsEnabled(); }
virtual void SetFocus();
virtual bool OnClose(); virtual bool OnClose();
virtual void SetFocus();
static wxWindow *FindFocus();
virtual void AddChild( wxWindow *child ); virtual void AddChild( wxWindow *child );
wxList& GetChildren() { return m_children; } wxList& GetChildren() { return m_children; }
@@ -331,6 +343,7 @@ public:
GdkGC *m_scrollGC; GdkGC *m_scrollGC;
GtkStyle *m_widgetStyle; GtkStyle *m_widgetStyle;
bool m_isStaticBox; bool m_isStaticBox;
bool m_acceptsFocus;
wxInsertChildFunction m_insertCallback; wxInsertChildFunction m_insertCallback;

View File

@@ -7,7 +7,6 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef __GTKCONTROLH__ #ifndef __GTKCONTROLH__
#define __GTKCONTROLH__ #define __GTKCONTROLH__
@@ -46,10 +45,11 @@ public:
// char (the one immediately after '&') into m_chAccel (@@ not yet) // char (the one immediately after '&') into m_chAccel (@@ not yet)
virtual void SetLabel( const wxString &label ); virtual void SetLabel( const wxString &label );
virtual wxString GetLabel() const; virtual wxString GetLabel() const;
protected: protected:
wxString m_label; wxString m_label;
char m_chAccel; // enabled to avoid breaking binary compatibility later on char m_chAccel; // enabled to avoid breaking binary compatibility later on
}; };
#endif // __GTKCONTROLH__ #endif // __GTKCONTROLH__

View File

@@ -146,7 +146,7 @@ public:
// don't delete it yourself). If bSelect, this page becomes active. // don't delete it yourself). If bSelect, this page becomes active.
bool AddPage(wxWindow *pPage, bool AddPage(wxWindow *pPage,
const wxString& strText, const wxString& strText,
bool bSelect = FALSE, bool select = FALSE,
int imageId = -1); int imageId = -1);
// @@@@ VZ: I don't know how to implement InsertPage() // @@@@ VZ: I don't know how to implement InsertPage()

View File

@@ -80,6 +80,7 @@ class wxRadioBox: public wxControl
void SetNumberOfRowsOrCols( int n ); void SetNumberOfRowsOrCols( int n );
void OnSize( wxSizeEvent &event ); void OnSize( wxSizeEvent &event );
void SetFocus();
// implementation // implementation

View File

@@ -88,6 +88,16 @@ private:
wxString m_data; wxString m_data;
}; };
//-----------------------------------------------------------------------------
// (debug)
//-----------------------------------------------------------------------------
#ifdef __WXDEBUG__
void debug_focus_in( GtkWidget* widget, const char* name, const char* window );
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxWindow // wxWindow
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -151,9 +161,11 @@ public:
virtual void MakeModal( bool modal ); virtual void MakeModal( bool modal );
virtual bool IsEnabled() const { return m_isEnabled; } virtual bool IsEnabled() const { return m_isEnabled; }
inline bool Enabled() const { return IsEnabled(); } inline bool Enabled() const { return IsEnabled(); }
virtual void SetFocus();
virtual bool OnClose(); virtual bool OnClose();
virtual void SetFocus();
static wxWindow *FindFocus();
virtual void AddChild( wxWindow *child ); virtual void AddChild( wxWindow *child );
wxList& GetChildren() { return m_children; } wxList& GetChildren() { return m_children; }
@@ -331,6 +343,7 @@ public:
GdkGC *m_scrollGC; GdkGC *m_scrollGC;
GtkStyle *m_widgetStyle; GtkStyle *m_widgetStyle;
bool m_isStaticBox; bool m_isStaticBox;
bool m_acceptsFocus;
wxInsertChildFunction m_insertCallback; wxInsertChildFunction m_insertCallback;

View File

@@ -24,9 +24,15 @@
#include "wx/wx.h" #include "wx/wx.h"
#endif #endif
#ifdef __WXMSW__
#include "wx/ownerdrw.h" #include "wx/ownerdrw.h"
#endif
#include "wx/menuitem.h" #include "wx/menuitem.h"
#include "wx/msw/checklst.h" #include "wx/checklst.h"
#ifdef __WXGTK__
#include "mondrian.xpm"
#endif
// Define a new application type // Define a new application type
class CheckListBoxApp: public wxApp class CheckListBoxApp: public wxApp
@@ -89,7 +95,7 @@ CheckListBoxFrame::CheckListBoxFrame(wxFrame *frame, char *title, int x, int y,
: wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) : wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
{ {
// set the icon // set the icon
SetIcon(wxIcon("mondrian")); SetIcon(wxICON(mondrian));
// Make a menubar // Make a menubar
wxMenu *file_menu = new wxMenu; wxMenu *file_menu = new wxMenu;
@@ -127,9 +133,11 @@ CheckListBoxFrame::CheckListBoxFrame(wxFrame *frame, char *title, int x, int y,
delete [] astrChoices; delete [] astrChoices;
#ifdef __WXMSW__
for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) { for ( ui = 0; ui < WXSIZEOF(aszChoices); ui += 2 ) {
m_pListBox->GetItem(ui)->SetBackgroundColour(wxColor(200, 200, 200)); m_pListBox->GetItem(ui)->SetBackgroundColour(wxColor(200, 200, 200));
} }
#endif
m_pListBox->Check(2); m_pListBox->Check(2);
@@ -163,7 +171,7 @@ void CheckListBoxFrame::OnListboxSelect(wxCommandEvent& event)
wxString strSelection; wxString strSelection;
unsigned int nSel = event.GetSelection(); unsigned int nSel = event.GetSelection();
strSelection.sprintf("item %d selected (%schecked)", nSel, strSelection.sprintf("item %d selected (%schecked)", nSel,
m_pListBox->IsChecked(nSel) ? "" : "not "); m_pListBox->IsChecked((int)nSel) ? "" : "not ");
SetStatusText(strSelection); SetStatusText(strSelection);
} }

View File

@@ -2301,7 +2301,7 @@ bool wxListCtrl::Create( wxWindow *parent, wxWindowID id,
m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s ); m_mainWin = new wxListMainWindow( this, -1, wxPoint(0,0), size, s );
if (GetWindowStyleFlag() & wxLC_REPORT) if (GetWindowStyleFlag() & wxLC_REPORT)
m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23) ); m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(size.x,23), wxTAB_TRAVERSAL );
else else
m_headerWin = (wxListHeaderWindow *) NULL; m_headerWin = (wxListHeaderWindow *) NULL;
@@ -2355,7 +2355,7 @@ void wxListCtrl::SetWindowStyleFlag( long flag )
// m_mainWin->SetSize( 0, 24, width, height-24 ); // m_mainWin->SetSize( 0, 24, width, height-24 );
if (!m_headerWin) if (!m_headerWin)
{ {
m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(width,23) ); m_headerWin = new wxListHeaderWindow( this, -1, m_mainWin, wxPoint(0,0), wxSize(width,23), wxTAB_TRAVERSAL );
} }
else else
{ {

View File

@@ -46,28 +46,24 @@ bool wxPanel::Create(wxWindow *parent, wxWindowID id,
long style, long style,
const wxString& name) const wxString& name)
{ {
bool ret = wxWindow::Create(parent, id, pos, size, style, name); bool ret = wxWindow::Create(parent, id, pos, size, style, name);
if ( ret ) { if ( ret )
{
#ifndef __WXGTK__ #ifndef __WXGTK__
SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE)); SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE));
SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
#endif #endif
} }
return ret; return ret;
} }
void wxPanel::InitDialog(void) void wxPanel::InitDialog(void)
{ {
wxInitDialogEvent event(GetId()); wxInitDialogEvent event(GetId());
event.SetEventObject(this); event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event); GetEventHandler()->ProcessEvent(event);
}
void wxPanel::SetFocus()
{
SetFocusToNextChild();
} }
// Responds to colour changes, and passes event on to children. // Responds to colour changes, and passes event on to children.
@@ -80,97 +76,68 @@ void wxPanel::OnSysColourChanged(wxSysColourChangedEvent& event)
wxWindow::OnSysColourChanged(event); wxWindow::OnSysColourChanged(event);
} }
void wxPanel::OnNavigationKey(wxNavigationKeyEvent& event) void wxPanel::OnNavigationKey( wxNavigationKeyEvent& event )
{ {
// don't process these ones here if (m_children.GetCount() < 2)
if ( event.IsWindowChange() ) { {
event.Skip(); event.Skip();
return; return;
} }
// first of all, find the window which currently has the focus // don't process these ones here
wxNode *node = GetChildren().First(); if (event.IsWindowChange())
wxWindow *winFocus = event.GetCurrentFocus(); {
event.Skip();
// @@@ no FindFocus() in wxGTK return;
#ifndef __WXGTK__ }
if ( winFocus == NULL )
winFocus = wxWindow::FindFocus();
#endif
while ( node != NULL ) {
if ( node->Data() == winFocus )
break;
node = node->Next(); wxWindow *winFocus = event.GetCurrentFocus();
} if (!winFocus) winFocus = wxWindow::FindFocus();
if (!winFocus)
{
event.Skip();
return;
}
wxNode *start_node = m_children.Find( winFocus );
if (!start_node) start_node = m_children.First();
wxNode *node = event.GetDirection() ? start_node->Next() : start_node->Previous();
while (node != start_node)
{
if (!node)
{
/*
if (GetParent() != NULL)
{
wxNavigationKeyEvent new_event;
new_event.SetDirection( event.GetDirection() );
new_event.SetWindowChange(FALSE);
new_event.SetCurrentFocus( this );
if ( !SetFocusToNextChild(node, event.GetDirection()) ) if (GetParent()->GetEventHandler()->ProcessEvent(new_event))
{
return;
}
}
*/
node = event.GetDirection() ? m_children.First() : m_children.Last();
}
wxWindow *child = (wxWindow*) node->Data();
if (child->AcceptsFocus())
{
child->SetFocus();
return;
}
node = node->Next();
}
event.Skip(); event.Skip();
} }
// set focus to the next child which accepts it (or first/last if node == NULL)
bool wxPanel::SetFocusToNextChild(wxNode *node, bool bForward)
{
// @@ using typed list would be better...
#define WIN(node) ((wxWindow *)(node->Data()))
bool bFound = FALSE; // have we found a window we will set focus to?
wxList *children = & GetChildren();
if ( node == NULL ) {
// we've never had focus before
node = bForward ? children->First() : children->Last();
if ( node == NULL ) {
// no children
return FALSE;
}
bFound = WIN(node)->AcceptsFocus();
}
#if 0 // to restore when it will really work (now it's triggered all the time)
else {
// just to be sure it's the right one
wxASSERT( WIN(node)->AcceptsFocus() );
}
#endif // 0
// find the next child which accepts focus
bool bParentWantsIt = TRUE;
while ( !bFound ) {
node = bForward ? node->Next() : node->Previous();
if ( node == NULL ) {
if ( !bParentWantsIt ) {
// we've already been here which means that we've done a whole
// cycle without success - get out from the infinite loop
return FALSE;
}
// ask parent if he doesn't want to advance focus to the next panel
if ( GetParent() != NULL ) {
wxNavigationKeyEvent event;
event.SetDirection(bForward);
event.SetWindowChange(FALSE);
event.SetCurrentFocus(this);
if ( GetParent()->ProcessEvent(event) )
return TRUE;
}
// a sentinel to avoid infinite loops
bParentWantsIt = FALSE;
// wrap around
node = bForward ? children->First() : children->Last();
}
bFound = WIN(node)->AcceptsFocus();
}
WIN(node)->SetFocus();
#undef WIN
return TRUE;
}

View File

@@ -84,7 +84,7 @@ bool wxStatusBar::Create(wxWindow *parent, wxWindowID id,
m_borderX = wxTHICK_LINE_BORDER; m_borderX = wxTHICK_LINE_BORDER;
m_borderY = wxTHICK_LINE_BORDER; m_borderY = wxTHICK_LINE_BORDER;
bool success = wxWindow::Create(parent, id, pos, size, style, name); bool success = wxWindow::Create(parent, id, pos, size, style | wxTAB_TRAVERSAL, name);
// Don't wish this to be found as a child // Don't wish this to be found as a child
parent->GetChildren().DeleteObject(this); parent->GetChildren().DeleteObject(this);

View File

@@ -102,6 +102,7 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
wxSize newSize = size; wxSize newSize = size;

View File

@@ -58,37 +58,38 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_clientData = (wxClientData*) NULL; m_clientData = (wxClientData*) NULL;
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
wxSize newSize = size; wxSize newSize = size;
PreCreation( parent, id, pos, newSize, style, name ); PreCreation( parent, id, pos, newSize, style, name );
SetValidator( validator ); SetValidator( validator );
m_widget = gtk_button_new_with_label( m_label ); m_widget = gtk_button_new_with_label( m_label );
SetLabel(label); SetLabel(label);
if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label ); if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
if (newSize.y == -1) newSize.y = 26; if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y ); SetSize( newSize.x, newSize.y );
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); PostCreation();
SetBackgroundColour( parent->GetBackgroundColour() ); SetBackgroundColour( parent->GetBackgroundColour() );
SetForegroundColour( parent->GetForegroundColour() ); SetForegroundColour( parent->GetForegroundColour() );
Show( TRUE ); Show( TRUE );
return TRUE; return TRUE;
} }
void wxButton::SetDefault(void) void wxButton::SetDefault(void)
@@ -101,27 +102,27 @@ void wxButton::SetDefault(void)
void wxButton::SetLabel( const wxString &label ) void wxButton::SetLabel( const wxString &label )
{ {
wxCHECK_RET( m_widget != NULL, "invalid button" ); wxCHECK_RET( m_widget != NULL, "invalid button" );
wxControl::SetLabel( label ); wxControl::SetLabel( label );
gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() ); gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
} }
void wxButton::Enable( bool enable ) void wxButton::Enable( bool enable )
{ {
wxCHECK_RET( m_widget != NULL, "invalid button" ); wxCHECK_RET( m_widget != NULL, "invalid button" );
wxControl::Enable( enable ); wxControl::Enable( enable );
gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable ); gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
} }
void wxButton::ApplyWidgetStyle() void wxButton::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle ); gtk_widget_set_style( m_widget, m_widgetStyle );
gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle ); gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
} }

View File

@@ -26,20 +26,20 @@ extern bool g_blockEventsOnDrag;
static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb ) static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
{ {
if (!cb->HasVMT()) return; if (!cb->HasVMT()) return;
if (cb->m_blockFirstEvent) if (cb->m_blockFirstEvent)
{ {
cb->m_blockFirstEvent = FALSE; cb->m_blockFirstEvent = FALSE;
return; return;
} }
if (g_blockEventsOnDrag) return; if (g_blockEventsOnDrag) return;
wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId()); wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
event.SetInt( cb->GetValue() ); event.SetInt( cb->GetValue() );
event.SetEventObject(cb); event.SetEventObject(cb);
cb->GetEventHandler()->ProcessEvent(event); cb->GetEventHandler()->ProcessEvent(event);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -56,81 +56,82 @@ bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
SetValidator( validator ); SetValidator( validator );
m_widget = gtk_check_button_new_with_label( m_label ); m_widget = gtk_check_button_new_with_label( m_label );
m_blockFirstEvent = FALSE; m_blockFirstEvent = FALSE;
wxSize newSize = size; wxSize newSize = size;
if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label ); if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
if (newSize.y == -1) newSize.y = 26; if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y ); SetSize( newSize.x, newSize.y );
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this ); GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); PostCreation();
gtk_widget_realize( GTK_BUTTON( m_widget )->child ); gtk_widget_realize( GTK_BUTTON( m_widget )->child );
SetLabel( label ); SetLabel( label );
SetBackgroundColour( parent->GetBackgroundColour() ); SetBackgroundColour( parent->GetBackgroundColour() );
SetForegroundColour( parent->GetForegroundColour() ); SetForegroundColour( parent->GetForegroundColour() );
Show( TRUE ); Show( TRUE );
return TRUE; return TRUE;
} }
void wxCheckBox::SetValue( bool state ) void wxCheckBox::SetValue( bool state )
{ {
wxCHECK_RET( m_widget != NULL, "invalid checkbox" ); wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
m_blockFirstEvent = TRUE; m_blockFirstEvent = TRUE;
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state ); gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state );
} }
bool wxCheckBox::GetValue() const bool wxCheckBox::GetValue() const
{ {
wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" ); wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
return GTK_TOGGLE_BUTTON(m_widget)->active; return GTK_TOGGLE_BUTTON(m_widget)->active;
} }
void wxCheckBox::SetLabel( const wxString& label ) void wxCheckBox::SetLabel( const wxString& label )
{ {
wxCHECK_RET( m_widget != NULL, "invalid checkbox" ); wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
wxControl::SetLabel( label ); wxControl::SetLabel( label );
gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() ); gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
} }
void wxCheckBox::Enable( bool enable ) void wxCheckBox::Enable( bool enable )
{ {
wxCHECK_RET( m_widget != NULL, "invalid checkbox" ); wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
wxControl::Enable( enable ); wxControl::Enable( enable );
gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable ); gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
} }
void wxCheckBox::ApplyWidgetStyle() void wxCheckBox::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle ); gtk_widget_set_style( m_widget, m_widgetStyle );
gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle ); gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
} }

View File

@@ -63,6 +63,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
{ {
m_alreadySent = FALSE; m_alreadySent = FALSE;
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );

View File

@@ -21,7 +21,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxControl,wxWindow)
wxControl::wxControl(void) wxControl::wxControl(void)
{ {
m_needParent = TRUE; m_needParent = TRUE;
} }
wxControl::wxControl( wxWindow *parent, wxWindowID id, wxControl::wxControl( wxWindow *parent, wxWindowID id,
@@ -37,24 +37,23 @@ void wxControl::Command( wxCommandEvent &WXUNUSED(event) )
void wxControl::SetLabel( const wxString &label ) void wxControl::SetLabel( const wxString &label )
{ {
m_label = ""; m_label = "";
for ( const char *pc = label; *pc != '\0'; pc++ ) { for ( const char *pc = label; *pc != '\0'; pc++ )
if ( *pc == '&' ) { {
pc++; // skip it if ( *pc == '&' )
{
pc++; // skip it
#if 0 // it would be unused anyhow for now - kbd interface not done yet #if 0 // it would be unused anyhow for now - kbd interface not done yet
if ( *pc != '&' ) if ( *pc != '&' ) m_chAccel = *pc;
m_chAccel = *pc;
#endif #endif
}
m_label << *pc;
} }
m_label << *pc;
}
} }
wxString wxControl::GetLabel(void) const wxString wxControl::GetLabel(void) const
{ {
return m_label; return m_label;
} }

View File

@@ -142,6 +142,10 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
m_widget = gtk_window_new( win_type ); m_widget = gtk_window_new( win_type );
#ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxFrame::m_widget", name );
#endif
if ((size.x != -1) && (size.y != -1)) if ((size.x != -1) && (size.y != -1))
gtk_widget_set_usize( m_widget, m_width, m_height ); gtk_widget_set_usize( m_widget, m_width, m_height );
if ((pos.x != -1) && (pos.y != -1)) if ((pos.x != -1) && (pos.y != -1))
@@ -159,6 +163,10 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
gtk_widget_show( m_wxwindow ); gtk_widget_show( m_wxwindow );
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
#ifdef __WXDEBUG__
debug_focus_in( m_wxwindow, "wxFrame::m_wxwindow", name );
#endif
gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",

View File

@@ -130,6 +130,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
@@ -138,7 +139,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL ); m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget), gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
m_list = GTK_LIST( gtk_list_new() ); m_list = GTK_LIST( gtk_list_new() );
GtkSelectionMode mode = GTK_SELECTION_BROWSE; GtkSelectionMode mode = GTK_SELECTION_BROWSE;
@@ -155,6 +156,25 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) ); gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) );
#endif #endif
#ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxListBox::m_widget", name );
debug_focus_in( GTK_WIDGET(m_list), "wxListBox::m_list", name );
GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget);
debug_focus_in( s_window->hscrollbar, "wxWindow::hsrcollbar", name );
debug_focus_in( s_window->vscrollbar, "wxWindow::vsrcollbar", name );
#ifdef NEW_GTK_SCROLL_CODE
GtkViewport *viewport = GTK_VIEWPORT(s_window->child);
#else
GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
#endif
debug_focus_in( GTK_WIDGET(viewport), "wxWindow::viewport", name );
#endif
gtk_widget_show( GTK_WIDGET(m_list) ); gtk_widget_show( GTK_WIDGET(m_list) );
wxSize newSize = size; wxSize newSize = size;
@@ -180,6 +200,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
list_item = gtk_list_item_new_with_label( choices[i] ); list_item = gtk_list_item_new_with_label( choices[i] );
} }
#ifdef __WXDEBUG__
debug_focus_in( list_item, "wxListBox::list_item", name );
#endif
gtk_container_add( GTK_CONTAINER(m_list), list_item ); gtk_container_add( GTK_CONTAINER(m_list), list_item );
gtk_signal_connect( GTK_OBJECT(list_item), "select", gtk_signal_connect( GTK_OBJECT(list_item), "select",

View File

@@ -17,6 +17,13 @@
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#include "gdk/gdkkeysyms.h"
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxNotebookPage // wxNotebookPage
@@ -72,16 +79,16 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
gint nPage, gint nPage,
gpointer data) gpointer data)
{ {
wxNotebook *notebook = (wxNotebook *)data; wxNotebook *notebook = (wxNotebook *)data;
int old = notebook->GetSelection(); int old = notebook->GetSelection();
// TODO: emulate PAGE_CHANGING event // TODO: emulate PAGE_CHANGING event
wxNotebookEvent event( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEvent event( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
notebook->GetId(), nPage, old ); notebook->GetId(), nPage, old );
event.SetEventObject( notebook ); event.SetEventObject( notebook );
notebook->GetEventHandler()->ProcessEvent( event ); notebook->GetEventHandler()->ProcessEvent( event );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -90,17 +97,48 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
{ {
if ((win->m_x == alloc->x) && if ((win->m_x == alloc->x) &&
(win->m_y == alloc->y) && (win->m_y == alloc->y) &&
(win->m_width == alloc->width) && (win->m_width == alloc->width) &&
(win->m_height == alloc->height)) (win->m_height == alloc->height))
{ {
return; return;
} }
win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
if (win->GetAutoLayout()) win->Layout(); if (win->GetAutoLayout()) win->Layout();
}
//-----------------------------------------------------------------------------
// "key_press_event"
//-----------------------------------------------------------------------------
static gint
gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook )
{
if (g_blockEventsOnDrag) return FALSE;
if (!notebook->HasVMT()) return FALSE;
if (gdk_event->keyval != GDK_Down) return FALSE;
if (notebook != notebook->FindFocus()) return FALSE;
if (notebook->m_pages.GetCount() == 0) return FALSE;
wxNode *node = notebook->m_pages.Nth( notebook->GetSelection() );
if (!node) return FALSE;
wxNotebookPage *page = (wxNotebookPage*) node->Data();
// don't let others the key event
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
page->m_client->SetFocus();
return TRUE;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -109,32 +147,28 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation*
static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child )
{ {
wxNotebookPage *page = new wxNotebookPage(); wxNotebookPage *page = new wxNotebookPage();
page->m_id = parent->GetPageCount(); page->m_id = parent->GetPageCount();
page->m_box = gtk_hbox_new (FALSE, 0); page->m_box = gtk_hbox_new (FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); gtk_container_border_width(GTK_CONTAINER(page->m_box), 2);
GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
page->m_client = child; page->m_client = child;
gtk_notebook_append_page( notebook, child->m_widget, page->m_box ); gtk_notebook_append_page( notebook, child->m_widget, page->m_box );
page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
page->m_parent = notebook; page->m_parent = notebook;
gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
if (!page->m_page) wxASSERT_MSG( page->m_page, "Notebook page creation error" );
{
wxLogFatalError( "Notebook page creation error" );
return;
}
parent->m_pages.Append( page ); parent->m_pages.Append( page );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -145,155 +179,164 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl)
void wxNotebook::Init() void wxNotebook::Init()
{ {
m_imageList = (wxImageList *) NULL; m_imageList = (wxImageList *) NULL;
m_pages.DeleteContents( TRUE ); m_pages.DeleteContents( TRUE );
m_idHandler = 0; m_idHandler = 0;
} }
wxNotebook::wxNotebook() wxNotebook::wxNotebook()
{ {
Init(); Init();
} }
wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style, const wxString& name ) long style, const wxString& name )
{ {
Init(); Init();
Create( parent, id, pos, size, style, name ); Create( parent, id, pos, size, style, name );
} }
wxNotebook::~wxNotebook() wxNotebook::~wxNotebook()
{ {
// don't generate change page events any more // don't generate change page events any more
if (m_idHandler != 0) if (m_idHandler != 0)
gtk_signal_disconnect(GTK_OBJECT(m_widget), m_idHandler); gtk_signal_disconnect(GTK_OBJECT(m_widget), m_idHandler);
DeleteAllPages(); DeleteAllPages();
} }
bool wxNotebook::Create(wxWindow *parent, wxWindowID id, bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style, const wxString& name ) long style, const wxString& name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; m_acceptsFocus = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_notebook_new(); m_widget = gtk_notebook_new();
gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); #ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxNotebook::m_widget", name );
#endif
m_idHandler = gtk_signal_connect ( gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
m_idHandler = gtk_signal_connect (
GTK_OBJECT(m_widget), "switch_page", GTK_OBJECT(m_widget), "switch_page",
GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback),
(gpointer)this ); (gpointer)this );
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event",
GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this );
Show( TRUE ); PostCreation();
return TRUE; Show( TRUE );
return TRUE;
} }
int wxNotebook::GetSelection() const int wxNotebook::GetSelection() const
{ {
wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
if (m_pages.Number() == 0) return -1; if (m_pages.Number() == 0) return -1;
GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page; GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page;
if (!g_page) return -1; if (!g_page) return -1;
wxNotebookPage *page = (wxNotebookPage *) NULL; wxNotebookPage *page = (wxNotebookPage *) NULL;
wxNode *node = m_pages.First(); wxNode *node = m_pages.First();
while (node) while (node)
{
page = (wxNotebookPage*)node->Data();
if ((page->m_page == g_page) || (page->m_page == (GtkNotebookPage*)NULL))
{ {
// page->m_page is NULL directly after gtk_notebook_append. gtk emits page = (wxNotebookPage*)node->Data();
// "switch_page" then and we ask for GetSelection() in the handler for
// "switch_page". otherwise m_page should never be NULL. all this if ((page->m_page == g_page) || (page->m_page == (GtkNotebookPage*)NULL))
// might also be wrong. {
break; // page->m_page is NULL directly after gtk_notebook_append. gtk emits
// "switch_page" then and we ask for GetSelection() in the handler for
// "switch_page". otherwise m_page should never be NULL. all this
// might also be wrong.
break;
}
node = node->Next();
} }
node = node->Next();
}
wxCHECK_MSG( node != NULL, -1, "wxNotebook: no selection?" ); wxCHECK_MSG( node != NULL, -1, "wxNotebook: no selection?" );
return page->m_id; return page->m_id;
} }
int wxNotebook::GetPageCount() const int wxNotebook::GetPageCount() const
{ {
// count only the pages which were already added to the notebook for MSW // count only the pages which were already added to the notebook for MSW
// compatibility (and, in fact, this behaviour makes more sense anyhow // compatibility (and, in fact, this behaviour makes more sense anyhow
// because only the added pages are shown) // because only the added pages are shown)
int n = 0;
for ( wxNode *node = m_pages.First(); node; node = node->Next() ) int n = 0;
{ for ( wxNode *node = m_pages.First(); node; node = node->Next() )
wxNotebookPage *page = (wxNotebookPage*)node->Data(); {
if ( page->WasAdded() ) wxNotebookPage *page = (wxNotebookPage*)node->Data();
n++;
} if (page->WasAdded()) n++;
}
return n; return n;
} }
int wxNotebook::GetRowCount() const int wxNotebook::GetRowCount() const
{ {
return 1; return 1;
} }
wxString wxNotebook::GetPageText( int page ) const wxString wxNotebook::GetPageText( int page ) const
{ {
wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" );
wxNotebookPage* nb_page = GetNotebookPage(page); wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page) if (nb_page)
return nb_page->m_text; return nb_page->m_text;
else else
return ""; return "";
} }
int wxNotebook::GetPageImage( int page ) const int wxNotebook::GetPageImage( int page ) const
{ {
wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" );
wxNotebookPage* nb_page = GetNotebookPage(page); wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page) if (nb_page)
return nb_page->m_image; return nb_page->m_image;
else else
return 0; return 0;
} }
wxNotebookPage* wxNotebook::GetNotebookPage(int page) const wxNotebookPage* wxNotebook::GetNotebookPage(int page) const
{ {
wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" );
wxNotebookPage *nb_page = (wxNotebookPage *) NULL; wxNotebookPage *nb_page = (wxNotebookPage *) NULL;
wxNode *node = m_pages.First(); wxNode *node = m_pages.First();
while (node) while (node)
{ {
nb_page = (wxNotebookPage*)node->Data(); nb_page = (wxNotebookPage*)node->Data();
if (nb_page->m_id == page) if (nb_page->m_id == page)
return nb_page; return nb_page;
node = node->Next(); node = node->Next();
} }
wxLogDebug( "Notebook page %d not found!", page ); wxFAIL_MSG( "Notebook page not found!" );
return (wxNotebookPage *) NULL; return (wxNotebookPage *) NULL;
} }
int wxNotebook::SetSelection( int page ) int wxNotebook::SetSelection( int page )
@@ -437,7 +480,7 @@ bool wxNotebook::RemovePage( int page )
} }
bool wxNotebook::AddPage(wxWindow* win, const wxString& text, bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
bool bSelect, int imageId) bool select, int imageId)
{ {
wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
@@ -491,38 +534,38 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
gtk_widget_show((GtkWidget *)page->m_label); gtk_widget_show((GtkWidget *)page->m_label);
if (bSelect) SetSelection(GetPageCount()); if (select) SetSelection( GetPageCount()-1 );
return TRUE; return TRUE;
} }
wxWindow *wxNotebook::GetPage( int page ) const wxWindow *wxNotebook::GetPage( int page ) const
{ {
wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" );
wxNotebookPage* nb_page = GetNotebookPage(page); wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page) if (!nb_page)
return (wxWindow *) NULL; return (wxWindow *) NULL;
else else
return nb_page->m_client; return nb_page->m_client;
} }
// override these 2 functions to do nothing: everything is done in OnSize // override these 2 functions to do nothing: everything is done in OnSize
void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
{ {
// don't set the sizes of the pages - their correct size is not yet known // don't set the sizes of the pages - their correct size is not yet known
wxControl::SetConstraintSizes(FALSE); wxControl::SetConstraintSizes(FALSE);
} }
bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
{ {
return TRUE; return TRUE;
} }
void wxNotebook::ApplyWidgetStyle() void wxNotebook::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle ); gtk_widget_set_style( m_widget, m_widgetStyle );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -71,6 +71,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
{ {
m_alreadySent = FALSE; m_alreadySent = FALSE;
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
@@ -282,6 +283,27 @@ int wxRadioBox::FindString( const wxString &s ) const
return -1; return -1;
} }
void wxRadioBox::SetFocus()
{
wxCHECK_RET( m_widget != NULL, "invalid radiobox" );
if (m_boxes.GetCount() == 0) return;
wxNode *node = m_boxes.First();
while (node)
{
GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
if (button->active)
{
gtk_widget_grab_focus( GTK_WIDGET(button) );
return;
}
node = node->Next();
}
}
void wxRadioBox::SetSelection( int n ) void wxRadioBox::SetSelection( int n )
{ {
wxCHECK_RET( m_widget != NULL, "invalid radiobox" ); wxCHECK_RET( m_widget != NULL, "invalid radiobox" );

View File

@@ -53,6 +53,7 @@ bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& lab
const wxPoint& pos, const wxSize& size, long style, const wxPoint& pos, const wxSize& size, long style,
const wxValidator& validator, const wxString& name ) const wxValidator& validator, const wxString& name )
{ {
m_acceptsFocus = TRUE;
m_needParent = TRUE; m_needParent = TRUE;
wxSize newSize = size; wxSize newSize = size;

View File

@@ -116,6 +116,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
long style, const wxValidator& validator, const wxString& name ) long style, const wxValidator& validator, const wxString& name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );

View File

@@ -79,6 +79,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style, const wxValidator& validator, const wxString& name ) long style, const wxValidator& validator, const wxString& name )
{ {
m_acceptsFocus = TRUE;
m_needParent = TRUE; m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );

View File

@@ -20,6 +20,14 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h> #include <ctype.h>
#include "gdk/gdkkeysyms.h"
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "changed" // "changed"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -48,7 +56,6 @@ gtk_text_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* WXUNUSED(all
win->CalculateScrollbar(); win->CalculateScrollbar();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxTextCtrl // wxTextCtrl
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -81,6 +88,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
int style, const wxValidator& validator, const wxString &name ) int style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
@@ -152,9 +160,8 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
} }
// we want to be notified about text changes // we want to be notified about text changes
gtk_signal_connect(GTK_OBJECT(m_text), "changed", gtk_signal_connect( GTK_OBJECT(m_text), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback), GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
(gpointer)this);
if (!value.IsNull()) if (!value.IsNull())
{ {
@@ -608,15 +615,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event )
event.SetEventObject(this); event.SetEventObject(this);
if (GetEventHandler()->ProcessEvent(event)) return; if (GetEventHandler()->ProcessEvent(event)) return;
} }
else if (key_event.KeyCode() == WXK_TAB)
{
wxNavigationKeyEvent event;
event.SetDirection( key_event.m_shiftDown );
event.SetWindowChange(FALSE);
event.SetEventObject(this);
if (GetEventHandler()->ProcessEvent(event)) return;
}
key_event.Skip(); key_event.Skip();
} }

View File

@@ -120,15 +120,51 @@
#endif #endif
#endif #endif
//-----------------------------------------------------------------------------
// (debug)
//-----------------------------------------------------------------------------
#ifdef __WXDEBUG__
static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget),
GdkEvent *WXUNUSED(event),
const char *name )
{
printf( "FOCUS NOW AT: " );
printf( name );
printf( "\n" );
return FALSE;
}
void debug_focus_in( GtkWidget* widget, const char* name, const char *window )
{
return;
wxString tmp = name;
tmp += " FROM ";
tmp += window;
char *s = new char[tmp.Length()+1];
strcpy( s, WXSTRINGCAST tmp );
gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s );
}
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// data // data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern wxList wxPendingDelete; extern wxList wxPendingDelete;
extern wxList wxTopLevelWindows; extern wxList wxTopLevelWindows;
extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnDrag;
extern bool g_blockEventsOnScroll; extern bool g_blockEventsOnScroll;
static bool g_capturing = FALSE; static bool g_capturing = FALSE;
static wxWindow *g_focusWindow = (wxWindow*) NULL;
// hack: we need something to pass to gtk_menu_popup, so we store the time of // hack: we need something to pass to gtk_menu_popup, so we store the time of
// the last click here // the last click here
@@ -181,7 +217,7 @@ static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "key_press_event" // "key_press_event" from any window
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win )
@@ -303,11 +339,41 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
ancestor = ancestor->GetParent(); ancestor = ancestor->GetParent();
} }
} }
// win is a control: tab can be propagated up
if ((!ret) && (gdk_event->keyval == GDK_Tab))
{
wxNavigationKeyEvent new_event;
new_event.SetDirection( !(gdk_event->state & GDK_SHIFT_MASK) );
new_event.SetWindowChange( FALSE );
new_event.SetCurrentFocus( win );
ret = win->GetEventHandler()->ProcessEvent( new_event );
}
/*
// win is a panel: up can be propagated to the panel
if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) &&
(gdk_event->keyval == GDK_Up))
{
win->m_parent->SetFocus();
ret = TRUE;
}
// win is a panel: left/right can be propagated to the panel
if ((!ret) && (win->m_wxwindow) &&
((gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Left) ||
(gdk_event->keyval == GDK_Up) || (gdk_event->keyval == GDK_Down)))
{
wxNavigationKeyEvent new_event;
new_event.SetDirection( (gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Down) );
new_event.SetCurrentFocus( win );
ret = win->GetEventHandler()->ProcessEvent( new_event );
}
*/
if (ret) if (ret)
{ {
if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF)) gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
} }
return ret; return ret;
@@ -658,6 +724,9 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion
static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
{ {
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
g_focusWindow = win;
if (win->m_wxwindow) if (win->m_wxwindow)
{ {
if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
@@ -729,10 +798,13 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
{ {
if (widget->window != gdk_event->window) return TRUE;
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() );
if (widget->window != gdk_event->window) return TRUE;
if (!win->HasVMT()) return TRUE; if (!win->HasVMT()) return TRUE;
/* /*
@@ -742,9 +814,6 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
printf( ".\n" ); printf( ".\n" );
*/ */
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() );
wxMouseEvent event( wxEVT_ENTER_WINDOW ); wxMouseEvent event( wxEVT_ENTER_WINDOW );
event.SetEventObject( win ); event.SetEventObject( win );
@@ -777,10 +846,13 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
{ {
if (widget->window != gdk_event->window) return TRUE;
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
if (widget->window != gdk_event->window) return TRUE;
if (!win->HasVMT()) return TRUE; if (!win->HasVMT()) return TRUE;
/* /*
@@ -790,9 +862,6 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_
printf( ".\n" ); printf( ".\n" );
*/ */
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
wxMouseEvent event( wxEVT_LEAVE_WINDOW ); wxMouseEvent event( wxEVT_LEAVE_WINDOW );
event.SetEventObject( win ); event.SetEventObject( win );
@@ -1104,6 +1173,7 @@ wxWindow::wxWindow()
m_clientData = NULL; m_clientData = NULL;
m_isStaticBox = FALSE; m_isStaticBox = FALSE;
m_acceptsFocus = FALSE;
} }
wxWindow::wxWindow( wxWindow *parent, wxWindowID id, wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
@@ -1126,9 +1196,18 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
#ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxWindow::m_widget", name );
#endif
GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget); GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget);
#ifdef __WXDEBUG__
debug_focus_in( s_window->hscrollbar, "wxWindow::hsrcollbar", name );
debug_focus_in( s_window->vscrollbar, "wxWindow::vsrcollbar", name );
#endif
GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
scroll_class->scrollbar_spacing = 0; scroll_class->scrollbar_spacing = 0;
@@ -1142,6 +1221,10 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
m_wxwindow = gtk_myfixed_new(); m_wxwindow = gtk_myfixed_new();
#ifdef __WXDEBUG__
debug_focus_in( m_wxwindow, "wxWindow::m_wxwindow", name );
#endif
#ifdef NEW_GTK_SCROLL_CODE #ifdef NEW_GTK_SCROLL_CODE
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), m_wxwindow ); gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), m_wxwindow );
GtkViewport *viewport = GTK_VIEWPORT(s_window->child); GtkViewport *viewport = GTK_VIEWPORT(s_window->child);
@@ -1150,6 +1233,10 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport); GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
#endif #endif
#ifdef __WXDEBUG__
debug_focus_in( GTK_WIDGET(viewport), "wxWindow::viewport", name );
#endif
if (m_windowStyle & wxRAISED_BORDER) if (m_windowStyle & wxRAISED_BORDER)
{ {
gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT ); gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT );
@@ -1163,10 +1250,16 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE ); gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
} }
if (m_windowStyle & wxTAB_TRAVERSAL == wxTAB_TRAVERSAL) if ((m_windowStyle & wxTAB_TRAVERSAL) != 0)
{
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
m_acceptsFocus = FALSE;
}
else else
{
GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
m_acceptsFocus = TRUE;
}
// shut the viewport up // shut the viewport up
gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
@@ -1902,17 +1995,34 @@ void wxWindow::MakeModal( bool modal )
void wxWindow::SetFocus() void wxWindow::SetFocus()
{ {
wxCHECK_RET( (m_widget != NULL), "invalid window" ); wxCHECK_RET( (m_widget != NULL), "invalid window" );
GtkWidget *connect_widget = GetConnectWidget(); GtkWidget *connect_widget = GetConnectWidget();
if (connect_widget) if (connect_widget)
{ {
if (GTK_WIDGET_CAN_FOCUS(connect_widget) && !GTK_WIDGET_HAS_FOCUS (connect_widget) ) if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
{ {
gtk_widget_grab_focus (connect_widget); gtk_widget_grab_focus (connect_widget);
} }
else if (GTK_IS_CONTAINER(connect_widget))
{
gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD );
}
else
{
}
} }
} }
wxWindow *wxWindow::FindFocus()
{
return g_focusWindow;
}
bool wxWindow::AcceptsFocus() const
{
return IsEnabled() && IsShown() && m_acceptsFocus;
}
bool wxWindow::OnClose() bool wxWindow::OnClose()
{ {
return TRUE; return TRUE;
@@ -3154,8 +3264,8 @@ void wxWindow::GetClientSizeConstraint(int *w, int *h) const
void wxWindow::GetPositionConstraint(int *x, int *y) const void wxWindow::GetPositionConstraint(int *x, int *y) const
{ {
wxLayoutConstraints *constr = GetConstraints(); wxLayoutConstraints *constr = GetConstraints();
if (constr) if (constr)
{ {
*x = constr->left.GetValue(); *x = constr->left.GetValue();
*y = constr->top.GetValue(); *y = constr->top.GetValue();
@@ -3164,12 +3274,7 @@ void wxWindow::GetPositionConstraint(int *x, int *y) const
GetPosition(x, y); GetPosition(x, y);
} }
bool wxWindow::AcceptsFocus() const
{
return IsEnabled() && IsShown();
}
void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) ) void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) )
{ {
UpdateWindowUI(); UpdateWindowUI();
} }

View File

@@ -102,6 +102,7 @@ bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bi
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
wxSize newSize = size; wxSize newSize = size;

View File

@@ -58,37 +58,38 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_clientData = (wxClientData*) NULL; m_clientData = (wxClientData*) NULL;
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
wxSize newSize = size; wxSize newSize = size;
PreCreation( parent, id, pos, newSize, style, name ); PreCreation( parent, id, pos, newSize, style, name );
SetValidator( validator ); SetValidator( validator );
m_widget = gtk_button_new_with_label( m_label ); m_widget = gtk_button_new_with_label( m_label );
SetLabel(label); SetLabel(label);
if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label ); if (newSize.x == -1) newSize.x = 15+gdk_string_measure( m_widget->style->font, label );
if (newSize.y == -1) newSize.y = 26; if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y ); SetSize( newSize.x, newSize.y );
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this );
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); PostCreation();
SetBackgroundColour( parent->GetBackgroundColour() ); SetBackgroundColour( parent->GetBackgroundColour() );
SetForegroundColour( parent->GetForegroundColour() ); SetForegroundColour( parent->GetForegroundColour() );
Show( TRUE ); Show( TRUE );
return TRUE; return TRUE;
} }
void wxButton::SetDefault(void) void wxButton::SetDefault(void)
@@ -101,27 +102,27 @@ void wxButton::SetDefault(void)
void wxButton::SetLabel( const wxString &label ) void wxButton::SetLabel( const wxString &label )
{ {
wxCHECK_RET( m_widget != NULL, "invalid button" ); wxCHECK_RET( m_widget != NULL, "invalid button" );
wxControl::SetLabel( label ); wxControl::SetLabel( label );
gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() ); gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
} }
void wxButton::Enable( bool enable ) void wxButton::Enable( bool enable )
{ {
wxCHECK_RET( m_widget != NULL, "invalid button" ); wxCHECK_RET( m_widget != NULL, "invalid button" );
wxControl::Enable( enable ); wxControl::Enable( enable );
gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable ); gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
} }
void wxButton::ApplyWidgetStyle() void wxButton::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle ); gtk_widget_set_style( m_widget, m_widgetStyle );
gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle ); gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
} }

View File

@@ -26,20 +26,20 @@ extern bool g_blockEventsOnDrag;
static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb ) static void gtk_checkbox_clicked_callback( GtkWidget *WXUNUSED(widget), wxCheckBox *cb )
{ {
if (!cb->HasVMT()) return; if (!cb->HasVMT()) return;
if (cb->m_blockFirstEvent) if (cb->m_blockFirstEvent)
{ {
cb->m_blockFirstEvent = FALSE; cb->m_blockFirstEvent = FALSE;
return; return;
} }
if (g_blockEventsOnDrag) return; if (g_blockEventsOnDrag) return;
wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId()); wxCommandEvent event(wxEVT_COMMAND_CHECKBOX_CLICKED, cb->GetId());
event.SetInt( cb->GetValue() ); event.SetInt( cb->GetValue() );
event.SetEventObject(cb); event.SetEventObject(cb);
cb->GetEventHandler()->ProcessEvent(event); cb->GetEventHandler()->ProcessEvent(event);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -56,81 +56,82 @@ bool wxCheckBox::Create( wxWindow *parent, wxWindowID id, const wxString &label
const wxPoint &pos, const wxSize &size, const wxPoint &pos, const wxSize &size,
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
SetValidator( validator ); SetValidator( validator );
m_widget = gtk_check_button_new_with_label( m_label ); m_widget = gtk_check_button_new_with_label( m_label );
m_blockFirstEvent = FALSE; m_blockFirstEvent = FALSE;
wxSize newSize = size; wxSize newSize = size;
if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label ); if (newSize.x == -1) newSize.x = 25+gdk_string_measure( m_widget->style->font, label );
if (newSize.y == -1) newSize.y = 26; if (newSize.y == -1) newSize.y = 26;
SetSize( newSize.x, newSize.y ); SetSize( newSize.x, newSize.y );
gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", gtk_signal_connect( GTK_OBJECT(m_widget), "clicked",
GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this ); GTK_SIGNAL_FUNC(gtk_checkbox_clicked_callback), (gpointer*)this );
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); PostCreation();
gtk_widget_realize( GTK_BUTTON( m_widget )->child ); gtk_widget_realize( GTK_BUTTON( m_widget )->child );
SetLabel( label ); SetLabel( label );
SetBackgroundColour( parent->GetBackgroundColour() ); SetBackgroundColour( parent->GetBackgroundColour() );
SetForegroundColour( parent->GetForegroundColour() ); SetForegroundColour( parent->GetForegroundColour() );
Show( TRUE ); Show( TRUE );
return TRUE; return TRUE;
} }
void wxCheckBox::SetValue( bool state ) void wxCheckBox::SetValue( bool state )
{ {
wxCHECK_RET( m_widget != NULL, "invalid checkbox" ); wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
m_blockFirstEvent = TRUE; m_blockFirstEvent = TRUE;
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state ); gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_widget), state );
} }
bool wxCheckBox::GetValue() const bool wxCheckBox::GetValue() const
{ {
wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" ); wxCHECK_MSG( m_widget != NULL, FALSE, "invalid checkbox" );
return GTK_TOGGLE_BUTTON(m_widget)->active; return GTK_TOGGLE_BUTTON(m_widget)->active;
} }
void wxCheckBox::SetLabel( const wxString& label ) void wxCheckBox::SetLabel( const wxString& label )
{ {
wxCHECK_RET( m_widget != NULL, "invalid checkbox" ); wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
wxControl::SetLabel( label ); wxControl::SetLabel( label );
gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() ); gtk_label_set( GTK_LABEL( GTK_BUTTON(m_widget)->child ), GetLabel() );
} }
void wxCheckBox::Enable( bool enable ) void wxCheckBox::Enable( bool enable )
{ {
wxCHECK_RET( m_widget != NULL, "invalid checkbox" ); wxCHECK_RET( m_widget != NULL, "invalid checkbox" );
wxControl::Enable( enable ); wxControl::Enable( enable );
gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable ); gtk_widget_set_sensitive( GTK_BUTTON(m_widget)->child, enable );
} }
void wxCheckBox::ApplyWidgetStyle() void wxCheckBox::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle ); gtk_widget_set_style( m_widget, m_widgetStyle );
gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle ); gtk_widget_set_style( GTK_BUTTON(m_widget)->child, m_widgetStyle );
} }

View File

@@ -63,6 +63,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value,
{ {
m_alreadySent = FALSE; m_alreadySent = FALSE;
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );

View File

@@ -21,7 +21,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxControl,wxWindow)
wxControl::wxControl(void) wxControl::wxControl(void)
{ {
m_needParent = TRUE; m_needParent = TRUE;
} }
wxControl::wxControl( wxWindow *parent, wxWindowID id, wxControl::wxControl( wxWindow *parent, wxWindowID id,
@@ -37,24 +37,23 @@ void wxControl::Command( wxCommandEvent &WXUNUSED(event) )
void wxControl::SetLabel( const wxString &label ) void wxControl::SetLabel( const wxString &label )
{ {
m_label = ""; m_label = "";
for ( const char *pc = label; *pc != '\0'; pc++ ) { for ( const char *pc = label; *pc != '\0'; pc++ )
if ( *pc == '&' ) { {
pc++; // skip it if ( *pc == '&' )
{
pc++; // skip it
#if 0 // it would be unused anyhow for now - kbd interface not done yet #if 0 // it would be unused anyhow for now - kbd interface not done yet
if ( *pc != '&' ) if ( *pc != '&' ) m_chAccel = *pc;
m_chAccel = *pc;
#endif #endif
}
m_label << *pc;
} }
m_label << *pc;
}
} }
wxString wxControl::GetLabel(void) const wxString wxControl::GetLabel(void) const
{ {
return m_label; return m_label;
} }

View File

@@ -142,6 +142,10 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
m_widget = gtk_window_new( win_type ); m_widget = gtk_window_new( win_type );
#ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxFrame::m_widget", name );
#endif
if ((size.x != -1) && (size.y != -1)) if ((size.x != -1) && (size.y != -1))
gtk_widget_set_usize( m_widget, m_width, m_height ); gtk_widget_set_usize( m_widget, m_width, m_height );
if ((pos.x != -1) && (pos.y != -1)) if ((pos.x != -1) && (pos.y != -1))
@@ -159,6 +163,10 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
gtk_widget_show( m_wxwindow ); gtk_widget_show( m_wxwindow );
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
#ifdef __WXDEBUG__
debug_focus_in( m_wxwindow, "wxFrame::m_wxwindow", name );
#endif
gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate",

View File

@@ -130,6 +130,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
long style, const wxValidator& validator, const wxString &name ) long style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
@@ -138,7 +139,7 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL ); m_widget = gtk_scrolled_window_new( (GtkAdjustment*) NULL, (GtkAdjustment*) NULL );
gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget), gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(m_widget),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
m_list = GTK_LIST( gtk_list_new() ); m_list = GTK_LIST( gtk_list_new() );
GtkSelectionMode mode = GTK_SELECTION_BROWSE; GtkSelectionMode mode = GTK_SELECTION_BROWSE;
@@ -155,6 +156,25 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) ); gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_list) );
#endif #endif
#ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxListBox::m_widget", name );
debug_focus_in( GTK_WIDGET(m_list), "wxListBox::m_list", name );
GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget);
debug_focus_in( s_window->hscrollbar, "wxWindow::hsrcollbar", name );
debug_focus_in( s_window->vscrollbar, "wxWindow::vsrcollbar", name );
#ifdef NEW_GTK_SCROLL_CODE
GtkViewport *viewport = GTK_VIEWPORT(s_window->child);
#else
GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
#endif
debug_focus_in( GTK_WIDGET(viewport), "wxWindow::viewport", name );
#endif
gtk_widget_show( GTK_WIDGET(m_list) ); gtk_widget_show( GTK_WIDGET(m_list) );
wxSize newSize = size; wxSize newSize = size;
@@ -180,6 +200,10 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id,
list_item = gtk_list_item_new_with_label( choices[i] ); list_item = gtk_list_item_new_with_label( choices[i] );
} }
#ifdef __WXDEBUG__
debug_focus_in( list_item, "wxListBox::list_item", name );
#endif
gtk_container_add( GTK_CONTAINER(m_list), list_item ); gtk_container_add( GTK_CONTAINER(m_list), list_item );
gtk_signal_connect( GTK_OBJECT(list_item), "select", gtk_signal_connect( GTK_OBJECT(list_item), "select",

View File

@@ -17,6 +17,13 @@
#include "wx/imaglist.h" #include "wx/imaglist.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#include "gdk/gdkkeysyms.h"
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxNotebookPage // wxNotebookPage
@@ -72,16 +79,16 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
gint nPage, gint nPage,
gpointer data) gpointer data)
{ {
wxNotebook *notebook = (wxNotebook *)data; wxNotebook *notebook = (wxNotebook *)data;
int old = notebook->GetSelection(); int old = notebook->GetSelection();
// TODO: emulate PAGE_CHANGING event // TODO: emulate PAGE_CHANGING event
wxNotebookEvent event( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, wxNotebookEvent event( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED,
notebook->GetId(), nPage, old ); notebook->GetId(), nPage, old );
event.SetEventObject( notebook ); event.SetEventObject( notebook );
notebook->GetEventHandler()->ProcessEvent( event ); notebook->GetEventHandler()->ProcessEvent( event );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -90,17 +97,48 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget),
static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win ) static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxWindow *win )
{ {
if ((win->m_x == alloc->x) && if ((win->m_x == alloc->x) &&
(win->m_y == alloc->y) && (win->m_y == alloc->y) &&
(win->m_width == alloc->width) && (win->m_width == alloc->width) &&
(win->m_height == alloc->height)) (win->m_height == alloc->height))
{ {
return; return;
} }
win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height );
if (win->GetAutoLayout()) win->Layout(); if (win->GetAutoLayout()) win->Layout();
}
//-----------------------------------------------------------------------------
// "key_press_event"
//-----------------------------------------------------------------------------
static gint
gtk_notebook_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxNotebook *notebook )
{
if (g_blockEventsOnDrag) return FALSE;
if (!notebook->HasVMT()) return FALSE;
if (gdk_event->keyval != GDK_Down) return FALSE;
if (notebook != notebook->FindFocus()) return FALSE;
if (notebook->m_pages.GetCount() == 0) return FALSE;
wxNode *node = notebook->m_pages.Nth( notebook->GetSelection() );
if (!node) return FALSE;
wxNotebookPage *page = (wxNotebookPage*) node->Data();
// don't let others the key event
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
page->m_client->SetFocus();
return TRUE;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -109,32 +147,28 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation*
static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child ) static void wxInsertChildInNotebook( wxNotebook* parent, wxWindow* child )
{ {
wxNotebookPage *page = new wxNotebookPage(); wxNotebookPage *page = new wxNotebookPage();
page->m_id = parent->GetPageCount(); page->m_id = parent->GetPageCount();
page->m_box = gtk_hbox_new (FALSE, 0); page->m_box = gtk_hbox_new (FALSE, 0);
gtk_container_border_width(GTK_CONTAINER(page->m_box), 2); gtk_container_border_width(GTK_CONTAINER(page->m_box), 2);
GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget); GtkNotebook *notebook = GTK_NOTEBOOK(parent->m_widget);
page->m_client = child; page->m_client = child;
gtk_notebook_append_page( notebook, child->m_widget, page->m_box ); gtk_notebook_append_page( notebook, child->m_widget, page->m_box );
page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data); page->m_page = (GtkNotebookPage*) (g_list_last(notebook->children)->data);
page->m_parent = notebook; page->m_parent = notebook;
gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate", gtk_signal_connect( GTK_OBJECT(child->m_widget), "size_allocate",
GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child ); GTK_SIGNAL_FUNC(gtk_page_size_callback), (gpointer)child );
if (!page->m_page) wxASSERT_MSG( page->m_page, "Notebook page creation error" );
{
wxLogFatalError( "Notebook page creation error" );
return;
}
parent->m_pages.Append( page ); parent->m_pages.Append( page );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -145,155 +179,164 @@ IMPLEMENT_DYNAMIC_CLASS(wxNotebook,wxControl)
void wxNotebook::Init() void wxNotebook::Init()
{ {
m_imageList = (wxImageList *) NULL; m_imageList = (wxImageList *) NULL;
m_pages.DeleteContents( TRUE ); m_pages.DeleteContents( TRUE );
m_idHandler = 0; m_idHandler = 0;
} }
wxNotebook::wxNotebook() wxNotebook::wxNotebook()
{ {
Init(); Init();
} }
wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id, wxNotebook::wxNotebook( wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style, const wxString& name ) long style, const wxString& name )
{ {
Init(); Init();
Create( parent, id, pos, size, style, name ); Create( parent, id, pos, size, style, name );
} }
wxNotebook::~wxNotebook() wxNotebook::~wxNotebook()
{ {
// don't generate change page events any more // don't generate change page events any more
if (m_idHandler != 0) if (m_idHandler != 0)
gtk_signal_disconnect(GTK_OBJECT(m_widget), m_idHandler); gtk_signal_disconnect(GTK_OBJECT(m_widget), m_idHandler);
DeleteAllPages(); DeleteAllPages();
} }
bool wxNotebook::Create(wxWindow *parent, wxWindowID id, bool wxNotebook::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style, const wxString& name ) long style, const wxString& name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook; m_acceptsFocus = TRUE;
m_insertCallback = (wxInsertChildFunction)wxInsertChildInNotebook;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
m_widget = gtk_notebook_new(); m_widget = gtk_notebook_new();
gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 ); #ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxNotebook::m_widget", name );
#endif
m_idHandler = gtk_signal_connect ( gtk_notebook_set_scrollable( GTK_NOTEBOOK(m_widget), 1 );
m_idHandler = gtk_signal_connect (
GTK_OBJECT(m_widget), "switch_page", GTK_OBJECT(m_widget), "switch_page",
GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback), GTK_SIGNAL_FUNC(gtk_notebook_page_change_callback),
(gpointer)this ); (gpointer)this );
m_parent->AddChild( this ); m_parent->AddChild( this );
(m_parent->m_insertCallback)( m_parent, this ); (m_parent->m_insertCallback)( m_parent, this );
PostCreation(); gtk_signal_connect( GTK_OBJECT(m_widget), "key_press_event",
GTK_SIGNAL_FUNC(gtk_notebook_key_press_callback), (gpointer)this );
Show( TRUE ); PostCreation();
return TRUE; Show( TRUE );
return TRUE;
} }
int wxNotebook::GetSelection() const int wxNotebook::GetSelection() const
{ {
wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, -1, "invalid notebook" );
if (m_pages.Number() == 0) return -1; if (m_pages.Number() == 0) return -1;
GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page; GtkNotebookPage *g_page = GTK_NOTEBOOK(m_widget)->cur_page;
if (!g_page) return -1; if (!g_page) return -1;
wxNotebookPage *page = (wxNotebookPage *) NULL; wxNotebookPage *page = (wxNotebookPage *) NULL;
wxNode *node = m_pages.First(); wxNode *node = m_pages.First();
while (node) while (node)
{
page = (wxNotebookPage*)node->Data();
if ((page->m_page == g_page) || (page->m_page == (GtkNotebookPage*)NULL))
{ {
// page->m_page is NULL directly after gtk_notebook_append. gtk emits page = (wxNotebookPage*)node->Data();
// "switch_page" then and we ask for GetSelection() in the handler for
// "switch_page". otherwise m_page should never be NULL. all this if ((page->m_page == g_page) || (page->m_page == (GtkNotebookPage*)NULL))
// might also be wrong. {
break; // page->m_page is NULL directly after gtk_notebook_append. gtk emits
// "switch_page" then and we ask for GetSelection() in the handler for
// "switch_page". otherwise m_page should never be NULL. all this
// might also be wrong.
break;
}
node = node->Next();
} }
node = node->Next();
}
wxCHECK_MSG( node != NULL, -1, "wxNotebook: no selection?" ); wxCHECK_MSG( node != NULL, -1, "wxNotebook: no selection?" );
return page->m_id; return page->m_id;
} }
int wxNotebook::GetPageCount() const int wxNotebook::GetPageCount() const
{ {
// count only the pages which were already added to the notebook for MSW // count only the pages which were already added to the notebook for MSW
// compatibility (and, in fact, this behaviour makes more sense anyhow // compatibility (and, in fact, this behaviour makes more sense anyhow
// because only the added pages are shown) // because only the added pages are shown)
int n = 0;
for ( wxNode *node = m_pages.First(); node; node = node->Next() ) int n = 0;
{ for ( wxNode *node = m_pages.First(); node; node = node->Next() )
wxNotebookPage *page = (wxNotebookPage*)node->Data(); {
if ( page->WasAdded() ) wxNotebookPage *page = (wxNotebookPage*)node->Data();
n++;
} if (page->WasAdded()) n++;
}
return n; return n;
} }
int wxNotebook::GetRowCount() const int wxNotebook::GetRowCount() const
{ {
return 1; return 1;
} }
wxString wxNotebook::GetPageText( int page ) const wxString wxNotebook::GetPageText( int page ) const
{ {
wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, "", "invalid notebook" );
wxNotebookPage* nb_page = GetNotebookPage(page); wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page) if (nb_page)
return nb_page->m_text; return nb_page->m_text;
else else
return ""; return "";
} }
int wxNotebook::GetPageImage( int page ) const int wxNotebook::GetPageImage( int page ) const
{ {
wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, 0, "invalid notebook" );
wxNotebookPage* nb_page = GetNotebookPage(page); wxNotebookPage* nb_page = GetNotebookPage(page);
if (nb_page) if (nb_page)
return nb_page->m_image; return nb_page->m_image;
else else
return 0; return 0;
} }
wxNotebookPage* wxNotebook::GetNotebookPage(int page) const wxNotebookPage* wxNotebook::GetNotebookPage(int page) const
{ {
wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, (wxNotebookPage*)NULL, "invalid notebook" );
wxNotebookPage *nb_page = (wxNotebookPage *) NULL; wxNotebookPage *nb_page = (wxNotebookPage *) NULL;
wxNode *node = m_pages.First(); wxNode *node = m_pages.First();
while (node) while (node)
{ {
nb_page = (wxNotebookPage*)node->Data(); nb_page = (wxNotebookPage*)node->Data();
if (nb_page->m_id == page) if (nb_page->m_id == page)
return nb_page; return nb_page;
node = node->Next(); node = node->Next();
} }
wxLogDebug( "Notebook page %d not found!", page ); wxFAIL_MSG( "Notebook page not found!" );
return (wxNotebookPage *) NULL; return (wxNotebookPage *) NULL;
} }
int wxNotebook::SetSelection( int page ) int wxNotebook::SetSelection( int page )
@@ -437,7 +480,7 @@ bool wxNotebook::RemovePage( int page )
} }
bool wxNotebook::AddPage(wxWindow* win, const wxString& text, bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
bool bSelect, int imageId) bool select, int imageId)
{ {
wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, FALSE, "invalid notebook" );
@@ -491,38 +534,38 @@ bool wxNotebook::AddPage(wxWindow* win, const wxString& text,
gtk_widget_show((GtkWidget *)page->m_label); gtk_widget_show((GtkWidget *)page->m_label);
if (bSelect) SetSelection(GetPageCount()); if (select) SetSelection( GetPageCount()-1 );
return TRUE; return TRUE;
} }
wxWindow *wxNotebook::GetPage( int page ) const wxWindow *wxNotebook::GetPage( int page ) const
{ {
wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" ); wxCHECK_MSG( m_widget != NULL, (wxWindow*) NULL, "invalid notebook" );
wxNotebookPage* nb_page = GetNotebookPage(page); wxNotebookPage* nb_page = GetNotebookPage(page);
if (!nb_page) if (!nb_page)
return (wxWindow *) NULL; return (wxWindow *) NULL;
else else
return nb_page->m_client; return nb_page->m_client;
} }
// override these 2 functions to do nothing: everything is done in OnSize // override these 2 functions to do nothing: everything is done in OnSize
void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) ) void wxNotebook::SetConstraintSizes( bool WXUNUSED(recurse) )
{ {
// don't set the sizes of the pages - their correct size is not yet known // don't set the sizes of the pages - their correct size is not yet known
wxControl::SetConstraintSizes(FALSE); wxControl::SetConstraintSizes(FALSE);
} }
bool wxNotebook::DoPhase( int WXUNUSED(nPhase) ) bool wxNotebook::DoPhase( int WXUNUSED(nPhase) )
{ {
return TRUE; return TRUE;
} }
void wxNotebook::ApplyWidgetStyle() void wxNotebook::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style( m_widget, m_widgetStyle ); gtk_widget_set_style( m_widget, m_widgetStyle );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -71,6 +71,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title,
{ {
m_alreadySent = FALSE; m_alreadySent = FALSE;
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
@@ -282,6 +283,27 @@ int wxRadioBox::FindString( const wxString &s ) const
return -1; return -1;
} }
void wxRadioBox::SetFocus()
{
wxCHECK_RET( m_widget != NULL, "invalid radiobox" );
if (m_boxes.GetCount() == 0) return;
wxNode *node = m_boxes.First();
while (node)
{
GtkToggleButton *button = GTK_TOGGLE_BUTTON( node->Data() );
if (button->active)
{
gtk_widget_grab_focus( GTK_WIDGET(button) );
return;
}
node = node->Next();
}
}
void wxRadioBox::SetSelection( int n ) void wxRadioBox::SetSelection( int n )
{ {
wxCHECK_RET( m_widget != NULL, "invalid radiobox" ); wxCHECK_RET( m_widget != NULL, "invalid radiobox" );

View File

@@ -53,6 +53,7 @@ bool wxRadioButton::Create( wxWindow *parent, wxWindowID id, const wxString& lab
const wxPoint& pos, const wxSize& size, long style, const wxPoint& pos, const wxSize& size, long style,
const wxValidator& validator, const wxString& name ) const wxValidator& validator, const wxString& name )
{ {
m_acceptsFocus = TRUE;
m_needParent = TRUE; m_needParent = TRUE;
wxSize newSize = size; wxSize newSize = size;

View File

@@ -116,6 +116,7 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id,
long style, const wxValidator& validator, const wxString& name ) long style, const wxValidator& validator, const wxString& name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );

View File

@@ -79,6 +79,7 @@ bool wxSlider::Create(wxWindow *parent, wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
long style, const wxValidator& validator, const wxString& name ) long style, const wxValidator& validator, const wxString& name )
{ {
m_acceptsFocus = TRUE;
m_needParent = TRUE; m_needParent = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );

View File

@@ -20,6 +20,14 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h> #include <ctype.h>
#include "gdk/gdkkeysyms.h"
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
extern bool g_blockEventsOnDrag;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "changed" // "changed"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -48,7 +56,6 @@ gtk_text_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* WXUNUSED(all
win->CalculateScrollbar(); win->CalculateScrollbar();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxTextCtrl // wxTextCtrl
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -81,6 +88,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
int style, const wxValidator& validator, const wxString &name ) int style, const wxValidator& validator, const wxString &name )
{ {
m_needParent = TRUE; m_needParent = TRUE;
m_acceptsFocus = TRUE;
PreCreation( parent, id, pos, size, style, name ); PreCreation( parent, id, pos, size, style, name );
@@ -152,9 +160,8 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value,
} }
// we want to be notified about text changes // we want to be notified about text changes
gtk_signal_connect(GTK_OBJECT(m_text), "changed", gtk_signal_connect( GTK_OBJECT(m_text), "changed",
GTK_SIGNAL_FUNC(gtk_text_changed_callback), GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
(gpointer)this);
if (!value.IsNull()) if (!value.IsNull())
{ {
@@ -608,15 +615,7 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event )
event.SetEventObject(this); event.SetEventObject(this);
if (GetEventHandler()->ProcessEvent(event)) return; if (GetEventHandler()->ProcessEvent(event)) return;
} }
else if (key_event.KeyCode() == WXK_TAB)
{
wxNavigationKeyEvent event;
event.SetDirection( key_event.m_shiftDown );
event.SetWindowChange(FALSE);
event.SetEventObject(this);
if (GetEventHandler()->ProcessEvent(event)) return;
}
key_event.Skip(); key_event.Skip();
} }

View File

@@ -120,15 +120,51 @@
#endif #endif
#endif #endif
//-----------------------------------------------------------------------------
// (debug)
//-----------------------------------------------------------------------------
#ifdef __WXDEBUG__
static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget),
GdkEvent *WXUNUSED(event),
const char *name )
{
printf( "FOCUS NOW AT: " );
printf( name );
printf( "\n" );
return FALSE;
}
void debug_focus_in( GtkWidget* widget, const char* name, const char *window )
{
return;
wxString tmp = name;
tmp += " FROM ";
tmp += window;
char *s = new char[tmp.Length()+1];
strcpy( s, WXSTRINGCAST tmp );
gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s );
}
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// data // data
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
extern wxList wxPendingDelete; extern wxList wxPendingDelete;
extern wxList wxTopLevelWindows; extern wxList wxTopLevelWindows;
extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnDrag;
extern bool g_blockEventsOnScroll; extern bool g_blockEventsOnScroll;
static bool g_capturing = FALSE; static bool g_capturing = FALSE;
static wxWindow *g_focusWindow = (wxWindow*) NULL;
// hack: we need something to pass to gtk_menu_popup, so we store the time of // hack: we need something to pass to gtk_menu_popup, so we store the time of
// the last click here // the last click here
@@ -181,7 +217,7 @@ static void gtk_window_draw_callback( GtkWidget *WXUNUSED(widget), GdkRectangle
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// "key_press_event" // "key_press_event" from any window
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win ) static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_event, wxWindow *win )
@@ -303,11 +339,41 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
ancestor = ancestor->GetParent(); ancestor = ancestor->GetParent();
} }
} }
// win is a control: tab can be propagated up
if ((!ret) && (gdk_event->keyval == GDK_Tab))
{
wxNavigationKeyEvent new_event;
new_event.SetDirection( !(gdk_event->state & GDK_SHIFT_MASK) );
new_event.SetWindowChange( FALSE );
new_event.SetCurrentFocus( win );
ret = win->GetEventHandler()->ProcessEvent( new_event );
}
/*
// win is a panel: up can be propagated to the panel
if ((!ret) && (win->m_wxwindow) && (win->m_parent) && (win->m_parent->AcceptsFocus()) &&
(gdk_event->keyval == GDK_Up))
{
win->m_parent->SetFocus();
ret = TRUE;
}
// win is a panel: left/right can be propagated to the panel
if ((!ret) && (win->m_wxwindow) &&
((gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Left) ||
(gdk_event->keyval == GDK_Up) || (gdk_event->keyval == GDK_Down)))
{
wxNavigationKeyEvent new_event;
new_event.SetDirection( (gdk_event->keyval == GDK_Right) || (gdk_event->keyval == GDK_Down) );
new_event.SetCurrentFocus( win );
ret = win->GetEventHandler()->ProcessEvent( new_event );
}
*/
if (ret) if (ret)
{ {
if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF)) gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "key_press_event" );
} }
return ret; return ret;
@@ -658,6 +724,9 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion
static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win ) static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(event), wxWindow *win )
{ {
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
g_focusWindow = win;
if (win->m_wxwindow) if (win->m_wxwindow)
{ {
if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow)) if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
@@ -729,10 +798,13 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
{ {
if (widget->window != gdk_event->window) return TRUE;
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() );
if (widget->window != gdk_event->window) return TRUE;
if (!win->HasVMT()) return TRUE; if (!win->HasVMT()) return TRUE;
/* /*
@@ -742,9 +814,6 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
printf( ".\n" ); printf( ".\n" );
*/ */
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() );
wxMouseEvent event( wxEVT_ENTER_WINDOW ); wxMouseEvent event( wxEVT_ENTER_WINDOW );
event.SetEventObject( win ); event.SetEventObject( win );
@@ -777,10 +846,13 @@ static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_
static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win ) static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
{ {
if (widget->window != gdk_event->window) return TRUE;
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
if (widget->window != gdk_event->window) return TRUE;
if (!win->HasVMT()) return TRUE; if (!win->HasVMT()) return TRUE;
/* /*
@@ -790,9 +862,6 @@ static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_
printf( ".\n" ); printf( ".\n" );
*/ */
if ((widget->window) && (win->m_cursor))
gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
wxMouseEvent event( wxEVT_LEAVE_WINDOW ); wxMouseEvent event( wxEVT_LEAVE_WINDOW );
event.SetEventObject( win ); event.SetEventObject( win );
@@ -1104,6 +1173,7 @@ wxWindow::wxWindow()
m_clientData = NULL; m_clientData = NULL;
m_isStaticBox = FALSE; m_isStaticBox = FALSE;
m_acceptsFocus = FALSE;
} }
wxWindow::wxWindow( wxWindow *parent, wxWindowID id, wxWindow::wxWindow( wxWindow *parent, wxWindowID id,
@@ -1126,9 +1196,18 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL ); m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
#ifdef __WXDEBUG__
debug_focus_in( m_widget, "wxWindow::m_widget", name );
#endif
GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget); GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget);
#ifdef __WXDEBUG__
debug_focus_in( s_window->hscrollbar, "wxWindow::hsrcollbar", name );
debug_focus_in( s_window->vscrollbar, "wxWindow::vsrcollbar", name );
#endif
GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass ); GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
scroll_class->scrollbar_spacing = 0; scroll_class->scrollbar_spacing = 0;
@@ -1142,6 +1221,10 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
m_wxwindow = gtk_myfixed_new(); m_wxwindow = gtk_myfixed_new();
#ifdef __WXDEBUG__
debug_focus_in( m_wxwindow, "wxWindow::m_wxwindow", name );
#endif
#ifdef NEW_GTK_SCROLL_CODE #ifdef NEW_GTK_SCROLL_CODE
gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), m_wxwindow ); gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), m_wxwindow );
GtkViewport *viewport = GTK_VIEWPORT(s_window->child); GtkViewport *viewport = GTK_VIEWPORT(s_window->child);
@@ -1150,6 +1233,10 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport); GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
#endif #endif
#ifdef __WXDEBUG__
debug_focus_in( GTK_WIDGET(viewport), "wxWindow::viewport", name );
#endif
if (m_windowStyle & wxRAISED_BORDER) if (m_windowStyle & wxRAISED_BORDER)
{ {
gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT ); gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_OUT );
@@ -1163,10 +1250,16 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE ); gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
} }
if (m_windowStyle & wxTAB_TRAVERSAL == wxTAB_TRAVERSAL) if ((m_windowStyle & wxTAB_TRAVERSAL) != 0)
{
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
m_acceptsFocus = FALSE;
}
else else
{
GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
m_acceptsFocus = TRUE;
}
// shut the viewport up // shut the viewport up
gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ); gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
@@ -1902,17 +1995,34 @@ void wxWindow::MakeModal( bool modal )
void wxWindow::SetFocus() void wxWindow::SetFocus()
{ {
wxCHECK_RET( (m_widget != NULL), "invalid window" ); wxCHECK_RET( (m_widget != NULL), "invalid window" );
GtkWidget *connect_widget = GetConnectWidget(); GtkWidget *connect_widget = GetConnectWidget();
if (connect_widget) if (connect_widget)
{ {
if (GTK_WIDGET_CAN_FOCUS(connect_widget) && !GTK_WIDGET_HAS_FOCUS (connect_widget) ) if (GTK_WIDGET_CAN_FOCUS(connect_widget) /*&& !GTK_WIDGET_HAS_FOCUS (connect_widget)*/ )
{ {
gtk_widget_grab_focus (connect_widget); gtk_widget_grab_focus (connect_widget);
} }
else if (GTK_IS_CONTAINER(connect_widget))
{
gtk_container_focus( GTK_CONTAINER(connect_widget), GTK_DIR_TAB_FORWARD );
}
else
{
}
} }
} }
wxWindow *wxWindow::FindFocus()
{
return g_focusWindow;
}
bool wxWindow::AcceptsFocus() const
{
return IsEnabled() && IsShown() && m_acceptsFocus;
}
bool wxWindow::OnClose() bool wxWindow::OnClose()
{ {
return TRUE; return TRUE;
@@ -3154,8 +3264,8 @@ void wxWindow::GetClientSizeConstraint(int *w, int *h) const
void wxWindow::GetPositionConstraint(int *x, int *y) const void wxWindow::GetPositionConstraint(int *x, int *y) const
{ {
wxLayoutConstraints *constr = GetConstraints(); wxLayoutConstraints *constr = GetConstraints();
if (constr) if (constr)
{ {
*x = constr->left.GetValue(); *x = constr->left.GetValue();
*y = constr->top.GetValue(); *y = constr->top.GetValue();
@@ -3164,12 +3274,7 @@ void wxWindow::GetPositionConstraint(int *x, int *y) const
GetPosition(x, y); GetPosition(x, y);
} }
bool wxWindow::AcceptsFocus() const
{
return IsEnabled() && IsShown();
}
void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) ) void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event) )
{ {
UpdateWindowUI(); UpdateWindowUI();
} }