From 2b07d7130880c63b7f7908606a10f885e2719efc Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 24 Apr 1999 21:57:18 +0000 Subject: [PATCH] Had to change the time point, when widgets are created (no longer forced). This seems to break wxNotebook... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2276 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/controls/controls.cpp | 1 + src/gtk/checkbox.cpp | 3 -- src/gtk/choice.cpp | 12 +++--- src/gtk/combobox.cpp | 15 ++++--- src/gtk/dcclient.cpp | 8 ---- src/gtk/dialog.cpp | 77 +++++++++++++++++++++-------------- src/gtk/frame.cpp | 77 +++++++++++++++++++++-------------- src/gtk/listbox.cpp | 16 +++++--- src/gtk/notebook.cpp | 4 +- src/gtk/window.cpp | 72 ++++++++++++++++++++++++++++---- src/gtk1/checkbox.cpp | 3 -- src/gtk1/choice.cpp | 12 +++--- src/gtk1/combobox.cpp | 15 ++++--- src/gtk1/dcclient.cpp | 8 ---- src/gtk1/dialog.cpp | 77 +++++++++++++++++++++-------------- src/gtk1/frame.cpp | 77 +++++++++++++++++++++-------------- src/gtk1/listbox.cpp | 16 +++++--- src/gtk1/notebook.cpp | 4 +- src/gtk1/window.cpp | 72 ++++++++++++++++++++++++++++---- 19 files changed, 363 insertions(+), 206 deletions(-) diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index 3f1df49a66..5365385b03 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -474,6 +474,7 @@ m_text(NULL), m_notebook(NULL) panel = new wxPanel(m_notebook); m_choice = new wxChoice( panel, ID_CHOICE, wxPoint(10,10), wxSize(120,-1), 5, choices ); + m_choice->SetBackgroundColour( "red" ); (void)new wxButton( panel, ID_CHOICE_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); (void)new wxButton( panel, ID_CHOICE_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); (void)new wxButton( panel, ID_CHOICE_CLEAR, "Clear", wxPoint(180,80), wxSize(140,30) ); diff --git a/src/gtk/checkbox.cpp b/src/gtk/checkbox.cpp index d4023c5a04..8cda3d112b 100644 --- a/src/gtk/checkbox.cpp +++ b/src/gtk/checkbox.cpp @@ -121,9 +121,6 @@ bool wxCheckBox::Create(wxWindow *parent, PostCreation(); - gtk_widget_realize( m_widgetLabel ); - gtk_widget_realize( m_widgetCheckbox ); - SetBackgroundColour( parent->GetBackgroundColour() ); SetForegroundColour( parent->GetForegroundColour() ); SetFont( parent->GetFont() ); diff --git a/src/gtk/choice.cpp b/src/gtk/choice.cpp index 2c1d4c702c..ba049f6447 100644 --- a/src/gtk/choice.cpp +++ b/src/gtk/choice.cpp @@ -85,9 +85,6 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, GtkWidget *item = gtk_menu_item_new_with_label( choices[i].mbc_str() ); gtk_menu_append( GTK_MENU(menu), item ); - gtk_widget_realize( item ); - gtk_widget_realize( GTK_BIN(item)->child ); - gtk_widget_show( item ); gtk_signal_connect( GTK_OBJECT( item ), "activate", @@ -124,10 +121,13 @@ void wxChoice::AppendCommon( const wxString &item ) gtk_menu_append( GTK_MENU(menu), menu_item ); - gtk_widget_realize( menu_item ); - gtk_widget_realize( GTK_BIN(menu_item)->child ); + if (GTK_WIDGET_REALIZED(m_widget)) + { + gtk_widget_realize( menu_item ); + gtk_widget_realize( GTK_BIN(menu_item)->child ); - if (m_widgetStyle) ApplyWidgetStyle(); + if (m_widgetStyle) ApplyWidgetStyle(); + } gtk_signal_connect( GTK_OBJECT( menu_item ), "activate", GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this ); diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 54aea8e647..c202ba56eb 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -113,9 +113,6 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, gtk_container_add( GTK_CONTAINER(list), list_item ); - gtk_widget_realize( list_item ); - gtk_widget_realize( GTK_BIN(list_item)->child ); - gtk_widget_show( list_item ); gtk_signal_connect( GTK_OBJECT(list_item), "select", @@ -132,10 +129,6 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, if (!value.IsNull()) SetValue( value ); - gtk_widget_realize( GTK_COMBO(m_widget)->list ); - gtk_widget_realize( GTK_COMBO(m_widget)->entry ); - gtk_widget_realize( GTK_COMBO(m_widget)->button ); - if (style & wxCB_READONLY) gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO(m_widget)->entry ), FALSE ); @@ -176,7 +169,13 @@ void wxComboBox::AppendCommon( const wxString &item ) gtk_container_add( GTK_CONTAINER(list), list_item ); - if (m_widgetStyle) ApplyWidgetStyle(); + if (GTK_WIDGET_REALIZED(m_widget)) + { + gtk_widget_realize( list_item ); + gtk_widget_realize( GTK_BIN(list_item)->child ); + + if (m_widgetStyle) ApplyWidgetStyle(); + } gtk_widget_show( list_item ); } diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 2cdeb7137a..ffd5d9ef15 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -825,8 +825,6 @@ void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *heigh long *descent, long *externalLeading, wxFont *theFont, bool WXUNUSED(use16) ) { - wxCHECK_RET( Ok(), _T("invalid window dc") ); - wxFont fontToUse = m_font; if (theFont) fontToUse = *theFont; @@ -839,16 +837,12 @@ void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *heigh long wxWindowDC::GetCharWidth() { - wxCHECK_MSG( Ok(), 0, _T("invalid window dc") ); - GdkFont *font = m_font.GetInternalFont( m_scaleY ); return long(gdk_string_width( font, "H" ) / m_scaleX); } long wxWindowDC::GetCharHeight() { - wxCHECK_MSG( Ok(), 0, _T("invalid window dc") ); - GdkFont *font = m_font.GetInternalFont( m_scaleY ); return long((font->ascent + font->descent) / m_scaleY); } @@ -883,8 +877,6 @@ void wxWindowDC::Clear() void wxWindowDC::SetFont( const wxFont &font ) { - wxCHECK_RET( Ok(), _T("invalid window dc") ); - m_font = font; } diff --git a/src/gtk/dialog.cpp b/src/gtk/dialog.cpp index 7edb2940c8..427557a8c6 100644 --- a/src/gtk/dialog.cpp +++ b/src/gtk/dialog.cpp @@ -82,6 +82,48 @@ static gint gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEvent return FALSE; } +//----------------------------------------------------------------------------- +// "realize" from m_widget +//----------------------------------------------------------------------------- + +/* we cannot MWM hints before the widget has been realized, + so we do this directly after realization */ + +static gint +gtk_dialog_realized_callback( GtkWidget *widget, wxWindow *win ) +{ + /* all this is for Motif Window Manager "hints" and is supposed to be + recognized by other WM as well. not tested. */ + long decor = (long) GDK_DECOR_ALL; + long func = (long) GDK_FUNC_ALL; + + if ((win->m_windowStyle & wxCAPTION) == 0) + decor |= GDK_DECOR_TITLE; +/* if ((win->m_windowStyle & wxMINIMIZE) == 0) + func |= GDK_FUNC_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE) == 0) + func |= GDK_FUNC_MAXIMIZE; */ + if ((win->m_windowStyle & wxSYSTEM_MENU) == 0) + decor |= GDK_DECOR_MENU; + if ((win->m_windowStyle & wxMINIMIZE_BOX) == 0) + decor |= GDK_DECOR_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE_BOX) == 0) + decor |= GDK_DECOR_MAXIMIZE; + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + func |= GDK_FUNC_RESIZE; + + gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); + gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); + + /* GTK's shrinking/growing policy */ + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); + else + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); + + return FALSE; +} + //----------------------------------------------------------------------------- // wxDialog //----------------------------------------------------------------------------- @@ -143,37 +185,12 @@ bool wxDialog::Create( wxWindow *parent, PostCreation(); - gtk_widget_realize( m_widget ); - - /* all this is for Motif Window Manager "hints" and is supposed to be - recognized by other WM as well. not tested. */ - long decor = (long) GDK_DECOR_ALL; - long func = (long) GDK_FUNC_ALL; + /* we cannot set MWM hints before the widget has + been realized, so we do this directly after realization */ + gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + GTK_SIGNAL_FUNC(gtk_dialog_realized_callback), (gpointer) this ); - if ((m_windowStyle & wxCAPTION) == 0) - decor |= GDK_DECOR_TITLE; -/* if ((m_windowStyle & wxMINIMIZE) == 0) - func |= GDK_FUNC_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE) == 0) - func |= GDK_FUNC_MAXIMIZE; */ - if ((m_windowStyle & wxSYSTEM_MENU) == 0) - decor |= GDK_DECOR_MENU; - if ((m_windowStyle & wxMINIMIZE_BOX) == 0) - decor |= GDK_DECOR_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE_BOX) == 0) - decor |= GDK_DECOR_MAXIMIZE; - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - func |= GDK_FUNC_RESIZE; - - gdk_window_set_decorations(m_widget->window, (GdkWMDecoration)decor); - gdk_window_set_functions(m_widget->window, (GdkWMFunction)func); - - /* GTK's shrinking/growing policy */ - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - gtk_window_set_policy(GTK_WINDOW(m_widget), 0, 0, 1); - else - gtk_window_set_policy(GTK_WINDOW(m_widget), 1, 1, 1); - + /* the user resized the frame by dragging etc. */ gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", GTK_SIGNAL_FUNC(gtk_dialog_size_callback), (gpointer)this ); diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 288579b661..edef46b4ee 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -146,6 +146,48 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC return FALSE; } +//----------------------------------------------------------------------------- +// "realize" from m_widget +//----------------------------------------------------------------------------- + +/* we cannot MWM hints before the widget has been realized, + so we do this directly after realization */ + +static gint +gtk_frame_realized_callback( GtkWidget *widget, wxWindow *win ) +{ + /* all this is for Motif Window Manager "hints" and is supposed to be + recognized by other WM as well. not tested. */ + long decor = (long) GDK_DECOR_ALL; + long func = (long) GDK_FUNC_ALL; + + if ((win->m_windowStyle & wxCAPTION) == 0) + decor |= GDK_DECOR_TITLE; +/* if ((win->m_windowStyle & wxMINIMIZE) == 0) + func |= GDK_FUNC_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE) == 0) + func |= GDK_FUNC_MAXIMIZE; */ + if ((win->m_windowStyle & wxSYSTEM_MENU) == 0) + decor |= GDK_DECOR_MENU; + if ((win->m_windowStyle & wxMINIMIZE_BOX) == 0) + decor |= GDK_DECOR_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE_BOX) == 0) + decor |= GDK_DECOR_MAXIMIZE; + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + func |= GDK_FUNC_RESIZE; + + gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); + gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); + + /* GTK's shrinking/growing policy */ + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); + else + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); + + return FALSE; +} + //----------------------------------------------------------------------------- // InsertChild for wxFrame //----------------------------------------------------------------------------- @@ -281,7 +323,6 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, gtk_widget_show( m_mainWidget ); GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); - gtk_widget_realize( m_mainWidget ); /* m_wxwindow only represents the client area without toolbar and menubar */ m_wxwindow = gtk_myfixed_new(); @@ -293,37 +334,11 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, PostCreation(); - gtk_widget_realize( m_widget ); + /* we cannot set MWM hints before the widget has + been realized, so we do this directly after realization */ + gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + GTK_SIGNAL_FUNC(gtk_frame_realized_callback), (gpointer) this ); - /* all this is for Motif Window Manager "hints" and is supposed to be - recognized by other WM as well. not tested. */ - long decor = (long) GDK_DECOR_ALL; - long func = (long) GDK_FUNC_ALL; - - if ((m_windowStyle & wxCAPTION) == 0) - decor |= GDK_DECOR_TITLE; -/* if ((m_windowStyle & wxMINIMIZE) == 0) - func |= GDK_FUNC_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE) == 0) - func |= GDK_FUNC_MAXIMIZE; */ - if ((m_windowStyle & wxSYSTEM_MENU) == 0) - decor |= GDK_DECOR_MENU; - if ((m_windowStyle & wxMINIMIZE_BOX) == 0) - decor |= GDK_DECOR_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE_BOX) == 0) - decor |= GDK_DECOR_MAXIMIZE; - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - func |= GDK_FUNC_RESIZE; - - gdk_window_set_decorations(m_widget->window, (GdkWMDecoration)decor); - gdk_window_set_functions(m_widget->window, (GdkWMFunction)func); - - /* GTK's shrinking/growing policy */ - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - gtk_window_set_policy(GTK_WINDOW(m_widget), 0, 0, 1); - else - gtk_window_set_policy(GTK_WINDOW(m_widget), 1, 1, 1); - /* the user resized the frame by dragging etc. */ gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index e20908585c..138fc38d96 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -274,8 +274,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, PostCreation(); - gtk_widget_realize( GTK_WIDGET(m_list) ); - SetBackgroundColour( parent->GetBackgroundColour() ); SetForegroundColour( parent->GetForegroundColour() ); SetFont( parent->GetFont() ); @@ -411,8 +409,6 @@ void wxListBox::AppendCommon( const wxString &item ) gtk_signal_connect( GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - if (m_widgetStyle) ApplyWidgetStyle(); - gtk_signal_connect( GTK_OBJECT(list_item), "button_press_event", (GtkSignalFunc)gtk_listbox_button_press_callback, @@ -430,15 +426,23 @@ void wxListBox::AppendCommon( const wxString &item ) ConnectWidget( list_item ); + if (GTK_WIDGET_REALIZED(m_widget)) + { + gtk_widget_realize( list_item ); + gtk_widget_realize( GTK_BIN(list_item)->child ); + + if (m_widgetStyle) ApplyWidgetStyle(); + #if wxUSE_DRAG_AND_DROP #ifndef NEW_GTK_DND_CODE - if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); + if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); #endif #endif #if wxUSE_TOOLTIPS - if (m_toolTip) m_toolTip->Apply( this ); + if (m_toolTip) m_toolTip->Apply( this ); #endif + } } void wxListBox::Append( const wxString &item ) diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 364487fafc..eb13d01f46 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -109,9 +109,9 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* (win->m_width == alloc->width) && (win->m_height == alloc->height)) { - return; +// return; } - + win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); if (win->GetAutoLayout()) win->Layout(); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index a84758ad85..2c6b88d560 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1294,6 +1294,40 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, return FALSE; } +//----------------------------------------------------------------------------- +// "realize" from m_widget +//----------------------------------------------------------------------------- + +/* we cannot set colours, fonts and cursors before the widget has + been realized, so we do this directly after realization */ + +static gint +gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) +{ + if (win->m_font != *wxSWISS_FONT) + { + wxFont font( win->m_font ); + win->m_font = wxNullFont; + win->SetFont( font ); + } + + if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE )) + { + wxColour bg( win->m_backgroundColour ); + win->m_backgroundColour = wxNullColour; + win->SetBackgroundColour( bg ); + } + + if (win->m_foregroundColour != *wxBLACK) + { + wxColour fg( win->m_foregroundColour ); + win->m_foregroundColour = wxNullColour; + win->SetForegroundColour( fg ); + } + + return FALSE; +} + //----------------------------------------------------------------------------- // InsertChild for wxWindow. //----------------------------------------------------------------------------- @@ -1750,13 +1784,12 @@ void wxWindow::PostCreation() ConnectWidget( GetConnectWidget() ); - /* we force the creation of wxFrame and wxDialog in the respective code */ - if (m_parent) gtk_widget_realize( m_widget ); - - if (m_wxwindow) gtk_widget_realize( m_wxwindow ); - - SetCursor( *wxSTANDARD_CURSOR ); - +/* we cannot set colours, fonts and cursors before the widget has + been realized, so we do this directly after realization */ + + gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); + m_hasVMT = TRUE; } @@ -2071,6 +2104,8 @@ void wxWindow::ClientToScreen( int *x, int *y ) { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) source = m_wxwindow->window; @@ -2098,6 +2133,8 @@ void wxWindow::ScreenToClient( int *x, int *y ) { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) source = m_wxwindow->window; @@ -2351,6 +2388,8 @@ void wxWindow::Raise() { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + if (m_widget) gdk_window_raise( m_widget->window ); } @@ -2358,6 +2397,8 @@ void wxWindow::Lower() { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + if (m_widget) gdk_window_lower( m_widget->window ); } @@ -2459,8 +2500,9 @@ void wxWindow::SetCursor( const wxCursor &cursor ) *m_cursor = *wxSTANDARD_CURSOR; } - if ((m_widget) && (m_widget->window)) - gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() ); + if (!m_widget->window) return; + + gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() ); if ((m_wxwindow) && (m_wxwindow->window)) gdk_window_set_cursor( m_wxwindow->window, m_cursor->GetCursor() ); @@ -2475,6 +2517,8 @@ void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + if (eraseBackground && m_wxwindow && m_wxwindow->window) { if (rect) @@ -2540,6 +2584,8 @@ void wxWindow::Clear() { wxCHECK_RET( m_widget != NULL, _T("invalid window") ); + if (!m_widget->window) return; + if (m_wxwindow && m_wxwindow->window) { gdk_window_clear( m_wxwindow->window ); @@ -2596,6 +2642,8 @@ void wxWindow::SetBackgroundColour( const wxColour &colour ) m_backgroundColour = colour; if (!m_backgroundColour.Ok()) return; + if (!m_widget->window) return; + if (m_wxwindow && m_wxwindow->window) { /* wxMSW doesn't clear the window here. I don't do that @@ -2636,6 +2684,8 @@ void wxWindow::SetForegroundColour( const wxColour &colour ) m_foregroundColour = colour; if (!m_foregroundColour.Ok()) return; + if (!m_widget->window) return; + wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); if (sysbg.Red() == colour.Red() && sysbg.Green() == colour.Green() && @@ -2896,6 +2946,8 @@ void wxWindow::CaptureMouse() wxCHECK_RET( g_capturing == FALSE, _T("CaptureMouse called twice") ); + if (!m_widget->window) return; + GtkWidget *connect_widget = GetConnectWidget(); gtk_grab_add( connect_widget ); gdk_pointer_grab( connect_widget->window, FALSE, @@ -2915,6 +2967,8 @@ void wxWindow::ReleaseMouse() wxCHECK_RET( g_capturing == TRUE, _T("ReleaseMouse called twice") ); + if (!m_widget->window) return; + GtkWidget *connect_widget = GetConnectWidget(); gtk_grab_remove( connect_widget ); gdk_pointer_ungrab ( GDK_CURRENT_TIME ); diff --git a/src/gtk1/checkbox.cpp b/src/gtk1/checkbox.cpp index d4023c5a04..8cda3d112b 100644 --- a/src/gtk1/checkbox.cpp +++ b/src/gtk1/checkbox.cpp @@ -121,9 +121,6 @@ bool wxCheckBox::Create(wxWindow *parent, PostCreation(); - gtk_widget_realize( m_widgetLabel ); - gtk_widget_realize( m_widgetCheckbox ); - SetBackgroundColour( parent->GetBackgroundColour() ); SetForegroundColour( parent->GetForegroundColour() ); SetFont( parent->GetFont() ); diff --git a/src/gtk1/choice.cpp b/src/gtk1/choice.cpp index 2c1d4c702c..ba049f6447 100644 --- a/src/gtk1/choice.cpp +++ b/src/gtk1/choice.cpp @@ -85,9 +85,6 @@ bool wxChoice::Create( wxWindow *parent, wxWindowID id, GtkWidget *item = gtk_menu_item_new_with_label( choices[i].mbc_str() ); gtk_menu_append( GTK_MENU(menu), item ); - gtk_widget_realize( item ); - gtk_widget_realize( GTK_BIN(item)->child ); - gtk_widget_show( item ); gtk_signal_connect( GTK_OBJECT( item ), "activate", @@ -124,10 +121,13 @@ void wxChoice::AppendCommon( const wxString &item ) gtk_menu_append( GTK_MENU(menu), menu_item ); - gtk_widget_realize( menu_item ); - gtk_widget_realize( GTK_BIN(menu_item)->child ); + if (GTK_WIDGET_REALIZED(m_widget)) + { + gtk_widget_realize( menu_item ); + gtk_widget_realize( GTK_BIN(menu_item)->child ); - if (m_widgetStyle) ApplyWidgetStyle(); + if (m_widgetStyle) ApplyWidgetStyle(); + } gtk_signal_connect( GTK_OBJECT( menu_item ), "activate", GTK_SIGNAL_FUNC(gtk_choice_clicked_callback), (gpointer*)this ); diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 54aea8e647..c202ba56eb 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -113,9 +113,6 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, gtk_container_add( GTK_CONTAINER(list), list_item ); - gtk_widget_realize( list_item ); - gtk_widget_realize( GTK_BIN(list_item)->child ); - gtk_widget_show( list_item ); gtk_signal_connect( GTK_OBJECT(list_item), "select", @@ -132,10 +129,6 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, if (!value.IsNull()) SetValue( value ); - gtk_widget_realize( GTK_COMBO(m_widget)->list ); - gtk_widget_realize( GTK_COMBO(m_widget)->entry ); - gtk_widget_realize( GTK_COMBO(m_widget)->button ); - if (style & wxCB_READONLY) gtk_entry_set_editable( GTK_ENTRY( GTK_COMBO(m_widget)->entry ), FALSE ); @@ -176,7 +169,13 @@ void wxComboBox::AppendCommon( const wxString &item ) gtk_container_add( GTK_CONTAINER(list), list_item ); - if (m_widgetStyle) ApplyWidgetStyle(); + if (GTK_WIDGET_REALIZED(m_widget)) + { + gtk_widget_realize( list_item ); + gtk_widget_realize( GTK_BIN(list_item)->child ); + + if (m_widgetStyle) ApplyWidgetStyle(); + } gtk_widget_show( list_item ); } diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 2cdeb7137a..ffd5d9ef15 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -825,8 +825,6 @@ void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *heigh long *descent, long *externalLeading, wxFont *theFont, bool WXUNUSED(use16) ) { - wxCHECK_RET( Ok(), _T("invalid window dc") ); - wxFont fontToUse = m_font; if (theFont) fontToUse = *theFont; @@ -839,16 +837,12 @@ void wxWindowDC::GetTextExtent( const wxString &string, long *width, long *heigh long wxWindowDC::GetCharWidth() { - wxCHECK_MSG( Ok(), 0, _T("invalid window dc") ); - GdkFont *font = m_font.GetInternalFont( m_scaleY ); return long(gdk_string_width( font, "H" ) / m_scaleX); } long wxWindowDC::GetCharHeight() { - wxCHECK_MSG( Ok(), 0, _T("invalid window dc") ); - GdkFont *font = m_font.GetInternalFont( m_scaleY ); return long((font->ascent + font->descent) / m_scaleY); } @@ -883,8 +877,6 @@ void wxWindowDC::Clear() void wxWindowDC::SetFont( const wxFont &font ) { - wxCHECK_RET( Ok(), _T("invalid window dc") ); - m_font = font; } diff --git a/src/gtk1/dialog.cpp b/src/gtk1/dialog.cpp index 7edb2940c8..427557a8c6 100644 --- a/src/gtk1/dialog.cpp +++ b/src/gtk1/dialog.cpp @@ -82,6 +82,48 @@ static gint gtk_dialog_configure_callback( GtkWidget *WXUNUSED(widget), GdkEvent return FALSE; } +//----------------------------------------------------------------------------- +// "realize" from m_widget +//----------------------------------------------------------------------------- + +/* we cannot MWM hints before the widget has been realized, + so we do this directly after realization */ + +static gint +gtk_dialog_realized_callback( GtkWidget *widget, wxWindow *win ) +{ + /* all this is for Motif Window Manager "hints" and is supposed to be + recognized by other WM as well. not tested. */ + long decor = (long) GDK_DECOR_ALL; + long func = (long) GDK_FUNC_ALL; + + if ((win->m_windowStyle & wxCAPTION) == 0) + decor |= GDK_DECOR_TITLE; +/* if ((win->m_windowStyle & wxMINIMIZE) == 0) + func |= GDK_FUNC_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE) == 0) + func |= GDK_FUNC_MAXIMIZE; */ + if ((win->m_windowStyle & wxSYSTEM_MENU) == 0) + decor |= GDK_DECOR_MENU; + if ((win->m_windowStyle & wxMINIMIZE_BOX) == 0) + decor |= GDK_DECOR_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE_BOX) == 0) + decor |= GDK_DECOR_MAXIMIZE; + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + func |= GDK_FUNC_RESIZE; + + gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); + gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); + + /* GTK's shrinking/growing policy */ + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); + else + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); + + return FALSE; +} + //----------------------------------------------------------------------------- // wxDialog //----------------------------------------------------------------------------- @@ -143,37 +185,12 @@ bool wxDialog::Create( wxWindow *parent, PostCreation(); - gtk_widget_realize( m_widget ); - - /* all this is for Motif Window Manager "hints" and is supposed to be - recognized by other WM as well. not tested. */ - long decor = (long) GDK_DECOR_ALL; - long func = (long) GDK_FUNC_ALL; + /* we cannot set MWM hints before the widget has + been realized, so we do this directly after realization */ + gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + GTK_SIGNAL_FUNC(gtk_dialog_realized_callback), (gpointer) this ); - if ((m_windowStyle & wxCAPTION) == 0) - decor |= GDK_DECOR_TITLE; -/* if ((m_windowStyle & wxMINIMIZE) == 0) - func |= GDK_FUNC_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE) == 0) - func |= GDK_FUNC_MAXIMIZE; */ - if ((m_windowStyle & wxSYSTEM_MENU) == 0) - decor |= GDK_DECOR_MENU; - if ((m_windowStyle & wxMINIMIZE_BOX) == 0) - decor |= GDK_DECOR_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE_BOX) == 0) - decor |= GDK_DECOR_MAXIMIZE; - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - func |= GDK_FUNC_RESIZE; - - gdk_window_set_decorations(m_widget->window, (GdkWMDecoration)decor); - gdk_window_set_functions(m_widget->window, (GdkWMFunction)func); - - /* GTK's shrinking/growing policy */ - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - gtk_window_set_policy(GTK_WINDOW(m_widget), 0, 0, 1); - else - gtk_window_set_policy(GTK_WINDOW(m_widget), 1, 1, 1); - + /* the user resized the frame by dragging etc. */ gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", GTK_SIGNAL_FUNC(gtk_dialog_size_callback), (gpointer)this ); diff --git a/src/gtk1/frame.cpp b/src/gtk1/frame.cpp index 288579b661..edef46b4ee 100644 --- a/src/gtk1/frame.cpp +++ b/src/gtk1/frame.cpp @@ -146,6 +146,48 @@ static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventC return FALSE; } +//----------------------------------------------------------------------------- +// "realize" from m_widget +//----------------------------------------------------------------------------- + +/* we cannot MWM hints before the widget has been realized, + so we do this directly after realization */ + +static gint +gtk_frame_realized_callback( GtkWidget *widget, wxWindow *win ) +{ + /* all this is for Motif Window Manager "hints" and is supposed to be + recognized by other WM as well. not tested. */ + long decor = (long) GDK_DECOR_ALL; + long func = (long) GDK_FUNC_ALL; + + if ((win->m_windowStyle & wxCAPTION) == 0) + decor |= GDK_DECOR_TITLE; +/* if ((win->m_windowStyle & wxMINIMIZE) == 0) + func |= GDK_FUNC_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE) == 0) + func |= GDK_FUNC_MAXIMIZE; */ + if ((win->m_windowStyle & wxSYSTEM_MENU) == 0) + decor |= GDK_DECOR_MENU; + if ((win->m_windowStyle & wxMINIMIZE_BOX) == 0) + decor |= GDK_DECOR_MINIMIZE; + if ((win->m_windowStyle & wxMAXIMIZE_BOX) == 0) + decor |= GDK_DECOR_MAXIMIZE; + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + func |= GDK_FUNC_RESIZE; + + gdk_window_set_decorations( win->m_widget->window, (GdkWMDecoration)decor); + gdk_window_set_functions( win->m_widget->window, (GdkWMFunction)func); + + /* GTK's shrinking/growing policy */ + if ((win->m_windowStyle & wxRESIZE_BORDER) == 0) + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 0, 0, 1); + else + gtk_window_set_policy(GTK_WINDOW(win->m_widget), 1, 1, 1); + + return FALSE; +} + //----------------------------------------------------------------------------- // InsertChild for wxFrame //----------------------------------------------------------------------------- @@ -281,7 +323,6 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, gtk_widget_show( m_mainWidget ); GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); - gtk_widget_realize( m_mainWidget ); /* m_wxwindow only represents the client area without toolbar and menubar */ m_wxwindow = gtk_myfixed_new(); @@ -293,37 +334,11 @@ bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, PostCreation(); - gtk_widget_realize( m_widget ); + /* we cannot set MWM hints before the widget has + been realized, so we do this directly after realization */ + gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + GTK_SIGNAL_FUNC(gtk_frame_realized_callback), (gpointer) this ); - /* all this is for Motif Window Manager "hints" and is supposed to be - recognized by other WM as well. not tested. */ - long decor = (long) GDK_DECOR_ALL; - long func = (long) GDK_FUNC_ALL; - - if ((m_windowStyle & wxCAPTION) == 0) - decor |= GDK_DECOR_TITLE; -/* if ((m_windowStyle & wxMINIMIZE) == 0) - func |= GDK_FUNC_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE) == 0) - func |= GDK_FUNC_MAXIMIZE; */ - if ((m_windowStyle & wxSYSTEM_MENU) == 0) - decor |= GDK_DECOR_MENU; - if ((m_windowStyle & wxMINIMIZE_BOX) == 0) - decor |= GDK_DECOR_MINIMIZE; - if ((m_windowStyle & wxMAXIMIZE_BOX) == 0) - decor |= GDK_DECOR_MAXIMIZE; - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - func |= GDK_FUNC_RESIZE; - - gdk_window_set_decorations(m_widget->window, (GdkWMDecoration)decor); - gdk_window_set_functions(m_widget->window, (GdkWMFunction)func); - - /* GTK's shrinking/growing policy */ - if ((m_windowStyle & wxRESIZE_BORDER) == 0) - gtk_window_set_policy(GTK_WINDOW(m_widget), 0, 0, 1); - else - gtk_window_set_policy(GTK_WINDOW(m_widget), 1, 1, 1); - /* the user resized the frame by dragging etc. */ gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index e20908585c..138fc38d96 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -274,8 +274,6 @@ bool wxListBox::Create( wxWindow *parent, wxWindowID id, PostCreation(); - gtk_widget_realize( GTK_WIDGET(m_list) ); - SetBackgroundColour( parent->GetBackgroundColour() ); SetForegroundColour( parent->GetForegroundColour() ); SetFont( parent->GetFont() ); @@ -411,8 +409,6 @@ void wxListBox::AppendCommon( const wxString &item ) gtk_signal_connect( GTK_OBJECT(list_item), "deselect", GTK_SIGNAL_FUNC(gtk_listitem_select_callback), (gpointer)this ); - if (m_widgetStyle) ApplyWidgetStyle(); - gtk_signal_connect( GTK_OBJECT(list_item), "button_press_event", (GtkSignalFunc)gtk_listbox_button_press_callback, @@ -430,15 +426,23 @@ void wxListBox::AppendCommon( const wxString &item ) ConnectWidget( list_item ); + if (GTK_WIDGET_REALIZED(m_widget)) + { + gtk_widget_realize( list_item ); + gtk_widget_realize( GTK_BIN(list_item)->child ); + + if (m_widgetStyle) ApplyWidgetStyle(); + #if wxUSE_DRAG_AND_DROP #ifndef NEW_GTK_DND_CODE - if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); + if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); #endif #endif #if wxUSE_TOOLTIPS - if (m_toolTip) m_toolTip->Apply( this ); + if (m_toolTip) m_toolTip->Apply( this ); #endif + } } void wxListBox::Append( const wxString &item ) diff --git a/src/gtk1/notebook.cpp b/src/gtk1/notebook.cpp index 364487fafc..eb13d01f46 100644 --- a/src/gtk1/notebook.cpp +++ b/src/gtk1/notebook.cpp @@ -109,9 +109,9 @@ static void gtk_page_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* (win->m_width == alloc->width) && (win->m_height == alloc->height)) { - return; +// return; } - + win->SetSize( alloc->x, alloc->y, alloc->width, alloc->height ); if (win->GetAutoLayout()) win->Layout(); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index a84758ad85..2c6b88d560 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -1294,6 +1294,40 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, return FALSE; } +//----------------------------------------------------------------------------- +// "realize" from m_widget +//----------------------------------------------------------------------------- + +/* we cannot set colours, fonts and cursors before the widget has + been realized, so we do this directly after realization */ + +static gint +gtk_window_realized_callback( GtkWidget *widget, wxWindow *win ) +{ + if (win->m_font != *wxSWISS_FONT) + { + wxFont font( win->m_font ); + win->m_font = wxNullFont; + win->SetFont( font ); + } + + if (win->m_backgroundColour != wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE )) + { + wxColour bg( win->m_backgroundColour ); + win->m_backgroundColour = wxNullColour; + win->SetBackgroundColour( bg ); + } + + if (win->m_foregroundColour != *wxBLACK) + { + wxColour fg( win->m_foregroundColour ); + win->m_foregroundColour = wxNullColour; + win->SetForegroundColour( fg ); + } + + return FALSE; +} + //----------------------------------------------------------------------------- // InsertChild for wxWindow. //----------------------------------------------------------------------------- @@ -1750,13 +1784,12 @@ void wxWindow::PostCreation() ConnectWidget( GetConnectWidget() ); - /* we force the creation of wxFrame and wxDialog in the respective code */ - if (m_parent) gtk_widget_realize( m_widget ); - - if (m_wxwindow) gtk_widget_realize( m_wxwindow ); - - SetCursor( *wxSTANDARD_CURSOR ); - +/* we cannot set colours, fonts and cursors before the widget has + been realized, so we do this directly after realization */ + + gtk_signal_connect( GTK_OBJECT(m_widget), "realize", + GTK_SIGNAL_FUNC(gtk_window_realized_callback), (gpointer) this ); + m_hasVMT = TRUE; } @@ -2071,6 +2104,8 @@ void wxWindow::ClientToScreen( int *x, int *y ) { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) source = m_wxwindow->window; @@ -2098,6 +2133,8 @@ void wxWindow::ScreenToClient( int *x, int *y ) { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + GdkWindow *source = (GdkWindow *) NULL; if (m_wxwindow) source = m_wxwindow->window; @@ -2351,6 +2388,8 @@ void wxWindow::Raise() { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + if (m_widget) gdk_window_raise( m_widget->window ); } @@ -2358,6 +2397,8 @@ void wxWindow::Lower() { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + if (m_widget) gdk_window_lower( m_widget->window ); } @@ -2459,8 +2500,9 @@ void wxWindow::SetCursor( const wxCursor &cursor ) *m_cursor = *wxSTANDARD_CURSOR; } - if ((m_widget) && (m_widget->window)) - gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() ); + if (!m_widget->window) return; + + gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() ); if ((m_wxwindow) && (m_wxwindow->window)) gdk_window_set_cursor( m_wxwindow->window, m_cursor->GetCursor() ); @@ -2475,6 +2517,8 @@ void wxWindow::Refresh( bool eraseBackground, const wxRect *rect ) { wxCHECK_RET( (m_widget != NULL), _T("invalid window") ); + if (!m_widget->window) return; + if (eraseBackground && m_wxwindow && m_wxwindow->window) { if (rect) @@ -2540,6 +2584,8 @@ void wxWindow::Clear() { wxCHECK_RET( m_widget != NULL, _T("invalid window") ); + if (!m_widget->window) return; + if (m_wxwindow && m_wxwindow->window) { gdk_window_clear( m_wxwindow->window ); @@ -2596,6 +2642,8 @@ void wxWindow::SetBackgroundColour( const wxColour &colour ) m_backgroundColour = colour; if (!m_backgroundColour.Ok()) return; + if (!m_widget->window) return; + if (m_wxwindow && m_wxwindow->window) { /* wxMSW doesn't clear the window here. I don't do that @@ -2636,6 +2684,8 @@ void wxWindow::SetForegroundColour( const wxColour &colour ) m_foregroundColour = colour; if (!m_foregroundColour.Ok()) return; + if (!m_widget->window) return; + wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE ); if (sysbg.Red() == colour.Red() && sysbg.Green() == colour.Green() && @@ -2896,6 +2946,8 @@ void wxWindow::CaptureMouse() wxCHECK_RET( g_capturing == FALSE, _T("CaptureMouse called twice") ); + if (!m_widget->window) return; + GtkWidget *connect_widget = GetConnectWidget(); gtk_grab_add( connect_widget ); gdk_pointer_grab( connect_widget->window, FALSE, @@ -2915,6 +2967,8 @@ void wxWindow::ReleaseMouse() wxCHECK_RET( g_capturing == TRUE, _T("ReleaseMouse called twice") ); + if (!m_widget->window) return; + GtkWidget *connect_widget = GetConnectWidget(); gtk_grab_remove( connect_widget ); gdk_pointer_ungrab ( GDK_CURRENT_TIME ); -- 2.45.2