]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
Compilation fix for !wxUSE_OWNER_DRAWN.
[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
6c9a19aa 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
2bda0e17
KB
9/////////////////////////////////////////////////////////////////////////////
10
f6bcfd97
BP
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
2bda0e17
KB
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
f6bcfd97 23 #pragma hdrstop
2bda0e17
KB
24#endif
25
ce5d92e1
WS
26#if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
27
28#include "wx/colordlg.h"
691745ab 29#include "wx/modalhook.h"
ce5d92e1 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"
18680f86 37 #include "wx/math.h"
2bda0e17
KB
38#endif
39
2bda0e17 40#include "wx/msw/private.h"
4676948b 41
2bda0e17
KB
42#include <stdlib.h>
43#include <string.h>
44
82c63878
VZ
45// ----------------------------------------------------------------------------
46// globals
47// ----------------------------------------------------------------------------
48
49// standard colors dialog size for the Windows systems
50// this is ok if color dialog created with standart color
51// and "Define Custom Colors" extension not shown
52static wxRect gs_rectDialog(0, 0, 222, 324);
53
f6bcfd97
BP
54// ----------------------------------------------------------------------------
55// wxWin macros
56// ----------------------------------------------------------------------------
2bda0e17 57
2bda0e17 58IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
2bda0e17 59
f6bcfd97
BP
60// ============================================================================
61// implementation
62// ============================================================================
63
64// ----------------------------------------------------------------------------
65// colour dialog hook proc
66// ----------------------------------------------------------------------------
67
975b6bcf
VZ
68UINT_PTR CALLBACK
69wxColourDialogHookProc(HWND hwnd,
70 UINT uiMsg,
71 WPARAM WXUNUSED(wParam),
72 LPARAM lParam)
f6bcfd97
BP
73{
74 if ( uiMsg == WM_INITDIALOG )
75 {
76 CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
82c63878 77 wxColourDialog * const
5c33522f 78 dialog = reinterpret_cast<wxColourDialog *>(pCC->lCustData);
f6bcfd97 79
e42aab7f 80 const wxString title = dialog->GetTitle();
283db411 81 if ( !title.empty() )
017dc06b 82 ::SetWindowText(hwnd, title.t_str());
f63e3ebb 83
82c63878 84 dialog->MSWOnInitDone((WXHWND)hwnd);
f6bcfd97
BP
85 }
86
87 return 0;
88}
89
90// ----------------------------------------------------------------------------
91// wxColourDialog
92// ----------------------------------------------------------------------------
2bda0e17 93
82c63878 94void wxColourDialog::Init()
2bda0e17 95{
82c63878
VZ
96 m_movedWindow = false;
97 m_centreDir = 0;
98
99 // reset to zero, otherwise the wx routines won't size the window the
100 // second time the dialog is shown, because they would believe it already
101 // has the requested size/position
102 gs_rectDialog.x =
103 gs_rectDialog.y = 0;
2bda0e17
KB
104}
105
106bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
107{
f6bcfd97
BP
108 m_parent = parent;
109 if (data)
110 m_colourData = *data;
bbcdf8bc 111
02b7b6b0 112 return true;
2bda0e17
KB
113}
114
f6bcfd97 115int wxColourDialog::ShowModal()
2bda0e17 116{
691745ab 117 WX_HOOK_MODAL_DIALOG();
643e9cf9 118
2349ba4c 119 // initialize the struct used by Windows
2bda0e17 120 CHOOSECOLOR chooseColorStruct;
2bda0e17
KB
121 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
122
05be97a8 123 size_t i;
2349ba4c
VZ
124
125 // and transfer data from m_colourData to it
126 COLORREF custColours[16];
127 for ( i = 0; i < WXSIZEOF(custColours); i++ )
393c836c 128 {
6869b469
FM
129 if ( m_colourData.GetCustomColour(i).IsOk() )
130 custColours[i] = wxColourToRGB(m_colourData.GetCustomColour(i));
393c836c
VS
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);
6869b469 138 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.GetColour());
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
2349ba4c 145 if ( m_colourData.GetChooseFull() )
cf75c1b4 146 chooseColorStruct.Flags |= CC_FULLOPEN;
2bda0e17 147
2349ba4c
VZ
148 // do show the modal dialog
149 if ( !::ChooseColor(&chooseColorStruct) )
2bda0e17 150 {
2349ba4c
VZ
151 // 0 error means the dialog was simply cancelled, i.e. no real error
152 // occurred
153 const DWORD err = CommDlgExtendedError();
154 if ( err )
43b2d5e7 155 {
2349ba4c 156 wxLogError(_("Colour selection dialog failed with error %0lx."), err);
43b2d5e7 157 }
2349ba4c
VZ
158
159 return wxID_CANCEL;
2bda0e17
KB
160 }
161
162
2349ba4c
VZ
163 // transfer the values chosen by user back into m_colourData
164 for ( i = 0; i < WXSIZEOF(custColours); i++ )
2bda0e17 165 {
f4efd805 166 wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
2bda0e17
KB
167 }
168
6869b469 169 wxRGBToColour(m_colourData.GetColour(), chooseColorStruct.rgbResult);
2bda0e17 170
2349ba4c
VZ
171 // this doesn't seem to work (contrary to what MSDN implies) on current
172 // Windows versions: CC_FULLOPEN is never set on return if it wasn't
173 // initially set and vice versa
174 //m_colourData.SetChooseFull((chooseColorStruct.Flags & CC_FULLOPEN) != 0);
175
176 return wxID_OK;
2bda0e17
KB
177}
178
f6bcfd97
BP
179// ----------------------------------------------------------------------------
180// title
181// ----------------------------------------------------------------------------
182
183void wxColourDialog::SetTitle(const wxString& title)
184{
185 m_title = title;
186}
187
ba14d986 188wxString wxColourDialog::GetTitle() const
f6bcfd97
BP
189{
190 return m_title;
191}
192
193// ----------------------------------------------------------------------------
194// position/size
195// ----------------------------------------------------------------------------
196
f63e3ebb
VZ
197void wxColourDialog::DoGetPosition(int *x, int *y) const
198{
199 if ( x )
82c63878 200 *x = gs_rectDialog.x;
f63e3ebb 201 if ( y )
82c63878 202 *y = gs_rectDialog.y;
f63e3ebb
VZ
203}
204
82c63878 205void wxColourDialog::DoCentre(int dir)
f6bcfd97 206{
82c63878
VZ
207 m_centreDir = dir;
208
209 // it's unnecessary to do anything else at this stage as we'll redo it in
210 // MSWOnInitDone() anyhow
211}
f63e3ebb 212
82c63878
VZ
213void wxColourDialog::DoMoveWindow(int x, int y, int WXUNUSED(w), int WXUNUSED(h))
214{
215 gs_rectDialog.x = x;
216 gs_rectDialog.y = y;
f63e3ebb 217
82c63878
VZ
218 // our HWND is only set when we're called from MSWOnInitDone(), test if
219 // this is the case
220 HWND hwnd = GetHwnd();
221 if ( hwnd )
222 {
223 // size of the dialog can't be changed because the controls are not
224 // laid out correctly then
225 ::SetWindowPos(hwnd, HWND_TOP, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
226 }
227 else // just remember that we were requested to move the window
228 {
229 m_movedWindow = true;
230
231 // if Centre() had been called before, it shouldn't be taken into
232 // account now
233 m_centreDir = 0;
234 }
f6bcfd97
BP
235}
236
f6bcfd97
BP
237void wxColourDialog::DoGetSize(int *width, int *height) const
238{
f6bcfd97 239 if ( width )
82c63878 240 *width = gs_rectDialog.width;
f6bcfd97 241 if ( height )
82c63878 242 *height = gs_rectDialog.height;
f6bcfd97
BP
243}
244
245void wxColourDialog::DoGetClientSize(int *width, int *height) const
246{
f6bcfd97 247 if ( width )
82c63878 248 *width = gs_rectDialog.width;
f6bcfd97 249 if ( height )
82c63878
VZ
250 *height = gs_rectDialog.height;
251}
252
253void wxColourDialog::MSWOnInitDone(WXHWND hDlg)
254{
255 // set HWND so that our DoMoveWindow() works correctly
256 SetHWND(hDlg);
257
258 if ( m_centreDir )
259 {
260 // now we have the real dialog size, remember it
261 RECT rect;
262 ::GetWindowRect((HWND)hDlg, &rect);
263 gs_rectDialog = wxRectFromRECT(rect);
264
265 // and position the window correctly: notice that we must use the base
266 // class version as our own doesn't do anything except setting flags
267 wxDialog::DoCentre(m_centreDir);
268 }
269 else if ( m_movedWindow ) // need to just move it to the correct place
270 {
271 SetPosition(GetPosition());
272 }
273
274 // we shouldn't destroy hDlg, so disassociate from it
275 SetHWND(NULL);
f6bcfd97 276}
f63e3ebb 277
3180bc0e 278#endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)