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

  1. #ifndef _IVPORT_
  2.   #define _IVPORT_
  3. /*******************************************************************************
  4. * FILE NAME: ivport.hpp                                                        *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IViewPort - This class creates a view port window that allows scrolling  *
  9. *                 of a client control or window.                               *
  10. *                                                                              *
  11. * COPYRIGHT:                                                                   *
  12. *   Licensed Materials - Property of IBM                                       *
  13. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  14. *   All Rights Reserved                                                        *
  15. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. * CHANGE HISTORY:                                                              *
  19. *******************************************************************************/
  20. #ifndef _ICANVAS_
  21.   #include <icanvas.hpp>
  22. #endif
  23.  
  24. #ifndef _IPOINT_
  25.   #include <ipoint.hpp>
  26. #endif
  27. #ifndef _IRECT_
  28.   #include <irect.hpp>
  29. #endif
  30.  
  31. /*----------------------------------------------------------------------------*/
  32. /* Align classes on four byte boundary.                                       */
  33. /*----------------------------------------------------------------------------*/
  34. #pragma pack(4)
  35.  
  36. // Forward declarations for other classes:
  37. class IColor;
  38. class IScrollBar;
  39. class IViewRectangle;
  40.  
  41.  
  42. class IViewPort : public ICanvas {
  43. typedef ICanvas
  44.   Inherited;
  45. /*******************************************************************************
  46. * The IViewPort class is used to provide scrolling support for a client        *
  47. * window known as the view window.  Typically, the view window does not        *
  48. * readily support resizing.  Because of this, it needs to be scrolled so that  *
  49. * clipped information is not lost to the user.  Candidate view windows         *
  50. * include the following classes:                                               *
  51. *   - ICanvas                                                                  *
  52. *   - ISetCanvas                                                               *
  53. *   - INotebook                                                                *
  54. *   - IContainer                                                               *
  55. *                                                                              *
  56. * The view window is specified by making it a child window of the view port.   *
  57. * The view port is the parent window of the view window.  A view port          *
  58. * supports only one view window.                                               *
  59. *                                                                              *
  60. * The IViewPort optionally includes horizontal and vertical scroll bars.  The  *
  61. * scroll bars can be specified to always be visible, to never be visible, or   *
  62. * to only be shown if the size of the view window is larger than the size of   *
  63. * the view port window.  If the view port has nothing to scroll because the    *
  64. * view window is entirely visible, the scroll bars are hidden.                 *
  65. *                                                                              *
  66. * Example:                                                                     *
  67. *   myViewPort = new IViewPort(ID_VIEWPORT, myFrame, myFrame);                 *
  68. *   myFrame->setClient(myViewPort);   // make it the client area               *
  69. *   myViewWindow = new MyViewWindow(ID_VIEWWINDOW, myViewPort, myViewPort);    *
  70. *            // make it the view window by making it a child of the view port  *
  71. *******************************************************************************/
  72. public:
  73. class Style;                  // forward declaration for nested class
  74.  
  75. /*-------------------------- Constructor/Destructor ----------------------------
  76. | You can construct instances of this class by specifying a window ID, parent  |
  77. | and owner windows, an optional position and size, and an optional style.     |
  78. |                                                                              |
  79. | The IViewPort class reserves the use of the following window IDs for child   |
  80. | windows that it creates:                                                     |
  81. |   0x8000 - Vertical scroll bar.                                              |
  82. |   0x8001 - Horizontal scroll bar.                                            |
  83. |   0x8002 - Scroll rectangle (the window within which the application window  |
  84. |            is scrolled).                                                     |
  85. ------------------------------------------------------------------------------*/
  86.   IViewPort  ( unsigned long windowId,
  87.                IWindow* parent,
  88.                IWindow* owner,
  89.                const IRectangle& initial = IRectangle(),
  90.                const Style& style = defaultStyle() );
  91.  
  92. virtual
  93.   ~IViewPort ( );
  94.  
  95. /*--------------------------------- Style --------------------------------------
  96. | The IViewPort::Style nested class provides static members that define the    |
  97. | set of valid styles for IViewPort objects.  These styles can also be used    |
  98. | in conjunction with the styles defined by the nested classes                 |
  99. | ICanvas::Style and IWindow::Style.  For example, you could define an         |
  100. | instance of the IViewPort::Style class and initialize it like:               |
  101. |             IViewPort::Style style = IViewPort::classDefaultStyle |          |
  102. |                                      IWindow::saveBits;                      |
  103. | An object of this type is provided when the IViewPort object is created.     |
  104. | A customizable default is used if no styles are specified.  Once the         |
  105. | object is constructed, IViewPort, ICanvas, and IWindow member functions      |
  106. | can be used to set or query the object's style.                              |
  107. |                                                                              |
  108. | The declaration of the IViewPort::Style nested class is generated by the     |
  109. | INESTEDBITFLAGCLASSDEF2 macro.                                               |
  110. |                                                                              |
  111. | The valid IViewPort object styles are:                                       |
  112. |   alwaysHorizontalScrollBar   - This style specifies to never remove the     |
  113. |                                 horizontal scroll bar.                       |
  114. |   asNeededHorizontalScrollBar - This style specifies the removal of the      |
  115. |                                 horizontal scroll bar when the entire width  |
  116. |                                 of the view window is visible and there is   |
  117. |                                 no data to scroll horizontally.              |
  118. |   noHorizontalScrollBar       - This style specifies to never show the       |
  119. |                                 horizontal scroll bar.                       |
  120. |   alwaysVerticalScrollBar     - This style specifies to never remove the     |
  121. |                                 vertical scroll bar.                         |
  122. |   asNeededVerticalScrollBar   - This style specifies the removal of the      |
  123. |                                 vertical scroll bar when the entire height   |
  124. |                                 of the view window is visible and there is   |
  125. |                                 no data to scroll vertically.                |
  126. |   noVerticalScrollBar         - This style specifies to never show the       |
  127. |                                 vertical scroll bar.                         |
  128. |   noViewWindowFill            - This style specifies that the view port will |
  129. |                                 not paint the portion of the view rectangle  |
  130. |                                 occupied by the view window.  This should be |
  131. |                                 specified to optimize overall painting if    |
  132. |                                 the view window is known to paint its entire |
  133. |                                 rectangle.                                   |
  134. |   classDefaultStyle           - Original default style for this class,       |
  135. |                                 which is asNeededHorizontalScrollBar |       |
  136. |                                 asNeededVerticalScrollBar |                  |
  137. |                                 IWindow::visible.                            |
  138. |                                                                              |
  139. | The following functions provide a means of getting and setting the default   |
  140. | style for this class:                                                        |
  141. |   defaultStyle    - Returns the current default style.  This is the same     |
  142. |                     as classDefaultStyle unless setDefaultStyle has been     |
  143. |                     called.                                                  |
  144. |   setDefaultStyle - Sets the default style for all subsequent IViewPort      |
  145. |                     objects.                                                 |
  146. ------------------------------------------------------------------------------*/
  147. INESTEDBITFLAGCLASSDEF2(Style, IViewPort, IWindow, ICanvas);
  148.                                   // style class definition
  149. static const Style
  150.   alwaysHorizontalScrollBar,
  151.   asNeededHorizontalScrollBar,
  152.   noHorizontalScrollBar,
  153.   alwaysVerticalScrollBar,
  154.   asNeededVerticalScrollBar,
  155.   noVerticalScrollBar,
  156.   noViewWindowFill,
  157.   classDefaultStyle;
  158. static Style
  159.   defaultStyle             ( );
  160. static void
  161.   setDefaultStyle          ( const Style& style );
  162.  
  163. /*-------------------------------- Accessors -----------------------------------
  164. | These functions provide a means of getting and setting the accessible        |
  165. | attributes of instances of this class:                                       |
  166. |   viewWindow          - Returns the handle of the window bounded by the      |
  167. |                         view port. If more than one child of the view port   |
  168. |                         is found, an exception is thrown.  The parent of     |
  169. |                         the view window is changed so that the view window   |
  170. |                         is properly clipped.                                 |
  171. |   horizontalScrollBar - Returns the address of the horizontal scroll bar.    |
  172. |   verticalScrollBar   - Returns the address of the vertical scroll bar.      |
  173. ------------------------------------------------------------------------------*/
  174. virtual IWindowHandle
  175.   viewWindow               ( );
  176. IScrollBar
  177.  *horizontalScrollBar      ( ) const,
  178.  *verticalScrollBar        ( ) const;
  179.  
  180. /*------------------------- View Window Manipulation ---------------------------
  181. | These functions provide a means of affecting the appearance of the view      |
  182. | window in the viewport:                                                      |
  183. |   scrollViewVerticallyTo   - Causes the specified 0-based offset from the    |
  184. |                              top of the view window to be scrolled to the    |
  185. |                              top of the view port.                           |
  186. |   scrollViewHorizontallyTo - Causes the specified 0-based offset from the    |
  187. |                              left edge of the view window to be scrolled to  |
  188. |                              the left edge of the view port.                 |
  189. |   setViewWindowSize        - Changes the logical size of the window being    |
  190. |                              scrolled.  The logical size does not have to    |
  191. |                              match the real size of the window.              |
  192. |   viewWindowSize           - Returns the logical size of the window being    |
  193. |                              scrolled.  If the setViewWindowSize function    |
  194. |                              has not been called to set a logical size, the  |
  195. |                              real size of the view window is returned.       |
  196. |   viewWindowDrawRectangle  - Returns the area of the view window that is     |
  197. |                              currently visible in the view port.             |
  198. ------------------------------------------------------------------------------*/
  199. virtual IViewPort
  200.  &scrollViewVerticallyTo   ( unsigned long topOffset ),
  201.  &scrollViewHorizontallyTo ( unsigned long leftOffset );
  202. virtual IViewPort
  203.  &setViewWindowSize        ( const ISize& size );
  204. virtual ISize
  205.   viewWindowSize           ( ) const;
  206. virtual IRectangle
  207.   viewWindowDrawRectangle  ( ) const;
  208.  
  209. /*------------------------------- Enumeration ----------------------------------
  210. | The following enumeration is defined:                                        |
  211. |   ColorArea - Enumeration used to specify an area of the view port that can  |
  212. |               be affected with color.  The valid value is:                   |
  213. |                 fillBackground - The portion of the view rectangle that is   |
  214. |                                  not occupied by the view window.  This      |
  215. |                                  situation occurs if the size of the view    |
  216. |                                  window is smaller than the size of the      |
  217. |                                  view port.                                  |
  218. ------------------------------------------------------------------------------*/
  219. enum ColorArea {
  220.   fillBackground
  221. };
  222.  
  223. /*---------------------------------- Color -------------------------------------
  224. | These functions set and query the color of the view port:                    |
  225. |   setColor - Sets the specified color of the view port.                      |
  226. |   color    - Returns the specified color of the view port.                   |
  227. ------------------------------------------------------------------------------*/
  228. IViewPort
  229.  &setColor                 ( ColorArea area, const IColor& color );
  230. IColor
  231.   color                    ( ColorArea area ) const;
  232.  
  233. /*-------------------------------- Overrides -----------------------------------
  234. | This class overrides the following inherited function:                       |
  235. |   setLayoutDistorted - Treats a size change like a layout change.            |
  236. ------------------------------------------------------------------------------*/
  237. virtual IViewPort
  238.  &setLayoutDistorted       ( unsigned long layoutAttributeOn,
  239.                              unsigned long layoutAttributeOff );
  240.  
  241. protected:
  242. /*--------------------------- Protected Overrides ------------------------------
  243. | This class overrides the following protected functions:                      |
  244. |   calcMinimumSize - Returns the recommended minimum size of this IViewPort   |
  245. |                     object.  The size is based on the minimum size of the    |
  246. |                     vertical and horizontal scroll bars.                     |
  247. |   layout          - Positions the scroll bars and view window.               |
  248. ------------------------------------------------------------------------------*/
  249. virtual ISize
  250.   calcMinimumSize          ( ) const;
  251. virtual IViewPort
  252.  &layout                   ( );
  253.  
  254. /*------------------------------ Implementation --------------------------------
  255. | These functions are used to size and position the scroll bars and view       |
  256. | window when the view port is resized or repainted.                           |
  257. |   setupScrollBars     - Sizes, shows, and hides scroll bars for the view     |
  258. |                         port window, as appropriate.  This function also     |
  259. |                         sets the rectangle that bounds the view window.      |
  260. |   positionViewWindow  - Positions the view window within the view rectangle. |
  261. |   setTopLeftViewPoint - Sets the view window coordinate that is displayed    |
  262. |                         in the upper left corner of the view rectangle.      |
  263. |   topLeftViewPoint    - Returns the view window coordinate that is           |
  264. |                         displayed in the upper left corner of the view       |
  265. |                         rectangle.                                           |
  266. ------------------------------------------------------------------------------*/
  267. IViewPort
  268.  &setupScrollBars          ( );
  269. virtual IViewPort
  270.  &positionViewWindow       ( const IWindowHandle& viewWindow,
  271.                              const IRectangle& viewRectangle );
  272. IViewPort
  273.  &setTopLeftViewPoint      ( const IPoint& topLeft );
  274. IPoint
  275.   topLeftViewPoint         ( ) const;
  276.  
  277. private:
  278. /*--------------------------------- Private ----------------------------------*/
  279.   IViewPort              ( const IViewPort& );
  280. IViewPort
  281.  &operator=              ( const IViewPort& );
  282.  
  283. static Style
  284.   currentDefaultStyle;
  285. Style
  286.   vpsClStyle;
  287. IPoint
  288.   ptClTopLeftView;
  289. IScrollBar
  290.  *psbClVert,
  291.  *psbClHorz;
  292. IViewRectangle
  293.  *pcvClViewRect;
  294. ISize
  295.   sizClViewWindow;
  296.  
  297. enum Flag { initialized=1, resizeHandlerAdded=2, scrollHandlerAdded=4,
  298.             keyboardHandlerAdded=8, paintHandlerAdded=16,
  299.             rectanglePaintHandlerAdded=32, useMinimumSizeView=64 };
  300. unsigned long
  301.   ulClFlag;
  302. }; // IViewPort
  303.  
  304. INESTEDBITFLAGCLASSFUNCS(Style, IViewPort);
  305.  
  306. /*----------------------------------------------------------------------------*/
  307. /* Resume compiler default packing.                                           */
  308. /*----------------------------------------------------------------------------*/
  309. #pragma pack()
  310.  
  311. /*----------------------------- Inline Functions -----------------------------*/
  312. #ifndef I_NO_INLINES
  313.   #include <ivport.inl>
  314. #endif
  315.  
  316. #endif /* _IVPORT_ */
  317.