1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        gtk/bmpbuttn.cpp 
   4 // Author:      Robert Roebling 
   6 // Copyright:   (c) 1998 Robert Roebling 
   7 // Licence:     wxWindows licence 
   8 ///////////////////////////////////////////////////////////////////////////// 
  11 #pragma implementation "bmpbuttn.h" 
  18 #include "wx/bmpbuttn.h" 
  23 //----------------------------------------------------------------------------- 
  25 //----------------------------------------------------------------------------- 
  29 //----------------------------------------------------------------------------- 
  31 //----------------------------------------------------------------------------- 
  33 extern void wxapp_install_idle_handler(); 
  36 //----------------------------------------------------------------------------- 
  38 //----------------------------------------------------------------------------- 
  40 extern bool   g_blockEventsOnDrag
; 
  42 //----------------------------------------------------------------------------- 
  44 //----------------------------------------------------------------------------- 
  46 static void gtk_bmpbutton_clicked_callback( GtkWidget 
*WXUNUSED(widget
), wxBitmapButton 
*button 
) 
  49         wxapp_install_idle_handler(); 
  51     if (!button
->m_hasVMT
) return; 
  52     if (g_blockEventsOnDrag
) return; 
  54     wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, button
->GetId()); 
  55     event
.SetEventObject(button
); 
  56     button
->GetEventHandler()->ProcessEvent(event
); 
  59 //----------------------------------------------------------------------------- 
  61 //----------------------------------------------------------------------------- 
  63 static void gtk_bmpbutton_enter_callback( GtkWidget 
*WXUNUSED(widget
), wxBitmapButton 
*button 
) 
  65     if (!button
->m_hasVMT
) return; 
  66     if (g_blockEventsOnDrag
) return; 
  71 //----------------------------------------------------------------------------- 
  73 //----------------------------------------------------------------------------- 
  75 static void gtk_bmpbutton_leave_callback( GtkWidget 
*WXUNUSED(widget
), wxBitmapButton 
*button 
) 
  77     if (!button
->m_hasVMT
) return; 
  78     if (g_blockEventsOnDrag
) return; 
  83 //----------------------------------------------------------------------------- 
  85 //----------------------------------------------------------------------------- 
  87 static void gtk_bmpbutton_press_callback( GtkWidget 
*WXUNUSED(widget
), wxBitmapButton 
*button 
) 
  89     if (!button
->m_hasVMT
) return; 
  90     if (g_blockEventsOnDrag
) return; 
  92     button
->StartSelect(); 
  95 //----------------------------------------------------------------------------- 
  97 //----------------------------------------------------------------------------- 
  99 static void gtk_bmpbutton_release_callback( GtkWidget 
*WXUNUSED(widget
), wxBitmapButton 
*button 
) 
 101     if (!button
->m_hasVMT
) return; 
 102     if (g_blockEventsOnDrag
) return; 
 107 //----------------------------------------------------------------------------- 
 109 //----------------------------------------------------------------------------- 
 111 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
,wxButton
) 
 113 wxBitmapButton::wxBitmapButton() 
 117 bool wxBitmapButton::Create( wxWindow 
*parent
, wxWindowID id
, const wxBitmap 
&bitmap
, 
 118                              const wxPoint 
&pos
, const wxSize 
&size
, 
 119                              long style
, const wxValidator
& validator
, const wxString 
&name 
) 
 122     m_acceptsFocus 
= TRUE
; 
 124     if (!PreCreation( parent
, pos
, size 
) || 
 125         !CreateBase( parent
, id
, pos
, size
, style
, validator
, name 
)) 
 127         wxFAIL_MSG( wxT("wxBitmapButton creation failed") ); 
 134     m_bmpSelected 
= bitmap
; 
 136     m_widget 
= gtk_button_new(); 
 138 #if (GTK_MINOR_VERSION > 0) 
 139     if (style 
& wxNO_BORDER
) 
 140        gtk_button_set_relief( GTK_BUTTON(m_widget
), GTK_RELIEF_NONE 
); 
 143     if (m_bmpNormal
.Ok()) 
 145         wxSize newSize 
= size
; 
 146         int border 
= (style 
& wxNO_BORDER
) ? 4 : 10; 
 148             newSize
.x 
= m_bmpNormal
.GetWidth()+border
; 
 150             newSize
.y 
= m_bmpNormal
.GetHeight()+border
; 
 151         SetSize( newSize
.x
, newSize
.y 
); 
 155     gtk_signal_connect( GTK_OBJECT(m_widget
), "clicked", 
 156       GTK_SIGNAL_FUNC(gtk_bmpbutton_clicked_callback
), (gpointer
*)this ); 
 158     gtk_signal_connect( GTK_OBJECT(m_widget
), "enter", 
 159       GTK_SIGNAL_FUNC(gtk_bmpbutton_enter_callback
), (gpointer
*)this ); 
 160     gtk_signal_connect( GTK_OBJECT(m_widget
), "leave", 
 161       GTK_SIGNAL_FUNC(gtk_bmpbutton_leave_callback
), (gpointer
*)this ); 
 162     gtk_signal_connect( GTK_OBJECT(m_widget
), "pressed", 
 163       GTK_SIGNAL_FUNC(gtk_bmpbutton_press_callback
), (gpointer
*)this ); 
 164     gtk_signal_connect( GTK_OBJECT(m_widget
), "released", 
 165       GTK_SIGNAL_FUNC(gtk_bmpbutton_release_callback
), (gpointer
*)this ); 
 167     m_parent
->DoAddChild( this ); 
 171     SetBackgroundColour( parent
->GetBackgroundColour() ); 
 178 void wxBitmapButton::SetDefault() 
 180     GTK_WIDGET_SET_FLAGS( m_widget
, GTK_CAN_DEFAULT 
); 
 181     gtk_widget_grab_default( m_widget 
); 
 183     SetSize( m_x
, m_y
, m_width
, m_height 
); 
 186 void wxBitmapButton::SetLabel( const wxString 
&label 
) 
 188     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid button") ); 
 190     wxControl::SetLabel( label 
); 
 193 wxString 
wxBitmapButton::GetLabel() const 
 195     wxCHECK_MSG( m_widget 
!= NULL
, wxT(""), wxT("invalid button") ); 
 197     return wxControl::GetLabel(); 
 200 void wxBitmapButton::ApplyWidgetStyle() 
 202     if (GTK_BUTTON(m_widget
)->child 
== NULL
) return; 
 204     wxButton::ApplyWidgetStyle(); 
 207 void wxBitmapButton::OnSetBitmap() 
 209     wxCHECK_RET( m_widget 
!= NULL
, wxT("invalid bitmap button") ); 
 213         the_one 
= m_bmpDisabled
; 
 214     else if (m_isSelected
) 
 215         the_one 
= m_bmpSelected
; 
 217         the_one 
= m_bmpFocus
; 
 222             the_one 
= m_bmpSelected
; 
 227                 the_one 
= m_bmpFocus
; 
 229                 the_one 
= m_bmpNormal
; 
 233     if (!the_one
.Ok()) the_one 
= m_bmpNormal
; 
 234     if (!the_one
.Ok()) return; 
 236     GdkBitmap 
*mask 
= (GdkBitmap 
*) NULL
; 
 237     if (the_one
.GetMask()) mask 
= the_one
.GetMask()->GetBitmap(); 
 239     GtkButton 
*bin 
= GTK_BUTTON(m_widget
); 
 240     if (bin
->child 
== NULL
) 
 243         GtkWidget 
*pixmap 
= gtk_pixmap_new(the_one
.GetPixmap(), mask
); 
 244         gtk_widget_show(pixmap
); 
 245         gtk_container_add(GTK_CONTAINER(m_widget
), pixmap
); 
 248     {   // subsequent bitmaps 
 249         GtkPixmap 
*g_pixmap 
= GTK_PIXMAP(bin
->child
); 
 250         gtk_pixmap_set(g_pixmap
, the_one
.GetPixmap(), mask
); 
 254 bool wxBitmapButton::Enable( bool enable 
) 
 256     if ( !wxWindow::Enable(enable
) ) 
 264 void wxBitmapButton::HasFocus() 
 270 void wxBitmapButton::NotFocus() 
 276 void wxBitmapButton::StartSelect() 
 282 void wxBitmapButton::EndSelect() 
 284     m_isSelected 
= FALSE
; 
 288 #endif // wxUSE_BMPBUTTON