1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/colordlg.cpp
3 // Purpose: wxColourDialog class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "colordlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/bitmap.h"
37 #include "wx/colour.h"
38 #include "wx/gdicmn.h"
41 #include "wx/dialog.h"
42 #include "wx/msgdlg.h"
47 #if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
51 #include "wx/msw/private.h"
52 #include "wx/colordlg.h"
53 #include "wx/cmndata.h"
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
65 // ============================================================================
67 // ============================================================================
69 // ----------------------------------------------------------------------------
70 // colour dialog hook proc
71 // ----------------------------------------------------------------------------
73 UINT CALLBACK
wxColourDialogHookProc(HWND hwnd
,
75 WPARAM
WXUNUSED(wParam
),
78 if ( uiMsg
== WM_INITDIALOG
)
80 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
81 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
83 ::SetWindowText(hwnd
, dialog
->GetTitle());
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 wxColourDialog::wxColourDialog()
97 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
102 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
106 m_colourData
= *data
;
111 int wxColourDialog::ShowModal()
113 CHOOSECOLOR chooseColorStruct
;
114 COLORREF custColours
[16];
115 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
118 for (i
= 0; i
< 16; i
++)
119 custColours
[i
] = wxColourToRGB(m_colourData
.custColours
[i
]);
121 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
123 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
124 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.dataColour
);
125 chooseColorStruct
.lpCustColors
= custColours
;
127 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
128 chooseColorStruct
.lCustData
= (LPARAM
)this;
129 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
131 if (m_colourData
.GetChooseFull())
132 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
134 // Do the modal dialog
135 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
137 // Try to highlight the correct window (the parent)
141 hWndParent
= (HWND
) GetParent()->GetHWND();
143 ::BringWindowToTop(hWndParent
);
148 for (i
= 0; i
< 16; i
++)
150 wxRGBToColour(m_colourData
.custColours
[i
], custColours
[i
]);
153 wxRGBToColour(m_colourData
.dataColour
, chooseColorStruct
.rgbResult
);
155 return success
? wxID_OK
: wxID_CANCEL
;
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
162 void wxColourDialog::SetTitle(const wxString
& title
)
167 wxString
wxColourDialog::GetTitle()
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 void wxColourDialog::DoSetSize(int WXUNUSED(x
), int WXUNUSED(y
),
177 int WXUNUSED(width
), int WXUNUSED(height
),
178 int WXUNUSED(sizeFlags
))
180 // ignore - we can't change the size of this standard dialog
184 // NB: of course, both of these functions are completely bogus, but it's better
186 void wxColourDialog::DoGetSize(int *width
, int *height
) const
188 // the standard dialog size
195 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
197 // the standard dialog size