]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/clrpicker.cpp
Style listbox now shows current style
[wxWidgets.git] / src / gtk / clrpicker.cpp
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 // Id: $Id$
8 // Copyright: (c) Francesco Montorsi
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 // ----------------------------------------------------------------------------
14 // headers
15 // ----------------------------------------------------------------------------
16
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
19
20 #if wxUSE_COLOURPICKERCTRL && defined(__WXGTK24__)
21
22 #include "wx/clrpicker.h"
23
24 #include <gtk/gtk.h>
25
26 // ============================================================================
27 // implementation
28 // ============================================================================
29
30 //-----------------------------------------------------------------------------
31 // "color-set"
32 //-----------------------------------------------------------------------------
33
34 extern "C" {
35 static void gtk_clrbutton_setcolor_callback(GtkColorButton *widget,
36 wxColourButton *p)
37 {
38 // update the m_colour member of the wxColourButton
39 wxASSERT(p);
40 GdkColor gdkColor;
41 gtk_color_button_get_color(widget, &gdkColor);
42 p->SetGdkColor(gdkColor);
43
44 // fire the colour-changed event
45 wxColourPickerEvent event(p, p->GetId(), p->GetColour());
46 p->GetEventHandler()->ProcessEvent(event);
47 }
48 }
49
50 //-----------------------------------------------------------------------------
51 // wxColourButton
52 //-----------------------------------------------------------------------------
53
54 IMPLEMENT_DYNAMIC_CLASS(wxColourButton, wxGenericColourButton)
55
56 bool wxColourButton::Create( wxWindow *parent, wxWindowID id,
57 const wxColour &col,
58 const wxPoint &pos, const wxSize &size,
59 long style, const wxValidator& validator,
60 const wxString &name )
61 {
62 if (!gtk_check_version(2,4,0))
63 {
64 m_needParent = true;
65 m_acceptsFocus = true;
66
67 if (!PreCreation( parent, pos, size ) ||
68 !wxControl::CreateBase(parent, id, pos, size, style, validator, name))
69 {
70 wxFAIL_MSG( wxT("wxColourButton creation failed") );
71 return false;
72 }
73
74 m_colour = col;
75 m_widget = gtk_color_button_new_with_color( m_colour.GetColor() );
76 gtk_widget_show( GTK_WIDGET(m_widget) );
77
78 // GtkColourButton signals
79 g_signal_connect(m_widget, "color-set",
80 G_CALLBACK(gtk_clrbutton_setcolor_callback), this);
81
82
83 m_parent->DoAddChild( this );
84
85 PostCreation(size);
86 SetBestSize(size);
87 }
88 else
89 return wxGenericColourButton::Create(parent, id, col, pos, size,
90 style, validator, name);
91 return true;
92 }
93
94 wxColourButton::~wxColourButton()
95 {
96 }
97
98 void wxColourButton::UpdateColour()
99 {
100 if (!gtk_check_version(2,4,0))
101 gtk_color_button_set_color(GTK_COLOR_BUTTON(m_widget), m_colour.GetColor());
102 else
103 wxGenericColourButton::UpdateColour();
104 }
105
106 #endif // wxUSE_COLOURPICKERCTRL && defined(__WXGTK24__)