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