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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "colordlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/colour.h"
35 #include "wx/gdicmn.h"
37 #include "wx/dialog.h"
40 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
42 #include "wx/msw/private.h"
43 #include "wx/colordlg.h"
44 #include "wx/cmndata.h"
46 #include "wx/msw/wrapcdlg.h"
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
57 // ============================================================================
59 // ============================================================================
61 // ----------------------------------------------------------------------------
62 // colour dialog hook proc
63 // ----------------------------------------------------------------------------
66 wxColourDialogHookProc(HWND hwnd
,
68 WPARAM
WXUNUSED(wParam
),
71 if ( uiMsg
== WM_INITDIALOG
)
73 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
74 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
76 ::SetWindowText(hwnd
, dialog
->GetTitle());
78 wxPoint pos
= dialog
->GetPosition();
79 if ( pos
!= wxDefaultPosition
)
81 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
83 SWP_NOSIZE
| SWP_NOZORDER
);
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 wxColourDialog::wxColourDialog()
96 m_pos
= wxDefaultPosition
;
99 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
101 m_pos
= wxDefaultPosition
;
103 Create(parent
, data
);
106 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
110 m_colourData
= *data
;
115 int wxColourDialog::ShowModal()
117 CHOOSECOLOR chooseColorStruct
;
118 COLORREF custColours
[16];
119 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
122 for (i
= 0; i
< 16; i
++)
124 if (m_colourData
.m_custColours
[i
].Ok())
125 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
127 custColours
[i
] = RGB(255,255,255);
130 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
132 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
133 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
134 chooseColorStruct
.lpCustColors
= custColours
;
136 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
137 chooseColorStruct
.lCustData
= (LPARAM
)this;
138 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
140 if (m_colourData
.GetChooseFull())
141 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
143 // Do the modal dialog
144 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
146 // Try to highlight the correct window (the parent)
149 HWND hWndParent
= (HWND
) GetParent()->GetHWND();
151 ::BringWindowToTop(hWndParent
);
156 for (i
= 0; i
< 16; i
++)
158 wxRGBToColour(m_colourData
.m_custColours
[i
], custColours
[i
]);
161 wxRGBToColour(m_colourData
.m_dataColour
, chooseColorStruct
.rgbResult
);
163 return success
? wxID_OK
: wxID_CANCEL
;
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 void wxColourDialog::SetTitle(const wxString
& title
)
175 wxString
wxColourDialog::GetTitle() const
180 // ----------------------------------------------------------------------------
182 // ----------------------------------------------------------------------------
184 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
192 void wxColourDialog::DoSetSize(int x
, int y
,
193 int WXUNUSED(width
), int WXUNUSED(height
),
194 int WXUNUSED(sizeFlags
))
196 if ( x
!= wxDefaultCoord
)
199 if ( y
!= wxDefaultCoord
)
202 // ignore the size params - we can't change the size of a standard dialog
206 // NB: of course, both of these functions are completely bogus, but it's better
208 void wxColourDialog::DoGetSize(int *width
, int *height
) const
210 // the standard dialog size
217 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
219 // the standard dialog size
226 #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)