diff options
Diffstat (limited to 'wx+')
-rw-r--r-- | wx+/app_main.h | 18 | ||||
-rw-r--r-- | wx+/button.cpp | 2 | ||||
-rw-r--r-- | wx+/format_unit.cpp | 31 | ||||
-rw-r--r-- | wx+/format_unit.h | 2 | ||||
-rw-r--r-- | wx+/graph.cpp | 24 | ||||
-rw-r--r-- | wx+/graph.h | 9 | ||||
-rw-r--r-- | wx+/grid.h | 135 | ||||
-rw-r--r-- | wx+/image_tools.h | 14 |
8 files changed, 199 insertions, 36 deletions
diff --git a/wx+/app_main.h b/wx+/app_main.h index 6b375592..ae36a8de 100644 --- a/wx+/app_main.h +++ b/wx+/app_main.h @@ -23,14 +23,24 @@ bool mainWindowWasSet(); + + + + //######################## implementation ######################## inline -bool& getMainWndStatus() +bool& refMainWndStatus() { static bool status = false; //external linkage! return status; } +inline +bool& refQueryEnd() +{ + static bool status = false; //external linkage! + return status; +} inline void setMainWindow(wxWindow* window) @@ -38,12 +48,10 @@ void setMainWindow(wxWindow* window) wxTheApp->SetTopWindow(window); wxTheApp->SetExitOnFrameDelete(true); - getMainWndStatus() = true; + refMainWndStatus() = true; } - -inline -bool mainWindowWasSet() { return getMainWndStatus(); } +inline bool mainWindowWasSet() { return refMainWndStatus(); } } #endif // APPMAIN_H_INCLUDED diff --git a/wx+/button.cpp b/wx+/button.cpp index a4d543cf..80a9f8ba 100644 --- a/wx+/button.cpp +++ b/wx+/button.cpp @@ -175,7 +175,7 @@ wxBitmap BitmapButton::createBitmapFromText(const wxString& text) //copy one image into another, allowing arbitrary overlapping! (pos may contain negative numbers) -void writeToImage(const wxImage& source, const wxPoint pos, wxImage& target) +void writeToImage(const wxImage& source, const wxPoint& pos, wxImage& target) { //determine startpositions in source and target image, as well as width and height to be copied wxPoint posSrc, posTrg; diff --git a/wx+/format_unit.cpp b/wx+/format_unit.cpp index 361dbc62..13e53ba3 100644 --- a/wx+/format_unit.cpp +++ b/wx+/format_unit.cpp @@ -28,11 +28,11 @@ size_t getDigitCount(size_t number) } -std::wstring zen::filesizeToShortString(UInt64 size) +std::wstring zen::filesizeToShortString(Int64 size) { - if (to<Int64>(size) < 0) return _("Error"); + //if (to<Int64>(size) < 0) return _("Error"); -> really? there's one exceptional case: a failed rename operation falls-back to copy + delete, reducing "bytes transferred" to potentially < 0! - if (size <= 999U) + if (numeric::abs(size) <= 999) return replaceCpy(_P("1 Byte", "%x Bytes", to<int>(size)), L"%x", toString<std::wstring>(size)); @@ -42,19 +42,19 @@ std::wstring zen::filesizeToShortString(UInt64 size) filesize /= 1024; std::wstring output = _("%x KB"); - if (filesize > 999) + if (numeric::abs(filesize) > 999) { filesize /= 1024; output = _("%x MB"); - if (filesize > 999) + if (numeric::abs(filesize) > 999) { filesize /= 1024; output = _("%x GB"); - if (filesize > 999) + if (numeric::abs(filesize) > 999) { filesize /= 1024; output = _("%x TB"); - if (filesize > 999) + if (numeric::abs(filesize) > 999) { filesize /= 1024; output = _("%x PB"); @@ -63,13 +63,13 @@ std::wstring zen::filesizeToShortString(UInt64 size) } } //print just three significant digits: 0,01 | 0,11 | 1,11 | 11,1 | 111 - const size_t leadDigitCount = getDigitCount(static_cast<size_t>(filesize)); //number of digits before decimal point + const size_t leadDigitCount = getDigitCount(static_cast<size_t>(numeric::abs(filesize))); //number of digits before decimal point if (leadDigitCount == 0 || leadDigitCount > 3) return _("Error"); wchar_t buffer[50]; #ifdef __MINGW32__ - int charsWritten = ::snwprintf(buffer, 50, L"%.*f", static_cast<int>(3 - leadDigitCount), filesize); //MinGW does not comply to the C standard here + int charsWritten = ::snwprintf(buffer, 50, L"%.*f", static_cast<int>(3 - leadDigitCount), filesize); //MinGW does not comply to the C standard here #else int charsWritten = std::swprintf(buffer, 50, L"%.*f", static_cast<int>(3 - leadDigitCount), filesize); #endif @@ -144,9 +144,16 @@ std::wstring zen::fractionToShortString(double fraction) std::wstring zen::ffs_Impl::includeNumberSeparator(const std::wstring& number) { std::wstring output(number); - for (size_t i = output.size(); i > 3; i -= 3) - output.insert(i - 3, zen::getThousandsSeparator()); - + size_t i = output.size(); + for (;;) + { + if (i <= 3) + break; + i -= 3; + if (!cStringIsDigit(output[i - 1])) + break; + output.insert(i, zen::getThousandsSeparator()); + } return output; } diff --git a/wx+/format_unit.h b/wx+/format_unit.h index 953910b6..6eba90de 100644 --- a/wx+/format_unit.h +++ b/wx+/format_unit.h @@ -13,7 +13,7 @@ namespace zen { -std::wstring filesizeToShortString(UInt64 filesize); +std::wstring filesizeToShortString(Int64 filesize); std::wstring remainingTimeToShortString(double timeInSec); std::wstring fractionToShortString(double fraction); //within [0, 1] diff --git a/wx+/graph.cpp b/wx+/graph.cpp index 2e000389..4fdfb35d 100644 --- a/wx+/graph.cpp +++ b/wx+/graph.cpp @@ -1,8 +1,7 @@ // ************************************************************************** -// * This file is part of the zenXML project. It is distributed under the * -// * Boost Software License, Version 1.0. See accompanying file * -// * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** #include "graph.h" @@ -401,8 +400,8 @@ void Graph2D::render(wxDC& dc) const } //detect x value range - double minWndX = attr.minXauto ? HUGE_VAL : attr.minX; //automatic: ensure values are initialized by first curve - double maxWndX = attr.maxXauto ? -HUGE_VAL : attr.maxX; // + double minWndX = attr.minXauto ? std::numeric_limits<double>::infinity() : attr.minX; //automatic: ensure values are initialized by first curve + double maxWndX = attr.maxXauto ? -std::numeric_limits<double>::infinity() : attr.maxX; // if (!curves_.empty()) { for (GraphList::const_iterator j = curves_.begin(); j != curves_.end(); ++j) @@ -424,8 +423,8 @@ void Graph2D::render(wxDC& dc) const { //detect y value range std::vector<std::pair<std::vector<double>, int>> yValuesList(curves_.size()); - double minWndY = attr.minYauto ? HUGE_VAL : attr.minY; //automatic: ensure values are initialized by first curve - double maxWndY = attr.maxYauto ? -HUGE_VAL : attr.maxY; // + double minWndY = attr.minYauto ? std::numeric_limits<double>::infinity() : attr.minY; //automatic: ensure values are initialized by first curve + double maxWndY = attr.maxYauto ? -std::numeric_limits<double>::infinity() : attr.maxY; // if (!curves_.empty()) { const int AVG_FACTOR = 2; //some averaging of edgy input data to smoothen behavior on window resize @@ -433,14 +432,17 @@ void Graph2D::render(wxDC& dc) const for (GraphList::const_iterator j = curves_.begin(); j != curves_.end(); ++j) { - if (!j->first.get()) continue; + if (!j->first) continue; const GraphData& graph = *j->first; std::vector<double>& yValues = yValuesList[j - curves_.begin()].first; //actual y-values int& offset = yValuesList[j - curves_.begin()].second; //x-value offset in pixel { - const int posFirst = std::max<int>(std::ceil(cvrtX.realToScreen(graph.getXBegin())), 0); //evaluate visible area only and make sure to not step one pixel before xbegin()! - const int postLast = std::min<int>(std::floor(cvrtX.realToScreen(graph.getXEnd())), dataArea.width * AVG_FACTOR); // + const double xBegin = graph.getXBegin(); + const double xEnd = graph.getXEnd(); + + const int posFirst = std::ceil (cvrtX.realToScreen(std::max(xBegin, minWndX))); //evaluate visible area only and make sure to not step one pixel before xbegin()! + const int postLast = std::floor(cvrtX.realToScreen(std::min(xEnd, maxWndX))); //apply min/max *before* calling realToScreen()! for (int i = posFirst; i < postLast; ++i) yValues.push_back(graph.getValue(cvrtX.screenToReal(i))); diff --git a/wx+/graph.h b/wx+/graph.h index 34ef196e..aadba04b 100644 --- a/wx+/graph.h +++ b/wx+/graph.h @@ -1,8 +1,7 @@ // ************************************************************************** -// * This file is part of the zenXML project. It is distributed under the * -// * Boost Software License, Version 1.0. See accompanying file * -// * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt. * -// * Copyright (C) 2011 ZenJu (zhnmju123 AT gmx.de) * +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * // ************************************************************************** #ifndef WX_PLOT_HEADER_2344252459 @@ -122,7 +121,7 @@ struct SelectionBlock class GraphSelectEvent : public wxCommandEvent { public: - GraphSelectEvent(const SelectionBlock& selBlock) : wxCommandEvent(wxEVT_GRAPH_SELECTION), selBlock_(selBlock_) {} + GraphSelectEvent(const SelectionBlock& selBlock) : wxCommandEvent(wxEVT_GRAPH_SELECTION), selBlock_(selBlock) {} virtual wxEvent* Clone() const { return new GraphSelectEvent(selBlock_); } diff --git a/wx+/grid.h b/wx+/grid.h new file mode 100644 index 00000000..e0069e32 --- /dev/null +++ b/wx+/grid.h @@ -0,0 +1,135 @@ +// ************************************************************************** +// * This file is part of the FreeFileSync project. It is distributed under * +// * GNU General Public License: http://www.gnu.org/licenses/gpl.html * +// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) * +// ************************************************************************** + +#ifndef WX_TREE_LIST_HEADER_8347021348317 +#define WX_TREE_LIST_HEADER_8347021348317 + +#include <set> +#include <memory> +#include <vector> +#include <wx/scrolwin.h> + +namespace zen +{ +//------------------------------------------------------------------------------------------------------------ +class Grid; + +class GridDataView +{ +public: + virtual ~GridDataView() {} + + virtual wxString getValue(int row, int col) = 0; + virtual void renderCell(Grid& grid, wxDC& dc, const wxRect& rect, int row, int col, bool selected); //default implementation + + virtual wxString getColumnLabel(int col) = 0; + virtual void renderColumnLabel(Grid& tree, wxDC& dc, const wxRect& rect, int col, bool highlighted); //default implementation + +protected: + static wxRect drawCellBorder (wxDC& dc, const wxRect& rect); //returns inner rectangle + static void drawCellBackground(wxDC& dc, const wxRect& rect, bool selected, bool enabled, bool hasFocus); + static void drawCellText (wxDC& dc, const wxRect& rect, const wxString& text, bool enabled); + + static wxRect drawColumnLabelBorder (wxDC& dc, const wxRect& rect); //returns inner rectangle + static void drawColumnLabelBackground(wxDC& dc, const wxRect& rect, bool highlighted); + static void drawColumnLabelText (wxDC& dc, const wxRect& rect, const wxString& text); +}; + + + +class Grid : public wxScrolledWindow +{ +public: + Grid(wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr); + + //------------ set grid data -------------------------------------------------- + void setRowCount(int rowCount); + int getRowCount() const; + + void setRowHeight(int height); + int getRowHeight(); + + void setColumnConfig(const std::vector<int>& widths); //set column count + widths + std::vector<int> getColumnConfig() const; + + void setDataProvider(const std::shared_ptr<GridDataView>& dataView) { dataView_ = dataView; } + //----------------------------------------------------------------------------- + + void setColumnLabelHeight(int height); + void showRowLabel(bool visible); + + void showScrollBars(bool horizontal, bool vertical); + + std::vector<int> getSelectedRows() const; + +private: + void onSizeEvent(wxEvent& evt) { updateWindowSizes(); } + + void updateWindowSizes(); + + int getScrollUnitsTotalX() const; + int getScrollUnitsTotalY() const; + + int getPixelsPerScrollUnit() const; + + void scrollDelta(int deltaX, int deltaY); //in scroll units + + void redirectRowLabelEvent(wxMouseEvent& event); + +#ifdef FFS_WIN + virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); //support horizontal mouse wheel +void SetScrollbar(int orientation, int position, int thumbSize, int range, bool refresh); //get rid of scrollbars, but preserve scrolling behavior! +#endif + GridDataView* getDataProvider() { return dataView_.get(); } + + static const int defaultRowHeight = 20; + static const int defaultColLabelHeight = 25; + static const int columnBorderLeft = 4; //for left-aligned text + static const int columnLabelBorder = columnBorderLeft; + static const int columnMoveDelay = 5; //unit [pixel] (Explorer) + static const int columnMinWidth = 30; + static const int rowLabelBorder = 3; + static const int columnResizeTolerance = 5; //unit [pixel] + static const int mouseDragScrollIncrementY = 2; //in scroll units + static const int mouseDragScrollIncrementX = 1; // + + friend class GridDataView; + class SubWindow; + class CornerWin; + class RowLabelWin; + class ColLabelWin; + class MainWin; + + /* + Visual layout: + ---------------------------- + |CornerWin | RowLabelWin | + |--------------------------- + |ColLabelWin | MainWin | + ---------------------------- + */ + CornerWin* cornerWin_; + RowLabelWin* rowLabelWin_; + ColLabelWin* colLabelWin_; + MainWin* mainWin_; + + std::shared_ptr<GridDataView> dataView_; + + bool showScrollbarX; + bool showScrollbarY; + + int colLabelHeight; + int drawRowLabel; +}; +} + + +#endif //WX_TREE_LIST_HEADER_8347021348317 diff --git a/wx+/image_tools.h b/wx+/image_tools.h index 23a363df..687025d0 100644 --- a/wx+/image_tools.h +++ b/wx+/image_tools.h @@ -9,6 +9,7 @@ #include <numeric> #include <wx/bitmap.h> +#include <wx/image.h> #include <wx/dcmemory.h> #include <zen/basic_math.h> @@ -24,7 +25,7 @@ void brighten(wxImage& img, int level); //level: delta per channel in points bool isEqual(const wxBitmap& lhs, const wxBitmap& rhs); //pixel-wise equality (respecting alpha channel) - +wxColor gradient(const wxColor& from, const wxColor& to, double fraction); //maps fraction within [0, 1] to an intermediate color @@ -152,6 +153,17 @@ bool isEqual(const wxBitmap& lhs, const wxBitmap& rhs) return std::equal(imLhs.GetData(), imLhs.GetData() + pixelCount * 3, imRhs.GetData()); } + +inline +wxColor gradient(const wxColor& from, const wxColor& to, double fraction) +{ + fraction = std::max(0.0, fraction); + fraction = std::min(1.0, fraction); + return wxColor(from.Red () + (to.Red () - from.Red ()) * fraction, + from.Green() + (to.Green() - from.Green()) * fraction, + from.Blue () + (to.Blue () - from.Blue ()) * fraction, + from.Alpha() + (to.Alpha() - from.Alpha()) * fraction); +} } |