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