+
+// This is a simple subclass of wxListView that just resets focus to the
+// parent when it gets it.
+class wxSTCListBox : public wxListView {
+public:
+ wxSTCListBox(wxWindow* parent, wxWindowID id,
+ const wxPoint& pos, const wxSize& size,
+ long style)
+ : wxListView(parent, id, pos, size, style)
+ {}
+
+ void OnFocus(wxFocusEvent& event) {
+ GetParent()->SetFocus();
+ event.Skip();
+ }
+
+ void OnKillFocus(wxFocusEvent& event) {
+ // Do nothing. Prevents base class from resetting the colors...
+ }
+
+private:
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxSTCListBox, wxListView)
+ EVT_SET_FOCUS( wxSTCListBox::OnFocus)
+ EVT_KILL_FOCUS(wxSTCListBox::OnKillFocus)
+END_EVENT_TABLE()
+
+
+
+
+// A window to place the wxSTCListBox upon
+class wxSTCListBoxWin : public wxWindow {
+private:
+ wxListView* lv;
+ CallBackAction doubleClickAction;
+ void* doubleClickActionData;
+public:
+ wxSTCListBoxWin(wxWindow* parent, wxWindowID id) :
+ wxWindow(parent, id, wxDefaultPosition, wxSize(0,0), wxNO_BORDER )
+ {
+
+ SetBackgroundColour(*wxBLACK);
+ lv = new wxSTCListBox(this, id, wxDefaultPosition, wxDefaultSize,
+ wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxNO_BORDER);
+ lv->SetCursor(wxCursor(wxCURSOR_ARROW));
+ lv->InsertColumn(0, wxEmptyString);
+ lv->InsertColumn(1, wxEmptyString);
+
+ // Eventhough we immediately reset the focus to the parent, this helps
+ // things to look right...
+ lv->SetFocus();
+
+ Hide();
+ }
+
+
+ // On OSX and (possibly others) there can still be pending
+ // messages/events for the list control when Scintilla wants to
+ // close it, so do a pending delete of it instead of destroying
+ // immediately.
+ bool Destroy() {
+ if ( !wxPendingDelete.Member(this) )
+ wxPendingDelete.Append(this);
+ return TRUE;
+ }
+
+
+ int IconWidth() {
+ wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL);
+ if (il != NULL) {
+ int w, h;
+ il->GetSize(0, w, h);
+ return w;
+ }
+ return 0;
+ }
+
+
+ void SetDoubleClickAction(CallBackAction action, void *data) {
+ doubleClickAction = action;
+ doubleClickActionData = data;
+ }
+
+
+ void OnFocus(wxFocusEvent& event) {
+ GetParent()->SetFocus();
+ event.Skip();
+ }
+
+ void OnSize(wxSizeEvent& event) {
+ // resize the child, leaving a 1 pixel border
+ wxSize sz = GetClientSize();
+ lv->SetSize(1, 1, sz.x-2, sz.y-2);
+ // reset the column widths
+ lv->SetColumnWidth(0, IconWidth()+4);
+ lv->SetColumnWidth(1, sz.x - 2 - lv->GetColumnWidth(0) -
+ wxSystemSettings::GetMetric(wxSYS_VSCROLL_X));
+ event.Skip();
+ }
+
+ void OnActivate(wxListEvent& event) {
+ doubleClickAction(doubleClickActionData);
+ }
+
+ wxListView* GetLB() { return lv; }
+
+private:
+ DECLARE_EVENT_TABLE()
+};
+
+
+BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxWindow)
+ EVT_SET_FOCUS ( wxSTCListBoxWin::OnFocus)
+ EVT_SIZE ( wxSTCListBoxWin::OnSize)
+ EVT_LIST_ITEM_ACTIVATED(-1, wxSTCListBoxWin::OnActivate)
+END_EVENT_TABLE()
+
+
+
+inline wxSTCListBoxWin* GETLBW(WindowID win) {
+ return ((wxSTCListBoxWin*)win);