home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / ibmcli / ireslib.hp_ / IRESLIB.HPP
Encoding:
C/C++ Source or Header  |  1992-10-26  |  16.1 KB  |  367 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. *$Log:   R:/IBMCLASS/IBASEAPP/VCS/IRESLIB.HPV  $                                                                         *
  20. // 
  21. //    Rev 1.8   25 Oct 1992 16:57:30   nunn
  22. // changed library name to ICLUI
  23. // 
  24. //    Rev 1.7   24 Oct 1992 14:47:40   BOBLOVE
  25. // Updated documentation
  26.    
  27. *******************************************************************************/
  28. #if !defined(_IVBASE_)
  29.   #include <ivbase.hpp>
  30. #endif
  31.  
  32. #if !defined(_IHANDLE_)
  33.   #include <ihandle.hpp>
  34. #endif
  35.  
  36. // Forward declarations for other classes:
  37. class IString;
  38. class IResourceLibrary;
  39. class IDynamicLinkLibrary;
  40. class IDLLModule;
  41. class ISize;
  42. class IWindow;
  43. class IProcAddressHandle;
  44.  
  45.  
  46. class IResourceLibrary  : public IVBase
  47. /*******************************************************************************
  48. * IResourceLibrary provide the functions for loading most types of OS/2        *
  49. * resources.  This class defaults the location of resources to the             *
  50. * EXE itself. Resources stored in a DLL can be loaded using the class          *
  51. * IDynamicLinkLibrary.                                                         *
  52. *                                                                              *
  53. * For the most part, this class is used very little outside of the             *
  54. * User Interface library itself as these components typically take             *
  55. * an IResourceId as input and do the resource loading themselves.              *
  56. *                                                                              *
  57. *                                                                              *
  58. * EXAMPLE:                                                                     *
  59. *                                                                              *
  60. * const unsigned MyIcon 15;                                                    *
  61. * IResourceLibrary reslib;                                                     *
  62. * IPointerHandle ptrh = reslib.loadIcon(MyIcon);                               *
  63. *                                                                              *
  64. *******************************************************************************/
  65. {
  66.   friend class IPointerHandle;
  67.   friend class IBitmapHandle;
  68.   friend class ISysPointerHandle;
  69.   friend class ISysBitmapHandle;
  70.  
  71. public:
  72. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  73. | There is one way to construct instances of this class:                       |
  74. |   1. The default which takes no parameters.                                  |
  75. ------------------------------------------------------------------------------*/
  76.   IResourceLibrary();
  77. virtual 
  78.   ~IResourceLibrary() {}
  79.  
  80. /*-------------------------------- ACCESSORS -----------------------------------
  81. | These function provide means of getting and setting the accessible           |
  82. | attributes of instances of this class:                                       |
  83. |   fileName - Returns the path qualified name of the current executable file. |
  84. |   asString - Provides textual information about the class instance.          |
  85. |   asDebugInfo - Provides debugging information about the class instance.     |
  86. |   isOpen - Returns the open state of the resource file. This is always true  |
  87. |            for an IResourceLibrary.                                          |
  88. |   handle - Returns the handle used to load resources. This is always zero    |
  89. |            for an IResourceLibrary.                                          |
  90. ------------------------------------------------------------------------------*/
  91. virtual IString 
  92.   fileName() const,
  93.   asString() const,
  94.   asDebugInfo() const;
  95.  
  96. virtual Boolean 
  97.   isOpen()   const;   
  98.  
  99. virtual IModuleHandle 
  100.   handle() const;
  101.  
  102.  
  103. /*----------------------- RESOURCE LOADING FUNCTIONS ---------------------------
  104. | These functions load specific resources from an OS/2 resource file:          |
  105. |   loadString     - Load a string resource from a resource file.              |
  106. |   loadMessage    - Load a message resource from a resource file.             |
  107. |   loadMenu       - Load a menu for a window from a resource file.            |
  108. |   loadDialog     - Load and start a Dialog from a resource file.             |
  109. |   loadAccelTable - Load an accelerator table from a resource file.           |
  110. |   loadHelpTable  - Load a help table from a resource file.                   |
  111. |   loadHelpTable  - Load a help table from a resource file.                   |
  112. |   loadIcon       - Load an icon from a resource file.  If managed is         |
  113. |                    specified then the icon is reference counted.             |
  114. |   loadBitmap     - Load a bitmap from a resource file.  If managed is        |
  115. |                    specified then the bitmap is reference counted.  If       |
  116. |                    a size is specified then the bitmap is loaded at that     |
  117. |                    size.                                                     |
  118. ------------------------------------------------------------------------------*/
  119. IString 
  120.   loadString(unsigned long stringId) const,
  121.   loadMessage(unsigned long messageId) const;
  122.  
  123. IWindowHandle  
  124.   loadMenu(unsigned long menuId, 
  125.            const IWindow* menuOwner) const,
  126.   loadDialog(unsigned long dialogId, 
  127.              const IWindow* dialogParent,
  128.              const IWindow* dialogOwner, 
  129.              IWINCALLBACK* pDialogProc,
  130.              void* pDialogCreateParams) const;
  131.  
  132. IAccelTblHandle 
  133.   loadAccelTable(unsigned long accelTableId) const;
  134.  
  135. void 
  136.   loadHelpTable(const IWindow* helpInstance, 
  137.                 unsigned long helpTableId) const;
  138.  
  139. /* Note: Cached Icons and Bitmaps use reference counting to reduce loading */
  140. IPointerHandle
  141.   loadIcon(unsigned long iconId, 
  142.            Boolean cached=true) const,
  143.   loadPointer(unsigned long iconId, 
  144.            Boolean cached=true) const;
  145.  
  146. IBitmapHandle 
  147.   loadBitmap(unsigned long bitmapId, 
  148.              Boolean cached=true) const,
  149.   loadBitmap(unsigned long bitmapId, 
  150.              const ISize& bitmapSize,
  151.              Boolean cached=true) const;
  152.  
  153. private:
  154. char
  155.  *loadText(Boolean isString,
  156.            unsigned long StringID, 
  157.            char* Buffer=0,
  158.            unsigned long Length=0) const;
  159.  
  160. /* Static functions to cache icon & bitmap resources  */
  161. static unsigned long 
  162.   addRef(const IPointerHandle& ptrh),
  163.   addRef(const IBitmapHandle& bmph),
  164.   removeRef(const IPointerHandle& ptrh),
  165.   removeRef(const IBitmapHandle& bmph);
  166.  
  167.  
  168.  
  169. };
  170.  
  171.  
  172. class IDynamicLinkLibrary : public IResourceLibrary
  173. /*******************************************************************************
  174. * IDynamicLinkLibrary provides the support for loading OS/2 resources from a   *
  175. * Dynamic Link Library.                                                        *
  176. *                                                                              *
  177. *                                                                              *
  178. * EXAMPLE:                                                                     *
  179. *                                                                              *
  180. * const unsigned MyIcon 15;                                                    *
  181. * IDynamicLinkLibrary reslib("icons");                                         *
  182. * IPointerHandle ptrh = reslib.loadIcon(MyIcon);                               *
  183. *                                                                              *
  184. *******************************************************************************/
  185. {
  186. public:
  187.  
  188. friend class IProcAddressHandle;
  189.  
  190. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  191. | There are three ways to construct instances of this class:                   |
  192. |   1. By providing a name to use for the Dynamic Link Module. The name should |
  193. |      be specified without the path or extension.                             |
  194. |   2. From an IModuleHandle obtained by loading the DLL explicitly.           |
  195. |   3. By copying an existing IDynamicLinkLibary.                              |
  196. ------------------------------------------------------------------------------*/
  197. IDynamicLinkLibrary(const char* resourceFileName);
  198. IDynamicLinkLibrary(const IModuleHandle& modh);
  199. IDynamicLinkLibrary(const IDynamicLinkLibrary& resmgr);
  200.  
  201. virtual 
  202.   ~IDynamicLinkLibrary();
  203.  
  204. IDynamicLinkLibrary
  205.  &operator=(const IDynamicLinkLibrary& resmgr);
  206.  
  207.  
  208. /*----------------------- DLL OPEN/CLOSE FUNCTIONS -----------------------------
  209. | These functions open and close an OS/2 Dynamic Link Library.                 |
  210. |   open  - Open a Dynamic Link Library.                                       |
  211. |   close - Close a Dynamic Link Library.                                      |
  212. ------------------------------------------------------------------------------*/
  213. virtual void 
  214.   open(),
  215.   close();
  216.  
  217. /*----------------------- PROCEDURE ADDRESS FUNCTIONS --------------------------
  218. | These functions open and close an OS/2 Dynamic Link Library.                 |
  219. |   procAddress - Load a procedure address from a Dynamic Link Library.        |
  220. ------------------------------------------------------------------------------*/
  221. IProcAddressHandle 
  222.   procAddress(const char* procedureName),
  223.   procAddress(unsigned long procedureOrdinal);
  224.  
  225. /*-------------------------------- OVERRIDES -----------------------------------
  226. | This class overrides the following inherited functions:                      |
  227. |   isOpen       - Overridden to return the open state of the Dynamic Link     |
  228. |                  Library.                                                    |
  229. |   fileName     - Overridden to return the name of Dynamic Link Library.      |
  230. |   asString     - Overridden to provide textual information about the class   |
  231. |                  instance.                                                   |
  232. |   asDebugInfo  - Overridden to provide debugging information about the class |
  233. |                  instance.                                                   |
  234. |   handle       - Overridden to provide the Dynamic Link Module handle.       |
  235. ------------------------------------------------------------------------------*/
  236. virtual Boolean 
  237.   isOpen() const;
  238.  
  239. virtual IString 
  240.   fileName() const,
  241.   asString() const,
  242.   asDebugInfo() const;
  243.  
  244.   /* Note: Call to handle() before open() causes exception */
  245. virtual IModuleHandle 
  246.   handle() const;
  247.  
  248. private:
  249. IDynamicLinkLibrary();
  250.  
  251. // Static functions to reference count DLL's  */
  252. static unsigned long 
  253.   addRef(const IModuleHandle& modh),
  254.   removeRef(const IModuleHandle& modh);
  255.  
  256. IDLLModule
  257.  *pmodClResource;    
  258. };
  259.  
  260.  
  261.  
  262. class IResourceId  : public IBase /* resid */
  263. /*******************************************************************************
  264. * IResourceId is a "wrapper" class for a resource identifier. Part of the      *
  265. * information contained in the class is the location of the resources which    *
  266. * is described using either an IResourceLibrary or an IDynamicLinkLibrary.     *
  267. * Most classes in the User Interface Library typically take an IResourceId     *
  268. * as input to describe resources and provide the resource loading themselves.  *
  269. *                                                                              *
  270. * EXAMPLE:                                                                     *
  271. *                                                                              *
  272. * const unsigned MyIcon 15;                                                    *
  273. * IResourceId resid(10);                                                       *
  274. *                                                                              *
  275. * IDynamicLinkLibrary reslib("icons");                                         *
  276. * IResourceId resid(10, reslib);                                               *
  277. *                                                                              *
  278. *                                                                              *
  279. *******************************************************************************/
  280. {
  281. public:
  282.  
  283. /*------------------------ CONSTRUCTORS/DESTRUCTORS ----------------------------
  284. | There are three ways to construct instances of this class:                   |
  285. |   1. By providing an id and a reference to an IResourceLibrary.              |
  286. |   2. By providing an id and a reference to an IDynamicLinkLibrary.           |
  287. |   3. By providing only an id.  The resource library used is that returned    |
  288. |      by a call to IApplication::resource(). This is the recommended use of   |
  289. |      the class.                                                              |
  290. ------------------------------------------------------------------------------*/
  291. IResourceId(unsigned long Resid, const IResourceLibrary&);
  292. IResourceId(unsigned long Resid, const IDynamicLinkLibrary&);
  293.  
  294.      /* The following ResourceId defaults to IApplication::resource() */
  295. IResourceId(unsigned long resourceId);
  296.  
  297. const IResourceLibrary
  298.  &resourceLibrary() const;
  299.  
  300. unsigned long 
  301.   id() const;
  302.  
  303. operator unsigned long( ) const;
  304.  
  305. virtual IString 
  306.   asString() const,
  307.   asDebugInfo() const;
  308.  
  309.  
  310. private:
  311. unsigned long 
  312.   ulClId;
  313. const IResourceLibrary
  314.  &reslibCl;
  315.  
  316. };
  317.  
  318.  
  319.  
  320.  
  321. /***************************************************************/
  322. /* Inline Functions.                                           */
  323. /***************************************************************/
  324.  
  325.  
  326. inline IPointerHandle IResourceLibrary::loadPointer(unsigned long iconId, Boolean managed) const
  327. /***************************************************************/
  328. /* Load a Pointer.                                             */
  329. /***************************************************************/
  330. { return loadIcon(iconId, managed); }
  331.  
  332.  
  333. inline Boolean IResourceLibrary::isOpen() const
  334. /***************************************************************/
  335. /* Return the fact the the library is always open.             */
  336. /***************************************************************/
  337. {
  338.   return true;
  339. }
  340.  
  341.  
  342.  
  343. inline const IResourceLibrary& IResourceId::resourceLibrary() const
  344. /***************************************************************/
  345. /* Return the Resource Manager associated with the id.         */
  346. /***************************************************************/
  347. { return reslibCl; }
  348.  
  349. inline IResourceId::operator unsigned long( )   const
  350. /***************************************************************/
  351. /* Return the Resource Id as an unsigned long integer.         */
  352. /***************************************************************/
  353. { return this->ulClId; }
  354.  
  355.  
  356. inline unsigned long IResourceId::id( )   const
  357. /***************************************************************/
  358. /* Return the Resource Id as an unsigned long integer.         */
  359. /***************************************************************/
  360. { return this->ulClId; }
  361.  
  362.  
  363.  
  364.  
  365.  
  366. #endif
  367.