]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/statbmp.cpp
Use wxGtkString here too
[wxWidgets.git] / src / gtk / 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 bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
38 const wxPoint &pos, const wxSize &size,
39 long style, const wxString &name )
40 {
41 m_needParent = TRUE;
42
43 if (!PreCreation( parent, pos, size ) ||
44 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
45 {
46 wxFAIL_MSG( wxT("wxStaticBitmap creation failed") );
47 return false;
48 }
49
50 m_bitmap = bitmap;
51
52 m_widget = gtk_image_new();
53
54 if (bitmap.Ok())
55 SetBitmap(bitmap);
56
57 PostCreation(size);
58 m_parent->DoAddChild( this );
59
60 return true;
61 }
62
63 void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
64 {
65 m_bitmap = bitmap;
66
67 if (m_bitmap.Ok())
68 {
69 GdkBitmap *mask = (GdkBitmap *) NULL;
70 if (m_bitmap.GetMask())
71 mask = m_bitmap.GetMask()->GetBitmap();
72
73 if (m_bitmap.HasPixbuf())
74 {
75 gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget),
76 m_bitmap.GetPixbuf());
77 }
78 else
79 gtk_image_set_from_pixmap(GTK_IMAGE(m_widget),
80 m_bitmap.GetPixmap(), mask);
81
82 InvalidateBestSize();
83 SetSize(GetBestSize());
84 }
85 }
86
87 // static
88 wxVisualAttributes
89 wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
90 {
91 // TODO: overload to allow using gtk_pixmap_new?
92 return GetDefaultAttributesFromGTKWidget(gtk_label_new);
93 }
94
95 #endif // wxUSE_STATBMP
96