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