]> git.saurik.com Git - wxWidgets.git/blob - src/msw/colordlg.cpp
Added corrected Show() to wxPopupWindow
[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 #ifdef __GNUG__
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
46
47 #include <windows.h>
48
49 #if !defined(__WIN32__) || defined(__SALFORDC__)
50 #include <commdlg.h>
51 #endif
52
53 #include "wx/msw/private.h"
54 #include "wx/colordlg.h"
55 #include "wx/cmndata.h"
56
57 #include <math.h>
58 #include <stdlib.h>
59 #include <string.h>
60
61 // ----------------------------------------------------------------------------
62 // wxWin macros
63 // ----------------------------------------------------------------------------
64
65 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
66
67 // ============================================================================
68 // implementation
69 // ============================================================================
70
71 // ----------------------------------------------------------------------------
72 // colour dialog hook proc
73 // ----------------------------------------------------------------------------
74
75 UINT CALLBACK wxColourDialogHookProc(HWND hwnd,
76 UINT uiMsg,
77 WPARAM WXUNUSED(wParam),
78 LPARAM lParam)
79 {
80 if ( uiMsg == WM_INITDIALOG )
81 {
82 CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
83 wxColourDialog *dialog = (wxColourDialog *)pCC->lCustData;
84
85 ::SetWindowText(hwnd, dialog->GetTitle());
86
87 wxPoint pos = dialog->GetPosition();
88 if ( pos != wxDefaultPosition )
89 {
90 ::SetWindowPos(hwnd, NULL /* Z-order: ignored */,
91 pos.x, pos.y, -1, -1,
92 SWP_NOSIZE | SWP_NOZORDER);
93 }
94 }
95
96 return 0;
97 }
98
99 // ----------------------------------------------------------------------------
100 // wxColourDialog
101 // ----------------------------------------------------------------------------
102
103 wxColourDialog::wxColourDialog()
104 {
105 m_pos = wxDefaultPosition;
106 }
107
108 wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
109 {
110 m_pos = wxDefaultPosition;
111
112 Create(parent, data);
113 }
114
115 bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
116 {
117 m_parent = parent;
118 if (data)
119 m_colourData = *data;
120
121 return TRUE;
122 }
123
124 int wxColourDialog::ShowModal()
125 {
126 CHOOSECOLOR chooseColorStruct;
127 COLORREF custColours[16];
128 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
129
130 int i;
131 for (i = 0; i < 16; i++)
132 custColours[i] = wxColourToRGB(m_colourData.custColours[i]);
133
134 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
135 if ( m_parent )
136 chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
137 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.dataColour);
138 chooseColorStruct.lpCustColors = custColours;
139
140 chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
141 chooseColorStruct.lCustData = (LPARAM)this;
142 chooseColorStruct.lpfnHook = wxColourDialogHookProc;
143
144 if (m_colourData.GetChooseFull())
145 chooseColorStruct.Flags |= CC_FULLOPEN;
146
147 // Do the modal dialog
148 bool success = ::ChooseColor(&(chooseColorStruct)) != 0;
149
150 // Try to highlight the correct window (the parent)
151 HWND hWndParent = 0;
152 if (GetParent())
153 {
154 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.custColours[i], custColours[i]);
164 }
165
166 wxRGBToColour(m_colourData.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 != -1 )
202 m_pos.x = x;
203
204 if ( y != -1 )
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