1/////////////////////////////////////////////////////////////////////////////
2// Name:        statbmp.cpp
3// Purpose:
4// Author:      Robert Roebling
5// Id:          $Id: statbmp.cpp 54676 2008-07-18 02:45:48Z PC $
6// Copyright:   (c) 1998 Robert Roebling
7// Licence:           wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#if wxUSE_STATBMP
14
15#include "wx/statbmp.h"
16
17#include "gdk/gdk.h"
18#include "gtk/gtk.h"
19
20//-----------------------------------------------------------------------------
21// wxStaticBitmap
22//-----------------------------------------------------------------------------
23
24IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
25
26wxStaticBitmap::wxStaticBitmap(void)
27{
28}
29
30wxStaticBitmap::wxStaticBitmap( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
31      const wxPoint &pos, const wxSize &size,
32      long style, const wxString &name )
33{
34    Create( parent, id, bitmap, pos, size, style, name );
35}
36
37bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
38                             const wxPoint &pos, const wxSize &size,
39                             long style, const wxString &name )
40{
41    m_needParent = TRUE;
42
43    if (!PreCreation( parent, pos, size ) ||
44        !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
45    {
46        wxFAIL_MSG( wxT("wxStaticBitmap creation failed") );
47        return false;
48    }
49
50    m_bitmap = bitmap;
51
52    m_widget = gtk_image_new();
53
54    if (bitmap.Ok())
55        SetBitmap(bitmap);
56
57    PostCreation(size);
58    m_parent->DoAddChild( this );
59
60    return true;
61}
62
63void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
64{
65    m_bitmap = bitmap;
66
67    if (m_bitmap.Ok())
68    {
69        // always use pixbuf, because pixmap mask does not
70        // work with disabled images in some themes
71        gtk_image_set_from_pixbuf(GTK_IMAGE(m_widget), m_bitmap.GetPixbuf());
72
73        InvalidateBestSize();
74        SetSize(GetBestSize());
75    }
76}
77
78// static
79wxVisualAttributes
80wxStaticBitmap::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
81{
82    // TODO: overload to allow using gtk_pixmap_new?
83    return GetDefaultAttributesFromGTKWidget(gtk_label_new);
84}
85
86#endif // wxUSE_STATBMP
87
88