]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
Clean-up, speed-up and bug-fix for wxListCtrl drawing,
[wxWidgets.git] / src / msw / colordlg.cpp
CommitLineData
2bda0e17
KB
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"
2432b92d 26#include "wx/bitmap.h"
2bda0e17
KB
27#include "wx/pen.h"
28#include "wx/brush.h"
2432b92d 29#include "wx/colour.h"
2bda0e17
KB
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
4286a5b5 39#if !defined(__WIN32__) || defined(__SALFORDC__) || defined(__WXWINE__)
2bda0e17
KB
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
2bda0e17 54IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
2bda0e17
KB
55
56/*
57 * wxColourDialog
58 */
59
60wxColourDialog::wxColourDialog(void)
61{
bbcdf8bc 62 m_dialogParent = NULL;
2bda0e17
KB
63}
64
65wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
66{
67 Create(parent, data);
68}
69
70bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
71{
bbcdf8bc
JS
72 m_dialogParent = parent;
73
2bda0e17 74 if (data)
bbcdf8bc 75 m_colourData = *data;
2bda0e17
KB
76 return TRUE;
77}
78
79int 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++)
bbcdf8bc 87 custColours[i] = RGB(m_colourData.custColours[i].Red(), m_colourData.custColours[i].Green(), m_colourData.custColours[i].Blue());
2bda0e17
KB
88
89 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
57c208c5 90 chooseColorStruct.hwndOwner = (HWND) (m_dialogParent ? (HWND) m_dialogParent->GetHWND() : (HWND) NULL);
bbcdf8bc 91 chooseColorStruct.rgbResult = RGB(m_colourData.dataColour.Red(), m_colourData.dataColour.Green(), m_colourData.dataColour.Blue());
2bda0e17
KB
92 chooseColorStruct.lpCustColors = custColours;
93
94 chooseColorStruct.Flags = CC_RGBINIT;
95
bbcdf8bc 96 if (!m_colourData.GetChooseFull())
2bda0e17
KB
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 {
bbcdf8bc 115 m_colourData.custColours[i].Set(GetRValue(custColours[i]), GetGValue(custColours[i]),
2bda0e17
KB
116 GetBValue(custColours[i]));
117 }
118
bbcdf8bc 119 m_colourData.dataColour.Set(GetRValue(chooseColorStruct.rgbResult), GetGValue(chooseColorStruct.rgbResult),
2bda0e17
KB
120 GetBValue(chooseColorStruct.rgbResult));
121
122 return success ? wxID_OK : wxID_CANCEL;
123}
124