⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 napi.c

📁 CD_高级PALM编程
💻 C
📖 第 1 页 / 共 3 页
字号:
// find out what index was selected		wwwInstance.prefs.inetConfigIndex = (unsigned short)LstGetSelection ( uiListP );		WWWSetPrefs();	}	else if ( btnObjectID == _WWWConfigNetworkButton )	{		WWWGotoPanel( sysFileCNetworkPanel );	}	else if ( btnObjectID == _WWWConfigWirelessButton )	{		WWWGotoPanel( sysFileCWirelessPanel );	}// Delete the dialog form	FrmEraseForm (dialogFrmP );	FrmDeleteForm ( dialogFrmP );	// Restore the old form	if ( prevFrmP != NULL )	{		FrmSetActiveForm(prevFrmP);	}// Re-draw the previous form	if ( prevFrmP != NULL )	{		FrmUpdateForm( FrmGetFormId( prevFrmP ),  frmRedrawUpdateCode );	}// Help the caller a bit here. If we're not open, let's open anyway.	WWWClose();}/*********************************************************************** * FUNCTION:    	WWWOpen * * DESCRIPTION: Opens the WWW function library. Initializes INetLib,  * and sets state variables. * * RETURNED:    	noErr or error code of failure. ***********************************************************************/Err WWWOpen(	void){	Err anErr;		MemSet( &wwwInstance, sizeof( wwwInstance ),  0 );// load prefs	WWWGetPrefs();	// Initialize the INetLib	wwwInstance.conType = wwwConnectionINetLib;	anErr = INetStart( );	return anErr;}/*********************************************************************** * FUNCTION:    	WWWClose * * DESCRIPTION: Closes the WWW function library. Closes INetLib,  * and tears down state variables. * * RETURNED:    	noErr or error code of failure. ***********************************************************************/Err WWWClose(	void){	Err anErr;	/*	 * As an exercise for the reader:	 * You could extend this function here to support platforms without the InetLib.	 */	anErr =  INetEnd() ;	MemSet( &wwwInstance, sizeof( wwwInstance ),  0 );	return anErr;}	/*********************************************************************** * FUNCTION:    	WWWDisplayConnectionDialogMsg * * DESCRIPTION: 	Display a message on the progress dialog * * RETURNED:    	nothing ***********************************************************************/static void WWWDisplayConnectionDialogMsg(	Char *		msg){	RectangleType r = { DIALOG_MSG_X, DIALOG_MSG_Y, DIALOG_WIN_X - DIALOG_MSG_X, 12 };		WinEraseRectangle( &r, 0 );	WinDrawChars ( msg, StrLen ( msg ),  DIALOG_MSG_X, DIALOG_MSG_Y );}/*********************************************************************** * FUNCTION:    	WWWTimeToDrawIcon * * DESCRIPTION: 	Checks to see if it's time to draw another animated icon. *		It's time if ticksPerIcon ticks have passed since the last drawing. * * RETURNED:    	true if it's time to draw another icon ***********************************************************************/static Boolean 	WWWTimeToDrawIcon(	void){	Boolean	update = false;	UInt32 nowTicks = TimGetTicks ();// Check to see if ticksPerIcon have passed		if ( nowTicks - wwwInstance.progressThenTicks > ticksPerIcon )	{	// Yes, reset the ticks count for the next calculation and		update = true;		wwwInstance.progressThenTicks = nowTicks;	}	return ( update );}/*********************************************************************** * FUNCTION:    	WWWRotateDialogIcon * * DESCRIPTION: 	Draw the next phase of an animated icon if it's time. * * RETURNED:    	Nothing ***********************************************************************/static void 		WWWRotateDialogIcon(	Int16			direction	// (in) 1 = forwards, -1 = backwards){	UInt16			iconIDs [ NUM_ICONS ] = 						{ _WWWGlass1Bitmap, _WWWGlass2Bitmap, _WWWGlass3Bitmap, _WWWGlass4Bitmap };	static Int16	iconCnt;	MemHandle	resH;		if ( WWWTimeToDrawIcon ())	{	// Adjust the icon # and correct for boundaries		iconCnt = iconCnt + direction;		if ( iconCnt > NUM_ICONS - 1 )		{			iconCnt = 0;		}		if ( iconCnt < 0 )		{			iconCnt = NUM_ICONS - 1;		}// Get the proper icon for display		resH = DmGetResource ( bitmapRsc, iconIDs [ iconCnt ] );		if ( resH )		{			BitmapPtr		resP = MemHandleLock ( resH );			if ( resP )			{			// Display the icon				WinDrawBitmap ( resP, DIALOG_PIC_X, DIALOG_PIC_Y );				MemPtrUnlock ( resP );			}			DmReleaseResource ( resH );		}	}}/*********************************************************************** * FUNCTION:    	WWWGetEvent * * DESCRIPTION: 	Get the next event in the Q. * * RETURNED:    	 ***********************************************************************/static void WWWGetEvent	(	EventType *eventP, 	// (in) where to put event (out) event	Int32 timeout		// how long to wait for event){	if ( wwwInstance.conType == wwwConnectionINetLib )	{		INGetEvent( eventP, timeout );	}	else	{		EvtGetEvent( eventP, timeout );	}	}/*********************************************************************** * FUNCTION:    	WWWConnectionEventHandler * * DESCRIPTION: 	Handle events for the progress dialog. * * RETURNED:    	true if canceled ***********************************************************************/static Boolean WWWConnectionEventHandler	// (out) User canceled.(){	INetEventType 	event;	EventType *theEventP = (EventType *)&event;	Boolean			canceled = false;	ControlPtr		ctlP = ( ControlPtr ) GetObjectPtr ( _WWWConnectionCancelButton );	// Check for low and high-level events.	WWWGetEvent ( theEventP, wwwContentEvtWaitTicks ); 		// If the cancel button has been clicked, let the caller know.	if ( theEventP->eType == ctlSelectEvent  && 		theEventP->data.ctlSelect.controlID == ctlP->id )	{		WinInvertRectangle ( &ctlP->bounds, 4 );		canceled = true;	}		// Let the network layer handle the event if necessary	if ( !canceled )		if ( wwwInstance.conType == wwwConnectionINetLib )			canceled = INetConnectionEventHandler( &event );		// Nope, let the system or the control event manager deal with it.	if ( !canceled )		if ( !SysHandleEvent ( theEventP ))			CtlHandleEvent ( ctlP, theEventP );					return ( canceled );}/*********************************************************************** * FUNCTION:    	WWWShowIndicator * * DESCRIPTION: 	Shows the wireless indicator * * RETURNED:    	noErr on success, or error code. * ***********************************************************************/void WWWShowIndicator(	void){	if ( wwwInstance.conType == wwwConnectionINetLib )	{		INetShowIndicator();	}	else	{		// Support other network layers here.	}  }/*********************************************************************** * FUNCTION:    	WWWHideIndicator * * DESCRIPTION: 	Shows the wireless indicator * * RETURNED:    	noErr on success, or error code. * ***********************************************************************/void WWWHideIndicator(	void){	if ( wwwInstance.conType == wwwConnectionINetLib )	{		INetHideIndicator();	}	else	{		// Support other network layers here.	}}/*********************************************************************** * FUNCTION:    	WWWUrlClose * * DESCRIPTION: 	Opens socket & stuff for getting a URL. * * RETURNED:    	noErr on success, or error code. * ***********************************************************************/static Err WWWUrlClose	// (out) How did it go?(	void){	/*	 * As an exercise for the reader:	 * You could extend the open function here to support platforms without the InetLib.	 */	 return INetEndTransaction();;}/*********************************************************************** * FUNCTION:    	WWWUrlOpen * * DESCRIPTION: 	Opens socket & stuff for getting a URL. * * RETURNED:    	noErr on success, or error code. * ***********************************************************************/static Err WWWUrlOpen	// (out) How did it go?(	Char *inUrlP				// (in) URL to open){	Err anErr;	anErr = INetGo(inUrlP, NULL, -1 );    return anErr;}/*********************************************************************** * FUNCTION:    	WWWSubTask * * DESCRIPTION: 	Does any and all network I/O during a fetch. *					Must keep its own state and such in wwwInstance * * RETURNED:    	state of connection * ***********************************************************************/static Err WWWSubTask			// (out) error if there's an error;(	void){	if ( wwwInstance.conType == wwwConnectionINetLib )	{		return INetSubTask();	}	else	{		return inetErrParamsInvalid;	}	}static Boolean WWWAntennaDialogFormHandler(	EventPtr eventP		// Pointer to an EventType that contains the event to handle){    Boolean 	handled = false;    FormPtr		frmP = FrmGetActiveForm ();	switch ( eventP->eType ) 	{		case ctlSelectEvent:			FrmEraseForm ( frmP );			FrmDeleteForm ( frmP );			FrmSetActiveForm ( wwwInstance.saveFrmP );					handled = true;			break;						case keyDownEvent:			if ( eventP->data.keyDown.chr == vchrHardAntenna )			{				wwwInstance.socketStatus = wwwStatusCompleted;				FrmEraseForm ( frmP );				FrmDeleteForm ( frmP );				FrmSetActiveForm ( wwwInstance.saveFrmP );					handled = true;			}			break;	}	if ( !handled )		handled = SysHandleEvent( eventP );		return handled;}/*********************************************************************** * FUNCTION:    	WWWFetch * * DESCRIPTION: 	Fetches the content at the indicated URL and *					returns the contents in the handle. * * RETURNED:    	Handle with contents at URL;  * ***********************************************************************/MemHandle WWWFetch			// (out) results(	CharPtr urlP,		// (in) URL to fetch	Err *errP			// (in) Where to put error)						// (out) error code{	Boolean	canceled = false;	FormPtr saveFrmP, frmP;	Int16 dir = FORWARDS;	MemHandle result = NULL;		*errP = inetErrParamsInvalid;// Validate arguments.	if ( urlP == NULL )		return result;		// Open the network	*errP = WWWOpen();		if ( *errP )		return result;		*errP = memErrNotEnoughSpace;// Set aside the handle and set up for reading.	result = wwwInstance.contentHandle = MemHandleNew( 2 * MAX_RESPONSE_SIZE );	wwwInstance.contentSz = 0;	if ( !wwwInstance.contentHandle )		return NULL;	*errP = WWWUrlOpen( urlP );	if ( *errP )	{		MemHandleFree( wwwInstance.contentHandle );		WWWClose();		return NULL;	}// Display the progress dialog	saveFrmP = FrmGetActiveForm ( );	wwwInstance.saveFrmP =  frmP = FrmInitForm ( _WWWConnectionForm );	FrmDrawForm ( frmP );	FrmSetActiveForm ( frmP );	WWWShowIndicator( );// Read from the socket as we get events from the network layer.		while ( !canceled && ! WWWConnectionEventHandler () )	{// Display the scanning message and icon		WWWRotateDialogIcon ( dir );						// Give cycles to the WWW subtask		*errP = WWWSubTask( );		// If there's an error, notify the user.		if ( *errP != noErr )		{			canceled = true;			break;		}// resize the handle if we're running out of space.		if ( MemHandleSize( wwwInstance.contentHandle ) 			< wwwInstance.contentSz + MAX_RESPONSE_SIZE )		{			*errP = MemHandleResize( wwwInstance.contentHandle,  				wwwInstance.contentSz + 2 * MAX_RESPONSE_SIZE );			if ( *errP != noErr)			{				canceled = true;				break;			}		}				if ( wwwInstance.socketStatus == wwwStatusCompleted || 			wwwInstance.socketStatus == wwwStatusError )			canceled = true;		} // while	// Return a result only if there's no error.	if ( *errP == noErr )		MemHandleResize( wwwInstance.contentHandle, wwwInstance.contentSz );	else	{		MemHandleFree( wwwInstance.contentHandle );			wwwInstance.contentHandle = NULL;		result = NULL;	}		if ( wwwInstance.contentSz == 0 )	{		// Hmm. We got nothing. Spooky.		MemHandleFree( wwwInstance.contentHandle );			wwwInstance.contentHandle = NULL;		result = NULL;			} // Close down the network	WWWHideIndicator( );	WWWUrlClose( );	WWWClose();// Done, remove the progress dialog and restore the main form	FrmEraseForm ( frmP );	FrmDeleteForm ( frmP );	FrmSetActiveForm ( saveFrmP );	// If there's an error, inform the user.	if ( *errP != noErr )	{		Char msg[64];		StrPrintF( msg, "%d", *errP );		FrmCustomAlert ( _WWWErrorAlert, msg, "", " " );	}		return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -