<?php

/*******************************************************************************

 WINBINDER - The native Windows binding for PHP for PHP

 Copyright © Hypervisual - see LICENSE.TXT for details
 Author: Rubem Pechansky (http://winbinder.org/contact.php)

 Code sample: Demonstrates RTF text

*******************************************************************************/

//------------------------------------------------------------ SYSTEM PARAMETERS

define("PATH_SCRIPT",	dirname(__FILE__) . "/");
define("PATH_DATA",		PATH_SCRIPT);
define("PATH_INC",		PATH_SCRIPT . "../include/");
define("PATH_RES",		PATH_SCRIPT . "../resources/");

//----------------------------------------------------------------- DEPENDENCIES

include PATH_INC . "winbinder.php";

//-------------------------------------------------------------------- CONSTANTS

define("APPNAME", 	"WinBinder RTF test");

// This RTF code is the WordPad output, byte by byte

define("RTF_FILE", "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}{\\f1\\froman\\fprq2\\fcharset0 Times New Roman;}}
{\\colortbl ;\\red128\\green0\\blue0;\\red0\\green0\\blue255;}
\\viewkind4\\uc1\\pard\\cf1\\b\\f0\\fs20 Hello\\cf0\\b0 ,\\par
\\pard\\fi568 This is a \\i \"test\" \\i0\\f1 (Rich Text)\\f0 .\\par
\\pard\\par
\\cf2\\fs16 This text was generated on WordPad.\\cf0\\fs20\\par
}\r\n\0");

// This RTF code was written manually

define("RTF_FMT", "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 Arial;}{\\f1\\fscript\\fprq2\\fcharset0 Times New Roman;}}{\\colortbl ;\\red128\\green0\\blue0;}\\viewkind4\\uc1\\pard\\cf1\\b\\f0\\fs20 Hello\\cf0\\b0 ,\\pard\\fi568  %s. \\i0\\f1\\par This text is fixed\\f0 .\\par}");

//-------------------------------------------------------------- EXECUTABLE CODE

// NOTE: This kind of application does not need a window handler function

$mainwin = wb_create_window(NULL, PopupWindow, APPNAME, 540, 340);

file_put_contents("sample.rtf", RTF_FILE);
$r = file_get_contents("sample.rtf");
$rtfctrl1 = wb_create_control($mainwin, RTFEditBox, $r, 0, 0, 540, 150, 101);
unlink("sample.rtf");

$rtfctrl2 = wb_create_control($mainwin, RTFEditBox, sprintf(RTF_FMT, APPNAME), 0, 150, 540, 340, 102, WBC_READONLY);

wb_main_loop();                                                 // Enter message loop

//------------------------------------------------------------------ END OF FILE

?>