コード例 #1
0
bool GameOutFile::open() {
    char filename[MAX_PATH];
    OPENFILENAME ofn;
    InitializeOPENFILENAME( ofn, filename );
    ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
    ofn.lpstrTitle = "Save As";
    if( GetSaveFileName(&ofn) ) {
        hFile = CreateFile(filename,               // File to open
                           GENERIC_WRITE,          // Open for writing
                           0,                      // Do not share
                           NULL,                   // Default security
                           CREATE_ALWAYS,          // Overwrite existing
                           FILE_ATTRIBUTE_NORMAL,  // Normal file
                           NULL);                  // No attribute template
        doAfterOpen();
        return true;
    } else {
        DWORD err = CommDlgExtendedError();
        hFile = 0;
        return false;
    }
}
コード例 #2
0
bool GameInFile::open() {
    char filename[MAX_PATH];
    OPENFILENAME ofn;
    InitializeOPENFILENAME( ofn, filename );
    ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
    ofn.lpstrTitle = "Open File";
    if( GetOpenFileName(&ofn) ) {
        hFile = CreateFile(filename,          // File to open
                           GENERIC_READ,          // Open for reading
                           FILE_SHARE_READ,       // Share for reading
                           NULL,                  // Default security
                           OPEN_EXISTING,         // Existing file only
                           FILE_ATTRIBUTE_NORMAL, // Normal file
                           NULL);                 // No attribute template
        doAfterOpen();
        return true;
    } else {
        DWORD err = CommDlgExtendedError();
        hFile = 0;
        return false;
    }
}
コード例 #3
0
/*
 * OpenImage - Get the filename of the file to open.  Depending on the
 *              extension set the type (.ico, .bmp, .cur) and call the
 *              appropriate function to open it.
 */
int OpenImage( HANDLE hDrop )
{
    char                fname[ _MAX_PATH ];
    int                 rv  = FALSE;

    if (NULL==hDrop) {
        /*
         * Not doing a drag-drop
         */
        if (!getOpenFName( &fname )) {
            if ( CommDlgExtendedError() == FNERR_INVALIDFILENAME ) {
                WImgEditError( WIE_ERR_BAD_FILENAME, fname );
                return( FALSE );
            }
            return( FALSE );
        }
        rv = ReallyOpenImage(fname);
        
    } else {
        /*
         * hDrop is only ever !NULL when we're dealing with a WM_DROPFILES
         * message, and that only happens with __NT__
         */
#ifdef __NT__
        int     nFiles = DragQueryFile(hDrop,0xFFFFFFFF,NULL,0),i;
        
        for(i=0,rv=TRUE; rv && i<nFiles; i++) {
            DragQueryFile(hDrop,i,fname,_MAX_PATH-1);
            imgType = getImageTypeFromFilename(fname);
            rv = ReallyOpenImage(fname);
        }
#endif
    }
    
    if (rv)
        SetupMenuAfterOpen();
    
    return rv;
} /* OpenImage */
コード例 #4
0
ファイル: w32ans.cpp プロジェクト: alilloyd/livecode
// MW-2005-05-15: Updated for new answer command restructuring
bool MCA_color(MCStringRef p_title, MCColor p_initial_color, bool p_as_sheet, bool& r_chosen, MCColor& r_chosen_color)
{
	CHOOSECOLORW chooseclr ;

	memset(&chooseclr, 0, sizeof(CHOOSECOLORW));
	chooseclr.lStructSize = sizeof (CHOOSECOLORW);
	chooseclr.lpCustColors = (LPDWORD)s_colordialogcolors;

	Window t_parent_window;
	t_parent_window = MCModeGetParentWindow();
	chooseclr.hwndOwner = t_parent_window != NULL ? (HWND)t_parent_window -> handle . window : NULL;

	chooseclr.Flags = CC_RGBINIT;
	chooseclr.rgbResult = RGB(p_initial_color.red >> 8, p_initial_color.green >> 8,
	                          p_initial_color.blue >> 8);

	bool t_success = true;
	if (!ChooseColorW(&chooseclr))
	{
		DWORD err = CommDlgExtendedError();
		r_chosen = false;
	}
	else
	{
		r_chosen = true;
		r_chosen_color.red = GetRValue(chooseclr.rgbResult);
		r_chosen_color.red |= r_chosen_color.red << 8;
		r_chosen_color.green = GetGValue(chooseclr.rgbResult);
		r_chosen_color.green |= r_chosen_color.green << 8;
		r_chosen_color.blue = GetBValue(chooseclr.rgbResult);
		r_chosen_color.blue |= r_chosen_color.blue << 8;
	}

	//  SMR 1880 clear shift and button state
	waitonbutton();

	return t_success;
}
コード例 #5
0
std::string PlayerFileDialogServiceWin::saveFile(const std::string &title,
                                                 const std::string &path) const
{
    std::u16string u16title;
    cocos2d::StringUtils::UTF8ToUTF16(title, u16title);

    WCHAR buff[MAX_PATH + 1] = {0};
    if (path.length() > 0)
    {
        std::u16string u16filename;
        cocos2d::StringUtils::UTF8ToUTF16(path, u16filename);
        wcscpy_s(buff, (WCHAR*)u16filename.c_str());
    }

    OPENFILENAME ofn = {0};
    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner = _hwnd;
    ofn.lpstrFilter = L"All Files (*.*)\0*.*\0";
    ofn.lpstrTitle = (LPCTSTR)u16title.c_str();
    ofn.Flags = OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES;
    ofn.lpstrFile = buff;
    ofn.nMaxFile = MAX_PATH;

    std::string result;
    if (!GetSaveFileName(&ofn))
    {
        // user cancel dialog, GetSaveFileName() will return FALSE
        DWORD err = CommDlgExtendedError();
        if (err)
        {
            CCLOG("PlayerFileDialogServiceWin::saveFile() - failed, title (%s),  error code = %u", title.c_str(), err);
        }
        return result;
    }

    cocos2d::StringUtils::UTF16ToUTF8((char16_t*)buff, result);
    return result;
}
コード例 #6
0
ファイル: PECheckSumCalcDlg.cpp プロジェクト: libprot/trunk
void CPECheckSumCalcDlg::OnBnOpenDialogClicked()
{
    // simple open dialog to get file name
    OPENFILENAME openFileName;
    ZeroMemory(&openFileName, sizeof(openFileName));
    
    TCHAR strFileName[MAX_PATH];
    ZeroMemory(strFileName, MAX_PATH);
 
    openFileName.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
    openFileName.nMaxFile = MAX_PATH;
    openFileName.Flags = OFN_EXPLORER;
    openFileName.lpstrFile = strFileName;
    openFileName.lpstrFilter =  _T("Executable files\0*.exe;*.dll\0");
    openFileName.lpstrDefExt = _T("");
    openFileName.lpstrTitle = _T("Select executable file");
    openFileName.lStructSize = sizeof(OPENFILENAMEA);

    GetOpenFileName(&openFileName);
    if ((int)CommDlgExtendedError() == 0) {
        GetDlgItem(IDC_FILEPATHEDIT)->SetWindowText(strFileName);
    }
}
コード例 #7
0
ファイル: gisnap.cpp プロジェクト: CoreSecurity/Agafi
bool DumpProcess(DWORD pid)
{
	gMemSnap = new MemorySnapshot;
	char filename[1024];
	OPENFILENAME ofln;

	memset(&filename, 0, sizeof(filename));
	memset(&ofln, 0, sizeof(OPENFILENAME));
	ofln.lStructSize = sizeof(OPENFILENAME);
	ofln.hwndOwner = gHWND;
	ofln.lpstrFile = filename;
	ofln.nMaxFile = sizeof(filename);
	ofln.lpstrFilter = "snap\0*.snap\0All\0*.*\0";
	ofln.nFilterIndex = 1;
	ofln.lpstrFileTitle = NULL;
	ofln.nMaxFileTitle = 0;
	ofln.lpstrInitialDir = NULL;
	ofln.lpstrDefExt = ".snap";
	ofln.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT;
	GetSaveFileName(&ofln);
	CommDlgExtendedError();
	return gMemSnap->Dump(pid, filename);
}
コード例 #8
0
ファイル: printer.c プロジェクト: Bgods/r-source
static HDC chooseprinter(void)
{
    PRINTDLG pd;
    HDC dc;
    DWORD rc;
    char cwd[MAX_PATH];

    GetCurrentDirectory(MAX_PATH,cwd);

    pd.lStructSize = sizeof( PRINTDLG );
    pd.hwndOwner = NULL;
    pd.hDevMode = (HANDLE)NULL;
    pd.hDevNames = (HANDLE)NULL;
    pd.Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS |
	PD_USEDEVMODECOPIES;
    pd.nFromPage = 0;
    pd.nToPage = 0;
    pd.nMinPage = 0;
    pd.nMaxPage = 0;
    pd.nCopies = 1;
    pd.hInstance = (HINSTANCE)NULL;
    pd.lCustData = (LPARAM)0;
    pd.lpfnPrintHook = 0;
    pd.lpfnSetupHook = 0;
    pd.lpPrintTemplateName = (LPCSTR) 0;
    pd.lpSetupTemplateName = (LPCSTR) 0;
    pd.hPrintTemplate = (HGLOBAL)0;
    pd.hSetupTemplate = (HGLOBAL)0;

    dc = PrintDlg( &pd ) ? pd.hDC : NULL;
    SetCurrentDirectory(cwd);
    if (!dc) {
	rc = CommDlgExtendedError(); /* 0 means user cancelled */
	if (rc) R_ShowMessage(_("Unable to choose printer"));
    }
    return dc;
}
コード例 #9
0
void CMyRichEditView::OnPageSetupDlg()
{
   CPageSetupDialog psd(PSD_INTHOUSANDTHSOFINCHES | PSD_MARGINS | 
      PSD_ENABLEPAGEPAINTHOOK, this);

   // Initialize margins
   psd.m_psd.rtMargin.top = 1000;
   psd.m_psd.rtMargin.left = 1250;
   psd.m_psd.rtMargin.right = 1250;
   psd.m_psd.rtMargin.bottom = 1000;
   psd.m_psd.lpfnPagePaintHook = (LPPAGEPAINTHOOK)PaintHook;

   if(IDOK == psd.DoModal()) 
   {
      // Propagate changes to the app
      AfxGetApp()->SelectPrinter(psd.m_psd.hDevNames, psd.m_psd.hDevMode);
   }
   else
   {
      TRACE(_T("CommDlgExtendedError returned error %d from ")
         _T("CPageSetupDialog::DoModal().\n"),
         (int)CommDlgExtendedError());
   }
}
コード例 #10
0
ファイル: export.c プロジェクト: Nevermore2015/reactos
VOID ExportFile(PMAIN_WND_INFO Info)
{
    OPENFILENAME ofn;
    TCHAR szFileName[MAX_PATH] = _T("");

    ZeroMemory(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = Info->hMainWnd;
    ofn.lpstrFilter = _T("Text (Tab Delimited)(*.txt)\0*.txt\0Text (Comma Delimited)(*.csv)\0*.csv\0");
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.lpstrDefExt = _T("txt");
    ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

    if(GetSaveFileName(&ofn))
    {
        if (SaveServicesToFile(Info, szFileName))
            return;
    }

    if (CommDlgExtendedError() != CDERR_GENERALCODES)
        MessageBox(NULL, _T("Export to file failed"), NULL, 0);
}
コード例 #11
0
ファイル: WinGUI.cpp プロジェクト: Fliper12/darkbasicpro
void CallFileRequester ( void )
{
	// Aquire HWND from core
	MaintainGlobalHWND();

	// Create space for return filename
	char pFile[2048];

	// Create special dialogue control
	OPENFILENAME ofn;
	memset ( &ofn, 0, sizeof(OPENFILENAME) );
	ofn.lStructSize			= sizeof(OPENFILENAME);
//	ofn.hwndOwner			= hwndOriginalParent;
//	ofn.hInstance			= (HINSTANCE) GetWindowLong(hwndOriginalParent, GWL_HINSTANCE),

	ofn.Flags			= 0;
	ofn.lpstrFilter		= "All Files (*.*)|*.*|Text Files (*.txt)|*.txt||";

	ofn.lpstrFile			= pFile;
	ofn.nMaxFile			= sizeof(pFile);

	int iResult = GetOpenFileName ( &ofn );
	DWORD dwErr = CommDlgExtendedError();
}
コード例 #12
0
ファイル: MixereView.cpp プロジェクト: victimofleisure/Mixere
void CMixereView::LoadAudio()
{
	CFileDialog	fd(TRUE, ".wav", NULL,
		OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		CChannel::GetFileFilter());
	// prepare OPENFILENAME struct for multiple select
	CString	Buffer;
	const	BUFSIZE = 0x7fff;
	LPTSTR	FileBuf = Buffer.GetBufferSetLength(BUFSIZE);
	ZeroMemory(FileBuf, BUFSIZE);
	fd.m_ofn.lpstrFile = FileBuf;
	fd.m_ofn.nMaxFile = BUFSIZE;
	fd.m_ofn.nFileOffset = 0;
	CString	Title(LDS(LOAD_AUDIO));
	fd.m_ofn.lpstrTitle = Title;
	// display the dialog
	int	retc = fd.DoModal();
	int	Pos = m_CurPos;
	if (retc == IDOK) {
		// iterate through the results
		CStringArray	ErrPath;
		POSITION	FilePos;
        FilePos = fd.GetStartPosition();
        while (FilePos != NULL) {
			CString	Path = fd.GetNextPathName(FilePos);
			if (!LoadAudio(Pos++, Path))
				AddStringUnique(ErrPath, Path);
		}
		// if audio files couldn't be opened, display error message
		if (ErrPath.GetSize())
			MsgBoxStrList(LDS(CANT_LOAD_AUDIO), ErrPath);
	} else {
		if (CommDlgExtendedError())
			AfxMessageBox(LDS(FILE_DIALOG_ERROR));
	}
}
コード例 #13
0
ファイル: FileSystem.cpp プロジェクト: Frankie-666/xray-16
bool EFS_Utils::GetSaveName(LPCSTR initial, string_path& buffer, LPCSTR offset, int start_flt_ext)
{
    // unsigned int dwVersion = GetVersion();
    // unsigned int dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));

    FS_Path& P = *FS.get_path(initial);
    string1024 flt;

    LPCSTR def_ext = P.m_DefExt;
    if (false)//&& dwWindowsMajorVersion == 6 )
    {
        if (strstr(P.m_DefExt, "*."))
            def_ext = strstr(P.m_DefExt, "*.") + 2;
    }


    MakeFilter(flt, P.m_FilterCaption ? P.m_FilterCaption : "", def_ext);
    OPENFILENAME ofn;
    Memory.mem_fill(&ofn, 0, sizeof(ofn));
    if (xr_strlen(buffer))
    {
        string_path dr;
        if (!(buffer[0] == '\\' && buffer[1] == '\\'))  // if !network
        {
            _splitpath(buffer, dr, 0, 0, 0);
            if (0 == dr[0]) P._update(buffer, buffer);
        }
    }
    ofn.hwndOwner = GetForegroundWindow();
    ofn.lpstrDefExt = def_ext;
    ofn.lpstrFile = buffer;
    ofn.lpstrFilter = flt;
    ofn.lStructSize = sizeof(ofn);
    ofn.nMaxFile = sizeof(buffer);
    ofn.nFilterIndex = start_flt_ext + 2;
    ofn.lpstrTitle = "Save a File";
    string512 path;
    xr_strcpy(path, (offset&&offset[0]) ? offset : P.m_Path);
    ofn.lpstrInitialDir = path;
    ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR;
    ofn.FlagsEx = OFN_EX_NOPLACESBAR;

    /*
     if ( dwWindowsMajorVersion == 6 )
     {
     ofn.Flags |= OFN_ENABLEHOOK;
     ofn.lpfnHook = OFNHookProcOldStyle;
     }
     */

    bool bRes = !!GetSaveFileName(&ofn);
    if (!bRes)
    {
        u32 err = CommDlgExtendedError();
        switch (err)
        {
        case FNERR_BUFFERTOOSMALL:
            Log("Too many file selected.");
            break;
        }
    }
    strlwr(buffer);
    return bRes;
}
コード例 #14
0
ファイル: FileSystem.cpp プロジェクト: Frankie-666/xray-16
bool EFS_Utils::GetOpenNameInternal(LPCSTR initial, LPSTR buffer, int sz_buf, bool bMulti, LPCSTR offset, int start_flt_ext)
{
    VERIFY(buffer && (sz_buf > 0));
    FS_Path& P = *FS.get_path(initial);
    string1024 flt;
    MakeFilter(flt, P.m_FilterCaption ? P.m_FilterCaption : "", P.m_DefExt);

    OPENFILENAME ofn;
    Memory.mem_fill(&ofn, 0, sizeof(ofn));

    if (xr_strlen(buffer))
    {
        string_path dr;
        if (!(buffer[0] == '\\' && buffer[1] == '\\'))  // if !network
        {
            _splitpath(buffer, dr, 0, 0, 0);

            if (0 == dr[0])
            {
                string_path bb;
                P._update(bb, buffer);
                xr_strcpy(buffer, sz_buf, bb);
            }
        }
    }
    ofn.lStructSize = sizeof(OPENFILENAME);
    ofn.hwndOwner = GetForegroundWindow();
    ofn.lpstrDefExt = P.m_DefExt;
    ofn.lpstrFile = buffer;
    ofn.nMaxFile = sz_buf;
    ofn.lpstrFilter = flt;
    ofn.nFilterIndex = start_flt_ext + 2;
    ofn.lpstrTitle = "Open a File";
    string512 path;
    xr_strcpy(path, (offset&&offset[0]) ? offset : P.m_Path);
    ofn.lpstrInitialDir = path;
    ofn.Flags = OFN_PATHMUSTEXIST |
                OFN_FILEMUSTEXIST |
                OFN_HIDEREADONLY |
                OFN_FILEMUSTEXIST |
                OFN_NOCHANGEDIR |
                (bMulti ? OFN_ALLOWMULTISELECT | OFN_EXPLORER : 0);

    ofn.FlagsEx = OFN_EX_NOPLACESBAR;

    /*
     unsigned int dwVersion = GetVersion();
     unsigned int dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
     if ( dwWindowsMajorVersion == 6 )
     {
     ofn.Flags |= OFN_ENABLEHOOK;
     ofn.lpfnHook = OFNHookProcOldStyle;
     }
     */

    bool bRes = !!GetOpenFileName(&ofn);
    if (!bRes)
    {
        u32 err = CommDlgExtendedError();
        switch (err)
        {
        case FNERR_BUFFERTOOSMALL:
            Log("Too many files selected.");
            break;
        }
    }
    if (bRes && bMulti)
    {
        Log("buff=", buffer);
        int cnt = _GetItemCount(buffer, 0x0);
        if (cnt > 1)
        {
            char dir[255 * 255];
            char buf[255 * 255];
            char fns[255 * 255];

            xr_strcpy(dir, buffer);
            xr_strcpy(fns, dir);
            xr_strcat(fns, "\\");
            xr_strcat(fns, _GetItem(buffer, 1, buf, 0x0));

            for (int i = 2; i < cnt; i++)
            {
                xr_strcat(fns, ",");
                xr_strcat(fns, dir);
                xr_strcat(fns, "\\");
                xr_strcat(fns, _GetItem(buffer, i, buf, 0x0));
            }
            xr_strcpy(buffer, sz_buf, fns);
        }
    }
    strlwr(buffer);
    return bRes;
}
コード例 #15
0
ファイル: colordlg.cpp プロジェクト: Asmodean-/Ishiiruka
int wxColourDialog::ShowModal()
{
    WX_HOOK_MODAL_DIALOG();

    // initialize the struct used by Windows
    CHOOSECOLOR chooseColorStruct;
    memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));

    size_t i;

    // and transfer data from m_colourData to it
    COLORREF custColours[16];
    for ( i = 0; i < WXSIZEOF(custColours); i++ )
    {
        if ( m_colourData.GetCustomColour(i).IsOk() )
            custColours[i] = wxColourToRGB(m_colourData.GetCustomColour(i));
        else
            custColours[i] = RGB(255,255,255);
    }

    chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
    if ( m_parent )
        chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
    chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.GetColour());
    chooseColorStruct.lpCustColors = custColours;

    chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
    chooseColorStruct.lCustData = (LPARAM)this;
    chooseColorStruct.lpfnHook = wxColourDialogHookProc;

    if ( m_colourData.GetChooseFull() )
        chooseColorStruct.Flags |= CC_FULLOPEN;

    // do show the modal dialog
    if ( !::ChooseColor(&chooseColorStruct) )
    {
        // 0 error means the dialog was simply cancelled, i.e. no real error
        // occurred
        const DWORD err = CommDlgExtendedError();
        if ( err )
        {
            wxLogError(_("Colour selection dialog failed with error %0lx."), err);
        }

        return wxID_CANCEL;
    }


    // transfer the values chosen by user back into m_colourData
    for ( i = 0; i < WXSIZEOF(custColours); i++ )
    {
      wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
    }

    wxRGBToColour(m_colourData.GetColour(), chooseColorStruct.rgbResult);

    // this doesn't seem to work (contrary to what MSDN implies) on current
    // Windows versions: CC_FULLOPEN is never set on return if it wasn't
    // initially set and vice versa
    //m_colourData.SetChooseFull((chooseColorStruct.Flags & CC_FULLOPEN) != 0);

    return wxID_OK;
}
コード例 #16
0
ファイル: audicle_utils.cpp プロジェクト: alltom/taps
fileData* 
winDirScanner::openFileDialog() { 

    char newname[512];
    newname[0] = '\0';
    
    if ( openfD ) { 
        delete openfD;
        openfD = NULL;
    }
    //XXX make this non-modal 
    //fprintf(stderr, "fetching WIN32 file dialog\n");
    BB_log( BB_LOG_INFO, "opening win32 open file dialog..." );
    BB_pushlog();
    
    ShowCursor(true);
    OPENFILENAME ofn;
    ZeroMemory(&ofn, sizeof(ofn));
    ofn.lpstrFile = newname;
    ofn.lStructSize = sizeof(ofn); // SEE NOTE BELOW
    ofn.hwndOwner = NULL;
    ofn.lpstrFilter = m_types ? m_types : "All Files (*.*)\0*.*\0";
    ofn.lpstrFile = newname;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_ALLOWMULTISELECT | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = "txt";
    
    if( GetOpenFileName( &ofn ) && ofn.lpstrFile )
    {
        // fprintf(stderr, "file - %s %s\n", ofn.lpstrFile, ofn.lpstrFileTitle );
        // BB_log( BB_LOG_INFO, "file: %s %s", ofn.lpstrFile, ofn.lpstrFileTitle );
        openfD = new fileData();
        fileData * newFile = openfD;
        char * next = newname; 
        next += strlen(next) + 1;
        if( *next )
        { 
            char basepath[512];
            char fullpath[512];
            strncpy( basepath, newname, 512 );
            strcat( basepath, "\\" );
            do
            { 
                strcpy( fullpath, basepath );
                strcat( fullpath, next );
                fprintf( stderr, "returned multi file %s\n", fullpath );
                newFile->fileName = fullpath;
                next += strlen(next) + 1;
                if( *next )
                { 
                    newFile->next = new fileData();
                    newFile = newFile->next;
                }
            }while ( *next ) ;
        } 
        else
        {   //no extra files, we copied the full path in already
            // fprintf ( stderr, "returned single file %s\n", newname );
            // BB_log( BB_LOG_INFO, "got single file: %s", newname );
            openfD->fileName = newname;
        }
    }
    else
    {
        if( CommDlgExtendedError() == 0 )
        {
            BB_log( BB_LOG_INFO, "no file selected..." );
        }
        else
        {
            BB_log( BB_LOG_INFO, "openfile error: %d", CommDlgExtendedError() );
        }

        BB_poplog();

        return NULL;
    }

    ShowCursor(false);

    BB_poplog();
    
    return openfD;
}
コード例 #17
0
ファイル: printdlg.c プロジェクト: howard5888/wineT
#if 0
    /* will crash with unpatched wine */
    SetLastError(0xdeadbeef);
    res = PrintDlgA(NULL);
    ok( !res && (CommDlgExtendedError() == CDERR_INITIALIZATION),
        "returned %ld with 0x%lx and 0x%lx (expected '0' and " \
        "CDERR_INITIALIZATION)\n", res, GetLastError(), CommDlgExtendedError());
    }
#endif

    ZeroMemory(pDlg, sizeof(PRINTDLGA));
    pDlg->lStructSize = sizeof(PRINTDLGA) - 1;
    SetLastError(0xdeadbeef);
    res = PrintDlgA(pDlg);
    ok( !res && (CommDlgExtendedError() == CDERR_STRUCTSIZE),
        "returned %ld with 0x%lx and 0x%lx (expected '0' and " \
        "CDERR_STRUCTSIZE)\n", res, GetLastError(), CommDlgExtendedError());


    ZeroMemory(pDlg, sizeof(PRINTDLGA));
    pDlg->lStructSize = sizeof(PRINTDLGA);
    pDlg->Flags = PD_RETURNDEFAULT;
    SetLastError(0xdeadbeef);
    res = PrintDlgA(pDlg);
    ok( res || (CommDlgExtendedError() == PDERR_NODEFAULTPRN),
        "returned %ld with 0x%lx and 0x%lx (expected '!= 0' or '0' and " \
        "PDERR_NODEFAULTPRN)\n", res, GetLastError(), CommDlgExtendedError());

    HeapFree(GetProcessHeap(), 0, pDlg);
コード例 #18
0
ファイル: InstallerOptions.cpp プロジェクト: kichik/nsis-1
LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) {
  int nIdx = FindControlIdx(id);
  // Ignore if the dialog is in the process of being created
  if (g_done || nIdx < 0)
    return 0;

  switch (pFields[nIdx].nType)
  {
    case FIELD_BROWSEBUTTON:
      --nIdx;
    case FIELD_LINK:
    case FIELD_BUTTON:
    case FIELD_CHECKBOX:
    case FIELD_RADIOBUTTON:
      if (codeNotify != BN_CLICKED)
        return 0;
      break;
    case FIELD_COMBOBOX:
    case FIELD_LISTBOX:
      if (codeNotify != LBN_SELCHANGE) // LBN_SELCHANGE == CBN_SELCHANGE
        return 0;
      break;
    default:
      return 0;
  }

  FieldType *pField = pFields + nIdx;

  char szBrowsePath[MAX_PATH];

  switch (pField->nType) {
    case FIELD_FILEREQUEST: {
      OPENFILENAME ofn={0,};

      ofn.lStructSize = sizeof(ofn);
      ofn.hwndOwner = hConfigWindow;
      ofn.lpstrFilter = pField->pszFilter;
      ofn.lpstrFile = szBrowsePath;
      ofn.nMaxFile  = sizeof(szBrowsePath);
      ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);

      GetWindowText(pField->hwnd, szBrowsePath, sizeof(szBrowsePath));

    tryagain:
      GetCurrentDirectory(BUFFER_SIZE, szResult); // save working dir
      if ((pField->nFlags & FLAG_SAVEAS) ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)) {
        mySetWindowText(pField->hwnd, szBrowsePath);
        SetCurrentDirectory(szResult); // restore working dir
                                       // OFN_NOCHANGEDIR doesn't always work (see MSDN)
        break;
      }
      else if (szBrowsePath[0] && CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
        szBrowsePath[0] = '\0';
        goto tryagain;
      }

      break;
    }

    case FIELD_DIRREQUEST: {
      BROWSEINFO bi;

      bi.hwndOwner = hConfigWindow;
      bi.pidlRoot = NULL;
      bi.pszDisplayName = szBrowsePath;
      bi.lpszTitle = pField->pszText;
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040
#endif
      bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
      bi.lpfn = BrowseCallbackProc;
      bi.lParam = nIdx;
      bi.iImage = 0;

      if (pField->pszRoot) {
        LPSHELLFOLDER sf;
        ULONG eaten;
        LPITEMIDLIST root;
        int ccRoot = (lstrlen(pField->pszRoot) * 2) + 2;
        LPWSTR pwszRoot = (LPWSTR) MALLOC(ccRoot);
        MultiByteToWideChar(CP_ACP, 0, pField->pszRoot, -1, pwszRoot, ccRoot);
        SHGetDesktopFolder(&sf);
        sf->ParseDisplayName(hConfigWindow, NULL, pwszRoot, &eaten, &root, NULL);
        bi.pidlRoot = root;
        sf->Release();
        FREE(pwszRoot);
      }
      //CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
      LPITEMIDLIST pResult = SHBrowseForFolder(&bi);
      if (!pResult)
        break;

      if (SHGetPathFromIDList(pResult, szBrowsePath)) {
        mySetWindowText(pField->hwnd, szBrowsePath);
      }

      CoTaskMemFree(pResult);

      break;
    }

    case FIELD_LINK:
    case FIELD_BUTTON:
      // Allow the state to be empty - this might be useful in conjunction
      // with the NOTIFY flag
      if (*pField->pszState)
        ShellExecute(hMainWindow, NULL, pField->pszState, NULL, NULL, SW_SHOWDEFAULT);
      break;
  }

  if (pField->nFlags & LBS_NOTIFY) {
    // Remember which control was activated then pretend the user clicked Next
    g_NotifyField = nIdx + 1;
    mySendMessage(hMainWindow, WM_NOTIFY_OUTER_NEXT, 1, 0);
  }

  return 0;
}
コード例 #19
0
ファイル: tclwinprint.c プロジェクト: AndresGG/sn-8.4
static int
winprint_print_text_dialog (struct winprint_data *wd, Tcl_Interp *interp,
			    const struct print_text_options *pto,
			    PRINTDLG *pd, int *cancelled)
{
  int mode, ret;

  *cancelled = 0;

  memset (pd, 0, sizeof (PRINTDLG));
  pd->lStructSize = sizeof (PRINTDLG);

  if (! pto->dialog)
    pd->Flags = PD_RETURNDEFAULT | PD_RETURNDC;
  else
    {
      Tk_Window parent;

      if (pto->parent == NULL)
	parent = Tk_MainWindow (interp);
      else
	{
	  parent = Tk_NameToWindow (interp, pto->parent,
				    Tk_MainWindow (interp));
	  if (parent == NULL)
	    return TCL_ERROR;
	}
      if (Tk_WindowId (parent) == None)
	Tk_MakeWindowExist (parent);
      pd->hwndOwner = Tk_GetHWND (Tk_WindowId (parent));

      if (wd->page_setup != NULL)
	{
	  pd->hDevMode = wd->page_setup->hDevMode;
	  pd->hDevNames = wd->page_setup->hDevNames;
	}

      pd->Flags = PD_NOSELECTION | PD_RETURNDC | PD_USEDEVMODECOPIES;

      pd->nCopies = 1;
      pd->nFromPage = 1;
      pd->nToPage = 1;
      pd->nMinPage = 1;
      pd->nMaxPage = 0xffff;
    }

  mode = Tcl_SetServiceMode (TCL_SERVICE_ALL);

  ret = PrintDlg (pd);

  (void) Tcl_SetServiceMode (mode);

  if (! ret)
    {
      DWORD code;

      code = CommDlgExtendedError ();

      /* For some errors, the print dialog will already have reported
         an error.  We treat those as though the user pressed cancel.
         Unfortunately, I do not know just which errors those are.  */

      if (code == 0 || code == PDERR_NODEFAULTPRN)
	{
	  *cancelled = 1;
	  return TCL_OK;
	}
      else
	{
	  char buf[20];

	  sprintf (buf, "0x%lx", (unsigned long) code);
	  Tcl_ResetResult (interp);
	  Tcl_AppendStringsToObj (Tcl_GetObjResult (interp),
				  "Windows common dialog error ", buf,
				  (char *) NULL);
	  return TCL_ERROR;
	}
    }

  return TCL_OK;
}
コード例 #20
0
ファイル: tclwinprint.c プロジェクト: AndresGG/sn-8.4
static int
winprint_page_setup_command (ClientData cd, Tcl_Interp *interp, int argc,
			     char **argv)
{
  struct winprint_data *wd = (struct winprint_data *) cd;
  Tk_Window parent;
  int i, mode, ret;
  PAGESETUPDLG psd;

  parent = Tk_MainWindow (interp);

  for (i = 2; i < argc; i += 2)
    {
      if (i + 1 >= argc)
	{
	  Tcl_ResetResult (interp);
	  Tcl_AppendStringsToObj (Tcl_GetObjResult (interp),
				  "value for \"", argv[i], "\" missing",
				  (char *) NULL);
	  return TCL_ERROR;
	}

      if (strcmp (argv[i], "-parent") == 0)
	{
	  parent = Tk_NameToWindow (interp, argv[i + 1],
				    Tk_MainWindow (interp));
	  if (parent == NULL)
	    return TCL_ERROR;
	}
      else
	{
	  Tcl_ResetResult (interp);
	  Tcl_AppendStringsToObj (Tcl_GetObjResult (interp),
				  "unknown option \"", argv[i], "\"",
				  (char *) NULL);
	  return TCL_ERROR;
	}
    }

  if (wd->page_setup != NULL)
    psd = *wd->page_setup;
  else
    {
      memset (&psd, 0, sizeof (PAGESETUPDLG));
      psd.lStructSize = sizeof (PAGESETUPDLG);
      psd.Flags = PSD_DEFAULTMINMARGINS;
    }

  if (Tk_WindowId (parent) == None)
    Tk_MakeWindowExist (parent);
  psd.hwndOwner = Tk_GetHWND (Tk_WindowId (parent));

  mode = Tcl_SetServiceMode (TCL_SERVICE_ALL);

  ret = PageSetupDlg (&psd);

  (void) Tcl_SetServiceMode (mode);

  if (! ret)
    {
      DWORD code;

      code = CommDlgExtendedError ();
      if (code == 0)
	{
	  /* The user pressed cancel.  */
	  return TCL_OK;
	}
      else
	{
	  char buf[20];

	  sprintf (buf, "0x%lx", (unsigned long) code);
	  Tcl_ResetResult (interp);
	  Tcl_AppendStringsToObj (Tcl_GetObjResult (interp),
				  "Windows common dialog error ", buf,
				  (char *) NULL);
	  return TCL_ERROR;
	}
    }

  if (wd->page_setup == NULL)
    wd->page_setup = (PAGESETUPDLG *) ckalloc (sizeof (PAGESETUPDLG));

  *wd->page_setup = psd;

  return TCL_OK;
}
コード例 #21
0
ファイル: browse.c プロジェクト: 151706061/nsis-chinese
void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop, extra_parameters *extra)
{
  OPENFILENAME ofn={0,}; // XXX WTF
  int save;
  TCHAR type[5];
  const int len = 1024;
  // Avoid _chkstk by using allocated arrays.
  TCHAR* path = (TCHAR*) GlobalAlloc(GPTR, len*sizeof(TCHAR));
  TCHAR* filter =(TCHAR*) GlobalAlloc(GPTR, len*sizeof(TCHAR)); 
  TCHAR* currentDirectory = (TCHAR*) GlobalAlloc(GPTR, len*sizeof(TCHAR));
  TCHAR* initialDir = (TCHAR*) GlobalAlloc(GPTR, len*sizeof(TCHAR));
  DWORD  gfa;

  EXDLL_INIT();

  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner = hwndParent;
  ofn.lpstrFilter = filter;
  ofn.lpstrFile = path;
  ofn.nMaxFile  = len;
  //ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);
  ofn.Flags = OFN_CREATEPROMPT | OFN_EXPLORER;

  popstringn(type, len);
  popstringn(path, len);
  popstringn(filter, len);

  save = !lstrcmpi(type, _T("save"));

  // Check if the path given is a folder. If it is we initialize the 
  // ofn.lpstrInitialDir parameter
  gfa = GetFileAttributes(path);
  if ((gfa != INVALID_FILE_ATTRIBUTES) && (gfa & FILE_ATTRIBUTE_DIRECTORY))
  {
    lstrcpy(initialDir, path);
    ofn.lpstrInitialDir = initialDir;
    path[0] = _T('\0'); // disable initial file selection as path is actually a directory
  }

  if (!filter[0])
  {
    lstrcpy(filter, _T("All Files|*.*"));
  }

  {
    // Convert the filter to the format required by Windows: NULL after each
    // item followed by a terminating NULL
    TCHAR *p = filter;
    while (*p) // XXX take care for 1024
    {
      if (*p == _T('|'))
      {
        *p++ = 0;
      }
      else
      {
        p = CharNext(p);
      }
    }
    p++;
    *p = 0;
  }

  GetCurrentDirectory(sizeof(currentDirectory), currentDirectory); // save working dir

  if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)))
  {
    pushstring(path);
  }
  else if (CommDlgExtendedError() == FNERR_INVALIDFILENAME)
  {
    *path = _T('\0');
    if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)))
    {
      pushstring(path);
    }
    else
    {
      pushstring(_T(""));
    }
  }
  else
  {
    pushstring(_T(""));
  }

  // restore working dir
  // OFN_NOCHANGEDIR doesn't always work (see MSDN)
  SetCurrentDirectory(currentDirectory);

  GlobalFree(path);
  GlobalFree(filter);
  GlobalFree(currentDirectory);
  GlobalFree(initialDir);
}
コード例 #22
0
ファイル: guifdlg.c プロジェクト: pavanvunnava/open-watcom-v2
int GUIGetFileName( gui_window *wnd, open_file_name *ofn )
{
    OPENFILENAME        wofn;
    bool                issave;
    int                 rc;
    unsigned            drive;
#if defined(HAVE_DRIVES)
    unsigned            old_drive;
    unsigned            drives;
#endif

    LastPath = NULL;
    if( ofn->initial_dir != NULL && ofn->initial_dir[0] != '\0' && ofn->initial_dir[1] == ':' ) {
        drive = ofn->initial_dir[0];
        memmove( ofn->initial_dir, ofn->initial_dir+2, strlen( ofn->initial_dir+2 ) + 1 );
    } else {
        drive = 0;
    }

    memset( &wofn, 0 , sizeof( wofn ) );

    if( ofn->flags & OFN_ISSAVE ) {
        issave = true;
    } else {
        issave = false;
    }

    wofn.Flags = 0;
    if( hookFileDlg ) {
        wofn.Flags |= OFN_ENABLEHOOK;
    }
    if( !(ofn->flags & OFN_CHANGEDIR) ) {
        wofn.Flags |= OFN_NOCHANGEDIR;
    }

    if( ofn->flags & OFN_OVERWRITEPROMPT ) {
        wofn.Flags |= OFN_OVERWRITEPROMPT;
    }
    if( ofn->flags & OFN_HIDEREADONLY ) {
        wofn.Flags |= OFN_HIDEREADONLY;
    }
    if( ofn->flags & OFN_FILEMUSTEXIST ) {
        wofn.Flags |= OFN_FILEMUSTEXIST;
    }
    if( ofn->flags & OFN_PATHMUSTEXIST ) {
        wofn.Flags |= OFN_PATHMUSTEXIST;
    }
    if( ofn->flags & OFN_ALLOWMULTISELECT ) {
        wofn.Flags |= OFN_ALLOWMULTISELECT;
    }
    wofn.hwndOwner = GUIGetParentFrameHWND( wnd );
    wofn.hInstance = GUIMainHInst;
    wofn.lStructSize = sizeof( wofn );
    wofn.lpstrFilter = ofn->filter_list;
    wofn.nFilterIndex = ofn->filter_index;
    wofn.lpstrFile = ofn->file_name;
    wofn.nMaxFile = ofn->max_file_name;
    wofn.lpstrFileTitle = ofn->base_file_name;
    wofn.nMaxFileTitle = ofn->max_base_file_name;
    wofn.lpstrTitle = ofn->title;
    wofn.lpstrInitialDir = ofn->initial_dir;
    wofn.lpfnHook = (LPOFNHOOKPROC)NULL;
    if( hookFileDlg ) {
        wofn.lpfnHook = (LPOFNHOOKPROC)MakeOpenFileHookProcInstance( OpenHook, GUIMainHInst );
    }

#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_getdrive( &old_drive );
        _dos_setdrive( tolower( drive ) - 'a' + 1, &drives );
    }
#endif
    if( issave ) {
        rc = GetSaveFileName( &wofn );
    } else {
        rc = GetOpenFileName( &wofn );
    }

    if( hookFileDlg ) {
        (void)FreeProcInstance( (FARPROC)wofn.lpfnHook );
    }

    if( LastPath && ( !rc || !( ofn->flags & OFN_WANT_LAST_PATH ) ) ) {
        GUIMemFree( LastPath );
        LastPath = NULL;
    }
    ofn->last_path = LastPath;
#if defined( HAVE_DRIVES )
    if( drive ) {
        _dos_setdrive( old_drive, &drives );
    }
#endif
    if( rc ) {
        return( OFN_RC_FILE_SELECTED );
    }
    if( !CommDlgExtendedError() ) {
        return( OFN_RC_NO_FILE_SELECTED );
    }
    return( OFN_RC_FAILED_TO_INITIALIZE );
} /* _GUIGetFileName */
コード例 #23
0
ファイル: w32ans.cpp プロジェクト: Bjoernke/livecode
static int MCA_do_file_dialog(MCExecPoint& ep, const char *p_title, const char *p_prompt, const char *p_filter, const char *p_initial, unsigned int p_options)
{
	int t_result = 0;

	char *t_initial_file;
	t_initial_file = NULL;

	char *t_initial_folder;
	t_initial_folder = NULL;

	ep . clear();

	if (*p_initial != '\0')
	{
		char *t_initial_clone;
		t_initial_clone = strdup(p_initial);
		MCU_w32path2std(t_initial_clone);
		MCU_fix_path(t_initial_clone);

		if (MCS_exists(t_initial_clone, False))
			t_initial_folder = t_initial_clone;
		else if ((p_options & MCA_OPTION_SAVE_DIALOG) != 0)
		{
			t_initial_file = strrchr(t_initial_clone, '/');
			if (t_initial_file == NULL)
			{
				if (strlen(t_initial_clone) != 0)
					t_initial_file = t_initial_clone;
			}
			else
			{
				*t_initial_file = '\0';
				t_initial_file++;
				
				if (t_initial_file[0] == '\0')
					t_initial_file = NULL;

				if (MCS_exists(t_initial_clone, False))
					t_initial_folder = t_initial_clone;
			}
		}
		else
		{
			char *t_leaf;
			t_leaf = strrchr(t_initial_clone, '/');
			if (t_leaf != NULL)
			{
				*t_leaf = '\0';
				if (MCS_exists(t_initial_clone, False))
					t_initial_folder = t_initial_clone;
			}
		}

		t_initial_file = strdup(t_initial_file);
		t_initial_folder = MCS_resolvepath(t_initial_folder);

		delete t_initial_clone;
	}

	if (!MCModeMakeLocalWindows())
	{
		char ** t_filters = NULL;
		uint32_t t_filter_count = 0;

		if (p_filter != NULL)
		{
			const char *t_strptr = p_filter;
			while (t_strptr[0] != '\0')
			{
				t_filter_count++;
				t_filters = (char**)realloc(t_filters, t_filter_count * sizeof(char*));
				t_filters[t_filter_count - 1] = (char *)t_strptr;
				t_strptr += strlen(t_strptr) + 1;
			}
		}

		MCRemoteFileDialog(ep, p_title, p_prompt, t_filters, t_filter_count, t_initial_folder, t_initial_file, (p_options & MCA_OPTION_SAVE_DIALOG) != 0, (p_options & MCA_OPTION_PLURAL) != 0);

		free(t_filters);
		return 0;
	}

	Window t_window;
	t_window = MCModeGetParentWindow();

	bool t_succeeded;
	int t_filter_index;

	if (MCmajorosversion >= 0x0600)
	{
		static SHCreateItemFromParsingNamePtr  s_shcreateitemfromparsingname = NULL;
		if (s_shcreateitemfromparsingname == NULL)
		{
			static HMODULE s_shell32_module = NULL;
			s_shell32_module = LoadLibraryA("shell32.dll");
			s_shcreateitemfromparsingname = (SHCreateItemFromParsingNamePtr)GetProcAddress(s_shell32_module, "SHCreateItemFromParsingName");
		}

		IFileSaveDialog *t_file_save_dialog;
		IFileOpenDialog *t_file_open_dialog;
		IFileDialog *t_file_dialog;

		t_file_dialog = NULL;

		HRESULT t_hresult;

		if ((p_options & MCA_OPTION_SAVE_DIALOG) == 0)
		{
			t_hresult = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, __uuidof(IFileOpenDialog), (LPVOID *)&t_file_open_dialog);
			t_succeeded = SUCCEEDED(t_hresult);

			t_file_dialog = t_file_open_dialog;
		}
		else
		{
			t_hresult = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, __uuidof(IFileSaveDialog), (LPVOID *)&t_file_save_dialog);
			t_succeeded = SUCCEEDED(t_hresult);

			t_file_dialog = t_file_save_dialog;
		}

		if (t_succeeded)
		{
			DWORD t_options;

			t_options = FOS_FORCEFILESYSTEM | FOS_NOCHANGEDIR | FOS_PATHMUSTEXIST;
			if (p_options & MCA_OPTION_PLURAL)
				t_options |= FOS_ALLOWMULTISELECT;
			if (p_options & MCA_OPTION_SAVE_DIALOG)
				t_options |= FOS_OVERWRITEPROMPT;
			if (p_options & MCA_OPTION_FOLDER_DIALOG)
				t_options |= FOS_PICKFOLDERS;
			else
				t_options |= FOS_FILEMUSTEXIST;

			t_hresult = t_file_dialog -> SetOptions(t_options);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && t_initial_folder != NULL)
		{
			IShellItem *t_initial_folder_shellitem;
			t_initial_folder_shellitem = NULL;
			t_hresult = s_shcreateitemfromparsingname(WideCString(t_initial_folder), NULL, __uuidof(IShellItem), (LPVOID *)&t_initial_folder_shellitem);
			if (SUCCEEDED(t_hresult))
				t_file_dialog -> SetFolder(t_initial_folder_shellitem);
			if (t_initial_folder_shellitem != NULL)
				t_initial_folder_shellitem -> Release();
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && t_initial_file != NULL)
		{
			t_hresult = t_file_dialog -> SetFileName(WideCString(t_initial_file));
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded && p_filter != NULL && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			uint4 t_filter_length, t_filter_count;
			measure_filter(p_filter, t_filter_length, t_filter_count);

			WideCString t_filters(p_filter, t_filter_length);
			COMDLG_FILTERSPEC *t_filter_spec;

			filter_to_spec(t_filters, t_filter_count, t_filter_spec);

			t_hresult = t_file_dialog -> SetFileTypes(t_filter_count, t_filter_spec);
			t_succeeded = SUCCEEDED(t_hresult);

			delete t_filter_spec;
		}

		if (t_succeeded && p_filter != NULL && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			t_hresult = t_file_dialog -> SetFileTypeIndex(1);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if (t_succeeded)
			t_hresult = t_file_dialog -> SetTitle(WideCString(p_prompt));

		if (t_succeeded)
		{
			t_hresult = t_file_dialog -> Show(t_window != NULL ? (HWND)t_window -> handle . window : NULL);
			t_succeeded = SUCCEEDED(t_hresult);
		}

		if ((p_options & MCA_OPTION_SAVE_DIALOG) == 0)
		{
			IShellItemArray *t_file_items;
			t_file_items = NULL;
			if (t_succeeded)
			{
				t_hresult = t_file_open_dialog -> GetResults(&t_file_items);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			DWORD t_file_item_count;
			if (t_succeeded)
			{
				t_hresult = t_file_items -> GetCount(&t_file_item_count);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			if (t_succeeded)
			{
				ep . clear();
				for(uint4 t_index = 0; t_index < t_file_item_count && t_succeeded; ++t_index)
				{
					IShellItem *t_file_item;
					t_file_item = NULL;
					if (t_succeeded)
					{
						t_hresult = t_file_items -> GetItemAt(t_index, &t_file_item);
						t_succeeded = SUCCEEDED(t_hresult);
					}

					if (t_succeeded)
					{
						t_hresult = append_shellitem_path_and_release(ep, t_file_item, t_index == 0);
						t_succeeded = SUCCEEDED(t_hresult);
					}
				}
			}

			if (t_file_items != NULL)
				t_file_items -> Release();
		}
		else
		{
			IShellItem *t_file_item;
			t_file_item = NULL;
			if (t_succeeded)
			{
				t_hresult = t_file_dialog -> GetResult(&t_file_item);
				t_succeeded = SUCCEEDED(t_hresult);
			}

			if (t_succeeded)
			{
				ep . clear();
				t_hresult = append_shellitem_path_and_release(ep, t_file_item, true);
				t_succeeded = SUCCEEDED(t_hresult);
			}
		}

		t_filter_index = 0;
		if (t_succeeded && (p_options & MCA_OPTION_FOLDER_DIALOG) == 0)
		{
			UINT t_index;
			t_hresult = t_file_dialog -> GetFileTypeIndex(&t_index);
			t_succeeded = SUCCEEDED(t_hresult);
			if (t_succeeded)
				t_filter_index = (int)t_index;
		}

		if (t_file_dialog != NULL)
			t_file_dialog -> Release();

		if (!t_succeeded)
			t_result = t_hresult;
		else
			t_result = 0;
	}
	else
	{
		OPENFILENAMEA t_open_dialog;
		memset(&t_open_dialog, 0, sizeof(OPENFILENAMEA));
		t_open_dialog . lStructSize = sizeof(OPENFILENAMEA);

		char *t_initial_file_buffer = new char[MAX_PATH];
		if (t_initial_file != NULL)
			strcpy(t_initial_file_buffer, t_initial_file);
		else
			*t_initial_file_buffer = '\0';

		t_open_dialog . lpstrFilter = p_filter;
		t_open_dialog . nFilterIndex = 1;
		t_open_dialog . lpstrFile = t_initial_file_buffer;
		t_open_dialog . nMaxFile = MAX_PATH;
		t_open_dialog . lpstrInitialDir = t_initial_folder;
		t_open_dialog . lpstrTitle = p_prompt;
		t_open_dialog . Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NOCHANGEDIR |
														OFN_LONGNAMES | OFN_PATHMUSTEXIST | OFN_EXPLORER |
														OFN_ENABLEHOOK | OFN_ENABLESIZING;

		if (p_options & MCA_OPTION_PLURAL)
			t_open_dialog . Flags |= OFN_ALLOWMULTISELECT;

		if (p_options & MCA_OPTION_SAVE_DIALOG)
			t_open_dialog . Flags |= OFN_OVERWRITEPROMPT;

		t_open_dialog . lpstrFilter = p_filter;
		t_open_dialog . lpfnHook = open_dialog_hook;
		t_open_dialog . hwndOwner = t_window != NULL ? (HWND)t_window -> handle . window : NULL;

		if (p_options & MCA_OPTION_SAVE_DIALOG)
			t_succeeded = GetSaveFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;
		else
		{
			*t_open_dialog . lpstrFile = '\0';
			t_succeeded = GetOpenFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;
		}

		if (!t_succeeded)
			t_result = CommDlgExtendedError();

		// MW-2005-07-26: Try again without the specified filename if it was invalid
		if (t_result == FNERR_INVALIDFILENAME)
		{
			*t_open_dialog . lpstrFile = '\0';
			if (p_options & MCA_OPTION_SAVE_DIALOG)
				t_succeeded = GetSaveFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;
			else
				t_succeeded = GetOpenFileNameA((LPOPENFILENAMEA)&t_open_dialog) == TRUE;

			if (!t_succeeded)
				t_result = CommDlgExtendedError();	
		}

		if (t_result == FNERR_BUFFERTOOSMALL)
			t_succeeded = true;

		if (t_succeeded)
		{
			build_paths(ep);
			t_filter_index = t_open_dialog . nFilterIndex;
		}

		delete t_initial_file_buffer;
	}

	if (t_succeeded)
	{
		if (p_options & MCA_OPTION_RETURN_FILTER)
		{
			const char *t_type = p_filter;
			const char *t_types = p_filter;
			for(int t_index = t_filter_index * 2 - 1; t_index > 1; t_types += 1)
				if (*t_types == '\0')
					t_type = t_types + 1, t_index -= 1;
			MCresult -> copysvalue(t_type);
		}

		t_result = 0;
	}

	waitonbutton();

	if (t_initial_folder != NULL)
		delete t_initial_folder;

	if (t_initial_file != NULL)
		delete t_initial_file;

	return t_result;
}
コード例 #24
0
ファイル: uiDlg.cpp プロジェクト: SummerSut/ui
bbCHAR* uiDlgFileName(uiWINH hWin, const bbCHAR* pPath, bbUINT opt, uiDlgFileNameFilter* const pFilter)
{
#if (bbOS == bbOS_WIN32) || (bbOS == bbOS_WINCE)

    bbCHAR* pFileNameBuffer;
    bbUINT const bufferstart = (opt & uiDLGFILEOPT_MULTISELECT) ? sizeof(uiDlgFileNameBlock)/sizeof(bbCHAR) : 0;
    OPENFILENAME ofn;

    bbMemClear(&ofn, sizeof(ofn));

    ofn.lStructSize = sizeof(ofn);
    ofn.hwndOwner   = hWin;

    if (pPath)
        ofn.nMaxFile = bbStrLen(pPath) + 1;

    if (ofn.nMaxFile < 512)
        ofn.nMaxFile = 512;

    if ((pFileNameBuffer = (bbCHAR*) bbMemAlloc(sizeof(bbCHAR) * ofn.nMaxFile + sizeof(uiDlgFileNameBlock))) == NULL)
        return NULL;

    ofn.lpstrFile = pFileNameBuffer + bufferstart;

    if (pPath)
        bbStrCpy(ofn.lpstrFile, pPath);
    else
        *ofn.lpstrFile = 0;

    if (pFilter)
    {
        ofn.nFilterIndex = pFilter->FilterIndex;
        ofn.lpstrFilter  = pFilter->pFilter;
    }

    ofn.Flags = (opt & (uiDLGFILEOPT_MULTISELECT|uiDLGFILEOPT_NODEREFERENCELINKS|uiDLGFILEOPT_OVERWRITEPROMPT))
        | OFN_DONTADDTORECENT | OFN_ENABLESIZING | OFN_NOTESTFILECREATE | OFN_HIDEREADONLY | OFN_EXPLORER;

    BOOL (__stdcall *fnGetFileName)(LPOPENFILENAME) = (opt & uiDLGFILEOPT_SAVE) ? GetSaveFileName : GetOpenFileName;

    if (fnGetFileName(&ofn) == 0)
    {
        DWORD err = CommDlgExtendedError();

        if (err == FNERR_BUFFERTOOSMALL)
        {
            ofn.nMaxFile = *(WORD*)ofn.lpstrFile;
            if (bbMemRealloc(sizeof(bbCHAR) * ofn.nMaxFile + sizeof(uiDlgFileNameBlock), (void**)&pFileNameBuffer) != bbEOK)
                goto uiDlgFileSave_err;
            ofn.lpstrFile = pFileNameBuffer + bufferstart;

            if (fnGetFileName(&ofn))
                goto uiDlgFileSave_ok;
            err = CommDlgExtendedError();
        }

        if (err == 0)
        {
            bbErrSet(bbEEND);
        }
        else
        {
            bbErrSet(bbESYS); //xxx add error codes
            bbLog(bbErr, bbT("uiDlgFileSave: error %X\n"), err);
        }

        goto uiDlgFileSave_err;
    }

    uiDlgFileSave_ok:

    if (pFilter)
    {
        pFilter->FilterIndex = ofn.nFilterIndex;
    }

    if (opt & uiDLGFILEOPT_MULTISELECT)
    {
        ((uiDlgFileNameBlock*)pFileNameBuffer)->CurFileOffset = 
        ((uiDlgFileNameBlock*)pFileNameBuffer)->FirstFileOffset = ofn.nFileOffset;

        if (ofn.nFileOffset > 0)
            pFileNameBuffer[ofn.nFileOffset + bufferstart - 1] = '\0'; // 0-term path also for single-selection case
    }

    return pFileNameBuffer;

    uiDlgFileSave_err:
    bbMemFree(pFileNameBuffer);
    return NULL;
#else
#endif
}
コード例 #25
0
static void do_browse(const char *title, const char *entry_to_populate,
                      int filts)
{
#ifdef win32
    OPENFILENAME of;
    int retval;
    char fname[1024];
    fname[0] = '\0';
    memset(&of, 0, sizeof(of));

#ifdef OPENFILENAME_SIZE_VERSION_400
    of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
#else
    of.lStructSize = sizeof(of);
#endif

    of.hwndOwner = NULL;

    if (filts == (L_FILT | LED_FILT | ALL_CEOS_LEADER_FILT | XML_FILT | 
		  RSC_FILT | MOSAIC_FILT)) {
      of.lpstrFilter =
        "CEOS Level 1 Files\0*.L;LED-*\0"
        "RSAT/ERS CEOS L1\0*.L\0"
        "ALOS Leader Files\0LED-*\0"
	"TerraSAR-X/Radarsat-2\0*.xml\0"
	"ALOS mosaics\0*HDR.txt;*HDR\0"
	"ROI_PAC Files\0*.rsc\0"
        "All Files\0*\0";
    }
    else if (filts == (L_FILT | LED_FILT | ALL_CEOS_LEADER_FILT | XML_FILT)) {
      of.lpstrFilter =
        "CEOS Level 1 Files\0*.L;LED-*\0"
        "RSAT/ERS CEOS L1\0*.L\0"
        "ALOS Leader Files\0LED-*\0"
	"TerraSAR-X/Radarsat-2\0*.xml\0"
        "All Files\0*\0";
    }
    else if (filts == (L_FILT | LED_FILT | ALL_CEOS_LEADER_FILT | XML_FILT | ANN_FILT )) {
      of.lpstrFilter =
        "All Metadata Files\0*.L;LED-*;*.xml;*.ann\0"
        "CEOS Level 1 Files\0*.L;LED-*\0"
        "RSAT/ERS CEOS L1\0*.L\0"
        "ALOS Leader Files\0LED-*\0"
	"TerraSAR-X/Radarsat-2\0*.xml\0"
	"UAVSAR Annotation File\0*.ann\0"
        "All Files\0*\0";
    }
    else if (filts == BIN_FILT) {
      of.lpstrFilter =
        "PolSARPro Files\0*.bin\0"
        "All Files\0*\0";
    }
    else if (filts == ANN_FILT) {
      of.lpstrFilter =
        "UAVSAR Annotation File\0*.ann\0"
        "All Files\0*\0";
    } else {
      of.lpstrFilter = "All Files\0*\0";
    }

    of.lpstrCustomFilter = NULL;
    of.nFilterIndex = 1;
    of.lpstrFile = fname;
    of.nMaxFile = sizeof(fname);
    of.lpstrFileTitle = NULL;
    of.lpstrInitialDir = ".";
    of.lpstrTitle = "Select File";
    of.lpstrDefExt = NULL;
    of.Flags = OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER;

    retval = GetOpenFileName(&of);

    if (!retval) {
        if (CommDlgExtendedError())
            message_box("File dialog box error");
        return;
    }

    /* the returned "fname" has the following form:            */
    /*   <directory>\0<first file>\0<second file>\0<third ...  */
    char * dir = STRDUP(fname);
    char * p = fname + strlen(dir) + 1;

    if (*p) {
        while (*p) {
            char * dir_and_file =
                malloc(sizeof(char)*(strlen(dir)+strlen(p)+5));
            sprintf(dir_and_file, "%s%c%s", dir, DIR_SEPARATOR, p);
            put_string_to_entry(entry_to_populate, dir_and_file);
            p += strlen(p) + 1;
            free(dir_and_file);
        }
    }
    else {
      put_string_to_entry(entry_to_populate, dir);
    }

    free(dir);

#else // #ifdef win32

    GtkWidget *parent = get_widget_checked("asf_convert");

    GtkWidget *browse_widget = gtk_file_chooser_dialog_new(
        title, GTK_WINDOW(parent),
        GTK_FILE_CHOOSER_ACTION_OPEN,
        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, //Cancel button
        GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,   //Open button
        NULL);

    // we need to extract the buttons, so we can connect them to our
    // button handlers, above
    GtkHButtonBox *box =
        (GtkHButtonBox*)(((GtkDialog*)browse_widget)->action_area);
    GList *buttons = box->button_box.box.children;

    GtkWidget *cancel_btn = ((GtkBoxChild*)buttons->data)->widget;
    GtkWidget *ok_btn = ((GtkBoxChild*)buttons->next->data)->widget;

    g_signal_connect((gpointer)cancel_btn, "clicked",
        G_CALLBACK(do_browse_cancel_clicked), NULL);
    g_signal_connect((gpointer)ok_btn, "clicked",
        G_CALLBACK(do_browse_ok_clicked), NULL);

    // store the entry that should be populated as aux data in the widget
    g_object_set_data(G_OBJECT(browse_widget), "entry",
                      (gpointer)entry_to_populate);

    // store a pointer to the browse widget as aux data in the buttons
    g_object_set_data(G_OBJECT(cancel_btn), "browse_widget",
                      (gpointer)browse_widget);
    g_object_set_data(G_OBJECT(ok_btn), "browse_widget",
                      (gpointer)browse_widget);

    // add the filters
    if (filts & ALL_CEOS_DATA_FILT) {
      GtkFileFilter *ceos_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(ceos_filt, "All CEOS Level 1 Files");
      gtk_file_filter_add_pattern(ceos_filt, "*.D");
      gtk_file_filter_add_pattern(ceos_filt, "IMG-*");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), ceos_filt);
    }
    if (filts & ALL_CEOS_LEADER_FILT) {
      GtkFileFilter *ceos_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(ceos_filt, "All CEOS Level 1 Files");
      gtk_file_filter_add_pattern(ceos_filt, "*.L");
      gtk_file_filter_add_pattern(ceos_filt, "LED-*");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), ceos_filt);
    }
    if (filts & D_FILT) {
      GtkFileFilter *D_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(D_filt, "RSAT/ERS CEOS L1 (*.D)");
      gtk_file_filter_add_pattern(D_filt, "*.D");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), D_filt);
    }
    if (filts & L_FILT) {
      GtkFileFilter *L_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(L_filt, "RSAT/ERS CEOS L1 (*.L)");
      gtk_file_filter_add_pattern(L_filt, "*.L");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), L_filt);
    }
    if (filts & LED_FILT) {
      GtkFileFilter *alos_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(alos_filt, "ALOS Leader Files (LED-*)");
      gtk_file_filter_add_pattern(alos_filt, "LED-*");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), alos_filt);
    }
    if (filts & IMG_FILT) {
      GtkFileFilter *img_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(img_filt, "ALOS Data Files (IMG-*)");
      gtk_file_filter_add_pattern(img_filt, "IMG-*");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), img_filt);
    }
    if (filts & BIN_FILT) {
      GtkFileFilter *polsarpro_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(polsarpro_filt,
                               "PolSARpro Data Files (*.bin)");
      gtk_file_filter_add_pattern(polsarpro_filt, "*.bin");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget),
                                  polsarpro_filt);
    }
    if (filts & HDR_FILT) {
      GtkFileFilter *hdr_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(hdr_filt, "PolSARPro Header Files (*.hdr)");
      gtk_file_filter_add_pattern(hdr_filt, "*.hdr");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), hdr_filt);
    }
    if (filts & XML_FILT) {
      GtkFileFilter *xml_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(xml_filt, "TerraSAR-X/Radarsat-2 Files (*.xml)");
      gtk_file_filter_add_pattern(xml_filt, "*.xml");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), xml_filt);
    }
    if (filts & RSC_FILT) {
      GtkFileFilter *rsc_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(rsc_filt, "ROI_PAC Files (*.rsc)");
      gtk_file_filter_add_pattern(rsc_filt, "*.rsc");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), rsc_filt);
    }
    if (filts & MOSAIC_FILT) {
      GtkFileFilter *mosaic_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(mosaic_filt, "ALOS mosaic Files (*HDR.txt, *HDR)");
      gtk_file_filter_add_pattern(mosaic_filt, "*HDR.txt");
      gtk_file_filter_add_pattern(mosaic_filt, "*HDR");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), mosaic_filt);
    }
    if (filts & ANN_FILT) {
      GtkFileFilter *ann_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(ann_filt, "UAVSAR Annotation File");
      gtk_file_filter_add_pattern(ann_filt, "*.ann");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), ann_filt);
    }
    if (filts & DIR_FILT) {
      GtkFileFilter *dir_filt = gtk_file_filter_new();
      gtk_file_filter_set_name(dir_filt, "PolSARPro matrix directory");
      gtk_file_filter_add_pattern(dir_filt, "*.");
      gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), dir_filt);
    }

    GtkFileFilter *all_filt = gtk_file_filter_new();
    gtk_file_filter_set_name(all_filt, "All Files (*.*)");
    gtk_file_filter_add_pattern(all_filt, "*");
    gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(browse_widget), all_filt);

    // do not allow multi-select
    gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(browse_widget),
                                         FALSE);

    // we need to make these modal -- if the user opens multiple "open"
    // dialogs, we'll get confused on the callbacks
    gtk_window_set_modal(GTK_WINDOW(browse_widget), TRUE);
    gtk_window_set_destroy_with_parent(GTK_WINDOW(browse_widget), TRUE);
    gtk_dialog_set_default_response(GTK_DIALOG(browse_widget),
                                    GTK_RESPONSE_OK);

    gtk_widget_show(browse_widget);
#endif
}
コード例 #26
0
SIGNAL_CALLBACK void
on_browse_input_files_button_clicked(GtkWidget *widget)
{
  GtkWidget *combo = get_widget_checked("browse_format_combobox");
  GtkWidget *browse_select_colormap_optionmenu =
      get_widget_checked("browse_select_colormap_optionmenu");
  GtkWidget *browse_select_colormap_label =
      get_widget_checked("browse_select_colormap_label");
  GtkWidget *browse_select_image_data_type_optionmenu =
      get_widget_checked("browse_select_colormap_optionmenu");
  GtkWidget *browse_select_image_data_type_label =
      get_widget_checked("browse_select_colormap_label");
  GtkWindow *ancillary_dialog =
      GTK_WINDOW(get_widget_checked("add_file_with_ancillary_dialog"));
  GtkWindow *main_window =
      GTK_WINDOW(get_widget_checked("asf_convert"));
  int sel = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
  GtkWidget *ok_button =
    get_widget_checked("add_file_with_ancillary_ok_button");

  // open the "add with ancillary" if needed, otherwise we'll use the
  // normal 'open file' dialog
  if (sel==FORMAT_GAMMA || sel==FORMAT_POLSARPRO || sel==FORMAT_UAVSAR) {
    show_widget("hbox_polsarpro", sel==FORMAT_POLSARPRO);
    show_widget("hbox_gamma", sel==FORMAT_GAMMA);
    show_widget("vbox_uavsar", sel==FORMAT_UAVSAR);
    switch (sel) {
      case FORMAT_GAMMA:
        put_string_to_label("add_with_ancillary_format_label", "GAMMA");
        show_widget("hbox_gamma_description", TRUE);
        gtk_widget_set_sensitive(ok_button, TRUE);	
        break;
      case FORMAT_UAVSAR:
        put_string_to_label("add_with_ancillary_format_label", "UAVSAR");
        show_widget("hbox_gamma_description", FALSE);
        gtk_widget_set_sensitive(ok_button, FALSE);	
        break;
      case FORMAT_POLSARPRO:
        put_string_to_label("add_with_ancillary_format_label", "PolSARPro");
        show_widget("hbox_gamma_description", FALSE);
        gtk_widget_show(browse_select_colormap_optionmenu);
        gtk_widget_show(browse_select_colormap_label);
        gtk_widget_show(browse_select_image_data_type_optionmenu);
        gtk_widget_show(browse_select_image_data_type_label);
        gtk_widget_set_sensitive(ok_button, FALSE);	
        init_image_data_type_combobox();
        polsarpro_image_data_type_changed();
        break;
      default:
        put_string_to_label("add_with_ancillary_format_label", "Unknown");
        break;
    }
    gtk_window_set_transient_for(ancillary_dialog, main_window);
    gtk_widget_show(GTK_WIDGET(ancillary_dialog));
    return;
  }

  // normal case -- not requiring ancillary files

#ifdef win32
    OPENFILENAME of;
    int retval;
    char fname[1024];

    fname[0] = '\0';

    memset(&of, 0, sizeof(of));

#ifdef OPENFILENAME_SIZE_VERSION_400
    of.lStructSize = OPENFILENAME_SIZE_VERSION_400;
#else
    of.lStructSize = sizeof(of);
#endif

    of.hwndOwner = NULL;

    switch (sel) {
      case FORMAT_CEOS:
        of.lpstrFilter =
            "CEOS Level 1 Files\0*.L;LED-*;*.LEA;*.lea;LEA_*;lea_*;*.ldr;*.sarl\0"
            "RSAT/ERS CEOS L1 (*.L)\0*.L\0"
            "ALOS Files (LED-*)\0LED-*\0"
            "LEA Leader Files (LEA_*, lea_*, *.lea, *.LEA)\0LEA_*;lea_*;*.lea;*.LEA\0"
            "LDR Leader Files (*.ldr)\0*.ldr\0"
            "SARL Leader Files (*.sarl)\0*.sarl\0"
            "All Files\0*\0";
        break;

      case FORMAT_AIRSAR:
        of.lpstrFilter =
            "AirSAR Files (*.airsar)\0*.airsar\0"
            "All Files\0*\0";
        break;

      case FORMAT_UAVSAR:
        of.lpstrFilter =
            "UAVSAR Files (*.ann)\0*.ann\0"
            "All Files\0*\0";
        break;

      case FORMAT_TERRASARX:
        of.lpstrFilter =
            "TerraSAR-X Metadata Files (*.xml)\0*.xml\0"
            "All Files\0*\0";
        break;

      case FORMAT_RADARSAT2:
        of.lpstrFilter =
            "Radarsat-2 Metadata Files (*.xml)\0*.xml\0"
            "All Files\0*\0";
        break;

      case FORMAT_ROIPAC:
        of.lpstrFilter =
            "ROI_PAC Metadata Files (*.rsc)\0*.rsc\0"
            "All Files\0*\0";
        break;

      case FORMAT_ALOS_MOSAIC:
        of.lpstrFilter =
            "ALOS mosaic Metadata Files (*HDR.txt, *HDR.txt)\0*HDR.txt;*HDR\0"
            "All Files\0*\0";
        break;

      case FORMAT_GEOTIFF:
        of.lpstrFilter =
            "GeoTIFF Files (*.tif, *.tiff)\0*.tif;*.tiff\0"
            "All Files\0*\0";
        break;

      case FORMAT_ASF_INTERNAL:
        of.lpstrFilter =
            "ASF Internal Files (*.img)\0*.img\0"
            "All Files\0*\0";
        break;
    }

    of.lpstrCustomFilter = NULL;
    of.nFilterIndex = 1;
    of.lpstrFile = fname;
    of.nMaxFile = sizeof(fname);
    of.lpstrFileTitle = NULL;
    of.lpstrInitialDir = ".";
    of.lpstrTitle = "Select File";
    of.lpstrDefExt = NULL;
    of.Flags = OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_EXPLORER;

    retval = GetOpenFileName(&of);

    if (!retval) {
        if (CommDlgExtendedError())
            message_box("File dialog box error");
        return;
    }

    /* the returned "fname" has the following form:            */
    /*   <directory>\0<first file>\0<second file>\0<third ...  */
    char * dir = STRDUP(fname);
    char * p = fname + strlen(dir) + 1;

    if (*p) {
        while (*p) {
            char * dir_and_file =
                malloc(sizeof(char)*(strlen(dir)+strlen(p)+5));
            sprintf(dir_and_file, "%s%c%s", dir, DIR_SEPARATOR, p);
            add_to_files_list(dir_and_file);
            p += strlen(p) + 1;
            free(dir_and_file);
        }
    }
    else {
        add_to_files_list(dir);
    }

    free(dir);

#else // #ifdef win32

    /* Linux version -- use GtkFileChooser if possible */

#ifdef USE_GTK_FILE_CHOOSER

    if (GTK_IS_WIDGET(browse_widget))
      gtk_widget_destroy(browse_widget);
    create_file_chooser_dialog(sel);

    gtk_widget_show(browse_widget);

#else // #ifdef USE_GTK_FILE_CHOOSER

    GtkWidget *file_selection_dialog =
        get_widget_checked("input_file_selection");

    gtk_widget_show(file_selection_dialog);

#endif // #ifdef USE_GTK_FILE_CHOOSER
#endif // #ifdef win32
}
コード例 #27
0
ファイル: InstallerOptions.cpp プロジェクト: kichik/nsis-1
LRESULT WINAPI WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) {
  switch (codeNotify) {
    case BN_CLICKED:    // The user pressed a button
    case LBN_SELCHANGE: // The user changed the selection in a ListBox control
//  case CBN_SELCHANGE: // The user changed the selection in a DropList control (same value as LBN_SELCHANGE)
    {
      char szBrowsePath[MAX_PATH];
      int nIdx = FindControlIdx(id);
      if (nIdx < 0)
        break;
      if (pFields[nIdx].nType == FIELD_BROWSEBUTTON)
        --nIdx;
      FieldType *pField = pFields + nIdx;
      switch (pField->nType) {
        case FIELD_FILEREQUEST: {
          OPENFILENAME ofn={0,};

          ofn.lStructSize = sizeof(ofn);
          ofn.hwndOwner = hConfigWindow;
          ofn.lpstrFilter = pField->pszFilter;
          ofn.lpstrFile = szBrowsePath;
          ofn.nMaxFile  = sizeof(szBrowsePath);
          ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);

          GetWindowText(pField->hwnd, szBrowsePath, sizeof(szBrowsePath));

        tryagain:
          if ((pField->nFlags & FLAG_SAVEAS) ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)) {
            mySetWindowText(pField->hwnd, szBrowsePath);
            break;
          }
          else if (szBrowsePath[0] && CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
            szBrowsePath[0] = '\0';
            goto tryagain;
          }

          break;
        }

        case FIELD_DIRREQUEST: {
          BROWSEINFO bi;

          bi.hwndOwner = hConfigWindow;
          bi.pidlRoot = NULL;
          bi.pszDisplayName = szBrowsePath;
          bi.lpszTitle = pField->pszText;
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040
#endif
          bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
          bi.lpfn = BrowseCallbackProc;
          bi.lParam = nIdx;
          bi.iImage = 0;

          if (pField->pszRoot) {
            LPSHELLFOLDER sf;
            ULONG eaten;
            LPITEMIDLIST root;
            int ccRoot = (lstrlen(pField->pszRoot) * 2) + 2;
            LPWSTR pwszRoot = (LPWSTR) MALLOC(ccRoot);
            MultiByteToWideChar(CP_ACP, 0, pField->pszRoot, -1, pwszRoot, ccRoot);
            SHGetDesktopFolder(&sf);
            sf->ParseDisplayName(hConfigWindow, NULL, pwszRoot, &eaten, &root, NULL);
            bi.pidlRoot = root;
            sf->Release();
            FREE(pwszRoot);
          }
//          CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
          LPITEMIDLIST pResult = SHBrowseForFolder(&bi);
          if (!pResult)
            break;

          if (SHGetPathFromIDList(pResult, szBrowsePath)) {
            mySetWindowText(pField->hwnd, szBrowsePath);
          }

          LPMALLOC pMalloc;
          if (!SHGetMalloc(&pMalloc)) {
            pMalloc->Free(pResult);
          }

          break;
        }

        case FIELD_LINK:
        case FIELD_BUTTON:
          // Allow the state to be empty - this might be useful in conjunction
          // with the NOTIFY flag
          if (*pField->pszState)
            ShellExecute(hMainWindow, NULL, pField->pszState, NULL, NULL, SW_SHOWDEFAULT);
          break;
      }

      if (pField->nFlags & LBS_NOTIFY) {
        // Remember which control was activated then pretend the user clicked Next
        g_NotifyField = nIdx + 1;
        // the next button must be enabled or nsis will ignore WM_COMMAND
        BOOL bWasDisabled = EnableWindow(hNextButton, TRUE);
        FORWARD_WM_COMMAND(hMainWindow, IDOK, hNextButton, BN_CLICKED, mySendMessage);
        if (bWasDisabled)
          EnableWindow(hNextButton, FALSE);
      }
    }
    break;
  }
  return 0;
}
コード例 #28
0
ファイル: shellprint.c プロジェクト: dvincent/frontier
boolean shellinitprint (void) {
	
	/*
	 9/5/90 dmb: close print resources after initializing stuff
	 
	 10/21/91 dmb: added margins field to print info; structure is now here to 
	 have user-settable margins.
	 
	 12/31/91 dmb: initialize shellprintinfo.paperrect to standard 72dpi values in 
	 case no printer is chosen and shellcopyprintinfo never gets called
	 
	 1/18/93 dmb: don't call shellcheckprinterror the first time; if PrOpen fails 
	 here, we don't want to raise an alert.
	 */
	
#if MACVERSION && !TARGET_API_MAC_CARBON
	
	Handle h;
	
#endif
	
	currentprintport = NULL;
	
	clearbytes (&shellprintinfo, longsizeof (shellprintinfo));
	
	setrect (&shellprintinfo.margins, 36, 36, 36, 36);
	
	setrect (&shellprintinfo.paperrect, 5, 6, 725, 546); /*defaults in case PrOpen fails*/
	
	shellprintinfo.scaleMult = 1;
	shellprintinfo.scaleDiv = 1;
	
#ifdef MACVERSION
	
#	if TARGET_API_MAC_CARBON == 1
	
	//I realized this is only called once during the startup of the app.
	//Carbon printing really doesn't need any global structures. Better to 
	//allocate them as we use them.
	
	// Nope.
	// We need a global var for calling page setup
	
	shellprintinfo.printport = nil;
	shellprintinfo.printhandle = nil;
	shellprintinfo.pageformat = nil;
	shellprintinfo.printsettings = nil;
	// shellprintinfo.pagerect = {0,0,0,0};
	
#	else		
	
	if (!newclearhandle (longsizeof (TPrint), &h))
		return (false);
	
	shellprintinfo.printhandle = (THPrint) h; /*copy into print record*/
	
	PrOpen (); /*initialize the Mac print manager*/
	
	if (PrError () != noErr)
		goto error;
	
	PrintDefault (shellprintinfo.printhandle); /*set default print record*/
	
	PrClose (); /*shouldn't leave print resources open all the time*/
	
	if (!shellcheckprinterror (false)) 
		goto error;
#	endif
	
#endif
	
#ifdef WIN95VERSION
	
	ZeroMemory (&shellprintinfo.pagesetupinfo, sizeof (PAGESETUPDLG));
	
	shellprintinfo.pagesetupinfo.lStructSize = sizeof (PAGESETUPDLG);
	
	shellprintinfo.pagesetupinfo.hwndOwner = NULL;
	
	shellprintinfo.pagesetupinfo.Flags = PSD_RETURNDEFAULT | PSD_NOWARNING;
	
	if (! PageSetupDlg (&shellprintinfo.pagesetupinfo)) {
		
		if (CommDlgExtendedError() != 0)
			goto error;
	}
	
#endif
	
	//#if !TARGET_API_MAC_CARBON
	
	shellcopyprintinfo (); /*copies fields from handle into record*/
	
	//#endif
	
	return (true);
	
#if !defined(MACVERSION) || !TARGET_API_MAC_CARBON
	
error:
		
#endif
		
		/*
		 shelldisposeprintinfo ();
		 */
		
		return (false);
} /*shellinitprint*/
コード例 #29
0
ファイル: wdegetfn.c プロジェクト: Azarien/open-watcom-v2
char *WdeGetFileName( WdeGetFileStruct *gf, DWORD flags, WdeGetFileNameAction action )
{
    OPENFILENAME        wdeofn;
    HWND                owner_window;
    DWORD               error;
    char                fn_drive[_MAX_DRIVE];
    char                fn_dir[_MAX_DIR];
    char                fn_name[_MAX_FNAME];
    char                fn_ext[_MAX_EXT];
    char                ext[_MAX_EXT + 1];
    HINSTANCE           app_inst;
    int                 len;
    int                 filter;
    bool                ret;

    if( gf == NULL ) {
        return( NULL );
    }

    owner_window = WdeGetMainWindowHandle();
    app_inst = WdeGetAppInstance();

    if( app_inst == NULL || owner_window == NULL ) {
        return( NULL );
    }

    /* set the initial directory */
    if( *wde_initial_dir == '\0' ) {
        getcwd( wde_initial_dir, MAXFILENAME );
    }

    if( gf->title != NULL ) {
        len = strlen( gf->title );
        if ( len < MAX_NAME ) {
            memcpy( wdefntitle, gf->title, len + 1 );
        } else {
            memcpy( wdefntitle, gf->title, MAX_NAME );
            wdefntitle[MAX_NAME - 1] = 0;
        }
    } else {
        wdefntitle[0] = 0;
    }

    filter = 0;

    if( gf->file_name != NULL && *gf->file_name != '\0' ) {
        _splitpath( gf->file_name, fn_drive, fn_dir, fn_name, fn_ext );
        if( *fn_drive != '\0' || *fn_dir != '\0' ) {
            _makepath( wde_initial_dir, fn_drive, fn_dir, NULL, NULL );
        }
        _makepath( wde_file_name, NULL, NULL, fn_name, fn_ext );
        if( fn_ext[0] != '\0' ) {
            ext[0] = '*';
            strcpy( ext + 1, fn_ext );
            filter = WdeFindFileFilterIndex( gf->filter, ext );
        }
    } else {
        wde_file_name[0] = 0;
    }

    if( filter == 0 ) {
        filter = WdeFindFileFilterIndex( gf->filter, WdeFileFilter );
        if( filter < 1 ) {
            filter = 1;
        }
    }

    // CTL3D no longer requires this
#if !defined( __NT__ )
    flags |= OFN_ENABLEHOOK;
#endif
    /* initialize the OPENFILENAME struct */
    memset( &wdeofn, 0, sizeof( OPENFILENAME ) );

    /* fill in non-variant fields of OPENFILENAME struct */
    wdeofn.lStructSize = sizeof( OPENFILENAME );
    wdeofn.hwndOwner = owner_window;
    wdeofn.hInstance = app_inst;
    wdeofn.lpstrFilter = gf->filter;
    wdeofn.lpstrCustomFilter = NULL;
    wdeofn.nMaxCustFilter = 0;
    wdeofn.nFilterIndex = filter;
    wdeofn.lpstrFile = wde_file_name;
    wdeofn.nMaxFile = MAXFILENAME;
    wdeofn.lpstrFileTitle = wdefntitle;
    wdeofn.nMaxFileTitle = MAXFILENAME;
    wdeofn.lpstrInitialDir = wde_initial_dir;
    wdeofn.lpstrTitle = wdefntitle;
    wdeofn.Flags = flags;
#if !defined( __NT__ )
    wdeofn.lpfnHook = (LPOFNHOOKPROC)MakeProcInstance( (FARPROC)WdeOpenHookProc, app_inst );
#endif

#if 0
    wdeofn.nFileOffset = 0L;
    wdeofn.nFileExtension = 0L;
    wdeofn.lpstrDefExt = NULL;
    wdeofn.lCustData = NULL;
    wdeofn.lpfnHook = NULL;
    wdeofn.lpTemplateName = NULL;
#endif

    if( action == WDEOPENFILE ) {
        ret = GetOpenFileName( (LPOPENFILENAME)&wdeofn );
    } else if( action == WDESAVEFILE ) {
        ret = GetSaveFileName( (LPOPENFILENAME)&wdeofn );
    } else {
        return( NULL );
    }

#ifndef __NT__
    if( wdeofn.lpfnHook != NULL ) {
        FreeProcInstance( (FARPROC)wdeofn.lpfnHook );
    }
#endif

    gf->fn_offset = wdeofn.nFileOffset;
    gf->ext_offset = wdeofn.nFileExtension;

    /* show the dialog box */
    if( !ret ) {
        error = CommDlgExtendedError();
        if( error ) {
            WdeDisplayErrorMsg( WDE_ERRORSELECTINGFILE );
        }
        return( NULL );
    } else {
        memcpy( wde_initial_dir, wde_file_name, wdeofn.nFileOffset );
        if( wde_initial_dir[wdeofn.nFileOffset - 1] == '\\' &&
            wde_initial_dir[wdeofn.nFileOffset - 2] != ':' ) {
            wde_initial_dir[wdeofn.nFileOffset - 1] = '\0';
        } else {
            wde_initial_dir[wdeofn.nFileOffset] = '\0';
        }
        _splitpath( wde_file_name, NULL, NULL, NULL, fn_ext + 1 );
        if( fn_ext[1] != '\0' ) {
            fn_ext[0] = '*';
            WdeSetFileFilter( fn_ext );
        } else {
            char *out_ext;
            out_ext = WdeFindFileFilterFromIndex( gf->filter, wdeofn.nFilterIndex );
            if( out_ext[2] != '*' ) {
                strcat( wde_file_name, &out_ext[1] );
            }
        }
    }

    UpdateWindow( WdeGetMainWindowHandle() );

    return( WdeStrDup( wde_file_name ) );
}
コード例 #30
0
ファイル: Print.cpp プロジェクト: iamplaced/sumatrapdf
void OnMenuPrint(WindowInfo *win, bool waitForCompletion)
{
    // we remember some printer settings per process
    static ScopedMem<DEVMODE> defaultDevMode;
    static PrintScaleAdv defaultScaleAdv = PrintScaleShrink;
    static bool defaultAsImage = false;

    bool printSelection = false;
    Vec<PRINTPAGERANGE> ranges;
    PRINTER_INFO_2 printerInfo = { 0 };

    if (!HasPermission(Perm_PrinterAccess)) return;

    DisplayModel *dm = win->dm;
    assert(dm);
    if (!dm) return;

    if (!dm->engine || !dm->engine->AllowsPrinting())
        return;

    if (win->IsChm()) {
        win->dm->AsChmEngine()->PrintCurrentPage();
        return;
    }

    if (win->printThread) {
        int res = MessageBox(win->hwndFrame, _TR("Printing is still in progress. Abort and start over?"), _TR("Printing in progress."), MB_ICONEXCLAMATION | MB_YESNO | (IsUIRightToLeft() ? MB_RTLREADING : 0));
        if (res == IDNO)
            return;
    }
    AbortPrinting(win);

    PRINTDLGEX pd;
    ZeroMemory(&pd, sizeof(PRINTDLGEX));
    pd.lStructSize = sizeof(PRINTDLGEX);
    pd.hwndOwner   = win->hwndFrame;
    pd.Flags       = PD_USEDEVMODECOPIESANDCOLLATE | PD_COLLATE;
    if (!win->selectionOnPage)
        pd.Flags |= PD_NOSELECTION;
    pd.nCopies     = 1;
    /* by default print all pages */
    pd.nPageRanges = 1;
    pd.nMaxPageRanges = MAXPAGERANGES;
    PRINTPAGERANGE *ppr = AllocArray<PRINTPAGERANGE>(MAXPAGERANGES);
    pd.lpPageRanges = ppr;
    ppr->nFromPage = 1;
    ppr->nToPage = dm->PageCount();
    pd.nMinPage = 1;
    pd.nMaxPage = dm->PageCount();
    pd.nStartPage = START_PAGE_GENERAL;

    Print_Advanced_Data advanced(PrintRangeAll, defaultScaleAdv, defaultAsImage);
    ScopedMem<DLGTEMPLATE> dlgTemplate; // needed for RTL languages
    HPROPSHEETPAGE hPsp = CreatePrintAdvancedPropSheet(&advanced, dlgTemplate);
    pd.lphPropertyPages = &hPsp;
    pd.nPropertyPages = 1;

    // restore remembered settings
    if (defaultDevMode)
        pd.hDevMode = GlobalMemDup(defaultDevMode.Get(), defaultDevMode.Get()->dmSize + defaultDevMode.Get()->dmDriverExtra);

    if (PrintDlgEx(&pd) != S_OK) {
        if (CommDlgExtendedError() != 0) {
            /* if PrintDlg was cancelled then
               CommDlgExtendedError is zero, otherwise it returns the
               error code, which we could look at here if we wanted.
               for now just warn the user that printing has stopped
               becasue of an error */
            MessageBox(win->hwndFrame, _TR("Couldn't initialize printer"), _TR("Printing problem."), MB_ICONEXCLAMATION | MB_OK | (IsUIRightToLeft() ? MB_RTLREADING : 0));
        }
        goto Exit;
    }

    if (pd.dwResultAction == PD_RESULT_PRINT || pd.dwResultAction == PD_RESULT_APPLY) {
        // remember settings for this process
        LPDEVMODE devMode = (LPDEVMODE)GlobalLock(pd.hDevMode);
        if (devMode) {
            defaultDevMode.Set((LPDEVMODE)memdup(devMode, devMode->dmSize + devMode->dmDriverExtra));
            GlobalUnlock(pd.hDevMode);
        }
        defaultScaleAdv = advanced.scale;
        defaultAsImage = advanced.asImage;
    }

    if (pd.dwResultAction != PD_RESULT_PRINT)
        goto Exit;

    if (pd.Flags & PD_CURRENTPAGE) {
        PRINTPAGERANGE pr = { dm->CurrentPageNo(), dm->CurrentPageNo() };
        ranges.Append(pr);
    } else if (win->selectionOnPage && (pd.Flags & PD_SELECTION)) {
        printSelection = true;
    } else if (!(pd.Flags & PD_PAGENUMS)) {
        PRINTPAGERANGE pr = { 1, dm->PageCount() };
        ranges.Append(pr);
    } else {
        assert(pd.nPageRanges > 0);
        for (DWORD i = 0; i < pd.nPageRanges; i++)
            ranges.Append(pd.lpPageRanges[i]);
    }

    LPDEVNAMES devNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
    LPDEVMODE devMode = (LPDEVMODE)GlobalLock(pd.hDevMode);
    if (devNames) {
        printerInfo.pDriverName = (LPWSTR)devNames + devNames->wDriverOffset;
        printerInfo.pPrinterName = (LPWSTR)devNames + devNames->wDeviceOffset;
        printerInfo.pPortName = (LPWSTR)devNames + devNames->wOutputOffset;
    }
    PrintData *data = new PrintData(dm->engine, &printerInfo, devMode, ranges, advanced,
                                    dm->Rotation(), printSelection ? win->selectionOnPage : NULL);
    if (devNames)
        GlobalUnlock(pd.hDevNames);
    if (devMode)
        GlobalUnlock(pd.hDevMode);

    if (!waitForCompletion)
        PrintToDeviceOnThread(win, data);
    else {
        PrintToDevice(*data);
        delete data;
    }

Exit:
    free(ppr);
    GlobalFree(pd.hDevNames);
    GlobalFree(pd.hDevMode);
}