]> git.saurik.com Git - wxWidgets.git/blame - src/generic/clrpickerg.cpp
Rework IE virtual file system support to use new syntax. Remove now unused code for...
[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"
30#include "wx/colordlg.h"
8f782954 31#include "wx/dcmemory.h"
ec376c8f
VZ
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,
da1f0e87 54 size, style | wxBU_AUTODRAW, validator, name ))
ec376c8f
VZ
55 {
56 wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
57 return false;
58 }
59
60 // and handle user clicks on it
29f571de 61 Connect(GetId(), wxEVT_COMMAND_BUTTON_CLICKED,
ec376c8f
VZ
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{
4c51a665 86 // update the wxColouData to be shown in the dialog
ec376c8f
VZ
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() );
29f571de 108
a5b43304 109 if ( HasFlag(wxCLRP_SHOW_LABEL) )
da1f0e87
RR
110 {
111 wxColour col( ~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue() );
112 dc.SetTextForeground( col );
113 dc.SetFont( GetFont() );
114 dc.DrawText( m_colour.GetAsString(wxC2S_HTML_SYNTAX), 0, 0 );
115 }
29f571de 116
480be76a
RR
117 dc.SelectObject( wxNullBitmap );
118 SetBitmapLabel( m_bitmap );
ec376c8f
VZ
119}
120
e8427971
WS
121wxSize wxGenericColourButton::DoGetBestSize() const
122{
480be76a 123 wxSize sz(wxBitmapButton::DoGetBestSize());
da1f0e87 124#ifdef __WXMAC__
480be76a 125 sz.y += 6;
da1f0e87
RR
126#else
127 sz.y += 2;
128#endif
480be76a 129 sz.x += 30;
e8427971
WS
130 if ( HasFlag(wxCLRP_SHOW_LABEL) )
131 return sz;
132
133 // if we have no label, then make this button a square
480be76a
RR
134 // (like e.g. native GTK version of this control) ???
135 // sz.SetWidth(sz.GetHeight());
e8427971
WS
136 return sz;
137}
138
ec376c8f 139#endif // wxUSE_COLOURPICKERCTRL