]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/statbmp.cpp
readability cleanup
[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 #ifndef __WXGTK20__
38 // empty bitmap, so that we can create GtkPixmap widget:
39 static char * bogus_xpm[] = {
40 "2 2 1 1",
41 " c None",
42 " ",
43 " "};
44 #endif
45
46 bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
47 const wxPoint &pos, const wxSize &size,
48 long style, const wxString &name )
49 {
50 m_needParent = TRUE;
51
52 if (!PreCreation( parent, pos, size ) ||
53 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
54 {
55 wxFAIL_MSG( wxT("wxStaticBitmap creation failed") );
56 return false;
57 }
58
59 m_bitmap = bitmap;
60
61 #ifdef __WXGTK20__
62 m_widget = gtk_image_new();
63 #else
64 wxBitmap bmp(bitmap.Ok() ? bitmap : wxBitmap(bogus_xpm));
65 m_widget = gtk_pixmap_new(bmp.GetPixmap(), NULL);
66 #endif
67
68 if (bitmap.Ok())
69 SetBitmap(bitmap);
70
71 PostCreation(size);
72 m_parent->DoAddChild( this );
73
74 return true;
75 }
76
77 void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
78 {
79 m_bitmap = bitmap;
80
81 if (m_bitmap.Ok())
82 {
83 GdkBitmap *mask = (GdkBitmap *) NULL;
84 if (m_bitmap.GetMask())
85 mask = m_bitmap.GetMask()->GetBitmap();
86
87 #ifdef __WXGTK20__
88 if (m_bitmap.HasPixbuf())
89 {
90 gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget),
91 m_bitmap.GetPixbuf());
92 }
93 else
94 gtk_image_set_from_pixmap(GTK_IMAGE(m_widget),
95 m_bitmap.GetPixmap(), mask);
96 #else
97 gtk_pixmap_set(GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask);
98 #endif
99
100 InvalidateBestSize();
101 SetSize(GetBestSize());
102 }
103 }
104
105 // static
106 wxVisualAttributes
107 wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
108 {
109 // TODO: overload to allow using gtk_pixmap_new?
110 return GetDefaultAttributesFromGTKWidget(gtk_label_new);
111 }
112
113 #endif // wxUSE_STATBMP
114