home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ComponentLib / UIComponent.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.5 KB  |  137 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. ///////////////////////////////////////////////////////////////
  22. // UIComponent.C: Base class for all C++/Motif UI components
  23. ///////////////////////////////////////////////////////////////
  24. #include "UIComponent.h"
  25. #include <assert.h>
  26. #include <stdio.h>
  27.  
  28. UIComponent::UIComponent ( const char *name ) : BasicComponent ( name )
  29. {
  30.     // Empty
  31. }
  32.  
  33. void UIComponent::widgetDestroyedCallback ( Widget, 
  34.                        XtPointer clientData, 
  35.                        XtPointer )
  36. {
  37.     UIComponent * obj = (UIComponent *) clientData;    
  38.     
  39.     obj->widgetDestroyed();
  40. }
  41.  
  42. void UIComponent::widgetDestroyed()
  43. {
  44.     _w = NULL;
  45. }
  46.  
  47. void UIComponent::installDestroyHandler()
  48. {
  49.     assert ( _w != NULL );
  50.     XtAddCallback ( _w, 
  51.            XmNdestroyCallback,
  52.            &UIComponent::widgetDestroyedCallback, 
  53.            (XtPointer) this );
  54. }
  55.  
  56. void UIComponent::manage()
  57. {
  58.     assert ( _w != NULL );
  59.     assert ( XtHasCallbacks ( _w, XmNdestroyCallback ) ==
  60.         XtCallbackHasSome );
  61.     XtManageChild ( _w );
  62. }
  63.  
  64. UIComponent::~UIComponent()
  65. {
  66.     // Make sure the widget hasn't already been destroyed
  67.     
  68.     if ( _w ) 
  69.     {
  70.     // Remove destroy callback so Xt can't call the callback
  71.     // with a pointer to an object that has already been freed
  72.     
  73.     XtRemoveCallback ( _w, 
  74.               XmNdestroyCallback,
  75.               &UIComponent::widgetDestroyedCallback,
  76.               (XtPointer) this );    
  77.     }
  78. }
  79.  
  80. void UIComponent::getResources ( const XtResourceList resources, 
  81.                 const int numResources )
  82. {
  83.     // Check for errors
  84.     
  85.     assert ( _w != NULL );
  86.     assert ( resources != NULL );
  87.     
  88.     // Retrieve the requested resources relative to the 
  89.     // parent of this object's base widget
  90.     
  91.     XtGetSubresources ( XtParent( _w ), 
  92.                (XtPointer) this, 
  93.                _name,
  94.                className(),
  95.                resources, 
  96.                numResources,
  97.                NULL, 
  98.                0 );
  99. }
  100.  
  101. void UIComponent::setDefaultResources ( const Widget w, 
  102.                                          const String *resourceSpec )
  103. {
  104.    int         i;    
  105.    Display    *dpy = XtDisplay ( w );      // Retrieve the display pointer
  106.    XrmDatabase rdb = NULL;             // A resource data base
  107.  
  108.    // Create an empty resource database
  109.  
  110.    rdb = XrmGetStringDatabase ( "" );
  111.  
  112.    // Add the Component resources, prepending the name of the component
  113.  
  114.    i = 0;
  115.    while ( resourceSpec[i] != NULL )
  116.    {
  117.        char buf[1000];
  118.  
  119.        sprintf(buf, "*%s%s", _name, resourceSpec[i++]);
  120.        XrmPutLineResource( &rdb, buf );
  121.    }
  122.  
  123.    // Merge them into the Xt database, with lowest precendence
  124.  
  125.    if ( rdb )
  126.    {
  127. #if (XlibSpecificationRelease>=5)
  128.         XrmDatabase db = XtDatabase(dpy);
  129.     XrmCombineDatabase(rdb, &db, FALSE);
  130. #else
  131.         XrmMergeDatabases ( dpy->db, &rdb );
  132.         dpy->db = rdb;
  133. #endif
  134.     }
  135. }
  136.  
  137.