]> git.saurik.com Git - wxWidgets.git/blob - src/msw/colordlg.cpp
fixed the vsprintf() problem once and for all
[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/pen.h"
27 #include "wx/brush.h"
28 #include "wx/gdicmn.h"
29 #include "wx/utils.h"
30 #include "wx/frame.h"
31 #include "wx/dialog.h"
32 #include "wx/msgdlg.h"
33 #endif
34
35 #include <windows.h>
36
37 #ifndef __WIN32__
38 #include <commdlg.h>
39 #endif
40
41 #include "wx/msw/private.h"
42 #include "wx/colordlg.h"
43 #include "wx/cmndata.h"
44
45 #include <math.h>
46 #include <stdlib.h>
47 #include <string.h>
48
49 #define wxDIALOG_DEFAULT_X 300
50 #define wxDIALOG_DEFAULT_Y 300
51
52 #if !USE_SHARED_LIBRARY
53 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
54 #endif
55
56 /*
57 * wxColourDialog
58 */
59
60 wxColourDialog::wxColourDialog(void)
61 {
62 m_dialogParent = NULL;
63 }
64
65 wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
66 {
67 Create(parent, data);
68 }
69
70 bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
71 {
72 m_dialogParent = parent;
73
74 if (data)
75 m_colourData = *data;
76 return TRUE;
77 }
78
79 int wxColourDialog::ShowModal(void)
80 {
81 CHOOSECOLOR chooseColorStruct;
82 COLORREF custColours[16];
83 memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
84
85 int i;
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());
88
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;
93
94 chooseColorStruct.Flags = CC_RGBINIT;
95
96 if (!m_colourData.GetChooseFull())
97 chooseColorStruct.Flags |= CC_PREVENTFULLOPEN;
98
99 // Do the modal dialog
100 bool success = (ChooseColor(&(chooseColorStruct)) != 0);
101
102 // Try to highlight the correct window (the parent)
103 HWND hWndParent = 0;
104 if (GetParent())
105 {
106 hWndParent = (HWND) GetParent()->GetHWND();
107 if (hWndParent)
108 ::BringWindowToTop(hWndParent);
109 }
110
111
112 // Restore values
113 for (i = 0; i < 16; i++)
114 {
115 m_colourData.custColours[i].Set(GetRValue(custColours[i]), GetGValue(custColours[i]),
116 GetBValue(custColours[i]));
117 }
118
119 m_colourData.dataColour.Set(GetRValue(chooseColorStruct.rgbResult), GetGValue(chooseColorStruct.rgbResult),
120 GetBValue(chooseColorStruct.rgbResult));
121
122 return success ? wxID_OK : wxID_CANCEL;
123 }
124