integrated my latest changes and Vadim's fixes on top of that

Compiles, but works?


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@523 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1998-08-13 10:03:26 +00:00
parent fc008f2592
commit 5e0394ae9b
5 changed files with 124 additions and 83 deletions

View File

@@ -159,7 +159,7 @@ MyFrame::AddSampleText(wxLayoutList &llist)
void void
MyFrame::Clear(void) MyFrame::Clear(void)
{ {
m_lwin->Erase(); m_lwin->Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false);
m_lwin->UpdateScrollbars(); m_lwin->UpdateScrollbars();
} }

View File

@@ -34,31 +34,41 @@
# include <wx/dc.h> # include <wx/dc.h>
# include <wx/postscrp.h> # include <wx/postscrp.h>
# include <wx/print.h> # include <wx/print.h>
# include <wx/log.h>
#endif #endif
#define BASELINESTRETCH 12 #define BASELINESTRETCH 12
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
static const char *_t[] = { "invalid", "text", "cmd", "icon", static const char *g_aTypeStrings[] =
"linebreak"}; {
"invalid", "text", "cmd", "icon", "linebreak"
};
# define wxLayoutDebug wxLogDebug
# define WXL_VAR(x) wxLogDebug(#x " = ", x)
# define WXL_DBG_POINT(p) wxLogDebug(#p ": (%d, %d)", p.x, p.y)
# define WXL_TRACE(f) wxLogDebug(#f ": ")
# define TypeString(t) g_aTypeStrings[t]
void void
wxLayoutObjectBase::Debug(void) wxLayoutObjectBase::Debug(void)
{ {
CoordType bl = 0; CoordType bl = 0;
cerr << _t[GetType()] << ": size=" << GetSize(&bl).x << "," wxLogDebug("%s: size = %dx%d, bl = %d",
<< GetSize(&bl).y << " bl=" << bl; TypeString(GetType()), GetSize(&bl).x, GetSize(&bl).y, bl);
} }
# define WXL_VAR(x) cerr << #x"=" << x << endl
# define WXL_DBG_POINT(p) cerr << #p << ": " << p.x << ',' << p.y << endl
# define WXL_TRACE(f) cerr << #f":" << endl
#else #else
# define WXL_VAR(x) # define WXL_VAR(x)
# define WXL_DBG_POINT(p) # define WXL_DBG_POINT(p)
# define WXL_TRACE(f) # define WXL_TRACE(f)
# define ShowCurrentObject()
# define TypeString(t) ""
inline void wxLayoutDebug(const char *, ...) { }
#endif #endif
//-------------------------- wxLayoutObjectText //-------------------------- wxLayoutObjectText
wxLayoutObjectText::wxLayoutObjectText(const String &txt) wxLayoutObjectText::wxLayoutObjectText(const String &txt)
@@ -89,6 +99,7 @@ wxLayoutObjectText::Draw(wxDC &dc, wxPoint position, CoordType baseLine,
position.y += baseLine-m_BaseLine; position.y += baseLine-m_BaseLine;
if(draw) if(draw)
dc.DrawText(Str(m_Text),position.x,position.y); dc.DrawText(Str(m_Text),position.x,position.y);
// Don't remove this, important help for debugging layout.
# ifdef WXLAYOUT_DEBUG # ifdef WXLAYOUT_DEBUG
// dc.DrawRectangle(position.x, position.y, m_Width, m_Height); // dc.DrawRectangle(position.x, position.y, m_Width, m_Height);
# endif # endif
@@ -99,7 +110,7 @@ void
wxLayoutObjectText::Debug(void) wxLayoutObjectText::Debug(void)
{ {
wxLayoutObjectBase::Debug(); wxLayoutObjectBase::Debug();
cerr << " `" << m_Text << '\''; wxLogDebug(" `%s`", m_Text.c_str());
} }
#endif #endif
@@ -193,9 +204,9 @@ wxLayoutList::~wxLayoutList()
{ {
if(m_DefaultSetting) if(m_DefaultSetting)
delete m_DefaultSetting; delete m_DefaultSetting;
// no deletion of objects, they are owned by the list
} }
void void
wxLayoutList::LineBreak(void) wxLayoutList::LineBreak(void)
{ {
@@ -398,8 +409,11 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
} }
else else
{ {
cursorPosition = wxPoint(position.x, position.y); // this is not necessarily the most "beautiful" solution:
cursorSize = wxPoint(size.x > 0 ? size.x : 1,size.y > 0 ? size.y : baseLineSkip); //cursorPosition = wxPoint(position.x, position.y);
//cursorSize = wxPoint(size.x > 0 ? size.x : 1,size.y > 0 ? size.y : baseLineSkip);
cursorPosition = wxPoint(position.x+size.x, position.y+(size.y-baseLineSkip));
cursorSize = wxPoint(1, baseLineSkip);
} }
} }
@@ -482,38 +496,53 @@ wxLayoutList::Debug(void)
CoordType offs; CoordType offs;
wxLayoutObjectList::iterator i; wxLayoutObjectList::iterator i;
cerr << wxLogDebug("------------------------debug start-------------------------");
"------------------------debug start-------------------------" << endl;
for(i = begin(); i != end(); i++) for(i = begin(); i != end(); i++)
{
(*i)->Debug(); (*i)->Debug();
cerr << endl; wxLogDebug("-----------------------debug end----------------------------");
}
cerr <<
"-----------------------debug end----------------------------"
<< endl;
// show current object:
cerr << "Cursor: "
<< m_CursorPosition.x << ','
<< m_CursorPosition.y;
// show current object:
ShowCurrentObject();
i = FindCurrentObject(&offs); i = FindCurrentObject(&offs);
cerr << " line length: " << GetLineLength(i,offs) << " "; wxLogDebug(" line length: %l", (long int) GetLineLength(i,offs));
if(i == end()) if(i == end())
{ {
cerr << "<<no object found>>" << endl; wxLogDebug("<<no object found>>");
return; // FIXME we should set cursor position to maximum allowed return; // FIXME we should set cursor position to maximum allowed
// value then // value then
} }
if((*i)->GetType() == WXLO_TYPE_TEXT) if((*i)->GetType() == WXLO_TYPE_TEXT)
{ wxLogDebug(" \"%s\", offs=%d",((wxLayoutObjectText *)(*i))->GetText().c_str(), (int) offs);
cerr << " \"" << ((wxLayoutObjectText *)(*i))->GetText() << "\", offs: "
<< offs << endl;
}
else else
cerr << ' ' << _t[(*i)->GetType()] << endl; wxLogDebug(g_aTypeStrings[(*i)->GetType()]);
} }
void
wxLayoutList::ShowCurrentObject()
{
CoordType offs;
wxLayoutObjectList::iterator i = FindCurrentObject(&offs);
wxLayoutDebug("Cursor is at (%d, %d)",
m_CursorPosition.x, m_CursorPosition.y);
i = FindCurrentObject(&offs);
wxLogDebug(" Line length: %d", GetLineLength(i));
if(i == end())
{
wxLogDebug("<<no object found>>");
return; // FIXME we should set cursor position to maximum allowed
// value then
}
if((*i)->GetType() == WXLO_TYPE_TEXT)
wxLogDebug(" \"%s\", offs: %d",
((wxLayoutObjectText *)(*i))->GetText().c_str(), offs);
else
wxLogDebug(" %s", TypeString((*i)->GetType()));
}
#endif #endif
/******************** editing stuff ********************/ /******************** editing stuff ********************/
@@ -540,8 +569,7 @@ wxLayoutList::FindObjectCursor(wxPoint *cpos, CoordType *offset)
wxLayoutObjectList::iterator i; wxLayoutObjectList::iterator i;
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
cerr << "Looking for object at " << cpos->x << ',' << cpos->y << wxLayoutDebug("Looking for object at (%d, %d)", cpos->x, cpos->y);
endl;
#endif #endif
for(i = begin(); i != end() && object.y <= cpos->y; i++) for(i = begin(); i != end() && object.y <= cpos->y; i++)
{ {
@@ -563,13 +591,13 @@ wxLayoutList::FindObjectCursor(wxPoint *cpos, CoordType *offset)
{ {
if(offset) *offset = cpos->x-object.x; if(offset) *offset = cpos->x-object.x;
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
cerr << " found object at " << object.x << ',' << wxLayoutDebug(" found object at (%d, %d), type: %s",
object.y << ", type:" << _t[(*i)->GetType()] <<endl; object.x, object.y, TypeString((*i)->GetType()));
#endif #endif
return i; return i;
} }
} }
// no overlap, increment coordinates // no overlap, increment coordinates
object.x += width; object.x += width;
if((**i).GetType() == WXLO_TYPE_LINEBREAK) if((**i).GetType() == WXLO_TYPE_LINEBREAK)
{ {
@@ -578,9 +606,9 @@ wxLayoutList::FindObjectCursor(wxPoint *cpos, CoordType *offset)
} }
} }
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
cerr << " not found" << endl; wxLayoutDebug(" not found");
#endif #endif
// return last object, coordinates of that one: // return last object, coordinates of that one:
i = tail(); i = tail();
if(i == end()) if(i == end())
return i; return i;
@@ -686,7 +714,7 @@ wxLayoutList::MoveCursor(int dx, int dy)
} }
} }
} }
// final adjustment: // final adjustment:
i = FindCurrentObject(&offs); i = FindCurrentObject(&offs);
lineLength = GetLineLength(i,offs); lineLength = GetLineLength(i,offs);
if(m_CursorPosition.x > lineLength) if(m_CursorPosition.x > lineLength)
@@ -695,24 +723,7 @@ wxLayoutList::MoveCursor(int dx, int dy)
rc = false; rc = false;
} }
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
i = FindCurrentObject(&offs); ShowCurrentObject();
cerr << "Cursor: "
<< m_CursorPosition.x << ','
<< m_CursorPosition.y;
if(i == end())
{
cerr << "<<no object found>>" << endl;
return rc; // FIXME we should set cursor position to maximum allowed
// value then
}
if((*i)->GetType() == WXLO_TYPE_TEXT)
{
cerr << " \"" << ((wxLayoutObjectText *)(*i))->GetText() << "\", offs: "
<< offs << endl;
}
else
cerr << ' ' << _t[(*i)->GetType()] << endl;
#endif #endif
return rc; return rc;
} }
@@ -737,7 +748,7 @@ wxLayoutList::Delete(CoordType count)
if(i == end()) if(i == end())
return; // we cannot delete anything more return; // we cannot delete anything more
/* Here we need to treat linebreaks differently. /* Here we need to treat linebreaks differently.
If offs==0 we are before the linebreak, otherwise behind. */ If offs==0 we are before the linebreak, otherwise behind. */
if((*i)->GetType() == WXLO_TYPE_LINEBREAK) if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
{ {
@@ -759,8 +770,8 @@ wxLayoutList::Delete(CoordType count)
{ {
wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i; wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
CoordType len = tobj->CountPositions(); CoordType len = tobj->CountPositions();
// If we find the end of a text object, this means that we // If we find the end of a text object, this means that we
// have to delete from the object following it. // have to delete from the object following it.
if(len == offs) if(len == offs)
{ {
i++; i++;
@@ -780,11 +791,23 @@ wxLayoutList::Delete(CoordType count)
return; // we are done return; // we are done
} }
} }
else // all other objects: delete the object else// all other objects: delete the object
// this only works as expected if the non-text object has 0/1
// as offset values. Not tested with "longer" objects.
{ {
CoordType len = (*i)->CountPositions(); CoordType len = (*i)->CountPositions();
erase(i); // after this, i is the iterator for the following object if(offs == 0)
{
count = count > len ? count -= len : 0; count = count > len ? count -= len : 0;
erase(i); // after this, i is the iterator for the following object
continue;
}
else // delete the following object
{
i++; // we increment and continue as normal
offs=0;
goto startover;
}
} }
} }
while(count && i != end()); while(count && i != end());
@@ -803,24 +826,24 @@ wxLayoutList::Insert(wxLayoutObjectBase *obj)
push_back(obj); push_back(obj);
else if(offs == 0) else if(offs == 0)
insert(i,obj); insert(i,obj);
// do we have to split a text object? // do we have to split a text object?
else if((*i)->GetType() == WXLO_TYPE_TEXT && offs != (*i)->CountPositions()) else if((*i)->GetType() == WXLO_TYPE_TEXT && offs != (*i)->CountPositions())
{ {
wxLayoutObjectText *tobj = (wxLayoutObjectText *) *i; wxLayoutObjectText *tobj = (wxLayoutObjectText *) *i;
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
cerr << "text: '" << tobj->GetText() << "'" << endl; wxLayoutDebug("text: %s", tobj->GetText().c_str());
WXL_VAR(offs); WXL_VAR(offs);
#endif #endif
String left = tobj->GetText().substr(0,offs); // get part before cursor String left = tobj->GetText().substr(0,offs); // get part before cursor
WXL_VAR(left); WXL_VAR(left.c_str());
tobj->GetText() = tobj->GetText().substr(offs,(*i)->CountPositions()-offs); // keeps the right half tobj->GetText() = tobj->GetText().substr(offs,(*i)->CountPositions()-offs); // keeps the right half
WXL_VAR(tobj->GetText()); WXL_VAR(tobj->GetText().c_str());
insert(i,obj); insert(i,obj);
insert(i,new wxLayoutObjectText(left)); // inserts before insert(i,new wxLayoutObjectText(left)); // inserts before
} }
else else
{ {
// all other cases, append after object: // all other cases, append after object:
wxLayoutObjectList::iterator j = i; // we want to apend after this object wxLayoutObjectList::iterator j = i; // we want to apend after this object
j++; j++;
if(j != end()) if(j != end())
@@ -857,13 +880,14 @@ wxLayoutList::Insert(String const &text)
switch((**i).GetType()) switch((**i).GetType())
{ {
case WXLO_TYPE_TEXT: case WXLO_TYPE_TEXT:
// insert into an existing text object: // insert into an existing text object:
WXL_TRACE(inserting into existing object); WXL_TRACE(inserting into existing object);
tobj = (wxLayoutObjectText *)*i ; tobj = (wxLayoutObjectText *)*i ;
wxASSERT(tobj); wxASSERT(tobj);
tobj->GetText().insert(offs,text); tobj->GetText().insert(offs,text);
break; break;
case WXLO_TYPE_LINEBREAK: case WXLO_TYPE_LINEBREAK:
default:
j = i; j = i;
if(offs == 0) // try to append to previous object if(offs == 0) // try to append to previous object
{ {
@@ -893,6 +917,7 @@ wxLayoutList::Insert(String const &text)
} }
} }
break; break;
#if 0
default: default:
j = i; j--; j = i; j--;
WXL_TRACE(checking previous object); WXL_TRACE(checking previous object);
@@ -907,6 +932,7 @@ wxLayoutList::Insert(String const &text)
Insert(new wxLayoutObjectText(text)); //FIXME not too optimal, slow Insert(new wxLayoutObjectText(text)); //FIXME not too optimal, slow
return; // position gets incremented in Insert(obj) return; // position gets incremented in Insert(obj)
} }
#endif
} }
m_CursorPosition.x += strlen(text.c_str()); m_CursorPosition.x += strlen(text.c_str());
} }
@@ -920,14 +946,14 @@ wxLayoutList::GetLineLength(wxLayoutObjectList::iterator i, CoordType offs)
CoordType len = 0; CoordType len = 0;
if(offs == 0 && (**i).GetType() == WXLO_TYPE_LINEBREAK) if(offs == 0 && (**i).GetType() == WXLO_TYPE_LINEBREAK)
// we are before a linebrak // we are before a linebrak
return 0; return 0;
// search backwards for beginning of line: // search backwards for beginning of line:
while(i != begin() && (*i)->GetType() != WXLO_TYPE_LINEBREAK) while(i != begin() && (*i)->GetType() != WXLO_TYPE_LINEBREAK)
i--; i--;
if((*i)->GetType() == WXLO_TYPE_LINEBREAK) if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
i++; i++;
// now we can start counting: // now we can start counting:
while(i != end() && (*i)->GetType() != WXLO_TYPE_LINEBREAK) while(i != end() && (*i)->GetType() != WXLO_TYPE_LINEBREAK)
{ {
len += (*i)->CountPositions(); len += (*i)->CountPositions();
@@ -945,7 +971,7 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
while(i != end()) // == while valid while(i != end()) // == while valid
erase(i); erase(i);
// set defaults // set defaults
m_FontPtSize = size; m_FontPtSize = size;
m_FontUnderline = false; m_FontUnderline = false;
m_FontFamily = family; m_FontFamily = family;

View File

@@ -236,6 +236,7 @@ public:
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
void Debug(void); void Debug(void);
void ShowCurrentObject();
#endif #endif

View File

@@ -21,15 +21,29 @@ BEGIN_EVENT_TABLE(wxLayoutWindow,wxScrolledWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
wxLayoutWindow::wxLayoutWindow(wxWindow *parent) wxLayoutWindow::wxLayoutWindow(wxWindow *parent)
: wxScrolledWindow(parent) : wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize,
wxHSCROLL | wxVSCROLL | wxBORDER)
{ {
m_ScrollbarsSet = false; m_ScrollbarsSet = false;
m_EventId = -1; m_EventId = -1;
} }
#ifdef __WXMSW__
long
wxLayoutWindow::MSWGetDlgCode()
{
// if we don't return this, we won't get OnChar() events
return DLGC_WANTCHARS | DLGC_WANTARROWS | DLGC_WANTMESSAGE;
}
#endif //MSW
void void
wxLayoutWindow::OnMouse(wxMouseEvent& event) wxLayoutWindow::OnMouse(wxMouseEvent& event)
{ {
SetFocus();
if(m_EventId == -1) // nothing to do if(m_EventId == -1) // nothing to do
return; return;
@@ -38,7 +52,8 @@ wxLayoutWindow::OnMouse(wxMouseEvent& event)
m_FoundObject = NULL; m_FoundObject = NULL;
#ifdef WXLAYOUT_DEBUG #ifdef WXLAYOUT_DEBUG
cerr << "OnMouse: " << m_FindPos.x << ',' << m_FindPos.y << endl; //doesn't work, undefined functions
//wxLogTrace("OnMouse: (%d, %d)", m_FindPos.x, m_FindPos.y);
#endif #endif
Refresh(); Refresh();
if(m_FoundObject) if(m_FoundObject)

View File

@@ -47,11 +47,10 @@ public:
void UpdateScrollbars(void); void UpdateScrollbars(void);
void Print(void); void Print(void);
void Erase(void) { m_llist.Clear(); Clear(); }
void SetEventId(int id) { m_EventId = id; } void SetEventId(int id) { m_EventId = id; }
wxPoint const &GetClickPosition(void) const { return m_ClickPosition; } // what for? Caller doesn't even know object's positions in window
//wxPoint const &GetClickPosition(void) const { return m_ClickPosition; }
virtual ~wxLayoutWindow() {} virtual ~wxLayoutWindow() {}
private: private:
/// for sending events /// for sending events
wxWindow *m_Parent; wxWindow *m_Parent;