home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / palette / part02 / desktop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-18  |  3.2 KB  |  105 lines

  1. /* 
  2.  * desktop.c - This module contains the routines to access other windows 
  3.  *             on the screen.
  4.  *             
  5.  *             Exported routines:
  6.  *               WalkWinTree
  7.  *               Get_Root
  8.  */
  9.  
  10. /**************************************************************************
  11.  *      palette - a colormap editor
  12.  *      Copyright (c) 1988 Wayne Mesard                                   *
  13.  *                                                                        *
  14.  *      This is free software.  It may be reproduced, retransmitted,      *
  15.  *      redistributed and otherwise propogated at will, provided that     *
  16.  *      no monetary profit is realized and that this notice remains       *
  17.  *      intact and in place.                                              *
  18.  *                                                                        *
  19.  *      Please direct bug reports, code enhancements and comments         *
  20.  *      to mesard@BBN.COM.                                                *
  21.  *                                                                        *
  22.  **************************************************************************/
  23.  
  24. #include <suntool/sunview.h>
  25. #include <suntool/panel.h>
  26. #include <sunwindow/win_enum.h>
  27. #include <stdio.h>
  28. #include <fcntl.h>
  29.  
  30. #include "wsm_types.h"
  31.  
  32. /* 
  33.  * WalkWinTree - Given a root fd, call the function Get_CMS_Data() on 
  34.  *               every window on the screen, or if kids_onlyP, only call 
  35.  *               it on the children of the root (i.e., top level frames).
  36.  */
  37.  
  38. boolean WalkWinTree(root_fd, kids_onlyP)
  39. int root_fd;
  40. boolean kids_onlyP;
  41. {
  42.     enum win_enumerator_result Get_CMS_Data();
  43.     enum win_enumerator_result result;
  44.  
  45.     if (kids_onlyP) {
  46.     (void) Get_CMS_Data(root_fd);
  47.     result = win_enumerate_children(root_fd, Get_CMS_Data, NULL);
  48.     }
  49.     else
  50.     result = win_enumerate_subtree(root_fd, Get_CMS_Data, NULL);
  51.     return ((result == Enum_Fail) ? false : true);
  52. }
  53.  
  54.  
  55.  
  56. /* 
  57.  * Get_Root - Given a window, return an open fd of its root window.
  58.  */
  59.  
  60. int Get_Root(win)
  61. Window win;
  62. {
  63.     struct screen rootscreen;
  64.  
  65.     win_screenget((int) window_get(win, WIN_FD), &rootscreen);
  66.     return(open(rootscreen.scr_rootname, O_RDONLY));
  67. }
  68.  
  69.  
  70.  
  71. /* 
  72.  * Get_CMS_Data - Given a window fd, get its color map, and if this map 
  73.  *                isn't in the table yet (because it's not being shared with
  74.  *                another window), call MakeCMS() to have it inserted.
  75.  */
  76.  
  77. static enum win_enumerator_result Get_CMS_Data(fd)
  78. int fd;
  79. {
  80.     extern char *malloc();
  81.     boolean MakeCMS();
  82.     struct colormapseg cmsdata;
  83.     struct cms_map themap;
  84.     int planes;
  85.     Pixwin *pw;
  86.     enum win_enumerator_result result = Enum_Normal;
  87.  
  88.     pw = (Pixwin *) pw_open(fd);
  89.     pw_getattributes(pw, &planes);
  90.     pw_getcmsdata(pw, &cmsdata, &planes);
  91.     if (H_Member(cmsdata.cms_name, NIL(struct cms_map),
  92.          NIL(Panel_item *)) == 0) {
  93.     themap.cm_red = (unsigned char *) malloc((unsigned)cmsdata.cms_size);
  94.     themap.cm_green = (unsigned char *) malloc((unsigned)cmsdata.cms_size);
  95.     themap.cm_blue = (unsigned char *) malloc((unsigned)cmsdata.cms_size);
  96.     pw_getcolormap(pw, 0, cmsdata.cms_size,
  97.                themap.cm_red, themap.cm_green, themap.cm_blue);
  98.     if (!MakeCMS(&cmsdata, &themap))
  99.         result = Enum_Fail;
  100.     }
  101.     pw_close(pw);
  102.     return(result);
  103. }
  104.  
  105.