]> git.saurik.com Git - wxWidgets.git/blobdiff - src/html/htmlcell.cpp
Attempt to make wxWindows play better with XP themes
[wxWidgets.git] / src / html / htmlcell.cpp
index 2e2fa772d9db080e52140e010baa3516ec2eef0b..ad79eb042fc0c6d4feb8a15ef7a42c0f3d89bf2d 100644 (file)
@@ -119,12 +119,33 @@ const wxHtmlCell* wxHtmlCell::Find(int WXUNUSED(condition), const void* WXUNUSED
 wxHtmlCell *wxHtmlCell::FindCellByPos(wxCoord x, wxCoord y,
                                       unsigned flags) const
 {
-    if ( (flags & wxHTML_FIND_TERMINAL) &&
-         x >= 0 && x < m_Width && y >= 0 && y < m_Height )
+    if ( x >= 0 && x < m_Width && y >= 0 && y < m_Height )
     {
         return wxConstCast(this, wxHtmlCell);
     }
-    return NULL;
+    else
+    {
+        if ((flags & wxHTML_FIND_NEAREST_AFTER) &&
+                (y < 0 || (y == 0 && x <= 0)))
+            return wxConstCast(this, wxHtmlCell);
+        else if ((flags & wxHTML_FIND_NEAREST_BEFORE) &&
+                (y > m_Height-1 || (y == m_Height-1 && x >= m_Width)))
+            return wxConstCast(this, wxHtmlCell);
+        else
+            return NULL;
+    }
+}
+
+
+wxPoint wxHtmlCell::GetAbsPos() const
+{
+    wxPoint p(m_PosX, m_PosY);
+    for (wxHtmlCell *parent = m_Parent; parent; parent = parent->m_Parent)
+    {
+        p.x += parent->m_PosX;
+        p.y += parent->m_PosY;
+    }
+    return p;
 }
 
 
@@ -145,7 +166,7 @@ void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
                           int WXUNUSED(view_y1), int WXUNUSED(view_y2),
                           wxHtmlRenderingState& state)
 {
-    if (state.GetSelectionState() == wxHTML_SEL_IN &&
+    if (state.GetSelectionState() != wxHTML_SEL_OUT &&
         dc.GetBackgroundMode() != wxSOLID)
     {
         dc.SetBackgroundMode(wxSOLID);
@@ -429,7 +450,7 @@ void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingState& state,
 {
     wxHtmlSelection *s = state.GetSelection();
     if (!s) return;
-    if (s->GetFromCell() == this || s->GetToCell() == this)
+    if (s->GetFromCell() == cell || s->GetToCell() == cell)
     {
         state.SetSelectionState(wxHTML_SEL_CHANGING);
     }
@@ -440,10 +461,10 @@ void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingState& state,
 {
     wxHtmlSelection *s = state.GetSelection();
     if (!s) return;
-    if (s->GetFromCell() == this)
-        state.SetSelectionState(wxHTML_SEL_IN);
-    else if (s->GetToCell() == this)
+    if (s->GetToCell() == cell)
         state.SetSelectionState(wxHTML_SEL_OUT);
+    else if (s->GetFromCell() == cell)
+        state.SetSelectionState(wxHTML_SEL_IN);
 }
 
 #define mMin(a, b) (((a) < (b)) ? (a) : (b))
@@ -616,24 +637,49 @@ const wxHtmlCell* wxHtmlContainerCell::Find(int condition, const void* param) co
 wxHtmlCell *wxHtmlContainerCell::FindCellByPos(wxCoord x, wxCoord y,
                                                unsigned flags) const
 {
-    for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
+    if ( flags & wxHTML_FIND_EXACT )
     {
-        int cx = cell->GetPosX(),
-            cy = cell->GetPosY();
+        for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
+        {
+            int cx = cell->GetPosX(),
+                cy = cell->GetPosY();
 
-        if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
-             (cy <= y) && (cy + cell->GetHeight() > y) )
+            if ( (cx <= x) && (cx + cell->GetWidth() > x) &&
+                 (cy <= y) && (cy + cell->GetHeight() > y) )
+            {
+                return cell->FindCellByPos(x - cx, y - cy, flags);
+            }
+        }
+    }
+    else if ( flags & wxHTML_FIND_NEAREST_AFTER )
+    {
+        wxHtmlCell *c;
+        int y2;
+        for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
         {
-            wxHtmlCell *c = cell->FindCellByPos(x - cx, y - cy, flags);
-            if (c == NULL && (flags & wxHTML_FIND_NONTERMINAL))
-                return wxConstCast(this, wxHtmlContainerCell);
-            else
-                return c;
+            y2 = cell->GetPosY() + cell->GetHeight() - 1;
+            if (y2 < y || (y2 == y && cell->GetPosX()+cell->GetWidth()-1 < x))
+                continue;
+            c = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(),
+                                    flags);
+            if (c) return c;
+        }
+    }
+    else if ( flags & wxHTML_FIND_NEAREST_BEFORE )
+    {
+        wxHtmlCell *c;
+        for ( const wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext() )
+        {
+            if (cell->GetPosY() > y || 
+                    (cell->GetPosY() == y && cell->GetPosX() > x))
+                break;
+            c = cell->FindCellByPos(x - cell->GetPosX(), y - cell->GetPosY(),
+                                    flags);
+            if (c) return c;
         }
     }
 
-    return (flags & wxHTML_FIND_NONTERMINAL) ? 
-                wxConstCast(this, wxHtmlContainerCell) : NULL;
+    return NULL;
 }
 
 
@@ -669,6 +715,26 @@ void wxHtmlContainerCell::GetHorizontalConstraints(int *left, int *right) const
         *right = cright;
 }
 
+    
+wxHtmlCell *wxHtmlContainerCell::GetFirstTerminal() const
+{
+    if (m_Cells)
+        return m_Cells->GetFirstTerminal();
+    else
+        return NULL;
+}
+
+wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const
+{
+    if (m_Cells)
+    {
+        wxHtmlCell *c;
+        for (c = m_Cells; c->GetNext(); c = c->GetNext()) {}
+        return c;
+    }
+    else
+        return NULL;
+}