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