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__)
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());
85 wxPoint pos
= dialog
->GetPosition();
86 if ( pos
!= wxDefaultPosition
)
88 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
90 SWP_NOSIZE
| SWP_NOZORDER
);
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 wxColourDialog::wxColourDialog()
103 m_pos
= wxDefaultPosition
;
106 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
108 m_pos
= wxDefaultPosition
;
110 Create(parent
, data
);
113 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
117 m_colourData
= *data
;
122 int wxColourDialog::ShowModal()
124 CHOOSECOLOR chooseColorStruct
;
125 COLORREF custColours
[16];
126 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
129 for (i
= 0; i
< 16; i
++)
130 custColours
[i
] = wxColourToRGB(m_colourData
.custColours
[i
]);
132 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
134 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
135 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.dataColour
);
136 chooseColorStruct
.lpCustColors
= custColours
;
138 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
139 chooseColorStruct
.lCustData
= (LPARAM
)this;
140 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
142 if (m_colourData
.GetChooseFull())
143 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
145 // Do the modal dialog
146 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
148 // Try to highlight the correct window (the parent)
152 hWndParent
= (HWND
) GetParent()->GetHWND();
154 ::BringWindowToTop(hWndParent
);
159 for (i
= 0; i
< 16; i
++)
161 wxRGBToColour(m_colourData
.custColours
[i
], custColours
[i
]);
164 wxRGBToColour(m_colourData
.dataColour
, chooseColorStruct
.rgbResult
);
166 return success
? wxID_OK
: wxID_CANCEL
;
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
173 void wxColourDialog::SetTitle(const wxString
& title
)
178 wxString
wxColourDialog::GetTitle() const
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
195 void wxColourDialog::DoSetSize(int x
, int y
,
196 int WXUNUSED(width
), int WXUNUSED(height
),
197 int WXUNUSED(sizeFlags
))
205 // ignore the size params - we can't change the size of a standard dialog
209 // NB: of course, both of these functions are completely bogus, but it's better
211 void wxColourDialog::DoGetSize(int *width
, int *height
) const
213 // the standard dialog size
220 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
222 // the standard dialog size