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