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

  1. #ifndef _IFONTDLG_
  2. #define _IFONTDLG_
  3. /*******************************************************************************
  4. * FILE NAME: IFONTDLG.HPP                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     IFontPkg - Package of font information for the font dialog.              *
  9. *     IFontDialog - A dialog box to select a font.                             *
  10. *                                                                              *
  11. * COPYRIGHT:                                                                   *
  12. *   (C) Copyright IBM Corporation 1992                                         *
  13. *   All Rights Reserved                                                        *
  14. *   Licensed Materials * Property of IBM                                       *
  15. *                                                                              *
  16. * HISTORY:                                                                     *
  17. *******************************************************************************/
  18.  
  19. #ifndef _IFRAME_
  20.   #include <iframe.hpp>
  21. #endif
  22.  
  23. #ifndef _IBITFLAG_
  24.   #include <ibitflag.hpp>
  25. #endif
  26.  
  27. #ifndef _ISTRING_
  28.   #include <istring.hpp>
  29. #endif
  30.  
  31. #ifndef _IRESLIB_
  32.   #include <ireslib.hpp>
  33. #endif
  34.  
  35. #ifndef _IPOINT_
  36.   #include <ipoint.hpp>
  37. #endif
  38.  
  39. /*----------------------------------------------------------------------------*/
  40. /* Align classes on four byte boundary.                                       */
  41. /*----------------------------------------------------------------------------*/
  42. #pragma pack(4)
  43.  
  44. /*----------------------------------------------------------------------------*/
  45. /* Turn off warning for compiler generated copy/assignment                    */
  46. /*----------------------------------------------------------------------------*/
  47. #pragma info(nocpy)
  48.  
  49. // Forward declarations for other classes:
  50. class   IString;
  51. class   IFont;
  52. class   IFontHandler;
  53.  
  54. struct _FONTDLG;
  55. struct _FATTRS;
  56.  
  57.  
  58. class IFontDialog : public IFrameWindow
  59. {
  60. typedef IFrameWindow Inherited;
  61. /*******************************************************************************
  62. * The IFontDialog class displays a font dialog for the user to choose a font.  *
  63. * Once the user has chosen a font, accessor methods allow you to retrieve      *
  64. * information about the chosen font.                                           *
  65. *                                                                              *
  66. * The easiest way to use this class is to pass an IFont object on the          *
  67. * IFontDialog::Settings constructor.  (Settings is nested within IFontDialog.) *
  68. * This causes the following to happen:                                         *
  69. *     - The passed in IFont will be used as the initially displayed font       *
  70. *       choice in the dialog.                                                  *
  71. *     - If the user dismisses the dialog by pressing the OK push button, the   *
  72. *       passed in IFont object is automatically changed to what the user       *
  73. *       selected.                                                              *
  74. *                                                                              *
  75. * Example:                                                                     *
  76. *       IFont curFont("Tms Rmn", 24);                                          *
  77. *       // Font Dialog displayed with Tms Rmn 24 as initial selection          *
  78. *       IFontDialog::Settings fdSettings(&curFont);                            *
  79. *       IFontDialog fd(desktopWindow(), this, fdSettings);                     *
  80. *       // curFont now set to user's selection                                 *
  81. *    }                                                                         *
  82. *******************************************************************************/
  83. public:
  84. /*------------------------ Style -----------------------------------------------
  85. | The following functions provide a means to set and query font dialog         |
  86. | styles:                                                                      |
  87. |                                                                              |
  88. |   Style - Nested class that provides static members that define the set of   |
  89. |           valid font dialog styles.  For example, you could define an        |
  90. |           instance of this class and initialize it like:                     |
  91. |             IFontDialog::Style                                               |
  92. |               style = IFontDialog::modeless | IFontDialog::applyButton;      |
  93. |           An object of this type is provided when the font dialog is         |
  94. |           created.  A customizable default is used if no styles are          |
  95. |           specified.  Once the object is constructed, IFontDialog member     |
  96. |           functions can be used to set or query the object's style.          |
  97. |                                                                              |
  98. |           The declaration of the IFontDialog::Style nested class is          |
  99. |           generated by the INESTEDBITFLAGCLASSDEF0 macro.                    |
  100. |                                                                              |
  101. | The valid font dialog styles are:                                            |
  102. |                                                                              |
  103. |   classDefaultStyle - Static variable that is set to 0.  This means that no  |
  104. |                       style flags are set.                                   |
  105. |   noStyle           - None of the valid styles are enabled when noStyle is   |
  106. |                       set.                                                   |
  107. |   applyButton       - An Apply push button is added to the dialog.  This is  |
  108. |                       useful in a modeless dialog.                           |
  109. |   bitmapOnly        - The dialog presents bit-map fonts only.                |
  110. |   fixedWidthOnly    - The dialog presents fixed-width (monospace) fonts      |
  111. |                       only.                                                  |
  112. |   helpButton        - A Help push button is added to the dialog.  It will    |
  113. |                       send a Help message to the owner of the dialog.        |
  114. |   modeless          - When this style is specified, the dialog is modeless.  |
  115. |                       The constructor for a modeless dialog will return      |
  116. |                       immediately.  To determine the font chosen by the      |
  117. |                       user, you should create an IFontDialogHandler and use  |
  118. |                       the modelessResults function.                          |
  119. |   noSynthesize      - The dialog will not manipulate bit-map fonts to        |
  120. |                       synthesize features, such as italics and bold.         |
  121. |   proportionalOnly  - The dialog presents proportionally spaced fonts only.  |
  122. |   resetButton       - A Reset push button is added to the dialog.  When      |
  123. |                       this push button is pressed, the values for the        |
  124. |                       dialog are restored to their initial values.           |
  125. |   vectorOnly        - The dialog presents vector fonts only.                 |
  126. ------------------------------------------------------------------------------*/
  127.     INESTEDBITFLAGCLASSDEF0(Style, IFontDialog);
  128.  
  129. static Style
  130.   classDefaultStyle;
  131.  
  132.     static const Style
  133.       noStyle,
  134.       applyButton,
  135.       bitmapOnly,
  136.       fixedWidthOnly,
  137.       helpButton,
  138.       modeless,
  139.       noSynthesize,
  140.       proportionalOnly,
  141.       resetButton,
  142.       vectorOnly;
  143.  
  144. class Settings : public IBase
  145. /*******************************************************************************
  146. | The IFontDialog::Settings class is nested within IFontDialog.  It is used    |
  147. | to pass input to the IFontDialog.  The font dialog will be displayed with    |
  148. | the items specified in the settings.  If no Settings object is passed into   |
  149. | the IFontDialog constructor, a default Settings object is constructed for    |
  150. | you.  The default is to set nothing.                                         |
  151. *******************************************************************************/
  152. {
  153. public:
  154.  
  155.  
  156. /*------------------------ Constructor/Destructor ------------------------------
  157. |  The only way you can construct an instance of this class is by using a      |
  158. |  constructor that takes an optional IFont* argument.  The optional IFont*    |
  159. |  specifies a font to be displayed as the initial selection in the dialog.    |
  160. |  If the OK push button is pressed, the passed in font is changed to the      |
  161. |  font selected by the user.                                                  |
  162. ------------------------------------------------------------------------------*/
  163.  Settings(IFont* pfont = 0);
  164.  ~Settings();
  165.  
  166.  
  167.  
  168. /*---------------- Setting Information About the Dialog ------------------------
  169. | These functions provide ways to customize the font dialog:                   |
  170. |    setTitle          - Sets the font dialog's title.                         |
  171. |    setPreviewText    - Sets the text to display in the font sample box.      |
  172. |    setSizeList       - Sets the list of point size choices.  This only       |
  173. |                        affects dialogs for vector fonts.  A dialog for a     |
  174. |                        bit-map font will have the size list automatically    |
  175. |                        set to the available sizes for the bit-map font.      |
  176. |    setDialogTemplate - Specifies a dialog template resource to be used in    |
  177. |                        place of the OS/2-supplied default font dialog.       |
  178. |    setPosition       - Sets the initial placement of the dialog within the   |
  179. |                        parent window.  If this is not set, the dialog is     |
  180. |                        centered in the parent window.                        |
  181. ------------------------------------------------------------------------------*/
  182. Settings
  183.    &setTitle              (const char* title),
  184.    &setTitle              (const IResourceId& resId),
  185.    &setPreviewText        (const char* previewText),
  186.    &setSizeList           (const char* sizeList),
  187.  
  188.    &setDialogTemplate       (const IResourceId& resId),
  189.    &setPosition             (const IPoint& pos);
  190.  
  191. /*------------------- Setting the Presentation Space ---------------------------
  192. | These functions provide ways to set the presentation space that will be      |
  193. | used to determine which fonts are available.                                 |
  194. |    setDisplayPS - Sets the display's presentation space.                     |
  195. |    setPrinterPS - Sets the printer's presentation space.                     |
  196. |                   NOTE: If the presentation space is not specified in the    |
  197. |                         settings, the display's presentation space is        |
  198. |                         automatically used.                                  |
  199. ------------------------------------------------------------------------------*/
  200. Settings
  201.    &setDisplayPS          (const IPresSpaceHandle& hpsDisplay),
  202.    &setPrinterPS          (const IPresSpaceHandle& hpsPrinter);
  203.  
  204. /*----------- Setting Information About the Initial Font -----------------------
  205. | These functions provide ways to set information about the initial font that  |
  206. | will be displayed in the font dialog.                                        |
  207. |    setFamily    - Sets the font's family name.                               |
  208. |    setPointSize - Sets the font's point size.                                |
  209. ------------------------------------------------------------------------------*/
  210. Settings
  211.    &setFamily          (const char* fontFamily),
  212.    &setPointSize           (unsigned long pointSize);
  213.  
  214.  
  215.  
  216. private: /*------------------------ PRIVATE ----------------------------------*/
  217.  
  218. IFont
  219.    *papplyFont;
  220.  
  221. struct _FONTDLG
  222.    *pData;
  223.  
  224. friend IFontDialog;
  225.  
  226. };   /* Settings */
  227.  
  228.  
  229. /*------------------------ Constructors/Destructor -----------------------------
  230. | You can construct instances of this class in the following ways:             |
  231. |    - Using a constructor that takes a parent, owner, Style, and Settings.    |
  232. |      For these, the Style and Settings are optional and can be specified     |
  233. |      in any order following the parent and owner.                            |
  234. |                                                                              |
  235. |    - Using a constructor that takes a pointer to an IHandler object.  You    |
  236. |      would use this if you wanted to add an IFontDialogHandler to a modal    |
  237. |      font dialog.  The handler must be passed on the constructor because     |
  238. |      once a modal font dialog is created, the program will not return to     |
  239. |      you until the user has dismissed the dialog.  At that time it is too    |
  240. |      late to add a handler.                                                  |
  241. |                                                                              |
  242. | All of the constructors cause a modal dialog to be created by default.       |
  243. | If you require a modeless dialog, you must set the modeless style bit        |
  244. | in the Style argument of the constructor.                                    |
  245. |                                                                              |
  246. | NOTE: Due to the way the Presentation Manager works, a dialog with modal     |
  247. |       style will behave modeless if its parent is not the desktop.  However, |
  248. |       if you pass 0 as the parent argument, the desktop will automatically   |
  249. |       be made the parent of the dialog.                                      |
  250. ------------------------------------------------------------------------------*/
  251.  
  252.  IFontDialog(IWindow*    parent,
  253.              IWindow*    owner,
  254.              Style       style = defaultStyle() );
  255.  
  256.  IFontDialog(IWindow*    parent,
  257.              IWindow*    owner,
  258.              const Settings& settings,
  259.              Style       style = defaultStyle() );
  260.  
  261.  IFontDialog(IWindow*    parent,
  262.              IWindow*    owner,
  263.              Style       style,
  264.              const Settings& settings );
  265.  
  266.  IFontDialog(IWindow*    parent,
  267.              IWindow*    owner,
  268.              IHandler*   handler,
  269.              Style       style = defaultStyle(),
  270.              const Settings& settings = Settings(0) );
  271.  
  272.  ~IFontDialog( );
  273.  
  274. /*-------------------------------- Accessors -----------------------------------
  275. | The following functions provide means of getting and setting the accessible  |
  276. | attributes of instances of this class:                                       |
  277. |   setDefaultStyle - Sets the default style for all subsequent items.         |
  278. |   defaultStyle    - Returns the current default style.                       |
  279. ------------------------------------------------------------------------------*/
  280.  
  281. static void
  282.   setDefaultStyle                  ( Style      newDefault);
  283. static Style
  284.   defaultStyle                     ( );
  285.  
  286.  
  287. /*---------------- Getting Information About the Dialog ------------------------
  288. | These functions provide ways to get information about the dialog:            |
  289. |    isModeless      - Returns true if this is a modeless dialog.              |
  290. |    pressedOK       - Returns true if the user ended the dialog by pressing   |
  291. |                      the OK push button.                                     |
  292. |    buttonPressedId - Returns the ID of the push button that was used to end  |
  293. |                      the dialog.                                             |
  294. |    returnValue     - Returns the return code if an error occurred.           |
  295. ------------------------------------------------------------------------------*/
  296.  
  297. long
  298.    buttonPressedId       () const,
  299.    returnValue           () const;
  300.  
  301. Boolean
  302.   isModeless                       ( ) const,
  303.   pressedOK                        ( ) const;
  304.  
  305. /*----------- Getting Information About the Chosen Font ------------------------
  306. | These functions provide ways to get information about the font that was      |
  307. | selected in the font dialog.                                                 |
  308. |    fontFamily       - Returns the font's family name.                        |
  309. |    fontWeight       - Returns the weight class (boldness) of the font.       |
  310. |    fontWidth        - Returns the width class of the font.                   |
  311. |    emHeight         - Returns the height of the Em square for the font.      |
  312. |    xHeight          - Returns the height above the baseline for lowercase    |
  313. |                       letters.                                               |
  314. |    externalLeading  - Returns the amount of white space between lines of     |
  315. |                       text.                                                  |
  316. |    pointSize        - Returns the font's point size.                         |
  317. |    nominalPointSize - For a bit-map font, this returns the height of the     |
  318. |                       font.  For a vector font, this is the optimal size     |
  319. |                       for the font.                                          |
  320. ------------------------------------------------------------------------------*/
  321. IString
  322.    fontFamily             () const;
  323.  
  324. unsigned long
  325.    fontWeight             () const,
  326.    fontWidth              () const;
  327.  
  328. long
  329.    emHeight               () const,
  330.    xHeight                () const,
  331.    externalLeading        () const,
  332.    pointSize              () const,
  333.    nominalPointSize       () const;
  334.  
  335.  
  336.  
  337. private: /*------------------------ PRIVATE ----------------------------------*/
  338.  
  339. IFont* papplyFont;
  340.  
  341. static Style currentDefaultStyle;
  342.  
  343.  
  344. IHandler*
  345.   _handlerToAdd;
  346.  
  347. void IFontDialog  :: initialize (IWindow*    parent,
  348.                             IWindow*    owner,
  349.                             Style       style,
  350.                             IHandler*   handler,
  351.                             const Settings& settings);
  352.  
  353.  
  354. struct _FONTDLG
  355.    *pData;
  356.  
  357.  
  358. friend  void* _System
  359.   _IFontDlgProc(unsigned long hwnd, unsigned long ulMsg, void* mp1, void* mp2);
  360. friend IFont;
  361. friend IFontHandler;
  362.  
  363. }; /* IFontDialog */
  364.  
  365. /*----------------------------------------------------------------------------*/
  366. /* Resume compiler default packing and warning messages.                      */
  367. /*----------------------------------------------------------------------------*/
  368. #pragma pack()
  369. #pragma info(restore)
  370.  
  371. #ifndef I_NO_INLINES
  372.   #include <ifontdlg.inl>
  373. #endif
  374.  
  375. #endif
  376.