Debian Codegraph @

phoenix/cocoa/widget/check-button.cpp

raw
1 @implementation CocoaCheckButton : NSButton
2
3 -(id) initWith:(phoenix::CheckButton&)checkButtonReference {
4 if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
5 checkButton = &checkButtonReference;
6
7 [self setTarget:self];
8 [self setAction:@selector(activate:)];
9 [self setBezelStyle:NSRegularSquareBezelStyle];
10 [self setButtonType:NSOnOffButton];
11 }
12 return self;
13 }
14
15 -(IBAction) activate:(id)sender {
16 checkButton->state.checked = [self state] != NSOffState;
17 if(checkButton->onToggle) checkButton->onToggle();
18 }
19
20 @end
21
22 namespace phoenix {
23
24 Size pCheckButton::minimumSize() {
25 Size size = Font::size(checkButton.font(), checkButton.state.text);
26
27 if(checkButton.state.orientation == Orientation::Horizontal) {
28 size.width += checkButton.state.image.width;
29 size.height = max(checkButton.state.image.height, size.height);
30 }
31
32 if(checkButton.state.orientation == Orientation::Vertical) {
33 size.width = max(checkButton.state.image.width, size.width);
34 size.height += checkButton.state.image.height;
35 }
36
37 return {size.width + 20, size.height + 4};
38 }
39
40 void pCheckButton::setChecked(bool checked) {
41 @autoreleasepool {
42 [cocoaView setState:checked ? NSOnState : NSOffState];
43 }
44 }
45
46 void pCheckButton::setGeometry(Geometry geometry) {
47 pWidget::setGeometry({
48 geometry.x - 2, geometry.y - 2,
49 geometry.width + 4, geometry.height + 4
50 });
51 }
52
53 void pCheckButton::setImage(const image& image, Orientation orientation) {
54 @autoreleasepool {
55 if(image.empty()) {
56 [cocoaView setImage:nil];
57 return;
58 }
59
60 [cocoaView setImage:NSMakeImage(image)];
61
62 if(orientation == Orientation::Horizontal) [cocoaView setImagePosition:NSImageLeft];
63 if(orientation == Orientation::Vertical ) [cocoaView setImagePosition:NSImageAbove];
64 }
65 }
66
67 void pCheckButton::setText(string text) {
68 @autoreleasepool {
69 [cocoaView setTitle:[NSString stringWithUTF8String:text]];
70 }
71 }
72
73 void pCheckButton::constructor() {
74 @autoreleasepool {
75 cocoaView = cocoaCheckButton = [[CocoaCheckButton alloc] initWith:checkButton];
76 }
77 }
78
79 void pCheckButton::destructor() {
80 @autoreleasepool {
81 [cocoaView release];
82 }
83 }
84
85 }