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