1 /* 2 * Copyright 2006-2013, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _MENU_FIELD_H 6 #define _MENU_FIELD_H 7 8 9 #include <Menu.h> 10 11 12 class BMenuBar; 13 class BMessageFilter; 14 15 16 class BMenuField : public BView { 17 public: 18 BMenuField(BRect frame, const char* name, 19 const char* label, BMenu* menu, 20 uint32 resizingMode = B_FOLLOW_LEFT 21 | B_FOLLOW_TOP, 22 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 23 BMenuField(BRect frame, const char* name, 24 const char* label, BMenu* menu, 25 bool fixed_size, 26 uint32 resizingMode = B_FOLLOW_LEFT 27 | B_FOLLOW_TOP, 28 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 29 BMenuField(const char* name, 30 const char* label, BMenu* menu, 31 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 32 BMenuField(const char* label, BMenu* menu, 33 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 34 BMenuField(BMessage* data); 35 virtual ~BMenuField(); 36 37 static BArchivable* Instantiate(BMessage* archive); 38 virtual status_t Archive(BMessage* archive, 39 bool deep = true) const; 40 41 virtual void Draw(BRect updateRect); 42 virtual void AttachedToWindow(); 43 virtual void AllAttached(); 44 virtual void MouseDown(BPoint where); 45 virtual void KeyDown(const char* bytes, int32 numBytes); 46 virtual void MakeFocus(bool focused); 47 virtual void MessageReceived(BMessage* message); 48 virtual void WindowActivated(bool state); 49 virtual void MouseUp(BPoint where); 50 virtual void MouseMoved(BPoint where, uint32 transit, 51 const BMessage* dragMessage); 52 virtual void DetachedFromWindow(); 53 virtual void AllDetached(); 54 virtual void FrameMoved(BPoint where); 55 virtual void FrameResized(float width, float height); 56 57 BMenu* Menu() const; 58 BMenuBar* MenuBar() const; 59 BMenuItem* MenuItem() const; 60 61 virtual void SetLabel(const char* label); 62 const char* Label() const; 63 64 virtual void SetEnabled(bool on); 65 bool IsEnabled() const; 66 67 virtual void SetAlignment(alignment label); 68 alignment Alignment() const; 69 virtual void SetDivider(float position); 70 float Divider() const; 71 72 void ShowPopUpMarker(); 73 void HidePopUpMarker(); 74 75 virtual BHandler* ResolveSpecifier(BMessage* message, 76 int32 index, BMessage* specifier, 77 int32 form, const char* property); 78 virtual status_t GetSupportedSuites(BMessage* data); 79 80 virtual void ResizeToPreferred(); 81 virtual void GetPreferredSize(float* width, float* height); 82 83 virtual BSize MinSize(); 84 virtual BSize MaxSize(); 85 virtual BSize PreferredSize(); 86 87 BLayoutItem* CreateLabelLayoutItem(); 88 BLayoutItem* CreateMenuBarLayoutItem(); 89 90 virtual status_t Perform(perform_code d, void* arg); 91 92 protected: 93 virtual status_t AllArchived(BMessage* into) const; 94 virtual status_t AllUnarchived(const BMessage* from); 95 96 virtual void LayoutInvalidated(bool descendants); 97 virtual void DoLayout(); 98 99 private: 100 // FBC padding 101 virtual void _ReservedMenuField1(); 102 virtual void _ReservedMenuField2(); 103 virtual void _ReservedMenuField3(); 104 105 // Forbidden 106 BMenuField& operator=(const BMenuField& other); 107 108 private: 109 class LabelLayoutItem; 110 class MenuBarLayoutItem; 111 struct LayoutData; 112 113 friend class _BMCMenuBar_; 114 friend class LabelLayoutItem; 115 friend class MenuBarLayoutItem; 116 friend class LayoutData; 117 118 BMenuField(const char* name, 119 const char* label, BMenu* menu, 120 BMessage* message, 121 uint32 flags); 122 BMenuField(const char* label, 123 BMenu* menu, BMessage* message); 124 125 void _DrawLabel(BRect updateRect); 126 void _DrawMenuBar(BRect updateRect); 127 128 void InitObject(const char* label); 129 void InitObject2(); 130 131 static void InitMenu(BMenu* menu); 132 133 int32 _MenuTask(); 134 static int32 _thread_entry(void *arg); 135 136 void _UpdateFrame(); 137 void _InitMenuBar(BMenu* menu, 138 BRect frame, bool fixedSize); 139 void _InitMenuBar(const BMessage* archive); 140 141 void _ValidateLayoutData(); 142 float _MenuBarOffset() const; 143 float _MenuBarWidth() const; 144 145 void _DoneTracking(BPoint point); 146 void _Track(BPoint point, uint32); 147 148 private: 149 char* fLabel; 150 BMenu* fMenu; 151 BMenuBar* fMenuBar; 152 alignment fAlign; 153 float fDivider; 154 bool fEnabled; 155 bool fFixedSizeMB; 156 thread_id fMenuTaskID; 157 158 LayoutData* fLayoutData; 159 BMessageFilter* fMouseDownFilter; 160 161 uint32 _reserved[2]; 162 }; 163 164 #endif // _MENU_FIELD_H 165