File: check-label.cpp

package info (click to toggle)
ares 126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 32,600 kB
  • sloc: cpp: 356,508; ansic: 20,394; makefile: 16; sh: 2
file content (59 lines) | stat: -rw-r--r-- 1,393 bytes parent folder | download | duplicates (2)
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
#if defined(Hiro_CheckLabel)

@implementation CocoaCheckLabel : NSButton

-(id) initWith:(hiro::mCheckLabel&)checkLabelReference {
  if(self = [super initWithFrame:NSMakeRect(0, 0, 0, 0)]) {
    checkLabel = &checkLabelReference;

    [self setTarget:self];
    [self setAction:@selector(activate:)];
    [self setButtonType:NSSwitchButton];
  }
  return self;
}

-(IBAction) activate:(id)sender {
  checkLabel->state.checked = [self state] != NSOffState;
  checkLabel->doToggle();
}

@end

namespace hiro {

auto pCheckLabel::construct() -> void {
  cocoaView = cocoaCheckLabel = [[CocoaCheckLabel alloc] initWith:self()];
  pWidget::construct();

  setChecked(state().checked);
  setText(state().text);
}

auto pCheckLabel::destruct() -> void {
  [cocoaView removeFromSuperview];
}

auto pCheckLabel::minimumSize() const -> Size {
  Size size = pFont::size(self().font(true), state().text);
  return {size.width() + 20, size.height()};
}

auto pCheckLabel::setChecked(bool checked) -> void {
  [(CocoaCheckLabel*)cocoaView setState:checked ? NSOnState : NSOffState];
}

auto pCheckLabel::setGeometry(Geometry geometry) -> void {
  pWidget::setGeometry({
    geometry.x() - 2, geometry.y(),
    geometry.width() + 4, geometry.height()
  });
}

auto pCheckLabel::setText(const string& text) -> void {
  [(CocoaCheckLabel*)cocoaView setTitle:[NSString stringWithUTF8String:text]];
}

}

#endif