]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/statbmp.cpp
Fix memory leak when a spacer is added, and crash when a window is added before wxSiz...
[wxWidgets.git] / src / gtk1 / 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
65571936 7// Licence: wxWindows licence
1a56f55c
RR
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2 10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1a56f55c
RR
11#pragma implementation "statbmp.h"
12#endif
13
14f355c2
VS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
1a56f55c 16
dcf924a3
RR
17#if wxUSE_STATBMP
18
1e6feb95
VZ
19#include "wx/statbmp.h"
20
83624f79
RR
21#include "gdk/gdk.h"
22#include "gtk/gtk.h"
23
1a56f55c
RR
24//-----------------------------------------------------------------------------
25// wxStaticBitmap
26//-----------------------------------------------------------------------------
27
28IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
29
30wxStaticBitmap::wxStaticBitmap(void)
31{
58614078 32}
1a56f55c 33
c35414db
VZ
34wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
35 const wxPoint &pos, const wxSize &size,
debe6624 36 long style, const wxString &name )
1a56f55c 37{
a93109d5 38 Create( parent, id, bitmap, pos, size, style, name );
58614078 39}
1a56f55c 40
4fab7128
VS
41#ifndef __WXGTK20__
42// empty bitmap, so that we can create GtkPixmap widget:
43static char * bogus_xpm[] = {
44"2 2 1 1",
45" c None",
46" ",
47" "};
48#endif
32d4bfd1 49
c35414db 50bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
32d4bfd1
VZ
51 const wxPoint &pos, const wxSize &size,
52 long style, const wxString &name )
1a56f55c 53{
a93109d5 54 m_needParent = TRUE;
c35414db 55
4dcaf11a
RR
56 if (!PreCreation( parent, pos, size ) ||
57 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
58 {
4fab7128
VS
59 wxFAIL_MSG( wxT("wxStaticBitmap creation failed") );
60 return false;
4dcaf11a 61 }
1a56f55c 62
a93109d5 63 m_bitmap = bitmap;
c35414db 64
4fab7128
VS
65#ifdef __WXGTK20__
66 m_widget = gtk_image_new();
67#else
68 wxBitmap bmp(bitmap.Ok() ? bitmap : wxBitmap(bogus_xpm));
69 m_widget = gtk_pixmap_new(bmp.GetPixmap(), NULL);
70#endif
71
72 if (bitmap.Ok())
73 SetBitmap(bitmap);
31528cd3 74
abdeb9e7 75 PostCreation(size);
f03fc89f 76 m_parent->DoAddChild( this );
c35414db 77
4fab7128 78 return true;
58614078 79}
1a56f55c 80
c35414db 81void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
1a56f55c 82{
a93109d5 83 m_bitmap = bitmap;
c35414db 84
a93109d5
RR
85 if (m_bitmap.Ok())
86 {
4fab7128
VS
87 GdkBitmap *mask = (GdkBitmap *) NULL;
88 if (m_bitmap.GetMask())
89 mask = m_bitmap.GetMask()->GetBitmap();
90
91#ifdef __WXGTK20__
92 if (m_bitmap.HasPixbuf())
32d4bfd1 93 {
4fab7128
VS
94 gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget),
95 m_bitmap.GetPixbuf());
32d4bfd1 96 }
31528cd3 97 else
4fab7128
VS
98 gtk_image_set_from_pixmap(GTK_IMAGE(m_widget),
99 m_bitmap.GetPixmap(), mask);
100#else
101 gtk_pixmap_set(GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask);
102#endif
31528cd3 103
9f884528
RD
104 InvalidateBestSize();
105 SetSize(GetBestSize());
a93109d5 106 }
58614078 107}
dcf924a3 108
9d522606
RD
109// static
110wxVisualAttributes
111wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
112{
113 // TODO: overload to allow using gtk_pixmap_new?
114 return GetDefaultAttributesFromGTKWidget(gtk_label_new);
115}
116
1e6feb95 117#endif // wxUSE_STATBMP
f68586e5 118