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