1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 35 // Implementation for the public FilePanel object. 36 37 #include <sys/resource.h> 38 39 #include <BeBuild.h> 40 #include <Debug.h> 41 #include <FilePanel.h> 42 43 #include "AutoLock.h" 44 #include "Commands.h" 45 #include "FilePanelPriv.h" 46 47 48 // prototypes for some private kernel calls that will some day be public 49 #ifndef _IMPEXP_ROOT 50 # define _IMPEXP_ROOT 51 #endif 52 #ifndef _IMPEXP_TRACKER 53 # define _IMPEXP_TRACKER 54 #endif 55 56 // these two calls are deprecated 57 extern _IMPEXP_TRACKER void run_open_panel(); 58 extern _IMPEXP_TRACKER void run_save_panel(); 59 60 61 void 62 run_open_panel() 63 { 64 (new TFilePanel())->Show(); 65 } 66 67 void 68 run_save_panel() 69 { 70 (new TFilePanel(B_SAVE_PANEL))->Show(); 71 } 72 73 74 // #pragma mark - 75 76 77 BFilePanel::BFilePanel(file_panel_mode mode, BMessenger *target, 78 const entry_ref *ref, uint32 nodeFlavors, bool multipleSelection, 79 BMessage *message, BRefFilter *filter, bool modal, 80 bool hideWhenDone) 81 { 82 // boost file descriptor limit so file panels in other apps don't have 83 // problems 84 struct rlimit rl; 85 rl.rlim_cur = 512; 86 rl.rlim_max = RLIM_SAVED_MAX; 87 setrlimit(RLIMIT_NOFILE, &rl); 88 89 BEntry startDir(ref); 90 fWindow = new TFilePanel(mode, target, &startDir, nodeFlavors, 91 multipleSelection, message, filter, 0, B_DOCUMENT_WINDOW_LOOK, 92 modal ? B_MODAL_APP_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL, 93 hideWhenDone); 94 95 static_cast<TFilePanel *>(fWindow)->SetClientObject(this); 96 97 fWindow->SetIsFilePanel(true); 98 } 99 100 BFilePanel::~BFilePanel() 101 { 102 if (fWindow->Lock()) 103 fWindow->Quit(); 104 } 105 106 void 107 BFilePanel::Show() 108 { 109 AutoLock<BWindow> lock(fWindow); 110 if (!lock) 111 return; 112 113 // if the window is already showing, don't jerk the workspaces around, 114 // just pull it to us 115 uint32 workspace = 1UL << (uint32)current_workspace(); 116 uint32 windowWorkspaces = fWindow->Workspaces(); 117 if (!(windowWorkspaces & workspace)) 118 // window in a different workspace, reopen in current 119 fWindow->SetWorkspaces(workspace); 120 121 if (!IsShowing()) 122 fWindow->Show(); 123 124 fWindow->Activate(); 125 } 126 127 void 128 BFilePanel::Hide() 129 { 130 AutoLock<BWindow> lock(fWindow); 131 if (!lock) 132 return; 133 134 if (!fWindow->IsHidden()) 135 fWindow->QuitRequested(); 136 } 137 138 bool 139 BFilePanel::IsShowing() const 140 { 141 AutoLock<BWindow> lock(fWindow); 142 if (!lock) 143 return false; 144 145 return !fWindow->IsHidden(); 146 } 147 148 149 void 150 BFilePanel::SendMessage(const BMessenger *messenger, BMessage *message) 151 { 152 messenger->SendMessage(message); 153 } 154 155 file_panel_mode 156 BFilePanel::PanelMode() const 157 { 158 AutoLock<BWindow> lock(fWindow); 159 if (!lock) 160 return B_OPEN_PANEL; 161 162 if (static_cast<TFilePanel *>(fWindow)->IsSavePanel()) 163 return B_SAVE_PANEL; 164 165 return B_OPEN_PANEL; 166 } 167 168 BMessenger 169 BFilePanel::Messenger() const 170 { 171 BMessenger target; 172 173 AutoLock<BWindow> lock(fWindow); 174 if (!lock) 175 return target; 176 177 return *static_cast<TFilePanel *>(fWindow)->Target(); 178 } 179 180 void 181 BFilePanel::SetTarget(BMessenger target) 182 { 183 AutoLock<BWindow> lock(fWindow); 184 if (!lock) 185 return; 186 187 static_cast<TFilePanel *>(fWindow)->SetTarget(target); 188 } 189 190 void 191 BFilePanel::SetMessage(BMessage *message) 192 { 193 AutoLock<BWindow> lock(fWindow); 194 if (!lock) 195 return; 196 197 static_cast<TFilePanel *>(fWindow)->SetMessage(message); 198 } 199 200 void 201 BFilePanel::Refresh() 202 { 203 AutoLock<BWindow> lock(fWindow); 204 if (!lock) 205 return; 206 207 static_cast<TFilePanel *>(fWindow)->Refresh(); 208 } 209 210 BRefFilter * 211 BFilePanel::RefFilter() const 212 { 213 AutoLock<BWindow> lock(fWindow); 214 if (!lock) 215 return 0; 216 217 return static_cast<TFilePanel *>(fWindow)->Filter(); 218 } 219 220 void 221 BFilePanel::SetRefFilter(BRefFilter *filter) 222 { 223 AutoLock<BWindow> lock(fWindow); 224 if (!lock) 225 return; 226 227 static_cast<TFilePanel *>(fWindow)->SetRefFilter(filter); 228 } 229 230 void 231 BFilePanel::SetButtonLabel(file_panel_button button, const char *text) 232 { 233 AutoLock<BWindow> lock(fWindow); 234 if (!lock) 235 return; 236 237 static_cast<TFilePanel *>(fWindow)->SetButtonLabel(button, text); 238 } 239 240 void 241 BFilePanel::GetPanelDirectory(entry_ref *ref) const 242 { 243 AutoLock<BWindow> lock(fWindow); 244 if (!lock) 245 return; 246 247 *ref = *static_cast<TFilePanel *>(fWindow)->TargetModel()->EntryRef(); 248 } 249 250 void 251 BFilePanel::SetSaveText(const char *text) 252 { 253 AutoLock<BWindow> lock(fWindow); 254 if (!lock) 255 return; 256 257 static_cast<TFilePanel *>(fWindow)->SetSaveText(text); 258 } 259 260 void 261 BFilePanel::SetPanelDirectory(const entry_ref *ref) 262 { 263 AutoLock<BWindow> lock(fWindow); 264 if (!lock) 265 return; 266 267 static_cast<TFilePanel *>(fWindow)->SetTo(ref); 268 } 269 270 void 271 BFilePanel::SetPanelDirectory(const char *path) 272 { 273 entry_ref ref; 274 status_t err = get_ref_for_path(path, &ref); 275 if (err < B_OK) 276 return; 277 278 AutoLock<BWindow> lock(fWindow); 279 if (!lock) 280 return; 281 282 static_cast<TFilePanel *>(fWindow)->SetTo(&ref); 283 } 284 285 void 286 BFilePanel::SetPanelDirectory(const BEntry *entry) 287 { 288 entry_ref ref; 289 290 if (entry && entry->GetRef(&ref) == B_OK) 291 SetPanelDirectory(&ref); 292 } 293 294 void 295 BFilePanel::SetPanelDirectory(const BDirectory *dir) 296 { 297 BEntry entry; 298 299 if (dir && (dir->GetEntry(&entry) == B_OK)) 300 SetPanelDirectory(&entry); 301 } 302 303 BWindow * 304 BFilePanel::Window() const 305 { 306 return fWindow; 307 } 308 309 void 310 BFilePanel::Rewind() 311 { 312 AutoLock<BWindow> lock(fWindow); 313 if (!lock) 314 return; 315 316 static_cast<TFilePanel *>(fWindow)->Rewind(); 317 } 318 319 status_t 320 BFilePanel::GetNextSelectedRef(entry_ref *ref) 321 { 322 AutoLock<BWindow> lock(fWindow); 323 if (!lock) 324 return B_ERROR; 325 326 return static_cast<TFilePanel *>(fWindow)->GetNextEntryRef(ref); 327 328 } 329 330 331 void 332 BFilePanel::SetHideWhenDone(bool on) 333 { 334 AutoLock<BWindow> lock(fWindow); 335 if (!lock) 336 return; 337 338 static_cast<TFilePanel *>(fWindow)->SetHideWhenDone(on); 339 } 340 341 bool 342 BFilePanel::HidesWhenDone(void) const 343 { 344 AutoLock<BWindow> lock(fWindow); 345 if (!lock) 346 return false; 347 348 return static_cast<TFilePanel *>(fWindow)->HidesWhenDone(); 349 } 350 351 void 352 BFilePanel::WasHidden() 353 { 354 // hook function 355 } 356 357 void 358 BFilePanel::SelectionChanged() 359 { 360 // hook function 361 } 362 363