]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
build fixes
[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
82c63878
VZ
47// ----------------------------------------------------------------------------
48// globals
49// ----------------------------------------------------------------------------
50
51// standard colors dialog size for the Windows systems
52// this is ok if color dialog created with standart color
53// and "Define Custom Colors" extension not shown
54static wxRect gs_rectDialog(0, 0, 222, 324);
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;
82c63878
VZ
79 wxColourDialog * const
80 dialog = wx_reinterpret_cast(wxColourDialog *, pCC->lCustData);
f6bcfd97 81
e42aab7f 82 const wxString title = dialog->GetTitle();
283db411
VZ
83 if ( !title.empty() )
84 ::SetWindowText(hwnd, title.wx_str());
f63e3ebb 85
82c63878 86 dialog->MSWOnInitDone((WXHWND)hwnd);
f6bcfd97
BP
87 }
88
89 return 0;
90}
91
92// ----------------------------------------------------------------------------
93// wxColourDialog
94// ----------------------------------------------------------------------------
2bda0e17 95
82c63878 96void wxColourDialog::Init()
2bda0e17 97{
82c63878
VZ
98 m_movedWindow = false;
99 m_centreDir = 0;
100
101 // reset to zero, otherwise the wx routines won't size the window the
102 // second time the dialog is shown, because they would believe it already
103 // has the requested size/position
104 gs_rectDialog.x =
105 gs_rectDialog.y = 0;
2bda0e17
KB
106}
107
108bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
109{
f6bcfd97
BP
110 m_parent = parent;
111 if (data)
112 m_colourData = *data;
bbcdf8bc 113
02b7b6b0 114 return true;
2bda0e17
KB
115}
116
f6bcfd97 117int wxColourDialog::ShowModal()
2bda0e17
KB
118{
119 CHOOSECOLOR chooseColorStruct;
120 COLORREF custColours[16];
121 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
122
123 int i;
124 for (i = 0; i < 16; i++)
393c836c
VS
125 {
126 if (m_colourData.m_custColours[i].Ok())
127 custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]);
128 else
129 custColours[i] = RGB(255,255,255);
130 }
2bda0e17
KB
131
132 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
f6bcfd97
BP
133 if ( m_parent )
134 chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
ae500232 135 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.m_dataColour);
2bda0e17
KB
136 chooseColorStruct.lpCustColors = custColours;
137
f6bcfd97
BP
138 chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
139 chooseColorStruct.lCustData = (LPARAM)this;
140 chooseColorStruct.lpfnHook = wxColourDialogHookProc;
2bda0e17 141
cf75c1b4
RD
142 if (m_colourData.GetChooseFull())
143 chooseColorStruct.Flags |= CC_FULLOPEN;
2bda0e17
KB
144
145 // Do the modal dialog
f6bcfd97 146 bool success = ::ChooseColor(&(chooseColorStruct)) != 0;
2bda0e17
KB
147
148 // Try to highlight the correct window (the parent)
2bda0e17
KB
149 if (GetParent())
150 {
5cb598ae 151 HWND hWndParent = (HWND) GetParent()->GetHWND();
2bda0e17
KB
152 if (hWndParent)
153 ::BringWindowToTop(hWndParent);
154 }
155
156
157 // Restore values
158 for (i = 0; i < 16; i++)
159 {
ae500232 160 wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
2bda0e17
KB
161 }
162
ae500232 163 wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult);
2bda0e17
KB
164
165 return success ? wxID_OK : wxID_CANCEL;
166}
167
f6bcfd97
BP
168// ----------------------------------------------------------------------------
169// title
170// ----------------------------------------------------------------------------
171
172void wxColourDialog::SetTitle(const wxString& title)
173{
174 m_title = title;
175}
176
ba14d986 177wxString wxColourDialog::GetTitle() const
f6bcfd97
BP
178{
179 return m_title;
180}
181
182// ----------------------------------------------------------------------------
183// position/size
184// ----------------------------------------------------------------------------
185
f63e3ebb
VZ
186void wxColourDialog::DoGetPosition(int *x, int *y) const
187{
188 if ( x )
82c63878 189 *x = gs_rectDialog.x;
f63e3ebb 190 if ( y )
82c63878 191 *y = gs_rectDialog.y;
f63e3ebb
VZ
192}
193
82c63878 194void wxColourDialog::DoCentre(int dir)
f6bcfd97 195{
82c63878
VZ
196 m_centreDir = dir;
197
198 // it's unnecessary to do anything else at this stage as we'll redo it in
199 // MSWOnInitDone() anyhow
200}
f63e3ebb 201
82c63878
VZ
202void wxColourDialog::DoMoveWindow(int x, int y, int WXUNUSED(w), int WXUNUSED(h))
203{
204 gs_rectDialog.x = x;
205 gs_rectDialog.y = y;
f63e3ebb 206
82c63878
VZ
207 // our HWND is only set when we're called from MSWOnInitDone(), test if
208 // this is the case
209 HWND hwnd = GetHwnd();
210 if ( hwnd )
211 {
212 // size of the dialog can't be changed because the controls are not
213 // laid out correctly then
214 ::SetWindowPos(hwnd, HWND_TOP, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
215 }
216 else // just remember that we were requested to move the window
217 {
218 m_movedWindow = true;
219
220 // if Centre() had been called before, it shouldn't be taken into
221 // account now
222 m_centreDir = 0;
223 }
f6bcfd97
BP
224}
225
f6bcfd97
BP
226void wxColourDialog::DoGetSize(int *width, int *height) const
227{
f6bcfd97 228 if ( width )
82c63878 229 *width = gs_rectDialog.width;
f6bcfd97 230 if ( height )
82c63878 231 *height = gs_rectDialog.height;
f6bcfd97
BP
232}
233
234void wxColourDialog::DoGetClientSize(int *width, int *height) const
235{
f6bcfd97 236 if ( width )
82c63878 237 *width = gs_rectDialog.width;
f6bcfd97 238 if ( height )
82c63878
VZ
239 *height = gs_rectDialog.height;
240}
241
242void wxColourDialog::MSWOnInitDone(WXHWND hDlg)
243{
244 // set HWND so that our DoMoveWindow() works correctly
245 SetHWND(hDlg);
246
247 if ( m_centreDir )
248 {
249 // now we have the real dialog size, remember it
250 RECT rect;
251 ::GetWindowRect((HWND)hDlg, &rect);
252 gs_rectDialog = wxRectFromRECT(rect);
253
254 // and position the window correctly: notice that we must use the base
255 // class version as our own doesn't do anything except setting flags
256 wxDialog::DoCentre(m_centreDir);
257 }
258 else if ( m_movedWindow ) // need to just move it to the correct place
259 {
260 SetPosition(GetPosition());
261 }
262
263 // we shouldn't destroy hDlg, so disassociate from it
264 SetHWND(NULL);
f6bcfd97 265}
f63e3ebb 266
3180bc0e 267#endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)