24 |
# include <config.h> |
# include <config.h> |
25 |
#endif |
#endif |
26 |
|
|
27 |
|
#include <cstring> |
28 |
|
#include <algorithm> |
29 |
|
|
30 |
|
#ifdef GLIBMM_HEADER_FILE |
31 |
|
# include GLIBMM_HEADER_FILE(glibmmconfig.h) |
32 |
|
#else |
33 |
|
# include <glibmmconfig.h> |
34 |
|
#endif |
35 |
|
// threads.h must be included first to be able to build with |
36 |
|
// G_DISABLE_DEPRECATED |
37 |
|
#if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 31 && GLIBMM_MICRO_VERSION >= 2) || \ |
38 |
|
(GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION > 31) || GLIBMM_MAJOR_VERSION > 2 |
39 |
|
#include <glibmm/threads.h> |
40 |
|
#endif |
41 |
|
|
42 |
#if !defined(WIN32) |
#if !defined(WIN32) |
43 |
# include <unistd.h> |
# include <unistd.h> |
44 |
# include <errno.h> |
# include <errno.h> |
49 |
|
|
50 |
#ifdef LIBGIG_HEADER_FILE |
#ifdef LIBGIG_HEADER_FILE |
51 |
# include LIBGIG_HEADER_FILE(gig.h) |
# include LIBGIG_HEADER_FILE(gig.h) |
52 |
|
# include LIBGIG_HEADER_FILE(Serialization.h) |
53 |
#else |
#else |
54 |
# include <gig.h> |
# include <gig.h> |
55 |
|
# include <Serialization.h> |
56 |
#endif |
#endif |
57 |
|
|
58 |
//FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler? |
//FIXME: for some reason AC GETTEXT check fails on the Mac cross compiler? |
59 |
#if (HAVE_GETTEXT || defined(__APPLE__)) |
#ifdef GETTEXT_HEADER_FILE |
60 |
|
# include GETTEXT_HEADER_FILE(libintl.h) |
61 |
|
#elif (HAVE_GETTEXT || defined(__APPLE__)) |
62 |
# include <libintl.h> |
# include <libintl.h> |
63 |
# define _(String) gettext(String) |
# define _(String) gettext(String) |
64 |
#else |
#else |
73 |
|
|
74 |
#define UNICODE_RIGHT_ARROW Glib::ustring(1, gunichar(0x2192)) |
#define UNICODE_RIGHT_ARROW Glib::ustring(1, gunichar(0x2192)) |
75 |
#define UNICODE_LEFT_ARROW Glib::ustring(1, gunichar(0x2190)) |
#define UNICODE_LEFT_ARROW Glib::ustring(1, gunichar(0x2190)) |
76 |
|
#define UNICODE_SHIFT_KEY_SYMBOL Glib::ustring("\xe2\x87\xa7") |
77 |
|
#if defined(__APPLE__) |
78 |
|
# define UNICODE_ALT_KEY_SYMBOL Glib::ustring("\xe2\x8c\xa5") |
79 |
|
#else |
80 |
|
# define UNICODE_ALT_KEY_SYMBOL Glib::ustring("Alt") |
81 |
|
#endif |
82 |
|
#define UNICODE_ERASE_KEY_SYMBOL Glib::ustring("\xe2\x8c\xab") |
83 |
|
#define UNICODE_CTRL_KEY_SYMBOL Glib::ustring("Ctrl") |
84 |
|
#define UNICODE_CMD_KEY_SYMBOL Glib::ustring(1, gunichar(0x2318)) |
85 |
|
#if defined(__APPLE__) |
86 |
|
# define UNICODE_PRIMARY_KEY_SYMBOL UNICODE_CMD_KEY_SYMBOL |
87 |
|
#else |
88 |
|
# define UNICODE_PRIMARY_KEY_SYMBOL UNICODE_CTRL_KEY_SYMBOL |
89 |
|
#endif |
90 |
|
|
91 |
// taken from gdk/gdkkeysyms.h |
// taken from gdk/gdkkeysyms.h |
92 |
// (define on demand, to avoid unnecessary dev lib package build dependency) |
// (define on demand, to avoid unnecessary dev lib package build dependency) |
109 |
# define GDK_KEY_Down 0xff54 |
# define GDK_KEY_Down 0xff54 |
110 |
#endif |
#endif |
111 |
|
|
112 |
|
#include <glibmm/convert.h> |
113 |
|
|
114 |
|
#define GIG_STR_ENCODING "CP1252" |
115 |
|
|
116 |
|
static inline |
117 |
|
Glib::ustring gig_to_utf8(const gig::String& gig_string) { |
118 |
|
return Glib::convert_with_fallback(gig_string, "UTF-8", GIG_STR_ENCODING, "?"); |
119 |
|
} |
120 |
|
|
121 |
|
static inline |
122 |
|
gig::String gig_from_utf8(const Glib::ustring& utf8_string) { |
123 |
|
return Glib::convert_with_fallback(utf8_string, GIG_STR_ENCODING, "UTF-8", "?"); |
124 |
|
} |
125 |
|
|
126 |
|
inline Glib::ustring ltrim(Glib::ustring s) { |
127 |
|
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace)))); |
128 |
|
return s; |
129 |
|
} |
130 |
|
|
131 |
|
inline Glib::ustring rtrim(Glib::ustring s) { |
132 |
|
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end()); |
133 |
|
return s; |
134 |
|
} |
135 |
|
|
136 |
|
inline Glib::ustring trim(Glib::ustring s) { |
137 |
|
return ltrim(rtrim(s)); |
138 |
|
} |
139 |
|
|
140 |
template<class T> inline std::string ToString(T o) { |
template<class T> inline std::string ToString(T o) { |
141 |
std::stringstream ss; |
std::stringstream ss; |
142 |
ss << o; |
ss << o; |
143 |
return ss.str(); |
return ss.str(); |
144 |
} |
} |
145 |
|
|
146 |
|
inline static bool endsWith(const std::string& haystack, const std::string& needle, bool caseSensitive) { |
147 |
|
if (haystack.size() < needle.size()) return false; |
148 |
|
const std::string sub = haystack.substr(haystack.size() - needle.size(), needle.size()); |
149 |
|
return (caseSensitive) ? (sub == needle) : (!strcasecmp(sub.c_str(), needle.c_str())); |
150 |
|
} |
151 |
|
|
152 |
inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) { |
inline int getDimensionIndex(gig::dimension_t type, gig::Region* rgn) { |
153 |
for (uint i = 0; i < rgn->Dimensions; ++i) |
for (uint i = 0; i < rgn->Dimensions; ++i) |
154 |
if (rgn->pDimensionDefinitions[i].dimension == type) |
if (rgn->pDimensionDefinitions[i].dimension == type) |
232 |
return dimCase; |
return dimCase; |
233 |
} |
} |
234 |
|
|
235 |
inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching(const DimensionCase& dimCase, gig::Region* rgn) { |
/** |
236 |
|
* Checks whether the passed dimension zones are within the boundaries of the |
237 |
|
* defined dimensions. This is especially relevant if there are dimensions |
238 |
|
* defined with an amount not equal to a power of two, in that case there are |
239 |
|
* unused dimensions regions which should be ignored. |
240 |
|
*/ |
241 |
|
inline bool isUsedCase(const DimensionCase& c, gig::Region* rgn) { |
242 |
|
for (int d = 0; d < rgn->Dimensions; ++d) { |
243 |
|
gig::dimension_t type = rgn->pDimensionDefinitions[d].dimension; |
244 |
|
if (c.find(type) == c.end()) continue; |
245 |
|
int zone = c.find(type)->second; |
246 |
|
if (zone < 0 || zone >= rgn->pDimensionDefinitions[d].zones) |
247 |
|
return false; |
248 |
|
} |
249 |
|
return true; |
250 |
|
} |
251 |
|
|
252 |
|
inline std::vector<gig::DimensionRegion*> dimensionRegionsMatching( |
253 |
|
const DimensionCase& dimCase, gig::Region* rgn, bool skipUnusedZones = false) |
254 |
|
{ |
255 |
std::vector<gig::DimensionRegion*> v; |
std::vector<gig::DimensionRegion*> v; |
256 |
for (int idr = 0; idr < 256; ++idr) { |
for (int idr = 0; idr < 256; ++idr) { |
257 |
if (!rgn->pDimensionRegions[idr]) continue; |
if (!rgn->pDimensionRegions[idr]) continue; |
258 |
DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]); |
DimensionCase c = dimensionCaseOf(rgn->pDimensionRegions[idr]); |
259 |
if (!dimCase.isViolating(c)) v.push_back(rgn->pDimensionRegions[idr]); |
if (dimCase.isViolating(c)) continue; |
260 |
|
if (skipUnusedZones && !isUsedCase(c, rgn)) continue; |
261 |
|
v.push_back(rgn->pDimensionRegions[idr]); |
262 |
} |
} |
263 |
return v; |
return v; |
264 |
} |
} |
272 |
return NULL; |
return NULL; |
273 |
} |
} |
274 |
|
|
275 |
|
template<typename T_Message> |
276 |
|
class SignalGuard { |
277 |
|
public: |
278 |
|
SignalGuard(sigc::signal<void, T_Message>& start, sigc::signal<void, T_Message>& end, T_Message message) |
279 |
|
: m_end(end), m_message(message) |
280 |
|
{ |
281 |
|
if (message) start.emit(message); |
282 |
|
} |
283 |
|
|
284 |
|
virtual ~SignalGuard() { |
285 |
|
if (m_message) m_end.emit(m_message); |
286 |
|
} |
287 |
|
protected: |
288 |
|
sigc::signal<void, T_Message>& m_end; |
289 |
|
T_Message m_message; |
290 |
|
}; |
291 |
|
|
292 |
#endif // GIGEDIT_GLOBAL_H |
#endif // GIGEDIT_GLOBAL_H |