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

  1. #ifndef _ISTATTXT_
  2.   #define _ISTATTXT_
  3. /*******************************************************************************
  4. * FILE NAME: istattxt.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IStaticText - This class creates and manages the static text control     *
  9. *                   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. *******************************************************************************/
  19. #ifndef _ITEXTCTL_
  20.   #include <itextctl.hpp>
  21. #endif
  22. #ifndef _IBITFLAG_
  23.   #include <ibitflag.hpp>
  24. #endif
  25. #ifndef _ICOLOR_
  26.   #include <icolor.hpp>
  27. #endif
  28. #ifndef _IRECT_
  29.   #include <irect.hpp>
  30. #endif
  31.  
  32. /*----------------------------------------------------------------------------*/
  33. /* Align classes on four byte boundary.                                       */
  34. /*----------------------------------------------------------------------------*/
  35. #pragma pack(4)
  36.  
  37. // Forward declarations for other classes:
  38. class ISize;
  39. class IStaticTextHandler;
  40.  
  41.  
  42. class IStaticText : public ITextControl {
  43. typedef ITextControl
  44.   Inherited;
  45. /*******************************************************************************
  46. * The IStaticText class creates and manages the static text control window.    *
  47. * Static text controls are simple text fields, bit maps, and icons.  Static    *
  48. * text controls do not accept user input.                                      *
  49. *                                                                              *
  50. * Example:                                                                     *
  51. *   IStaticText sttxtText(ID_TEXT, this, this, IRectangle(10,10,70,24));       *
  52. *   sttxtText.setText("It is a wonderful day");                                *
  53. *                                                                              *
  54. * To change the style of the static text control after it has been created,    *
  55. * use functions such as:                                                       *
  56. *   setAlignment(IStaticText::centerCenter);                                   *
  57. *******************************************************************************/
  58. public:
  59. /*------------------------- Style ---------------------------------------------
  60.   The following functions provide a means to set and query static text styles:
  61.  
  62.     Style - Nested class that provides static members that define the set of
  63.             valid static text styles.  These styles can be used in conjunction
  64.             with the styles defined by the nested classes IWindow::Style and
  65.             IControl::Style.  For example, you could define an instance of the
  66.             IStaticText::Style class and initialize it like:
  67.                IStaticText::Style
  68.                  style = IStaticText::left | IControl::group;
  69.             An object of this type is provided when the static text is
  70.             created.  A customizable default is used if no styles are
  71.             specified.  Once the object is constructed, IStaticText,
  72.             IWindow, and IControl member functions can be used to set or
  73.             query the object's style.
  74.  
  75.             The declaration of the IStaticText::Style nested class is
  76.             generated by the INESTEDBITFLAGCLASSDEF2 macro.
  77.  
  78.    The valid static text styles are:
  79.     classDefaultStyle - Original default style for this class, which is
  80.                         left | top | fillBackground | IWindow::visible.
  81.     left              - Used to make the text left-justified.
  82.     center            - Used to make the text centered.
  83.     right             - Used to make the text right-justified.
  84.     top               - Used to align the text to the top of the window.
  85.     vertCenter        - Used to align the text vertically in the center of
  86.                         the window.
  87.     bottom            - Used to align the text to the bottom of the window.
  88.     mnemonic          - If a mnemonic prefix character is encountered, the
  89.                         next character is drawn with mnemonic emphasis.
  90.     halftone          - The text will be drawn in halftone color.
  91.     underscore        - The text will be drawn underscored.
  92.     strikeout         - The text will be drawn overstriked.
  93.     wordBreak         - Can only be used when the left and top styles are
  94.                         also specified.  This causes word-wrapping at ends of
  95.                         lines for text that has multiple lines.
  96.     fillBackground    - Erases the background using the currently set fill
  97.                         color before drawing the text.
  98.  
  99.   The following functions provide a means of getting and setting the default
  100.   style for this class:
  101.     defaultStyle    - Returns the current default style.  This is the same as
  102.                       classDefaultStyle unless setDefaultStyle has been
  103.                       called.
  104.     setDefaultStyle - Sets the default style for all subsequent static text
  105.                       controls.
  106. -----------------------------------------------------------------------------*/
  107. INESTEDBITFLAGCLASSDEF2(Style, IStaticText, IWindow, IControl);
  108. static const Style
  109.   classDefaultStyle,
  110.   left,
  111.   center,
  112.   right,
  113.   top,
  114.   vertCenter,
  115.   bottom,
  116.   mnemonic,
  117.   halftone,
  118.   underscore,
  119.   strikeout,
  120.   wordBreak,
  121.   fillBackground;
  122.  
  123. static Style
  124.   defaultStyle    ( );
  125. static void
  126.   setDefaultStyle ( Style style );
  127.  
  128. /*------------------------- Constructors/Destructor ----------------------------
  129. | You can construct instances of this class in the following ways:             |
  130. |    - From a control ID, parent and owner windows, rectangle, and style.      |
  131. |      This creates the specified static text control and an object for it.    |
  132. |    - From the ID of an existing static text control on a dialog window.      |
  133. |      This creates the object for the specified static text control.          |
  134. |    - From the window handle of an existing static text control.  This        |
  135. |      creates the object for the specified static text control.               |
  136. ------------------------------------------------------------------------------*/
  137.   IStaticText ( unsigned long id,
  138.                 IWindow* parent,
  139.                 IWindow* owner,
  140.                 const IRectangle& initial= IRectangle(),
  141.                 const Style& style = defaultStyle() );
  142.  
  143.   IStaticText ( unsigned long id,
  144.                 IWindow* parent );
  145.  
  146.   IStaticText ( const IWindowHandle& handle );
  147.  
  148. virtual
  149.  ~IStaticText ( );
  150.  
  151. /*------------------------------- Enumerations ---------------------------------
  152. |  Alignment - Enumeration used to replace the alignment style.  Values are:   |
  153. |                topLeft        - Text is aligned to the top of the window     |
  154. |                                 and is left-justified.                       |
  155. |                topLeftWrapped - Text is aligned to the top of the window,    |
  156. |                                 is left-justified and is multiple-line with  |
  157. |                                 word-wrapping at ends of lines.              |
  158. |                topCenter      - Text is aligned to the top of the window     |
  159. |                                 and is centered.                             |
  160. |                topRight       - Text is aligned to the top of the window     |
  161. |                                 and is right-justified.                      |
  162. |                centerLeft     - Text is aligned vertically in the center of  |
  163. |                                 the window and is left-justified.            |
  164. |                centerCenter   - Text is aligned vertically in the center of  |
  165. |                                 the window and is centered.                  |
  166. |                centerRight    - Text is aligned vertically in the center of  |
  167. |                                 the window and is right-justified.           |
  168. |                bottomLeft     - Text is aligned to the bottom of the window  |
  169. |                                 and is left-justified.                       |
  170. |                bottomCenter   - Text is aligned to the bottom of the window  |
  171. |                                 and is centered.                             |
  172. |                bottomRight    - Text is aligned to the bottom of the window  |
  173. |                                 and is right-justified.                      |
  174. |                                                                              |
  175. |  ColorArea - Enumeration used to replace the color for a particular region.  |
  176. |              Values are:                                                     |
  177. |                foreground - Sets the color in which the text is drawn.       |
  178. |                background - Sets the color of the character fields.  A       |
  179. |                             character field is the small rectangle of space  |
  180. |                             that contains a character.                       |
  181. |                fill       - Sets the color for the area of the static text   |
  182. |                             control window that is not occupied by text.     |
  183. ------------------------------------------------------------------------------*/
  184. enum Alignment {
  185.   topLeft,
  186.   topLeftWrapped,
  187.   topCenter,
  188.   topRight,
  189.   centerLeft,
  190.   centerCenter,
  191.   centerRight,
  192.   bottomLeft,
  193.   bottomCenter,
  194.   bottomRight
  195. };
  196. enum ColorArea {
  197.   foreground,
  198.   background,
  199.   fill
  200. };
  201.  
  202. /*--------------------------- Alignment Operation ------------------------------
  203. |   setAlignment - Sets the alignment of the static text.                      |
  204. |   alignment    - Returns the current alignment for the static text.          |
  205. ------------------------------------------------------------------------------*/
  206. IStaticText
  207.  &setAlignment ( Alignment alignment );
  208. Alignment
  209.   alignment    ( ) const;
  210.  
  211. /*-------------------------------- Attributes ------------------------------------
  212. | These operations can be used to query and change the style of the text.        |
  213. |   enableFillBackground  - Either erases the background before the text is      |
  214. |                           drawn, or does not change the background.            |
  215. |   disableFillBackground - Draws text over what is currently in the background. |
  216. |   enableStrikeout       - Draws a line through the text.                       |
  217. |   disableStrikeout      - Removes the line that has been drawn through the     |
  218. |                           text.                                                |
  219. |   enableUnderscore      - Draws a line beneath the text.                       |
  220. |   disableUnderscore     - Removes the line beneath the text.                   |
  221. |   enableHalftone        - Draws the text in the halftone style.                |
  222. |   disableHalftone       - Removes halftone style from the text.                |
  223. |   hasFillBackground     - Returns true if the background is erased before any  |
  224. |                           text is drawn.                                       |
  225. |   isStrikeout           - Queries whether the text has the strikeout style.    |
  226. |   isUnderscore          - Queries whether the text has the underscore style.   |
  227. |   isHalftone            - Queries whether the text has the halftone style.     |
  228. --------------------------------------------------------------------------------*/
  229. IStaticText
  230.  &enableFillBackground  ( Boolean enable = true ),
  231.  &disableFillBackground ( ),
  232.  &enableStrikeout       ( Boolean enable = true ),
  233.  &disableStrikeout      ( ),
  234.  &enableUnderscore      ( Boolean enable = true ),
  235.  &disableUnderscore     ( ),
  236.  &enableHalftone        ( Boolean enable = true ),
  237.  &disableHalftone       ( );
  238.  
  239. Boolean
  240.   hasFillBackground     ( ) const,
  241.   isStrikeout           ( ) const,
  242.   isUnderscore          ( ) const,
  243.   isHalftone            ( ) const;
  244.  
  245. /*----------------------------- Color Functions --------------------------------
  246. | These functions are used to change or set the colors used by the control:    |
  247. |  setColor - Changes the color of the given color region.                     |
  248. |  color    - Returns the color of the given color region.                     |
  249. ------------------------------------------------------------------------------*/
  250. IStaticText
  251.  &setColor              ( ColorArea value, const IColor& color );
  252.  
  253. IColor
  254.   color                 ( ColorArea value ) const;
  255.  
  256. /*-------------------------- Minimum Size Adjustment ---------------------------
  257. | The following operations set and query the number of characters that the     |
  258. | minimum size can be based on.                                                |
  259. |    setLimit - Sets the maximum number of characters that the static text     |
  260. |               control is likely to display.  This function should be used by |
  261. |               static text controls that will be changing the text they       |
  262. |               display while on an ISetCanvas or IMultiCellCanvas.            |
  263. |               A non-zero value is used to calculate a minimum size for this  |
  264. |               window that can be larger than that needed to hold the         |
  265. |               currently-displayed text.  The larger of the actual size       |
  266. |               needed by the text or the size based on the limit specified to |
  267. |               this function is used as the minimum size.  A limit of 0       |
  268. |               specifies that the minimum size should only be what is needed  |
  269. |               to display the current text, which is the default if this      |
  270. |               function is not called.                                        |
  271. |    limit    - Returns the maximum number of characters that the static text  |
  272. |               control is likely to display.                                  |
  273. ------------------------------------------------------------------------------*/
  274. IStaticText
  275.  &setLimit              ( unsigned long limit = 0 );
  276. unsigned long
  277.   limit                 ( ) const;
  278.  
  279. /*-------------------------------- Overrides -----------------------------------
  280. | This class overrides the following inherited functions:                      |
  281. |   setText            - Sets the text for the control and notifies a parent   |
  282. |                        canvas to update how it lays out its child windows,   |
  283. |                        if appropriate.                                       |
  284. ------------------------------------------------------------------------------*/
  285. virtual IStaticText
  286.  &setText               ( const char* text ),
  287.  &setText               ( const IResourceId& text );
  288.  
  289. protected:
  290. /*------------------------------- Layout Size ----------------------------------
  291. | calcMinimumSize  - Returns the recommended minimum size of this static text  |
  292. |                    control.  The size is based on the text string length     |
  293. |                    and the current font, and the value returned by           |
  294. |                    calcLimitSize.                                            |
  295. | calcLimitSize    - Returns a size based on the text limit value and the      |
  296. |                    current font.                                             |
  297. ------------------------------------------------------------------------------*/
  298. virtual ISize
  299.   calcMinimumSize        ( ) const,
  300.   calcLimitSize          ( ) const;
  301.  
  302. private:
  303. /*--------------------------------- Private ----------------------------------*/
  304.   IStaticText ( const IStaticText& );
  305. IStaticText
  306.  &operator=   ( const IStaticText& );
  307.  
  308. static Style
  309.   currentDefaultStyle;
  310. IColor
  311.   clrfill,
  312.   clrback;
  313. Boolean
  314.   clrset;
  315. unsigned long
  316.   ulClLimit;
  317.  
  318. friend class IStaticTextHandler;
  319. }; // class IStaticText
  320.  
  321. INESTEDBITFLAGCLASSFUNCS(Style, IStaticText);
  322.                                   // global style functions
  323.  
  324. /*----------------------------------------------------------------------------*/
  325. /* Resume compiler default packing.                                           */
  326. /*----------------------------------------------------------------------------*/
  327. #pragma pack()
  328.  
  329. #endif  // _ISTATTXT_
  330.