From 3ba62ef1de77153e5a8c7bad4451b96f6a1678b0 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Sun, 12 Mar 2017 22:00:35 -0600 Subject: 8.10 --- wx+/app_main.h | 6 -- wx+/file_drop.cpp | 2 +- wx+/grid.cpp | 4 +- wx+/http.cpp | 13 ++-- wx+/image_resources.cpp | 2 +- wx+/string_conv.h | 28 -------- wx+/timespan.h | 166 ------------------------------------------------ 7 files changed, 10 insertions(+), 211 deletions(-) delete mode 100755 wx+/string_conv.h delete mode 100755 wx+/timespan.h (limited to 'wx+') diff --git a/wx+/app_main.h b/wx+/app_main.h index 2202ebc5..4b2d92a4 100755 --- a/wx+/app_main.h +++ b/wx+/app_main.h @@ -21,12 +21,6 @@ bool mainWindowWasSet(); - - - - - - //######################## implementation ######################## inline bool& refMainWndStatus() diff --git a/wx+/file_drop.cpp b/wx+/file_drop.cpp index cab848b9..f951ca3c 100755 --- a/wx+/file_drop.cpp +++ b/wx+/file_drop.cpp @@ -37,7 +37,7 @@ private: //wxPoint clientDropPos(x, y) std::vector filePaths; for (const wxString& file : fileArray) - filePaths.push_back(utfCvrtTo(file)); + filePaths.push_back(utfTo(file)); //create a custom event on drop window: execute event after file dropping is completed! (after mouse is released) if (wxEvtHandler* handler = dropWindow_.GetEventHandler()) diff --git a/wx+/grid.cpp b/wx+/grid.cpp index 75abcd2f..d714ecf5 100755 --- a/wx+/grid.cpp +++ b/wx+/grid.cpp @@ -142,7 +142,7 @@ wxSize GridData::drawCellText(wxDC& dc, const wxRect& rect, const std::wstring& wxSize extentTrunc = dc.GetTextExtent(textTrunc); if (extentTrunc.GetWidth() > rect.width) { - //unlike Windows 7 Explorer, we truncate UTF-16 correctly: e.g. CJK-Ideogramm encodes to TWO wchar_t: utfCvrtTo("\xf0\xa4\xbd\x9c"); + //unlike Windows 7 Explorer, we truncate UTF-16 correctly: e.g. CJK-Ideogramm encodes to TWO wchar_t: utfTo("\xf0\xa4\xbd\x9c"); size_t low = 0; //number of unicode chars! size_t high = unicodeLength(text); // if (high > 1) @@ -159,7 +159,7 @@ wxSize GridData::drawCellText(wxDC& dc, const wxRect& rect, const std::wstring& break; } - const std::wstring& candidate = std::wstring(strBegin(text), findUnicodePos(text, middle)) + ELLIPSIS; + const std::wstring& candidate = getUnicodeSubstring(text, 0, middle) + ELLIPSIS; const wxSize extentCand = dc.GetTextExtent(candidate); //perf: most expensive call of this routine! if (extentCand.GetWidth() <= rect.width) diff --git a/wx+/http.cpp b/wx+/http.cpp index 851b3ed0..944c771a 100755 --- a/wx+/http.cpp +++ b/wx+/http.cpp @@ -33,9 +33,9 @@ public: { ZEN_ON_SCOPE_FAIL( cleanup(); /*destructor call would lead to member double clean-up!!!*/ ); - assert(!startsWith(makeUpperCopy(url), L"HTTPS:")); //not supported by wxHTTP! - const std::wstring urlFmt = startsWith(makeUpperCopy(url), L"HTTP://") || - startsWith(makeUpperCopy(url), L"HTTPS://") ? afterFirst(url, L"://", IF_MISSING_RETURN_NONE) : url; + assert(!startsWith(url, L"https:", CmpAsciiNoCase())); //not supported by wxHTTP! + const std::wstring urlFmt = startsWith(url, L"http://", CmpAsciiNoCase()) || + startsWith(url, L"https://", CmpAsciiNoCase()) ? afterFirst(url, L"://", IF_MISSING_RETURN_NONE) : url; const std::wstring server = beforeFirst(urlFmt, L'/', IF_MISSING_RETURN_ALL); const std::wstring page = L'/' + afterFirst(urlFmt, L'/', IF_MISSING_RETURN_NONE); @@ -49,7 +49,7 @@ public: throw SysError(L"wxHTTP::Connect"); if (postParams) - if (!webAccess_.SetPostText(L"application/x-www-form-urlencoded", utfCvrtTo(*postParams))) + if (!webAccess_.SetPostText(L"application/x-www-form-urlencoded", utfTo(*postParams))) throw SysError(L"wxHTTP::SetPostText"); httpStream_.reset(webAccess_.GetInputStream(page)); //pass ownership @@ -87,7 +87,7 @@ public: if (notifyUnbufferedIO_) notifyUnbufferedIO_(bytesRead); //throw X if (bytesRead == 0) //end of file - bytesToRead = memBuf_.size(); + bytesToRead = std::min(bytesToRead, memBuf_.size()); } std::copy(memBuf_.begin(), memBuf_.begin() + bytesToRead, static_cast(buffer)); @@ -225,8 +225,7 @@ std::vector> zen::xWwwFormUrlDecode(const st { std::vector> output; - for (const std::string& nvPair : split(str, '&')) - if (!nvPair.empty()) + for (const std::string& nvPair : split(str, '&', SplitType::SKIP_EMPTY)) output.emplace_back(urldecode(beforeFirst(nvPair, '=', IF_MISSING_RETURN_ALL)), urldecode(afterFirst (nvPair, '=', IF_MISSING_RETURN_NONE))); return output; diff --git a/wx+/image_resources.cpp b/wx+/image_resources.cpp index 5cd9df0b..dd8299c2 100755 --- a/wx+/image_resources.cpp +++ b/wx+/image_resources.cpp @@ -76,7 +76,7 @@ void GlobalBitmaps::init(const Zstring& filepath) { assert(bitmaps.empty() && anims.empty()); - wxFFileInputStream input(utfCvrtTo(filepath)); + wxFFileInputStream input(utfTo(filepath)); if (input.IsOk()) //if not... we don't want to react too harsh here { //activate support for .png files diff --git a/wx+/string_conv.h b/wx+/string_conv.h deleted file mode 100755 index 5db49ff2..00000000 --- a/wx+/string_conv.h +++ /dev/null @@ -1,28 +0,0 @@ -// ***************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * -// ***************************************************************************** - -#ifndef STRING_CONV_H_893217450815743 -#define STRING_CONV_H_893217450815743 - -#include -#include -#include - -namespace zen -{ -//conversion between Zstring and wxString -inline wxString toWx(const Zstring& str) { return utfCvrtTo(str); } -inline Zstring toZ(const wxString& str) { return utfCvrtTo(str); } - -inline std::vector toZ(const std::vector& strList) -{ - std::vector tmp; - std::transform(strList.begin(), strList.end(), std::back_inserter(tmp), [](const wxString& str) { return toZ(str); }); - return tmp; -} -} - -#endif //STRING_CONV_H_893217450815743 diff --git a/wx+/timespan.h b/wx+/timespan.h deleted file mode 100755 index b165351f..00000000 --- a/wx+/timespan.h +++ /dev/null @@ -1,166 +0,0 @@ -// ***************************************************************************** -// * This file is part of the FreeFileSync project. It is distributed under * -// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 * -// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved * -// ***************************************************************************** - -#ifndef TIMESPAN_H_254783756533456 -#define TIMESPAN_H_254783756533456 - -#include -#include -#include -#include - -//user friendly time span control -//- constructor is compatible with a wxTextControl -//- emits change event: wxEVT_TIMESPAN_CHANGE - -namespace zen -{ -inline -wxEventType getEventType() -{ - static wxEventType evt = wxNewEventType(); //external linkage! - return evt; -} -const wxEventType wxEVT_TIMESPAN_CHANGE = getEventType(); - - -class TimeSpanCtrl : public wxPanel -{ -public: - TimeSpanCtrl(wxWindow* parent, wxWindowID id, - const wxString& value = {}, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxTextCtrlNameStr) : - wxPanel(parent, id, pos, size, style, name), - FORMAT_TIMESPAN(wxT("%H:%M:%S")) - { - wxBoxSizer* bSizer27 = new wxBoxSizer( wxHORIZONTAL ); - - m_textCtrl = new wxTextCtrl(this, wxID_ANY, wxString(), wxDefaultPosition, wxDefaultSize, wxTE_CENTRE ); - bSizer27->Add(m_textCtrl, 1, wxALIGN_CENTER_VERTICAL | wxEXPAND, 5 ); - - m_spinBtn = new wxSpinButton(this, wxID_ANY, wxDefaultPosition, wxSize( 20, -1 ), wxSP_ARROW_KEYS ); - bSizer27->Add(m_spinBtn, 0, wxALIGN_CENTER_VERTICAL | wxEXPAND, 5 ); - - SetSizer(bSizer27); - Layout(); - - //connect events - m_spinBtn ->Connect(wxEVT_SCROLL_LINEUP, wxEventHandler (TimeSpanCtrl::OnSpinUp), nullptr, this); - m_spinBtn ->Connect(wxEVT_SCROLL_LINEDOWN, wxEventHandler (TimeSpanCtrl::OnSpinDown), nullptr, this); - m_textCtrl->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler (TimeSpanCtrl::OnKeyPress), nullptr, this); - m_textCtrl->Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(TimeSpanCtrl::OnMouseAction), nullptr, this); - - setValue(0); - } - - void setValue(int span) //unit: [s] - { - wxString newValue; - if (span < 0) - { - newValue += wxT("- "); - span = -span; - } - newValue += wxTimeSpan::Seconds(span).Format(FORMAT_TIMESPAN); - - long pos = m_textCtrl->GetInsertionPoint(); - pos += newValue.size() - m_textCtrl->GetValue().size(); - - m_textCtrl->ChangeValue(newValue); - m_textCtrl->SetInsertionPoint(pos); - - wxCommandEvent chgEvent(wxEVT_TIMESPAN_CHANGE); - wxPostEvent(this, chgEvent); - } - - int getValue() const - { - wxString textVal = m_textCtrl->GetValue(); - textVal.Trim(false); - - bool isNegative = false; - if (textVal.StartsWith(wxT("-"))) - { - isNegative = true; - textVal = textVal.substr(1); - } - textVal.Trim(false); - - wxDateTime tmp(time_t(0)); - if (tmp.ParseFormat(textVal, FORMAT_TIMESPAN, wxDateTime(tmp)) == nullptr) - return 0; - - return (isNegative ? -1 : 1) * - (tmp.GetHour () * 3600 + - tmp.GetMinute() * 60 + - tmp.GetSecond()); - } - -private: - void OnSpinUp (wxEvent& event) { spinValue(true); } - void OnSpinDown(wxEvent& event) { spinValue(false); } - - void OnKeyPress(wxKeyEvent& event) - { - const int keyCode = event.GetKeyCode(); - switch (keyCode) - { - case WXK_UP: - case WXK_NUMPAD_UP: - return spinValue(true); - case WXK_DOWN: - case WXK_NUMPAD_DOWN: - return spinValue(false); - default: - event.Skip(); - } - } - - void OnMouseAction(wxMouseEvent& event) - { - int delta = event.GetWheelRotation(); - if (delta > 0) - spinValue(true); - else if (delta < 0) - spinValue(false); - else - event.Skip(); - } - - void spinValue(bool up) - { - wxString textval = m_textCtrl->GetValue(); - long pos = m_textCtrl->GetInsertionPoint(); - - int stepSize = 1; - if (pos <= static_cast(textval.size())) - { - int delimCount = std::count(textval.begin() + pos, textval.end(), wxT(':')); - if (delimCount == 1) - stepSize = 60; //minute - else if (delimCount == 2) - stepSize = 3600; //hour - } - - if (!up) - stepSize *= -1; - - setValue(getValue() + stepSize); - } - - wxTextCtrl* m_textCtrl; - wxSpinButton* m_spinBtn; - - const wxString FORMAT_TIMESPAN; -}; -} - - -#endif //TIMESPAN_H_254783756533456 -- cgit