]> git.saurik.com Git - wxWidgets.git/blame - src/generic/clrpickerg.cpp
unifying CFTypes
[wxWidgets.git] / src / generic / clrpickerg.cpp
CommitLineData
ec376c8f
VZ
1///////////////////////////////////////////////////////////////////////////////
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$
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
c757b5fe 27#if wxUSE_COLOURPICKERCTRL
ec376c8f
VZ
28
29#include "wx/clrpicker.h"
c757b5fe 30
ec376c8f
VZ
31#include "wx/colordlg.h"
32
33
34// ============================================================================
35// implementation
36// ============================================================================
37
ec376c8f 38wxColourData wxGenericColourButton::ms_data;
480be76a 39IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxBitmapButton)
ec376c8f
VZ
40
41// ----------------------------------------------------------------------------
42// wxGenericColourButton
43// ----------------------------------------------------------------------------
44
45bool 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{
480be76a
RR
50 m_bitmap = wxBitmap( 60, 13 );
51
ec376c8f 52 // create this button
480be76a 53 if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
ec376c8f
VZ
54 size, style, validator, name ))
55 {
56 wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
57 return false;
58 }
59
60 // and handle user clicks on it
61 Connect(wxEVT_COMMAND_BUTTON_CLICKED,
62 wxCommandEventHandler(wxGenericColourButton::OnButtonClick),
63 NULL, this);
64
65 m_colour = col;
66 UpdateColour();
67 InitColourData();
68
69 return true;
70}
71
72void wxGenericColourButton::InitColourData()
73{
74 ms_data.SetChooseFull(true);
7c808858
WS
75 unsigned char grey = 0;
76 for (int i = 0; i < 16; i++, grey += 16)
ec376c8f
VZ
77 {
78 // fill with grey tones the custom colors palette
7c808858 79 wxColour colour(grey, grey, grey);
ec376c8f
VZ
80 ms_data.SetCustomColour(i, colour);
81 }
82}
83
84void wxGenericColourButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
85{
86 // update the wxColouData to be shown in the the dialog
87 ms_data.SetColour(m_colour);
88
89 // create the colour dialog and display it
90 wxColourDialog dlg(this, &ms_data);
91 if (dlg.ShowModal() == wxID_OK)
92 {
93 ms_data = dlg.GetColourData();
94 SetColour(ms_data.GetColour());
95
96 // fire an event
97 wxColourPickerEvent event(this, GetId(), m_colour);
98 GetEventHandler()->ProcessEvent(event);
99 }
100}
101
102void wxGenericColourButton::UpdateColour()
103{
480be76a
RR
104 wxMemoryDC dc(m_bitmap);
105 dc.SetPen( *wxTRANSPARENT_PEN );
106 dc.SetBrush( wxBrush(m_colour) );
107 dc.DrawRectangle( 0,0,m_bitmap.GetWidth(),m_bitmap.GetHeight() );
108 dc.SelectObject( wxNullBitmap );
109 SetBitmapLabel( m_bitmap );
110
111#if 0
ec376c8f
VZ
112 if ( HasFlag(wxCLRP_SHOW_LABEL) )
113 SetLabel(m_colour.GetAsString(wxC2S_HTML_SYNTAX));
480be76a 114#endif
ec376c8f
VZ
115}
116
e8427971
WS
117wxSize wxGenericColourButton::DoGetBestSize() const
118{
480be76a
RR
119 wxSize sz(wxBitmapButton::DoGetBestSize());
120 sz.y += 6;
121 sz.x += 30;
e8427971
WS
122 if ( HasFlag(wxCLRP_SHOW_LABEL) )
123 return sz;
124
125 // if we have no label, then make this button a square
480be76a
RR
126 // (like e.g. native GTK version of this control) ???
127 // sz.SetWidth(sz.GetHeight());
e8427971
WS
128 return sz;
129}
130
ec376c8f 131#endif // wxUSE_COLOURPICKERCTRL