home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F37605_ToolList.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-16  |  5.8 KB  |  234 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // ToolList.cpp : implementation file
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "InsTool.h"
  16. #include "ToolList.h"
  17. #include "TDialog.h"
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. /////////////////////////////////////////////////////////////////////////////
  26. // ToolList
  27.  
  28. CSymbolsList::CSymbolsList()
  29. {
  30. }
  31.  
  32. CSymbolsList::~CSymbolsList()
  33. {
  34. }
  35.  
  36. void CSymbolsList::OnFinalRelease()
  37. {
  38.     CListBox::OnFinalRelease();
  39. }
  40.  
  41.  
  42. BEGIN_MESSAGE_MAP(CSymbolsList, CListBox)
  43.     //{{AFX_MSG_MAP(CToolList)
  44.     ON_WM_LBUTTONDOWN()
  45.     ON_WM_LBUTTONUP()
  46.     ON_WM_MOUSEMOVE()
  47.     ON_CONTROL_REFLECT(LBN_SELCHANGE, OnSelchange)
  48.     //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // ToolList message handlers
  53.  
  54. void CSymbolsList::RefreshFileList(CString path)
  55. {
  56.     struct _finddata_t c_file;
  57.     long hFile;
  58.     hFile = 0;
  59.     int i = _chdir(path);  // the directory that contains symbols. 
  60.     ResetContent();
  61.     m_cstrCurSelected = "";
  62.     /* Find first .c file in current directory */
  63.     if (i == 0)
  64.     {
  65. // We allows here only tcw files as files that contains symbols
  66. // add any file extension (that TurboCad supports) here
  67.         if( (hFile = _findfirst( "*.tcw", &c_file )) != -1L )//# Non-localizable string#
  68.         {
  69.             /* Find the rest of the .c files */
  70.             AddString(c_file.name); //add first file to the list
  71.   
  72.             while( _findnext( hFile, &c_file ) == 0 )            
  73.             {
  74.                 AddString(c_file.name);
  75.                     
  76.             }
  77.             _findclose( hFile );  
  78.         }
  79.     }
  80.  
  81. }
  82.  
  83.  
  84.  
  85. void CSymbolsList::OnLButtonDown(UINT nFlags, CPoint point) 
  86. {
  87.     CListBox::OnLButtonDown(nFlags, point);
  88.     BOOL bRet;
  89.  
  90.     m_LB_DOWNpoint.x = point.x;
  91.     m_LB_DOWNpoint.y = point.y;
  92.     
  93.     CString cstrSelected = "";
  94.     CListBox *pSymbolsList = (CListBox *) (GetParent()->GetDlgItem(IDC_SYMBOLSLIST));
  95.  
  96.     UINT index = ItemFromPoint(point, bRet);
  97.     if (bRet == FALSE)
  98.     {
  99.         m_bDrag = TRUE; 
  100.         GetText(index, cstrSelected);
  101.     }
  102.     if (m_cstrCurSelected != cstrSelected && cstrSelected != "") // check if the current selection is changed
  103.     {
  104.         BeginWaitCursor();    
  105.         CPreviewWnd *pViewWnd = (CPreviewWnd *) (((CTDialog*)GetParent())->GetDlgItem(IDC_PREVIEW));
  106.         pViewWnd->ClearAll();
  107.         int index = pSymbolsList->GetCurSel();
  108.         
  109.         bRet = FALSE;
  110.         bRet = pViewWnd->CreatePreview();
  111.         if(bRet == FALSE)
  112.             return;
  113.         
  114.         bRet = FALSE;
  115.         bRet = pViewWnd->DoPreview();
  116.         if (bRet == FALSE)
  117.         {
  118.             CString szMess;
  119.             CString szCap;
  120.             szMess.LoadString(IDS_STRING105);
  121.             szCap.LoadString(IDS_STRERROR);
  122.             MessageBox(LPCTSTR(szMess),LPCTSTR(szCap), MB_OK);
  123.             pSymbolsList->DeleteString(index);
  124.         }
  125.         m_cstrCurSelected = cstrSelected;
  126.         pViewWnd->Invalidate();
  127.         EndWaitCursor();
  128.     }
  129. }
  130.  
  131. void CSymbolsList::OnLButtonUp(UINT nFlags, CPoint point) 
  132. {
  133.     CListBox::OnLButtonUp(nFlags, point);
  134.     m_bDrag = FALSE;
  135.  
  136.     CPoint Pt = point;
  137.     ClientToScreen(&Pt);
  138.     CWnd *pClickWNd = WindowFromPoint(Pt);
  139.         
  140.     if(pClickWNd && pClickWNd != this)
  141.     {
  142.         pClickWNd->ScreenToClient(&Pt);
  143.         pClickWNd->PostMessage(WM_LBUTTONUP, nFlags, MAKELONG(Pt.x, Pt.y));
  144.         SetCursor(m_OldCursor);
  145.         ShowCursor(TRUE);
  146.         return;
  147.     }
  148.     else
  149.     {
  150.         SetCursor(m_OldCursor);
  151.         ShowCursor(TRUE);
  152.     }
  153. }
  154.  
  155. void CSymbolsList::OnMouseMove(UINT nFlags, CPoint point) 
  156. {
  157.     
  158.     if(nFlags & MK_LBUTTON)
  159.     {
  160.         
  161.         int dx = m_LB_DOWNpoint.x - point.x;
  162.         int dy = m_LB_DOWNpoint.y - point.y;
  163.         CPoint Pt = point;
  164.  
  165.         if((abs(dx) > 1 || abs(dy) > 1) && m_bDrag)
  166.         {
  167.             // if dragging
  168.             if (((CTDialog*)GetParent())->m_dwEventConnection == 0)
  169.             {
  170.                 ((CTDialog*)GetParent())->ConnectEvents();
  171.             }
  172.  
  173.             m_OldCursor = GetCursor();
  174.             m_DragCursor = LoadCursor(AfxGetInstanceHandle( ), MAKEINTRESOURCE(IDC_CURSOR1));
  175.             SetCursor(m_DragCursor);
  176.             ShowCursor(TRUE);
  177.             m_bDrag = FALSE;
  178.             m_LB_DOWNpoint.x = -1;
  179.             m_LB_DOWNpoint.y = -1;
  180.             ((CTDialog*)GetParent())->m_FirstClick = TRUE;
  181.             return;
  182.         }
  183.  
  184.         ClientToScreen(&Pt);
  185.         CWnd *pClickWNd = WindowFromPoint(Pt);
  186.  
  187.         if(pClickWNd && pClickWNd != this)
  188.         {
  189.             pClickWNd->ScreenToClient(&Pt);
  190.             pClickWNd->PostMessage(WM_MOUSEMOVE, nFlags, MAKELONG(Pt.x, Pt.y));
  191.         }
  192.     }
  193. }
  194.  
  195. void CSymbolsList::OnSelchange() 
  196.  
  197. {
  198.     CString cstrSelected;
  199.     BOOL bRet = FALSE;
  200.  
  201.     CListBox *pSymbolsList = (CListBox *) (GetParent()->GetDlgItem(IDC_SYMBOLSLIST));
  202.     int index = pSymbolsList->GetCurSel();
  203.  
  204.     HCURSOR hOC = ::SetCursor(::LoadCursor(NULL,IDC_WAIT));
  205.  
  206.     pSymbolsList->GetText(index, cstrSelected);
  207.     
  208.     if (m_cstrCurSelected != cstrSelected && cstrSelected != "")
  209.     {
  210.         CPreviewWnd *pViewWnd = (CPreviewWnd *) (((CTDialog*)GetParent())->GetDlgItem(IDC_PREVIEW));
  211.         pViewWnd->ClearAll();
  212.         
  213.         bRet = pViewWnd->CreatePreview();
  214.         if(bRet == FALSE)
  215.             return;
  216.         
  217.         bRet = FALSE;
  218.         bRet = pViewWnd->DoPreview();
  219.         if (bRet == FALSE)
  220.         {
  221.             CString szMess;
  222.             CString szCap;
  223.             szMess.LoadString(IDS_STRING105);
  224.             szCap.LoadString(IDS_STRERROR);
  225.             //MessageBox("The drawing have Brush styles or Line styles different from default. This sample can't work with such files", "ERROR!", MB_OK);//# Localizable string#
  226.             MessageBox(LPCTSTR(szMess),LPCTSTR(szCap), MB_OK);
  227.             pSymbolsList->DeleteString(index);
  228.         }
  229.         m_cstrCurSelected = cstrSelected;
  230.     }
  231.  
  232.     ::SetCursor(hOC);
  233. }
  234.