BPopUpMenu style fixes

This commit is contained in:
John Scipione
2013-05-01 22:18:56 -04:00
parent 211e7b396d
commit 01b1b8bdaa
2 changed files with 65 additions and 59 deletions
+5 -5
View File
@@ -43,7 +43,7 @@ public:
int32 form, const char* property); int32 form, const char* property);
virtual status_t GetSupportedSuites(BMessage* data); virtual status_t GetSupportedSuites(BMessage* data);
virtual status_t Perform(perform_code code, void* data); virtual status_t Perform(perform_code code, void* _data);
virtual void ResizeToPreferred(); virtual void ResizeToPreferred();
virtual void GetPreferredSize(float* _width, virtual void GetPreferredSize(float* _width,
@@ -66,13 +66,13 @@ protected:
private: private:
BMenuItem* _Go(BPoint where, bool autoInvoke, BMenuItem* _Go(BPoint where, bool autoInvoke,
bool startOpened, BRect* specialRect, bool startOpened, BRect* _specialRect,
bool async); bool async);
BMenuItem* _StartTrack(BPoint where, bool autoInvoke, BMenuItem* _StartTrack(BPoint where, bool autoInvoke,
bool startOpened, BRect* specialRect); bool startOpened, BRect* _specialRect);
BMenuItem* _WaitMenu(void* data); BMenuItem* _WaitMenu(void* _data);
static int32 _thread_entry(void* data); static int32 _thread_entry(void* menuData);
private: private:
BPoint fWhere; BPoint fWhere;
+60 -54
View File
@@ -20,9 +20,9 @@
struct popup_menu_data { struct popup_menu_data {
BPopUpMenu *object; BPopUpMenu* object;
BWindow *window; BWindow* window;
BMenuItem *selected; BMenuItem* selected;
BPoint where; BPoint where;
BRect rect; BRect rect;
@@ -36,9 +36,10 @@ struct popup_menu_data {
}; };
BPopUpMenu::BPopUpMenu(const char *title, bool radioMode, bool autoRename, BPopUpMenu::BPopUpMenu(const char* title, bool radioMode, bool autoRename,
menu_layout layout) menu_layout layout)
: BMenu(title, layout), :
BMenu(title, layout),
fUseWhere(false), fUseWhere(false),
fAutoDestruct(false), fAutoDestruct(false),
fTrackThread(-1) fTrackThread(-1)
@@ -51,8 +52,9 @@ BPopUpMenu::BPopUpMenu(const char *title, bool radioMode, bool autoRename,
} }
BPopUpMenu::BPopUpMenu(BMessage *archive) BPopUpMenu::BPopUpMenu(BMessage* archive)
: BMenu(archive), :
BMenu(archive),
fUseWhere(false), fUseWhere(false),
fAutoDestruct(false), fAutoDestruct(false),
fTrackThread(-1) fTrackThread(-1)
@@ -71,14 +73,14 @@ BPopUpMenu::~BPopUpMenu()
status_t status_t
BPopUpMenu::Archive(BMessage *data, bool deep) const BPopUpMenu::Archive(BMessage* data, bool deep) const
{ {
return BMenu::Archive(data, deep); return BMenu::Archive(data, deep);
} }
BArchivable * BArchivable*
BPopUpMenu::Instantiate(BMessage *data) BPopUpMenu::Instantiate(BMessage* data)
{ {
if (validate_instantiation(data, "BPopUpMenu")) if (validate_instantiation(data, "BPopUpMenu"))
return new BPopUpMenu(data); return new BPopUpMenu(data);
@@ -87,14 +89,14 @@ BPopUpMenu::Instantiate(BMessage *data)
} }
BMenuItem * BMenuItem*
BPopUpMenu::Go(BPoint where, bool deliversMessage, bool openAnyway, bool async) BPopUpMenu::Go(BPoint where, bool deliversMessage, bool openAnyway, bool async)
{ {
return _Go(where, deliversMessage, openAnyway, NULL, async); return _Go(where, deliversMessage, openAnyway, NULL, async);
} }
BMenuItem * BMenuItem*
BPopUpMenu::Go(BPoint where, bool deliversMessage, bool openAnyway, BPopUpMenu::Go(BPoint where, bool deliversMessage, bool openAnyway,
BRect clickToOpen, bool async) BRect clickToOpen, bool async)
{ {
@@ -103,9 +105,9 @@ BPopUpMenu::Go(BPoint where, bool deliversMessage, bool openAnyway,
void void
BPopUpMenu::MessageReceived(BMessage *msg) BPopUpMenu::MessageReceived(BMessage* message)
{ {
BMenu::MessageReceived(msg); BMenu::MessageReceived(message);
} }
@@ -124,9 +126,9 @@ BPopUpMenu::MouseUp(BPoint point)
void void
BPopUpMenu::MouseMoved(BPoint point, uint32 code, const BMessage *msg) BPopUpMenu::MouseMoved(BPoint point, uint32 code, const BMessage* message)
{ {
BView::MouseMoved(point, code, msg); BView::MouseMoved(point, code, message);
} }
@@ -158,16 +160,16 @@ BPopUpMenu::FrameResized(float newWidth, float newHeight)
} }
BHandler * BHandler*
BPopUpMenu::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, BPopUpMenu::ResolveSpecifier(BMessage* message, int32 index,
int32 form, const char *property) BMessage* specifier, int32 form, const char* property)
{ {
return BMenu::ResolveSpecifier(msg, index, specifier, form, property); return BMenu::ResolveSpecifier(message, index, specifier, form, property);
} }
status_t status_t
BPopUpMenu::GetSupportedSuites(BMessage *data) BPopUpMenu::GetSupportedSuites(BMessage* data)
{ {
return BMenu::GetSupportedSuites(data); return BMenu::GetSupportedSuites(data);
} }
@@ -204,7 +206,7 @@ BPopUpMenu::Perform(perform_code code, void* _data)
BPopUpMenu::GetHeightForWidth(data->width, &data->min, &data->max, BPopUpMenu::GetHeightForWidth(data->width, &data->min, &data->max,
&data->preferred); &data->preferred);
return B_OK; return B_OK;
} }
case PERFORM_CODE_SET_LAYOUT: case PERFORM_CODE_SET_LAYOUT:
{ {
perform_data_set_layout* data = (perform_data_set_layout*)_data; perform_data_set_layout* data = (perform_data_set_layout*)_data;
@@ -237,7 +239,7 @@ BPopUpMenu::ResizeToPreferred()
void void
BPopUpMenu::GetPreferredSize(float *_width, float *_height) BPopUpMenu::GetPreferredSize(float* _width, float* _height)
{ {
BMenu::GetPreferredSize(_width, _height); BMenu::GetPreferredSize(_width, _height);
} }
@@ -284,9 +286,9 @@ BPopUpMenu::ScreenLocation()
if (fUseWhere) if (fUseWhere)
return fWhere; return fWhere;
BMenuItem *superItem = Superitem(); BMenuItem* superItem = Superitem();
BMenu *superMenu = Supermenu(); BMenu* superMenu = Supermenu();
BMenuItem *selectedItem = FindItem(superItem->Label()); BMenuItem* selectedItem = FindItem(superItem->Label());
BPoint point = superItem->Frame().LeftTop(); BPoint point = superItem->Frame().LeftTop();
superMenu->ConvertToScreen(&point); superMenu->ConvertToScreen(&point);
@@ -306,18 +308,17 @@ void BPopUpMenu::_ReservedPopUpMenu2() {}
void BPopUpMenu::_ReservedPopUpMenu3() {} void BPopUpMenu::_ReservedPopUpMenu3() {}
BPopUpMenu & BPopUpMenu&
BPopUpMenu::operator=(const BPopUpMenu &) BPopUpMenu::operator=(const BPopUpMenu& other)
{ {
return *this; return *this;
} }
BMenuItem * 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)
{ {
if (fTrackThread >= B_OK) { if (fTrackThread >= B_OK) {
// we already have an active menu, wait for it to go away before // we already have an active menu, wait for it to go away before
// spawning another // spawning another
@@ -325,8 +326,9 @@ BPopUpMenu::_Go(BPoint where, bool autoInvoke, bool startOpened,
while (wait_for_thread(fTrackThread, &unused) == B_INTERRUPTED) while (wait_for_thread(fTrackThread, &unused) == B_INTERRUPTED)
; ;
} }
popup_menu_data *data = new (std::nothrow) popup_menu_data;
if (!data) popup_menu_data* data = new (std::nothrow) popup_menu_data;
if (data == NULL)
return NULL; return NULL;
sem_id sem = create_sem(0, "window close lock"); sem_id sem = create_sem(0, "window close lock");
@@ -336,14 +338,14 @@ BPopUpMenu::_Go(BPoint where, bool autoInvoke, bool startOpened,
} }
// Get a pointer to the window from which Go() was called // Get a pointer to the window from which Go() was called
BWindow *window = dynamic_cast<BWindow *>(BLooper::LooperForThread(find_thread(NULL))); 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
// and let BWindow block when needed // and let BWindow block when needed
if (async && window != NULL) { if (async && window != NULL)
_set_menu_sem_(window, sem); _set_menu_sem_(window, sem);
}
data->object = this; data->object = this;
data->autoInvoke = autoInvoke; data->autoInvoke = autoInvoke;
@@ -357,7 +359,8 @@ BPopUpMenu::_Go(BPoint where, bool autoInvoke, bool startOpened,
data->lock = sem; data->lock = sem;
// Spawn the tracking thread // Spawn the tracking thread
fTrackThread = spawn_thread(_thread_entry, "popup", B_DISPLAY_PRIORITY, data); fTrackThread = spawn_thread(_thread_entry, "popup", B_DISPLAY_PRIORITY,
data);
if (fTrackThread < B_OK) { if (fTrackThread < B_OK) {
// Something went wrong. Cleanup and return NULL // Something went wrong. Cleanup and return NULL
delete_sem(sem); delete_sem(sem);
@@ -378,16 +381,17 @@ BPopUpMenu::_Go(BPoint where, bool autoInvoke, bool startOpened,
/* static */ /* static */
int32 int32
BPopUpMenu::_thread_entry(void *arg) BPopUpMenu::_thread_entry(void* menuData)
{ {
popup_menu_data *data = static_cast<popup_menu_data *>(arg); popup_menu_data* data = static_cast<popup_menu_data*>(menuData);
BPopUpMenu *menu = data->object; BPopUpMenu* menu = data->object;
BRect *rect = NULL; BRect* rect = NULL;
if (data->useRect) if (data->useRect)
rect = &data->rect; rect = &data->rect;
data->selected = menu->_StartTrack(data->where, data->autoInvoke, data->startOpened, rect); data->selected = menu->_StartTrack(data->where, data->autoInvoke,
data->startOpened, rect);
// Reset the window menu semaphore // Reset the window menu semaphore
if (data->async && data->window) if (data->async && data->window)
@@ -408,8 +412,9 @@ BPopUpMenu::_thread_entry(void *arg)
} }
BMenuItem * BMenuItem*
BPopUpMenu::_StartTrack(BPoint where, bool autoInvoke, bool startOpened, BRect *_specialRect) BPopUpMenu::_StartTrack(BPoint where, bool autoInvoke, bool startOpened,
BRect* _specialRect)
{ {
fWhere = where; fWhere = where;
@@ -418,18 +423,19 @@ BPopUpMenu::_StartTrack(BPoint where, bool autoInvoke, bool startOpened, BRect *
// called by BMenu::Track() // called by BMenu::Track()
fUseWhere = true; fUseWhere = true;
// Determine when mouse-down-up will be taken as a 'press', rather than a 'click' // Determine when mouse-down-up will be taken as a 'press',
// rather than a 'click'
bigtime_t clickMaxTime = 0; bigtime_t clickMaxTime = 0;
get_click_speed(&clickMaxTime); get_click_speed(&clickMaxTime);
clickMaxTime += system_time(); clickMaxTime += system_time();
// Show the menu's window // Show the menu's window
Show(); Show();
snooze(50000); snooze(50000);
BMenuItem *result = Track(startOpened, _specialRect); BMenuItem* result = Track(startOpened, _specialRect);
// If it was a click, keep the menu open and tracking // If it was a click, keep the menu open and tracking
if (system_time() <= clickMaxTime) if (system_time() <= clickMaxTime)
result = Track(true, _specialRect); result = Track(true, _specialRect);
if (result != NULL && autoInvoke) if (result != NULL && autoInvoke)
result->Invoke(); result->Invoke();
@@ -443,11 +449,11 @@ BPopUpMenu::_StartTrack(BPoint where, bool autoInvoke, bool startOpened, BRect *
} }
BMenuItem * BMenuItem*
BPopUpMenu::_WaitMenu(void *_data) BPopUpMenu::_WaitMenu(void* _data)
{ {
popup_menu_data *data = (popup_menu_data *)_data; popup_menu_data* data = (popup_menu_data*)_data;
BWindow *window = data->window; BWindow* window = data->window;
sem_id sem = data->lock; sem_id sem = data->lock;
if (window != NULL) { if (window != NULL) {
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)
@@ -460,7 +466,7 @@ BPopUpMenu::_WaitMenu(void *_data)
fTrackThread = -1; fTrackThread = -1;
BMenuItem *selected = data->selected; BMenuItem* selected = data->selected;
// data->selected is filled by the tracking thread // data->selected is filled by the tracking thread
delete data; delete data;