]>
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 | ||
ff654490 | 20 | #if wxUSE_COLOURPICKERCTRL |
4ce7b1e4 | 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); | |
9dc44eff PC |
40 | #ifdef __WXGTK3__ |
41 | GdkRGBA gdkColor; | |
42 | gtk_color_button_get_rgba(widget, &gdkColor); | |
43 | #else | |
c6685317 PC |
44 | GdkColor gdkColor; |
45 | gtk_color_button_get_color(widget, &gdkColor); | |
9dc44eff PC |
46 | #endif |
47 | p->GTKSetColour(gdkColor); | |
ec376c8f VZ |
48 | |
49 | // fire the colour-changed event | |
50 | wxColourPickerEvent event(p, p->GetId(), p->GetColour()); | |
937013e0 | 51 | p->HandleWindowEvent(event); |
ec376c8f VZ |
52 | } |
53 | } | |
54 | ||
55 | //----------------------------------------------------------------------------- | |
56 | // wxColourButton | |
57 | //----------------------------------------------------------------------------- | |
58 | ||
ff654490 | 59 | IMPLEMENT_DYNAMIC_CLASS(wxColourButton, wxButton) |
ec376c8f VZ |
60 | |
61 | bool wxColourButton::Create( wxWindow *parent, wxWindowID id, | |
62 | const wxColour &col, | |
63 | const wxPoint &pos, const wxSize &size, | |
64 | long style, const wxValidator& validator, | |
65 | const wxString &name ) | |
66 | { | |
ff654490 VZ |
67 | if (!PreCreation( parent, pos, size ) || |
68 | !wxControl::CreateBase(parent, id, pos, size, style, validator, name)) | |
ec376c8f | 69 | { |
ff654490 VZ |
70 | wxFAIL_MSG( wxT("wxColourButton creation failed") ); |
71 | return false; | |
72 | } | |
ec376c8f | 73 | |
ff654490 | 74 | m_colour = col; |
9dc44eff PC |
75 | #ifdef __WXGTK3__ |
76 | m_widget = gtk_color_button_new_with_rgba(m_colour); | |
77 | #else | |
ff654490 | 78 | m_widget = gtk_color_button_new_with_color( m_colour.GetColor() ); |
9dc44eff | 79 | #endif |
9ff9d30c | 80 | g_object_ref(m_widget); |
ec376c8f | 81 | |
ff654490 VZ |
82 | // GtkColourButton signals |
83 | g_signal_connect(m_widget, "color-set", | |
84 | G_CALLBACK(gtk_clrbutton_setcolor_callback), this); | |
ec376c8f VZ |
85 | |
86 | ||
ff654490 VZ |
87 | m_parent->DoAddChild( this ); |
88 | ||
89 | PostCreation(size); | |
90 | SetInitialSize(size); | |
ec376c8f | 91 | |
ec376c8f VZ |
92 | return true; |
93 | } | |
94 | ||
95 | wxColourButton::~wxColourButton() | |
96 | { | |
97 | } | |
98 | ||
99 | void wxColourButton::UpdateColour() | |
100 | { | |
9dc44eff PC |
101 | #ifdef __WXGTK3__ |
102 | gtk_color_button_set_rgba(GTK_COLOR_BUTTON(m_widget), m_colour); | |
103 | #else | |
ff654490 | 104 | gtk_color_button_set_color(GTK_COLOR_BUTTON(m_widget), m_colour.GetColor()); |
9dc44eff | 105 | #endif |
ec376c8f VZ |
106 | } |
107 | ||
ff654490 | 108 | #endif // wxUSE_COLOURPICKERCTRL |