added wx{Colour|File|Dir|Font}PickerCtrl (patch 1472329 by Francesco)
[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 #include "wx/gtk/private.h"
21 #include "wx/clrpicker.h"
22
23 #include <gdk/gdk.h>
24 #include <gtk/gtk.h>
25
26
27
28 // ============================================================================
29 // implementation
30 // ============================================================================
31
32 #if wxUSE_COLOURPICKERCTRL && defined(__WXGTK24__)
33
34 //-----------------------------------------------------------------------------
35 // "color-set"
36 //-----------------------------------------------------------------------------
37
38 extern "C" {
39 static void gtk_clrbutton_setcolor_callback(GtkColorButton *widget,
40 wxColourButton *p)
41 {
42 // update the m_colour member of the wxColourButton
43 wxASSERT(p);
44 gtk_color_button_get_color(widget, p->GetGdkColor());
45
46 // fire the colour-changed event
47 wxColourPickerEvent event(p, p->GetId(), p->GetColour());
48 p->GetEventHandler()->ProcessEvent(event);
49 }
50 }
51
52 //-----------------------------------------------------------------------------
53 // wxColourButton
54 //-----------------------------------------------------------------------------
55
56 IMPLEMENT_DYNAMIC_CLASS(wxColourButton, wxGenericColourButton)
57
58 bool wxColourButton::Create( wxWindow *parent, wxWindowID id,
59 const wxColour &col,
60 const wxPoint &pos, const wxSize &size,
61 long style, const wxValidator& validator,
62 const wxString &name )
63 {
64 if (!gtk_check_version(2,4,0))
65 {
66 m_needParent = true;
67
68 if (!PreCreation( parent, pos, size ) ||
69 !wxControl::CreateBase(parent, id, pos, size, style, validator, name))
70 {
71 wxFAIL_MSG( wxT("wxColourButton creation failed") );
72 return false;
73 }
74
75 m_colour = col;
76 m_widget = gtk_color_button_new_with_color( m_colour.GetColor() );
77 gtk_widget_show( GTK_WIDGET(m_widget) );
78
79 // GtkColourButton signals
80 g_signal_connect(m_widget, "color-set",
81 G_CALLBACK(gtk_clrbutton_setcolor_callback), this);
82
83
84 m_parent->DoAddChild( this );
85
86 PostCreation(size);
87 SetBestSize(size);
88 }
89 else
90 return wxGenericColourButton::Create(parent, id, col, pos, size,
91 style, validator, name);
92 return true;
93 }
94
95 wxColourButton::~wxColourButton()
96 {
97 }
98
99 void wxColourButton::UpdateColour()
100 {
101 if (!gtk_check_version(2,4,0))
102 gtk_color_button_set_color(GTK_COLOR_BUTTON(m_widget), m_colour.GetColor());
103 else
104 wxGenericColourButton::UpdateColour();
105 }
106
107 #endif // wxUSE_COLOURPICKERCTRL && defined(__WXGTK24__)