/* Rwv2 -- Microsoft Word Parser extension
   Copyright (C) 2003 Hannes Wyss, ywesee

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   ywesee - intellectual capital connected
	 Winterthurerstrasse 52, CH-8006 Zürich, Switzerland
   hwyss@ywesee.com
*/

#include "ruby.h"

#include "rwv2.h"
#include "rwv2_handlers.h"

extern "C" {

void Rwv2TableHandler::tableRowStart(wvWare::SharedPtr<const wvWare::Word97::TAP> tap) {
	Rwv2Tap * stub;	
	VALUE rb_tap;
	rb_tap = Data_Make_Struct(cRwv2Tap, Rwv2Tap, 0, rwv2_tap_free, stub);
	stub->wv_tap = tap;
	rb_funcall(m_rb_handler, rb_intern("row_start"), 1, rb_tap);
};

void Rwv2TextHandler::sectionStart(wvWare::SharedPtr<const wvWare::Word97::SEP> sep) {
	Rwv2Sep * stub;
	VALUE rb_sep;
	rb_sep = Data_Make_Struct(cRwv2Sep, Rwv2Sep, 0, rwv2_sep_free, stub);
	stub->wv_sep = sep;
	rb_funcall(m_rb_handler, rb_intern("section_start"), 1, rb_sep);
}

void Rwv2TextHandler::paragraphStart(wvWare::SharedPtr<const wvWare::ParagraphProperties> pap) {
	Rwv2Pap * stub;
	VALUE rb_pap;
	rb_pap = Data_Make_Struct(cRwv2Pap, Rwv2Pap, 0, free, stub);
	stub->wv_pap = pap;
	rb_funcall(m_rb_handler, rb_intern("paragraph_start"), 1, rb_pap);
}

void Rwv2TextHandler::runOfText(const wvWare::UString & text, 
		wvWare::SharedPtr<const wvWare::Word97::CHP> chp) {
	wvWare::CString cstr = text.cstring();
	char * txt = (char *) cstr.c_str();
	VALUE rb_str = rb_str_new2(txt);
	VALUE rb_chp = wrap_chp(chp);
	rb_funcall(m_rb_handler, rb_intern("run_of_text"), 2, rb_str, rb_chp);
};

VALUE Rwv2TextHandler::wrap_chp(wvWare::SharedPtr<const wvWare::Word97::CHP> chp) {
	Rwv2Chp * stub;
	VALUE rb_chp;
	rb_chp = Data_Make_Struct(cRwv2Chp, Rwv2Chp, 0, rwv2_chp_free, stub);
	stub->wv_chp = chp;
	return rb_chp;
}

}; // extern "C"
