]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/statbmp.cpp
wxSlider should now display int values,
[wxWidgets.git] / src / gtk1 / statbmp.cpp
... / ...
CommitLineData
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
25IMPLEMENT_DYNAMIC_CLASS(wxStaticBitmap,wxControl)
26
27wxStaticBitmap::wxStaticBitmap(void)
28{
29}
30
31wxStaticBitmap::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
38void wxStaticBitmap::CreatePixmapWidget()
39{
40 wxCHECK_RET( m_bitmap.Ok(), wxT("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 /* insert GTK representation */
48 (*m_parent->m_insertCallback)(m_parent, this);
49
50 gtk_widget_show( m_widget );
51
52 PostCreation();
53}
54
55bool wxStaticBitmap::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap,
56 const wxPoint &pos, const wxSize &size,
57 long style, const wxString &name )
58{
59 m_needParent = TRUE;
60
61 if (!PreCreation( parent, pos, size ) ||
62 !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
63 {
64 wxFAIL_MSG( wxT("wxXX creation failed") );
65 return FALSE;
66 }
67
68 m_bitmap = bitmap;
69
70 if (m_bitmap.Ok())
71 {
72 wxSize newSize = size;
73
74 GdkBitmap *mask = (GdkBitmap *) NULL;
75 if ( m_bitmap.GetMask() )
76 mask = m_bitmap.GetMask()->GetBitmap();
77 m_widget = gtk_pixmap_new( m_bitmap.GetPixmap(), mask );
78
79 if (newSize.x == -1) newSize.x = m_bitmap.GetWidth();
80 if (newSize.y == -1) newSize.y = m_bitmap.GetHeight();
81 SetSize( newSize.x, newSize.y );
82 }
83 else
84 {
85 m_widget = gtk_label_new( "Bitmap" );
86
87 PostCreation();
88 }
89
90 m_parent->DoAddChild( this );
91
92 Show( TRUE );
93
94 return TRUE;
95}
96
97void wxStaticBitmap::SetBitmap( const wxBitmap &bitmap )
98{
99 bool hasWidget = m_bitmap.Ok();
100 m_bitmap = bitmap;
101
102 if (m_bitmap.Ok())
103 {
104 if (!hasWidget)
105 {
106 gtk_widget_destroy( m_widget );
107
108 /* recreate m_widget because we've created a label
109 and not a bitmap above */
110 CreatePixmapWidget();
111 }
112 else
113 {
114 GdkBitmap *mask = (GdkBitmap *) NULL;
115 if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap();
116 gtk_pixmap_set( GTK_PIXMAP(m_widget), m_bitmap.GetPixmap(), mask );
117 }
118
119 SetSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() );
120 }
121}
122
123#endif