]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied colour patch for better 8-bit support,
authorRobert Roebling <robert@roebling.de>
Sat, 16 Dec 2000 12:27:26 +0000 (12:27 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 16 Dec 2000 12:27:26 +0000 (12:27 +0000)
  Improved handling of inserting controls into
    a toolbar that don't have any def width. This
    works for all controls but wxComboBox.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/mdi/mdi.cpp
samples/toolbar/toolbar.cpp
src/gtk/colour.cpp
src/gtk/tbargtk.cpp
src/gtk/window.cpp
src/gtk1/colour.cpp
src/gtk1/tbargtk.cpp
src/gtk1/window.cpp

index eb98b73dee8f9f5544d92a7ebf01b1be49ddd3a5..60da58b8d7d5895d1503b754e31bab0b842d71ea 100644 (file)
@@ -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
index df5e434c44f07e50842f004552b0a3c7e63abdc6..c0a98dd8dc8c087150e5ae374757c5019d698574 100644 (file)
@@ -31,6 +31,7 @@
 #include <wx/toolbar.h>
 #include <wx/log.h>
 #include <wx/image.h>
+#include <wx/spinctrl.h>
 
 // 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
index 60e62c4b3a50aa738c2916584737380e0220d210..a54ca5fdac5109e3721a738e5ee42e117d4f1353 100644 (file)
 
 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
     { 
index cfa38c8eb520533adffcdbe68b3e0a02e5882355..8753cade8d270b4e40e4d13f0bd6a62144e9a79a 100644 (file)
@@ -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
     {     
index 937692b0514797746e26a5b16b8f3a661584a33f..37404ebf0f985e7faaf841c54f928f04d7a9b062 100644 (file)
@@ -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;
 }
 
index 60e62c4b3a50aa738c2916584737380e0220d210..a54ca5fdac5109e3721a738e5ee42e117d4f1353 100644 (file)
 
 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
     { 
index cfa38c8eb520533adffcdbe68b3e0a02e5882355..8753cade8d270b4e40e4d13f0bd6a62144e9a79a 100644 (file)
@@ -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
     {     
index 937692b0514797746e26a5b16b8f3a661584a33f..37404ebf0f985e7faaf841c54f928f04d7a9b062 100644 (file)
@@ -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;
 }