fixes for user dash handling (patch 717736)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20135 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2003-04-11 14:02:32 +00:00
parent 3251b83466
commit e2a5251d01
6 changed files with 54 additions and 12 deletions

View File

@ -42,6 +42,7 @@ All GUI ports:
- implemented alignment for wxGrid bool editor and renderer
- support wxListCtrl columns alignment for all platforms and not just MSW
- added wxToolBar Add/InsertTool(tool) (Janusz Piwowarski)
- fixed user dash handling for MSW and GTK (Ken Edwards)
- WXR resources can now be used in Unicode builds
- it is now possible to use several wxFileHistory objects in the same menu
by giving them different base IDs (Dimitri Schoolwerth)

View File

@ -53,6 +53,7 @@ private:
};
#define M_PENDATA ((wxPenRefData *)m_refData)
#define wxPENDATA(x) ((wxPenRefData *)(x).m_refData)
// Pen
class WXDLLEXPORT wxPen: public wxGDIObject
@ -66,8 +67,28 @@ public:
~wxPen();
inline wxPen& operator = (const wxPen& pen) { if (*this == pen) return (*this); Ref(pen); return *this; }
inline bool operator == (const wxPen& pen) const { return m_refData == pen.m_refData; }
inline bool operator != (const wxPen& pen) const { return m_refData != pen.m_refData; }
inline bool operator == (const wxPen& pen) const
{
// It is impossible to know if the user dashes have changed,
// so we must assume that they have
if ( m_refData && pen.m_refData )
{
if ( M_PENDATA->m_nbDash != 0 || wxPENDATA(pen)->m_nbDash != 0 )
return false;
}
return m_refData == pen.m_refData;
}
inline bool operator != (const wxPen& pen) const
{
// It is impossible to know if the user dashes have changed,
// so we must assume that they have
if ( m_refData && pen.m_refData )
{
if ( M_PENDATA->m_nbDash != 0 || wxPENDATA(pen)->m_nbDash != 0 )
return true;
}
return m_refData != pen.m_refData;
}
virtual bool Ok() const { return (m_refData != NULL) ; }

View File

@ -464,18 +464,27 @@ void MyCanvas::DrawTestLines( int x, int y, int width, wxDC &dc )
dc.DrawText(_T("User dash"), x + 150, y + 140);
wxPen ud( wxT("black"), width, wxUSER_DASH );
wxDash dash1[1];
dash1[0] = 0;
ud.SetDashes( 1, dash1 );
wxDash dash1[6];
dash1[0] = 8; // Long dash <---------+
dash1[1] = 2; // Short gap |
dash1[2] = 3; // Short dash |
dash1[3] = 2; // Short gap |
dash1[4] = 3; // Short dash |
dash1[5] = 2; // Short gap and repeat +
ud.SetDashes( 6, dash1 );
dc.SetPen( ud );
dc.DrawLine( x+20, y+140, 100, y+140 );
dash1[0] = 1;
ud.SetDashes( 1, dash1 );
dash1[0] = 5; // Make first dash shorter
ud.SetDashes( 6, dash1 );
dc.SetPen( ud );
dc.DrawLine( x+20, y+150, 100, y+150 );
dash1[0] = 2;
ud.SetDashes( 1, dash1 );
dash1[2] = 5; // Make second dash longer
ud.SetDashes( 6, dash1 );
dc.SetPen( ud );
dc.DrawLine( x+20, y+160, 100, y+160 );
dash1[0] = 0x7F;
ud.SetDashes( 1, dash1 );
dash1[4] = 5; // Make third dash longer
ud.SetDashes( 6, dash1 );
dc.SetPen( ud );
dc.DrawLine( x+20, y+170, 100, y+170 );
}

View File

@ -52,6 +52,11 @@ public:
bool operator == (const wxPenRefData& data) const
{
// It is impossible to tell if the dashes have changed
// so the only thing to do is assume they have
if (m_countDashes != 0 || data.m_countDashes != 0)
return false;
return (m_style == data.m_style &&
m_width == data.m_width &&
m_joinStyle == data.m_joinStyle &&

View File

@ -52,6 +52,11 @@ public:
bool operator == (const wxPenRefData& data) const
{
// It is impossible to tell if the dashes have changed
// so the only thing to do is assume they have
if (m_countDashes != 0 || data.m_countDashes != 0)
return false;
return (m_style == data.m_style &&
m_width == data.m_width &&
m_joinStyle == data.m_joinStyle &&

View File

@ -232,8 +232,9 @@ bool wxPen::RealizeResource()
if (M_PENDATA->m_style==wxUSER_DASH && M_PENDATA->m_nbDash && M_PENDATA->m_dash)
{
real_dash = new wxMSWDash[M_PENDATA->m_nbDash];
int rw = M_PENDATA->m_width > 1 ? M_PENDATA->m_width : 1;
for ( int i = 0; i < M_PENDATA->m_nbDash; i++ )
real_dash[i] = M_PENDATA->m_dash[i] * M_PENDATA->m_width;
real_dash[i] = M_PENDATA->m_dash[i] * rw;
}
else
{