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"
27 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
29 #include "wx/colordlg.h"
32 #include "wx/msw/wrapcdlg.h"
34 #include "wx/colour.h"
35 #include "wx/gdicmn.h"
37 #include "wx/dialog.h"
38 #include "wx/cmndata.h"
42 #include "wx/msw/private.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
58 // colour dialog hook proc
59 // ----------------------------------------------------------------------------
62 wxColourDialogHookProc(HWND hwnd
,
64 WPARAM
WXUNUSED(wParam
),
67 if ( uiMsg
== WM_INITDIALOG
)
69 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
70 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
72 const wxString title
= dialog
->GetTitle();
74 ::SetWindowText(hwnd
, title
.wx_str());
76 wxPoint pos
= dialog
->GetPosition();
77 if ( pos
!= wxDefaultPosition
)
79 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
81 SWP_NOSIZE
| SWP_NOZORDER
);
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 wxColourDialog::wxColourDialog()
94 m_pos
= wxDefaultPosition
;
97 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
99 m_pos
= wxDefaultPosition
;
101 Create(parent
, data
);
104 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
108 m_colourData
= *data
;
113 int wxColourDialog::ShowModal()
115 CHOOSECOLOR chooseColorStruct
;
116 COLORREF custColours
[16];
117 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
120 for (i
= 0; i
< 16; i
++)
122 if (m_colourData
.m_custColours
[i
].Ok())
123 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
125 custColours
[i
] = RGB(255,255,255);
128 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
130 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
131 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
132 chooseColorStruct
.lpCustColors
= custColours
;
134 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
135 chooseColorStruct
.lCustData
= (LPARAM
)this;
136 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
138 if (m_colourData
.GetChooseFull())
139 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
141 // Do the modal dialog
142 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
144 // Try to highlight the correct window (the parent)
147 HWND hWndParent
= (HWND
) GetParent()->GetHWND();
149 ::BringWindowToTop(hWndParent
);
154 for (i
= 0; i
< 16; i
++)
156 wxRGBToColour(m_colourData
.m_custColours
[i
], custColours
[i
]);
159 wxRGBToColour(m_colourData
.m_dataColour
, chooseColorStruct
.rgbResult
);
161 return success
? wxID_OK
: wxID_CANCEL
;
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 void wxColourDialog::SetTitle(const wxString
& title
)
173 wxString
wxColourDialog::GetTitle() const
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
182 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
190 void wxColourDialog::DoSetSize(int x
, int y
,
191 int WXUNUSED(width
), int WXUNUSED(height
),
192 int WXUNUSED(sizeFlags
))
194 if ( x
!= wxDefaultCoord
)
197 if ( y
!= wxDefaultCoord
)
200 // ignore the size params - we can't change the size of a standard dialog
204 // NB: of course, both of these functions are completely bogus, but it's better
206 void wxColourDialog::DoGetSize(int *width
, int *height
) const
208 // the standard dialog size
215 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
217 // the standard dialog size
224 #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)