home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n08 / sketchsc.exe / USER.CPP < prev    next >
C/C++ Source or Header  |  1995-08-01  |  6KB  |  216 lines

  1. //-----------------------------------------------------------------------
  2. // USER.CPP: Implemenation for the user_interface (view) class
  3. //-----------------------------------------------------------------------
  4.  
  5. #include "stdafx.h"
  6. #include "sketch.h"
  7.  
  8. #include "user.h"
  9. #include "data.h"
  10.  
  11. #include "mywin.h"
  12. #include <limits.h>    // for INT_MIN and INT_MAX
  13.  
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // user_interface
  21.  
  22. IMPLEMENT_DYNCREATE(user_interface, CScrollView)
  23.  
  24. BEGIN_MESSAGE_MAP(user_interface, CScrollView)
  25.     //{{AFX_MSG_MAP(user_interface)
  26.     ON_COMMAND(ID_DISPLAYASTEXT, OnDisplayastext)
  27.     ON_UPDATE_COMMAND_UI(ID_DISPLAYASTEXT, OnUpdateDisplayastext)
  28.     ON_WM_LBUTTONDOWN()
  29.     ON_WM_MOUSEMOVE()
  30.     ON_WM_LBUTTONUP()
  31.     ON_WM_SIZE()
  32.     ON_COMMAND(ID_TRACELINE, OnTraceline)
  33.     //}}AFX_MSG_MAP
  34.     // Standard printing commands
  35.     ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  36.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  37. END_MESSAGE_MAP()
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // user_interface construction/destruction
  41.  
  42. user_interface::user_interface() : dwg_object        (0)
  43.                                  , display_as_text    (0)
  44. {
  45.     // Install random mapping mode and size. This is required by the
  46.     // framework. OnInitialUpdate (called after the document object
  47.     // exists) will set it for real.
  48.  
  49.     SetScrollSizes( MM_TEXT, CSize(0, 0) );
  50. }
  51.  
  52. /*virtual*/ user_interface::~user_interface()
  53. {}
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // user_interface drawing
  57. //-----------------------------------------------------------------------
  58. void user_interface::OnDraw(CDC* pDC)
  59. {
  60.     data_interface* pDoc = GetDocument();
  61.     ASSERT_VALID(pDoc);
  62.  
  63.      device dc(pDC);
  64.     rect_clip clip_rect( dc );
  65.  
  66.     if( !clip_rect.IsRectEmpty() )
  67.     {
  68.         if( display_as_text )
  69.             pDoc->print_all_objects_in_this_rect( &dc, CRect(0,0,INT_MAX,INT_MAX), 1 );
  70.         else
  71.             pDoc->print_all_objects_in_this_rect( &dc, clip_rect, 0 );
  72.     }
  73. }
  74. //-----------------------------------------------------------------------
  75. /*afx_msg*/ void user_interface::OnSize(UINT nType, int cx, int cy)
  76. {
  77.     GetDocument()->set_up_scrolling( this );
  78.     CScrollView::OnSize(nType, cx, cy);
  79. }
  80. //-----------------------------------------------------------------------
  81. /*virtual*/ void user_interface::OnInitialUpdate( void )
  82. {
  83.     GetDocument()->set_up_scrolling( this );
  84.     CScrollView::OnInitialUpdate();
  85. }
  86. //-----------------------------------------------------------------------
  87. /*virtual*/ void user_interface::OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint )
  88. {
  89.     // This function is called implicitly by OnInitialUpdate() as well
  90.     // as being called from UpdateAllViews. In the former case, all
  91.     // arguments are zero or NULL. It is also called explicitly
  92.     // to update an entire window when all objects in the document
  93.     // have been deleted.
  94.  
  95.     Invalidate();
  96. }
  97. //-----------------------------------------------------------------------
  98. void user_interface::new_drawing_element( drawing_element *element )
  99. {
  100.     if( display_as_text )    // for text displays, just invalidate the whole window
  101.         Invalidate();
  102.     else                    // if image, invaliate only the rectangle for the new object.
  103.     {
  104.         device        dc            ( this    );
  105.         rect_client client_rect    ( dc    );
  106.         if(  element->is_in( client_rect ) )
  107.             element->invalidate(this);
  108.     }
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // user_interface printing
  112.  
  113. BOOL user_interface::OnPreparePrinting(CPrintInfo* pInfo)
  114. {
  115.     // default preparation
  116.     return DoPreparePrinting(pInfo);
  117. }
  118.  
  119. void user_interface::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  120. {
  121.     // TODO: add extra initialization before printing
  122. }
  123.  
  124. void user_interface::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  125. {
  126.     // TODO: add cleanup after printing
  127. }
  128.  
  129. /////////////////////////////////////////////////////////////////////////////
  130. // user_interface diagnostics
  131.  
  132. #ifdef _DEBUG
  133. void user_interface::AssertValid() const
  134. {
  135.     CScrollView::AssertValid();
  136. }
  137.  
  138. void user_interface::Dump(CDumpContext& dc) const
  139. {
  140.     CScrollView::Dump(dc);
  141. }
  142.  
  143. data_interface* user_interface::GetDocument() // non-debug version is inline
  144. {
  145.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(data_interface)));
  146.     return (data_interface*)m_pDocument;
  147. }
  148. #endif //_DEBUG
  149.  
  150. /////////////////////////////////////////////////////////////////////////////
  151. // user_interface message handlers
  152.  
  153. void user_interface::OnLButtonDown( UINT flags, CPoint point )
  154. {
  155.     // We don't want to accept any mouse input at all if displaying objects
  156.     // as text. By not calling SetCapture(), OnMouseMove() and OnLButtonUp()
  157.     // are both effectivly disabled.
  158.  
  159.     if( !display_as_text )
  160.     {
  161.         device dc ( this   );
  162.         dc.DPtoLP ( &point );
  163.  
  164.         SetCapture();
  165.         dwg_object = GetDocument()->give_me_an_empty_drawing_element();
  166.         dwg_object->start_load( point, &dc );
  167.     }
  168. }
  169.  
  170. void user_interface::OnMouseMove( UINT flags, CPoint point )
  171. {
  172.     if( ::GetCapture() == m_hWnd && dwg_object )
  173.     {
  174.         device dc( this   );
  175.         dc.DPtoLP( &point );
  176.  
  177.         dwg_object->mouse_has_moved( point, &dc );
  178.     }
  179. }
  180.  
  181. void user_interface::OnLButtonUp( UINT flags, CPoint point )
  182. {
  183.     if( ::GetCapture() == m_hWnd && dwg_object )
  184.     {
  185.         device dc( this    );
  186.         dc.DPtoLP( &point    ); // convert point to document coordinates
  187.  
  188.         ReleaseCapture();
  189.  
  190.         int redraw =
  191.         dwg_object     ->end_load          (point, &dc            );
  192.         GetDocument()->am_done_loading(this,  dwg_object    );
  193.  
  194.         if( redraw )        // Update all of current view to clean up after
  195.             Invalidate();    // creating a line. (Document doesn't update current view.)
  196.  
  197.         dwg_object = NULL;    
  198.     }
  199. }
  200.  
  201. void user_interface::OnDisplayastext() 
  202. {
  203.     display_as_text = !display_as_text ;
  204.     Invalidate();
  205. }
  206.  
  207. void user_interface::OnUpdateDisplayastext(CCmdUI* pCmdUI) 
  208. {
  209.     pCmdUI->SetCheck( display_as_text );
  210. }
  211.  
  212. void user_interface::OnTraceline() 
  213. {
  214.     TRACE("================================================\n");
  215. }
  216.