home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / ui / dialog.h < prev    next >
C/C++ Source or Header  |  1995-03-28  |  5KB  |  165 lines

  1.  
  2. #ifndef _dialog_h_
  3. #define _dialog_h_
  4.  
  5.  
  6.  
  7.  
  8.  
  9. /*
  10.  *
  11.  *          Copyright (C) 1994, M. A. Sridhar
  12.  *  
  13.  *
  14.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  15.  *     to copy, modify or distribute this software  as you see fit,
  16.  *     and to use  it  for  any  purpose, provided   this copyright
  17.  *     notice and the following   disclaimer are included  with all
  18.  *     copies.
  19.  *
  20.  *                        DISCLAIMER
  21.  *
  22.  *     The author makes no warranties, either expressed or implied,
  23.  *     with respect  to  this  software, its  quality, performance,
  24.  *     merchantability, or fitness for any particular purpose. This
  25.  *     software is distributed  AS IS.  The  user of this  software
  26.  *     assumes all risks  as to its quality  and performance. In no
  27.  *     event shall the author be liable for any direct, indirect or
  28.  *     consequential damages, even if the  author has been  advised
  29.  *     as to the possibility of such damages.
  30.  *
  31.  */
  32.  
  33.  
  34.  
  35. // Authors:   M. A. Sridhar
  36. //            N. Bhowmik
  37.  
  38.  
  39.  
  40. // The behavior of the Dialog is an enhancement of that of the Composite,
  41. // in that that Dialog supports the notion of "dialog events" on certain
  42. // designated children. A Dialog is created with a set of "dialog events"
  43. // that are significant to it, and remembers the most recent dialog event
  44. // that occurred on it. The
  45. // types of dialog events, and the identities of the children they must occur
  46. // on, can be specified when the dialog is constructed. 
  47. //
  48. // The Dialog also includes the method ExecuteModal, which causes the
  49. // Dialog to run modally until one of the dialog events occurs on the
  50. // corresponding child. If this
  51. // method is not invoked, the Dialog is modeless.
  52.  
  53.  
  54.  
  55. #if defined(__GNUC__)
  56. #pragma interface
  57. #endif
  58.  
  59.  
  60. #include "base/objset.h"
  61. #include "ui/composit.h"
  62.  
  63. struct UI_DialogEventDescriptor {
  64.     UI_ViewID  id;
  65.     UI_EventType type;
  66. };
  67.                  
  68. class CL_EXPORT UI_Dialog : public UI_CompositeVObject {
  69.  
  70. public:
  71.  
  72.     // -------------------- Construction and destruction ------------------
  73.  
  74.     UI_Dialog (UI_CompositeVObject* parent, UI_ViewDescriptor* children,
  75.                const UI_Rectangle& shape,
  76.                UI_DialogEventDescriptor* events = NULL,
  77.                long id = -1);
  78.     // Constructor: build a dialog ``manually'', by specifying the parent and
  79.     // shape, all the children of the dialog (in the {\tt children} array), and
  80.     // the dialog events for this Dialog. Both {\tt children}
  81.     // and {\tt events} must point to arrays of elements whose
  82.     // last element has id <= 0. If the {\tt children} pointer is NULL, it is
  83.     // assumed that any events originating from either of children with id's
  84.     // UI_IDOK and UI_IDCANCEL are the dialog events.
  85.  
  86.  
  87. #if defined(__MS_WINDOWS__)
  88.     UI_Dialog(UI_CompositeVObject* parent, const char* resourceName,
  89.                UI_DialogEventDescriptor* events = NULL,
  90.                UI_ViewID id = -1);
  91.     // Resource-based construction (only under MS-Windows).
  92.  
  93. #endif
  94.     
  95.     // ---------------------- Dialog events ----------------------------
  96.     virtual bool AddDialogEvent    (UI_ViewID id, UI_EventType type);
  97.     // Add to the set of dialog events recognized by this Dialog.
  98.  
  99.     virtual bool RemoveDialogEvent (UI_ViewID id, UI_EventType type);
  100.     // Remove a dialog event. Return FALSE if no such dialog event was
  101.     // recognized by this Dialog.
  102.  
  103.     UI_DialogEventDescriptor LastDialogEvent () { return _lastEvent;};
  104.     // Return the most recent dialog event. If this event contains an id of
  105.     // -1, then no dialog events have occurred yet.
  106.     
  107.     // ---------------------- Modal execution ----------------------------
  108.     
  109.     UI_DialogEventDescriptor ExecuteModal ();
  110.     // Execute the given dialog modally until a dialog event occurs, and
  111.     // return that event.
  112.  
  113.     bool InModalState ();
  114.     // Are we currently running modally?
  115.     
  116.     // ---------------- Basic methods ---------------------------------
  117.     
  118.     const char* ClassName() const {return "UI_Dialog";};
  119.  
  120.     // ------------------- End public protocol -------------------------
  121.  
  122.     
  123. protected:
  124.     virtual bool MakeVisualElement ();
  125.     // Override method inherited from VisualObject.
  126.     
  127.     ~UI_Dialog ();
  128.     // Destructor.
  129.  
  130.     void CloseDown ();
  131.     
  132.     //
  133.     // Instance Variables:
  134.     //
  135.     UI_DialogEventDescriptor    _lastEvent;
  136.     CL_ObjectSet                _dialogEvents;
  137.  
  138. private:
  139.  
  140.     void _Init (UI_DialogEventDescriptor*);
  141.     
  142.     bool EventFilter (CL_Object&, long);
  143.     // The event filter used by the modal event loop.
  144.     
  145.     bool RunFinished (CL_Object&, long);
  146.     // The termination filter used by the modal event loop.
  147.  
  148.     bool _DialogEventOccurred (CL_Object&, long);
  149.     // The event dependent method.
  150.  
  151.     bool                        _closed;
  152.     bool                        _modalState;
  153.     
  154. };
  155.  
  156.  
  157.  
  158. inline bool UI_Dialog::InModalState ()
  159. {
  160.     return _modalState;
  161. }
  162.  
  163.  
  164. #endif
  165.