home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /////////////////////////////////////////////////////////////
- //
- // Source file for DrcmapControlDerived
- //
- // This file generated by BuilderXcessory.
- /////////////////////////////////////////////////////////////
-
- #include "DrcmapControlDerived.h"
- #include <iostream.h>
- #include <Xm/List.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include "XLayerUtil.h"
- #include <Vk/VkApp.h>
- #include <Vk/VkIcon.h>
- #include <Vk/xpm.h>
- #include "drcmap.xpm"
- #include "bbl.xpm"
- #include "bbinvl.xpm"
- #include "bbr.xpm"
- #include "bbinvr.xpm"
- #include <X11/cursorfont.h>
- #include <X11/Xmu/WinUtil.h>
-
- char *installNames[] = {
- "No",
- "Yes",
- };
-
- char *vtypeNames[] = {
- "Underlay",
- "Normal",
- "Overlay",
- "Popup",
- };
-
-
- char *vclassNames[] = {
- "StaticGray",
- "GrayScale",
- "StaticColor",
- "PseudoColor",
- "TrueColor",
- "DirectColor",
- };
-
- enum Vtype {underlay, normal, overlay, popup};
-
- struct {
- Colormap cmap;
- int vclass;
- enum Vtype vtype;
- int depth;
- int installed;
- int numRefs;
- int layer;
- Visual *visual;
- GC gc;
- Window win;
- int winIO;
- char title[80];
- } allcmaps[1000];
-
- int cmapCnt = 0;
- int cmapsInstalled = 0;
- int winCnt = 0;
- int winChoice;
- Widget list;
- Widget rgbDisp;
- Window drawArea;
- Window basewind;
- DrawwinDerived *drawwin;
- Pixmap drcmapPixmap;
- Pixmap drcmapShapemask;
- Pixmap bblPixmap;
- Pixmap bblShapemask;
- Pixmap bbinvlPixmap;
- Pixmap bbinvlShapemask;
- Pixmap bbrPixmap;
- Pixmap bbrShapemask;
- Pixmap bbinvrPixmap;
- Pixmap bbinvrShapemask;
-
- extern "C" {
- Boolean buildList(XtPointer);
- void scanXTree(Display *, Window, Window, int);
- void walkTree(Display *, Window, Window, int, int);
- enum Vtype identifyVisual(Display *, Visual *);
- void buildWin(Display *, Window, int);
- void setWMColormaps(Display *, Window);
- void displayColormap(Display *);
- void updateWindowsAndList(Display *);
- Window Select_Window(Display *);
- void getWindowCmapInfo(Display *, Window, Window);
- };
-
-
- DrcmapControlDerived::DrcmapControlDerived(const char *name, Widget parent) :
- DrcmapControl(name, parent)
- {
- char *colors[] = {
- "highlightColor1",
- NULL
- };
-
- XpmAttributes attr;
- int status = 0;
- Display *dpy;
-
-
- winChoice = 0;
- list = _list1;
- rgbDisp = _rgbDisp;
- drawwin = _drawwin;
- XtAppContext app = XtWidgetToApplicationContext(_drawwin->baseWidget());
- XtAppAddWorkProc(app, buildList, _drawwin);
-
- dpy = XtDisplay(theApplication->baseWidget());
- basewind = XtWindow(theApplication->baseWidget());
- /*
- colormap = XCreateColormap(dpy, basewind,
- DefaultVisual(dpy, DefaultScreen(dpy)),
- AllocNone);
- attr.colormap = colormap;
- attr.valuemask = XpmColormap | XpmCloseness;
- */
- attr.valuemask = XpmCloseness;
- attr.closeness = 40000;
-
- status = XpmCreatePixmapFromData(dpy,
- DefaultRootWindow(dpy),
- docbak, &drcmapPixmap, &drcmapShapemask,
- &attr);
- if (status)
- cout << "error creating pixmap" << endl;
-
- XtVaSetValues(_baseWidget,
- XmNbackgroundPixmap, drcmapPixmap,
- NULL);
-
- status = XpmCreatePixmapFromData(dpy,
- basewind,
- bbl, &bblPixmap, &bblShapemask,
- &attr);
- if (status)
- cout << "error creating pixmap" << endl;
-
- status = XpmCreatePixmapFromData(dpy,
- basewind,
- bbinvl, &bbinvlPixmap, &bbinvlShapemask,
- &attr);
- if (status)
- cout << "error creating pixmap" << endl;
-
- status = XpmCreatePixmapFromData(dpy,
- basewind,
- bbr, &bbrPixmap, &bbrShapemask,
- &attr);
- if (status)
- cout << "error creating pixmap" << endl;
-
- status = XpmCreatePixmapFromData(dpy,
- basewind,
- bbinvr, &bbinvrPixmap, &bbinvrShapemask,
- &attr);
- if (status)
- cout << "error creating pixmap" << endl;
-
-
- XtVaSetValues(_prevCmap1,
- XmNlabelPixmap, bblPixmap,
- NULL);
-
- XtVaSetValues(_nextCmap1,
- XmNlabelPixmap, bbrPixmap,
- NULL);
- }
-
-
- DrcmapControlDerived::~DrcmapControlDerived()
- {
- // Empty
- }
-
-
- const char * DrcmapControlDerived::className() // classname
- {
- return ("DrcmapControlDerived");
- }
-
- void DrcmapControlDerived::pickCmap(Widget w, XtPointer calldata)
- {
- XmListCallbackStruct *cbs = (XmListCallbackStruct *)calldata;
-
- if (cbs->reason == XmCR_BROWSE_SELECT) {
- winChoice = cbs->item_position - 1;
- updateWindowsAndList(XtDisplay(w));
- displayColormap(XtDisplay(w));
- }
- else
- cout << "other select" << endl;
- }
-
- void DrcmapControlDerived::prevCmap(Widget w, XtPointer)
- {
- if (cmapCnt == 1)
- return;
- winChoice--;
- if (winChoice < 0)
- winChoice = cmapCnt - 1;
- updateWindowsAndList(XtDisplay(w));
- displayColormap(XtDisplay(w));
- }
-
-
- void DrcmapControlDerived::nextCmap(Widget w, XtPointer)
- {
- if (cmapCnt == 1)
- return;
- winChoice++;
- winChoice = winChoice % cmapCnt;
- updateWindowsAndList(XtDisplay(w));
- displayColormap(XtDisplay(w));
- }
-
-
- void DrcmapControlDerived::pushedBtnl(Widget w, XtPointer)
- {
- XtVaSetValues(w,
- XmNlabelPixmap, bbinvlPixmap,
- NULL);
- }
-
- void DrcmapControlDerived::normalBtnl(Widget w, XtPointer)
- {
- XtVaSetValues(w,
- XmNlabelPixmap, bblPixmap,
- NULL);
- }
-
-
- void DrcmapControlDerived::pushedBtnr(Widget w, XtPointer)
- {
- XtVaSetValues(w,
- XmNlabelPixmap, bbinvrPixmap,
- NULL);
- }
-
- void DrcmapControlDerived::normalBtnr(Widget w, XtPointer)
- {
- XtVaSetValues(w,
- XmNlabelPixmap, bbrPixmap,
- NULL);
- }
-
-
- void DrcmapControlDerived::rootList(Widget w, XtPointer)
- {
- scanXTree(XtDisplay(w),
- RootWindow(XtDisplay(w), DefaultScreen(XtDisplay(w))),
- XtWindow(_drawwin->baseWidget()), 1);
- }
-
-
- void DrcmapControlDerived::pickList(Widget w, XtPointer)
- {
- scanXTree(XtDisplay(w),
- Select_Window(XtDisplay(w)),
- XtWindow(_drawwin->baseWidget()), 1);
- }
-
-
- void DrcmapControlDerived::setList(XmString *items, int itemCnt)
- {
-
- XmListAddItems(_list1, items, itemCnt, 0);
- }
-
-
- Boolean
- buildList(XtPointer widg)
- {
- DrawwinDerived *drawW = (DrawwinDerived *)widg;
- Widget w = drawW->baseWidget();
- static int first = 1;
-
- drawArea = XtWindow(w);
- if (!drawW->isExposed())
- return(False);
-
- if (first) {
- first = 0;
- scanXTree(XtDisplay(w),
- RootWindow(XtDisplay(w), DefaultScreen(XtDisplay(w))),
- XtWindow(w), 0);
- setWMColormaps(XtDisplay(w), XtWindow(theApplication->baseWidget()));
- updateWindowsAndList(XtDisplay(w));
- displayColormap(XtDisplay(w));
- }
- return(True);
- }
-
-
-
-
- void
- scanXTree(Display *dpy, Window startWin, Window attachWin, int recurse)
- {
- winCnt = 0;
- XDestroySubwindows(dpy, attachWin);
- cmapCnt = 0;
- XmListDeleteAllItems(list);
- theApplication->busy();
- getWindowCmapInfo(dpy, startWin, attachWin);
- walkTree(dpy, startWin, attachWin, recurse, 0);
- theApplication->notBusy();
- }
-
-
-
- void
- walkTree(Display *dpy, Window startWin, Window attachWin, int recurse, int level)
- {
- int i;
- Window root_win, parent_win;
- unsigned int num_children;
- Window *child_list;
-
- if (!XQueryTree(dpy, startWin, &root_win, &parent_win, &child_list,
- &num_children)) {
- fprintf(stderr, "Can't query window tree.");
- exit(-1);
- }
-
- winCnt += num_children;
-
- getWindowCmapInfo(dpy, startWin, attachWin);
-
- for (i = (int)num_children - 1; i >= 0; i--) {
- if (recurse)
- walkTree(dpy, child_list[i], attachWin, 1, level+1);
- }
- if (child_list) XFree((char *)child_list);
- }
-
-
- void
- getWindowCmapInfo(Display *dpy, Window startWin, Window attachWin)
- {
- int j;
- XWindowAttributes win_attributes;
- XVisualInfo vistemplate;
- XVisualInfo *vinfo;
- int junk;
- XmString item;
- int newcmap;
-
-
- if (!XGetWindowAttributes(dpy, startWin, &win_attributes)) {
- fprintf(stderr, "Can't get window attributes.");
- exit(-1);
- }
- vistemplate.visualid = XVisualIDFromVisual(win_attributes.visual);
- vinfo = XGetVisualInfo(dpy, VisualIDMask, &vistemplate, &junk);
-
- newcmap = 1;
- for (j = 0; j < cmapCnt; j++)
- if (win_attributes.colormap == allcmaps[j].cmap) {
- allcmaps[j].numRefs++;
- if (win_attributes.map_installed)
- allcmaps[j].installed = True;
- newcmap = 0;
- break;
- }
-
- if (newcmap && win_attributes.depth != 0) { /* if InputOnly, ignore */
- allcmaps[cmapCnt].numRefs++;
- allcmaps[cmapCnt].cmap = win_attributes.colormap;
- allcmaps[cmapCnt].vclass = vinfo->c_class;
- allcmaps[cmapCnt].visual = vinfo->visual;
- allcmaps[cmapCnt].vtype = identifyVisual(dpy, vinfo->visual);
- allcmaps[cmapCnt].depth = win_attributes.depth;
- allcmaps[cmapCnt].winIO = win_attributes.c_class;
- if (win_attributes.map_installed)
- cmapsInstalled++;
- else
- allcmaps[cmapCnt].installed = 0;
- sprintf(allcmaps[cmapCnt].title, "%-8s %2d %-11s 0x%-x",
- vtypeNames[allcmaps[cmapCnt].vtype],
- allcmaps[cmapCnt].depth,
- vclassNames[allcmaps[cmapCnt].vclass],
- allcmaps[cmapCnt].cmap);
- item = XmStringCreateSimple(allcmaps[cmapCnt].title);
- XmListAddItem(list, item, 0);
- buildWin(dpy, attachWin, cmapCnt);
- winChoice = cmapCnt;
- cmapCnt++;
- updateWindowsAndList(dpy);
- displayColormap(dpy);
- }
- }
-
-
-
- enum Vtype
- identifyVisual(Display *dpy, Visual *vis)
- {
- int nVisuals;
- static int defLayer;
- int tmpLayer;
- XLayerVisualInfo tmpLayerInfo;
- XLayerVisualInfo *defaultLayerInfo;
- Visual *defaultVisual;
- static int first = 1;
-
- if (first) {
- defaultVisual = DefaultVisual(dpy, DefaultScreen(dpy));
- tmpLayerInfo.vinfo.visualid = defaultVisual->visualid;
- defaultLayerInfo = XGetLayerVisualInfo(dpy, VisualIDMask, &tmpLayerInfo, &nVisuals);
- defLayer = defaultLayerInfo->layer;
- first = 0;
- }
-
- tmpLayerInfo.vinfo.visualid = vis->visualid;
- defaultLayerInfo = XGetLayerVisualInfo(dpy,
- VisualIDMask, &tmpLayerInfo, &nVisuals);
- tmpLayer = defaultLayerInfo->layer;
-
- if (tmpLayer < defLayer && defaultLayerInfo->type != None)
- return(underlay);
- else if (tmpLayer == defLayer)
- return(normal);
- else if (tmpLayer == defLayer + 1 && defaultLayerInfo->type != None)
- return(overlay);
- else if (tmpLayer == defLayer + 2 && defaultLayerInfo->type != None)
- return(popup);
- else {
- fprintf(stderr, "error determining layer\n");
- exit(-1);
- return(popup);
- }
- }
-
-
- void
- buildWin(Display *dpy, Window win, int newWin)
- {
- XSetWindowAttributes winattr;
-
- winattr.event_mask = ExposureMask;
- winattr.background_pixel = None;
- winattr.colormap = allcmaps[newWin].cmap;
- winattr.border_pixel = None;
-
- allcmaps[newWin].win = XCreateWindow(dpy, win,
- 1, 1, 256, 256,
- 0, allcmaps[newWin].depth, allcmaps[newWin].winIO,
- allcmaps[newWin].visual,
- CWEventMask | CWBackPixel | CWBorderPixel | CWColormap, &winattr);
-
- allcmaps[newWin].gc = XCreateGC(dpy, allcmaps[newWin].win, NULL, NULL);
- }
-
-
- void
- setWMColormaps(Display *dpy, Window win)
- {
- int i;
- Window tmpwins[100];
-
- for (i = 0; i < cmapCnt; i++)
- tmpwins[i] = allcmaps[i].win;
- XSetWMColormapWindows(dpy, win, tmpwins, cmapCnt);
- }
-
-
- void
- updateWindowsAndList(Display *dpy)
- {
- static int lastChoice = 0;
- int top, visible;
-
- XmListSelectPos(list, winChoice + 1, False);
- XtVaGetValues(list,
- XmNtopItemPosition, &top,
- XmNvisibleItemCount, &visible,
- NULL);
- if (winChoice + 1 < top)
- XmListSetPos(list, winChoice + 1);
- else if (winChoice + 1 >= top + visible)
- XmListSetBottomPos(list, winChoice + 1);
-
- // XClearWindow(dpy, drawArea);
- // XUnmapWindow(dpy, allcmaps[lastChoice].win);
- XUnmapSubwindows(dpy, drawArea);
- XClearWindow(dpy, allcmaps[winChoice].win);
- XMapWindow(dpy, allcmaps[winChoice].win);
- lastChoice = winChoice;
- }
-
-
- void
- displayColormap(Display *dpy)
- {
- int i;
- int sqw = 16;
- int sqh = 16;
- int cells;
- int cellx;
- div_t loc;
- int locx, locy, loccell;
- XColor color;
- char colorStr[80];
- XmString item;
-
- if (cmapCnt == 0) // buildList (of cmaps) has not be run yet
- return;
-
- cells = allcmaps[winChoice].visual->map_entries;
- if (cells > 256)
- cells = 256;
- cellx = 16;
-
- loc = div(drawwin->selectx, sqw);
- locx = loc.quot;
-
- loc = div(drawwin->selecty, sqh);
- locy = loc.quot;
-
- loccell = locy * cellx + locx;
-
- if (loccell > cells)
- loccell = cells;
-
- for (i = 0; i < cells; i++) {
- XSetForeground(dpy, allcmaps[winChoice].gc, i);
- if (cells <= 256) {
- XFillRectangle(dpy, allcmaps[winChoice].win, allcmaps[winChoice].gc,
- (i % cellx) * sqw, (i / cellx) * sqh, sqw, sqh);
- if (i == loccell) {
- XSetFunction(dpy, allcmaps[winChoice].gc, GXxor);
- XSetLineAttributes(dpy, allcmaps[winChoice].gc, 2, 0, 0, 0);
- XDrawRectangle(dpy, allcmaps[winChoice].win, allcmaps[winChoice].gc,
- (i % cellx) * sqw, (i / cellx) * sqh, sqw - 1, sqh - 1);
- XSetLineAttributes(dpy, allcmaps[winChoice].gc, 1, 0, 0, 0);
- XSetFunction(dpy, allcmaps[winChoice].gc, GXcopy);
- color.pixel = i;
- XQueryColor(dpy, allcmaps[winChoice].cmap, &color);
- sprintf(colorStr, "%d R:%d G:%d B:%d", i,
- color.red >> 8,
- color.green >> 8,
- color.blue >> 8);
- item = XmStringCreateSimple(colorStr);
- XtVaSetValues(rgbDisp,
- XmNlabelString, item,
- NULL);
- }
- }
- else
- XDrawPoint(dpy, allcmaps[winChoice].win, allcmaps[winChoice].gc,
- (i % cellx), (i / cellx));
- }
- }
-
-
-
-
- /*
- * Routine to let user select a window using the mouse
- */
-
- Window Select_Window(Display *dpy)
- {
- int status;
- Cursor cursor;
- XEvent event;
- Window target_win = None, root = RootWindow(dpy,DefaultScreen(dpy));
- int buttons = 0;
- int dummyi;
- unsigned int dummy;
-
- /* Make the target cursor */
- cursor = XCreateFontCursor(dpy, XC_crosshair);
-
- /* Grab the pointer using target cursor, letting it room all over */
- status = XGrabPointer(dpy, root, False,
- (unsigned long)ButtonPressMask|ButtonReleaseMask, GrabModeSync,
- GrabModeAsync, root, cursor, CurrentTime);
- if (status != GrabSuccess) printf("Can't grab the mouse.");
-
- /* Let the user select a window... */
- while ((target_win == None) || (buttons != 0)) {
- /* allow one more event */
- XAllowEvents(dpy, SyncPointer, CurrentTime);
- XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event);
- switch (event.type) {
- case ButtonPress:
- if (target_win == None) {
- target_win = event.xbutton.subwindow; /* window selected */
- if (target_win == None) target_win = root;
- }
- buttons++;
- break;
- case ButtonRelease:
- if (buttons > 0) /* there may have been some down before we started */
- buttons--;
- break;
- }
- }
-
- XUngrabPointer(dpy, CurrentTime); /* Done with pointer */
-
- if (XGetGeometry (dpy, target_win, &root, &dummyi, &dummyi,
- &dummy, &dummy, &dummy, &dummy) &&
- target_win != root)
- target_win = XmuClientWindow (dpy, target_win);
-
- return(target_win);
- }
-
-
-