]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/statbmp.cpp
wxInputConsumer
[wxWidgets.git] / src / gtk / statbmp.cpp
CommitLineData
1a56f55c
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: statbmp.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
f03fc89f 7// Licence: wxWindows licence
1a56f55c
RR
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "statbmp.h"
12#endif
13
1e6feb95 14#include "wx/defs.h"
1a56f55c 15
dcf924a3
RR
16#if wxUSE_STATBMP
17
1e6feb95
VZ
18#include "wx/statbmp.h"
19
83624f79
RR
20#include "gdk/gdk.h"
21#include "gtk/gtk.h"
22
1a56f55c
RR
23//-----------------------------------------------------------------------------
24// wxStaticBitmap
25//-----------------------------------------------------------------------------
26
27IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
28
29wxStaticBitmap::wxStaticBitmap(void)
30{
58614078 31}
1a56f55c 32
c35414db
VZ
33wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
34 const wxPoint &pos, const wxSize &size,
debe6624 35 long style, const wxString &name )
1a56f55c 36{
a93109d5 37 Create( parent, id, bitmap, pos, size, style, name );
58614078 38}
1a56f55c 39
32d4bfd1
VZ
40void wxStaticBitmap::CreatePixmapWidget()
41{
223d09f6 42 wxCHECK_RET( m_bitmap.Ok(), wxT("should only be called if we have a bitmap") );
32d4bfd1
VZ
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
76fcf0f2 49 // insert GTK representation
953704c1 50 (*m_parent->m_insertCallback)(m_parent, this);
31528cd3 51
953704c1
RR
52 gtk_widget_show( m_widget );
53
76fcf0f2
RR
54 m_focusWidget = m_widget;
55
32d4bfd1
VZ
56 PostCreation();
57}
58
c35414db 59bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
32d4bfd1
VZ
60 const wxPoint &pos, const wxSize &size,
61 long style, const wxString &name )
1a56f55c 62{
a93109d5 63 m_needParent = TRUE;
c35414db 64
4dcaf11a
RR
65 if (!PreCreation( parent, pos, size ) ||
66 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
67 {
223d09f6 68 wxFAIL_MSG( wxT("wxXX creation failed") );
76fcf0f2 69 return FALSE;
4dcaf11a 70 }
1a56f55c 71
a93109d5 72 m_bitmap = bitmap;
c35414db 73
a93109d5
RR
74 if (m_bitmap.Ok())
75 {
953704c1
RR
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 );
c35414db 80
1e6feb95 81 SetBestSize( size );
a93109d5
RR
82 }
83 else
84 {
85 m_widget = gtk_label_new( "Bitmap" );
76fcf0f2
RR
86
87 m_focusWidget = m_widget;
c35414db 88
953704c1
RR
89 PostCreation();
90 }
31528cd3 91
f03fc89f 92 m_parent->DoAddChild( this );
c35414db 93
a93109d5 94 Show( TRUE );
c35414db 95
a93109d5 96 return TRUE;
58614078 97}
1a56f55c 98
c35414db 99void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
1a56f55c 100{
32d4bfd1 101 bool hasWidget = m_bitmap.Ok();
a93109d5 102 m_bitmap = bitmap;
c35414db 103
a93109d5
RR
104 if (m_bitmap.Ok())
105 {
953704c1 106 if (!hasWidget)
32d4bfd1
VZ
107 {
108 gtk_widget_destroy( m_widget );
109
31528cd3
VZ
110 /* recreate m_widget because we've created a label
111 and not a bitmap above */
32d4bfd1
VZ
112 CreatePixmapWidget();
113 }
31528cd3
VZ
114 else
115 {
953704c1
RR
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 );
31528cd3
VZ
119 }
120
1e6feb95 121 SetBestSize(wxSize(bitmap.GetWidth(), bitmap.GetHeight()));
a93109d5 122 }
58614078 123}
dcf924a3 124
1e6feb95 125#endif // wxUSE_STATBMP
f68586e5 126