home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / wapuniverse-src-0.3.5.build9.tar.gz / wapuniverse-src-0.3.5.build9.tar / wapuniverse-0.3.5.build9 / formConnectionList.c < prev    next >
C/C++ Source or Header  |  2000-11-12  |  9KB  |  281 lines

  1. // ---------------------------------------------------------------------------
  2. // FormConnectionList.c
  3. // Contains the PalmOS specific code for the ConnectionList form
  4. // 
  5. // Project: WAPUniverse for PalmOS
  6. // Copyright ⌐ 1999-2000 Filip Onkelinx
  7. //
  8. // http://www.wapuniverse.com/
  9. // filip@onkelinx.com
  10. //
  11. // This program is free software; you can redistribute it and/or
  12. // modify it under the terms of the GNU General Public License
  13. // as published by the Free Software Foundation; either version 2
  14. // of the License, or (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program; if not, write to the Free Software 
  23. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
  24. //
  25. // 
  26. // $Workfile: formConnectionList.c $  
  27. // $Author: wapuniverse $  
  28. // $Date: 2000/11/11 20:51:09 $     
  29. // $Revision: 1.7 $
  30. // 
  31. // $Header: /cvsroot/wapuniverse/wapuniverse/src/formConnectionList.c,v 1.7 2000/11/11 20:51:09 wapuniverse Exp $
  32. // 
  33. // -------------------------------------------------------------------------------
  34. #include    <PalmOS.h>
  35. #include    <SysEvtMgr.h>
  36. #include     "WAPUniverse.h"
  37. #include     "../res/WAPUniverse_res.h"
  38. #include    "formConnectionList.h"
  39. #include    "MenuHnd.h"
  40. #include    "dbConn.h"
  41. #include     "WAP.h"
  42. #include     "PalmUtils.h"
  43. #ifdef __GNUC__
  44. #include "callbacks.h"
  45. #endif
  46.  
  47.         
  48.  
  49. // function prototypes
  50. static Boolean ButtonConnectionActivate_OH(EventPtr event, GlobalsType *g);
  51. static Boolean ButtonConnectionNew_OH(EventPtr event, GlobalsType *g);
  52. static Boolean ListConnectionSettings_OH(EventPtr event);
  53. static Boolean ButtonConnectionEdit_OH(EventPtr event, GlobalsType *g);
  54.  
  55. void enableConnectionEditOpen(GlobalsType *g)
  56. {
  57.   FormPtr    frm;
  58.   Boolean     enable;
  59.   UInt16    nr;
  60.   
  61.     nr =  dbConnNumRecords(g); 
  62.     if (nr >0)
  63.         enable = true;
  64.     else
  65.         enable = false;
  66.     frm = FrmGetFormPtr (frmConnectionList);
  67.     CtlSetEnabled(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, buttonConnectionActivate)),enable);
  68.       CtlSetEnabled(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, buttonConnectionEdit)),enable);
  69.     CtlSetUsable(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, buttonConnectionActivate)),enable);
  70.       CtlSetUsable(FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, buttonConnectionEdit)),enable);
  71.     
  72. }
  73.  
  74.  
  75. static void
  76. DrawOneConnectionInList (Int16 itemNumber, RectangleType *bounds, Char * * text)
  77. {
  78.   MemHandle            h;
  79.   Int16             seekAmount = itemNumber;
  80.   UInt16            index = 0;
  81.   GlobalsType         *g;
  82.  
  83.  
  84. #ifdef __GNUC__
  85.   CALLBACK_PROLOGUE
  86. #endif
  87.  
  88.  FtrGet(wuAppType, ftrGlobals, (UInt32 *)&g);
  89.  
  90.   // must do seek to skip over secret records
  91.   DmSeekRecordInCategory (g->DbConnDb, &index, seekAmount, dmSeekForward, dmAllCategories);
  92.   h = DmQueryRecord (g->DbConnDb, index);
  93.   if (h)
  94.     {
  95.       dbConnPackedConnection* packedConnection = MemHandleLock (h);
  96.  
  97.       if (StrCompare (packedConnection->name, g->ActiveConnection) == 0)
  98.         DrawCharsToFitWidth (packedConnection->name, bounds, '\273');
  99.       else
  100.         DrawCharsToFitWidth (packedConnection->name, bounds, ' ');
  101.       MemHandleUnlock (h);
  102.     }
  103. #ifdef __GNUC__
  104.   CALLBACK_EPILOGUE
  105. #endif
  106. }
  107.  
  108. static void
  109. InitViewConnectionList(GlobalsType *g)
  110. {
  111.  
  112.   FormPtr         frm = FrmGetActiveForm ();
  113.   ListPtr         list = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, lstConnectionSettings));
  114.   UInt16            numConnections = DmNumRecordsInCategory (g->DbConnDb, dmAllCategories);
  115.   LstSetListChoices (list, NULL, numConnections);
  116.   LstSetDrawFunction (list, DrawOneConnectionInList);
  117.  
  118. }
  119.  
  120.  
  121. /**----------------------------------**/
  122. /** Form Event Handler for FormConnectionList**/
  123. /**----------------------------------**/
  124.  
  125. /****************************************************/
  126. /* 
  127.    Function: Boolean FormConnectionList_EH(EventPtr event);
  128.    Description: Main Form Event Handler for FormConnectionList
  129.  */
  130. /****************************************************/
  131.  
  132.  
  133. /* Form Event Handler */
  134. Boolean ehFormConnectionList(EventPtr event)
  135. {
  136.     Boolean handled = false;
  137.     GlobalsType *g;
  138.     
  139. #ifdef __GNUC__
  140.     CALLBACK_PROLOGUE
  141. #endif
  142.  
  143.     FtrGet(wuAppType, ftrGlobals, (UInt32 *)&g);
  144.     switch(event->eType) {
  145.  
  146.         case ctlSelectEvent:
  147.             if (event->data.ctlSelect.controlID == buttonConnectionActivate) {
  148.                 handled = ButtonConnectionActivate_OH(event, g); }
  149.             if (event->data.ctlSelect.controlID == buttonConnectionNew) {
  150.                 handled = ButtonConnectionNew_OH(event, g); }
  151.             if (event->data.ctlSelect.controlID == buttonConnectionEdit) {
  152.                 handled = ButtonConnectionEdit_OH(event, g); }
  153.             if (event->data.ctlSelect.controlID == buttonViewC) {
  154.                 if(dbConnNumRecords(g)>0){
  155.                     SwitchForm(frmUrlList,g);                     
  156.                 }
  157.                 else{
  158.                     FrmCustomAlert (alError, "You need to define at least one connection\n", "", NULL);
  159.                 }
  160.                 }
  161.             if (event->data.ctlSelect.controlID == buttonInfoC) {
  162.                 DisplayAbout(); }
  163.             break;
  164.  
  165.         case ctlRepeatEvent:
  166.             break;
  167.  
  168.         case tblSelectEvent:
  169.             break;
  170.  
  171.         case lstSelectEvent:
  172.         case popSelectEvent:
  173.             if (event->data.ctlSelect.controlID == lstConnectionSettings) {
  174.                 ListConnectionSettings_OH(event); }
  175.             break;
  176.  
  177.         case sclEnterEvent:
  178.             break;
  179.  
  180.  
  181.         case frmOpenEvent:
  182.            InitViewConnectionList(g);
  183.            enableConnectionEditOpen(g);
  184.            FrmDrawForm(FrmGetActiveForm());
  185.            handled = true;
  186.            break;
  187.  
  188.          case menuEvent:
  189.              mhMenuOptions(event->data.menu.itemID,g);
  190.              break;
  191.     default:
  192.          break;
  193.  
  194.  
  195.            }
  196. #ifdef __GNUC__
  197.     CALLBACK_EPILOGUE
  198. #endif
  199.     return handled;
  200. }
  201.  
  202.  
  203. /* Item Handler Functions Here */
  204.  
  205. /**--------------------------------------**/
  206. /** Form Object Handler Functions for FormConnectionList **/
  207. /**--------------------------------------**/
  208.  
  209. /****************************************************/
  210. /* 
  211.    Function: Int16 ButtonConnectionActivate_OH(EventPtr event);
  212.    Description: Button Object Handler for the FormConnectionList Form
  213.  */
  214. /****************************************************/
  215.  
  216. static Boolean ButtonConnectionActivate_OH(EventPtr event, GlobalsType *g)
  217. {
  218.   FormPtr frm;
  219.  
  220.      frm = FrmGetActiveForm ();
  221.      g->DbConnCurrentRecord = LstGetSelection (FrmGetObjectPtr (frm,                                                           FrmGetObjectIndex
  222.                                                                 (frm, lstConnectionSettings)));
  223.      dbConnReadCurrentConnection (g);
  224.      StrCopy (g->ActiveConnection, g->CurrentConnection.name);
  225.      g->CurrentView = frmConnectionList;
  226.      FrmGotoForm (g->CurrentView);
  227.       return(true);
  228. }
  229.  
  230.  
  231. /****************************************************/
  232. /* 
  233.    Function: Int16 ButtonConnectionNew_OH(EventPtr event);
  234.    Description: Button Object Handler for the FormConnectionList Form
  235.  */
  236. /****************************************************/
  237. static Boolean ButtonConnectionNew_OH(EventPtr event, GlobalsType *g)
  238. {
  239.  
  240.    dbConnCreateRecord (g);
  241.    g->CurrentView = frmEditConnection;
  242.    FrmGotoForm (g->CurrentView);
  243.    enableConnectionEditOpen(g);
  244.    return(true);
  245. }
  246.  
  247.  
  248. /****************************************************/
  249. /* 
  250.    Function: Int16 ButtonConnectionEdit_OH(EventPtr event);
  251.    Description: Button Object Handler for the FormConnectionList Form
  252.  */
  253. /****************************************************/
  254. static Boolean ButtonConnectionEdit_OH(EventPtr event, GlobalsType *g)
  255. {
  256.   FormPtr frm;
  257.   
  258.     frm = FrmGetActiveForm ();
  259.     g->DbConnCurrentRecord = LstGetSelection (FrmGetObjectPtr (frm, 
  260.                            FrmGetObjectIndex(frm, lstConnectionSettings)));
  261.     g->CurrentView = frmEditConnection;
  262.     FrmGotoForm (g->CurrentView);
  263.     return(true);
  264. }
  265.  
  266.  
  267. /****************************************************/
  268. /* 
  269.    Function: Int16 ListConnectionSettings_OH(EventPtr event);
  270.    Description: List Object Handler for the FormConnectionList Form
  271.  */
  272. /****************************************************/
  273.  
  274. static Boolean ListConnectionSettings_OH(EventPtr event)
  275. {
  276.  
  277.     return(0);
  278. }
  279.  
  280.  
  281.