📄 floatfld.c
字号:
* to another field. * * RETURNED: Nothing. ***********************************************************************/static void DisplayNumber( void){ Char * strP; // temp string pointer double num; // temp num holder UInt8 precision = 0; // digits to the right of the decimal UInt8 maxLen = 0; // overall maximum length Boolean localize = false; // add 1000ths separators to left-hand side Boolean rAlign = false; // justify left or right FieldAttrType attr; FieldPtr fldP; // Get the first field value as a string strP = FldGetTextPtr ( GetObjectPtr ( MainNumEnterField )); if ( strP ) { // Convert the user-entered string to a double precision number num = StringToDouble ( strP ); // Get the user-defined attributes for displaying the number localize = ( Boolean ) CtlGetValue ( GetObjectPtr ( MainLocalizeCheckbox )); precision = ( UInt8 ) LstGetSelection ( GetObjectPtr ( MainPrecisionList )); maxLen = ( UInt8 ) FldGetMaxChars ( GetObjectPtr ( MainNumDisplayField )); rAlign = ( Boolean ) CtlGetValue ( GetObjectPtr ( MainJustifyCheckbox )); // Convert the number back to a string DoubleToString ( num, gNumStr, localize, ( UInt8 ) precision, maxLen ); // Set the output field alignment as appropriate fldP = GetObjectPtr ( MainNumDisplayField ); FldGetAttributes ( fldP, &attr ); attr.justification = ( UInt16 ) ( rAlign == true? rightAlign: leftAlign ); FldSetAttributes ( fldP, &attr ); // Draw the output field SetTextFieldWithString ( MainNumDisplayField, gNumStr, true ); }}#pragma mark ----------------/*********************************************************************** * FUNCTION: MainFormInit * * DESCRIPTION: This routine initializes the main form. * * RETURNED: nothing ***********************************************************************/static void MainFormInit( FormPtr frmP // ( in ) Pointer to the main form.){ if ( frmP != NULL ) { }}/*********************************************************************** * FUNCTION: MainFormDraw * * DESCRIPTION: This routine draws the non-form contents of the main form. * * RETURNED: nothing ***********************************************************************/static void MainFormDraw( FormPtr frmP // ( in ) Pointer to the main form.){ if ( frmP != NULL ) { // Set the focus to the first field UInt16 fldIdx = FrmGetObjectIndex ( frmP, MainNumEnterField ); if ( fldIdx ) { FrmSetFocus ( frmP, fldIdx ); } // Set the precision popup trigger SetPopup ( MainPrecisionPopTrigger, MainPrecisionList, 7 ); }}/*********************************************************************** * FUNCTION: MainFormDone * * DESCRIPTION: This routine cleans up after the main form. * * RETURNED: nothing ***********************************************************************/static void MainFormDone( FormPtr frmP // ( in ) Pointer to the main form){ if ( frmP != NULL ) { // Insert application-specific code first// Then do this as the very last thing FrmEraseForm ( frmP ); FrmDeleteForm ( frmP ); }}/*********************************************************************** * FUNCTION: EditMenuCommand * * DESCRIPTION: This routine handles edit menu commands by converting * the edit menu command ID to a system edit menu command ID. * * RETURNED: nothing ***********************************************************************/static Boolean EditMenuCommand // ( out ) handled?( UInt16 * command // ( in ) Pointer to the ID of the menu command to do){ Boolean isEditCmd = false; UInt16 cmd = * command; if ( *command >= EditUndo && *command <= EditGraffitiHelp ) { *command = * command - EditUndo + sysEditMenuUndoCmd; isEditCmd = true; } return ( isEditCmd );}/*********************************************************************** * FUNCTION: MainFormDoMenuCommand * * DESCRIPTION: This routine handles menu commands. * * RETURNED: nothing ***********************************************************************/static Boolean MainFormDoMenuCommand // ( out ) handled?( UInt16 command // ( in ) The ID of menu command to do){ Boolean handled = false; FormPtr frmP; switch ( command ) { case MainOptionsAboutFieldFun: MenuEraseStatus ( 0 ); frmP = FrmInitForm ( AboutForm ); FrmDoDialog ( frmP ); FrmDeleteForm ( frmP ); handled = true; break; } return handled;}/*********************************************************************** * FUNCTION: MainFormProcessKey * * DESCRIPTION: Handle keystrokes for the main form. * * RETURNED: true if the event is handled. ***********************************************************************/static Boolean MainFormProcessKey // ( out ) handled?( FormPtr frmP, // ( in ) the current form UInt8 key // ( in ) the key to process){ Boolean handled = true; // Handle next field/prev field characters if (( key == nextFieldChr ) || ( key == prevFieldChr )) { MoveToNextField ( frmP, key ); } else { // Check for special numeric fields and filter if necessary UInt16 focusIdx = FrmGetFocus ( FrmGetActiveForm ()); if ( focusIdx != noFocus ) { UInt8 precision = ( UInt8 ) LstGetSelection ( GetObjectPtr ( MainPrecisionList )); FieldPtr fldP = FrmGetObjectPtr ( frmP, focusIdx ); handled = CheckValidNumChar ( fldP, key, precision ); } } return handled;}/*********************************************************************** * FUNCTION: MainFormHandleEvent * * DESCRIPTION: This routine is the event handler for MainForm. * * RETURNED: true if the event is handled. ***********************************************************************/static Boolean MainFormHandleEvent // ( out ) handled?( EventPtr eventP // ( in ) Pointer to the event to handle){ Boolean handled = false; FormPtr frmP = FrmGetActiveForm (); ControlPtr ctlP; if ( frmP ) { switch ( eventP->eType ) { // Form events case frmOpenEvent: MainFormInit ( frmP ); // ***** WARNING - falls thru to next case ***** case frmUpdateEvent: FrmDrawForm ( frmP ); MainFormDraw ( frmP ); handled = true; break; case frmCloseEvent: MainFormDone ( frmP ); handled = true; break;// Menu events case menuEvent: if ( ! EditMenuCommand ( &eventP->data.menu.itemID )) { handled = MainFormDoMenuCommand ( eventP->data.menu.itemID ); } break; // Buttons, checkboxes. all result in redrawing.// The control processing is done in DrawNumber case ctlSelectEvent: DisplayNumber (); handled = true; break;// Popup triggers case ctlEnterEvent: ctlP = GetObjectPtr ( eventP->data.ctlSelect.controlID ); if ( ctlP->style == popupTriggerCtl ) { HandlePopup ( eventP->data.ctlSelect.controlID ); handled = true; DisplayNumber (); } break;// Keystrokes case keyDownEvent: handled = MainFormProcessKey ( frmP, ( UInt8 ) eventP->data.keyDown.chr ); break; } } return handled;}#pragma mark ----------------/*********************************************************************** * FUNCTION: AppHandleEvent * * DESCRIPTION: Loads a form's resources and set its event handler. * * RETURNED: true if the event is handled. ***********************************************************************/static Boolean AppHandleEvent // ( out ) handled?( EventPtr eventP // ( in ) Pointer to the event to handle){ Boolean handled = false; if ( eventP->eType == frmLoadEvent ) { // Form load event--initialize the form and make it the active form. UInt16 formId = eventP->data.frmLoad.formID; FormPtr frmP = FrmInitForm ( formId ); FrmSetActiveForm ( frmP );// Set the event handler for the form. switch (formId) { case MainForm: FrmSetEventHandler(frmP, MainFormHandleEvent); handled = true; break;// Insert other cases as needed for other forms. } handled = true; } return handled;}/*********************************************************************** * FUNCTION: AppEventLoop * * DESCRIPTION: The main event loop for the application. * * RETURNED: nothing ***********************************************************************/static void AppEventLoop( void){ UInt16 error; EventType event; do { EvtGetEvent ( &event, evtWaitForever ); if (! SysHandleEvent ( &event)) if (! MenuHandleEvent ( 0, &event, &error )) if (! AppHandleEvent ( &event )) FrmDispatchEvent ( &event ); } while ( event.eType != appStopEvent );}/*********************************************************************** * FUNCTION: AppStart * * DESCRIPTION: Get the user's number format punctuation. * * RETURNED: Err value or 0 if nothing went wrong ***********************************************************************/static UInt32 AppStart // ( out ) error or zero( void){ UInt32 pref = PrefGetPreference ( prefNumberFormat ); LocGetNumberSeparators (( NumberFormatType ) pref, &gKSep, &gDSep); return 0;}/*********************************************************************** * FUNCTION: AppStop * * DESCRIPTION: Do whatever you need to do, like save the preferences. * * RETURNED: nothing ***********************************************************************/static void AppStop( void){ FrmCloseAllForms ();}/*********************************************************************** * FUNCTION: PilotMain * * DESCRIPTION: The application main entry point. * * RETURNED: 0 if launch & execution are successful, non-zero otherwise. ***********************************************************************/UInt32 PilotMain // ( out ) error code or zero( UInt16 cmd, // ( in ) The launch code MemPtr /* cmdPBP*/, // ( in ) Pointer to the launch code structure UInt16 launchFlags // ( in ) Extra launch info){ UInt32 error = 0;// Check the ROM version for compatibility. error = RomVersionCompatible ( MIN_ROM_VERSION, launchFlags); if ( error == 0 ){// ROM OK, check for the various launch codes as needed. switch (cmd) { case sysAppLaunchCmdNormalLaunch: error = AppStart (); if ( error == 0 ) { FrmGotoForm ( MainForm ); AppEventLoop (); AppStop (); } break; } } return error;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -