home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / notebook / smrtguid / smrtguid.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  10.1 KB  |  391 lines

  1. #ifndef _SMRTGUID_
  2. #define _SMRTGUID_
  3. //************************************************************
  4. // Notebook Control - Smart Guide Notebook
  5. //
  6. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  7. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  8. // All Rights Reserved.
  9. //************************************************************
  10. #include <istring.hpp>
  11. #include <ibitflag.hpp>
  12. #include <irect.hpp>
  13.  
  14. class IWindow;
  15. class IFrameWindow;
  16. class INotebook;
  17. class IMultiCellCanvas;
  18. class IPageSelectEvent;
  19. class IPageHandle;
  20. class IPushButton;
  21. class IHelpWindow;
  22. class SmartGuideList;
  23. class SmartGuidePageHandler;
  24. class SmartGuideCommandHandler;
  25. class SmartChoiceSelectHandler;
  26. class SmartChoiceList;
  27. class SmartPageInfoList;
  28. class SmartTree;
  29. class SmartPageInfo;
  30.  
  31. //  SmartPage is an abstract base class that defines the protocol
  32. //  for pages in a SmartGuide.  This includes help for the
  33. //  page (not implemented), text for the notebook tab,
  34. //  the protocol to specify the size of the view for the page,
  35. //  and the protocol to create the view of the page.
  36. //
  37. class SmartPage   {
  38.  
  39. public:
  40. /*------------------------------- Constructors -----------------------*/
  41. SmartPage ( )
  42.   : fTabText(""),
  43.     fHelpId (0)
  44.   { }
  45. virtual
  46.  ~SmartPage ( )
  47.   { }
  48.  
  49. /*----------------------------- Panel Creation -----------------------*/
  50. virtual ISize
  51.   minimumSize    ( ) const;
  52.  
  53. virtual IWindow*
  54.   createAndOrphanPage ( IWindow*          parent,
  55.                         IWindow*          owner,
  56.                         const IRectangle& initialRect) = 0;
  57.  
  58. /*------------------------- Navigation and Choice --------------------*/
  59. // The following function is called by the SmartGuide when
  60. // navigating to the next page in the notebook.  All Choices are
  61. // zero based.  The zero returned here causes traversal to
  62. // the first leg of the node.  Multi-choice smart pages overide this to
  63. // pick other legs.
  64. virtual unsigned long
  65.   currentChoice  ( )  const { return 0; }
  66.  
  67. // The following function is called by SmartGuide to determine
  68. // if it is ok to enable the "Done" button.
  69. virtual Boolean
  70.   isOKToClose    ( IString& closeErrorIfFalse ) const;
  71.  
  72. /*----------------------------- Panel Text ---------------------------*/
  73. virtual SmartPage
  74.  &setTabText     ( const IString& tabText);
  75.  
  76. virtual IString
  77.   tabText        ( ) const;
  78.  
  79.  
  80. /*------------------------------ Displaying Help ---------------------*/
  81. // The following functions store and retrieve a help identifier
  82. // for the page.
  83. virtual SmartPage
  84.  &setHelpId      ( unsigned long helpId);
  85.  
  86. virtual unsigned long
  87.   helpId         ( ) const;
  88.  
  89. private:
  90. /*------------------------------ Hidden Members ----------------------*/
  91.   SmartPage ( const SmartPage& );
  92. SmartPage
  93.  &operator=   ( const SmartPage& );
  94.  
  95. IString
  96.  fTabText;
  97. unsigned long
  98.  fHelpId;
  99.  
  100. }; // SmartPage
  101.  
  102.  
  103.  
  104.  
  105. // TextSmartPage is a SmartPage that adds a label
  106. // and non-editable text to the page.
  107. //
  108. class TextSmartPage : public SmartPage
  109. {
  110. typedef SmartPage
  111.   Inherited;
  112. public:
  113. /*------------------------------- Constructors -----------------------*/
  114.   TextSmartPage ( )
  115.    :  fPageLabel ( "" ),
  116.       fPageText  ( "" )
  117.     {}
  118.  
  119. /*----------------------------- Panel Creation -----------------------*/
  120. virtual ISize
  121.   minimumSize     ( ) const;
  122.  
  123. virtual IWindow*
  124.   createAndOrphanPage ( IWindow*          parent,
  125.                         IWindow*          owner,
  126.                         const IRectangle& initialRect);
  127.  
  128. /*----------------------------- Panel Text ---------------------------*/
  129. virtual TextSmartPage
  130.  &setPageLabel   ( const IString& pageLabel),
  131.  &setPageText    ( const IString& pageText),
  132.  &setPageTextFile( const IString& pageTextFile);
  133.  
  134. virtual IString
  135.   pageLabel      ( ) const,
  136.   pageText       ( ) const,
  137.   pageTextFile   ( ) const;
  138.  
  139. private:
  140. /*------------------------------ Hidden Members ----------------------*/
  141.   TextSmartPage ( const TextSmartPage& );
  142. TextSmartPage
  143.  &operator=   ( const TextSmartPage& );
  144. IString
  145.  fPageLabel,
  146.  fPageText,
  147.  fPageTextFile;
  148. IMultiCellCanvas
  149.  *fMultiCellCanvas;
  150. };
  151.  
  152. // SingleChoiceSmartPage is a SmartPage that adds
  153. // the ability for the page to display multiple
  154. // choices and overrides "currentChoice" to
  155. // enable the SmartGuide to pick different paths.
  156. //
  157. class SingleChoiceSmartPage : public TextSmartPage
  158. {
  159. typedef TextSmartPage
  160.   Inherited;
  161. public:
  162.  
  163.  
  164. /*------------------------------- Constructors -----------------------*/
  165.   SingleChoiceSmartPage  ( )
  166.    : fSmartChoiceList  ( 0 ),
  167.      fNumberOfChoices  ( 0 ),
  168.      fSelectedChoice   ( 0 ),
  169.      fSelectHandler    ( 0 ),
  170.      fSelectionWindow  ( 0 )
  171.     {}
  172.  
  173. /*----------------------------- Panel Creation -----------------------*/
  174. virtual ISize
  175.   minimumSize     ( ) const;
  176.  
  177. virtual IWindow*
  178.   createAndOrphanPage ( IWindow*          parent,
  179.                         IWindow*          owner,
  180.                         const IRectangle& initialRect);
  181.  
  182. /*------------------------- Navigation and Choice --------------------*/
  183. virtual SingleChoiceSmartPage
  184.  &addChoice ( const IString&  choiceText,
  185.               unsigned long   helpId = 0 );
  186.  
  187. virtual SingleChoiceSmartPage
  188.  &setSelectedChoice   ( unsigned long choiceIndex);
  189.  
  190. virtual unsigned long
  191.   currentChoice       ( ) const;
  192.  
  193. virtual IString
  194.   choiceTextAtIndex   ( unsigned long index);
  195.  
  196. unsigned long
  197.   numberOfChoices     ( ) const;
  198.  
  199. virtual Boolean
  200.   isOKToClose    ( IString& closeErrorIfFalse ) const;
  201.  
  202. /*------------------------------ Displaying Help ---------------------*/
  203. // Override the following function to return a choice sensitive
  204. // help id. You specify the help id on the constructor.
  205. virtual unsigned long
  206.   helpId    ( ) const;
  207.  
  208. private:
  209. /*------------------------------ Hidden Members ----------------------*/
  210.   SingleChoiceSmartPage ( const SingleChoiceSmartPage& );
  211. SingleChoiceSmartPage
  212.  &operator=   ( const SingleChoiceSmartPage& );
  213.  
  214. SmartChoiceList
  215.  *fSmartChoiceList;
  216. unsigned long
  217.   fNumberOfChoices;
  218. unsigned long
  219.   fSelectedChoice;
  220. SmartChoiceSelectHandler
  221.  *fSelectHandler;
  222. IWindow
  223.  *fSelectionWindow;
  224. };
  225.  
  226. // SmartGuide contains all smart pages and controls:
  227. // 1) Telling a page to create its windows
  228. // 2) Navigation through the pages of the guide
  229. // 3) Cancel and Close requests
  230. //
  231. class SmartGuide
  232. {
  233. public:
  234. class Cursor;
  235.  
  236.  
  237. /*------------------------------- Constructors -----------------------*/
  238.   SmartGuide    ( const IString&  guideName);
  239.  
  240.  
  241.  
  242. /*------------------------- Navigation and Choice --------------------*/
  243. unsigned long
  244.   addPage  ( SmartPage*     smartPage,
  245.              unsigned long  referencePageHandle=0);
  246. virtual Boolean
  247.   isOKToClose    ( IString& closeErrorIfFalse );
  248.  
  249. /*----------------------------- Panel Creation -----------------------*/
  250. virtual SmartGuide
  251.  &show           ( ),
  252.  &refreshPages   ( );
  253.  
  254. virtual ISize
  255.   newPageSize    ( ) const;
  256.  
  257. /*------------------------------ Displaying Help ---------------------*/
  258. virtual SmartGuide
  259.  &setHelpWindow     ( IHelpWindow& helpWindow );
  260.  
  261.  
  262. /*------------------------------ Cursor Functions --------------------*/
  263. enum IterationOrder
  264. {
  265.    selectedOrder,
  266.    topDown,
  267.    bottomUp
  268. };
  269.  
  270. SmartPage
  271.  *pageAtLocation ( Cursor& cursor) const;
  272.  
  273.   class Cursor {
  274.   public :
  275.   /*------------------------------- Constructors -----------------------*/
  276.     Cursor  ( SmartGuide&                 smartGuide,
  277.               SmartGuide::IterationOrder  order =
  278.                                            SmartGuide::selectedOrder);
  279.  
  280.   virtual
  281.     ~Cursor ( );
  282.  
  283.   /*------------------------------ Page Iteration ----------------------*/
  284.   virtual Boolean
  285.     setToFirst    ( ),
  286.     setToNext     ( ),
  287.     setToPrevious ( ),
  288.     setToLast     ( ),
  289.     isValid       ( ) const;
  290.  
  291.   void
  292.     setCurrent ( unsigned long smartPageHandle );
  293.  
  294.   private:
  295.   /*----------------------------- Hidden Members -----------------------*/
  296.   Cursor       ( const Cursor& cursor );
  297.   Cursor
  298.    &operator=  ( const Cursor& cursor );
  299.  
  300.   /*--------------------------------- Private --------------------------*/
  301.   void
  302.    *fTreeCursor;
  303.   SmartGuide
  304.    &fSmartGuide;
  305.   SmartGuide::IterationOrder
  306.     fOrder;
  307.   friend class SmartGuide;
  308.   };
  309.  
  310.  
  311. /*------------------------------ Debug Functions ---------------------*/
  312. virtual IString
  313.   asString       ( ) const,
  314.   asDebugInfo    ( ) const;
  315.  
  316. protected:
  317. /*------------------------------ Callback Functions ------------------*/
  318. virtual Boolean
  319.   handlePageSelect  ( IPageSelectEvent& event ),
  320.   handleBack        ( ),
  321.   handleNext        ( ),
  322.   handleCancel      ( ),
  323.   handleDone        ( ),   // Open can of worms at the moment
  324.   handleHelp        ( ),
  325.   handleRefresh     ( );
  326.  
  327.  
  328. SmartPageInfo
  329.  *pageInfoAtLocation ( Cursor& cursor) const,
  330.  *pageInfoWithHandle ( const IPageHandle& pageHandle) const;
  331.  
  332.  
  333.  
  334. private:
  335. /*----------------------------- Hidden Members -------------------------*/
  336. SmartGuide       ( const SmartGuide& );
  337. SmartGuide
  338.  &operator=  ( const SmartGuide&);
  339.  
  340. /*--------------------------------- Private ----------------------------*/
  341. // Consider moving the following to a private data class.
  342. IString
  343.   fGuideName;
  344. SmartTree
  345.  *fSmartTree;
  346. SmartPageInfoList
  347.  *fPageInfoList;
  348. SmartPageInfo
  349.  *fCurrentPageInfo;
  350. IFrameWindow
  351.  *fFrameWindow;
  352. INotebook
  353.  *fNotebook;
  354. IPushButton
  355.  *fBackButton,
  356.  *fNextButton,
  357.  *fCancelButton,
  358.  *fDoneButton,
  359.  *fHelpButton;
  360. SmartGuidePageHandler
  361.  *fPageHandler;
  362. SmartGuideCommandHandler
  363.  *fCommandHandler;
  364. ISize
  365.  fLastPageSize;
  366. IHelpWindow
  367.  *fHelpWindow;
  368. friend class SmartGuidePageHandler;
  369. friend class SmartGuideCommandHandler;
  370. friend class Cursor;
  371. };
  372.  
  373. // Constants for Panels
  374. #define WID_TEXTCANVAS    100
  375. #define WID_TEXTLABEL     101
  376. #define WID_TEXTTEXT      102
  377. #define WID_SELECTRADIO   103  // 5 numbers Required
  378. #define WID_CLIENTCANVAS  110
  379. #define WID_SELECTLISTBOX 111
  380. #define WID_SELECTCANVAS  112
  381.  
  382. #define WID_BUTTONS 200
  383. #define WID_BACK    201
  384. #define WID_NEXT    202
  385. #define WID_HELP    203
  386. #define WID_CANCEL  204
  387. #define WID_DONE    205
  388. #define CID_REFRESH 206
  389.  
  390. #endif // _SMRTGUID_
  391.