/* 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 "parserfactory.h"
#include "rwv2.h"
#include "rwv2_parser.h"

extern "C" {

VALUE mRwv2;
VALUE cRwv2Parser;
VALUE cRwv2Sep;
VALUE cRwv2Pap;
VALUE cRwv2Chp;
VALUE cRwv2Tap;
VALUE cRwv2Tc;

VALUE rwv2_create_parser(VALUE self, VALUE filename) {
	VALUE parser;
	Rwv2Parser * stub;
	parser = Data_Make_Struct(cRwv2Parser, Rwv2Parser, 
														rwv2_parser_mark, rwv2_parser_free, stub);
	stub->parser = wvWare::ParserFactory::createParser(STR2CSTR(filename));
	return parser;
}
void Init_rwv2() {

	/* module Rwv2 */
	mRwv2 = rb_define_module("Rwv2");
	rb_define_module_function(mRwv2, "create_parser", 
													 (VALUE (*)(...))rwv2_create_parser, 1);
	rb_define_const(mRwv2, "HEADER_EVEN", INT2FIX(0x01));
	rb_define_const(mRwv2, "HEADER_ODD", INT2FIX(0x02));
	rb_define_const(mRwv2, "FOOTER_EVEN", INT2FIX(0x04));
	rb_define_const(mRwv2, "FOOTER_ODD", INT2FIX(0x08));
	rb_define_const(mRwv2, "HEADER_FIRST", INT2FIX(0x10));
	rb_define_const(mRwv2, "FOOTER_FIRST", INT2FIX(0x20));
	rb_define_const(mRwv2, "ALIGN_LEFT", CHR2FIX(0));
	rb_define_const(mRwv2, "ALIGN_CENTER", CHR2FIX(1));
	rb_define_const(mRwv2, "ALIGN_RIGHT", CHR2FIX(2));
	rb_define_const(mRwv2, "ALIGN_JUSTIFY", CHR2FIX(3));

	/* class Rwv2::Parser */
	cRwv2Parser = rb_define_class_under(mRwv2, "Parser", rb_cObject);
	rb_define_method(cRwv2Parser, "is_ok?", 
									(VALUE (*)(...)) rwv2_parser_is_ok, 0);
	rb_define_method(cRwv2Parser, "parse",
									(VALUE (*)(...)) rwv2_parser_parse, 0);
	rb_define_method(cRwv2Parser, "set_inline_replacement_handler", 
									(VALUE (*)(...)) rwv2_parser_set_inline_replacement_handler, 1);
	rb_define_method(cRwv2Parser, "set_subdocument_handler", 
									(VALUE (*)(...)) rwv2_parser_set_subdocument_handler, 1);
	rb_define_method(cRwv2Parser, "set_table_handler", 
									(VALUE (*)(...)) rwv2_parser_set_table_handler, 1);
	rb_define_method(cRwv2Parser, "set_text_handler", 
									(VALUE (*)(...)) rwv2_parser_set_text_handler, 1);

	/* class Rwv2::SectionProperties */
	cRwv2Sep = rb_define_class_under(mRwv2, "SectionProperties", rb_cObject);
	rb_define_method(cRwv2Sep, "break_code", 
									(VALUE (*)(...)) rwv2_sep_break_code, 0);
	rb_define_const(cRwv2Sep, "BREAK_NONE", Qfalse);
	rb_define_const(cRwv2Sep, "BREAK_COLUMN", CHR2FIX(1));
	rb_define_const(cRwv2Sep, "BREAK_PAGE", CHR2FIX(2));
	rb_define_const(cRwv2Sep, "BREAK_EVEN", CHR2FIX(3));
	rb_define_const(cRwv2Sep, "BREAK_ODD", CHR2FIX(4));
	rb_define_method(cRwv2Sep, "title_page?", 
									(VALUE (*)(...)) rwv2_sep_title_page, 0);
	rb_define_method(cRwv2Sep, "page_number_format", 
									(VALUE (*)(...)) rwv2_sep_page_number_format, 0);
	rb_define_const(cRwv2Sep, "NUMBER_ARABIC", CHR2FIX(0));
	rb_define_const(cRwv2Sep, "NUMBER_ROMAN_UPPER", CHR2FIX(1));
	rb_define_const(cRwv2Sep, "NUMBER_ROMAN_LOWER", CHR2FIX(2));
	rb_define_const(cRwv2Sep, "NUMBER_LETTER_UPPER", CHR2FIX(3));
	rb_define_const(cRwv2Sep, "NUMBER_LETTER_LOWER", CHR2FIX(4));
	rb_define_method(cRwv2Sep, "unlocked?", 
									(VALUE (*)(...)) rwv2_sep_unlocked, 0);
	rb_define_method(cRwv2Sep, "page_number_restart?", 
									(VALUE (*)(...)) rwv2_sep_page_number_restart, 0);
	rb_define_method(cRwv2Sep, "endnote?", 
									(VALUE (*)(...)) rwv2_sep_endnote, 0);
	rb_define_method(cRwv2Sep, "line_numbering_code", 
									(VALUE (*)(...)) rwv2_sep_line_numbering_code, 0);
	rb_define_const(cRwv2Sep, "LINE_NUMBERING_PER_PAGE", CHR2FIX(0));
	rb_define_const(cRwv2Sep, "LINE_NUMBERING_RESTART", CHR2FIX(1));
	rb_define_const(cRwv2Sep, "LINE_NUMBERING_CONTINUE", CHR2FIX(2));
	rb_define_method(cRwv2Sep, "line_numbering_modulus", 
									(VALUE (*)(...)) rwv2_sep_line_numbering_modulus, 0);
	rb_define_method(cRwv2Sep, "columns", 
									(VALUE (*)(...)) rwv2_sep_columns, 0);
	
	/* class Rwv2::ParagraphProperties */
	cRwv2Pap = rb_define_class_under(mRwv2, "ParagraphProperties", rb_cObject);
	rb_define_method(cRwv2Pap, "align", 
									(VALUE (*)(...)) rwv2_pap_justify, 0);
	rb_define_method(cRwv2Pap, "keep?", 
									(VALUE (*)(...)) rwv2_pap_keep, 0);
	rb_define_method(cRwv2Pap, "keep_with_next?", 
									(VALUE (*)(...)) rwv2_pap_keep_follow, 0);
	rb_define_method(cRwv2Pap, "page_break_before?", 
									(VALUE (*)(...)) rwv2_pap_page_break_before, 0);
	rb_define_method(cRwv2Pap, "widow_control?", 
									(VALUE (*)(...)) rwv2_pap_widow_control, 0);
	rb_define_method(cRwv2Pap, "indent_right", 
									(VALUE (*)(...)) rwv2_pap_indent_right, 0);
	rb_define_method(cRwv2Pap, "indent_left", 
									(VALUE (*)(...)) rwv2_pap_indent_left, 0);
	rb_define_method(cRwv2Pap, "indent_first_line", 
									(VALUE (*)(...)) rwv2_pap_indent_first_line, 0);
	
	/* class Rwv2::CharacterProperties */
	cRwv2Chp = rb_define_class_under(mRwv2, "CharacterProperties", rb_cObject);
	rb_define_method(cRwv2Chp, "bold?", 
									(VALUE (*)(...)) rwv2_chp_bold, 0);
	rb_define_method(cRwv2Chp, "italic?", 
									(VALUE (*)(...)) rwv2_chp_italic, 0);
	rb_define_method(cRwv2Chp, "rev_mark?", 
									(VALUE (*)(...)) rwv2_chp_rev_mark, 0);
	rb_define_method(cRwv2Chp, "rev_mark_del?", 
									(VALUE (*)(...)) rwv2_chp_rev_mark_del, 0);
	rb_define_method(cRwv2Chp, "outline?", 
									(VALUE (*)(...)) rwv2_chp_outline, 0);
	rb_define_method(cRwv2Chp, "small_caps?", 
									(VALUE (*)(...)) rwv2_chp_small_caps, 0);
	rb_define_method(cRwv2Chp, "caps?", 
									(VALUE (*)(...)) rwv2_chp_caps, 0);
	rb_define_method(cRwv2Chp, "special_char?", 
									(VALUE (*)(...)) rwv2_chp_special_char, 0);
	rb_define_method(cRwv2Chp, "strikethrough?", 
									(VALUE (*)(...)) rwv2_chp_strikethrough, 0);
	rb_define_method(cRwv2Chp, "shadow?", 
									(VALUE (*)(...)) rwv2_chp_shadow, 0);
	rb_define_method(cRwv2Chp, "lowercase?", 
									(VALUE (*)(...)) rwv2_chp_lowercase, 0);
	rb_define_method(cRwv2Chp, "emboss?", 
									(VALUE (*)(...)) rwv2_chp_emboss, 0);
	rb_define_method(cRwv2Chp, "imprint?", 
									(VALUE (*)(...)) rwv2_chp_imprint, 0);
	rb_define_method(cRwv2Chp, "double_strikethrough?", 
									(VALUE (*)(...)) rwv2_chp_double_strikethrough, 0);
	rb_define_method(cRwv2Chp, "position", 
									(VALUE (*)(...)) rwv2_chp_position, 0);
	rb_define_const(cRwv2Chp, "POSITION_NORMAL", Qfalse);
	rb_define_const(cRwv2Chp, "POSITION_SUPERSCRIPT", CHR2FIX(1));
	rb_define_const(cRwv2Chp, "POSITION_SUBSCRIPT", CHR2FIX(2));
	rb_define_method(cRwv2Chp, "underline", 
									(VALUE (*)(...)) rwv2_chp_underline, 0);
	rb_define_const(cRwv2Chp, "UNDERLINE_NONE", Qfalse);
	rb_define_const(cRwv2Chp, "UNDERLINE_SINGLE", CHR2FIX(1));
	rb_define_const(cRwv2Chp, "UNDERLINE_BY_WORD", CHR2FIX(2));
	rb_define_const(cRwv2Chp, "UNDERLINE_DOUBLE", CHR2FIX(3));
	rb_define_const(cRwv2Chp, "UNDERLINE_DOTTED", CHR2FIX(4));
	rb_define_const(cRwv2Chp, "UNDERLINE_THICK", CHR2FIX(6));
	rb_define_const(cRwv2Chp, "UNDERLINE_DASH", CHR2FIX(7));
	rb_define_const(cRwv2Chp, "UNDERLINE_DOT_DASH", CHR2FIX(9));
	rb_define_const(cRwv2Chp, "UNDERLINE_DOT_DOT_DASH", CHR2FIX(10));
	rb_define_const(cRwv2Chp, "UNDERLINE_WAVE", CHR2FIX(11));

	/* class Rwv2::TableProperties */
	cRwv2Tap = rb_define_class_under(mRwv2, "TableProperties", rb_cObject);
	rb_define_method(cRwv2Tap, "align", 
									(VALUE (*)(...)) rwv2_tap_justify, 0);
	rb_define_method(cRwv2Tap, "gap_half", 
									(VALUE (*)(...)) rwv2_tap_gap_half, 0);
	rb_define_method(cRwv2Tap, "row_height", 
									(VALUE (*)(...)) rwv2_tap_row_height, 0);
	rb_define_method(cRwv2Tap, "cant_split?", 
									(VALUE (*)(...)) rwv2_tap_cant_split, 0);
	rb_define_method(cRwv2Tap, "table_header?", 
									(VALUE (*)(...)) rwv2_tap_table_header, 0);
	rb_define_method(cRwv2Tap, "row_cells", 
									(VALUE (*)(...)) rwv2_tap_row_cells, 0);
	rb_define_method(cRwv2Tap, "cell_boundaries", 
									(VALUE (*)(...)) rwv2_tap_cell_boundaries, 0);
	rb_define_method(cRwv2Tap, "cell_descriptors", 
									(VALUE (*)(...)) rwv2_tap_cell_descriptors, 0);

	/* class Rwv2::TableProperties::CellDescriptor */
	cRwv2Tc = rb_define_class_under(cRwv2Tap, "CellDescriptor", rb_cObject);
	rb_define_method(cRwv2Tc, "first_merged?", 
									(VALUE (*)(...)) rwv2_tc_first_merged, 0);
	rb_define_method(cRwv2Tc, "merged?", 
									(VALUE (*)(...)) rwv2_tc_merged, 0);
	rb_define_method(cRwv2Tc, "vertical?", 
									(VALUE (*)(...)) rwv2_tc_vertical, 0);
	rb_define_method(cRwv2Tc, "backward?", 
									(VALUE (*)(...)) rwv2_tc_backward, 0);
	rb_define_method(cRwv2Tc, "rotate_font?", 
									(VALUE (*)(...)) rwv2_tc_rotate_font, 0);
	rb_define_method(cRwv2Tc, "vertical_merged?", 
									(VALUE (*)(...)) rwv2_tc_vertical_merged, 0);
	rb_define_method(cRwv2Tc, "vertical_restart?", 
									(VALUE (*)(...)) rwv2_tc_vertical_restart, 0);
	rb_define_method(cRwv2Tc, "vertical_align", 
									(VALUE (*)(...)) rwv2_tc_vertical_align, 0);
	rb_define_const(cRwv2Tc, "ALIGN_TOP", CHR2FIX(0));
	rb_define_const(cRwv2Tc, "ALIGN_CENTER", CHR2FIX(1));
	rb_define_const(cRwv2Tc, "ALIGN_BOTTOM", CHR2FIX(2));
}
} // extern "C"
