+inline wxListView* GETLB(WindowID win) {
+ return GETLBW(win)->GetLB();
+}
+
+//----------------------------------------------------------------------
+
+class ListBoxImpl : public ListBox {
+private:
+ int lineHeight;
+ bool unicodeMode;
+ int desiredVisibleRows;
+ int aveCharWidth;
+ int maxStrWidth;
+ wxImageList* imgList;
+ wxArrayInt* imgTypeMap;
+
+public:
+ ListBoxImpl();
+ ~ListBoxImpl();
+
+ virtual void SetFont(Font &font);
+ virtual void Create(Window &parent, int ctrlID, int lineHeight_, bool unicodeMode_);
+ virtual void SetAverageCharWidth(int width);
+ virtual void SetVisibleRows(int rows);
+ virtual PRectangle GetDesiredRect();
+ virtual int CaretFromEdge();
+ virtual void Clear();
+ virtual void Append(char *s, int type = -1);
+ virtual int Length();
+ virtual void Select(int n);
+ virtual int GetSelection();
+ virtual int Find(const char *prefix);
+ virtual void GetValue(int n, char *value, int len);
+ virtual void Sort();
+ virtual void RegisterImage(int type, const char *xpm_data);
+ virtual void ClearRegisteredImages();
+ virtual void SetDoubleClickAction(CallBackAction, void *);
+
+};
+
+
+ListBoxImpl::ListBoxImpl()
+ : lineHeight(10), unicodeMode(false),
+ desiredVisibleRows(5), aveCharWidth(8), maxStrWidth(0),
+ imgList(NULL), imgTypeMap(NULL)
+{
+}
+
+ListBoxImpl::~ListBoxImpl() {
+ if (imgList) {
+ delete imgList;
+ imgList = NULL;
+ }
+ if (imgTypeMap) {
+ delete imgTypeMap;
+ imgTypeMap = NULL;
+ }
+}
+
+
+void ListBoxImpl::SetFont(Font &font) {
+ GETLB(id)->SetFont(*((wxFont*)font.GetID()));
+}
+
+
+void ListBoxImpl::Create(Window &parent, int ctrlID, int lineHeight_, bool unicodeMode_) {
+ lineHeight = lineHeight_;
+ unicodeMode = unicodeMode_;
+ maxStrWidth = 0;
+ id = new wxSTCListBoxWin(GETWIN(parent.GetID()), ctrlID);
+ if (imgList != NULL)
+ GETLB(id)->SetImageList(imgList, wxIMAGE_LIST_SMALL);
+}
+
+
+void ListBoxImpl::SetAverageCharWidth(int width) {
+ aveCharWidth = width;
+}
+
+
+void ListBoxImpl::SetVisibleRows(int rows) {
+ desiredVisibleRows = rows;
+}
+
+
+PRectangle ListBoxImpl::GetDesiredRect() {
+ // wxListCtrl doesn't have a DoGetBestSize, so instead we kept track of
+ // the max size in Append and calculate it here...
+ int maxw = maxStrWidth;
+ int maxh = 0;
+
+ // give it a default if there are no lines, and/or add a bit more
+ if (maxw == 0) maxw = 100;
+ maxw += aveCharWidth * 3 +
+ GETLBW(id)->IconWidth() + wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
+ if (maxw > 350)
+ maxw = 350;
+
+ // estimate a desired height
+ int count = GETLB(id)->GetItemCount();
+ if (count) {
+ wxRect rect;
+ GETLB(id)->GetItemRect(0, rect);
+ maxh = count * rect.GetHeight();
+ if (maxh > 140) // TODO: Use desiredVisibleRows??
+ maxh = 140;
+
+ // Try to make the size an exact multiple of some number of lines
+ int lines = maxh / rect.GetHeight();
+ maxh = (lines + 1) * rect.GetHeight() + 2;
+ }
+ else
+ maxh = 100;
+
+ PRectangle rc;
+ rc.top = 0;
+ rc.left = 0;
+ rc.right = maxw;
+ rc.bottom = maxh;
+ return rc;