01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Rustem Rafikov
19: * @version $Revision$
20: */package org.apache.harmony.awt.nativebridge.windows;
21:
22: import org.apache.harmony.awt.internal.nls.Messages;
23:
24: public class Callback {
25:
26: public interface Handler {
27: long windowProc(long hwnd, int msg, long wParam, long lParam);
28: }
29:
30: private static long callbackWNDPROC = 0;
31: private static long callbackOFNHOOKPROC = 0;
32: private static long callbackDataTransferProc = 0;
33:
34: private static Handler handler;
35: private static Handler handlerOFN;
36: private static Handler handlerDataTransfer;
37:
38: static {
39: System.loadLibrary("Win32Wrapper"); //$NON-NLS-1$
40: callbackWNDPROC = initCallBackWNDPROC();
41: callbackOFNHOOKPROC = initCallBackOFNHOOKPROC();
42: callbackDataTransferProc = initCallBackDataTransferProc();
43: }
44:
45: public static long registerCallback(Handler h) {
46: if (handler != null && handler != h) {
47: // awt.1E=Attempt to replace WindowProc handler
48: throw new RuntimeException(Messages.getString("awt.1E")); //$NON-NLS-1$
49: }
50: handler = h;
51: return callbackWNDPROC;
52: }
53:
54: public static long registerCallbackOFN(Handler h) {
55: handlerOFN = h;
56: return callbackOFNHOOKPROC;
57: }
58:
59: public static long registerCallbackDataTransfer(Handler h) {
60: handlerDataTransfer = h;
61: return callbackDataTransferProc;
62: }
63:
64: private static native long initCallBackWNDPROC();
65:
66: private static native long initCallBackOFNHOOKPROC();
67:
68: private static native long initCallBackDataTransferProc();
69:
70: /**
71: * Calls registred java method. Called from JNI code.
72: */
73: static long runCallbackWNDPROC(long p1, int p2, long p3, long p4) {
74: return (handler != null) ? handler.windowProc(p1, p2, p3, p4)
75: : 0;
76: }
77:
78: static long runCallbackOFNHOOKPROC(long p1, int p2, long p3, long p4) {
79: return (handlerOFN != null) ? handlerOFN.windowProc(p1, p2, p3,
80: p4) : 0;
81: }
82:
83: static long runCallbackDataTransferProc(long p1, int p2, long p3,
84: long p4) {
85: return (handlerDataTransfer != null) ? handlerDataTransfer
86: .windowProc(p1, p2, p3, p4) : 0;
87: }
88: }
|