8#include <osgViewer/Viewer>
9#include <osgViewer/api/Win32/GraphicsWindowWin32>
11#include <simgear/debug/logstream.hxx>
12#include <simgear/misc/strutils.hxx>
22 osgViewer::Viewer::Windows windows;
23 if (!
globals->get_renderer() || !
globals->get_renderer()->getViewerBase()) {
27 globals->get_renderer()->getViewerBase()->getWindows(windows);
28 osgViewer::Viewer::Windows::const_iterator it = windows.begin();
29 for(; it != windows.end(); ++it) {
30 if (strcmp((*it)->className(),
"GraphicsWindowWin32")) {
34 osgViewer::GraphicsWindowWin32* platformWin =
35 static_cast<osgViewer::GraphicsWindowWin32*
>(*it);
36 return platformWin->getHWND();
42static int CALLBACK BrowseFolderCallback(
43 HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
45 if (uMsg == BFFM_INITIALIZED) {
49 ::SendMessageW(hwnd, BFFM_SETSELECTIONW,
true, (LPARAM) w.c_str());
69 char Filestring[MAX_PATH] =
"\0";
70 OPENFILENAMEA opf = {0};
71 opf.lStructSize =
sizeof(OPENFILENAME);
72 opf.lpstrFile = Filestring;
73 opf.lpstrTitle =
const_cast<char *
>(
_title.c_str());
74 opf.nMaxFile = MAX_PATH;
76 std::string extensions;
77 size_t extensionsLen=0;
80 if (!simgear::strutils::starts_with(ext,
"*.")) {
81 SG_LOG(SG_GENERAL, SG_ALERT,
"WindowsFileDialog: can't use pattern on Windows:" << ext);
84 extensions +=
"("+ext+
")\0"+ext+
"\0";
85 extensionsLen += ext.size()*2+4;
87 opf.lpstrFilter = (LPCSTR) malloc(extensionsLen);
88 memcpy((
void*)opf.lpstrFilter, (
void*)extensions.data(), extensionsLen);
92 opf.lpstrInitialDir =
const_cast<char *
>(s.c_str());
95 opf.Flags = OFN_PATHMUSTEXIST;
99 if (GetSaveFileNameA(&opf)) {
100 std::string stringPath(opf.lpstrFile);
101 _callback->onFileDialogDone(
this, stringPath);
106 if (GetOpenFileNameA(&opf)) {
107 std::string stringPath(opf.lpstrFile);
108 _callback->onFileDialogDone(
this, stringPath);
118void WindowsFileDialog::chooseDir()
123 char pathBuf[MAX_PATH] =
"\0";
126 memset(&binfo, 0,
sizeof(BROWSEINFOA));
128 binfo.ulFlags = BIF_USENEWUI | BIF_RETURNONLYFSDIRS | BIF_EDITBOX;
130 binfo.pidlRoot = NULL;
131 binfo.lpszTitle =
const_cast<char *
>(
_title.c_str());
132 binfo.lpfn = BrowseFolderCallback;
133 binfo.lParam =
reinterpret_cast<LPARAM
>(
this);
135 PIDLIST_ABSOLUTE results = SHBrowseForFolderA(&binfo);
136 if (results == NULL) {
141 SHGetPathFromIDListA(results, pathBuf);
142 CoTaskMemFree(results);
144 _callback->onFileDialogDone(
this, SGPath(pathBuf));
string_list _filterPatterns
SGPath getDirectory() const
std::unique_ptr< Callback > _callback
WindowsFileDialog(FGFileDialog::Usage use)
virtual ~WindowsFileDialog()