new rendering customization API for Vadim

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@20902 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2003-06-03 23:04:59 +00:00
parent 0ea0359bca
commit f30e67dbea
3 changed files with 136 additions and 78 deletions

View File

@@ -57,6 +57,19 @@ void wxHtmlSelection::Set(wxHtmlCell *fromCell, wxHtmlCell *toCell)
Set(p1, fromCell, p2, toCell); Set(p1, fromCell, p2, toCell);
} }
wxColour wxDefaultHtmlRenderingStyle::GetSelectedTextColour(
const wxColour& WXUNUSED(clr))
{
return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
}
wxColour wxDefaultHtmlRenderingStyle::GetSelectedTextBgColour(
const wxColour& WXUNUSED(clr))
{
return wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxHtmlCell // wxHtmlCell
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -238,8 +251,7 @@ wxHtmlWordCell::wxHtmlWordCell(const wxString& word, wxDC& dc) : wxHtmlCell()
// where s2 and s3 start: // where s2 and s3 start:
void wxHtmlWordCell::Split(wxDC& dc, void wxHtmlWordCell::Split(wxDC& dc,
const wxPoint& selFrom, const wxPoint& selTo, const wxPoint& selFrom, const wxPoint& selTo,
wxString& s1, wxString& s2, wxString& s3, unsigned& pos1, unsigned& pos2) const
unsigned& pos1, unsigned& pos2)
{ {
wxPoint pt1 = (selFrom == wxDefaultPosition) ? wxPoint pt1 = (selFrom == wxDefaultPosition) ?
wxDefaultPosition : selFrom - GetAbsPos(); wxDefaultPosition : selFrom - GetAbsPos();
@@ -250,7 +262,6 @@ void wxHtmlWordCell::Split(wxDC& dc,
unsigned len = m_Word.length(); unsigned len = m_Word.length();
unsigned i = 0; unsigned i = 0;
pos1 = 0; pos1 = 0;
s1 = s2 = s3 = wxEmptyString;
// before selection: // before selection:
while ( pt1.x > 0 && i < len ) while ( pt1.x > 0 && i < len )
@@ -279,94 +290,127 @@ void wxHtmlWordCell::Split(wxDC& dc,
} }
} }
s1 = m_Word.Mid(0, i); pos1 = i;
s2 = m_Word.Mid(i, j-i); pos2 = j;
s3 = m_Word.Mid(j); }
#if 0 // FIXME
printf(" '%s' %i '%s' %i '%s'\n", s1.mb_str(), pos1, void wxHtmlWordCell::SetSelectionPrivPos(wxDC& dc, wxHtmlSelection *s) const
s2.mb_str(), pos2,s3.mb_str()); {
#endif unsigned p1, p2;
Split(dc,
this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition,
this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition,
p1, p2);
wxPoint p(0, m_Word.length());
if ( this == s->GetFromCell() )
p.x = p1; // selection starts here
if ( this == s->GetToCell() )
p.y = p2; // selection ends here
if ( this == s->GetFromCell() )
s->SetFromPrivPos(p);
if ( this == s->GetToCell() )
s->SetToPrivPos(p);
} }
static void SwitchSelState(wxDC& dc, wxHtmlRenderingState& state, static void SwitchSelState(wxDC& dc, wxHtmlRenderingInfo& info,
bool toSelection) bool toSelection)
{ {
wxColour fg = info.GetState().GetFgColour();
wxColour bg = info.GetState().GetBgColour();
if ( toSelection ) if ( toSelection )
{ {
dc.SetBackgroundMode(wxSOLID); dc.SetBackgroundMode(wxSOLID);
dc.SetTextBackground( dc.SetTextForeground(info.GetStyle().GetSelectedTextColour(fg));
wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); dc.SetTextBackground(info.GetStyle().GetSelectedTextBgColour(bg));
dc.SetTextForeground(
wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
} }
else else
{ {
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
dc.SetTextForeground(state.GetFgColour()); dc.SetTextForeground(fg);
dc.SetTextBackground(state.GetBgColour()); dc.SetTextBackground(bg);
} }
} }
void wxHtmlWordCell::Draw(wxDC& dc, int x, int y, void wxHtmlWordCell::Draw(wxDC& dc, int x, int y,
int WXUNUSED(view_y1), int WXUNUSED(view_y2), int WXUNUSED(view_y1), int WXUNUSED(view_y2),
wxHtmlRenderingState& state) wxHtmlRenderingInfo& info)
{ {
#if 0 // useful for debugging #if 0 // useful for debugging
dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height); dc.DrawRectangle(x+m_PosX,y+m_PosY,m_Width,m_Height);
#endif #endif
if ( state.GetSelectionState() == wxHTML_SEL_CHANGING ) if ( info.GetState().GetSelectionState() == wxHTML_SEL_CHANGING )
{ {
// Selection changing, we must draw the word piecewise: // Selection changing, we must draw the word piecewise:
wxHtmlSelection *s = info.GetSelection();
wxString txt;
int w, h;
int ofs = 0;
unsigned ofs1, ofs2; wxPoint priv = (this == s->GetFromCell()) ?
wxString textBefore, textInside, textAfter; s->GetFromPrivPos() : s->GetToPrivPos();
wxHtmlSelection *s = state.GetSelection(); int part1 = priv.x;
int part2 = priv.y;
Split(dc, if ( part1 > 0 )
this == s->GetFromCell() ? s->GetFromPos() : wxDefaultPosition,
this == s->GetToCell() ? s->GetToPos() : wxDefaultPosition,
textBefore, textInside, textAfter, ofs1, ofs2);
dc.DrawText(textBefore, x + m_PosX, y + m_PosY);
int w1,w2,w3,h123;
dc.GetTextExtent(textBefore, &w1,&h123);
dc.GetTextExtent(textInside, &w2,&h123);
dc.GetTextExtent(textAfter, &w3,&h123);
if ( !textInside.empty() )
{ {
SwitchSelState(dc, state, true); txt = m_Word.Mid(0, part1);
dc.DrawText(textInside, x + m_PosX + ofs1, y + m_PosY); dc.DrawText(txt, x + m_PosX, y + m_PosY);
dc.GetTextExtent(txt, &w, &h);
ofs += w;
} }
if ( !textAfter.empty() )
SwitchSelState(dc, info, true);
txt = m_Word.Mid(part1, part2-part1);
dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
if ( part2 < m_Word.length() )
{ {
SwitchSelState(dc, state, false); dc.GetTextExtent(txt, &w, &h);
dc.DrawText(textAfter, x + m_PosX + ofs2, y + m_PosY); ofs += w;
SwitchSelState(dc, info, false);
txt = m_Word.Mid(part2);
dc.DrawText(txt, ofs + x + m_PosX, y + m_PosY);
} }
} }
else else
{ {
// Not changing selection state, draw the word in single mode: // Not changing selection state, draw the word in single mode:
if ( state.GetSelectionState() != wxHTML_SEL_OUT && if ( info.GetState().GetSelectionState() != wxHTML_SEL_OUT &&
dc.GetBackgroundMode() != wxSOLID ) dc.GetBackgroundMode() != wxSOLID )
{ {
SwitchSelState(dc, state, true); SwitchSelState(dc, info, true);
} }
else if ( state.GetSelectionState() == wxHTML_SEL_OUT && else if ( info.GetState().GetSelectionState() == wxHTML_SEL_OUT &&
dc.GetBackgroundMode() == wxSOLID ) dc.GetBackgroundMode() == wxSOLID )
{ {
SwitchSelState(dc, state, false); SwitchSelState(dc, info, false);
} }
dc.DrawText(m_Word, x + m_PosX, y + m_PosY); dc.DrawText(m_Word, x + m_PosX, y + m_PosY);
} }
} }
wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *sel) const wxString wxHtmlWordCell::ConvertToText(wxHtmlSelection *s) const
{ {
// FIXME - use selection if ( s && (this == s->GetFromCell() || this == s->GetToCell()) )
{
wxPoint priv = (this == s->GetFromCell()) ?
s->GetFromPrivPos() : s->GetToPrivPos();
int part1 = priv.x;
int part2 = priv.y;
return m_Word.Mid(part1, part2-part1);
}
else
return m_Word; return m_Word;
} }
@@ -629,33 +673,33 @@ void wxHtmlContainerCell::Layout(int w)
m_LastLayout = w; m_LastLayout = w;
} }
void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingState& state, void wxHtmlContainerCell::UpdateRenderingStatePre(wxHtmlRenderingInfo& info,
wxHtmlCell *cell) const wxHtmlCell *cell) const
{ {
wxHtmlSelection *s = state.GetSelection(); wxHtmlSelection *s = info.GetSelection();
if (!s) return; if (!s) return;
if (s->GetFromCell() == cell || s->GetToCell() == cell) if (s->GetFromCell() == cell || s->GetToCell() == cell)
{ {
state.SetSelectionState(wxHTML_SEL_CHANGING); info.GetState().SetSelectionState(wxHTML_SEL_CHANGING);
} }
} }
void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingState& state, void wxHtmlContainerCell::UpdateRenderingStatePost(wxHtmlRenderingInfo& info,
wxHtmlCell *cell) const wxHtmlCell *cell) const
{ {
wxHtmlSelection *s = state.GetSelection(); wxHtmlSelection *s = info.GetSelection();
if (!s) return; if (!s) return;
if (s->GetToCell() == cell) if (s->GetToCell() == cell)
state.SetSelectionState(wxHTML_SEL_OUT); info.GetState().SetSelectionState(wxHTML_SEL_OUT);
else if (s->GetFromCell() == cell) else if (s->GetFromCell() == cell)
state.SetSelectionState(wxHTML_SEL_IN); info.GetState().SetSelectionState(wxHTML_SEL_IN);
} }
#define mMin(a, b) (((a) < (b)) ? (a) : (b)) #define mMin(a, b) (((a) < (b)) ? (a) : (b))
#define mMax(a, b) (((a) < (b)) ? (b) : (a)) #define mMax(a, b) (((a) < (b)) ? (b) : (a))
void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
wxHtmlRenderingState& state) wxHtmlRenderingInfo& info)
{ {
// container visible, draw it: // container visible, draw it:
if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1)) if ((y + m_PosY <= view_y2) && (y + m_PosY + m_Height > view_y1))
@@ -690,33 +734,33 @@ void wxHtmlContainerCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
// draw container's contents: // draw container's contents:
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
{ {
UpdateRenderingStatePre(state, cell); UpdateRenderingStatePre(info, cell);
cell->Draw(dc, cell->Draw(dc,
x + m_PosX, y + m_PosY, view_y1, view_y2, x + m_PosX, y + m_PosY, view_y1, view_y2,
state); info);
UpdateRenderingStatePost(state, cell); UpdateRenderingStatePost(info, cell);
} }
} }
} }
// container invisible, just proceed font+color changing: // container invisible, just proceed font+color changing:
else else
{ {
DrawInvisible(dc, x, y, state); DrawInvisible(dc, x, y, info);
} }
} }
void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y, void wxHtmlContainerCell::DrawInvisible(wxDC& dc, int x, int y,
wxHtmlRenderingState& state) wxHtmlRenderingInfo& info)
{ {
if (m_Cells) if (m_Cells)
{ {
for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext()) for (wxHtmlCell *cell = m_Cells; cell; cell = cell->GetNext())
{ {
UpdateRenderingStatePre(state, cell); UpdateRenderingStatePre(info, cell);
cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, state); cell->DrawInvisible(dc, x + m_PosX, y + m_PosY, info);
UpdateRenderingStatePost(state, cell); UpdateRenderingStatePost(info, cell);
} }
} }
} }
@@ -945,15 +989,16 @@ wxHtmlCell *wxHtmlContainerCell::GetLastTerminal() const
void wxHtmlColourCell::Draw(wxDC& dc, void wxHtmlColourCell::Draw(wxDC& dc,
int x, int y, int x, int y,
int WXUNUSED(view_y1), int WXUNUSED(view_y2), int WXUNUSED(view_y1), int WXUNUSED(view_y2),
wxHtmlRenderingState& state) wxHtmlRenderingInfo& info)
{ {
DrawInvisible(dc, x, y, state); DrawInvisible(dc, x, y, info);
} }
void wxHtmlColourCell::DrawInvisible(wxDC& dc, void wxHtmlColourCell::DrawInvisible(wxDC& dc,
int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(x), int WXUNUSED(y),
wxHtmlRenderingState& state) wxHtmlRenderingInfo& info)
{ {
wxHtmlRenderingState& state = info.GetState();
if (m_Flags & wxHTML_CLR_FOREGROUND) if (m_Flags & wxHTML_CLR_FOREGROUND)
{ {
state.SetFgColour(m_Colour); state.SetFgColour(m_Colour);
@@ -979,13 +1024,13 @@ void wxHtmlColourCell::DrawInvisible(wxDC& dc,
void wxHtmlFontCell::Draw(wxDC& dc, void wxHtmlFontCell::Draw(wxDC& dc,
int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(x), int WXUNUSED(y),
int WXUNUSED(view_y1), int WXUNUSED(view_y2), int WXUNUSED(view_y1), int WXUNUSED(view_y2),
wxHtmlRenderingState& WXUNUSED(state)) wxHtmlRenderingInfo& WXUNUSED(info))
{ {
dc.SetFont(m_Font); dc.SetFont(m_Font);
} }
void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y), void wxHtmlFontCell::DrawInvisible(wxDC& dc, int WXUNUSED(x), int WXUNUSED(y),
wxHtmlRenderingState& WXUNUSED(state)) wxHtmlRenderingInfo& WXUNUSED(info))
{ {
dc.SetFont(m_Font); dc.SetFont(m_Font);
} }
@@ -1014,7 +1059,7 @@ wxHtmlWidgetCell::wxHtmlWidgetCell(wxWindow *wnd, int w)
void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc), void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc),
int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(x), int WXUNUSED(y),
int WXUNUSED(view_y1), int WXUNUSED(view_y2), int WXUNUSED(view_y1), int WXUNUSED(view_y2),
wxHtmlRenderingState& WXUNUSED(state)) wxHtmlRenderingInfo& WXUNUSED(info))
{ {
int absx = 0, absy = 0, stx, sty; int absx = 0, absy = 0, stx, sty;
wxHtmlCell *c = this; wxHtmlCell *c = this;
@@ -1034,7 +1079,7 @@ void wxHtmlWidgetCell::Draw(wxDC& WXUNUSED(dc),
void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc), void wxHtmlWidgetCell::DrawInvisible(wxDC& WXUNUSED(dc),
int WXUNUSED(x), int WXUNUSED(y), int WXUNUSED(x), int WXUNUSED(y),
wxHtmlRenderingState& WXUNUSED(state)) wxHtmlRenderingInfo& WXUNUSED(info))
{ {
int absx = 0, absy = 0, stx, sty; int absx = 0, absy = 0, stx, sty;
wxHtmlCell *c = this; wxHtmlCell *c = this;

View File

@@ -642,6 +642,8 @@ wxString wxHtmlWindow::SelectionToText()
if ( !m_selection ) if ( !m_selection )
return wxEmptyString; return wxEmptyString;
wxClientDC dc(this);
const wxHtmlCell *end = m_selection->GetToCell(); const wxHtmlCell *end = m_selection->GetToCell();
wxString text; wxString text;
wxHtmlTerminalCellsInterator i(m_selection->GetFromCell(), end); wxHtmlTerminalCellsInterator i(m_selection->GetFromCell(), end);
@@ -714,11 +716,14 @@ void wxHtmlWindow::OnDraw(wxDC& dc)
dc.SetBackgroundMode(wxTRANSPARENT); dc.SetBackgroundMode(wxTRANSPARENT);
GetViewStart(&x, &y); GetViewStart(&x, &y);
wxHtmlRenderingState rstate(m_selection); wxHtmlRenderingInfo rinfo;
wxDefaultHtmlRenderingStyle rstyle;
rinfo.SetSelection(m_selection);
rinfo.SetStyle(&rstyle);
m_Cell->Draw(dc, 0, 0, m_Cell->Draw(dc, 0, 0,
y * wxHTML_SCROLL_STEP + rect.GetTop(), y * wxHTML_SCROLL_STEP + rect.GetTop(),
y * wxHTML_SCROLL_STEP + rect.GetBottom(), y * wxHTML_SCROLL_STEP + rect.GetBottom(),
rstate); rinfo);
} }
@@ -765,6 +770,9 @@ void wxHtmlWindow::OnMouseUp(wxMouseEvent& event)
// did the user move the mouse far enough from starting point? // did the user move the mouse far enough from starting point?
if ( m_selection ) if ( m_selection )
{ {
#ifdef __UNIX__
CopySelection(Primary);
#endif
// we don't want mouse up event that ended selecting to be // we don't want mouse up event that ended selecting to be
// handled as mouse click and e.g. follow hyperlink: // handled as mouse click and e.g. follow hyperlink:
return; return;
@@ -870,17 +878,20 @@ void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
if ( m_tmpSelFromCell->IsBefore(selcell) ) if ( m_tmpSelFromCell->IsBefore(selcell) )
{ {
m_selection->Set(m_tmpSelFromPos, m_tmpSelFromCell, m_selection->Set(m_tmpSelFromPos, m_tmpSelFromCell,
wxPoint(x,y), selcell); wxPoint(x,y), selcell); }
}
else else
{ {
m_selection->Set(wxPoint(x,y), selcell, m_selection->Set(wxPoint(x,y), selcell,
m_tmpSelFromPos, m_tmpSelFromCell); m_tmpSelFromPos, m_tmpSelFromCell);
} }
{
wxClientDC dc(this);
m_selection->GetFromCell()->SetSelectionPrivPos(
dc, m_selection);
m_selection->GetToCell()->SetSelectionPrivPos(
dc, m_selection);
}
Refresh(); // FIXME - optimize! Refresh(); // FIXME - optimize!
#ifdef __UNIX__
CopySelection(Primary);
#endif
} }
} }
} }

View File

@@ -114,13 +114,15 @@ int wxHtmlDCRenderer::Render(int x, int y, int from, int dont_render, int to, in
if (!dont_render) if (!dont_render)
{ {
wxHtmlRenderingState rstate(NULL); wxHtmlRenderingInfo rinfo;
wxDefaultHtmlRenderingStyle rstyle;
rinfo.SetStyle(&rstyle);
m_DC->SetBrush(*wxWHITE_BRUSH); m_DC->SetBrush(*wxWHITE_BRUSH);
m_DC->SetClippingRegion(x, y, m_Width, hght); m_DC->SetClippingRegion(x, y, m_Width, hght);
m_Cells->Draw(*m_DC, m_Cells->Draw(*m_DC,
x, (y - from), x, (y - from),
y, pbreak + (y /*- from*/), y, pbreak + (y /*- from*/),
rstate); rinfo);
m_DC->DestroyClippingRegion(); m_DC->DestroyClippingRegion();
} }