jdk/src/solaris/native/sun/awt/awt_MenuItem.c
changeset 1211 b659a7cee935
parent 1210 7798f9e88bf9
parent 1203 3e5496df0d2b
child 1212 d718a4419361
equal deleted inserted replaced
1210:7798f9e88bf9 1211:b659a7cee935
     1 /*
       
     2  * Copyright 1995-2004 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 #ifdef HEADLESS
       
    27     #error This file should not be included in headless library
       
    28 #endif
       
    29 
       
    30 #include "awt_p.h"
       
    31 #include <Xm/Separator.h>
       
    32 #include "java_awt_MenuItem.h"
       
    33 #include "sun_awt_motif_MMenuItemPeer.h"
       
    34 #include "sun_awt_motif_MCheckboxMenuItemPeer.h"
       
    35 #include "java_awt_Menu.h"
       
    36 #include "sun_awt_motif_MMenuPeer.h"
       
    37 
       
    38 #include "awt_MenuComponent.h"
       
    39 #include "awt_MenuItem.h"
       
    40 
       
    41 #include "multi_font.h"
       
    42 #include <jni.h>
       
    43 #include <jni_util.h>
       
    44 #include <jlong.h>
       
    45 
       
    46 extern struct MenuComponentIDs menuComponentIDs;
       
    47 
       
    48 /* fieldIDs for MenuItem fields that may be accessed from C */
       
    49 struct MenuItemIDs menuItemIDs;
       
    50 
       
    51 /*
       
    52  * Class:     java_awt_MenuItem
       
    53  * Method:    initIDs
       
    54  * Signature: ()V
       
    55  */
       
    56 
       
    57 /* This function gets called from the static initializer for
       
    58    MenuItem.java to initialize the fieldIDs for fields that may
       
    59    be accessed from C */
       
    60 
       
    61 JNIEXPORT void JNICALL Java_java_awt_MenuItem_initIDs
       
    62   (JNIEnv *env, jclass cls)
       
    63 {
       
    64     menuItemIDs.label =
       
    65       (*env)->GetFieldID(env, cls, "label", "Ljava/lang/String;");
       
    66     menuItemIDs.enabled =
       
    67       (*env)->GetFieldID(env, cls, "enabled", "Z");
       
    68     menuItemIDs.shortcut =
       
    69       (*env)->GetFieldID(env, cls, "shortcut", "Ljava/awt/MenuShortcut;");
       
    70 }
       
    71 
       
    72 /* fieldIDs for MMenuItemPeer fields that may be accessed from C */
       
    73 struct MMenuItemPeerIDs mMenuItemPeerIDs;
       
    74 
       
    75 /*
       
    76  * Class:     sun_awt_motif_MMenuItemPeer
       
    77  * Method:    initIDs
       
    78  * Signature: ()V
       
    79  */
       
    80 
       
    81 /* This function gets called from the static initializer for
       
    82    MMenuItemPeer.java to initialize the fieldIDs for fields that may
       
    83    be accessed from C */
       
    84 
       
    85 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuItemPeer_initIDs
       
    86   (JNIEnv *env, jclass cls)
       
    87 {
       
    88     mMenuItemPeerIDs.target =
       
    89       (*env)->GetFieldID(env, cls, "target", "Ljava/awt/MenuItem;");
       
    90     mMenuItemPeerIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J");
       
    91     mMenuItemPeerIDs.isCheckbox =
       
    92       (*env)->GetFieldID(env, cls, "isCheckbox", "Z");
       
    93     mMenuItemPeerIDs.jniGlobalRef =
       
    94       (*env)->GetFieldID(env, cls, "jniGlobalRef", "J");
       
    95 }
       
    96 
       
    97 /*
       
    98  * Class:     sun_awt_motif_MMenuItemPeer
       
    99  * Method:    getParent_NoClientCode
       
   100  * Signature: (Ljava/awt/MenuComponent;)Ljava/awt/MenuContainer;
       
   101  *
       
   102  * Gets the MenuContainer parent of this object, without executing client
       
   103  * code (e.g., no code in subclasses will be executed).
       
   104  */
       
   105 JNIEXPORT jobject JNICALL Java_sun_awt_motif_MMenuItemPeer_getParent_1NoClientCode
       
   106   (JNIEnv *env, jclass thisClass, jobject menuComponent)
       
   107 {
       
   108     jobject parent = NULL;
       
   109 
       
   110     /* getParent is actually getParent_NoClientCode() */
       
   111     parent = (*env)->CallObjectMethod(
       
   112                         env,menuComponent,menuComponentIDs.getParent);
       
   113     DASSERT(!((*env)->ExceptionOccurred(env)));
       
   114     return parent;
       
   115 }
       
   116 
       
   117 /*
       
   118  *  client_data is MMenuItemPeer instance pointer
       
   119  */
       
   120 static void
       
   121 MenuItem_selected(Widget w, XtPointer client_data, XmAnyCallbackStruct * s)
       
   122 {
       
   123     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
       
   124     jobject this = (jobject) client_data;
       
   125     ConvertEventTimeAndModifiers converted;
       
   126 
       
   127     awt_util_convertEventTimeAndModifiers(s->event, &converted);
       
   128 
       
   129     if ((*env)->GetBooleanField(env, this, mMenuItemPeerIDs.isCheckbox)) {
       
   130         jboolean state;
       
   131         struct MenuItemData *mdata;
       
   132 
       
   133         mdata = (struct MenuItemData *)
       
   134           JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);
       
   135 
       
   136         if (mdata != NULL) {
       
   137             XtVaGetValues(mdata->comp.widget, XmNset, &state, NULL);
       
   138 
       
   139             JNU_CallMethodByName(env, NULL, this
       
   140                                  ,"action"
       
   141                                  ,"(JIZ)V"
       
   142                                  ,converted.when, converted.modifiers,
       
   143                                  state);
       
   144             if ((*env)->ExceptionOccurred(env)) {
       
   145                 (*env)->ExceptionDescribe(env);
       
   146                 (*env)->ExceptionClear(env);
       
   147             }
       
   148         }
       
   149     } else {
       
   150         JNU_CallMethodByName(env, NULL, this, "action", "(JI)V",
       
   151                              converted.when, converted.modifiers);
       
   152         if ((*env)->ExceptionOccurred(env)) {
       
   153             (*env)->ExceptionDescribe(env);
       
   154             (*env)->ExceptionClear(env);
       
   155         }
       
   156     }
       
   157 }
       
   158 
       
   159 /*
       
   160  * Class:     sun_awt_motif_MMenuItemPeer
       
   161  * Method:    createMenuItem
       
   162  * Signature: (Lsun/awt/motif/MMenuPeer;)V
       
   163  *
       
   164  * ASSUMES: This function is never called by a privileged thread
       
   165  */
       
   166 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuItemPeer_createMenuItem(
       
   167 JNIEnv *env, jobject this, jobject parent)
       
   168 {
       
   169     int32_t argc;
       
   170 #define MAX_ARGC 20
       
   171     Arg args[MAX_ARGC];
       
   172     char *clabel;
       
   173     struct MenuData *menuData;
       
   174     struct MenuItemData *mdata;
       
   175     struct FontData *fdata;
       
   176     Pixel bg;
       
   177     Pixel fg;
       
   178     XmFontList fontlist = NULL;
       
   179     jobject target;
       
   180     jobject targetFont;
       
   181     XmString mfstr = NULL;
       
   182     XmString shortcut_str = NULL;
       
   183     XmString str = NULL;
       
   184     jobject font;
       
   185     jobject shortcut;
       
   186     jboolean IsMultiFont;
       
   187     jboolean isCheckbox;
       
   188     jstring label;
       
   189     jobject globalRef = (*env)->NewGlobalRef(env, this);
       
   190     const jchar *unicodeLabel = NULL;
       
   191     jsize unicodeLabelLen = 0;
       
   192     jboolean isCopy = JNI_FALSE;
       
   193 
       
   194     // We call client code on this thread, so it must *NOT* be privileged
       
   195     DASSERT(!awt_currentThreadIsPrivileged(env));
       
   196 
       
   197     JNU_SetLongFieldFromPtr(env, this, mMenuItemPeerIDs.jniGlobalRef,
       
   198                             globalRef);
       
   199 
       
   200     fdata = NULL;
       
   201 
       
   202     fflush(stderr);
       
   203     target =
       
   204       (*env)->GetObjectField(env, this, mMenuItemPeerIDs.target);
       
   205     if (JNU_IsNull(env, target)) {
       
   206         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   207         return;
       
   208     }
       
   209     font = JNU_CallMethodByName(env, NULL, target, "getFont_NoClientCode",
       
   210                                 "()Ljava/awt/Font;").l;
       
   211 
       
   212     if (JNU_IsNull(env, parent)) {
       
   213         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   214         return;
       
   215     }
       
   216     AWT_LOCK();
       
   217     menuData = (struct MenuData *)
       
   218       JNU_GetLongFieldAsPtr(env, parent, mMenuItemPeerIDs.pData);
       
   219 
       
   220     targetFont =
       
   221       (*env)->GetObjectField(env, target, menuComponentIDs.font);
       
   222     if (!JNU_IsNull(env, targetFont) &&
       
   223         (fdata = awtJNI_GetFontData(env, targetFont, NULL)) != NULL) {
       
   224         IsMultiFont = awtJNI_IsMultiFont(env, targetFont);
       
   225     } else {
       
   226         IsMultiFont = awtJNI_IsMultiFont(env, font);
       
   227     }
       
   228 
       
   229     label = (*env)->GetObjectField(env, target, menuItemIDs.label);
       
   230     if (JNU_IsNull(env, label) || ((*env)->GetStringLength (env, label) == 0)) {
       
   231         mfstr = XmStringCreateLocalized("");
       
   232         clabel = "";
       
   233     } else {
       
   234         if (IsMultiFont) {
       
   235             mfstr = awtJNI_MakeMultiFontString(env, label, font);
       
   236         } else {
       
   237             mfstr = XmStringCreateLocalized("");
       
   238         }
       
   239         clabel = (char *) JNU_GetStringPlatformChars(env, label, NULL);
       
   240     }
       
   241 
       
   242     mdata = ZALLOC(MenuItemData);
       
   243     JNU_SetLongFieldFromPtr(env, this, mMenuItemPeerIDs.pData, mdata);
       
   244 
       
   245     argc = 0;
       
   246     XtSetArg(args[argc], XmNbackground, &bg);
       
   247     argc++;
       
   248     XtSetArg(args[argc], XmNforeground, &fg);
       
   249     argc++;
       
   250     XtGetValues(menuData->itemData.comp.widget, args, argc);
       
   251 
       
   252     argc = 0;
       
   253     XtSetArg(args[argc], XmNbackground, bg);
       
   254     argc++;
       
   255     XtSetArg(args[argc], XmNforeground, fg);
       
   256     argc++;
       
   257 
       
   258     /* check if the label is "-" but don't use strcmp(clabel, "-") because
       
   259      * the high-order bytes in the unicode characters are not present in
       
   260      * the C string (bugid 4099695)
       
   261      */
       
   262     if (!JNU_IsNull(env, label)) {
       
   263         unicodeLabel = (*env)->GetStringChars(env, label, &isCopy);
       
   264         unicodeLabelLen = (*env)->GetStringLength(env, label);
       
   265     }
       
   266     if ((unicodeLabel != NULL) && (unicodeLabel[0] == '-') &&
       
   267         (unicodeLabelLen == 1)) {
       
   268         DASSERT(!(argc > MAX_ARGC));
       
   269         mdata->comp.widget = XmCreateSeparator(menuData->itemData.comp.widget,
       
   270                                                "", args, argc);
       
   271     } else {
       
   272         if (IsMultiFont) {
       
   273             XtSetArg(args[argc], XmNlabelString, mfstr);
       
   274         } else {
       
   275             str = XmStringCreate(clabel, XmSTRING_DEFAULT_CHARSET);
       
   276             XtSetArg(args[argc], XmNlabelString, str);
       
   277         }
       
   278         argc++;
       
   279 
       
   280         shortcut =
       
   281           (*env)->GetObjectField(env, target, menuItemIDs.shortcut);
       
   282         if (!JNU_IsNull(env, shortcut)) {
       
   283             jstring shortcutText;
       
   284             char *text = "";
       
   285 
       
   286             shortcutText = JNU_CallMethodByName(env, NULL, shortcut,
       
   287                                                 "toString",
       
   288                                                 "()Ljava/lang/String;").l;
       
   289 
       
   290             if (!JNU_IsNull(env, shortcutText)) {
       
   291                 text = (char *) JNU_GetStringPlatformChars(env, shortcutText, NULL);
       
   292             }
       
   293             shortcut_str = XmStringCreate(text, XmSTRING_DEFAULT_CHARSET);
       
   294             XtSetArg(args[argc], XmNacceleratorText, shortcut_str);
       
   295 
       
   296             argc++;
       
   297 
       
   298             if (!JNU_IsNull(env, shortcutText)) {
       
   299                 JNU_ReleaseStringPlatformChars(env, shortcutText, (const char *) text);
       
   300             }
       
   301         }
       
   302         if (!JNU_IsNull(env, targetFont) && (fdata != NULL)) {
       
   303             if (IsMultiFont) {
       
   304                 fontlist = awtJNI_GetFontList(env, targetFont);
       
   305             } else {
       
   306                 fontlist = XmFontListCreate(fdata->xfont, "labelFont");
       
   307             }
       
   308             XtSetArg(args[argc], XmNfontList, fontlist);
       
   309             argc++;
       
   310         } else {
       
   311             if (IsMultiFont) {
       
   312                 fontlist = awtJNI_GetFontList(env, font);
       
   313                 XtSetArg(args[argc], XmNfontList, fontlist);
       
   314                 argc++;
       
   315             }
       
   316         }
       
   317 
       
   318         isCheckbox =
       
   319           (*env)->GetBooleanField(env, this, mMenuItemPeerIDs.isCheckbox);
       
   320         if (isCheckbox) {
       
   321             /* Fix for 4090493 */
       
   322             if (IsMultiFont) {
       
   323                 /* FontData that correspond to XmNfontList we just set */
       
   324                 struct FontData *fdataForIndSize;
       
   325                 Dimension indSize;
       
   326                 if (!JNU_IsNull(env, targetFont) && (fdata != NULL)) {
       
   327                     fdataForIndSize = fdata;
       
   328                 }
       
   329                 else {
       
   330                 fdataForIndSize = awtJNI_GetFontData(env, font, NULL);
       
   331                 }
       
   332                 indSize = awt_adjustIndicatorSizeForMenu(awt_computeIndicatorSize(fdataForIndSize));
       
   333                 if (indSize != MOTIF_XmINVALID_DIMENSION) {
       
   334                     XtSetArg(args[argc], XmNindicatorSize, indSize); argc++;
       
   335                 }
       
   336             }
       
   337             /* End of fix for 4090493 */
       
   338             XtSetArg(args[argc], XmNset, False);
       
   339             argc++;
       
   340             XtSetArg(args[argc], XmNvisibleWhenOff, True);
       
   341             argc++;
       
   342 
       
   343             DASSERT(!(argc > MAX_ARGC));
       
   344             mdata->comp.widget = XmCreateToggleButton(menuData->itemData.comp.widget,
       
   345                                                       clabel,
       
   346                                                       args,
       
   347                                                       argc);
       
   348         } else {
       
   349             DASSERT(!(argc > MAX_ARGC));
       
   350             mdata->comp.widget = XmCreatePushButton(menuData->itemData.comp.widget,
       
   351                                                     clabel,
       
   352                                                     args,
       
   353                                                     argc);
       
   354         }
       
   355         XtAddCallback(mdata->comp.widget,
       
   356                       ((isCheckbox) ? XmNvalueChangedCallback : XmNactivateCallback),
       
   357                       (XtCallbackProc) MenuItem_selected,
       
   358                       (XtPointer) globalRef);
       
   359 
       
   360         XtSetSensitive(mdata->comp.widget,
       
   361           (*env)->GetBooleanField(env, target, menuItemIDs.enabled) ?
       
   362                        True : False);
       
   363 
       
   364 
       
   365         if (!JNU_IsNull(env, targetFont)) {
       
   366             XmFontListFree(fontlist);
       
   367         }
       
   368     }
       
   369 
       
   370     if (clabel && (clabel != "")) {
       
   371         JNU_ReleaseStringPlatformChars(env, label, clabel);
       
   372     }
       
   373 
       
   374     /*
       
   375      * Free up resources after we have created the widget
       
   376      */
       
   377     if (mfstr != NULL) {
       
   378       XmStringFree(mfstr);
       
   379       mfstr = NULL;
       
   380     }
       
   381     if (str) {
       
   382       XmStringFree(str);
       
   383       str = NULL;
       
   384     }
       
   385     if (shortcut_str) {
       
   386       XmStringFree(shortcut_str);
       
   387       shortcut_str = NULL;
       
   388     }
       
   389     if (isCopy == JNI_TRUE) {
       
   390         (*env)->ReleaseStringChars(env, label, unicodeLabel);
       
   391     }
       
   392 
       
   393     XtManageChild(mdata->comp.widget);
       
   394     AWT_UNLOCK();
       
   395 }
       
   396 
       
   397 /*
       
   398  * Class:     sun_awt_motif_MMenuItemPeer
       
   399  * Method:    pSetLabel
       
   400  * Signature: (Ljava/lang/String;)V
       
   401  */
       
   402 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuItemPeer_pSetLabel
       
   403 (JNIEnv *env, jobject this, jstring label)
       
   404 {
       
   405     struct ComponentData *wdata;
       
   406     char *clabel;
       
   407     XmString xim;
       
   408 
       
   409     AWT_LOCK();
       
   410     wdata = (struct ComponentData *)
       
   411         JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);
       
   412     if (wdata == NULL) {
       
   413         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   414         AWT_UNLOCK();
       
   415         return;
       
   416     }
       
   417     if (JNU_IsNull(env, label) || ((*env)->GetStringLength (env, label) == 0)) {
       
   418         xim = XmStringCreateLocalized("");
       
   419     } else {
       
   420         jobject font;
       
   421         jobject target;
       
   422 
       
   423         target = (*env)->GetObjectField(env, this, mMenuItemPeerIDs.target);
       
   424         if (JNU_IsNull(env, target)) {
       
   425             JNU_ThrowNullPointerException(env, "NullPointerException");
       
   426             AWT_UNLOCK();
       
   427             return;
       
   428         }
       
   429         font = JNU_CallMethodByName(env, NULL, target, "getFont_NoClientCode",
       
   430                                     "()Ljava/awt/Font;").l;
       
   431 
       
   432         if (awtJNI_IsMultiFont(env, font)) {
       
   433             xim = awtJNI_MakeMultiFontString(env, label, font);
       
   434         } else {
       
   435             clabel = (char *) JNU_GetStringPlatformChars(env, label, NULL);
       
   436             xim = XmStringCreate(clabel, "labelFont");
       
   437             JNU_ReleaseStringPlatformChars(env, label, clabel);
       
   438         }
       
   439     }
       
   440     XtUnmanageChild(wdata->widget);
       
   441     XtVaSetValues(wdata->widget, XmNlabelString, xim, NULL);
       
   442     XtManageChild(wdata->widget);
       
   443     XmStringFree(xim);
       
   444     AWT_UNLOCK();
       
   445 }
       
   446 
       
   447 
       
   448 /*
       
   449  * Class:     sun_awt_motif_MMenuItemPeer
       
   450  * Method:    pSetShortCut
       
   451  * Signature: (Ljava/lang/String;)V
       
   452  */
       
   453 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuItemPeer_pSetShortcut
       
   454 (JNIEnv *env, jobject this, jstring shortcut)
       
   455 {
       
   456     struct ComponentData *wdata;
       
   457     char *cshortcut;
       
   458     XmString xim;
       
   459 
       
   460 
       
   461     AWT_LOCK();
       
   462     wdata = (struct ComponentData *)
       
   463         JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);
       
   464     if (wdata == NULL) {
       
   465         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   466         AWT_UNLOCK();
       
   467         return;
       
   468     }
       
   469     if (JNU_IsNull(env, shortcut)) {
       
   470         xim = XmStringCreateLocalized("");
       
   471     } else {
       
   472         jobject font;
       
   473         jobject target;
       
   474 
       
   475         target = (*env)->GetObjectField(env, this, mMenuItemPeerIDs.target);
       
   476         if (JNU_IsNull(env, target)) {
       
   477             JNU_ThrowNullPointerException(env, "NullPointerException");
       
   478             AWT_UNLOCK();
       
   479             return;
       
   480         }
       
   481         font = JNU_CallMethodByName(env, NULL, target, "getFont_NoClientCode",
       
   482                                     "()Ljava/awt/Font;").l;
       
   483 
       
   484         if (awtJNI_IsMultiFont(env, font)) {
       
   485             xim = awtJNI_MakeMultiFontString(env, shortcut, font);
       
   486         } else {
       
   487             cshortcut = (char *) JNU_GetStringPlatformChars(env, shortcut, NULL);
       
   488             xim = XmStringCreate(cshortcut, "labelFont");
       
   489             JNU_ReleaseStringPlatformChars(env, shortcut, cshortcut);
       
   490         }
       
   491     }
       
   492 
       
   493     XtUnmanageChild(wdata->widget);
       
   494     XtVaSetValues(wdata->widget, XmNacceleratorText, xim, NULL);
       
   495     XtManageChild(wdata->widget);
       
   496     XmStringFree(xim);
       
   497     AWT_UNLOCK();
       
   498 }
       
   499 
       
   500 
       
   501 /*
       
   502  * Class:     sun_awt_motif_MMenuItemPeer
       
   503  * Method:    pEnable
       
   504  * Signature: ()V
       
   505  */
       
   506 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuItemPeer_pEnable
       
   507 (JNIEnv *env, jobject this)
       
   508 {
       
   509     struct MenuItemData *mdata;
       
   510 
       
   511     AWT_LOCK();
       
   512 
       
   513     mdata = (struct MenuItemData *)
       
   514         JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);
       
   515 
       
   516     if (mdata == NULL) {
       
   517         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   518         AWT_UNLOCK();
       
   519         return;
       
   520     }
       
   521     XtSetSensitive(mdata->comp.widget, True);
       
   522     AWT_UNLOCK();
       
   523 }
       
   524 
       
   525 /*
       
   526  * Class:     sun_awt_motif_MMenuItemPeer
       
   527  * Method:    pDisable
       
   528  * Signature: ()V
       
   529  */
       
   530 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuItemPeer_pDisable
       
   531 (JNIEnv *env, jobject this)
       
   532 {
       
   533     struct MenuItemData *mdata;
       
   534 
       
   535     AWT_LOCK();
       
   536 
       
   537     mdata = (struct MenuItemData *)
       
   538         JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);
       
   539 
       
   540     if (mdata == NULL) {
       
   541         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   542         AWT_UNLOCK();
       
   543         return;
       
   544     }
       
   545     XtSetSensitive(mdata->comp.widget, False);
       
   546     AWT_UNLOCK();
       
   547 }
       
   548 
       
   549 /*
       
   550  * Class:     sun_awt_motif_MMenuItemPeer
       
   551  * Method:    pDispose
       
   552  * Signature: ()V
       
   553  */
       
   554 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuItemPeer_pDispose
       
   555 (JNIEnv *env, jobject this)
       
   556 {
       
   557     struct MenuItemData *mdata;
       
   558     Widget parent;
       
   559     Boolean isParentManaged = False;
       
   560 
       
   561     AWT_LOCK();
       
   562 
       
   563     mdata = (struct MenuItemData *)
       
   564         JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);
       
   565 
       
   566     if (mdata != NULL) {
       
   567         /* Fix for 4280561:Workspace freezes, does not respond to mouse clicks
       
   568         **
       
   569         ** this really helps a lot of Fujitsu problems, take down a popup
       
   570         ** menu when removing items, on windows you could never get here, since
       
   571         ** the show() of a popup menu puts it in a menu loop where further
       
   572         ** events are processed in that loop, its like a modal dialog show,
       
   573         ** in that it dosn't return till it comes down.
       
   574         ** in X - future xevents will be dispatched immeadiatly, but some
       
   575         ** may be still waiting on the java queue - which can cause them to be
       
   576         ** dispatched out of order (sometimes hanging system !)
       
   577         */
       
   578         /* note: should realy only take down if XtParent(mdata->comp.widget)
       
   579         ** is the activePopup (in awt_PopupMenu.c) but ...
       
   580         */
       
   581         {
       
   582             removePopupMenus();
       
   583         }
       
   584         XtUnmanageChild(mdata->comp.widget);
       
   585         awt_util_consumeAllXEvents(mdata->comp.widget);
       
   586 
       
   587         parent = XtParent(mdata->comp.widget);
       
   588         if (parent != NULL && XtIsManaged(parent)) {
       
   589             isParentManaged = True;
       
   590             XtUnmanageChild(parent);
       
   591         }
       
   592 
       
   593         XtDestroyWidget(mdata->comp.widget);
       
   594 
       
   595         if (isParentManaged) {
       
   596             XtManageChild(parent);
       
   597         }
       
   598 
       
   599         free((void *) mdata);
       
   600         (*env)->SetLongField(env, this, mMenuItemPeerIDs.pData, (jlong)0);
       
   601         awtJNI_DeleteGlobalMenuRef(env, this);
       
   602     }
       
   603     AWT_UNLOCK();
       
   604 }
       
   605 
       
   606 /*
       
   607  * Class:     sun_awt_motif_MCheckboxMenuItemPeer
       
   608  * Method:    pSetState
       
   609  * Signature: (Z)V
       
   610  */
       
   611 JNIEXPORT void JNICALL Java_sun_awt_motif_MCheckboxMenuItemPeer_pSetState
       
   612   (JNIEnv *env, jobject this, jboolean state)
       
   613 {
       
   614     struct MenuItemData *mdata;
       
   615 
       
   616     AWT_LOCK();
       
   617 
       
   618     mdata = (struct MenuItemData *)
       
   619         JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData);
       
   620 
       
   621     if (mdata == NULL) {
       
   622         JNU_ThrowNullPointerException(env, "menuitem data is null");
       
   623         AWT_UNLOCK();
       
   624         return;
       
   625     }
       
   626     XtVaSetValues(mdata->comp.widget, XmNset, (Boolean)state, NULL);
       
   627     AWT_UNLOCK();
       
   628 }
       
   629 
       
   630 /*
       
   631  * Class:     sun_awt_motif_MCheckboxMenuItemPeer
       
   632  * Method:    getState
       
   633  * Signature: ()Z
       
   634  */
       
   635 JNIEXPORT jboolean JNICALL Java_sun_awt_motif_MCheckboxMenuItemPeer_getState
       
   636   (JNIEnv *env, jobject this)
       
   637 {
       
   638     struct MenuItemData *mdata;
       
   639     Boolean             state;
       
   640 
       
   641     AWT_LOCK();
       
   642 
       
   643     mdata = (struct MenuItemData *)
       
   644       (*env)->GetLongField(env, this, mMenuItemPeerIDs.pData);
       
   645 
       
   646     if (mdata == NULL) {
       
   647         JNU_ThrowNullPointerException(env, "menuitem data is null");
       
   648         AWT_UNLOCK();
       
   649         return JNI_FALSE;
       
   650     }
       
   651     XtVaGetValues(mdata->comp.widget, XmNset, &state, NULL);
       
   652     AWT_UNLOCK();
       
   653     return ((state) ? JNI_TRUE : JNI_FALSE);
       
   654 }