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 && !wxUSE_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
++)
131 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
133 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
135 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
136 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
137 chooseColorStruct
.lpCustColors
= custColours
;
139 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
140 chooseColorStruct
.lCustData
= (LPARAM
)this;
141 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
143 if (m_colourData
.GetChooseFull())
144 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
146 // Do the modal dialog
147 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
149 // Try to highlight the correct window (the parent)
153 hWndParent
= (HWND
) GetParent()->GetHWND();
155 ::BringWindowToTop(hWndParent
);
160 for (i
= 0; i
< 16; i
++)
162 wxRGBToColour(m_colourData
.m_custColours
[i
], custColours
[i
]);
165 wxRGBToColour(m_colourData
.m_dataColour
, chooseColorStruct
.rgbResult
);
167 return success
? wxID_OK
: wxID_CANCEL
;
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
174 void wxColourDialog::SetTitle(const wxString
& title
)
179 wxString
wxColourDialog::GetTitle() const
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
196 void wxColourDialog::DoSetSize(int x
, int y
,
197 int WXUNUSED(width
), int WXUNUSED(height
),
198 int WXUNUSED(sizeFlags
))
206 // ignore the size params - we can't change the size of a standard dialog
210 // NB: of course, both of these functions are completely bogus, but it's better
212 void wxColourDialog::DoGetSize(int *width
, int *height
) const
214 // the standard dialog size
221 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
223 // the standard dialog size