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