#include "wx/mstream.h"
#include "wx/image.h"
#include "wx/imaglist.h"
+#include "wx/tokenzr.h"
#include "Platform.h"
#include "PlatWX.h"
// so we adjust the encoding before passing it to Scintilla. See also
// wxStyledTextCtrl::StyleSetCharacterSet
wxFontEncoding encoding = (wxFontEncoding)(characterSet-1);
-
+
wxFontEncodingArray ea = wxEncodingConverter::GetPlatformEquivalents(encoding);
if (ea.GetCount())
encoding = ea[0];
-#if wxUSE_POPUPWIN //-----------------------------------
+#if wxUSE_POPUPWIN //-----------------------------------
#include <wx/popupwin.h>
// implement wxPopupWindow for the Mac!!)
//
// In the meantime, be careful to duplicate any changes as needed...
-//
-
-// A popup window to place the wxSTCListBox upon
+//
+
+// A popup window to place the wxSTCListBox upon
class wxSTCListBoxWin : public wxPopupWindow
{
private:
CallBackAction doubleClickAction;
void* doubleClickActionData;
public:
- wxSTCListBoxWin(wxWindow* parent, wxWindowID id) :
+ wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) :
wxPopupWindow(parent, wxBORDER_NONE)
{
SetBackgroundColour(*wxBLACK); // for our simple border
// "right" to the user. But since the wxPopupWindow or its children
// can't receive focus then we have to pull a fast one and temporarily
// parent the listctrl on the STC window and then call SetFocus and
- // then reparent it back to the popup.
+ // then reparent it back to the popup.
lv->SetFocus();
lv->Reparent(this);
#ifdef __WXMSW__
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, wxSTCListBoxWin::OnActivate)
END_EVENT_TABLE()
-
+
#else // wxUSE_POPUPWIN -----------------------------------
CallBackAction doubleClickAction;
void* doubleClickActionData;
public:
- wxSTCListBoxWin(wxWindow* parent, wxWindowID id) :
- wxWindow(parent, id, wxDefaultPosition, wxSize(0,0), wxSIMPLE_BORDER )
+ wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point location) :
+ wxWindow(parent, id, wxPoint(location.x, location.y), wxSize(0,0), wxSIMPLE_BORDER )
{
lv = new wxSTCListBox(this, id, wxDefaultPosition, wxDefaultSize,
return rv;
}
#endif
-
+
void OnActivate(wxListEvent& WXUNUSED(event)) {
doubleClickAction(doubleClickActionData);
}
bool unicodeMode;
int desiredVisibleRows;
int aveCharWidth;
- int maxStrWidth;
+ size_t maxStrWidth;
+ Point location; // Caret location at which the list is opened
wxImageList* imgList;
wxArrayInt* imgTypeMap;
~ListBoxImpl();
virtual void SetFont(Font &font);
- virtual void Create(Window &parent, int ctrlID, int lineHeight_, bool unicodeMode_);
+ virtual void Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_);
virtual void SetAverageCharWidth(int width);
virtual void SetVisibleRows(int rows);
+ virtual int GetVisibleRows() const;
virtual PRectangle GetDesiredRect();
virtual int CaretFromEdge();
virtual void Clear();
virtual void Append(char *s, int type = -1);
+ void Append(const wxString& text, int type);
virtual int Length();
virtual void Select(int n);
virtual int GetSelection();
virtual void RegisterImage(int type, const char *xpm_data);
virtual void ClearRegisteredImages();
virtual void SetDoubleClickAction(CallBackAction, void *);
-
+ virtual void SetList(const char* list, char separator, char typesep);
};
}
-void ListBoxImpl::Create(Window &parent, int ctrlID, int lineHeight_, bool unicodeMode_) {
+void ListBoxImpl::Create(Window &parent, int ctrlID, Point location_, int lineHeight_, bool unicodeMode_) {
+ location = location_;
lineHeight = lineHeight_;
unicodeMode = unicodeMode_;
maxStrWidth = 0;
- id = new wxSTCListBoxWin(GETWIN(parent.GetID()), ctrlID);
+ id = new wxSTCListBoxWin(GETWIN(parent.GetID()), ctrlID, location);
if (imgList != NULL)
GETLB(id)->SetImageList(imgList, wxIMAGE_LIST_SMALL);
}
}
+int ListBoxImpl::GetVisibleRows() const {
+ return desiredVisibleRows;
+}
+
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 maxw = maxStrWidth * aveCharWidth;
int maxh ;
// give it a default if there are no lines, and/or add a bit more
void ListBoxImpl::Append(char *s, int type) {
- wxString text = stc2wx(s);
+ Append(stc2wx(s), type);
+}
+
+void ListBoxImpl::Append(const wxString& text, int type) {
long count = GETLB(id)->GetItemCount();
long itemID = GETLB(id)->InsertItem(count, wxEmptyString);
GETLB(id)->SetItem(itemID, 1, text);
- int itemWidth = 0;
- GETLB(id)->GetTextExtent(text, &itemWidth, NULL);
- maxStrWidth = wxMax(maxStrWidth, itemWidth);
+ maxStrWidth = wxMax(maxStrWidth, text.length());
if (type != -1) {
wxCHECK_RET(imgTypeMap, wxT("Unexpected NULL imgTypeMap"));
long idx = imgTypeMap->Item(type);
}
}
+void ListBoxImpl::SetList(const char* list, char separator, char typesep) {
+ GETLB(id)->Freeze();
+ Clear();
+ wxStringTokenizer tkzr(stc2wx(list), (wxChar)separator);
+ while ( tkzr.HasMoreTokens() ) {
+ wxString token = tkzr.GetNextToken();
+ long type = -1;
+ int pos = token.Find(typesep);
+ if (pos != -1) {
+ token.Mid(pos+1).ToLong(&type);
+ token.Truncate(pos);
+ }
+ Append(token, (int)type);
+ }
+ GETLB(id)->Thaw();
+}
+
int ListBoxImpl::Length() {
return GETLB(id)->GetItemCount();
}
-
ListBox::ListBox() {
}
//----------------------------------------------------------------------
ElapsedTime::ElapsedTime() {
- wxStartTimer();
+ wxLongLong localTime = wxGetLocalTimeMillis();
+ littleBit = localTime.GetLo();
+ bigBit = localTime.GetHi();
}
double ElapsedTime::Duration(bool reset) {
- double result = wxGetElapsedTime(reset);
+ wxLongLong prevTime(bigBit, littleBit);
+ wxLongLong localTime = wxGetLocalTimeMillis();
+ if(reset) {
+ littleBit = localTime.GetLo();
+ bigBit = localTime.GetHi();
+ }
+ wxLongLong duration = localTime - prevTime;
+ double result = duration.ToDouble();
result /= 1000.0;
return result;
}
}
#endif
-
-
-
-
-
-