Page 2 of 2

Re: Which files I need to modify to customize wxOwnerDrawnComboBox?

Posted: Fri Oct 07, 2016 8:42 pm
by Tapsa
It appears to be enough to edit wxVListBoxComboPopup, merging some necessary drawing codes from wxOwnerDrawnComboBox.
Anyway, I've effectively completed my custom popup. It feels good and works well.

Re: Which files I need to modify to customize wxOwnerDrawnComboBox?

Posted: Fri Oct 07, 2016 9:40 pm
by PB
Congrats then. What did you end up using as a combo box class then? I was rather annoyed noticing that wxComboCtrl does not support keyboard navigation on its own, all the code necessary is added in the wxOwnerDrawnComboBox.

Re: Which files I need to modify to customize wxOwnerDrawnComboBox?

Posted: Sat Oct 08, 2016 6:57 am
by Tapsa
Here are my combo popup codes:
SharedComboPopup.h
SharedComboPopup.cpp

This is my combo box class stripped down:

Code: Select all

class AGEComboBox: public wxComboCtrl
{
public:
    AGEComboBox(wxWindow *parent, wxArrayString *choices, int width):
    wxComboCtrl(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, -1), wxTE_PROCESS_ENTER)
    {
        popup = new SharedComboPopup();
        SetPopupControl(popup);
        popup->Imbue(choices);
        Bind(wxEVT_MOUSEWHEEL, [=](wxMouseEvent &event){GetParent()->GetEventHandler()->ProcessEvent(event);});
    }
    unsigned int GetCount() const {return popup->GetCount();}
    void SetSelection(int n)
    {
        wxString str;
        if(GetCount())
        {
            popup->SetSelection(n);
            if(n >= 0)
            {
                str = popup->GetString(n);
            }
        }
        // Refresh text portion in control
        if(m_text)
            m_text->ChangeValue(str);
        else
            m_valueString = str;
        Refresh();
    }
    int GetSelection() const {return popup->GetSelection();}
    void Flash() {popup->Flash();}
    void SwapList(wxArrayString *choices) {popup->Imbue(choices);}

protected:
    SharedComboPopup *popup;
};
I hope this helps anyone looking for a virtual combo box in wx.