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/bitmap.h"
37 #include "wx/colour.h"
38 #include "wx/gdicmn.h"
41 #include "wx/dialog.h"
42 #include "wx/msgdlg.h"
45 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
47 #include "wx/msw/private.h"
48 #include "wx/colordlg.h"
49 #include "wx/cmndata.h"
51 #include "wx/msw/wrapcdlg.h"
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
62 // ============================================================================
64 // ============================================================================
66 // ----------------------------------------------------------------------------
67 // colour dialog hook proc
68 // ----------------------------------------------------------------------------
71 wxColourDialogHookProc(HWND hwnd
,
73 WPARAM
WXUNUSED(wParam
),
76 if ( uiMsg
== WM_INITDIALOG
)
78 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
79 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
81 ::SetWindowText(hwnd
, dialog
->GetTitle());
83 wxPoint pos
= dialog
->GetPosition();
84 if ( pos
!= wxDefaultPosition
)
86 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
88 SWP_NOSIZE
| SWP_NOZORDER
);
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 wxColourDialog::wxColourDialog()
101 m_pos
= wxDefaultPosition
;
104 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
106 m_pos
= wxDefaultPosition
;
108 Create(parent
, data
);
111 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
115 m_colourData
= *data
;
120 int wxColourDialog::ShowModal()
122 CHOOSECOLOR chooseColorStruct
;
123 COLORREF custColours
[16];
124 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
127 for (i
= 0; i
< 16; i
++)
129 if (m_colourData
.m_custColours
[i
].Ok())
130 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
132 custColours
[i
] = RGB(255,255,255);
135 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
137 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
138 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
139 chooseColorStruct
.lpCustColors
= custColours
;
141 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
142 chooseColorStruct
.lCustData
= (LPARAM
)this;
143 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
145 if (m_colourData
.GetChooseFull())
146 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
148 // Do the modal dialog
149 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
151 // Try to highlight the correct window (the parent)
154 HWND hWndParent
= (HWND
) GetParent()->GetHWND();
156 ::BringWindowToTop(hWndParent
);
161 for (i
= 0; i
< 16; i
++)
163 wxRGBToColour(m_colourData
.m_custColours
[i
], custColours
[i
]);
166 wxRGBToColour(m_colourData
.m_dataColour
, chooseColorStruct
.rgbResult
);
168 return success
? wxID_OK
: wxID_CANCEL
;
171 // ----------------------------------------------------------------------------
173 // ----------------------------------------------------------------------------
175 void wxColourDialog::SetTitle(const wxString
& title
)
180 wxString
wxColourDialog::GetTitle() const
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
197 void wxColourDialog::DoSetSize(int x
, int y
,
198 int WXUNUSED(width
), int WXUNUSED(height
),
199 int WXUNUSED(sizeFlags
))
201 if ( x
!= wxDefaultCoord
)
204 if ( y
!= wxDefaultCoord
)
207 // ignore the size params - we can't change the size of a standard dialog
211 // NB: of course, both of these functions are completely bogus, but it's better
213 void wxColourDialog::DoGetSize(int *width
, int *height
) const
215 // the standard dialog size
222 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
224 // the standard dialog size
231 #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)