]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
Added licence/copyright information
[wxWidgets.git] / src / msw / colordlg.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
f6bcfd97 2// Name: src/msw/colordlg.cpp
2bda0e17
KB
3// Purpose: wxColourDialog class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
f6bcfd97
BP
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
f6bcfd97 21 #pragma implementation "colordlg.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
f6bcfd97 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
f6bcfd97
BP
32 #include <stdio.h>
33 #include "wx/defs.h"
34 #include "wx/bitmap.h"
35 #include "wx/pen.h"
36 #include "wx/brush.h"
37 #include "wx/colour.h"
38 #include "wx/gdicmn.h"
39 #include "wx/utils.h"
40 #include "wx/frame.h"
41 #include "wx/dialog.h"
42 #include "wx/msgdlg.h"
2bda0e17
KB
43#endif
44
3180bc0e 45#if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
adf9e099 46
2bda0e17
KB
47#include "wx/msw/private.h"
48#include "wx/colordlg.h"
49#include "wx/cmndata.h"
b713f891 50#include "wx/math.h"
660296aa 51#include "wx/msw/wrapcdlg.h"
4676948b 52
2bda0e17
KB
53#include <stdlib.h>
54#include <string.h>
55
f6bcfd97
BP
56// ----------------------------------------------------------------------------
57// wxWin macros
58// ----------------------------------------------------------------------------
2bda0e17 59
2bda0e17 60IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
2bda0e17 61
f6bcfd97
BP
62// ============================================================================
63// implementation
64// ============================================================================
65
66// ----------------------------------------------------------------------------
67// colour dialog hook proc
68// ----------------------------------------------------------------------------
69
975b6bcf
VZ
70UINT_PTR CALLBACK
71wxColourDialogHookProc(HWND hwnd,
72 UINT uiMsg,
73 WPARAM WXUNUSED(wParam),
74 LPARAM lParam)
f6bcfd97
BP
75{
76 if ( uiMsg == WM_INITDIALOG )
77 {
78 CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
79 wxColourDialog *dialog = (wxColourDialog *)pCC->lCustData;
80
81 ::SetWindowText(hwnd, dialog->GetTitle());
f63e3ebb
VZ
82
83 wxPoint pos = dialog->GetPosition();
84 if ( pos != wxDefaultPosition )
85 {
86 ::SetWindowPos(hwnd, NULL /* Z-order: ignored */,
87 pos.x, pos.y, -1, -1,
88 SWP_NOSIZE | SWP_NOZORDER);
89 }
f6bcfd97
BP
90 }
91
92 return 0;
93}
94
95// ----------------------------------------------------------------------------
96// wxColourDialog
97// ----------------------------------------------------------------------------
2bda0e17 98
f6bcfd97 99wxColourDialog::wxColourDialog()
2bda0e17 100{
f63e3ebb 101 m_pos = wxDefaultPosition;
2bda0e17
KB
102}
103
104wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
105{
f63e3ebb
VZ
106 m_pos = wxDefaultPosition;
107
f6bcfd97 108 Create(parent, data);
2bda0e17
KB
109}
110
111bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
112{
f6bcfd97
BP
113 m_parent = parent;
114 if (data)
115 m_colourData = *data;
bbcdf8bc 116
02b7b6b0 117 return true;
2bda0e17
KB
118}
119
f6bcfd97 120int wxColourDialog::ShowModal()
2bda0e17
KB
121{
122 CHOOSECOLOR chooseColorStruct;
123 COLORREF custColours[16];
124 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
125
126 int i;
127 for (i = 0; i < 16; i++)
393c836c
VS
128 {
129 if (m_colourData.m_custColours[i].Ok())
130 custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]);
131 else
132 custColours[i] = RGB(255,255,255);
133 }
2bda0e17
KB
134
135 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
f6bcfd97
BP
136 if ( m_parent )
137 chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
ae500232 138 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.m_dataColour);
2bda0e17
KB
139 chooseColorStruct.lpCustColors = custColours;
140
f6bcfd97
BP
141 chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
142 chooseColorStruct.lCustData = (LPARAM)this;
143 chooseColorStruct.lpfnHook = wxColourDialogHookProc;
2bda0e17 144
cf75c1b4
RD
145 if (m_colourData.GetChooseFull())
146 chooseColorStruct.Flags |= CC_FULLOPEN;
2bda0e17
KB
147
148 // Do the modal dialog
f6bcfd97 149 bool success = ::ChooseColor(&(chooseColorStruct)) != 0;
2bda0e17
KB
150
151 // Try to highlight the correct window (the parent)
2bda0e17
KB
152 if (GetParent())
153 {
5cb598ae 154 HWND hWndParent = (HWND) GetParent()->GetHWND();
2bda0e17
KB
155 if (hWndParent)
156 ::BringWindowToTop(hWndParent);
157 }
158
159
160 // Restore values
161 for (i = 0; i < 16; i++)
162 {
ae500232 163 wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
2bda0e17
KB
164 }
165
ae500232 166 wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult);
2bda0e17
KB
167
168 return success ? wxID_OK : wxID_CANCEL;
169}
170
f6bcfd97
BP
171// ----------------------------------------------------------------------------
172// title
173// ----------------------------------------------------------------------------
174
175void wxColourDialog::SetTitle(const wxString& title)
176{
177 m_title = title;
178}
179
ba14d986 180wxString wxColourDialog::GetTitle() const
f6bcfd97
BP
181{
182 return m_title;
183}
184
185// ----------------------------------------------------------------------------
186// position/size
187// ----------------------------------------------------------------------------
188
f63e3ebb
VZ
189void wxColourDialog::DoGetPosition(int *x, int *y) const
190{
191 if ( x )
192 *x = m_pos.x;
193 if ( y )
194 *y = m_pos.y;
195}
196
197void wxColourDialog::DoSetSize(int x, int y,
f6bcfd97
BP
198 int WXUNUSED(width), int WXUNUSED(height),
199 int WXUNUSED(sizeFlags))
200{
02b7b6b0 201 if ( x != wxDefaultCoord )
f63e3ebb
VZ
202 m_pos.x = x;
203
02b7b6b0 204 if ( y != wxDefaultCoord )
f63e3ebb
VZ
205 m_pos.y = y;
206
207 // ignore the size params - we can't change the size of a standard dialog
f6bcfd97
BP
208 return;
209}
210
211// NB: of course, both of these functions are completely bogus, but it's better
212// than nothing
213void wxColourDialog::DoGetSize(int *width, int *height) const
214{
215 // the standard dialog size
216 if ( width )
217 *width = 225;
218 if ( height )
219 *height = 324;
220}
221
222void wxColourDialog::DoGetClientSize(int *width, int *height) const
223{
224 // the standard dialog size
225 if ( width )
226 *width = 219;
227 if ( height )
228 *height = 299;
229}
f63e3ebb 230
3180bc0e 231#endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)