]>
git.saurik.com Git - wxWidgets.git/blob - src/common/colourdata.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/colourdata.cpp
3 // Author: Julian Smart
5 // Copyright: (c) Julian Smart
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_COLOURDLG || wxUSE_COLOURPICKERCTRL
17 #include "wx/colourdata.h"
18 #include "wx/tokenzr.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 IMPLEMENT_DYNAMIC_CLASS(wxColourData
, wxObject
)
26 wxColourData::wxColourData()
29 m_dataColour
.Set(0,0,0);
30 // m_custColours are wxNullColours initially
33 wxColourData::wxColourData(const wxColourData
& data
)
39 wxColourData::~wxColourData()
43 void wxColourData::SetCustomColour(int i
, const wxColour
& colour
)
45 wxCHECK_RET( i
>= 0 && i
< NUM_CUSTOM
, wxT("custom colour index out of range") );
47 m_custColours
[i
] = colour
;
50 wxColour
wxColourData::GetCustomColour(int i
) const
52 wxCHECK_MSG( i
>= 0 && i
< NUM_CUSTOM
, wxColour(0,0,0),
53 wxT("custom colour index out of range") );
55 return m_custColours
[i
];
58 wxColourData
& wxColourData::operator=(const wxColourData
& data
)
60 for ( int i
= 0; i
< NUM_CUSTOM
; i
++)
61 m_custColours
[i
] = data
.m_custColours
[i
];
63 m_dataColour
= data
.m_dataColour
;
64 m_chooseFull
= data
.m_chooseFull
;
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 // separator used between different fields
74 static const char wxCOL_DATA_SEP
= ',';
76 wxString
wxColourData::ToString() const
78 wxString
str(m_chooseFull
? '1' : '0');
80 for ( int i
= 0; i
< NUM_CUSTOM
; i
++ )
82 str
+= wxCOL_DATA_SEP
;
84 const wxColour
& clr
= m_custColours
[i
];
86 str
+= clr
.GetAsString(wxC2S_HTML_SYNTAX
);
92 bool wxColourData::FromString(const wxString
& str
)
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
++)
100 token
= tokenizer
.GetNextToken();
102 m_custColours
[i
] = wxColour();
104 success
= m_custColours
[i
].Set(token
);
108 #endif // wxUSE_COLOURDLG || wxUSE_COLOURPICKERCTRL