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