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"
28 #include "wx/gdicmn.h"
31 #include "wx/dialog.h"
32 #include "wx/msgdlg.h"
41 #include "wx/msw/private.h"
42 #include "wx/colordlg.h"
43 #include "wx/cmndata.h"
49 #define wxDIALOG_DEFAULT_X 300
50 #define wxDIALOG_DEFAULT_Y 300
52 #if !USE_SHARED_LIBRARY
53 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() : 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
;