Permalink
Browse files

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

  • Loading branch information...
1 parent 502ce6d commit c2fbd971a647b2df233b31d6a6fdbcfd7485332c @larskanis committed Feb 15, 2013
Showing with 138 additions and 80 deletions.
  1. +7 −2 ext/fox16/FXRuby.cpp
  2. +4 −0 ext/fox16/include/FXRbCommon.h
  3. +4 −4 ext/fox16/include/FXRbDC.h
  4. +24 −2 ext/fox16/include/FXRuby.h
  5. +1 −1 swig-interfaces/FXApp.i
  6. +2 −2 swig-interfaces/FXBMPIcon.i
  7. +2 −2 swig-interfaces/FXBMPImage.i
  8. +1 −1 swig-interfaces/FXCURCursor.i
  9. +6 −6 swig-interfaces/FXFileDialog.i
  10. +3 −3 swig-interfaces/FXFileSelector.i
  11. +1 −1 swig-interfaces/FXGIFCursor.i
  12. +2 −2 swig-interfaces/FXGIFIcon.i
  13. +2 −2 swig-interfaces/FXGIFImage.i
  14. +2 −2 swig-interfaces/FXICOIcon.i
  15. +2 −2 swig-interfaces/FXICOImage.i
  16. +2 −2 swig-interfaces/FXJPGIcon.i
  17. +2 −2 swig-interfaces/FXJPGImage.i
  18. +2 −2 swig-interfaces/FXPCXIcon.i
  19. +2 −2 swig-interfaces/FXPCXImage.i
  20. +2 −2 swig-interfaces/FXPNGIcon.i
  21. +2 −2 swig-interfaces/FXPNGImage.i
  22. +2 −2 swig-interfaces/FXPPMIcon.i
  23. +2 −2 swig-interfaces/FXPPMImage.i
  24. +2 −2 swig-interfaces/FXRGBIcon.i
  25. +2 −2 swig-interfaces/FXRGBImage.i
  26. +2 −2 swig-interfaces/FXScintilla.i
  27. +2 −2 swig-interfaces/FXTGAIcon.i
  28. +2 −2 swig-interfaces/FXTGAImage.i
  29. +2 −2 swig-interfaces/FXTIFIcon.i
  30. +2 −2 swig-interfaces/FXTIFImage.i
  31. +1 −1 swig-interfaces/FXTable.i
  32. +5 −5 swig-interfaces/FXText.i
  33. +2 −2 swig-interfaces/FXXBMIcon.i
  34. +2 −2 swig-interfaces/FXXBMImage.i
  35. +2 −2 swig-interfaces/FXXPMIcon.i
  36. +2 −2 swig-interfaces/FXXPMImage.i
  37. +1 −1 swig-interfaces/fxdefs.i
  38. +3 −3 swig-interfaces/ruby-typemaps.i
  39. +9 −0 test/TC_FXComboBox.rb
  40. +9 −0 test/TC_FXList.rb
  41. +9 −0 test/TC_FXText.rb
@@ -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);
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));
}
@@ -1996,6 +1996,8 @@ void FXRbDestroyAppSensitiveObjects(){
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);
@@ -2051,6 +2053,9 @@ Init_fox16(void) {
id_begin=rb_intern("begin");
id_end=rb_intern("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();
appSensitiveObjs=st_init_numtable();
@@ -26,6 +26,10 @@
extern "C" {
#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){ \
FXRbCallVoidMethod(this,rb_intern("drawIconSunken"),icon,dx,dy); \
} \
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){ \
- 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){ \
- 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){ \
- 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){ \
FXRbCallVoidMethod(this,rb_intern("setForeground"),clr); \
@@ -171,6 +171,11 @@ FXint FXRbSignalNameToNumber(const char* name);
// Fox module instance
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
inline VALUE to_ruby(const void* ptr){
return Qnil; // FIXME: Used for some FXIconSource methods
@@ -223,11 +228,28 @@ inline VALUE to_ruby(unsigned long l){
#endif
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){
- 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);
@@ -161,7 +161,7 @@ public:
%extend {
// Copyright notice for library
static VALUE copyright() {
- return rb_str_new2((const char *) FXApp::copyright);
+ return to_ruby(FXApp::copyright);
}
}
@@ -28,10 +28,10 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXBMPIcon::fileExt);
+ return to_ruby(FXBMPIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXBMPIcon::mimeType);
+ return to_ruby(FXBMPIcon::mimeType);
}
}
public:
@@ -28,10 +28,10 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXBMPImage::fileExt);
+ return to_ruby(FXBMPImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXBMPImage::mimeType);
+ return to_ruby(FXBMPImage::mimeType);
}
}
public:
@@ -28,7 +28,7 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXCURCursor::fileExt);
+ return to_ruby(FXCURCursor::fileExt);
}
}
public:
@@ -70,10 +70,10 @@ public:
if (filenames) {
register FXString *p = filenames;
while ((*p) != FXString::null) {
- rb_ary_push(result, rb_str_new2((*p).text()));
- p++;
+ rb_ary_push(result, to_ruby(*p));
+ p++;
}
- delete [] filenames;
+ delete [] filenames;
}
return result;
}
@@ -239,10 +239,10 @@ public:
if (filenames) {
register FXString *p = filenames;
while ((*p) != FXString::null) {
- rb_ary_push(result, rb_str_new2((*p).text()));
- p++;
+ rb_ary_push(result, to_ruby(*p));
+ p++;
}
- delete [] filenames;
+ delete [] filenames;
}
return result;
}
@@ -167,10 +167,10 @@ public:
if (filenames) {
register FXString *p = filenames;
while ((*p) != FXString::null) {
- rb_ary_push(result, rb_str_new2((*p).text()));
- p++;
+ rb_ary_push(result, to_ruby(*p));
+ p++;
}
- delete [] filenames;
+ delete [] filenames;
}
return result;
}
@@ -27,7 +27,7 @@ class FXGIFCursor : public FXCursor {
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXGIFCursor::fileExt);
+ return to_ruby(FXGIFCursor::fileExt);
}
}
public:
@@ -28,10 +28,10 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXGIFIcon::fileExt);
+ return to_ruby(FXGIFIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXGIFIcon::mimeType);
+ return to_ruby(FXGIFIcon::mimeType);
}
}
public:
@@ -28,10 +28,10 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXGIFImage::fileExt);
+ return to_ruby(FXGIFImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXGIFImage::mimeType);
+ return to_ruby(FXGIFImage::mimeType);
}
}
public:
@@ -28,10 +28,10 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXICOIcon::fileExt);
+ return to_ruby(FXICOIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXICOIcon::mimeType);
+ return to_ruby(FXICOIcon::mimeType);
}
}
public:
@@ -28,10 +28,10 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXICOImage::fileExt);
+ return to_ruby(FXICOImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXICOImage::mimeType);
+ return to_ruby(FXICOImage::mimeType);
}
}
public:
@@ -31,11 +31,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXJPGIcon::fileExt);
+ return to_ruby(FXJPGIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXJPGIcon::mimeType);
+ return to_ruby(FXJPGIcon::mimeType);
}
/// True if format is supported
@@ -31,11 +31,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXJPGImage::fileExt);
+ return to_ruby(FXJPGImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXJPGImage::mimeType);
+ return to_ruby(FXJPGImage::mimeType);
}
/// True if format is supported
@@ -28,11 +28,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXPCXIcon::fileExt);
+ return to_ruby(FXPCXIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXPCXIcon::mimeType);
+ return to_ruby(FXPCXIcon::mimeType);
}
}
public:
@@ -28,11 +28,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXPCXImage::fileExt);
+ return to_ruby(FXPCXImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXPCXImage::mimeType);
+ return to_ruby(FXPCXImage::mimeType);
}
}
public:
@@ -29,11 +29,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXPNGIcon::fileExt);
+ return to_ruby(FXPNGIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXPNGIcon::mimeType);
+ return to_ruby(FXPNGIcon::mimeType);
}
/// True if format is supported
@@ -29,11 +29,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXPNGImage::fileExt);
+ return to_ruby(FXPNGImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXPNGImage::mimeType);
+ return to_ruby(FXPNGImage::mimeType);
}
/// True if format is supported
@@ -28,11 +28,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXPPMIcon::fileExt);
+ return to_ruby(FXPPMIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXPPMIcon::mimeType);
+ return to_ruby(FXPPMIcon::mimeType);
}
}
public:
@@ -28,11 +28,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXPPMImage::fileExt);
+ return to_ruby(FXPPMImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXPPMImage::mimeType);
+ return to_ruby(FXPPMImage::mimeType);
}
}
public:
@@ -28,11 +28,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXRGBIcon::fileExt);
+ return to_ruby(FXRGBIcon::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXRGBIcon::mimeType);
+ return to_ruby(FXRGBIcon::mimeType);
}
}
public:
@@ -28,11 +28,11 @@ protected:
public:
%extend {
static VALUE fileExt() {
- return rb_str_new2(FXRGBImage::fileExt);
+ return to_ruby(FXRGBImage::fileExt);
}
static VALUE mimeType() {
- return rb_str_new2(FXRGBImage::mimeType);
+ return to_ruby(FXRGBImage::mimeType);
}
}
public:
Oops, something went wrong.

0 comments on commit c2fbd97

Please sign in to comment.