home *** CD-ROM | disk | FTP | other *** search
/ linuxmafia.com 2016 / linuxmafia.com.tar / linuxmafia.com / pub / palmos / happydays-src-1.37.tar.gz / happydays-src-1.37.tar / happydays-1.37 / s2lconvert.c < prev    next >
C/C++ Source or Header  |  2000-11-03  |  7KB  |  232 lines

  1. /*
  2. HappyDays - A Birthdate displayer for the PalmPilot
  3. Copyright (C) 1999-2000 JaeMok Jeong
  4.  
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9.  
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with this program; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. */
  19.  
  20. #include <PalmOS.h>
  21.  
  22. #include "happydays.h"
  23. #include "happydaysRsc.h"
  24. #include "calendar.h"
  25. #include "birthdate.h"
  26. #include "util.h"
  27.  
  28. static Boolean TextMenuHandleEvent(UInt16 menuID, UInt16 objectID)
  29. {
  30.     FormPtr   form = FrmGetActiveForm();
  31.     FieldPtr  field = GetObjectPointer(form, objectID);
  32.  
  33.     if (!field) return false;
  34.  
  35.     switch (menuID) {
  36.     case TextMenuUndo:
  37.         FldUndo(field);
  38.         return true;
  39.     case TextMenuCut:
  40.         FldCut(field);
  41.         return true;
  42.     case TextMenuCopy:
  43.         FldCopy(field);
  44.         return true;
  45.     case TextMenuPaste:
  46.         FldPaste(field);
  47.         return true;
  48.     case TextMenuSAll:
  49.         FldSetSelection(field, 0, FldGetTextLength (field));
  50.         return true;
  51.     case TextMenuKBoard:
  52.         SysKeyboardDialog(kbdDefault);
  53.         return true;
  54.  
  55.     case TextMenuGHelp:
  56.         SysGraffitiReferenceDialog(referenceDefault);
  57.         return true;
  58.     }
  59.  
  60.     return false;
  61. }
  62.  
  63.  
  64. Boolean Sl2LnFormHandleEvent(EventPtr e)
  65. {
  66.     Boolean handled = false;
  67.     DateType dt = {0, 0};
  68.     FormPtr frm = FrmGetFormPtr(Sl2LnForm);
  69.  
  70.     switch (e->eType) {
  71.     case frmOpenEvent:
  72.         DateSecondsToDate(TimGetSeconds(), &dt);
  73.  
  74.         DateToAsciiLong(dt.month, dt.day, dt.year + 1904,
  75.                         gPrefdfmts, gAppErrStr);
  76.  
  77.         SetFieldTextFromStr(Sl2LnFormInput, gAppErrStr);
  78.  
  79.         FrmDrawForm(frm);
  80.         handled = true;
  81.         break;
  82.  
  83.     case ctlSelectEvent:
  84.         switch(e->data.ctlSelect.controlID) {
  85.         case Sl2LnFormConvert:
  86.         {
  87.             DateTimeType rtVal;
  88.             BirthdateFlag dummy;
  89.             Int16 year, month, day;
  90.             Char* input;
  91.             int ret = false;
  92.  
  93.             input = FldGetTextPtr(GetObjectPointer(frm, Sl2LnFormInput));
  94.             if ((ret = AnalysisBirthDate(input, &dummy,
  95.                                          &year, &month, &day))) {
  96.                 int leapyes = 0;
  97.  
  98.                 ret = !sol2lun(year, month, day, &rtVal,
  99.                                &leapyes);
  100.                 if (ret) {
  101.                     if (leapyes) {
  102.                         StrCopy(gAppErrStr, "#)");
  103.                     }
  104.                     else {
  105.                         StrCopy(gAppErrStr, "-)");
  106.                     }
  107.                     DateToAsciiLong(rtVal.month, rtVal.day, rtVal.year,
  108.                                     gPrefdfmts, &gAppErrStr[2]);
  109.                           
  110.                     FldDrawField(SetFieldTextFromStr(Sl2LnFormResult,
  111.                                                      gAppErrStr));
  112.                 }
  113.  
  114.             }
  115.             if (!ret) {
  116.                 FldDrawField(ClearFieldText(Sl2LnFormResult));
  117.                 SysCopyStringResource(gAppErrStr, InvalidDateString);
  118.                 FrmCustomAlert(ErrorAlert, gAppErrStr, " ", " ");
  119.             }
  120.  
  121.             handled = true;
  122.             break;
  123.         }
  124.  
  125.         case Sl2LnFormOk:
  126.             FrmReturnToForm(0);
  127.  
  128.             handled = true;
  129.             break;
  130.             
  131.         default:
  132.             break;
  133.                 
  134.         }
  135.         break;
  136.  
  137.     case menuEvent:
  138.         handled = TextMenuHandleEvent(e->data.menu.itemID, Sl2LnFormInput);
  139.         break;
  140.  
  141.     default:
  142.         break;
  143.     }
  144.  
  145.     return handled;
  146. }
  147.  
  148. Boolean Ln2SlFormHandleEvent(EventPtr e)
  149. {
  150.     Boolean handled = false;
  151.     DateType dt = {0, 0};
  152.     FormPtr frm = FrmGetFormPtr(Ln2SlForm);
  153.  
  154.     switch (e->eType) {
  155.     case frmOpenEvent:
  156.         DateSecondsToDate(TimGetSeconds(), &dt);
  157.         DateToAsciiLong(dt.month, dt.day, dt.year + 1904,
  158.                     gPrefdfmts, gAppErrStr);
  159.         SetFieldTextFromStr(Ln2SlFormInput, gAppErrStr);
  160.  
  161.         FrmDrawForm(frm);
  162.         handled = true;
  163.         break;
  164.  
  165.     case ctlSelectEvent:
  166.         switch(e->data.ctlSelect.controlID) {
  167.         case Ln2SlFormOk:
  168.             FrmReturnToForm(0);
  169.  
  170.             handled = true;
  171.             break;
  172.  
  173.         case Ln2SlFormConvert:
  174.         {
  175.             DateTimeType rtVal;
  176.             BirthdateFlag dummy;
  177.             Int16 year, month, day;
  178.             Char* input;
  179.             int ret;
  180.             
  181.             input = FldGetTextPtr(GetObjectPointer(frm, Ln2SlFormInput));
  182.  
  183.             if ((ret = AnalysisBirthDate(input, &dummy,
  184.                                          &year, &month, &day))) {
  185.                 int leapyes
  186.                     = CtlGetValue(GetObjectPointer(frm, Ln2SlFormInputLeap));
  187.  
  188.                 ret = !lun2sol(year, month, day, leapyes, &rtVal);
  189.                 if (ret) {
  190.                     Char temp[15];
  191.                     SysCopyStringResource(temp,
  192.                                           DayOfWeek(rtVal.month, rtVal.day,
  193.                                                     rtVal.year) + SunString);
  194.  
  195.                     DateToAsciiLong(rtVal.month, rtVal.day, rtVal.year,
  196.                                     gPrefdfmts, gAppErrStr);
  197.                     StrNCat(gAppErrStr, " [", AppErrStrLen);
  198.                     StrNCat(gAppErrStr, temp, AppErrStrLen);
  199.                     StrNCat(gAppErrStr, "]", AppErrStrLen);
  200.  
  201.                     FldDrawField(SetFieldTextFromStr(Ln2SlFormResult,
  202.                                                      gAppErrStr));
  203.                 }
  204.             }
  205.             
  206.             if (!ret) {
  207.                 FldDrawField(ClearFieldText(Ln2SlFormResult));
  208.                 SysCopyStringResource(gAppErrStr, InvalidDateString);
  209.                 FrmCustomAlert(ErrorAlert, gAppErrStr, " ", " ");
  210.             }
  211.             
  212.             handled = true;
  213.             break;
  214.         }
  215.         
  216.         default:
  217.             break;
  218.                 
  219.         }
  220.         break;
  221.  
  222.     case menuEvent:
  223.         handled = TextMenuHandleEvent(e->data.menu.itemID, Ln2SlFormInput);
  224.         break;
  225.  
  226.     default:
  227.         break;
  228.     }
  229.  
  230.     return handled;
  231. }
  232.