Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/awt/VDrawingArea.c
32287 views
/*1* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#ifndef HEADLESS2627#include <X11/IntrinsicP.h>28#include "VDrawingAreaP.h"2930#endif /* !HEADLESS */3132#include <stdio.h>33#include <stdlib.h>3435#ifdef __linux__36/* XXX: Shouldn't be necessary. */37#include "awt_p.h"38#endif /* __linux__ */394041/******************************************************************42*43* Provides Canvas widget which allows the X11 visual to be44* changed (the Motif DrawingArea restricts the visual to that45* of the parent widget).46*47******************************************************************/484950/******************************************************************51*52* VDrawingArea Widget Resources53*54******************************************************************/5556#ifndef HEADLESS57#define Offset(x) (XtOffsetOf(VDrawingAreaRec, x))58static XtResource resources[]=59{60{ XtNvisual, XtCVisual, XtRVisual, sizeof(Visual*),61Offset(vdrawing_area.visual), XtRImmediate, CopyFromParent}62};636465static void Realize();66static Boolean SetValues();67static void Destroy ();6869static XmBaseClassExtRec baseClassExtRec = {70NULL,71NULLQUARK,72XmBaseClassExtVersion,73sizeof(XmBaseClassExtRec),74NULL, /* InitializePrehook */75NULL, /* SetValuesPrehook */76NULL, /* InitializePosthook */77NULL, /* SetValuesPosthook */78NULL, /* secondaryObjectClass */79NULL, /* secondaryCreate */80NULL, /* getSecRes data */81{ 0 }, /* fastSubclass flags */82NULL, /* getValuesPrehook */83NULL, /* getValuesPosthook */84NULL, /* classPartInitPrehook */85NULL, /* classPartInitPosthook*/86NULL, /* ext_resources */87NULL, /* compiled_ext_resources*/880, /* num_ext_resources */89FALSE, /* use_sub_resources */90NULL, /* widgetNavigable */91NULL, /* focusChange */92NULL /* wrapper_data */93};9495VDrawingAreaClassRec vDrawingAreaClassRec = {96{97/* Core class part */9899/* superclass */ (WidgetClass)&xmDrawingAreaClassRec,100/* class_name */ "VDrawingArea",101/* widget_size */ sizeof(VDrawingAreaRec),102/* class_initialize */ NULL,103/* class_part_initialize*/ NULL,104/* class_inited */ FALSE,105/* initialize */ NULL,106/* initialize_hook */ NULL,107/* realize */ Realize,108/* actions */ NULL,109/* num_actions */ 0,110/* resources */ resources,111/* num_resources */ XtNumber(resources),112/* xrm_class */ NULLQUARK,113/* compress_motion */ FALSE,114/* compress_exposure */ FALSE,115/* compress_enterleave*/ FALSE,116/* visible_interest */ FALSE,117/* destroy */ Destroy,118/* resize */ XtInheritResize,119/* expose */ XtInheritExpose,120/* set_values */ SetValues,121/* set_values_hook */ NULL,122/* set_values_almost */ XtInheritSetValuesAlmost,123/* get_values_hook */ NULL,124/* accept_focus */ NULL,125/* version */ XtVersion,126/* callback_offsets */ NULL,127/* tm_table */ NULL,128/* query_geometry */ NULL,129/* display_accelerator */ NULL,130/* extension */ NULL131},132133{ /* composite_class fields */134XtInheritGeometryManager, /* geometry_manager */135XtInheritChangeManaged, /* change_managed */136XtInheritInsertChild, /* insert_child */137XtInheritDeleteChild, /* delete_child */138NULL, /* extension */139},140141{ /* constraint_class fields */142NULL, /* resource list */1430, /* num resources */1440, /* constraint size */145NULL, /* init proc */146NULL, /* destroy proc */147NULL, /* set values proc */148NULL, /* extension */149},150151{ /* manager_class fields */152XtInheritTranslations, /* translations */153NULL, /* syn_resources */1540, /* num_get_resources */155NULL, /* syn_cont_resources */1560, /* num_get_cont_resources */157XmInheritParentProcess, /* parent_process */158NULL, /* extension */159},160161{ /* drawingArea class */162/* extension */ NULL163},164165/* VDrawingArea class part */166{167/* extension */ NULL168}169};170171WidgetClass vDrawingAreaClass = (WidgetClass)&vDrawingAreaClassRec;172173static Boolean174SetValues(cw, rw, nw, args, num_args)175Widget cw;176Widget rw;177Widget nw;178ArgList args;179Cardinal *num_args;180{181VDrawingAreaWidget current = (VDrawingAreaWidget)cw;182VDrawingAreaWidget new_w = (VDrawingAreaWidget)nw;183184if (new_w->vdrawing_area.visual != current->vdrawing_area.visual) {185new_w->vdrawing_area.visual = current->vdrawing_area.visual;186#ifdef DEBUG187fprintf(stdout, "VDrawingArea.SetValues: can't change visual from: visualID=%ld to visualID=%ld\n",188current->vdrawing_area.visual->visualid,189new_w->vdrawing_area.visual->visualid);190#endif191192}193194return (False);195}196197int198FindWindowInList (Window parentWindow, Window *colormap_windows, int count)199{200int i;201202for (i = 0; i < count; i++)203if (colormap_windows [i] == parentWindow)204return i;205return -1;206}207208static void209Realize(w, value_mask, attributes)210Widget w;211XtValueMask *value_mask;212XSetWindowAttributes *attributes;213{214Widget parent;215Status status;216Window *colormap_windows;217Window *new_colormap_windows;218int count;219int i;220VDrawingAreaWidget vd = (VDrawingAreaWidget)w;221222#ifdef DEBUG223fprintf(stdout, "VDrawingArea.Realize: visualID=%ld, depth=%d\n",224vd->vdrawing_area.visual->visualid, w->core.depth);225#endif226227/* 4328588:228* Since we have our own Realize() function, we don't execute the one for229* our super-super class, XmManager, and miss the code which checks that230* height and width != 0. I've added that here. -bchristi231*/232if (!XtWidth(w)) XtWidth(w) = 1 ;233if (!XtHeight(w)) XtHeight(w) = 1 ;234235w->core.window = XCreateWindow (XtDisplay (w), XtWindow (w->core.parent),236w->core.x, w->core.y, w->core.width, w->core.height,2370, w->core.depth, InputOutput,238vd->vdrawing_area.visual,239*value_mask, attributes );240241/* Need to add this window to the list of Colormap windows */242parent = XtParent (w);243while ((parent != NULL) && (!(XtIsShell (parent))))244parent = XtParent (parent);245if (parent == NULL) {246fprintf (stderr, "NO TopLevel widget?!\n");247return;248}249250status = XGetWMColormapWindows (XtDisplay (w), XtWindow (parent),251&colormap_windows, &count);252253/* If status is zero, add this window and shell to the list254of colormap Windows */255if (status == 0) {256new_colormap_windows = (Window *) calloc (2, sizeof (Window));257new_colormap_windows [0] = XtWindow (w);258new_colormap_windows [1] = XtWindow (parent);259XSetWMColormapWindows (XtDisplay (w), XtWindow (parent),260new_colormap_windows, 2);261free (new_colormap_windows);262} else {263/* Check if parent is already in the list */264int parent_entry = -1;265266if (count > 0)267parent_entry = FindWindowInList (XtWindow (parent),268colormap_windows, count);269if (parent_entry == -1) { /* Parent not in list */270new_colormap_windows = (Window *) calloc (count + 2,271sizeof (Window));272new_colormap_windows [0] = XtWindow (w);273new_colormap_windows [1] = XtWindow (parent);274for (i = 0; i < count; i++)275new_colormap_windows [i + 2] = colormap_windows [i];276XSetWMColormapWindows (XtDisplay (w), XtWindow (parent),277new_colormap_windows, count + 2);278279} else { /* parent already in list, just add new window */280new_colormap_windows = (Window *) calloc (count + 1,281sizeof (Window));282new_colormap_windows [0] = XtWindow (w);283for (i = 0; i < count; i++)284new_colormap_windows [i + 1] = colormap_windows [i];285XSetWMColormapWindows (XtDisplay (w), XtWindow (parent),286new_colormap_windows, count + 1);287}288free (new_colormap_windows);289XFree (colormap_windows);290}291292293}294295static void296Destroy(Widget widget)297{298Status status;299Widget parent;300Window *colormap_windows;301Window *new_colormap_windows;302int count;303int listEntry;304int i;305int j;306307/* Need to get this window's parent shell first */308parent = XtParent (widget);309while ((parent != NULL) && (!(XtIsShell (parent))))310parent = XtParent (parent);311if (parent == NULL) {312fprintf (stderr, "NO TopLevel widget?!\n");313return;314}315316status = XGetWMColormapWindows (XtDisplay (widget), XtWindow (parent),317&colormap_windows, &count);318319/* If status is zero, then there were no colormap windows for320the parent ?? */321322if (status == 0)323return;324325/* Remove this window from the list of colormap windows */326listEntry = FindWindowInList (XtWindow (widget), colormap_windows,327count);328329new_colormap_windows = (Window *) calloc (count - 1, sizeof (Window));330j = 0;331for (i = 0; i < count; i++) {332if (i == listEntry)333continue;334new_colormap_windows [j] = colormap_windows [i];335j++;336}337XSetWMColormapWindows (XtDisplay (widget), XtWindow (parent),338new_colormap_windows, count - 1);339free (new_colormap_windows);340XFree (colormap_windows);341342}343#endif /* !HEADLESS */344345346