Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 9ff5c9078435970d03687b2d20ba5ec0744e0b07 @Hanmac committed Feb 23, 2012
0 README
No changes.
@@ -0,0 +1,8 @@
+require "mkmf"
+
+$CFLAGS += " -x c++ -g -Wall " + `wx-config --cflags`.chomp + " " + `wx-config --cxxflags`.chomp
+$CPPFLAGS += " " + `wx-config --cppflags`
+$LDFLAGS += " " + `wx-config --libs`
+
+dir_config "rwx"
+create_makefile "rwx"
@@ -0,0 +1,143 @@
+/*
+ * main.hpp
+ *
+ * Created on: 04.02.2012
+ * Author: hanmac
+ */
+
+#ifndef MAIN_HPP_
+#define MAIN_HPP_
+
+#include <cerrno>
+
+#include <wx/wx.h>
+#include <ruby.h>
+
+#ifdef HAVE_RUBY_ENCODING_H
+#include <ruby/encoding.h>
+#endif
+
+
+template <typename T>
+VALUE wrap(T *arg);
+
+template <typename T>
+T wrap(const VALUE &arg);
+
+
+template <typename T>
+VALUE wrap(const T &arg){
+ return wrap(new T(arg));
+};
+
+template <typename T>
+bool is_wrapable(const VALUE &arg);
+
+
+template <>
+inline bool wrap< bool >(const VALUE &val )
+{
+ return RTEST(val);
+}
+
+template <>
+inline VALUE wrap< bool >(const bool &st )
+{
+ return st ? Qtrue : Qfalse;
+}
+
+
+
+template <>
+inline VALUE wrap< wxString >(const wxString &st )
+{
+#ifdef HAVE_RUBY_ENCODING_H
+ return rb_enc_str_new(st.c_str(),st.capacity(),rb_utf8_encoding());
+#else
+ return rb_str_new2(st.c_str());
+#endif
+}
+template <>
+inline VALUE wrap< wxChar >(const wxChar &c )
+{
+ return wrap(wxString(c));
+}
+
+template <>
+inline char* wrap< char* >(const VALUE &val )
+{
+ if(NIL_P(val))
+ return NULL;
+ if (rb_obj_is_kind_of(val, rb_cString)){
+ return RSTRING_PTR(val);
+ }
+ else
+ return wrap< char* >(rb_funcall(val,rb_intern("to_s"),0));
+}
+
+template <>
+inline wxString wrap< wxString >(const VALUE &val )
+{
+ if(NIL_P(val))
+ return wxEmptyString;
+ else
+ return wxString(wrap< char* >(val));
+}
+
+
+
+#define macro_attr(attr,type) \
+VALUE _get##attr(VALUE self)\
+{return wrap(_self->Get##attr());}\
+\
+VALUE _set##attr(VALUE self,VALUE other)\
+{\
+ _self->Set##attr(wrap<type>(other));\
+ return other;\
+}
+
+
+template <typename T>
+T* unwrapPtr(const VALUE &obj,const VALUE &klass)
+{
+ if(NIL_P(obj))
+ return NULL;
+ if (rb_obj_is_kind_of(obj, klass)){
+ T *temp;
+ Data_Get_Struct( obj, T, temp);
+ return temp;
+ }else{
+ rb_raise(rb_eTypeError,
+ "Expected %s got %s!",
+ rb_class2name(klass),
+ rb_obj_classname(obj)
+ );
+ return NULL;
+ }
+
+}
+
+inline void rb_define_attr_method(VALUE klass,std::string name,VALUE(get)(VALUE),VALUE(set)(VALUE,VALUE))
+{
+ rb_define_method(klass,name.c_str(),RUBY_METHOD_FUNC(get),0);
+ rb_define_method(klass,(name + "=").c_str(),RUBY_METHOD_FUNC(set),1);
+}
+
+
+
+
+#define singlefunc(func) \
+VALUE _##func(VALUE self)\
+{\
+ _self->func();\
+ return self;\
+}
+
+
+#define singlereturn(func) \
+VALUE _##func(VALUE self)\
+{\
+ return wrap(_self->func());\
+}
+
+#endif /* MAIN_HPP_ */
@@ -0,0 +1,57 @@
+/*
+ * rwx.cpp
+ *
+ * Created on: 07.02.2012
+ * Author: hanmac
+ */
+
+#include "wxError.hpp"
+
+#include "wxSize.hpp"
+#include "wxColor.hpp"
+
+#include "wxImage.hpp"
+#include "wxBitmap.hpp"
+
+#include "wxEvent.hpp"
+#include "wxEvtHandler.hpp"
+
+#include "wxMenu.hpp"
+#include "wxMenuItem.hpp"
+
+#include "wxApp.hpp"
+#include "wxWindow.hpp"
+
+VALUE rb_mWX;
+
+
+extern "C" void Init_rwx()
+{
+ //wxInitialize();
+
+
+ rb_mWX = rb_define_module("WX");
+
+ Init_WXError(rb_mWX);
+
+ Init_WXColor(rb_mWX);
+
+ Init_WXImage(rb_mWX);
+ Init_WXBitmap(rb_mWX);
+
+ Init_WXSize(rb_mWX);
+
+ Init_WXEvent(rb_mWX);
+
+ Init_WXEvtHandler(rb_mWX);
+
+ Init_WXMenu(rb_mWX);
+ Init_WXMenuItem(rb_mWX);
+
+ Init_WXApp(rb_mWX);
+
+ Init_WXWindow(rb_mWX);
+ Init_WXTopLevel(rb_mWX);
+ Init_WXFrame(rb_mWX);
+ Init_WXDialog(rb_mWX);
+}
@@ -0,0 +1,40 @@
+/*
+ * wxAnyButton.cpp
+ *
+ * Created on: 13.02.2012
+ * Author: hanmac
+ */
+
+
+
+#include "wxWindow.hpp"
+
+VALUE rb_cWXAnyButton;
+
+#define _self wrap<wxAnyButton*>(self)
+
+RubyAnyButton::RubyAnyButton(VALUE klass)
+: wxAnyButton(), RubyControl::RubyControl(klass)
+{}
+
+namespace RubyWX {
+namespace AnyButton {
+
+macro_attr(LabelText,wxString)
+
+VALUE _alloc(VALUE self)
+{
+ return wrap(new RubyAnyButton(self));
+}
+
+}
+}
+
+void Init_WXAnyButton(VALUE rb_mWX)
+{
+ using namespace RubyWX::AnyButton;
+ rb_cWXAnyButton = rb_define_class_under(rb_mWX,"AnyButton",rb_cWXTopLevel);
+ rb_define_alloc_func(rb_cWXAnyButton,_alloc);
+}
+
+
@@ -0,0 +1,19 @@
+/*
+ * wxAnyButton.hpp
+ *
+ * Created on: 13.02.2012
+ * Author: hanmac
+ */
+
+#ifndef WXANYBUTTON_HPP_
+#define WXANYBUTTON_HPP_
+
+#include "wxControl.hpp"
+
+class RubyAnyButton : public wxAnyButton, RubyControl {
+public:
+ RubyAnyButton(VALUE klass);
+};
+
+
+#endif /* WXANYBUTTON_HPP_ */
@@ -0,0 +1,103 @@
+/*
+ * wxApp.cpp
+ *
+ * Created on: 07.02.2012
+ * Author: hanmac
+ */
+
+#include "wxApp.hpp"
+
+#define _self wrap<wxApp*>(self)
+VALUE rb_cWXApp;
+
+bool ruby_app_inited;
+
+RubyApp::RubyApp(VALUE klass)
+{
+ mRuby = Data_Wrap_Struct(klass, 0, 0, this);
+}
+bool RubyApp::OnInit()
+{
+ wxApp::OnInit();
+ ruby_app_inited = true;
+ return RTEST(rb_funcall(mRuby, rb_intern("on_init"), 0));
+}
+
+
+int RubyApp::OnRun()
+{
+ wxApp::OnRun();
+ rb_funcall(mRuby, rb_intern("on_run"), 0);
+ return 0;
+}
+
+
+int RubyApp::OnExit()
+{
+ wxApp::OnExit();
+ ruby_app_inited = false;
+ rb_funcall(mRuby, rb_intern("on_exit"), 0);
+ return 0;
+}
+
+
+namespace RubyWX {
+namespace App {
+
+macro_attr(AppName,wxString)
+macro_attr(AppDisplayName,wxString)
+macro_attr(ClassName,wxString)
+macro_attr(VendorName,wxString)
+macro_attr(VendorDisplayName,wxString)
+
+
+VALUE _alloc(VALUE self)
+{
+ return wrap(new RubyApp(self));
+}
+
+
+VALUE _main_loop(VALUE self)
+{
+ wxChar* argv[] = { NULL};
+ int argc = 0;
+ return INT2NUM(wxEntry(argc, argv));
+}
+
+VALUE _on_init(VALUE self)
+{
+ return Qtrue; //For wxWidgets to continue
+}
+
+VALUE _on_run(VALUE self)
+{
+ return Qnil;
+}
+
+VALUE _on_exit(VALUE self)
+{
+ return Qnil;
+}
+}
+}
+
+void Init_WXApp(VALUE rb_mWX)
+{
+ using namespace RubyWX::App;
+ rb_cWXApp = rb_define_class_under(rb_mWX,"App",rb_cObject);
+ rb_define_alloc_func(rb_cWXApp,_alloc);
+
+ rb_define_attr_method(rb_cWXApp,"appName",_getAppName,_setAppName);
+ rb_define_attr_method(rb_cWXApp,"appDisplayName",_getAppDisplayName,_setAppDisplayName);
+
+ rb_define_attr_method(rb_cWXApp,"vendorName",_getVendorName,_setVendorName);
+ rb_define_attr_method(rb_cWXApp,"vendorDisplayName",_getVendorDisplayName,_setVendorDisplayName);
+
+
+ rb_define_method(rb_cWXApp,"main_loop",RUBY_METHOD_FUNC(_main_loop),0);
+
+ rb_define_method(rb_cWXApp,"on_init",RUBY_METHOD_FUNC(_on_init),0);
+ rb_define_method(rb_cWXApp,"on_run",RUBY_METHOD_FUNC(_on_run),0);
+ rb_define_method(rb_cWXApp,"on_exit",RUBY_METHOD_FUNC(_on_exit),0);
+}
+
Oops, something went wrong.

0 comments on commit 9ff5c90

Please sign in to comment.