Rewrote PopUpMenu.h and MenuBar.h. Adjusted source files accordingly.

Added license to SeparatorItem.h


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22759 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-10-29 10:40:16 +00:00
parent 6ae06ef86a
commit 795a2888e7
5 changed files with 145 additions and 175 deletions
+75 -93
View File
@@ -1,13 +1,7 @@
/******************************************************************************* /*
/ * Copyright 2003-2007, Haiku, Inc. All Rights Reserved.
/ File: Menubar.h * Distributed under the terms of the MIT License.
/ */
/ Description: BMenuBar is a menu that's at the root of a menu hierarchy.
/
/ Copyright 1994-98, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _MENU_BAR_H #ifndef _MENU_BAR_H
#define _MENU_BAR_H #define _MENU_BAR_H
@@ -16,8 +10,6 @@
#include <Menu.h> #include <Menu.h>
#include <OS.h> #include <OS.h>
/*----------------------------------------------------------------*/
/*----- BmenuBar declarations ------------------------------------*/
enum menu_bar_border { enum menu_bar_border {
B_BORDER_FRAME, B_BORDER_FRAME,
@@ -30,100 +22,90 @@ class BWindow;
class BMenuItem; class BMenuItem;
class BMenuField; class BMenuField;
/*----------------------------------------------------------------*/
/*----- BMenuBar class -------------------------------------------*/
class BMenuBar : public BMenu class BMenuBar : public BMenu {
{ public:
public: BMenuBar(BRect frame, const char *title,
BMenuBar(BRect frame, uint32 resizeMask = B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
const char *title, menu_layout layout = B_ITEMS_IN_ROW,
uint32 resizeMask = bool resizeToFit = true);
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, BMenuBar(const char *title, menu_layout layout = B_ITEMS_IN_ROW,
menu_layout layout = B_ITEMS_IN_ROW, uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS);
bool resizeToFit = true); BMenuBar(BMessage *data);
BMenuBar(const char *title, virtual ~BMenuBar();
menu_layout layout = B_ITEMS_IN_ROW,
uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS); static BArchivable* Instantiate(BMessage *data);
BMenuBar(BMessage *data); virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual ~BMenuBar();
static BArchivable *Instantiate(BMessage *data);
virtual status_t Archive(BMessage *data, bool deep = true) const;
virtual void SetBorder(menu_bar_border border); virtual void SetBorder(menu_bar_border border);
menu_bar_border Border() const; menu_bar_border Border() const;
virtual void Draw(BRect updateRect);
virtual void AttachedToWindow(); virtual void Draw(BRect updateRect);
virtual void DetachedFromWindow(); virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *msg); virtual void DetachedFromWindow();
virtual void MouseDown(BPoint where); virtual void MessageReceived(BMessage *message);
virtual void WindowActivated(bool state); virtual void MouseDown(BPoint where);
virtual void MouseUp(BPoint where); virtual void WindowActivated(bool state);
virtual void FrameMoved(BPoint new_position); virtual void MouseUp(BPoint where);
virtual void FrameResized(float new_width, float new_height); virtual void FrameMoved(BPoint newPosition);
virtual void FrameResized(float newWidth, float newHeight);
virtual void Show();
virtual void Hide();
virtual void Show(); virtual BHandler* ResolveSpecifier(BMessage *message, int32 index,
virtual void Hide(); BMessage *specifier, int32 form,
const char *property);
virtual status_t GetSupportedSuites(BMessage *data);
virtual BHandler *ResolveSpecifier(BMessage *msg, virtual void ResizeToPreferred();
int32 index, virtual void GetPreferredSize(float *width, float *height);
BMessage *specifier, virtual void MakeFocus(bool state = true);
int32 form, virtual void AllAttached();
const char *property); virtual void AllDetached();
virtual status_t GetSupportedSuites(BMessage *data);
virtual void ResizeToPreferred(); // layout related
virtual void GetPreferredSize(float *width, float *height); virtual BSize MinSize();
virtual void MakeFocus(bool state = true); virtual BSize MaxSize();
virtual void AllAttached(); virtual BSize PreferredSize();
virtual void AllDetached();
virtual status_t Perform(perform_code code, void *arg);
private:
friend class BWindow;
friend class BMenuField;
friend class BMenu;
// layout related virtual void _ReservedMenuBar1();
virtual BSize MinSize(); virtual void _ReservedMenuBar2();
virtual BSize MaxSize(); virtual void _ReservedMenuBar3();
virtual BSize PreferredSize(); virtual void _ReservedMenuBar4();
/*----- Private or reserved -----------------------------------------*/ BMenuBar &operator=(const BMenuBar &);
virtual status_t Perform(perform_code d, void *arg);
private: // TODO: Tracker uses this function so we can't change
friend class BWindow; // its signature without breaking it
friend class BMenuItem; void StartMenuBar(int32 menuIndex, bool sticky = true,
friend class BMenuField; bool showMenu = false,
friend class BMenu; BRect *special_rect = NULL);
static int32 _TrackTask(void *arg);
BMenuItem *_Track(int32 *action, int32 startIndex = -1,
bool showMenu = false);
void _StealFocus();
void _RestoreFocus();
void _InitData(menu_layout layout);
virtual void _ReservedMenuBar1(); menu_bar_border fBorder;
virtual void _ReservedMenuBar2(); thread_id fTrackingPID;
virtual void _ReservedMenuBar3(); int32 fPrevFocusToken;
virtual void _ReservedMenuBar4(); sem_id fMenuSem;
BRect* fLastBounds;
uint32 _reserved[2]; // was 3
BMenuBar &operator=(const BMenuBar &); bool fTracking;
void StartMenuBar( int32 menuIndex,
bool sticky = true,
bool show_menu = false,
BRect *special_rect = NULL);
static long TrackTask(void *arg);
BMenuItem *Track( int32 *action,
int32 startIndex = -1,
bool showMenu = false);
void StealFocus();
void RestoreFocus();
void InitData(menu_layout layout);
menu_bar_border fBorder;
thread_id fTrackingPID;
int32 fPrevFocusToken;
sem_id fMenuSem;
BRect* fLastBounds;
uint32 _reserved[2]; // was 3
bool fTracking;
}; };
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
#endif /* _MENU_BAR_H */ #endif /* _MENU_BAR_H */
+49 -66
View File
@@ -1,90 +1,75 @@
/******************************************************************************* /*
/ * Copyright 2007, Haiku, Inc. All Rights Reserved.
/ File: PopUpMenu.h * Distributed under the terms of the MIT License.
/ */
/ Description: BPopUpMenu represents a menu that pops up when you
/ activate it.
/
/ Copyright 1994-98, Be Incorporated, All Rights Reserved
/
*******************************************************************************/
#ifndef _POP_UP_MENU_H #ifndef _POP_UP_MENU_H
#define _POP_UP_MENU_H #define _POP_UP_MENU_H
#include <BeBuild.h> #include <BeBuild.h>
#include <Menu.h> #include <Menu.h>
/*----------------------------------------------------------------*/ class BPopUpMenu : public BMenu {
/*----- BPopUpMenu class -----------------------------------------*/ public:
BPopUpMenu(const char *title, bool radioMode = true,
bool autoRename = true,
menu_layout layout = B_ITEMS_IN_COLUMN);
BPopUpMenu(BMessage *data);
virtual ~BPopUpMenu();
virtual status_t Archive(BMessage *data, bool deep = true) const;
static BArchivable* Instantiate(BMessage *data);
class BPopUpMenu : public BMenu BMenuItem* Go(BPoint where, bool autoInvoke = false,
{ bool keepOpen = false,
public:
BPopUpMenu( const char *title,
bool radioMode = true,
bool autoRename = true,
menu_layout layout = B_ITEMS_IN_COLUMN
);
BPopUpMenu(BMessage *data);
virtual ~BPopUpMenu();
virtual status_t Archive(BMessage *data, bool deep = true) const;
static BArchivable *Instantiate(BMessage *data);
BMenuItem *Go(BPoint where,
bool delivers_message = false,
bool open_anyway = false,
bool async = false); bool async = false);
BMenuItem *Go(BPoint where, BMenuItem* Go(BPoint where, bool autoInvoke,
bool delivers_message, bool keepOpen,
bool open_anyway, BRect openRect,
BRect click_to_open,
bool async = false); bool async = false);
virtual void MessageReceived(BMessage *msg); virtual void MessageReceived(BMessage *message);
virtual void MouseDown(BPoint pt); virtual void MouseDown(BPoint point);
virtual void MouseUp(BPoint pt); virtual void MouseUp(BPoint point);
virtual void MouseMoved(BPoint pt, uint32 code, const BMessage *msg); virtual void MouseMoved(BPoint point, uint32 code,
virtual void AttachedToWindow(); const BMessage *message);
virtual void DetachedFromWindow(); virtual void AttachedToWindow();
virtual void FrameMoved(BPoint new_position); virtual void DetachedFromWindow();
virtual void FrameResized(float new_width, float new_height); virtual void FrameMoved(BPoint newPosition);
virtual void FrameResized(float newWidth, float newHeight);
virtual BHandler *ResolveSpecifier(BMessage *msg, virtual BHandler* ResolveSpecifier(BMessage *message, int32 index,
int32 index, BMessage *specifier, int32 form,
BMessage *specifier, const char *property);
int32 form, virtual status_t GetSupportedSuites(BMessage *data);
const char *property);
virtual status_t GetSupportedSuites(BMessage *data);
virtual status_t Perform(perform_code d, void *arg); virtual status_t Perform(perform_code code, void *arg);
virtual void ResizeToPreferred(); virtual void ResizeToPreferred();
virtual void GetPreferredSize(float *width, float *height); virtual void GetPreferredSize(float *width, float *height);
virtual void MakeFocus(bool state = true); virtual void MakeFocus(bool state = true);
virtual void AllAttached(); virtual void AllAttached();
virtual void AllDetached(); virtual void AllDetached();
void SetAsyncAutoDestruct(bool state); void SetAsyncAutoDestruct(bool state);
bool AsyncAutoDestruct() const; bool AsyncAutoDestruct() const;
protected: protected:
virtual BPoint ScreenLocation(); virtual BPoint ScreenLocation();
virtual void _ReservedPopUpMenu1(); virtual void _ReservedPopUpMenu1();
virtual void _ReservedPopUpMenu2(); virtual void _ReservedPopUpMenu2();
virtual void _ReservedPopUpMenu3(); virtual void _ReservedPopUpMenu3();
BPopUpMenu &operator=(const BPopUpMenu &); BPopUpMenu &operator=(const BPopUpMenu &);
/*----- Private or reserved -----------------------------------------*/ private:
private:
BMenuItem *_Go(BPoint where, bool autoInvoke, bool startOpened, BMenuItem *_Go(BPoint where, bool autoInvoke, bool startOpened,
BRect *specialRect, bool async); BRect *specialRect, bool async);
BMenuItem *_StartTrack(BPoint where, bool autoInvoke, bool startOpened, BRect *specialRect); BMenuItem *_StartTrack(BPoint where, bool autoInvoke,
bool startOpened, BRect *specialRect);
BMenuItem *_WaitMenu(void *data); BMenuItem *_WaitMenu(void *data);
static int32 _thread_entry(void *); static int32 _thread_entry(void *);
BPoint fWhere; BPoint fWhere;
bool fUseWhere; bool fUseWhere;
@@ -95,7 +80,5 @@ static int32 _thread_entry(void *);
uint32 _reserved[3]; uint32 _reserved[3];
}; };
/*-------------------------------------------------------------*/
/*-------------------------------------------------------------*/
#endif /* _POP_UP_MENU_H */ #endif /* _POP_UP_MENU_H */
+5
View File
@@ -1,3 +1,8 @@
/*
* Copyright 2001-2007, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
*/
#ifndef _SEPARATOR_ITEM_H #ifndef _SEPARATOR_ITEM_H
#define _SEPARATOR_ITEM_H #define _SEPARATOR_ITEM_H
+2 -2
View File
@@ -2162,7 +2162,7 @@ BMenu::_SetStickyMode(bool on)
if (on && menuBar != NULL && menuBar->LockLooper()) { if (on && menuBar != NULL && menuBar->LockLooper()) {
// Steal the focus from the current focus view // Steal the focus from the current focus view
// (needed to handle keyboard navigation) // (needed to handle keyboard navigation)
menuBar->StealFocus(); menuBar->_StealFocus();
menuBar->UnlockLooper(); menuBar->UnlockLooper();
} }
@@ -2332,7 +2332,7 @@ BMenu::QuitTracking()
{ {
_SelectItem(NULL); _SelectItem(NULL);
if (BMenuBar *menuBar = dynamic_cast<BMenuBar *>(this)) if (BMenuBar *menuBar = dynamic_cast<BMenuBar *>(this))
menuBar->RestoreFocus(); menuBar->_RestoreFocus();
fChosenItem = NULL; fChosenItem = NULL;
fState = MENU_STATE_CLOSED; fState = MENU_STATE_CLOSED;
+14 -14
View File
@@ -47,7 +47,7 @@ BMenuBar::BMenuBar(BRect frame, const char *title, uint32 resizeMask,
fLastBounds(NULL), fLastBounds(NULL),
fTracking(false) fTracking(false)
{ {
InitData(layout); _InitData(layout);
} }
@@ -62,7 +62,7 @@ BMenuBar::BMenuBar(const char *title, menu_layout layout, uint32 flags)
fLastBounds(NULL), fLastBounds(NULL),
fTracking(false) fTracking(false)
{ {
InitData(layout); _InitData(layout);
} }
@@ -83,7 +83,7 @@ BMenuBar::BMenuBar(BMessage *data)
menu_layout layout = B_ITEMS_IN_COLUMN; menu_layout layout = B_ITEMS_IN_COLUMN;
data->FindInt32("_layout", (int32 *)&layout); data->FindInt32("_layout", (int32 *)&layout);
InitData(layout); _InitData(layout);
} }
@@ -390,7 +390,7 @@ BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu, BRect *speci
fMenuSem = create_sem(0, "window close sem"); fMenuSem = create_sem(0, "window close sem");
_set_menu_sem_(window, fMenuSem); _set_menu_sem_(window, fMenuSem);
fTrackingPID = spawn_thread(TrackTask, "menu_tracking", B_DISPLAY_PRIORITY, NULL); fTrackingPID = spawn_thread(_TrackTask, "menu_tracking", B_DISPLAY_PRIORITY, NULL);
if (fTrackingPID >= 0) { if (fTrackingPID >= 0) {
menubar_data data; menubar_data data;
data.menuBar = this; data.menuBar = this;
@@ -412,21 +412,21 @@ BMenuBar::StartMenuBar(int32 menuIndex, bool sticky, bool showMenu, BRect *speci
} }
long /* static */
BMenuBar::TrackTask(void *arg) int32
BMenuBar::_TrackTask(void *arg)
{ {
menubar_data data; menubar_data data;
thread_id id; thread_id id;
receive_data(&id, &data, sizeof(data)); receive_data(&id, &data, sizeof(data));
BMenuBar *menuBar = data.menuBar; BMenuBar *menuBar = data.menuBar;
if (data.useRect) if (data.useRect)
menuBar->fExtraRect = &data.rect; menuBar->fExtraRect = &data.rect;
menuBar->_SetStickyMode(data.sticky); menuBar->_SetStickyMode(data.sticky);
int32 action; int32 action;
menuBar->Track(&action, data.menuIndex, data.showMenu); menuBar->_Track(&action, data.menuIndex, data.showMenu);
menuBar->fTracking = false; menuBar->fTracking = false;
menuBar->fExtraRect = NULL; menuBar->fExtraRect = NULL;
@@ -458,7 +458,7 @@ point_distance(const BPoint &pointA, const BPoint &pointB)
BMenuItem * BMenuItem *
BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu) BMenuBar::_Track(int32 *action, int32 startIndex, bool showMenu)
{ {
// TODO: Cleanup, merge some "if" blocks if possible // TODO: Cleanup, merge some "if" blocks if possible
fChosenItem = NULL; fChosenItem = NULL;
@@ -588,7 +588,7 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
if (fChosenItem != NULL) if (fChosenItem != NULL)
fChosenItem->Invoke(); fChosenItem->Invoke();
RestoreFocus(); _RestoreFocus();
window->Unlock(); window->Unlock();
} }
@@ -605,7 +605,7 @@ BMenuBar::Track(int32 *action, int32 startIndex, bool showMenu)
void void
BMenuBar::StealFocus() BMenuBar::_StealFocus()
{ {
// We already stole the focus, don't do anything // We already stole the focus, don't do anything
if (fPrevFocusToken != -1) if (fPrevFocusToken != -1)
@@ -623,7 +623,7 @@ BMenuBar::StealFocus()
void void
BMenuBar::RestoreFocus() BMenuBar::_RestoreFocus()
{ {
BWindow *window = Window(); BWindow *window = Window();
if (window != NULL && window->Lock()) { if (window != NULL && window->Lock()) {
@@ -644,7 +644,7 @@ BMenuBar::RestoreFocus()
void void
BMenuBar::InitData(menu_layout layout) BMenuBar::_InitData(menu_layout layout)
{ {
fLastBounds = new BRect(Bounds()); fLastBounds = new BRect(Bounds());
SetItemMargins(8, 2, 8, 2); SetItemMargins(8, 2, 8, 2);