home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / hpp.z / DTOBASE.HPP < prev    next >
C/C++ Source or Header  |  1996-12-07  |  22KB  |  620 lines

  1. #ifndef _DTOBASE_HPP
  2. #define _DTOBASE_HPP
  3.  
  4. /*************************************************************************
  5.  *
  6.  * DTObject -- Base Design-Time object
  7.  *
  8.  *  DTObject is an abstract base class. Do not add any data members or
  9.  *  non-pure-virtual member functions.
  10.  *
  11.  *  NOTE: if you add methods to DTObject, keep DTUObject synchronized!
  12.  *
  13.  *************************************************************************/
  14.  
  15. #include "mtdef.hpp"
  16.  
  17. class  MetaObject;
  18. class  FormEdit;
  19. class  DTFormEditBase;
  20. class  WStringList;
  21. class  MMStyle;
  22. class  MMProperty;
  23. class  MMEvent;
  24. class  MTPropertyDialog;
  25. class  OleEventDialog;
  26. class  MTIPropertyList;
  27. class  MTIEventList;
  28. class  DTCodeBlockList;
  29. class  DTCodeBlockListList;
  30. class  DTIInterface;
  31. class  SaveSource;
  32. class  SaveBlock;
  33. class  DTCodeBlockBase;
  34. struct DTObjectImp;
  35.  
  36.  
  37. #undef GetForm
  38. #if defined( _UNICODE )
  39.     #define GetForm GetFormW
  40.     #define SetForm SetFormW
  41. #else
  42.     #define GetForm GetFormA
  43.     #define SetForm SetFormA
  44. #endif
  45.  
  46. #define VEXPORT virtual         // don't override these
  47.  
  48. typedef WInt  DT_TextifyV;
  49. typedef WLong MMFileFragment;
  50. typedef WLong MMCodeGeneration;
  51. struct  MMFileGenerationParms;
  52.  
  53. class METAEXPORTCLASSDEF DTObject : public WObject
  54. {
  55.     public:
  56.         virtual WBool           operator== ( const DTObject & ) const = 0;
  57.  
  58.     public:
  59.  
  60.         /*************************************************************
  61.          * Position
  62.          *************************************************************/
  63.  
  64.         //
  65.         // Rectangle
  66.         //
  67.         //    The pixel-based position of the object; optionally, absolute
  68.         //    to the desktop.  
  69.  
  70.         virtual void            DTGetRectangle( WRect & r,
  71.                                                 WBool abs = FALSE ) const = 0;
  72.         virtual void            DTSetRectangle( const WRect & r ) = 0;
  73.  
  74.         //
  75.         // ClientRectangle
  76.         //
  77.         //    Get the client rectangle.  This is mainly used for DTForms.
  78.  
  79.         virtual void            DTGetClientRectangle( WRect & r ) const = 0;
  80.  
  81.         //
  82.         // RCRectangle
  83.         //
  84.         //    The rectangle to use in the .rc file (still in pixel though).
  85.         //    This differs for WComboBox, which gives a .rc file rectangle
  86.         //    of the correct height instead of the design time height.
  87.  
  88.         virtual void            DTGetRCRectangle( WRect & r ) const = 0;
  89.  
  90.         //
  91.         // PixelsToDLU / DLUToPixels
  92.         //
  93.         //    Map between pixels and dialog units (DLU).
  94.  
  95.         virtual WRect           DTMapPixelsToDLU( const WRect & pix ) const = 0;
  96.         virtual WRect           DTMapDLUToPixels( const WRect & dlu ) const = 0;
  97.  
  98.         //
  99.         // BringToTop
  100.         //
  101.         //    Bring the object to the top of the Z- order
  102.  
  103.         virtual void            DTBringToTop() = 0;
  104.  
  105.         //
  106.         // Repaint
  107.         //
  108.         //    Invalidate an object and cause it to be repainted
  109.  
  110.         virtual void            DTRepaint() = 0;
  111.  
  112.         //
  113.         // GenFileFragment
  114.         //
  115.         //    Generate a file-level fragment of code.
  116.  
  117.         virtual void GenFileFragment( MMFileFragment fg, WStringList &,
  118.                                         MMFileGenerationParms * parms ) const = 0;
  119.  
  120.         //
  121.         // GenCode
  122.         //
  123.         //    This function is called from Optima to generate
  124.         //    the source code for an object.  The "cg" parameter
  125.         //    indicates which scrap of code to generate.
  126.  
  127.         virtual void GenCode( MMCodeGeneration cg, WStringList & ) const = 0;
  128.  
  129.         /*************************************************************
  130.          * Common Behaviour
  131.          *************************************************************/
  132.  
  133.         //
  134.         // Meta
  135.         //
  136.         //    The Meta- object instance that is associated
  137.         //    with this DT- object
  138.  
  139.         VEXPORT const MetaObject *  GetMeta() const = 0;
  140.         VEXPORT void                SetMeta( const MetaObject * ) = 0;
  141.  
  142.         //
  143.         // Reference Card Meta
  144.         //    The Meta-object that is used to provide reference
  145.         //    card information.  The default implentation returns GetMeta()
  146.  
  147.         VEXPORT const MetaObject *  GetRefCardMeta() const = 0;
  148.  
  149.         //
  150.         // Name
  151.         //
  152.         //    The variable used in the user's code to represent this
  153.         //    object (eg. cb_1).  Although there is a default implementation,
  154.         //    you may wish to override this to perform an action when the
  155.         //    name changes (eg. change names of all child objects).
  156.  
  157.         virtual void            DTSetName( const WString & name ) = 0;
  158.         virtual WString         DTGetName() const = 0;
  159.  
  160.         //
  161.         // ClassDefinition
  162.         //
  163.         //    The class name used to implement a component in code.
  164.         //    This lets the user specify a different class than the
  165.         //    default.
  166.  
  167.         virtual void            SetClassDefinition( const WString & ) = 0;
  168.         virtual WString         GetClassDefinition() const = 0;
  169.  
  170.         //
  171.         // ClassIncludes
  172.         //
  173.         //    Extra header files this compnonent requires (specified
  174.         //    by the user.  For use with ClassDefinition.
  175.  
  176.         virtual void            SetClassIncludes( const WString & ) = 0;
  177.         virtual WString         GetClassIncludes() const = 0;
  178.  
  179.         //
  180.         // WImplementation
  181.         //
  182.         //    Each DT- object must have an associated WObject that
  183.         //    represents it on the design-time form.  This is not
  184.         //    required to be a WWindow-derived class, but that is the
  185.         //    case that has been tested most -- only WOleObjects are
  186.         //    an exception.
  187.  
  188.         VEXPORT WObject *       GetWImplementation() const = 0;
  189.         VEXPORT void            SetWImplementation( WObject * wobj ) = 0;
  190.  
  191.         //
  192.         // Window
  193.         //
  194.         //    If there is a WWindow implementing the design-time
  195.         //    behaviour of the object, get and return it.  Otherwise,
  196.         //    NULL (as for WOleObject).
  197.  
  198.         VEXPORT WWindow *       GetWindow() const = 0;
  199.  
  200.  
  201.         //
  202.         // DTGetParent
  203.         //
  204.         //    The parent window if there is a window.
  205.  
  206.         VEXPORT WWindow *       DTGetParent() const = 0;
  207.  
  208.         //
  209.         // ResourceID
  210.         //
  211.         //    The id of the control in the .res file
  212.  
  213.         VEXPORT void            SetResourceID( long id ) = 0;
  214.         VEXPORT long            GetResourceID() const = 0;
  215.  
  216.         //
  217.         // TabIndex
  218.         //
  219.         //    Tabbing order of control.  Controls are emitted into
  220.         //    the resource file in tab index order.
  221.  
  222.         VEXPORT void            SetTabIndex( long idx ) = 0;
  223.         VEXPORT long            GetTabIndex() const = 0;
  224.  
  225.  
  226.         //
  227.         // CodeBlockList
  228.         //
  229.         //    A list of code block's (functions) associated with the
  230.         //    object.
  231.         //
  232.  
  233.         VEXPORT const DTCodeBlockList & GetCodeBlockList() const = 0;
  234.         VEXPORT DTCodeBlockList &       GetCodeBlockList() = 0;
  235.  
  236.         VEXPORT WInt                    GetAllCodeBlockLists( DTCodeBlockListList & ) = 0;
  237.  
  238.         //
  239.         // RemoveEvent
  240.         //
  241.         //    Remove a code block from the list and remove any
  242.         //    other pointers to it (ie. from object inspector).
  243.  
  244.         VEXPORT DTCodeBlockBase *       RemoveEvent( DTCodeBlockBase * ) = 0;
  245.  
  246.         //
  247.         // FindEvent
  248.         //
  249.         //    Find a code block that has already been added to
  250.         //    this object.
  251.  
  252.         VEXPORT DTCodeBlockBase *       FindEvent( const char * ) const = 0;
  253.  
  254.         //
  255.         // Form, DTForm
  256.         //
  257.         //    The FormEdit associated with this object; the first
  258.         //    form is only useful from within Optima code; the second,
  259.         //    mainly from CompDLL.  SetForm is called by Optima when
  260.         //    it instantiates the object.
  261.  
  262.         VEXPORT FormEdit *      GetForm() const = 0;
  263.         VEXPORT DTFormEditBase *GetDTForm() const = 0;
  264.         VEXPORT void            SetForm( DTFormEditBase * ) = 0;
  265.  
  266.         //
  267.         // Child
  268.         //
  269.         //    The DTObject Children for this DTObject.  DTObjects
  270.         //    may now own other DTObjects.
  271.  
  272.         VEXPORT int             GetChildCount() const = 0;
  273.         VEXPORT DTObject *      GetChild( int index ) const = 0;
  274.         VEXPORT WBool           AddChild( DTObject *, int after = -1 ) = 0;
  275.         VEXPORT WBool           RemoveChild( DTObject * ) = 0;
  276.         VEXPORT DTObject *      GetParent() const = 0;
  277.  
  278.         //
  279.         // Style
  280.         //
  281.         //    The Windows style property of the associated Window.
  282.         //    This doesn't necessarily match GetWindow()->GetStyle()
  283.         //    because some styles are deferred until run-time (such
  284.         //    as WSVisible).
  285.  
  286.         VEXPORT WStyle          GetStyle() const = 0;
  287.         VEXPORT WBool           SetStyle( WStyle stl, WBool clone=FALSE ) = 0;
  288.  
  289.         //
  290.         // DefaultStyle
  291.         //
  292.         //    The style with which new instances are created.  Default
  293.         //    implementation returns GetWindow()->GetDefaultStyle().
  294.  
  295.         virtual WStyle          GetDefaultStyle() const = 0;
  296.  
  297.         //
  298.         // ExtendedStyle
  299.         //
  300.         //    The ExtendedStyle property of the window nature.
  301.  
  302.         virtual WStyle          GetExtendedStyle() const = 0;
  303.         virtual WBool           SetExtendedStyle( WStyle style, WBool clone=FALSE ) = 0;
  304.  
  305.         //
  306.         // DefaultExtendedStyle
  307.         //
  308.         //    See DefaultStyle
  309.  
  310.         virtual WStyle          GetDefaultExtendedStyle() const = 0;
  311.  
  312.         //
  313.         // Create
  314.         //
  315.         //    Call Create on the windowed object.
  316.         //
  317.         virtual WBool           Create( WWindow * parent, const WRect & r,
  318.                                         const WChar * text, WStyle style,
  319.                                         WStyle exStyle, void * data = NULL,
  320.                                         WBool isLoading = FALSE ) = 0;
  321.  
  322.         //
  323.         // NonVisual
  324.         //
  325.         //    NonVisual objects are represented by a picture box at
  326.         //    design time -- eg. WTimer, WMessageBox, WFileDialog.
  327.  
  328.         VEXPORT WBool           GetNonVisual() const = 0;
  329.  
  330.         // DTInfo
  331.         //
  332.         //    Each object can have information that is not handled by
  333.         //    the general framework.  For instance, listboxes store their
  334.         //    lines separately.  HasDTInfo should return true if you want
  335.         //    to store object-specific information, then the SaveDTInfo
  336.         //    and LoadDTInfo functions will be called.
  337.  
  338.         virtual WBool           HasDTInfo() = 0;
  339.         virtual WBool           SaveDTInfo( SaveSource & ) = 0;
  340.         virtual WBool           LoadDTInfo( SaveBlock *, WBool beforeCreate ) = 0;
  341.  
  342.         //
  343.         // CreateEventPopupMenu
  344.         //
  345.         //    Popupulate a popup menu with the events that are deemed
  346.         //    useful ("hot" events) as well as events with code.  There
  347.         //    is a default behaviour which is overriden for Ole objects.
  348.  
  349.         virtual WBool           CreateEventPopupMenu( WPopupMenu * popup ) = 0;
  350.  
  351.         //
  352.         // IsResizeable
  353.         //
  354.         //    IsResizeable allows non-visual objects and Ole objects to
  355.         //    deny resizing (can change after created
  356.  
  357.         virtual WBool           GetIsResizeable() = 0;
  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() = 0;      // groupbox
  370.         virtual WRect           GetHollowRect() = 0;    // 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 * ) = 0;
  379.         VEXPORT DTObject *      GetDTPopupMenu() const = 0;
  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 ) = 0;
  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 = 0;
  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 = 0;
  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 ) = 0;
  420.  
  421.         //
  422.         // DTIInterface
  423.         //
  424.         //    Get DTInterface with a particular name. This virtual
  425.         //    function is overridden once by derived classes that use
  426.         //    DTInterfaces
  427.  
  428.         virtual DTIInterface *  GetDTIInterface( const WChar * ifname ) = 0;
  429.  
  430.         //
  431.         // Protected
  432.         //
  433.         //    This property controls the behaviour of a design time
  434.         //    object.  Protected objects are:
  435.         //              -  not saved or loaded
  436.         //              -  cannot be deleted directly by the user
  437.  
  438.         virtual WBool GetProtected() const = 0;
  439.  
  440.  
  441.         /*************************************************************
  442.          * Property Editting
  443.          *************************************************************/
  444.  
  445.         //
  446.         // EditProperties
  447.         //
  448.         //    Display a property sheet window.  Depending on "child",
  449.         //    the property sheet may be a child (as in object view) or
  450.         //    a popup dialog (normal property sheets).
  451.  
  452.         VEXPORT WBool                   EditProperties( WWindow *,
  453.                                                         WBool child = FALSE ) = 0;
  454.         //
  455.         // ClearPropertyEditor
  456.         //
  457.         //    Remove and destroy any open property editor for this object.
  458.  
  459.         VEXPORT void                    ClearPropertyEditor( WBool deleteNow = FALSE ) = 0;
  460.  
  461.         //
  462.         // UpdatePropertyRect
  463.         //
  464.         //    Inform any open property editors to update the position
  465.         //    property since this object has been moved
  466.  
  467.         virtual WBool                   UpdatePropertyRect() = 0;
  468.  
  469.         //
  470.         // PropDialog
  471.         //
  472.         //    Get a pointer to the open property editor or return NULL.
  473.  
  474.         VEXPORT MTPropertyDialog *      GetPropDialog() = 0;
  475.  
  476.         //
  477.         // HasProperty
  478.         //
  479.         //    Return TRUE if this object has a property named "name".
  480.  
  481.         VEXPORT WBool                   HasProperty( const WString & name ) const = 0;
  482.  
  483.         //
  484.         // Property
  485.         //
  486.         //    Get or set a property with various formats.  
  487.         //    The additional formats are provided for convenience only.
  488.  
  489.         VEXPORT WString                 GetProperty( const WString & name, DT_TextifyV t = 1 ) const = 0;
  490.         VEXPORT WBool                   GetPropertyBool( const WString & name ) const = 0;
  491.         VEXPORT WLong                   GetPropertyEnum( const WString & name ) const = 0;
  492.         VEXPORT WRect                   GetPropertyRect( const WString & name ) const = 0;
  493.         VEXPORT WLong                   GetPropertyLong( const WString & name ) const = 0;
  494.         VEXPORT WBool                   SetProperty( const WString & name, const WString & val, DT_TextifyV t = 1 ) = 0;
  495.         VEXPORT WBool                   SetPropertyBool( const WString & name, WBool val ) = 0;
  496.         VEXPORT void                    SetPropertyEnum( const WString & name, WLong val ) = 0;
  497.         VEXPORT void                    SetPropertyRect( const WString & name, const WRect & r ) = 0;
  498.         VEXPORT void                    SetPropertyLong( const WString & name, WLong r ) = 0;
  499.  
  500.         //
  501.         // MappedValue
  502.         //
  503.         //    Deferred properties are stored internally as mapped values.
  504.         //    You can access these mapped values directly by index.
  505.         //    [ITB:REMOVE]
  506.  
  507.         VEXPORT WString                 GetMappedValue( WUInt i ) const = 0;
  508.         VEXPORT void                    SetMappedValue( WUInt i, const WString & s ) = 0;
  509.  
  510.         //
  511.         // PropertyChanged
  512.         //
  513.         //    This function is called after any property has changed
  514.         //    values.  You can override this function to perform
  515.         //    required actions when a property changes.
  516.         //    "name" is the name of the changed property
  517.  
  518.         virtual void                    PropertyChanged( const WString & name ) = 0;
  519.  
  520.         //
  521.         // DetachEditor
  522.         //
  523.         //    Virtual call to detach an editor if necessary.
  524.  
  525.         virtual void                    DetachEditor() = 0;
  526.  
  527.  
  528.  
  529.         /*************************************************************
  530.          * Code Generation
  531.          *************************************************************/
  532.  
  533.         //
  534.         // ObjectPrefix
  535.         //
  536.         //    Get the prefix used when accessing member functions of the
  537.         //    object -- eg. "cb_1->"
  538.  
  539.         VEXPORT WString GetObjectPrefix() const = 0;
  540.  
  541.         //
  542.         // GenName
  543.         //    Generate a variable name by number, eg. cb_1 if id == 1
  544.         //    The string is an out parameter.
  545.  
  546.         VEXPORT void GenName( WUInt id, WString & ) const = 0;
  547.  
  548.         //
  549.         // GenClassName
  550.         //
  551.         //    Generate the name of the C++ or Java class that implements
  552.         //    this object.
  553.  
  554.         VEXPORT void GenClassName( WString & ) const = 0;
  555.  
  556.         //
  557.         // GenResourceName
  558.         //
  559.         //    Generate the resource ID from the object name.  This is
  560.         //    usually of the form ID_name.
  561.  
  562.         VEXPORT void GenResourceName( WString & ) const = 0;
  563.  
  564.         //
  565.         // GenResourceStyles
  566.         //
  567.         //     Generate the .rc file styles that will be used; the first
  568.         //     parameter is a string list filled with styles, the second
  569.         //     is filled with extended styles
  570.  
  571.         VEXPORT void GenResourceStyles( WStringList &, WStringList & ) const = 0;
  572.  
  573.         //
  574.         // GenEventObjectName
  575.         //
  576.         //     Generate the object name for an event. The name is built
  577.         // by recursing the DTObject hierarchy and prepending the names
  578.         // of the DTObjects
  579.  
  580.         VEXPORT void GenEventObjectName( WString & ) const = 0;
  581.  
  582.         //
  583.         // FindStyle
  584.         //
  585.         //     Find a style of a given name within the object
  586.  
  587.         VEXPORT const MMStyle *     FindStyle( const char * ) const = 0;
  588.  
  589.         //
  590.         // FindProperty
  591.         //
  592.         //     Find a property of a given name within an object
  593.  
  594.         VEXPORT const MMProperty *  FindProperty( const char * ) const = 0;
  595.  
  596.  
  597.         /*************************************************************
  598.          * Form Data Exchange [move to DTWObject]
  599.          *************************************************************/
  600.     public:
  601.         VEXPORT DTObjectImp *   GetImplementation() = 0;
  602.         virtual WBool           GetDDXEnabled() const = 0;
  603.         virtual void            SetDDXEnabled( WBool e ) = 0;
  604.  
  605.         virtual WString         GetDDXFieldName() const = 0;
  606.         virtual void            SetDDXFieldName( const WString & ) = 0;
  607.  
  608.         virtual WString         GetDDXFieldType() const = 0;
  609.         virtual void            SetDDXFieldType( const WString & ) = 0;
  610.  
  611.         virtual WString         GetDDXModifiedFieldName() const = 0;
  612.         virtual void            SetDDXModifiedFieldName( const WString & ) = 0;
  613.  
  614.         virtual WString         GetDDXAdditional( unsigned i ) const = 0;
  615.         virtual void            SetDDXAdditional( unsigned i, const WString & ) = 0;
  616.         VEXPORT void            EscapeCString( WString &, const WString & ) const = 0;
  617. };
  618.  
  619. #endif // _DTOBASE_HPP
  620.