X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/31528cd3cac75558beef4bce0ba21fd182a808ab..c9b142c9f8a33853c9183df8304bd6fe8d945964:/src/motif/choice.cpp diff --git a/src/motif/choice.cpp b/src/motif/choice.cpp index 71981d44d2..9cfe04c8d1 100644 --- a/src/motif/choice.cpp +++ b/src/motif/choice.cpp @@ -13,20 +13,30 @@ #pragma implementation "choice.h" #endif -// For compilers that support precompilation, includes "wx.h". +#ifdef __VMS +#define XtDisplay XTDISPLAY +#define XtParent XTPARENT +#endif + +#include "wx/defs.h" + #include "wx/choice.h" #include "wx/utils.h" +#ifdef __VMS__ +#pragma message disable nosimpint +#endif #include #include #include #include +#ifdef __VMS__ +#pragma message enable nosimpint +#endif #include "wx/motif/private.h" -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl) -#endif void wxChoiceCallback (Widget w, XtPointer clientData, XtPointer ptr); @@ -185,32 +195,37 @@ void wxChoice::Append(const wxString& item) for (i = 0; i < m_noStrings; i++) new_widgetList[i] = m_widgetList[i]; - new_widgetList[m_noStrings] = (WXWidget) w; + new_widgetList[m_noStrings] = (WXWidget) w; - if (m_widgetList) - delete[] m_widgetList; - m_widgetList = new_widgetList; + if (m_widgetList) + delete[] m_widgetList; + m_widgetList = new_widgetList; - char mnem = wxFindMnemonic ((char*) (const char*) item); - if (mnem != 0) - XtVaSetValues (w, XmNmnemonic, mnem, NULL); + char mnem = wxFindMnemonic ((char*) (const char*) item); + if (mnem != 0) + XtVaSetValues (w, XmNmnemonic, mnem, NULL); - XtAddCallback (w, XmNactivateCallback, (XtCallbackProc) wxChoiceCallback, (XtPointer) this); + XtAddCallback (w, XmNactivateCallback, (XtCallbackProc) wxChoiceCallback, (XtPointer) this); - if (m_noStrings == 0 && m_buttonWidget) - { - XtVaSetValues ((Widget) m_buttonWidget, XmNmenuHistory, w, NULL); - Widget label = XmOptionButtonGadget ((Widget) m_buttonWidget); - XmString text = XmStringCreateSimple ((char*) (const char*) item); - XtVaSetValues (label, - XmNlabelString, text, - NULL); - XmStringFree (text); - } - wxNode *node = m_stringList.Add (item); - XtVaSetValues (w, XmNuserData, node->Data (), NULL); + if (m_noStrings == 0 && m_buttonWidget) + { + XtVaSetValues ((Widget) m_buttonWidget, XmNmenuHistory, w, NULL); + Widget label = XmOptionButtonGadget ((Widget) m_buttonWidget); + XmString text = XmStringCreateSimple ((char*) (const char*) item); + XtVaSetValues (label, + XmNlabelString, text, + NULL); + XmStringFree (text); + } + wxNode *node = m_stringList.Add (item); + XtVaSetValues (w, XmNuserData, node->Data (), NULL); - m_noStrings ++; + if (m_noStrings == 0) + m_clientList.Append((wxObject*) NULL); + else + m_clientList.Insert( m_clientList.Item(m_noStrings-1), + (wxObject*) NULL ); + m_noStrings ++; } void wxChoice::Delete(int WXUNUSED(n)) @@ -239,6 +254,21 @@ void wxChoice::Clear() m_widgetList = (WXWidget*) NULL; if (m_buttonWidget) XtVaSetValues ((Widget) m_buttonWidget, XmNmenuHistory, (Widget) NULL, NULL); + + if ( HasClientObjectData() ) + { + // destroy the data (due to Robert's idea of using wxList + // and not wxList we can't just say + // m_clientList.DeleteContents(TRUE) - this would crash! + wxNode *node = m_clientList.First(); + while ( node ) + { + delete (wxClientData *)node->Data(); + node = node->Next(); + } + } + m_clientList.Clear(); + m_noStrings = 0; } @@ -477,3 +507,91 @@ void wxChoice::ChangeForegroundColour() for (i = 0; i < m_noStrings; i++) DoChangeForegroundColour(m_widgetList[i], m_foregroundColour); } + + +// These implement functions needed by wxControlWithItems. +// Unfortunately, they're not all implemented yet. + +int wxChoice::GetCount() const +{ + return Number(); +} + +int wxChoice::DoAppend(const wxString& item) +{ + Append(item); + return GetCount() - 1; +} + +// Just appends, doesn't yet insert +void wxChoice::DoInsertItems(const wxArrayString& items, int WXUNUSED(pos)) +{ + size_t nItems = items.GetCount(); + + for ( size_t n = 0; n < nItems; n++ ) + { + Append( items[n]); + } +} + +void wxChoice::DoSetItems(const wxArrayString& items, void **WXUNUSED(clientData)) +{ + Clear(); + size_t nItems = items.GetCount(); + + for ( size_t n = 0; n < nItems; n++ ) + { + Append(items[n]); + } +} + +void wxChoice::DoSetFirstItem(int WXUNUSED(n)) +{ + wxFAIL_MSG( wxT("wxChoice::DoSetFirstItem not implemented") ); +} + +void wxChoice::DoSetItemClientData(int n, void* clientData) +{ + wxNode *node = m_clientList.Nth( n ); + wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientData") ); + + node->SetData( (wxObject*) clientData ); +} + +void* wxChoice::DoGetItemClientData(int n) const +{ + wxNode *node = m_clientList.Nth( n ); + wxCHECK_MSG( node, NULL, wxT("invalid index in wxChoice::DoGetItemClientData") ); + + return node->Data(); +} + +void wxChoice::DoSetItemClientObject(int n, wxClientData* clientData) +{ + wxNode *node = m_clientList.Nth( n ); + wxCHECK_RET( node, wxT("invalid index in wxChoice::DoSetItemClientObject") ); + + wxClientData *cd = (wxClientData*) node->Data(); + delete cd; + + node->SetData( (wxObject*) clientData ); +} + +wxClientData* wxChoice::DoGetItemClientObject(int n) const +{ + wxNode *node = m_clientList.Nth( n ); + wxCHECK_MSG( node, (wxClientData *)NULL, + wxT("invalid index in wxChoice::DoGetItemClientObject") ); + + return (wxClientData*) node->Data(); +} + +void wxChoice::Select(int n) +{ + SetSelection(n); +} + +void wxChoice::SetString(int WXUNUSED(n), const wxString& WXUNUSED(s)) +{ + wxFAIL_MSG( wxT("wxChoice::SetString not implemented") ); +}