home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IRESLIB.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  18KB  |  360 lines

  1. #ifndef _IRESLIB_
  2. #define   _IRESLIB_
  3. /*******************************************************************************
  4. * FILE NAME: ireslib.hpp                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IResourceLibrary - Base class for Resources                              *
  9. *     IDynamicLinkLibrary - DLL resources                                      *
  10. *     IResourceId - Wrapper class for resource identifier                      *
  11. *                                                                              *
  12. * COPYRIGHT:                                                                   *
  13. *   Licensed Materials - Property of IBM                                       *
  14. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  15. *   All Rights Reserved                                                        *
  16. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  17. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  18. *                                                                              *
  19. *******************************************************************************/
  20. #if !defined(_IVBASE_)
  21.   #include <ivbase.hpp>
  22. #endif
  23.  
  24. #if !defined(_IHANDLE_)
  25.   #include <ihandle.hpp>
  26. #endif
  27.  
  28. /*----------------------------------------------------------------------------*/
  29. /* Align classes on four byte boundary.                                       */
  30. /*----------------------------------------------------------------------------*/
  31. #pragma pack(4)
  32.  
  33. /*----------------------------------------------------------------------------*/
  34. /* Turn off warning for compiler generated copy/assignment                    */
  35. /*----------------------------------------------------------------------------*/
  36. #pragma info(nocpy)
  37.  
  38. // Forward declarations for other classes:
  39. class IString;
  40. class IResourceLibrary;
  41. class IDynamicLinkLibrary;
  42. class IDLLModule;
  43. class ISize;
  44. class IWindow;
  45.  
  46.  
  47. class IResourceLibrary  : public IVBase
  48. {
  49. typedef IVBase
  50.   Inherited;
  51. /*******************************************************************************
  52. * The IResourceLibrary class provides the functions for loading most types of  *
  53. * OS/2 resources.  This class defaults the location of resources to the        *
  54. * executable file itself.  Resources stored in a dynamic-link library (DLL)    *
  55. * can be loaded using the IDynamicLinkLibrary class.                           *
  56. *                                                                              *
  57. * Generally, this class is seldom used outside of the User Interface Class     *
  58. * Library itself, as these components typically take an IResourceId as input   *
  59. * and do the resource loading themselves.                                      *
  60. *                                                                              *
  61. * Example:                                                                     *
  62. *                                                                              *
  63. * const unsigned MyIcon 15;                                                    *
  64. * IResourceLibrary reslib;                                                     *
  65. * IPointerHandle ptrh = reslib.loadIcon(MyIcon);                               *
  66. *******************************************************************************/
  67. friend class IPointerHandle;
  68. friend class IBitmapHandle;
  69. friend class ISystemPointerHandle;
  70. friend class ISystemBitmapHandle;
  71.  
  72. public:
  73. /*------------------------ Constructor -----------------------------------------
  74. | The only way to construct instances of this class is by using the default    |
  75. | constructor, which does not take any arguments.                              |
  76. ------------------------------------------------------------------------------*/
  77.   IResourceLibrary   ( );
  78. virtual
  79.  ~IResourceLibrary   ( );
  80.  
  81. /*-------------------------------- Accessors -----------------------------------
  82. | These functions provide a means of getting and setting the accessible        |
  83. | attributes of instances of this class:                                       |
  84. |   fileName    - Returns the path qualified name of the current executable    |
  85. |                 file.                                                        |
  86. |   asString    - Provides textual information about the class instance.       |
  87. |   asDebugInfo - Provides debugging information about the class instance.     |
  88. |   isOpen      - Returns the open state of the resource file.  This is        |
  89. |                 always true for an IResourceLibrary.                         |
  90. |   handle      - Returns the handle used to load resources.  This is always   |
  91. |                 0 for an IResourceLibrary.                                   |
  92. ------------------------------------------------------------------------------*/
  93. virtual IString
  94.   fileName           ( ) const,
  95.   asString           ( ) const,
  96.   asDebugInfo        ( ) const;
  97.  
  98. virtual Boolean
  99.   isOpen             ( )   const;
  100.  
  101. virtual IModuleHandle
  102.   handle             ( ) const;
  103.  
  104.  
  105. /*----------------------- Resource Loading -------------------------------------
  106. | These functions load specific resources from an OS/2 resource file:          |
  107. |   loadString     - Loads a string resource from a resource file.             |
  108. |   loadMessage    - Loads a message resource from a resource file.            |
  109. |   loadMenu       - Loads a menu for a window from a resource file.           |
  110. |   loadDialog     - Loads and starts a dialog from a resource file.           |
  111. |   loadAccelTable - Loads an accelerator table from a resource file.          |
  112. |   loadHelpTable  - Loads a help table from a resource file.                  |
  113. |   loadIcon       - Loads an icon from a resource file.  If the cached        |
  114. |                    argument is specified, the icon is reference counted.     |
  115. |   loadPointer    - Loads a pointer from a resource file.  If the cached      |
  116. |                    argument is specified, the pointer is reference counted.  |
  117. |                    This is the same as a call to loadIcon.                   |
  118. |   loadBitmap     - Loads a bit map from a resource file.  If the cached      |
  119. |                    argument is specified, the bit map is reference counted.  |
  120. |                    However, if a size is specified, the bit map is loaded    |
  121. |                    at that size.                                             |
  122. ------------------------------------------------------------------------------*/
  123. IString
  124.   loadString      ( unsigned long stringId  ) const,
  125.   loadMessage     ( unsigned long messageId ) const;
  126.  
  127. IWindowHandle
  128.   loadMenu        ( unsigned long menuId,
  129.                     IWindow*      menuOwner) const,
  130.   loadDialog      ( unsigned long dialogId,
  131.                     IWindow*      dialogParent,
  132.                     IWindow*      dialogOwner,
  133.                     IWinProc*     dialogProcedure,
  134.                     void*         dialogCreateParameters) const;
  135.  
  136. IAccelTblHandle
  137.   loadAccelTable  ( unsigned long accelTableId) const;
  138.  
  139. IResourceLibrary
  140.  &loadHelpTable   ( IWindow*      helpInstance,
  141.                     unsigned long helpTableId) const;
  142.  
  143. IPointerHandle
  144.   loadIcon       ( unsigned long iconId,
  145.                    Boolean       cached = true) const,
  146.   loadPointer    ( unsigned long iconId,
  147.                    Boolean       cached = true) const;
  148.  
  149. IBitmapHandle
  150.   loadBitmap     ( unsigned long bitmapId,
  151.                    Boolean       cached = true) const,
  152.   loadBitmap     ( unsigned long bitmapId,
  153.                    const ISize&  bitmapSize,
  154.                    Boolean       cached = true) const;
  155.  
  156. private:
  157. char
  158.  *loadText       ( Boolean       isString,
  159.                    unsigned long stringID,
  160.                    char*         buffer=0,
  161.                    unsigned long length=0) const;
  162.  
  163. /* Static functions to cache icon & bitmap resources  */
  164. static unsigned long
  165.   addRef          ( const IPointerHandle& pointerHandle),
  166.   addRef          ( const IBitmapHandle&  bitmapHandle),
  167.   removeRef       ( const IPointerHandle& pointerHandle),
  168.   removeRef       ( const IBitmapHandle&  bitmapHandle);
  169. static unsigned long
  170.   systemPointer ( unsigned long systemPointerId,
  171.                       Boolean fCopy = false);
  172. static unsigned long
  173.   systemBitmap  ( unsigned long systemPointerId);
  174. };
  175.  
  176.  
  177. class IDynamicLinkLibrary : public IResourceLibrary
  178. {
  179. typedef IResourceLibrary
  180.   Inherited;
  181. /*******************************************************************************
  182. * The IDynamicLinkLibrary class provides the support for loading OS/2          *
  183. * resources from a dynamic-link library (DLL).                                 *                 *
  184. *                                                                              *
  185. * Example:                                                                     *
  186. *                                                                              *
  187. * const unsigned MyIcon 15;                                                    *
  188. * IDynamicLinkLibrary reslib("icons");                                         *
  189. * IPointerHandle ptrh = reslib.loadIcon(MyIcon);                               *
  190. *******************************************************************************/
  191. public:
  192.  
  193. //friend class IProcAddressHandle;
  194.  
  195. /*------------------------ Constructors/Destructor  ----------------------------
  196. | You can construct an instance of this class in the following ways:           |
  197. |    - By providing a name to use for the dynamic link module.  The name       |
  198. |      should be specified without the path or extension if the LIBPATH is     |
  199. |      to be searched for the DLL.                                             |
  200. |    - From an IModuleHandle obtained by loading the DLL explicitly.           |
  201. |    - By copying an existing IDynamicLinkLibary.                              |
  202. ------------------------------------------------------------------------------*/
  203.   IDynamicLinkLibrary   (const char*                resourceFileName);
  204.   IDynamicLinkLibrary   (const IModuleHandle&       moduleHandle);
  205.   IDynamicLinkLibrary   (const IDynamicLinkLibrary& dllLibrary);
  206.  
  207. virtual
  208.   ~IDynamicLinkLibrary  ( );
  209.  
  210. /*----------------------- Assignment -------------------------------------------
  211. | This operator is used for assignment:                                        |
  212. |   operator =   - Used to assign one DLL to another.                          |
  213. ------------------------------------------------------------------------------*/
  214.  
  215. IDynamicLinkLibrary
  216.  &operator=             ( const IDynamicLinkLibrary& dllLibrary);
  217.  
  218.  
  219. /*----------------------- DLL Open/Close ---------------------------------------
  220. | These functions open and close an OS/2 DLL:                                  |
  221. |   open  - Opens a DLL.                                                       |
  222. |   close - Closes a DLL.                                                      |
  223. ------------------------------------------------------------------------------*/
  224. virtual IDynamicLinkLibrary
  225.  &open                ( ),
  226.  &close               ( );
  227.  
  228. /*----------------------- Procedure Address Loading ----------------------------
  229. | This is used to get a procedure address from a DLL:                          |
  230. |   procAddress       - Loads a procedure address from a DLL.                  |
  231. |   isEntryPoint32Bit - Returns true if the entry point with a given name or   |
  232. |                       ordinal is a 32-bit function.                          |
  233. ------------------------------------------------------------------------------*/
  234. void
  235.  *procAddress        (const char*   procedureName),
  236.  *procAddress        (unsigned long procedureOrdinal);
  237.  
  238. Boolean
  239.   isEntryPoint32Bit  (const char*   procedureName) const,
  240.   isEntryPoint32Bit  (unsigned long procedureOrdinal) const;
  241.  
  242. /*-------------------------------- Overrides -----------------------------------
  243. | This class overrides the following inherited functions:                      |
  244. |   isOpen       - Overridden to return the open state of the DLL.             |
  245. |   fileName     - Overridden to return the name of the DLL.                   |
  246. |   asString     - Overridden to provide textual information about the class   |
  247. |                  instance.                                                   |
  248. |   asDebugInfo  - Overridden to provide debugging information about the class |
  249. |                  instance.                                                   |
  250. |   handle       - Overridden to provide the dynamic link module handle.       |
  251. ------------------------------------------------------------------------------*/
  252. virtual Boolean
  253.   isOpen           ( ) const;
  254.  
  255. virtual IString
  256.   fileName         ( ) const,
  257.   asString         ( ) const,
  258.   asDebugInfo      ( ) const;
  259.  
  260. virtual IModuleHandle
  261.   handle           ( ) const;
  262.  
  263.  
  264. private:
  265.  
  266. // Static functions to reference count DLL's  */
  267. static unsigned long
  268.   addRef          ( const IModuleHandle& moduleHandle),
  269.   removeRef       ( const IModuleHandle& moduleHandle);
  270.  
  271. IDLLModule
  272.  *pmodClResource;
  273. };
  274.  
  275. class IResourceId  : public IBase
  276. {
  277. typedef IBase
  278.   Inherited;
  279. /*******************************************************************************
  280. * The IResourceId class is a wrapper class for a resource identifier.  Part    *
  281. * of the information contained in the class is the location of the resources   *
  282. * that are described using either an IResourceLibrary or an                    *
  283. * IDynamicLinkLibrary.  Most classes in the User Interface Class Library       *
  284. * typically take an IResourceId as input to describe resources and provide     *
  285. * the resource loading themselves.                                             *
  286. *                                                                              *
  287. * Example:                                                                     *
  288. *                                                                              *
  289. * const unsigned MyIcon 15;                                                    *
  290. * IResourceId resid(10);                                                       *
  291. *                                                                              *
  292. * IDynamicLinkLibrary reslib("icons");                                         *
  293. * IResourceId resid(10, reslib);                                               *
  294. *******************************************************************************/
  295. public:
  296.  
  297. /*------------------------ Constructors ----------------------------------------
  298. | You can construct an instance of this class in the following ways:           |
  299. |    - By providing an ID and a reference to an IResourceLibrary.              |
  300. |    - By providing an ID and a reference to an IDynamicLinkLibrary.           |
  301. |    - By providing only an ID.  The resource library used is the one          |
  302. |      returned by a call to ICurrentApplication::userResourceLibrary.  This   |
  303. |      is the recommended use of the class.                                    |
  304. ------------------------------------------------------------------------------*/
  305.   IResourceId      ( unsigned long              resourceId,
  306.                      const IResourceLibrary&    resourceLibrary);
  307.   IResourceId      ( unsigned long              resourceId,
  308.                      const IDynamicLinkLibrary& dllLibrary);
  309.   IResourceId      ( unsigned long              resourceId);
  310.  
  311.  
  312. /*-------------------------------- Accessors -----------------------------------
  313. | These functions provide a means of getting and setting the accessible        |
  314. | attributes of instances of this class:                                       |
  315. |   id                     - Returns the identifier used for the resource.     |
  316. |   operator unsigned long - Returns the identifier used for the resource.     |
  317. |   resourceLibrary        - Returns a const reference to the resource         |
  318. |                            library.                                          |
  319. ------------------------------------------------------------------------------*/
  320. unsigned long
  321.   id                    ( ) const;
  322.  
  323. operator unsigned long  ( ) const;
  324.  
  325. const IResourceLibrary
  326.  &resourceLibrary       ( ) const;
  327.  
  328. /*-------------------------------- Overrides -----------------------------------
  329. | This class overrides the following inherited functions:                      |
  330. |   asString    - Overridden to provide textual information about the class    |
  331. |                 instance.                                                    |
  332. |   asDebugInfo - Overridden to provide debugging information about the class  |
  333. |                 instance.                                                    |
  334. ------------------------------------------------------------------------------*/
  335. virtual IString
  336.   asString         ( ) const,
  337.   asDebugInfo      ( ) const;
  338.  
  339.  
  340. private:
  341. unsigned long
  342.   ulClId;
  343. const IResourceLibrary
  344.  &reslibCl;
  345.  
  346. };
  347.  
  348. /*----------------------------------------------------------------------------*/
  349. /* Resume compiler default packing and warning messages.                      */
  350. /*----------------------------------------------------------------------------*/
  351. #pragma pack()
  352. #pragma info(restore)
  353.  
  354. /*----------------------------- Inline Functions -----------------------------*/
  355. #ifndef I_NO_INLINES
  356.   #include <ireslib.inl>
  357. #endif
  358.  
  359. #endif /* _IRESLIB_ */
  360.