home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / step16.pak / STEP16DV.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  7KB  |  294 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1994 by Borland International
  3. //   Tutorial application -- step16dv.h
  4. //   Automation Server example
  5. //----------------------------------------------------------------------------
  6. #if !defined(STEP16DV_H)
  7. #define STEP16DV_H
  8.  
  9. typedef TArray<TPoint> TPoints;
  10. typedef TArrayIterator<TPoint> TPointsIterator;
  11.  
  12. class TLine : public TPoints {
  13.   public:
  14.     // Constructor to allow construction from a color and a pen size.
  15.     // Also serves as default constructor.
  16.     TLine(const TColor& color = TColor(0), int penSize = 1) :
  17.       TPoints(10, 0, 10), PenSize(penSize), Color(color){}
  18.  
  19.     // Functions to modify and query pen attributes.
  20.     int QueryPenSize() const
  21.     {
  22.       return PenSize;
  23.     }
  24.  
  25.     const TColor& QueryColor() const
  26.     {
  27.       return Color;
  28.     }
  29.  
  30.     void SetPen(TColor& newColor, int penSize = 0);
  31.     void SetPen(int penSize);
  32.     friend bool GetPenSize(TWindow* parent, TLine& line);
  33.     friend bool GetPenColor(TWindow* parent, TLine& line);
  34.  
  35.     // TLine draws itself.  Returns true if everything went OK.
  36.     virtual bool Draw(TDC&) const;
  37.     void DrawSelection(TDC& dc);
  38.  
  39.     // The == operator must be defined for the container class, even if unused
  40.     bool operator ==(const TLine& other) const
  41.     {
  42.       return &other == this;
  43.     }
  44.  
  45.     friend ostream& operator <<(ostream& os, const TLine& line);
  46.     friend istream& operator >>(istream& is, TLine& line);
  47.  
  48.  
  49.   protected:
  50.     int PenSize;
  51.     TColor Color;
  52. };
  53.  
  54. typedef TArray<TLine> TLines;
  55. typedef TArrayIterator<TLine> TLinesIterator;
  56.  
  57. class _USERCLASS TDrawDocument : public TOleDocument {
  58.   public:
  59.     enum {
  60.       PrevProperty = TOleDocument::NextProperty-1,
  61.       LineCount,
  62.       Description,
  63.       NextProperty,
  64.     };
  65.  
  66.     enum {
  67.       UndoNone,
  68.       UndoDelete,
  69.       UndoAppend,
  70.       UndoModify
  71.     };
  72.  
  73.     TDrawDocument(TDocument* parent = 0);
  74.    ~TDrawDocument();
  75.  
  76.     // implement virtual methods of TDocument
  77.     bool   Open(int mode, const char far* path=0);
  78.     bool   Close();
  79.     bool   Commit(bool force = false);
  80.  
  81.     int         FindProperty(const char far* name);  // return index
  82.     int         PropertyFlags(int index);
  83.     const char* PropertyName(int index);
  84.     int         PropertyCount()
  85.     {
  86.       return NextProperty - 1;
  87.     }
  88.  
  89.     int         GetProperty(int index, void far* dest, int textlen=0);
  90.  
  91.     // data access functions
  92.     TLine* GetLine(uint index);
  93.     TLines* GetLines()
  94.     {
  95.       return Lines;
  96.     }
  97.  
  98.     int    AddLine(TLine& line);
  99.     void   DeleteLine(uint index);
  100.     void   ModifyLine(TLine& line, uint index);
  101.     void   Clear();
  102.     void   Undo();
  103.  
  104.   protected:
  105.     TLines* Lines;
  106.     TLine*  UndoLine;
  107.     int     UndoState;
  108.     int     UndoIndex;
  109.     string  FileInfo;
  110.  
  111.   private:
  112.     // To not interfere with normal mouse operations, the automation
  113.     // entry points have their own lines with their own attributes.
  114.     long GetPenColor()
  115.     {
  116.       return AutoPenColor;
  117.     }
  118.  
  119.     void SetPenColor(long color)
  120.     {
  121.       AutoPenColor = color;
  122.       AutoLine->SetPen(TColor(color));
  123.     }
  124.  
  125.     short GetPenSize()
  126.     {
  127.       return AutoPenSize;
  128.     }
  129.  
  130.     void SetPenSize(short penSize)
  131.     {
  132.       AutoPenSize = penSize;
  133.       AutoLine->SetPen(penSize);
  134.     }
  135.  
  136.     void AddPoint(short x, short y)
  137.     {
  138.       AutoLine->Add(TPoint(x,y));
  139.     }
  140.  
  141.     void AddLine()
  142.     {
  143.       AddLine(*AutoLine);
  144.       ClearLine();
  145.     }
  146.  
  147.     void ClearLine()
  148.     {
  149.       delete AutoLine;
  150.       AutoLine = new TLine(AutoPenColor, AutoPenSize);
  151.     }
  152.  
  153.     TLine*  AutoLine;
  154.     long    AutoPenColor;
  155.     short   AutoPenSize;
  156.  
  157.   DECLARE_AUTOCLASS(TDrawDocument)
  158.     AUTOPROP(PenSize,    GetPenSize,  SetPenSize,  short, )
  159.     AUTOPROP(PenColor,   GetPenColor, SetPenColor, long, )
  160.     AUTOFUNC2V(AddPoint, AddPoint, short, short, )
  161.     AUTOFUNC0V(AddLine,  AddLine, )
  162.     AUTOFUNC0V(ClearLine,ClearLine, )
  163. };
  164.  
  165. class _USERCLASS TDrawView : public TOleView {
  166.   public:
  167.     TDrawView(TDrawDocument& doc, TWindow* parent = 0);
  168.    ~TDrawView()
  169.     {
  170.       delete Line;
  171.     }
  172.  
  173.     static const char far* StaticName()
  174.     {
  175.       return "Draw View";
  176.     }
  177.  
  178.     const char far* GetViewName()
  179.     {
  180.       return StaticName();
  181.     }
  182.  
  183.   protected:
  184.     // Message response functions
  185.     void EvLButtonDown(uint, TPoint&);
  186.     void EvMouseMove(uint, TPoint&);
  187.     void EvLButtonUp(uint, TPoint&);
  188.  
  189.     void Paint(TDC&, bool, TRect&);
  190.     void CmPenSize();
  191.     void CmPenColor();
  192.     void CmClear();
  193.     void CmUndo();
  194.  
  195.     void CmEditCut();
  196.     void CmEditCopy();
  197.     bool EvOcViewPartSize(TOcPartSize far& ps);
  198.     bool EvOcViewShowTools(TOcToolBarInfo far& tbi);
  199.  
  200.     // Document notifications
  201.     bool VnCommit(bool force);
  202.     bool VnRevert(bool clear);
  203.     bool VnAppend(uint index);
  204.     bool VnDelete(uint index);
  205.     bool VnModify(uint index);
  206.  
  207.     TDrawDocument* DrawDoc;  // same as Doc member, but cast to derived class
  208.     TPen*          Pen;
  209.     TLine*         Line;     // To hold a single line sent or received from document
  210.     TControlBar*   ToolBar;
  211.  
  212.   DECLARE_RESPONSE_TABLE(TDrawView);
  213. };
  214.  
  215.  
  216. class _USERCLASS TDrawListView : public TListBox, public TView {
  217.   public:
  218.     TDrawListView(TDrawDocument& doc, TWindow* parent = 0);
  219.    ~TDrawListView(){}
  220.     static const char far* StaticName()
  221.     {
  222.       return "DrawList View";
  223.     }
  224.  
  225.     int CurIndex;
  226.  
  227.     // Overridden virtuals from TView
  228.     //
  229.     const char far* GetViewName()
  230.     {
  231.       return StaticName();
  232.     }
  233.  
  234.     TWindow* GetWindow()
  235.     {
  236.       return (TWindow*)this;
  237.     }
  238.  
  239.     bool SetDocTitle(const char far* docname, int index)
  240.     {
  241.       return TListBox::SetDocTitle(docname, index);
  242.     }
  243.  
  244.     // Overridden virtuals from TWindow
  245.     //
  246.     bool CanClose();
  247.     bool Create();
  248.  
  249.   protected:
  250.     TDrawDocument* DrawDoc;  // same as Doc member, but cast to derived class
  251.     void LoadData();
  252.     void FormatData(const TLine* line, uint index);
  253.  
  254.     // Message response functions
  255.     void CmPenSize();
  256.     void CmPenColor();
  257.     void CmClear();
  258.     void CmUndo();
  259.     void CmDelete();
  260.  
  261.     // Document notifications
  262.     bool VnIsWindow(HWND hWnd)
  263.     {
  264.       return HWindow == hWnd;
  265.     }
  266.  
  267.     bool VnCommit(bool force);
  268.     bool VnRevert(bool clear);
  269.     bool VnAppend(uint index);
  270.     bool VnDelete(uint index);
  271.     bool VnModify(uint index);
  272.  
  273.     // OC server changes
  274.     LRESULT   EvOcEvent(WPARAM wParam, LPARAM lParam);
  275.     uint32    EvOcViewPaint(void far*);
  276.  
  277.     DECLARE_RESPONSE_TABLE(TDrawListView);
  278. };
  279.  
  280. const int vnDrawAppend = vnCustomBase+0;
  281. const int vnDrawDelete = vnCustomBase+1;
  282. const int vnDrawModify = vnCustomBase+2;
  283.  
  284. NOTIFY_SIG(vnDrawAppend, uint)
  285. NOTIFY_SIG(vnDrawDelete, uint)
  286. NOTIFY_SIG(vnDrawModify, uint)
  287.  
  288. #define EV_VN_DRAWAPPEND  VN_DEFINE(vnDrawAppend,  VnAppend,  int)
  289. #define EV_VN_DRAWDELETE  VN_DEFINE(vnDrawDelete,  VnDelete,  int)
  290. #define EV_VN_DRAWMODIFY  VN_DEFINE(vnDrawModify,  VnModify,  int)
  291.  
  292.  
  293. #endif // __STEP16DV_H
  294.