Added finding of text in the list and fixed calculation of scrollbar

size.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2441 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder 1999-05-13 10:14:30 +00:00
parent b0e813a0c1
commit 0c34becbea
7 changed files with 134 additions and 14 deletions

View File

@ -4,5 +4,5 @@
without modifying them.
*/
static int _mpch_dummy = 0;
// static int _mpch_dummy = 0;

View File

@ -23,10 +23,17 @@ Selections:
wxllist::GetSize() requires extra Layout() call, which should not be
necessary. Find out why this is so.
YES, it is necessary, because the normal drawing only happens within
the visible window.
I must find a way to re-Layout() objects. This is only required after
their sizes change:
- Just mark them as dirty:
- mark current line as dirty when editing it (so width gets recalculated)
- mark all following lines as dirty when changing font settings
- Let Layout() work only on the dirty lines.
!!! GOOD: this can also be used to recalculate the wxLayoutObjectCmds'
fonts! :-)
- Image at end of a message doesn't get considered properly in
wxLayoutList::GetSize(), so it cannot be seen
- searching for text
- moving cursor in non-edit mode
- cursor screen positioning ignores font sizes once again :-(

View File

@ -36,7 +36,7 @@ IMPLEMENT_APP(MyApp)
enum ids{ ID_ADD_SAMPLE = 1, ID_CLEAR, ID_PRINT,
ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS,
ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_PS,
ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, ID_CUT,
ID_WRAP, ID_NOWRAP, ID_PASTE, ID_COPY, ID_CUT, ID_FIND,
ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT,
ID_TEST, ID_LONG_TEST };
@ -96,6 +96,7 @@ MyFrame::MyFrame(void) :
edit_menu->Append(ID_COPY, "Copy", "Copy text to clipboard.");
edit_menu->Append(ID_CUT, "Cut", "Cut text to clipboard.");
edit_menu->Append(ID_PASTE,"Paste", "Paste text from clipboard.");
edit_menu->Append(ID_FIND, "Find", "Find text.");
menu_bar->Append(edit_menu, "Edit" );
#ifndef __WXMSW__
@ -242,6 +243,10 @@ void MyFrame::OnCommand( wxCommandEvent &event )
m_lwin->Cut();
m_lwin->Refresh(FALSE);
break;
case ID_FIND:
m_lwin->Find("void");
m_lwin->Refresh(FALSE);
break;
case ID_HTML:
{
wxLayoutExportObject *export;

View File

@ -439,9 +439,13 @@ wxLayoutLine::~wxLayoutLine()
wxPoint
wxLayoutLine::RecalculatePosition(wxLayoutList *llist)
{
wxASSERT(m_Previous || GetLineNumber() == 0);
if(m_Previous)
m_Position = m_Previous->GetPosition() +
wxPoint(0,m_Previous->GetHeight());
{
m_Position = m_Previous->GetPosition();
m_Position.y += m_Previous->GetHeight();
}
else
m_Position = wxPoint(0,0);
llist->SetUpdateRect(m_Position);
@ -513,7 +517,7 @@ wxLayoutLine::FindObjectScreen(wxDC &dc,
if( x <= xpos && xpos <= x + width )
{
*cxpos = cx + (**i).GetOffsetScreen(dc, xpos-x);
WXLO_DEBUG(("wxLayoutLine::FindObjectScreen: cursor xpos = %ld", *cxpos));
// WXLO_DEBUG(("wxLayoutLine::FindObjectScreen: cursor xpos = %ld", *cxpos));
if(found) *found = true;
return i;
}
@ -526,6 +530,38 @@ wxLayoutLine::FindObjectScreen(wxDC &dc,
return m_ObjectList.tail();
}
/** Finds text in this line.
@param needle the text to find
@param xpos the position where to start the search
@return the cursoor coord where it was found or -1
*/
CoordType
wxLayoutLine::FindText(const wxString &needle, CoordType xpos = 0) const
{
int
cpos = 0,
relpos = -1;
wxString const *text;
for(wxLOiterator i = m_ObjectList.begin(); i != m_ObjectList.end(); i++)
{
if(cpos >= xpos) // search from here!
{
if((**i).GetType() == WXLO_TYPE_TEXT)
{
text = & ((wxLayoutObjectText*)(*i))->GetText();
relpos = text->Find(needle);
if(relpos >= cpos-xpos) // -1 if not found
{
return xpos+relpos;
}
}
cpos += (**i).GetLength();
}
}
return -1; // not found
}
bool
wxLayoutLine::Insert(CoordType xpos, wxLayoutObject *obj)
{
@ -730,7 +766,7 @@ wxLayoutLine::Draw(wxDC &dc,
CoordType from, to, tempto;
int highlight = llist->IsSelected(this, &from, &to);
WXLO_DEBUG(("highlight=%d", highlight ));
// WXLO_DEBUG(("highlight=%d", highlight ));
if(highlight == 1) // we need to draw the whole line inverted!
llist->StartHighlighting(dc);
else
@ -1032,7 +1068,10 @@ wxLayoutLine::Debug(void)
WXLO_DEBUG(("Line %ld, Pos (%ld,%ld), Height %ld",
(long int) GetLineNumber(),
(long int) pos.x, (long int) pos.y,
(long int) GetHeight()));
(long int) GetHeight()));
if(m_ObjectList.begin() != NULLIT)
(**m_ObjectList.begin()).Debug();
}
#endif
@ -1200,6 +1239,27 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
wxLayoutStyleInfo(family,size,style,weight,underline,fg,bg);
}
wxPoint
wxLayoutList::FindText(const wxString &needle, const wxPoint &cpos) const
{
int xpos;
wxLayoutLine *line;
for(line = m_FirstLine;
line;
line = line->GetNextLine())
{
if(line->GetLineNumber() >= cpos.y)
{
xpos = line->FindText(needle,
(line->GetLineNumber() == cpos.y) ?
cpos.x : 0);
if(xpos != -1)
return wxPoint(xpos, line->GetLineNumber());
}
}
return wxPoint(-1,-1);
}
bool
@ -1381,7 +1441,7 @@ wxLayoutList::WrapLine(CoordType column)
LineBreak();
Delete(1); // delete the space
m_CursorPos.x = newpos;
m_CursorLine->RecalculatePositions(true, this); //FIXME needed?
m_CursorLine->RecalculatePositions(true, this); //FIXME needed?
return true;
}
}
@ -1440,6 +1500,7 @@ wxLayoutList::DeleteLines(int n)
{ // we cannot delete this line, but we can clear it
MoveCursorToBeginOfLine();
DeleteToEndOfLine();
m_CursorLine->RecalculatePositions(2, this);
return n-1;
}
//else:
@ -1606,6 +1667,7 @@ wxLayoutList::GetSize(void) const
return maxPoint;
}
void
wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate)
{

View File

@ -451,6 +451,13 @@ public:
CoordType *offset,
bool *found = NULL) const ;
/** Finds text in this line.
@param needle the text to find
@param xpos the position where to start the search
@return the cursoor coord where it was found or -1
*/
CoordType FindText(const wxString &needle, CoordType xpos = 0) const;
/** Get the first object in the list. This is used by the wxlparser
functions to export the list.
@return iterator to the first object
@ -512,6 +519,7 @@ public:
*/
wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool
*found = NULL);
//@}
/**@name List traversal */
@ -669,6 +677,8 @@ public:
/// Returns current cursor position.
wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
wxPoint GetCursorPos() const { return m_CursorPos; }
//@}
/**@name Editing functions.
@ -729,6 +739,13 @@ public:
//@}
/** Finds text in this list.
@param needle the text to find
@param cpos the position where to start the search
@return the cursoor coord where it was found or (-1,-1)
*/
wxPoint FindText(const wxString &needle, const wxPoint &cpos = wxPoint(0,0)) const;
/**@name Formatting options */
//@{
/// sets font parameters

View File

@ -403,6 +403,8 @@ wxLayoutWindow::ScrollToCursor(void)
GetScrollPixelsPerUnit(&dx, &dy);
x0 *= dx; y0 *= dy;
WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0, y0));
// Get the size of the visible window:
GetClientSize(&x1,&y1);
wxASSERT(x1 > 0);
@ -474,7 +476,7 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
if(IsDirty())
{
//FIXME m_llist->Layout(dc);
m_llist->Layout(dc);
ResizeScrollbars();
}
/* Check whether the window has grown, if so, we need to reallocate
@ -576,7 +578,9 @@ void
wxLayoutWindow::ResizeScrollbars(bool exact)
{
wxPoint max = m_llist->GetSize();
WXLO_DEBUG(("ResizeScrollbars: GetSize: %ld, %ld", (long int)max.x,
(long int) max.y));
if(max.x > m_maxx || max.y > m_maxy
|| max.x > m_maxx-WXLO_ROFFSET || max.y > m_maxy-WXLO_BOFFSET
|| exact)
@ -678,6 +682,29 @@ wxLayoutWindow::Cut(void)
else
return FALSE;
}
bool
wxLayoutWindow::Find(const wxString &needle,
wxPoint * fromWhere)
{
wxPoint found;
if(fromWhere == NULL)
found = m_llist->FindText(needle, m_llist->GetCursorPos());
else
found = m_llist->FindText(needle, *fromWhere);
if(found.x != -1)
{
if(fromWhere)
{
*fromWhere = found;
fromWhere->x ++;
}
m_llist->MoveCursorTo(found);
ScrollToCursor();
return true;
}
return false;
}
wxMenu *
wxLayoutWindow::MakeFormatMenu()

View File

@ -84,8 +84,10 @@ public:
bool Copy(void);
/// Copies selection to clipboard and deletes it.
bool Cut(void);
//@}
bool Find(const wxString &needle,
wxPoint * fromWhere = NULL);
void EnablePopup(bool enable = true) { m_DoPopupMenu = enable; }