]> git.saurik.com Git - wxWidgets.git/commitdiff
Added finding of text in the list and fixed calculation of scrollbar
authorKarsten Ballüder <ballueder@usa.net>
Thu, 13 May 1999 10:14:30 +0000 (10:14 +0000)
committerKarsten Ballüder <ballueder@usa.net>
Thu, 13 May 1999 10:14:30 +0000 (10:14 +0000)
size.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2441 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

user/wxLayout/Mpch.h
user/wxLayout/TODO
user/wxLayout/wxLayout.cpp
user/wxLayout/wxllist.cpp
user/wxLayout/wxllist.h
user/wxLayout/wxlwindow.cpp
user/wxLayout/wxlwindow.h

index c3af53687d05449d9932c0f70f499b35ff56219a..863f2eb9b5803e171d754df947dd0be42dc558ab 100644 (file)
@@ -4,5 +4,5 @@
   without modifying them.
 */
 
-static int _mpch_dummy = 0;
+// static int _mpch_dummy = 0;
 
index f19ba13770a04a1c6221b575e3fa491ab40eccd5..e7c4ec319913fd84589f09e5127560ad4ed4a5cd 100644 (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 :-(
index 7a0e4e3436adfa7426f526f42a7fd8e68c55770e..ae08a6ce9b83d28659edf7de400093bf0dad3c62 100644 (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;
index 4f9db2af9e4b3229a26e364983d55b8bc76cb0b4..142c2b8d2de073178ceb1abfbcd5232eef702f1b 100644 (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)
 {
index b181235238b57884fa7c8b215ca35bbeef101e53..72324a6ec0179fa0df2f361724677a9a1e939531 100644 (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
index 5d36dfa9a314b588c9235c89c71e962053bca83b..a59a472002a5f49d586b19ab20f0db015169c8cb 100644 (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()
index 8efd166fce8df9ac78a711f45100c27591186e66..00b50ed3a7071b45b640137e97eada6ee580db30 100644 (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; }