home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Sample Controls / Ticker / CTickerControl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-12-20  |  6.6 KB  |  186 lines  |  [TEXT/CWIE]

  1. #ifndef __CTickerControl_h__
  2. #define __CTickerControl_h__
  3.  
  4. #include <QuickDraw.h>
  5. #include <QDOffscreen.h>
  6. #include <deque.h>
  7.  
  8. #include "CBaseBindStatusCallback.h"
  9.  
  10. class CTick;
  11. class CTickerError;
  12.  
  13. ///////////////////////////////////////////////////////////////////////////////
  14. //
  15. //    Things to make Intrinsic Control ported souRce compile
  16. //
  17. #define T2OLE(x) (x) // T2OLE not needed on Mac, which doesn't use Unicode
  18. #define LPTSTR char*
  19. #define TCHAR char
  20. #define _T(x) (x)
  21.  
  22. ///////////////////////////////////////////////////////////////////////////////
  23. //
  24. //    convenience items
  25. //
  26. #define streq(x,y) (!strcmp((x),(y)))
  27. #define NO_XRT_SUPPORT "WOSA/XRT\tDATA\nFORMAT\tNOT\nYET\tSUPPORTED...\n" // default
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Numeric constants
  32. //
  33.  
  34. // Set user-definable defaults
  35. const short    TICK_WIDTH                 = 1;
  36. const long    SCROLL_INTERVAL            = 1;    // 60 ticks == 1 second
  37. const long    RELOAD_INTERVAL         = 3600; // 60 ticks == 1 second
  38.  
  39. // other constants
  40.  
  41. // the max que size is set large because we've optimized the CTick objects and
  42. // the usage thereof in CTickControl to require minimum memory.  We don't keep
  43. // old renderings around in any offscreen bitmaps.
  44. const unsigned long QUEUE_SIZE         = 0x7FFFFFFF; // not max because we still detect overflow
  45.  
  46. // token used in parsing ticks.  Logic depends on TICKTOKENS being a
  47. // concatenation of CRCHAR AND LFCHAR.  Saw no need for anything more elegant.
  48. const char    NAMEVALUETOKENS[]         = "\t";
  49. const char    TICKTOKENS[]             = "\r\n"; // must be concatenation of CRCHAR and LFCHAR
  50. const char    CRCHAR                    = '\r'; // <-- tied to TICKTOKENS
  51. const char    LFCHAR                    = '\n'; // <-- tied to TICKTOKENS
  52.  
  53. // Somewhat arbitrary
  54. const int    MAX_URL_STRING_LENGTH     = 1024;
  55.  
  56. // data validation
  57. typedef enum tagDataValidation
  58. {
  59.     dataUnconfirmed        = 0,
  60.     dataValid            = 1,
  61.     dataInvalid            = 2
  62. } DataValidation;
  63.  
  64. /////////////////////////////////////////////////////////////////////////////
  65. //
  66. // Dumb Structs
  67. //
  68.  
  69. typedef struct
  70. {
  71.     DateTimeRec     time;
  72.     unsigned long     ticks;
  73.     unsigned long     idleValue;
  74.     unsigned long     idleAccumulator;
  75.     Boolean         changed;
  76. }
  77. Timer;
  78.  
  79. typedef struct
  80. {
  81.     Style    textFace;
  82.     short    textFont;
  83.     short    textSize;
  84.     short    textMode;
  85. }
  86. FontParams;
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. //
  90. // CTickerControl class definition
  91. //
  92.  
  93. class CTickerControl : 
  94.     public CBaseControl, 
  95.     public CBaseBindStatusCallback,
  96.     public CErrorControl
  97. {
  98. public:
  99.     
  100.     // *** CPictControl methods ***
  101.     CTickerControl();
  102.     ~CTickerControl();
  103.  
  104.     // *** IIUnknown methods ***
  105.     STDMETHOD (QueryInterface)(REFIID inRefID, void** outObj);
  106.  
  107.     // *** IControl methods ***
  108.     STDMETHOD (Draw) (THIS_ DrawContext* inContext);
  109.     STDMETHOD (DoMouse)(THIS_ MouseEventType inMouseET, PlatformEvent* inEvent);
  110.     STDMETHOD (DoIdle)(THIS_ Uint32 idleRefCon) ;
  111.  
  112.     //  *** IPersistPropertyBag methods ***
  113.     STDMETHOD(Load)(IPropertyBag* propertyBag, IErrorLog* errorLog);
  114.     STDMETHOD(LoadTextState)(IPropertyBag * propertyBag, IErrorLog * errorLog);
  115.  
  116.     //  *** IBindStatusCallback methods ***
  117.     STDMETHOD(OnStopBinding)(HRESULT result, const char* error);
  118.     STDMETHOD(OnDataAvailable)(DWORD BSCF, DWORD size, FORMATETC* formatEtc, STGMEDIUM* stgMedium);
  119.  
  120. public: // accessors for CTick
  121.     Boolean GetUserOffsetValues(void) { return mUserOffsetValues; }
  122.     short GetOffsetValues(void) { return mOffsetValues; }
  123.     void GetForeColor(RGBColor * theColor) { *theColor = mForeColor; }
  124.     void GetBackColor(RGBColor * theColor) { *theColor = mBackColor; }
  125.     
  126. friend CTickerError;
  127.     
  128. protected:
  129.     void OnNewTextData(void);
  130.     void PrepareOffscreenWorld(void);
  131.     void MoveTicker(short nMove);
  132.     CTick * GetNextTick(void);
  133.     void ClearDisplay(void);
  134.     void MoveOnScreen(DrawContext* Context = NULL);
  135.     Boolean LoadColor(RGBColor * theColor, char * colorString);
  136.     Boolean IsXRT(FORMATETC* FormatEtc);
  137.     Boolean SaveLeftOvers(char * theData);
  138.     BitMap * GetOffscreenBitMap(void);
  139.     void ReleaseOffscreenBitMap(BitMap * offscreenBitMap);
  140.     void ReloadTicker(void);
  141.     void BindToData(void);
  142.     void ClearQueues(void);
  143.     Boolean ContinueRead(void);
  144.     
  145. protected: // user-adjustable parameters
  146.     char            mDataURL[MAX_URL_STRING_LENGTH];    // location of the data
  147.     Boolean            mDataActive;            // use data? (do nothing otherwise)
  148.     short            mScrollWidth;            // how big a chunk we scroll at a time
  149.     long            mScrollInterval;        // the time between scrolling jumps (ticks)
  150.     long            mReloadInterval;        // how long between data fetches (in ticks)
  151.     RGBColor        mForeColor;                // foreground color specifier
  152.     RGBColor        mBackColor;                // background color specifier
  153.     short             mOffsetValues;            // how much (in pixels) we offset the value from the name.
  154.     Boolean            mUserOffsetValues;        // did the user specify an offset value?
  155.  
  156. protected: // internal variables
  157.     long            mBirthTime;                // the time at which the control is born
  158.     long            mNextScrollTime;        // the next point at which we scroll
  159.     long            mNextReloadTime;        // the next point at which we reload data
  160.     char *            mData;                    // the textual data being displayed
  161.     char *            mDataTemp;                // used for mData reallocation
  162.     Boolean            mBound;                    // bind status
  163.     LPBINDHOST         mBindSite;                // site we bind to (duh)
  164.     Boolean            mFeedDown;                // is the data feed down?
  165.     GWorldPtr        mOffscreenGWorld;        // where all the drawing gets done
  166.     short            mGWorldPixelDepth;        //  how deep is the offscreen GWorld
  167.     Rect            mRectOffscreenBounds;    //  bounds of offscreen world
  168.     CTabHandle        mGWorldCTable;            //  color table for the offscreen GWorld
  169.     GDHandle        mGWorldAGDevice;        //  graphics device for the offscreen GWorld
  170.     GWorldFlags        mGWorldFlags;            //  flags for offscreen GWorld
  171.     PixMapHandle    mPixOffscreenPixMap;    // pixmap of offscreen world
  172.     deque<CTick*>    mQNew;                    // CTick objects that have yet to be drawn
  173.     deque<CTick*>    mQCache;                // CTick objects that have already been drawn once
  174.     CTick*            mOnstage;                // Currently being drawn
  175.     long            mMaxCacheSize;            // limit on number of ticks
  176.     char *            mCurrentLeftOvers;        // any incomplete tick data from the last new data
  177.     unsigned long    mReadTillNow;            // how much data we've actuall pulled from the stream
  178.     Boolean            mOffscreenWorldReady;    // tells us when the offscreen gworld is set up
  179.     Boolean            mOffscreenImageReady;    // tells us when we've got an offscreen image to move on screen
  180.     Boolean            mPurgeOnstage;            // trash the current onstage tick when we load the next one
  181.     DataValidation    mDataValidation;        // used to confirm valid data
  182.     Boolean            mIsIdling;                // TRUE if we are idling
  183. };
  184.  
  185. #endif // __CTickerControl_h__
  186.