FileChooserWin.cpp [plain text]
#include "config.h"
#include "FileChooser.h"
#include "Document.h"
#include "FrameView.h"
#include "Icon.h"
#include "LocalizedStrings.h"
#include "RenderObject.h"
#include "RenderThemeWin.h"
#include "RenderView.h"
#include "StringTruncator.h"
#include <shlwapi.h>
#include <tchar.h>
#include <windows.h>
namespace WebCore {
FileChooser::FileChooser(FileChooserClient* client, const String& filename)
: m_client(client)
, m_filename(filename)
, m_icon(chooseIcon(filename))
{
}
FileChooser::~FileChooser()
{
}
void FileChooser::openFileChooser(Document* document)
{
FrameView* view = document->view();
if (!view)
return;
TCHAR fileBuf[MAX_PATH];
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
fileBuf[0] = '\0';
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = view->containingWindow();
String allFiles = allFilesText();
allFiles.append(TEXT("\0*.*\0\0"), 6);
ofn.lpstrFilter = allFiles.charactersWithNullTermination();
ofn.lpstrFile = fileBuf;
ofn.nMaxFile = sizeof(fileBuf);
String dialogTitle = uploadFileText();
ofn.lpstrTitle = dialogTitle.charactersWithNullTermination();
ofn.Flags = OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
RefPtr<FileChooser> protector(this);
if (GetOpenFileName(&ofn))
chooseFile(String(fileBuf));
}
String FileChooser::basenameForWidth(const Font& font, int width) const
{
if (width <= 0)
return String();
String string;
if (m_filename.isEmpty())
string = fileButtonNoFileSelectedLabel();
else {
String tmpFilename = m_filename;
LPTSTR basename = PathFindFileName(tmpFilename.charactersWithNullTermination());
string = String(basename);
}
return StringTruncator::centerTruncate(string, width, font, false);
}
}