From f94a81c084696210418b8709e8ab649a18465fa6 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Wed, 28 Sep 2005 21:16:27 +0000 Subject: [PATCH] Implement wxChoice::Insert. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35754 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/motif/choice.cpp | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/motif/choice.cpp b/src/motif/choice.cpp index 8b8062b87b..af308732cf 100644 --- a/src/motif/choice.cpp +++ b/src/motif/choice.cpp @@ -183,13 +183,25 @@ wxChoice::~wxChoice() m_clientDataDict.DestroyData(); } -int wxChoice::DoAppend(const wxString& item) +static inline wxChar* MYcopystring(const wxChar* s) { + wxChar* copy = new wxChar[wxStrlen(s) + 1]; + return wxStrcpy(copy, s); +} + +int wxChoice::DoInsert(const wxString& item, int pos) +{ +#ifndef XmNpositionIndex + wxCHECK_MSG( pos == GetCount(), -1, wxT("insert not implemented")); +#endif Widget w = XtVaCreateManagedWidget (wxStripMenuCodes(item), #if wxUSE_GADGETS xmPushButtonGadgetClass, (Widget) m_menuWidget, #else xmPushButtonWidgetClass, (Widget) m_menuWidget, +#endif +#ifdef XmNpositionIndex + XmNpositionIndex, pos, #endif NULL); @@ -198,7 +210,7 @@ int wxChoice::DoAppend(const wxString& item) if( m_font.Ok() ) wxDoChangeFont( w, m_font ); - m_widgetArray.Add(w); + m_widgetArray.Insert(w, pos); char mnem = wxFindMnemonic (item); if (mnem != 0) @@ -217,18 +229,16 @@ int wxChoice::DoAppend(const wxString& item) XmNlabelString, text(), NULL); } - m_stringList.Add(item); + // need to ditch wxStringList for wxArrayString + m_stringList.Insert(pos, MYcopystring(item)); m_noStrings ++; - return GetCount() - 1; + return pos; } -int wxChoice::DoInsert(const wxString& item, int pos) +int wxChoice::DoAppend(const wxString& item) { - wxCHECK_MSG(false, -1, wxT("insert not implemented")); - -// wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index")); -// if (pos == GetCount()) return DoAppend(item); + return DoInsert(item, GetCount()); } void wxChoice::Delete(int n)