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"
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 #if !USE_SHARED_LIBRARY
55 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
62 wxColourDialog::wxColourDialog(void)
64 m_dialogParent
= NULL
;
67 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
72 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
74 m_dialogParent
= parent
;
81 int wxColourDialog::ShowModal(void)
83 CHOOSECOLOR chooseColorStruct
;
84 COLORREF custColours
[16];
85 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
88 for (i
= 0; i
< 16; i
++)
89 custColours
[i
] = RGB(m_colourData
.custColours
[i
].Red(), m_colourData
.custColours
[i
].Green(), m_colourData
.custColours
[i
].Blue());
91 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
92 chooseColorStruct
.hwndOwner
= (HWND
) (m_dialogParent
? (HWND
) m_dialogParent
->GetHWND() : NULL
);
93 chooseColorStruct
.rgbResult
= RGB(m_colourData
.dataColour
.Red(), m_colourData
.dataColour
.Green(), m_colourData
.dataColour
.Blue());
94 chooseColorStruct
.lpCustColors
= custColours
;
96 chooseColorStruct
.Flags
= CC_RGBINIT
;
98 if (!m_colourData
.GetChooseFull())
99 chooseColorStruct
.Flags
|= CC_PREVENTFULLOPEN
;
101 // Do the modal dialog
102 bool success
= (ChooseColor(&(chooseColorStruct
)) != 0);
104 // Try to highlight the correct window (the parent)
108 hWndParent
= (HWND
) GetParent()->GetHWND();
110 ::BringWindowToTop(hWndParent
);
115 for (i
= 0; i
< 16; i
++)
117 m_colourData
.custColours
[i
].Set(GetRValue(custColours
[i
]), GetGValue(custColours
[i
]),
118 GetBValue(custColours
[i
]));
121 m_colourData
.dataColour
.Set(GetRValue(chooseColorStruct
.rgbResult
), GetGValue(chooseColorStruct
.rgbResult
),
122 GetBValue(chooseColorStruct
.rgbResult
));
124 return success
? wxID_OK
: wxID_CANCEL
;