void
MyFrame::AddSampleText(wxLayoutList &llist)
{
+ llist.Insert("--");
+ llist.LineBreak();
llist.Insert("The quick brown fox jumps over the lazy dog.");
llist.LineBreak();
llist.LineBreak();
}
}
-
+
m_lwin->Refresh();
m_lwin->UpdateScrollbars();
+ llist.SetEditable();
+ llist.SetCursor(wxPoint(0,0));
}
void
llist.MoveCursor(0,2);
llist.Delete(2);
llist.MoveCursor(2);
- llist.Insert("not all so ");
+ llist.Insert("not");
llist.LineBreak();
m_lwin->Refresh();
}
#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"};
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
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);
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 ++;
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;
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;
#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
@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.
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; }
/**@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);
/// 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;
/// 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);
};
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:
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;
#include "wxllist.h"
-#define BROKEN_COMPILER
+#define BROKEN_COMPILER
#ifdef BROKEN_COMPILER
# define virtual