]> git.saurik.com Git - wxWidgets.git/blame - src/generic/clrpickerg.cpp
Expose the Apple menu so it can be setup manually.
[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
ec376c8f
VZ
7// Copyright: (c) Vadim Zeitlin, Francesco Montorsi
8// Licence: wxWindows licence
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
c757b5fe 26#if wxUSE_COLOURPICKERCTRL
ec376c8f
VZ
27
28#include "wx/clrpicker.h"
29#include "wx/colordlg.h"
8f782954 30#include "wx/dcmemory.h"
ec376c8f
VZ
31
32
33// ============================================================================
34// implementation
35// ============================================================================
36
ec376c8f 37wxColourData wxGenericColourButton::ms_data;
480be76a 38IMPLEMENT_DYNAMIC_CLASS(wxGenericColourButton, wxBitmapButton)
ec376c8f
VZ
39
40// ----------------------------------------------------------------------------
41// wxGenericColourButton
42// ----------------------------------------------------------------------------
43
44bool wxGenericColourButton::Create( wxWindow *parent, wxWindowID id,
45 const wxColour &col, const wxPoint &pos,
46 const wxSize &size, long style,
47 const wxValidator& validator, const wxString &name)
48{
480be76a
RR
49 m_bitmap = wxBitmap( 60, 13 );
50
ec376c8f 51 // create this button
480be76a 52 if (!wxBitmapButton::Create( parent, id, m_bitmap, pos,
da1f0e87 53 size, style | wxBU_AUTODRAW, validator, name ))
ec376c8f
VZ
54 {
55 wxFAIL_MSG( wxT("wxGenericColourButton creation failed") );
56 return false;
57 }
58
59 // and handle user clicks on it
ce7fe42e 60 Connect(GetId(), wxEVT_BUTTON,
ec376c8f
VZ
61 wxCommandEventHandler(wxGenericColourButton::OnButtonClick),
62 NULL, this);
63
64 m_colour = col;
65 UpdateColour();
66 InitColourData();
67
68 return true;
69}
70
71void wxGenericColourButton::InitColourData()
72{
73 ms_data.SetChooseFull(true);
7c808858
WS
74 unsigned char grey = 0;
75 for (int i = 0; i < 16; i++, grey += 16)
ec376c8f
VZ
76 {
77 // fill with grey tones the custom colors palette
7c808858 78 wxColour colour(grey, grey, grey);
ec376c8f
VZ
79 ms_data.SetCustomColour(i, colour);
80 }
81}
82
83void wxGenericColourButton::OnButtonClick(wxCommandEvent& WXUNUSED(ev))
84{
4c51a665 85 // update the wxColouData to be shown in the dialog
ec376c8f
VZ
86 ms_data.SetColour(m_colour);
87
88 // create the colour dialog and display it
89 wxColourDialog dlg(this, &ms_data);
90 if (dlg.ShowModal() == wxID_OK)
91 {
92 ms_data = dlg.GetColourData();
93 SetColour(ms_data.GetColour());
94
95 // fire an event
96 wxColourPickerEvent event(this, GetId(), m_colour);
97 GetEventHandler()->ProcessEvent(event);
98 }
99}
100
101void wxGenericColourButton::UpdateColour()
102{
480be76a
RR
103 wxMemoryDC dc(m_bitmap);
104 dc.SetPen( *wxTRANSPARENT_PEN );
105 dc.SetBrush( wxBrush(m_colour) );
106 dc.DrawRectangle( 0,0,m_bitmap.GetWidth(),m_bitmap.GetHeight() );
29f571de 107
a5b43304 108 if ( HasFlag(wxCLRP_SHOW_LABEL) )
da1f0e87
RR
109 {
110 wxColour col( ~m_colour.Red(), ~m_colour.Green(), ~m_colour.Blue() );
111 dc.SetTextForeground( col );
112 dc.SetFont( GetFont() );
113 dc.DrawText( m_colour.GetAsString(wxC2S_HTML_SYNTAX), 0, 0 );
114 }
29f571de 115
480be76a
RR
116 dc.SelectObject( wxNullBitmap );
117 SetBitmapLabel( m_bitmap );
ec376c8f
VZ
118}
119
e8427971
WS
120wxSize wxGenericColourButton::DoGetBestSize() const
121{
480be76a 122 wxSize sz(wxBitmapButton::DoGetBestSize());
da1f0e87 123#ifdef __WXMAC__
480be76a 124 sz.y += 6;
da1f0e87
RR
125#else
126 sz.y += 2;
127#endif
480be76a 128 sz.x += 30;
e8427971
WS
129 if ( HasFlag(wxCLRP_SHOW_LABEL) )
130 return sz;
131
132 // if we have no label, then make this button a square
480be76a
RR
133 // (like e.g. native GTK version of this control) ???
134 // sz.SetWidth(sz.GetHeight());
e8427971
WS
135 return sz;
136}
137
ec376c8f 138#endif // wxUSE_COLOURPICKERCTRL