Merge branch 'macos' of https://github.com/BenjaminNavarro/nana into BenjaminNavarro-macos
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Nana Configuration
|
||||
* 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.
|
||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -13,7 +13,6 @@
|
||||
#ifndef NANA_CONFIG_HPP
|
||||
#define NANA_CONFIG_HPP
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define _SCL_SECURE_NO_WARNINGS
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
@@ -53,7 +52,7 @@
|
||||
#define NANA_X11 1
|
||||
#define STD_CODECVT_NOT_SUPPORTED
|
||||
#else
|
||||
# static_assert(false, "Only Windows and Unix are supported now");
|
||||
# static_assert(false, "Only Windows and Unix are supported now (Mac OS is experimental)");
|
||||
#endif
|
||||
|
||||
#if defined(NANA_MINGW) || defined(NANA_LINUX)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
#include <nana/config.hpp>
|
||||
#include <nana/charset.hpp>
|
||||
#if defined(NANA_LINUX)
|
||||
#if defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#undef NANA_WINDOWS
|
||||
#endif
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace nana
|
||||
|
||||
#if defined(NANA_WINDOWS)
|
||||
#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"
|
||||
#endif
|
||||
|
||||
|
||||
32
include/nana/detail/macos_X11/msg_packet.hpp
Normal file
32
include/nana/detail/macos_X11/msg_packet.hpp
Normal 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
|
||||
|
||||
325
include/nana/detail/macos_X11/platform_spec.hpp
Normal file
325
include/nana/detail/macos_X11/platform_spec.hpp
Normal 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
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#ifdef NANA_WINDOWS
|
||||
#include <windows.h>
|
||||
typedef HANDLE find_handle_t;
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
@@ -38,7 +38,7 @@ namespace filesystem
|
||||
fileinfo();
|
||||
#ifdef NANA_WINDOWS
|
||||
fileinfo(const WIN32_FIND_DATA& wfd);
|
||||
#elif NANA_LINUX
|
||||
#elif NANA_LINUX or NANA_MACOS
|
||||
fileinfo(const nana::string& filename, const struct stat &);
|
||||
#endif
|
||||
nana::string name;
|
||||
@@ -119,7 +119,7 @@ namespace filesystem
|
||||
}
|
||||
}
|
||||
value_ = value_type(wfd_);
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
path_ = nana::charset(file_path);
|
||||
if(path_.size() && (path_[path_.size() - 1] != '/'))
|
||||
path_ += '/';
|
||||
@@ -181,7 +181,7 @@ namespace filesystem
|
||||
}
|
||||
else
|
||||
end_ = true;
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
struct dirent * dnt = readdir(handle_);
|
||||
if(dnt)
|
||||
{
|
||||
@@ -214,7 +214,7 @@ namespace filesystem
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
::FindClose(*handle);
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
::closedir(*handle);
|
||||
#endif
|
||||
}
|
||||
@@ -227,7 +227,7 @@ namespace filesystem
|
||||
#if defined(NANA_WINDOWS)
|
||||
WIN32_FIND_DATA wfd_;
|
||||
nana::string path_;
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
std::string path_;
|
||||
#endif
|
||||
std::shared_ptr<find_handle_t> find_ptr_;
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#ifdef NANA_WINDOWS
|
||||
#include <windows.h>
|
||||
typedef HANDLE find_handle_t;
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
@@ -264,7 +264,7 @@ namespace filesystem
|
||||
(FILE_ATTRIBUTE_DIRECTORY & wfd_.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY,
|
||||
wfd_.nFileSizeLow);
|
||||
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
path_ = nana::charset(file_path);
|
||||
if(path_.size() && (path_[path_.size() - 1] != '/'))
|
||||
path_ += '/';
|
||||
@@ -326,7 +326,7 @@ namespace filesystem
|
||||
}
|
||||
else
|
||||
end_ = true;
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
struct dirent * dnt = readdir(handle_);
|
||||
if(dnt)
|
||||
{
|
||||
@@ -361,7 +361,7 @@ namespace filesystem
|
||||
{
|
||||
#if defined(NANA_WINDOWS)
|
||||
::FindClose(*handle);
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
::closedir(*handle);
|
||||
#endif
|
||||
}
|
||||
@@ -374,7 +374,7 @@ namespace filesystem
|
||||
#if defined(NANA_WINDOWS)
|
||||
WIN32_FIND_DATA wfd_;
|
||||
nana::string path_;
|
||||
#elif defined(NANA_LINUX)
|
||||
#elif defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
std::string path_;
|
||||
#endif
|
||||
std::shared_ptr<find_handle_t> find_ptr_;
|
||||
|
||||
@@ -128,7 +128,7 @@ namespace detail
|
||||
void _m_init_pos_and_size(basic_window* parent, const rectangle&);
|
||||
void _m_initialize(basic_window* parent);
|
||||
public:
|
||||
#if defined(NANA_LINUX)
|
||||
#if defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||
point pos_native;
|
||||
#endif
|
||||
point pos_root; //coordinate for root window
|
||||
|
||||
Reference in New Issue
Block a user