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__)
47 #include "wx/msw/private.h"
48 #include "wx/colordlg.h"
49 #include "wx/cmndata.h"
51 #if !defined(__WIN32__) || defined(__WXWINCE__)
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
65 // ============================================================================
67 // ============================================================================
69 // ----------------------------------------------------------------------------
70 // colour dialog hook proc
71 // ----------------------------------------------------------------------------
74 wxColourDialogHookProc(HWND hwnd
,
76 WPARAM
WXUNUSED(wParam
),
79 if ( uiMsg
== WM_INITDIALOG
)
81 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
82 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
84 ::SetWindowText(hwnd
, dialog
->GetTitle());
86 wxPoint pos
= dialog
->GetPosition();
87 if ( pos
!= wxDefaultPosition
)
89 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
91 SWP_NOSIZE
| SWP_NOZORDER
);
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 wxColourDialog::wxColourDialog()
104 m_pos
= wxDefaultPosition
;
107 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
109 m_pos
= wxDefaultPosition
;
111 Create(parent
, data
);
114 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
118 m_colourData
= *data
;
123 int wxColourDialog::ShowModal()
125 CHOOSECOLOR chooseColorStruct
;
126 COLORREF custColours
[16];
127 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
130 for (i
= 0; i
< 16; i
++)
132 if (m_colourData
.m_custColours
[i
].Ok())
133 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
135 custColours
[i
] = RGB(255,255,255);
138 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
140 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
141 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
142 chooseColorStruct
.lpCustColors
= custColours
;
144 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
145 chooseColorStruct
.lCustData
= (LPARAM
)this;
146 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
148 if (m_colourData
.GetChooseFull())
149 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
151 // Do the modal dialog
152 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
154 // Try to highlight the correct window (the parent)
157 HWND hWndParent
= (HWND
) GetParent()->GetHWND();
159 ::BringWindowToTop(hWndParent
);
164 for (i
= 0; i
< 16; i
++)
166 wxRGBToColour(m_colourData
.m_custColours
[i
], custColours
[i
]);
169 wxRGBToColour(m_colourData
.m_dataColour
, chooseColorStruct
.rgbResult
);
171 return success
? wxID_OK
: wxID_CANCEL
;
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
178 void wxColourDialog::SetTitle(const wxString
& title
)
183 wxString
wxColourDialog::GetTitle() const
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
192 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
200 void wxColourDialog::DoSetSize(int x
, int y
,
201 int WXUNUSED(width
), int WXUNUSED(height
),
202 int WXUNUSED(sizeFlags
))
210 // ignore the size params - we can't change the size of a standard dialog
214 // NB: of course, both of these functions are completely bogus, but it's better
216 void wxColourDialog::DoGetSize(int *width
, int *height
) const
218 // the standard dialog size
225 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
227 // the standard dialog size