home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / Resources.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.6 KB  |  207 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/Resources.c>                                        */
  21. /* Description:    Xfe widgets resources utilities.                        */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeP.h>
  28.  
  29. #define XmNisEnabled "isEnabled"
  30. #define XmCIsEnabled "IsEnabled"
  31.  
  32. /*----------------------------------------------------------------------*/
  33. /*                                                                        */
  34. /* Private functions                                                    */
  35. /*                                                                        */
  36. /*----------------------------------------------------------------------*/
  37. static XtPointer
  38. SubResourceGetValue            (Widget        parent,
  39.                              String        widget_name,
  40.                              String        widget_class,
  41.                              String        resource_name,
  42.                              String        resource_class,
  43.                              String        resource_type,
  44.                              Cardinal    resource_size,
  45.                              XtPointer    default_addr);
  46. /*----------------------------------------------------------------------*/
  47.  
  48. /*----------------------------------------------------------------------*/
  49. /*                                                                        */
  50. /* Public functions                                                        */
  51. /*                                                                        */
  52. /*----------------------------------------------------------------------*/
  53. /* extern */ Boolean
  54. XfeSubResourceGetBooleanValue(Widget    parent,
  55.                               String    widget_name,
  56.                               String    widget_class,
  57.                               String    resource_name,
  58.                               String    resource_class,
  59.                               Boolean    default_value)
  60. {
  61.     XtPointer value;
  62.     XtPointer default_ptr = default_value ? (XtPointer)True : (XtPointer)False;
  63.  
  64.     value = SubResourceGetValue(parent,
  65.                                 widget_name,
  66.                                 widget_class,
  67.                                 resource_name,
  68.                                 resource_class,
  69.                                 XmRBoolean,
  70.                                 sizeof(Boolean),
  71.                                 default_ptr);
  72.  
  73.     return (value != NULL) ? True : False;
  74. }
  75. /*----------------------------------------------------------------------*/
  76. /* extern */ XmString
  77. XfeSubResourceGetXmStringValue(Widget    parent,
  78.                                String    widget_name,
  79.                                String    widget_class,
  80.                                String    resource_name,
  81.                                String    resource_class,
  82.                                XmString    default_value)
  83. {
  84.     return (XmString) SubResourceGetValue(parent,
  85.                                           widget_name,
  86.                                           widget_class,
  87.                                           resource_name,
  88.                                           resource_class,
  89.                                           XmRXmString,
  90.                                           sizeof(XmString),
  91.                                           (XtPointer) default_value);
  92. }
  93. /*----------------------------------------------------------------------*/
  94. /* extern */ String
  95. XfeSubResourceGetStringValue(Widget        parent,
  96.                              String        widget_name,
  97.                              String        widget_class,
  98.                              String        resource_name,
  99.                              String        resource_class,
  100.                              String        default_value)
  101. {
  102.     return (String) SubResourceGetValue(parent,
  103.                                         widget_name,
  104.                                         widget_class,
  105.                                         resource_name,
  106.                                         resource_class,
  107.                                         XmRString,
  108.                                         sizeof(String),
  109.                                         (XtPointer) default_value);
  110. }
  111. /*----------------------------------------------------------------------*/
  112. /* extern */ Pixel
  113. XfeSubResourceGetPixelValue(Widget        parent,
  114.                             String        widget_name,
  115.                             String        widget_class,
  116.                             String        resource_name,
  117.                             String        resource_class,
  118.                             Pixel        default_value)
  119. {
  120.     /* Pixel default_pixel = WhitePixelOfScreen(_XfeScreen(parent)); */
  121.  
  122.     return (Pixel) SubResourceGetValue(parent,
  123.                                        widget_name,
  124.                                        widget_class,
  125.                                        resource_name,
  126.                                        resource_class,
  127.                                        XmRPixel,
  128.                                        sizeof(Pixel),
  129.                                        (XtPointer) default_value);
  130. }
  131. /*----------------------------------------------------------------------*/
  132. /* extern */ String
  133. XfeSubResourceGetWidgetStringValue(Widget        w,
  134.                                    String        resource_name,
  135.                                    String        resource_class)
  136. {
  137.     return XfeSubResourceGetStringValue(_XfeParent(w),
  138.                                         XtName(w),
  139.                                         XfeClassNameForWidget(w),
  140.                                         resource_name,
  141.                                         resource_class,
  142.                                         NULL);
  143. }
  144. /*----------------------------------------------------------------------*/
  145.  
  146.  
  147. /*----------------------------------------------------------------------*/
  148. /*                                                                        */
  149. /* Check whether a child is enabled.                                    */
  150. /*                                                                        */
  151. /*----------------------------------------------------------------------*/
  152. /* extern */ Boolean
  153. XfeChildIsEnabled(Widget    parent,
  154.                   String    child_name,
  155.                   String    child_class,
  156.                   Boolean    default_value)
  157. {
  158.     return XfeSubResourceGetBooleanValue(parent,
  159.                                          child_name,
  160.                                          child_class,
  161.                                          XmNisEnabled,
  162.                                          XmCIsEnabled,
  163.                                          default_value);
  164. }
  165. /*----------------------------------------------------------------------*/
  166.  
  167.  
  168. /*----------------------------------------------------------------------*/
  169. /*                                                                        */
  170. /* Private functions                                                    */
  171. /*                                                                        */
  172. /*----------------------------------------------------------------------*/
  173. static XtPointer
  174. SubResourceGetValue(Widget        parent,
  175.                     String        widget_name,
  176.                     String        widget_class,
  177.                     String        resource_name,
  178.                     String        resource_class,
  179.                     String        resource_type,
  180.                     Cardinal    resource_size,
  181.                     XtPointer    default_addr)
  182. {
  183.     static XtResource    _resource;
  184.  
  185.     XtPointer            value = NULL;
  186.  
  187.     _resource.resource_name        = resource_name;
  188.     _resource.resource_class    = resource_class;
  189.     _resource.resource_type        = resource_type;
  190.     _resource.resource_size        = resource_size;
  191.     _resource.resource_offset    = 0;
  192.     _resource.default_type        = XtRImmediate;
  193.     _resource.default_addr        = default_addr;
  194.  
  195.     XtGetSubresources(parent,                /* w                */
  196.                       &value,                /* base                */
  197.                       widget_name,            /* name                */
  198.                       widget_class,            /* class            */
  199.                       &_resource,            /* resources        */
  200.                       1,                    /* num_resources    */
  201.                       NULL,                    /* args                */
  202.                       0);                    /* num_args            */
  203.  
  204.     return value;
  205. }
  206. /*----------------------------------------------------------------------*/
  207.