#include "xfiledlg.h"
#include "xwindow.h"

#include <stdlib.h>


/*@ 
@class XFileDialog
@parent XSystemDialog
@type overview
@symbol _
*/


/*@ XFileDialog :: XFileDialog(const XWindow * owner, const char *f, const char *title, const char *fileType, const LONG options)
@group constructors/destructors
@remarks Open the system defined file-dialog
@parameters <t 'ø' c=2>
				øXWindow * theOwner           øowner-window
            øchar * fileMask              øthe file-mask to be displayed (default is <*.*>)
            øchar * theTitle              øtitle of the dialog (default is NULL)
            øchar * filetype              øfile-type to be displayed (default is NULL)
            øLONG options                 øoptions, valid values are:
														<t 'ø' c=2>
                                             øFD_OPEN         øopen-dialog
                                             øFD_CENTER       ødialog is centered
                                             øFD_SAVEAS_      øsaveas-dialog
                                             øFD_MULTIPLESEL  ømultiple file-selection
                                             øFD_HELP         øthe dialog has a help-button. To display help the owner-window must be associated with a help-instance and in th help-file there must be an entry with an id of 267 (res=267)
                                             øFD_MODELESS     øshow modeless
                                             øFD_APPLYBUTTON  øapply-button
                                             øFD_EAS          øuse EAs
                                             øFD_FILTERUNION  øuse filter from string-filter and EAs
															øFD_HELPBUTTON	 øshow a help-button
														</t>
                                         (default is FD_OPEN | FD_CENTER, can be or-ed)
				</t>
*/
XFileDialog :: XFileDialog(const XWindow * owner, const char *f, const char *title, const char *fileType, const LONG options)
{
	FILEDLG fild;

	fileName = NULL;
	memset(&fild, 0, sizeof(FILEDLG));
	fild.cbSize = sizeof(FILEDLG);
	fild.fl = options;
	fild.pszTitle = (PSZ) title;
	fild.pszIType = (PSZ) fileType;


	strcpy(fild.szFullFile, f);

	WinFileDlg(HWND_DESKTOP, owner->GetHandle(), &fild);
	pap = fild.papszFQFilename;
	numbers = fild.ulFQFCount;
	command = fild.lReturn;
	fileName = (char *) malloc(strlen(fild.szFullFile) + 1);
	strcpy(fileName, fild.szFullFile);
}


/*@ XFileDialog::GetFileName()
@group misc
@remarks If the file-dialog is proceeded you can ask for the
selected filename. If FD_MULTIPLESEL is specified, at first ask with GetFileCount()
for the number of files selected.
@parameters XString * buffer                the buffer which will contain the filename
            SHORT index                     zero-based index of filename to get
                                            (default is 0)
*/



XFileDialog :: ~XFileDialog()
{
	WinFreeFileDlgList(pap);
	free(fileName);
}

