]> git.saurik.com Git - wxWidgets.git/blame - src/msw/colordlg.cpp
Rename() (partly) implemented for wxRegConf
[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
ce3ed50d 39#if !defined(__WIN32__) || defined(__SALFORDC__)
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
54#if !USE_SHARED_LIBRARY
55IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
56#endif
57
58/*
59 * wxColourDialog
60 */
61
62wxColourDialog::wxColourDialog(void)
63{
bbcdf8bc 64 m_dialogParent = NULL;
2bda0e17
KB
65}
66
67wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
68{
69 Create(parent, data);
70}
71
72bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
73{
bbcdf8bc
JS
74 m_dialogParent = parent;
75
2bda0e17 76 if (data)
bbcdf8bc 77 m_colourData = *data;
2bda0e17
KB
78 return TRUE;
79}
80
81int 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++)
bbcdf8bc 89 custColours[i] = RGB(m_colourData.custColours[i].Red(), m_colourData.custColours[i].Green(), m_colourData.custColours[i].Blue());
2bda0e17
KB
90
91 chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
57c208c5 92 chooseColorStruct.hwndOwner = (HWND) (m_dialogParent ? (HWND) m_dialogParent->GetHWND() : (HWND) NULL);
bbcdf8bc 93 chooseColorStruct.rgbResult = RGB(m_colourData.dataColour.Red(), m_colourData.dataColour.Green(), m_colourData.dataColour.Blue());
2bda0e17
KB
94 chooseColorStruct.lpCustColors = custColours;
95
96 chooseColorStruct.Flags = CC_RGBINIT;
97
bbcdf8bc 98 if (!m_colourData.GetChooseFull())
2bda0e17
KB
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 {
bbcdf8bc 117 m_colourData.custColours[i].Set(GetRValue(custColours[i]), GetGValue(custColours[i]),
2bda0e17
KB
118 GetBValue(custColours[i]));
119 }
120
bbcdf8bc 121 m_colourData.dataColour.Set(GetRValue(chooseColorStruct.rgbResult), GetGValue(chooseColorStruct.rgbResult),
2bda0e17
KB
122 GetBValue(chooseColorStruct.rgbResult));
123
124 return success ? wxID_OK : wxID_CANCEL;
125}
126