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