Skip to content
Snippets Groups Projects
Commit c2fbd971 authored by Lars Kanis's avatar Lars Kanis
Browse files

Mark strings retrieved from fox as UTF-8 when running Ruby 1.9.

parent 502ce6d1
No related branches found
No related tags found
No related merge requests found
Showing
with 73 additions and 42 deletions
...@@ -1484,10 +1484,10 @@ FXFoldingItem* FXRbCallFoldingItemMethod(const FXFoldingList* recv,ID func,FXint ...@@ -1484,10 +1484,10 @@ FXFoldingItem* FXRbCallFoldingItemMethod(const FXFoldingList* recv,ID func,FXint
//---------------------------------------------------------------------- //----------------------------------------------------------------------
FXFileAssoc* FXRbCallFileAssocMethod(const FXFileDict* recv,ID func,const char* pathname){ FXFileAssoc* FXRbCallFileAssocMethod(const FXFileDict* recv,ID func,const FXchar* pathname){
VALUE obj=FXRbGetRubyObj(recv,false); VALUE obj=FXRbGetRubyObj(recv,false);
FXASSERT(!NIL_P(obj)); FXASSERT(!NIL_P(obj));
VALUE result=rb_funcall(obj,func,1,rb_str_new2(pathname)); VALUE result=rb_funcall(obj,func,1,to_ruby(pathname));
return NIL_P(result) ? 0 : reinterpret_cast<FXFileAssoc*>(DATA_PTR(result)); return NIL_P(result) ? 0 : reinterpret_cast<FXFileAssoc*>(DATA_PTR(result));
} }
...@@ -1996,6 +1996,8 @@ void FXRbDestroyAppSensitiveObjects(){ ...@@ -1996,6 +1996,8 @@ void FXRbDestroyAppSensitiveObjects(){
FXTRACE((100,"%s:%d: Finished destroying objects that hold references to the FXApp.\n",__FILE__,__LINE__)); FXTRACE((100,"%s:%d: Finished destroying objects that hold references to the FXApp.\n",__FILE__,__LINE__));
} }
int utf8_enc_idx;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
extern "C" void Init_core(void); extern "C" void Init_core(void);
...@@ -2051,6 +2053,9 @@ Init_fox16(void) { ...@@ -2051,6 +2053,9 @@ Init_fox16(void) {
id_begin=rb_intern("begin"); id_begin=rb_intern("begin");
id_end=rb_intern("end"); id_end=rb_intern("end");
id_exclude_endp=rb_intern("exclude_end?"); id_exclude_endp=rb_intern("exclude_end?");
#ifdef HAVE_RUBY_ENCODING_H
utf8_enc_idx = rb_enc_find_index("UTF-8");
#endif
FXRuby_Objects=st_init_numtable(); FXRuby_Objects=st_init_numtable();
appSensitiveObjs=st_init_numtable(); appSensitiveObjs=st_init_numtable();
......
...@@ -26,6 +26,10 @@ ...@@ -26,6 +26,10 @@
extern "C" { extern "C" {
#include "ruby.h" #include "ruby.h"
#ifdef HAVE_RUBY_ENCODING_H
#include "ruby/encoding.h"
#endif
} }
/** /**
......
...@@ -329,16 +329,16 @@ inline void klass ## _clipChildren(klass* self,FXbool yes){ \ ...@@ -329,16 +329,16 @@ inline void klass ## _clipChildren(klass* self,FXbool yes){ \
FXRbCallVoidMethod(this,rb_intern("drawIconSunken"),icon,dx,dy); \ FXRbCallVoidMethod(this,rb_intern("drawIconSunken"),icon,dx,dy); \
} \ } \
void cls::drawText(FXint x,FXint y,const FXString& string){ \ void cls::drawText(FXint x,FXint y,const FXString& string){ \
rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawText"),3,to_ruby(x),to_ruby(y),rb_str_new(string.text(),string.length())); \ rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawText"),3,to_ruby(x),to_ruby(y),to_ruby(string)); \
} \ } \
void cls::drawText(FXint x,FXint y,const FXchar* string,FXuint length){ \ void cls::drawText(FXint x,FXint y,const FXchar* string,FXuint length){ \
rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawText"),3,to_ruby(x),to_ruby(y),rb_str_new(string,length)); \ rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawText"),3,to_ruby(x),to_ruby(y),to_ruby(string,length)); \
} \ } \
void cls::drawImageText(FXint x,FXint y,const FXString& string){ \ void cls::drawImageText(FXint x,FXint y,const FXString& string){ \
rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawImageText"),3,to_ruby(x),to_ruby(y),rb_str_new(string.text(),string.length())); \ rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawImageText"),3,to_ruby(x),to_ruby(y),to_ruby(string)); \
} \ } \
void cls::drawImageText(FXint x,FXint y,const FXchar* string,FXuint length){ \ void cls::drawImageText(FXint x,FXint y,const FXchar* string,FXuint length){ \
rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawImageText"),3,to_ruby(x),to_ruby(y),rb_str_new(string,length)); \ rb_funcall(FXRbGetRubyObj(this,false),rb_intern("drawImageText"),3,to_ruby(x),to_ruby(y),to_ruby(string,length)); \
} \ } \
void cls::setForeground(FXColor clr){ \ void cls::setForeground(FXColor clr){ \
FXRbCallVoidMethod(this,rb_intern("setForeground"),clr); \ FXRbCallVoidMethod(this,rb_intern("setForeground"),clr); \
......
...@@ -171,6 +171,11 @@ FXint FXRbSignalNameToNumber(const char* name); ...@@ -171,6 +171,11 @@ FXint FXRbSignalNameToNumber(const char* name);
// Fox module instance // Fox module instance
extern VALUE mFox; extern VALUE mFox;
#ifdef HAVE_RUBY_ENCODING_H
// UTF-8 encoding index
extern int utf8_enc_idx;
#endif
// Convert from FOX datatypes to Ruby objects // Convert from FOX datatypes to Ruby objects
inline VALUE to_ruby(const void* ptr){ inline VALUE to_ruby(const void* ptr){
return Qnil; // FIXME: Used for some FXIconSource methods return Qnil; // FIXME: Used for some FXIconSource methods
...@@ -223,11 +228,28 @@ inline VALUE to_ruby(unsigned long l){ ...@@ -223,11 +228,28 @@ inline VALUE to_ruby(unsigned long l){
#endif #endif
inline VALUE to_ruby(const FXString& s){ inline VALUE to_ruby(const FXString& s){
return rb_str_new2(s.text()); VALUE str = rb_str_new(s.text(), s.length());
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, utf8_enc_idx);
#endif
return str;
} }
inline VALUE to_ruby(const FXchar* s){ inline VALUE to_ruby(const FXchar* s){
return s ? rb_str_new2(s) : Qnil; if(!s) return Qnil;
VALUE str = rb_str_new2(s);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, utf8_enc_idx);
#endif
return str;
}
inline VALUE to_ruby(const FXchar* s, int length){
VALUE str = rb_str_new(s, length);
#ifdef HAVE_RUBY_ENCODING_H
rb_enc_associate_index(str, utf8_enc_idx);
#endif
return str;
} }
extern VALUE to_ruby(const FXObject* obj); extern VALUE to_ruby(const FXObject* obj);
......
...@@ -161,7 +161,7 @@ public: ...@@ -161,7 +161,7 @@ public:
%extend { %extend {
// Copyright notice for library // Copyright notice for library
static VALUE copyright() { static VALUE copyright() {
return rb_str_new2((const char *) FXApp::copyright); return to_ruby(FXApp::copyright);
} }
} }
......
...@@ -28,10 +28,10 @@ protected: ...@@ -28,10 +28,10 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXBMPIcon::fileExt); return to_ruby(FXBMPIcon::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXBMPIcon::mimeType); return to_ruby(FXBMPIcon::mimeType);
} }
} }
public: public:
......
...@@ -28,10 +28,10 @@ protected: ...@@ -28,10 +28,10 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXBMPImage::fileExt); return to_ruby(FXBMPImage::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXBMPImage::mimeType); return to_ruby(FXBMPImage::mimeType);
} }
} }
public: public:
......
...@@ -28,7 +28,7 @@ protected: ...@@ -28,7 +28,7 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXCURCursor::fileExt); return to_ruby(FXCURCursor::fileExt);
} }
} }
public: public:
......
...@@ -70,10 +70,10 @@ public: ...@@ -70,10 +70,10 @@ public:
if (filenames) { if (filenames) {
register FXString *p = filenames; register FXString *p = filenames;
while ((*p) != FXString::null) { while ((*p) != FXString::null) {
rb_ary_push(result, rb_str_new2((*p).text())); rb_ary_push(result, to_ruby(*p));
p++; p++;
} }
delete [] filenames; delete [] filenames;
} }
return result; return result;
} }
...@@ -239,10 +239,10 @@ public: ...@@ -239,10 +239,10 @@ public:
if (filenames) { if (filenames) {
register FXString *p = filenames; register FXString *p = filenames;
while ((*p) != FXString::null) { while ((*p) != FXString::null) {
rb_ary_push(result, rb_str_new2((*p).text())); rb_ary_push(result, to_ruby(*p));
p++; p++;
} }
delete [] filenames; delete [] filenames;
} }
return result; return result;
} }
......
...@@ -167,10 +167,10 @@ public: ...@@ -167,10 +167,10 @@ public:
if (filenames) { if (filenames) {
register FXString *p = filenames; register FXString *p = filenames;
while ((*p) != FXString::null) { while ((*p) != FXString::null) {
rb_ary_push(result, rb_str_new2((*p).text())); rb_ary_push(result, to_ruby(*p));
p++; p++;
} }
delete [] filenames; delete [] filenames;
} }
return result; return result;
} }
......
...@@ -27,7 +27,7 @@ class FXGIFCursor : public FXCursor { ...@@ -27,7 +27,7 @@ class FXGIFCursor : public FXCursor {
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXGIFCursor::fileExt); return to_ruby(FXGIFCursor::fileExt);
} }
} }
public: public:
......
...@@ -28,10 +28,10 @@ protected: ...@@ -28,10 +28,10 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXGIFIcon::fileExt); return to_ruby(FXGIFIcon::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXGIFIcon::mimeType); return to_ruby(FXGIFIcon::mimeType);
} }
} }
public: public:
......
...@@ -28,10 +28,10 @@ protected: ...@@ -28,10 +28,10 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXGIFImage::fileExt); return to_ruby(FXGIFImage::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXGIFImage::mimeType); return to_ruby(FXGIFImage::mimeType);
} }
} }
public: public:
......
...@@ -28,10 +28,10 @@ protected: ...@@ -28,10 +28,10 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXICOIcon::fileExt); return to_ruby(FXICOIcon::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXICOIcon::mimeType); return to_ruby(FXICOIcon::mimeType);
} }
} }
public: public:
......
...@@ -28,10 +28,10 @@ protected: ...@@ -28,10 +28,10 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXICOImage::fileExt); return to_ruby(FXICOImage::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXICOImage::mimeType); return to_ruby(FXICOImage::mimeType);
} }
} }
public: public:
......
...@@ -31,11 +31,11 @@ protected: ...@@ -31,11 +31,11 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXJPGIcon::fileExt); return to_ruby(FXJPGIcon::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXJPGIcon::mimeType); return to_ruby(FXJPGIcon::mimeType);
} }
/// True if format is supported /// True if format is supported
......
...@@ -31,11 +31,11 @@ protected: ...@@ -31,11 +31,11 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXJPGImage::fileExt); return to_ruby(FXJPGImage::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXJPGImage::mimeType); return to_ruby(FXJPGImage::mimeType);
} }
/// True if format is supported /// True if format is supported
......
...@@ -28,11 +28,11 @@ protected: ...@@ -28,11 +28,11 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXPCXIcon::fileExt); return to_ruby(FXPCXIcon::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXPCXIcon::mimeType); return to_ruby(FXPCXIcon::mimeType);
} }
} }
public: public:
......
...@@ -28,11 +28,11 @@ protected: ...@@ -28,11 +28,11 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXPCXImage::fileExt); return to_ruby(FXPCXImage::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXPCXImage::mimeType); return to_ruby(FXPCXImage::mimeType);
} }
} }
public: public:
......
...@@ -29,11 +29,11 @@ protected: ...@@ -29,11 +29,11 @@ protected:
public: public:
%extend { %extend {
static VALUE fileExt() { static VALUE fileExt() {
return rb_str_new2(FXPNGIcon::fileExt); return to_ruby(FXPNGIcon::fileExt);
} }
static VALUE mimeType() { static VALUE mimeType() {
return rb_str_new2(FXPNGIcon::mimeType); return to_ruby(FXPNGIcon::mimeType);
} }
/// True if format is supported /// True if format is supported
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment