fix some compiler errors and warnings

This commit is contained in:
Jinhao 2016-10-31 06:36:03 +08:00
parent b1ce0eaff2
commit 043ebad317
2 changed files with 69 additions and 70 deletions

View File

@ -1117,9 +1117,9 @@ namespace nana
delete impl_;
}
auto menu::append(std::string text_utf8, const menu::event_fn_t& f) -> item_proxy
auto menu::append(std::string text_utf8, const menu::event_fn_t& callback) -> item_proxy
{
impl_->mbuilder.data().items.emplace_back(new item_type(std::move(text_utf8, callback));
impl_->mbuilder.data().items.emplace_back(new item_type(std::move(text_utf8), callback));
return item_proxy(size() - 1, *impl_->mbuilder.data().items.back());
}
@ -1159,7 +1159,7 @@ namespace nana
void menu::text(std::size_t index, std::string text_utf8)
{
impl_->mbuilder.data().items.at(index).text.swap(text_utf8);
impl_->mbuilder.data().items.at(index)->text.swap(text_utf8);
}
bool menu::link(std::size_t index, menu& menu_obj)

View File

@ -1,11 +1,11 @@
#ifndef NANA_PAINT_DETAIL_IMAGE_ICO_EX_HPP
#define NANA_PAINT_DETAIL_IMAGE_ICO_EX_HPP
#include "image_pixbuf.hpp"
namespace nana {
namespace paint {
namespace detail {
#ifndef NANA_PAINT_DETAIL_IMAGE_ICO_EX_HPP
#define NANA_PAINT_DETAIL_IMAGE_ICO_EX_HPP
#include "image_pixbuf.hpp"
namespace nana {
namespace paint {
namespace detail {
// These next two structs represent how the icon information is stored
// in an ICO file.
typedef struct
@ -52,21 +52,21 @@ typedef struct
uint8_t icXOR[1]; // DIB bits for XOR mask
uint8_t icAND[1]; // DIB bits for AND mask
} ICONIMAGE, *LPICONIMAGE;
class image_ico_ex
: public basic_image_pixbuf
{
bool _m_read_ico(const void* data, std::size_t size)
{
class image_ico_ex
: public basic_image_pixbuf
{
bool _m_read_ico(const void* data, std::size_t size)
{
auto width = 0;
auto height = 0;
auto buffer = (unsigned char *)data;
auto icoDir = reinterpret_cast<LPICONDIR>(buffer);
int iconsCount = icoDir->idCount;
if (icoDir->idReserved != 0 || icoDir->idType != 1 || iconsCount == 0 || iconsCount > 20)
if (icoDir->idReserved != 0 || icoDir->idType != 1 || iconsCount == 0 || iconsCount > 20)
return false;
auto cursor = buffer;
cursor += 6;
auto dirEntry = reinterpret_cast<ICONDIRENTRY*>(cursor);
@ -83,11 +83,11 @@ class image_ico_ex
width = w;
height = h;
offset = dirEntry->dwImageOffset;
maxSize = w * h;
maxSize = w * h;
maxBitCount = bitCount;
}
}
if (offset == 0) return false;
cursor = buffer;
@ -119,8 +119,8 @@ class image_ico_ex
{
for (auto x = 0; x < width; x++)
for (auto y = 0; y < height; y++)
{
pixbuf_.alpha_channel(true);
{
pixbuf_.alpha_channel(true);
auto shift2 = 3 * (x + (height - y - 1) * width);
pixel_color_t image;
image.element.red = cursor[shift2 + 2];
@ -138,10 +138,10 @@ class image_ico_ex
cursor += 256 * 4;
for (auto x = 0; x < width; x++)
for (auto y = 0; y < height; y++)
{
pixbuf_.alpha_channel(true);
auto shift2 = (x + (height - y - 1) * width);
{
pixbuf_.alpha_channel(true);
auto shift2 = (x + (height - y - 1) * width);
auto index = 4 * cursor[shift2];
pixel_color_t image;
image.element.red = colors[index + 2];
@ -159,8 +159,8 @@ class image_ico_ex
cursor += 16 * 4;
for (auto x = 0; x < width; x++)
for (auto y = 0; y < height; y++)
{
auto shift2 = (x + (height - y - 1) * width);
{
auto shift2 = (x + (height - y - 1) * width);
auto index = cursor[shift2 / 2];
if (shift2 % 2 == 0)
index = (index >> 4) & 0xF;
@ -186,8 +186,8 @@ class image_ico_ex
while (boundary % 32 != 0) boundary++;
for (auto x = 0; x < width; x++)
for (auto y = 0; y < height; y++)
{
auto shift2 = (x + (height - y - 1) * boundary);
{
auto shift2 = (x + (height - y - 1) * boundary);
auto index = cursor[shift2 / 8];
// select 1 bit only
@ -214,9 +214,9 @@ class image_ico_ex
while (boundary % 32 != 0) boundary++;
for (auto y = 0; y < height; y++)
for (auto x = 0; x < width; x++)
{
unsigned char bit = 7 - (x % 8);
auto shift2 = (x + (height - y - 1) * boundary) / 8;
{
unsigned char bit = 7 - (x % 8);
auto shift2 = (x + (height - y - 1) * boundary) / 8;
auto mask = (0x01 & (static_cast<unsigned char>(cursor[shift2]) >> bit));
auto pc = pixbuf_.pixel(x, y);
auto alpha = pc.element.alpha_channel;
@ -225,39 +225,38 @@ class image_ico_ex
pixbuf_.pixel(x, y, pc);
}
}
return true;
}
public:
bool open(const std::experimental::filesystem::path& ico_file) override
{
std::ifstream file(ico_file.string(), std::ios::binary);
if (!file.is_open()) return false;
// allocates a buffer for the image
std::streampos size = 0;
file.seekg(0, std::ios::end);
size = file.tellg() - size;
file.seekg(0, std::ios::beg);
auto buffer = new char[size];
// read data from the file and set them in the buffer
file.read(buffer, size);
auto okret = _m_read_ico(buffer, size);
// delete buffer and return
delete[] buffer;
return okret;
}
bool open(const void* data, std::size_t bytes) override
{
return _m_read_ico(data, bytes);
}
};
}//end namespace detail
}//end namespace paint
}//end namespace nana
return true;
}
public:
bool open(const std::experimental::filesystem::path& ico_file) override
{
std::ifstream file(ico_file.string(), std::ios::binary);
if (!file.is_open()) return false;
// allocates a buffer for the image
file.seekg(0, std::ios::end);
const auto bytes = static_cast<std::size_t>(file.tellg());
file.seekg(0, std::ios::beg);
auto buffer = new char[bytes];
// read data from the file and set them in the buffer
file.read(buffer, bytes);
auto okret = _m_read_ico(buffer, bytes);
// delete buffer and return
delete[] buffer;
return okret;
}
bool open(const void* data, std::size_t bytes) override
{
return _m_read_ico(data, bytes);
}
};
}//end namespace detail
}//end namespace paint
}//end namespace nana
#endif