home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / include / pagecanvas.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-11  |  4.4 KB  |  180 lines

  1. #pragma once
  2.  
  3. //-----------------------------------------------------------------------------------//
  4. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  5. //                             ISBN  0-13-086985-6                                   //
  6. //                                                                                   //
  7. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  8. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  9. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  10. //                                                                                   //
  11. //  FileName   : pagecancas.h                                                         //
  12. //  Description: Multiple page, device independent layout                            //
  13. //  Version    : 1.00.000, May 31, 2000                                              //
  14. //-----------------------------------------------------------------------------------//
  15.  
  16. #include "win.h"
  17. #include "canvas.h"
  18. #include "scrollcanvas.h"
  19.  
  20. // 1440 = LCM(72, 96, 120, 360)
  21. // 7200 = LCM(72, 96, 120, 360, 600)
  22.  
  23. #ifdef NT_ONLY
  24. typedef enum { ONEINCH = 7200 };
  25. #else
  26. typedef enum { ONEINCH = 1440 };
  27. #endif
  28.  
  29. class KSurface
  30. {
  31. public:
  32.     typedef enum {     BASE_DPI   = ONEINCH,
  33.                     MARGIN_X   = 16,
  34.                     MARGIN_Y   = 16
  35.                 };
  36.  
  37.     KOutputSetup m_OutputSetup;
  38.  
  39.     int      m_nSurfaceWidth;   // total surface width  in pixel
  40.     int   m_nSurfaceHeight;  // total surface height in pixel
  41.  
  42.     SIZE  m_Paper;        // in BASE_DPI
  43.     RECT  m_Margin;        // in BASE_DPI
  44.     RECT  m_MinMargin;    // in BASE_DPI
  45.  
  46.     int   m_nZoom;        // 100 for 1:1
  47.     int      m_nScale;        // GetDeviceCaps(hDC, LOGPIXELSX) * zoom / 100
  48.     
  49.     int px(int x, int col) // from base_dpi to screen
  50.     {
  51.         return ( x + m_Paper.cx * col ) * m_nScale / BASE_DPI + MARGIN_X * (col+1);
  52.     }
  53.  
  54.     int py(int y, int row) // from base_dpi to screen
  55.     {
  56.         return ( y + m_Paper.cy * row ) * m_nScale / BASE_DPI + MARGIN_Y * (row+1);
  57.     }
  58.  
  59. public:
  60.  
  61.     int GetDrawableWidth(void)
  62.     {
  63.         return m_Paper.cx - m_Margin.left - m_Margin.right;
  64.     }
  65.     
  66.     int GetDrawableHeight(void) 
  67.     {
  68.         return m_Paper.cy - m_Margin.top  - m_Margin.bottom;
  69.     }
  70.     
  71.     virtual int GetColumnCount(void)
  72.     {
  73.         return 1;
  74.     }
  75.  
  76.     virtual int  GetPageCount(void)
  77.     {
  78.         return 1;    // single page
  79.     }
  80.  
  81.     virtual const TCHAR * GetDocumentName(void)
  82.     {
  83.         return _T("KSurface - Document");
  84.     }
  85.  
  86.     virtual void DrawPaper(HDC hDC, const RECT * rcPaint, int col, int row);
  87.     virtual void CalculateSize(void);
  88.     virtual void SetPaper(void);
  89.     virtual void RefreshPaper(void);
  90.  
  91.     virtual void UponDrawPage(HDC hDC, const RECT * rcPaint, int width, int height, int pageno=1);
  92.     virtual bool UponSetZoom(int zoom);
  93.     virtual void UponInitialize(HWND hWnd);
  94.     virtual void UponDraw(HDC hDC, const RECT * rcPaint);
  95.     virtual bool UponPrint(HDC hDC, const TCHAR * pDocName);
  96.     virtual bool UponFilePrint(void);
  97.     virtual bool UponFilePageSetup(void);
  98. };
  99.  
  100.  
  101. ///////////////////////////////////////////////////////////
  102.  
  103.  
  104. class KPageCanvas : public KScrollCanvas, public KSurface
  105. {
  106. public:
  107.     typedef enum { View_NoChange = 0, View_Redraw = 1, View_Resize = 2 };
  108.  
  109. protected:
  110.     HMENU        m_hViewMenu;
  111.     int            m_nMenuID;
  112.     HBRUSH        m_hBackground;
  113.     
  114.     int            m_nPixelWidth;
  115.     int            m_nPixelHeight;
  116.  
  117.     virtual void OnDraw(HDC hdc, const RECT * rcPaint)
  118.     {
  119.         UponDraw(hdc, rcPaint);
  120.     }
  121.  
  122.     void GetDimension(void) // synchronize with KSurface
  123.     {
  124.         m_nPixelWidth  = m_nSurfaceWidth;
  125.         m_nPixelHeight = m_nSurfaceHeight;
  126.     }
  127.  
  128.     int SetZoom(int zoom)
  129.     {
  130.         if ( UponSetZoom(zoom) )
  131.         {
  132.             GetDimension();
  133.             return View_Resize;
  134.         }
  135.         else
  136.             return View_NoChange;
  137.     }
  138.  
  139. public:
  140.  
  141.     virtual const TCHAR * GetClassName(void) const
  142.     {
  143.         return _T("KPageCanvasCanvas");
  144.     }
  145.  
  146.     int GetPixelWidth(void) const
  147.     {
  148.         return m_nPixelWidth;
  149.     }
  150.  
  151.     int GetPixelHeight(void) const
  152.     {
  153.         return m_nPixelHeight;
  154.     }
  155.  
  156.     virtual int  OnCommand(int cmd, HWND hWnd) = 0;
  157.     virtual void OnCreate(void);    
  158.     
  159.     virtual int  OnKey(int vkey)
  160.     {
  161.         return View_NoChange;
  162.     }
  163.  
  164.     void Response(int rslt);
  165.  
  166.     virtual LRESULT WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  167.  
  168.     void GetWndClassEx(WNDCLASSEX & wc);
  169.     
  170. public:
  171.  
  172.     bool Initialize(HINSTANCE hInstance, KStatusWindow * pStatus, int menuid);
  173.  
  174.     KPageCanvas(HBRUSH hBackground = NULL);
  175.  
  176.     virtual ~KPageCanvas()
  177.     {
  178.     }
  179. };
  180.