]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/clrpicker.cpp
native scaling support for bitmap
[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
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 #ifdef __WXGTK3__
41 GdkRGBA gdkColor;
42 gtk_color_button_get_rgba(widget, &gdkColor);
43 #else
44 GdkColor gdkColor;
45 gtk_color_button_get_color(widget, &gdkColor);
46 #endif
47 p->GTKSetColour(gdkColor);
48
49 // fire the colour-changed event
50 wxColourPickerEvent event(p, p->GetId(), p->GetColour());
51 p->HandleWindowEvent(event);
52 }
53 }
54
55 //-----------------------------------------------------------------------------
56 // wxColourButton
57 //-----------------------------------------------------------------------------
58
59 IMPLEMENT_DYNAMIC_CLASS(wxColourButton, wxButton)
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 {
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 #ifdef __WXGTK3__
76 m_widget = gtk_color_button_new_with_rgba(m_colour);
77 #else
78 m_widget = gtk_color_button_new_with_color( m_colour.GetColor() );
79 #endif
80 g_object_ref(m_widget);
81
82 // GtkColourButton signals
83 g_signal_connect(m_widget, "color-set",
84 G_CALLBACK(gtk_clrbutton_setcolor_callback), this);
85
86
87 m_parent->DoAddChild( this );
88
89 PostCreation(size);
90 SetInitialSize(size);
91
92 return true;
93 }
94
95 wxColourButton::~wxColourButton()
96 {
97 }
98
99 void wxColourButton::UpdateColour()
100 {
101 #ifdef __WXGTK3__
102 gtk_color_button_set_rgba(GTK_COLOR_BUTTON(m_widget), m_colour);
103 #else
104 gtk_color_button_set_color(GTK_COLOR_BUTTON(m_widget), m_colour.GetColor());
105 #endif
106 }
107
108 #endif // wxUSE_COLOURPICKERCTRL