diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lldirpicker.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r-- | linden/indra/newview/lldirpicker.cpp | 285 |
1 files changed, 285 insertions, 0 deletions
diff --git a/linden/indra/newview/lldirpicker.cpp b/linden/indra/newview/lldirpicker.cpp new file mode 100644 index 0000000..38a008c --- /dev/null +++ b/linden/indra/newview/lldirpicker.cpp | |||
@@ -0,0 +1,285 @@ | |||
1 | /** | ||
2 | * @file lldirpicker.cpp | ||
3 | * @brief OS-specific file picker | ||
4 | * | ||
5 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "lldirpicker.h" | ||
31 | //#include "viewer.h" | ||
32 | //#include "llviewermessage.h" | ||
33 | #include "llworld.h" | ||
34 | #include "llviewerwindow.h" | ||
35 | #include "llkeyboard.h" | ||
36 | #include "lldir.h" | ||
37 | #include "llframetimer.h" | ||
38 | |||
39 | // | ||
40 | // Globals | ||
41 | // | ||
42 | |||
43 | LLDirPicker LLDirPicker::sInstance; | ||
44 | |||
45 | #if LL_WINDOWS | ||
46 | #include <shlobj.h> | ||
47 | #endif | ||
48 | |||
49 | // | ||
50 | // Implementation | ||
51 | // | ||
52 | #if LL_WINDOWS | ||
53 | |||
54 | LLDirPicker::LLDirPicker() | ||
55 | { | ||
56 | } | ||
57 | |||
58 | LLDirPicker::~LLDirPicker() | ||
59 | { | ||
60 | // nothing | ||
61 | } | ||
62 | |||
63 | BOOL LLDirPicker::getDir(LLString* filename) | ||
64 | { | ||
65 | if( mLocked ) | ||
66 | { | ||
67 | return FALSE; | ||
68 | } | ||
69 | BOOL success = FALSE; | ||
70 | |||
71 | // Modal, so pause agent | ||
72 | send_agent_pause(); | ||
73 | |||
74 | BROWSEINFO bi; | ||
75 | memset(&bi, 0, sizeof(bi)); | ||
76 | |||
77 | bi.ulFlags = BIF_USENEWUI; | ||
78 | bi.hwndOwner = (HWND)gViewerWindow->getPlatformWindow(); | ||
79 | bi.lpszTitle = NULL; | ||
80 | |||
81 | ::OleInitialize(NULL); | ||
82 | |||
83 | LPITEMIDLIST pIDL = ::SHBrowseForFolder(&bi); | ||
84 | |||
85 | if(pIDL != NULL) | ||
86 | { | ||
87 | WCHAR buffer[_MAX_PATH] = {'\0'}; | ||
88 | |||
89 | if(::SHGetPathFromIDList(pIDL, buffer) != 0) | ||
90 | { | ||
91 | // Set the string value. | ||
92 | |||
93 | mDir = utf16str_to_utf8str(llutf16string(buffer)); | ||
94 | success = TRUE; | ||
95 | } | ||
96 | |||
97 | // free the item id list | ||
98 | CoTaskMemFree(pIDL); | ||
99 | } | ||
100 | |||
101 | ::OleUninitialize(); | ||
102 | |||
103 | send_agent_resume(); | ||
104 | |||
105 | // Account for the fact that the app has been stalled. | ||
106 | LLFrameTimer::updateFrameTime(); | ||
107 | return success; | ||
108 | } | ||
109 | |||
110 | LLString LLDirPicker::getDirName() | ||
111 | { | ||
112 | return mDir; | ||
113 | } | ||
114 | |||
115 | /////////////////////////////////////////////DARWIN | ||
116 | #elif LL_DARWIN | ||
117 | |||
118 | LLDirPicker::LLDirPicker() | ||
119 | { | ||
120 | reset(); | ||
121 | |||
122 | memset(&mNavOptions, 0, sizeof(mNavOptions)); | ||
123 | OSStatus error = NavGetDefaultDialogCreationOptions(&mNavOptions); | ||
124 | if (error == noErr) | ||
125 | { | ||
126 | mNavOptions.modality = kWindowModalityAppModal; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | LLDirPicker::~LLDirPicker() | ||
131 | { | ||
132 | // nothing | ||
133 | } | ||
134 | |||
135 | //static | ||
136 | pascal void LLDirPicker::doNavCallbackEvent(NavEventCallbackMessage callBackSelector, | ||
137 | NavCBRecPtr callBackParms, void* callBackUD) | ||
138 | { | ||
139 | switch(callBackSelector) | ||
140 | { | ||
141 | case kNavCBStart: | ||
142 | { | ||
143 | if (!sInstance.mFileName) break; | ||
144 | |||
145 | OSStatus error = noErr; | ||
146 | AEDesc theLocation = {typeNull, NULL}; | ||
147 | FSSpec outFSSpec; | ||
148 | |||
149 | //Convert string to a FSSpec | ||
150 | FSRef myFSRef; | ||
151 | |||
152 | const char* filename=sInstance.mFileName->c_str(); | ||
153 | |||
154 | error = FSPathMakeRef ((UInt8*)filename, &myFSRef, NULL); | ||
155 | |||
156 | if (error != noErr) break; | ||
157 | |||
158 | error = FSGetCatalogInfo (&myFSRef, kFSCatInfoNone, NULL, NULL, &outFSSpec, NULL); | ||
159 | |||
160 | if (error != noErr) break; | ||
161 | |||
162 | error = AECreateDesc(typeFSS, &outFSSpec, sizeof(FSSpec), &theLocation); | ||
163 | |||
164 | if (error != noErr) break; | ||
165 | |||
166 | error = NavCustomControl(callBackParms->context, | ||
167 | kNavCtlSetLocation, (void*)&theLocation); | ||
168 | |||
169 | } | ||
170 | } | ||
171 | } | ||
172 | |||
173 | OSStatus LLDirPicker::doNavChooseDialog() | ||
174 | { | ||
175 | OSStatus error = noErr; | ||
176 | NavDialogRef navRef = NULL; | ||
177 | NavReplyRecord navReply; | ||
178 | |||
179 | memset(&navReply, 0, sizeof(navReply)); | ||
180 | |||
181 | // NOTE: we are passing the address of a local variable here. | ||
182 | // This is fine, because the object this call creates will exist for less than the lifetime of this function. | ||
183 | // (It is destroyed by NavDialogDispose() below.) | ||
184 | |||
185 | error = NavCreateChooseFolderDialog(&mNavOptions, &doNavCallbackEvent, NULL, NULL, &navRef); | ||
186 | |||
187 | gViewerWindow->mWindow->beforeDialog(); | ||
188 | |||
189 | if (error == noErr) | ||
190 | error = NavDialogRun(navRef); | ||
191 | |||
192 | gViewerWindow->mWindow->afterDialog(); | ||
193 | |||
194 | if (error == noErr) | ||
195 | error = NavDialogGetReply(navRef, &navReply); | ||
196 | |||
197 | if (navRef) | ||
198 | NavDialogDispose(navRef); | ||
199 | |||
200 | if (error == noErr && navReply.validRecord) | ||
201 | { | ||
202 | FSRef fsRef; | ||
203 | AEKeyword theAEKeyword; | ||
204 | DescType typeCode; | ||
205 | Size actualSize = 0; | ||
206 | char path[LL_MAX_PATH]; | ||
207 | |||
208 | memset(&fsRef, 0, sizeof(fsRef)); | ||
209 | error = AEGetNthPtr(&navReply.selection, 1, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); | ||
210 | |||
211 | if (error == noErr) | ||
212 | error = FSRefMakePath(&fsRef, (UInt8*) path, sizeof(path)); | ||
213 | |||
214 | if (error == noErr) | ||
215 | mDir = path; | ||
216 | } | ||
217 | |||
218 | return error; | ||
219 | } | ||
220 | |||
221 | BOOL LLDirPicker::getDir(LLString* filename) | ||
222 | { | ||
223 | if( mLocked ) return FALSE; | ||
224 | BOOL success = FALSE; | ||
225 | OSStatus error = noErr; | ||
226 | |||
227 | mFileName = filename; | ||
228 | |||
229 | // mNavOptions.saveFileName | ||
230 | |||
231 | // Modal, so pause agent | ||
232 | send_agent_pause(); | ||
233 | { | ||
234 | error = doNavChooseDialog(); | ||
235 | } | ||
236 | send_agent_resume(); | ||
237 | if (error == noErr) | ||
238 | { | ||
239 | if (mDir.length() > 0) | ||
240 | success = true; | ||
241 | } | ||
242 | |||
243 | // Account for the fact that the app has been stalled. | ||
244 | LLFrameTimer::updateFrameTime(); | ||
245 | return success; | ||
246 | } | ||
247 | |||
248 | LLString LLDirPicker::getDirName() | ||
249 | { | ||
250 | return mDir; | ||
251 | } | ||
252 | |||
253 | void LLDirPicker::reset() | ||
254 | { | ||
255 | mLocked = FALSE; | ||
256 | mDir = NULL; | ||
257 | } | ||
258 | |||
259 | #else // not implemented | ||
260 | |||
261 | LLDirPicker::LLDirPicker() | ||
262 | { | ||
263 | reset(); | ||
264 | } | ||
265 | |||
266 | LLDirPicker::~LLDirPicker() | ||
267 | { | ||
268 | } | ||
269 | |||
270 | |||
271 | void LLDirPicker::reset() | ||
272 | { | ||
273 | } | ||
274 | |||
275 | BOOL LLDirPicker::getDir(LLString* filename) | ||
276 | { | ||
277 | return FALSE; | ||
278 | } | ||
279 | |||
280 | LLString LLDirPicker::getDirName() | ||
281 | { | ||
282 | return ""; | ||
283 | } | ||
284 | |||
285 | #endif | ||