home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 September / PCO_0998.ISO / filesbbs / frei / palmsrc.arj / PALMSRC.ZIP / AppStdIO.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-07-06  |  4.5 KB  |  155 lines

  1. /***********************************************************************
  2.  *
  3.  *    Copyright (c) Palm Computing 1996 -- All Rights Reserved ip_rcv
  4.  *
  5.  * PROJECT:  Any Pilot app that wants a stdio window
  6.  * FILE:     AppStdIO.h
  7.  * AUTHOR:     Ron Marianetti 8/20/96
  8.  *
  9.  * DESCRIPTION:
  10.  *      This module implements stdin/stdout support for a pilot application.
  11.  * It requires that the application provide a form with a text field and
  12.  * up and down repeating buttons. 
  13.  *
  14.  *   To use this module, the application must do the following:
  15.  *
  16.  * 1.) Call StdInit during app initialization. StdInit() will save away
  17.  *        the object ID of the form that contains the stdio field, the field
  18.  *        itself, and the up and down buttons in the field. It also saves
  19.  *        the pointer to the procedure in the application which is responsible
  20.  *        for executing command lines. This procedure will be called when the user
  21.  *        enters a return character in the field.
  22.  *
  23.  *    2.) Call StdHandleEvent from the form's event handler before doing application
  24.  *        specific processing of the event.
  25.  *        In other words, the form event handler that the application
  26.  *        installs with FrmSetEventHandler() should call StdHandleEvent before
  27.  *        it does anything else with the event. 
  28.  *
  29.  * 3.) Call StdFree() during app shutdown.
  30.  *
  31.  *
  32.  * Other than that, the app is free to call StdPutS, StdPrintF, etc anytime it wants
  33.  *        between the StdInit() and StdFree() calls. If the current form is not the
  34.  *        StdIO form when these calls are made, they will record changes to the
  35.  *        active text and display it next time the form becomes active. 
  36.  *
  37.  *----------------------------------------------------------------------------
  38.  *
  39.  * A "typical" application will have the following routine called
  40.  *        ApplicationHandleEvent which gets called from it's main event loop
  41.  *        after SysHandleEvent() and MenuHandleEvent():
  42.  *
  43.  *----------------------------------------------------------------------------
  44.     static Boolean ApplicationHandleEvent (EventPtr event)
  45.     {
  46.         FormPtr frm;
  47.         Word formId;
  48.  
  49.         if (event->eType == frmLoadEvent) {
  50.             formId = event->data.frmLoad.formID;
  51.             frm = FrmInitForm (formId);
  52.             FrmSetActiveForm (frm);        
  53.             
  54.             switch (formId) {
  55.                 .....
  56.                 case myViewWithStdIO:
  57.                     FrmSetEventHandler (frm, MyViewHandleEvent);
  58.                     break;
  59.                 }
  60.             return (true);
  61.             }     
  62.  
  63.         return (false);
  64.         }     
  65.  *
  66.  *
  67.  *----------------------------------------------------------------------------
  68.  *
  69.  * A "typical" application form event handler will look like this:
  70.  *
  71.  *----------------------------------------------------------------------------
  72.     static Boolean MyViewHandleEvent (EventPtr event)
  73.     {
  74.         FormPtr frm;
  75.         Boolean handled = false;
  76.  
  77.  
  78.         // Let StdIO handler to it's thing first.
  79.         if (StdHandleEvent(event)) return true;
  80.  
  81.  
  82.         // If StdIO did not completely handle the event...
  83.         if (event->eType == keyDownEvent) {
  84.             if ( (event->data.keyDown.modifiers & commandKeyMask) &&
  85.                     (event->data.keyDown.chr == hardCradleChr) ) {
  86.                 FrmGotoForm( kMainFormID );                    // exit to main view
  87.                 EvtAddEventToQueue( event );                    // ... and repost the key event
  88.                 handled = true;
  89.                 }
  90.             
  91.         else if (event->eType == ctlSelectEvent) {        
  92.             switch (event->data.ctlSelect.controlID) {
  93.                 case myViewDoneButtonID:
  94.                     FrmGotoForm (networkFormID);
  95.                     handled = true;
  96.                     break;
  97.                 }
  98.             }
  99.  
  100.  
  101.         else if (event->eType == menuEvent) 
  102.             return MyMenuDoCommand( event->data.menu.itemID );
  103.  
  104.             
  105.         else if (event->eType == frmUpdateEvent) {
  106.             MyViewDraw( FrmGetActiveForm() );
  107.             handled = true;
  108.             }
  109.             
  110.             
  111.         else if (event->eType == frmOpenEvent) {
  112.             frm = FrmGetActiveForm();
  113.             MyViewInit( frm );
  114.             MyViewDraw( frm );
  115.             handled = true;
  116.             }
  117.             
  118.             
  119.         else if (event->eType == frmCloseEvent) {
  120.             frm = FrmGetActiveForm();
  121.             MyViewClose(frm);
  122.             }
  123.             
  124.         return (handled);
  125.     }
  126.  *
  127.  *
  128.  **********************************************************************/
  129.  
  130. Err        StdInit(Word formID, Word fieldID, Word scrollerID, 
  131.                 void (*appProcessCmd)(CharPtr cmdP) );
  132. Err        StdFree(void);
  133. Err        StdSave(void); /* VM */
  134. Boolean     StdHandleEvent (EventPtr event);
  135.  
  136.  
  137. void         StdColumn (Word column);
  138. void         StdBS (void);
  139. void         StdPutS (CharPtr str);
  140. void         StdClear(void);
  141. int        StdPrintF(const CharPtr formatStr, ...);
  142. int        StdFPrintF(unsigned char* fd, const CharPtr formatStr, ...);
  143. int        StdVPrintF(const CharPtr formatStr, va_list args);
  144. Int        StdGetS(CharPtr strP, Boolean echo);
  145. Int        StdGetChar(Boolean echo);
  146.  
  147.  
  148. #ifndef    __DONT_MAP_STDIO__
  149. #define    printf                StdPrintF
  150. #define    fprintf                StdFPrintF
  151. #define    puts                StdPutS
  152. #endif
  153.  
  154.  
  155.