1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxColourDialog class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "colordlg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/bitmap.h"
29 #include "wx/colour.h"
30 #include "wx/gdicmn.h"
33 #include "wx/dialog.h"
34 #include "wx/msgdlg.h"
39 #if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
43 #include "wx/msw/private.h"
44 #include "wx/colordlg.h"
45 #include "wx/cmndata.h"
51 #define wxDIALOG_DEFAULT_X 300
52 #define wxDIALOG_DEFAULT_Y 300
54 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
60 wxColourDialog::wxColourDialog(void)
62 m_dialogParent
= NULL
;
65 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
70 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
72 m_dialogParent
= parent
;
79 int wxColourDialog::ShowModal(void)
81 CHOOSECOLOR chooseColorStruct
;
82 COLORREF custColours
[16];
83 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
86 for (i
= 0; i
< 16; i
++)
87 custColours
[i
] = RGB(m_colourData
.custColours
[i
].Red(), m_colourData
.custColours
[i
].Green(), m_colourData
.custColours
[i
].Blue());
89 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
90 chooseColorStruct
.hwndOwner
= (HWND
) (m_dialogParent
? (HWND
) m_dialogParent
->GetHWND() : (HWND
) NULL
);
91 chooseColorStruct
.rgbResult
= RGB(m_colourData
.dataColour
.Red(), m_colourData
.dataColour
.Green(), m_colourData
.dataColour
.Blue());
92 chooseColorStruct
.lpCustColors
= custColours
;
94 chooseColorStruct
.Flags
= CC_RGBINIT
;
96 if (!m_colourData
.GetChooseFull())
97 chooseColorStruct
.Flags
|= CC_PREVENTFULLOPEN
;
99 // Do the modal dialog
100 bool success
= (ChooseColor(&(chooseColorStruct
)) != 0);
102 // Try to highlight the correct window (the parent)
106 hWndParent
= (HWND
) GetParent()->GetHWND();
108 ::BringWindowToTop(hWndParent
);
113 for (i
= 0; i
< 16; i
++)
115 m_colourData
.custColours
[i
].Set(GetRValue(custColours
[i
]), GetGValue(custColours
[i
]),
116 GetBValue(custColours
[i
]));
119 m_colourData
.dataColour
.Set(GetRValue(chooseColorStruct
.rgbResult
), GetGValue(chooseColorStruct
.rgbResult
),
120 GetBValue(chooseColorStruct
.rgbResult
));
122 return success
? wxID_OK
: wxID_CANCEL
;