diff --git a/samples/mdi/mdi.cpp b/samples/mdi/mdi.cpp index eb98b73dee..60da58b8d7 100644 --- a/samples/mdi/mdi.cpp +++ b/samples/mdi/mdi.cpp @@ -176,7 +176,7 @@ MyFrame::MyFrame(wxWindow *parent, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSUNKEN_BORDER); - CreateToolBar(wxNO_BORDER | wxTB_FLAT | wxTB_HORIZONTAL); + CreateToolBar(wxNO_BORDER | wxTB_HORIZONTAL); InitToolBar(GetToolBar()); // Accelerators diff --git a/samples/toolbar/toolbar.cpp b/samples/toolbar/toolbar.cpp index df5e434c44..c0a98dd8dc 100644 --- a/samples/toolbar/toolbar.cpp +++ b/samples/toolbar/toolbar.cpp @@ -31,6 +31,7 @@ #include #include #include +#include // define this to 1 to use wxToolBarSimple instead of the native one #define USE_GENERIC_TBAR 0 @@ -298,12 +299,15 @@ void MyFrame::RecreateToolbar() // adding a combo to a vertical toolbar is not very smart if ( m_horzToolbar ) { - wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO); + wxComboBox *combo = new wxComboBox(toolBar, ID_COMBO, "", wxDefaultPosition, wxSize(200,-1) ); combo->Append("This"); combo->Append("is a"); combo->Append("combobox"); combo->Append("in a"); combo->Append("toolbar"); +/* + wxTextCtrl *combo = new wxTextCtrl( toolBar, -1, "", wxDefaultPosition, wxSize(80,-1) ); +*/ toolBar->AddControl(combo); } #endif // toolbars which don't support controls diff --git a/src/gtk/colour.cpp b/src/gtk/colour.cpp index 60e62c4b3a..a54ca5fdac 100644 --- a/src/gtk/colour.cpp +++ b/src/gtk/colour.cpp @@ -24,12 +24,13 @@ class wxColourRefData: public wxObjectRefData { - public: - +public: wxColourRefData(); ~wxColourRefData(); + void FreeColour(); +public: GdkColor m_color; GdkColormap *m_colormap; bool m_hasPixel; @@ -54,7 +55,22 @@ wxColourRefData::~wxColourRefData() void wxColourRefData::FreeColour() { -// if (m_hasPixel) gdk_colors_free( m_colormap, &m_color, 1, 0 ); + if (m_colormap) + { +#ifdef __WXGTK20__ + if ((m_colormap->visual->type == GDK_VISUAL_GRAYSCALE) || + (m_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) +#else + GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) m_colormap; + if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) || + (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) +#endif + { + // What happens if the colour has not been allocated + // anew but has been found? RR. + gdk_colormap_free_colors( m_colormap, &m_color, 1 ); + } + } } //----------------------------------------------------------------------------- @@ -190,21 +206,7 @@ void wxColour::CalcPixel( GdkColormap *cmap ) (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) #endif { - GdkColor *colors = cmap->colors; - int max = 3 * (65536); - int index = -1; - - for (int i = 0; i < cmap->size; i++) - { - int rdiff = (M_COLDATA->m_color.red - colors[i].red); - int gdiff = (M_COLDATA->m_color.green - colors[i].green); - int bdiff = (M_COLDATA->m_color.blue - colors[i].blue); - int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); - if (sum < max) { index = i; max = sum; } - } - - M_COLDATA->m_hasPixel = TRUE; - M_COLDATA->m_color.pixel = index; + M_COLDATA->m_hasPixel = gdk_colormap_alloc_color( cmap, &M_COLDATA->m_color, FALSE, TRUE ); } else { diff --git a/src/gtk/tbargtk.cpp b/src/gtk/tbargtk.cpp index cfa38c8eb5..8753cade8d 100644 --- a/src/gtk/tbargtk.cpp +++ b/src/gtk/tbargtk.cpp @@ -141,35 +141,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), wxToolBar *tb = (wxToolBar *)tool->GetToolBar(); -#if (GTK_MINOR_VERSION == 0) - /* we grey-out the tip text of disabled tool in GTK 1.0 */ - if (tool->IsEnabled()) - { - if (tb->m_fg->red != 0) - { - tb->m_fg->red = 0; - tb->m_fg->green = 0; - tb->m_fg->blue = 0; - gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); - - gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); - } - } - else - { - if (tb->m_fg->red == 0) - { - tb->m_fg->red = 33000; - tb->m_fg->green = 33000; - tb->m_fg->blue = 33000; - gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); - gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); - } - } -#endif - - /* emit the event */ - + // emit the event tb->OnMouseEnter( tool->GetId() ); return FALSE; @@ -182,7 +154,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), wxWindow* WXUNUSED(child) ) { - /* we don't do anything here but pray */ + // we don't do anything here } // ---------------------------------------------------------------------------- @@ -260,10 +232,8 @@ bool wxToolBar::Create( wxWindow *parent, gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); gtk_widget_show( GTK_WIDGET(m_toolbar) ); -#if (GTK_MINOR_VERSION > 0) if (style & wxTB_FLAT) gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); -#endif } else { diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 937692b051..37404ebf0f 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -655,6 +655,21 @@ static long map_to_wx_keysym( KeySym keysym ) return (key_code); } +//----------------------------------------------------------------------------- +// "size_request" of m_widget +//----------------------------------------------------------------------------- + +static void gtk_window_size_request_callback( GtkWidget *widget, GtkRequisition *requisition, wxWindow *win ) +{ + int w,h; + win->GetSize( &w, &h ); + if (w < 2) w = 2; + if (h < 2) h = 2; + + requisition->height = h; + requisition->width = w; +} + //----------------------------------------------------------------------------- // "expose_event" of m_wxwindow //----------------------------------------------------------------------------- @@ -2454,19 +2469,30 @@ void wxWindow::PostCreation() if (m_wxwindow) { - /* Catch native resize events. */ + // Catch native resize events gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate", GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this ); - /* Initialize XIM support. */ + // Initialize XIM support gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize", GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback), (gpointer) this ); - /* And resize XIM window. */ + // And resize XIM window gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate", GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this ); } + if (!GTK_IS_COMBO(m_widget)) + { + // This is needed if we want to add our windows into native + // GTK control, such as the toolbar. With this callback, the + // toolbar gets to know the correct size (the one set by the + // programmer). Sadly, it misbehaves for wxComboBox. FIXME + // when moving to GTK 2.0. + gtk_signal_connect( GTK_OBJECT(m_widget), "size_request", + GTK_SIGNAL_FUNC(gtk_window_size_request_callback), (gpointer) this ); + } + m_hasVMT = TRUE; } diff --git a/src/gtk1/colour.cpp b/src/gtk1/colour.cpp index 60e62c4b3a..a54ca5fdac 100644 --- a/src/gtk1/colour.cpp +++ b/src/gtk1/colour.cpp @@ -24,12 +24,13 @@ class wxColourRefData: public wxObjectRefData { - public: - +public: wxColourRefData(); ~wxColourRefData(); + void FreeColour(); +public: GdkColor m_color; GdkColormap *m_colormap; bool m_hasPixel; @@ -54,7 +55,22 @@ wxColourRefData::~wxColourRefData() void wxColourRefData::FreeColour() { -// if (m_hasPixel) gdk_colors_free( m_colormap, &m_color, 1, 0 ); + if (m_colormap) + { +#ifdef __WXGTK20__ + if ((m_colormap->visual->type == GDK_VISUAL_GRAYSCALE) || + (m_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) +#else + GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) m_colormap; + if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) || + (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) +#endif + { + // What happens if the colour has not been allocated + // anew but has been found? RR. + gdk_colormap_free_colors( m_colormap, &m_color, 1 ); + } + } } //----------------------------------------------------------------------------- @@ -190,21 +206,7 @@ void wxColour::CalcPixel( GdkColormap *cmap ) (private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR)) #endif { - GdkColor *colors = cmap->colors; - int max = 3 * (65536); - int index = -1; - - for (int i = 0; i < cmap->size; i++) - { - int rdiff = (M_COLDATA->m_color.red - colors[i].red); - int gdiff = (M_COLDATA->m_color.green - colors[i].green); - int bdiff = (M_COLDATA->m_color.blue - colors[i].blue); - int sum = ABS (rdiff) + ABS (gdiff) + ABS (bdiff); - if (sum < max) { index = i; max = sum; } - } - - M_COLDATA->m_hasPixel = TRUE; - M_COLDATA->m_color.pixel = index; + M_COLDATA->m_hasPixel = gdk_colormap_alloc_color( cmap, &M_COLDATA->m_color, FALSE, TRUE ); } else { diff --git a/src/gtk1/tbargtk.cpp b/src/gtk1/tbargtk.cpp index cfa38c8eb5..8753cade8d 100644 --- a/src/gtk1/tbargtk.cpp +++ b/src/gtk1/tbargtk.cpp @@ -141,35 +141,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), wxToolBar *tb = (wxToolBar *)tool->GetToolBar(); -#if (GTK_MINOR_VERSION == 0) - /* we grey-out the tip text of disabled tool in GTK 1.0 */ - if (tool->IsEnabled()) - { - if (tb->m_fg->red != 0) - { - tb->m_fg->red = 0; - tb->m_fg->green = 0; - tb->m_fg->blue = 0; - gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); - - gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); - } - } - else - { - if (tb->m_fg->red == 0) - { - tb->m_fg->red = 33000; - tb->m_fg->green = 33000; - tb->m_fg->blue = 33000; - gdk_color_alloc( gtk_widget_get_colormap( GTK_WIDGET(tb->m_toolbar) ), tb->m_fg ); - gtk_tooltips_set_colors( GTK_TOOLBAR(tb->m_toolbar)->tooltips, tb->m_bg, tb->m_fg ); - } - } -#endif - - /* emit the event */ - + // emit the event tb->OnMouseEnter( tool->GetId() ); return FALSE; @@ -182,7 +154,7 @@ static gint gtk_toolbar_enter_callback( GtkWidget *WXUNUSED(widget), static void wxInsertChildInToolBar( wxToolBar* WXUNUSED(parent), wxWindow* WXUNUSED(child) ) { - /* we don't do anything here but pray */ + // we don't do anything here } // ---------------------------------------------------------------------------- @@ -260,10 +232,8 @@ bool wxToolBar::Create( wxWindow *parent, gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); gtk_widget_show( GTK_WIDGET(m_toolbar) ); -#if (GTK_MINOR_VERSION > 0) if (style & wxTB_FLAT) gtk_handle_box_set_shadow_type( GTK_HANDLE_BOX(m_widget), GTK_SHADOW_NONE ); -#endif } else { diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 937692b051..37404ebf0f 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -655,6 +655,21 @@ static long map_to_wx_keysym( KeySym keysym ) return (key_code); } +//----------------------------------------------------------------------------- +// "size_request" of m_widget +//----------------------------------------------------------------------------- + +static void gtk_window_size_request_callback( GtkWidget *widget, GtkRequisition *requisition, wxWindow *win ) +{ + int w,h; + win->GetSize( &w, &h ); + if (w < 2) w = 2; + if (h < 2) h = 2; + + requisition->height = h; + requisition->width = w; +} + //----------------------------------------------------------------------------- // "expose_event" of m_wxwindow //----------------------------------------------------------------------------- @@ -2454,19 +2469,30 @@ void wxWindow::PostCreation() if (m_wxwindow) { - /* Catch native resize events. */ + // Catch native resize events gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate", GTK_SIGNAL_FUNC(gtk_window_size_callback), (gpointer)this ); - /* Initialize XIM support. */ + // Initialize XIM support gtk_signal_connect( GTK_OBJECT(m_wxwindow), "realize", GTK_SIGNAL_FUNC(gtk_wxwindow_realized_callback), (gpointer) this ); - /* And resize XIM window. */ + // And resize XIM window gtk_signal_connect( GTK_OBJECT(m_wxwindow), "size_allocate", GTK_SIGNAL_FUNC(gtk_wxwindow_size_callback), (gpointer)this ); } + if (!GTK_IS_COMBO(m_widget)) + { + // This is needed if we want to add our windows into native + // GTK control, such as the toolbar. With this callback, the + // toolbar gets to know the correct size (the one set by the + // programmer). Sadly, it misbehaves for wxComboBox. FIXME + // when moving to GTK 2.0. + gtk_signal_connect( GTK_OBJECT(m_widget), "size_request", + GTK_SIGNAL_FUNC(gtk_window_size_request_callback), (gpointer) this ); + } + m_hasVMT = TRUE; }