/*___INFO__MARK_BEGIN__*/ /************************************************************************* * * The Contents of this file are made available subject to the terms of * the Sun Industry Standards Source License Version 1.2 * * Sun Microsystems Inc., March, 2001 * * * Sun Industry Standards Source License Version 1.2 * ================================================= * The contents of this file are subject to the Sun Industry Standards * Source License Version 1.2 (the "License"); You may not use this file * except in compliance with the License. You may obtain a copy of the * License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html * * Software provided under this License is provided on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. * See the License for the specific provisions governing your rights and * obligations concerning the Software. * * The Initial Developer of the Original Code is: Sun Microsystems, Inc. * * Copyright: 2001 by Sun Microsystems, Inc. * * All Rights Reserved. * ************************************************************************/ /*___INFO__MARK_END__*/ #include #include #include #include #include #include #include #include #include #include "qmon_util.h" #include "qmon_cull.h" #include "qmon_rmon.h" #if XmVersion < 1002 /*-------------------------------------------------------------------------*/ void XmListDeletePositions(Widget list, int *pos_list, int pos_count) { int i; for (i=0; i delete the rest */ DTRACE; if (i= ws) x = 0; else x = (ws - w) / 2; if ((y + h) >= hs) y = 0; else y = (hs - h) / 2; XtVaSetValues(dialog, XmNx, x, XmNy, y, NULL); DEXIT; } /*-------------------------------------------------------------------------*/ void SetMinShellSize(Widget shell, XtPointer cld, XEvent *event, Boolean *ctd) { XConfigureEvent *cevent = (XConfigureEvent*)event; DENTER(GUI_LAYER, "SetMinShellSize"); if (cevent->type != ConfigureNotify) { DEXIT; return; } if (!cld) { XtVaSetValues( shell, XmNminWidth, cevent->width, XmNminHeight, cevent->height, NULL); } else if ((long)cld == SHELL_WIDTH) { XtVaSetValues( shell, XmNminWidth, cevent->width, NULL); } else if ((long)cld == SHELL_HEIGHT) { XtVaSetValues( shell, XmNminHeight, cevent->height, NULL); } XtRemoveEventHandler(shell, StructureNotifyMask, False, SetMinShellSize, NULL); DEXIT; } /*-------------------------------------------------------------------------*/ void SetMaxShellSize(Widget shell, XtPointer cld, XEvent *event, Boolean *ctd) { XConfigureEvent *cevent = (XConfigureEvent*)event; DENTER(GUI_LAYER, "SetMinShellSize"); if (cevent->type != ConfigureNotify) { DEXIT; return; } if (!cld) { XtVaSetValues( shell, XmNmaxWidth, cevent->width, XmNmaxHeight, cevent->height, NULL); } else if ((long)cld == SHELL_WIDTH) { XtVaSetValues( shell, XmNmaxWidth, cevent->width, NULL); } else if ((long)cld == SHELL_HEIGHT) { XtVaSetValues( shell, XmNmaxHeight, cevent->height, NULL); } XtRemoveEventHandler(shell, StructureNotifyMask, False, SetMaxShellSize, NULL); DEXIT; } /*-------------------------------------------------------------------------*/ int qmonForkEditor(String file) { char *cp; char *editor = NULL; char command[BUFSIZ]; static char default_editor[] = "vi"; int status; DENTER(GUI_LAYER, "qmonForkEditor"); if (!(editor = getenv("EDITOR"))) editor = default_editor; cp = strrchr(editor, '/'); if (cp && !strcmp(cp + 1, "jot")) strcpy(command, editor); else sprintf(command, "xterm -e %s", editor); if (file) sprintf(command, "%s %s &", command, file ? file : ""); else strcat(command, "&"); status = system(command); DEXIT; return status; } /*-------------------------------------------------------------------------*/ void qmonXmStringDrawImage(Display *dpy, Drawable da, GC gc, Position x, Position y, XmFontList fontlist, XmString str, unsigned char layout, XRectangle *clip, Dimension *width, Dimension *height) { DENTER(GUI_LAYER, "qmonDrawRequestEntry"); /* GET THE BOUNDING BOX */ XmStringExtent(fontlist, str, width, height); /* DRAW RECTANGLE AND LABEL */ XmStringDrawImage(dpy, da, fontlist, str, gc, x, y, *width, layout, XmSTRING_DIRECTION_L_TO_R, clip); DEXIT; } /*-------------------------------------------------------------------------*/ void qmonXmStringDraw(Display *dpy, Drawable da, GC gc, Position x, Position y, XmFontList fontlist, XmString str, unsigned char layout, XRectangle *clip, Dimension *width, Dimension *height) { DENTER(GUI_LAYER, "qmonXmStringDraw"); /* GET THE BOUNDING BOX */ XmStringExtent(fontlist, str, width, height); /* DRAW RECTANGLE AND LABEL */ XmStringDraw(dpy, da, fontlist, str, gc, x, y, *width, layout, XmSTRING_DIRECTION_L_TO_R, clip); DEXIT; } /*-------------------------------------------------------------------------*/ void setButtonLabel(Widget w, String label) { XmString xlab; DENTER(GUI_LAYER, "setButtonLabel"); xlab = XmtCreateLocalizedXmString(w, label); XtVaSetValues(w, XmNlabelString, xlab, NULL); XmStringFree(xlab); DEXIT; } /*-------------------------------------------------------------------------*/ void qmonScaleWeightToggle(Widget w, XtPointer cld, XtPointer cad) { XmToggleButtonCallbackStruct *cbs = (XmToggleButtonCallbackStruct*)cad; tScaleWeight *weights = (tScaleWeight*) cld; int index; int *ip; DENTER(GUI_LAYER, "qmonScaleWeightToggle"); XtVaGetValues(w, XmNuserData, &ip, NULL); index = *ip; DPRINTF(("index = %d\n", index)); if (cbs->set) { weights[index].lock = 1; XtSetSensitive(weights[index].scale, False); } else { weights[index].lock = 0; XtSetSensitive(weights[index].scale, True); } DEXIT; } /*-------------------------------------------------------------------------*/ void qmonScaleWeight(Widget w, XtPointer cld, XtPointer cad) { XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*)cad; tScaleWeight *weights = (tScaleWeight*) cld; int delta; int *ip; int index; int count = 0; int i, j; int max_value = 0; int delta_part; int sum = 0; DENTER(GUI_LAYER, "qmonScaleWeight"); XtVaGetValues(w, XmNuserData, &ip, NULL); index = *ip; DPRINTF(("index = %d\n", index)); if (cbs->value != weights[index].weight) { /* ** get the max_value and the number of non-locked scales */ for (i=0; ivalue > max_value) weights[index].weight = max_value; else weights[index].weight = cbs->value; max_value -= weights[index].weight; if (!max_value) { /* ** set the remaining non-locked scales to zero */ for (i=0; i max_value) { weights[i].weight = max_value; } max_value -= weights[i].weight; delta = max_value; if (max_value) { for (j=i+1; j= lowerBound) { int i = lowerBound + (upperBound - lowerBound) / 2; /* convert XmString to String */ if (!XmStringGetLtoR(items[i], XmFONTLIST_DEFAULT_TAG, &text)) break; if (strcmp(text, item2) > 0) upperBound = i - 1; /* text comes after item2 */ else lowerBound = i + 1; /* text comes before item2 */ XtFree(text); } XtFree(item2); XmListAddItemUnselected(list, xmitem, lowerBound + 1); } DEXIT; } /*-------------------------------------------------------------------------*/ void XmListAddItemUniqueSorted(Widget list, String item) { XmString xmitem = NULL; XmString *items = NULL; int upperBound = 0, lowerBound = 0; String text = NULL, item2 = NULL; DENTER(GUI_LAYER, "AddItemUniqueSorted"); if (item && item[0] != '\0') { /* ** fix the strange behavior of @f* hostgroup names, this is caused ** by the Xmt font converter that interpretes @f as the beginning of ** a font change */ char buf[10000]; if (item[0] == '@' && item[1] != '{') sprintf(buf, "@%s", item); else sprintf(buf, item); xmitem = XmtCreateLocalizedXmString(list, buf); if (XmListItemExists(list, xmitem)) { XmStringFree(xmitem); DEXIT; return; } if (!XmStringGetLtoR(xmitem, XmFONTLIST_DEFAULT_TAG, &item2)) { XmStringFree(xmitem); DEXIT; return; } XtVaGetValues( list, XmNitems, &items, XmNitemCount, &upperBound, NULL); /* ** binary search through the items in the list */ upperBound--; while (upperBound >= lowerBound) { int i = lowerBound + (upperBound - lowerBound) / 2; /* convert XmString to String */ if (!XmStringGetLtoR(items[i], XmFONTLIST_DEFAULT_TAG, &text)) break; if (strcmp(text, item2) > 0) upperBound = i - 1; /* text comes after item2 */ else lowerBound = i + 1; /* text comes before item2 */ XtFree(text); } XtFree(item2); XmListAddItemUnselected(list, xmitem, lowerBound + 1); XmStringFree(xmitem); } DEXIT; } /*-------------------------------------------------------------------------*/ void XmListMoveItemToPos(Widget list, String item, int pos) { XmString xmitem = NULL; DENTER(GUI_LAYER, "XmListMoveItemToPos"); if (item && item[0] != '\0') { xmitem = XmtCreateXmString(item); if (XmListItemExists(list, xmitem)) { XmListDeleteItem(list, xmitem); XmListAddItem(list, xmitem, pos); } XmStringFree(xmitem); } DEXIT; } /* ** removes leading and trailing whitespace ** the string is changed */ char *qmon_trim( char *s ) { int len, i; if (!s) return NULL; /* ** remove leading whitespace */ while (*s && isspace(*s)) s++; len = strlen(s) - 1; for (i=len; i>0 && *s && isspace(s[i]); i--) s[i] = '\0'; return s; } void ForceUpdate( Widget w ) { Widget diashell, topshell; Window diawindow, topwindow; XtAppContext cxt = XtWidgetToApplicationContext(w); Display *dpy; XWindowAttributes xwa; XEvent event; for (diashell = w; !XtIsShell(diashell); diashell = XtParent(diashell)) ; for (topshell = diashell; !XtIsTopLevelShell(topshell); topshell = XtParent(topshell)) ; if (XtIsRealized(diashell) && XtIsRealized(topshell)) { dpy = XtDisplay(topshell); diawindow = XtWindow(diashell); topwindow = XtWindow(topshell); while (XGetWindowAttributes(dpy, diawindow, &xwa) && xwa.map_state != IsViewable) { if (XGetWindowAttributes(dpy, topwindow, &xwa) && xwa.map_state != IsViewable) break; XtAppNextEvent(cxt, &event); XtDispatchEvent(&event); } } XmUpdateDisplay(topshell); }