]> git.saurik.com Git - wxWidgets.git/blob - src/msw/colordlg.cpp
Fixed wxWindow::HandleCommand so multiple toolbars work again (e.g. ogl/studio sample);
[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__) || defined(__WXWINE__)
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 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
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() : (HWND) 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