Wed, 04 Dec 2024 08:55:49 +0100
add first working cocoa code
404
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2024 Olaf Wintermann. All rights reserved. |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #import "GridLayout.h" |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | @implementation GridLayout |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | @synthesize label=_label; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | @synthesize uilayout=_uilayout; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | @synthesize newline=_newline; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | - (GridLayout*)init { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | self = [super init]; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | _columnspacing = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | _rowspacing = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | _children = cxArrayListCreateSimple(sizeof(GridElm), 32); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | return self; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | /* |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | - (void) layout { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | [super layout]; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | NSRect r1 = _test.frame; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | NSSize s1 = _test.intrinsicContentSize; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | NSEdgeInsets e1 = _test.alignmentRectInsets; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | printf("fuck\n"); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | */ |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | - (void) layout { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | int ncols = _cols+1; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | int nrows = _rows+1; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | GridDef *coldef = calloc(ncols, sizeof(GridDef)); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | GridDef *rowdef = calloc(nrows, sizeof(GridDef)); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | NSRect viewFrame = self.frame; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | int colspacing = _columnspacing; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | int rowspacing = _rowspacing; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | CxIterator i = cxListIterator(_children); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | cx_foreach(GridElm *, elm, i) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | NSSize size = elm->view.intrinsicContentSize; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | NSEdgeInsets alignment = elm->view.alignmentRectInsets; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | if(size.width != NSViewNoIntrinsicMetric) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | CGFloat width = size.width + alignment.left + alignment.right; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | if(width > coldef[elm->x].preferred_size) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | coldef[elm->x].preferred_size = width; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | if(size.height != NSViewNoIntrinsicMetric) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | CGFloat height = size.height + alignment.top + alignment.right; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | //CGFloat height = size.height; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | if(height > rowdef[elm->y].preferred_size) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | rowdef[elm->y].preferred_size = height; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | if(elm->hexpand) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | coldef[elm->x].extend = TRUE; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | if(elm->vexpand) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | rowdef[elm->y].extend = TRUE; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | int col_ext = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | int row_ext = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | int preferred_width = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | int preferred_height = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | for(int j=0;j<ncols;j++) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | preferred_width += coldef[j].preferred_size + colspacing; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | if(coldef[j].extend) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | col_ext++; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | for(int j=0;j<nrows;j++) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | preferred_height += rowdef[j].preferred_size + rowspacing; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | if(rowdef[j].extend) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | row_ext++; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | _preferredSize.width = preferred_width; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | _preferredSize.height = preferred_height; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | int hremaining = viewFrame.size.width - preferred_width; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | int vremaining = viewFrame.size.height - preferred_height; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | int hext = hremaining/col_ext; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | int vext = vremaining/row_ext; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | for(int j=0;j<ncols;j++) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | GridDef *col = &coldef[j]; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | if(col->extend) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | col->size = col->preferred_size + hext; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | } else { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | col->size = col->preferred_size; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | for(int j=0;j<nrows;j++) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | GridDef *row = &rowdef[j]; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | if(row->extend) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | row->size = row->preferred_size + vext; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | } else { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | row->size = row->preferred_size; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | int pos = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | for(int j=0;j<ncols;j++) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | coldef[j].pos = pos; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | pos += coldef[j].size + colspacing; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | pos = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | for(int j=0;j<nrows;j++) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | rowdef[j].pos = pos; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | pos += rowdef[j].size + rowspacing; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | i = cxListIterator(_children); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | cx_foreach(GridElm *, elm, i) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | //NSSize size = elm->view.intrinsicContentSize; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | GridDef *col = &coldef[elm->x]; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | GridDef *row = &rowdef[elm->y]; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | NSEdgeInsets alignment = elm->view.alignmentRectInsets; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | NSRect frame; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | frame.size.width = col->size; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | frame.size.height = row->size; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | frame.origin.x = col->pos - (alignment.left+alignment.right)/2; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | frame.origin.y = viewFrame.size.height - row->pos - frame.size.height + ((alignment.top+alignment.right)/2); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | elm->view.frame = frame; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | free(coldef); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | free(rowdef); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | - (NSSize)intrinsicContentSize { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | return self.preferredSize; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | - (void) addView:(NSView*)view fill:(BOOL)fill { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | if(_newline) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | _y++; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | _x = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | _newline = FALSE; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | GridElm elm; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | elm.x = _x; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | elm.y = _y; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | elm.margin = 0; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | elm.colspan = _uilayout.colspan; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | elm.rowspan = _uilayout.rowspan; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | elm.hfill = _uilayout.hfill; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | elm.vfill = _uilayout.vfill; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | elm.hexpand = _uilayout.hexpand; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | elm.vexpand = _uilayout.vexpand; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | elm.view = view; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | cxListAdd(_children, &elm); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | [self addSubview:view]; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | self.needsLayout = YES; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | if(_x > _cols) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | _cols = _x; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | if(_y > _rows) { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | _rows = _y; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | _x++; |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | - (void) dealloc { |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | cxListDestroy(_children); |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | } |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | |
384f6d1f5784
add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | @end |