Remove GTK2 stuff from src/gtk1. Rename wx/gtk includes to wx/gtk1.
[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 if (m_bitmap.HasPixbuf())
82 {
83 gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget),
84 m_bitmap.GetPixbuf());
85 }
86 else
87 gtk_image_set_from_pixmap(GTK_IMAGE(m_widget),
88 m_bitmap.GetPixmap(), mask);
89
90 InvalidateBestSize();
91 SetSize(GetBestSize());
92 }
93 }
94
95 // static
96 wxVisualAttributes
97 wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
98 {
99 // TODO: overload to allow using gtk_pixmap_new?
100 return GetDefaultAttributesFromGTKWidget(gtk_label_new);
101 }
102
103 #endif // wxUSE_STATBMP
104