Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / kits / tracker / FilePanel.cpp
blob539b7eaf5c25d29d459b8ecd4701a025ef7d6d9b
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
35 // Implementation for the public FilePanel object.
38 #include <sys/resource.h>
40 #include <BeBuild.h>
41 #include <Debug.h>
42 #include <FilePanel.h>
43 #include <Looper.h>
44 #include <Screen.h>
45 #include <Window.h>
47 #include "AutoLock.h"
48 #include "Commands.h"
49 #include "FilePanelPriv.h"
52 // prototypes for some private kernel calls that will some day be public
53 #ifndef _IMPEXP_ROOT
54 # define _IMPEXP_ROOT
55 #endif
58 // #pragma mark - BFilePanel
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)
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);
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);
79 static_cast<TFilePanel*>(fWindow)->SetClientObject(this);
81 fWindow->SetIsFilePanel(true);
85 BFilePanel::~BFilePanel()
87 if (fWindow->Lock())
88 fWindow->Quit();
92 void
93 BFilePanel::Show()
95 AutoLock<BWindow> lock(fWindow);
96 if (!lock)
97 return;
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);
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();
114 fWindow->MoveTo(fWindow->AlertPosition(frame));
115 if (!IsShowing())
116 fWindow->Show();
118 fWindow->Activate();
122 void
123 BFilePanel::Hide()
125 AutoLock<BWindow> lock(fWindow);
126 if (!lock)
127 return;
129 if (!fWindow->IsHidden())
130 fWindow->QuitRequested();
134 bool
135 BFilePanel::IsShowing() const
137 AutoLock<BWindow> lock(fWindow);
138 if (!lock)
139 return false;
141 return !fWindow->IsHidden();
145 void
146 BFilePanel::SendMessage(const BMessenger* messenger, BMessage* message)
148 messenger->SendMessage(message);
152 file_panel_mode
153 BFilePanel::PanelMode() const
155 AutoLock<BWindow> lock(fWindow);
156 if (!lock)
157 return B_OPEN_PANEL;
159 if (static_cast<TFilePanel*>(fWindow)->IsSavePanel())
160 return B_SAVE_PANEL;
162 return B_OPEN_PANEL;
166 BMessenger
167 BFilePanel::Messenger() const
169 BMessenger target;
171 AutoLock<BWindow> lock(fWindow);
172 if (!lock)
173 return target;
175 return *static_cast<TFilePanel*>(fWindow)->Target();
179 void
180 BFilePanel::SetTarget(BMessenger target)
182 AutoLock<BWindow> lock(fWindow);
183 if (!lock)
184 return;
186 static_cast<TFilePanel*>(fWindow)->SetTarget(target);
190 void
191 BFilePanel::SetMessage(BMessage* message)
193 AutoLock<BWindow> lock(fWindow);
194 if (!lock)
195 return;
197 static_cast<TFilePanel*>(fWindow)->SetMessage(message);
201 void
202 BFilePanel::Refresh()
204 AutoLock<BWindow> lock(fWindow);
205 if (!lock)
206 return;
208 static_cast<TFilePanel*>(fWindow)->Refresh();
212 BRefFilter*
213 BFilePanel::RefFilter() const
215 AutoLock<BWindow> lock(fWindow);
216 if (!lock)
217 return 0;
219 return static_cast<TFilePanel*>(fWindow)->Filter();
223 void
224 BFilePanel::SetRefFilter(BRefFilter* filter)
226 AutoLock<BWindow> lock(fWindow);
227 if (!lock)
228 return;
230 static_cast<TFilePanel*>(fWindow)->SetRefFilter(filter);
234 void
235 BFilePanel::SetButtonLabel(file_panel_button button, const char* text)
237 AutoLock<BWindow> lock(fWindow);
238 if (!lock)
239 return;
241 static_cast<TFilePanel*>(fWindow)->SetButtonLabel(button, text);
245 void
246 BFilePanel::SetNodeFlavors(uint32 flavors)
248 AutoLock<BWindow> lock(fWindow);
249 if (!lock)
250 return;
252 static_cast<TFilePanel*>(fWindow)->SetNodeFlavors(flavors);
256 void
257 BFilePanel::GetPanelDirectory(entry_ref* ref) const
259 AutoLock<BWindow> lock(fWindow);
260 if (!lock)
261 return;
263 *ref = *static_cast<TFilePanel*>(fWindow)->TargetModel()->EntryRef();
267 void
268 BFilePanel::SetSaveText(const char* text)
270 AutoLock<BWindow> lock(fWindow);
271 if (!lock)
272 return;
274 static_cast<TFilePanel*>(fWindow)->SetSaveText(text);
278 void
279 BFilePanel::SetPanelDirectory(const entry_ref* ref)
281 AutoLock<BWindow> lock(fWindow);
282 if (!lock)
283 return;
285 static_cast<TFilePanel*>(fWindow)->SetTo(ref);
289 void
290 BFilePanel::SetPanelDirectory(const char* path)
292 entry_ref ref;
293 status_t err = get_ref_for_path(path, &ref);
294 if (err < B_OK)
295 return;
297 AutoLock<BWindow> lock(fWindow);
298 if (!lock)
299 return;
301 static_cast<TFilePanel*>(fWindow)->SetTo(&ref);
305 void
306 BFilePanel::SetPanelDirectory(const BEntry* entry)
308 entry_ref ref;
310 if (entry && entry->GetRef(&ref) == B_OK)
311 SetPanelDirectory(&ref);
315 void
316 BFilePanel::SetPanelDirectory(const BDirectory* dir)
318 BEntry entry;
320 if (dir && (dir->GetEntry(&entry) == B_OK))
321 SetPanelDirectory(&entry);
325 BWindow*
326 BFilePanel::Window() const
328 return fWindow;
332 void
333 BFilePanel::Rewind()
335 AutoLock<BWindow> lock(fWindow);
336 if (!lock)
337 return;
339 static_cast<TFilePanel*>(fWindow)->Rewind();
343 status_t
344 BFilePanel::GetNextSelectedRef(entry_ref* ref)
346 AutoLock<BWindow> lock(fWindow);
347 if (!lock)
348 return B_ERROR;
350 return static_cast<TFilePanel*>(fWindow)->GetNextEntryRef(ref);
355 void
356 BFilePanel::SetHideWhenDone(bool on)
358 AutoLock<BWindow> lock(fWindow);
359 if (!lock)
360 return;
362 static_cast<TFilePanel*>(fWindow)->SetHideWhenDone(on);
366 bool
367 BFilePanel::HidesWhenDone(void) const
369 AutoLock<BWindow> lock(fWindow);
370 if (!lock)
371 return false;
373 return static_cast<TFilePanel*>(fWindow)->HidesWhenDone();
377 void
378 BFilePanel::WasHidden()
380 // hook function
384 void
385 BFilePanel::SelectionChanged()
387 // hook function