//-----------------------------------------------------------------------------
enum ids{ ID_EDIT = 1, ID_ADD_SAMPLE, ID_CLEAR, ID_PRINT, ID_DPRINT,
- ID_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT };
+ ID_WXLAYOUT_DEBUG, ID_QUIT, ID_CLICK, ID_HTML, ID_TEXT };
IMPLEMENT_DYNAMIC_CLASS( MyFrame, wxFrame )
file_menu->Append( ID_CLEAR, "Clear");
file_menu->Append( ID_ADD_SAMPLE, "Example");
file_menu->Append( ID_EDIT, "Edit");
- file_menu->Append( ID_DEBUG, "Debug");
+ file_menu->Append( ID_WXLAYOUT_DEBUG, "Debug");
file_menu->Append( ID_PRINT, "Print");
file_menu->Append( ID_DPRINT, "Direct Print");
file_menu->Append( ID_TEXT, "Export Text");
MyFrame::AddSampleText(wxLayoutList &llist)
{
- llist.SetFont(wxROMAN,24,wxNORMAL,wxNORMAL, false);
+ llist.Clear(wxROMAN,16,wxNORMAL,wxNORMAL, false);
llist.Insert("The quick brown fox jumps over the lazy dog.");
llist.LineBreak();
-
llist.Insert("Hello ");
llist.Insert(new wxLayoutObjectIcon(new wxIcon(Micon_xpm,-1,-1)));
- llist.Insert("World!");
-
-
+ llist.LineBreak();
+ llist.SetFontWeight(wxBOLD);
+ llist.Insert("World! ");
+ llist.SetFontWeight(wxNORMAL);
llist.Insert("The quick brown fox jumps...");
llist.LineBreak();
llist.SetFont(-1,-1,-1,-1,-1,"blue");
llist.Insert("blue");
llist.SetFont(-1,-1,-1,-1,-1,"black");
- llist.Insert("and ");
+ llist.Insert(" and ");
llist.SetFont(-1,-1,-1,-1,-1,"red","black");
llist.Insert("red on black");
llist.SetFont(-1,-1,-1,-1,-1,"black");
if (dc.Ok() && dc.StartDoc((char *)_("Printing message...")))
{
//dc.SetUserScale(1.0, 1.0);
- llist.Draw(dc);
+ llist.Draw(dc); //,false,wxPoint(0,0),true);
dc.EndDoc();
}
}
case ID_CLEAR:
Clear();
break;
- case ID_DEBUG:
+ case ID_WXLAYOUT_DEBUG:
m_lwin->GetLayoutList().Debug();
break;
case ID_CLICK:
#include "wxllist.h"
#include "iostream"
+#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 WXDEBUG
+#ifdef WXLAYOUT_DEBUG
static const char *_t[] = { "invalid", "text", "cmd", "icon",
"linebreak"};
//-------------------------- wxLayoutObjectText
-wxLayoutObjectText::wxLayoutObjectText(const wxString &txt)
+wxLayoutObjectText::wxLayoutObjectText(const String &txt)
{
m_Text = txt;
m_Width = 0;
bool draw)
{
long descent = 0l;
- dc.GetTextExtent(m_Text,&m_Width, &m_Height, &descent);
+ dc.GetTextExtent(Str(m_Text),&m_Width, &m_Height, &descent);
//FIXME: wxGTK does not set descent to a descent value yet.
if(descent == 0)
descent = (2*m_Height)/10; // crude fix
m_BaseLine = m_Height - descent;
position.y += baseLine-m_BaseLine;
if(draw)
- dc.DrawText(m_Text,position.x,position.y);
-# ifdef WXDEBUG
+ dc.DrawText(Str(m_Text),position.x,position.y);
+# ifdef WXLAYOUT_DEBUG
// dc.DrawRectangle(position.x, position.y, m_Width, m_Height);
# endif
}
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
void
wxLayoutObjectText::Debug(void)
{
wxLayoutList::wxLayoutList()
{
+ m_DefaultSetting = NULL;
Clear();
}
wxLayoutList::~wxLayoutList()
{
+ if(m_DefaultSetting)
+ delete m_DefaultSetting;
}
wxPoint position = wxPoint(0,0);
wxPoint position_HeadOfLine;
CoordType baseLine = m_FontPtSize;
- CoordType baseLineSkip = (12 * baseLine)/10;
+ CoordType baseLineSkip = (BASELINESTRETCH * baseLine)/10;
// we trace the objects' cursor positions so we can draw the cursor
wxPoint cursor = wxPoint(0,0);
CoordType objBaseLine = baseLine;
wxLayoutObjectType type;
+ // used temporarily
+ wxLayoutObjectText *tobj = NULL;
+
VAR(findObject); VAR(findCoords.x); VAR(findCoords.y);
// if the cursorobject is a cmd, we need to find the first
// printable object:
dc.SetTextForeground( *wxBLACK );
dc.SetFont( *wxNORMAL_FONT );
+ if(m_DefaultSetting)
+ m_DefaultSetting->Draw(dc,wxPoint(0,0),0,true);
+
// we calculate everything for drawing a line, then rewind to the
// begin of line and actually draw it
i = begin();
if(type == WXLO_TYPE_TEXT) // special treatment
{
long descent = 0l; long width, height;
- wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
- wxString str = tobj->GetText();
+ tobj = (wxLayoutObjectText *)*i;
+ String str = tobj->GetText();
VAR(m_CursorPosition.x); VAR(cursor.x);
str = str.substr(0, cursorOffset);
VAR(str);
- dc.GetTextExtent(str, &width,&height, &descent);
+ dc.GetTextExtent(Str(str), &width,&height, &descent);
VAR(height);
VAR(width); VAR(descent);
dc.DrawLine(position.x+width,
position.x = 0;
position.y += baseLineSkip;
baseLine = m_FontPtSize;
- baseLineSkip = (12 * baseLine)/10;
+ objBaseLine = baseLine; // not all objects set it
+ baseLineSkip = (BASELINESTRETCH * baseLine)/10;
headOfLine = i;
headOfLine++;
position_HeadOfLine = position;
return foundObject;
}
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
void
wxLayoutList::Debug(void)
{
CoordType width;
wxLayoutObjectList::iterator i;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << "Looking for object at " << cpos.x << ',' << cpos.y <<
endl;
#endif
if(offset)
*offset = cpos.x-(cursor.x-width); // 0==cursor before
// the object
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << " found object at " << cursor.x-width << ',' <<
cursor.y << ", type:" << _t[(*i)->GetType()] <<endl;
#endif
return i;
}
}
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << " not found" << endl;
#endif
return end(); // not found
if(m_CursorPosition.x > lineLength)
m_CursorPosition.x = lineLength;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
i = FindCurrentObject(&offs);
cerr << "Cursor: "
<< m_CursorPosition.x << ','
i = FindCurrentObject(&offs);
if(i == end())
return;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << "trying to delete: " << _t[(*i)->GetType()] << endl;
#endif
if((*i)->GetType() == WXLO_TYPE_LINEBREAK)
if((*i)->GetType() == WXLO_TYPE_TEXT && offs != 0 && offs != (*i)->CountPositions())
{
wxLayoutObjectText *tobj = (wxLayoutObjectText *) *i;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << "text: '" << tobj->GetText() << "'" << endl;
VAR(offs);
#endif
- wxString left = tobj->GetText().substr(0,offs); // get part before cursor
+ String left = tobj->GetText().substr(0,offs); // get part before cursor
VAR(left);
tobj->GetText() = tobj->GetText().substr(offs,(*i)->CountPositions()-offs); // keeps the right half
VAR(tobj->GetText());
}
void
-wxLayoutList::Insert(wxString const &text)
+wxLayoutList::Insert(String const &text)
{
+ wxLayoutObjectText *tobj = NULL;
TRACE(Insert(text));
if(! m_Editable)
if(i != end() && (*i)->GetType() == WXLO_TYPE_TEXT)
{ // insert into an existing text object:
TRACE(inserting into existing object);
- wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
+ tobj = (wxLayoutObjectText *)*i ;
+ wxASSERT(tobj);
tobj->GetText().insert(offs,text);
}
- else
+ else // check whether the previous object is text:
{
- // check whether the previous object is text:
wxLayoutObjectList::iterator j = i;
j--;
TRACE(checking previous object);
if(0 && j != end() && (*j)->GetType() == WXLO_TYPE_TEXT)
{
- wxLayoutObjectText *tobj = (wxLayoutObjectText *)*i;
+ tobj = (wxLayoutObjectText *)*i;
+ wxASSERT(tobj);
tobj->GetText()+=text;
}
else // insert a new text object
}
void
-wxLayoutList::Clear(void)
+wxLayoutList::Clear(int family, int size, int style, int weight,
+ int underline, char const *fg, char const *bg)
{
wxLayoutObjectList::iterator i = begin();
erase(i);
// set defaults
- m_FontPtSize = 12;
+ m_FontPtSize = size;
m_FontUnderline = false;
- m_FontFamily = wxDEFAULT;
- m_FontStyle = wxNORMAL;
- m_FontWeight = wxNORMAL;
- m_ColourFG = wxTheColourDatabase->FindColour("BLACK");
- m_ColourBG = wxTheColourDatabase->FindColour("WHITE");
+ m_FontFamily = family;
+ m_FontStyle = style;
+ m_FontWeight = weight;
+ m_ColourFG = wxTheColourDatabase->FindColour(fg);
+ m_ColourBG = wxTheColourDatabase->FindColour(bg);
m_Position = wxPoint(0,0);
m_CursorPosition = wxPoint(0,0);
m_MaxLine = 0;
- m_LineHeight = (12*m_FontPtSize)/10;
+ m_LineHeight = (BASELINESTRETCH*m_FontPtSize)/10;
m_MaxX = 0; m_MaxY = 0;
+
+ if(m_DefaultSetting)
+ delete m_DefaultSetting;
+ m_DefaultSetting = new
+ wxLayoutObjectCmd(m_FontPtSize,m_FontFamily,m_FontStyle,
+ m_FontWeight,m_FontUnderline,
+ m_ColourFG, m_ColourBG);
}
#include <wx/wx.h>
-#ifndef WXDEBUG
-# define WXDEBUG
+// skip the following defines if embedded in M application
+#ifndef MCONFIG_H
+// for testing only:
+# define WXLAYOUT_DEBUG
+# cdefine USE_STD_STRING
#endif
+#ifdef USE_STD_STRING
+# include <string>
+ typedef std::string String;
+# define Str(str)(str.c_str())
+#else
+ typedef wxString String;
+# define Str(str) str
+#endif
enum wxLayoutObjectType { WXLO_TYPE_INVALID, WXLO_TYPE_TEXT, WXLO_TYPE_CMD, WXLO_TYPE_ICON, WXLO_TYPE_LINEBREAK };
virtual CoordType CountPositions(void) const { return 1; }
wxLayoutObjectBase() { m_UserData = NULL; }
- virtual ~wxLayoutObjectBase() {}
-#ifdef WXDEBUG
+ virtual ~wxLayoutObjectBase() { if(m_UserData) delete m_UserData; }
+#ifdef WXLAYOUT_DEBUG
virtual void Debug(void);
#endif
align text objects.
*/
virtual wxPoint GetSize(CoordType *baseLine) const;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
virtual void Debug(void);
#endif
- wxLayoutObjectText(const wxString &txt);
+ wxLayoutObjectText(const String &txt);
virtual CoordType CountPositions(void) const { return strlen(m_Text.c_str()); }
// for editing:
- wxString & GetText(void) { return m_Text; }
- void SetText(wxString const &text) { m_Text = text; }
+ String & GetText(void) { return m_Text; }
+ void SetText(String const &text) { m_Text = text; }
private:
- wxString m_Text;
+ String m_Text;
/// size of the box containing text
long m_Width, m_Height;
/// the position of the baseline counted from the top of the box
/// adds an object:
void AddObject(wxLayoutObjectBase *obj);
- void AddText(wxString const &txt);
+ void AddText(String const &txt);
void LineBreak(void);
void SetFont(int family, int size, int style,
int weight=-1, int underline = -1,
char const *fg = NULL,
char const *bg = NULL);
+ inline void SetFontFamily(int family) { SetFont(family); }
+ inline void SetFontSize(int size) { SetFont(-1,size); }
+ inline void SetFontStyle(int style) { SetFont(-1,-1,style); }
+ inline void SetFontWeight(int weight) { SetFont(-1,-1,-1,weight); }
+ inline void SetFontUnderline(bool ul) { SetFont(-1,-1,-1,-1,(int)ul); }
+ inline void SetFontColour(char const *fg, char const *bg = NULL) { SetFont(-1,-1,-1,-1,-1,fg,bg); }
+
+
/** Draw the list on a given DC.
@param findObject if true, return the object occupying the
position specified by coords
wxLayoutObjectBase *Draw(wxDC &dc, bool findObject = false,
wxPoint const &coords = wxPoint(0,0));
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
void Debug(void);
#endif
void SetCursor(wxPoint const &p) { m_CursorPosition = p; }
/// delete one or more cursor positions
void Delete(CoordType count = 1);
- void Insert(wxString const &text);
+ void Insert(String const &text);
void Insert(wxLayoutObjectBase *obj);
- void Clear(void);
+ void Clear(int family = wxROMAN, int size=12, int style=wxNORMAL, int weight=wxNORMAL,
+ int underline=0, char const *fg="black", char const *bg="white");
//@}
protected:
/// colours:
wxColour const * m_ColourFG;
wxColour const * m_ColourBG;
+ /// the default setting:
+ wxLayoutObjectCmd *m_DefaultSetting;
/// needs recalculation?
bool m_dirty;
#define BASE_SIZE 12
-void wxLayoutImportText(wxLayoutList &list, wxString const &str)
+void wxLayoutImportText(wxLayoutList &list, String const &str)
{
char * cptr = (char *)str.c_str(); // string gets changed only temporarily
const char * begin = cptr;
}
static
-wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
+String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
wxLayoutStyleInfo **lastStylePtr)
{
static char buffer[20];
- wxString html;
+ String html;
wxLayoutStyleInfo *si = cmd.GetStyle();
wxLayoutStyleInfo *last_si = NULL;
return export;
}
- wxString *str = new wxString();
+ String *str = new String();
// text must be concatenated
while(from != list.end() && WXLO_IS_TEXT(type))
wxLayoutExportType type;
union
{
- wxString *text;
+ String *text;
wxLayoutObjectBase *object;
}content;
~wxLayoutExportObject()
};
/// import text into a wxLayoutList (including linefeeds):
-void wxLayoutImportText(wxLayoutList &list, wxString const &str);
+void wxLayoutImportText(wxLayoutList &list, String const &str);
wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
m_FindPos.y = event.GetY();
m_FoundObject = NULL;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
cerr << "OnMouse: " << m_FindPos.x << ',' << m_FindPos.y << endl;
#endif
Refresh();
{
wxCommandEvent commandEvent(wxEVENT_TYPE_MENU_COMMAND, m_EventId);
commandEvent.SetEventObject( this );
+ commandEvent.SetClientData((char *)m_FoundObject);
+ m_ClickPosition = wxPoint(event.GetX(), event.GetY());
GetEventHandler()->ProcessEvent(commandEvent);
}
}
case WXK_RETURN:
m_llist.LineBreak();
break;
-#ifdef WXDEBUG
+#ifdef WXLAYOUT_DEBUG
case WXK_F1:
m_llist.Debug();
break;
default:
if(keyCode < 256 && keyCode >= 32)
{
- wxString tmp;
+ String tmp;
tmp += keyCode;
m_llist.Insert(tmp);
}
void Erase(void)
{ m_llist.Clear(); Clear(); }
void SetEventId(int id) { m_EventId = id; }
+ wxPoint const &GetClickPosition(void) const { return
+ m_ClickPosition; }
private:
+ /// for sending events
+ wxWindow *m_Parent;
int m_EventId;
/// the layout list to be displayed
wxLayoutList m_llist;
/// if we want to find an object:
wxPoint m_FindPos;
wxLayoutObjectBase *m_FoundObject;
-
+ wxPoint m_ClickPosition;
DECLARE_EVENT_TABLE()
};