コード例 #1
0
ファイル: FormGroupManagement.cpp プロジェクト: oldhu/smstw
static void DrawList()
{
	FormPtr form = FrmGetActiveForm();
	if (FormIsNot(form, FormGroupManagement)) return;
	ListPtr list = (ListPtr) GetObjectPtr(form, ListGroups);
	LstSetListChoices(list, NULL, g_PhoneGroups.size());
	LstSetDrawFunction(list, ListDrawDataFunc);
	LstDrawList(list);
}
コード例 #2
0
ファイル: savegame.c プロジェクト: petesh/pocketcity
/*!
 * \brief Update the list of save games.
 *
 * Can be called from 2 contexts ... from the delete items dialog
 * or from the main save game dialog. That's the reason for the
 * check agains the active form and the formID_files pointer
 */
static void
UpdateSaveGameList(void)
{
	int count;
	FormPtr files_form;
	ListPtr list;

	if (citylist != NULL)
		FreeCityNames(citylist);

	citylist = CityNames(&count);

	files_form = FrmGetFormPtr((UInt16)formID_files);

	if (files_form == NULL) {
		WriteLog("could not get the files form pointer\n");
		return;
	}
	list = (ListPtr)GetObjectPtr(files_form, listID_FilesList);

	if (list == NULL) {
		WriteLog("Could not get the pointer for list\n");
		return;
	}

	if (NULL == citylist) {
		LstSetListChoices(list, NULL, 0);
		if (files_form == FrmGetActiveForm() && FrmVisible(files_form))
			LstDrawList(list);
		return; /* no cities */
	}

	/* update list */
	LstSetListChoices(list, citylist, count);
	if (files_form == FrmGetActiveForm() && FrmVisible(files_form))
		LstDrawList(list);
}
コード例 #3
0
ファイル: SMSReply.cpp プロジェクト: oldhu/smstw
static void DrawList()
{
	FormPtr form = FrmGetActiveForm();
	if (FormIsNot(form, FormReply)) return;
	ListPtr list = (ListPtr) GetObjectPtr(form, ListGroups);
	LstSetListChoices(list, NULL, g_PhoneGroups.size() + 1);
	
	UInt16 maxVisible = 8;
	if (g_PhoneGroups.size() < maxVisible - 1) 
		maxVisible = g_PhoneGroups.size() + 1;
	
	LstSetHeight(list, maxVisible);
	LstSetDrawFunction(list, ListDrawDataFunc);
	LstDrawList(list);
}
コード例 #4
0
ファイル: kartrando.c プロジェクト: samskivert/kartrando
static void
rando ()
{
    int ccount, cskip, tcount = TRACK_COUNT, tskip;
    int r, p, c, t;
    char* tmptracks[TRACK_COUNT];
    char* chars[CHAR_COUNT];

    // if we're not allowing rainbow road, decrement the tcount to 15 as
    // if the track doesn't exist
    if (!rainbow) tcount--;

    // make a temporary copy of the tracks array
    for (r = 0; r < TRACK_COUNT; r++) {
	tmptracks[r] = tracks[r];
    }

    // now select some random tracks
    for (r = 0; r < races; r++) {
	ccount = CHAR_COUNT;

	// make a temporary copy of the characters array
	for (c = 0; c < CHAR_COUNT; c++) {
	    chars[c] = characters[c];
	}

	for (p = 0; p < players; p++) {
	    // pick a random position
	    cskip = SysRandom(0) % ccount;

	    // now iterate over the list skipping already chosen characters
	    for (c = 0; c < cskip; c++) {
		while (chars[c] == 0) c++;
	    }

	    // skip any trailing used characters
	    while (chars[c] == 0) c++;

	    // decrement the character count for next time
	    ccount--;

	    if (p > 0) {
		StrCat(racestrs[r], chars[c]);
	    } else {
		StrCopy(racestrs[r], chars[c]);
	    }

	    if (p < players-1) {
		StrCat(racestrs[r], " ");
	    }

	    // mark the player as used
	    chars[c] = 0;
	}

	// pick a random position
	if (repeats) {
	    t = SysRandom(0) % tcount;

	} else {
	    tskip = SysRandom(0) % tcount;

	    // now iterate over the list skipping already chosen characters
	    for (t = 0; t < tskip; t++) {
		while (tmptracks[t] == 0) t++;
	    }

	    // skip any trailing used characters
	    while (tmptracks[t] == 0) t++;

	    // decrement the character count for next time
	    tcount--;
	}

	StrCat(racestrs[r], ": ");

	if (extra) {
	    StrCat(racestrs[r], SysRandom(0) % 100 > 50 ? "* " : "");
	}

	StrCat(racestrs[r], tmptracks[t]);

	// clear out this track if we're allowing no repeats
	if (!repeats) {
	    tmptracks[t] = 0;
	}
    }

    // update the list with the new choices
    LstSetListChoices(listPtr_races, &racestrs[0], races);

    // clear the list selection
    LstSetSelection(listPtr_races, -1);

    // and draw it
    LstDrawList(listPtr_races);
}
コード例 #5
0
ファイル: xfer.c プロジェクト: jemyzhang/DiddleBug
/*
** 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();
}
コード例 #6
0
ファイル: StripCS.c プロジェクト: sjlombardo/strip-palm
/********************************************************************************
 * Description: this is the function responsible for checking the 
 * input password value of the authentication form. 
 * ******************************************************************************/ 
static void 
checkPassword (void) 
{
	MemPtr pass1, scratch = NULL;
	char *input;

	UInt16 index = 0;
	MemHandle rec;
	mdKey in;
	ListType *list;
	
		// compact text and get a pointer.
		FldCompactText (GetObjectFromActiveForm (PasswordField));
	input = FldGetTextPtr (GetObjectFromActiveForm (PasswordField));
	list = GetObjectFromActiveForm (selPopupList);
	
		// if SysPass is defined, free it. this happens when Strip locks
		// itself after the timeout.
		if (SysPass)
		MemPtrFree (SysPass);
	
		// if its the first time the user has used the program we need 
		// to set some things up. 
		if (input && StrLen (input))
		
	{
		
			// read the password from the database, decrypt with the input text.
			if ((rec = DmQueryRecord (PasswordDB, index)))
			
		{
			pass1 = MemHandleLock (rec);
			if ((scratch = MemPtrNew (24)))
				
			{
				UInt16 chk = LstGetSelection (list);
				
					//printf("%d\n", LstGetSelection(list)); 
					switch (chk)
					
				{
					case 0:
						UnpackPassword_old (pass1, scratch, input, 1);
						break;
					case 1:
						UnpackPassword_old (pass1, scratch, input, 2);
						break;
					case 2:
						UnpackPassword_old (pass1, scratch, input, 0);
						break;
				}
			}
			MemHandleUnlock (rec);
		}
		
			// the message digest of the password they provided should be exactly the
			// same as the message digest that was just decrypted out of the password
			// database. Do a MemCmp to make sure they are the same.
		md5_string (input, in);

		if ((!MemCmp (in, scratch, 16)) && input)
			
		{
			
				// if so, copy the password onto the system-password
		if ((SysPass = MemPtrNew (StrLen (input) + 1)))
				StrCopy (SysPass, input);
		if (scratch)
				MemPtrFree (scratch);
		md_string(SysPass, NewSysPass);
		cryptSwitch (LstGetSelection (list));
		}
		
		else
			
		{
			
				// FAILURE!!!!!!
				// free the memory and tell the user they entered the wrong password.
				FieldType *fld = GetObjectFromActiveForm (PasswordField);
			FrmCustomAlert (GenericError,
							  "The password you entered is incorrect", NULL,
							  NULL);
				FldSetSelection (fld, 0, FldGetTextLength (fld));
			LstDrawList (list);
			if (scratch)
				
			{
				MemPtrFree (scratch);
				SysPass = NULL;
			}
		}
	}
	
		// null string is always wrong!!!
		else
		
	{
		FrmCustomAlert (GenericError, "You forgot to enter a password!!",
						 NULL, NULL);
		LstDrawList (list);
	}
}
コード例 #7
0
/* Event handler for the bookmark form */
Boolean BookmarksFormHandleEvent
    (
    EventType* event  /* pointer to an EventType structure */
    )
{
    Boolean handled    = false;

    switch ( event->eType ) {
        case winEnterEvent:
            handled = ResizeHandleWinEnterEvent();
            break;

        case winDisplayChangedEvent:
            handled = ResizeHandleWinDisplayChangedEvent();
            break;

        case winExitEvent:
            handled = ResizeHandleWinExitEvent();
            break;

        case frmOpenEvent:
#ifdef HAVE_SILKSCREEN
            ResizeHandleFrmOpenEvent();
#endif
            BookmarksFormInit();
            handled = true;
            break;

        case frmCloseEvent:
            ReleaseBookmarkList();
#ifdef HAVE_SILKSCREEN
            ResizeHandleFrmCloseEvent();
#endif
            handled = false;
            break;

        case ctlSelectEvent:
            if ( event->data.ctlEnter.controlID == frmBookmarksDelete ) {
                ListType*   list;
                Int16       selection;

                list        = GetObjectPtr( frmBookmarksList );
                selection   = LstGetSelection( list );
                if ( selection != noListSelection ) {
                    BookmarkListEntry* e;

                    e = GetBookmarkListEntry( selection );

                    if ( e->kind == BOOKMARK_ANNOTATION ||
                         e->kind == BOOKMARK_BOOKMARK ) {
                        UInt16 choice;

                        choice = FrmCustomAlert( confirmDelete,
                                    LstGetSelectionText( list, selection ), NULL,
                                        NULL );
                        if ( choice == DELETE_BOOKMARK ) {
                            ErrTry {
                                DeleteAnnotationByRecordNum( e->recordNum );
                                ReleaseBookmarkList();
                                CreateBookmarkList( list );
                                LstDrawList( list );
                                deleted = true;
                            }
                            ErrCatch( UNUSED_PARAM( err ) ) {
                                FrmCustomAlert( errCannotDeleteBookmark,
                                    LstGetSelectionText( list, selection ), NULL,
                                    NULL );
                            } ErrEndCatch
                        }
                     }