without modifying them.
*/
-static int _mpch_dummy = 0;
+// static int _mpch_dummy = 0;
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 :-(
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 };
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__
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;
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);
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;
}
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)
{
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
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
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
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;
}
}
{ // we cannot delete this line, but we can clear it
MoveCursorToBeginOfLine();
DeleteToEndOfLine();
+ m_CursorLine->RecalculatePositions(2, this);
return n-1;
}
//else:
return maxPoint;
}
+
void
wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate)
{
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
*/
wxLayoutObject * FindObjectScreen(wxDC &dc, CoordType xpos, bool
*found = NULL);
+
//@}
/**@name List traversal */
/// Returns current cursor position.
wxPoint GetCursorPos(wxDC &dc) const { return m_CursorPos; }
+ wxPoint GetCursorPos() const { return m_CursorPos; }
+
//@}
/**@name Editing functions.
//@}
+ /** 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
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);
if(IsDirty())
{
-//FIXME m_llist->Layout(dc);
+ m_llist->Layout(dc);
ResizeScrollbars();
}
/* Check whether the window has grown, if so, we need to reallocate
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)
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()
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; }