Selection marking seems fine now.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2377 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder 1999-05-09 17:28:58 +00:00
parent 18d084cf1f
commit 404d805e79
4 changed files with 125 additions and 57 deletions

View File

@ -110,21 +110,6 @@ bool Contains(const wxRect &r, const wxPoint &p)
} }
/// 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);
}
//@} //@}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
@ -164,6 +149,7 @@ wxLayoutObjectText::GetSize(CoordType *top, CoordType *bottom) const
void void
wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords, wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords,
wxLayoutList *wxllist,
CoordType begin, CoordType end) CoordType begin, CoordType end)
{ {
if(begin == -1) if(begin == -1)
@ -181,12 +167,12 @@ wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords,
dc.DrawText(str, xpos, ypos); dc.DrawText(str, xpos, ypos);
dc.GetTextExtent(str, &width, &height, &descent); dc.GetTextExtent(str, &width, &height, &descent);
xpos += width; xpos += width;
StartHighlighting(dc); wxllist->StartHighlighting(dc);
str = m_Text.Mid(begin, end-begin); str = m_Text.Mid(begin, end-begin);
dc.DrawText(str, xpos, ypos); dc.DrawText(str, xpos, ypos);
dc.GetTextExtent(str, &width, &height, &descent); dc.GetTextExtent(str, &width, &height, &descent);
xpos += width; xpos += width;
dc.SetLogicalFunction(wxCOPY); wxllist->EndHighlighting(dc);
str = m_Text.Mid(end, m_Text.Length()-end); str = m_Text.Mid(end, m_Text.Length()-end);
dc.DrawText(str, xpos, ypos); dc.DrawText(str, xpos, ypos);
} }
@ -263,11 +249,9 @@ wxLayoutObjectIcon::wxLayoutObjectIcon(wxBitmap *icon)
void void
wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &coords, wxLayoutObjectIcon::Draw(wxDC &dc, wxPoint const &coords,
wxLayoutList *wxllist,
CoordType begin, CoordType /* len */) CoordType begin, CoordType /* len */)
{ {
if(begin == 0)
StartHighlighting(dc);
dc.DrawBitmap(*m_Icon, coords.x, coords.y-m_Icon->GetHeight(), dc.DrawBitmap(*m_Icon, coords.x, coords.y-m_Icon->GetHeight(),
(m_Icon->GetMask() == NULL) ? FALSE : TRUE); (m_Icon->GetMask() == NULL) ? FALSE : TRUE);
} }
@ -341,6 +325,7 @@ wxLayoutObjectCmd::GetStyle(wxLayoutStyleInfo *si) const
void void
wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const & /* coords */, wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint const & /* coords */,
wxLayoutList *wxllist,
CoordType begin, CoordType /* len */) CoordType begin, CoordType /* len */)
{ {
wxASSERT(m_font); wxASSERT(m_font);
@ -353,7 +338,7 @@ void
wxLayoutObjectCmd::Layout(wxDC &dc) wxLayoutObjectCmd::Layout(wxDC &dc)
{ {
// this get called, so that recalculation uses right font sizes // this get called, so that recalculation uses right font sizes
Draw(dc, wxPoint(0,0)); Draw(dc, wxPoint(0,0), NULL);
} }
@ -687,9 +672,9 @@ wxLayoutLine::Draw(wxDC &dc,
CoordType from, to, tempto; CoordType from, to, tempto;
int highlight = llist->IsSelected(this, &from, &to); int highlight = llist->IsSelected(this, &from, &to);
if(highlight == 1) // we need to draw the whole line inverted! if(highlight == 1) // we need to draw the whole line inverted!
StartHighlighting(dc); llist->StartHighlighting(dc);
else else
EndHighlighting(dc); llist->EndHighlighting(dc);
for(i = m_ObjectList.begin(); i != NULLIT; i++) for(i = m_ObjectList.begin(); i != NULLIT; i++)
{ {
@ -697,18 +682,23 @@ wxLayoutLine::Draw(wxDC &dc,
{ {
// parts of the line need highlighting // parts of the line need highlighting
tempto = xpos+(**i).GetLength(); tempto = xpos+(**i).GetLength();
if(tempto >= from && tempto <= to) if(tempto >= from && xpos <= to)
{ {
tempto = to-xpos; tempto = to-xpos;
if(tempto > (**i).GetLength()) if(tempto > (**i).GetLength())
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 else
EndHighlighting(dc); {
llist->EndHighlighting(dc); // FIXME! inefficient
(**i).Draw(dc, pos, llist);
}
} }
else else
(**i).Draw(dc, pos); (**i).Draw(dc, pos, llist);
pos.x += (**i).GetWidth(); pos.x += (**i).GetWidth();
xpos += (**i).GetLength(); xpos += (**i).GetLength();
} }
@ -1418,7 +1408,7 @@ wxLayoutList::Draw(wxDC &dc,
wxLayoutLine *line = m_FirstLine; wxLayoutLine *line = m_FirstLine;
Layout(dc, bottom); Layout(dc, bottom);
m_DefaultSetting->Draw(dc, wxPoint(0,0)); m_DefaultSetting->Draw(dc, wxPoint(0,0), this);
wxBrush brush(m_ColourBG, wxSOLID); wxBrush brush(m_ColourBG, wxSOLID);
dc.SetBrush(brush); dc.SetBrush(brush);
@ -1436,6 +1426,11 @@ wxLayoutList::Draw(wxDC &dc,
m_CursorLine->GetNextLine() == NULL && m_CursorLine->GetNextLine() == NULL &&
m_CursorLine == m_FirstLine)); m_CursorLine == m_FirstLine));
InvalidateUpdateRect(); 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 * wxLayoutObject *
@ -1550,13 +1545,12 @@ wxLayoutList::StartSelection(void)
} }
void 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_CursorB = m_CursorPos;
m_Selection.m_selecting = false;
m_Selection.m_valid = true;
// We always want m_CursorA <= m_CursorB! // We always want m_CursorA <= m_CursorB!
if(! (m_Selection.m_CursorA <= m_Selection.m_CursorB)) if(! (m_Selection.m_CursorA <= m_Selection.m_CursorB))
{ {
@ -1566,6 +1560,16 @@ wxLayoutList::EndSelection(void)
} }
} }
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 bool
wxLayoutList::IsSelecting(void) wxLayoutList::IsSelecting(void)
{ {
@ -1575,6 +1579,8 @@ wxLayoutList::IsSelecting(void)
bool bool
wxLayoutList::IsSelected(const wxPoint &cursor) wxLayoutList::IsSelected(const wxPoint &cursor)
{ {
if(! m_Selection.m_valid && ! m_Selection.m_selecting)
return false;
return m_Selection.m_CursorA <= cursor return m_Selection.m_CursorA <= cursor
&& cursor <= m_Selection.m_CursorB; && cursor <= m_Selection.m_CursorB;
} }
@ -1592,6 +1598,9 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
{ {
wxASSERT(line); wxASSERT(to); wxASSERT(from); wxASSERT(line); wxASSERT(to); wxASSERT(from);
if(! m_Selection.m_valid && ! m_Selection.m_selecting)
return 0;
CoordType y = line->GetLineNumber(); CoordType y = line->GetLineNumber();
if(m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y) if(m_Selection.m_CursorA.y < y && m_Selection.m_CursorB.y > y)
return 1; return 1;
@ -1617,6 +1626,24 @@ wxLayoutList::IsSelected(const wxLayoutLine *line, CoordType *from,
return 0; 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 #ifdef WXLAYOUT_DEBUG
void void

View File

@ -111,11 +111,13 @@ public:
/** Draws an object. /** Draws an object.
@param dc the wxDC to draw on @param dc the wxDC to draw on
@param coords where to draw the baseline of the object. @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 begin if !=-1, from which position on to highlight it
@param end if begin !=-1, how many positions to highlight it @param end if begin !=-1, how many positions to highlight it
*/ */
virtual void Draw(wxDC & /* dc */, virtual void Draw(wxDC & /* dc */,
wxPoint const & /* coords */, wxPoint const & /* coords */,
class wxLayoutList *wxllist,
CoordType begin = -1, CoordType begin = -1,
CoordType end = -1) { } CoordType end = -1) { }
@ -193,6 +195,7 @@ public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; }
virtual void Layout(wxDC &dc); virtual void Layout(wxDC &dc);
virtual void Draw(wxDC &dc, wxPoint const &coords, virtual void Draw(wxDC &dc, wxPoint const &coords,
class wxLayoutList *wxllist,
CoordType begin = -1, CoordType begin = -1,
CoordType end = -1); CoordType end = -1);
/** Calculates and returns the size of the object. /** Calculates and returns the size of the object.
@ -252,6 +255,7 @@ public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; }
virtual void Layout(wxDC &dc); virtual void Layout(wxDC &dc);
virtual void Draw(wxDC &dc, wxPoint const &coords, virtual void Draw(wxDC &dc, wxPoint const &coords,
class wxLayoutList *wxllist,
CoordType begin = -1, CoordType begin = -1,
CoordType end = -1); CoordType end = -1);
@ -298,6 +302,7 @@ public:
virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; }
virtual void Layout(wxDC &dc); virtual void Layout(wxDC &dc);
virtual void Draw(wxDC &dc, wxPoint const &coords, virtual void Draw(wxDC &dc, wxPoint const &coords,
class wxLayoutList *wxllist,
CoordType begin = -1, CoordType begin = -1,
CoordType end = -1); CoordType end = -1);
wxLayoutObjectCmd(int size, int family, int style, int weight, wxLayoutObjectCmd(int size, int family, int style, int weight,
@ -825,12 +830,19 @@ public:
/// Begin selecting text. /// Begin selecting text.
void StartSelection(void); void StartSelection(void);
// Continue selecting text
void ContinueSelection(void);
/// End selecting text. /// End selecting text.
void EndSelection(void); void EndSelection(void);
/// Are we still selecting text? /// Are we still selecting text?
bool IsSelecting(void); bool IsSelecting(void);
bool IsSelected(const wxPoint &cursor); 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 /** Tests whether this layout line is selected and needs
highlighting. highlighting.
@param line to test for @param line to test for

View File

@ -158,12 +158,13 @@ wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list,
m_fromPos = fromPos; m_fromPos = fromPos;
m_toPos = toPos; m_toPos = toPos;
if(m_fromPos != wxLayoutExportNoPosition) if(m_fromPos.x != -1)
{ {
while(m_line && (*m_line)->GetLineNumber() != m_fromPos.y) while(m_line && m_line->GetLineNumber() != m_fromPos.y)
m_line->GetNextLine(); m_line = m_line->GetNextLine();
wxASSERT(m_line); wxASSERT(m_line);
m_iterator = (**i).FindObject(fromPos.x); CoordType dummy;
m_iterator = m_line->FindObject(fromPos.x, &dummy);
} }
} }

View File

@ -207,21 +207,55 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
} }
#endif #endif
long keyCode = event.KeyCode();
if(m_Selecting && ! event.ShiftDown())
{
m_llist->EndSelection();
m_Selecting = false;
}
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(!IsEditable()) // do nothing
{ {
event.Skip(); 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; return;
} }
long keyCode = event.KeyCode();
if(event.ShiftDown())
m_Selecting = true;
else
{
if(m_Selecting)
m_llist->EndSelection();
m_Selecting = false;
}
/* First, handle control keys */ /* First, handle control keys */
if(event.ControlDown() && ! event.AltDown()) if(event.ControlDown() && ! event.AltDown())
{ {
@ -271,35 +305,27 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
switch(keyCode) switch(keyCode)
{ {
case WXK_RIGHT: case WXK_RIGHT:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorHorizontally(1); m_llist->MoveCursorHorizontally(1);
break; break;
case WXK_LEFT: case WXK_LEFT:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorHorizontally(-1); m_llist->MoveCursorHorizontally(-1);
break; break;
case WXK_UP: case WXK_UP:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(-1); m_llist->MoveCursorVertically(-1);
break; break;
case WXK_DOWN: case WXK_DOWN:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(1); m_llist->MoveCursorVertically(1);
break; break;
case WXK_PRIOR: case WXK_PRIOR:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(-20); m_llist->MoveCursorVertically(-20);
break; break;
case WXK_NEXT: case WXK_NEXT:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorVertically(20); m_llist->MoveCursorVertically(20);
break; break;
case WXK_HOME: case WXK_HOME:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorToBeginOfLine(); m_llist->MoveCursorToBeginOfLine();
break; break;
case WXK_END: case WXK_END:
if(m_Selecting) m_llist->StartSelection();
m_llist->MoveCursorToEndOfLine(); m_llist->MoveCursorToEndOfLine();
break; break;
case WXK_DELETE : case WXK_DELETE :
@ -441,7 +467,6 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
// Device origins on the memDC are suspect, we translate manually // Device origins on the memDC are suspect, we translate manually
// with the translate parameter of Draw(). // with the translate parameter of Draw().
m_memDC->SetDeviceOrigin(0,0); m_memDC->SetDeviceOrigin(0,0);
m_memDC->SetBackgroundMode(wxTRANSPARENT);
m_memDC->SetBrush(wxBrush(m_llist->GetDefaults()->GetBGColour(), wxSOLID)); m_memDC->SetBrush(wxBrush(m_llist->GetDefaults()->GetBGColour(), wxSOLID));
m_memDC->SetPen(wxPen(m_llist->GetDefaults()->GetBGColour(),0,wxTRANSPARENT)); m_memDC->SetPen(wxPen(m_llist->GetDefaults()->GetBGColour(),0,wxTRANSPARENT));
m_memDC->SetLogicalFunction(wxCOPY); m_memDC->SetLogicalFunction(wxCOPY);
@ -454,10 +479,13 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
for(y = 0; y < y1; y+=h) for(y = 0; y < y1; y+=h)
for(x = 0; x < x1; x+=w) for(x = 0; x < x1; x+=w)
m_memDC->DrawBitmap(*m_BGbitmap, x, y); m_memDC->DrawBitmap(*m_BGbitmap, x, y);
m_memDC->SetBackgroundMode(wxTRANSPARENT);
} }
else else
{
m_memDC->SetBackgroundMode(wxSOLID);
m_memDC->DrawRectangle(0,0,x1, y1); m_memDC->DrawRectangle(0,0,x1, y1);
}
/* This is the important bit: we tell the list to draw itself: */ /* This is the important bit: we tell the list to draw itself: */