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 38 #include <sys/resource.h> 39 40 #include <BeBuild.h> 41 #include <Debug.h> 42 #include <FilePanel.h> 43 #include <Looper.h> 44 #include <Screen.h> 45 #include <Window.h> 46 47 #include "AutoLock.h" 48 #include "Commands.h" 49 #include "FilePanelPriv.h" 50 51 52 // prototypes for some private kernel calls that will some day be public 53 #ifndef _IMPEXP_ROOT 54 # define _IMPEXP_ROOT 55 #endif 56 57 58 // #pragma mark - BFilePanel 59 60 61 BFilePanel::BFilePanel(file_panel_mode mode, BMessenger* target, 62 const entry_ref* ref, uint32 nodeFlavors, bool multipleSelection, 63 BMessage* message, BRefFilter* filter, bool modal, 64 bool hideWhenDone) 65 { 66 // boost file descriptor limit so file panels in other apps don't have 67 // problems 68 struct rlimit rl; 69 rl.rlim_cur = 512; 70 rl.rlim_max = RLIM_SAVED_MAX; 71 setrlimit(RLIMIT_NOFILE, &rl); 72 73 BEntry startDir(ref); 74 fWindow = new TFilePanel(mode, target, &startDir, nodeFlavors, 75 multipleSelection, message, filter, 0, B_DOCUMENT_WINDOW_LOOK, 76 modal ? B_MODAL_APP_WINDOW_FEEL : B_NORMAL_WINDOW_FEEL, 77 hideWhenDone); 78 79 static_cast<TFilePanel*>(fWindow)->SetClientObject(this); 80 81 fWindow->SetIsFilePanel(true); 82 } 83 84 85 BFilePanel::~BFilePanel() 86 { 87 if (fWindow->Lock()) 88 fWindow->Quit(); 89 } 90 91 92 void 93 BFilePanel::Show() 94 { 95 AutoLock<BWindow> lock(fWindow); 96 if (!lock) 97 return; 98 99 // if the window is already showing, don't jerk the workspaces around, 100 // just pull it to us 101 uint32 workspace = 1UL << (uint32)current_workspace(); 102 uint32 windowWorkspaces = fWindow->Workspaces(); 103 if (!(windowWorkspaces & workspace)) { 104 // window in a different workspace, reopen in current 105 fWindow->SetWorkspaces(workspace); 106 } 107 108 // Position the file panel like an alert 109 BWindow* parent = dynamic_cast<BWindow*>( 110 BLooper::LooperForThread(find_thread(NULL))); 111 const BRect frame = parent != NULL ? parent->Frame() 112 : BScreen(fWindow).Frame(); 113 114 fWindow->MoveTo(fWindow->AlertPosition(frame)); 115 if (!IsShowing()) 116 fWindow->Show(); 117 118 fWindow->Activate(); 119 120 #if 1 121 // The Be Book gives the names for some of the child views so that apps 122 // could move them around if they needed to, but we have most in layouts, 123 // so once the window has been opened, we have to forcibly resize "PoseView" 124 // (fBackView) to fully invalidate its layout in case any of the controls 125 // in it have been moved. 126 fWindow->FindView("PoseView")->ResizeBy(1, 1); 127 fWindow->FindView("PoseView")->ResizeBy(-1, -1); 128 #endif 129 } 130 131 132 void 133 BFilePanel::Hide() 134 { 135 AutoLock<BWindow> lock(fWindow); 136 if (!lock) 137 return; 138 139 if (!fWindow->IsHidden()) 140 fWindow->QuitRequested(); 141 } 142 143 144 bool 145 BFilePanel::IsShowing() const 146 { 147 AutoLock<BWindow> lock(fWindow); 148 if (!lock) 149 return false; 150 151 return !fWindow->IsHidden(); 152 } 153 154 155 void 156 BFilePanel::SendMessage(const BMessenger* messenger, BMessage* message) 157 { 158 messenger->SendMessage(message); 159 } 160 161 162 file_panel_mode 163 BFilePanel::PanelMode() const 164 { 165 AutoLock<BWindow> lock(fWindow); 166 if (!lock) 167 return B_OPEN_PANEL; 168 169 if (static_cast<TFilePanel*>(fWindow)->IsSavePanel()) 170 return B_SAVE_PANEL; 171 172 return B_OPEN_PANEL; 173 } 174 175 176 BMessenger 177 BFilePanel::Messenger() const 178 { 179 BMessenger target; 180 181 AutoLock<BWindow> lock(fWindow); 182 if (!lock) 183 return target; 184 185 return *static_cast<TFilePanel*>(fWindow)->Target(); 186 } 187 188 189 void 190 BFilePanel::SetTarget(BMessenger target) 191 { 192 AutoLock<BWindow> lock(fWindow); 193 if (!lock) 194 return; 195 196 static_cast<TFilePanel*>(fWindow)->SetTarget(target); 197 } 198 199 200 void 201 BFilePanel::SetMessage(BMessage* message) 202 { 203 AutoLock<BWindow> lock(fWindow); 204 if (!lock) 205 return; 206 207 static_cast<TFilePanel*>(fWindow)->SetMessage(message); 208 } 209 210 211 void 212 BFilePanel::Refresh() 213 { 214 AutoLock<BWindow> lock(fWindow); 215 if (!lock) 216 return; 217 218 static_cast<TFilePanel*>(fWindow)->Refresh(); 219 } 220 221 222 BRefFilter* 223 BFilePanel::RefFilter() const 224 { 225 AutoLock<BWindow> lock(fWindow); 226 if (!lock) 227 return 0; 228 229 return static_cast<TFilePanel*>(fWindow)->Filter(); 230 } 231 232 233 void 234 BFilePanel::SetRefFilter(BRefFilter* filter) 235 { 236 AutoLock<BWindow> lock(fWindow); 237 if (!lock) 238 return; 239 240 static_cast<TFilePanel*>(fWindow)->SetRefFilter(filter); 241 } 242 243 244 void 245 BFilePanel::SetButtonLabel(file_panel_button button, const char* text) 246 { 247 AutoLock<BWindow> lock(fWindow); 248 if (!lock) 249 return; 250 251 static_cast<TFilePanel*>(fWindow)->SetButtonLabel(button, text); 252 } 253 254 255 void 256 BFilePanel::SetNodeFlavors(uint32 flavors) 257 { 258 AutoLock<BWindow> lock(fWindow); 259 if (!lock) 260 return; 261 262 static_cast<TFilePanel*>(fWindow)->SetNodeFlavors(flavors); 263 } 264 265 266 void 267 BFilePanel::GetPanelDirectory(entry_ref* ref) const 268 { 269 AutoLock<BWindow> lock(fWindow); 270 if (!lock) 271 return; 272 273 *ref = *static_cast<TFilePanel*>(fWindow)->TargetModel()->EntryRef(); 274 } 275 276 277 void 278 BFilePanel::SetSaveText(const char* text) 279 { 280 AutoLock<BWindow> lock(fWindow); 281 if (!lock) 282 return; 283 284 static_cast<TFilePanel*>(fWindow)->SetSaveText(text); 285 } 286 287 288 void 289 BFilePanel::SetPanelDirectory(const entry_ref* ref) 290 { 291 AutoLock<BWindow> lock(fWindow); 292 if (!lock) 293 return; 294 295 static_cast<TFilePanel*>(fWindow)->SetTo(ref); 296 } 297 298 299 void 300 BFilePanel::SetPanelDirectory(const char* path) 301 { 302 entry_ref ref; 303 status_t err = get_ref_for_path(path, &ref); 304 if (err < B_OK) 305 return; 306 307 AutoLock<BWindow> lock(fWindow); 308 if (!lock) 309 return; 310 311 static_cast<TFilePanel*>(fWindow)->SetTo(&ref); 312 } 313 314 315 void 316 BFilePanel::SetPanelDirectory(const BEntry* entry) 317 { 318 entry_ref ref; 319 320 if (entry && entry->GetRef(&ref) == B_OK) 321 SetPanelDirectory(&ref); 322 } 323 324 325 void 326 BFilePanel::SetPanelDirectory(const BDirectory* dir) 327 { 328 BEntry entry; 329 330 if (dir && (dir->GetEntry(&entry) == B_OK)) 331 SetPanelDirectory(&entry); 332 } 333 334 335 BWindow* 336 BFilePanel::Window() const 337 { 338 return fWindow; 339 } 340 341 342 void 343 BFilePanel::Rewind() 344 { 345 AutoLock<BWindow> lock(fWindow); 346 if (!lock) 347 return; 348 349 static_cast<TFilePanel*>(fWindow)->Rewind(); 350 } 351 352 353 status_t 354 BFilePanel::GetNextSelectedRef(entry_ref* ref) 355 { 356 AutoLock<BWindow> lock(fWindow); 357 if (!lock) 358 return B_ERROR; 359 360 return static_cast<TFilePanel*>(fWindow)->GetNextEntryRef(ref); 361 362 } 363 364 365 void 366 BFilePanel::SetHideWhenDone(bool on) 367 { 368 AutoLock<BWindow> lock(fWindow); 369 if (!lock) 370 return; 371 372 static_cast<TFilePanel*>(fWindow)->SetHideWhenDone(on); 373 } 374 375 376 bool 377 BFilePanel::HidesWhenDone(void) const 378 { 379 AutoLock<BWindow> lock(fWindow); 380 if (!lock) 381 return false; 382 383 return static_cast<TFilePanel*>(fWindow)->HidesWhenDone(); 384 } 385 386 387 void 388 BFilePanel::WasHidden() 389 { 390 // hook function 391 } 392 393 394 void 395 BFilePanel::SelectionChanged() 396 { 397 // hook function 398 } 399