refactoring
This commit is contained in:
parent
065e6f3081
commit
01bd43f960
@ -118,7 +118,5 @@ namespace nana
|
||||
}
|
||||
}
|
||||
|
||||
#define NANA_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 )
|
||||
|
||||
#include <nana/pop_ignore_diagnostic>
|
||||
#endif //NANA_DEPLOY_HPP
|
||||
|
@ -59,11 +59,7 @@ namespace nana
|
||||
void text(const ::std::string&);
|
||||
void icon(const ::std::string& icon_file);
|
||||
void insert_icon(const ::std::string& icon_file);
|
||||
#if 0 //deprecated
|
||||
void period(unsigned millisecond);
|
||||
#else
|
||||
void period(std::chrono::milliseconds time);
|
||||
#endif
|
||||
detail::notifier_events& events();
|
||||
window handle() const;
|
||||
private:
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Platform Specification Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -96,19 +96,28 @@ namespace detail
|
||||
unsigned whitespace_pixels;
|
||||
}string;
|
||||
|
||||
unsigned fgcolor_rgb{ 0xFFFFFFFF };
|
||||
unsigned bgcolor_rgb{ 0xFFFFFFFF };
|
||||
unsigned fgcolor_native{ 0xFFFFFFFF }; //Windows RGB format: 0xBBGGRR
|
||||
unsigned bgcolor_native{ 0xFFFFFFFF }; //Windows RGB format
|
||||
|
||||
drawable_impl_type(const drawable_impl_type&) = delete;
|
||||
drawable_impl_type& operator=(const drawable_impl_type&) = delete;
|
||||
|
||||
drawable_impl_type();
|
||||
~drawable_impl_type();
|
||||
|
||||
#if 0 //deprecated
|
||||
unsigned get_color() const;
|
||||
unsigned get_text_color() const;
|
||||
#endif
|
||||
void set_color(const ::nana::color&);
|
||||
void set_text_color(const ::nana::color&);
|
||||
#if 0 //deprecated
|
||||
private:
|
||||
unsigned color_{ 0xffffffff };
|
||||
unsigned text_color_{0xffffffff};
|
||||
#endif
|
||||
};
|
||||
|
||||
class platform_spec
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Platform Specification Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Nana Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -339,24 +339,9 @@ namespace detail
|
||||
string.tab_length = 4;
|
||||
string.tab_pixels = 0;
|
||||
string.whitespace_pixels = 0;
|
||||
|
||||
#if 0 //deprecated
|
||||
#if defined(NANA_USE_XFT)
|
||||
conv_.handle = ::iconv_open("UTF-8", NANA_UNICODE);
|
||||
conv_.code = NANA_UNICODE;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
drawable_impl_type::~drawable_impl_type()
|
||||
{
|
||||
#if 0 //deprecated
|
||||
#if defined(NANA_USE_XFT)
|
||||
::iconv_close(conv_.handle);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned drawable_impl_type::get_color() const
|
||||
{
|
||||
return color_;
|
||||
@ -366,27 +351,28 @@ namespace detail
|
||||
{
|
||||
return text_color_;
|
||||
}
|
||||
#endif
|
||||
|
||||
void drawable_impl_type::set_color(const ::nana::color& clr)
|
||||
{
|
||||
color_ = (clr.px_color().value & 0xFFFFFF);
|
||||
bgcolor_rgb = (clr.px_color().value & 0xFFFFFF);
|
||||
}
|
||||
|
||||
void drawable_impl_type::set_text_color(const ::nana::color& clr)
|
||||
{
|
||||
text_color_ = (clr.px_color().value & 0xFFFFFF);
|
||||
fgcolor_rgb = (clr.px_color().value & 0xFFFFFF);
|
||||
update_text_color();
|
||||
}
|
||||
|
||||
void drawable_impl_type::update_color()
|
||||
{
|
||||
if (color_ != current_color_)
|
||||
if (bgcolor_rgb != current_color_)
|
||||
{
|
||||
auto & spec = nana::detail::platform_spec::instance();
|
||||
platform_scope_guard lock;
|
||||
|
||||
current_color_ = color_;
|
||||
auto col = color_;
|
||||
current_color_ = bgcolor_rgb;
|
||||
auto col = bgcolor_rgb;
|
||||
switch (spec.screen_depth())
|
||||
{
|
||||
case 16:
|
||||
@ -397,18 +383,32 @@ namespace detail
|
||||
}
|
||||
::XSetForeground(spec.open_display(), context, col);
|
||||
::XSetBackground(spec.open_display(), context, col);
|
||||
|
||||
#if defined(NANA_USE_XFT)
|
||||
//xft_fgcolor also needs to be assigned.
|
||||
//assumes the xft_fgcolor is not assigned in update_color. There is a situation that causes a bug.
|
||||
//
|
||||
//update_text_color ( if fgcolor_rgb = A, then current_color = A and xft_fgcolor = A)
|
||||
//update_color (if bgcolor_rgb = B, then current_color = B and xft_fgcolor is still A)
|
||||
//update_text_color ( if fgcolor_rgb = B, then current_color = B, xft_fgcolor is still A)
|
||||
|
||||
xft_fgcolor.color.red = ((0xFF0000 & col) >> 16) * 0x101;
|
||||
xft_fgcolor.color.green = ((0xFF00 & col) >> 8) * 0x101;
|
||||
xft_fgcolor.color.blue = (0xFF & col) * 0x101;
|
||||
xft_fgcolor.color.alpha = 0xFFFF;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void drawable_impl_type::update_text_color()
|
||||
{
|
||||
if (text_color_ != current_color_)
|
||||
if (fgcolor_rgb != current_color_)
|
||||
{
|
||||
auto & spec = nana::detail::platform_spec::instance();
|
||||
platform_scope_guard lock;
|
||||
|
||||
current_color_ = text_color_;
|
||||
auto col = text_color_;
|
||||
current_color_ = fgcolor_rgb;
|
||||
auto col = fgcolor_rgb;
|
||||
switch (spec.screen_depth())
|
||||
{
|
||||
case 16:
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Platform Specification Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -42,6 +42,7 @@ namespace detail
|
||||
::DeleteObject(pixmap);
|
||||
}
|
||||
|
||||
#if 0 //deprecated
|
||||
unsigned drawable_impl_type::get_color() const
|
||||
{
|
||||
return color_;
|
||||
@ -51,19 +52,24 @@ namespace detail
|
||||
{
|
||||
return text_color_;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define NANA_WINDOWS_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 )
|
||||
|
||||
void drawable_impl_type::set_color(const ::nana::color& clr)
|
||||
{
|
||||
color_ = (clr.px_color().value & 0xFFFFFF);
|
||||
bgcolor_rgb = (clr.px_color().value & 0xFFFFFF);
|
||||
bgcolor_native = NANA_WINDOWS_RGB(bgcolor_rgb);
|
||||
}
|
||||
|
||||
void drawable_impl_type::set_text_color(const ::nana::color& clr)
|
||||
{
|
||||
auto rgb = (clr.px_color().value & 0xFFFFFF);
|
||||
if (text_color_ != rgb)
|
||||
if (fgcolor_rgb != rgb)
|
||||
{
|
||||
::SetTextColor(context, NANA_RGB(rgb));
|
||||
text_color_ = rgb;
|
||||
fgcolor_rgb = rgb;
|
||||
fgcolor_native = NANA_WINDOWS_RGB(rgb);
|
||||
::SetTextColor(context, fgcolor_native);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Platform Specification Implementation
|
||||
* Nana C++ Library(http://www.nanapro.org)
|
||||
* Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com)
|
||||
* Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com)
|
||||
*
|
||||
* Distributed under the Boost Software License, Version 1.0.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@ -42,7 +42,6 @@
|
||||
|
||||
#if defined(NANA_USE_XFT)
|
||||
#include <X11/Xft/Xft.h>
|
||||
// #include <iconv.h> //deprecated
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
@ -62,21 +61,6 @@ namespace detail
|
||||
private:
|
||||
std::ifstream ifs_;
|
||||
};
|
||||
|
||||
#if 0 //deprecated
|
||||
class charset_conv
|
||||
{
|
||||
charset_conv(const charset_conv&) = delete;
|
||||
charset_conv& operator=(const charset_conv*) = delete;
|
||||
public:
|
||||
charset_conv(const char* tocode, const char* fromcode);
|
||||
~charset_conv();
|
||||
std::string charset(const std::string& str) const;
|
||||
std::string charset(const char * buf, std::size_t len) const;
|
||||
private:
|
||||
iconv_t handle_;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct drawable_impl_type
|
||||
@ -97,16 +81,19 @@ namespace detail
|
||||
unsigned whitespace_pixels;
|
||||
}string;
|
||||
|
||||
unsigned fgcolor_rgb{ 0xFFFFFFFF };
|
||||
unsigned bgcolor_rgb{ 0xFFFFFFFF };
|
||||
|
||||
#if defined(NANA_USE_XFT)
|
||||
XftDraw * xftdraw{nullptr};
|
||||
XftColor xft_fgcolor;
|
||||
const std::string charset(const std::wstring& str, const std::string& strcode);
|
||||
#endif
|
||||
drawable_impl_type();
|
||||
~drawable_impl_type();
|
||||
|
||||
#if 0 //deprecated
|
||||
unsigned get_color() const;
|
||||
unsigned get_text_color() const;
|
||||
#endif
|
||||
void set_color(const ::nana::color&);
|
||||
void set_text_color(const ::nana::color&);
|
||||
|
||||
@ -117,17 +104,9 @@ namespace detail
|
||||
drawable_impl_type& operator=(const drawable_impl_type&) = delete;
|
||||
|
||||
unsigned current_color_{ 0xFFFFFF };
|
||||
#if 0 //deprecated
|
||||
unsigned color_{ 0xFFFFFFFF };
|
||||
unsigned text_color_{ 0xFFFFFFFF };
|
||||
|
||||
#if 0 //deprecated
|
||||
#if defined(NANA_USE_XFT)
|
||||
struct conv_tag
|
||||
{
|
||||
iconv_t handle;
|
||||
std::string code;
|
||||
}conv_;
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -110,42 +110,6 @@ namespace nana
|
||||
return tm.str();
|
||||
}
|
||||
return {};
|
||||
|
||||
/*
|
||||
// Deprecated
|
||||
//Windows stores file times using the FILETIME structure, which is a 64 bit value of 100ns intervals from January 1, 1601.
|
||||
//What's worse is that this 1601 date is fairly common to see given that it's the all zeroes value, and it is far before the
|
||||
//earliest date representable with time_t.std::filesystem can't change the reality of the underlying platform.
|
||||
|
||||
|
||||
try {
|
||||
#if NANA_USING_BOOST_FILESYSTEM
|
||||
// The return type of boost::filesystem::last_write_time isn't
|
||||
// the same as in nana and std implementations of this function
|
||||
auto ftime = std::chrono::system_clock::from_time_t(fs::last_write_time(path));
|
||||
#else
|
||||
auto ftime = fs::last_write_time(path);
|
||||
#endif
|
||||
|
||||
// crash: VS2015 will not read the time for some files (for example: C:/hiberfil.sys)
|
||||
// and will return file_time_type(-1) without throwing
|
||||
// https://msdn.microsoft.com/en-us/library/dn823784.aspx
|
||||
|
||||
if (ftime == ((fs::file_time_type::min)())) return{};
|
||||
|
||||
//A workaround for VC2013
|
||||
using time_point = decltype(ftime);
|
||||
auto cftime = time_point::clock::to_time_t(ftime);
|
||||
|
||||
std::stringstream tm;
|
||||
tm << std::put_time(std::localtime(&cftime), "%Y-%m-%d, %H:%M:%S");
|
||||
return tm.str();
|
||||
}
|
||||
catch (...) {
|
||||
return{};
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
bool modified_file_time(const fs::path& p, struct tm& t)
|
||||
|
@ -512,16 +512,9 @@ namespace detail
|
||||
|
||||
auto const native_window = rruntime->window->root;
|
||||
|
||||
#if 0 //deprecated
|
||||
nana::detail::charset_conv charset(NANA_UNICODE, "UTF-8");
|
||||
const std::string& str = charset.charset(std::string(keybuf, keybuf + keybuf_len));
|
||||
auto const charbuf = reinterpret_cast<const wchar_t*>(str.c_str());
|
||||
auto const len = str.size() / sizeof(wchar_t);
|
||||
#else
|
||||
auto wstr = nana::to_wstring(std::string{keybuf, keybuf + keybuf_len});
|
||||
auto const charbuf = wstr.c_str();
|
||||
auto const len = wstr.length();
|
||||
#endif
|
||||
|
||||
for(std::size_t i = 0; i < len; ++i)
|
||||
{
|
||||
|
@ -1108,7 +1108,7 @@ namespace paint
|
||||
::nana::color graphics::palette(bool for_text) const
|
||||
{
|
||||
if (impl_->handle)
|
||||
return static_cast<color_rgb>(for_text ? impl_->handle->get_text_color() : impl_->handle->get_color());
|
||||
return static_cast<color_rgb>(for_text ? impl_->handle->fgcolor_rgb : impl_->handle->bgcolor_rgb);
|
||||
|
||||
return{};
|
||||
}
|
||||
@ -1140,7 +1140,7 @@ namespace paint
|
||||
if (impl_->handle)
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
::SetPixel(impl_->handle->context, x, y, NANA_RGB(impl_->handle->get_color()));
|
||||
::SetPixel(impl_->handle->context, x, y, impl_->handle->bgcolor_native);
|
||||
#elif defined(NANA_X11)
|
||||
Display* disp = nana::detail::platform_spec::instance().open_display();
|
||||
impl_->handle->update_color();
|
||||
@ -1336,14 +1336,14 @@ namespace paint
|
||||
#if defined(NANA_WINDOWS)
|
||||
if (pos1 != pos2)
|
||||
{
|
||||
auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())));
|
||||
auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, impl_->handle->bgcolor_native));
|
||||
|
||||
::MoveToEx(impl_->handle->context, pos1.x, pos1.y, 0);
|
||||
::LineTo(impl_->handle->context, pos2.x, pos2.y);
|
||||
|
||||
::DeleteObject(::SelectObject(impl_->handle->context, prv_pen));
|
||||
}
|
||||
::SetPixel(impl_->handle->context, pos2.x, pos2.y, NANA_RGB(impl_->handle->get_color()));
|
||||
::SetPixel(impl_->handle->context, pos2.x, pos2.y, impl_->handle->bgcolor_native);
|
||||
#elif defined(NANA_X11)
|
||||
Display* disp = nana::detail::platform_spec::instance().open_display();
|
||||
impl_->handle->update_color();
|
||||
@ -1369,7 +1369,7 @@ namespace paint
|
||||
{
|
||||
if (!impl_->handle) return;
|
||||
#if defined(NANA_WINDOWS)
|
||||
auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())));
|
||||
auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, impl_->handle->bgcolor_native));
|
||||
|
||||
::LineTo(impl_->handle->context, pos.x, pos.y);
|
||||
|
||||
@ -1402,7 +1402,7 @@ namespace paint
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
|
||||
auto brush = ::CreateSolidBrush(NANA_RGB(impl_->handle->get_color()));
|
||||
auto brush = ::CreateSolidBrush(impl_->handle->bgcolor_native);
|
||||
|
||||
::RECT native_r = { r.x, r.y, r.right(), r.bottom()};
|
||||
|
||||
@ -1527,6 +1527,7 @@ namespace paint
|
||||
if (impl_->changed == false) impl_->changed = true;
|
||||
}
|
||||
|
||||
#define NANA_WINDOWS_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 )
|
||||
void graphics::round_rectangle(const ::nana::rectangle& r, unsigned radius_x, unsigned radius_y, const color& clr, bool solid, const color& solid_clr)
|
||||
{
|
||||
if (impl_->handle)
|
||||
@ -1536,8 +1537,8 @@ namespace paint
|
||||
|
||||
if (solid)
|
||||
{
|
||||
auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color())));
|
||||
auto prv_brush = ::SelectObject(impl_->handle->context, ::CreateSolidBrush(NANA_RGB(solid_clr.px_color().value)));
|
||||
auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, impl_->handle->bgcolor_native));
|
||||
auto prv_brush = ::SelectObject(impl_->handle->context, ::CreateSolidBrush(NANA_WINDOWS_RGB(solid_clr.px_color().value)));
|
||||
|
||||
::RoundRect(impl_->handle->context, r.x, r.y, r.right(), r.bottom(), static_cast<int>(radius_x * 2), static_cast<int>(radius_y * 2));
|
||||
|
||||
@ -1546,7 +1547,7 @@ namespace paint
|
||||
}
|
||||
else
|
||||
{
|
||||
auto brush = ::CreateSolidBrush(NANA_RGB(impl_->handle->get_color()));
|
||||
auto brush = ::CreateSolidBrush(impl_->handle->bgcolor_native);
|
||||
|
||||
auto region = ::CreateRoundRectRgn(r.x, r.y, r.x + static_cast<int>(r.width) + 1, r.y + static_cast<int>(r.height) + 1, static_cast<int>(radius_x + 1), static_cast<int>(radius_y + 1));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user