jdk/src/solaris/native/sun/awt/awt_motif21.c
changeset 1192 715cf9378c53
parent 1051 90cf935adb35
parent 1191 f142c1da78c2
child 1193 41afb8ee8f45
equal deleted inserted replaced
1051:90cf935adb35 1192:715cf9378c53
     1 /*
       
     2  * Copyright 2000-2006 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 #if MOTIF_VERSION!=2
       
    27     #error This file should only be compiled with motif 2.1
       
    28 #endif
       
    29 
       
    30 #include "awt_motif.h"
       
    31 #include <Xm/Xm.h>
       
    32 #include "awt.h"
       
    33 #include "awt_p.h"
       
    34 #include "awt_Component.h"
       
    35 
       
    36 #define XmPER_SHELL 0
       
    37 extern int32_t _XmImGetGeo(
       
    38                         Widget vw) ;
       
    39 
       
    40 #define MAXARGS 10
       
    41 static Arg xic_vlist[MAXARGS];
       
    42 
       
    43 #define SEPARATOR_HEIGHT        2
       
    44 #define MTEXTAREAPEER_CLASS_NAME        "sun/awt/motif/MTextAreaPeer"
       
    45 extern struct MComponentPeerIDs mComponentPeerIDs;
       
    46 static jobject  mTextAreaClass = NULL;
       
    47 
       
    48 /*
       
    49  * Get the Motif text widget from the text component peer.  XmImGetXIC()
       
    50  * function should be issued on Motif text widgets.
       
    51  */
       
    52 static Widget getTextWidget(jobject tc) {
       
    53     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
       
    54 
       
    55     if (mTextAreaClass == NULL) {
       
    56         jclass localClass = (*env)->FindClass(env, MTEXTAREAPEER_CLASS_NAME);
       
    57         mTextAreaClass = (jclass)(*env)->NewGlobalRef(env, localClass);
       
    58         (*env)->DeleteLocalRef(env, localClass);
       
    59     }
       
    60 
       
    61     if ((*env)->IsInstanceOf(env, tc, mTextAreaClass)) {
       
    62         struct TextAreaData * tdata = (struct TextAreaData *)
       
    63         JNU_GetLongFieldAsPtr(env, tc, mComponentPeerIDs.pData);
       
    64         return tdata->txt;
       
    65     } else {
       
    66         struct ComponentData * tdata = (struct ComponentData *)
       
    67         JNU_GetLongFieldAsPtr(env, tc, mComponentPeerIDs.pData);
       
    68         return tdata->widget;
       
    69     }
       
    70 }
       
    71 
       
    72 /* get_im_height: returns height of the input method status area in pixels.
       
    73  *
       
    74  * This function assumes that if any XIM related information cannot be
       
    75  * queried then the app must not have an input method status area in the
       
    76  * current locale and returns zero as the status area height
       
    77  */
       
    78 int32_t
       
    79 awt_motif_getIMStatusHeight(Widget w, jobject tc)
       
    80 {
       
    81     XIC xic = NULL;
       
    82     XRectangle *im_rect=NULL;
       
    83     int32_t im_height = 0;
       
    84     char *ret;
       
    85 
       
    86     xic = XmImGetXIC(getTextWidget(tc), XmPER_SHELL, NULL, 0);
       
    87 
       
    88     if(xic != NULL) {
       
    89         /* finally query the server for the status area geometry */
       
    90         xic_vlist[0].name = XNArea;
       
    91         xic_vlist[0].value = (XtArgVal)&im_rect;
       
    92         xic_vlist[1].name = NULL;
       
    93         ret=XGetICValues(xic, XNStatusAttributes, &xic_vlist[0], NULL);
       
    94         if (ret == NULL && im_rect != NULL) {
       
    95             im_height = im_rect->height;
       
    96             if (im_height > 0) {
       
    97                 im_height += SEPARATOR_HEIGHT;
       
    98             }
       
    99             XFree(im_rect);
       
   100         } else {
       
   101             im_height = 0;
       
   102         }
       
   103     }
       
   104 
       
   105     if (im_height == 0) {
       
   106         im_height = _XmImGetGeo(w);
       
   107     }
       
   108 
       
   109 #if defined(DEBUG)
       
   110     jio_fprintf(stderr,"awt_motif_getIMStatusHeight: Height = %d",im_height);
       
   111 #endif
       
   112     return im_height;
       
   113 }
       
   114 
       
   115 
       
   116 static XRectangle geomRect;
       
   117 static Pixmap bpm;
       
   118 XVaNestedList awt_motif_getXICStatusAreaList(Widget w, jobject tc)
       
   119 {
       
   120     XIC xic;
       
   121 
       
   122     XRectangle *im_rect;
       
   123     XFontSet   *im_font;
       
   124 
       
   125     Pixel bg ;
       
   126     Pixel fg ;
       
   127     Dimension height, width ;
       
   128     Position x,y ;
       
   129 
       
   130     XVaNestedList list = NULL;
       
   131 
       
   132     char *ret;
       
   133     Widget p=w;
       
   134 
       
   135     while (!XtIsShell(p)) {
       
   136         p = XtParent(p);
       
   137     }
       
   138 
       
   139     XtVaGetValues(p,
       
   140         XmNx, &x,
       
   141         XmNy, &y,
       
   142         XmNwidth, &width,
       
   143         XmNheight, &height,
       
   144         XmNbackgroundPixmap, &bpm,
       
   145         NULL);
       
   146 
       
   147 
       
   148 
       
   149     xic = XmImGetXIC(getTextWidget(tc), XmPER_SHELL, NULL, 0);
       
   150     if(xic == NULL)
       
   151     {
       
   152 #if defined DEBUG
       
   153         jio_fprintf(stderr,"Could not get XIC");
       
   154 #endif
       
   155         return list ;
       
   156     }
       
   157 
       
   158    /* finally query the server for the required attributes area geometry */
       
   159     xic_vlist[0].name = XNFontSet ;
       
   160     xic_vlist[0].value =  (XtArgVal) &im_font ;
       
   161     xic_vlist[1].name = XNArea;
       
   162     xic_vlist[1].value = (XtArgVal) &im_rect;
       
   163     xic_vlist[2].name = XNBackground ;
       
   164     xic_vlist[2].value = (XtArgVal) &bg ;
       
   165     xic_vlist[3].name = XNForeground ;
       
   166     xic_vlist[3].value = (XtArgVal) &fg ;
       
   167     xic_vlist[4].name = NULL;
       
   168 
       
   169 
       
   170     if(ret=XGetICValues(xic, XNStatusAttributes, &xic_vlist[0], NULL))
       
   171     {
       
   172         return list ;
       
   173     } else {
       
   174         geomRect.x = 0 ;
       
   175         geomRect.y = height - im_rect->height ;
       
   176         geomRect.width = im_rect->width ;
       
   177         geomRect.height = im_rect->height ;
       
   178         XFree(im_rect) ;
       
   179 
       
   180         list = XVaCreateNestedList(0 ,
       
   181                         XNFontSet, im_font ,
       
   182                         XNArea, &geomRect ,
       
   183                         XNBackground, bg ,
       
   184                         XNForeground, fg ,
       
   185                         XNBackgroundPixmap, &bpm ,
       
   186                         NULL );
       
   187     }
       
   188 #if defined(DEBUG)
       
   189     jio_fprintf(stderr,"awt_motif_getXICStatusAreaList:\n");
       
   190     jio_fprintf(stderr,"XNArea:x=%d,y=%d,width=%d,height=%d\n", \
       
   191          geomRect.x,geomRect.y,geomRect.width,geomRect.height);
       
   192     jio_fprintf(stderr,"XNBackground=0x%x\n",bg);
       
   193     jio_fprintf(stderr,"XNForeground=0x%x\n",fg);
       
   194     jio_fprintf(stderr,"XNBackgroundPixmap=0x%x\n",bpm);
       
   195 #endif
       
   196     return list ;
       
   197 
       
   198 }
       
   199 
       
   200     /* This function causes an UnsatisfiedLinkError on Linux.
       
   201      * Since Linux only links against Motif 2.1 and under 2.1 this function
       
   202      * is a no-op, we can safely remove
       
   203      * this function altogether from the Linux build.
       
   204      * bchristi 1/22/2001
       
   205      */
       
   206 
       
   207 #ifdef __solaris__
       
   208 void
       
   209 awt_motif_adjustDragTriggerEvent(XEvent* xevent) {
       
   210     /* Do nothing. In Motif 2.1 the sanity check is corrected
       
   211        to allow any imput event as a drag trigger event. */
       
   212 }
       
   213 #endif /* __solaris__ */
       
   214 
       
   215 static void
       
   216 CheckDragInitiator(Widget w, XtPointer client_data,
       
   217                    XmDragStartCallbackStruct* cbstruct) {
       
   218     Widget drag_initiator = (Widget)client_data;
       
   219     /*
       
   220      * Fix for BugTraq ID 4407057.
       
   221      * Enable the drag operation only if it is registered on the specific
       
   222      * widget. We use this check to disable Motif default drag support.
       
   223      */
       
   224     if (drag_initiator != cbstruct->widget) {
       
   225         cbstruct->doit = False;
       
   226     }
       
   227 }
       
   228 
       
   229 void
       
   230 awt_motif_enableSingleDragInitiator(Widget w) {
       
   231     XtAddCallback(XmGetXmDisplay(XtDisplay(w)),
       
   232                   XmNdragStartCallback, (XtCallbackProc)CheckDragInitiator,
       
   233                   (XtPointer)w);
       
   234 }