jdk/src/solaris/native/sun/awt/awt_MToolkit.c
author art
Tue, 09 Nov 2010 14:02:54 +0300
changeset 7151 8db734b13eb6
parent 5506 202f599c92aa
permissions -rw-r--r--
6984039: awt source rebranding vendor changes needed (jdk7 only) Reviewed-by: prr, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2810
diff changeset
     2
 * Copyright (c) 1995, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2810
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2810
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2810
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2810
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2810
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "awt_p.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <sys/time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <limits.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <locale.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include <X11/cursorfont.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include <Xm/MenuShell.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <Xm/RowColumn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <jvm.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <jni.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include <jlong.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#include <jni_util.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/* JNI headers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
#include "java_awt_AWTEvent.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
#include "java_awt_Frame.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
#include "java_awt_SystemColor.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
#include "sun_awt_motif_MToolkit.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/* JNI field and method ids */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#include "awt_Component.h"
1175
026b52c440fe 6706121: makefile: unnecessary Motif classes compilation in JDK7
yan
parents: 2
diff changeset
    51
//#include "awt_Cursor.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#include "awt_MenuComponent.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
#include "awt_TopLevel.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#include "canvas.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#include "color.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#include "awt_mgrsel.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
#include "awt_wm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#include "awt_DrawingSurface.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
#include "awt_Window.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#include "awt_xembed.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
#include "awt_xembed_server.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
extern JavaVM *jvm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
extern void statusWindowEventHandler(XEvent event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
JNI_OnLoad(JavaVM *vm, void *reserved)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    awt_util_debug_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#endif /* !HEADLESS */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jvm = vm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    return JNI_VERSION_1_2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
JNIEXPORT jboolean JNICALL AWTIsHeadless() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#ifdef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#ifndef HEADLESS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
static jlong awtJNI_TimeMillis(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
extern void awt_initialize_Xm_DnD(Display*);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
extern void awt_initialize_DataTransferer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
extern Display *awt_init_Display(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
extern void X11SD_LibDispose(JNIEnv *env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
extern Widget drag_source = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
extern struct ComponentIDs componentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
extern struct MenuComponentIDs menuComponentIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
extern struct MComponentPeerIDs mComponentPeerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
extern struct WindowIDs windowIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
static Atom _XA_XSETTINGS_SETTINGS = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
struct xsettings_callback_cookie {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    jobject mtoolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    jmethodID upcallMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
static struct xsettings_callback_cookie xsettings_callback_cookie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
static XEvent focusOutEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
static void awt_pipe_init(void);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
static void processOneEvent(XtInputMask iMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
extern void waitForEvents(JNIEnv *env, int32_t fdXPipe, int32_t fdAWTPipe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
#ifdef USE_SELECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
static void performSelect(JNIEnv *env, int32_t fdXPipe, int32_t fdAWTPipe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
static void performPoll(JNIEnv *env,int32_t fdXPipe, int32_t fdAWTPipe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
#include <X11/Intrinsic.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
#include <dlfcn.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
#include <fcntl.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
#ifdef USE_SELECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
#if defined(AIX)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
#include <sys/select.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
#include <poll.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
#ifndef POLLRDNORM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
#define POLLRDNORM POLLIN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
#ifdef NDEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#undef DEBUG            /* NDEBUG overrides DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
static struct WidgetInfo *awt_winfo = (struct WidgetInfo *) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
static struct MenuList* menu_list = (struct MenuList*) NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
#ifndef bzero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
#define bzero(a,b) memset(a, 0, b)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
static jboolean syncUpdated = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
static jboolean syncFailed = JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
static jint eventNumber = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
static void syncWait_eventHandler(XEvent *);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
static Atom oops_atom = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
static Atom wm_selection = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
static Atom version_atom = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
static Boolean inSyncWait = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
Widget grabbed_widget = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
XtAppContext awt_appContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
Widget awt_root_shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
Pixel awt_defaultBg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
Pixel awt_defaultFg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
int32_t awt_multiclick_time;        /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
uint32_t awt_MetaMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
uint32_t awt_AltMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
uint32_t awt_NumLockMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
uint32_t awt_ModeSwitchMask = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
Cursor awt_scrollCursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
Boolean  awt_ModLockIsShiftLock = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
extern Boolean awt_UseType4Patch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
extern Boolean awt_UseXKB;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
#define SPECIAL_KEY_EVENT 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
/* implement a "putback queue" -- see comments on awt_put_back_event() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
#define PUTBACK_QUEUE_MIN_INCREMENT 5   /* min size increase */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
static XEvent *putbackQueue = NULL;     /* the queue -- next event is 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
static int32_t putbackQueueCount = 0;   /* # of events available on queue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
static int32_t putbackQueueCapacity = 0;        /* total capacity of queue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
static XtInputMask awt_events_pending(XtAppContext appContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
static int32_t awt_get_next_put_back_event(XEvent *xev_out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
#define AWT_FLUSH_TIMEOUT    ((uint32_t)100) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
#define AWT_MIN_POLL_TIMEOUT ((uint32_t)0) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
#define AWT_MAX_POLL_TIMEOUT ((uint32_t)250) /* milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
#define AWT_POLL_BUFSIZE        100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
#define AWT_READPIPE            (awt_pipe_fds[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
#define AWT_WRITEPIPE           (awt_pipe_fds[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#define AWT_FLUSHOUTPUT_NOW()  \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
{                              \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    XFlush(awt_display);       \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    awt_next_flush_time = 0LL; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
typedef XtIntervalId (*XTFUNC)();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
static jobject  awt_MainThread = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
static char     read_buf[AWT_POLL_BUFSIZE + 1];    /* dummy buf to empty pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
static int32_t      awt_pipe_fds[2];                   /* fds for wkaeup pipe */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
static Boolean  awt_pipe_inited = False;           /* make sure pipe is initialized before write */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
static int32_t      def_poll_timeout = AWT_MAX_POLL_TIMEOUT;   /* default value for timeout */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
static jlong awt_next_flush_time = 0LL; /* 0 == no scheduled flush */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
static void     *xt_lib = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
static XTFUNC   xt_timeout = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
#ifdef DEBUG_AWT_LOCK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
int32_t awt_locked = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
char *lastF = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
int32_t lastL = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
#ifndef NOMODALFIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
extern Boolean awt_isModal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
extern Boolean awt_isWidgetModal(Widget w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
Boolean keyboardGrabbed = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
static uint32_t curPollTimeout = AWT_MAX_POLL_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
/* Font information to feed Motif widgets. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
static const char      *motifFontList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
static XFontSet        defaultMotifFontSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
static XFontStruct     *defaultMotifFontStruct;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
static const char *defaultMotifFont =  /* a.k.a "fixed", known everywhere */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
XFontSet getMotifFontSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    char    **missingList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    int32_t     missingCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    char    *defChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    return XCreateFontSet(awt_display, motifFontList,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                          &missingList, &missingCount, &defChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
XFontStruct *getMotifFontStruct() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    return XLoadQueryFont(awt_display, defaultMotifFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
XmFontList getMotifFontList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    XmFontListEntry motifFontListEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    XmFontList fontlist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    if (strchr(motifFontList, ',') == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        /* If the default font is a single font. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        if (defaultMotifFontStruct == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            defaultMotifFontStruct = getMotifFontStruct();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        motifFontListEntry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                                                   XmFONT_IS_FONT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                                           (XtPointer)defaultMotifFontStruct);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        /* If the default font is multiple fonts. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (defaultMotifFontSet == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            defaultMotifFontSet = getMotifFontSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            motifFontListEntry = XmFontListEntryCreate(XmFONTLIST_DEFAULT_TAG,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                               XmFONT_IS_FONTSET,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                                               (XtPointer)defaultMotifFontSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    fontlist = XmFontListAppendEntry(NULL, motifFontListEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    XmFontListEntryFree(&motifFontListEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    return fontlist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
awt_set_poll_timeout (uint32_t newTimeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    DTRACE_PRINTLN1("awt_set_poll_timeout(%lu)", newTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    newTimeout = max(AWT_MIN_POLL_TIMEOUT, newTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    newTimeout = min(AWT_MAX_POLL_TIMEOUT, newTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    newTimeout = min(newTimeout, curPollTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    curPollTimeout = newTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
} /* awt_set_poll_timeout */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
 * Gets the best timeout for the next call to poll() or select().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
 * If timedOut is True, we assume that our previous timeout elapsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
 * with no events/timers arriving. Therefore, we can increase the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
 * next timeout slightly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
static uint32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
awt_get_poll_timeout( Boolean timedOut )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    uint32_t timeout = AWT_MAX_POLL_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    DTRACE_PRINTLN2("awt_get_poll_timeout(%s), awt_next_flush_time:%ld",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        (remove?"true":"false"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        awt_next_flush_time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    if (timedOut) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        /* add 1/16 (plus 1, in case the division truncates to 0) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        curPollTimeout += ((curPollTimeout>>4) + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    if (awt_next_flush_time > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        int32_t flushDiff = (int32_t)(awt_next_flush_time - awtJNI_TimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        timeout = min(curPollTimeout, flushDiff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        timeout = curPollTimeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    return timeout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
} /* awt_get_poll_timeout() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
static jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
awtJNI_TimeMillis(void)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    struct timeval t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    gettimeofday(&t, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    return jlong_add(jlong_mul(jint_to_jlong(t.tv_sec), jint_to_jlong(1000)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                     jint_to_jlong(t.tv_usec / 1000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
static int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
xtError()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    jio_fprintf(stderr, "Xt error\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    JNU_ThrowNullPointerException(env, "NullPointerException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
static int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
xIOError(Display *dpy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    jclass cl = (*env)->FindClass(env, "java/lang/Thread");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    if (errno == EPIPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        jio_fprintf(stderr, "X connection to %s host broken (explicit kill or server shutdown)\n", XDisplayName(NULL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    JVM_RaiseSignal(JVM_SIGTERM); /* Shut down cleanly */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    if (cl != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        JVM_Sleep(env, cl, 20000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    return 0; /* to keep compiler happy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
/* Like XKeysymToKeycode, but ensures that keysym is the primary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
 * symbol on the keycode returned.  Returns zero otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
static int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
keysym_to_keycode_if_primary(Display *dpy, KeySym sym)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    KeyCode code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    KeySym primary;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    code = XKeysymToKeycode(dpy, sym);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    if (code == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    primary = XKeycodeToKeysym(dpy, code, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    if (sym == primary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return code;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
 * +kb or -kb ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
static Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
isXKBenabled(Display *display) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    int mop, beve, berr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * NB: TODO: hope it will return False if XkbIgnoreExtension was called!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    return XQueryExtension(display, "XKEYBOARD", &mop, &beve, &berr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
/* Assign meaning - alt, meta, etc. - to X modifiers mod1 ... mod5.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
 * Only consider primary symbols on keycodes attached to modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
setup_modifier_map(Display *disp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    KeyCode metaL      = keysym_to_keycode_if_primary(disp, XK_Meta_L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    KeyCode metaR      = keysym_to_keycode_if_primary(disp, XK_Meta_R);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    KeyCode altL       = keysym_to_keycode_if_primary(disp, XK_Alt_L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    KeyCode altR       = keysym_to_keycode_if_primary(disp, XK_Alt_R);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    KeyCode numLock    = keysym_to_keycode_if_primary(disp, XK_Num_Lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    KeyCode modeSwitch = keysym_to_keycode_if_primary(disp, XK_Mode_switch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    KeyCode shiftLock  = keysym_to_keycode_if_primary(disp, XK_Shift_Lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    KeyCode capsLock   = keysym_to_keycode_if_primary(disp, XK_Caps_Lock);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    XModifierKeymap *modmap = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    int32_t nkeys, modn, i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    char *ptr = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    DTRACE_PRINTLN("In setup_modifier_map");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    modmap = XGetModifierMapping(disp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    nkeys = modmap->max_keypermod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    for (modn = Mod1MapIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
         (modn <= Mod5MapIndex) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
             (awt_MetaMask == 0 || awt_AltMask == 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
              awt_NumLockMask == 0 || awt_ModeSwitchMask == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
         ++modn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        static const uint32_t modmask[8] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            ShiftMask, LockMask, ControlMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            Mod1Mask, Mod2Mask, Mod3Mask, Mod4Mask, Mod5Mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        for (i = 0; i < nkeys; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            /* for each keycode attached to this modifier */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            KeyCode keycode = modmap->modifiermap[modn * nkeys + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            if (keycode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            if (awt_MetaMask == 0 && (keycode == metaL || keycode == metaR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                awt_MetaMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                DTRACE_PRINTLN2("    awt_MetaMask       = %d, modn = %d", awt_MetaMask, modn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            } else if (awt_AltMask == 0 && (keycode == altL || keycode == altR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                awt_AltMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                DTRACE_PRINTLN2("    awt_AltMask        = %d, modn = %d", awt_AltMask, modn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            } else if (awt_NumLockMask == 0 && keycode == numLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                awt_NumLockMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                DTRACE_PRINTLN2("    awt_NumLockMask    = %d, modn = %d", awt_NumLockMask, modn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            } else if (awt_ModeSwitchMask == 0 && keycode == modeSwitch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                awt_ModeSwitchMask = modmask[modn];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                DTRACE_PRINTLN2("    awt_ModeSwitchMask = %d, modn = %d", awt_ModeSwitchMask, modn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    for(i = 0; i < nkeys; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        KeyCode keycode = modmap->modifiermap[LockMapIndex * nkeys + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (keycode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (keycode == shiftLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            awt_ModLockIsShiftLock = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        if (keycode == capsLock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    DTRACE_PRINTLN1("    ShiftMask          = %d", ShiftMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    DTRACE_PRINTLN1("    ControlMask        = %d", ControlMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    XFreeModifiermap(modmap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    ptr = getenv("_AWT_USE_TYPE4_PATCH");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    if( ptr != NULL && ptr[0] != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if( strncmp("true", ptr, 4) == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
           awt_UseType4Patch = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }else if( strncmp("false", ptr, 5) == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
           awt_UseType4Patch = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    awt_UseXKB = isXKBenabled(disp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
Boolean scrollBugWorkAround;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
awt_output_flush()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    char c = 'p';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    if (awt_next_flush_time == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        Boolean needsWakeup = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        if (awt_pipe_inited && (awt_get_poll_timeout(False) > (2*AWT_FLUSH_TIMEOUT))){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            needsWakeup = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        /* awt_next_flush_time affects awt_get_poll_timeout(), so set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
         * the variable *after* calling the function.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        awt_next_flush_time = awtJNI_TimeMillis() + AWT_FLUSH_TIMEOUT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (needsWakeup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            /* write to the utility pipe to wake up the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
             * loop, if it's sleeping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            write ( AWT_WRITEPIPE, &c, 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
#ifdef FLUSHDEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
jio_fprintf(stderr, "!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
} /* awt_output_flush() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
null_event_handler(Widget w, XtPointer client_data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                   XEvent * event, Boolean * cont)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /* do nothing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
struct WidgetInfo *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
findWidgetInfo(Widget widget)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    struct WidgetInfo *cw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    for (cw = awt_winfo; cw != NULL; cw = cw->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        if (cw->widget == widget || cw->origin == widget) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            return cw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
awt_addWidget(Widget w, Widget origin, void *peer, jlong event_flags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    if (findWidgetInfo(w) != NULL) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    if (!XtIsSubclass(w, xmFileSelectionBoxWidgetClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        struct WidgetInfo *nw = (struct WidgetInfo *) malloc(sizeof(struct WidgetInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (nw) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            nw->widget     = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            nw->origin     = origin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            nw->peer       = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            nw->event_mask = event_flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            nw->next       = awt_winfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            awt_winfo      = nw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if (event_flags & java_awt_AWTEvent_MOUSE_EVENT_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                XtAddEventHandler(w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                  ButtonPressMask | ButtonReleaseMask |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                                  EnterWindowMask | LeaveWindowMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                  False, null_event_handler, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                if (w != origin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    XtAddEventHandler(origin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                      ButtonPressMask | ButtonReleaseMask |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                                      EnterWindowMask | LeaveWindowMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                                      False, null_event_handler, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            if (event_flags & java_awt_AWTEvent_MOUSE_MOTION_EVENT_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                XtAddEventHandler(w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                  PointerMotionMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                  False, null_event_handler, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                if (w != origin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    XtAddEventHandler(origin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                      PointerMotionMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                      False, null_event_handler, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            if (event_flags & java_awt_AWTEvent_KEY_EVENT_MASK) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                XtAddEventHandler(w,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                                  KeyPressMask | KeyReleaseMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                                  False, null_event_handler, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                if (w != origin) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    XtAddEventHandler(origin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                      KeyPressMask | KeyReleaseMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                      False, null_event_handler, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
awt_delWidget(Widget w)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    struct WidgetInfo *cw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    if (awt_winfo != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        if ((awt_winfo->widget == w) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            (awt_winfo->origin == w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            cw = awt_winfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            awt_winfo = awt_winfo->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            free((void *) cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            struct WidgetInfo *pw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            for (pw = awt_winfo, cw = awt_winfo->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                 cw != NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                 pw = cw, cw = cw->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                if ((cw->widget == w) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    (cw->origin == w)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    pw->next = cw->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    free((void *) cw);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
void *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
findPeer(Widget * pwidget)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    struct WidgetInfo   *cw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    Widget widgetParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    void * peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    if ((cw = findWidgetInfo(*pwidget)) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        return cw->peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    /* fix for 4053856, robi.khan@eng
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
       couldn't find peer corresponding to widget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
       but the widget may be child of one with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
       a peer, so recurse up the hierarchy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    widgetParent = XtParent(*pwidget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    if (widgetParent != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        peer = findPeer(&widgetParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        if( peer != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        /* found peer attached to ancestor of given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
           widget, so set widget return value as well */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            *pwidget = widgetParent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            return peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
awt_isAwtWidget(Widget widget)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    return (findWidgetInfo(widget) != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
static Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
awt_isAwtMenuWidget(Widget wdgt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    struct MenuList* cur;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    if (!XtIsSubclass(wdgt, xmRowColumnWidgetClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    for (cur = menu_list; cur != NULL; cur = cur->next) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        if (cur->menu == wdgt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
awt_addMenuWidget(Widget wdgt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    DASSERT(XtIsSubclass(wdgt, xmRowColumnWidgetClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    if (!awt_isAwtMenuWidget(wdgt)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        struct MenuList* ml = (struct MenuList*) malloc(sizeof(struct MenuList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        if (ml != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            ml->menu = wdgt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            ml->next = menu_list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            menu_list = ml;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            JNIEnv* env = (JNIEnv*)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
awt_delMenuWidget(Widget wdgt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    struct MenuList** pp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    struct MenuList* p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    DASSERT(XtIsSubclass(wdgt, xmRowColumnWidgetClass));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    for (pp = &menu_list; *pp != NULL; pp = &((*pp)->next)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if ((*pp)->menu == wdgt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            p = *pp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            *pp = (*pp)->next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            free((void*)p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
static Widget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
getShellWidgetByPart(Widget part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    for (i = 0; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        if (part == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        if (XtIsShell(part)) return part;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        part = XtParent(part);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
static Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
isTheSameShellWidget(Widget shell, Widget w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    Widget s1, s2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    if (shell == NULL || w == NULL) return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    s1 = getShellWidgetByPart(shell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    s2 = getShellWidgetByPart(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    if (s1 == s2 && s1 != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
static Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
shouldDispatchToWidget(XEvent * xev)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
  /* If this function returns False, that means that it has not pre-posted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     this event to Java. The caller will then dispatch the event to Motif,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     and our handlers will be called to post it to Java.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     If this function returns true, then this function has posted this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     to java before returning. The caller will not dispatch it to Motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     it will be dispatched to Motif via the putbackQueue after it has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     processed by Java */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    Window win;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    Widget widget = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    struct WidgetInfo *winfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    void *peer = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    Boolean cont = FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    switch (xev->type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        case KeyPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        case KeyRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            win = xev->xkey.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        case FocusIn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        case FocusOut:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            win = xev->xfocus.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        case ButtonPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        case ButtonRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            win = xev->xbutton.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        case MotionNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            win = xev->xmotion.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        case EnterNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        case LeaveNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            win = xev->xcrossing.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    if ((widget = XtWindowToWidget(awt_display, win)) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
    if (xev->type == KeyPress || xev->type == KeyRelease) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        Widget focusWidget = XmGetFocusWidget(widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        /* Fix for 4328561 by ibd@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
           If the widget is a Choice, the widget with focus is probably lying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
           outside the current widget's sub-hierarchy, so we have to go up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
           hierarchy to reach it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        if ((focusWidget == NULL) && XmIsMenuShell(widget)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            if ((widget = XtParent(widget)) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                focusWidget = XmGetFocusWidget(widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            /* In this case, focus widget should be CascadeButtonGadget type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
               but we should send the events to its parent */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            if (focusWidget != NULL && XmIsCascadeButtonGadget(focusWidget)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                widget = XtParent(focusWidget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                /* If something went wrong, restore the original status */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                widget = XtWindowToWidget(awt_display, win);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        /* if focus owner is null, redirect key events to focused window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        if (focusWidget == NULL && findWidgetInfo(widget) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            focusWidget = findTopLevelByShell(widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        /* If we are on a non-choice widget, process events in a normal way */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        if ((focusWidget != NULL) && (focusWidget != widget)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            if (isTheSameShellWidget(focusWidget, widget)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                focusWidget = findTopLevelByShell(widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            if (focusWidget != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                peer = findPeer(&focusWidget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            if (peer != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                widget = focusWidget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                win = xev->xkey.window = XtWindow(focusWidget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    if ((winfo = findWidgetInfo(widget)) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * Fix for bug 4145193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * If a menu is up (not just a popup menu), prevent awt components from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * getting any events until the menu is popped down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Before this fix, the fact that mouse/button events were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * preposted to the Java event queue was causing the ButtonRelease
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * (needed to pop menu down) to be seen by the menu's parent and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * not the menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    if (awtMenuIsActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        Widget focusWidget = XmGetFocusWidget(widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        if (focusWidget == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        /* If we are on a choice, dispatch the events to widget, but do not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
         * dispatch the events if we are on popped up menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        if (!XmIsRowColumn(widget) || !XmIsCascadeButtonGadget(focusWidget)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            /* Fix for 4328557 by ibd@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
             * If we are dragging mouse from choice and are currently outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
             * of it, dispatch events to the choice - the source of dragging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            if ((drag_source != NULL) && (widget != drag_source) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                (peer = findPeer(&drag_source))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                awt_canvas_handleEvent(drag_source, peer, xev, winfo, &cont, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    /* If the keyboard is grabbed by a popup (such as a choice) during
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
       a time when a focus proxy is in effect, the abovefocusIsOnMenu
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
       test will not detect the sitation because the focus will be on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
       the proxy. But we need events to go to Motif first, so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
       grab can be undone when appropriate. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    if (keyboardGrabbed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    /* If it's a keyboard event, we need to find the peer associated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    /* with the widget that has the focus rather than the widget */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    /* associated with the window in the X event. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    switch (xev->type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
      case KeyPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
      case KeyRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
          if (!(winfo->event_mask & java_awt_AWTEvent_KEY_EVENT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
              return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
          break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        case FocusIn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        case FocusOut:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            if (!(winfo->event_mask & java_awt_AWTEvent_FOCUS_EVENT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        case ButtonPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        case ButtonRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            if (!(winfo->event_mask & java_awt_AWTEvent_MOUSE_EVENT_MASK)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        case EnterNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        case LeaveNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
             * Do not post the enter/leave event if it's on a subwidget
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
             * within the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (!(winfo->event_mask & java_awt_AWTEvent_MOUSE_EVENT_MASK) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                widget != winfo->origin)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        case MotionNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            if (!(winfo->event_mask & java_awt_AWTEvent_MOUSE_MOTION_EVENT_MASK))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    peer = winfo->peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    /* If we found a widget and a suitable peer (either the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
       peer above or the one associated with the widget then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
       dispatch to it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    if (peer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * Fix for bug 4173714 - java.awt.button behaves differently under
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * Win32/Solaris.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * Component should not get any events when it's disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
    if (!XtIsSensitive(widget)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        if (xev->type == EnterNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            updateCursor(peer, CACHE_UPDATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    awt_canvas_handleEvent(widget, peer, xev, winfo, &cont, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    return (!cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
} /* shouldDispatchToWidget() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
void set_toolkit_busy(Boolean busy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    static jclass awtAutoShutdownClass = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    static jmethodID notifyBusyMethodID = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    static jmethodID notifyFreeMethodID = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    if (awtAutoShutdownClass == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        jclass awtAutoShutdownClassLocal = (*env)->FindClass(env, "sun/awt/AWTAutoShutdown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        DASSERT(awtAutoShutdownClassLocal != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        if (awtAutoShutdownClassLocal == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        awtAutoShutdownClass = (jclass)(*env)->NewGlobalRef(env, awtAutoShutdownClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        (*env)->DeleteLocalRef(env, awtAutoShutdownClassLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        notifyBusyMethodID = (*env)->GetStaticMethodID(env, awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                                                    "notifyToolkitThreadBusy", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        notifyFreeMethodID = (*env)->GetStaticMethodID(env, awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                                                    "notifyToolkitThreadFree", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        DASSERT(notifyBusyMethodID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        DASSERT(notifyFreeMethodID != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        if (notifyBusyMethodID == NULL || notifyFreeMethodID == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    } /* awtAutoShutdownClass == NULL*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    if (busy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        (*env)->CallStaticVoidMethod(env, awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                     notifyBusyMethodID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        (*env)->CallStaticVoidMethod(env, awtAutoShutdownClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                                     notifyFreeMethodID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
static int32_t debugPrintLineCount = 0;   /* limit debug output per line */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
 * This is the main Xt event loop for the AWT.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
 * Because java applications are multithreaded, but X and Xt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
 * are thread-dumb, we must make special considerations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
 * make ensure that the X/Xt libraries are not entered by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
 * multiple threads simultaneously.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
 * The biggest difference between the standard Xt loop
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
 * and this loop is that we go to great lengths never to block
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
 * in the X libraries. We poll() on the X event pipe, waiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
 * for events, rather than simply calling XtAppNextEvent() and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
 * blocking. If this thread were to block in XtAppNextEvent(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
 * no other thread could enter (e.g., to perform a paint or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
 * retrieve data).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
/* #ifdef DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    int32_t  numEventsHandled = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
/* #endif */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
awt_MToolkit_loop(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    XtInputMask iMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    int32_t  fdXPipe = -1;              /* pipe where X events arrive */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    /* only privileged thread should be running here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    DASSERT(awt_currentThreadIsPrivileged(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    /* The pipe where X events arrive */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    fdXPipe = ConnectionNumber(awt_display) ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    /* We execute events while locked, unlocking only when waiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * for an event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    /* Create the AWT utility pipe. See the comments on awt_pipe_init() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    awt_pipe_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Need to flush here in case data on the connection was read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * before we acquired the monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * I don't get this, but I'm too chicken to remove it. -jethro 2Sep98
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    AWT_FLUSHOUTPUT_NOW();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * ACTUALLY PROCESS EVENTS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    while(True) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        /* process all events in the queue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
/*      #ifdef DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
/*          numEventsHandled = 0; */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
/*      #endif */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
        while (((iMask = awt_events_pending(awt_appContext)) & XtIMAll) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
/*          #ifdef DEBUG */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                ++numEventsHandled;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
/*          #endif */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            processOneEvent(iMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        }  /* end while awt_events_pending() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        /* At this point, we have exhausted the event queue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        /* print the number of events handled in parens */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        DTRACE_PRINT1("(%d events)",(int32_t)numEventsHandled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        if (++debugPrintLineCount > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            DTRACE_PRINTLN("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            debugPrintLineCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        AWT_NOTIFY_ALL();               /* wake up modalWait() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        set_toolkit_busy(False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        /* Here, we wait for X events, outside of the X libs. When
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
         * it's likely that an event is waiting, we process the queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        waitForEvents(env, fdXPipe, AWT_READPIPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        set_toolkit_busy(True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    } /* while(True) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    /* If we ever exit the loop, must unlock the toolkit */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
} /* awt_MToolkit_loop() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
 * Creates the AWT utility pipe. This pipe exists solely so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
 * we can cause the main event thread to wake up from a poll() or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
 * select() by writing to this pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
awt_pipe_init(void) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
    if (awt_pipe_inited) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    if ( pipe ( awt_pipe_fds ) == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        ** the write wakes us up from the infinite sleep, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        ** then we cause a delay of AWT_FLUSHTIME and then we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        ** flush.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        int32_t flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        awt_set_poll_timeout (def_poll_timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        /* set the pipe to be non-blocking */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        flags = fcntl ( AWT_READPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        fcntl( AWT_READPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        flags = fcntl ( AWT_WRITEPIPE, F_GETFL, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        fcntl( AWT_WRITEPIPE, F_SETFL, flags | O_NDELAY | O_NONBLOCK );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        awt_pipe_inited = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        AWT_READPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        AWT_WRITEPIPE = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        awt_pipe_inited = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
} /* awt_pipe_init() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
static Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
proxyTopLevel(Window proxyWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    Window parent = None, root = None, *children = NULL, retvalue = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    uint32_t nchildren = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    Status res = XQueryTree(awt_display, proxyWindow, &root, &parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
             &children, &nchildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
    if (res != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (nchildren > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            retvalue = children[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        else retvalue = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        if (children != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            XFree(children);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        return retvalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        return None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
static jclass clazzF, clazzD = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
static Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
initClazzD(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
    jclass t_clazzD = (*env)->FindClass(env, "java/awt/Dialog");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    DASSERT(t_clazzD != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
    if (t_clazzD == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    clazzD = (*env)->NewGlobalRef(env, t_clazzD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
    DASSERT(clazzD != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    (*env)->DeleteLocalRef(env, t_clazzD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
isFrameOrDialog(jobject target, JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    if (clazzF == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        jclass t_clazzF = (*env)->FindClass(env, "java/awt/Frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        DASSERT(t_clazzF != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        if (t_clazzF == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        clazzF = (*env)->NewGlobalRef(env, t_clazzF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        DASSERT(clazzF != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        (*env)->DeleteLocalRef(env, t_clazzF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
    if (clazzD == NULL && !initClazzD(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
    return (*env)->IsInstanceOf(env, target, clazzF) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        (*env)->IsInstanceOf(env, target, clazzD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
isDialog(jobject target, JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    if (clazzD == NULL && !initClazzD(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
    return (*env)->IsInstanceOf(env, target, clazzD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
// Returns a local ref to a decorated owner of the target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
// or NULL if the target is Frame or Dialog itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
// The local ref returned should be deleted by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
getOwningFrameOrDialog(jobject target, JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    jobject _target = (*env)->NewLocalRef(env, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    jobject parent = _target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    Boolean isSelfFrameOrDialog = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    while (!isFrameOrDialog(parent, env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        isSelfFrameOrDialog = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        parent = (*env)->CallObjectMethod(env, _target, componentIDs.getParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        (*env)->DeleteLocalRef(env, _target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        _target = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
    if (isSelfFrameOrDialog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        (*env)->DeleteLocalRef(env, parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
    return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
Widget
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
findWindowsProxy(jobject window, JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
    struct ComponentData *cdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    jobject tlPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
    jobject owner_prev = NULL, owner_new = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    /* the owner of a Window is in its parent field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    /* we may have a chain of Windows; go up the chain till we find the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
       owning Frame or Dialog */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    if ((*env)->EnsureLocalCapacity(env, 4) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    if (window == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    owner_prev = (*env)->NewLocalRef(env, window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    while (!JNU_IsNull(env, owner_prev) && !(isFrameOrDialog(owner_prev, env))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        owner_new = (*env)->CallObjectMethod(env, owner_prev, componentIDs.getParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        (*env)->DeleteLocalRef(env, owner_prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        owner_prev = owner_new;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
    if (owner_prev == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    tlPeer = (*env)->GetObjectField(env, owner_prev, componentIDs.peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    (*env)->DeleteLocalRef(env, owner_prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
    if (tlPeer == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    cdata = (struct ComponentData *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        JNU_GetLongFieldAsPtr(env, tlPeer, mComponentPeerIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    (*env)->DeleteLocalRef(env, tlPeer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    if (cdata == NULL) return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    return(findFocusProxy(cdata->widget));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
jobject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
findTopLevel(jobject peer, JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    jobject target_prev = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    static jclass clazzW = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    if ((*env)->EnsureLocalCapacity(env, 3) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    if (clazzW == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        jclass t_clazzW = (*env)->FindClass(env, "java/awt/Window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        if ((*env)->ExceptionOccurred(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            (*env)->ExceptionDescribe(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        DASSERT(t_clazzW != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        if (t_clazzW == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        clazzW = (*env)->NewGlobalRef(env, t_clazzW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        DASSERT(clazzW != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        (*env)->DeleteLocalRef(env, t_clazzW);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    target_prev = (*env)->GetObjectField(env, peer, mComponentPeerIDs.target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    if (target_prev == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    while ((target_prev != NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
           && !(*env)->IsInstanceOf(env, target_prev, clazzW) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        /* go up the hierarchy until we find a window */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        jobject target_new = (*env)->CallObjectMethod(env, target_prev, componentIDs.getParent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        (*env)->DeleteLocalRef(env, target_prev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        target_prev = target_new;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
    return target_prev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
static Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
rootWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    Window root = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    Window parent = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    Window *children = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    uint32_t nchildren = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    if (w != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        Status res = XQueryTree(awt_display, w, &root, &parent, &children, &nchildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        if (res == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            return None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        if (children != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            XFree(children);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
  return root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        return None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
Boolean IsRootOf(Window root, Window child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
    Window w_root = None, w_parent = None, * children = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    uint32_t c_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
    if (root == None || child == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        w_root = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        w_parent = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        children = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        c_count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        if (XQueryTree(awt_display, child, &w_root, &w_parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                       &children, &c_count)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            if (children != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                XFree(children);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
            if (w_parent == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            if (w_parent == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        child = w_parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
    } while (True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
Window findShellByProxy(Window proxy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
    Widget proxy_wid = XtWindowToWidget(awt_display, proxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
    while (proxy_wid != NULL && !XtIsShell(proxy_wid)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        proxy_wid = XtParent(proxy_wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    if (proxy_wid == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        return None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    return XtWindow(proxy_wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
// Window which contains focus owner when focus proxy is enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
Window trueFocusWindow = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
// Window which works as proxy for input events for real focus owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
Window focusProxyWindow = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
void clearFocusPathOnWindow(Window win) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
    if (focusProxyWindow != None && IsRootOf(win, trueFocusWindow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        XEvent ev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        memset(&ev, 0, sizeof(ev));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
        ev.type = FocusOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        ev.xany.send_event = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        ev.xany.display = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        ev.xfocus.mode = NotifyNormal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
        ev.xfocus.detail = NotifyNonlinear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            Window root = rootWindow(trueFocusWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            JNIEnv *env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            ev.xfocus.window = trueFocusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            while (ev.xfocus.window != root &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                   ev.xfocus.window != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                Widget w = XtWindowToWidget(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                                            ev.xfocus.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                awt_put_back_event(env, &ev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                if (w == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                if (XtParent(w) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    ev.xfocus.window = XtWindow(XtParent(w));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    ev.xfocus.window = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        XSetInputFocus(awt_display, findShellByProxy(focusProxyWindow), RevertToPointerRoot, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        trueFocusWindow = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        focusProxyWindow = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
void clearFocusPath(Widget shell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    Window w = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
    if (shell == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    w = XtWindow(shell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    clearFocusPathOnWindow(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
void globalClearFocusPath(Widget focusOwnerShell ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
    if (focusProxyWindow != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        Window shellWindow = findShellByProxy(trueFocusWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        if (shellWindow != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            Widget shell = XtWindowToWidget(awt_display, shellWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            if (shell != NULL && shell != focusOwnerShell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                clearFocusPath(shell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
focusEventForProxy(XEvent xev,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                   JNIEnv *env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                   Window *trueFocusWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                   Window *focusProxyWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
    DASSERT (trueFocusWindow != NULL && focusProxyWindow != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
  if (xev.type == FocusOut) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
    if (xev.xfocus.window == *focusProxyWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            if (*trueFocusWindow != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                Window root = rootWindow(*trueFocusWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
      focusOutEvent.xfocus.window = *trueFocusWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
      printf(" nulling out proxy; putting back event"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
             "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
      while (focusOutEvent.xfocus.window != root &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
             focusOutEvent.xfocus.window != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        Widget w = XtWindowToWidget(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                                    focusOutEvent.xfocus.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        awt_put_back_event(env, &focusOutEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        if (w != NULL && XtParent(w) != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
          focusOutEvent.xfocus.window = XtWindow(XtParent(w));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
          focusOutEvent.xfocus.window = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
      *trueFocusWindow = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
      *focusProxyWindow = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
      printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
    printf("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
focusEventForFrame(XEvent xev, Window focusProxyWindow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
  if (xev.type == FocusIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
    if (focusProxyWindow != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
      /* eat it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
    } else /* FocusIn on Frame or Dialog */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
      XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
  } else /* FocusOut on Frame or Dialog */{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
focusEventForWindow(XEvent xev, JNIEnv *env, Window *trueFocusWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                    Window *focusProxyWindow, jobject target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
  XEvent pev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
  if (xev.type == FocusIn && xev.xfocus.mode == NotifyNormal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
    /* If it's a FocusIn, allow it to process, then set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
       focus to focus proxy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
    Widget focusProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
    focusProxy = findWindowsProxy(target, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
    if (focusProxy != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
      XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
      *focusProxyWindow = XtWindow(focusProxy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
      XSetInputFocus(awt_display, *focusProxyWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                     RevertToParent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                     CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
      XPeekEvent(awt_display, &pev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
      while (pev.type == FocusIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        XNextEvent(awt_display, &xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        XPeekEvent(awt_display, &pev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
      *trueFocusWindow = xev.xany.window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
    } /* otherwise error */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
  } else /* FocusOut */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    /* If it's a FocusOut on a Window, discard it unless
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
       it's an event generated by us. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    if (xev.xany.send_event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
      XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
isAncestor(Window ancestor, Window child) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
  Window *children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
  uint32_t nchildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
  Boolean retvalue = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
  while (child != ancestor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
    Window parent, root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    Status status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    status = XQueryTree(awt_display, child, &root, &parent,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                        &children, &nchildren);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    if (status == 0) return False; /* should be an error of some sort? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
    if (parent == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
      if (child != ancestor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        retvalue = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        retvalue = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    if (parent == ancestor) { retvalue = True; break; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
    if (nchildren > 0) XFree(children);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
    child = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
  if (nchildren > 0) XFree(children);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
  return retvalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
 * Returns focusability of the corresponding Java Window object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
isFocusableWindow(Window w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
    Widget wid = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
    JNIEnv *env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
    wid = XtWindowToWidget(awt_display, w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
    while (wid != NULL && !XtIsShell(wid)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
        wid = XtParent(wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
    // If the window doesn't have shell consider it focusable as all windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
    // are focusable by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    if (wid == NULL) return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
    return isFocusableWindowByShell(env, wid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
void postUngrabEvent(Widget shell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    JNIEnv *env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    Widget canvas = findTopLevelByShell(shell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
    if (canvas != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        jobject peer = findPeer(&canvas);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        if (peer != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            JNU_CallMethodByName(env, NULL, peer, "postUngrabEvent", "()V", NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
Boolean eventInsideGrabbed(XEvent * ev) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    if (grabbed_widget == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
    switch (ev->xany.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
      case LeaveNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
      case ButtonPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
      case ButtonRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
      case MotionNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
      case EnterNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
          JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
          Widget grab = findTopLevelByShell(grabbed_widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
          if (grab != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
              jobject peer = findPeer(&grab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
              Widget target = XtWindowToWidget(awt_display, ev->xbutton.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
              jobject targetPeer = findPeer(&target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
              if (peer != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                  return JNU_CallMethodByName(env, NULL, peer, "processUngrabMouseEvent", "(Lsun/awt/motif/MComponentPeer;III)Z",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                                              targetPeer, ev->xbutton.x_root, ev->xbutton.y_root,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                                              ev->xany.type, NULL).z;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
          return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
      case FocusOut:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
          if (ev->xfocus.window == XtWindow(grabbed_widget) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
              isAncestor(XtWindow(grabbed_widget), ev->xfocus.window))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
          {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
              postUngrabEvent(grabbed_widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
              return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
          return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
 * Processes and removes one X/Xt event from the Xt event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
 * Handles events pushed back via awt_put_back_event() FIRST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
 * then new events on the X queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
processOneEvent(XtInputMask iMask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            XEvent xev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            Boolean haveEvent = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            if (putbackQueueCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                // There is a pushed-back event - handle it first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                if (awt_get_next_put_back_event(&xev) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                    if (xev.xany.send_event != SPECIAL_KEY_EVENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                        if (xev.type == FocusOut) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                            printf("putback FocusOut on window %d, mode %d, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                                   "detail %d, send_event  %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                                   xev.xfocus.window, xev.xfocus.mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                                   xev.xfocus.detail, xev.xfocus.send_event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                        eventNumber++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                        XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                        haveEvent = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            if (haveEvent || XtAppPeekEvent(awt_appContext, &xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
             /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
              * Fix for BugTraq ID 4041235, 4100167:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
              * First check that the event still has a widget, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
              * the widget may have been destroyed by another thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
              */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
              Widget widget=XtWindowToWidget(awt_display, xev.xany.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
              eventNumber++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
#ifdef __linux__
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
              statusWindowEventHandler(xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
              xembed_eventHandler(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
              xembed_serverEventHandler(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
              syncWait_eventHandler(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
              if (!haveEvent && awt_dnd_process_event(&xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                  return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
              if ((widget == NULL) || (!XtIsObject(widget)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                  (widget->core.being_destroyed)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                 * if we get here, the event could be one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                 * the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                 * - notification that a "container" of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                 *    any of our embedded frame has been moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                 * - event understandable by XFilterEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                 * - for one of our old widget which has gone away
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                XNextEvent(awt_display, &xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                if (widget == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                    /* an embedded frame container has been moved? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
                    if (awt_util_processEventForEmbeddedFrame(&xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                    /* manager selections related event? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                    if (awt_mgrsel_processEvent(&xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                 * Fix for BugTraq ID 4196573:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                 * Call XFilterEvent() to give a chance to X Input
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                 * Method to process this event before being
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                 * discarded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                (void) XFilterEvent(&xev, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
              /* There is an X event on the queue. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
              switch (xev.type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
              case KeyPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
              case KeyRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
              case ButtonPress:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
              case ButtonRelease:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
              case MotionNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
              case EnterNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
              case LeaveNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                /* Fix for BugTraq ID 4048060. Dispatch scrolling events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                   immediately to the ScrollBar widget to prevent spurious
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                   continuous scrolling. Otherwise, if the application is busy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                   the ButtonRelease event is not dispatched in time to prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                   a ScrollBar timeout from expiring, and restarting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                   continuous scrolling timer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                  if ((xev.type == ButtonPress                          ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                       xev.type == ButtonRelease                                ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                       (xev.type == MotionNotify                                &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                        (xev.xmotion.state == Button1Mask                       ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                         xev.xmotion.state == Button2Mask                       ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                         xev.xmotion.state == Button3Mask)))            &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                      (XtIsSubclass(widget, xmScrollBarWidgetClass))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                      /* Use XNextEvent instead of XtAppNextEvent, because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                         XtAppNextEvent processes timers before getting the next X
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                         event, causing a race condition, since the TimerEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                         callback in the ScrollBar widget restarts the continuous
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                         scrolling timer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                      XNextEvent(awt_display, &xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                      XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                      XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                      // This is the event on scrollbar.  Key, Motion,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                      // Enter/Leave dispatch as usual, Button should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                      // generate Ungrab after Java mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                      if (xev.type == ButtonPress && grabbed_widget != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                          eventInsideGrabbed(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                  else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                      if (!haveEvent) XtAppNextEvent(awt_appContext, &xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                      // This is an event on one of our widgets.  Key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                      // Motion, Enter/Leave dispatch as usual, Button
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                      // should generate Ungrab after Java mouse event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
/*                       if (grabbed_widget != NULL && !eventInsideGrabbed(&xev)) { */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
/*                           return; */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
/*                       } */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                      if (xev.type == ButtonPress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                          Window window = findShellByProxy(xev.xbutton.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                          if (window != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                              XWindowAttributes winAttr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                              memset(&winAttr, 0, sizeof(XWindowAttributes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                              XGetWindowAttributes(awt_display, window, &winAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                              if (winAttr.override_redirect == TRUE && isFocusableWindow(window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                                  XSetInputFocus(awt_display, window, RevertToPointerRoot, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                      if(xev.type == KeyPress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                          printf("KeyPress on window %d\n", xev.xany.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                    /* this could be moved to shouldDispatchToWidget */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                    /* if there is a proxy in effect, dispatch key events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                       through the proxy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
                    if ((xev.type == KeyPress || xev.type == KeyRelease) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
                        !keyboardGrabbed && !haveEvent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
                        if (focusProxyWindow != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
                            Widget widget;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
                            struct WidgetInfo *winfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
                            Boolean cont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
                            /* Key event should be posted to the top-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
                               widget of the proxy */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                            xev.xany.window = proxyTopLevel(focusProxyWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                            widget = XtWindowToWidget(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                                                      xev.xany.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                            if (widget == NULL) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                            if ((winfo = findWidgetInfo(widget)) == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                            awt_canvas_handleEvent(widget, winfo->peer, &xev,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                                                   winfo, &cont, TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                    if (!shouldDispatchToWidget(&xev)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                        XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                    // See comment above - "after time" is here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    if (grabbed_widget != NULL && xev.type == ButtonPress) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                        eventInsideGrabbed(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
              case FocusIn:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
              case FocusOut: {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                  void *peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                  jobject target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                  JNIEnv *env = (JNIEnv *) JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                  if (xev.type == FocusIn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
                      fprintf(stderr, "FocusIn on window %x, mode %d, detail %d, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
                             "send_event %d\n", xev.xfocus.window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
                             xev.xfocus.mode, xev.xfocus.detail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                             xev.xfocus.send_event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
                  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                      fprintf(stderr, "FocusOut on window %x, mode %d, detail %d, "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                             "send_event %d\n", xev.xfocus.window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                             xev.xfocus.mode, xev.xfocus.detail,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                             xev.xfocus.send_event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                  XtAppNextEvent(awt_appContext, &xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                  if (xev.xfocus.detail == NotifyVirtual ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                      xev.xfocus.detail == NotifyNonlinearVirtual) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                      printf("discarding\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                  // Check for xembed on this window. If it is active and this is not XEmbed focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                  // event(send_event = 0) then we should skip it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                  if (isXEmbedActiveByWindow(xev.xfocus.window) && !xev.xfocus.send_event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                  /* In general, we need to to block out focus events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                     that are caused by keybaord grabs initiated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                     dragging the title bar or the scrollbar. But we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                     need to let through the ones that are aimed at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                     choice boxes or menus. So we keep track of when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                     the keyboard is grabbed by a popup. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                  if (awt_isAwtMenuWidget(widget)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                    if (xev.type == FocusIn &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                        xev.xfocus.mode == NotifyGrab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                          extern Boolean poppingDown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                          if (!poppingDown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                      keyboardGrabbed = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                      } else /* FocusOut */ {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                          if (xev.type == FocusOut &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                              xev.xfocus.mode == NotifyUngrab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                        keyboardGrabbed = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                  if (focusProxyWindow != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                      printf("non-null proxy; proxy = %d ", focusProxyWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                      if (trueFocusWindow != None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                        /* trueFocusWindow should never be None here, but if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                           things ever get skewed, we want to be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                           recover rather than crash */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                        focusEventForProxy(xev, env, &trueFocusWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                                           &focusProxyWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                      } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                        /* beartrap -- remove before shipping */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                        /* printf("trueFocusWindow None in processOneEvent;\n"); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                        /* printf("Please file a bug\n"); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                  peer = findPeer(&widget);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                  if (peer == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                      printf("null peer -- shouldn't see in java handler\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                      XtDispatchEvent(&xev);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                  /* Find the top-level component */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                  if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                  target = findTopLevel(peer, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                  if (target == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                      JNU_ThrowNullPointerException(env, "component without a "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                                                    "window");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                  if (isFrameOrDialog(target, env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                      printf("Focus event directed at a frame; frame = %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                             xev.xany.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                      focusEventForFrame(xev, focusProxyWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                      (*env)->DeleteLocalRef(env, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                  } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                      printf("Focus event directed at a window; window = %d\n",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                             xev.xany.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                      focusEventForWindow(xev, env, &trueFocusWindow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                                          &focusProxyWindow, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                      (*env)->DeleteLocalRef(env, target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
              case UnmapNotify:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
#ifdef DEBUG_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                printf("Unmap on window %d\n", xev.xany.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                printf("True focus window is %d\n", trueFocusWindow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                clearFocusPathOnWindow(xev.xunmap.window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
              default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                XtAppProcessEvent(awt_appContext, iMask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
              /* There must be a timer, alternate input, or signal event. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
              XtAppProcessEvent(awt_appContext, iMask & ~XtIMXEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
} /* processOneEvent() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
 * Waits for X/Xt events to appear on the pipe. Returns only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
 * it is likely (but not definite) that there are events waiting to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
 * be processed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
 * This routine also flushes the outgoing X queue, when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
 * awt_next_flush_time has been reached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
 * If fdAWTPipe is greater or equal than zero the routine also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
 * checks if there are events pending on the putback queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
waitForEvents(JNIEnv *env, int32_t fdXPipe, int32_t fdAWTPipe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        while ((fdAWTPipe >= 0 && awt_events_pending(awt_appContext) == 0) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
               (fdAWTPipe <  0 && XtAppPending(awt_appContext) == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
#ifdef USE_SELECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            performSelect(env,fdXPipe,fdAWTPipe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            performPoll(env,fdXPipe,fdAWTPipe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
            if ((awt_next_flush_time > 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                (awtJNI_TimeMillis() > awt_next_flush_time)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                AWT_FLUSHOUTPUT_NOW();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
        }  /* end while awt_events_pending() == 0 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
} /* waitForEvents() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
/*************************************************************************
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
 **                                                                     **
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
 ** WE USE EITHER select() OR poll(), DEPENDING ON THE USE_SELECT       **
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
 ** COMPILE-TIME CONSTANT.                                              **
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
 **                                                                     **
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
 *************************************************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
#ifdef USE_SELECT
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
static struct fd_set rdset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
struct timeval sel_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
 * Performs select() on both the X pipe and our AWT utility pipe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
 * Returns when data arrives or the operation times out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
 * Not all Xt events come across the X pipe (e.g., timers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
 * and alternate inputs), so we must time out every now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
 * then to check the Xt event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
 * The fdAWTPipe will be empty when this returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
performSelect(JNIEnv *env, int32_t fdXPipe, int32_t fdAWTPipe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            int32_t result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            int32_t count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            int32_t nfds = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            uint32_t timeout = awt_get_poll_timeout(False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
            /* Fixed 4250354 7/28/99 ssi@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
             * Cleaning up Global Refs in case of No Events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
            awtJNI_CleanupGlobalRefs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            FD_ZERO( &rdset );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            FD_SET(fdXPipe, &rdset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
            if (fdAWTPipe >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                nfds++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                FD_SET(fdAWTPipe, &rdset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
            if (timeout == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                // be sure other threads get a chance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                awtJNI_ThreadYield(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            // set the appropriate time values. The DASSERT() in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
            // MToolkit_run() makes sure that this will not overflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
            sel_time.tv_sec = (timeout * 1000) / (1000 * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
            sel_time.tv_usec = (timeout * 1000) % (1000 * 1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
            AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            result = select(nfds, &rdset, 0, 0, &sel_time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
            /* reset tick if this was not a time out */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            if (result == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                /* select() timed out -- update timeout value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                awt_get_poll_timeout(True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            if (fdAWTPipe >= 0 && FD_ISSET ( fdAWTPipe, &rdset ) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                /* There is data on the AWT pipe - empty it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                    count = read(fdAWTPipe, read_buf, AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                } while (count == AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
} /* performSelect() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
#else /* !USE_SELECT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
 * Polls both the X pipe and our AWT utility pipe. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
 * when there is data on one of the pipes, or the operation times
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
 * out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
 * Not all Xt events come across the X pipe (e.g., timers
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
 * and alternate inputs), so we must time out every now and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
 * then to check the Xt event queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
 * The fdAWTPipe will be empty when this returns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
performPoll(JNIEnv *env, int32_t fdXPipe, int32_t fdAWTPipe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
            static struct pollfd pollFds[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
            uint32_t timeout = awt_get_poll_timeout(False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            int32_t result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
            int32_t count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
            /* Fixed 4250354 7/28/99 ssi@sparc.spb.su
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
             * Cleaning up Global Refs in case of No Events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
            awtJNI_CleanupGlobalRefs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            pollFds[0].fd = fdXPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            pollFds[0].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
            pollFds[0].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
            pollFds[1].fd = fdAWTPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            pollFds[1].events = POLLRDNORM;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            pollFds[1].revents = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
            AWT_NOFLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
            /* print the poll timeout time in brackets */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
            DTRACE_PRINT1("[%dms]",(int32_t)timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
            if (++debugPrintLineCount > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                DTRACE_PRINTLN("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                debugPrintLineCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
            /* ACTUALLY DO THE POLL() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
            if (timeout == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
                // be sure other threads get a chance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
                awtJNI_ThreadYield(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
            result = poll( pollFds, 2, (int32_t) timeout );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            DTRACE_PRINT1("[poll()->%d]", result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
            if (++debugPrintLineCount > 8) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                DTRACE_PRINTLN("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
                debugPrintLineCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            if (result == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                /* poll() timed out -- update timeout value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                awt_get_poll_timeout(True);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            if ( pollFds[1].revents )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
                /* There is data on the AWT pipe - empty it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                    count = read(AWT_READPIPE, read_buf, AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                } while (count == AWT_POLL_BUFSIZE );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                DTRACE_PRINTLN1("wokeup on AWTPIPE, timeout:%d", timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
} /* performPoll() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
#endif /* !USE_SELECT */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
 * Pushes an X event back on the queue to be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
 * later.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
 * Ignores the request if event is NULL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
awt_put_back_event(JNIEnv *env, XEvent *event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
    Boolean addIt = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
    if (putbackQueueCount >= putbackQueueCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        /* not enough room - alloc 50% more space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
        int32_t newCapacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        XEvent *newQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        newCapacity = putbackQueueCapacity * 3 / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
        if ((newCapacity - putbackQueueCapacity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
                                        < PUTBACK_QUEUE_MIN_INCREMENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
            /* always increase by at least min increment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
            newCapacity = putbackQueueCapacity + PUTBACK_QUEUE_MIN_INCREMENT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
        newQueue = (XEvent*)realloc(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                        putbackQueue, newCapacity*(sizeof(XEvent)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
        if (newQueue == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
            JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
            addIt = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            putbackQueue = newQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
            putbackQueueCapacity = newCapacity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    if (addIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
        char oneChar = 'p';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
        memcpy(&(putbackQueue[putbackQueueCount]), event, sizeof(XEvent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
        putbackQueueCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
        // wake up the event loop, if it's sleeping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
        write (AWT_WRITEPIPE, &oneChar, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
} /* awt_put_back_event() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
 * Gets the next event that has been pushed back onto the queue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
 * Returns 0 and fills in xev_out if successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
static int32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
awt_get_next_put_back_event(XEvent *xev_out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
    Boolean err = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
    if (putbackQueueCount < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        err = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        memcpy(xev_out, &(putbackQueue[0]), sizeof(XEvent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
    if (!err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        /* remove it from the queue */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        if (putbackQueueCount == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
            // queue is now empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
            if (putbackQueueCapacity > PUTBACK_QUEUE_MIN_INCREMENT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                /* Too much space -- delete it and rebuild later */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
                free(putbackQueue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
                putbackQueue = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
                putbackQueueCapacity = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
            /* more than 1 event in queue - shift all events to the left */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
            /* We don't free the allocated memory until the queue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
               becomes empty, just 'cause it's easier that way. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
            /* NOTE: use memmove(), because the memory blocks overlap */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
            memmove(&(putbackQueue[0]), &(putbackQueue[1]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
                (putbackQueueCount-1)*sizeof(XEvent));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
        --putbackQueueCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
    DASSERT(putbackQueueCount >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    return (err? -1:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
} /* awt_get_next_put_back_event() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
 * Determines whether or not there are X or Xt events pending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
 * Looks at the putbackQueue.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
static XtInputMask
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
awt_events_pending(XtAppContext appContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
    XtInputMask imask = 0L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
    imask = XtAppPending(appContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
    if (putbackQueueCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        imask |= XtIMXEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    return imask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
#ifndef NOMODALFIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
#define WIDGET_ARRAY_SIZE 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
static int32_t arraySize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
static int32_t arrayIndx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
static Widget *dShells = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
awt_shellPoppedUp(Widget shell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
                   XtPointer modal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
                   XtPointer call_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
    if (arrayIndx == arraySize ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
        /* if we have not allocate an array, do it first */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        if (arraySize == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
            arraySize += WIDGET_ARRAY_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
            dShells = (Widget *) malloc(sizeof(Widget) * arraySize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
            arraySize += WIDGET_ARRAY_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
            dShells = (Widget *) realloc((void *)dShells, sizeof(Widget) * arraySize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
    dShells[arrayIndx] = shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
    arrayIndx++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
awt_shellPoppedDown(Widget shell,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
                   XtPointer modal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                   XtPointer call_data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
    arrayIndx--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
    if (dShells[arrayIndx] == shell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        dShells[arrayIndx] = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        int32_t i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
        /* find the position of the shell in the array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
        for (i = arrayIndx; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
            if (dShells[i] == shell) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        /* remove the found element */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
        while (i <= arrayIndx-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
            dShells[i] = dShells[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
awt_isWidgetModal(Widget widget)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
    Widget w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
    for (w = widget; !XtIsShell(w); w = XtParent(w)) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
    while (w != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        if (w == dShells[arrayIndx-1]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
            return True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        w = XtParent(w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
    return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
awt_isModal()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
    return (arrayIndx > 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
#endif // NOMODALFIX
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
 * Simply waits for terminateFn() to return True. Waits on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
 * awt lock and is notified to check its state by the main event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
 * loop whenever the Xt event queue is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
 * NOTE: when you use this routine check if it can be called on the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
 * dispatch thread during drag-n-drop operation and update
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
 * secondary_loop_event() predicate to prevent deadlock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
awt_MToolkit_modalWait(int32_t (*terminateFn) (void *data), void *data )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
    AWT_FLUSHOUTPUT_NOW();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
    while ((*terminateFn) (data) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        AWT_WAIT(AWT_MAX_POLL_TIMEOUT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
        if ((*env)->ExceptionCheck(env)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
            (*env)->ExceptionClear(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
    AWT_NOTIFY_ALL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
static uint32_t
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
colorToRGB(XColor * color)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
    int32_t rgb = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
    rgb |= ((color->red >> 8) << 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    rgb |= ((color->green >> 8) << 8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
    rgb |= ((color->blue >> 8) << 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
    return rgb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
 * fix for bug #4088106 - ugly text boxes and grayed out looking text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
XmColorProc oldColorProc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
ColorProc(XColor* bg_color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
          XColor* fg_color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
          XColor* sel_color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
          XColor* ts_color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
          XColor* bs_color)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    unsigned long plane_masks[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
    unsigned long colors[5];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
    /* use the default procedure to calculate colors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
    oldColorProc(bg_color, fg_color, sel_color, ts_color, bs_color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
    /* check if there is enought free color cells */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
    if (XAllocColorCells(awt_display, defaultConfig->awt_cmap, False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
        plane_masks, 0, colors, 5)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
        XFreeColors(awt_display, defaultConfig->awt_cmap, colors, 5, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
    /* find the closest matches currently available */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
    fg_color->pixel = defaultConfig->AwtColorMatch(fg_color->red   >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
                                                   fg_color->green >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
                                                   fg_color->blue  >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
                                                   defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
    fg_color->flags = DoRed | DoGreen | DoBlue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    XQueryColor(awt_display, defaultConfig->awt_cmap, fg_color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
    sel_color->pixel = defaultConfig->AwtColorMatch(sel_color->red   >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
                                                    sel_color->green >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
                                                    sel_color->blue  >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                                                    defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
    sel_color->flags = DoRed | DoGreen | DoBlue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
    XQueryColor(awt_display, defaultConfig->awt_cmap, sel_color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
    ts_color->pixel = defaultConfig->AwtColorMatch(ts_color->red   >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
                                                   ts_color->green >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
                                                   ts_color->blue  >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                                                   defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
    ts_color->flags = DoRed | DoGreen | DoBlue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
    XQueryColor(awt_display, defaultConfig->awt_cmap, ts_color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    bs_color->pixel = defaultConfig->AwtColorMatch(bs_color->red   >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
                                                   bs_color->green >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
                                                   bs_color->blue  >> 8,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                                                   defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    bs_color->flags = DoRed | DoGreen | DoBlue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
    XQueryColor(awt_display, defaultConfig->awt_cmap, bs_color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
 * Read _XSETTINGS_SETTINGS property from _XSETTINGS selection owner
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
 * and pass its value to the java world for processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
/*static*/ void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
awt_xsettings_update(int scr, Window owner, void *cookie)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
    Display *dpy = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
    int status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
    JNIEnv *env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
    jobject mtoolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    jmethodID upcall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
    jbyteArray array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
    struct xsettings_callback_cookie *upcall_cookie = cookie;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
    /* Returns of XGetWindowProperty */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
    Atom actual_type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
    int actual_format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
    unsigned long nitems;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    unsigned long bytes_after;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
    unsigned char *xsettings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
    DTRACE_PRINTLN2("XS: update screen %d, owner 0x%08lx",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
                    scr, owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
#if 1 /* XXX: kludge */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
     * As toolkit cannot yet cope with per-screen desktop properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
     * only report XSETTINGS changes on the default screen.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
     * should be "good enough" for most cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
    if (scr != DefaultScreen(dpy)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
        DTRACE_PRINTLN2("XS: XXX: default screen is %d, update is for %d, ignoring", DefaultScreen(dpy), scr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
#endif /* kludge */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
    env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
    DASSERT(env != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
    DASSERT(upcall_cookie != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
    mtoolkit = upcall_cookie->mtoolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
    upcall = upcall_cookie->upcallMID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
    DASSERT(!JNU_IsNull(env, mtoolkit));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
    DASSERT(upcall != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
     * XXX: move awt_getPropertyFOO from awt_wm.c to awt_util.c and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
     * use the appropriate one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
    status = XGetWindowProperty(dpy, owner,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
                 _XA_XSETTINGS_SETTINGS, 0, 0xFFFF, False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                 _XA_XSETTINGS_SETTINGS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                 &actual_type, &actual_format, &nitems, &bytes_after,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                 &xsettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
    if (status != Success) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
        DTRACE_PRINTLN("XS:   unable to read _XSETTINGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    if (xsettings == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
        DTRACE_PRINTLN("XS:   reading _XSETTINGS, got NULL");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
    if (actual_type != _XA_XSETTINGS_SETTINGS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
        XFree(xsettings);       /* NULL data already catched above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
        DTRACE_PRINTLN("XS:   _XSETTINGS_SETTINGS is not of type _XSETTINGS_SETTINGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
    DTRACE_PRINTLN1("XS:   read %lu bytes of _XSETTINGS_SETTINGS",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                    nitems);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
    /* ok, propagate xsettings to the toolkit for processing */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
        DTRACE_PRINTLN("XS:   EnsureLocalCapacity failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        XFree(xsettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
    array = (*env)->NewByteArray(env, (jint)nitems);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
    if (JNU_IsNull(env, array)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        DTRACE_PRINTLN("awt_xsettings_update: NewByteArray failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        XFree(xsettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
    (*env)->SetByteArrayRegion(env, array, 0, (jint)nitems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
                               (jbyte *)xsettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
    XFree(xsettings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
    (*env)->CallVoidMethod(env, mtoolkit, upcall, (jint)scr, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
    (*env)->DeleteLocalRef(env, array);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
 * Event handler for events on XSETTINGS selection owner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
 * We are interested in PropertyNotify only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
awt_xsettings_callback(int scr, XEvent *xev, void *cookie)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
    Display *dpy = awt_display; /* xev->xany.display */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
    XPropertyEvent *ev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
    if (xev->type != PropertyNotify) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        DTRACE_PRINTLN2("XS: awt_xsettings_callback(%d) event %d ignored",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
                        scr, xev->type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
    ev = &xev->xproperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
    if (ev->atom == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
        DTRACE_PRINTLN("XS: awt_xsettings_callback(%d) atom == None");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
#ifdef DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
        char *name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
        DTRACE_PRINT2("XS: awt_xsettings_callback(%d) 0x%08lx ",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                      scr, ev->window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
        name = XGetAtomName(dpy, ev->atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
        if (name == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
            DTRACE_PRINT1("atom #%d", ev->atom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            DTRACE_PRINT1("%s", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
            XFree(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
        DTRACE_PRINTLN1(" %s", ev->state == PropertyNewValue ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                                        "changed" : "deleted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
    if (ev->atom != _XA_XSETTINGS_SETTINGS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
        DTRACE_PRINTLN("XS:   property != _XSETTINGS_SETTINGS ...  ignoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
    if (ev->state == PropertyDelete) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
        /* XXX: notify toolkit to reset to "defaults"? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
    awt_xsettings_update(scr, ev->window, cookie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
 * Owner of XSETTINGS selection changed on the given screen.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
awt_xsettings_owner_callback(int scr, Window owner, long *data_unused,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                             void *cookie)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
    if (owner == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
        DTRACE_PRINTLN("XS: awt_xsettings_owner_callback: owner = None");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
        /* XXX: reset to defaults??? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
    DTRACE_PRINTLN1("XS: awt_xsettings_owner_callback: owner = 0x%08lx",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
                    owner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
    awt_xsettings_update(scr, owner, cookie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
 * Returns a reference to the class java.awt.Component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
jclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
getComponentClass(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
    static jclass componentCls = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
    // get global reference of java/awt/Component class (run only once)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
    if (componentCls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
        jclass componentClsLocal = (*env)->FindClass(env, "java/awt/Component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
        DASSERT(componentClsLocal != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
        if (componentClsLocal == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
            /* exception already thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
        componentCls = (jclass)(*env)->NewGlobalRef(env, componentClsLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
        (*env)->DeleteLocalRef(env, componentClsLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
    return componentCls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
 * Returns a reference to the class java.awt.MenuComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
jclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
getMenuComponentClass(JNIEnv *env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
    static jclass menuComponentCls = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
    // get global reference of java/awt/MenuComponent class (run only once)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
    if (menuComponentCls == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        jclass menuComponentClsLocal = (*env)->FindClass(env, "java/awt/MenuComponent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
        DASSERT(menuComponentClsLocal != NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        if (menuComponentClsLocal == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            /* exception already thrown */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
            return NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
        menuComponentCls = (jclass)(*env)->NewGlobalRef(env, menuComponentClsLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
        (*env)->DeleteLocalRef(env, menuComponentClsLocal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
    return menuComponentCls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
 * Method:    init
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
 * Signature: (Ljava/lang/String;)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
Java_sun_awt_motif_MToolkit_init(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
    jstring mainClassName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
    char *appName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
    char *mainChars = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
    int32_t   argc     = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
    char *argv[10] = { NULL };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
     * Note: The MToolkit object depends on the static initializer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
     * of X11GraphicsEnvironment to initialize the connection to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
     * the X11 server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
    XFontStruct *xfont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    XmFontListEntry tmpFontListEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
    char *multiclick_time_query;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
    AwtScreenDataPtr defaultScreen =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
        getScreenData(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
    static String fallback_resources[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
        "*enableThinThickness:                   True",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
        "*XmFileSelectionBox.fileFilterStyle:    XmFILTER_HIDDEN_FILES",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
        "*XmFileSelectionBox.pathMode:           XmPATH_MODE_RELATIVE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
        "*XmFileSelectionBox.resizePolicy:       XmRESIZE_GROW",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
        "*XmFileSelectionBox*dirTextLabelString:         Enter path or folder name:",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
        "*XmFileSelectionBox*applyLabelString:           Update",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
        "*XmFileSelectionBox*selectionLabelString:       Enter file name:",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
        "*XmFileSelectionBox*dirListLabelString:         Folders",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
        NULL                        /* Must be NULL terminated */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
    focusOutEvent.type = FocusOut;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    focusOutEvent.xfocus.send_event = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
    focusOutEvent.xfocus.display = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
    focusOutEvent.xfocus.mode = NotifyNormal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
    focusOutEvent.xfocus.detail = NotifyNonlinear;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
    /* Need to make sure this is deleted someplace! */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
    XSetIOErrorHandler(xIOError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
    if (!XSupportsLocale()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        jio_fprintf(stderr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
                    "current locale is not supported in X11, locale is set to C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
        setlocale(LC_ALL, "C");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
    if (!XSetLocaleModifiers("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
        jio_fprintf(stderr, "X locale modifiers are not supported, using default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
#ifdef NETSCAPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
    if (awt_init_xt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
        XtToolkitInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
    XtToolkitInitialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
        jclass  fontConfigClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
        jmethodID methID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
        jstring jFontList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
        char       *cFontRsrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
        char       *cFontRsrc2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
        fontConfigClass = (*env)->FindClass(env, "sun/awt/motif/MFontConfiguration");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
        methID = (*env)->GetStaticMethodID(env, fontConfigClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
                                           "getDefaultMotifFontSet",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
                                           "()Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
        jFontList = (*env)->CallStaticObjectMethod(env, fontConfigClass, methID);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
        if (jFontList == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
            motifFontList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
                "-monotype-arial-regular-r-normal--*-140-*-*-p-*-iso8859-1";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            motifFontList = JNU_GetStringPlatformChars(env, jFontList, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
        /* fprintf(stderr, "motifFontList: %s\n", motifFontList); */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
        cFontRsrc = malloc(strlen(motifFontList) + 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
        strcpy(cFontRsrc, "*fontList: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
        strcat(cFontRsrc, motifFontList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
        cFontRsrc2 = malloc(strlen(motifFontList) + 20);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
        strcpy(cFontRsrc2, "*labelFontList: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
        strcat(cFontRsrc2, motifFontList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
        argc = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
        argv[argc++] = "-xrm";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
        argv[argc++] = cFontRsrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
        argv[argc++] = "-xrm";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
        argv[argc++] = cFontRsrc2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
        argv[argc++] = "-font";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
        argv[argc++] = (char *)defaultMotifFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
    awt_appContext = XtCreateApplicationContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
    XtAppSetErrorHandler(awt_appContext, (XtErrorHandler) xtError);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
    XtAppSetFallbackResources(awt_appContext, fallback_resources);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
    appName = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
    mainChars = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
    if (!JNU_IsNull(env, mainClassName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
        mainChars = (char *)JNU_GetStringPlatformChars(env, mainClassName, NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
        appName = mainChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
    if (appName == NULL || appName[0] == '\0') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
        appName = "AWT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
    XtDisplayInitialize(awt_appContext, awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
                        appName, /* application name  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
                        appName, /* application class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                        NULL, 0, &argc, argv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2719
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2720
    /* Root shell widget that serves as a parent for all AWT top-levels.    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
    awt_root_shell = XtVaAppCreateShell(appName, /* application name  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
                                        appName, /* application class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
                                        applicationShellWidgetClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
                                        awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
                                        /* va_list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
                                        XmNmappedWhenManaged, False,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
                                        NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
    XtRealizeWidget(awt_root_shell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
    if (mainChars != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
        JNU_ReleaseStringPlatformChars(env, mainClassName, mainChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
    awt_mgrsel_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
    awt_wm_init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
    init_xembed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
     * Find the correct awt_multiclick_time to use. We normally
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
     * would call XtMultiClickTime() and wouldn't have to do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
     * anything special, but because OpenWindows defines its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
     * version (OpenWindows.MultiClickTimeout), we need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
     * determine out which resource to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2745
     * We do this by searching in order for:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
     *   1) an explicit definition of multiClickTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
     *      (this is the resource that XtGetMultiClickTime uses)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
     * if that fails, search for:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
     *   2) an explicit definition of Openwindows.MultiClickTimeout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
     * if both searches fail:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
     *   3) use the fallback provided by XtGetMultiClickTime()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
     *      (which is 200 milliseconds... I looked at the source :-)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
    multiclick_time_query = XGetDefault(awt_display, "*", "multiClickTime");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
    if (multiclick_time_query) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
        awt_multiclick_time = XtGetMultiClickTime(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
        multiclick_time_query = XGetDefault(awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
                                            "OpenWindows", "MultiClickTimeout");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
        if (multiclick_time_query) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
            /* Note: OpenWindows.MultiClickTimeout is in tenths of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
               a second, so we need to multiply by 100 to convert to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
               milliseconds */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            awt_multiclick_time = atoi(multiclick_time_query) * 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
            awt_multiclick_time = XtGetMultiClickTime(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
    scrollBugWorkAround = TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
     * Create the cursor for TextArea scrollbars...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
    awt_scrollCursor = XCreateFontCursor(awt_display, XC_left_ptr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
    awt_defaultBg = defaultConfig->AwtColorMatch(200, 200, 200, defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
    awt_defaultFg = defaultScreen->blackpixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
    setup_modifier_map(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
    awt_initialize_DataTransferer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
    awt_initialize_Xm_DnD(awt_display);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
     * fix for bug #4088106 - ugly text boxes and grayed out looking text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
    oldColorProc = XmGetColorCalculation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
    XmSetColorCalculation(ColorProc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
 * Method:    run
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
JNIEXPORT void JNICALL Java_sun_awt_motif_MToolkit_run
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
     * in performSelect(), we multiply the timeout by 1000. Make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
     * that the maximum value will not cause an overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
    DASSERT(AWT_MAX_POLL_TIMEOUT <= (ULONG_MAX/1000));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
    awt_MainThread = (*env)->NewGlobalRef(env, awtJNI_GetCurrentThread(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
    awt_MToolkit_loop(env); /* never returns */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
 * Method:    makeColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
 * Signature: ()Ljava/awt/image/ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
JNIEXPORT jobject JNICALL Java_sun_awt_motif_MToolkit_makeColorModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
  (JNIEnv *env, jclass this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
    return awtJNI_GetColorModel(env, defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
 * Method:    getScreenResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
JNIEXPORT jint JNICALL Java_sun_awt_motif_MToolkit_getScreenResolution
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
    return (jint) ((DisplayWidth(awt_display, DefaultScreen(awt_display))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
                    * 25.4) /
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
                   DisplayWidthMM(awt_display, DefaultScreen(awt_display)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2846
 * Method:    getScreenWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2848
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2849
JNIEXPORT jint JNICALL Java_sun_awt_motif_MToolkit_getScreenWidth
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2850
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2851
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2852
    return DisplayWidth(awt_display, DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2853
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2854
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2855
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2856
 * Method:    getScreenHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2857
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2858
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2859
JNIEXPORT jint JNICALL Java_sun_awt_motif_MToolkit_getScreenHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2860
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2861
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2862
    return DisplayHeight(awt_display, DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2863
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2864
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2865
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2866
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2867
 * Method:    beep
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2868
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2869
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2870
JNIEXPORT void JNICALL Java_sun_awt_motif_MToolkit_beep
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2871
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2872
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2873
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
    XBell(awt_display, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2875
    AWT_FLUSH_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2876
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
 * Method:    shutdown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
JNIEXPORT void JNICALL Java_sun_awt_motif_MToolkit_shutdown
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
    X11SD_LibDispose(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
 * Method:    getLockingKeyStateNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
 * Signature: (I)B
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
JNIEXPORT jboolean JNICALL Java_sun_awt_motif_MToolkit_getLockingKeyStateNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
  (JNIEnv *env, jobject this, jint awtKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
    KeySym sym;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
    KeyCode keyCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
    uint32_t byteIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
    uint32_t bitIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
    char keyVector[32];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
    sym = awt_getX11KeySym(awtKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
    keyCode = XKeysymToKeycode(awt_display, sym);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
    if (sym == NoSymbol || keyCode == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
        JNU_ThrowByName(env, "java/lang/UnsupportedOperationException", "Keyboard doesn't have requested key");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
        return False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
    byteIndex = (keyCode/8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
    bitIndex = keyCode & 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
    XQueryKeymap(awt_display, keyVector);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
    return (1 & (keyVector[byteIndex] >> bitIndex));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
 * Method:    loadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
 * Signature: ([I)V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
JNIEXPORT void JNICALL Java_sun_awt_motif_MToolkit_loadSystemColors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
  (JNIEnv *env, jobject this, jintArray systemColors)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
    Widget frame, panel, control, menu, text, scrollbar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
    Colormap cmap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
    Pixel bg, fg, highlight, shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
    Pixel pixels[java_awt_SystemColor_NUM_COLORS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
    XColor *colorsPtr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
    jint rgbColors[java_awt_SystemColor_NUM_COLORS];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
    int32_t count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
    int32_t i, j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
    Arg args[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
    int32_t argc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
    AwtGraphicsConfigDataPtr defaultConfig =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
        getDefaultConfig(DefaultScreen(awt_display));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
     * initialize array of pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
    for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
        pixels[i] = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
     * Create phantom widgets in order to determine the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
     * colors;  this is somewhat inelegant, however it is the simplest
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
     * and most reliable way to determine the system's default colors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
     * for objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
    argc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
    XtSetArg(args[argc], XmNbuttonFontList,  getMotifFontList()); argc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
    XtSetArg(args[argc], XmNlabelFontList,   getMotifFontList()); argc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
    XtSetArg(args[argc], XmNtextFontList,    getMotifFontList()); argc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
    frame = XtAppCreateShell("AWTColors", "XApplication",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
                             vendorShellWidgetClass,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
                             awt_display,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
                             args, argc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
      XtSetMappedWhenManaged(frame, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
      XtRealizeWidget(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
    panel = XmCreateDrawingArea(frame, "awtPanelColor", NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
    argc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
    XtSetArg(args[argc], XmNfontList,        getMotifFontList()); argc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
    control = XmCreatePushButton(panel, "awtControlColor", args, argc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
    argc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
    XtSetArg(args[argc], XmNlabelFontList,   getMotifFontList()); argc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
    XtSetArg(args[argc], XmNbuttonFontList,  getMotifFontList()); argc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
    menu = XmCreatePulldownMenu(control, "awtColorMenu", args, argc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
    argc = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
    XtSetArg(args[argc], XmNfontList,        getMotifFontList()); argc++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
    text = XmCreateText(panel, "awtTextColor", args, argc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
    scrollbar = XmCreateScrollBar(panel, "awtScrollbarColor", NULL, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
    XtVaGetValues(panel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
                  XmNbackground, &bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
                  XmNforeground, &fg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
                  XmNcolormap, &cmap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
                  NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
    pixels[java_awt_SystemColor_WINDOW] = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
    pixels[java_awt_SystemColor_INFO] = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
    pixels[java_awt_SystemColor_WINDOW_TEXT] = fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
    pixels[java_awt_SystemColor_INFO_TEXT] = fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
    XtVaGetValues(menu,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
                  XmNbackground, &bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3001
                  XmNforeground, &fg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3002
                  NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3004
    pixels[java_awt_SystemColor_MENU] = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3005
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3006
    pixels[java_awt_SystemColor_MENU_TEXT] = fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3007
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3009
    XtVaGetValues(text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3010
                  XmNbackground, &bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3011
                  XmNforeground, &fg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3012
                  NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3014
    pixels[java_awt_SystemColor_TEXT] = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3015
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3016
    pixels[java_awt_SystemColor_TEXT_TEXT] = fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3017
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3018
    pixels[java_awt_SystemColor_TEXT_HIGHLIGHT] = fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3019
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3020
    pixels[java_awt_SystemColor_TEXT_HIGHLIGHT_TEXT] = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3021
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3023
    XtVaGetValues(control,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3024
                  XmNbackground, &bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3025
                  XmNforeground, &fg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3026
                  XmNtopShadowColor, &highlight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3027
                  XmNbottomShadowColor, &shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3028
                  NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3030
    pixels[java_awt_SystemColor_CONTROL] = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3031
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3032
    pixels[java_awt_SystemColor_CONTROL_TEXT] = fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3033
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3034
    pixels[java_awt_SystemColor_CONTROL_HIGHLIGHT] = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3035
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3036
    pixels[java_awt_SystemColor_CONTROL_LT_HIGHLIGHT] = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3037
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3038
    pixels[java_awt_SystemColor_CONTROL_SHADOW] = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3039
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3040
    pixels[java_awt_SystemColor_CONTROL_DK_SHADOW] = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3041
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3043
    XtVaGetValues(scrollbar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3044
                  XmNbackground, &bg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3045
                  NULL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3046
    pixels[java_awt_SystemColor_SCROLLBAR] = bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3047
    count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3049
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3050
     * Convert pixel values to RGB
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3051
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3052
    colorsPtr = (XColor *) malloc(count * sizeof(XColor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3053
    j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3054
    for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3055
        if (pixels[i] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3056
            colorsPtr[j++].pixel = pixels[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3059
    XQueryColors(awt_display, cmap, colorsPtr, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3061
    /* Get current System Colors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3063
    (*env)->GetIntArrayRegion (env, systemColors, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3064
                              java_awt_SystemColor_NUM_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3065
                              rgbColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3067
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3068
     * Fill systemColor array with new rgb values
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3069
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3071
    j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3072
    for (i = 0; i < java_awt_SystemColor_NUM_COLORS; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3073
        if (pixels[i] != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3074
            uint32_t rgb = colorToRGB(&colorsPtr[j++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3076
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3077
              printf("SystemColor[%d] = %x\n", i, rgb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3078
            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3079
            rgbColors[i] = (rgb | 0xFF000000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3083
    (*env)->SetIntArrayRegion(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3084
                              systemColors,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3085
                              0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3086
                              java_awt_SystemColor_NUM_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3087
                              rgbColors);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3089
    /* Duplicate system colors. If color allocation is unsuccessful,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3090
       system colors will be approximated with matched colors */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3091
    if (defaultConfig->awt_depth == 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3092
        awt_allocate_systemcolors(colorsPtr, count, defaultConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3094
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3095
     * Cleanup
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3096
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3097
    XtDestroyWidget(frame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3098
    free(colorsPtr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3100
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3101
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3103
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3104
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3105
 * Method:    isDynamicLayoutSupportedNative
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3106
 * Signature: ()Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3107
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3108
 * Note: there doesn't seem to be a protocol for querying the WM
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3109
 * about its opaque resize settings, so this function just returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3110
 * whether there is a solid resize option available for that WM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3111
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3112
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3113
Java_sun_awt_motif_MToolkit_isDynamicLayoutSupportedNative(JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3114
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3115
    enum wmgr_t wm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3117
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3118
    wm = awt_wm_getRunningWM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3119
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3121
    switch (wm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3122
      case ENLIGHTEN_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3123
      case KDE2_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3124
      case SAWFISH_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3125
      case ICE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3126
      case METACITY_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3127
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3128
      case OPENLOOK_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3129
      case MOTIF_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3130
      case CDE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3131
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3132
      default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3133
        return JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3135
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3137
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3138
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3139
 * Method:    isFrameStateSupported
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3140
 * Signature: (I)Z
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3141
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3142
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3143
Java_sun_awt_motif_MToolkit_isFrameStateSupported(JNIEnv *env, jobject this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3144
    jint state)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3145
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3146
    if (state == java_awt_Frame_NORMAL || state == java_awt_Frame_ICONIFIED) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3147
        return JNI_TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3148
    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3149
        return awt_wm_supportsExtendedState(state) ? JNI_TRUE : JNI_FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3151
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3153
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3154
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3155
 * Method:    getMulticlickTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3156
 * Signature: ()I
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3157
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3158
JNIEXPORT jint JNICALL Java_sun_awt_motif_MToolkit_getMulticlickTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3159
  (JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3160
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3161
    return awt_multiclick_time;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3162
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3164
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3165
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3166
 * Method:    loadXSettings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3167
 * Signature: ()V
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3168
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3169
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3170
Java_sun_awt_motif_MToolkit_loadXSettings(JNIEnv *env, jobject this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3171
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3172
    static Boolean registered = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3174
    jclass mtoolkitCLS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3175
    Display *dpy = awt_display;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3176
    const Window *owners;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3177
    int scr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3179
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3181
    if (registered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3182
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3183
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3186
    if (_XA_XSETTINGS_SETTINGS == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3187
        _XA_XSETTINGS_SETTINGS = XInternAtom(dpy, "_XSETTINGS_SETTINGS", False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3188
        if (_XA_XSETTINGS_SETTINGS == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3189
            JNU_ThrowNullPointerException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3190
                "unable to intern _XSETTINGS_SETTINGS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3191
            AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3192
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3196
    mtoolkitCLS = (*env)->GetObjectClass(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3198
    xsettings_callback_cookie.mtoolkit =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3199
        (*env)->NewGlobalRef(env, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3200
    xsettings_callback_cookie.upcallMID =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3201
        (*env)->GetMethodID(env, mtoolkitCLS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3202
                            "parseXSettings", "(I[B)V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3204
    if (JNU_IsNull(env, xsettings_callback_cookie.upcallMID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3205
        JNU_ThrowNoSuchMethodException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3206
            "sun.awt.motif.MToolkit.parseXSettings");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3207
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3208
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3211
    owners = awt_mgrsel_select("_XSETTINGS", PropertyChangeMask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3212
                               &xsettings_callback_cookie,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3213
                               awt_xsettings_callback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3214
                               awt_xsettings_owner_callback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3215
    if (owners == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3216
        JNU_ThrowNullPointerException(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3217
            "unable to regiser _XSETTINGS with mgrsel");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3218
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3219
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3222
    registered = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3224
    for (scr = 0; scr < ScreenCount(dpy); ++scr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3225
        if (owners[scr] == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3226
            DTRACE_PRINTLN1("XS: MToolkit.loadXSettings: none on screen %d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3227
                            scr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3228
            continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3230
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3231
        awt_xsettings_update(scr, owners[scr], &xsettings_callback_cookie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3234
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3235
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3237
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3238
Java_sun_awt_motif_MToolkit_isAlwaysOnTopSupported(JNIEnv *env, jobject toolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3239
    Boolean res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3240
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3241
    res = awt_wm_supportsAlwaysOnTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3242
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3243
    return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3244
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3246
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3247
 * Returns true if the current thread is privileged. Currently,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3248
 * only the main event loop thread is considered to be privileged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3249
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3250
Boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3251
awt_currentThreadIsPrivileged(JNIEnv *env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3252
    return (*env)->IsSameObject(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3253
                        awt_MainThread, awtJNI_GetCurrentThread(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3254
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3256
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3257
Java_sun_awt_motif_MToolkit_isSyncUpdated(JNIEnv *env, jobject toolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3258
    return syncUpdated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3259
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3261
JNIEXPORT jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3262
Java_sun_awt_motif_MToolkit_isSyncFailed(JNIEnv *env, jobject toolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3263
    return syncFailed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3264
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3266
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3267
Java_sun_awt_motif_MToolkit_updateSyncSelection(JNIEnv *env, jobject toolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3269
    // AWT_LOCK is held by calling function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3270
    if (wm_selection == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3271
        wm_selection = XInternAtom(awt_display, "WM_S0", False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3273
    if (version_atom == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3274
        version_atom = XInternAtom(awt_display, "VERSION", False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3276
    if (oops_atom == None) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3277
        oops_atom = XInternAtom(awt_display, "OOPS", False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3279
    syncUpdated = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3280
    syncFailed = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3281
    XConvertSelection(awt_display, wm_selection, version_atom, oops_atom, XtWindow(awt_root_shell), CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3282
    XSync(awt_display, False);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3283
    inSyncWait = True; // Protect from spurious events
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3284
    // Calling function will call AWT_LOCK_WAIT instead of AWT_UNLOCK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3285
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3287
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3288
Java_sun_awt_motif_MToolkit_getEventNumber(JNIEnv *env, jobject toolkit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3289
    // AWT_LOCK must be held by the calling method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3290
    return eventNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3291
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3293
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3294
syncWait_eventHandler(XEvent * event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3295
    static jmethodID syncNotifyMID = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3296
    if (event != NULL && event->xany.type == SelectionNotify &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3297
        event->xselection.requestor == XtWindow(awt_root_shell) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3298
        event->xselection.property == oops_atom &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3299
        inSyncWait)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3300
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3301
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3302
        syncUpdated = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3303
        inSyncWait = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3304
        AWT_NOTIFY_ALL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3305
    } else if (event != NULL && event->xany.type == SelectionNotify &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3306
               event->xselection.requestor == XtWindow(awt_root_shell) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3307
               event->xselection.target == version_atom &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3308
               event->xselection.property == None &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3309
               XGetSelectionOwner(awt_display, wm_selection) == None &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3310
               event->xselection.selection == wm_selection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3311
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3312
        JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3313
        syncFailed = True;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3314
        inSyncWait = False;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3315
        AWT_NOTIFY_ALL();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3317
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3319
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3320
Java_sun_awt_motif_MToolkit_nativeGrab(JNIEnv *env, jobject toolkit, jobject window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3321
    struct FrameData    *wdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3322
    static Cursor cursor = None;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3323
    int grab_result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3325
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3327
    wdata = (struct FrameData *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3328
        JNU_GetLongFieldAsPtr(env, window, mComponentPeerIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3329
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3330
    if (wdata == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3331
        wdata->winData.comp.widget == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3332
        wdata->winData.shell == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3333
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3334
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3335
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3337
    if (None == cursor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3338
        cursor = XCreateFontCursor(awt_display, XC_hand2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3339
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3340
    grabbed_widget = wdata->winData.shell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3341
    grab_result = XGrabPointer(awt_display, XtWindow(wdata->winData.shell),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3342
                               True, (ButtonPressMask | ButtonReleaseMask
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3343
                                      | EnterWindowMask | LeaveWindowMask | PointerMotionMask
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3344
                                      | ButtonMotionMask),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3345
                               GrabModeAsync, GrabModeAsync, None,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3346
                               cursor, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3347
    if (GrabSuccess != grab_result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3348
        XUngrabPointer(awt_display, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3349
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3350
        DTRACE_PRINTLN1("XGrabPointer() failed, result %d", grab_result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3351
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3353
    grab_result = XGrabKeyboard(awt_display, XtWindow(wdata->winData.shell),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3354
                                True,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3355
                                GrabModeAsync, GrabModeAsync, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3356
    if (GrabSuccess != grab_result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3357
        XUngrabKeyboard(awt_display, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3358
        XUngrabPointer(awt_display, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3359
        DTRACE_PRINTLN1("XGrabKeyboard() failed, result %d", grab_result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3361
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3362
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3364
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3365
Java_sun_awt_motif_MToolkit_nativeUnGrab(JNIEnv *env, jobject toolkit, jobject window) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3366
    struct FrameData    *wdata;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3368
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3369
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3370
    wdata = (struct FrameData *)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3371
        JNU_GetLongFieldAsPtr(env, window, mComponentPeerIDs.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3373
    if (wdata == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3374
        wdata->winData.comp.widget == NULL ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3375
        wdata->winData.shell == NULL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3376
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3377
        AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3378
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3381
    XUngrabPointer(awt_display, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3382
    XUngrabKeyboard(awt_display, CurrentTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3383
    grabbed_widget = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3384
    AWT_FLUSHOUTPUT_NOW();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3385
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3386
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3387
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3388
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3390
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3391
 * Class:     sun_awt_motif_MToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3392
 * Method:    getWMName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3393
 * Signature: ()Ljava/lang/String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3394
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3395
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3396
Java_sun_awt_motif_MToolkit_getWMName(JNIEnv *env, jclass this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3397
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3398
    enum wmgr_t wm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3400
    AWT_LOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3401
    wm = awt_wm_getRunningWM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3402
    AWT_UNLOCK();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3404
    switch (wm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3405
      case NO_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3406
          return (*env)->NewStringUTF(env, "NO_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3407
      case OTHER_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3408
          return (*env)->NewStringUTF(env, "OTHER_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3409
      case ENLIGHTEN_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3410
          return (*env)->NewStringUTF(env, "ENLIGHTEN_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3411
      case KDE2_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3412
          return (*env)->NewStringUTF(env, "KDE2_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3413
      case SAWFISH_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3414
          return (*env)->NewStringUTF(env, "SAWFISH_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3415
      case ICE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3416
          return (*env)->NewStringUTF(env, "ICE_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3417
      case METACITY_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3418
          return (*env)->NewStringUTF(env, "METACITY_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3419
      case OPENLOOK_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3420
          return (*env)->NewStringUTF(env, "OPENLOOK_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3421
      case MOTIF_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3422
          return (*env)->NewStringUTF(env, "MOTIF_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3423
      case CDE_WM:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3424
          return (*env)->NewStringUTF(env, "CDE_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3426
    return (*env)->NewStringUTF(env, "UNDETERMINED_WM");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3427
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3430
#endif /* !HEADLESS */