#include <math.h>
+#ifdef __VMS__
+#pragma message disable nosimpint
+#endif
#include <Xm/Xm.h>
+#ifdef __VMS__
+#pragma message enable nosimpint
+#endif
#include "wx/motif/private.h"
+#ifdef __EMX__
+ #include <float.h> // for M_PI
+#endif // __EMX__
+
#include "bdiag.xbm"
#include "fdiag.xbm"
#include "cdiag.xbm"
// constants
// ----------------------------------------------------------------------------
-#define RAD2DEG 57.2957795131
-
// Fudge factor (VZ: what??)
#define WX_GC_CF 1
// macros
// ----------------------------------------------------------------------------
-#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
-#endif
// ----------------------------------------------------------------------------
// prototypes
// implementation
// ============================================================================
+/*
+ * compare two doubles and return the larger rounded
+ * to the nearest int
+ */
+static int roundmax(double a, double b)
+{
+ return (int)((a > b ? a : b) + 0.5);
+}
+
+/*
+ * compare two doubles and return the smaller rounded
+ * to the nearest int
+ */
+static int roundmin(double a, double b)
+{
+ return (int)((a < b ? a : b) - 0.5);
+}
+
+
// ----------------------------------------------------------------------------
// wxWindowDC
// ----------------------------------------------------------------------------
m_currentPenWidth = 1;
m_currentPenJoin = -1;
m_currentPenDashCount = -1;
- m_currentPenDash = (char*) NULL;
+ m_currentPenDash = (wxMOTIFDash*) NULL;
m_currentStyle = -1;
m_currentFill = -1;
// m_currentBkMode = wxTRANSPARENT;
m_currentPenWidth = 1;
m_currentPenJoin = -1;
m_currentPenDashCount = -1;
- m_currentPenDash = (char*) NULL;
+ m_currentPenDash = (wxMOTIFDash*) NULL;
m_currentStyle = -1;
m_currentFill = -1;
// m_currentBkMode = wxTRANSPARENT;
gcvalues.foreground = BlackPixel (display, DefaultScreen (display));
gcvalues.background = WhitePixel (display, DefaultScreen (display));
gcvalues.graphics_exposures = False;
+ gcvalues.subwindow_mode = IncludeInferiors;
gcvalues.line_width = 1;
m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)),
- GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
+ GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
&gcvalues);
if (m_window->GetBackingPixmap())
{
m_gcBacking = (WXGC) XCreateGC (display, RootWindow (display,
DefaultScreen (display)),
- GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth,
+ GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
&gcvalues);
}
wxFAIL_MSG("not implemented");
}
-bool wxWindowDC::DoGetPixel( wxCoord WXUNUSED(x1), wxCoord WXUNUSED(y1), wxColour *WXUNUSED(col) ) const
+bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const
{
- wxFAIL_MSG("not implemented");
-
- return FALSE;
+ // Generic (and therefore rather inefficient) method.
+ // Could be improved.
+ wxMemoryDC memdc;
+ wxBitmap bitmap(1, 1);
+ memdc.SelectObject(bitmap);
+ memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1);
+ memdc.SelectObject(wxNullBitmap);
+ wxImage image(bitmap);
+ col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0));
+ return TRUE;
}
void wxWindowDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 )
wxCoord dx = xx1 - xxc;
wxCoord dy = yy1 - yyc;
- double radius = sqrt (dx * dx + dy * dy);
+ double radius = sqrt ((double)(dx * dx + dy * dy));
wxCoord r = (wxCoord) radius;
double radius1, radius2;
CalcBoundingBox (x, y);
}
+void wxWindowDC::DoDrawRotatedText( const wxString &text, wxCoord x, wxCoord y, double angle )
+{
+ if (angle == 0.0)
+ {
+ DrawText(text, x, y);
+ return;
+ }
+
+ wxCHECK_RET( Ok(), "invalid dc" );
+
+ // Since X draws from the baseline of the text, must add the text height
+ int cx = 0;
+ int cy = 0;
+ int ascent = 0;
+ int slen;
+
+ slen = strlen(text);
+
+ if (m_font.Ok())
+ {
+ // Calculate text extent.
+ WXFontStructPtr pFontStruct = m_font.GetFontStruct(m_userScaleY*m_logicalScaleY, m_display);
+ int direction, descent;
+ XCharStruct overall_return;
+#if 0
+ if (use16)
+ (void)XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *)(const char*) text, slen, &direction,
+ &ascent, &descent, &overall_return);
+ else
+#endif // 0
+ (void)XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) text, slen, &direction,
+ &ascent, &descent, &overall_return);
+
+ cx = overall_return.width;
+ cy = ascent + descent;
+ }
+
+ wxBitmap src(cx, cy);
+ wxMemoryDC dc;
+ dc.SelectObject(src);
+ dc.SetFont(GetFont());
+ dc.SetBackground(*wxWHITE_BRUSH);
+ dc.SetBrush(*wxBLACK_BRUSH);
+ dc.Clear();
+ dc.DrawText(text, 0, 0);
+ dc.SetFont(wxNullFont);
+
+ // Calculate the size of the rotated bounding box.
+ double dx = cos(angle / 180.0 * M_PI);
+ double dy = sin(angle / 180.0 * M_PI);
+ double x4 = -cy * dy;
+ double y4 = cy * dx;
+ double x3 = cx * dx;
+ double y3 = cx * dy;
+ double x2 = x3 + x4;
+ double y2 = y3 + y4;
+ double x1 = x;
+ double y1 = y;
+
+ // Create image from the source bitmap after writing the text into it.
+ wxImage image(src);
+
+ int minx = roundmin(0, roundmin(x4, roundmin(x2, x3)));
+ int miny = roundmin(0, roundmin(y4, roundmin(y2, y3)));
+ int maxx = roundmax(0, roundmax(x4, roundmax(x2, x3)));
+ int maxy = roundmax(0, roundmax(y4, roundmax(y2, y3)));
+
+ // This rotates counterclockwise around the top left corner.
+ for (int rx = minx; rx < maxx; rx++)
+ {
+ for (int ry = miny; ry < maxy; ry++)
+ {
+ // transform dest coords to source coords
+ int sx = (int) (rx * dx + ry * dy + 0.5);
+ int sy = (int) (ry * dx - rx * dy + 0.5);
+ if (sx >= 0 && sx < cx && sy >= 0 && sy < cy)
+ {
+ // draw black pixels, ignore white ones (i.e. transparent b/g)
+ if (image.GetRed(sx, sy) == 0)
+ {
+ DrawPoint((wxCoord) (x1 + maxx - rx), (wxCoord) (cy + y1 - ry));
+ }
+ else
+ {
+ // Background
+ //DrawPoint(x1 + maxx - rx, cy + y1 + maxy - ry);
+ }
+ }
+ }
+ }
+
+#if 0
+ // First draw a rectangle representing the text background, if a text
+ // background is specified
+ if (m_textBackgroundColour.Ok () && (m_backgroundMode != wxTRANSPARENT))
+ {
+ wxColour oldPenColour = m_currentColour;
+ m_currentColour = m_textBackgroundColour;
+ bool sameColour = (oldPenColour.Ok () && m_textBackgroundColour.Ok () &&
+ (oldPenColour.Red () == m_textBackgroundColour.Red ()) &&
+ (oldPenColour.Blue () == m_textBackgroundColour.Blue ()) &&
+ (oldPenColour.Green () == m_textBackgroundColour.Green ()));
+
+ // This separation of the big && test required for gcc2.7/HP UX 9.02
+ // or pixel value can be corrupted!
+ sameColour = (sameColour &&
+ (oldPenColour.GetPixel() == m_textBackgroundColour.GetPixel()));
+
+ if (!sameColour || !GetOptimization())
+ {
+ int pixel = m_textBackgroundColour.AllocColour(m_display);
+ m_currentColour = m_textBackgroundColour;
+
+ // Set the GC to the required colour
+ if (pixel > -1)
+ {
+ XSetForeground ((Display*) m_display, (GC) m_gc, pixel);
+ if (m_window && m_window->GetBackingPixmap())
+ XSetForeground ((Display*) m_display,(GC) m_gcBacking, pixel);
+ }
+ }
+ else
+ m_textBackgroundColour = oldPenColour ;
+
+ XFillRectangle ((Display*) m_display, (Pixmap) m_pixmap, (GC) m_gc, XLOG2DEV (x), YLOG2DEV (y), cx, cy);
+ if (m_window && m_window->GetBackingPixmap())
+ XFillRectangle ((Display*) m_display, (Pixmap) m_window->GetBackingPixmap(),(GC) m_gcBacking,
+ XLOG2DEV_2 (x), YLOG2DEV_2 (y), cx, cy);
+ }
+#endif
+
+ long w, h;
+ // XXX use pixmap size
+ GetTextExtent (text, &w, &h);
+ CalcBoundingBox (x + w, y + h);
+ CalcBoundingBox (x, y);
+}
+
bool wxWindowDC::CanGetTextExtent() const
{
return TRUE;
int old_pen_join = m_currentPenJoin;
int old_pen_cap = m_currentPenCap;
int old_pen_nb_dash = m_currentPenDashCount;
- char *old_pen_dash = m_currentPenDash;
+ wxMOTIFDash *old_pen_dash = m_currentPenDash;
wxColour oldPenColour = m_currentColour;
m_currentColour = m_pen.GetColour ();
m_currentPenJoin = m_pen.GetJoin ();
m_currentPenCap = m_pen.GetCap ();
m_currentPenDashCount = m_pen.GetDashCount();
- m_currentPenDash = m_pen.GetDash();
+ m_currentPenDash = (wxMOTIFDash*)m_pen.GetDash();
if (m_currentStyle == wxSTIPPLE)
m_currentStipple = * m_pen.GetStipple ();
int style;
int join;
int cap;
- static const char dotted[] = {2, 5};
- static const char short_dashed[] = {4, 4};
- static const char long_dashed[] = {4, 8};
- static const char dotted_dashed[] = {6, 6, 2, 6};
+ static const wxMOTIFDash dotted[] = {2, 5};
+ static const wxMOTIFDash short_dashed[] = {4, 4};
+ static const wxMOTIFDash long_dashed[] = {4, 8};
+ static const wxMOTIFDash dotted_dashed[] = {6, 6, 2, 6};
// We express dash pattern in pen width unit, so we are
// independent of zoom factor and so on...
int req_nb_dash;
- const char *req_dash;
+ const wxMOTIFDash *req_dash;
switch (m_pen.GetStyle ())
{
case wxTRANSPARENT:
default:
style = LineSolid;
- req_dash = NULL;
+ req_dash = (wxMOTIFDash*)NULL;
req_nb_dash = 0;
}
if (req_dash && req_nb_dash)
{
- char *real_req_dash = new char[req_nb_dash];
+ wxMOTIFDash *real_req_dash = new wxMOTIFDash[req_nb_dash];
if (real_req_dash)
{
int factor = scaled_width == 0 ? 1 : scaled_width;
void wxWindowDC::DoDrawSpline( wxList *points )
{
wxCHECK_RET( Ok(), wxT("invalid window dc") );
-
+
wxPoint *p;
double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
double x1, y1, x2, y2;
win->SetUpdateRegion(*region);
+ wxRegion& theRegion(win->GetUpdateRegion());
+ theRegion.SetRects(updateRects); // We also store in terms of rects, for iteration to work.
+
// Set the clipping region. Any user-defined region will be combined with this
// one in SetDCClipping.
XSetRegion ((Display*) m_display, (GC) m_gc, (Region) region->GetXRegion());