]> git.saurik.com Git - wxWidgets.git/blob - src/common/clrpickercmn.cpp
Add more checks for Intel compiler.
[wxWidgets.git] / src / common / clrpickercmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/clrpickercmn.cpp
3 // Purpose: wxColourPickerCtrl class implementation
4 // Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
5 // Modified by:
6 // Created: 15/04/2006
7 // Copyright: (c) Vadim Zeitlin, Francesco Montorsi
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_COLOURPICKERCTRL
27
28 #include "wx/clrpicker.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/textctrl.h"
32 #endif
33
34 const char wxColourPickerCtrlNameStr[] = "colourpicker";
35 const char wxColourPickerWidgetNameStr[] = "colourpickerwidget";
36
37 // ============================================================================
38 // implementation
39 // ============================================================================
40
41 wxDEFINE_EVENT(wxEVT_COLOURPICKER_CHANGED, wxColourPickerEvent);
42 IMPLEMENT_DYNAMIC_CLASS(wxColourPickerCtrl, wxPickerBase)
43 IMPLEMENT_DYNAMIC_CLASS(wxColourPickerEvent, wxEvent)
44
45 // ----------------------------------------------------------------------------
46 // wxColourPickerCtrl
47 // ----------------------------------------------------------------------------
48
49 #define M_PICKER ((wxColourPickerWidget*)m_picker)
50
51 bool wxColourPickerCtrl::Create( wxWindow *parent, wxWindowID id,
52 const wxColour &col,
53 const wxPoint &pos, const wxSize &size,
54 long style, const wxValidator& validator,
55 const wxString &name )
56 {
57 if (!wxPickerBase::CreateBase(parent, id, col.GetAsString(), pos, size,
58 style, validator, name))
59 return false;
60
61 // we are not interested to the ID of our picker as we connect
62 // to its "changed" event dynamically...
63 m_picker = new wxColourPickerWidget(this, wxID_ANY, col,
64 wxDefaultPosition, wxDefaultSize,
65 GetPickerStyle(style));
66
67 // complete sizer creation
68 wxPickerBase::PostCreation();
69
70 m_picker->Connect(wxEVT_COLOURPICKER_CHANGED,
71 wxColourPickerEventHandler(wxColourPickerCtrl::OnColourChange),
72 NULL, this);
73
74 return true;
75 }
76
77 void wxColourPickerCtrl::SetColour(const wxColour &col)
78 {
79 M_PICKER->SetColour(col);
80 UpdateTextCtrlFromPicker();
81 }
82
83 bool wxColourPickerCtrl::SetColour(const wxString &text)
84 {
85 wxColour col(text); // smart wxString->wxColour conversion
86 if ( !col.IsOk() )
87 return false;
88 M_PICKER->SetColour(col);
89 UpdateTextCtrlFromPicker();
90
91 return true;
92 }
93
94 void wxColourPickerCtrl::UpdatePickerFromTextCtrl()
95 {
96 wxASSERT(m_text);
97
98 // wxString -> wxColour conversion
99 wxColour col(m_text->GetValue());
100 if ( !col.IsOk() )
101 return; // invalid user input
102
103 if (M_PICKER->GetColour() != col)
104 {
105 M_PICKER->SetColour(col);
106
107 // fire an event
108 wxColourPickerEvent event(this, GetId(), col);
109 GetEventHandler()->ProcessEvent(event);
110 }
111 }
112
113 void wxColourPickerCtrl::UpdateTextCtrlFromPicker()
114 {
115 if (!m_text)
116 return; // no textctrl to update
117
118 // Take care to use ChangeValue() here and not SetValue() to avoid
119 // infinite recursion.
120 m_text->ChangeValue(M_PICKER->GetColour().GetAsString());
121 }
122
123
124
125 // ----------------------------------------------------------------------------
126 // wxColourPickerCtrl - event handlers
127 // ----------------------------------------------------------------------------
128
129 void wxColourPickerCtrl::OnColourChange(wxColourPickerEvent &ev)
130 {
131 UpdateTextCtrlFromPicker();
132
133 // the wxColourPickerWidget sent us a colour-change notification.
134 // forward this event to our parent
135 wxColourPickerEvent event(this, GetId(), ev.GetColour());
136 GetEventHandler()->ProcessEvent(event);
137 }
138
139 #endif // wxUSE_COLOURPICKERCTRL