📄 platwx.cpp
字号:
int lineHeight; bool unicodeMode; int desiredVisibleRows; int aveCharWidth; size_t maxStrWidth; Point location; // Caret location at which the list is opened wxImageList* imgList; wxArrayInt* imgTypeMap;public: ListBoxImpl(); ~ListBoxImpl(); virtual void SetFont(Font &font); 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); virtual void Append(const wxString& text, int type); 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 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);};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, Point location_, int lineHeight_, bool unicodeMode_) { lineHeight = lineHeight_; unicodeMode = unicodeMode_; maxStrWidth = 0; id = new wxSCIListBoxWin (GETWIN(parent.GetID()), ctrlID, location_); if (imgList != NULL) GETLB(id)->SetImageList (imgList, wxIMAGE_LIST_SMALL);}void ListBoxImpl::SetAverageCharWidth(int width) { aveCharWidth = width;}void ListBoxImpl::SetVisibleRows(int rows) { desiredVisibleRows = rows;}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 * aveCharWidth; int maxh ; // 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;}int ListBoxImpl::CaretFromEdge() { return 4 + GETLBW(id)->IconWidth();}void ListBoxImpl::Clear() { GETLB(id)->DeleteAllItems();}void ListBoxImpl::Append(char *s, int type) { Append(sci2wx(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); maxStrWidth = wxMax(maxStrWidth, text.length()); if (type != -1) { wxCHECK_RET(imgTypeMap, wxT("Unexpected NULL imgTypeMap")); long idx = imgTypeMap->Item(type); GETLB(id)->SetItemImage(itemID, idx, idx); }}int ListBoxImpl::Length() { return GETLB(id)->GetItemCount();}void ListBoxImpl::Select(int n) { bool select = true; if (n == -1) { n = 0; select = FALSE; } GETLB(id)->Focus(n); GETLB(id)->Select(n, select);}int ListBoxImpl::GetSelection() { return GETLB(id)->GetFirstSelected();}int ListBoxImpl::Find(const char *WXUNUSED(prefix)) { // No longer used return wxNOT_FOUND;}void ListBoxImpl::GetValue(int n, char *value, int len) { wxListItem item; item.SetId(n); item.SetColumn(1); item.SetMask(wxLIST_MASK_TEXT); GETLB(id)->GetItem(item); strncpy(value, wx2sci(item.GetText()), len); value[len-1] = '\0';}void ListBoxImpl::RegisterImage(int type, const char *xpm_data) { wxMemoryInputStream stream(xpm_data, strlen(xpm_data)+1); wxImage img(stream, wxBITMAP_TYPE_XPM); wxBitmap bmp(img); if (! imgList) { // assumes all images are the same size imgList = new wxImageList(bmp.GetWidth(), bmp.GetHeight(), true); imgTypeMap = new wxArrayInt; } int idx = imgList->Add(bmp); // do we need to extend the mapping array? wxArrayInt& itm = *imgTypeMap; if ( itm.GetCount() < (size_t)type+1) itm.Add(-1, type - itm.GetCount() + 1); // Add an item that maps type to the image index itm[type] = idx;}void ListBoxImpl::ClearRegisteredImages() { if (imgList) { delete imgList; imgList = NULL; } if (imgTypeMap) { delete imgTypeMap; imgTypeMap = NULL; } if (id) GETLB(id)->SetImageList(NULL, wxIMAGE_LIST_SMALL);}void ListBoxImpl::SetDoubleClickAction(CallBackAction action, void *data) { GETLBW(id)->SetDoubleClickAction(action, data);}void ListBoxImpl::SetList(const char* list, char separator, char typesep) { GETLB(id)->Freeze(); Clear(); wxStringTokenizer tkzr(sci2wx(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();}ListBox::ListBox() {}ListBox::~ListBox() {}ListBox *ListBox::Allocate() { return new ListBoxImpl();}//----------------------------------------------------------------------Menu::Menu() : id(0) {}void Menu::CreatePopUp() { Destroy(); id = new wxMenu();}void Menu::Destroy() { if (id) delete (wxMenu*)id; id = 0;}void Menu::Show(Point pt, Window &w) { GETWIN(w.GetID())->PopupMenu((wxMenu*)id, pt.x - 4, pt.y); Destroy();}//----------------------------------------------------------------------DynamicLibrary *DynamicLibrary::Load(const char *WXUNUSED(modulePath)) { wxFAIL_MSG(wxT("Dynamic lexer loading not implemented yet")); return NULL;}//----------------------------------------------------------------------ColourDesired Platform::Chrome() { wxColour c; c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); return ColourDesired(c.Red(), c.Green(), c.Blue());}ColourDesired Platform::ChromeHighlight() { wxColour c; c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT); return ColourDesired(c.Red(), c.Green(), c.Blue());}const char *Platform::DefaultFont() { static char buf[128]; strcpy(buf, wxNORMAL_FONT->GetFaceName().mbc_str()); return buf;}int Platform::DefaultFontSize() { return wxNORMAL_FONT->GetPointSize();}unsigned int Platform::DoubleClickTime() { return 500; // **** ::GetDoubleClickTime();}bool Platform::MouseButtonBounce() { return FALSE;}void Platform::DebugDisplay(const char *s) { wxLogDebug(sci2wx(s));}bool Platform::IsKeyDown(int WXUNUSED(key)) { return false; // I don't think we'll need this.}long Platform::SendScintilla(WindowID w, unsigned int msg, unsigned long wParam, long lParam) { wxScintilla* sci = (wxScintilla*)w; return sci->SendMsg(msg, wParam, lParam);}long Platform::SendScintillaPointer(WindowID w, unsigned int msg, unsigned long wParam, void *lParam) { wxScintilla* sci = (wxScintilla*)w; return sci->SendMsg(msg, wParam, (long)lParam);}// These are utility functions not really tied to a platformint Platform::Minimum(int a, int b) { if (a < b) return a; else return b;}int Platform::Maximum(int a, int b) { if (a > b) return a; else return b;}#define TRACEvoid Platform::DebugPrintf(const char *format, ...) {#ifdef TRACE char buffer[2000]; va_list pArguments; va_start(pArguments, format); vsprintf(buffer,format,pArguments); va_end(pArguments); Platform::DebugDisplay(buffer);#endif}static bool assertionPopUps = true;bool Platform::ShowAssertionPopUps(bool assertionPopUps_) { bool ret = assertionPopUps; assertionPopUps = assertionPopUps_; return ret;}void Platform::Assert(const char *c, const char *file, int line) { char buffer[2000]; sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line); if (assertionPopUps) { /*int idButton = */ wxMessageBox(sci2wx(buffer), wxT("Assertion failure"), wxICON_HAND | wxOK);// if (idButton == IDRETRY) {// ::DebugBreak();// } else if (idButton == IDIGNORE) {// // all OK// } else {// abort();// } } else { strcat(buffer, "\r\n"); Platform::DebugDisplay(buffer); abort(); }}int Platform::Clamp(int val, int minVal, int maxVal) { if (val > maxVal) val = maxVal; if (val < minVal) val = minVal; return val;}bool Platform::IsDBCSLeadByte(int WXUNUSED(codePage), char WXUNUSED(ch)) { return false;}int Platform::DBCSCharLength(int WXUNUSED(codePage), const char *WXUNUSED(s)) { return 1;}int Platform::DBCSCharMaxLength() { return 1;}//----------------------------------------------------------------------ElapsedTime::ElapsedTime() { wxLongLong localTime = wxGetLocalTimeMillis(); littleBit = localTime.GetLo(); bigBit = localTime.GetHi();}double ElapsedTime::Duration(bool 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;}//----------------------------------------------------------------------#if wxUSE_UNICODE#include "UniConversion.h"// Convert using Scintilla's functions instead of wx's, Scintilla's are more// forgiving and won't assert...wxString sci2wx(const char* str, size_t len){ if (!len) return wxEmptyString; size_t wclen = UCS2Length(str, len); wxWCharBuffer buffer(wclen+1); size_t actualLen = UCS2FromUTF8(str, len, buffer.data(), wclen+1); return wxString(buffer.data(), actualLen);}const wxWX2MBbuf wx2stc(const wxString& str){ const wchar_t* wcstr = str.c_str(); size_t wclen = str.length(); size_t len = UTF8Length(wcstr, wclen); wxCharBuffer buffer(len+1); UTF8FromUCS2(wcstr, wclen, buffer.data(), len); // TODO check NULL termination!! return buffer;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -