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.
35 // Implementation for the public FilePanel object.
38 #include <sys/resource.h>
42 #include <FilePanel.h>
49 #include "FilePanelPriv.h"
52 // prototypes for some private kernel calls that will some day be public
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
,
66 // boost file descriptor limit so file panels in other apps don't have
70 rl
.rlim_max
= RLIM_SAVED_MAX
;
71 setrlimit(RLIMIT_NOFILE
, &rl
);
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
,
79 static_cast<TFilePanel
*>(fWindow
)->SetClientObject(this);
81 fWindow
->SetIsFilePanel(true);
85 BFilePanel::~BFilePanel()
95 AutoLock
<BWindow
> lock(fWindow
);
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
));
125 AutoLock
<BWindow
> lock(fWindow
);
129 if (!fWindow
->IsHidden())
130 fWindow
->QuitRequested();
135 BFilePanel::IsShowing() const
137 AutoLock
<BWindow
> lock(fWindow
);
141 return !fWindow
->IsHidden();
146 BFilePanel::SendMessage(const BMessenger
* messenger
, BMessage
* message
)
148 messenger
->SendMessage(message
);
153 BFilePanel::PanelMode() const
155 AutoLock
<BWindow
> lock(fWindow
);
159 if (static_cast<TFilePanel
*>(fWindow
)->IsSavePanel())
167 BFilePanel::Messenger() const
171 AutoLock
<BWindow
> lock(fWindow
);
175 return *static_cast<TFilePanel
*>(fWindow
)->Target();
180 BFilePanel::SetTarget(BMessenger target
)
182 AutoLock
<BWindow
> lock(fWindow
);
186 static_cast<TFilePanel
*>(fWindow
)->SetTarget(target
);
191 BFilePanel::SetMessage(BMessage
* message
)
193 AutoLock
<BWindow
> lock(fWindow
);
197 static_cast<TFilePanel
*>(fWindow
)->SetMessage(message
);
202 BFilePanel::Refresh()
204 AutoLock
<BWindow
> lock(fWindow
);
208 static_cast<TFilePanel
*>(fWindow
)->Refresh();
213 BFilePanel::RefFilter() const
215 AutoLock
<BWindow
> lock(fWindow
);
219 return static_cast<TFilePanel
*>(fWindow
)->Filter();
224 BFilePanel::SetRefFilter(BRefFilter
* filter
)
226 AutoLock
<BWindow
> lock(fWindow
);
230 static_cast<TFilePanel
*>(fWindow
)->SetRefFilter(filter
);
235 BFilePanel::SetButtonLabel(file_panel_button button
, const char* text
)
237 AutoLock
<BWindow
> lock(fWindow
);
241 static_cast<TFilePanel
*>(fWindow
)->SetButtonLabel(button
, text
);
246 BFilePanel::SetNodeFlavors(uint32 flavors
)
248 AutoLock
<BWindow
> lock(fWindow
);
252 static_cast<TFilePanel
*>(fWindow
)->SetNodeFlavors(flavors
);
257 BFilePanel::GetPanelDirectory(entry_ref
* ref
) const
259 AutoLock
<BWindow
> lock(fWindow
);
263 *ref
= *static_cast<TFilePanel
*>(fWindow
)->TargetModel()->EntryRef();
268 BFilePanel::SetSaveText(const char* text
)
270 AutoLock
<BWindow
> lock(fWindow
);
274 static_cast<TFilePanel
*>(fWindow
)->SetSaveText(text
);
279 BFilePanel::SetPanelDirectory(const entry_ref
* ref
)
281 AutoLock
<BWindow
> lock(fWindow
);
285 static_cast<TFilePanel
*>(fWindow
)->SetTo(ref
);
290 BFilePanel::SetPanelDirectory(const char* path
)
293 status_t err
= get_ref_for_path(path
, &ref
);
297 AutoLock
<BWindow
> lock(fWindow
);
301 static_cast<TFilePanel
*>(fWindow
)->SetTo(&ref
);
306 BFilePanel::SetPanelDirectory(const BEntry
* entry
)
310 if (entry
&& entry
->GetRef(&ref
) == B_OK
)
311 SetPanelDirectory(&ref
);
316 BFilePanel::SetPanelDirectory(const BDirectory
* dir
)
320 if (dir
&& (dir
->GetEntry(&entry
) == B_OK
))
321 SetPanelDirectory(&entry
);
326 BFilePanel::Window() const
335 AutoLock
<BWindow
> lock(fWindow
);
339 static_cast<TFilePanel
*>(fWindow
)->Rewind();
344 BFilePanel::GetNextSelectedRef(entry_ref
* ref
)
346 AutoLock
<BWindow
> lock(fWindow
);
350 return static_cast<TFilePanel
*>(fWindow
)->GetNextEntryRef(ref
);
356 BFilePanel::SetHideWhenDone(bool on
)
358 AutoLock
<BWindow
> lock(fWindow
);
362 static_cast<TFilePanel
*>(fWindow
)->SetHideWhenDone(on
);
367 BFilePanel::HidesWhenDone(void) const
369 AutoLock
<BWindow
> lock(fWindow
);
373 return static_cast<TFilePanel
*>(fWindow
)->HidesWhenDone();
378 BFilePanel::WasHidden()
385 BFilePanel::SelectionChanged()