]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
In wxApp::OnIdle() check to see if there is not a current menubar and if
[wxWidgets.git] / src / msw / colordlg.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
f6bcfd97 2// Name: src/msw/colordlg.cpp
2bda0e17
KB
3// Purpose: wxColourDialog class
4// Author: Julian Smart
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
f6bcfd97 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
f6bcfd97
BP
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
f6bcfd97 21 #pragma implementation "colordlg.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
f6bcfd97 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
f6bcfd97
BP
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"
2bda0e17
KB
43#endif
44
adf9e099
VZ
45#if wxUSE_COLOURDLG
46
2bda0e17
KB
47#include <windows.h>
48
b4da152e 49#if !defined(__WIN32__) || defined(__SALFORDC__)
f6bcfd97 50 #include <commdlg.h>
2bda0e17
KB
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
f6bcfd97
BP
61// ----------------------------------------------------------------------------
62// wxWin macros
63// ----------------------------------------------------------------------------
2bda0e17 64
2bda0e17 65IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
2bda0e17 66
f6bcfd97
BP
67// ============================================================================
68// implementation
69// ============================================================================
70
71// ----------------------------------------------------------------------------
72// colour dialog hook proc
73// ----------------------------------------------------------------------------
74
75UINT CALLBACK wxColourDialogHookProc(HWND hwnd,
76 UINT uiMsg,
33ac7e6f 77 WPARAM WXUNUSED(wParam),
f6bcfd97
BP
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());
f63e3ebb
VZ
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 }
f6bcfd97
BP
94 }
95
96 return 0;
97}
98
99// ----------------------------------------------------------------------------
100// wxColourDialog
101// ----------------------------------------------------------------------------
2bda0e17 102
f6bcfd97 103wxColourDialog::wxColourDialog()
2bda0e17 104{
f63e3ebb 105 m_pos = wxDefaultPosition;
2bda0e17
KB
106}
107
108wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
109{
f63e3ebb
VZ
110 m_pos = wxDefaultPosition;
111
f6bcfd97 112 Create(parent, data);
2bda0e17
KB
113}
114
115bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
116{
f6bcfd97
BP
117 m_parent = parent;
118 if (data)
119 m_colourData = *data;
bbcdf8bc 120
f6bcfd97 121 return TRUE;
2bda0e17
KB
122}
123
f6bcfd97 124int wxColourDialog::ShowModal()
2bda0e17
KB
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++)
f6bcfd97 132 custColours[i] = wxColourToRGB(m_colourData.custColours[i]);
2bda0e17
KB
133
134 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
f6bcfd97
BP
135 if ( m_parent )
136 chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
137 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.dataColour);
2bda0e17
KB
138 chooseColorStruct.lpCustColors = custColours;
139
f6bcfd97
BP
140 chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
141 chooseColorStruct.lCustData = (LPARAM)this;
142 chooseColorStruct.lpfnHook = wxColourDialogHookProc;
2bda0e17 143
cf75c1b4
RD
144 if (m_colourData.GetChooseFull())
145 chooseColorStruct.Flags |= CC_FULLOPEN;
2bda0e17
KB
146
147 // Do the modal dialog
f6bcfd97 148 bool success = ::ChooseColor(&(chooseColorStruct)) != 0;
2bda0e17
KB
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 {
f6bcfd97 163 wxRGBToColour(m_colourData.custColours[i], custColours[i]);
2bda0e17
KB
164 }
165
f6bcfd97 166 wxRGBToColour(m_colourData.dataColour, chooseColorStruct.rgbResult);
2bda0e17
KB
167
168 return success ? wxID_OK : wxID_CANCEL;
169}
170
f6bcfd97
BP
171// ----------------------------------------------------------------------------
172// title
173// ----------------------------------------------------------------------------
174
175void wxColourDialog::SetTitle(const wxString& title)
176{
177 m_title = title;
178}
179
ba14d986 180wxString wxColourDialog::GetTitle() const
f6bcfd97
BP
181{
182 return m_title;
183}
184
185// ----------------------------------------------------------------------------
186// position/size
187// ----------------------------------------------------------------------------
188
f63e3ebb
VZ
189void 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
197void wxColourDialog::DoSetSize(int x, int y,
f6bcfd97
BP
198 int WXUNUSED(width), int WXUNUSED(height),
199 int WXUNUSED(sizeFlags))
200{
f63e3ebb
VZ
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
f6bcfd97
BP
208 return;
209}
210
211// NB: of course, both of these functions are completely bogus, but it's better
212// than nothing
213void 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
222void 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}
f63e3ebb 230
adf9e099 231#endif