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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1994 by Borland International
  3. //   Tutorial application -- step18dv.h
  4. //   Automation Container Server example
  5. //----------------------------------------------------------------------------
  6. #if !defined(STEP18DV_H)
  7. #define STEP18DV_H
  8.  
  9. #if !defined(OCF_OCLINK_H)
  10. # include <ocf/oclink.h>
  11. #endif
  12.  
  13. #if !defined(OCF_OCCTRL_H)
  14. # include <ocf/occtrl.h>
  15. #endif
  16.  
  17. const int Margin  = 15;   // Margins used for copying selection
  18.  
  19. class _ICLASS TOcPart;
  20. class _USERCLASS TDrawView;
  21.  
  22.  
  23. typedef TArray<TPoint> TPoints;
  24. typedef TArrayIterator<TPoint> TPointsIterator;
  25.  
  26. class TLine : public TPoints {
  27.   public:
  28.     // Constructor to allow construction from a color and a pen size.
  29.     // Also serves as default constructor.
  30.     TLine(const TColor& color = TColor(0), int penSize = 1) :
  31.       TPoints(10, 0, 10), PenSize(penSize), Color(color), Bound(0, 0, 0, 0),
  32.       Selected(false) {}
  33.  
  34.     // Functions to modify and query pen attributes.
  35.     int QueryPenSize() const
  36.     {
  37.       return PenSize;
  38.     }
  39.  
  40.     const TColor& QueryColor() const
  41.     {
  42.       return Color;
  43.     }
  44.  
  45.     void SetPen(const TColor& newColor, int penSize = 0);
  46.     void SetPen(int penSize);
  47.     friend bool GetPenSize(TWindow* parent, TLine& line);
  48.     friend bool GetPenColor(TWindow* parent, TLine& line);
  49.  
  50.     // TLine draws itself.  Returns true if everything went OK.
  51.     virtual bool Draw(TDC&) const;
  52.     void DrawSelection(TDC& dc);
  53.  
  54.     // The == operator must be defined for the container class, even if unused
  55.     bool operator ==(const TLine& other) const
  56.     {
  57.       return &other == this;
  58.     }
  59.  
  60.     friend ostream& operator <<(ostream& os, const TLine& line);
  61.     friend istream& operator >>(istream& is, TLine& line);
  62.  
  63.     // bound related functions
  64.     void Invalidate(TDrawView& view);
  65.     TPoint& GetPos()
  66.     {
  67.       return Bound.TopLeft();
  68.     }
  69.  
  70.     TSize& GetSize()
  71.     {
  72.       return Bound.Size();
  73.     }
  74.  
  75.     TRect& GetBound()
  76.     {
  77.       return Bound;
  78.     }
  79.  
  80.     void UpdateBound();
  81.     void UpdatePosition(TPoint&);
  82.     void UpdateSize(TSize& newSize);
  83.  
  84.     // Selection
  85.     bool IsSelected()
  86.     {
  87.       return Selected;
  88.     }
  89.  
  90.     void Select(bool select = true)
  91.     {
  92.       Selected = select;
  93.     }
  94.  
  95.     TUIHandle::TWhere Where;
  96.  
  97.   protected:
  98.     int PenSize;
  99.     TColor Color;
  100.     TRect Bound;          // the enclosing rectangle for line
  101.     bool Selected;
  102. };
  103.  
  104. typedef TArray<TLine> TLines;
  105. typedef TArrayIterator<TLine> TLinesIterator;
  106.  
  107. class _USERCLASS TMyOcxEvent : public TOcControlEvent {
  108.   public:
  109.  
  110.     void       InitEventDispatch();
  111.  
  112.     long       SpinPositive();  // for spindial control test
  113.  
  114.   DECLARE_AUTOCLASS (TMyOcxEvent)
  115.     AUTOFUNC0 (SpinPositive,  SpinPositive,  long,)
  116. };
  117.  
  118.  
  119. class _USERCLASS TDrawDocument : public TOleDocument {
  120.   public:
  121.     enum {
  122.       PrevProperty = TOleDocument::NextProperty-1,
  123.       LineCount,
  124.       Description,
  125.       NextProperty,
  126.     };
  127.  
  128.     enum {
  129.       UndoNone,
  130.       UndoDelete,
  131.       UndoAppend,
  132.       UndoModify
  133.     };
  134.  
  135.     // OCServer changes begin
  136.     TDrawDocument(TDocument* parent = 0);
  137.     // OCServer changes end
  138.  
  139.    ~TDrawDocument();
  140.  
  141.     // implement virtual methods of TDocument
  142.     bool   Open(int mode, const char far* path=0);
  143.     bool OpenSelection(int mode, const char far* path, TPoint far* where);
  144.     bool   Close();
  145.     bool   Commit(bool force = false);
  146.     bool   CommitSelection(TOleWindow& oleWin, void* userData);
  147.  
  148.     int         FindProperty(const char far* name);  // return index
  149.     int         PropertyFlags(int index);
  150.     const char* PropertyName(int index);
  151.     int         PropertyCount()
  152.     {
  153.       return NextProperty - 1;
  154.     }
  155.  
  156.     int         GetProperty(int index, void far* dest, int textlen=0);
  157.  
  158.     // data access functions
  159.     TLine* GetLine(uint index);
  160.     TLines* GetLines()
  161.     {
  162.       return Lines;
  163.     }
  164.  
  165.     TLine* GetLine(TString& moniker);
  166.     int    AddLine(TLine& line);
  167.     void   DeleteLine(uint index);
  168.     void   ModifyLine(TLine& line, uint index);
  169.     void   Clear();
  170.     void   Undo();
  171.     TSize& GetDocSize(){return DocSize;}
  172.  
  173.   protected:
  174.     TLines* Lines;
  175.     TLine*  UndoLine;
  176.     int     UndoState;
  177.     int     UndoIndex;
  178.     string  FileInfo;
  179.     TSize   DocSize;      // Document size in log unit
  180.  
  181.   private:
  182.     // To not interfere with normal mouse operations, the automation
  183.     // entry points have their own lines with their own attributes.
  184.     long GetPenColor()
  185.     {
  186.       return AutoPenColor;
  187.     }
  188.  
  189.     void SetPenColor(long color)
  190.     {
  191.       AutoPenColor = color;
  192.       AutoLine->SetPen(TColor(color));
  193.     }
  194.  
  195.     short GetPenSize()
  196.     {
  197.       return AutoPenSize;
  198.     }
  199.  
  200.     void SetPenSize(short penSize)
  201.     {
  202.       AutoPenSize = penSize;
  203.       AutoLine->SetPen(penSize);
  204.     }
  205.  
  206.     void AddPoint(short x, short y)
  207.     {
  208.       AutoLine->Add(TPoint(x,y));
  209.     }
  210.  
  211.     void AddLine()
  212.     {
  213.       AddLine(*AutoLine);
  214.       ClearLine();
  215.     }
  216.  
  217.     void ClearLine()
  218.     {
  219.       delete AutoLine;
  220.       AutoLine = new TLine(AutoPenColor, AutoPenSize);
  221.     }
  222.  
  223.     TLine*  AutoLine;
  224.     long    AutoPenColor;
  225.     short   AutoPenSize;
  226.  
  227.   DECLARE_AUTOCLASS(TDrawDocument)
  228.     AUTOPROP(PenSize,    GetPenSize,  SetPenSize,  short, )
  229.     AUTOPROP(PenColor,   GetPenColor, SetPenColor, long, )
  230.     AUTOFUNC2V(AddPoint, AddPoint, short, short, )
  231.     AUTOFUNC0V(AddLine,  AddLine, )
  232.     AUTOFUNC0V(ClearLine,ClearLine, )
  233. };
  234.  
  235.  
  236. //=====================  TDrawLinkView  =======================================
  237.  
  238. class _ICLASS   TOcControl;
  239. class _ICLASS   IDispatch;
  240.  
  241. class _USERCLASS TDrawLinkView : public TOleLinkView {
  242.   public:
  243.     TDrawLinkView(TDocument& doc, TOcLinkView& view);
  244.    ~TDrawLinkView();
  245.  
  246.     bool VnModify(uint index);
  247.     bool VnDelete(uint index);
  248.  
  249.     static const char far* StaticName()
  250.     {
  251.       return "Draw Link View";
  252.     }
  253.  
  254.     const char far* GetViewName()
  255.     {
  256.       return StaticName();
  257.     }
  258.  
  259.   protected:
  260.     TDrawDocument* DrawDoc;
  261.  
  262.   DECLARE_RESPONSE_TABLE(TDrawLinkView);
  263. };
  264.  
  265. class _USERCLASS TDrawView : public TOleView {
  266.   public:
  267.     TDrawView(TDrawDocument& doc, TWindow* parent = 0);
  268.    ~TDrawView();
  269.  
  270.     static const char far* StaticName()
  271.     {
  272.       return "Draw View";
  273.     }
  274.  
  275.     const char far* GetViewName()
  276.     {
  277.       return StaticName();
  278.     }
  279.     static void CleanUp(void* userData);
  280.  
  281.     void SetLineSelection(TLine* Line);
  282.     void SetLineSelection(int index);
  283.     TLine* HitTest(TPoint& pt);
  284.     bool Select(uint modKeys, TPoint& point);
  285.     void SetupWindow();
  286.     TLine* GetSelected() {return Selected;}
  287.     void SetStatusText (char far* text);
  288.  
  289.     bool EvOcViewSetLink(TOcLinkView& view);
  290.  
  291.     enum DRAWTOOL {
  292.       DrawSelect = 0,
  293.       DrawPen,
  294.     };
  295.     IDispatch *pIFont;
  296.     long       backRGB;
  297.     long       designMode;
  298.  
  299.   protected:
  300.     // Message response functions
  301.     void EvSize(uint sizeType, TSize& size);
  302.     void EvLButtonDown(uint, TPoint&);
  303.     void EvMouseMove(uint, TPoint&);
  304.     void EvLButtonUp(uint, TPoint&);
  305.     bool ShowCursor(HWND, uint, uint);
  306.     bool EvOcViewPartSize(TOcPartSize far& ps);
  307.     bool EvOcViewShowTools(TOcToolBarInfo far& tbi);
  308.     bool EvOcViewGetItemName(TOcItemName& item);
  309.     bool EvOcViewClipData(TOcFormatData far& format);
  310.  
  311.     bool EvOcAmbientGetBackColor(long* rgb);
  312.     bool EvOcAmbientGetFont(IDispatch** font);
  313.     bool EvOcAmbientGetUserMode(bool* mode);
  314.     bool EvOcAmbientGetShowGrabHandles(bool* show);
  315.     bool EvOcAmbientGetShowHatching(bool* show);
  316.     bool EvOcAmbientGetDisplayAsDefault(bool* disp);
  317.     bool EvOcAmbientGetTextAlign(short* align);
  318.  
  319.     bool EvOcCtrlClick(TCtrlEvent* pev);
  320.     bool EvOcCtrlDblClick(TCtrlEvent* pev);
  321.     bool EvOcCtrlCustomEvent(TCtrlCustomEvent* pev);
  322.  
  323.     // painting
  324.     void Paint(TDC&, bool, TRect&);
  325.     bool PaintSelection(TDC&, bool, TRect&, void* userData = 0);
  326.     bool PaintLink(TDC& dc, bool erase, TRect& rect, TString& moniker);
  327.  
  328.     void CmPenSize();
  329.     void CmPenColor();
  330.     void CmClear();
  331.     void CmUndo();
  332.     void CmEditCut();
  333.     void CmEditCopy();
  334.     void CeEditCut(TCommandEnabler& ce);
  335.     void CeEditCopy(TCommandEnabler& ce);
  336.  
  337.     void CePen(TCommandEnabler&);
  338.     void CeSelect(TCommandEnabler&);
  339.     void CeOrgSize(TCommandEnabler&);
  340.     void CeDoubleSize(TCommandEnabler&);
  341.     void CeHalfSize(TCommandEnabler&);
  342.     void CeControlProps(TCommandEnabler&);
  343.     void CeContainerMode(TCommandEnabler& ce);
  344.     void CmControlProps();
  345.     void CmControlFont ();
  346.     void CmControlCaption ();
  347.     void CmNewControl();
  348.     void CmContainerMode ();
  349.     void CmRegisterControl ();
  350.     void CmUnregisterControl ();
  351.     void CmPen();
  352.     void CmSelect();
  353.     void CmOrgSize();
  354.     void CmDoubleSize();
  355.     void CmHalfSize();
  356.  
  357.     // Document notifications
  358.     bool VnCommit(bool force);
  359.     bool VnRevert(bool clear);
  360.     bool VnAppend(uint index);
  361.     bool VnDelete(uint index);
  362.     bool VnModify(uint index);
  363.  
  364.     TDrawDocument*    DrawDoc;  // same as Doc member, but cast to derived class
  365.     TPen*             Pen;
  366.     TLine*            Line;     // To hold a single line sent or received from document
  367.     TLine*            Selected; // To hold a single selected line
  368.     DRAWTOOL          Tool;     // current tool selected
  369.     TControlBar*      ToolBar;
  370.  
  371.     // OC client changes end
  372.  
  373.   private:
  374.     void InsertObject(TOcInitInfo &init);
  375.     void AdjustScroller(); // scrolling support
  376.  
  377.   DECLARE_RESPONSE_TABLE(TDrawView);
  378. };
  379.  
  380.  
  381. class _USERCLASS TDrawListView : public TListBox, public TView {
  382.   public:
  383.     TDrawListView(TDrawDocument& doc, TWindow* parent = 0);
  384.    ~TDrawListView(){}
  385.     static const char far* StaticName()
  386.     {
  387.       return "DrawList View";
  388.     }
  389.  
  390.     int CurIndex;
  391.  
  392.     // Overridden virtuals from TView
  393.     //
  394.     const char far* GetViewName()
  395.     {
  396.       return StaticName();
  397.     }
  398.  
  399.     TWindow* GetWindow()
  400.     {
  401.       return (TWindow*)this;
  402.     }
  403.  
  404.     bool SetDocTitle(const char far* docname, int index)
  405.     {
  406.       return TListBox::SetDocTitle(docname, index);
  407.     }
  408.  
  409.     // Overridden virtuals from TWindow
  410.     //
  411.     bool CanClose()
  412.     {
  413.       return TListBox::CanClose() && Doc->CanClose();
  414.     }
  415.  
  416.     bool Create();
  417.  
  418.   protected:
  419.     TDrawDocument* DrawDoc;  // same as Doc member, but cast to derived class
  420.     void LoadData();
  421.     void FormatData(const TLine* line, uint index);
  422.  
  423.     // Message response functions
  424.     void CmPenSize();
  425.     void CmPenColor();
  426.     void CmClear();
  427.     void CmUndo();
  428.     void CmDelete();
  429.  
  430.     // Document notifications
  431.     bool VnIsWindow(HWND hWnd)
  432.     {
  433.       return HWindow == hWnd;
  434.     }
  435.  
  436.     bool VnCommit(bool force);
  437.     bool VnRevert(bool clear);
  438.     bool VnAppend(uint index);
  439.     bool VnDelete(uint index);
  440.     bool VnModify(uint index);
  441.  
  442.     // OC server changes
  443.     LRESULT EvOcEvent(WPARAM wParam, LPARAM lParam);
  444.     uint32  EvOcViewPaint(void far*);
  445.  
  446.   DECLARE_RESPONSE_TABLE(TDrawListView);
  447. };
  448.  
  449. const int vnDrawAppend     = vnCustomBase+0;
  450. const int vnDrawDelete     = vnCustomBase+1;
  451. const int vnDrawModify     = vnCustomBase+2;
  452.  
  453. NOTIFY_SIG(vnDrawAppend, uint)
  454. NOTIFY_SIG(vnDrawDelete, uint)
  455. NOTIFY_SIG(vnDrawModify, uint)
  456.  
  457. #define EV_VN_DRAWAPPEND  VN_DEFINE(vnDrawAppend,  VnAppend,   int)
  458. #define EV_VN_DRAWDELETE  VN_DEFINE(vnDrawDelete,  VnDelete,   int)
  459. #define EV_VN_DRAWMODIFY  VN_DEFINE(vnDrawModify,  VnModify,   int)
  460.  
  461. #endif // __STEP18DV_H
  462.