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

  1. /*
  2.  * File:     wx_canvs.h
  3.  * Purpose:  wxCanvas subwindow declarations
  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. #ifndef wx_canvsh
  30. #define wx_canvsh
  31.  
  32. #include <iostream.h>
  33. #include "common.h"
  34. #include "wx_frame.h"
  35. #include "wx_gdi.h"
  36.  
  37. #ifdef wx_xview
  38. #include <xview/canvas.h>
  39. #include <xview/scrollbar.h>
  40. #include <xview/xv_xrect.h>
  41. #endif
  42.  
  43. // Canvas subwindow for drawing on
  44. class wxCanvas: public wxWindow
  45. {
  46.  public:
  47.   wxDC *wx_dc;    // The canvas's real context
  48.   wxDC *context;  // Switchable context, normally = wx_dc
  49. #ifdef wx_motif
  50.   Widget scrolledWindow;
  51.   void PreResize(void);
  52.   Bool hScroll;
  53.   Bool vScroll;
  54.   int  hExtent;   // Actual extent of virtual scrolled canvas
  55.   int  vExtent;
  56.   Widget hScrollBar;
  57.   Widget vScrollBar;
  58.   Bool allowRepainting;
  59.   Bool hScrollingEnabled;
  60.   Bool vScrollingEnabled;
  61.   // The next 4 values need to be stored because Xt refuses to
  62.   // return the correct values. (I may be wrong here actually...)
  63.   int canvasWidth;
  64.   int canvasHeight;
  65.   int canvasX;
  66.   int canvasY;
  67.   Pixmap backingPixmap;
  68.   int pixmapWidth;
  69.   int pixmapHeight;
  70.   int pixmapOffsetX;
  71.   int pixmapOffsetY;
  72.   // Need to store state of buttons (whether they're still down)
  73.   Bool button1Pressed;
  74.   Bool button2Pressed;
  75.   Bool button3Pressed;
  76.   void Refresh(void);
  77. #endif
  78. #ifdef wx_xview
  79.   int DRAG_MAX;
  80.   int drag_count;
  81.   int repaint_countdown;
  82.   Xv_xrectlist *xrects;
  83. #endif
  84. #ifdef wx_msw
  85.   Bool clipping;
  86.   int clip_x1;
  87.   int clip_y1;
  88.   int clip_x2;
  89.   int clip_y2;
  90. #endif
  91.   Bool is_retained;
  92.   int horiz_units;
  93.   int vert_units;
  94.  
  95.   wxCanvas(wxFrame *frame, int x=-1, int y=-1, int width=-1, int height=-1,
  96.            int style = wxRETAINED);
  97.   virtual ~wxCanvas(void);
  98.  
  99.   void SetSize(int x, int y, int width, int height);
  100.   void SetClientSize(int width, int height);
  101.   void GetSize(int *width, int *height);
  102.   void GetClientSize(int *width, int *height);
  103.   void GetPosition(int *x, int *y);
  104.  
  105.   // Number of pixels per user unit (0 or -1 for no scrollbar)
  106.   // Length of virtual canvas in user units
  107.   // Length of page in user units
  108.   virtual void SetScrollbars(int horizontal, int vertical,
  109.                              int x_length, int y_length,
  110.                              int x_page, int y_page);
  111.  
  112.   // Scroll the canvas
  113.   virtual void Scroll(int x_pos, int y_pos);
  114.  
  115. #ifdef wx_xview
  116. // Every time a callback happens, these are set to point to the right values
  117. // for drawing calls to work
  118.   Xv_Window paint_window;
  119.   Scrollbar horiz_scroll;
  120.   Scrollbar vert_scroll;
  121. #endif
  122. #ifdef wx_x
  123.   Display *display;
  124.   Window xwindow;
  125. #endif
  126.   virtual void DrawLine(float x1, float y1, float x2, float y2);
  127.   virtual void DrawPoint(float x, float y);
  128.   virtual void DrawLines(int n, wxPoint points[], float xoffset = 0, float yoffset = 0);
  129.   virtual void DrawLines(wxList *list, float xoffset = 0, float yoffset = 0);
  130.   virtual void DrawPolygon(int n, wxPoint points[], float xoffset = 0, float yoffset = 0);
  131.   virtual void DrawPolygon(wxList *list, float xoffset = 0, float yoffset = 0);
  132.   virtual void DrawRectangle(float x, float y, float width, float height);
  133.   virtual void DrawRoundedRectangle(float x, float y, float width, float height, float radius = 20);
  134.   virtual void DrawEllipse(float x, float y, float width, float height);
  135.  
  136.   // Splines
  137.   // 3-point spline
  138.   virtual void DrawSpline(float x1, float y1, float x2, float y2, float x3, float y3);
  139.   // Any number of control points - a list of pointers to wxPoints
  140.   virtual void DrawSpline(wxList *points);
  141.  
  142.   virtual void Clear(void);
  143.   virtual void ViewStart(int *x, int *y);
  144.   virtual void SetFont(wxFont *font);
  145.   virtual void SetPen(wxPen *pen);
  146.   virtual void SetBrush(wxBrush *brush);
  147.   virtual void SetLogicalFunction(int function);
  148.   virtual void SetBackground(wxBrush *brush);
  149.   virtual void SetTextForeground(wxColour *colour);
  150.   virtual void SetTextBackground(wxColour *colour);
  151.   virtual void SetClippingRegion(float x, float y, float width, float height);
  152.   virtual void DestroyClippingRegion(void);
  153.   virtual void DrawText(char *text, float x, float y);
  154.  
  155.   // Actual size in pixels when scrolling is taken into account
  156.   virtual void GetVirtualSize(int *x, int *y);
  157.   virtual int GetTextFamily(void);
  158.   virtual int GetTextStyle(void);
  159.   virtual int GetTextWeight(void);
  160.   virtual float GetTextHeight(void);
  161.   virtual float GetTextWidth(void);
  162.   virtual void GetTextExtent(char *string, float *x, float *y);
  163.  
  164.   // Gets 'context' member
  165.   virtual wxDC *GetDC(void);
  166.  
  167.   // Use this to set the canvas's 'context' member to
  168.   // a user-supplied dc
  169.   void SetContext(wxDC *dc);
  170.   // Reset 'context' back to the canvas' context
  171.   void ResetContext(void);
  172.  
  173.   // Enable/disable Windows 3.1 scrolling in either direction.
  174.   // If TRUE, wxWindows scrolls the canvas and only a bit of
  175.   // the canvas is invalidated; no Clear() is necessary.
  176.   // If FALSE, the whole canvas is invalidated and a Clear() is
  177.   // necessary. Disable for when the scroll increment is used
  178.   // to actually scroll a non-constant distance
  179.   void EnableScrolling(Bool x_scrolling, Bool y_scrolling);
  180.  
  181. #ifdef wx_msw
  182.   void PreDelete(HDC dc);
  183. #endif
  184.  
  185.   Bool IsRetained(void) { return is_retained; }
  186.  
  187.   // Fix for too many XView repaints - call this with n if you know there are too many
  188.   // repaints, and canvas will be drawn after 0 is reached
  189.   // Doesn't actually work unfortunately...
  190.   void SetCountdown(int count);
  191. };
  192.  
  193. #endif // wc_canvsh
  194.