Applied patches for wxBU_EXACTFIT to button.cpp and tglbtn.cpp

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
This commit is contained in:
Robert Roebling
2002-01-12 11:36:43 +00:00
parent d491523b1f
commit 8ab696e0a9
6 changed files with 238 additions and 162 deletions

View File

@@ -439,9 +439,16 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) ); SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) );
// Retrieve depth // Retrieve depth, using XVisualInfo from app, if set
GdkVisual *visual;
GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); if (wxTheApp->m_glVisualInfo)
{
visual = gdkx_visual_get( ((XVisualInfo *) wxTheApp->m_glVisualInfo)->visualid );
}
else
{
visual = gdk_window_get_visual( wxGetRootWindow()->window );
}
wxASSERT( visual ); wxASSERT( visual );
int bpp = visual->depth; 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 == 16) && (visual->red_mask != 0xf800)) bpp = 15;
if (bpp < 8) bpp = 8; if (bpp < 8) bpp = 8;
#if (GTK_MINOR_VERSION > 0) // We handle 8-bit bitmaps ourselves using the colour cube, 12-bit
// visuals are not supported by GDK so we do these ourselves, too.
if (!image.HasMask() && (bpp > 8)) // 15-bit and 16-bit should actually work and 24-bit certainly does.
if (!image.HasMask() && (bpp > 12))
{ {
static bool s_hasInitialized = FALSE; static bool s_hasInitialized = FALSE;
@@ -477,8 +485,6 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
return TRUE; return TRUE;
} }
#endif
// Create picture image // Create picture image
GdkImage *data_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 }; enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
byte_order b_o = RGB; 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; 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; 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) switch (bpp)
{ {
case 8: case 8:
{ {
int pixel = -1; int pixel = -1;
if (wxTheApp->m_colorCube) if (wxTheApp->m_colorCube)
@@ -555,7 +561,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
GdkColormap *cmap = gtk_widget_get_default_colormap(); GdkColormap *cmap = gtk_widget_get_default_colormap();
GdkColor *colors = cmap->colors; GdkColor *colors = cmap->colors;
int max = 3 * (65536); int max = 3 * (65536);
for (int i = 0; i < cmap->size; i++) for (int i = 0; i < cmap->size; i++)
{ {
int rdiff = (r << 8) - colors[i].red; 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; } if (sum < max) { pixel = i; max = sum; }
} }
} }
gdk_image_put_pixel( data_image, x, y, pixel ); gdk_image_put_pixel( data_image, x, y, pixel );
break; break;
} }
case 15: case 12: // SGI only
{
guint32 pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3);
gdk_image_put_pixel( data_image, x, y, pixel );
break;
}
case 16:
{
guint32 pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3);
gdk_image_put_pixel( data_image, x, y, pixel );
break;
}
case 32:
case 24:
{ {
guint32 pixel = 0; guint32 pixel = 0;
switch (b_o) switch (b_o)
{ {
case RGB: pixel = (r << 16) | (g << 8) | b; break; case RGB: pixel = ((r & 0xf0) << 4) | (g & 0xf0) | ((b & 0xf0) >> 4); break;
case RBG: pixel = (r << 16) | (b << 8) | g; break; case RBG: pixel = ((r & 0xf0) << 4) | (b & 0xf0) | ((g & 0xf0) >> 4); break;
case BRG: pixel = (b << 16) | (r << 8) | g; break; case GRB: pixel = ((g & 0xf0) << 4) | (r & 0xf0) | ((b & 0xf0) >> 4); break;
case BGR: pixel = (b << 16) | (g << 8) | r; break; case GBR: pixel = ((g & 0xf0) << 4) | (b & 0xf0) | ((r & 0xf0) >> 4); break;
case GRB: pixel = (g << 16) | (r << 8) | b; break; case BRG: pixel = ((b & 0xf0) << 4) | (r & 0xf0) | ((g & 0xf0) >> 4); break;
case GBR: pixel = (g << 16) | (b << 8) | r; break; case BGR: pixel = ((b & 0xf0) << 4) | (g & 0xf0) | ((r & 0xf0) >> 4); break;
}
gdk_image_put_pixel( data_image, x, y, pixel );
break;
}
case 15:
{
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 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 & 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 ); gdk_image_put_pixel( data_image, x, y, pixel );
} }
default: break; default: break;
} }
} // for } // for
} // for } // for
@@ -711,27 +752,27 @@ wxImage wxBitmap::ConvertToImage() const
for (int i = 0; i < GetWidth(); i++) for (int i = 0; i < GetWidth(); i++)
{ {
wxUint32 pixel = gdk_image_get_pixel( gdk_image, i, j ); 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] = 0;
data[pos+1] = 0; data[pos+1] = 0;
data[pos+2] = 0; data[pos+2] = 0;
} }
else else
{ {
data[pos] = 255; data[pos] = 255;
data[pos+1] = 255; data[pos+1] = 255;
data[pos+2] = 255; data[pos+2] = 255;
} }
} }
else if (use_shift) else if (use_shift)
{ {
data[pos] = (pixel >> red_shift_right) << red_shift_left; data[pos] = (pixel >> red_shift_right) << red_shift_left;
data[pos+1] = (pixel >> green_shift_right) << green_shift_left; data[pos+1] = (pixel >> green_shift_right) << green_shift_left;
data[pos+2] = (pixel >> blue_shift_right) << blue_shift_left; data[pos+2] = (pixel >> blue_shift_right) << blue_shift_left;
} }
else if (cmap->colors) else if (cmap->colors)
{ {
data[pos] = cmap->colors[pixel].red >> 8; data[pos] = cmap->colors[pixel].red >> 8;

View File

@@ -4,7 +4,7 @@
// Author: Robert Roebling // Author: Robert Roebling
// Id: $Id$ // Id: $Id$
// Copyright: (c) 1998 Robert Roebling // Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
@@ -81,7 +81,7 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
!CreateBase( parent, id, pos, size, style, validator, name )) !CreateBase( parent, id, pos, size, style, validator, name ))
{ {
wxFAIL_MSG( wxT("wxButton creation failed") ); 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++) for (size_t i = 0; i < label2.Len(); i++)
{ {
if (label2.GetChar(i) == wxT('&')) if (label2.GetChar(i) == wxT('&'))
label2.SetChar(i,wxT('_')); label2.SetChar(i,wxT('_'));
} }
GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() ); GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
@@ -186,7 +186,12 @@ void wxButton::ApplyWidgetStyle()
wxSize wxButton::DoGetBestSize() const wxSize wxButton::DoGetBestSize() const
{ {
wxSize ret( wxControl::DoGetBestSize() ); wxSize ret( wxControl::DoGetBestSize() );
if (ret.x < 80) ret.x = 80;
if (!HasFlag(wxBU_EXACTFIT))
{
if (ret.x < 80) ret.x = 80;
}
return ret; return ret;
} }

View File

@@ -11,6 +11,7 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#include "wx/tglbtn.h" #include "wx/tglbtn.h"
#include "wx/button.h"
#if wxUSE_TOGGLEBTN #if wxUSE_TOGGLEBTN
@@ -44,10 +45,6 @@ static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxTog
IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) 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, bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
const wxString &label, const wxPoint &pos, const wxString &label, const wxPoint &pos,
const wxSize &size, long style, const wxSize &size, long style,
@@ -122,74 +119,69 @@ bool wxToggleButton::GetValue() const
return GTK_TOGGLE_BUTTON(m_widget)->active; return GTK_TOGGLE_BUTTON(m_widget)->active;
} }
// void SetLabel(const wxString& label)
// Set the button's label.
void wxToggleButton::SetLabel(const wxString& 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()); GetLabel().mbc_str());
} }
// bool Enable(bool enable)
// Enable (or disable) the control.
bool wxToggleButton::Enable(bool enable /*=TRUE*/) bool wxToggleButton::Enable(bool enable /*=TRUE*/)
{ {
if (!wxControl::Enable(enable)) if (!wxControl::Enable(enable))
return FALSE; 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() void wxToggleButton::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style(m_widget, m_widgetStyle); gtk_widget_set_style(m_widget, m_widgetStyle);
gtk_widget_set_style(GTK_BUTTON(m_widget)->child, 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) 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() void wxToggleButton::OnInternalIdle()
{ {
wxCursor cursor = m_cursor; wxCursor cursor = m_cursor;
if (g_globalCursor.Ok())
cursor = g_globalCursor; 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 /* I now set the cursor the anew in every OnInternalIdle call
as setting the cursor in a parent window also effects the as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is windows above so that checking for the current cursor is
not possible. */ 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()); cursor.GetCursor());
} }
UpdateWindowUI(); UpdateWindowUI();
} }
// wxSize DoGetBestSize() const // wxSize DoGetBestSize() const
// Get the "best" size for this control. // Get the "best" size for this control.
wxSize wxToggleButton::DoGetBestSize() const wxSize wxToggleButton::DoGetBestSize() const
{ {
wxSize ret(wxControl::DoGetBestSize()); wxSize ret(wxControl::DoGetBestSize());
if (ret.x < 80)
ret.x = 80; if (!HasFlag(wxBU_EXACTFIT))
{
if (ret.x < 80) ret.x = 80;
}
return ret; return ret;
} }

View File

@@ -439,9 +439,16 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) ); SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) );
// Retrieve depth // Retrieve depth, using XVisualInfo from app, if set
GdkVisual *visual;
GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); if (wxTheApp->m_glVisualInfo)
{
visual = gdkx_visual_get( ((XVisualInfo *) wxTheApp->m_glVisualInfo)->visualid );
}
else
{
visual = gdk_window_get_visual( wxGetRootWindow()->window );
}
wxASSERT( visual ); wxASSERT( visual );
int bpp = visual->depth; 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 == 16) && (visual->red_mask != 0xf800)) bpp = 15;
if (bpp < 8) bpp = 8; if (bpp < 8) bpp = 8;
#if (GTK_MINOR_VERSION > 0) // We handle 8-bit bitmaps ourselves using the colour cube, 12-bit
// visuals are not supported by GDK so we do these ourselves, too.
if (!image.HasMask() && (bpp > 8)) // 15-bit and 16-bit should actually work and 24-bit certainly does.
if (!image.HasMask() && (bpp > 12))
{ {
static bool s_hasInitialized = FALSE; static bool s_hasInitialized = FALSE;
@@ -477,8 +485,6 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
return TRUE; return TRUE;
} }
#endif
// Create picture image // Create picture image
GdkImage *data_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 }; enum byte_order { RGB, RBG, BRG, BGR, GRB, GBR };
byte_order b_o = RGB; 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; 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; 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) switch (bpp)
{ {
case 8: case 8:
{ {
int pixel = -1; int pixel = -1;
if (wxTheApp->m_colorCube) if (wxTheApp->m_colorCube)
@@ -555,7 +561,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
GdkColormap *cmap = gtk_widget_get_default_colormap(); GdkColormap *cmap = gtk_widget_get_default_colormap();
GdkColor *colors = cmap->colors; GdkColor *colors = cmap->colors;
int max = 3 * (65536); int max = 3 * (65536);
for (int i = 0; i < cmap->size; i++) for (int i = 0; i < cmap->size; i++)
{ {
int rdiff = (r << 8) - colors[i].red; 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; } if (sum < max) { pixel = i; max = sum; }
} }
} }
gdk_image_put_pixel( data_image, x, y, pixel ); gdk_image_put_pixel( data_image, x, y, pixel );
break; break;
} }
case 15: case 12: // SGI only
{
guint32 pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((b & 0xf8) >> 3);
gdk_image_put_pixel( data_image, x, y, pixel );
break;
}
case 16:
{
guint32 pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3);
gdk_image_put_pixel( data_image, x, y, pixel );
break;
}
case 32:
case 24:
{ {
guint32 pixel = 0; guint32 pixel = 0;
switch (b_o) switch (b_o)
{ {
case RGB: pixel = (r << 16) | (g << 8) | b; break; case RGB: pixel = ((r & 0xf0) << 4) | (g & 0xf0) | ((b & 0xf0) >> 4); break;
case RBG: pixel = (r << 16) | (b << 8) | g; break; case RBG: pixel = ((r & 0xf0) << 4) | (b & 0xf0) | ((g & 0xf0) >> 4); break;
case BRG: pixel = (b << 16) | (r << 8) | g; break; case GRB: pixel = ((g & 0xf0) << 4) | (r & 0xf0) | ((b & 0xf0) >> 4); break;
case BGR: pixel = (b << 16) | (g << 8) | r; break; case GBR: pixel = ((g & 0xf0) << 4) | (b & 0xf0) | ((r & 0xf0) >> 4); break;
case GRB: pixel = (g << 16) | (r << 8) | b; break; case BRG: pixel = ((b & 0xf0) << 4) | (r & 0xf0) | ((g & 0xf0) >> 4); break;
case GBR: pixel = (g << 16) | (b << 8) | r; break; case BGR: pixel = ((b & 0xf0) << 4) | (g & 0xf0) | ((r & 0xf0) >> 4); break;
}
gdk_image_put_pixel( data_image, x, y, pixel );
break;
}
case 15:
{
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 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 & 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 ); gdk_image_put_pixel( data_image, x, y, pixel );
} }
default: break; default: break;
} }
} // for } // for
} // for } // for
@@ -711,27 +752,27 @@ wxImage wxBitmap::ConvertToImage() const
for (int i = 0; i < GetWidth(); i++) for (int i = 0; i < GetWidth(); i++)
{ {
wxUint32 pixel = gdk_image_get_pixel( gdk_image, i, j ); 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] = 0;
data[pos+1] = 0; data[pos+1] = 0;
data[pos+2] = 0; data[pos+2] = 0;
} }
else else
{ {
data[pos] = 255; data[pos] = 255;
data[pos+1] = 255; data[pos+1] = 255;
data[pos+2] = 255; data[pos+2] = 255;
} }
} }
else if (use_shift) else if (use_shift)
{ {
data[pos] = (pixel >> red_shift_right) << red_shift_left; data[pos] = (pixel >> red_shift_right) << red_shift_left;
data[pos+1] = (pixel >> green_shift_right) << green_shift_left; data[pos+1] = (pixel >> green_shift_right) << green_shift_left;
data[pos+2] = (pixel >> blue_shift_right) << blue_shift_left; data[pos+2] = (pixel >> blue_shift_right) << blue_shift_left;
} }
else if (cmap->colors) else if (cmap->colors)
{ {
data[pos] = cmap->colors[pixel].red >> 8; data[pos] = cmap->colors[pixel].red >> 8;

View File

@@ -4,7 +4,7 @@
// Author: Robert Roebling // Author: Robert Roebling
// Id: $Id$ // Id: $Id$
// Copyright: (c) 1998 Robert Roebling // Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__ #ifdef __GNUG__
@@ -81,7 +81,7 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
!CreateBase( parent, id, pos, size, style, validator, name )) !CreateBase( parent, id, pos, size, style, validator, name ))
{ {
wxFAIL_MSG( wxT("wxButton creation failed") ); 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++) for (size_t i = 0; i < label2.Len(); i++)
{ {
if (label2.GetChar(i) == wxT('&')) if (label2.GetChar(i) == wxT('&'))
label2.SetChar(i,wxT('_')); label2.SetChar(i,wxT('_'));
} }
GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() ); GtkWidget *accel_label = gtk_accel_label_new( label2.mb_str() );
@@ -186,7 +186,12 @@ void wxButton::ApplyWidgetStyle()
wxSize wxButton::DoGetBestSize() const wxSize wxButton::DoGetBestSize() const
{ {
wxSize ret( wxControl::DoGetBestSize() ); wxSize ret( wxControl::DoGetBestSize() );
if (ret.x < 80) ret.x = 80;
if (!HasFlag(wxBU_EXACTFIT))
{
if (ret.x < 80) ret.x = 80;
}
return ret; return ret;
} }

View File

@@ -11,6 +11,7 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#include "wx/tglbtn.h" #include "wx/tglbtn.h"
#include "wx/button.h"
#if wxUSE_TOGGLEBTN #if wxUSE_TOGGLEBTN
@@ -44,10 +45,6 @@ static void gtk_togglebutton_clicked_callback(GtkWidget *WXUNUSED(widget), wxTog
IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl)
DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) 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, bool wxToggleButton::Create(wxWindow *parent, wxWindowID id,
const wxString &label, const wxPoint &pos, const wxString &label, const wxPoint &pos,
const wxSize &size, long style, const wxSize &size, long style,
@@ -122,74 +119,69 @@ bool wxToggleButton::GetValue() const
return GTK_TOGGLE_BUTTON(m_widget)->active; return GTK_TOGGLE_BUTTON(m_widget)->active;
} }
// void SetLabel(const wxString& label)
// Set the button's label.
void wxToggleButton::SetLabel(const wxString& 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()); GetLabel().mbc_str());
} }
// bool Enable(bool enable)
// Enable (or disable) the control.
bool wxToggleButton::Enable(bool enable /*=TRUE*/) bool wxToggleButton::Enable(bool enable /*=TRUE*/)
{ {
if (!wxControl::Enable(enable)) if (!wxControl::Enable(enable))
return FALSE; 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() void wxToggleButton::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
gtk_widget_set_style(m_widget, m_widgetStyle); gtk_widget_set_style(m_widget, m_widgetStyle);
gtk_widget_set_style(GTK_BUTTON(m_widget)->child, 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) 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() void wxToggleButton::OnInternalIdle()
{ {
wxCursor cursor = m_cursor; wxCursor cursor = m_cursor;
if (g_globalCursor.Ok())
cursor = g_globalCursor; 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 /* I now set the cursor the anew in every OnInternalIdle call
as setting the cursor in a parent window also effects the as setting the cursor in a parent window also effects the
windows above so that checking for the current cursor is windows above so that checking for the current cursor is
not possible. */ 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()); cursor.GetCursor());
} }
UpdateWindowUI(); UpdateWindowUI();
} }
// wxSize DoGetBestSize() const // wxSize DoGetBestSize() const
// Get the "best" size for this control. // Get the "best" size for this control.
wxSize wxToggleButton::DoGetBestSize() const wxSize wxToggleButton::DoGetBestSize() const
{ {
wxSize ret(wxControl::DoGetBestSize()); wxSize ret(wxControl::DoGetBestSize());
if (ret.x < 80)
ret.x = 80; if (!HasFlag(wxBU_EXACTFIT))
{
if (ret.x < 80) ret.x = 80;
}
return ret; return ret;
} }