]> git.saurik.com Git - wxWidgets.git/blob - src/msw/colordlg.cpp
Soem corrections for SetSize changes
[wxWidgets.git] / src / msw / colordlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: colordlg.cpp
3 // Purpose: wxColourDialog class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "colordlg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <stdio.h>
25 #include "wx/defs.h"
26 #include "wx/bitmap.h"
27 #include "wx/pen.h"
28 #include "wx/brush.h"
29 #include "wx/colour.h"
30 #include "wx/gdicmn.h"
31 #include "wx/utils.h"
32 #include "wx/frame.h"
33 #include "wx/dialog.h"
34 #include "wx/msgdlg.h"
35 #endif
36
37 #include <windows.h>
38
39 #if !defined(__WIN32__) || defined(__SALFORDC__)
40 #include <commdlg.h>
41 #endif
42
43 #include "wx/msw/private.h"
44 #include "wx/colordlg.h"
45 #include "wx/cmndata.h"
46
47 #include <math.h>
48 #include <stdlib.h>
49 #include <string.h>
50
51 #define wxDIALOG_DEFAULT_X 300
52 #define wxDIALOG_DEFAULT_Y 300
53
54 #if !USE_SHARED_LIBRARY
55 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
56 #endif
57
58 /*
59 * wxColourDialog
60 */
61
62 wxColourDialog::wxColourDialog(void)
63 {
64 m_dialogParent = NULL;
65 }
66
67 wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
68 {
69 Create(parent, data);
70 }
71
72 bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
73 {
74 m_dialogParent = parent;
75
76 if (data)
77 m_colourData = *data;
78 return TRUE;
79 }
80
81 int wxColourDialog::ShowModal(void)
82 {
83 CHOOSECOLOR chooseColorStruct;
84 COLORREF custColours[16];
85 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
86
87 int i;
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());
90
91 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
92 chooseColorStruct.hwndOwner = (HWND) (m_dialogParent ? (HWND) m_dialogParent->GetHWND() : (HWND) NULL);
93 chooseColorStruct.rgbResult = RGB(m_colourData.dataColour.Red(), m_colourData.dataColour.Green(), m_colourData.dataColour.Blue());
94 chooseColorStruct.lpCustColors = custColours;
95
96 chooseColorStruct.Flags = CC_RGBINIT;
97
98 if (!m_colourData.GetChooseFull())
99 chooseColorStruct.Flags |= CC_PREVENTFULLOPEN;
100
101 // Do the modal dialog
102 bool success = (ChooseColor(&(chooseColorStruct)) != 0);
103
104 // Try to highlight the correct window (the parent)
105 HWND hWndParent = 0;
106 if (GetParent())
107 {
108 hWndParent = (HWND) GetParent()->GetHWND();
109 if (hWndParent)
110 ::BringWindowToTop(hWndParent);
111 }
112
113
114 // Restore values
115 for (i = 0; i < 16; i++)
116 {
117 m_colourData.custColours[i].Set(GetRValue(custColours[i]), GetGValue(custColours[i]),
118 GetBValue(custColours[i]));
119 }
120
121 m_colourData.dataColour.Set(GetRValue(chooseColorStruct.rgbResult), GetGValue(chooseColorStruct.rgbResult),
122 GetBValue(chooseColorStruct.rgbResult));
123
124 return success ? wxID_OK : wxID_CANCEL;
125 }
126