/*	GBScalingDialog()

	GBScalingDialog is called when user clicks the Scaling button in the
	GBLoadWave dialog.
	
	offsetPtr and multiplierPtr are used as both inputs and outputs.
	If the user cancels, they are not changed.
	
	Returns 0 if user clicks OK, -1 if user clicks cancel, or an error code.
*/
int
GBScalingDialog(double* offsetPtr, double* multiplierPtr)
{
	DialogStorage ds;
	int result;
	
	if (result = InitDialogStorage(&ds, offsetPtr, multiplierPtr))
		return result;

	result = (int)DialogBoxParam(XOPModule(), MAKEINTRESOURCE(DIALOG_TEMPLATE_ID), IgorClientHWND(), DialogProc, (LPARAM)&ds);

	DisposeDialogStorage(&ds);

	if (result == OK_BUTTON)
		return 0;
	return -1;					// Cancel.
}
Exemple #2
0
/*	XOPSaveFileDialog(prompt, fileFilterStr, fileIndexPtr, initialDir, defaultExtensionStr, filePath)

	Displays the save file dialog.
	
	Returns 0 if the user provides a file name or -1 if the user cancels or another
	non-zero number in the event of an error.
	
	Returns the full path to the file via filePath. filePath is both an input and an
	output as explained below. In the event of a cancel, filePath is unmodified.
	filePath is a Macintosh HFS path on Macintosh and a Windows path on Windows.
	
	On Windows, prompt sets the dialog caption. On Macintosh, it sets a prompt
	string in the dialog.
	
	fileFilterStr is now used to control the contents of the Format popup menu
	in the Save File dialog.
	
	On Macintosh, if there is only one format in which you can save the file,
	pass "" for fileFilterStr. This will cause the Format menu to be hidden.
	If you can save the file in more than one format, pass a string like this:
		"Plain Text:TEXT:.txt;Igor Text:IGTX:.itx;"
		
	This would give you a Format menu like this:
		Plain Text
		Igor Text
	
	fileFilterStr on Macintosh

		fileFilterStr consists of sections terminated by a semicolon. For example,
		here is one section:
			"Data Files:TEXT:.dat;"
			
		Each section consists of three components: a menu item string (e.g., Data Files)
		to be displayed in the Format popup menu, a Macintosh file type (e.g., TEXT),
		and an extension (e.g., .dat).

		At present, only the menu item string and extension are used.

		The Macintosh file type is currently not used. If there is no meaningful Macintosh
		file type, leave the file type component empty.

		If there is no meaningful extension, leave the extension component empty.

	fileFilterStr on Windows
	
		On Windows, fileFilterStr identifies the types of files to display and the types
		of files that can be created. It is constructed as for the lpstrFilter
		field of the OPENFILENAME structure for the Windows GetSaveFileName routine.
		For example, to allow the user to save as a text file or as an Igor Text file,
		use "Text Files (*.txt)\0*.txt\0Igor Text Files (*.itx)\0*.itx\0\0". Note that
		the string ends with two null characters (\0\0). If fileFilterStr is "", this
		behaves the same as "Text Files (*.txt)\0*.txt\0\0". 

	fileIndexPtr it is ignored if it is NULL. If it is not NULL, then *fileIndexPtr
	is the one-based index of the file type filter to be initially selected.
	In the example given above, setting *fileIndexPtr to 2 would select the Igor
	Text file type on entry to the dialog. On exit from the dialog, *fileIndexPtr
	is set to the index of the file type string that the user last selected.
	
	initialDir can be "" or it can point to a full path to a directory. It
	determines the directory that will be initially displayed in the save file
	dialog. If "", the directory will be the last directory that was seen in the
	open or save file dialogs. If initialDir points to a valid path to a directory,
	then this directory will be initially displayed in the dialog. On Macintosh,
	initialDir is a Macintosh HFS path. On Windows, it is a Windows path. 
	
	defaultExtensionStr points to the extension to be added to the
	file name if the user does not enter an extension. For example, pass "txt"
	to have ".txt" appended if the user does not enter an extension. If you don't
	want any extension to be added in this case, pass NULL.
	
	Prior to XOP Toolkit 6.00, defaultExtensionStr was ignored on Macintosh.
	
	Returns via filePath the full path to the file that the user chose
	or "" if the user cancelled. The path is a Macintosh HFS path on Macintosh
	and a Windows path on Windows. filePath must point to a buffer of
	at least MAX_PATH_LEN+1 bytes.
	
	On Windows and Macintosh, the initial value of filePath sets the initial contents of
	the File Name edit control in the save file dialog. The following values
	are valid:
		""									If there is no initial file name
		a file name
		a full Mac or Win path to a file
	
	In the event of an error other than a cancel, XOPSaveFileDialog displays
	an error dialog. This should never or rarely happen.
	
	WINDOWS NOTES
	
	The dialog will appear in the upper left corner of the screen. This is
	because Windows provides no straight-forward way to set the position of
	the dialog.
	
	Thread Safety: XOPSaveFileDialog is not thread-safe.
*/
int
XOPSaveFileDialog(
	const char* prompt,
	const char* fileFilterStr, int* fileIndexPtr,
	const char* initialDir,
	const char* defaultExtensionStr,
	char filePath[MAX_PATH_LEN+1])
{
	OPENFILENAME ofn;
	char filePath2[MAX_PATH_LEN+1];
	char initialDir2[MAX_PATH_LEN+1];
	
	if (!CheckRunningInMainThread("XOPSaveFileDialog"))
		return NOT_IN_THREADSAFE;
	
	if (*fileFilterStr == 0)
		fileFilterStr = "Text Files (*.txt)\0*.txt\0\0";
		
	if (*initialDir == 0) {
		GetStandardFileWinPath(initialDir2);	// Get Igor's save file dialog directory.
	}
	else {
		strcpy(initialDir2, initialDir);
		SetStandardFileWinPath(initialDir);		// Sets initial directory for next save file dialog. This will be overridden below, but not if the user cancels.
	}
		
	/*	HR, 040928, XOP Toolkit 5.04
		Previously this copied filePath to filePath2. This was correct because the filePath parameter
		was supposed to be either "" or just the proposed file name. However, I incorrectly passed
		a full path for the filePath parameter in all of the sample XOPs. This mistake undoubtedly
		leaked into users' XOPs. Therefore I now allow filePath to be either "", just a file name,
		or a full path.
	*/
	// strcpy(filePath2, filePath);				// HR, 010815: Previously filePath2 was set to "" which prevented the File Name item in the Windows Open File dialog from being preset as the comment above says it should be.
	GetLeafName(filePath, filePath2);

	MemClear(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = IgorClientHWND();
	ofn.lpstrFile = filePath2;
	ofn.nMaxFile = MAX_PATH_LEN+1;
	ofn.lpstrFilter = fileFilterStr;
	ofn.nFilterIndex = fileIndexPtr==NULL ? 1 : *fileIndexPtr;
	ofn.lpstrDefExt = defaultExtensionStr;
	ofn.lpstrTitle = prompt;
	ofn.lpstrFileTitle = NULL;
	ofn.lpstrInitialDir = initialDir2;
	ofn.lpfnHook = OpenOrSaveFileNameHook;		// Needed to set position of the dialog. Otherwise, it is in top/left corner of screen.
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
	ofn.Flags |= OFN_EXPLORER;
	ofn.Flags |= OFN_ENABLEHOOK;				// Needed so that hook will be called.
	ofn.Flags |= OFN_ENABLESIZING;				// HR, 090121: Added this to get resizeable dialog.
	ofn.Flags |= OFN_HIDEREADONLY;
	ofn.Flags |= OFN_NOCHANGEDIR;				// Changing the current directory causes problems. e.g., if set to floppy disk and the floppy is removed, the system slows down.

	if (GetSaveFileName(&ofn) == 0) {
		int err;
		err = CommDlgExtendedError();			// err will be zero if cancel.
		if (err == 0)
			return -1;

		// We got an error other than cancel.
		*filePath2 = 0;							// HR, 021114: Clear possible bad fields
		*initialDir2 = 0;						// and try again.
		if (GetSaveFileName(&ofn) != 0) {		// Succeeded this time?
			err = 0;
		}
		else {
			if (CommDlgExtendedError() == 0)
				return -1;						// User canceled.
			
			// Report the original error.
			err = WindowsErrorToIgorError(err);
			IgorError("XOPSaveFileDialog", err);
			return err;
		}
	}
	
	if (fileIndexPtr != NULL)
		*fileIndexPtr = ofn.nFilterIndex;
	
	strcpy(filePath, filePath2);
	SetStandardFileWinPath(filePath);			// Update Igor's open file dialog directory.

	return 0;
}