1 | /* |
2 | * $Id: RECT.java,v 1.3 2006/03/04 06:04:22 hastings Exp $ |
3 | * |
4 | * (c) Copyright, Moebius Solutions, Inc., 2004 |
5 | * |
6 | * All Rights Reserved |
7 | * |
8 | * This material may be reproduced by or for the U. S. Government |
9 | * pursuant to the copyright license under the clause at |
10 | * DFARS 252.227-7014 (OCT 2001). |
11 | */ |
12 | |
13 | package com.moesol.bindings.platform_sdk.windows_api; |
14 | |
15 | /** |
16 | * RECT structure. |
17 | */ |
18 | public class RECT extends com.moesol.bindings.NativeStructure { |
19 | /** |
20 | * Create a new instance. |
21 | */ |
22 | public RECT() { |
23 | super(new byte[sizeof()]); |
24 | } |
25 | /** |
26 | * Create a new instance on a byte buffer. |
27 | */ |
28 | public RECT(java.nio.ByteBuffer bb) { |
29 | super(bb); |
30 | // set limit based on the dynamic size in byte in bb. |
31 | bb.limit(getDynamicSize()); |
32 | } |
33 | public static int sizeof() { |
34 | return 16; |
35 | } |
36 | |
37 | /** |
38 | * Represent a native array of these structures |
39 | */ |
40 | public static class Array extends com.moesol.bindings.NativeArrayOfStructs { |
41 | public Array(java.nio.ByteBuffer bb) { |
42 | super(bb); |
43 | } |
44 | public RECT get(int index) { |
45 | return new RECT(getElementSlice(index, RECT.sizeof())); |
46 | } |
47 | public void put(int index, RECT value) { |
48 | get(index).putStruct(0, RECT.sizeof(), value); |
49 | } |
50 | public int length() { |
51 | return _getByteBuffer().limit() / RECT.sizeof(); |
52 | } |
53 | public int getDynamicSize() { |
54 | return _getByteBuffer().limit(); |
55 | } |
56 | public String toString() { |
57 | StringBuffer sb = new StringBuffer(); |
58 | for (int i = 0; i < length(); i++) { |
59 | sb.append(get(i)); |
60 | } |
61 | return sb.toString(); |
62 | } |
63 | } |
64 | |
65 | |
66 | |
67 | public static final int OFFSET_left = 0; |
68 | /** |
69 | * |
70 | * @param v new left value |
71 | */ |
72 | public void set_left(int v) { |
73 | putInt(0, v); |
74 | } |
75 | /** |
76 | * |
77 | * @return left value |
78 | */ |
79 | public int get_left() { |
80 | return getInt(0); |
81 | } |
82 | |
83 | public static final int OFFSET_top = 4; |
84 | /** |
85 | * |
86 | * @param v new top value |
87 | */ |
88 | public void set_top(int v) { |
89 | putInt(4, v); |
90 | } |
91 | /** |
92 | * |
93 | * @return top value |
94 | */ |
95 | public int get_top() { |
96 | return getInt(4); |
97 | } |
98 | |
99 | public static final int OFFSET_right = 8; |
100 | /** |
101 | * |
102 | * @param v new right value |
103 | */ |
104 | public void set_right(int v) { |
105 | putInt(8, v); |
106 | } |
107 | /** |
108 | * |
109 | * @return right value |
110 | */ |
111 | public int get_right() { |
112 | return getInt(8); |
113 | } |
114 | |
115 | public static final int OFFSET_bottom = 12; |
116 | /** |
117 | * |
118 | * @param v new bottom value |
119 | */ |
120 | public void set_bottom(int v) { |
121 | putInt(12, v); |
122 | } |
123 | /** |
124 | * |
125 | * @return bottom value |
126 | */ |
127 | public int get_bottom() { |
128 | return getInt(12); |
129 | } |
130 | |
131 | /** |
132 | * Get dynamic size in bytes. |
133 | * If this structure contains a variable size array, |
134 | * return the number of bytes needed to hold the fixed |
135 | * part and the variable sized array based on the [length_is()] |
136 | * attribute. Note that the sizeof method on returns the |
137 | * size of the fixed part plus the size of one array entry. |
138 | * |
139 | * @return dynamic size in bytes. |
140 | */ |
141 | public int getDynamicSize() { |
142 | return sizeof(); |
143 | } |
144 | |
145 | public String toString() { |
146 | StringBuffer sb = new StringBuffer(); |
147 | sb.append("\nRECT("); |
148 | sb.append("left("); |
149 | sb.append(get_left()); |
150 | sb.append(")"); |
151 | |
152 | sb.append("top("); |
153 | sb.append(get_top()); |
154 | sb.append(")"); |
155 | |
156 | sb.append("right("); |
157 | sb.append(get_right()); |
158 | sb.append(")"); |
159 | |
160 | sb.append("bottom("); |
161 | sb.append(get_bottom()); |
162 | sb.append(")"); |
163 | |
164 | sb.append(')'); |
165 | return sb.toString(); |
166 | } |
167 | |
168 | // |
169 | // Additional methods that MFC/ATL have on CRect |
170 | // |
171 | |
172 | /** |
173 | * @return width of this rectangle |
174 | */ |
175 | public int getWidth() { |
176 | return get_right() - get_left(); |
177 | } |
178 | |
179 | /** |
180 | * @return height of this rectangle |
181 | */ |
182 | public int getHeight() { |
183 | return get_bottom() - get_top(); |
184 | } |
185 | } |