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

  1. #ifndef _IFILEDLG_
  2. #define _IFILEDLG_
  3. /*******************************************************************************
  4. * FILE NAME: ifiledlg.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   This file contains the declaration(s) of the class(es):                    *
  8. *     IFiledlg -                                                               *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or               *
  15. *   disclosure                                                                 *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #ifndef _IBASE_
  20.   #include <ibase.hpp>
  21. #endif
  22.  
  23. // forward declarations here
  24. class IFileDialog;
  25. class StringSeq;
  26. class IResourceId;
  27.  
  28. struct _FILEDLG;
  29.  
  30.  
  31. #ifndef _IFRAME_
  32.   #include <iframe.hpp>
  33. #endif
  34.  
  35. #ifndef _IBITFLAG_
  36.   #include <ibitflag.hpp>
  37. #endif
  38.  
  39. #ifndef _ISTRING_
  40.   #include <istring.hpp>
  41. #endif
  42.  
  43. #ifndef _IRESLIB_
  44.   #include <ireslib.hpp>
  45. #endif
  46.  
  47. #ifndef _IPOINT_
  48.   #include <ipoint.hpp>
  49. #endif
  50.  
  51. /*----------------------------------------------------------------------------*/
  52. /* Align classes on four byte boundary.                                       */
  53. /*----------------------------------------------------------------------------*/
  54. #pragma pack(4)
  55.  
  56. /*----------------------------------------------------------------------------*/
  57. /* Turn off warning for compiler generated copy/assignment                    */
  58. /*----------------------------------------------------------------------------*/
  59. #pragma info(nocpy)
  60.  
  61. class IFileDialog : public IFrameWindow {
  62. typedef IFrameWindow Inherited;
  63. /*******************************************************************************
  64. * The IFIleDialog class displays a file dialog for the user to choose a file.  *
  65. * Once the user has chosen a file, accessor methods allow you to retrieve      *
  66. * information about the chosen file.                                           *
  67. *                                                                              *
  68. *                                                                              *
  69. * Example:                                                                     *
  70. *    // Modal Open Dialog with default behavior                                *
  71. *    IFileDialog fd(desktopWindow(), this);                                    *
  72. *    // selected file will contain fully qualified file name chosen by user    *
  73. *    if (fd.pressedOK())                                                       *
  74. *      IString selectedFile(fd.fileName());                                    *
  75. *                                                                              *
  76. *    // SaveAs modeless dialog with Title                                      *
  77. *    IFileDialog::Settings settings;                                           *
  78. *    settings.setTitle("Example").setFileName("c:\\iclui\\read.me");           *
  79. *    IFileDialog fd(desktopWindow(), this, fdSettings, IFileDialog::modeless); *
  80. *    MyFileDlgHandler fdHandler;  // derived from IFileDialogHandler           *
  81. *    fdHandler.handleEventsFor(fd);                                            *
  82. *    // selected file can be obtained in MyFileDlgHandler::modelessResults.    *
  83. *                                                                              *
  84. *******************************************************************************/
  85. public:
  86. /*-------------------------------- Style ---------------------------------------
  87. | The following functions provide a means to set and query file dialog         |
  88. | styles:                                                                      |
  89. |                                                                              |
  90. |   Style - Nested class that provides static members that define the set of   |
  91. |           valid file dialog styles.  For example, you could define an        |
  92. |           instance of this class and initialize it like:                     |
  93. |             IFileDialog::Style                                               |
  94. |               style = IFileDialog::modeless | IFileDialog::applyButton;      |
  95. |           An object of this type is provided when the file dialog is         |
  96. |           created.  A customizable default is used if no styles are          |
  97. |           specified.  Once the object is constructed, IFileDialog member     |
  98. |           functions can be used to set or query the object's style.          |
  99. |                                                                              |
  100. |           The declaration of the IFileDialog::Style nested class is          |
  101. |           generated by the INESTEDBITFLAGCLASSDEF0 macro.                    |
  102. |                                                                              |
  103. | The valid file dialog styles are:                                            |
  104. |                                                                              |
  105. |   classDefaultStyle - Original default style for this class, which is        |
  106. |                       noStyle.                                               |
  107. |   noStyle           - None of the valid styles are enabled when noStyle is   |
  108. |                       set.                                                   |
  109. |   modeless          - When this style is specified, the dialog is modeless.  |
  110. |                       The constructor for a modeless dialog will return      |
  111. |                       immediately.  To determine the file chosen by the
  112. |                       user, you should create an IFileDialogHandler and use
  113. |                       the modelessResults function.
  114. |   applyButton       - Adds an Apply push button to the dialog.  This is
  115. |                       useful in a modeless dialog.
  116. |   includeEAS        - If this style is specified, the dialog will always     |
  117. |                       query extended attribute information for files as it   |
  118. |                       fills the Files list box.  The default is to not       |
  119. |                       query the information unless the user has selected     |
  120. |                       an extened attribute type filter from the dialog.      |
  121. |   helpButton        - A Help push button is added to the dialog.  It will    |
  122. |                       send a Help message to the owner of the dialog.|
  123. |   filter            - When this style is specified, the dialog uses the      |
  124. |                       union of the string filter and the extended-attribute  |
  125. |                       type filter when filtering files for the Files list    |
  126. |                       box.  When this style is not specified, the list box,  |
  127. |                       by default, uses the intersection of the two.          |
  128. |   multiSelection    - When this style is specified, the Files list box for   |
  129. |                       the dialog is a multiple selection list box.  When     |
  130. |                       this style is not specified, the default is a          |
  131. |                       single-selection list box.                             |
  132. |   selectableListbox - When this style is specified, the Files list box on a  |
  133. |                       Save As dialog is enabled.  When this style is not     |
  134. |                       specified, the Files list box is not enabled for a     |
  135. |                       Save As dialog.  This is the default.                  |
  136. |   preload           - If this style is specified, the dialog will preload    |
  137. |                       the volume information for the drives and will         |
  138. |                       preset the current default directory for each drive.   |
  139. |                       The default behavior is for the volume label to be     |
  140. |                       blank and the initial directory will be the root       |
  141. |                       directory for each drive.                              |
  142. |                                                                              |
  143. | The following functions provide a means of getting and setting the default   |
  144. | style for this class:                                                        |
  145. |                                                                              |
  146. |   defaultStyle    - Returns the current default style.  This is the same as  |
  147. |                     classDefaultStyle unless setDefaultStyle has been    |
  148. |                     called.                                                  |
  149. |   setDefaultStyle - Sets the default style for all subsequent file dialogs.  |
  150. ------------------------------------------------------------------------------*/
  151.     INESTEDBITFLAGCLASSDEF0(Style, IFileDialog);
  152.  
  153. static Style
  154.   classDefaultStyle;
  155.  
  156.     static const Style
  157.       noStyle,
  158.       modeless,
  159.       applyButton,
  160.       includeEAS,
  161.       helpButton,
  162.       filter,
  163.       multiSelection,
  164.       selectableListbox,
  165.       preload;
  166.  
  167. static void
  168.   setDefaultStyle                  ( Style      newDefault);
  169. static Style
  170.   defaultStyle                     ( );
  171.  
  172. class Settings : public IBase
  173. /*******************************************************************************
  174. | The IFileDialog::Settings class is nested within the IFileDialog class.  It  |
  175. | is used to pass input to the file dialog.  The file dialog will be           |
  176. | displayed with the items specified in the settings.  If no Settings object   |
  177. | is passed into the IFileDialog constructor, a default Settings object is     |
  178. | constructed for you. The default Settings object provides an Open Dialog     |
  179. | with none of the other settings in effect.                                   |
  180. *******************************************************************************/
  181. {
  182.     public:
  183.  
  184. /*------------------------- Constructor/Destructor ----------------------------
  185. | The only way to construct instances of this class is by using the default    |
  186. | constructor.                                                                 |
  187. ------------------------------------------------------------------------------*/
  188.  Settings();
  189.  ~Settings();
  190.  
  191. /*---------------- Setting Information About the Dialog ------------------------
  192. |These functions provide ways to set information about the dialog:             |
  193. |  setOpenDialog       - Creates an Open File dialog (default).                |
  194. |  setSaveAsDialog     - Creates a Save As dialog.                             |
  195. |  setTitle            - Sets the dialog's title.                              |
  196. |  setOKButtonText     - Sets the text that appears on the OK button.          |
  197. |  setFileName         - Sets a default file name selection.                   |
  198. |  setInitialFileType  - Extended attribute that is used to filter the initial |
  199. |                        display of files.  If this function is not specified, |
  200. |                        the default is <All Files>.  This type need not be    |
  201. |                        used on an addFileType call.                          |
  202. |  addFileType         - Adds a specified type to the drop-down box of         |
  203. |                        extended-attribute types.                             |
  204. |  setInitialDrive     - Drive for which initial information is displayed.  If |
  205. |                        this function is not called, the dialog displays      |
  206. |                        information for the current drive.  This drive need   |
  207. |                        not be used on an addDrive call.                      |
  208. |  addDrive            - Adds a drive or network identifier to the Drive list  |
  209. |                        in the initial dialog. If this function is invoked,   |
  210. |                        then the Drive List will be limited to the drives     |
  211. |                        specified on addDrive calls.                          |
  212. |  setDialogTemplate   - Specifies a dialog template resource to be used in    |
  213. |                        place of the OS/2-supplied default font dialog.       |
  214. |  setPosition         - Sets the initial placement of the dialog within the   |
  215. |                        parent window.  If this is not set, the dialog is     |
  216. |                        centered in the parent window.                        |
  217. ------------------------------------------------------------------------------*/
  218.  
  219.  Settings
  220.    &setOpenDialog           ( ),
  221.    &setSaveAsDialog         ( ),
  222.    &setTitle                (char* newTitle),
  223.    &setTitle                (const IResourceId& resId),
  224.    &setOKButtonText         (char* newText),
  225.    &setOKButtonText         (const IResourceId& resId),
  226.    &setInitialFileType      (char* fileType),
  227.    &setFileName             (char* fileName),
  228.    &addFileType             (char* fileType),
  229.    &setInitialDrive         (char* drive),
  230.    &addDrive                (char* drive),
  231.    &setDialogTemplate       (const IResourceId& resId),
  232.    &setPosition             (const IPoint& pos);
  233.  
  234.  
  235.  
  236. private: /*------------------------ PRIVATE ----------------------------------*/
  237.  IString
  238.    title                    ( ) const,
  239.    OKButtonText             ( ) const,
  240.    fileName                 ( ) const,
  241.    initialDrive             ( ) const,
  242.    initialFileType          ( ) const;
  243.  
  244.  StringSeq
  245.    *fileTypes               ( ) const,
  246.    *drives                  ( ) const;
  247.  
  248.  
  249.  IPoint
  250.    position                 ( ) const;
  251.  
  252.  Boolean
  253.    isOpenDialog             ( ) const,
  254.    isPositionSet            ( ) const,
  255.    isDialogTemplateSet      ( ) const;
  256.  
  257.  
  258. friend IFileDialog;
  259.  
  260. IString
  261.   _title,
  262.   _OKButtonText,
  263.   _fileName,
  264.   _initialDrive,
  265.   _initialFileType;
  266.  
  267. StringSeq
  268.   *_fileTypes,
  269.   *_drives;
  270.  
  271. unsigned long
  272.   _dlgId;
  273.  
  274. IModuleHandle
  275.   _dlgHandle;
  276.  
  277. IPoint
  278.   _position;
  279.  
  280. Boolean
  281.   _isOpenDialog,
  282.   _isPositionSet,
  283.   _isDialogTemplateSet;
  284.  
  285. };   /* Settings */
  286.  
  287. /*------------------------ Constructors/Destructor -----------------------------
  288. | You can construct an instance of this class in the following ways:           |
  289. |     - Using constructors that take a parent, owner, Style, and Settings.     |
  290. |       For these, the Style and Settings are optional and can be specified    |
  291. |       in any order following the parent and owner.                           |
  292. |     - Using a constructor that takes a pointer to an IHandler object.  You   |
  293. |       would use this if you wanted to add an IFileDialogHandler to a modal   |
  294. |       IFileDialog.  The handler must be passed on the constructor because    |
  295. |       once a modal IFileDialog is created, the program will not return to    |
  296. |       you until the user has dismissed the dialog.  At that time, it is too  |
  297. |       late to add a handler.                                                 |
  298. |                                                                              |
  299. | All of the constructors cause a modal dialog to be created by default.       |
  300. | If you require a modeless dialog, you must set the modeless style bit        |
  301. | in the Style argument of the constructor.                                    |
  302. |                                                                              |
  303. | NOTE: Due to the way the Presentation Manager works, a dialog with modal     |
  304. |       style will behave modeless if its parent is not the desktop.  However, |
  305. |       if you pass 0 as the parent argument, the desktop will automatically   |
  306. |       be made the parent of the dialog.                                      |
  307. |------------------------------------------------------------------------------*/
  308.  
  309.  IFileDialog(IWindow*    parent,
  310.              IWindow*    owner,
  311.              Style       style = defaultStyle() );
  312.  
  313.  IFileDialog(IWindow*    parent,
  314.              IWindow*    owner,
  315.              const Settings& settings,
  316.              Style       style = defaultStyle() );
  317.  
  318.  IFileDialog(IWindow*    parent,
  319.              IWindow*    owner,
  320.              Style       style,
  321.              const Settings& settings );
  322.  
  323.  IFileDialog(IWindow*    parent,
  324.              IWindow*    owner,
  325.              IHandler*   handler,
  326.              Style       style = defaultStyle(),
  327.              const Settings& settings = Settings() );
  328.  
  329.  ~IFileDialog( );
  330.  
  331.  
  332. /*---------------- Getting Information About the Dialog ------------------------
  333. | These functions provide ways to get information about the dialog:            |
  334. |    isModeless      - Returns true if this is a modeless dialog.              |
  335. |    pressedOK       - Returns true if the user ended the dialog by pressing   |
  336. |                      the OK push button.                                     |
  337. |    buttonPressedId - Returns the ID of the push button that was used to      |
  338. |                      dismiss the dialog.                                     |
  339. |    returnValue     - Returns the return code, if an error occurred.          |
  340. ------------------------------------------------------------------------------*/
  341.  
  342. Boolean
  343.   isModeless                       ( ) const,
  344.   pressedOK                        ( ) const;
  345.  
  346. long
  347.   buttonPressedId                  ( ) const,
  348.   returnValue                      ( ) const;
  349.  
  350.  
  351. /*----------- Getting Information About the Chosen File ------------------------
  352. | These functions provide ways to get information about the font that was      |
  353. | selected in the font dialog:                                                 |
  354. |    selectedFileCount - Returns the number of files selected by the user.     |
  355. |                        This number can be more than one if the dialog was    |
  356. |                        created with IFileDialog::multiSelection.             |
  357. |    fileName          - Returns the fully qualified file name selected by     |
  358. |                        the user.  When multiSelection is used, you should    |
  359. |                        call this function with the fileNumber parameter set  |
  360. |                        from 0 to selectedFileCount - 1, to ensure the        |
  361. |                        correct number of files is returned.                  |
  362. |    saveAsEAType      - Returns the extended-attribute for a Save As dialog.  |
  363. |                        This is the type the user chose from the drop-down    |
  364. |                        list of EA types.  If <All Files> was the chosen EA   |
  365. |                        type, then this returns a 0-length IString.           |
  366. ------------------------------------------------------------------------------*/
  367. unsigned
  368.   selectedFileCount                ( ) const;
  369.  
  370. IString
  371.   fileName                         (unsigned fileNumber = 0) const,
  372.   saveAsEAType                     ( ) const;
  373.  
  374.  
  375.  
  376.  
  377. private: /*------------------------ Private ----------------------------------*/
  378.  
  379. static Style currentDefaultStyle;
  380.  
  381. friend void* _System
  382.   _IFileDlgProc(unsigned long hwnd, unsigned long ulMsg, void* mp1, void* mp2);
  383.  
  384. struct _FILEDLG*
  385.   pData;
  386.  
  387.  
  388. IHandler*
  389.   handlerToAdd;
  390.  
  391. void IFileDialog :: initialize (IWindow*    parent,
  392.                             IWindow*    owner,
  393.                             Style       style,
  394.                             IHandler*   handler,
  395.                             const Settings& settings);
  396.  
  397. }; /* IFileDialog */
  398.  
  399. /*----------------------------------------------------------------------------*/
  400. /* Resume compiler default packing and warning messages.                      */
  401. /*----------------------------------------------------------------------------*/
  402. #pragma pack()
  403. #pragma info(restore)
  404.  
  405. #ifndef I_NO_INLINES
  406.   #include <ifiledlg.inl>
  407. #endif
  408.  
  409. #endif // _IFILEDLG_
  410.