1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        src/gtk/clrpicker.cpp
3 // Purpose:     implementation of wxColourButton
4 // Author:      Francesco Montorsi
5 // Modified By:
6 // Created:     15/04/2006
7 // Copyright:   (c) Francesco Montorsi
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 
12 // ----------------------------------------------------------------------------
13 // headers
14 // ----------------------------------------------------------------------------
15 
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18 
19 #if wxUSE_COLOURPICKERCTRL
20 
21 #include "wx/clrpicker.h"
22 
23 #include <gtk/gtk.h>
24 
25 // ============================================================================
26 // implementation
27 // ============================================================================
28 
29 //-----------------------------------------------------------------------------
30 // "color-set"
31 //-----------------------------------------------------------------------------
32 
33 extern "C" {
gtk_clrbutton_setcolor_callback(GtkColorButton * widget,wxColourButton * p)34 static void gtk_clrbutton_setcolor_callback(GtkColorButton *widget,
35                                             wxColourButton *p)
36 {
37     // update the m_colour member of the wxColourButton
38     wxASSERT(p);
39 #ifdef __WXGTK3__
40     GdkRGBA gdkColor;
41     gtk_color_button_get_rgba(widget, &gdkColor);
42 #else
43     GdkColor gdkColor;
44     gtk_color_button_get_color(widget, &gdkColor);
45 #endif
46     p->GTKSetColour(gdkColor);
47 
48     // fire the colour-changed event
49     wxColourPickerEvent event(p, p->GetId(), p->GetColour());
50     p->HandleWindowEvent(event);
51 }
52 }
53 
54 //-----------------------------------------------------------------------------
55 // wxColourButton
56 //-----------------------------------------------------------------------------
57 
IMPLEMENT_DYNAMIC_CLASS(wxColourButton,wxButton)58 IMPLEMENT_DYNAMIC_CLASS(wxColourButton, wxButton)
59 
60 bool wxColourButton::Create( wxWindow *parent, wxWindowID id,
61                         const wxColour &col,
62                         const wxPoint &pos, const wxSize &size,
63                         long style, const wxValidator& validator,
64                         const wxString &name )
65 {
66     if (!PreCreation( parent, pos, size ) ||
67         !wxControl::CreateBase(parent, id, pos, size, style, validator, name))
68     {
69         wxFAIL_MSG( wxT("wxColourButton creation failed") );
70         return false;
71     }
72 
73     m_colour = col;
74 #ifdef __WXGTK3__
75     m_widget = gtk_color_button_new_with_rgba(m_colour);
76 #else
77     m_widget = gtk_color_button_new_with_color( m_colour.GetColor() );
78 #endif
79     g_object_ref(m_widget);
80 
81     // GtkColourButton signals
82     g_signal_connect(m_widget, "color-set",
83                     G_CALLBACK(gtk_clrbutton_setcolor_callback), this);
84 
85 
86     m_parent->DoAddChild( this );
87 
88     PostCreation(size);
89     SetInitialSize(size);
90 
91     return true;
92 }
93 
~wxColourButton()94 wxColourButton::~wxColourButton()
95 {
96 }
97 
UpdateColour()98 void wxColourButton::UpdateColour()
99 {
100 #ifdef __WXGTK3__
101     gtk_color_button_set_rgba(GTK_COLOR_BUTTON(m_widget), m_colour);
102 #else
103     gtk_color_button_set_color(GTK_COLOR_BUTTON(m_widget), m_colour.GetColor());
104 #endif
105 }
106 
107 #endif // wxUSE_COLOURPICKERCTRL
108