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