some cleanups
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18834 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
struct popup_menu_data {
|
struct popup_menu_data {
|
||||||
BPopUpMenu *object;
|
BPopUpMenu *object;
|
||||||
@@ -264,15 +265,18 @@ BMenuItem *
|
|||||||
BPopUpMenu::_go(BPoint where, bool autoInvoke, bool startOpened,
|
BPopUpMenu::_go(BPoint where, bool autoInvoke, bool startOpened,
|
||||||
BRect *_specialRect, bool async)
|
BRect *_specialRect, bool async)
|
||||||
{
|
{
|
||||||
BMenuItem *selected = NULL;
|
popup_menu_data *data = new (nothrow) popup_menu_data;
|
||||||
|
if (!data)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
// Can't use Window(), as the BPopUpMenu isn't attached
|
|
||||||
BLooper *looper = BLooper::LooperForThread(find_thread(NULL));
|
|
||||||
BWindow *window = dynamic_cast<BWindow *>(looper);
|
|
||||||
|
|
||||||
popup_menu_data *data = new popup_menu_data;
|
|
||||||
sem_id sem = create_sem(0, "window close lock");
|
sem_id sem = create_sem(0, "window close lock");
|
||||||
|
if (sem < B_OK) {
|
||||||
|
delete data;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a pointer to the window from which Go() was called
|
||||||
|
BWindow *window = dynamic_cast<BWindow *>(BLooper::LooperForThread(find_thread(NULL)));
|
||||||
data->window = window;
|
data->window = window;
|
||||||
|
|
||||||
// Asynchronous menu: we set the BWindow menu's semaphore
|
// Asynchronous menu: we set the BWindow menu's semaphore
|
||||||
@@ -289,7 +293,7 @@ BPopUpMenu::_go(BPoint where, bool autoInvoke, bool startOpened,
|
|||||||
data->async = async;
|
data->async = async;
|
||||||
data->where = where;
|
data->where = where;
|
||||||
data->startOpened = startOpened;
|
data->startOpened = startOpened;
|
||||||
data->selected = selected;
|
data->selected = NULL;
|
||||||
data->lock = sem;
|
data->lock = sem;
|
||||||
|
|
||||||
// Spawn the tracking thread
|
// Spawn the tracking thread
|
||||||
@@ -305,22 +309,22 @@ BPopUpMenu::_go(BPoint where, bool autoInvoke, bool startOpened,
|
|||||||
|
|
||||||
resume_thread(fTrackThread);
|
resume_thread(fTrackThread);
|
||||||
|
|
||||||
// Synchronous menu: we block on the sem till
|
BMenuItem *selected = NULL;
|
||||||
// the other thread deletes it.
|
|
||||||
if (!async) {
|
if (!async) {
|
||||||
if (window) {
|
// Synchronous menu: we update the parent window in a loop,
|
||||||
// TODO: usually it's not a good idea to check for a particular error
|
// until the other thread finishes and deletes this semaphore.
|
||||||
// code. Though here we just want to wait till the semaphore is deleted
|
if (window != NULL) {
|
||||||
// (it will return B_BAD_SEM_ID in that case), not provide locking or whatever.
|
while (acquire_sem_etc(sem, 1, B_TIMEOUT, 50000) != B_BAD_SEM_ID)
|
||||||
while (acquire_sem_etc(sem, 1, B_TIMEOUT, 50000) != B_BAD_SEM_ID) {
|
|
||||||
window->UpdateIfNeeded();
|
window->UpdateIfNeeded();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t unused;
|
status_t unused;
|
||||||
while (wait_for_thread(fTrackThread, &unused) == B_INTERRUPTED)
|
while (wait_for_thread(fTrackThread, &unused) == B_INTERRUPTED)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
fTrackThread = -1;
|
||||||
|
|
||||||
selected = data->selected;
|
selected = data->selected;
|
||||||
delete data;
|
delete data;
|
||||||
}
|
}
|
||||||
@@ -359,8 +363,7 @@ BPopUpMenu::entry(void *arg)
|
|||||||
|
|
||||||
|
|
||||||
BMenuItem *
|
BMenuItem *
|
||||||
BPopUpMenu::start_track(BPoint where, bool autoInvoke,
|
BPopUpMenu::start_track(BPoint where, bool autoInvoke, bool startOpened, BRect *_specialRect)
|
||||||
bool startOpened, BRect *_specialRect)
|
|
||||||
{
|
{
|
||||||
fWhere = where;
|
fWhere = where;
|
||||||
|
|
||||||
@@ -383,8 +386,6 @@ BPopUpMenu::start_track(BPoint where, bool autoInvoke,
|
|||||||
Hide();
|
Hide();
|
||||||
be_app->ShowCursor();
|
be_app->ShowCursor();
|
||||||
|
|
||||||
fTrackThread = -1;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user