]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/statbmp.cpp
fix compilation both for Robert's cross-compiler and for all normal compilers by...
[wxWidgets.git] / src / gtk1 / statbmp.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: statbmp.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #if wxUSE_STATBMP
14
15 #include "wx/statbmp.h"
16
17 #include "gdk/gdk.h"
18 #include "gtk/gtk.h"
19
20 //-----------------------------------------------------------------------------
21 // wxStaticBitmap
22 //-----------------------------------------------------------------------------
23
24 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
25
26 wxStaticBitmap::wxStaticBitmap(void)
27 {
28 }
29
30 wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
31 const wxPoint &pos, const wxSize &size,
32 long style, const wxString &name )
33 {
34 Create( parent, id, bitmap, pos, size, style, name );
35 }
36
37 // empty bitmap, so that we can create GtkPixmap widget:
38 static char * bogus_xpm[] = {
39 "2 2 1 1",
40 " c None",
41 " ",
42 " "};
43
44 bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
45 const wxPoint &pos, const wxSize &size,
46 long style, const wxString &name )
47 {
48 m_needParent = TRUE;
49
50 if (!PreCreation( parent, pos, size ) ||
51 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
52 {
53 wxFAIL_MSG( wxT("wxStaticBitmap creation failed") );
54 return false;
55 }
56
57 m_bitmap = bitmap;
58
59 wxBitmap bmp(bitmap.Ok() ? bitmap : wxBitmap(bogus_xpm));
60 m_widget = gtk_pixmap_new(bmp.GetPixmap(), NULL);
61
62 if (bitmap.Ok())
63 SetBitmap(bitmap);
64
65 PostCreation(size);
66 m_parent->DoAddChild( this );
67
68 return true;
69 }
70
71 void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
72 {
73 m_bitmap = bitmap;
74
75 if (m_bitmap.Ok())
76 {
77 GdkBitmap *mask = (GdkBitmap *) NULL;
78 if (m_bitmap.GetMask())
79 mask = m_bitmap.GetMask()->GetBitmap();
80
81 gtk_pixmap_set(GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask);
82
83 InvalidateBestSize();
84 SetSize(GetBestSize());
85 }
86 }
87
88 // static
89 wxVisualAttributes
90 wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
91 {
92 // TODO: overload to allow using gtk_pixmap_new?
93 return GetDefaultAttributesFromGTKWidget(gtk_label_new);
94 }
95
96 #endif // wxUSE_STATBMP
97