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