1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/colordlg.cpp
3 // Purpose: wxColourDialog class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/colour.h"
30 #include "wx/gdicmn.h"
32 #include "wx/dialog.h"
35 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
37 #include "wx/msw/private.h"
38 #include "wx/colordlg.h"
39 #include "wx/cmndata.h"
41 #include "wx/msw/wrapcdlg.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // colour dialog hook proc
58 // ----------------------------------------------------------------------------
61 wxColourDialogHookProc(HWND hwnd
,
63 WPARAM
WXUNUSED(wParam
),
66 if ( uiMsg
== WM_INITDIALOG
)
68 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
69 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
71 ::SetWindowText(hwnd
, dialog
->GetTitle());
73 wxPoint pos
= dialog
->GetPosition();
74 if ( pos
!= wxDefaultPosition
)
76 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
78 SWP_NOSIZE
| SWP_NOZORDER
);
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 wxColourDialog::wxColourDialog()
91 m_pos
= wxDefaultPosition
;
94 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
96 m_pos
= wxDefaultPosition
;
101 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
105 m_colourData
= *data
;
110 int wxColourDialog::ShowModal()
112 CHOOSECOLOR chooseColorStruct
;
113 COLORREF custColours
[16];
114 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
117 for (i
= 0; i
< 16; i
++)
119 if (m_colourData
.m_custColours
[i
].Ok())
120 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
122 custColours
[i
] = RGB(255,255,255);
125 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
127 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
128 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
129 chooseColorStruct
.lpCustColors
= custColours
;
131 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
132 chooseColorStruct
.lCustData
= (LPARAM
)this;
133 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
135 if (m_colourData
.GetChooseFull())
136 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
138 // Do the modal dialog
139 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
141 // Try to highlight the correct window (the parent)
144 HWND hWndParent
= (HWND
) GetParent()->GetHWND();
146 ::BringWindowToTop(hWndParent
);
151 for (i
= 0; i
< 16; i
++)
153 wxRGBToColour(m_colourData
.m_custColours
[i
], custColours
[i
]);
156 wxRGBToColour(m_colourData
.m_dataColour
, chooseColorStruct
.rgbResult
);
158 return success
? wxID_OK
: wxID_CANCEL
;
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 void wxColourDialog::SetTitle(const wxString
& title
)
170 wxString
wxColourDialog::GetTitle() const
175 // ----------------------------------------------------------------------------
177 // ----------------------------------------------------------------------------
179 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
187 void wxColourDialog::DoSetSize(int x
, int y
,
188 int WXUNUSED(width
), int WXUNUSED(height
),
189 int WXUNUSED(sizeFlags
))
191 if ( x
!= wxDefaultCoord
)
194 if ( y
!= wxDefaultCoord
)
197 // ignore the size params - we can't change the size of a standard dialog
201 // NB: of course, both of these functions are completely bogus, but it's better
203 void wxColourDialog::DoGetSize(int *width
, int *height
) const
205 // the standard dialog size
212 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
214 // the standard dialog size
221 #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)