]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/statbmp.cpp
*** empty log message ***
[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/statbmp.h"
15
16 #if wxUSE_STATBMP
17
18 #include "gdk/gdk.h"
19 #include "gtk/gtk.h"
20
21 //-----------------------------------------------------------------------------
22 // wxStaticBitmap
23 //-----------------------------------------------------------------------------
24
25 IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
26
27 wxStaticBitmap::wxStaticBitmap(void)
28 {
29 }
30
31 wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
32 const wxPoint &pos, const wxSize &size,
33 long style, const wxString &name )
34 {
35 Create( parent, id, bitmap, pos, size, style, name );
36 }
37
38 void wxStaticBitmap::CreatePixmapWidget()
39 {
40 wxCHECK_RET( m_bitmap.Ok(), "should only be called if we have a bitmap" );
41
42 GdkBitmap *mask = (GdkBitmap *) NULL;
43 if ( m_bitmap.GetMask() )
44 mask = m_bitmap.GetMask()->GetBitmap();
45 m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
46
47 PostCreation();
48 }
49
50 bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
51 const wxPoint &pos, const wxSize &size,
52 long style, const wxString &name )
53 {
54 m_needParent = TRUE;
55
56 wxSize newSize = size;
57
58 PreCreation( parent, id, pos, size, style, name );
59
60 m_bitmap = bitmap;
61
62 if (m_bitmap.Ok())
63 {
64 CreatePixmapWidget();
65
66 if (newSize.x == -1) newSize.x = m_bitmap.GetWidth();
67 if (newSize.y == -1) newSize.y = m_bitmap.GetHeight();
68 SetSize( newSize.x, newSize.y );
69 }
70 else
71 {
72 m_widget = gtk_label_new( "Bitmap" );
73
74 PostCreation();
75 }
76
77 m_parent->DoAddChild( this );
78
79 Show( TRUE );
80
81 return TRUE;
82 }
83
84 void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
85 {
86 bool hasWidget = m_bitmap.Ok();
87 m_bitmap = bitmap;
88
89 if (m_bitmap.Ok())
90 {
91 if ( !hasWidget )
92 {
93 gtk_widget_destroy( m_widget );
94
95 // recreate m_widget because we'd created a label and not a bitmap
96 // above
97 CreatePixmapWidget();
98 }
99
100 GdkBitmap *mask = (GdkBitmap *) NULL;
101 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
102 gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
103 }
104 }
105
106 #endif