diff options
Diffstat (limited to 'wx+')
-rw-r--r-- | wx+/button.h | 4 | ||||
-rw-r--r-- | wx+/graph.cpp | 18 | ||||
-rw-r--r-- | wx+/grid.cpp | 36 | ||||
-rw-r--r-- | wx+/grid.h | 2 | ||||
-rw-r--r-- | wx+/zlib_wrap.h | 4 |
5 files changed, 40 insertions, 24 deletions
diff --git a/wx+/button.h b/wx+/button.h index 6aba0788..5a704840 100644 --- a/wx+/button.h +++ b/wx+/button.h @@ -24,9 +24,9 @@ public: const wxValidator& validator = wxDefaultValidator, const wxString& name = wxButtonNameStr); - void setBitmapFront(const wxBitmap& bitmap, size_t spaceAfter = 0); + void setBitmapFront(const wxBitmap& bitmap, size_t spaceAfter = 0); //...and enlarge button if required! void setTextLabel( const wxString& text); - void setBitmapBack( const wxBitmap& bitmap, size_t spaceBefore = 0); + void setBitmapBack( const wxBitmap& bitmap, size_t spaceBefore = 0); // private: wxBitmap createBitmapFromText(const wxString& text); diff --git a/wx+/graph.cpp b/wx+/graph.cpp index a50f3c34..6fefeb93 100644 --- a/wx+/graph.cpp +++ b/wx+/graph.cpp @@ -98,7 +98,7 @@ void drawYLabel(wxDC& dc, double& yMin, double& yMax, const wxRect& clientArea, int optimalBlockHeight = 3 * dc.GetMultiLineTextExtent(L"1").GetHeight(); - double valRangePerBlock = (yMax - yMin) * optimalBlockHeight / clientArea.GetHeight(); + double valRangePerBlock = (yMax - yMin) * optimalBlockHeight / clientArea.GetHeight(); //proposal valRangePerBlock = labelFmt.getOptimalBlockSize(valRangePerBlock); if (isNull(valRangePerBlock)) return; @@ -150,7 +150,7 @@ void drawXLabel(wxDC& dc, double& xMin, double& xMax, const wxRect& clientArea, const int optimalBlockWidth = dc.GetMultiLineTextExtent(L"100000000000000").GetWidth(); - double valRangePerBlock = (xMax - xMin) * optimalBlockWidth / clientArea.GetWidth(); + double valRangePerBlock = (xMax - xMin) * optimalBlockWidth / clientArea.GetWidth(); //proposal valRangePerBlock = labelFmt.getOptimalBlockSize(valRangePerBlock); if (isNull(valRangePerBlock)) return; @@ -224,13 +224,11 @@ void subsample(StdCont& cont, size_t factor) { if (factor <= 1) return; - typedef typename StdCont::iterator IterType; + auto iterOut = cont.begin(); + for (auto iterIn = cont.begin(); cont.end() - iterIn >= static_cast<ptrdiff_t>(factor); iterIn += factor) //don't even let iterator point out of range! + *iterOut++ = std::accumulate(iterIn, iterIn + factor, 0.0) / static_cast<double>(factor); - IterType posWrite = cont.begin(); - for (IterType posRead = cont.begin(); cont.end() - posRead >= static_cast<int>(factor); posRead += factor) //don't even let iterator point out of range! - *posWrite++ = std::accumulate(posRead, posRead + factor, 0.0) / static_cast<double>(factor); - - cont.erase(posWrite, cont.end()); + cont.erase(iterOut, cont.end()); } } @@ -542,11 +540,11 @@ void Graph2D::render(wxDC& dc) const for (GraphList::const_iterator j = curves_.begin(); j != curves_.end(); ++j) { std::vector<double>& yValues = yValuesList[j - curves_.begin()].first; //actual y-values - int offset = yValuesList[j - curves_.begin()].second; //x-value offset in pixel + int offsetX = yValuesList[j - curves_.begin()].second; //x-value offset in pixel std::vector<wxPoint> curve; for (std::vector<double>::const_iterator i = yValues.begin(); i != yValues.end(); ++i) - curve.push_back(wxPoint(i - yValues.begin() + offset, + curve.push_back(wxPoint(i - yValues.begin() + offsetX, dataArea.height - 1 - cvrtY.realToScreen(*i)) + dataOrigin); //screen y axis starts upper left if (!curve.empty()) diff --git a/wx+/grid.cpp b/wx+/grid.cpp index 9f94b7f0..22a8bba1 100644 --- a/wx+/grid.cpp +++ b/wx+/grid.cpp @@ -251,6 +251,18 @@ void drawTextLabelFitting(wxDC& dc, const wxString& text, const wxRect& rect, in { DcClipper clip(dc, rect); //wxDC::DrawLabel doesn't care about width, WTF? + /* + performance notes: + wxDC::DrawLabel() is implemented in terms of both wxDC::GetMultiLineTextExtent() and wxDC::DrawText() + wxDC::GetMultiLineTextExtent() is implemented in terms of wxDC::GetTextExtent() + + average total times: + Windows Linux + single wxDC::DrawText() 7µs 50µs + wxDC::DrawLabel() + 10µs 90µs + repeated GetTextExtent() + */ + //truncate large texts and add ellipsis auto textFits = [&](const wxString& phrase) { return dc.GetTextExtent(phrase).GetWidth() <= rect.GetWidth(); }; dc.DrawLabel(getTruncatedText(text, textFits), rect, alignment); @@ -355,9 +367,9 @@ public: Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(SubWindow::onLeaveWindow ), nullptr, this); Connect(wxEVT_MOUSE_CAPTURE_LOST, wxMouseCaptureLostEventHandler(SubWindow::onMouseCaptureLost), nullptr, this); - Connect(wxEVT_CHAR, wxKeyEventHandler(SubWindow::onChar ), nullptr, this); - Connect(wxEVT_KEY_UP, wxKeyEventHandler(SubWindow::onKeyUp ), nullptr, this); - Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(SubWindow::onKeyDown), nullptr, this); + Connect(wxEVT_CHAR, wxKeyEventHandler(SubWindow::onChar ), nullptr, this); + Connect(wxEVT_KEY_UP, wxKeyEventHandler(SubWindow::onKeyUp ), nullptr, this); + Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(SubWindow::onKeyDown), nullptr, this); } Grid& refParent() { return parent_; } @@ -385,8 +397,8 @@ protected: { //wxWidgets bug: tooltip multiline property is defined by first tooltip text containing newlines or not (same is true for maximum width) if (!tt) - SetToolTip(new wxToolTip(wxT("a b\n\ - a b"))); //ugly, but is working (on Windows) + SetToolTip(new wxToolTip(L"a b\n\ + a b")); //ugly, but is working (on Windows) tt = GetToolTip(); //should be bound by now if (tt) tt->SetTip(text); @@ -966,6 +978,7 @@ private: const int rowHeight = rowLabelWin_.getRowHeight(); + //why again aren't we using RowLabelWin::getRowsOnClient() here? const wxPoint topLeft = refParent().CalcUnscrolledPosition(rect.GetTopLeft()); const wxPoint bottomRight = refParent().CalcUnscrolledPosition(rect.GetBottomRight()); @@ -990,10 +1003,10 @@ private: drawBackground(*prov, dc, wxRect(cellAreaTL + wxPoint(0, row * rowHeight), wxSize(compWidth, rowHeight)), row, compPos); } - //draw single cells + //draw single cells, column by column for (auto iterCol = iterComp->begin(); iterCol != iterComp->end(); ++iterCol) { - const int width = iterCol->width_; //don't use unsigned for calculations! + const int width = iterCol->width_; //don't use unsigned for calculations! if (cellAreaTL.x > rect.GetRight()) return; //done @@ -1629,6 +1642,9 @@ void Grid::scrollDelta(int deltaX, int deltaY) scrollPosX += deltaX; scrollPosY += deltaY; + scrollPosX = std::max(0, scrollPosX); //wxScrollHelper::Scroll() will exit prematurely if input happens to be "-1"! + scrollPosY = std::max(0, scrollPosY); // + //const int unitsTotalX = GetScrollLines(wxHORIZONTAL); //const int unitsTotalY = GetScrollLines(wxVERTICAL); @@ -1819,7 +1835,9 @@ void Grid::SetScrollbar(int orientation, int position, int thumbSize, int range, WXLRESULT Grid::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { - if (nMsg == WM_MOUSEHWHEEL) + //we land here if wxWindowMSW::MSWWindowProc() couldn't handle the message + //http://msdn.microsoft.com/en-us/library/windows/desktop/ms645614(v=vs.85).aspx + if (nMsg == WM_MOUSEHWHEEL) //horizontal wheel { const int distance = GET_WHEEL_DELTA_WPARAM(wParam); const int delta = WHEEL_DELTA; @@ -1830,8 +1848,8 @@ WXLRESULT Grid::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) if (!::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerRotation, 0)) linesPerRotation = 3; - SetFocus(); scrollDelta(rotations * linesPerRotation, 0); //in scroll units + return 0; //"If an application processes this message, it should return zero." } return wxScrolledWindow::MSWDefWindowProc(nMsg, wParam, lParam); @@ -18,7 +18,7 @@ namespace zen { -typedef enum { DUMMY_COLUMN_TYPE = static_cast<size_t>(-1) } ColumnType; +typedef enum { DUMMY_COLUMN_TYPE = static_cast<unsigned int>(-1) } ColumnType; //----- Events ----------------------------------------------------------------------------------------------- extern const wxEventType EVENT_GRID_COL_LABEL_MOUSE_LEFT; //generates: GridClickEvent diff --git a/wx+/zlib_wrap.h b/wx+/zlib_wrap.h index 7c805e23..a5ad2cb1 100644 --- a/wx+/zlib_wrap.h +++ b/wx+/zlib_wrap.h @@ -101,7 +101,7 @@ BinContainer decompress(const BinContainer& stream) //throw ZlibInternalError if (uncompressedSize == 0) //cannot be 0: compress() directly maps empty -> empty container skipping zlib! throw ZlibInternalError(); - contOut.resize(uncompressedSize); //throw std::bad_alloc + contOut.resize(static_cast<size_t>(uncompressedSize)); //throw std::bad_alloc } catch (std::bad_alloc&) //most likely due to data corruption! { @@ -112,7 +112,7 @@ BinContainer decompress(const BinContainer& stream) //throw ZlibInternalError stream.size() - sizeof(uncompressedSize), &*contOut.begin(), uncompressedSize); //throw ZlibInternalError - if (bytesWritten != uncompressedSize) + if (bytesWritten != static_cast<size_t>(uncompressedSize)) throw ZlibInternalError(); } return contOut; |