Exemple #1
0
bool PickingWindow::OnMouseClick(MouseButton button, MouseState state, int x,
    int y, unsigned int modifiers)
{
    if (!Window3::OnMouseClick(button, state, x, y, modifiers))
    {
        if (button == MOUSE_RIGHT && state == MOUSE_DOWN)
        {
            DoPick(x, mYSize - 1 - y);
        }
    }
    return true;
}
//-------------------------------------------------------------------------------
//
//	PluginMain / main
//
//	All calls to the plug-in module come through this routine.
//	It must be placed first in the resource.  To achieve this,
//	most development systems require this be the first routine
//	in the source.
//
//	The entrypoint will be "pascal void" for Macintosh,
//	"void" for Windows.
//
//	Inputs:
//		const int16 selector				Host provides selector indicating
//											what command to do.
//
//		PIPickerParams *pickerParamBlock	Host provides pointer to parameter
//											block containing pertinent data
//											and callbacks from the host.
//											See PIPicker.h.
//
//	Outputs:
//		PIPickerParams * pickerParamBlock	Host provides pointer to parameter
//											block. Use it to pass pertinent
//											data to and from the host.
//											See PIPicker.h.
//
//		intptr_t *data						Use this to store a handle or pointer to our
//											global parameters structure, which
//											is maintained by the host between
//											calls to the plug-in.
//
//		int16 *result						Return error result or noErr.  Some
//											errors are handled by the host, some
//											are silent, and some you must handle.
//											See PIGeneral.h.
//
//-------------------------------------------------------------------------------
DLLExport MACPASCAL void PluginMain (const int16 selector,
						             PIPickerParams * pickerParamBlock,
						             intptr_t * data,
						             int16 * result)
{

	try { 

	//---------------------------------------------------------------------------
	//	(1) Check for about box request.
	//
	// 	The about box is a special request; the parameter block is not filled
	// 	out, none of the callbacks or standard data is available.  Instead,
	// 	the parameter block points to an AboutRecord.
	//---------------------------------------------------------------------------

	if (selector == pickerSelectorAbout)
	{
		sSPBasic = ((AboutRecord*)pickerParamBlock)->sSPBasic;
		DoAbout((AboutRecordPtr)pickerParamBlock);
	}
	else
	{ // do the rest of the process as normal:

		sSPBasic = ((PIPickerParams*)pickerParamBlock)->sSPBasic;

		Ptr globalPtr = NULL;		// Pointer for global structure
		GPtr globals = NULL; 		// actual globals

		//-----------------------------------------------------------------------
		//	(2) Allocate and initalize globals.
		//
		// 	AllocateGlobals requires the pointer to result, the pointer to the
		// 	parameter block, a pointer to the handle procs, the size of our local
		// 	"Globals" structure, a pointer to the long *data, a Function
		// 	Proc (FProcP) to the InitGlobals routine.  It automatically sets-up,
		// 	initializes the globals (if necessary), results result to 0, and
		// 	returns with a valid pointer to the locked globals handle or NULL.
		//-----------------------------------------------------------------------
		
		globalPtr = AllocateGlobals (result,
									 pickerParamBlock,
									 pickerParamBlock->handleProcs,
									 sizeof(Globals),
						 			 data,
						 			 InitGlobals);
		
		if (globalPtr == NULL)
		{ // Something bad happened if we couldn't allocate our pointer.
		  // Fortunately, everything's already been cleaned up,
		  // so all we have to do is report an error.
		  
		  *result = memFullErr;
		  return;
		}
		
		// Get our "globals" variable assigned as a Global Pointer struct with the
		// data we've returned:
		globals = (GPtr)globalPtr;

		//-----------------------------------------------------------------------
		//	(3) Run the plug in's main routine.
		//
		//-----------------------------------------------------------------------	

		DoPick(globals);
					
		//-----------------------------------------------------------------------
		//	(4) Unlock data, and exit resource.
		//
		//	Result is automatically returned in *result, which is
		//	pointed to by gResult.
		//-----------------------------------------------------------------------	
		
		// unlock handle pointing to parameter block and data so it can move
		// if memory gets shuffled:
		if ((Handle)*data != NULL)
			PIUnlockHandle((Handle)*data);
	
	} // about selector special		
	
	} // end try

	catch (...)
	{
		if (NULL != result)
			*result = -1;
	}

} // end PluginMain