X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3727c043a846bed24554c47b723da9fbe3b9a010..cc1487e53905bd534dba2099d33ac2142cec7818:/src/stc/PlatWX.cpp diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 2e5309ef25..2e80894a47 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -6,12 +6,13 @@ #include -#include -#include -#include -#include -#include -#include +#include "wx/wx.h" +#include "wx/encconv.h" +#include "wx/listctrl.h" +#include "wx/mstream.h" +#include "wx/image.h" +#include "wx/imaglist.h" +#include "wx/tokenzr.h" #include "Platform.h" #include "PlatWX.h" @@ -46,14 +47,21 @@ wxColour wxColourFromCA(const ColourAllocated& ca) { Palette::Palette() { used = 0; allowRealization = false; + size = 100; + entries = new ColourPair[size]; } Palette::~Palette() { Release(); + delete [] entries; + entries = 0; } void Palette::Release() { used = 0; + delete [] entries; + size = 100; + entries = new ColourPair[size]; } // This method either adds a colour to the list of wanted colours (want==true) @@ -66,11 +74,20 @@ void Palette::WantFind(ColourPair &cp, bool want) { return; } - if (used < numEntries) { - entries[used].desired = cp.desired; - entries[used].allocated.Set(cp.desired.AsLong()); - used++; + if (used >= size) { + int sizeNew = size * 2; + ColourPair *entriesNew = new ColourPair[sizeNew]; + for (int j=0; jDrawRoundedRectangle(wxRectFromPRectangle(rc), 4); } +void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, + ColourAllocated fill, int alphaFill, + ColourAllocated outline, int alphaOutline, int flags) { +// ** TODO + + RectangleDraw(rc, outline, fill); +} + void SurfaceImpl::Ellipse(PRectangle rc, ColourAllocated fore, ColourAllocated back) { PenColour(fore); BrushColour(back); @@ -403,8 +430,12 @@ void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positio #else // If not unicode then just use the widths we have +#if wxUSE_STL + std::copy(tpos.begin(), tpos.end(), positions); +#else memcpy(positions, tpos.begin(), len * sizeof(int)); #endif +#endif } @@ -538,13 +569,11 @@ void Window::Show(bool show) { void Window::InvalidateAll() { GETWIN(id)->Refresh(false); - wxWakeUpIdle(); } void Window::InvalidateRectangle(PRectangle rc) { wxRect r = wxRectFromPRectangle(rc); GETWIN(id)->Refresh(false, &r); - wxWakeUpIdle(); } void Window::SetFont(Font &font) { @@ -588,12 +617,16 @@ void Window::SetCursor(Cursor curs) { #else wxCursor wc = wxCursor(cursorId) ; #endif - GETWIN(id)->SetCursor(wc); + if(curs != cursorLast) + { + GETWIN(id)->SetCursor(wc); + cursorLast = curs; + } } void Window::SetTitle(const char *s) { - GETWIN(id)->SetTitle(stc2wx(s)); + GETWIN(id)->SetLabel(stc2wx(s)); } @@ -658,7 +691,7 @@ END_EVENT_TABLE() -#if wxUSE_POPUPWIN //----------------------------------- +#if wxUSE_POPUPWIN //----------------------------------- #include @@ -668,9 +701,9 @@ END_EVENT_TABLE() // 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: @@ -678,7 +711,7 @@ 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 @@ -694,7 +727,7 @@ public: // "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__ @@ -785,7 +818,7 @@ BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxPopupWindow) EVT_LIST_ITEM_ACTIVATED(wxID_ANY, wxSTCListBoxWin::OnActivate) END_EVENT_TABLE() - + #else // wxUSE_POPUPWIN ----------------------------------- @@ -796,8 +829,8 @@ private: 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, @@ -873,7 +906,7 @@ public: return rv; } #endif - + void OnActivate(wxListEvent& WXUNUSED(event)) { doubleClickAction(doubleClickActionData); } @@ -910,7 +943,8 @@ private: 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; @@ -919,13 +953,15 @@ public: ~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(); @@ -934,7 +970,7 @@ public: 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); }; @@ -962,11 +998,12 @@ void ListBoxImpl::SetFont(Font &font) { } -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); } @@ -982,10 +1019,14 @@ void ListBoxImpl::SetVisibleRows(int 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; + int maxw = maxStrWidth * aveCharWidth; int maxh ; // give it a default if there are no lines, and/or add a bit more @@ -1031,13 +1072,14 @@ void ListBoxImpl::Clear() { 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); @@ -1045,6 +1087,23 @@ void ListBoxImpl::Append(char *s, int 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(); @@ -1125,7 +1184,6 @@ void ListBoxImpl::SetDoubleClickAction(CallBackAction action, void *data) { } - ListBox::ListBox() { } @@ -1308,11 +1366,20 @@ int Platform::DBCSCharMaxLength() { //---------------------------------------------------------------------- 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; } @@ -1362,9 +1429,3 @@ const wxWX2MBbuf wx2stc(const wxString& str) } #endif - - - - - -