home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
g
/
gina15.zip
/
demos
/
ted.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-27
|
2KB
|
100 lines
/* @(#)ted.C 1.13 7/31/91 */
#include <Gina/Gina.h>
#ifdef INCLUDE_SRC
#include "Gina.C"
#endif
class TextEditApplication : public GnApplication {
public:
virtual GnDocument *create_document ();
virtual char * app_class () { return "Ted" ; }
virtual char * app_signature() { return "ted" ; }
virtual char * app_file_type() { return ".ted" ; }
};
class TextEditDocument : public GnDocument {
public:
virtual void create_windows(int new_width = 0, int new_height = 0);
void value_changed_cb(caddr_t);
// Document IO
virtual Boolean write_to_stream ( ostream & );
virtual Boolean read_from_stream ( istream & );
private:
GnScrolledText *text;
GnCallback *vccb;
};
//---------------------------------------------------------------------
GnDocument *TextEditApplication ::
create_document () { return new TextEditDocument; }
//---------------------------------------------------------------------
void TextEditDocument ::
create_windows(int new_width, int new_height)
{
main_shell = new GnDocumentShell( this, new_width, new_height);
main_shell->create(GnApplication::get()->get_application_shell(), "shell");
text = new GnScrolledText;
// text->setR_editMode(XmMULTI_LINE_EDIT);
text->create(main_shell, "tedText");
text->add_valueChangedCallback(vccb = CALLBACK(TextEditDocument,
value_changed_cb,this));
}
void TextEditDocument ::
value_changed_cb(caddr_t)
{
set_modified( True );
// vccb->remove();
// vccb = NULL;
}
Boolean TextEditDocument ::
write_to_stream( ostream &ofs )
{
char * t = text->get_string();
ofs << strlen(t) << endl;
ofs << t;
if (! vccb)
text->add_valueChangedCallback(vccb = CALLBACK(TextEditDocument,
value_changed_cb,this));
return True;
}
Boolean TextEditDocument ::
read_from_stream ( istream &ifs )
{
int l;
ifs >> l;
if ( ifs.get() == EOF ) return False;
char *t = new char [ l+1 ];
if( l > 0 ) {
ifs.read(t,l);
}
t[l] = '\0';
text->set_string(t);
if (! vccb)
text->add_valueChangedCallback(vccb = CALLBACK(TextEditDocument,
value_changed_cb,this));
return True;
}
//---------------------------------------------------------------------
int main (unsigned int argc, char ** argv)
{
TextEditApplication tea;
#ifdef GINA_DEBUG
tea.set_sync();
#endif
tea.run ( argc, argv );
}