]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/statbmp.cpp
Added a sample to the demo that catches various key events and
[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 #ifdef __GNUG__
11 #pragma implementation "statbmp.h"
12 #endif
13
14 #include "wx/defs.h"
15
16 #if wxUSE_STATBMP
17
18 #include "wx/statbmp.h"
19
20 #include "gdk/gdk.h"
21 #include "gtk/gtk.h"
22
23 //-----------------------------------------------------------------------------
24 // wxStaticBitmap
25 //-----------------------------------------------------------------------------
26
27 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
28
29 wxStaticBitmap::wxStaticBitmap(void)
30 {
31 }
32
33 wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
34 const wxPoint &pos, const wxSize &size,
35 long style, const wxString &name )
36 {
37 Create( parent, id, bitmap, pos, size, style, name );
38 }
39
40 void wxStaticBitmap::CreatePixmapWidget()
41 {
42 wxCHECK_RET( m_bitmap.Ok(), wxT("should only be called if we have a bitmap") );
43
44 GdkBitmap *mask = (GdkBitmap *) NULL;
45 if ( m_bitmap.GetMask() )
46 mask = m_bitmap.GetMask()->GetBitmap();
47 m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
48
49 // insert GTK representation
50 (*m_parent->m_insertCallback)(m_parent, this);
51
52 gtk_widget_show( m_widget );
53
54 m_focusWidget = m_widget;
55
56 PostCreation();
57 }
58
59 bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
60 const wxPoint &pos, const wxSize &size,
61 long style, const wxString &name )
62 {
63 m_needParent = TRUE;
64
65 if (!PreCreation( parent, pos, size ) ||
66 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
67 {
68 wxFAIL_MSG( wxT("wxXX creation failed") );
69 return FALSE;
70 }
71
72 m_bitmap = bitmap;
73
74 if (m_bitmap.Ok())
75 {
76 GdkBitmap *mask = (GdkBitmap *) NULL;
77 if ( m_bitmap.GetMask() )
78 mask = m_bitmap.GetMask()->GetBitmap();
79 m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
80
81 SetBestSize( size );
82 }
83 else
84 {
85 m_widget = gtk_label_new( "Bitmap" );
86
87 m_focusWidget = m_widget;
88
89 PostCreation();
90 }
91
92 m_parent->DoAddChild( this );
93
94 Show( TRUE );
95
96 return TRUE;
97 }
98
99 void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
100 {
101 bool hasWidget = m_bitmap.Ok();
102 m_bitmap = bitmap;
103
104 if (m_bitmap.Ok())
105 {
106 if (!hasWidget)
107 {
108 gtk_widget_destroy( m_widget );
109
110 /* recreate m_widget because we've created a label
111 and not a bitmap above */
112 CreatePixmapWidget();
113 }
114 else
115 {
116 GdkBitmap *mask = (GdkBitmap *) NULL;
117 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
118 gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
119 }
120
121 SetBestSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
122 }
123 }
124
125 #endif // wxUSE_STATBMP
126