]>
Commit | Line | Data |
---|---|---|
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 | ||
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 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 | ||
86 | return 0; | |
87 | } | |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // wxColourDialog | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | wxColourDialog::wxColourDialog() | |
94 | { | |
95 | } | |
96 | ||
97 | wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data) | |
98 | { | |
99 | Create(parent, data); | |
100 | } | |
101 | ||
102 | bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) | |
103 | { | |
104 | m_parent = parent; | |
105 | if (data) | |
106 | m_colourData = *data; | |
107 | ||
108 | return TRUE; | |
109 | } | |
110 | ||
111 | int wxColourDialog::ShowModal() | |
112 | { | |
113 | CHOOSECOLOR chooseColorStruct; | |
114 | COLORREF custColours[16]; | |
115 | memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR)); | |
116 | ||
117 | int i; | |
118 | for (i = 0; i < 16; i++) | |
119 | custColours[i] = wxColourToRGB(m_colourData.custColours[i]); | |
120 | ||
121 | chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR); | |
122 | if ( m_parent ) | |
123 | chooseColorStruct.hwndOwner = GetHwndOf(m_parent); | |
124 | chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.dataColour); | |
125 | chooseColorStruct.lpCustColors = custColours; | |
126 | ||
127 | chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK; | |
128 | chooseColorStruct.lCustData = (LPARAM)this; | |
129 | chooseColorStruct.lpfnHook = wxColourDialogHookProc; | |
130 | ||
131 | if (!m_colourData.GetChooseFull()) | |
132 | chooseColorStruct.Flags |= CC_PREVENTFULLOPEN; | |
133 | ||
134 | // Do the modal dialog | |
135 | bool success = ::ChooseColor(&(chooseColorStruct)) != 0; | |
136 | ||
137 | // Try to highlight the correct window (the parent) | |
138 | HWND hWndParent = 0; | |
139 | if (GetParent()) | |
140 | { | |
141 | hWndParent = (HWND) GetParent()->GetHWND(); | |
142 | if (hWndParent) | |
143 | ::BringWindowToTop(hWndParent); | |
144 | } | |
145 | ||
146 | ||
147 | // Restore values | |
148 | for (i = 0; i < 16; i++) | |
149 | { | |
150 | wxRGBToColour(m_colourData.custColours[i], custColours[i]); | |
151 | } | |
152 | ||
153 | wxRGBToColour(m_colourData.dataColour, chooseColorStruct.rgbResult); | |
154 | ||
155 | return success ? wxID_OK : wxID_CANCEL; | |
156 | } | |
157 | ||
158 | // ---------------------------------------------------------------------------- | |
159 | // title | |
160 | // ---------------------------------------------------------------------------- | |
161 | ||
162 | void wxColourDialog::SetTitle(const wxString& title) | |
163 | { | |
164 | m_title = title; | |
165 | } | |
166 | ||
167 | wxString wxColourDialog::GetTitle() | |
168 | { | |
169 | return m_title; | |
170 | } | |
171 | ||
172 | // ---------------------------------------------------------------------------- | |
173 | // position/size | |
174 | // ---------------------------------------------------------------------------- | |
175 | ||
176 | void wxColourDialog::DoSetSize(int WXUNUSED(x), int WXUNUSED(y), | |
177 | int WXUNUSED(width), int WXUNUSED(height), | |
178 | int WXUNUSED(sizeFlags)) | |
179 | { | |
180 | // ignore - we can't change the size of this standard dialog | |
181 | return; | |
182 | } | |
183 | ||
184 | // NB: of course, both of these functions are completely bogus, but it's better | |
185 | // than nothing | |
186 | void wxColourDialog::DoGetSize(int *width, int *height) const | |
187 | { | |
188 | // the standard dialog size | |
189 | if ( width ) | |
190 | *width = 225; | |
191 | if ( height ) | |
192 | *height = 324; | |
193 | } | |
194 | ||
195 | void wxColourDialog::DoGetClientSize(int *width, int *height) const | |
196 | { | |
197 | // the standard dialog size | |
198 | if ( width ) | |
199 | *width = 219; | |
200 | if ( height ) | |
201 | *height = 299; | |
202 | } |