]>
Commit | Line | Data |
---|---|---|
151ccd11 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bmpbuttn.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
01111366 RR |
5 | // Id: $id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
151ccd11 RR |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "bmpbuttn.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/bmpbuttn.h" | |
15 | ||
16 | //----------------------------------------------------------------------------- | |
17 | // classes | |
18 | //----------------------------------------------------------------------------- | |
19 | ||
20 | class wxBitmapButton; | |
21 | ||
66bd6b93 RR |
22 | //----------------------------------------------------------------------------- |
23 | // data | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
26 | extern bool g_blockEventsOnDrag; | |
27 | ||
151ccd11 | 28 | //----------------------------------------------------------------------------- |
e1e955e1 | 29 | // "clicked" |
151ccd11 RR |
30 | //----------------------------------------------------------------------------- |
31 | ||
66bd6b93 | 32 | static void gtk_bmpbutton_clicked_callback( GtkWidget *WXUNUSED(widget), wxBitmapButton *button ) |
151ccd11 | 33 | { |
66bd6b93 RR |
34 | if (!button->HasVMT()) return; |
35 | if (g_blockEventsOnDrag) return; | |
36 | ||
151ccd11 RR |
37 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, button->GetId()); |
38 | event.SetEventObject(button); | |
47908e25 | 39 | button->GetEventHandler()->ProcessEvent(event); |
6de97a3b | 40 | } |
151ccd11 RR |
41 | |
42 | //----------------------------------------------------------------------------- | |
e1e955e1 RR |
43 | // wxBitmapButton |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton,wxControl) | |
151ccd11 RR |
47 | |
48 | wxBitmapButton::wxBitmapButton(void) | |
49 | { | |
6de97a3b | 50 | } |
151ccd11 RR |
51 | |
52 | bool wxBitmapButton::Create( wxWindow *parent, wxWindowID id, const wxBitmap &bitmap, | |
53 | const wxPoint &pos, const wxSize &size, | |
6de97a3b | 54 | long style, const wxValidator& validator, const wxString &name ) |
151ccd11 RR |
55 | { |
56 | m_needParent = TRUE; | |
57 | ||
58 | wxSize newSize = size; | |
59 | ||
60 | PreCreation( parent, id, pos, newSize, style, name ); | |
61 | ||
6de97a3b RR |
62 | SetValidator( validator ); |
63 | ||
151ccd11 RR |
64 | m_bitmap = bitmap; |
65 | m_label = ""; | |
66 | ||
67 | m_widget = gtk_button_new(); | |
68 | ||
69 | if (m_bitmap.Ok()) | |
70 | { | |
c67daf87 | 71 | GdkBitmap *mask = (GdkBitmap *) NULL; |
151ccd11 RR |
72 | if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap(); |
73 | GtkWidget *pixmap = gtk_pixmap_new( m_bitmap.GetPixmap(), mask ); | |
74 | ||
75 | gtk_widget_show( pixmap ); | |
76 | gtk_container_add( GTK_CONTAINER(m_widget), pixmap ); | |
6de97a3b | 77 | } |
151ccd11 | 78 | |
151ccd11 RR |
79 | if (newSize.x == -1) newSize.x = m_bitmap.GetHeight()+10; |
80 | if (newSize.y == -1) newSize.y = m_bitmap.GetWidth()+10; | |
81 | SetSize( newSize.x, newSize.y ); | |
82 | ||
83 | gtk_signal_connect( GTK_OBJECT(m_widget), "clicked", | |
112892b9 | 84 | GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback), (gpointer*)this ); |
151ccd11 RR |
85 | |
86 | PostCreation(); | |
87 | ||
88 | Show( TRUE ); | |
89 | ||
90 | return TRUE; | |
6de97a3b | 91 | } |
151ccd11 RR |
92 | |
93 | void wxBitmapButton::SetDefault(void) | |
94 | { | |
903f689b RR |
95 | /* |
96 | GTK_WIDGET_SET_FLAGS( m_widget, GTK_CAN_DEFAULT ); | |
6de97a3b | 97 | gtk_widget_grab_default( m_widget ); |
903f689b | 98 | */ |
6de97a3b | 99 | } |
151ccd11 RR |
100 | |
101 | void wxBitmapButton::SetLabel( const wxString &label ) | |
102 | { | |
103 | wxControl::SetLabel( label ); | |
6de97a3b | 104 | } |
151ccd11 RR |
105 | |
106 | wxString wxBitmapButton::GetLabel(void) const | |
107 | { | |
108 | return wxControl::GetLabel(); | |
6de97a3b | 109 | } |
903f689b RR |
110 | |
111 | void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap ) | |
112 | { | |
113 | m_bitmap = bitmap; | |
114 | if (!m_bitmap.Ok()) return; | |
115 | ||
116 | GtkButton *bin = GTK_BUTTON( m_widget ); | |
117 | GtkPixmap *g_pixmap = GTK_PIXMAP( bin->child ); | |
118 | ||
c67daf87 | 119 | GdkBitmap *mask = (GdkBitmap *) NULL; |
903f689b RR |
120 | if (m_bitmap.GetMask()) mask = m_bitmap.GetMask()->GetBitmap(); |
121 | ||
122 | gtk_pixmap_set( g_pixmap, m_bitmap.GetPixmap(), mask ); | |
123 | } | |
124 | ||
125 | ||
126 | ||
127 |