]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
wxCocoa: Better icon support
[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
f6bcfd97 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
449110cd 45#if wxUSE_COLOURDLG && !wxUSE_SMARTPHONE
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
73UINT CALLBACK wxColourDialogHookProc(HWND hwnd,
74 UINT uiMsg,
33ac7e6f 75 WPARAM WXUNUSED(wParam),
f6bcfd97
BP
76 LPARAM lParam)
77{
78 if ( uiMsg == WM_INITDIALOG )
79 {
80 CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
81 wxColourDialog *dialog = (wxColourDialog *)pCC->lCustData;
82
83 ::SetWindowText(hwnd, dialog->GetTitle());
f63e3ebb
VZ
84
85 wxPoint pos = dialog->GetPosition();
86 if ( pos != wxDefaultPosition )
87 {
88 ::SetWindowPos(hwnd, NULL /* Z-order: ignored */,
89 pos.x, pos.y, -1, -1,
90 SWP_NOSIZE | SWP_NOZORDER);
91 }
f6bcfd97
BP
92 }
93
94 return 0;
95}
96
97// ----------------------------------------------------------------------------
98// wxColourDialog
99// ----------------------------------------------------------------------------
2bda0e17 100
f6bcfd97 101wxColourDialog::wxColourDialog()
2bda0e17 102{
f63e3ebb 103 m_pos = wxDefaultPosition;
2bda0e17
KB
104}
105
106wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
107{
f63e3ebb
VZ
108 m_pos = wxDefaultPosition;
109
f6bcfd97 110 Create(parent, data);
2bda0e17
KB
111}
112
113bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
114{
f6bcfd97
BP
115 m_parent = parent;
116 if (data)
117 m_colourData = *data;
bbcdf8bc 118
f6bcfd97 119 return TRUE;
2bda0e17
KB
120}
121
f6bcfd97 122int wxColourDialog::ShowModal()
2bda0e17
KB
123{
124 CHOOSECOLOR chooseColorStruct;
125 COLORREF custColours[16];
126 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
127
128 int i;
129 for (i = 0; i < 16; i++)
ae500232 130 custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]);
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)
149 HWND hWndParent = 0;
150 if (GetParent())
151 {
152 hWndParent = (HWND) GetParent()->GetHWND();
153 if (hWndParent)
154 ::BringWindowToTop(hWndParent);
155 }
156
157
158 // Restore values
159 for (i = 0; i < 16; i++)
160 {
ae500232 161 wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
2bda0e17
KB
162 }
163
ae500232 164 wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult);
2bda0e17
KB
165
166 return success ? wxID_OK : wxID_CANCEL;
167}
168
f6bcfd97
BP
169// ----------------------------------------------------------------------------
170// title
171// ----------------------------------------------------------------------------
172
173void wxColourDialog::SetTitle(const wxString& title)
174{
175 m_title = title;
176}
177
ba14d986 178wxString wxColourDialog::GetTitle() const
f6bcfd97
BP
179{
180 return m_title;
181}
182
183// ----------------------------------------------------------------------------
184// position/size
185// ----------------------------------------------------------------------------
186
f63e3ebb
VZ
187void wxColourDialog::DoGetPosition(int *x, int *y) const
188{
189 if ( x )
190 *x = m_pos.x;
191 if ( y )
192 *y = m_pos.y;
193}
194
195void wxColourDialog::DoSetSize(int x, int y,
f6bcfd97
BP
196 int WXUNUSED(width), int WXUNUSED(height),
197 int WXUNUSED(sizeFlags))
198{
f63e3ebb
VZ
199 if ( x != -1 )
200 m_pos.x = x;
201
202 if ( y != -1 )
203 m_pos.y = y;
204
205 // ignore the size params - we can't change the size of a standard dialog
f6bcfd97
BP
206 return;
207}
208
209// NB: of course, both of these functions are completely bogus, but it's better
210// than nothing
211void wxColourDialog::DoGetSize(int *width, int *height) const
212{
213 // the standard dialog size
214 if ( width )
215 *width = 225;
216 if ( height )
217 *height = 324;
218}
219
220void wxColourDialog::DoGetClientSize(int *width, int *height) const
221{
222 // the standard dialog size
223 if ( width )
224 *width = 219;
225 if ( height )
226 *height = 299;
227}
f63e3ebb 228
adf9e099 229#endif