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 / formEditURL.c < prev    next >
C/C++ Source or Header  |  2000-11-12  |  11KB  |  356 lines

  1. // ---------------------------------------------------------------------------
  2. // FormEditURL.c
  3. // Contains PalmOS specific code, for EditURL 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: formEditURL.c $  
  27. // $Author: wapuniverse $  
  28. // $Date: 2000/11/11 20:51:09 $     
  29. // $Revision: 1.9 $
  30. // 
  31. // $Header: /cvsroot/wapuniverse/wapuniverse/src/formEditURL.c,v 1.9 2000/11/11 20:51:09 wapuniverse Exp $
  32. // 
  33. // -------------------------------------------------------------------------------#include "Decls.h"
  34. #include    <PalmOS.h>
  35. #include    <SysEvtMgr.h>
  36. #include     "WAPUniverse.h"
  37. #include    "formConnectionList.h"
  38. #include    "dbUrl.h"
  39. #include    "dbConn.h"
  40. #include    "MenuHnd.h"
  41. #include    "PalmUtils.h"
  42. #include    "FormEditUrl.h"
  43. #include     "../res/WAPUniverse_res.h"
  44. #ifdef __GNUC__
  45. #include "callbacks.h"
  46. #endif
  47.  
  48.  
  49.  
  50. static Boolean EditURLDoneButton_OH(EventPtr event, GlobalsType *g) SEC_1;
  51. static Boolean TriggerURLConnection_OH(EventPtr event, GlobalsType *g) SEC_1;
  52. static Boolean EditURLCategoryPoptrigger_OH(EventPtr event, GlobalsType *g) SEC_1;
  53. static Boolean EditURLPrivateCheckBox_OH(EventPtr event) SEC_1;
  54. static Boolean EditURLDeleteButton_OH(EventPtr event, GlobalsType *g) SEC_1;
  55.  
  56. static void URLDetailsInit(GlobalsType *g)
  57. {
  58.   ControlPtr      ctl;
  59.   UInt16          attr;
  60.   Boolean         secret;
  61.   dbUrlPackedURL* purl;
  62.   MemHandle       rechand;
  63.   Int16           seekAmount = g->DbUrlCurrentRecord;
  64.   UInt16          index = 0;
  65.  
  66.   // must do seek to skip over secret records
  67.   DmSeekRecordInCategory (g->DbUrlDb, &index, seekAmount, dmSeekForward, g->DbUrlCurrentCategory);
  68.  
  69.   // Get the secret and category attributes of the current record.
  70.   DmRecordInfo (g->DbUrlDb, index, &attr, NULL, NULL);
  71.   secret = attr & dmRecAttrSecret;
  72.   g->RecordCategory = attr & dmRecAttrCategoryMask;
  73.  
  74.   // If the record is marked secret, turn on the secret checkbox.
  75.   CtlSetValue (GetObjectPtr (chkbxEditURLPrivate), secret);
  76.  
  77.   rechand = DmQueryRecord (g->DbUrlDb, index);
  78.   purl = MemHandleLock (rechand);
  79.   dbUrlUnPackURL (&g->DbUrlCurrentURL, purl);
  80.  
  81.   // Set the label of the category trigger.
  82.   CategoryGetName (g->DbUrlDb, g->RecordCategory, g->DbUrlCategoryName);
  83.   ctl = GetObjectPtr (poptriggerEditURLCategory);
  84.   CategorySetTriggerLabel (ctl, g->DbUrlCategoryName);
  85.  
  86.   // NewCategory indicates which category wants to changed the 
  87.   // current record to.  Initialize it to the current record's current
  88.   // category.
  89.   g->NewCategory = g->RecordCategory;
  90.   g->NewCategoryEdited = false;
  91.  
  92.   SetFieldFromStr(g->DbUrlCurrentURL.name , fldURLTitle);
  93.   if (StrLen(g->DbUrlCurrentURL.urlstr) == 0)
  94.       StrCopy(g->DbUrlCurrentURL.urlstr,"http://");
  95.   SetFieldFromStr(g->DbUrlCurrentURL.urlstr , fldURL);
  96.  
  97.   MemHandleUnlock (rechand);
  98.   dbConnGetConnectionsList(g);
  99.  
  100. }
  101.  
  102. static UInt16 URLDetailsApply (GlobalsType *g)
  103. {
  104.   UInt16        attr;
  105.   Boolean       secret;
  106.   UInt16        updateCode = 0;
  107.   Boolean       dirty = false;    // P11. If an attribute changed
  108.   dbUrlURL         tURL;
  109.   MemHandle     currec;
  110.   FormPtr       frm;
  111.   FieldPtr      ipPtr;
  112.   Int16         seekAmount = g->DbUrlCurrentRecord;
  113.   UInt16        index = 0;
  114.   Char             *c;
  115.  
  116.   // must do seek to skip over secret records
  117.   DmSeekRecordInCategory (g->DbUrlDb, &index, seekAmount, dmSeekForward, g->DbUrlCurrentCategory);
  118.  
  119.   // Get the secret and category attributes of the current record.
  120.   DmRecordInfo (g->DbUrlDb, index, &attr, NULL, NULL);
  121.  
  122.   frm = FrmGetFormPtr (frmEditURL);
  123.   ipPtr = (FieldPtr) (FrmGetObjectPtr (frm, (FrmGetObjectIndex (frm, fldURLTitle))));
  124.   if (FldGetTextPtr (ipPtr) != NULL)
  125.     StrCopy (tURL.name, FldGetTextPtr (ipPtr));
  126.   ipPtr = (FieldPtr) (FrmGetObjectPtr (frm, (FrmGetObjectIndex (frm, fldURL))));
  127.   if (FldGetTextPtr (ipPtr) != NULL){
  128.     StrCopy (tURL.urlstr, FldGetTextPtr (ipPtr));
  129.     while((c=StrChr(tURL.urlstr,0x0A))){  // remove CR/LF
  130.         StrCopy(c,c+1);
  131.     }
  132.   }
  133.   StrCopy (tURL.connection,g->EditURLConnection);
  134.  
  135.   currec = DmGetRecord (g->DbUrlDb, index);
  136.   dbUrlPackURL (&tURL, currec);
  137.   DmReleaseRecord (g->DbUrlDb, index, true);
  138.  
  139.   // Get the current setting of the secret checkbox.
  140.   secret = (CtlGetValue (GetObjectPtr (chkbxEditURLPrivate)) != 0);
  141.  
  142.   // Has the secret attribute been changed?
  143.   if (((attr & dmRecAttrSecret) == dmRecAttrSecret) != secret)
  144.     {
  145.       // Yes, it was changed.  What is the new setting?
  146.       if (secret)
  147.         // Now it should be secret.
  148.         attr |= dmRecAttrSecret;
  149.       else
  150.         // Now it should not be secret.
  151.         attr &= ~dmRecAttrSecret;
  152.  
  153.       dirty = true;
  154.     }
  155.  
  156.  
  157.   // P11. Has the category been changed?
  158.   if (g->RecordCategory != g->NewCategory)
  159.     {
  160.       attr &= ~dmRecAttrCategoryMask; // Remove all category bits.
  161.       attr |= g->NewCategory;      // Set the new category
  162.       dirty = true;             // mark this record dirty later
  163.       g->RecordCategory = g->NewCategory;     // remember which category the record 
  164.                                         // is in
  165.       updateCode |= updateCategoryChanged;  // send this update code
  166.     }
  167.  
  168.  
  169.   // P11. If the current category was deleted, renamed, or merged with
  170.   // another category, then the list view needs to be redrawn.
  171.   if (g->NewCategoryEdited)
  172.     {
  173.       g->RecordCategory = g->NewCategory;
  174.       updateCode |= updateCategoryChanged;
  175.     }
  176.  
  177.  
  178.   if (dirty)
  179.     {
  180.       // Set the dirty flag for the record.
  181.       attr |= dmRecAttrDirty;
  182.       DmSetRecordInfo (g->DbUrlDb, index, &attr, NULL);
  183.     }
  184.  
  185.   dbUrlSortRecord (g->DbUrlDb, &index);
  186.  
  187.   return updateCode;
  188. }
  189.  
  190.  
  191. /**----------------------------------**/
  192. /** Form Event Handler for FormEditURL**/
  193. /**----------------------------------**/
  194.  
  195. /****************************************************/
  196. /* 
  197.    Function: Boolean FormEditURL_EH(EventPtr event);
  198.    Description: Main Form Event Handler for FormEditURL
  199.  */
  200. /****************************************************/
  201.  
  202.  
  203. /* Form Event Handler */
  204. Boolean ehFormEditURL(EventPtr event)
  205. {
  206.     Boolean handled = false;
  207.     GlobalsType *g;
  208.     
  209. #ifdef __GNUC__
  210.     CALLBACK_PROLOGUE
  211. #endif
  212.  
  213.       FtrGet(wuAppType, ftrGlobals, (UInt32 *)&g);
  214.     switch(event->eType) {
  215.  
  216.         case ctlSelectEvent:
  217.             if (event->data.ctlSelect.controlID == buttonEditURLDone) {    
  218.                 handled = EditURLDoneButton_OH(event,g); }
  219.             if (event->data.ctlSelect.controlID == buttonEditURLDelete) {
  220.                 handled = EditURLDeleteButton_OH(event,g); }
  221.             if (event->data.ctlSelect.controlID == chkbxEditURLPrivate) {
  222.                 handled = EditURLPrivateCheckBox_OH(event); }
  223.             if (event->data.ctlSelect.controlID == poptriggerEditURLCategory) {
  224.                 handled = EditURLCategoryPoptrigger_OH(event,g); }
  225.             break;
  226.  
  227.         case lstSelectEvent:
  228.         case popSelectEvent:
  229.             if (event->data.popSelect.controlID == poptriggerEditURLCategory) {
  230.                 handled = EditURLCategoryPoptrigger_OH(event,g); }
  231.             if (event->data.popSelect.controlID == triggerURLConnection) {
  232.                 handled = TriggerURLConnection_OH(event,g); }
  233.             break;
  234.  
  235.         case frmOpenEvent:
  236.            URLDetailsInit(g);
  237.            FrmDrawForm(FrmGetActiveForm());
  238.            handled = true;
  239.            break;
  240.  
  241.         case menuEvent:
  242.            mhMenuEdit(event->data.menu.itemID);
  243.            break;
  244.     default:
  245.        break;
  246.  
  247.  
  248.            }
  249. #ifdef __GNUC__
  250.     CALLBACK_EPILOGUE
  251. #endif
  252.     return handled;
  253. }
  254.  
  255.  
  256. /* Item Handler Functions Here */
  257.  
  258. /**--------------------------------------**/
  259. /** Form Object Handler Functions for FormEditURL **/
  260. /**--------------------------------------**/
  261.  
  262. /****************************************************/
  263. /* 
  264.    Function: Int16 EditURLDoneButton_OH(EventPtr event);
  265.    Description: Button Object Handler for the FormEditURL Form
  266.  */
  267. /****************************************************/
  268.  
  269. static Boolean EditURLDoneButton_OH(EventPtr event, GlobalsType *g)
  270. {
  271.     URLDetailsApply(g);
  272.     dbConnDisposeConnectionsList(g);
  273.     FrmCloseAllForms ();
  274.     FrmGotoForm (frmUrlList);
  275.     return(true);
  276. }
  277.  
  278.  
  279. /****************************************************/
  280. /* 
  281.    Function: Int16 EditURLDeleteButton_OH(EventPtr event);
  282.    Description: Button Object Handler for the FormEditURL Form
  283.  */
  284. /****************************************************/
  285.  
  286. static Boolean EditURLDeleteButton_OH(EventPtr event, GlobalsType *g)
  287. {
  288.    if (dbUrlDeleteCurrentRecord (g))
  289.    {
  290.        // Delete was completed.  Close the details and the edit forms.
  291.        dbConnDisposeConnectionsList(g);
  292.        FrmCloseAllForms ();
  293.  
  294.        // Go to the main form.
  295.        FrmGotoForm (frmUrlList);
  296.    }
  297.    return(true);
  298. }
  299.  
  300.  
  301. /****************************************************/
  302. /* 
  303.    Function: Int16 EditURLPrivateCheckBox_OH(EventPtr event);
  304.    Description: CheckBox Object Handler for the FormEditURL Form
  305.  */
  306. /****************************************************/
  307.  
  308. static Boolean EditURLPrivateCheckBox_OH(EventPtr event)
  309. {
  310.  
  311.     return(0);
  312. }
  313.  
  314.  
  315. /****************************************************/
  316. /* 
  317.    Function: Int16 EditURLCategoryPoptrigger_OH(EventPtr event);
  318.    Description: Pop-up Trigger Object Handler for the FormEditURL Form
  319.  */
  320. /****************************************************/
  321.  
  322. static Boolean EditURLCategoryPoptrigger_OH(EventPtr event, GlobalsType *g)
  323. {
  324.           if (CategorySelect (g->DbUrlDb, FrmGetActiveForm (),
  325.                               poptriggerEditURLCategory, listEditURLCategoriesList,
  326.                               true, &(g->NewCategory), g->DbUrlCategoryName, 1, 0))
  327.             {
  328.               g->NewCategoryEdited = true;
  329.             }
  330.   
  331.     return(true);
  332. }
  333.  
  334.  
  335. /****************************************************/
  336. /* 
  337.    Function: Int16 TriggerURLConnection_OH(EventPtr event);
  338.    Description: Pop-up Trigger Object Handler for the FormEditURL Form
  339.  */
  340. /****************************************************/
  341.  
  342. static Boolean TriggerURLConnection_OH(EventPtr event, GlobalsType *g)
  343. {
  344.     ControlPtr      ctlPtr;
  345.     FormPtr         frm;
  346.  
  347.     g->EditURLConnection = LstGetSelectionText(event->data.popSelect.listP,
  348.                             event->data.popSelect.selection); 
  349.     frm = FrmGetFormPtr (frmEditURL);
  350.     ctlPtr =(ControlPtr)(FrmGetObjectPtr(frm,(FrmGetObjectIndex(frm,triggerURLConnection))));
  351.     CtlSetLabel(ctlPtr,g->EditURLConnection);
  352.     return(true);
  353. }
  354.  
  355.  
  356.