Updated wxColour for handling Colormaps and ref couting.
    Updated wxClientDC et al. for conforming to wxGTK. Many
      tricky parts, particularly the bitmap drawing and
      blitting is still missing.
    Any sample crashes now for some reason with an X error.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14136 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2002-02-11 20:41:24 +00:00
parent d8356fa39a
commit 3cd0b8c5b5
16 changed files with 2009 additions and 2229 deletions

View File

@@ -1860,6 +1860,7 @@ typedef void* WXWindow;
typedef void* WXWidget; typedef void* WXWidget;
typedef void* WXAppContext; typedef void* WXAppContext;
typedef void* WXColormap; typedef void* WXColormap;
typedef void* WXColor;
typedef void WXDisplay; typedef void WXDisplay;
typedef void WXEvent; typedef void WXEvent;
typedef void* WXCursor; typedef void* WXCursor;

View File

@@ -1,11 +1,11 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: colour.h // Name: colour.h
// Purpose: wxColour class // Purpose: wxColour class
// Author: Julian Smart // Author: Julian Smart, Robert Roebling
// Modified by: // Modified by:
// Created: 17/09/98 // Created: 17/09/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart, Robert Roebling
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -16,77 +16,82 @@
#pragma interface "colour.h" #pragma interface "colour.h"
#endif #endif
#include "wx/defs.h"
#include "wx/object.h" #include "wx/object.h"
#include "wx/string.h" #include "wx/string.h"
#include "wx/gdiobj.h"
#include "wx/palette.h"
// Colour //-----------------------------------------------------------------------------
class WXDLLEXPORT wxColour : public wxObject // classes
//-----------------------------------------------------------------------------
class wxDC;
class wxPaintDC;
class wxBitmap;
class wxWindow;
class wxColour;
//-----------------------------------------------------------------------------
// wxColour
//-----------------------------------------------------------------------------
class wxColour: public wxGDIObject
{ {
DECLARE_DYNAMIC_CLASS(wxColour)
public: public:
// ctors wxColour() { }
// default
wxColour(); // Construct from RGB
// from RGB
wxColour( unsigned char red, unsigned char green, unsigned char blue ); wxColour( unsigned char red, unsigned char green, unsigned char blue );
wxColour( unsigned long colRGB ) { Set(colRGB); } wxColour( unsigned long colRGB ) { Set(colRGB); }
// implicit conversion from the colour name // Implicit conversion from the colour name
wxColour( const wxString &colourName ) { InitFromName(colourName); } wxColour( const wxString &colourName ) { InitFromName(colourName); }
wxColour( const char *colourName ) { InitFromName(colourName); } wxColour( const char *colourName ) { InitFromName(colourName); }
// copy ctors and assignment operators wxColour( const wxColour& col ) { Ref(col); }
wxColour( const wxColour& col ); wxColour& operator = ( const wxColour& col ) { Ref(col); return *this; }
wxColour& operator = ( const wxColour& col );
// dtor
~wxColour(); ~wxColour();
// Set() functions bool Ok() const { return m_refData != NULL; }
bool operator == ( const wxColour& col ) const;
bool operator != ( const wxColour& col ) const { return !(*this == col); }
void Set( unsigned char red, unsigned char green, unsigned char blue ); void Set( unsigned char red, unsigned char green, unsigned char blue );
void Set( unsigned long colRGB ) void Set( unsigned long colRGB )
{ {
// we don't need to know sizeof(long) here because we assume that the three // We don't need to know sizeof(long) here because we assume that the three
// least significant bytes contain the R, G and B values // least significant bytes contain the R, G and B values
Set((unsigned char)colRGB, Set((unsigned char)colRGB,
(unsigned char)(colRGB >> 8), (unsigned char)(colRGB >> 8),
(unsigned char)(colRGB >> 16)); (unsigned char)(colRGB >> 16));
} }
unsigned char Red() const;
unsigned char Green() const;
unsigned char Blue() const;
// Implementation part
// accessors void CalcPixel( WXColormap cmap );
bool Ok() const {return m_isInit; } unsigned long GetPixel() const;
unsigned char Red() const { return m_red; } WXColor *GetColor() const;
unsigned char Green() const { return m_green; }
unsigned char Blue() const { return m_blue; } protected:
// ref counting code
int GetPixel() const { return m_pixel; }; virtual wxObjectRefData *CreateRefData() const;
void SetPixel(int pixel) { m_pixel = pixel; m_isInit = TRUE; }; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
inline bool operator == (const wxColour& colour) const { return (m_red == colour.m_red && m_green == colour.m_green && m_blue == colour.m_blue); }
inline bool operator != (const wxColour& colour) const { return (!(m_red == colour.m_red && m_green == colour.m_green && m_blue == colour.m_blue)); }
// Allocate a colour, or nearest colour, using the given display.
// If realloc is TRUE, ignore the existing pixel, otherwise just return
// the existing one.
// Returns the allocated pixel.
// TODO: can this handle mono displays? If not, we should have an extra
// flag to specify whether this should be black or white by default.
int AllocColour(WXDisplay* display, bool realloc = FALSE);
void InitFromName(const wxString& col);
// Helper functions
void InitFromName(const wxString& colourName);
private: private:
bool m_isInit; DECLARE_DYNAMIC_CLASS(wxColour)
unsigned char m_red;
unsigned char m_blue;
unsigned char m_green;
public:
int m_pixel;
}; };
#endif #endif
// _WX_COLOUR_H_
// _WX_COLOUR_H_

View File

@@ -43,8 +43,6 @@
class WXDLLEXPORT wxDC : public wxDCBase class WXDLLEXPORT wxDC : public wxDCBase
{ {
DECLARE_DYNAMIC_CLASS(wxDC)
public: public:
wxDC(); wxDC();
~wxDC() { } ~wxDC() { }
@@ -64,13 +62,8 @@ public:
virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp);
protected: protected:
virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y);
virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y,
bool useMask = FALSE);
virtual void DoSetClippingRegion(wxCoord x, wxCoord y, virtual void DoSetClippingRegion(wxCoord x, wxCoord y,
wxCoord width, wxCoord height); wxCoord width, wxCoord height);
virtual void DoGetSize(int *width, int *height) const;
virtual void DoGetSizeMM(int* width, int* height) const; virtual void DoGetSizeMM(int* width, int* height) const;
public: public:
@@ -114,15 +107,6 @@ public:
else else
return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX;
} }
// Without device translation, for backing pixmap purposes
wxCoord XLOG2DEV_2(wxCoord x) const
{
wxCoord new_x = x - m_logicalOriginX;
if (new_x > 0)
return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX;
else
return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX;
}
wxCoord XLOG2DEVREL(wxCoord x) const wxCoord XLOG2DEVREL(wxCoord x) const
{ {
if (x > 0) if (x > 0)
@@ -138,15 +122,6 @@ public:
else else
return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY;
} }
// Without device translation, for backing pixmap purposes
wxCoord YLOG2DEV_2(wxCoord y) const
{
wxCoord new_y = y - m_logicalOriginY;
if (new_y > 0)
return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY;
else
return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY;
}
wxCoord YLOG2DEVREL(wxCoord y) const wxCoord YLOG2DEVREL(wxCoord y) const
{ {
if (y > 0) if (y > 0)
@@ -162,6 +137,9 @@ public:
// recompute scale? // recompute scale?
bool m_needComputeScaleX, m_needComputeScaleY; bool m_needComputeScaleX, m_needComputeScaleY;
private:
DECLARE_ABSTRACT_CLASS(wxDC)
}; };
#endif #endif

View File

@@ -17,87 +17,45 @@
#endif #endif
#include "wx/dc.h" #include "wx/dc.h"
#include "wx/region.h"
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// fwd declarations // fwd declarations
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
class WXDLLEXPORT wxWindowDC; class wxWindow;
class WXDLLEXPORT wxWindow;
// Under Windows, wxClientDC, wxPaintDC and wxWindowDC are implemented class wxWindowDC;
// differently. On many platforms, however, they will be the same. class wxPaintDC;
class wxClientDC;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxWindowDC // wxWindowDC
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class WXDLLEXPORT wxWindowDC : public wxDC class wxWindowDC : public wxDC
{ {
DECLARE_DYNAMIC_CLASS(wxWindowDC)
public: public:
wxWindowDC(); wxWindowDC();
wxWindowDC( wxWindow *win ); wxWindowDC( wxWindow *win );
~wxWindowDC(); ~wxWindowDC();
// TODO this function is Motif-only for now - should it go into base class? virtual bool CanDrawBitmap() const { return TRUE; }
void Clear(const wxRect& rect); virtual bool CanGetTextExtent() const { return TRUE; }
// implement base class pure virtuals
// ----------------------------------
virtual void Clear();
virtual void SetFont(const wxFont& font);
virtual void SetPen(const wxPen& pen);
virtual void SetBrush(const wxBrush& brush);
virtual void SetBackground(const wxBrush& brush);
virtual void SetBackgroundMode(int mode);
virtual void SetPalette(const wxPalette& palette);
virtual void SetLogicalFunction( int function );
virtual void SetTextForeground(const wxColour& colour);
virtual void SetTextBackground(const wxColour& colour);
virtual wxCoord GetCharHeight() const;
virtual wxCoord GetCharWidth() const;
virtual void DoGetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,
wxCoord *descent = NULL,
wxCoord *externalLeading = NULL,
wxFont *theFont = NULL) const;
virtual bool CanDrawBitmap() const;
virtual bool CanGetTextExtent() const;
virtual int GetDepth() const;
virtual wxSize GetPPI() const;
virtual void DestroyClippingRegion();
// Helper function for setting clipping
void SetDCClipping();
// implementation from now on
// --------------------------
WXGC GetGC() const { return m_gc; }
WXGC GetBackingGC() const { return m_gcBacking; }
WXDisplay* GetDisplay() const { return m_display; }
bool GetAutoSetting() const { return m_autoSetting; }
void SetAutoSetting(bool flag) { m_autoSetting = flag; }
protected: protected:
virtual void DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, virtual void DoGetSize(int *width, int *height) const;
int style = wxFLOOD_SURFACE); virtual void DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, int style = wxFLOOD_SURFACE );
virtual bool DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const;
virtual bool DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const;
virtual void DoDrawPoint(wxCoord x, wxCoord y); virtual void DoDrawPoint(wxCoord x, wxCoord y);
virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2); virtual void DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2);
virtual void DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y );
virtual void DoDrawBitmap( const wxBitmap &bitmap, wxCoord x, wxCoord y,
bool useMask = FALSE );
virtual void DoDrawArc(wxCoord x1, wxCoord y1, virtual void DoDrawArc(wxCoord x1, wxCoord y1,
wxCoord x2, wxCoord y2, wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc); wxCoord xc, wxCoord yc);
@@ -128,49 +86,89 @@ protected:
virtual void DoDrawPolygon(int n, wxPoint points[], virtual void DoDrawPolygon(int n, wxPoint points[],
wxCoord xoffset, wxCoord yoffset, wxCoord xoffset, wxCoord yoffset,
int fillStyle = wxODDEVEN_RULE); int fillStyle = wxODDEVEN_RULE);
WXGC m_gc;
WXGC m_gcBacking;
WXDisplay* m_display;
wxWindow* m_window;
WXRegion m_currentRegion; // Current clipping region (incl. paint clip region)
WXRegion m_userRegion; // User-defined clipping region
WXPixmap m_pixmap; // Pixmap for drawing on
// Not sure if we'll need all of these
int m_backgroundPixel;
wxColour m_currentColour;
// int m_currentBkMode;
int m_currentPenWidth ;
int m_currentPenJoin ;
int m_currentPenCap ;
int m_currentPenDashCount ;
wxX11Dash* m_currentPenDash ;
wxBitmap m_currentStipple ;
int m_currentStyle ;
int m_currentFill ;
int m_autoSetting ; // See comment in dcclient.cpp
WXFont m_oldFont;
};
class WXDLLEXPORT wxPaintDC: public wxWindowDC
{
DECLARE_DYNAMIC_CLASS(wxPaintDC)
public: public:
wxPaintDC() { } virtual void Clear();
wxPaintDC(wxWindow* win);
~wxPaintDC(); virtual void SetFont(const wxFont& font);
virtual void SetPen(const wxPen& pen);
virtual void SetBrush(const wxBrush& brush);
virtual void SetBackground(const wxBrush& brush);
virtual void SetBackgroundMode(int mode);
virtual void SetPalette(const wxPalette& palette);
virtual void SetLogicalFunction( int function );
virtual void SetTextForeground(const wxColour& colour);
virtual void SetTextBackground(const wxColour& colour);
virtual wxCoord GetCharHeight() const;
virtual wxCoord GetCharWidth() const;
virtual void DoGetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,
wxCoord *descent = NULL,
wxCoord *externalLeading = NULL,
wxFont *theFont = NULL) const;
virtual int GetDepth() const;
virtual wxSize GetPPI() const;
virtual void DestroyClippingRegion();
protected:
// implementation
// --------------
WXDisplay *m_display;
WXWindow m_window;
WXGC m_penGC;
WXGC m_brushGC;
WXGC m_textGC;
WXGC m_bgGC;
WXColormap m_cmap;
bool m_isMemDC;
bool m_isScreenDC;
wxWindow *m_owner;
wxRegion m_currentClippingRegion;
wxRegion m_paintClippingRegion;
void SetUpDC();
void Destroy();
void ComputeScaleAndOrigin();
private:
DECLARE_DYNAMIC_CLASS(wxWindowDC)
}; };
class WXDLLEXPORT wxClientDC: public wxWindowDC //-----------------------------------------------------------------------------
// wxClientDC
//-----------------------------------------------------------------------------
class wxClientDC : public wxWindowDC
{ {
DECLARE_DYNAMIC_CLASS(wxClientDC)
public: public:
wxClientDC() { } wxClientDC() { }
wxClientDC(wxWindow* win) : wxWindowDC(win) { } wxClientDC( wxWindow *win );
protected:
virtual void DoGetSize(int *width, int *height) const;
private:
DECLARE_DYNAMIC_CLASS(wxClientDC)
};
//-----------------------------------------------------------------------------
// wxPaintDC
//-----------------------------------------------------------------------------
class wxPaintDC : public wxClientDC
{
public:
wxPaintDC() { }
wxPaintDC( wxWindow *win );
private:
DECLARE_DYNAMIC_CLASS(wxPaintDC)
}; };
#endif #endif

View File

@@ -20,23 +20,18 @@
class wxMemoryDC : public wxWindowDC class wxMemoryDC : public wxWindowDC
{ {
DECLARE_DYNAMIC_CLASS(wxMemoryDC)
public: public:
wxMemoryDC(); wxMemoryDC();
wxMemoryDC( wxDC *dc ); // Create compatible DC wxMemoryDC( wxDC *dc ); // Create compatible DC
~wxMemoryDC(); ~wxMemoryDC();
virtual void SelectObject( const wxBitmap& bitmap ); virtual void SelectObject( const wxBitmap& bitmap );
void DoGetSize( int *width, int *height ) const; void DoGetSize( int *width, int *height ) const;
wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; } // implementation
wxBitmap m_selected;
private: private:
friend class wxPaintDC; DECLARE_DYNAMIC_CLASS(wxMemoryDC)
wxBitmap m_bitmap;
}; };
#endif #endif

View File

@@ -18,31 +18,34 @@
#include "wx/dcclient.h" #include "wx/dcclient.h"
class WXDLLEXPORT wxScreenDC: public wxWindowDC //-----------------------------------------------------------------------------
// wxScreenDC
//-----------------------------------------------------------------------------
class wxScreenDC : public wxPaintDC
{ {
DECLARE_DYNAMIC_CLASS(wxScreenDC)
public: public:
// Create a DC representing the whole screen
wxScreenDC(); wxScreenDC();
~wxScreenDC(); virtual ~wxScreenDC();
// Compatibility with X's requirements for static bool StartDrawingOnTop( wxWindow *window );
// drawing on top of all windows static bool StartDrawingOnTop( wxRect *rect = (wxRect *) NULL );
static bool StartDrawingOnTop(wxWindow* window);
static bool StartDrawingOnTop(wxRect* rect = NULL);
static bool EndDrawingOnTop(); static bool EndDrawingOnTop();
// implementation
static WXWindow *sm_overlayWindow;
static int sm_overlayWindowX;
static int sm_overlayWindowY;
protected:
virtual void DoGetSize(int *width, int *height) const;
private: private:
static WXWindow sm_overlayWindow; DECLARE_DYNAMIC_CLASS(wxScreenDC)
// If we have started transparent drawing at a non-(0,0) point
// then we will have to adjust the device origin in the
// constructor.
static int sm_overlayWindowX;
static int sm_overlayWindowY;
}; };
#endif #endif
// _WX_DCSCREEN_H_ // _WX_DCSCREEN_H_

View File

@@ -123,6 +123,9 @@ public:
// Generates paint events // Generates paint events
void X11SendPaintEvents(); void X11SendPaintEvents();
// Clip to paint region?
bool GetClipPaintRegion() { return m_clipPaintRegion; }
// sets the fore/background colour for the given widget // sets the fore/background colour for the given widget
static void DoChangeForegroundColour(WXWindow widget, wxColour& foregroundColour); static void DoChangeForegroundColour(WXWindow widget, wxColour& foregroundColour);
static void DoChangeBackgroundColour(WXWindow widget, wxColour& backgroundColour, bool changeArmColour = FALSE); static void DoChangeBackgroundColour(WXWindow widget, wxColour& backgroundColour, bool changeArmColour = FALSE);

View File

@@ -246,6 +246,8 @@ wxWindowDC::wxWindowDC()
wxWindowDC::wxWindowDC( wxWindow *window ) wxWindowDC::wxWindowDC( wxWindow *window )
{ {
wxASSERT_MSG( window, wxT("DC needs a window") );
m_penGC = (GdkGC *) NULL; m_penGC = (GdkGC *) NULL;
m_brushGC = (GdkGC *) NULL; m_brushGC = (GdkGC *) NULL;
m_textGC = (GdkGC *) NULL; m_textGC = (GdkGC *) NULL;
@@ -256,8 +258,6 @@ wxWindowDC::wxWindowDC( wxWindow *window )
m_isScreenDC = FALSE; m_isScreenDC = FALSE;
m_font = window->GetFont(); m_font = window->GetFont();
wxASSERT_MSG( window, wxT("DC needs a window") );
GtkWidget *widget = window->m_wxwindow; GtkWidget *widget = window->m_wxwindow;
// some controls don't have m_wxwindow - like wxStaticBox, but the user // some controls don't have m_wxwindow - like wxStaticBox, but the user

View File

@@ -246,6 +246,8 @@ wxWindowDC::wxWindowDC()
wxWindowDC::wxWindowDC( wxWindow *window ) wxWindowDC::wxWindowDC( wxWindow *window )
{ {
wxASSERT_MSG( window, wxT("DC needs a window") );
m_penGC = (GdkGC *) NULL; m_penGC = (GdkGC *) NULL;
m_brushGC = (GdkGC *) NULL; m_brushGC = (GdkGC *) NULL;
m_textGC = (GdkGC *) NULL; m_textGC = (GdkGC *) NULL;
@@ -256,8 +258,6 @@ wxWindowDC::wxWindowDC( wxWindow *window )
m_isScreenDC = FALSE; m_isScreenDC = FALSE;
m_font = window->GetFont(); m_font = window->GetFont();
wxASSERT_MSG( window, wxT("DC needs a window") );
GtkWidget *widget = window->m_wxwindow; GtkWidget *widget = window->m_wxwindow;
// some controls don't have m_wxwindow - like wxStaticBox, but the user // some controls don't have m_wxwindow - like wxStaticBox, but the user

View File

@@ -531,11 +531,13 @@ wxBitmap wxCreateMaskedBitmap(const wxBitmap& bitmap, wxColour& colour)
srcDC.SelectObject(bitmap); srcDC.SelectObject(bitmap);
destDC.SelectObject(newBitmap); destDC.SelectObject(newBitmap);
#if 0
wxBrush brush(colour, wxSOLID); wxBrush brush(colour, wxSOLID);
destDC.SetOptimization(FALSE); destDC.SetOptimization(FALSE);
destDC.SetBackground(brush); destDC.SetBackground(brush);
destDC.Clear(); destDC.Clear();
destDC.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & srcDC, 0, 0, wxCOPY, TRUE); destDC.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & srcDC, 0, 0, wxCOPY, TRUE);
#endif
return newBitmap; return newBitmap;
} }

View File

@@ -1,214 +1,254 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: colour.cpp // Name: colour.cpp
// Purpose: wxColour class // Purpose: wxColour class
// Author: Julian Smart // Author: Julian Smart, Robert Roebling
// Modified by: // Modified by:
// Created: 17/09/98 // Created: 17/09/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart, Robert Roebling
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
//// TODO: make wxColour a ref-counted object,
//// so pixel values get shared.
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation "colour.h" #pragma implementation "colour.h"
#endif #endif
#include "wx/gdicmn.h" #include "wx/gdicmn.h"
#include "wx/colour.h"
#include "wx/app.h"
#ifdef __VMS__
#pragma message disable nosimpint
#endif
#include <Xm/Xm.h>
#ifdef __VMS__
#pragma message enable nosimpint
#endif
#include "wx/x11/private.h" #include "wx/x11/private.h"
IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject) //-----------------------------------------------------------------------------
// wxColour
//-----------------------------------------------------------------------------
// Colour class wxColourRefData: public wxObjectRefData
wxColour::wxColour ()
{ {
m_isInit = FALSE; public:
m_red = m_blue = m_green = 0; wxColourRefData()
m_pixel = -1;
}
wxColour::wxColour (unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
m_pixel = -1;
}
wxColour::wxColour (const wxColour& col)
{
m_red = col.m_red;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
m_pixel = col.m_pixel;
}
wxColour& wxColour::operator =(const wxColour& col)
{
m_red = col.m_red;
m_green = col.m_green;
m_blue = col.m_blue;
m_isInit = col.m_isInit;
m_pixel = col.m_pixel;
return *this;
}
void wxColour::InitFromName(const wxString& col)
{
wxColour *the_colour = wxTheColourDatabase->FindColour (col);
if (the_colour)
{ {
m_red = the_colour->Red (); m_color.red = 0;
m_green = the_colour->Green (); m_color.green = 0;
m_blue = the_colour->Blue (); m_color.blue = 0;
m_pixel = the_colour->m_pixel; m_color.pixel = 0;
m_isInit = TRUE; m_colormap = (WXColormap *) NULL;
m_hasPixel = FALSE;
}
~wxColourRefData()
{
FreeColour();
}
bool operator == (const wxColourRefData& data) const
{
return (m_colormap == data.m_colormap &&
m_hasPixel == data.m_hasPixel &&
m_color.red == data.m_color.red &&
m_color.green == data.m_color.green &&
m_color.blue == data.m_color.blue &&
m_color.pixel == data.m_color.pixel);
}
void FreeColour();
void AllocColour( WXColormap cmap );
XColor m_color;
WXColormap m_colormap;
bool m_hasPixel;
friend class wxColour;
// reference counter for systems with <= 8-Bit display
static unsigned short colMapAllocCounter[ 256 ];
};
unsigned short wxColourRefData::colMapAllocCounter[ 256 ] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
void wxColourRefData::FreeColour()
{
if (m_colormap)
{
Colormap cm = (Colormap)m_colormap;
#if 0
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) m_colormap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
{
int idx = m_color.pixel;
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] - 1;
if (colMapAllocCounter[ idx ] == 0)
gdk_colormap_free_colors( m_colormap, &m_color, 1 );
}
#endif
}
}
void wxColourRefData::AllocColour( WXColormap cmap )
{
if (m_hasPixel && (m_colormap == cmap))
return;
FreeColour();
#if 0
GdkColormapPrivate *private_colormap = (GdkColormapPrivate*) cmap;
if ((private_colormap->visual->type == GDK_VISUAL_GRAYSCALE) ||
(private_colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR))
{
m_hasPixel = gdk_colormap_alloc_color( cmap, &m_color, FALSE, TRUE );
int idx = m_color.pixel;
colMapAllocCounter[ idx ] = colMapAllocCounter[ idx ] + 1;
}
else
#endif
{
m_hasPixel = XAllocColor( wxGlobalDisplay(), (Colormap) cmap, &m_color );
}
m_colormap = cmap;
}
//-----------------------------------------------------------------------------
#define M_COLDATA ((wxColourRefData *)m_refData)
#define SHIFT (8*(sizeof(short int)-sizeof(char)))
IMPLEMENT_DYNAMIC_CLASS(wxColour,wxGDIObject)
wxColour::wxColour( unsigned char red, unsigned char green, unsigned char blue )
{
m_refData = new wxColourRefData();
M_COLDATA->m_color.red = ((unsigned short)red) << SHIFT;
M_COLDATA->m_color.green = ((unsigned short)green) << SHIFT;
M_COLDATA->m_color.blue = ((unsigned short)blue) << SHIFT;
M_COLDATA->m_color.pixel = 0;
}
void wxColour::InitFromName( const wxString &colourName )
{
wxNode *node = (wxNode *) NULL;
if ( (wxTheColourDatabase) && (node = wxTheColourDatabase->Find(colourName)) )
{
wxColour *col = (wxColour*)node->Data();
UnRef();
if (col) Ref( *col );
} }
else else
{ {
m_red = 0; m_refData = new wxColourRefData();
m_green = 0; if (!XParseColor( wxGlobalDisplay(), (Colormap) M_COLDATA->m_colormap, colourName.mb_str(), &M_COLDATA->m_color ))
m_blue = 0;
m_isInit = FALSE;
}
}
wxColour::~wxColour ()
{
}
void wxColour::Set (unsigned char r, unsigned char g, unsigned char b)
{
m_red = r;
m_green = g;
m_blue = b;
m_isInit = TRUE;
m_pixel = -1;
}
// Allocate a colour, or nearest colour, using the given display.
// If realloc is TRUE, ignore the existing pixel, otherwise just return
// the existing one.
// Returns the old or allocated pixel.
// TODO: can this handle mono displays? If not, we should have an extra
// flag to specify whether this should be black or white by default.
int wxColour::AllocColour(WXDisplay* display, bool realloc)
{
if ((m_pixel != -1) && !realloc)
return m_pixel;
XColor color;
color.red = (unsigned short) Red ();
color.red |= color.red << 8;
color.green = (unsigned short) Green ();
color.green |= color.green << 8;
color.blue = (unsigned short) Blue ();
color.blue |= color.blue << 8;
color.flags = DoRed | DoGreen | DoBlue;
WXColormap cmap = wxTheApp->GetMainColormap(display);
if (!XAllocColor ((Display*) display, (Colormap) cmap, &color))
{
m_pixel = wxGetBestMatchingPixel((Display*) display, &color,(Colormap) cmap);
return m_pixel;
}
else
{
m_pixel = (int) color.pixel;
return m_pixel;
}
}
/*-------------------------------------------
Markus Emmenegger <mege@iqe.ethz.ch>
Find the pixel value with an assigned color closest to the desired color
Used if color cell allocation fails
As the returned pixel value may be in use by another application,
the color might change anytime.
But in many cases, that is still better than always using black.
--
Chris Breeze <chris@hel.co.uk>
Improvements:
1) More efficient calculation of RGB distance of colour cell from
the desired colour. There is no need to take the sqrt of 'dist', and
since we are only interested in the top 8-bits of R, G and B we
can perform integer arithmetic.
2) Attempt to allocate a read-only colour when a close match is found.
A read-only colour will not change.
3) Fall back to the closest match if no read-only colours are available.
Possible further improvements:
1) Scan the lookup table and sort the colour cells in order of
increasing
distance from the desired colour. Then attempt to allocate a
read-only
colour starting from the nearest match.
2) Linear RGB distance is not a particularly good method of colour
matching
(though it is quick). Converting the colour to HLS and then comparing
may give better matching.
-------------------------------------------*/
int wxGetBestMatchingPixel(Display *display, XColor *desiredColor, Colormap cmap)
{
if (cmap == (Colormap) NULL)
cmap = (Colormap) wxTheApp->GetMainColormap(display);
int numPixVals = XDisplayCells(display, DefaultScreen (display));
int mindist = 256 * 256 * 3;
int bestpixel = (int) BlackPixel (display, DefaultScreen (display));
int red = desiredColor->red >> 8;
int green = desiredColor->green >> 8;
int blue = desiredColor->blue >> 8;
const int threshold = 2 * 2 * 3; // allow an error of up to 2 in R,G & B
for (int pixelcount = 0; pixelcount < numPixVals; pixelcount++)
{
XColor matching_color;
matching_color.pixel = pixelcount;
XQueryColor(display,cmap,&matching_color);
int delta_red = red - (matching_color.red >> 8);
int delta_green = green - (matching_color.green >> 8);
int delta_blue = blue - (matching_color.blue >> 8);
int dist = delta_red * delta_red +
delta_green * delta_green +
delta_blue * delta_blue;
if (dist <= threshold)
{ {
// try to allocate a read-only colour... // VZ: asserts are good in general but this one is triggered by
if (XAllocColor (display, cmap, &matching_color)) // calling wxColourDatabase::FindColour() with an
{ // unrecognized colour name and this can't be avoided from the
return matching_color.pixel; // user code, so don't give it here
} //
} // a better solution would be to changed code in FindColour()
if (dist < mindist)
{ //wxFAIL_MSG( wxT("wxColour: couldn't find colour") );
bestpixel = pixelcount;
mindist = dist; delete m_refData;
m_refData = (wxObjectRefData *) NULL;
} }
} }
return bestpixel; }
wxColour::~wxColour()
{
}
bool wxColour::operator == ( const wxColour& col ) const
{
if (m_refData == col.m_refData) return TRUE;
if (!m_refData || !col.m_refData) return FALSE;
XColor *own = &(((wxColourRefData*)m_refData)->m_color);
XColor *other = &(((wxColourRefData*)col.m_refData)->m_color);
if (own->red != other->red) return FALSE;
if (own->blue != other->blue) return FALSE;
if (own->green != other->green) return FALSE;
return TRUE;
}
wxObjectRefData *wxColour::CreateRefData() const
{
return new wxColourRefData;
}
wxObjectRefData *wxColour::CloneRefData(const wxObjectRefData *data) const
{
return new wxColourRefData(*(wxColourRefData *)data);
}
void wxColour::Set( unsigned char red, unsigned char green, unsigned char blue )
{
AllocExclusive();
m_refData = new wxColourRefData();
M_COLDATA->m_color.red = ((unsigned short)red) << SHIFT;
M_COLDATA->m_color.green = ((unsigned short)green) << SHIFT;
M_COLDATA->m_color.blue = ((unsigned short)blue) << SHIFT;
M_COLDATA->m_color.pixel = 0;
}
unsigned char wxColour::Red() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid colour") );
return (unsigned char)(M_COLDATA->m_color.red >> SHIFT);
}
unsigned char wxColour::Green() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid colour") );
return (unsigned char)(M_COLDATA->m_color.green >> SHIFT);
}
unsigned char wxColour::Blue() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid colour") );
return (unsigned char)(M_COLDATA->m_color.blue >> SHIFT);
}
void wxColour::CalcPixel( WXColormap cmap )
{
if (!Ok()) return;
M_COLDATA->AllocColour( cmap );
}
unsigned long wxColour::GetPixel() const
{
wxCHECK_MSG( Ok(), 0, wxT("invalid colour") );
return M_COLDATA->m_color.pixel;
}
WXColor *wxColour::GetColor() const
{
wxCHECK_MSG( Ok(), (WXColor *) NULL, wxT("invalid colour") );
return (WXColor*) &M_COLDATA->m_color;
} }

View File

@@ -38,44 +38,28 @@ wxDC::wxDC()
{ {
m_ok = FALSE; m_ok = FALSE;
#if 1
m_mm_to_pix_x = 1.0; m_mm_to_pix_x = 1.0;
m_mm_to_pix_y = 1.0; m_mm_to_pix_y = 1.0;
#else
m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
(double)wxGetDisplaySizeMM().GetWidth();
m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
(double)wxGetDisplaySizeMM().GetHeight();
#endif
m_needComputeScaleX = FALSE; /* not used yet */
m_needComputeScaleY = FALSE; /* not used yet */
m_logicalFunction = wxCOPY;
m_pen = *wxBLACK_PEN;
m_font = *wxNORMAL_FONT;
m_brush = *wxWHITE_BRUSH;
m_backgroundMode = wxTRANSPARENT; m_backgroundMode = wxTRANSPARENT;
m_isInteractive = FALSE; m_isInteractive = FALSE; // ???
}
void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y)
{
wxCHECK_RET( Ok(), "invalid dc" );
wxCHECK_RET( icon.Ok(), "invalid icon" );
DoDrawBitmap(icon, x, y, TRUE);
}
void wxDC::DoDrawBitmap( const wxBitmap& bitmap, wxCoord x, wxCoord y, bool useMask )
{
wxCHECK_RET( bitmap.Ok(), "invalid bitmap" );
wxMemoryDC memDC;
memDC.SelectObject(bitmap);
#if 0
// Not sure if we need this. The mask should leave the masked areas as per
// the original background of this DC.
if (useMask)
{
// There might be transparent areas, so make these the same colour as this
// DC
memDC.SetBackground(* GetBackground());
memDC.Clear();
}
#endif // 0
Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, wxCOPY, useMask);
memDC.SelectObject(wxNullBitmap);
} }
void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height )
@@ -92,14 +76,6 @@ void wxDC::DestroyClippingRegion()
m_clipping = FALSE; m_clipping = FALSE;
} }
void wxDC::DoGetSize( int* width, int* height ) const
{
if ( width )
*width = m_maxX - m_minX;
if ( height )
*height = m_maxY - m_minY;
}
void wxDC::DoGetSizeMM( int* width, int* height ) const void wxDC::DoGetSizeMM( int* width, int* height ) const
{ {
int w, h; int w, h;

File diff suppressed because it is too large Load Diff

View File

@@ -17,142 +17,72 @@
#include "wx/settings.h" #include "wx/settings.h"
#include "wx/utils.h" #include "wx/utils.h"
#ifdef __VMS__
#pragma message disable nosimpint
#endif
#ifdef __VMS__
#pragma message enable nosimpint
#endif
#include "wx/x11/private.h" #include "wx/x11/private.h"
//----------------------------------------------------------------------------- IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC,wxWindowDC)
// wxMemoryDC
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxMemoryDC, wxWindowDC) wxMemoryDC::wxMemoryDC() : wxWindowDC()
wxMemoryDC::wxMemoryDC(void)
{ {
m_ok = TRUE; m_ok = FALSE;
m_display = wxGetDisplay();
Display* display = (Display*) m_display; m_display = (WXDisplay *) wxGlobalDisplay();
XGCValues gcvalues;
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 | GCSubwindowMode,
&gcvalues);
m_backgroundPixel = (int) gcvalues.background;
// Get the current Font so we can set it back later
XGCValues valReturn;
XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
m_oldFont = (WXFont) valReturn.font;
SetBrush (* wxWHITE_BRUSH);
SetPen (* wxBLACK_PEN);
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
};
wxMemoryDC::wxMemoryDC( wxDC* dc ) int screen = DefaultScreen( wxGlobalDisplay() );
{ m_cmap = (WXColormap) DefaultColormap( wxGlobalDisplay(), screen );
m_ok = TRUE; }
if (dc && dc->IsKindOf(CLASSINFO(wxWindowDC)))
m_display = ((wxWindowDC*)dc)->GetDisplay();
else
m_display = wxGetDisplay();
Display* display = (Display*) m_display;
XGCValues gcvalues;
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 | GCSubwindowMode,
&gcvalues);
m_backgroundPixel = (int) gcvalues.background;
// Get the current Font so we can set it back later
XGCValues valReturn;
XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
m_oldFont = (WXFont) valReturn.font;
SetBrush (* wxWHITE_BRUSH);
SetPen (* wxBLACK_PEN);
};
wxMemoryDC::~wxMemoryDC(void) wxMemoryDC::wxMemoryDC( wxDC *WXUNUSED(dc) )
: wxWindowDC()
{ {
}; m_ok = FALSE;
m_display = (WXDisplay *) wxGlobalDisplay();
int screen = DefaultScreen( wxGlobalDisplay() );
m_cmap = (WXColormap) DefaultColormap( wxGlobalDisplay(), screen );
}
wxMemoryDC::~wxMemoryDC()
{
}
void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
{ {
m_bitmap = bitmap; Destroy();
if (m_gc) m_selected = bitmap;
XFreeGC((Display*) m_display, (GC) m_gc); if (m_selected.Ok())
m_gc = (WXGC) NULL;
if (m_bitmap.Ok() && (bitmap.GetDisplay() == m_display))
{ {
m_pixmap = m_bitmap.GetPixmap(); if (m_selected.GetPixmap())
Display* display = (Display*) m_display; {
m_window = (WXWindow) m_selected.GetPixmap();
XGCValues gcvalues; }
gcvalues.foreground = BlackPixel (display, DefaultScreen (display)); else
gcvalues.background = WhitePixel (display, DefaultScreen (display)); {
gcvalues.graphics_exposures = False; // m_window = m_selected.GetBitmap();
gcvalues.subwindow_mode = IncludeInferiors; }
gcvalues.line_width = 1;
m_gc = (WXGC) XCreateGC (display, RootWindow (display, DefaultScreen (display)), m_isMemDC = TRUE;
GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
&gcvalues); SetUpDC();
m_backgroundPixel = (int) gcvalues.background;
// Get the current Font so we can set it back later
XGCValues valReturn;
XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn);
m_oldFont = (WXFont) valReturn.font;
bool oldOpt = GetOptimization();
SetOptimization(FALSE);
SetBrush (* wxWHITE_BRUSH);
SetPen (* wxBLACK_PEN);
SetOptimization(oldOpt);
m_ok = TRUE;
} }
else else
{ {
m_ok = FALSE; m_ok = FALSE;
m_pixmap = (WXPixmap) 0; m_window = NULL;
}; }
}; }
void wxMemoryDC::DoGetSize( int *width, int *height ) const void wxMemoryDC::DoGetSize( int *width, int *height ) const
{ {
if (m_bitmap.Ok()) if (m_selected.Ok())
{ {
if (width) (*width) = m_bitmap.GetWidth(); if (width) (*width) = m_selected.GetWidth();
if (height) (*height) = m_bitmap.GetHeight(); if (height) (*height) = m_selected.GetHeight();
} }
else else
{ {
if (width) (*width) = 0; if (width) (*width) = 0;
if (height) (*height) = 0; if (height) (*height) = 0;
}; }
}; }

View File

@@ -1,11 +1,11 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: dcscreen.cpp // Name: dcscreen.cpp
// Purpose: wxScreenDC class // Purpose: wxScreenDC class
// Author: Julian Smart // Author: Julian Smart, Robert Roebling
// Modified by: // Modified by:
// Created: 17/09/98 // Created: 17/09/98
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Julian Smart // Copyright: (c) Julian Smart, Robert Roebling
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -18,117 +18,102 @@
#include "wx/dcscreen.h" #include "wx/dcscreen.h"
#include "wx/utils.h" #include "wx/utils.h"
#ifdef __VMS__
#pragma message disable nosimpint
#endif
#ifdef __VMS__
#pragma message enable nosimpint
#endif
#include "wx/x11/private.h" #include "wx/x11/private.h"
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC) //-----------------------------------------------------------------------------
// global data initialization
//-----------------------------------------------------------------------------
WXWindow wxScreenDC::sm_overlayWindow = 0; WXWindow *wxScreenDC::sm_overlayWindow = (WXWindow*) NULL;
int wxScreenDC::sm_overlayWindowX = 0; int wxScreenDC::sm_overlayWindowX = 0;
int wxScreenDC::sm_overlayWindowY = 0; int wxScreenDC::sm_overlayWindowY = 0;
// Create a DC representing the whole screen //-----------------------------------------------------------------------------
// wxScreenDC
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxScreenDC,wxPaintDC)
wxScreenDC::wxScreenDC() wxScreenDC::wxScreenDC()
{ {
m_display = wxGetDisplay(); m_ok = FALSE;
Display* display = (Display*) m_display;
if (sm_overlayWindow) m_display = (WXDisplay *) wxGlobalDisplay();
{
m_pixmap = sm_overlayWindow;
m_deviceOriginX = - sm_overlayWindowX;
m_deviceOriginY = - sm_overlayWindowY;
}
else
m_pixmap = (WXPixmap) RootWindow(display, DefaultScreen(display));
XGCValues gcvalues; int screen = DefaultScreen( (Display*) m_display );
gcvalues.foreground = BlackPixel (display, DefaultScreen (display)); m_cmap = (WXColormap) DefaultColormap( (Display*) m_display, screen );
gcvalues.background = WhitePixel (display, DefaultScreen (display));
gcvalues.graphics_exposures = False;
gcvalues.subwindow_mode = IncludeInferiors;
gcvalues.line_width = 1;
m_gc = XCreateGC (display, RootWindow (display, DefaultScreen (display)),
GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCSubwindowMode,
&gcvalues);
m_backgroundPixel = (int) gcvalues.background; m_window = (WXWindow) RootWindow( (Display*) m_display, screen );
m_ok = TRUE;
m_isScreenDC = TRUE;
SetUpDC();
XSetSubwindowMode( (Display*) m_display, (GC) m_penGC, IncludeInferiors );
XSetSubwindowMode( (Display*) m_display, (GC) m_brushGC, IncludeInferiors );
XSetSubwindowMode( (Display*) m_display, (GC) m_textGC, IncludeInferiors );
XSetSubwindowMode( (Display*) m_display, (GC) m_bgGC, IncludeInferiors );
} }
wxScreenDC::~wxScreenDC() wxScreenDC::~wxScreenDC()
{ {
XSetSubwindowMode( (Display*) m_display, (GC) m_penGC, ClipByChildren );
XSetSubwindowMode( (Display*) m_display, (GC) m_brushGC, ClipByChildren );
XSetSubwindowMode( (Display*) m_display, (GC) m_textGC, ClipByChildren );
XSetSubwindowMode( (Display*) m_display, (GC) m_bgGC, ClipByChildren );
EndDrawingOnTop(); EndDrawingOnTop();
} }
bool wxScreenDC::StartDrawingOnTop(wxWindow* window) bool wxScreenDC::StartDrawingOnTop( wxWindow *window )
{ {
wxRect rect; if (!window) return StartDrawingOnTop();
int x, y, width, height;
window->GetPosition(& x, & y);
if (window->GetParent() && !window->IsKindOf(CLASSINFO(wxFrame)))
window->GetParent()->ClientToScreen(& x, & y);
window->GetSize(& width, & height);
rect.x = x; rect.y = y;
rect.width = width; rect.height = height;
return StartDrawingOnTop(& rect);
}
bool wxScreenDC::StartDrawingOnTop(wxRect* rect)
{
if (sm_overlayWindow)
return FALSE;
Display *dpy = (Display*) wxGetDisplay();
Pixmap screenPixmap = RootWindow(dpy, DefaultScreen(dpy));
int x = 0; int x = 0;
int y = 0; int y = 0;
int width, height; window->GetPosition( &x, &y );
wxDisplaySize(&width, &height); int w = 0;
int h = 0;
window->GetSize( &w, &h );
window->ClientToScreen( &x, &y );
wxRect rect;
rect.x = x;
rect.y = y;
rect.width = 0;
rect.height = 0;
return StartDrawingOnTop( &rect );
}
bool wxScreenDC::StartDrawingOnTop( wxRect *rect )
{
int x = 0;
int y = 0;
#if 0
int width = gdk_screen_width();
int height = gdk_screen_height();
#else
int width = 1024;
int height = 768;
#endif
if (rect) if (rect)
{ {
x = rect->x; y = rect->y; x = rect->x;
width = rect->width; height = rect->height; y = rect->y;
width = rect->width;
height = rect->height;
} }
sm_overlayWindowX = x;
sm_overlayWindowY = y; return TRUE;
XSetWindowAttributes attributes;
attributes.override_redirect = True;
unsigned long valueMask = CWOverrideRedirect;
sm_overlayWindow = (WXWindow) XCreateWindow(dpy, screenPixmap, x, y, width, height, 0,
wxDisplayDepth(), InputOutput,
DefaultVisual(dpy, 0), valueMask,
& attributes);
if (sm_overlayWindow)
{
XMapWindow(dpy, (Window) sm_overlayWindow);
return TRUE;
}
else
return FALSE;
} }
bool wxScreenDC::EndDrawingOnTop() bool wxScreenDC::EndDrawingOnTop()
{ {
if (sm_overlayWindow) return TRUE;
{ }
XDestroyWindow((Display*) wxGetDisplay(), (Window) sm_overlayWindow);
sm_overlayWindow = 0; void wxScreenDC::DoGetSize(int *width, int *height) const
return TRUE; {
} wxDisplaySize(width, height);
else
return FALSE;
} }

View File

@@ -121,11 +121,7 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
CreateBase(parent, id, pos, size, style, wxDefaultValidator, name); CreateBase(parent, id, pos, size, style, wxDefaultValidator, name);
if (parent) parent->AddChild(this);
parent->AddChild(this);
m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
m_foregroundColour = *wxBLACK;
int w = size.GetWidth(); int w = size.GetWidth();
int h = size.GetHeight(); int h = size.GetHeight();
@@ -136,18 +132,25 @@ bool wxWindowX11::Create(wxWindow *parent, wxWindowID id,
if (x == -1) x = 0; if (x == -1) x = 0;
if (y == -1) y = 0; if (y == -1) y = 0;
int screen = DefaultScreen(wxGlobalDisplay()); Display *xdisplay = (Display*) wxGlobalDisplay();
int xscreen = DefaultScreen( xdisplay );
Colormap cm = DefaultColormap( xdisplay, xscreen );
Window parentWindow; m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
if (parent) m_backgroundColour.CalcPixel( (WXColormap) cm );
parentWindow = (Window) parent->GetMainWindow();
else m_foregroundColour = *wxBLACK;
parentWindow = RootWindow(wxGlobalDisplay(), screen); m_foregroundColour.CalcPixel( (WXColormap) cm );
Window window = XCreateSimpleWindow(wxGlobalDisplay(), parentWindow, Window parentWindow = (Window) parent->GetMainWindow();
x, y, w, h, 0,
m_backgroundColour.AllocColour(wxGlobalDisplay()), Window window = XCreateSimpleWindow(
m_foregroundColour.AllocColour(wxGlobalDisplay())); xdisplay, parentWindow,
x, y, w, h, 0,
m_backgroundColour.GetPixel(),
m_foregroundColour.GetPixel() );
m_mainWidget = (WXWindow) window; m_mainWidget = (WXWindow) window;
// Select event types wanted // Select event types wanted
@@ -411,6 +414,7 @@ void wxWindowX11::WarpPointer (int x, int y)
// Does a physical scroll // Does a physical scroll
void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect) void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
{ {
#if 0
int x, y, w, h; int x, y, w, h;
if (rect) if (rect)
{ {
@@ -573,10 +577,7 @@ void wxWindowX11::ScrollWindow(int dx, int dy, const wxRect *rect)
delete rect; delete rect;
node = node->Next(); node = node->Next();
} }
#endif
// TODO
// XmUpdateDisplay((Widget) GetMainWidget());
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -697,7 +698,7 @@ void wxWindowX11::DoGetClientSize(int *x, int *y) const
if (window) if (window)
{ {
XWindowAttributes attr; XWindowAttributes attr;
Status status = XGetWindowAttributes(wxGlobalDisplay(), window, & attr); Status status = XGetWindowAttributes( wxGlobalDisplay(), window, &attr );
wxASSERT(status); wxASSERT(status);
if (status) if (status)
@@ -972,9 +973,9 @@ void wxWindowX11::X11SendPaintEvents()
m_clearRegion.Clear(); m_clearRegion.Clear();
} }
wxNcPaintEvent nc_paint_event( GetId() ); // wxNcPaintEvent nc_paint_event( GetId() );
nc_paint_event.SetEventObject( this ); // nc_paint_event.SetEventObject( this );
GetEventHandler()->ProcessEvent( nc_paint_event ); // GetEventHandler()->ProcessEvent( nc_paint_event );
wxPaintEvent paint_event( GetId() ); wxPaintEvent paint_event( GetId() );
paint_event.SetEventObject( this ); paint_event.SetEventObject( this );
@@ -1314,9 +1315,15 @@ bool wxWindowX11::SetBackgroundColour(const wxColour& col)
if (!GetMainWindow()) if (!GetMainWindow())
return FALSE; return FALSE;
Display *xdisplay = (Display*) wxGlobalDisplay();
int xscreen = DefaultScreen( xdisplay );
Colormap cm = DefaultColormap( xdisplay, xscreen );
wxColour colour( col ); wxColour colour( col );
colour.CalcPixel( (WXColormap) cm );
XSetWindowAttributes attrib; XSetWindowAttributes attrib;
attrib.background_pixel = colour.AllocColour(wxGlobalDisplay()); attrib.background_pixel = colour.GetPixel();
XChangeWindowAttributes(wxGlobalDisplay(), XChangeWindowAttributes(wxGlobalDisplay(),
(Window) GetMainWindow(), (Window) GetMainWindow(),