X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8704bf74fba8523e2e174bd5a8195b5202009cd0..184b5d99a5382cd7a19888c85aff11f8a21af2f6:/src/motif/combobox.cpp?ds=inline diff --git a/src/motif/combobox.cpp b/src/motif/combobox.cpp index 305a39a2b9..4537779eb6 100644 --- a/src/motif/combobox.cpp +++ b/src/motif/combobox.cpp @@ -40,6 +40,8 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetValidator(validator); m_noStrings = n; m_windowStyle = style; + m_backgroundColour = parent->GetBackgroundColour(); + m_foregroundColour = parent->GetForegroundColour(); if (parent) parent->AddChild(this); @@ -81,15 +83,30 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, SetValue(value); + m_windowFont = parent->GetFont(); + ChangeFont(FALSE); + SetCanAddEventHandler(TRUE); AttachWidget (parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y); - SetFont(* parent->GetFont()); - ChangeColour(m_mainWidget); + ChangeBackgroundColour(); return TRUE; } +wxComboBox::~wxComboBox() +{ + DetachWidget((Widget) m_mainWidget); // Removes event handlers + XtDestroyWidget((Widget) m_mainWidget); + m_mainWidget = (WXWidget) 0; +} + +void wxComboBox::SetSize(int x, int y, int width, int height, int sizeFlags) +{ + // Necessary so it doesn't call wxChoice::SetSize + wxWindow::SetSize(x, y, width, height, sizeFlags); +} + wxString wxComboBox::GetValue() const { char *s = XmComboBoxGetString ((Widget) m_mainWidget); @@ -111,6 +128,97 @@ void wxComboBox::SetValue(const wxString& value) m_inSetValue = FALSE; } +void wxComboBox::Append(const wxString& item) +{ + XmString str = XmStringCreateLtoR((char*) (const char*) item, XmSTRING_DEFAULT_CHARSET); + XmComboBoxAddItem((Widget) m_mainWidget, str, 0); + m_stringList.Add(item); + XmStringFree(str); + m_noStrings ++; +} + +void wxComboBox::Delete(int n) +{ + XmComboBoxDeletePos((Widget) m_mainWidget, n-1); + wxNode *node = m_stringList.Nth(n); + if (node) + { + delete[] (char *)node->Data(); + delete node; + } + m_noStrings--; +} + +void wxComboBox::Clear() +{ + XmComboBoxDeleteAllItems((Widget) m_mainWidget); + m_stringList.Clear(); +} + +void wxComboBox::SetSelection (int n) +{ + XmComboBoxSelectPos((Widget) m_mainWidget, n+1, False); +} + +int wxComboBox::GetSelection (void) const +{ + int sel = XmComboBoxGetSelectedPos((Widget) m_mainWidget); + if (sel == 0) + return -1; + else + return sel - 1; +} + +wxString wxComboBox::GetString(int n) const +{ + wxNode *node = m_stringList.Nth (n); + if (node) + return wxString((char *) node->Data ()); + else + return wxEmptyString; +} + +wxString wxComboBox::GetStringSelection() const +{ + int sel = GetSelection(); + if (sel == -1) + return wxEmptyString; + else + return GetString(sel); +} + +bool wxComboBox::SetStringSelection(const wxString& sel) +{ + int n = FindString(sel); + if (n == -1) + return FALSE; + else + { + SetSelection(n); + return TRUE; + } +} + +int wxComboBox::FindString(const wxString& s) const +{ + int *pos_list = NULL; + int count = 0; + XmString text = XmStringCreateSimple ((char*) (const char*) s); + bool found = (XmComboBoxGetMatchPos((Widget) m_mainWidget, + text, &pos_list, &count) != 0); + + XmStringFree(text); + + if (found && count > 0) + { + int pos = pos_list[0] - 1; + free(pos_list); + return pos; + } + + return -1; +} + // Clipboard operations void wxComboBox::Copy() { @@ -127,7 +235,7 @@ void wxComboBox::Paste() XmComboBoxPaste((Widget) m_mainWidget); } -void wxComboBox::SetEditable(bool editable) +void wxComboBox::SetEditable(bool WXUNUSED(editable)) { // TODO } @@ -172,7 +280,7 @@ void wxComboBox::SetSelection(long from, long to) (Time) 0); } -void wxComboBoxCallback (Widget w, XtPointer clientData, +void wxComboBoxCallback (Widget WXUNUSED(w), XtPointer clientData, XmComboBoxSelectionCallbackStruct * cbs) { wxComboBox *item = (wxComboBox *) clientData; @@ -205,5 +313,21 @@ void wxComboBoxCallback (Widget w, XtPointer clientData, } } +void wxComboBox::ChangeFont(bool keepOriginalSize) +{ + // Don't use the base class wxChoice's ChangeFont + wxWindow::ChangeFont(keepOriginalSize); +} + +void wxComboBox::ChangeBackgroundColour() +{ + wxWindow::ChangeBackgroundColour(); +} + +void wxComboBox::ChangeForegroundColour() +{ + wxWindow::ChangeBackgroundColour(); +} + #endif