forked from gildor2/UEViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileControls.cpp
More file actions
126 lines (103 loc) · 2.95 KB
/
Copy pathFileControls.cpp
File metadata and controls
126 lines (103 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#if _WIN32
#include <ObjBase.h> // CoInitialize()
#include <Shlwapi.h> // SH* functions
#include <Shlobj.h> // SHBrowseForFolder
#undef PLATFORM_UNKNOWN
#endif // _WIN32
#include "BaseDialog.h"
#include "FileControls.h"
#if HAS_UI
#if _WIN32
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "shlwapi.lib")
#pragma comment(lib, "shell32.lib")
static void InitializeOLE()
{
static bool initialized = false;
if (initialized) return;
initialized = true;
CoInitialize(NULL);
}
#endif // _WIN32
/*-----------------------------------------------------------------------------
UIFilePathEditor
-----------------------------------------------------------------------------*/
#define BROWSE_BUTTON_WIDTH 70
UIFilePathEditor::UIFilePathEditor(FString* path)
: UIGroup(GROUP_HORIZONTAL_LAYOUT|GROUP_NO_BORDER)
, Path(path)
{
#if _WIN32
for (int i = 0; i < Path->Len(); i++)
if ((*Path)[i] == '/') (*Path)[i] = '\\';
#endif
}
void UIFilePathEditor::Create(UIBaseDialog* dialog)
{
Super::Create(dialog);
InitializeOLE();
SHAutoComplete(Editor->GetWnd(), SHACF_FILESYS_DIRS);
DlgWnd = dialog->GetWnd();
}
void UIFilePathEditor::AddCustomControls()
{
(*this)
[
NewControl(UITextEdit, Path)
.Expose(Editor)
+ NewControl(UISpacer)
+ NewControl(UIButton, "Browse ...")
.SetWidth(BROWSE_BUTTON_WIDTH)
.SetCallback(BIND_MEM_CB(&UIFilePathEditor::OnBrowseClicked, this))
];
}
static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
{
static LPARAM stored_lpData;
switch (uMsg)
{
case BFFM_INITIALIZED:
if (lpData)
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
stored_lpData = lpData;
break;
case BFFM_SELCHANGED:
if (stored_lpData)
{
// http://social.msdn.microsoft.com/Forums/vstudio/en-US/a22b664e-cb30-44f4-bf77-b7a385de49f3/shbrowseforfolder-bug-in-windows-7?forum=vcgeneral
// send BFFM_SETSELECTION after popping up the dialog again - this will fix
// out-of-view selection on Windows 7
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, stored_lpData);
stored_lpData = NULL;
}
break;
}
return 0; // The function should always return 0.
}
void UIFilePathEditor::OnBrowseClicked(UIButton* sender)
{
BROWSEINFO bi;
memset(&bi, 0, sizeof(bi));
char szDisplayName[MAX_PATH]; // will not be used
szDisplayName[0] = 0;
bi.hwndOwner = DlgWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = "Please select a directory:"; //!! customize
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lParam = (LPARAM)Editor->GetText();
bi.iImage = 0;
bi.lpfn = BrowseCallbackProc;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
char szPathName[1024];
if (pidl)
{
BOOL bRet = SHGetPathFromIDList(pidl, szPathName);
if (bRet)
{
*Path = szPathName;
Editor->SetText();
}
}
}
#endif // HAS_UI