]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/colordlgosx.mm
GetPixel isn't returning RGBColor anymore, so change call
[wxWidgets.git] / src / mac / carbon / colordlgosx.mm
CommitLineData
3582fcbc 1/////////////////////////////////////////////////////////////////////////////
ae6c6c35 2// Name: src/mac/carbon/colordlg.mm
3582fcbc
RN
3// Purpose: wxColourDialog class. NOTE: you can use the generic class
4// if you wish, instead of implementing this.
18f8d063 5// Author: Ryan Norton
3582fcbc 6// Modified by:
18f8d063 7// Created: 2004-11-16
3582fcbc 8// RCS-ID: $Id$
18f8d063 9// Copyright: (c) Ryan Norton
3582fcbc
RN
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13// ===========================================================================
14// declarations
15// ===========================================================================
16
17// ---------------------------------------------------------------------------
18// headers
19// ---------------------------------------------------------------------------
20
ae6c6c35
VZ
21#include "wx/wxprec.h"
22
3582fcbc
RN
23#include "wx/mac/colordlg.h"
24#include "wx/fontdlg.h"
25
3582fcbc
RN
26// ============================================================================
27// implementation
28// ============================================================================
29
30//Mac OSX 10.2+ only
356c775f 31#if USE_NATIVE_FONT_DIALOG_FOR_MACOSX
3582fcbc 32
4e69ff22 33IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog)
4e69ff22 34
3582fcbc
RN
35// Cocoa headers
36#include "wx/cocoa/autorelease.h"
37#include "wx/cocoa/string.h"
38
39#import <AppKit/NSFont.h>
40#import <AppKit/NSFontManager.h>
41#import <AppKit/NSFontPanel.h>
42#import <AppKit/NSColor.h>
43#import <AppKit/NSColorPanel.h>
44
45// ---------------------------------------------------------------------------
46// wxCPWCDelegate - Window Closed delegate
47// ---------------------------------------------------------------------------
48
49@interface wxCPWCDelegate : NSObject
50{
51 bool m_bIsClosed;
52}
53
54// Delegate methods
55- (id)init;
56- (BOOL)windowShouldClose:(id)sender;
57- (BOOL)isClosed;
58@end // interface wxNSFontPanelDelegate : NSObject
59
60@implementation wxCPWCDelegate : NSObject
61
62- (id)init
63{
64 [super init];
65 m_bIsClosed = false;
66
67 return self;
68}
69
70- (BOOL)windowShouldClose:(id)sender
71{
89954433
VZ
72 wxUnusedVar(sender);
73
3582fcbc 74 m_bIsClosed = true;
89954433 75
3582fcbc
RN
76 [NSApp abortModal];
77 [NSApp stopModal];
78 return YES;
79}
80
81- (BOOL)isClosed
82{
83 return m_bIsClosed;
84}
85
86@end // wxNSFontPanelDelegate
87
88/*
89 * wxColourDialog
90 */
91
92wxColourDialog::wxColourDialog()
93{
94 m_dialogParent = NULL;
95}
96
97wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data)
98{
99 Create(parent, data);
100}
101
102bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
103{
104 m_dialogParent = parent;
89954433 105
3582fcbc
RN
106 if (data)
107 m_colourData = *data;
108
109 //
110 // This is the key call - this initializes
111 // events and window stuff for cocoa for carbon
112 // applications.
113 //
89954433 114 // This is also the only call here that is
3582fcbc
RN
115 // 10.2+ specific (the rest is OSX only),
116 // which, ironically, the carbon font
117 // panel requires.
118 //
119 bool bOK = NSApplicationLoad();
120
121 //autorelease pool - req'd for carbon
122 NSAutoreleasePool *thePool;
123 thePool = [[NSAutoreleasePool alloc] init];
124
125 if(m_colourData.m_dataColour.Ok())
126 [[NSColorPanel sharedColorPanel] setColor:
127 [NSColor colorWithCalibratedRed:m_colourData.m_dataColour.Red() / 255.0
18f8d063
RN
128 green:m_colourData.m_dataColour.Green() / 255.0
129 blue:m_colourData.m_dataColour.Blue() / 255.0
3582fcbc
RN
130 alpha:1.0]
131 ];
132 else
89954433
VZ
133 [[NSColorPanel sharedColorPanel] setColor:[NSColor blackColor]];
134
3582fcbc
RN
135 //We're done - free up the pool
136 [thePool release];
89954433 137
3582fcbc
RN
138 return bOK;
139}
140int wxColourDialog::ShowModal()
141{
89954433 142 //Start the pool. Required for carbon interaction
3582fcbc
RN
143 //(For those curious, the only thing that happens
144 //if you don't do this is a bunch of error
145 //messages about leaks on the console,
146 //with no windows shown or anything).
147 NSAutoreleasePool *thePool;
148 thePool = [[NSAutoreleasePool alloc] init];
149
150 //Get the shared color and font panel
151 NSColorPanel* theColorPanel = [NSColorPanel sharedColorPanel];
152
153 //Create and assign the delegates (cocoa event handlers) so
154 //we can tell if a window has closed/open or not
155 wxCPWCDelegate* theCPDelegate = [[wxCPWCDelegate alloc] init];
156 [theColorPanel setDelegate:theCPDelegate];
89954433 157
3582fcbc
RN
158 //
159 // Start the color panel modal loop
160 //
161 NSModalSession session = [NSApp beginModalSessionForWindow:theColorPanel];
89954433 162 for (;;)
3582fcbc
RN
163 {
164 [NSApp runModalSession:session];
89954433 165
3582fcbc
RN
166 //If the color panel is closed, return the font panel modal loop
167 if ([theCPDelegate isClosed])
168 break;
169 }
170 [NSApp endModalSession:session];
89954433 171
3582fcbc
RN
172 //free up the memory for the delegates - we don't need them anymore
173 [theCPDelegate release];
89954433 174
3582fcbc
RN
175 //Get the shared color panel along with the chosen color and set the chosen color
176 NSColor* theColor = [[theColorPanel color] colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
89954433 177
3582fcbc
RN
178 m_colourData.m_dataColour.Set(
179 (unsigned char) ([theColor redComponent] * 255.0),
180 (unsigned char) ([theColor greenComponent] * 255.0),
181 (unsigned char) ([theColor blueComponent] * 255.0)
182 );
183
184 //Release the pool, we're done :)
185 [thePool release];
186
187 //Return ID_OK - there are no "apply" buttons or the like
188 //on either the font or color panel
189 return wxID_OK;
190}
191
3582fcbc
RN
192#endif //use native font dialog
193