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. 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 wxllist::GetSize() requires extra Layout() call, which should not be
necessary. Find out why this is so. 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 - searching for text
- moving cursor in non-edit mode - moving cursor in non-edit mode
- cursor screen positioning ignores font sizes once again :-( - 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, enum ids{ ID_ADD_SAMPLE = 1, ID_CLEAR, ID_PRINT,
ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS, ID_PRINT_SETUP, ID_PAGE_SETUP, ID_PREVIEW, ID_PRINT_PS,
ID_PRINT_SETUP_PS, ID_PAGE_SETUP_PS,ID_PREVIEW_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_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT,
ID_TEST, ID_LONG_TEST }; 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_COPY, "Copy", "Copy text to clipboard.");
edit_menu->Append(ID_CUT, "Cut", "Cut 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_PASTE,"Paste", "Paste text from clipboard.");
edit_menu->Append(ID_FIND, "Find", "Find text.");
menu_bar->Append(edit_menu, "Edit" ); menu_bar->Append(edit_menu, "Edit" );
#ifndef __WXMSW__ #ifndef __WXMSW__
@@ -242,6 +243,10 @@ void MyFrame::OnCommand( wxCommandEvent &event )
m_lwin->Cut(); m_lwin->Cut();
m_lwin->Refresh(FALSE); m_lwin->Refresh(FALSE);
break; break;
case ID_FIND:
m_lwin->Find("void");
m_lwin->Refresh(FALSE);
break;
case ID_HTML: case ID_HTML:
{ {
wxLayoutExportObject *export; wxLayoutExportObject *export;

View File

@@ -439,9 +439,13 @@ wxLayoutLine::~wxLayoutLine()
wxPoint wxPoint
wxLayoutLine::RecalculatePosition(wxLayoutList *llist) wxLayoutLine::RecalculatePosition(wxLayoutList *llist)
{ {
wxASSERT(m_Previous || GetLineNumber() == 0);
if(m_Previous) 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 else
m_Position = wxPoint(0,0); m_Position = wxPoint(0,0);
llist->SetUpdateRect(m_Position); llist->SetUpdateRect(m_Position);
@@ -513,7 +517,7 @@ wxLayoutLine::FindObjectScreen(wxDC &dc,
if( x <= xpos && xpos <= x + width ) if( x <= xpos && xpos <= x + width )
{ {
*cxpos = cx + (**i).GetOffsetScreen(dc, xpos-x); *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; if(found) *found = true;
return i; return i;
} }
@@ -526,6 +530,38 @@ wxLayoutLine::FindObjectScreen(wxDC &dc,
return m_ObjectList.tail(); 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 bool
wxLayoutLine::Insert(CoordType xpos, wxLayoutObject *obj) wxLayoutLine::Insert(CoordType xpos, wxLayoutObject *obj)
{ {
@@ -730,7 +766,7 @@ 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);
WXLO_DEBUG(("highlight=%d", highlight )); // WXLO_DEBUG(("highlight=%d", highlight ));
if(highlight == 1) // we need to draw the whole line inverted! if(highlight == 1) // we need to draw the whole line inverted!
llist->StartHighlighting(dc); llist->StartHighlighting(dc);
else else
@@ -1033,6 +1069,9 @@ wxLayoutLine::Debug(void)
(long int) GetLineNumber(), (long int) GetLineNumber(),
(long int) pos.x, (long int) pos.y, (long int) pos.x, (long int) pos.y,
(long int) GetHeight())); (long int) GetHeight()));
if(m_ObjectList.begin() != NULLIT)
(**m_ObjectList.begin()).Debug();
} }
#endif #endif
@@ -1200,6 +1239,27 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
wxLayoutStyleInfo(family,size,style,weight,underline,fg,bg); 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 bool
@@ -1440,6 +1500,7 @@ wxLayoutList::DeleteLines(int n)
{ // we cannot delete this line, but we can clear it { // we cannot delete this line, but we can clear it
MoveCursorToBeginOfLine(); MoveCursorToBeginOfLine();
DeleteToEndOfLine(); DeleteToEndOfLine();
m_CursorLine->RecalculatePositions(2, this);
return n-1; return n-1;
} }
//else: //else:
@@ -1606,6 +1667,7 @@ wxLayoutList::GetSize(void) const
return maxPoint; return maxPoint;
} }
void void
wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate) wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate)
{ {

View File

@@ -451,6 +451,13 @@ public:
CoordType *offset, CoordType *offset,
bool *found = NULL) const ; 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 /** Get the first object in the list. This is used by the wxlparser
functions to export the list. functions to export the list.
@return iterator to the first object @return iterator to the first object
@@ -512,6 +519,7 @@ public:
*/ */
wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool
*found = NULL); *found = NULL);
//@} //@}
/**@name List traversal */ /**@name List traversal */
@@ -669,6 +677,8 @@ public:
/// Returns current cursor position. /// Returns current cursor position.
wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; } wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
wxPoint GetCursorPos() const { return m_CursorPos; }
//@} //@}
/**@name Editing functions. /**@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 */ /**@name Formatting options */
//@{ //@{
/// sets font parameters /// sets font parameters

View File

@@ -403,6 +403,8 @@ wxLayoutWindow::ScrollToCursor(void)
GetScrollPixelsPerUnit(&dx, &dy); GetScrollPixelsPerUnit(&dx, &dy);
x0 *= dx; y0 *= dy; x0 *= dx; y0 *= dy;
WXLO_DEBUG(("ScrollToCursor: ViewStart is %d/%d", x0, y0));
// Get the size of the visible window: // Get the size of the visible window:
GetClientSize(&x1,&y1); GetClientSize(&x1,&y1);
wxASSERT(x1 > 0); wxASSERT(x1 > 0);
@@ -474,7 +476,7 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect)
if(IsDirty()) if(IsDirty())
{ {
//FIXME m_llist->Layout(dc); m_llist->Layout(dc);
ResizeScrollbars(); ResizeScrollbars();
} }
/* Check whether the window has grown, if so, we need to reallocate /* Check whether the window has grown, if so, we need to reallocate
@@ -577,6 +579,8 @@ wxLayoutWindow::ResizeScrollbars(bool exact)
{ {
wxPoint max = m_llist->GetSize(); 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 if(max.x > m_maxx || max.y > m_maxy
|| max.x > m_maxx-WXLO_ROFFSET || max.y > m_maxy-WXLO_BOFFSET || max.x > m_maxx-WXLO_ROFFSET || max.y > m_maxy-WXLO_BOFFSET
|| exact) || exact)
@@ -678,6 +682,29 @@ wxLayoutWindow::Cut(void)
else else
return FALSE; 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 * wxMenu *
wxLayoutWindow::MakeFormatMenu() wxLayoutWindow::MakeFormatMenu()

View File

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