Пример #1
0
/*
 * function : HandleKeyEvent
 *
 */
static Boolean HandleKeyEvent(EventPtr event) {
	
	Boolean handled = false;

	switch (PFEventGetKeyChr(event)) {
	case vchrPageUp:

		if (topOfList > 0) {

			topOfList = MAX(0, topOfList-4);
			
		} else {

			SndPlaySystemSound(sndError);

		}

		UpdateDisplay();
		handled = true;
		break;

	case vchrPageDown:

		if (topOfList < proxList.numWaypoints-4) {

			topOfList = MIN(topOfList+4, MAX(0,proxList.numWaypoints - 4));

		} else {

			SndPlaySystemSound(sndError);

		}
		UpdateDisplay();
		handled = true;
		break;

	default:
		break;

	}
	return handled;
}
Пример #2
0
/*
** Track pen and do the appropriate thing.
*/
Boolean XferPenDown(EventPtr e) {
  Boolean handled = false;

  if (RctPtInRectangle(e->screenX, e->screenY, screen)	/* This cancels the xfer mode */
      && !FrmPointInTitle(FrmGetActiveForm(), e->screenX, e->screenY)) {/* unless we should just popdown the menu */
    SndPlaySystemSound(sndWarning);
    CancelXferMode();
    handled = true;
  }

  return handled;
}
Пример #3
0
UInt32
start ()
{
  SysAppInfoType *appInfo;
  void *prevGlobals;
  void *globalsPtr;

  if (SysAppStartup (&appInfo, &prevGlobals, &globalsPtr) != 0)
    {
      SndPlaySystemSound (sndError);
      return -1;
    }
  else
    {
      Int16 mainCmd = appInfo->cmd;
      void *mainPBP = appInfo->cmdPBP;
      UInt16 mainFlags = appInfo->launchFlags;
      UInt32 result;

#ifdef __OWNGP__
      UInt32 save_a4 = reg_a4;

      if (mainFlags & sysAppLaunchFlagNewGlobals)
	asm ("move.l %%a5,%%a4; sub.l #edata,%%a4" : : : "%a4");
      else
	reg_a4 = 0;
#endif

      if (mainFlags & sysAppLaunchFlagNewGlobals)
	_GccRelocateData ();

      __do_bhook (mainCmd, mainPBP, mainFlags);

      if (mainFlags & sysAppLaunchFlagNewGlobals)
	__do_ctors ();

      result = PilotMain (mainCmd, mainPBP, mainFlags);

      if (mainFlags & sysAppLaunchFlagNewGlobals)
	__do_dtors ();

      __do_ehook (mainCmd, mainPBP, mainFlags);

#ifdef __OWNGP__
      reg_a4 = save_a4;
#endif

      SysAppExit (appInfo, prevGlobals, globalsPtr);

      return result;
    }
Пример #4
0
/***********************************************************************
 *
 * FUNCTION:    RepeatSelectEndDate
 *
 * DESCRIPTION: This routine selects the end date of a repeating event.
 *
 * PARAMETERS:  event - pointer to a popup select event
 *
 * RETURNED:    nothing
 *
 ***********************************************************************/
static void RepeatSelectEndDate(EventType* event) {
  Int16 month, day, year;
  Char* titleP = NULL;
  MemHandle titleH = NULL;

  /* "No due date" items selected? */
  if (event->data.popSelect.selection == repeatNoEndDateItem)
    DateToInt(d.repeat_end_date) = apptNoEndDate;

  /* "Select date" item selected? */
  else if (event->data.popSelect.selection == repeatChooseDateItem) {
    if (DateToInt (d.repeat_end_date) == apptNoEndDate) {
      year = d.frm_date.year;
      month = d.frm_date.month;
      day = d.frm_date.day;
    } else {
      year = d.repeat_end_date.year + firstYear;
      month = d.repeat_end_date.month;
      day = d.repeat_end_date.day;
    }
    
    titleH = DmGetResource(strRsc, endDateTitleString);
    titleP = MemHandleLock(titleH);
    
    if (SelectDay (selectDayByDay, &month, &day, &year, titleP)) {
      d.repeat_end_date.day = day;
      d.repeat_end_date.month = month;
      d.repeat_end_date.year = year - firstYear;
      
      /* Make sure the end date is not before the start date. */
      if (DateToInt(d.repeat_end_date) < DateToInt (d.frm_date)) {
	SndPlaySystemSound (sndError);
	DateToInt (d.repeat_end_date) = apptNoEndDate;
      }
    }
    
    MemHandleUnlock(titleH);
  }

  RepeatSetDateTrigger(d.repeat_end_date);
}
Пример #5
0
/***********************************************************************
 *
 * FUNCTION:    SelectTime
 *
 * DESCRIPTION: Display a form showing a start and end time.
 *					 Allow the user to change the time and then
 *              return them.
 *					 pTimeDiff.
 *
 * PARAMETERS:  pStartTime	- pointer to TimeType
 *              pEndTime   - pointer to TimeType
 *              untimed  	- true if there isn't a time.
 *              title	   - string containing the title
 *              startOfDay - used when "All Day" button selected.
 *					 endOfDay	- our used when "All Day" button selected.
 *              startOfDisplay - first hour initially visible
 *
 * RETURNED:	 True if the time was changed by the user.
 * 				 The first three parameters may change.
 *
 * REVISION HISTORY:
 *			Name	Date		Description
 *			----	----		-----------
 *			roger	12/2/94	Initial Revision
 *			trev	08/12/97	made non modified passed variables constant
 *			css	06/08/99	added new parameter & "All Day" button for gromit change.
 *
 ***********************************************************************/
Boolean SelectTime (TimeType * startTimeP, TimeType * endTimeP, 
	Boolean untimed, const Char * titleP, Int16 startOfDay, Int16 endOfDay, 
	Int16 startOfDisplay)
{
	Int16							firstHour;
	Char 							startTimeText [timeStringLength];
	Char 							endTimeText [timeStringLength];
	Char							timeChars [timeStringLength];
	TimePtr						timeP;
	FormType 					*originalForm, *frm;
	ListPtr 						hoursLst, minutesLst;
	ControlPtr 					startTimeCtl, endTimeCtl;
	EventType 					event;
	Boolean 						confirmed = false;
	MemHandle 						hoursItems;
	TimeType 					startTime, endTime, timeDiff;
	TimeFormatType 			timeFormat;
	ChangingTimeType			changingTime;

	// Get the time format from the system preerances;
	timeFormat = (TimeFormatType)PrefGetPreference(prefTimeFormat);


	// Because this routine only deals with minutes in five minute
	// intervals we convert the proposed times from those passed.
	startTime.hours = startTimeP->hours;
	startTime.minutes = startTimeP->minutes;
	endTime.hours = endTimeP->hours;
	endTime.minutes = endTimeP->minutes;
	TimeDifference (&endTime, &startTime, &timeDiff);
	
	// Make sure the end time is displayable (clips at 11:55 pm)
	AdjustTimes (&startTime, &endTime, &timeDiff, changingStartTime);
	
	// Clear the buffer that holds written characters.
	*timeChars = 0;

	startOfDisplay = min (startOfDisplay, 12);

	originalForm = FrmGetActiveForm();
	frm = (FormType *) FrmInitForm (TimeSelectorForm);
	FrmSetActiveForm (frm);

	hoursLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorHourList));
	minutesLst = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorMinuteList));
	startTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorStartTimeButton));
	endTimeCtl = FrmGetObjectPtr (frm, FrmGetObjectIndex (frm, TimeSelectorEndTimeButton));


	// Set list to use either 12 or 24 hour time
	hoursItems = SysFormPointerArrayToStrings (
		((timeFormat == tfColon24h) || (timeFormat == tfDot24h)) ? 
			(Char *) Hours24Array() : (Char *) Hours12Array(), 24);
 
 	LstSetListChoices (hoursLst, MemHandleLock(hoursItems), 24);
	LstSetTopItem (hoursLst, startOfDisplay);
	//	Used to do LstMakeItemVisible (hoursLst, startTime.hours); no longer.


	if (! untimed)
		{
		LstSetSelection (hoursLst, startTime.hours);
		LstSetSelection (minutesLst, startTime.minutes / 5);

		CtlSetValue (startTimeCtl, true);
		changingTime = changingStartTime;
		}
	else
		{
		// The hour list is dynamically created and doesn't have a selection
		LstSetSelection (minutesLst, noListSelection);

		changingTime = changingNoTime;
		}


	// Set the start and end time buttons to the current times or blank them
	// if No Time is selected.
	SetTimeTriggers (startTime, endTime, startTimeText, endTimeText, 
		timeFormat, untimed);
		

	// This needs to be taken out when SelectTimeV33 goes away.  It allows for backward 
	// compatibility for this change of adding the end of day variable as a parameter.
	if (endOfDay != noDisplayOfAllDay)
	{
	  FrmShowObject (frm, FrmGetObjectIndex (frm, TimeSelectorAllDayButton));
	}
	
	FrmSetTitle (frm, (Char *) titleP);
	FrmDrawForm (frm);
	
	
	while (true)
		{
		EvtGetEvent (&event, evtWaitForever);

		if (SysHandleEvent ((EventType *)&event))
			continue;
			
		if (event.eType == appStopEvent)
			{
			// Cancel the dialog and repost this event for the app
			EvtAddEventToQueue(&event);
			confirmed = false;
			break;
			}
			
		// Handle these before the form does to overide the default behavior
		if (changingTime == changingNoTime &&
			event.eType == lstEnterEvent && 
			event.data.lstEnter.listID == TimeSelectorMinuteList)
			{
			SndPlaySystemSound(sndError);
			continue;
			}

		FrmHandleEvent (frm, &event);


		// If the start or end time buttons are pressed then change
		// the time displayed in the lists.
		if (event.eType == ctlSelectEvent)
			{
			// "Ok" button pressed?
			if (event.data.ctlSelect.controlID == TimeSelectorOKButton)
				{
				confirmed = true;
				}

			// "Cancel" button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorCancelButton)
				{
				break;
				}

			// Start time button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorStartTimeButton)
				{
				if (changingTime != changingStartTime)
					{
					if (changingTime == changingNoTime)
						{
						SetTimeTriggers (startTime, endTime, startTimeText, 
							endTimeText, timeFormat, false);
						}

					CtlSetValue (endTimeCtl, false);
					LstSetSelection (hoursLst, startTime.hours);
					LstSetSelection (minutesLst, startTime.minutes / 5);
					changingTime = changingStartTime;
					}
				else
					CtlSetValue(startTimeCtl, true);
				}

			// End time button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorEndTimeButton)
				{
				if (changingTime != changingEndTime)
					{
					if (changingTime == changingNoTime)
						{
						SetTimeTriggers (startTime, endTime, startTimeText, 
							endTimeText, timeFormat, false);
						}

					CtlSetValue(startTimeCtl, false);
					LstSetSelection (hoursLst, endTime.hours);
					LstSetSelection (minutesLst, endTime.minutes / 5);
					changingTime = changingEndTime;
					}
				else
					CtlSetValue(endTimeCtl, true);
				}

			// No time button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorNoTimeButton)
				{
				if (changingTime != changingNoTime)
					{
					if (changingTime == changingStartTime)
						CtlSetValue(startTimeCtl, false);
					else
						CtlSetValue(endTimeCtl, false);
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, true);
					
					LstSetSelection (hoursLst, noListSelection);
					LstSetSelection (minutesLst, noListSelection);
					changingTime = changingNoTime;
					}
					// Get us out of this form display now.
					confirmed = true;
				}

			// All day button pressed?
			else if (event.data.ctlSelect.controlID == TimeSelectorAllDayButton)
				{
				if (changingTime != changingNoTime)
					{
					if (changingTime == changingStartTime)
						CtlSetValue(startTimeCtl, false);
					else
						CtlSetValue(endTimeCtl, false);
					
					LstSetSelection (hoursLst, noListSelection);
					LstSetSelection (minutesLst, noListSelection);
					changingTime = changingNoTime;
					}
											
					// No matter what, the minutes are 0 for both because only the hour is registered for start/end
					// times.
					startTime.minutes = 0;
					endTime.minutes 	= 0;
					startTime.hours 	= startOfDay;
					endTime.hours 		= endOfDay;
					
					// Set the times to the new times.
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, true);
					// Get us out of this form display now.  First set the changing time to anything but the changingNoTime value
					// so that the pointers at the end of this function get set correctly.
					changingTime = changingStartTime;
					confirmed = true;
				}

			// Clear the buffer that holds written characters.
			*timeChars = 0;
			}


		// If either list is changed then get the new time.  If the
		// start time is changed then change the end time so that the
		// the time difference remains the same.  If the end time is
		// changed then make sure the end time isn't before the start
		// time.  Also calculate a new time difference.
		else if (event.eType == lstSelectEvent)
			{
         // First, get the info from the list which has changed.
			if (event.data.lstSelect.listID == TimeSelectorHourList)
				{
				if (changingTime == changingStartTime)
               startTime.hours = (UInt8) LstGetSelection (hoursLst);
           	else if (changingTime == changingEndTime)
               endTime.hours = (UInt8) LstGetSelection (hoursLst);
           	else if (changingTime == changingNoTime)
           		{
               startTime.hours = (UInt8) LstGetSelection (hoursLst);
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, false);
					CtlSetValue (endTimeCtl, false);
					LstSetSelection (minutesLst, startTime.minutes / 5);
					changingTime = changingStartTime;
					}
				}
         else if (event.data.lstSelect.listID == TimeSelectorMinuteList)
				{
				if (changingTime == changingStartTime)
               startTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5;
           	else if (changingTime == changingEndTime)
					endTime.minutes = (UInt8) LstGetSelection (minutesLst) * 5;
           	else if (changingTime == changingNoTime)
           		{
               ErrNonFatalDisplay("lstEnterEvent not being filtered.");
               }
				}


			if (AdjustTimes (&startTime, &endTime, &timeDiff, changingTime))
				{
				if (changingTime == changingStartTime)
					{
					TimeToAscii (startTime.hours, startTime.minutes, timeFormat, 
						startTimeText);
					CtlSetLabel (startTimeCtl, startTimeText);
					}
				else if (changingTime == changingEndTime)
					{
					LstSetSelection (hoursLst, startTime.hours);
					LstSetSelection (minutesLst, startTime.minutes / 5);
					}
				}
			TimeToAscii(endTime.hours, endTime.minutes, timeFormat, endTimeText);
			CtlSetLabel(endTimeCtl, endTimeText);


			// Clear the buffer that holds written characters.
			*timeChars = 0;
			}


		// Handle character written in the time picker.
		else if (event.eType == keyDownEvent)
			{
			if (changingTime == changingEndTime)
				{
				timeP = &endTime;
				firstHour = startTime.hours;
				}
			else
				{
				timeP = &startTime;
				firstHour = startOfDisplay;
				}
		
			// If a backspace character was written, change the time picker's
			// current setting to "no-time".
			if (event.data.keyDown.chr == backspaceChr)
				{
				*timeChars = 0;
				if (changingTime != changingNoTime)
					{
					if (changingTime == changingStartTime)
						CtlSetValue (startTimeCtl, false);
					else
						CtlSetValue (endTimeCtl, false);
					SetTimeTriggers (startTime, endTime, startTimeText, 
						endTimeText, timeFormat, true);
					LstSetSelection (hoursLst, noListSelection);
					LstSetSelection (minutesLst, noListSelection);
					changingTime = changingNoTime;
					}
				}

			// A linefeed character confirms the dialog box.
			else if (event.data.keyDown.chr == linefeedChr)
				{
				confirmed = true;
				}

			// If next-field character toggle between start time in end
			// time.
			else if (event.data.keyDown.chr == nextFieldChr)
				{
				*timeChars = 0;
				if (changingTime == changingStartTime)
					{
					CtlSetValue (startTimeCtl, false);
					CtlSetValue (endTimeCtl, true);
					changingTime = changingEndTime;
					}
				else
					{
					CtlSetValue (endTimeCtl, false);
					CtlSetValue (startTimeCtl, true);
					changingTime = changingStartTime;
					}
				}


			// If a valid time character was written, translate the written 
			// character into a time and update the time picker's UI.
			else if (TranslateTime (timeFormat, event.data.keyDown.chr, 
				firstHour, timeChars, timeP))
				{
				if (changingTime == changingNoTime)
					{
					changingTime = changingStartTime;
					CtlSetValue (startTimeCtl, true);
					}

				AdjustTimes (&startTime, &endTime, &timeDiff, changingTime);
				
				SetTimeTriggers (startTime, endTime, startTimeText, 
					endTimeText, timeFormat, false);

				LstSetSelection (hoursLst, timeP->hours);
				LstSetSelection (minutesLst, timeP->minutes / 5);
				}
			}

		// Has the dialog been confirmed.
		if (confirmed)
			{
			if (changingTime != changingNoTime)
				{
				*startTimeP = startTime;
				*endTimeP = endTime;
				}
			else
				{
				TimeToInt(*startTimeP) = noTime;
				TimeToInt(*endTimeP) = noTime;
				}
			break;
			}

		}

	FrmEraseForm (frm);
	FrmDeleteForm (frm);
	MemHandleFree (hoursItems);
	
	FrmSetActiveForm(originalForm);
	
	return (confirmed);
	}
Пример #6
0
// Emit a beeeeeep
void wxBell()
{
    SndPlaySystemSound(sndWarning);
}
Пример #7
0
/*
** TrackXferDone
*/
static void TrackXferDone(DynamicButtonType* btn) {
  RectangleType bounds[5], frame, popFrame, popShadowFrame;
  Boolean penDown, on_button;
  Int16 x, y, clicked_on = 0;
  Int16 state = 1;
  Int16 i = 0;
  WinHandle offscreenH = NULL;
  FormType* frm = FrmGetActiveForm();
  const UInt16 listIdx = FrmGetObjectIndex(frm, XferDoneList);
  ListType* list = FrmGetObjectPtr(frm, listIdx);
  UInt16 width = 0, choices = 0;
  Err err = errNone;
  Char str[48];
  Int16 n = 0;

  /* Save the old drawing context */
  WinPushDrawState();

  /* This should match the XferDoneButton bounds */
  FrmGetObjectBounds(frm, FrmGetObjectIndex(frm, btn->id), &bounds[0]);

  /* Invert the done button */
  SelectAndDrawButton(btn, true);
  SndPlaySystemSound(sndClick);

  /* Set the status of each menu pick */
  for (; i < 4; i++)
    d.xfer.status[i] = 0x00;
  
  if (xferGotoIsAlways)
    d.xfer.status[0] = TRACKXFERDONE_ALWAYS;
  else if (xferGotoIsNever)
    d.xfer.status[0] = TRACKXFERDONE_NEVER;
  else if (p.flags&PFLAGS_XFER_GOTO)
    d.xfer.status[0] = TRACKXFERDONE_CHECKED;

  if (xferCompleteIsAlways)
    d.xfer.status[1] = TRACKXFERDONE_ALWAYS;
  else if (xferCompleteIsNever)
    d.xfer.status[1] = TRACKXFERDONE_NEVER;
  else if (d.xfer.complete)
    d.xfer.status[1] = TRACKXFERDONE_CHECKED;

  if (!d.linker_available)
    d.xfer.status[2] = TRACKXFERDONE_NEVER;
  else if (p.flags&PFLAGS_XFER_BACKLINK)
    d.xfer.status[2] = TRACKXFERDONE_CHECKED;
  if (p.flags&PFLAGS_XFER_DELETE)
    d.xfer.status[3] = TRACKXFERDONE_CHECKED;

  for (i = 0; i < 4; ++i) {
    if (!(d.xfer.status[i] & TRACKXFERDONE_NEVER)) {
      d.xfer.choice_map[choices] = i;
      ++choices;

      /* calculate list width */
      SysCopyStringResource(str, XferMenuOptionsStrings + i);
      n = FntCharsWidth(str, StrLen(str));
      width = Max(width, n);
    }
  }

  LstSetDrawFunction(list, XferDoneListDrawFunc);
  LstSetListChoices(list, 0, choices);
  LstSetHeight(list, Min(choices, 10));
  FrmGetObjectBounds(frm, listIdx, &frame);
  frame.topLeft.y = 144 - frame.extent.y - 1; /* -1 to compensate for white border */
  frame.extent.x = width + 15 + 6;
  FrmSetObjectBounds(frm, listIdx, &frame);
  WinGetFramesRectangle(popupFrame, &frame, &popFrame);
  WinGetFramesRectangle(rectangleFrame, &popFrame, &popShadowFrame);

  for (i = 0; i < choices; ++i)
    RctSetRectangle(&bounds[i+1], frame.topLeft.x, frame.topLeft.y + 10 * i, 
		    frame.extent.x, 10);

  /* Save the bits of the whole menu */
  offscreenH = WinSaveBits(&popShadowFrame, &err);
  if (err) abort();

  /* None selected */
  LstSetSelection(list, -1);

  FrmShowObject(frm, listIdx);
  WinEraseRectangle(&popShadowFrame, 0);
  LstDrawList(list);
  WinEraseRectangleFrame(rectangleFrame, &frame);
  WinDrawRectangleFrame(popupFrame, &frame);

  do {
    EvtGetPen(&x, &y, &penDown);
    if (!state || !RctPtInRectangle(x, y, &bounds[state-1])) {
      on_button = false;
      for (i = 1; i <= choices + 1; i++) {
	if ((state != i) && RctPtInRectangle(x, y, &bounds[i-1])) {
	  /* Invert the new state */
	  LstSetSelection(list, i - 2);
	  LstDrawList(list);
	  WinEraseRectangleFrame(rectangleFrame, &frame);
	  WinDrawRectangleFrame(popupFrame, &frame);
	  
	  SelectAndDrawButton(btn, i == 1);
	  
	  state = i;
	  on_button = true;
	}
      }

      if (state && !on_button) {
	/* Moved off the current button */
	LstSetSelection(list, -1);
	LstDrawList(list);
	WinEraseRectangleFrame(rectangleFrame, &frame);
	WinDrawRectangleFrame(popupFrame, &frame);

	if (state == 1) 
	  SelectAndDrawButton(btn, false);
	state = 0;
      }
    }
  } while (penDown);

  FrmHideObject(frm, listIdx);
  LstEraseList(list);

  /* Restore the framed rect */
  WinRestoreBits(offscreenH, popShadowFrame.topLeft.x, popShadowFrame.topLeft.y);

  /* Unselect the button */
  SelectAndDrawButton(btn, false);

  /* Finish up if we just tapped the button */
  if (RctPtInRectangle(x, y, &bounds[0])) {
    FinishXferMode();
    
    /* Restore the old draw state */
    WinPopDrawState();
    return;
  }

  /* Change the setting for goto or delete */
  for (i = 1; i <= choices; i++) {
    if (RctPtInRectangle(x, y, &bounds[i])) {
      clicked_on = i;
      break;
    }
  }

  if (clicked_on) 
    clicked_on = d.xfer.choice_map[clicked_on-1] + 1;

  switch (clicked_on) {
  case 1: /* Goto */
    if (d.xfer.status[0] & TRACKXFERDONE_CHECKED)
      p.flags &= ~PFLAGS_XFER_GOTO;
    else if (!d.xfer.status[0])
      p.flags |= PFLAGS_XFER_GOTO;
    break;
  case 2: /* Complete */
    if (d.xfer.status[1] & TRACKXFERDONE_CHECKED)
      d.xfer.complete = false;
    else if (!d.xfer.status[1])
      d.xfer.complete = true;
    break;
  case 3: /* BackLink */
    if (d.xfer.status[2] & TRACKXFERDONE_CHECKED)
      p.flags &= ~PFLAGS_XFER_BACKLINK;
    else if (!d.xfer.status[2]) {
      p.flags |= PFLAGS_XFER_BACKLINK;
      p.flags &= ~PFLAGS_XFER_DELETE; /* No delete if backlink */
    }
    break;
  case 4: /* Delete */
    if (d.xfer.status[3] & TRACKXFERDONE_CHECKED)
      p.flags &= ~PFLAGS_XFER_DELETE;
    else if (!d.xfer.status[3]) {
      p.flags |= PFLAGS_XFER_DELETE;
      p.flags &= ~PFLAGS_XFER_BACKLINK; /* No backlink if delete */
    }
    break;
  }

  /* Click and redraw the button */
  if (clicked_on) {
    DrawXferDoneButton(btn);
    DynBtnDraw(btn);
    
    if (d.xfer.status[clicked_on-1] & TRACKXFERDONE_ALWAYS)
      SndPlaySystemSound(sndWarning);
    else
      SndPlaySystemSound(sndClick);
  }

  /* Restore the old draw state */
  WinPopDrawState();
}
Пример #8
0
/* Perform action assigned to given control object */
void DoControlAction
    (
    const Int16 control /* control value of the object */
    )
{
    UInt16  newRecord;
    Int16   controlID;

    /* Clear location of find pattern */
    ClearFindPatternData();

    if ( 0 < control ) {
        Int16   anchorIndex;
        UInt16  reference;
        Int16   paragraphOffset;
        Int16   byteOffsetInPara;
        UInt16  image;
        AnchorMode type;

        anchorIndex         = control - 1;
        reference           = GetVisibleReference( anchorIndex );
        paragraphOffset     = GetVisibleParagraphOffset( anchorIndex );
        byteOffsetInPara    = GetVisibleByteOffset( anchorIndex );
        image               = GetVisibleImage( anchorIndex );
        image               = GetVisibleImage( anchorIndex );
        type                = GetVisibleMode( anchorIndex );

        SndPlaySystemSound( sndClick );

        if ( image != 0 ) {
            RectangleType   bounds;
            ListType*       list;
            Int16           x;
            Int16           y;
            UInt16          prevCoordSys;
            Int16           selection;

            bounds  = GetVisibleImagePosition( anchorIndex );
            list    = GetObjectPtr( frmMainImageDialog );

            x = ( bounds.extent.x - 60 ) / 2;
            if ( x < 0 )
                x = 0;
            y = ( bounds.extent.y - 22 ) / 2;
            if ( y < 0 )
                y = 0;
            x += bounds.topLeft.x;
            y += bounds.topLeft.y;
            LstSetPosition( list, x, y );

            prevCoordSys    = PalmSetCoordinateSystem( STANDARD );
            selection       = LstPopupList( list );
            PalmSetCoordinateSystem( prevCoordSys );
            if ( selection == noListSelection ) {
                return;
            }
            else if ( selection == 1 ) {
                reference = image;
            }
        }
        if ( type == ANCHORMODE_LINK ) {
            Int16 byteOffset;
            
            if ( byteOffsetInPara == 0 ) {
                byteOffset = NO_OFFSET;
            }
            else {
                byteOffset      = ParagraphNumToByteOffset( paragraphOffset ) +
                                      byteOffsetInPara;
                paragraphOffset = NO_OFFSET;
            }
            JumpToRecord( reference, paragraphOffset, byteOffset );
        }
#ifdef SUPPORT_ANNOTATION
        else if ( type == ANCHORMODE_ANNOTATION ) {
            DoAnnotate( GetVisibleAnnotationIdentifier( anchorIndex ),
                0, 0, 0, 0, 0, NULL );
        }
#endif

        return;
    }

    if ( control != 0 )
        SndPlaySystemSound( sndClick );

    controlID = -( control + 1 );
    switch ( controlID ) {
        case HOMECONTROL:
            DoAutoscrollToggle( AUTOSCROLL_OFF );
            ViewRecord( HOME_PAGE_ID, ADD_TO_HISTORY, 0, 0,
                WRITEMODE_DRAW_CHAR );
            SetVisitedLink( HOME_PAGE_ID );
            break;

        case LEFTCONTROL:
            DoAutoscrollToggle( AUTOSCROLL_OFF );
            newRecord = GetHistoryPrev();
            if ( newRecord != NO_RECORD ) {
                ViewRecord( newRecord, FROM_HISTORY, NO_OFFSET, NO_OFFSET,
                    WRITEMODE_DRAW_CHAR );
                SetVisitedLink( newRecord );
            }
            else {
                FrmGotoForm( GetValidForm( frmLibrary ) );
            }
            break;

        case RIGHTCONTROL:
            DoAutoscrollToggle( AUTOSCROLL_OFF );
            newRecord = GetHistoryNext();
            if ( newRecord != NO_RECORD ) {
                ViewRecord( newRecord, FROM_HISTORY, NO_OFFSET, NO_OFFSET,
                    WRITEMODE_DRAW_CHAR );
                SetVisitedLink( newRecord );
            }
            break;

        case LIBRARYCONTROL:
            DoAutoscrollToggle( AUTOSCROLL_OFF );
            CloseDocument();
            FrmGotoForm( GetValidForm( frmLibrary ) );
            break;

        case FINDCONTROL:
            DoAutoscrollToggle( AUTOSCROLL_OFF );
            FrmPopupForm( frmSearch );
            break;

        case AGAINCONTROL:
            DoAutoscrollToggle( AUTOSCROLL_OFF );
            SearchAgain();
            break;

        case MENUCONTROL:
            DoAutoscrollToggle( AUTOSCROLL_OFF );
            EvtEnqueueKey( menuChr, 0, commandKeyMask );
            break;

        case OFFSETCONTROL:
        {
            UInt16 prevCoordSys;
            Int16  selection;

            DoAutoscrollToggle( AUTOSCROLL_OFF );
            prevCoordSys = PalmSetCoordinateSystem( STANDARD );
            selection = LstPopupList( GetObjectPtr( frmMainPercentList ) );
            PalmSetCoordinateSystem( prevCoordSys );
            if ( selection != noListSelection )
                GotoLocation( selection );

            break;
        }

        case BOOKMARKCONTROL:
        {
            UInt16      prevCoordSys;
            ListType*   list;
            Int16       selection;
            UInt16      numOfBookmarks;

            DoAutoscrollToggle( AUTOSCROLL_OFF );

            prevCoordSys = PalmSetCoordinateSystem( STANDARD );

            list            = GetObjectPtr( frmMainBookmarkList );
            numOfBookmarks  = CreatePopupBookmarkList( list );
            if ( numOfBookmarks == 0 ) {
                PalmSetCoordinateSystem( prevCoordSys );
                break;
            }
            
            selection = LstPopupList( GetObjectPtr( frmMainBookmarkList ) );
            
            if ( 0 <= selection ) {
                BookmarkListEntry e;

                MemMove( &e, GetBookmarkListEntry( selection ), sizeof( BookmarkListEntry ) );

                ReleaseBookmarkList();
                PalmSetCoordinateSystem( prevCoordSys );

                switch ( e.kind ) {
                    case BOOKMARK_ADD_BOOKMARK: 
                        DoAddBookmark();
                        break;
                    case BOOKMARK_EDIT_BOOKMARK:
                        FrmPopupForm( frmBookmarks );
                        break;
#ifdef SUPPORT_ANNOTATION
                    case BOOKMARK_ADD_ANNOTATION:
                        isSelectWordTapMode = true;
                        selectedWordAction  = SELECT_WORD_ANNOTATE;
                        ShowSelectWordTapIcon();
                        break;
#endif
                    case BOOKMARK_BOOKMARK:
                    case BOOKMARK_ANNOTATION:
                        SendBookmarkGoToEvent( &e, false );
                        break;

                    case BOOKMARK_EXT_BOOKMARK:
                        GoToExtBookmark( e.recordNum );
                        break;
                        
                    case BOOKMARK_INVALID:
                        break;
                }
            }
            else {
                ReleaseBookmarkList();
                PalmSetCoordinateSystem( prevCoordSys );
            }

            break;
        }

        case AUTOSCROLLSTARTCONTROL:
        case AUTOSCROLLSTOPCONTROL:
            DoAutoscrollToggle( AUTOSCROLL_TOGGLE );
            break;

        case AUTOSCROLLINCRCONTROL:
            DoAutoscrollIncr();
            break;

        case AUTOSCROLLDECRCONTROL:
            DoAutoscrollDecr();
            break;

        case COPYTOMEMOCONTROL:
            DoHardcopy();
            break;

#ifdef SUPPORT_WORD_LOOKUP
        case SELECTEDWORDCONTROL: {
            EventType newEvent;

            MemSet( &newEvent, sizeof( newEvent ), 0 );
            newEvent.eType                   = pluckerSelectedWordEvent;
            newEvent.data.generic.datum[ 0 ] = selectedWordAction;
            EvtAddEventToQueue( &newEvent );

            break;
        }
#endif

        default:
            break;
    }
}
Пример #9
0
/*****************************************************************************
* Function: GadgetTap
*
* Description: Handles penDown events (taps) on the gadget
*****************************************************************************/
void
GadgetTap(FormGadgetType *pGadget, EventType *event)
{
  //you may find it useful to track if they
  //lift the pen still within the boundaries of the gadget
  Boolean isPenDown = true;
  Int16 newPointX, newPointY, startPointX, startPointY;
  UInt16 index;
  RectangleType bounds;

  // This is just needed since we do not want to access internal structure
  // data directly in FormGadgetType (need rect field below)
  index = TNGetObjectIndexFromPtr(FrmGetActiveForm(), pGadget);
  FrmGetObjectBounds(FrmGetActiveForm(), index, &bounds);

  //track the pen down event
  EvtGetPen(&newPointX, &newPointY, &isPenDown);
  startPointX = newPointX;
  startPointY = newPointY;
  while (isPenDown){
    EvtGetPen(&newPointX, &newPointY, &isPenDown);
  }

  if (RctPtInRectangle(newPointX, newPointY, &bounds)) {
    /* the pen up was also in the gadget
       This can mean two things:
       1) we got a strike command
       2) a field was tapped
    */
    RectangleType topRight, bottomRight;
    Boolean found=false, foundTime=false;
    MemHandle m;
    TimeDBRecord *t;
    UInt16 index=0, wantCourse=0, tmp3_4th=0;
    GadgetTimeListType *gtl;
    TNlist *tmpl;

    /* Check for stroke commands */

    tmp3_4th = (3 * bounds.extent.x) / 4;
    RctSetRectangle(&topRight,
                    bounds.topLeft.x+ tmp3_4th,
                    bounds.topLeft.y,
                    bounds.extent.x - tmp3_4th,
                    bounds.extent.y/2
                   );
    RctSetRectangle(&bottomRight,
                    bounds.topLeft.x + tmp3_4th,
                    bounds.topLeft.y + (bounds.extent.y/2),
                    bounds.extent.x - tmp3_4th,
                    bounds.extent.y / 2
                   );

    if (RctPtInRectangle(startPointX, startPointY, &bottomRight) &&
        RctPtInRectangle(newPointX, newPointY, &topRight) ) {
      // Stroke Command: BACK
      GadgetDrawStep(winUp);
      return;
    } else if (RctPtInRectangle(startPointX, startPointY, &topRight) &&
               RctPtInRectangle(newPointX, newPointY, &bottomRight) ) {
      // Stroke Command: NEXT
      GadgetDrawStep(winDown);
      return;
    }


    tmpl = gGadgetTimeList;
    while (tmpl != NULL) {
      gtl = (GadgetTimeListType *)tmpl->data;
      if (RctPtInRectangle(newPointX, newPointY, &(gtl->rect))) {
	m = DmQueryRecord(DatabaseGetRef(), gtl->index);
        if (m) {
          // mt may be null, for example if next is drawn after delete!
          t = (TimeDBRecord *)MemHandleLock(m);

	  // we got a match
	  wantCourse = t->course;
	  gTimeIndex = gtl->index;
	  foundTime  = true;

	  MemHandleUnlock(m);
	}
      }
      tmpl = tmpl->next;
    }

    // Search for the clicked time
    if (foundTime) {
      index = 0;
      while(! found && ((m = DmQueryNextInCategory(DatabaseGetRef(), &index, DatabaseGetCat())) != NULL)) {
	Char *s = (Char *)MemHandleLock(m);
	if (s[0] == TYPE_COURSE) {
	  CourseDBRecord c;
	  UnpackCourse(&c, s);
	  if (c.id == wantCourse) {
	    SndPlaySystemSound(sndClick);
	    gCourseIndex = index;
	    found=true;
	  }
	}
	MemHandleUnlock(m);
	index += 1;
      }
    }

    if (found && foundTime) {
      GadgetDrawHintCurrent();
    } else {
      SndPlaySystemSound(sndError);
    }

  } // else outside gadget bounds -> do nothing

}
Пример #10
0
/***********************************************************************
 *
 * FUNCTION:    SelectTimeZone
 *
 * DESCRIPTION: Display a form showing a time zone and allow the user
 *              to select a different time zone. This is the time zone
 *					 dialog as seen in Date & Dime panel
 *
 * PARAMETERS:
 *		ioTimeZoneP				<->	pointer to time zone to change
 *		ioLocaleInTimeZoneP	<->	Ptr to locale found in time zone.
 *		titleP					 ->	String title for the dialog.
 *		showTimes				 -> 	True => show current and new times
 *		anyLocale				 ->	True => ignore ioLocaleInTimeZoneP on entry.
 *
 * RETURNED:
 *		true if the OK button was pressed (in which case *ioTimeZoneP and
 *		*ioCountryInTimeZoneP might be changed).
 *
 * HISTORY:
 *		03/02/00	peter	Created by Peter Epstein.
 *		04/03/00	peter	Allow NULL currentTimeP.
 *		04/12/00	peter API changed to get rid of trigger text
 *		04/14/00	peter Update current & new time as time passes
 *		07/31/00	kwk	Use SysTicksPerSecond() routine vs. sysTicksPerSecond macro.
 *					kwk	Re-wrote to use set of resources (name, offset, country),
 *							scrollbar vs. arrows, etc.
 *		08/01/00	kwk	Support scroll-to-key. Fixed scrollbar/list sync bugs.
 *		08/02/00	kwk	New API w/ioCountryInTimeZoneP and anyCountry parameters.
 *					kwk	Call FrmHandleEvent _after_ our event handling code has
 *							decided that it doesn't want to handle the event, not before.
 *		08/03/00	kwk	Call LstSetListChoices before calling LstGetVisibleItems,
 *							as otherwise accessing the time zone picker from the
 *							Setup app (when <showTimes> is false) gives you a two-
 *							line high display because LstGetVisibleItems returns 0.
 *		08/18/00	kwk	Play error sound if user writes letter that doesn't
 *							match any entries.
 *					kwk	Don't select item if doing scroll-to-view for entry
 *							that matches the letter the user wrote.
 *		08/21/00	kwk	Scroll-to-view with text entry now scrolls to the top
 *							of the list, versus the middle.
 *		10/09/00	peter	Get rid of scroll bar and let list do the scrolling.
 *		11/17/00	CS		Change ioCountryInTimeZoneP to ioLocaleInTimeZoneP,
 *							(and anyCountry to anyLocale, but that doesn't matter),
 *							since CountryType is only a UInt8, and this may
 *							change someday.
 *
 ***********************************************************************/
Boolean SelectTimeZone(Int16 *ioTimeZoneP, LmLocaleType* ioLocaleInTimeZoneP,
				const Char *titleP, Boolean showTimes, Boolean anyLocale)
{
	FormType* originalForm;
	FormType* dialog;
	EventType event;
	Boolean confirmed = false;
	Boolean done = false;
	Boolean adjustTimes = false;
	Boolean foundLocale = false;
	MemHandle currentTimeHandle, newTimeHandle;
	ListPtr listP;
	Int16 oldTimeZone, newTimeZone, testTimeZone;
	LmLocaleType newTimeZoneLocale;
	Int16 delta, closestDelta, timeZoneIndex, closestIndex;
	DateTimeType currentTime, newTime;
	TimeZoneEntryType* tzArrayP;
	UInt16 numTimeZones;
	MemHandle tzNamesH;
	
	if (showTimes)
	{
		TimSecondsToDateTime(TimGetSeconds(), &currentTime);
	}
	
	oldTimeZone = *ioTimeZoneP;
	newTimeZone = oldTimeZone;
	newTimeZoneLocale = *ioLocaleInTimeZoneP;
	
	originalForm = FrmGetActiveForm();
	dialog = (FormType *) FrmInitForm (TimeZoneDialogForm); 
	listP = FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogTimeZoneList));
	
	if (titleP)
	{
		FrmSetTitle (dialog, (Char *) titleP);
	}
	
	FrmSetActiveForm (dialog);
	
	// We need to call LstSetListChoices before calling LstSetHeight below, as otherwise
	// LstGetVisibleItems will return 0.
	tzArrayP = PrvCreateTimeZoneArray(&tzNamesH, &numTimeZones);
	LstSetListChoices(listP, (Char**)tzArrayP, numTimeZones);
	
	if (showTimes)
	{
		currentTimeHandle = MemHandleNew(timeStringLength + 1 + dowLongDateStrLength + 1);
		ErrFatalDisplayIf (!currentTimeHandle, "Out of memory");
		newTimeHandle = MemHandleNew(timeStringLength + 1 + dowLongDateStrLength + 1);
		ErrFatalDisplayIf (!newTimeHandle, "Out of memory");

		PrvSetTimeField(dialog, TimeZoneDialogCurrentTimeField, currentTimeHandle, &currentTime, false);
	}
	else
	{
		// Hide the current and new time.
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeLabel));
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeField));
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeLabel));
		FrmHideObject(dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeField));
		
		// Make the list show more items to take up extra the space.
		LstSetHeight(listP, LstGetVisibleItems(listP) + extraTimeZonesToShowWhenNoTimes);
	}
	
	// Find the time zone in the list closest to the current time zone, and that
	// matches <*ioLocaleInTimeZoneP> if <anyLocale> is false.
	closestDelta = hoursInMinutes * hoursPerDay;		// so big that all others will be smaller
	for (timeZoneIndex = 0; timeZoneIndex < numTimeZones; timeZoneIndex++)
	{
		Boolean checkDelta = anyLocale;
		testTimeZone = tzArrayP[timeZoneIndex].tzOffset;
		delta = Abs(testTimeZone - oldTimeZone);
		
		if (!anyLocale)
		{
			if (tzArrayP[timeZoneIndex].tzCountry == ioLocaleInTimeZoneP->country)
			{
				// If we haven't previously found a matching locale, reset the
				// delta so that this entry overrides any previous best entry.
				if (!foundLocale)
				{
					foundLocale = true;
					closestDelta = hoursInMinutes * hoursPerDay;
				}
				
				checkDelta = true;
			}
			
			// If we haven't yet found a matching locale, go for the closest delta.
			else
			{
				checkDelta = !foundLocale;
			}
		}
		
		// If we want to check the time zone delta, do it now.
		if (checkDelta && (delta < closestDelta))
		{
			closestIndex = timeZoneIndex;
			closestDelta = delta;
		}
	}
	
	// Scroll so that time zone is in the center of the screen and select it if it's an exact match.
	LstSetTopItem(listP, max(0, closestIndex - (LstGetVisibleItems(listP) / 2)));
	if ((closestDelta == 0) && (anyLocale || foundLocale))
	{
		LstSetSelection(listP, closestIndex);
		if (showTimes)
		{
			newTime = currentTime;
			PrvSetTimeField(dialog, TimeZoneDialogNewTimeField, newTimeHandle, &newTime, false);
		}
	}
	else
	{
		LstSetSelection(listP, noListSelection);
	}
	
	LstSetDrawFunction(listP, PrvTimeZoneListDrawItem);
	
	FrmDrawForm (dialog);
	
	while (!done)
	{
		Boolean handled = false;
		EvtGetEvent(&event, SysTicksPerSecond());		// so we can update the current and new time

		if (SysHandleEvent ((EventType *)&event))
		{
			continue;
		}
		
		if (event.eType == nilEvent)
		{
			if (showTimes)
			{
				PrvUpdateTimeFields(	dialog,
										&currentTime,
										&newTime,
										currentTimeHandle,
										newTimeHandle,
										TimeZoneDialogCurrentTimeField,
										TimeZoneDialogNewTimeField);
			}
		}
		
		else if (event.eType == ctlSelectEvent)
		{
			handled = true;
			
			switch (event.data.ctlSelect.controlID)
			{
				case TimeZoneDialogOKButton:
					// Set the new time zone.
					*ioTimeZoneP = newTimeZone;
					*ioLocaleInTimeZoneP = newTimeZoneLocale;

					done = true;
					confirmed = true;
				break;

				case TimeZoneDialogCancelButton:
					done = true;
				break;
				
				default:
					ErrNonFatalDisplay("Unknown control in form");
				break;
			}
		}
		
		// User tapped on a time zone in the list.
		else if (event.eType == lstSelectEvent)
		{
			UInt16 localeIndex;
			
			ErrNonFatalDisplayIf(event.data.lstSelect.listID != TimeZoneDialogTimeZoneList,
										"Unknown list in form");
			
			newTimeZone = tzArrayP[event.data.lstSelect.selection].tzOffset;
			newTimeZoneLocale.country =
				tzArrayP[event.data.lstSelect.selection].tzCountry;
			newTimeZoneLocale.language = lmAnyLanguage;
			if (LmLocaleToIndex(&newTimeZoneLocale, &localeIndex) == errNone)
			{
				if (LmGetLocaleSetting(	localeIndex,
												lmChoiceLocale,
												&newTimeZoneLocale,
												sizeof(newTimeZoneLocale)))
				{
					ErrNonFatalDisplay("Can\'t get locale");
				}
			}
			adjustTimes = showTimes;
			handled = true;
		}

		else if (event.eType == keyDownEvent)
		{
			if	(!TxtCharIsHardKey(event.data.keyDown.modifiers, event.data.keyDown.chr))
			{
				//	Hard scroll buttons
				if (EvtKeydownIsVirtual(&event))
				{
					if (event.data.keyDown.chr == vchrPageUp)
					{
						handled = true;
						LstScrollList(listP, winUp, LstGetVisibleItems(listP) - 1);
					}
					else if (event.data.keyDown.chr == vchrPageDown)
					{
						handled = true;
						LstScrollList(listP, winDown, LstGetVisibleItems(listP) - 1);
					}
				}
				else if (TxtCharIsPrint(event.data.keyDown.chr))
				{
					Int16 index;
					
					handled = true;
					index = PrvSearchTimeZoneNames(tzArrayP, numTimeZones, event.data.keyDown.chr);
					
					if (index != noListSelection)
					{
						Int16 delta = index - listP->topItem;
						if (delta < 0)
						{
							LstScrollList(listP, winUp, -delta);
						}
						else if (delta > 0)
						{
							LstScrollList(listP, winDown, delta);
						}
					}
					else
					{
						SndPlaySystemSound(sndError);
					}
				}
			}
		}

		else if (event.eType == appStopEvent)
		{
			EvtAddEventToQueue (&event);
			done = true;
			break;
		}
		
		// If we didn't handle the event, give the form code a crack at it.
		// This simulates the "normal" method of installing an event handler
		// for a form, which gets called, and then if it returns false, the
		// FrmHandleEvent routine gets called.
		if (!handled)
		{
			FrmHandleEvent(dialog, &event); 
		}
		
		// If something changed, and we need to update our time display,
		// do it now.
		if (adjustTimes)
		{
			adjustTimes = false;
			newTime = currentTime;
			TimAdjust(&newTime, (Int32)(newTimeZone - oldTimeZone) * minutesInSeconds);
			PrvSetTimeField(dialog, TimeZoneDialogNewTimeField, newTimeHandle, &newTime, true);
		}
	}	// end while true
		
	if (showTimes)
	{
		FldSetTextHandle(FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogCurrentTimeField)), NULL);
		FldSetTextHandle(FrmGetObjectPtr (dialog, FrmGetObjectIndex (dialog, TimeZoneDialogNewTimeField)), NULL);
		MemHandleFree(currentTimeHandle);
		MemHandleFree(newTimeHandle);
	}
	
	FrmEraseForm (dialog);
	FrmDeleteForm (dialog);
	FrmSetActiveForm(originalForm);

	PrvDeleteTimeZoneArray(tzArrayP, tzNamesH);

	return confirmed;
} // SelectTimeZone