]> git.saurik.com Git - wxWidgets.git/blob - src/msw/colour.cpp
Send all menu item actions to a dedicated target. This is to ensure
[wxWidgets.git] / src / msw / colour.cpp
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$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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"
24 #include "wx/msw/private.h"
25
26 #include <string.h>
27
28 #if wxUSE_EXTENDED_RTTI
29
30 template<> 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
50 template<> void wxStringWriteValue(wxString &s , const wxColour &data )
51 {
52 s = wxString::Format(wxT("#%02X%02X%02X"), data.Red() , data.Green() , data.Blue() ) ;
53 }
54
55 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( wxColour , wxObject , "wx/colour.h" , &wxToStringConverter<wxColour> , &wxFromStringConverter<wxColour>)
56
57 WX_BEGIN_PROPERTIES_TABLE(wxColour)
58 WX_READONLY_PROPERTY( Red, unsigned char , Red , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
59 WX_READONLY_PROPERTY( Green, unsigned char , Green , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
60 WX_READONLY_PROPERTY( Blue, unsigned char , Blue , , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
61 WX_END_PROPERTIES_TABLE()
62
63 WX_CONSTRUCTOR_3( wxColour , unsigned char , Red , unsigned char , Green , unsigned char , Blue )
64
65 WX_BEGIN_HANDLERS_TABLE(wxColour)
66 WX_END_HANDLERS_TABLE()
67 #else
68 IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
69 #endif
70
71 // Colour
72
73 wxColour::wxColour ()
74 {
75 m_isInit = FALSE;
76 m_pixel = 0;
77 m_red = m_blue = m_green = 0;
78 }
79
80 wxColour::wxColour (unsigned char r, unsigned char g, unsigned char b)
81 {
82 m_red = r;
83 m_green = g;
84 m_blue = b;
85 m_isInit = TRUE;
86 m_pixel = PALETTERGB (m_red, m_green, m_blue);
87 }
88
89 wxColour::wxColour (const wxColour& col)
90 {
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 }
97
98 wxColour& wxColour::operator =(const wxColour& col)
99 {
100 m_red = col.m_red;
101 m_green = col.m_green;
102 m_blue = col.m_blue;
103 m_isInit = col.m_isInit;
104 m_pixel = col.m_pixel;
105 return *this;
106 }
107
108 void wxColour::InitFromName(const wxString& col)
109 {
110 wxColour *the_colour = wxTheColourDatabase->FindColour (col);
111 if (the_colour)
112 {
113 m_red = the_colour->Red ();
114 m_green = the_colour->Green ();
115 m_blue = the_colour->Blue ();
116 m_isInit = TRUE;
117 }
118 else
119 {
120 m_red = 0;
121 m_green = 0;
122 m_blue = 0;
123 m_isInit = FALSE;
124 }
125 m_pixel = PALETTERGB (m_red, m_green, m_blue);
126 }
127
128 wxColour::~wxColour()
129 {
130 }
131
132 void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
133 {
134 m_red = r;
135 m_green = g;
136 m_blue = b;
137 m_isInit = TRUE;
138 m_pixel = PALETTERGB (m_red, m_green, m_blue);
139 }