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

  1. //-----------------------------------------------------------------------
  2. // MYWIN.CPP:            Various Windows support classes
  3. //-----------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include "mywin.h"
  6.  
  7. #include <stdarg.h>
  8. //-----------------------------------------------------------------------
  9. int mapping_mode::mode = mapping_mode::MM_NONE;
  10. //-----------------------------------------------------------------------
  11. /*virtual*/ void device::prepare( void )
  12. {
  13.     // If the owning window is a view, call it's OnPrepareDC
  14.     // function to set up the DC, otherwise just swap in the
  15.     // mapping mode. User can override this function to do
  16.     // other things if necessary.
  17.  
  18.     ASSERT( owner );    
  19.  
  20.     if( owner->IsKindOf( RUNTIME_CLASS(CView) ) )
  21.         ((CView *)owner)->OnPrepareDC( this );
  22.     else
  23.         SetMapMode( mapping_mode() );
  24. }
  25. //-----------------------------------------------------------------------
  26. device::device(const CWnd *pWnd)
  27.                                         : owner     ( pWnd )
  28.                                         , cursor    ( 0, 0 )
  29.                                         , bounding    ( 0,0,0,0 )
  30. {
  31.     ASSERT( pWnd                     );
  32.     ASSERT( ::IsWindow(pWnd->m_hWnd) );
  33.     
  34.     HDC hdc = ::GetDC( owner->GetSafeHwnd() );
  35.  
  36.     if( !Attach( hdc ) )
  37.         AfxThrowResourceException();
  38.  
  39.     prepare();    // User can get control of this virtual function
  40. }
  41. //-----------------------------------------------------------------------
  42. device::device(const CDC *dc)
  43.                                         : owner     ( NULL )
  44.                                         , cursor    ( 0, 0 )
  45.                                         , bounding    ( 0,0,0,0 )
  46. {
  47.     // BUG: The docs claim that CDC::GetWindow() returns the
  48.     //         window associated with a DC. The function isn't
  49.     //        implemented, though, so we can't set owner to
  50.     //        the window unless we create it in device(CWnd);
  51.  
  52.     if( !Attach( dc->m_hDC ) )
  53.         AfxThrowResourceException();
  54. }
  55.  
  56. /*virtual*/ device::~device()
  57. {
  58.     if( owner )
  59.     {
  60.         ASSERT( m_hDC );
  61.         ::ReleaseDC( owner->m_hWnd, m_hDC );
  62.     }
  63.     Detach();
  64. }
  65. //-----------------------------------------------------------------------
  66. void device::invalidate_rect( CRect invalid_region,
  67.                                       int    erase_background /*=TRUE*/ )    
  68. {
  69.     ASSERT( owner );
  70.     LPtoDP( &invalid_region );
  71.     ((CWnd *)owner)->InvalidateRect( &invalid_region, erase_background );
  72. }
  73. //-----------------------------------------------------------------------
  74. CRect *device::get_client_rect( CRect *r ) const
  75. {
  76.     ASSERT( owner );
  77.     owner->GetClientRect( r );
  78.     DPtoLP( r );
  79.     return r;
  80. }
  81. //-----------------------------------------------------------------------
  82. void device::set_up_scrolling( CSize document_size )
  83. {
  84.     // Typically called from the document; document_size must
  85.     // not be passed in by reference---I'm modifying it. The
  86.     // document_size must be in logical units. 
  87.  
  88.     ASSERT( owner );
  89.     ASSERT( owner->IsKindOf(RUNTIME_CLASS(CScrollView)) );
  90.     LPtoDP( &document_size );
  91.     ((CScrollView*)owner)->SetScrollSizes( mapping_mode(), document_size );
  92. }
  93. //-----------------------------------------------------------------------
  94. const CPoint &device::puts( const CString &str )
  95. {
  96.     TEXTMETRIC    tm;             /*=*/ GetTextMetrics( &tm );
  97.     int            tab_separation =   8*tm.tmAveCharWidth;
  98.  
  99.     CSize line_size = TabbedTextOut( cursor.x, cursor.y, str,
  100.                     str.GetLength(),
  101.                     1,                    // nTabPositions,
  102.                     &tab_separation,    // lpnTabStopPositions,
  103.                     0 );                // nTabOrigin );
  104.  
  105.     cursor.y += (line_size.cy + tm.tmExternalLeading);
  106.     return cursor;
  107. }
  108.