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