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:
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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,8 +591,8 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -578,7 +606,7 @@ 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();
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
@@ -781,10 +792,22 @@ wxLayoutList::Delete(CoordType count)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
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());
|
||||||
@@ -808,13 +831,13 @@ wxLayoutList::Insert(wxLayoutObjectBase *obj)
|
|||||||
{
|
{
|
||||||
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
|
||||||
}
|
}
|
||||||
@@ -864,6 +887,7 @@ wxLayoutList::Insert(String const &text)
|
|||||||
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());
|
||||||
}
|
}
|
||||||
|
@@ -236,6 +236,7 @@ public:
|
|||||||
|
|
||||||
#ifdef WXLAYOUT_DEBUG
|
#ifdef WXLAYOUT_DEBUG
|
||||||
void Debug(void);
|
void Debug(void);
|
||||||
|
void ShowCurrentObject();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user