]>
Commit | Line | Data |
---|---|---|
ec376c8f VZ |
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 | ||
4ce7b1e4 WS |
20 | #if wxUSE_COLOURPICKERCTRL && defined(__WXGTK24__) |
21 | ||
ec376c8f VZ |
22 | #include "wx/clrpicker.h" |
23 | ||
4ce7b1e4 WS |
24 | #include "wx/gtk/private.h" |
25 | ||
ec376c8f VZ |
26 | #include <gdk/gdk.h> |
27 | #include <gtk/gtk.h> | |
28 | ||
ec376c8f VZ |
29 | // ============================================================================ |
30 | // implementation | |
31 | // ============================================================================ | |
32 | ||
ec376c8f VZ |
33 | //----------------------------------------------------------------------------- |
34 | // "color-set" | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
37 | extern "C" { | |
38 | static void gtk_clrbutton_setcolor_callback(GtkColorButton *widget, | |
39 | wxColourButton *p) | |
40 | { | |
41 | // update the m_colour member of the wxColourButton | |
42 | wxASSERT(p); | |
43 | gtk_color_button_get_color(widget, p->GetGdkColor()); | |
44 | ||
45 | // fire the colour-changed event | |
46 | wxColourPickerEvent event(p, p->GetId(), p->GetColour()); | |
47 | p->GetEventHandler()->ProcessEvent(event); | |
48 | } | |
49 | } | |
50 | ||
51 | //----------------------------------------------------------------------------- | |
52 | // wxColourButton | |
53 | //----------------------------------------------------------------------------- | |
54 | ||
55 | IMPLEMENT_DYNAMIC_CLASS(wxColourButton, wxGenericColourButton) | |
56 | ||
57 | bool wxColourButton::Create( wxWindow *parent, wxWindowID id, | |
58 | const wxColour &col, | |
59 | const wxPoint &pos, const wxSize &size, | |
60 | long style, const wxValidator& validator, | |
61 | const wxString &name ) | |
62 | { | |
63 | if (!gtk_check_version(2,4,0)) | |
64 | { | |
65 | m_needParent = 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__) |