home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvdraw / examples / testwin / testchildwnd.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-19  |  11.4 KB  |  459 lines

  1. // TestChildWnd.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "TestChildWnd.h"
  6. #include "DvDsDll.h"
  7.  
  8. #include "VOfundecl.h"
  9. #include "VPfundecl.h"
  10. #include "VGfundecl.h"
  11. #include "GRfundecl.h"
  12. #include "VUerfundecl.h"
  13.  
  14. #include "Msparams.h"
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. // Data Structure used to rebind/rename vdp's
  23. typedef struct {
  24.   CDvDsDll* pDsDll;     //
  25.   int       arrayIndex;
  26.   BOOL      renameVdp;
  27.   float*    rebindArray;
  28. } VDP_TRAVERSAL_DATA;
  29.  
  30.  
  31. #define TEXT_BUFFER_SIZE 80
  32. static char g_TextBuffer[TEXT_BUFFER_SIZE];
  33.  
  34. extern "C" {
  35.  
  36. GLOBALREF long M_runtype;
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. //
  40. ADDRESS 
  41. CountVdps(OBJECT vd, VARDESC vdp, ADDRESS args)
  42.   int* nVdps = (int*)args;
  43.   (*nVdps)++; 
  44.   return V_CONTINUE_TRAVERSAL; 
  45. }
  46.  
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. //
  50. //  DataViews traversal function that gets called for every vdp if the
  51. //  data browser uses custom tag names.  We ask the browser to supply a
  52. //  human readable name for the vdp so that they appear as expected in
  53. //  graph legends as expected...
  54. //
  55. ADDRESS
  56. RenameRebindVdp(OBJECT data_obj, VARDESC vdp, ADDRESS pData)
  57. {
  58.   VDP_TRAVERSAL_DATA *vdpData = (VDP_TRAVERSAL_DATA*)pData;
  59.  
  60.   // Rename the vdp if necessary...
  61.   if(vdpData->pDsDll && vdpData->renameVdp)
  62.   {
  63.        DV_DSDLLDATA data;
  64.  
  65.       data.m_Context    = DV_DSDLL_GETNAMEBITS;
  66.       data.m_Pvdp       = vdp;
  67.       data.m_pszVarname = 0;
  68.     data.m_pszVartags = 0;
  69.  
  70.       vdpData->pDsDll->HandleRequest(&data, 0);
  71.  
  72.     if(data.m_pszVarname)
  73.       VPvdvarname(vdp,data.m_pszVarname);
  74.   }
  75.  
  76.   // ... now rebind it (special casing text variables)...
  77.   if( VGvdtype( vdp ) != V_T_TYPE )
  78.   {
  79.     TvdPutBuffer(vdp, (ADDRESS)&(vdpData->rebindArray[vdpData->arrayIndex++]));
  80.   }
  81.   else
  82.   {
  83.     VPvddim( vdp, 1, 1, TEXT_BUFFER_SIZE );
  84.     TvdPutBuffer( vdp, (ADDRESS)g_TextBuffer );
  85.   }
  86.  
  87.   return V_CONTINUE_TRAVERSAL;
  88. }
  89.  
  90. }
  91.  
  92.  
  93. UINT CTestChildWnd::m_Speed[] =    { 10, 20, 50, 100, 125, 200, 250, 333, 500, 1000 };
  94.  
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. //
  98. void CALLBACK EXPORT TimerProc(
  99.    HWND hWnd,      //handle of CWnd that called SetTimer
  100.    UINT nMsg,      //WM_TIMER
  101.    UINT nIDEvent,  //timer identification
  102.    DWORD dwTime    //system time
  103. )
  104. {
  105.     CTestChildWnd* runView = (CTestChildWnd*)nIDEvent;
  106.     runView->UpdateView();
  107. }
  108.  
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CTestChildWnd dialog
  112.  
  113.  
  114. CTestChildWnd::CTestChildWnd(UINT aid, VIEW v, char* clut, CWnd* pParent /*=NULL*/)
  115.     : CDialog(CTestChildWnd::IDD, pParent), m_areaID(aid), m_View(v),
  116.   m_Screen(0), m_Drawport(0), m_Loc(0), m_pszClut(clut), m_pRebindArray(0),
  117.   m_NumVdps(0),m_SpeedIndex(DEFAULT_UPD_RATE), m_TimerID(0), m_Running(FALSE),
  118.   m_Paused(FALSE), m_DataCounter(0)
  119. {
  120.     //{{AFX_DATA_INIT(CTestChildWnd)
  121.         // NOTE: the ClassWizard will add member initialization here
  122.     //}}AFX_DATA_INIT
  123. }
  124.  
  125. CTestChildWnd::~CTestChildWnd()
  126. {
  127.   if(m_pRebindArray)
  128.     delete[] m_pRebindArray;
  129. }
  130.  
  131.  
  132. void CTestChildWnd::DoDataExchange(CDataExchange* pDX)
  133. {
  134.     CDialog::DoDataExchange(pDX);
  135.     //{{AFX_DATA_MAP(CTestChildWnd)
  136.         // NOTE: the ClassWizard will add DDX and DDV calls here
  137.     //}}AFX_DATA_MAP
  138. }
  139.  
  140.  
  141. BEGIN_MESSAGE_MAP(CTestChildWnd, CDialog)
  142.     //{{AFX_MSG_MAP(CTestChildWnd)
  143.     ON_WM_CREATE()
  144.     ON_WM_DESTROY()
  145.     ON_WM_PAINT()
  146.     ON_WM_MOUSEMOVE()
  147.     ON_WM_LBUTTONDOWN()
  148.     ON_WM_RBUTTONDOWN()
  149.     ON_WM_LBUTTONUP()
  150.     ON_WM_RBUTTONUP()
  151.     //}}AFX_MSG_MAP
  152. END_MESSAGE_MAP()
  153.  
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. //
  157. //  Simulates reading default.dat. The file default.dat contains 78 numbers
  158. //  repeated over and over.  So does this, with the same numbers found in
  159. //  in the standard default.dat file that gets shipped with DataViews.
  160. //
  161. #define NUM_DATA 78
  162. void CTestChildWnd::UpdateView()
  163. {
  164.   static double DefaultData[NUM_DATA] = {
  165.               0.01,  0.1,   0.4,   0.35,  0.7,
  166.               0.8,   0.2,   0.24,  0.26,  0.43,
  167.               0.54,  0.6,   0.21,  0.32,  0.46,
  168.               0.73,  0.86,  0.92,  0.0,   0.3,
  169.               0.5,   0.73,  0.89,  0.58,  0.3,
  170.               0.5,   0.63,  0.79,  0.83,  0.67,
  171.               0.3,   0.42,  0.57,  0.74,  0.93,
  172.               0.57,  0.35,  0.63,  0.74,  0.87,
  173.               0.94,  0.81,  0.02,  0.4,   0.42,
  174.               0.53,  0.64,  0.40,  0.02,  0.5,
  175.               0.85,  0.87,  0.64,  0.3,   0.4,
  176.               0.6,   0.66,  0.83,  0.75,  0.36,
  177.               0.37,  0.44,  0.52,  0.75,  0.59,
  178.               0.43,  0.1,   0.73,  0.84,  0.81,
  179.               0.73,  0.69,  0.1,   0.58,  0.74,
  180.               0.79,  0.80,  0.79
  181.               };
  182.  
  183.   if(m_DataCounter && !(m_DataCounter % NUM_DATA)) 
  184.   {
  185.     m_DataCounter = 0;
  186.     TRACE0("Resetting data counter...\n");
  187.   }
  188.  
  189.   if(m_pRebindArray)
  190.   {
  191.     for(int i=0;i<m_NumVdps;i++)
  192.       m_pRebindArray[i] = (float)(DefaultData[m_DataCounter++]);
  193.   }
  194.  
  195.     M_runtype = MRUNNING;
  196.   TdpDrawNext(m_Drawport);
  197.  
  198. }
  199.  
  200.  
  201. /////////////////////////////////////////////////////////////////////////////
  202. //
  203. BOOL CTestChildWnd::SetupLoc(const MSG* msg)
  204. {
  205.     if(m_Screen && m_Drawport)
  206.     {
  207.         WINEVENT we;
  208.         GRwe_convert((ADDRESS)msg, &we);
  209.         return (BOOL)TloWinEventSetup(m_Loc,&we,m_Screen,m_Drawport);
  210.     }
  211.     return FALSE;
  212. }
  213.  
  214.  
  215. /////////////////////////////////////////////////////////////////////////////
  216. //
  217. void CTestChildWnd::HandleOnDraw(const MSG* msg)
  218. {
  219.     if(m_Screen && m_Drawport)
  220.     {
  221.         TscSetCurrentScreen(m_Screen);  
  222.         if(TdpIsDrawn(m_Drawport ))
  223.         {
  224.             WINEVENT we;
  225.             GRwe_convert((ADDRESS)msg, &we);
  226.             TdpRedraw(m_Drawport, &we.region, YES);
  227.         }
  228.          else
  229.              TdpDraw(m_Drawport);
  230.     TscFlush(m_Screen);
  231.     }
  232. }
  233.  
  234.  
  235. /////////////////////////////////////////////////////////////////////////////
  236. //
  237. void CTestChildWnd::SetUpdateRate(int rate)
  238. {
  239.   if(rate >=0 && rate < NUM_UPD_RATES)
  240.   {
  241.     m_SpeedIndex = rate;
  242.     InstallTimer();
  243.   }
  244. }
  245.  
  246.  
  247. /////////////////////////////////////////////////////////////////////////////
  248. //
  249. void CTestChildWnd::InstallTimer()
  250. {
  251.     if(m_TimerID)
  252.         KillTimer(m_TimerID);
  253.     m_TimerID = SetTimer((UINT)this,m_Speed[m_SpeedIndex],TimerProc );
  254. }
  255.  
  256.  
  257. /////////////////////////////////////////////////////////////////////////////
  258. //
  259. void CTestChildWnd::HandleMousePointerMsg(const MSG* msg) 
  260. {
  261.     if(m_Screen && m_Running && !m_Paused)
  262.   {
  263.       SetupLoc(msg);
  264.       VUerHandleLocEvent(m_Loc);
  265.   }
  266. }
  267.  
  268.  
  269. /////////////////////////////////////////////////////////////////////////////
  270. //
  271. void CTestChildWnd::StartTest() 
  272. {
  273.     m_Running = TRUE;
  274.     m_Paused = FALSE;
  275.   m_DataCounter = 0;
  276.     UpdateView();
  277.     InstallTimer();
  278. }
  279.  
  280.  
  281. /////////////////////////////////////////////////////////////////////////////
  282. //
  283. void CTestChildWnd::StopTest() 
  284. {
  285.     KillTimer(m_TimerID);
  286.     if (m_Drawport) 
  287.   {
  288.     if(m_pRebindArray)
  289.     {
  290.       for(int i=0;i<m_NumVdps;i++)
  291.         m_pRebindArray[i] = (float)0.0;
  292.     }
  293.         TscErase(m_Screen);
  294.     TdpDraw(m_Drawport);
  295.     }
  296.     m_Running = FALSE;
  297.     m_Paused  = FALSE;
  298. }
  299.  
  300.  
  301. /////////////////////////////////////////////////////////////////////////////
  302. //
  303. void CTestChildWnd::PauseTest() 
  304. {
  305.     if(m_Paused)
  306.     {
  307.         m_Paused = FALSE;
  308.         InstallTimer();
  309.     }
  310.     else
  311.     {
  312.         m_Paused = TRUE;
  313.         KillTimer(m_TimerID);
  314.         m_TimerID = 0;
  315.     }
  316. }
  317.  
  318.  
  319. /////////////////////////////////////////////////////////////////////////////
  320. // CTestChildWnd message handlers
  321.  
  322.  
  323. /////////////////////////////////////////////////////////////////////////////
  324. //
  325. int CTestChildWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  326. {
  327.     if (CDialog::OnCreate(lpCreateStruct) == -1)
  328.         return -1;
  329.     
  330.     // Parent dialog contains a static group box we'll use as a border for
  331.     // our actual test area screen.  Locate it, size it, and make our child
  332.     // dialog fit inside it...
  333.     m_pParent = GetParent();
  334.     CWnd *testArea = m_pParent->GetDlgItem(m_areaID);
  335.  
  336.   CRect testAreaRect;
  337.  
  338.     testArea->GetWindowRect(&testAreaRect);
  339.      m_pParent->ScreenToClient(&testAreaRect);
  340.     MoveWindow(&testAreaRect, FALSE);
  341.  
  342.     // Done with static border...
  343.     testArea->DestroyWindow();
  344.     
  345.     return 0;
  346. }
  347.  
  348.  
  349. /////////////////////////////////////////////////////////////////////////////
  350. //
  351. void CTestChildWnd::OnDestroy() 
  352. {
  353.     TdpDestroy(m_Drawport);
  354.     TviDestroy(m_View);
  355.     TscClose(m_Screen);
  356.     VOloDereference(m_Loc);
  357.     CDialog::OnDestroy();
  358. }
  359.  
  360.  
  361. /////////////////////////////////////////////////////////////////////////////
  362. //
  363. void CTestChildWnd::OnPaint() 
  364. {
  365.   HandleOnDraw(GetCurrentMessage());
  366. }
  367.  
  368.  
  369. /////////////////////////////////////////////////////////////////////////////
  370. //
  371. BOOL CTestChildWnd::OnInitDialog() 
  372. {
  373.     CDialog::OnInitDialog();
  374.     
  375.   // Check to see if the current data browser uses custom vdp names, and if
  376.   // so, we'll need to go through all of the vdp's used in graphs and rename
  377.   // them to their 'human readable' form (which the data browser will supply)
  378.   // so that they will make sense in graph legends...
  379.     CDvDsDll* pDsDll = 0;
  380.  
  381.   VDP_TRAVERSAL_DATA args;
  382.  
  383.     DVIGetInterface(IID_Datasource, (void**)&pDsDll);
  384.  
  385.   if(pDsDll)
  386.   {
  387.       DV_DSDLLDATA data;
  388.        data.m_Context = DV_DSDLL_QUERYDLL;
  389.       pDsDll->HandleRequest(&data, this);
  390.  
  391.     args.renameVdp = (BOOL)(data.m_Context & DV_DSDLL_USESCUSTOMTAGS);
  392.     args.pDsDll    = pDsDll;
  393.   }
  394.   else
  395.   {
  396.     args.renameVdp = FALSE;
  397.     args.pDsDll    = 0;
  398.   }
  399.  
  400.   OBJECT drawing = TviGetDrawing(m_View);
  401.   TobForEachVdp(drawing,CountVdps,(ADDRESS)&m_NumVdps);
  402.   if(m_NumVdps)
  403.     m_pRebindArray = new float[m_NumVdps];
  404.  
  405.   args.arrayIndex  = 0;
  406.   args.rebindArray = m_pRebindArray;
  407.   TobForEachVdp(drawing,RenameRebindVdp,(ADDRESS)&args);
  408.  
  409.   // Create a location object...used to make input objects respond...
  410.     m_Loc = VOloCreate();
  411.  
  412.   // OK, now we can set up the DataViews screen and drawport.  One noteworthy
  413.   // point here is that the interface to DV-Draw, besides including a cloned
  414.   // view of the view being currently edited, it also passed in a viewport 
  415.   // rectangle if the user happens to be zoomed in, allowing you to run the
  416.   // view as the user currently sees it.  If this is the desired behavior, then
  417.   // this is where it would be done...
  418.  
  419.     m_Screen = TscOpenSet("W", m_pszClut,
  420.                     V_WIN32_WINDOW_HANDLE, GetSafeHwnd(),
  421.                     V_WIN32_DOUBLE_BUFFER,TRUE,
  422.                     V_ACTIVE_CURSOR,V_END_OF_LIST );
  423.  
  424.     m_Drawport = TdpCreateStretch(m_Screen,m_View,0,0);
  425.  
  426.     M_runtype = MRUNNING;
  427.  
  428.     TscErase(m_Screen);
  429.     TdpDraw(m_Drawport);
  430.     
  431.     return TRUE;  // return TRUE unless you set the focus to a control
  432.                   // EXCEPTION: OCX Property Pages should return FALSE
  433. }
  434.  
  435.  
  436. /////////////////////////////////////////////////////////////////////////////
  437. //
  438. //  Mouse and pointer message handlers...
  439. //
  440. void CTestChildWnd::OnMouseMove(UINT nFlags, CPoint point) 
  441. { HandleMousePointerMsg(GetCurrentMessage()); }
  442.  
  443. void CTestChildWnd::OnLButtonDown(UINT nFlags, CPoint point) 
  444. { HandleMousePointerMsg(GetCurrentMessage()); }
  445.  
  446. void CTestChildWnd::OnRButtonDown(UINT nFlags, CPoint point) 
  447. { HandleMousePointerMsg(GetCurrentMessage()); }
  448.  
  449. void CTestChildWnd::OnLButtonUp(UINT nFlags, CPoint point) 
  450. { HandleMousePointerMsg(GetCurrentMessage()); }
  451.  
  452. void CTestChildWnd::OnRButtonUp(UINT nFlags, CPoint point) 
  453. { HandleMousePointerMsg(GetCurrentMessage()); }
  454.  
  455.  
  456. /////////////////////////////////////////////////////////////////////////////
  457. //
  458.