]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/colordlg.cpp
Clean up memory if have to exit early
[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 and Markus Holzem
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#include <windows.h>
46
47#if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
48 #include <commdlg.h>
49#endif
50
51#include "wx/msw/private.h"
52#include "wx/colordlg.h"
53#include "wx/cmndata.h"
54
55#include <math.h>
56#include <stdlib.h>
57#include <string.h>
58
59// ----------------------------------------------------------------------------
60// wxWin macros
61// ----------------------------------------------------------------------------
62
63IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
64
65// ============================================================================
66// implementation
67// ============================================================================
68
69// ----------------------------------------------------------------------------
70// colour dialog hook proc
71// ----------------------------------------------------------------------------
72
73UINT 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
101wxColourDialog::wxColourDialog()
102{
103 m_pos = wxDefaultPosition;
104}
105
106wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
107{
108 m_pos = wxDefaultPosition;
109
110 Create(parent, data);
111}
112
113bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
114{
115 m_parent = parent;
116 if (data)
117 m_colourData = *data;
118
119 return TRUE;
120}
121
122int 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.custColours[i]);
131
132 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
133 if ( m_parent )
134 chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
135 chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.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.custColours[i], custColours[i]);
162 }
163
164 wxRGBToColour(m_colourData.dataColour, chooseColorStruct.rgbResult);
165
166 return success ? wxID_OK : wxID_CANCEL;
167}
168
169// ----------------------------------------------------------------------------
170// title
171// ----------------------------------------------------------------------------
172
173void wxColourDialog::SetTitle(const wxString& title)
174{
175 m_title = title;
176}
177
178wxString wxColourDialog::GetTitle() const
179{
180 return m_title;
181}
182
183// ----------------------------------------------------------------------------
184// position/size
185// ----------------------------------------------------------------------------
186
187void 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
195void 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
211void 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
220void 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