Debian Codegraph @

hiro/cocoa/widget/widget.cpp

raw
1 #if defined(Hiro_Widget)
2
3 namespace hiro {
4
5 auto pWidget::construct() -> void {
6 if(!cocoaView) {
7 abstract = true;
8 cocoaView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 0, 0)];
9 [cocoaView setHidden:true];
10 }
11
12 if(auto window = self().parentWindow(true)) {
13 if(auto p = window->self()) p->_append(self());
14 setDroppable(self().droppable());
15 setEnabled(self().enabled(true));
16 setFocusable(self().focusable());
17 setFont(self().font(true));
18 setMouseCursor(self().mouseCursor());
19 setToolTip(self().toolTip());
20 setVisible(self().visible(true));
21 }
22 }
23
24 auto pWidget::destruct() -> void {
25 [cocoaView removeFromSuperview];
26 }
27
28 auto pWidget::focused() const -> bool {
29 return cocoaView == [[cocoaView window] firstResponder];
30 }
31
32 auto pWidget::setDroppable(bool droppable) -> void {
33 //virtual
34 }
35
36 auto pWidget::setEnabled(bool enabled) -> void {
37 if(abstract) enabled = false;
38
39 if([cocoaView respondsToSelector:@selector(setEnabled:)]) {
40 [(id)cocoaView setEnabled:enabled];
41 }
42 }
43
44 auto pWidget::setFocusable(bool focusable) -> void {
45 //virtual
46 }
47
48 auto pWidget::setFocused() -> void {
49 [[cocoaView window] makeFirstResponder:cocoaView];
50 }
51
52 auto pWidget::setFont(const Font& font) -> void {
53 if([cocoaView respondsToSelector:@selector(setFont:)]) {
54 [(id)cocoaView setFont:pFont::create(font)];
55 }
56 }
57
58 auto pWidget::setGeometry(Geometry geometry) -> void {
59 CGFloat windowHeight = [[cocoaView superview] frame].size.height;
60 //round coordinates
61 f32 x = geometry.x();
62 f32 y = windowHeight - geometry.y() - geometry.height();
63 f32 width = geometry.width();
64 f32 height = geometry.height();
65 [cocoaView setFrame:NSMakeRect(x, y, width, height)];
66 [[cocoaView superview] setNeedsDisplay:YES];
67 pSizable::setGeometry(geometry);
68 }
69
70 auto pWidget::setMouseCursor(const MouseCursor& mouseCursor) -> void {
71 //TODO
72 }
73
74 auto pWidget::setToolTip(const string& toolTip) -> void {
75 //TODO
76 }
77
78 auto pWidget::setVisible(bool visible) -> void {
79 if(abstract) visible = false;
80
81 [cocoaView setHidden:!visible];
82 }
83
84 }
85
86 #endif