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