]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patches for wxBU_EXACTFIT to button.cpp and tglbtn.cpp
authorRobert Roebling <robert@roebling.de>
Sat, 12 Jan 2002 11:36:43 +0000 (11:36 +0000)
committerRobert Roebling <robert@roebling.de>
Sat, 12 Jan 2002 11:36:43 +0000 (11:36 +0000)
  Applied patch for SGI's 12-bit visuals to bitmap.cpp.

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

src/gtk/bitmap.cpp
src/gtk/button.cpp
src/gtk/tglbtn.cpp
src/gtk1/bitmap.cpp
src/gtk1/button.cpp
src/gtk1/tglbtn.cpp

index 1f62c2a11be98d0aff1282aed4a3abe3aa55ff8d..9fda483abaf5b402f1a6c50f8a598587b79d9d51 100644 (file)
@@ -439,9 +439,16 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
 
         SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) );
 
-        // Retrieve depth
-
-        GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window );
+        // Retrieve depth, using XVisualInfo from app, if set
+        GdkVisual *visual;
+        if (wxTheApp->m_glVisualInfo)
+        {
+            visual = gdkx_visual_get( ((XVisualInfo *) wxTheApp->m_glVisualInfo)->visualid );
+        }
+        else
+        {
+            visual = gdk_window_get_visual( wxGetRootWindow()->window );
+        }
         wxASSERT( visual );
 
         int bpp = visual->depth;
@@ -451,9 +458,10 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
         if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
         if (bpp < 8) bpp = 8;
 
-#if (GTK_MINOR_VERSION > 0)
-
-        if (!image.HasMask() && (bpp > 8))
+        // We handle 8-bit bitmaps ourselves using the colour cube, 12-bit 
+        // visuals are not supported by GDK so we do these ourselves, too.
+        // 15-bit and 16-bit should actually work and 24-bit certainly does.
+        if (!image.HasMask() && (bpp > 12))
         {
             static bool s_hasInitialized = FALSE;
 
@@ -477,8 +485,6 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
             return TRUE;
         }
 
-#endif
-
         // Create picture image
 
         GdkImage *data_image =
@@ -505,7 +511,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
         enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
         byte_order b_o = RGB;
 
-        if (bpp >= 24)
+        if (bpp > 8)
         {
             if ((visual->red_mask > visual->green_mask) && (visual->green_mask > visual->blue_mask))      b_o = RGB;
             else if ((visual->red_mask > visual->blue_mask) && (visual->blue_mask > visual->green_mask))  b_o = RGB;
@@ -543,7 +549,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
 
                 switch (bpp)
                 {
-                case 8:
+                    case 8:
                     {
                         int pixel = -1;
                         if (wxTheApp->m_colorCube)
@@ -555,7 +561,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
                             GdkColormap *cmap = gtk_widget_get_default_colormap();
                             GdkColor *colors = cmap->colors;
                             int max = 3 * (65536);
-
+    
                             for (int i = 0; i < cmap->size; i++)
                             {
                                 int rdiff = (r << 8) - colors[i].red;
@@ -565,39 +571,74 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
                                 if (sum < max) { pixel = i; max = sum; }
                             }
                         }
-
+    
                         gdk_image_put_pixel( data_image, x, y, pixel );
-
+    
                         break;
                     }
-                case 15:
+                    case 12:  // SGI only
                     {
-                        guint32 pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3);
+                        guint32 pixel = 0;
+                        switch (b_o)
+                        {
+                            case RGB: pixel = ((r & 0xf0) << 4) | (g & 0xf0) | ((b & 0xf0) >> 4); break;
+                            case RBG: pixel = ((r & 0xf0) << 4) | (b & 0xf0) | ((g & 0xf0) >> 4); break;
+                            case GRB: pixel = ((g & 0xf0) << 4) | (r & 0xf0) | ((b & 0xf0) >> 4); break;
+                            case GBR: pixel = ((g & 0xf0) << 4) | (b & 0xf0) | ((r & 0xf0) >> 4); break;
+                            case BRG: pixel = ((b & 0xf0) << 4) | (r & 0xf0) | ((g & 0xf0) >> 4); break;
+                            case BGR: pixel = ((b & 0xf0) << 4) | (g & 0xf0) | ((r & 0xf0) >> 4); break;
+                        }
                         gdk_image_put_pixel( data_image, x, y, pixel );
                         break;
                     }
-                case 16:
+                    case 15:
                     {
-                        guint32 pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3);
+                        guint32 pixel = 0;
+                        switch (b_o)
+                        {
+                            case RGB: pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); break;
+                            case RBG: pixel = ((r & 0xf8) << 7) | ((b & 0xf8) << 2) | ((g & 0xf8) >> 3); break;
+                            case GRB: pixel = ((g & 0xf8) << 7) | ((r & 0xf8) << 2) | ((b & 0xf8) >> 3); break;
+                            case GBR: pixel = ((g & 0xf8) << 7) | ((b & 0xf8) << 2) | ((r & 0xf8) >> 3); break;
+                            case BRG: pixel = ((b & 0xf8) << 7) | ((r & 0xf8) << 2) | ((g & 0xf8) >> 3); break;
+                            case BGR: pixel = ((b & 0xf8) << 7) | ((g & 0xf8) << 2) | ((r & 0xf8) >> 3); break;
+                        }
                         gdk_image_put_pixel( data_image, x, y, pixel );
                         break;
                     }
-                case 32:
-                case 24:
+                    case 16:
                     {
+                        // I actually don't know if for 16-bit displays, it is alway the green
+                        // component or the second component which has 6 bits.
                         guint32 pixel = 0;
                         switch (b_o)
                         {
-                        case RGB: pixel = (r << 16) | (g << 8) | b; break;
-                        case RBG: pixel = (r << 16) | (b << 8) | g; break;
-                        case BRG: pixel = (b << 16) | (r << 8) | g; break;
-                        case BGR: pixel = (b << 16) | (g << 8) | r; break;
-                        case GRB: pixel = (g << 16) | (r << 8) | b; break;
-                        case GBR: pixel = (g << 16) | (b << 8) | r; break;
+                            case RGB: pixel = ((r & 0xf8) << 7) | ((g & 0xfc) << 2) | ((b & 0xf8) >> 3); break;
+                            case RBG: pixel = ((r & 0xf8) << 7) | ((b & 0xfc) << 2) | ((g & 0xf8) >> 3); break;
+                            case GRB: pixel = ((g & 0xf8) << 7) | ((r & 0xfc) << 2) | ((b & 0xf8) >> 3); break;
+                            case GBR: pixel = ((g & 0xf8) << 7) | ((b & 0xfc) << 2) | ((r & 0xf8) >> 3); break;
+                            case BRG: pixel = ((b & 0xf8) << 7) | ((r & 0xfc) << 2) | ((g & 0xf8) >> 3); break;
+                            case BGR: pixel = ((b & 0xf8) << 7) | ((g & 0xfc) << 2) | ((r & 0xf8) >> 3); break;
+                        }
+                        gdk_image_put_pixel( data_image, x, y, pixel );
+                        break;
+                    }
+                    case 32:
+                    case 24:
+                    {
+                        guint32 pixel = 0;
+                        switch (b_o)
+                        {
+                            case RGB: pixel = (r << 16) | (g << 8) | b; break;
+                            case RBG: pixel = (r << 16) | (b << 8) | g; break;
+                            case BRG: pixel = (b << 16) | (r << 8) | g; break;
+                            case BGR: pixel = (b << 16) | (g << 8) | r; break;
+                            case GRB: pixel = (g << 16) | (r << 8) | b; break;
+                            case GBR: pixel = (g << 16) | (b << 8) | r; break;
                         }
                         gdk_image_put_pixel( data_image, x, y, pixel );
                     }
-                default: break;
+                    default: break;
                 }
             } // for
         }  // for
@@ -711,27 +752,27 @@ wxImage wxBitmap::ConvertToImage() const
         for (int i = 0; i < GetWidth(); i++)
         {
             wxUint32 pixel = gdk_image_get_pixel( gdk_image, i, j );
-                if (bpp == 1)
+            if (bpp == 1)
+            {
+                if (pixel == 0)
                 {
-                    if (pixel == 0)
-                        {
                     data[pos]   = 0;
                     data[pos+1] = 0;
                     data[pos+2] = 0;
-                        }
-                        else
-                        {
+                }
+                else
+                {
                     data[pos]   = 255;
                     data[pos+1] = 255;
                     data[pos+2] = 255;
-                        }
+                }
             }
             else if (use_shift)
             {
                 data[pos] =   (pixel >> red_shift_right)   << red_shift_left;
                 data[pos+1] = (pixel >> green_shift_right) << green_shift_left;
                 data[pos+2] = (pixel >> blue_shift_right)  << blue_shift_left;
-                }
+            }
             else if (cmap->colors)
             {
                 data[pos] =   cmap->colors[pixel].red   >> 8;
index 01b3283adcd389665996f97dd30995b20bc4bcd5..d594d37e2663b95b54b137557ca7f3fa15606a44 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Robert Roebling
 // Id:          $Id$
 // Copyright:   (c) 1998 Robert Roebling
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
@@ -81,7 +81,7 @@ bool wxButton::Create(  wxWindow *parent, wxWindowID id, const wxString &label,
         !CreateBase( parent, id, pos, size, style, validator, name ))
     {
         wxFAIL_MSG( wxT("wxButton creation failed") );
-           return FALSE;
+        return FALSE;
     }
 
 /*
@@ -89,7 +89,7 @@ bool wxButton::Create(  wxWindow *parent, wxWindowID id, const wxString &label,
     for (size_t i = 0; i < label2.Len(); i++)
     {
         if (label2.GetChar(i) == wxT('&'))
-           label2.SetChar(i,wxT('_'));
+        label2.SetChar(i,wxT('_'));
     }
     
     GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
@@ -186,7 +186,12 @@ void wxButton::ApplyWidgetStyle()
 wxSize wxButton::DoGetBestSize() const
 {
     wxSize ret( wxControl::DoGetBestSize() );
-    if (ret.x < 80) ret.x = 80;
+    
+    if (!HasFlag(wxBU_EXACTFIT))
+    {
+        if (ret.x < 80) ret.x = 80;
+    }
+    
     return ret;
 }
 
index ad1993d221788dbefe7a18f0d06822545e3cfb0d..b3b2ec9ef340310f5d0f77e252ed1752b51b8215 100644 (file)
@@ -11,6 +11,7 @@
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/tglbtn.h"
+#include "wx/button.h"
 
 #if wxUSE_TOGGLEBTN
 
@@ -44,10 +45,6 @@ static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxTog
 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
 
-// bool Create(wxWindow *parent, wxWindowID id, const wxString &label,
-//             const wxPoint &pos, const wxSize &size, long style,
-//             const wxValidator& validator, const wxString &name)
-// Create the control.
 bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
                             const wxString &label, const wxPoint &pos,
                             const wxSize &size, long style,
@@ -122,74 +119,69 @@ bool wxToggleButton::GetValue() const
    return GTK_TOGGLE_BUTTON(m_widget)->active;
 }
 
-// void SetLabel(const wxString& label)
-// Set the button's label.
 void wxToggleButton::SetLabel(const wxString& label)
 {
-   wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button"));
+    wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button"));
 
-   wxControl::SetLabel(label);
+    wxControl::SetLabel(label);
 
-   gtk_label_set(GTK_LABEL(GTK_BUTTON(m_widget)->child),
+    gtk_label_set(GTK_LABEL(GTK_BUTTON(m_widget)->child),
                  GetLabel().mbc_str());
 }
 
-// bool Enable(bool enable)
-// Enable (or disable) the control.
 bool wxToggleButton::Enable(bool enable /*=TRUE*/)
 {
-   if (!wxControl::Enable(enable))
-      return FALSE;
+    if (!wxControl::Enable(enable))
+        return FALSE;
 
-   gtk_widget_set_sensitive(GTK_BUTTON(m_widget)->child, enable);
+    gtk_widget_set_sensitive(GTK_BUTTON(m_widget)->child, enable);
 
-   return TRUE;
+    return TRUE;
 }
 
-// void ApplyWidgetStyle()
-// I don't really know what this does.
 void wxToggleButton::ApplyWidgetStyle()
 {
-   SetWidgetStyle();
-   gtk_widget_set_style(m_widget, m_widgetStyle);
-   gtk_widget_set_style(GTK_BUTTON(m_widget)->child, m_widgetStyle);
+    SetWidgetStyle();
+    gtk_widget_set_style(m_widget, m_widgetStyle);
+    gtk_widget_set_style(GTK_BUTTON(m_widget)->child, m_widgetStyle);
 }
 
-// bool IsOwnGtkWindow(GdkWindow *window)
-// I'm not really sure what this is for, either.
 bool wxToggleButton::IsOwnGtkWindow(GdkWindow *window)
 {
-   return (window == GTK_TOGGLE_BUTTON(m_widget)->event_window);
+    return (window == GTK_TOGGLE_BUTTON(m_widget)->event_window);
 }
 
-// void OnInternalIdle()
-// Apparently gtk cursors are difficult to deal with.
 void wxToggleButton::OnInternalIdle()
 {
-   wxCursor cursor = m_cursor;
-   if (g_globalCursor.Ok())
-      cursor = g_globalCursor;
+    wxCursor cursor = m_cursor;
+    
+    if (g_globalCursor.Ok())
+        cursor = g_globalCursor;
 
-   if (GTK_TOGGLE_BUTTON(m_widget)->event_window && cursor.Ok()) {
+    if (GTK_TOGGLE_BUTTON(m_widget)->event_window && cursor.Ok()) {
       /* I now set the cursor the anew in every OnInternalIdle call
          as setting the cursor in a parent window also effects the
          windows above so that checking for the current cursor is
          not possible. */
 
-      gdk_window_set_cursor(GTK_TOGGLE_BUTTON(m_widget)->event_window,
+        gdk_window_set_cursor(GTK_TOGGLE_BUTTON(m_widget)->event_window,
                             cursor.GetCursor());
-   }
+    }
 
-   UpdateWindowUI();
+    UpdateWindowUI();
 }
 
 // wxSize DoGetBestSize() const
 // Get the "best" size for this control.
 wxSize wxToggleButton::DoGetBestSize() const
 {
-   wxSize ret(wxControl::DoGetBestSize());
-   if (ret.x < 80)
-      ret.x = 80;
+    wxSize ret(wxControl::DoGetBestSize());
+   
+    if (!HasFlag(wxBU_EXACTFIT))
+    {
+        if (ret.x < 80) ret.x = 80;
+    }
+    
 
    return ret;
 }
index 1f62c2a11be98d0aff1282aed4a3abe3aa55ff8d..9fda483abaf5b402f1a6c50f8a598587b79d9d51 100644 (file)
@@ -439,9 +439,16 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
 
         SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) );
 
-        // Retrieve depth
-
-        GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window );
+        // Retrieve depth, using XVisualInfo from app, if set
+        GdkVisual *visual;
+        if (wxTheApp->m_glVisualInfo)
+        {
+            visual = gdkx_visual_get( ((XVisualInfo *) wxTheApp->m_glVisualInfo)->visualid );
+        }
+        else
+        {
+            visual = gdk_window_get_visual( wxGetRootWindow()->window );
+        }
         wxASSERT( visual );
 
         int bpp = visual->depth;
@@ -451,9 +458,10 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
         if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15;
         if (bpp < 8) bpp = 8;
 
-#if (GTK_MINOR_VERSION > 0)
-
-        if (!image.HasMask() && (bpp > 8))
+        // We handle 8-bit bitmaps ourselves using the colour cube, 12-bit 
+        // visuals are not supported by GDK so we do these ourselves, too.
+        // 15-bit and 16-bit should actually work and 24-bit certainly does.
+        if (!image.HasMask() && (bpp > 12))
         {
             static bool s_hasInitialized = FALSE;
 
@@ -477,8 +485,6 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
             return TRUE;
         }
 
-#endif
-
         // Create picture image
 
         GdkImage *data_image =
@@ -505,7 +511,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
         enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
         byte_order b_o = RGB;
 
-        if (bpp >= 24)
+        if (bpp > 8)
         {
             if ((visual->red_mask > visual->green_mask) && (visual->green_mask > visual->blue_mask))      b_o = RGB;
             else if ((visual->red_mask > visual->blue_mask) && (visual->blue_mask > visual->green_mask))  b_o = RGB;
@@ -543,7 +549,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
 
                 switch (bpp)
                 {
-                case 8:
+                    case 8:
                     {
                         int pixel = -1;
                         if (wxTheApp->m_colorCube)
@@ -555,7 +561,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
                             GdkColormap *cmap = gtk_widget_get_default_colormap();
                             GdkColor *colors = cmap->colors;
                             int max = 3 * (65536);
-
+    
                             for (int i = 0; i < cmap->size; i++)
                             {
                                 int rdiff = (r << 8) - colors[i].red;
@@ -565,39 +571,74 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
                                 if (sum < max) { pixel = i; max = sum; }
                             }
                         }
-
+    
                         gdk_image_put_pixel( data_image, x, y, pixel );
-
+    
                         break;
                     }
-                case 15:
+                    case 12:  // SGI only
                     {
-                        guint32 pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3);
+                        guint32 pixel = 0;
+                        switch (b_o)
+                        {
+                            case RGB: pixel = ((r & 0xf0) << 4) | (g & 0xf0) | ((b & 0xf0) >> 4); break;
+                            case RBG: pixel = ((r & 0xf0) << 4) | (b & 0xf0) | ((g & 0xf0) >> 4); break;
+                            case GRB: pixel = ((g & 0xf0) << 4) | (r & 0xf0) | ((b & 0xf0) >> 4); break;
+                            case GBR: pixel = ((g & 0xf0) << 4) | (b & 0xf0) | ((r & 0xf0) >> 4); break;
+                            case BRG: pixel = ((b & 0xf0) << 4) | (r & 0xf0) | ((g & 0xf0) >> 4); break;
+                            case BGR: pixel = ((b & 0xf0) << 4) | (g & 0xf0) | ((r & 0xf0) >> 4); break;
+                        }
                         gdk_image_put_pixel( data_image, x, y, pixel );
                         break;
                     }
-                case 16:
+                    case 15:
                     {
-                        guint32 pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3);
+                        guint32 pixel = 0;
+                        switch (b_o)
+                        {
+                            case RGB: pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3); break;
+                            case RBG: pixel = ((r & 0xf8) << 7) | ((b & 0xf8) << 2) | ((g & 0xf8) >> 3); break;
+                            case GRB: pixel = ((g & 0xf8) << 7) | ((r & 0xf8) << 2) | ((b & 0xf8) >> 3); break;
+                            case GBR: pixel = ((g & 0xf8) << 7) | ((b & 0xf8) << 2) | ((r & 0xf8) >> 3); break;
+                            case BRG: pixel = ((b & 0xf8) << 7) | ((r & 0xf8) << 2) | ((g & 0xf8) >> 3); break;
+                            case BGR: pixel = ((b & 0xf8) << 7) | ((g & 0xf8) << 2) | ((r & 0xf8) >> 3); break;
+                        }
                         gdk_image_put_pixel( data_image, x, y, pixel );
                         break;
                     }
-                case 32:
-                case 24:
+                    case 16:
                     {
+                        // I actually don't know if for 16-bit displays, it is alway the green
+                        // component or the second component which has 6 bits.
                         guint32 pixel = 0;
                         switch (b_o)
                         {
-                        case RGB: pixel = (r << 16) | (g << 8) | b; break;
-                        case RBG: pixel = (r << 16) | (b << 8) | g; break;
-                        case BRG: pixel = (b << 16) | (r << 8) | g; break;
-                        case BGR: pixel = (b << 16) | (g << 8) | r; break;
-                        case GRB: pixel = (g << 16) | (r << 8) | b; break;
-                        case GBR: pixel = (g << 16) | (b << 8) | r; break;
+                            case RGB: pixel = ((r & 0xf8) << 7) | ((g & 0xfc) << 2) | ((b & 0xf8) >> 3); break;
+                            case RBG: pixel = ((r & 0xf8) << 7) | ((b & 0xfc) << 2) | ((g & 0xf8) >> 3); break;
+                            case GRB: pixel = ((g & 0xf8) << 7) | ((r & 0xfc) << 2) | ((b & 0xf8) >> 3); break;
+                            case GBR: pixel = ((g & 0xf8) << 7) | ((b & 0xfc) << 2) | ((r & 0xf8) >> 3); break;
+                            case BRG: pixel = ((b & 0xf8) << 7) | ((r & 0xfc) << 2) | ((g & 0xf8) >> 3); break;
+                            case BGR: pixel = ((b & 0xf8) << 7) | ((g & 0xfc) << 2) | ((r & 0xf8) >> 3); break;
+                        }
+                        gdk_image_put_pixel( data_image, x, y, pixel );
+                        break;
+                    }
+                    case 32:
+                    case 24:
+                    {
+                        guint32 pixel = 0;
+                        switch (b_o)
+                        {
+                            case RGB: pixel = (r << 16) | (g << 8) | b; break;
+                            case RBG: pixel = (r << 16) | (b << 8) | g; break;
+                            case BRG: pixel = (b << 16) | (r << 8) | g; break;
+                            case BGR: pixel = (b << 16) | (g << 8) | r; break;
+                            case GRB: pixel = (g << 16) | (r << 8) | b; break;
+                            case GBR: pixel = (g << 16) | (b << 8) | r; break;
                         }
                         gdk_image_put_pixel( data_image, x, y, pixel );
                     }
-                default: break;
+                    default: break;
                 }
             } // for
         }  // for
@@ -711,27 +752,27 @@ wxImage wxBitmap::ConvertToImage() const
         for (int i = 0; i < GetWidth(); i++)
         {
             wxUint32 pixel = gdk_image_get_pixel( gdk_image, i, j );
-                if (bpp == 1)
+            if (bpp == 1)
+            {
+                if (pixel == 0)
                 {
-                    if (pixel == 0)
-                        {
                     data[pos]   = 0;
                     data[pos+1] = 0;
                     data[pos+2] = 0;
-                        }
-                        else
-                        {
+                }
+                else
+                {
                     data[pos]   = 255;
                     data[pos+1] = 255;
                     data[pos+2] = 255;
-                        }
+                }
             }
             else if (use_shift)
             {
                 data[pos] =   (pixel >> red_shift_right)   << red_shift_left;
                 data[pos+1] = (pixel >> green_shift_right) << green_shift_left;
                 data[pos+2] = (pixel >> blue_shift_right)  << blue_shift_left;
-                }
+            }
             else if (cmap->colors)
             {
                 data[pos] =   cmap->colors[pixel].red   >> 8;
index 01b3283adcd389665996f97dd30995b20bc4bcd5..d594d37e2663b95b54b137557ca7f3fa15606a44 100644 (file)
@@ -4,7 +4,7 @@
 // Author:      Robert Roebling
 // Id:          $Id$
 // Copyright:   (c) 1998 Robert Roebling
-// Licence:    wxWindows licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #ifdef __GNUG__
@@ -81,7 +81,7 @@ bool wxButton::Create(  wxWindow *parent, wxWindowID id, const wxString &label,
         !CreateBase( parent, id, pos, size, style, validator, name ))
     {
         wxFAIL_MSG( wxT("wxButton creation failed") );
-           return FALSE;
+        return FALSE;
     }
 
 /*
@@ -89,7 +89,7 @@ bool wxButton::Create(  wxWindow *parent, wxWindowID id, const wxString &label,
     for (size_t i = 0; i < label2.Len(); i++)
     {
         if (label2.GetChar(i) == wxT('&'))
-           label2.SetChar(i,wxT('_'));
+        label2.SetChar(i,wxT('_'));
     }
     
     GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
@@ -186,7 +186,12 @@ void wxButton::ApplyWidgetStyle()
 wxSize wxButton::DoGetBestSize() const
 {
     wxSize ret( wxControl::DoGetBestSize() );
-    if (ret.x < 80) ret.x = 80;
+    
+    if (!HasFlag(wxBU_EXACTFIT))
+    {
+        if (ret.x < 80) ret.x = 80;
+    }
+    
     return ret;
 }
 
index ad1993d221788dbefe7a18f0d06822545e3cfb0d..b3b2ec9ef340310f5d0f77e252ed1752b51b8215 100644 (file)
@@ -11,6 +11,7 @@
 /////////////////////////////////////////////////////////////////////////////
 
 #include "wx/tglbtn.h"
+#include "wx/button.h"
 
 #if wxUSE_TOGGLEBTN
 
@@ -44,10 +45,6 @@ static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxTog
 IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
 DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED)
 
-// bool Create(wxWindow *parent, wxWindowID id, const wxString &label,
-//             const wxPoint &pos, const wxSize &size, long style,
-//             const wxValidator& validator, const wxString &name)
-// Create the control.
 bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
                             const wxString &label, const wxPoint &pos,
                             const wxSize &size, long style,
@@ -122,74 +119,69 @@ bool wxToggleButton::GetValue() const
    return GTK_TOGGLE_BUTTON(m_widget)->active;
 }
 
-// void SetLabel(const wxString& label)
-// Set the button's label.
 void wxToggleButton::SetLabel(const wxString& label)
 {
-   wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button"));
+    wxCHECK_RET(m_widget != NULL, wxT("invalid toggle button"));
 
-   wxControl::SetLabel(label);
+    wxControl::SetLabel(label);
 
-   gtk_label_set(GTK_LABEL(GTK_BUTTON(m_widget)->child),
+    gtk_label_set(GTK_LABEL(GTK_BUTTON(m_widget)->child),
                  GetLabel().mbc_str());
 }
 
-// bool Enable(bool enable)
-// Enable (or disable) the control.
 bool wxToggleButton::Enable(bool enable /*=TRUE*/)
 {
-   if (!wxControl::Enable(enable))
-      return FALSE;
+    if (!wxControl::Enable(enable))
+        return FALSE;
 
-   gtk_widget_set_sensitive(GTK_BUTTON(m_widget)->child, enable);
+    gtk_widget_set_sensitive(GTK_BUTTON(m_widget)->child, enable);
 
-   return TRUE;
+    return TRUE;
 }
 
-// void ApplyWidgetStyle()
-// I don't really know what this does.
 void wxToggleButton::ApplyWidgetStyle()
 {
-   SetWidgetStyle();
-   gtk_widget_set_style(m_widget, m_widgetStyle);
-   gtk_widget_set_style(GTK_BUTTON(m_widget)->child, m_widgetStyle);
+    SetWidgetStyle();
+    gtk_widget_set_style(m_widget, m_widgetStyle);
+    gtk_widget_set_style(GTK_BUTTON(m_widget)->child, m_widgetStyle);
 }
 
-// bool IsOwnGtkWindow(GdkWindow *window)
-// I'm not really sure what this is for, either.
 bool wxToggleButton::IsOwnGtkWindow(GdkWindow *window)
 {
-   return (window == GTK_TOGGLE_BUTTON(m_widget)->event_window);
+    return (window == GTK_TOGGLE_BUTTON(m_widget)->event_window);
 }
 
-// void OnInternalIdle()
-// Apparently gtk cursors are difficult to deal with.
 void wxToggleButton::OnInternalIdle()
 {
-   wxCursor cursor = m_cursor;
-   if (g_globalCursor.Ok())
-      cursor = g_globalCursor;
+    wxCursor cursor = m_cursor;
+    
+    if (g_globalCursor.Ok())
+        cursor = g_globalCursor;
 
-   if (GTK_TOGGLE_BUTTON(m_widget)->event_window && cursor.Ok()) {
+    if (GTK_TOGGLE_BUTTON(m_widget)->event_window && cursor.Ok()) {
       /* I now set the cursor the anew in every OnInternalIdle call
          as setting the cursor in a parent window also effects the
          windows above so that checking for the current cursor is
          not possible. */
 
-      gdk_window_set_cursor(GTK_TOGGLE_BUTTON(m_widget)->event_window,
+        gdk_window_set_cursor(GTK_TOGGLE_BUTTON(m_widget)->event_window,
                             cursor.GetCursor());
-   }
+    }
 
-   UpdateWindowUI();
+    UpdateWindowUI();
 }
 
 // wxSize DoGetBestSize() const
 // Get the "best" size for this control.
 wxSize wxToggleButton::DoGetBestSize() const
 {
-   wxSize ret(wxControl::DoGetBestSize());
-   if (ret.x < 80)
-      ret.x = 80;
+    wxSize ret(wxControl::DoGetBestSize());
+   
+    if (!HasFlag(wxBU_EXACTFIT))
+    {
+        if (ret.x < 80) ret.x = 80;
+    }
+    
 
    return ret;
 }