}
-/// Starts highlighting the selection
-static
-inline void StartHighlighting(wxDC &dc)
-{
- dc.SetBrush(*wxBLACK_BRUSH);
- dc.SetPen(wxPen(*wxBLACK,1,wxSOLID));
- dc.SetLogicalFunction(wxINVERT);
-}
-
-/// Ends highlighting the selection
-static
-inline void EndHighlighting(wxDC &dc)
-{
- dc.SetLogicalFunction(wxCOPY);
-}
//@}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
void
wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords,
+ wxLayoutList *wxllist,
CoordType begin, CoordType end)
{
if(begin == -1)
dc.DrawText(str, xpos, ypos);
dc.GetTextExtent(str, &width, &height, &descent);
xpos += width;
- StartHighlighting(dc);
+ wxllist->StartHighlighting(dc);
str = m_Text.Mid(begin, end-begin);
dc.DrawText(str, xpos, ypos);
dc.GetTextExtent(str, &width, &height, &descent);
xpos += width;
- dc.SetLogicalFunction(wxCOPY);
+ wxllist->EndHighlighting(dc);
str = m_Text.Mid(end, m_Text.Length()-end);
dc.DrawText(str, xpos, ypos);
}
void
wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &coords,
+ wxLayoutList *wxllist,
CoordType begin, CoordType /* len */)
{
- if(begin == 0)
- StartHighlighting(dc);
-
dc.DrawBitmap(*m_Icon, coords.x, coords.y-m_Icon->GetHeight(),
(m_Icon->GetMask() == NULL) ? FALSE : TRUE);
}
void
wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const & /* coords */,
+ wxLayoutList *wxllist,
CoordType begin, CoordType /* len */)
{
wxASSERT(m_font);
wxLayoutObjectCmd::Layout(wxDC &dc)
{
// this get called, so that recalculation uses right font sizes
- Draw(dc, wxPoint(0,0));
+ Draw(dc, wxPoint(0,0), NULL);
}
CoordType from, to, tempto;
int highlight = llist->IsSelected(this, &from, &to);
if(highlight == 1) // we need to draw the whole line inverted!
- StartHighlighting(dc);
+ llist->StartHighlighting(dc);
else
- EndHighlighting(dc);
+ llist->EndHighlighting(dc);
for(i = m_ObjectList.begin(); i != NULLIT; i++)
{
{
// parts of the line need highlighting
tempto = xpos+(**i).GetLength();
- if(tempto >= from && tempto <= to)
+ if(tempto >= from && xpos <= to)
{
tempto = to-xpos;
if(tempto > (**i).GetLength())
tempto = (**i).GetLength();
- (**i).Draw(dc, pos, from-xpos, to);
+ CoordType tmp = from-xpos;
+ if(tmp < 0) tmp = 0;
+ (**i).Draw(dc, pos, llist, from-xpos, to);
}
else
- EndHighlighting(dc);
+ {
+ llist->EndHighlighting(dc); // FIXME! inefficient
+ (**i).Draw(dc, pos, llist);
+ }
}
else
- (**i).Draw(dc, pos);
+ (**i).Draw(dc, pos, llist);
pos.x += (**i).GetWidth();
xpos += (**i).GetLength();
}
wxLayoutLine *line = m_FirstLine;
Layout(dc, bottom);
- m_DefaultSetting->Draw(dc, wxPoint(0,0));
+ m_DefaultSetting->Draw(dc, wxPoint(0,0), this);
wxBrush brush(m_ColourBG, wxSOLID);
dc.SetBrush(brush);
m_CursorLine->GetNextLine() == NULL &&
m_CursorLine == m_FirstLine));
InvalidateUpdateRect();
+
+ wxLogDebug("Selection is %s : l%d,%ld/%ld,%ld",
+ m_Selection.m_valid ? "valid" : "invalid",
+ m_Selection.m_CursorA.x, m_Selection.m_CursorA.y,
+ m_Selection.m_CursorB.x, m_Selection.m_CursorB.y);
}
wxLayoutObject *
}
void
-wxLayoutList::EndSelection(void)
+wxLayoutList::ContinueSelection(void)
{
- wxLogDebug("Ending selection at %ld/%ld", m_CursorPos.x, m_CursorPos.y);
+ wxASSERT(m_Selection.m_selecting == true);
+ wxASSERT(m_Selection.m_valid == false);
+ wxLogDebug("Continuing selection at %ld/%ld", m_CursorPos.x, m_CursorPos.y);
m_Selection.m_CursorB = m_CursorPos;
- m_Selection.m_selecting = false;
- m_Selection.m_valid = true;
-
// We always want m_CursorA <= m_CursorB!
if(! (m_Selection.m_CursorA <= m_Selection.m_CursorB))
{
}
}
+void
+wxLayoutList::EndSelection(void)
+{
+ ContinueSelection();
+ wxLogDebug("Ending selection at %ld/%ld", m_CursorPos.x, m_CursorPos.y);
+ m_Selection.m_selecting = false;
+ m_Selection.m_valid = true;
+}
+
+
bool
wxLayoutList::IsSelecting(void)
{
bool
wxLayoutList::IsSelected(const wxPoint &cursor)
{
+ if(! m_Selection.m_valid && ! m_Selection.m_selecting)
+ return false;
return m_Selection.m_CursorA <= cursor
&& cursor <= m_Selection.m_CursorB;
}
{
wxASSERT(line); wxASSERT(to); wxASSERT(from);
+ if(! m_Selection.m_valid && ! m_Selection.m_selecting)
+ return 0;
+
CoordType y = line->GetLineNumber();
if(m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y)
return 1;
return 0;
}
+
+/// Starts highlighting the selection
+void
+wxLayoutList::StartHighlighting(wxDC &dc)
+{
+ dc.SetTextForeground(m_ColourBG);
+ dc.SetTextBackground(m_ColourFG);
+}
+
+/// Ends highlighting the selection
+void
+wxLayoutList::EndHighlighting(wxDC &dc)
+{
+ dc.SetTextForeground(m_ColourFG);
+ dc.SetTextBackground(m_ColourBG);
+}
+
+
#ifdef WXLAYOUT_DEBUG
void
/** Draws an object.
@param dc the wxDC to draw on
@param coords where to draw the baseline of the object.
+ @param wxllist pointer to wxLayoutList
@param begin if !=-1, from which position on to highlight it
@param end if begin !=-1, how many positions to highlight it
*/
virtual void Draw(wxDC & /* dc */,
wxPoint const & /* coords */,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1) { }
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
virtual void Layout(wxDC &dc);
virtual void Draw(wxDC &dc, wxPoint const &coords,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
/** Calculates and returns the size of the object.
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
virtual void Layout(wxDC &dc);
virtual void Draw(wxDC &dc, wxPoint const &coords,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
virtual void Layout(wxDC &dc);
virtual void Draw(wxDC &dc, wxPoint const &coords,
+ class wxLayoutList *wxllist,
CoordType begin = -1,
CoordType end = -1);
wxLayoutObjectCmd(int size, int family, int style, int weight,
/// Begin selecting text.
void StartSelection(void);
+ // Continue selecting text
+ void ContinueSelection(void);
/// End selecting text.
void EndSelection(void);
/// Are we still selecting text?
bool IsSelecting(void);
bool IsSelected(const wxPoint &cursor);
+ /// starts highlighting of text for selections
+ void StartHighlighting(wxDC &dc);
+ /// ends highlighting of text for selections
+ void EndHighlighting(wxDC &dc);
+
/** Tests whether this layout line is selected and needs
highlighting.
@param line to test for
}
#endif
- if(!IsEditable()) // do nothing
+ long keyCode = event.KeyCode();
+ if(m_Selecting && ! event.ShiftDown())
{
- event.Skip();
- return;
+ m_llist->EndSelection();
+ m_Selecting = false;
}
-
- long keyCode = event.KeyCode();
- if(event.ShiftDown())
- m_Selecting = true;
else
+ if(! m_Selecting && event.ShiftDown())
+ {
+ switch(keyCode)
+ {
+ case WXK_UP:
+ case WXK_DOWN:
+ case WXK_RIGHT:
+ case WXK_LEFT:
+ case WXK_PRIOR:
+ case WXK_NEXT:
+ case WXK_HOME:
+ case WXK_END:
+ m_Selecting = true;
+ m_llist->StartSelection();
+ break;
+ default:
+ ;
+ }
+ }
+
+ if(!IsEditable()) // do nothing
{
- if(m_Selecting)
- m_llist->EndSelection();
- m_Selecting = false;
+ switch(keyCode)
+ {
+ case WXK_UP:
+ m_llist->MoveCursorVertically(-1);
+ break;
+ case WXK_DOWN:
+ m_llist->MoveCursorVertically(1);
+ break;
+ case WXK_PRIOR:
+ m_llist->MoveCursorVertically(-20);
+ break;
+ case WXK_NEXT:
+ m_llist->MoveCursorVertically(20);
+ break;
+ default:
+ ;
+ }
+ return;
}
+
/* First, handle control keys */
if(event.ControlDown() && ! event.AltDown())
{
switch(keyCode)
{
case WXK_RIGHT:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorHorizontally(1);
break;
case WXK_LEFT:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorHorizontally(-1);
break;
case WXK_UP:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(-1);
break;
case WXK_DOWN:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(1);
break;
case WXK_PRIOR:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(-20);
break;
case WXK_NEXT:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(20);
break;
case WXK_HOME:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorToBeginOfLine();
break;
case WXK_END:
- if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorToEndOfLine();
break;
case WXK_DELETE :
// Device origins on the memDC are suspect, we translate manually
// with the translate parameter of Draw().
m_memDC->SetDeviceOrigin(0,0);
- m_memDC->SetBackgroundMode(wxTRANSPARENT);
m_memDC->SetBrush(wxBrush(m_llist->GetDefaults()->GetBGColour(), wxSOLID));
m_memDC->SetPen(wxPen(m_llist->GetDefaults()->GetBGColour(),0,wxTRANSPARENT));
m_memDC->SetLogicalFunction(wxCOPY);
for(y = 0; y < y1; y+=h)
for(x = 0; x < x1; x+=w)
m_memDC->DrawBitmap(*m_BGbitmap, x, y);
+ m_memDC->SetBackgroundMode(wxTRANSPARENT);
}
else
+ {
+ m_memDC->SetBackgroundMode(wxSOLID);
m_memDC->DrawRectangle(0,0,x1, y1);
-
+ }
/* This is the important bit: we tell the list to draw itself: */