home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / GcUtil.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.6 KB  |  168 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <Xfe/GcUtil.c>                                            */
  21. /* Description:    Xfe widgets graphic context utilities.                    */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeP.h>
  28.  
  29. /*----------------------------------------------------------------------*/
  30. /*                                                                        */
  31. /* GC functions                                                            */
  32. /*                                                                        */
  33. /*----------------------------------------------------------------------*/
  34. GC
  35. XfeAllocateStringGc(Widget        w,
  36.                     XmFontList    font_list,
  37.                     Pixel        fg,
  38.                     Pixel        bg,
  39.                     Boolean         sensitive)
  40. /*----------------------------------------------------------------------*/
  41. {
  42.     XGCValues        values;
  43.     XFontStruct *    fs = (XFontStruct *) NULL;
  44.     XtGCMask        value_mask;
  45.  
  46.     value_mask = GCGraphicsExposures | GCForeground;
  47.    
  48.     values.graphics_exposures    = False;
  49.     values.foreground            = fg;
  50.  
  51.     /* Add insensitive tile if needed */
  52.     if (!sensitive)
  53.     {
  54.         value_mask |= (GCFillStyle | GCTile);
  55.       
  56.         values.fill_style    = FillTiled;
  57.  
  58.         values.tile = XfeInsensitiveTile(_XfeScreen(w),_XfeDepth(w),fg,bg);
  59.     }
  60.  
  61.     /* Obtain the XFontStruct */
  62.     _XmFontListGetDefaultFont(font_list,&fs);
  63.  
  64.     /* Add font if it is good */
  65.     if (fs != NULL)
  66.     {
  67.         value_mask |= GCFont;
  68.         values.font = fs->fid;
  69.     }
  70.  
  71.     /* Allocate the string GC */
  72.     return XtAllocateGC(w,_XfeDepth(w),value_mask,&values,0,0);
  73. }
  74. /*----------------------------------------------------------------------*/
  75. GC
  76. XfeAllocateColorGc(Widget w,Pixel fg,Pixel bg,Boolean sensitive)
  77. {
  78.     XGCValues    values;
  79.     XtGCMask    value_mask;
  80.     
  81.     value_mask = GCGraphicsExposures | GCForeground;
  82.     
  83.     values.graphics_exposures    = False;
  84.     values.foreground            = fg;
  85.     
  86.     /* Add insensitive tile if needed */
  87.     if (!sensitive)
  88.     {
  89.         value_mask |= (GCFillStyle | GCTile);
  90.         
  91.         values.fill_style    = FillTiled;
  92.         
  93.         values.tile = XfeInsensitiveTile(_XfeScreen(w),_XfeDepth(w),fg,bg);
  94.     }
  95.     
  96.     return XtGetGC(w,value_mask,&values);
  97. }
  98. /*----------------------------------------------------------------------*/
  99. GC
  100. XfeAllocateTileGc(Widget w,Pixmap tile_pixmap)
  101. {
  102.     XGCValues    values;
  103.     XtGCMask    value_mask;
  104.     
  105.     value_mask = GCGraphicsExposures;
  106.     
  107.     values.graphics_exposures    = False;
  108.  
  109.     /* Use the tile pixmap only if it is good */
  110.     if (_XfePixmapGood(tile_pixmap))
  111.     {
  112.         value_mask |= GCFillStyle | GCTile;
  113.  
  114.         values.fill_style     = FillTiled;
  115.         values.tile            = tile_pixmap;
  116.     }
  117.  
  118.     return XtGetGC(w,value_mask,&values);
  119. }
  120. /*----------------------------------------------------------------------*/
  121. GC
  122. XfeAllocateTransparentGc(Widget w)
  123. {
  124.     XGCValues    values;
  125.     XtGCMask    value_mask = GCGraphicsExposures;
  126.     XtGCMask    dynamic_mask = GCClipMask | GCClipXOrigin | GCClipYOrigin;
  127.  
  128.     values.graphics_exposures = False;
  129.  
  130.     return XtAllocateGC(w,_XfeDepth(w),value_mask,&values,dynamic_mask,0);
  131. }
  132. /*----------------------------------------------------------------------*/
  133. GC
  134. XfeAllocateSelectionGc(Widget        w,
  135.                        Dimension    thickness,
  136.                        Pixel        fg,
  137.                        Pixel        bg)
  138. {
  139.     XGCValues    values;
  140.     XtGCMask    value_mask;
  141.  
  142.     value_mask = 
  143.         GCGraphicsExposures | GCForeground | GCLineWidth | 
  144.         GCFunction | GCSubwindowMode;
  145.  
  146.     values.graphics_exposures    = False;
  147.     values.line_width            = thickness;
  148.     values.function                = GXxor;
  149.     values.subwindow_mode        = IncludeInferiors;
  150.     values.foreground            = fg ^ bg;
  151.  
  152.     return XtGetGC(w,value_mask,&values);
  153. }
  154. /*----------------------------------------------------------------------*/
  155. GC
  156. XfeAllocateCopyGc(Widget w)
  157. {
  158.     XGCValues    values;
  159.     XtGCMask    value_mask;
  160.  
  161.     value_mask = GCGraphicsExposures;
  162.  
  163.     values.graphics_exposures    = False;
  164.  
  165.     return XtGetGC(w,value_mask,&values);
  166. }
  167. /*----------------------------------------------------------------------*/
  168.