Backgrounds work again

splitter sample compiles with Unicode
  if a wxClientDC is used on an unrealized widget,
    the widget's realization is forced in wxClientDC
  added underscores to wxMenuBar - don't work..
  tried to figure out why wxFrame doesn't get keyboard input


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2281 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling 1999-04-25 15:10:52 +00:00
parent eea4f86a0c
commit 1e133b7d64
11 changed files with 330 additions and 122 deletions

View File

@ -48,6 +48,7 @@ public:
wxMenuBar(); wxMenuBar();
wxMenuBar(long style); wxMenuBar(long style);
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
~wxMenuBar();
// menubar construction // menubar construction
void Append( wxMenu *menu, const wxString &title ); void Append( wxMenu *menu, const wxString &title );
@ -88,12 +89,15 @@ public:
wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); } wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); }
#endif // WXWIN_COMPATIBILITY #endif // WXWIN_COMPATIBILITY
// implementation // implementation only
wxList& GetMenus() { return m_menus; } wxList& GetMenus() { return m_menus; }
protected: GtkAccelGroup *m_accel;
wxList m_menus; GtkItemFactory *m_factory;
GtkWidget *m_menubar;
private:
wxList m_menus;
GtkWidget *m_menubar;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -170,14 +174,14 @@ public:
void SetInvokingWindow( wxWindow *win ); void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow(); wxWindow *GetInvokingWindow();
// implementation only // implementation GTK only
GtkWidget *m_menu; // GtkMenu GtkWidget *m_menu; // GtkMenu
GtkWidget *m_owner; GtkWidget *m_owner;
GtkAccelGroup *m_accel; GtkAccelGroup *m_accel;
GtkItemFactory *m_factory; GtkItemFactory *m_factory;
private: private:
wxString m_title; wxString m_title;
wxList m_items; wxList m_items;
wxWindow *m_invokingWindow; wxWindow *m_invokingWindow;

View File

@ -48,6 +48,7 @@ public:
wxMenuBar(); wxMenuBar();
wxMenuBar(long style); wxMenuBar(long style);
wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); wxMenuBar(int n, wxMenu *menus[], const wxString titles[]);
~wxMenuBar();
// menubar construction // menubar construction
void Append( wxMenu *menu, const wxString &title ); void Append( wxMenu *menu, const wxString &title );
@ -88,12 +89,15 @@ public:
wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); } wxMenuItem* FindMenuItemById( int id ) const { return FindItem(id); }
#endif // WXWIN_COMPATIBILITY #endif // WXWIN_COMPATIBILITY
// implementation // implementation only
wxList& GetMenus() { return m_menus; } wxList& GetMenus() { return m_menus; }
protected: GtkAccelGroup *m_accel;
wxList m_menus; GtkItemFactory *m_factory;
GtkWidget *m_menubar;
private:
wxList m_menus;
GtkWidget *m_menubar;
}; };
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -170,14 +174,14 @@ public:
void SetInvokingWindow( wxWindow *win ); void SetInvokingWindow( wxWindow *win );
wxWindow *GetInvokingWindow(); wxWindow *GetInvokingWindow();
// implementation only // implementation GTK only
GtkWidget *m_menu; // GtkMenu GtkWidget *m_menu; // GtkMenu
GtkWidget *m_owner; GtkWidget *m_owner;
GtkAccelGroup *m_accel; GtkAccelGroup *m_accel;
GtkItemFactory *m_factory; GtkItemFactory *m_factory;
private: private:
wxString m_title; wxString m_title;
wxList m_items; wxList m_items;
wxWindow *m_invokingWindow; wxWindow *m_invokingWindow;

View File

@ -46,7 +46,7 @@ public:
return FALSE; return FALSE;
wxString str; wxString str;
str.Printf("Sash position = %d", newSashPosition); str.Printf( _T("Sash position = %d"), newSashPosition);
m_frame->SetStatusText(str); m_frame->SetStatusText(str);
return TRUE; return TRUE;
@ -219,15 +219,19 @@ void MyFrame::Unsplit(wxCommandEvent& WXUNUSED(event) )
void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) ) void MyFrame::SetMinSize(wxCommandEvent& WXUNUSED(event) )
{ {
wxString str; wxString str;
str.Printf("%d", m_splitter->GetMinimumPaneSize()); str.Printf( _T("%d"), m_splitter->GetMinimumPaneSize());
str = wxGetTextFromUser("Enter minimal size for panes:", "", str, this); str = wxGetTextFromUser("Enter minimal size for panes:", "", str, this);
if ( str.IsEmpty() ) if ( str.IsEmpty() )
return; return;
/*
What is atoi in Unicode?
int minsize = atoi(str); int minsize = atoi(str);
m_splitter->SetMinimumPaneSize(minsize); m_splitter->SetMinimumPaneSize(minsize);
str.Printf("Min pane size = %d", minsize); str.Printf( _T("Min pane size = %d"), minsize);
SetStatusText(str, 1); SetStatusText(str, 1);
*/
} }
void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event) void MyFrame::UpdateUIHorizontal(wxUpdateUIEvent& event)
@ -248,7 +252,7 @@ void MyFrame::UpdateUIUnsplit(wxUpdateUIEvent& event)
void MyFrame::UpdatePosition() void MyFrame::UpdatePosition()
{ {
wxString str; wxString str;
str.Printf("Sash position = %d", m_splitter->GetSashPosition()); str.Printf( _("Sash position = %d"), m_splitter->GetSashPosition());
SetStatusText(str); SetStatusText(str);
} }

View File

@ -109,10 +109,23 @@ wxWindowDC::wxWindowDC( wxWindow *window )
m_owner = (wxWindow *)NULL; m_owner = (wxWindow *)NULL;
if (!window) return; if (!window) return;
GtkWidget *widget = window->m_wxwindow; GtkWidget *widget = window->m_wxwindow;
if (!widget) return; if (!widget) return;
m_window = widget->window; m_window = widget->window;
/* not realized ? */
if (!m_window)
{
/* force realization */
gtk_widget_realize( widget );
m_window = widget->window;
}
/* still not realized ? */
if (!m_window) return; if (!m_window) return;
if (window->m_wxwindow) if (window->m_wxwindow)
m_cmap = gtk_widget_get_colormap( window->m_wxwindow ); m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
else else

View File

@ -249,13 +249,6 @@ static void wxInsertChildInFrame( wxWindow* parent, wxWindow* child )
/* resize on OnInternalIdle */ /* resize on OnInternalIdle */
parent->m_sizeSet = FALSE; parent->m_sizeSet = FALSE;
if (parent->m_windowStyle & wxTAB_TRAVERSAL)
{
/* we now allow a window to get the focus as long as it
doesn't have any children. */
GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS );
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -335,8 +328,14 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
/* m_wxwindow only represents the client area without toolbar and menubar */ /* m_wxwindow only represents the client area without toolbar and menubar */
m_wxwindow = gtk_myfixed_new(); m_wxwindow = gtk_myfixed_new();
gtk_widget_show( m_wxwindow ); gtk_widget_show( m_wxwindow );
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow );
/* we allow the frame to get the focus as otherwise no
keye vents will get sent to it. the point with this is
that the menu's key accelerators work by interceting
key events here */
GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
GTK_WIDGET_SET_FLAGS (m_wxwindow, GTK_HAS_FOCUS);
if (m_parent) m_parent->AddChild( this ); if (m_parent) m_parent->AddChild( this );
@ -763,6 +762,11 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
if (m_frameMenuBar) if (m_frameMenuBar)
{ {
/* support for native key accelerators indicated by underscroes */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
gtk_accel_group_attach( m_frameMenuBar->m_accel, GTK_OBJECT(m_wxwindow));
#endif
wxNode *node = m_frameMenuBar->GetMenus().First(); wxNode *node = m_frameMenuBar->GetMenus().First();
while (node) while (node)
{ {
@ -788,6 +792,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
} }
} }
/* resize window in OnInternalIdle */
m_sizeSet = FALSE; m_sizeSet = FALSE;
} }

View File

@ -28,13 +28,21 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
wxMenuBar::wxMenuBar( long style ) wxMenuBar::wxMenuBar( long style )
{ {
m_needParent = FALSE; // hmmm /* the parent window is known after wxFrame::SetMenu() */
m_needParent = FALSE;
PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" );
m_menus.DeleteContents( TRUE ); m_menus.DeleteContents( TRUE );
/* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
m_accel = gtk_accel_group_new();
m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "<main>", m_accel );
m_menubar = gtk_item_factory_get_widget( m_factory, "<main>" );
#else
m_menubar = gtk_menu_bar_new(); m_menubar = gtk_menu_bar_new();
#endif
if (style & wxMB_DOCKABLE) if (style & wxMB_DOCKABLE)
{ {
@ -54,13 +62,21 @@ wxMenuBar::wxMenuBar( long style )
wxMenuBar::wxMenuBar() wxMenuBar::wxMenuBar()
{ {
m_needParent = FALSE; // hmmm /* the parent window is known after wxFrame::SetMenu() */
m_needParent = FALSE;
PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" );
m_menus.DeleteContents( TRUE ); m_menus.DeleteContents( TRUE );
/* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
m_accel = gtk_accel_group_new();
m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "<main>", m_accel );
m_menubar = gtk_item_factory_get_widget( m_factory, "<main>" );
#else
m_menubar = gtk_menu_bar_new(); m_menubar = gtk_menu_bar_new();
#endif
m_widget = GTK_WIDGET(m_menubar); m_widget = GTK_WIDGET(m_menubar);
@ -69,29 +85,70 @@ wxMenuBar::wxMenuBar()
Show( TRUE ); Show( TRUE );
} }
wxMenuBar::~wxMenuBar()
{
// how to destroy a GtkItemFactory ?
}
void wxMenuBar::Append( wxMenu *menu, const wxString &title ) void wxMenuBar::Append( wxMenu *menu, const wxString &title )
{ {
m_menus.Append( menu ); m_menus.Append( menu );
wxString s = _T(""); /* GTK 1.2 wants to have "_" instead of "&" for accelerators */
wxString str;
for ( const wxChar *pc = title; *pc != _T('\0'); pc++ ) for ( const wxChar *pc = title; *pc != _T('\0'); pc++ )
{ {
if (*pc == _T('&')) if (*pc == _T('&'))
{ {
pc++; /* skip it */ pc++; /* skip it */
#if (GTK_MINOR_VERSION > 0) #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
// s << '_'; not yet str << _T('_');
#endif #endif
} }
s << *pc; str << *pc;
} }
menu->SetTitle(s); /* this doesn't have much effect right now */
menu->m_owner = gtk_menu_item_new_with_label( MBSTRINGCAST s.mbc_str() ); menu->SetTitle( str );
/* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
/* local buffer in multibyte form */
char buf[200];
strcpy( buf, "/" );
strcat( buf, str.mb_str() );
GtkItemFactoryEntry entry;
entry.path = buf;
entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0;
entry.item_type = "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */
wxString tmp = _T("<main>/");
for ( const wxChar *pc = str; *pc != _T('\0'); pc++ )
{
if (*pc == _T('_')) pc++; /* skip it */
tmp << *pc;
}
menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
#else
menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() );
gtk_widget_show( menu->m_owner ); gtk_widget_show( menu->m_owner );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner ); gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner );
#endif
} }
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
@ -420,7 +477,7 @@ void wxMenuItem::SetName( const wxString& str )
if (m_menuItem) if (m_menuItem)
{ {
GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
gtk_label_set( label, m_text.mbc_str()); gtk_label_set( label, m_text.mb_str());
} }
} }
@ -525,16 +582,18 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool
mitem->SetText(item); mitem->SetText(item);
mitem->SetHelp(helpStr); mitem->SetHelp(helpStr);
mitem->SetCheckable(checkable); mitem->SetCheckable(checkable);
const wxChar *text = mitem->GetText();
#if (GTK_MINOR_VERSION > 0) #if (GTK_MINOR_VERSION > 0)
wxChar buf[100]; /* text has "_" instead of "&" after mitem->SetText() */
wxStrcpy( buf, _T("/") ); wxString text( mitem->GetText() );
wxStrcat( buf, text );
/* local buffer in multibyte form */
char buf[200];
strcpy( buf, "/" );
strcat( buf, text.mb_str() );
const wxWX2MBbuf pbuf = wxConv_current->cWX2MB(buf);
GtkItemFactoryEntry entry; GtkItemFactoryEntry entry;
entry.path = MBSTRINGCAST pbuf; entry.path = buf;
entry.accelerator = (gchar*) NULL; entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback; entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
entry.callback_action = 0; entry.callback_action = 0;
@ -553,12 +612,12 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool
s << *pc; s << *pc;
} }
GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mbc_str() ); GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() );
#else #else
GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label(text) GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( item.mb_str() )
: gtk_menu_item_new_with_label(text); : gtk_menu_item_new_with_label( item.mb_str() );
gtk_signal_connect( GTK_OBJECT(menuItem), "activate", gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),

View File

@ -281,12 +281,11 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnDrag) return FALSE;
/* /*
printf( "OnKeyPress from " ); wxPrintf( _T("OnKeyPress from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
long key_code = 0; long key_code = 0;
switch (gdk_event->keyval) switch (gdk_event->keyval)
{ {
@ -572,6 +571,13 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk
static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
{ {
/*
wxPrintf( _T("1) OnButtonPress from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
wxPrintf( win->GetClassInfo()->GetClassName() );
wxPrintf( _T(".\n") );
*/
if (!win->HasVMT()) return FALSE; if (!win->HasVMT()) return FALSE;
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
if (g_blockEventsOnScroll) return TRUE; if (g_blockEventsOnScroll) return TRUE;
@ -585,20 +591,31 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
gtk_widget_grab_focus (win->m_wxwindow); gtk_widget_grab_focus (win->m_wxwindow);
/* /*
printf( "GrabFocus from " ); wxPrintf( _T("GrabFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
} }
/*
else
{
wxPrintf( _T("No GrabFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
wxPrintf( win->GetClassInfo()->GetClassName() );
if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
wxPrintf( _T(" because it already has") );
wxPrintf( _T(".\n") );
}
*/
} }
/* /*
printf( "OnButtonPress from " ); wxPrintf( _T("2) OnButtonPress from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
wxEventType event_type = wxEVT_LEFT_DOWN; wxEventType event_type = wxEVT_LEFT_DOWN;
@ -948,12 +965,12 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(
/* /*
printf( "OnSetFocus from " ); wxPrintf( _T("OnSetFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( " " ); wxPrintf( _T(" ") );
printf( WXSTRINGCAST win->GetLabel() ); wxPrintf( win->GetLabel() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
@ -984,10 +1001,12 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
} }
/* /*
printf( "OnKillFocus from " ); wxPrintf( _T("OnKillFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(" ") );
wxPrintf( win->GetLabel() );
wxPrintf( _T(".\n") );
*/ */
wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
@ -1314,14 +1333,14 @@ gtk_window_realized_callback( GtkWidget *widget, wxWindow *win )
if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE )) if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ))
{ {
wxColour bg( win->m_backgroundColour ); wxColour bg( win->m_backgroundColour );
win->SetBackgroundColour( wxNullColour ); win->m_backgroundColour = wxNullColour;
win->SetBackgroundColour( bg ); win->SetBackgroundColour( bg );
} }
if (win->m_foregroundColour != *wxBLACK) if (win->m_foregroundColour != *wxBLACK)
{ {
wxColour fg( win->m_foregroundColour ); wxColour fg( win->m_foregroundColour );
win->SetForegroundColour( wxNullColour ); win->m_foregroundColour = wxNullColour;
win->SetForegroundColour( fg ); win->SetForegroundColour( fg );
} }
@ -1781,12 +1800,13 @@ void wxWindow::PostCreation()
#endif #endif
} }
ConnectWidget( GetConnectWidget() ); GtkWidget *connect_widget = GetConnectWidget();
/* we cannot set colours, fonts and cursors before the widget has ConnectWidget( connect_widget );
been realized, so we do this directly after realization */
/* we cannot set colours, fonts and cursors before the widget has
gtk_signal_connect( GTK_OBJECT(m_widget), "realize", been realized, so we do this directly after realization */
gtk_signal_connect( GTK_OBJECT(connect_widget), "realize",
GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this );
m_hasVMT = TRUE; m_hasVMT = TRUE;
@ -2641,8 +2661,9 @@ void wxWindow::SetBackgroundColour( const wxColour &colour )
m_backgroundColour = colour; m_backgroundColour = colour;
if (!m_backgroundColour.Ok()) return; if (!m_backgroundColour.Ok()) return;
if (!m_widget->window) return; GtkWidget *connect_widget = GetConnectWidget();
if (!connect_widget->window) return;
if (m_wxwindow && m_wxwindow->window) if (m_wxwindow && m_wxwindow->window)
{ {
/* wxMSW doesn't clear the window here. I don't do that /* wxMSW doesn't clear the window here. I don't do that

View File

@ -109,10 +109,23 @@ wxWindowDC::wxWindowDC( wxWindow *window )
m_owner = (wxWindow *)NULL; m_owner = (wxWindow *)NULL;
if (!window) return; if (!window) return;
GtkWidget *widget = window->m_wxwindow; GtkWidget *widget = window->m_wxwindow;
if (!widget) return; if (!widget) return;
m_window = widget->window; m_window = widget->window;
/* not realized ? */
if (!m_window)
{
/* force realization */
gtk_widget_realize( widget );
m_window = widget->window;
}
/* still not realized ? */
if (!m_window) return; if (!m_window) return;
if (window->m_wxwindow) if (window->m_wxwindow)
m_cmap = gtk_widget_get_colormap( window->m_wxwindow ); m_cmap = gtk_widget_get_colormap( window->m_wxwindow );
else else

View File

@ -249,13 +249,6 @@ static void wxInsertChildInFrame( wxWindow* parent, wxWindow* child )
/* resize on OnInternalIdle */ /* resize on OnInternalIdle */
parent->m_sizeSet = FALSE; parent->m_sizeSet = FALSE;
if (parent->m_windowStyle & wxTAB_TRAVERSAL)
{
/* we now allow a window to get the focus as long as it
doesn't have any children. */
GTK_WIDGET_UNSET_FLAGS( parent->m_wxwindow, GTK_CAN_FOCUS );
}
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -335,8 +328,14 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title,
/* m_wxwindow only represents the client area without toolbar and menubar */ /* m_wxwindow only represents the client area without toolbar and menubar */
m_wxwindow = gtk_myfixed_new(); m_wxwindow = gtk_myfixed_new();
gtk_widget_show( m_wxwindow ); gtk_widget_show( m_wxwindow );
GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow ); gtk_container_add( GTK_CONTAINER(m_mainWidget), m_wxwindow );
/* we allow the frame to get the focus as otherwise no
keye vents will get sent to it. the point with this is
that the menu's key accelerators work by interceting
key events here */
GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
GTK_WIDGET_SET_FLAGS (m_wxwindow, GTK_HAS_FOCUS);
if (m_parent) m_parent->AddChild( this ); if (m_parent) m_parent->AddChild( this );
@ -763,6 +762,11 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
if (m_frameMenuBar) if (m_frameMenuBar)
{ {
/* support for native key accelerators indicated by underscroes */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
gtk_accel_group_attach( m_frameMenuBar->m_accel, GTK_OBJECT(m_wxwindow));
#endif
wxNode *node = m_frameMenuBar->GetMenus().First(); wxNode *node = m_frameMenuBar->GetMenus().First();
while (node) while (node)
{ {
@ -788,6 +792,7 @@ void wxFrame::SetMenuBar( wxMenuBar *menuBar )
} }
} }
/* resize window in OnInternalIdle */
m_sizeSet = FALSE; m_sizeSet = FALSE;
} }

View File

@ -28,13 +28,21 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
wxMenuBar::wxMenuBar( long style ) wxMenuBar::wxMenuBar( long style )
{ {
m_needParent = FALSE; // hmmm /* the parent window is known after wxFrame::SetMenu() */
m_needParent = FALSE;
PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" );
m_menus.DeleteContents( TRUE ); m_menus.DeleteContents( TRUE );
/* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
m_accel = gtk_accel_group_new();
m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "<main>", m_accel );
m_menubar = gtk_item_factory_get_widget( m_factory, "<main>" );
#else
m_menubar = gtk_menu_bar_new(); m_menubar = gtk_menu_bar_new();
#endif
if (style & wxMB_DOCKABLE) if (style & wxMB_DOCKABLE)
{ {
@ -54,13 +62,21 @@ wxMenuBar::wxMenuBar( long style )
wxMenuBar::wxMenuBar() wxMenuBar::wxMenuBar()
{ {
m_needParent = FALSE; // hmmm /* the parent window is known after wxFrame::SetMenu() */
m_needParent = FALSE;
PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" );
m_menus.DeleteContents( TRUE ); m_menus.DeleteContents( TRUE );
/* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
m_accel = gtk_accel_group_new();
m_factory = gtk_item_factory_new( GTK_TYPE_MENU_BAR, "<main>", m_accel );
m_menubar = gtk_item_factory_get_widget( m_factory, "<main>" );
#else
m_menubar = gtk_menu_bar_new(); m_menubar = gtk_menu_bar_new();
#endif
m_widget = GTK_WIDGET(m_menubar); m_widget = GTK_WIDGET(m_menubar);
@ -69,29 +85,70 @@ wxMenuBar::wxMenuBar()
Show( TRUE ); Show( TRUE );
} }
wxMenuBar::~wxMenuBar()
{
// how to destroy a GtkItemFactory ?
}
void wxMenuBar::Append( wxMenu *menu, const wxString &title ) void wxMenuBar::Append( wxMenu *menu, const wxString &title )
{ {
m_menus.Append( menu ); m_menus.Append( menu );
wxString s = _T(""); /* GTK 1.2 wants to have "_" instead of "&" for accelerators */
wxString str;
for ( const wxChar *pc = title; *pc != _T('\0'); pc++ ) for ( const wxChar *pc = title; *pc != _T('\0'); pc++ )
{ {
if (*pc == _T('&')) if (*pc == _T('&'))
{ {
pc++; /* skip it */ pc++; /* skip it */
#if (GTK_MINOR_VERSION > 0) #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
// s << '_'; not yet str << _T('_');
#endif #endif
} }
s << *pc; str << *pc;
} }
menu->SetTitle(s); /* this doesn't have much effect right now */
menu->m_owner = gtk_menu_item_new_with_label( MBSTRINGCAST s.mbc_str() ); menu->SetTitle( str );
/* GTK 1.2.0 doesn't have gtk_item_factory_get_item(), but GTK 1.2.1 has. */
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
/* local buffer in multibyte form */
char buf[200];
strcpy( buf, "/" );
strcat( buf, str.mb_str() );
GtkItemFactoryEntry entry;
entry.path = buf;
entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0;
entry.item_type = "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */
wxString tmp = _T("<main>/");
for ( const wxChar *pc = str; *pc != _T('\0'); pc++ )
{
if (*pc == _T('_')) pc++; /* skip it */
tmp << *pc;
}
menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
#else
menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() );
gtk_widget_show( menu->m_owner ); gtk_widget_show( menu->m_owner );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner ); gtk_menu_bar_append( GTK_MENU_BAR(m_menubar), menu->m_owner );
#endif
} }
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString ) static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
@ -420,7 +477,7 @@ void wxMenuItem::SetName( const wxString& str )
if (m_menuItem) if (m_menuItem)
{ {
GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child ); GtkLabel *label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
gtk_label_set( label, m_text.mbc_str()); gtk_label_set( label, m_text.mb_str());
} }
} }
@ -525,16 +582,18 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool
mitem->SetText(item); mitem->SetText(item);
mitem->SetHelp(helpStr); mitem->SetHelp(helpStr);
mitem->SetCheckable(checkable); mitem->SetCheckable(checkable);
const wxChar *text = mitem->GetText();
#if (GTK_MINOR_VERSION > 0) #if (GTK_MINOR_VERSION > 0)
wxChar buf[100]; /* text has "_" instead of "&" after mitem->SetText() */
wxStrcpy( buf, _T("/") ); wxString text( mitem->GetText() );
wxStrcat( buf, text );
/* local buffer in multibyte form */
char buf[200];
strcpy( buf, "/" );
strcat( buf, text.mb_str() );
const wxWX2MBbuf pbuf = wxConv_current->cWX2MB(buf);
GtkItemFactoryEntry entry; GtkItemFactoryEntry entry;
entry.path = MBSTRINGCAST pbuf; entry.path = buf;
entry.accelerator = (gchar*) NULL; entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback; entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
entry.callback_action = 0; entry.callback_action = 0;
@ -553,12 +612,12 @@ void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool
s << *pc; s << *pc;
} }
GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mbc_str() ); GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, s.mb_str() );
#else #else
GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label(text) GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( item.mb_str() )
: gtk_menu_item_new_with_label(text); : gtk_menu_item_new_with_label( item.mb_str() );
gtk_signal_connect( GTK_OBJECT(menuItem), "activate", gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),

View File

@ -281,12 +281,11 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
if (g_blockEventsOnDrag) return FALSE; if (g_blockEventsOnDrag) return FALSE;
/* /*
printf( "OnKeyPress from " ); wxPrintf( _T("OnKeyPress from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
long key_code = 0; long key_code = 0;
switch (gdk_event->keyval) switch (gdk_event->keyval)
{ {
@ -572,6 +571,13 @@ static gint gtk_window_key_release_callback( GtkWidget *widget, GdkEventKey *gdk
static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win ) static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
{ {
/*
wxPrintf( _T("1) OnButtonPress from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
wxPrintf( win->GetClassInfo()->GetClassName() );
wxPrintf( _T(".\n") );
*/
if (!win->HasVMT()) return FALSE; if (!win->HasVMT()) return FALSE;
if (g_blockEventsOnDrag) return TRUE; if (g_blockEventsOnDrag) return TRUE;
if (g_blockEventsOnScroll) return TRUE; if (g_blockEventsOnScroll) return TRUE;
@ -585,20 +591,31 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
gtk_widget_grab_focus (win->m_wxwindow); gtk_widget_grab_focus (win->m_wxwindow);
/* /*
printf( "GrabFocus from " ); wxPrintf( _T("GrabFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
} }
/*
else
{
wxPrintf( _T("No GrabFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
wxPrintf( win->GetClassInfo()->GetClassName() );
if (GTK_WIDGET_CAN_FOCUS(win->m_wxwindow))
wxPrintf( _T(" because it already has") );
wxPrintf( _T(".\n") );
}
*/
} }
/* /*
printf( "OnButtonPress from " ); wxPrintf( _T("2) OnButtonPress from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
wxEventType event_type = wxEVT_LEFT_DOWN; wxEventType event_type = wxEVT_LEFT_DOWN;
@ -948,12 +965,12 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, GdkEvent *WXUNUSED(
/* /*
printf( "OnSetFocus from " ); wxPrintf( _T("OnSetFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( " " ); wxPrintf( _T(" ") );
printf( WXSTRINGCAST win->GetLabel() ); wxPrintf( win->GetLabel() );
printf( ".\n" ); wxPrintf( _T(".\n") );
*/ */
wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() ); wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
@ -984,10 +1001,12 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
} }
/* /*
printf( "OnKillFocus from " ); wxPrintf( _T("OnKillFocus from ") );
if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
printf( win->GetClassInfo()->GetClassName() ); wxPrintf( win->GetClassInfo()->GetClassName() );
printf( ".\n" ); wxPrintf( _T(" ") );
wxPrintf( win->GetLabel() );
wxPrintf( _T(".\n") );
*/ */
wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() );
@ -1314,14 +1333,14 @@ gtk_window_realized_callback( GtkWidget *widget, wxWindow *win )
if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE )) if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ))
{ {
wxColour bg( win->m_backgroundColour ); wxColour bg( win->m_backgroundColour );
win->SetBackgroundColour( wxNullColour ); win->m_backgroundColour = wxNullColour;
win->SetBackgroundColour( bg ); win->SetBackgroundColour( bg );
} }
if (win->m_foregroundColour != *wxBLACK) if (win->m_foregroundColour != *wxBLACK)
{ {
wxColour fg( win->m_foregroundColour ); wxColour fg( win->m_foregroundColour );
win->SetForegroundColour( wxNullColour ); win->m_foregroundColour = wxNullColour;
win->SetForegroundColour( fg ); win->SetForegroundColour( fg );
} }
@ -1781,12 +1800,13 @@ void wxWindow::PostCreation()
#endif #endif
} }
ConnectWidget( GetConnectWidget() ); GtkWidget *connect_widget = GetConnectWidget();
/* we cannot set colours, fonts and cursors before the widget has ConnectWidget( connect_widget );
been realized, so we do this directly after realization */
/* we cannot set colours, fonts and cursors before the widget has
gtk_signal_connect( GTK_OBJECT(m_widget), "realize", been realized, so we do this directly after realization */
gtk_signal_connect( GTK_OBJECT(connect_widget), "realize",
GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this );
m_hasVMT = TRUE; m_hasVMT = TRUE;
@ -2641,8 +2661,9 @@ void wxWindow::SetBackgroundColour( const wxColour &colour )
m_backgroundColour = colour; m_backgroundColour = colour;
if (!m_backgroundColour.Ok()) return; if (!m_backgroundColour.Ok()) return;
if (!m_widget->window) return; GtkWidget *connect_widget = GetConnectWidget();
if (!connect_widget->window) return;
if (m_wxwindow && m_wxwindow->window) if (m_wxwindow && m_wxwindow->window)
{ {
/* wxMSW doesn't clear the window here. I don't do that /* wxMSW doesn't clear the window here. I don't do that