Example #1
0
/***********************************************************************
 *
 * FUNCTION:    ThumbnailViewInit
 *
 * DESCRIPTION: This routine initializes the "Thumbnail View".
 *
 * PARAMETERS:  event  - a pointer to an EventType structure
 *
 * RETURNED:    nothing.
 *
 ***********************************************************************/
static void ThumbnailViewInit (FormPtr frm) {
  ControlPtr ctl;
  UInt16 i;
  Err err;
  DynamicButtonType* btn;

  for (i = Thumb1; i <= Thumb30; ++i) {
    btn = DynBtnInitGadget(i, rectangleFrame, true, true, false, d.sonyClie, 
               d.sonyHRRefNum, false, dynBtnGraphical, 0, &err, frm,
               ThumbnailGadgetEvent);
    if (err != errNone) abort();
  }

  ThumbnailViewLoadRecords(frm);

  /* Set the label of the category trigger. */
  ctl = GetObjectPointer(frm, CategoryPop);
  CategoryGetName(d.dbR, p.category, d.categoryName);
  CategorySetTriggerLabel(ctl, d.categoryName);

  /* Update scroll bar variables */
  ThumbnailViewUpdateScrollers(frm);

  /* Initialize grid coordinates */
  MapIndexToCoordinates(&p.dbI, &d.thumbnailX, &d.thumbnailY);
}
Example #2
0
/* Get category name */
void GetCategoryName
    (
    UInt8   index,  /* category index */
    Char*   name    /* upon successful return, the name of
                       the category, otherwise an empty string */
    )
{
    CategoryGetName( plkrDocList, index, name );
}
Example #3
0
/***********************************************************************
 *
 * FUNCTION:    ThumbnailViewNextCategory
 *
 * DESCRIPTION: This routine display the next category,  if the last
 *              catagory isn't being displayed
 *
 * PARAMETERS:  nothing
 *
 * RETURNED:    nothing
 *
 *              The following global variables are modified:
 *          p.category
 *          d.categoryName
 *
 ***********************************************************************/
void ThumbnailViewNextCategory(void) {
  UInt16 category = CategoryGetNext(d.dbR, p.category);

  if (category != p.category) {
    FormPtr frm = FrmGetActiveForm();
    ControlPtr ctl = GetObjectPointer(frm, CategoryPop);

    ChangeCategory(category);

    /* Set the label of the category trigger. */
    CategoryGetName(d.dbR, p.category, d.categoryName);
    CategorySetTriggerLabel(ctl, d.categoryName);

    /* Display the new category. */
    SetTopVisibleRecord(0);
    ThumbnailViewLoadGadgets(frm);
  }
}
Example #4
0
/* Create new item in app database */
static UInt16
DoTheBoogie(KleenexPtr kleenexP, DmOpenRef dbR, UInt16 *index)
{
    MemoItemType memo;
    UInt16 ii, category, result;
    Char catName[dmCategoryLength];
    const UInt32 titleLen = StrLen(kleenexP->text);
    const UInt32 noteLen = kleenexP->note ? StrLen(kleenexP->note) : 0;
    Char* note = MemPtrNew(noteLen ? titleLen + 2 + noteLen + 1 : titleLen + 1);

    // Create memo text
    StrCopy(note, kleenexP->text);
    if (noteLen) {
      StrCat(note, "\n\n");
      StrCat(note, kleenexP->note);
    }

    // Set up the new item
    memo.note = note;

    // Set up category
    category = dmUnfiledCategory;
    if (kleenexP->category) {
        StrCopy(catName, "");
        for (ii=0; ii<dmRecNumCategories; ii++) {
            CategoryGetName(dbR, ii, catName);
            if (!StrCaselessCompare(catName, kleenexP->category)) {
                category = ii;
                break;
            }
        }
    }

    // Add it to the DB
    result = MemoNewRecord(dbR, &memo, category, index);

    // Clean up
    MemPtrFree(note);

    return result;
}
Example #5
0
Boolean
CourseListHandleEvent(EventPtr event)
{
  FormPtr frm=FrmGetActiveForm();
  Boolean handled = false;
  ListType *lstP=GetObjectPtr(LIST_courses);
  Boolean categoryEdited, reDraw=false;
  UInt16 category, numRecords;
  ControlType *ctl;
  UInt32 *recordList;

  if (event->eType == ctlSelectEvent) {
    // button handling
    switch (event->data.ctlSelect.controlID) {
      case BUTTON_courselist_back:
        handled=true;
        FrmGotoForm(FORM_main);
        break;

      case BUTTON_courselist_del:
        handled=true;
        if (LstGetSelection(lstP) == noListSelection) {
          FrmAlert(ALERT_clist_noitem);
        } else {
          DeleteCourse(gCourseInd[LstGetSelection(lstP)]);
          CleanupCourselist();
          DrawCourses(lstP);
          FrmDrawForm(FrmGetActiveForm());
        }
        break;

      case BUTTON_courselist_add:
        handled=true;
        gMenuCurrentForm=FORM_courselist;
        AddCourse();
        break;

      case BUTTON_courselist_edit:
        handled=true;
        if (LstGetSelection(lstP) == noListSelection) {
          FrmAlert(ALERT_clist_noitem);
        } else {
          gMenuCurrentForm=FORM_courselist;
          EditCourse(gCourseInd[LstGetSelection(lstP)]);
        }
        break;

      case BUTTON_courselist_beam:
        handled=true;
        if (LstGetSelection(lstP) == noListSelection) {
          FrmAlert(ALERT_clist_noitem);
        } else {
          BeamCourse(gCourseInd[LstGetSelection(lstP)]);
        }
        break;


      case LIST_cl_cat_trigger:
        handled=true;
        category=DatabaseGetCat();
        numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY);
        recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32));
        CatPreEdit(numRecords, recordList);
        categoryEdited = CategorySelect(DatabaseGetRef(), frm,
                                        LIST_cl_cat_trigger, LIST_cl_cat, false,
                                        &category, gCategoryName, 0,
                                        STRING_cat_edit); // categoryDefaultEditCategoryString
        if (categoryEdited || (category != DatabaseGetCat())) {
          reDraw=true;
          DatabaseSetCat(category);
          ctl = GetObjectPtr(LIST_cl_cat_trigger);
          CategoryGetName(DatabaseGetRef(), category, gCategoryName); 
          CategorySetTriggerLabel(ctl, gCategoryName);
        }
        CatPostEdit(numRecords, recordList);
        if (reDraw) {
          CleanupCourselist();
          DrawCourses(lstP);
          FrmDrawForm(FrmGetActiveForm());
        }
        if (recordList != NULL)  MemPtrFree((MemPtr)recordList);
        break;



      default:
        break;
    }
  } else if (event->eType == keyDownEvent) {
    // We have a hard button assigned and it was pressed
    if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
      if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) {
        FrmGotoForm(FORM_main);
        handled = true;
      }
    } else if (EvtKeydownIsVirtual(event)) {
      // Up or down keys pressed
      ListType *lst=GetObjectPtr(LIST_courses);
      switch (event->data.keyDown.chr) {
        case vchrPageUp:
          if (LstGetSelection(lst) == noListSelection) {
            LstSetSelection(lst, gNumCourses-1);
            CourseListHandleSelection();
          } else if (LstGetSelection(lst) > 0) {
            LstSetSelection(lst, LstGetSelection(lst)-1);
            CourseListHandleSelection();
          }
          handled=true;
          break;
        
        case vchrPageDown:
          if (LstGetSelection(lst) == noListSelection) {
            LstSetSelection(lst, 0);
            CourseListHandleSelection();
          } else if (LstGetSelection(lst) < (gNumCourses-1)) {
            LstSetSelection(lst, LstGetSelection(lst)+1);
            CourseListHandleSelection();
          }
          handled=true;
          break;

        default:
          break;
      }
    }
  } else if (event->eType == lstSelectEvent) {
    return CourseListHandleSelection();
  } else if (event->eType == menuOpenEvent) {
    return HandleMenuOpenEvent(event);
  } else if (event->eType == menuEvent) {
    // forwarding of menu events
    return HandleMenuEvent(event->data.menu.itemID);
  } else if (event->eType == frmOpenEvent) {
    // initializes and draws the form
    ControlType *ctl;

    frm = FrmGetActiveForm();
    lstP=GetObjectPtr(LIST_courses);
    FrmDrawForm (frm);
    DrawCourses(lstP);
    FrmDrawForm (frm);

    ctl = GetObjectPtr(LIST_cl_cat_trigger);
    CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
    CategorySetTriggerLabel (ctl, gCategoryName); 

    WinDrawLine(1, 140, 158, 140);
    
    handled = true;
  } else if (event->eType == frmUpdateEvent) {
    // redraws the form if needed
    CleanupCourselist();
    DrawCourses(GetObjectPtr(LIST_courses));
    FrmDrawForm (frm);
    WinDrawLine(1, 140, 158, 140);
    handled = false;
  } else if (event->eType == frmCloseEvent) {
    // this is done if form is closed
    CleanupCourselist();
  }

  return (handled);

}
Example #6
0
Boolean
ExamsFormHandleEvent(EventPtr event)
{
  FormPtr frm=FrmGetActiveForm();
  Boolean handled = false;
  Boolean categoryEdited, reDraw=false;
  UInt16 category, numRecords;
  ControlType *ctl;
  UInt32 *recordList;

  if (event->eType == ctlSelectEvent) {
    // button handling
    switch (event->data.ctlSelect.controlID) {
      case BUTTON_ex_back:
        handled=true;
        FrmGotoForm(FORM_main);
        break;

      case BUTTON_ex_add:
        handled=true;
        if (CountCourses() > 0) {
          gExamsLastSelRowUID=0;
          FrmPopupForm(FORM_exam_details);
        } else {
          FrmAlert(ALERT_nocourses);
        }
        break;

      case BUTTON_ex_edit:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        FrmPopupForm(FORM_exam_details);
        break;

      case BUTTON_ex_note:
      {
        UInt16 index=0;

        handled=true;

        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index);
        NoteSet(index, FORM_exams);
        FrmPopupForm(NewNoteView);
        break;
      }

      case BUTTON_ex_del:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        ExamDelete();
        break;

      case BUTTON_ex_beam:
        handled=true;
        gExamsLastSelRowUID=TblGetRowData(GetObjectPtr(TABLE_exams), gExamsSelRow);
        ExamBeam();
        break;

      case LIST_ex_cat_trigger:
        handled=true;
        category=DatabaseGetCat();
        numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY);
        recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32));
        CatPreEdit(numRecords, recordList);
        categoryEdited = CategorySelect(DatabaseGetRef(), frm,
                                        LIST_ex_cat_trigger, LIST_ex_cat, false,
                                        &category, gCategoryName, 0,
                                        STRING_cat_edit); // categoryDefaultEditCategoryString
        if (categoryEdited || (category != DatabaseGetCat())) {
          reDraw=true;
          DatabaseSetCat(category);
          ctl = GetObjectPtr(LIST_ex_cat_trigger);
          CategoryGetName(DatabaseGetRef(), category, gCategoryName); 
          CategorySetTriggerLabel(ctl, gCategoryName);
        }
        CatPostEdit(numRecords, recordList);
        if (reDraw) {
          gExamsOffset=0;
          gExamsSelRow=0;
          FrmUpdateForm(FORM_exams, frmRedrawUpdateCode);
        }
        if (recordList != NULL)  MemPtrFree((MemPtr)recordList);
        break;

      default:
        break;
    }
  } else if (event->eType == tblEnterEvent) {
    UInt16 i;
    
    if (event->data.tblEnter.column == EXCOL_DONE) {
      handled=false;
    } else if (event->data.tblEnter.column == EXCOL_NOTE) {
      MemHandle m;
      Boolean hasNote=false;

      gExamsSelRow=event->data.tblEnter.row;
      for (i=0; i < TblGetNumberOfRows(event->data.tblEnter.pTable); ++i) {
        RectangleType r;
        TblGetItemBounds(event->data.tblEnter.pTable, i, EXCOL_SELI, &r);
        TableDrawSelection(event->data.tblEnter.pTable, i, event->data.tblEnter.column, &r);
      }


      m = DmQueryRecord(DatabaseGetRefN(DB_MAIN), TblGetRowID(event->data.tblEnter.pTable, event->data.tblEnter.row));
      if (m) {
        ExamDBRecord *ex = (ExamDBRecord *)MemHandleLock(m);
        if (ex->note) hasNote = true;
        else          hasNote = false;
        MemHandleUnlock(m);
      }

      if (hasNote) {
        Coord newPointX, newPointY;
        Boolean isPenDown=false, drawn=false;
        RectangleType fieldBounds;
        IndexedColorType curForeColor, curBackColor, curTextColor;
        Char noteSymb[2] = { GADGET_NOTESYMBOL, 0 };
        FontID oldFont;
  
  
        EvtGetPen(&newPointX, &newPointY, &isPenDown);
        TblGetItemBounds(event->data.tblEnter.pTable, event->data.tblEnter.row, EXCOL_NOTE, &fieldBounds);
  
        oldFont = FntSetFont(symbolFont);
        while (isPenDown){
          if (! drawn && RctPtInRectangle(newPointX, newPointY, &fieldBounds)) {
            curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground));
            curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectSelectedFill));
            curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectSelectedForeground));
            TNDrawCharsToFitWidth(noteSymb, &fieldBounds);
            WinSetForeColor(curForeColor);
            WinSetForeColor(curBackColor);
            WinSetForeColor(curTextColor);
            drawn = true;
          } else if (drawn && ! RctPtInRectangle(newPointX, newPointY, &fieldBounds)) {
            curForeColor = WinSetForeColor(UIColorGetTableEntryIndex(UIObjectForeground));
            curBackColor = WinSetBackColor(UIColorGetTableEntryIndex(UIObjectFill));
            curTextColor = WinSetTextColor(UIColorGetTableEntryIndex(UIObjectForeground));
            TNDrawCharsToFitWidth(noteSymb, &fieldBounds);
            WinSetForeColor(curForeColor);
            WinSetForeColor(curBackColor);
            WinSetForeColor(curTextColor);
            drawn = false;
          }
          EvtGetPen(&newPointX, &newPointY, &isPenDown);
        }
        FntSetFont(oldFont);
      } else {
        handled = true;
      }
    } else {
      gExamsSelRow=event->data.tblEnter.row;
      for (i=0; i < TblGetNumberOfRows(event->data.tblEnter.pTable); ++i) {
        RectangleType r;
        TblGetItemBounds(event->data.tblEnter.pTable, i, EXCOL_SELI, &r);
        TableDrawSelection(event->data.tblEnter.pTable, i, event->data.tblEnter.column, &r);
      }
      handled=true;
    }
  } else if (event->eType == tblSelectEvent) {
    if (event->data.tblEnter.column == EXCOL_DONE) {
      MemHandle mex;
      ExamDBRecord *ex;
      Boolean done=(TblGetItemInt(event->data.tblSelect.pTable, event->data.tblSelect.row, event->data.tblSelect.column) == 0) ? false : true;
      UInt16 flags, index=TblGetRowID(event->data.tblSelect.pTable, event->data.tblSelect.row);

      mex=DmGetRecord(DatabaseGetRefN(DB_MAIN), index);
      ex = MemHandleLock(mex);
      flags = ex->flags;

      if (done) {
        flags |= EX_FLAG_DONE;
      } else {
        flags &= (EX_FLAG_DONE ^ 0xFFFF);
      }

      DmWrite(ex, offsetof(ExamDBRecord, flags), &flags, sizeof(flags));
      DmReleaseRecord(DatabaseGetRefN(DB_MAIN), index, false);

      TblMarkRowInvalid(event->data.tblSelect.pTable, event->data.tblSelect.row);
      TblRedrawTable(event->data.tblSelect.pTable);

      MemHandleUnlock(mex);

    } else if (event->data.tblEnter.column == EXCOL_NOTE) {
      ControlType *ctl=GetObjectPtr(BUTTON_ex_note);
      // Don't need code twice, just read ctlSelect Event for BUTTON_ex_note
      CtlHitControl(ctl);
    }
    handled=true;
  } else if (event->eType == ctlRepeatEvent) {
    // Repeat buttons pressed
    if( event->data.ctlRepeat.controlID == REPEAT_ex_up )
      gExamsOffset -= 1;
    else
      gExamsOffset += 1;

    ExamsTableInit();
    TblMarkTableInvalid(GetObjectPtr(TABLE_exams));
    TblRedrawTable(GetObjectPtr(TABLE_exams));
  } else if (event->eType == keyDownEvent) {
    // We have a hard button assigned and it was pressed
    if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
      if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) {
        FrmGotoForm(FORM_main);
        handled = true;
      }
    }
  } else if (event->eType == menuOpenEvent) {
    return HandleMenuOpenEvent(event);
  } else if (event->eType == menuEvent) {
    // forwarding of menu events
    return HandleMenuEvent(event->data.menu.itemID);
  } else if (event->eType == frmOpenEvent) {
    // initializes and draws the form
    ControlType *ctl;

    gExamsOffset=0;
    ExamsTableInit();
    FrmDrawForm (frm);

    ctl = GetObjectPtr(LIST_ex_cat_trigger);
    CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
    CategorySetTriggerLabel (ctl, gCategoryName); 

    handled = true;
  } else if (event->eType == frmUpdateEvent) {
    // redraws the form if needed
    gExamsOffset=0;
    ExamsTableInit();
    FrmDrawForm(frm);
    handled = false;
  } else if (event->eType == frmCloseEvent) {
    // this is done if form is closed
    // TblEraseTable(GetObjectPtr(TABLE_exams));
    // ExamsFormFree();
    FrmEraseForm(frm);
  }

  return (handled);

}
Example #7
0
/*
** FinishXferMode
*/
void FinishXferMode(void) {
  KleenexType kleenex;
  DtbkRepeatInfoType repeat;
  FormType* frm = FrmGetActiveForm();
  SysDBListItemType* pluglistP = NULL;
  Int16 current_plug = -1;
  UInt32 result;
  Boolean is_goto = false;
  Err err = errNone;
  Char cat_name[dmCategoryLength];
  Char* note = NULL;
  UInt16 attr;

  /* Zero the kleenex */
  MemSet(&kleenex, sizeof(KleenexType), 0);

  /* Bail if no plugins installed */
  if (!d.xfer.pluglistH) {
    FrmAlert(NoPluginInstalled);
    return;
  }

  /* Lock the plugin list */
  pluglistP = MemHandleLock(d.xfer.pluglistH);
  current_plug = GetCurrentXferAppListIndex();
  if (current_plug == -1) {
    FrmAlert(NoPluginSelected);
    MemHandleUnlock(d.xfer.pluglistH);
    return;
  }

  /* Set the version */
  if (pluglistP[current_plug].version & IBVERSION_PICTURE)
    kleenex.version = IBVERSION_PICTURE;
  else if (pluglistP[current_plug].version & IBVERSION_ORIG)
    kleenex.version = IBVERSION_ORIG;
  else
    abort();
  /* Add flag notifier */
  kleenex.version |= IBVERSION_FLAGS;

  /* Set flags */
  if (d.hires) 
    kleenex.flags = IBFLAG_HIRES;
  
  /* Set the current record index */
  kleenex.sketchRecordNum = p.dbI;

  /* Set the pick text */
  kleenex.text = GetLink(FldGetTextPtr(GetObjectPointer(frm, XferField)));
  if (!kleenex.text) {
    FlashWaitMessage(XferNoTextString);
    MemHandleUnlock(d.xfer.pluglistH);
    return;
  }
  
  /* Set the title text */
  kleenex.title = MemHandleLock(d.record_name);

  /* Set the category text */
  DmRecordInfo(d.dbR, p.dbI, &attr, NULL, NULL);
  CategoryGetName(d.dbR, attr & dmRecAttrCategoryMask, cat_name);
  kleenex.category = cat_name;

  /* Set the note */
  note = MemHandleLock(d.record_note);
  if (StrLen(note))
    kleenex.note = note;

  /* Set the seconds for the alarm */
  if (recordIsAlarmSet) 
    kleenex.alarm_secs = d.record.alarmSecs;

  /* Set the repeat information */
  kleenex.repeat = &repeat;
  switch (d.record.repeatInfo.repeatType) {
  case repeatDaily:
  case repeatWeekly:
  case repeatMonthlyByDay:
  case repeatMonthlyByDate:
  case repeatYearly:
    repeat.repeatType = d.record.repeatInfo.repeatType - 1; /* fix offset caused by repeatHourly */
    repeat.repeatFrequency = d.record.repeatInfo.repeatFrequency;
    repeat.repeatEndDate = d.record.repeatInfo.repeatEndDate;
    repeat.repeatOn = d.record.repeatInfo.repeatOn;
    repeat.repeatStartOfWeek = d.record.repeatInfo.repeatStartOfWeek;
    break;
  case repeatNone:
  case repeatHourly:
  default:
    kleenex.repeat = NULL;
  }

  /* Set the priority */
  kleenex.priority = d.record.priority + 1; /* DiddleBug priority is zero-based */

  /* Set the completion flag */
  if ((d.xfer.complete || (xferCompleteIsAlways)) && !(xferCompleteIsNever)) 
    kleenex.is_complete = 1;
  else
    kleenex.is_complete = 0;

  /* Load the sketch data */
  if (kleenex.version & IBVERSION_PICTURE) {
    if (!d.sonyClie || !d.hires) {
      kleenex.data = BmpGetBits(WinGetBitmap(d.winbufM));
      kleenex.data_size = BmpBitsSize(WinGetBitmap(d.winbufM));
    } else {
      kleenex.data = BmpGetBits(WinGetBitmap(d.winbufM));
      kleenex.data_size = HRBmpBitsSize(d.sonyHRRefNum, WinGetBitmap(d.winbufM));
    }
  }

  /* Call the plugin */
  err = SysAppLaunch(pluglistP[current_plug].cardNo,
		     pluglistP[current_plug].dbID, 0,
		     boogerPlugLaunchCmdBlowNose, (MemPtr)&kleenex, &result);

  /* Clean up some stuff */
  MemHandleUnlock(d.xfer.pluglistH);
  MemPtrFree(kleenex.text);
  if (err || result) {
    FrmAlert(PluginError);
    return;
  }

  /* Just to save some typing */
  is_goto = (((p.flags&PFLAGS_XFER_GOTO) || (xferGotoIsAlways)) &&
	     !(xferGotoIsNever));

  if (!is_goto)
    FlashWaitMessage(XferSavingString);
  
  /* Clean up some more */
  MemHandleUnlock(d.record_name);
  MemHandleUnlock(d.record_note);

  /* Delete the sketch if selected */
  if (p.flags&PFLAGS_XFER_DELETE)
    DoCmdRemove();

  /* Goto the new sketch if required */
  if (is_goto) {
    /* Clean up */
    MemHandleFree(d.xfer.pluglistH);
    d.xfer.pluglistH = NULL;
    
    /* Switch to other application */
    err = SysUIAppSwitch(kleenex.booger.cardNo, kleenex.booger.dbID,
			 kleenex.booger.cmd, kleenex.booger.cmdPBP);
    
    /* Clean up on error */
    if (err && kleenex.booger.cmdPBP) 
      MemPtrFree(kleenex.booger.cmdPBP);
  } else {
    if (kleenex.booger.cmdPBP) 
      MemPtrFree(kleenex.booger.cmdPBP);
  }

  CancelXferMode();
}
Example #8
0
/* Create new item in app database */
static UInt16
DoTheBoogie(KleenexPtr kleenexP, DmOpenRef dbR, UInt16 *index)
{
    AddrDBRecordType addr;
    UInt16 ii, category;
    Char catName[dmCategoryLength];
    Char *fn, *cn;

    MemSet(&addr, sizeof(AddrDBRecordType), 0);

    // Set up the new record
    addr.options.phones.phone1 = workLabel;
    addr.options.phones.phone2 = homeLabel;
    addr.options.phones.phone3 = faxLabel;
    addr.options.phones.phone4 = otherLabel;
    addr.options.phones.phone5 = emailLabel;

    // Add user data
    if (((*kleenexP->text >= '0') && (*kleenexP->text <= '9')) ||
	(*kleenexP->text == '+'))
    {
	// User provided a phone number
        addr.fields[phone1] = kleenexP->text;

    } else if ((fn = StrChr(kleenexP->text, (WChar)';')) &&
	       (cn = StrChr(&fn[1], (WChar)';')))
    {
	// Format is 'last name; first name; company name'
	*fn = '\0'; do { fn++; } while (*fn == ' ');
	*cn = '\0'; do { cn++; } while (*cn == ' ');
	if (*kleenexP->text)
	    addr.fields[name] = kleenexP->text;
	if (*fn)
	    addr.fields[firstName] = fn;
	if (*cn)
	    addr.fields[company] = cn;

    } else if (StrChr(kleenexP->text, (WChar)' ')) {
	// If it has a space, put it in the company name field
        addr.fields[company] = kleenexP->text;

    } else {
	// Assume a single word is just a last name
        addr.fields[name] = kleenexP->text;
    }

    // Set up category
    category = dmUnfiledCategory;
    if (kleenexP->category) {
        StrCopy(catName, "");
        for (ii=0; ii<dmRecNumCategories; ii++) {
            CategoryGetName(dbR, ii, catName);
            if (!StrCaselessCompare(catName, kleenexP->category)) {
                category = ii;
                break;
            }
        }
    }

    // Add it to the DB
    return (AddrDBNewRecord(dbR, &addr, category, index));
}
Example #9
0
/*-----------------------------------------CIRexxApp::initializeIndexDatabase-+
|                                                                             |
+----------------------------------------------------------------------------*/
void CIRexxApp::initializeIndexDatabase()
{
   m_isScriptIndexDBInitialized = true;

   Err err;
   char categoryName[dmCategoryLength];

   // Open MemoPad's DB as a source for scripts.
   m_memoDB = new CDatabase(
      0, "MemoDB", sysFileCMemo, 'data', false, false, dmModeReadOnly
   );
   for (m_memoCategory = 0; m_memoCategory < dmRecNumCategories; ++m_memoCategory) {
       CategoryGetName(m_memoDB->GetDatabasePtr(), m_memoCategory, categoryName);
       if (!StrCaselessCompare(categoryName, "REXX")) { break; }
   }
   if (m_memoCategory == dmRecNumCategories ||
       m_memoDB->NumRecordsInCategory(m_memoCategory) == 0) {
       delete m_memoDB;
       m_memoDB = 0;
   }

   //<<<JAL TODO:  I think CategoryGetName() will core dump
   // if the db has no categories.  So, we should probably
   // check the db attrs before doing this.


   // Open pedit's DB as a source for scripts.
   // Since this DB may not exist (unlike MmeoPad's)
   // then Open() or CategoryGetName() may throw an exception
   // that we'll have to handle properly.
   try {
      m_pedit32DB = new CDatabase();
      err = m_pedit32DB->Open(0, "Memo32DB", dmModeReadOnly);
      for (m_pedit32Category = 0; m_pedit32Category < dmRecNumCategories; ++m_pedit32Category) {
          CategoryGetName(m_pedit32DB->GetDatabasePtr(), m_pedit32Category, categoryName);
          if (!StrCaselessCompare(categoryName, "REXX")) { break; }
      }
      if (m_pedit32Category == dmRecNumCategories ||
          m_pedit32DB->NumRecordsInCategory(m_pedit32Category) == 0) {
         delete m_pedit32DB;
         m_pedit32DB = 0;
      }
   } catch (...) {
       delete m_pedit32DB;
       m_pedit32DB = 0;
   }

   // Open our own DB as a source for scripts.
   try {
      m_rexxDB = new CDatabase();
      err = m_rexxDB->Open(0, "RexxDB", dmModeReadOnly);
      for (m_rexxCategory = 0; m_rexxCategory < dmRecNumCategories; ++m_rexxCategory) {
          CategoryGetName(m_rexxDB->GetDatabasePtr(), m_rexxCategory, categoryName);
          if (!StrCaselessCompare(categoryName, "REXX")) { break; }
      }
      if (m_rexxCategory == dmRecNumCategories ||
          m_rexxDB->NumRecordsInCategory(m_rexxCategory) == 0) {
         delete m_rexxDB;
         m_rexxDB = 0;
      }
   } catch (...) {
       delete m_rexxDB;
       m_rexxDB = 0;
   }

   if (m_memoDB == 0 && m_pedit32DB == 0 && m_rexxDB == 0) { return; }

   // Create an index and then index each database so that we can
   // serialize the index into a actual POL database for grid mapping.
   CArray<ScriptRecord *> records;

   addRecordsToIndex(records, m_pedit32DB, m_pedit32Category, "P");
   addRecordsToIndex(records, m_memoDB, m_memoCategory, "M");
   addRecordsToIndex(records, m_rexxDB, m_rexxCategory, "R");

   m_scriptIndexDB = new CDatabase(0, "RexxScriptIndexDB", CREATORID, 'temp');
   m_scriptIndexDB->RemoveAllRecords();
   for (int i = 0; i < records.GetCount(); ++i) {
      ScriptRecord * sr = records[i];
      CRecordStream rs(m_scriptIndexDB);
      rs << sr->m_title;  //<<<JAL TODO:  YUCK!  MOVE ACCESS TO ScriptRecord CLASS!
      rs << sr->m_dbi;
      rs << (UInt32)sr->m_db;
      rs << sr->m_indexes.GetCount();
      for (int j = 0; j < sr->m_indexes.GetCount(); ++j) {
         rs << sr->m_indexes[j] << sr->m_segments[j];
      }
   }
   for (int i = 0; i < records.GetCount(); ++i) {
      delete records[i];
   }
   return;
}
Example #10
0
/*------------------------------------------------------CIRexxApp::FindLaunch-+
|                                                                             |
+----------------------------------------------------------------------------*/
Err CIRexxApp::FindLaunch(FindParamsPtr pFindParams)
{
   //<<<JAL TODO: This is currently dependent on the Rexx category.
   //             I'm not sure if we'll ever need to change/add-to this,
   //             but if we do, then this code will have to be changed
   //             along with the GoTo command.
   Err err;
   LocalID dbID;
   UInt16 cardNo = 0;
   DmOpenRef dbP;
   DmSearchStateType searchState;
   UInt16 recordNum;
   MemHandle hRecord;
   UInt32 pos;
   UInt16 matchLength;
   Boolean match, full;
   RectangleType r;
   UInt32 type;
   UInt32 creator;

   // Open our database (should we search MemoPad and pedit, too?)
   // and do our Find.  We define the semantics of Find, so
   // instead of searching the whole records for the search string,
   // let's just search for scripts with the search string as their "name."
   if (FindDrawHeader(pFindParams, "Rexx Scripts")) {
      goto m_return;
   }
   if ((err = DmGetNextDatabaseByTypeCreator(
       true, &searchState, 'data', CREATORID, true, &cardNo, &dbID)) != errNone) {
      pFindParams->more = false;
      return errNone;
   }
   if ((err = DmDatabaseInfo(0, dbID, 0, 0, 0, 0, 0, 0, 0, 0, 0, &type, &creator)) != errNone ||
      (type != 'data' && creator != CREATORID)) {
      pFindParams->more = false;
      return errNone;
   }
   if ((dbP = DmOpenDatabase(cardNo, dbID, pFindParams->dbAccesMode)) == 0 || 
      DmGetAppInfoID(dbP) == 0) { /* if categories not initialized then CategoryGetName throws fatal error */ 
      pFindParams->more = false;
      return errNone;
   }
   UInt16 category;
   char categoryName[dmCategoryLength];
   for (category = 0; category < dmRecNumCategories; ++category) {
       CategoryGetName(dbP, category, categoryName);
       if (!StrCaselessCompare(categoryName, "REXX")) { break; }
   }
   if (category == dmRecNumCategories) { goto m_return; }
   // set it to dmAllCategories?

   UInt32 romVersion;
   FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);

   full = false;
   recordNum = pFindParams->recordNum;
   while (true) {

      // Because applications can take a long time to finish a Find when
      // the result may already be on the screen, or for other reasons,
      // users like to be able to stop the Find.  So, stop it if any event
      // is pending, i.e., if the user does something with the device.
      // Because actually checking if an event is pending slows the
      // search itself, just check it every so many records.
      if ((recordNum & 0x000f) == 0 && EvtSysEventAvail(true)) {
         pFindParams->more = true;
         break;
      }
      if (!(hRecord = DmQueryNextInCategory(dbP, &recordNum, category))) {
         pFindParams->more = false;
         break;
      }

      Char * p = (char *)MemHandleLock(hRecord);
      UInt32 isInternational;
      err = FtrGet(sysFtrCreator, sysFtrNumIntlMgr, &isInternational);
      if (err == errNone && isInternational) {
         match = TxtFindString(p, pFindParams->strToFind, &pos, &matchLength);
      } else {
         match = TxtGlueFindString(p, pFindParams->strToFind, &pos, &matchLength);
      }
      if (match) {
         // Add the match to the find paramter block.
         // If there is no room to display the match
         // then the following function will return true.
         full = FindSaveMatch(pFindParams, recordNum, (UInt16)pos, 0, 0, cardNo, dbID);
         if (!full) {
            // Get the bounds of the region where we will draw the results, and
            // display the title of the description neatly in that area.
            FindGetLineBounds(pFindParams, &r);
            Int16 x = r.topLeft.x + 1;
            Int16 y = r.topLeft.y;
            Int16 w = r.extent.x - 2;
            Char * cr = StrChr(p, linefeedChr);
            UInt16 titleLen = (cr == 0)? StrLen(p) : cr - p;
            Int16 fntWidthToOffset;
            if (romVersion >= sysMakeROMVersion(3, 1, 0, sysROMStageRelease, 0)) {
               fntWidthToOffset = FntWidthToOffset(p, titleLen, w, 0, 0);
            } else {
               fntWidthToOffset = FntGlueWidthToOffset(p, titleLen, w, 0, 0);
            }
            if (fntWidthToOffset == titleLen) {
               WinDrawChars(p, titleLen, x, y);
            } else {
               Int16 titleWidth;
               titleLen = FntWidthToOffset(p, titleLen, w - FntCharWidth(chrEllipsis), 0, &titleWidth);
               WinDrawChars(p, titleLen, x, y);
               WinDrawChar (chrEllipsis, x + titleWidth, y);
            }
            ++pFindParams->lineNumber;
         }
      }
      MemHandleUnlock(hRecord);
      if (full) { break; }
      ++recordNum;
   }

m_return:
   DmCloseDatabase(dbP);
   return errNone;
}
Example #11
0
/***********************************************************************
 * handling for form and control actions
 * menu actions are forwarded to MainFormDoCommand
 ***********************************************************************/
static Boolean
MainFormHandleEvent (EventPtr event)
{
  FormType *frm;
  Boolean handled = false;
  Boolean categoryEdited, reDraw=false;
  UInt16 category, numRecords;
  ControlType *ctl;
  UInt32 *recordList;

  
  if (event->eType == ctlSelectEvent) {
    // button handling
    handled = true;
    switch (event->data.ctlSelect.controlID) {
      // the ok button - this leaves the application

      case LIST_cat_trigger:
        frm = FrmGetActiveForm();
        category=DatabaseGetCat();
        numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY);
        recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32));
        CatPreEdit(numRecords, recordList);
        categoryEdited = CategorySelect(DatabaseGetRef(), frm,
                                        LIST_cat_trigger, LIST_cat, false,
                                        &category, gCategoryName, 0,
                                        STRING_cat_edit); // categoryDefaultEditCategoryString
        if (categoryEdited || (category != DatabaseGetCat())) {
          reDraw=true;
          DatabaseSetCat(category);
          ctl = GetObjectPtr(LIST_cat_trigger);
          CategoryGetName(DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
          CategorySetTriggerLabel(ctl, gCategoryName); 
        }
        CatPostEdit(numRecords, recordList);
        if (reDraw)  {
          GadgetSetNeedsCompleteRedraw(true);
          FrmDrawForm(frm);
        }
        if (recordList != NULL)    MemPtrFree((MemPtr)recordList);
        break;

      case BUTTON_beam:
        BeamCourse(GadgetGetHintCourseIndex());
        break;

      case BUTTON_edit:
        gMenuCurrentForm=FORM_main;
        EditTime();
        break;

      case BUTTON_next:
        GadgetDrawHintNext();
        break;

      default:
        break;
      }
    } else if (event->eType == keyDownEvent) {
      // We have a hard button assigned and it was pressed
      if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) {
        if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) {
          GadgetDrawHintNext();
          handled = true;
        }
      } else if (EvtKeydownIsVirtual(event)) {
        // Up or down keys pressed
        switch (event->data.keyDown.chr) {
          case vchrPageUp:
            if (event->data.keyDown.modifiers & autoRepeatKeyMask) {
              if (! gMainRepeat) {
                GadgetSwitchScreen();
                gMainRepeat = true;
              }
            } else {
              GadgetDrawStep(winUp);
              gMainRepeat = false;
            }
            handled=true;
            break;

          case vchrPageDown:
            if (event->data.keyDown.modifiers & autoRepeatKeyMask) {
              if (! gMainRepeat) {
                GadgetSwitchScreen();
                gMainRepeat = true;
              }
            } else {
              GadgetDrawStep(winDown);
              gMainRepeat = false;
            }
            handled=true;
            break;

          case vchrSendData:
            BeamCourse(GadgetGetHintCourseIndex());
            handled=true;
            break;

          default:
            break;
        }
      }
    } else if (event->eType == menuEvent) {
      // forwarding of menu events
      return HandleMenuEvent(event->data.menu.itemID);
    } else if (event->eType == menuOpenEvent) {
      return HandleMenuOpenEvent(event);
    } else if (event->eType == frmUpdateEvent) {
      // redraws the form if needed
      frm = FrmGetActiveForm();
      FrmDrawForm(frm);
      // GadgetDrawHintNext();
      handled = true;
    } else if (event->eType == frmOpenEvent) {
      ControlType *ctl;
      LocalID dbID;
      UInt16 cardNo;
      Boolean newKeyP4=false;
      UInt16 newKeyP2=0xFFFF;

      // initializes and draws the form at program launch
      frm = FrmGetActiveForm();

      GadgetSet(frm, GADGET_main, GADGET_hint);
      FrmSetGadgetHandler(frm, FrmGetObjectIndex(frm, GADGET_main), GadgetHandler);
      FrmSetGadgetHandler(frm, FrmGetObjectIndex(frm, GADGET_hint), GadgetHintHandler);

      FrmDrawForm(frm);
      GadgetDrawHintNext();

      ctl = GetObjectPtr(LIST_cat_trigger);
      CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); 
      CategorySetTriggerLabel (ctl, gCategoryName); 

      DmOpenDatabaseInfo(DatabaseGetRefN(DB_MAIN), &dbID, NULL, NULL, &cardNo, NULL);
      SysNotifyRegister(cardNo, dbID, sysNotifyLateWakeupEvent, HandleNotification, sysNotifyNormalPriority, NULL);

    	KeyRates(false,&gKeyP1, &gKeyP2, &gKeyP3, &gKeyP4);
	    KeyRates(true, &gKeyP1, &newKeyP2, &gKeyP3, &newKeyP4);

      handled = true;
    } else if (event->eType == frmCloseEvent) {
      // this is done if program is closed
      LocalID dbID;
      UInt16 cardNo;
      DmOpenDatabaseInfo(DatabaseGetRefN(DB_MAIN), &dbID, NULL, NULL, &cardNo, NULL);
      SysNotifyUnregister(cardNo, dbID, sysNotifyLateWakeupEvent, sysNotifyNormalPriority);
      // Restore original key rates
	    KeyRates(true, &gKeyP1, &gKeyP2, &gKeyP3, &gKeyP4);
    }

  return (handled);
}