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 // ----------------------------------------------------------------------------
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"
49 #include "wx/msw/private.h"
50 #include "wx/colordlg.h"
51 #include "wx/cmndata.h"
53 #if !defined(__WIN32__) || defined(__WXWINCE__)
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
67 // ============================================================================
69 // ============================================================================
71 // ----------------------------------------------------------------------------
72 // colour dialog hook proc
73 // ----------------------------------------------------------------------------
75 UINT CALLBACK
wxColourDialogHookProc(HWND hwnd
,
77 WPARAM
WXUNUSED(wParam
),
80 if ( uiMsg
== WM_INITDIALOG
)
82 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
83 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
85 ::SetWindowText(hwnd
, dialog
->GetTitle());
87 wxPoint pos
= dialog
->GetPosition();
88 if ( pos
!= wxDefaultPosition
)
90 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
92 SWP_NOSIZE
| SWP_NOZORDER
);
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 wxColourDialog::wxColourDialog()
105 m_pos
= wxDefaultPosition
;
108 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
110 m_pos
= wxDefaultPosition
;
112 Create(parent
, data
);
115 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
119 m_colourData
= *data
;
124 int wxColourDialog::ShowModal()
126 CHOOSECOLOR chooseColorStruct
;
127 COLORREF custColours
[16];
128 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
131 for (i
= 0; i
< 16; i
++)
132 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
134 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
136 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
137 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
138 chooseColorStruct
.lpCustColors
= custColours
;
140 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
141 chooseColorStruct
.lCustData
= (LPARAM
)this;
142 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
144 if (m_colourData
.GetChooseFull())
145 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
147 // Do the modal dialog
148 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
150 // Try to highlight the correct window (the parent)
154 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
))
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