]>
Commit | Line | Data |
---|---|---|
1a56f55c RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: statbmp.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
1a56f55c RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
1a56f55c | 12 | |
dcf924a3 RR |
13 | #if wxUSE_STATBMP |
14 | ||
1e6feb95 VZ |
15 | #include "wx/statbmp.h" |
16 | ||
83624f79 RR |
17 | #include "gdk/gdk.h" |
18 | #include "gtk/gtk.h" | |
19 | ||
1a56f55c RR |
20 | //----------------------------------------------------------------------------- |
21 | // wxStaticBitmap | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl) | |
25 | ||
26 | wxStaticBitmap::wxStaticBitmap(void) | |
27 | { | |
58614078 | 28 | } |
1a56f55c | 29 | |
c35414db VZ |
30 | wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap, |
31 | const wxPoint &pos, const wxSize &size, | |
debe6624 | 32 | long style, const wxString &name ) |
1a56f55c | 33 | { |
a93109d5 | 34 | Create( parent, id, bitmap, pos, size, style, name ); |
58614078 | 35 | } |
1a56f55c | 36 | |
4fab7128 VS |
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 | |
32d4bfd1 | 45 | |
c35414db | 46 | bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap, |
32d4bfd1 VZ |
47 | const wxPoint &pos, const wxSize &size, |
48 | long style, const wxString &name ) | |
1a56f55c | 49 | { |
a93109d5 | 50 | m_needParent = TRUE; |
c35414db | 51 | |
4dcaf11a RR |
52 | if (!PreCreation( parent, pos, size ) || |
53 | !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name )) | |
54 | { | |
4fab7128 VS |
55 | wxFAIL_MSG( wxT("wxStaticBitmap creation failed") ); |
56 | return false; | |
4dcaf11a | 57 | } |
1a56f55c | 58 | |
a93109d5 | 59 | m_bitmap = bitmap; |
c35414db | 60 | |
4fab7128 VS |
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); | |
31528cd3 | 70 | |
abdeb9e7 | 71 | PostCreation(size); |
f03fc89f | 72 | m_parent->DoAddChild( this ); |
c35414db | 73 | |
4fab7128 | 74 | return true; |
58614078 | 75 | } |
1a56f55c | 76 | |
c35414db | 77 | void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap ) |
1a56f55c | 78 | { |
a93109d5 | 79 | m_bitmap = bitmap; |
c35414db | 80 | |
a93109d5 RR |
81 | if (m_bitmap.Ok()) |
82 | { | |
4fab7128 VS |
83 | GdkBitmap *mask = (GdkBitmap *) NULL; |
84 | if (m_bitmap.GetMask()) | |
85 | mask = m_bitmap.GetMask()->GetBitmap(); | |
3d257b8d | 86 | |
4fab7128 VS |
87 | #ifdef __WXGTK20__ |
88 | if (m_bitmap.HasPixbuf()) | |
32d4bfd1 | 89 | { |
4fab7128 VS |
90 | gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget), |
91 | m_bitmap.GetPixbuf()); | |
32d4bfd1 | 92 | } |
31528cd3 | 93 | else |
4fab7128 VS |
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 | |
31528cd3 | 99 | |
9f884528 RD |
100 | InvalidateBestSize(); |
101 | SetSize(GetBestSize()); | |
a93109d5 | 102 | } |
58614078 | 103 | } |
dcf924a3 | 104 | |
9d522606 RD |
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 | ||
1e6feb95 | 113 | #endif // wxUSE_STATBMP |
f68586e5 | 114 |