001: /* Copyright (c) 2007 Timothy Wall, All Rights Reserved
002: *
003: * This library is free software; you can redistribute it and/or
004: * modify it under the terms of the GNU Lesser General Public
005: * License as published by the Free Software Foundation; either
006: * version 2.1 of the License, or (at your option) any later version.
007: *
008: * This library is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: */
013: package org.netbeans.core.nativeaccess.transparency.win32;
014:
015: import java.util.HashMap;
016: import java.util.Map;
017:
018: import com.sun.jna.FromNativeContext;
019: import com.sun.jna.IntegerType;
020: import com.sun.jna.Pointer;
021: import com.sun.jna.PointerType;
022: import com.sun.jna.ptr.ByReference;
023: import com.sun.jna.win32.StdCallLibrary;
024: import com.sun.jna.win32.W32APIFunctionMapper;
025: import com.sun.jna.win32.W32APITypeMapper;
026:
027: /** Base type for most W32 API libraries. Provides standard options
028: * for unicode/ASCII mappings. Set the system property <code>w32.ascii</code>
029: * to <code>true</code> to default to the ASCII mappings.
030: */
031: public interface W32API extends StdCallLibrary, W32Errors {
032:
033: /** Standard options to use the unicode version of a w32 API. */
034: Map UNICODE_OPTIONS = new HashMap() {
035: {
036: put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
037: put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
038: }
039: };
040: /** Standard options to use the ASCII/MBCS version of a w32 API. */
041: Map ASCII_OPTIONS = new HashMap() {
042: {
043: put(OPTION_TYPE_MAPPER, W32APITypeMapper.ASCII);
044: put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.ASCII);
045: }
046: };
047: Map DEFAULT_OPTIONS = Boolean.getBoolean("w32.ascii") ? ASCII_OPTIONS
048: : UNICODE_OPTIONS;
049:
050: public static class HANDLE extends PointerType {
051: /** Override to the appropriate object for INVALID_HANDLE_VALUE. */
052: public Object fromNative(Object nativeValue,
053: FromNativeContext context) {
054: Object o = super .fromNative(nativeValue, context);
055: if (INVALID_HANDLE_VALUE.equals(o))
056: return INVALID_HANDLE_VALUE;
057: return o;
058: }
059: }
060:
061: public static class HDC extends HANDLE {
062: }
063:
064: public static class HICON extends HANDLE {
065: }
066:
067: public static class HBITMAP extends HANDLE {
068: }
069:
070: public static class HRGN extends HANDLE {
071: }
072:
073: public static class HWND extends HANDLE {
074: }
075:
076: public static class HINSTANCE extends HANDLE {
077: }
078:
079: public static class HMODULE extends HINSTANCE {
080: }
081:
082: /** Constant value representing an invalid HANDLE. */
083: HANDLE INVALID_HANDLE_VALUE = new HANDLE() {
084: {
085: super .setPointer(Pointer.createConstant(-1));
086: }
087:
088: public void setPointer(Pointer p) {
089: throw new UnsupportedOperationException(
090: "Immutable reference");
091: }
092: };
093: /** Special HWND value. */
094: HWND HWND_BROADCAST = new HWND() {
095: {
096: super .setPointer(Pointer.createConstant(0xFFFF));
097: }
098:
099: public void setPointer(Pointer p) {
100: throw new UnsupportedOperationException(
101: "Immutable reference");
102: }
103: };
104:
105: /** LPHANDLE */
106: public static class HANDLEByReference extends ByReference {
107: public HANDLEByReference() {
108: this (null);
109: }
110:
111: public HANDLEByReference(HANDLE h) {
112: super (Pointer.SIZE);
113: setValue(h);
114: }
115:
116: public void setValue(HANDLE h) {
117: getPointer().setPointer(0,
118: h != null ? h.getPointer() : null);
119: }
120:
121: public HANDLE getValue() {
122: Pointer p = getPointer().getPointer(0);
123: if (p == null)
124: return null;
125: if (INVALID_HANDLE_VALUE.getPointer().equals(p))
126: return INVALID_HANDLE_VALUE;
127: HANDLE h = new HANDLE();
128: h.setPointer(p);
129: return h;
130: }
131: }
132:
133: public static class LONG_PTR extends IntegerType {
134: public LONG_PTR() {
135: this (0);
136: }
137:
138: public LONG_PTR(long value) {
139: super (Pointer.SIZE, value);
140: }
141: }
142:
143: public static class SSIZE_T extends LONG_PTR {
144: public SSIZE_T() {
145: this (0);
146: }
147:
148: public SSIZE_T(long value) {
149: super (value);
150: }
151: }
152:
153: public static class ULONG_PTR extends IntegerType {
154: public ULONG_PTR() {
155: this (0);
156: }
157:
158: public ULONG_PTR(long value) {
159: super (Pointer.SIZE, value);
160: }
161: }
162:
163: public static class SIZE_T extends ULONG_PTR {
164: public SIZE_T() {
165: this (0);
166: }
167:
168: public SIZE_T(long value) {
169: super (value);
170: }
171: }
172:
173: public static class LPARAM extends LONG_PTR {
174: public LPARAM() {
175: this (0);
176: }
177:
178: public LPARAM(long value) {
179: super (value);
180: }
181: }
182:
183: public static class LRESULT extends LONG_PTR {
184: public LRESULT() {
185: this (0);
186: }
187:
188: public LRESULT(long value) {
189: super (value);
190: }
191: }
192:
193: public static class UINT_PTR extends IntegerType {
194: public UINT_PTR() {
195: super (Pointer.SIZE);
196: }
197:
198: public UINT_PTR(long value) {
199: super (Pointer.SIZE, value);
200: }
201:
202: public Pointer toPointer() {
203: return Pointer.createConstant(longValue());
204: }
205: }
206:
207: public static class WPARAM extends UINT_PTR {
208: public WPARAM() {
209: this (0);
210: }
211:
212: public WPARAM(long value) {
213: super(value);
214: }
215: }
216: }
|