jdk/src/solaris/native/sun/awt/awt_MenuBar.c
changeset 1192 715cf9378c53
parent 1051 90cf935adb35
parent 1191 f142c1da78c2
child 1193 41afb8ee8f45
equal deleted inserted replaced
1051:90cf935adb35 1192:715cf9378c53
     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 #ifdef HEADLESS
       
    26     #error This file should not be included in headless library
       
    27 #endif
       
    28 
       
    29 #include "awt_p.h"
       
    30 #include "java_awt_MenuBar.h"
       
    31 #include "sun_awt_motif_MMenuBarPeer.h"
       
    32 #include "java_awt_Menu.h"
       
    33 #include "java_awt_Frame.h"
       
    34 #include "sun_awt_motif_MFramePeer.h"
       
    35 
       
    36 #include "awt_GraphicsEnv.h"
       
    37 #include "awt_MenuBar.h"
       
    38 #include "awt_Component.h"
       
    39 
       
    40 #include <jni.h>
       
    41 #include <jni_util.h>
       
    42 
       
    43 extern struct MComponentPeerIDs mComponentPeerIDs;
       
    44 extern struct X11GraphicsConfigIDs x11GraphicsConfigIDs;
       
    45 struct MMenuBarPeerIDs mMenuBarPeerIDs;
       
    46 
       
    47 /*
       
    48  * Class:     sun_awt_motif_MMenuBarPeer
       
    49  * Method:    initIDs
       
    50  * Signature: ()V
       
    51  */
       
    52 
       
    53 /* This function gets called from the static initializer for MMenuBarPeer.java
       
    54    to initialize the fieldIDs fields that may be accessed from C */
       
    55 JNIEXPORT void JNICALL
       
    56 Java_sun_awt_motif_MMenuBarPeer_initIDs
       
    57   (JNIEnv *env, jclass cls)
       
    58 {
       
    59   mMenuBarPeerIDs.pData = (*env)->GetFieldID(env, cls, "pData", "J");
       
    60   mMenuBarPeerIDs.graphicsConfig =
       
    61       (*env)->GetFieldID(env, cls, "graphicsConfig",
       
    62                          "Lsun/awt/X11GraphicsConfig;");
       
    63 }
       
    64 
       
    65 static AwtGraphicsConfigDataPtr
       
    66 copyGraphicsConfigToMenuBarPeer(
       
    67 JNIEnv *env, jobject frame, jobject thisMenuBar) {
       
    68 
       
    69     jobject gc_object;
       
    70     AwtGraphicsConfigDataPtr adata;
       
    71 
       
    72     /* GraphicsConfiguration object of Component */
       
    73     gc_object = (*env)->GetObjectField(env, frame,
       
    74                                        mComponentPeerIDs.graphicsConfig);
       
    75 
       
    76     if (gc_object != NULL) {
       
    77         /* Set graphicsConfig field of MComponentPeer */
       
    78         (*env)->SetObjectField (env, thisMenuBar,
       
    79                                 mMenuBarPeerIDs.graphicsConfig,
       
    80                                 gc_object);
       
    81         adata = (AwtGraphicsConfigDataPtr)
       
    82             JNU_GetLongFieldAsPtr(env, gc_object,
       
    83                                   x11GraphicsConfigIDs.aData);
       
    84     } else {
       
    85         /* Component was not constructed with a GraphicsConfiguration
       
    86            object */
       
    87         adata = getDefaultConfig(DefaultScreen(awt_display));
       
    88     }
       
    89 
       
    90     return adata;
       
    91 }
       
    92 
       
    93 AwtGraphicsConfigDataPtr
       
    94 getGraphicsConfigFromMenuBarPeer(JNIEnv *env, jobject menubarPeer) {
       
    95 
       
    96     jobject gc_object;
       
    97     AwtGraphicsConfigDataPtr adata;
       
    98 
       
    99     /* GraphicsConfiguration object of Component */
       
   100     gc_object = (*env)->GetObjectField(env, menubarPeer,
       
   101                                        mMenuBarPeerIDs.graphicsConfig);
       
   102 
       
   103     if (gc_object != NULL) {
       
   104         adata = (AwtGraphicsConfigDataPtr)
       
   105             JNU_GetLongFieldAsPtr(env, gc_object,
       
   106                                   x11GraphicsConfigIDs.aData);
       
   107     } else {
       
   108         adata = getDefaultConfig(DefaultScreen(awt_display));
       
   109     }
       
   110 
       
   111     return adata;
       
   112 }
       
   113 
       
   114 /*
       
   115  * Class:     sun_awt_motif_MMenuBarPeer
       
   116  * Method:    create
       
   117  * Signature: (Lsun/awt/motif/MFramePeer;)V
       
   118  */
       
   119 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuBarPeer_create
       
   120   (JNIEnv * env, jobject this, jobject frame)
       
   121 {
       
   122 #define MAX_ARGC 20
       
   123     Arg args[MAX_ARGC];
       
   124     int32_t argc;
       
   125     struct ComponentData *mdata;
       
   126     struct FrameData *wdata;
       
   127     Pixel bg;
       
   128     Pixel fg;
       
   129     AwtGraphicsConfigDataPtr adata;
       
   130 
       
   131     if (JNU_IsNull(env, frame)) {
       
   132         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   133         return;
       
   134     }
       
   135     AWT_LOCK();
       
   136     wdata = (struct FrameData *)
       
   137         JNU_GetLongFieldAsPtr(env, frame, mComponentPeerIDs.pData);
       
   138     mdata = ZALLOC(ComponentData);
       
   139 
       
   140     if (wdata == NULL || mdata == NULL) {
       
   141         JNU_ThrowNullPointerException(env, "NullPointerException");
       
   142         AWT_UNLOCK();
       
   143         return;
       
   144     }
       
   145     JNU_SetLongFieldFromPtr(env, this, mMenuBarPeerIDs.pData, mdata);
       
   146 
       
   147     adata = copyGraphicsConfigToMenuBarPeer(env, frame, this);
       
   148 
       
   149     XtVaGetValues(wdata->winData.comp.widget,
       
   150                   XmNbackground, &bg,
       
   151                   XmNforeground, &fg,
       
   152                   NULL);
       
   153 
       
   154     argc = 0;
       
   155     XtSetArg(args[argc], XmNbackground, bg);
       
   156     argc++;
       
   157     XtSetArg(args[argc], XmNforeground, fg);
       
   158     argc++;
       
   159     XtSetArg (args[argc], XmNscreen,
       
   160               ScreenOfDisplay(awt_display,
       
   161                               adata->awt_visInfo.screen));
       
   162     argc++;
       
   163 
       
   164     DASSERT(!(argc > MAX_ARGC));
       
   165     mdata->widget = XmCreateMenuBar(wdata->mainWindow, "menu_bar", args, argc);
       
   166     awt_addMenuWidget(mdata->widget);
       
   167     XtSetMappedWhenManaged(mdata->widget, False);
       
   168     XtManageChild(mdata->widget);
       
   169     AWT_UNLOCK();
       
   170 }
       
   171 
       
   172 /*
       
   173  * Class:     sun_awt_motif_MMenuBarPeer
       
   174  * Method:    dispose
       
   175  * Signature: ()V
       
   176  */
       
   177 JNIEXPORT void JNICALL Java_sun_awt_motif_MMenuBarPeer_pDispose
       
   178   (JNIEnv * env, jobject this)
       
   179 {
       
   180     struct ComponentData *mdata;
       
   181 
       
   182     AWT_LOCK();
       
   183 
       
   184     /*hania LOOK HERE does this make sense? look at original code */
       
   185     mdata = (struct ComponentData *)
       
   186         JNU_GetLongFieldAsPtr(env, this, mMenuBarPeerIDs.pData);
       
   187     if (mdata == NULL) {
       
   188         AWT_UNLOCK();
       
   189         return;
       
   190     }
       
   191     awt_delMenuWidget(mdata->widget);
       
   192     XtUnmanageChild(mdata->widget);
       
   193     awt_util_consumeAllXEvents(mdata->widget);
       
   194     XtDestroyWidget(mdata->widget);
       
   195     free((void *) mdata);
       
   196     (*env)->SetLongField(env, this, mMenuBarPeerIDs.pData, (jlong)0);
       
   197     AWT_UNLOCK();
       
   198 }