/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/clrpickerg.cpp
ViewVC logotype

Annotation of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/generic/clrpickerg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (10 years ago) by william
File size: 5618 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 william 31 ///////////////////////////////////////////////////////////////////////////////
2     // Name: src/generic/clrpickerg.cpp
3     // Purpose: wxGenericColourButton class implementation
4     // Author: Francesco Montorsi (readapted code written by Vadim Zeitlin)
5     // Modified by:
6     // Created: 15/04/2006
7     // RCS-ID: $Id: clrpickerg.cpp 58967 2009-02-17 13:31:28Z SC $
8     // Copyright: (c) Vadim Zeitlin, Francesco Montorsi
9     // Licence: wxWindows licence
10     ///////////////////////////////////////////////////////////////////////////////
11    
12     // ============================================================================
13     // declarations
14     // ============================================================================
15    
16     // ----------------------------------------------------------------------------
17     // headers
18     // ----------------------------------------------------------------------------
19    
20     // For compilers that support precompilation, includes "wx.h".
21     #include "wx/wxprec.h"
22    
23     #ifdef __BORLANDC__
24     #pragma hdrstop
25     #endif
26    
27     #if wxUSE_COLOURPICKERCTRL
28    
29     #include "wx/clrpicker.h"
30    
31     #include "wx/colordlg.h"
32    
33    
34     // ============================================================================
35     // implementation
36     // ============================================================================
37    
38     wxColourData wxGenericColourButton::ms_data;
39     IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxCLRBTN_BASE_CLASS)
40    
41     // ----------------------------------------------------------------------------
42     // wxGenericColourButton
43     // ----------------------------------------------------------------------------
44    
45     bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id,
46     const wxColour &col, const wxPoint &pos,
47     const wxSize &size, long style,
48     const wxValidator& validator, const wxString &name)
49     {
50     // create this button
51     #if wxCLRBTN_USES_BMP_BUTTON
52     wxBitmap empty(1,1);
53     if (!wxBitmapButton::Create( parent, id, empty, pos,
54     size, style, validator, name ))
55     #else
56     if (!wxButton::Create( parent, id, wxEmptyString, pos,
57     size, style, validator, name ))
58     #endif
59     {
60     wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
61     return false;
62     }
63    
64     // and handle user clicks on it
65     Connect(GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
66     wxCommandEventHandler(wxGenericColourButton::OnButtonClick),
67     NULL, this);
68    
69     m_colour = col;
70     UpdateColour();
71     InitColourData();
72    
73     return true;
74     }
75    
76     void wxGenericColourButton::InitColourData()
77     {
78     ms_data.SetChooseFull(true);
79     unsigned char grey = 0;
80     for (int i = 0; i < 16; i++, grey += 16)
81     {
82     // fill with grey tones the custom colors palette
83     wxColour colour(grey, grey, grey);
84     ms_data.SetCustomColour(i, colour);
85     }
86     }
87    
88     void wxGenericColourButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
89     {
90     // update the wxColouData to be shown in the the dialog
91     ms_data.SetColour(m_colour);
92    
93     // create the colour dialog and display it
94     wxColourDialog dlg(this, &ms_data);
95     if (dlg.ShowModal() == wxID_OK)
96     {
97     ms_data = dlg.GetColourData();
98     SetColour(ms_data.GetColour());
99    
100     // fire an event
101     wxColourPickerEvent event(this, GetId(), m_colour);
102     GetEventHandler()->ProcessEvent(event);
103     }
104     }
105    
106     void wxGenericColourButton::UpdateColour()
107     {
108     if ( !m_colour.Ok() )
109     {
110     #if wxCLRBTN_USES_BMP_BUTTON
111     wxBitmap empty(1,1);
112     SetBitmapLabel(empty);
113     #else
114     if ( HasFlag(wxCLRP_SHOW_LABEL) )
115     SetLabel(wxEmptyString);
116     #endif
117     return;
118     }
119    
120     // some combinations of the fg/bg colours may be unreadable, so we invert
121     // the colour to make sure fg colour is different enough from m_colour
122     wxColour colFg(~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue());
123    
124     #if wxCLRBTN_USES_BMP_BUTTON
125     wxSize sz = GetSize();
126     sz.x -= 2*GetMarginX();
127     sz.y -= 2*GetMarginY();
128    
129     wxPoint topleft;
130    
131     if ( sz.x < 1 )
132     sz.x = 1;
133     else
134     if ( sz.y < 1 )
135     sz.y = 1;
136    
137     wxBitmap bmp(sz.x, sz.y);
138     {
139     wxMemoryDC memdc(bmp);
140     memdc.SetPen(colFg);
141     memdc.SetBrush(m_colour);
142     memdc.DrawRectangle(topleft,sz);
143     if ( HasFlag(wxCLRP_SHOW_LABEL) )
144     {
145     int x, y, leading, desc;
146     wxString label = m_colour.GetAsString(wxC2S_HTML_SYNTAX);
147     memdc.GetTextExtent(label,&x,&y,&desc,&leading);
148     if ( x <= sz.x && y <= sz.y )
149     {
150     topleft.x += (sz.x-x)/2;
151     topleft.y += (sz.y-y)/2;
152     memdc.SetTextForeground(colFg);
153     memdc.DrawText(label,topleft);
154     }
155     }
156     }
157     SetBitmapLabel(bmp);
158     #else
159     SetForegroundColour(colFg);
160     SetBackgroundColour(m_colour);
161    
162     if ( HasFlag(wxCLRP_SHOW_LABEL) )
163     SetLabel(m_colour.GetAsString(wxC2S_HTML_SYNTAX));
164     #endif
165     }
166    
167     wxSize wxGenericColourButton::DoGetBestSize() const
168     {
169     wxSize sz(wxButton::DoGetBestSize());
170     if ( HasFlag(wxCLRP_SHOW_LABEL) )
171     {
172     #if wxCLRBTN_USES_BMP_BUTTON
173     int x, y, leading, desc;
174     wxString label = m_colour.GetAsString(wxC2S_HTML_SYNTAX);
175     wxClientDC dc(const_cast<wxGenericColourButton*>(this));
176     dc.GetTextExtent(label,&x,&y,&desc,&leading);
177     sz.x = sz.y+x;
178     #endif
179     return sz;
180     }
181    
182     // if we have no label, then make this button a square
183     // (like e.g. native GTK version of this control)
184     sz.SetWidth(sz.GetHeight());
185     return sz;
186     }
187    
188     #endif // wxUSE_COLOURPICKERCTRL

  ViewVC Help
Powered by ViewVC 1.1.22