several fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@446 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1998-08-06 19:23:19 +00:00
parent 09cf7c5853
commit c6cdf16c93
5 changed files with 60 additions and 25 deletions

View File

@@ -76,6 +76,8 @@ IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
void
MyFrame::AddSampleText(wxLayoutList &llist)
{
llist.Insert("--");
llist.LineBreak();
llist.Insert("The quick brown fox jumps over the lazy dog.");
llist.LineBreak();
@@ -146,9 +148,11 @@ MyFrame::AddSampleText(wxLayoutList &llist)
llist.LineBreak();
}
}
m_lwin->Refresh();
m_lwin->UpdateScrollbars();
llist.SetEditable();
llist.SetCursor(wxPoint(0,0));
}
void
@@ -169,7 +173,7 @@ void MyFrame::Edit(void)
llist.MoveCursor(0,2);
llist.Delete(2);
llist.MoveCursor(2);
llist.Insert("not all so ");
llist.Insert("not");
llist.LineBreak();
m_lwin->Refresh();
}

View File

@@ -31,10 +31,6 @@
#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
static const char *_t[] = { "invalid", "text", "cmd", "icon",
"linebreak"};
@@ -46,6 +42,14 @@ wxLayoutObjectBase::Debug(void)
cerr << _t[GetType()] << ": size=" << GetSize(&bl).x << ","
<< 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
//-------------------------- wxLayoutObjectText
@@ -372,6 +376,7 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords)
dc.GetTextExtent(Str(str), &width,&height, &descent);
VAR(height);
VAR(width); VAR(descent);
if(width < 1) width = 1;
dc.DrawLine(position.x+width,
position.y+(baseLineSkip-height),
position.x+width, position.y+baseLineSkip);
@@ -523,11 +528,10 @@ wxLayoutList::FindObjectCursor(wxPoint const &cpos, CoordType *offset)
width = 0;
if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
{
if(cpos.y == cursor.y)
if(cpos.y == cursor.y && i != begin())
{
--i;
if(offset)
*offset = (*i)->CountPositions();
if(offset) *offset = i != end() ? (*i)->CountPositions() : 0;
return i;
}
cursor.x = 0; cursor.y ++;
@@ -690,7 +694,7 @@ wxLayoutList::Delete(CoordType count)
if(offs == len)
{
i++;
if((*i)->GetType() == WXLO_TYPE_TEXT)
if(i != end() && (*i)->GetType() == WXLO_TYPE_TEXT)
{
offs = 0; // delete from begin of next string
tobj = (wxLayoutObjectText *)*i;
@@ -851,6 +855,9 @@ wxLayoutList::Clear(int family, int size, int style, int weight,
m_ColourFG = wxTheColourDatabase->FindColour(fg);
m_ColourBG = wxTheColourDatabase->FindColour(bg);
if(! m_ColourFG) m_ColourFG = wxBLACK;
if(! m_ColourBG) m_ColourBG = wxWHITE;
m_Position = wxPoint(0,0);
m_CursorPosition = wxPoint(0,0);
m_MaxLine = 0;

View File

@@ -17,10 +17,15 @@
#include <wx/wx.h>
// skip the following defines if embedded in M application
#ifndef MCONFIG_H
// for testing only:
#ifdef M_BASEDIR
# ifdef DEBUG
//# define WXLAYOUT_DEBUG
# endif
#else
// for testing only:
# define WXLAYOUT_DEBUG
//# define USE_STD_STRING
// The wxLayout classes can be compiled with std::string instead of wxString
//# define USE_STD_STRING
#endif
#ifdef USE_STD_STRING
@@ -60,8 +65,8 @@ public:
@param baseLine the baseline for alignment, from top of box
@draw if set to false, do not draw but just calculate sizes
*/
virtual void Draw( wxDC &WXUNUSED(dc), wxPoint WXUNUSED(position),
CoordType WXUNUSED(baseLine), bool draw = true) {};
virtual void Draw(wxDC &dc, wxPoint position, CoordType baseLine,
bool draw = true) {};
/** Calculates and returns the size of the object. May need to be
called twice to work.
@@ -70,9 +75,8 @@ public:
baseline)
@return the size of the object's box in pixels
*/
virtual wxPoint GetSize( CoordType *WXUNUSED(baseLine) ) const
{ return wxPoint(0,0); };
virtual wxPoint GetSize(CoordType *baseLine) const { return
wxPoint(0,0); };
/// returns the number of cursor positions occupied by this object
virtual CoordType CountPositions(void) const { return 1; }
@@ -236,10 +240,13 @@ public:
/**@name Functionality for editing */
//@{
/// 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
void MoveCursor(int dx = 0, int dy = 0);
void SetCursor(wxPoint const &p) { m_CursorPosition = p; }
wxPoint GetCursor(void) const { return m_CursorPosition; }
/// delete one or more cursor positions
void Delete(CoordType count = 1);
void Insert(String const &text);
@@ -250,7 +257,10 @@ public:
/// return a pointer to the default settings:
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:
/// font parameters:
int m_FontFamily, m_FontStyle, m_FontWeight;
@@ -285,9 +295,6 @@ protected:
/// find the object to the cursor position and returns the offset
/// in there
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);
};

View File

@@ -60,8 +60,15 @@ wxLayoutWindow::OnMouse(wxMouseEvent& event)
void
wxLayoutWindow::OnChar(wxKeyEvent& event)
{
if(! m_llist.IsEditable()) // do nothing
{
event.Skip();
return;
}
long keyCode = event.KeyCode();
wxPoint p;
switch(event.KeyCode())
{
case WXK_RIGHT:
@@ -82,6 +89,16 @@ wxLayoutWindow::OnChar(wxKeyEvent& event)
case WXK_NEXT:
m_llist.MoveCursor(0,20);
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 :
m_llist.Delete(1);
break;

View File

@@ -16,7 +16,7 @@
#include "wxllist.h"
#define BROKEN_COMPILER
#define BROKEN_COMPILER
#ifdef BROKEN_COMPILER
# define virtual