From: Karsten Ballüder Date: Sun, 12 Jul 1998 15:02:44 +0000 (+0000) Subject: latest sources from M X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/23f641681ff8f715c49f21ac61b8cd522835a758 latest sources from M git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@233 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/user/wxLayout/wxLayout.cpp b/user/wxLayout/wxLayout.cpp index 7aefb35cbc..41e3392c61 100644 --- a/user/wxLayout/wxLayout.cpp +++ b/user/wxLayout/wxLayout.cpp @@ -31,7 +31,7 @@ IMPLEMENT_APP(MyApp) //----------------------------------------------------------------------------- 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 ) @@ -53,7 +53,7 @@ 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"); @@ -76,16 +76,16 @@ void 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(); @@ -113,7 +113,7 @@ MyFrame::AddSampleText(wxLayoutList &llist) 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"); @@ -194,7 +194,7 @@ void MyFrame::OnCommand( wxCommandEvent &event ) 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(); } } @@ -208,7 +208,7 @@ void MyFrame::OnCommand( wxCommandEvent &event ) case ID_CLEAR: Clear(); break; - case ID_DEBUG: + case ID_WXLAYOUT_DEBUG: m_lwin->GetLayoutList().Debug(); break; case ID_CLICK: diff --git a/user/wxLayout/wxllist.cpp b/user/wxLayout/wxllist.cpp index 925fad2d92..60dd99e6d2 100644 --- a/user/wxLayout/wxllist.cpp +++ b/user/wxLayout/wxllist.cpp @@ -25,11 +25,13 @@ #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"}; @@ -44,7 +46,7 @@ wxLayoutObjectBase::Debug(void) //-------------------------- wxLayoutObjectText -wxLayoutObjectText::wxLayoutObjectText(const wxString &txt) +wxLayoutObjectText::wxLayoutObjectText(const String &txt) { m_Text = txt; m_Width = 0; @@ -64,20 +66,20 @@ wxLayoutObjectText::Draw(wxDC &dc, wxPoint position, CoordType baseLine, 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) { @@ -168,11 +170,14 @@ wxLayoutObjectCmd::Draw(wxDC &dc, wxPoint position, CoordType lineHeight, wxLayoutList::wxLayoutList() { + m_DefaultSetting = NULL; Clear(); } wxLayoutList::~wxLayoutList() { + if(m_DefaultSetting) + delete m_DefaultSetting; } @@ -250,7 +255,7 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords) 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); @@ -264,6 +269,9 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords) 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: @@ -278,6 +286,9 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords) 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(); @@ -311,12 +322,12 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords) 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, @@ -386,7 +397,8 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords) 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; @@ -397,7 +409,7 @@ wxLayoutList::Draw(wxDC &dc, bool findObject, wxPoint const &findCoords) return foundObject; } -#ifdef WXDEBUG +#ifdef WXLAYOUT_DEBUG void wxLayoutList::Debug(void) { @@ -447,7 +459,7 @@ wxLayoutList::FindObjectCursor(wxPoint const &cpos, CoordType *offset) CoordType width; wxLayoutObjectList::iterator i; -#ifdef WXDEBUG +#ifdef WXLAYOUT_DEBUG cerr << "Looking for object at " << cpos.x << ',' << cpos.y << endl; #endif @@ -474,14 +486,14 @@ wxLayoutList::FindObjectCursor(wxPoint const &cpos, CoordType *offset) 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()] < lineLength) m_CursorPosition.x = lineLength; -#ifdef WXDEBUG +#ifdef WXLAYOUT_DEBUG i = FindCurrentObject(&offs); cerr << "Cursor: " << m_CursorPosition.x << ',' @@ -609,7 +621,7 @@ wxLayoutList::Delete(CoordType count) 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) @@ -678,11 +690,11 @@ wxLayoutList::Insert(wxLayoutObjectBase *obj) 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()); @@ -705,8 +717,9 @@ wxLayoutList::Insert(wxLayoutObjectBase *obj) } void -wxLayoutList::Insert(wxString const &text) +wxLayoutList::Insert(String const &text) { + wxLayoutObjectText *tobj = NULL; TRACE(Insert(text)); if(! m_Editable) @@ -718,18 +731,19 @@ wxLayoutList::Insert(wxString const &text) 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 @@ -765,7 +779,8 @@ wxLayoutList::GetLineLength(wxLayoutObjectList::iterator i) } 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(); @@ -773,17 +788,24 @@ wxLayoutList::Clear(void) 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); } diff --git a/user/wxLayout/wxllist.h b/user/wxLayout/wxllist.h index 8d99808069..d7d5d4b497 100644 --- a/user/wxLayout/wxllist.h +++ b/user/wxLayout/wxllist.h @@ -16,10 +16,21 @@ #include -#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 + 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 }; @@ -51,8 +62,8 @@ public: 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 @@ -75,18 +86,18 @@ public: 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 @@ -162,7 +173,7 @@ public: /// 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, @@ -173,6 +184,14 @@ public: 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 @@ -182,7 +201,7 @@ public: wxLayoutObjectBase *Draw(wxDC &dc, bool findObject = false, wxPoint const &coords = wxPoint(0,0)); -#ifdef WXDEBUG +#ifdef WXLAYOUT_DEBUG void Debug(void); #endif @@ -200,9 +219,10 @@ public: 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: @@ -213,6 +233,8 @@ protected: /// colours: wxColour const * m_ColourFG; wxColour const * m_ColourBG; + /// the default setting: + wxLayoutObjectCmd *m_DefaultSetting; /// needs recalculation? bool m_dirty; diff --git a/user/wxLayout/wxlparser.cpp b/user/wxLayout/wxlparser.cpp index 90d92e9156..2e3f9f54c4 100644 --- a/user/wxLayout/wxlparser.cpp +++ b/user/wxLayout/wxlparser.cpp @@ -15,7 +15,7 @@ #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; @@ -39,11 +39,11 @@ void wxLayoutImportText(wxLayoutList &list, wxString const &str) } 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; @@ -152,7 +152,7 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, return export; } - wxString *str = new wxString(); + String *str = new String(); // text must be concatenated while(from != list.end() && WXLO_IS_TEXT(type)) diff --git a/user/wxLayout/wxlparser.h b/user/wxLayout/wxlparser.h index c59b7dc189..b1a0f68409 100644 --- a/user/wxLayout/wxlparser.h +++ b/user/wxLayout/wxlparser.h @@ -36,7 +36,7 @@ struct wxLayoutExportObject wxLayoutExportType type; union { - wxString *text; + String *text; wxLayoutObjectBase *object; }content; ~wxLayoutExportObject() @@ -47,7 +47,7 @@ struct 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, diff --git a/user/wxLayout/wxlwindow.cpp b/user/wxLayout/wxlwindow.cpp index 333fd782b2..b20d08085e 100644 --- a/user/wxLayout/wxlwindow.cpp +++ b/user/wxLayout/wxlwindow.cpp @@ -37,7 +37,7 @@ wxLayoutWindow::OnMouse(wxMouseEvent& event) m_FindPos.y = event.GetY(); m_FoundObject = NULL; -#ifdef WXDEBUG +#ifdef WXLAYOUT_DEBUG cerr << "OnMouse: " << m_FindPos.x << ',' << m_FindPos.y << endl; #endif Refresh(); @@ -47,6 +47,8 @@ wxLayoutWindow::OnMouse(wxMouseEvent& event) { 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); } } @@ -90,7 +92,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) case WXK_RETURN: m_llist.LineBreak(); break; -#ifdef WXDEBUG +#ifdef WXLAYOUT_DEBUG case WXK_F1: m_llist.Debug(); break; @@ -98,7 +100,7 @@ wxLayoutWindow::OnChar(wxKeyEvent& event) default: if(keyCode < 256 && keyCode >= 32) { - wxString tmp; + String tmp; tmp += keyCode; m_llist.Insert(tmp); } diff --git a/user/wxLayout/wxlwindow.h b/user/wxLayout/wxlwindow.h index 31e98e498a..fea528ac79 100644 --- a/user/wxLayout/wxlwindow.h +++ b/user/wxLayout/wxlwindow.h @@ -32,7 +32,11 @@ public: 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; @@ -41,7 +45,7 @@ private: /// if we want to find an object: wxPoint m_FindPos; wxLayoutObjectBase *m_FoundObject; - + wxPoint m_ClickPosition; DECLARE_EVENT_TABLE() };