summaryrefslogtreecommitdiff
path: root/wx+
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:39 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:39 +0200
commitd2854834e18443876c8f75e0a7f3b88d1d549fc4 (patch)
treee967b628081e50abc7c34cd264e6586271c7e728 /wx+
parent4.1 (diff)
downloadFreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.gz
FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.bz2
FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.zip
4.2
Diffstat (limited to 'wx+')
-rw-r--r--wx+/button.cpp2
-rw-r--r--wx+/button.h2
-rw-r--r--wx+/format_unit.cpp24
-rw-r--r--wx+/graph.cpp38
-rw-r--r--wx+/graph.h10
-rw-r--r--wx+/image_tools.h9
-rw-r--r--wx+/mouse_move_dlg.cpp10
-rw-r--r--wx+/mouse_move_dlg.h1
-rw-r--r--wx+/no_flicker.h35
-rw-r--r--wx+/pch.h2
-rw-r--r--wx+/serialize.h18
-rw-r--r--wx+/string_conv.h4
-rw-r--r--wx+/timespan.h4
13 files changed, 100 insertions, 59 deletions
diff --git a/wx+/button.cpp b/wx+/button.cpp
index 7edfdea8..a4d543cf 100644
--- a/wx+/button.cpp
+++ b/wx+/button.cpp
@@ -15,7 +15,7 @@
using namespace zen;
-void zen::setBitmapLabel(wxBitmapButton& button, const wxBitmap& bmp)
+void zen::setImage(wxBitmapButton& button, const wxBitmap& bmp)
{
if (!isEqual(button.GetBitmapLabel(), bmp))
button.SetBitmapLabel(bmp);
diff --git a/wx+/button.h b/wx+/button.h
index e5d63a19..15ebc5a0 100644
--- a/wx+/button.h
+++ b/wx+/button.h
@@ -40,7 +40,7 @@ private:
};
//set bitmap label flicker free!
-void setBitmapLabel(wxBitmapButton& button, const wxBitmap& bmp);
+void setImage(wxBitmapButton& button, const wxBitmap& bmp);
}
diff --git a/wx+/format_unit.cpp b/wx+/format_unit.cpp
index 771778aa..994a2b29 100644
--- a/wx+/format_unit.cpp
+++ b/wx+/format_unit.cpp
@@ -7,6 +7,7 @@
#include "format_unit.h"
#include <zen/basic_math.h>
#include <zen/i18n.h>
+#include <zen/time.h>
#include <cwchar> //swprintf
#include <ctime>
#include <cstdio>
@@ -211,22 +212,17 @@ std::wstring zen::utcToLocalTimeString(Int64 utcTime)
return _("Error");
}
- struct tm loc = {};
- loc.tm_year = systemTimeLocal.wYear - 1900;
- loc.tm_mon = systemTimeLocal.wMonth - 1;
- loc.tm_mday = systemTimeLocal.wDay;
- loc.tm_hour = systemTimeLocal.wHour;
- loc.tm_min = systemTimeLocal.wMinute;
- loc.tm_sec = systemTimeLocal.wSecond;
- const struct tm* timePtr = &loc;
+ zen::TimeComp loc;
+ loc.year = systemTimeLocal.wYear;
+ loc.month = systemTimeLocal.wMonth;
+ loc.day = systemTimeLocal.wDay;
+ loc.hour = systemTimeLocal.wHour;
+ loc.minute = systemTimeLocal.wMinute;
+ loc.second = systemTimeLocal.wSecond;
#elif defined FFS_LINUX
- const time_t fileTime = to<time_t>(utcTime);
- const struct tm* timePtr = ::localtime(&fileTime); //convert to local time
+ zen::TimeComp loc = zen::localTime(to<time_t>(utcTime));
#endif
- wchar_t buffer[1000];
- size_t charsWritten = std::wcsftime(buffer, 1000, L"%x %X", timePtr);
-
- return std::wstring(buffer, charsWritten);
+ return formatTime<std::wstring>(L"%x %X", loc);
}
diff --git a/wx+/graph.cpp b/wx+/graph.cpp
index 584ef0ea..2e000389 100644
--- a/wx+/graph.cpp
+++ b/wx+/graph.cpp
@@ -35,6 +35,8 @@ double zen::nextNiceNumber(double blockSize) //round to next number which is a c
const double k = std::floor(std::log10(blockSize));
const double e = std::pow(10, k);
+ if (isNull(e))
+ return 0;
const double a = blockSize / e; //blockSize = a * 10^k with a in (1, 10)
//have a look at leading two digits: "nice" numbers start with 1, 2, 2.5 and 5
@@ -90,13 +92,15 @@ wxColor getDefaultColor(size_t pos)
void drawYLabel(wxDC& dc, double& yMin, double& yMax, const wxRect& clientArea, int labelWidth, bool drawLeft, const LabelFormatter& labelFmt) //clientArea := y-label + data window
{
//note: DON'T use wxDC::GetSize()! DC may be larger than visible area!
- if (clientArea.GetHeight() <= 0 || clientArea.GetWidth() <= 0) return;
+ if (clientArea.GetHeight() <= 0 || clientArea.GetWidth() <= 0)
+ return;
int optimalBlockHeight = 3 * dc.GetMultiLineTextExtent(wxT("1")).GetHeight();;
double valRangePerBlock = (yMax - yMin) * optimalBlockHeight / clientArea.GetHeight();
valRangePerBlock = labelFmt.getOptimalBlockSize(valRangePerBlock);
- if (numeric::isNull(valRangePerBlock)) return;
+ if (isNull(valRangePerBlock))
+ return;
double yMinNew = std::floor(yMin / valRangePerBlock) * valRangePerBlock;
double yMaxNew = std::ceil (yMax / valRangePerBlock) * valRangePerBlock;
@@ -139,18 +143,21 @@ void drawYLabel(wxDC& dc, double& yMin, double& yMax, const wxRect& clientArea,
void drawXLabel(wxDC& dc, double& xMin, double& xMax, const wxRect& clientArea, int labelHeight, bool drawBottom, const LabelFormatter& labelFmt) //clientArea := x-label + data window
{
//note: DON'T use wxDC::GetSize()! DC may be larger than visible area!
- if (clientArea.GetHeight() <= 0 || clientArea.GetWidth() <= 0) return;
+ if (clientArea.GetHeight() <= 0 || clientArea.GetWidth() <= 0)
+ return;
int optimalBlockWidth = dc.GetMultiLineTextExtent(wxT("100000000000000")).GetWidth();
double valRangePerBlock = (xMax - xMin) * optimalBlockWidth / clientArea.GetWidth();
valRangePerBlock = labelFmt.getOptimalBlockSize(valRangePerBlock);
- if (numeric::isNull(valRangePerBlock)) return;
+ if (isNull(valRangePerBlock))
+ return;
double xMinNew = std::floor(xMin / valRangePerBlock) * valRangePerBlock;
double xMaxNew = std::ceil (xMax / valRangePerBlock) * valRangePerBlock;
int blockCount = numeric::round((xMaxNew - xMinNew) / valRangePerBlock);
- if (blockCount == 0) return;
+ if (blockCount == 0)
+ return;
xMin = xMinNew; //inform about adjusted x value range
xMax = xMaxNew;
@@ -190,8 +197,8 @@ class ConvertCoord //convert between screen and actual coordinates
public:
ConvertCoord(double valMin, double valMax, size_t screenSize) :
min_(valMin),
- scaleToReal(screenSize == 0 ? 0 : (valMax - valMin) / screenSize),
- scaleToScr(numeric::isNull(valMax - valMin) ? 0 : screenSize / (valMax - valMin)) {}
+ scaleToReal(screenSize == 0 ? 0 : (valMax - valMin) / screenSize),
+ scaleToScr(isNull(valMax - valMin) ? 0 : screenSize / (valMax - valMin)) {}
double screenToReal(double screenPos) const //input value: [0, screenSize - 1]
{
@@ -333,8 +340,11 @@ void Graph2D::render(wxDC& dc) const
{
{
//have everything including label background in natural window color by default (overwriting current background color)
- DcBackgroundChanger dummy(dc, wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); //sigh, who *invents* this stuff??? -> workaround for issue with wxBufferedPaintDC
- //wxDCBrushChanger dummy(dc, *wxTRANSPARENT_BRUSH);
+ const wxColor backColor = wxPanel::GetClassDefaultAttributes().colBg != wxNullColour ?
+ wxPanel::GetClassDefaultAttributes().colBg :
+ wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
+ //wxDCBrushChanger dummy(dc, *wxTRANSPARENT_BRUSH); //sigh, who *invents* this stuff??? -> workaround for issue with wxBufferedPaintDC
+ DcBackgroundChanger dummy(dc, backColor);
dc.Clear();
}
@@ -418,8 +428,8 @@ void Graph2D::render(wxDC& dc) const
double maxWndY = attr.maxYauto ? -HUGE_VAL : attr.maxY; //
if (!curves_.empty())
{
- const int avgFactor = 2; //some averaging of edgy input data to smoothen behavior on window resize
- const ConvertCoord cvrtX(minWndX, maxWndX, dataArea.width * avgFactor);
+ const int AVG_FACTOR = 2; //some averaging of edgy input data to smoothen behavior on window resize
+ const ConvertCoord cvrtX(minWndX, maxWndX, dataArea.width * AVG_FACTOR);
for (GraphList::const_iterator j = curves_.begin(); j != curves_.end(); ++j)
{
@@ -430,13 +440,13 @@ void Graph2D::render(wxDC& dc) const
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 * avgFactor); //
+ const int postLast = std::min<int>(std::floor(cvrtX.realToScreen(graph.getXEnd())), dataArea.width * AVG_FACTOR); //
for (int i = posFirst; i < postLast; ++i)
yValues.push_back(graph.getValue(cvrtX.screenToReal(i)));
- subsample(yValues, avgFactor);
- offset = posFirst / avgFactor;
+ subsample(yValues, AVG_FACTOR);
+ offset = posFirst / AVG_FACTOR;
}
if (!yValues.empty())
diff --git a/wx+/graph.h b/wx+/graph.h
index 61a90ca1..34ef196e 100644
--- a/wx+/graph.h
+++ b/wx+/graph.h
@@ -25,7 +25,7 @@ Example:
setLabelX(Graph2D::POSLX_BOTTOM, 20, std::make_shared<LabelFormatterTimeElapsed>()).
setLabelY(Graph2D::POSLY_RIGHT, 60, std::make_shared<LabelFormatterBytes>()));
//set graph data
- std::shared_ptr<GraphData>() graphDataBytes = ...
+ std::shared_ptr<GraphData> graphDataBytes = ...
m_panelGraph->setData(graphDataBytes, Graph2D::LineAttributes().setLineWidth(2).setColor(wxColor(0, 192, 0)));
*/
@@ -33,9 +33,9 @@ Example:
struct GraphData
{
virtual ~GraphData() {}
- virtual double getValue(double x) const = 0;
- virtual double getXBegin() const = 0;
- virtual double getXEnd() const = 0; //upper bound for x, getValue() is NOT evaluated at this position! Similar to std::vector::end()
+ virtual double getValue (double x) const = 0;
+ virtual double getXBegin() const = 0;
+ virtual double getXEnd () const = 0; //upper bound for x, getValue() is NOT evaluated at this position! Similar to std::vector::end()
};
@@ -99,7 +99,7 @@ struct DecimalNumberFormatter : public LabelFormatter
//------------------------------------------------------------------------------------------------------------
//emit data selection event
-//usage: wnd.Connect(wxEVT_GRAPH_SELECTION, GraphSelectEventHandler(MyDlg::OnGraphSelection), NULL, this);
+//Usage: wnd.Connect(wxEVT_GRAPH_SELECTION, GraphSelectEventHandler(MyDlg::OnGraphSelection), NULL, this);
// void MyDlg::OnGraphSelection(GraphSelectEvent& event);
diff --git a/wx+/image_tools.h b/wx+/image_tools.h
index e78e7ced..23a363df 100644
--- a/wx+/image_tools.h
+++ b/wx+/image_tools.h
@@ -10,7 +10,7 @@
#include <numeric>
#include <wx/bitmap.h>
#include <wx/dcmemory.h>
-
+#include <zen/basic_math.h>
namespace zen
{
@@ -64,7 +64,8 @@ double getAvgBrightness(const wxImage& img)
{
const int pixelCount = img.GetWidth() * img.GetHeight();
auto pixBegin = img.GetData();
- if (pixBegin)
+
+ if (pixelCount > 0 && pixBegin)
{
auto pixEnd = pixBegin + 3 * pixelCount; //RGB
@@ -77,9 +78,9 @@ double getAvgBrightness(const wxImage& img)
for (auto iter = pixBegin; iter != pixEnd; ++iter)
dividend += *iter * static_cast<double>(alphaFirst[(iter - pixBegin) / 3]);
- const int divisor = 3.0 * std::accumulate(alphaFirst, alphaFirst + pixelCount, 0.0);
+ const double divisor = 3.0 * std::accumulate(alphaFirst, alphaFirst + pixelCount, 0.0);
- return dividend / divisor;
+ return numeric::isNull(divisor) ? 0 : dividend / divisor;
}
else
return std::accumulate(pixBegin, pixEnd, 0.0) / (3.0 * pixelCount);
diff --git a/wx+/mouse_move_dlg.cpp b/wx+/mouse_move_dlg.cpp
index 3f7ca755..7edaa5db 100644
--- a/wx+/mouse_move_dlg.cpp
+++ b/wx+/mouse_move_dlg.cpp
@@ -14,6 +14,8 @@
#include <wx/panel.h>
#include <wx/gauge.h>
#include <wx/statusbr.h>
+#include <wx/frame.h>
+#include <wx/dialog.h>
using namespace zen;
@@ -35,7 +37,7 @@ void forEachChild(wxWindow& parent, Fun f)
MouseMoveWindow::MouseMoveWindow(wxWindow& parent, bool includeParent) : wxWindow(&parent, wxID_ANY)
{
- wxObjectEventFunction memFunMouseDown = wxMouseEventHandler(MouseMoveWindow::LeftButtonDown);
+ wxObjectEventFunction memFunMouseDown = wxMouseEventHandler(MouseMoveWindow::LeftButtonDown); //wxWidgets macros are obviously not C++11 ready
auto connect = [&](wxWindow& wnd)
{
if (dynamic_cast<wxStaticText*> (&wnd) || //redirect clicks on these "dead" controls to move dialog instead
@@ -44,8 +46,10 @@ MouseMoveWindow::MouseMoveWindow(wxWindow& parent, bool includeParent) : wxWindo
dynamic_cast<wxGauge*> (&wnd) ||
dynamic_cast<wxStaticLine*> (&wnd) ||
dynamic_cast<wxStatusBar*> (&wnd) ||
- dynamic_cast<wxPanel*> (&wnd))
- wnd.Connect(wxEVT_LEFT_DOWN, memFunMouseDown, NULL, this); //wxWidgets macros are obviously not C++11 ready
+ dynamic_cast<wxPanel*> (&wnd) ||
+ dynamic_cast<wxFrame*> (&wnd) ||
+ dynamic_cast<wxDialog*> (&wnd))
+ wnd.Connect(wxEVT_LEFT_DOWN, memFunMouseDown, NULL, this);
};
if (includeParent)
diff --git a/wx+/mouse_move_dlg.h b/wx+/mouse_move_dlg.h
index 44988e3a..c97ef19c 100644
--- a/wx+/mouse_move_dlg.h
+++ b/wx+/mouse_move_dlg.h
@@ -11,7 +11,6 @@
namespace zen
{
-
/*
move dialog by mouse-dragging contained sub-windows: just attach to parent via new in constructor:
diff --git a/wx+/no_flicker.h b/wx+/no_flicker.h
new file mode 100644
index 00000000..0dceba97
--- /dev/null
+++ b/wx+/no_flicker.h
@@ -0,0 +1,35 @@
+// **************************************************************************
+// * 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 NO_FLICKER_HEADER_893421590321532
+#define NO_FLICKER_HEADER_893421590321532
+
+#include <wx/window.h>
+
+namespace zen
+{
+inline
+void setText(wxTextCtrl& control, const wxString& newText, bool* additionalLayoutChange = NULL)
+{
+ if (additionalLayoutChange && !*additionalLayoutChange) //never revert from true to false!
+ *additionalLayoutChange = control.GetValue().length() != newText.length(); //avoid screen flicker: update layout only when necessary
+
+ if (control.GetValue() != newText)
+ control.ChangeValue(newText);
+}
+
+inline
+void setText(wxStaticText& control, const wxString& newText, bool* additionalLayoutChange = NULL)
+{
+ if (additionalLayoutChange && !*additionalLayoutChange)
+ *additionalLayoutChange = control.GetLabel().length() != newText.length(); //avoid screen flicker: update layout only when necessary
+
+ if (control.GetLabel() != newText)
+ control.SetLabel(newText);
+}
+}
+
+#endif //NO_FLICKER_HEADER_893421590321532
diff --git a/wx+/pch.h b/wx+/pch.h
index acc03012..0a799217 100644
--- a/wx+/pch.h
+++ b/wx+/pch.h
@@ -18,7 +18,7 @@
#define WX_PRECOMP
#endif
-#include <wx/wxprec.h> //#includes <wx/msw/wrapwin.h>
+#include <wx/wxprec.h> //includes <wx/msw/wrapwin.h>
//other wxWidgets headers
#include <wx/log.h>
diff --git a/wx+/serialize.h b/wx+/serialize.h
index c15e963d..cec70278 100644
--- a/wx+/serialize.h
+++ b/wx+/serialize.h
@@ -64,7 +64,7 @@ private:
class ReadInputStream //throw FileError
{
protected:
- ReadInputStream(wxInputStream& stream, const wxString& errorObjName) : stream_(stream), errorObjName_(errorObjName) {}
+ ReadInputStream(wxInputStream& stream, const Zstring& errorObjName) : stream_(stream), errorObjName_(errorObjName) {}
template <class T>
T readNumberC() const; //throw FileError, checked read operation
@@ -81,14 +81,14 @@ protected:
private:
wxInputStream& stream_;
- const wxString& errorObjName_; //used for error text only
+ const Zstring& errorObjName_; //used for error text only
};
class WriteOutputStream //throw FileError
{
protected:
- WriteOutputStream(const wxString& errorObjName, wxOutputStream& stream) : stream_(stream), errorObjName_(errorObjName) {}
+ WriteOutputStream(const Zstring& errorObjName, wxOutputStream& stream) : stream_(stream), errorObjName_(errorObjName) {}
template <class T>
void writeNumberC(T number) const; //throw FileError, checked write operation
@@ -104,7 +104,7 @@ protected:
private:
wxOutputStream& stream_;
- const wxString& errorObjName_; //used for error text only!
+ const Zstring& errorObjName_; //used for error text only!
};
@@ -185,7 +185,7 @@ inline
void ReadInputStream::check() const
{
if (stream_.GetLastError() != wxSTREAM_NO_ERROR)
- throw zen::FileError(_("Error reading from synchronization database:") + " \n" + "\"" + errorObjName_.c_str() + "\"");
+ throw zen::FileError(_("Error reading from synchronization database:") + L" \n" + L"\"" + errorObjName_ + L"\"");
}
@@ -210,7 +210,7 @@ S ReadInputStream::readStringC() const //checked read operation
}
catch (std::exception&)
{
- throw FileError(_("Error reading from synchronization database:") + " \n" + "\"" + errorObjName_.c_str() + "\"");
+ throw FileError(_("Error reading from synchronization database:") + L" \n" + L"\"" + errorObjName_ + L"\"");
}
return output;
}
@@ -226,7 +226,7 @@ ReadInputStream::CharArray ReadInputStream::readArrayC() const
stream_.Read(&(*buffer)[0], byteCount);
check();
if (stream_.LastRead() != byteCount) //some additional check
- throw FileError(_("Error reading from synchronization database:") + " \n" + "\"" + errorObjName_.c_str() + "\"");
+ throw FileError(_("Error reading from synchronization database:") + L" \n" + L"\"" + errorObjName_ + L"\"");
}
return buffer;
}
@@ -257,7 +257,7 @@ void WriteOutputStream::writeArrayC(const std::vector<char>& buffer) const
stream_.Write(&buffer[0], buffer.size());
check();
if (stream_.LastWrite() != buffer.size()) //some additional check
- throw FileError(_("Error writing to synchronization database:") + " \n" + "\"" + errorObjName_.c_str() + "\"");
+ throw FileError(_("Error writing to synchronization database:") + L" \n" + L"\"" + errorObjName_ + L"\"");
}
}
@@ -266,7 +266,7 @@ inline
void WriteOutputStream::check() const
{
if (stream_.GetLastError() != wxSTREAM_NO_ERROR)
- throw FileError(_("Error writing to synchronization database:") + " \n" + "\"" + errorObjName_.c_str() + "\"");
+ throw FileError(_("Error writing to synchronization database:") + L" \n" + L"\"" + errorObjName_ + L"\"");
}
}
diff --git a/wx+/string_conv.h b/wx+/string_conv.h
index 3f4574ab..76249aca 100644
--- a/wx+/string_conv.h
+++ b/wx+/string_conv.h
@@ -13,10 +13,6 @@
namespace zen
{
-inline wxString operator+(const wxString& lhs, const char* rhs) { return wxString(lhs) += utf8CvrtTo<wxString>(rhs); }
-inline wxString operator+(const wxString& lhs, const Zstring& rhs) { return wxString(lhs) += utf8CvrtTo<wxString>(rhs); }
-
-
//conversion between Zstring and wxString
inline wxString toWx(const Zstring& str) { return utf8CvrtTo<wxString>(str); }
inline Zstring toZ(const wxString& str) { return utf8CvrtTo<Zstring>(str); }
diff --git a/wx+/timespan.h b/wx+/timespan.h
index d11b328e..698171fa 100644
--- a/wx+/timespan.h
+++ b/wx+/timespan.h
@@ -19,9 +19,9 @@
namespace zen
{
inline
-wxEventType getEventType() //external linkage
+wxEventType getEventType()
{
- static wxEventType evt = wxNewEventType();
+ static wxEventType evt = wxNewEventType(); //external linkage!
return evt;
}
const wxEventType wxEVT_TIMESPAN_CHANGE = getEventType();
bgstack15