]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colour.cpp
cleanup - reformat - 4th pass
[wxWidgets.git] / src / msw / colour.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
edc536d3 2// Name: src/msw/colour.cpp
2bda0e17
KB
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
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
2bda0e17
KB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#include "wx/gdicmn.h"
8cb172b4 20#include "wx/msw/private.h"
2bda0e17
KB
21
22#include <string.h>
2bda0e17 23
066f1b7a 24#if wxUSE_EXTENDED_RTTI
067e9be6 25
067e9be6
SC
26template<> void wxStringReadValue(const wxString &s , wxColour &data )
27{
aad6765c
JS
28 // copied from VS xrc
29 unsigned long tmp = 0;
067e9be6 30
aad6765c
JS
31 if (s.Length() != 7 || s[0u] != wxT('#')
32 || wxSscanf(s.c_str(), wxT("#%lX"), &tmp) != 1)
067e9be6 33 {
aad6765c
JS
34 wxLogError(_("String To Colour : Incorrect colour specification : %s"),
35 s.c_str() );
067e9be6
SC
36 data = wxNullColour;
37 }
aad6765c
JS
38 else
39 {
40 data = wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) ,
41 (unsigned char) ((tmp & 0x00FF00) >> 8),
42 (unsigned char) ((tmp & 0x0000FF)));
43 }
067e9be6
SC
44}
45
46template<> void wxStringWriteValue(wxString &s , const wxColour &data )
47{
aad6765c
JS
48 s = wxString::Format(wxT("#%02X%02X%02X"),
49 data.Red(), data.Green(), data.Blue() );
067e9be6
SC
50}
51
af498247
VZ
52wxTO_STRING_IMP( wxColour )
53wxFROM_STRING_IMP( wxColour )
02b7b6b0 54
af498247 55IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( wxColour , wxObject , "wx/colour.h" , &wxTO_STRING( wxColour ) , &wxFROM_STRING( wxColour ))
066f1b7a 56
3ff066a4 57wxBEGIN_PROPERTIES_TABLE(wxColour)
af498247
VZ
58 wxREADONLY_PROPERTY( Red, unsigned char, Red, EMPTY_MACROVALUE , 0 /*flags*/, wxT("Helpstring"), wxT("group"))
59 wxREADONLY_PROPERTY( Green, unsigned char, Green, EMPTY_MACROVALUE , 0 /*flags*/, wxT("Helpstring"), wxT("group"))
60 wxREADONLY_PROPERTY( Blue, unsigned char, Blue, EMPTY_MACROVALUE , 0 /*flags*/, wxT("Helpstring"), wxT("group"))
3ff066a4 61wxEND_PROPERTIES_TABLE()
066f1b7a 62
aad6765c 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{
aad6765c 75 m_isInit = false;
f75aecd0
VZ
76 m_pixel = 0;
77 m_red =
78 m_blue =
79 m_green = 0;
2bda0e17
KB
80}
81
aad6765c 82wxColour::wxColour(const wxColour& col)
04a18b0d 83 :wxObject()
2bda0e17 84{
f75aecd0 85 *this = col;
2bda0e17
KB
86}
87
f75aecd0 88wxColour& wxColour::operator=(const wxColour& col)
2bda0e17 89{
f75aecd0
VZ
90 m_red = col.m_red;
91 m_green = col.m_green;
92 m_blue = col.m_blue;
93 m_isInit = col.m_isInit;
94 m_pixel = col.m_pixel;
95 return *this;
2bda0e17
KB
96}
97
f75aecd0 98void wxColour::InitFromName(const wxString& name)
2bda0e17 99{
f75aecd0 100 if ( wxTheColourDatabase )
2bda0e17 101 {
f75aecd0
VZ
102 wxColour col = wxTheColourDatabase->Find(name);
103 if ( col.Ok() )
104 {
105 *this = col;
106 return;
107 }
2bda0e17 108 }
f75aecd0
VZ
109
110 // leave invalid
111 Init();
2bda0e17
KB
112}
113
68dda785 114wxColour::~wxColour()
2bda0e17
KB
115{
116}
117
aad6765c 118void wxColour::Set(unsigned char r, unsigned char g, unsigned char b)
2bda0e17 119{
f75aecd0
VZ
120 m_red = r;
121 m_green = g;
122 m_blue = b;
aad6765c
JS
123 m_isInit = true;
124 m_pixel = PALETTERGB(m_red, m_green, m_blue);
2bda0e17 125}