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 / clock.C < prev    next >
C/C++ Source or Header  |  1992-02-27  |  2KB  |  82 lines

  1. /* @(#)clock.C    1.5 7/29/91 */
  2.  
  3. /*
  4.   Dies ist eine 'Clock'-Anwendung.
  5. */
  6.  
  7. #include <Gina/Gina.h>
  8. #ifdef INCLUDE_SRC
  9. #include "Gina.C"
  10. #endif
  11.  
  12. //---------------------------------------------------------------------
  13. class clock_document;
  14.  
  15. class clock_application : public GnApplication {
  16.   public:
  17.     GnDocument *create_document ();
  18.  
  19.     char * app_class () { return "Clock" ; }
  20.     char * app_signature() { return "clock" ; }
  21.     char * app_file_type() { return NULL ; }
  22.  
  23.     void idle_action();
  24.  
  25.     clock_document *cl_doc;
  26. };
  27.  
  28. class clock_document : public GnDocument {
  29.   public:
  30.     virtual void create_windows (int new_width = 0, int new_height = 0);
  31.     void tick();
  32.  
  33.     GnLabel *digi_clock;
  34. };
  35.  
  36. //---------------------------------------------------------------------
  37. GnDocument * clock_application ::
  38. create_document () { return new clock_document; }
  39.  
  40. void clock_application ::
  41. idle_action()
  42. {
  43.     cl_doc->tick();
  44. }
  45.  
  46. //---------------------------------------------------------------------
  47. void clock_document ::
  48. create_windows(int new_width, int new_height)
  49. {
  50.     Gina_Debug_NL ("clock_document :: create_windows");
  51.     main_shell = new GnDocumentShell( this, new_width, new_height, False );
  52.     main_shell->create(GnApplication::get()->get_application_shell(), "shell");
  53.  
  54.     digi_clock = new GnLabel(" 00:00:00 ");
  55.     digi_clock->create(main_shell, "digi_clock");
  56.  
  57.     ((clock_application*)GnApplication::get())->cl_doc = this;
  58. }
  59.  
  60. void clock_document::
  61. tick()
  62. {
  63.     time_t t = time((time_t)0);
  64.     char *ts = ctime(&t);
  65.     char *tss = new char [11];
  66.     strncpy(tss, &ts[10], 10);
  67.     tss[10] = '\0';
  68.     digi_clock->setR_labelString( tss );
  69.     digi_clock->SetValues();
  70. }
  71.  
  72. //---------------------------------------------------------------------
  73. int main (unsigned int argc, char ** argv)
  74. {
  75.     clock_application clock;
  76. #ifdef GINA_DEBUG
  77.     clock.set_sync();
  78. #endif
  79.     clock.set_idle_timeout(1000);
  80.     clock.run ( argc, argv );
  81. }
  82.