]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/bitmap.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "bitmap.h"
16 #include "wx/palette.h"
17 #include "wx/bitmap.h"
19 #include "wx/filefn.h"
21 #include "wx/dcmemory.h"
28 #if (GTK_MINOR_VERSION > 0)
29 #include <gdk/gdkrgb.h>
32 extern void gdk_wx_draw_bitmap (GdkDrawable
*drawable
,
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 extern GtkWidget
*wxGetRootWindow();
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxMask
,wxObject
)
56 m_bitmap
= (GdkBitmap
*) NULL
;
59 wxMask::wxMask( const wxBitmap
& bitmap
, const wxColour
& colour
)
61 m_bitmap
= (GdkBitmap
*) NULL
;
62 Create( bitmap
, colour
);
65 wxMask::wxMask( const wxBitmap
& bitmap
, int paletteIndex
)
67 m_bitmap
= (GdkBitmap
*) NULL
;
68 Create( bitmap
, paletteIndex
);
71 wxMask::wxMask( const wxBitmap
& bitmap
)
73 m_bitmap
= (GdkBitmap
*) NULL
;
80 gdk_bitmap_unref( m_bitmap
);
83 bool wxMask::Create( const wxBitmap
& bitmap
,
84 const wxColour
& colour
)
88 gdk_bitmap_unref( m_bitmap
);
89 m_bitmap
= (GdkBitmap
*) NULL
;
92 wxImage
image( bitmap
);
93 if (!image
.Ok()) return FALSE
;
95 m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, image
.GetWidth(), image
.GetHeight(), 1 );
96 GdkGC
*gc
= gdk_gc_new( m_bitmap
);
103 gdk_gc_set_foreground( gc
, &color
);
104 gdk_gc_set_fill( gc
, GDK_SOLID
);
105 gdk_draw_rectangle( m_bitmap
, gc
, TRUE
, 0, 0, image
.GetWidth(), image
.GetHeight() );
107 unsigned char *data
= image
.GetData();
110 unsigned char red
= colour
.Red();
111 unsigned char green
= colour
.Green();
112 unsigned char blue
= colour
.Blue();
114 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
117 int bpp
= visual
->depth
;
118 if ((bpp
== 16) && (visual
->red_mask
!= 0xf800)) bpp
= 15;
122 green
= green
& 0xf8;
128 green
= green
& 0xfc;
136 gdk_gc_set_foreground( gc
, &color
);
138 for (int j
= 0; j
< image
.GetHeight(); j
++)
142 for (i
= 0; i
< image
.GetWidth(); i
++)
144 if ((data
[index
] == red
) &&
145 (data
[index
+1] == green
) &&
146 (data
[index
+2] == blue
))
155 gdk_draw_line( m_bitmap
, gc
, start_x
, j
, i
-1, j
);
162 gdk_draw_line( m_bitmap
, gc
, start_x
, j
, i
, j
);
170 bool wxMask::Create( const wxBitmap
& bitmap
, int paletteIndex
)
173 wxPalette
*pal
= bitmap
.GetPalette();
175 wxCHECK_MSG( pal
, FALSE
, wxT("Cannot create mask from bitmap without palette") );
177 pal
->GetRGB(paletteIndex
, &r
, &g
, &b
);
179 return Create(bitmap
, wxColour(r
, g
, b
));
182 bool wxMask::Create( const wxBitmap
& bitmap
)
186 gdk_bitmap_unref( m_bitmap
);
187 m_bitmap
= (GdkBitmap
*) NULL
;
190 if (!bitmap
.Ok()) return FALSE
;
192 wxCHECK_MSG( bitmap
.GetBitmap(), FALSE
, wxT("Cannot create mask from colour bitmap") );
194 m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, bitmap
.GetWidth(), bitmap
.GetHeight(), 1 );
196 if (!m_bitmap
) return FALSE
;
198 GdkGC
*gc
= gdk_gc_new( m_bitmap
);
200 gdk_wx_draw_bitmap( m_bitmap
, gc
, bitmap
.GetBitmap(), 0, 0, 0, 0, bitmap
.GetWidth(), bitmap
.GetHeight() );
207 GdkBitmap
*wxMask::GetBitmap() const
212 //-----------------------------------------------------------------------------
214 //-----------------------------------------------------------------------------
216 class wxBitmapRefData
: public wxObjectRefData
228 wxPalette
*m_palette
;
231 wxBitmapRefData::wxBitmapRefData()
233 m_pixmap
= (GdkPixmap
*) NULL
;
234 m_bitmap
= (GdkBitmap
*) NULL
;
235 m_mask
= (wxMask
*) NULL
;
239 m_palette
= (wxPalette
*) NULL
;
242 wxBitmapRefData::~wxBitmapRefData()
244 if (m_pixmap
) gdk_pixmap_unref( m_pixmap
);
245 if (m_bitmap
) gdk_bitmap_unref( m_bitmap
);
246 if (m_mask
) delete m_mask
;
247 if (m_palette
) delete m_palette
;
250 //-----------------------------------------------------------------------------
252 #define M_BMPDATA ((wxBitmapRefData *)m_refData)
254 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
,wxGDIObject
)
260 wxBitmap::wxBitmap( int width
, int height
, int depth
)
262 Create( width
, height
, depth
);
265 bool wxBitmap::Create( int width
, int height
, int depth
)
269 wxCHECK_MSG( (width
> 0) && (height
> 0), FALSE
, wxT("invalid bitmap size") )
271 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
274 if (depth
== -1) depth
= visual
->depth
;
276 wxCHECK_MSG( (depth
== visual
->depth
) ||
277 (depth
== 1), FALSE
, wxT("invalid bitmap depth") )
279 m_refData
= new wxBitmapRefData();
280 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
281 M_BMPDATA
->m_width
= width
;
282 M_BMPDATA
->m_height
= height
;
285 M_BMPDATA
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 );
286 M_BMPDATA
->m_bpp
= 1;
290 M_BMPDATA
->m_pixmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, depth
);
291 M_BMPDATA
->m_bpp
= visual
->depth
;
297 bool wxBitmap::CreateFromXpm( const char **bits
)
299 wxCHECK_MSG( bits
!= NULL
, FALSE
, wxT("invalid bitmap data") )
301 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
304 m_refData
= new wxBitmapRefData();
306 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
308 M_BMPDATA
->m_pixmap
= gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window
, &mask
, NULL
, (gchar
**) bits
);
310 wxCHECK_MSG( M_BMPDATA
->m_pixmap
, FALSE
, wxT("couldn't create pixmap") );
314 M_BMPDATA
->m_mask
= new wxMask();
315 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
318 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
320 M_BMPDATA
->m_bpp
= visual
->depth
; // ?
325 bool wxBitmap::CreateFromImage( const wxImage
& image
, int depth
)
327 wxCHECK_MSG( image
.Ok(), FALSE
, wxT("invalid image") )
328 wxCHECK_MSG( depth
== -1 || depth
== 1, FALSE
, wxT("invalid bitmap depth") )
330 m_refData
= new wxBitmapRefData();
333 // convertion to mono bitmap:
337 int width
= image
.GetWidth();
338 int height
= image
.GetHeight();
343 SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 ) );
347 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
350 // Create picture image
352 unsigned char *data_data
= (unsigned char*)malloc( ((width
>> 3)+8) * height
);
354 GdkImage
*data_image
=
355 gdk_image_new_bitmap( visual
, data_data
, width
, height
);
359 GdkImage
*mask_image
= (GdkImage
*) NULL
;
363 unsigned char *mask_data
= (unsigned char*)malloc( ((width
>> 3)+8) * height
);
365 mask_image
= gdk_image_new_bitmap( visual
, mask_data
, width
, height
);
367 wxMask
*mask
= new wxMask();
368 mask
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 );
373 int r_mask
= image
.GetMaskRed();
374 int g_mask
= image
.GetMaskGreen();
375 int b_mask
= image
.GetMaskBlue();
377 unsigned char* data
= image
.GetData();
380 for (int y
= 0; y
< height
; y
++)
382 for (int x
= 0; x
< width
; x
++)
393 if ((r
== r_mask
) && (b
== b_mask
) && (g
== g_mask
))
394 gdk_image_put_pixel( mask_image
, x
, y
, 1 );
396 gdk_image_put_pixel( mask_image
, x
, y
, 0 );
399 if ((r
== 255) && (b
== 255) && (g
== 255))
400 gdk_image_put_pixel( data_image
, x
, y
, 1 );
402 gdk_image_put_pixel( data_image
, x
, y
, 0 );
409 GdkGC
*data_gc
= gdk_gc_new( GetBitmap() );
411 gdk_draw_image( GetBitmap(), data_gc
, data_image
, 0, 0, 0, 0, width
, height
);
413 gdk_image_destroy( data_image
);
414 gdk_gc_unref( data_gc
);
420 GdkGC
*mask_gc
= gdk_gc_new( GetMask()->GetBitmap() );
422 gdk_draw_image( GetMask()->GetBitmap(), mask_gc
, mask_image
, 0, 0, 0, 0, width
, height
);
424 gdk_image_destroy( mask_image
);
425 gdk_gc_unref( mask_gc
);
430 // convertion to colour bitmap:
434 int width
= image
.GetWidth();
435 int height
= image
.GetHeight();
440 SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, -1 ) );
444 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
447 int bpp
= visual
->depth
;
451 if ((bpp
== 16) && (visual
->red_mask
!= 0xf800)) bpp
= 15;
452 if (bpp
< 8) bpp
= 8;
454 #if (GTK_MINOR_VERSION > 0)
456 if (!image
.HasMask() && (bpp
> 8))
458 static bool s_hasInitialized
= FALSE
;
460 if (!s_hasInitialized
)
463 s_hasInitialized
= TRUE
;
466 GdkGC
*gc
= gdk_gc_new( GetPixmap() );
468 gdk_draw_rgb_image( GetPixmap(),
482 // Create picture image
484 GdkImage
*data_image
=
485 gdk_image_new( GDK_IMAGE_FASTEST
, visual
, width
, height
);
489 GdkImage
*mask_image
= (GdkImage
*) NULL
;
493 unsigned char *mask_data
= (unsigned char*)malloc( ((width
>> 3)+8) * height
);
495 mask_image
= gdk_image_new_bitmap( visual
, mask_data
, width
, height
);
497 wxMask
*mask
= new wxMask();
498 mask
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, width
, height
, 1 );
505 enum byte_order
{ RGB
, RBG
, BRG
, BGR
, GRB
, GBR
};
506 byte_order b_o
= RGB
;
510 if ((visual
->red_mask
> visual
->green_mask
) && (visual
->green_mask
> visual
->blue_mask
)) b_o
= RGB
;
511 else if ((visual
->red_mask
> visual
->blue_mask
) && (visual
->blue_mask
> visual
->green_mask
)) b_o
= RGB
;
512 else if ((visual
->blue_mask
> visual
->red_mask
) && (visual
->red_mask
> visual
->green_mask
)) b_o
= BRG
;
513 else if ((visual
->blue_mask
> visual
->green_mask
) && (visual
->green_mask
> visual
->red_mask
)) b_o
= BGR
;
514 else if ((visual
->green_mask
> visual
->red_mask
) && (visual
->red_mask
> visual
->blue_mask
)) b_o
= GRB
;
515 else if ((visual
->green_mask
> visual
->blue_mask
) && (visual
->blue_mask
> visual
->red_mask
)) b_o
= GBR
;
518 int r_mask
= image
.GetMaskRed();
519 int g_mask
= image
.GetMaskGreen();
520 int b_mask
= image
.GetMaskBlue();
522 unsigned char* data
= image
.GetData();
525 for (int y
= 0; y
< height
; y
++)
527 for (int x
= 0; x
< width
; x
++)
538 if ((r
== r_mask
) && (b
== b_mask
) && (g
== g_mask
))
539 gdk_image_put_pixel( mask_image
, x
, y
, 1 );
541 gdk_image_put_pixel( mask_image
, x
, y
, 0 );
549 if (wxTheApp
->m_colorCube
)
551 pixel
= wxTheApp
->m_colorCube
[ ((r
& 0xf8) << 7) + ((g
& 0xf8) << 2) + ((b
& 0xf8) >> 3) ];
555 GdkColormap
*cmap
= gtk_widget_get_default_colormap();
556 GdkColor
*colors
= cmap
->colors
;
557 int max
= 3 * (65536);
559 for (int i
= 0; i
< cmap
->size
; i
++)
561 int rdiff
= (r
<< 8) - colors
[i
].red
;
562 int gdiff
= (g
<< 8) - colors
[i
].green
;
563 int bdiff
= (b
<< 8) - colors
[i
].blue
;
564 int sum
= ABS (rdiff
) + ABS (gdiff
) + ABS (bdiff
);
565 if (sum
< max
) { pixel
= i
; max
= sum
; }
569 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
575 guint32 pixel
= ((r
& 0xf8) << 7) | ((g
& 0xf8) << 2) | ((b
& 0xf8) >> 3);
576 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
581 guint32 pixel
= ((r
& 0xf8) << 8) | ((g
& 0xfc) << 3) | ((b
& 0xf8) >> 3);
582 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
591 case RGB
: pixel
= (r
<< 16) | (g
<< 8) | b
; break;
592 case RBG
: pixel
= (r
<< 16) | (b
<< 8) | g
; break;
593 case BRG
: pixel
= (b
<< 16) | (r
<< 8) | g
; break;
594 case BGR
: pixel
= (b
<< 16) | (g
<< 8) | r
; break;
595 case GRB
: pixel
= (g
<< 16) | (r
<< 8) | b
; break;
596 case GBR
: pixel
= (g
<< 16) | (b
<< 8) | r
; break;
598 gdk_image_put_pixel( data_image
, x
, y
, pixel
);
607 GdkGC
*data_gc
= gdk_gc_new( GetPixmap() );
609 gdk_draw_image( GetPixmap(), data_gc
, data_image
, 0, 0, 0, 0, width
, height
);
611 gdk_image_destroy( data_image
);
612 gdk_gc_unref( data_gc
);
618 GdkGC
*mask_gc
= gdk_gc_new( GetMask()->GetBitmap() );
620 gdk_draw_image( GetMask()->GetBitmap(), mask_gc
, mask_image
, 0, 0, 0, 0, width
, height
);
622 gdk_image_destroy( mask_image
);
623 gdk_gc_unref( mask_gc
);
630 wxImage
wxBitmap::ConvertToImage() const
634 wxCHECK_MSG( Ok(), wxNullImage
, wxT("invalid bitmap") );
636 GdkImage
*gdk_image
= (GdkImage
*) NULL
;
639 gdk_image
= gdk_image_get( GetPixmap(),
641 GetWidth(), GetHeight() );
645 gdk_image
= gdk_image_get( GetBitmap(),
647 GetWidth(), GetHeight() );
650 wxFAIL_MSG( wxT("Ill-formed bitmap") );
653 wxCHECK_MSG( gdk_image
, wxNullImage
, wxT("couldn't create image") );
655 image
.Create( GetWidth(), GetHeight() );
656 char unsigned *data
= image
.GetData();
660 gdk_image_destroy( gdk_image
);
661 wxFAIL_MSG( wxT("couldn't create image") );
665 GdkImage
*gdk_image_mask
= (GdkImage
*) NULL
;
668 gdk_image_mask
= gdk_image_get( GetMask()->GetBitmap(),
670 GetWidth(), GetHeight() );
672 image
.SetMaskColour( 16, 16, 16 ); // anything unlikely and dividable
676 int red_shift_right
= 0;
677 int green_shift_right
= 0;
678 int blue_shift_right
= 0;
679 int red_shift_left
= 0;
680 int green_shift_left
= 0;
681 int blue_shift_left
= 0;
682 bool use_shift
= FALSE
;
686 GdkVisual
*visual
= gdk_window_get_visual( GetPixmap() );
688 if (visual
== NULL
) visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
690 if (bpp
== 16) bpp
= visual
->red_prec
+ visual
->green_prec
+ visual
->blue_prec
;
691 red_shift_right
= visual
->red_shift
;
692 red_shift_left
= 8-visual
->red_prec
;
693 green_shift_right
= visual
->green_shift
;
694 green_shift_left
= 8-visual
->green_prec
;
695 blue_shift_right
= visual
->blue_shift
;
696 blue_shift_left
= 8-visual
->blue_prec
;
698 use_shift
= (visual
->type
== GDK_VISUAL_TRUE_COLOR
) || (visual
->type
== GDK_VISUAL_DIRECT_COLOR
);
706 GdkColormap
*cmap
= gtk_widget_get_default_colormap();
709 for (int j
= 0; j
< GetHeight(); j
++)
711 for (int i
= 0; i
< GetWidth(); i
++)
713 wxUint32 pixel
= gdk_image_get_pixel( gdk_image
, i
, j
);
731 data
[pos
] = (pixel
>> red_shift_right
) << red_shift_left
;
732 data
[pos
+1] = (pixel
>> green_shift_right
) << green_shift_left
;
733 data
[pos
+2] = (pixel
>> blue_shift_right
) << blue_shift_left
;
735 else if (cmap
->colors
)
737 data
[pos
] = cmap
->colors
[pixel
].red
>> 8;
738 data
[pos
+1] = cmap
->colors
[pixel
].green
>> 8;
739 data
[pos
+2] = cmap
->colors
[pixel
].blue
>> 8;
743 wxFAIL_MSG( wxT("Image conversion failed. Unknown visual type.") );
748 int mask_pixel
= gdk_image_get_pixel( gdk_image_mask
, i
, j
);
761 gdk_image_destroy( gdk_image
);
762 if (gdk_image_mask
) gdk_image_destroy( gdk_image_mask
);
767 wxBitmap::wxBitmap( const wxBitmap
& bmp
)
772 wxBitmap::wxBitmap( const wxString
&filename
, int type
)
774 LoadFile( filename
, type
);
777 wxBitmap::wxBitmap( const char bits
[], int width
, int height
, int WXUNUSED(depth
))
779 m_refData
= new wxBitmapRefData();
781 M_BMPDATA
->m_mask
= (wxMask
*) NULL
;
782 M_BMPDATA
->m_bitmap
=
783 gdk_bitmap_create_from_data( wxGetRootWindow()->window
, (gchar
*) bits
, width
, height
);
784 M_BMPDATA
->m_width
= width
;
785 M_BMPDATA
->m_height
= height
;
786 M_BMPDATA
->m_bpp
= 1;
788 wxCHECK_RET( M_BMPDATA
->m_bitmap
, wxT("couldn't create bitmap") );
791 wxBitmap::~wxBitmap()
795 wxBitmap
& wxBitmap::operator = ( const wxBitmap
& bmp
)
797 if ( m_refData
!= bmp
.m_refData
)
803 bool wxBitmap::operator == ( const wxBitmap
& bmp
) const
805 return m_refData
== bmp
.m_refData
;
808 bool wxBitmap::operator != ( const wxBitmap
& bmp
) const
810 return m_refData
!= bmp
.m_refData
;
813 bool wxBitmap::Ok() const
815 return (m_refData
!= NULL
);
818 int wxBitmap::GetHeight() const
820 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
822 return M_BMPDATA
->m_height
;
825 int wxBitmap::GetWidth() const
827 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
829 return M_BMPDATA
->m_width
;
832 int wxBitmap::GetDepth() const
834 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
836 return M_BMPDATA
->m_bpp
;
839 wxMask
*wxBitmap::GetMask() const
841 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
843 return M_BMPDATA
->m_mask
;
846 void wxBitmap::SetMask( wxMask
*mask
)
848 wxCHECK_RET( Ok(), wxT("invalid bitmap") );
850 if (M_BMPDATA
->m_mask
) delete M_BMPDATA
->m_mask
;
852 M_BMPDATA
->m_mask
= mask
;
855 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
861 wxBitmap
wxBitmap::GetSubBitmap( const wxRect
& rect
) const
864 (rect
.x
>= 0) && (rect
.y
>= 0) &&
865 (rect
.x
+rect
.width
<= M_BMPDATA
->m_width
) && (rect
.y
+rect
.height
<= M_BMPDATA
->m_height
),
866 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
868 wxBitmap
ret( rect
.width
, rect
.height
, M_BMPDATA
->m_bpp
);
869 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
873 GdkGC
*gc
= gdk_gc_new( ret
.GetPixmap() );
874 gdk_draw_pixmap( ret
.GetPixmap(), gc
, GetPixmap(), rect
.x
, rect
.y
, 0, 0, rect
.width
, rect
.height
);
875 gdk_gc_destroy( gc
);
879 GdkGC
*gc
= gdk_gc_new( ret
.GetBitmap() );
880 gdk_wx_draw_bitmap( ret
.GetBitmap(), gc
, GetBitmap(), rect
.x
, rect
.y
, 0, 0, rect
.width
, rect
.height
);
881 gdk_gc_destroy( gc
);
886 wxMask
*mask
= new wxMask
;
887 mask
->m_bitmap
= gdk_pixmap_new( wxGetRootWindow()->window
, rect
.width
, rect
.height
, 1 );
889 GdkGC
*gc
= gdk_gc_new( mask
->m_bitmap
);
890 gdk_wx_draw_bitmap( mask
->m_bitmap
, gc
, M_BMPDATA
->m_mask
->m_bitmap
, 0, 0, rect
.x
, rect
.y
, rect
.width
, rect
.height
);
891 gdk_gc_destroy( gc
);
899 bool wxBitmap::SaveFile( const wxString
&name
, int type
, wxPalette
*WXUNUSED(palette
) )
901 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid bitmap") );
903 // Try to save the bitmap via wxImage handlers:
905 wxImage
image( *this );
906 if (image
.Ok()) return image
.SaveFile( name
, type
);
912 bool wxBitmap::LoadFile( const wxString
&name
, int type
)
916 if (!wxFileExists(name
)) return FALSE
;
918 GdkVisual
*visual
= gdk_window_get_visual( wxGetRootWindow()->window
);
921 if (type
== wxBITMAP_TYPE_XPM
)
923 m_refData
= new wxBitmapRefData();
925 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
927 M_BMPDATA
->m_pixmap
= gdk_pixmap_create_from_xpm( wxGetRootWindow()->window
, &mask
, NULL
, name
.fn_str() );
931 M_BMPDATA
->m_mask
= new wxMask();
932 M_BMPDATA
->m_mask
->m_bitmap
= mask
;
935 gdk_window_get_size( M_BMPDATA
->m_pixmap
, &(M_BMPDATA
->m_width
), &(M_BMPDATA
->m_height
) );
937 M_BMPDATA
->m_bpp
= visual
->depth
;
939 else // try if wxImage can load it
942 if (!image
.LoadFile( name
, type
)) return FALSE
;
943 if (image
.Ok()) *this = image
.ConvertToBitmap();
950 wxPalette
*wxBitmap::GetPalette() const
952 if (!Ok()) return (wxPalette
*) NULL
;
954 return M_BMPDATA
->m_palette
;
957 void wxBitmap::SetHeight( int height
)
959 if (!m_refData
) m_refData
= new wxBitmapRefData();
961 M_BMPDATA
->m_height
= height
;
964 void wxBitmap::SetWidth( int width
)
966 if (!m_refData
) m_refData
= new wxBitmapRefData();
968 M_BMPDATA
->m_width
= width
;
971 void wxBitmap::SetDepth( int depth
)
973 if (!m_refData
) m_refData
= new wxBitmapRefData();
975 M_BMPDATA
->m_bpp
= depth
;
978 void wxBitmap::SetPixmap( GdkPixmap
*pixmap
)
980 if (!m_refData
) m_refData
= new wxBitmapRefData();
982 M_BMPDATA
->m_pixmap
= pixmap
;
985 void wxBitmap::SetBitmap( GdkPixmap
*bitmap
)
987 if (!m_refData
) m_refData
= new wxBitmapRefData();
989 M_BMPDATA
->m_bitmap
= bitmap
;
992 GdkPixmap
*wxBitmap::GetPixmap() const
994 wxCHECK_MSG( Ok(), (GdkPixmap
*) NULL
, wxT("invalid bitmap") );
996 return M_BMPDATA
->m_pixmap
;
999 GdkBitmap
*wxBitmap::GetBitmap() const
1001 wxCHECK_MSG( Ok(), (GdkBitmap
*) NULL
, wxT("invalid bitmap") );
1003 return M_BMPDATA
->m_bitmap
;