2007-09-30 14:52:45 +04:00
|
|
|
/*
|
2013-05-07 00:53:21 +04:00
|
|
|
* Copyright 2007-2013 Haiku, Inc. All rights reserved.
|
2009-08-27 15:12:41 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
2007-09-30 14:52:45 +04:00
|
|
|
*/
|
2002-10-23 17:54:44 +04:00
|
|
|
#ifndef _MENU_H
|
|
|
|
#define _MENU_H
|
|
|
|
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
#include <InterfaceDefs.h>
|
|
|
|
#include <List.h>
|
|
|
|
#include <View.h>
|
|
|
|
|
2013-05-07 00:50:23 +04:00
|
|
|
|
2007-10-16 00:13:55 +04:00
|
|
|
class BMenu;
|
2002-10-23 17:54:44 +04:00
|
|
|
class BMenuBar;
|
2007-10-16 00:13:55 +04:00
|
|
|
class BMenuItem;
|
2006-11-22 14:52:18 +03:00
|
|
|
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2006-11-22 14:52:18 +03:00
|
|
|
namespace BPrivate {
|
|
|
|
class BMenuWindow;
|
2007-09-30 14:52:45 +04:00
|
|
|
class ExtraMenuData;
|
|
|
|
class TriggerList;
|
2008-04-11 12:22:09 +04:00
|
|
|
class MenuPrivate;
|
2006-11-22 14:52:18 +03:00
|
|
|
}
|
2002-10-23 17:54:44 +04:00
|
|
|
|
|
|
|
enum menu_layout {
|
|
|
|
B_ITEMS_IN_ROW = 0,
|
|
|
|
B_ITEMS_IN_COLUMN,
|
|
|
|
B_ITEMS_IN_MATRIX
|
|
|
|
};
|
|
|
|
|
|
|
|
struct menu_info {
|
|
|
|
float font_size;
|
|
|
|
font_family f_family;
|
|
|
|
font_style f_style;
|
|
|
|
rgb_color background_color;
|
|
|
|
int32 separator;
|
|
|
|
bool click_to_open;
|
|
|
|
bool triggers_always_shown;
|
|
|
|
};
|
|
|
|
|
2007-09-30 14:52:45 +04:00
|
|
|
status_t get_menu_info(menu_info* info);
|
|
|
|
status_t set_menu_info(menu_info* info);
|
2002-10-23 17:54:44 +04:00
|
|
|
|
2007-09-30 14:52:45 +04:00
|
|
|
typedef bool (*menu_tracking_hook)(BMenu* menu, void* state);
|
2002-10-23 17:54:44 +04:00
|
|
|
|
|
|
|
|
2007-09-30 14:52:45 +04:00
|
|
|
class BMenu : public BView {
|
2002-10-23 17:54:44 +04:00
|
|
|
public:
|
2013-11-06 04:19:11 +04:00
|
|
|
BMenu(const char* name,
|
2009-08-26 16:08:09 +04:00
|
|
|
menu_layout layout = B_ITEMS_IN_COLUMN);
|
2013-11-06 04:19:11 +04:00
|
|
|
BMenu(const char* name, float width,
|
2009-08-26 16:08:09 +04:00
|
|
|
float height);
|
|
|
|
BMenu(BMessage* archive);
|
|
|
|
|
|
|
|
virtual ~BMenu();
|
|
|
|
|
|
|
|
static BArchivable* Instantiate(BMessage* archive);
|
|
|
|
virtual status_t Archive(BMessage* archive,
|
|
|
|
bool deep = true) const;
|
|
|
|
|
|
|
|
virtual void AttachedToWindow();
|
|
|
|
virtual void DetachedFromWindow();
|
|
|
|
virtual void AllAttached();
|
|
|
|
virtual void AllDetached();
|
|
|
|
|
|
|
|
virtual void Draw(BRect updateRect);
|
|
|
|
|
|
|
|
virtual void MessageReceived(BMessage* message);
|
|
|
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
|
|
|
|
|
|
|
virtual BSize MinSize();
|
|
|
|
virtual BSize MaxSize();
|
|
|
|
virtual BSize PreferredSize();
|
|
|
|
virtual void GetPreferredSize(float* _width,
|
|
|
|
float* _height);
|
|
|
|
virtual void ResizeToPreferred();
|
|
|
|
virtual void DoLayout();
|
|
|
|
virtual void FrameMoved(BPoint newPosition);
|
|
|
|
virtual void FrameResized(float newWidth, float newHeight);
|
|
|
|
|
2011-12-09 01:09:35 +04:00
|
|
|
void InvalidateLayout();
|
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
virtual void MakeFocus(bool focus = true);
|
|
|
|
|
|
|
|
bool AddItem(BMenuItem* item);
|
|
|
|
bool AddItem(BMenuItem* item, int32 index);
|
|
|
|
bool AddItem(BMenuItem* item, BRect frame);
|
|
|
|
bool AddItem(BMenu* menu);
|
|
|
|
bool AddItem(BMenu* menu, int32 index);
|
|
|
|
bool AddItem(BMenu* menu, BRect frame);
|
|
|
|
bool AddList(BList* list, int32 index);
|
|
|
|
|
|
|
|
bool AddSeparatorItem();
|
|
|
|
|
|
|
|
bool RemoveItem(BMenuItem* item);
|
|
|
|
BMenuItem* RemoveItem(int32 index);
|
|
|
|
bool RemoveItems(int32 index, int32 count,
|
|
|
|
bool deleteItems = false);
|
|
|
|
bool RemoveItem(BMenu* menu);
|
|
|
|
|
|
|
|
BMenuItem* ItemAt(int32 index) const;
|
|
|
|
BMenu* SubmenuAt(int32 index) const;
|
|
|
|
int32 CountItems() const;
|
|
|
|
int32 IndexOf(BMenuItem* item) const;
|
|
|
|
int32 IndexOf(BMenu* menu) const;
|
|
|
|
BMenuItem* FindItem(uint32 command) const;
|
|
|
|
BMenuItem* FindItem(const char* name) const;
|
|
|
|
|
|
|
|
virtual status_t SetTargetForItems(BHandler* target);
|
|
|
|
virtual status_t SetTargetForItems(BMessenger messenger);
|
2013-11-06 04:19:11 +04:00
|
|
|
virtual void SetEnabled(bool enable);
|
|
|
|
virtual void SetRadioMode(bool on);
|
|
|
|
virtual void SetTriggersEnabled(bool enable);
|
2009-08-26 16:08:09 +04:00
|
|
|
virtual void SetMaxContentWidth(float maxWidth);
|
|
|
|
|
2013-11-06 04:19:11 +04:00
|
|
|
void SetLabelFromMarked(bool on);
|
2009-08-26 16:08:09 +04:00
|
|
|
bool IsLabelFromMarked();
|
|
|
|
bool IsEnabled() const;
|
|
|
|
bool IsRadioMode() const;
|
|
|
|
bool AreTriggersEnabled() const;
|
|
|
|
bool IsRedrawAfterSticky() const;
|
|
|
|
float MaxContentWidth() const;
|
|
|
|
|
|
|
|
BMenuItem* FindMarked();
|
2013-01-03 20:02:21 +04:00
|
|
|
int32 FindMarkedIndex();
|
2009-08-26 16:08:09 +04:00
|
|
|
|
|
|
|
BMenu* Supermenu() const;
|
|
|
|
BMenuItem* Superitem() const;
|
|
|
|
|
|
|
|
|
|
|
|
virtual BHandler* ResolveSpecifier(BMessage* message,
|
|
|
|
int32 index, BMessage* specifier,
|
|
|
|
int32 form, const char* property);
|
|
|
|
virtual status_t GetSupportedSuites(BMessage* data);
|
|
|
|
|
|
|
|
virtual status_t Perform(perform_code d, void* arg);
|
2002-10-23 17:54:44 +04:00
|
|
|
|
|
|
|
protected:
|
2009-08-26 16:08:09 +04:00
|
|
|
BMenu(BRect frame, const char* name,
|
|
|
|
uint32 resizeMask, uint32 flags,
|
|
|
|
menu_layout layout, bool resizeToFit);
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2011-10-23 01:01:47 +04:00
|
|
|
virtual void LayoutInvalidated(bool descendants);
|
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
virtual BPoint ScreenLocation();
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
void SetItemMargins(float left, float top,
|
|
|
|
float right, float bottom);
|
|
|
|
void GetItemMargins(float* _left, float* _top,
|
|
|
|
float* _right, float* _bottom) const;
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
menu_layout Layout() const;
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
virtual void Show();
|
|
|
|
void Show(bool selectFirstItem);
|
|
|
|
void Hide();
|
|
|
|
BMenuItem* Track(bool startOpened = false,
|
|
|
|
BRect* specialRect = NULL);
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
public:
|
2007-09-30 14:52:45 +04:00
|
|
|
enum add_state {
|
|
|
|
B_INITIAL_ADD,
|
|
|
|
B_PROCESSING,
|
|
|
|
B_ABORT
|
|
|
|
};
|
2009-08-26 16:08:09 +04:00
|
|
|
virtual bool AddDynamicItem(add_state state);
|
2013-11-06 04:19:11 +04:00
|
|
|
virtual void DrawBackground(BRect updateRect);
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
void SetTrackingHook(menu_tracking_hook hook,
|
|
|
|
void* state);
|
2007-09-30 14:52:45 +04:00
|
|
|
|
2002-10-23 17:54:44 +04:00
|
|
|
private:
|
2007-09-30 14:52:45 +04:00
|
|
|
friend class BMenuBar;
|
2008-04-11 12:22:09 +04:00
|
|
|
friend class BPrivate::MenuPrivate;
|
2007-09-30 14:52:45 +04:00
|
|
|
friend status_t _init_interface_kit_();
|
|
|
|
friend status_t set_menu_info(menu_info* info);
|
|
|
|
friend status_t get_menu_info(menu_info* info);
|
|
|
|
|
|
|
|
struct LayoutData;
|
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
virtual void _ReservedMenu3();
|
|
|
|
virtual void _ReservedMenu4();
|
|
|
|
virtual void _ReservedMenu5();
|
|
|
|
virtual void _ReservedMenu6();
|
|
|
|
|
|
|
|
BMenu& operator=(const BMenu& other);
|
|
|
|
|
|
|
|
void _InitData(BMessage* archive);
|
2010-06-26 16:29:17 +04:00
|
|
|
bool _Show(bool selectFirstItem = false,
|
|
|
|
bool keyDown = false);
|
2009-08-26 16:08:09 +04:00
|
|
|
void _Hide();
|
|
|
|
BMenuItem* _Track(int* action, long start = -1);
|
|
|
|
|
|
|
|
void _UpdateNavigationArea(BPoint position,
|
|
|
|
BRect& navAreaRectAbove,
|
|
|
|
BRect& navAreaBelow);
|
|
|
|
|
|
|
|
void _UpdateStateOpenSelect(BMenuItem* item,
|
|
|
|
BPoint position, BRect& navAreaRectAbove,
|
|
|
|
BRect& navAreaBelow,
|
|
|
|
bigtime_t& selectedTime,
|
|
|
|
bigtime_t& navigationAreaTime);
|
|
|
|
void _UpdateStateClose(BMenuItem* item,
|
|
|
|
const BPoint& where,
|
|
|
|
const uint32& buttons);
|
|
|
|
|
|
|
|
bool _AddItem(BMenuItem* item, int32 index);
|
|
|
|
bool _RemoveItems(int32 index, int32 count,
|
|
|
|
BMenuItem* item, bool deleteItems = false);
|
|
|
|
bool _RelayoutIfNeeded();
|
|
|
|
void _LayoutItems(int32 index);
|
|
|
|
BSize _ValidatePreferredSize();
|
|
|
|
void _ComputeLayout(int32 index, bool bestFit,
|
|
|
|
bool moveItems, float* width,
|
|
|
|
float* height);
|
|
|
|
void _ComputeColumnLayout(int32 index, bool bestFit,
|
2013-04-13 12:28:48 +04:00
|
|
|
bool moveItems, BRect* override, BRect& outRect);
|
2009-08-26 16:08:09 +04:00
|
|
|
void _ComputeRowLayout(int32 index, bool bestFit,
|
2013-05-07 00:50:23 +04:00
|
|
|
bool moveItems, BRect& outRect);
|
2009-08-26 16:08:09 +04:00
|
|
|
void _ComputeMatrixLayout(BRect& outRect);
|
|
|
|
|
|
|
|
BRect _CalcFrame(BPoint where, bool* scrollOn);
|
2007-09-30 14:52:45 +04:00
|
|
|
|
Implemented a new look for the Haiku interface controls. It was
overheard that they looked too ninety-ish.
TODO: The code behind this is work in progress. The basic idea
is to extract all drawing code into a new class BControlLook,
of which there is a global instance be_control_look, instantiated
in InterfaceDefs.cpp. At the moment, all the old drawing code is
still there, and the usage of be_control_look is inside if-bodies
checking the instance against NULL. In another words, by not
instanitating be_control_look, you can revert back to the old look.
BControlLook's job is to provide reusable methods for drawing
certain types of frames, backgrounds and labels, so that application
developers can make controls that re-use the same drawing code
as built-in controls and adopt to changes made there. I have added
the notion of "borders". Each of the frame drawing methods can be
made to draw certain borders only, which is supposed to help when
controls shall visually attach. This feature is not fully explored
at all ATM.
TODO: Update BColumnListView header view and BStringItem text
spacing. Update other apps where it makes sense to use BControlLook.
For the moment, only Tracker and LaunchBox are updated. More...
NOTE: The new look is not very radically different, so that existing
apps do not immediately look too ugly or out of place.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29221 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-02-15 21:23:19 +03:00
|
|
|
protected:
|
2016-04-19 23:48:53 +03:00
|
|
|
void DrawItems(BRect updateRect);
|
2007-09-30 14:52:45 +04:00
|
|
|
|
Implemented a new look for the Haiku interface controls. It was
overheard that they looked too ninety-ish.
TODO: The code behind this is work in progress. The basic idea
is to extract all drawing code into a new class BControlLook,
of which there is a global instance be_control_look, instantiated
in InterfaceDefs.cpp. At the moment, all the old drawing code is
still there, and the usage of be_control_look is inside if-bodies
checking the instance against NULL. In another words, by not
instanitating be_control_look, you can revert back to the old look.
BControlLook's job is to provide reusable methods for drawing
certain types of frames, backgrounds and labels, so that application
developers can make controls that re-use the same drawing code
as built-in controls and adopt to changes made there. I have added
the notion of "borders". Each of the frame drawing methods can be
made to draw certain borders only, which is supposed to help when
controls shall visually attach. This feature is not fully explored
at all ATM.
TODO: Update BColumnListView header view and BStringItem text
spacing. Update other apps where it makes sense to use BControlLook.
For the moment, only Tracker and LaunchBox are updated. More...
NOTE: The new look is not very radically different, so that existing
apps do not immediately look too ugly or out of place.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29221 a95241bf-73f2-0310-859d-f6bbb57e9c96
2009-02-15 21:23:19 +03:00
|
|
|
private:
|
2009-08-26 16:08:09 +04:00
|
|
|
bool _OverSuper(BPoint loc);
|
|
|
|
bool _OverSubmenu(BMenuItem* item, BPoint loc);
|
2007-09-30 14:52:45 +04:00
|
|
|
BPrivate::BMenuWindow* _MenuWindow();
|
2009-08-26 16:08:09 +04:00
|
|
|
void _DeleteMenuWindow();
|
|
|
|
BMenuItem* _HitTestItems(BPoint where,
|
|
|
|
BPoint slop = B_ORIGIN) const;
|
|
|
|
BRect _Superbounds() const;
|
|
|
|
void _CacheFontInfo();
|
|
|
|
|
|
|
|
void _ItemMarked(BMenuItem* item);
|
|
|
|
void _Install(BWindow* target);
|
|
|
|
void _Uninstall();
|
|
|
|
void _SelectItem(BMenuItem* item,
|
|
|
|
bool showSubmenu = true,
|
2010-06-26 16:29:17 +04:00
|
|
|
bool selectFirstItem = false,
|
|
|
|
bool keyDown = false);
|
2009-08-26 16:08:09 +04:00
|
|
|
bool _SelectNextItem(BMenuItem* item, bool forward);
|
|
|
|
BMenuItem* _NextItem(BMenuItem* item, bool forward) const;
|
2016-04-19 23:48:25 +03:00
|
|
|
void _SetIgnoreHidden(bool ignoreHidden)
|
2018-12-10 07:00:47 +03:00
|
|
|
{ fIgnoreHidden = ignoreHidden; }
|
2009-08-26 16:08:09 +04:00
|
|
|
void _SetStickyMode(bool on);
|
|
|
|
bool _IsStickyMode() const;
|
2011-11-07 05:46:42 +04:00
|
|
|
|
|
|
|
// Methods to get the current modifier keycode
|
|
|
|
void _GetShiftKey(uint32 &value) const;
|
|
|
|
void _GetControlKey(uint32 &value) const;
|
|
|
|
void _GetCommandKey(uint32 &value) const;
|
|
|
|
void _GetOptionKey(uint32 &value) const;
|
|
|
|
void _GetMenuKey(uint32 &value) const;
|
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
void _CalcTriggers();
|
|
|
|
bool _ChooseTrigger(const char* title, int32& index,
|
|
|
|
uint32& trigger,
|
|
|
|
BPrivate::TriggerList& triggers);
|
2010-04-20 16:37:08 +04:00
|
|
|
void _UpdateWindowViewSize(const bool &updatePosition);
|
2010-06-30 18:49:42 +04:00
|
|
|
bool _AddDynamicItems(bool keyDown = false);
|
2010-06-26 16:29:17 +04:00
|
|
|
bool _OkToProceed(BMenuItem* item,
|
|
|
|
bool keyDown = false);
|
2009-08-26 16:08:09 +04:00
|
|
|
|
|
|
|
bool _CustomTrackingWantsToQuit();
|
|
|
|
|
|
|
|
int _State(BMenuItem** _item = NULL) const;
|
|
|
|
void _InvokeItem(BMenuItem* item, bool now = false);
|
|
|
|
void _QuitTracking(bool onlyThis = true);
|
|
|
|
|
|
|
|
static menu_info sMenuInfo;
|
2011-11-07 05:46:42 +04:00
|
|
|
|
|
|
|
// Variables to keep track of what code is currently assigned to
|
|
|
|
// each modifier key
|
|
|
|
static uint32 sShiftKey;
|
|
|
|
static uint32 sControlKey;
|
|
|
|
static uint32 sOptionKey;
|
|
|
|
static uint32 sCommandKey;
|
|
|
|
static uint32 sMenuKey;
|
2009-08-26 16:08:09 +04:00
|
|
|
|
|
|
|
BMenuItem* fChosenItem;
|
|
|
|
BList fItems;
|
|
|
|
BRect fPad;
|
|
|
|
BMenuItem* fSelected;
|
2007-09-30 14:52:45 +04:00
|
|
|
BPrivate::BMenuWindow* fCachedMenuWindow;
|
2009-08-26 16:08:09 +04:00
|
|
|
BMenu* fSuper;
|
|
|
|
BMenuItem* fSuperitem;
|
|
|
|
BRect fSuperbounds;
|
|
|
|
float fAscent;
|
|
|
|
float fDescent;
|
|
|
|
float fFontHeight;
|
|
|
|
uint32 fState;
|
|
|
|
menu_layout fLayout;
|
|
|
|
BRect* fExtraRect;
|
|
|
|
float fMaxContentWidth;
|
|
|
|
BPoint* fInitMatrixSize;
|
2007-09-30 14:52:45 +04:00
|
|
|
BPrivate::ExtraMenuData* fExtraMenuData;
|
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
LayoutData* fLayoutData;
|
|
|
|
|
2010-06-30 18:49:42 +04:00
|
|
|
int32 _reserved;
|
2009-08-26 16:08:09 +04:00
|
|
|
|
|
|
|
char fTrigger;
|
|
|
|
bool fResizeToFit;
|
|
|
|
bool fUseCachedMenuLayout;
|
|
|
|
bool fEnabled;
|
|
|
|
bool fDynamicName;
|
|
|
|
bool fRadioMode;
|
|
|
|
bool fTrackNewBounds;
|
|
|
|
bool fStickyMode;
|
|
|
|
bool fIgnoreHidden;
|
|
|
|
bool fTriggerEnabled;
|
|
|
|
bool fRedrawAfterSticky;
|
|
|
|
bool fAttachAborted;
|
2002-10-23 17:54:44 +04:00
|
|
|
};
|
|
|
|
|
2009-08-26 16:08:09 +04:00
|
|
|
#endif // _MENU_H
|