home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / ADDONINC.PAK / IVIEW.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  11.6 KB  |  310 lines

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   iview.h
  4.   Created: 11/01/95
  5.   Copyright (c) 1995, Borland International
  6.   $Header:   Y:\admin\bride\addon\deliver\interfac\iview.h_v   1.20   18 Nov 1996 11:30:14   JDOUGLAS  $
  7.   $Revision:   1.20  $
  8.     
  9.  Interfaces declared in this file:
  10.  
  11.  implemented by IDE
  12.  
  13.     IViewParentWnd
  14.     IViewType
  15.  
  16.  implemented by IDE client
  17.  
  18.     IViewClient
  19.     IViewFile
  20.     IUserViewFactory
  21.  
  22. Overview:
  23.  
  24.  Assuming client has impelemented IUserViewFactory and IViewClient interfaces.
  25.  View is initialized in the following order:
  26.  
  27.   1) Create IUserViewFactory and IViewType.
  28.      Register IUserViewFactory by calling IViewTye::Init() during startup.
  29.  
  30.   2) IDE calls IUserViewFactory::InitializeProperty() during startup.
  31.      If you have any properties you need to initialize at this point, you can 
  32.      call IViewType::InitFontAndColorProperty() now.
  33.      IViewClient::PropertyChangeNotify() is called when user change any
  34.      properties register. Adon client should call IViewType::Get*() to retrieve
  35.      the new property value.  Unfortunately, thie notification does not tell
  36.      you which property has changed, so you have to check every property that
  37.      can be changed.
  38.  
  39.   3) Call IViewType::CreateInstance() to create a IViewClient.
  40.      IViewType::CreateInstance() calls IUserViewFactory::CreateView()
  41.      to return a IViewClient.
  42.      Client can call IViewParentWnd::GetHwnd to get a valid window handle here.
  43.      NOTE: An addon client never calls IUserViewFactory::CreateView().
  44.  
  45. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ 
  46.  
  47. #ifndef __IVIEW_H
  48. #define __IVIEW_H
  49.  
  50. #include <ideaddon\ipolystr.h>
  51. #include <ideaddon\iview.uid>
  52. #include <ideaddon\common.h>
  53.  
  54. //
  55. // These are menu or toolbar commands that want to be enabled based on the
  56. // active view. 
  57. //
  58.  
  59. #define CMD_SEND      "FileSendMail"
  60. #define CMD_SELECTALL "EditSelectAll"
  61. #define CMD_CUT       "EditCut"
  62. #define CMD_CLEAR     "EditClear"
  63. #define CMD_COPY      "EditCopy"
  64. #define CMD_PASTE     "EditPaste"
  65. #define CMD_UNDO      "EditUndo"
  66. #define CMD_REDO      "EditRedo"
  67.  
  68. #define CMD_FIND          "SearchFind"
  69. #define CMD_REPLACE       "SearchReplace"
  70. #define CMD_SEARCHAGAIN   "SearchAgain"
  71.  
  72. #define CMD_CLOSE         "FileClose"
  73. #define CMD_SAVE          "FileSave"
  74. #define CMD_SAVEAS        "FileSaveas"
  75. #define CMD_PRINT         "FilePrint"
  76.  
  77. //
  78. // return values of CommandSupported()
  79. //
  80. #define CMD_UNKNOWN        -1
  81. #define CMD_UNAVAILABLE     0
  82. #define CMD_AVAILABLE       1
  83.  
  84.  
  85. enum FontAttribute {
  86.   FA_Bold = 1,
  87.   FA_Italic = 2,
  88.   FA_Underline =4
  89. };
  90.  
  91. //
  92. // forward declaration
  93. //
  94. struct IViewType;
  95.  
  96. //.............................................................................
  97. struct IViewClient : public IUnknown {
  98.  public:
  99.   //
  100.   //  You must return the HWND of the view window associated with this
  101.   // object.
  102.   //
  103.   virtual HWND BCWADDON_CMETHOD GetHwnd() = 0;
  104.   //
  105.   //  These methods are called by the IDE when it is ready to take
  106.   // your restore data. Return -1 from GetRestoreDataLen() if you
  107.   // don't wish to be restored when the project is re-opened. 
  108.   //
  109.   virtual long  BCWADDON_CMETHOD GetRestoreDataLen() = 0;
  110.   virtual void* BCWADDON_CMETHOD GetRestoreData() = 0;
  111.   //
  112.   //  If your view is 'dirty', you should ask the user the appropriate
  113.   // questions and either save or discard data associated with the 
  114.   // view. Returning FALSE will cancel the window close.
  115.   //
  116.   virtual BOOL BCWADDON_CMETHOD CanClose() = 0;
  117.  
  118.   // 
  119.   // Each view will be asked if it supports a polymorphic command such as "Save"
  120.   // when the appropriate menu is opened or in some cases on a regular basis 
  121.   // to allow tool bar buttons to be in the proper state when a view is 
  122.   // active.
  123.   // 
  124.   virtual unsigned BCWADDON_CMETHOD CommandSupported( IPolyString* ) = 0;
  125.  
  126.   //
  127.   //  If CommandSupported() returns TRUE for a particular polymorphic command,
  128.   // the ExecuteCommand() method may be called.
  129.   // See IviewFile for File menu command processing.
  130.   //
  131.   virtual void BCWADDON_CMETHOD ExecuteCommand( IPolyString* ) = 0;
  132.   //
  133.   // This method is called when the view property changed
  134.   //
  135.   virtual void BCWADDON_CMETHOD PropertyChangeNotify() = 0;
  136. };
  137.  
  138.  
  139. //
  140. // IViewFile is used to support the following polymorphic command
  141. //      CMD_CLOSE, CMD_SAVE ,CMD_SAVEAS adn CMD_PRINT.
  142. // These commands are not invoked thru IViewClient::ExecuteCommand()
  143. //
  144. // It should be returned by IViewClient if client want to support any
  145. // file menu commnad processing.
  146. //
  147. //
  148. struct IViewFile : IUnknown  {
  149.   // class TIFileSave
  150.   virtual BOOL BCWADDON_CMETHOD IsDirty() = 0;
  151.   virtual BOOL BCWADDON_CMETHOD Save() = 0;
  152.  
  153.   //  class TIFileSaveAs
  154.   virtual BOOL BCWADDON_CMETHOD SaveAs(IPolyString* FileName) = 0;
  155.  
  156.   //  class TIFileClose
  157.   virtual BOOL BCWADDON_CMETHOD Close() = 0;
  158.  
  159.   // class TIFilePrint
  160.   virtual BOOL BCWADDON_CMETHOD Print(BOOL noDialogs) = 0;
  161. };
  162.  
  163.  
  164. //.............................................................................
  165. //
  166. //  Whenever your IUserViewFactory-derived CreateView() is called, it is handed
  167. // an IViewParentWnd pointer. You will need its GetHwnd() method to set it
  168. // as the parent of the window you are about to create. You can use its other
  169. // methods to manipulate the parent window's attributes. You should use these
  170. // methods instead of the Windows API whenever possible.
  171. //
  172. struct IViewParentWnd : public IUnknown {
  173.   virtual HWND BCWADDON_CMETHOD GetHwnd() = 0;
  174.   virtual void BCWADDON_CMETHOD Activate() = 0;
  175.   virtual void BCWADDON_CMETHOD Move(int left, int top, int width, int height ) = 0;
  176.   virtual void BCWADDON_CMETHOD Display() = 0;
  177.   virtual void BCWADDON_CMETHOD SetTitle( IPolyString * title ) = 0;
  178.   virtual IViewClient* BCWADDON_CMETHOD GetViewClient() = 0;
  179.   virtual void BCWADDON_CMETHOD UpdateModifyState() = 0;
  180. };
  181.  
  182. //.............................................................................
  183. //
  184. //  Derive a class from IUserViewFactory for each type of view you intend to 
  185. // register with the IDE.
  186. //
  187. struct IUserViewFactory : public IUnknown {
  188. public:
  189.   //
  190.   //  CreateView() will be called in response to an IViewType::CreateInstance()
  191.   // call. Create your window as a child of wndServer->GetHwnd(). Return
  192.   // a new instance of your IViewClient-derived class to describe the new
  193.   // view window to the caller.
  194.   //
  195.   //  If you are being asked to restore a view from a previous project 
  196.   // session, restoreData will be non-null and is a pointer to a copy
  197.   // of the persistence data you passed to the ide in response to an
  198.   // IViewClient::GetRestoreData() request.
  199.   // 
  200.   // Remember that the caller of createView owns the restoreData memory 
  201.   // block, so you should copy it if you intend to use it after returning 
  202.   // from this function call.
  203.   //
  204.   virtual IViewClient * BCWADDON_CMETHOD CreateView(IViewParentWnd * wndServer,
  205.                                   void * restoreData = NULL ) = 0;
  206.   //
  207.   // call client to register properties
  208.   //
  209.   virtual void BCWADDON_CMETHOD InitializeProperty(IViewType* viewType) = 0;
  210. };
  211.  
  212. //.............................................................................
  213. //
  214. //  This interface is used to register your view types and to instantiate new
  215. // view windows. At IDE startup time, use helper function "CreateViewType" to 
  216. // get an IViewType pointer for each view you need to register with the IDE. 
  217. //
  218. struct IViewType : public IUnknown {
  219.   //
  220.   // After getting an IViewType pointer, use Init() to register the ViewType's
  221.   // properties. 
  222.   // 
  223.   // viewFactory: See the comments above under IUserViewFactory
  224.   // viewTypeName: This must be unique name for the view, if it is already
  225.   // registered with the IDE, Init will return FALSE.
  226.   //
  227.   virtual BOOL BCWADDON_CMETHOD Init(IUserViewFactory * viewFactory,
  228.                     IPolyString* viewType, 
  229.                     int left,
  230.                     int top,
  231.                     int right,
  232.                     int bottom,
  233.                     HINSTANCE hInstance = 0, 
  234.                     DWORD iconResourceId = 0 ) = 0;
  235.  
  236.   //
  237.   // Call CreateInstance() for each new view you wish to create. Your 
  238.   // IUserViewFactory::CreateView() method will be called while inside
  239.   // this method.
  240.   //
  241.   virtual IViewParentWnd* BCWADDON_CMETHOD CreateInstance(IPolyString* title) = 0;
  242.  
  243.   //
  244.   //  If the view permits font and color selection, register its defaults
  245.   // here. Both the viewTypeName and propName will appear in the 
  246.   // environment/options/fonts dialog box and will be passed back to you 
  247.   // through the IViewClient SetFont() and SetColor() callbacks. Once you 
  248.   // set the initial property here, the IDE will call the set functions when 
  249.   // the user requests a change and it will keep track of the on-going state 
  250.   // for each property. This should be called after Init() at startup time.
  251.   //
  252.   virtual void BCWADDON_CMETHOD InitFontAndColorProperty(  IPolyString * propName, 
  253.                                           IPolyString * fontName,
  254.                                           int fontSize,
  255.                                           FontAttribute attrib,
  256.                                           DWORD foreColor,
  257.                                           DWORD backColor ) = 0;
  258.  
  259.    virtual IPolyString* BCWADDON_CMETHOD GetFontName(IPolyString * propName) = 0;
  260.    virtual int BCWADDON_CMETHOD GetFontSize(IPolyString * propName) = 0;
  261.    virtual int BCWADDON_CMETHOD GetFontAttribute(IPolyString * propName) = 0;
  262.    virtual DWORD BCWADDON_CMETHOD GetForegroundColor(IPolyString * propName) = 0;
  263.    virtual DWORD BCWADDON_CMETHOD GetBackgroundColor(IPolyString * propName) = 0;
  264. };
  265.  
  266. //.............................................................................
  267. // IViewType2 is new as of BCW version 5.01. To get a pointer to this
  268. // interface, query the IViewType interface returned from the IDEServer
  269. // or through the CreateViewType() helper function. Be prepared to downgrade
  270. // gracefully if this interface isn't available. Here's an example:
  271. // 
  272. //  IViewType * viewType = ::CreateViewType();
  273. //  if ( viewType ) {
  274. //    viewType->Init( myViewFactory, ::MakePolyString( "MyView" ), 0, 100, 100, 100 );
  275. //    // you can call other IViewType methods using 'viewType'here
  276. // 
  277. //    IViewType2 * viewType2 = QUERY_INTERFACE( viewType, IViewType2 );
  278. //    if ( viewType2 ) {
  279. //      viewType2->SetDisplayName( ::MakePolyString( "MyDisplayName" ) );
  280. //      // you can call other IViewType or IViewType2 methods using 'viewType2'
  281. //    }
  282. //  }
  283. //  
  284. //
  285. struct IViewType2 : public IViewType {
  286.  public:
  287.   //
  288.   // SetDisplayName(). The DisplayName is a string that will be used in the 
  289.   // list of views for speedbar customization and per-view font optons (see
  290.   // Environment|Options in the IDE).If you don't use SetDisplayName, the 
  291.   // ViewType string passed to IViewType::Init() is used.
  292.   // 
  293.   virtual void BCWADDON_CMETHOD SetDisplayName( IPolyString * displayName ) = 0;
  294.   //
  295.   // SetFamilyName(). The FamilyName should be a unique string which is used
  296.   // to group one or more views together. This determines which views will
  297.   // be grouped together for things such as the Window|Close All sub-menu.
  298.   //
  299.   virtual void BCWADDON_CMETHOD SetFamilyName( IPolyString * familyName ) = 0;
  300.   //
  301.   // SetDisplayFamilyName(). DisplayFamilyName is what the end-user will 
  302.   // see whenever FamilyNames are displayed. If this is not set, the 
  303.   // FamilyName string will be displayed. 
  304.   //
  305.   virtual void BCWADDON_CMETHOD SetDisplayFamilyName( IPolyString * displayFamilyName ) = 0;  
  306. };
  307.  
  308.  
  309. #endif //  __IVIEW_H
  310.