fix reference to temporary
[wxWidgets.git] / src / msw / colordlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/colordlg.cpp
3 // Purpose: wxColourDialog class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
28
29 #include "wx/colordlg.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/msw/wrapcdlg.h"
33 #include <stdio.h>
34 #include "wx/colour.h"
35 #include "wx/gdicmn.h"
36 #include "wx/utils.h"
37 #include "wx/dialog.h"
38 #include "wx/cmndata.h"
39 #include "wx/math.h"
40 #endif
41
42 #include "wx/msw/private.h"
43
44 #include <stdlib.h>
45 #include <string.h>
46
47 // ----------------------------------------------------------------------------
48 // wxWin macros
49 // ----------------------------------------------------------------------------
50
51 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
52
53 // ============================================================================
54 // implementation
55 // ============================================================================
56
57 // ----------------------------------------------------------------------------
58 // colour dialog hook proc
59 // ----------------------------------------------------------------------------
60
61 UINT_PTR CALLBACK
62 wxColourDialogHookProc(HWND hwnd,
63 UINT uiMsg,
64 WPARAM WXUNUSED(wParam),
65 LPARAM lParam)
66 {
67 if ( uiMsg == WM_INITDIALOG )
68 {
69 CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
70 wxColourDialog *dialog = (wxColourDialog *)pCC->lCustData;
71
72 const wxString title = dialog->GetTitle();
73 if ( !title.empty() )
74 ::SetWindowText(hwnd, title.wx_str());
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 }
83 }
84
85 return 0;
86 }
87
88 // ----------------------------------------------------------------------------
89 // wxColourDialog
90 // ----------------------------------------------------------------------------
91
92 wxColourDialog::wxColourDialog()
93 {
94 m_pos = wxDefaultPosition;
95 }
96
97 wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
98 {
99 m_pos = wxDefaultPosition;
100
101 Create(parent, data);
102 }
103
104 bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
105 {
106 m_parent = parent;
107 if (data)
108 m_colourData = *data;
109
110 return true;
111 }
112
113 int wxColourDialog::ShowModal()
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++)
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 }
127
128 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
129 if ( m_parent )
130 chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
131 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.m_dataColour);
132 chooseColorStruct.lpCustColors = custColours;
133
134 chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
135 chooseColorStruct.lCustData = (LPARAM)this;
136 chooseColorStruct.lpfnHook = wxColourDialogHookProc;
137
138 if (m_colourData.GetChooseFull())
139 chooseColorStruct.Flags |= CC_FULLOPEN;
140
141 // Do the modal dialog
142 bool success = ::ChooseColor(&(chooseColorStruct)) != 0;
143
144 // Try to highlight the correct window (the parent)
145 if (GetParent())
146 {
147 HWND hWndParent = (HWND) GetParent()->GetHWND();
148 if (hWndParent)
149 ::BringWindowToTop(hWndParent);
150 }
151
152
153 // Restore values
154 for (i = 0; i < 16; i++)
155 {
156 wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
157 }
158
159 wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult);
160
161 return success ? wxID_OK : wxID_CANCEL;
162 }
163
164 // ----------------------------------------------------------------------------
165 // title
166 // ----------------------------------------------------------------------------
167
168 void wxColourDialog::SetTitle(const wxString& title)
169 {
170 m_title = title;
171 }
172
173 wxString wxColourDialog::GetTitle() const
174 {
175 return m_title;
176 }
177
178 // ----------------------------------------------------------------------------
179 // position/size
180 // ----------------------------------------------------------------------------
181
182 void 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
190 void wxColourDialog::DoSetSize(int x, int y,
191 int WXUNUSED(width), int WXUNUSED(height),
192 int WXUNUSED(sizeFlags))
193 {
194 if ( x != wxDefaultCoord )
195 m_pos.x = x;
196
197 if ( y != wxDefaultCoord )
198 m_pos.y = y;
199
200 // ignore the size params - we can't change the size of a standard dialog
201 return;
202 }
203
204 // NB: of course, both of these functions are completely bogus, but it's better
205 // than nothing
206 void 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
215 void 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 }
223
224 #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)