home *** CD-ROM | disk | FTP | other *** search
/ PC Direct 1998 August / PC Direct August 1998.iso / S / powerj / Product / hpp.z / dtobject.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-25  |  23.4 KB  |  683 lines

  1. #ifndef _DTOBJECT_HPP
  2. #define _DTOBJECT_HPP
  3.  
  4. #include "dtobase.hpp"
  5.  
  6. #pragma warning 849 9
  7.  
  8. class SaveItem;
  9. class SaveSource;
  10. class SaveBlock;
  11.  
  12. //
  13. // MMFileGenerationParms
  14. //
  15. //    Parameters to accompany the GenFileFragment call.  Avoid
  16. //    modifying this structure, instead declare a derived version.
  17.  
  18. struct MMFileGenerationParms {
  19.     WFilePath   path;
  20.  
  21.     virtual ~MMFileGenerationParms() {}
  22. };
  23.  
  24. struct MMCodeGenerationParms {
  25.     MMCodeGeneration    tag;            // redundancy
  26.     WString             owning_form;
  27.     WString             form_res_name;
  28.     WBool               isDialog;
  29.     WULong              userData;
  30.     WString             fdxFields;
  31.  
  32.     virtual ~MMCodeGenerationParms() {}
  33. };
  34.  
  35. struct MMFDXPropertyData {
  36.     WString             property;
  37.     WString             fieldName;
  38.     WString             onValue;
  39. };
  40.  
  41. class MMFDXPropertyVect : public WArray< MMFDXPropertyData > {
  42.     public:
  43. };
  44.  
  45. class METAEXPORTCLASSDEF DTObjectBase : public DTObject
  46. {
  47.     public:
  48.         virtual                 ~DTObjectBase() = 0;
  49.         VEXPORT WBool           operator== ( const DTObject & ) const;
  50.  
  51.     public:
  52.  
  53.         /*************************************************************
  54.          * WClass / Awt specific behaviour
  55.          *************************************************************/
  56.  
  57.         //
  58.         // GenFileFragment
  59.         //
  60.         //    Generate a file-level fragment of code.
  61.  
  62.         virtual void GenFileFragment( MMFileFragment fg, WStringList &,
  63.                                         MMFileGenerationParms * parms ) const;
  64.  
  65.  
  66.         /*************************************************************
  67.          * Common Behaviour
  68.          *************************************************************/
  69.  
  70.         //
  71.         // Meta
  72.         //
  73.         //    The Meta- object instance that is associated
  74.         //    with this DT- object
  75.  
  76.         VEXPORT const MetaObject *GetMeta() const;
  77.  
  78.  
  79.         //
  80.         // Reference Card Meta
  81.         //    The Meta-object that is used to provide reference
  82.         //    card information.  The default implentation returns GetMeta()
  83.  
  84.         VEXPORT const MetaObject *  GetRefCardMeta() const;
  85.  
  86.         //
  87.         // Name
  88.         //
  89.         //    The variable used in the user's code to represent this
  90.         //    object (eg. cb_1).  Although there is a default implementation,
  91.         //    you may wish to override this to perform an action when the
  92.         //    name changes (eg. change names of all child objects).
  93.  
  94.         virtual void            DTSetName( const WString & name );
  95.         virtual WString         DTGetName() const ;
  96.         virtual WString         DTGetClassName() const;
  97.  
  98.         //
  99.         // ClassDefinition
  100.         //
  101.         //    The class name used to implement a component in code.
  102.         //    This lets the user specify a different class than the
  103.         //    default.
  104.  
  105.         virtual void            SetClassDefinition( const WString & );
  106.         virtual WString         GetClassDefinition() const;
  107.  
  108.         //
  109.         // ClassIncludes
  110.         //
  111.         //    Extra header files this compnonent requires (specified
  112.         //    by the user.  For use with ClassDefinition.
  113.  
  114.         virtual void            SetClassIncludes( const WString & );
  115.         virtual WString         GetClassIncludes() const;
  116.  
  117.         //
  118.         // WImplementation
  119.         //
  120.         //    Each DT- object must have an associated WObject that
  121.         //    represents it on the design-time form.  This is not
  122.         //    required to be a WWindow-derived class, but that is the
  123.         //    case that has been tested most -- only WOleObjects are
  124.         //    an exception.
  125.  
  126.         VEXPORT WObject *       GetWImplementation() const;
  127.         VEXPORT void            SetWImplementation( WObject * wobj,
  128.                                                     WBool deleteOld=TRUE );
  129.  
  130.         //
  131.         // ConcreteInstance
  132.         //
  133.         //    Return the concrete instance (the aggregated object)
  134.  
  135.         virtual const DTObject *GetConcreteImplementation() const;
  136.         virtual DTObject *      GetConcreteImplementation();
  137.  
  138.         //
  139.         // Window
  140.         //
  141.         //    If there is a WWindow implementing the design-time
  142.         //    behaviour of the object, get and return it.  Otherwise,
  143.         //    NULL (as for WOleObject).
  144.  
  145.         VEXPORT WWindow *       GetWindow() const;
  146.  
  147.  
  148.         //
  149.         // DTGetParent
  150.         //
  151.         //    The parent window if there is a window.
  152.  
  153.         VEXPORT WWindow *       DTGetParent() const;
  154.  
  155.         //
  156.         // ResourceID
  157.         //
  158.         //    The id of the control in the .res file
  159.  
  160.         VEXPORT void            SetResourceID( long id );
  161.         VEXPORT long            GetResourceID() const;
  162.  
  163.         //
  164.         // TabIndex
  165.         //
  166.         //    Tabbing order of control.  Controls are emitted into
  167.         //    the resource file in tab index order.
  168.  
  169.         VEXPORT void            SetTabIndex( long idx );
  170.         VEXPORT long            GetTabIndex() const;
  171.  
  172.  
  173.         //
  174.         // CodeBlockList
  175.         //
  176.         //    A list of event code block's (functions) associated with the
  177.         //    object.  The name is unfortunate, since only events are
  178.         //    stored in this list.
  179.         //
  180.  
  181.         VEXPORT const DTCodeBlockList & GetCodeBlockList() const;
  182.         VEXPORT DTCodeBlockList &       GetCodeBlockList();
  183.  
  184.         VEXPORT WInt                    GetAllCodeBlockLists( DTCodeBlockListList & );
  185.  
  186.         //
  187.         // RemoveEvent
  188.         //
  189.         //    Remove a code block from the list and remove any
  190.         //    other pointers to it (ie. from object inspector).
  191.  
  192.         VEXPORT DTCodeBlockBase *       RemoveEvent( DTCodeBlockBase * );
  193.  
  194.         //
  195.         // FindEvent
  196.         //
  197.         //    Find a code block that has already been added to
  198.         //    this object.
  199.  
  200.         VEXPORT DTCodeBlockBase *       FindEvent( const char * ) const;
  201.  
  202.         //
  203.         // AllowEvent
  204.         //
  205.         //    Allow the given event to be included in the event inpector
  206.         //    for this object.
  207.  
  208.         VEXPORT WBool                   AllowEvent( const MMEvent * ) const;
  209.  
  210.         //
  211.         // UserFunctionVect
  212.         //    A vector of user functions associated with the object.
  213.         //
  214.  
  215.         VEXPORT const DTUserFunctionVect &  GetUserFunctionVect() const;
  216.         VEXPORT DTUserFunctionVect &        GetUserFunctionVect();
  217.         VEXPORT void                        AddUserFunction( DTCodeBlockBase * );
  218.         VEXPORT void                        RemoveUserFunction( DTCodeBlockBase * );
  219.         VEXPORT DTCodeBlockBase *           FindUserFunction( const char * );
  220.  
  221.         //
  222.         // CMCodeBlock
  223.         //
  224.         //    Special class code blocks.  These don't appear in the
  225.         //    UserFunctionVect.
  226.         //
  227.         VEXPORT DTCodeBlockBase *   GetCMCodeBlock( WULong b ) const;
  228.         VEXPORT void                SetCMCodeBlock( WULong b, DTCodeBlockBase * );
  229.  
  230.         //
  231.         // Form, DTForm
  232.         //
  233.         //    The FormEdit associated with this object; the first
  234.         //    form is only useful from within Optima code; the second,
  235.         //    mainly from CompDLL.  SetForm is called by Optima when
  236.         //    it instantiates the object.
  237.  
  238.         VEXPORT FormEdit *      GetForm() const;
  239.         VEXPORT DTFormEditBase *GetDTForm() const;
  240.         VEXPORT void            SetForm( DTFormEditBase * );
  241.  
  242.         //
  243.         // Child
  244.         //
  245.         //    The DTObject Children for this DTObject.  DTObjects
  246.         //    may now own other DTObjects.
  247.  
  248.         VEXPORT int             GetChildCount() const;
  249.         VEXPORT DTObject *      GetChild( int index ) const;
  250.         VEXPORT WBool           AddChild( DTObject *, int after = -1 );
  251.         VEXPORT WBool           RemoveChild( DTObject * );
  252.         VEXPORT DTObject *      GetParent() const;
  253.  
  254.         //
  255.         // Style
  256.         //
  257.         //    The Windows style property of the associated Window.
  258.         //    This doesn't necessarily match GetWindow()->GetStyle()
  259.         //    because some styles are deferred until run-time (such
  260.         //    as WSVisible).
  261.  
  262.         VEXPORT WStyle          GetStyle() const;
  263.         VEXPORT WBool           SetStyle( WStyle stl, WBool clone=FALSE );
  264.  
  265.         //
  266.         // DefaultStyle
  267.         //
  268.         //    The style with which new instances are created.  Default
  269.         //    implementation returns GetWindow()->GetDefaultStyle().
  270.  
  271.         virtual WStyle          GetDefaultStyle() const;
  272.  
  273.         //
  274.         // ExtendedStyle
  275.         //
  276.         //    The ExtendedStyle property of the window nature.
  277.  
  278.         virtual WStyle          GetExtendedStyle() const;
  279.         virtual WBool           SetExtendedStyle( WStyle style, WBool clone=FALSE );
  280.  
  281.         //
  282.         // DefaultExtendedStyle
  283.         //
  284.         //    See DefaultStyle
  285.  
  286.         virtual WStyle          GetDefaultExtendedStyle() const;
  287.  
  288.         //
  289.         // InternalStyle
  290.         //
  291.         //    The styles that are stored internally.
  292.  
  293.         virtual void            SetInternalStyle( WStyle s, WStyle ex );
  294.  
  295.         //
  296.         // Visible
  297.         //
  298.         //    The object is currently visible.
  299.  
  300.         virtual WBool           GetVisible();
  301.         virtual WBool           SetVisible( WBool visible );
  302.  
  303.         //
  304.         // Create
  305.         //
  306.         //    Call Create on the windowed object.
  307.         //
  308.         virtual WBool           Create( WWindow * parent, const WRect & r,
  309.                                         const WChar * text, WStyle style,
  310.                                         WStyle exStyle, void * data = NULL,
  311.                                         WBool isLoading = FALSE );
  312.  
  313.         //
  314.         // NonVisual
  315.         //
  316.         //    NonVisual objects are represented by a picture box at
  317.         //    design time -- eg. WTimer, WMessageBox, WFileDialog.
  318.  
  319.         VEXPORT WBool           GetNonVisual() const;
  320.  
  321.         // DTInfo
  322.         //
  323.         //    Each object can have information that is not handled by
  324.         //    the general framework.  For instance, listboxes store their
  325.         //    lines separately.  HasDTInfo should return true if you want
  326.         //    to store object-specific information, then the SaveDTInfo
  327.         //    and LoadDTInfo functions will be called.
  328.  
  329.         virtual WBool           HasDTInfo();
  330.         virtual WBool           SaveDTInfo( SaveSource & );
  331.         virtual WBool           LoadDTInfo( SaveBlock *, WBool beforeCreate );
  332.  
  333.         //
  334.         // CreateEventPopupMenu
  335.         //
  336.         //    Popupulate a popup menu with the events that are deemed
  337.         //    useful ("hot" events) as well as events with code.  There
  338.         //    is a default behaviour which is overriden for Ole objects.
  339.  
  340.         virtual WBool           CreateEventPopupMenu( WPopupMenu * popup );
  341.  
  342.         //
  343.         // IsResizeable
  344.         //
  345.         //    IsResizeable allows non-visual objects and Ole objects to
  346.         //    deny resizing (can change after created
  347.  
  348.         virtual WBool           GetIsResizeable();
  349.  
  350.         //
  351.         // IsMoveable
  352.         //
  353.         //    IsMoveable allows objects to deny being moved
  354.         //    for example if they are participating in a layout manager
  355.         //    or if they are a tab control page.
  356.  
  357.         virtual WBool           GetIsMoveable();
  358.  
  359.  
  360.         //
  361.         // Hollow
  362.         //
  363.         //    GroupBoxes are treated as "Hollow" controls in that when
  364.         //    they are moved, contained controls are also moved.  Also,
  365.         //    hollow controls are not active except for a border around
  366.         //    the outside.  HollowRect is the rectangle in the center
  367.         //    that doesn't activate the object.
  368.  
  369.         virtual WBool           GetIsHollow();          // groupbox
  370.         virtual WRect           GetHollowRect();        // interior of groupbox
  371.  
  372.         //
  373.         // DTPopupMenu
  374.         //    The popup menu associated with a WWindow.  NOT the
  375.         //    popup menu that shows up at design-time.
  376.         //    [ITB:06/4] expect this will move to DTW.
  377.  
  378.         VEXPORT WBool           SetDTPopupMenu( DTObject * );
  379.         VEXPORT DTObject *      GetDTPopupMenu() const;
  380.  
  381.         //
  382.         // AmendPopup 
  383.         //
  384.         //    Override this function to modify the design-time context
  385.         //    popup.  "before" is true before the popup is displayed,
  386.         //    false afterwards.  Make sure you clean up any menu items
  387.         //    you add or they will remain for other objects as well.
  388.         //
  389.         virtual void            AmendPopup( WPopupMenu *, WBool before );
  390.  
  391.         //
  392.         // IsValidChild
  393.         //
  394.         //    Returns true if obj is allowed as a child of this
  395.         //    DTObject.  errMsg is filled in with details about
  396.         //    why it isn't allowed.
  397.         virtual WBool           IsValidChild(
  398.                                         const MetaObject *obj,
  399.                                         WString &errMsg ) const;
  400.  
  401.         //
  402.         // IsValidContainer
  403.         //
  404.         //    Returns true if obj is allowed as a container for this
  405.         //    DTObject.  errMsg is filled in with details about
  406.         //    about why it isn't allowed.
  407.         virtual WBool           IsValidContainer(
  408.                                         const DTObject *obj,
  409.                                         WString &errMsg ) const;
  410.  
  411.         //
  412.         // SetEventHandler
  413.         //
  414.         //    Set an event handler on the W-Implementation object.
  415.  
  416.         virtual WBool           DTSetEventHandler( WEventID id,
  417.                                                  WObject * object,
  418.                                                  WEventHandler handler,
  419.                                                  void *userdata=NULL );
  420.  
  421.         //
  422.         // RemoveEventHandler
  423.         //
  424.         //    Remove an event handler on the W-Implementation object.
  425.  
  426.         virtual WBool           DTRemoveEventHandler( WEventID id,
  427.                                                  WObject * object,
  428.                                                  WEventHandler handler );
  429.  
  430.         //
  431.         // CallEventHandler
  432.         //
  433.         //    Call an event handler on the W-Implementation object.
  434.  
  435.         virtual WBool           DTCallEventHandler( WEventID id,
  436.                                                 WObject * object,
  437.                                                 WEventData * eventData=NULL,
  438.                                                 WLong * retval=NULL,
  439.                                                 WInt indexToStartAt=0 ) const;
  440.  
  441.         //
  442.         // DTIInterface
  443.         //
  444.         //    Get DTInterface with a particular name. This virtual
  445.         //    function is overridden once by derived classes that use
  446.         //    DTInterfaces
  447.  
  448.         virtual DTIInterface *  GetDTIInterface( const WChar * ifname );
  449.  
  450.         //
  451.         // Protected
  452.         //
  453.         //    This property controls the behaviour of a design time
  454.         //    object.  Protected objects are:
  455.         //              -  not saved or loaded
  456.         //              -  cannot be deleted directly by the user
  457.  
  458.         virtual WBool GetProtected() const;
  459.  
  460.  
  461.         /*************************************************************
  462.          * Property Editting
  463.          *************************************************************/
  464.  
  465.         //
  466.         // EditProperties
  467.         //
  468.         //    Display a property sheet window.  Depending on "child",
  469.         //    the property sheet may be a child (as in object view) or
  470.         //    a popup dialog (normal property sheets).
  471.  
  472.         VEXPORT WBool                   EditProperties( WWindow *,
  473.                                                         WBool child = FALSE );
  474.         //
  475.         // ClearPropertyEditor
  476.         //
  477.         //    Remove and destroy any open property editor for this object.
  478.  
  479.         VEXPORT void                    ClearPropertyEditor( WBool deleteNow = FALSE );
  480.  
  481.         //
  482.         // UpdatePropertyRect
  483.         //
  484.         //    Inform any open property editors to update the position
  485.         //    property since this object has been moved
  486.  
  487.         virtual WBool                   UpdatePropertyRect();
  488.  
  489.         //
  490.         // PropDialog
  491.         //
  492.         //    Get a pointer to the open property editor or return NULL.
  493.  
  494.         VEXPORT MTPropertyDialog *      GetPropDialog();
  495.  
  496.         //
  497.         // HasProperty
  498.         //
  499.         //    Return TRUE if this object has a property named "name".
  500.  
  501.         VEXPORT WBool                   HasProperty( const WString & name ) const;
  502.  
  503.         //
  504.         // Property
  505.         //
  506.         //    Get or set a property with various formats.  
  507.         //    The additional formats are provided for convenience only.
  508.  
  509.         VEXPORT WString                 GetProperty( const WString & name, DT_TextifyV t = 1 ) const;
  510.         VEXPORT WBool                   GetPropertyBool( const WString & name ) const;
  511.         VEXPORT WLong                   GetPropertyEnum( const WString & name ) const;
  512.         VEXPORT WRect                   GetPropertyRect( const WString & name ) const;
  513.         VEXPORT WLong                   GetPropertyLong( const WString & name ) const;
  514.         VEXPORT WBool                   SetProperty( const WString & name, const WString & val, DT_TextifyV t = 1 );
  515.         VEXPORT WBool                   SetPropertyBool( const WString & name, WBool val );
  516.         VEXPORT void                    SetPropertyEnum( const WString & name, WLong val );
  517.         VEXPORT void                    SetPropertyRect( const WString & name, const WRect & r );
  518.         VEXPORT void                    SetPropertyLong( const WString & name, WLong r );
  519.  
  520.         virtual void                    PropertyChanged( const WString & name );
  521.         virtual void                    SetAllowUpdates( WBool allow, WBool doPropertyChanged = FALSE );
  522.         virtual WBool                   GetAllowUpdates() const;
  523.  
  524.         //
  525.         // DetachEditor
  526.         //
  527.         //    Virtual call to detach an editor mini application if necessary.
  528.  
  529.         virtual void                    DetachEditor();
  530.  
  531.  
  532.  
  533.         /*************************************************************
  534.          * Code Generation
  535.          *************************************************************/
  536.  
  537.         //
  538.         // ObjectPrefix
  539.         //
  540.         //    Get the prefix used when accessing member functions of the
  541.         //    object -- eg. "cb_1->"
  542.  
  543.         VEXPORT WString GetObjectPrefix() const;
  544.  
  545.         //
  546.         // GenName
  547.         //    Generate a variable name by number, eg. cb_1 if id == 1
  548.         //    The string is an out parameter.
  549.  
  550.         VEXPORT void GenName( WUInt id, WString & ) const;
  551.  
  552.         //
  553.         // GenClassName
  554.         //
  555.         //    Generate the name of the C++ or Java class that implements
  556.         //    this object.
  557.  
  558.         VEXPORT void GenClassName( WString & ) const;
  559.  
  560.         //
  561.         // GenResourceName
  562.         //
  563.         //    Generate the resource ID from the object name.  This is
  564.         //    usually of the form ID_name.
  565.  
  566.         VEXPORT void GenResourceName( WString & ) const;
  567.  
  568.         //
  569.         // GenResourceStyles
  570.         //
  571.         //     Generate the .rc file styles that will be used; the first
  572.         //     parameter is a string list filled with styles, the second
  573.         //     is filled with extended styles
  574.  
  575.         VEXPORT void GenResourceStyles( WStringList &, WStringList & ) const;
  576.  
  577.         //
  578.         // GenEventObjectName
  579.         //
  580.         //     Generate the object name for an event. The name is built
  581.         // by recursing the DTObject hierarchy and prepending the names
  582.         // of the DTObjects
  583.  
  584.         VEXPORT void GenEventObjectName( WString & ) const;
  585.  
  586.         //
  587.         // RequiredIncludes
  588.         //
  589.         //    Fill in a list of required include files.
  590.  
  591.         virtual void GetRequiredIncludes( WStringList & includes ) const;
  592.  
  593.         //
  594.         // RequiredBaseClasses
  595.         //
  596.         //    Fill in a list of required base classes to add to the form
  597.  
  598.         virtual void GetRequiredBaseClasses( WStringList & bases ) const;
  599.  
  600.         //
  601.         // GenerateCode [new]
  602.         //
  603.         //    Generate a fragment of code for a component.
  604.         //    The "cg" parameter indicates which scrap of code to generate.
  605.  
  606.         void GenerateCode( MMCodeGeneration, ostream &, MMCodeGenerationParms & );
  607.  
  608.         //
  609.         // FindStyle
  610.         //
  611.         //     Find a style of a given name within the object
  612.  
  613.         VEXPORT const MMStyle *     FindStyle( const char * ) const;
  614.  
  615.         //
  616.         // FindProperty
  617.         //
  618.         //     Find a property of a given name within an object
  619.  
  620.         VEXPORT const MMProperty *  FindProperty( const char * ) const;
  621.  
  622.         virtual WString         GetMappedValue( WUInt i ) const;
  623.         virtual void            SetMappedValue( WUInt i, const WString & s );
  624.  
  625.         /*************************************************************
  626.          * Form Data Exchange [move to DTWObject]
  627.          *************************************************************/
  628.     public:
  629.         virtual WBool           GetDDXEnabled() const;
  630.         virtual void            SetDDXEnabled( WBool e );
  631.  
  632.         virtual WString         GetDDXFieldName() const;
  633.         virtual void            SetDDXFieldName( const WString & );
  634.  
  635.         virtual WString         GetDDXFieldType() const;
  636.         virtual void            SetDDXFieldType( const WString & );
  637.  
  638.         virtual WString         GetDDXModifiedFieldName() const;
  639.         virtual void            SetDDXModifiedFieldName( const WString & );
  640.  
  641.         virtual void            EscapeCString( WString &, const WString & ) const;
  642.  
  643.         /*************************************************************
  644.          * Implementation
  645.          *************************************************************/
  646.  
  647.     public:
  648.         void                    FillInspectProperties( MTIPropertyList & ) const;
  649.         void                    FillInspectEvents( MTIEventList & ) const;
  650.         WBool                   HandleEventClick( WMenuItem *, WEventData * );
  651.         WBool                   HandleWizardMenuClick( WMenuItem *, WEventData * );
  652.         virtual DTObjectImp *   GetImplementation();
  653.  
  654.         MMFDXPropertyVect       GetFDXProperties() const;
  655.         void                    SetFDXProperties( const MMFDXPropertyVect & );
  656.         WString                 GetFDXFieldName( const MMProperty * prop ) const;
  657.  
  658.     protected:
  659.         DTObjectBase();
  660.  
  661.         void                    SetWindow( WWindow * );
  662.         void                    SetMeta( const MetaObject * );
  663.  
  664.         WString                 TabTo( const WString & str, unsigned col ) const;
  665.  
  666.         WBool                   saveDTProperties( SaveSource & );
  667.         WBool                   loadOneDTProperty( SaveItem * );
  668.  
  669.         /*************************************************************
  670.          * Un-Implemented functions
  671.          *************************************************************/
  672.  
  673.     private:
  674.         DTObjectBase( const DTObjectImp & );
  675.         DTObjectBase &          operator=( const DTObjectBase & );
  676.  
  677.  
  678.     protected:
  679.         DTObjectImp *           _imp;
  680. };
  681.  
  682. #endif // _DTOBJECT_HPP
  683.