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