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