cosmetic changes : indentation etc.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4398 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
1999-11-06 15:41:14 +00:00
parent 5c172c1788
commit 01325161d5
2 changed files with 235 additions and 275 deletions

View File

@@ -52,15 +52,15 @@ WX_DEFINE_OBJARRAY(CoordArray);
class wxHtmlImageMapAreaCell : public wxHtmlCell class wxHtmlImageMapAreaCell : public wxHtmlCell
{ {
public: public:
enum celltype{ CIRCLE, RECT, POLY }; enum celltype { CIRCLE, RECT, POLY };
protected: protected:
CoordArray coords; CoordArray coords;
celltype type; celltype type;
int radius; int radius;
public: public:
wxHtmlImageMapAreaCell( celltype t, wxString &coords ); wxHtmlImageMapAreaCell( celltype t, wxString &coords );
virtual wxString GetLink( int x = 0, int y = 0 ) const; virtual wxString GetLink( int x = 0, int y = 0 ) const;
}; };
@@ -69,144 +69,119 @@ public:
wxHtmlImageMapAreaCell::wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::celltype t, wxString &incoords ) wxHtmlImageMapAreaCell::wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::celltype t, wxString &incoords )
{ {
int i; int i;
wxString x = incoords, y; wxString x = incoords, y;
type = t; type = t;
while ((i = x.Find( ',' )) != -1) while ((i = x.Find( ',' )) != -1) {
{ coords.Add( wxAtoi( x.Left( i ).c_str() ) );
coords.Add( wxAtoi( x.Left( i ).c_str() ) ); x = x.Mid( i + 1 );
x = x.Mid( i + 1 ); }
} coords.Add( wxAtoi( x.c_str() ) );
coords.Add( wxAtoi( x.c_str() ) );
} }
wxString wxHtmlImageMapAreaCell::GetLink( int x, int y ) const wxString wxHtmlImageMapAreaCell::GetLink( int x, int y ) const
{ {
switch (type) switch (type) {
{ case RECT:
case RECT: {
{ int l, t, r, b;
int l, t, r, b;
l = coords[ 0 ]; l = coords[ 0 ];
t = coords[ 1 ]; t = coords[ 1 ];
r = coords[ 2 ]; r = coords[ 2 ];
b = coords[ 3 ]; b = coords[ 3 ];
if (x >= l && x <= r && y >= t && y <= b) if (x >= l && x <= r && y >= t && y <= b) {
{ return m_Link;
return m_Link; }
} break;
break; }
} case CIRCLE:
case CIRCLE: {
{ int l, t, r;
int l, t, r; double d;
double d;
l = coords[ 0 ]; l = coords[ 0 ];
t = coords[ 1 ]; t = coords[ 1 ];
r = coords[ 2 ]; r = coords[ 2 ];
d = sqrt( (double) (((x - l) * (x - l)) + ((y - t) * (y - t))) ); d = sqrt( (double) (((x - l) * (x - l)) + ((y - t) * (y - t))) );
if (d < (double)r) if (d < (double)r) {
{ return m_Link;
return m_Link; }
} }
} break;
break; case POLY:
case POLY: {
{ if (coords.GetCount() >= 6) {
if (coords.GetCount() >= 6) int intersects = 0;
{ int wherex = x;
int intersects = 0; int wherey = y;
int wherex = x; int totalv = coords.GetCount() / 2;
int wherey = y; int totalc = totalv * 2;
int totalv = coords.GetCount() / 2; int xval = coords[totalc - 2];
int totalc = totalv * 2; int yval = coords[totalc - 1];
int xval = coords[totalc - 2]; int end = totalc;
int yval = coords[totalc - 1]; int pointer = 1;
int end = totalc;
int pointer = 1;
if ((yval >= wherey) != (coords[pointer] >= wherey)) if ((yval >= wherey) != (coords[pointer] >= wherey)) {
{ if ((xval >= wherex) == (coords[0] >= wherex)) {
if ((xval >= wherex) == (coords[0] >= wherex)) intersects += (xval >= wherex) ? 1 : 0;
{ } else {
intersects += (xval >= wherex) ? 1 : 0; intersects += ((xval - (yval - wherey) *
} (coords[0] - xval) /
else (coords[pointer] - yval)) >= wherex) ? 1 : 0;
{ }
intersects += ((xval - (yval - wherey) * }
(coords[0] - xval) /
(coords[pointer] - yval)) >= wherex) ? 1 : 0;
}
}
while (pointer < end) while (pointer < end) {
{ yval = coords[pointer];
yval = coords[pointer]; pointer += 2;
pointer += 2; if (yval >= wherey) {
if (yval >= wherey) while ((pointer < end) && (coords[pointer] >= wherey)) {
{ pointer += 2;
while((pointer < end) && (coords[pointer] >= wherey)) }
{ if (pointer >= end) {
pointer+=2; break;
} }
if (pointer >= end) if ((coords[pointer - 3] >= wherex) ==
{ (coords[pointer - 1] >= wherex)) {
break; intersects += (coords[pointer - 3] >= wherex) ? 1 : 0;
} } else {
if ((coords[pointer-3] >= wherex) == intersects +=
(coords[pointer-1] >= wherex)) ((coords[pointer - 3] - (coords[pointer - 2] - wherey) *
{ (coords[pointer - 1] - coords[pointer - 3]) /
intersects += (coords[pointer-3] >= wherex) ? 1 : 0; (coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0;
} }
else } else {
{ while ((pointer < end) && (coords[pointer] < wherey)) {
intersects += pointer += 2;
((coords[pointer-3] - (coords[pointer-2] - wherey) * }
(coords[pointer-1] - coords[pointer-3]) / if (pointer >= end) {
(coords[pointer] - coords[pointer - 2])) >= wherex) ? 1:0; break;
} }
} if ((coords[pointer - 3] >= wherex) ==
else (coords[pointer - 1] >= wherex)) {
{ intersects += (coords[pointer - 3] >= wherex) ? 1 : 0;
while((pointer < end) && (coords[pointer] < wherey)) } else {
{ intersects +=
pointer+=2; ((coords[pointer - 3] - (coords[pointer - 2] - wherey) *
} (coords[pointer - 1] - coords[pointer - 3]) /
if (pointer >= end) (coords[pointer] - coords[pointer - 2])) >= wherex) ? 1 : 0;
{ }
break; }
} }
if ((coords[pointer-3] >= wherex) == if ((intersects & 1) != 0) {
(coords[pointer-1] >= wherex)) return m_Link;
{ }
intersects += (coords[pointer-3] >= wherex) ? 1:0; }
} }
else break;
{ }
intersects += if (m_Next) {
((coords[pointer-3] - (coords[pointer-2] - wherey) * wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next;
(coords[pointer-1] - coords[pointer-3]) / return a->GetLink( x, y );
(coords[pointer] - coords[pointer - 2])) >= wherex) ? 1:0; }
} return wxEmptyString;
}
}
if ((intersects & 1) != 0)
{
return m_Link;
}
}
}
break;
}
if (m_Next)
{
wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next;
return a->GetLink( x, y );
}
return wxEmptyString;
} }
@@ -226,37 +201,36 @@ wxString wxHtmlImageMapAreaCell::GetLink( int x, int y ) const
class wxHtmlImageMapCell : public wxHtmlCell class wxHtmlImageMapCell : public wxHtmlCell
{ {
public: public:
wxHtmlImageMapCell( wxString &name ); wxHtmlImageMapCell( wxString &name );
protected: protected:
wxString m_Name; wxString m_Name;
public: public:
virtual wxString GetLink( int x = 0, int y = 0 ) const; virtual wxString GetLink( int x = 0, int y = 0 ) const;
virtual const wxHtmlCell *Find( int cond, const void *param ) const; virtual const wxHtmlCell *Find( int cond, const void *param ) const;
}; };
wxHtmlImageMapCell::wxHtmlImageMapCell( wxString &name ) wxHtmlImageMapCell::wxHtmlImageMapCell( wxString &name )
{ {
m_Name = name ; m_Name = name ;
} }
wxString wxHtmlImageMapCell::GetLink( int x, int y ) const wxString wxHtmlImageMapCell::GetLink( int x, int y ) const
{ {
wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next; wxHtmlImageMapAreaCell *a = (wxHtmlImageMapAreaCell*)m_Next;
if (a) if (a)
return a->GetLink( x, y ); return a->GetLink( x, y );
return wxHtmlCell::GetLink( x, y ); return wxHtmlCell::GetLink( x, y );
} }
const wxHtmlCell *wxHtmlImageMapCell::Find( int cond, const void *param ) const const wxHtmlCell *wxHtmlImageMapCell::Find( int cond, const void *param ) const
{ {
if (cond == wxHTML_COND_ISIMAGEMAP) if (cond == wxHTML_COND_ISIMAGEMAP) {
{ if (m_Name == *((wxString*)(param)))
if (m_Name == *((wxString*)(param))) return this;
return this; }
} return wxHtmlCell::Find(cond, param);
return wxHtmlCell::Find(cond, param);
} }
@@ -272,13 +246,13 @@ class wxHtmlImageCell : public wxHtmlCell
{ {
public: public:
wxBitmap *m_Image; wxBitmap *m_Image;
wxHtmlImageMapCell *m_ImageMap; wxHtmlImageMapCell *m_ImageMap;
wxString m_MapName; wxString m_MapName;
wxHtmlImageCell(wxFSFile *input, int w = -1, int h = -1, int align = wxHTML_ALIGN_BOTTOM, wxString mapname = wxEmptyString); wxHtmlImageCell(wxFSFile *input, int w = -1, int h = -1, int align = wxHTML_ALIGN_BOTTOM, wxString mapname = wxEmptyString);
~wxHtmlImageCell() {if (m_Image) delete m_Image;} ~wxHtmlImageCell() {if (m_Image) delete m_Image; }
void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
virtual wxString GetLink( int x = 0, int y = 0 ) const; virtual wxString GetLink( int x = 0, int y = 0 ) const;
}; };
@@ -305,18 +279,21 @@ wxHtmlImageCell::wxHtmlImageCell(wxFSFile *input, int w, int h, int align, wxStr
if ((m_Width != ww) || (m_Height != hh)) { if ((m_Width != ww) || (m_Height != hh)) {
wxImage img2 = img -> Scale(m_Width, m_Height); wxImage img2 = img -> Scale(m_Width, m_Height);
m_Image = new wxBitmap(img2.ConvertToBitmap()); m_Image = new wxBitmap(img2.ConvertToBitmap());
} } else
else
m_Image = new wxBitmap(img -> ConvertToBitmap()); m_Image = new wxBitmap(img -> ConvertToBitmap());
delete img; delete img;
} }
switch (align) { switch (align) {
case wxHTML_ALIGN_TOP : case wxHTML_ALIGN_TOP :
m_Descent = m_Height; break; m_Descent = m_Height;
break;
case wxHTML_ALIGN_CENTER : case wxHTML_ALIGN_CENTER :
m_Descent = m_Height / 2; break; m_Descent = m_Height / 2;
case wxHTML_ALIGN_BOTTOM : default : break;
m_Descent = 0; break; case wxHTML_ALIGN_BOTTOM :
default :
m_Descent = 0;
break;
} }
m_ImageMap = NULL; m_ImageMap = NULL;
@@ -335,31 +312,28 @@ void wxHtmlImageCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
wxString wxHtmlImageCell::GetLink( int x, int y ) const wxString wxHtmlImageCell::GetLink( int x, int y ) const
{ {
if (m_MapName.IsEmpty()) if (m_MapName.IsEmpty())
return wxHtmlCell::GetLink( x, y ); return wxHtmlCell::GetLink( x, y );
if (!m_ImageMap) if (!m_ImageMap) {
{ wxHtmlContainerCell *p, *op;
wxHtmlContainerCell *p, *op; op = p = GetParent();
op = p = GetParent(); while (p) {
while (p) op = p;
{ p = p->GetParent();
op = p;
p = p->GetParent();
}
p = op;
wxHtmlCell *cell = (wxHtmlCell*)p->Find( wxHTML_COND_ISIMAGEMAP, (const void*)(&m_MapName));
if (!cell)
{
((wxString&)m_MapName).Clear();
return wxHtmlCell::GetLink( x, y );
}
{ // dirty hack, ask Joel why he fills m_ImageMap in this place
// THE problem is that we're in const method and we can't modify m_ImageMap
wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_ImageMap);
*cx = (wxHtmlImageMapCell*)cell;
} }
} p = op;
return m_ImageMap->GetLink( x, y ); wxHtmlCell *cell = (wxHtmlCell*)p->Find( wxHTML_COND_ISIMAGEMAP, (const void*)(&m_MapName));
if (!cell) {
((wxString&)m_MapName).Clear();
return wxHtmlCell::GetLink( x, y );
}
{ // dirty hack, ask Joel why he fills m_ImageMap in this place
// THE problem is that we're in const method and we can't modify m_ImageMap
wxHtmlImageMapCell **cx = (wxHtmlImageMapCell**)(&m_ImageMap);
*cx = (wxHtmlImageMapCell*)cell;
}
}
return m_ImageMap->GetLink( x, y );
} }
@@ -368,97 +342,83 @@ wxString wxHtmlImageCell::GetLink( int x, int y ) const
// tag handler // tag handler
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
TAG_HANDLER_BEGIN(IMG, "IMG, MAP, AREA") TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
TAG_HANDLER_PROC(tag) TAG_HANDLER_PROC(tag)
{ {
if (tag.GetName() == "IMG") if (tag.GetName() == "IMG") {
{ if (tag.HasParam("SRC")) {
if (tag.HasParam("SRC")) { int w = -1, h = -1;
int w = -1, h = -1; int al;
int al; wxFSFile *str;
wxFSFile *str; wxString tmp = tag.GetParam("SRC");
wxString tmp = tag.GetParam("SRC"); wxString mn = wxEmptyString;
wxString mn = wxEmptyString;
str = m_WParser -> GetFS() -> OpenFile(tmp); str = m_WParser -> GetFS() -> OpenFile(tmp);
if (tag.HasParam(wxT("WIDTH"))) tag.ScanParam(wxT("WIDTH"), wxT("%i"), &w); if (tag.HasParam(wxT("WIDTH"))) tag.ScanParam(wxT("WIDTH"), wxT("%i"), &w);
if (tag.HasParam(wxT("HEIGHT"))) tag.ScanParam(wxT("HEIGHT"), wxT("%i"), &h); if (tag.HasParam(wxT("HEIGHT"))) tag.ScanParam(wxT("HEIGHT"), wxT("%i"), &h);
al = wxHTML_ALIGN_BOTTOM; al = wxHTML_ALIGN_BOTTOM;
if (tag.HasParam("ALIGN")) { if (tag.HasParam("ALIGN")) {
wxString alstr = tag.GetParam("ALIGN"); wxString alstr = tag.GetParam("ALIGN");
alstr.MakeUpper(); // for the case alignment was in ".." alstr.MakeUpper(); // for the case alignment was in ".."
if (alstr == "TEXTTOP") al = wxHTML_ALIGN_TOP; if (alstr == "TEXTTOP") al = wxHTML_ALIGN_TOP;
else if ((alstr == "CENTER") || (alstr == "ABSCENTER")) al = wxHTML_ALIGN_CENTER; else if ((alstr == "CENTER") || (alstr == "ABSCENTER")) al = wxHTML_ALIGN_CENTER;
} }
if (tag.HasParam("USEMAP")) if (tag.HasParam("USEMAP")) {
{ mn = tag.GetParam( "USEMAP" );
mn = tag.GetParam( "USEMAP" ); if (mn[ 0 ] == '#') {
if (mn[ 0 ] == '#') mn = mn.Mid( 1 );
{ }
mn = mn.Mid( 1 ); }
} wxHtmlImageCell *cel = NULL;
} if (str) {
wxHtmlImageCell *cel = NULL; cel = new wxHtmlImageCell(str, w, h, al, mn);
if (str) { cel -> SetLink(m_WParser -> GetLink());
cel = new wxHtmlImageCell(str, w, h, al, mn); m_WParser -> GetContainer() -> InsertCell(cel);
cel -> SetLink(m_WParser -> GetLink()); delete str;
m_WParser -> GetContainer() -> InsertCell(cel); }
delete str; }
} }
} if (tag.GetName() == "MAP") {
} m_WParser->CloseContainer();
if (tag.GetName() == "MAP") m_WParser->OpenContainer();
{ if (tag.HasParam("NAME")) {
m_WParser->CloseContainer(); wxString tmp = tag.GetParam("NAME");
m_WParser->OpenContainer(); wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp );
if (tag.HasParam("NAME")) m_WParser->GetContainer()->InsertCell( cel );
{ }
wxString tmp = tag.GetParam("NAME"); ParseInner( tag );
wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp ); m_WParser->CloseContainer();
m_WParser->GetContainer()->InsertCell( cel ); m_WParser->OpenContainer();
} }
ParseInner( tag ); if (tag.GetName() == "AREA") {
m_WParser->CloseContainer(); if (tag.HasParam("SHAPE")) {
m_WParser->OpenContainer(); wxString tmp = tag.GetParam("SHAPE");
} wxString coords;
if (tag.GetName() == "AREA") tmp.MakeUpper();
{ wxHtmlImageMapAreaCell *cel = NULL;
if (tag.HasParam("SHAPE")) if (tag.HasParam("COORDS")) {
{ coords = tag.GetParam("COORDS");
wxString tmp = tag.GetParam("SHAPE"); }
wxString coords; if (tmp == "POLY") {
tmp.MakeUpper(); cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords );
wxHtmlImageMapAreaCell *cel = NULL; } else if (tmp == "CIRCLE") {
if (tag.HasParam("COORDS")) cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::CIRCLE, coords );
{ } else if (tmp == "RECT") {
coords = tag.GetParam("COORDS"); cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords );
} }
if (tmp == "POLY") if (cel != NULL && tag.HasParam("HREF")) {
{ wxString tmp = tag.GetParam("HREF");
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords ); cel->SetLink( tmp );
} }
else if (tmp == "CIRCLE") if (cel != NULL) m_WParser->GetContainer()->InsertCell( cel );
{ }
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::CIRCLE, coords ); }
}
else if (tmp == "RECT")
{
cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords );
}
if (cel != NULL && tag.HasParam("HREF"))
{
wxString tmp = tag.GetParam("HREF");
cel->SetLink( tmp );
}
if (cel != NULL) m_WParser->GetContainer()->InsertCell( cel );
}
}
return FALSE; return FALSE;
} }
TAG_HANDLER_END(IMAGE) TAG_HANDLER_END(IMG)

View File

@@ -411,8 +411,8 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
TAG_HANDLER_CONSTR(TABLE) TAG_HANDLER_CONSTR(TABLE)
{ {
m_Table = NULL; m_Table = NULL;
m_tAlign = m_rAlign = wxEmptyString; m_tAlign = m_rAlign = wxEmptyString;
m_OldAlign = wxHTML_ALIGN_LEFT; m_OldAlign = wxHTML_ALIGN_LEFT;
} }