1 /*
   2  * Copyright 1995-2009 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 /*
  27  * Motif-specific data structures for AWT Java objects.
  28  *
  29  */
  30 #ifndef _AWT_P_H_
  31 #define _AWT_P_H_
  32 
  33 /* turn on to do event filtering */
  34 #define NEW_EVENT_MODEL
  35 /* turn on to only filter keyboard events */
  36 #define KEYBOARD_ONLY_EVENTS
  37 
  38 #include <stdarg.h>
  39 #include <stdio.h>
  40 #include <stdlib.h>
  41 #include <string.h>
  42 #include <unistd.h>
  43 #ifndef HEADLESS
  44 #include <X11/Intrinsic.h>
  45 #include <X11/IntrinsicP.h>
  46 #include <X11/Shell.h>
  47 #include <X11/StringDefs.h>
  48 #include <X11/Xatom.h>
  49 #include <X11/keysym.h>
  50 #include <X11/keysymdef.h>
  51 #ifndef XAWT
  52 #include <Xm/CascadeB.h>
  53 #include <Xm/DrawingA.h>
  54 #include <Xm/FileSB.h>
  55 #include <Xm/BulletinB.h>
  56 #include <Xm/Form.h>
  57 #include <Xm/Frame.h>
  58 #include <Xm/Label.h>
  59 #include <Xm/PushB.h>
  60 #include <Xm/PushBG.h>
  61 #include <Xm/RowColumn.h>
  62 #include <Xm/ScrollBar.h>
  63 #include <Xm/ScrolledW.h>
  64 #include <Xm/SelectioB.h>
  65 #include <Xm/SeparatoG.h>
  66 #include <Xm/ToggleB.h>
  67 #include <Xm/TextF.h>
  68 #include <Xm/Text.h>
  69 #include <Xm/List.h>
  70 #include <Xm/Xm.h>
  71 #include <Xm/MainW.h>
  72 #endif
  73 #endif /* !HEADLESS */
  74 #include "awt.h"
  75 #include "awt_util.h"
  76 #include "color.h"
  77 #include "colordata.h"
  78 #include "gdefs.h"
  79 
  80 #ifndef XAWT
  81 #include "GLXGraphicsConfig.h"
  82 //#include <sun_awt_motif_MComponentPeer.h>
  83 #endif
  84 
  85 #ifndef HEADLESS
  86 #ifndef XAWT
  87 #include "awt_motif.h"
  88 #endif
  89 #ifndef min
  90 #define min(a,b) ((a) <= (b)? (a):(b))
  91 #endif
  92 #ifndef max
  93 #define max(a,b) ((a) >= (b)? (a):(b))
  94 #endif
  95 
  96 extern Pixel awt_pixel_by_name(Display *dpy, char *color, char *defaultColor);
  97 
  98 typedef struct DropSiteInfo* DropSitePtr;
  99 
 100 struct WidgetInfo {
 101     Widget             widget;
 102     Widget             origin;
 103     void*              peer;
 104     jlong              event_mask;
 105     struct WidgetInfo* next;
 106 };
 107 #endif /* !HEADLESS */
 108 
 109 #define RepaintPending_NONE     0
 110 #define RepaintPending_REPAINT  (1 << 0)
 111 #define RepaintPending_EXPOSE   (1 << 1)
 112 #define LOOKUPSIZE 32
 113 
 114 typedef struct _DamageRect {
 115     int x1;
 116     int y1;
 117     int x2;
 118     int y2;
 119 } DamageRect;
 120 
 121 #ifndef HEADLESS
 122 
 123 /* Note: until we include the <X11/extensions/Xrender.h> explicitly
 124  * we have to define a couple of things ourselves.
 125  */
 126 typedef unsigned long   PictFormat;
 127 #define PictTypeIndexed             0
 128 #define PictTypeDirect              1
 129 
 130 typedef struct {
 131     short   red;
 132     short   redMask;
 133     short   green;
 134     short   greenMask;
 135     short   blue;
 136     short   blueMask;
 137     short   alpha;
 138     short   alphaMask;
 139 } XRenderDirectFormat;
 140 
 141 typedef struct {
 142     PictFormat      id;
 143     int         type;
 144     int         depth;
 145     XRenderDirectFormat direct;
 146     Colormap        colormap;
 147 } XRenderPictFormat;
 148 
 149 #define PictFormatID        (1 << 0)
 150 #define PictFormatType      (1 << 1)
 151 #define PictFormatDepth     (1 << 2)
 152 #define PictFormatRed       (1 << 3)
 153 #define PictFormatRedMask   (1 << 4)
 154 #define PictFormatGreen     (1 << 5)
 155 #define PictFormatGreenMask (1 << 6)
 156 #define PictFormatBlue      (1 << 7)
 157 #define PictFormatBlueMask  (1 << 8)
 158 #define PictFormatAlpha     (1 << 9)
 159 #define PictFormatAlphaMask (1 << 10)
 160 #define PictFormatColormap  (1 << 11)
 161 
 162 typedef XRenderPictFormat *
 163 XRenderFindVisualFormatFunc (Display *dpy, _Xconst Visual *visual);
 164 /* END OF Xrender.h chunk */
 165 
 166 typedef struct _AwtGraphicsConfigData  {
 167     int         awt_depth;
 168     Colormap    awt_cmap;
 169     XVisualInfo awt_visInfo;
 170     int         awt_num_colors;
 171     awtImageData *awtImage;
 172     int         (*AwtColorMatch)(int, int, int,
 173                                  struct _AwtGraphicsConfigData *);
 174     XImage      *monoImage;
 175     Pixmap      monoPixmap;      /* Used in X11TextRenderer_md.c */
 176     int         monoPixmapWidth; /* Used in X11TextRenderer_md.c */
 177     int         monoPixmapHeight;/* Used in X11TextRenderer_md.c */
 178     GC          monoPixmapGC;    /* Used in X11TextRenderer_md.c */
 179     int         pixelStride;     /* Used in X11SurfaceData.c */
 180     ColorData      *color_data;
 181     struct _GLXGraphicsConfigInfo *glxInfo;
 182     int         isTranslucencySupported; /* Uses Xrender to find this out. */
 183     XRenderPictFormat renderPictFormat; /*Used only if translucency supported*/
 184 } AwtGraphicsConfigData;
 185 
 186 typedef AwtGraphicsConfigData* AwtGraphicsConfigDataPtr;
 187 
 188 typedef struct _AwtScreenData {
 189     int numConfigs;
 190     Window root;
 191     unsigned long whitepixel;
 192     unsigned long blackpixel;
 193     AwtGraphicsConfigDataPtr defaultConfig;
 194     AwtGraphicsConfigDataPtr *configs;
 195 } AwtScreenData;
 196 
 197 typedef AwtScreenData* AwtScreenDataPtr;
 198 
 199 struct ComponentData {
 200     Widget      widget;
 201     int         repaintPending;
 202     DamageRect  repaintRect;
 203     DamageRect  exposeRect;
 204     DropSitePtr dsi;
 205 };
 206 
 207 struct MessageDialogData {
 208     struct ComponentData        comp;
 209     int                 isModal;
 210 };
 211 
 212 struct CanvasData {
 213     struct ComponentData        comp;
 214     Widget                      shell;
 215     int                         flags;
 216 };
 217 
 218 struct MenuItemData {
 219     struct ComponentData        comp;
 220     int                         index;
 221 };
 222 
 223 struct MenuData {
 224     struct ComponentData        comp;
 225     struct MenuItemData         itemData;
 226 };
 227 
 228 
 229 #define W_GRAVITY_INITIALIZED 1
 230 #define W_IS_EMBEDDED 2
 231 
 232 struct FrameData {
 233     struct CanvasData   winData;
 234     int                 isModal;
 235     Widget              mainWindow;
 236     Widget              focusProxy;     /* for all key events */
 237     Widget              menuBar;
 238     Widget              warningWindow;
 239     int                 top;            /* these four are the insets... */
 240     int                 bottom;
 241     int                 left;
 242     int                 right;
 243     int                 topGuess;       /* these four are the guessed insets */
 244     int                 bottomGuess;
 245     int                 leftGuess;
 246     int                 rightGuess;
 247     int                 mbHeight;       /* height of the menubar window */
 248     int                 wwHeight;       /* height of the warning window */
 249     jint                state;          /* java.awt.Frame.state bits    */
 250     Boolean             reparented;
 251     Boolean             configure_seen;
 252     Boolean             shellResized;   /* frame shell has been resized */
 253     Boolean             canvasResized;  /* frame inner canvas resized   */
 254     Boolean             menuBarReset;   /* frame menu bar added/removed */
 255     Boolean             isResizable;    /* is this window resizable ?   */
 256     Boolean             isFixedSizeSet; /* is fixed size already set ?  */
 257     Boolean             isShowing;      /* is this window now showing ? */
 258     Boolean             hasTextComponentNative;
 259     Boolean             need_reshape;
 260     Boolean             callbacksAdded; /* needed for fix for 4078176   */
 261     Pixmap              iconPixmap;     /* Pixmap to hold icon image    */
 262     int                 iconWidth;
 263     int                 iconHeight;
 264     int                 imHeight;       /* imStatusBar's height         */
 265     Boolean             imRemove;       /* ImStatusBar is being removed */
 266     Boolean             fixInsets;      /* [jk] REMINDER: remove if possible */
 267     int                 decor;          /* type of native decorations */
 268     Boolean             initialFocus;   /* does Window take focus initially */
 269     Boolean             isInputMethodWindow;
 270 
 271     /*
 272      * Fix for BugTraq ID 4060975.
 273      * firstShellEH() stores to this field handle of the widget that had
 274      * focus before the shell was resized so that we can later restore it.
 275      */
 276     Widget              focusWidget;
 277     int screenNum;      /* Which screen this Window is on.  Xinerama-aware. */
 278     Boolean             isDisposeScheduled;
 279     Boolean             isFocusableWindow;  /* a cache of Window.isFocusableWindow() return value */
 280 };
 281 
 282 struct ListData {
 283     struct ComponentData comp;
 284     Widget               list;
 285 };
 286 
 287 struct TextAreaData {
 288     struct ComponentData comp;
 289     Widget               txt;
 290 };
 291 
 292 struct TextFieldData {
 293     struct ComponentData comp;
 294     int                  echoContextID;
 295     Boolean              echoContextIDInit;
 296 };
 297 
 298 struct FileDialogData {
 299     struct ComponentData comp;
 300     char        *file;
 301 };
 302 
 303 typedef struct awtFontList {
 304     char *xlfd;
 305     int index_length;
 306     int load;
 307     char *charset_name;
 308     XFontStruct *xfont;
 309 } awtFontList;
 310 
 311 struct FontData {
 312     int charset_num;
 313     awtFontList *flist;
 314     XFontSet xfs;       /* for TextField & TextArea */
 315     XFontStruct *xfont; /* Latin1 font */
 316 };
 317 
 318 #ifndef XAWT
 319 extern XmFontList getMotifFontList(void);
 320 extern XFontSet getMotifFontSet(void);
 321 extern XFontStruct *getMotifFontStruct(void);
 322 extern Boolean awt_isAwtWidget(Widget widget);
 323 #endif
 324 
 325 struct ChoiceData {
 326     struct ComponentData comp;
 327     Widget               menu;
 328     Widget               *items;
 329     int                  maxitems;
 330     int                  n_items;
 331     short                n_columns;
 332 /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match
 333  * actual size
 334  * y and height which Choice takes in pReshape
 335 */
 336     jint                 bounds_y;
 337     jint                 bounds_height;
 338 };
 339 
 340 struct MenuList {
 341     Widget menu;
 342     struct MenuList* next;
 343 };
 344 
 345 extern struct FontData *awtJNI_GetFontData(JNIEnv *env,jobject font, char **errmsg);
 346 
 347 extern AwtGraphicsConfigDataPtr getDefaultConfig(int screen);
 348 extern AwtScreenDataPtr getScreenData(int screen);
 349 #endif /* !HEADLESS */
 350 
 351 /* allocated and initialize a structure */
 352 #define ZALLOC(T)       ((struct T *)calloc(1, sizeof(struct T)))
 353 
 354 #ifndef HEADLESS
 355 #define XDISPLAY awt_display;
 356 
 357 extern Boolean awt_currentThreadIsPrivileged(JNIEnv *env);
 358 extern void null_event_handler(Widget w, XtPointer client_data,
 359                         XEvent * event, Boolean * cont);
 360 
 361 extern void awt_put_back_event(JNIEnv *env, XEvent *event);
 362 extern void awt_MToolkit_modalWait(int (*terminateFn)(void *data), void *data);
 363 extern void awt_Frame_guessInsets(struct FrameData *fdata);
 364 
 365 extern void awt_addWidget(Widget w, Widget origin, void *peer, jlong event_mask);
 366 extern void awt_delWidget(Widget w);
 367 
 368 extern void awt_addMenuWidget(Widget w);
 369 extern void awt_delMenuWidget(Widget w);
 370 
 371 extern int awt_allocate_colors(AwtGraphicsConfigDataPtr);
 372 extern void awt_allocate_systemcolors(XColor *, int, AwtGraphicsConfigDataPtr);
 373 extern void awt_allocate_systemrgbcolors(jint *, int, AwtGraphicsConfigDataPtr);
 374 
 375 extern int awtJNI_GetColor(JNIEnv *, jobject);
 376 extern int awtJNI_GetColorForVis (JNIEnv *, jobject, AwtGraphicsConfigDataPtr);
 377 extern jobject awtJNI_GetColorModel(JNIEnv *, AwtGraphicsConfigDataPtr);
 378 extern void awtJNI_CreateColorData (JNIEnv *, AwtGraphicsConfigDataPtr, int lock);
 379 
 380 extern Boolean awtJNI_isSelectionOwner(JNIEnv *env, char *sel_str);
 381 extern void awtJNI_notifySelectionLost(JNIEnv *env, char *sel_str);
 382 extern void removePopupMenus();
 383 extern Boolean awtMenuIsActive();
 384 #endif /* !HEADLESS */
 385 
 386 extern void awtJNI_DeleteGlobalRef(JNIEnv *env,jobject thiscomp);
 387 extern void awtJNI_DeleteGlobalMenuRef(JNIEnv *env,jobject thismenu);
 388 extern jobject awtJNI_CreateAndSetGlobalRef(JNIEnv *env,jobject thiscomp);
 389 extern void awtJNI_CleanupGlobalRefs(void);
 390 
 391 #ifndef HEADLESS
 392 /* XXX: Motif internals. Need to fix 4090493. */
 393 #define MOTIF_XmINVALID_DIMENSION       ((Dimension) 0xFFFF)
 394 #define MOTIF_XmDEFAULT_INDICATOR_DIM   ((Dimension) 9)
 395 
 396 extern Dimension awt_computeIndicatorSize(struct FontData *fdata);
 397 extern Dimension awt_adjustIndicatorSizeForMenu(Dimension indSize);
 398 #endif /* !HEADLESS */
 399 
 400 #endif           /* _AWT_P_H_ */