]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colour.cpp
Applied socket destruction bug patch
[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
65571936 9// Licence: wxWindows licence
2bda0e17
KB
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{
aad6765c
JS
32 // copied from VS xrc
33 unsigned long tmp = 0;
067e9be6 34
aad6765c
JS
35 if (s.Length() != 7 || s[0u] != wxT('#')
36 || wxSscanf(s.c_str(), wxT("#%lX"), &tmp) != 1)
067e9be6 37 {
aad6765c
JS
38 wxLogError(_("String To Colour : Incorrect colour specification : %s"),
39 s.c_str() );
067e9be6
SC
40 data = wxNullColour;
41 }
aad6765c
JS
42 else
43 {
44 data = wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) ,
45 (unsigned char) ((tmp & 0x00FF00) >> 8),
46 (unsigned char) ((tmp & 0x0000FF)));
47 }
067e9be6
SC
48}
49
50template<> void wxStringWriteValue(wxString &s , const wxColour &data )
51{
aad6765c
JS
52 s = wxString::Format(wxT("#%02X%02X%02X"),
53 data.Red(), data.Green(), data.Blue() );
067e9be6
SC
54}
55
af498247
VZ
56wxTO_STRING_IMP( wxColour )
57wxFROM_STRING_IMP( wxColour )
02b7b6b0 58
af498247 59IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( wxColour , wxObject , "wx/colour.h" , &wxTO_STRING( wxColour ) , &wxFROM_STRING( wxColour ))
066f1b7a 60
3ff066a4 61wxBEGIN_PROPERTIES_TABLE(wxColour)
af498247
VZ
62 wxREADONLY_PROPERTY( Red, unsigned char, Red, EMPTY_MACROVALUE , 0 /*flags*/, wxT("Helpstring"), wxT("group"))
63 wxREADONLY_PROPERTY( Green, unsigned char, Green, EMPTY_MACROVALUE , 0 /*flags*/, wxT("Helpstring"), wxT("group"))
64 wxREADONLY_PROPERTY( Blue, unsigned char, Blue, EMPTY_MACROVALUE , 0 /*flags*/, wxT("Helpstring"), wxT("group"))
3ff066a4 65wxEND_PROPERTIES_TABLE()
066f1b7a 66
aad6765c 67wxCONSTRUCTOR_3( wxColour, unsigned char, Red, unsigned char, Green, unsigned char, Blue )
066f1b7a 68
3ff066a4
SC
69wxBEGIN_HANDLERS_TABLE(wxColour)
70wxEND_HANDLERS_TABLE()
066f1b7a 71#else
2bda0e17 72IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
066f1b7a 73#endif
2bda0e17
KB
74
75// Colour
76
f75aecd0 77void wxColour::Init()
2bda0e17 78{
aad6765c 79 m_isInit = false;
f75aecd0
VZ
80 m_pixel = 0;
81 m_red =
82 m_blue =
83 m_green = 0;
2bda0e17
KB
84}
85
aad6765c 86wxColour::wxColour(const wxColour& col)
04a18b0d 87 :wxObject()
2bda0e17 88{
f75aecd0 89 *this = col;
2bda0e17
KB
90}
91
f75aecd0 92wxColour& wxColour::operator=(const wxColour& col)
2bda0e17 93{
f75aecd0
VZ
94 m_red = col.m_red;
95 m_green = col.m_green;
96 m_blue = col.m_blue;
97 m_isInit = col.m_isInit;
98 m_pixel = col.m_pixel;
99 return *this;
2bda0e17
KB
100}
101
f75aecd0 102void wxColour::InitFromName(const wxString& name)
2bda0e17 103{
f75aecd0 104 if ( wxTheColourDatabase )
2bda0e17 105 {
f75aecd0
VZ
106 wxColour col = wxTheColourDatabase->Find(name);
107 if ( col.Ok() )
108 {
109 *this = col;
110 return;
111 }
2bda0e17 112 }
f75aecd0
VZ
113
114 // leave invalid
115 Init();
2bda0e17
KB
116}
117
68dda785 118wxColour::~wxColour()
2bda0e17
KB
119{
120}
121
aad6765c 122void wxColour::Set(unsigned char r, unsigned char g, unsigned char b)
2bda0e17 123{
f75aecd0
VZ
124 m_red = r;
125 m_green = g;
126 m_blue = b;
aad6765c
JS
127 m_isInit = true;
128 m_pixel = PALETTERGB(m_red, m_green, m_blue);
2bda0e17 129}
f75aecd0 130