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;
@@ -570,15 +576,50 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
break; break;
} }
case 12: // SGI only
{
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 15: case 15:
{ {
guint32 pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((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 ); gdk_image_put_pixel( data_image, x, y, pixel );
break; break;
} }
case 16: case 16:
{ {
guint32 pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); // 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 ); gdk_image_put_pixel( data_image, x, y, pixel );
break; break;
} }

View File

@@ -186,7 +186,12 @@ void wxButton::ApplyWidgetStyle()
wxSize wxButton::DoGetBestSize() const wxSize wxButton::DoGetBestSize() const
{ {
wxSize ret( wxControl::DoGetBestSize() ); wxSize ret( wxControl::DoGetBestSize() );
if (!HasFlag(wxBU_EXACTFIT))
{
if (ret.x < 80) ret.x = 80; 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,8 +119,6 @@ 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"));
@@ -134,8 +129,6 @@ void wxToggleButton::SetLabel(const wxString& label)
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))
@@ -146,8 +139,6 @@ bool wxToggleButton::Enable(bool enable /*=TRUE*/)
return TRUE; return TRUE;
} }
// void ApplyWidgetStyle()
// I don't really know what this does.
void wxToggleButton::ApplyWidgetStyle() void wxToggleButton::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
@@ -155,18 +146,15 @@ void wxToggleButton::ApplyWidgetStyle()
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()) if (g_globalCursor.Ok())
cursor = g_globalCursor; cursor = g_globalCursor;
@@ -188,8 +176,12 @@ void wxToggleButton::OnInternalIdle()
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;
@@ -570,15 +576,50 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
break; break;
} }
case 12: // SGI only
{
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 15: case 15:
{ {
guint32 pixel = ((r & 0xf8) << 7) | ((g & 0xf8) << 2) | ((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 ); gdk_image_put_pixel( data_image, x, y, pixel );
break; break;
} }
case 16: case 16:
{ {
guint32 pixel = ((r & 0xf8) << 8) | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3); // 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 ); gdk_image_put_pixel( data_image, x, y, pixel );
break; break;
} }

View File

@@ -186,7 +186,12 @@ void wxButton::ApplyWidgetStyle()
wxSize wxButton::DoGetBestSize() const wxSize wxButton::DoGetBestSize() const
{ {
wxSize ret( wxControl::DoGetBestSize() ); wxSize ret( wxControl::DoGetBestSize() );
if (!HasFlag(wxBU_EXACTFIT))
{
if (ret.x < 80) ret.x = 80; 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,8 +119,6 @@ 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"));
@@ -134,8 +129,6 @@ void wxToggleButton::SetLabel(const wxString& label)
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))
@@ -146,8 +139,6 @@ bool wxToggleButton::Enable(bool enable /*=TRUE*/)
return TRUE; return TRUE;
} }
// void ApplyWidgetStyle()
// I don't really know what this does.
void wxToggleButton::ApplyWidgetStyle() void wxToggleButton::ApplyWidgetStyle()
{ {
SetWidgetStyle(); SetWidgetStyle();
@@ -155,18 +146,15 @@ void wxToggleButton::ApplyWidgetStyle()
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()) if (g_globalCursor.Ok())
cursor = g_globalCursor; cursor = g_globalCursor;
@@ -188,8 +176,12 @@ void wxToggleButton::OnInternalIdle()
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;
} }