]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colour.cpp
Applied [ 827604 ] missing method for wxCalendarEvent
[wxWidgets.git] / src / msw / colour.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: colour.cpp
3// Purpose: wxColour class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
2bda0e17
KB
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
2bda0e17
KB
13#pragma implementation "colour.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#include "wx/gdicmn.h"
8cb172b4 24#include "wx/msw/private.h"
2bda0e17
KB
25
26#include <string.h>
2bda0e17 27
066f1b7a 28#if wxUSE_EXTENDED_RTTI
067e9be6 29
067e9be6
SC
30template<> void wxStringReadValue(const wxString &s , wxColour &data )
31{
32 // copied from VS xrc
33 unsigned long tmp = 0;
34
35 if (s.Length() != 7 || s[0u] != wxT('#') ||
36 wxSscanf(s.c_str(), wxT("#%lX"), &tmp) != 1)
37 {
38 wxLogError(_("String To Colour : Incorrect colour specification : %s"),
39 s.c_str() );
40 data = wxNullColour;
41 }
42 else
43 {
44 data = wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) ,
45 (unsigned char) ((tmp & 0x00FF00) >> 8),
46 (unsigned char) ((tmp & 0x0000FF)));
47 }
48}
49
50template<> void wxStringWriteValue(wxString &s , const wxColour &data )
51{
c34e3c79 52 s = wxString::Format(wxT("#%02X%02X%02X"), data.Red() , data.Green() , data.Blue() ) ;
067e9be6
SC
53}
54
e70b4f10 55IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( wxColour , wxObject , "wx/colour.h" , &wxToStringConverter<wxColour> , &wxFromStringConverter<wxColour>)
066f1b7a 56
3ff066a4
SC
57wxBEGIN_PROPERTIES_TABLE(wxColour)
58 wxREADONLY_PROPERTY( Red, unsigned char , Red , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
59 wxREADONLY_PROPERTY( Green, unsigned char , Green , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
60 wxREADONLY_PROPERTY( Blue, unsigned char , Blue , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
61wxEND_PROPERTIES_TABLE()
066f1b7a 62
3ff066a4 63wxCONSTRUCTOR_3( wxColour , unsigned char , Red , unsigned char , Green , unsigned char , Blue )
066f1b7a 64
3ff066a4
SC
65wxBEGIN_HANDLERS_TABLE(wxColour)
66wxEND_HANDLERS_TABLE()
066f1b7a 67#else
2bda0e17 68IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
066f1b7a 69#endif
2bda0e17
KB
70
71// Colour
72
f75aecd0 73void wxColour::Init()
2bda0e17 74{
f75aecd0
VZ
75 m_isInit = FALSE;
76 m_pixel = 0;
77 m_red =
78 m_blue =
79 m_green = 0;
2bda0e17
KB
80}
81
82wxColour::wxColour (const wxColour& col)
83{
f75aecd0 84 *this = col;
2bda0e17
KB
85}
86
f75aecd0 87wxColour& wxColour::operator=(const wxColour& col)
2bda0e17 88{
f75aecd0
VZ
89 m_red = col.m_red;
90 m_green = col.m_green;
91 m_blue = col.m_blue;
92 m_isInit = col.m_isInit;
93 m_pixel = col.m_pixel;
94 return *this;
2bda0e17
KB
95}
96
f75aecd0 97void wxColour::InitFromName(const wxString& name)
2bda0e17 98{
f75aecd0 99 if ( wxTheColourDatabase )
2bda0e17 100 {
f75aecd0
VZ
101 wxColour col = wxTheColourDatabase->Find(name);
102 if ( col.Ok() )
103 {
104 *this = col;
105 return;
106 }
2bda0e17 107 }
f75aecd0
VZ
108
109 // leave invalid
110 Init();
2bda0e17
KB
111}
112
68dda785 113wxColour::~wxColour()
2bda0e17
KB
114{
115}
116
2bda0e17
KB
117void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
118{
f75aecd0
VZ
119 m_red = r;
120 m_green = g;
121 m_blue = b;
122 m_isInit = TRUE;
123 m_pixel = PALETTERGB (m_red, m_green, m_blue);
2bda0e17 124}
f75aecd0 125