]> git.saurik.com Git - wxWidgets.git/blob - src/common/colourdata.cpp
fix some more improper widget casts
[wxWidgets.git] / src / common / colourdata.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/colourdata.cpp
3 // Author: Julian Smart
4 // RCS-ID: $Id$
5 // Copyright: (c) Julian Smart
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 #include "wx/wxprec.h"
10
11 #ifdef __BORLANDC__
12 #pragma hdrstop
13 #endif
14
15 #if wxUSE_COLOURDLG || wxUSE_COLOURPICKERCTRL
16
17 #include "wx/colourdata.h"
18 #include "wx/tokenzr.h"
19
20 // ----------------------------------------------------------------------------
21 // wxColourData
22 // ----------------------------------------------------------------------------
23
24 IMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject)
25
26 wxColourData::wxColourData()
27 {
28 m_chooseFull = false;
29 m_dataColour.Set(0,0,0);
30 // m_custColours are wxNullColours initially
31 }
32
33 wxColourData::wxColourData(const wxColourData& data)
34 : wxObject()
35 {
36 (*this) = data;
37 }
38
39 wxColourData::~wxColourData()
40 {
41 }
42
43 void wxColourData::SetCustomColour(int i, const wxColour& colour)
44 {
45 wxCHECK_RET( i >= 0 && i < NUM_CUSTOM, wxT("custom colour index out of range") );
46
47 m_custColours[i] = colour;
48 }
49
50 wxColour wxColourData::GetCustomColour(int i) const
51 {
52 wxCHECK_MSG( i >= 0 && i < NUM_CUSTOM, wxColour(0,0,0),
53 wxT("custom colour index out of range") );
54
55 return m_custColours[i];
56 }
57
58 wxColourData& wxColourData::operator=(const wxColourData& data)
59 {
60 for ( int i = 0; i < NUM_CUSTOM; i++)
61 m_custColours[i] = data.m_custColours[i];
62
63 m_dataColour = data.m_dataColour;
64 m_chooseFull = data.m_chooseFull;
65
66 return *this;
67 }
68
69 // ----------------------------------------------------------------------------
70 // [de]serialization
71 // ----------------------------------------------------------------------------
72
73 // separator used between different fields
74 static const char wxCOL_DATA_SEP = ',';
75
76 wxString wxColourData::ToString() const
77 {
78 wxString str(m_chooseFull ? '1' : '0');
79
80 for ( int i = 0; i < NUM_CUSTOM; i++ )
81 {
82 str += wxCOL_DATA_SEP;
83
84 const wxColour& clr = m_custColours[i];
85 if ( clr.IsOk() )
86 str += clr.GetAsString(wxC2S_HTML_SYNTAX);
87 }
88
89 return str;
90 }
91
92 bool wxColourData::FromString(const wxString& str)
93 {
94 wxStringTokenizer tokenizer(str, wxCOL_DATA_SEP);
95 wxString token = tokenizer.GetNextToken();
96 m_chooseFull = token == '1';
97 bool success = m_chooseFull || token == '0';
98 for (int i = 0; success && i < NUM_CUSTOM; i++)
99 {
100 token = tokenizer.GetNextToken();
101 if (token.empty())
102 m_custColours[i] = wxColour();
103 else
104 success = m_custColours[i].Set(token);
105 }
106 return success;
107 }
108 #endif // wxUSE_COLOURDLG || wxUSE_COLOURPICKERCTRL