home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / include / wx_dc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  10.2 KB  |  374 lines

  1. /*
  2.  * File:     wx_dc.h
  3.  * Purpose:  wxDC device context declaration
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29.  
  30. #ifndef wx_dch
  31. #define wx_dch
  32.  
  33. #include <fstream.h>
  34. #include "common.h"
  35. #include "wx_frame.h"
  36. #include "wx_gdi.h"
  37.  
  38. #ifdef wx_xview
  39. #include "xview/scrollbar.h"
  40. #endif
  41.  
  42. #define wxDEVICE_CANVAS  1  // X canvas
  43. #define wxDEVICE_EPS     2  // Encapsulated PostScript on any platform
  44. #define wxDEVICE_WINDOWS 3  // MS Windows device (canvas, printer)
  45. #define wxDEVICE_PIXMAP  4  // X pixmap
  46.  
  47. #ifdef wx_x
  48. #define MM_TEXT        1
  49. #define MM_ISOTROPIC   2
  50. #define MM_ANISOTROPIC 3
  51. #define MM_LOMETRIC    4
  52. #define MM_HIMETRIC    5
  53. #define MM_TWIPS       6
  54. #endif
  55.  
  56. #define MM_POINTS      7
  57. #define MM_METRIC      8
  58.  
  59.  
  60. class wxCanvas;
  61. class wxDC: public wxObject
  62. {
  63.  public:
  64.   int device;
  65.   Bool ok;
  66.   Bool clipping;
  67.   Bool wx_interactive;
  68.  
  69.   // Coordinate system variables
  70.   float logical_origin_x;
  71.   float logical_origin_y;
  72.  
  73.   float device_origin_x;
  74.   float device_origin_y;
  75.  
  76.   float logical_scale_x;
  77.   float logical_scale_y;
  78.  
  79.   float user_scale_x;
  80.   float user_scale_y;
  81.  
  82.   int mapping_mode;
  83.  
  84.   int yorigin;          // For EPS
  85.   ofstream *pstream;    // PostScript output stream
  86.   float min_x;          // EPS bounding box
  87.   float min_y;
  88.   float max_x;
  89.   float max_y;
  90.   char *title;
  91.   char *filename;
  92. #ifdef wx_x
  93.   // Every time a callback happens, these are set to point to the right values
  94.   // for drawing calls to work
  95.   GC gc;
  96. #ifdef wx_motif
  97.   GC gcBacking;
  98. #endif
  99.   int background_pixel;
  100.   wxColour *current_colour;
  101.   wxBitmap *selected_pixmap;
  102. #endif
  103. #ifdef wx_msw
  104.   int clip_x1;
  105.   int clip_y1;
  106.   int clip_x2;
  107.   int clip_y2;
  108.   HDC cdc;
  109.   Bool dont_delete;
  110.   int window_ext_x;
  111.   int window_ext_y;
  112.  
  113.   // Store all old GDI objects when do a SelectObject,
  114.   // so we can select them back in (this unselecting user's
  115.   // objects) so we can safely delete the DC.
  116.   HBITMAP old_bitmap;
  117.   HPEN    old_pen;
  118.   HBRUSH  old_brush;
  119.   HFONT   old_font;
  120. #endif
  121.   wxCanvas *canvas;
  122.   Bool Colour;
  123.  
  124.   int current_logical_function;
  125.  
  126.   wxPen *current_pen;
  127.   wxBrush *current_brush;
  128.   wxBrush *current_background_brush;
  129.   wxColour *current_text_foreground;
  130.   wxColour *current_text_background;
  131.   wxFont *font;
  132.  
  133.   wxDC(void);
  134.  
  135.   // Create a compatible DC from an existing one
  136.   wxDC(wxDC *old_dc);
  137.  
  138.   // Create a DC corresponding to a canvas
  139.   wxDC(wxCanvas *canvas);
  140.  
  141.   // Create a printer DC
  142.   wxDC(char *driver, char *device, char *output, Bool interactive = TRUE);
  143.  
  144.   ~wxDC(void);
  145.  
  146.   virtual void DrawLine(float x1, float y1, float x2, float y2);
  147.   virtual void DrawPoint(float x, float y);
  148.   virtual void DrawLines(int n, wxPoint points[], float xoffset = 0, float yoffset = 0);
  149.   virtual void DrawLines(wxList *list, float xoffset = 0, float yoffset = 0);
  150.   virtual void DrawPolygon(int n, wxPoint points[], float xoffset = 0, float yoffset = 0);
  151.   virtual void DrawPolygon(wxList *list, float xoffset = 0, float yoffset = 0);
  152.   virtual void DrawRectangle(float x, float y, float width, float height);
  153.   virtual void DrawRoundedRectangle(float x, float y, float width, float height, float radius = 20);
  154.   virtual void DrawEllipse(float x, float y, float width, float height);
  155.  
  156.   // Splines
  157.   // 3-point spline
  158.   virtual void DrawSpline(float x1, float y1, float x2, float y2, float x3, float y3);
  159.   // Any number of control points - a list of pointers to wxPoints
  160.   virtual void DrawSpline(wxList *points);
  161.  
  162.   virtual void DrawIcon(wxIcon *icon, float x, float y);
  163.  
  164.   virtual void Clear(void);
  165.   virtual void SetFont(wxFont *font);
  166.   virtual void SetPen(wxPen *pen);
  167.   virtual void SetBrush(wxBrush *brush);
  168.   virtual void SetLogicalFunction(int function);
  169.   virtual void SetBackground(wxBrush *brush);
  170.   virtual void SetTextForeground(wxColour *colour);
  171.   virtual void SetTextBackground(wxColour *colour);
  172.   virtual void SetClippingRegion(float x, float y, float width, float height);
  173.   virtual void DestroyClippingRegion(void);
  174.   virtual void DrawText(char *text, float x, float y);
  175.  
  176.   virtual int GetTextFamily(void);
  177.   virtual int GetTextStyle(void);
  178.   virtual int GetTextWeight(void);
  179.   virtual float GetTextHeight(void);
  180.   virtual float GetTextWidth(void);
  181.   virtual void GetTextExtent(char *string, float *x, float *y);
  182.   virtual Bool Ok(void);
  183.   virtual Bool StartDoc(char *message);
  184.   virtual void EndDoc(void);
  185.   virtual void StartPage(void);
  186.   virtual void EndPage(void);
  187.   virtual void SetMapMode(int mode);
  188.   virtual int  GetMapMode(void);
  189.   virtual void SetLogicalOrigin(float x, float y);
  190.   virtual void SetDeviceOrigin(float x, float y);
  191.   virtual void SetLogicalScale(float x, float y);
  192.   virtual void SetUserScale(float x, float y);
  193.   virtual float DeviceToLogicalX(int x);
  194.   virtual float DeviceToLogicalY(int y);
  195.   virtual int LogicalToDeviceX(float x);
  196.   virtual int LogicalToDeviceY(float y);
  197.  
  198.   // Only works for PostScript *after* you've printed an image.
  199.   // Gives width and height of image.
  200.   virtual void GetSize(float *width, float *height);
  201.  
  202.   void CalcBoundingBox(float x, float y);
  203.  
  204. #ifdef wx_msw
  205.   void SetRop(HDC cdc);
  206.   void DoClipping(HDC cdc);
  207.   void SelectOldObjects(HDC dc);
  208. #endif
  209.  
  210.   wxDC *CreateCompatibleDC(void);
  211.   void SelectObject(wxBitmap *bitmap);
  212.   Bool Blit(float xdest, float ydest, float width, float height,
  213.             wxDC *source, float xsrc, float ysrc, int rop = wxCOPY);
  214. };
  215.  
  216. /*
  217.  * Metafile and metafile device context classes - work in Windows 3.1 only
  218.  *
  219.  */
  220.  
  221. class wxMetaFile: public wxObject
  222. {
  223.  public:
  224.     
  225. #ifdef wx_msw
  226.   HANDLE metafile;
  227. #endif
  228.   wxMetaFile(void);
  229.   ~wxMetaFile(void);
  230.  
  231.   // After this is called, the metafile cannot be used for anything
  232.   // since it is now owned by the clipboard.
  233.   Bool SetClipboard(int width = 0, int height = 0);
  234. };
  235.  
  236. class wxMetaFileDC: public wxDC
  237. {
  238.  public:
  239. #ifdef wx_msw
  240.   wxMetaFile *metafile;
  241. #endif
  242.  
  243.   wxMetaFileDC(char *file = NULL);
  244.   ~wxMetaFileDC(void);
  245.  
  246.   // Should be called at end of drawing
  247.   wxMetaFile *Close(void);
  248.   void SetMapMode(int mode);
  249. };
  250.  
  251. extern char *wx_printer_command;
  252. extern char *wx_printer_flags;
  253. extern Bool wx_preview;
  254. extern char *wx_preview_command;
  255. extern Bool wx_portrait;
  256. extern float wx_printer_scale_x;
  257. extern float wx_printer_scale_y;
  258. extern float wx_printer_translate_x;
  259. extern float wx_printer_translate_y;
  260. extern Bool wx_print_to_file;
  261.  
  262. /*
  263.  * XView
  264.  * Ok, so all this isn't neat, but it about works.
  265.  */
  266. #ifdef wx_x
  267.  
  268. // Logical to device
  269. // Absolute
  270. #define XLOG2DEV(x) (int)(((x) - logical_origin_x)*logical_scale_x*user_scale_x + device_origin_x)
  271. #define YLOG2DEV(y) (int)(((y) - logical_origin_y)*logical_scale_y*user_scale_y + device_origin_y)
  272.  
  273. // Logical to device without the device translation
  274. #define XLOG2DEV_2(x) (int)(((x) - logical_origin_x)*logical_scale_x*user_scale_x)
  275. #define YLOG2DEV_2(y) (int)(((y) - logical_origin_y)*logical_scale_y*user_scale_y)
  276.  
  277. // Relative
  278. #define XLOG2DEVREL(x) (int)((x)*logical_scale_x*user_scale_x)
  279. #define YLOG2DEVREL(y) (int)((y)*logical_scale_y*user_scale_y)
  280.  
  281. // Device to logical
  282. // Absolute
  283. #define XDEV2LOG(x) (int)(((x) - device_origin_x)/(logical_scale_x*user_scale_x) + logical_origin_x)
  284.  
  285. #define YDEV2LOG(y) (int)(((y) - device_origin_y)/(logical_scale_y*user_scale_y) + logical_origin_y)
  286.  
  287. // Relative
  288. #define XDEV2LOGREL(x) (int)((x)/(logical_scale_x*user_scale_x))
  289. #define YDEV2LOGREL(y) (int)((y)/(logical_scale_y*user_scale_y))
  290.  
  291. #endif
  292.  
  293. /*
  294.  * MS Windows
  295.  */
  296. #ifdef wx_msw
  297.  
  298. // Logical to device
  299. // Absolute
  300. #define XLOG2DEV(x) (int)((x))
  301.  
  302. #define YLOG2DEV(y) (int)((y))
  303.  
  304. // Relative
  305. #define XLOG2DEVREL(x) (int)((x))
  306. #define YLOG2DEVREL(y) (int)((y))
  307.  
  308. // Device to logical
  309. // Absolute
  310. #define XDEV2LOG(x) (int)((x))
  311.  
  312. #define YDEV2LOG(y) (int)((y))
  313.  
  314. // Relative
  315. #define XDEV2LOGREL(x) (int)((x))
  316. #define YDEV2LOGREL(y) (int)((y))
  317.  
  318. /*
  319.  * Have the same macros as for XView but not for every operation:
  320.  * just for calculating window/viewport extent (a better way of scaling).
  321.  */
  322.  
  323. // Logical to device
  324. // Absolute
  325. #define MS_XLOG2DEV(x) (int)(((x) - logical_origin_x)*logical_scale_x*user_scale_x + device_origin_x)
  326.  
  327. #define MS_YLOG2DEV(y) (int)(((y) - logical_origin_y)*logical_scale_y*user_scale_y + device_origin_y)
  328.  
  329. // Relative
  330. #define MS_XLOG2DEVREL(x) (int)((x)*logical_scale_x*user_scale_x)
  331. #define MS_YLOG2DEVREL(y) (int)((y)*logical_scale_y*user_scale_y)
  332.  
  333. // Device to logical
  334. // Absolute
  335. #define MS_XDEV2LOG(x) (int)(((x) - device_origin_x)/(logical_scale_x*user_scale_x) + logical_origin_x)
  336.  
  337. #define MS_YDEV2LOG(y) (int)(((y) - device_origin_y)/(logical_scale_y*user_scale_y) + logical_origin_y)
  338.  
  339. // Relative
  340. #define MS_XDEV2LOGREL(x) (int)((x)/(logical_scale_x*user_scale_x))
  341. #define MS_YDEV2LOGREL(y) (int)((y)/(logical_scale_y*user_scale_y))
  342.  
  343. #define VIEWPORT_EXTENT 1000
  344.  
  345. #endif
  346.  
  347. // Conversion
  348. #define METRIC_CONVERSION_CONSTANT  0.0393700787
  349.  
  350. // Scaling factors for various unit conversions
  351. #define mm2inches (METRIC_CONVERSION_CONSTANT)
  352. #define inches2mm (1/METRIC_CONVERSION_CONSTANT)
  353.  
  354. #define mm2twips (METRIC_CONVERSION_CONSTANT*1440)
  355. #define twips2mm (1/(METRIC_CONVERSION_CONSTANT*1440))
  356.  
  357. #define mm2pt (METRIC_CONVERSION_CONSTANT*72)
  358. #define pt2mm (1/(METRIC_CONVERSION_CONSTANT*72))
  359.  
  360. class wxSpline: public wxObject
  361. {
  362.  public:
  363.   int type;
  364.   wxList *points;
  365.  
  366.   wxSpline(wxList *list);
  367.   void DeletePoints(void);
  368.  
  369.   // Doesn't delete points
  370.   ~wxSpline(void);
  371. };
  372.  
  373. #endif
  374.