home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_GetHints.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  10KB  |  318 lines

  1. /* $XConsortium: GetHints.c,v 11.35 94/04/17 20:19:34 rws Exp $ */
  2.  
  3. /***********************************************************
  4.  
  5. Copyright (c) 1987  X Consortium
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  20. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  
  24. Except as contained in this notice, the name of the X Consortium shall not be
  25. used in advertising or otherwise to promote the sale, use or other dealings
  26. in this Software without prior written authorization from the X Consortium.
  27.  
  28.  
  29. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
  30.  
  31.                         All Rights Reserved
  32.  
  33. Permission to use, copy, modify, and distribute this software and its 
  34. documentation for any purpose and without fee is hereby granted, 
  35. provided that the above copyright notice appear in all copies and that
  36. both that copyright notice and this permission notice appear in 
  37. supporting documentation, and that the name of Digital not be
  38. used in advertising or publicity pertaining to distribution of the
  39. software without specific, written prior permission.  
  40.  
  41. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  42. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  43. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  44. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  45. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  46. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  47. SOFTWARE.
  48.  
  49. ******************************************************************/
  50.  
  51. #include "Xlib_private.h"
  52. #include <X11/Xos.h>
  53. #include <X11/Xutil.h>
  54. #include "Xatomtype.h"
  55. #include <X11/Xatom.h>
  56. #include <stdio.h>
  57.  
  58. Status XGetSizeHints (dpy, w, hints, property)
  59.     Display *dpy;
  60.     Window w;
  61.     XSizeHints *hints;
  62.         Atom property;
  63. {
  64.         DBUG_ENTER("XGetSizeHints")
  65.         XSizeHints *gothints;
  66.         Atom actual_type;
  67.         int actual_format;
  68.         unsigned long leftover;
  69.         unsigned long nitems;
  70.     if (XGetWindowProperty(dpy, w, property, 0L,
  71.                    (long) OldNumPropSizeElements,
  72.         False, XA_WM_SIZE_HINTS, &actual_type, &actual_format,
  73.             &nitems, &leftover, (unsigned char **)&gothints)
  74.             != Success) DBUG_RETURN(0);
  75.  
  76.         if ((actual_type != XA_WM_SIZE_HINTS) ||
  77.         (nitems < OldNumPropSizeElements) || (actual_format != 32)) {
  78.         if (gothints != NULL) free(gothints);
  79.                 DBUG_RETURN(0);
  80.         }
  81.         memcpy(hints, gothints, sizeof(XSizeHints));
  82.     Xfree((char *)gothints);
  83.     DBUG_RETURN(1);
  84. }
  85.  
  86. /* 
  87.  * must return a pointer to the hint, in malloc'd memory, or routine is not
  88.  * extensible; any use of the caller's memory would cause things to be stepped
  89.  * on.
  90.  */
  91.  
  92. XWMHints *XGetWMHints (dpy, w)
  93.     Display *dpy;
  94.     Window w;
  95. {
  96.     DBUG_ENTER("XGetWMHints")
  97.     XWMHints *hints;
  98.         Atom actual_type;
  99.         int actual_format;
  100.         unsigned long leftover;
  101.         unsigned long nitems;
  102.     if (XGetWindowProperty(dpy, w, XA_WM_HINTS, 
  103.         0L, (long)NumPropWMHintsElements,
  104.         False, XA_WM_HINTS, &actual_type, &actual_format,
  105.             &nitems, &leftover, (unsigned char **)&hints)
  106.             != Success) DBUG_RETURN(NULL);
  107.  
  108.     /* If the property is undefined on the window, return null pointer. */
  109.     /* pre-R3 bogusly truncated window_group, don't fail on them */
  110.  
  111.         if ((actual_type != XA_WM_HINTS) ||
  112.         (nitems < (NumPropWMHintsElements - 1)) || (actual_format != 32)) {
  113.         if (hints != NULL) Xfree ((char *)hints);
  114.                 DBUG_RETURN(NULL);
  115.         }
  116.         DBUG_RETURN(hints);
  117. }
  118.  
  119. Status
  120. XGetZoomHints (dpy, w, zhints)
  121.     Display *dpy;
  122.     Window w;
  123.     XSizeHints *zhints;
  124. {
  125.     DBUG_ENTER("XGetZoomHints")
  126.     Status result = XGetSizeHints(dpy, w, zhints, XA_WM_ZOOM_HINTS);
  127.     DBUG_RETURN(result);
  128. }
  129.  
  130. Status
  131. XGetNormalHints (dpy, w, hints)
  132.     Display *dpy;
  133.     Window w;
  134.     XSizeHints *hints;
  135. {
  136.     DBUG_ENTER("XGetNormalHints")
  137.     Status result = XGetSizeHints(dpy, w, hints, XA_WM_NORMAL_HINTS);
  138.     DBUG_RETURN(result);
  139. }
  140.  
  141.                 
  142. /*
  143.  * XGetIconSizes reads the property 
  144.  *    ICONSIZE_ATOM    type: ICONSIZE_ATOM format: 32
  145.  */
  146.  
  147. Status XGetIconSizes (dpy, w, size_list, count)
  148.     Display *dpy;
  149.     Window w;    /* typically, root */
  150.     XIconSize **size_list;    /* RETURN */
  151.     int *count;         /* RETURN number of items on the list */
  152. {
  153.     DBUG_ENTER("XGetIconSizes")
  154.     xPropIconSize *prop = NULL;
  155.     register xPropIconSize *pp;
  156.     register XIconSize *hp, *hints;
  157.         Atom actual_type;
  158.         int actual_format;
  159.         unsigned long leftover;
  160.         unsigned long nitems;
  161.     register int i;
  162.  
  163.     if (XGetWindowProperty(dpy, w, XA_WM_ICON_SIZE, 0L, 60L,
  164.         False, XA_WM_ICON_SIZE, &actual_type, &actual_format,
  165.             &nitems, &leftover, (unsigned char **)&prop)
  166.             != Success) DBUG_RETURN(0);
  167.  
  168.     pp = prop;
  169.  
  170.         if ((actual_type != XA_WM_ICON_SIZE) ||
  171.         (nitems < NumPropIconSizeElements) ||
  172.         (nitems % NumPropIconSizeElements != 0) ||
  173.         (actual_format != 32)) {
  174.         if (prop != NULL) Xfree ((char *)prop);
  175.                 DBUG_RETURN(0);
  176.         }
  177.  
  178.     /* static copies not allowed in library, due to reentrancy constraint*/
  179.  
  180.     nitems /= NumPropIconSizeElements;
  181.     if (! (hp = hints = (XIconSize *) 
  182.       Xcalloc ((unsigned) nitems, (unsigned) sizeof(XIconSize)))) {
  183.         if (prop) Xfree ((char *) prop);
  184.         DBUG_RETURN(0);
  185.     }
  186.  
  187.     /* march down array putting things into native form */
  188.     for (i = 0; i < nitems; i++) {
  189.         hp->min_width  = cvtINT32toInt (pp->minWidth);
  190.         hp->min_height = cvtINT32toInt (pp->minHeight);
  191.         hp->max_width  = cvtINT32toInt (pp->maxWidth);
  192.         hp->max_height = cvtINT32toInt (pp->maxHeight);
  193.         hp->width_inc  = cvtINT32toInt (pp->widthInc);
  194.         hp->height_inc = cvtINT32toInt (pp->heightInc);
  195.         hp += 1;
  196.         pp += 1;
  197.     }
  198.     *count = nitems;
  199.     *size_list = hints;
  200.     Xfree ((char *)prop);
  201.     DBUG_RETURN(1);
  202. }
  203.  
  204.  
  205. Status XGetCommand (dpy, w, argvp, argcp)
  206.     Display *dpy;
  207.     Window w;
  208.     char ***argvp;
  209.     int *argcp;
  210. {
  211.     DBUG_ENTER("XGetCommand")
  212.     XTextProperty tp;
  213.     int argc;
  214.     char **argv;
  215.  
  216.     if (!XGetTextProperty (dpy, w, &tp, XA_WM_COMMAND)) DBUG_RETURN(0);
  217.  
  218.     if (tp.encoding != XA_STRING || tp.format != 8) {
  219.     if (tp.value) Xfree ((char *) tp.value);
  220.     DBUG_RETURN(0);
  221.     }
  222.  
  223.  
  224.     /*
  225.      * ignore final <NUL> if present since UNIX WM_COMMAND is nul-terminated
  226.      */
  227.     if (tp.nitems && (tp.value[tp.nitems - 1] == '\0')) tp.nitems--;
  228.  
  229.  
  230.     /*
  231.      * create a string list and return if successful
  232.      */
  233.     if (!XTextPropertyToStringList (&tp, &argv, &argc)) {
  234.     if (tp.value) Xfree ((char *) tp.value);
  235.     DBUG_RETURN(0);
  236.     }
  237.  
  238.     if (tp.value) Xfree ((char *) tp.value);
  239.     *argvp = argv;
  240.     *argcp = argc;
  241.     DBUG_RETURN(1);
  242. }
  243.  
  244.  
  245. Status
  246. XGetTransientForHint(dpy, w, propWindow)
  247.     Display *dpy;
  248.     Window w;
  249.     Window *propWindow;
  250. {
  251.     DBUG_ENTER("XGetTransientForHint")
  252.     Atom actual_type;
  253.     int actual_format;
  254.     unsigned long nitems;
  255.     unsigned long leftover;
  256.     Window *data = NULL;
  257.     if (XGetWindowProperty(dpy, w, XA_WM_TRANSIENT_FOR, 0L, 1L, False,
  258.         XA_WINDOW, 
  259.     &actual_type,
  260.     &actual_format, &nitems, &leftover, (unsigned char **) &data)
  261.     != Success) {
  262.     *propWindow = None;
  263.     DBUG_RETURN(0);
  264.     }
  265.     if ( (actual_type == XA_WINDOW) && (actual_format == 32) &&
  266.      (nitems != 0) ) {
  267.     *propWindow = *data;
  268.     Xfree( (char *) data);
  269.     DBUG_RETURN(1);
  270.     }
  271.     *propWindow = None;
  272.     if (data) Xfree( (char *) data);
  273.     DBUG_RETURN(0);
  274. }
  275.  
  276. Status
  277. XGetClassHint(dpy, w, classhint)
  278.     Display *dpy;
  279.     Window w;
  280.     XClassHint *classhint;    /* RETURN */
  281. {
  282.     DBUG_ENTER("XGetClassHint")
  283.     int len_name, len_class;
  284.  
  285.     Atom actual_type;
  286.     int actual_format;
  287.     unsigned long nitems;
  288.     unsigned long leftover;
  289.     unsigned char *data = NULL;
  290.     if (XGetWindowProperty(dpy, w, XA_WM_CLASS, 0L, (long)BUFSIZ, False,
  291.         XA_STRING, 
  292.     &actual_type,
  293.     &actual_format, &nitems, &leftover, &data) != Success)
  294.            DBUG_RETURN(0);
  295.     
  296.    if ( (actual_type == XA_STRING) && (actual_format == 8) ) {
  297.     len_name = strlen((char *) data);
  298.     if (! (classhint->res_name = Xmalloc((unsigned) (len_name+1)))) {
  299.         Xfree((char *) data);
  300.         DBUG_RETURN(0);
  301.     }
  302.     strcpy(classhint->res_name, (char *) data);
  303.     if (len_name == nitems) len_name--;
  304.     len_class = strlen((char *) (data+len_name+1));
  305.     if (! (classhint->res_class = Xmalloc((unsigned) (len_class+1)))) {
  306.         Xfree(classhint->res_name);
  307.         classhint->res_name = (char *) NULL;
  308.         Xfree((char *) data);
  309.         DBUG_RETURN(0);
  310.     }
  311.     strcpy(classhint->res_class, (char *) (data+len_name+1));
  312.     Xfree( (char *) data);
  313.     DBUG_RETURN(1);
  314.     }
  315.     if (data) Xfree( (char *) data);
  316.     DBUG_RETURN(0);
  317. }
  318.