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