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 >
C/C++ Source or Header  |  1992-02-27  |  2KB  |  100 lines

  1. /* @(#)ted.C    1.13 7/31/91 */
  2.  
  3. #include <Gina/Gina.h>
  4.  
  5. #ifdef INCLUDE_SRC
  6. #include "Gina.C"
  7. #endif
  8.  
  9. class TextEditApplication : public GnApplication {
  10.   public:
  11.     virtual GnDocument *create_document ();
  12.  
  13.     virtual char * app_class ()    { return "Ted" ; }
  14.     virtual char * app_signature() { return "ted" ; }
  15.     virtual char * app_file_type() { return ".ted" ; }
  16. };
  17.  
  18.  
  19. class TextEditDocument : public GnDocument {
  20.   public:
  21.     virtual void create_windows(int new_width = 0, int new_height = 0);
  22.     void value_changed_cb(caddr_t);
  23.  
  24.     // Document IO
  25.     virtual Boolean write_to_stream ( ostream & );
  26.     virtual Boolean read_from_stream ( istream & );
  27.   private:
  28.     GnScrolledText *text;
  29.     GnCallback *vccb;
  30. };
  31.  
  32. //---------------------------------------------------------------------
  33.  
  34. GnDocument *TextEditApplication ::
  35. create_document () { return new TextEditDocument; }
  36.  
  37. //---------------------------------------------------------------------
  38.  
  39. void TextEditDocument ::
  40. create_windows(int new_width, int new_height)
  41. {
  42.     main_shell = new GnDocumentShell( this, new_width, new_height);
  43.     main_shell->create(GnApplication::get()->get_application_shell(), "shell");
  44.  
  45.     text = new GnScrolledText;
  46. //    text->setR_editMode(XmMULTI_LINE_EDIT);
  47.     text->create(main_shell, "tedText");
  48.  
  49.     text->add_valueChangedCallback(vccb = CALLBACK(TextEditDocument,
  50.                              value_changed_cb,this));
  51. }
  52.  
  53. void TextEditDocument ::
  54. value_changed_cb(caddr_t)
  55. {
  56.     set_modified( True );
  57. //    vccb->remove();
  58. //    vccb = NULL;
  59. }
  60.  
  61. Boolean TextEditDocument ::
  62. write_to_stream( ostream &ofs )
  63. {
  64.     char * t = text->get_string();
  65.     ofs << strlen(t) << endl;
  66.     ofs << t;
  67.     if (! vccb)
  68.     text->add_valueChangedCallback(vccb = CALLBACK(TextEditDocument,
  69.                              value_changed_cb,this));
  70.     return True;
  71. }
  72.  
  73. Boolean TextEditDocument ::
  74. read_from_stream ( istream &ifs )
  75. {
  76.     int l;
  77.     ifs >> l;
  78.     if ( ifs.get() == EOF ) return False;
  79.     char *t = new char [ l+1 ];
  80.     if( l > 0 ) {
  81.     ifs.read(t,l);
  82.     }
  83.     t[l] = '\0';
  84.     text->set_string(t);
  85.     if (! vccb)
  86.     text->add_valueChangedCallback(vccb = CALLBACK(TextEditDocument,
  87.                              value_changed_cb,this));
  88.     return True;
  89. }
  90.  
  91. //---------------------------------------------------------------------
  92. int main (unsigned int argc, char ** argv)
  93. {
  94.     TextEditApplication tea;
  95. #ifdef GINA_DEBUG
  96.     tea.set_sync();
  97. #endif
  98.     tea.run ( argc, argv );
  99. }
  100.