home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_07 / ACS.ZIP / ACS / AUF_AB / AUF_AB.C < prev    next >
C/C++ Source or Header  |  1992-01-28  |  5KB  |  225 lines

  1. /*
  2.     Beispielapplikation    für ACS
  3.  
  4.     "Auf & Ab"
  5.  
  6.     27.9.91            Stefan Bachert
  7.  
  8. */
  9.  
  10. #include    <stdio.h>
  11. #include    <string.h>
  12. #include    <acs.h>
  13. #include    <auf_ab.h>        /* nicht wirklich notwendig in diesem Beispiel */
  14.  
  15. static int tasten (Awindow *window, int key, int kstate);    /* eigene Tastenroutine */
  16. static Awindow *updown_make (void *not_used);        /* Fenster erzeugen */
  17. static void hoch (void);                            /* click-routine Zählt hoch */
  18. static void runter (void);                            /* click-routine Zählt runter */
  19. static void neuer_wert (void);                        /* drag-routine empfängt neuen Wert */
  20. static void frage (void);                            /* doppelklick auf Zahl */
  21. static int updown_service (Awindow *window, int task, void *in_out);
  22.  
  23.  
  24. #define        NUM_STRING    12345    /* Typ des Objektes */
  25.  
  26. #include    <auf_ab.ah>
  27.  
  28.  
  29. static void update (void)
  30.     /*
  31.      *    Macht Änderungen sichtbar
  32.      */
  33. {
  34.     /*    Das Objekt mit der Nummer VALUE wird neu gezeichnet
  35.         da sich der 'ob_state' nicht ändert.
  36.     */
  37.   (ev_window-> obchange) (ev_window, VALUE, ev_window-> work [VALUE]. ob_state);
  38. }
  39.  
  40.  
  41. static void hoch (void)
  42.     /*
  43.      *    Zählt den Wert hoch
  44.      */
  45. {
  46.   char *p;
  47.   int wert;
  48.  
  49.   p = ev_object [VALUE]. ob_spec. tedinfo-> te_ptext;        /* Zeiger auf den Nummernstring */
  50.   sscanf (p, "%d", &wert);                /* wert in integer wandeln */
  51.   if (wert >= 999) return;                /* finito */
  52.   wert ++;
  53.   sprintf (p, "%d", wert);                /* wieder als String */
  54.   update ();
  55. }
  56.  
  57.  
  58. static void runter (void)
  59.     /*
  60.      *    Zählt den Wert runter
  61.      */
  62. {
  63.   char *p;
  64.   unsigned int wert;
  65.  
  66.   p = ev_object [VALUE]. ob_spec. tedinfo-> te_ptext;        /* Zeiger auf den Nummernstring */
  67.   sscanf (p, "%d", &wert);                /* wert in integer wandeln */
  68.   if (wert < 1) return;                    /* finito */
  69.   wert --;
  70.   sprintf (p, "%d", wert);                /* wieder als String */
  71.   update ();
  72. }
  73.  
  74.  
  75.  
  76. static void neuer (Awindow *window)
  77.     /*
  78.      *    Erfrage neuen Wert
  79.      */
  80. {
  81.   OBJECT *dia;
  82.  
  83.   dia = Aob_create (&NEU_DIA);            /* Erzeuge Dialog */
  84.   if (dia == NULL) return;
  85.  
  86.   strcpy (dia [DIA_VAL]. ob_spec. tedinfo-> te_ptext,    /* Vorgabe eintragen */
  87.             window-> work [VALUE]. ob_spec. tedinfo-> te_ptext);
  88.   if (DIA_OK == A_dialog (dia)) {                        /* ok gedrückt */
  89.     strcpy (window-> work [VALUE]. ob_spec. tedinfo-> te_ptext,    /* Wert übernehmen */
  90.             dia [DIA_VAL]. ob_spec. tedinfo-> te_ptext);
  91.     (window-> obchange) (window, VALUE, window-> work [VALUE]. ob_state);
  92.   };
  93.   Aob_delete (dia);                        /* gebe Dialog wieder frei */
  94. }
  95.  
  96.  
  97. static void frage (void)
  98.     /*
  99.      *    Frage nach Wert
  100.      */
  101. {
  102.   neuer (ev_window);
  103. }
  104.  
  105.  
  106. static int tasten (Awindow *window, int key, int kstate)
  107.     /*
  108.      *    eigene Tastenroutine ruft einfach den Dialog auf
  109.      */
  110. {
  111.   neuer (window);
  112.   return OK;
  113. }
  114.  
  115.  
  116. static void hole_wert (Awindow *window)
  117.     /*
  118.      *    Empfängt Wert
  119.      */
  120. {
  121.   AOBJECT *aob;
  122.   int nr;
  123.  
  124.   Aselect. next = 0;                    /* erstes Objekt der Liste lesen */
  125.   nr = Adr_next ();                        /* hier macht es nur Sinn ein Objekt anzunehmen */
  126.  
  127.   if (nr >= 0) {                        /* ein Objekt ist da (test ist überflüssig) */
  128.     aob = (AOBJECT *) Aselect. window-> work + nr + 1;    /* zeigt auf extented Objekt, unterstellt die Existenz ohne Test ! */
  129.     if (aob-> type == NUM_STRING) {        /* es ist der richtig Typ */
  130.  
  131.       if (Aselect. window == window) return;    /* auf sich selbst ?? */
  132.  
  133.       Adr_del (Aselect. window, nr);    /* Objekt konsumiert */
  134.       strcpy (window-> work [VALUE]. ob_spec. tedinfo-> te_ptext,    /* auf das eigene Objekt kopieren */
  135.             aob-> userp1);
  136.       (window-> obchange) (window, VALUE, window-> work [VALUE]. ob_state);
  137.     };
  138.     if (aob-> type == AT_NEW) {            /* Neu darauf gezogen */
  139.       Adr_del (Aselect. window, nr);    /* Objekt konsumiert */
  140.       neuer (window);
  141.     };
  142.     
  143.   };
  144. }
  145.  
  146.  
  147. static void neuer_wert (void)
  148.     /*
  149.      *    Empfange durch Objekt
  150.      */
  151. {
  152.   hole_wert (ev_window);
  153. }
  154.  
  155.  
  156. static Awindow *updown_make (void *not_used)
  157.     /*
  158.      *    Erzeuge "Auf und AB" Fenster
  159.      */
  160. {
  161.   Awindow *wi;
  162.  
  163.   wi = Awi_create (&FENSTER);
  164.   if (wi == NULL) return NULL;
  165.  
  166.   ((AOBJECT *) wi-> work + VALUE + 1)-> userp1 =        /* userp1 des erweiterten Objektes das VALUE trägt */
  167.     wi-> work [VALUE]. ob_spec. tedinfo-> te_ptext;    /* gleich dem Text */
  168.  
  169.   (wi-> open) (wi);                    /* öffne gleich */
  170.   return wi;
  171. }
  172.  
  173.  
  174. void delete (Awindow *window)
  175.     /*
  176.      *    
  177.      */
  178. {
  179.   Adr_unselect ();            /* die Auswahlliste löschen */
  180.   strcpy (window-> work [VALUE]. ob_spec. tedinfo-> te_ptext, "0");
  181.   (window-> obchange) (window, VALUE, window-> work [VALUE]. ob_state);
  182. }
  183.  
  184.  
  185. static int updown_service (Awindow *window, int task, void *in_out)
  186.     /*
  187.      *    service Routine
  188.      */
  189. {
  190.   switch (task) {
  191.     case AS_TERM:                /* Fenster freigeben */
  192.       Awi_delete (window); break;
  193.     case AS_DRAGGED:            /* gezogene Objekte als Ikone empfangen */
  194.       hole_wert (window); break;
  195.     case AS_DELETE:                /* lösche Wert */
  196.       delete (window); break;
  197.     case AS_INFO:                /* Info zeigen */
  198.       A_dialog (&INFOBOX); break;
  199.     default:
  200.       return FAIL;
  201.   };
  202.   return TRUE;
  203. }
  204.  
  205.  
  206. int ACSinit (void)
  207.     /*
  208.      *    Doppelklick auf NEU erzeugt ein neues Fenster
  209.      */
  210. {
  211.   Awindow *window;
  212.  
  213.   window = Awi_root ();                        /* root window */
  214.   if (window == NULL) return FAIL;            /* lege NEU Icon an */
  215.   (window-> service) (window, AS_NEWCALL, &FENSTER. create);
  216.  
  217.   return OK;
  218. }
  219.  
  220.  
  221. void ACSaboutme (void)            /* Überschreibe Default ABOUT_ME */
  222. {
  223.   A_dialog (&ABOUT_ME);
  224. }
  225.