-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.cpccDlgColorPickerMac.mm
More file actions
118 lines (85 loc) · 3.47 KB
/
gui.cpccDlgColorPickerMac.mm
File metadata and controls
118 lines (85 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#include "gui.cpccDlgColorPicker.h"
#include "io.cpccLog.h"
@interface colorPanelWrapper : NSObject <NSWindowDelegate>
{
}
// - (void) colorUpdate:(NSColorPanel*)cp;
- (NSColor *) show:(NSColor *)color;
@end
@implementation colorPanelWrapper
- (BOOL)windowShouldClose:(NSWindow *)sender
{
// return: YES to allow sender to be closed; otherwise, NO.
// NSLog(@"colorPanelWrapper: windowShouldClose");
infoLog().add("colorPanelWrapper: windowShouldClose");
[NSApp stopModalWithCode:NSOKButton];
return YES;
}
/*
-(void) colorUpdate:(NSColorPanel*)cp
{
//NSLog(@"colorPanelWrapper: colorClick");
infoLog().add("colorPanelWrapper: colorUpdate");
m_color = cp.color;
//m_color.fromNSColor([cp color]);
}
*/
- (NSColor *)show:(NSColor *)color;
{
logFunctionLife _fnShow("colorPanelWrapper: show");
/*
NSColorPanel is a singleton, that is loaded lazily.
Only one instance of NSColorPanel may be created.
Color panel is loaded to memory on first sharedColorPanel call.
If you will release this panel, application will crash next time you will
access it, because NSColorPanel class keeps reference to released instance.
Apple doesn't provide a way to clear resources after sharedColorPanel usage.
*/
NSColorPanel *panel; // weak ref
panel = [NSColorPanel sharedColorPanel];
[panel setShowsAlpha:NO];
[panel setColor: color ];
[panel setDelegate:self];
// about the disabled close button under mojave:
// override func viewDidAppear() {
//var button = view.window?.standardWindowButton(NSWindowButton.CloseButton)
//button?.enabled = true
//}
// [[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
//[panel setTarget:self]; // Sets the target of the receiver.
//[panel setAction:@selector(colorUpdate:)]; // Sets the color panel's action message.
// na dokimaso: [window makeKeyAndOrderFront:self];
// [[panel standardWindowButton:NSWindowCloseButton] setEnabled:YES];
// [[panel standardWindowButton:NSWindowCloseButton] setHidden:NO];
// test gia na katalabo poio ta dexetai ayta ta events
// [[panel standardWindowButton:NSWindowZoomButton] setHidden:YES];
// [[panel standardWindowButton:NSWindowZoomButton] setEnabled:NO];
// [panel setTitle:@"test title"];
// NSColorWell example / test
// https://github.com/gnustep/tests-examples/blob/master/gui/GSTest/NSColorWell-test/NSColorWell-test.m
// show panel
// [panel makeKeyAndOrderFront:self];
// [panel orderFront: self];
[NSApp runModalForWindow:panel]; // resets panel position
[panel setDelegate:nil];
NSColor *result=panel.color;
[panel close];
return result;
}
@end
bool showColorPicker(cpccColor &aColor)
{
// https://books.google.gr/books?id=a4WTYqg3S1UC&pg=PT266&lpg=PT266&dq=nscolorpanel+modal&source=bl&ots=cDVnXrrPLg&sig=mIZoT6UmWl0JG6iZnng9c2esDU0&hl=en&sa=X&ved=0ahUKEwif-_nO2Y_aAhXPa5oKHVJVClAQ6AEIXjAI#v=onepage&q=nscolorpanel%20modal&f=false
// http://www.ccp4.ac.uk/dist/checkout/wxPython-src-3.0.2.0/src/osx/carbon/colordlgosx.mm
infoLog().add("showColorPicker");
colorPanelWrapper *cpw = [[[colorPanelWrapper alloc] init] autorelease];
NSColor *macColor = aColor.asNSColor();
macColor = [cpw show:macColor];
aColor.fromNSColor(macColor);
//[cp orderOut:cp];
//[cp close];
return true;
}