llfilepicker.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:32k
- /**
- * @file llfilepicker.cpp
- * @brief OS-specific file picker
- *
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2010, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #include "llviewerprecompiledheaders.h"
- #include "llfilepicker.h"
- #include "llworld.h"
- #include "llviewerwindow.h"
- #include "llkeyboard.h"
- #include "lldir.h"
- #include "llframetimer.h"
- #include "lltrans.h"
- #include "llwindow.h" // beforeDialog()
- #if LL_SDL
- #include "llwindowsdl.h" // for some X/GTK utils to help with filepickers
- #endif // LL_SDL
- //
- // Globals
- //
- LLFilePicker LLFilePicker::sInstance;
- #if LL_WINDOWS
- #define SOUND_FILTER L"Sounds (*.wav) *.wav "
- #define IMAGE_FILTER L"Images (*.tga; *.bmp; *.jpg; *.jpeg; *.png) *.tga;*.bmp;*.jpg;*.jpeg;*.png "
- #define ANIM_FILTER L"Animations (*.bvh) *.bvh "
- #ifdef _CORY_TESTING
- #define GEOMETRY_FILTER L"SL Geometry (*.slg) *.slg "
- #endif
- #define XML_FILTER L"XML files (*.xml) *.xml "
- #define SLOBJECT_FILTER L"Objects (*.slobject) *.slobject "
- #define RAW_FILTER L"RAW files (*.raw) *.raw "
- #endif
- //
- // Implementation
- //
- LLFilePicker::LLFilePicker()
- : mCurrentFile(0),
- mLocked(false)
- {
- reset();
- #if LL_WINDOWS
- mOFN.lStructSize = sizeof(OPENFILENAMEW);
- mOFN.hwndOwner = NULL; // Set later
- mOFN.hInstance = NULL;
- mOFN.lpstrCustomFilter = NULL;
- mOFN.nMaxCustFilter = 0;
- mOFN.lpstrFile = NULL; // set in open and close
- mOFN.nMaxFile = LL_MAX_PATH;
- mOFN.lpstrFileTitle = NULL;
- mOFN.nMaxFileTitle = 0;
- mOFN.lpstrInitialDir = NULL;
- mOFN.lpstrTitle = NULL;
- mOFN.Flags = 0; // set in open and close
- mOFN.nFileOffset = 0;
- mOFN.nFileExtension = 0;
- mOFN.lpstrDefExt = NULL;
- mOFN.lCustData = 0L;
- mOFN.lpfnHook = NULL;
- mOFN.lpTemplateName = NULL;
- mFilesW[0] = ' ';
- #endif
- #if LL_DARWIN
- memset(&mNavOptions, 0, sizeof(mNavOptions));
- OSStatus error = NavGetDefaultDialogCreationOptions(&mNavOptions);
- if (error == noErr)
- {
- mNavOptions.modality = kWindowModalityAppModal;
- }
- #endif
- }
- LLFilePicker::~LLFilePicker()
- {
- // nothing
- }
- const std::string LLFilePicker::getFirstFile()
- {
- mCurrentFile = 0;
- return getNextFile();
- }
- const std::string LLFilePicker::getNextFile()
- {
- if (mCurrentFile >= getFileCount())
- {
- mLocked = false;
- return std::string();
- }
- else
- {
- return mFiles[mCurrentFile++];
- }
- }
- const std::string LLFilePicker::getCurFile()
- {
- if (mCurrentFile >= getFileCount())
- {
- mLocked = false;
- return std::string();
- }
- else
- {
- return mFiles[mCurrentFile];
- }
- }
- void LLFilePicker::reset()
- {
- mLocked = false;
- mFiles.clear();
- mCurrentFile = 0;
- }
- #if LL_WINDOWS
- BOOL LLFilePicker::setupFilter(ELoadFilter filter)
- {
- BOOL res = TRUE;
- switch (filter)
- {
- case FFLOAD_ALL:
- mOFN.lpstrFilter = L"All Files (*.*) *.* "
- SOUND_FILTER
- IMAGE_FILTER
- ANIM_FILTER
- L"