From: Vadim Zeitlin Date: Wed, 2 Jun 1999 21:26:11 +0000 (+0000) Subject: First part of fixes to make this work under MSW. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5bdc3b1d4a6585edbe4416e5f7dfb02b6ab771af First part of fixes to make this work under MSW. 1. letters actually appear on the screen 2. Clear() works 3. Backspace/Delete in one line works too 4. breaking lines works 5. cursor is now a wxCaret 6. tons of other fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2652 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/user/wxLayout/wxLayout.cpp b/user/wxLayout/wxLayout.cpp index b7df97f28a..41431fbe24 100644 --- a/user/wxLayout/wxLayout.cpp +++ b/user/wxLayout/wxLayout.cpp @@ -1,6 +1,6 @@ /* * Program: wxLayout - * + * * Author: Karsten Ballüder * * Copyright: (C) 1998, Karsten Ballüder @@ -61,12 +61,12 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame ) MyFrame::MyFrame(void) : wxFrame( (wxFrame *) NULL, -1, (char *) "wxLayout", wxPoint(20,20), wxSize(600,360) ) { - CreateStatusBar( 1 ); - + CreateStatusBar( 2 ); + SetStatusText( "wxLayout by Karsten Ballüder." ); wxMenuBar *menu_bar = new wxMenuBar(); - + wxMenu *file_menu = new wxMenu; file_menu->Append(ID_PRINT, "&Print...", "Print"); file_menu->Append(ID_PRINT_SETUP, "Print &Setup...","Setup printer properties"); @@ -102,10 +102,11 @@ MyFrame::MyFrame(void) : #ifndef __WXMSW__ menu_bar->Show( TRUE ); #endif // MSW - + SetMenuBar( menu_bar ); m_lwin = new wxLayoutWindow(this); + m_lwin->SetStatusBar(GetStatusBar(), 0, 1); m_lwin->SetMouseTracking(true); m_lwin->SetEditable(true); m_lwin->SetWrapMargin(40); @@ -122,11 +123,11 @@ MyFrame::AddSampleText(wxLayoutList *llist) llist->SetFont(-1,-1,-1,-1,-1,"black"); llist->Insert("The quick brown fox jumps over the lazy dog."); llist->LineBreak(); - + llist->SetFont(wxROMAN,16,wxNORMAL,wxNORMAL, false); llist->Insert("--"); llist->LineBreak(); - + llist->SetFont(wxROMAN); llist->Insert("The quick brown fox jumps over the lazy dog."); llist->LineBreak(); @@ -218,7 +219,7 @@ void MyFrame::OnCommand( wxCommandEvent &event ) wxPrinter printer; wxLayoutPrintout printout(m_lwin->GetLayoutList(),_("M: Printout")); if (! printer.Print(this, &printout, TRUE)) - wxMessageBox( + wxMessageBox( _("There was a problem with printing the message:\n" "perhaps your current printer is not set up correctly?"), _("Printing"), wxOK); @@ -314,7 +315,7 @@ void MyFrame::OnPrint(wxCommandEvent& WXUNUSED(event)) if (! printer.Print(this, &printout, TRUE)) wxMessageBox( "There was a problem printing.\nPerhaps your current printer is not set correctly?", - "Printing", wxOK); + "Printing", wxOK); } void MyFrame::OnPrintPS(wxCommandEvent& WXUNUSED(event)) @@ -340,14 +341,14 @@ void MyFrame::OnPrintPreview(wxCommandEvent& WXUNUSED(event)) // Pass two printout objects: for preview, and possible printing. wxPrintPreview *preview = new wxPrintPreview(new wxLayoutPrintout( - m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData); + m_lwin->GetLayoutList()), new wxLayoutPrintout( m_lwin->GetLayoutList()), & printData); if (!preview->Ok()) { delete preview; wxMessageBox("There was a problem previewing.\nPerhaps your current printer is not set correctly?", "Previewing", wxOK); return; } - + wxPreviewFrame *frame = new wxPreviewFrame(preview, this, "Demo Print Preview", wxPoint(100, 100), wxSize(600, 650)); frame->Centre(wxBOTH); frame->Initialize(); @@ -430,7 +431,7 @@ void MyFrame::OnPageSetupPS(wxCommandEvent& WXUNUSED(event)) // MyApp //----------------------------------------------------------------------------- -MyApp::MyApp(void) : +MyApp::MyApp(void) : wxApp( ) { }; diff --git a/user/wxLayout/wxllist.cpp b/user/wxLayout/wxllist.cpp index caf366bcb2..906aead71a 100644 --- a/user/wxLayout/wxllist.cpp +++ b/user/wxLayout/wxllist.cpp @@ -7,21 +7,21 @@ *******************************************************************/ /* - + */ - + #ifdef __GNUG__ -#pragma implementation "wxllist.h" + #pragma implementation "wxllist.h" #endif -#include "Mpch.h" +#include - -#include "wx/wxprec.h" #ifdef __BORLANDC__ # pragma hdrstop #endif +#include "Mpch.h" + #ifdef M_BASEDIR # include "gui/wxllist.h" # include "gui/wxlparser.h" @@ -33,14 +33,19 @@ #endif #ifndef USE_PCH -# include "iostream.h" -# include -# include -# include -# include -# include +# include + +# include +# include +# include +# include +# include #endif +#ifdef WXLAYOUT_USE_CARET +# include +#endif // WXLAYOUT_USE_CARET + #include /// This should never really get created @@ -48,23 +53,32 @@ #ifdef WXLAYOUT_DEBUG -# define TypewxString(t) g_aTypewxStrings[t] +# define TypeString(t) g_aTypeStrings[t] # define WXLO_DEBUG(x) wxLogDebug x - static const char *g_aTypewxStrings[] = - { + static const char *g_aTypeStrings[] = + { "invalid", "text", "cmd", "icon" }; void wxLayoutObject::Debug(void) { - WXLO_DEBUG(("%s",g_aTypewxStrings[GetType()])); + WXLO_DEBUG(("%s",g_aTypeStrings[GetType()])); } -#else -# define TypewxString(t) "" -# define WXLO_DEBUG(x) +#else +# define TypeString(t) "" +# define WXLO_DEBUG(x) #endif +// FIXME under MSW, this constant is needed to make the thing properly redraw +// itself - I don't know where the size calculation error is and I can't +// waste time looking for it right now. Search for occurences of +// MSW_CORRECTION to find all the places where I did it. +#ifdef __WXMSW__ + static const int MSW_CORRECTION = 10; +#else + static const int MSW_CORRECTION = 0; +#endif /// Cursors smaller than this disappear in XOR drawing mode #define WXLO_MINIMUM_CURSOR_WIDTH 4 @@ -73,18 +87,6 @@ #define WXLO_CURSORCHAR "E" /** @name Helper functions */ //@{ -/// allows me to compare to wxPoints -bool operator ==(wxPoint const &p1, wxPoint const &p2) -{ - return p1.x == p2.x && p1.y == p2.y; -} - -/// allows me to compare to wxPoints -bool operator !=(wxPoint const &p1, wxPoint const &p2) -{ - return p1.x != p2.x || p1.y != p2.y; -} - /// allows me to compare to wxPoints bool operator <=(wxPoint const &p1, wxPoint const &p2) { @@ -100,7 +102,7 @@ void GrowRect(wxRect &r, CoordType x, CoordType y) r.x = x; else if(r.x + r.width < x) r.width = x - r.x; - + if(r.y > y) r.y = y; else if(r.y + r.height < y) @@ -131,7 +133,7 @@ void ReadString(wxString &to, wxString &from) from = cptr; } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutObject @@ -145,7 +147,7 @@ wxLayoutObject::Read(wxString &istr) ReadString(tmp, istr); int type = -1; sscanf(tmp.c_str(),"%d", &type); - + switch(type) { case WXLO_TYPE_TEXT: @@ -159,7 +161,7 @@ wxLayoutObject::Read(wxString &istr) } } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutObjectText @@ -190,7 +192,7 @@ wxLayoutObjectText::Copy(void) void wxLayoutObjectText::Write(wxString &ostr) { - ostr << (int) WXLO_TYPE_TEXT << '\n' + ostr << (int) WXLO_TYPE_TEXT << '\n' << m_Text << '\n'; } /* static */ @@ -199,7 +201,7 @@ wxLayoutObjectText::Read(wxString &istr) { wxString text; ReadString(text, istr); - + return new wxLayoutObjectText(text); } @@ -230,7 +232,7 @@ wxLayoutObjectText::Draw(wxDC &dc, wxPoint const &coords, if(begin < 0) begin = 0; if( end > (signed)m_Text.Length() ) end = m_Text.Length(); - + str = m_Text.Mid(0, begin); dc.DrawText(str, xpos, ypos); dc.GetTextExtent(str, &width, &height, &descent); @@ -257,26 +259,50 @@ wxLayoutObjectText::GetOffsetScreen(wxDC &dc, CoordType xpos) const height, descent = 0l; if(xpos == 0) return 0; // easy - + while(width < xpos && offs < maxlen) { dc.GetTextExtent(m_Text.substr(0,offs), &width, &height, &descent); offs++; } - /* We have to substract 1 to compensate for the offs++, and another + /* We have to substract 1 to compensate for the offs++, and another one because we don't want to position the cursor behind the object what we clicked on, but before - otherwise it looks funny. */ - return (xpos > 2) ? offs-2 : 0; + return (xpos > 2) ? offs-2 : 0; } void -wxLayoutObjectText::Layout(wxDC &dc, class wxLayoutList * ) +wxLayoutObjectText::Layout(wxDC &dc, class wxLayoutList *llist) { long descent = 0l; - dc.GetTextExtent(m_Text,&m_Width, &m_Height, &descent); + CoordType widthOld = m_Width, + heightOld = m_Height; + dc.GetTextExtent(m_Text, &m_Width, &m_Height, &descent); + + if ( widthOld != m_Width || heightOld != m_Height ) + { + // as the text length changed, it must be refreshed + wxLayoutLine *line = GetLine(); + + wxCHECK_RET( line, "wxLayoutObjectText can't refresh itself" ); + + // as our size changed, we need to repaint the part which was appended + wxPoint position(line->GetPosition()); + + // this is not the most efficient way (we repaint the whole line), but + // it's not too slow and is *simple* + if ( widthOld < m_Width ) + widthOld = m_Width; + if ( heightOld < m_Height ) + heightOld = m_Height; + + llist->SetUpdateRect(position.x + widthOld + MSW_CORRECTION, + position.y + heightOld + MSW_CORRECTION); + } + m_Bottom = descent; m_Top = m_Height - m_Bottom; } @@ -291,7 +317,7 @@ wxLayoutObjectText::Debug(void) } #endif -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutObjectIcon @@ -320,11 +346,11 @@ wxLayoutObjectIcon::Read(wxString &istr) { wxString file; ReadString(file, istr); - + if(! wxFileExists(file)) return NULL; wxLayoutObjectIcon *obj = new wxLayoutObjectIcon; - + if(!obj->m_Icon->LoadFile(file, WXLO_BITMAP_FORMAT)) { delete obj; @@ -372,7 +398,7 @@ wxLayoutObjectIcon::GetSize(CoordType *top, CoordType *bottom) const -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutObjectCmd @@ -389,7 +415,7 @@ wxLayoutStyleInfo::wxLayoutStyleInfo(int ifamily, { family = ifamily; size = isize; style = istyle; weight = iweight; - underline = iul; + underline = iul != 0; if(fg) { m_fg = *fg; @@ -424,7 +450,7 @@ wxLayoutStyleInfo::operator=(const wxLayoutStyleInfo &right) wxLayoutObjectCmd::wxLayoutObjectCmd(int family, int size, int style, int weight, int underline, wxColour *fg, wxColour *bg) - + { m_StyleInfo = new wxLayoutStyleInfo(family, size,style,weight,underline,fg,bg); } @@ -545,7 +571,7 @@ wxLayoutObjectCmd::Layout(wxDC &dc, class wxLayoutList * llist) } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * The wxLayoutLine object @@ -602,11 +628,11 @@ wxLayoutLine::RecalculatePositions(int recurse, wxLayoutList *llist) // Recursing here, drives computation time up exponentially, as // each line will cause all following lines to be recalculated. // Yes, or linenumbers go wrong. - + wxASSERT(recurse >= 0); wxPoint pos = m_Position; CoordType height = m_Height; - + // WXLO_TRACE("RecalculatePositions()"); RecalculatePosition(llist); if(m_Next) @@ -614,7 +640,7 @@ wxLayoutLine::RecalculatePositions(int recurse, wxLayoutList *llist) if(recurse > 0) m_Next->RecalculatePositions(--recurse, llist); else if(pos != m_Position || m_Height != height) - m_Next->RecalculatePositions(0, llist); + m_Next->RecalculatePositions(0, llist); } } @@ -627,7 +653,7 @@ wxLayoutLine::FindObject(CoordType xpos, CoordType *offset) const i, found = NULLIT; CoordType x = 0, len; - + /* We search through the objects. As we don't like returning the object that the cursor is behind, we just remember such an object in "found" so we can return it if there is really no @@ -657,7 +683,7 @@ wxLayoutLine::FindObjectScreen(wxDC &dc, wxASSERT(cxpos); wxLayoutObjectList::iterator i; CoordType x = 0, cx = 0, width; - + for(i = m_ObjectList.begin(); i != NULLIT; i++) { width = (**i).GetWidth(); @@ -688,7 +714,7 @@ wxLayoutLine::FindText(const wxString &needle, CoordType xpos) const cpos = 0, relpos = -1; wxString const *text; - + for(wxLOiterator i = m_ObjectList.begin(); i != m_ObjectList.end(); i++) { if(cpos >= xpos) // search from here! @@ -713,6 +739,10 @@ wxLayoutLine::Insert(CoordType xpos, wxLayoutObject *obj) { wxASSERT(xpos >= 0); wxASSERT(obj != NULL); + + // in any case, the object is going to belong to this line + obj->AttachToLine(this); + //FIXME: this could be optimised, for now be prudent: m_Dirty = true; CoordType offset; @@ -764,7 +794,7 @@ wxLayoutLine::Insert(CoordType xpos, wxLayoutObject *obj) m_ObjectList.insert(i,new wxLayoutObjectText(left)); return true; } - + bool wxLayoutLine::Insert(CoordType xpos, wxString text) { @@ -824,7 +854,7 @@ wxLayoutLine::Delete(CoordType xpos, CoordType npos) { if(xpos == GetLength()) return npos; - else + else { // at the end of an object // move to begin of next object: i++; offset = 0; @@ -839,6 +869,7 @@ wxLayoutLine::Delete(CoordType xpos, CoordType npos) ((wxLayoutObjectText *)(*i))->GetText().Remove(offset,max); } } + return npos; } @@ -857,7 +888,7 @@ wxLayoutLine::DeleteWord(CoordType xpos) if(i == NULLIT) return false; if((**i).GetType() != WXLO_TYPE_TEXT) { - // This should only happen when at end of line, behind a non-text + // This should only happen when at end of line, behind a non-text // object: if(offset == (**i).GetLength()) return false; m_Length -= (**i).GetLength(); // -1 @@ -885,7 +916,7 @@ wxLayoutLine::DeleteWord(CoordType xpos) ((wxLayoutObjectText *)*i)->GetText().erase(offset,count); m_Length -= count; return true; - } + } } wxASSERT(0); // we should never arrive here } @@ -913,7 +944,7 @@ wxLayoutLine::Draw(wxDC &dc, wxLayoutObjectList::iterator i; wxPoint pos = offset; pos = pos + GetPosition(); - + pos.y += m_BaseLine; CoordType xpos = 0; // cursorpos, lenght of line @@ -949,11 +980,12 @@ wxLayoutLine::Layout(wxDC &dc, wxLayoutList *llist, wxPoint *cursorPos, wxPoint *cursorSize, - int cx) + int cx) { wxLayoutObjectList::iterator i; CoordType + oldWidth = m_Width, oldHeight = m_Height; CoordType topHeight, bottomHeight; // above and below baseline @@ -969,7 +1001,7 @@ wxLayoutLine::Layout(wxDC &dc, bool cursorFound = false; m_Dirty = false; - + if(cursorPos) { *cursorPos = m_Position; @@ -993,7 +1025,7 @@ wxLayoutLine::Layout(wxDC &dc, { len = cx - count; // pos in object CoordType width, height, descent; - dc.GetTextExtent((*(wxLayoutObjectText*)*i).GetText().substr(0,len), + dc.GetTextExtent((*(wxLayoutObjectText*)*i).GetText().substr(0,len), &width, &height, &descent); cursorPos->x += width; cursorPos->y = m_Position.y; @@ -1011,7 +1043,7 @@ wxLayoutLine::Layout(wxDC &dc, cursorSize->y = height; cursorFound = true; // no more checks } - else + else { // on some other object CoordType top, bottom; // unused *cursorSize = (**i).GetSize(&top,&bottom); @@ -1031,8 +1063,19 @@ wxLayoutLine::Layout(wxDC &dc, if(objTopHeight > topHeight) topHeight = objTopHeight; if(objBottomHeight > bottomHeight) bottomHeight = objBottomHeight; } - if(topHeight + bottomHeight > m_Height) m_Height = - topHeight+bottomHeight; + + // special case of a line which becomes empty (after deletion, for example): + // we should invalidate the screen space it occupied (usually this happens + // from wxLayoutObject::Layout called in the loop above) + if ( m_ObjectList.empty() ) + { + wxPoint position(GetPosition()); + llist->SetUpdateRect(position.x + oldWidth + MSW_CORRECTION, + position.y + oldHeight + MSW_CORRECTION); + } + + if(topHeight + bottomHeight > m_Height) + m_Height = topHeight+bottomHeight; m_BaseLine = topHeight; if(m_Height == 0) @@ -1043,7 +1086,7 @@ wxLayoutLine::Layout(wxDC &dc, m_BaseLine = m_Height - descent; } - + // tell next line about coordinate change if(m_Next && objHeight != oldHeight) m_Next->RecalculatePositions(0, llist); @@ -1075,7 +1118,7 @@ wxLayoutLine::Break(CoordType xpos, wxLayoutList *llist) m_Dirty = true; /* If we are at the begin of a line, we want to move all other - lines down and stay with the cursor where we are. However, if we + lines down and stay with the cursor where we are. However, if we are in an empty line, we want to move down with it. */ if(xpos == 0 && GetLength() > 0) { // insert an empty line before this one @@ -1091,7 +1134,7 @@ wxLayoutLine::Break(CoordType xpos, wxLayoutList *llist) m_Next->RecalculatePositions(1, llist); return m_Previous; } - + CoordType offset; wxLOiterator i = FindObject(xpos, &offset); if(i == NULLIT) @@ -1127,7 +1170,7 @@ wxLayoutLine::Break(CoordType xpos, wxLayoutList *llist) m_Next->RecalculatePositions(2, llist); return newLine; } - + void wxLayoutLine::MergeNextLine(wxLayoutList *llist) @@ -1137,18 +1180,44 @@ wxLayoutLine::MergeNextLine(wxLayoutList *llist) wxLOiterator i; //FIXME: this could be optimised, for now be prudent: m_Dirty = true; - + + wxLayoutObject *last = NULL; for(i = list.begin(); i != list.end();) { - Append(*i); - list.remove(i); // remove without deleting it + wxLayoutObject *current = *i; + + // merge text objects together for efficiency + if ( last && last->GetType() == WXLO_TYPE_TEXT && + current->GetType() == WXLO_TYPE_TEXT ) + { + wxLayoutObjectText *textObj = (wxLayoutObjectText *)last; + wxString text(textObj->GetText()); + text += ((wxLayoutObjectText *)current)->GetText(); + textObj->SetText(text); + + list.erase(i); // remove and delete it + } + else + { + // just append the object "as was" + current->UnattachFromLine(); + Append(current); + + list.remove(i); // remove without deleting it + } } wxASSERT(list.empty()); + wxLayoutLine *oldnext = GetNextLine(); - SetNext(GetNextLine()->GetNextLine()); + wxLayoutLine *nextLine = oldnext->GetNextLine(); + SetNext(nextLine); delete oldnext; - GetNextLine()->MoveLines(-1); - RecalculatePositions(1, llist); + if ( nextLine ) + { + nextLine->MoveLines(-1); + } + + // no RecalculatePositions needed - called from Delete() anyhow } CoordType @@ -1158,7 +1227,7 @@ wxLayoutLine::GetWrapPosition(CoordType column) wxLOiterator i = FindObject(column, &offset); if(i == NULLIT) return -1; // cannot wrap - // go backwards through the list and look for space in text objects + // go backwards through the list and look for space in text objects do { if((**i).GetType() == WXLO_TYPE_TEXT) @@ -1206,7 +1275,7 @@ wxLayoutLine::GetWrapPosition(CoordType column) pos -= (**i).GetLength(); return pos; // in front of it } - + #ifdef WXLAYOUT_DEBUG void @@ -1233,7 +1302,7 @@ wxLayoutLine::Copy(wxLayoutList *llist, if(to == -1) to = GetLength(); if(from == to) return; - + wxLOiterator first = FindObject(from, &firstOffset); wxLOiterator last = FindObject(to, &lastOffset); @@ -1257,7 +1326,7 @@ wxLayoutLine::Copy(wxLayoutList *llist, } } - // If we reach here, we can safely copy the whole first object from + // If we reach here, we can safely copy the whole first object from // the firstOffset position on: if((**first).GetType() == WXLO_TYPE_TEXT && firstOffset != 0) { @@ -1268,7 +1337,7 @@ wxLayoutLine::Copy(wxLayoutList *llist, else if(firstOffset == 0) llist->Insert( (**first).Copy() ); // else nothing to copy :-( - + // Now we copy all objects before the last one: wxLOiterator i = first; i++; for( ; i != last; i++) @@ -1290,13 +1359,17 @@ wxLayoutLine::Copy(wxLayoutList *llist, /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - + The wxLayoutList object - + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ wxLayoutList::wxLayoutList() { +#ifdef WXLAYOUT_USE_CARET + m_caret = NULL; +#endif // WXLAYOUT_USE_CARET + m_FirstLine = NULL; InvalidateUpdateRect(); Clear(); @@ -1339,7 +1412,7 @@ wxLayoutList::InternalClear(void) m_DefaultSetting.m_fg = *wxBLACK; m_DefaultSetting.m_bg_valid = TRUE; m_DefaultSetting.m_bg = *wxWHITE; - + m_CurrentSetting = m_DefaultSetting; } @@ -1378,7 +1451,7 @@ wxLayoutList::SetFont(int family, int size, int style, int weight, cfg = wxTheColourDatabase->FindColour(fg); if( bg ) cbg = wxTheColourDatabase->FindColour(bg); - + SetFont(family,size,style,weight,underline,cfg,cbg); } @@ -1396,7 +1469,7 @@ wxPoint wxLayoutList::FindText(const wxString &needle, const wxPoint &cpos) const { int xpos; - + wxLayoutLine *line; for(line = m_FirstLine; line; @@ -1418,8 +1491,8 @@ wxLayoutList::FindText(const wxString &needle, const wxPoint &cpos) const bool wxLayoutList::MoveCursorTo(wxPoint const &p) { - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + AddCursorPosToUpdateRect(); + wxLayoutLine *line = m_FirstLine; while(line && line->GetLineNumber() != p.y) line = line->GetNextLine(); @@ -1441,12 +1514,12 @@ wxLayoutList::MoveCursorTo(wxPoint const &p) } return false; } - + bool wxLayoutList::MoveCursorVertically(int n) { - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + AddCursorPosToUpdateRect(); + bool rc; if(n < 0) // move up { @@ -1499,8 +1572,8 @@ wxLayoutList::MoveCursorVertically(int n) bool wxLayoutList::MoveCursorHorizontally(int n) { - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + AddCursorPosToUpdateRect(); + int move; while(n < 0) { @@ -1540,8 +1613,9 @@ bool wxLayoutList::Insert(wxString const &text) { wxASSERT(m_CursorLine); - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + + AddCursorPosToUpdateRect(); + m_CursorLine->Insert(m_CursorPos.x, text); m_CursorPos.x += text.Length(); m_CursorLine->RecalculatePositions(true, this); //FIXME needed? @@ -1552,9 +1626,12 @@ bool wxLayoutList::Insert(wxLayoutObject *obj) { wxASSERT(m_CursorLine); - if(! m_CursorLine) m_CursorLine = GetFirstLine(); - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + + if(! m_CursorLine) + m_CursorLine = GetFirstLine(); + + AddCursorPosToUpdateRect(); + m_CursorLine->Insert(m_CursorPos.x, obj); m_CursorPos.x += obj->GetLength(); m_CursorLine->RecalculatePositions(true, this); //FIXME needed? @@ -1566,7 +1643,7 @@ wxLayoutList::Insert(wxLayoutList *llist) { wxASSERT(llist); bool rc = TRUE; - + for(wxLayoutLine *line = llist->GetFirstLine(); line; line = line->GetNextLine() @@ -1581,16 +1658,19 @@ wxLayoutList::Insert(wxLayoutList *llist) return rc; } - - - bool wxLayoutList::LineBreak(void) { wxASSERT(m_CursorLine); bool setFirst = (m_CursorLine == m_FirstLine && m_CursorPos.x == 0); - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + + AddCursorPosToUpdateRect(); + + wxPoint position(m_CursorLine->GetPosition()); + + wxCoord width = m_CursorLine->GetWidth(), + height = m_CursorLine->GetHeight(); + m_CursorLine = m_CursorLine->Break(m_CursorPos.x, this); if(setFirst) // we were at beginning of first line m_FirstLine = m_CursorLine->GetPreviousLine(); @@ -1598,7 +1678,16 @@ wxLayoutList::LineBreak(void) m_CursorPos.y++; m_CursorPos.x = 0; // doesn't help m_CursorLine.MarkDirty(); - m_CursorLine->RecalculatePositions(true, this); //FIXME needed? + + wxLayoutLine *prev = m_CursorLine->GetPreviousLine(); + wxCHECK_MSG(prev, false, "just broke the line, where is the previous one?"); + + height += prev->GetHeight(); + + SetUpdateRect(position); + SetUpdateRect(position.x + width + MSW_CORRECTION, + position.y + height + MSW_CORRECTION); + return true; } @@ -1615,8 +1704,9 @@ wxLayoutList::WrapLine(CoordType column) //else: CoordType newpos = m_CursorPos.x - xpos - 1; m_CursorPos.x = xpos; - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + + AddCursorPosToUpdateRect(); + LineBreak(); Delete(1); // delete the space m_CursorPos.x = newpos; @@ -1628,41 +1718,68 @@ wxLayoutList::WrapLine(CoordType column) bool wxLayoutList::Delete(CoordType npos) { - wxASSERT(m_CursorLine); - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + wxCHECK_MSG(m_CursorLine, false, "can't delete in non existing line"); + wxASSERT_MSG(npos > 0, "nothing to delete?"); + + AddCursorPosToUpdateRect(); + + // were other lines appended to this one (this is important to know because + // this means that our width _increased_ as the result of deletion) + bool wasMerged = false; + + // the size of the region to update + CoordType totalHeight = m_CursorLine->GetHeight(), + totalWidth = m_CursorLine->GetWidth(); + CoordType left; do { left = m_CursorLine->Delete(m_CursorPos.x, npos); - if(left == 0) - return true; - // More to delete, continue on next line. - // First, check if line is empty: - if(m_CursorLine->GetLength() == 0) - { // in this case, updating could probably be optimised -#ifdef WXLO_DEBUG - wxASSERT(DeleteLines(1) == 0); + + if( left > 0 ) + { + // More to delete, continue on next line. + + // First, check if line is empty: + if(m_CursorLine->GetLength() == 0) + { + // in this case, updating could probably be optimised +#ifdef WXLO_DEBUG + wxASSERT(DeleteLines(1) == 0); #else - DeleteLines(1); + DeleteLines(1); #endif - - left--; - } - else - { - // Need to join next line - if(! m_CursorLine->GetNextLine()) - break; // cannot + + left--; + } else { - m_CursorLine->MergeNextLine(this); - left--; + // Need to join next line + if(! m_CursorLine->GetNextLine()) + break; // cannot + else + { + wasMerged = true; + wxLayoutLine *next = m_CursorLine->GetNextLine(); + if ( next ) + totalHeight += next->GetHeight(); + m_CursorLine->MergeNextLine(this); + left--; + } } } } - while(left); - m_CursorLine->RecalculatePositions(true, this); //FIXME needed? + while ( left> 0 ); + + // we need to update the whole tail of the line and the lines which + // disappeared + if ( wasMerged ) + { + wxPoint position(m_CursorLine->GetPosition()); + SetUpdateRect(position.x + totalWidth + MSW_CORRECTION, + position.y + totalHeight + MSW_CORRECTION); + } + return left == 0; } @@ -1671,8 +1788,9 @@ wxLayoutList::DeleteLines(int n) { wxASSERT(m_CursorLine); wxLayoutLine *line; - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + + AddCursorPosToUpdateRect(); + while(n > 0) { if(!m_CursorLine->GetNextLine()) @@ -1726,14 +1844,14 @@ wxLayoutList::GetCursorScreenPos(wxDC &dc) } /* - Is called before each Draw(). Now, it will re-layout all lines which + Is called before each Draw(). Now, it will re-layout all lines which have changed. */ void wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll) { wxLayoutLine *line = m_FirstLine; - + // first, make sure everything is calculated - this might not be // needed, optimise it later ApplyStyle(&m_DefaultSetting, dc); @@ -1761,8 +1879,7 @@ wxLayoutList::Layout(wxDC &dc, CoordType bottom, bool forceAll) m_CursorLine->GetNextLine() == NULL && m_CursorLine == m_FirstLine)); #endif - SetUpdateRect(m_CursorScreenPos); - SetUpdateRect(m_CursorScreenPos+m_CursorSize); + AddCursorPosToUpdateRect(); } void @@ -1773,12 +1890,12 @@ wxLayoutList::Draw(wxDC &dc, { wxLayoutLine *line = m_FirstLine; - Layout(dc); + Layout(dc); ApplyStyle(&m_DefaultSetting, dc); wxBrush brush(m_CurrentSetting.m_bg, wxSOLID); dc.SetBrush(brush); dc.SetBackgroundMode(wxTRANSPARENT); - + while(line) { // only draw if between top and bottom: @@ -1806,7 +1923,7 @@ wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos, // First, find the right line: wxLayoutLine *line = m_FirstLine; wxPoint p; - + // we need to run a layout here to get font sizes right :-( ApplyStyle(&m_DefaultSetting, dc); while(line) @@ -1828,7 +1945,7 @@ wxLayoutList::FindObjectScreen(wxDC &dc, wxPoint const pos, cursorPos ? & cursorPos->x : NULL , found); return (i == NULLIT) ? NULL : *i; - + } wxPoint @@ -1841,7 +1958,7 @@ wxLayoutList::GetSize(void) const return wxPoint(0,0); wxPoint maxPoint(0,0); - + // find last line: while(line) { @@ -1859,10 +1976,8 @@ wxLayoutList::GetSize(void) const void wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate) { - wxPoint coords; - coords = m_CursorScreenPos; - coords.x += translate.x; - coords.y += translate.y; + wxPoint coords(m_CursorScreenPos); + coords += translate; #ifdef WXLAYOUT_DEBUG WXLO_DEBUG(("Drawing cursor (%ld,%ld) at %ld,%ld, size %ld,%ld, line: %ld, len %ld", @@ -1871,8 +1986,13 @@ wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate) (long)m_CursorSize.x, (long)m_CursorSize.y, (long)m_CursorLine->GetLineNumber(), (long)m_CursorLine->GetLength())); + + wxLogStatus("Cursor is at (%d, %d)", m_CursorPos.x, m_CursorPos.y); #endif - + +#ifdef WXLAYOUT_USE_CARET + m_caret->Move(coords); +#else // !WXLAYOUT_USE_CARET dc.SetBrush(*wxBLACK_BRUSH); dc.SetLogicalFunction(wxXOR); dc.SetPen(wxPen(*wxBLACK,1,wxSOLID)); @@ -1892,6 +2012,7 @@ wxLayoutList::DrawCursor(wxDC &dc, bool active, wxPoint const &translate) } dc.SetLogicalFunction(wxCOPY); //dc.SetBrush(wxNullBrush); +#endif // WXLAYOUT_USE_CARET/!WXLAYOUT_USE_CARET } void @@ -2017,7 +2138,7 @@ wxLayoutList::DeleteSelection(void) return; m_Selection.m_valid = false; - + // Only delete part of the current line? if(m_Selection.m_CursorA.y == m_Selection.m_CursorB.y) { @@ -2061,11 +2182,11 @@ wxLayoutList::DeleteSelection(void) Delete(1); // This joins firstLine and nextLine Delete(m_Selection.m_CursorB.x); // This deletes the first x // positions - + /// Recalculate: firstLine->RecalculatePositions(1, this); } - + /// Starts highlighting the selection void wxLayoutList::StartHighlighting(wxDC &dc) @@ -2153,12 +2274,12 @@ wxLayoutList::GetSelection(wxLayoutDataObject *wxlo, bool invalidate) else return NULL; } - + if(invalidate) m_Selection.m_valid = false; wxLayoutList *llist = Copy( m_Selection.m_CursorA, m_Selection.m_CursorB ); - + if(llist && wxlo) // export as data object, too { wxString string; @@ -2173,6 +2294,7 @@ wxLayoutList::GetSelection(wxLayoutDataObject *wxlo, bool invalidate) export->content.object->Write(string); delete export; } + wxlo->SetData(string.c_str(), string.Length()+1); } return llist; @@ -2210,7 +2332,7 @@ wxLayoutList::ApplyStyle(wxLayoutStyleInfo *si, wxDC &dc) #ifdef WXLAYOUT_DEBUG void -wxLayoutList::Debug(void) +wxLayoutList::Debug(void) { wxLayoutLine *line; @@ -2224,7 +2346,7 @@ wxLayoutList::Debug(void) #endif -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutPrintout @@ -2238,7 +2360,7 @@ wxLayoutPrintout::wxLayoutPrintout(wxLayoutList *llist, m_title = title; // remove any highlighting which could interfere with printing: m_llist->StartSelection(); - m_llist->EndSelection(); + m_llist->EndSelection(); } wxLayoutPrintout::~wxLayoutPrintout() @@ -2250,7 +2372,7 @@ wxLayoutPrintout::ScaleDC(wxDC *dc) { // The following bit is taken from the printing sample, let's see // whether it works for us. - + /* You might use THIS code to set the printer DC to ROUGHLY reflect * the screen text size. This page also draws lines of actual length 5cm * on the page. @@ -2271,7 +2393,7 @@ wxLayoutPrintout::ScaleDC(wxDC *dc) ppiPrinterX = 72; ppiPrinterY = 72; } - + // This scales the DC so that the printout roughly represents the // the screen scaling. The text point size _should_ be the right size // but in fact is too small for some reason. This is a detail that will @@ -2300,7 +2422,7 @@ bool wxLayoutPrintout::OnPrintPage(int page) wxDC *dc = GetDC(); ScaleDC(dc); - + if (dc) { int top, bottom; @@ -2336,8 +2458,8 @@ void wxLayoutPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, // This is the length of the printable area. m_PrintoutHeight = m_PageHeight - (int) (m_PageHeight * 0.15); m_PrintoutHeight = (int)( m_PrintoutHeight / scale); // we want to use the real paper height - - + + m_NumOfPages = 1 + (int)( m_llist->GetSize().y / (float)(m_PrintoutHeight)); @@ -2368,12 +2490,12 @@ wxLayoutPrintout::DrawHeader(wxDC &dc, const wxBrush& brush = dc.GetBrush(); const wxPen& pen = dc.GetPen(); const wxFont& font = dc.GetFont(); - + dc.SetBrush(*wxWHITE_BRUSH); dc.SetPen(wxPen(*wxBLACK,0,wxSOLID)); dc.DrawRoundedRectangle(topleft.x, topleft.y,bottomright.x-topleft.x, - bottomright.y-topleft.y); + bottomright.y-topleft.y); dc.SetBrush(*wxBLACK_BRUSH); wxFont myfont = wxFont((WXLO_DEFAULTFONTSIZE*12)/10, wxSWISS,wxNORMAL,wxBOLD,false,"Helvetica"); @@ -2397,7 +2519,7 @@ wxLayoutPrintout::DrawHeader(wxDC &dc, wxFont & -wxFontCache::GetFont(int family, int size, int style, int weight, +wxFontCache::GetFont(int family, int size, int style, int weight, bool underline) { for(wxFCEList::iterator i = m_FontList.begin(); @@ -2410,4 +2532,4 @@ wxFontCache::GetFont(int family, int size, int style, int weight, m_FontList.push_back(fce); return fce->GetFont(); } - + diff --git a/user/wxLayout/wxllist.h b/user/wxLayout/wxllist.h index 84a1e1c7c6..630596b8df 100644 --- a/user/wxLayout/wxllist.h +++ b/user/wxLayout/wxllist.h @@ -30,6 +30,12 @@ # define WXMENU_LAYOUT_DBLCLICK 1113 #endif +// use the wxWindows caret class instead of home grown cursor whenever possible +#ifdef __WXMSW__ + #undef WXLAYOUT_USE_CARET + #define WXLAYOUT_USE_CARET 1 +#endif // __WXMSW__ + // do not enable debug mode within Mahogany #if defined(__WXDEBUG__) && ! defined(M_BASEDIR) # define WXLAYOUT_DEBUG @@ -38,7 +44,7 @@ #ifdef WXLAYOUT_DEBUG # define WXLO_TRACE(x) wxLogDebug(x) #else -# define WXLO_TRACE(x) +# define WXLO_TRACE(x) #endif #define WXLO_DEBUG_URECT 0 @@ -72,20 +78,22 @@ typedef long CoordType; // Forward declarations. class wxLayoutList; +class wxLayoutLine; class wxLayoutObject; -class wxDC; -class wxColour; -class wxFont; +class WXDLLEXPORT wxCaret; +class WXDLLEXPORT wxColour; +class WXDLLEXPORT wxDC; +class WXDLLEXPORT wxFont; -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * The wxLayout objects which make up the lines. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - + /** The base class defining the interface to each object which can be - part of the layout. Each object needs to draw itself and calculate + part of the layout. Each object needs to draw itself and calculate its size. */ class wxLayoutObject @@ -118,7 +126,7 @@ public: @param dc the wxDC to draw on @param llist the wxLayoutList */ - virtual void Layout(wxDC &dc, class wxLayoutList *llist) = 0; + virtual void Layout(wxDC &dc, wxLayoutList *llist) = 0; /** Draws an object. @param dc the wxDC to draw on @@ -129,11 +137,11 @@ public: */ virtual void Draw(wxDC & /* dc */, wxPoint const & /* coords */, - class wxLayoutList *wxllist, + wxLayoutList *wxllist, CoordType begin = -1, CoordType end = -1) { } - /** Calculates and returns the size of the object. + /** Calculates and returns the size of the object. @param top where to store height above baseline @param bottom where to store height below baseline @return the size of the object's box in pixels @@ -154,7 +162,7 @@ public: virtual CoordType GetOffsetScreen(wxDC &dc, CoordType xpos) const { return 0; } /// constructor - wxLayoutObject() { m_UserData = NULL; } + wxLayoutObject() { m_UserData = NULL; m_Line = NULL; } /// delete the user data virtual ~wxLayoutObject() { if(m_UserData) m_UserData->DecRef(); } @@ -174,7 +182,21 @@ public: if(m_UserData) m_UserData->IncRef(); } - + + /// returns the line we belong to (or NULL) + wxLayoutLine *GetLine() const { return m_Line; } + + /// attaches this object to the given line, it's an error to reattach us + void AttachToLine(wxLayoutLine *line) + { + wxASSERT_MSG( !m_Line, "this layout object already belongs to a line" ); + + m_Line = line; + } + + /// unattaches the object (should reattach it immediately afterwards!) + void UnattachFromLine() { if ( m_Line ) m_Line = (wxLayoutLine *)NULL; } + /** Return the user data. Increments the object's reference count. When no longer needed, caller must call DecRef() on the pointer returned. @@ -199,6 +221,9 @@ public: protected: /// optional data for application's use UserData *m_UserData; + + /// the line of the text we belong to or NULL if we're not shown on screen + wxLayoutLine *m_Line; }; /// Define a list type of wxLayoutObject pointers. @@ -209,7 +234,7 @@ KBLIST_DEFINE(wxLayoutObjectList, wxLayoutObject); /// The iterator type. #define wxLOiterator wxLayoutObjectList::iterator -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutObjectText @@ -220,14 +245,14 @@ class wxLayoutObjectText : public wxLayoutObject { public: wxLayoutObjectText(const wxString &txt = ""); - + virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_TEXT; } - virtual void Layout(wxDC &dc, class wxLayoutList *llist); + virtual void Layout(wxDC &dc, wxLayoutList *llist); virtual void Draw(wxDC &dc, wxPoint const &coords, - class wxLayoutList *wxllist, + wxLayoutList *wxllist, CoordType begin = -1, CoordType end = -1); - /** Calculates and returns the size of the object. + /** Calculates and returns the size of the object. @param top where to store height above baseline @param bottom where to store height below baseline @return the size of the object's box in pixels @@ -268,7 +293,7 @@ private: long m_Bottom; }; -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutObjectIcon @@ -284,13 +309,13 @@ public: ~wxLayoutObjectIcon() { if(m_Icon) delete m_Icon; } virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_ICON; } - virtual void Layout(wxDC &dc, class wxLayoutList *llist); + virtual void Layout(wxDC &dc, wxLayoutList *llist); virtual void Draw(wxDC &dc, wxPoint const &coords, - class wxLayoutList *wxllist, + wxLayoutList *wxllist, CoordType begin = -1, CoordType end = -1); - /** Calculates and returns the size of the object. + /** Calculates and returns the size of the object. @param top where to store height above baseline @param bottom where to store height below baseline @return the size of the object's box in pixels @@ -309,7 +334,7 @@ private: wxBitmap *m_Icon; }; -/** This structure holds all formatting information. Members which are +/** This structure holds all formatting information. Members which are undefined (for a CmdObject this means: no change), are set to -1. */ struct wxLayoutStyleInfo @@ -337,7 +362,7 @@ struct wxLayoutStyleInfo class wxFontCacheEntry { public: - wxFontCacheEntry(int family, int size, int style, int weight, + wxFontCacheEntry(int family, int size, int style, int weight, bool underline) { m_Family = family; m_Size = size; m_Style = style; @@ -345,7 +370,7 @@ public: m_Font = new wxFont(m_Size, m_Family, m_Style, m_Weight, m_Underline); } - bool Matches(int family, int size, int style, int weight, + bool Matches(int family, int size, int style, int weight, bool underline) const { return size == m_Size && family == m_Family @@ -368,17 +393,18 @@ KBLIST_DEFINE(wxFCEList, wxFontCacheEntry); class wxFontCache { public: - wxFont & GetFont(int family, int size, int style, int weight, + wxFont & GetFont(int family, int size, int style, int weight, bool underline); wxFont & GetFont(wxLayoutStyleInfo const &si) { - return GetFont(si.family, si.size, si.style, si.weight, si.underline); + return GetFont(si.family, si.size, si.style, si.weight, + si.underline != 0); } private: wxFCEList m_FontList; }; -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * wxLayoutObjectCmd @@ -389,9 +415,9 @@ class wxLayoutObjectCmd : public wxLayoutObject { public: virtual wxLayoutObjectType GetType(void) const { return WXLO_TYPE_CMD; } - virtual void Layout(wxDC &dc, class wxLayoutList *llist); + virtual void Layout(wxDC &dc, wxLayoutList *llist); virtual void Draw(wxDC &dc, wxPoint const &coords, - class wxLayoutList *wxllist, + wxLayoutList *wxllist, CoordType begin = -1, CoordType end = -1); wxLayoutObjectCmd(int family = -1, @@ -413,19 +439,16 @@ private: wxLayoutStyleInfo *m_StyleInfo; }; -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * The wxLayoutLine object * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/// forward declaration -class wxLayoutList; - /** This class represents a single line of objects to be displayed. It knows its height and total size and whether it needs to be redrawn or not. - It has pointers to its first and next line so it can automatically + It has pointers to its first and next line so it can automatically update them as needed. */ class wxLayoutLine @@ -443,7 +466,7 @@ public: @return true if that xpos existed and the object was inserted */ bool Insert(CoordType xpos, wxLayoutObject *obj); - + /** This function inserts text at cursor position xpos. @param xpos where to insert @param text the text to insert @@ -457,6 +480,8 @@ public: void Append(wxLayoutObject * obj) { wxASSERT(obj); + + obj->AttachToLine(this); m_ObjectList.push_back(obj); m_Length += obj->GetLength(); } @@ -483,20 +508,20 @@ public: whitespace. This function does not delete over font changes, i.e. a word with formatting instructions in the middle of it is treated as - two (three actually!) words. In fact, if the cursor is on a non-text object, that + two (three actually!) words. In fact, if the cursor is on a non-text object, that one is treated as a word. @param xpos from where to delete @return true if a word was deleted */ bool DeleteWord(CoordType npos); - /** Finds a suitable position left to the given column to break the + /** Finds a suitable position left to the given column to break the line. @param column we want to break the line to the left of this @return column for breaking line or -1 if no suitable location found */ CoordType GetWrapPosition(CoordType column); - + /** Finds the object which covers the cursor position xpos in this line. @param xpos the column number @@ -526,8 +551,8 @@ public: @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. @return iterator to the first object */ @@ -535,7 +560,7 @@ public: { return m_ObjectList.begin(); } - + /** Deletes this line, returns pointer to next line. @param update If true, update all following lines. */ @@ -557,17 +582,17 @@ public: //@{ /** Draws the line on a wxDC. @param dc the wxDC to draw on - @param llist the wxLayoutList + @param llist the wxLayoutList @param offset an optional offset to shift printout */ void Draw(wxDC &dc, wxLayoutList *llist, const wxPoint &offset = wxPoint(0,0)) const; - + /** Recalculates the positions of objects and the height of the line. @param dc the wxDC to draw on - @param llist th e wxLayoutList + @param llist th e wxLayoutList @param cursorPos if not NULL, set cursor screen position in there @param cursorSize if not cursorPos != NULL, set cursor size in there @param cx if cursorPos != NULL, the cursor x position @@ -631,7 +656,7 @@ public: void Copy(wxLayoutList *llist, CoordType from = 0, CoordType to = -1); - + #ifdef WXLAYOUT_DEBUG void Debug(void); #endif @@ -695,13 +720,13 @@ private: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - + The wxLayoutList object - + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /** The wxLayoutList is a list of wxLayoutLine objects. It provides a - higher level of abstraction for the text and can generally be considered - as representing "the text". + higher level of abstraction for the text and can generally be considered + as representing "the text". */ class wxLayoutList { @@ -711,6 +736,11 @@ public: /// Destructor. ~wxLayoutList(); +#ifdef WXLAYOUT_USE_CARET + /// give us the pointer to the caret to use + void SetCaret(wxCaret *caret) { m_caret = caret; } +#endif // WXLAYOUT_USE_CARET + /// Clear the list. void Clear(int family = wxROMAN, int size=WXLO_DEFAULTFONTSIZE, @@ -721,7 +751,7 @@ public: wxColour *bg=NULL); /// Empty: clear the list but leave font settings. void Empty(void); - + /**@name Cursor Management */ //@{ /** Set new cursor position. @@ -744,9 +774,9 @@ public: void MoveCursorToEndOfLine(void) { wxASSERT(m_CursorLine); - MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x); + MoveCursorHorizontally(m_CursorLine->GetLength()-m_CursorPos.x); } - + /// Move cursor to begin of line. void MoveCursorToBeginOfLine(void) { MoveCursorHorizontally(-m_CursorPos.x); } @@ -754,7 +784,7 @@ public: /// Returns current cursor position. const wxPoint &GetCursorPos(wxDC &dc) const { return m_CursorPos; } const wxPoint &GetCursorPos() const { return m_CursorPos; } - + //@} /**@name Editing functions. @@ -767,7 +797,7 @@ public: bool Insert(wxLayoutObject *obj); /// Inserts objects at current cursor positions bool Insert(wxLayoutList *llist); - + /// Inserts a linebreak at current cursor position. bool LineBreak(void); /** Wraps the current line. Searches to the left of the cursor to @@ -788,7 +818,7 @@ public: @return how many it could not delete */ int DeleteLines(int n); - + /// Delete to end of line. void DeleteToEndOfLine(void) { @@ -843,7 +873,7 @@ public: /// changes to the next smaller font size inline void SetFontSmaller(void) { SetFont(-1,(10*m_CurrentSetting.size)/12); } - + /// set font family inline void SetFontFamily(int family) { SetFont(family); } /// set font size @@ -898,7 +928,7 @@ public: @param bottom optional y coordinate where to stop calculating */ void Recalculate(wxDC &dc, CoordType bottom = -1); - + /** Returns the size of the list in screen coordinates. The return value only makes sense after the list has been drawn. @@ -911,7 +941,7 @@ public: @return cursor position in pixels */ wxPoint GetCursorScreenPos(wxDC &dc); - + /** Draws the cursor. @param active If true, draw a bold cursor to mark window as active. @@ -944,6 +974,15 @@ public: */ inline void SetUpdateRect(const wxPoint &p) { SetUpdateRect(p.x,p.y); } + /// adds the cursor position to the update rectangle + void AddCursorPosToUpdateRect() + { + #ifndef WXLAYOUT_USE_CARET + SetUpdateRect(m_CursorScreenPos); + SetUpdateRect(m_CursorScreenPos+m_CursorSize); + //#else - the caret will take care of refreshing itself + #endif // !WXLAYOUT_USE_CARET + } /// Invalidates the update rectangle. void InvalidateUpdateRect(void) { m_UpdateRectValid = false; } /// Returns the update rectangle. @@ -977,7 +1016,7 @@ public: wxLayoutList *GetSelection(class wxLayoutDataObject *wxldo = NULL, bool invalidate = TRUE); /// Delete selected bit void DeleteSelection(void); - + wxLayoutList *Copy(const wxPoint &from = wxPoint(0,0), const wxPoint &to = wxPoint(-1,-1)); @@ -985,7 +1024,7 @@ public: void StartHighlighting(wxDC &dc); /// ends highlighting of text for selections void EndHighlighting(wxDC &dc); - + /** Tests whether this layout line is selected and needs highlighting. @param line to test for @@ -993,7 +1032,7 @@ public: @param to set to last cursorpos to be highlighted (for returncode == -1) @return 0 = not selected, 1 = fully selected, -1 = partially selected - + */ int IsSelected(const wxLayoutLine *line, CoordType *from, CoordType *to); @@ -1007,7 +1046,7 @@ private: /** Calculates the cursor position on the screen. */ void UpdateCursorScreenPos(wxDC &dc); - + /// The list of lines. wxLayoutLine *m_FirstLine; /// The update rectangle which needs to be refreshed: @@ -1018,13 +1057,17 @@ private: //@{ /// Where the text cursor (column,line) is. wxPoint m_CursorPos; - /// The size of the cursor. - wxPoint m_CursorSize; /// Where the cursor should be drawn. wxPoint m_CursorScreenPos; /// The line where the cursor is. wxLayoutLine *m_CursorLine; - //@} + /// The size of the cursor. + wxPoint m_CursorSize; +#ifdef WXLAYOUT_USE_CARET + /// the caret + wxCaret *m_caret; +#endif // WXLAYOUT_USE_CARET + //@} /// A structure for the selection. struct Selection @@ -1045,12 +1088,11 @@ private: //@} }; - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - + The wxLayoutDataObject for exporting data to the clipboard in our own format. - + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ class wxLayoutDataObject : public wxPrivateDataObject { @@ -1063,10 +1105,10 @@ public: }; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - + The wxLayoutPrintout object for printing within the wxWindows print framework. - + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /** This class implements a wxPrintout for printing a wxLayoutList within the wxWindows printing framework. @@ -1083,7 +1125,7 @@ public: "wxLayout Printout"); /// Destructor. ~wxLayoutPrintout(); - + /** Function which prints the n-th page. @param page the page number to print @return bool true if we are not at end of document yet @@ -1114,7 +1156,7 @@ protected: /* no longer used virtual void DrawHeader(wxDC &dc, wxPoint topleft, wxPoint bottomright, int pageno); - */ + */ private: /// The list to print. wxLayoutList *m_llist; diff --git a/user/wxLayout/wxlparser.cpp b/user/wxLayout/wxlparser.cpp index b93f39e473..3370fd5fc7 100644 --- a/user/wxLayout/wxlparser.cpp +++ b/user/wxLayout/wxlparser.cpp @@ -10,7 +10,14 @@ # pragma implementation "wxlparser.h" #endif +#include + +#ifdef __BORLANDC__ +# pragma hdrstop +#endif + #include "Mpch.h" + #ifdef M_PREFIX # include "gui/wxllist.h" # include "gui/wxlparser.h" diff --git a/user/wxLayout/wxlwindow.cpp b/user/wxLayout/wxlwindow.cpp index 4331bd51bf..093db74fa4 100644 --- a/user/wxLayout/wxlwindow.cpp +++ b/user/wxLayout/wxlwindow.cpp @@ -1,7 +1,7 @@ /*-*- c++ -*-******************************************************** * wxLwindow.h : a scrolled Window for displaying/entering rich text* * * - * (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) * + * (C) 1998, 1999 by Karsten Ballüder (Ballueder@usa.net) * * * * $Id$ *******************************************************************/ @@ -11,12 +11,13 @@ #endif #include "wx/wxprec.h" + #ifdef __BORLANDC__ # pragma hdrstop #endif - #include "Mpch.h" + #ifdef M_BASEDIR # ifndef USE_PCH # include "Mcommon.h" @@ -41,6 +42,10 @@ #include #include +#ifdef WXLAYOUT_USE_CARET +# include +#endif // WXLAYOUT_USE_CARET + #include #ifdef WXLAYOUT_DEBUG @@ -71,8 +76,9 @@ BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow) END_EVENT_TABLE() wxLayoutWindow::wxLayoutWindow(wxWindow *parent) - : wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize, - wxHSCROLL | wxVSCROLL | wxBORDER) + : wxScrolledWindow(parent, -1, + wxDefaultPosition, wxDefaultSize, + wxHSCROLL | wxVSCROLL | wxBORDER) { SetStatusBar(NULL); // don't use statusbar @@ -85,6 +91,7 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent) m_bitmap = new wxBitmap(4,4); m_bitmapSize = wxPoint(4,4); m_llist = new wxLayoutList(); + m_BGbitmap = NULL; m_ScrollToCursor = false; SetWrapMargin(0); @@ -93,7 +100,16 @@ wxLayoutWindow::wxLayoutWindow(wxWindow *parent) EnableScrolling(true,true); m_maxx = max.x; m_maxy = max.y; m_Selecting = false; - SetCursorVisibility(-1); + +#ifdef WXLAYOUT_USE_CARET + // FIXME cursor size shouldn't be hardcoded + wxCaret *caret = new wxCaret(this, 2, 20); + SetCaret(caret); + m_llist->SetCaret(caret); + caret->Show(); +#endif // WXLAYOUT_USE_CARET + + SetCursorVisibility(-1); SetCursor(wxCURSOR_IBEAM); SetDirty(); } @@ -121,12 +137,8 @@ wxLayoutWindow::Clear(int family, ResizeScrollbars(true); SetDirty(); SetModified(false); - wxRect r; - int w,h; - r.x = r.y = 0; GetSize(&w,&h); - r.width = w; - r.height = h; - DoPaint(&r); + + DoPaint((wxRect *)NULL); } #ifdef __WXMSW__ @@ -142,7 +154,7 @@ void wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event) { wxPaintDC dc( this ); - PrepareDC( dc ); + PrepareDC( dc ); SetFocus(); wxPoint findPos; @@ -173,7 +185,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event) if(!m_HandCursor) SetCursor(wxCURSOR_HAND); m_HandCursor = TRUE; - if(m_StatusBar && m_StatusFieldLabel != -1) + if(m_StatusBar && m_StatusFieldLabel != -1) { const wxString &label = u->GetLabel(); if(label.Length()) @@ -186,7 +198,7 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event) if(m_HandCursor) SetCursor(wxCURSOR_IBEAM); m_HandCursor = FALSE; - if(m_StatusBar && m_StatusFieldLabel != -1) + if(m_StatusBar && m_StatusFieldLabel != -1) m_StatusBar->SetStatusText("", m_StatusFieldLabel); } if(event.LeftIsDown()) @@ -195,19 +207,19 @@ wxLayoutWindow::OnMouse(int eventId, wxMouseEvent& event) { m_llist->StartSelection(); m_Selecting = true; - DoPaint(FALSE); + DoPaint(FALSE); } else { m_llist->ContinueSelection(cursorPos); - DoPaint(FALSE); - } + DoPaint(FALSE); + } } if(m_Selecting && ! event.LeftIsDown()) { m_llist->EndSelection(cursorPos); m_Selecting = false; - DoPaint(FALSE); + DoPaint(FALSE); } if(u) u->DecRef(); return; @@ -257,7 +269,7 @@ void wxLayoutWindow::OnChar(wxKeyEvent& event) { int keyCode = event.KeyCode(); - + #ifdef WXLAYOUT_DEBUG if(keyCode == WXK_F1) { @@ -289,7 +301,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) // If needed, make cursor visible: if(m_CursorVisibility == -1) m_CursorVisibility = 1; - + /* These two nested switches work like this: The first one processes all non-editing keycodes, to move the cursor, etc. It's default will process all keycodes causing @@ -323,7 +335,10 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) break; default: if(keyCode == 'c' && event.ControlDown()) + { + // this should work even in read-only mode Copy(); + } if( IsEditable() ) { /* First, handle control keys */ @@ -353,9 +368,6 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) case 'v': Paste(); break; - case 'c': - Copy(); - break; case 'x': Cut(); break; @@ -420,7 +432,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) } SetDirty(); SetModified(); - }// if(IsEditable()) + }// if(IsEditable()) }// first switch() if(m_Selecting) { @@ -464,14 +476,14 @@ wxLayoutWindow::ScrollToCursor(void) 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); wxASSERT(y1 > 0); // As we have the values anyway, use them to avoid unnecessary // scrollbar updates. - if(x1 > m_maxx) m_maxx = x1; + if(x1 > m_maxx) m_maxx = x1; if(y1 > m_maxy) m_maxy = y1; /* Make sure that the scrollbars are at a position so that the cursor is visible if we are editing. */ @@ -513,6 +525,11 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) wxPaintDC dc( this ); PrepareDC( dc ); +#ifdef WXLAYOUT_USE_CARET + // hide the caret before drawing anything + GetCaret()->Hide(); +#endif // WXLAYOUT_USE_CARET + int x0,y0,x1,y1, dx, dy; // Calculate where the top of the visible area is: @@ -526,7 +543,7 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) wxASSERT(y1 > 0); // As we have the values anyway, use them to avoid unnecessary // scrollbar updates. - if(x1 > m_maxx) m_maxx = x1; + if(x1 > m_maxx) m_maxx = x1; if(y1 > m_maxy) m_maxy = y1; @@ -542,13 +559,13 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) m_llist->Layout(dc); 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 the bitmap to be larger. */ if(x1 > m_bitmapSize.x || y1 > m_bitmapSize.y) { wxASSERT(m_bitmapSize.x > 0); wxASSERT(m_bitmapSize.y > 0); - + m_memDC->SelectObject(wxNullBitmap); delete m_bitmap; m_bitmapSize = wxPoint(x1,y1); @@ -559,7 +576,7 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) m_memDC->SetDeviceOrigin(0,0); m_memDC->SetBrush(wxBrush(m_llist->GetDefaults()->GetBGColour(),wxSOLID)); m_memDC->SetPen(wxPen(m_llist->GetDefaults()->GetBGColour(), - 0,wxTRANSPARENT)); + 0,wxTRANSPARENT)); m_memDC->SetLogicalFunction(wxCOPY); /* Either fill the background with the background bitmap, or clear @@ -582,7 +599,7 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) m_memDC->DrawRectangle(0,0,x1, y1); } - + /* This is the important bit: we tell the list to draw itself: */ #if WXLO_DEBUG_URECT if(updateRect) @@ -590,10 +607,10 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) WXLO_DEBUG(("Update rect: %ld,%ld / %ld,%ld", updateRect->x, updateRect->y, updateRect->x+updateRect->width, - updateRect->y+updateRect->height)); + updateRect->y+updateRect->height)); } #endif - + // Device origins on the memDC are suspect, we translate manually // with the translate parameter of Draw(). wxPoint offset(-x0+WXLO_XOFFSET,-y0+WXLO_YOFFSET); @@ -603,8 +620,8 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) // cursor, so that the cursor coordinates get included in the next // update rectangle (although they are drawn on the memDC, this is // needed to erase it): - m_llist->InvalidateUpdateRect(); - if(m_CursorVisibility == 1) + m_llist->InvalidateUpdateRect(); + if(m_CursorVisibility != 0) m_llist->DrawCursor(*m_memDC, m_HaveFocus && IsEditable(), // draw a thick // cursor for editable windows with focus @@ -636,12 +653,19 @@ wxLayoutWindow::InternalPaint(const wxRect *updateRect) dc.Blit(x0,y0,x1,y1,m_memDC,0,0,wxCOPY,FALSE); } +#ifdef WXLAYOUT_USE_CARET + // show the caret back after everything is redrawn + m_caret->Show(); +#endif // WXLAYOUT_USE_CARET + ResetDirty(); m_ScrollToCursor = false; - if(m_StatusBar && m_StatusFieldCursor != -1) + if(m_StatusBar && m_StatusFieldCursor != -1) { wxString label; - label.Printf(_("L:%d C:%d"), m_llist->GetCursorPos().x+1, m_llist->GetCursorPos().y+1); + label.Printf(_("Ln:%d Col:%d"), + m_llist->GetCursorPos().y+1, + m_llist->GetCursorPos().x+1); m_StatusBar->SetStatusText(label, m_StatusFieldCursor); } } @@ -652,16 +676,16 @@ wxLayoutWindow::ResizeScrollbars(bool exact) { wxPoint max = m_llist->GetSize(); - WXLO_DEBUG(("ResizeScrollbars: GetSize: %ld, %ld", (long int)max.x, + 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) { - if(! exact) + if(! exact) { // add an extra bit to the sizes to avoid future updates - max.x = max.x+WXLO_ROFFSET; + max.x = max.x+WXLO_ROFFSET; max.y = max.y+WXLO_BOFFSET; } ViewStart(&m_ViewStartX, &m_ViewStartY); @@ -684,7 +708,7 @@ wxLayoutWindow::Paste(void) { } //FIXME: missing functionality m_llist->Insert(wxldo.GetList()); - } + } else #endif { @@ -698,6 +722,7 @@ wxLayoutWindow::Paste(void) } wxTheClipboard->Close(); } + #if 0 /* My attempt to get the primary selection, but it does not work. :-( */ @@ -746,7 +771,7 @@ wxLayoutWindow::Copy(bool invalidate) else if(len > 1 && text[len-1] == '\n') text = text.Mid(0,len-1); } - + if (wxTheClipboard->Open()) { @@ -758,6 +783,7 @@ wxLayoutWindow::Copy(bool invalidate) wxTheClipboard->Close(); return rc; } + return FALSE; } @@ -777,7 +803,7 @@ wxLayoutWindow::Find(const wxString &needle, wxPoint * fromWhere) { wxPoint found; - + if(fromWhere == NULL) found = m_llist->FindText(needle, m_llist->GetCursorPos()); else diff --git a/user/wxLayout/wxlwindow.h b/user/wxLayout/wxlwindow.h index 881dc66e65..080ff000ee 100644 --- a/user/wxLayout/wxlwindow.h +++ b/user/wxLayout/wxlwindow.h @@ -23,7 +23,7 @@ #endif -#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 0 +#define wxUSE_PRIVATE_CLIPBOARD_FORMAT 1 enum {