several fixes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@446 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -76,6 +76,8 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
|
|||||||
void
|
void
|
||||||
MyFrame::AddSampleText(wxLayoutList &llist)
|
MyFrame::AddSampleText(wxLayoutList &llist)
|
||||||
{
|
{
|
||||||
|
llist.Insert("--");
|
||||||
|
llist.LineBreak();
|
||||||
|
|
||||||
llist.Insert("The quick brown fox jumps over the lazy dog.");
|
llist.Insert("The quick brown fox jumps over the lazy dog.");
|
||||||
llist.LineBreak();
|
llist.LineBreak();
|
||||||
@@ -149,6 +151,8 @@ MyFrame::AddSampleText(wxLayoutList &llist)
|
|||||||
|
|
||||||
m_lwin->Refresh();
|
m_lwin->Refresh();
|
||||||
m_lwin->UpdateScrollbars();
|
m_lwin->UpdateScrollbars();
|
||||||
|
llist.SetEditable();
|
||||||
|
llist.SetCursor(wxPoint(0,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -169,7 +173,7 @@ void MyFrame::Edit(void)
|
|||||||
llist.MoveCursor(0,2);
|
llist.MoveCursor(0,2);
|
||||||
llist.Delete(2);
|
llist.Delete(2);
|
||||||
llist.MoveCursor(2);
|
llist.MoveCursor(2);
|
||||||
llist.Insert("not all so ");
|
llist.Insert("not");
|
||||||
llist.LineBreak();
|
llist.LineBreak();
|
||||||
m_lwin->Refresh();
|
m_lwin->Refresh();
|
||||||
}
|
}
|
||||||
|
@@ -31,10 +31,6 @@
|
|||||||
|
|
||||||
#define BASELINESTRETCH 12
|
#define BASELINESTRETCH 12
|
||||||
|
|
||||||
#define VAR(x) cerr << #x"=" << x << endl;
|
|
||||||
#define DBG_POINT(p) cerr << #p << ": " << p.x << ',' << p.y << endl
|
|
||||||
#define TRACE(f) cerr << #f":" << endl;
|
|
||||||
|
|
||||||
#ifdef WXLAYOUT_DEBUG
|
#ifdef WXLAYOUT_DEBUG
|
||||||
static const char *_t[] = { "invalid", "text", "cmd", "icon",
|
static const char *_t[] = { "invalid", "text", "cmd", "icon",
|
||||||
"linebreak"};
|
"linebreak"};
|
||||||
@@ -46,6 +42,14 @@ wxLayoutObjectBase::Debug(void)
|
|||||||
cerr << _t[GetType()] << ": size=" << GetSize(&bl).x << ","
|
cerr << _t[GetType()] << ": size=" << GetSize(&bl).x << ","
|
||||||
<< GetSize(&bl).y << " bl=" << bl;
|
<< GetSize(&bl).y << " bl=" << bl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# define VAR(x) cerr << #x"=" << x << endl;
|
||||||
|
# define DBG_POINT(p) cerr << #p << ": " << p.x << ',' << p.y << endl
|
||||||
|
# define TRACE(f) cerr << #f":" << endl;
|
||||||
|
#else
|
||||||
|
# define VAR(x)
|
||||||
|
# define DBG_POINT(p)
|
||||||
|
# define TRACE(f)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//-------------------------- wxLayoutObjectText
|
//-------------------------- wxLayoutObjectText
|
||||||
@@ -372,6 +376,7 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
|
|||||||
dc.GetTextExtent(Str(str), &width,&height, &descent);
|
dc.GetTextExtent(Str(str), &width,&height, &descent);
|
||||||
VAR(height);
|
VAR(height);
|
||||||
VAR(width); VAR(descent);
|
VAR(width); VAR(descent);
|
||||||
|
if(width < 1) width = 1;
|
||||||
dc.DrawLine(position.x+width,
|
dc.DrawLine(position.x+width,
|
||||||
position.y+(baseLineSkip-height),
|
position.y+(baseLineSkip-height),
|
||||||
position.x+width, position.y+baseLineSkip);
|
position.x+width, position.y+baseLineSkip);
|
||||||
@@ -523,11 +528,10 @@ wxLayoutList::FindObjectCursor(wxPoint const &cpos, CoordType *offset)
|
|||||||
width = 0;
|
width = 0;
|
||||||
if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
|
if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
|
||||||
{
|
{
|
||||||
if(cpos.y == cursor.y)
|
if(cpos.y == cursor.y && i != begin())
|
||||||
{
|
{
|
||||||
--i;
|
--i;
|
||||||
if(offset)
|
if(offset) *offset = i != end() ? (*i)->CountPositions() : 0;
|
||||||
*offset = (*i)->CountPositions();
|
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
cursor.x = 0; cursor.y ++;
|
cursor.x = 0; cursor.y ++;
|
||||||
@@ -690,7 +694,7 @@ wxLayoutList::Delete(CoordType count)
|
|||||||
if(offs == len)
|
if(offs == len)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
if((*i)->GetType() == WXLO_TYPE_TEXT)
|
if(i != end() && (*i)->GetType() == WXLO_TYPE_TEXT)
|
||||||
{
|
{
|
||||||
offs = 0; // delete from begin of next string
|
offs = 0; // delete from begin of next string
|
||||||
tobj = (wxLayoutObjectText *)*i;
|
tobj = (wxLayoutObjectText *)*i;
|
||||||
@@ -851,6 +855,9 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
|
|||||||
m_ColourFG = wxTheColourDatabase->FindColour(fg);
|
m_ColourFG = wxTheColourDatabase->FindColour(fg);
|
||||||
m_ColourBG = wxTheColourDatabase->FindColour(bg);
|
m_ColourBG = wxTheColourDatabase->FindColour(bg);
|
||||||
|
|
||||||
|
if(! m_ColourFG) m_ColourFG = wxBLACK;
|
||||||
|
if(! m_ColourBG) m_ColourBG = wxWHITE;
|
||||||
|
|
||||||
m_Position = wxPoint(0,0);
|
m_Position = wxPoint(0,0);
|
||||||
m_CursorPosition = wxPoint(0,0);
|
m_CursorPosition = wxPoint(0,0);
|
||||||
m_MaxLine = 0;
|
m_MaxLine = 0;
|
||||||
|
@@ -17,9 +17,14 @@
|
|||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
|
|
||||||
// skip the following defines if embedded in M application
|
// skip the following defines if embedded in M application
|
||||||
#ifndef MCONFIG_H
|
#ifdef M_BASEDIR
|
||||||
|
# ifdef DEBUG
|
||||||
|
//# define WXLAYOUT_DEBUG
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
// for testing only:
|
// for testing only:
|
||||||
# define WXLAYOUT_DEBUG
|
# define WXLAYOUT_DEBUG
|
||||||
|
// The wxLayout classes can be compiled with std::string instead of wxString
|
||||||
//# define USE_STD_STRING
|
//# define USE_STD_STRING
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -60,8 +65,8 @@ public:
|
|||||||
@param baseLine the baseline for alignment, from top of box
|
@param baseLine the baseline for alignment, from top of box
|
||||||
@draw if set to false, do not draw but just calculate sizes
|
@draw if set to false, do not draw but just calculate sizes
|
||||||
*/
|
*/
|
||||||
virtual void Draw( wxDC &WXUNUSED(dc), wxPoint WXUNUSED(position),
|
virtual void Draw(wxDC &dc, wxPoint position, CoordType baseLine,
|
||||||
CoordType WXUNUSED(baseLine), bool draw = true) {};
|
bool draw = true) {};
|
||||||
|
|
||||||
/** Calculates and returns the size of the object. May need to be
|
/** Calculates and returns the size of the object. May need to be
|
||||||
called twice to work.
|
called twice to work.
|
||||||
@@ -70,9 +75,8 @@ public:
|
|||||||
baseline)
|
baseline)
|
||||||
@return the size of the object's box in pixels
|
@return the size of the object's box in pixels
|
||||||
*/
|
*/
|
||||||
virtual wxPoint GetSize( CoordType *WXUNUSED(baseLine) ) const
|
virtual wxPoint GetSize(CoordType *baseLine) const { return
|
||||||
{ return wxPoint(0,0); };
|
wxPoint(0,0); };
|
||||||
|
|
||||||
/// returns the number of cursor positions occupied by this object
|
/// returns the number of cursor positions occupied by this object
|
||||||
virtual CoordType CountPositions(void) const { return 1; }
|
virtual CoordType CountPositions(void) const { return 1; }
|
||||||
|
|
||||||
@@ -236,10 +240,13 @@ public:
|
|||||||
/**@name Functionality for editing */
|
/**@name Functionality for editing */
|
||||||
//@{
|
//@{
|
||||||
/// set list editable or read only
|
/// set list editable or read only
|
||||||
void SetEditable(bool editable = true) { m_Editable = true; }
|
void SetEditable(bool editable = true) { m_Editable = editable; }
|
||||||
|
/// return true if list is editable
|
||||||
|
bool IsEditable(void) const { return m_Editable; }
|
||||||
/// move cursor
|
/// move cursor
|
||||||
void MoveCursor(int dx = 0, int dy = 0);
|
void MoveCursor(int dx = 0, int dy = 0);
|
||||||
void SetCursor(wxPoint const &p) { m_CursorPosition = p; }
|
void SetCursor(wxPoint const &p) { m_CursorPosition = p; }
|
||||||
|
wxPoint GetCursor(void) const { return m_CursorPosition; }
|
||||||
/// delete one or more cursor positions
|
/// delete one or more cursor positions
|
||||||
void Delete(CoordType count = 1);
|
void Delete(CoordType count = 1);
|
||||||
void Insert(String const &text);
|
void Insert(String const &text);
|
||||||
@@ -250,6 +257,9 @@ public:
|
|||||||
/// return a pointer to the default settings:
|
/// return a pointer to the default settings:
|
||||||
wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; }
|
wxLayoutObjectCmd const *GetDefaults(void) const { return m_DefaultSetting ; }
|
||||||
|
|
||||||
|
wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = NULL);
|
||||||
|
// get the length of the line with the object pointed to by i
|
||||||
|
CoordType GetLineLength(wxLayoutObjectList::iterator i);
|
||||||
//@}
|
//@}
|
||||||
protected:
|
protected:
|
||||||
/// font parameters:
|
/// font parameters:
|
||||||
@@ -285,9 +295,6 @@ protected:
|
|||||||
/// find the object to the cursor position and returns the offset
|
/// find the object to the cursor position and returns the offset
|
||||||
/// in there
|
/// in there
|
||||||
wxLayoutObjectList::iterator FindObjectCursor(wxPoint const &cpos, CoordType *offset = NULL);
|
wxLayoutObjectList::iterator FindObjectCursor(wxPoint const &cpos, CoordType *offset = NULL);
|
||||||
wxLayoutObjectList::iterator FindCurrentObject(CoordType *offset = NULL);
|
|
||||||
// get the length of the line with the object pointed to by i
|
|
||||||
CoordType GetLineLength(wxLayoutObjectList::iterator i);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -60,7 +60,14 @@ wxLayoutWindow::OnMouse(wxMouseEvent& event)
|
|||||||
void
|
void
|
||||||
wxLayoutWindow::OnChar(wxKeyEvent& event)
|
wxLayoutWindow::OnChar(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
|
if(! m_llist.IsEditable()) // do nothing
|
||||||
|
{
|
||||||
|
event.Skip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
long keyCode = event.KeyCode();
|
long keyCode = event.KeyCode();
|
||||||
|
wxPoint p;
|
||||||
|
|
||||||
switch(event.KeyCode())
|
switch(event.KeyCode())
|
||||||
{
|
{
|
||||||
@@ -82,6 +89,16 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
|
|||||||
case WXK_NEXT:
|
case WXK_NEXT:
|
||||||
m_llist.MoveCursor(0,20);
|
m_llist.MoveCursor(0,20);
|
||||||
break;
|
break;
|
||||||
|
case WXK_HOME:
|
||||||
|
p = m_llist.GetCursor();
|
||||||
|
p.x = 0;
|
||||||
|
m_llist.SetCursor(p);
|
||||||
|
break;
|
||||||
|
case WXK_END:
|
||||||
|
p = m_llist.GetCursor();
|
||||||
|
p.x = m_llist.GetLineLength(m_llist.FindCurrentObject(NULL));
|
||||||
|
m_llist.SetCursor(p);
|
||||||
|
break;
|
||||||
case WXK_DELETE :
|
case WXK_DELETE :
|
||||||
m_llist.Delete(1);
|
m_llist.Delete(1);
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user