]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
There was no icon file in this example, causing compilation with VC to fail. I just...
[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$
8// Copyright: (c) Julian Smart and Markus Holzem
f6bcfd97 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
f6bcfd97
BP
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
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
45#include <windows.h>
46
4286a5b5 47#if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
f6bcfd97 48 #include <commdlg.h>
2bda0e17
KB
49#endif
50
51#include "wx/msw/private.h"
52#include "wx/colordlg.h"
53#include "wx/cmndata.h"
54
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,
75 WPARAM wParam,
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());
84 }
85
86 return 0;
87}
88
89// ----------------------------------------------------------------------------
90// wxColourDialog
91// ----------------------------------------------------------------------------
2bda0e17 92
f6bcfd97 93wxColourDialog::wxColourDialog()
2bda0e17 94{
2bda0e17
KB
95}
96
97wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
98{
f6bcfd97 99 Create(parent, data);
2bda0e17
KB
100}
101
102bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
103{
f6bcfd97
BP
104 m_parent = parent;
105 if (data)
106 m_colourData = *data;
bbcdf8bc 107
f6bcfd97 108 return TRUE;
2bda0e17
KB
109}
110
f6bcfd97 111int wxColourDialog::ShowModal()
2bda0e17
KB
112{
113 CHOOSECOLOR chooseColorStruct;
114 COLORREF custColours[16];
115 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
116
117 int i;
118 for (i = 0; i < 16; i++)
f6bcfd97 119 custColours[i] = wxColourToRGB(m_colourData.custColours[i]);
2bda0e17
KB
120
121 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
f6bcfd97
BP
122 if ( m_parent )
123 chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
124 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.dataColour);
2bda0e17
KB
125 chooseColorStruct.lpCustColors = custColours;
126
f6bcfd97
BP
127 chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
128 chooseColorStruct.lCustData = (LPARAM)this;
129 chooseColorStruct.lpfnHook = wxColourDialogHookProc;
2bda0e17 130
cf75c1b4
RD
131 if (m_colourData.GetChooseFull())
132 chooseColorStruct.Flags |= CC_FULLOPEN;
2bda0e17
KB
133
134 // Do the modal dialog
f6bcfd97 135 bool success = ::ChooseColor(&(chooseColorStruct)) != 0;
2bda0e17
KB
136
137 // Try to highlight the correct window (the parent)
138 HWND hWndParent = 0;
139 if (GetParent())
140 {
141 hWndParent = (HWND) GetParent()->GetHWND();
142 if (hWndParent)
143 ::BringWindowToTop(hWndParent);
144 }
145
146
147 // Restore values
148 for (i = 0; i < 16; i++)
149 {
f6bcfd97 150 wxRGBToColour(m_colourData.custColours[i], custColours[i]);
2bda0e17
KB
151 }
152
f6bcfd97 153 wxRGBToColour(m_colourData.dataColour, chooseColorStruct.rgbResult);
2bda0e17
KB
154
155 return success ? wxID_OK : wxID_CANCEL;
156}
157
f6bcfd97
BP
158// ----------------------------------------------------------------------------
159// title
160// ----------------------------------------------------------------------------
161
162void wxColourDialog::SetTitle(const wxString& title)
163{
164 m_title = title;
165}
166
167wxString wxColourDialog::GetTitle()
168{
169 return m_title;
170}
171
172// ----------------------------------------------------------------------------
173// position/size
174// ----------------------------------------------------------------------------
175
176void wxColourDialog::DoSetSize(int WXUNUSED(x), int WXUNUSED(y),
177 int WXUNUSED(width), int WXUNUSED(height),
178 int WXUNUSED(sizeFlags))
179{
180 // ignore - we can't change the size of this standard dialog
181 return;
182}
183
184// NB: of course, both of these functions are completely bogus, but it's better
185// than nothing
186void wxColourDialog::DoGetSize(int *width, int *height) const
187{
188 // the standard dialog size
189 if ( width )
190 *width = 225;
191 if ( height )
192 *height = 324;
193}
194
195void wxColourDialog::DoGetClientSize(int *width, int *height) const
196{
197 // the standard dialog size
198 if ( width )
199 *width = 219;
200 if ( height )
201 *height = 299;
202}