Mac OS X support

This commit is contained in:
Benjamin Navarro 2015-10-11 18:31:30 +02:00
parent faa74047db
commit a09d5c3c95
28 changed files with 2223 additions and 154 deletions

1
.gitignore vendored
View File

@ -33,3 +33,4 @@ _ReSharper*/
*.suo *.suo
*.sdf *.sdf
lib/ lib/
*.DS_Store

View File

@ -19,11 +19,14 @@ if(BIICODE)
if(WIN32) if(WIN32)
file(GLOB_RECURSE platform_files "*/detail/win32/*") file(GLOB_RECURSE platform_files "*/detail/win32/*")
list(APPEND BII_LIB_SRC ${platform_files}) list(APPEND BII_LIB_SRC ${platform_files})
elseif(APPLE)
file(GLOB_RECURSE platform_files "*/detail/macos_X11/*")
list(APPEND BII_LIB_SRC ${platform_files})
elseif(UNIX) elseif(UNIX)
file(GLOB_RECURSE platform_files "*/detail/linux_X11/*") file(GLOB_RECURSE platform_files "*/detail/linux_X11/*")
list(APPEND BII_LIB_SRC ${platform_files}) list(APPEND BII_LIB_SRC ${platform_files})
else() else()
message(FATAL_ERROR "Only Windows and Unix are supported for the moment") message(FATAL_ERROR "Only Windows and Unix are supported for the moment (Mac OS is experimental)")
endif() endif()
# set compile flags # set compile flags
@ -61,7 +64,13 @@ if(WIN32)
endif() endif()
endif() endif()
endif() endif()
if(UNIX) if(APPLE)
add_definitions(-DNANA_MACOS)
add_definitions(-DNANA_X11)
add_definitions(-DPLATFORM_SPEC_HPP=<nana/detail/macos_X11/platform_spec.hpp>)
add_definitions(-DSTD_CODECVT_NOT_SUPPORTED)
include_directories(/opt/X11/include/)
elseif(UNIX)
add_definitions(-DNANA_LINUX) add_definitions(-DNANA_LINUX)
add_definitions(-DNANA_X11) add_definitions(-DNANA_X11)
add_definitions(-DPLATFORM_SPEC_HPP=<nana/detail/linux_X11/platform_spec.hpp>) add_definitions(-DPLATFORM_SPEC_HPP=<nana/detail/linux_X11/platform_spec.hpp>)
@ -133,8 +142,10 @@ include_directories(${NANA_INCLUDE_DIR})
aux_source_directory(${NANA_SOURCE_DIR} NANA_SOURCE) aux_source_directory(${NANA_SOURCE_DIR} NANA_SOURCE)
aux_source_directory(${NANA_SOURCE_DIR}/detail NANA_DETAIL_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/detail NANA_DETAIL_SOURCE)
aux_source_directory(${NANA_SOURCE_DIR}/filesystem NANA_FILESYSTEM_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/filesystem NANA_FILESYSTEM_SOURCE)
if(NOT APPLE)
aux_source_directory(${NANA_SOURCE_DIR}/audio NANA_AUDIO_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/audio NANA_AUDIO_SOURCE)
aux_source_directory(${NANA_SOURCE_DIR}/audio/detail NANA_AUDIO_DETAIL_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/audio/detail NANA_AUDIO_DETAIL_SOURCE)
endif()
aux_source_directory(${NANA_SOURCE_DIR}/gui NANA_GUI_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/gui NANA_GUI_SOURCE)
aux_source_directory(${NANA_SOURCE_DIR}/gui/detail NANA_GUI_DETAIL_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/gui/detail NANA_GUI_DETAIL_SOURCE)
aux_source_directory(${NANA_SOURCE_DIR}/gui/widgets NANA_GUI_WIDGETS_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/gui/widgets NANA_GUI_WIDGETS_SOURCE)
@ -147,8 +158,10 @@ aux_source_directory(${NANA_SOURCE_DIR}/threads NANA_THREADS_SOURCE)
add_library(${PROJECT_NAME} ${NANA_SOURCE} add_library(${PROJECT_NAME} ${NANA_SOURCE}
${NANA_DETAIL_SOURCE} ${NANA_DETAIL_SOURCE}
${NANA_FILESYSTEM_SOURCE} ${NANA_FILESYSTEM_SOURCE}
#if(NOT APPLE)
${NANA_AUDIO_SOURCE} ${NANA_AUDIO_SOURCE}
${NANA_AUDIO_DETAIL_SOURCE} ${NANA_AUDIO_DETAIL_SOURCE}
#endif
${NANA_GUI_SOURCE} ${NANA_GUI_SOURCE}
${NANA_GUI_DETAIL_SOURCE} ${NANA_GUI_DETAIL_SOURCE}
${NANA_GUI_WIDGETS_SOURCE} ${NANA_GUI_WIDGETS_SOURCE}
@ -156,10 +169,19 @@ add_library(${PROJECT_NAME} ${NANA_SOURCE}
${NANA_PAINT_SOURCE} ${NANA_PAINT_SOURCE}
${NANA_PAINT_DETAIL_SOURCE} ${NANA_PAINT_DETAIL_SOURCE}
${NANA_SYSTEM_SOURCE} ${NANA_SYSTEM_SOURCE}
${NANA_THREADS_SOURCE}) ${NANA_THREADS_SOURCE})
#if(APPLE)
target_link_libraries(${PROJECT_NAME} -L/opt/X11/lib/ -lX11 -lXft -lpng -liconv)
#endif()
install(TARGETS ${PROJECT_NAME} install(TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib) LIBRARY DESTINATION lib)
install(DIRECTORY ${NANA_INCLUDE_DIR}/nana DESTINATION include) install(DIRECTORY ${NANA_INCLUDE_DIR}/nana DESTINATION include)
set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14 ) set_property( TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14 )
add_executable(nana_test test.cpp)
set_property( TARGET nana_test PROPERTY CXX_STANDARD 14 )
target_link_libraries(nana_test ${PROJECT_NAME})

View File

@ -1,7 +1,7 @@
/* /*
* Nana Configuration * Nana Configuration
* Nana C++ Library(http://www.nanapro.org) * Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
* *
* Distributed under the Boost Software License, Version 1.0. * Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at * (See accompanying file LICENSE_1_0.txt or copy at
@ -13,78 +13,6 @@
#ifndef NANA_CONFIG_HPP #ifndef NANA_CONFIG_HPP
#define NANA_CONFIG_HPP #define NANA_CONFIG_HPP
//All defines have been moved to the CMakelists.txt in the root directory.
#if defined(_MSC_VER)
#define _SCL_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning(disable : 4996)
#if (_MSC_VER < 1900)
// is this a good idea?
#define NOT_IMPLEMENTED_KEYWORD_noexcept
#endif // _MSC_VER < 1900
#if (_MSC_VER == 1900)
// google: break any code that tries to use codecvt<char16_t> or codecvt<char32_t>.
// google: It appears the C++ libs haven't been compiled with native char16_t/char32_t support.
// google: Those definitions are for codecvt<wchar_t>::id, codecvt<unsigned short>::id and codecvt<char>::id respectively.
// However, the codecvt<char16_t>::id and codecvt<char32_t>::id definitions aren't there, and indeed, if you look at locale0.cpp in the CRT source code you'll see they're not defined at all.
// google: That's a known issue, tracked by an active bug (DevDiv#1060849). We were able to update the STL's headers in response to char16_t/char32_t, but we still need to update the separately compiled sources.
#define STD_CODECVT_NOT_SUPPORTED
#endif // _MSC_VER == 1900
#endif // _MSVC
//Select platform automatically
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
//Windows:
#define NANA_WINDOWS 1
#define PLATFORM_SPEC_HPP <nana/detail/win32/platform_spec.hpp>
//Test if it is MINGW
#if defined(__MINGW32__) || defined(__MINGW64__)
#define NANA_MINGW
#define STD_CODECVT_NOT_SUPPORTED
#if (__GNUC__ == 4) && ((__GNUC_MINOR__ < 8) || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ < 1))
//Use this flag if MinGW version is older than 4.8.1
#define STD_THREAD_NOT_SUPPORTED
#endif
#endif
#elif (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC)
//Linux:
#define NANA_LINUX 1
#define NANA_X11 1
#define PLATFORM_SPEC_HPP <nana/detail/linux_X11/platform_spec.hpp>
#define STD_CODECVT_NOT_SUPPORTED
#else
# static_assert(false, "Only Windows and Unix are supported now");
#endif
#if defined(NANA_MINGW) || defined(NANA_LINUX)
#if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ <= 1)
//Some functions which are specified in 21.5 Numeric conversions in Strings library have not yet implemented
#define STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED
#endif
#endif
//Here defines some flags that tell Nana what features will be supported.
#define NANA_UNICODE
#if defined(NANA_UNICODE) && defined(NANA_WINDOWS)
#ifndef _UNICODE
#define _UNICODE
#endif
#ifndef UNICODE
#define UNICODE
#endif
#endif
//Support for PNG
// Comment it to disable the feature of support for PNG.
//#define NANA_ENABLE_PNG
#if defined(NANA_ENABLE_PNG)
//Comment it to use libpng from operating system.
#define NANA_LIBPNG
#endif
#endif //NANA_CONFIG_HPP #endif //NANA_CONFIG_HPP

View File

@ -19,7 +19,7 @@
#include <nana/config.hpp> #include <nana/config.hpp>
#include <nana/charset.hpp> #include <nana/charset.hpp>
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
#undef NANA_WINDOWS #undef NANA_WINDOWS
#endif #endif
@ -111,7 +111,7 @@ namespace nana
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#define NANA_SHARED_EXPORT extern "C" _declspec(dllexport) #define NANA_SHARED_EXPORT extern "C" _declspec(dllexport)
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#define NANA_SHARED_EXPORT extern "C" #define NANA_SHARED_EXPORT extern "C"
#endif #endif

View File

@ -0,0 +1,32 @@
#ifndef NANA_DETAIL_MSG_PACKET_HPP
#define NANA_DETAIL_MSG_PACKET_HPP
#include <X11/Xlib.h>
#include <vector>
#include <nana/deploy.hpp>
namespace nana
{
namespace detail
{
struct msg_packet_tag
{
enum kind_t{kind_xevent, kind_mouse_drop, kind_cleanup};
kind_t kind;
union
{
XEvent xevent;
Window packet_window; //Avaiable if the packet is not kind_xevent
struct mouse_drop_tag
{
Window window;
int x;
int y;
std::vector<nana::string> * files;
}mouse_drop;
}u;
};
}//end namespace detail
}//end namespace nana
#endif

View File

@ -0,0 +1,325 @@
/*
* Platform Specification Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com)
*
* 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)
*
* @file: nana/detail/platform_spec.hpp
*
* This file provides basis class and data structrue that required by nana
* This file should not be included by any header files.
*/
#ifndef NANA_DETAIL_PLATFORM_SPEC_HPP
#define NANA_DETAIL_PLATFORM_SPEC_HPP
#include <thread>
#include <mutex>
#include <memory>
#include <condition_variable>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/Xos.h>
#include <nana/gui/basis.hpp>
#include <nana/paint/image.hpp>
#include <nana/paint/graphics.hpp>
#include <nana/gui/detail/event_code.hpp>
#include <vector>
#include <map>
#include "msg_packet.hpp"
#if defined(NANA_UNICODE)
#include <X11/Xft/Xft.h>
#include <iconv.h>
#include <fstream>
#endif
namespace nana
{
namespace detail
{
class msg_dispatcher;
#if defined(NANA_UNICODE)
class conf
{
public:
conf(const char * file);
bool open(const char* file);
std::string value(const char* key);
private:
std::ifstream ifs_;
};
class charset_conv
{
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
struct font_tag
{
nana::string name;
unsigned height;
unsigned weight;
bool italic;
bool underline;
bool strikeout;
#if defined(NANA_UNICODE)
XftFont * handle;
#else
XFontSet handle;
#endif
};
struct drawable_impl_type
{
typedef std::shared_ptr<font_tag> font_ptr_t;
Pixmap pixmap;
GC context;
font_ptr_t font;
nana::point line_begin_pos;
struct string_spec
{
unsigned tab_length;
unsigned tab_pixels;
unsigned whitespace_pixels;
}string;
#if defined(NANA_UNICODE)
XftDraw * xftdraw{nullptr};
XftColor xft_fgcolor;
const std::string charset(const nana::string& str, const std::string& strcode);
#endif
drawable_impl_type();
~drawable_impl_type();
void fgcolor(const ::nana::color&); //deprecated
void set_color(const ::nana::color&);
void set_text_color(const ::nana::color&);
void update_color();
void update_text_color();
private:
unsigned current_color_{ 0xFFFFFF };
unsigned color_{ 0xFFFFFFFF };
unsigned text_color_{ 0xFFFFFFFF };
#if defined(NANA_UNICODE)
struct conv_tag
{
iconv_t handle;
std::string code;
}conv_;
#endif
};
struct atombase_tag
{
Atom wm_protocols;
//window manager support
Atom wm_change_state;
Atom wm_delete_window;
//ext
Atom net_wm_state;
Atom net_wm_state_skip_taskbar;
Atom net_wm_state_fullscreen;
Atom net_wm_state_maximized_horz;
Atom net_wm_state_maximized_vert;
Atom net_wm_state_modal;
Atom net_wm_name;
Atom net_wm_window_type;
Atom net_wm_window_type_normal;
Atom net_wm_window_type_utility;
Atom net_wm_window_type_dialog;
Atom motif_wm_hints;
Atom clipboard;
Atom text;
Atom text_uri_list;
Atom utf8_string;
Atom targets;
Atom xdnd_aware;
Atom xdnd_enter;
Atom xdnd_position;
Atom xdnd_status;
Atom xdnd_action_copy;
Atom xdnd_drop;
Atom xdnd_selection;
Atom xdnd_typelist;
Atom xdnd_finished;
};
struct caret_tag;
class timer_runner;
class platform_scope_guard
{
public:
platform_scope_guard();
~platform_scope_guard();
};
class platform_spec
{
typedef platform_spec self_type;
struct window_context_t
{
native_window_type owner;
std::vector<native_window_type> * owned;
};
public:
int error_code;
public:
typedef drawable_impl_type::font_ptr_t font_ptr_t;
typedef void (*timer_proc_type)(unsigned tid);
typedef void (*event_proc_type)(Display*, msg_packet_tag&);
typedef ::nana::event_code event_code;
typedef ::nana::native_window_type native_window_type;
platform_spec();
~platform_spec();
const font_ptr_t& default_native_font() const;
void default_native_font(const font_ptr_t&);
unsigned font_size_to_height(unsigned) const;
unsigned font_height_to_size(unsigned) const;
font_ptr_t make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strick_out);
Display* open_display();
void close_display();
void lock_xlib();
void unlock_xlib();
Window root_window();
int screen_depth();
Visual* screen_visual();
Colormap& colormap();
static self_type& instance();
const atombase_tag & atombase() const;
void make_owner(native_window_type owner, native_window_type wd);
native_window_type get_owner(native_window_type) const;
void remove(native_window_type);
void write_keystate(const XKeyEvent&);
void read_keystate(XKeyEvent&);
XIC caret_input_context(native_window_type) const;
void caret_open(native_window_type, const ::nana::size&);
void caret_close(native_window_type);
void caret_pos(native_window_type, const ::nana::point&);
void caret_visible(native_window_type, bool);
void caret_flash(caret_tag&);
bool caret_update(native_window_type, nana::paint::graphics& root_graph, bool is_erase_caret_from_root_graph);
static bool caret_reinstate(caret_tag&);
void set_error_handler();
int rev_error_handler();
//grab
//register a grab window while capturing it if it is unviewable.
//when native_interface::show a window that is registered as a grab
//window, the native_interface grabs the window.
Window grab(Window);
void set_timer(std::size_t id, std::size_t interval, void (*timer_proc)(std::size_t id));
void kill_timer(std::size_t id);
void timer_proc(unsigned tid);
//Message dispatcher
void msg_insert(native_window_type);
void msg_set(timer_proc_type, event_proc_type);
void msg_dispatch(native_window_type modal);
//X Selections
void* request_selection(native_window_type requester, Atom type, size_t & bufsize);
void write_selection(native_window_type owner, Atom type, const void* buf, size_t bufsize);
//Icon storage
//@biref: The image object should be kept for a long time till the window is closed,
// the image object is release in remove() method.
const nana::paint::graphics& keep_window_icon(native_window_type, const nana::paint::image&);
private:
static int _m_msg_filter(XEvent&, msg_packet_tag&);
void _m_caret_routine();
private:
Display* display_;
Colormap colormap_;
atombase_tag atombase_;
font_ptr_t def_font_ptr_;
XKeyEvent key_state_;
int (*def_X11_error_handler_)(Display*, XErrorEvent*);
Window grab_;
std::recursive_mutex xlib_locker_;
struct caret_holder_tag
{
volatile bool exit_thread;
std::unique_ptr<std::thread> thr;
std::map<native_window_type, caret_tag*> carets;
}caret_holder_;
std::map<native_window_type, window_context_t> wincontext_;
std::map<native_window_type, nana::paint::graphics> iconbase_;
struct timer_runner_tag
{
timer_runner * runner;
std::recursive_mutex mutex;
bool delete_declared;
timer_runner_tag();
}timer_;
struct selection_tag
{
struct item_t
{
Atom type;
Window requestor;
void* buffer;
size_t bufsize;
std::mutex cond_mutex;
std::condition_variable cond;
};
std::vector<item_t*> items;
struct content_tag
{
std::string * utf8_string;
}content;
}selection_;
struct xdnd_tag
{
Atom good_type;
int timestamp;
Window wd_src;
nana::point pos;
}xdnd_;
msg_dispatcher * msg_dispatcher_;
};//end class platform_X11
}//end namespace detail
}//end namespace nana
#endif

View File

@ -22,7 +22,7 @@
#ifdef NANA_WINDOWS #ifdef NANA_WINDOWS
#include <windows.h> #include <windows.h>
typedef HANDLE find_handle_t; typedef HANDLE find_handle_t;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
@ -38,7 +38,7 @@ namespace filesystem
fileinfo(); fileinfo();
#ifdef NANA_WINDOWS #ifdef NANA_WINDOWS
fileinfo(const WIN32_FIND_DATA& wfd); fileinfo(const WIN32_FIND_DATA& wfd);
#elif NANA_LINUX #elif NANA_LINUX or NANA_MACOS
fileinfo(const nana::string& filename, const struct stat &); fileinfo(const nana::string& filename, const struct stat &);
#endif #endif
nana::string name; nana::string name;
@ -119,7 +119,7 @@ namespace filesystem
} }
} }
value_ = value_type(wfd_); value_ = value_type(wfd_);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
path_ = nana::charset(file_path); path_ = nana::charset(file_path);
if(path_.size() && (path_[path_.size() - 1] != '/')) if(path_.size() && (path_[path_.size() - 1] != '/'))
path_ += '/'; path_ += '/';
@ -181,7 +181,7 @@ namespace filesystem
} }
else else
end_ = true; end_ = true;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct dirent * dnt = readdir(handle_); struct dirent * dnt = readdir(handle_);
if(dnt) if(dnt)
{ {
@ -214,7 +214,7 @@ namespace filesystem
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::FindClose(*handle); ::FindClose(*handle);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
::closedir(*handle); ::closedir(*handle);
#endif #endif
} }
@ -227,7 +227,7 @@ namespace filesystem
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
WIN32_FIND_DATA wfd_; WIN32_FIND_DATA wfd_;
nana::string path_; nana::string path_;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::string path_; std::string path_;
#endif #endif
std::shared_ptr<find_handle_t> find_ptr_; std::shared_ptr<find_handle_t> find_ptr_;

View File

@ -42,7 +42,7 @@
#ifdef NANA_WINDOWS #ifdef NANA_WINDOWS
#include <windows.h> #include <windows.h>
typedef HANDLE find_handle_t; typedef HANDLE find_handle_t;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
@ -264,7 +264,7 @@ namespace filesystem
(FILE_ATTRIBUTE_DIRECTORY & wfd_.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY, (FILE_ATTRIBUTE_DIRECTORY & wfd_.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY,
wfd_.nFileSizeLow); wfd_.nFileSizeLow);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
path_ = nana::charset(file_path); path_ = nana::charset(file_path);
if(path_.size() && (path_[path_.size() - 1] != '/')) if(path_.size() && (path_[path_.size() - 1] != '/'))
path_ += '/'; path_ += '/';
@ -326,7 +326,7 @@ namespace filesystem
} }
else else
end_ = true; end_ = true;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct dirent * dnt = readdir(handle_); struct dirent * dnt = readdir(handle_);
if(dnt) if(dnt)
{ {
@ -361,7 +361,7 @@ namespace filesystem
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::FindClose(*handle); ::FindClose(*handle);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
::closedir(*handle); ::closedir(*handle);
#endif #endif
} }
@ -374,7 +374,7 @@ namespace filesystem
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
WIN32_FIND_DATA wfd_; WIN32_FIND_DATA wfd_;
nana::string path_; nana::string path_;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::string path_; std::string path_;
#endif #endif
std::shared_ptr<find_handle_t> find_ptr_; std::shared_ptr<find_handle_t> find_ptr_;

View File

@ -128,7 +128,7 @@ namespace detail
void _m_init_pos_and_size(basic_window* parent, const rectangle&); void _m_init_pos_and_size(basic_window* parent, const rectangle&);
void _m_initialize(basic_window* parent); void _m_initialize(basic_window* parent);
public: public:
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
point pos_native; point pos_native;
#endif #endif
point pos_root; //coordinate for root window point pos_root; //coordinate for root window

View File

@ -284,7 +284,7 @@ namespace nana
std::u32string utf32str = std::wstring_convert<std::codecvt_utf16<char32_t>, char32_t>().from_bytes(bytes, bytes + sizeof(wchar_t) * wcstr.size()); std::u32string utf32str = std::wstring_convert<std::codecvt_utf16<char32_t>, char32_t>().from_bytes(bytes, bytes + sizeof(wchar_t) * wcstr.size());
return std::string(reinterpret_cast<const char*>(utf32str.c_str()), sizeof(char32_t) * utf32str.size()); return std::string(reinterpret_cast<const char*>(utf32str.c_str()), sizeof(char32_t) * utf32str.size());
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
return std::string(reinterpret_cast<const char*>(wcstr.c_str()), sizeof(wchar_t) * wcstr.size()); return std::string(reinterpret_cast<const char*>(wcstr.c_str()), sizeof(wchar_t) * wcstr.size());
#else #else
throw std::runtime_error("Bad charset"); throw std::runtime_error("Bad charset");
@ -376,7 +376,7 @@ namespace nana
std::u32string utf32str = std::wstring_convert<std::codecvt_utf16<char32_t>, char32_t>().from_bytes(bytes, bytes + sizeof(wchar_t) * data_.size()); std::u32string utf32str = std::wstring_convert<std::codecvt_utf16<char32_t>, char32_t>().from_bytes(bytes, bytes + sizeof(wchar_t) * data_.size());
return std::string(reinterpret_cast<const char*>(utf32str.c_str()), sizeof(char32_t) * utf32str.size()); return std::string(reinterpret_cast<const char*>(utf32str.c_str()), sizeof(char32_t) * utf32str.size());
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
return std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t)); return std::string(reinterpret_cast<const char*>(data_.c_str()), data_.size() * sizeof(wchar_t));
#else #else
throw std::runtime_error("Bad charset"); throw std::runtime_error("Bad charset");

View File

@ -18,7 +18,7 @@
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#include <windows.h> #include <windows.h>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <string.h> #include <string.h>
#include PLATFORM_SPEC_HPP #include PLATFORM_SPEC_HPP
#endif #endif

View File

@ -0,0 +1,341 @@
/*
* Message Dispatcher Implementation
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
*
* 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)
*
* @file: nana/detail/msg_dispatcher.hpp
*
* @DO NOT INCLUDE THIS HEADER FILE IN YOUR SOURCE FILE!!
*
* This class msg_dispatcher provides a simulation of Windows-like message
* dispatcher. Every event is dispatched into its own message queue for
* corresponding thread.
*/
#ifndef NANA_DETAIL_MSG_DISPATCHER_HPP
#define NANA_DETAIL_MSG_DISPATCHER_HPP
#include <nana/detail/linux_X11/msg_packet.hpp>
#include <nana/system/platform.hpp>
#include <list>
#include <set>
#include <map>
#include <mutex>
#include <condition_variable>
#include <memory>
#include <thread>
namespace nana
{
namespace detail
{
class msg_dispatcher
{
struct thread_binder
{
unsigned tid;
std::mutex mutex;
std::condition_variable cond;
std::list<msg_packet_tag> msg_queue;
std::set<Window> window;
};
public:
typedef msg_packet_tag msg_packet;
typedef void (*timer_proc_type)(unsigned tid);
typedef void (*event_proc_type)(Display*, msg_packet_tag&);
typedef int (*event_filter_type)(XEvent&, msg_packet_tag&);
typedef std::list<msg_packet_tag> msg_queue_type;
msg_dispatcher(Display* disp)
: display_(disp), is_work_(false)
{
proc_.event_proc = 0;
proc_.timer_proc = 0;
proc_.filter_proc = 0;
}
void set(timer_proc_type timer_proc, event_proc_type event_proc, event_filter_type filter)
{
proc_.timer_proc = timer_proc;
proc_.event_proc = event_proc;
proc_.filter_proc = filter;
}
void insert(Window wd)
{
unsigned tid = nana::system::this_thread_id();
bool start_driver;
{
std::lock_guard<decltype(table_.mutex)> lock(table_.mutex);
//No thread is running, so msg dispatcher should start the msg driver.
start_driver = (0 == table_.thr_table.size());
thread_binder * thr;
std::map<unsigned, thread_binder*>::iterator i = table_.thr_table.find(tid);
if(i == table_.thr_table.end())
{
thr = new thread_binder;
thr->tid = tid;
table_.thr_table.insert(std::make_pair(tid, thr));
}
else
thr = i->second;
thr->mutex.lock();
thr->window.insert(wd);
thr->mutex.unlock();
table_.wnd_table[wd] = thr;
}
if(start_driver && proc_.event_proc && proc_.timer_proc)
{
//It should start the msg driver, before starting it, the msg driver must be inactive.
if(thrd_)
{
is_work_ = false;
thrd_->join();
}
is_work_ = true;
thrd_ = std::unique_ptr<std::thread>(new std::thread([this](){ this->_m_msg_driver(); }));
}
}
void erase(Window wd)
{
std::lock_guard<decltype(table_.mutex)> lock(table_.mutex);
auto i = table_.wnd_table.find(wd);
if(i != table_.wnd_table.end())
{
thread_binder * const thr = i->second;
std::lock_guard<decltype(thr->mutex)> lock(thr->mutex);
for(auto li = thr->msg_queue.begin(); li != thr->msg_queue.end();)
{
if(wd == _m_window(*li))
li = thr->msg_queue.erase(li);
else
++li;
}
table_.wnd_table.erase(i);
thr->window.erase(wd);
//There still is at least one window alive.
if(thr->window.size())
{
//Make a cleanup msg packet to infor the dispatcher the window is closed.
msg_packet_tag msg;
msg.kind = msg.kind_cleanup;
msg.u.packet_window = wd;
thr->msg_queue.push_back(msg);
}
}
}
void dispatch(Window modal)
{
unsigned tid = nana::system::this_thread_id();
msg_packet_tag msg;
int qstate;
//Test whether the thread is registered for window, and retrieve the queue state for event
while((qstate = _m_read_queue(tid, msg, modal)))
{
//the queue is empty
if(-1 == qstate)
{
if(false == _m_wait_for_queue(tid))
proc_.timer_proc(tid);
}
else
{
proc_.event_proc(display_, msg);
}
}
}
private:
void _m_msg_driver()
{
int fd_X11 = ConnectionNumber(display_);
msg_packet_tag msg_pack;
XEvent event;
while(is_work_)
{
int pending;
{
nana::detail::platform_scope_guard lock;
pending = ::XPending(display_);
if(pending)
{
::XNextEvent(display_, &event);
if(::XFilterEvent(&event, None))
continue;
}
}
if(0 == pending)
{
fd_set fdset;
FD_ZERO(&fdset);
FD_SET(fd_X11, &fdset);
struct timeval tv;
tv.tv_usec = 10000;
tv.tv_sec = 0;
::select(fd_X11 + 1, &fdset, 0, 0, &tv);
}
else
{
switch(proc_.filter_proc(event, msg_pack))
{
case 0:
msg_pack.kind = msg_pack.kind_xevent;
msg_pack.u.xevent = event;
case 1:
_m_msg_dispatch(msg_pack);
}
}
}
}
private:
static Window _m_event_window(const XEvent& event)
{
switch(event.type)
{
case MapNotify:
case UnmapNotify:
return event.xmap.window;
}
return event.xkey.window;
}
static Window _m_window(const msg_packet_tag& pack)
{
switch(pack.kind)
{
case msg_packet_tag::kind_xevent:
return _m_event_window(pack.u.xevent);
case msg_packet_tag::kind_mouse_drop:
return pack.u.mouse_drop.window;
default:
break;
}
return 0;
}
void _m_msg_dispatch(const msg_packet_tag &msg)
{
std::lock_guard<decltype(table_.mutex)> lock(table_.mutex);
auto i = table_.wnd_table.find(_m_window(msg));
if(i != table_.wnd_table.end())
{
thread_binder * const thr = i->second;
std::lock_guard<decltype(thr->mutex)> lock(thr->mutex);
thr->msg_queue.push_back(msg);
thr->cond.notify_one();
}
}
//_m_read_queue
//@brief:Read the event from a specified thread queue.
//@return: 0 = exit the queue, 1 = fetch the msg, -1 = no msg
int _m_read_queue(unsigned tid, msg_packet_tag& msg, Window modal)
{
bool stop_driver = false;
{
std::lock_guard<decltype(table_.mutex)> lock(table_.mutex);
//Find the thread whether it is registered for the window.
auto i = table_.thr_table.find(tid);
if(i != table_.thr_table.end())
{
if(i->second->window.size())
{
msg_queue_type & queue = i->second->msg_queue;
if(queue.size())
{
msg = queue.front();
queue.pop_front();
//Check whether the event dispatcher is used for the modal window
//and when the modal window is closing, the event dispatcher would
//stop event pumping.
if((modal == msg.u.packet_window) && (msg.kind == msg.kind_cleanup))
return 0;
return 1;
}
else
return -1;
}
delete i->second;
table_.thr_table.erase(i);
stop_driver = (table_.thr_table.size() == 0);
}
}
if(stop_driver)
{
is_work_ = false;
thrd_->join();
thrd_.reset();
}
return 0;
}
//_m_wait_for_queue
// wait for the insertion of queue.
//return@ it returns true if the queue is not empty, otherwise the wait is timeout.
bool _m_wait_for_queue(unsigned tid)
{
thread_binder * thr = nullptr;
{
std::lock_guard<decltype(table_.mutex)> lock(table_.mutex);
auto i = table_.thr_table.find(tid);
if(i != table_.thr_table.end())
{
if(i->second->msg_queue.size())
return true;
thr = i->second;
}
}
//Waits for notifying the condition variable, it indicates a new msg is pushing into the queue.
std::unique_lock<decltype(thr->mutex)> lock(thr->mutex);
return (thr->cond.wait_for(lock, std::chrono::milliseconds(10)) != std::cv_status::timeout);
}
private:
Display * display_;
volatile bool is_work_;
std::unique_ptr<std::thread> thrd_;
struct table_tag
{
std::recursive_mutex mutex;
std::map<unsigned, thread_binder*> thr_table;
std::map<Window, thread_binder*> wnd_table;
}table_;
struct proc_tag
{
timer_proc_type timer_proc;
event_proc_type event_proc;
event_filter_type filter_proc;
}proc_;
};
}//end namespace detail
}//end namespace nana
#endif

File diff suppressed because it is too large Load Diff

View File

@ -19,4 +19,6 @@
#include "win32/platform_spec.cpp" #include "win32/platform_spec.cpp"
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX)
#include "linux_X11/platform_spec.cpp" #include "linux_X11/platform_spec.cpp"
#elif defined(NANA_MACOS)
#include "macos_X11/platform_spec.cpp"
#endif #endif

View File

@ -28,7 +28,7 @@ namespace filesystem
directory((FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) directory((FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY)
{ {
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
fileinfo::fileinfo(const nana::string& name, const struct stat& fst) fileinfo::fileinfo(const nana::string& name, const struct stat& fst)
:name(name), size(fst.st_size), directory(0 != S_ISDIR(fst.st_mode)) :name(name), size(fst.st_size), directory(0 != S_ISDIR(fst.st_mode))
{ {

View File

@ -24,7 +24,7 @@
#include <shlobj.h> #include <shlobj.h>
#include <nana/datetime.hpp> #include <nana/datetime.hpp>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <nana/charset.hpp> #include <nana/charset.hpp>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -42,7 +42,7 @@ namespace nana {
namespace filesystem namespace filesystem
{ {
//Because of No wide character version of POSIX //Because of No wide character version of POSIX
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
typedef std::string string_t; typedef std::string string_t;
const char* splstr = "/\\"; const char* splstr = "/\\";
#else #else
@ -69,7 +69,7 @@ namespace nana {
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
return (::GetFileAttributes(text_.c_str()) == INVALID_FILE_ATTRIBUTES); return (::GetFileAttributes(text_.c_str()) == INVALID_FILE_ATTRIBUTES);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat sta; struct stat sta;
return (::stat(text_.c_str(), &sta) == -1); return (::stat(text_.c_str(), &sta) == -1);
#endif #endif
@ -79,7 +79,7 @@ namespace nana {
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
return path(filesystem::root(text_)); return path(filesystem::root(text_));
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
return path(filesystem::root(nana::charset(text_))); return path(filesystem::root(nana::charset(text_)));
#endif #endif
} }
@ -95,7 +95,7 @@ namespace nana {
return file_type::directory; return file_type::directory;
return file_type::regular; return file_type::regular;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat sta; struct stat sta;
if (-1 == ::stat(text_.c_str(), &sta)) if (-1 == ::stat(text_.c_str(), &sta))
return file_type::not_found; //?? return file_type::not_found; //??
@ -154,7 +154,7 @@ namespace nana {
} }
if_exist = (::GetLastError() == ERROR_ALREADY_EXISTS); if_exist = (::GetLastError() == ERROR_ALREADY_EXISTS);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if (0 == ::mkdir(static_cast<std::string>(nana::charset(dir)).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) if (0 == ::mkdir(static_cast<std::string>(nana::charset(dir)).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
{ {
if_exist = false; if_exist = false;
@ -202,7 +202,7 @@ namespace nana {
detail::filetime_to_c_tm(fad.ftLastWriteTime, attr.modified); detail::filetime_to_c_tm(fad.ftLastWriteTime, attr.modified);
return true; return true;
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat fst; struct stat fst;
if (0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &fst)) if (0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &fst))
{ {
@ -245,6 +245,16 @@ namespace nana {
fclose(stream); fclose(stream);
} }
return size; return size;
#elif defined(NANA_MACOS)
FILE * stream = ::fopen(static_cast<std::string>(nana::charset(file)).c_str(), "rb");
long long size = 0;
if (stream)
{
fseeko(stream, 0, SEEK_END);
size = ftello(stream);
fclose(stream);
}
return size;
#endif #endif
} }
@ -271,7 +281,7 @@ namespace nana {
return true; return true;
} }
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat attr; struct stat attr;
if (0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &attr)) if (0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &attr))
{ {
@ -291,7 +301,7 @@ namespace nana {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
if (path.size() > 3 && path[1] == STR(':')) if (path.size() > 3 && path[1] == STR(':'))
root = path.substr(0, 3); root = path.substr(0, 3);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if (path[0] == STR('/')) if (path[0] == STR('/'))
root = '/'; root = '/';
#endif #endif
@ -315,7 +325,7 @@ namespace nana {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
root += STR('\\'); root += STR('\\');
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
root += STR('/'); root += STR('/');
#endif #endif
} }
@ -345,7 +355,7 @@ namespace nana {
} }
return ret; return ret;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if (std::remove(static_cast<std::string>(nana::charset(file)).c_str())) if (std::remove(static_cast<std::string>(nana::charset(file)).c_str()))
return (errno == ENOENT); return (errno == ENOENT);
return true; return true;
@ -361,7 +371,7 @@ namespace nana {
ret = (::RemoveDirectory(dir) == TRUE); ret = (::RemoveDirectory(dir) == TRUE);
if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY)) if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY))
ret = detail::rm_dir_recursive(dir); ret = detail::rm_dir_recursive(dir);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::string mbstr = nana::charset(dir); std::string mbstr = nana::charset(dir);
if (::rmdir(mbstr.c_str())) if (::rmdir(mbstr.c_str()))
{ {
@ -407,7 +417,7 @@ namespace nana {
nana::char_t path[MAX_PATH]; nana::char_t path[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path))) if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path)))
return path; return path;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
const char * s = ::getenv("HOME"); const char * s = ::getenv("HOME");
if (s) if (s)
return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8);
@ -432,7 +442,7 @@ namespace nana {
} }
return buf; return buf;
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
const char * s = ::getenv("PWD"); const char * s = ::getenv("PWD");
if (s) if (s)
return static_cast<nana::string>(nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8)); return static_cast<nana::string>(nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8));

View File

@ -25,7 +25,7 @@
#include <shlobj.h> #include <shlobj.h>
#include <nana/datetime.hpp> #include <nana/datetime.hpp>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <nana/charset.hpp> #include <nana/charset.hpp>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
@ -42,7 +42,7 @@ namespace nana
namespace filesystem namespace filesystem
{ {
//Because of No wide character version of POSIX //Because of No wide character version of POSIX
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
typedef std::string string_t; typedef std::string string_t;
const char* splstr = "/\\"; const char* splstr = "/\\";
#else #else
@ -69,7 +69,7 @@ namespace filesystem
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
return (::GetFileAttributes(text_.c_str()) == INVALID_FILE_ATTRIBUTES); return (::GetFileAttributes(text_.c_str()) == INVALID_FILE_ATTRIBUTES);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat sta; struct stat sta;
return (::stat(text_.c_str(), &sta) == -1); return (::stat(text_.c_str(), &sta) == -1);
#endif #endif
@ -79,7 +79,7 @@ namespace filesystem
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
return path(filesystem::root(text_)); return path(filesystem::root(text_));
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
return path(filesystem::root(nana::charset(text_))); return path(filesystem::root(nana::charset(text_)));
#endif #endif
} }
@ -95,7 +95,7 @@ namespace filesystem
return type::directory; return type::directory;
return type::file; return type::file;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat sta; struct stat sta;
if(-1 == ::stat(text_.c_str(), &sta)) if(-1 == ::stat(text_.c_str(), &sta))
return type::not_exist; return type::not_exist;
@ -154,7 +154,7 @@ namespace filesystem
} }
if_exist = (::GetLastError() == ERROR_ALREADY_EXISTS); if_exist = (::GetLastError() == ERROR_ALREADY_EXISTS);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if(0 == ::mkdir(static_cast<std::string>(nana::charset(dir)).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) if(0 == ::mkdir(static_cast<std::string>(nana::charset(dir)).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))
{ {
if_exist = false; if_exist = false;
@ -202,7 +202,7 @@ namespace filesystem
detail::filetime_to_c_tm(fad.ftLastWriteTime, attr.modified); detail::filetime_to_c_tm(fad.ftLastWriteTime, attr.modified);
return true; return true;
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat fst; struct stat fst;
if(0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &fst)) if(0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &fst))
{ {
@ -245,6 +245,16 @@ namespace filesystem
fclose(stream); fclose(stream);
} }
return size; return size;
#elif defined(NANA_MACOS)
FILE * stream = ::fopen(static_cast<std::string>(nana::charset(file)).c_str(), "rb");
long long size = 0;
if (stream)
{
fseeko(stream, 0, SEEK_END);
size = ftello(stream);
fclose(stream);
}
return size;
#endif #endif
} }
@ -271,7 +281,7 @@ namespace filesystem
return true; return true;
} }
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct stat attr; struct stat attr;
if(0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &attr)) if(0 == ::stat(static_cast<std::string>(nana::charset(file)).c_str(), &attr))
{ {
@ -291,7 +301,7 @@ namespace filesystem
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
if(path.size() > 3 && path[1] == STR(':')) if(path.size() > 3 && path[1] == STR(':'))
root = path.substr(0, 3); root = path.substr(0, 3);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if(path[0] == STR('/')) if(path[0] == STR('/'))
root = '/'; root = '/';
#endif #endif
@ -315,7 +325,7 @@ namespace filesystem
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
root += STR('\\'); root += STR('\\');
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
root += STR('/'); root += STR('/');
#endif #endif
} }
@ -345,7 +355,7 @@ namespace filesystem
} }
return ret; return ret;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
if(std::remove(static_cast<std::string>(nana::charset(file)).c_str())) if(std::remove(static_cast<std::string>(nana::charset(file)).c_str()))
return (errno == ENOENT); return (errno == ENOENT);
return true; return true;
@ -361,7 +371,7 @@ namespace filesystem
ret = (::RemoveDirectory(dir) == TRUE); ret = (::RemoveDirectory(dir) == TRUE);
if(!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY)) if(!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY))
ret = detail::rm_dir_recursive(dir); ret = detail::rm_dir_recursive(dir);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::string mbstr = nana::charset(dir); std::string mbstr = nana::charset(dir);
if(::rmdir(mbstr.c_str())) if(::rmdir(mbstr.c_str()))
{ {
@ -407,7 +417,7 @@ namespace filesystem
nana::char_t path[MAX_PATH]; nana::char_t path[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path))) if(SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path)))
return path; return path;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
const char * s = ::getenv("HOME"); const char * s = ::getenv("HOME");
if(s) if(s)
return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8);
@ -432,7 +442,7 @@ namespace filesystem
} }
return buf; return buf;
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
const char * s = ::getenv("PWD"); const char * s = ::getenv("PWD");
if(s) if(s)
return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8);

View File

@ -17,7 +17,7 @@
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#include "win32/bedrock.cpp" #include "win32/bedrock.cpp"
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include "linux_X11/bedrock.cpp" #include "linux_X11/bedrock.cpp"
#endif #endif

View File

@ -675,7 +675,7 @@ namespace detail
if (impl_->wd_register.available(wd) && !wd->is_draw_through()) if (impl_->wd_register.available(wd) && !wd->is_draw_through())
{ {
//Copy the root buffer that wd specified into DeviceContext //Copy the root buffer that wd specified into DeviceContext
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
wd->drawer.map(reinterpret_cast<window>(wd), forced, update_area); wd->drawer.map(reinterpret_cast<window>(wd), forced, update_area);
#elif defined(NANA_WINDOWS) #elif defined(NANA_WINDOWS)
if(nana::system::this_thread_id() == wd->thread_id) if(nana::system::this_thread_id() == wd->thread_id)

View File

@ -16,7 +16,7 @@
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#include <windows.h> #include <windows.h>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <nana/gui/widgets/label.hpp> #include <nana/gui/widgets/label.hpp>
#include <nana/gui/widgets/button.hpp> #include <nana/gui/widgets/button.hpp>
#include <nana/gui/widgets/listbox.hpp> #include <nana/gui/widgets/listbox.hpp>
@ -32,7 +32,7 @@
namespace nana namespace nana
{ {
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
class filebox_implement class filebox_implement
: public form : public form
{ {
@ -1027,7 +1027,7 @@ namespace nana
return false; return false;
impl_->file.resize(nana::strlen(impl_->file.data())); impl_->file.resize(nana::strlen(impl_->file.data()));
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
filebox_implement fb(impl_->owner, impl_->open_or_save, impl_->title); filebox_implement fb(impl_->owner, impl_->open_or_save, impl_->title);
if(impl_->filters.size()) if(impl_->filters.size())

View File

@ -26,7 +26,7 @@
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#include <nana/detail/win32/platform_spec.hpp> #include <nana/detail/win32/platform_spec.hpp>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include PLATFORM_SPEC_HPP #include PLATFORM_SPEC_HPP
#include <nana/system/platform.hpp> #include <nana/system/platform.hpp>
#include <iostream> #include <iostream>

View File

@ -26,7 +26,7 @@
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#include <windows.h> #include <windows.h>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include PLATFORM_SPEC_HPP #include PLATFORM_SPEC_HPP
#include <nana/system/platform.hpp> #include <nana/system/platform.hpp>
#endif #endif

View File

@ -901,7 +901,7 @@ namespace nana
/// add a new cat created at "pos" and return a ref to it /// add a new cat created at "pos" and return a ref to it
category_t* create_cat(std::size_t pos, nana::string&& text) category_t* create_cat(std::size_t pos, nana::string&& text)
{ {
#if defined(NANA_LINUX) || defined(NANA_MINGW) #if defined(NANA_LINUX) || defined(NANA_MACOS) || defined(NANA_MINGW)
//Call begin instead of cbegin, because the first parameter //Call begin instead of cbegin, because the first parameter
//of emplace is not const_iterator in GCC's C++ standard //of emplace is not const_iterator in GCC's C++ standard
//library implementation. //library implementation.

View File

@ -933,7 +933,7 @@ namespace paint
{ {
const nana::char_t * end = str + len; const nana::char_t * end = str + len;
const nana::char_t * i = std::find(str, end, '\t'); const nana::char_t * i = std::find(str, end, '\t');
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
handle_->update_text_color(); handle_->update_text_color();
#endif #endif
if (i != end) if (i != end)

View File

@ -15,7 +15,7 @@
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#include <windows.h> #include <windows.h>
#include PLATFORM_SPEC_HPP #include PLATFORM_SPEC_HPP
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
@ -34,7 +34,7 @@ namespace system
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::Sleep(milliseconds); ::Sleep(milliseconds);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timespec timeOut, remains; struct timespec timeOut, remains;
timeOut.tv_sec = milliseconds / 1000; timeOut.tv_sec = milliseconds / 1000;
timeOut.tv_nsec = (milliseconds % 1000) * 1000000; timeOut.tv_nsec = (milliseconds % 1000) * 1000000;
@ -56,6 +56,8 @@ namespace system
return ::GetCurrentThreadId(); return ::GetCurrentThreadId();
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX)
return ::syscall(__NR_gettid); return ::syscall(__NR_gettid);
#elif defined(NANA_MACOS)
return ::syscall(SYS_thread_selfid);
#endif #endif
} }
@ -63,7 +65,7 @@ namespace system
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
return ::GetTickCount(); return ::GetTickCount();
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timeval tv; struct timeval tv;
::gettimeofday(&tv, 0); ::gettimeofday(&tv, 0);
return (tv.tv_sec * 1000 + tv.tv_usec / 1000); return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
@ -88,7 +90,7 @@ namespace system
} }
return (::GetAsyncKeyState(button) != 0); return (::GetAsyncKeyState(button) != 0);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
return false; return false;
#endif #endif
} }
@ -109,7 +111,7 @@ namespace system
nana::detail::platform_spec::co_initializer co_init; nana::detail::platform_spec::co_initializer co_init;
::ShellExecute(0, STR("open"), url.c_str(), 0, 0, SW_SHOWNORMAL); ::ShellExecute(0, STR("open"), url.c_str(), 0, 0, SW_SHOWNORMAL);
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#endif #endif
} }
}//end namespace system }//end namespace system

View File

@ -12,7 +12,7 @@
#include <nana/system/shared_wrapper.hpp> #include <nana/system/shared_wrapper.hpp>
#include <algorithm> #include <algorithm>
#include <iterator> #include <iterator>
#ifdef NANA_LINUX #if defined(NANA_LINUX) or defined(NANA_MACOS)
#include <dlfcn.h> #include <dlfcn.h>
#else #else
#include <windows.h> #include <windows.h>
@ -30,7 +30,7 @@ namespace system
module_t open(const char* filename) module_t open(const char* filename)
{ {
#ifdef NANA_LINUX #if defined(NANA_LINUX) or defined(NANA_MACOS)
return ::dlopen(filename, RTLD_LAZY); return ::dlopen(filename, RTLD_LAZY);
#else #else
return ::LoadLibraryA(filename); return ::LoadLibraryA(filename);
@ -39,7 +39,7 @@ namespace system
void* symbols(module_t handle, const char* symbol) void* symbols(module_t handle, const char* symbol)
{ {
#ifdef NANA_LINUX #if defined(NANA_LINUX) or defined(NANA_MACOS)
return ::dlsym(handle, const_cast<char*>(symbol)); return ::dlsym(handle, const_cast<char*>(symbol));
#else #else
return (void*)(::GetProcAddress(reinterpret_cast<HMODULE>(handle), symbol)); return (void*)(::GetProcAddress(reinterpret_cast<HMODULE>(handle), symbol));
@ -48,7 +48,7 @@ namespace system
void close(module_t handle) void close(module_t handle)
{ {
#ifdef NANA_LINUX #if defined(NANA_LINUX) or defined(NANA_MACOS)
::dlclose(handle); ::dlclose(handle);
#else #else
::FreeLibrary(reinterpret_cast<HMODULE>(handle)); ::FreeLibrary(reinterpret_cast<HMODULE>(handle));
@ -90,7 +90,7 @@ namespace system
std::transform(filename + length - 13, filename + length , std::back_inserter(file), tolower); std::transform(filename + length - 13, filename + length , std::back_inserter(file), tolower);
if(file == ".nana_shared") if(file == ".nana_shared")
{ {
#ifdef NANA_LINUX #if defined(NANA_LINUX) or defined(NANA_MACOS)
ofn.replace(length - 13, 13, ".so"); ofn.replace(length - 13, 13, ".so");
#else #else
ofn.replace(length - 13, 13, ".DLL"); ofn.replace(length - 13, 13, ".DLL");

View File

@ -2,7 +2,7 @@
#include <nana/config.hpp> #include <nana/config.hpp>
#ifdef NANA_WINDOWS #ifdef NANA_WINDOWS
#include <windows.h> #include <windows.h>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <sys/time.h> #include <sys/time.h>
#endif #endif
@ -15,7 +15,7 @@ namespace system
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
LARGE_INTEGER beg_timestamp; LARGE_INTEGER beg_timestamp;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timeval beg_timestamp; struct timeval beg_timestamp;
#endif #endif
}; };
@ -45,7 +45,7 @@ namespace system
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::QueryPerformanceCounter(&impl_->beg_timestamp); ::QueryPerformanceCounter(&impl_->beg_timestamp);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timezone tz; struct timezone tz;
::gettimeofday(&impl_->beg_timestamp, &tz); ::gettimeofday(&impl_->beg_timestamp, &tz);
#endif #endif
@ -63,7 +63,7 @@ namespace system
::QueryPerformanceFrequency(&freq); ::QueryPerformanceFrequency(&freq);
return double(diff)/double(freq.QuadPart) * 1000; return double(diff)/double(freq.QuadPart) * 1000;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
struct timeval tv; struct timeval tv;
struct timezone tz; struct timezone tz;
gettimeofday(&tv, &tz); gettimeofday(&tv, &tz);

View File

@ -27,7 +27,7 @@
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
#include <windows.h> #include <windows.h>
#include <process.h> #include <process.h>
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
#include <pthread.h> #include <pthread.h>
#endif #endif
@ -61,7 +61,7 @@ namespace threads
{ {
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
typedef HANDLE thread_t; typedef HANDLE thread_t;
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
typedef pthread_t thread_t; typedef pthread_t thread_t;
#endif #endif
impl * pool_ptr; impl * pool_ptr;
@ -69,7 +69,7 @@ namespace threads
thread_t handle; thread_t handle;
volatile state thr_state; volatile state thr_state;
time_t timestamp; time_t timestamp;
#if defined(NANA_LINUX) #if defined(NANA_LINUX) || defined(NANA_MACOS)
std::mutex wait_mutex; std::mutex wait_mutex;
std::condition_variable wait_cond; std::condition_variable wait_cond;
volatile bool suspended; volatile bool suspended;
@ -89,7 +89,7 @@ namespace threads
pto->task_ptr = nullptr; pto->task_ptr = nullptr;
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
pto->handle = (HANDLE)::_beginthreadex(0, 0, reinterpret_cast<unsigned(__stdcall*)(void*)>(&impl::_m_thr_starter), pto, 0, 0); pto->handle = (HANDLE)::_beginthreadex(0, 0, reinterpret_cast<unsigned(__stdcall*)(void*)>(&impl::_m_thr_starter), pto, 0, 0);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
pto->suspended = false; pto->suspended = false;
::pthread_create(&(pto->handle), 0, reinterpret_cast<void*(*)(void*)>(&impl::_m_thr_starter), pto); ::pthread_create(&(pto->handle), 0, reinterpret_cast<void*(*)(void*)>(&impl::_m_thr_starter), pto);
#endif #endif
@ -136,7 +136,7 @@ namespace threads
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::WaitForSingleObject(thr->handle, INFINITE); ::WaitForSingleObject(thr->handle, INFINITE);
::CloseHandle(thr->handle); ::CloseHandle(thr->handle);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
::pthread_join(thr->handle, 0); ::pthread_join(thr->handle, 0);
::pthread_detach(thr->handle); ::pthread_detach(thr->handle);
#endif #endif
@ -222,7 +222,7 @@ namespace threads
pto->thr_state = state::idle; pto->thr_state = state::idle;
#if defined(NANA_WINDOWS) #if defined(NANA_WINDOWS)
::SuspendThread(pto->handle); ::SuspendThread(pto->handle);
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
std::unique_lock<std::mutex> lock(pto->wait_mutex); std::unique_lock<std::mutex> lock(pto->wait_mutex);
pto->suspended = true; pto->suspended = true;
pto->wait_cond.wait(lock); pto->wait_cond.wait(lock);
@ -239,7 +239,7 @@ namespace threads
if(n == 1 || n == static_cast<DWORD>(-1)) if(n == 1 || n == static_cast<DWORD>(-1))
break; break;
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
while(false == pto->suspended) while(false == pto->suspended)
; ;
std::unique_lock<std::mutex> lock(pto->wait_mutex); std::unique_lock<std::mutex> lock(pto->wait_mutex);
@ -326,7 +326,7 @@ namespace threads
::_endthreadex(0); ::_endthreadex(0);
return 0; return 0;
} }
#elif defined(NANA_LINUX) #elif defined(NANA_LINUX) || defined(NANA_MACOS)
static void * _m_thr_starter(pool_throbj * pto) static void * _m_thr_starter(pool_throbj * pto)
{ {
pto->pool_ptr->_m_thr_runner(pto); pto->pool_ptr->_m_thr_runner(pto);