home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / tools / nosecuri / nosecuri.EXE / nosecurity.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-11  |  4.2 KB  |  162 lines

  1. //=============================================================================
  2. // $Id: nosecurity.c,v 1.1 1999/05/25 15:19:59 hofer Exp hofer $
  3. //=============================================================================
  4.  
  5. /*
  6. Copyright (C) 1999 Remo Hofer <nucifera@geocities.com>
  7. For more information see http://www.geocities.com/SiliconValley/Cable/5206/
  8.  
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22. */
  23.  
  24. // include headers
  25. #include <Pilot.h>
  26. #include <System/Password.h>
  27. #include "callback.h"
  28. #include "resources.h"
  29.  
  30. // global vaiables
  31. Char    titlestr[80];
  32.  
  33. //-----------------------------------------------------------------------------
  34. Boolean MainFormHandleEvent(EventPtr event) {
  35.     FormPtr            formPtr;
  36.     VoidHand        h;
  37.     SWord            x, y;
  38.     Boolean            handled = false;
  39.     
  40.     CALLBACK_PROLOGUE
  41.     
  42.     formPtr = FrmGetFormPtr(idMainForm);
  43.  
  44.     switch (event->eType) {
  45.  
  46.       case frmOpenEvent:
  47.         // set form title and label to the application name
  48.           h = DmGetResource(ainRsc, idAppName);
  49.           StrCopy(titlestr,  MemHandleLock(h));
  50.         MemHandleUnlock(h);
  51.           DmReleaseResource(h);
  52.           FrmSetTitle(formPtr, titlestr);
  53.         FrmCopyLabel(formPtr, idAppNameLabel, titlestr);
  54.         // set form label to application version string
  55.           h = DmGetResource(verRsc, idVersion);
  56.         FrmCopyLabel(formPtr, idVersionLabel, MemHandleLock(h));
  57.           MemHandleUnlock(h);
  58.           DmReleaseResource(h);
  59.         case frmUpdateEvent:
  60.          // draw the form
  61.         FrmDrawForm(formPtr);
  62.         // get the coords of the button rect to draw into
  63.         FrmGetObjectPosition(formPtr, FrmGetObjectIndex(formPtr, idIconRect), 
  64.           &x, &y);
  65.           // get and draw the bitmap of the application icon
  66.            h = DmGetResource(iconType, idAppIcon);
  67.         WinDrawBitmap(MemHandleLock(h), x, y);
  68.           MemHandleUnlock(h);
  69.           DmReleaseResource(h);
  70.         handled = true;
  71.         break;
  72.         
  73.       case ctlSelectEvent:
  74.         switch (event->data.ctlSelect.controlID) {
  75.           case idAboutButton:
  76.             // show about form
  77.             FrmHelp(idAboutStr);
  78.             handled = true;
  79.             break;
  80.           case idPasswordButton:
  81.             if (PwdExists()) {
  82.                 // remove password
  83.                 PwdRemove();
  84.                 FrmAlert(idPasswordRemovedAlert);
  85.             } else {
  86.                 // no password is assigned
  87.                 FrmAlert(idNoPasswordAlert);
  88.             }
  89.             handled = true;
  90.             break;
  91.         }
  92.         
  93.     }
  94.     
  95.     CALLBACK_EPILOGUE
  96.     return(handled);
  97. }
  98.  
  99. //-----------------------------------------------------------------------------
  100. static Boolean ApplicationHandleEvent(EventPtr event) {
  101.     Word    formId;
  102.     FormPtr    formPtr;
  103.     
  104.     if (event->eType == frmLoadEvent) {
  105.  
  106.         formId = event->data.frmLoad.formID;
  107.         
  108.         // load the form resource
  109.         formPtr = FrmInitForm(formId);
  110.         FrmSetActiveForm(formPtr);        
  111.  
  112.         // set the event handler for the form
  113.         FrmSetEventHandler (formPtr, MainFormHandleEvent);
  114.  
  115.         return(true);
  116.         
  117.     }
  118.             
  119.     return(false);
  120.  
  121. }
  122.  
  123. //-----------------------------------------------------------------------------
  124. static void EventLoop(void) {
  125.     EventType    event;
  126.     Word    error;
  127.  
  128.     do {
  129.         EvtGetEvent(&event, evtWaitForever);
  130.         if (! SysHandleEvent(&event)) {
  131.             if (! MenuHandleEvent(NULL, &event, &error)) {
  132.                 if (! ApplicationHandleEvent(&event)) {
  133.                     FrmDispatchEvent(&event);
  134.                 }
  135.             }
  136.         }
  137.     } while (event.eType != appStopEvent);    
  138.  
  139. }
  140.  
  141. //-----------------------------------------------------------------------------
  142. DWord PilotMain(Word cmd, Ptr cmdPBP, Word launchFlags) {
  143.     
  144.     switch (cmd) {
  145.         
  146.       case sysAppLaunchCmdNormalLaunch:
  147.         // display the initial form (usally called from StartApplication)
  148.         FrmGotoForm(idMainForm);
  149.         // enter the event loop
  150.         EventLoop();
  151.         // send a frmCloseEvent to active form handlers
  152.         // (usally called from StopApplication)
  153.         FrmCloseAllForms();
  154.         break;
  155.         
  156.     }
  157.  
  158.     return(0);
  159. }
  160.  
  161. //=============================================================================
  162.